/
hl2_player.cpp
3930 lines (3258 loc) · 107 KB
/
hl2_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: Player for HL2.
//
//=============================================================================//
#include "cbase.h"
#include "hl2_player.h"
#include "globalstate.h"
#include "game.h"
#include "gamerules.h"
#include "trains.h"
#include "basehlcombatweapon_shared.h"
#include "vcollide_parse.h"
#include "in_buttons.h"
#include "ai_interactions.h"
#include "ai_squad.h"
#include "igamemovement.h"
#include "ai_hull.h"
#include "hl2_shareddefs.h"
#include "info_camera_link.h"
#include "point_camera.h"
#include "engine/IEngineSound.h"
#include "ndebugoverlay.h"
#include "iservervehicle.h"
#include "IVehicle.h"
#include "globals.h"
#include "collisionutils.h"
#include "coordsize.h"
#include "effect_color_tables.h"
#include "vphysics/player_controller.h"
#include "player_pickup.h"
#include "weapon_physcannon.h"
#include "script_intro.h"
#include "effect_dispatch_data.h"
#include "te_effect_dispatch.h"
#include "ai_basenpc.h"
#include "AI_Criteria.h"
#include "npc_barnacle.h"
#include "entitylist.h"
#include "env_zoom.h"
#include "hl2_gamerules.h"
#include "prop_combine_ball.h"
#include "datacache/imdlcache.h"
#include "eventqueue.h"
#include "gamestats.h"
#include "filters.h"
#include "tier0/icommandline.h"
#ifdef HL2_EPISODIC
#include "npc_alyx_episodic.h"
#endif
#ifdef PORTAL
#include "portal_player.h"
#endif // PORTAL
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
extern ConVar weapon_showproficiency;
extern ConVar autoaim_max_dist;
// Do not touch with without seeing me, please! (sjb)
// For consistency's sake, enemy gunfire is traced against a scaled down
// version of the player's hull, not the hitboxes for the player's model
// because the player isn't aware of his model, and can't do anything about
// preventing headshots and other such things. Also, game difficulty will
// not change if the model changes. This is the value by which to scale
// the X/Y of the player's hull to get the volume to trace bullets against.
#define PLAYER_HULL_REDUCTION 0.70
// This switches between the single primary weapon, and multiple weapons with buckets approach (jdw)
#define HL2_SINGLE_PRIMARY_WEAPON_MODE 0
#define TIME_IGNORE_FALL_DAMAGE 10.0
extern int gEvilImpulse101;
ConVar sv_autojump( "sv_autojump", "0" );
ConVar hl2_walkspeed( "hl2_walkspeed", "150" );
ConVar hl2_normspeed( "hl2_normspeed", "190" );
ConVar hl2_sprintspeed( "hl2_sprintspeed", "320" );
ConVar hl2_darkness_flashlight_factor ( "hl2_darkness_flashlight_factor", "1" );
#ifdef HL2MP
#define HL2_WALK_SPEED 150
#define HL2_NORM_SPEED 190
#define HL2_SPRINT_SPEED 320
#else
#define HL2_WALK_SPEED hl2_walkspeed.GetFloat()
#define HL2_NORM_SPEED hl2_normspeed.GetFloat()
#define HL2_SPRINT_SPEED hl2_sprintspeed.GetFloat()
#endif
ConVar player_showpredictedposition( "player_showpredictedposition", "0" );
ConVar player_showpredictedposition_timestep( "player_showpredictedposition_timestep", "1.0" );
ConVar player_squad_transient_commands( "player_squad_transient_commands", "1", FCVAR_REPLICATED );
ConVar player_squad_double_tap_time( "player_squad_double_tap_time", "0.25" );
ConVar sv_infinite_aux_power( "sv_infinite_aux_power", "0", FCVAR_CHEAT );
ConVar autoaim_unlock_target( "autoaim_unlock_target", "0.8666" );
ConVar sv_stickysprint("sv_stickysprint", "0", FCVAR_ARCHIVE | FCVAR_ARCHIVE_XBOX);
#define FLASH_DRAIN_TIME 1.1111 // 100 units / 90 secs
#define FLASH_CHARGE_TIME 50.0f // 100 units / 2 secs
//==============================================================================================
// CAPPED PLAYER PHYSICS DAMAGE TABLE
//==============================================================================================
static impactentry_t cappedPlayerLinearTable[] =
{
{ 150*150, 5 },
{ 250*250, 10 },
{ 450*450, 20 },
{ 550*550, 30 },
//{ 700*700, 100 },
//{ 1000*1000, 500 },
};
static impactentry_t cappedPlayerAngularTable[] =
{
{ 100*100, 10 },
{ 150*150, 20 },
{ 200*200, 30 },
//{ 300*300, 500 },
};
static impactdamagetable_t gCappedPlayerImpactDamageTable =
{
cappedPlayerLinearTable,
cappedPlayerAngularTable,
ARRAYSIZE(cappedPlayerLinearTable),
ARRAYSIZE(cappedPlayerAngularTable),
24*24.0f, // minimum linear speed
360*360.0f, // minimum angular speed
2.0f, // can't take damage from anything under 2kg
5.0f, // anything less than 5kg is "small"
5.0f, // never take more than 5 pts of damage from anything under 5kg
36*36.0f, // <5kg objects must go faster than 36 in/s to do damage
0.0f, // large mass in kg (no large mass effects)
1.0f, // large mass scale
2.0f, // large mass falling scale
320.0f, // min velocity for player speed to cause damage
};
// Flashlight utility
bool g_bCacheLegacyFlashlightStatus = true;
bool g_bUseLegacyFlashlight;
bool Flashlight_UseLegacyVersion( void )
{
// If this is the first run through, cache off what the answer should be (cannot change during a session)
if ( g_bCacheLegacyFlashlightStatus )
{
char modDir[MAX_PATH];
if ( UTIL_GetModDir( modDir, sizeof(modDir) ) == false )
return false;
g_bUseLegacyFlashlight = ( !Q_strcmp( modDir, "hl2" ) ||
!Q_strcmp( modDir, "episodic" ) ||
!Q_strcmp( modDir, "lostcoast" ) || !Q_strcmp( modDir, "hl1" ));
g_bCacheLegacyFlashlightStatus = false;
}
// Return the results
return g_bUseLegacyFlashlight;
}
//-----------------------------------------------------------------------------
// Purpose: Used to relay outputs/inputs from the player to the world and viceversa
//-----------------------------------------------------------------------------
class CLogicPlayerProxy : public CLogicalEntity
{
DECLARE_CLASS( CLogicPlayerProxy, CLogicalEntity );
private:
DECLARE_DATADESC();
public:
COutputEvent m_OnFlashlightOn;
COutputEvent m_OnFlashlightOff;
COutputEvent m_PlayerHasAmmo;
COutputEvent m_PlayerHasNoAmmo;
COutputEvent m_PlayerDied;
COutputEvent m_PlayerMissedAR2AltFire; // Player fired a combine ball which did not dissolve any enemies.
COutputInt m_RequestedPlayerHealth;
void InputRequestPlayerHealth( inputdata_t &inputdata );
void InputSetFlashlightSlowDrain( inputdata_t &inputdata );
void InputSetFlashlightNormalDrain( inputdata_t &inputdata );
void InputSetPlayerHealth( inputdata_t &inputdata );
void InputRequestAmmoState( inputdata_t &inputdata );
void InputLowerWeapon( inputdata_t &inputdata );
void InputEnableCappedPhysicsDamage( inputdata_t &inputdata );
void InputDisableCappedPhysicsDamage( inputdata_t &inputdata );
void InputSetLocatorTargetEntity( inputdata_t &inputdata );
#ifdef PORTAL
void InputSuppressCrosshair( inputdata_t &inputdata );
#endif // PORTAL2
void Activate ( void );
bool PassesDamageFilter( const CTakeDamageInfo &info );
EHANDLE m_hPlayer;
};
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void CC_ToggleZoom( void )
{
CBasePlayer* pPlayer = UTIL_GetCommandClient();
if( pPlayer )
{
CHL2_Player *pHL2Player = dynamic_cast<CHL2_Player*>(pPlayer);
if( pHL2Player && pHL2Player->IsSuitEquipped() )
{
pHL2Player->ToggleZoom();
}
}
}
static ConCommand toggle_zoom("toggle_zoom", CC_ToggleZoom, "Toggles zoom display" );
// ConVar cl_forwardspeed( "cl_forwardspeed", "400", FCVAR_CHEAT ); // Links us to the client's version
ConVar xc_crouch_range( "xc_crouch_range", "0.85", FCVAR_ARCHIVE, "Percentarge [1..0] of joystick range to allow ducking within" ); // Only 1/2 of the range is used
ConVar xc_use_crouch_limiter( "xc_use_crouch_limiter", "0", FCVAR_ARCHIVE, "Use the crouch limiting logic on the controller" );
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void CC_ToggleDuck( void )
{
CBasePlayer* pPlayer = UTIL_GetCommandClient();
if ( pPlayer == NULL )
return;
// Cannot be frozen
if ( pPlayer->GetFlags() & FL_FROZEN )
return;
static bool bChecked = false;
static ConVar *pCVcl_forwardspeed = NULL;
if ( !bChecked )
{
bChecked = true;
pCVcl_forwardspeed = ( ConVar * )cvar->FindVar( "cl_forwardspeed" );
}
// If we're not ducked, do extra checking
if ( xc_use_crouch_limiter.GetBool() )
{
if ( pPlayer->GetToggledDuckState() == false )
{
float flForwardSpeed = 400.0f;
if ( pCVcl_forwardspeed )
{
flForwardSpeed = pCVcl_forwardspeed->GetFloat();
}
flForwardSpeed = MAX( 1.0f, flForwardSpeed );
// Make sure we're not in the blindspot on the crouch detection
float flStickDistPerc = ( pPlayer->GetStickDist() / flForwardSpeed ); // Speed is the magnitude
if ( flStickDistPerc > xc_crouch_range.GetFloat() )
return;
}
}
// Toggle the duck
pPlayer->ToggleDuck();
}
static ConCommand toggle_duck("toggle_duck", CC_ToggleDuck, "Toggles duck" );
#ifndef HL2MP
#ifndef PORTAL
LINK_ENTITY_TO_CLASS( player, CHL2_Player );
#endif
#endif
PRECACHE_REGISTER(player);
CBaseEntity *FindEntityForward( CBasePlayer *pMe, bool fHull );
BEGIN_SIMPLE_DATADESC( LadderMove_t )
DEFINE_FIELD( m_bForceLadderMove, FIELD_BOOLEAN ),
DEFINE_FIELD( m_bForceMount, FIELD_BOOLEAN ),
DEFINE_FIELD( m_flStartTime, FIELD_TIME ),
DEFINE_FIELD( m_flArrivalTime, FIELD_TIME ),
DEFINE_FIELD( m_vecGoalPosition, FIELD_POSITION_VECTOR ),
DEFINE_FIELD( m_vecStartPosition, FIELD_POSITION_VECTOR ),
DEFINE_FIELD( m_hForceLadder, FIELD_EHANDLE ),
DEFINE_FIELD( m_hReservedSpot, FIELD_EHANDLE ),
END_DATADESC()
// Global Savedata for HL2 player
BEGIN_DATADESC( CHL2_Player )
DEFINE_FIELD( m_nControlClass, FIELD_INTEGER ),
DEFINE_EMBEDDED( m_HL2Local ),
DEFINE_FIELD( m_bSprintEnabled, FIELD_BOOLEAN ),
DEFINE_FIELD( m_flTimeAllSuitDevicesOff, FIELD_TIME ),
DEFINE_FIELD( m_fIsSprinting, FIELD_BOOLEAN ),
DEFINE_FIELD( m_fIsWalking, FIELD_BOOLEAN ),
/*
// These are initialized every time the player calls Activate()
DEFINE_FIELD( m_bIsAutoSprinting, FIELD_BOOLEAN ),
DEFINE_FIELD( m_fAutoSprintMinTime, FIELD_TIME ),
*/
// Field is used within a single tick, no need to save restore
// DEFINE_FIELD( m_bPlayUseDenySound, FIELD_BOOLEAN ),
// m_pPlayerAISquad reacquired on load
DEFINE_AUTO_ARRAY( m_vecMissPositions, FIELD_POSITION_VECTOR ),
DEFINE_FIELD( m_nNumMissPositions, FIELD_INTEGER ),
// m_pPlayerAISquad
DEFINE_EMBEDDED( m_CommanderUpdateTimer ),
// m_RealTimeLastSquadCommand
DEFINE_FIELD( m_QueuedCommand, FIELD_INTEGER ),
DEFINE_FIELD( m_flTimeIgnoreFallDamage, FIELD_TIME ),
DEFINE_FIELD( m_bIgnoreFallDamageResetAfterImpact, FIELD_BOOLEAN ),
// Suit power fields
DEFINE_FIELD( m_flSuitPowerLoad, FIELD_FLOAT ),
DEFINE_FIELD( m_flIdleTime, FIELD_TIME ),
DEFINE_FIELD( m_flMoveTime, FIELD_TIME ),
DEFINE_FIELD( m_flLastDamageTime, FIELD_TIME ),
DEFINE_FIELD( m_flTargetFindTime, FIELD_TIME ),
DEFINE_FIELD( m_flAdmireGlovesAnimTime, FIELD_TIME ),
DEFINE_FIELD( m_flNextFlashlightCheckTime, FIELD_TIME ),
DEFINE_FIELD( m_flFlashlightPowerDrainScale, FIELD_FLOAT ),
DEFINE_FIELD( m_bFlashlightDisabled, FIELD_BOOLEAN ),
DEFINE_FIELD( m_bUseCappedPhysicsDamageTable, FIELD_BOOLEAN ),
DEFINE_FIELD( m_hLockedAutoAimEntity, FIELD_EHANDLE ),
DEFINE_EMBEDDED( m_LowerWeaponTimer ),
DEFINE_EMBEDDED( m_AutoaimTimer ),
DEFINE_INPUTFUNC( FIELD_FLOAT, "IgnoreFallDamage", InputIgnoreFallDamage ),
DEFINE_INPUTFUNC( FIELD_FLOAT, "IgnoreFallDamageWithoutReset", InputIgnoreFallDamageWithoutReset ),
DEFINE_INPUTFUNC( FIELD_VOID, "OnSquadMemberKilled", OnSquadMemberKilled ),
DEFINE_INPUTFUNC( FIELD_VOID, "DisableFlashlight", InputDisableFlashlight ),
DEFINE_INPUTFUNC( FIELD_VOID, "EnableFlashlight", InputEnableFlashlight ),
DEFINE_INPUTFUNC( FIELD_VOID, "ForceDropPhysObjects", InputForceDropPhysObjects ),
DEFINE_SOUNDPATCH( m_sndLeeches ),
DEFINE_SOUNDPATCH( m_sndWaterSplashes ),
DEFINE_FIELD( m_flArmorReductionTime, FIELD_TIME ),
DEFINE_FIELD( m_iArmorReductionFrom, FIELD_INTEGER ),
DEFINE_FIELD( m_flTimeUseSuspended, FIELD_TIME ),
DEFINE_FIELD( m_hLocatorTargetEntity, FIELD_EHANDLE ),
DEFINE_FIELD( m_flTimeNextLadderHint, FIELD_TIME ),
//DEFINE_FIELD( m_hPlayerProxy, FIELD_EHANDLE ), //Shut up class check!
END_DATADESC()
CHL2_Player::CHL2_Player()
{
m_nNumMissPositions = 0;
m_pPlayerAISquad = 0;
m_bSprintEnabled = true;
m_flArmorReductionTime = 0.0f;
m_iArmorReductionFrom = 0;
}
//
// SUIT POWER DEVICES
//
#define SUITPOWER_CHARGE_RATE 12.5 // 100 units in 8 seconds
#ifdef HL2MP
CSuitPowerDevice SuitDeviceSprint( bits_SUIT_DEVICE_SPRINT, 25.0f ); // 100 units in 4 seconds
#else
CSuitPowerDevice SuitDeviceSprint( bits_SUIT_DEVICE_SPRINT, 12.5f ); // 100 units in 8 seconds
#endif
#ifdef HL2_EPISODIC
CSuitPowerDevice SuitDeviceFlashlight( bits_SUIT_DEVICE_FLASHLIGHT, 1.111 ); // 100 units in 90 second
#else
CSuitPowerDevice SuitDeviceFlashlight( bits_SUIT_DEVICE_FLASHLIGHT, 2.222 ); // 100 units in 45 second
#endif
CSuitPowerDevice SuitDeviceBreather( bits_SUIT_DEVICE_BREATHER, 6.7f ); // 100 units in 15 seconds (plus three padded seconds)
IMPLEMENT_SERVERCLASS_ST(CHL2_Player, DT_HL2_Player)
SendPropDataTable(SENDINFO_DT(m_HL2Local), &REFERENCE_SEND_TABLE(DT_HL2Local), SendProxy_SendLocalDataTable),
SendPropBool( SENDINFO(m_fIsSprinting) ),
END_SEND_TABLE()
void CHL2_Player::Precache( void )
{
BaseClass::Precache();
PrecacheScriptSound( "HL2Player.SprintNoPower" );
PrecacheScriptSound( "HL2Player.SprintStart" );
PrecacheScriptSound( "HL2Player.UseDeny" );
PrecacheScriptSound( "HL2Player.FlashLightOn" );
PrecacheScriptSound( "HL2Player.FlashLightOff" );
PrecacheScriptSound( "HL2Player.PickupWeapon" );
PrecacheScriptSound( "HL2Player.TrainUse" );
PrecacheScriptSound( "HL2Player.Use" );
PrecacheScriptSound( "HL2Player.BurnPain" );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHL2_Player::CheckSuitZoom( void )
{
//#ifndef _XBOX
//Adrian - No zooming without a suit!
if ( IsSuitEquipped() )
{
if ( m_afButtonReleased & IN_ZOOM )
{
StopZooming();
}
else if ( m_afButtonPressed & IN_ZOOM )
{
StartZooming();
}
}
//#endif//_XBOX
}
void CHL2_Player::EquipSuit( bool bPlayEffects )
{
MDLCACHE_CRITICAL_SECTION();
BaseClass::EquipSuit();
m_HL2Local.m_bDisplayReticle = true;
if ( bPlayEffects == true )
{
StartAdmireGlovesAnimation();
}
}
void CHL2_Player::RemoveSuit( void )
{
BaseClass::RemoveSuit();
m_HL2Local.m_bDisplayReticle = false;
}
void CHL2_Player::HandleSpeedChanges( void )
{
int buttonsChanged = m_afButtonPressed | m_afButtonReleased;
bool bCanSprint = CanSprint();
bool bIsSprinting = IsSprinting();
bool bWantSprint = ( bCanSprint && IsSuitEquipped() && (m_nButtons & IN_SPEED) );
if ( bIsSprinting != bWantSprint && (buttonsChanged & IN_SPEED) )
{
// If someone wants to sprint, make sure they've pressed the button to do so. We want to prevent the
// case where a player can hold down the sprint key and burn tiny bursts of sprint as the suit recharges
// We want a full debounce of the key to resume sprinting after the suit is completely drained
if ( bWantSprint )
{
if ( sv_stickysprint.GetBool() )
{
StartAutoSprint();
}
else
{
StartSprinting();
}
}
else
{
if ( !sv_stickysprint.GetBool() )
{
StopSprinting();
}
// Reset key, so it will be activated post whatever is suppressing it.
m_nButtons &= ~IN_SPEED;
}
}
bool bIsWalking = IsWalking();
// have suit, pressing button, not sprinting or ducking
bool bWantWalking;
if( IsSuitEquipped() )
{
bWantWalking = (m_nButtons & IN_WALK) && !IsSprinting() && !(m_nButtons & IN_DUCK);
}
else
{
bWantWalking = true;
}
if( bIsWalking != bWantWalking )
{
if ( bWantWalking )
{
StartWalking();
}
else
{
StopWalking();
}
}
}
//-----------------------------------------------------------------------------
// This happens when we powerdown from the mega physcannon to the regular one
//-----------------------------------------------------------------------------
void CHL2_Player::HandleArmorReduction( void )
{
if ( m_flArmorReductionTime < gpGlobals->curtime )
return;
if ( ArmorValue() <= 0 )
return;
float flPercent = 1.0f - (( m_flArmorReductionTime - gpGlobals->curtime ) / ARMOR_DECAY_TIME );
int iArmor = Lerp( flPercent, m_iArmorReductionFrom, 0 );
SetArmorValue( iArmor );
}
//-----------------------------------------------------------------------------
// Purpose: Allow pre-frame adjustments on the player
//-----------------------------------------------------------------------------
void CHL2_Player::PreThink(void)
{
if ( player_showpredictedposition.GetBool() )
{
Vector predPos;
UTIL_PredictedPosition( this, player_showpredictedposition_timestep.GetFloat(), &predPos );
NDebugOverlay::Box( predPos, NAI_Hull::Mins( GetHullType() ), NAI_Hull::Maxs( GetHullType() ), 0, 255, 0, 0, 0.01f );
NDebugOverlay::Line( GetAbsOrigin(), predPos, 0, 255, 0, 0, 0.01f );
}
#ifdef HL2_EPISODIC
if( m_hLocatorTargetEntity != NULL )
{
// Keep track of the entity here, the client will pick up the rest of the work
m_HL2Local.m_vecLocatorOrigin = m_hLocatorTargetEntity->WorldSpaceCenter();
}
else
{
m_HL2Local.m_vecLocatorOrigin = vec3_invalid; // This tells the client we have no locator target.
}
#endif//HL2_EPISODIC
// Riding a vehicle?
if ( IsInAVehicle() )
{
VPROF( "CHL2_Player::PreThink-Vehicle" );
// make sure we update the client, check for timed damage and update suit even if we are in a vehicle
UpdateClientData();
CheckTimeBasedDamage();
// Allow the suit to recharge when in the vehicle.
SuitPower_Update();
CheckSuitUpdate();
CheckSuitZoom();
WaterMove();
return;
}
// This is an experiment of mine- autojumping!
// only affects you if sv_autojump is nonzero.
if( (GetFlags() & FL_ONGROUND) && sv_autojump.GetFloat() != 0 )
{
VPROF( "CHL2_Player::PreThink-Autojump" );
// check autojump
Vector vecCheckDir;
vecCheckDir = GetAbsVelocity();
float flVelocity = VectorNormalize( vecCheckDir );
if( flVelocity > 200 )
{
// Going fast enough to autojump
vecCheckDir = WorldSpaceCenter() + vecCheckDir * 34 - Vector( 0, 0, 16 );
trace_t tr;
UTIL_TraceHull( WorldSpaceCenter() - Vector( 0, 0, 16 ), vecCheckDir, NAI_Hull::Mins(HULL_TINY_CENTERED),NAI_Hull::Maxs(HULL_TINY_CENTERED), MASK_PLAYERSOLID, this, COLLISION_GROUP_PLAYER, &tr );
//NDebugOverlay::Line( tr.startpos, tr.endpos, 0,255,0, true, 10 );
if( tr.fraction == 1.0 && !tr.startsolid )
{
// Now trace down!
UTIL_TraceLine( vecCheckDir, vecCheckDir - Vector( 0, 0, 64 ), MASK_PLAYERSOLID, this, COLLISION_GROUP_NONE, &tr );
//NDebugOverlay::Line( tr.startpos, tr.endpos, 0,255,0, true, 10 );
if( tr.fraction == 1.0 && !tr.startsolid )
{
// !!!HACKHACK
// I KNOW, I KNOW, this is definitely not the right way to do this,
// but I'm prototyping! (sjb)
Vector vecNewVelocity = GetAbsVelocity();
vecNewVelocity.z += 250;
SetAbsVelocity( vecNewVelocity );
}
}
}
}
VPROF_SCOPE_BEGIN( "CHL2_Player::PreThink-Speed" );
HandleSpeedChanges();
#ifdef HL2_EPISODIC
HandleArmorReduction();
#endif
if( sv_stickysprint.GetBool() && m_bIsAutoSprinting )
{
// If we're ducked and not in the air
if( IsDucked() && GetGroundEntity() != NULL )
{
StopSprinting();
}
// Stop sprinting if the player lets off the stick for a moment.
else if( GetStickDist() == 0.0f )
{
if( gpGlobals->curtime > m_fAutoSprintMinTime )
{
StopSprinting();
}
}
else
{
// Stop sprinting one half second after the player stops inputting with the move stick.
m_fAutoSprintMinTime = gpGlobals->curtime + 0.5f;
}
}
else if ( IsSprinting() )
{
// Disable sprint while ducked unless we're in the air (jumping)
if ( IsDucked() && ( GetGroundEntity() != NULL ) )
{
StopSprinting();
}
}
VPROF_SCOPE_END();
if ( g_fGameOver || IsPlayerLockedInPlace() )
return; // finale
VPROF_SCOPE_BEGIN( "CHL2_Player::PreThink-ItemPreFrame" );
ItemPreFrame( );
VPROF_SCOPE_END();
VPROF_SCOPE_BEGIN( "CHL2_Player::PreThink-WaterMove" );
WaterMove();
VPROF_SCOPE_END();
if ( g_pGameRules && g_pGameRules->FAllowFlashlight() )
m_Local.m_iHideHUD &= ~HIDEHUD_FLASHLIGHT;
else
m_Local.m_iHideHUD |= HIDEHUD_FLASHLIGHT;
VPROF_SCOPE_BEGIN( "CHL2_Player::PreThink-CommanderUpdate" );
CommanderUpdate();
VPROF_SCOPE_END();
// Operate suit accessories and manage power consumption/charge
VPROF_SCOPE_BEGIN( "CHL2_Player::PreThink-SuitPower_Update" );
SuitPower_Update();
VPROF_SCOPE_END();
// checks if new client data (for HUD and view control) needs to be sent to the client
VPROF_SCOPE_BEGIN( "CHL2_Player::PreThink-UpdateClientData" );
UpdateClientData();
VPROF_SCOPE_END();
VPROF_SCOPE_BEGIN( "CHL2_Player::PreThink-CheckTimeBasedDamage" );
CheckTimeBasedDamage();
VPROF_SCOPE_END();
VPROF_SCOPE_BEGIN( "CHL2_Player::PreThink-CheckSuitUpdate" );
CheckSuitUpdate();
VPROF_SCOPE_END();
VPROF_SCOPE_BEGIN( "CHL2_Player::PreThink-CheckSuitZoom" );
CheckSuitZoom();
VPROF_SCOPE_END();
if (m_lifeState >= LIFE_DYING)
{
PlayerDeathThink();
return;
}
#ifdef HL2_EPISODIC
CheckFlashlight();
#endif // HL2_EPISODIC
// So the correct flags get sent to client asap.
//
if ( m_afPhysicsFlags & PFLAG_DIROVERRIDE )
AddFlag( FL_ONTRAIN );
else
RemoveFlag( FL_ONTRAIN );
// Train speed control
if ( m_afPhysicsFlags & PFLAG_DIROVERRIDE )
{
CBaseEntity *pTrain = GetGroundEntity();
float vel;
if ( pTrain )
{
if ( !(pTrain->ObjectCaps() & FCAP_DIRECTIONAL_USE) )
pTrain = NULL;
}
if ( !pTrain )
{
if ( GetActiveWeapon() && (GetActiveWeapon()->ObjectCaps() & FCAP_DIRECTIONAL_USE) )
{
m_iTrain = TRAIN_ACTIVE | TRAIN_NEW;
if ( m_nButtons & IN_FORWARD )
{
m_iTrain |= TRAIN_FAST;
}
else if ( m_nButtons & IN_BACK )
{
m_iTrain |= TRAIN_BACK;
}
else
{
m_iTrain |= TRAIN_NEUTRAL;
}
return;
}
else
{
trace_t trainTrace;
// Maybe this is on the other side of a level transition
UTIL_TraceLine( GetAbsOrigin(), GetAbsOrigin() + Vector(0,0,-38),
MASK_PLAYERSOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, &trainTrace );
if ( trainTrace.fraction != 1.0 && trainTrace.m_pEnt )
pTrain = trainTrace.m_pEnt;
if ( !pTrain || !(pTrain->ObjectCaps() & FCAP_DIRECTIONAL_USE) || !pTrain->OnControls(this) )
{
// Warning( "In train mode with no train!\n" );
m_afPhysicsFlags &= ~PFLAG_DIROVERRIDE;
m_iTrain = TRAIN_NEW|TRAIN_OFF;
return;
}
}
}
else if ( !( GetFlags() & FL_ONGROUND ) || pTrain->HasSpawnFlags( SF_TRACKTRAIN_NOCONTROL ) || (m_nButtons & (IN_MOVELEFT|IN_MOVERIGHT) ) )
{
// Turn off the train if you jump, strafe, or the train controls go dead
m_afPhysicsFlags &= ~PFLAG_DIROVERRIDE;
m_iTrain = TRAIN_NEW|TRAIN_OFF;
return;
}
SetAbsVelocity( vec3_origin );
vel = 0;
if ( m_afButtonPressed & IN_FORWARD )
{
vel = 1;
pTrain->Use( this, this, USE_SET, (float)vel );
}
else if ( m_afButtonPressed & IN_BACK )
{
vel = -1;
pTrain->Use( this, this, USE_SET, (float)vel );
}
if (vel)
{
m_iTrain = TrainSpeed(pTrain->m_flSpeed, ((CFuncTrackTrain*)pTrain)->GetMaxSpeed());
m_iTrain |= TRAIN_ACTIVE|TRAIN_NEW;
}
}
else if (m_iTrain & TRAIN_ACTIVE)
{
m_iTrain = TRAIN_NEW; // turn off train
}
//
// If we're not on the ground, we're falling. Update our falling velocity.
//
if ( !( GetFlags() & FL_ONGROUND ) )
{
m_Local.m_flFallVelocity = -GetAbsVelocity().z;
}
if ( m_afPhysicsFlags & PFLAG_ONBARNACLE )
{
bool bOnBarnacle = false;
CNPC_Barnacle *pBarnacle = NULL;
do
{
// FIXME: Not a good or fast solution, but maybe it will catch the bug!
pBarnacle = (CNPC_Barnacle*)gEntList.FindEntityByClassname( pBarnacle, "npc_barnacle" );
if ( pBarnacle )
{
if ( pBarnacle->GetEnemy() == this )
{
bOnBarnacle = true;
}
}
} while ( pBarnacle );
if ( !bOnBarnacle )
{
Warning( "Attached to barnacle?\n" );
Assert( 0 );
m_afPhysicsFlags &= ~PFLAG_ONBARNACLE;
}
else
{
SetAbsVelocity( vec3_origin );
}
}
// StudioFrameAdvance( );//!!!HACKHACK!!! Can't be hit by traceline when not animating?
// Update weapon's ready status
UpdateWeaponPosture();
// Disallow shooting while zooming
if ( IsX360() )
{
if ( IsZooming() )
{
if( GetActiveWeapon() && !GetActiveWeapon()->IsWeaponZoomed() )
{
// If not zoomed because of the weapon itself, do not attack.
m_nButtons &= ~(IN_ATTACK|IN_ATTACK2);
}
}
}
else
{
if ( m_nButtons & IN_ZOOM )
{
//FIXME: Held weapons like the grenade get sad when this happens
#ifdef HL2_EPISODIC
// Episodic allows players to zoom while using a func_tank
CBaseCombatWeapon* pWep = GetActiveWeapon();
if ( !m_hUseEntity || ( pWep && pWep->IsWeaponVisible() ) )
#endif
m_nButtons &= ~(IN_ATTACK|IN_ATTACK2);
}
}
}
void CHL2_Player::PostThink( void )
{
BaseClass::PostThink();
if ( !g_fGameOver && !IsPlayerLockedInPlace() && IsAlive() )
{
HandleAdmireGlovesAnimation();
}
}
void CHL2_Player::StartAdmireGlovesAnimation( void )
{
MDLCACHE_CRITICAL_SECTION();
CBaseViewModel *vm = GetViewModel( 0 );
if ( vm && !GetActiveWeapon() )
{
vm->SetWeaponModel( "models/weapons/v_hands.mdl", NULL );
ShowViewModel( true );
int idealSequence = vm->SelectWeightedSequence( ACT_VM_IDLE );
if ( idealSequence >= 0 )
{
vm->SendViewModelMatchingSequence( idealSequence );
m_flAdmireGlovesAnimTime = gpGlobals->curtime + vm->SequenceDuration( idealSequence );
}
}
}
void CHL2_Player::HandleAdmireGlovesAnimation( void )
{
CBaseViewModel *pVM = GetViewModel();
if ( pVM && pVM->GetOwningWeapon() == NULL )
{
if ( m_flAdmireGlovesAnimTime != 0.0 )
{
if ( m_flAdmireGlovesAnimTime > gpGlobals->curtime )
{
pVM->m_flPlaybackRate = 1.0f;
pVM->StudioFrameAdvance( );
}
else if ( m_flAdmireGlovesAnimTime < gpGlobals->curtime )
{
m_flAdmireGlovesAnimTime = 0.0f;
pVM->SetWeaponModel( NULL, NULL );
}
}
}
else
m_flAdmireGlovesAnimTime = 0.0f;
}
#define HL2PLAYER_RELOADGAME_ATTACK_DELAY 1.0f
void CHL2_Player::Activate( void )
{
BaseClass::Activate();
InitSprinting();
#ifdef HL2_EPISODIC
// Delay attacks by 1 second after loading a game.
if ( GetActiveWeapon() )
{
float flRemaining = GetActiveWeapon()->m_flNextPrimaryAttack - gpGlobals->curtime;
if ( flRemaining < HL2PLAYER_RELOADGAME_ATTACK_DELAY )
{
GetActiveWeapon()->m_flNextPrimaryAttack = gpGlobals->curtime + HL2PLAYER_RELOADGAME_ATTACK_DELAY;
}
flRemaining = GetActiveWeapon()->m_flNextSecondaryAttack - gpGlobals->curtime;
if ( flRemaining < HL2PLAYER_RELOADGAME_ATTACK_DELAY )
{
GetActiveWeapon()->m_flNextSecondaryAttack = gpGlobals->curtime + HL2PLAYER_RELOADGAME_ATTACK_DELAY;
}
}
#endif
GetPlayerProxy();
}
//------------------------------------------------------------------------------
// Purpose :
// Input :
// Output :
//------------------------------------------------------------------------------
Class_T CHL2_Player::Classify ( void )
{
// If player controlling another entity? If so, return this class
if (m_nControlClass != CLASS_NONE)
{
return m_nControlClass;
}
else
{
if(IsInAVehicle())
{
IServerVehicle *pVehicle = GetVehicle();
return pVehicle->ClassifyPassenger( this, CLASS_PLAYER );