1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#ifndef TAKEDAMAGEINFO_H
#define TAKEDAMAGEINFO_H
#ifdef _WIN32
#pragma once
#endif
#include "networkvar.h" // todo: change this when DECLARE_CLASS is moved into a better location.
// Used to initialize m_flBaseDamage to something that we know pretty much for sure
// hasn't been modified by a user.
#define BASEDAMAGE_NOT_SPECIFIED FLT_MAX
class CBaseEntity;
class CTakeDamageInfo
{
public:
DECLARE_CLASS_NOBASE( CTakeDamageInfo );
CTakeDamageInfo();
CTakeDamageInfo( CBaseEntity *pInflictor, CBaseEntity *pAttacker, float flDamage, int bitsDamageType, int iKillType = 0 );
CTakeDamageInfo( CBaseEntity *pInflictor, CBaseEntity *pAttacker, CBaseEntity *pWeapon, float flDamage, int bitsDamageType, int iKillType = 0 );
CTakeDamageInfo( CBaseEntity *pInflictor, CBaseEntity *pAttacker, const Vector &damageForce, const Vector &damagePosition, float flDamage, int bitsDamageType, int iKillType = 0, Vector *reportedPosition = NULL );
CTakeDamageInfo( CBaseEntity *pInflictor, CBaseEntity *pAttacker, CBaseEntity *pWeapon, const Vector &damageForce, const Vector &damagePosition, float flDamage, int bitsDamageType, int iKillType = 0, Vector *reportedPosition = NULL );
// Inflictor is the weapon or rocket (or player) that is dealing the damage.
CBaseEntity* GetInflictor() const;
void SetInflictor( CBaseEntity *pInflictor );
// Weapon is the weapon that did the attack.
// For hitscan weapons, it'll be the same as the inflictor. For projectile weapons, the projectile
// is the inflictor, and this contains the weapon that created the projectile.
CBaseEntity* GetWeapon() const;
void SetWeapon( CBaseEntity *pWeapon );
// Attacker is the character who originated the attack (like a player or an AI).
CBaseEntity* GetAttacker() const;
void SetAttacker( CBaseEntity *pAttacker );
float GetDamage() const;
void SetDamage( float flDamage );
float GetMaxDamage() const;
void SetMaxDamage( float flMaxDamage );
void ScaleDamage( float flScaleAmount );
void AddDamage( float flAddAmount );
void SubtractDamage( float flSubtractAmount );
float GetDamageBonus() const;
CBaseEntity *GetDamageBonusProvider() const;
void SetDamageBonus( float flBonus, CBaseEntity *pProvider = NULL );
float GetBaseDamage() const;
bool BaseDamageIsValid() const;
Vector GetDamageForce() const;
void SetDamageForce( const Vector &damageForce );
void ScaleDamageForce( float flScaleAmount );
float GetDamageForForceCalc() const;
void SetDamageForForceCalc( const float flScaleAmount );
Vector GetDamagePosition() const;
void SetDamagePosition( const Vector &damagePosition );
Vector GetReportedPosition() const;
void SetReportedPosition( const Vector &reportedPosition );
int GetDamageType() const;
void SetDamageType( int bitsDamageType );
void AddDamageType( int bitsDamageType );
int GetDamageCustom( void ) const;
void SetDamageCustom( int iDamageCustom );
int GetDamageStats( void ) const;
void SetDamageStats( int iDamageStats );
void SetForceFriendlyFire( bool bValue ) { m_bForceFriendlyFire = bValue; }
bool IsForceFriendlyFire( void ) const { return m_bForceFriendlyFire; }
int GetAmmoType() const;
void SetAmmoType( int iAmmoType );
const char * GetAmmoName() const;
int GetPlayerPenetrationCount() const { return m_iPlayerPenetrationCount; }
void SetPlayerPenetrationCount( int iPlayerPenetrationCount ) { m_iPlayerPenetrationCount = iPlayerPenetrationCount; }
int GetDamagedOtherPlayers() const { return m_iDamagedOtherPlayers; }
void SetDamagedOtherPlayers( int iVal ) { m_iDamagedOtherPlayers = iVal; }
void Set( CBaseEntity *pInflictor, CBaseEntity *pAttacker, float flDamage, int bitsDamageType, int iKillType = 0 );
void Set( CBaseEntity *pInflictor, CBaseEntity *pAttacker, CBaseEntity *pWeapon, float flDamage, int bitsDamageType, int iKillType = 0 );
void Set( CBaseEntity *pInflictor, CBaseEntity *pAttacker, const Vector &damageForce, const Vector &damagePosition, float flDamage, int bitsDamageType, int iKillType = 0, Vector *reportedPosition = NULL );
void Set( CBaseEntity *pInflictor, CBaseEntity *pAttacker, CBaseEntity *pWeapon, const Vector &damageForce, const Vector &damagePosition, float flDamage, int bitsDamageType, int iKillType = 0, Vector *reportedPosition = NULL );
void AdjustPlayerDamageInflictedForSkillLevel();
void AdjustPlayerDamageTakenForSkillLevel();
// Given a damage type (composed of the #defines above), fill out a string with the appropriate text.
// For designer debug output.
static void DebugGetDamageTypeString(unsigned int DamageType, char *outbuf, int outbuflength );
//private:
void CopyDamageToBaseDamage();
protected:
void Init( CBaseEntity *pInflictor, CBaseEntity *pAttacker, CBaseEntity *pWeapon, const Vector &damageForce, const Vector &damagePosition, const Vector &reportedPosition, float flDamage, int bitsDamageType, int iKillType );
Vector m_vecDamageForce;
Vector m_vecDamagePosition;
Vector m_vecReportedPosition; // Position players are told damage is coming from
EHANDLE m_hInflictor;
EHANDLE m_hAttacker;
EHANDLE m_hWeapon;
float m_flDamage;
float m_flMaxDamage;
float m_flBaseDamage; // The damage amount before skill leve adjustments are made. Used to get uniform damage forces.
int m_bitsDamageType;
int m_iDamageCustom;
int m_iDamageStats;
int m_iAmmoType; // AmmoType of the weapon used to cause this damage, if any
int m_iDamagedOtherPlayers;
int m_iPlayerPenetrationCount;
float m_flDamageBonus; // Anything that increases damage (crit) - store the delta
EHANDLE m_hDamageBonusProvider; // Who gave us the ability to do extra damage?
bool m_bForceFriendlyFire; // Ideally this would be a dmg type, but we can't add more
float m_flDamageForForce;
DECLARE_SIMPLE_DATADESC();
};
//-----------------------------------------------------------------------------
// Purpose: Multi damage. Used to collect multiple damages in the same frame (i.e. shotgun pellets)
//-----------------------------------------------------------------------------
class CMultiDamage : public CTakeDamageInfo
{
DECLARE_CLASS( CMultiDamage, CTakeDamageInfo );
public:
CMultiDamage();
bool IsClear( void ) { return (m_hTarget == NULL); }
CBaseEntity *GetTarget() const;
void SetTarget( CBaseEntity *pTarget );
void Init( CBaseEntity *pTarget, CBaseEntity *pInflictor, CBaseEntity *pAttacker, CBaseEntity *pWeapon, const Vector &damageForce, const Vector &damagePosition, const Vector &reportedPosition, float flDamage, int bitsDamageType, int iKillType );
protected:
EHANDLE m_hTarget;
DECLARE_SIMPLE_DATADESC();
};
extern CMultiDamage g_MultiDamage;
// Multidamage accessors
void ClearMultiDamage( void );
void ApplyMultiDamage( void );
void AddMultiDamage( const CTakeDamageInfo &info, CBaseEntity *pEntity );
//-----------------------------------------------------------------------------
// Purpose: Utility functions for physics damage force calculation
//-----------------------------------------------------------------------------
float ImpulseScale( float flTargetMass, float flDesiredSpeed );
void CalculateExplosiveDamageForce( CTakeDamageInfo *info, const Vector &vecDir, const Vector &vecForceOrigin, float flScale = 1.0 );
void CalculateBulletDamageForce( CTakeDamageInfo *info, int iBulletType, const Vector &vecBulletDir, const Vector &vecForceOrigin, float flScale = 1.0 );
void CalculateMeleeDamageForce( CTakeDamageInfo *info, const Vector &vecMeleeDir, const Vector &vecForceOrigin, float flScale = 1.0 );
void GuessDamageForce( CTakeDamageInfo *info, const Vector &vecForceDir, const Vector &vecForceOrigin, float flScale = 1.0 );
// -------------------------------------------------------------------------------------------------- //
// Inlines.
// -------------------------------------------------------------------------------------------------- //
inline CBaseEntity* CTakeDamageInfo::GetInflictor() const
{
return m_hInflictor;
}
inline void CTakeDamageInfo::SetInflictor( CBaseEntity *pInflictor )
{
m_hInflictor = pInflictor;
}
inline CBaseEntity* CTakeDamageInfo::GetAttacker() const
{
return m_hAttacker;
}
inline void CTakeDamageInfo::SetAttacker( CBaseEntity *pAttacker )
{
m_hAttacker = pAttacker;
}
inline CBaseEntity* CTakeDamageInfo::GetWeapon() const
{
return m_hWeapon;
}
inline void CTakeDamageInfo::SetWeapon( CBaseEntity *pWeapon )
{
m_hWeapon = pWeapon;
}
inline float CTakeDamageInfo::GetDamage() const
{
return m_flDamage;
}
inline void CTakeDamageInfo::SetDamage( float flDamage )
{
m_flDamage = flDamage;
}
inline float CTakeDamageInfo::GetMaxDamage() const
{
return m_flMaxDamage;
}
inline void CTakeDamageInfo::SetMaxDamage( float flMaxDamage )
{
m_flMaxDamage = flMaxDamage;
}
inline void CTakeDamageInfo::ScaleDamage( float flScaleAmount )
{
m_flDamage *= flScaleAmount;
}
inline void CTakeDamageInfo::AddDamage( float flAddAmount )
{
m_flDamage += flAddAmount;
}
inline void CTakeDamageInfo::SubtractDamage( float flSubtractAmount )
{
m_flDamage -= flSubtractAmount;
}
inline float CTakeDamageInfo::GetDamageBonus() const
{
return m_flDamageBonus;
}
inline CBaseEntity *CTakeDamageInfo::GetDamageBonusProvider() const
{
return m_hDamageBonusProvider;
}
inline void CTakeDamageInfo::SetDamageBonus( float flBonus, CBaseEntity *pProvider /*= NULL*/ )
{
m_flDamageBonus = flBonus;
m_hDamageBonusProvider = pProvider;
}
inline float CTakeDamageInfo::GetBaseDamage() const
{
if( BaseDamageIsValid() )
return m_flBaseDamage;
// No one ever specified a base damage, so just return damage.
return m_flDamage;
}
inline bool CTakeDamageInfo::BaseDamageIsValid() const
{
return (m_flBaseDamage != BASEDAMAGE_NOT_SPECIFIED);
}
inline Vector CTakeDamageInfo::GetDamageForce() const
{
return m_vecDamageForce;
}
inline void CTakeDamageInfo::SetDamageForce( const Vector &damageForce )
{
m_vecDamageForce = damageForce;
}
inline void CTakeDamageInfo::ScaleDamageForce( float flScaleAmount )
{
m_vecDamageForce *= flScaleAmount;
}
inline float CTakeDamageInfo::GetDamageForForceCalc() const
{
return m_flDamageForForce;
}
inline void CTakeDamageInfo::SetDamageForForceCalc( float flDamage )
{
m_flDamageForForce = flDamage;
}
inline Vector CTakeDamageInfo::GetDamagePosition() const
{
return m_vecDamagePosition;
}
inline void CTakeDamageInfo::SetDamagePosition( const Vector &damagePosition )
{
m_vecDamagePosition = damagePosition;
}
inline Vector CTakeDamageInfo::GetReportedPosition() const
{
return m_vecReportedPosition;
}
inline void CTakeDamageInfo::SetReportedPosition( const Vector &reportedPosition )
{
m_vecReportedPosition = reportedPosition;
}
inline void CTakeDamageInfo::SetDamageType( int bitsDamageType )
{
m_bitsDamageType = bitsDamageType;
}
inline int CTakeDamageInfo::GetDamageType() const
{
return m_bitsDamageType;
}
inline void CTakeDamageInfo::AddDamageType( int bitsDamageType )
{
m_bitsDamageType |= bitsDamageType;
}
inline int CTakeDamageInfo::GetDamageCustom() const
{
return m_iDamageCustom;
}
inline void CTakeDamageInfo::SetDamageCustom( int iDamageCustom )
{
m_iDamageCustom = iDamageCustom;
}
inline int CTakeDamageInfo::GetDamageStats() const
{
return m_iDamageCustom;
}
inline void CTakeDamageInfo::SetDamageStats( int iDamageCustom )
{
m_iDamageCustom = iDamageCustom;
}
inline int CTakeDamageInfo::GetAmmoType() const
{
return m_iAmmoType;
}
inline void CTakeDamageInfo::SetAmmoType( int iAmmoType )
{
m_iAmmoType = iAmmoType;
}
inline void CTakeDamageInfo::CopyDamageToBaseDamage()
{
m_flBaseDamage = m_flDamage;
}
// -------------------------------------------------------------------------------------------------- //
// Inlines.
// -------------------------------------------------------------------------------------------------- //
inline CBaseEntity *CMultiDamage::GetTarget() const
{
return m_hTarget;
}
inline void CMultiDamage::SetTarget( CBaseEntity *pTarget )
{
m_hTarget = pTarget;
}
#endif // TAKEDAMAGEINFO_H
|