Emergency 20 Dokumentation  4.2.0
CloseQuartersCombatAction.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"
15 
18 
19 
20 //[-------------------------------------------------------]
21 //[ Forward declarations ]
22 //[-------------------------------------------------------]
23 namespace em5
24 {
25  class HealthComponent;
26 }
27 
28 
29 //[-------------------------------------------------------]
30 //[ Namespace ]
31 //[-------------------------------------------------------]
32 namespace em5
33 {
34 
35 
36  //[-------------------------------------------------------]
37  //[ Classes ]
38  //[-------------------------------------------------------]
44  {
45 
46 
47  //[-------------------------------------------------------]
48  //[ Public definitions ]
49  //[-------------------------------------------------------]
50  public:
52 
53 
54  //[-------------------------------------------------------]
55  //[ Public methods ]
56  //[-------------------------------------------------------]
57  public:
63 
68  virtual ~CloseQuartersCombatAction();
69 
89  void init(const qsf::Entity& targetEntity, weapon::Weapon attackerWeapon, weapon::Weapon targetWeapon, uint64 maxCombatRounds = 0, float lowerTargetLife = qsf::getUninitialized<float>(0.0f), float lowerAttackerLife = qsf::getUninitialized<float>(0.0f), float healthRestrictionPercentage = 0.0f);
90 
91 
92  //[-------------------------------------------------------]
93  //[ Public virtual qsf::Actions methods ]
94  //[-------------------------------------------------------]
95  public:
96  virtual void serialize(qsf::BinarySerializer& serializer) override;
97 
98 
99  //[-------------------------------------------------------]
100  //[ Protected virtual qsf::Action methods ]
101  //[-------------------------------------------------------]
102  protected:
103  virtual bool onStartup() override;
104  virtual void onShutdown() override;
105  virtual qsf::action::Result updateAction(const qsf::Clock& clock) override;
106 
107 
108  //[-------------------------------------------------------]
109  //[ Private definitions ]
110  //[-------------------------------------------------------]
111  private:
112  enum CombatState
113  {
114  COMBATSTATE_INIT,
115  COMBATSTATE_ATTACK,
116  COMBATSTATE_CHECK_INJURIES,
117  COMBATSTATE_COUNTERATTACK,
118  COMBATSTATE_DONE
119  };
120 
121  // As used in "enqueueFightingAnimations()" - Needed to enqueue parts of
122  enum FightAnimationMode
123  {
124  FULL_ANIMATION,
125  FIRST_PART,
126  LAST_PART
127  };
128 
129 
130  //[-------------------------------------------------------]
131  //[ Private methods ]
132  //[-------------------------------------------------------]
133  private:
134  // Enqueue the animations for exactly one fighting round
135  void enqueueFightingAnimations(qsf::Entity& attackerEntity, qsf::Entity& targetEntity, weapon::Weapon attackerWeapon, weapon::Weapon targetWeapon, FightAnimationMode animationMode = FULL_ANIMATION);
136 
137  // Returns a human readable string for the name of the given weapon
138  std::string getDebugWeaponName(weapon::Weapon weapon) const;
139 
140  // Returns the default damage the specified weapon does each round
141  float getDefaultWeaponDamage(weapon::Weapon weapon) const;
142 
143  // Return an injury (random!) that was caused by the given weapon
144  qsf::StringHash getInjuryCausedByWeapon(weapon::Weapon weapon) const;
145 
146  bool damageEntity(HealthComponent& healthComponent, float damage, qsf::Entity& damgeSourceEntity);
147 
148  // Internal helper function for playing animation
149  void playAnimationStartByWeapon(qsf::Entity& entity, weapon::Weapon weaponType);
150  void playAnimationEndByWeapon(qsf::Entity& entity, weapon::Weapon weaponType);
151  void playAnimationWithOffset(qsf::Entity& entity, std::string animationPfath, qsf::Time blendTime, float startOffset, float endOffset, const boost::optional<qsf::Time> maxPlayTime = boost::optional<qsf::Time>());
152 
153 
154  //[-------------------------------------------------------]
155  //[ Private data ]
156  //[-------------------------------------------------------]
157  private:
158  uint64 mTargetEntityId;
159  CombatState mState;
160  weapon::Weapon mAttackerWeapon;
161  weapon::Weapon mTargetWeapon;
162  float mLowerTargetLife;
163  float mLowerAttackerLife;
164  uint64 mMaxCombatRounds;
165  uint64 mCurrentRound;
166  bool mTargetInjured;
167  bool mAttackerInjured;
168  bool mCounterAttack;
169  float mLowerHealthLimitPercentage;
170  AudioProxy mAudioProxy;
171  AudioProxy mKickAudioProxy;
172 
173  // Debug
174  // -> 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
175  qsf::DebugDrawProxy mDebugDrawProxy;
176 
177 
178  //[-------------------------------------------------------]
179  //[ CAMP reflection system ]
180  //[-------------------------------------------------------]
181  QSF_CAMP_RTTI() // Only adds the virtual method "campClassId()", nothing more
182 
183 
184  };
185 
186 
187 //[-------------------------------------------------------]
188 //[ Namespace ]
189 //[-------------------------------------------------------]
190 } // em5
191 
192 
193 //[-------------------------------------------------------]
194 //[ CAMP reflection system ]
195 //[-------------------------------------------------------]
Definition: ActionPriority.h:13
static const qsf::NamedIdentifier ACTION_ID
"em5::PullObjectAction" unique action identifier
Definition: CloseQuartersCombatAction.h:51
Entity class.
Definition: Entity.h:46
EMERGENCY 5 close quarters combat action.
Definition: CloseQuartersCombatAction.h:43
Clock class.
Definition: Clock.h:33
#define EM5_API_EXPORT
Definition: Export.h:28
uint64_t uint64
Definition: PlatformTypes.h:184
void serialize(BinarySerializer &serializer, BitFlagSet< STORAGE, ENUM > &bitFlagSet)
Definition: BitFlagSet.h:359
Debug draw proxy class.
Definition: DebugDrawProxy.h:46
#define QSF_CAMP_RTTI()
Only adds the virtual method "campClassId()", nothing more.
Definition: CampClass.h:75
#define QSF_CAMP_TYPE_NONCOPYABLE(type)
See "CAMP_TYPE_NONCOPYABLE" for details.
Definition: CampClass.h:112
Weapon
Definition: Weapon.h:22
Abstract action base class.
Definition: Action.h:59
Class combining strings with their hashes.
Definition: NamedIdentifier.h:34
Compile time string hash class.
Definition: StringHash.h:59
Binary serializer class.
Definition: BinarySerializer.h:35
Result
Definition: ActionResult.h:20
Data type for encapsulating time information. It might represents points in time and time spans...
Definition: Time.h:32