Emergency 20 Dokumentation  4.2.0
InhabitantSpawnComponent.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 //[-------------------------------------------------------]
14 
16 
17 
18 //[-------------------------------------------------------]
19 //[ Namespace ]
20 //[-------------------------------------------------------]
21 namespace em5
22 {
23 
24 
25  //[-------------------------------------------------------]
26  //[ Classes ]
27  //[-------------------------------------------------------]
35  {
36 
37 
38  //[-------------------------------------------------------]
39  //[ Public definitions ]
40  //[-------------------------------------------------------]
41  public:
42  static const uint32 COMPONENT_ID;
43  static const uint32 PERSON;
45  static const uint32 TIME_BEGIN;
46  static const uint32 TIME_END;
47 
48 
49  //[-------------------------------------------------------]
50  //[ Public methods ]
51  //[-------------------------------------------------------]
52  public:
53  explicit InhabitantSpawnComponent(qsf::Prototype* prototype);
54  virtual ~InhabitantSpawnComponent();
55 
56  virtual void serialize(qsf::BinarySerializer& serializer) override;
57 
58  // Returns true if the inhabitant person is allowed to be spawned.
59  bool allowSpawn(int currentMinuteOfDay) const;
60 
61  // Spawns the inhabitant if it has not been spawned already. Returns true if spawning succeeded.
62  bool spawnInhabitant();
63 
64  // Get / set the person to spawn.
66  const std::string& getPerson() const;
67  void setPerson(const std::string& personName);
69 
70  // Get / set the entity id of the destination the inhabitant is supposed to reach.
72  uint64 getDestinationEntityId() const;
73  void setDestinationEntityId(uint64 entityId);
75 
76  // The starting-time at which spawning is desired, x = hour in [0, 23]h range, y = minute in [0, 59]m range
78  glm::vec2 getTimeBegin() const;
79  void setTimeBegin(const glm::vec2& time);
81 
82  // The ending-time at which spawning is desired, x = hour in [0, 23]h range, y = minute in [0, 59]m range
84  glm::vec2 getTimeEnd() const;
85  void setTimeEnd(const glm::vec2& time);
87 
88  // Checks if the floatTime is valid (x = hour in [0, 23]h range, y = minute in [0, 59]m range)
89  static bool isValidFloatTime(const glm::vec2& floatTime);
90 
91  // Convert a glm::vec2 time to the corresponding minute-of-day or vice versa.
93  static int floatTimeToToMinuteOfDay(const glm::vec2& floatTime);
94  static glm::vec2 minuteOfDayToFloatTime(int minuteOfDay);
96 
97 
98  //[-------------------------------------------------------]
99  //[ Private methods ]
100  //[-------------------------------------------------------]
101  private:
102  // Calculates the real spawn time mTime to be a random value between mTimeBegin and mTimeEnd.
103  void updateSpawnTime();
104 
105 
106  //[-------------------------------------------------------]
107  //[ Private data ]
108  //[-------------------------------------------------------]
109  private:
110  // Connected to the CAMP reflection system
111  uint64 mDestinationEntityId;
112  int mTimeBegin;
113  int mTimeEnd;
114 
115  int mTime;
116  qsf::WeakPtr<qsf::Entity> mInhabitant;
117 
118 
119  QSF_CAMP_RTTI() // Only adds the virtual method "campClassId()", nothing more
120 
121 
122  };
123 
124 
125 //[-------------------------------------------------------]
126 //[ Namespace ]
127 //[-------------------------------------------------------]
128 } // em5
129 
130 
131 //[-------------------------------------------------------]
132 //[ Implementation ]
133 //[-------------------------------------------------------]
135 
136 
137 //[-------------------------------------------------------]
138 //[ CAMP reflection system ]
139 //[-------------------------------------------------------]
Definition: ActionPriority.h:13
unsigned int uint32
Definition: PlatformTypes.h:181
#define EM5_API_EXPORT
Definition: Export.h:28
static const uint32 DESTINATION_ENTITY_ID
"DestinationEntityId" unique class property ID inside the class
Definition: InhabitantSpawnComponent.h:44
uint64_t uint64
Definition: PlatformTypes.h:184
void serialize(BinarySerializer &serializer, BitFlagSet< STORAGE, ENUM > &bitFlagSet)
Definition: BitFlagSet.h:359
#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 entities can spawn from this point. It has a list of valid entities which can spawn from ...
Definition: SpawnPointComponent.h:49
static const uint32 TIME_BEGIN
"TimeBegin" unique class property ID inside the class
Definition: InhabitantSpawnComponent.h:45
Definition: InhabitantSpawnComponent.h:34
Prototype class.
Definition: Prototype.h:100
static const uint32 TIME_END
"TimeEnd" unique class property ID inside the class
Definition: InhabitantSpawnComponent.h:46
static const uint32 COMPONENT_ID
"em5::InhabitantSpawnComponent" unique component ID
Definition: InhabitantSpawnComponent.h:42
static const uint32 PERSON
"Person" unique class property ID inside the class
Definition: InhabitantSpawnComponent.h:43
Binary serializer class.
Definition: BinarySerializer.h:35