CombatInfo::CombatInfo(int system_id_, int turn_) : turn(turn_), system_id(system_id_) { TemporaryPtr<System> system = ::GetSystem(system_id); if (!system) { Logger().errorStream() << "CombatInfo constructed with invalid system id: " << system_id; return; } // add system to full / complete objects in combat - NOTE: changed from copy of system objects.Insert(system); // find ships and their owners in system std::vector<TemporaryPtr<Ship> > ships = Objects().FindObjects<Ship>(system->ShipIDs()); for (std::vector<TemporaryPtr<Ship> >::const_iterator ship_it = ships.begin(); ship_it != ships.end(); ++ship_it) { TemporaryPtr<Ship> ship = *ship_it; // add owner to empires that have assets in this battle empire_ids.insert(ship->Owner()); objects.Insert(ship); } // find planets and their owners in system std::vector<TemporaryPtr<Planet> > planets = Objects().FindObjects<Planet>(system->PlanetIDs()); for (std::vector<TemporaryPtr<Planet> >::const_iterator planet_it = planets.begin(); planet_it != planets.end(); ++planet_it) { TemporaryPtr<Planet> planet = *planet_it; // if planet is populated, add owner to empires that have assets in this battle if (planet->CurrentMeterValue(METER_POPULATION) > 0.0) empire_ids.insert(planet->Owner()); objects.Insert(planet); } // TODO: should buildings be considered separately? // now that all participants in the battle have been found, loop through // objects again to assemble each participant empire's latest // known information about all objects in this battle // system for (std::set<int>::const_iterator empire_it = empire_ids.begin(); empire_it != empire_ids.end(); ++empire_it) { int empire_id = *empire_it; if (empire_id == ALL_EMPIRES) continue; empire_known_objects[empire_id].Insert(GetEmpireKnownSystem(system->ID(), empire_id)); } // ships for (std::vector<TemporaryPtr<Ship> >::const_iterator it = ships.begin(); it != ships.end(); ++it) { TemporaryPtr<Ship> ship = *it; int ship_id = ship->ID(); TemporaryPtr<const Fleet> fleet = GetFleet(ship->FleetID()); if (!fleet) { Logger().errorStream() << "CombatInfo::CombatInfo couldn't get fleet with id " << ship->FleetID() << " in system " << system->Name() << " (" << system_id << ")"; continue; } for (std::set<int>::const_iterator empire_it = empire_ids.begin(); empire_it != empire_ids.end(); ++empire_it) { int empire_id = *empire_it; if (empire_id == ALL_EMPIRES) continue; if (GetUniverse().GetObjectVisibilityByEmpire(ship_id, empire_id) >= VIS_BASIC_VISIBILITY || (fleet->Aggressive() && (empire_id == ALL_EMPIRES || fleet->Unowned() || Empires().GetDiplomaticStatus(empire_id, fleet->Owner()) == DIPLO_WAR))) { empire_known_objects[empire_id].Insert(GetEmpireKnownShip(ship->ID(), empire_id));} } } // planets for (std::vector<TemporaryPtr<Planet> >::const_iterator it = planets.begin(); it != planets.end(); ++it) { TemporaryPtr<Planet> planet = *it; int planet_id = planet->ID(); for (std::set<int>::const_iterator empire_it = empire_ids.begin(); empire_it != empire_ids.end(); ++empire_it) { int empire_id = *empire_it; if (empire_id == ALL_EMPIRES) continue; if (GetUniverse().GetObjectVisibilityByEmpire(planet_id, empire_id) >= VIS_BASIC_VISIBILITY) { empire_known_objects[empire_id].Insert(GetEmpireKnownPlanet(planet->ID(), empire_id)); } } } // after battle is simulated, any changes to latest known or actual objects // will be copied back to the main Universe's ObjectMap and the Universe's // empire latest known objects ObjectMap - NOTE: Using the real thing now }