Emergency 20 Dokumentation  4.2.0
UnitPool.h
Go to the documentation of this file.
1 // Copyright (C) 2012-2018 Promotion Software GmbH
2 
3 
4 //[-------------------------------------------------------]
5 //[ Header guard ]
6 //[-------------------------------------------------------]
7 #pragma once
8 
9 
10 //[-------------------------------------------------------]
11 //[ Includes ]
12 //[-------------------------------------------------------]
15 
18 
19 #include <vector>
20 #include <unordered_map>
21 
22 
23 //[-------------------------------------------------------]
24 //[ Forward declarations ]
25 //[-------------------------------------------------------]
26 namespace qsf
27 {
28  class BinarySerializer;
29  class DebugDrawProxy;
30 }
31 namespace em5
32 {
33  class UnitPoolDefinition;
34  class OrderInfo;
35 }
36 
37 
38 //[-------------------------------------------------------]
39 //[ Namespace ]
40 //[-------------------------------------------------------]
41 namespace em5
42 {
43 
44 
45  //[-------------------------------------------------------]
46  //[ Classes ]
47  //[-------------------------------------------------------]
56  {
57 
58 
59  //[-------------------------------------------------------]
60  //[ Public methods ]
61  //[-------------------------------------------------------]
62  public:
67  UnitPool();
68 
73  virtual ~UnitPool();
74 
75  void setGameEdition(VersionSwitch::Edition gameEdition);
76 
77  void loadStartConfiguration();
78  void eraseAllRegisteredUnitsFromPool();
79 
80  bool hasUnit(const qsf::StringHash& identifier) const;
81 
82  void registerUnitInSpawn(const OrderInfo& orderInfo, int amount = 1);
83  void unregisterUnitInSpawn(const OrderInfo& orderInfo, int amount = 1);
84 
85  void registerUnitInMap(const OrderInfo& orderInfo, uint64 unitEntityId);
86  void unregisterUnitInMap(const OrderInfo& orderInfo, uint64 unitEntityId);
87 
88  void registerUnitBlocking(const OrderInfo& orderInfo, int amount = 1);
89  void unregisterAllUnitBlocking();
90 
91  // All together in every state
92  uint32 getNumberMaxAvailable(const OrderInfo& orderInfo) const;
93  uint32 getNumberMaxAvailableByName(const qsf::StringHash& identifier) const;
94 
95  // Between HQ and map (trying to find a place on the spawn)
96  bool isUnitAvailableInSpawn(const OrderInfo& orderInfo) const;
97  uint32 getNumberInSpawning(const OrderInfo& orderInfo) const;
98 
99  // Dead or otherwise blocked. Restored at the end of the day
100  uint32 getNumberBlocked(const OrderInfo& orderInfo) const;
101  uint32 getNumberBlockedByName(const qsf::StringHash& identifier) const;
102 
103  // Those can be ordered by the player
104  bool isUnitAvailableInHQ(const OrderInfo& orderInfo) const;
105  int getNumberInHQ(const OrderInfo& orderInfo) const;
106 
107  // InUse = on map
108  uint32 getNumberUnitsInUse(const OrderInfo& orderInfo) const;
109  uint32 getNumberUnitsInUseByName(const qsf::StringHash& identifier) const;
110  void getAllUnitsInUse(std::vector<uint64>& allUnitsInUse) const;
111  const std::vector<uint64>& getUnitsInUse(const OrderInfo& orderinfo) const;
112  const std::vector<uint64>& getUnitsInUseByName(const qsf::StringHash& identifier) const;
113 
114  void increaseNumberAvailable(const std::string& unitName, int amount);
115  void increaseLimitForBuying(const std::string& unitName, int amount);
116 
117  bool isBuyLimitReached(const OrderInfo& orderInfo) const;
118  bool isBuyLimitReached(const std::string& unitName) const;
119 
120  void getAllUnitOrderInfos(std::vector<const OrderInfo*>& outOrderInfos) const;
121  void getUnitOrderInfosByDepartment(units::Department, std::vector<const OrderInfo*>& outOrderInfos) const;
122  int getOriginalOrderIndexOfOrderInfoId(uint32 orderInfoId) const; // Negative if not found
123 
131  void replaceParamedicInUse(uint64 newSingleParamedicId, uint64 oldParamedicTeamId);
132 
138  void addAvailableUnitByName(const qsf::NamedIdentifier& unitName, uint32 unitCount, bool allowDuplicates);
139 
140  //[-------------------------------------------------------]
141  //[ Serialization ]
142  //[-------------------------------------------------------]
147  void loadFromDefinition(const UnitPoolDefinition& unitPoolDefinition);
148 
153  void serialize(qsf::BinarySerializer& serializer);
154 
155  //[-------------------------------------------------------]
156  //[ Debug ]
157  //[-------------------------------------------------------]
162  void addDebugOutput(qsf::DebugDrawProxy& debugDrawProxy);
163 
164 
165  //[-------------------------------------------------------]
166  //[ Private definitions ]
167  //[-------------------------------------------------------]
168  private:
169  struct OrderInfoDetail
170  {
171  int mUnitsAvailable;
172  int mUnitsLimitForBuying;
173  int mUnitsInSpawning;
174  int mUnitsBlocked;
175  std::vector<uint64> mUnitsInUse;
176 
177  OrderInfoDetail();
178  };
179  typedef std::unordered_map<uint32, OrderInfoDetail> OrderInfoDetailMap;
180  typedef std::vector<uint32> OrderInfoIdArray;
181 
182 
183  //[-------------------------------------------------------]
184  //[ Private methods ]
185  //[-------------------------------------------------------]
186  private:
187  OrderInfoDetail* getOrderInfoDetail(const OrderInfo& orderInfo);
188  const OrderInfoDetail* getOrderInfoDetail(const OrderInfo& orderInfo) const;
189 
190 
191  //[-------------------------------------------------------]
192  //[ Private data ]
193  //[-------------------------------------------------------]
194  private:
195  OrderInfoDetailMap mOrderInfoDetails;
196  OrderInfoIdArray mOrderInfoIdOriginalOrder;
197  VersionSwitch::Edition mGameEdition;
198 
199 
200  //[-------------------------------------------------------]
201  //[ CAMP reflection system ]
202  //[-------------------------------------------------------]
203  QSF_CAMP_RTTI() // Only adds the virtual method "campClassId()", nothing more
204 
205 
206  };
207 
208 
209 //[-------------------------------------------------------]
210 //[ Namespace ]
211 //[-------------------------------------------------------]
212 } // em5
213 
214 
215 //[-------------------------------------------------------]
216 //[ CAMP reflection system ]
217 //[-------------------------------------------------------]
Definition: ActionPriority.h:13
Object base class.
Definition: Object.h:68
Order information.
Definition: OrderInfo.h:54
unsigned int uint32
Definition: PlatformTypes.h:181
Department
Definition: Department.h:19
#define EM5_API_EXPORT
Definition: Export.h:28
uint64_t uint64
Definition: PlatformTypes.h:184
void serialize(BinarySerializer &serializer, BitFlagSet< STORAGE, ENUM > &bitFlagSet)
Definition: BitFlagSet.h:359
Definition: PickupPersonByParamedicAction.h:21
Definition: UnitPoolDefinition.h:30
Debug draw proxy class.
Definition: DebugDrawProxy.h:46
#define QSF_CAMP_RTTI()
Only adds the virtual method "campClassId()", nothing more.
Definition: CampClass.h:75
Keeps track of ordered units from the player and manages the ordering process for new units Spawning ...
Definition: UnitPool.h:55
#define QSF_CAMP_TYPE_NONCOPYABLE(type)
See "CAMP_TYPE_NONCOPYABLE" for details.
Definition: CampClass.h:112
Edition
Definition: VersionSwitch.h:41
Class combining strings with their hashes.
Definition: NamedIdentifier.h:34
Compile time string hash class.
Definition: StringHash.h:59
Binary serializer class.
Definition: BinarySerializer.h:35