-
Notifications
You must be signed in to change notification settings - Fork 2
/
bot_navigate.cpp
2452 lines (1924 loc) · 74.6 KB
/
bot_navigate.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// HPB bot - botman's High Ping Bastard bot
//
// (http://planethalflife.com/botman/)
//
// bot_navigate.cpp
//
#ifndef _WIN32
#include <string.h>
#endif
#include <extdll.h>
#include <dllapi.h>
#include <h_export.h>
#include <meta_api.h>
#include "bot.h"
#include "bot_func.h"
#include "bot_weapons.h"
#include "waypoint.h"
extern int mod_id;
extern WAYPOINT waypoints[MAX_WAYPOINTS];
extern int num_waypoints; // number of waypoints currently in use
extern int team_allies[4];
extern edict_t *pent_info_ctfdetect;
extern bool is_team_play;
extern bool checked_teamplay;
extern FLAG_S flags[MAX_FLAGS];
extern int num_flags;
extern bot_weapon_t weapon_defs[MAX_WEAPONS];
extern edict_t *holywars_saint;
extern int halo_status;
extern int holywars_gamemode;
// SET THIS UP BASED ON MOD!!!
int max_drop_height = 800;
static FILE *fp;
char welcome_msg[80];
int x_welcome_msg_len = 42;
unsigned char x_welcome_msg[] = {
'H'^0x5a, 'P'^0xa5, 'B'^0x5a, ' '^0xa5, 'b'^0x5a, 'o'^0xa5, 't'^0x5a, ' '^0xa5,
'-'^0x5a, ' '^0xa5, 'h'^0x5a, 't'^0xa5, 't'^0x5a, 'p'^0xa5, ':'^0x5a, '/'^0xa5,
'/'^0x5a, 'p'^0xa5, 'l'^0x5a, 'a'^0xa5, 'n'^0x5a, 'e'^0xa5, 't'^0x5a, 'h'^0xa5,
'a'^0x5a, 'l'^0xa5, 'f'^0x5a, 'l'^0xa5, 'i'^0x5a, 'f'^0xa5, 'e'^0x5a, '.'^0xa5,
'c'^0x5a, 'o'^0xa5, 'm'^0x5a, '/'^0xa5, 'b'^0x5a, 'o'^0xa5, 't'^0x5a, 'm'^0xa5,
'a'^0x5a, 'n'^0xa5};
extern void BotCheckTeamplay(void);
void welcome_init(void)
{
for (int i=0; i < x_welcome_msg_len; i++)
{
if ((i % 2) == 0)
welcome_msg[i] = x_welcome_msg[i]^0x5a;
else
welcome_msg[i] = x_welcome_msg[i]^0xa5;
}
welcome_msg[x_welcome_msg_len] = 0;
}
void BotFixIdealPitch(edict_t *pEdict)
{
// check for wrap around of angle...
if (pEdict->v.idealpitch > 180)
pEdict->v.idealpitch -= 360;
if (pEdict->v.idealpitch < -180)
pEdict->v.idealpitch += 360;
}
// returns the number of degrees left to turn toward ideal pitch...
float BotChangePitch( bot_t *pBot, float speed )
{
edict_t *pEdict = pBot->pEdict;
float ideal;
float current;
float current_180; // current +/- 180 degrees
float diff;
// turn from the current v_angle pitch to the idealpitch by selecting
// the quickest way to turn to face that direction
current = pEdict->v.v_angle.x;
ideal = pEdict->v.idealpitch;
// find the difference in the current and ideal angle
diff = fabs(current - ideal);
speed = speed * pBot->f_frame_time; // angles per second
// check if difference is less than the max degrees per turn
if (diff < speed)
speed = diff; // just need to turn a little bit (less than max)
// here we have four cases, both angle positive, one positive and
// the other negative, one negative and the other positive, or
// both negative. handle each case separately...
if ((current >= 0) && (ideal >= 0)) // both positive
{
if (current > ideal)
current -= speed;
else
current += speed;
}
else if ((current >= 0) && (ideal < 0))
{
current_180 = current - 180;
if (current_180 > ideal)
current += speed;
else
current -= speed;
}
else if ((current < 0) && (ideal >= 0))
{
current_180 = current + 180;
if (current_180 > ideal)
current += speed;
else
current -= speed;
}
else // (current < 0) && (ideal < 0) both negative
{
if (current > ideal)
current -= speed;
else
current += speed;
}
// check for wrap around of angle...
if (current > 180)
current -= 360;
if (current < -180)
current += 360;
pEdict->v.v_angle.x = current;
return diff; // return number of degrees left to turn
}
void BotFixIdealYaw(edict_t *pEdict)
{
// check for wrap around of angle...
if (pEdict->v.ideal_yaw > 180)
pEdict->v.ideal_yaw -= 360;
if (pEdict->v.ideal_yaw < -180)
pEdict->v.ideal_yaw += 360;
}
// returns the number of degrees left to turn toward ideal yaw...
float BotChangeYaw( bot_t *pBot, float speed )
{
edict_t *pEdict = pBot->pEdict;
float ideal;
float current;
float current_180; // current +/- 180 degrees
float diff;
// turn from the current v_angle yaw to the ideal_yaw by selecting
// the quickest way to turn to face that direction
current = pEdict->v.v_angle.y;
ideal = pEdict->v.ideal_yaw;
// find the difference in the current and ideal angle
diff = fabs(current - ideal);
// speed that we can turn during this frame...
speed = speed * pBot->f_frame_time;
// check if difference is less than the max degrees per turn
if (diff < speed)
speed = diff; // just need to turn a little bit (less than max)
// here we have four cases, both angle positive, one positive and
// the other negative, one negative and the other positive, or
// both negative. handle each case separately...
if ((current >= 0) && (ideal >= 0)) // both positive
{
if (current > ideal)
current -= speed;
else
current += speed;
}
else if ((current >= 0) && (ideal < 0))
{
current_180 = current - 180;
if (current_180 > ideal)
current += speed;
else
current -= speed;
}
else if ((current < 0) && (ideal >= 0))
{
current_180 = current + 180;
if (current_180 > ideal)
current += speed;
else
current -= speed;
}
else // (current < 0) && (ideal < 0) both negative
{
if (current > ideal)
current -= speed;
else
current += speed;
}
// check for wrap around of angle...
if (current > 180)
current -= 360;
if (current < -180)
current += 360;
pEdict->v.v_angle.y = current;
return diff; // return number of degrees left to turn
}
bool BotFindWaypoint( bot_t *pBot )
{
int index, select_index;
int team;
PATH *pPath = NULL;
int path_index;
float distance, min_distance[3];
int min_index[3];
edict_t *pEdict = pBot->pEdict;
if (mod_id == FRONTLINE_DLL)
team = pBot->defender;
else
team = UTIL_GetTeam(pEdict);
for (index=0; index < 3; index++)
{
min_distance[index] = 9999.0;
min_index[index] = -1;
}
index = WaypointFindPath(&pPath, &path_index, pBot->curr_waypoint_index, team);
while (index != -1)
{
// if index is not a current or recent previous waypoint...
if ((index != pBot->curr_waypoint_index) &&
(index != pBot->prev_waypoint_index[0]) &&
(index != pBot->prev_waypoint_index[1]) &&
(index != pBot->prev_waypoint_index[2]) &&
(index != pBot->prev_waypoint_index[3]) &&
(index != pBot->prev_waypoint_index[4]))
{
// find the distance from the bot to this waypoint
distance = (pEdict->v.origin - waypoints[index].origin).Length();
if (distance < min_distance[0])
{
min_distance[2] = min_distance[1];
min_index[2] = min_index[1];
min_distance[1] = min_distance[0];
min_index[1] = min_index[0];
min_distance[0] = distance;
min_index[0] = index;
}
else if (distance < min_distance [1])
{
min_distance[2] = min_distance[1];
min_index[2] = min_index[1];
min_distance[1] = distance;
min_index[1] = index;
}
else if (distance < min_distance[2])
{
min_distance[2] = distance;
min_index[2] = index;
}
}
// find the next path to a waypoint
index = WaypointFindPath(&pPath, &path_index, pBot->curr_waypoint_index, team);
}
select_index = -1;
// about 20% of the time choose a waypoint at random
// (don't do this any more often than every 10 seconds)
if ((RANDOM_LONG(1, 100) <= 20) &&
(pBot->f_random_waypoint_time <= gpGlobals->time))
{
pBot->f_random_waypoint_time = gpGlobals->time + 10.0;
if (min_index[2] != -1)
index = RANDOM_LONG(0, 2);
else if (min_index[1] != -1)
index = RANDOM_LONG(0, 1);
else if (min_index[0] != -1)
index = 0;
else
return FALSE; // no waypoints found!
select_index = min_index[index];
}
else
{
// use the closest waypoint that has been recently used
select_index = min_index[0];
}
if (select_index != -1) // was a waypoint found?
{
pBot->prev_waypoint_index[4] = pBot->prev_waypoint_index[3];
pBot->prev_waypoint_index[3] = pBot->prev_waypoint_index[2];
pBot->prev_waypoint_index[2] = pBot->prev_waypoint_index[1];
pBot->prev_waypoint_index[1] = pBot->prev_waypoint_index[0];
pBot->prev_waypoint_index[0] = pBot->curr_waypoint_index;
pBot->curr_waypoint_index = select_index;
pBot->waypoint_origin = waypoints[select_index].origin;
pBot->f_waypoint_time = gpGlobals->time;
return TRUE;
}
return FALSE; // couldn't find a waypoint
}
bool BotHeadTowardWaypoint( bot_t *pBot )
{
int i;
Vector v_src, v_dest;
TraceResult tr;
int index;
bool status;
float waypoint_distance, min_distance;
int team, skin;
float distance;
float pause_time = 0.0;
edict_t *pent;
bool bot_has_flag = FALSE;
bool touching;
edict_t *pEdict = pBot->pEdict;
if (!checked_teamplay) // check for team play...
BotCheckTeamplay();
// is team play enabled (or is it Counter-Strike)?
if (is_team_play)
team = UTIL_GetTeam(pEdict);
else
team = -1; // not team play (all waypoints are valid for everyone)
// check if the bot has been trying to get to this waypoint for a while...
if ((pBot->f_waypoint_time + 5.0) < gpGlobals->time)
{
pBot->curr_waypoint_index = -1; // forget about this waypoint
pBot->waypoint_goal = -1; // also forget about a goal
}
// check if a goal item exists...
if (mod_id == TFC_DLL)
{
pent = NULL;
while ((pent = UTIL_FindEntityByClassname( pent, "item_tfgoal" )) != NULL)
{
if (pent->v.owner == pEdict) // is this bot carrying the item?
{
// we are carrying the flag/card/ball
bot_has_flag = TRUE;
break; // break out of while loop
}
else if (FInViewCone( &pent->v.origin, pEdict ) && // can bot see it?
FVisible( pent->v.origin, pEdict))
{
// check if the flag has an owner...
if (pent->v.owner != NULL)
{
// get the team for the owner of the flag...
int player_team = UTIL_GetTeam(pent->v.owner);
// attack if not our team and not allies team...
if ((player_team != team) &&
!(team_allies[team] & (1<<player_team)))
{
// kill the man with the flag!
pBot->pBotEnemy = pent->v.owner;
pBot->waypoint_goal = -1; // forget the goal (if there is one)
return TRUE;
}
}
else
{
// check if it matches one of the flags...
for (i=0; i < num_flags; i++)
{
// is the flag for this team (or any team)?
if ((flags[i].edict == pent) &&
((flags[i].team_no == (team+1)) || (flags[i].team_no == 0)))
{
// find the nearest waypoint to the ball...
index = WaypointFindNearest(pent->v.origin, pEdict, 500, team);
if (index == -1)
{
// no waypoint is close enough, just head straight towards the ball
Vector v_flag = pent->v.origin - pEdict->v.origin;
Vector bot_angles = UTIL_VecToAngles( v_flag );
pEdict->v.ideal_yaw = bot_angles.y;
BotFixIdealYaw(pEdict);
return TRUE;
}
else
{
waypoint_distance = (waypoints[index].origin - pent->v.origin).Length();
distance = (pent->v.origin - pEdict->v.origin).Length();
// is the bot closer to the ball than the waypoint is?
if (distance < waypoint_distance)
{
// just head towards the ball
Vector v_flag = pent->v.origin - pEdict->v.origin;
Vector bot_angles = UTIL_VecToAngles( v_flag );
pEdict->v.ideal_yaw = bot_angles.y;
BotFixIdealYaw(pEdict);
return TRUE;
}
else
{
// head towards this waypoint
pBot->waypoint_goal = index;
// remember where the ball is located...
pBot->waypoint_near_flag = TRUE;
pBot->waypoint_flag_origin = pent->v.origin;
}
}
}
}
}
}
}
}
else if ((mod_id == GEARBOX_DLL) && (pent_info_ctfdetect != NULL))
{
pent = NULL;
while ((pent = UTIL_FindEntityByClassname( pent, "item_ctfflag" )) != NULL)
{
// is this bot carrying the item? (after capture bug fix by Whistler)
if ((pent->v.owner == pEdict) && (pent->v.origin == pEdict->v.origin))
{
// we are carrying the flag
bot_has_flag = TRUE;
break; // break out of while loop
}
else if (FInViewCone( &pent->v.origin, pEdict ) &&
FVisible( pent->v.origin, pEdict))
{
// the bot can see it, check what type of model it is...
skin = pent->v.skin;
if (skin == 0) // Opposing Force team (these are BACKASSWARDS!)
skin = 1;
else if (skin == 1) // Black Mesa team
skin = 0;
// see if the flag matches the bot's team...
if (skin == team)
{
// is and enemy carrying our flag/card?
if (pent->v.owner != NULL)
{
// kill the man with the flag/card!
pBot->pBotEnemy = pent->v.owner;
pBot->waypoint_goal = -1; // forget the goal (if there is one)
return TRUE;
}
}
else // flag/card is for another team!
{
// check if someone is NOT carrying the flag/card...
if (pent->v.owner == NULL)
{
// find the nearest waypoint to the flag/card...
index = WaypointFindNearest(pent->v.origin, pEdict, 500, team);
if (index == -1)
{
// no waypoint is close enough, just head straight towards the flag/card
Vector v_flag = pent->v.origin - pEdict->v.origin;
Vector bot_angles = UTIL_VecToAngles( v_flag );
pEdict->v.ideal_yaw = bot_angles.y;
BotFixIdealYaw(pEdict);
return TRUE;
}
else
{
waypoint_distance = (waypoints[index].origin - pent->v.origin).Length();
distance = (pent->v.origin - pEdict->v.origin).Length();
// is the bot closer to the flag/card than the waypoint is?
if (distance < waypoint_distance)
{
// just head towards the flag/card
Vector v_flag = pent->v.origin - pEdict->v.origin;
Vector bot_angles = UTIL_VecToAngles( v_flag );
pEdict->v.ideal_yaw = bot_angles.y;
BotFixIdealYaw(pEdict);
return TRUE;
}
else
{
// head towards this waypoint
pBot->waypoint_goal = index;
// remember where the flag/card is located...
pBot->waypoint_near_flag = TRUE;
pBot->waypoint_flag_origin = pent->v.origin;
}
}
}
}
}
}
}
else if (mod_id == FRONTLINE_DLL)
{
if ((pBot->waypoint_goal != -1) && // does bot have a goal?
(pBot->pCaptureEdict))
{
int team = UTIL_GetTeam(pEdict); // skin and team must match
if (!pBot->defender) // if attacker...
{
if (pBot->pCaptureEdict->v.skin == team) // was point captured?
{
pBot->waypoint_goal = -1;
}
}
else
{
if (pBot->pCaptureEdict->v.skin != team) // was point captured?
{
pBot->waypoint_goal = -1;
}
}
}
}
else if (mod_id == HOLYWARS_DLL)
{
if (pBot->waypoint_goal != -1)
{
// is the bot currently heading toward halo AND halo is gone?
if ((waypoints[pBot->waypoint_goal].flags & W_FL_FLAG) &&
(holywars_saint != NULL) && (holywars_gamemode == 1))
{
pBot->waypoint_goal = -1;
}
}
}
// check if we need to find a waypoint...
if (pBot->curr_waypoint_index == -1)
{
pBot->waypoint_top_of_ladder = FALSE;
// did we just come off of a ladder or are we underwater?
if (((pBot->f_end_use_ladder_time + 2.0) > gpGlobals->time) ||
(pBot->pEdict->v.waterlevel == 3))
{
// find the nearest visible waypoint
if (mod_id == FRONTLINE_DLL)
i = WaypointFindNearest(pEdict, REACHABLE_RANGE, pBot->defender);
else
i = WaypointFindNearest(pEdict, REACHABLE_RANGE, team);
}
else
{
// find the nearest reachable waypoint
if (mod_id == FRONTLINE_DLL)
i = WaypointFindReachable(pEdict, REACHABLE_RANGE, pBot->defender);
else
i = WaypointFindReachable(pEdict, REACHABLE_RANGE, team);
}
if (i == -1)
{
pBot->curr_waypoint_index = -1;
return FALSE;
}
pBot->curr_waypoint_index = i;
pBot->waypoint_origin = waypoints[i].origin;
pBot->f_waypoint_time = gpGlobals->time;
}
else
{
// skip this part if bot is trying to get out of water...
if (pBot->f_exit_water_time < gpGlobals->time)
{
// check if we can still see our target waypoint...
v_src = pEdict->v.origin + pEdict->v.view_ofs;
v_dest = waypoints[pBot->curr_waypoint_index].origin;
// trace a line from bot's eyes to destination...
UTIL_TraceLine( v_src, v_dest, ignore_monsters,
pEdict->v.pContainingEntity, &tr );
// check if line of sight to object is blocked (i.e. not visible)
if (tr.flFraction < 1.0)
{
// did we just come off of a ladder or are we under water?
if (((pBot->f_end_use_ladder_time + 2.0) > gpGlobals->time) ||
(pBot->pEdict->v.waterlevel == 3))
{
// find the nearest visible waypoint
if (mod_id == FRONTLINE_DLL)
i = WaypointFindNearest(pEdict, REACHABLE_RANGE, pBot->defender);
else
i = WaypointFindNearest(pEdict, REACHABLE_RANGE, team);
}
else
{
// find the nearest reachable waypoint
if (mod_id == FRONTLINE_DLL)
i = WaypointFindReachable(pEdict, REACHABLE_RANGE, pBot->defender);
else
i = WaypointFindReachable(pEdict, REACHABLE_RANGE, team);
}
if (i == -1)
{
pBot->curr_waypoint_index = -1;
return FALSE;
}
pBot->curr_waypoint_index = i;
pBot->waypoint_origin = waypoints[i].origin;
pBot->f_waypoint_time = gpGlobals->time;
}
}
}
// find the distance to the target waypoint
waypoint_distance = (pEdict->v.origin - pBot->waypoint_origin).Length();
// set the minimum distance from waypoint to be considered "touching" it
min_distance = 50.0;
// if this is a crouch waypoint, bot must be fairly close...
if (waypoints[pBot->curr_waypoint_index].flags & W_FL_CROUCH)
min_distance = 20.0;
if (waypoints[pBot->curr_waypoint_index].flags & W_FL_JUMP)
min_distance = 25.0;
if (waypoints[pBot->curr_waypoint_index].flags & W_FL_SENTRYGUN)
min_distance = 20.0;
if (waypoints[pBot->curr_waypoint_index].flags & W_FL_DISPENSER)
min_distance = 20.0;
// if this is a ladder waypoint, bot must be fairly close to get on ladder
if (waypoints[pBot->curr_waypoint_index].flags & W_FL_LADDER)
min_distance = 20.0;
// if this is a defenders waypoint, bot must be fairly close...
if ((mod_id == FRONTLINE_DLL) &&
(waypoints[pBot->curr_waypoint_index].flags & W_FL_FLF_DEFEND))
min_distance = 20.0;
// if trying to get out of water, need to get very close to waypoint...
if (pBot->f_exit_water_time >= gpGlobals->time)
min_distance = 20.0;
touching = FALSE;
// did the bot run past the waypoint? (prevent the loop-the-loop problem)
if ((pBot->prev_waypoint_distance > 1.0) &&
(waypoint_distance > pBot->prev_waypoint_distance))
touching = TRUE;
// are we close enough to a target waypoint...
if (waypoint_distance < min_distance)
touching = TRUE;
// save current distance as previous
pBot->prev_waypoint_distance = waypoint_distance;
if (touching)
{
bool waypoint_found = FALSE;
pBot->prev_waypoint_distance = 0.0;
// check if the waypoint is a door waypoint
if (waypoints[pBot->curr_waypoint_index].flags & W_FL_DOOR)
{
pBot->f_dont_avoid_wall_time = gpGlobals->time + 5.0;
}
// check if the next waypoint is a jump waypoint...
if (waypoints[pBot->curr_waypoint_index].flags & W_FL_JUMP)
{
pEdict->v.button |= IN_JUMP; // jump here
}
// check if the waypoint is a sniper waypoint...
if (waypoints[pBot->curr_waypoint_index].flags & W_FL_SNIPER)
{
if (((mod_id == TFC_DLL) && (pEdict->v.playerclass == TFC_CLASS_SNIPER)) ||
(mod_id != TFC_DLL))
{
int aim_index;
aim_index = WaypointFindNearestAiming(waypoints[pBot->curr_waypoint_index].origin);
if (aim_index != -1)
{
Vector v_aim = waypoints[aim_index].origin - waypoints[pBot->curr_waypoint_index].origin;
Vector aim_angles = UTIL_VecToAngles( v_aim );
pEdict->v.ideal_yaw = aim_angles.y;
BotFixIdealYaw(pEdict);
}
pBot->f_pause_time = gpGlobals->time + RANDOM_FLOAT(20.0, 30.0);
// fix f_waypoint_time so bot won't think it is stuck
pBot->f_waypoint_time = pBot->f_pause_time;
return TRUE;
}
}
// check if the bot has reached the goal waypoint...
if (pBot->curr_waypoint_index == pBot->waypoint_goal)
{
pBot->waypoint_goal = -1; // forget this goal waypoint
if (pBot->waypoint_near_flag)
{
pBot->waypoint_near_flag = FALSE;
// just head towards the flag/card/ball
Vector v_flag = pBot->waypoint_flag_origin - pEdict->v.origin;
Vector bot_angles = UTIL_VecToAngles( v_flag );
pEdict->v.ideal_yaw = bot_angles.y;
BotFixIdealYaw(pEdict);
return TRUE;
}
// see if this waypoint is a sentry gun waypoint...
if ((waypoints[pBot->curr_waypoint_index].flags & W_FL_SENTRYGUN) &&
(mod_id == TFC_DLL) && (pEdict->v.playerclass == TFC_CLASS_ENGINEER))
{
if (pBot->m_rgAmmo[weapon_defs[TF_WEAPON_SPANNER].iAmmo1] >= 130)
{
int aim_index;
aim_index = WaypointFindNearestAiming(waypoints[pBot->curr_waypoint_index].origin);
if (aim_index != -1)
{
Vector v_aim = waypoints[aim_index].origin - waypoints[pBot->curr_waypoint_index].origin;
Vector aim_angles = UTIL_VecToAngles( v_aim );
pEdict->v.ideal_yaw = aim_angles.y;
BotFixIdealYaw(pEdict);
pBot->b_build_sentrygun = TRUE;
pBot->sentrygun_waypoint = pBot->curr_waypoint_index;
pBot->f_look_for_waypoint_time = gpGlobals->time + 5.0;
return TRUE;
}
}
}
// see if this waypoint is a dispenser waypoint...
if ((waypoints[pBot->curr_waypoint_index].flags & W_FL_DISPENSER) &&
(mod_id == TFC_DLL) && (pEdict->v.playerclass == TFC_CLASS_ENGINEER))
{
// does bot have enough metal to build a dispenser?
if (pBot->m_rgAmmo[weapon_defs[TF_WEAPON_SPANNER].iAmmo1] >= 100)
{
int aim_index;
aim_index = WaypointFindNearestAiming(waypoints[pBot->curr_waypoint_index].origin);
if (aim_index != -1)
{
Vector v_aim = waypoints[aim_index].origin - waypoints[pBot->curr_waypoint_index].origin;
Vector aim_angles = UTIL_VecToAngles( v_aim );
pEdict->v.ideal_yaw = aim_angles.y;
BotFixIdealYaw(pEdict);
pBot->b_build_dispenser = TRUE;
pBot->dispenser_waypoint = pBot->curr_waypoint_index;
pBot->f_look_for_waypoint_time = gpGlobals->time + 5.0;
return TRUE;
}
}
}
if ((mod_id == FRONTLINE_DLL) &&
(waypoints[pBot->curr_waypoint_index].flags & W_FL_FLF_CAP))
{
// it's a capture point
pent = NULL;
while ((pent = UTIL_FindEntityInSphere( pent, pEdict->v.origin, 100.0 )) != NULL)
{
if (strcmp(STRING(pent->v.classname), "capture_point") == 0)
{
if (pent->v.skin != (1 - team)) // already captured?
return TRUE; // can't do anything here, just return
// turn to face the capture entity
Vector v_aim = pent->v.origin - pEdict->v.origin;
Vector aim_angles = UTIL_VecToAngles( v_aim );
pEdict->v.ideal_yaw = aim_angles.y;
BotFixIdealYaw(pEdict);
return TRUE;
}
}
}
if ((mod_id == FRONTLINE_DLL) &&
(waypoints[pBot->curr_waypoint_index].flags & W_FL_FLF_DEFEND))
{
// it's a defend point
int aim_index;
aim_index = WaypointFindNearestAiming(waypoints[pBot->curr_waypoint_index].origin);
if (aim_index != -1)
{
Vector v_aim = waypoints[aim_index].origin - waypoints[pBot->curr_waypoint_index].origin;
Vector aim_angles = UTIL_VecToAngles( v_aim );
pEdict->v.ideal_yaw = aim_angles.y;
BotFixIdealYaw(pEdict);
pBot->f_pause_time = gpGlobals->time + RANDOM_FLOAT(30.0, 45.0);
// fix f_waypoint_time so bot won't think it is stuck
pBot->f_waypoint_time = pBot->f_pause_time;
return TRUE;
}
}
}
// check if the bot is carrying the flag/card/ball...
if (bot_has_flag)
{
pBot->bot_has_flag = TRUE;
// find the nearest flag goal waypoint...
index = WaypointFindNearestGoal(pEdict, pBot->curr_waypoint_index,
team, W_FL_FLAG_GOAL);
pBot->waypoint_goal = index; // goal index or -1
pBot->waypoint_near_flag = FALSE;
}
else
{
pBot->bot_has_flag = FALSE;
}
// test special case of bot underwater and close to surface...
if (pBot->pEdict->v.waterlevel == 3)
{
Vector v_src, v_dest;
TraceResult tr;
int contents;
// trace a line straight up 100 units...
v_src = pEdict->v.origin;
v_dest = v_src;
v_dest.z = v_dest.z + 100.0;
// trace a line to destination...
UTIL_TraceLine( v_src, v_dest, ignore_monsters,
pEdict->v.pContainingEntity, &tr );
if (tr.flFraction >= 1.0)
{
// find out what the contents is of the end of the trace...
contents = POINT_CONTENTS( tr.vecEndPos );
// check if the trace endpoint is in open space...
if (contents == CONTENTS_EMPTY)
{
// find the nearest visible waypoint
if (mod_id == FRONTLINE_DLL)
i = WaypointFindNearest(tr.vecEndPos, pEdict, 100, pBot->defender);
else
i = WaypointFindNearest(tr.vecEndPos, pEdict, 100, team);
if (i != -1)
{
waypoint_found = TRUE;
pBot->curr_waypoint_index = i;
pBot->waypoint_origin = waypoints[i].origin;
pBot->f_waypoint_time = gpGlobals->time;
// keep trying to exit water for next 3 seconds
pBot->f_exit_water_time = gpGlobals->time + 3.0;
}
}
}
}
// if the bot doesn't have a goal waypoint then pick one...
if ((pBot->waypoint_goal == -1) &&
(pBot->f_waypoint_goal_time < gpGlobals->time))
{
// don't pick a goal more often than every 10 seconds...