Emergency 20 Dokumentation  4.2.0
VehicleComponent.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 
18 
19 //[-------------------------------------------------------]
20 //[ Forward declarations ]
21 //[-------------------------------------------------------]
22 namespace em5
23 {
24  class FreeplayEvent;
25 }
26 namespace qsf
27 {
28  class Map;
29  class Entity;
30  class Prototype;
31  class LinkComponent;
32 }
33 
34 
35 //[-------------------------------------------------------]
36 //[ Namespace ]
37 //[-------------------------------------------------------]
38 namespace em5
39 {
40 
41 
42  //[-------------------------------------------------------]
43  //[ Classes ]
44  //[-------------------------------------------------------]
50  {
51 
52 
53  //[-------------------------------------------------------]
54  //[ Public definitions ]
55  //[-------------------------------------------------------]
56  public:
57  static const uint32 COMPONENT_ID;
58 
59  // Door categories
60  static const uint32 CATEGORY_PASSENGER;
61  static const uint32 CATEGORY_PERSONNEL;
62  static const uint32 CATEGORY_VEHICLE;
63 
64  typedef std::vector<uint64> EntityIdArray;
65  typedef boost::container::flat_map<DoorComponent::DoorType, std::vector<uint64>> DoorMap;
66 
67 
68  //[-------------------------------------------------------]
69  //[ Public methods ]
70  //[-------------------------------------------------------]
71  public:
79  inline explicit VehicleComponent(qsf::Prototype* prototype);
80 
85  inline virtual ~VehicleComponent();
86 
91  inline uint64 getSpecialEntity() const;
92  void setSpecialEntity(uint64 specialEntityId);
93 
98  inline DoorComponent::DoorType getMainDoorType() const;
99  void setMainDoorType(DoorComponent::DoorType mainDoorType);
100 
101  //[-------------------------------------------------------]
102  //[ Doors ]
103  //[-------------------------------------------------------]
113  void openDoor(DoorComponent::DoorType doorType, bool open);
114 
124  bool areAllDoorsOfTypeInState(DoorComponent::DoorType doorType, DoorComponent::DoorState doorState, float percent = 1.0f) const;
125 
126  bool getFirstDoorTransformByType(uint32 doorType, qsf::Transform& outDoorTransform) const;
127 
128  qsf::Entity* findNearestDoor(DoorComponent::DoorType doorType, const glm::vec3& targetPoint) const;
129 
130  inline const std::vector<uint64>& getVehicleDoors() const;
131 
132  const std::vector<uint64>& getVehicleDoorIdsByType(DoorComponent::DoorType doorType) const;
133  uint64 getDriverVehicleDoorId() const;
134 
135  void closeAllDoors();
136 
137  //[-------------------------------------------------------]
138  //[ Gameplay ]
139  //[-------------------------------------------------------]
144  void personsFleeFromFire(bool allowSpawning);
145 
150  void trapPersons(FreeplayEvent* freeplayEvent = nullptr, const std::vector<uint32>& injuryPool = std::vector<uint32>());
151 
152  //[-------------------------------------------------------]
153  //[ Damage ]
154  //[-------------------------------------------------------]
159  inline float getLifeEnergy() const;
160 
165  void applyDamage(float damageValue, FreeplayEvent* freeplayEvent = nullptr);
166 
171  bool canBeRepaired() const;
172 
177  inline bool isMovable() const;
178 
183  bool getCanBeCut() const;
184 
189  void setCanBeCut(bool canBeCut, FreeplayEvent* freeplayEvent = nullptr);
190 
195  void setCanBeRepaired(bool canBeRepaired, FreeplayEvent* freeplayEvent = nullptr);
196 
201  qsf::Time getCutDuration() const;
202 
207  void setCutDuration(const qsf::Time& duration);
208 
213  inline bool getCanBeTowed() const;
214 
219  inline bool getCanBeTowedFlag() const;
220 
225  void setCanBeTowed(bool canBeTowed, FreeplayEvent* freeplayEvent = nullptr);
226 
231  inline bool getCanReallyNotBeTowed() const;
232 
237  void setCanReallyNotBeTowed(bool canReallyNotBeTowed, FreeplayEvent* freeplayEvent = nullptr);
238 
243  inline bool getMustBeRecovered() const;
244 
249  void setMustBeRecovered(bool mustBeRecovered, FreeplayEvent* freeplayEvent = nullptr);
250 
251  void hideParticleChildrenAtMapSave();
252 
257  bool isInvincible() const;
258  void setInvincible(bool invincible);
259 
260  inline bool getIsParkingEntity() const;
261  inline void setIsParkingEntity(bool isParkingEntity);
262 
267  void stopActions() const;
268 
269  void precalculateDoorsToEntitiesMap() const;
270 
271  //[-------------------------------------------------------]
272  //[ Resistances ]
273  //[-------------------------------------------------------]
278  const float getFireResistance() const;
279 
284  const float getDamageResistance() const;
285 
286  // Get the resistances as string
287  std::string getResistancesAsString() const;
288 
289  // Set the resistances by string
290  void setResistancesByString(const std::string& resistances);
291 
292  //[-------------------------------------------------------]
293  //[ Emergency operations ]
294  //[-------------------------------------------------------]
295  inline bool getIsOnEmergencyOperations() const;
296  inline void setIsOnEmergencyOperations(bool enable);
297 
298  inline const qsf::AssetProxy& getSignalAudioAsset() const;
299  inline void setSignalAudioAsset(const qsf::AssetProxy& signalSound);
300 
301  inline bool isSirenEnabled() const;
302  void setSirenEnabled(bool sirenEnabled);
303 
308  void playSirenOnce();
309  void playSirenLoop();
310  void stopSiren();
311  void stopSirenLoop();
312 
313  inline AudioProxy& getSirenSFX() { return mSirenSFX; }
314 
315 
316  //[-------------------------------------------------------]
317  //[ Public virtual methods ]
318  //[-------------------------------------------------------]
319  public:
320  virtual bool getDoorPositions(DoorComponent::DoorType doorType, std::vector<qsf::Transform>& outDoorTransform, const qsf::Transform& worldTransform) const;
321  virtual bool getDoorPosition(uint32 doorIndex, glm::vec3& outDoorPosition) const;
322 
323 
324  //[-------------------------------------------------------]
325  //[ Public virtual em5::DamageComponent methods ]
326  //[-------------------------------------------------------]
327  public:
328  virtual void receiveDamage(float amount, damagetype::DamageType damageType, qsf::Component* sender = nullptr) override;
329 
334  virtual bool isReadyForCleanup() const override;
335 
336 
337  //[-------------------------------------------------------]
338  //[ Public virtual qsf::Component methods ]
339  //[-------------------------------------------------------]
340  public:
341  virtual bool onStartup() override;
342  virtual void onShutdown() override;
343  virtual void onSetSimulating(bool simulating) override;
344  virtual void serialize(qsf::BinarySerializer& serializer) override;
345 
346 
347  //[-------------------------------------------------------]
348  //[ Protected virtual qsf::MovableObjectRenderingListener methods ]
349  //[-------------------------------------------------------]
350  protected:
351  virtual qsf::Component* getMovableObjectRenderingListenerComponent() override;
352  virtual void onObjectRenderingStartup() override;
353 
354 
355  //[-------------------------------------------------------]
356  //[ Protected virtual qsf::JobProxyMovableObjectRenderingListener methods ]
357  //[-------------------------------------------------------]
358  protected:
359  virtual void onUpdateMovableObjectRenderingJob(const qsf::JobArguments& jobArguments) override;
360 
361 
362  //[-------------------------------------------------------]
363  //[ Protected virtual em5::DamageComponent methods ]
364  //[-------------------------------------------------------]
365  protected:
366  virtual void onSetDamageState(DamageState damageState) override;
367  virtual void onSetIntact() override;
368  virtual void onSetDamagedLevel1() override;
369  virtual void onSetDamagedLevel2() override;
370  virtual void onSetDestroyed() override;
371  virtual void onSetFireLifePercentage(float fireLifePercentage) override;
372  virtual void onFireStarted(FreeplayEvent* freeplayEvent) override;
373  virtual void onFireStopped() override;
374  virtual void onExplosion(FireComponent* fireComponent) override;
375 
376 
377  //[-------------------------------------------------------]
378  //[ Protected virtual methods ]
379  //[-------------------------------------------------------]
380  protected:
381  virtual void restoreEntitiesFromPrefab(const qsf::Prototype& prototype, std::unordered_map<uint64, uint64>& prototypeIdMap);
382  virtual void initializePrefabClearComponentExceptions();
383 
384 
385  //[-------------------------------------------------------]
386  //[ Protected definitions ]
387  //[-------------------------------------------------------]
388  protected:
389  static std::vector<uint64> EMPTY_ENTITY_VECTOR;
390 
391 
392  //[-------------------------------------------------------]
393  //[ Protected methods ]
394  //[-------------------------------------------------------]
395  protected:
397  {
402  CAN_BE_REPAIRED
403  };
405 
406  inline InternalFlagSet& getInternalFlags();
407 
408 
409  //[-------------------------------------------------------]
410  //[ Protected methods ]
411  //[-------------------------------------------------------]
412  protected:
413  // Damage
414  void setVehiclePrefab(const qsf::AssetProxy& prefabAssetProxy);
415  void cloneEntitiesFromPrefabByComponentId(qsf::Map& map, const qsf::Entity& parentEntity, const std::vector<uint32>& componentIds, const qsf::LinkComponent& prototypeLinkComponent, std::unordered_map<uint64, uint64>& prototypeIdMap);
416  void cloneEntitiesFromPrefab(qsf::Map& map, const qsf::Entity& parentEntity, const std::vector<uint64>& sourceEntityIds, std::vector<uint64>& destinationEntityIds, const qsf::LinkComponent& prototypeLinkComponent, std::unordered_map<uint64, uint64>& prototypeIdMap);
417  void setDamageOverlaysActive(bool smutActive, bool emissiveActive);
418  void switchToDamagePrefab(bool prefabActive);
419  void switchFromCombinedToNormalPrefab();
420 
421 
422  //[-------------------------------------------------------]
423  //[ Protected data ]
424  //[-------------------------------------------------------]
425  protected:
426  EntityIdArray mVehicleDoorsIds;
427 
428  // Damage
429  std::vector<uint32> mComponentExceptionIds;
430 
431 
432  //[-------------------------------------------------------]
433  //[ Private methods ]
434  //[-------------------------------------------------------]
435  private:
436  // Helper
437  void updateHighlightJob(const qsf::JobArguments& arguments);
438 
439  // Damage
440  void applyDamageLevel1MaterialToIntactMesh(bool materialActive);
441 
442  // Mesh
443  void updateShaderHeatValue(float heat);
444 
445  // Hint
446  void showDamageHint(float oldLifeEnergy) const;
447 
448  // Life bar
449  void showHitpointBar();
450 
451  void playSirenInternal(bool loop);
452 
453 
454  //[-------------------------------------------------------]
455  //[ Private definitions ]
456  //[-------------------------------------------------------]
457  private:
458  enum VehiclePrefabState
459  {
460  VehiclePrefabState_Normal,
461  VehiclePrefabState_Destroyed,
462  VehiclePrefabState_Combined
463  };
464 
465 
466  //[-------------------------------------------------------]
467  //[ Private data ]
468  //[-------------------------------------------------------]
469  private:
470  EntityIdArray mDamagedLevel1ParticleIds;
471  EntityIdArray mDamagedLevel2ParticleIds;
472  EntityIdArray mDestroyedParticleIds;
473  mutable DoorMap mDoorTypeToEntityIdsMap;
474  qsf::Time mCutDuration;
475 
476  // Player vehicle logic
477  bool mIsOnEmergencyOperations;
478 
479  InternalFlagSet mInternalFlags;
480 
481  // Highlighting
482  qsf::JobProxy mHighlightJobProxy;
483 
484  // Damage
485  float mLifeEnergy;
486  bool mDamageLevel1MaterialActive;
487  bool mDamagePrefabActive;
488  std::string mPrefabLocalAssetName;
489  std::string mDamagePrefabLocalAssetName;
490  float mFireResistance;
491  float mDamageResistance;
492  bool mInvincible;
493  bool mIsParkingEntity;
494  VehiclePrefabState mCurrentPrefabState;
495 
496  // Siren sound
497  qsf::AssetProxy mSignalSound;
498  AudioProxy mSirenSFX;
499  bool mIsSirenEnabled;
500  bool mIsSirenSFXSet;
501 
502  // Special
503  uint64 mSpecialEntityId;
504  DoorComponent::DoorType mMainDoorType;
505 
506  // Rendering
507  float mSecondsPassedBetweenUpdates;
508 
509 
510  //[-------------------------------------------------------]
511  //[ CAMP reflection system ]
512  //[-------------------------------------------------------]
513  QSF_CAMP_RTTI() // Only adds the virtual method "campClassId()", nothing more
514 
515  public:
516  QSF_CAMP_ARRAY_INTERFACE_CLASS_WITH_VARIABLE(EntityIdArrayInterface, VehicleComponent, std::vector<uint64>, uint64);
517  EntityIdArrayInterface VehicleDoorsArray;
518  EntityIdArrayInterface DamagedLevel1Particles;
519  EntityIdArrayInterface DamagedLevel2Particles;
520  EntityIdArrayInterface DestroyedParticles;
521 
522 
523  };
524 
525 
526 //[-------------------------------------------------------]
527 //[ Namespace ]
528 //[-------------------------------------------------------]
529 } // em5
530 
531 
532 //[-------------------------------------------------------]
533 //[ Implementation ]
534 //[-------------------------------------------------------]
535 #include "em5/component/vehicle/VehicleComponent-inl.h"
536 
537 
538 //[-------------------------------------------------------]
539 //[ CAMP reflection system ]
540 //[-------------------------------------------------------]
542 QSF_CAMP_ARRAY_MAPPER_DEFINITION(em5::VehicleComponent::EntityIdArrayInterface)
Definition: ActionPriority.h:13
Job proxy class.
Definition: JobProxy.h:51
Abstract component class.
Definition: Component.h:105
Entity class.
Definition: Entity.h:46
static const uint32 CATEGORY_PASSENGER
"0" unique identifier for the passenger door category
Definition: VehicleComponent.h:60
Map class.
Definition: Map.h:93
DoorState
Definition: DoorComponent.h:54
unsigned int uint32
Definition: PlatformTypes.h:181
AudioProxy & getSirenSFX()
Definition: VehicleComponent.h:313
#define EM5_API_EXPORT
Definition: Export.h:28
Vehicle component base class.
Definition: VehicleComponent.h:49
Definition: AreaConfiguration.h:58
The vehicle can not be towed under any circumstances.
Definition: VehicleComponent.h:398
static const uint32 COMPONENT_ID
"em5::VehicleComponent" unique component ID
Definition: VehicleComponent.h:57
#define QSF_CAMP_ARRAY_INTERFACE_CLASS_WITH_VARIABLE(interfaceClassName, ownerType, variableType, elementType)
Definition: CampClass.h:241
EMERGENCY 5 fire component class.
Definition: FireComponent.h:64
std::vector< uint64 > EntityIdArray
Array of entity IDs.
Definition: VehicleComponent.h:64
uint64_t uint64
Definition: PlatformTypes.h:184
Has to be recovered by the crane vehicle before any other interaction.
Definition: VehicleComponent.h:401
Job arguments class: holds data to be passed to the called job method by the job manager.
Definition: JobArguments.h:40
Prototype container base class.
Definition: PrototypeContainer.h:52
std::vector< uint32 > mComponentExceptionIds
Definition: VehicleComponent.h:429
void serialize(BinarySerializer &serializer, BitFlagSet< STORAGE, ENUM > &bitFlagSet)
Definition: BitFlagSet.h:359
3D transform class
Definition: Transform.h:45
Definition: PickupPersonByParamedicAction.h:21
static std::vector< uint64 > EMPTY_ENTITY_VECTOR
Definition: VehicleComponent.h:389
QSF_CAMP_ARRAY_MAPPER_DEFINITION(qsf::ai::TrafficLightTimerComponent::ManagedTrafficLightList)
Asset proxy class.
Definition: AssetProxy.h:57
#define QSF_CAMP_RTTI()
Only adds the virtual method "campClassId()", nothing more.
Definition: CampClass.h:75
EMERGENCY 5 damage component class.
Definition: DamageComponent.h:49
Can be picked up by the tow car.
Definition: VehicleComponent.h:400
Extended audio proxy for easier multiplay usage.
Definition: AudioProxy.h:47
boost::container::flat_map< DoorComponent::DoorType, std::vector< uint64 > > DoorMap
Definition: VehicleComponent.h:65
DoorType
Definition: DoorComponent.h:63
#define QSF_CAMP_TYPE_NONCOPYABLE(type)
See "CAMP_TYPE_NONCOPYABLE" for details.
Definition: CampClass.h:112
InternalFlags
Definition: VehicleComponent.h:396
EntityIdArray mVehicleDoorsIds
Definition: VehicleComponent.h:426
Prototype class.
Definition: Prototype.h:100
qsf::EnumBitmask< uint8, InternalFlags > InternalFlagSet
Definition: VehicleComponent.h:404
Can be cut open with the fireman's rescue scissors.
Definition: VehicleComponent.h:399
DamageType
Definition: DamageType.h:20
Abstract EMERGENCY 5 freeplay event base class.
Definition: FreeplayEvent.h:66
static const uint32 CATEGORY_PERSONNEL
"1" unique identifier for the personnel door category
Definition: VehicleComponent.h:61
Binary serializer class.
Definition: BinarySerializer.h:35
static const uint32 CATEGORY_VEHICLE
"2" unique identifier for the vehicle door category – TODO(fw): What is this for actually...
Definition: VehicleComponent.h:62
Data type for encapsulating time information. It might represents points in time and time spans...
Definition: Time.h:32