-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathasw_player.cpp
More file actions
3778 lines (3300 loc) · 109 KB
/
Copy pathasw_player.cpp
File metadata and controls
3778 lines (3300 loc) · 109 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
//========= Copyright © 1996-2001, Valve LLC, All rights reserved. ============
//
// Purpose: Player for Swarm. This is an invisible entity that doesn't move, representing the commander.
// The player drives movement of CASW_Marine NPC entities
//
// $NoKeywords: $
//=============================================================================
#include "cbase.h"
#include "asw_player.h"
#include "in_buttons.h"
#include "asw_gamerules.h"
#include "asw_marine_resource.h"
#include "asw_marine.h"
#include "asw_marine_speech.h"
#include "asw_marine_profile.h"
#include "asw_spawner.h"
#include "asw_alien.h"
#include "asw_simple_alien.h"
#include "asw_pickup.h"
#include "asw_use_area.h"
#include "asw_button_area.h"
#include "asw_weapon.h"
#include "asw_ammo.h"
#include "asw_weapon_parse.h"
#include "asw_computer_area.h"
#include "asw_hack.h"
#include "asw_point_camera.h"
#include "ai_waypoint.h"
#include "inetchannelinfo.h"
#include "asw_sentry_base.h"
#include "asw_shareddefs.h"
#include "iasw_vehicle.h"
#include "obstacle_pushaway.h"
#include "SoundEmitterSystem/isoundemittersystembase.h"
#include "asw_door.h"
#include "asw_remote_turret_shared.h"
#include "asw_weapon_medical_satchel_shared.h"
#include "Sprite.h"
#include "physics_prop_ragdoll.h"
#include "asw_util_shared.h"
#include "asw_campaign_save.h"
#include "gib.h"
#include "asw_intro_control.h"
#include "asw_weapon_ammo_bag_shared.h"
#include "ai_network.h"
#include "ai_navigator.h"
#include "ai_node.h"
#include "datacache/imdlcache.h"
#include "asw_spawn_manager.h"
#include "sendprop_priorities.h"
#include "asw_deathmatch_mode.h"
#include "asw_trace_filter.h"
#include "env_tonemap_controller.h"
#include "fogvolume.h"
#include "missionchooser/iasw_mission_chooser.h"
#include "missionchooser/iasw_mission_chooser_source.h"
#include "rd_vgui_vscript_shared.h"
#include "rd_crafting_defs.h"
#include <algorithm>
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
#define ASW_PLAYER_MODEL "models/swarm/marine/Marine.mdl"
//#define MARINE_ORDER_DISTANCE 500
#define MARINE_ORDER_DISTANCE 32000
ConVar asw_client_chatter_enabled("asw_client_chatter_enabled", "1", FCVAR_NONE, "If zero cl_chatter is played only for the player who issued the command");
ConVar asw_blend_test_scale("asw_blend_test_scale", "0.1f", FCVAR_CHEAT);
ConVar asw_debug_pvs( "asw_debug_pvs", "0", FCVAR_CHEAT );
extern ConVar asw_rts_controls;
extern ConVar asw_DebugAutoAim;
extern ConVar asw_debug_marine_damage;
extern ConVar rd_respawn_time;
extern ConVar asw_default_campaign;
extern ConVar rd_lock_onslaught;
extern ConVar rd_lock_hardcoreff;
extern ConVar rd_lock_challenge;
extern ConVar rd_add_index_to_name;
ConVar rm_welcome_message("rm_welcome_message", "", FCVAR_NONE, "This message is displayed to a player after they join the game");
ConVar rm_welcome_message_delay("rm_welcome_message_delay", "10", FCVAR_NONE, "The number of seconds the welcome message is delayed.", true, 0, true, 30);
ConVar rd_kick_inactive_players( "rd_kick_inactive_players", "0", FCVAR_NONE, "If positive, kick players who are inactive for this many seconds." );
ConVar rd_kick_inactive_players_warning( "rd_kick_inactive_players_warning", "0.8", FCVAR_NONE, "Warn players that they will be kicked after this fraction of the inactive time.", true, 0, true, 1 );
ConVar rd_force_all_marines_in_pvs( "rd_force_all_marines_in_pvs", "3", FCVAR_NONE, "Send information about objects near all marines to all players. Helps record more complete demos, but increases memory and bandwidth usage. 2=only for spectators, 3=only for players with rd_auto_record_lobbies enabled" );
ConVar rd_throttle_inventory_counter_updates( "rd_throttle_inventory_counter_updates", "60", FCVAR_NONE, "Only update inventory item counters once every this many seconds to save bandwidth. Staggered per player." );
static const char* s_pWelcomeMessageContext = "WelcomeMessageDelayedContext";
// -------------------------------------------------------------------------------- //
// Player animation event. Sent to the client when a player fires, jumps, reloads, etc..
// -------------------------------------------------------------------------------- //
class CTEPlayerAnimEvent : public CBaseTempEntity
{
public:
DECLARE_CLASS( CTEPlayerAnimEvent, CBaseTempEntity );
DECLARE_SERVERCLASS();
CTEPlayerAnimEvent( const char *name ) : CBaseTempEntity( name )
{
}
CNetworkHandle( CBasePlayer, m_hPlayer );
CNetworkVar( int, m_iEvent );
};
IMPLEMENT_SERVERCLASS_ST_NOBASE( CTEPlayerAnimEvent, DT_TEPlayerAnimEvent )
SendPropEHandle( SENDINFO( m_hPlayer ) ),
SendPropInt( SENDINFO( m_iEvent ), Q_log2( PLAYERANIMEVENT_COUNT ) + 1, SPROP_UNSIGNED ),
END_SEND_TABLE()
static CTEPlayerAnimEvent g_TEPlayerAnimEvent( "PlayerAnimEvent" );
void TE_PlayerAnimEvent( CBasePlayer *pPlayer, PlayerAnimEvent_t event )
{
CPVSFilter filter( (const Vector&) pPlayer->EyePosition() );
// The player himself doesn't need to be sent his animation events
// unless cs_showanimstate wants to show them.
//if ( asw_showanimstate.GetInt() == pPlayer->entindex() )
//{
//filter.RemoveRecipient( pPlayer );
//}
g_TEPlayerAnimEvent.m_hPlayer = pPlayer;
g_TEPlayerAnimEvent.m_iEvent = event;
g_TEPlayerAnimEvent.Create( filter, 0 );
}
// -------------------------------------------------------------------------------- //
// Marine animation event.
// -------------------------------------------------------------------------------- //
class CTEMarineAnimEvent : public CBaseTempEntity
{
public:
DECLARE_CLASS( CTEMarineAnimEvent, CBaseTempEntity );
DECLARE_SERVERCLASS();
CTEMarineAnimEvent( const char *name ) : CBaseTempEntity( name )
{
}
CNetworkHandle( CBasePlayer, m_hExcludePlayer );
CNetworkHandle( CASW_Marine, m_hMarine );
CNetworkVar( int, m_iEvent );
};
IMPLEMENT_SERVERCLASS_ST_NOBASE( CTEMarineAnimEvent, DT_TEMarineAnimEvent )
SendPropEHandle( SENDINFO( m_hMarine ) ),
SendPropEHandle( SENDINFO( m_hExcludePlayer ) ),
SendPropInt( SENDINFO( m_iEvent ), Q_log2( PLAYERANIMEVENT_COUNT ) + 1, SPROP_UNSIGNED ),
END_SEND_TABLE()
static CTEMarineAnimEvent g_TEMarineAnimEvent( "MarineAnimEvent" );
void TE_MarineAnimEvent( CASW_Marine *pMarine, PlayerAnimEvent_t event )
{
CPVSFilter filter( (const Vector&) pMarine->EyePosition() );
g_TEMarineAnimEvent.m_hMarine = pMarine;
g_TEMarineAnimEvent.m_hExcludePlayer = NULL;
g_TEMarineAnimEvent.m_iEvent = event;
g_TEMarineAnimEvent.Create( filter, 0 );
}
void TE_MarineAnimEventExceptCommander( CASW_Marine *pMarine, PlayerAnimEvent_t event )
{
if (!pMarine)
return;
CPVSFilter filter( (const Vector&) pMarine->EyePosition() );
if (pMarine->GetCommander() && pMarine->IsInhabited())
g_TEMarineAnimEvent.m_hExcludePlayer = pMarine->GetCommander();
else
g_TEMarineAnimEvent.m_hExcludePlayer = NULL;
//filter.RemoveRecipient(pMarine->GetCommander());
g_TEMarineAnimEvent.m_hMarine = pMarine;
g_TEMarineAnimEvent.m_iEvent = event;
g_TEMarineAnimEvent.Create( filter, 0 );
}
// NOTE: This animevent won't get recorded in demos properly, since it's not sent to everyone!
void TE_MarineAnimEventJustCommander( CASW_Marine *pMarine, PlayerAnimEvent_t event )
{
if (!pMarine || !pMarine->IsInhabited())
return;
if (!pMarine->GetCommander())
return;
CRecipientFilter filter;
filter.RemoveAllRecipients();
filter.AddRecipient(pMarine->GetCommander());
g_TEMarineAnimEvent.m_hExcludePlayer = NULL;
g_TEMarineAnimEvent.m_hMarine = pMarine;
g_TEMarineAnimEvent.m_iEvent = event;
g_TEMarineAnimEvent.Create( filter, 0 );
}
// -------------------------------------------------------------------------------- //
// Tables.
// -------------------------------------------------------------------------------- //
LINK_ENTITY_TO_CLASS( player, CASW_Player );
PRECACHE_REGISTER(player);
IMPLEMENT_SERVERCLASS_ST( CASW_Player, DT_ASW_Player )
SendPropExclude( "DT_BaseAnimating", "m_flPoseParameter" ),
SendPropExclude( "DT_BaseAnimating", "m_flPlaybackRate" ),
SendPropExclude( "DT_BaseAnimating", "m_nSequence" ),
SendPropExclude( "DT_BaseEntity", "m_angRotation" ),
SendPropExclude( "DT_BaseAnimatingOverlay", "overlay_vars" ),
// cs_playeranimstate and clientside animation takes care of these on the client
SendPropExclude( "DT_ServerAnimationData", "m_flCycle" ),
SendPropExclude( "DT_AnimTimeMustBeFirst", "m_flAnimTime" ),
SendPropQAngles( SENDINFO( m_angEyeAngles ), 10, SPROP_CHANGES_OFTEN, SendProxy_QAngles, SENDPROP_PLAYER_EYE_ANGLES_PRIORITY ),
SendPropEHandle( SENDINFO( m_hInhabiting ) ),
SendPropEHandle( SENDINFO( m_hSpectating ) ),
SendPropInt( SENDINFO( m_iSpectatorIndexes ) ),
SendPropFloat( SENDINFO( m_fMarineDeathTime ) ),
SendPropEHandle( SENDINFO( m_hOrderingMarine ) ),
SendPropEHandle( SENDINFO( m_pCurrentInfoMessage ) ),
SendPropInt( SENDINFO( m_iLeaderVoteIndex ) ),
SendPropInt( SENDINFO( m_iKickVoteIndex ) ),
SendPropFloat( SENDINFO( m_fMapGenerationProgress ) ),
SendPropTime( SENDINFO( m_flUseKeyDownTime ) ),
SendPropEHandle( SENDINFO( m_hUseKeyDownEnt ) ),
SendPropFloat( SENDINFO( m_flMovementAxisYaw ) ),
SendPropInt( SENDINFO( m_nChangingMR ) ),
SendPropInt( SENDINFO( m_nChangingSlot ) ),
SendPropInt( SENDINFO( m_iMapVoted ) ),
SendPropInt( SENDINFO( m_iNetworkedXP ) ),
SendPropInt( SENDINFO( m_iNetworkedPromotion ) ),
SendPropInt( SENDINFO( m_iScreenWidthHeight ) ),
SendPropInt( SENDINFO( m_iMouseXY ), -1, SPROP_CHANGES_OFTEN ),
SendPropBool( SENDINFO( m_bSentJoinedMessage ) ),
SendPropQAngles( SENDINFO( m_angMarineAutoAimFromClient ), 10, SPROP_CHANGES_OFTEN ),
SendPropFloat( SENDINFO( m_flInactiveKickWarning ) ),
SendPropDataTable( SENDINFO_DT( m_EquippedItemData ), &REFERENCE_SEND_TABLE( DT_RD_ItemInstances_Player ) ),
SendPropInt( SENDINFO( m_iChallengeScratch ) ),
END_SEND_TABLE()
BEGIN_DATADESC( CASW_Player )
DEFINE_FIELD( m_fIsWalking, FIELD_BOOLEAN ),
DEFINE_FIELD( m_vecLastMarineOrigin, FIELD_VECTOR ),
DEFINE_FIELD( m_hInhabiting, FIELD_EHANDLE ),
DEFINE_FIELD( m_hSpectating, FIELD_EHANDLE ),
DEFINE_FIELD( m_iSpectatorIndexes, FIELD_INTEGER ),
DEFINE_FIELD( m_vecStoredPosition, FIELD_VECTOR ),
DEFINE_FIELD( m_pCurrentInfoMessage, FIELD_EHANDLE ),
DEFINE_FIELD( m_iUseEntities, FIELD_INTEGER ),
DEFINE_AUTO_ARRAY( m_hUseEntities, FIELD_EHANDLE ),
DEFINE_FIELD( m_fBlendAmount, FIELD_FLOAT ),
DEFINE_FIELD( m_angEyeAngles, FIELD_VECTOR ),
DEFINE_FIELD( m_iLeaderVoteIndex, FIELD_INTEGER ),
DEFINE_FIELD( m_iKickVoteIndex, FIELD_INTEGER ),
DEFINE_FIELD( m_iKLVotesStarted, FIELD_INTEGER ),
DEFINE_FIELD( m_fLastKLVoteTime, FIELD_TIME ),
DEFINE_FIELD( m_hOrderingMarine, FIELD_EHANDLE ),
DEFINE_FIELD( m_vecFreeCamOrigin, FIELD_VECTOR ),
DEFINE_FIELD( m_bUsedFreeCam, FIELD_BOOLEAN ),
DEFINE_FIELD( m_bSentJoinedMessage, FIELD_BOOLEAN ),
DEFINE_FIELD( m_iMapVoted, FIELD_INTEGER ),
DEFINE_FIELD( m_fLastControlledMarineTime, FIELD_TIME ),
DEFINE_FIELD( m_vecCrosshairTracePos, FIELD_VECTOR ),
DEFINE_ARRAY( m_iScreenWidthHeight, FIELD_SHORT, 2 ),
DEFINE_ARRAY( m_iMouseXY, FIELD_SHORT, 2 ),
DEFINE_FIELD( m_angMarineAutoAimFromClient, FIELD_VECTOR ),
DEFINE_FIELD( m_flLastActiveTime, FIELD_TIME ),
DEFINE_FIELD( m_flInactiveKickWarning, FIELD_TIME ),
DEFINE_FIELD( m_iChallengeScratch, FIELD_INTEGER ),
END_DATADESC()
BEGIN_ENT_SCRIPTDESC( CASW_Player, CBasePlayer, "The player entity." )
DEFINE_SCRIPTFUNC( ResurrectMarine, "Resurrect the marine" )
DEFINE_SCRIPTFUNC_NAMED( ScriptGetNPC, "GetNPC", "Returns entity the player is inhabiting" )
DEFINE_SCRIPTFUNC_NAMED( ScriptGetSpectatingNPC, "GetSpectatingNPC", "Returns entity the player is spectating" )
DEFINE_SCRIPTFUNC_NAMED( ScriptSetNPC, "SetNPC", "Force the player to inhabit an NPC" )
DEFINE_SCRIPTFUNC_NAMED( ScriptSetSpectatingNPC, "SetSpectatingNPC", "Force the player to spectate an NPC" )
DEFINE_SCRIPTFUNC_NAMED( ScriptGetViewNPC, "GetViewNPC", "Returns entity the player is spectating, else will return inhabiting entity" )
DEFINE_SCRIPTFUNC_NAMED( ScriptGetMarine, "GetMarine", "Returns the marine the player is commanding" )
DEFINE_SCRIPTFUNC_NAMED( ScriptFindPickerEntity, "FindPickerEntity", "Finds the nearest entity in front of the player" )
DEFINE_SCRIPTFUNC( GetCrosshairTracePos, "Returns the world location directly beneath the player's crosshair" )
DEFINE_SCRIPTFUNC_NAMED( ScriptShowMenu, "ShowMenu", "Show a menu with up to 10 options." )
END_SCRIPTDESC()
static const float s_flPlayerItemUpdateOffset[ABSOLUTE_PLAYER_LIMIT]
{
0.0f, 0.5f, 0.25f, 0.75f, 0.125f, 0.625f, 0.375f, 0.875f, 0.0625f, 0.5625f,
0.3125f, 0.8125f, 0.1875f, 0.6875f, 0.4375f, 0.9375f, 0.03125f, 0.53125f,
0.28125f, 0.78125f, 0.15625f, 0.65625f, 0.40625f, 0.90625f, 0.09375f,
0.59375f, 0.34375f, 0.84375f, 0.21875f, 0.71875f, 0.46875f, 0.96875f,
0.015625f, 0.515625f, 0.265625f, 0.765625f, 0.140625f, 0.640625f,
0.390625f, 0.890625f, 0.078125f, 0.578125f, 0.328125f, 0.828125f,
0.203125f, 0.703125f, 0.453125f, 0.953125f, 0.046875f, 0.546875f,
0.296875f, 0.796875f, 0.171875f, 0.671875f, 0.421875f, 0.921875f,
0.109375f, 0.609375f, 0.359375f, 0.859375f, 0.234375f, 0.734375f,
0.484375f, 0.984375f,
};
// -------------------------------------------------------------------------------- //
void ASW_GetNumAIAwake(const char* szClass, int &iAwake, int &iAsleep, int &iNormal, int &iEfficient, int &iVEfficient, int &iSEfficient, int &iDormant)
{
CBaseEntity* pEntity = NULL;
iAwake = 0;
iAsleep = 0;
iNormal = iEfficient = iVEfficient = iSEfficient = iDormant = 0;
while ((pEntity = gEntList.FindEntityByClassname( pEntity, szClass )) != NULL)
{
CAI_BaseNPC* pAI = pEntity->MyNPCPointer();
if (pAI)
{
if (pAI->GetEfficiency() == AIE_NORMAL)
iNormal++;
else if (pAI->GetEfficiency() == AIE_EFFICIENT)
iEfficient++;
else if (pAI->GetEfficiency() == AIE_VERY_EFFICIENT)
iVEfficient++;
else if (pAI->GetEfficiency() == AIE_SUPER_EFFICIENT)
iSEfficient++;
else if (pAI->GetEfficiency() == AIE_DORMANT)
iDormant++;
if (pAI->GetSleepState() == AISS_AWAKE)
iAwake++;
else
iAsleep++;
}
else
{
CASW_Simple_Alien *pSimple = dynamic_cast<CASW_Simple_Alien*>(pEntity);
if (pSimple)
{
if (!pSimple->m_bSleeping)
iAwake++;
else
iAsleep++;
}
}
}
}
void ASW_DrawAwakeAI()
{
int iAwake = 0;
int iAsleep = 0;
int iDormant = 0;
int iEfficient = 0;
int iVEfficient = 0;
int iSEfficient = 0;
int iNormal = 0;
int nprintIndex = 18;
engine->Con_NPrintf( nprintIndex, "AI (awake/asleep) (normal/efficient/very efficient/super efficient/dormant)");
nprintIndex++;
engine->Con_NPrintf( nprintIndex, "================================");
nprintIndex++;
for ( int i = 0; i < ASWSpawnManager()->GetNumAlienClasses(); i++ )
{
ASW_GetNumAIAwake( ASWSpawnManager()->GetAlienClass( i )->m_pszAlienClass, iAwake, iAsleep, iNormal, iEfficient, iVEfficient, iSEfficient, iDormant);
engine->Con_NPrintf( nprintIndex, "%s: (%d / %d) (%d / %d / %d / %d / %d)\n", ASWSpawnManager()->GetAlienClass( i )->m_pszAlienClass, iAwake, iAsleep, iNormal, iEfficient, iVEfficient, iSEfficient, iDormant );
nprintIndex++;
}
}
ConVar asw_draw_awake_ai( "asw_draw_awake_ai", "0", FCVAR_CHEAT, "Lists how many of each AI are awake");
CBaseEntity *CASW_Player::spawn_point = NULL;
CASW_Player::CASW_Player()
{
m_PlayerAnimState = CreatePlayerAnimState(this, this, LEGANIM_9WAY, false);
UseClientSideAnimation();
m_angEyeAngles.Init();
SetViewOffset( ASW_PLAYER_VIEW_OFFSET );
m_iKickVoteIndex = -1;
m_iLeaderVoteIndex = -1;
m_hInhabiting = NULL;
m_hSpectating = NULL;
m_pCurrentInfoMessage = NULL;
m_vecLastMarineOrigin = vec3_origin;
m_bLastAttackButton= false;
m_bLastAttack2Button= false;
m_fLastAICountTime = 0;
m_bAutoReload = true;
m_hUseKeyDownEnt = NULL;
m_flUseKeyDownTime = 0.0f;
m_flMovementAxisYaw = 90.0f;
m_fMarineDeathTime = 0.0f;
m_Local.m_vecPunchAngle.Set( ROLL, 15 );
m_Local.m_vecPunchAngle.Set( PITCH, 8 );
m_Local.m_vecPunchAngle.Set( YAW, 0 );
m_angMarineAutoAim = vec3_angle;
m_angMarineAutoAimFromClient = vec3_angle;
m_bPendingSteamStats = false;
m_flPendingSteamStatsStart = 0.0f;
m_bWelcomed = false;
if ( ASWGameRules() )
{
ASWGameRules()->ClearLeaderKickVotes( this );
if ( ASWGameRules()->GetGameState() == ASW_GS_INGAME )
{
SpectateNextMarine();
}
}
m_fLastFragTime = FLT_MIN;
m_iKillingSpree = 0;
m_iScreenWidthHeight = 0;
m_iMouseXY = 0;
m_bLeaderboardReady = false;
m_bSentJoinedMessage = false;
m_flLastActiveTime = 0.0f;
m_flInactiveKickWarning = 0.0f;
m_flNextItemCounterCommit = -1;
m_iWantsAutoRecord = 0;
m_iRecentMapVotesCount = 0;
m_fMapVoteCooldownEndTime = 0.0f;
m_fLastMapVoteTime = -1000.0f;
m_iChallengeScratch = 0;
}
CASW_Player::~CASW_Player()
{
m_PlayerAnimState->Release();
if ( ASWGameRules() )
ASWGameRules()->SetMaxMarines( this );
SetSpectatingNPC( NULL );
}
//------------------------------------------------------------------------------
// Purpose : Send even though we don't have a model
//------------------------------------------------------------------------------
int CASW_Player::UpdateTransmitState()
{
// ALWAYS transmit to all clients.
return SetTransmitState( FL_EDICT_ALWAYS );
}
CASW_Player *CASW_Player::CreatePlayer( const char *className, edict_t *ed )
{
CASW_Player::s_PlayerEdict = ed;
return (CASW_Player*)CreateEntityByName( className );
}
void CASW_Player::PreThink( void )
{
BaseClass::PreThink();
HandleSpeedChanges();
}
void CASW_Player::PostThink()
{
BaseClass::PostThink();
QAngle angles = GetLocalAngles();
if ( GetNPC() )
angles[PITCH] = 0;
SetLocalAngles( angles );
// Store the eye angles pitch so the client can compute its animation state correctly.
m_angEyeAngles = EyeAngles();
m_PlayerAnimState->Update( m_angEyeAngles[YAW], m_angEyeAngles[PITCH] );
// find nearby usable items
FindUseEntities();
if ( CanBeKicked() && rd_kick_inactive_players.GetFloat() > 0 )
{
float flInactiveFor = gpGlobals->curtime - m_flLastActiveTime;
float flInactiveRatio = flInactiveFor / rd_kick_inactive_players.GetFloat();
m_flInactiveKickWarning = flInactiveRatio >= rd_kick_inactive_players_warning.GetFloat() ? m_flLastActiveTime + rd_kick_inactive_players.GetFloat() : 0.0f;
if ( flInactiveRatio >= 1.0f )
{
engine->ServerCommand( CFmtStr( "kickid %d Disconnected due to inactivity\n", GetUserID() ) );
}
}
// clicking while ingame on mission with no marine makes us spectate the next marine
if ((!GetNPC() || GetNPC()->GetHealth()<=0)
/*&& !HasLiveMarines()*/ && ASWGameRules() && ASWGameRules()->GetGameState() == ASW_GS_INGAME)
{
//Msg("m_nButtons & IN_ATTACK = %d (m_Local.m_nOldButtons & IN_ATTACK) = %d\n", (m_nButtons & IN_ATTACK), (m_Local.m_nOldButtons & IN_ATTACK));
bool bClicked = (!m_bLastAttackButton && (m_nButtons & IN_ATTACK));
bool bRightClicked = (!m_bLastAttack2Button && (m_nButtons & IN_ALT1));
bool bJumpPressed = (!m_bLastAttackButton && (m_nButtons & IN_JUMP));
// for deathmatch we spectate after 1.5 sec and respawn marine on click
// after 5 seconds
if ( ASWDeathmatchMode() )
{
if ( bJumpPressed && gpGlobals->curtime > m_fMarineDeathTime + rd_respawn_time.GetFloat() )
{
ASWDeathmatchMode()->SpawnMarine( this );
}
else if ( !GetSpectatingNPC() && gpGlobals->curtime > m_fLastControlledMarineTime + 6.0f )
{
SpectateNextMarine();
m_fLastControlledMarineTime = gpGlobals->curtime - 5.0f; // set this again so we don't spam SpectateNextMarine
}
else if ( ( bClicked || bRightClicked ) && gpGlobals->curtime > m_fMarineDeathTime + 1.5f )
{
SpectateNextMarine();
}
}
else if ( bClicked && gpGlobals->curtime > m_fLastControlledMarineTime + 6.0f )
{
// riflemod: allow drop in
CASW_Game_Resource *pGameResource = ASWGameResource();
if ( !this->HasLiveMarines() && pGameResource )
{
bool found_available_marine = false;
CASW_Marine *pBotMarine = NULL;
if ( CASW_Marine::AsMarine( GetSpectatingNPC() ) && !GetSpectatingNPC()->IsInhabited() )
{
found_available_marine = true;
pBotMarine = CASW_Marine::AsMarine( GetSpectatingNPC() );
}
else
{
for ( int i = 0; i < pGameResource->GetMaxMarineResources(); i++ )
{
CASW_Marine_Resource* pMR = pGameResource->GetMarineResource( i );
if ( !pMR )
continue;
CASW_Marine *pMarine = pMR->GetMarineEntity();
if ( pMarine && !pMarine->IsInhabited() )
{
found_available_marine = true;
pBotMarine = pMarine;
break;
}
}
}
if (found_available_marine)
{
DevMsg(" Riflemod Drop-In. Switching player to marine 0\n");
SetSpectatingNPC( NULL );
pBotMarine->SetCommander( this );
pBotMarine->GetMarineResource()->SetCommander( this );
SwitchMarine( 0, false );
// reactivedrop: when player took marine under control
// delay his primary attack to prevent immediate shooting at
// unknown posisition which can kill teammates
pBotMarine->SetNextAttack( gpGlobals->curtime + 1.0f );
// reactivedrop: additionally check bots. If they have no
// commander then assign to this player
//
// This happens when the only one player on server plays with bots
// and goes asw_afk. When this player takes control over a bot
// all other bots are now assigned to this player. Previously
// they were assigned to nobody
for (int i = 0; i < pGameResource->GetMaxMarineResources(); ++i)
{
CASW_Marine_Resource* pMR = pGameResource->GetMarineResource( i );
if (!pMR || pMR->GetHealthPercent() <= 0)
continue;
if (pMR->GetCommander() == NULL)
pMR->SetCommander( this );
}
}
else
{
SpectateNextMarine();
}
}
}
else if ( bRightClicked || ( !GetSpectatingNPC() && gpGlobals->curtime > m_fLastControlledMarineTime + 6.0f ) )
{
// riflemod: right click when spectating cycles through marines
SpectateNextMarine();
}
}
else
{
m_fLastControlledMarineTime = gpGlobals->curtime;
}
m_bLastAttackButton = (m_nButtons & IN_ATTACK) != 0;
m_bLastAttack2Button= (m_nButtons & IN_ALT1) != 0;
RagdollBlendTest();
if (asw_draw_awake_ai.GetBool() && gpGlobals->curtime - m_fLastAICountTime > 2.0f)
{
ASW_DrawAwakeAI();
m_fLastAICountTime = gpGlobals->curtime;
}
bool bShouldCommitCounters = true;
if ( rd_throttle_inventory_counter_updates.GetFloat() > 0 )
{
bShouldCommitCounters = m_flNextItemCounterCommit <= gpGlobals->curtime;
if ( bShouldCommitCounters )
{
float flNext = gpGlobals->curtime;
flNext /= rd_throttle_inventory_counter_updates.GetFloat();
flNext += 1 - s_flPlayerItemUpdateOffset[entindex() - 1];
flNext = roundf( flNext );
flNext += s_flPlayerItemUpdateOffset[entindex() - 1];
flNext *= rd_throttle_inventory_counter_updates.GetFloat();
Assert( flNext > gpGlobals->curtime && flNext <= gpGlobals->curtime + rd_throttle_inventory_counter_updates.GetFloat() );
m_flNextItemCounterCommit = flNext;
}
}
if ( bShouldCommitCounters )
{
for ( int i = 0; i < RD_NUM_STEAM_INVENTORY_EQUIP_SLOTS_PLAYER; i++ )
{
m_EquippedItemData[i].CommitCounters();
}
}
}
CBaseEntity* CASW_Player::GetUseEntity(int i)
{
return m_hUseEntities[i];
}
void CASW_Player::Precache()
{
PrecacheModel( ASW_PLAYER_MODEL );
PrecacheModel( "models/swarm/OrderArrow/OrderArrow.mdl" );
// ASWTODO - precache the actual model set in asw_client_corpse.cpp rather than assuming this one
PrecacheModel( "models/swarm/colonist/male/malecolonist.mdl" );
PrecacheScriptSound( "noslow.BulletTimeIn" );
PrecacheScriptSound( "noslow.BulletTimeOut" );
PrecacheScriptSound( "noslow.SingleBreath" );
PrecacheScriptSound( "Game.ObjectiveComplete" );
PrecacheScriptSound( "Game.MissionWon" );
PrecacheScriptSound( "Game.MissionLost" );
PrecacheScriptSound( "asw_song.stims" );
//PrecacheScriptSound( "Holdout.GetReadySlide" );
//PrecacheScriptSound( "Holdout.GetReadySlam" );
PrecacheScriptSound( "asw_song.StatsSuccess" );
PrecacheScriptSound( "asw_song.StatsSuccessCampaign" );
PrecacheScriptSound( "asw_song.StatsFail" );
if (MarineProfileList())
{
MarineProfileList()->PrecacheSpeech(this);
}
else
{
Msg("Couldn't precache marine speech as profile list isn't created yet\n");
}
BaseClass::Precache();
}
void CASW_Player::Spawn()
{
SetModel( ASW_PLAYER_MODEL );
BaseClass::Spawn();
m_vecLastMarineOrigin = vec3_origin;
m_flMovementAxisYaw = 90.0f;
SetMoveType( MOVETYPE_WALK );
m_takedamage = DAMAGE_NO;
BecomeNonSolid();
m_bFirstInhabit = false;
m_bRequestedSpectator = false;
m_bPrintedWantStartMessage = false;
m_bPrintedWantsContinueMessage = false;
m_nChangingMR = -1;
m_nChangingSlot = 0;
m_bHasAwardedXP = false;
m_bSentPromotedMessage = false;
m_iSpectatorIndexes = 0;
m_flLastActiveTime = gpGlobals->curtime;
#ifdef RD_7A_DROPS
m_bCraftingMaterialsSent = false;
for ( int i = 0; i < RD_MAX_CRAFTING_MATERIAL_SPAWN_LOCATIONS; i++ )
{
m_CraftingMaterialType[i] = RD_CRAFTING_MATERIAL_NONE;
}
m_CraftingMaterialFound = 0;
m_CraftingMaterialInstances.Purge();
#endif
if (ASWGameRules())
{
ASWGameRules()->SetMaxMarines();
}
}
void CASW_Player::DoAnimationEvent( PlayerAnimEvent_t event )
{
TE_PlayerAnimEvent( this, event ); // Send to any clients who can see this guy.
}
CBaseCombatWeapon* CASW_Player::ASWAnim_GetActiveWeapon()
{
return GetActiveWeapon();
}
void CASW_Player::EmitPrivateSound( const char *soundName, bool bFromNPC )
{
CSoundParameters params;
if ( !GetParametersForSound( soundName, params, NULL ) )
return;
CSingleUserRecipientFilter filter( this );
if ( bFromNPC && GetNPC() )
{
EmitSound( filter, GetNPC()->entindex(), soundName );
}
else
{
EmitSound( filter, entindex(), soundName );
}
}
bool CASW_Player::ASWAnim_CanMove()
{
return true;
}
void CASW_Player::WelcomeMessageThink()
{
m_bWelcomed = true;
char buffer[512];
Q_snprintf(buffer, sizeof(buffer), rm_welcome_message.GetString());
ClientPrint(this, HUD_PRINTTALK, buffer);
SetContextThink(NULL, gpGlobals->curtime, s_pWelcomeMessageContext);
}
bool CASW_Player::ClientCommand( const CCommand &args )
{
const char *pcmd = args[0];
m_flLastActiveTime = gpGlobals->curtime;
switch ( ASWGameRules()->GetGameState() )
{
case ASW_GS_BRIEFING:
{
if ( FStrEq( pcmd, "cl_selectm" ) ) // selecting a marine from the roster
{
CASW_Game_Resource *pGameResource = ASWGameResource();
if (!pGameResource)
return false;
if ( args.ArgC() < 3 )
{
Warning( "Player %s sent bad cl_selectm command\n", GetASWNetworkID() );
return false;
}
int iRosterIndex = clamp(atoi( args[1] ), 0, ASW_NUM_MARINE_PROFILES-1);
int nPreferredSlot = atoi( args[2] );
if (CASW_Marine_Resource *pMR = ASWGameRules()->RosterSelect( this, iRosterIndex, nPreferredSlot ) )
{
// did they specify a previous inventory selection too?
if ( args.ArgC() == 9 )
{
m_bRequestedSpectator = false;
int primary = atoi( args[3] );
int secondary = atoi( args[4] );
int extra = atoi( args[5] );
// args[6], args[7], and args[8] are currently unused.
if ( primary != -1 )
ASWGameRules()->LoadoutSelect( pMR, ASW_INVENTORY_SLOT_PRIMARY, primary );
if ( secondary != -1 )
ASWGameRules()->LoadoutSelect( pMR, ASW_INVENTORY_SLOT_SECONDARY, secondary );
if ( extra != -1 )
ASWGameRules()->LoadoutSelect( pMR, ASW_INVENTORY_SLOT_EXTRA, extra );
}
}
return true;
}
else if ( FStrEq( pcmd, "cl_dselectm" ) ) // selecting a marine from the roster
{
if ( args.ArgC() < 2 )
{
Warning( "Player %s sent bad cl_dselectm command\n", GetASWNetworkID() );
return false;
}
if (!ASWGameRules())
return false;
int iRosterIndex = clamp(atoi( args[1] ), 0, ASW_NUM_MARINE_PROFILES-1);
ASWGameRules()->RosterDeselect(this, iRosterIndex);
return true;
}
else if ( FStrEq( pcmd, "cl_dselectallm" ) )
{
if ( !ASWGameRules() )
return false;
ASWGameRules()->RosterDeselectAll( this );
return true;
}
else if ( FStrEq( pcmd, "cl_revive" ) ) // revive all dead marines, leader only
{
if (ASWGameResource() && ASWGameResource()->GetLeader() == this && ASWGameRules())
{
ASWGameRules()->ReviveDeadMarines();
}
return true;
}
else if ( FStrEq( pcmd, "cl_wants_start" ) ) // print a message telling the other players that you want to start
{
if (ASWGameResource() && ASWGameResource()->GetLeader() == this && ASWGameRules() )
{
if (ASWGameRules()->GetGameState() == ASW_GS_BRIEFING)
{
if (!m_bPrintedWantStartMessage)
{
UTIL_ClientPrintAll( ASW_HUD_PRINTTALKANDCONSOLE, "#asw_wants_start", GetPlayerName() );
m_bPrintedWantStartMessage = true;
}
}
}
return true;
}
else if ( FStrEq( pcmd, "cl_loadouta" ) ) // selecting equipment
{
if ( args.ArgC() < 9 )
{
Warning( "Player %s sent bad loadouta command\n", GetASWNetworkID() );
return false;
}
int iProfileIndex = clamp( atoi( args[1] ), 0, ASW_NUM_MARINE_PROFILES - 1 );
int iMarineIndex = atoi( args[2] );
int iPrimary = atoi( args[3] );
int iSecondary = atoi( args[4] );
int iExtra = atoi( args[5] );
// args[6], args[7], and args[8] are currently unused.
if ( iMarineIndex == -1 )
{
for ( int i = 0; i < ASW_MAX_MARINE_RESOURCES; i++ )
{
CASW_Marine_Resource *pMarineResource = ASWGameResource()->GetMarineResource( i );
if ( pMarineResource && pMarineResource->GetCommander() == this && pMarineResource->GetProfileIndex() == iProfileIndex )
{
iMarineIndex = i;
break;
}
}
}
CASW_Marine_Resource *pMR = ASWGameResource()->GetMarineResource( iMarineIndex );
if ( !pMR || pMR->GetCommander() != this || pMR->GetProfileIndex() != iProfileIndex )
{
Warning( "Player sent bad loadouta command\n" );
return false;
}
if ( iPrimary >= 0 )
ASWGameRules()->LoadoutSelect( pMR, ASW_INVENTORY_SLOT_PRIMARY, iPrimary );
if ( iSecondary >= 0 )
ASWGameRules()->LoadoutSelect( pMR, ASW_INVENTORY_SLOT_SECONDARY, iSecondary );
if ( iExtra >= 0 )
ASWGameRules()->LoadoutSelect( pMR, ASW_INVENTORY_SLOT_EXTRA, iExtra );
return true;
}
else if ( FStrEq( pcmd, "cl_start" ) ) // done selecting, go ingame
{
// check if all players are ready, etc
BecomeNonSolid();
// send a message to client telling him to close the briefing
if (ASWGameRules())
{
ASWGameRules()->RequestStartMission(this);
}
return true;
}
else if ( FStrEq( pcmd, "cl_spendskill") )
{
if ( args.ArgC() < 3 )
{
Warning( "Player %s sent a bad cl_spendskill command\n", GetASWNetworkID() );
return false;
}
int iProfileIndex = atoi(args[1]);
int nSkillSlot = atoi(args[2]);
if (iProfileIndex < 0 || iProfileIndex >= ASW_NUM_MARINE_PROFILES )
return false;
if (nSkillSlot < 0 || nSkillSlot >= ASW_SKILL_SLOT_SPARE )
return false;
if (ASWGameRules() && ASWGameRules()->CanSpendPoint(this, iProfileIndex, nSkillSlot))
ASWGameRules()->SpendSkill(iProfileIndex, nSkillSlot);
return true;
}
else if ( FStrEq( pcmd, "cl_undoskill" ) )
{
if ( args.ArgC() < 2 )
{
Warning( "Player %s sent a bad cl_undoskill command\n", GetASWNetworkID() );
return false;
}
int iProfileIndex = atoi(args[1]);
if (iProfileIndex < 0 || iProfileIndex >= ASW_NUM_MARINE_PROFILES )
return false;
if (ASWGameRules())
ASWGameRules()->SkillsUndo(this, iProfileIndex);
return true;
}
else if ( FStrEq( pcmd, "cl_hardcore_ff") )
{
if ( args.ArgC() < 2 )
{
Warning( "Player %s sent a bad cl_hardcore_ff command\n", GetASWNetworkID() );
return false;
}
if ( ASWGameResource() && ASWGameResource()->GetLeader() == this && !rd_lock_hardcoreff.GetBool() )
{
bool bOldHardcoreMode = CAlienSwarm::IsHardcoreFF();
int nHardcore = atoi( args[1] );
nHardcore = clamp<int>( nHardcore, 0, 1 );
extern ConVar asw_sentry_friendly_fire_scale;
extern ConVar asw_marine_ff_absorption;
asw_sentry_friendly_fire_scale.SetValue( nHardcore );
asw_marine_ff_absorption.SetValue( 1 - nHardcore );
if ( CAlienSwarm::IsHardcoreFF() != bOldHardcoreMode )
{
CReliableBroadcastRecipientFilter filter;
filter.RemoveRecipient( this ); // notify everyone except the player changing the setting
if ( nHardcore > 0 )
{
UTIL_ClientPrintFilter( filter, ASW_HUD_PRINTTALKANDCONSOLE, "#asw_enabled_hardcoreff", GetPlayerName() );
}
else
{
UTIL_ClientPrintFilter( filter, ASW_HUD_PRINTTALKANDCONSOLE, "#asw_disabled_hardcoreff", GetPlayerName() );
}
}
}
return true;
}
else if ( FStrEq( pcmd, "rd_set_challenge" ) )
{
if ( args.ArgC() < 2 )
{
Warning( "Player %s sent a bad rd_set_challenge command\n", GetASWNetworkID() );
return false;
}
if ( ASWGameResource() && ASWGameResource()->GetLeader() == this && !rd_lock_challenge.GetBool() )
{
const char *szChallengeName = args[1];
if ( ASWGameRules() )
{