-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathasw_weapon_flamer_shared.cpp
More file actions
492 lines (410 loc) · 12 KB
/
asw_weapon_flamer_shared.cpp
File metadata and controls
492 lines (410 loc) · 12 KB
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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
#include "cbase.h"
#include "asw_weapon_flamer_shared.h"
#include "in_buttons.h"
#include "asw_marine_skills.h"
#ifdef CLIENT_DLL
#include "c_asw_player.h"
#include "c_asw_weapon.h"
#include "c_asw_marine.h"
#include "c_asw_generic_emitter_entity.h"
#include "idebugoverlaypanel.h"
#include "engine/IVDebugOverlay.h"
#else
#include "asw_marine.h"
#include "asw_player.h"
#include "asw_weapon.h"
#include "asw_marine_resource.h"
#include "npcevent.h"
#include "shot_manipulator.h"
#include "asw_flamer_projectile.h"
#include "asw_fire.h"
#include "asw_marine_speech.h"
#include "asw_weapon_ammo_bag_shared.h"
#include "asw_gamerules.h"
#include "asw_extinguisher_projectile.h"
#include "EntityFlame.h"
#include "te_effect_dispatch.h"
#include "IEffects.h"
#endif
#include "asw_weapon_parse.h"
#include "asw_deathmatch_mode_light.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
ConVar rd_flamer_infinite_extinguisher( "rd_flamer_infinite_extinguisher", "0", FCVAR_REPLICATED | FCVAR_CHEAT, "If 1 the flamer's extinguisher has infinite ammo" );
IMPLEMENT_NETWORKCLASS_ALIASED( ASW_Weapon_Flamer, DT_ASW_Weapon_Flamer )
BEGIN_NETWORK_TABLE( CASW_Weapon_Flamer, DT_ASW_Weapon_Flamer )
#ifdef CLIENT_DLL
// recvprops
RecvPropBool(RECVINFO(m_bIsSecondaryFiring)),
#else
// sendprops
SendPropBool(SENDINFO(m_bIsSecondaryFiring)),
SendPropExclude( "DT_BaseAnimating", "m_nSkin" ),
#endif
END_NETWORK_TABLE()
BEGIN_PREDICTION_DATA( CASW_Weapon_Flamer )
#ifdef CLIENT_DLL
DEFINE_PRED_FIELD( m_bIsSecondaryFiring, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ),
#endif
END_PREDICTION_DATA()
LINK_ENTITY_TO_CLASS( asw_weapon_flamer, CASW_Weapon_Flamer );
PRECACHE_WEAPON_REGISTER(asw_weapon_flamer);
#ifndef CLIENT_DLL
//---------------------------------------------------------
// Save/Restore
//---------------------------------------------------------
BEGIN_DATADESC( CASW_Weapon_Flamer )
END_DATADESC()
#endif /* not client */
CASW_Weapon_Flamer::CASW_Weapon_Flamer()
{
m_fMinRange1 = 0;
m_fMaxRange1 = 160;
m_fMinRange2 = 0;
m_fMaxRange2 = 160;
m_flLastFireTime = 0;
}
CASW_Weapon_Flamer::~CASW_Weapon_Flamer()
{
#ifdef CLIENT_DLL
if ( m_hPilotLight )
{
ParticleProp()->StopEmissionAndDestroyImmediately( m_hPilotLight );
m_hPilotLight = NULL;
}
#endif
}
void CASW_Weapon_Flamer::Spawn()
{
BaseClass::Spawn();
}
#ifdef CLIENT_DLL
void CASW_Weapon_Flamer::OnDataChanged( DataUpdateType_t updateType )
{
BaseClass::OnDataChanged( updateType );
if ( updateType == DATA_UPDATE_CREATED )
{
SetNextClientThink( CLIENT_THINK_ALWAYS );
if ( !m_hPilotLight )
{
m_hPilotLight = ParticleProp()->Create( "asw_flamethrower_pilot_sml", PATTACH_POINT_FOLLOW, "flame" );
if ( m_hPilotLight )
m_hPilotLight->SetControlPoint( 1, Vector( 1, 0, 0 ) );
}
}
ACTIVE_SPLITSCREEN_PLAYER_GUARD_VGUI( GET_ACTIVE_SPLITSCREEN_SLOT() );
if ( m_hPilotLight )
{
int iPilot = (m_bSwitchingWeapons || !IsVisible() || !GetMarine() || m_bIsFiring || m_bIsSecondaryFiring || IsReloading() || (Clip1() <= 0)) ? 0 : 1;
m_hPilotLight->SetControlPoint( 1, Vector( iPilot, 0, 0 ) );
}
}
void CASW_Weapon_Flamer::UpdateOnRemove()
{
BaseClass::UpdateOnRemove();
if ( m_hPilotLight )
{
ParticleProp()->StopEmissionAndDestroyImmediately( m_hPilotLight );
m_hPilotLight = NULL;
}
}
void CASW_Weapon_Flamer::ClientThink()
{
BaseClass::ClientThink();
if ( m_bIsFiring && m_iClip1 != 0 )
{
if( !pEffect )
{
pEffect = ParticleProp()->Create( "asw_flamethrower", PATTACH_POINT_FOLLOW, "muzzle" );
}
}
else
{
if ( pEffect )
{
pEffect->StopEmission();
pEffect = NULL;
}
}
if ( m_bIsSecondaryFiring )
{
if( !pExtinguishEffect )
{
pExtinguishEffect = ParticleProp()->Create( "asw_fireextinguisher", PATTACH_POINT_FOLLOW, "muzzle" );
}
}
else
{
if ( pExtinguishEffect )
{
pExtinguishEffect->StopEmission();
pExtinguishEffect = NULL;
}
}
}
#endif
void CASW_Weapon_Flamer::ClearIsFiring()
{
BaseClass::ClearIsFiring();
m_bIsSecondaryFiring = false;
}
void CASW_Weapon_Flamer::ItemPostFrame( void )
{
CASW_Marine* pOwner = GetMarine();
if (!pOwner)
return;
BaseClass::ItemPostFrame();
bool bAttack1, bAttack2, bReload, bOldReload, bOldAttack1;
static bool bOldAttack2 = false;
GetButtons(bAttack1, bAttack2, bReload, bOldReload, bOldAttack1 );
// we need to check for old attacks otherwise flamer will fire last pellet without sound and particles
if ( m_iClip1 == 0 && ( bOldAttack1 || bOldAttack2 ) )
{
ClearIsFiring();
return;
}
if ( !bAttack2 || ( m_iClip1 <= 1 && bOldAttack2 ) )
m_bIsSecondaryFiring = false;
bOldAttack2 = bAttack2;
}
//-----------------------------------------------------------------------------
// Purpose:
// Output : Activity
//-----------------------------------------------------------------------------
Activity CASW_Weapon_Flamer::GetPrimaryAttackActivity( void )
{
return ACT_VM_PRIMARYATTACK;
}
void CASW_Weapon_Flamer::PrimaryAttack( void )
{
// If my clip is empty (and I use clips) start reload
if ( UsesClipsForAmmo1() && !m_iClip1 )
{
Reload();
return;
}
if ( m_bIsSecondaryFiring.Get() )
{
m_bIsFiring = false;
return;
}
CASW_Marine *pMarine = GetMarine();
if (pMarine) // firing from a marine
{
// MUST call sound before removing a round from the clip of a CMachineGun
//WeaponSound(SINGLE);
m_bIsFiring = true;
// tell the marine to tell its weapon to draw the muzzle flash
pMarine->DoMuzzleFlash();
// sets the animation on the weapon model iteself
SendWeaponAnim( GetPrimaryAttackActivity() );
// sets the animation on the marine holding this weapon
#ifndef CLIENT_DLL
Vector vecSrc = pMarine->Weapon_ShootPosition( );
Vector vecAiming = vec3_origin;
CASW_Player *pPlayer = GetCommander();
if ( pPlayer && pMarine->IsInhabited() )
{
vecAiming = pPlayer->GetAutoaimVectorForMarine(pMarine, GetAutoAimAmount(), GetVerticalAdjustOnlyAutoAimAmount()); // 45 degrees = 0.707106781187
}
else
{
vecAiming = pMarine->GetActualShootTrajectory( vecSrc );
}
// Fire the bullets, and force the first shot to be perfectly accuracy
CShotManipulator Manipulator( vecAiming );
AngularImpulse rotSpeed(0,0,720);
// create a pellet at some random spread direction
Vector newVel = Manipulator.ApplySpread(GetBulletSpread());
if ( pMarine->GetWaterLevel() != 3 )
{
newVel *= FLAMER_PROJECTILE_AIR_VELOCITY;
newVel *= (1.0 + (0.1 * random->RandomFloat(-1,1)));
// add marine velocity to projectile to make if fly realistically
Vector marine_velocity = pMarine->GetAbsVelocity();
newVel = newVel + marine_velocity;
CASW_Flamer_Projectile::Flamer_Projectile_Create( GetWeaponDamage(), vecSrc, QAngle(0,0,0),
newVel, rotSpeed, pMarine, pMarine, this );
if (ASWGameRules())
ASWGameRules()->m_fLastFireTime = gpGlobals->curtime;
pMarine->OnWeaponFired( this, 1 );
}
#endif
// decrement ammo
m_iClip1 -= 1;
NotifyIfNoneClip1Ammo( pMarine );
/*
if (!m_iClip1 && pMarine->GetAmmoCount(m_iPrimaryAmmoType) <= 0)
{
// HEV suit - indicate out of ammo condition
if (pPlayer)
pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, 0);
}
*/
}
if (m_iClip1 > 0) // only force the fire wait time if we have ammo for another shot
{
m_flNextPrimaryAttack = gpGlobals->curtime + GetFireRate();
m_flNextSecondaryAttack = gpGlobals->curtime + GetFireRate();
}
else
{
m_flNextPrimaryAttack = gpGlobals->curtime;
}
m_flLastFireTime = gpGlobals->curtime;
}
void CASW_Weapon_Flamer::SecondaryAttack( void )
{
// If my clip is empty (and I use clips) start reload
if ( !rd_flamer_infinite_extinguisher.GetBool() && UsesClipsForAmmo1() && m_iClip1 < 2 )
{
#ifdef CLIENT_DLL
CASW_Player *pPlayer = GetCommander();
#else
CASW_Marine *pMarine = GetMarine();
CASW_Player *pPlayer = GetCommander();
if ( !pMarine || !pMarine->IsInhabited() )
pPlayer = NULL;
#endif // CLIENT_DLL
if ( pPlayer && pPlayer->ShouldAutoReload() )
Reload();
return;
}
// clear primary fire if we're secondary firing
if ( m_bIsFiring )
{
m_bIsFiring = false;
return;
}
CASW_Marine *pMarine = GetMarine();
if (pMarine) // firing from a marine
{
// MUST call sound before removing a round from the clip of a CMachineGun
//WeaponSound(SINGLE);
m_bIsSecondaryFiring = true;
// tell the marine to tell its weapon to draw the muzzle flash
pMarine->DoMuzzleFlash();
// sets the animation on the weapon model iteself
SendWeaponAnim( GetSecondaryAttackActivity() );
// sets the animation on the marine holding this weapon
#ifndef CLIENT_DLL
Vector vecSrc = pMarine->Weapon_ShootPosition( );
Vector vecAiming = vec3_origin;
CASW_Player *pPlayer = GetCommander();
if ( pPlayer && pMarine->IsInhabited() )
{
vecAiming = pPlayer->GetAutoaimVectorForMarine(pMarine, GetAutoAimAmount(), GetVerticalAdjustOnlyAutoAimAmount()); // 45 degrees = 0.707106781187
}
else
{
vecAiming = pMarine->GetActualShootTrajectory( vecSrc );
}
CShotManipulator Manipulator( vecAiming );
AngularImpulse rotSpeed(0,0,720);
// create a pellet at some random spread direction
Vector newVel = Manipulator.ApplySpread(GetBulletSpread());
if ( pMarine->GetWaterLevel() != 3 )
{
newVel *= EXTINGUISHER_PROJECTILE_AIR_VELOCITY;
newVel *= (1.0 + (0.1 * random->RandomFloat(-1,1)));
// aim it downwards a bit
newVel.z -= 40.0f;
CASW_Extinguisher_Projectile::Extinguisher_Projectile_Create( vecSrc, QAngle(0,0,0),
newVel, rotSpeed, pMarine, this );
// check for putting outselves out
if (pMarine->IsOnFire())
{
CEntityFlame *pFireChild = dynamic_cast<CEntityFlame *>( pMarine->GetEffectEntity() );
if ( pFireChild )
{
pMarine->SetEffectEntity( NULL );
UTIL_Remove( pFireChild );
}
pMarine->Extinguish( pMarine, this );
// spawn a cloud effect on this marine
CEffectData data;
data.m_vOrigin = pMarine->GetAbsOrigin();
//data.m_nEntIndex = pMarine->entindex();
CPASFilter filter( data.m_vOrigin );
filter.SetIgnorePredictionCull(true);
DispatchEffect( filter, 0.0, "ExtinguisherCloud", data );
}
pMarine->OnWeaponFired( this, 1, true );
}
#endif
if ( !rd_flamer_infinite_extinguisher.GetBool() )
{
// decrement ammo
m_iClip1 -= 2;
}
}
if (!rd_flamer_infinite_extinguisher.GetBool() || m_iClip1 > 0) // only force the fire wait time if we have ammo for another shot
{
m_flNextSecondaryAttack = gpGlobals->curtime + GetFireRate();
m_flNextPrimaryAttack = gpGlobals->curtime + GetFireRate();
}
else
{
m_flNextSecondaryAttack = gpGlobals->curtime;
}
m_flLastFireTime = gpGlobals->curtime;
}
void CASW_Weapon_Flamer::Precache()
{
PrecacheModel( "swarm/sprites/whiteglow1.vmt" );
PrecacheModel( "swarm/sprites/greylaser1.vmt" );
PrecacheScriptSound("ASW_Flamer.ReloadA");
PrecacheScriptSound("ASW_Flamer.ReloadB");
PrecacheScriptSound("ASW_Flamer.ReloadC");
PrecacheParticleSystem( "asw_flamethrower" );
PrecacheParticleSystem( "asw_fireextinguisher" );
BaseClass::Precache();
}
#ifdef CLIENT_DLL
// if true, the marine emits flames from his flame emitter
bool CASW_Weapon_Flamer::ShouldMarineFlame()
{
return IsFiring();
}
#endif
bool CASW_Weapon_Flamer::SupportsBayonet()
{
return true;
}
float CASW_Weapon_Flamer::GetWeaponBaseDamageOverride()
{
extern ConVar rd_flamer_dmg_base;
return rd_flamer_dmg_base.GetFloat();
}
int CASW_Weapon_Flamer::GetWeaponSkillId()
{
return ASW_MARINE_SKILL_ACCURACY;
}
int CASW_Weapon_Flamer::GetWeaponSubSkillId()
{
return ASW_MARINE_SUBSKILL_ACCURACY_FLAMER_DMG;
}
#ifdef CLIENT_DLL
const char* CASW_Weapon_Flamer::GetPartialReloadSound(int iPart)
{
switch (iPart)
{
case 1: return "ASW_Flamer.ReloadB"; break;
case 2: return "ASW_Flamer.ReloadC"; break;
default: break;
};
return "ASW_Flamer.ReloadA";
}
bool CASW_Weapon_Flamer::Simulate()
{
BaseClass::Simulate();
// hide our blue flame tip when appropriate
m_nSkin = (IsFiring() || m_bIsSecondaryFiring || IsReloading() || (Clip1() <= 0)) ? 0 : 1;
return true;
}
// if true, the marine emits fire extinguisher smoke from his emitter
bool CASW_Weapon_Flamer::ShouldMarineFireExtinguish()
{
return m_bIsSecondaryFiring;
}
#endif