-
Notifications
You must be signed in to change notification settings - Fork 67
/
tf_player.cpp
6170 lines (5250 loc) · 175 KB
/
tf_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-2001, Valve LLC, All rights reserved. ============
//
// Purpose: Player for HL1.
//
// $NoKeywords: $
//=============================================================================
#include "cbase.h"
#include "tf_player.h"
#include "tf_gamerules.h"
#include "tf_gamestats.h"
#include "KeyValues.h"
#include "viewport_panel_names.h"
#include "client.h"
#include "team.h"
#include "tf_weaponbase.h"
#include "tf_client.h"
#include "tf_team.h"
#include "tf_viewmodel.h"
#include "tf_item.h"
#include "in_buttons.h"
#include "entity_capture_flag.h"
#include "effect_dispatch_data.h"
#include "te_effect_dispatch.h"
#include "game.h"
#include "tf_weapon_builder.h"
#include "tf_obj.h"
#include "tf_ammo_pack.h"
#include "datacache/imdlcache.h"
#include "particle_parse.h"
#include "props_shared.h"
#include "filesystem.h"
#include "toolframework_server.h"
#include "IEffects.h"
#include "func_respawnroom.h"
#include "networkstringtable_gamedll.h"
#include "team_control_point_master.h"
#include "tf_weapon_pda.h"
#include "sceneentity.h"
#include "fmtstr.h"
#include "tf_weapon_sniperrifle.h"
#include "tf_weapon_minigun.h"
#include "trigger_area_capture.h"
#include "triggers.h"
#include "tf_weapon_medigun.h"
#include "hl2orange.spa.h"
#include "te_tfblood.h"
#include "activitylist.h"
#include "steam/steam_api.h"
#include "cdll_int.h"
#include "tf_weaponbase.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
#define DAMAGE_FORCE_SCALE_SELF 9
extern bool IsInCommentaryMode( void );
extern ConVar sk_player_head;
extern ConVar sk_player_chest;
extern ConVar sk_player_stomach;
extern ConVar sk_player_arm;
extern ConVar sk_player_leg;
extern ConVar tf_spy_invis_time;
extern ConVar tf_spy_invis_unstealth_time;
extern ConVar tf_stalematechangeclasstime;
EHANDLE g_pLastSpawnPoints[TF_TEAM_COUNT];
ConVar tf_playerstatetransitions( "tf_playerstatetransitions", "-2", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY, "tf_playerstatetransitions <ent index or -1 for all>. Show player state transitions." );
ConVar tf_playergib( "tf_playergib", "1", FCVAR_PROTECTED, "Allow player gibbing." );
ConVar tf_weapon_ragdoll_velocity_min( "tf_weapon_ragdoll_velocity_min", "100", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY );
ConVar tf_weapon_ragdoll_velocity_max( "tf_weapon_ragdoll_velocity_max", "150", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY );
ConVar tf_weapon_ragdoll_maxspeed( "tf_weapon_ragdoll_maxspeed", "300", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY );
ConVar tf_damageforcescale_other( "tf_damageforcescale_other", "6.0", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY );
ConVar tf_damageforcescale_self_soldier( "tf_damageforcescale_self_soldier", "10.0", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY );
ConVar tf_damagescale_self_soldier( "tf_damagescale_self_soldier", "0.60", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY );
ConVar tf_damage_lineardist( "tf_damage_lineardist", "0", FCVAR_DEVELOPMENTONLY );
ConVar tf_damage_range( "tf_damage_range", "0.5", FCVAR_DEVELOPMENTONLY );
ConVar tf_max_voice_speak_delay( "tf_max_voice_speak_delay", "1.5", FCVAR_DEVELOPMENTONLY, "Max time after a voice command until player can do another one" );
extern ConVar spec_freeze_time;
extern ConVar spec_freeze_traveltime;
extern ConVar sv_maxunlag;
extern ConVar tf_damage_disablespread;
extern ConVar tf_gravetalk;
extern ConVar tf_spectalk;
// -------------------------------------------------------------------------------- //
// 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 )
{
m_iPlayerIndex = TF_PLAYER_INDEX_NONE;
}
CNetworkVar( int, m_iPlayerIndex );
CNetworkVar( int, m_iEvent );
CNetworkVar( int, m_nData );
};
IMPLEMENT_SERVERCLASS_ST_NOBASE( CTEPlayerAnimEvent, DT_TEPlayerAnimEvent )
SendPropInt( SENDINFO( m_iPlayerIndex ), 7, SPROP_UNSIGNED ),
SendPropInt( SENDINFO( m_iEvent ), Q_log2( PLAYERANIMEVENT_COUNT ) + 1, SPROP_UNSIGNED ),
// BUGBUG: ywb we assume this is either 0 or an animation sequence #, but it could also be an activity, which should fit within this limit, but we're not guaranteed.
SendPropInt( SENDINFO( m_nData ), ANIMATION_SEQUENCE_BITS ),
END_SEND_TABLE()
static CTEPlayerAnimEvent g_TEPlayerAnimEvent( "PlayerAnimEvent" );
void TE_PlayerAnimEvent( CBasePlayer *pPlayer, PlayerAnimEvent_t event, int nData )
{
Vector vecEyePos = pPlayer->EyePosition();
CPVSFilter filter( vecEyePos );
if ( !IsCustomPlayerAnimEvent( event ) && ( event != PLAYERANIMEVENT_SNAP_YAW ) && ( event != PLAYERANIMEVENT_VOICE_COMMAND_GESTURE ) )
{
filter.RemoveRecipient( pPlayer );
}
Assert( pPlayer->entindex() >= 1 && pPlayer->entindex() <= MAX_PLAYERS );
g_TEPlayerAnimEvent.m_iPlayerIndex = pPlayer->entindex();
g_TEPlayerAnimEvent.m_iEvent = event;
Assert( nData < (1<<ANIMATION_SEQUENCE_BITS) );
Assert( (1<<ANIMATION_SEQUENCE_BITS) >= ActivityList_HighestIndex() );
g_TEPlayerAnimEvent.m_nData = nData;
g_TEPlayerAnimEvent.Create( filter, 0 );
}
//=================================================================================
//
// Ragdoll Entity
//
class CTFRagdoll : public CBaseAnimatingOverlay
{
public:
DECLARE_CLASS( CTFRagdoll, CBaseAnimatingOverlay );
DECLARE_SERVERCLASS();
CTFRagdoll()
{
m_iPlayerIndex.Set( TF_PLAYER_INDEX_NONE );
m_bGib = false;
m_bBurning = false;
m_vecRagdollOrigin.Init();
m_vecRagdollVelocity.Init();
}
// Transmit ragdolls to everyone.
virtual int UpdateTransmitState()
{
return SetTransmitState( FL_EDICT_ALWAYS );
}
CNetworkVar( int, m_iPlayerIndex );
CNetworkVector( m_vecRagdollVelocity );
CNetworkVector( m_vecRagdollOrigin );
CNetworkVar( bool, m_bGib );
CNetworkVar( bool, m_bBurning );
CNetworkVar( int, m_iTeam );
CNetworkVar( int, m_iClass );
};
LINK_ENTITY_TO_CLASS( tf_ragdoll, CTFRagdoll );
IMPLEMENT_SERVERCLASS_ST_NOBASE( CTFRagdoll, DT_TFRagdoll )
SendPropVector( SENDINFO( m_vecRagdollOrigin ), -1, SPROP_COORD ),
SendPropInt( SENDINFO( m_iPlayerIndex ), 7, SPROP_UNSIGNED ),
SendPropVector ( SENDINFO(m_vecForce), -1, SPROP_NOSCALE ),
SendPropVector( SENDINFO( m_vecRagdollVelocity ), 13, SPROP_ROUNDDOWN, -2048.0f, 2048.0f ),
SendPropInt( SENDINFO( m_nForceBone ) ),
SendPropBool( SENDINFO( m_bGib ) ),
SendPropBool( SENDINFO( m_bBurning ) ),
SendPropInt( SENDINFO( m_iTeam ), 3, SPROP_UNSIGNED ),
SendPropInt( SENDINFO( m_iClass ), 4, SPROP_UNSIGNED ),
END_SEND_TABLE()
// -------------------------------------------------------------------------------- //
// Tables.
// -------------------------------------------------------------------------------- //
//-----------------------------------------------------------------------------
// Purpose: Filters updates to a variable so that only non-local players see
// the changes. This is so we can send a low-res origin to non-local players
// while sending a hi-res one to the local player.
// Input : *pVarData -
// *pOut -
// objectID -
//-----------------------------------------------------------------------------
void* SendProxy_SendNonLocalDataTable( const SendProp *pProp, const void *pStruct, const void *pVarData, CSendProxyRecipients *pRecipients, int objectID )
{
pRecipients->SetAllRecipients();
pRecipients->ClearRecipient( objectID - 1 );
return ( void * )pVarData;
}
REGISTER_SEND_PROXY_NON_MODIFIED_POINTER( SendProxy_SendNonLocalDataTable );
//-----------------------------------------------------------------------------
// Purpose: SendProxy that converts the UtlVector list of objects to entindexes, where it's reassembled on the client
//-----------------------------------------------------------------------------
void SendProxy_PlayerObjectList( const SendProp *pProp, const void *pStruct, const void *pData, DVariant *pOut, int iElement, int objectID )
{
CTFPlayer *pPlayer = (CTFPlayer*)pStruct;
// If this fails, then SendProxyArrayLength_PlayerObjects didn't work.
Assert( iElement < pPlayer->GetObjectCount() );
CBaseObject *pObject = pPlayer->GetObject(iElement);
EHANDLE hObject;
hObject = pObject;
SendProxy_EHandleToInt( pProp, pStruct, &hObject, pOut, iElement, objectID );
}
int SendProxyArrayLength_PlayerObjects( const void *pStruct, int objectID )
{
CTFPlayer *pPlayer = (CTFPlayer*)pStruct;
int iObjects = pPlayer->GetObjectCount();
Assert( iObjects <= MAX_OBJECTS_PER_PLAYER );
return iObjects;
}
BEGIN_DATADESC( CTFPlayer )
END_DATADESC()
extern void SendProxy_Origin( const SendProp *pProp, const void *pStruct, const void *pData, DVariant *pOut, int iElement, int objectID );
// specific to the local player
BEGIN_SEND_TABLE_NOBASE( CTFPlayer, DT_TFLocalPlayerExclusive )
// send a hi-res origin to the local player for use in prediction
SendPropVector (SENDINFO(m_vecOrigin), -1, SPROP_NOSCALE|SPROP_CHANGES_OFTEN, 0.0f, HIGH_DEFAULT, SendProxy_Origin ),
SendPropArray2(
SendProxyArrayLength_PlayerObjects,
SendPropInt("player_object_array_element", 0, SIZEOF_IGNORE, NUM_NETWORKED_EHANDLE_BITS, SPROP_UNSIGNED, SendProxy_PlayerObjectList),
MAX_OBJECTS_PER_PLAYER,
0,
"player_object_array"
),
SendPropFloat( SENDINFO_VECTORELEM(m_angEyeAngles, 0), 8, SPROP_CHANGES_OFTEN, -90.0f, 90.0f ),
// SendPropAngle( SENDINFO_VECTORELEM(m_angEyeAngles, 1), 10, SPROP_CHANGES_OFTEN ),
END_SEND_TABLE()
// all players except the local player
BEGIN_SEND_TABLE_NOBASE( CTFPlayer, DT_TFNonLocalPlayerExclusive )
// send a lo-res origin to other players
SendPropVector (SENDINFO(m_vecOrigin), -1, SPROP_COORD_MP_LOWPRECISION|SPROP_CHANGES_OFTEN, 0.0f, HIGH_DEFAULT, SendProxy_Origin ),
SendPropFloat( SENDINFO_VECTORELEM(m_angEyeAngles, 0), 8, SPROP_CHANGES_OFTEN, -90.0f, 90.0f ),
SendPropAngle( SENDINFO_VECTORELEM(m_angEyeAngles, 1), 10, SPROP_CHANGES_OFTEN ),
END_SEND_TABLE()
//============
LINK_ENTITY_TO_CLASS( player, CTFPlayer );
PRECACHE_REGISTER(player);
IMPLEMENT_SERVERCLASS_ST( CTFPlayer, DT_TFPlayer )
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" ),
SendPropExclude( "DT_BaseEntity", "m_nModelIndex" ),
SendPropExclude( "DT_BaseEntity", "m_vecOrigin" ),
// cs_playeranimstate and clientside animation takes care of these on the client
SendPropExclude( "DT_ServerAnimationData" , "m_flCycle" ),
SendPropExclude( "DT_AnimTimeMustBeFirst" , "m_flAnimTime" ),
SendPropExclude( "DT_BaseFlex", "m_flexWeight" ),
SendPropExclude( "DT_BaseFlex", "m_blinktoggle" ),
SendPropExclude( "DT_BaseFlex", "m_viewtarget" ),
SendPropBool(SENDINFO(m_bSaveMeParity)),
// This will create a race condition will the local player, but the data will be the same so.....
SendPropInt( SENDINFO( m_nWaterLevel ), 2, SPROP_UNSIGNED ),
SendPropEHandle(SENDINFO(m_hItem)),
// Ragdoll.
SendPropEHandle( SENDINFO( m_hRagdoll ) ),
SendPropDataTable( SENDINFO_DT( m_PlayerClass ), &REFERENCE_SEND_TABLE( DT_TFPlayerClassShared ) ),
SendPropDataTable( SENDINFO_DT( m_Shared ), &REFERENCE_SEND_TABLE( DT_TFPlayerShared ) ),
// Data that only gets sent to the local player
SendPropDataTable( "tflocaldata", 0, &REFERENCE_SEND_TABLE(DT_TFLocalPlayerExclusive), SendProxy_SendLocalDataTable ),
// Data that gets sent to all other players
SendPropDataTable( "tfnonlocaldata", 0, &REFERENCE_SEND_TABLE(DT_TFNonLocalPlayerExclusive), SendProxy_SendNonLocalDataTable ),
SendPropBool( SENDINFO( m_iSpawnCounter ) ),
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 | FCVAR_DEVELOPMENTONLY );
// Hint callbacks
bool HintCallbackNeedsResources_Sentrygun( CBasePlayer *pPlayer )
{
return ( pPlayer->GetAmmoCount( TF_AMMO_METAL ) > CalculateObjectCost( OBJ_SENTRYGUN ) );
}
bool HintCallbackNeedsResources_Dispenser( CBasePlayer *pPlayer )
{
return ( pPlayer->GetAmmoCount( TF_AMMO_METAL ) > CalculateObjectCost( OBJ_DISPENSER ) );
}
bool HintCallbackNeedsResources_Teleporter( CBasePlayer *pPlayer )
{
return ( pPlayer->GetAmmoCount( TF_AMMO_METAL ) > CalculateObjectCost( OBJ_TELEPORTER_ENTRANCE ) );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CTFPlayer::CTFPlayer()
{
m_PlayerAnimState = CreateTFPlayerAnimState( this );
item_list = 0;
SetArmorValue( 10 );
m_hItem = NULL;
m_hTauntScene = NULL;
UseClientSideAnimation();
m_angEyeAngles.Init();
m_pStateInfo = NULL;
m_lifeState = LIFE_DEAD; // Start "dead".
m_iMaxSentryKills = 0;
m_flNextNameChangeTime = 0;
m_flNextTimeCheck = gpGlobals->curtime;
m_flSpawnTime = 0;
SetViewOffset( TF_PLAYER_VIEW_OFFSET );
m_Shared.Init( this );
m_iLastSkin = -1;
m_bHudClassAutoKill = false;
m_bMedigunAutoHeal = false;
m_vecLastDeathPosition = Vector( FLT_MAX, FLT_MAX, FLT_MAX );
SetDesiredPlayerClassIndex( TF_CLASS_UNDEFINED );
SetContextThink( &CTFPlayer::TFPlayerThink, gpGlobals->curtime, "TFPlayerThink" );
ResetScores();
m_flLastAction = gpGlobals->curtime;
m_bInitTaunt = false;
m_bSpeakingConceptAsDisguisedSpy = false;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFPlayer::TFPlayerThink()
{
if ( m_pStateInfo && m_pStateInfo->pfnThink )
{
(this->*m_pStateInfo->pfnThink)();
}
// Time to finish the current random expression? Or time to pick a new one?
if ( IsAlive() && m_flNextRandomExpressionTime >= 0 && gpGlobals->curtime > m_flNextRandomExpressionTime )
{
// Random expressions need to be cleared, because they don't loop. So if we
// pick the same one again, we want to restart it.
ClearExpression();
m_iszExpressionScene = NULL_STRING;
UpdateExpression();
}
// Check to see if we are in the air and taunting. Stop if so.
if ( GetGroundEntity() == NULL && m_Shared.InCond( TF_COND_TAUNTING ) )
{
if( m_hTauntScene.Get() )
{
StopScriptedScene( this, m_hTauntScene );
m_Shared.m_flTauntRemoveTime = 0.0f;
m_hTauntScene = NULL;
}
}
SetContextThink( &CTFPlayer::TFPlayerThink, gpGlobals->curtime, "TFPlayerThink" );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFPlayer::MedicRegenThink( void )
{
if ( IsPlayerClass( TF_CLASS_MEDIC ) )
{
if ( IsAlive() )
{
// Heal faster if we haven't been in combat for a while
float flTimeSinceDamage = gpGlobals->curtime - GetLastDamageTime();
float flScale = RemapValClamped( flTimeSinceDamage, 5, 10, 1.0, 3.0 );
int iHealAmount = ceil(TF_MEDIC_REGEN_AMOUNT * flScale);
TakeHealth( iHealAmount, DMG_GENERIC );
}
SetContextThink( &CTFPlayer::MedicRegenThink, gpGlobals->curtime + TF_MEDIC_REGEN_TIME, "MedicRegenThink" );
}
}
CTFPlayer::~CTFPlayer()
{
DestroyRagdoll();
m_PlayerAnimState->Release();
}
CTFPlayer *CTFPlayer::CreatePlayer( const char *className, edict_t *ed )
{
CTFPlayer::s_PlayerEdict = ed;
return (CTFPlayer*)CreateEntityByName( className );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFPlayer::UpdateTimers( void )
{
m_Shared.ConditionThink();
m_Shared.InvisibilityThink();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFPlayer::PreThink()
{
// Update timers.
UpdateTimers();
// Pass through to the base class think.
BaseClass::PreThink();
// Reset bullet force accumulator, only lasts one frame, for ragdoll forces from multiple shots.
m_vecTotalBulletForce = vec3_origin;
CheckForIdle();
}
ConVar mp_idledealmethod( "mp_idledealmethod", "1", FCVAR_GAMEDLL, "Deals with Idle Players. 1 = Sends them into Spectator mode then kicks them if they're still idle, 2 = Kicks them out of the game;" );
ConVar mp_idlemaxtime( "mp_idlemaxtime", "3", FCVAR_GAMEDLL, "Maximum time a player is allowed to be idle (in minutes)" );
void CTFPlayer::CheckForIdle( void )
{
if ( m_afButtonLast != m_nButtons )
m_flLastAction = gpGlobals->curtime;
if ( mp_idledealmethod.GetInt() )
{
if ( IsHLTV() )
return;
if ( IsFakeClient() )
return;
//Don't mess with the host on a listen server (probably one of us debugging something)
if ( engine->IsDedicatedServer() == false && entindex() == 1 )
return;
if ( m_bIsIdle == false )
{
if ( StateGet() == TF_STATE_OBSERVER || StateGet() != TF_STATE_ACTIVE )
return;
}
float flIdleTime = mp_idlemaxtime.GetFloat() * 60;
if ( TFGameRules()->InStalemate() )
{
flIdleTime = mp_stalemate_timelimit.GetInt() * 0.5f;
}
if ( (gpGlobals->curtime - m_flLastAction) > flIdleTime )
{
bool bKickPlayer = false;
ConVarRef mp_allowspectators( "mp_allowspectators" );
if ( mp_allowspectators.IsValid() && ( mp_allowspectators.GetBool() == false ) )
{
// just kick the player if this server doesn't allow spectators
bKickPlayer = true;
}
else if ( mp_idledealmethod.GetInt() == 1 )
{
//First send them into spectator mode then kick him.
if ( m_bIsIdle == false )
{
ForceChangeTeam( TEAM_SPECTATOR );
m_flLastAction = gpGlobals->curtime;
m_bIsIdle = true;
return;
}
else
{
bKickPlayer = true;
}
}
else if ( mp_idledealmethod.GetInt() == 2 )
{
bKickPlayer = true;
}
if ( bKickPlayer == true )
{
UTIL_ClientPrintAll( HUD_PRINTCONSOLE, "#game_idle_kick", GetPlayerName() );
engine->ServerCommand( UTIL_VarArgs( "kickid %d\n", GetUserID() ) );
m_flLastAction = gpGlobals->curtime;
}
}
}
}
extern ConVar flashlight;
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
int CTFPlayer::FlashlightIsOn( void )
{
return IsEffectActive( EF_DIMLIGHT );
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void CTFPlayer::FlashlightTurnOn( void )
{
if( flashlight.GetInt() > 0 && IsAlive() )
{
AddEffects( EF_DIMLIGHT );
}
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void CTFPlayer::FlashlightTurnOff( void )
{
if( IsEffectActive(EF_DIMLIGHT) )
{
RemoveEffects( EF_DIMLIGHT );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFPlayer::PostThink()
{
BaseClass::PostThink();
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] );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFPlayer::Precache()
{
// Precache the player models and gibs.
PrecachePlayerModels();
// Precache the player sounds.
PrecacheScriptSound( "Player.Spawn" );
PrecacheScriptSound( "TFPlayer.Pain" );
PrecacheScriptSound( "TFPlayer.CritHit" );
PrecacheScriptSound( "TFPlayer.CritPain" );
PrecacheScriptSound( "TFPlayer.CritDeath" );
PrecacheScriptSound( "TFPlayer.FreezeCam" );
PrecacheScriptSound( "TFPlayer.Drown" );
PrecacheScriptSound( "TFPlayer.AttackerPain" );
PrecacheScriptSound( "TFPlayer.SaveMe" );
PrecacheScriptSound( "Camera.SnapShot" );
PrecacheScriptSound( "Game.YourTeamLost" );
PrecacheScriptSound( "Game.YourTeamWon" );
PrecacheScriptSound( "Game.SuddenDeath" );
PrecacheScriptSound( "Game.Stalemate" );
PrecacheScriptSound( "TV.Tune" );
// Precache particle systems
PrecacheParticleSystem( "crit_text" );
PrecacheParticleSystem( "cig_smoke" );
PrecacheParticleSystem( "speech_mediccall" );
PrecacheParticleSystem( "player_recent_teleport_blue" );
PrecacheParticleSystem( "player_recent_teleport_red" );
PrecacheParticleSystem( "particle_nemesis_red" );
PrecacheParticleSystem( "particle_nemesis_blue" );
PrecacheParticleSystem( "spy_start_disguise_red" );
PrecacheParticleSystem( "spy_start_disguise_blue" );
PrecacheParticleSystem( "burningplayer_red" );
PrecacheParticleSystem( "burningplayer_blue" );
PrecacheParticleSystem( "blood_spray_red_01" );
PrecacheParticleSystem( "blood_spray_red_01_far" );
PrecacheParticleSystem( "water_blood_impact_red_01" );
PrecacheParticleSystem( "blood_impact_red_01" );
PrecacheParticleSystem( "water_playerdive" );
PrecacheParticleSystem( "water_playeremerge" );
BaseClass::Precache();
}
//-----------------------------------------------------------------------------
// Purpose: Precache the player models and player model gibs.
//-----------------------------------------------------------------------------
void CTFPlayer::PrecachePlayerModels( void )
{
int i;
for ( i = 0; i < TF_CLASS_COUNT_ALL; i++ )
{
const char *pszModel = GetPlayerClassData( i )->m_szModelName;
if ( pszModel && pszModel[0] )
{
int iModel = PrecacheModel( pszModel );
PrecacheGibsForModel( iModel );
}
if ( !IsX360() )
{
// Precache the hardware facial morphed models as well.
const char *pszHWMModel = GetPlayerClassData( i )->m_szHWMModelName;
if ( pszHWMModel && pszHWMModel[0] )
{
PrecacheModel( pszHWMModel );
}
}
}
if ( TFGameRules() && TFGameRules()->IsBirthday() )
{
for ( i = 1; i < ARRAYSIZE(g_pszBDayGibs); i++ )
{
PrecacheModel( g_pszBDayGibs[i] );
}
PrecacheModel( "models/effects/bday_hat.mdl" );
}
// Precache player class sounds
for ( i = TF_FIRST_NORMAL_CLASS; i < TF_CLASS_COUNT_ALL; ++i )
{
TFPlayerClassData_t *pData = GetPlayerClassData( i );
PrecacheScriptSound( pData->m_szDeathSound );
PrecacheScriptSound( pData->m_szCritDeathSound );
PrecacheScriptSound( pData->m_szMeleeDeathSound );
PrecacheScriptSound( pData->m_szExplosionDeathSound );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CTFPlayer::IsReadyToPlay( void )
{
return ( ( GetTeamNumber() > LAST_SHARED_TEAM ) &&
( GetDesiredPlayerClassIndex() > TF_CLASS_UNDEFINED ) );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CTFPlayer::IsReadyToSpawn( void )
{
if ( IsClassMenuOpen() )
{
return false;
}
return ( StateGet() != TF_STATE_DYING );
}
//-----------------------------------------------------------------------------
// Purpose: Return true if this player should be allowed to instantly spawn
// when they next finish picking a class.
//-----------------------------------------------------------------------------
bool CTFPlayer::ShouldGainInstantSpawn( void )
{
return ( GetPlayerClass()->GetClassIndex() == TF_CLASS_UNDEFINED || IsClassMenuOpen() );
}
//-----------------------------------------------------------------------------
// Purpose: Resets player scores
//-----------------------------------------------------------------------------
void CTFPlayer::ResetScores( void )
{
CTF_GameStats.ResetPlayerStats( this );
RemoveNemesisRelationships();
BaseClass::ResetScores();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFPlayer::InitialSpawn( void )
{
BaseClass::InitialSpawn();
SetWeaponBuilder( NULL );
m_iMaxSentryKills = 0;
CTF_GameStats.Event_MaxSentryKills( this, 0 );
StateEnter( TF_STATE_WELCOME );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFPlayer::Spawn()
{
MDLCACHE_CRITICAL_SECTION();
m_flSpawnTime = gpGlobals->curtime;
UpdateModel();
SetMoveType( MOVETYPE_WALK );
BaseClass::Spawn();
// Create our off hand viewmodel if necessary
CreateViewModel( 1 );
// Make sure it has no model set, in case it had one before
GetViewModel(1)->SetModel( "" );
// Kind of lame, but CBasePlayer::Spawn resets a lot of the state that we initially want on.
// So if we're in the welcome state, call its enter function to reset
if ( m_Shared.InState( TF_STATE_WELCOME ) )
{
StateEnterWELCOME();
}
// If they were dead, then they're respawning. Put them in the active state.
if ( m_Shared.InState( TF_STATE_DYING ) )
{
StateTransition( TF_STATE_ACTIVE );
}
// If they're spawning into the world as fresh meat, give them items and stuff.
if ( m_Shared.InState( TF_STATE_ACTIVE ) )
{
// remove our disguise each time we spawn
if ( m_Shared.InCond( TF_COND_DISGUISED ) )
{
m_Shared.RemoveDisguise();
}
EmitSound( "Player.Spawn" );
InitClass();
m_Shared.RemoveAllCond( NULL ); // Remove conc'd, burning, rotting, hallucinating, etc.
UpdateSkin( GetTeamNumber() );
TeamFortress_SetSpeed();
// Prevent firing for a second so players don't blow their faces off
SetNextAttack( gpGlobals->curtime + 1.0 );
DoAnimationEvent( PLAYERANIMEVENT_SPAWN );
// Force a taunt off, if we are still taunting, the condition should have been cleared above.
if( m_hTauntScene.Get() )
{
StopScriptedScene( this, m_hTauntScene );
m_Shared.m_flTauntRemoveTime = 0.0f;
m_hTauntScene = NULL;
}
// turn on separation so players don't get stuck in each other when spawned
m_Shared.SetSeparation( true );
m_Shared.SetSeparationVelocity( vec3_origin );
RemoveTeleportEffect();
//If this is true it means I respawned without dying (changing class inside the spawn room) but doesn't necessarily mean that my healers have stopped healing me
//This means that medics can still be linked to me but my health would not be affected since this condition is not set.
//So instead of going and forcing every healer on me to stop healing we just set this condition back on.
//If the game decides I shouldn't be healed by someone (LOS, Distance, etc) they will break the link themselves like usual.
if ( m_Shared.GetNumHealers() > 0 )
{
m_Shared.AddCond( TF_COND_HEALTH_BUFF );
}
if ( !m_bSeenRoundInfo )
{
TFGameRules()->ShowRoundInfoPanel( this );
m_bSeenRoundInfo = true;
}
if ( IsInCommentaryMode() && !IsFakeClient() )
{
// Player is spawning in commentary mode. Tell the commentary system.
CBaseEntity *pEnt = NULL;
variant_t emptyVariant;
while ( (pEnt = gEntList.FindEntityByClassname( pEnt, "commentary_auto" )) != NULL )
{
pEnt->AcceptInput( "MultiplayerSpawned", this, this, emptyVariant, 0 );
}
}
}
CTF_GameStats.Event_PlayerSpawned( this );
m_iSpawnCounter = !m_iSpawnCounter;
m_bAllowInstantSpawn = false;
m_Shared.SetSpyCloakMeter( 100.0f );
m_Shared.ClearDamageEvents();
ClearDamagerHistory();
m_flLastDamageTime = 0;
m_flNextVoiceCommandTime = gpGlobals->curtime;
ClearZoomOwner();
SetFOV( this , 0 );
SetViewOffset( GetClassEyeHeight() );
ClearExpression();
m_flNextSpeakWeaponFire = gpGlobals->curtime;
m_bIsIdle = false;
m_flPowerPlayTime = 0.0;
// This makes the surrounding box always the same size as the standing collision box
// helps with parts of the hitboxes that extend out of the crouching hitbox, eg with the
// heavyweapons guy
Vector mins = VEC_HULL_MIN;
Vector maxs = VEC_HULL_MAX;
CollisionProp()->SetSurroundingBoundsType( USE_SPECIFIED_BOUNDS, &mins, &maxs );
}
//-----------------------------------------------------------------------------
// Purpose: Removes all nemesis relationships between this player and others
//-----------------------------------------------------------------------------
void CTFPlayer::RemoveNemesisRelationships()
{
for ( int i = 1 ; i <= gpGlobals->maxClients ; i++ )
{
CTFPlayer *pTemp = ToTFPlayer( UTIL_PlayerByIndex( i ) );
if ( pTemp && pTemp != this )
{
// set this player to be not dominating anyone else
m_Shared.SetPlayerDominated( pTemp, false );
// set no one else to be dominating this player
pTemp->m_Shared.SetPlayerDominated( this, false );
}
}
// reset the matrix of who has killed whom with respect to this player
CTF_GameStats.ResetKillHistory( this );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFPlayer::Regenerate( void )
{
// We may have been boosted over our max health. If we have,
// restore it after we reset out class values.
int iCurrentHealth = GetHealth();
m_bRegenerating = true;
InitClass();
m_bRegenerating = false;
if ( iCurrentHealth > GetHealth() )
{
SetHealth( iCurrentHealth );
}
if ( m_Shared.InCond( TF_COND_BURNING ) )
{
m_Shared.RemoveCond( TF_COND_BURNING );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFPlayer::InitClass( void )
{
// Set initial health and armor based on class.
SetMaxHealth( GetPlayerClass()->GetMaxHealth() );
SetHealth( GetMaxHealth() );
SetArmorValue( GetPlayerClass()->GetMaxArmor() );
// Init the anim movement vars
m_PlayerAnimState->SetRunSpeed( GetPlayerClass()->GetMaxSpeed() );
m_PlayerAnimState->SetWalkSpeed( GetPlayerClass()->GetMaxSpeed() * 0.5 );
// Give default items for class.
GiveDefaultItems();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFPlayer::CreateViewModel( int iViewModel )
{
Assert( iViewModel >= 0 && iViewModel < MAX_VIEWMODELS );
if ( GetViewModel( iViewModel ) )
return;
CTFViewModel *pViewModel = ( CTFViewModel * )CreateEntityByName( "tf_viewmodel" );
if ( pViewModel )
{
pViewModel->SetAbsOrigin( GetAbsOrigin() );
pViewModel->SetOwner( this );
pViewModel->SetIndex( iViewModel );
DispatchSpawn( pViewModel );
pViewModel->FollowEntity( this, false );
m_hViewModel.Set( iViewModel, pViewModel );
}
}
//-----------------------------------------------------------------------------
// Purpose: Gets the view model for the player's off hand
//-----------------------------------------------------------------------------
CBaseViewModel *CTFPlayer::GetOffHandViewModel()
{
// off hand model is slot 1
return GetViewModel( 1 );
}
//-----------------------------------------------------------------------------
// Purpose: Sends the specified animation activity to the off hand view model
//-----------------------------------------------------------------------------
void CTFPlayer::SendOffHandViewModelActivity( Activity activity )
{
CBaseViewModel *pViewModel = GetOffHandViewModel();
if ( pViewModel )
{
int sequence = pViewModel->SelectWeightedSequence( activity );
pViewModel->SendViewModelMatchingSequence( sequence );
}
}
//-----------------------------------------------------------------------------
// Purpose: Set the player up with the default weapons, ammo, etc.
//-----------------------------------------------------------------------------
void CTFPlayer::GiveDefaultItems()
{
// Get the player class data.
TFPlayerClassData_t *pData = m_PlayerClass.GetData();
RemoveAllAmmo();
// Give ammo. Must be done before weapons, so weapons know the player has ammo for them.
for ( int iAmmo = 0; iAmmo < TF_AMMO_COUNT; ++iAmmo )
{
GiveAmmo( pData->m_aAmmoMax[iAmmo], iAmmo );