-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot_combat.cpp
5141 lines (4370 loc) · 152 KB
/
bot_combat.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_combat.cpp
//
////////////////////////////////////////////////////////////////////////////////////////////////
#if defined(WIN32)
#pragma warning(disable: 4005 91 4477)
#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_weapons.h"
extern bot_weapon_t weapon_defs[MAX_WEAPONS];
float rg_modif = 2.5; // multiplier that modifies all effective ranges for game purpose
// better bot = longer delay between two sprints towards enemy (i.e. better bots hold their positions more often)
float g_combat_advance_delay[BOT_SKILL_LEVELS] = { 7.0, 5.5, 4.0, 2.5, 1.0 };
#ifdef _DEBUG
bool in_bot_dev_level1 = FALSE; // if TRUE print basic info at_console
bool in_bot_dev_level2 = FALSE; // detailed info - print every action
#endif
// BotFireWeapon(), BotUseKnife() and BotThrowGrenade() return constants
#define RETURN_NOTFIRED 0
#define RETURN_FIRED 1
#define RETURN_RELOADING 2
#define RETURN_NOAMMO 3
#define RETURN_TOOCLOSE 4
#define RETURN_TOOFAR 5
#define RETURN_SECONDARY 6
#define RETURN_TAKING 7
#define RETURN_PRIMING 8
// we need these variables to handle different weapon IDs in FA versions
int default_ID = 0;
int fa_weapon_knife = default_ID;
int fa_weapon_coltgov = default_ID;
int fa_weapon_ber92f = default_ID;
int fa_weapon_ber93r = default_ID;
int fa_weapon_anaconda = default_ID;
int fa_weapon_desert = default_ID;
int fa_weapon_benelli = default_ID; // remington in FA28 and above
int fa_weapon_saiga = default_ID;
int fa_weapon_mp5k = default_ID; // FA24 weapon
int fa_weapon_mp5a5 = default_ID;
int fa_weapon_mc51 = default_ID; // FA25 weapon
int fa_weapon_m11 = default_ID; // FA25 weapon
int fa_weapon_bizon = default_ID;
int fa_weapon_sterling = default_ID;
int fa_weapon_uzi = default_ID;
int fa_weapon_m79 = default_ID;
int fa_weapon_frag = default_ID;
int fa_weapon_concussion = default_ID;
int fa_weapon_flashbang = default_ID;
int fa_weapon_stg24 = default_ID; // stielhandgranate
int fa_weapon_claymore = default_ID;
int fa_weapon_ak47 = default_ID;
int fa_weapon_famas = default_ID;
int fa_weapon_g3a3 = default_ID;
int fa_weapon_g36e = default_ID;
int fa_weapon_m16 = default_ID;
int fa_weapon_ak74 = default_ID;
int fa_weapon_m14 = default_ID;
int fa_weapon_m4 = default_ID;
int fa_weapon_aug = default_ID; // FA25 weapon
int fa_weapon_psg1 = default_ID; // FA25 weapon
int fa_weapon_ssg3000 = default_ID;
int fa_weapon_m82 = default_ID;
int fa_weapon_svd = default_ID;
int fa_weapon_m60 = default_ID;
int fa_weapon_m249 = default_ID;
int fa_weapon_pkm = default_ID;
// bot_combat functions prototypes
bool InitFABaseWeapons();
bool InitFASameWeapons();
bool InitFA24Weapons();
bool InitFA25Weapons();
bool InitFA26Weapons();
bool InitFA27Weapons();
bool InitFA28Weapons();
bool InitFA29Weapons();
void BotReactions(bot_t *pBot);
inline void DontSeeEnemyActions(bot_t *pBot);
void BotFireMountedGun(const Vector& v_enemy, bot_t *pBot);
int BotFireWeapon(const Vector& v_enemy, bot_t *pBot);
int BotUseKnife(const Vector& v_enemy, bot_t *pBot);
int BotThrowGrenade(const Vector& v_enemy, bot_t *pBot);
bool CanUseBackupInsteadofReload(bot_t *pBot, float enemy_distance = 0.0);
inline void IsChanceToAdvance(bot_t *pBot);
inline void CheckStance(bot_t *pBot, float enemy_distance);
bool IsEnemyTooClose(bot_t *pBot, float enemy_distance);
/*
* inits a few weapons that have same ID in all FA versions
*/
bool InitFABaseWeapons()
{
fa_weapon_knife = FAB_WEAPON_KNIFE;
fa_weapon_coltgov = FAB_WEAPON_COLTGOV;
fa_weapon_ber92f = FAB_WEAPON_BER92F;
fa_weapon_ber93r = FAB_WEAPON_BER93R;
fa_weapon_anaconda = FAB_WEAPON_ANACONDA;
fa_weapon_desert = FAB_WEAPON_DESERT;
fa_weapon_benelli = FAB_WEAPON_BENELLI;
fa_weapon_saiga = FAB_WEAPON_SAIGA;
// test if all weapons were successfully initialized
if ((fa_weapon_knife == default_ID) || (fa_weapon_coltgov == default_ID) ||
(fa_weapon_ber92f == default_ID) || (fa_weapon_ber93r == default_ID) ||
(fa_weapon_anaconda == default_ID || (fa_weapon_desert == default_ID) ||
(fa_weapon_benelli == default_ID) || (fa_weapon_saiga == default_ID)))
{
return FALSE;
}
return TRUE;
}
/*
* inits a few weapons that have same ID in more than one version
*/
bool InitFASameWeapons()
{
fa_weapon_mp5a5 = FA25_WEAPON_MP5A5;
fa_weapon_m79 = FA25_WEAPON_M79;
fa_weapon_frag = FA25_WEAPON_FRAG;
fa_weapon_claymore = FA25_WEAPON_CLAYMORE;
fa_weapon_stg24 = FA25_WEAPON_STG24;
fa_weapon_ak47 = FA25_WEAPON_AK47;
fa_weapon_famas = FA25_WEAPON_FAMAS;
fa_weapon_g3a3 = FA25_WEAPON_G3A3;
fa_weapon_g36e = FA25_WEAPON_G36E;
fa_weapon_m16 = FA25_WEAPON_M16;
fa_weapon_m82 = FA25_WEAPON_M82;
fa_weapon_m60 = FA25_WEAPON_M60;
fa_weapon_bizon = FA25_WEAPON_BIZON;
fa_weapon_sterling = FA25_WEAPON_STERLING;
if ((fa_weapon_mp5a5 == default_ID) || (fa_weapon_m79 == default_ID) ||
(fa_weapon_frag == default_ID) || (fa_weapon_claymore == default_ID) ||
(fa_weapon_stg24 == default_ID) || (fa_weapon_ak47 == default_ID) ||
(fa_weapon_famas == default_ID) || (fa_weapon_g3a3 == default_ID) ||
(fa_weapon_g36e == default_ID) || (fa_weapon_m16 == default_ID) ||
(fa_weapon_m82 == default_ID) || (fa_weapon_m60 == default_ID) ||
(fa_weapon_bizon == default_ID) || (fa_weapon_sterling == default_ID))
{
return FALSE;
}
return TRUE;
}
/*
* inits all FA24 versions, we can't use the same weapons init method because of sterling
*/
bool InitFA24Weapons()
{
fa_weapon_mp5k = FA24_WEAPON_MP5K;
fa_weapon_mp5a5 = FA25_WEAPON_MP5A5;
fa_weapon_mc51 = FA25_WEAPON_MC51;
fa_weapon_m11 = FA25_WEAPON_M11;
fa_weapon_m79 = FA25_WEAPON_M79;
fa_weapon_frag = FA25_WEAPON_FRAG;
fa_weapon_flashbang = FA25_WEAPON_FLASHBANG;
fa_weapon_claymore = FA25_WEAPON_CLAYMORE;
fa_weapon_stg24 = FA25_WEAPON_STG24;
fa_weapon_ak47 = FA25_WEAPON_AK47;
fa_weapon_famas = FA25_WEAPON_FAMAS;
fa_weapon_psg1 = FA25_WEAPON_PSG1;
fa_weapon_g3a3 = FA25_WEAPON_G3A3;
fa_weapon_g36e = FA25_WEAPON_G36E;
fa_weapon_m16 = FA25_WEAPON_M16;
fa_weapon_aug = FA25_WEAPON_AUG;
fa_weapon_m82 = FA25_WEAPON_M82;
fa_weapon_m4 = FA25_WEAPON_M4;
fa_weapon_m60 = FA25_WEAPON_M60;
fa_weapon_bizon = FA25_WEAPON_BIZON;
if ((fa_weapon_mp5k == default_ID) || (fa_weapon_mp5a5 == default_ID) ||
(fa_weapon_mc51 == default_ID) || (fa_weapon_m11 == default_ID) ||
(fa_weapon_m79 == default_ID) || (fa_weapon_frag == default_ID) ||
(fa_weapon_flashbang == default_ID) || (fa_weapon_claymore == default_ID) ||
(fa_weapon_stg24 == default_ID) || (fa_weapon_ak47 == default_ID) ||
(fa_weapon_famas == default_ID) || (fa_weapon_psg1 == default_ID) ||
(fa_weapon_g3a3 == default_ID) || (fa_weapon_g36e == default_ID) ||
(fa_weapon_m16 == default_ID) || (fa_weapon_aug == default_ID) ||
(fa_weapon_m82 == default_ID) || (fa_weapon_m4 == default_ID) ||
(fa_weapon_m60 == default_ID) || (fa_weapon_bizon == default_ID))
{
return FALSE;
}
return TRUE;
}
/*
* inits all FA25 versions
*/
bool InitFA25Weapons()
{
bool prev_inits = FALSE;
// we are using special initinalization for some weapons
// because their IDs are same in more versions
if (InitFASameWeapons())
prev_inits = TRUE;
fa_weapon_mc51 = FA25_WEAPON_MC51;
fa_weapon_m11 = FA25_WEAPON_M11;
fa_weapon_flashbang = FA25_WEAPON_FLASHBANG;
fa_weapon_psg1 = FA25_WEAPON_PSG1;
fa_weapon_aug = FA25_WEAPON_AUG;
fa_weapon_m4 = FA25_WEAPON_M4;
if ((prev_inits == FALSE) || (fa_weapon_mc51 == default_ID) ||
(fa_weapon_m11 == default_ID) || (fa_weapon_flashbang == default_ID) ||
(fa_weapon_psg1 == default_ID) || (fa_weapon_aug == default_ID) ||
(fa_weapon_m4 == default_ID))
{
return FALSE;
}
return TRUE;
}
/*
* inits all FA26 (2.65 as well) versions
*/
bool InitFA26Weapons()
{
bool prev_inits = FALSE;
// we are using special initinalization for some weapons
// because their IDs are same in more versions
if (InitFASameWeapons())
prev_inits = TRUE;
fa_weapon_svd = FA26_WEAPON_SVD;
fa_weapon_uzi = FA26_WEAPON_UZI;
fa_weapon_concussion = FA26_WEAPON_CONCUSSION;
fa_weapon_ssg3000 = FA26_WEAPON_SSG3000;
fa_weapon_ak74 = FA26_WEAPON_AK74;
fa_weapon_pkm = FA26_WEAPON_PKM;
if ((prev_inits == FALSE) || (fa_weapon_svd == default_ID) || (fa_weapon_uzi == default_ID) ||
(fa_weapon_concussion == default_ID) || (fa_weapon_ssg3000 == default_ID) ||
(fa_weapon_ak74 == default_ID) || (fa_weapon_pkm == default_ID))
{
return FALSE;
}
return TRUE;
}
/*
* inits all FA27 versions
*/
bool InitFA27Weapons()
{
bool prev_inits = FALSE;
// we are using special initinalization for some weapons
// because their IDs are same in more versions
if (InitFASameWeapons())
prev_inits = TRUE;
fa_weapon_svd = FA26_WEAPON_SVD;
fa_weapon_uzi = FA26_WEAPON_UZI;
fa_weapon_concussion = FA26_WEAPON_CONCUSSION;
fa_weapon_ssg3000 = FA26_WEAPON_SSG3000;
fa_weapon_ak74 = FA26_WEAPON_AK74;
fa_weapon_m249 = FA26_WEAPON_PKM; // the ID is same just different name
if ((prev_inits == FALSE) || (fa_weapon_svd == default_ID) || (fa_weapon_uzi == default_ID) ||
(fa_weapon_concussion == default_ID) || (fa_weapon_ssg3000 == default_ID) ||
(fa_weapon_ak74 == default_ID) || (fa_weapon_m249 == default_ID))
{
return FALSE;
}
return TRUE;
}
/*
* inits all FA28 versions
*/
bool InitFA28Weapons()
{
fa_weapon_mp5a5 = FA28_WEAPON_MP5A5;
fa_weapon_bizon = FA28_WEAPON_BIZON;
fa_weapon_sterling = FA28_WEAPON_STERLING;
fa_weapon_m79 = FA28_WEAPON_M79;
fa_weapon_frag = FA28_WEAPON_FRAG;
fa_weapon_concussion = FA28_WEAPON_CONCUSSION;
fa_weapon_claymore = FA28_WEAPON_CLAYMORE;
fa_weapon_ak47 = FA28_WEAPON_AK47;
fa_weapon_famas = FA28_WEAPON_FAMAS;
fa_weapon_g3a3 = FA28_WEAPON_G3A3;
fa_weapon_g36e = FA28_WEAPON_G36E;
fa_weapon_m16 = FA28_WEAPON_M16;
fa_weapon_ssg3000 = FA28_WEAPON_SSG3000;
fa_weapon_m82 = FA28_WEAPON_M82;
fa_weapon_ak74 = FA28_WEAPON_AK74;
fa_weapon_m60 = FA28_WEAPON_M60;
fa_weapon_m249 = FA28_WEAPON_M249;
fa_weapon_uzi = FA28_WEAPON_UZI;
fa_weapon_svd = FA28_WEAPON_SVD;
fa_weapon_pkm = FA28_WEAPON_PKM;
if ((fa_weapon_mp5a5 == default_ID) || (fa_weapon_bizon == default_ID) ||
(fa_weapon_sterling == default_ID) || (fa_weapon_m79 == default_ID) ||
(fa_weapon_frag == default_ID) || (fa_weapon_concussion == default_ID) ||
(fa_weapon_claymore == default_ID) || (fa_weapon_ak47 == default_ID) ||
(fa_weapon_famas == default_ID) || (fa_weapon_g3a3 == default_ID) ||
(fa_weapon_g36e == default_ID) || (fa_weapon_m16 == default_ID) ||
(fa_weapon_ssg3000 == default_ID) || (fa_weapon_m82 == default_ID) ||
(fa_weapon_ak74 == default_ID) || (fa_weapon_m60 == default_ID) ||
(fa_weapon_m249 == default_ID) || (fa_weapon_uzi == default_ID) ||
(fa_weapon_svd == default_ID) || (fa_weapon_pkm == default_ID))
{
return FALSE;
}
return TRUE;
}
/*
* inits all FA29 versions
*/
bool InitFA29Weapons()
{
bool prev_inits = FALSE;
// we can use previous version initinalization because weapon IDs are same
if (InitFA28Weapons())
prev_inits = TRUE;
fa_weapon_m14 = FA29_WEAPON_M14;
fa_weapon_m4 = FA29_WEAPON_M4;
if ((prev_inits == FALSE) || (fa_weapon_m14 == default_ID) || (fa_weapon_m4 == default_ID))
return FALSE;
return TRUE;
}
/*
* inits the right weapon set based on mod version
*/
bool InitFAWeapons()
{
bool a_problem = FALSE;
// these weapon have their IDs same in all version se we can call them here
if (InitFABaseWeapons() == FALSE)
a_problem = TRUE;
if (g_mod_version == FA_24)
{
if (InitFA24Weapons())
ALERT(at_console, "MarineBot firearms 2.4 weapon detection done\n");
else
{
a_problem = TRUE;
ALERT(at_console, "MarineBot cannot detect firearms 2.4 weapons!\n");
}
}
else if (g_mod_version == FA_25)
{
if (InitFA25Weapons())
ALERT(at_console, "MarineBot firearms 2.5 weapon detection done\n");
else
{
a_problem = TRUE;
ALERT(at_console, "MarineBot cannot detect firearms 2.5 weapons!\n");
}
}
else if (g_mod_version == FA_26)
{
if (InitFA26Weapons())
ALERT(at_console, "MarineBot firearms 2.6 (2.65) weapon detection done\n");
else
{
a_problem = TRUE;
ALERT(at_console, "MarineBot cannot detect firearms 2.6 (2.65) weapons!\n");
}
}
else if (g_mod_version == FA_27)
{
if (InitFA27Weapons())
ALERT(at_console, "MarineBot firearms 2.7 weapon detection done\n");
else
{
a_problem = TRUE;
ALERT(at_console, "MarineBot cannot detect firearms 2.7 weapons!\n");
}
}
else if (g_mod_version == FA_28)
{
if (InitFA28Weapons())
ALERT(at_console, "MarineBot firearms 2.8 weapon detection done\n");
else
{
a_problem = TRUE;
ALERT(at_console, "MarineBot cannot detect firearms 2.8 weapons!\n");
}
}
else if (g_mod_version == FA_29)
{
if (InitFA29Weapons())
ALERT(at_console, "MarineBot firearms 2.9 weapon detection done\n");
else
{
a_problem = TRUE;
ALERT(at_console, "MarineBot cannot detect firearms 2.9 weapons!\n");
}
}
else if (g_mod_version == FA_30)
{
if (InitFA29Weapons())
ALERT(at_console, "MarineBot firearms 3.0 weapon detection done\n");
else
{
a_problem = TRUE;
ALERT(at_console, "MarineBot cannot detect firearms 3.0 weapons!\n");
}
}
// there was some problem during initialization so return error
if (a_problem)
return FALSE;
return TRUE;
}
/*
* inits both weapon stucts (select as well as delay)
* weapons are stored based on their ID
*/
void BotWeaponArraysInit(Section *conf_weapons)
{
int index, i;
char weapon_num[16];
bool modif=true;
char msg[1024];
if (conf_weapons == nullptr) //init all weapons to 0
{
for (index = 0; index < MAX_WEAPONS; ++index)
{
bot_weapon_select[index].iId = index;
bot_weapon_select[index].max_effective_distance = 0.0;
bot_weapon_select[index].min_safe_distance = 0.0;
bot_fire_delay[index].primary_base_delay = 0.0;
for (i=0; i<BOT_SKILL_LEVELS; ++i)
{
bot_fire_delay[index].primary_min_delay[i] = 0.0;
bot_fire_delay[index].primary_max_delay[i] = 0.0;
}
}
ALERT(at_console, "MarineBot firearms weapons initialisation WASN'T done\n");
return;
}
else {
for (index = 0; index < MAX_WEAPONS; ++index)
{
bot_weapon_select[index].iId = index;
bot_fire_delay[index].iId = index;
sprintf(weapon_num, "%d",index);
CSI si = conf_weapons->sectionList.find(weapon_num);
if (si==conf_weapons->sectionList.end()) {
bot_weapon_select[index].max_effective_distance = 0.0;
bot_weapon_select[index].min_safe_distance = 0.0;
}
else {
SetupVars set_vars;
set_vars.Add("modif", new SetupBaseType_yesno(modif), false, "no");
set_vars.Add("min_safe_distance", new SetupBaseType_float(bot_weapon_select[index].min_safe_distance), false, "0.0");
set_vars.Add("max_effective_distance", new SetupBaseType_float(bot_weapon_select[index].max_effective_distance), false, "9999.0");
set_vars.Add("primary_base_delay", new SetupBaseType_float(bot_fire_delay[index].primary_base_delay), false, "0.0");
try
{
set_vars.Set(si->second);
}
catch (errGetVal &er_val)
{
sprintf(msg, "** missing variable '%s'", er_val.key.c_str());
PrintOutput(nullptr, msg, MType::msg_error);
}
if (modif==true)
{
bot_weapon_select[index].max_effective_distance *= rg_modif;
}
for (i=0; i<BOT_SKILL_LEVELS; ++i)
{
bot_fire_delay[index].primary_min_delay[i] = 0.0f;
bot_fire_delay[index].primary_max_delay[i] = 0.0f;
}
CII ii;
CSI delay_si = si->second->sectionList.find("primary_min_delay");
if (delay_si != si->second->sectionList.end()) //found
{
for(i=0,ii=delay_si->second->item.begin(); ii!=delay_si->second->item.end() && i<BOT_SKILL_LEVELS; ++ii,++i)
{
bot_fire_delay[index].primary_min_delay[i] = atof(ii->second.c_str());
}
}
delay_si = si->second->sectionList.find("primary_max_delay");
if (delay_si != si->second->sectionList.end()) //found
{
for(i=0,ii=delay_si->second->item.begin(); ii!=delay_si->second->item.end() && i<BOT_SKILL_LEVELS; ++ii,++i)
{
bot_fire_delay[index].primary_max_delay[i] = atof(ii->second.c_str());
}
}
}
}
}
ALERT(at_console, "MarineBot firearms weapons initialisation done\n");
}
/*
* checks the amount of magazines for main weapon
* and sets out of ammo if there are no magazines left
* and the weapon clip is also empty
*/
bool bot_t::CheckMainWeaponOutOfAmmo(const char* loc)
{
if ((current_weapon.iClip == 0) && (current_weapon.iAmmo1 == 0) && (main_no_ammo == false) &&
(weapon_action == W_READY) && (current_weapon.iId == main_weapon))
{
main_no_ammo = true;
#ifdef DEBUG
if (loc != NULL)
{
char dbgmsg[256];
sprintf(dbgmsg, "MainWeaponOutOfAmmo() called @ %s)\n", loc);
HudNotify(dbgmsg, this);
}
#else
if (botdebugger.IsDebugActions())
HudNotify("MAIN weapon completely out of ammo (no magazines)\n", this);
#endif // DEBUG
}
return main_no_ammo;
}
/*
* checks the amount of magazines for backup weapon
* and sets out of ammo if there are no magazines left
* and the weapon clip is also empty
*/
bool bot_t::CheckBackupWeaponOutOfAmmo(const char* loc)
{
if ((current_weapon.iClip == 0) && (current_weapon.iAmmo1 == 0) && (backup_no_ammo == false) &&
(weapon_action == W_READY) && (current_weapon.iId == backup_weapon))
{
backup_no_ammo = true;
#ifdef DEBUG
if (loc != NULL)
{
char dbgmsg[256];
sprintf(dbgmsg, "BackupWeaponOutOfAmmo() called @ %s)\n", loc);
HudNotify(dbgmsg, this);
}
#else
if (botdebugger.IsDebugActions())
HudNotify("BACKUP weapon completely out of ammo (no magazines)\n", this);
#endif // DEBUG
}
return backup_no_ammo;
}
/*
* returns the max effective range of given weapon
* it takes the current weapon by default
*/
float bot_t::GetEffectiveRange(int weapon_index) const
{
// NEW CODE 094
if (weapon_index == NO_VAL)
{
// always try main weapon first
// the bot may have backup weapon in hands at the moment, but can still switch back to main (unless it's empty)
if ((main_weapon != NO_VAL) && !main_no_ammo)
weapon_index = main_weapon;
else
// if the bot has no main weapon or is out of ammo for it then take the current one
weapon_index = current_weapon.iId;
}
// if there's no weapon at all return zero ... just for sure
if (weapon_index == NO_VAL)
return 0.0;
float range = bot_weapon_select[weapon_index].max_effective_distance;
// see if we do limit the max distance the bot can see (ie. view distance)
// if so and the weapon effective range is bigger then the limit
// we will use the view distance limit instead
if (internals.IsEnemyDistanceLimit() && (range > internals.GetEnemyDistanceLimit()))
range = internals.GetEnemyDistanceLimit();
return range;
/*/// NEW CODE 094 (prev code)
// if the bot has no main weapon than take the current one
if (weapon_index == -1)
weapon_index = current_weapon.iId;
// if there's no weapon at all return zero ... just for sure
if (weapon_index == -1)
return 0.0;
float range;
range = bot_weapon_select[weapon_index].max_effective_distance;
// see if we do limit the max distance the bot can see (ie. view distance)
// if so and the weapon effective range is bigger then the limit
// we will use the view distance limit instead
if (internals.IsDistLimit() && (range > internals.GetMaxDistance()))
range = internals.GetMaxDistance();
return range;
/**/
}
/*
* checks if is team play on
*/
void BotCheckTeamplay()
{
// is this mod Firearms?
if (mod_id == FIREARMS_DLL)
internals.SetTeamPlay(1.0);
else
internals.SetTeamPlay(CVAR_GET_FLOAT("mp_teamplay")); // teamplay enabled?
internals.SetTeamPlayChecked(true);
}
/*
* sets correct reaction delay based on bot skill level
* eg. if reaction time is set to 1s then the best bot will use 0.5s as his reaction time
*/
void BotReactions(bot_t *pBot)
{
// we shouldn't set reaction too often it could cause loop
if (pBot->f_reaction_time + 2.0 > gpGlobals->time)
return;
if (pBot->pBotEnemy)
{
Vector vEnemyHead = pBot->pBotEnemy->v.origin + pBot->pBotEnemy->v.view_ofs;
Vector vEnemyBody = pBot->pBotEnemy->v.origin;
// is the enemy right in front of the bot
// (ie. the bot don't have to turn to side to face it)?
if (FInNarrowViewCone(&vEnemyHead, pBot->pEdict, 0.85) ||
FInNarrowViewCone(&vEnemyBody, pBot->pEdict, 0.85))
{
// the bot will fire/attack in next frame
// (ie. will skip this frame just to simulate some "aiming")
pBot->f_reaction_time = gpGlobals->time;
return;
}
}
float react_time = externals.GetReactionTime();
const int skill = pBot->bot_skill + 1; // array based
// we are using skill level 3 as a default level so its reaction time isn't changed
// but other skill levels should be modified
switch (skill)
{
case 1:
react_time -= externals.GetReactionTime() / 2.0f; // use only 50% of it
break;
case 2:
react_time -= externals.GetReactionTime() / 3.0f; // use only 66% of it
break;
case 4:
react_time += externals.GetReactionTime() / 2.0f; // use 150% of it
break;
case 5:
react_time += externals.GetReactionTime(); // use 200% or it
break;
default:
break;
}
// if we get under zero reset it back to zero value
// shouldn't happen but just in case
if (react_time < 0.0f)
react_time = 0.0f;
// store the reaction time
pBot->f_reaction_time = gpGlobals->time + react_time;
}
/*
* bot does these actions when do not have enemy at all or
* when do not currently see him (ie lost clear view)
*/
inline void DontSeeEnemyActions(bot_t *pBot)
{
edict_t *pEdict = pBot->pEdict;
// is there NO enemy for a while AND NOT doing any weapon beased action ...
if ((pBot->bandage_time == -1.0) && pBot->NotSeenEnemyfor(0.5) && (pBot->weapon_action == W_READY))
{
// then bot is allowed to use bandages again
pBot->bandage_time = gpGlobals->time;
#ifdef _DEBUG
if (botdebugger.IsDebugActions())
{
HudNotify("bot_combat.cpp|DontSeeEnemy Actions() -> bandaging ALLOWED again\n", pBot);
}
#endif
}
// if the bot doesn't use main weapon and can use it then try to switch back to it
pBot->BotSelectMainWeapon("DontSeeEnemy Actions() -> time to switch back to MAIN WEAPON");
// bot is waiting if the enemy become visible again AND current weapon is ready AND not going to/resume from prone
if ((pBot->f_bot_wait_for_enemy_time > gpGlobals->time) && (pBot->weapon_action == W_READY) && !pBot->IsGoingProne())
{
// PREVIOUS CODE
/*/
// is the bot holding partly loaded m3/remington AND have ammo AND can manipulate with gun AND
// not doing any waypoint action AND is some time bot seen an enemy OR is bot waiting for enemy
if ((pBot->current_weapon.iId == fa_weapon_benelli) && (pBot->current_weapon.iClip < 8) &&
(pBot->current_weapon.iAmmo1 != 0))
{
pBot->ReloadWeapon("bot_combat.cpp|DontSeeEnemy Actions() -> remington-benelli clip < 8");
}
// is the bot holding colt with less than half rounds in it AND have ammo AND
// is some time bot seen an enemy OR is bot waiting for enemy
else if ((pBot->current_weapon.iId == fa_weapon_anaconda) && (pBot->current_weapon.iClip < 3) &&
(pBot->current_weapon.iAmmo1 != 0))
{
pBot->ReloadWeapon("bot_combat.cpp|DontSeeEnemy Actions() -> anaconda clip < 3");
}
// is clip empty AND have at least one magazine AND
// is some time bot seen an enemy so reload
else if ((pBot->current_weapon.iClip == 0) && (pBot->current_weapon.iAmmo1 != 0))
{
pBot->ReloadWeapon("bot_combat.cpp|DontSeeEnemy Actions() -> weapon clip is empty");
}
/**/
if (UTIL_ShouldReload(pBot, "bot_combat.cpp|DontSeeEnemy Actions()"))
pBot->ReloadWeapon("bot_combat.cpp|DontSeeEnemy Actions()");
}
// did the bot lost his enemy while switched to GL attachement on m16 or ak74
if (pBot->secondary_active && pBot->NotSeenEnemyfor(1.5) && (pBot->weapon_action == W_READY) &&
(pBot->f_bot_wait_for_enemy_time < gpGlobals->time) && (pBot->f_pause_time < gpGlobals->time) &&
((pBot->current_weapon.iId == fa_weapon_m16) || (pBot->current_weapon.iId == fa_weapon_ak74)))
{
// then switch back to normal fire mode
pBot->pEdict->v.button |= IN_ATTACK2;
pBot->SetPauseTime(1.0);
#ifdef DEBUG
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ NEW CODE 094 (remove it)
if (botdebugger.IsDebugActions())
HudNotify("Lost enemy while m203/gp25 ready -> switching back to normal fire mode on m16/ak74\n", pBot);
#endif // DEBUG
}
// didn't the bot seen ememy in last few seconds AND
// is chance to speak (time to area clear)?
if (!externals.GetDontSpeak() && pBot->NotSeenEnemyfor(8.0f) &&
((pBot->speak_time + RANDOM_FLOAT(25.5f, 40.0f)) < gpGlobals->time) && (RANDOM_LONG(1, 100) <= 1))
{
UTIL_Radio(pEdict, "clear");
pBot->speak_time = gpGlobals->time;
}
// remove ignore enemy task if the bot is not by/on the "crucial" waypoint/path
if (pBot->IsTask(TASK_IGNORE_ENEMY) && (pBot->crowded_wpt_index == -1) && !pBot->IsIgnorePath())
{
pBot->RemoveTask(TASK_IGNORE_ENEMY);
#ifdef _DEBUG
if (botdebugger.IsDebugActions())
{
HudNotify("bot_combat.cpp|DontSeeEnemy Actions() -> Removed IGNORE ENEMY flag\n", pBot);
}
#endif
}
}
/*
* will make sure the bot "forgets" about his current enemy (ie. clear all important variables)
*/
void bot_t::BotForgetEnemy()
{
#ifdef _DEBUG
extern edict_t* g_debug_bot;
extern bool g_debug_bot_on;
// can't use hudnotify() here, because it can crash hl engine if the bot gets hit
// then the code in botclient.cpp -> fa dmg message can call this method
// (clientprint in hudnotify() starts new engine msg before the fa_dmg one was finished and hl crashes)
if (g_debug_bot_on && (g_debug_bot == pEdict) || !g_debug_bot_on)
{
char femsg[128];
sprintf(femsg, "%s called ForgetEnemy()\n", name);
ALERT(at_console, femsg);
// so if there is a need to log things in file we have to do it manually right here
UTIL_DebugInFile(femsg);
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// @@@@@@@@@@@@ ^^^^ (uncomment logging in file if it is needed for tests) ^^^^ NEW CODE 094
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}
#endif
// don't have an enemy anymore so null out the pointer
pBotEnemy = nullptr;
// clear his backed up position
v_last_enemy_position = g_vecZero;//Vector(0, 0, 0);
// reset wait & watch time
f_bot_wait_for_enemy_time = gpGlobals->time - 0.1f;
// if the bot is doing any weapon action like reloading for example we can't clear these two, because
// bot can start one of these in the next frame and weapon action would be invalidated
// (e.g. bot would end up with empty weapon)
//if (weapon_action == W_READY) // NEW CODE 094
//{
// reset prone prevention time
//f_cant_prone = gpGlobals->time - 0.1; NEW CODE 094
// no enemy so bot is clear to use bandages <<< BUGS THINGS
//bandage_time = gpGlobals->time;
//}
// reset enemy distance backup
f_prev_enemy_dist = 0.0;
// clear medical treatment flag
RemoveTask(TASK_HEALHIM);
// clear heavy tracelining
RemoveTask(TASK_DEATHFALL);
// bot most probably fired couple rounds at this enemy so let him check his weapon clip
SetSubTask(ST_W_CLIP);
// allow the bot to try deploying bipod later on when he finds new enemy
RemoveWeaponStatus(WS_CANTBIPOD);
#ifdef _DEBUG
curr_aim_offset = g_vecZero;//Vector(0, 0, 0);
target_aim_offset = g_vecZero;//Vector(0, 0, 0);
#endif
}
/*
* search the world for best enemy
* checks if enemy is still alive and visible and sets right behaviour based on it
*/
edict_t * bot_t::BotFindEnemy()
{
Vector vecEnd;
edict_t *pPrevEnemy = nullptr; // previous enemy
float nearest_distance;
// does the bot already have an enemy?
if (pBotEnemy != nullptr)
{
vecEnd = pBotEnemy->v.origin + pBotEnemy->v.view_ofs;
// the bot is going to medevac downed teammate so don't look for new enemy
if (IsTask(TASK_HEALHIM) && IsTask(TASK_MEDEVAC))
{
return (pBotEnemy);
}
// the enemy is already dead
// the enemy probably died during previous frame, assume bot or someone else killed it
else if (IsAlive(pBotEnemy) == FALSE)
{
BotForgetEnemy();
// is still snipe time
if (sniping_time > gpGlobals->time)
{
// break snipe time only if bot is NOT using bipod AND is chance
if ((UTIL_IsMachinegun(current_weapon.iId)) && !IsTask(TASK_BIPOD) && (RANDOM_LONG(1, 100) < 10))
{
sniping_time = gpGlobals->time; // so stop sniping
#ifdef _DEBUG
// testing - snipe time
if (in_bot_dev_level2)
{
char msg[80];
sprintf(msg, "BREAKING sniping time\n");
HudNotify(msg);
}
#endif
}
}
}
// the enemy must still be alive so ...
else
{
// this "enemy" is a wounded teammate
if (IsTask(TASK_HEALHIM))
{
// just return its pointer
return (pBotEnemy);
}
// the bot is carrying a goal item
// make him less aggresive
if (IsTask(TASK_GOALITEM))
{
// don't attack "healthy" enemy -- PROBABLY NOT SO GOOD IDEA TO LIMIT BOT THIS MUCH
//if (pBotEnemy->v.health > 25)
//{
// BotForgetEnemy();
// return (pBotEnemy);