-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathneo_player.cpp
More file actions
4387 lines (3769 loc) · 122 KB
/
neo_player.cpp
File metadata and controls
4387 lines (3769 loc) · 122 KB
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
#include "cbase.h"
#include "neo_player.h"
#include "neo_predicted_viewmodel.h"
#include "neo_predicted_viewmodel_muzzleflash.h"
#include "in_buttons.h"
#include "neo_gamerules.h"
#include "team.h"
#include "engine/IEngineSound.h"
#include "SoundEmitterSystem/isoundemittersystembase.h"
#include "ilagcompensationmanager.h"
#include "datacache/imdlcache.h"
#include "neo_model_manager.h"
#include "gib.h"
#include "world.h"
#include "weapon_ghost.h"
#include "weapon_supa7.h"
#include "weapon_knife.h"
#include "weapon_grenade.h"
#include "weapon_smokegrenade.h"
#include "weapon_tachi.h"
#include "shareddefs.h"
#include "inetchannelinfo.h"
#include "eiface.h"
#include "sequence_Transitioner.h"
#include "neo_te_tocflash.h"
#include "viewport_panel_names.h"
#include "neo_weapon_loadout.h"
#include "player_resource.h"
#include "neo_player_shared.h"
#include "bot/neo_bot.h"
#include "nav_mesh.h"
#include "neo_spawn_manager.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
LINK_ENTITY_TO_CLASS(player, CNEO_Player);
IMPLEMENT_SERVERCLASS_ST(CNEO_Player, DT_NEO_Player)
SendPropInt(SENDINFO(m_iNeoClass)),
SendPropInt(SENDINFO(m_iNeoSkin), NumBitsForCount(NEO_SKIN_ENUM_COUNT), SPROP_UNSIGNED),
SendPropInt(SENDINFO(m_iNeoStar), NumBitsForCount(STAR__TOTAL), SPROP_UNSIGNED),
SendPropInt(SENDINFO(m_iClassBeforeTakeover)),
SendPropInt(SENDINFO(m_iXP)),
SendPropInt(SENDINFO(m_iLoadoutWepChoice), NumBitsForCount(MAX_WEAPON_LOADOUTS), SPROP_UNSIGNED),
SendPropInt(SENDINFO(m_iNextSpawnClassChoice)),
SendPropInt(SENDINFO(m_bInLean), NumBitsForCount(NEO_LEAN_ENUM_COUNT), SPROP_UNSIGNED),
SendPropEHandle(SENDINFO(m_hServerRagdoll)),
SendPropEHandle(SENDINFO(m_hCommandingPlayer)),
SendPropBool(SENDINFO(m_bInThermOpticCamo)),
SendPropBool(SENDINFO(m_bLastTickInThermOpticCamo)),
SendPropBool(SENDINFO(m_bInVision)),
SendPropBool(SENDINFO(m_bHasBeenAirborneForTooLongToSuperJump)),
SendPropBool(SENDINFO(m_bShowTestMessage)),
SendPropBool(SENDINFO(m_bInAim)),
SendPropBool(SENDINFO(m_bIneligibleForLoadoutPick)),
SendPropBool(SENDINFO(m_bCarryingGhost)),
SendPropTime(SENDINFO(m_flCamoAuxLastTime)),
SendPropInt(SENDINFO(m_nVisionLastTick), -1, SPROP_UNSIGNED),
SendPropTime(SENDINFO(m_flJumpLastTime)),
SendPropTime(SENDINFO(m_flNextPingTime)),
SendPropString(SENDINFO(m_pszTestMessage)),
SendPropArray(SendPropInt(SENDINFO_ARRAY(m_rfAttackersScores)), m_rfAttackersScores),
SendPropArray(SendPropFloat(SENDINFO_ARRAY(m_rfAttackersAccumlator), -1, SPROP_COORD_MP_LOWPRECISION | SPROP_CHANGES_OFTEN, MIN_COORD_FLOAT, MAX_COORD_FLOAT), m_rfAttackersAccumlator),
SendPropArray(SendPropInt(SENDINFO_ARRAY(m_rfAttackersHits)), m_rfAttackersHits),
SendPropArray(SendPropVector(SENDINFO_ARRAY(m_vLastPingByStar), -1, SPROP_COORD), m_vLastPingByStar),
SendPropInt(SENDINFO(m_NeoFlags), 4, SPROP_UNSIGNED),
SendPropString(SENDINFO(m_szNeoName)),
SendPropString(SENDINFO(m_szNeoClantag)),
SendPropString(SENDINFO(m_szNeoCrosshair)),
SendPropInt(SENDINFO(m_szNameDupePos)),
SendPropBool(SENDINFO(m_bClientWantNeoName)),
SendPropTime(SENDINFO(m_flDeathTime)),
SendPropEHandle(SENDINFO(m_hSpectatorTakeoverPlayerTarget)),
SendPropEHandle(SENDINFO(m_hSpectatorTakeoverPlayerImpersonatingMe)),
END_SEND_TABLE()
BEGIN_DATADESC(CNEO_Player)
DEFINE_FIELD(m_iNeoClass, FIELD_INTEGER),
DEFINE_FIELD(m_iNeoSkin, FIELD_INTEGER),
DEFINE_FIELD(m_iNeoStar, FIELD_INTEGER),
DEFINE_FIELD(m_iClassBeforeTakeover, FIELD_INTEGER),
DEFINE_FIELD(m_iXP, FIELD_INTEGER),
DEFINE_FIELD(m_iLoadoutWepChoice, FIELD_INTEGER),
DEFINE_FIELD(m_bIneligibleForLoadoutPick, FIELD_BOOLEAN),
DEFINE_FIELD(m_iNextSpawnClassChoice, FIELD_INTEGER),
DEFINE_FIELD(m_bInLean, FIELD_INTEGER),
DEFINE_FIELD(m_bInThermOpticCamo, FIELD_BOOLEAN),
DEFINE_FIELD(m_bLastTickInThermOpticCamo, FIELD_BOOLEAN),
DEFINE_FIELD(m_bInVision, FIELD_BOOLEAN),
DEFINE_FIELD(m_bHasBeenAirborneForTooLongToSuperJump, FIELD_BOOLEAN),
DEFINE_FIELD(m_bShowTestMessage, FIELD_BOOLEAN),
DEFINE_FIELD(m_bInAim, FIELD_BOOLEAN),
DEFINE_FIELD(m_flCamoAuxLastTime, FIELD_TIME),
DEFINE_FIELD(m_nVisionLastTick, FIELD_TICK),
DEFINE_FIELD(m_flJumpLastTime, FIELD_TIME),
DEFINE_FIELD(m_flNextPingTime, FIELD_TIME),
DEFINE_FIELD(m_pszTestMessage, FIELD_STRING),
DEFINE_FIELD(m_rfAttackersScores, FIELD_CUSTOM),
DEFINE_FIELD(m_rfAttackersAccumlator, FIELD_CUSTOM),
DEFINE_FIELD(m_rfAttackersHits, FIELD_CUSTOM),
DEFINE_FIELD(m_NeoFlags, FIELD_CHARACTER),
DEFINE_FIELD(m_szNeoName, FIELD_STRING),
DEFINE_FIELD(m_szNeoClantag, FIELD_STRING),
DEFINE_FIELD(m_szNeoCrosshair, FIELD_STRING),
DEFINE_FIELD(m_szNameDupePos, FIELD_INTEGER),
DEFINE_FIELD(m_bClientWantNeoName, FIELD_BOOLEAN),
// Inputs
DEFINE_INPUTFUNC(FIELD_STRING, "SetPlayerModel", InputSetPlayerModel),
DEFINE_INPUTFUNC(FIELD_VOID, "RefillAmmo", InputRefillAmmo),
DEFINE_INPUTFUNC(FIELD_INTEGER, "SetTeam", InputSetTeam),
END_DATADESC()
BEGIN_ENT_SCRIPTDESC(CNEO_Player, CHL2MP_Player, "NEO Player")
END_SCRIPTDESC();
static constexpr int SHOWMENU_STRLIMIT = 512;
const Vector CNEO_Player::VECTOR_INVALID_WAYPOINT = vec3_invalid;
CBaseEntity *g_pLastJinraiSpawn, *g_pLastNSFSpawn;
CNEOGameRulesProxy* neoGameRules;
extern CBaseEntity *g_pLastSpawn;
extern ConVar sv_neo_bot_cmdr_enable;
extern ConVar sv_neo_ignore_wep_xp_limit;
extern ConVar sv_neo_clantag_allow;
extern ConVar sv_neo_dev_test_clantag;
extern ConVar sv_stickysprint;
extern ConVar sv_neo_dev_loadout;
extern ConVar neo_bot_difficulty;
ConVar sv_neo_can_change_classes_anytime("sv_neo_can_change_classes_anytime", "0", FCVAR_CHEAT | FCVAR_REPLICATED, "Can players change classes at any moment, even mid-round?",
true, 0.0f, true, 1.0f);
ConVar sv_neo_change_suicide_player("sv_neo_change_suicide_player", "0", FCVAR_REPLICATED, "Kill the player if they change the team and they're alive.", true, 0.0f, true, 1.0f);
ConVar sv_neo_change_threshold_interval("sv_neo_change_threshold_interval", "0.25", FCVAR_REPLICATED, "The interval threshold limit in seconds before the player is allowed to change team.", true, 0.0f, true, 1000.0f);
ConVar sv_neo_dm_max_class_dur("sv_neo_dm_max_class_dur", "10", FCVAR_REPLICATED, "The time in seconds when the player can change class on respawn during deathmatch.", true, 0.0f, true, 60.0f);
ConVar sv_neo_warmup_godmode("sv_neo_warmup_godmode", "0", FCVAR_REPLICATED, "If enabled, everyone is invincible on idle and warmup.", true, 0.0f, true, 1.0f);
ConVar bot_class("bot_class", "-1", 0, "Force all bots to spawn with the specified class number, or -1 to disable.", true, NEO_CLASS_RANDOM, true, NEO_CLASS_LOADOUTABLE_COUNT-1);
static void BotChangeClassFn(const CCommand& args);
ConCommand bot_changeclass("bot_changeclass", BotChangeClassFn, "Force all bots to switch to the specified class number.");
// Bot Cloak Detection Thresholds
// Base detection chance ratio (0.0 - 1.0) for bots to notice a cloaked target based on difficulty
// e.g. 0 implies the bot is oblivious to anything, while 1.0 implies a bot that can roll very high on detection checks
ConVar sv_neo_bot_cloak_detection_threshold_ratio_easy("sv_neo_bot_cloak_detection_threshold_ratio_easy", "0.35", FCVAR_NONE, "Bot cloak detection threshold for easy difficulty observers", true, 0.0f, true, 1.0f);
ConVar sv_neo_bot_cloak_detection_threshold_ratio_normal("sv_neo_bot_cloak_detection_threshold_ratio_normal", "0.40", FCVAR_NONE, "Bot cloak detection threshold for normal difficulty observers", true, 0.0f, true, 1.0f);
ConVar sv_neo_bot_cloak_detection_threshold_ratio_hard("sv_neo_bot_cloak_detection_threshold_ratio_hard", "0.45", FCVAR_NONE, "Bot cloak detection threshold for hard difficulty observers", true, 0.0f, true, 1.0f);
ConVar sv_neo_bot_cloak_detection_threshold_ratio_expert("sv_neo_bot_cloak_detection_threshold_ratio_expert", "0.50", FCVAR_NONE, "Bot cloak detection threshold for expert difficulty observers", true, 0.0f, true, 1.0f);
// Bot Cloak Detection Bonus Factors
// Used in CNEO_Player::GetFogObscuredRatio to determine if the bot (me) can detect a cloaked target given circumstances
// Style guide:
// - positive values mean the cloak effect of the target player is more easily detectable by a bot observer
// - ideally all of these values are positive so the bonus is monotonically increasing
// - see CNEO_Player::IsHiddenByFog for base detection rates by difficulting rating of bot observer
ConVar sv_neo_bot_cloak_debug_perceive_always_on("sv_neo_bot_cloak_debug_perceive_always_on", "0", FCVAR_CHEAT,
"Debug: Force bots to perceive all players as having cloaking on all the time", true, 0, true, 1);
ConVar sv_neo_bot_cloak_detection_bonus_disruption_effect("sv_neo_bot_cloak_detection_bonus_disruption_effect", "30", FCVAR_NONE,
"Bot cloak detection bonus for target being surrounded by the blue disruption effect", true, 0, true, 100);
ConVar sv_neo_bot_cloak_detection_bonus_assault_motion_vision("sv_neo_bot_cloak_detection_bonus_assault_motion_vision", "60", FCVAR_NONE,
"Bot cloak detection bonus for assault class detecting movement with motion vision", true, 0, true, 100);
// Support has difficulty seeing cloak in thermal vision
ConVar sv_neo_bot_cloak_detection_bonus_non_support("sv_neo_bot_cloak_detection_bonus_non_support", "1", FCVAR_NONE,
"Bot cloak detection bonus for non-support classes", true, 0, true, 100);
// 0.7 dot product is about a 45 degree half hangle for a 90 degree cone
ConVar sv_neo_bot_cloak_detection_aim_bonus_dot_threshold("sv_neo_bot_cloak_detection_aim_bonus_dot_threshold", "0.3", FCVAR_NONE,
"Bot cloak detection bonus minimum dot product threshold for aim bonus", true, 0.01, true, 0.7);
ConVar sv_neo_bot_cloak_detection_bonus_observer_stationary("sv_neo_bot_cloak_detection_bonus_observer_stationary", "2", FCVAR_NONE,
"Bot cloak detection bonus for observer being stationary", true, 0, true, 100);
ConVar sv_neo_bot_cloak_detection_bonus_observer_walking("sv_neo_bot_cloak_detection_bonus_observer_walking", "1", FCVAR_NONE,
"Bot cloak detection bonus for observer walking", true, 0, true, 100);
ConVar sv_neo_bot_cloak_detection_bonus_target_running("sv_neo_bot_cloak_detection_bonus_target_running", "2", FCVAR_NONE,
"Bot cloak detection bonus for target running", true, 0, true, 100);
ConVar sv_neo_bot_cloak_detection_bonus_target_moving("sv_neo_bot_cloak_detection_bonus_target_moving", "1", FCVAR_NONE,
"Bot cloak detection bonus for target moving", true, 0, true, 100);
ConVar sv_neo_bot_cloak_detection_bonus_target_standing("sv_neo_bot_cloak_detection_bonus_target_standing", "1", FCVAR_NONE,
"Bot cloak detection bonus for target standing", true, 0, true, 100);
ConVar sv_neo_bot_cloak_detection_bonus_scope_range("sv_neo_bot_cloak_detection_bonus_scope_range", "1", FCVAR_NONE,
"Bot cloak detection bonus for being in scope range", true, 0, true, 100);
ConVar sv_neo_bot_cloak_detection_bonus_shotgun_range("sv_neo_bot_cloak_detection_bonus_shotgun_range", "5", FCVAR_NONE,
"Bot cloak detection bonus for being in shotgun range", true, 0, true, 100);
ConVar sv_neo_bot_cloak_detection_bonus_melee_range("sv_neo_bot_cloak_detection_bonus_melee_range", "50", FCVAR_NONE,
"Bot cloak detection bonus for being in melee range", true, 0, true, 100);
ConVar sv_neo_bot_cloak_detection_bonus_per_injury("sv_neo_bot_cloak_detection_bonus_per_injury", "1", FCVAR_NONE,
"Bot cloak detection bonus per injury event", true, 0, true, 100);
// TODO: Lighting information is not yet baked into NavAreas, so we would need to implement that for bots to detect based on lighting
// See "FIXMEL4DTOMAINMERGE" for how NavArea::ComputeLighting() is not fully implemented
ConVar sv_neo_bot_cloak_detection_bonus_lighting_enabled("sv_neo_bot_cloak_detection_bonus_lighting_enabled", "0", FCVAR_NONE,
"Enable/Disable bot cloak detection lighting bonus", false, 0, false, 1);
// Depends on sv_neo_bot_cloak_detection_bonus_lighting_enabled
ConVar sv_neo_bot_cloak_detection_bonus_lighting("sv_neo_bot_cloak_detection_bonus_lighting", "0", FCVAR_NONE,
"Bot cloak detection bonus for target being in a well lit area (scaled by light intensity ratio 0.0-1.0)", true, 0, true, 100);
void CNEO_Player::RequestSetClass(int newClass)
{
if (newClass < 0 || newClass >= NEO_CLASS_ENUM_COUNT)
{
Assert(false);
return;
}
if (newClass == m_iNeoClass) {
return;
}
const bool bIsTypeDM = (NEORules()->GetGameType() == NEO_GAME_TYPE_TDM || NEORules()->GetGameType() == NEO_GAME_TYPE_DM);
const NeoRoundStatus status = NEORules()->GetRoundStatus();
if (IsDead() || sv_neo_can_change_classes_anytime.GetBool() ||
(!m_bIneligibleForLoadoutPick && NEORules()->GetRemainingPreRoundFreezeTime(false) > 0) ||
(bIsTypeDM && !m_bIneligibleForLoadoutPick && GetAliveDuration() < sv_neo_dm_max_class_dur.GetFloat()) ||
(status == NeoRoundStatus::Idle || status == NeoRoundStatus::Warmup || status == NeoRoundStatus::Countdown))
{
m_iNeoClass = newClass;
m_iNextSpawnClassChoice = NEO_CLASS_RANDOM;
SetPlayerTeamModel();
SetViewOffset(VEC_VIEW_NEOSCALE(this));
InitSprinting();
RemoveAllItems(false);
if (NEORules()->GetGameType() != NEO_GAME_TYPE_TUT)
{
GiveDefaultItems();
RequestSetLoadout(0);
}
m_HL2Local.m_cloakPower = CloakPower_Cap();
SetMaxHealth(MAX_HEALTH_FOR_CLASS[newClass]);
SetHealth(GetMaxHealth());
}
else
{
m_iNextSpawnClassChoice = newClass;
const char* classes[] = { "recon", "assault", "support", "VIP" };
const char* msg = "You will spawn as %s class next round.\n";
Msg(msg, classes[newClass]);
ConMsg(msg, classes[newClass]);
}
}
void CNEO_Player::RequestSetSkin(int newSkin)
{
const NeoRoundStatus roundStatus = NEORules()->GetRoundStatus();
bool canChangeImmediately = ((roundStatus != NeoRoundStatus::RoundLive) && (roundStatus != NeoRoundStatus::Overtime) && (roundStatus != NeoRoundStatus::PostRound)) || !IsAlive();
if (canChangeImmediately)
{
m_iNeoSkin = newSkin;
SetPlayerTeamModel();
}
//else NEOTODO Set for next spawn
}
static bool IsNeoPrimary(CNEOBaseCombatWeapon *pNeoWep)
{
if (!pNeoWep)
{
return false;
}
const auto bits = pNeoWep->GetNeoWepBits();
Assert(bits > NEO_WEP_INVALID);
const auto primaryBits = NEO_WEP_AA13 | NEO_WEP_GHOST | NEO_WEP_JITTE | NEO_WEP_JITTE_S |
NEO_WEP_M41 | NEO_WEP_M41_L | NEO_WEP_M41_S | NEO_WEP_MPN | NEO_WEP_MPN_S |
NEO_WEP_MX | NEO_WEP_MX_S | NEO_WEP_PZ | NEO_WEP_SMAC | NEO_WEP_SRM |
NEO_WEP_SRM_S | NEO_WEP_SRS | NEO_WEP_SUPA7 | NEO_WEP_ZR68_C | NEO_WEP_ZR68_L |
NEO_WEP_ZR68_S | NEO_WEP_BALC
#ifdef INCLUDE_WEP_PBK
| NEO_WEP_PBK56S
#endif
;
return (primaryBits & bits) ? true : false;
}
void CNEO_Player::RequestSetStar(int newStar)
{
const int team = GetTeamNumber();
if (team != TEAM_JINRAI && team != TEAM_NSF)
{
return;
}
if (newStar < STAR_ALPHA || newStar > STAR_NONE)
{
return;
}
if (newStar == m_iNeoStar)
{
return;
}
m_iNeoStar.GetForModify() = newStar;
}
bool CNEO_Player::RequestSetLoadout(int loadoutNumber)
{
int classChosen = m_iNextSpawnClassChoice.Get() != NEO_CLASS_RANDOM ? m_iNextSpawnClassChoice.Get() : m_iNeoClass.Get();
const int iLoadoutClass = sv_neo_dev_loadout.GetBool() ? NEO_LOADOUT_DEV : classChosen;
const char *pszWepName = (IN_BETWEEN_AR(0, iLoadoutClass, NEO_LOADOUT__COUNT) && IN_BETWEEN_AR(0, loadoutNumber, MAX_WEAPON_LOADOUTS)) ?
CNEOWeaponLoadout::s_LoadoutWeapons[iLoadoutClass][loadoutNumber].info.m_szWeaponEntityName :
"";
if (FStrEq(pszWepName, ""))
{
Assert(false);
Warning("CNEO_Player::RequestSetLoadout: Loadout request failed\n");
return false;
}
EHANDLE pEnt;
pEnt = CreateEntityByName(pszWepName);
if (!pEnt)
{
Assert(false);
Warning("NULL Ent in RequestSetLoadout!\n");
return false;
}
pEnt->SetLocalOrigin(GetLocalOrigin());
pEnt->AddSpawnFlags(SF_NORESPAWN);
auto *pNeoWeapon = assert_cast<CNEOBaseCombatWeapon*>((CBaseEntity*)pEnt);
if (!pNeoWeapon)
{
if (pEnt != NULL && !(pEnt->IsMarkedForDeletion()))
{
UTIL_Remove((CBaseEntity*)pEnt);
Assert(false);
Warning("CNEO_Player::RequestSetLoadout: Not a Neo base weapon: %s\n", pszWepName);
return false;
}
}
bool result = true;
if (!IsNeoPrimary(pNeoWeapon))
{
Assert(false);
Warning("CNEO_Player::RequestSetLoadout: Not a Neo primary weapon: %s\n", pszWepName);
result = false;
}
if (!sv_neo_ignore_wep_xp_limit.GetBool() &&
loadoutNumber+1 > CNEOWeaponLoadout::GetNumberOfLoadoutWeapons(m_iXP,
sv_neo_dev_loadout.GetBool() ? NEO_LOADOUT_DEV : classChosen))
{
DevMsg("Insufficient XP for %s\n", pszWepName);
result = RequestSetLoadout(0);
}
if (result)
{
m_iLoadoutWepChoice = loadoutNumber;
GiveLoadoutWeapon();
}
if (pEnt != NULL && !(pEnt->IsMarkedForDeletion()))
{
UTIL_Remove((CBaseEntity*)pEnt);
}
return result;
}
void SetClass(const CCommand &command)
{
auto player = static_cast<CNEO_Player*>(UTIL_GetCommandClient());
if (!player)
{
return;
}
if (player->IsAlive() && NEORules()->GetGameType() == NEO_GAME_TYPE_TUT)
{
return;
}
if (command.ArgC() == 2)
{
// Class number from the .res button click action.
// Our NeoClass enum is zero indexed, so we subtract one.
int nextClass = atoi(command.ArgV()[1]) - 1;
auto playerIsVip = NEORules()->GetGameType() == NEO_GAME_TYPE_VIP && player->m_iNeoClass == NEO_CLASS_VIP;
auto playerIsSameClass = player->m_iNeoClass == nextClass;
if (playerIsVip || playerIsSameClass)
{
return;
}
nextClass = clamp(nextClass, NEO_CLASS_RECON, NEO_CLASS_SUPPORT);
player->RequestSetClass(nextClass);
}
}
extern void respawn(CBaseEntity* pEdict, bool fCopyCorpse);
void SetSkin(const CCommand &command)
{
auto player = static_cast<CNEO_Player*>(UTIL_GetCommandClient());
if (!player)
{
return;
}
if (player->IsAlive() && NEORules()->GetGameType() == NEO_GAME_TYPE_TUT)
{
return;
}
if (command.ArgC() == 2)
{
// Skin number from the .res button click action.
// These are actually zero indexed by the .res already,
// so we don't need to subtract from the value.
int nextSkin = atoi(command.ArgV()[1]);
clamp(nextSkin, NEO_SKIN_FIRST, NEO_SKIN_THIRD);
player->RequestSetSkin(nextSkin);
}
if (NEORules()->GetGameType() == NEO_GAME_TYPE_TUT && NEORules()->GetForcedWeapon() >= 0)
{
respawn(player, false);
}
}
void SetLoadout(const CCommand &command)
{
auto player = static_cast<CNEO_Player*>(UTIL_GetCommandClient());
if (!player)
{
return;
}
if (player->IsAlive() && NEORules()->GetGameType() == NEO_GAME_TYPE_TUT)
{
return;
}
if (command.ArgC() == 2)
{
int loadoutNumber = atoi(command.ArgV()[1]);
player->RequestSetLoadout(loadoutNumber);
}
if (NEORules()->GetGameType() == NEO_GAME_TYPE_TUT)
{
respawn(player, false);
}
}
ConCommand setclass("setclass", SetClass, "Set class", FCVAR_USERINFO);
ConCommand setskin("SetVariant", SetSkin, "Set skin", FCVAR_USERINFO);
ConCommand loadout("loadout", SetLoadout, "Set loadout", FCVAR_USERINFO);
CON_COMMAND_F(joinstar, "Join star", FCVAR_USERINFO)
{
auto player = static_cast<CNEO_Player*>(UTIL_GetCommandClient());
if (player && args.ArgC() == 2)
{
const int star = atoi(args.ArgV()[1]);
player->RequestSetStar(star);
}
}
static int GetNumOtherPlayersConnected(CNEO_Player *asker)
{
if (!asker)
{
Assert(false);
return 0;
}
int numConnected = 0;
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CNEO_Player *player = static_cast<CNEO_Player*>(UTIL_PlayerByIndex(i));
if (player && player != asker && player->IsConnected())
{
numConnected++;
}
}
return numConnected;
}
CNEO_Player::CNEO_Player()
{
m_iNeoClass = NEORules()->GetForcedClass() >= 0 ? NEORules()->GetForcedClass() : NEO_CLASS_ASSAULT;
m_iNeoSkin = NEORules()->GetForcedSkin() >= 0 ? NEORules()->GetForcedSkin() : NEO_SKIN_FIRST;
m_iNeoStar = NEO_DEFAULT_STAR;
m_iXP.GetForModify() = 0;
V_memset(m_szNeoName.GetForModify(), 0, sizeof(m_szNeoName));
m_bNeoNameHasSet = false;
V_memset(m_szNeoClantag.GetForModify(), 0, sizeof(m_szNeoClantag));
V_memset(m_szNeoCrosshair.GetForModify(), 0, sizeof(m_szNeoCrosshair));
m_bInThermOpticCamo = m_bInVision = false;
m_bHasBeenAirborneForTooLongToSuperJump = false;
m_bInAim = false;
m_bCarryingGhost = false;
m_bInLean = NEO_LEAN_NONE;
m_iLoadoutWepChoice = NEORules()->GetForcedWeapon() >= 0 ? NEORules()->GetForcedWeapon() : 0;
m_iNextSpawnClassChoice = NEO_CLASS_RANDOM;
m_bShowTestMessage = false;
V_memset(m_pszTestMessage.GetForModify(), 0, sizeof(m_pszTestMessage));
m_flCamoAuxLastTime = 0;
m_nVisionLastTick = 0;
m_flLastAirborneJumpOkTime = 0;
m_flLastSuperJumpTime = 0;
m_botThermOpticCamoDisruptedTimer.Invalidate();
m_bFirstDeathTick = true;
m_bCorpseSet = false;
m_bPreviouslyReloading = false;
m_bLastTickInThermOpticCamo = false;
m_bIsPendingSpawnForThisRound = false;
m_bAllowGibbing = true;
m_flNextTeamChangeTime = gpGlobals->curtime + 0.5f;
m_NeoFlags = 0;
memset(m_szNeoNameWDupeIdx, 0, sizeof(m_szNeoNameWDupeIdx));
m_szNeoNameWDupeIdxNeedUpdate = true;
m_szNameDupePos = 0;
m_flNextPingTime = 0;
ResetBotCommandState();
// set default values for convars only present on the client and read by the server
edict_t* pEdict = edict();
if (pEdict)
{
{
char szCrhSerial[NEO_XHAIR_SEQMAX] = {};
DefaultCrosshairSerial(szCrhSerial);
engine->SetFakeClientConVarValue(pEdict, "cl_neo_crosshair", szCrhSerial);
}
constexpr struct {
const char* name, *value;
} convars[] = {
{ "cl_neo_pvs_cull_roaming_observer", "0" },
{ "cl_neo_streamermode", "0" },
{ "cl_neo_tachi_prefer_auto", "1" },
{ "cl_neo_taking_damage_sounds", "0" },
{ "cl_onlysteamnick", "0" },
{ "hap_HasDevice", "0" },
{ "neo_clantag", "" },
{ "neo_fov", "90" },
{ "neo_name", "" },
};
for (const auto& convar : convars)
{
engine->SetFakeClientConVarValue(pEdict, convar.name, convar.value);
}
}
}
CNEO_Player::~CNEO_Player( void )
{
}
void CNEO_Player::Precache( void )
{
BaseClass::Precache();
}
void CNEO_Player::Spawn(void)
{
int teamNumber = GetTeamNumber();
ShowViewPortPanel(PANEL_SPECGUI, teamNumber == TEAM_SPECTATOR);
if (teamNumber == TEAM_JINRAI || teamNumber == TEAM_NSF)
{
if (NEORules()->GetRoundStatus() == NeoRoundStatus::PreRoundFreeze)
{
AddFlag(FL_GODMODE);
AddNeoFlag(NEO_FL_FREEZETIME);
}
if (NEORules()->IsRoundOn())
{ // NEO TODO (Adam) should people who were spectating at the start of the match and potentially have unfair information about the enemy team be allowed to join the game?
m_bSpawnedThisRound = true;
}
State_Transition(STATE_ACTIVE);
}
if (IsBot())
{
const int forcedBotClass = bot_class.GetInt();
if (forcedBotClass == NEO_CLASS_RANDOM)
{
if (auto* thisBot = ToNEOBot(this))
m_iNextSpawnClassChoice = thisBot->ChooseRandomClass();
else
AssertMsg(false, "this IsBot() but can't convert to NEO bot!?");
}
else
{
m_iNextSpawnClassChoice = forcedBotClass;
}
}
// Should do this class update first, because most of the stuff below depends on which player class we are.
if ((m_iNextSpawnClassChoice != NEO_CLASS_RANDOM) && (m_iNeoClass != m_iNextSpawnClassChoice))
{
m_iNeoClass = m_iNextSpawnClassChoice;
}
BaseClass::Spawn();
SetMaxHealth(MAX_HEALTH_FOR_CLASS[m_iNeoClass]);
SetHealth(GetMaxHealth());
m_HL2Local.m_cloakPower = CloakPower_Cap();
m_bIsPendingSpawnForThisRound = false;
m_bLastTickInThermOpticCamo = m_bInThermOpticCamo = false;
m_flCamoAuxLastTime = 0;
m_bInVision = false;
m_nVisionLastTick = 0;
m_bInLean = NEO_LEAN_NONE;
m_bCorpseSet = false;
m_bAllowGibbing = true;
m_bIneligibleForLoadoutPick = false;
static_assert(_ARRAYSIZE(m_rfAttackersScores) == MAX_PLAYERS_ARRAY_SAFE);
static_assert(_ARRAYSIZE(m_rfAttackersAccumlator) == MAX_PLAYERS_ARRAY_SAFE);
static_assert(_ARRAYSIZE(m_rfAttackersHits) == MAX_PLAYERS_ARRAY_SAFE);
for (int i = 0; i < MAX_PLAYERS_ARRAY_SAFE; ++i)
{
m_rfAttackersScores.GetForModify(i) = 0;
m_rfAttackersAccumlator.GetForModify(i) = 0.0f;
m_rfAttackersHits.GetForModify(i) = 0;
}
m_flRanOutSprintTime = 0.0f;
m_flNextPingTime = 0.0f;
Weapon_SetZoom(false);
ShowCrosshair(false);
SetTransmitState(FL_EDICT_PVSCHECK);
StopWaterDeathSounds();
SetPlayerTeamModel();
if (teamNumber == TEAM_JINRAI || teamNumber == TEAM_NSF)
{
RequestSetLoadout(m_iLoadoutWepChoice);
SetViewOffset(VEC_VIEW_NEOSCALE(this));
}
if (teamNumber == TEAM_UNASSIGNED && gpGlobals->eLoadType != MapLoad_Background)
{
int forcedTeam = NEORules()->GetForcedTeam();
if (NEORules()->GetForcedTeam() < 1) // don't let this loop infinitely if forcedTeam set to TEAM_UNASSIGNED
{
engine->ClientCommand(this->edict(), "teammenu");
return;
}
ChangeTeam(forcedTeam);
if (NEORules()->GetForcedClass() < 0)
{
engine->ClientCommand(this->edict(), "classmenu");
return;
}
m_iNeoClass = NEORules()->GetForcedClass();
if (NEORules()->GetForcedWeapon() < 0)
{
engine->ClientCommand(this->edict(), "loadoutmenu");
return;
}
m_iLoadoutWepChoice = NEORules()->GetForcedWeapon();
respawn(this, false);
}
ResetBotCommandState();
m_iBotDetectableBleedingInjuryEvents = 0;
}
extern ConVar neo_lean_angle;
ConVar neo_lean_thirdperson_roll_lerp_scale("neo_lean_thirdperson_roll_lerp_scale", "5",
FCVAR_REPLICATED | FCVAR_CHEAT, "Multiplier for 3rd person lean roll lerping.", true, 0.0, false, 0);
//just need to calculate lean angle in here
void CNEO_Player::Lean(void)
{
auto vm = static_cast<CNEOPredictedViewModel*>(GetViewModel());
if (vm)
{
Assert(GetBaseAnimating());
GetBaseAnimating()->SetBoneController(0, vm->lean(this));
}
}
void CNEO_Player::CheckVisionButtons()
{
if (m_iNeoClass == NEO_CLASS_VIP)
return;
if (gpGlobals->tickcount - m_nVisionLastTick < TIME_TO_TICKS(0.1f))
{
return;
}
if (m_afButtonPressed & IN_VISION)
{
if (IsAlive())
{
m_nVisionLastTick = gpGlobals->tickcount;
m_bInVision = !m_bInVision;
if (m_bInVision)
{
CRecipientFilter filter;
// NEO TODO/FIXME (Rain): optimise this loop to once per cycle instead of repeating for each client
for (int i = 1; i <= gpGlobals->maxClients; ++i)
{
if (edict()->m_EdictIndex == i)
{
continue;
}
auto player = UTIL_PlayerByIndex(i);
if (!player || !player->IsDead() || player->GetObserverMode() != OBS_MODE_IN_EYE)
{
continue;
}
if (player->GetObserverTarget() == this)
{
filter.AddRecipient(player);
}
}
if (filter.GetRecipientCount() > 0)
{
static int visionToggle = CBaseEntity::PrecacheScriptSound("NeoPlayer.VisionOn");
EmitSound_t params;
params.m_bEmitCloseCaption = false;
params.m_hSoundScriptHandle = visionToggle;
params.m_pOrigin = &GetAbsOrigin();
params.m_nChannel = CHAN_ITEM;
EmitSound(filter, edict()->m_EdictIndex, params);
}
}
}
}
}
void CNEO_Player::CheckLeanButtons()
{
if (!IsAlive() || GetFlags() & FL_FROZEN)
{
return;
}
m_bInLean = NEO_LEAN_NONE;
if ((m_nButtons & IN_LEAN_LEFT) && !(m_nButtons & IN_LEAN_RIGHT || IsSprinting()))
{
m_bInLean = NEO_LEAN_LEFT;
}
else if ((m_nButtons & IN_LEAN_RIGHT) && !(m_nButtons & IN_LEAN_LEFT || IsSprinting()))
{
m_bInLean = NEO_LEAN_RIGHT;
}
}
void CNEO_Player::CalculateSpeed(void)
{
float speed = GetNormSpeed();
if (auto pNeoWep = static_cast<CNEOBaseCombatWeapon*>(GetActiveWeapon()))
{
speed *= pNeoWep->GetSpeedScale();
}
if (GetFlags() & FL_DUCKING)
{
speed *= NEO_CROUCH_WALK_MODIFIER;
}
if (m_nButtons & IN_WALK)
{
speed *= NEO_CROUCH_WALK_MODIFIER; // They stack
}
if (IsSprinting())
{
switch (m_iNeoClass) {
case NEO_CLASS_RECON:
speed *= NEO_RECON_SPRINT_MODIFIER;
break;
case NEO_CLASS_ASSAULT:
case NEO_CLASS_VIP:
case NEO_CLASS_JUGGERNAUT:
speed *= NEO_ASSAULT_SPRINT_MODIFIER;
break;
case NEO_CLASS_SUPPORT:
speed *= NEO_SUPPORT_SPRINT_MODIFIER; // Should never happen
break;
default:
break;
}
}
if (IsInAim())
{
speed *= NEO_AIM_MODIFIER;
}
speed = MAX(speed, 55);
// Slowdown after jumping
if (m_iNeoClass != NEO_CLASS_RECON)
{
const float timeSinceJumping = gpGlobals->curtime - m_flJumpLastTime;
constexpr float SLOWDOWN_TIME = 1.15f;
if (timeSinceJumping < SLOWDOWN_TIME)
{
speed = MAX(75, speed * (1 - ((SLOWDOWN_TIME - timeSinceJumping) * 1.75)));
}
}
SetMaxSpeed(speed);
}
void CNEO_Player::HandleSpeedChangesLegacy()
{
int buttonsChanged = m_afButtonPressed | m_afButtonReleased;
bool bCanSprint = CanSprint();
bool bIsSprinting = IsSprinting();
#ifdef NEO
constexpr float MOVING_SPEED_MINIMUM = 0.5f; // NEOTODO (Adam) This is the same value as defined in cbaseanimating, should we be using the same value? Should we import it here?
bool bWantSprint = (bCanSprint && IsSuitEquipped() && (m_nButtons & IN_SPEED) && GetLocalVelocity().IsLengthGreaterThan(MOVING_SPEED_MINIMUM));
#else
bool bWantSprint = ( bCanSprint && IsSuitEquipped() && (m_nButtons & IN_SPEED) && (m_nButtons & (IN_FORWARD | IN_BACK | IN_MOVELEFT | IN_MOVERIGHT)));
#endif
#ifdef NEO
if ( bIsSprinting != bWantSprint && ((m_nButtons & IN_SPEED) || buttonsChanged & IN_SPEED))
#else
if ( bIsSprinting != bWantSprint && (buttonsChanged & IN_SPEED) )
#endif
{
// 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;
}
}
#ifdef NEO
if (bIsSprinting && GetLocalVelocity().IsLengthLessThan(MOVING_SPEED_MINIMUM))
#else
if (bIsSprinting && !(m_nButtons & (IN_FORWARD | IN_BACK | IN_MOVELEFT | IN_MOVERIGHT)))
#endif
{
StopSprinting();
}
bool bIsWalking = IsWalking();
// have suit, pressing button, not sprinting
bool bWantWalking;
if( IsSuitEquipped() )
{
bWantWalking = (m_nButtons & IN_WALK) && !IsSprinting();
}
else
{
bWantWalking = true;
}
if( bIsWalking != bWantWalking )
{
if ( bWantWalking )
{
StartWalking();
}
else
{
StopWalking();
}
}
}
#if 0
void CNEO_Player::HandleSpeedChanges( CMoveData *mv )
{
int nChangedButtons = mv->m_nButtons ^ mv->m_nOldButtons;
bool bJustPressedSpeed = !!( nChangedButtons & IN_SPEED );
#ifdef NEO
constexpr float MOVING_SPEED_MINIMUM = 0.5f; // NEOTODO (Adam) This is the same value as defined in cbaseanimating, should we be using the same value? Should we import it here?
const bool bWantSprint = ( CanSprint() && IsSuitEquipped() && ( mv->m_nButtons & IN_SPEED ) && GetLocalVelocity().IsLengthGreaterThan(MOVING_SPEED_MINIMUM));
#else
const bool bWantSprint = ( CanSprint() && IsSuitEquipped() && ( mv->m_nButtons & IN_SPEED ) );
#endif
#ifdef NEO
const bool bWantsToChangeSprinting = ( IsSprinting() != bWantSprint ) && ((mv->m_nButtons & IN_SPEED) || (( nChangedButtons & IN_SPEED ) != 0));
#else
const bool bWantsToChangeSprinting = ( m_HL2Local.m_bNewSprinting != bWantSprint ) && ( nChangedButtons & IN_SPEED ) != 0;
#endif
bool bSprinting = IsSprinting();
if ( bWantsToChangeSprinting )
{
if ( bWantSprint )
{
#ifdef NEO
if ( m_HL2Local.m_flSuitPower < SPRINT_START_MIN )
#else