From: <geo...@us...> - 2014-01-23 23:12:59
|
Revision: 6666 http://sourceforge.net/p/freeorion/code/6666 Author: geoffthemedio Date: 2014-01-23 23:12:56 +0000 (Thu, 23 Jan 2014) Log Message: ----------- Give object to empire Order. Modified Paths: -------------- trunk/FreeOrion/util/Order.cpp trunk/FreeOrion/util/Order.h trunk/FreeOrion/util/SerializeOrderSet.cpp Modified: trunk/FreeOrion/util/Order.cpp =================================================================== --- trunk/FreeOrion/util/Order.cpp 2014-01-23 23:12:02 UTC (rev 6665) +++ trunk/FreeOrion/util/Order.cpp 2014-01-23 23:12:56 UTC (rev 6666) @@ -54,7 +54,6 @@ bool Order::UndoImpl() const { return false; } - //////////////////////////////////////////////// // RenameOrder //////////////////////////////////////////////// @@ -107,7 +106,6 @@ obj->Rename(m_name); } - //////////////////////////////////////////////// // CreateFleetOrder //////////////////////////////////////////////// @@ -208,7 +206,6 @@ system->StateChangedSignal(); } - //////////////////////////////////////////////// // FleetMoveOrder //////////////////////////////////////////////// @@ -328,7 +325,6 @@ fleet->SetRoute(route_list); } - //////////////////////////////////////////////// // FleetTransferOrder //////////////////////////////////////////////// @@ -417,7 +413,6 @@ target_fleet->AddShips(validated_ship_ids); } - //////////////////////////////////////////////// // ColonizeOrder //////////////////////////////////////////////// @@ -529,7 +524,6 @@ return true; } - //////////////////////////////////////////////// // InvadeOrder //////////////////////////////////////////////// @@ -630,7 +624,6 @@ return true; } - //////////////////////////////////////////////// // BombardOrder //////////////////////////////////////////////// @@ -723,7 +716,6 @@ return true; } - //////////////////////////////////////////////// // DeleteFleetOrder //////////////////////////////////////////////// @@ -762,7 +754,6 @@ GetUniverse().Destroy(FleetID()); } - //////////////////////////////////////////////// // ChangeFocusOrder //////////////////////////////////////////////// @@ -1141,3 +1132,50 @@ fleet->SetAggressive(m_aggression); } } + +///////////////////////////////////////////////////// +// GiveObjectToEmpireOrder +///////////////////////////////////////////////////// +GiveObjectToEmpireOrder::GiveObjectToEmpireOrder() : + Order(), + m_object_id(INVALID_OBJECT_ID), + m_recipient_empire_id(ALL_EMPIRES) +{} + +GiveObjectToEmpireOrder::GiveObjectToEmpireOrder(int empire, int object_id, int recipient) : + Order(), + m_object_id(INVALID_OBJECT_ID), + m_recipient_empire_id(ALL_EMPIRES) +{} + +void GiveObjectToEmpireOrder::ExecuteImpl() const { + ValidateEmpireID(); + int empire_id = EmpireID(); + + if (TemporaryPtr<Ship> ship = GetShip(m_object_id)) { + if (ship->OwnedBy(empire_id)) + ship->SetGiveToEmpire(m_recipient_empire_id); + } else if (TemporaryPtr<Planet> planet = GetPlanet(m_object_id)) { + if (planet->OwnedBy(empire_id)) + planet->SetGiveToEmpire(m_recipient_empire_id); + } +} + +bool GiveObjectToEmpireOrder::UndoImpl() const { + ValidateEmpireID(); + int empire_id = EmpireID(); + + if (TemporaryPtr<Ship> ship = GetShip(m_object_id)) { + if (ship->OwnedBy(empire_id)) { + ship->ClearGiveToEmpire(); + return true; + } + } else if (TemporaryPtr<Planet> planet = GetPlanet(m_object_id)) { + if (planet->OwnedBy(empire_id)) { + planet->ClearGiveToEmpire(); + return true; + } + } + return false; +} + Modified: trunk/FreeOrion/util/Order.h =================================================================== --- trunk/FreeOrion/util/Order.h 2014-01-23 23:12:02 UTC (rev 6665) +++ trunk/FreeOrion/util/Order.h 2014-01-23 23:12:56 UTC (rev 6666) @@ -628,6 +628,44 @@ void serialize(Archive& ar, const unsigned int version); }; + +///////////////////////////////////////////////////// +// GiveObjectToEmpireOrder +///////////////////////////////////////////////////// +/** the Order subclass that represents giving control of a ship to + * another empire */ +class FO_COMMON_API GiveObjectToEmpireOrder : public Order { +public: + /** \name Structors */ //@{ + GiveObjectToEmpireOrder(); + GiveObjectToEmpireOrder(int empire, int object_id, int recipient); + //@} + + /** \name Accessors */ //@{ + int ObjectID() const { return m_object_id; } ///< returns ID of object selected in this order + int RecipientEmpireID() { return m_recipient_empire_id; } ///< returns ID of empire to which object is given + //@} + +private: + /** + * Preconditions: + * - m_object_id must be the ID of an object owned by issuing empire + * - m_recipient_empire_id must be the ID of another empire + * + * Postconditions: + * - the object's ownership is set to the other empire + */ + virtual void ExecuteImpl() const; + virtual bool UndoImpl() const; + + int m_object_id; + int m_recipient_empire_id; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); +}; + // Note: *::serialize() implemented in SerializeOrderSet.cpp. #endif // _Order_h_ Modified: trunk/FreeOrion/util/SerializeOrderSet.cpp =================================================================== --- trunk/FreeOrion/util/SerializeOrderSet.cpp 2014-01-23 23:12:02 UTC (rev 6665) +++ trunk/FreeOrion/util/SerializeOrderSet.cpp 2014-01-23 23:12:56 UTC (rev 6666) @@ -169,6 +169,14 @@ & BOOST_SERIALIZATION_NVP(m_aggression); } +template <class Archive> +void GiveObjectToEmpireOrder::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Order) + & BOOST_SERIALIZATION_NVP(m_object_id) + & BOOST_SERIALIZATION_NVP(m_recipient_empire_id); +} + void Serialize(freeorion_oarchive& oa, const OrderSet& order_set) { oa << BOOST_SERIALIZATION_NVP(order_set); } |