-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathconsole_commands.cpp
4561 lines (3879 loc) · 144 KB
/
console_commands.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <good/string_buffer.h>
#include <good/string_utils.h>
#include <good/log.h>
#include "bot.h"
#include "clients.h"
#include "config.h"
#include "console_commands.h"
#include "item.h"
#include "waypoint.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
#define MAIN_COMMAND "botrix"
good::unique_ptr<CBotrixCommand> CBotrixCommand::instance;
good::unique_ptr<ConCommand> CBotrixCommand::m_pServerCommand;
const good::string sHelp( "help" );
const good::string sAll( "all" );
const good::string sNone( "none" );
const good::string sNext( "next" );
const good::string sRandom( "random" );
const good::string sFirstAngle( "angle1" );
const good::string sSecondAngle( "angle2" );
const good::string sButton( "button" );
const good::string sDoor( "door" );
const good::string sElevator( "elevator" );
const good::string sWeapon( "weapon" ); // Next 4 are only for unknown mods
const good::string sAmmo( "ammo" );
const good::string sHealth( "health" );
const good::string sArmor( "armor" );
const good::string sCurrent( "current" );
const good::string sDestination( "destination" );
const good::string sActionTime( "action-time" );
const good::string sActionDuration( "action-duration" );
const good::string sUnlock( "unlock" );
const good::string sForever( "forever" );
const good::string sOn( "on" );
const good::string sOff( "off" );
const good::string sClear( "clear" );
const good::string sMelee( "melee" );
const good::string sRanged( "ranged" );
extern char* szMainBuffer;
extern int iMainBufferSize;
StringVector aBoolsCompletion(2);
StringVector aWaypointCompletion(2);
#define ANALIZE_WAYPOINTS_CHECK() \
if ( CWaypoints::IsAnalyzing() )\
{\
BLOG_W( "You can't use this command while map is being analyzed for waypoints." );\
return ECommandError;\
}
//----------------------------------------------------------------------------------------------------------------
// Singleton to access console variables.
//----------------------------------------------------------------------------------------------------------------
//CPluginConVarAccessor CPluginConVarAccessor::instance;
//
//bool CPluginConVarAccessor::RegisterConCommandBase( ConCommandBase *pCommand )
//{
// // Link to engine's list.
// CBotrixPlugin::pCvar->RegisterConCommand( pCommand );
// return true;
//}
//----------------------------------------------------------------------------------------------------------------
// CConsoleCommand.
//----------------------------------------------------------------------------------------------------------------
#if defined(BOTRIX_NO_COMMAND_COMPLETION)
#elif defined(BOTRIX_OLD_COMMAND_COMPLETION)
int CConsoleCommand::AutoComplete( const char* partial, int partialLength,
char commands[ COMMAND_COMPLETION_MAXITEMS ][ COMMAND_COMPLETION_ITEM_LENGTH ],
int strIndex, int charIndex )
{
if (charIndex + partialLength >= COMMAND_COMPLETION_ITEM_LENGTH ||
strIndex >= COMMAND_COMPLETION_ITEM_LENGTH-1)
return 0; // Check bounds.
int result = 0;
int maxLength = COMMAND_COMPLETION_ITEM_LENGTH - charIndex - 1; // Save one space for trailing 0.
if ( partialLength <= m_sCommand.size() )
{
if ( strncmp( m_sCommand.c_str(), partial, partialLength ) == 0 )
{
// Autocomplete only command name.
strncpy( &commands[strIndex][charIndex], m_sCommand.c_str(), MIN2(maxLength, m_sCommand.size()+1) );
commands[strIndex+result][COMMAND_COMPLETION_ITEM_LENGTH-1] = 0;
result++;
}
}
else
{
if ( m_cAutoCompleteArguments.size() > 0 &&
strncmp( m_sCommand.c_str(), partial, m_sCommand.size() ) == 0 )
{
// Autocomplete command name with arguments.
good::string part(partial, false, false, partialLength);
int start = m_sCommand.size();
if ( part[start] == ' ' )
{
int lastSpace = part.rfind(' ');
if ( lastSpace != good::string::npos )
{
if ( !m_bAutoCompleteOnlyOneArgument || (lastSpace == start) )
{
lastSpace++;
good::string partArg(&partial[lastSpace], false, false, partialLength - lastSpace);
maxLength = COMMAND_COMPLETION_ITEM_LENGTH - (charIndex + lastSpace) - 1; // Save one space for trailing 0.
if ( maxLength > 0 ) // There is still space in autocomplete field.
{
for ( int i = 0; i < m_cAutoCompleteArguments.size(); ++i )
{
const good::string& arg = m_cAutoCompleteArguments[i];
if ( good::starts_with(arg, partArg) )
{
strncpy( &commands[strIndex+result][charIndex], partial, lastSpace );
strncpy( &commands[strIndex+result][charIndex+lastSpace], arg.c_str(), MIN2(maxLength, arg.size()+1) );
commands[strIndex+result][COMMAND_COMPLETION_ITEM_LENGTH-1] = 0;
result++;
if ( strIndex+result >= COMMAND_COMPLETION_ITEM_LENGTH-1 )
return result; // Bound check.
}
}
}
}
}
}
}
}
return result;
}
#else // BOTRIX_OLD_COMMAND_COMPLETION
int CConsoleCommand::AutoComplete( good::string& partial, CUtlVector<CUtlString>& cCommands, int charIndex )
{
int result = 0;
const char* szSubPartial = &partial[charIndex];
int iLen = partial.size() - charIndex;
if ( iLen <= m_sCommand.size() )
{
if ( strncmp( m_sCommand.c_str(), szSubPartial, iLen ) == 0 )
{
// Autocomplete only command name.
CUtlString sStr( partial.c_str(), charIndex );
sStr.Append( m_sCommand.c_str() );
cCommands.AddToTail( sStr );
result++;
}
}
else
{
BASSERT(m_cAutoCompleteArguments.size() == m_cAutoCompleteValues.size(), return result);
char last = szSubPartial[m_sCommand.size()]; // Can't be 0, because iLen > command length
if ( (m_cAutoCompleteArguments.size() > 0) &&
(strncmp( m_sCommand.c_str(), szSubPartial, m_sCommand.size() ) == 0) &&
(last == ' ') )
{
szSubPartial += m_sCommand.size() + 1;
iLen -= m_sCommand.size() + 1;
while ( iLen > 0 && *szSubPartial == ' ')
{
++szSubPartial;
--iLen;
}
// Autocomplete command name with arguments.
good::string sArg(szSubPartial, false, false, iLen);
int currentArg = 0, lastSpace = 0;
bool hadQuote = false;
for (int i = 0; i < iLen; ++i) {
if ( sArg[i] == '"' )
hadQuote = !hadQuote;
else if ( (sArg[i] == ' ') && !hadQuote )
{
while ( sArg[++i] == ' ' ); // Skip spaces.
lastSpace = i;
i--; // Will increment i again.
++currentArg;
}
}
// Get current argument type.
TConsoleAutoCompleteArg argType = currentArg < m_cAutoCompleteArguments.size() ? m_cAutoCompleteArguments[currentArg] : EConsoleAutoCompleteArgInvalid;
if ( argType == EConsoleAutoCompleteArgInvalid )
{
switch ( m_cAutoCompleteArguments.back() )
{
case EConsoleAutoCompleteArgValuesForever:
argType = EConsoleAutoCompleteArgValues;
currentArg = m_cAutoCompleteValues.size() - 1;
break;
case EConsoleAutoCompleteArgPlayersForever:
argType = EConsoleAutoCompleteArgPlayers;
break;
case EConsoleAutoCompleteArgUsersForever:
argType = EConsoleAutoCompleteArgUsers;
break;
case EConsoleAutoCompleteArgBotsForever:
argType = EConsoleAutoCompleteArgBots;
break;
case EConsoleAutoCompleteArgWaypointForever:
argType = EConsoleAutoCompleteArgWaypoint;
break;
default:
return result;
}
}
// Get completion values.
StringVector completionValues;
StringVector* completion = NULL;
switch (argType) {
case EConsoleAutoCompleteArgBool:
completion = &aBoolsCompletion;
break;
case EConsoleAutoCompleteArgValues:
case EConsoleAutoCompleteArgValuesForever:
completion = &m_cAutoCompleteValues[currentArg];
break;
case EConsoleAutoCompleteArgWaypoint:
case EConsoleAutoCompleteArgWaypointForever:
completion = &aWaypointCompletion;
break;
case EConsoleAutoCompleteArgBots:
case EConsoleAutoCompleteArgBotsForever:
case EConsoleAutoCompleteArgUsers:
case EConsoleAutoCompleteArgUsersForever:
case EConsoleAutoCompleteArgPlayers:
case EConsoleAutoCompleteArgPlayersForever:
completionValues.push_back( sAll );
CPlayers::GetNames(
completionValues,
argType != EConsoleAutoCompleteArgUsers && argType != EConsoleAutoCompleteArgUsersForever,
argType != EConsoleAutoCompleteArgBots && argType != EConsoleAutoCompleteArgBotsForever
);
completion = &completionValues;
for ( int i = 1; i < completionValues.size(); ++i )
{
if ( completionValues[i].find(' ') != good::string::npos )
{
good::string_buffer sBuff( completionValues[i].size() + 2 );
sBuff.append('"');
sBuff.append(completionValues[i]);
sBuff.append('"');
completionValues[i] = sBuff;
}
}
break;
default:
return result;
}
if ( completion->empty() )
return result;
good::string sPartArg(&sArg[lastSpace], true, true, iLen - lastSpace);
good::string sCmd(partial.c_str(), true, true, partial.size() - sPartArg.size());
for ( int i = 0; i < completion->size(); ++i )
{
const good::string& arg = (*completion)[i];
if ( good::starts_with(arg, sPartArg) )
{
CUtlString sStr( sCmd.c_str() );
sStr.Append( arg.c_str() );
cCommands.AddToTail( sStr );
result++;
}
}
}
}
return result;
}
#endif // BOTRIX_OLD_COMMAND_COMPLETION
TCommandResult CConsoleCommand::Execute( CClient* pClient, int argc, const char** argv )
{
if ( argc == 1 && sHelp == argv[0] )
{
PrintCommand( pClient ? pClient->GetEdict() : NULL, 0 );
return ECommandPerformed;
}
return ECommandNotImplemented;
}
void CConsoleCommand::PrintCommand( edict_t* pPrintTo, int indent )
{
bool bHasAccess = true;
if ( pPrintTo )
{
CPlayer* pPlayer = CPlayers::Get( pPrintTo );
BASSERT( pPlayer && !pPlayer->IsBot(), return );
CClient* pClient = (CClient*)pPlayer;
bHasAccess = HasAccess(pClient);
}
int i;
for ( i = 0; i < indent*2; i ++ )
szMainBuffer[i] = ' ';
szMainBuffer[i]=0;
const char* sCantUse = bHasAccess ? "" : "[can't use]";
BULOG_I( pPrintTo, "%s[%s]%s: %s", szMainBuffer, m_sCommand.c_str(), sCantUse, m_sHelp.c_str() );
if ( m_sDescription.length() > 0 )
BULOG_I( pPrintTo, "%s %s", szMainBuffer, m_sDescription.c_str() );
}
//----------------------------------------------------------------------------------------------------------------
// CConsoleCommandContainer.
//----------------------------------------------------------------------------------------------------------------
#if defined(BOTRIX_NO_COMMAND_COMPLETION)
#elif defined(BOTRIX_OLD_COMMAND_COMPLETION)
int CConsoleCommandContainer::AutoComplete( const char* partial, int partialLength, char commands[ COMMAND_COMPLETION_MAXITEMS ][ COMMAND_COMPLETION_ITEM_LENGTH ], int strIndex, int charIndex )
{
int result = 0;
int command_size = m_sCommand.size();
if ( command_size >= partialLength ) // only Add command to commands array
{
if ( strncmp( m_sCommand.c_str(), partial, partialLength ) == 0 )
{
strcpy( &commands[strIndex][charIndex], m_sCommand.c_str() ); // e.g. "way" -> "waypoint"
result++;
}
}
else
{
if ( strncmp( m_sCommand.c_str(), partial, command_size ) == 0 )
{
partial += command_size;
partialLength -= command_size;
while ( *partial == ' ' )
{
partial++; // remove root command from partial command(e.g. "botrix way" -> "way")
partialLength--;
}
int charIdx = charIndex + command_size + 1; // 1 is for space
for ( int i = 0; i < m_aCommands.size(); i ++ )
{
int count = m_aCommands[i]->AutoComplete(partial, partialLength, commands, strIndex, charIdx);
for ( int j = 0; j < count; j ++ )
{
strncpy(&commands[strIndex][charIndex], m_sCommand.c_str(), command_size);
commands[strIndex][charIndex+command_size] = ' ';
strIndex ++;
result ++;
}
}
}
}
return result;
}
#else // BOTRIX_OLD_COMMAND_COMPLETION
int CConsoleCommandContainer::AutoComplete( good::string& partial, CUtlVector< CUtlString > &cCommands, int charIndex )
{
int result = 0;
int command_size = m_sCommand.size();
if ( command_size >= partial.size() - charIndex ) // Only add this command to commands array.
{
if ( strncmp(m_sCommand.c_str(), &partial[charIndex], partial.size() - charIndex) == 0 )
{
// Autocomplete only command name.
CUtlString sStr( partial.c_str(), charIndex );
sStr.Append( m_sCommand.c_str() );
cCommands.AddToTail( sStr );
result++;
}
}
else
{
if (strncmp(m_sCommand.c_str(), &partial[charIndex], command_size) == 0)
{
int partialLength = partial.size();
int iLen = partialLength - charIndex - command_size - 1;
const char* szSubPartial = &partial[partialLength - iLen];
while ( *szSubPartial == ' ' )
{
szSubPartial++;
iLen--;
}
for ( int i = 0; i < m_aCommands.size(); i++ )
result += m_aCommands[i]->AutoComplete(partial, cCommands, partialLength - iLen);
}
}
return result;
}
#endif // BOTRIX_OLD_COMMAND_COMPLETION
TCommandResult CConsoleCommandContainer::Execute( CClient* pClient, int argc, const char** argv )
{
if ( CConsoleCommand::Execute( pClient, argc, argv ) == ECommandPerformed )
return ECommandPerformed;
if ( argc > 0 )
{
for ( int i = 0; i < m_aCommands.size(); i ++ )
{
CConsoleCommand *pCommand = m_aCommands[i].get();
if ( pCommand->IsCommand(argv[0]) )
{
if ( pCommand->HasAccess( pClient ) )
return pCommand->Execute( pClient, argc-1, &argv[1] );
else
return ECommandRequireAccess;
}
}
}
PrintCommand( pClient ? pClient->GetEdict() : NULL );
return ECommandNotFound;
}
void CConsoleCommandContainer::PrintCommand( edict_t* pPrintTo, int indent )
{
int i;
for ( i = 0; i < indent*2; i ++ )
szMainBuffer[i] = ' ';
szMainBuffer[i]=0;
BULOG_I( pPrintTo, "%s[%s]", szMainBuffer, m_sCommand.c_str() );
for ( int i = 0; i < m_aCommands.size(); i ++ )
m_aCommands[i]->PrintCommand( pPrintTo, indent+1 );
}
//----------------------------------------------------------------------------------------------------------------
// Userful functions.
//----------------------------------------------------------------------------------------------------------------
TWaypointId GetWaypointId( int iCurrentIndex, int argc, const char **argv, CClient *pClient, int iDefaultId )
{
TWaypointId id = -1;
if ( iCurrentIndex >= argc )
id = iDefaultId;
else if ( iCurrentIndex < argc )
{
if ( sCurrent == argv[iCurrentIndex] )
id = pClient->iCurrentWaypoint;
else if ( sDestination == argv[iCurrentIndex] )
id = pClient->iDestinationWaypoint;
else
sscanf( argv[iCurrentIndex], "%d", &id );
}
return id;
}
//----------------------------------------------------------------------------------------------------------------
// Waypoints commands.
//----------------------------------------------------------------------------------------------------------------
CWaypointDrawFlagCommand::CWaypointDrawFlagCommand()
{
m_sCommand = "drawtype";
m_sHelp = "defines how to draw waypoint";
m_sDescription = good::string("Can be 'none' / 'all' / 'next' or mix of: ") + CTypeToString::WaypointDrawFlagsToString(FWaypointDrawAll);
m_iAccessLevel = FCommandAccessWaypoint;
StringVector args;
args.push_back(sNone);
args.push_back(sAll);
args.push_back(sNext);
for (int i = 0; i < EWaypointDrawFlagTotal; ++i)
args.push_back(CTypeToString::WaypointDrawFlagsToString(1 << i).duplicate());
m_cAutoCompleteValues.push_back(args);
m_cAutoCompleteArguments.push_back(EConsoleAutoCompleteArgValuesForever);
}
TCommandResult CWaypointDrawFlagCommand::Execute( CClient* pClient, int argc, const char** argv )
{
if ( CConsoleCommand::Execute( pClient, argc, argv ) == ECommandPerformed )
return ECommandPerformed;
if ( pClient == NULL )
{
BLOG_W( "Please login to server to execute this command." );
return ECommandError;
}
if ( argc == 0 )
{
const good::string& sType = CTypeToString::WaypointDrawFlagsToString(pClient->iWaypointDrawFlags);
BULOG_I( pClient->GetEdict(), "Waypoint draw flags: %s.", (sType.size() != 0) ? sType.c_str() : sNone.c_str() );
return ECommandPerformed;
}
// Retrieve flags from string arguments.
bool bFinished = false;
TWaypointDrawFlags iFlags = FWaypointDrawNone;
if ( argc == 1 )
{
if ( sNone == argv[0] )
bFinished = true;
else if ( sAll == argv[0] )
{
iFlags = FWaypointDrawAll;
bFinished = true;
}
else if ( sNext == argv[0] )
{
int iNew = (pClient->iWaypointDrawFlags) ? pClient->iWaypointDrawFlags<< 1 : 1;
iFlags = (iNew > FWaypointDrawAll) ? 0 : iNew;
bFinished = true;
}
}
if ( !bFinished )
{
for ( int i=0; i < argc; ++i )
{
int iAddFlag = CTypeToString::WaypointDrawFlagsFromString(argv[i]);
if ( iAddFlag == -1 )
{
BULOG_E( pClient->GetEdict(), "Error, invalid draw flag(s). Can be 'none' / 'all' / 'next' or mix of: %s", CTypeToString::WaypointDrawFlagsToString(FWaypointDrawAll).c_str() );
return ECommandError;
}
FLAG_SET(iAddFlag, iFlags);
}
}
pClient->iWaypointDrawFlags = iFlags;
BULOG_I(pClient->GetEdict(), "Waypoints drawing is %s.", iFlags ? "on" : "off");
return ECommandPerformed;
}
TCommandResult CWaypointResetCommand::Execute( CClient* pClient, int argc, const char** argv )
{
if ( CConsoleCommand::Execute( pClient, argc, argv ) == ECommandPerformed )
return ECommandPerformed;
if ( pClient == NULL )
{
BLOG_W( "Please login to server to execute this command." );
return ECommandError;
}
Vector vOrigin( pClient->GetHead() );
pClient->iCurrentWaypoint = CWaypoints::GetNearestWaypoint( vOrigin );
BULOG_I(pClient->GetEdict(), "Current waypoint %d.", pClient->iCurrentWaypoint);
return ECommandPerformed;
}
TCommandResult CWaypointCreateCommand::Execute( CClient* pClient, int argc, const char** argv )
{
if ( CConsoleCommand::Execute( pClient, argc, argv ) == ECommandPerformed )
return ECommandPerformed;
if ( pClient == NULL )
{
BLOG_W( "Please login to server to execute this command." );
return ECommandError;
}
ANALIZE_WAYPOINTS_CHECK();
if ( !pClient->IsAlive() )
{
BULOG_W(pClient->GetEdict(), "Error, you need to be alive to create waypoints (bots can't just fly around you know).");
return ECommandError;
}
TWaypointId id = CWaypoints::Add( pClient->GetHead(), FWaypointNone );
pClient->iCurrentWaypoint = id;
// Check if player is crouched.
float fHeight = pClient->GetPlayerInfo()->GetPlayerMaxs().z - pClient->GetPlayerInfo()->GetPlayerMins().z + 1;
bool bIsCrouched = ( fHeight < CMod::GetVar( EModVarPlayerHeight ) );
if (pClient->bAutoCreatePaths)
CWaypoints::CreateAutoPaths(id, bIsCrouched);
else if ( CWaypoint::IsValid( pClient->iDestinationWaypoint ) )
CWaypoints::CreatePathsWithAutoFlags( pClient->iDestinationWaypoint, pClient->iCurrentWaypoint, bIsCrouched );
BULOG_I(pClient->GetEdict(), "Waypoint %d added.", id);
CItems::MapUnloaded();
CItems::MapLoaded(false);
return ECommandPerformed;
}
CWaypointRemoveCommand::CWaypointRemoveCommand()
{
m_sCommand = "remove";
m_sHelp = "delete waypoints";
m_sDescription = "Parameters can be: current / destination / other waypoint id(s)";
m_iAccessLevel = FCommandAccessWaypoint;
m_cAutoCompleteArguments.push_back(EConsoleAutoCompleteArgWaypoint);
m_cAutoCompleteValues.push_back(StringVector());
}
TCommandResult CWaypointRemoveCommand::Execute( CClient* pClient, int argc, const char** argv )
{
if ( CConsoleCommand::Execute( pClient, argc, argv ) == ECommandPerformed )
return ECommandPerformed;
if ( pClient == NULL )
{
BLOG_W( "Please login to server to execute this command." );
return ECommandError;
}
ANALIZE_WAYPOINTS_CHECK();
if ( argc > 1 )
{
BLOG_W( "Error, invalid parameters count." );
return ECommandError;
}
TWaypointId id = GetWaypointId( 0, argc, argv, pClient, pClient->iCurrentWaypoint );
if ( !CWaypoints::IsValid(id) )
{
BULOG_W(pClient->GetEdict(), "Error, invalid given or current waypoint (move closer to some waypoint).");
return ECommandError;
}
CWaypoints::Remove(id);
BULOG_I(pClient->GetEdict(), "Waypoint %d deleted.", id);
CPlayers::InvalidatePlayersWaypoints();
CItems::MapUnloaded();
CItems::MapLoaded(false);
return ECommandPerformed;
}
TCommandResult CWaypointMoveCommand::Execute( CClient* pClient, int argc, const char** argv )
{
if ( CConsoleCommand::Execute( pClient, argc, argv ) == ECommandPerformed )
return ECommandPerformed;
if ( pClient == NULL )
{
BLOG_W( "Please login to server to execute this command." );
return ECommandError;
}
if ( argc > 1 )
{
BLOG_W( "Error, invalid parameters count." );
return ECommandError;
}
TWaypointId id = GetWaypointId( 0, argc, argv, pClient, pClient->iCurrentWaypoint );
if ( !CWaypoints::IsValid(id) )
{
BULOG_W(pClient->GetEdict(), "Error, invalid waypoint %s (move closer to some waypoint).", argc == 0 ? "current" : argv[0]);
return ECommandError;
}
Vector vOrigin( pClient->GetHead() );
CWaypoints::Move(id, vOrigin);
BULOG_I(pClient->GetEdict(), "Set new position for waypoint %d (%d, %d, %d).", id, (int)vOrigin.x, (int)vOrigin.y, (int)vOrigin.z);
CItems::MapUnloaded();
CItems::MapLoaded(false);
return ECommandPerformed;
}
TCommandResult CWaypointAutoCreateCommand::Execute( CClient* pClient, int argc, const char** argv )
{
if ( CConsoleCommand::Execute( pClient, argc, argv ) == ECommandPerformed )
return ECommandPerformed;
if ( pClient == NULL )
{
BLOG_W( "Please login to server to execute this command." );
return ECommandError;
}
if ( argc == 0 )
{
BULOG_I( pClient->GetEdict(), pClient->bAutoCreateWaypoints ? "Auto create waypoints is on." : "Auto create waypoints is off." );
return ECommandPerformed;
}
ANALIZE_WAYPOINTS_CHECK();
int iValue = -1;
if ( argc == 1 )
iValue = CTypeToString::BoolFromString(argv[0]);
if ( iValue == -1 )
{
BULOG_W(pClient->GetEdict(), "Error, invalid argument (must be 'on' or 'off').");
return ECommandError;
}
pClient->bAutoCreateWaypoints = iValue != 0;
BULOG_I(pClient->GetEdict(), iValue ? "Auto create waypoints is on." : "Auto create waypoints is off.");
return ECommandPerformed;
}
TCommandResult CWaypointClearCommand::Execute( CClient* pClient, int argc, const char** argv )
{
if ( CConsoleCommand::Execute( pClient, argc, argv ) == ECommandPerformed )
return ECommandPerformed;
if ( pClient == NULL )
{
BLOG_W( "Please login to server to execute this command." );
return ECommandError;
}
ANALIZE_WAYPOINTS_CHECK();
int iSize = CWaypoints::Size();
CWaypoints::Clear();
BULOG_I( pClient->GetEdict(), "%d waypoints deleted.", iSize );
CItems::MapUnloaded();
CItems::MapLoaded(false);
return ECommandPerformed;
}
TCommandResult CWaypointAddTypeCommand::Execute( CClient* pClient, int argc, const char** argv )
{
if ( CConsoleCommand::Execute( pClient, argc, argv ) == ECommandPerformed )
return ECommandPerformed;
if ( pClient == NULL )
{
BLOG_W( "Please login to server to execute this command." );
return ECommandError;
}
if ( !CWaypoint::IsValid(pClient->iCurrentWaypoint) )
{
BULOG_W(pClient->GetEdict(), "Error, no waypoint nearby to add type (move closer to waypoint).");
return ECommandError;
}
// Retrieve flags from string arguments.
TWaypointFlags iFlags = FWaypointNone;
for ( int i=0; i < argc; ++i )
{
int iAddFlag = CTypeToString::WaypointFlagsFromString(argv[i]);
if ( iAddFlag == -1 )
{
BULOG_E( pClient->GetEdict(), "Error, invalid waypoint flag: %s. Can be one of: %s", argv[i], CTypeToString::WaypointFlagsToString(FWaypointAll).c_str() );
return ECommandError;
}
FLAG_SET(iAddFlag, iFlags);
}
if ( iFlags == FWaypointNone )
{
BULOG_E(pClient->GetEdict(), "Error, specify at least one waypoint type. Can be one of: %s.", CTypeToString::WaypointFlagsToString(FWaypointAll).c_str());
return ECommandError;
}
else
{
CWaypoint& w = CWaypoints::Get(pClient->iCurrentWaypoint);
bool bAngle1 = FLAG_SOME_SET( FWaypointCamper | FWaypointSniper | FWaypointArmorMachine | FWaypointHealthMachine | FWaypointButton | FWaypointUse, w.iFlags );
bool bAngle2 = FLAG_SOME_SET(FWaypointCamper | FWaypointSniper, w.iFlags);
bool bWeapon = FLAG_SOME_SET(FWaypointAmmo | FWaypointWeapon, w.iFlags);
bool bArmor = FLAG_SOME_SET(FWaypointArmor, w.iFlags);
bool bHealth = FLAG_SOME_SET(FWaypointHealth, w.iFlags);
if ( (bAngle1 && bWeapon) || ( bAngle2 && (bWeapon || bArmor || bHealth) ) )
{
BULOG_W(pClient->GetEdict(), "Error, you can't mix these waypoint types.");
return ECommandError;
}
FLAG_SET(iFlags, w.iFlags);
BULOG_I(pClient->GetEdict(), "Types %s (%d) added to waypoint %d.", CTypeToString::WaypointFlagsToString(iFlags).c_str(), iFlags, pClient->iCurrentWaypoint);
return ECommandPerformed;
}
}
TCommandResult CWaypointAnalyzeToggleCommand::Execute( CClient* pClient, int argc, const char** argv )
{
if ( CConsoleCommand::Execute( pClient, argc, argv ) == ECommandPerformed )
return ECommandPerformed;
edict_t* pEdict = ( pClient ) ? pClient->GetEdict() : NULL;
if ( !CBotrixPlugin::instance->bMapRunning )
{
BULOG_W( pEdict, "Error: no map is loaded." );
return ECommandError;
}
if ( CWaypoints::IsAnalyzing() )
{
CWaypoints::StopAnalyzing();
BULOG_W( pEdict, "Stopped analyzing waypoints." );
}
else
{
for ( int iPlayer = 0; iPlayer < CPlayers::Size(); ++iPlayer )
{
CClient *pClient = (CClient *)CPlayers::Get( iPlayer );
if ( pClient && !pClient->IsBot() && pClient->IsAutoCreatingWaypoints() )
{
BULOG_W( pEdict, "Someone (%s) is auto-creating waypoints, you can't mix it with analyze command.", pClient->GetName() );
return ECommandError;
}
}
CWaypoints::Analyze( pEdict );
}
return ECommandPerformed;
}
TCommandResult WaypointAnalyzeAux( CClient* pClient, int argc, const char** argv, CWaypoints::TAnalyzeWaypoints iWhich )
{
edict_t* pEdict = ( pClient ) ? pClient->GetEdict() : NULL;
if ( !CBotrixPlugin::instance->bMapRunning )
{
BULOG_W( pEdict, "Error: no map is loaded." );
return ECommandError;
}
if ( argc == 1 && sClear == argv[ 0 ] )
{
CWaypoints::AnalyzeClear( iWhich );
return ECommandPerformed;
}
int iAdd = 1;
if ( argc > 0 )
iAdd = CTypeToString::BoolFromString( argv[ 0 ] );
if ( iAdd == -1 )
{
BULOG_W( pClient->GetEdict(), "Error, invalid argument '%s' (must be 'on' or 'off').", argv[ 0 ] );
return ECommandError;
}
TWaypointId iWaypoint = GetWaypointId( 1, argc, argv, pClient, pClient->iCurrentWaypoint );
if ( !CWaypoints::IsValid( iWaypoint ) )
{
BULOG_W( pClient->GetEdict(), "Error, invalid waypoint." );
return ECommandError;
}
CWaypoints::AnalyzeAddPosition( iWaypoint, iAdd != 0, iWhich );
return ECommandPerformed;
}
CWaypointAnalyzeCreateCommand::CWaypointAnalyzeCreateCommand()
{
m_sCommand = "create";
m_sHelp = "create given waypoint during map analyze";
m_sDescription = "Parameter: (on / off / clear) (current / destination / waypoint id). 'clear' will remove all positions to create waypoints.";
m_iAccessLevel = FCommandAccessWaypoint;
StringVector args0;
args0.push_back( sOn );
args0.push_back( sOff );
args0.push_back( sClear );
m_cAutoCompleteArguments.push_back( EConsoleAutoCompleteArgValues );
m_cAutoCompleteValues.push_back( args0 );
StringVector args1;
args1.push_back( sCurrent );
args1.push_back( sDestination );
m_cAutoCompleteArguments.push_back( EConsoleAutoCompleteArgValues );
m_cAutoCompleteValues.push_back( args1 );
}
TCommandResult CWaypointAnalyzeCreateCommand::Execute( CClient* pClient, int argc, const char** argv )
{
if ( CConsoleCommand::Execute( pClient, argc, argv ) == ECommandPerformed )
return ECommandPerformed;
return WaypointAnalyzeAux( pClient, argc, argv, CWaypoints::EAnalyzeWaypointsAdd );
}
CWaypointAnalyzeDebugCommand::CWaypointAnalyzeDebugCommand()
{
m_sCommand = "debug";
m_sHelp = "show collision lines for given waypoint during map analyze";
m_sDescription = "Parameter: (on / off / clear) (current / destination / waypoint id). 'clear' will remove all debug waypoints.";
m_iAccessLevel = FCommandAccessWaypoint;
StringVector args0;
args0.push_back( sOn );
args0.push_back( sOff );
args0.push_back( sClear );
m_cAutoCompleteArguments.push_back( EConsoleAutoCompleteArgValues );
m_cAutoCompleteValues.push_back( args0 );
StringVector args1;
args1.push_back( sCurrent );
args1.push_back( sDestination );
m_cAutoCompleteArguments.push_back( EConsoleAutoCompleteArgValues );
m_cAutoCompleteValues.push_back( args1 );
}
TCommandResult CWaypointAnalyzeDebugCommand::Execute( CClient* pClient, int argc, const char** argv )
{
if ( CConsoleCommand::Execute( pClient, argc, argv ) == ECommandPerformed )
return ECommandPerformed;
return WaypointAnalyzeAux(pClient, argc, argv, CWaypoints::EAnalyzeWaypointsDebug);
}
CWaypointAnalyzeOmitCommand::CWaypointAnalyzeOmitCommand()
{
m_sCommand = "omit";
m_sHelp = "omit given waypoint next time analyze runs";
m_sDescription = "Parameter: (on / off / clear) (current / destination / waypoint id). Sometimes analyze adds waypoints at invalid places. This command will disable analyze for a given waypoint. 'clear' will remove all omited waypoints.";
m_iAccessLevel = FCommandAccessWaypoint;
StringVector args0;
args0.push_back( sOn );
args0.push_back( sOff );
args0.push_back( sClear );
m_cAutoCompleteArguments.push_back( EConsoleAutoCompleteArgValues );
m_cAutoCompleteValues.push_back( args0 );
StringVector args1;
args1.push_back( sCurrent );
args1.push_back( sDestination );
m_cAutoCompleteArguments.push_back( EConsoleAutoCompleteArgValues );
m_cAutoCompleteValues.push_back( args1 );
}
TCommandResult CWaypointAnalyzeOmitCommand::Execute( CClient* pClient, int argc, const char** argv )
{
if ( CConsoleCommand::Execute( pClient, argc, argv ) == ECommandPerformed )
return ECommandPerformed;
return WaypointAnalyzeAux( pClient, argc, argv, CWaypoints::EAnalyzeWaypointsOmit );
}
TCommandResult CWaypointAnalyzeTraceCommand::Execute( CClient* pClient, int argc, const char** argv )