forked from APGRoboCop/foxbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot_combat.cpp
2485 lines (2138 loc) · 107 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
//
// FoXBot - AI Bot for Halflife's Team Fortress Classic
//
// (http://foxbot.net)
//
// bot_combat.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.
//
#define NADEVELOCITY 650 // DrEvil #define
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "bot.h"
#include "bot_func.h"
#include "bot_job_think.h"
#include "bot_weapons.h"
#include "waypoint.h"
#include "bot_navigate.h"
extern WAYPOINT waypoints[MAX_WAYPOINTS];
extern int num_waypoints; // number of waypoints currently in map
// area defs...
extern AREA areas[MAX_WAYPOINTS];
extern int num_areas;
extern int mod_id;
extern bot_weapon_t weapon_defs[MAX_WEAPONS];
extern bool b_observer_mode;
extern edict_t* pent_info_ctfdetect;
extern float is_team_play;
extern bool checked_teamplay;
// bot settings //////////////////
extern int bot_use_grenades;
extern bool offensive_chatter;
extern int bot_skill_1_aim; // accuracy for skill 1 bots
extern int bot_aim_per_skill; // accuracy modifier for bots from skill 1 downwards
// accuracy levels for each bot skill level
static float bot_max_inaccuracy[5] = { 20.0, 30.0, 40.0, 50.0, 60.0 };
static float bot_snipe_max_inaccuracy[5] = { 10.0, 20.0, 30.0, 40.0, 50.0 };
extern bool is_team[4];
extern int team_allies[4];
extern bot_t bots[32];
// list of which player indices carry a flag(updated each frame)
// You should call PlayerHasFlag() rather than use this array directly, because of
// Half-Life engine complications(client list starts with index of 1 instead of 0).
static bool playerHasFlag[32];
// FUNCTION PROTOTYPES ///////////////
static void BotPipeBombCheck(bot_t* pBot);
static edict_t* BotFindEnemy(bot_t* pBot);
static bool BotSpyDetectCheck(bot_t* pBot, edict_t* Spy);
static void BotSGSpotted(bot_t* pBot, edict_t* sg);
static bool BotPrimeGrenade(bot_t* pBot, const int slot, const char nadeType, const unsigned short reserve);
static bool BotClearShotCheck(bot_t* pBot);
static Vector BotBodyTarget(edict_t* pBotEnemy, bot_t* pBot);
static int BotLeadTarget(edict_t* pBotEnemy, bot_t* pBot, const int projSpeed, float& d_x, float& d_y, float& d_z);
typedef struct {
int iId; // the weapon ID value
char weapon_name[64]; // name of the weapon when selecting it
int skill_level; // bot skill must be less than or equal to this value
float primary_min_distance; // 0 = no minimum
float primary_max_distance; // 9999 = no maximum
float secondary_min_distance; // 0 = no minimum
float secondary_max_distance; // 9999 = no maximum
int use_percent; // times out of 100 to use this weapon when available
bool can_use_underwater; // can use this weapon underwater
int primary_fire_percent; // times out of 100 to use primary fire
int min_primary_ammo; // minimum ammout of primary ammo needed to fire
int min_secondary_ammo; // minimum ammout of secondary ammo needed to fire
bool primary_fire_hold; // hold down primary fire button to use?
bool secondary_fire_hold; // hold down secondary fire button to use?
bool primary_fire_charge; // charge weapon using primary fire?
bool secondary_fire_charge; // charge weapon using secondary fire?
float primary_charge_delay; // time to charge weapon
float secondary_charge_delay; // time to charge weapon
} bot_weapon_select_t;
typedef struct {
int iId;
float primary_base_delay;
float primary_min_delay[5];
float primary_max_delay[5];
float secondary_base_delay;
float secondary_min_delay[5];
float secondary_max_delay[5];
} bot_fire_delay_t;
// This holds the multigun names we will check using a repeat loop
#define NumNTFGuns 8
char* ntfTargetChecks[] = {
"ntf_teslacoil", "ntf_grenlauncher", "ntf_rocklauncher", "ntf_lrlauncher", "ntf_flamegun", "ntf_crowbar",
"ntf_displacer", "ntf_biocannon",
};
// weapons are stored in priority order, most desired weapon should be at
// the start of the array and least desired should be at the end
static bot_weapon_select_t tfc_weapon_select[] = { { TF_WEAPON_KNIFE, "tf_weapon_knife", 5, 0.0, 90.0, 0.0, 0.0, 100,
TRUE, 100, 0, 0, FALSE, FALSE, FALSE, FALSE, 0.0, 0.0 },
{ TF_WEAPON_SPANNER, "tf_weapon_spanner", 5, 0.0, 90.0, 0.0, 0.0, 100, TRUE, 100, 0, 0, FALSE, FALSE, FALSE, FALSE,
0.0, 0.0 },
{ TF_WEAPON_MEDIKIT, "tf_weapon_medikit", 5, 0.0, 90.0, 0.0, 0.0, 100, TRUE, 100, 0, 0, FALSE, FALSE, FALSE, FALSE,
0.0, 0.0 },
{ TF_WEAPON_SNIPERRIFLE, "tf_weapon_sniperrifle", 5, 300.0, 4000.0, 0.0, 0.0, 100, TRUE, 100, 1, 0, FALSE, FALSE,
TRUE, FALSE, 2.0, 0.0 },
{ TF_WEAPON_FLAMETHROWER, "tf_weapon_flamethrower", 5, 0.0, 400.0, 0.0, 0.0, 100, FALSE, 100, 1, 0, TRUE, FALSE,
FALSE, FALSE, 0.0, 0.0 },
{ TF_WEAPON_AC, "tf_weapon_ac", 5, 0.0, 2500.0, 0.0, 0.0, 100, TRUE, 100, 1, 0, TRUE, FALSE, FALSE, FALSE, 0.0,
0.0 },
{ TF_WEAPON_RPG, "tf_weapon_rpg", 5, 180.0, 3000.0, 0.0, 0.0, 100, TRUE, 100, 1, 0, FALSE, FALSE, FALSE, FALSE, 0.0,
0.0 },
{ TF_WEAPON_IC, "tf_weapon_ic", 5, 300.0, 2000.0, 0.0, 0.0, 100, TRUE, 100, 1, 0, FALSE, FALSE, FALSE, FALSE, 0.0,
0.0 },
{ TF_WEAPON_SUPERSHOTGUN, "tf_weapon_supershotgun", 5, 0.0, 2000.0, 0.0, 0.0, 100, TRUE, 100, 2, 0, FALSE, FALSE,
FALSE, FALSE, 0.0, 0.0 },
{ TF_WEAPON_SUPERNAILGUN, "tf_weapon_superng", 5, 40.0, 3000.0, 0.0, 0.0, 100, TRUE, 100, 1, 0, TRUE, FALSE, FALSE,
FALSE, 0.0, 0.0 },
{ TF_WEAPON_TRANQ, "tf_weapon_tranq", 5, 40.0, 1000.0, 0.0, 0.0, 100, TRUE, 100, 1, 0, FALSE, FALSE, FALSE, FALSE,
0.0, 0.0 },
{ TF_WEAPON_AUTORIFLE, "tf_weapon_autorifle", 5, 0.0, 1000.0, 0.0, 0.0, 100, TRUE, 100, 1, 0, FALSE, FALSE, FALSE,
FALSE, 0.0, 0.0 },
{ TF_WEAPON_AXE, "tf_weapon_axe", 5, 0.0, 90.0, 0.0, 0.0, 100, TRUE, 100, 0, 0, FALSE, FALSE, FALSE, FALSE, 0.0,
0.0 },
{ TF_WEAPON_PL, "tf_weapon_pl", 5, 400.0, 900.0, 0.0, 0.0, 100, TRUE, 100, 1, 0, FALSE, FALSE, FALSE, FALSE, 0.0,
0.0 },
{ TF_WEAPON_GL, "tf_weapon_gl", 5, 180.0, 900.0, 0.0, 0.0, 100, TRUE, 100, 1, 0, FALSE, FALSE, FALSE, FALSE, 0.0,
0.0 },
{ TF_WEAPON_SHOTGUN, "tf_weapon_shotgun", 5, 0.0, 4000.0, 0.0, 0.0, 100, TRUE, 100, 1, 0, FALSE, FALSE, FALSE,
FALSE, 0.0, 0.0 },
{ TF_WEAPON_NAILGUN, "tf_weapon_ng", 5, 0.0, 3000.0, 0.0, 0.0, 100, TRUE, 100, 1, 0, FALSE, FALSE, FALSE, FALSE,
0.0, 0.0 },
{ TF_WEAPON_RAILGUN, "tf_weapon_railgun", 5, 40.0, 4000.0, 0.0, 0.0, 100, TRUE, 100, 1, 0, FALSE, FALSE, FALSE,
FALSE, 0.0, 0.0 },
/* terminator */
{ 0, "", 0, 0.0, 0.0, 0.0, 0.0, 0, TRUE, 0, 1, 1, FALSE, FALSE, FALSE, FALSE, 0.0, 0.0 } };
static bot_fire_delay_t tfc_fire_delay[] = {
{ TF_WEAPON_KNIFE, 0.3, { 0.0, 0.2, 0.3, 0.4, 0.6 }, { 0.1, 0.3, 0.5, 0.7, 1.0 }, 0.0, { 0.0, 0.0, 0.0, 0.0, 0.0 },
{ 0.0, 0.0, 0.0, 0.0, 0.0 } },
{ TF_WEAPON_SPANNER, 0.3, { 0.0, 0.2, 0.3, 0.4, 0.6 }, { 0.1, 0.3, 0.5, 0.7, 1.0 }, 0.0,
{ 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0 } },
{ TF_WEAPON_MEDIKIT, 0.3, { 0.0, 0.2, 0.3, 0.4, 0.6 }, { 0.1, 0.3, 0.5, 0.7, 1.0 }, 0.0,
{ 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0 } },
{ TF_WEAPON_SNIPERRIFLE, 0.5, { 0.0, 0.2, 0.6, 0.8, 1.0 }, { 0.3, 0.5, 0.7, 0.9, 1.1 }, 0.0,
{ 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0 } },
{ TF_WEAPON_FLAMETHROWER, 0.0, { 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0 }, 0.0,
{ 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0 } },
{ TF_WEAPON_AC, 0.0, { 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0 }, 0.0, { 0.0, 0.0, 0.0, 0.0, 0.0 },
{ 0.0, 0.0, 0.0, 0.0, 0.0 } },
{ TF_WEAPON_RPG, 0.6, { 0.0, 0.1, 0.3, 0.6, 1.0 }, { 0.1, 0.2, 0.7, 1.0, 2.0 }, 0.0, { 0.0, 0.0, 0.0, 0.0, 0.0 },
{ 0.0, 0.0, 0.0, 0.0, 0.0 } },
{ TF_WEAPON_IC, 0.6, { 1.0, 2.0, 3.0, 4.0, 5.0 }, { 3.0, 4.0, 5.0, 6.0, 7.0 }, 0.0, { 0.0, 0.0, 0.0, 0.0, 0.0 },
{ 0.0, 0.0, 0.0, 0.0, 0.0 } },
{ TF_WEAPON_SUPERSHOTGUN, 0.6, { 0.0, 0.2, 0.5, 0.8, 1.0 }, { 0.25, 0.4, 0.7, 1.0, 1.3 }, 0.0,
{ 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0 } },
{ TF_WEAPON_SUPERNAILGUN, 0.0, { 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0 }, 0.0,
{ 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0 } },
{ TF_WEAPON_TRANQ, 1.5, { 1.0, 2.0, 3.0, 4.0, 5.0 }, { 3.0, 4.0, 5.0, 6.0, 7.0 }, 0.0, { 0.0, 0.0, 0.0, 0.0, 0.0 },
{ 0.0, 0.0, 0.0, 0.0, 0.0 } },
{ TF_WEAPON_AUTORIFLE, 0.1, { 0.0, 0.1, 0.2, 0.4, 0.6 }, { 0.1, 0.2, 0.5, 0.7, 1.0 }, 0.0,
{ 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0 } },
{ TF_WEAPON_AXE, 0.3, { 0.0, 0.2, 0.3, 0.4, 0.6 }, { 0.1, 0.3, 0.5, 0.7, 1.0 }, 0.0, { 0.0, 0.0, 0.0, 0.0, 0.0 },
{ 0.0, 0.0, 0.0, 0.0, 0.0 } },
{ TF_WEAPON_PL, 0.6, { 0.0, 0.2, 0.5, 0.8, 1.0 }, { 0.25, 0.4, 0.7, 1.0, 1.3 }, 0.0, { 0.0, 0.0, 0.0, 0.0, 0.0 },
{ 0.0, 0.0, 0.0, 0.0, 0.0 } },
{ TF_WEAPON_GL, 0.6, { 0.0, 0.2, 0.5, 0.8, 1.0 }, { 0.25, 0.4, 0.7, 1.0, 1.3 }, 0.0, { 0.0, 0.0, 0.0, 0.0, 0.0 },
{ 0.0, 0.0, 0.0, 0.0, 0.0 } },
{ TF_WEAPON_SHOTGUN, 0.5, { 0.0, 0.2, 0.4, 0.6, 0.8 }, { 0.25, 0.5, 0.8, 1.2, 2.0 }, 0.0,
{ 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0 } },
{ TF_WEAPON_NAILGUN, 0.1, { 0.0, 0.1, 0.2, 0.4, 0.6 }, { 0.1, 0.2, 0.5, 0.7, 1.0 }, 0.0,
{ 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0 } },
{ TF_WEAPON_RAILGUN, 0.4, { 0.0, 0.1, 0.2, 0.3, 0.4 }, { 0.1, 0.2, 0.3, 0.4, 0.5 }, 0.0,
{ 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0 } },
/* terminator */
{ 0, 0.0, { 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0 }, 0.0, { 0.0, 0.0, 0.0, 0.0, 0.0 },
{ 0.0, 0.0, 0.0, 0.0, 0.0 } }
};
void BotCheckTeamplay(void)
{
// is this TFC?
if(mod_id == TFC_DLL)
is_team_play = 1.0;
else
is_team_play = CVAR_GET_FLOAT("mp_teamplay"); // teamplay enabled?
checked_teamplay = TRUE;
}
// This function can be used to report the number of players using the specified class
// on the specified players team, or a team allied to them.
// You'll be cheating if you use this function on an enemy team. >:-O
int FriendlyClassTotal(edict_t* pEdict, const int specifiedClass, const bool ignoreSelf)
{
if(!checked_teamplay) // check for team play...
BotCheckTeamplay();
// report failure if there is no team play
if(is_team_play <= 0 || mod_id != TFC_DLL)
return FALSE;
const int my_team = UTIL_GetTeam(pEdict);
edict_t* pPlayer;
int player_team;
int classTotal = 0;
// search the world for players...
for(int i = 1; i <= gpGlobals->maxClients; i++) {
pPlayer = INDEXENT(i);
// skip invalid players
if(pPlayer && !pPlayer->free) {
// check the specified player if instructed to do so
if(pPlayer == pEdict) {
if(pPlayer->v.playerclass == specifiedClass && !ignoreSelf)
++classTotal;
} else if(IsAlive(pPlayer) && pPlayer->v.playerclass == specifiedClass) {
player_team = UTIL_GetTeam(pPlayer);
// add another if the player is a teammate or ally
if(my_team == player_team || team_allies[my_team] & (1 << player_team))
++classTotal;
}
}
}
return classTotal;
}
// This function should be called whenever bot_skill_1_aim or bot_aim_per_skill
// are changed, because it updates the bot inaccuracy levels based on those two
// config settings.
void BotUpdateSkillInaccuracy(void)
{
const float f_aim_per_skill = static_cast<float>(bot_aim_per_skill);
bot_max_inaccuracy[0] = static_cast<float>(bot_skill_1_aim);
bot_max_inaccuracy[1] = bot_max_inaccuracy[0] + f_aim_per_skill;
bot_max_inaccuracy[2] = bot_max_inaccuracy[1] + f_aim_per_skill;
bot_max_inaccuracy[3] = bot_max_inaccuracy[2] + f_aim_per_skill; // Foxbot >0.77 Version had a typo? [APG]RoboCop[CL]
bot_max_inaccuracy[4] = bot_max_inaccuracy[3] + f_aim_per_skill;
// sniper rifle inaccuracy starts out a bit lower than with other weapons
// but then scales up in the same way
bot_snipe_max_inaccuracy[0] = bot_max_inaccuracy[0] * 0.75;
bot_snipe_max_inaccuracy[1] = bot_snipe_max_inaccuracy[0] + f_aim_per_skill;
bot_snipe_max_inaccuracy[2] = bot_snipe_max_inaccuracy[1] + f_aim_per_skill;
bot_snipe_max_inaccuracy[3] = bot_snipe_max_inaccuracy[2] + f_aim_per_skill;
bot_snipe_max_inaccuracy[4] = bot_snipe_max_inaccuracy[3] + f_aim_per_skill;
// UTIL_BotLogPrintf("New bot accuracy levels %f %f %f %f %f\n",
// bot_max_inaccuracy[0], bot_max_inaccuracy[1], bot_max_inaccuracy[2],
// bot_max_inaccuracy[3], bot_max_inaccuracy[4]);
}
// Set pipebombs off if they are near to the bots enemy.
static void BotPipeBombCheck(bot_t* pBot)
{
edict_t* pent = NULL;
while((pent = FIND_ENTITY_BY_CLASSNAME(pent, "tf_gl_pipebomb")) != NULL && !FNullEnt(pent)) {
if(pBot->pEdict == pent->v.owner && VectorsNearerThan(pBot->enemy.ptr->v.origin, pent->v.origin, 90.0)) {
FakeClientCommand(pBot->pEdict, "detpipe", NULL, NULL);
return;
}
}
}
// This function was created for use by feigning Spies.
// It will search for an enemy player who is near to the Spy and facing
// away from them. i.e. backstabbing victims!
static void BotFeigningEnemyCheck(bot_t* pBot)
{
pBot->lastEnemySentryGun = NULL; // ignore all sentry guns, the bot is feigning
pBot->visAllyCount = 1; // assume the bot can't see much because it has to stay still
// see if there are any enemies near enough to this location
edict_t* pPlayer;
int player_team;
for(int i = 1; i <= gpGlobals->maxClients; i++) {
pPlayer = INDEXENT(i);
// skip invalid players and skip self (i.e. this bot)
if(pPlayer && !pPlayer->free && pPlayer != pBot->pEdict && IsAlive(pPlayer)) {
// ignore humans in observer mode
if(b_observer_mode && !(pPlayer->v.flags & FL_FAKECLIENT))
continue;
// ignore allied players
player_team = UTIL_GetTeam(pPlayer);
if(player_team > -1 &&
(player_team == pBot->current_team || team_allies[pBot->current_team] & (1 << player_team)))
continue;
// is this enemy near and facing away from the bot?
if(VectorsNearerThan(pPlayer->v.origin, pBot->pEdict->v.origin, 400.0f) &&
!FInViewCone(pBot->pEdict->v.origin, pPlayer) && FVisible(pPlayer->v.origin, pBot->pEdict)) {
// is this a new sighting?
if(pBot->enemy.ptr != pPlayer)
pBot->enemy.f_firstSeen = pBot->f_think_time;
pBot->enemy.ptr = pPlayer;
pBot->enemy.f_lastSeen = pBot->f_think_time;
pBot->enemy.lastLocation = pPlayer->v.origin;
pBot->visEnemyCount = 1;
return;
}
}
}
// no target found, clear the Spies knowledge of enemies
pBot->enemy.ptr = NULL;
pBot->visEnemyCount = 0;
}
// This function will first check that the bots current enemy is still a
// valid target for attacking.
// Then it will check if the bot can see a new(perhaps more important) target.
void BotEnemyCheck(bot_t* pBot)
{
// let feigning spys target enemies in their own way
if(pBot->pEdict->v.playerclass == TFC_CLASS_SPY && pBot->pEdict->v.deadflag == 5) {
BotFeigningEnemyCheck(pBot);
return;
}
// stupidity check... dont target yourself moron.
if(pBot->enemy.ptr == pBot->pEdict)
pBot->enemy.ptr = NULL;
// handle sniper firing delays(when they have a target)
if(pBot->f_snipe_time > pBot->f_think_time) {
pBot->pEdict->v.button |= IN_ATTACK;
}
// test our last SG to see if its still valid
// a crash could occur if using a pointer to a non-existant SG
if(!FNullEnt(pBot->lastEnemySentryGun)) {
// Is it a sentry gun or an NTF multigun?
if((strcmp(STRING(pBot->lastEnemySentryGun->v.classname), "building_sentrygun") == 0 ||
strncmp(STRING(pBot->lastEnemySentryGun->v.classname), "ntf_", 4) == 0) &&
(BotTeamColorCheck(pBot->lastEnemySentryGun) != pBot->current_team)) {
// get the bots to notice the destruction of this sentry gun
if(!IsAlive(pBot->lastEnemySentryGun) && pBot->lastEnemySentryGun->v.origin != Vector(0, 0, 0)) {
edict_t* deadSG = pBot->lastEnemySentryGun;
int area = AreaInsideClosest(deadSG);
if(area != -1) {
char msg[MAX_CHAT_LENGTH];
if(pBot->current_team == 0)
_snprintf(msg, MAX_CHAT_LENGTH, "Sentry Down %s", areas[area].namea);
else if(pBot->current_team == 1)
_snprintf(msg, MAX_CHAT_LENGTH, "Sentry Down %s", areas[area].nameb);
else if(pBot->current_team == 2)
_snprintf(msg, MAX_CHAT_LENGTH, "Sentry Down %s", areas[area].namec);
else if(pBot->current_team == 3)
_snprintf(msg, MAX_CHAT_LENGTH, "Sentry Down %s", areas[area].named);
msg[MAX_CHAT_LENGTH - 1] = '\0';
bool destruction_reported = FALSE;
for(int i = 0; i < 32; i++) {
if(bots[i].is_used && bots[i].lastEnemySentryGun == deadSG) {
// get one bot that saw the sentry get destroyed to report it
if(!destruction_reported && bots[i].current_team == pBot->current_team &&
!BufferContainsJobType(&bots[i], JOB_REPORT) &&
VectorsNearerThan(deadSG->v.origin, bots[i].pEdict->v.origin, 1400.0f) &&
FVisible(deadSG->v.origin + deadSG->v.view_ofs, bots[i].pEdict)) {
job_struct* newJob = InitialiseNewJob(&bots[i], JOB_REPORT);
if(newJob != NULL) {
strncpy(newJob->message, msg, MAX_CHAT_LENGTH);
newJob->message[MAX_CHAT_LENGTH - 1] = '\0';
SubmitNewJob(&bots[i], JOB_REPORT, newJob);
destruction_reported = TRUE;
}
}
bots[i].lastEnemySentryGun = NULL;
}
}
}
}
} else // sentry pointer is pointing at something which isn't a sentry gun
{
if(pBot->enemy.ptr == pBot->lastEnemySentryGun)
pBot->enemy.ptr = NULL;
pBot->lastEnemySentryGun = NULL;
}
} else {
if(pBot->enemy.ptr == pBot->lastEnemySentryGun)
pBot->enemy.ptr = NULL;
pBot->lastEnemySentryGun = NULL;
}
// clear this, it's tested below
pBot->enemy.seenWithFlag = FALSE;
// if the bot has a current enemy, check if it's still valid
if(pBot->enemy.ptr != NULL) {
Vector vecEnd = pBot->enemy.ptr->v.origin + pBot->enemy.ptr->v.view_ofs;
// anti friendly fire
if(pBot->pEdict->v.playerclass != TFC_CLASS_MEDIC && pBot->pEdict->v.playerclass != TFC_CLASS_ENGINEER &&
(pBot->pEdict->v.team == pBot->enemy.ptr->v.team ||
BotTeamColorCheck(pBot->enemy.ptr) == pBot->current_team)) {
if(pBot->enemy.ptr->v.playerclass != TFC_CLASS_MEDIC)
pBot->enemy.ptr = NULL;
} else if(pBot->enemy.ptr->v.flags & FL_KILLME) {
// the enemies edict has been flagged for deletion
// so null out the pointer to them
pBot->enemy.ptr = NULL;
}
// is the enemy dead? assume bot killed it
else if(!IsAlive(pBot->enemy.ptr) &&
!(pBot->enemy.ptr->v.deadflag == 5 && random_long(0, (pBot->bot_skill + 1) * 1000) < 900)) {
// the enemy is dead, jump for joy about 20% of the time
if(random_long(1, 100) <= 20)
pBot->pEdict->v.button |= IN_JUMP;
if(random_long(1, 100) <= 20)
BotSprayLogo(pBot->pEdict, TRUE);
// don't have an enemy anymore so null out the pointer...
pBot->enemy.ptr = NULL;
} else if(!FInViewCone(vecEnd, pBot->pEdict) || !FVisible(vecEnd, pBot->pEdict)) {
pBot->enemy.ptr = NULL; // forget the enemy
} else // enemy is visible
{
// keep this up to date
pBot->enemy.lastLocation = pBot->enemy.ptr->v.origin;
// keep track of when the bot last saw an enemy
pBot->enemy.f_lastSeen = pBot->f_think_time;
// update the bots known distance from it's enemy
pBot->enemy.f_seenDistance = (pBot->pEdict->v.origin - pBot->enemy.ptr->v.origin).Length();
// check and remember if the bots enemy has a flag
// so that we can avoid repeating this test elsewhere
if(PlayerHasFlag(pBot->enemy.ptr))
pBot->enemy.seenWithFlag = TRUE;
// this code segment sets up a snipers sniper rifle firing delay
if(pBot->pEdict->v.playerclass == TFC_CLASS_SNIPER && pBot->current_weapon.iId == TF_WEAPON_SNIPERRIFLE) {
float timeVal = (pBot->bot_skill + 1) * 0.4;
// if f_snipe_time is too high or too low reset it
if((pBot->f_snipe_time + 0.3) < pBot->f_think_time ||
pBot->f_snipe_time > pBot->f_think_time + timeVal) {
// set pBot->f_snipe_time for a short delay
pBot->f_snipe_time = pBot->f_think_time + random_float(0.0, timeVal);
pBot->pEdict->v.button |= IN_ATTACK;
pBot->f_pause_time = pBot->f_snipe_time;
}
}
}
}
// is the enemy near one of the bot's pipebombs?
if(pBot->pEdict->v.playerclass == TFC_CLASS_DEMOMAN && pBot->enemy.ptr != NULL)
BotPipeBombCheck(pBot);
// optimization - don't check for new enemies too often
if(pBot->f_enemy_check_time > pBot->f_think_time)
return;
else
pBot->f_enemy_check_time = pBot->f_think_time + 0.2f;
// now scan the visible area around the bot for new enemies
edict_t* new_enemy = BotFindEnemy(pBot);
if(new_enemy != NULL && new_enemy != pBot->enemy.ptr) {
pBot->enemy.ptr = new_enemy;
pBot->enemy.f_firstSeen = pBot->f_think_time;
pBot->enemy.f_lastSeen = pBot->f_think_time;
pBot->enemy.lastLocation = new_enemy->v.origin;
}
}
// This function is responsible for checking if the bot can see a new
// target worth attacking.
static edict_t* BotFindEnemy(bot_t* pBot)
{
edict_t* pEdict = pBot->pEdict;
int i;
bool return_null = FALSE;
edict_t* pNewEnemy = NULL;
edict_t* pent;
Vector vecEnd;
float nearestDistance;
// some basic TFC stuff
if(mod_id == TFC_DLL) {
// if bot is a disguised spy consider not targetting anyone
if(pEdict->v.playerclass == TFC_CLASS_SPY && pBot->enemy.ptr == NULL &&
pBot->disguise_state == DISGUISE_COMPLETE && (pBot->f_injured_time + 0.5f) < pBot->f_think_time)
return_null = TRUE;
// if injured whilst carrying a flag always shoot back
if((pBot->f_injured_time + 0.3f) > pBot->f_think_time && pBot->bot_has_flag)
return_null = FALSE;
}
// if the bot currently has an enemy
if(pBot->enemy.ptr != NULL) {
vecEnd = pBot->enemy.ptr->v.origin + pBot->enemy.ptr->v.view_ofs;
if(FInViewCone(vecEnd, pEdict) && FVisible(vecEnd, pEdict)) {
// check for closer enemy, or enemy with flag here!
// and sentry guns!!!!!!
pent = NULL;
nearestDistance = 2000.0;
while((pent = FIND_ENTITY_BY_CLASSNAME(pent, "building_sentrygun")) != NULL && (!FNullEnt(pent))) {
int sentry_team = BotTeamColorCheck(pent);
// don't target your own team's sentry guns...
// don't target allied sentry guns either...
if(pBot->current_team == sentry_team || team_allies[pBot->current_team] & (1 << sentry_team))
continue;
vecEnd = pent->v.origin + pent->v.view_ofs;
// is this the closest visible sentry gun?
float distance = (pent->v.origin - pEdict->v.origin).Length();
if(distance < nearestDistance && FInViewCone(vecEnd, pEdict) && FVisible(vecEnd, pEdict)) {
nearestDistance = distance;
pNewEnemy = pent;
return_null = FALSE;
BotSGSpotted(pBot, pent);
}
}
// This checks for uncaptured multiguns.
pent = NULL;
while((pent = FIND_ENTITY_BY_CLASSNAME(pent, "ntf_multigun")) != NULL && (!FNullEnt(pent))) {
if((pent->v.flags & FL_KILLME) == FL_KILLME)
continue;
int sentry_team = pent->v.team - 1;
// don't target friendly sentry guns...
if(pBot->current_team == sentry_team || team_allies[pBot->current_team] & (1 << sentry_team))
continue;
// ntf_capture_mg 1 = ignore, we can cap it
char* cvar_ntf_capture_mg = (char*)CVAR_GET_STRING("ntf_capture_mg");
if(strcmp(cvar_ntf_capture_mg, "1") == 0)
continue;
// is this the closest visible sentry gun?
vecEnd = pent->v.origin + pent->v.view_ofs;
float distance = (pent->v.origin - pEdict->v.origin).Length();
if(distance < nearestDistance && FInViewCone(vecEnd, pEdict) && FVisible(vecEnd, pEdict)) {
nearestDistance = distance;
pNewEnemy = pent;
return_null = FALSE;
BotSGSpotted(pBot, pent);
}
}
// This function loops through the multiguns
// looking for a better target.
BotCheckForMultiguns(pBot, nearestDistance, pNewEnemy, return_null);
if(pNewEnemy)
return pNewEnemy;
// only return enemy we got if they're close..
// and we're not sniping
// and they're not the player we're tracking
if(pBot->enemy.ptr != NULL) {
// put random in, so hopefully cpu usage is a bit less
if(pBot->f_snipe_time < pBot->f_think_time &&
(VectorsNearerThan(pBot->enemy.ptr->v.origin, pEdict->v.origin, 250.0f) ||
random_long(1, 1000) < 700))
return (pBot->enemy.ptr);
} else
return NULL;
} else {
// if the bot can't see it's targetted Sentry Gun fuggedaboutit
if(pBot->lastEnemySentryGun != NULL && pBot->enemy.ptr == pBot->lastEnemySentryGun &&
!FNullEnt(pBot->lastEnemySentryGun))
pBot->enemy.ptr = NULL;
pBot->f_shoot_time = pBot->f_think_time + 1.0f; // normally +2
}
}
pNewEnemy = NULL;
nearestDistance = 1000.0;
if(mod_id == TFC_DLL) {
// get medics and engineers to heal/repair teammates
if(pBot->pEdict->v.playerclass == TFC_CLASS_MEDIC ||
(pBot->pEdict->v.playerclass == TFC_CLASS_ENGINEER &&
pBot->m_rgAmmo[weapon_defs[TF_WEAPON_SPANNER].iAmmo1] > 90)) {
nearestDistance = 1000.0;
edict_t* pPlayer;
int player_team;
// search the world for players...
for(i = 1; i <= gpGlobals->maxClients; i++) {
pPlayer = INDEXENT(i);
// skip invalid players and skip self (i.e. this bot)
if(pPlayer && !pPlayer->free && pPlayer != pEdict) {
// skip this player if they're not alive
if(!IsAlive(pPlayer))
continue;
// skip human players in observer mode
if(b_observer_mode && !(pPlayer->v.flags & FL_FAKECLIENT))
continue;
player_team = UTIL_GetTeamColor(pPlayer);
// ignore all enemies...
if((pBot->current_team != player_team) && !(team_allies[pBot->current_team] & (1 << player_team)))
continue;
// check if the player needs to be healed
if(pBot->pEdict->v.playerclass == TFC_CLASS_MEDIC &&
(pPlayer->v.health / pPlayer->v.max_health) > 0.80 &&
!PlayerIsInfected(pPlayer)) // scores a point, even to selfish medics
continue; // health greater than 70% so ignore
// check if the player needs to be armored...
if(pBot->pEdict->v.playerclass == TFC_CLASS_ENGINEER &&
(PlayerIsInfected(pPlayer) || PlayerArmorPercent(pPlayer) > 50))
continue; // armor greater than 50% so ignore
// see if bot can see the player...
float distance = (pPlayer->v.origin - pEdict->v.origin).Length();
vecEnd = pPlayer->v.origin + pPlayer->v.view_ofs;
if(distance < nearestDistance && FInViewCone(vecEnd, pEdict) && FVisible(vecEnd, pEdict)) {
nearestDistance = distance;
// set up a job to handle the healing/repairing
job_struct* newJob = InitialiseNewJob(pBot, JOB_BUFF_ALLY);
if(newJob != NULL) {
newJob->player = pPlayer;
newJob->origin = pPlayer->v.origin; // remember where the player was seen
SubmitNewJob(pBot, JOB_BUFF_ALLY, newJob);
}
break;
}
}
}
}
if(!pNewEnemy) {
// check for sniper laser dots
pent = NULL;
while((pent = FIND_ENTITY_BY_CLASSNAME(pent, "laser_spot")) != NULL && (!FNullEnt(pent))) {
// ignore your own sniper spot
if(pent->v.owner == pEdict)
continue;
int sniper_team = UTIL_GetTeam(pent->v.owner);
// ignore sniper spots from your team
// and ignore sniper spots from your allies
if(sniper_team == pBot->current_team || team_allies[pBot->current_team] & (1 << sniper_team))
continue;
// ok... check distance to sniper spot and see if its nearish
// to the bot... if it is and they can see the sniper...
// make them the enemy! not very human like..but fun!
if(VectorsNearerThan(pent->v.origin, pEdict->v.origin, 500.0f)) {
vecEnd = pent->v.owner->v.origin + pent->v.owner->v.view_ofs;
if(FVisible(vecEnd, pEdict)) {
// DrEvil
// Lets add some error into this. annoying when the
// bots always snapshot as soon as they see your dot.
if(pBot->pEdict->v.playerclass == TFC_CLASS_CIVILIAN ||
(pBot->bot_skill * 10 + random_long(0, 50)) < 60)
pNewEnemy = pent->v.owner;
}
}
}
// check for sentry guns
pent = NULL;
while((pent = FIND_ENTITY_BY_CLASSNAME(pent, "building_sentrygun")) != NULL && (!FNullEnt(pent))) {
int sentry_team = BotTeamColorCheck(pent);
// don't target your own team's sentry guns...
// don't target allied sentry guns either...
vecEnd = pent->v.origin + pent->v.view_ofs; // + Vector(0,0,16);
if(pBot->current_team == sentry_team || team_allies[pBot->current_team] & (1 << sentry_team)) {
if(VectorsNearerThan(pent->v.origin, pEdict->v.origin, 300.0f) &&
pEdict->v.playerclass != TFC_CLASS_ENGINEER && FInViewCone(vecEnd, pEdict) &&
FVisible(vecEnd, pEdict)) {
// ntf_feature_antigren
char* cvar_ntf_feature_antigren = (char*)CVAR_GET_STRING("ntf_feature_antigren");
if(pEdict->v.playerclass == TFC_CLASS_MEDIC && strcmp(cvar_ntf_feature_antigren, "1") == 0) {
FakeClientCommand(pEdict, "_special2", NULL, NULL);
}
// discard uneeded ammo when near friendly SG's
FakeClientCommand(pEdict, "discard", NULL, NULL);
BlacklistJob(pBot, JOB_SPOT_STIMULUS, 2.0); // ignore the pack as it drops
if(pBot->ammoStatus != AMMO_UNNEEDED)
BlacklistJob(pBot, JOB_PICKUP_ITEM, 2.0); // don't pick up your pack
}
continue;
}
// is this the closest visible sentry gun?
const float distance = (pent->v.origin - pEdict->v.origin).Length();
if(distance < nearestDistance && FInViewCone(vecEnd, pEdict) && FVisible(vecEnd, pEdict)) {
nearestDistance = distance;
pNewEnemy = pent;
return_null = FALSE;
BotSGSpotted(pBot, pent);
}
}
// neotf guns
pent = NULL;
while((pent = FIND_ENTITY_BY_CLASSNAME(pent, "ntf_multigun")) != NULL && (!FNullEnt(pent))) {
if((pent->v.flags & FL_KILLME) == FL_KILLME)
continue;
int sentry_team = pent->v.team - 1;
// don't target friendly sentry guns...
if(pBot->current_team == sentry_team || team_allies[pBot->current_team] & (1 << sentry_team))
continue;
// ntf_capture_mg 1 = ignore, we can cap it
char* cvar_ntf_capture_mg = (char*)CVAR_GET_STRING("ntf_capture_mg");
if(strcmp(cvar_ntf_capture_mg, "1") == 0)
continue;
// is this the closest visible sentry gun?
const float distance = (pent->v.origin - pEdict->v.origin).Length();
vecEnd = pent->v.origin + pent->v.view_ofs;
if(distance < nearestDistance && FInViewCone(vecEnd, pEdict) && FVisible(vecEnd, pEdict)) {
nearestDistance = distance;
pNewEnemy = pent;
return_null = FALSE;
}
}
// This function loops through the multiguns
// looking for a better target.
BotCheckForMultiguns(pBot, nearestDistance, pNewEnemy, return_null);
}
} // end tfc mod if
if(!pNewEnemy) {
edict_t* pPlayer;
int player_team;
bool player_is_ally;
pBot->visEnemyCount = 0; // reset this, so that it can be recalculated
pBot->visAllyCount = 1; // reset this, so that it can be recalculated
nearestDistance = 3000;
if(!checked_teamplay) // check for team play...
BotCheckTeamplay();
// track whether or not the bot is willing to escort an ally
bool canEscort = FALSE;
if(!pBot->bot_has_flag && !BufferContainsJobType(pBot, JOB_ESCORT_ALLY))
canEscort = TRUE;
// search the world for players...
for(i = 1; i <= gpGlobals->maxClients; i++) {
pPlayer = INDEXENT(i);
// skip invalid players and skip self (i.e. this bot)
if((pPlayer) && (!pPlayer->free) && (pPlayer != pEdict)) {
// skip this player if not alive (i.e. dead or dying)
if(!IsAlive(pPlayer) &&
!(pPlayer->v.deadflag == 5 // a feign check
&& random_long(0, (pBot->bot_skill + 1) * 1000) < 900))
continue;
// skip human players in observer mode
if(b_observer_mode && !(pPlayer->v.flags & FL_FAKECLIENT))
continue;
player_is_ally = FALSE;
// is team play enabled?
if(is_team_play > 0.0) {
player_team = UTIL_GetTeam(pPlayer);
// don't target your teammates...
if(pBot->current_team == player_team)
player_is_ally = TRUE;
if(mod_id == TFC_DLL) {
// don't target your allies either...
if(team_allies[pBot->current_team] & (1 << player_team))
player_is_ally = TRUE;
// so disguised spys wont attack other disguised spys
if(pEdict->v.playerclass == TFC_CLASS_SPY && (pPlayer->v.playerclass == TFC_CLASS_SPY) &&
pBot->current_team == UTIL_GetTeamColor(pPlayer))
continue;
}
}
// check for allied players
if(player_is_ally) {
vecEnd = pPlayer->v.origin + pPlayer->v.view_ofs;
if(VectorsNearerThan(pPlayer->v.origin, pEdict->v.origin, 1000.0f) && FVisible(vecEnd, pEdict)) {
// keep tags on the allies the bot can see
++pBot->visAllyCount;
pBot->lastAllyVector = pPlayer->v.origin;
pBot->f_lastAllySeenTime = pBot->f_think_time;
// seen a friendly Medic?
if(pPlayer->v.playerclass == TFC_CLASS_MEDIC)
pBot->f_alliedMedicSeenTime = pBot->f_think_time;
// try and set up an escort job if the ally has a flag
if(canEscort && PlayerHasFlag(pPlayer)) {
job_struct* newJob = InitialiseNewJob(pBot, JOB_ESCORT_ALLY);
if(newJob != NULL) {
newJob->player = pPlayer;
newJob->origin = pPlayer->v.origin; // remember where
if(SubmitNewJob(pBot, JOB_ESCORT_ALLY, newJob) == TRUE)
canEscort = FALSE;
}
}
}
continue;
}
vecEnd = pPlayer->v.origin + pPlayer->v.view_ofs;
// see if the bot can see the player...
if(FInViewCone(vecEnd, pEdict) && FVisible(vecEnd, pEdict)) {
const float distance = (pPlayer->v.origin - pEdict->v.origin).Length();
// count the number of visible enemies nearby
if(distance < 1200.0f)
++pBot->visEnemyCount;
if(distance < nearestDistance) {
nearestDistance = distance;
pNewEnemy = pPlayer;
}
}
}
}
}
if(pNewEnemy && mod_id == TFC_DLL) {
const float distance = (pNewEnemy->v.origin - pEdict->v.origin).Length();
vecEnd = pEdict->v.origin + pEdict->v.view_ofs;
// if the enemy can't see this bot and this bot is a Spy
if(pBot->pEdict->v.playerclass == TFC_CLASS_SPY && pBot->bot_real_health > 25 && !pBot->enemy.ptr &&
pBot->disguise_state == DISGUISE_COMPLETE && distance < 400.0 &&
!(FInViewCone(vecEnd, pNewEnemy) && FVisible(vecEnd, pNewEnemy))) {
// backstab routine...might work :)
pBot->strafe_mod = STRAFE_MOD_STAB;
return_null = FALSE;
}
// turn off backstab routine if too far away
else if(pBot->pEdict->v.playerclass == TFC_CLASS_SPY && distance >= 400.0)
pBot->strafe_mod = STRAFE_MOD_NORMAL;
// return null(if return_null == true)
// only if the enemy hasn't got your flag
if(return_null && pNewEnemy != pEdict) {
bool enemy_has_flag = FALSE;
// is the enemy carrying the flag/card/ball ?
edict_t* pent = NULL;
while((pent = FIND_ENTITY_BY_CLASSNAME(pent, "item_tfgoal")) != NULL && !FNullEnt(pent)) {
if(pent->v.owner == pNewEnemy) {
enemy_has_flag = TRUE;
break; // break out of while loop
}
}
if(enemy_has_flag == FALSE && (pBot->enemy.f_lastSeen + 2.0) <= pBot->f_think_time)
return pBot->enemy.ptr; // if the enemy doesn't have the flag
}
}
// check if the bot should continue to target a disguised/feigning Spy
if(return_null == FALSE && BotSpyDetectCheck(pBot, pNewEnemy) == FALSE)
return (pBot->enemy.ptr);
if(pNewEnemy) {
// face the new enemy
Vector v_enemy = pNewEnemy->v.origin - pEdict->v.origin;
Vector bot_angles = UTIL_VecToAngles(v_enemy);
pEdict->v.ideal_yaw = bot_angles.y;
pEdict->v.idealpitch = bot_angles.x;
if(pEdict->v.playerclass == TFC_CLASS_SNIPER && pBot->current_weapon.iId == TF_WEAPON_SNIPERRIFLE &&
pBot->bot_skill > 0 && mod_id == TFC_DLL) {
// BotChangeYaw(pBot->pEdict,1);
} else
BotFixIdealYaw(pEdict);
}
// has the bot NOT seen an enemy for a few seconds? (time to reload)
if((pBot->enemy.f_lastSeen + 0.5f) <= pBot->f_think_time && (pBot->enemy.f_lastSeen + 1.5f) > pBot->f_think_time) {
// press reload button
pEdict->v.button |= IN_RELOAD;
return (pNewEnemy);
}
if(!pNewEnemy) {
pEdict->v.button |= IN_RELOAD; // press reload button
// if not a disguised spy return the bots current enemy
if(!(return_null && pEdict->v.playerclass == TFC_CLASS_SPY && pBot->disguise_state == DISGUISE_COMPLETE))
return pBot->enemy.ptr;
}
return (pNewEnemy);
}
// You can call this function when the bot spots a disguised or feigning Spy.
// Spies will be given a random amount of seconds before they are attacked.
// It returns true if the Spy should be attacked, false otherwise.
static bool BotSpyDetectCheck(bot_t* pBot, edict_t* pNewEnemy)
{
// the bot has encountered a new enemy
if(pNewEnemy != NULL && pNewEnemy != pBot->suspectedSpy) {
// if the enemy is not disguised/feigning forget the last Spy
if(pBot->current_team != UTIL_GetTeamColor(pNewEnemy) && pNewEnemy->v.deadflag != 5) {
pBot->suspectedSpy = NULL;
pBot->f_suspectSpyTime = 0;
return TRUE;
}
const float distance = (pNewEnemy->v.origin - pBot->pEdict->v.origin).Length();
// only consider disguised/feigning Spies who are near enough
if(distance < 1200.0f) {
// a cool laser effect to show who has just spotted a Spy
// (for debugging purposes)
// WaypointDrawBeam(INDEXENT(1), pBot->pEdict->v.origin,
// pNewEnemy->v.origin, 10, 2, 250, 50, 250, 200, 10);
pBot->suspectedSpy = pNewEnemy;
// moderate the bots suspicion based on what role it's filling
if(pBot->mission == ROLE_DEFENDER) {
pBot->f_suspectSpyTime = (pBot->f_think_time + random_float(2.0f, 5.0f)) + (pBot->bot_skill * 0.5f);
// maybe track the spy about for a bit whilst suspicious
if(pBot->bot_class != TFC_CLASS_CIVILIAN && random_long(0, 1000) < 250) {
job_struct* newJob = InitialiseNewJob(pBot, JOB_PURSUE_ENEMY);
if(newJob != NULL) {
newJob->player = pBot->suspectedSpy;
newJob->origin = pBot->suspectedSpy->v.origin; // remember where
SubmitNewJob(pBot, JOB_PURSUE_ENEMY, newJob);
}
pBot->f_suspectSpyTime += 2.0f;
}
} else // attackers
{
pBot->f_suspectSpyTime = (pBot->f_think_time + random_float(2.0f, 5.0f)) + (pBot->bot_skill * 0.5f);
// maybe track the spy about for a bit whilst suspicious
if(pBot->bot_class != TFC_CLASS_CIVILIAN && random_long(0, 1000) < 100) {