-
-
Notifications
You must be signed in to change notification settings - Fork 213
/
Copy pathplayer.cpp
9416 lines (7790 loc) · 249 KB
/
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 Valve Corporation, All rights reserved. ============//
//
// Purpose: Functions dealing with the player.
//
//===========================================================================//
#include "cbase.h"
#include "const.h"
#include "baseplayer_shared.h"
#include "trains.h"
#include "soundent.h"
#include "gib.h"
#include "shake.h"
#include "decals.h"
#include "gamerules.h"
#include "game.h"
#include "entityapi.h"
#include "entitylist.h"
#include "eventqueue.h"
#include "worldsize.h"
#include "isaverestore.h"
#include "globalstate.h"
#include "basecombatweapon.h"
#include "ai_basenpc.h"
#include "ai_network.h"
#include "ai_node.h"
#include "ai_networkmanager.h"
#include "ammodef.h"
#include "mathlib/mathlib.h"
#include "ndebugoverlay.h"
#include "baseviewmodel.h"
#include "in_buttons.h"
#include "client.h"
#include "team.h"
#include "particle_smokegrenade.h"
#include "IEffects.h"
#include "vstdlib/random.h"
#include "engine/IEngineSound.h"
#include "movehelper_server.h"
#include "igamemovement.h"
#include "saverestoretypes.h"
#include "iservervehicle.h"
#include "movevars_shared.h"
#include "vcollide_parse.h"
#include "player_command.h"
#include "vehicle_base.h"
#include "AI_Criteria.h"
#include "globals.h"
#include "usermessages.h"
#include "gamevars_shared.h"
#include "world.h"
#include "physobj.h"
#include "KeyValues.h"
#include "coordsize.h"
#include "vphysics/player_controller.h"
#include "saverestore_utlvector.h"
#include "hltvdirector.h"
#include "nav_mesh.h"
#include "env_zoom.h"
#include "rumble_shared.h"
#include "gamestats.h"
#include "npcevent.h"
#include "datacache/imdlcache.h"
#include "hintsystem.h"
#include "env_debughistory.h"
#include "fogcontroller.h"
#include "gameinterface.h"
#include "hl2orange.spa.h"
#include "dt_utlvector_send.h"
#include "vote_controller.h"
#include "ai_speech.h"
#if defined USES_ECON_ITEMS
#include "econ_wearable.h"
#endif
// NVNT haptic utils
#include "haptics/haptic_utils.h"
#ifdef HL2_DLL
#include "combine_mine.h"
#include "weapon_physcannon.h"
#endif
ConVar autoaim_max_dist( "autoaim_max_dist", "2160" ); // 2160 = 180 feet
ConVar autoaim_max_deflect( "autoaim_max_deflect", "0.99" );
#ifdef CSTRIKE_DLL
ConVar spec_freeze_time( "spec_freeze_time", "5.0", FCVAR_CHEAT | FCVAR_REPLICATED, "Time spend frozen in observer freeze cam." );
ConVar spec_freeze_traveltime( "spec_freeze_traveltime", "0.7", FCVAR_CHEAT | FCVAR_REPLICATED, "Time taken to zoom in to frame a target in observer freeze cam.", true, 0.01, false, 0 );
#else
ConVar spec_freeze_time( "spec_freeze_time", "4.0", FCVAR_CHEAT | FCVAR_REPLICATED, "Time spend frozen in observer freeze cam." );
ConVar spec_freeze_traveltime( "spec_freeze_traveltime", "0.4", FCVAR_CHEAT | FCVAR_REPLICATED, "Time taken to zoom in to frame a target in observer freeze cam.", true, 0.01, false, 0 );
#endif
ConVar sv_bonus_challenge( "sv_bonus_challenge", "0", FCVAR_REPLICATED, "Set to values other than 0 to select a bonus map challenge type." );
static ConVar sv_maxusrcmdprocessticks( "sv_maxusrcmdprocessticks", "24", FCVAR_NOTIFY, "Maximum number of client-issued usrcmd ticks that can be replayed in packet loss conditions, 0 to allow no restrictions" );
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
static ConVar old_armor( "player_old_armor", "0" );
static ConVar physicsshadowupdate_render( "physicsshadowupdate_render", "0" );
bool IsInCommentaryMode( void );
bool IsListeningToCommentary( void );
#if !defined( CSTRIKE_DLL )
ConVar cl_sidespeed( "cl_sidespeed", "450", FCVAR_REPLICATED | FCVAR_CHEAT );
ConVar cl_upspeed( "cl_upspeed", "320", FCVAR_REPLICATED | FCVAR_CHEAT );
ConVar cl_forwardspeed( "cl_forwardspeed", "450", FCVAR_REPLICATED | FCVAR_CHEAT );
ConVar cl_backspeed( "cl_backspeed", "450", FCVAR_REPLICATED | FCVAR_CHEAT );
#endif // CSTRIKE_DLL
// This is declared in the engine, too
ConVar sv_noclipduringpause( "sv_noclipduringpause", "0", FCVAR_REPLICATED | FCVAR_CHEAT, "If cheats are enabled, then you can noclip with the game paused (for doing screenshots, etc.)." );
extern ConVar sv_maxunlag;
extern ConVar sv_turbophysics;
extern ConVar *sv_maxreplay;
extern CServerGameDLL g_ServerGameDLL;
// TIME BASED DAMAGE AMOUNT
// tweak these values based on gameplay feedback:
#define PARALYZE_DURATION 2 // number of 2 second intervals to take damage
#define PARALYZE_DAMAGE 1.0 // damage to take each 2 second interval
#define NERVEGAS_DURATION 2
#define NERVEGAS_DAMAGE 5.0
#define POISON_DURATION 5
#define POISON_DAMAGE 2.0
#define RADIATION_DURATION 2
#define RADIATION_DAMAGE 1.0
#define ACID_DURATION 2
#define ACID_DAMAGE 5.0
#define SLOWBURN_DURATION 2
#define SLOWBURN_DAMAGE 1.0
#define SLOWFREEZE_DURATION 2
#define SLOWFREEZE_DAMAGE 1.0
//----------------------------------------------------
// Player Physics Shadow
//----------------------------------------------------
#define VPHYS_MAX_DISTANCE 2.0
#define VPHYS_MAX_VEL 10
#define VPHYS_MAX_DISTSQR (VPHYS_MAX_DISTANCE*VPHYS_MAX_DISTANCE)
#define VPHYS_MAX_VELSQR (VPHYS_MAX_VEL*VPHYS_MAX_VEL)
extern bool g_fDrawLines;
int gEvilImpulse101;
bool gInitHUD = true;
extern void respawn(CBaseEntity *pEdict, bool fCopyCorpse);
int MapTextureTypeStepType(char chTextureType);
extern void SpawnBlood(Vector vecSpot, const Vector &vecDir, int bloodColor, float flDamage);
extern void AddMultiDamage( const CTakeDamageInfo &info, CBaseEntity *pEntity );
#define CMD_MOSTRECENT 0
//#define FLASH_DRAIN_TIME 1.2 //100 units/3 minutes
//#define FLASH_CHARGE_TIME 0.2 // 100 units/20 seconds (seconds per unit)
//#define PLAYER_MAX_SAFE_FALL_DIST 20// falling any farther than this many feet will inflict damage
//#define PLAYER_FATAL_FALL_DIST 60// 100% damage inflicted if player falls this many feet
//#define DAMAGE_PER_UNIT_FALLEN (float)( 100 ) / ( ( PLAYER_FATAL_FALL_DIST - PLAYER_MAX_SAFE_FALL_DIST ) * 12 )
//#define MAX_SAFE_FALL_UNITS ( PLAYER_MAX_SAFE_FALL_DIST * 12 )
// player damage adjusters
ConVar sk_player_head( "sk_player_head","2" );
ConVar sk_player_chest( "sk_player_chest","1" );
ConVar sk_player_stomach( "sk_player_stomach","1" );
ConVar sk_player_arm( "sk_player_arm","1" );
ConVar sk_player_leg( "sk_player_leg","1" );
//ConVar player_usercommand_timeout( "player_usercommand_timeout", "10", 0, "After this many seconds without a usercommand from a player, the client is kicked." );
#ifdef _DEBUG
ConVar sv_player_net_suppress_usercommands( "sv_player_net_suppress_usercommands", "0", FCVAR_CHEAT, "For testing usercommand hacking sideeffects. DO NOT SHIP" );
#endif // _DEBUG
ConVar sv_player_display_usercommand_errors( "sv_player_display_usercommand_errors", "0", FCVAR_CHEAT, "1 = Display warning when command values are out-of-range. 2 = Spew invalid ranges." );
ConVar player_debug_print_damage( "player_debug_print_damage", "0", FCVAR_CHEAT, "When true, print amount and type of all damage received by player to console." );
void CC_GiveCurrentAmmo( void )
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(1);
if( pPlayer )
{
CBaseCombatWeapon *pWeapon = pPlayer->GetActiveWeapon();
if( pWeapon )
{
if( pWeapon->UsesPrimaryAmmo() )
{
int ammoIndex = pWeapon->GetPrimaryAmmoType();
if( ammoIndex != -1 )
{
int giveAmount;
giveAmount = GetAmmoDef()->MaxCarry(ammoIndex);
pPlayer->GiveAmmo( giveAmount, GetAmmoDef()->GetAmmoOfIndex(ammoIndex)->pName );
}
}
if( pWeapon->UsesSecondaryAmmo() && pWeapon->HasSecondaryAmmo() )
{
// Give secondary ammo out, as long as the player already has some
// from a presumeably natural source. This prevents players on XBox
// having Combine Balls and so forth in areas of the game that
// were not tested with these items.
int ammoIndex = pWeapon->GetSecondaryAmmoType();
if( ammoIndex != -1 )
{
int giveAmount;
giveAmount = GetAmmoDef()->MaxCarry(ammoIndex);
pPlayer->GiveAmmo( giveAmount, GetAmmoDef()->GetAmmoOfIndex(ammoIndex)->pName );
}
}
}
}
}
static ConCommand givecurrentammo("givecurrentammo", CC_GiveCurrentAmmo, "Give a supply of ammo for current weapon..\n", FCVAR_CHEAT );
// pl
BEGIN_SIMPLE_DATADESC( CPlayerState )
// DEFINE_FIELD( netname, FIELD_STRING ), // Don't stomp player name with what's in save/restore
DEFINE_FIELD( v_angle, FIELD_VECTOR ),
DEFINE_FIELD( deadflag, FIELD_BOOLEAN ),
// this is always set to true on restore, don't bother saving it.
// DEFINE_FIELD( fixangle, FIELD_INTEGER ),
// DEFINE_FIELD( anglechange, FIELD_FLOAT ),
// DEFINE_FIELD( hltv, FIELD_BOOLEAN ),
// DEFINE_FIELD( replay, FIELD_BOOLEAN ),
// DEFINE_FIELD( frags, FIELD_INTEGER ),
// DEFINE_FIELD( deaths, FIELD_INTEGER ),
END_DATADESC()
// Global Savedata for player
BEGIN_DATADESC( CBasePlayer )
DEFINE_EMBEDDED( m_Local ),
#if defined USES_ECON_ITEMS
DEFINE_EMBEDDED( m_AttributeList ),
#endif
DEFINE_UTLVECTOR( m_hTriggerSoundscapeList, FIELD_EHANDLE ),
DEFINE_EMBEDDED( pl ),
DEFINE_FIELD( m_StuckLast, FIELD_INTEGER ),
DEFINE_FIELD( m_nButtons, FIELD_INTEGER ),
DEFINE_FIELD( m_afButtonLast, FIELD_INTEGER ),
DEFINE_FIELD( m_afButtonPressed, FIELD_INTEGER ),
DEFINE_FIELD( m_afButtonReleased, FIELD_INTEGER ),
DEFINE_FIELD( m_afButtonDisabled, FIELD_INTEGER ),
DEFINE_FIELD( m_afButtonForced, FIELD_INTEGER ),
DEFINE_FIELD( m_iFOV, FIELD_INTEGER ),
DEFINE_FIELD( m_iFOVStart, FIELD_INTEGER ),
DEFINE_FIELD( m_flFOVTime, FIELD_TIME ),
DEFINE_FIELD( m_iDefaultFOV,FIELD_INTEGER ),
DEFINE_FIELD( m_flVehicleViewFOV, FIELD_FLOAT ),
//DEFINE_FIELD( m_fOnTarget, FIELD_BOOLEAN ), // Don't need to restore
DEFINE_FIELD( m_iObserverMode, FIELD_INTEGER ),
DEFINE_FIELD( m_iObserverLastMode, FIELD_INTEGER ),
DEFINE_FIELD( m_hObserverTarget, FIELD_EHANDLE ),
DEFINE_FIELD( m_bForcedObserverMode, FIELD_BOOLEAN ),
DEFINE_AUTO_ARRAY( m_szAnimExtension, FIELD_CHARACTER ),
// DEFINE_CUSTOM_FIELD( m_Activity, ActivityDataOps() ),
DEFINE_FIELD( m_nUpdateRate, FIELD_INTEGER ),
DEFINE_FIELD( m_fLerpTime, FIELD_FLOAT ),
DEFINE_FIELD( m_bLagCompensation, FIELD_BOOLEAN ),
DEFINE_FIELD( m_bPredictWeapons, FIELD_BOOLEAN ),
DEFINE_FIELD( m_vecAdditionalPVSOrigin, FIELD_POSITION_VECTOR ),
DEFINE_FIELD( m_vecCameraPVSOrigin, FIELD_POSITION_VECTOR ),
DEFINE_FIELD( m_hUseEntity, FIELD_EHANDLE ),
DEFINE_FIELD( m_iTrain, FIELD_INTEGER ),
DEFINE_FIELD( m_iRespawnFrames, FIELD_FLOAT ),
DEFINE_FIELD( m_afPhysicsFlags, FIELD_INTEGER ),
DEFINE_FIELD( m_hVehicle, FIELD_EHANDLE ),
// recreate, don't restore
// DEFINE_FIELD( m_CommandContext, CUtlVector < CCommandContext > ),
//DEFINE_FIELD( m_pPhysicsController, FIELD_POINTER ),
//DEFINE_FIELD( m_pShadowStand, FIELD_POINTER ),
//DEFINE_FIELD( m_pShadowCrouch, FIELD_POINTER ),
//DEFINE_FIELD( m_vphysicsCollisionState, FIELD_INTEGER ),
DEFINE_ARRAY( m_szNetworkIDString, FIELD_CHARACTER, MAX_NETWORKID_LENGTH ),
DEFINE_FIELD( m_oldOrigin, FIELD_POSITION_VECTOR ),
DEFINE_FIELD( m_vecSmoothedVelocity, FIELD_VECTOR ),
//DEFINE_FIELD( m_touchedPhysObject, FIELD_BOOLEAN ),
//DEFINE_FIELD( m_bPhysicsWasFrozen, FIELD_BOOLEAN ),
//DEFINE_FIELD( m_iPlayerSound, FIELD_INTEGER ), // Don't restore, set in Precache()
DEFINE_FIELD( m_iTargetVolume, FIELD_INTEGER ),
DEFINE_AUTO_ARRAY( m_rgItems, FIELD_INTEGER ),
//DEFINE_FIELD( m_fNextSuicideTime, FIELD_TIME ),
// DEFINE_FIELD( m_PlayerInfo, CPlayerInfo ),
DEFINE_FIELD( m_flSwimTime, FIELD_TIME ),
DEFINE_FIELD( m_flDuckTime, FIELD_TIME ),
DEFINE_FIELD( m_flDuckJumpTime, FIELD_TIME ),
DEFINE_FIELD( m_flSuitUpdate, FIELD_TIME ),
DEFINE_AUTO_ARRAY( m_rgSuitPlayList, FIELD_INTEGER ),
DEFINE_FIELD( m_iSuitPlayNext, FIELD_INTEGER ),
DEFINE_AUTO_ARRAY( m_rgiSuitNoRepeat, FIELD_INTEGER ),
DEFINE_AUTO_ARRAY( m_rgflSuitNoRepeatTime, FIELD_TIME ),
DEFINE_FIELD( m_bPauseBonusProgress, FIELD_BOOLEAN ),
DEFINE_FIELD( m_iBonusProgress, FIELD_INTEGER ),
DEFINE_FIELD( m_iBonusChallenge, FIELD_INTEGER ),
DEFINE_FIELD( m_lastDamageAmount, FIELD_INTEGER ),
DEFINE_FIELD( m_tbdPrev, FIELD_TIME ),
DEFINE_FIELD( m_flStepSoundTime, FIELD_FLOAT ),
DEFINE_ARRAY( m_szNetname, FIELD_CHARACTER, MAX_PLAYER_NAME_LENGTH ),
//DEFINE_FIELD( m_flgeigerRange, FIELD_FLOAT ), // Don't restore, reset in Precache()
//DEFINE_FIELD( m_flgeigerDelay, FIELD_FLOAT ), // Don't restore, reset in Precache()
//DEFINE_FIELD( m_igeigerRangePrev, FIELD_FLOAT ), // Don't restore, reset in Precache()
//DEFINE_FIELD( m_iStepLeft, FIELD_INTEGER ), // Don't need to restore
//DEFINE_FIELD( m_chTextureType, FIELD_CHARACTER ), // Don't need to restore
//DEFINE_FIELD( m_surfaceProps, FIELD_INTEGER ), // don't need to restore, reset by gamemovement
// DEFINE_FIELD( m_pSurfaceData, surfacedata_t* ),
//DEFINE_FIELD( m_surfaceFriction, FIELD_FLOAT ),
//DEFINE_FIELD( m_chPreviousTextureType, FIELD_CHARACTER ),
DEFINE_FIELD( m_idrowndmg, FIELD_INTEGER ),
DEFINE_FIELD( m_idrownrestored, FIELD_INTEGER ),
DEFINE_FIELD( m_nPoisonDmg, FIELD_INTEGER ),
DEFINE_FIELD( m_nPoisonRestored, FIELD_INTEGER ),
DEFINE_FIELD( m_bitsHUDDamage, FIELD_INTEGER ),
DEFINE_FIELD( m_fInitHUD, FIELD_BOOLEAN ),
DEFINE_FIELD( m_flDeathTime, FIELD_TIME ),
DEFINE_FIELD( m_flDeathAnimTime, FIELD_TIME ),
//DEFINE_FIELD( m_fGameHUDInitialized, FIELD_BOOLEAN ), // only used in multiplayer games
//DEFINE_FIELD( m_fWeapon, FIELD_BOOLEAN ), // Don't restore, client needs reset
//DEFINE_FIELD( m_iUpdateTime, FIELD_INTEGER ), // Don't need to restore
//DEFINE_FIELD( m_iClientBattery, FIELD_INTEGER ), // Don't restore, client needs reset
//DEFINE_FIELD( m_iClientHideHUD, FIELD_INTEGER ), // Don't restore, client needs reset
//DEFINE_FIELD( m_vecAutoAim, FIELD_VECTOR ), // Don't save/restore - this is recomputed
//DEFINE_FIELD( m_lastx, FIELD_INTEGER ),
//DEFINE_FIELD( m_lasty, FIELD_INTEGER ),
DEFINE_FIELD( m_iFrags, FIELD_INTEGER ),
DEFINE_FIELD( m_iDeaths, FIELD_INTEGER ),
DEFINE_FIELD( m_bAllowInstantSpawn, FIELD_BOOLEAN ),
DEFINE_FIELD( m_flNextDecalTime, FIELD_TIME ),
//DEFINE_AUTO_ARRAY( m_szTeamName, FIELD_STRING ), // mp
//DEFINE_FIELD( m_iConnected, FIELD_INTEGER ),
// from edict_t
DEFINE_FIELD( m_ArmorValue, FIELD_INTEGER ),
DEFINE_FIELD( m_DmgOrigin, FIELD_VECTOR ),
DEFINE_FIELD( m_DmgTake, FIELD_FLOAT ),
DEFINE_FIELD( m_DmgSave, FIELD_FLOAT ),
DEFINE_FIELD( m_AirFinished, FIELD_TIME ),
DEFINE_FIELD( m_PainFinished, FIELD_TIME ),
DEFINE_FIELD( m_iPlayerLocked, FIELD_INTEGER ),
DEFINE_AUTO_ARRAY( m_hViewModel, FIELD_EHANDLE ),
DEFINE_FIELD( m_flMaxspeed, FIELD_FLOAT ),
DEFINE_FIELD( m_flWaterJumpTime, FIELD_TIME ),
DEFINE_FIELD( m_vecWaterJumpVel, FIELD_VECTOR ),
DEFINE_FIELD( m_nImpulse, FIELD_INTEGER ),
DEFINE_FIELD( m_flSwimSoundTime, FIELD_TIME ),
DEFINE_FIELD( m_vecLadderNormal, FIELD_VECTOR ),
DEFINE_FIELD( m_flFlashTime, FIELD_TIME ),
DEFINE_FIELD( m_nDrownDmgRate, FIELD_INTEGER ),
DEFINE_FIELD( m_iSuicideCustomKillFlags, FIELD_INTEGER ),
// NOT SAVED
//DEFINE_FIELD( m_vForcedOrigin, FIELD_VECTOR ),
//DEFINE_FIELD( m_bForceOrigin, FIELD_BOOLEAN ),
//DEFINE_FIELD( m_nTickBase, FIELD_INTEGER ),
//DEFINE_FIELD( m_LastCmd, FIELD_ ),
// DEFINE_FIELD( m_pCurrentCommand, CUserCmd ),
//DEFINE_FIELD( m_bGamePaused, FIELD_BOOLEAN ),
// DEFINE_FIELD( m_iVehicleAnalogBias, FIELD_INTEGER ),
// m_flVehicleViewFOV
// m_vecVehicleViewOrigin
// m_vecVehicleViewAngles
// m_nVehicleViewSavedFrame
DEFINE_FIELD( m_bitsDamageType, FIELD_INTEGER ),
DEFINE_AUTO_ARRAY( m_rgbTimeBasedDamage, FIELD_CHARACTER ),
DEFINE_FIELD( m_fLastPlayerTalkTime, FIELD_FLOAT ),
DEFINE_FIELD( m_hLastWeapon, FIELD_EHANDLE ),
#if !defined( NO_ENTITY_PREDICTION )
// DEFINE_FIELD( m_SimulatedByThisPlayer, CUtlVector < CHandle < CBaseEntity > > ),
#endif
DEFINE_FIELD( m_flOldPlayerZ, FIELD_FLOAT ),
DEFINE_FIELD( m_flOldPlayerViewOffsetZ, FIELD_FLOAT ),
DEFINE_FIELD( m_bPlayerUnderwater, FIELD_BOOLEAN ),
DEFINE_FIELD( m_hViewEntity, FIELD_EHANDLE ),
DEFINE_FIELD( m_hConstraintEntity, FIELD_EHANDLE ),
DEFINE_FIELD( m_vecConstraintCenter, FIELD_VECTOR ),
DEFINE_FIELD( m_flConstraintRadius, FIELD_FLOAT ),
DEFINE_FIELD( m_flConstraintWidth, FIELD_FLOAT ),
DEFINE_FIELD( m_flConstraintSpeedFactor, FIELD_FLOAT ),
DEFINE_FIELD( m_hZoomOwner, FIELD_EHANDLE ),
DEFINE_FIELD( m_flLaggedMovementValue, FIELD_FLOAT ),
DEFINE_FIELD( m_vNewVPhysicsPosition, FIELD_VECTOR ),
DEFINE_FIELD( m_vNewVPhysicsVelocity, FIELD_VECTOR ),
DEFINE_FIELD( m_bSinglePlayerGameEnding, FIELD_BOOLEAN ),
DEFINE_ARRAY( m_szLastPlaceName, FIELD_CHARACTER, MAX_PLACE_NAME_LENGTH ),
DEFINE_FIELD( m_autoKickDisabled, FIELD_BOOLEAN ),
// Function Pointers
DEFINE_FUNCTION( PlayerDeathThink ),
// Inputs
DEFINE_INPUTFUNC( FIELD_INTEGER, "SetHealth", InputSetHealth ),
DEFINE_INPUTFUNC( FIELD_BOOLEAN, "SetHUDVisibility", InputSetHUDVisibility ),
DEFINE_INPUTFUNC( FIELD_STRING, "SetFogController", InputSetFogController ),
DEFINE_INPUTFUNC( FIELD_STRING, "HandleMapEvent", InputHandleMapEvent ),
DEFINE_FIELD( m_nNumCrouches, FIELD_INTEGER ),
DEFINE_FIELD( m_bDuckToggled, FIELD_BOOLEAN ),
DEFINE_FIELD( m_flForwardMove, FIELD_FLOAT ),
DEFINE_FIELD( m_flSideMove, FIELD_FLOAT ),
DEFINE_FIELD( m_vecPreviouslyPredictedOrigin, FIELD_POSITION_VECTOR ),
DEFINE_FIELD( m_nNumCrateHudHints, FIELD_INTEGER ),
// DEFINE_FIELD( m_nBodyPitchPoseParam, FIELD_INTEGER ),
// DEFINE_ARRAY( m_StepSoundCache, StepSoundCache_t, 2 ),
// DEFINE_UTLVECTOR( m_vecPlayerCmdInfo ),
// DEFINE_UTLVECTOR( m_vecPlayerSimInfo ),
END_DATADESC()
int giPrecacheGrunt = 0;
edict_t *CBasePlayer::s_PlayerEdict = NULL;
inline bool ShouldRunCommandsInContext( const CCommandContext *ctx )
{
// TODO: This should be enabled at some point. If usercmds can run while paused, then
// they can create entities which will never die and it will fill up the entity list.
#ifdef NO_USERCMDS_DURING_PAUSE
return !ctx->paused || sv_noclipduringpause.GetInt();
#else
return true;
#endif
}
//-----------------------------------------------------------------------------
// Purpose:
// Output : CBaseViewModel
//-----------------------------------------------------------------------------
CBaseViewModel *CBasePlayer::GetViewModel( int index /*= 0*/, bool bObserverOK )
{
Assert( index >= 0 && index < MAX_VIEWMODELS );
return m_hViewModel[ index ].Get();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBasePlayer::CreateViewModel( int index /*=0*/ )
{
Assert( index >= 0 && index < MAX_VIEWMODELS );
if ( GetViewModel( index ) )
return;
CBaseViewModel *vm = ( CBaseViewModel * )CreateEntityByName( "viewmodel" );
if ( vm )
{
vm->SetAbsOrigin( GetAbsOrigin() );
vm->SetOwner( this );
vm->SetIndex( index );
DispatchSpawn( vm );
vm->FollowEntity( this );
m_hViewModel.Set( index, vm );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBasePlayer::DestroyViewModels( void )
{
int i;
for ( i = MAX_VIEWMODELS - 1; i >= 0; i-- )
{
CBaseViewModel *vm = GetViewModel( i );
if ( !vm )
continue;
UTIL_Remove( vm );
m_hViewModel.Set( i, NULL );
}
}
//-----------------------------------------------------------------------------
// Purpose: Static member function to create a player of the specified class
// Input : *className -
// *ed -
// Output : CBasePlayer
//-----------------------------------------------------------------------------
CBasePlayer *CBasePlayer::CreatePlayer( const char *className, edict_t *ed )
{
CBasePlayer *player;
CBasePlayer::s_PlayerEdict = ed;
player = ( CBasePlayer * )CreateEntityByName( className );
return player;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input :
// Output :
//-----------------------------------------------------------------------------
CBasePlayer::CBasePlayer( )
{
AddEFlags( EFL_NO_AUTO_EDICT_ATTACH );
#ifdef _DEBUG
m_vecAutoAim.Init();
m_vecAdditionalPVSOrigin.Init();
m_vecCameraPVSOrigin.Init();
m_DmgOrigin.Init();
m_vecLadderNormal.Init();
m_oldOrigin.Init();
m_vecSmoothedVelocity.Init();
#endif
if ( s_PlayerEdict )
{
// take the assigned edict_t and attach it
Assert( s_PlayerEdict != NULL );
NetworkProp()->AttachEdict( s_PlayerEdict );
s_PlayerEdict = NULL;
}
m_flFlashTime = -1;
pl.fixangle = FIXANGLE_ABSOLUTE;
pl.hltv = false;
pl.replay = false;
pl.frags = 0;
pl.deaths = 0;
m_szNetname[0] = '\0';
m_iHealth = 0;
Weapon_SetLast( NULL );
m_bitsDamageType = 0;
m_bForceOrigin = false;
m_hVehicle = NULL;
m_pCurrentCommand = NULL;
m_iLockViewanglesTickNumber = 0;
m_qangLockViewangles.Init();
// Setup our default FOV
m_iDefaultFOV = g_pGameRules->DefaultFOV();
m_hZoomOwner = NULL;
m_nUpdateRate = 1.0f/TICK_INTERVAL; // cl_updaterate defualt
m_fLerpTime = TICK_INTERVAL; // cl_interp default
m_bPredictWeapons = true;
m_bLagCompensation = false;
m_flLaggedMovementValue = 1.0f;
m_StuckLast = 0;
m_impactEnergyScale = 1.0f;
m_fLastPlayerTalkTime = 0.0f;
m_PlayerInfo.SetParent( this );
ResetObserverMode();
m_surfaceProps = 0;
m_pSurfaceData = NULL;
m_surfaceFriction = 1.0f;
m_chTextureType = 0;
m_chPreviousTextureType = 0;
m_iSuicideCustomKillFlags = 0;
m_fDelay = 0.0f;
m_fReplayEnd = -1;
m_iReplayEntity = 0;
m_autoKickDisabled = false;
m_nNumCrouches = 0;
m_bDuckToggled = false;
m_bPhysicsWasFrozen = false;
// Used to mask off buttons
m_afButtonDisabled = 0;
m_afButtonForced = 0;
m_nBodyPitchPoseParam = -1;
m_flForwardMove = 0;
m_flSideMove = 0;
// NVNT default to no haptics
m_bhasHaptics = false;
m_vecConstraintCenter = vec3_origin;
m_flLastUserCommandTime = 0.f;
m_flMovementTimeForUserCmdProcessingRemaining = 0.0f;
m_flLastObjectiveTime = -1.f;
}
CBasePlayer::~CBasePlayer( )
{
VPhysicsDestroyObject();
}
//-----------------------------------------------------------------------------
// Purpose:
// Input :
// Output :
//-----------------------------------------------------------------------------
void CBasePlayer::UpdateOnRemove( void )
{
VPhysicsDestroyObject();
// Remove him from his current team
if ( GetTeam() )
{
GetTeam()->RemovePlayer( this );
}
// Chain at end to mimic destructor unwind order
BaseClass::UpdateOnRemove();
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : **pvs -
// **pas -
//-----------------------------------------------------------------------------
void CBasePlayer::SetupVisibility( CBaseEntity *pViewEntity, unsigned char *pvs, int pvssize )
{
// If we have a viewentity, we don't add the player's origin.
if ( pViewEntity )
return;
Vector org;
org = EyePosition();
engine->AddOriginToPVS( org );
}
int CBasePlayer::UpdateTransmitState()
{
// always call ShouldTransmit() for players
return SetTransmitState( FL_EDICT_FULLCHECK );
}
int CBasePlayer::ShouldTransmit( const CCheckTransmitInfo *pInfo )
{
// Allow me to introduce myself to, err, myself.
// I.e., always update the recipient player data even if it's nodraw (first person mode)
if ( pInfo->m_pClientEnt == edict() )
{
return FL_EDICT_ALWAYS;
}
// when HLTV/Replay is connected and spectators press +USE, they
// signal that they are recording a interesting scene
// so transmit these 'cameramans' to the HLTV or Replay client
if ( HLTVDirector()->GetCameraMan() == entindex() )
{
CBaseEntity *pRecipientEntity = CBaseEntity::Instance( pInfo->m_pClientEnt );
Assert( pRecipientEntity->IsPlayer() );
CBasePlayer *pRecipientPlayer = static_cast<CBasePlayer*>( pRecipientEntity );
if ( pRecipientPlayer->IsHLTV() ||
pRecipientPlayer->IsReplay() )
{
// HACK force calling RecomputePVSInformation to update PVS data
NetworkProp()->AreaNum();
return FL_EDICT_ALWAYS;
}
}
// Transmit for a short time after death and our death anim finishes so ragdolls can access reliable player data.
// Note that if m_flDeathAnimTime is never set, as long as m_lifeState is set to LIFE_DEAD after dying, this
// test will act as if the death anim is finished.
if ( IsEffectActive( EF_NODRAW ) || ( IsObserver() && ( gpGlobals->curtime - m_flDeathTime > 0.5 ) &&
( m_lifeState == LIFE_DEAD ) && ( gpGlobals->curtime - m_flDeathAnimTime > 0.5 ) ) )
{
return FL_EDICT_DONTSEND;
}
return BaseClass::ShouldTransmit( pInfo );
}
bool CBasePlayer::WantsLagCompensationOnEntity( const CBasePlayer *pPlayer, const CUserCmd *pCmd, const CBitVec<MAX_EDICTS> *pEntityTransmitBits ) const
{
// Team members shouldn't be adjusted unless friendly fire is on.
if ( !friendlyfire.GetInt() && pPlayer->GetTeamNumber() == GetTeamNumber() )
return false;
// If this entity hasn't been transmitted to us and acked, then don't bother lag compensating it.
if ( pEntityTransmitBits && !pEntityTransmitBits->Get( pPlayer->entindex() ) )
return false;
const Vector &vMyOrigin = GetAbsOrigin();
const Vector &vHisOrigin = pPlayer->GetAbsOrigin();
// get max distance player could have moved within max lag compensation time,
// multiply by 1.5 to to avoid "dead zones" (sqrt(2) would be the exact value)
float maxDistance = 1.5 * pPlayer->MaxSpeed() * sv_maxunlag.GetFloat();
// If the player is within this distance, lag compensate them in case they're running past us.
if ( vHisOrigin.DistTo( vMyOrigin ) < maxDistance )
return true;
// If their origin is not within a 45 degree cone in front of us, no need to lag compensate.
Vector vForward;
AngleVectors( pCmd->viewangles, &vForward );
Vector vDiff = vHisOrigin - vMyOrigin;
VectorNormalize( vDiff );
float flCosAngle = 0.707107f; // 45 degree angle
if ( vForward.Dot( vDiff ) < flCosAngle )
return false;
return true;
}
void CBasePlayer::PauseBonusProgress( bool bPause )
{
m_bPauseBonusProgress = bPause;
}
void CBasePlayer::SetBonusProgress( int iBonusProgress )
{
if ( !m_bPauseBonusProgress )
m_iBonusProgress = iBonusProgress;
}
void CBasePlayer::SetBonusChallenge( int iBonusChallenge )
{
m_iBonusChallenge = iBonusChallenge;
}
//-----------------------------------------------------------------------------
// Sets the view angles
//-----------------------------------------------------------------------------
void CBasePlayer::SnapEyeAngles( const QAngle &viewAngles )
{
pl.v_angle.GetForModify() = viewAngles;
pl.fixangle = FIXANGLE_ABSOLUTE;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : iSpeed -
// iMax -
// Output : int
//-----------------------------------------------------------------------------
int TrainSpeed(int iSpeed, int iMax)
{
float fSpeed, fMax;
int iRet = 0;
fMax = (float)iMax;
fSpeed = iSpeed;
fSpeed = fSpeed/fMax;
if (iSpeed < 0)
iRet = TRAIN_BACK;
else if (iSpeed == 0)
iRet = TRAIN_NEUTRAL;
else if (fSpeed < 0.33)
iRet = TRAIN_SLOW;
else if (fSpeed < 0.66)
iRet = TRAIN_MEDIUM;
else
iRet = TRAIN_FAST;
return iRet;
}
void CBasePlayer::DeathSound( const CTakeDamageInfo &info )
{
// temporarily using pain sounds for death sounds
// Did we die from falling?
if ( m_bitsDamageType & DMG_FALL )
{
// They died in the fall. Play a splat sound.
EmitSound( "Player.FallGib" );
}
else
{
EmitSound( "Player.Death" );
}
// play one of the suit death alarms
if ( IsSuitEquipped() )
{
UTIL_EmitGroupnameSuit(edict(), "HEV_DEAD");
}
}
// override takehealth
// bitsDamageType indicates type of damage healed.
int CBasePlayer::TakeHealth( float flHealth, int bitsDamageType )
{
// clear out any damage types we healed.
// UNDONE: generic health should not heal any
// UNDONE: time-based damage
if (m_takedamage)
{
int bitsDmgTimeBased = g_pGameRules->Damage_GetTimeBased();
m_bitsDamageType &= ~( bitsDamageType & ~bitsDmgTimeBased );
}
// I disabled reporting history into the dbghist because it was super spammy.
// But, if you need to reenable it, the code is below in the "else" clause.
#if 1 // #ifdef DISABLE_DEBUG_HISTORY
return BaseClass::TakeHealth (flHealth, bitsDamageType);
#else
const int healingTaken = BaseClass::TakeHealth(flHealth,bitsDamageType);
char buf[256];
Q_snprintf(buf, 256, "[%f] Player %s healed for %d with damagetype %X\n", gpGlobals->curtime, GetDebugName(), healingTaken, bitsDamageType);
ADD_DEBUG_HISTORY( HISTORY_PLAYER_DAMAGE, buf );
return healingTaken;
#endif
}
//-----------------------------------------------------------------------------
// Purpose: Draw all overlays (should be implemented in cascade by subclass to add
// any additional non-text overlays)
// Input :
// Output : Current text offset from the top
//-----------------------------------------------------------------------------
void CBasePlayer::DrawDebugGeometryOverlays(void)
{
// --------------------------------------------------------
// If in buddha mode and dead draw lines to indicate death
// --------------------------------------------------------
if ((m_debugOverlays & OVERLAY_BUDDHA_MODE) && m_iHealth == 1)
{
Vector vBodyDir = BodyDirection2D( );
Vector eyePos = EyePosition() + vBodyDir*10.0;
Vector vUp = Vector(0,0,8);
Vector vSide;
CrossProduct( vBodyDir, vUp, vSide);
NDebugOverlay::Line(eyePos+vSide+vUp, eyePos-vSide-vUp, 255,0,0, false, 0);
NDebugOverlay::Line(eyePos+vSide-vUp, eyePos-vSide+vUp, 255,0,0, false, 0);
}
BaseClass::DrawDebugGeometryOverlays();
}
//=========================================================
// TraceAttack
//=========================================================
void CBasePlayer::TraceAttack( const CTakeDamageInfo &inputInfo, const Vector &vecDir, trace_t *ptr, CDmgAccumulator *pAccumulator )
{
if ( m_takedamage )
{
CTakeDamageInfo info = inputInfo;
if ( info.GetAttacker() )
{
// --------------------------------------------------
// If an NPC check if friendly fire is disallowed
// --------------------------------------------------
CAI_BaseNPC *pNPC = info.GetAttacker()->MyNPCPointer();
if ( pNPC && (pNPC->CapabilitiesGet() & bits_CAP_NO_HIT_PLAYER) && pNPC->IRelationType( this ) != D_HT )
return;
// Prevent team damage here so blood doesn't appear
if ( info.GetAttacker()->IsPlayer() )
{
if ( !g_pGameRules->FPlayerCanTakeDamage( this, info.GetAttacker(), info ) )
return;
}
}
SetLastHitGroup( ptr->hitgroup );
switch ( ptr->hitgroup )
{
case HITGROUP_GENERIC:
break;
case HITGROUP_HEAD:
info.ScaleDamage( sk_player_head.GetFloat() );
break;
case HITGROUP_CHEST:
info.ScaleDamage( sk_player_chest.GetFloat() );
break;
case HITGROUP_STOMACH:
info.ScaleDamage( sk_player_stomach.GetFloat() );
break;
case HITGROUP_LEFTARM:
case HITGROUP_RIGHTARM:
info.ScaleDamage( sk_player_arm.GetFloat() );
break;
case HITGROUP_LEFTLEG:
case HITGROUP_RIGHTLEG:
info.ScaleDamage( sk_player_leg.GetFloat() );
break;
default:
break;
}
#ifdef HL2_EPISODIC
// If this damage type makes us bleed, then do so
bool bShouldBleed = !g_pGameRules->Damage_ShouldNotBleed( info.GetDamageType() );
if ( bShouldBleed )
#endif
{
SpawnBlood(ptr->endpos, vecDir, BloodColor(), info.GetDamage());// a little surface blood.
TraceBleed( info.GetDamage(), vecDir, ptr, info.GetDamageType() );
}
AddMultiDamage( info, this );
}
}
//------------------------------------------------------------------------------
// Purpose : Do some kind of damage effect for the type of damage
// Input :
// Output :
//------------------------------------------------------------------------------
void CBasePlayer::DamageEffect(float flDamage, int fDamageType)
{
if (fDamageType & DMG_CRUSH)
{
//Red damage indicator
color32 red = {128,0,0,128};
UTIL_ScreenFade( this, red, 1.0f, 0.1f, FFADE_IN );
}
else if (fDamageType & DMG_DROWN)
{
//Blue damage indicator
color32 blue = {0,0,128,128};
UTIL_ScreenFade( this, blue, 1.0f, 0.1f, FFADE_IN );
}
else if (fDamageType & DMG_SLASH)
{
// If slash damage shoot some blood
SpawnBlood(EyePosition(), g_vecAttackDir, BloodColor(), flDamage);
}
else if (fDamageType & DMG_PLASMA)
{
// Blue screen fade
color32 blue = {0,0,255,100};
UTIL_ScreenFade( this, blue, 0.2, 0.4, FFADE_MODULATE );
// Very small screen shake
// Both -0.1 and 0.1 map to 0 when converted to integer, so all of these RandomInt
// calls are just expensive ways of returning zero. This code has always been this
// way and has never had any value. clang complains about the conversion from a
// literal floating-point number to an integer.