
#include "MW4Headers.hpp"

#include "AI_Damage.hpp"
#include "MWDamageObject.hpp"



using namespace MW4AI;
using namespace MW4AI::Damage;



int Damage::GetArmorDamage(MWObject& mwobject, int armor_zone)
{
	Stuff::SortedChainIteratorOf<Adept::DamageObject*,int> i(&(mwobject.damageObjects));
	Adept::DamageObject* o;

	while ((o = i.ReadAndNext()) != 0)
	{
		if (o->armorZone == armor_zone)
		{
			return (o->GetCurrentDamageLevel());
		}
	}

	return (Adept::DamageObject::Destroyed);
}

Stuff::Scalar Damage::GetHighResArmorLevel(MechWarrior4::MWObject& mwobject, int armor_zone)
{
	Stuff::SortedChainIteratorOf<Adept::DamageObject*,int> i(&(mwobject.damageObjects));
	Adept::DamageObject* o;

	while ((o = i.ReadAndNext()) != 0)
	{
		if (o->armorZone == armor_zone)
		{
			return (o->GetHighResDamageLevel());
		}
	}

	return (0);
}

int Damage::GetInternalDamage(MWObject& mwobject, int internal_zone)
{
	Stuff::SortedChainIteratorOf<MechWarrior4::MWInternalDamageObject*,int> i(&(mwobject.internalDamageObjects));
	MechWarrior4::MWInternalDamageObject* o;

	while ((o = i.ReadAndNext()) != 0)
	{
		if (o->damageZone == internal_zone)
		{
			return (o->GetCurrentDamageLevel());
		}
	}

	return (Adept::InternalDamageObject::Destroyed);
}

bool Damage::CanRepair(MechWarrior4::MWObject& mwobject)
{
	{
		Stuff::SortedChainIteratorOf<MWInternalDamageObject*,int> i(&(mwobject.internalDamageObjects));

		MWInternalDamageObject* internal_damageobject = 0;
		while ((internal_damageobject = i.ReadAndNext()) != 0)
		{
			if (internal_damageobject->CanRepair() == true)
			{
				return (true);
			}
		}
	}

	{
		Stuff::SortedChainIteratorOf<Adept::DamageObject*,int> i(&(mwobject.damageObjects));

		Adept::DamageObject* damageobject = 0;
		while ((damageobject = i.ReadAndNext()) != 0)
		{
			if (damageobject->CanRepair() == true)
			{
				return (true);
			}
		}
	}

	return (false);
}

Stuff::Scalar Damage::GetDamageRating(MechWarrior4::MWObject& mwobject)
{
	Stuff::Scalar score = 0;

	Stuff::SortedChainIteratorOf<Adept::DamageObject*,int> i(&(mwobject.damageObjects));

	Adept::DamageObject* damageobject = 0;
	while ((damageobject = i.ReadAndNext()) != 0)
	{
		score += damageobject->currentArmorValue;
	}

	return (score);
}
