Emergency 20 Dokumentation  4.2.0
RoadVehicleComponent.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 
17 
19 
20 #include <boost/container/flat_map.hpp>
21 
22 
23 //[-------------------------------------------------------]
24 //[ Forward declarations ]
25 //[-------------------------------------------------------]
26 namespace em5
27 {
28  class WaterCannonComponent;
29 }
30 namespace qsf
31 {
32  class MovableComponent;
33  class Prototype;
34 }
35 
36 
37 //[-------------------------------------------------------]
38 //[ Namespace ]
39 //[-------------------------------------------------------]
40 namespace em5
41 {
42 
43 
44  //[-------------------------------------------------------]
45  //[ Classes ]
46  //[-------------------------------------------------------]
55  {
56 
57 
58  //[-------------------------------------------------------]
59  //[ Public definitions ]
60  //[-------------------------------------------------------]
61  public:
62  static const uint32 COMPONENT_ID;
63  static const uint32 VEHICLE_WHEELS;
64  static const uint32 VEHICLE_LIGHTS;
65 
67  {
71  BLINKERS_BOTH_ON
72  };
73 
74 
75  //[-------------------------------------------------------]
76  //[ Public methods ]
77  //[-------------------------------------------------------]
78  public:
86  inline explicit RoadVehicleComponent(qsf::Prototype* prototype);
87 
92  inline virtual ~RoadVehicleComponent();
93 
94  inline void setFrontWheelDirection(float degrees);
95 
96  const std::vector<uint64>& getVehicleWheelIdsByType(WheelComponent::WheelType wheelType) const;
97 
98  const std::vector<uint64>& getVehicleLightIdsByType(qsf::game::LightControllerComponent::LightPosition lightPosition) const;
99 
104  void updateLightStates();
105  void setBlinkerState(BlinkerState blinkerState, bool force = false);
106  void setHeadLightState(bool enabled, bool force = false);
107  void setBrakeLightState(bool enabled, bool force = false);
108  void setBlueLightState(bool enabled, bool force = false);
109  void setEmergencyFlasher(bool enabled);
110 
111  inline bool getTooBigToTow() const;
112  inline void setTooBigToTow(bool tooBigToTow);
113 
114  inline bool getCanSpawnDriver() const;
115  inline void setCanSpawnDriver(bool canSpawnDriver);
116 
117  WaterCannonComponent* getWaterCannonComponent() const;
118 
123  void disableVehicleHydrants();
124 
125 
126  //[-------------------------------------------------------]
127  //[ Public virtual em5::DamageComponent methods ]
128  //[-------------------------------------------------------]
129  public:
130  virtual void onSetIntact() override;
131  virtual void onSetDamagedLevel1() override;
132  virtual void onSetDamagedLevel2() override;
133  virtual void onSetDestroyed() override;
134  virtual void onFireStarted(FreeplayEvent* freeplayEvent) override;
135  virtual void onExplosion(FireComponent* fireComponent) override;
136 
137 
138  //[-------------------------------------------------------]
139  //[ Public virtual qsf::Component methods ]
140  //[-------------------------------------------------------]
141  public:
142  virtual void serialize(qsf::BinarySerializer& serializer) override;
143 
144 
145  //[-------------------------------------------------------]
146  //[ Protected virtual qsf::Component methods ]
147  //[-------------------------------------------------------]
148  protected:
149  virtual bool onStartup() override;
150  virtual void onShutdown() override;
151  virtual void onSetSimulating(bool simulating) override;
152 
153 
154  //[-------------------------------------------------------]
155  //[ Protected virtual em5::VehicleComponent methods ]
156  //[-------------------------------------------------------]
157  protected:
158  virtual void restoreEntitiesFromPrefab(const qsf::Prototype& prototype, std::unordered_map<uint64, uint64>& prototypeIdMap) override;
159  virtual void initializePrefabClearComponentExceptions() override;
160 
161 
162  //[-------------------------------------------------------]
163  //[ Protected virtual qsf::MovableObjectRenderingListener methods ]
164  //[-------------------------------------------------------]
165  protected:
166  virtual void onObjectRenderingStartup() override;
167  virtual void onObjectRenderingShutdown() override;
168 
169 
170  //[-------------------------------------------------------]
171  //[ Protected virtual qsf::JobProxyMovableObjectRenderingListener methods ]
172  //[-------------------------------------------------------]
173  protected:
174  virtual void onUpdateMovableObjectRenderingJob(const qsf::JobArguments& jobArguments) override;
175 
176 
177  //[-------------------------------------------------------]
178  //[ Private definitions ]
179  //[-------------------------------------------------------]
180  private:
181  typedef std::vector<uint64> EntityIdArray;
182 
183 
184  //[-------------------------------------------------------]
185  //[ Private methods ]
186  //[-------------------------------------------------------]
187  private:
192  void sendRoadVehicleDamagedMessage();
193  void placeAllPassengerDeadAroundVehicle(FreeplayEvent* freeplayEvent);
194 
195  // Job updates
196  void registerSimulationJobProxy();
197  void updateSimulation(const qsf::JobArguments& jobArguments);
198 
199  // Wheels
200  void initializeWheel(uint64 entityId);
201  void updateWheels(const qsf::Time& timePassed);
202 
203  // Lights
204  void updateLightsList(const std::vector<uint64>& lightIds, const qsf::Time& timePassed, bool update, bool show = false, bool force = false);
205  void updateBrakeLightsState(const qsf::Time& timePassed);
206  bool checkBrakeLights();
207 
208  // Swinging
209  void checkSwing();
210  void updateSwingAnimation(const qsf::Time& timePassed);
211 
212  // Helper
213  void precalculateLightsToEntitiesMap() const;
214  void precalculateWheelsToEntitiesMap() const;
215 
216  bool checkEnvironmentForHeadlight();
217 
218 
219  //[-------------------------------------------------------]
220  //[ Private data ]
221  //[-------------------------------------------------------]
222  private:
223  // Weak pointers for important components inside the same entity
224  qsf::WeakPtr<qsf::MovableComponent> mMovableComponent;
225 
226  // Wheels
227  float mFrontWheelDirection;
228  EntityIdArray mVehicleWheelIds;
229  mutable boost::container::flat_map<WheelComponent::WheelType, std::vector<uint64>> mWheelTypeToEntityIdsMap;
230  float mChainAngle;
231 
232  // Lights
233  EntityIdArray mVehicleLightIds;
234  mutable boost::container::flat_map<qsf::game::LightControllerComponent::LightPosition, std::vector<uint64>> mLightTypeToEntityIdsMap;
235  mutable bool mLightTypeToEntityIdsMapInitialized;
236 
237  // Blinkers
238  BlinkerState mBlinkerState;
239  qsf::Time mBlinkerTime;
240 
241  // Blue lights
242  bool mBlueLightActive;
243  float mBlueLightTime;
244 
245  // Brake lights
246  bool mIsBrakeLightActive;
247  qsf::Time mBrakeLightTimeout;
248 
249  // Head lights
250  bool mIsHeadLightActive;
251 
252  // Special
253  uint64 mSpecialEntityId;
254  bool mIsCommandable;
255 
256  // Particles
257  EntityIdArray mStateDamagedParticleIds;
258  EntityIdArray mStateHeavilyDamagedParticleIds;
259  // TODO(mk) Remove explode particle from road vehicle
260  EntityIdArray mStateExplodedParticleIds;
261 
262  // Job proxies for regular update
263  qsf::JobProxy mSimulationJobProxy;
264 
265  // Swinging effect
266  qsf::Time mSwingTimeout;
267 
268  // Tow Car Help
269  bool mTooBigToTow;
270 
271  bool mCanSpawnDriver;
272 
273  qsf::DebugDrawProxy mDebugDrawProxy;
274 
275 
276  //[-------------------------------------------------------]
277  //[ CAMP reflection system ]
278  //[-------------------------------------------------------]
279  QSF_CAMP_RTTI() // Only adds the virtual method "campClassId()", nothing more
280 
281  public:
282  EntityIdArrayInterface VehicleWheelsArray;
283  EntityIdArrayInterface VehicleLightsArray;
284  EntityIdArrayInterface StateDamagedParticles;
285  EntityIdArrayInterface StateHeavilyDamagedParticles;
286  EntityIdArrayInterface StateExplodedParticles;
287 
288 
289  };
290 
291 
292 //[-------------------------------------------------------]
293 //[ Namespace ]
294 //[-------------------------------------------------------]
295 } // em5
296 
297 
298 //[-------------------------------------------------------]
299 //[ Implementation ]
300 //[-------------------------------------------------------]
301 #include "em5/component/vehicle/RoadVehicleComponent-inl.h"
302 
303 
304 //[-------------------------------------------------------]
305 //[ CAMP reflection system ]
306 //[-------------------------------------------------------]
Definition: ActionPriority.h:13
Job proxy class.
Definition: JobProxy.h:51
WheelType
Definition: WheelComponent.h:45
unsigned int uint32
Definition: PlatformTypes.h:181
static const uint32 COMPONENT_ID
"em5::RoadVehicleComponent" unique component ID
Definition: RoadVehicleComponent.h:62
#define EM5_API_EXPORT
Definition: Export.h:28
Vehicle component base class.
Definition: VehicleComponent.h:49
EMERGENCY 5 fire component class.
Definition: FireComponent.h:64
uint64_t uint64
Definition: PlatformTypes.h:184
Job arguments class: holds data to be passed to the called job method by the job manager.
Definition: JobArguments.h:40
void serialize(BinarySerializer &serializer, BitFlagSet< STORAGE, ENUM > &bitFlagSet)
Definition: BitFlagSet.h:359
Definition: PickupPersonByParamedicAction.h:21
Debug draw proxy class.
Definition: DebugDrawProxy.h:46
#define QSF_CAMP_RTTI()
Only adds the virtual method "campClassId()", nothing more.
Definition: CampClass.h:75
Definition: RoadVehicleComponent.h:70
#define QSF_CAMP_TYPE_NONCOPYABLE(type)
See "CAMP_TYPE_NONCOPYABLE" for details.
Definition: CampClass.h:112
Definition: RoadVehicleComponent.h:69
EMERGENCY 5 road vehicle component class.
Definition: RoadVehicleComponent.h:54
BlinkerState
Definition: RoadVehicleComponent.h:66
static const uint32 VEHICLE_WHEELS
"VehicleWheels" unique property ID
Definition: RoadVehicleComponent.h:63
Prototype class.
Definition: Prototype.h:100
static const uint32 VEHICLE_LIGHTS
"VehicleLights" unique property ID
Definition: RoadVehicleComponent.h:64
Abstract EMERGENCY 5 freeplay event base class.
Definition: FreeplayEvent.h:66
LightPosition
Definition: LightControllerComponent.h:50
Binary serializer class.
Definition: BinarySerializer.h:35
Definition: RoadVehicleComponent.h:68
EMERGENCY 5 water cannon component. Consists in a cannon part with this component and an optional can...
Definition: WaterCannonComponent.h:43
Data type for encapsulating time information. It might represents points in time and time spans...
Definition: Time.h:32