1 #ifndef _Ship_h_ 2 #define _Ship_h_ 3 4 #include "UniverseObject.h" 5 #include "Meter.h" 6 7 #include "../util/Export.h" 8 9 FO_COMMON_API extern const int ALL_EMPIRES; 10 FO_COMMON_API extern const int INVALID_DESIGN_ID; 11 FO_COMMON_API extern const int INVALID_GAME_TURN; 12 FO_COMMON_API extern const int BEFORE_FIRST_TURN; 13 FO_COMMON_API extern const int INVALID_OBJECT_ID; 14 class ShipDesign; 15 16 /** a class representing a single FreeOrion ship */ 17 class FO_COMMON_API Ship : public UniverseObject { 18 public: 19 typedef std::map<std::pair<MeterType, std::string>, Meter> PartMeterMap; 20 21 /** \name Accessors */ //@{ 22 bool HostileToEmpire(int empire_id) const override; 23 std::set<std::string> Tags() const override; 24 bool HasTag(const std::string& name) const override; 25 UniverseObjectType ObjectType() const override; 26 std::string Dump(unsigned short ntabs = 0) const override; 27 ContainerObjectID()28 int ContainerObjectID() const override 29 { return m_fleet_id; } 30 31 bool ContainedBy(int object_id) const override; 32 const std::string& PublicName(int empire_id) const override; 33 std::shared_ptr<UniverseObject> Accept(const UniverseObjectVisitor& visitor) const override; 34 35 /** Back propagates part meters (which UniverseObject equivalent doesn't). */ 36 void BackPropagateMeters() override; 37 38 void ResetTargetMaxUnpairedMeters() override; 39 void ResetPairedActiveMeters() override; 40 void ClampMeters() override; 41 42 /** Returns new copy of this Ship. */ 43 Ship* Clone(int empire_id = ALL_EMPIRES) const override; 44 45 void Copy(std::shared_ptr<const UniverseObject> copied_object, int empire_id = ALL_EMPIRES) override; 46 47 const ShipDesign* Design() const; ///< returns the design of the ship, containing engine type, weapons, etc. DesignID()48 int DesignID() const { return m_design_id; } ///< returns the design id of the ship 49 FleetID()50 int FleetID() const { return m_fleet_id; } ///< returns the ID of the fleet the ship is residing in 51 ProducedByEmpireID()52 int ProducedByEmpireID() const { return m_produced_by_empire_id; } ///< returns the empire ID of the empire that produced this ship ArrivedOnTurn()53 int ArrivedOnTurn() const { return m_arrived_on_turn; } ///< returns the turn on which this ship arrived in its current system LastResuppliedOnTurn()54 int LastResuppliedOnTurn() const{ return m_last_resupplied_on_turn;}///< returns the turn on which this ship was last resupplied / upgraded 55 56 bool IsMonster() const; 57 bool IsArmed() const; 58 bool HasFighters() const; 59 bool CanColonize() const; 60 bool HasTroops() const; 61 bool CanHaveTroops() const; 62 bool CanBombard() const; SpeciesName()63 const std::string& SpeciesName() const { return m_species_name; } 64 float Speed() const; 65 float ColonyCapacity() const; 66 float TroopCapacity() const; 67 OrderedScrapped()68 bool OrderedScrapped() const { return m_ordered_scrapped; } ///< returns true iff this ship has been ordered scrapped, or false otherwise OrderedColonizePlanet()69 int OrderedColonizePlanet() const { return m_ordered_colonize_planet_id; }///< returns the ID of the planet this ship has been ordered to colonize, or INVALID_OBJECT_ID if this ship hasn't been ordered to colonize a planet OrderedInvadePlanet()70 int OrderedInvadePlanet() const { return m_ordered_invade_planet_id; } ///< returns the ID of the planet this ship has been ordered to invade with ground troops, or INVALID_OBJECT_ID if this ship hasn't been ordered to invade a planet OrderedBombardPlanet()71 int OrderedBombardPlanet() const { return m_ordered_bombard_planet_id; } ///< returns the ID of the planet this ship has been ordered to bombard, or INVALID_OBJECT_ID if this ship hasn't been ordered to bombard a planet LastTurnActiveInCombat()72 int LastTurnActiveInCombat() const { return m_last_turn_active_in_combat; }///< returns the last turn this ship has been actively involved in combat 73 PartMeters()74 const PartMeterMap& PartMeters() const { return m_part_meters; } ///< returns this Ship's part meters 75 const Meter* GetPartMeter(MeterType type, const std::string& part_name) const; ///< returns the requested part Meter, or 0 if no such part Meter of that type is found in this ship for that part name 76 float CurrentPartMeterValue(MeterType type, const std::string& part_name) const; ///< returns current value of the specified part meter \a type for the specified part name 77 float InitialPartMeterValue(MeterType type, const std::string& part_name) const; ///< returns this turn's initial value for the specified part meter \a type for the specified part name 78 79 /** Returns sum of current value for part meter @p type of all parts with ShipPartClass @p part_class */ 80 float SumCurrentPartMeterValuesForPartClass(MeterType type, ShipPartClass part_class) const; 81 82 float TotalWeaponsDamage(float shield_DR = 0.0f, bool include_fighters = true) const; ///< versus an enemy with a given shields DR 83 float FighterCount() const; 84 float FighterMax() const; 85 std::vector<float> AllWeaponsDamage(float shield_DR = 0.0f, bool include_fighters = true) const; ///< any nonzero weapons strengths after adjustment versus an enemy with a given shields DR 86 std::vector<float> AllWeaponsMaxDamage(float shield_DR = 0.0f, bool include_fighters = true) const;///< any nonzero weapons strengths, assuming the shpi has been refueled recently, after adjustment versus an enemy with a given shields DR 87 //@} 88 89 /** \name Mutators */ //@{ 90 void SetFleetID(int fleet_id); ///< sets the ID of the fleet the ship resides in 91 void SetArrivedOnTurn(int turn); 92 93 void Resupply(); 94 95 void SetSpecies(const std::string& species_name); 96 97 void SetOrderedScrapped(bool b = true); ///< flags ship for scrapping 98 void SetColonizePlanet(int planet_id); ///< marks ship to colonize the indicated planet 99 void ClearColonizePlanet(); ///< marks ship to colonize no planets 100 void SetInvadePlanet(int planet_id); ///< marks ship to invade the indicated planet 101 void ClearInvadePlanet(); ///< marks ship to invade no planets 102 void SetBombardPlanet(int planet_id); ///< marks ship to bombard the indicated planet 103 void ClearBombardPlanet(); ///< marks ship to bombard no planets 104 SetLastTurnActiveInCombat(int turn)105 void SetLastTurnActiveInCombat(int turn) { m_last_turn_active_in_combat = turn; } ///< sets the last turn this ship was actively involved in combat 106 107 Meter* GetPartMeter(MeterType type, const std::string& part_name); ///< returns the requested Meter, or 0 if no such Meter of that type is found in this object 108 109 virtual void SetShipMetersToMax(); 110 //@} 111 112 protected: 113 friend class Universe; 114 115 /** \name Structors */ //@{ 116 Ship(); 117 118 public: 119 /** Create a ship from an @p empire_id, @p design_id, @p species_name and 120 @p production_by_empire_id. */ 121 Ship(int empire_id, int design_id, const std::string& species_name, 122 int produced_by_empire_id = ALL_EMPIRES); 123 124 protected: 125 template <typename T> friend void boost::python::detail::value_destroyer<false>::execute(T const volatile* p); 126 127 public: ~Ship()128 ~Ship() {} 129 //@} 130 131 private: 132 int m_design_id = INVALID_DESIGN_ID; 133 int m_fleet_id = INVALID_OBJECT_ID; 134 bool m_ordered_scrapped = false; 135 int m_ordered_colonize_planet_id = INVALID_OBJECT_ID; 136 int m_ordered_invade_planet_id = INVALID_OBJECT_ID; 137 int m_ordered_bombard_planet_id = INVALID_OBJECT_ID; 138 int m_last_turn_active_in_combat = INVALID_GAME_TURN; 139 PartMeterMap m_part_meters; 140 std::string m_species_name; 141 int m_produced_by_empire_id = ALL_EMPIRES; 142 int m_arrived_on_turn = INVALID_GAME_TURN; 143 int m_last_resupplied_on_turn = BEFORE_FIRST_TURN; 144 145 friend class boost::serialization::access; 146 template <typename Archive> 147 void serialize(Archive& ar, const unsigned int version); 148 }; 149 150 FO_COMMON_API std::string NewMonsterName(); 151 152 #endif // _Ship_h_ 153