Emergency 20 Dokumentation  4.2.0
BuildingComponent.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/audio/AudioProxy.h"
16 
18 
21 #include <qsf/math/EnumBitmask.h>
25 
26 
27 //[-------------------------------------------------------]
28 //[ Forward declarations ]
29 //[-------------------------------------------------------]
30 namespace em5
31 {
32  class BuildingClippingManager;
33  class DoorComponent;
34  class FreeplayEvent;
35  namespace multiplayer
36  {
37  class BuildingData;
38  }
39 }
40 
41 
42 //[-------------------------------------------------------]
43 //[ Namespace ]
44 //[-------------------------------------------------------]
45 namespace em5
46 {
47 
48 
49  //[-------------------------------------------------------]
50  //[ Classes ]
51  //[-------------------------------------------------------]
57  {
58 
59 
60  //[-------------------------------------------------------]
61  //[ Friends ]
62  //[-------------------------------------------------------]
64  friend class BuildingClippingManager;
66 
67 
68  //[-------------------------------------------------------]
69  //[ Public definitions ]
70  //[-------------------------------------------------------]
71  public:
72  static const uint32 COMPONENT_ID;
73  static const uint32 CLIPPING_ENABLED;
74 
75 
76  //[-------------------------------------------------------]
77  //[ Public methods ]
78  //[-------------------------------------------------------]
79  public:
87  inline explicit BuildingComponent(qsf::Prototype* prototype);
88 
93  inline virtual ~BuildingComponent();
94 
105  inline bool getClippingEnabled() const;
106 
117  inline void setClippingEnabled(bool clippingEnabled);
118 
123  void onCaughtFire();
124 
132  void onStoppedFire(bool destroyed);
133 
138  bool letPersonWaveOutOfWindow(qsf::Entity& personEntity, FreeplayEvent* freeplayEvent, float chance = 1.0f);
139 
144  void stopPersonWaveOutOfWindow();
145 
153  qsf::Entity* getPersonWavingOutOfWindow() const;
154 
160  inline uint16 getSetupNumberOfTrappedPersons() const;
161 
167  inline uint16 getSetupNumberOfTrappedInjuredPersons() const;
168 
173  inline bool isPersonWavingOutOfWindow() const;
174 
186  bool isContainingTrappedPersons() const;
187  void setupTrappedPersons(uint16 minPersonCount, uint16 maxPersonCount, bool createPersons = true, const qsf::Time& rescueTime = qsf::Time::fromSeconds(300.0f));
188  void setupTrappedInjuredPersons(uint16 minHealthyPersonCount, uint16 maxHealthyPersonCount, uint16 minInjuredPersonCount, uint16 maxInjuredPersonCount, bool blockedDoor = true, bool createPersons = true, const qsf::Time& rescueTime = qsf::Time::fromSeconds(300.0f));
189 
190  bool isContainingGangsters() const;
191  bool isContainingHostages() const;
192 
198  void createTrappedPerson(FreeplayEvent& freeplayEvent);
199 
200  qsf::Time getRemainingTimeForTrappedPersons() const;
201 
206  void setTrappedPersonTimer(qsf::Time time);
207 
215  void untrapPersons();
216 
217  void untrapPerson_SingleInjured();
218  void untrapPersonsInternal(bool singleInjuredPerson);
219  bool untrapPersonInternal(qsf::Entity& personToUntrap, qsf::Time fleeWaitTime);
220  void updateIcons();
221 
229  glm::vec3 getDoorPosition() const;
230 
238  glm::quat getDoorRotation() const;
239 
247  qsf::Transform getDoorTransform() const;
248 
253  bool getWorldPositionInFrontOfDoor(float distance, glm::vec3& position, glm::quat& rotation) const;
254 
259  bool hasDoor() const;
260 
261  // Getters and setters for single entity slots
262  QSF_DEFINE_SIMPLE_GETTER_AND_SETTER(MainDoorId, uint64, mDoors.mMainDoorId);
263  QSF_DEFINE_SIMPLE_GETTER_AND_SETTER(EventWindowId, uint64, mEventWindowId);
264 
265  // Getter and setter for building explosion center (for the fake explosion for the event: fire after explosion in building)
266  QSF_DEFINE_SIMPLE_GETTER_AND_SETTER(ExplosionCenter, const glm::vec3&, mExplosionCenter);
267  glm::vec3 getExplosionCenterWorldSpacePosition() const;
268  void setExplosionCenterWorldSpacePosition(const glm::vec3& worldSpacePosition);
269 
270  // Evacuate feature
271  QSF_DEFINE_SIMPLE_GETTER_AND_SETTER(EvacuateBuildingId, uint64, mEvacuateBuildingId); // Connected to CAMP
272  QSF_DEFINE_SIMPLE_GETTER_AND_SETTER(TrappedPersonsInjuryId, uint32, mTrappedPersonsInjuryId);
273 
281  void setMainDoorDamaged(bool isDamaged);
282 
283  void hideParticleChildrenAtMapSave();
284 
285  inline const qsf::AssetProxy& getDamagedLevel1Material() const;
286  void setDamagedLevel1Material(const qsf::AssetProxy& assetProxy);
287 
288  inline const qsf::AssetProxy& getIntactMaterial() const;
289  void setIntactMaterial(const qsf::AssetProxy& assetProxy);
290 
291  inline float getCollapseDampeningFactor() const;
292  inline void setCollapseDampeningFactor(float collapseDampeningFactor);
293 
294  inline float getCollapseDelay() const;
295  inline void setCollapseDelay(float collapseDelay);
296 
297  inline float getCollapseShowRuinsDelay() const;
298  inline void setCollapseShowRuinsDelay(float collapseShowRuinsDelay);
299 
300  inline bool getIsDoorBlocked() const;
301  inline void setIsDoorBlocked(bool isDoorBlocked);
302 
303  inline qsf::Time getEboxRepairTime() const;
304  inline void setEboxRepairTime(qsf::Time time);
305 
306  inline qsf::Time getFirefighterRescueTime() const;
307  inline void setFirefighterRescueTime(qsf::Time time);
308 
316  void setCollapseRubbleVisible(bool show);
317 
318  void spawnGangsterInside(int numberOfGangsters, int numberOfHostages, int numberOfInjuredHostages, GangsterPool gangsterPoolType = GangsterPool::DEFAULT_EXTENDED);
319 
320  inline bool isClipped() const;
321 
326  void setDestroyedWithoutAnimation(FreeplayEvent* freeplayEvent);
327 
332  void resetEboxes();
333 
334 
335  //[-------------------------------------------------------]
336  //[ Public virtual em5::DamageComponent methods ]
337  //[-------------------------------------------------------]
338  public:
339  virtual bool isBurning() const override;
340 
341 
342  //[-------------------------------------------------------]
343  //[ Protected virtual em5::DamageComponent methods ]
344  //[-------------------------------------------------------]
345  protected:
346  virtual void onSetDamageState(DamageState damageState) override;
347  virtual void onSetIntact() override;
348  virtual void onSetDamagedLevel1() override;
349  virtual void onSetDamagedLevel2() override;
350  virtual void onSetDestroyed() override;
351  virtual void onSetFireLifePercentage(float fireLifePercentage) override;
352  virtual void onFireStarted(FreeplayEvent* freeplayEvent) override;
353  virtual void onFireStopped() override;
354  virtual void onFireDamageReceived(float amount, qsf::Component* sender, bool damageJustStarted) override;
355  virtual void onExplosion(FireComponent* fireComponent) override;
356 
357 
358  //[-------------------------------------------------------]
359  //[ Protected virtual qsf::Component methods ]
360  //[-------------------------------------------------------]
361  protected:
362  virtual bool onStartup() override;
363  virtual void onSetSimulating(bool simulating) override;
364  virtual void serialize(qsf::BinarySerializer& serializer) override;
365 
366 
367  //[-------------------------------------------------------]
368  //[ Protected virtual qsf::MovableObjectRenderingListener methods ]
369  //[-------------------------------------------------------]
370  protected:
371  virtual void onObjectRenderingStartup() override;
372  virtual void onObjectRendering(const qsf::Component& component, const Ogre::Camera& ogreCamera) override;
373 
374 
375  //[-------------------------------------------------------]
376  //[ Private definitions ]
377  //[-------------------------------------------------------]
378  private:
379  enum InternalFlags
380  {
381  SHOW_EXPLOSION,
382  MESH_ACTIVE
383  };
384  typedef qsf::EnumBitmask<uint8, InternalFlags> InternalFlagSet;
385 
386  typedef std::vector<uint64> EntityIdArray;
387 
388 
389  //[-------------------------------------------------------]
390  //[ Private methods ]
391  //[-------------------------------------------------------]
392  private:
393  // Job updates
394  void updateCollapseAnimation(const qsf::JobArguments& jobArguments);
395  void updateClippingAnimation(const qsf::JobArguments& jobArguments);
396 
397  // Lights
398  void setLightsActive(bool active, bool force = false);
399  void setLightControllerActive(bool active);
400 
401  // Spawn points
402  void setSpawnsActive(bool active);
403 
404  // Door
405  DoorComponent* getMainDoorComponent(qsf::Entity** outBestEntityFound) const;
406 
407  // Mesh
408  void showChildMeshes(EntityIdArray& entityIdArray, bool show);
409  void setDamageOverlaysActive(bool smutActive, bool emissiveActive);
410 
411  void killTrappedPersons(const qsf::MessageParameters& parameters = qsf::MessageParameters());
412  void enableParticle(uint64 particleEntityId, bool enable);
413  void enableParticle(qsf::Entity* particleEntity, bool enable);
414 
415  void applyDamageLevel1MaterialToIntactMesh(bool materialActive);
416 
417  void sendBuildingGetsDamagedMessage();
418 
419  void setHiddenSelfOnly(bool hidden);
420 
421  // Building clipping
422  void startClipping();
423  void continueClipping();
424  void endClipping();
425  void hideFire(bool hide);
426 
427  // Ebox blocking extinguish
428  void updateFireExtinguishBlocked();
429  void prepareEboxes();
430  void onEboxRepaired(const qsf::MessageParameters& parameters, uint64 eboxId);
431 
432  // Debug
433  void showDebug();
434  void updateDebugDraw();
435  void registerDebugDraw();
436 
437 
438  //[-------------------------------------------------------]
439  //[ Private data ]
440  //[-------------------------------------------------------]
441  private:
442  struct DoorData
443  {
444  // Connected to CAMP
445  uint64 mMainDoorId;
446 
447  inline DoorData();
448  }
449  mDoors;
450 
451  struct LightData
452  {
453  // Connected to CAMP
454  EntityIdArray mLightIds;
455  bool mLightsActive;
456 
457  inline LightData();
458  }
459  mLights;
460 
461  qsf::AssetProxy mDamagedLevel1Material;
462  qsf::AssetProxy mIntactMaterial;
463 
464  EntityIdArray mDamagedLevel1EntityIds;
465  EntityIdArray mDamagedLevel2EntityIds;
466  EntityIdArray mDestroyedEntityIds;
467  EntityIdArray mCollapseRubbleEntityIds;
468  EntityIdArray mEboxEntityIds;
469  uint64 mEvacuateBuildingId;
470 
471  InternalFlagSet mInternalFlags;
472 
473  bool mClippingEnabled;
474  uint64 mEventWindowId;
475  uint64 mPersonInWindowEntityId;
476  glm::vec3 mExplosionCenter;
477 
478  qsf::Time mEboxRepairTime;
479  qsf::Time mFirefighterRescueTime;
480 
481  // Internal state data
482  bool mCanCreateTrappedPersons;
483  uint16 mSetupNumberOfPersonsTrapped;
484  uint16 mSetupNumberOfInjuredPersonsTrapped;
485  uint32 mTrappedPersonsInjuryId;
486  uint32 mTrappedPersonsDieTimerId;
487  uint64 mDoorParticleEffectId;
488  bool mIsDoorBlocked;
489  bool mMainDoorIsDamaged;
490  qsf::Time mTrappedPersonsRescueTime;
491  qsf::MessageProxy mMessageProxyKillTrappedPersons;
492 
493  uint64 mCollapseAnimationEntityId;
494  float mCollapseAnimationYDistance;
495  float mCollapseElapsedTime;
496  float mCollapseDampeningFactor;
497  float mCollapseDelay;
498  float mCollapseShowRuinsDelay;
499  float mCollapseDelayTimeout;
500  bool mCollapseComplete;
501  bool mDamageLevel1MaterialActive;
502 
503  BuildingClippingManager* mBuildingClippingManager;
504  bool mUseCameraClipping;
505  bool mDirtyMaterialAabb;
506  float mCurrentCameraHeight;
507  float mCurrentFadeOffset;
508 
509  // Check if a ebox was repaired
510  std::vector<qsf::MessageProxy> mMessageProxyEboxRepaired;
511 
512  // Audio proxy for destruction
513  AudioProxy mAudioProxy;
514 
515  // Job proxies for regular update
516  qsf::JobProxy mAnimationJobProxy;
517  qsf::JobProxy mClippingAnimationJobProxy;
518 
519  // Debug
520  qsf::JobProxy mDebugJobProxy;
521  qsf::DebugDrawProxy mDebugDrawProxy;
522 
523 
524  //[-------------------------------------------------------]
525  //[ CAMP reflection system ]
526  //[-------------------------------------------------------]
527  QSF_CAMP_RTTI() // Only adds the virtual method "campClassId()", nothing more
528 
529  public:
530  QSF_CAMP_ARRAY_INTERFACE_CLASS_WITH_VARIABLE(EntityIdArrayInterface, BuildingComponent, std::vector<uint64>, uint64);
531  EntityIdArrayInterface LightArray;
532  EntityIdArrayInterface DamagedLevel1EntitiesArray;
533  EntityIdArrayInterface DamagedLevel2EntitiesArray;
534  EntityIdArrayInterface DestroyedEntitiesArray;
535  EntityIdArrayInterface CollapseRubbleArray;
536  EntityIdArrayInterface EboxEntitiesArray;
537 
538 
539  };
540 
541 
542 //[-------------------------------------------------------]
543 //[ Namespace ]
544 //[-------------------------------------------------------]
545 } // em5
546 
547 
548 //[-------------------------------------------------------]
549 //[ Implementation ]
550 //[-------------------------------------------------------]
551 #include "em5/component/building/BuildingComponent-inl.h"
552 
553 
554 //[-------------------------------------------------------]
555 //[ CAMP reflection system ]
556 //[-------------------------------------------------------]
558 QSF_CAMP_ARRAY_MAPPER_DEFINITION(em5::BuildingComponent::EntityIdArrayInterface)
Definition: ActionPriority.h:13
Job proxy class.
Definition: JobProxy.h:51
EMERGENCY 5 building component class.
Definition: BuildingComponent.h:56
EMERGENCY 5 building light time control component class.
Definition: BuildingLightTimeControlComponent.h:30
Abstract component class.
Definition: Component.h:105
Entity class.
Definition: Entity.h:46
EMERGENCY 5 simple damage component class.
Definition: SimpleDamageComponent.h:36
Message parameters class.
Definition: MessageParameters.h:34
("List B") The ones from default + several male civil types (e.g. for running amok, arsonist, ...)
unsigned int uint32
Definition: PlatformTypes.h:181
#define EM5_API_EXPORT
Definition: Export.h:28
Definition: AreaConfiguration.h:58
EMERGENCY 5 entity with a building component data cache for a single entity for multiplayer.
Definition: BuildingData.h:53
Message listener proxy class.
Definition: MessageProxy.h:47
#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
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
Prototype container base class.
Definition: PrototypeContainer.h:52
void serialize(BinarySerializer &serializer, BitFlagSet< STORAGE, ENUM > &bitFlagSet)
Definition: BitFlagSet.h:359
3D transform class
Definition: Transform.h:45
QSF_CAMP_ARRAY_MAPPER_DEFINITION(qsf::ai::TrafficLightTimerComponent::ManagedTrafficLightList)
Debug draw proxy class.
Definition: DebugDrawProxy.h:46
Asset proxy class.
Definition: AssetProxy.h:57
static const uint32 COMPONENT_ID
"em5::BuildingComponent" unique component ID
Definition: BuildingComponent.h:72
#define QSF_CAMP_RTTI()
Only adds the virtual method "campClassId()", nothing more.
Definition: CampClass.h:75
static const uint32 CLIPPING_ENABLED
"ClippingEnabled" unique class property ID inside the class
Definition: BuildingComponent.h:73
#define QSF_CAMP_TYPE_NONCOPYABLE(type)
See "CAMP_TYPE_NONCOPYABLE" for details.
Definition: CampClass.h:112
unsigned short uint16
Definition: PlatformTypes.h:178
static Time fromSeconds(float seconds)
Definition: Time-inl.h:74
GangsterPool
Defines pools of gangster prefabs needed for a events. Only prefabs from the resp. pool are picked for new gangster entities.
Definition: GangsterPool.h:22
#define QSF_DEFINE_SIMPLE_GETTER_AND_SETTER(name, type, variable)
Definition: PropertyHelper.h:16
EMERGENCY 5 door component class.
Definition: DoorComponent.h:41
Prototype class.
Definition: Prototype.h:100
EMERGENCY 5 building clipping manager.
Definition: BuildingClippingManager.h:53
Abstract EMERGENCY 5 freeplay event base class.
Definition: FreeplayEvent.h:66
Binary serializer class.
Definition: BinarySerializer.h:35
DamageState
Definition: DamageComponent.h:70
Data type for encapsulating time information. It might represents points in time and time spans...
Definition: Time.h:32