forked from hitmen047/Source-PlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathai_concommands.cpp
890 lines (765 loc) · 36.6 KB
/
ai_concommands.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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Console commands for debugging and manipulating NPCs.
//
//===========================================================================//
#include "cbase.h"
#include "ai_basenpc.h"
#include "player.h"
#include "entitylist.h"
#include "ai_network.h"
#include "ai_node.h"
#include "ai_link.h"
#include "ai_networkmanager.h"
#include "ndebugoverlay.h"
#include "datacache/imdlcache.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
extern CAI_Node* FindPickerAINode( CBasePlayer* pPlayer, NodeType_e nNodeType );
extern void SetDebugBits( CBasePlayer* pPlayer, const char *name, int bit );
extern CBaseEntity *FindPickerEntity( CBasePlayer *pPlayer );
extern bool g_bAIDisabledByUser;
//------------------------------------------------------------------------------
// Purpose: Disables all NPCs
//------------------------------------------------------------------------------
void CC_AI_Disable( void )
{
if (CAI_BaseNPC::m_nDebugBits & bits_debugDisableAI)
{
CAI_BaseNPC::m_nDebugBits &= ~bits_debugDisableAI;
DevMsg("AI Enabled.\n");
}
else
{
CAI_BaseNPC::m_nDebugBits |= bits_debugDisableAI;
DevMsg("AI Disabled.\n");
g_bAIDisabledByUser = true;
}
CBaseEntity::m_nDebugPlayer = UTIL_GetCommandClientIndex();
}
static ConCommand ai_disable("ai_disable", CC_AI_Disable, "Bi-passes all AI logic routines and puts all NPCs into their idle animations. Can be used to get NPCs out of your way and to test effect of AI logic routines on frame rate", FCVAR_CHEAT);
//------------------------------------------------------------------------------
// Purpose: Show hint nodes
//------------------------------------------------------------------------------
void CC_AI_ShowHints( void )
{
// Eventually this will be done by name when mulitple
// networks are used, but for now have one big AINet
//static char entName[256];
//Q_strncpy( entName, args[1],sizeof(entName) );
if ( !g_pAINetworkManager )
return;
g_pAINetworkManager->GetEditOps()->SetDebugBits("BigNet",bits_debugOverlayHints);
CBaseEntity::m_nDebugPlayer = UTIL_GetCommandClientIndex();
}
static ConCommand ai_show_hints("ai_show_hints", CC_AI_ShowHints, "Displays all hints as small boxes\n\tBlue - hint is available for use\n\tRed - hint is currently being used by an NPC\n\tOrange - hint not being used by timed out\n\tGrey - hint has been disabled", FCVAR_CHEAT);
//------------------------------------------------------------------------------
// Purpose: Show node connections with hulls
//------------------------------------------------------------------------------
void CC_AI_ShowHull( const CCommand &args )
{
// Eventually this will be done by name when mulitple
// networks are used, but for now have one big AINet
//static char entName[256];
//Q_strncpy( entName, args[1),sizeof(entName) );
g_pAINetworkManager->GetEditOps()->SetDebugBits("BigNet",bits_debugOverlayHulls);
CBaseEntity::m_nDebugPlayer = UTIL_GetCommandClientIndex();
}
static ConCommand ai_show_hull("ai_show_hull", CC_AI_ShowHull, "Displays the allowed hulls between each node for the currently selected hull type. Hulls are color code as follows:\n\tGreen - ground movement \n\tBlue - jumping movement\n\tCyan - flying movement\n\tMagenta - climbing movement\n\tArguments: -none-", FCVAR_CHEAT);
//------------------------------------------------------------------------------
// Purpose: Show node connections with lines
//------------------------------------------------------------------------------
void CC_AI_ShowConnect( const CCommand &args )
{
// Eventually this will be done by name when mulitple
// networks are used, but for now have one big AINet
//static char entName[256];
//Q_strncpy( entName, args[1],sizeof(entName) );
if ( !g_pAINetworkManager )
return;
g_pAINetworkManager->GetEditOps()->SetDebugBits("BigNet",bits_debugOverlayConnections);
CBaseEntity::m_nDebugPlayer = UTIL_GetCommandClientIndex();
}
static ConCommand ai_show_connect("ai_show_connect", CC_AI_ShowConnect, "Displays the allowed connections between each node for the currently selected hull type. Hulls are color code as follows:\n\tGreen - ground movement \n\tBlue - jumping movement\n\tCyan - flying movement\n\tMagenta - climbing movement\n\tRed - connection disabled", FCVAR_CHEAT);
//------------------------------------------------------------------------------
// Purpose: Show node connections with lines
//------------------------------------------------------------------------------
void CC_AI_ShowJumpConnect( const CCommand &args )
{
// Eventually this will be done by name when mulitple
// networks are used, but for now have one big AINet
//static char entName[256];
//Q_strncpy( entName, args[1],sizeof(entName) );
if ( !g_pAINetworkManager )
return;
g_pAINetworkManager->GetEditOps()->SetDebugBits("BigNet",bits_debugOverlayConnections);
g_pAINetworkManager->GetEditOps()->SetDebugBits("BigNet",bits_debugOverlayJumpConnections);
CBaseEntity::m_nDebugPlayer = UTIL_GetCommandClientIndex();
}
static ConCommand ai_show_connect_jump("ai_show_connect_jump", CC_AI_ShowJumpConnect, "Displays the allowed connections between each node for the currently selected hull type. Hulls are color code as follows:\n\tGreen - ground movement \n\tBlue - jumping movement\n\tCyan - flying movement\n\tMagenta - climbing movement\n\tRed - connection disabled", FCVAR_CHEAT);
//------------------------------------------------------------------------------
// Purpose: Show node connections with lines
//------------------------------------------------------------------------------
void CC_AI_ShowFlyConnect( const CCommand &args )
{
// Eventually this will be done by name when mulitple
// networks are used, but for now have one big AINet
//static char entName[256];
//Q_strncpy( entName, args[1],sizeof(entName) );
if ( !g_pAINetworkManager )
return;
g_pAINetworkManager->GetEditOps()->SetDebugBits("BigNet",bits_debugOverlayConnections);
g_pAINetworkManager->GetEditOps()->SetDebugBits("BigNet",bits_debugOverlayFlyConnections);
CBaseEntity::m_nDebugPlayer = UTIL_GetCommandClientIndex();
}
static ConCommand ai_show_connect_fly("ai_show_connect_fly", CC_AI_ShowFlyConnect, "Displays the allowed connections between each node for the currently selected hull type. Hulls are color code as follows:\n\tGreen - ground movement \n\tBlue - jumping movement\n\tCyan - flying movement\n\tMagenta - climbing movement\n\tRed - connection disabled", FCVAR_CHEAT);
//------------------------------------------------------------------------------
// Purpose: Draw a grid on the screen (good for laying down nodes)
//------------------------------------------------------------------------------
void CC_AI_ShowGrid( const CCommand &args )
{
// Eventually this will be done by name when mulitple
// networks are used, but for now have one big AINet
//static char entName[256];
//Q_strncpy( entName, args[1],sizeof(entName) );
if ( !g_pAINetworkManager )
return;
g_pAINetworkManager->GetEditOps()->SetDebugBits("BigNet",bits_debugOverlayGrid);
CBaseEntity::m_nDebugPlayer = UTIL_GetCommandClientIndex();
}
static ConCommand ai_show_grid("ai_show_grid", CC_AI_ShowGrid, "Draw a grid on the floor where looking.", FCVAR_CHEAT);
//------------------------------------------------------------------------------
// Purpose: NPC step trough AI
//------------------------------------------------------------------------------
void CC_AI_Step( void )
{
DevMsg("AI Stepping...\n");
// Start NPC's stepping through tasks
CAI_BaseNPC::m_nDebugBits |= bits_debugStepAI;
CAI_BaseNPC::m_nDebugPauseIndex++;
}
static ConCommand ai_step("ai_step", CC_AI_Step, "NPCs will freeze after completing their current task. To complete the next task, use 'ai_step' again. To resume processing normally use 'ai_resume'", FCVAR_CHEAT);
//------------------------------------------------------------------------------
// Purpose: Resume normal AI processing after stepping
//------------------------------------------------------------------------------
void CC_AI_Resume( void )
{
DevMsg("AI Resume...\n");
// End NPC's stepping through tasks
CAI_BaseNPC::m_nDebugBits &= ~bits_debugStepAI;
}
static ConCommand ai_resume("ai_resume", CC_AI_Resume, "If NPC is stepping through tasks (see ai_step ) will resume normal processing.", FCVAR_CHEAT);
//------------------------------------------------------------------------------
// Purpose: Switch to display of next hull type
//------------------------------------------------------------------------------
void CC_AI_NextHull( const CCommand &args )
{
// Eventually this will be done by name when mulitple
// networks are used, but for now have one big AINet
//static char entName[256];
//Q_strncpy( entName, args[1],sizeof(entName) );
if ( !g_pAINetworkManager )
return;
g_pAINetworkManager->GetEditOps()->DrawNextHull("BigNet");
CBaseEntity::m_nDebugPlayer = UTIL_GetCommandClientIndex();
}
static ConCommand ai_next_hull("ai_next_hull", CC_AI_NextHull, "Cycles through the various hull sizes. Currently selected hull size is written to the screen. Controls which connections are shown when ai_show_hull or ai_show_connect commands are used\n\tArguments: -none-", FCVAR_CHEAT);
//------------------------------------------------------------------------------
// Display the hull type of the specified NPC.
//------------------------------------------------------------------------------
void CC_AI_Hull( const CCommand &args )
{
if ( !g_pAINetworkManager )
return;
bool bSpawned = false;
CBaseEntity *pEnt = NULL;
if ( !args[1] || !args[1][0] )
{
// No arg means the entity under the crosshair.
pEnt = FindPickerEntity( UTIL_GetCommandClient() );
if ( !pEnt )
{
DevMsg( "No entity under the crosshair.\n" );
return;
}
}
else
{
// Find the entity specified on the command line.
pEnt = gEntList.FindEntityGeneric( NULL, args[1] );
if ( !pEnt )
{
// Not found, try to create one.
pEnt = (CAI_BaseNPC *)CreateEntityByName( args[1] );
if ( !pEnt )
{
DevMsg( "Entity %s not found, and couldn't create!\n", args[1] );
return;
}
bSpawned = true;
DispatchSpawn( pEnt );
}
}
CAI_BaseNPC *pNPC = dynamic_cast<CAI_BaseNPC *>( pEnt );
if ( !pNPC )
{
DevMsg( "Entity %s is not an NPC.\n", pEnt->GetDebugName() );
return;
}
Hull_t eHull = pNPC->GetHullType();
if ( bSpawned )
{
UTIL_Remove( pEnt );
}
g_pAINetworkManager->GetEditOps()->DrawHull( eHull );
CBaseEntity::m_nDebugPlayer = UTIL_GetCommandClientIndex();
}
static ConCommand ai_hull("ai_hull", CC_AI_Hull, "Controls which connections are shown when ai_show_hull or ai_show_connect commands are used\n\tArguments: NPC name or classname, <none>=NPC under crosshair", FCVAR_CHEAT);
//------------------------------------------------------------------------------
// Purpose: Show AI nodes
//------------------------------------------------------------------------------
void CC_AI_Nodes( const CCommand &args )
{
// Eventually this will be done by name when mulitple
// networks are used, but for now have one big AINet
// static char entName[256];
//Q_strncpy( entName, args[1],sizeof(entName) );
if ( !g_pAINetworkManager )
return;
g_pAINetworkManager->GetEditOps()->SetDebugBits("BigNet",bits_debugOverlayNodes);
CBaseEntity::m_nDebugPlayer = UTIL_GetCommandClientIndex();
}
static ConCommand ai_nodes("ai_nodes", CC_AI_Nodes, "Toggles node display. First call displays the nodes for the given network as green objects. Second call displays the nodes and their IDs. Nodes are color coded as follows:\n\tGreen - ground node\n\tCyan - air node\n\tMagenta - climb node\n\tGrey - node not available for selected hull size\n\tOrange - node currently locked", FCVAR_CHEAT);
CON_COMMAND(ai_show_node, "Highlight the specified node")
{
if ( args.ArgC() > 1 )
{
int node = atoi(args[1]);
CAI_Node* pAINode = g_pBigAINet->GetNode( node, false );
if ( pAINode )
{
NDebugOverlay::Cross3D(pAINode->GetOrigin(), 1024, 255, 255, 255, true, 5.0 );
}
}
}
//------------------------------------------------------------------------------
// Purpose: Show visibility from selected node to all other nodes
//------------------------------------------------------------------------------
void CC_AI_ShowVisibility( const CCommand &args )
{
// Eventually this will be done by name when mulitple
// networks are used, but for now have one big AINet
// static char entName[256];
//Q_strncpy( entName, args[1],sizeof(entName) );
if ( !g_pAINetworkManager )
return;
g_pAINetworkManager->GetEditOps()->SetDebugBits("BigNet",bits_debugOverlayVisibility);
CAI_Node* pAINode = FindPickerAINode(UTIL_GetCommandClient(), NODE_ANY);
if (pAINode != NULL)
{
g_pAINetworkManager->GetEditOps()->m_iVisibilityNode = pAINode->GetId();
}
else
{
g_pAINetworkManager->GetEditOps()->m_iVisibilityNode = NO_NODE;
}
CBaseEntity::m_nDebugPlayer = UTIL_GetCommandClientIndex();
}
static ConCommand ai_show_visibility("ai_show_visibility", CC_AI_ShowVisibility, "Toggles visibility display for the node that the player is looking at. Nodes that are visible from the selected node will be drawn in red with yellow lines connecting to the selected node. Nodes that are not visible from the selected node will be drawn in blue.", FCVAR_CHEAT);
//------------------------------------------------------------------------------
// Purpose: Show what nodes the selected node is connected to using the
// netowrk graph
//------------------------------------------------------------------------------
void CC_AI_GraphConnect( const CCommand &args )
{
if ( !g_pAINetworkManager )
return;
// Eventually this will be done by name when mulitple
// networks are used, but for now have one big AINet
//static char entName[256];
//Q_strncpy( entName, args[1],sizeof(entName) );
g_pAINetworkManager->GetEditOps()->SetDebugBits("BigNet",bits_debugOverlayGraphConnect);
CAI_Node* pAINode = FindPickerAINode(UTIL_GetCommandClient(), NODE_ANY);
if (pAINode != NULL)
{
g_pAINetworkManager->GetEditOps()->m_iGConnectivityNode = pAINode->GetId();
}
else
{
g_pAINetworkManager->GetEditOps()->m_iGConnectivityNode = NO_NODE;
}
CBaseEntity::m_nDebugPlayer = UTIL_GetCommandClientIndex();
}
static ConCommand ai_show_graph_connect("ai_show_graph_connect", CC_AI_GraphConnect, "Toggles graph connection display for the node that the player is looking at. Nodes that are connected to the selected node by the net graph will be drawn in red with magenta lines connecting to the selected node. Nodes that are not connected via the net graph from the selected node will be drawn in blue.", FCVAR_CHEAT);
//------------------------------------------------------------------------------
// Purpose: Show route triangulation attempts
//------------------------------------------------------------------------------
void CC_NPC_Bipass( const CCommand &args )
{
SetDebugBits( UTIL_GetCommandClient(),args[1],OVERLAY_NPC_TRIANGULATE_BIT);
}
static ConCommand npc_bipass("npc_bipass", CC_NPC_Bipass, "Displays the local movement attempts by the given NPC(s) (triangulation detours). Failed bypass routes are displayed in red, successful bypasses are shown in green.\n\tArguments: {entity_name} / {class_name} / no argument picks what player is looking at.", FCVAR_CHEAT);
//------------------------------------------------------------------------------
// Purpose: Destroy selected NPC
//------------------------------------------------------------------------------
void CC_NPC_Destroy( const CCommand &args )
{
SetDebugBits( UTIL_GetCommandClient(),args[1],OVERLAY_NPC_ZAP_BIT);
}
static ConCommand npc_destroy("npc_destroy", CC_NPC_Destroy, "Removes the given NPC(s) from the universe\nArguments: {npc_name} / {npc_class_name} / no argument picks what player is looking at", FCVAR_CHEAT);
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void CC_NPC_Kill( const CCommand &args )
{
SetDebugBits( UTIL_GetCommandClient(),args[1],OVERLAY_NPC_KILL_BIT);
}
static ConCommand npc_kill("npc_kill", CC_NPC_Kill, "Kills the given NPC(s)\nArguments: {npc_name} / {npc_class_name} / no argument picks what player is looking at", FCVAR_CHEAT);
//------------------------------------------------------------------------------
// Purpose: Show selected NPC's enemies
//------------------------------------------------------------------------------
void CC_NPC_Enemies( const CCommand &args )
{
SetDebugBits( UTIL_GetCommandClient(),args[1],OVERLAY_NPC_ENEMIES_BIT);
}
static ConCommand npc_enemies("npc_enemies", CC_NPC_Enemies, "Shows memory of NPC. Draws an X on top of each memory.\n\tEluded entities drawn in blue (don't know where it went)\n\tUnreachable entities drawn in green (can't get to it)\n\tCurrent enemy drawn in red\n\tCurrent target entity drawn in magenta\n\tAll other entities drawn in pink\n\tArguments: {npc_name} / {npc class_name} / no argument picks what player is looking at", FCVAR_CHEAT);
//------------------------------------------------------------------------------
// Purpose: Show seletected NPC's current enemy and target entity
//------------------------------------------------------------------------------
void CC_NPC_Focus( const CCommand &args )
{
SetDebugBits( UTIL_GetCommandClient(),args[1],OVERLAY_NPC_FOCUS_BIT);
}
static ConCommand npc_focus("npc_focus", CC_NPC_Focus, "Displays red line to NPC's enemy (if has one) and blue line to NPC's target entity (if has one)\n\tArguments: {npc_name} / {npc class_name} / no argument picks what player is looking at", FCVAR_CHEAT);
ConVar npc_create_equipment("npc_create_equipment", "");
//------------------------------------------------------------------------------
// Purpose: Create an NPC of the given type
//------------------------------------------------------------------------------
void CC_NPC_Create( const CCommand &args )
{
MDLCACHE_CRITICAL_SECTION();
bool allowPrecache = CBaseEntity::IsPrecacheAllowed();
CBaseEntity::SetAllowPrecache( true );
// Try to create entity
CAI_BaseNPC *baseNPC = dynamic_cast< CAI_BaseNPC * >( CreateEntityByName(args[1]) );
if (baseNPC)
{
baseNPC->KeyValue( "additionalequipment", npc_create_equipment.GetString() );
baseNPC->Precache();
if ( args.ArgC() == 3 )
{
baseNPC->SetName( AllocPooledString( args[2] ) );
}
DispatchSpawn(baseNPC);
// Now attempt to drop into the world
CBasePlayer* pPlayer = UTIL_GetCommandClient();
trace_t tr;
Vector forward;
pPlayer->EyeVectors( &forward );
AI_TraceLine(pPlayer->EyePosition(),
pPlayer->EyePosition() + forward * MAX_TRACE_LENGTH,MASK_NPCSOLID,
pPlayer, COLLISION_GROUP_NONE, &tr );
if ( tr.fraction != 1.0)
{
if (baseNPC->CapabilitiesGet() & bits_CAP_MOVE_FLY)
{
Vector pos = tr.endpos - forward * 36;
baseNPC->Teleport( &pos, NULL, NULL );
}
else
{
// Raise the end position a little up off the floor, place the npc and drop him down
tr.endpos.z += 12;
baseNPC->Teleport( &tr.endpos, NULL, NULL );
UTIL_DropToFloor( baseNPC, MASK_NPCSOLID );
}
// Now check that this is a valid location for the new npc to be
Vector vUpBit = baseNPC->GetAbsOrigin();
vUpBit.z += 1;
AI_TraceHull( baseNPC->GetAbsOrigin(), vUpBit, baseNPC->GetHullMins(), baseNPC->GetHullMaxs(),
MASK_NPCSOLID, baseNPC, COLLISION_GROUP_NONE, &tr );
if ( tr.startsolid || (tr.fraction < 1.0) )
{
baseNPC->SUB_Remove();
DevMsg("Can't create %s. Bad Position!\n",args[1]);
NDebugOverlay::Box(baseNPC->GetAbsOrigin(), baseNPC->GetHullMins(), baseNPC->GetHullMaxs(), 255, 0, 0, 0, 0);
}
}
baseNPC->Activate();
}
CBaseEntity::SetAllowPrecache( allowPrecache );
}
static ConCommand npc_create("npc_create", CC_NPC_Create, "Creates an NPC of the given type where the player is looking (if the given NPC can actually stand at that location). Note that this only works for npc classes that are already in the world. You can not create an entity that doesn't have an instance in the level.\n\tArguments: {npc_class_name}", FCVAR_CHEAT);
//------------------------------------------------------------------------------
// Purpose: Create an NPC of the given type
//------------------------------------------------------------------------------
void CC_NPC_Create_Aimed( const CCommand &args )
{
MDLCACHE_CRITICAL_SECTION();
bool allowPrecache = CBaseEntity::IsPrecacheAllowed();
CBaseEntity::SetAllowPrecache( true );
// Try to create entity
CAI_BaseNPC *baseNPC = dynamic_cast< CAI_BaseNPC * >( CreateEntityByName(args[1]) );
if (baseNPC)
{
baseNPC->KeyValue( "additionalequipment", npc_create_equipment.GetString() );
baseNPC->Precache();
DispatchSpawn( baseNPC );
// Now attempt to drop into the world
QAngle angles;
CBasePlayer* pPlayer = UTIL_GetCommandClient();
trace_t tr;
Vector forward;
pPlayer->EyeVectors( &forward );
VectorAngles( forward, angles );
angles.x = 0;
angles.z = 0;
AI_TraceLine( pPlayer->EyePosition(),
pPlayer->EyePosition() + forward * MAX_TRACE_LENGTH,MASK_NPCSOLID,
pPlayer, COLLISION_GROUP_NONE, &tr );
if ( tr.fraction != 1.0)
{
if (baseNPC->CapabilitiesGet() & bits_CAP_MOVE_FLY)
{
Vector pos = tr.endpos - forward * 36;
baseNPC->Teleport( &pos, &angles, NULL );
}
else
{
// Raise the end position a little up off the floor, place the npc and drop him down
tr.endpos.z += 12;
baseNPC->Teleport( &tr.endpos, &angles, NULL );
UTIL_DropToFloor( baseNPC, MASK_NPCSOLID );
}
// Now check that this is a valid location for the new npc to be
Vector vUpBit = baseNPC->GetAbsOrigin();
vUpBit.z += 1;
AI_TraceHull( baseNPC->GetAbsOrigin(), vUpBit, baseNPC->GetHullMins(), baseNPC->GetHullMaxs(),
MASK_NPCSOLID, baseNPC, COLLISION_GROUP_NONE, &tr );
if ( tr.startsolid || (tr.fraction < 1.0) )
{
baseNPC->SUB_Remove();
DevMsg("Can't create %s. Bad Position!\n",args[1]);
NDebugOverlay::Box(baseNPC->GetAbsOrigin(), baseNPC->GetHullMins(), baseNPC->GetHullMaxs(), 255, 0, 0, 0, 0);
}
}
else
{
baseNPC->Teleport( NULL, &angles, NULL );
}
baseNPC->Activate();
}
CBaseEntity::SetAllowPrecache( allowPrecache );
}
static ConCommand npc_create_aimed("npc_create_aimed", CC_NPC_Create_Aimed, "Creates an NPC aimed away from the player of the given type where the player is looking (if the given NPC can actually stand at that location). Note that this only works for npc classes that are already in the world. You can not create an entity that doesn't have an instance in the level.\n\tArguments: {npc_class_name}", FCVAR_CHEAT);
//------------------------------------------------------------------------------
// Purpose: Destroy unselected NPCs
//------------------------------------------------------------------------------
void CC_NPC_DestroyUnselected( void )
{
CAI_BaseNPC *pNPC = gEntList.NextEntByClass( (CAI_BaseNPC *)NULL );
while (pNPC)
{
if (!(pNPC->m_debugOverlays & OVERLAY_NPC_SELECTED_BIT) && !pNPC->ClassMatches("npc_bullseye"))
{
pNPC->m_debugOverlays |= OVERLAY_NPC_ZAP_BIT;
}
pNPC = gEntList.NextEntByClass(pNPC);
}
}
static ConCommand npc_destroy_unselected("npc_destroy_unselected", CC_NPC_DestroyUnselected, "Removes all NPCs from the universe that aren't currently selected", FCVAR_CHEAT);
//------------------------------------------------------------------------------
// Purpose: Freeze or unfreeze the selected NPCs. If no NPCs are selected, the
// NPC under the crosshair is frozen/unfrozen.
//------------------------------------------------------------------------------
void CC_NPC_Freeze( const CCommand &args )
{
if (FStrEq(args[1], ""))
{
//
// No NPC was specified, try to freeze selected NPCs.
//
bool bFound = false;
CAI_BaseNPC *npc = gEntList.NextEntByClass( (CAI_BaseNPC *)NULL );
while (npc)
{
if (npc->m_debugOverlays & OVERLAY_NPC_SELECTED_BIT)
{
bFound = true;
npc->ToggleFreeze();
}
npc = gEntList.NextEntByClass(npc);
}
if (!bFound)
{
//
// No selected NPCs, look for the NPC under the crosshair.
//
CBaseEntity *pEntity = FindPickerEntity( UTIL_GetCommandClient() );
if ( pEntity )
{
CAI_BaseNPC *pNPC = pEntity->MyNPCPointer();
if (pNPC)
{
pNPC->ToggleFreeze();
}
}
}
}
else
{
// TODO: look for NPCs by name, classname.
}
}
static ConCommand npc_freeze("npc_freeze", CC_NPC_Freeze, "Selected NPC(s) will freeze in place (or unfreeze). If there are no selected NPCs, uses the NPC under the crosshair.\n\tArguments: -none-", FCVAR_CHEAT);
CON_COMMAND( npc_freeze_unselected, "Freeze all NPCs not selected" )
{
CAI_BaseNPC *pNPC = gEntList.NextEntByClass( (CAI_BaseNPC *)NULL );
while (pNPC)
{
if (!(pNPC->m_debugOverlays & OVERLAY_NPC_SELECTED_BIT))
{
pNPC->ToggleFreeze();
}
pNPC = gEntList.NextEntByClass(pNPC);
}
}
//------------------------------------------------------------------------------
CON_COMMAND(npc_thinknow, "Trigger NPC to think")
{
if ( !UTIL_IsCommandIssuedByServerAdmin() )
return;
CBaseEntity *pEntity = FindPickerEntity( UTIL_GetCommandClient() );
if ( pEntity )
{
CAI_BaseNPC *pNPC = pEntity->MyNPCPointer();
if (pNPC)
{
pNPC->SetThink( &CAI_BaseNPC::CallNPCThink );
pNPC->SetNextThink( gpGlobals->curtime );
}
}
}
//------------------------------------------------------------------------------
// Purpose: Tell selected NPC to go to a where player is looking
//------------------------------------------------------------------------------
void CC_NPC_Teleport( void )
{
CBasePlayer* pPlayer = UTIL_GetCommandClient();
trace_t tr;
Vector forward;
pPlayer->EyeVectors( &forward );
AI_TraceLine(pPlayer->EyePosition(),
pPlayer->EyePosition() + forward * MAX_TRACE_LENGTH,MASK_NPCSOLID,
pPlayer, COLLISION_GROUP_NONE, &tr );
if ( tr.fraction != 1.0)
{
CAI_BaseNPC *npc = gEntList.NextEntByClass( (CAI_BaseNPC *)NULL );
while (npc)
{
//Only Teleport one NPC if more than one is selected.
if (npc->m_debugOverlays & OVERLAY_NPC_SELECTED_BIT)
{
npc->Teleport( &tr.endpos, NULL, NULL );
break;
}
npc = gEntList.NextEntByClass(npc);
}
}
}
static ConCommand npc_teleport("npc_teleport", CC_NPC_Teleport, "Selected NPC will teleport to the location that the player is looking (shown with a purple box)\n\tArguments: -none-", FCVAR_CHEAT);
static ConVar npc_go_do_run( "npc_go_do_run", "1", 0, "Set whether should run on NPC go" );
void CC_NPC_Go( void )
{
CBasePlayer* pPlayer = UTIL_GetCommandClient();
trace_t tr;
Vector forward;
pPlayer->EyeVectors( &forward );
AI_TraceLine(pPlayer->EyePosition(),
pPlayer->EyePosition() + forward * MAX_TRACE_LENGTH,MASK_NPCSOLID,
pPlayer, COLLISION_GROUP_NONE, &tr );
if ( tr.fraction != 1.0)
{
CAI_BaseNPC::ForceSelectedGo(pPlayer, tr.endpos, forward, npc_go_do_run.GetBool());
}
}
static ConCommand npc_go("npc_go", CC_NPC_Go, "Selected NPC(s) will go to the location that the player is looking (shown with a purple box)\n\tArguments: -none-", FCVAR_CHEAT);
//------------------------------------------------------------------------------
// Purpose: Tell seclected NPC to go to a random node location
//------------------------------------------------------------------------------
void CC_NPC_GoRandom( void )
{
CAI_BaseNPC::ForceSelectedGoRandom();
}
static ConCommand npc_go_random("npc_go_random", CC_NPC_GoRandom, "Sends all selected NPC(s) to a random node.\n\tArguments: -none-", FCVAR_CHEAT);
//------------------------------------------------------------------------------
// Purpose: ?Does this work?
//------------------------------------------------------------------------------
void CC_NPC_Reset( void )
{
CAI_BaseNPC::ClearAllSchedules();
g_AI_SchedulesManager.LoadAllSchedules();
}
static ConCommand npc_reset("npc_reset", CC_NPC_Reset, "Reloads schedules for all NPC's from their script files\n\tArguments: -none-", FCVAR_CHEAT);
//------------------------------------------------------------------------------
// Purpose: Show the selected NPC's nearest node
//------------------------------------------------------------------------------
void CC_NPC_Nearest( const CCommand &args )
{
SetDebugBits( UTIL_GetCommandClient(),args[1],OVERLAY_NPC_NEAREST_BIT);
}
static ConCommand npc_nearest("npc_nearest", CC_NPC_Nearest, "Draw's a while box around the NPC(s) nearest node\n\tArguments: {entity_name} / {class_name} / no argument picks what player is looking at ", FCVAR_CHEAT);
//------------------------------------------------------------------------------
// Purpose: Show the selected NPC's route
//------------------------------------------------------------------------------
void CC_NPC_Route( const CCommand &args )
{
SetDebugBits( UTIL_GetCommandClient(),args[1],OVERLAY_NPC_ROUTE_BIT);
}
static ConCommand npc_route("npc_route", CC_NPC_Route, "Displays the current route of the given NPC as a line on the screen. Waypoints along the route are drawn as small cyan rectangles. Line is color coded in the following manner:\n\tBlue - path to a node\n\tCyan - detour around an object (triangulation)\n\tRed - jump\n\tMaroon - path to final target position\n\tArguments: {npc_name} / {npc_class_name} / no argument picks what player is looking at ", FCVAR_CHEAT);
//------------------------------------------------------------------------------
// Purpose: Select an NPC
//------------------------------------------------------------------------------
void CC_NPC_Select( const CCommand &args )
{
SetDebugBits( UTIL_GetCommandClient(),args[1],OVERLAY_NPC_SELECTED_BIT);
}
static ConCommand npc_select("npc_select", CC_NPC_Select, "Select or deselects the given NPC(s) for later manipulation. Selected NPC's are shown surrounded by a red translucent box\n\tArguments: {entity_name} / {class_name} / no argument picks what player is looking at ", FCVAR_CHEAT);
//------------------------------------------------------------------------------
// Purpose: Show combat related data for an NPC
//------------------------------------------------------------------------------
void CC_NPC_Combat( const CCommand &args )
{
SetDebugBits( UTIL_GetCommandClient(),args[1],OVERLAY_NPC_SQUAD_BIT);
}
static ConCommand npc_combat("npc_combat", CC_NPC_Combat, "Displays text debugging information about the squad and enemy of the selected NPC (See Overlay Text)\n\tArguments: {npc_name} / {npc class_name} / no argument picks what player is looking at", FCVAR_CHEAT);
// For backwards compatibility
static ConCommand npc_squads("npc_squads", CC_NPC_Combat, "Obsolete. Replaced by npc_combat", FCVAR_CHEAT);
//------------------------------------------------------------------------------
// Purpose: Show tasks for an NPC
//------------------------------------------------------------------------------
void CC_NPC_Tasks( const CCommand &args )
{
SetDebugBits( UTIL_GetCommandClient(),args[1],OVERLAY_NPC_TASK_BIT);
}
static ConCommand npc_tasks("npc_tasks", CC_NPC_Tasks, "Displays detailed text debugging information about the all the tasks of the selected NPC current schedule (See Overlay Text)\n\tArguments: {npc_name} / {npc class_name} / no argument picks what player is looking at ", FCVAR_CHEAT);
//------------------------------------------------------------------------------
// Purpose: Show tasks (on the console) for an NPC
//------------------------------------------------------------------------------
void CC_NPC_Task_Text( const CCommand &args )
{
SetDebugBits( UTIL_GetCommandClient(), args[1], OVERLAY_TASK_TEXT_BIT);
}
static ConCommand npc_task_text("npc_task_text", CC_NPC_Task_Text, "Outputs text debugging information to the console about the all the tasks + break conditions of the selected NPC current schedule\n\tArguments: {npc_name} / {npc class_name} / no argument picks what player is looking at ", FCVAR_CHEAT);
//------------------------------------------------------------------------------
// Purpose: Shows all current conditions for an NPC.
//------------------------------------------------------------------------------
void CC_NPC_Conditions( const CCommand &args )
{
SetDebugBits( UTIL_GetCommandClient(), args[1], OVERLAY_NPC_CONDITIONS_BIT);
}
static ConCommand npc_conditions("npc_conditions", CC_NPC_Conditions, "Displays all the current AI conditions that an NPC has in the overlay text.\n\tArguments: {npc_name} / {npc class_name} / no argument picks what player is looking at", FCVAR_CHEAT);
//------------------------------------------------------------------------------
// Purpose: Show an NPC's viewcone
//------------------------------------------------------------------------------
void CC_NPC_Viewcone( const CCommand &args )
{
SetDebugBits( UTIL_GetCommandClient(),args[1],OVERLAY_NPC_VIEWCONE_BIT);
}
static ConCommand npc_viewcone("npc_viewcone", CC_NPC_Viewcone, "Displays the viewcone of the NPC (where they are currently looking and what the extents of there vision is)\n\tArguments: {entity_name} / {class_name} / no argument picks what player is looking at", FCVAR_CHEAT);
//------------------------------------------------------------------------------
// Purpose: Show an NPC's relationships to other NPCs
//------------------------------------------------------------------------------
void CC_NPC_Relationships( const CCommand &args )
{
SetDebugBits( UTIL_GetCommandClient(),args[1], OVERLAY_NPC_RELATION_BIT );
}
static ConCommand npc_relationships("npc_relationships", CC_NPC_Relationships, "Displays the relationships between this NPC and all others.\n\tArguments: {entity_name} / {class_name} / no argument picks what player is looking at", FCVAR_CHEAT );
//------------------------------------------------------------------------------
// Purpose: Show an NPC's steering regulations
//------------------------------------------------------------------------------
void CC_NPC_ViewSteeringRegulations( const CCommand &args )
{
SetDebugBits( UTIL_GetCommandClient(), args[1], OVERLAY_NPC_STEERING_REGULATIONS);
}
static ConCommand npc_steering("npc_steering", CC_NPC_ViewSteeringRegulations, "Displays the steering obstructions of the NPC (used to perform local avoidance)\n\tArguments: {entity_name} / {class_name} / no argument picks what player is looking at", FCVAR_CHEAT);
void CC_NPC_ViewSteeringRegulationsAll( void )
{
CAI_BaseNPC *pNPC = gEntList.NextEntByClass( (CAI_BaseNPC *)NULL );
while (pNPC)
{
if (!(pNPC->m_debugOverlays & OVERLAY_NPC_SELECTED_BIT))
{
pNPC->m_debugOverlays |= OVERLAY_NPC_STEERING_REGULATIONS;
}
else
{
pNPC->m_debugOverlays &= ~OVERLAY_NPC_STEERING_REGULATIONS;
}
pNPC = gEntList.NextEntByClass(pNPC);
}
}
static ConCommand npc_steering_all("npc_steering_all", CC_NPC_ViewSteeringRegulationsAll, "Displays the steering obstructions of all NPCs (used to perform local avoidance)\n", FCVAR_CHEAT);
//------------------------------------------------------------------------------
CON_COMMAND( npc_heal, "Heals the target back to full health" )
{
if ( !UTIL_IsCommandIssuedByServerAdmin() )
return;
CBaseEntity *pEntity = FindPickerEntity( UTIL_GetCommandClient() );
if ( pEntity )
{
CAI_BaseNPC *pNPC = pEntity->MyNPCPointer();
if (pNPC)
{
pNPC->SetHealth( pNPC->GetMaxHealth() );
}
}
}
CON_COMMAND( npc_ammo_deplete, "Subtracts half of the target's ammo" )
{
if ( !UTIL_IsCommandIssuedByServerAdmin() )
return;
CBaseEntity *pEntity = FindPickerEntity( UTIL_GetCommandClient() );
if ( pEntity )
{
CAI_BaseNPC *pNPC = pEntity->MyNPCPointer();
if (pNPC && pNPC->GetActiveWeapon())
{
pNPC->GetActiveWeapon()->m_iClip1 *= 0.5;
}
}
}
CON_COMMAND( ai_clear_bad_links, "Clears bits set on nav links indicating link is unusable " )
{
if ( !UTIL_IsCommandIssuedByServerAdmin() )
return;
CAI_Node *pNode;
for ( int i = 0; i < g_pBigAINet->NumNodes(); i++ )
{
pNode = g_pBigAINet->GetNode( i );
for ( int j = 0; j < pNode->NumLinks(); j++ )
{
pNode->GetLinkByIndex( j )->m_LinkInfo &= ~bits_LINK_STALE_SUGGESTED;
}
}
}
CON_COMMAND( ai_test_los, "Test AI LOS from the player's POV" )
{
if ( !UTIL_IsCommandIssuedByServerAdmin() )
return;
trace_t tr;
// Use the custom LOS trace filter
CTraceFilterLOS traceFilter( UTIL_GetLocalPlayer(), COLLISION_GROUP_NONE );
UTIL_TraceLine( UTIL_GetLocalPlayer()->EyePosition(), UTIL_GetLocalPlayer()->EyePosition() + UTIL_GetLocalPlayer()->EyeDirection3D() * MAX_COORD_RANGE, MASK_BLOCKLOS_AND_NPCS, &traceFilter, &tr );
NDebugOverlay::Line( UTIL_GetLocalPlayer()->EyePosition(), tr.endpos, 127, 127, 127, true, 5 );
NDebugOverlay::Cross3D( tr.endpos, 24, 255, 255, 255, true, 5 );
}
#ifdef VPROF_ENABLED
CON_COMMAND(ainet_generate_report, "Generate a report to the console.")
{
g_VProfCurrentProfile.OutputReport( VPRT_FULL, "AINet" );
}
CON_COMMAND(ainet_generate_report_only, "Generate a report to the console.")
{
g_VProfCurrentProfile.OutputReport( VPRT_FULL, "AINet", g_VProfCurrentProfile.BudgetGroupNameToBudgetGroupID( "AINet" ) );
}
#endif