Emergency 20 Dokumentation  4.2.0
DamageComponent.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/Export.h"
15 
19 
20 
21 //[-------------------------------------------------------]
22 //[ Forward declarations ]
23 //[-------------------------------------------------------]
24 namespace em5
25 {
26  class FireComponent;
27  class FreeplayEvent;
28 }
29 namespace qsf
30 {
31  class MeshComponent;
32 }
33 
34 
35 //[-------------------------------------------------------]
36 //[ Namespace ]
37 //[-------------------------------------------------------]
38 namespace em5
39 {
40 
41 
42  //[-------------------------------------------------------]
43  //[ Classes ]
44  //[-------------------------------------------------------]
50  {
51 
52 
53  //[-------------------------------------------------------]
54  //[ Friends ]
55  //[-------------------------------------------------------]
56  friend class FireComponent; // Needs to call "setFireLifePercentage" and "onExplosion"
57  friend class ComplexFireComponent; // Needs to call "setFireLifePercentage"
58 
59 
60  //[-------------------------------------------------------]
61  //[ Public definitions ]
62  //[-------------------------------------------------------]
63  public:
64  static const uint32 COMPONENT_ID;
65  static const uint32 DAMAGE;
66  static const uint32 DAMAGE_STATE;
67  static const uint32 DAMAGE_SIMULATION;
68 
69  // Damage state (basic definition for all sub-classes)
71  {
76  DAMAGESTATE_INVALID // Don't export this via camp, this value is only used internal to signal, that the damage state doesn't matter (e.g. in the fire component when checking when a particle should be active)
77  };
78 
79 
80  //[-------------------------------------------------------]
81  //[ Public methods ]
82  //[-------------------------------------------------------]
83  public:
91  inline explicit DamageComponent(qsf::Prototype* prototype);
92 
97  inline virtual ~DamageComponent();
98 
99  inline DamageState getDamageState() const;
100  void setDamageState(DamageState damageState);
101 
102  inline float getFireGlowIntensity() const;
103  inline void setFireGlowIntensity(float fireGlowIntensity);
104 
105  inline bool getDamageSimulation() const;
106  inline void setDamageSimulation(bool damageSimulation);
107 
108  //[-------------------------------------------------------]
109  //[ Fire ]
110  //[-------------------------------------------------------]
115  const FireComponent* getBurningFireComponent() const;
116 
117  inline float getFireLifePercentage() const;
118 
123  void showExplosionFireParticles();
124 
129  void setFireExtinguishBlocked(bool blocked);
130 
131 
132  //[-------------------------------------------------------]
133  //[ Public virtual em5::DamageComponent methods ]
134  //[-------------------------------------------------------]
135  public:
136  inline virtual bool isIntact() const;
137  inline virtual bool isDamaged() const;
138  inline virtual bool isDamagedLevel1() const;
139  inline virtual bool isDamagedLevel2() const;
140  inline virtual bool isDestroyed() const;
141 
142  inline virtual bool isBurning() const;
143 
144  virtual void receiveDamage(float amount, damagetype::DamageType damageType, qsf::Component* sender = nullptr);
145  virtual bool checkReceiveDamage(damagetype::DamageType damageType, qsf::Component* sender = nullptr);
146 
147  inline virtual bool isReadyForCleanup() const;
148  virtual void cleanup();
149 
150 
151  //[-------------------------------------------------------]
152  //[ Public virtual qsf::Component methods ]
153  //[-------------------------------------------------------]
154  public:
155  virtual void onSetSimulating(bool simulating) override;
156  virtual void serialize(qsf::BinarySerializer& serializer) override;
157 
158  //[-------------------------------------------------------]
159  //[ Lifecycle ]
160  //[-------------------------------------------------------]
161  virtual bool onStartup() override;
162  virtual void onShutdown() override;
163 
164 
165  //[-------------------------------------------------------]
166  //[ Protected virtual em5::DamageComponent methods ]
167  //[-------------------------------------------------------]
168  protected:
169  inline virtual void onSetDamageState(DamageState damageState);
170  inline virtual void onSetIntact();
171  inline virtual void onSetDamagedLevel1();
172  inline virtual void onSetDamagedLevel2();
173  inline virtual void onSetDestroyed();
174 
175  inline virtual void onSetFireLifePercentage(float fireLifePercentage);
176  virtual void onFireStarted(FreeplayEvent* freeplayEvent);
177  virtual void onFireStopped();
178 
180  inline virtual void onExplosion(FireComponent* fireComponent);
181 
182  inline virtual void onFireDamageReceived(float amount, qsf::Component* sender, bool damageJustStarted);
183 
184  virtual void setCustomParametersForFireGlowAndSmutOverlay(const qsf::MeshComponent& meshComponent);
185 
186 
187  //[-------------------------------------------------------]
188  //[ Protected virtual qsf::MovableObjectRenderingListener methods ]
189  //[-------------------------------------------------------]
190  protected:
191  virtual qsf::Component* getMovableObjectRenderingListenerComponent() override;
192  virtual void onObjectRenderingStartup() override;
193 
194 
195  //[-------------------------------------------------------]
196  //[ Protected virtual qsf::JobProxyMovableObjectRenderingListener methods ]
197  //[-------------------------------------------------------]
198  protected:
199  virtual void onUpdateMovableObjectRenderingJob(const qsf::JobArguments& jobArguments) override;
200 
201 
202  //[-------------------------------------------------------]
203  //[ Protected static methods ]
204  //[-------------------------------------------------------]
205  protected:
206  static void exchangeDamageMaterials(qsf::Entity& entity, bool setDamaged);
207  static qsf::GlobalAssetId getDamageMaterialName(qsf::GlobalAssetId originalMaterialGlobalAssetId);
208 
209 
210  //[-------------------------------------------------------]
211  //[ Protected methods ]
212  //[-------------------------------------------------------]
213  protected:
214  void setFireStateIntact();
215  void setFireStateDestroyed();
216 
217  // For (complex) fire component friends
218  void setFireLifePercentage(float fireLifePercentage);
219 
220  void updateTintableMesh();
221 
222  // For fire glow and smut
223  void setupFireFadeAnimation();
224 
225 
226  //[-------------------------------------------------------]
227  //[ Protected data ]
228  //[-------------------------------------------------------]
229  protected:
231 
232 
233  //[-------------------------------------------------------]
234  //[ Private methods ]
235  //[-------------------------------------------------------]
236  private:
237  void updateFireFadeAnimation(const qsf::JobArguments& jobArguments);
238  void setCustomParametersForFireGlowAndSmutOverlay();
239  void internalDamageStateUpdated(bool isStartup = false);
240 
241 
242  //[-------------------------------------------------------]
243  //[ Private data ]
244  //[-------------------------------------------------------]
245  private:
246  // Connected to the CAMP reflection system
247  DamageState mDamageState;
248  float mFireGlowIntensity;
249  // Internal only
250  float mFireLifePercentage;
251  bool mIsDamageSimulationActive;
252  qsf::Time mLastReceivedFireDamageTimestamp;
253  float mEmissiveMapStrength;
254 
255  // Job proxies for regular update
256  qsf::JobProxy mFireFadeAnimationJobProxy;
257 
258 
259  //[-------------------------------------------------------]
260  //[ CAMP reflection system ]
261  //[-------------------------------------------------------]
262  QSF_CAMP_RTTI() // Only adds the virtual method "campClassId()", nothing more
263 
264 
265  };
266 
267 
268 //[-------------------------------------------------------]
269 //[ Namespace ]
270 //[-------------------------------------------------------]
271 } // em5
272 
273 
274 //[-------------------------------------------------------]
275 //[ Implementation ]
276 //[-------------------------------------------------------]
278 
279 
280 //[-------------------------------------------------------]
281 //[ CAMP reflection system ]
282 //[-------------------------------------------------------]
284 QSF_CAMP_TYPE_NONCOPYABLE(em5::DamageComponent::DamageState)
Definition: ActionPriority.h:13
Job proxy class.
Definition: JobProxy.h:51
Abstract component class.
Definition: Component.h:105
Entity class.
Definition: Entity.h:46
Job proxy based OGRE movable object rendering listener.
Definition: JobProxyMovableObjectRenderingListener.h:31
static const uint32 DAMAGE
"Damage" unique class property ID inside the class
Definition: DamageComponent.h:65
unsigned int uint32
Definition: PlatformTypes.h:181
float mPeakFireEnergyPercent
Definition: DamageComponent.h:230
#define EM5_API_EXPORT
Definition: Export.h:28
EMERGENCY 5 complex fire component class.
Definition: ComplexFireComponent.h:50
EMERGENCY 5 fire component class.
Definition: FireComponent.h:64
Definition: DamageComponent.h:72
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
Definition: DamageComponent.h:74
static const uint32 COMPONENT_ID
"em5::DamageComponent" unique component ID
Definition: DamageComponent.h:64
#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
#define QSF_CAMP_TYPE_NONCOPYABLE(type)
See "CAMP_TYPE_NONCOPYABLE" for details.
Definition: CampClass.h:112
Mesh component class.
Definition: MeshComponent.h:51
static const uint32 DAMAGE_SIMULATION
"DamageSimulation" unique class property ID inside the class
Definition: DamageComponent.h:67
Definition: DamageComponent.h:73
Prototype class.
Definition: Prototype.h:100
DamageType
Definition: DamageType.h:20
Abstract EMERGENCY 5 freeplay event base class.
Definition: FreeplayEvent.h:66
Definition: DamageComponent.h:75
Binary serializer class.
Definition: BinarySerializer.h:35
DamageState
Definition: DamageComponent.h:70
static const uint32 DAMAGE_STATE
"DamageState" unique class property ID inside the class
Definition: DamageComponent.h:66
uint64 GlobalAssetId
Definition: AssetSystemTypes.h:28
Data type for encapsulating time information. It might represents points in time and time spans...
Definition: Time.h:32