Emergency 20 Dokumentation  4.2.0
FireComponent.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 #include "em5/component/damage/DamageComponent.h" // For the DamageState enum
15 
16 #include <qsf/job/JobProxy.h>
19 #include <qsf/math/EnumBitmask.h>
20 #include <qsf/audio/AudioProxy.h>
21 
22 #include <boost/signals2.hpp>
23 
24 
25 //[-------------------------------------------------------]
26 //[ Forward declarations ]
27 //[-------------------------------------------------------]
28 namespace em5
29 {
30  class FireMaterial;
31  class FreeplayEvent;
32  class GameDebugGroup;
33  class ComplexFireComponent;
34  namespace multiplayer
35  {
36  class FireData;
37  }
38 }
39 namespace qsf
40 {
41  class TransformComponent;
42  class CameraComponent;
43  class MessageParameters;
44 }
45 
46 
47 //[-------------------------------------------------------]
48 //[ Namespace ]
49 //[-------------------------------------------------------]
50 namespace em5
51 {
52 
53 
54  //[-------------------------------------------------------]
55  //[ Classes ]
56  //[-------------------------------------------------------]
65  {
66 
67 
68  //[-------------------------------------------------------]
69  //[ Friends ]
70  //[-------------------------------------------------------]
71  friend class ComplexFireComponent;
72  friend class FireSystem;
73 
74  // TODO(sw) This is only needed for multiplay and there only on client side
75  // It would be better, when the simulation and pure visually updates are split into separate methods
76  // The pure visually updates could then be called cyclic on the multiplayer client (via an update job) to update the visually aspects
77  friend class multiplayer::FireData;
78 
79 
80  //[-------------------------------------------------------]
81  //[ Public definitions ]
82  //[-------------------------------------------------------]
83  public:
84  static const uint32 COMPONENT_ID;
85  static const uint32 HARD_RADIUS;
86  static const uint32 SOFT_RADIUS;
87 
88  enum FireState
89  {
94  _NUM_FIRESTATES
95  };
96 
98  {
103  _NUM_FIREAUDIOSTATES
104  };
105 
106 
107  //[-------------------------------------------------------]
108  //[ Public static methods ]
109  //[-------------------------------------------------------]
110  public:
111  static bool getAllFireComponents(qsf::Entity& entity, std::vector<FireComponent*>& outFireComponents);
112  inline static bool isBurningFireState(FireState fireState);
113 
114 
115  //[-------------------------------------------------------]
116  //[ Public methods ]
117  //[-------------------------------------------------------]
118  public:
126  explicit FireComponent(qsf::Prototype* prototype);
127 
132  virtual ~FireComponent();
133 
141  qsf::Entity& getMainEntity() const;
142 
150  inline ComplexFireComponent* getComplexFireComponent() const;
151 
157  void showOnExplosionFireParticles();
158 
159  //[-------------------------------------------------------]
160  //[ Properties ]
161  //[-------------------------------------------------------]
162  float getRelativeCombustionEnergy() const;
163 
171  inline float getEnergy() const;
172 
180  inline void setEnergy(float energy);
181 
182  void setEnergyPercent(float fraction);
183 
184  float getMaxEnergyValue() const;
185 
190  float getEnergyPercent() const;
191 
199  inline float getTotalDamage() const;
200 
208  inline void setTotalDamage(float damage);
209 
210  float getTotalDamagePercentage() const;
211 
216  float getMaximumLife() const;
217 
222  inline FireState getFireState() const;
223 
231  void setFireState(FireState fireState);
232 
237  void setFireStateByEvent(FireState fireState, FreeplayEvent* freeplayEvent = nullptr);
238 
246  const std::string& getFireMaterialName() const;
247 
255  void setFireMaterialByName(const std::string& fireMaterialName);
256 
261  inline float getHardRadius() const;
262 
270  inline void setHardRadius(float hardRadius);
271 
276  inline float getSoftRadius() const;
277 
285  inline void setSoftRadius(float softRadius);
286 
291  inline bool getPlayAudio();
292 
297  inline void setPlayAudio(bool playAudio);
298 
299  //[-------------------------------------------------------]
300  //[ State query ]
301  //[-------------------------------------------------------]
306  inline bool isIntact() const;
307 
312  inline virtual bool isBurning() const override;
313 
318  inline virtual bool isBurned() const override;
319 
324  inline bool isBurnable() const;
325 
332  float getExplosionBlastForce() const;
333 
340  float getExplosionBlastRadius() const;
341 
348  float getFireResistance() const;
349 
354  float getReceivedEnergyFactor() const;
355 
360  void setReceivedEnergyFactor(float factor);
361 
362  //[-------------------------------------------------------]
363  //[ Cleanup ]
364  //[-------------------------------------------------------]
369  bool isReadyForCleanup() const;
370 
375  void cleanup();
376 
377  //[-------------------------------------------------------]
378  //[ Fire control ]
379  //[-------------------------------------------------------]
384  void startFire(FreeplayEvent* freeplayEvent);
385 
390  void stopFire();
391 
396  void destroyByFire();
397 
402  void triggerExplosion();
403 
411  void hideParticleChildrenAtMapSave();
412 
417  void forceFireDamage(float fireDamage);
418 
419  inline void updateParticlesVisibility() { setParticlesActive(); }
420 
421  /*
422  * @brief
423  * Get/Set if extinguishing of the fire is blocked or not
424  */
425  inline bool isExtinguishBlocked() const;
426  inline void setExtinguishBlocked(bool extinguishBlocked);
427 
428  //[-------------------------------------------------------]
429  //[ Debug ]
430  //[-------------------------------------------------------]
435  void setShowFireRadii(bool showFireRadii);
436 
441  void addFireRadiiDebugDrawRequests(qsf::DebugDrawProxy& debugDrawProxy);
442 
443  //[-------------------------------------------------------]
444  //[ Tutorial ]
445  //[-------------------------------------------------------]
453  void setFireEnergyAndDamageRestrictionPercentage(float limitPercentage);
454 
455 
456  //[-------------------------------------------------------]
457  //[ Public virtual em5::FireReceiver methods ]
458  //[-------------------------------------------------------]
459  public:
460  virtual bool canCountedForExtinguishAchievement() const override;
461  virtual void setCountedForExtinguishAchievement(bool canCounted) override;
462 
463 
464  //[-------------------------------------------------------]
465  //[ Protected virtual em5::FireReceiver methods ]
466  //[-------------------------------------------------------]
467  protected:
468  virtual bool checkFireReceiver(qsf::Component* senderComponent) override;
469  virtual void receiveFireEnergy(float fireEnergy, const qsf::Time& timePassed, qsf::Component* senderComponent) override;
470  virtual void updateSimulation(const qsf::Time& timePassed) override;
471 
472 
473  //[-------------------------------------------------------]
474  //[ Protected virtual qsf::Component methods ]
475  //[-------------------------------------------------------]
476  protected:
477  virtual void onSetActive(bool active) override;
478  virtual void onSetSimulating(bool simulating) override;
479  virtual bool onStartup() override;
480  virtual void onShutdown() override;
481  inline virtual bool implementsOnComponentPropertyChange() const override { return true; }
482  virtual void onComponentPropertyChange(const qsf::Component& component, uint32 propertyId) override;
483 
484 
485  //[-------------------------------------------------------]
486  //[ Private static methods ]
487  //[-------------------------------------------------------]
488  private:
489  static void onObjectStartedBurning(qsf::Entity& entity, qsf::Component* sender);
490  static void onObjectStoppedBurning(qsf::Entity& entity, bool destroyed, bool isCleanup = false);
491 
492 
493  //[-------------------------------------------------------]
494  //[ Private definitions ]
495  //[-------------------------------------------------------]
496  private:
497  enum InternalFlags
498  {
499  FLAG_INTACT
500  };
501  typedef qsf::EnumBitmask<uint8, InternalFlags> InternalFlagSet;
502 
503  typedef std::vector<uint64> EntityIdArray;
504 
505 
506  //[-------------------------------------------------------]
507  //[ Private methods ]
508  //[-------------------------------------------------------]
509  private:
510  // Job updates
511  void updateReceivedEnergy(const qsf::Time& timePassed);
512  void updateBurning(const qsf::Time& timePassed);
513  void updateFireStateChanges();
514  void updateBalanceEnergy();
515  void updateHitPointBar();
516  void updateDamageComponent();
517 
518  // State change
519  void onFireStateChange(FireState newFireState, FireState oldFireState, FreeplayEvent* freeplayEvent);
520  void onStartedBurning(FreeplayEvent* freeplayEvent);
521  void onStoppedBurning();
522 
523  // Helper
524  FreeplayEvent* getSenderEvent();
525  void loadFireMaterial();
526  void onFadeInLight(const qsf::MessageParameters& parameters);
527 
528  // Particles
529  void setParticlesActive();
530  void stopAllParticles();
531  void setParticlesActiveInternal(DamageComponent::DamageState damageLevel);
532  void detectEarlyParticleStoping();
533 
534  // Exploding flag
535  inline bool isExploding() const;
536  inline void setIsExploding(bool isExploding);
537 
538  inline bool internalIsBurning() const;
539  inline bool internalIsBurned() const;
540 
541  // Sensor and ReactionComponent Handling
542  void setSensorAndReactionComponent(bool active);
543 
544  // Audio
545  void updateAudio();
546 
547  // Debug
548  void showDebug();
549  void onPreCompositorWorkspaceUpdate(const qsf::CameraComponent& cameraComponent);
550 
551 
552  //[-------------------------------------------------------]
553  //[ Private data ]
554  //[-------------------------------------------------------]
555  private:
556  // Connected to CAMP
557  FireState mFireState;
558  float mHardRadius;
559  float mSoftRadius;
560  float mFireEnergy;
561  float mTotalDamage;
562  InternalFlagSet mInternalFlags;
563  EntityIdArray mFireParticlesIds;
564 
565  // Internal
566  GameDebugGroup& mGameDebugGroup;
567  std::string mFireMaterialName;
568  FireMaterial* mFireMaterial;
569  float mCombustionEnergy;
570  float mReceivedEnergy;
571  qsf::Component* mSenderComponent;
572  ComplexFireComponent* mComplexFireComponent;
573  bool mIsExploding;
574  bool mShowFireRadii;
575  float mLowerFireEnergyLimitPercentage;
576  float mUpperFireDamageLimitPercentage;
577  glm::vec3 mFireParticlesCenter[2];
578  float mFireParticlesRadius[2];
579  qsf::MessageProxy mLightDelayMessageProxy;
580  bool mIsInCleanupProcess;
581  float mReceivedEnergyFactor;
582  bool mExtinguishBlocked;
583  bool mWasAlwaysInactive;
584  boost::container::flat_set<uint64> mDelayedLightIds;
585 
586  // Audio
587  bool mPlayAudio;
588  FireAudioState mFireAudioState;
589  uint64 mAmbientAudioSourceHandle;
590 
591  // Debugging
592  // -> Actually only for internal builds (additional check to find erroneous behavior), but we need to make sure end-user SDK is the same with or without ENDUSER define
593  qsf::DebugDrawProxy mDebugDrawProxy;
594  qsf::DebugDrawProxy mHitpointbarProxy;
595  uint32 mLastShownHitpointValue;
596 
597  // Achievement
598  bool mCanCountedForExtinguishAchievement;
599 
600  boost::signals2::connection mPreCompositorWorkspaceUpdateConnection;
601 
602 
603  //[-------------------------------------------------------]
604  //[ CAMP reflection system ]
605  //[-------------------------------------------------------]
606  QSF_CAMP_RTTI() // Only adds the virtual method "campClassId()", nothing more
607 
608  public:
609  QSF_CAMP_ARRAY_INTERFACE_CLASS_WITH_VARIABLE(EntityIdArrayInterface, FireComponent, std::vector<uint64>, uint64);
610  EntityIdArrayInterface FireParticlesArray;
611 
612 
613  };
614 
615 
616 //[-------------------------------------------------------]
617 //[ Namespace ]
618 //[-------------------------------------------------------]
619 } // em5
620 
621 
622 //[-------------------------------------------------------]
623 //[ Implementation ]
624 //[-------------------------------------------------------]
625 #include "em5/fire/component/FireComponent-inl.h"
626 
627 
628 //[-------------------------------------------------------]
629 //[ CAMP reflection system ]
630 //[-------------------------------------------------------]
632 QSF_CAMP_TYPE_NONCOPYABLE(em5::FireComponent::FireState)
633 QSF_CAMP_ARRAY_MAPPER_DEFINITION(em5::FireComponent::EntityIdArrayInterface)
Definition: ActionPriority.h:13
Definition: FireComponent.h:99
Entity is not burning, but completely destroyed by fire; it can't start burning again because there's...
Definition: FireComponent.h:93
Abstract component class.
Definition: Component.h:105
Fire system.
Definition: FireSystem.h:63
Entity class.
Definition: Entity.h:46
Message parameters class.
Definition: MessageParameters.h:34
static const uint32 SOFT_RADIUS
Definition: FireComponent.h:86
unsigned int uint32
Definition: PlatformTypes.h:181
EMERGENCY 5 fire receiver component class.
Definition: FireReceiverComponent.h:69
Definition: FireComponent.h:102
FireAudioState
Definition: FireComponent.h:97
FireState
Definition: FireComponent.h:88
Definition: FireComponent.h:101
#define EM5_API_EXPORT
Definition: Export.h:28
Definition: AreaConfiguration.h:58
Camera component class.
Definition: CameraComponent.h:50
EMERGENCY 5 complex fire component class.
Definition: ComplexFireComponent.h:50
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
Definition: PickupPersonByParamedicAction.h:21
virtual bool implementsOnComponentPropertyChange() const override
Signal whether this component needs the "onComponentPropertyChange" callback at all.
Definition: FireComponent.h:481
QSF_CAMP_ARRAY_MAPPER_DEFINITION(qsf::ai::TrafficLightTimerComponent::ManagedTrafficLightList)
Entity is currently not burning (but may still be damaged by a former fire)
Definition: FireComponent.h:90
Debug draw proxy class.
Definition: DebugDrawProxy.h:46
#define QSF_CAMP_RTTI()
Only adds the virtual method "campClassId()", nothing more.
Definition: CampClass.h:75
static const uint32 HARD_RADIUS
Definition: FireComponent.h:85
EMERGENCY 5 entity with a fire component data cache for a single entity for multiplayer.
Definition: FireData.h:51
#define QSF_CAMP_TYPE_NONCOPYABLE(type)
See "CAMP_TYPE_NONCOPYABLE" for details.
Definition: CampClass.h:112
Entity is burning with a small fire, i.e. it's not burning very hot yet.
Definition: FireComponent.h:91
Prototype class.
Definition: Prototype.h:100
Entity is burning with a large fire, i.e. it's burning relatively hot now.
Definition: FireComponent.h:92
Abstract EMERGENCY 5 freeplay event base class.
Definition: FreeplayEvent.h:66
DamageState
Definition: DamageComponent.h:70
Definition: FireComponent.h:100
static const uint32 COMPONENT_ID
"em5::FireComponent" unique component ID
Definition: FireComponent.h:84
void updateParticlesVisibility()
Definition: FireComponent.h:419
Data type for encapsulating time information. It might represents points in time and time spans...
Definition: Time.h:32