-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot_client.cpp
1524 lines (1256 loc) · 41.1 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
///////////////////////////////////////////////////////////////////////////////////////////////
//
// -- GNU -- open source
// Please read and agree to the mb_gnu_license.txt file
// (the file is located in the marine_bot source folder)
// before editing or distributing this source code.
// This source code is free for use under the rules of the GNU General Public License.
// For more information goto:: http://www.gnu.org/licenses/
//
// credits to - valve, botman.
//
// Marine Bot - code by Frank McNeil, Kota@, Mav, Shrike.
//
// (http://marinebot.xf.cz)
//
//
// bot_client.cpp
//
////////////////////////////////////////////////////////////////////////////////////////////////
#if defined(WIN32)
#pragma warning(disable: 4005 91)
#endif
#include "defines.h"
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "bot.h"
#include "bot_func.h"
#include "bot_manager.h"
#include "bot_client.h"
#include "bot_weapons.h"
// types of damage to ignore
#define IGNORE_DAMAGE (DMG_CRUSH | DMG_FREEZE | DMG_FALL | DMG_SHOCK | \
DMG_NERVEGAS | DMG_RADIATION | DMG_ACID | DMG_SLOWBURN | \
DMG_SLOWFREEZE | 0xFF000000)
bot_weapon_t weapon_defs[MAX_WEAPONS]; // array of weapon definitions
/*
* this message is sent when the Firearms VGUI menu is displayed
*/
void BotClient_FA_VGUI(void *p, int bot_index)
{
static int state = 0; // current state machine state
static int iValue1; // the first byte is the most important value in vgui message
// we need to process the whole message first
if (state == 0)
{
state++;
iValue1 = *static_cast<int*>(p); // store this away we need it
}
// additionals two values, but we don't use/need them now
else if (state == 1)
{
state++; // just skip it
}
else if (state == 2)
{
state = 0; // reset the counter
}
// now process the important values...
// handle Firearms 2.9 MOTD window confirmation
if ((g_mod_version == FA_29) || (g_mod_version == FA_30))
{
if (iValue1 == 19)
bots[bot_index].start_action = MSG_FA_MOTD_WINDOW;
}
// do we spawn a bot in Firearms 2.5 and below?
if (UTIL_IsOldVersion())
{
if (iValue1 == 1)
bots[bot_index].start_action = MSG_FA25_BASE_ARMOR_SELECT;
else if (iValue1 == 2)
bots[bot_index].start_action = MSG_FA25_ARMOR_SELECT;
else if (iValue1 == 3)
bots[bot_index].start_action = MSG_FA25_ITEMS_SELECT;
else if (iValue1 == 4)
bots[bot_index].start_action = MSG_FA25_SIDEARMS_SELECT;
else if (iValue1 == 5)
bots[bot_index].start_action = MSG_FA25_SHOTGUNS_SELECT;
else if (iValue1 == 6)
bots[bot_index].start_action = MSG_FA25_SMGS_SELECT;
else if (iValue1 == 7)
bots[bot_index].start_action = MSG_FA25_RIFLES_SELECT;
else if (iValue1 == 8)
bots[bot_index].start_action = MSG_FA25_SNIPES_SELECT;
else if (iValue1 == 9)
bots[bot_index].start_action = MSG_FA25_MGUNS_SELECT;
else if (iValue1 == 10)
bots[bot_index].start_action = MSG_FA25_GLS_SELECT;
}
// is it a join the game confirmation?
if (iValue1 == 12)
bots[bot_index].start_action = MSG_FA_INTO_BATTLE;
//is it team select menu?
else if (iValue1 == 13)
bots[bot_index].start_action = MSG_FA_TEAM_SELECT;
// is it a class selection menu?
else if (iValue1 == 14)
bots[bot_index].start_action = MSG_FA_CLASS_SELECT;
// is it a skill selection menu?
// (it's also displayed after a round end if we have enough points to take new skill)
else if (iValue1 == 20)
bots[bot_index].start_action = MSG_FA_SKILL_SELECT;
//NOTE: This one was probably removed or changed to the one above (==12)
// is it a join the game confirmation?
else if (iValue1 == 22)
bots[bot_index].start_action = MSG_FA_INTO_BATTLE;
}
/*
* 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_FA_WeaponList(void *p, int bot_index)
{
static int state = 0; // current state machine state
static bot_weapon_t bot_weapon;
if (state == 0)
{
state++;
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 (???)
// store away this weapon with it's ammo information
weapon_defs[bot_weapon.iId] = bot_weapon;
}
}
/*
* this message is sent when a weapon is selected (either by the bot choosing
* a weapon or by the server auto assigning the bot a weapon)
*/
void BotClient_FA_CurrentWeapon(void *p, int bot_index)
{
static int state = 0; // current state machine state
static int iState;
static int iId;
static int iClip;
static int iAttach;
static int iFireMode;
if (state == 0)
{
state++;
iState = *static_cast<int*>(p); // state of the current weapon
}
else if (state == 1)
{
state++;
iId = *static_cast<int*>(p); // weapon ID of current weapon
}
else if (state == 2)
{
state++;
iClip = *static_cast<int*>(p); // ammo currently in the clip for this weapon
}
// probably secondary fire handler
// if stealth mount supressor (0-normal, 1-silenced)
// if arty ammo2 currently in chamber (0-empty 1-loaded)
else if (state == 3)
{
state++;
iAttach = *static_cast<int*>(p);
}
// fire mode handler code
else if (state == 4)
{
state = 0;
iFireMode = *static_cast<int*>(p); // 4-auto, 2-burst, 1-single, 0-on weapon where no choice
if (iId <= 31)
{
if (bot_index != -1)
{
bots[bot_index].bot_weapons |= (1<<iId); // set this weapon bit
if (iState == 1)
{
bots[bot_index].current_weapon.isActive = iState;
bots[bot_index].current_weapon.iId = iId;
bots[bot_index].current_weapon.iClip = iClip;
bots[bot_index].current_weapon.iAttachment = iAttach;
bots[bot_index].current_weapon.iFireMode = iFireMode;
// update the ammo counts for this weapon
bots[bot_index].current_weapon.iAmmo1 =
bots[bot_index].curr_rgAmmo[weapon_defs[iId].iAmmo1];
bots[bot_index].current_weapon.iAmmo2 =
bots[bot_index].curr_rgAmmo[weapon_defs[iId].iAmmo2];
}
}
}
}
}
/*
* this message is sent whenever ammo ammounts are adjusted (up or down)
*/
void BotClient_FA_AmmoX(void *p, int bot_index)
{
static int state = 0; // current state machine state
static int index;
static int ammount;
if (state == 0)
{
state++;
index = *static_cast<int*>(p); // ammo index (for type of ammo)
}
else if (state == 1)
{
state = 0;
ammount = *static_cast<int*>(p); // the ammount of ammo currently available
bots[bot_index].curr_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].curr_rgAmmo[weapon_defs[ammo_index].iAmmo1];
bots[bot_index].current_weapon.iAmmo2 =
bots[bot_index].curr_rgAmmo[weapon_defs[ammo_index].iAmmo2];
}
}
/*
* 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_FA_AmmoPickup(void *p, int bot_index)
{
static int state = 0; // current state machine state
static int index;
static int ammount;
if (state == 0)
{
state++;
index = *static_cast<int*>(p);
}
else if (state == 1)
{
state = 0;
ammount = *static_cast<int*>(p);
bots[bot_index].curr_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].curr_rgAmmo[weapon_defs[ammo_index].iAmmo1];
bots[bot_index].current_weapon.iAmmo2 =
bots[bot_index].curr_rgAmmo[weapon_defs[ammo_index].iAmmo2];
}
}
/*
* NEW CODE 094
* this message gets sent when the bot picks up a weapon
*/
void BotClient_FA_WeaponPickup(void *p, int bot_index)
{
const int index = *static_cast<int*>(p);
#ifdef DEBUG
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ NEW CODE 094 (remove it)
//char dmsg[256];
//sprintf(dmsg, "FA weap pickup() -> index =<%d>\n", index);
//UTIL_DebugInFile(dmsg);
//ALERT(at_console, dmsg);
#endif // DEBUG
// set this weapon bit to indicate that we are carrying this weapon
bots[bot_index].bot_weapons |= (1 << index);
if (bots[bot_index].bot_weapons & (1 << fa_weapon_claymore))
{
if (bots[bot_index].claymore_slot == NO_VAL)
bots[bot_index].claymore_slot = fa_weapon_claymore;
if (bots[bot_index].f_use_clay_time != 0.0)
bots[bot_index].f_use_clay_time = 0.0;
if (bots[bot_index].clay_action != ALTW_NOTUSED)
bots[bot_index].clay_action = ALTW_NOTUSED;
}
if (bots[bot_index].bot_weapons & (1 << fa_weapon_frag))
{
if (bots[bot_index].grenade_slot == NO_VAL)
bots[bot_index].grenade_slot = fa_weapon_frag;
if (bots[bot_index].grenade_time != 0.0)
bots[bot_index].grenade_time = 0.0;
if (bots[bot_index].grenade_action != ALTW_NOTUSED)
bots[bot_index].grenade_action = ALTW_NOTUSED;
// if the bot picked this grenade up while already in game then let him check for other grenades he may carry
if (bots[bot_index].IsSubTask(ST_NOOTHERNADE))
bots[bot_index].RemoveSubTask(ST_NOOTHERNADE);
}
if (bots[bot_index].bot_weapons & (1 << fa_weapon_concussion))
{
if (bots[bot_index].grenade_slot == NO_VAL)
bots[bot_index].grenade_slot = fa_weapon_concussion;
if (bots[bot_index].grenade_time != 0.0)
bots[bot_index].grenade_time = 0.0;
if (bots[bot_index].grenade_action != ALTW_NOTUSED)
bots[bot_index].grenade_action = ALTW_NOTUSED;
if (bots[bot_index].IsSubTask(ST_NOOTHERNADE))
bots[bot_index].RemoveSubTask(ST_NOOTHERNADE);
}
if (bots[bot_index].bot_weapons & (1 << fa_weapon_flashbang))
{
if (bots[bot_index].grenade_slot == NO_VAL)
bots[bot_index].grenade_slot = fa_weapon_flashbang;
if (bots[bot_index].grenade_time != 0.0)
bots[bot_index].grenade_time = 0.0;
if (bots[bot_index].grenade_action != ALTW_NOTUSED)
bots[bot_index].grenade_action = ALTW_NOTUSED;
if (bots[bot_index].IsSubTask(ST_NOOTHERNADE))
bots[bot_index].RemoveSubTask(ST_NOOTHERNADE);
}
if (bots[bot_index].bot_weapons & (1 << fa_weapon_stg24))
{
if (bots[bot_index].grenade_slot == NO_VAL)
bots[bot_index].grenade_slot = fa_weapon_stg24;
if (bots[bot_index].grenade_time != 0.0)
bots[bot_index].grenade_time = 0.0;
if (bots[bot_index].grenade_action != ALTW_NOTUSED)
bots[bot_index].grenade_action = ALTW_NOTUSED;
if (bots[bot_index].IsSubTask(ST_NOOTHERNADE))
bots[bot_index].RemoveSubTask(ST_NOOTHERNADE);
}
}
/*
* this message gets sent when the bot picks up an item (like a battery
* or a healthkit)
*/
void BotClient_FA_ItemPickup(void *p, int bot_index)
{
// do nothing
}
/*
* this message gets sent when bots health changes
*/
void BotClient_FA_Health(void *p, int bot_index)
{
bots[bot_index].bot_health = *static_cast<int*>(p); // health ammount
}
/*
* this message is sent when bot gets, picks up or uses bandages
*/
void BotClient_FA_Bandages(void *p, int bot_index)
{
bots[bot_index].bot_bandages = *static_cast<int*>(p); // bandages ammount
}
/*
* this message is sent when various events happens
* like picking up a parachute, using a bipod on weapons etc.
* (ie. all that are shown on hud as an icon)
*/
void BotClient_FA_StatusIcon(void *p, int bot_index)
{
static int state = 0; // current state machine state
static char event_type[64];
if (state == 0)
{
state++;
}
else if (state == 1)
{
state++;
strcpy(event_type, static_cast<char*>(p));
}
else if (state == 2)
{
state++;
}
else if (state == 3)
{
state++;
if (*static_cast<int*>(p) == 255)
{
if (strcmp(event_type, "parachute") == 0)
{
bots[bot_index].SetTask(TASK_PARACHUTE); // bot just picked up a parachute
}
else if (strcmp(event_type, "bipod") == 0)
{
bots[bot_index].SetTask(TASK_BIPOD); // bipod used
bots[bot_index].SetBehaviour(BOT_DONTGOPRONE); // bipod prevents changing stance so we can't go prone
#ifdef DEBUG
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ // NEW CODE 094 (remove it)
char dm[256];
sprintf(dm, "(bot_client.cpp) %s got BIPOD DISPLAYED message and SET DONTGOPRONE behaviour!\n", bots[bot_index].name);
//ALERT(at_console, dm);
UTIL_DebugInFile(dm);
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#endif // DEBUG
}
// NOTE: No use for this yet
else if (strcmp(event_type, "dmg_conc") == 0)
{
; // concussion grenade stun
}
}
else if (*static_cast<int*>(p) == 0)
{
// parachute was thrown off so reset variables to allow bot to use another parachute if needed
if (strcmp(event_type, "parachute") == 0)
{
bots[bot_index].RemoveTask(TASK_PARACHUTE);
bots[bot_index].RemoveTask(TASK_PARACHUTE_USED);
bots[bot_index].chute_action_time = 0.0;
}
else if (strcmp(event_type, "bipod") == 0)
{
bots[bot_index].RemoveTask(TASK_BIPOD);
bots[bot_index].RemoveBehaviour(BOT_DONTGOPRONE); // now we are free to go/resume prone again
#ifdef DEBUG
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ // NEW CODE 094 (remove it)
char dm[256];
sprintf(dm, "(bot_client.cpp) %s got BIPOD HIDE message and removed DONTGOPRONE behaviour!\n", bots[bot_index].name);
//ALERT(at_console, dm);
UTIL_DebugInFile(dm);
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#endif // DEBUG
}
else if (strcmp(event_type, "dmg_conc") == 0)
{
;
}
}
}
else if (state == 4)
{
state = 0;
if (*static_cast<int*>(p) == 128)
{
if (strcmp(event_type, "gotitem") == 0)
{
bots[bot_index].SetTask(TASK_GOALITEM); // the bot carries a goal item now
#ifdef _DEBUG
//@@@@@@@@@@@
//ALERT(at_console,"***bot picked up the goal item\n");
#endif
}
}
else if (*static_cast<int*>(p) == 0)
{
if (strcmp(event_type, "gotitem") == 0)
{
bots[bot_index].RemoveTask(TASK_GOALITEM); // the bot got it to goal area
#ifdef _DEBUG
//@@@@@@@@@@@
//ALERT(at_console,"***bot finished the goal item action (captured it)\n");
#endif
}
}
}
}
/*
* BACKWARD COMPATIBILITY code for FA 2.65 and versions below
* this message gets send when the bot has a parachute
* it displays that small parachute icon on the screen
*/
void BotClient_FA_Parachute(void *p, int bot_index)
{
// set this task only if we aren't trying to drop the parachute when back on ground
if (!bots[bot_index].IsNeed(NEED_RESETPARACHUTE))
bots[bot_index].SetTask(TASK_PARACHUTE);
}
/*
* BACKWARD COMPATIBILITY code for FA 2.65 and versions below
* this message is being send all the time
* first two bits are team reinforcements and the 3rd bit is current stamina value
*/
void BotClient_FA_BrokenLeg(void *p, int bot_index)
{
static int state = 0; // current state machine state
if (state == 0)
{
state++;
if (*static_cast<int*>(p) == 0)
{
botmanager.SetOverrideTeamsBalance(true);
}
}
else if (state == 1)
{
state++;
if (*static_cast<int*>(p) == 0)
{
botmanager.SetOverrideTeamsBalance(true);
}
}
else if (state == 2)
{
state = 0;
if (*static_cast<int*>(p) <= 4)
{
bots[bot_index].RemoveTask(TASK_SPRINT); // no sprint is allowed
}
else if (*static_cast<int*>(p) <= 15)
{
bots[bot_index].SetTask(TASK_NOJUMP); // no jump is allowed
}
else if (*static_cast<int*>(p) >= 35)
{
bots[bot_index].RemoveTask(TASK_NOJUMP); // the bot can jump again
}
}
}
/*
* this message gets sent when the bots armor changes
*/
void BotClient_FA_Battery(void *p, int bot_index)
{
bots[bot_index].bot_armor = *static_cast<int*>(p); // armor ammount
}
/*
* this message gets sent when the bots are getting damaged
*/
void BotClient_FA_Damage(void *p, 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;
// ignore all types of damage if the bot is in "I'm ignoring all" mode
if (botdebugger.IsIgnoreAll())
return;
damage_origin.z = *static_cast<float*>(p);
if ((damage_armor > 0) || (damage_taken > 0))
{
// NOTE: In FA 3.0 bleeding seems to have new value (1<<25) so as int value it's 33554432
// I'm not using it, because it doesn't seem to cause any unwanted turn around
// ignore bleeding hurt etc. (ie do not try to face it)
// we won't facing this hurt, because bot does stupid turn arounds
if (damage_bits == 2048) // i.e. (1<<11)
return;
// if bot fall off something and is hurt store new health value
// to prevent false bandage treatment and ignore
if (damage_bits & DMG_FALL)
{
bots[bot_index].bot_prev_health = bots[bot_index].bot_health;
return;
}
// set the drowing flag to know that the bot is drowing
// we have to handle FA2.9 changes
if ((damage_bits & DMG_DROWN) || ((damage_bits & DMG_ALWAYSGIB) &&
((g_mod_version == FA_29) || (g_mod_version == FA_30))))
{
bots[bot_index].SetTask(TASK_DROWNING);
// we also have to handle false bahaviour
// the bot doesn't bleed even if he's losing health and
// the engine is sending bleeding sound
bots[bot_index].RemoveTask(TASK_BLEEDING);
return;
}
// reset the drowing flag to know that the bot is no more drowing
// this works only in FA2.8 and lower versions but not in FA2.9
// FA2.9 doesn't send this bit
if (damage_bits & DMG_DROWNRECOVER)
{
bots[bot_index].RemoveTask(TASK_DROWNING);
return;
}
// ignore certain types of damage
if (damage_bits & IGNORE_DAMAGE)
return;
edict_t *pDmgEnt = bots[bot_index].pEdict->v.dmg_inflictor;
// is the bot being hurt by this trigger then ignore it for now
// prevents the bot to "dance" on such object
//
// NOTE: This should be changed to allow the bot to evade such object
if ((pDmgEnt != nullptr) && (strcmp(STRING(pDmgEnt->v.classname), "trigger_hurt") == 0))
return;
// react only on damage taken from another player's gunfire
// at least for now
if ((pDmgEnt != nullptr) && (strcmp(STRING(pDmgEnt->v.classname), "player") == 0))
{
const int enemy_team = UTIL_GetTeam(bots[bot_index].pEdict->v.dmg_inflictor);
const int bot_team = UTIL_GetTeam(bots[bot_index].pEdict);
// try to warn the teammate who's shooting at you
if ((enemy_team == bot_team) && (RANDOM_LONG(1, 100) <= 35) && // was 25
IsAlive(bots[bot_index].pEdict))
{
bots[bot_index].SetSubTask(ST_SAY_CEASEFIRE);
}
}
float new_enemy_dist;
// get the vector to new enemy
const Vector v_new_enemy = damage_origin - bots[bot_index].pEdict->v.origin;
// get the distance to new enemy
new_enemy_dist = v_new_enemy.Length();
// if the bot already has an enemy
if (bots[bot_index].pBotEnemy)
{
// get the distance for current enemy
const float curr_enemy_dist = (bots[bot_index].pBotEnemy->v.origin -
bots[bot_index].pEdict->v.origin).Length();
// is current enemy closer than the new enemy AND does the bot see him
// then ignore new enemy
if ((curr_enemy_dist < new_enemy_dist) &&
(bots[bot_index].f_bot_wait_for_enemy_time < gpGlobals->time))
return;
// the new enemy must be closer than current enemy so...
// is the bot sniper AND the new enemy is too close keep the current enemy
// (ie. bot isn't able to change to gun that fast so it's better if he try to do
// as many damage to the current enemy as he can)
//if ((bots[bot_index].bot_behaviour & SNIPER) && (enemy_dist < 400)) NEW CODE 094 (prev code)
if ((bots[bot_index].bot_behaviour & SNIPER) && (new_enemy_dist < 200) &&
(bots[bot_index].f_bot_wait_for_enemy_time < gpGlobals->time))
return;
// if the bot has clear view at current enemy AND
// the bot probably already shoot at current enemy than
// in most of the time keep current enemy
if ((bots[bot_index].f_bot_wait_for_enemy_time < gpGlobals->time) &&
(bots[bot_index].pBotEnemy->v.health < 50) && (RANDOM_LONG(1, 100) <= 90))
return;
// the bot decided to target the new enemy so forget the current one
bots[bot_index].BotForgetEnemy();
}
// it's a completely new enemy or the bot switched on this enemy so...
if (bots[bot_index].IsTask(TASK_GOALITEM) && (new_enemy_dist > ENEMY_DIST_GOALITEM))
return;
// face the attacker (ie. the new enemy)
const Vector bot_angles = UTIL_VecToAngles(v_new_enemy);
bots[bot_index].pEdict->v.ideal_yaw = bot_angles.y;
BotFixIdealYaw(bots[bot_index].pEdict);
bots[bot_index].SetSubTask(ST_FACEENEMY);
// we need to know if bot turned more than a few degree to a side
// if so then we have to trace that direction immediatelly to see
// if there's danger of death fall
if (bots[bot_index].IsTask(TASK_DEATHFALL) && (bots[bot_index].f_dontmove_time < gpGlobals->time))
{
bots[bot_index].move_speed = SPEED_NO;
bots[bot_index].SetDontMoveTime(1.0);
//@@@@@@@@@@@@@@@@@@@@@@@@@@@
#ifdef _DEBUG
ALERT(at_console, "BEEN HIT during DEATH FALL danger -->>> STOP\n");
#endif
}
// don't look for waypoint while searching the enemy
bots[bot_index].f_dont_look_for_waypoint_time = gpGlobals->time + 0.4f; // was 0.2
// if not already bandaging then prevent starting it
if (bots[bot_index].bandage_time <= gpGlobals->time) // NEW CODE 094
bots[bot_index].bandage_time = -1.0;
// break wpt_action_time
bots[bot_index].wpt_action_time = 0.0;
}
}
}
/*
* this message gets sent when the bots get killed
*/
void BotClient_FA_DeathMsg(void *p, int bot_index)
{
/* NOT USED YET
static int state = 0; // current state machine state
static int killer_index;
static int victim_index;
static edict_t *victim_edict;
static int index;
if (state == 0)
{
state++;
killer_index = *(int *)p; // ENTINDEX() of killer
}
else if (state == 1)
{
state++;
victim_index = *(int *)p; // ENTINDEX() of victim
}
else if (state == 2)
{
state = 0;
victim_edict = INDEXENT(victim_index);
index = UTIL_GetBotIndex(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 = NULL;
}
else
{
// store edict of player that killed this bot
bots[index].killer_edict = INDEXENT(killer_index);
}
}
}
*/
}
/*
* this message gets send when any text is printed on the client's screen
* like changing to gl attachment and back or player's promotion to Sergeant etc.
*/
void BotClient_FA_TextMsg(void *p, int bot_index)
{
static int state = 0; // current state machine state
if (state == 0)
state++;
else if (state == 1)
{
state = 0;
char the_text[256];
// get the message and its length engine sends
strcpy(the_text, static_cast<char*>(p));
int pos = strlen(the_text);
// remove '\n' sign from its end
the_text[pos - 1] = 0;
pos--;
// prevents going prone for some time
if ((strcmp(the_text, "Not enough room to go prone here!") == 0) ||
(strcmp(the_text, "Cannot prone on another player!") == 0))
{
#ifdef DEBUG
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ // NEW CODE 094 (remove it)
char dm[256];
sprintf(dm, "(bot_client.cpp) %s CANNOT PRONE message -> SET CANTPRONE subtask!\n", bots[bot_index].name);
//ALERT(at_console, dm);
UTIL_DebugInFile(dm);
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#endif // DEBUG
bots[bot_index].SetSubTask(ST_CANTPRONE);
}
// switches to secondary fire for m16
else if (strcmp(the_text, "Switched to M203 fire") == 0)
{
bots[bot_index].secondary_active = TRUE;
#ifdef DEBUG
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ // NEW CODE 094 (remove it)
char dm[256];
sprintf(dm, "(bot_client.cpp) %s got SWITCHED TO M203 message!\n", bots[bot_index].name);
ALERT(at_console, dm);
UTIL_DebugInFile(dm);
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#endif // DEBUG
}
// switches back to primary fire for m16
else if (strcmp(the_text, "Switched to M16 fire") == 0)
{
bots[bot_index].secondary_active = FALSE;
#ifdef DEBUG
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ // NEW CODE 094 (remove it)
char dm[256];
sprintf(dm, "(bot_client.cpp) %s got SWITCHED TO M16 FIRE message!\n", bots[bot_index].name);
ALERT(at_console, dm);
UTIL_DebugInFile(dm);
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#endif // DEBUG
}
// switches to secondary fire for ak74
else if (strcmp(the_text, "Switched to gp25 fire") == 0)
{
bots[bot_index].secondary_active = TRUE;
#ifdef DEBUG
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ // NEW CODE 094 (remove it)
char dm[256];
sprintf(dm, "(bot_client.cpp) %s got SWITCHED TO GP25 message!\n", bots[bot_index].name);
ALERT(at_console, dm);
UTIL_DebugInFile(dm);
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#endif // DEBUG
}
// switches back to primary fire for ak74
else if (strcmp(the_text, "Switched to normal fire") == 0)
{
bots[bot_index].secondary_active = FALSE;
#ifdef DEBUG