forked from ValveSoftware/source-sdk-2013
-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathtf_weapon_flamethrower.cpp
More file actions
3214 lines (2739 loc) · 106 KB
/
tf_weapon_flamethrower.cpp
File metadata and controls
3214 lines (2739 loc) · 106 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
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// TF Flame Thrower
//
//=============================================================================
#include "cbase.h"
#include "tf_weapon_flamethrower.h"
#include "tf_fx_shared.h"
#include "in_buttons.h"
#include "ammodef.h"
#include "tf_gamerules.h"
#include "tf_weapon_rocketpack.h"
#include "debugoverlay_shared.h"
#include "soundenvelope.h"
#if defined( CLIENT_DLL )
#include "c_tf_player.h"
#include "vstdlib/random.h"
#include "engine/IEngineSound.h"
#include "prediction.h"
#include "haptics/ihaptics.h"
#include "c_tf_gamestats.h"
#else
#include "explode.h"
#include "tf_player.h"
#include "tf_gamestats.h"
#include "ilagcompensationmanager.h"
#include "collisionutils.h"
#include "tf_team.h"
#include "tf_obj.h"
#include "tf_weapon_grenade_pipebomb.h"
#include "particle_parse.h"
#include "tf_weaponbase_grenadeproj.h"
#include "tf_weapon_compound_bow.h"
#include "tf_projectile_arrow.h"
#include "NextBot/NextBotManager.h"
#include "halloween/merasmus/merasmus_trick_or_treat_prop.h"
#include "tf_logic_robot_destruction.h"
#include "tf_passtime_logic.h"
ConVar tf_flamethrower_velocity( "tf_flamethrower_velocity", "2300.0", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY, "Initial velocity of flame damage entities." );
ConVar tf_flamethrower_drag("tf_flamethrower_drag", "0.87", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY, "Air drag of flame damage entities." );
ConVar tf_flamethrower_float("tf_flamethrower_float", "50.0", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY, "Upward float velocity of flame damage entities." );
ConVar tf_flamethrower_vecrand("tf_flamethrower_vecrand", "0.05", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY, "Random vector added to initial velocity of flame damage entities." );
ConVar tf_flamethrower_maxdamagedist("tf_flamethrower_maxdamagedist", "350.0", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY, "Maximum damage distance for flamethrower." );
ConVar tf_flamethrower_shortrangedamagemultiplier("tf_flamethrower_shortrangedamagemultiplier", "1.2", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY, "Damage multiplier for close-in flamethrower damage." );
ConVar tf_flamethrower_velocityfadestart("tf_flamethrower_velocityfadestart", ".3", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY, "Time at which attacker's velocity contribution starts to fade." );
ConVar tf_flamethrower_velocityfadeend("tf_flamethrower_velocityfadeend", ".5", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY, "Time at which attacker's velocity contribution finishes fading." );
ConVar tf_flamethrower_burst_zvelocity( "tf_flamethrower_burst_zvelocity", "350", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY );
const float tf_flamethrower_burn_frequency = 0.075f;
const float tf_flamethrower_afterburn_rate = 0.4f;
static const char *s_pszFlameThrowerHitTargetThink = "FlameThrowerHitTargetThink";
#endif
ConVar tf_debug_flamethrower("tf_debug_flamethrower", "0", FCVAR_CHEAT | FCVAR_REPLICATED, "Visualize the flamethrower damage." );
ConVar tf_flamethrower_boxsize("tf_flamethrower_boxsize", "12.0", FCVAR_CHEAT | FCVAR_REPLICATED, "Size of flame damage entities.", true, 1.f, true, 24.f );
ConVar tf_flamethrower_new_flame_offset( "tf_flamethrower_new_flame_offset", "40 5 0", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY | FCVAR_REPLICATED, "Starting position relative to the flamethrower." );
const float tf_flamethrower_initial_afterburn_duration = 3.f;
const float tf_flamethrower_airblast_cone_angle = 35.0f;
#include "tf_pumpkin_bomb.h"
const float tf_flamethrower_new_flame_fire_delay = 0.02f;
const float tf_flamethrower_damage_per_tick = 13.f;
ConVar tf_flamethrower_burstammo("tf_flamethrower_burstammo", "20", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY | FCVAR_REPLICATED, "How much ammo does the air burst use per shot." );
ConVar tf_flamethrower_flametime("tf_flamethrower_flametime", "0.5", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY | FCVAR_REPLICATED, "Time to live of flame damage entities." );
// If we're shipping this it needs to be better hooked with flame manager -- right now we just spawn 5 managers for
// prototyping
#ifdef WATERFALL_FLAMETHROWER_TEST
// TODO: ConVars for easier for easier testing, but should be attributes for shipping?
// (TODO: Add con commands to modify stock attributes on the fly)
ConVar tf_flamethrower_waterfall_damage_per_tick( "tf_flamethrower_waterfall_damage_per_tick", "7", FCVAR_REPLICATED );
#endif // WATERFALL_FLAMETHROWER_TEST
#if defined( GAME_DLL )
// TODO These should be cheat upon shipping probably
ConVar tf_airblast_cray( "tf_airblast_cray", "1", FCVAR_CHEAT,
"Use alternate cray airblast logic globally." );
ConVar tf_airblast_cray_debug( "tf_airblast_cray_debug", "0", FCVAR_CHEAT,
"Enable debugging overlays & output for cray airblast. "
"Value is length of time to show debug overlays in seconds." );
ConVar tf_airblast_cray_power( "tf_airblast_cray_power", "600", FCVAR_CHEAT,
"Amount of force cray airblast should apply unconditionally. "
"Set to 0 to only perform player momentum reflection.");
ConVar tf_airblast_cray_power_relative( "tf_airblast_cray_power_relative", "0", FCVAR_CHEAT,
"If set, the blast power power also inherits from the blast's forward momentum." );
ConVar tf_airblast_cray_reflect_coeff( "tf_airblast_cray_reflect_coeff", "2", FCVAR_CHEAT,
"The coefficient of reflective power cray airblast employs.\n"
" 0 - No reflective powers\n"
" 0-1 - Cancel out some/all incoming velocity\n"
" 1-2 - Reflect some/all incoming velocity outwards\n"
" 2+ - Reflect incoming velocity outwards and then some\n" );
ConVar tf_airblast_cray_reflect_cost_coeff( "tf_airblast_cray_reflect_cost_coeff", "0.5", FCVAR_CHEAT,
"What portion of power used for reflection is removed from the push effect. "
"Note that reflecting incoming momentum requires 2x the momentum - "
"to first neutralize and then reverse it. Setting this to 1 means that a "
"target running towards the blast at more than 50% blast-speed would have "
"a net pushback half that of a stationary target, since half the power was "
"used to negate their incoming momentum. A value of 0.5 would mean that "
"running towards the blast would not be beneficial vs being still, while "
"values >.5 would make it beneficial to do so, and <.5 detrimental." );
ConVar tf_airblast_cray_reflect_relative( "tf_airblast_cray_reflect_relative", "0", FCVAR_CHEAT,
"If set, the relative, rather than absolute, target velocity is considered "
"for reflection." );
ConVar tf_airblast_cray_ground_reflect( "tf_airblast_cray_ground_reflect", "1", FCVAR_CHEAT,
"If set, cray airblast reflects any airblast power directed into the ground "
"off of it, to prevent ground-stuck and provide a bit more control over "
"up-vs-forward vectoring" );
ConVar tf_airblast_cray_ground_minz( "tf_airblast_cray_ground_minz", "100", FCVAR_CHEAT,
"If set, cray airblast ensures the target has this minimum Z velocity after "
"reflections and impulse have been applied. "
"Set to 268.3281572999747 for exact old airblast Z behavior." );
ConVar tf_airblast_cray_lose_footing_duration( "tf_airblast_cray_lose_footing_duration", "0.5", FCVAR_CHEAT,
"How long the player should be unable to regain their footing after "
"being airblast, separate from air-control stun." );
ConVar tf_airblast_cray_stun_duration( "tf_airblast_cray_stun_duration", "0", FCVAR_CHEAT,
"If set, apply this duration of stun when initially hit by an airblast. "
"Does not apply to repeated airblasts.", true, 0.0f, true, 1.0f );
ConVar tf_airblast_cray_stun_amount( "tf_airblast_cray_stun_amount", "0", FCVAR_CHEAT,
"Amount of control loss to apply if stun_duration is set.",
true, 0.0f, true, 1.0f );
ConVar tf_airblast_cray_pitch_control( "tf_airblast_cray_pitch_control", "0", FCVAR_CHEAT,
"If set, allow controlling the pitch of the airblast, in addition to the yaw." );
#endif // defined( GAME_DLL )
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
// position of end of muzzle relative to shoot position
#define TF_FLAMETHROWER_MUZZLEPOS_FORWARD 70.0f
#define TF_FLAMETHROWER_MUZZLEPOS_RIGHT 12.0f
#define TF_FLAMETHROWER_MUZZLEPOS_UP -12.0f
#define TF_FLAMETHROWER_AMMO_PER_SECOND_PRIMARY_ATTACK 14.0f
#define TF_FLAMETHROWER_HITACCURACY_MED 40.0f
#define TF_FLAMETHROWER_HITACCURACY_HIGH 60.0f
//-----------------------------------------------------------------------------
#define TF_WEAPON_BUBBLE_WAND_MODEL "models/player/items/pyro/mtp_bubble_wand.mdl"
//-----------------------------------------------------------------------------
#ifndef CLIENT_DLL
//-----------------------------------------------------------------------------
// Purpose: Only send to local player
//-----------------------------------------------------------------------------
void* SendProxy_SendLocalFlameThrowerDataTable( const SendProp *pProp, const void *pStruct, const void *pVarData, CSendProxyRecipients *pRecipients, int objectID )
{
// Get the weapon entity
CBaseCombatWeapon *pWeapon = (CBaseCombatWeapon*)pVarData;
if ( pWeapon )
{
// Only send this chunk of data to the player carrying this weapon
CBasePlayer *pPlayer = ToBasePlayer( pWeapon->GetOwner() );
if ( pPlayer )
{
pRecipients->SetOnly( pPlayer->GetClientIndex() );
return (void*)pVarData;
}
}
return NULL;
}
REGISTER_SEND_PROXY_NON_MODIFIED_POINTER( SendProxy_SendLocalFlameThrowerDataTable );
#endif // CLIENT_DLL
IMPLEMENT_NETWORKCLASS_ALIASED( TFFlameThrower, DT_WeaponFlameThrower )
//-----------------------------------------------------------------------------
// Purpose: Only sent to the local player
//-----------------------------------------------------------------------------
BEGIN_NETWORK_TABLE_NOBASE( CTFFlameThrower, DT_LocalFlameThrower )
#if defined( CLIENT_DLL )
RecvPropInt( RECVINFO( m_iActiveFlames ) ),
RecvPropInt( RECVINFO( m_iDamagingFlames ) ),
RecvPropEHandle( RECVINFO( m_hFlameManager ) ),
RecvPropBool( RECVINFO( m_bHasHalloweenSpell ) ),
#else
SendPropInt( SENDINFO( m_iActiveFlames ), 5, SPROP_UNSIGNED | SPROP_CHANGES_OFTEN ),
SendPropInt( SENDINFO( m_iDamagingFlames ), 10, SPROP_UNSIGNED | SPROP_CHANGES_OFTEN ),
SendPropEHandle( SENDINFO( m_hFlameManager ) ),
SendPropBool( SENDINFO( m_bHasHalloweenSpell ) ),
#endif
END_NETWORK_TABLE()
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
BEGIN_NETWORK_TABLE( CTFFlameThrower, DT_WeaponFlameThrower )
#if defined( CLIENT_DLL )
RecvPropInt( RECVINFO( m_iWeaponState ) ),
RecvPropBool( RECVINFO( m_bCritFire ) ),
RecvPropBool( RECVINFO( m_bHitTarget ) ),
RecvPropFloat( RECVINFO( m_flChargeBeginTime ) ),
RecvPropDataTable("LocalFlameThrowerData", 0, 0, &REFERENCE_RECV_TABLE( DT_LocalFlameThrower ) ),
#else
SendPropInt( SENDINFO( m_iWeaponState ), 4, SPROP_UNSIGNED | SPROP_CHANGES_OFTEN ),
SendPropBool( SENDINFO( m_bCritFire ) ),
SendPropBool( SENDINFO( m_bHitTarget ) ),
SendPropFloat( SENDINFO( m_flChargeBeginTime ) ),
SendPropDataTable("LocalFlameThrowerData", 0, &REFERENCE_SEND_TABLE( DT_LocalFlameThrower ), SendProxy_SendLocalFlameThrowerDataTable ),
#endif
END_NETWORK_TABLE()
#if defined( CLIENT_DLL )
BEGIN_PREDICTION_DATA( CTFFlameThrower )
DEFINE_PRED_FIELD( m_iWeaponState, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_bCritFire, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ),
DEFINE_FIELD( m_flChargeBeginTime, FIELD_FLOAT ),
END_PREDICTION_DATA()
#endif
LINK_ENTITY_TO_CLASS( tf_weapon_flamethrower, CTFFlameThrower );
PRECACHE_WEAPON_REGISTER( tf_weapon_flamethrower );
BEGIN_DATADESC( CTFFlameThrower )
END_DATADESC()
// ------------------------------------------------------------------------------------------------ //
// CTFFlameThrower implementation.
// ------------------------------------------------------------------------------------------------ //
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CTFFlameThrower::CTFFlameThrower()
#if defined( CLIENT_DLL )
: m_FlameEffects( this )
, m_MmmmphEffect( this )
#endif
{
WeaponReset();
#if defined( CLIENT_DLL )
m_pFiringStartSound = NULL;
m_pFiringLoop = NULL;
m_pFiringAccuracyLoop = NULL;
m_pFiringHitLoop = NULL;
m_bFiringLoopCritical = false;
m_pPilotLightSound = NULL;
m_pSpinUpSound = NULL;
m_szAccuracySound = NULL;
m_bEffectsThinking = false;
m_bFullRageEffect = false;
#else
m_flTimeToStopHitSound = 0;
#endif
m_flSecondaryAnimTime = 0.f;
m_bHasHalloweenSpell.Set( false );
m_flMinPrimaryAttackBurstTime = 0.f;
m_szParticleEffectBlue[0] = '\0';
m_szParticleEffectRed[0] = '\0';
m_szParticleEffectBlueCrit[0] = '\0';
m_szParticleEffectRedCrit[0] = '\0';
ListenForGameEvent( "recalculate_holidays" );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CTFFlameThrower::~CTFFlameThrower()
{
DestroySounds();
#if defined( CLIENT_DLL )
StopFullCritEffect();
#endif
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
const char *CTFFlameThrower::GetNewFlameEffectInternal( int nTeam, bool bCrit )
{
static CSchemaAttributeDefHandle pAttrDef_FireParticleBlue( "fire particle blue" );
static CSchemaAttributeDefHandle pAttrDef_FireParticleRed( "fire particle red" );
static CSchemaAttributeDefHandle pAttrDef_FireParticleBlueCrit( "fire particle blue crit" );
static CSchemaAttributeDefHandle pAttrDef_FireParticleRedCrit( "fire particle red crit" );
char *pszParticleEffect = ( nTeam == TF_TEAM_BLUE ) ? ( bCrit ? m_szParticleEffectBlueCrit : m_szParticleEffectBlue ) : ( bCrit ? m_szParticleEffectRedCrit : m_szParticleEffectRed );
if ( !pszParticleEffect[0] )
{
CEconItemView *pItem = GetAttributeContainer()->GetItem();
if ( pItem )
{
CAttribute_String attrModule;
const CEconItemAttributeDefinition *pAttrDef = ( nTeam == TF_TEAM_BLUE ) ? ( bCrit ? pAttrDef_FireParticleBlueCrit : pAttrDef_FireParticleBlue ) : ( bCrit ? pAttrDef_FireParticleRedCrit : pAttrDef_FireParticleRed );
if ( !pItem->FindAttribute( pAttrDef, &attrModule ) || !attrModule.has_value() )
{
V_strncpy( pszParticleEffect, bCrit ? ( ( nTeam == TF_TEAM_BLUE ) ? "new_flame_crit_blue" : "new_flame_crit_red" ) : "new_flame", MAX_PARTICLE_EFFECT_NAME_LENGTH );
}
else
{
V_strncpy( pszParticleEffect, attrModule.value().c_str(), MAX_PARTICLE_EFFECT_NAME_LENGTH );
}
}
}
return ( pszParticleEffect[0] ? pszParticleEffect : "new_flame" );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFFlameThrower::Precache( void )
{
BaseClass::Precache();
int iModelIndex = PrecacheModel( TF_WEAPON_BUBBLE_WAND_MODEL );
PrecacheGibsForModel( iModelIndex );
PrecacheParticleSystem( "pyro_blast" );
PrecacheParticleSystem( "flamethrower_rope" );
PrecacheScriptSound( "Weapon_FlameThrower.AirBurstAttack" );
PrecacheScriptSound( "TFPlayer.AirBlastImpact" );
PrecacheScriptSound( "Weapon_FlameThrower.AirBurstAttackDeflect" );
PrecacheParticleSystem( "deflect_fx" );
PrecacheParticleSystem( "drg_bison_idle" );
PrecacheParticleSystem( "medicgun_invulnstatus_fullcharge_blue" );
PrecacheParticleSystem( "medicgun_invulnstatus_fullcharge_red" );
PrecacheParticleSystem( "halloween_burningplayer_flyingbits" );
PrecacheParticleSystem( "torch_player_burn" );
PrecacheParticleSystem( "torch_red_core_1" );
// for airblast projectile turn into ammopack
PrecacheModel( "models/items/ammopack_small.mdl" );
#ifdef GAME_DLL
// only do this for the server here, since the client
// isn't ready for this yet when it calls into Precache()
PrecacheParticleSystem( GetNewFlameEffectInternal( TF_TEAM_BLUE, false ) );
PrecacheParticleSystem( GetNewFlameEffectInternal( TF_TEAM_BLUE, true ) );
PrecacheParticleSystem( GetNewFlameEffectInternal( TF_TEAM_RED, false ) );
PrecacheParticleSystem( GetNewFlameEffectInternal( TF_TEAM_RED, true ) );
#endif // GAME_DLL
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CTFFlameThrower::CanAirBlast() const
{
CTFPlayer *pOwner = GetTFPlayerOwner();
if ( !pOwner )
return false;
int iAirblastDisabled = 0;
CALL_ATTRIB_HOOK_INT( iAirblastDisabled, airblast_disabled );
return ( iAirblastDisabled == 0 );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CTFFlameThrower::CanAirBlastPushPlayer() const
{
CTFPlayer *pOwner = GetTFPlayerOwner();
if ( !pOwner )
return false;
if ( !CanAirBlast() )
return false;
int iNoPushPlayer = 0;
CALL_ATTRIB_HOOK_INT( iNoPushPlayer, airblast_pushback_disabled );
return ( iNoPushPlayer == 0 );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CTFFlameThrower::CanAirBlastDeflectProjectile() const
{
CTFPlayer *pOwner = GetTFPlayerOwner();
if ( !pOwner )
return false;
if ( !CanAirBlast() )
return false;
int iDeflectProjectilesDisabled = 0;
CALL_ATTRIB_HOOK_INT( iDeflectProjectilesDisabled, airblast_deflect_projectiles_disabled );
return ( iDeflectProjectilesDisabled == 0 );
}
bool CTFFlameThrower::CanAirBlastPutOutTeammate() const
{
CTFPlayer *pOwner = GetTFPlayerOwner();
if ( !pOwner )
return false;
if ( !CanAirBlast() )
return false;
int iPutOutTeammateDisabled = 0;
CALL_ATTRIB_HOOK_INT( iPutOutTeammateDisabled, airblast_put_out_teammate_disabled );
return ( iPutOutTeammateDisabled == 0 );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFFlameThrower::DestroySounds( void )
{
#if defined( CLIENT_DLL )
CSoundEnvelopeController &controller = CSoundEnvelopeController::GetController();
if ( m_pFiringStartSound )
{
controller.SoundDestroy( m_pFiringStartSound );
m_pFiringStartSound = NULL;
}
if ( m_pFiringLoop )
{
controller.SoundDestroy( m_pFiringLoop );
m_pFiringLoop = NULL;
}
if ( m_pPilotLightSound )
{
controller.SoundDestroy( m_pPilotLightSound );
m_pPilotLightSound = NULL;
}
if ( m_pSpinUpSound )
{
controller.SoundDestroy( m_pSpinUpSound );
m_pSpinUpSound = NULL;
}
if ( m_pFiringAccuracyLoop )
{
controller.SoundDestroy( m_pFiringAccuracyLoop );
m_pFiringAccuracyLoop = NULL;
}
StopHitSound();
#endif
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFFlameThrower::WeaponReset( void )
{
BaseClass::WeaponReset();
SetWeaponState( FT_STATE_IDLE );
m_bCritFire = false;
m_bHitTarget = false;
m_flStartFiringTime = 0.f;
m_flMinPrimaryAttackBurstTime = 0.f;
m_flAmmoUseRemainder = 0.f;
m_flChargeBeginTime = 0.f;
m_flSpinupBeginTime = 0.f;
ResetFlameHitCount();
DestroySounds();
#if defined( CLIENT_DLL )
StopFullCritEffect();
#endif
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFFlameThrower::WeaponIdle( void )
{
BaseClass::WeaponIdle();
SetWeaponState( FT_STATE_IDLE );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFFlameThrower::Spawn( void )
{
m_iAltFireHint = HINT_ALTFIRE_FLAMETHROWER;
BaseClass::Spawn();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFFlameThrower::UpdateOnRemove( void )
{
#ifdef CLIENT_DLL
m_FlameEffects.StopEffects();
m_MmmmphEffect.StopEffects();
StopPilotLight();
StopFullCritEffect();
m_bEffectsThinking = false;
#endif // CLIENT_DLL
BaseClass::UpdateOnRemove();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CTFFlameThrower::CanInspect() const
{
return BaseClass::CanInspect() && !IsFiring();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CTFFlameThrower::Holster( CBaseCombatWeapon *pSwitchingTo )
{
SetWeaponState( FT_STATE_IDLE );
m_bCritFire = false;
m_bHitTarget = false;
m_flChargeBeginTime = 0;
#if defined ( CLIENT_DLL )
StopFlame();
StopPilotLight();
StopFullCritEffect();
m_bEffectsThinking = false;
#endif
return BaseClass::Holster( pSwitchingTo );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFFlameThrower::ItemPostFrame()
{
if ( m_bLowered )
return;
// Get the player owning the weapon.
CTFPlayer *pOwner = GetTFPlayerOwner();
if ( !pOwner )
return;
#ifdef CLIENT_DLL
if ( !m_bEffectsThinking )
{
m_bEffectsThinking = true;
SetContextThink( &CTFFlameThrower::ClientEffectsThink, gpGlobals->curtime, "EFFECTS_THINK" );
}
#endif
int iAmmo = pOwner->GetAmmoCount( m_iPrimaryAmmoType );
m_bFiredSecondary = false;
if ( pOwner->IsAlive() && ( pOwner->m_nButtons & IN_ATTACK2 ) )
{
SecondaryAttack();
}
// Fixes an exploit where the airblast effect repeats while +attack is active
if ( m_bFiredBothAttacks )
{
if ( pOwner->m_nButtons & IN_ATTACK && !( pOwner->m_nButtons & IN_ATTACK2 ) )
{
pOwner->m_nButtons &= ~IN_ATTACK;
}
m_bFiredBothAttacks = false;
}
if ( !( pOwner->m_nButtons & IN_ATTACK ) )
{
// We were forced to fire, but time's up
if ( m_flMinPrimaryAttackBurstTime > 0.f && gpGlobals->curtime > m_flMinPrimaryAttackBurstTime )
{
m_flMinPrimaryAttackBurstTime = 0.f;
#ifdef GAME_DLL
if ( m_hFlameManager )
{ m_hFlameManager->StopFiring(); }
#endif // GAME_DLL
//DevMsg( "Stop Firing\n" );
}
}
if ( pOwner->m_nButtons & IN_ATTACK && pOwner->m_nButtons & IN_ATTACK2 )
{
m_bFiredBothAttacks = true;
}
// Force a min window of emission to prevent a case where
// tap-spamming +attack can create invisible flame points.
bool bForceFire = ( m_flMinPrimaryAttackBurstTime > 0.f && gpGlobals->curtime < m_flMinPrimaryAttackBurstTime );
if ( !m_bFiredSecondary )
{
bool bSpinDown = m_flSpinupBeginTime > 0.0f;
if ( pOwner->IsAlive() && ( ( pOwner->m_nButtons & IN_ATTACK ) || bForceFire ) && iAmmo > 0 )
{
PrimaryAttack();
bSpinDown = false;
}
else if ( m_iWeaponState > FT_STATE_IDLE && m_iWeaponState != FT_STATE_SECONDARY )
{
SendWeaponAnim( ACT_MP_ATTACK_STAND_POSTFIRE );
pOwner->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_POST );
SetWeaponState( FT_STATE_IDLE );
m_bCritFire = false;
m_bHitTarget = false;
}
if ( bSpinDown )
{
m_flSpinupBeginTime = 0.0f;
#if defined( CLIENT_DLL )
if ( m_pSpinUpSound )
{
float flSpinUpTime = GetSpinUpTime();
CSoundEnvelopeController &controller = CSoundEnvelopeController::GetController();
controller.SoundChangePitch( m_pSpinUpSound, 40, flSpinUpTime * 0.5f );
controller.SoundChangeVolume( m_pSpinUpSound, 0.0f, flSpinUpTime * 2.0f );
}
#endif
}
}
if ( !( ( pOwner->m_nButtons & IN_ATTACK ) || ( pOwner->m_nButtons & IN_RELOAD ) || ( pOwner->m_nButtons & IN_ATTACK2 ) || m_bFiredSecondary ) && !bForceFire )
{
// no fire buttons down or reloading
if ( !ReloadOrSwitchWeapons() && ( m_bInReload == false ) && m_flSecondaryAnimTime < gpGlobals->curtime )
{
WeaponIdle();
}
}
// charged airblast
int iChargedAirblast = 0;
CALL_ATTRIB_HOOK_INT( iChargedAirblast, set_charged_airblast );
if ( iChargedAirblast != 0 )
{
if ( m_flChargeBeginTime > 0 )
{
// If we're not holding down the attack button, launch the flame rocket
if ( !(pOwner->m_nButtons & IN_ATTACK2) )
{
//FireProjectile( pOwner );
float flMultAmmoPerShot = 1.0f;
CALL_ATTRIB_HOOK_FLOAT( flMultAmmoPerShot, mult_airblast_cost );
int iAmmoPerShot = tf_flamethrower_burstammo.GetInt() * flMultAmmoPerShot;
FireAirBlast( iAmmoPerShot );
}
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFFlameThrower::PrimaryAttack()
{
float flSpinUpTime = GetSpinUpTime();
if ( flSpinUpTime > 0.0f )
{
if ( m_flSpinupBeginTime > 0.0f )
{
if ( gpGlobals->curtime - m_flSpinupBeginTime < flSpinUpTime )
{
return;
}
}
else
{
m_flSpinupBeginTime = gpGlobals->curtime;
#if defined( CLIENT_DLL )
CSoundEnvelopeController &controller = CSoundEnvelopeController::GetController();
if ( !m_pSpinUpSound )
{
// Create the looping pilot light sound
const char *pchSpinUpSound = GetShootSound( RELOAD );
CLocalPlayerFilter filter;
m_pSpinUpSound = controller.SoundCreate( filter, entindex(), pchSpinUpSound );
controller.Play( m_pSpinUpSound, 0.0f, 40 );
}
if ( m_pSpinUpSound )
{
controller.SoundChangePitch( m_pSpinUpSound, 100, flSpinUpTime );
controller.SoundChangeVolume( m_pSpinUpSound, 1.0f, flSpinUpTime * 0.1f );
}
#endif
return;
}
}
// Are we capable of firing again?
if ( m_flNextPrimaryAttack > gpGlobals->curtime )
return;
// Get the player owning the weapon.
CTFPlayer *pOwner = GetTFPlayerOwner();
if ( !pOwner )
return;
if ( !CanAttack() )
{
#if defined ( CLIENT_DLL )
StopFlame();
#endif
SetWeaponState( FT_STATE_IDLE );
return;
}
m_iWeaponMode = TF_WEAPON_PRIMARY_MODE;
CalcIsAttackCritical();
// Because the muzzle is so long, it can stick through a wall if the player is right up against it.
// Make sure the weapon can't fire in this condition by tracing a line between the eye point and the end of the muzzle.
trace_t trace;
Vector vecEye = pOwner->EyePosition();
Vector vecMuzzlePos = GetVisualMuzzlePos();
CTraceFilterIgnoreObjects traceFilter( this, COLLISION_GROUP_NONE );
UTIL_TraceLine( vecEye, vecMuzzlePos, MASK_SOLID, &traceFilter, &trace );
if ( trace.fraction < 1.0 && ( !trace.m_pEnt || trace.m_pEnt->m_takedamage == DAMAGE_NO ) )
{
// there is something between the eye and the end of the muzzle, most likely a wall, don't fire, and stop firing if we already are
if ( m_iWeaponState > FT_STATE_IDLE )
{
#if defined ( CLIENT_DLL )
StopFlame();
#endif
SetWeaponState( FT_STATE_IDLE );
}
return;
}
switch ( m_iWeaponState )
{
case FT_STATE_IDLE:
{
// Just started, play PRE and start looping view model anim
pOwner->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRE );
SendWeaponAnim( ACT_VM_PRIMARYATTACK );
m_flStartFiringTime = gpGlobals->curtime + 0.16; // 5 frames at 30 fps
// Force a min window of emission to prevent a case where
// tap-spamming +attack can create invisible flame points.
if ( m_flMinPrimaryAttackBurstTime == 0.f )
{
m_flMinPrimaryAttackBurstTime = gpGlobals->curtime + 0.2f;
}
SetWeaponState( FT_STATE_STARTFIRING );
}
break;
case FT_STATE_STARTFIRING:
{
// if some time has elapsed, start playing the looping third person anim
if ( gpGlobals->curtime > m_flStartFiringTime )
{
SetWeaponState( FT_STATE_FIRING );
m_flNextPrimaryAttackAnim = gpGlobals->curtime;
}
}
break;
case FT_STATE_FIRING:
{
if ( gpGlobals->curtime >= m_flNextPrimaryAttackAnim )
{
pOwner->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY );
m_flNextPrimaryAttackAnim = gpGlobals->curtime + 1.4; // fewer than 45 frames!
}
}
break;
default:
break;
}
#ifdef CLIENT_DLL
// Restart our particle effect if we've transitioned across water boundaries
if ( m_iParticleWaterLevel != -1 && pOwner->GetWaterLevel() != m_iParticleWaterLevel )
{
if ( m_iParticleWaterLevel == WL_Eyes || pOwner->GetWaterLevel() == WL_Eyes )
{
RestartParticleEffect();
}
}
#endif
#if !defined (CLIENT_DLL)
// Let the player remember the usercmd he fired a weapon on. Assists in making decisions about lag compensation.
pOwner->NoteWeaponFired();
pOwner->SpeakWeaponFire();
CTF_GameStats.Event_PlayerFiredWeapon( pOwner, m_bCritFire );
// Move other players back to history positions based on local player's lag
lagcompensation->StartLagCompensation( pOwner, pOwner->GetCurrentCommand() );
// PASSTIME custom lag compensation for the ball; see also tf_fx_shared.cpp
// it would be better if all entities could opt-in to this, or a way for lagcompensation to handle non-players automatically
if ( g_pPasstimeLogic && g_pPasstimeLogic->GetBall() )
{
g_pPasstimeLogic->GetBall()->StartLagCompensation( pOwner, pOwner->GetCurrentCommand() );
}
#endif
#ifdef CLIENT_DLL
C_CTF_GameStats.Event_PlayerFiredWeapon( pOwner, IsCurrentAttackACrit() );
#endif
float flFiringInterval = m_pWeaponInfo->GetWeaponData( m_iWeaponMode ).m_flTimeFireDelay;
{
flFiringInterval = tf_flamethrower_new_flame_fire_delay;
}
// Don't attack if we're underwater
if ( pOwner->GetWaterLevel() != WL_Eyes )
{
// Find eligible entities in a cone in front of us.
// Vector vOrigin = pOwner->Weapon_ShootPosition();
Vector vForward, vRight, vUp;
QAngle vAngles = pOwner->EyeAngles() + pOwner->GetPunchAngle();
AngleVectors( vAngles, &vForward, &vRight, &vUp );
#define NUM_TEST_VECTORS 30
#ifdef CLIENT_DLL
bool bWasCritical = m_bCritFire;
#endif
// Burn & Ignite 'em
int iDmgType = g_aWeaponDamageTypes[ GetWeaponID() ];
m_bCritFire = IsCurrentAttackACrit();
if ( m_bCritFire )
{
iDmgType |= DMG_CRITICAL;
}
#ifdef CLIENT_DLL
if ( bWasCritical != m_bCritFire )
{
RestartParticleEffect();
}
#endif
#ifdef GAME_DLL
// create the flame entity
int iDamagePerSec = m_pWeaponInfo->GetWeaponData( m_iWeaponMode ).m_nDamage;
float flDamage = (float)iDamagePerSec * flFiringInterval;
{
flDamage = tf_flamethrower_damage_per_tick;
}
#ifdef WATERFALL_FLAMETHROWER_TEST
int iWaterfallMode = 0;
CALL_ATTRIB_HOOK_INT( iWaterfallMode, flame_waterfall );
if ( iWaterfallMode )
{
flDamage = tf_flamethrower_waterfall_damage_per_tick.GetFloat();
}
#endif
CALL_ATTRIB_HOOK_FLOAT( flDamage, mult_dmg );
int iCritFromBehind = 0;
CALL_ATTRIB_HOOK_INT( iCritFromBehind, set_flamethrower_back_crit );
{
if ( !m_hFlameManager )
{
m_hFlameManager = CTFFlameManager::Create( this );
// This is a hack(?). Right now, the flame manager goes outside of the shooter's
// own PVS when they get very close to a wall (or just looks down), so we end
// up creating flame managers repeatedly for the same burst of flames. This
// call ensures that the new manager will create particle effects.
//
// The *real* fix is to figure out how to get the flame manager to not go out
// of the shooter's PVS ever.
m_hFlameManager->StartFiring();
}
if ( m_hFlameManager )
{
// update damage state
m_hFlameManager->UpdateDamage( iDmgType, flDamage, tf_flamethrower_burn_frequency, iCritFromBehind == 1 );
m_hFlameManager->AddPoint( TIME_TO_TICKS( gpGlobals->curtime ) );
}
}
// Pyros can become invis in some game modes. Hitting fire normally handles this,
// but in the case of flamethrowers it's likely that stealth will be applied while
// the fire button is down, so we have to call into RemoveInvisibility here, too.
if ( pOwner->m_Shared.IsStealthed() )
{
pOwner->RemoveInvisibility();
}
#endif
}
#ifdef GAME_DLL
// Figure how much ammo we're using per shot and add it to our remainder to subtract. (We may be using less than 1.0 ammo units
// per frame, depending on how constants are tuned, so keep an accumulator so we can expend fractional amounts of ammo per shot.)
// Note we do this only on server and network it to client. If we predict it on client, it can get slightly out of sync w/server
// and cause ammo pickup indicators to appear
float flAmmoPerSecond = TF_FLAMETHROWER_AMMO_PER_SECOND_PRIMARY_ATTACK;
CALL_ATTRIB_HOOK_FLOAT( flAmmoPerSecond, mult_flame_ammopersec );
m_flAmmoUseRemainder += flAmmoPerSecond * flFiringInterval;
// take the integer portion of the ammo use accumulator and subtract it from player's ammo count; any fractional amount of ammo use
// remains and will get used in the next shot
int iAmmoToSubtract = (int) m_flAmmoUseRemainder;
if ( iAmmoToSubtract > 0 )
{
pOwner->RemoveAmmo( iAmmoToSubtract, m_iPrimaryAmmoType );
m_flAmmoUseRemainder -= iAmmoToSubtract;
// round to 2 digits of precision
m_flAmmoUseRemainder = (float) ( (int) (m_flAmmoUseRemainder * 100) ) / 100.0f;
}
#endif
m_flNextPrimaryAttack = gpGlobals->curtime + flFiringInterval;
m_flTimeWeaponIdle = gpGlobals->curtime + flFiringInterval;
#if !defined (CLIENT_DLL)
lagcompensation->FinishLagCompensation( pOwner );
// PASSTIME custom lag compensation for the ball; see also tf_fx_shared.cpp
// it would be better if all entities could opt-in to this, or a way for lagcompensation to handle non-players automatically
if ( g_pPasstimeLogic && g_pPasstimeLogic->GetBall() )
{
g_pPasstimeLogic->GetBall()->FinishLagCompensation( pOwner );
}
#endif
pOwner->m_Shared.OnAttack();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
float AirBurstDamageForce( const Vector &size, float damage, float scale )
{
float force = damage * ((48 * 48 * 82.0) / (size.x * size.y * size.z)) * scale;
if ( force > 1000.0)
{
force = 1000.0;
}
return force;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFFlameThrower::FireAirBlast( int iAmmoPerShot )
{
CTFPlayer *pOwner = GetTFPlayerOwner();
if ( !pOwner )
return;
m_bFiredSecondary = true;
#ifdef CLIENT_DLL
// Stop the flame if we're currently firing
StopFlame( false );
#endif
SetWeaponState( FT_STATE_SECONDARY );
SendWeaponAnim( ACT_VM_SECONDARYATTACK );
pOwner->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_SECONDARY );
m_flSecondaryAnimTime = gpGlobals->curtime + SequenceDuration( GetSequence() );
#ifdef GAME_DLL
int nDash = 0;
CALL_ATTRIB_HOOK_INT( nDash, airblast_dashes );
if ( !nDash )
{
DeflectProjectiles();
}
else