示例#1
0
void Lieutenant::CheckEngaged()
{
	engaged = false;
	for (size_t i(0); i < marines.size(); ++i)
	{
		const Unit & marine(marines[i]);
		// Cache the unit's position and the range of its weapon
		const vec2	position(marine.GetPosition());
		const sint4 range(marine.GetWeaponRange());
		const sint4 rangeSq(range*range);
		//Quick Check
		if (marine.InCombat() && marine.IsAlive())
		{
			engaged = true;
			return;
		}
		for(size_t j(0); j<enemies.size(); ++j)
		{
			const Unit & enemy(enemies[j]);
			if(position.GetDistanceSqTo(enemy.GetPosition()) <= rangeSq)
			{
				engaged = true;
				return;
			}
		}
	}

	for (size_t i(0); i < tanks.size(); ++i)
	{
		const Unit & tank(tanks[i]);
		// Cache the unit's position and the range of its weapon
		const vec2	position(tank.GetPosition());
		const sint4 range(tank.GetWeaponRange());
		const sint4 rangeSq(range*range);
		//Quick Check
		if (tank.InCombat() && tank.IsAlive())
		{
			engaged = true;
			return;
		}
		for(size_t j(0); j<enemies.size(); ++j)
		{
			const Unit & enemy(enemies[j]);
			if(position.GetDistanceSqTo(enemy.GetPosition()) <= rangeSq)
			{
				engaged = true;
				return;
			}
		}
	}
}
示例#2
0
void Lieutenant::FireAtWill(Vector<Unit> enemies)
{
	for(size_t i(0); i<marines.size(); ++i)
	{
		sint4 weakestHP = 150;	//tanks maxhealth
		Unit& marine(marines[i]);
		Unit& target = enemies[0];

		// Cache the unit's position and the range of its weapon
		const vec2	position(marine.GetPosition());
		const sint4 range(marine.GetWeaponRange());
		const sint4 rangeSq(range*range);

		// Choose the weakest enemy unit we find in range
		for(size_t j(0); j<enemies.size(); ++j)
		{
			const Unit & enemy(enemies[j]);
			if(position.GetDistanceSqTo(enemy.GetPosition()) <= rangeSq)
			{
				sint4 hp = enemy.GetHitpoints();
				if (hp <= weakestHP && hp > 0)
				{
					weakestHP = hp;
					target = enemy;
				}
			}
		}
		if(position.GetDistanceSqTo(target.GetPosition()) <= rangeSq)
		{
		marine.Attack(target);
		engaged = true;
		}
	}

	for(size_t i(0); i<tanks.size(); ++i)
	{
		sint4 weakestHP = 150;	//tanks maxhealth
		Unit& tank(tanks[i]);
		Unit& target = enemies[0];

		// Cache the unit's position and the range of its weapon
		const vec2	position(tank.GetPosition());
		const sint4 range(tank.GetWeaponRange());
		const sint4 rangeSq(range*range);

		// Choose the weakest enemy unit we find in range
		for(size_t j(0); j<enemies.size(); ++j)
		{
			const Unit & enemy(enemies[j]);
			if(position.GetDistanceSqTo(enemy.GetPosition()) <= rangeSq)
			{
				sint4 hp = enemy.GetHitpoints();
				if (hp <= weakestHP && hp > 0)
				{
					weakestHP = hp;
					target = enemy;
				}
			}
		}
		if(position.GetDistanceSqTo(target.GetPosition()) <= rangeSq)
		{
		tank.Attack(target);
		engaged = true;
		}
	}
}