forked from Bots-United/jk_botti
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.cpp
1417 lines (1195 loc) · 45.1 KB
/
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
//
// JK_Botti - be more human!
//
// commands.cpp
//
#ifndef _WIN32
#include <string.h>
#endif
#include <extdll.h>
#include <dllapi.h>
#include <h_export.h>
#include <meta_api.h>
#include <entity_state.h>
#include <pm_defs.h>
#include <time.h>
#include "bot.h"
#include "bot_func.h"
#include "waypoint.h"
#include "bot_skill.h"
#include "bot_weapons.h"
#include "bot_query_hook.h"
extern char g_argv[1024*3];
extern char g_arg1[1024];
extern char g_arg2[1024];
extern char g_arg3[1024];
extern qboolean g_waypoint_on;
extern qboolean g_auto_waypoint;
extern qboolean g_path_waypoint;
extern qboolean g_path_waypoint_enable;
extern qboolean g_waypoint_updated;
extern int num_waypoints; // number of waypoints currently in use
extern WAYPOINT waypoints[MAX_WAYPOINTS];
extern float wp_display_time[MAX_WAYPOINTS];
extern bot_t bots[32];
extern qboolean b_observer_mode;
extern qboolean b_botdontshoot;
extern qboolean g_in_intermission;
extern BOOL wp_matrix_save_on_mapend;
extern int team_balancetype;
extern char *team_blockedlist;
extern float bot_check_time;
extern float bot_cfg_pause_time;
extern int randomize_bots_on_mapchange;
extern float bot_think_spf;
extern int min_bots;
extern int max_bots;
extern FILE *bot_cfg_fp;
extern int bot_cfg_linenumber;
extern int submod_id;
extern int debug_minmax;
extern int default_bot_skill;
extern int bot_add_level_tag;
extern int bot_chat_percent;
extern int bot_taunt_percent;
extern int bot_whine_percent;
extern int bot_endgame_percent;
extern int bot_logo_percent;
extern int bot_chat_tag_percent;
extern int bot_chat_drop_percent;
extern int bot_chat_swap_percent;
extern int bot_chat_lower_percent;
extern qboolean b_random_color;
qboolean isFakeClientCommand = FALSE;
int fake_arg_count;
int bot_conntimes = 0;
int cfg_bot_record_size = 0;
cfg_bot_record_t * cfg_bot_record;
#define CFGCMD_TYPE 1
#define SRVCMD_TYPE 2
#define CLICMD_TYPE 3
#define PRINTFUNC_INFO 1
#define PRINTFUNC_ERROR 2
typedef void (*printfunc_t)(int printtype, void *arg, char *msg);
//
const cfg_bot_record_t * GetUnusedCfgBotRecord(void)
{
if(cfg_bot_record_size <= 0)
return (const cfg_bot_record_t *)NULL;
//
int record_indexes[cfg_bot_record_size];
int num_records = 0;
record_indexes[0] = 0;
// collect unused records
for(int cfgindex = 0; cfgindex < cfg_bot_record_size; cfgindex++)
{
int used = 0;
for(int index = 0; index < 32; index++)
{
if(bots[index].is_used)
{
if(bots[index].cfg_bot_index == cfgindex)
{
used = 1;
break;
}
}
}
if(used)
continue;
record_indexes[num_records++] = cfgindex;
}
if(num_records <= 0)
return (const cfg_bot_record_t *)NULL;
// random pick one of unused records
int pick = RANDOM_LONG2(0, num_records-1);
//
return(&cfg_bot_record[record_indexes[pick]]);
}
//
void FreeCfgBotRecord(void)
{
if(cfg_bot_record_size > 0 && cfg_bot_record_size)
{
for(int i = 0; i < cfg_bot_record_size; i++)
{
if(cfg_bot_record[i].name)
free(cfg_bot_record[i].name);
if(cfg_bot_record[i].skin)
free(cfg_bot_record[i].skin);
}
free(cfg_bot_record);
}
cfg_bot_record = NULL;
cfg_bot_record_size = 0;
}
//
int AddToCfgBotRecord(const char *skin, const char *name, int skill, int top_color, int bottom_color)
{
int index = cfg_bot_record_size++;
cfg_bot_record = (cfg_bot_record_t*)realloc(cfg_bot_record, sizeof(cfg_bot_record_t) * cfg_bot_record_size);
cfg_bot_record[index].index = index;
cfg_bot_record[index].skin = (skin) ? strdup(skin) : NULL;
cfg_bot_record[index].name = (name) ? strdup(name) : NULL;
cfg_bot_record[index].skill = skill;
cfg_bot_record[index].top_color = top_color;
cfg_bot_record[index].bottom_color = bottom_color;
return(index);
}
//
static void UTIL_PrintBotInfo(const printfunc_t printfunc, void * arg)
{
//print out bot info
char msg[80];
int bot_index, count = 0;
for (bot_index = 0; bot_index < gpGlobals->maxClients; bot_index++)
{
if (bots[bot_index].is_used) {
count++;
safevoid_snprintf(msg, sizeof(msg), "Bot #%d\n", count);
printfunc(PRINTFUNC_INFO, arg, msg);
safevoid_snprintf(msg, sizeof(msg), " name: %s\n", bots[bot_index].name);
printfunc(PRINTFUNC_INFO, arg, msg);
safevoid_snprintf(msg, sizeof(msg), " skin: %s\n", bots[bot_index].skin);
printfunc(PRINTFUNC_INFO, arg, msg);
safevoid_snprintf(msg, sizeof(msg), " skill: %d\n", bots[bot_index].bot_skill + 1);
printfunc(PRINTFUNC_INFO, arg, msg);
safevoid_snprintf(msg, sizeof(msg), " got enemy: %s\n", (bots[bot_index].pBotEnemy != 0) ? "true" : "false");
printfunc(PRINTFUNC_INFO, arg, msg);
safevoid_snprintf(msg, sizeof(msg), "---\n");
printfunc(PRINTFUNC_INFO, arg, msg);
}
}
safevoid_snprintf(msg, sizeof(msg), "Total Bots: %d\n", count);
printfunc(PRINTFUNC_INFO, arg, msg);
}
//
static qboolean ProcessCommand(const int cmdtype, const printfunc_t printfunc, void * arg, const char * pcmd, const char * arg1, const char * arg2, const char * arg3, const char * arg4, const char * arg5)
{
char msg[128];
switch(cmdtype) {
default:
return FALSE;
case CFGCMD_TYPE:
case SRVCMD_TYPE:
case CLICMD_TYPE:
break;
}
if (FStrEq(pcmd, "info"))
{
UTIL_PrintBotInfo(printfunc, arg);
return TRUE;
}
else if (FStrEq(pcmd, "addbot"))
{
int cfg_bot_index = -1;
const char * skin = (arg1 && *arg1) ? arg1 : NULL;
const char * name = (arg2 && *arg2) ? arg2 : NULL;
int skill = (arg3 && *arg3) ? atoi(arg3) : default_bot_skill;
int top_color = (arg4 && *arg4) ? atoi(arg4) : -1;
int bottom_color = (arg5 && *arg5) ? atoi(arg5) : -1;
// save bots from config to special buffer
if(cmdtype == CFGCMD_TYPE)
cfg_bot_index = AddToCfgBotRecord(skin, name, skill, top_color, bottom_color);
// only add bots if max_bots not reached
if(max_bots == -1 || UTIL_GetClientCount() < max_bots)
{
BotCreate(skin, name, skill, top_color, bottom_color, cfg_bot_index);
if(cmdtype == CFGCMD_TYPE)
bot_cfg_pause_time = gpGlobals->time + 0.5;
}
bot_check_time = gpGlobals->time + 1.0;
return TRUE;
}
else if (FStrEq(pcmd, "show_waypoints"))
{
if ((arg1 != NULL) && (*arg1 != 0))
{
int temp = atoi(arg1);
if (temp)
g_waypoint_on = g_path_waypoint = TRUE;
else
g_waypoint_on = g_path_waypoint = FALSE;
}
g_path_waypoint = g_waypoint_on;
if (g_waypoint_on && g_path_waypoint)
printfunc(PRINTFUNC_INFO, arg, "waypoints are VISIBLE\n");
else
printfunc(PRINTFUNC_INFO, arg, "waypoints are HIDDEN\n");
return TRUE;
}
else if (FStrEq(pcmd, "debug_minmax"))
{
if ((arg1 != NULL) && (*arg1 != 0))
{
int temp = atoi(arg1);
if (temp)
debug_minmax = TRUE;
else
debug_minmax = FALSE;
}
if (debug_minmax)
printfunc(PRINTFUNC_INFO, arg, "debug_minmax mode ENABLED\n");
else
printfunc(PRINTFUNC_INFO, arg, "debug_minmax mode DISABLED\n");
return TRUE;
}
else if (FStrEq(pcmd, "observer"))
{
if ((arg1 != NULL) && (*arg1 != 0))
{
int temp = atoi(arg1);
if (temp)
b_observer_mode = TRUE;
else
b_observer_mode = FALSE;
}
if (b_observer_mode)
printfunc(PRINTFUNC_INFO, arg, "observer mode ENABLED\n");
else
printfunc(PRINTFUNC_INFO, arg, "observer mode DISABLED\n");
return TRUE;
}
else if (FStrEq(pcmd, "team_balancetype"))
{
if ((arg1 != NULL) && (*arg1 != 0))
{
int temp = atoi(arg1);
if (temp < 0)
temp = 0;
if (temp > 1)
temp = 1;
team_balancetype = temp;
}
safevoid_snprintf(msg, sizeof(msg), "team_balancetype is %d\n", team_balancetype);
printfunc(PRINTFUNC_INFO, arg, msg);
return TRUE;
}
else if (FStrEq(pcmd, "team_blockedlist"))
{
if ((arg1 != NULL) && (*arg1 != 0))
{
if(team_blockedlist)
free(team_blockedlist);
team_blockedlist = strdup(arg1);
}
if(!team_blockedlist)
team_blockedlist = strdup("");
safevoid_snprintf(msg, sizeof(msg), "team_blockedlist: %s\n", team_blockedlist);
printfunc(PRINTFUNC_INFO, arg, msg);
return TRUE;
}
else if (FStrEq(pcmd, "botskill"))
{
if ((arg1 != NULL) && (*arg1 != 0))
{
int temp = atoi(arg1);
if ((temp < 1) || (temp > 5))
printfunc(PRINTFUNC_ERROR, arg, "invalid botskill value!\n");
else
default_bot_skill = temp;
}
safevoid_snprintf(msg, sizeof(msg), "botskill is %d\n", default_bot_skill);
printfunc(PRINTFUNC_INFO, arg, msg);
return TRUE;
}
else if (FStrEq(pcmd, "bot_conntimes"))
{
if ((arg1 != NULL) && (*arg1 != 0))
{
int temp = atoi(arg1);
if ((temp < 0) || (temp > 1))
printfunc(PRINTFUNC_ERROR, arg, "invalid bot_conntimes value!\n");
else
bot_conntimes = temp;
}
if(!IS_DEDICATED_SERVER() && bot_conntimes != 0)
{
bot_conntimes = 0;
printfunc(PRINTFUNC_INFO, arg, "bot_conntimes is not supported on listenserver!");
}
safevoid_snprintf(msg, sizeof(msg), "bot_conntimes is %d (%s)\n", bot_conntimes, (bot_conntimes==0?"disabled":"enabled"));
printfunc(PRINTFUNC_INFO, arg, msg);
if(bot_conntimes == 0)
unhook_sendto_function();
else
hook_sendto_function();
return TRUE;
}
else if (FStrEq(pcmd, "randomize_bots_on_mapchange"))
{
if ((arg1 != NULL) && (*arg1 != 0))
{
randomize_bots_on_mapchange = !!atoi(arg1);
}
safevoid_snprintf(msg, sizeof(msg), "randomize_bots_on_mapchange is %s\n", (randomize_bots_on_mapchange?"on":"off"));
printfunc(PRINTFUNC_INFO, arg, msg);
return TRUE;
}
else if (FStrEq(pcmd, "bot_add_level_tag"))
{
if ((arg1 != NULL) && (*arg1 != 0))
{
bot_add_level_tag = !!atoi(arg1);
}
safevoid_snprintf(msg, sizeof(msg), "bot_add_level_tag is %s\n", (bot_add_level_tag?"on":"off"));
printfunc(PRINTFUNC_INFO, arg, msg);
return TRUE;
}
else if (FStrEq(pcmd, "botthinkfps"))
{
if ((arg1 != NULL) && (*arg1 != 0))
{
int temp = atoi(arg1);
if ((temp < 1) || (temp > 100))
printfunc(PRINTFUNC_ERROR, arg, "invalid botthinkfps value!\n");
else
bot_think_spf = 1.0 / (float)temp;
}
safevoid_snprintf(msg, sizeof(msg), "botthinkfps is %.2f\n", 1.0 / bot_think_spf);
printfunc(PRINTFUNC_INFO, arg, msg);
return TRUE;
}
else if (FStrEq(pcmd, "bot_chat_percent"))
{
if ((arg1 != NULL) && (*arg1 != 0))
{
int temp = atoi(arg1);
if ((temp < 0) || (temp > 100))
printfunc(PRINTFUNC_ERROR, arg, "invalid bot_chat_percent value!\n");
else
bot_chat_percent = temp;
}
safevoid_snprintf(msg, sizeof(msg), "bot_chat_percent is %d\n", bot_chat_percent);
printfunc(PRINTFUNC_INFO, arg, msg);
return TRUE;
}
else if (FStrEq(pcmd, "bot_taunt_percent"))
{
if ((arg1 != NULL) && (*arg1 != 0))
{
int temp = atoi(arg1);
if ((temp < 0) || (temp > 100))
printfunc(PRINTFUNC_ERROR, arg, "invalid bot_taunt_percent value!\n");
else
bot_taunt_percent = temp;
}
safevoid_snprintf(msg, sizeof(msg), "bot_taunt_percent is %d\n", bot_taunt_percent);
printfunc(PRINTFUNC_INFO, arg, msg);
return TRUE;
}
else if (FStrEq(pcmd, "bot_whine_percent"))
{
if ((arg1 != NULL) && (*arg1 != 0))
{
int temp = atoi(arg1);
if ((temp < 0) || (temp > 100))
printfunc(PRINTFUNC_INFO, arg, "invalid bot_whine_percent value!\n");
else
bot_whine_percent = temp;
}
safevoid_snprintf(msg, sizeof(msg), "bot_whine_percent is %d\n", bot_whine_percent);
printfunc(PRINTFUNC_INFO, arg, msg);
return TRUE;
}
else if (FStrEq(pcmd, "bot_endgame_percent"))
{
if ((arg1 != NULL) && (*arg1 != 0))
{
int temp = atoi(arg1);
if ((temp < 0) || (temp > 100))
printfunc(PRINTFUNC_INFO, arg, "invalid bot_endgame_percent value!\n");
else
bot_endgame_percent = temp;
}
safevoid_snprintf(msg, sizeof(msg), "bot_endgame_percent is %d\n", bot_endgame_percent);
printfunc(PRINTFUNC_INFO, arg, msg);
return TRUE;
}
else if (FStrEq(pcmd, "bot_chat_tag_percent"))
{
if ((arg1 != NULL) && (*arg1 != 0))
{
int temp = atoi(arg1);
if ((temp < 0) || (temp > 100))
printfunc(PRINTFUNC_ERROR, arg, "invalid bot_chat_tag_percent value!\n");
else
bot_chat_tag_percent = temp;
}
safevoid_snprintf(msg, sizeof(msg), "bot_chat_tag_percent is %d\n", bot_chat_tag_percent);
printfunc(PRINTFUNC_INFO, arg, msg);
return TRUE;
}
else if (FStrEq(pcmd, "bot_chat_drop_percent"))
{
if ((arg1 != NULL) && (*arg1 != 0))
{
int temp = atoi(arg1);
if ((temp < 0) || (temp > 100))
printfunc(PRINTFUNC_ERROR, arg, "invalid bot_chat_drop_percent value!\n");
else
bot_chat_drop_percent = temp;
}
safevoid_snprintf(msg, sizeof(msg), "bot_chat_drop_percent is %d\n", bot_chat_drop_percent);
printfunc(PRINTFUNC_INFO, arg, msg);
return TRUE;
}
else if (FStrEq(pcmd, "bot_chat_swap_percent"))
{
if ((arg1 != NULL) && (*arg1 != 0))
{
int temp = atoi(arg1);
if ((temp < 0) || (temp > 100))
printfunc(PRINTFUNC_ERROR, arg, "invalid bot_chat_swap_percent value!\n");
else
bot_chat_swap_percent = temp;
}
safevoid_snprintf(msg, sizeof(msg), "bot_chat_swap_percent is %d\n", bot_chat_swap_percent);
printfunc(PRINTFUNC_INFO, arg, msg);
return TRUE;
}
else if (FStrEq(pcmd, "bot_chat_lower_percent"))
{
if ((arg1 != NULL) && (*arg1 != 0))
{
int temp = atoi(arg1);
if ((temp < 0) || (temp > 100))
printfunc(PRINTFUNC_ERROR, arg, "invalid bot_chat_lower_percent value!\n");
else
bot_chat_lower_percent = temp;
}
safevoid_snprintf(msg, sizeof(msg), "bot_chat_lower_percent is %d\n", bot_chat_lower_percent);
printfunc(PRINTFUNC_INFO, arg, msg);
return TRUE;
}
else if (FStrEq(pcmd, "bot_logo_percent"))
{
if ((arg1 != NULL) && (*arg1 != 0))
{
int temp = atoi(arg1);
if ((temp < 0) || (temp > 100))
printfunc(PRINTFUNC_ERROR, arg, "invalid bot_logo_percent value!\n");
else
bot_logo_percent = temp;
}
safevoid_snprintf(msg, sizeof(msg), "bot_logo_percent is %d\n", bot_logo_percent);
printfunc(PRINTFUNC_INFO, arg, msg);
return TRUE;
}
else if (FStrEq(pcmd, "bot_reaction_time"))
{
safevoid_snprintf(msg, sizeof(msg), "bot_reaction_time setting was removed in jk_botti v1.42, ignoring setting\n");
printfunc(PRINTFUNC_INFO, arg, msg);
return TRUE;
}
else if (FStrEq(pcmd, "random_color"))
{
if ((arg1 != NULL) && (*arg1 != 0))
{
int temp = atoi(arg1);
if (temp)
b_random_color = TRUE;
else
b_random_color = FALSE;
}
if (b_random_color)
printfunc(PRINTFUNC_INFO, arg, "random_color ENABLED\n");
else
printfunc(PRINTFUNC_INFO, arg, "random_color DISABLED\n");
return TRUE;
}
else if (FStrEq(pcmd, "botdontshoot"))
{
if ((arg1 != NULL) && (*arg1 != 0))
{
int temp = atoi(arg1);
if (temp)
b_botdontshoot = TRUE;
else
b_botdontshoot = FALSE;
}
if (b_botdontshoot)
printfunc(PRINTFUNC_INFO, arg, "botdontshoot ENABLED\n");
else
printfunc(PRINTFUNC_INFO, arg, "botdontshoot DISABLED\n");
return TRUE;
}
else if (FStrEq(pcmd, "min_bots"))
{
if ((arg1 != NULL) && (*arg1 != 0))
{
min_bots = atoi( arg1 );
if ((min_bots < 0) || (min_bots > 31))
min_bots = -1;
}
safevoid_snprintf(msg, sizeof(msg), "min_bots is set to %d\n", min_bots);
printfunc(PRINTFUNC_INFO, arg, msg);
return TRUE;
}
else if (FStrEq(pcmd, "max_bots"))
{
if ((arg1 != NULL) && (*arg1 != 0))
{
max_bots = atoi( arg1 );
if ((max_bots < 0) || (max_bots > 31))
max_bots = -1;
}
safevoid_snprintf(msg, sizeof(msg), "max_bots is set to %d\n", max_bots);
printfunc(PRINTFUNC_INFO, arg, msg);
return TRUE;
}
else if (FStrEq(pcmd, "pause") && cmdtype == CFGCMD_TYPE)
{
if ((arg1 != NULL) && (*arg1 != 0))
{
bot_cfg_pause_time = gpGlobals->time + atoi( arg1 );
if(bot_cfg_pause_time <= 0.0f)
bot_cfg_pause_time = 0.1f;
}
return TRUE;
}
else if (FStrEq(pcmd, "autowaypoint"))
{
if ((arg1 != NULL) && (*arg1 != 0))
{
if (FStrEq(arg1, "on"))
{
g_auto_waypoint = TRUE;
}
else if (FStrEq(arg1, "off"))
{
g_auto_waypoint = FALSE;
}
else
{
g_auto_waypoint = !!atoi(arg1);
}
if (g_auto_waypoint)
{
if(cmdtype == CLICMD_TYPE)
g_waypoint_on = TRUE; //just in case
printfunc(PRINTFUNC_INFO, arg, "autowaypoint is ON\n");
}
else
printfunc(PRINTFUNC_INFO, arg, "autowaypoint is OFF\n");
}
return TRUE;
}
else if (FStrEq(pcmd, "botweapon"))
{ // this command allows editing of weapon information
if ((arg1 != NULL) && (*arg1 != 0))
{
int select_index = -1;
bot_weapon_select_t *pSelect = &weapon_select[0];
while (pSelect[++select_index].iId)
if (FStrEq(pSelect[select_index].weapon_name, arg1))
break;
if(pSelect[select_index].iId)
{
qboolean got_match = FALSE;
#define CHECK_AND_SET_BOTWEAPON_INT(setting) \
if ((arg2 == NULL) || (*arg2 == 0) || FStrEq(arg2, #setting)) { \
got_match = TRUE; \
if ((arg3 != NULL) && (*arg3 != 0)) { \
int temp = atoi(arg3); \
pSelect[select_index].setting = temp; \
safevoid_snprintf(msg, sizeof(msg), "'%s' for %s is %s'%i'.\n", #setting, arg1, "now ", temp); \
} else \
safevoid_snprintf(msg, sizeof(msg), "'%s' for %s is %s'%i'.\n", #setting, arg1, "", pSelect[select_index].setting); \
printfunc(PRINTFUNC_INFO, arg, msg); \
}
#define CHECK_AND_SET_BOTWEAPON_QBOOLEAN(setting) \
if ((arg2 == NULL) || (*arg2 == 0) || FStrEq(arg2, #setting)) { \
got_match = TRUE; \
if ((arg3 != NULL) && (*arg3 != 0)) { \
qboolean temp; \
if(!stricmp(arg3, "on") || !stricmp(arg3, "true")) \
temp = TRUE; \
else if(!stricmp(arg3, "off") || !stricmp(arg3, "false")) \
temp = FALSE; \
else \
temp = atoi(arg3) ? TRUE : FALSE; \
pSelect[select_index].setting = temp; \
safevoid_snprintf(msg, sizeof(msg), "'%s' for %s is %s'%s'.\n", #setting, arg1, "now ", temp ? "on" : "off"); \
} else \
safevoid_snprintf(msg, sizeof(msg), "'%s' for %s is %s'%s'.\n", #setting, arg1, "", pSelect[select_index].setting ? "on" : "off"); \
printfunc(PRINTFUNC_INFO, arg, msg); \
}
#define CHECK_AND_SET_BOTWEAPON_FLOAT(setting) \
if ((arg2 == NULL) || (*arg2 == 0) || FStrEq(arg2, #setting)) { \
got_match = TRUE; \
if ((arg3 != NULL) && (*arg3 != 0)) { \
float temp = atof(arg3); \
pSelect[select_index].setting = temp; \
safevoid_snprintf(msg, sizeof(msg), "'%s' for %s is %s'%.4f'.\n", #setting, arg1, "now ", temp); \
} else \
safevoid_snprintf(msg, sizeof(msg), "'%s' for %s is %s'%.4f'.\n", #setting, arg1, "", pSelect[select_index].setting); \
printfunc(PRINTFUNC_INFO, arg, msg); \
}
CHECK_AND_SET_BOTWEAPON_INT(primary_skill_level) // bot skill must be less than or equal to this value
CHECK_AND_SET_BOTWEAPON_INT(secondary_skill_level) // bot skill must be less than or equal to this value
CHECK_AND_SET_BOTWEAPON_FLOAT(aim_speed) // aim speed, 0.0 worst, 1.0 best.
CHECK_AND_SET_BOTWEAPON_QBOOLEAN(avoid_this_gun) // bot avoids using this weapon if possible
CHECK_AND_SET_BOTWEAPON_QBOOLEAN(prefer_higher_skill_attack) // bot uses better of primary and secondary attacks if both avaible
CHECK_AND_SET_BOTWEAPON_FLOAT(primary_min_distance) // 0 = no minimum
CHECK_AND_SET_BOTWEAPON_FLOAT(primary_max_distance) // 9999 = no maximum
CHECK_AND_SET_BOTWEAPON_FLOAT(secondary_min_distance) // 0 = no minimum
CHECK_AND_SET_BOTWEAPON_FLOAT(secondary_max_distance) // 9999 = no maximum
CHECK_AND_SET_BOTWEAPON_FLOAT(opt_distance) // optimal distance from target
CHECK_AND_SET_BOTWEAPON_INT(use_percent) // times out of 100 to use this weapon when available
CHECK_AND_SET_BOTWEAPON_QBOOLEAN(can_use_underwater) // can use this weapon underwater
CHECK_AND_SET_BOTWEAPON_INT(primary_fire_percent) // times out of 100 to use primary fire
CHECK_AND_SET_BOTWEAPON_INT(low_ammo_primary) // low ammo level
CHECK_AND_SET_BOTWEAPON_INT(low_ammo_secondary) // low ammo level
if(!got_match)
{
snprintf(msg, sizeof(msg), "unknown weapon setting %s.\n", arg2);
printfunc(PRINTFUNC_ERROR, arg, msg);
if(cmdtype == CLICMD_TYPE || cmdtype == SRVCMD_TYPE)
{
printfunc(PRINTFUNC_INFO, arg, "Usage: botweapon <weapon-name> <setting> <value> - set value\n");
printfunc(PRINTFUNC_INFO, arg, " botweapon <weapon-name> <setting> - shows setting value\n");
printfunc(PRINTFUNC_INFO, arg, " botweapon <weapon-name> - shows all setting values\n");
printfunc(PRINTFUNC_INFO, arg, " botweapon weapons - shows weapon-names\n");
}
}
}
else if(FStrEq("weapons", arg1))
{
printfunc(PRINTFUNC_INFO, arg, "List of available weapons:\n");
select_index = -1;
pSelect = &weapon_select[0];
while (pSelect[++select_index].iId)
{
safevoid_snprintf(msg, sizeof(msg), " %s\n", pSelect[select_index].weapon_name);
printfunc(PRINTFUNC_INFO, arg, msg);
}
}
else if((arg1 != NULL) && (*arg1 != 0) && FStrEq(arg1, "reset"))
{
//weapon select init
InitWeaponSelect(submod_id);
printfunc(PRINTFUNC_INFO, arg, "Bot weapon settings reset default.\n");
}
else
{
snprintf(msg, sizeof(msg), "Could not complete request! (unknown arg1: '%s')\n", arg1);
printfunc(PRINTFUNC_ERROR, arg, msg);
if(cmdtype == CLICMD_TYPE || cmdtype == SRVCMD_TYPE)
{
printfunc(PRINTFUNC_INFO, arg, "Usage: botweapon <weapon-name> <setting> <value> - set value\n");
printfunc(PRINTFUNC_INFO, arg, " botweapon <weapon-name> <setting> - shows setting value\n");
printfunc(PRINTFUNC_INFO, arg, " botweapon <weapon-name> - shows all setting values\n");
printfunc(PRINTFUNC_INFO, arg, " botweapon weapons - shows weapon-names\n");
printfunc(PRINTFUNC_INFO, arg, " botweapon reset - reset values back to defaults for all skills\n");
}
}
}
else
{
printfunc(PRINTFUNC_ERROR, arg, "Could not complete request! (arg1 not given)\n");
if(cmdtype == CLICMD_TYPE || cmdtype == SRVCMD_TYPE)
{
printfunc(PRINTFUNC_INFO, arg, "Usage: botweapon <weapon-name> <setting> <value> - set value\n");
printfunc(PRINTFUNC_INFO, arg, " botweapon <weapon-name> <setting> - shows setting value\n");
printfunc(PRINTFUNC_INFO, arg, " botweapon <weapon-name> - shows all setting values\n");
printfunc(PRINTFUNC_INFO, arg, " botweapon weapons - shows weapon-names\n");
printfunc(PRINTFUNC_INFO, arg, " botweapon reset - reset values back to defaults for all skills\n");
}
}
return TRUE;
}
else if (FStrEq(pcmd, "bot_skill_setup"))
{ // this command allows editing of botskill settings,
// bot_skill_setup <skill>, bot_skill_setup <skill> <setting>, bot_skill_setup <skill> <setting> <value>
if ((arg1 != NULL) && (*arg1 != 0) && atoi(arg1) >= 1 && atoi(arg1) <= 5)
{
int skill_idx = atoi(arg1)-1;
qboolean got_match = FALSE;
#define CHECK_AND_SET_BOTSKILL_INT(setting) \
if ((arg2 == NULL) || (*arg2 == 0) || FStrEq(arg2, #setting)) { \
got_match = TRUE; \
if ((arg3 != NULL) && (*arg3 != 0)) { \
int temp = atoi(arg3); \
skill_settings[skill_idx].setting = temp; \
safevoid_snprintf(msg, sizeof(msg), "'%s' for skill[%d] is %s'%i'.\n", #setting, skill_idx+1, "now ", temp); \
} else \
safevoid_snprintf(msg, sizeof(msg), "'%s' for skill[%d] is %s'%i'.\n", #setting, skill_idx+1, "", skill_settings[skill_idx].setting); \
printfunc(PRINTFUNC_INFO, arg, msg); \
}
#define CHECK_AND_SET_BOTSKILL_QBOOLEAN(setting) \
if ((arg2 == NULL) || (*arg2 == 0) || FStrEq(arg2, #setting)) { \
got_match = TRUE; \
if ((arg3 != NULL) && (*arg3 != 0)) { \
qboolean temp; \
if(!stricmp(arg3, "on") || !stricmp(arg3, "true")) \
temp = TRUE; \
else if(!stricmp(arg3, "off") || !stricmp(arg3, "false")) \
temp = FALSE; \
else \
temp = atoi(arg3) ? TRUE : FALSE; \
skill_settings[skill_idx].setting = temp; \
safevoid_snprintf(msg, sizeof(msg), "'%s' for skill[%d] is %s'%s'.\n", #setting, skill_idx+1, "now ", temp ? "on" : "off"); \
} else \
safevoid_snprintf(msg, sizeof(msg), "'%s' for skill[%d] is %s'%s'.\n", #setting, skill_idx+1, "", skill_settings[skill_idx].setting ? "on" : "off"); \
printfunc(PRINTFUNC_INFO, arg, msg); \
}
#define CHECK_AND_SET_BOTSKILL_FLOAT(setting) \
if ((arg2 == NULL) || (*arg2 == 0) || FStrEq(arg2, #setting)) { \
got_match = TRUE; \
if ((arg3 != NULL) && (*arg3 != 0)) { \
float temp = atof(arg3); \
skill_settings[skill_idx].setting = temp; \
safevoid_snprintf(msg, sizeof(msg), "'%s' for skill[%d] is %s'%.4f'.\n", #setting, skill_idx+1, "now ", temp); \
} else \
safevoid_snprintf(msg, sizeof(msg), "'%s' for skill[%d] is %s'%.4f'.\n", #setting, skill_idx+1, "", skill_settings[skill_idx].setting); \
printfunc(PRINTFUNC_INFO, arg, msg); \
}
#define CHECK_AND_SET_BOTSKILL_FLOAT100(setting) \
if ((arg2 == NULL) || (*arg2 == 0) || FStrEq(arg2, #setting)) { \
got_match = TRUE; \
if ((arg3 != NULL) && (*arg3 != 0)) { \
float temp = atof(arg3)/100; \
skill_settings[skill_idx].setting = temp; \
safevoid_snprintf(msg, sizeof(msg), "'%s' for skill[%d] is %s'%.0f'.\n", #setting, skill_idx+1, "now ", temp*100); \
} else \
safevoid_snprintf(msg, sizeof(msg), "'%s' for skill[%d] is %s'%.0f'.\n", #setting, skill_idx+1, "", skill_settings[skill_idx].setting*100); \
printfunc(PRINTFUNC_INFO, arg, msg); \
}
CHECK_AND_SET_BOTSKILL_INT(pause_frequency) // how often (out of 1000 times) the bot will pause, based on bot skill
CHECK_AND_SET_BOTSKILL_FLOAT(pause_time_min) // how long bot pauses (min, max)
CHECK_AND_SET_BOTSKILL_FLOAT(pause_time_max) //
CHECK_AND_SET_BOTSKILL_FLOAT100(normal_strafe) // how much bot strafes when walking around
CHECK_AND_SET_BOTSKILL_FLOAT100(battle_strafe) // how much bot strafes when attacking enemy
CHECK_AND_SET_BOTSKILL_INT(keep_optimal_dist) // how often bot (out of 100 times) the bot try to keep at optimum distance of weapon when attacking
CHECK_AND_SET_BOTSKILL_FLOAT(shootcone_diameter) // bot tries to fire when aim line is less than [diameter / 2] apart from target
CHECK_AND_SET_BOTSKILL_FLOAT(shootcone_minangle) // OR angle between bot aim line and line to target is less than angle set here
CHECK_AND_SET_BOTSKILL_FLOAT(turn_skill) // BotAim turn_skill, how good bot is at aiming on enemy origin.
CHECK_AND_SET_BOTSKILL_FLOAT(turn_slowness) // Is bot's aim in slow motion?
CHECK_AND_SET_BOTSKILL_FLOAT(updown_turn_ration) // how much slower bots aims up and down than side ways?
CHECK_AND_SET_BOTSKILL_FLOAT(ping_emu_latency) // how much ping latency bot brain has.
CHECK_AND_SET_BOTSKILL_FLOAT(ping_emu_speed_varitation) // how well bot can predict target speed.
CHECK_AND_SET_BOTSKILL_FLOAT(ping_emu_position_varitation) // how well bot can predict target position.
CHECK_AND_SET_BOTSKILL_FLOAT(hearing_sensitivity) // how well bot hears sounds
CHECK_AND_SET_BOTSKILL_FLOAT(track_sound_time_min) // how long bot tracks one sound
CHECK_AND_SET_BOTSKILL_FLOAT(track_sound_time_max)
CHECK_AND_SET_BOTSKILL_FLOAT(respawn_react_delay) // delay on players after respawn
CHECK_AND_SET_BOTSKILL_FLOAT(react_delay_min) //
CHECK_AND_SET_BOTSKILL_FLOAT(react_delay_max) //
CHECK_AND_SET_BOTSKILL_FLOAT(weaponchange_rate_min) // how fast changing weapons (min, max)
CHECK_AND_SET_BOTSKILL_FLOAT(weaponchange_rate_max) //
CHECK_AND_SET_BOTSKILL_QBOOLEAN(can_longjump) // and can longjump.
CHECK_AND_SET_BOTSKILL_INT(random_jump_frequency) // how often (out of 100 times) the bot will do random jump
CHECK_AND_SET_BOTSKILL_INT(random_jump_duck_frequency) // how often (out of 100 times) the bot will do random duck when random jumping
CHECK_AND_SET_BOTSKILL_INT(random_duck_frequency) // how often (out of 100 times) the bot will do random duck jumping in combat mode
CHECK_AND_SET_BOTSKILL_INT(random_longjump_frequency) // how often (out of 100 times) the bot will do random longjump instead of random jump
#if 0
CHECK_AND_SET_BOTSKILL_QBOOLEAN(can_taujump) // can tau jump?
CHECK_AND_SET_BOTSKILL_INT(attack_taujump_frequency) // how often (out of 100 times) the bot will do tau jump at far away enemy
CHECK_AND_SET_BOTSKILL_INT(flee_taujump_frequency) // how often (out of 100 times) the bot will taujump away from enemy
CHECK_AND_SET_BOTSKILL_FLOAT(attack_taujump_distance) // how far enemy have to be to bot to use tau jump
CHECK_AND_SET_BOTSKILL_FLOAT(flee_taujump_distance) // max distance to flee enemy from
CHECK_AND_SET_BOTSKILL_FLOAT(flee_taujump_health) // how much bot has health left when tries to escape
CHECK_AND_SET_BOTSKILL_FLOAT(flee_taujump_escape_distance) // how long way bot tries to move away
CHECK_AND_SET_BOTSKILL_QBOOLEAN(can_shoot_through_walls) // can shoot through walls by sound
CHECK_AND_SET_BOTSKILL_INT(wallshoot_frequency) // how often (out of 100 times) the bot will try attack enemy behind wall
#endif
if(!got_match)
{
snprintf(msg, sizeof(msg), "unknown skill setting %s.\n", arg2);
printfunc(PRINTFUNC_ERROR, arg, msg);
if(cmdtype == CLICMD_TYPE || cmdtype == SRVCMD_TYPE)
{
printfunc(PRINTFUNC_INFO, arg, "Usage: bot_skill_setup <skill> <setting> <value> - set value\n");
printfunc(PRINTFUNC_INFO, arg, " bot_skill_setup <skill> <setting> - shows setting value\n");
printfunc(PRINTFUNC_INFO, arg, " bot_skill_setup <skill> - shows all setting values\n");
printfunc(PRINTFUNC_INFO, arg, " bot_skill_setup reset - reset values back to defaults for all skills\n");
}
}
}
else if((arg1 != NULL) && (*arg1 != 0) && FStrEq(arg1, "reset"))
{
ResetSkillsToDefault();
printfunc(PRINTFUNC_INFO, arg, "Bot skill settings reset default.\n");
}
else
{
if((arg1 == NULL) || (*arg1 == 0))
printfunc(PRINTFUNC_ERROR, arg, "Could not complete request! (arg1 not given)\n");
else
{
snprintf(msg, sizeof(msg), "Could not complete request! (invalid skill %d, use 1-5)\n", atoi(arg1));
printfunc(PRINTFUNC_ERROR, arg, msg);
}
if(cmdtype == CLICMD_TYPE || cmdtype == SRVCMD_TYPE)
{
printfunc(PRINTFUNC_INFO, arg, "Usage: bot_skill_setup <skill> <setting> <value> - set value\n");
printfunc(PRINTFUNC_INFO, arg, " bot_skill_setup <skill> <setting> - shows setting value\n");
printfunc(PRINTFUNC_INFO, arg, " bot_skill_setup <skill> - shows all setting values\n");
printfunc(PRINTFUNC_INFO, arg, " bot_skill_setup reset - reset values back to defaults for all skills\n");
}
}
return TRUE;
}
return FALSE;
}
#if _DEBUG
static void print_to_client(int, void *arg, char *msg)
{
ClientPrint((edict_t *)arg, HUD_PRINTNOTIFY, msg);
}
#endif
void ClientCommand( edict_t *pEntity )
{
// only allow custom commands if deathmatch mode and NOT dedicated server and
// client sending command is the listen server client...
#if _DEBUG
if ((gpGlobals->deathmatch))
{
const char *pcmd = CMD_ARGV (0);
const char *arg1 = CMD_ARGV (1);
const char *arg2 = CMD_ARGV (2);
const char *arg3 = CMD_ARGV (3);
const char *arg4 = CMD_ARGV (4);
const char *arg5 = CMD_ARGV (5);
if(ProcessCommand(CLICMD_TYPE, print_to_client, pEntity, pcmd, arg1, arg2, arg3, arg4, arg5))