Emergency 20 Dokumentation  4.2.0
FreeplayEventFactory.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 //[-------------------------------------------------------]
13 #include "em5/Export.h"
14 
17 
18 #include <boost/property_tree/ptree.hpp> // TODO(co) Can we get rid of this heavy weighted include, please? (this does not mean just moving it to the cpp file while this header still has a real dependency)
19 
20 #include <vector>
21 
22 
23 //[-------------------------------------------------------]
24 //[ Forward declarations ]
25 //[-------------------------------------------------------]
26 namespace em5
27 {
28  class FreeplayEvent;
29  class FreeplayEventTriggerInfo;
30 }
31 namespace qsf
32 {
33  class Entity;
34  class Layer;
35 }
36 
37 
38 //[-------------------------------------------------------]
39 //[ Namespace ]
40 //[-------------------------------------------------------]
41 namespace em5
42 {
43 
44 
45  //[-------------------------------------------------------]
46  //[ Classes ]
47  //[-------------------------------------------------------]
57  {
58 
59 
60  //[-------------------------------------------------------]
61  //[ Friends ]
62  //[-------------------------------------------------------]
63  friend class FreeplayEventPoolManager; // May use the initialize method.
64 
65 
66  //[-------------------------------------------------------]
67  //[ Public definitions ]
68  //[-------------------------------------------------------]
69  public:
70  typedef std::vector<boost::property_tree::ptree> VariantArray;
71 
72 
73  //[-------------------------------------------------------]
74  //[ Public methods ]
75  //[-------------------------------------------------------]
76  public:
82 
87  virtual ~FreeplayEventFactory();
88 
93  inline uint32 getId() const;
94 
99  inline const std::string& getEventName() const;
100 
105  inline bool isEnabled() const;
106 
111  inline float getTriggerChance() const;
112 
117  inline void setTriggerChance(float triggerChance);
118 
123  inline float getEventDensity() const;
124 
129  inline void setEventDensity(float eventDensity);
130 
135  inline bool getStartEvent() const;
136 
141  inline void setStartEvent(bool startEvent);
142 
147  inline uint32 getMaxAppearances() const;
148 
153  inline void setMaxAppearances(uint32 maxAppearances);
154 
159  inline const std::string& getEventTag() const;
160 
165  inline void setEventTag(const std::string& eventTag);
166 
171  inline const VariantArray& getVariants() const;
172 
177  inline void setVariants(const VariantArray& variants);
178 
183  const boost::property_tree::ptree& getRandomVariant() const;
184 
189  const boost::property_tree::ptree& getMainVariant() const;
190 
195  const boost::property_tree::ptree& getVariantByIndex(uint32 index) const;
196 
201  inline bool operator ==(const FreeplayEventFactory& other) const;
202 
207  inline bool operator ==(const std::string& other) const;
208 
213  inline bool operator ==(uint32 other) const;
214 
222  FreeplayEvent* tryTriggerEvent(const FreeplayEventTriggerInfo& triggerInfo);
223 
224 
225  //[-------------------------------------------------------]
226  //[ Public virtual em5::FreeplayEventFactory methods ]
227  //[-------------------------------------------------------]
228  public:
229  virtual FreeplayEvent* tryTriggerEvent() = 0;
230 
231 
232  //[-------------------------------------------------------]
233  //[ Protected methods ]
234  //[-------------------------------------------------------]
235  protected:
236  template<typename T> T& createAndInitializeEvent();
237  FreeplayEvent& createAndInitializeEventByClassName(const std::string& className);
238 
239  void deserializeRandomFreeplayVariant(FreeplayEvent& freeplayEvent);
240  void deserializeFreeplayVariantByIndex(FreeplayEvent& freeplayEvent, uint32 index);
241 
242  bool isEventAlreadyRunning() const;
243 
244  // Only to be used inside "tryTriggerEvent", will throw an exception otherwise
245  const FreeplayEventTriggerInfo& getTriggerInfo() const;
246  void setTriggerFailReason(const std::string& reason) const;
247 
262  qsf::Layer* getCandidateEventLayer(const std::string& eventLayerName, const std::string& baseLayerName, const boost::function<bool(const qsf::Layer&)>& checkCandidateCallback) const;
263 
264 
265  //[-------------------------------------------------------]
266  //[ Private methods ]
267  //[-------------------------------------------------------]
268  private:
273  void initialize(const std::string& eventName);
274 
275  void initializeEventInstance(FreeplayEvent& freeplayEvent);
276 
277 
278  //[-------------------------------------------------------]
279  //[ Protected data ]
280  //[-------------------------------------------------------]
281  protected:
282  std::string mEventTag;
283 
284 
285  //[-------------------------------------------------------]
286  //[ Private data ]
287  //[-------------------------------------------------------]
288  private:
289  qsf::NamedIdentifier mName;
290  bool mIsEnabled;
291 
292  bool mStartEvent;
293  float mTriggerChance;
294  float mEventDensity;
295  uint32 mMaxAppearances;
296 
297  VariantArray mVariants;
298 
299  FreeplayEventTriggerInfo const* mTriggerInfo;
300 
301 
302  //[-------------------------------------------------------]
303  //[ CAMP reflection system ]
304  //[-------------------------------------------------------]
305  QSF_CAMP_RTTI() // Only adds the virtual method "campClassId()", nothing more
306 
307 
308  };
309 
310 
311 //[-------------------------------------------------------]
312 //[ Namespace ]
313 //[-------------------------------------------------------]
314 } // em5
315 
316 
317 //[-------------------------------------------------------]
318 //[ Implementation ]
319 //[-------------------------------------------------------]
321 
322 
323 //[-------------------------------------------------------]
324 //[ CAMP reflection system ]
325 //[-------------------------------------------------------]
Definition: ActionPriority.h:13
Object base class.
Definition: Object.h:68
Definition: FreeplayEventTriggerInfo.h:28
Layer class.
Definition: Layer.h:56
unsigned int uint32
Definition: PlatformTypes.h:181
#define EM5_API_EXPORT
Definition: Export.h:28
std::vector< boost::property_tree::ptree > VariantArray
Definition: FreeplayEventFactory.h:70
Definition: PickupPersonByParamedicAction.h:21
EMERGENCY 5 freeplay event pool manager.
Definition: FreeplayEventPoolManager.h:44
#define QSF_CAMP_RTTI()
Only adds the virtual method "campClassId()", nothing more.
Definition: CampClass.h:75
#define QSF_CAMP_TYPE_NONCOPYABLE(type)
See "CAMP_TYPE_NONCOPYABLE" for details.
Definition: CampClass.h:112
EMERGENCY 5 freeplay event factory base class.
Definition: FreeplayEventFactory.h:56
Definition: DensityCalculator.h:29
Class combining strings with their hashes.
Definition: NamedIdentifier.h:34
Abstract EMERGENCY 5 freeplay event base class.
Definition: FreeplayEvent.h:66
std::string mEventTag
Definition: FreeplayEventFactory.h:282