Emergency 20 Dokumentation  4.2.0
FreeplayEvent.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 //[-------------------------------------------------------]
17 
20 #include <qsf/base/WeakPtr.h>
21 #include <qsf/math/EnumBitmask.h>
24 
25 
26 //[-------------------------------------------------------]
27 //[ Forward declarations ]
28 //[-------------------------------------------------------]
29 namespace qsf
30 {
31  class Entity;
32  class BinarySerializer;
33  class Map;
34  class MessageParameters;
35  class DynamicMusicCompositorComponent;
36  class SoundTrackManager;
37 }
38 namespace em5
39 {
40  class EventIdComponent;
41  class Observer;
42  class MultiplayerDummyEvent;
43 }
44 
45 
46 //[-------------------------------------------------------]
47 //[ Namespace ]
48 //[-------------------------------------------------------]
49 namespace em5
50 {
51 
52 
53  //[-------------------------------------------------------]
54  //[ Classes ]
55  //[-------------------------------------------------------]
67  {
68 
69 
70  //[-------------------------------------------------------]
71  //[ Friends ]
72  //[-------------------------------------------------------]
73  friend class FreeplayEventManager; // May read and write event ID
74  friend class EventSpreading; // May change private data
75  friend class Observer; // May destroy observers
76  friend class HintHelper; // May use the hint data
77  friend class ObjectiveHelper; // May create objectives
78  friend class ObserverHelper; // May create observers
79  friend class EventIdComponent; // May access "insertEventId"
80  friend class MultiplayerDummyEvent; // Needs access to the mId member
81 
82 
83  //[-------------------------------------------------------]
84  //[ Public definitions ]
85  //[-------------------------------------------------------]
86  public:
88 
90  enum State
91  {
92  STATE_HIDDEN = 0,
95  STATE_FAILED
96  };
97 
99  enum class EventFlag
100  {
101  WORLD_EVENT,
102  MINI_EVENT
103  };
105 
106  // Shortcuts
108 
110  struct EventResult
111  {
112  std::string mEventName;
113  bool mSuccess = false;
114 
115  uint32 mPointGain = 0;
116 
117  uint32 mEfficiencyPoints = 0;
118  uint32 mObjectivePoints = 0;
119 
120  std::string mFailedText;
121 
122  boost::container::flat_map<std::string, uint32> mObjectiveNamesPoints;
123 
125 
126  uint32 mPlayerIndex = 0;
127  uint32 mEventId = 0;
128  };
129  typedef std::vector<uint64> EntityIdArray;
130 
132  {
135  };
136 
137  static const std::string MUSIC_LEVEL_LOW;
138  static const std::string MUSIC_LEVEL_HIGH;
139 
140  typedef boost::container::flat_map<std::string, int> ObjectivePoints;
141 
143  {
144  std::string hintId;
146  inline RecordedHintSystemMessage(const std::string& _hintId, HintMessage::MessageType _messageType) :
147  hintId(_hintId),
148  messageType(_messageType)
149  {};
150  };
151  typedef std::vector<RecordedHintSystemMessage> RecordedHintSystemMessages;
152 
153 
154  //[-------------------------------------------------------]
155  //[ Public methods ]
156  //[-------------------------------------------------------]
157  public:
162  FreeplayEvent();
163 
168  inline virtual ~FreeplayEvent();
169 
174  inline uint32 getId() const;
175 
180  inline const std::string& getEventName() const;
181 
186  inline void setEventName(const std::string& name);
187 
192  inline const qsf::NamedIdentifier& getEventFactoryName() const;
193 
198  inline void setEventFactoryName(const qsf::NamedIdentifier& factoryName);
199 
204  inline const EntityIdArray& getEntityIds() const;
205 
210  qsf::Entity* getRandomEventEntity() const;
211  qsf::Entity* getRandomVisibleEventEntity() const;
212 
217  inline const ObjectiveList& getObjectiveList() const;
218  const ObjectiveList& getObjectivesOrResultObjectives() const;
219 
224  inline qsf::Map& getMap();
225  inline const qsf::Map& getMap() const;
226 
231  int getObjectivePointByText(const std::string& objectiveText) const;
232 
240  int getObjectivePoints() const;
241 
249  inline const RecordedHintSystemMessages& getRecordedHintSystemMessages() const;
250 
251  //[-------------------------------------------------------]
252  //[ Lifecycle ]
253  //[-------------------------------------------------------]
258  bool startup();
259 
264  void shutdown();
265 
270  void setRunning();
271 
276  void setFinished(bool successful);
277 
282  void abortEvent();
283 
294  inline void setCanWinEvent(bool canWinEvent);
295 
300  inline bool getCanWinEvent() const;
301 
309  inline void setCanLoseEvent(bool canLoseEvent);
310 
315  inline bool getCanLoseEvent() const;
316 
317  void finishObjective(Objective& objective);
318 
319  //[-------------------------------------------------------]
320  //[ Update and time ]
321  //[-------------------------------------------------------]
326  void performUpdateFreeplayEvent(const qsf::Time& timePassed);
327 
332  void pauseEventTime();
333 
338  void resumeEventTime();
339 
344  inline qsf::Time getCurrentLifeTime() const;
345 
350  inline qsf::Time getCurrentRunningTime() const;
351 
352  //[-------------------------------------------------------]
353  //[ Point Gain ]
354  //[-------------------------------------------------------]
359  inline void setGreatJob(bool greatJob);
360 
365  inline uint32 getNormalPointGain() const;
366 
371  inline void setNormalPointGain(uint32 pointGain);
372 
377  inline uint32 getNormalCreditGain() const;
378 
383  inline void setNormalCreditGain(uint32 creditGain);
384 
389  inline uint32 getMultiplayerPointGain() const;
390 
395  inline void setMultiplayerPointGain(uint32 pointGain);
396 
401  QSF_DEFINE_SIMPLE_GETTER_AND_SETTER(MusicLevel, const std::string&, mMusicLevel)
402 
403 
407  QSF_DEFINE_FLAG_GETTER_AND_SETTER(IsWorldEvent, mEventFlags, EventFlag::WORLD_EVENT)
408  QSF_DEFINE_FLAG_GETTER_AND_SETTER(IsMiniEvent, mEventFlags, EventFlag::MINI_EVENT)
409 
414  QSF_DEFINE_SIMPLE_GETTER_AND_SETTER(Timeout, qsf::Time, mTimeout)
415 
416  //[-------------------------------------------------------]
417  //[ Event density ]
418  //[-------------------------------------------------------]
423  inline State getState() const;
424 
429  inline float getEventDensityIncrease() const;
430 
435  inline void setEventDensityIncrease(float eventDensityIncrease);
436 
444  inline float getEventDensity() const;
445 
450  inline void setEventDensity(float density);
451 
456  bool deserializeEventFromBoostPTree(const boost::property_tree::ptree& pTree, qsf::Object::SerializationMethod serializationMethod = qsf::Object::SERIALIZE_IGNORE_UNKNOWN);
457 
462  inline uint32 getPlayerIndex() const;
463 
468  void setPlayerIndex(uint32 playerIndex);
469 
470  //[-------------------------------------------------------]
471  //[ Event location ]
472  //[-------------------------------------------------------]
480  inline bool isEventLocationEntitySet() const;
481 
482  qsf::Entity* getEventLocationEntity() const;
483 
484  //[-------------------------------------------------------]
485  //[ Timeout ]
486  //[-------------------------------------------------------]
487  bool isTimeout(const qsf::Time& timePassed);
488 
489 
490  //[-------------------------------------------------------]
491  //[ Public virtual em5::FreeplayEvent methods ]
492  //[-------------------------------------------------------]
493  public:
498  virtual bool checkEventConfiguration() = 0;
499 
500  //[-------------------------------------------------------]
501  //[ Lifecycle ]
502  //[-------------------------------------------------------]
510  inline virtual bool onStartup();
511 
519  inline virtual void onShutdown();
520 
528  inline virtual void onRun();
529 
540  inline virtual bool onSuccess(EventResult& eventResult);
541 
549  virtual bool onFailure(EventResult& eventResult);
550 
551  //[-------------------------------------------------------]
552  //[ Points evaluation ]
553  //[-------------------------------------------------------]
558  virtual uint32 calculatePointGain(EventResult& eventResult);
559 
560  //[-------------------------------------------------------]
561  //[ Regular update ]
562  //[-------------------------------------------------------]
567  virtual void updateFreeplayEvent(const qsf::Time& timePassed) = 0;
568 
569  //[-------------------------------------------------------]
570  //[ Callbacks from observers ]
571  //[-------------------------------------------------------]
586  virtual bool addEntityToEvent(qsf::Entity& targetEntity, eventspreadreason::Reason eventSpreadReason, bool newReason);
587 
592  virtual void hintCallback(Observer& hintObserver);
593 
594  virtual void hintCallbackWithMessage(Observer& hintObserver, const qsf::MessageParameters& parameters);
595 
596  //[-------------------------------------------------------]
597  //[ Timers ]
598  //[-------------------------------------------------------]
599  inline virtual void onTimerTriggered(uint32 timerId) {}
600 
601  //[-------------------------------------------------------]
602  //[ Miscellaneous ]
603  //[-------------------------------------------------------]
609  virtual const qsf::Entity* getFocusEntity();
610 
611  //[-------------------------------------------------------]
612  //[ Serialize ]
613  //[-------------------------------------------------------]
618  virtual void serialize(qsf::BinarySerializer& serializer);
619 
620 
621  //[-------------------------------------------------------]
622  //[ Protected methods ]
623  //[-------------------------------------------------------]
624  protected:
625  //[-------------------------------------------------------]
626  //[ Objectives ]
627  //[-------------------------------------------------------]
632  Objective& addObjective(uint32 objectiveId, uint32 orderPriority = 100);
633 
638  Objective& addFailCondition(uint32 objectiveId, uint32 neededNumber, const std::string& objectiveText);
639 
644  inline ObjectiveList& getObjectives();
645 
650  void checkObjectivesState();
651 
652  //[-------------------------------------------------------]
653  //[ Fail reason ]
654  //[-------------------------------------------------------]
659  uint32 getFailReasonObjectiveTypeId(const ObjectiveList& objectives);
660 
661  //[-------------------------------------------------------]
662  //[ Hints ]
663  //[-------------------------------------------------------]
664  bool wasHintShown(const std::string& hintName) const;
665  void showHint(const std::string& hintName, bool notMoreThanOnce, bool textOnly = false);
666  void showSupervisorMessage(const std::string& messageId, bool audioOnly = false);
667  void markHintAsAlreadyShown(const std::string& hintName);
668 
669  //[-------------------------------------------------------]
670  //[ Observers ]
671  //[-------------------------------------------------------]
676  Observer& createObserverByTypeId(uint32 typeId, uint64 entityId, const std::string& name = std::string());
677 
682  template<typename T>
683  T& createObserver(uint64 entityId, const std::string& name = std::string());
684 
689  inline Observer& createGeneralObserverByTypeId(uint32 typeId, const std::string& name = std::string());
690 
695  template<typename T>
696  T& createGeneralObserver(const std::string& name = std::string());
697 
702  Observer* getObserverByTypeId(uint32 typeId, uint64 entityId);
703 
708  void removeObserver(Observer& observer);
709 
710  //[-------------------------------------------------------]
711  //[ Time ]
712  //[-------------------------------------------------------]
713  void informFreeplaySystemAboutBeFinished();
714 
715  //[-------------------------------------------------------]
716  //[ Event location ]
717  //[-------------------------------------------------------]
722  void createEventLocationEntity(qsf::Entity& entity);
723 
728  void createEventLocationEntity(const glm::vec3& position);
729 
730  //[-------------------------------------------------------]
731  //[ Music ]
732  //[-------------------------------------------------------]
733  qsf::DynamicMusicCompositorComponent& getDynamicMusicCompositor() const;
734 
735  //[-------------------------------------------------------]
736  //[ Special event types ]
737  //[-------------------------------------------------------]
738  // EM2016/2017 campaign mini-event
739  inline bool isMiniEvent() const;
740  void setFailHintsForMiniEvent(EventResult& eventResult, const std::string& failedText, const std::string& miniEventSupervisorMessage, const std::string& standardEventHint = "");
741 
742  //[-------------------------------------------------------]
743  //[ Timers ]
744  //[-------------------------------------------------------]
745  void startTimer(uint32 timerId, qsf::Time waitTime);
746  void setTimer(uint32 timerId, qsf::Time waitTime);
747  void cancelTimer(uint32 timerId);
748  void triggerTimer(uint32 timerId);
749 
750  //[-------------------------------------------------------]
751  //[ Debug ]
752  //[-------------------------------------------------------]
753  bool checkDebugButton(const std::string& buttonName);
754 
755 
756  //[-------------------------------------------------------]
757  //[ Private definitions ]
758  //[-------------------------------------------------------]
759  private:
760  typedef boost::container::flat_map<uint32, Observer*> ObserverMap;
761  typedef boost::container::flat_set<qsf::StringHash> HintIdSet;
762 
763 
764  //[-------------------------------------------------------]
765  //[ Private static methods ]
766  //[-------------------------------------------------------]
767  private:
772  static qsf::Time getCurrentGameTime();
773 
774 
775  //[-------------------------------------------------------]
776  //[ Private methods ]
777  //[-------------------------------------------------------]
778  private:
779  // For friend EventIdComponent
780  void insertEventId(EventIdComponent& eventIdComponent);
781  bool removeEventIdComponent(EventIdComponent& eventIdComponent);
782  void destroyEventIdComponent(EventIdComponent& eventIdComponent);
783 
784  // Internal
785  void onObserverDestroyed(Observer& observer);
786  void setObjectivePointsViaPTree(const boost::property_tree::ptree& pTree);
787 
795  void checkForFailedConditionOfUnavailableUnitsToWinEvent(qsf::Entity& incapacitatedEntity, const eventspreadreason::Reason& eventSpreadReason);
796  void handleWorldEventAchievements();
797 
798  void onGameTimerMessage(const qsf::MessageParameters& parameters);
799 
800 
801  //[-------------------------------------------------------]
802  //[ Private data ]
803  //[-------------------------------------------------------]
804  private:
805  uint32 mId;
806  std::string mEventName;
807  qsf::NamedIdentifier mEventFactoryName;
808  EventFlagSet mEventFlags;
809  State mState;
810  bool mCanWinEvent;
811  bool mCanLoseEvent;
812 
813  ObjectiveList mObjectives;
814  ObserverMap mObservers;
815  EntityIdArray mEntityIds;
816 
817  float mEventDensity;
818  float mEventDensityIncrease;
819 
820  bool mGreatJob;
821 
822  uint32 mNormalPointGain;
823  uint32 mMultiplayerPointGain;
824  uint32 mNormalCreditGain;
825 
826  ObjectivePoints mObjectivePoints;
827 
828  EventHintParameters mEventHintParameters;
829  HintIdSet mShownHintIdSet;
830  RecordedHintSystemMessages mRecordedHintSystemMessages;
831 
832  qsf::Time mLifeTime;
833  qsf::Time mRunningTime;
834  bool mTimeStopped;
835 
836  qsf::Map& mMap;
837  EventResult mEventResult;
838 
839  // Event location
840  qsf::WeakPtr<qsf::Entity> mEventLocationEntity;
841 
842  // Music
843  std::string mMusicLevel;
844 
845  // Timeout
846  qsf::Time mTimeout;
847 
848  // Timers
849  qsf::MessageProxy mGameTimerMessageProxy;
850  boost::container::flat_map<uint32, uint32> mGameTimerIdMap;
851 
852 
853  //[-------------------------------------------------------]
854  //[ CAMP reflection system ]
855  //[-------------------------------------------------------]
856  QSF_CAMP_RTTI() // Only adds the virtual method "campClassId()", nothing more
857 
858 
859  };
860 
861 
862 //[-------------------------------------------------------]
863 //[ Namespace ]
864 //[-------------------------------------------------------]
865 } // em5
866 
867 
868 //[-------------------------------------------------------]
869 //[ Implementation ]
870 //[-------------------------------------------------------]
872 
873 
874 //[-------------------------------------------------------]
875 //[ CAMP reflection system ]
876 //[-------------------------------------------------------]
static const std::string MUSIC_LEVEL_HIGH
Definition: FreeplayEvent.h:138
Definition: ActionPriority.h:13
Object base class.
Definition: Object.h:68
EMERGENCY 5 observer base class.
Definition: Observer.h:41
Definition: FreeplayEvent.h:110
Hint helper can create hint observers.
Definition: HintHelper.h:47
Entity class.
Definition: Entity.h:46
Message parameters class.
Definition: MessageParameters.h:34
Definition: DensityCalculator.h:24
Map class.
Definition: Map.h:93
std::string mEventName
Localizable name of the event (e.g. "EM5_EVENT_TITLE_04")
Definition: FreeplayEvent.h:112
unsigned int uint32
Definition: PlatformTypes.h:181
boost::container::flat_map< uint32, Objective * > ObjectiveInstanceMap
Definition: ObjectiveList.h:40
#define EM5_API_EXPORT
Definition: Export.h:28
boost::container::flat_map< std::string, uint32 > mObjectiveNamesPoints
Key: Name of the objective. Value: Point gain of the objective.
Definition: FreeplayEvent.h:122
SerializationMethod
Definition: Object.h:84
Message listener proxy class.
Definition: MessageProxy.h:47
Reason
Definition: EventSpreadReason.h:20
EMERGENCY 5 event ID component class.
Definition: EventIdComponent.h:34
ObjectiveList mObjectives
List of all objectives.
Definition: FreeplayEvent.h:124
uint64_t uint64
Definition: PlatformTypes.h:184
Definition: FreeplayEvent.h:131
Definition: FreeplayEvent.h:142
EMERGENCY 5 dummy event for multiplayer (used on client side)
Definition: MultiplayerDummyEvent.h:46
int objectivePoints
The total number of points for the objective.
Definition: FreeplayEvent.h:134
void serialize(BinarySerializer &serializer, BitFlagSet< STORAGE, ENUM > &bitFlagSet)
Definition: BitFlagSet.h:359
#define QSF_DEFINE_FLAG_GETTER_AND_SETTER(name, variable, flag)
Definition: PropertyHelper.h:24
Definition: FreeplayEvent.h:94
basic_ptree< std::string, std::string, std::less< std::string > > ptree
Definition: DensityCalculator.h:29
EMERGENCY 5 objective class.
Definition: Objective.h:51
Definition: PickupPersonByParamedicAction.h:21
Freeplay event hint parameters class.
Definition: EventHintParameters.h:35
EMERGENCY 5 objective helper class.
Definition: ObjectiveHelper.h:43
State
Definition: ProcessState.h:20
HintMessage::MessageType messageType
Definition: FreeplayEvent.h:145
#define QSF_CAMP_RTTI()
Only adds the virtual method "campClassId()", nothing more.
Definition: CampClass.h:75
Weak pointer target base class.
Definition: WeakPtr.h:318
uint32 objectiveId
Definition: FreeplayEvent.h:133
#define QSF_CAMP_TYPE_NONCOPYABLE(type)
See "CAMP_TYPE_NONCOPYABLE" for details.
Definition: CampClass.h:112
Definition: DensityCalculator.h:29
Observer helper can create observers.
Definition: ObserverHelper.h:30
std::string hintId
Definition: FreeplayEvent.h:144
Dynamic music core compositor.
Definition: DynamicMusicCompositorComponent.h:44
static const std::string MUSIC_LEVEL_LOW
Definition: FreeplayEvent.h:137
std::vector< uint64 > EntityIdArray
Definition: FreeplayEvent.h:129
qsf::EnumBitmask< uint8, EventFlag > EventFlagSet
Definition: FreeplayEvent.h:104
static const uint32 GAME_TIMER_MESSAGE_ID
"em5::FreeplayEvent_GameTimerMessage" unique message ID
Definition: FreeplayEvent.h:87
boost::container::flat_map< std::string, int > ObjectivePoints
Definition: FreeplayEvent.h:140
#define QSF_DEFINE_SIMPLE_GETTER_AND_SETTER(name, type, variable)
Definition: PropertyHelper.h:16
Class combining strings with their hashes.
Definition: NamedIdentifier.h:34
Definition: FreeplayEvent.h:93
ObjectiveList::ObjectiveInstanceMap ObjectiveInstanceMap
Definition: FreeplayEvent.h:107
EMERGENCY 5 freeplay event factory manager.
Definition: FreeplayEventManager.h:34
Static EMERGENCY 5 event spreading logic class.
Definition: EventSpreading.h:45
Abstract EMERGENCY 5 freeplay event base class.
Definition: FreeplayEvent.h:66
EventFlag
Definition: FreeplayEvent.h:99
EMERGENCY 5 objective list class.
Definition: ObjectiveList.h:32
RecordedHintSystemMessage(const std::string &_hintId, HintMessage::MessageType _messageType)
Definition: FreeplayEvent.h:146
std::vector< RecordedHintSystemMessage > RecordedHintSystemMessages
Definition: FreeplayEvent.h:151
MessageType
Definition: HintMessage.h:40
Binary serializer class.
Definition: BinarySerializer.h:35
State
Definition: FreeplayEvent.h:90
std::string mFailedText
The text, which should be shown on event failure.
Definition: FreeplayEvent.h:120
Data type for encapsulating time information. It might represents points in time and time spans...
Definition: Time.h:32