1 #ifndef _PopCenter_h_
2 #define _PopCenter_h_
3
4
5 #include "EnumsFwd.h"
6
7 #include <boost/serialization/nvp.hpp>
8
9 #include "../util/Export.h"
10
11 #include <memory>
12 #include <string>
13
14
15 class Meter;
16 class UniverseObject;
17
18 /** The PopCenter class is an abstract base class for anything in the FreeOrion
19 * gamestate that has population on or in it. Most likely, such an object
20 * will also be a subclass of UniverseObject.
21 * Planet is the most obvious class to inherit PopCenter, but other classes
22 * could be made from it as well (e.g., a ship that is large enough to support
23 * population and still travel between systems). */
24 class FO_COMMON_API PopCenter : virtual public std::enable_shared_from_this<UniverseObject> {
25 public:
26 /** \name Structors */ //@ {
27 PopCenter();
28 explicit PopCenter(const std::string& species_name);
29 virtual ~PopCenter();
30 //@}
31
32 /** \name Accessors */ //@ {
SpeciesName()33 const std::string& SpeciesName() const {return m_species_name;} ///< returns the name of the species that populates this planet
34 std::string Dump(unsigned short ntabs = 0) const;
35 bool Populated() const;
36 virtual Meter* GetMeter(MeterType type) = 0; ///< implementation should return the requested Meter, or 0 if no such Meter of that type is found in this object
37 virtual const Meter*GetMeter(MeterType type) const = 0; ///< implementation should return the requested Meter, or 0 if no such Meter of that type is found in this object
38 //@}
39
40 /** \name Mutators */ //@ {
41 void Copy(std::shared_ptr<const PopCenter> copied_object, Visibility vis);
42 void Copy(std::shared_ptr<const PopCenter> copied_object);
43 virtual void SetSpecies(const std::string& species_name); ///< sets the species of the population to \a species_name
44 virtual void Reset(); ///< sets all meters to 0, clears race name
45 virtual void Depopulate(); ///< removes population
46 //@}
47
48 protected:
49 void Init(); ///< initialization that needs to be called by derived class after derived class is constructed
50 void PopCenterResetTargetMaxUnpairedMeters();
51 void PopCenterClampMeters();
52 void PopCenterPopGrowthProductionResearchPhase();
53
54 private:
55 virtual void AddMeter(MeterType meter_type) = 0; ///< implementation should add a meter to the object so that it can be accessed with the GetMeter() functions
56
57 std::string m_species_name = ""; ///< the name of the species that occupies this planet
58
59 friend class boost::serialization::access;
60 template <typename Archive>
61 void serialize(Archive& ar, const unsigned int version);
62 };
63
64 // template implementations
65 template <typename Archive>
serialize(Archive & ar,const unsigned int version)66 void PopCenter::serialize(Archive& ar, const unsigned int version)
67 {
68 ar & BOOST_SERIALIZATION_NVP(m_species_name);
69 }
70
71 #endif // _PopCenter_h_
72
73
74