1 #ifndef _ResourceCenter_h_
2 #define _ResourceCenter_h_
3 
4 #include "EnumsFwd.h"
5 #include <boost/signals2/signal.hpp>
6 #include <boost/serialization/nvp.hpp>
7 
8 #include "../util/Export.h"
9 
10 class Empire;
11 class Meter;
12 class UniverseObject;
13 
14 /** The ResourceCenter class is an abstract base class for anything in the
15   * FreeOrion gamestate that generates resources (minerals, etc.).  Most
16   * likely, such an object will also be a subclass of UniverseObject.
17   *
18   * Planet is the most obvious class to inherit ResourceCenter, but other
19   * classes could be made from it as well (e.g., a trade-ship or mining vessel,
20   * or a non-Planet UniverseObject- and PopCenter- derived object of some
21   * sort. */
22 class FO_COMMON_API ResourceCenter : virtual public std::enable_shared_from_this<UniverseObject> {
23 public:
24     /** \name Structors */ //@{
25     ResourceCenter();
26     ResourceCenter(const ResourceCenter& rhs);
27     virtual ~ResourceCenter();
28     //@}
29 
30     /** \name Accessors */ //@{
31     const std::string&              Focus() const;                                  ///< current focus to which this ResourceCenter is set
32     int                             TurnsSinceFocusChange() const;                  ///< number of turns since focus was last changed.
33     virtual std::vector<std::string>AvailableFoci() const;                          ///< focus settings available to this ResourceCenter
34     virtual const std::string&      FocusIcon(const std::string& focus_name) const; ///< icon representing focus with name \a focus_name for this ResourceCenter
35     std::string                     Dump(unsigned short ntabs = 0) const;
36 
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     /** the state changed signal object for this ResourceCenter */
40     mutable boost::signals2::signal<void ()> ResourceCenterChangedSignal;
41     //@}
42 
43     /** \name Mutators */ //@{
44     void Copy(std::shared_ptr<const ResourceCenter> copied_object, Visibility vis);
45     void Copy(std::shared_ptr<const ResourceCenter> copied_object);
46 
47     void SetFocus(const std::string& focus);
48     void ClearFocus();
49     void UpdateFocusHistory();
50 
51     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
52 
53     /** Resets the meters, etc. This should be called when a ResourceCenter is
54         wiped out due to starvation, etc. */
55     virtual void Reset();
56     //@}
57 
58 protected:
59     void Init();    ///< initialization that needs to be called by derived class after derived class is constructed
60 
61     void ResourceCenterResetTargetMaxUnpairedMeters();
62     void ResourceCenterClampMeters();
63 
64 private:
65     std::string m_focus;
66     int         m_last_turn_focus_changed;
67     std::string m_focus_turn_initial;
68     int         m_last_turn_focus_changed_turn_initial;
69 
70     virtual Visibility  GetVisibility(int empire_id) const = 0;         ///< implementation should return the visibility of this ResourceCenter for the empire with the specified \a empire_id
71     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
72 
73     friend class boost::serialization::access;
74     template <typename Archive>
75     void serialize(Archive& ar, const unsigned int version);
76 };
77 
78 // template implementations
79 template <typename Archive>
serialize(Archive & ar,const unsigned int version)80 void ResourceCenter::serialize(Archive& ar, const unsigned int version)
81 {
82     ar  & BOOST_SERIALIZATION_NVP(m_focus)
83         & BOOST_SERIALIZATION_NVP(m_last_turn_focus_changed)
84         & BOOST_SERIALIZATION_NVP(m_focus_turn_initial)
85         & BOOST_SERIALIZATION_NVP(m_last_turn_focus_changed_turn_initial);
86 }
87 
88 #endif // _ResourceCenter_h_
89