1 #ifndef _CombatLogManager_h_
2 #define _CombatLogManager_h_
3 
4 #include "CombatSystem.h"
5 
6 #include "../util/Export.h"
7 #include "../util/Serialize.h"
8 
9 #include <boost/optional/optional.hpp>
10 #include <boost/serialization/nvp.hpp>
11 
12 #include <memory>
13 
14 
15 // A snapshot of the state of a participant of the combat
16 // at it's end
17 struct FO_COMMON_API CombatParticipantState {
18     float current_health = 0.0f;
19     float max_health = 0.0f;
20 
21     CombatParticipantState();
22     CombatParticipantState(const UniverseObject& object);
23 private:
24     friend class boost::serialization::access;
25     template <typename Archive>
26     void serialize(Archive& ar, const unsigned int version);
27 };
28 
29 struct FO_COMMON_API CombatLog {
30     CombatLog();
31     CombatLog(const CombatInfo& combat_info);
32 
33     int                         turn;
34     int                         system_id;
35     std::set<int>               empire_ids;
36     std::set<int>               object_ids;
37     std::set<int>               damaged_object_ids;
38     std::set<int>               destroyed_object_ids;
39     std::vector<CombatEventPtr> combat_events;
40     std::map<int, CombatParticipantState> participant_states;
41 
42     friend class boost::serialization::access;
43     template <typename Archive>
44     void serialize(Archive& ar, const unsigned int version);
45 };
46 
47 BOOST_CLASS_VERSION(CombatLog, 1);
48 
49 /** Stores and retreives combat logs. */
50 class FO_COMMON_API CombatLogManager {
51 public:
52     /** \name Accessors */ //@{
53     /** Return the requested combat log or boost::none.*/
54     boost::optional<const CombatLog&>  GetLog(int log_id) const;
55 
56     /** Return the ids of all incomplete logs or boost::none if they are all complete.*/
57     boost::optional<std::vector<int>> IncompleteLogIDs() const;
58     //@}
59 
60     /** \name Mutators */ //@{
61     int  AddNewLog(const CombatLog& log);   // adds log, returns unique log id
62     /** Replace incomplete log with \p id with \p log. An incomplete log is a
63         partially downloaded log where only the log id is known.*/
64     void CompleteLog(int id, const CombatLog& log);
65     void Clear();
66 
67     /** Serialize log headers so that the receiving LogManager can then request
68         complete logs in the background.*/
69     template <typename Archive>
70     void SerializeIncompleteLogs(Archive& ar, const unsigned int version);
71     //@}
72 
73     static CombatLogManager& GetCombatLogManager();
74 
75 private:
76     CombatLogManager();
77     ~CombatLogManager();
78 
79     class Impl;
80 
81     std::unique_ptr<Impl> const m_impl;
82 
83     friend class boost::serialization::access;
84     template <typename Archive>
85     void serialize(Archive& ar, const unsigned int version);
86 };
87 
88 
89 extern template
90 FO_COMMON_API void CombatLogManager::serialize<freeorion_bin_iarchive>(freeorion_bin_iarchive& ar, const unsigned int version);
91 extern template
92 FO_COMMON_API void CombatLogManager::serialize<freeorion_bin_oarchive>(freeorion_bin_oarchive& ar, const unsigned int version);
93 extern template
94 FO_COMMON_API void CombatLogManager::serialize<freeorion_xml_iarchive>(freeorion_xml_iarchive& ar, const unsigned int version);
95 extern template
96 FO_COMMON_API void CombatLogManager::serialize<freeorion_xml_oarchive>(freeorion_xml_oarchive& ar, const unsigned int version);
97 
98 
99 /** returns the singleton combat log manager */
100 FO_COMMON_API CombatLogManager& GetCombatLogManager();
101 
102 /** Returns the CombatLog with the indicated id, or an empty log if there
103   * is no avaiable log with that id. */
104 FO_COMMON_API boost::optional<const CombatLog&> GetCombatLog(int log_id);
105 
106 #endif // _CombatLogManager_h_
107