forked from Bots-United/HPB-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dll.cpp
2089 lines (1695 loc) · 61.5 KB
/
dll.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
//
// HPB bot - botman's High Ping Bastard bot
//
// (http://planethalflife.com/botman/)
//
// dll.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 "bot.h"
#include "bot_func.h"
#include "waypoint.h"
#define VER_MAJOR 4
#define VER_MINOR 0
#define MENU_NONE 0
#define MENU_1 1
#define MENU_2 2
#define MENU_3 3
#define MENU_4 4
extern DLL_FUNCTIONS gFunctionTable;
extern enginefuncs_t g_engfuncs;
extern globalvars_t *gpGlobals;
extern char g_argv[1024];
extern bool g_waypoint_on;
extern bool g_auto_waypoint;
extern bool g_path_waypoint;
extern bool g_path_waypoint_enable;
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 bool b_observer_mode;
extern bool b_botdontshoot;
extern char welcome_msg[80];
static FILE *fp;
int mod_id = 0;
int m_spriteTexture = 0;
int default_bot_skill = 2;
int bot_strafe_percent = 20; // percent of time to strafe
int bot_chat_percent = 10; // percent of time to chat
int bot_taunt_percent = 20; // percent of time to taunt after kill
int bot_whine_percent = 10; // percent of time to whine after death
int bot_grenade_time = 15; // seconds between grenade throws
int bot_logo_percent = 40; // percent of time to spray logo after kill
int bot_chat_tag_percent = 80; // percent of the time to drop clan tag
int bot_chat_drop_percent = 10; // percent of the time to drop characters
int bot_chat_swap_percent = 10; // percent of the time to swap characters
int bot_chat_lower_percent = 50; // percent of the time to lowercase chat
bool b_random_color = TRUE;
bool isFakeClientCommand = FALSE;
int fake_arg_count;
int IsDedicatedServer;
float bot_check_time = 60.0;
int bot_reaction_time = 2;
int min_bots = -1;
int max_bots = -1;
int num_bots = 0;
int prev_num_bots = 0;
bool g_GameRules = FALSE;
edict_t *clients[32];
edict_t *listenserver_edict = NULL;
float welcome_time = 0.0;
bool welcome_sent = FALSE;
int g_menu_waypoint;
int g_menu_state = 0;
int bot_stop = 0;
int jumppad_off = 0;
bool is_team_play = FALSE;
char team_names[MAX_TEAMS][MAX_TEAMNAME_LENGTH];
int num_teams = 0;
bool checked_teamplay = FALSE;
edict_t *pent_info_tfdetect = NULL;
edict_t *pent_info_ctfdetect = NULL;
edict_t *pent_info_frontline = NULL;
edict_t *pent_item_tfgoal = NULL;
edict_t *pent_info_tfgoal = NULL;
int max_team_players[4];
int team_class_limits[4];
int team_allies[4]; // bit mapped allies BLUE, RED, YELLOW, and GREEN
int max_teams = 0;
int num_flags = 0;
FLAG_S flags[MAX_FLAGS];
int num_backpacks = 0;
BACKPACK_S backpacks[MAX_BACKPACKS];
FILE *bot_cfg_fp = NULL;
bool need_to_open_cfg = TRUE;
float bot_cfg_pause_time = 0.0;
float respawn_time = 0.0;
bool spawn_time_reset = FALSE;
char *show_menu_none = {" "};
char *show_menu_1 =
{"Waypoint Tags\n\n1. Team Specific\n2. Wait for Lift\n3. Door\n4. Sniper Spot\n5. More..."};
char *show_menu_2 =
{"Waypoint Tags\n\n1. Team 1\n2. Team 2\n3. Team 3\n4. Team 4\n5. CANCEL"};
char *show_menu_2_flf =
{"Waypoint Tags\n\n1. Attackers\n2. Defenders\n\n5. CANCEL"};
char *show_menu_3 =
{"Waypoint Tags\n\n1. Flag Location\n2. Flag Goal Location\n3. Sentry gun\n4. Dispenser\n5. More"};
char *show_menu_3_flf =
{"Waypoint Tags\n\n1. Capture Point\n2. Defend Point\n3. Prone\n\n5. CANCEL"};
char *show_menu_3_hw =
{"Waypoint Tags\n\n1. Halo Location\n\n\n\n5. More"};
char *show_menu_4 =
{"Waypoint Tags\n\n1. Health\n2. Armor\n3. Ammo\n4. Jump\n5. CANCEL"};
void BotNameInit(void);
void BotLogoInit(void);
void UpdateClientData(const struct edict_s *ent, int sendweapons, struct clientdata_s *cd);
void ProcessBotCfgFile(void);
void HPB_Bot_ServerCommand (void);
extern void welcome_init(void);
// START of Metamod stuff
enginefuncs_t meta_engfuncs;
gamedll_funcs_t *gpGamedllFuncs;
mutil_funcs_t *gpMetaUtilFuncs;
meta_globals_t *gpMetaGlobals;
META_FUNCTIONS gMetaFunctionTable =
{
NULL, // pfnGetEntityAPI()
NULL, // pfnGetEntityAPI_Post()
GetEntityAPI2, // pfnGetEntityAPI2()
NULL, // pfnGetEntityAPI2_Post()
NULL, // pfnGetNewDLLFunctions()
NULL, // pfnGetNewDLLFunctions_Post()
GetEngineFunctions, // pfnGetEngineFunctions()
NULL, // pfnGetEngineFunctions_Post()
};
plugin_info_t Plugin_info = {
META_INTERFACE_VERSION, // interface version
"HPB_Bot", // plugin name
"4.0.4", // plugin version
"09/11/2004", // date of creation
"botman && Pierre-Marie Baty", // plugin author
"http://hpb-bot.bots-united.com/", // plugin URL
"HPB_BOT", // plugin logtag
PT_STARTUP, // when loadable
PT_ANYTIME, // when unloadable
};
C_DLLEXPORT int Meta_Query (const char *ifvers, plugin_info_t **pPlugInfo, mutil_funcs_t *pMetaUtilFuncs)
{
// this function is the first function ever called by metamod in the plugin DLL. Its purpose
// is for metamod to retrieve basic information about the plugin, such as its meta-interface
// version, for ensuring compatibility with the current version of the running metamod.
// keep track of the pointers to metamod function tables metamod gives us
gpMetaUtilFuncs = pMetaUtilFuncs;
*pPlugInfo = &Plugin_info;
// check for interface version compatibility
if (strcmp (ifvers, Plugin_info.ifvers) != 0)
{
int mmajor = 0, mminor = 0, pmajor = 0, pminor = 0;
LOG_CONSOLE (PLID, "%s: meta-interface version mismatch (metamod: %s, %s: %s)", Plugin_info.name, ifvers, Plugin_info.name, Plugin_info.ifvers);
LOG_MESSAGE (PLID, "%s: meta-interface version mismatch (metamod: %s, %s: %s)", Plugin_info.name, ifvers, Plugin_info.name, Plugin_info.ifvers);
// if plugin has later interface version, it's incompatible (update metamod)
sscanf (ifvers, "%d:%d", &mmajor, &mminor);
sscanf (META_INTERFACE_VERSION, "%d:%d", &pmajor, &pminor);
if ((pmajor > mmajor) || ((pmajor == mmajor) && (pminor > mminor)))
{
LOG_CONSOLE (PLID, "metamod version is too old for this plugin; update metamod");
LOG_ERROR (PLID, "metamod version is too old for this plugin; update metamod");
return (FALSE);
}
// if plugin has older major interface version, it's incompatible (update plugin)
else if (pmajor < mmajor)
{
LOG_CONSOLE (PLID, "metamod version is incompatible with this plugin; please find a newer version of this plugin");
LOG_ERROR (PLID, "metamod version is incompatible with this plugin; please find a newer version of this plugin");
return (FALSE);
}
}
return (TRUE); // tell metamod this plugin looks safe
}
C_DLLEXPORT int Meta_Attach (PLUG_LOADTIME now, META_FUNCTIONS *pFunctionTable, meta_globals_t *pMGlobals, gamedll_funcs_t *pGamedllFuncs)
{
// this function is called when metamod attempts to load the plugin. Since it's the place
// where we can tell if the plugin will be allowed to run or not, we wait until here to make
// our initialization stuff, like registering CVARs and dedicated server commands.
// are we allowed to load this plugin now ?
if (now > Plugin_info.loadable)
{
LOG_CONSOLE (PLID, "%s: plugin NOT attaching (can't load plugin right now)", Plugin_info.name);
LOG_ERROR (PLID, "%s: plugin NOT attaching (can't load plugin right now)", Plugin_info.name);
return (FALSE); // returning FALSE prevents metamod from attaching this plugin
}
// keep track of the pointers to engine function tables metamod gives us
gpMetaGlobals = pMGlobals;
memcpy (pFunctionTable, &gMetaFunctionTable, sizeof (META_FUNCTIONS));
gpGamedllFuncs = pGamedllFuncs;
// print a message to notify about plugin attaching
LOG_CONSOLE (PLID, "%s: plugin attaching", Plugin_info.name);
LOG_MESSAGE (PLID, "%s: plugin attaching", Plugin_info.name);
// ask the engine to register the server commands this plugin uses
REG_SVR_COMMAND ("HPB_Bot", HPB_Bot_ServerCommand);
return (TRUE); // returning TRUE enables metamod to attach this plugin
}
C_DLLEXPORT int Meta_Detach (PLUG_LOADTIME now, PL_UNLOAD_REASON reason)
{
// this function is called when metamod unloads the plugin. A basic check is made in order
// to prevent unloading the plugin if its processing should not be interrupted.
// is metamod allowed to unload the plugin ?
if ((now > Plugin_info.unloadable) && (reason != PNL_CMD_FORCED))
{
LOG_CONSOLE (PLID, "%s: plugin NOT detaching (can't unload plugin right now)", Plugin_info.name);
LOG_ERROR (PLID, "%s: plugin NOT detaching (can't unload plugin right now)", Plugin_info.name);
return (FALSE); // returning FALSE prevents metamod from unloading this plugin
}
return (TRUE); // returning TRUE enables metamod to unload this plugin
}
// END of Metamod stuff
void GameDLLInit( void )
{
int i;
IsDedicatedServer = IS_DEDICATED_SERVER();
for (i=0; i<32; i++)
clients[i] = NULL;
welcome_init();
// initialize the bots array of structures...
memset(bots, 0, sizeof(bots));
BotNameInit();
BotLogoInit();
LoadBotChat();
LoadBotModels();
RETURN_META (MRES_IGNORED);
}
int Spawn( edict_t *pent )
{
int index;
if (gpGlobals->deathmatch)
{
char *pClassname = (char *)STRING(pent->v.classname);
if (strcmp(pClassname, "worldspawn") == 0)
{
// do level initialization stuff here...
WaypointInit();
WaypointLoad(NULL);
pent_info_tfdetect = NULL;
pent_info_ctfdetect = NULL;
pent_info_frontline = NULL;
pent_item_tfgoal = NULL;
pent_info_tfgoal = NULL;
for (index=0; index < 4; index++)
{
max_team_players[index] = 0; // no player limit
team_class_limits[index] = 0; // no class limits
team_allies[index] = 0;
}
max_teams = 0;
num_flags = 0;
for (index=0; index < MAX_FLAGS; index++)
{
flags[index].edict = NULL;
flags[index].team_no = 0; // any team unless specified
}
num_backpacks = 0;
for (index=0; index < MAX_BACKPACKS; index++)
{
backpacks[index].edict = NULL;
backpacks[index].armor = 0;
backpacks[index].health = 0;
backpacks[index].ammo = 0;
backpacks[index].team = 0; // any team unless specified
}
PRECACHE_SOUND("weapons/xbow_hit1.wav"); // waypoint add
PRECACHE_SOUND("weapons/mine_activate.wav"); // waypoint delete
PRECACHE_SOUND("common/wpn_hudoff.wav"); // path add/delete start
PRECACHE_SOUND("common/wpn_hudon.wav"); // path add/delete done
PRECACHE_SOUND("common/wpn_moveselect.wav"); // path add/delete cancel
PRECACHE_SOUND("common/wpn_denyselect.wav"); // path add/delete error
PRECACHE_SOUND("player/sprayer.wav"); // logo spray sound
m_spriteTexture = PRECACHE_MODEL( "sprites/lgtning.spr");
g_GameRules = TRUE;
is_team_play = FALSE;
memset(team_names, 0, sizeof(team_names));
num_teams = 0;
checked_teamplay = FALSE;
bot_cfg_pause_time = 0.0;
respawn_time = 0.0;
spawn_time_reset = FALSE;
prev_num_bots = num_bots;
num_bots = 0;
bot_check_time = gpGlobals->time + 60.0;
}
if ((mod_id == HOLYWARS_DLL) && (jumppad_off) &&
(strcmp(pClassname, "trigger_jumppad") == 0))
{
RETURN_META_VALUE (MRES_SUPERCEDE, -1); // disable jumppads
}
}
RETURN_META_VALUE (MRES_IGNORED, 0);
}
void KeyValue( edict_t *pentKeyvalue, KeyValueData *pkvd )
{
static edict_t *temp_pent;
static int flag_index;
static int backpack_index;
if (mod_id == TFC_DLL)
{
if (pentKeyvalue == pent_info_tfdetect)
{
if (strcmp(pkvd->szKeyName, "ammo_medikit") == 0) // max BLUE players
max_team_players[0] = atoi(pkvd->szValue);
else if (strcmp(pkvd->szKeyName, "ammo_detpack") == 0) // max RED players
max_team_players[1] = atoi(pkvd->szValue);
else if (strcmp(pkvd->szKeyName, "maxammo_medikit") == 0) // max YELLOW players
max_team_players[2] = atoi(pkvd->szValue);
else if (strcmp(pkvd->szKeyName, "maxammo_detpack") == 0) // max GREEN players
max_team_players[3] = atoi(pkvd->szValue);
else if (strcmp(pkvd->szKeyName, "maxammo_shells") == 0) // BLUE class limits
team_class_limits[0] = atoi(pkvd->szValue);
else if (strcmp(pkvd->szKeyName, "maxammo_nails") == 0) // RED class limits
team_class_limits[1] = atoi(pkvd->szValue);
else if (strcmp(pkvd->szKeyName, "maxammo_rockets") == 0) // YELLOW class limits
team_class_limits[2] = atoi(pkvd->szValue);
else if (strcmp(pkvd->szKeyName, "maxammo_cells") == 0) // GREEN class limits
team_class_limits[3] = atoi(pkvd->szValue);
else if (strcmp(pkvd->szKeyName, "team1_allies") == 0) // BLUE allies
team_allies[0] = atoi(pkvd->szValue);
else if (strcmp(pkvd->szKeyName, "team2_allies") == 0) // RED allies
team_allies[1] = atoi(pkvd->szValue);
else if (strcmp(pkvd->szKeyName, "team3_allies") == 0) // YELLOW allies
team_allies[2] = atoi(pkvd->szValue);
else if (strcmp(pkvd->szKeyName, "team4_allies") == 0) // GREEN allies
team_allies[3] = atoi(pkvd->szValue);
}
else if (pent_info_tfdetect == NULL)
{
if ((strcmp(pkvd->szKeyName, "classname") == 0) &&
(strcmp(pkvd->szValue, "info_tfdetect") == 0))
{
pent_info_tfdetect = pentKeyvalue;
}
}
if (pentKeyvalue == pent_item_tfgoal)
{
if (strcmp(pkvd->szKeyName, "team_no") == 0)
flags[flag_index].team_no = atoi(pkvd->szValue);
if ((strcmp(pkvd->szKeyName, "mdl") == 0) &&
((strcmp(pkvd->szValue, "models/flag.mdl") == 0) ||
(strcmp(pkvd->szValue, "models/keycard.mdl") == 0) ||
(strcmp(pkvd->szValue, "models/ball.mdl") == 0)))
{
num_flags++;
}
}
else if (pent_item_tfgoal == NULL)
{
if ((strcmp(pkvd->szKeyName, "classname") == 0) &&
(strcmp(pkvd->szValue, "item_tfgoal") == 0))
{
if (num_flags < MAX_FLAGS)
{
pent_item_tfgoal = pentKeyvalue;
flags[num_flags].edict = pentKeyvalue;
flag_index = num_flags; // in case the mdl comes before team_no
}
}
}
else
{
pent_item_tfgoal = NULL; // reset for non-flag item_tfgoal's
}
if (pentKeyvalue != pent_info_tfgoal) // different edict?
{
pent_info_tfgoal = NULL; // reset
}
if (pentKeyvalue == pent_info_tfgoal)
{
if (strcmp(pkvd->szKeyName, "team_no") == 0)
backpacks[backpack_index].team = atoi(pkvd->szValue);
if (strcmp(pkvd->szKeyName, "armorvalue") == 0)
backpacks[backpack_index].armor = atoi(pkvd->szValue);
if (strcmp(pkvd->szKeyName, "health") == 0)
backpacks[backpack_index].health = atoi(pkvd->szValue);
if ((strcmp(pkvd->szKeyName, "ammo_nails") == 0) ||
(strcmp(pkvd->szKeyName, "ammo_rockets") == 0) ||
(strcmp(pkvd->szKeyName, "ammo_cells") == 0) ||
(strcmp(pkvd->szKeyName, "ammo_shells") == 0))
backpacks[backpack_index].ammo = atoi(pkvd->szValue);
if ((strcmp(pkvd->szKeyName, "mdl") == 0) &&
(strcmp(pkvd->szValue, "models/backpack.mdl") == 0))
{
num_backpacks++;
}
}
else if (pent_info_tfgoal == NULL)
{
if (((strcmp(pkvd->szKeyName, "classname") == 0) &&
(strcmp(pkvd->szValue, "info_tfgoal") == 0)) ||
((strcmp(pkvd->szKeyName, "classname") == 0) &&
(strcmp(pkvd->szValue, "i_t_g") == 0)))
{
if (num_backpacks < MAX_BACKPACKS)
{
pent_info_tfgoal = pentKeyvalue;
backpacks[num_backpacks].edict = pentKeyvalue;
// in case the mdl comes before the other fields
backpack_index = num_backpacks;
}
}
}
if ((strcmp(pkvd->szKeyName, "classname") == 0) &&
((strcmp(pkvd->szValue, "info_player_teamspawn") == 0) ||
(strcmp(pkvd->szValue, "i_p_t") == 0)))
{
temp_pent = pentKeyvalue;
}
else if (pentKeyvalue == temp_pent)
{
if (strcmp(pkvd->szKeyName, "team_no") == 0)
{
int value = atoi(pkvd->szValue);
if (value > max_teams)
max_teams = value;
}
}
}
else if (mod_id == GEARBOX_DLL)
{
if (pent_info_ctfdetect == NULL)
{
if ((strcmp(pkvd->szKeyName, "classname") == 0) &&
(strcmp(pkvd->szValue, "info_ctfdetect") == 0))
{
pent_info_ctfdetect = pentKeyvalue;
}
}
}
RETURN_META (MRES_IGNORED);
}
BOOL ClientConnect( edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[ 128 ] )
{
if (gpGlobals->deathmatch)
{
int i;
int count = 0;
// check if this client is the listen server client
if (strcmp(pszAddress, "loopback") == 0)
{
// save the edict of the listen server client...
listenserver_edict = pEntity;
}
// check if this is NOT a bot joining the server...
if (strcmp(pszAddress, "127.0.0.1") != 0)
{
// don't try to add bots for 60 seconds, give client time to get added
bot_check_time = gpGlobals->time + 60.0;
for (i=0; i < 32; i++)
{
if (bots[i].is_used) // count the number of bots in use
count++;
}
// if there are currently more than the minimum number of bots running
// then kick one of the bots off the server...
if ((count > min_bots) && (min_bots != -1))
{
for (i=0; i < 32; i++)
{
if (bots[i].is_used) // is this slot used?
{
char cmd[80];
sprintf(cmd, "kick \"%s\"\n", bots[i].name);
SERVER_COMMAND(cmd); // kick the bot using (kick "name")
break;
}
}
}
}
}
RETURN_META_VALUE (MRES_IGNORED, 0);
}
void ClientDisconnect( edict_t *pEntity )
{
if (gpGlobals->deathmatch)
{
int i;
i = 0;
while ((i < 32) && (clients[i] != pEntity))
i++;
if (i < 32)
clients[i] = NULL;
for (i=0; i < 32; i++)
{
if (bots[i].pEdict == pEntity)
{
// someone kicked this bot off of the server...
bots[i].is_used = FALSE; // this slot is now free to use
bots[i].f_kick_time = gpGlobals->time; // save the kicked time
break;
}
}
}
RETURN_META (MRES_IGNORED);
}
void ClientPutInServer( edict_t *pEntity )
{
int i = 0;
while ((i < 32) && (clients[i] != NULL))
i++;
if (i < 32)
clients[i] = pEntity; // store this clients edict in the clients array
RETURN_META (MRES_IGNORED);
}
void ClientCommand( edict_t *pEntity )
{
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);
// only allow custom commands if deathmatch mode and NOT dedicated server and
// client sending command is the listen server client...
if ((gpGlobals->deathmatch) && (!IsDedicatedServer) &&
(pEntity == listenserver_edict))
{
char msg[80];
if (FStrEq(pcmd, "addbot"))
{
BotCreate( pEntity, arg1, arg2, arg3, arg4, arg5 );
bot_check_time = gpGlobals->time + 5.0;
RETURN_META (MRES_SUPERCEDE);
}
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)
ClientPrint(pEntity, HUD_PRINTNOTIFY, "observer mode ENABLED\n");
else
ClientPrint(pEntity, HUD_PRINTNOTIFY, "observer mode DISABLED\n");
RETURN_META (MRES_SUPERCEDE);
}
else if (FStrEq(pcmd, "botskill"))
{
if ((arg1 != NULL) && (*arg1 != 0))
{
int temp = atoi(arg1);
if ((temp < 1) || (temp > 5))
ClientPrint(pEntity, HUD_PRINTNOTIFY, "invalid botskill value!\n");
else
default_bot_skill = temp;
}
sprintf(msg, "botskill is %d\n", default_bot_skill);
ClientPrint(pEntity, HUD_PRINTNOTIFY, msg);
RETURN_META (MRES_SUPERCEDE);
}
else if (FStrEq(pcmd, "bot_strafe_percent"))
{
if ((arg1 != NULL) && (*arg1 != 0))
{
int temp = atoi(arg1);
if ((temp < 0) || (temp > 100))
ClientPrint(pEntity, HUD_PRINTNOTIFY, "invalid bot_strafe_percent value!\n");
else
bot_strafe_percent = temp;
}
sprintf(msg, "bot_strafe_percent is %d\n", bot_strafe_percent);
ClientPrint(pEntity, HUD_PRINTNOTIFY, msg);
RETURN_META (MRES_SUPERCEDE);
}
else if (FStrEq(pcmd, "bot_chat_percent"))
{
if ((arg1 != NULL) && (*arg1 != 0))
{
int temp = atoi(arg1);
if ((temp < 0) || (temp > 100))
ClientPrint(pEntity, HUD_PRINTNOTIFY, "invalid bot_chat_percent value!\n");
else
bot_chat_percent = temp;
}
sprintf(msg, "bot_chat_percent is %d\n", bot_chat_percent);
ClientPrint(pEntity, HUD_PRINTNOTIFY, msg);
RETURN_META (MRES_SUPERCEDE);
}
else if (FStrEq(pcmd, "bot_taunt_percent"))
{
if ((arg1 != NULL) && (*arg1 != 0))
{
int temp = atoi(arg1);
if ((temp < 0) || (temp > 100))
ClientPrint(pEntity, HUD_PRINTNOTIFY, "invalid bot_taunt_percent value!\n");
else
bot_taunt_percent = temp;
}
sprintf(msg, "bot_taunt_percent is %d\n", bot_taunt_percent);
ClientPrint(pEntity, HUD_PRINTNOTIFY, msg);
RETURN_META (MRES_SUPERCEDE);
}
else if (FStrEq(pcmd, "bot_whine_percent"))
{
if ((arg1 != NULL) && (*arg1 != 0))
{
int temp = atoi(arg1);
if ((temp < 0) || (temp > 100))
ClientPrint(pEntity, HUD_PRINTNOTIFY, "invalid bot_whine_percent value!\n");
else
bot_whine_percent = temp;
}
sprintf(msg, "bot_whine_percent is %d\n", bot_whine_percent);
ClientPrint(pEntity, HUD_PRINTNOTIFY, msg);
RETURN_META (MRES_SUPERCEDE);
}
else if (FStrEq(pcmd, "bot_chat_tag_percent"))
{
if ((arg1 != NULL) && (*arg1 != 0))
{
int temp = atoi(arg1);
if ((temp < 0) || (temp > 100))
ClientPrint(pEntity, HUD_PRINTNOTIFY, "invalid bot_chat_tag_percent value!\n");
else
bot_chat_tag_percent = temp;
}
sprintf(msg, "bot_chat_tag_percent is %d\n", bot_chat_tag_percent);
ClientPrint(pEntity, HUD_PRINTNOTIFY, msg);
RETURN_META (MRES_SUPERCEDE);
}
else if (FStrEq(pcmd, "bot_chat_drop_percent"))
{
if ((arg1 != NULL) && (*arg1 != 0))
{
int temp = atoi(arg1);
if ((temp < 0) || (temp > 100))
ClientPrint(pEntity, HUD_PRINTNOTIFY, "invalid bot_chat_drop_percent value!\n");
else
bot_chat_drop_percent = temp;
}
sprintf(msg, "bot_chat_drop_percent is %d\n", bot_chat_drop_percent);
ClientPrint(pEntity, HUD_PRINTNOTIFY, msg);
RETURN_META (MRES_SUPERCEDE);
}
else if (FStrEq(pcmd, "bot_chat_swap_percent"))
{
if ((arg1 != NULL) && (*arg1 != 0))
{
int temp = atoi(arg1);
if ((temp < 0) || (temp > 100))
ClientPrint(pEntity, HUD_PRINTNOTIFY, "invalid bot_chat_swap_percent value!\n");
else
bot_chat_swap_percent = temp;
}
sprintf(msg, "bot_chat_swap_percent is %d\n", bot_chat_swap_percent);
ClientPrint(pEntity, HUD_PRINTNOTIFY, msg);
RETURN_META (MRES_SUPERCEDE);
}
else if (FStrEq(pcmd, "bot_chat_lower_percent"))
{
if ((arg1 != NULL) && (*arg1 != 0))
{
int temp = atoi(arg1);
if ((temp < 0) || (temp > 100))
ClientPrint(pEntity, HUD_PRINTNOTIFY, "invalid bot_chat_lower_percent value!\n");
else
bot_chat_lower_percent = temp;
}
sprintf(msg, "bot_chat_lower_percent is %d\n", bot_chat_lower_percent);
ClientPrint(pEntity, HUD_PRINTNOTIFY, msg);
RETURN_META (MRES_SUPERCEDE);
}
else if (FStrEq(pcmd, "bot_grenade_time"))
{
if ((arg1 != NULL) && (*arg1 != 0))
{
int temp = atoi(arg1);
if ((temp < 0) || (temp > 60))
ClientPrint(pEntity, HUD_PRINTNOTIFY, "invalid bot_grenade_time value!\n");
else
bot_grenade_time = temp;
}
sprintf(msg, "bot_grenade_time is %d\n", bot_grenade_time);
ClientPrint(pEntity, HUD_PRINTNOTIFY, msg);
RETURN_META (MRES_SUPERCEDE);
}
else if (FStrEq(pcmd, "bot_logo_percent"))
{
if ((arg1 != NULL) && (*arg1 != 0))
{
int temp = atoi(arg1);
if ((temp < 0) || (temp > 100))
ClientPrint(pEntity, HUD_PRINTNOTIFY, "invalid bot_logo_percent value!\n");
else
bot_logo_percent = temp;
}
sprintf(msg, "bot_logo_percent is %d\n", bot_logo_percent);
ClientPrint(pEntity, HUD_PRINTNOTIFY, msg);
RETURN_META (MRES_SUPERCEDE);
}
else if (FStrEq(pcmd, "bot_reaction_time"))
{
if ((arg1 != NULL) && (*arg1 != 0))
{
int temp = atoi(arg1);
if ((temp < 0) || (temp > 3))
ClientPrint(pEntity, HUD_PRINTNOTIFY, "invalid bot_reaction_time value!\n");
else
bot_reaction_time = temp;
}
if (bot_reaction_time)
sprintf(msg, "bot_reaction_time is %d\n", bot_reaction_time);
else
sprintf(msg, "bot_reaction_time is DISABLED\n");
ClientPrint(pEntity, HUD_PRINTNOTIFY, msg);
RETURN_META (MRES_SUPERCEDE);
}
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)
ClientPrint(pEntity, HUD_PRINTNOTIFY, "random_color ENABLED\n");
else
ClientPrint(pEntity, HUD_PRINTNOTIFY, "random_color DISABLED\n");
RETURN_META (MRES_SUPERCEDE);
}
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)
ClientPrint(pEntity, HUD_PRINTNOTIFY, "botdontshoot ENABLED\n");
else
ClientPrint(pEntity, HUD_PRINTNOTIFY, "botdontshoot DISABLED\n");
RETURN_META (MRES_SUPERCEDE);
}
else if (FStrEq(pcmd, "waypoint"))
{
if (FStrEq(arg1, "on"))
{
g_waypoint_on = TRUE;
ClientPrint(pEntity, HUD_PRINTNOTIFY, "waypoints are ON\n");
}
else if (FStrEq(arg1, "off"))
{
g_waypoint_on = FALSE;
ClientPrint(pEntity, HUD_PRINTNOTIFY, "waypoints are OFF\n");
}
else if (FStrEq(arg1, "add"))
{
if (!g_waypoint_on)
g_waypoint_on = TRUE; // turn waypoints on if off
WaypointAdd(pEntity);
}
else if (FStrEq(arg1, "delete"))
{
if (!g_waypoint_on)
g_waypoint_on = TRUE; // turn waypoints on if off
WaypointDelete(pEntity);
}
else if (FStrEq(arg1, "save"))
{
WaypointSave();
ClientPrint(pEntity, HUD_PRINTNOTIFY, "waypoints saved\n");
}
else if (FStrEq(arg1, "load"))
{
if (WaypointLoad(pEntity))
ClientPrint(pEntity, HUD_PRINTNOTIFY, "waypoints loaded\n");
}
else if (FStrEq(arg1, "menu"))
{
int index;
if (num_waypoints < 1)
RETURN_META (MRES_SUPERCEDE);
index = WaypointFindNearest(pEntity, 50.0, -1);
if (index == -1)
RETURN_META (MRES_SUPERCEDE);
g_menu_waypoint = index;
g_menu_state = MENU_1;
UTIL_ShowMenu(pEntity, 0x1F, -1, FALSE, show_menu_1);
}
else if (FStrEq(arg1, "info"))
{
WaypointPrintInfo(pEntity);
}
else if (FStrEq(arg1, "update"))
{
ClientPrint(pEntity, HUD_PRINTNOTIFY, "updating waypoint tags...\n");
WaypointUpdate(pEntity);
ClientPrint(pEntity, HUD_PRINTNOTIFY, "...update done! (don't forget to save!)\n");
}
else
{
if (g_waypoint_on)
ClientPrint(pEntity, HUD_PRINTNOTIFY, "waypoints are ON\n");
else
ClientPrint(pEntity, HUD_PRINTNOTIFY, "waypoints are OFF\n");
}
RETURN_META (MRES_SUPERCEDE);
}
else if (FStrEq(pcmd, "autowaypoint"))
{
if (FStrEq(arg1, "on"))
{
g_auto_waypoint = TRUE;
g_waypoint_on = TRUE; // turn this on just in case
}
else if (FStrEq(arg1, "off"))
{
g_auto_waypoint = FALSE;