1 #ifndef _EmpireManager_h_
2 #define _EmpireManager_h_
3 
4 #include "Diplomacy.h"
5 #include "../universe/EnumsFwd.h"
6 #include "../util/Export.h"
7 #include "../util/Serialize.h"
8 
9 #include <GG/Clr.h>
10 
11 #include <boost/filesystem.hpp>
12 #include <boost/serialization/access.hpp>
13 #include <boost/signals2/signal.hpp>
14 
15 #include <map>
16 #include <set>
17 #include <string>
18 #include <vector>
19 
20 class Empire;
21 class UniverseObject;
22 
23 /** Maintains all of the Empire objects that exist in the application. */
24 class FO_COMMON_API EmpireManager {
25 public:
26     /// Iterator over Empires
27     typedef std::map<int, Empire*>::iterator iterator;
28 
29     /// Const Iterator over Empires
30     typedef std::map<int, Empire*>::const_iterator const_iterator;
31 
32     /** \name Structors */ //@{
33     EmpireManager();
34     virtual ~EmpireManager();
35 
36     const EmpireManager& operator=(EmpireManager& rhs); ///< assignment operator (move semantics)
37     //@}
38 
39     /** \name Accessors */ //@{
40     /** Returns the empire whose ID is \a ID, or 0 if none exists. */
41     const Empire*       GetEmpire(int id) const;
42     /** Return the empire source or nullptr if the empire or source doesn't exist.*/
43     std::shared_ptr<const UniverseObject> GetSource(int id) const;
44     const std::string&  GetEmpireName(int id) const;
45 
46     const_iterator      begin() const;
47     const_iterator      end() const;
48 
49     int                 NumEmpires() const;
50     int                 NumEliminatedEmpires() const;
51 
52     DiplomaticStatus            GetDiplomaticStatus(int empire1, int empire2) const;
53     std::set<int>               GetEmpireIDsWithDiplomaticStatusWithEmpire(int empire_id,
54                                                                            DiplomaticStatus diplo_status) const;
55     bool                        DiplomaticMessageAvailable(int sender_id, int recipient_id) const;
56     const DiplomaticMessage&    GetDiplomaticMessage(int sender_id, int recipient_id) const;
57 
58     std::string         Dump() const;
59     //@}
60 
61     /** \name Mutators */ //@{
62     /** Returns the empire whose ID is \a id, or 0 if none exists. */
63     Empire*     GetEmpire(int id);
64 
65     iterator    begin();
66     iterator    end();
67 
68     void        BackPropagateMeters();
69 
70     void        SetDiplomaticStatus(int empire1, int empire2, DiplomaticStatus status);
71     void        HandleDiplomaticMessage(const DiplomaticMessage& message);
72     void        SetDiplomaticMessage(const DiplomaticMessage& message);
73     void        RemoveDiplomaticMessage(int sender_id, int recipient_id);
74 
75     void        ResetDiplomacy();
76 
77     /** Creates and inserts an empire with the specified properties and returns
78       * a pointer to it.  This will only set up the data in Empire.  It is the
79       * caller's responsibility to make sure that universe updates planet
80       * ownership. */
81     Empire*     CreateEmpire(int empire_id, const std::string& name, const std::string& player_name,
82                              const GG::Clr& color, bool authenticated);
83 
84     /** Removes and deletes all empires from the manager. */
85     void        Clear();
86     //@}
87 
88     typedef boost::signals2::signal<void (int, int)>  DiploSignalType;
89 
90     mutable DiploSignalType DiplomaticStatusChangedSignal;
91     mutable DiploSignalType DiplomaticMessageChangedSignal;
92 
93 private:
94     std::string DumpDiplomacy() const;
95 
96     /** Adds the given empire to the manager. */
97     void        InsertEmpire(Empire* empire);
98     void        GetDiplomaticMessagesToSerialize(std::map<std::pair<int, int>, DiplomaticMessage>& messages,
99                                                  int encoding_empire) const;
100 
101     std::map<int, Empire*>                          m_empire_map;
102     std::map<std::pair<int, int>, DiplomaticStatus> m_empire_diplomatic_statuses;
103     std::map<std::pair<int, int>, DiplomaticMessage>m_diplomatic_messages;
104 
105     friend class ClientApp;
106     friend class ServerApp;
107 
108     friend class boost::serialization::access;
109     template <typename Archive>
110     void serialize(Archive& ar, const unsigned int version);
111 };
112 
113 extern template FO_COMMON_API void EmpireManager::serialize<freeorion_bin_oarchive>(freeorion_bin_oarchive&, const unsigned int);
114 extern template FO_COMMON_API void EmpireManager::serialize<freeorion_bin_iarchive>(freeorion_bin_iarchive&, const unsigned int);
115 extern template FO_COMMON_API void EmpireManager::serialize<freeorion_xml_oarchive>(freeorion_xml_oarchive&, const unsigned int);
116 extern template FO_COMMON_API void EmpireManager::serialize<freeorion_xml_iarchive>(freeorion_xml_iarchive&, const unsigned int);
117 
118 /** The colors that are available for use for empires in the game. */
119 FO_COMMON_API const std::vector<GG::Clr>& EmpireColors();
120 
121 /** Initialize empire colors from \p path */
122 FO_COMMON_API void InitEmpireColors(const boost::filesystem::path& path);
123 
124 #endif // _EmpireManager_h_
125