forked from borzh/botrix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsole_commands.cpp
More file actions
3046 lines (2675 loc) · 103 KB
/
console_commands.cpp
File metadata and controls
3046 lines (2675 loc) · 103 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <good/string_buffer.h>
#include <good/string_utils.h>
#include "bot.h"
#include "clients.h"
#include "config.h"
#include "console_commands.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;
const good::string sHelp("help"); // TODO: all commands.
const good::string sAll("all");
const good::string sNone("none");
const good::string sNext("next");
const good::string sWeapon = "weapon";
const good::string sAmmo = "ammo";
const good::string sHealth = "health";
const good::string sArmor = "armor";
const good::string sButton = "button";
const good::string sFirstAngle = "first";
const good::string sSecondAngle = "second";
extern char* szMainBuffer;
extern int iMainBufferSize;
//----------------------------------------------------------------------------------------------------------------
// 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( char* partial, int partialLength, CUtlVector<CUtlString>& cCommands, int charIndex )
{
int result = 0;
int iLen = partialLength - charIndex;
const char* szSubPartial = &partial[charIndex];
if ( iLen <= m_sCommand.size() )
{
if ( strncmp( m_sCommand.c_str(), szSubPartial, iLen ) == 0 )
{
partial[charIndex] = 0;
// Autocomplete only command name.
CUtlString sStr( partial );
sStr.Append( m_sCommand.c_str() );
cCommands.AddToTail( sStr );
result++;
}
}
else
{
if ( (m_cAutoCompleteArguments.size() > 0) &&
(strncmp( m_sCommand.c_str(), szSubPartial, m_sCommand.size() ) == 0) )
{
szSubPartial += m_sCommand.size() + 1;
iLen -= m_sCommand.size() + 1;
while ( *szSubPartial == ' ' )
{
++szSubPartial;
--iLen;
}
// Autocomplete command name with arguments.
good::string sArg(szSubPartial, false, false, iLen);
int lastSpace = sArg.rfind(' ');
if ( !m_bAutoCompleteOnlyOneArgument || (lastSpace == good::string::npos) )
{
lastSpace++; // Include last space.
good::string sPartArg(&sArg[lastSpace], true, true, iLen - lastSpace);
good::string sCmd(partial, false, false, sArg.c_str() - partial + lastSpace);
for ( int i = 0; i < m_cAutoCompleteArguments.size(); ++i )
{
const good::string& arg = m_cAutoCompleteArguments[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
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( char* partial, int partialLength, CUtlVector< CUtlString > &cCommands, int charIndex )
{
int result = 0;
int command_size = m_sCommand.size();
if ( command_size >= partialLength - charIndex ) // Only add command to commands array.
{
if ( strncmp(m_sCommand.c_str(), &partial[charIndex], partialLength - charIndex) == 0 )
{
// Autocomplete only command name.
partial[charIndex] = 0;
CUtlString sStr( partial );
sStr.Append( m_sCommand.c_str() );
cCommands.AddToTail( sStr );
result++;
}
}
else
{
if ( strncmp(m_sCommand.c_str(), &partial[charIndex], command_size) == 0 )
{
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, partialLength, cCommands, partialLength-iLen);
}
}
return result;
}
#endif // BOTRIX_OLD_COMMAND_COMPLETION
TCommandResult CConsoleCommandContainer::Execute( CClient* pClient, int argc, const char** argv )
{
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 );
}
//----------------------------------------------------------------------------------------------------------------
// 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;
m_cAutoCompleteArguments.push_back(sNone);
for (int i=0; i < EWaypointDrawFlagTotal; ++i)
m_cAutoCompleteArguments.push_back( CTypeToString::WaypointDrawFlagsToString(1<<i).duplicate() );
m_cAutoCompleteArguments.push_back(sAll);
}
TCommandResult CWaypointDrawFlagCommand::Execute( CClient* pClient, int argc, const char** argv )
{
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 ( 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 ( pClient == NULL )
{
BLOG_W( "Please login to server to execute this command." );
return ECommandError;
}
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::iPlayerHeight );
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);
return ECommandPerformed;
}
TCommandResult CWaypointRemoveCommand::Execute( CClient* pClient, int argc, const char** argv )
{
if ( pClient == NULL )
{
BLOG_W( "Please login to server to execute this command." );
return ECommandError;
}
TWaypointId id = -1;
if (argc == 0)
id = pClient->iCurrentWaypoint;
else if (argc == 1)
sscanf(argv[0], "%d", &id);
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);
// Invalidate current / destination waypoints for all players.
for (int i=0; i < CPlayers::Size(); ++i)
{
CPlayer* pPlayer = CPlayers::Get(i);
if ( pPlayer )
{
if ( pPlayer->IsBot() )
{
pPlayer->iCurrentWaypoint = -1; // Force bot move failure, because path can contain removed waypoint.
pPlayer->iNextWaypoint = -1;
}
else
{
CClient* pClient = (CClient*)pPlayer;
if ( pClient->iCurrentWaypoint == id )
pClient->iCurrentWaypoint = -1;
else if ( pClient->iCurrentWaypoint > id )
pClient->iCurrentWaypoint--;
if ( pClient->iDestinationWaypoint == id )
pClient->iDestinationWaypoint = -1;
else if ( pClient->iDestinationWaypoint > id )
pClient->iDestinationWaypoint--;
}
}
}
return ECommandPerformed;
}
TCommandResult CWaypointMoveCommand::Execute( CClient* pClient, int argc, const char** argv )
{
if ( pClient == NULL )
{
BLOG_W( "Please login to server to execute this command." );
return ECommandError;
}
TWaypointId id = -1;
if (argc == 0)
id = pClient->iDestinationWaypoint;
else if ( (argc == 1) || (argc == 4) )
sscanf(argv[0], "%d", &id);
else if ( argc != 3 )
{
BULOG_W(pClient->GetEdict(), "Error, invalid arguments count (waypoint id & point x/y/z).");
return ECommandError;
}
Vector vOrigin( pClient->GetHead() );
if ( argc >= 3 )
{
int iValue = 0;
sscanf(argv[argc - 3], "%d", &iValue); vOrigin.x = iValue;
sscanf(argv[argc - 2], "%d", &iValue); vOrigin.y = iValue;
sscanf(argv[argc - 1], "%d", &iValue); vOrigin.z = iValue;
}
if ( !CWaypoints::IsValid(id) )
{
BULOG_W(pClient->GetEdict(), "Error, invalid given or destination waypoint.");
return ECommandError;
}
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);
return ECommandPerformed;
}
TCommandResult CWaypointAutoCreateCommand::Execute( CClient* pClient, int argc, const char** argv )
{
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;
}
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 ( pClient == NULL )
{
BLOG_W( "Please login to server to execute this command." );
return ECommandError;
}
// Invalidate current / next / destination waypoints for all players.
for ( int i = 0; i < CPlayers::Size(); ++i )
{
CPlayer* pPlayer = CPlayers::Get(i);
if ( pPlayer )
{
pPlayer->iCurrentWaypoint = pPlayer->iNextWaypoint = -1;
if ( !pPlayer->IsBot() )
((CClient*)pPlayer)->iDestinationWaypoint = -1;
}
}
CWaypoints::Clear();
BULOG_I(pClient->GetEdict(), "All waypoints deleted.");
return ECommandPerformed;
}
TCommandResult CWaypointAddTypeCommand::Execute( CClient* pClient, int argc, const char** argv )
{
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, 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 CWaypointRemoveTypeCommand::Execute( CClient* pClient, int argc, const char** argv )
{
if ( pClient == NULL )
{
BLOG_W( "Please login to server to execute this command." );
return ECommandError;
}
TWaypointId id = -1;
if (argc == 0)
id = pClient->iCurrentWaypoint;
else if (argc == 1)
sscanf(argv[0], "%d", &id);
if ( CWaypoints::IsValid(id) )
{
CWaypoint& w = CWaypoints::Get(id);
w.iFlags = FWaypointNone;
BULOG_I(pClient->GetEdict(), "Waypoint %d has no type now.", id);
return ECommandPerformed;
}
else
{
BULOG_W(pClient->GetEdict(), "Error, no waypoint nearby to remove type (move closer to waypoint).");
return ECommandError;
}
}
CWaypointArgumentCommand::CWaypointArgumentCommand()
{
m_sCommand = "angle";
m_sHelp = "set waypoint angles";
m_iAccessLevel = FCommandAccessWaypoint;
//m_cAutoCompleteArguments.push_back(sWeapon);
//m_cAutoCompleteArguments.push_back(sAmmo);
//m_cAutoCompleteArguments.push_back(sHealth);
//m_cAutoCompleteArguments.push_back(sArmor);
//m_cAutoCompleteArguments.push_back(sButton);
m_cAutoCompleteArguments.push_back(sFirstAngle);
m_cAutoCompleteArguments.push_back(sSecondAngle);
}
TCommandResult CWaypointArgumentCommand::Execute( CClient* pClient, int argc, const char** argv )
{
if ( pClient == NULL )
{
BLOG_W( "Please login to server to execute this command." );
return ECommandError;
}
TWaypointId id = pClient->iCurrentWaypoint;
if ( !CWaypoints::IsValid(id) )
{
BULOG_W(pClient->GetEdict(), "Error, no waypoint nearby (move closer to waypoint).");
return ECommandError;
}
CWaypoint& w = CWaypoints::Get(pClient->iCurrentWaypoint);
bool bAngle1 = FLAG_SOME_SET(FWaypointCamper | FWaypointSniper | FWaypointArmorMachine | FWaypointHealthMachine | FWaypointButton | FWaypointSeeButton, 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);
bool bButton = FLAG_SOME_SET(FWaypointButton | FWaypointSeeButton, w.iFlags);
if ( argc == 0 )
{
if ( bWeapon )
BULOG_I(pClient->GetEdict(), "Weapon index %d, subindex %d.", CWaypoint::GetWeaponIndex(w.iArgument), CWaypoint::GetWeaponSubIndex(w.iArgument));
if ( FLAG_ALL_SET_OR_0(FWaypointAmmo, w.iFlags) )
{
bool bIsSecondary; int iAmmo = CWaypoint::GetAmmo(bIsSecondary, w.iArgument);
BULOG_I(pClient->GetEdict(), "Weapon ammo %d, secondary %s.", iAmmo, bIsSecondary ? "yes" : "no");
}
if ( bHealth )
BULOG_I(pClient->GetEdict(), "Health %d.", CWaypoint::GetHealth(w.iArgument));
if ( bArmor )
BULOG_I(pClient->GetEdict(), "Armor %d.", CWaypoint::GetArmor(w.iArgument));
if ( bButton )
BULOG_I(pClient->GetEdict(), "Button %d.", CWaypoint::GetButton(w.iArgument));
if ( bAngle1 )
{
QAngle a1; CWaypoint::GetFirstAngle(a1, w.iArgument);
BULOG_I(pClient->GetEdict(), "Angle 1 (pitch, yaw): (%.0f, %.0f).", a1.x, a1.y);
}
if ( bAngle2 )
{
QAngle a2; CWaypoint::GetSecondAngle(a2, w.iArgument);
BULOG_I(pClient->GetEdict(), "Angle 2 (pitch, yaw): (%.0f, %.0f).", a2.x, a2.y);
}
return ECommandPerformed;
}
if ( sHelp == argv[0] )
{
BULOG_I(pClient->GetEdict(), "You can add next arguments:");
BULOG_I(pClient->GetEdict(), " - 'first_angle': set your current angles as waypoint first angles (camper, sniper, machines)");
BULOG_I(pClient->GetEdict(), " - 'second_angle': set your current angles as second angles (camper, sniper)");
return ECommandPerformed;
}
int iArgument = w.iArgument;
QAngle angClient;
pClient->GetEyeAngles(angClient);
CUtil::DeNormalizeAngle(angClient.x);
CUtil::DeNormalizeAngle(angClient.y);
BASSERT( -90.0f <= angClient.x && angClient.x <= 90.0f, return ECommandError );
for ( int i=0; i < argc; ++i )
{
if ( sWeapon == argv[i] )
{
if ( i+2 >= argc )
{
BULOG_W(pClient->GetEdict(), "Error, you must provide 2 arguments for weapon (index and subindex).");
return ECommandError;
}
if ( bAngle1 )
{
BULOG_W(pClient->GetEdict(), "Error, you can't mix weapon/ammo with angles.");
return ECommandError;
}
if ( !bWeapon )
{
BULOG_W(pClient->GetEdict(), "Error, first you need to set waypoint type accordingly (weapon/ammo).");
return ECommandError;
}
int i1 = -1, i2 = -1;
sscanf(argv[++i], "%d", &i1);
sscanf(argv[++i], "%d", &i2);
if ( (i1 < 0) || (i1 > 15) || (i2 < 0) || (i2 > 15) )
{
BULOG_W(pClient->GetEdict(), "Error, invalid weapon arguments (must be from 0 to 15).");
return ECommandError;
}
CWaypoint::SetWeapon(i1, i2, iArgument);
}
else if ( sAmmo == argv[i] )
{
if ( i+2 >= argc )
{
BULOG_W(pClient->GetEdict(), "Error, you must provide 2 arguments to ammo (ammo amount and 0=primary/1=secondary).");
return ECommandError;
}
if ( bAngle1 )
{
BULOG_W(pClient->GetEdict(), "Error, you can't mix weapon/ammo with angles.");
return ECommandError;
}
if ( !FLAG_SOME_SET(FWaypointAmmo, w.iFlags) )
{
BULOG_W(pClient->GetEdict(), "Error, first you need to set waypoint type accordingly (ammo).");
return ECommandError;
}
int i1 = -1, i2 = -1;
sscanf(argv[++i], "%d", &i1);
sscanf(argv[++i], "%d", &i2);
if ( (i1 < 0) || (i1 > 127) || (i2 < 0) || (i2 > 1) )
{
BULOG_W(pClient->GetEdict(), "Error, invalid ammo arguments (must be 0 .. 127 / 0 .. 1).");
return ECommandError;
}
CWaypoint::SetAmmo(i1, i2 != 0, iArgument);
}
else if ( sHealth == argv[i] )
{
if ( i+1 >= argc )
{
BULOG_W(pClient->GetEdict(), "Error, you must provide 1 argument to health/health_machine (health amount).");
return ECommandError;
}
if ( bAngle2 )
{
BULOG_W(pClient->GetEdict(), "Error, you can't mix health with 2 angles.");
return ECommandError;
}
if ( !bHealth )
{
BULOG_W(pClient->GetEdict(), "Error, first you need to set waypoint type accordingly (health/health_machine).");
return ECommandError;
}
int i1 = -1;
sscanf(argv[++i], "%d", &i1);
if ( (i1 < 0) || (i1 > 100) )
{
BULOG_W(pClient->GetEdict(), "Error, invalid health argument (must be from 0 to 100).");
return ECommandError;
}
CWaypoint::SetHealth(i1, iArgument);
}
else if ( sArmor == argv[i] )
{
if ( i+1 >= argc )
{
BULOG_W(pClient->GetEdict(), "Error, you must provide 1 argument to armor/armor_machine (armor amount).");
return ECommandError;
}
if ( bAngle2 )
{
BULOG_W(pClient->GetEdict(), "Error, you can't mix armor with 2 angles.");
return ECommandError;
}
if ( !bArmor )
{
BULOG_W(pClient->GetEdict(), "Error, first you need to set waypoint type accordingly (armor/armor_machine).");
return ECommandError;
}
int i1 = -1;
sscanf(argv[++i], "%d", &i1);
if ( (i1 < 0) || (i1 > 100) )
{
BULOG_W(pClient->GetEdict(), "Error, invalid armor argument (must be from 0 to 100).");
return ECommandError;
}
CWaypoint::SetArmor(i1, iArgument);
}
else if ( sButton == argv[i] )
{
if ( i+1 >= argc )
{
BULOG_W(pClient->GetEdict(), "Error, you must provide 1 argument to button (button index).");
return ECommandError;
}
if ( bAngle2 )
{
BULOG_W(pClient->GetEdict(), "Error, you can't mix button with 2 angles.");
return ECommandError;
}
if ( !bButton )
{
BULOG_W(pClient->GetEdict(), "Error, first you need to set waypoint type accordingly (button/see_button).");
return ECommandError;
}
int i1 = -1;
sscanf(argv[++i], "%d", &i1);
int iButtonsCount = CItems::GetItems(EItemTypeButton).size();
if ( (i1 <= 0) || (i1 > iButtonsCount) )
{
BULOG_W(pClient->GetEdict(), "Error, invalid button argument (must be from 1 to %d).", iButtonsCount);
return ECommandError;
}
CWaypoint::SetButton(i1, iArgument);
}
else if ( sFirstAngle == argv[i] )
{
if ( bWeapon )
{
BULOG_W(pClient->GetEdict(), "Error, you can't mix weapon/ammo with angles.");
return ECommandError;
}
if ( !bAngle1 )
{
BULOG_W(pClient->GetEdict(), "Error, first you need to set waypoint type accordingly (camper/sniper/armor_machine/health_machine).");
return ECommandError;
}
int iPitch = angClient.x;
int iYaw = angClient.y;
if ( (CWaypoint::MIN_ANGLE_PITCH <= iPitch) && (iPitch <= CWaypoint::MAX_ANGLE_PITCH) &&
(CWaypoint::MIN_ANGLE_PITCH <= iPitch) && (iPitch <= CWaypoint::MAX_ANGLE_PITCH) )
CWaypoint::SetFirstAngle(iPitch, iYaw, iArgument);
else
{
BULOG_W(pClient->GetEdict(), "Error, up/down angle (pitch) must be from -64 to 63.");
return ECommandError;
}
}
else if ( sSecondAngle == argv[i] )
{
if ( bWeapon || bArmor || bHealth )
{
BULOG_W(pClient->GetEdict(), "Error, you can't mix weapon/ammo/health/armor with two angles.");
return ECommandError;
}
if ( !bAngle2 )
{
BULOG_W(pClient->GetEdict(), "Error, first you need to set waypoint type accordingly (camper/sniper).");
return ECommandError;
}
int iPitch = angClient.x;
int iYaw = angClient.y;
if ( (CWaypoint::MIN_ANGLE_PITCH <= iPitch) && (iPitch <= CWaypoint::MAX_ANGLE_PITCH) &&
(CWaypoint::MIN_ANGLE_PITCH <= iPitch) && (iPitch <= CWaypoint::MAX_ANGLE_PITCH) )
CWaypoint::SetSecondAngle(iPitch, iYaw, iArgument);
else
{
BULOG_W(pClient->GetEdict(), "Error, up/down angle (pitch) must be from -64 to 63.");
return ECommandError;
}
}
else
{
BULOG_W(pClient->GetEdict(), "Error, invalid argument %s.", argv[i]);
return ECommandError;
}
}
w.iArgument = iArgument;
return ECommandPerformed;
}
TCommandResult CWaypointInfoCommand::Execute( CClient* pClient, int argc, const char** argv )
{
if ( pClient == NULL )
{
BLOG_W( "Please login to server to execute this command." );
return ECommandError;
}
TWaypointId id = -1;
if (argc == 0)
id = pClient->iCurrentWaypoint;
else if (argc == 1)
sscanf(argv[0], "%d", &id);
if ( CWaypoints::IsValid(id) )
{
CWaypoint& w = CWaypoints::Get(id);
const good::string& sFlags = CTypeToString::WaypointFlagsToString(w.iFlags);
BULOG_I(pClient->GetEdict(), "Waypoint id %d: flags %s", id, (sFlags.size() > 0) ? sFlags.c_str() : sNone.c_str());
BULOG_I(pClient->GetEdict(), "Origin: %.0f %.0f %.0f", w.vOrigin.x, w.vOrigin.y, w.vOrigin.z);
return ECommandPerformed;
}