int WeaponGroup::Status() const { int status = System::NOMINAL; int critical = true; ListIter<Weapon> iter = (List<Weapon>&) weapons; // cast-away const while (++iter) { Weapon* w = iter.value(); if (w->Status() < System::NOMINAL) status = System::DEGRADED; if (w->Status() > System::CRITICAL) critical = false; } if (critical) return System::CRITICAL; return status; }
bool FighterTacticalAI::IsStrikeComplete(Instruction* instr) { // wingmen can not call a halt to a strike: if (!ship || element_index > 1) return false; // if there's nothing to shoot at, we must be done: if (!instr || !instr->GetTarget() || instr->GetTarget()->Life() == 0 || instr->GetTarget()->Type() != SimObject::SIM_SHIP) return true; // break off strike only when ALL weapons are expended: // (remember to check all relevant wingmen) Element* element = ship->GetElement(); Ship* target = (Ship*) instr->GetTarget(); if (!element) return true; for (int i = 0; i < element->NumShips(); i++) { Ship* s = element->GetShip(i+1); if (!s || s->Integrity() < 25) // || (s->Location() - target->Location()).length() > 250e3) continue; ListIter<WeaponGroup> g_iter = s->Weapons(); while (++g_iter) { WeaponGroup* w = g_iter.value(); if (w->Ammo() && w->CanTarget(target->Class())) { ListIter<Weapon> w_iter = w->GetWeapons(); while (++w_iter) { Weapon* weapon = w_iter.value(); if (weapon->Status() > System::CRITICAL) return false; } } } } // still here? we must be done! return true; }