-
Notifications
You must be signed in to change notification settings - Fork 9
/
bot_client.cpp
1070 lines (937 loc) · 30.6 KB
/
bot_client.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
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++, C#, and Java: http://www.viva64.com
//
// FoXBot - AI Bot for Halflife's Team Fortress Classic
//
// (http://foxbot.net)
//
// botclient.cpp
//
// Copyright (C) 2003 - Tom "Redfox" Simpson
//
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License for more details at:
// http://www.gnu.org/copyleft/gpl.html
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
#include "extdll.h"
#include "util.h"
#include "bot.h"
#include "waypoint.h"
#include "bot_client.h"
#include "bot_func.h"
#include "bot_job_think.h"
#include "bot_navigate.h"
#include "bot_weapons.h"
#include "tf_defs.h"
// types of damage to ignore...
#define IGNORE_DAMAGE (DMG_CRUSH | DMG_FREEZE | DMG_SHOCK | DMG_DROWN | DMG_NERVEGAS | DMG_RADIATION | DMG_DROWNRECOVER | DMG_ACID | DMG_SLOWBURN | DMG_SLOWFREEZE)
extern int mod_id;
extern bot_t bots[32];
extern edict_t* clients[32];
bot_weapon_t weapon_defs[MAX_WEAPONS]; // array of weapon definitions
int g_state;
// int MatchScores[4]; // doesn't update reliably on all maps
// This message is sent when the TFC VGUI menu is displayed.
void BotClient_TFC_VGUI(void* p, int bot_index) {
/*if((*(int *)p) == 2) // is it a team select menu?
bots[bot_index].start_action = MSG_TFC_TEAM_SELECT;
else if((*(int *)p) == 3) // is is a class selection menu?
bots[bot_index].start_action = MSG_TFC_CLASS_SELECT;*/
}
// This message is sent when the Counter-Strike VGUI menu is displayed. // Not required for TFC - [APG]RoboCop[CL]
/*void BotClient_CS_VGUI(void* p, int bot_index)
{
if((*(int*)p) == 2) // is it a team select menu?
bots[bot_index].start_action = MSG_CS_TEAM_SELECT;
else if((*(int*)p) == 26) // is is a terrorist model select menu?
bots[bot_index].start_action = MSG_CS_T_SELECT;
else if((*(int*)p) == 27) // is is a counter-terrorist model select menu?
bots[bot_index].start_action = MSG_CS_CT_SELECT;
}
// This message is sent when a menu is being displayed in Counter-Strike.
void BotClient_CS_ShowMenu(void* p, int bot_index)
{
static int state = 0; // current state machine state
if(state < 3) {
state++; // ignore first 3 fields of message
return;
}
if(std::strcmp((char*)p, "#Team_Select") == 0) // team select menu?
{
bots[bot_index].start_action = MSG_CS_TEAM_SELECT;
} else if(std::strcmp((char*)p, "#Terrorist_Select") == 0) // T model select?
{
bots[bot_index].start_action = MSG_CS_T_SELECT;
} else if(std::strcmp((char*)p, "#CT_Select") == 0) // CT model select menu?
{
bots[bot_index].start_action = MSG_CS_CT_SELECT;
}
state = 0; // reset state machine
}
// This message is sent when the Op4 VGUI menu is displayed.
void BotClient_Gearbox_VGUI(void* p, int bot_index)
{
if((*(int*)p) == 2) // is it a team select menu?
bots[bot_index].start_action = MSG_OPFOR_TEAM_SELECT;
else if((*(int*)p) == 3) // is is a class selection menu?
bots[bot_index].start_action = MSG_OPFOR_CLASS_SELECT;
}
// This message is sent when the FrontLineForce VGUI menu is displayed.
void BotClient_FLF_VGUI(void* p, int bot_index)
{
if((*(int*)p) == 2) // is it a team select menu?
bots[bot_index].start_action = MSG_FLF_TEAM_SELECT;
else if((*(int*)p) == 3) // is it a class selection menu?
bots[bot_index].start_action = MSG_FLF_CLASS_SELECT;
else if((*(int*)p) == 70) // is it a weapon selection menu?
bots[bot_index].start_action = MSG_FLF_WEAPON_SELECT;
else if((*(int*)p) == 72) // is it a submachine gun selection menu?
bots[bot_index].start_action = MSG_FLF_SUBMACHINE_SELECT;
else if((*(int*)p) == 73) // is it a shotgun selection menu?
bots[bot_index].start_action = MSG_FLF_SHOTGUN_SELECT;
else if((*(int*)p) == 75) // is it a rifle selection menu?
bots[bot_index].start_action = MSG_FLF_RIFLE_SELECT;
else if((*(int*)p) == 76) // is it a pistol selection menu?
bots[bot_index].start_action = MSG_FLF_PISTOL_SELECT;
else if((*(int*)p) == 78) // is it a heavyweapons selection menu?
bots[bot_index].start_action = MSG_FLF_HEAVYWEAPONS_SELECT;
}
*/
// This message is sent when a client joins the game. All of the weapons
// are sent with the weapon ID and information about what ammo is used.
void BotClient_Valve_WeaponList(void* p, int bot_index) {
static int state = 0; // current state machine state
static bot_weapon_t bot_weapon;
if (state == 0) {
state++;
std::strcpy(bot_weapon.szClassname, static_cast<char*>(p));
}
else if (state == 1) {
state++;
bot_weapon.iAmmo1 = *static_cast<int*>(p); // ammo index 1
}
else if (state == 2) {
state++;
bot_weapon.iAmmo1Max = *static_cast<int*>(p); // max ammo1
}
else if (state == 3) {
state++;
bot_weapon.iAmmo2 = *static_cast<int*>(p); // ammo index 2
}
else if (state == 4) {
state++;
bot_weapon.iAmmo2Max = *static_cast<int*>(p); // max ammo2
}
else if (state == 5) {
state++;
bot_weapon.iSlot = *static_cast<int*>(p); // slot for this weapon
}
else if (state == 6) {
state++;
bot_weapon.iPosition = *static_cast<int*>(p); // position in slot
}
else if (state == 7) {
state++;
bot_weapon.iId = *static_cast<int*>(p); // weapon ID
}
else if (state == 8) {
state = 0;
bot_weapon.iFlags = *static_cast<int*>(p); // flags for weapon (WTF???)
// store away this weapon with it's ammo information...
weapon_defs[bot_weapon.iId] = bot_weapon;
}
}
void BotClient_TFC_WeaponList(void* p, const int bot_index) {
// this is just like the Valve Weapon List message
BotClient_Valve_WeaponList(p, bot_index);
}
// Not required for TFC - [APG]RoboCop[CL]
/*void BotClient_CS_WeaponList(void* p, int bot_index)
{
// this is just like the Valve Weapon List message
BotClient_Valve_WeaponList(p, bot_index);
}
void BotClient_Gearbox_WeaponList(void* p, int bot_index)
{
// this is just like the Valve Weapon List message
BotClient_Valve_WeaponList(p, bot_index);
}
void BotClient_FLF_WeaponList(void* p, int bot_index)
{
// this is just like the Valve Weapon List message
BotClient_Valve_WeaponList(p, bot_index);
}
*/
// This message is sent when a weapon is selected (either by the bot chosing
// a weapon or by the server auto assigning the bot a weapon).
void BotClient_Valve_CurrentWeapon(void* p, const int bot_index) {
// static int state = 0; // current state machine state
static int iState;
static int iId;
if (g_state == 0) {
g_state++;
iState = *static_cast<int*>(p); // state of the current weapon
}
else if (g_state == 1) {
g_state++;
iId = *static_cast<int*>(p); // weapon ID of current weapon
}
else if (g_state == 2) {
static int iClip;
// state = 0;
iClip = *static_cast<int*>(p); // ammo currently in the clip for this weapon
if (iId <= 31) {
bots[bot_index].bot_weapons |= 1 << iId; // set this weapon bit
if (iState == 1) {
bots[bot_index].current_weapon.iId = iId;
bots[bot_index].current_weapon.iClip = iClip;
// update the ammo counts for this weapon...
bots[bot_index].current_weapon.iAmmo1 = bots[bot_index].m_rgAmmo[weapon_defs[iId].iAmmo1];
bots[bot_index].current_weapon.iAmmo2 = bots[bot_index].m_rgAmmo[weapon_defs[iId].iAmmo2];
}
}
}
}
void BotClient_TFC_CurrentWeapon(void* p, const int bot_index) {
// this is just like the Valve Current Weapon message
BotClient_Valve_CurrentWeapon(p, bot_index);
}
/* // Not required for TFC - [APG]RoboCop[CL]
void BotClient_CS_CurrentWeapon(void* p, int bot_index)
{
// this is just like the Valve Current Weapon message
BotClient_Valve_CurrentWeapon(p, bot_index);
}
void BotClient_Gearbox_CurrentWeapon(void* p, int bot_index)
{
// this is just like the Valve Current Weapon message
BotClient_Valve_CurrentWeapon(p, bot_index);
}
void BotClient_FLF_CurrentWeapon(void* p, int bot_index)
{
// this is just like the Valve Current Weapon message
BotClient_Valve_CurrentWeapon(p, bot_index);
}
*/
// This message is sent whenever ammo ammounts are adjusted (up or down).
void BotClient_Valve_AmmoX(void* p, const int bot_index) {
// static int state = 0; // current state machine state
static int index;
if (g_state == 0) {
g_state++;
index = *static_cast<int*>(p); // ammo index (for type of ammo)
}
else if (g_state == 1) {
static int ammount;
// state = 0;
ammount = *static_cast<int*>(p); // the amount of ammo currently available
bots[bot_index].m_rgAmmo[index] = ammount; // store it away
const int ammo_index = bots[bot_index].current_weapon.iId;
// update the ammo counts for this weapon...
bots[bot_index].current_weapon.iAmmo1 = bots[bot_index].m_rgAmmo[weapon_defs[ammo_index].iAmmo1];
bots[bot_index].current_weapon.iAmmo2 = bots[bot_index].m_rgAmmo[weapon_defs[ammo_index].iAmmo2];
}
}
void BotClient_TFC_AmmoX(void* p, const int bot_index) {
// this is just like the Valve AmmoX message
BotClient_Valve_AmmoX(p, bot_index);
}
/* // Not required for TFC - [APG]RoboCop[CL]
void BotClient_CS_AmmoX(void* p, int bot_index)
{
// this is just like the Valve AmmoX message
BotClient_Valve_AmmoX(p, bot_index);
}
void BotClient_Gearbox_AmmoX(void* p, int bot_index)
{
// this is just like the Valve AmmoX message
BotClient_Valve_AmmoX(p, bot_index);
}
void BotClient_FLF_AmmoX(void* p, int bot_index)
{
// this is just like the Valve AmmoX message
BotClient_Valve_AmmoX(p, bot_index);
}
*/
// This message is sent when the bot picks up some ammo (AmmoX messages are
// also sent so this message is probably not really necessary except it
// allows the HUD to draw pictures of ammo that have been picked up. The
// bots don't really need pictures since they don't have any eyes anyway.
void BotClient_Valve_AmmoPickup(void* p, const int bot_index) {
static int state = 0; // current state machine state
static int index;
if (state == 0) {
state++;
index = *static_cast<int*>(p);
}
else if (state == 1) {
static int ammount;
state = 0;
ammount = *static_cast<int*>(p);
bots[bot_index].m_rgAmmo[index] = ammount;
const int ammo_index = bots[bot_index].current_weapon.iId;
// update the ammo counts for this weapon...
bots[bot_index].current_weapon.iAmmo1 = bots[bot_index].m_rgAmmo[weapon_defs[ammo_index].iAmmo1];
bots[bot_index].current_weapon.iAmmo2 = bots[bot_index].m_rgAmmo[weapon_defs[ammo_index].iAmmo2];
}
}
void BotClient_TFC_AmmoPickup(void* p, const int bot_index) {
// this is just like the Valve Ammo Pickup message
BotClient_Valve_AmmoPickup(p, bot_index);
}
/* // Not required for TFC - [APG]RoboCop[CL]
void BotClient_CS_AmmoPickup(void* p, int bot_index)
{
// this is just like the Valve Ammo Pickup message
BotClient_Valve_AmmoPickup(p, bot_index);
}
void BotClient_Gearbox_AmmoPickup(void* p, int bot_index)
{
// this is just like the Valve Ammo Pickup message
BotClient_Valve_AmmoPickup(p, bot_index);
}
void BotClient_FLF_AmmoPickup(void* p, int bot_index)
{
// this is just like the Valve Ammo Pickup message
BotClient_Valve_AmmoPickup(p, bot_index);
}
*/
// This message gets sent when the bot picks up a weapon.
void BotClient_Valve_WeaponPickup(void* p, const int bot_index) {
const int index = *static_cast<int*>(p);
// set this weapon bit to indicate that we are carrying this weapon
bots[bot_index].bot_weapons |= 1 << index;
}
void BotClient_TFC_WeaponPickup(void* p, const int bot_index) {
// this is just like the Valve Weapon Pickup message
BotClient_Valve_WeaponPickup(p, bot_index);
}
/*// Not required for TFC - [APG]RoboCop[CL]
void BotClient_CS_WeaponPickup(void* p, int bot_index)
{
// this is just like the Valve Weapon Pickup message
BotClient_Valve_WeaponPickup(p, bot_index);
}
void BotClient_Gearbox_WeaponPickup(void* p, int bot_index)
{
// this is just like the Valve Weapon Pickup message
BotClient_Valve_WeaponPickup(p, bot_index);
}
void BotClient_FLF_WeaponPickup(void* p, int bot_index)
{
// this is just like the Valve Weapon Pickup message
BotClient_Valve_WeaponPickup(p, bot_index);
}
*/
// This message gets sent when the bot picks up an item (like a battery
// or a healthkit)
void BotClient_Valve_ItemPickup(void* p, int bot_index) {}
void BotClient_TFC_ItemPickup(void* p, const int bot_index) {
// this is just like the Valve Item Pickup message
BotClient_Valve_ItemPickup(p, bot_index);
const int index = *static_cast<int*>(p);
char msg[255];
snprintf(msg, sizeof(msg), "%d", index);
// UTIL_HostSay(0, 0, msg);
// FILE *fp;
//{ fp=std::fopen("route.txt","a"); std::fprintf(fp,"a %s\n",msg); std::fclose(fp); }
}
/* // Not required for TFC - [APG]RoboCop[CL]
void BotClient_CS_ItemPickup(void* p, int bot_index)
{
// this is just like the Valve Item Pickup message
BotClient_Valve_ItemPickup(p, bot_index);
}
void BotClient_Gearbox_ItemPickup(void* p, int bot_index)
{
// this is just like the Valve Item Pickup message
BotClient_Valve_ItemPickup(p, bot_index);
}
void BotClient_FLF_ItemPickup(void* p, int bot_index)
{
// this is just like the Valve Item Pickup message
BotClient_Valve_ItemPickup(p, bot_index);
}
*/
// This message gets sent when the bots health changes.
void BotClient_Valve_Health(void* p, const int bot_index) {
bots[bot_index].bot_real_health = *static_cast<int*>(p); // health ammount
}
void BotClient_TFC_Health(void* p, const int bot_index) {
// this is just like the Valve Health message
BotClient_Valve_Health(p, bot_index);
}
/* // Not required for TFC - [APG]RoboCop[CL]
void BotClient_CS_Health(void* p, int bot_index)
{
// this is just like the Valve Health message
BotClient_Valve_Health(p, bot_index);
}
void BotClient_Gearbox_Health(void* p, int bot_index)
{
// this is just like the Valve Health message
BotClient_Valve_Health(p, bot_index);
}
void BotClient_FLF_Health(void* p, int bot_index)
{
// this is just like the Valve Health message
BotClient_Valve_Health(p, bot_index);
}
*/
// This message gets sent when the bots armor changes.
void BotClient_Valve_Battery(void* p, const int bot_index) {
bots[bot_index].bot_armor = *static_cast<int*>(p); // armor ammount
}
void BotClient_TFC_Battery(void* p, const int bot_index) {
// this is just like the Valve Battery message
BotClient_Valve_Battery(p, bot_index);
}
/* // Not required for TFC - [APG]RoboCop[CL]
void BotClient_CS_Battery(void* p, int bot_index)
{
// this is just like the Valve Battery message
BotClient_Valve_Battery(p, bot_index);
}
void BotClient_Gearbox_Battery(void* p, int bot_index)
{
// this is just like the Valve Battery message
BotClient_Valve_Battery(p, bot_index);
}
void BotClient_FLF_Battery(void* p, int bot_index)
{
// this is just like the Valve Battery message
BotClient_Valve_Battery(p, bot_index);
}
*/
// This message gets sent when the bots are getting damaged.
// Note: This message might also be sent after a bot died and has
// respawned reporting the damage that killed it.
// i.e. after BotSpawnInit() is called.
void BotClient_Valve_Damage(void* p, const int bot_index) {
static int state = 0; // current state machine state
static int damage_armor;
static int damage_taken;
static int damage_bits; // type of damage being done
static Vector damage_origin;
if (state == 0) {
state++;
damage_armor = *static_cast<int*>(p);
}
else if (state == 1) {
state++;
damage_taken = *static_cast<int*>(p);
}
else if (state == 2) {
state++;
damage_bits = *static_cast<int*>(p);
}
else if (state == 3) {
state++;
damage_origin.x = *static_cast<float*>(p);
}
else if (state == 4) {
state++;
damage_origin.y = *static_cast<float*>(p);
}
else if (state == 5) {
state = 0;
damage_origin.z = *static_cast<float*>(p);
if (mod_id == TFC_DLL) {
if ((damage_bits & DMG_SONIC) == DMG_SONIC) {
bots[bot_index].disturbedViewAmount = 45;
bots[bot_index].f_disturbedViewTime = bots[bot_index].f_think_time + 5.0f;
}
else if ((damage_bits & DMG_BURN) == DMG_BURN) {
// added by Zybby, burning bots aim worse too
bots[bot_index].disturbedViewAmount = 15;
bots[bot_index].f_disturbedViewTime = bots[bot_index].f_think_time + 2.0f;
}
else if ((damage_bits & DMG_BLAST) == DMG_BLAST) {
// blown up bots aim worse too
bots[bot_index].disturbedViewAmount = 10;
bots[bot_index].f_disturbedViewTime = bots[bot_index].f_think_time + 2.0f;
}
}
// let the bot know it's getting hurt
if (damage_armor > 0 || damage_taken > 0) {
// drowning detection - set up a job to avoid death by drowning
if (damage_bits & DMG_DROWN
// && bots[bot_index].pEdict->v.waterlevel == WL_HEAD_IN_WATER
&& bots[bot_index].bot_skill < 3) {
job_struct* newJob = InitialiseNewJob(&bots[bot_index], JOB_DROWN_RECOVER);
if (newJob != nullptr) {
newJob->waypoint = BotDrowningWaypointSearch(&bots[bot_index]);
if (newJob->waypoint != -1)
SubmitNewJob(&bots[bot_index], JOB_DROWN_RECOVER, newJob);
}
}
// ignore certain types of damage(e.g. environmental)
if (damage_bits & IGNORE_DAMAGE)
return;
// if the bot didn't spawn very recently
if (gpGlobals->time > bots[bot_index].last_spawn_time + 1.0f) {
bots[bot_index].f_injured_time = gpGlobals->time;
// stop using health or HEV stations...
bots[bot_index].b_use_health_station = false;
bots[bot_index].b_use_HEV_station = false;
}
}
}
}
void BotClient_TFC_Damage(void* p, const int bot_index) { BotClient_Valve_Damage(p, bot_index); }
/* // Not required for TFC - [APG]RoboCop[CL]
void BotClient_CS_Damage(void* p, int bot_index)
{
// this is just like the Valve Battery message
BotClient_Valve_Damage(p, bot_index);
}
void BotClient_Gearbox_Damage(void* p, int bot_index)
{
// this is just like the Valve Battery message
BotClient_Valve_Damage(p, bot_index);
}
void BotClient_FLF_Damage(void* p, int bot_index)
{
// this is just like the Valve Battery message
BotClient_Valve_Damage(p, bot_index);
}
*/
// This message gets sent when the bots money ammount changes
// For Counterstrike.
/*void BotClient_CS_Money(void *p, int bot_index)
{
static int state = 0; // current state machine state
if(state == 0)
{
state++;
bots[bot_index].bot_money = *(int *)p; // amount of money
}
else
{
state = 0; // ingore this field
}
}*/
// This message gets sent when the bots get killed
void BotClient_Valve_DeathMsg(void* p, int bot_index) {
static int state = 0; // current state machine state
static int killer_index;
static int victim_index;
if (state == 0) {
state++;
killer_index = *static_cast<int*>(p); // ENTINDEX() of killer
}
else if (state == 1) {
state++;
victim_index = *static_cast<int*>(p); // ENTINDEX() of victim
}
else if (state == 2) {
static int indexb;
static int index;
static edict_t* killer_edict;
static edict_t* victim_edict;
state = 0;
victim_edict = INDEXENT(victim_index);
index = UTIL_GetBotIndex(victim_edict);
// do message return for human client, so bot can do
// haha killed ya message
// FILE *fp;
//{ fp=UTIL_OpenFoxbotLog(); std::fprintf(fp,"kill messages\n"); std::fclose(fp); }
if (index == -1) {
if (killer_index == 0 || killer_index == victim_index) {
// bot killed by world (worldspawn) or bot killed self...
// bots[index].killer_edict = NULL;
}
else {
killer_edict = INDEXENT(killer_index);
indexb = UTIL_GetBotIndex(killer_edict);
if (indexb != -1 && victim_edict != nullptr) {
if (UTIL_GetTeam(killer_edict) != UTIL_GetTeam(victim_edict)) {
bots[indexb].killed_edict = victim_edict;
}
}
}
}
// is this message about a bot being killed?
if (index != -1) {
if (killer_index == 0 || killer_index == victim_index) {
// bot killed by world (worldspawn) or bot killed self...
bots[index].killer_edict = nullptr;
}
else {
// store edict of player that killed this bot...
bots[index].killer_edict = INDEXENT(killer_index);
killer_edict = INDEXENT(killer_index);
indexb = UTIL_GetBotIndex(killer_edict);
if (indexb != -1 && victim_edict != nullptr) {
if (UTIL_GetTeam(killer_edict) != UTIL_GetTeam(victim_edict)) {
bots[indexb].killed_edict = victim_edict;
}
}
}
}
}
}
void BotClient_TFC_DeathMsg(void* p, const int bot_index) {
// this is just like the Valve DeathMsg message
BotClient_Valve_DeathMsg(p, bot_index);
}
/* // Not required for TFC - [APG]RoboCop[CL]
void BotClient_CS_DeathMsg(void* p, int bot_index)
{
// this is just like the Valve DeathMsg message
BotClient_Valve_DeathMsg(p, bot_index);
}
void BotClient_Gearbox_DeathMsg(void* p, int bot_index)
{
// this is just like the Valve DeathMsg message
BotClient_Valve_DeathMsg(p, bot_index);
}
void BotClient_FLF_DeathMsg(void* p, int bot_index)
{
// this is just like the Valve DeathMsg message
BotClient_Valve_DeathMsg(p, bot_index);
}
*/
// This message gets sent when a text message is displayed
/*void BotClient_FLF_TextMsg(void *p, int bot_index)
{
static int state = 0; // current state machine state
static int msg_dest = 0;
if(state == 0)
{
state++;
msg_dest = *(int *)p; // HUD_PRINTCENTER, etc.
}
else if(state == 1)
{
state = 0;
if(std::strcmp((char *)p, "You are Attacking\n") == 0) // attacker msg
{
bots[bot_index].defender = 0; // attacker
}
else if(std::strcmp((char *)p, "You are Defending\n") == 0) // defender msg
{
bots[bot_index].defender = 1; // defender
}
}
}
// This message gets sent when the WarmUpTime is enabled/disabled
void BotClient_FLF_WarmUp(void *p, int bot_index)
{
// bots[bot_index].warmup = *(int *)p;
}
// This message gets sent to ALL when the WarmUpTime is enabled/disabled
void BotClient_FLF_WarmUpAll(void *p, int bot_index)
{
for(int i = 0; i < 32; i++)
{
if(bots[i].is_used) // count the number of bots in use
bots[i].warmup = *(int *)p;
}
}
// This message gets sent when the round is over
void BotClient_FLF_WinMessage(void *p, int bot_index)
{
for(int i = 0; i < 32; i++)
{
if(bots[i].is_used) // count the number of bots in use
bots[i].round_end = 1;
}
}
// This message gets sent when a temp entity is created
void BotClient_FLF_TempEntity(void *p, int bot_index)
{
static int state = 0; // current state machine state
static int te_type; // TE_ message type
if(p == NULL) // end of message?
{
state = 0;
return;
}
if(state == 0)
{
state++;
te_type = *(int *)p;
return;
}
if(te_type == TE_TEXTMESSAGE)
{
if(state == 16)
{
if(std::strncmp((char *)p, "Capturing ", 10) == 0)
{
// if bot is currently capturing, keep timer alive...
if(bots[bot_index].b_use_capture)
bots[bot_index].f_use_capture_time = gpGlobals->time + 2.0f;
}
}
state++;
}
}*/
void BotClient_Valve_ScreenFade(void* p, const int bot_index) {
static int state = 0; // current state machine state
static int duration;
static int hold_time;
// static int fade_flags;
if (state == 0) {
state++;
duration = *static_cast<int*>(p);
}
else if (state == 1) {
state++;
hold_time = *static_cast<int*>(p);
}
else if (state == 2) {
state++;
// fade_flags = *static_cast<int *>(p);
}
else if (state == 6) {
state = 0;
const int length = (duration + hold_time) / 4096;
bots[bot_index].f_blinded_time = gpGlobals->time + static_cast<float>(length - 2);
}
else {
state++;
}
}
void BotClient_TFC_ScreenFade(void* p, const int bot_index) {
// this is just like the Valve ScreenFade message
BotClient_Valve_ScreenFade(p, bot_index);
}
/* // Not required for TFC - [APG]RoboCop[CL]
void BotClient_CS_ScreenFade(void* p, int bot_index)
{
// this is just like the Valve ScreenFade message
BotClient_Valve_ScreenFade(p, bot_index);
}
void BotClient_Gearbox_ScreenFade(void* p, int bot_index)
{
// this is just like the Valve ScreenFade message
BotClient_Valve_ScreenFade(p, bot_index);
}
void BotClient_FLF_ScreenFade(void* p, int bot_index)
{
// this is just like the Valve ScreenFade message
BotClient_Valve_ScreenFade(p, bot_index);
}
*/
// This function can be used to monitor which icons are displayed on the bot's HUD.
// NOTE: This can be used to see if a bot is tranquilised or hallucinating but not
// if it's infected.
void BotClient_TFC_StatusIcon(void* p, int bot_index) {
/* static int icon_status = 0;
if(g_state == 0)
{
icon_status = *(int *)p;
++g_state;
}
else if(g_state == 1)
{
// we could detect caltrop damage here
if(std::strncmp("dmg_", (char *)p, 4) == 0)
UTIL_BotLogPrintf("HUD: %s, status %d\n",
(char *)p, icon_status);
}*/
}
// This function can be used to track messages to TFC engineer bots telling
// them about the status of what they are building.
// From what I've seen a bot can be told by this function that it has
// built a sentry gun before the sentry gun even exists!
void BotClient_Engineer_BuildStatus(void* p, const int bot_index) {
// here are some interesting messages(so far unused):
// #Sentry_shellslow
// #Sentry_sbar n%% (where n is a number from 0 to 100 I think)
// #Sentry_finish (#Sentry_built seems to come after this)
// #Sentry_repair
// #Sentry_upgrade
// #Sentry_destroyed
// #Build_onesentry (just tried to make two?)
// #Build_stop (e.g. stopped building a sentry)
// #Observer (not engineer related, but received by this function)
// #Spy_disguised Red #Sniper
// #Teleporter_entrance_idle
// which tp component building
static int teleportType = 0;
if (g_state == 0) {
g_state++;
}
else if (g_state == 1) {
// UTIL_BotLogPrintf("%s, message %s\n", bots[bot_index].name, (char *)p);
if (std::strcmp(static_cast<char*>(p), "#Dispenser_used") == 0) // enemy is using bots dispenser
{
if (bot_index != -1) {
// set up the time when the bot will detonate it's dispenser
if (bots[bot_index].bot_skill < 3)
bots[bot_index].f_dispenserDetTime = gpGlobals->time + random_float(0.5f, static_cast<float>(bots[bot_index].bot_skill) + 0.5f);
}
g_state++;
}
else if (std::strcmp(static_cast<char*>(p), "#Teleporter_Entrance_Built") == 0) {
teleportType = W_FL_TFC_TELEPORTER_ENTRANCE;
g_state++;
}
else if (std::strcmp(static_cast<char*>(p), "#Teleporter_Exit_Built") == 0) {
teleportType = W_FL_TFC_TELEPORTER_EXIT;
g_state++;
}
else {
// do script handling... as hunted info gets passed in here
script(static_cast<char*>(p));
}
}
else if (g_state == 2) {
// here we can track objects built by human players
if (bot_index == -1) {
// The builders name
char builder[128];
std::strncpy(builder, static_cast<char*>(p), 128);
builder[127] = '\0';
// Loop through the humans to look for the builder
for (edict_t *&client : clients) {
// is this client the builder?
if (client && std::strcmp(STRING(client->v.netname), builder) == 0) {
// Get the teleporter ent
edict_t* pent = nullptr;
while ((pent = FIND_ENTITY_IN_SPHERE(pent, client->v.origin, 200)) != nullptr && !FNullEnt(pent)) {
const float l = (client->v.origin - pent->v.origin).Length2D();
if (std::strcmp("building_teleporter", STRING(pent->v.classname)) == 0 && l >= 16.0f && l <= 96.0f) {
// Set the owner on the teleport
pent->v.euser1 = client;
pent->v.iuser1 = teleportType;
teleportType = 0;
break;
}
}
break;
}
}
}
}
}
void BotClient_TFC_SentryAmmo(void* p, const int bot_index) {
// static int state = 0; // current state machine state
static int val;
if (g_state == 0) {
g_state++;
val = *static_cast<int*>(p);
}
else if (g_state == 1) {
if (val == 4) {
bots[bot_index].sentry_ammo = *static_cast<int*>(p);
}
}
}
void BotClient_TFC_DetPack(void* p, const int bot_index) {
// static int state = 0; // current state machine state
// static int val;
/*if(g_state == 0)
{
//g_state++;
val = *(int *)p;
}*/
bots[bot_index].detpack = *static_cast<int*>(p);
/* FILE *fp = UTIL_OpenFoxbotLog();
if(fp != NULL)
{
std::fprintf(fp,"%s detpack set to %d\n",
bots[bot_index].name, bots[bot_index].detpack);
std::fclose(fp);
}*/
}
void BotClient_Menu(void* p, int bot_index) {
#if FALSE
static int val, s;
if (g_state == 0) {
// g_state++;
val = *static_cast<int*>(p);
s = 0;
int i = 10;
while (!((1 << i & val) == 1 << i) && i >= 0)
i--;
s = i + 1;
// FILE *fp;
//{ fp=UTIL_OpenFoxbotLog(); std::fprintf(fp,"%d %d\n",*(int *)p,selection); std::fclose(fp); }
}
/*if(g_state==3)
{
if(s>0)
{
int c=RANDOM_LONG(1,s);
char msg[20];
itoa(c,msg,10);
FakeClientCommand(bots[bot_index].pEdict,"menuselect",msg,NULL);