Emergency 20 Dokumentation  4.2.0
FreeplayEventGenerator.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 
15 #include <qsf/time/Time.h>
17 
18 #include <boost/noncopyable.hpp>
19 
20 
21 //[-------------------------------------------------------]
22 //[ Forward declarations ]
23 //[-------------------------------------------------------]
24 namespace em5
25 {
26  class FreeplayEvent;
27  class FreeplayEventFactory;
28  class FreeplayEventTriggerInfo;
29 }
30 
31 
32 //[-------------------------------------------------------]
33 //[ Namespace ]
34 //[-------------------------------------------------------]
35 namespace em5
36 {
37 
38 
39  //[-------------------------------------------------------]
40  //[ Classes ]
41  //[-------------------------------------------------------]
46  class EM5_API_EXPORT FreeplayEventGenerator : public boost::noncopyable
47  {
48 
49 
50  //[-------------------------------------------------------]
51  //[ Friends ]
52  //[-------------------------------------------------------]
53  friend class FreeplaySystem; // May update the last triggered events
54  friend class FreeplayGameMode; // To update number of succeeded and failed events
55 
56 
57  //[-------------------------------------------------------]
58  //[ Public definitions ]
59  //[-------------------------------------------------------]
60  public:
61  typedef boost::function<bool(uint32)> EventIndexAllowedCallback;
62 
63 
64  //[-------------------------------------------------------]
65  //[ Public methods ]
66  //[-------------------------------------------------------]
67  public:
73 
79 
80  void startup();
81  void shutdown();
82 
83  void updateEventGeneration(const qsf::Time& timePassed);
84 
85  FreeplayEvent* triggerEvent(FreeplayEventFactory& factory, const FreeplayEventTriggerInfo& triggerInfo);
86 
91  float getUpperLimit() const;
92 
97  void setUpperLimit(float density);
98 
103  void setWaitTimeBetweenEvents(float mininumWaitTime, float maximumWaitTime);
104 
109  void setStartWaitTime(float mininumWaitTime, float maximumWaitTime);
110 
115  uint32 getUpperEventLimit() const;
116 
121  void setUpperEventLimit(uint32 maximumEventCount);
122 
123  uint32 getMaxEventLimit() const;
124 
125  bool isUsingForcedEventOrder() const;
126  void switchToForcedEventOrder(bool useForcedOrder, int32 lastEventIndex = -1);
127 
128  int32 getEventFactoryIndexById(uint32 factoryId) const;
129 
130  void setTriggerFailReason(const std::string& reason);
131 
132  //[-------------------------------------------------------]
133  //[ Serialize ]
134  //[-------------------------------------------------------]
135  void serialize(qsf::BinarySerializer& serializer);
136 
137 
138  //[-------------------------------------------------------]
139  //[ Private methods ]
140  //[-------------------------------------------------------]
141  private:
142  bool tryTriggerEvent();
143  bool triggerFromFactory(FreeplayEventFactory& factory);
144  bool wasFactoryRecentlyTriggered(FreeplayEventFactory& factory, uint32 numberOfRecentFactories) const;
145  FreeplayEventFactory* getNextForcedEventFactory();
146  void calculateNewWaitTime();
147 
148  std::string getEventGenerationDebugText() const;
149  void updateDebug();
150 
151 
152  //[-------------------------------------------------------]
153  //[ Private definitions ]
154  //[-------------------------------------------------------]
155  private:
156  typedef std::deque<std::string> FactoryDeque;
157  typedef boost::container::flat_map<uint32, uint32> CounterMap;
158 
159  struct TimeInterval
160  {
161  qsf::Time mMinimum;
162  qsf::Time mMaximum;
163  qsf::Time getRandomTime() const;
164  };
165 
166 
167  //[-------------------------------------------------------]
168  //[ Private data ]
169  //[-------------------------------------------------------]
170  private:
171  float mUpperDensityLimit;
172  qsf::Time mWaitTimeUntilNextEvent;
173  TimeInterval mWaitTimeBetweenEventsAtStart;
174  TimeInterval mWaitTimeBetweenEvents;
175  uint32 mCurrentEventLimit;
176  uint32 mMinEventLimit;
177  uint32 mMaxEventLimit;
178  bool mSelectOnlyEventsMarkedAsStartEvents;
179 
180  // Forced order mode
181  bool mForcedEventOrder;
182  int32 mLastEventIndex;
183 
184  // Statistics & information
185  const char* mLastTriedFactoryCampClassId;
186  CounterMap mTriggeredFactoryCounters;
187  FactoryDeque mLastTriggeredFactories;
188  uint32 mNumEventsTriggered;
189  uint32 mNumEventsSucceededInARow;
190  uint32 mNumEventsSucceededSinceCheck; // Not the total number
191  uint32 mNumEventsFailedSinceCheck; // Not the total number
192  uint32 mWonEventsForIncrease;
193  uint32 mWonEventsForNotDecrease; // Minimum number of events which have to be won, to not decrease the max event number when a second event is lost
194 
195  // Debug output
196  qsf::DebugDrawProxy mDebugDrawProxy;
197  std::string mLastTriggerFailReason;
198 
199 
200  };
201 
202 
203 //[-------------------------------------------------------]
204 //[ Namespace ]
205 //[-------------------------------------------------------]
206 } // em5
Definition: ActionPriority.h:13
boost::function< bool(uint32)> EventIndexAllowedCallback
Definition: FreeplayEventGenerator.h:61
Definition: FreeplayEventTriggerInfo.h:28
unsigned int uint32
Definition: PlatformTypes.h:181
#define EM5_API_EXPORT
Definition: Export.h:28
void serialize(BinarySerializer &serializer, BitFlagSet< STORAGE, ENUM > &bitFlagSet)
Definition: BitFlagSet.h:359
Debug draw proxy class.
Definition: DebugDrawProxy.h:46
EMERGENCY 5 freeplay event generation class.
Definition: FreeplayEventGenerator.h:46
EMERGENCY 5 freeplay event factory base class.
Definition: FreeplayEventFactory.h:56
signed int int32
Definition: PlatformTypes.h:180
Abstract EMERGENCY 5 freeplay event base class.
Definition: FreeplayEvent.h:66
EMERGENCY 5 freeplay game mode.
Definition: FreeplayGameMode.h:48
Binary serializer class.
Definition: BinarySerializer.h:35
EMERGENCY 5 freeplay system.
Definition: FreeplaySystem.h:55
Data type for encapsulating time information. It might represents points in time and time spans...
Definition: Time.h:32