コード例 #1
0
bool
StarshipAI::AssessTargetPointDefense()
{
	if (Game::GameTime() - point_defense_time < 3500)
	return tgt_point_defense;

	tgt_point_defense = false;

	if (!target || target->Type() != SimObject::SIM_SHIP || GetAILevel() < 2)
	return tgt_point_defense;

	Ship* tgt_ship = (Ship*) target;

	if (!tgt_ship->IsStarship())
	return tgt_point_defense;

	Weapon*  subtgt = 0;
	Point    svec   = ship->Location() - tgt_ship->Location();

	point_defense_time = Game::GameTime();

	// first pass: turrets
	ListIter<WeaponGroup> g_iter = tgt_ship->Weapons();
	while (++g_iter && !tgt_point_defense) {
		WeaponGroup* g = g_iter.value();

		if (g->CanTarget(1)) {
			ListIter<Weapon> w_iter = g->GetWeapons();
			while (++w_iter && !tgt_point_defense) {
				Weapon* w = w_iter.value();

				if (w->Availability() > 35 && w->GetAimVector() * svec > 0)
				tgt_point_defense = true;
			}
		}
	}

	return tgt_point_defense;
}
コード例 #2
0
System*
StarshipAI::SelectSubtarget()
{
	if (Game::GameTime() - sub_select_time < 2345)
	return subtarget;

	subtarget = 0;

	if (!target || target->Type() != SimObject::SIM_SHIP || GetAILevel() < 1)
	return subtarget;

	Ship* tgt_ship = (Ship*) target;

	if (!tgt_ship->IsStarship())
	return subtarget;

	Weapon*  subtgt = 0;
	double   dist   = 50e3;
	Point    svec   = ship->Location() - tgt_ship->Location();

	sub_select_time = Game::GameTime();

	// first pass: turrets
	ListIter<WeaponGroup> g_iter = tgt_ship->Weapons();
	while (++g_iter) {
		WeaponGroup* g = g_iter.value();

		if (g->GetDesign() && g->GetDesign()->turret_model) {
			ListIter<Weapon> w_iter = g->GetWeapons();
			while (++w_iter) {
				Weapon*  w     = w_iter.value();

				if (w->Availability() < 35)
				continue;

				if (w->GetAimVector() * svec < 0)
				continue;

				if (w->GetTurret()) {
					Point    tloc  = w->GetTurret()->Location();
					Point    delta = tloc - ship->Location();
					double   dlen  = delta.length();

					if (dlen < dist) {
						subtgt = w;
						dist   = dlen;
					}
				}
			}
		}
	}

	// second pass: major weapons
	if (!subtgt) {
		g_iter.reset();
		while (++g_iter) {
			WeaponGroup* g = g_iter.value();

			if (g->GetDesign() && !g->GetDesign()->turret_model) {
				ListIter<Weapon> w_iter = g->GetWeapons();
				while (++w_iter) {
					Weapon*  w     = w_iter.value();

					if (w->Availability() < 35)
					continue;

					if (w->GetAimVector() * svec < 0)
					continue;

					Point    tloc  = w->MountLocation();
					Point    delta = tloc - ship->Location();
					double   dlen  = delta.length();

					if (dlen < dist) {
						subtgt = w;
						dist   = dlen;
					}
				}
			}
		}
	}

	subtarget = subtgt;
	return subtarget;
}