forked from sears2424/Source-PlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc_baseplayer.cpp
3036 lines (2491 loc) · 91.6 KB
/
c_baseplayer.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: Client-side CBasePlayer.
//
// - Manages the player's flashlight effect.
//
//===========================================================================//
#include "cbase.h"
#include "c_baseplayer.h"
#include "flashlighteffect.h"
#include "weapon_selection.h"
#include "history_resource.h"
#include "iinput.h"
#include "input.h"
#include "view.h"
#include "iviewrender.h"
#include "iclientmode.h"
#include "in_buttons.h"
#include "engine/IEngineSound.h"
#include "c_soundscape.h"
#include "usercmd.h"
#include "c_playerresource.h"
#include "iclientvehicle.h"
#include "view_shared.h"
#include "movevars_shared.h"
#include "prediction.h"
#include "tier0/vprof.h"
#include "filesystem.h"
#include "bitbuf.h"
#include "KeyValues.h"
#include "particles_simple.h"
#include "fx_water.h"
#include "hltvcamera.h"
#include "toolframework/itoolframework.h"
#include "toolframework_client.h"
#include "view_scene.h"
#include "c_vguiscreen.h"
#include "datacache/imdlcache.h"
#include "vgui/ISurface.h"
#include "voice_status.h"
#include "fx.h"
#include "dt_utlvector_recv.h"
#include "cam_thirdperson.h"
#if defined( REPLAY_ENABLED )
#include "replay/replaycamera.h"
#include "replay/ireplaysystem.h"
#include "replay/ienginereplay.h"
#endif
#include "steam/steam_api.h"
#include "sourcevr/isourcevirtualreality.h"
#include "client_virtualreality.h"
#if defined USES_ECON_ITEMS
#include "econ_wearable.h"
#endif
// NVNT haptics system interface
#include "haptics/ihaptics.h"
#ifdef DEFERRED
#include "deferred/deferred_shared_common.h"
#endif
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
// Don't alias here
#if defined( CBasePlayer )
#undef CBasePlayer
#endif
int g_nKillCamMode = OBS_MODE_NONE;
int g_nKillCamTarget1 = 0;
int g_nKillCamTarget2 = 0;
extern ConVar mp_forcecamera; // in gamevars_shared.h
#define FLASHLIGHT_DISTANCE 1000
#define MAX_VGUI_INPUT_MODE_SPEED 30
#define MAX_VGUI_INPUT_MODE_SPEED_SQ (MAX_VGUI_INPUT_MODE_SPEED*MAX_VGUI_INPUT_MODE_SPEED)
static Vector WALL_MIN(-WALL_OFFSET,-WALL_OFFSET,-WALL_OFFSET);
static Vector WALL_MAX(WALL_OFFSET,WALL_OFFSET,WALL_OFFSET);
bool CommentaryModeShouldSwallowInput( C_BasePlayer *pPlayer );
extern ConVar default_fov;
#ifndef _XBOX
extern ConVar sensitivity;
#endif
static C_BasePlayer *s_pLocalPlayer = NULL;
static ConVar cl_customsounds ( "cl_customsounds", "0", 0, "Enable customized player sound playback" );
static ConVar spec_track ( "spec_track", "0", 0, "Tracks an entity in spec mode" );
static ConVar cl_smooth ( "cl_smooth", "1", 0, "Smooth view/eye origin after prediction errors" );
static ConVar cl_smoothtime (
"cl_smoothtime",
"0.1",
0,
"Smooth client's view after prediction error over this many seconds",
true, 0.01, // min/max is 0.01/2.0
true, 2.0
);
#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 );
ConVar spec_freeze_distance_min( "spec_freeze_distance_min", "80", FCVAR_CHEAT, "Minimum random distance from the target to stop when framing them in observer freeze cam." );
ConVar spec_freeze_distance_max( "spec_freeze_distance_max", "90", FCVAR_CHEAT, "Maximum random distance from the target to stop when framing them in observer freeze cam." );
#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 );
ConVar spec_freeze_distance_min( "spec_freeze_distance_min", "96", FCVAR_CHEAT, "Minimum random distance from the target to stop when framing them in observer freeze cam." );
ConVar spec_freeze_distance_max( "spec_freeze_distance_max", "200", FCVAR_CHEAT, "Maximum random distance from the target to stop when framing them in observer freeze cam." );
#endif
static ConVar cl_first_person_uses_world_model ( "cl_first_person_uses_world_model", "0", FCVAR_ARCHIVE, "Causes the third person model to be drawn instead of the view model" );
ConVar demo_fov_override( "demo_fov_override", "0", FCVAR_CLIENTDLL | FCVAR_DONTRECORD, "If nonzero, this value will be used to override FOV during demo playback." );
// This only needs to be approximate - it just controls the distance to the pivot-point of the head ("the neck") of the in-game character, not the player's real-world neck length.
// Ideally we would find this vector by subtracting the neutral-pose difference between the head bone (the pivot point) and the "eyes" attachment point.
// However, some characters don't have this attachment point, and finding the neutral pose is a pain.
// This value is found by hand, and a good value depends more on the in-game models than on actual human shapes.
ConVar cl_meathook_neck_pivot_ingame_up( "cl_meathook_neck_pivot_ingame_up", "7.0" );
ConVar cl_meathook_neck_pivot_ingame_fwd( "cl_meathook_neck_pivot_ingame_fwd", "3.0" );
static ConVar cl_clean_textures_on_death( "cl_clean_textures_on_death", "0", FCVAR_DEVELOPMENTONLY, "If enabled, attempts to purge unused textures every time a freeze cam is shown" );
void RecvProxy_LocalVelocityX( const CRecvProxyData *pData, void *pStruct, void *pOut );
void RecvProxy_LocalVelocityY( const CRecvProxyData *pData, void *pStruct, void *pOut );
void RecvProxy_LocalVelocityZ( const CRecvProxyData *pData, void *pStruct, void *pOut );
void RecvProxy_ObserverTarget( const CRecvProxyData *pData, void *pStruct, void *pOut );
void RecvProxy_ObserverMode ( const CRecvProxyData *pData, void *pStruct, void *pOut );
// -------------------------------------------------------------------------------- //
// RecvTable for CPlayerState.
// -------------------------------------------------------------------------------- //
BEGIN_RECV_TABLE_NOBASE(CPlayerState, DT_PlayerState)
RecvPropInt (RECVINFO(deadflag)),
END_RECV_TABLE()
BEGIN_RECV_TABLE_NOBASE( CPlayerLocalData, DT_Local )
RecvPropArray3( RECVINFO_ARRAY(m_chAreaBits), RecvPropInt(RECVINFO(m_chAreaBits[0]))),
RecvPropArray3( RECVINFO_ARRAY(m_chAreaPortalBits), RecvPropInt(RECVINFO(m_chAreaPortalBits[0]))),
RecvPropInt(RECVINFO(m_iHideHUD)),
// View
RecvPropFloat(RECVINFO(m_flFOVRate)),
RecvPropInt (RECVINFO(m_bDucked)),
RecvPropInt (RECVINFO(m_bDucking)),
RecvPropInt (RECVINFO(m_bInDuckJump)),
RecvPropFloat (RECVINFO(m_flDucktime)),
RecvPropFloat (RECVINFO(m_flDuckJumpTime)),
RecvPropFloat (RECVINFO(m_flJumpTime)),
RecvPropFloat (RECVINFO(m_flFallVelocity)),
#if PREDICTION_ERROR_CHECK_LEVEL > 1
RecvPropFloat (RECVINFO_NAME( m_vecPunchAngle.m_Value[0], m_vecPunchAngle[0])),
RecvPropFloat (RECVINFO_NAME( m_vecPunchAngle.m_Value[1], m_vecPunchAngle[1])),
RecvPropFloat (RECVINFO_NAME( m_vecPunchAngle.m_Value[2], m_vecPunchAngle[2] )),
RecvPropFloat (RECVINFO_NAME( m_vecPunchAngleVel.m_Value[0], m_vecPunchAngleVel[0] )),
RecvPropFloat (RECVINFO_NAME( m_vecPunchAngleVel.m_Value[1], m_vecPunchAngleVel[1] )),
RecvPropFloat (RECVINFO_NAME( m_vecPunchAngleVel.m_Value[2], m_vecPunchAngleVel[2] )),
#else
RecvPropVector (RECVINFO(m_vecPunchAngle)),
RecvPropVector (RECVINFO(m_vecPunchAngleVel)),
#endif
RecvPropInt (RECVINFO(m_bDrawViewmodel)),
RecvPropInt (RECVINFO(m_bWearingSuit)),
RecvPropBool (RECVINFO(m_bPoisoned)),
RecvPropFloat (RECVINFO(m_flStepSize)),
RecvPropInt (RECVINFO(m_bAllowAutoMovement)),
// 3d skybox data
RecvPropInt(RECVINFO(m_skybox3d.scale)),
RecvPropVector(RECVINFO(m_skybox3d.origin)),
RecvPropInt(RECVINFO(m_skybox3d.area)),
// 3d skybox fog data
RecvPropInt( RECVINFO( m_skybox3d.fog.enable ) ),
RecvPropInt( RECVINFO( m_skybox3d.fog.blend ) ),
RecvPropVector( RECVINFO( m_skybox3d.fog.dirPrimary ) ),
RecvPropInt( RECVINFO( m_skybox3d.fog.colorPrimary ) ),
RecvPropInt( RECVINFO( m_skybox3d.fog.colorSecondary ) ),
RecvPropFloat( RECVINFO( m_skybox3d.fog.start ) ),
RecvPropFloat( RECVINFO( m_skybox3d.fog.end ) ),
RecvPropFloat( RECVINFO( m_skybox3d.fog.maxdensity ) ),
// fog data
RecvPropEHandle( RECVINFO( m_PlayerFog.m_hCtrl ) ),
// audio data
RecvPropVector( RECVINFO( m_audio.localSound[0] ) ),
RecvPropVector( RECVINFO( m_audio.localSound[1] ) ),
RecvPropVector( RECVINFO( m_audio.localSound[2] ) ),
RecvPropVector( RECVINFO( m_audio.localSound[3] ) ),
RecvPropVector( RECVINFO( m_audio.localSound[4] ) ),
RecvPropVector( RECVINFO( m_audio.localSound[5] ) ),
RecvPropVector( RECVINFO( m_audio.localSound[6] ) ),
RecvPropVector( RECVINFO( m_audio.localSound[7] ) ),
RecvPropInt( RECVINFO( m_audio.soundscapeIndex ) ),
RecvPropInt( RECVINFO( m_audio.localBits ) ),
RecvPropEHandle( RECVINFO( m_audio.ent ) ),
END_RECV_TABLE()
// -------------------------------------------------------------------------------- //
// This data only gets sent to clients that ARE this player entity.
// -------------------------------------------------------------------------------- //
BEGIN_RECV_TABLE_NOBASE( C_BasePlayer, DT_LocalPlayerExclusive )
RecvPropDataTable ( RECVINFO_DT(m_Local),0, &REFERENCE_RECV_TABLE(DT_Local) ),
RecvPropFloat ( RECVINFO(m_vecViewOffset[0]) ),
RecvPropFloat ( RECVINFO(m_vecViewOffset[1]) ),
RecvPropFloat ( RECVINFO(m_vecViewOffset[2]) ),
RecvPropFloat ( RECVINFO(m_flFriction) ),
RecvPropArray3 ( RECVINFO_ARRAY(m_iAmmo), RecvPropInt( RECVINFO(m_iAmmo[0])) ),
RecvPropInt ( RECVINFO(m_fOnTarget) ),
RecvPropInt ( RECVINFO( m_nTickBase ) ),
RecvPropInt ( RECVINFO( m_nNextThinkTick ) ),
RecvPropEHandle ( RECVINFO( m_hLastWeapon ) ),
RecvPropEHandle ( RECVINFO( m_hGroundEntity ) ),
RecvPropFloat ( RECVINFO(m_vecVelocity[0]), 0, RecvProxy_LocalVelocityX ),
RecvPropFloat ( RECVINFO(m_vecVelocity[1]), 0, RecvProxy_LocalVelocityY ),
RecvPropFloat ( RECVINFO(m_vecVelocity[2]), 0, RecvProxy_LocalVelocityZ ),
RecvPropVector ( RECVINFO( m_vecBaseVelocity ) ),
RecvPropEHandle ( RECVINFO( m_hConstraintEntity)),
RecvPropVector ( RECVINFO( m_vecConstraintCenter) ),
RecvPropFloat ( RECVINFO( m_flConstraintRadius )),
RecvPropFloat ( RECVINFO( m_flConstraintWidth )),
RecvPropFloat ( RECVINFO( m_flConstraintSpeedFactor )),
RecvPropFloat ( RECVINFO( m_flDeathTime )),
RecvPropInt ( RECVINFO( m_nWaterLevel ) ),
RecvPropFloat ( RECVINFO( m_flLaggedMovementValue )),
END_RECV_TABLE()
// -------------------------------------------------------------------------------- //
// DT_BasePlayer datatable.
// -------------------------------------------------------------------------------- //
#if defined USES_ECON_ITEMS
EXTERN_RECV_TABLE(DT_AttributeList);
#endif
IMPLEMENT_CLIENTCLASS_DT(C_BasePlayer, DT_BasePlayer, CBasePlayer)
// We have both the local and nonlocal data in here, but the server proxies
// only send one.
RecvPropDataTable( "localdata", 0, 0, &REFERENCE_RECV_TABLE(DT_LocalPlayerExclusive) ),
#if defined USES_ECON_ITEMS
RecvPropDataTable(RECVINFO_DT(m_AttributeList),0, &REFERENCE_RECV_TABLE(DT_AttributeList) ),
#endif
RecvPropDataTable(RECVINFO_DT(pl), 0, &REFERENCE_RECV_TABLE(DT_PlayerState), DataTableRecvProxy_StaticDataTable),
RecvPropInt (RECVINFO(m_iFOV)),
RecvPropInt (RECVINFO(m_iFOVStart)),
RecvPropFloat (RECVINFO(m_flFOVTime)),
RecvPropInt (RECVINFO(m_iDefaultFOV)),
RecvPropEHandle (RECVINFO(m_hZoomOwner)),
RecvPropEHandle( RECVINFO(m_hVehicle) ),
RecvPropEHandle( RECVINFO(m_hUseEntity) ),
RecvPropInt (RECVINFO(m_iHealth)),
RecvPropInt (RECVINFO(m_lifeState)),
RecvPropInt (RECVINFO(m_iBonusProgress)),
RecvPropInt (RECVINFO(m_iBonusChallenge)),
RecvPropFloat (RECVINFO(m_flMaxspeed)),
RecvPropInt (RECVINFO(m_fFlags)),
RecvPropInt (RECVINFO(m_iObserverMode), 0, RecvProxy_ObserverMode ),
RecvPropEHandle (RECVINFO(m_hObserverTarget), RecvProxy_ObserverTarget ),
RecvPropArray ( RecvPropEHandle( RECVINFO( m_hViewModel[0] ) ), m_hViewModel ),
RecvPropString( RECVINFO(m_szLastPlaceName) ),
#if defined USES_ECON_ITEMS
RecvPropUtlVector( RECVINFO_UTLVECTOR( m_hMyWearables ), MAX_WEARABLES_SENT_FROM_SERVER, RecvPropEHandle(NULL, 0, 0) ),
#endif
END_RECV_TABLE()
BEGIN_PREDICTION_DATA_NO_BASE( CPlayerState )
DEFINE_PRED_FIELD( deadflag, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ),
// DEFINE_FIELD( netname, string_t ),
// DEFINE_FIELD( fixangle, FIELD_INTEGER ),
// DEFINE_FIELD( anglechange, FIELD_FLOAT ),
// DEFINE_FIELD( v_angle, FIELD_VECTOR ),
END_PREDICTION_DATA()
BEGIN_PREDICTION_DATA_NO_BASE( CPlayerLocalData )
// DEFINE_PRED_TYPEDESCRIPTION( m_skybox3d, sky3dparams_t ),
// DEFINE_PRED_TYPEDESCRIPTION( m_fog, fogparams_t ),
// DEFINE_PRED_TYPEDESCRIPTION( m_audio, audioparams_t ),
DEFINE_FIELD( m_nStepside, FIELD_INTEGER ),
DEFINE_PRED_FIELD( m_iHideHUD, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ),
#if PREDICTION_ERROR_CHECK_LEVEL > 1
DEFINE_PRED_FIELD( m_vecPunchAngle, FIELD_VECTOR, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_vecPunchAngleVel, FIELD_VECTOR, FTYPEDESC_INSENDTABLE ),
#else
DEFINE_PRED_FIELD_TOL( m_vecPunchAngle, FIELD_VECTOR, FTYPEDESC_INSENDTABLE, 0.125f ),
DEFINE_PRED_FIELD_TOL( m_vecPunchAngleVel, FIELD_VECTOR, FTYPEDESC_INSENDTABLE, 0.125f ),
#endif
DEFINE_PRED_FIELD( m_bDrawViewmodel, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_bWearingSuit, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_bPoisoned, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_bAllowAutoMovement, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_bDucked, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_bDucking, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_bInDuckJump, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_flDucktime, FIELD_FLOAT, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_flDuckJumpTime, FIELD_FLOAT, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_flJumpTime, FIELD_FLOAT, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD_TOL( m_flFallVelocity, FIELD_FLOAT, FTYPEDESC_INSENDTABLE, 0.5f ),
// DEFINE_PRED_FIELD( m_nOldButtons, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ),
DEFINE_FIELD( m_nOldButtons, FIELD_INTEGER ),
DEFINE_PRED_FIELD( m_flStepSize, FIELD_FLOAT, FTYPEDESC_INSENDTABLE ),
DEFINE_FIELD( m_flFOVRate, FIELD_FLOAT ),
END_PREDICTION_DATA()
BEGIN_PREDICTION_DATA( C_BasePlayer )
DEFINE_PRED_TYPEDESCRIPTION( m_Local, CPlayerLocalData ),
DEFINE_PRED_TYPEDESCRIPTION( pl, CPlayerState ),
DEFINE_PRED_FIELD( m_iFOV, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_hZoomOwner, FIELD_EHANDLE, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_flFOVTime, FIELD_FLOAT, 0 ),
DEFINE_PRED_FIELD( m_iFOVStart, FIELD_INTEGER, 0 ),
DEFINE_PRED_FIELD( m_hVehicle, FIELD_EHANDLE, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD_TOL( m_flMaxspeed, FIELD_FLOAT, FTYPEDESC_INSENDTABLE, 0.5f ),
DEFINE_PRED_FIELD( m_iHealth, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_iBonusProgress, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_iBonusChallenge, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_fOnTarget, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_nNextThinkTick, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_lifeState, FIELD_CHARACTER, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_nWaterLevel, FIELD_CHARACTER, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD_TOL( m_vecBaseVelocity, FIELD_VECTOR, FTYPEDESC_INSENDTABLE, 0.05 ),
DEFINE_FIELD( m_nButtons, FIELD_INTEGER ),
DEFINE_FIELD( m_flWaterJumpTime, FIELD_FLOAT ),
DEFINE_FIELD( m_nImpulse, FIELD_INTEGER ),
DEFINE_FIELD( m_flStepSoundTime, FIELD_FLOAT ),
DEFINE_FIELD( m_flSwimSoundTime, FIELD_FLOAT ),
DEFINE_FIELD( m_vecLadderNormal, FIELD_VECTOR ),
DEFINE_FIELD( m_flPhysics, FIELD_INTEGER ),
DEFINE_AUTO_ARRAY( m_szAnimExtension, FIELD_CHARACTER ),
DEFINE_FIELD( m_afButtonLast, FIELD_INTEGER ),
DEFINE_FIELD( m_afButtonPressed, FIELD_INTEGER ),
DEFINE_FIELD( m_afButtonReleased, FIELD_INTEGER ),
// DEFINE_FIELD( m_vecOldViewAngles, FIELD_VECTOR ),
// DEFINE_ARRAY( m_iOldAmmo, FIELD_INTEGER, MAX_AMMO_TYPES ),
//DEFINE_FIELD( m_hOldVehicle, FIELD_EHANDLE ),
// DEFINE_FIELD( m_pModelLight, dlight_t* ),
// DEFINE_FIELD( m_pEnvironmentLight, dlight_t* ),
// DEFINE_FIELD( m_pBrightLight, dlight_t* ),
DEFINE_PRED_FIELD( m_hLastWeapon, FIELD_EHANDLE, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_nTickBase, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_hGroundEntity, FIELD_EHANDLE, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_ARRAY( m_hViewModel, FIELD_EHANDLE, MAX_VIEWMODELS, FTYPEDESC_INSENDTABLE ),
DEFINE_FIELD( m_surfaceFriction, FIELD_FLOAT ),
END_PREDICTION_DATA()
LINK_ENTITY_TO_CLASS( player, C_BasePlayer );
// -------------------------------------------------------------------------------- //
// Functions.
// -------------------------------------------------------------------------------- //
C_BasePlayer::C_BasePlayer() : m_iv_vecViewOffset( "C_BasePlayer::m_iv_vecViewOffset" )
{
AddVar( &m_vecViewOffset, &m_iv_vecViewOffset, LATCH_SIMULATION_VAR );
#ifdef _DEBUG
m_vecLadderNormal.Init();
m_vecOldViewAngles.Init();
#endif
m_pFlashlight = NULL;
m_pCurrentVguiScreen = NULL;
m_pCurrentCommand = NULL;
m_flPredictionErrorTime = -100;
m_StuckLast = 0;
m_bWasFrozen = false;
m_bResampleWaterSurface = true;
ResetObserverMode();
m_vecPredictionError.Init();
m_flPredictionErrorTime = 0;
m_surfaceProps = 0;
m_pSurfaceData = NULL;
m_surfaceFriction = 1.0f;
m_chTextureType = 0;
m_flNextAchievementAnnounceTime = 0;
m_bFiredWeapon = false;
m_nForceVisionFilterFlags = 0;
m_nLocalPlayerVisionFlags = 0;
ListenForGameEvent( "base_player_teleported" );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
C_BasePlayer::~C_BasePlayer()
{
DeactivateVguiScreen( m_pCurrentVguiScreen.Get() );
if ( this == s_pLocalPlayer )
{
s_pLocalPlayer = NULL;
}
delete m_pFlashlight;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_BasePlayer::Spawn( void )
{
// Clear all flags except for FL_FULLEDICT
ClearFlags();
AddFlag( FL_CLIENT );
int effects = GetEffects() & EF_NOSHADOW;
SetEffects( effects );
m_iFOV = 0; // init field of view.
SetModel( "models/player.mdl" );
Precache();
SetThink(NULL);
SharedSpawn();
m_bWasFreezeFraming = false;
m_bFiredWeapon = false;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool C_BasePlayer::AudioStateIsUnderwater( Vector vecMainViewOrigin )
{
if ( IsObserver() )
{
// Just check the view position
int cont = enginetrace->GetPointContents ( vecMainViewOrigin );
return (cont & MASK_WATER);
}
return ( GetWaterLevel() >= WL_Eyes );
}
bool C_BasePlayer::IsHLTV() const
{
return ( IsLocalPlayer() && engine->IsHLTV() );
}
bool C_BasePlayer::IsReplay() const
{
#if defined( REPLAY_ENABLED )
return ( IsLocalPlayer() && g_pEngineClientReplay->IsPlayingReplayDemo() );
#else
return false;
#endif
}
CBaseEntity *C_BasePlayer::GetObserverTarget() const // returns players target or NULL
{
#ifndef _XBOX
if ( IsHLTV() )
{
return HLTVCamera()->GetPrimaryTarget();
}
#if defined( REPLAY_ENABLED )
if ( IsReplay() )
{
return ReplayCamera()->GetPrimaryTarget();
}
#endif
#endif
if ( GetObserverMode() == OBS_MODE_ROAMING )
{
return NULL; // no target in roaming mode
}
else
{
if ( IsLocalPlayer() && UseVR() )
{
// In VR mode, certain views cause disorientation and nausea. So let's not.
switch ( m_iObserverMode )
{
case OBS_MODE_NONE: // not in spectator mode
case OBS_MODE_FIXED: // view from a fixed camera position
case OBS_MODE_IN_EYE: // follow a player in first person view
case OBS_MODE_CHASE: // follow a player in third person view
case OBS_MODE_POI: // PASSTIME point of interest - game objective, big fight, anything interesting
case OBS_MODE_ROAMING: // free roaming
return m_hObserverTarget;
break;
case OBS_MODE_DEATHCAM: // special mode for death cam animation
case OBS_MODE_FREEZECAM: // zooms to a target, and freeze-frames on them
// These are both terrible - they get overriden to chase, but here we change it to "chase" your own body (which will be ragdolled).
return (const_cast<C_BasePlayer*>(this))->GetBaseEntity();
break;
default:
assert ( false );
break;
}
}
return m_hObserverTarget;
}
}
// Called from Recv Proxy, mainly to reset tone map scale
void C_BasePlayer::SetObserverTarget( EHANDLE hObserverTarget )
{
// If the observer target is changing to an entity that the client doesn't know about yet,
// it can resolve to NULL. If the client didn't have an observer target before, then
// comparing EHANDLEs directly will see them as equal, since it uses Get(), and compares
// NULL to NULL. To combat this, we need to check against GetEntryIndex() and
// GetSerialNumber().
if ( hObserverTarget.GetEntryIndex() != m_hObserverTarget.GetEntryIndex() ||
hObserverTarget.GetSerialNumber() != m_hObserverTarget.GetSerialNumber())
{
// Init based on the new handle's entry index and serial number, so that it's Get()
// has a chance to become non-NULL even if it currently resolves to NULL.
m_hObserverTarget.Init( hObserverTarget.GetEntryIndex(), hObserverTarget.GetSerialNumber() );
IGameEvent *event = gameeventmanager->CreateEvent( "spec_target_updated" );
if ( event )
{
gameeventmanager->FireEventClientSide( event );
}
if ( IsLocalPlayer() )
{
ResetToneMapping(1.0);
}
// NVNT notify haptics of changed player
if ( haptics )
haptics->OnPlayerChanged();
if ( IsLocalPlayer() )
{
// On a change of viewing mode or target, we may want to reset both head and torso to point at the new target.
g_ClientVirtualReality.AlignTorsoAndViewToWeapon();
}
}
}
void C_BasePlayer::SetObserverMode ( int iNewMode )
{
if ( m_iObserverMode != iNewMode )
{
m_iObserverMode = iNewMode;
if ( IsLocalPlayer() )
{
// On a change of viewing mode or target, we may want to reset both head and torso to point at the new target.
g_ClientVirtualReality.AlignTorsoAndViewToWeapon();
}
}
}
int C_BasePlayer::GetObserverMode() const
{
#ifndef _XBOX
if ( IsHLTV() )
{
return HLTVCamera()->GetMode();
}
#if defined( REPLAY_ENABLED )
if ( IsReplay() )
{
return ReplayCamera()->GetMode();
}
#endif
#endif
if ( IsLocalPlayer() && UseVR() )
{
// IN VR mode, certain views cause disorientation and nausea. So let's not.
switch ( m_iObserverMode )
{
case OBS_MODE_NONE: // not in spectator mode
case OBS_MODE_FIXED: // view from a fixed camera position
case OBS_MODE_IN_EYE: // follow a player in first person view
case OBS_MODE_CHASE: // follow a player in third person view
case OBS_MODE_POI: // PASSTIME point of interest - game objective, big fight, anything interesting
case OBS_MODE_ROAMING: // free roaming
return m_iObserverMode;
break;
case OBS_MODE_DEATHCAM: // special mode for death cam animation
case OBS_MODE_FREEZECAM: // zooms to a target, and freeze-frames on them
// These are both terrible - just do chase of your ragdoll.
return OBS_MODE_CHASE;
break;
default:
assert ( false );
break;
}
}
return m_iObserverMode;
}
bool C_BasePlayer::ViewModel_IsTransparent( void )
{
return IsTransparent();
}
bool C_BasePlayer::ViewModel_IsUsingFBTexture( void )
{
return UsesPowerOfTwoFrameBufferTexture();
}
//-----------------------------------------------------------------------------
// Used by prediction, sets the view angles for the player
//-----------------------------------------------------------------------------
void C_BasePlayer::SetLocalViewAngles( const QAngle &viewAngles )
{
pl.v_angle = viewAngles;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : ang -
//-----------------------------------------------------------------------------
void C_BasePlayer::SetViewAngles( const QAngle& ang )
{
SetLocalAngles( ang );
SetNetworkAngles( ang );
}
surfacedata_t* C_BasePlayer::GetGroundSurface()
{
//
// Find the name of the material that lies beneath the player.
//
Vector start, end;
VectorCopy( GetAbsOrigin(), start );
VectorCopy( start, end );
// Straight down
end.z -= 64;
// Fill in default values, just in case.
Ray_t ray;
ray.Init( start, end, GetPlayerMins(), GetPlayerMaxs() );
trace_t trace;
UTIL_TraceRay( ray, MASK_PLAYERSOLID_BRUSHONLY, this, COLLISION_GROUP_PLAYER_MOVEMENT, &trace );
if ( trace.fraction == 1.0f )
return NULL; // no ground
return physprops->GetSurfaceData( trace.surface.surfaceProps );
}
void C_BasePlayer::FireGameEvent( IGameEvent *event )
{
if ( FStrEq( event->GetName(), "base_player_teleported" ) )
{
const int index = event->GetInt( "entindex" );
if ( index == entindex() && IsLocalPlayer() )
{
// In VR, we want to make sure our head and body
// are aligned after we teleport.
g_ClientVirtualReality.AlignTorsoAndViewToWeapon();
}
}
}
//-----------------------------------------------------------------------------
// returns the player name
//-----------------------------------------------------------------------------
const char * C_BasePlayer::GetPlayerName()
{
return g_PR ? g_PR->GetPlayerName( entindex() ) : "";
}
//-----------------------------------------------------------------------------
// Is the player dead?
//-----------------------------------------------------------------------------
bool C_BasePlayer::IsPlayerDead()
{
return pl.deadflag == true;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_BasePlayer::SetVehicleRole( int nRole )
{
if ( !IsInAVehicle() )
return;
// HL2 has only a player in a vehicle.
if ( nRole > VEHICLE_ROLE_DRIVER )
return;
char szCmd[64];
Q_snprintf( szCmd, sizeof( szCmd ), "vehicleRole %i\n", nRole );
engine->ServerCmd( szCmd );
}
//-----------------------------------------------------------------------------
// Purpose: Store original ammo data to see what has changed
// Input : bnewentity -
//-----------------------------------------------------------------------------
void C_BasePlayer::OnPreDataChanged( DataUpdateType_t updateType )
{
for (int i = 0; i < MAX_AMMO_TYPES; ++i)
{
m_iOldAmmo[i] = GetAmmoCount(i);
}
m_bWasFreezeFraming = (GetObserverMode() == OBS_MODE_FREEZECAM);
m_hOldFogController = m_Local.m_PlayerFog.m_hCtrl;
BaseClass::OnPreDataChanged( updateType );
}
void C_BasePlayer::PreDataUpdate( DataUpdateType_t updateType )
{
BaseClass::PreDataUpdate( updateType );
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : updateType -
//-----------------------------------------------------------------------------
void C_BasePlayer::PostDataUpdate( DataUpdateType_t updateType )
{
// This has to occur here as opposed to OnDataChanged so that EHandles to the player created
// on this same frame are not stomped because prediction thinks there
// isn't a local player yet!!!
if ( updateType == DATA_UPDATE_CREATED )
{
// Make sure s_pLocalPlayer is correct
int iLocalPlayerIndex = engine->GetLocalPlayer();
if ( g_nKillCamMode )
iLocalPlayerIndex = g_nKillCamTarget1;
if ( iLocalPlayerIndex == index )
{
Assert( s_pLocalPlayer == NULL );
s_pLocalPlayer = this;
// Reset our sound mixed in case we were in a freeze cam when we
// changed level, which would cause the snd_soundmixer to be left modified.
ConVar *pVar = (ConVar *)cvar->FindVar( "snd_soundmixer" );
pVar->Revert();
}
}
bool bForceEFNoInterp = IsNoInterpolationFrame();
if ( IsLocalPlayer() )
{
SetSimulatedEveryTick( true );
}
else
{
SetSimulatedEveryTick( false );
// estimate velocity for non local players
float flTimeDelta = m_flSimulationTime - m_flOldSimulationTime;
if ( flTimeDelta > 0 && !( IsNoInterpolationFrame() || bForceEFNoInterp ) )
{
Vector newVelo = (GetNetworkOrigin() - GetOldOrigin() ) / flTimeDelta;
SetAbsVelocity( newVelo);
}
}
BaseClass::PostDataUpdate( updateType );
// Only care about this for local player
if ( IsLocalPlayer() )
{
QAngle angles;
engine->GetViewAngles( angles );
if ( updateType == DATA_UPDATE_CREATED )
{
SetLocalViewAngles( angles );
m_flOldPlayerZ = GetLocalOrigin().z;
// NVNT the local player has just been created.
// set in the "on_foot" navigation.
if ( haptics )
{
haptics->LocalPlayerReset();
haptics->SetNavigationClass("on_foot");
haptics->ProcessHapticEvent(2,"Movement","BasePlayer");
}
}
SetLocalAngles( angles );
if ( !m_bWasFreezeFraming && GetObserverMode() == OBS_MODE_FREEZECAM )
{
m_vecFreezeFrameStart = MainViewOrigin();
m_flFreezeFrameStartTime = gpGlobals->curtime;
m_flFreezeFrameDistance = RandomFloat( spec_freeze_distance_min.GetFloat(), spec_freeze_distance_max.GetFloat() );
m_flFreezeZOffset = RandomFloat( -30, 20 );
m_bSentFreezeFrame = false;
m_nForceVisionFilterFlags = 0;
C_BaseEntity *target = GetObserverTarget();
if ( target && target->IsPlayer() )
{
C_BasePlayer *player = ToBasePlayer( target );
if ( player )
{
m_nForceVisionFilterFlags = player->GetVisionFilterFlags();
CalculateVisionUsingCurrentFlags();
}
}
IGameEvent *pEvent = gameeventmanager->CreateEvent( "show_freezepanel" );
if ( pEvent )
{
pEvent->SetInt( "killer", target ? target->entindex() : 0 );
gameeventmanager->FireEventClientSide( pEvent );
}
// Force the sound mixer to the freezecam mixer
ConVar *pVar = (ConVar *)cvar->FindVar( "snd_soundmixer" );
pVar->SetValue( "FreezeCam_Only" );
// When we start, give unused textures an opportunity to unload
if ( cl_clean_textures_on_death.GetBool() )
g_pMaterialSystem->UncacheUnusedMaterials( false );
}
else if ( m_bWasFreezeFraming && GetObserverMode() != OBS_MODE_FREEZECAM )
{
IGameEvent *pEvent = gameeventmanager->CreateEvent( "hide_freezepanel" );
if ( pEvent )
{
gameeventmanager->FireEventClientSide( pEvent );
}
view->FreezeFrame(0);
ConVar *pVar = (ConVar *)cvar->FindVar( "snd_soundmixer" );
pVar->Revert();
m_nForceVisionFilterFlags = 0;
CalculateVisionUsingCurrentFlags();
}
// force calculate vision when the local vision flags changed
int nCurrentLocalPlayerVisionFlags = GetLocalPlayerVisionFilterFlags();
if ( m_nLocalPlayerVisionFlags != nCurrentLocalPlayerVisionFlags )
{
CalculateVisionUsingCurrentFlags();
m_nLocalPlayerVisionFlags = nCurrentLocalPlayerVisionFlags;
}
}
// If we are updated while paused, allow the player origin to be snapped by the
// server if we receive a packet from the server
if ( engine->IsPaused() || bForceEFNoInterp )
{
ResetLatched();
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool C_BasePlayer::CanSetSoundMixer( void )
{
// Can't set sound mixers when we're in freezecam mode, since it has a code-enforced mixer
return (GetObserverMode() != OBS_MODE_FREEZECAM);
}
void C_BasePlayer::ReceiveMessage( int classID, bf_read &msg )
{
if ( classID != GetClientClass()->m_ClassID )
{
// message is for subclass
BaseClass::ReceiveMessage( classID, msg );
return;
}
int messageType = msg.ReadByte();
switch( messageType )
{
case PLAY_PLAYER_JINGLE:
PlayPlayerJingle();
break;
}
}
void C_BasePlayer::OnRestore()
{
BaseClass::OnRestore();
if ( IsLocalPlayer() )
{
// debounce the attack key, for if it was used for restore
input->ClearInputButton( IN_ATTACK | IN_ATTACK2 );
// GetButtonBits() has to be called for the above to take effect
input->GetButtonBits( 0 );
}
// For ammo history icons to current value so they don't flash on level transtions
for ( int i = 0; i < MAX_AMMO_TYPES; i++ )
{
m_iOldAmmo[i] = GetAmmoCount(i);
}
}
//-----------------------------------------------------------------------------
// Purpose: Process incoming data
//-----------------------------------------------------------------------------
void C_BasePlayer::OnDataChanged( DataUpdateType_t updateType )
{
#if !defined( NO_ENTITY_PREDICTION )
if ( IsLocalPlayer() )
{
SetPredictionEligible( true );
}
#endif
BaseClass::OnDataChanged( updateType );
// Only care about this for local player
if ( IsLocalPlayer() )
{
// Reset engine areabits pointer
render->SetAreaState( m_Local.m_chAreaBits, m_Local.m_chAreaPortalBits );
// Check for Ammo pickups.
for ( int i = 0; i < MAX_AMMO_TYPES; i++ )