From: <geo...@us...> - 2012-07-02 22:55:24
|
Revision: 4964 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=4964&view=rev Author: geoffthemedio Date: 2012-07-02 22:55:18 +0000 (Mon, 02 Jul 2012) Log Message: ----------- Added recording of objects damaged during a combat to CombatInfo. Modified Paths: -------------- trunk/FreeOrion/combat/CombatSystem.cpp trunk/FreeOrion/combat/CombatSystem.h Modified: trunk/FreeOrion/combat/CombatSystem.cpp =================================================================== --- trunk/FreeOrion/combat/CombatSystem.cpp 2012-07-02 21:10:08 UTC (rev 4963) +++ trunk/FreeOrion/combat/CombatSystem.cpp 2012-07-02 22:55:18 UTC (rev 4964) @@ -143,6 +143,7 @@ objects.Clear(); for (std::map<int, ObjectMap>::iterator it = empire_known_objects.begin(); it != empire_known_objects.end(); ++it) it->second.Clear(); + damaged_object_ids.clear(); destroyed_object_ids.clear(); destroyed_object_knowers.clear(); } @@ -198,6 +199,15 @@ } } +void CombatInfo::GetDamagedObjectsToSerialize(std::set<int>& filtered_damaged_objects, int encoding_empire) const { + if (encoding_empire == ALL_EMPIRES) { + filtered_damaged_objects = this->damaged_object_ids; + return; + } + // TODO: decide if some filtering is needed for damaged objects... it may not be. + filtered_damaged_objects = this->damaged_object_ids; +} + void CombatInfo::GetDestroyedObjectsToSerialize(std::set<int>& filtered_destroyed_objects, int encoding_empire) const { if (encoding_empire == ALL_EMPIRES) { filtered_destroyed_objects = this->destroyed_object_ids; @@ -223,7 +233,7 @@ // AutoResolveCombat //////////////////////////////////////////////// namespace { - void AttackShipShip(Ship* attacker, Ship* target) { + void AttackShipShip(Ship* attacker, Ship* target, std::set<int>& damaged_object_ids) { if (!attacker || ! target) return; const ShipDesign* attacker_design = attacker->Design(); @@ -251,6 +261,9 @@ if (shield_damage >= target_shield->Current()) structure_damage = std::min(target_structure->Current(), damage - shield_damage); + if (shield_damage > 0 || structure_damage > 0) + damaged_object_ids.insert(target->ID()); + if (shield_damage > 0) { target_shield->AddToCurrent(-shield_damage); Logger().debugStream() << "COMBAT: Ship " << attacker->Name() << " (" << attacker->ID() << ") does " << shield_damage << " shield damage to Ship " << target->Name() << " (" << target->ID() << ")"; @@ -264,7 +277,7 @@ target->SetLastTurnActiveInCombat(CurrentTurn()); } - void AttackShipPlanet(Ship* attacker, Planet* target) { + void AttackShipPlanet(Ship* attacker, Planet* target, std::set<int>& damaged_object_ids) { if (!attacker || ! target) return; const ShipDesign* attacker_design = attacker->Design(); @@ -304,6 +317,9 @@ if (shield_damage >= target_shield->Current()) defense_damage = std::min(target_defense->Current(), damage - shield_damage); + if (shield_damage > 0 || defense_damage > 0 || construction_damage > 0) + damaged_object_ids.insert(target->ID()); + if (defense_damage >= target_defense->Current()) construction_damage = std::min(target_construction->Current(), damage - shield_damage - defense_damage); @@ -315,7 +331,6 @@ target_defense->AddToCurrent(-defense_damage); Logger().debugStream() << "COMBAT: Ship " << attacker->Name() << " (" << attacker->ID() << ") does " << defense_damage << " defense damage to Planet " << target->Name() << " (" << target->ID() << ")"; } - if (construction_damage >= 0) { target_construction->AddToCurrent(-construction_damage); Logger().debugStream() << "COMBAT: Ship " << attacker->Name() << " (" << attacker->ID() << ") does " << construction_damage << " instrastructure damage to Planet " << target->Name() << " (" << target->ID() << ")"; @@ -325,7 +340,7 @@ target->SetLastTurnAttackedByShip(CurrentTurn()); } - void AttackPlanetShip(Planet* attacker, Ship* target) { + void AttackPlanetShip(Planet* attacker, Ship* target, std::set<int>& damaged_object_ids) { if (!attacker || ! target) return; double damage = attacker->UniverseObject::GetMeter(METER_DEFENSE)->Current(); // planet "Defense" meter is actually its attack power @@ -350,6 +365,9 @@ if (shield_damage >= target_shield->Current()) structure_damage = std::min(target_structure->Current(), damage - shield_damage); + if (shield_damage > 0 || structure_damage > 0) + damaged_object_ids.insert(target->ID()); + if (shield_damage >= 0) { target_shield->AddToCurrent(-shield_damage); Logger().debugStream() << "COMBAT: Planet " << attacker->Name() << " (" << attacker->ID() << ") does " << shield_damage << " shield damage to Ship " << target->Name() << " (" << target->ID() << ")"; @@ -362,7 +380,7 @@ target->SetLastTurnActiveInCombat(CurrentTurn()); } - void AttackPlanetPlanet(Planet* attacker, Planet* target) { + void AttackPlanetPlanet(Planet* attacker, Planet* target, std::set<int>& damaged_object_ids) { Logger().debugStream() << "AttackPlanetPlanet does nothing!"; // intentionally left empty } @@ -538,15 +556,15 @@ // do actual attack if (Ship* attack_ship = universe_object_cast<Ship*>(attacker)) { if (Ship* target_ship = universe_object_cast<Ship*>(target)) { - AttackShipShip(attack_ship, target_ship); + AttackShipShip(attack_ship, target_ship, combat_info.damaged_object_ids); } else if (Planet* target_planet = universe_object_cast<Planet*>(target)) { - AttackShipPlanet(attack_ship, target_planet); + AttackShipPlanet(attack_ship, target_planet, combat_info.damaged_object_ids); } } else if (Planet* attack_planet = universe_object_cast<Planet*>(attacker)) { if (Ship* target_ship = universe_object_cast<Ship*>(target)) { - AttackPlanetShip(attack_planet, target_ship); + AttackPlanetShip(attack_planet, target_ship, combat_info.damaged_object_ids); } else if (Planet* target_planet = universe_object_cast<Planet*>(target)) { - AttackPlanetPlanet(attack_planet, target_planet); + AttackPlanetPlanet(attack_planet, target_planet, combat_info.damaged_object_ids); } } Modified: trunk/FreeOrion/combat/CombatSystem.h =================================================================== --- trunk/FreeOrion/combat/CombatSystem.h 2012-07-02 21:10:08 UTC (rev 4963) +++ trunk/FreeOrion/combat/CombatSystem.h 2012-07-02 22:55:18 UTC (rev 4964) @@ -6,8 +6,7 @@ /** Contains information about the state of a combat before or after the combat * occurs. */ -struct CombatInfo -{ +struct CombatInfo { public: /** \name Structors */ //@{ CombatInfo(); ///< Default ctor @@ -27,6 +26,7 @@ std::set<int> empire_ids; ///< IDs of empires involved in combat ObjectMap objects; ///< actual state of objects relevant to combat std::map<int, ObjectMap> empire_known_objects; ///< each empire's latest known state of objects relevant to combat + std::set<int> damaged_object_ids; ///< ids of objects damaged during this battle std::set<int> destroyed_object_ids; ///< ids of objects destroyed during this battle std::map<int, std::set<int> > destroyed_object_knowers; ///< indexed by empire ID, the set of ids of objects the empire knows were destroyed during the combat @@ -34,6 +34,7 @@ void GetEmpireIdsToSerialize( std::set<int>& filtered_empire_ids, int encoding_empire) const; void GetObjectsToSerialize( ObjectMap& filtered_objects, int encoding_empire) const; void GetEmpireKnownObjectsToSerialize( std::map<int, ObjectMap>& filtered_empire_known_objects, int encoding_empire) const; + void GetDamagedObjectsToSerialize( std::set<int>& filtered_damaged_objects, int encoding_empire) const; void GetDestroyedObjectsToSerialize( std::set<int>& filtered_destroyed_objects, int encoding_empire) const; void GetDestroyedObjectKnowersToSerialize( std::map<int, std::set<int> >& filtered_destroyed_object_knowers, int encoding_empire) const; @@ -54,12 +55,14 @@ std::set<int> filtered_empire_ids; ObjectMap filtered_objects; std::map<int, ObjectMap> filtered_empire_known_objects; + std::set<int> filtered_damaged_object_ids; std::set<int> filtered_destroyed_object_ids; std::map<int, std::set<int> > filtered_destroyed_object_knowers; GetEmpireIdsToSerialize( filtered_empire_ids, Universe::s_encoding_empire); GetObjectsToSerialize( filtered_objects, Universe::s_encoding_empire); GetEmpireKnownObjectsToSerialize( filtered_empire_known_objects, Universe::s_encoding_empire); + GetDamagedObjectsToSerialize( filtered_damaged_object_ids, Universe::s_encoding_empire); GetDestroyedObjectsToSerialize( filtered_destroyed_object_ids, Universe::s_encoding_empire); GetDestroyedObjectKnowersToSerialize( filtered_destroyed_object_knowers, Universe::s_encoding_empire); @@ -67,6 +70,7 @@ & BOOST_SERIALIZATION_NVP(filtered_empire_ids) & BOOST_SERIALIZATION_NVP(filtered_objects) & BOOST_SERIALIZATION_NVP(filtered_empire_known_objects) + & BOOST_SERIALIZATION_NVP(filtered_damaged_object_ids) & BOOST_SERIALIZATION_NVP(filtered_destroyed_object_ids) & BOOST_SERIALIZATION_NVP(filtered_destroyed_object_knowers); } @@ -78,6 +82,7 @@ & BOOST_SERIALIZATION_NVP(empire_ids) & BOOST_SERIALIZATION_NVP(objects) & BOOST_SERIALIZATION_NVP(empire_known_objects) + & BOOST_SERIALIZATION_NVP(damaged_object_ids) & BOOST_SERIALIZATION_NVP(destroyed_object_ids) & BOOST_SERIALIZATION_NVP(destroyed_object_knowers); } |