/
ff_player.cpp
7998 lines (6617 loc) · 240 KB
/
ff_player.cpp
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 © 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose: Player for HL1.
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "ff_player.h"
#include "ff_entity_system.h" // Entity system
#include "ff_scriptman.h"
#include "ff_luacontext.h"
#include "ff_gamerules.h"
#include "ff_weapon_base.h"
#include "ff_weapon_baseclip.h"
#include "predicted_viewmodel.h"
#include "iservervehicle.h"
#include "viewport_panel_names.h"
#include "EntityFlame.h"
#include "rumble_shared.h"
#include "soundent.h"
#include "nav_mesh.h"
#include "ff_item_flag.h"
#include "ff_utils.h"
#include "ff_grenade_base.h"
#include "ff_buildableobjects_shared.h"
#include "ff_item_backpack.h"
#include "ff_team.h" // team info
#include "in_buttons.h" // for in_attack2
#include "ff_projectile_pipebomb.h"
#include "ff_grenade_emp.h"
#include "ff_lualib_constants.h"
#include "client.h"
#include "gib.h"
#include "omnibot_interface.h"
#include "te_effect_dispatch.h"
// added these so I could cast to check for grenades that are not derived from projectile base
// Could probably do it more cleanly but I just went with what was already in place. -> Defrag
#include "ff_grenade_napalmlet.h"
extern int gEvilImpulse101;
#define FF_PLAYER_MODEL "models/player/demoman/demoman.mdl"
// Oh no a gobal.
int g_iLimbs[CLASS_CIVILIAN + 1][5] = { { 0 } };
#define PIPE_DET_DELAY 0.55 // this is mirrored in ff_projectile_pipebomb.cpp and ff_player_shared.cpp
// grenade information
//ConVar gren_timer("ffdev_gren_timer","3.81",0,"Timer length for all grenades.");
#define GREN_TIMER 3.81f
//ConVar gren_throw_delay("ffdev_throw_delay","0.5",0,"Delay before primed grenades can be thrown.");
#define GREN_THROW_DELAY 0.5f
//ConVar gren_speed("ffdev_gren_speed","500.0",0,"Speed grenades are thrown at.");
//ConVar gren_spawn_ang_x("ffdev_gren_spawn_ang_x","18.5",0,"X axis rotation grenades spawn at.");
#define GREN_SPAWN_ANG_X 18.5f
//ConVar gren_forward_offset("ffdev_gren_forward_offset","8",0,"Forward offset grenades spawn at in front of the player.");
#define BURN_TICK_INTERVAL 1.25f
//ConVar burn_damage_ic("ffdev_burn_damage_ic","7.0",0,"Burn damage of the Incendiary Cannon (per tick)");
//ConVar burn_damage_ng("ffdev_burn_damage_ng","7.0",0,"Burn damage of the Napalm Grenade (per tick)");
//ConVar burn_damage_ft("ffdev_burn_damage_ft","15.0",0,"Burn damage of the Flamethrower (per tick)");
#define BURN_DAMAGE_BASE 13.0f
//ConVar burn_ticks("ffdev_burn_ticks","6",0,"Number of burn ticks for pyro weapons.");
#define BURN_TICKS 6
//ConVar burn_multiplier_3burns("ffdev_burn_multiplier_3burns","5",0,"Burn damage multiplier for all 3 burn types.");
#define BURN_MULTIPLIER_3BURNS 5.0f
//ConVar burn_multiplier_2burns("ffdev_burn_multiplier_2burns","2.5",0,"Burn damage multiplier for 2 burn types.");
#define BURN_MULTIPLIER_2BURNS 2.0f
//ConVar ffdev_flamesize_burn1("ffdev_flamesize_burn1","0.015", FCVAR_FF_FFDEV_REPLICATED, "flame size multiplier for burn level 1");
#define FFDEV_FLAMESIZE_BURN1 0.015f //ffdev_flamesize_burn1.GetFloat()
//ConVar ffdev_flamesize_burn2("ffdev_flamesize_burn2","0.04", FCVAR_FF_FFDEV_REPLICATED, "flame size multiplier for burn level 2");
#define FFDEV_FLAMESIZE_BURN2 0.03f //ffdev_flamesize_burn2.GetFloat()
//ConVar ffdev_flamesize_burn3("ffdev_flamesize_burn3","0.055", FCVAR_FF_FFDEV_REPLICATED, "flame size multiplier for burn level 3");
#define FFDEV_FLAMESIZE_BURN3 0.045f //ffdev_flamesize_burn3.GetFloat()
// [integer] Max distance a player can be from us to be shown
//static ConVar radiotag_distance( "ffdev_radiotag_distance", "1024" );
#define RADIOTAG_DISTANCE 1024
// [float] Time between radio tag updates
//static ConVar radiotag_duration( "ffdev_radiotag_duration", "0.25" );
#define RADIOTAG_DURATION 0.25f
// [integer] Time in seconds you will stay 'tagged' once hit by a radio tag rifle round
//static ConVar radiotag_draw_duration( "ffdev_radiotag_draw_duration", "60" );
#define RADIOTAG_DRAW_DURATION 15
// [float] Time between updating the players location
//static ConVar location_update_frequency( "ffdev_location_update_frequency", "0.5" );
#define LOCATION_UPDATE_FREQUENCY 0.5f
//ConVar ffdev_changeclass_graceperiod( "ffdev_changeclass_graceperiod", "", "5", FCVAR_CHEATS | FCVAR_NOTIFY, "You can only change class once per grace period without getting a 5 second respawn delay" );
#define CHANGECLASS_GRACEPERIOD 5.0f
// status effect
//ConVar ffdev_infect_freq("ffdev_infect_freq","2",0,"Frequency (in seconds) a player loses health from an infection");
#define FFDEV_INFECT_FREQ 2.0f
//ConVar ffdev_infect_damage("ffdev_infect_damage","30",FCVAR_FF_FFDEV_REPLICATED,"Damage of the first infection tick (future ticks are modified by the infect_damagepertick_ vars)");
#define FFDEV_INFECT_DAMAGE 30.0f //ffdev_infect_damage.GetFloat()
//extern ConVar ffdev_infect_numticks; // in ff_player_shared.cpp
#define FFDEV_INFECT_NUMTICKS 10
//ConVar ffdev_infect_damagepertick_mult("ffdev_infect_damagepertick_mult","1",FCVAR_FF_FFDEV_REPLICATED,"Infection tick damage is multiplied by this number each tick");
#define FFDEV_INFECT_DAMAGEPERTICK_MULT 1 //ffdev_infect_damagepertick_mult.GetFloat()
//ConVar ffdev_infect_damagepertick_exp("ffdev_infect_damagepertick_exp",".8",FCVAR_FF_FFDEV_REPLICATED,"Infection tick damage is raised to this power each tick");
#define FFDEV_INFECT_DAMAGEPERTICK_EXP 0.8f //ffdev_infect_damagepertick_exp.GetFloat()
//ConVar ffdev_infect_regaindamage("ffdev_infect_regaindamage","10",FCVAR_FF_FFDEV_REPLICATED,"Amount of damage that is not regained after infection wears off");
#define FFDEV_INFECT_REGAINDAMAGE 10.0f //ffdev_infect_regaindamage.GetFloat()
//ConVar ffdev_regen_freq("ffdev_regen_freq","3",0,"Frequency (in seconds) a player loses health when a medic");
#define FFDEV_REGEN_FREQ 3.0f
//ConVar ffdev_regen_health("ffdev_regen_health","2",0,"Amount of health a player gains while a medic");
#define FFDEV_REGEN_HEALTH 2
//ConVar ffdev_regen_armor("ffdev_regen_armor","4",0,"Amount of armor a player gains while a engy");
#define FFDEV_REGEN_ARMOR 4
//ConVar ffdev_overhealth_freq("ffdev_overhealth_freq","3",0,"Frequency (in seconds) a player loses health when health > maxhealth");
#define FFDEV_OVERHEALTH_FREQ 3.0f
//ConVar ffdev_infection_time( "ffdev_infection_time", "14", FCVAR_FF_FFDEV_REPLICATED, "Amount of time for infection to last( in seconds )" );
#define FFDEV_INFECTION_TIME 14 //ffdev_infection_time.GetFloat()
//ConVar ffdev_immune_time( "ffdev_immune_time", "2", FCVAR_FF_FFDEV_REPLICATED, "Amount of time for immunity to last( in seconds )" );
#define FFDEV_IMMUNE_TIME 2 //ffdev_immune_time.GetFloat()
//ConVar ffdev_dmgforfullslow("ffdev_dmgforfullslow","90",FCVAR_FF_FFDEV_REPLICATED ,"When getting hit and player is moving above run speed, he gets slowed down in proportion to this damage");
#define FFDEV_DMGFORFULLSLOW 90.0f //ffdev_dmgforfullslow.GetFloat()
//ConVar ffdev_dmgforfullslow_sg("ffdev_dmgforfullslow_sg","90",FCVAR_FF_FFDEV_REPLICATED ,"When getting hit by a SG and player is moving above run speed, he gets slowed down in proportion to this damage");
#define FFDEV_DMGFORFULLSLOW_SG 90.0f //ffdev_dmgforfullslow_sg.GetFloat()
//static ConVar jerkmulti( "ffdev_concuss_jerkmulti", "0.0004", 0, "Amount to jerk view on conc" );
#define JERKMULTI 0.0004f
ConVar ffdev_gibdamage("ffdev_gibdamage", "50", FCVAR_FF_FFDEV_REPLICATED, "If a players health is -(ffdev_gibdamage's value) or less after death, then they will gib instead of ragdoll");
#define FFDEV_GIBDAMAGE ffdev_gibdamage.GetFloat()
extern ConVar sv_maxspeed;
extern ConVar mp_friendlyfire_armorstrip;
//ConVar ffdev_spy_cloakfadespeed( "ffdev_spy_cloaktime", "1", FCVAR_REPLICATED, "Time it takes to cloak (fade out to cloak)" );
#define FFDEV_SPY_CLOAKFADESPEED 1.0f
//ConVar ffdev_spy_scloakfadespeed( "ffdev_spy_scloaktime", ".3", FCVAR_REPLICATED, "Time it takes to silent cloak (fade out to cloak)" );
#define FFDEV_SPY_SCLOAKFADESPEED 0.3f
//ConVar ffdev_spy_speedenforcewait( "ffdev_spy_speedenforcewait", "2", FCVAR_REPLICATED, "Time after cloaking a spys' speed will get enforced to the max cloak speed" );
#define FFDEV_SPY_SPEEDENFORCEWAIT 2.0f
//ConVar ffdev_spy_cloakzvel( "ffdev_spy_cloakzvel", "0.5", FCVAR_REPLICATED, "To tweak z factor of velocity when spy is cloaked" );
#define FFDEV_SPY_CLOAKZVEL 0.5f
//ConVar ffdev_gren_throwspeed( "ffdev_gren_throwspeed", "660", FCVAR_FF_FFDEV_REPLICATED );
#define GREN_THROWSPEED 660.0f
#ifdef _DEBUG
// --------------------------------------------------------------------------------
// Purpose: To spawn a model for testing - REMOVE (or disable) for release
//
// Bug #0000605: Rebo would like a way to spawn models on the fly in game to test stuff
// --------------------------------------------------------------------------------
class CFFModelTemp : public CBaseAnimating
{
public:
DECLARE_CLASS( CFFModelTemp, CBaseAnimating );
CFFModelTemp( void ) { m_hModel = NULL; }
~CFFModelTemp( void ) {}
const char *m_hModel;
void Spawn( void )
{
if( m_hModel )
PrecacheModel( m_hModel );
BaseClass::Precache();
if( m_hModel )
SetModel( m_hModel );
}
static CFFModelTemp *Create( const char *szModel, const Vector& vecOrigin, const QAngle& vecAngles )
{
CFFModelTemp *pObject = ( CFFModelTemp * )CBaseEntity::Create( "ff_model_temp", vecOrigin, vecAngles );
pObject->m_hModel = szModel;
pObject->Spawn();
return pObject;
}
};
LINK_ENTITY_TO_CLASS( ff_model_temp, CFFModelTemp );
CON_COMMAND( model_temp, "Spawn a temporary model. Usage: model_temp <model> <distance_in_front_of_player>" )
{
if( ( engine->Cmd_Argc() > 2 ) && ( engine->Cmd_Argc() < 4 ) )
{
CFFPlayer *pPlayer = ToFFPlayer( UTIL_GetCommandClient() );
if( !pPlayer )
return;
Vector vecOrigin, vecForward, vecRight;
// Get some info from the player...
vecOrigin = pPlayer->GetAbsOrigin();
pPlayer->EyeVectors( &vecForward, &vecRight );
vecForward.z = 0;
// Normalize
VectorNormalize( vecForward );
vecOrigin += ( vecForward * atof( engine->Cmd_Argv(2) ) );
QAngle vecAngles;
VectorAngles( vecForward, vecAngles );
CFFModelTemp::Create( engine->Cmd_Argv(1), vecOrigin, vecAngles );
}
else
{
ClientPrint(UTIL_GetCommandClient(), HUD_PRINTCONSOLE, "Usage: model_temp <model> <distance_in_front_of_player>\n");
}
}
#endif
// --------------------------------------------------------------------------------
// Purpose: Kill the player and set a 5 second spawn delay
// Stolen from client.cpp for easier interfacing w/ CFFPlayer
// --------------------------------------------------------------------------------
void CC_Player_Kill( void )
{
CFFPlayer *pPlayer = ToFFPlayer( UTIL_GetCommandClient() );
if (pPlayer)
{
// Don't kill if we're a spec or something
if( pPlayer->GetTeamNumber() < TEAM_BLUE )
return;
// Bug #0000578: Suiciding using /kill doesn't cause a respawn delay
if( pPlayer->IsAlive() )
{
CFFLuaSC hPlayerOnKill;
hPlayerOnKill.Push(pPlayer);
if(_scriptman.RunPredicates_LUA( NULL, &hPlayerOnKill, "player_onkill" ))
{
if(hPlayerOnKill.GetBool() == false)
return;
}
pPlayer->SetRespawnDelay( 5.0f );
// Bug #0000700: people with infection should give medic kill if they suicide
if( pPlayer->IsInfected() && pPlayer->GetInfector() )
pPlayer->SetSpecialInfectedDeath();
ClientKill( pPlayer->edict() );
// Call lua player_killed on suicides
CFFLuaSC hPlayerKilled;
hPlayerKilled.Push(pPlayer);
_scriptman.RunPredicates_LUA( NULL, &hPlayerKilled, "player_killed" );
}
}
}
static ConCommand kill("kill", CC_Player_Kill, "kills the player");
// -------------------------------------------------------------------------------- //
// Player animation event. Sent to the client when a player fires, jumps, reloads, etc..
// -------------------------------------------------------------------------------- //
class CTEPlayerAnimEvent : public CBaseTempEntity
{
public:
DECLARE_CLASS( CTEPlayerAnimEvent, CBaseTempEntity );
DECLARE_SERVERCLASS();
CTEPlayerAnimEvent( const char *name ) : CBaseTempEntity( name )
{
}
CNetworkHandle( CBasePlayer, m_hPlayer );
CNetworkVar( int, m_iEvent );
};
IMPLEMENT_SERVERCLASS_ST_NOBASE( CTEPlayerAnimEvent, DT_TEPlayerAnimEvent )
SendPropEHandle( SENDINFO( m_hPlayer ) ),
SendPropInt( SENDINFO( m_iEvent ), Q_log2( PLAYERANIMEVENT_COUNT ) + 1, SPROP_UNSIGNED ),
END_SEND_TABLE()
static CTEPlayerAnimEvent g_TEPlayerAnimEvent( "PlayerAnimEvent" );
void TE_PlayerAnimEvent( CBasePlayer *pPlayer, PlayerAnimEvent_t event )
{
CPVSFilter filter( (const Vector&)pPlayer->EyePosition() );
// Mirv: Don't send animation event to self
filter.RemoveRecipient(pPlayer);
g_TEPlayerAnimEvent.m_hPlayer = pPlayer;
g_TEPlayerAnimEvent.m_iEvent = event;
g_TEPlayerAnimEvent.Create( filter, 0 );
}
// --------------------------------------------------------------------------------
// Purpose: Team spawn class
// --------------------------------------------------------------------------------
class CFFTeamSpawn : public CPointEntity
{
public:
DECLARE_CLASS( CFFTeamSpawn, CPointEntity );
virtual Class_T Classify( void ) { return CLASS_TEAMSPAWN; }
};
LINK_ENTITY_TO_CLASS( info_ff_teamspawn , CFFTeamSpawn );
#ifdef EXTRA_LOCAL_ORIGIN_ACCURACY
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
static void *SendProxy_NonLocalOrigin(const SendProp *pProp, const void *pStruct, const void *pVarData, CSendProxyRecipients *pRecipients, int objectID)
{
pRecipients->ClearRecipient(objectID - 1);
return (void *) pVarData;
}
REGISTER_SEND_PROXY_NON_MODIFIED_POINTER(SendProxy_NonLocalOrigin);
BEGIN_SEND_TABLE_NOBASE(CBaseEntity, DT_NonLocalOrigin)
SendPropVector(SENDINFO(m_vecOrigin), -1, SPROP_COORD|SPROP_CHANGES_OFTEN, 0.0f, HIGH_DEFAULT, SendProxy_Origin),
END_SEND_TABLE()
#endif
// -------------------------------------------------------------------------------- //
// Tables.
// -------------------------------------------------------------------------------- //
LINK_ENTITY_TO_CLASS( player, CFFPlayer );
PRECACHE_REGISTER(player);
BEGIN_SEND_TABLE_NOBASE( CFFPlayer, DT_FFPlayerObserver )
SendPropFloat(SENDINFO(m_flNextClassSpecificSkill)),
SendPropFloat(SENDINFO(m_flTrueAimTime)),
SendPropFloat(SENDINFO(m_flHitTime)),
SendPropInt(SENDINFO(m_nButtons)),
END_SEND_TABLE()
BEGIN_SEND_TABLE_NOBASE( CFFPlayer, DT_FFLocalPlayerExclusive )
#ifdef EXTRA_LOCAL_ORIGIN_ACCURACY
SendPropVector(SENDINFO(m_vecOrigin), 32, SPROP_CHANGES_OFTEN, 0.0f, HIGH_DEFAULT),
#endif
SendPropInt( SENDINFO( m_iShotsFired ), 8, SPROP_UNSIGNED ),
// Buildables
SendPropEHandle( SENDINFO( m_hDispenser ) ),
SendPropEHandle( SENDINFO( m_hSentryGun ) ),
SendPropEHandle( SENDINFO( m_hDetpack ) ),
SendPropEHandle( SENDINFO( m_hManCannon ) ),
SendPropBool( SENDINFO( m_bStaticBuilding ) ),
SendPropBool( SENDINFO( m_bBuilding ) ),
SendPropInt( SENDINFO( m_iCurBuild ), 3, SPROP_UNSIGNED ),
// health/armor
SendPropInt(SENDINFO( m_iArmorType ), 4, SPROP_UNSIGNED ),
// random player class
SendPropBool( SENDINFO ( m_fRandomPC ) ),
SendPropInt(SENDINFO(m_iSkiState)),
SendPropInt( SENDINFO( m_iLastSpyDisguise ), 8, SPROP_UNSIGNED ), // AfterShock: this only uses the last 2 hex digits, bits 1-4 for team, 5-8 for class
// Grenade Related
SendPropInt( SENDINFO( m_iGrenadeState ), 2, SPROP_UNSIGNED ),
SendPropInt( SENDINFO( m_iPrimary ), 4 ), // Not unsigned because can be -1
SendPropInt( SENDINFO( m_iSecondary ), 4 ),
SendPropFloat( SENDINFO( m_flServerPrimeTime ) ),
// Map guide
SendPropEHandle( SENDINFO( m_hNextMapGuide ) ),
SendPropEHandle( SENDINFO( m_hLastMapGuide ) ),
SendPropFloat( SENDINFO( m_flNextMapGuideTime ) ),
SendPropFloat(SENDINFO(m_flSlidingTime)),
SendPropFloat(SENDINFO(m_flSpeedModifier)),
SendPropInt( SENDINFO( m_iSpyDisguising ), 4 ),
// Radiotag information the local client needs to know
SendPropEHandle( SENDINFO( m_hRadioTagData ) ),
SendPropBool( SENDINFO( m_bCloakable ) ),
SendPropBool( SENDINFO( m_bDisguisable ) ),
SendPropQAngles( SENDINFO( m_vecInfoIntermission ), 13 ),
// Entity at player's current objective (set by Lua)
SendPropEHandle( SENDINFO( m_hObjectiveEntity ) ),
// Location of player's current objective (also set by Lua)
SendPropVector( SENDINFO( m_vecObjectiveOrigin ), SPROP_COORD ),
END_SEND_TABLE( )
IMPLEMENT_SERVERCLASS_ST( CFFPlayer, DT_FFPlayer )
SendPropExclude( "DT_BaseAnimating", "m_flPoseParameter" ),
SendPropExclude( "DT_BaseAnimating", "m_flPlaybackRate" ),
SendPropExclude( "DT_BaseAnimating", "m_nSequence" ),
SendPropExclude( "DT_BaseEntity", "m_angRotation" ),
SendPropExclude( "DT_BaseAnimatingOverlay", "overlay_vars" ),
// playeranimstate and clientside animation takes care of these on the client
SendPropExclude( "DT_ServerAnimationData" , "m_flCycle" ),
SendPropExclude( "DT_AnimTimeMustBeFirst" , "m_flAnimTime" ),
#ifdef EXTRA_LOCAL_ORIGIN_ACCURACY
SendPropExclude( "DT_BaseEntity" , "m_vecOrigin" ),
#endif
// Data that only gets sent to the local player.
SendPropDataTable( "fflocaldata", 0, &REFERENCE_SEND_TABLE(DT_FFLocalPlayerExclusive), SendProxy_SendLocalDataTable ),
#ifdef EXTRA_LOCAL_ORIGIN_ACCURACY
SendPropDataTable("fforigin", 0, &REFERENCE_SEND_TABLE(DT_NonLocalOrigin), SendProxy_NonLocalOrigin),
#endif
// Data that only gets sent to the player as well as observers of the player
SendPropDataTable( "ffplayerobserverdata", 0, &REFERENCE_SEND_TABLE(DT_FFPlayerObserver), SendProxy_OnlyToObservers ),
SendPropAngle( SENDINFO_VECTORELEM(m_angEyeAngles, 0), 11 ),
SendPropAngle( SENDINFO_VECTORELEM(m_angEyeAngles, 1), 11 ),
SendPropEHandle( SENDINFO( m_hRagdoll ) ),
SendPropInt( SENDINFO( m_iClassStatus ), 4, SPROP_UNSIGNED ), // AfterShock: this only uses the last hex digit i.e. 0x0000000F
SendPropInt( SENDINFO( m_iSpyDisguise ), 8, SPROP_UNSIGNED ), // AfterShock: this only uses the last 2 hex digits, bits 1-4 for team, 5-8 for class
SendPropInt(SENDINFO(m_iSpawnInterpCounter), 4),
SendPropFloat(SENDINFO(m_flConcTime)),
SendPropBool( SENDINFO( m_bSaveMe ) ),
SendPropBool( SENDINFO( m_bEngyMe ) ),
SendPropBool( SENDINFO( m_bAmmoMe ) ),
SendPropBool( SENDINFO( m_bConcussed ) ),
SendPropBool( SENDINFO( m_bTranqed ) ),
SendPropBool( SENDINFO( m_bSliding ) ),
SendPropBool( SENDINFO( m_bIsRampsliding ) ),
SendPropEHandle( SENDINFO( m_hActiveSlowfield ) ),
SendPropBool( SENDINFO( m_bInfected ) ),
SendPropBool( SENDINFO( m_bImmune ) ),
SendPropInt( SENDINFO( m_iInfectTick ) ),
SendPropInt( SENDINFO( m_iCloaked ), 1, SPROP_UNSIGNED ),
SendPropInt( SENDINFO( m_iActiveSabotages ), 2, SPROP_UNSIGNED ),
END_SEND_TABLE( )
LINK_ENTITY_TO_CLASS( ff_ragdoll, CFFRagdoll );
IMPLEMENT_SERVERCLASS_ST_NOBASE( CFFRagdoll, DT_FFRagdoll )
SendPropVector( SENDINFO(m_vecRagdollOrigin), -1, SPROP_COORD ),
SendPropEHandle( SENDINFO( m_hPlayer ) ),
SendPropModelIndex( SENDINFO( m_nModelIndex ) ),
SendPropInt ( SENDINFO(m_nForceBone), 8, 0 ),
SendPropVector ( SENDINFO(m_vecForce), -1, SPROP_NOSCALE ),
SendPropVector( SENDINFO( m_vecRagdollVelocity ) ),
// State of player's limbs
SendPropInt(SENDINFO(m_fBodygroupState), 5, SPROP_UNSIGNED), //AfterShock: this uses 5 flags for limbs decapped, up to DECAP_RIGHT_LEG which is 1 << 4
SendPropInt(SENDINFO(m_nSkinIndex), 3, SPROP_UNSIGNED),
END_SEND_TABLE()
// -------------------------------------------------------------------------------- //
void cc_CreatePredictionError_f()
{
CBaseEntity *pEnt = CBaseEntity::Instance( 1 );
pEnt->SetAbsOrigin( pEnt->GetAbsOrigin() + Vector( 63, 0, 0 ) );
}
ConCommand cc_CreatePredictionError( "CreatePredictionError", cc_CreatePredictionError_f, "Create a prediction error", FCVAR_CHEAT );
// --------------------------------------------------------------------------------
// Purpose: Constructor!
// --------------------------------------------------------------------------------
CFFPlayer::CFFPlayer()
{
#ifdef FF_BETA_TEST_COMPILE
CBaseEntity *p = NULL;
p->Activate();
#else
m_PlayerAnimState = CreatePlayerAnimState( this, this, LEGANIM_9WAY, true );
UseClientSideAnimation();
m_angEyeAngles.Init();
SetViewOffset( FF_PLAYER_VIEW_OFFSET );
m_iLocalSkiState = 0;
// Assume true
m_bRespawnable = true;
m_bStaticBuilding = false;
m_bBuilding = false;
//m_bCancelledBuild = false;
m_iWantBuild = FF_BUILD_NONE;
m_iCurBuild = FF_BUILD_NONE;
m_hDispenser = NULL;
m_hSentryGun = NULL;
m_hDetpack = NULL;
m_hManCannon = NULL;
m_flBuildTime = 0.0f;
m_bRadioTagged = false;
m_flRadioTaggedStartTime = 0.0f;
m_flRadioTaggedDuration = RADIOTAG_DRAW_DURATION;
// Grenade Related
m_iGrenadeState = FF_GREN_NONE;
m_flServerPrimeTime = 0;
m_bEngyGrenWarned = false;
m_iPrimary = 0;
m_iSecondary = 0;
m_bWantToThrowGrenade = false;
// Status Effects
m_flNextBurnTick = 0.0;
m_iBurnTicks = 0;
m_flBurningDamage = 0.0;
m_bBurnFlagNG = false; // AfterShock - burning flags for multiplying flames and damage for combos!
m_bBurnFlagFT = false;
m_bBurnFlagIC = false;
m_bACDamageHint = true; // For triggering the "Pyro takes damage from HWGuy" hint only once
m_bSGDamageHint = true; // For triggering the "Spy takes damage from SG while cloaked" hint only once
m_bDisguisable = true;
m_flNextJumpTimeForDouble = 0;
m_flSpeedModifier = 1.0f;
m_flSpeedModifierOld = 1.0f;
m_flSpeedModifierChangeTime = 0;
for (int i=0; i<NUM_SPEED_EFFECTS; i++)
{
RemoveSpeedEffectByIndex( i );
}
m_fLastHealTick = 0.0f;
m_fLastInfectedTick = 0.0f;
m_bInfected = false;
m_hInfector = NULL;
m_bImmune = false;
m_iInfectedTeam = TEAM_UNASSIGNED;
m_flImmuneTime = 0.0f;
m_iInfectTick = 0; //Green Mushy
m_nNumInfectDamage = 0;
m_flLastOverHealthTick = 0.0f;
m_iActiveSabotages = 0;
m_iSabotagedSentries = 0;
m_iSabotagedDispensers = 0;
m_iLastSpyDisguise = 0;
// Map guide stuff
m_hNextMapGuide = NULL;
m_flNextMapGuideTime = 0;
// Class stuff
m_fRandomPC = false;
m_iNextClass = 0;
m_flConcTime = 0; // Not concussed on creation
m_bConcussed = false;
m_flTrueAimTime = 0.0f;
m_flHitTime = 0.0f;
m_bTranqed = false;
m_iClassStatus = 0; // No class sorted yet
m_flSlidingTime = 0; // Not sliding on creation
m_bSliding = false;
m_bIsRampsliding = false;
m_bGassed = false;
m_hGasser = NULL;
m_flNextGas = 0;
m_flGasTime = 0;
m_hActiveSlowfield = NULL;
m_Locations.Purge();
m_iClientLocation = 0;
SetObjectiveEntity(NULL);
m_pLastWeapon = NULL;
m_flJumpTime = m_flFallTime = 0;
m_iSpawnInterpCounter = 0;
m_fl_LuaSet_PlayerRespawnDelay = 0.0f;
m_flLastClassSwitch = 0.0f;
m_SpawnPointOverride = 0;
//m_iStatsID = -1;
#endif // FF_BETA_TEST_COMPILE
}
CFFPlayer::~CFFPlayer()
{
m_PlayerAnimState->Release();
}
// --------------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------------
void CFFPlayer::UpdateOnRemove( void )
{
// Kill off flame & burning sound
Extinguish();
BaseClass::UpdateOnRemove();
}
// --------------------------------------------------------------------------------
// Purpose: Set the spawn delay for a player. If the current delay
// is longer than flDelay then flDelay is ignored and
// the longer delay is used. It also checks the entity
// system/mp_respawndelay for any global delay.
// --------------------------------------------------------------------------------
void CFFPlayer::SetRespawnDelay( float flDelay )
{
// The largest delay is what the player will be told
float flTmpDelay = max( flDelay, mp_respawndelay.GetFloat() );
m_flNextSpawnDelay = max( flTmpDelay, m_fl_LuaSet_PlayerRespawnDelay );
}
CFFPlayer *CFFPlayer::CreatePlayer( const char *className, edict_t *ed )
{
CFFPlayer::s_PlayerEdict = ed;
return (CFFPlayer*)CreateEntityByName( className );
}
void CFFPlayer::LeaveVehicle( const Vector &vecExitPoint, const QAngle &vecExitAngles )
{
BaseClass::LeaveVehicle( vecExitPoint, vecExitAngles );
//teleport physics shadow too
// Vector newPos = GetAbsOrigin();
// QAngle newAng = GetAbsAngles();
// Teleport( &newPos, &newAng, &vec3_origin );
}
void CFFPlayer::PreThink(void)
{
#ifdef FF_BETA_TEST_COMPILE
// Crash
CFFPlayer *p = NULL;
p->PreThink();
#endif
#ifndef FF_BETA_TEST_COMPILE
// reset these every frame
m_fBodygroupState = 0;
// Update networked current-speed-var for spy cloak mat proxy (sent to all players! :X)
//Vector vecCloakVelocity = GetLocalVelocity();
//m_flCloakSpeed = FastSqrt( ( vecCloakVelocity.x * vecCloakVelocity.x ) +
// ( vecCloakVelocity.y * vecCloakVelocity.y ) +
// ( ( vecCloakVelocity.z * ffdev_spy_cloakzvel.GetFloat() ) * ( vecCloakVelocity.z * ffdev_spy_cloakzvel.GetFloat() ) ) );
// Has our radio tag expired?
if( m_bRadioTagged && ( ( m_flRadioTaggedStartTime + m_flRadioTaggedDuration ) < gpGlobals->curtime ) )
{
m_bRadioTagged = false;
m_pWhoTaggedMe = NULL;
}
// See if it's time to reset our saveme status
if( ( m_flSaveMeTime < gpGlobals->curtime ) && ( m_bSaveMe ) )
m_bSaveMe = false;
// See if it's time to reset our engyme status
if( ( m_flSaveMeTime < gpGlobals->curtime ) && ( m_bEngyMe ) )
m_bEngyMe = false;
// See if it's time to reset our engyme status
if( ( m_flSaveMeTime < gpGlobals->curtime ) && ( m_bAmmoMe ) )
m_bAmmoMe = false;
// See if it's time to reset our concussion status
if( ( m_flConcTime < gpGlobals->curtime ) && ( m_bConcussed ) )
m_bConcussed = false;
// Update our list of tagged players that the client
FindRadioTaggedPlayers();
// Riding a vehicle?
if( IsInAVehicle() )
{
// make sure we update the client, check for timed damage and update suit even if we are in a vehicle
UpdateClientData();
CheckTimeBasedDamage();
// Allow the suit to recharge when in the vehicle.
CheckSuitUpdate();
WaterMove();
return;
}
// update the grenade status if needed
if( IsGrenadePrimed() )
GrenadeThink();
// Bug #0000459: building on ledge locks you into place.
if( m_bBuilding )
{
// Our origin has changed while building! no!!!!!!!!!!!!!!!!!!!!!!
if( m_bStaticBuilding && ( m_vecBuildOrigin.DistTo( GetAbsOrigin() ) > 128.0f ) )
{
Warning( "[Buildable] Player origin has changed!\n" );
m_iWantBuild = m_iCurBuild;
PreBuildGenericThink();
}
// Keeping the m_bBuilding line in there in case we cancel the build cause
// we left the ground in which case m_bBuilding will be false and we'll
// just skip this.
// If we're building and we've waited the two seconds or whatever...
if( m_bBuilding && ( m_flBuildTime < gpGlobals->curtime ) )
PostBuildGenericThink();
}
StatusEffectsThink();
// Do some spy stuff
if (GetClassSlot() == CLASS_SPY)
{
// Get horizontal + forward velocity (no vertical velocity)
//Vector vecVelocity = GetLocalVelocity();
//float flSpeed = FastSqrt( vecVelocity[ 0 ] * vecVelocity[ 0 ] + vecVelocity[ 1 ] * vecVelocity[ 1 ] );
//float flSpeed = m_flCloakSpeed;
// Jiggles: Nope, let's try it this way instead
Vector vecCloakVelocity = GetLocalVelocity();
float flSpeed = FastSqrt( ( vecCloakVelocity.x * vecCloakVelocity.x ) +
( vecCloakVelocity.y * vecCloakVelocity.y ) +
( ( vecCloakVelocity.z * FFDEV_SPY_CLOAKZVEL ) * ( vecCloakVelocity.z * FFDEV_SPY_CLOAKZVEL ) ) );
// If going faster than spies walk speed, reset
if( IsCloaked() && ( flSpeed > 220 /* ffdev_spy_maxcloakspeed */ ) )
{
// If it was a regular cloak, verify we haven't JUST cloaked
// and are still within the ffdev_spy_speedenforcewait period
bool bUncloak = false;
// When this is false it's a regular cloak that got us cloaked
if( !m_bCloakFadeType )
{
if( gpGlobals->curtime > ( m_flCloakTime + FFDEV_SPY_SPEEDENFORCEWAIT ) )
bUncloak = true;
}
else
{
// We silently cloaked and we're above the speed, uncloak!
bUncloak = true;
}
// Uncloak NOW
if( bUncloak )
Uncloak( true );
}
// Disguising
if (m_iNewSpyDisguise && gpGlobals->curtime > m_flFinishDisguise)
FinishDisguise();
// Sabotage!!
SpySabotageThink();
// Cloak fade thinking
SpyCloakFadeThink();
}
// Do we need to do a class specific skill?
if( m_afButtonPressed & IN_ATTACK2 )
ClassSpecificSkill();
else if (m_afButtonReleased & IN_ATTACK2)
ClassSpecificSkill_Post();
if (m_iSabotagedSentries == 0)
m_iActiveSabotages &= ~2;
if (m_iSabotagedDispensers == 0)
m_iActiveSabotages &= ~1;
BaseClass::PreThink();
#endif // FF_BETA_TEST_COMPILE
}
void CFFPlayer::PostThink()
{
#ifdef FF_BETA_TEST_COMPILE
// Crash
CFFPlayer *p = NULL;
p->PostThink();
#endif
#ifndef FF_BETA_TEST_COMPILE
BaseClass::PostThink();
if( GetTeamNumber() < TEAM_BLUE )
{
MoveTowardsMapGuide();
}
else
{
QAngle angles = GetLocalAngles();
angles[PITCH] = 0;
SetLocalAngles( angles );
// Store the eye angles pitch so the client can compute its animation state correctly.
m_angEyeAngles = EyeAngles();
m_PlayerAnimState->Update( m_angEyeAngles[YAW], m_angEyeAngles[PITCH] );
}
#endif // FF_BETA_TEST_COMPILE
}
void CFFPlayer::Precache()
{
#ifndef FF_BETA_TEST_COMPILE
PrecacheModel(FF_PLAYER_MODEL);
// #0000331: impulse 81 not working (weapon_cubemap)
PrecacheModel("models/shadertest/envballs.mdl");
// Quick addition to precache all the player models
PrecacheModel("models/player/scout/scout.mdl");
PrecacheModel("models/player/sniper/sniper.mdl");
PrecacheModel("models/player/soldier/soldier.mdl");
PrecacheModel("models/player/demoman/demoman.mdl");
PrecacheModel("models/player/medic/medic.mdl");
PrecacheModel("models/player/hwguy/hwguy.mdl");
PrecacheModel("models/player/pyro/pyro.mdl");
PrecacheModel("models/player/spy/spy.mdl");
PrecacheModel("models/player/engineer/engineer.mdl");
PrecacheModel("models/player/civilian/civilian.mdl");
// Sounds
//PrecacheScriptSound("Grenade.Timer");
PrecacheScriptSound("Grenade.Prime");
PrecacheScriptSound("Player.Jump");
PrecacheScriptSound("Player.SpyFall");
PrecacheScriptSound("Player.Deathbeep");
PrecacheScriptSound("Player.Ammotoss");
PrecacheScriptSound("speech.saveme");
PrecacheScriptSound("Player.bodysplat");
PrecacheScriptSound("Item.Toss");
PrecacheScriptSound("Player.Pain");
PrecacheScriptSound("Player.Scream");
PrecacheScriptSound("Player.Flameout");
PrecacheScriptSound("medical.saveme");
PrecacheScriptSound("maintenance.saveme");
PrecacheScriptSound("infected.saveme");
PrecacheScriptSound("ammo.saveme");
PrecacheScriptSound("overpressure.explode");
// Precache gib sound -> Defrag
PrecacheScriptSound("Player.Gib");
// Special case
PrecacheScriptSound( EMP_SOUND );
// Precache sabotage sounds
PrecacheScriptSound( "Player.Sabotage" );
PrecacheScriptSound( "Player.SabotageTimedOut" );
// Flashlight - Bug #0000679: flashlight sound isn't precached
PrecacheScriptSound( "HL2Player.FlashLightOn" );
PrecacheScriptSound( "HL2Player.FlashLightOff" );
PrecacheModel( "sprites/glow01.vmt" );
// Class specific things!
for (int i = CLASS_SCOUT; i <= CLASS_CIVILIAN; i++)
{
char buf[256];
const char *class_string = Class_IntToString(i);
// Model gibs
Q_snprintf(buf, 255, "models/player/%s/%s_head.mdl", class_string, class_string);
g_iLimbs[i][0] = PrecacheModel(buf);
Q_snprintf(buf, 255, "models/player/%s/%s_leftarm.mdl", class_string, class_string);
g_iLimbs[i][1] = PrecacheModel(buf);
Q_snprintf(buf, 255, "models/player/%s/%s_rightarm.mdl", class_string, class_string);
g_iLimbs[i][2] = PrecacheModel(buf);
Q_snprintf(buf, 255, "models/player/%s/%s_leftleg.mdl", class_string, class_string);
g_iLimbs[i][3] = PrecacheModel(buf);
Q_snprintf(buf, 255, "models/player/%s/%s_rightleg.mdl", class_string, class_string);
g_iLimbs[i][4] = PrecacheModel(buf);
// Saveme shouts
// 0001318: Get rid of class specific save me sounds
// Q_snprintf(buf, 255, "%s.saveme", class_string);
// PrecacheScriptSound(buf);
}
for (int i = 0; i < 8; i++)
{
PrecacheModel(UTIL_VarArgs("models/gibs/gib%d.mdl", (i + 1)));
}
BaseClass::Precache();
#endif // FF_BETA_TEST_COMPILE
}
extern CBaseEntity *g_pLastSpawn; // this is defined somewhere.. i'm using it :)
// this is going to strictly be for the randomizing at the beginning of EntSelectSpawnPoint
// by starting from the last entity when going into the for loop
CBaseEntity *g_pLastSpawnRandomizer = NULL;
void CFFPlayer::SetLastSpawn( CBaseEntity *pEntity )
{
g_pLastSpawn = pEntity;
if( !pEntity )
g_pLastSpawnRandomizer = NULL;
}
CBaseEntity *CFFPlayer::EntSelectSpawnPoint()
{
#ifdef FF_BETA_TEST_COMPILE
// Return bogus crap
return NULL;
#endif
#ifndef FF_BETA_TEST_COMPILE
/*
CBaseEntity *pSpot, *pGibSpot;
edict_t *player;
player = edict();
pSpot = g_pLastSpawn;
// Randomize the start spot
// NOTE: given a larger range from the default SDK function so that players won't always
// spawn at the "first" spawn point for their team if the spawns are put in a "bad" order
for ( int i = random->RandomInt(15,25); i > 0; i-- )
{
pSpot = gEntList.FindEntityByClassT( pSpot, CLASS_TEAMSPAWN );
if ( !pSpot ) // skip over the null point
pSpot = gEntList.FindEntityByClassT( pSpot, CLASS_TEAMSPAWN );
}
CBaseEntity *pFirstSpot = pSpot;
pGibSpot = pFirstSpot;
do
{
if ( pSpot )
{
// check the scripting system to check if the player is allowed to spawn here
// but let them spawn here if the name doesn't exist
if ( !FStrEq(STRING(pSpot->GetEntityName()), "") )
{
//CFFLuaObjectWrapper hSpawnSpot;
CFFLuaSC hAllowed( 1, this );
if( entsys.RunPredicates_LUA( pSpot, &hAllowed, "validspawn" ) )
{
// pSpot:validspawn() exists, check the value returned from it
if( !hAllowed.GetBool() )
{
//DevMsg("[entsys] Skipping spawn for player %s at %s because it fails the check\n", GetPlayerName(), STRING( pSpot->GetEntityName() ) );
pSpot = gEntList.FindEntityByClassname( pSpot, "info_ff_teamspawn" );
continue;
}
}
}
pGibSpot = pSpot;
// check if pSpot is valid
if ( g_pGameRules->IsSpawnPointValid( pSpot, this ) )
{
if ( pSpot->GetLocalOrigin() == vec3_origin )
{
pSpot = gEntList.FindEntityByClassT( pSpot, CLASS_TEAMSPAWN );
continue;
}