This repository has been archived by the owner on Sep 4, 2019. It is now read-only.
/
ai_dmq3.c
5464 lines (5218 loc) · 160 KB
/
ai_dmq3.c
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
/*
===========================================================================
Copyright (C) 1999-2005 Id Software, Inc.
This file is part of Quake III Arena source code.
Quake III Arena source code 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.
Quake III Arena source code 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.
You should have received a copy of the GNU General Public License
along with Foobar; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
// RIM_NDK WARNING!!!! Many function calls have had G_ prepended to them as defined in g_local.h
//
/*****************************************************************************
* name: ai_dmq3.c
*
* desc: Quake3 bot AI
*
* $Archive: /MissionPack/code/game/ai_dmq3.c $
*
*****************************************************************************/
#include "g_local.h"
#include "botlib.h"
#include "be_aas.h"
#include "be_ea.h"
#include "be_ai_char.h"
#include "be_ai_chat.h"
#include "be_ai_gen.h"
#include "be_ai_goal.h"
#include "be_ai_move.h"
#include "be_ai_weap.h"
//
#include "ai_main.h"
#include "ai_dmq3.h"
#include "ai_chat.h"
#include "ai_cmd.h"
#include "ai_dmnet.h"
#include "ai_team.h"
//
#include "chars.h" //characteristics
#include "inv.h" //indexes into the inventory
#include "syn.h" //synonyms
#include "match.h" //string matching types and vars
// for the voice chats
#include "../../ui/menudef.h" // sos001205 - for q3_ui also
// from aasfile.h
#define AREACONTENTS_MOVER 1024
#define AREACONTENTS_MODELNUMSHIFT 24
#define AREACONTENTS_MAXMODELNUM 0xFF
#define AREACONTENTS_MODELNUM (AREACONTENTS_MAXMODELNUM << AREACONTENTS_MODELNUMSHIFT)
#define IDEAL_ATTACKDIST 140
#define MAX_WAYPOINTS 128
//
bot_waypoint_t botai_waypoints[MAX_WAYPOINTS];
bot_waypoint_t *botai_freewaypoints;
//NOTE: not using a cvars which can be updated because the game should be reloaded anyway
int gametype; //game type
int maxclients; //maximum number of clients
vmCvar_t bot_grapple;
vmCvar_t bot_rocketjump;
vmCvar_t bot_fastchat;
vmCvar_t bot_nochat;
vmCvar_t bot_testrchat;
vmCvar_t bot_challenge;
vmCvar_t bot_predictobstacles;
vmCvar_t g_spSkill;
extern vmCvar_t g_bot_developer;
vec3_t lastteleport_origin; //last teleport event origin
float lastteleport_time; //last teleport event time
int max_bspmodelindex; //maximum BSP model index
//CTF flag goals
bot_goal_t ctf_redflag;
bot_goal_t ctf_blueflag;
#ifdef MISSIONPACK
bot_goal_t ctf_neutralflag;
bot_goal_t redobelisk;
bot_goal_t blueobelisk;
bot_goal_t neutralobelisk;
#endif
#define MAX_ALTROUTEGOALS 32
int altroutegoals_setup;
aas_altroutegoal_t red_altroutegoals[MAX_ALTROUTEGOALS];
int red_numaltroutegoals;
aas_altroutegoal_t blue_altroutegoals[MAX_ALTROUTEGOALS];
int blue_numaltroutegoals;
/*
==================
BotSetUserInfo
==================
*/
void BotSetUserInfo(bot_state_t *bs, char *key, char *value) {
char userinfo[MAX_INFO_STRING];
G_trap_GetUserinfo(bs->client, userinfo, sizeof(userinfo));
Info_SetValueForKey(userinfo, key, value);
G_trap_SetUserinfo(bs->client, userinfo);
ClientUserinfoChanged( bs->client );
}
/*
==================
BotCTFCarryingFlag
==================
*/
int BotCTFCarryingFlag(bot_state_t *bs) {
if (gametype != GT_CTF) return CTF_FLAG_NONE;
if (bs->inventory[INVENTORY_REDFLAG] > 0) return CTF_FLAG_RED;
else if (bs->inventory[INVENTORY_BLUEFLAG] > 0) return CTF_FLAG_BLUE;
return CTF_FLAG_NONE;
}
/*
==================
BotTeam
==================
*/
int BotTeam(bot_state_t *bs) {
char info[1024];
if (bs->client < 0 || bs->client >= MAX_CLIENTS) {
//BotAI_Print(PRT_ERROR, "BotCTFTeam: client out of range\n");
return qfalse;
}
G_trap_GetConfigstring(CS_PLAYERS+bs->client, info, sizeof(info));
//
if (atoi(Info_ValueForKey(info, "t")) == TEAM_RED) return TEAM_RED;
else if (atoi(Info_ValueForKey(info, "t")) == TEAM_BLUE) return TEAM_BLUE;
return TEAM_FREE;
}
/*
==================
BotOppositeTeam
==================
*/
int BotOppositeTeam(bot_state_t *bs) {
switch(BotTeam(bs)) {
case TEAM_RED: return TEAM_BLUE;
case TEAM_BLUE: return TEAM_RED;
default: return TEAM_FREE;
}
}
/*
==================
BotEnemyFlag
==================
*/
bot_goal_t *BotEnemyFlag(bot_state_t *bs) {
if (BotTeam(bs) == TEAM_RED) {
return &ctf_blueflag;
}
else {
return &ctf_redflag;
}
}
/*
==================
BotTeamFlag
==================
*/
bot_goal_t *BotTeamFlag(bot_state_t *bs) {
if (BotTeam(bs) == TEAM_RED) {
return &ctf_redflag;
}
else {
return &ctf_blueflag;
}
}
/*
==================
EntityIsDead
==================
*/
qboolean EntityIsDead(aas_entityinfo_t *entinfo) {
playerState_t ps;
if (entinfo->number >= 0 && entinfo->number < MAX_CLIENTS) {
//retrieve the current client state
BotAI_GetClientState( entinfo->number, &ps );
if (ps.pm_type != PM_NORMAL) return qtrue;
}
return qfalse;
}
/*
==================
EntityCarriesFlag
==================
*/
qboolean EntityCarriesFlag(aas_entityinfo_t *entinfo) {
if ( entinfo->powerups & ( 1 << PW_REDFLAG ) )
return qtrue;
if ( entinfo->powerups & ( 1 << PW_BLUEFLAG ) )
return qtrue;
#ifdef MISSIONPACK
if ( entinfo->powerups & ( 1 << PW_NEUTRALFLAG ) )
return qtrue;
#endif
return qfalse;
}
/*
==================
EntityIsInvisible
==================
*/
qboolean EntityIsInvisible(aas_entityinfo_t *entinfo) {
// the flag is always visible
if (EntityCarriesFlag(entinfo)) {
return qfalse;
}
if (entinfo->powerups & (1 << PW_INVIS)) {
return qtrue;
}
return qfalse;
}
/*
==================
EntityIsShooting
==================
*/
qboolean EntityIsShooting(aas_entityinfo_t *entinfo) {
if (entinfo->flags & EF_FIRING) {
return qtrue;
}
return qfalse;
}
/*
==================
EntityIsChatting
==================
*/
qboolean EntityIsChatting(aas_entityinfo_t *entinfo) {
if (entinfo->flags & EF_TALK) {
return qtrue;
}
return qfalse;
}
/*
==================
EntityHasQuad
==================
*/
qboolean EntityHasQuad(aas_entityinfo_t *entinfo) {
if (entinfo->powerups & (1 << PW_QUAD)) {
return qtrue;
}
return qfalse;
}
#ifdef MISSIONPACK
/*
==================
EntityHasKamikze
==================
*/
qboolean EntityHasKamikaze(aas_entityinfo_t *entinfo) {
if (entinfo->flags & EF_KAMIKAZE) {
return qtrue;
}
return qfalse;
}
/*
==================
EntityCarriesCubes
==================
*/
qboolean EntityCarriesCubes(aas_entityinfo_t *entinfo) {
entityState_t state;
if (gametype != GT_HARVESTER)
return qfalse;
//FIXME: get this info from the aas_entityinfo_t ?
BotAI_GetEntityState(entinfo->number, &state);
if (state.generic1 > 0)
return qtrue;
return qfalse;
}
/*
==================
Bot1FCTFCarryingFlag
==================
*/
int Bot1FCTFCarryingFlag(bot_state_t *bs) {
if (gametype != GT_1FCTF) return qfalse;
if (bs->inventory[INVENTORY_NEUTRALFLAG] > 0) return qtrue;
return qfalse;
}
/*
==================
BotHarvesterCarryingCubes
==================
*/
int BotHarvesterCarryingCubes(bot_state_t *bs) {
if (gametype != GT_HARVESTER) return qfalse;
if (bs->inventory[INVENTORY_REDCUBE] > 0) return qtrue;
if (bs->inventory[INVENTORY_BLUECUBE] > 0) return qtrue;
return qfalse;
}
#endif
/*
==================
BotRememberLastOrderedTask
==================
*/
void BotRememberLastOrderedTask(bot_state_t *bs) {
if (!bs->ordered) {
return;
}
bs->lastgoal_decisionmaker = bs->decisionmaker;
bs->lastgoal_ltgtype = bs->ltgtype;
memcpy(&bs->lastgoal_teamgoal, &bs->teamgoal, sizeof(bot_goal_t));
bs->lastgoal_teammate = bs->teammate;
}
/*
==================
BotSetTeamStatus
==================
*/
void BotSetTeamStatus(bot_state_t *bs) {
#ifdef MISSIONPACK
int teamtask;
aas_entityinfo_t entinfo;
teamtask = TEAMTASK_PATROL;
switch(bs->ltgtype) {
case LTG_TEAMHELP:
break;
case LTG_TEAMACCOMPANY:
BotEntityInfo(bs->teammate, &entinfo);
if ( ( (gametype == GT_CTF || gametype == GT_1FCTF) && EntityCarriesFlag(&entinfo))
|| ( gametype == GT_HARVESTER && EntityCarriesCubes(&entinfo)) ) {
teamtask = TEAMTASK_ESCORT;
}
else {
teamtask = TEAMTASK_FOLLOW;
}
break;
case LTG_DEFENDKEYAREA:
teamtask = TEAMTASK_DEFENSE;
break;
case LTG_GETFLAG:
teamtask = TEAMTASK_OFFENSE;
break;
case LTG_RUSHBASE:
teamtask = TEAMTASK_DEFENSE;
break;
case LTG_RETURNFLAG:
teamtask = TEAMTASK_RETRIEVE;
break;
case LTG_CAMP:
case LTG_CAMPORDER:
teamtask = TEAMTASK_CAMP;
break;
case LTG_PATROL:
teamtask = TEAMTASK_PATROL;
break;
case LTG_GETITEM:
teamtask = TEAMTASK_PATROL;
break;
case LTG_KILL:
teamtask = TEAMTASK_PATROL;
break;
case LTG_HARVEST:
teamtask = TEAMTASK_OFFENSE;
break;
case LTG_ATTACKENEMYBASE:
teamtask = TEAMTASK_OFFENSE;
break;
default:
teamtask = TEAMTASK_PATROL;
break;
}
BotSetUserInfo(bs, "teamtask", va("%d", teamtask));
#endif
}
/*
==================
BotSetLastOrderedTask
==================
*/
int BotSetLastOrderedTask(bot_state_t *bs) {
if (gametype == GT_CTF) {
// don't go back to returning the flag if it's at the base
if ( bs->lastgoal_ltgtype == LTG_RETURNFLAG ) {
if ( BotTeam(bs) == TEAM_RED ) {
if ( bs->redflagstatus == 0 ) {
bs->lastgoal_ltgtype = 0;
}
}
else {
if ( bs->blueflagstatus == 0 ) {
bs->lastgoal_ltgtype = 0;
}
}
}
}
if ( bs->lastgoal_ltgtype ) {
bs->decisionmaker = bs->lastgoal_decisionmaker;
bs->ordered = qtrue;
bs->ltgtype = bs->lastgoal_ltgtype;
memcpy(&bs->teamgoal, &bs->lastgoal_teamgoal, sizeof(bot_goal_t));
bs->teammate = bs->lastgoal_teammate;
bs->teamgoal_time = FloatTime() + 300;
BotSetTeamStatus(bs);
//
if ( gametype == GT_CTF ) {
if ( bs->ltgtype == LTG_GETFLAG ) {
bot_goal_t *tb, *eb;
int tt, et;
tb = BotTeamFlag(bs);
eb = BotEnemyFlag(bs);
tt = G_trap_AAS_AreaTravelTimeToGoalArea(bs->areanum, bs->origin, tb->areanum, TFL_DEFAULT);
et = G_trap_AAS_AreaTravelTimeToGoalArea(bs->areanum, bs->origin, eb->areanum, TFL_DEFAULT);
// if the travel time towards the enemy base is larger than towards our base
if (et > tt) {
//get an alternative route goal towards the enemy base
BotGetAlternateRouteGoal(bs, BotOppositeTeam(bs));
}
}
}
return qtrue;
}
return qfalse;
}
/*
==================
BotRefuseOrder
==================
*/
void BotRefuseOrder(bot_state_t *bs) {
if (!bs->ordered)
return;
// if the bot was ordered to do something
if ( bs->order_time && bs->order_time > FloatTime() - 10 ) {
G_trap_EA_Action(bs->client, ACTION_NEGATIVE);
BotVoiceChat(bs, bs->decisionmaker, VOICECHAT_NO);
bs->order_time = 0;
}
}
/*
==================
BotCTFSeekGoals
==================
*/
void BotCTFSeekGoals(bot_state_t *bs) {
float rnd, l1, l2;
int flagstatus, c;
vec3_t dir;
aas_entityinfo_t entinfo;
//when carrying a flag in ctf the bot should rush to the base
if (BotCTFCarryingFlag(bs)) {
//if not already rushing to the base
if (bs->ltgtype != LTG_RUSHBASE) {
BotRefuseOrder(bs);
bs->ltgtype = LTG_RUSHBASE;
bs->teamgoal_time = FloatTime() + CTF_RUSHBASE_TIME;
bs->rushbaseaway_time = 0;
bs->decisionmaker = bs->client;
bs->ordered = qfalse;
//
switch(BotTeam(bs)) {
case TEAM_RED: VectorSubtract(bs->origin, ctf_blueflag.origin, dir); break;
case TEAM_BLUE: VectorSubtract(bs->origin, ctf_redflag.origin, dir); break;
default: VectorSet(dir, 999, 999, 999); break;
}
// if the bot picked up the flag very close to the enemy base
if ( VectorLength(dir) < 128 ) {
// get an alternative route goal through the enemy base
BotGetAlternateRouteGoal(bs, BotOppositeTeam(bs));
} else {
// don't use any alt route goal, just get the hell out of the base
bs->altroutegoal.areanum = 0;
}
BotSetUserInfo(bs, "teamtask", va("%d", TEAMTASK_OFFENSE));
BotVoiceChat(bs, -1, VOICECHAT_IHAVEFLAG);
}
else if (bs->rushbaseaway_time > FloatTime()) {
if (BotTeam(bs) == TEAM_RED) flagstatus = bs->redflagstatus;
else flagstatus = bs->blueflagstatus;
//if the flag is back
if (flagstatus == 0) {
bs->rushbaseaway_time = 0;
}
}
return;
}
// if the bot decided to follow someone
if ( bs->ltgtype == LTG_TEAMACCOMPANY && !bs->ordered ) {
// if the team mate being accompanied no longer carries the flag
BotEntityInfo(bs->teammate, &entinfo);
if (!EntityCarriesFlag(&entinfo)) {
bs->ltgtype = 0;
}
}
//
if (BotTeam(bs) == TEAM_RED) flagstatus = bs->redflagstatus * 2 + bs->blueflagstatus;
else flagstatus = bs->blueflagstatus * 2 + bs->redflagstatus;
//if our team has the enemy flag and our flag is at the base
if (flagstatus == 1) {
//
if (bs->owndecision_time < FloatTime()) {
//if Not defending the base already
if (!(bs->ltgtype == LTG_DEFENDKEYAREA &&
(bs->teamgoal.number == ctf_redflag.number ||
bs->teamgoal.number == ctf_blueflag.number))) {
//if there is a visible team mate flag carrier
c = BotTeamFlagCarrierVisible(bs);
if (c >= 0 &&
// and not already following the team mate flag carrier
(bs->ltgtype != LTG_TEAMACCOMPANY || bs->teammate != c)) {
//
BotRefuseOrder(bs);
//follow the flag carrier
bs->decisionmaker = bs->client;
bs->ordered = qfalse;
//the team mate
bs->teammate = c;
//last time the team mate was visible
bs->teammatevisible_time = FloatTime();
//no message
bs->teammessage_time = 0;
//no arrive message
bs->arrive_time = 1;
//
BotVoiceChat(bs, bs->teammate, VOICECHAT_ONFOLLOW);
//get the team goal time
bs->teamgoal_time = FloatTime() + TEAM_ACCOMPANY_TIME;
bs->ltgtype = LTG_TEAMACCOMPANY;
bs->formation_dist = 3.5 * 32; //3.5 meter
BotSetTeamStatus(bs);
bs->owndecision_time = FloatTime() + 5;
}
}
}
return;
}
//if the enemy has our flag
else if (flagstatus == 2) {
//
if (bs->owndecision_time < FloatTime()) {
//if enemy flag carrier is visible
c = BotEnemyFlagCarrierVisible(bs);
if (c >= 0) {
//FIXME: fight enemy flag carrier
}
//if not already doing something important
if (bs->ltgtype != LTG_GETFLAG &&
bs->ltgtype != LTG_RETURNFLAG &&
bs->ltgtype != LTG_TEAMHELP &&
bs->ltgtype != LTG_TEAMACCOMPANY &&
bs->ltgtype != LTG_CAMPORDER &&
bs->ltgtype != LTG_PATROL &&
bs->ltgtype != LTG_GETITEM) {
BotRefuseOrder(bs);
bs->decisionmaker = bs->client;
bs->ordered = qfalse;
//
if (random() < 0.5) {
//go for the enemy flag
bs->ltgtype = LTG_GETFLAG;
}
else {
bs->ltgtype = LTG_RETURNFLAG;
}
//no team message
bs->teammessage_time = 0;
//set the time the bot will stop getting the flag
bs->teamgoal_time = FloatTime() + CTF_GETFLAG_TIME;
//get an alternative route goal towards the enemy base
BotGetAlternateRouteGoal(bs, BotOppositeTeam(bs));
//
BotSetTeamStatus(bs);
bs->owndecision_time = FloatTime() + 5;
}
}
return;
}
//if both flags Not at their bases
else if (flagstatus == 3) {
//
if (bs->owndecision_time < FloatTime()) {
// if not trying to return the flag and not following the team flag carrier
if ( bs->ltgtype != LTG_RETURNFLAG && bs->ltgtype != LTG_TEAMACCOMPANY ) {
//
c = BotTeamFlagCarrierVisible(bs);
// if there is a visible team mate flag carrier
if (c >= 0) {
BotRefuseOrder(bs);
//follow the flag carrier
bs->decisionmaker = bs->client;
bs->ordered = qfalse;
//the team mate
bs->teammate = c;
//last time the team mate was visible
bs->teammatevisible_time = FloatTime();
//no message
bs->teammessage_time = 0;
//no arrive message
bs->arrive_time = 1;
//
BotVoiceChat(bs, bs->teammate, VOICECHAT_ONFOLLOW);
//get the team goal time
bs->teamgoal_time = FloatTime() + TEAM_ACCOMPANY_TIME;
bs->ltgtype = LTG_TEAMACCOMPANY;
bs->formation_dist = 3.5 * 32; //3.5 meter
//
BotSetTeamStatus(bs);
bs->owndecision_time = FloatTime() + 5;
}
else {
BotRefuseOrder(bs);
bs->decisionmaker = bs->client;
bs->ordered = qfalse;
//get the enemy flag
bs->teammessage_time = FloatTime() + 2 * random();
//get the flag
bs->ltgtype = LTG_RETURNFLAG;
//set the time the bot will stop getting the flag
bs->teamgoal_time = FloatTime() + CTF_RETURNFLAG_TIME;
//get an alternative route goal towards the enemy base
BotGetAlternateRouteGoal(bs, BotOppositeTeam(bs));
//
BotSetTeamStatus(bs);
bs->owndecision_time = FloatTime() + 5;
}
}
}
return;
}
// don't just do something wait for the bot team leader to give orders
if (BotTeamLeader(bs)) {
return;
}
// if the bot is ordered to do something
if ( bs->lastgoal_ltgtype ) {
bs->teamgoal_time += 60;
}
// if the bot decided to do something on it's own and has a last ordered goal
if ( !bs->ordered && bs->lastgoal_ltgtype ) {
bs->ltgtype = 0;
}
//if already a CTF or team goal
if (bs->ltgtype == LTG_TEAMHELP ||
bs->ltgtype == LTG_TEAMACCOMPANY ||
bs->ltgtype == LTG_DEFENDKEYAREA ||
bs->ltgtype == LTG_GETFLAG ||
bs->ltgtype == LTG_RUSHBASE ||
bs->ltgtype == LTG_RETURNFLAG ||
bs->ltgtype == LTG_CAMPORDER ||
bs->ltgtype == LTG_PATROL ||
bs->ltgtype == LTG_GETITEM ||
bs->ltgtype == LTG_MAKELOVE_UNDER ||
bs->ltgtype == LTG_MAKELOVE_ONTOP) {
return;
}
//
if (BotSetLastOrderedTask(bs))
return;
//
if (bs->owndecision_time > FloatTime())
return;;
//if the bot is roaming
if (bs->ctfroam_time > FloatTime())
return;
//if the bot has anough aggression to decide what to do
if (BotAggression(bs) < 50)
return;
//set the time to send a message to the team mates
bs->teammessage_time = FloatTime() + 2 * random();
//
if (bs->teamtaskpreference & (TEAMTP_ATTACKER|TEAMTP_DEFENDER)) {
if (bs->teamtaskpreference & TEAMTP_ATTACKER) {
l1 = 0.7f;
}
else {
l1 = 0.2f;
}
l2 = 0.9f;
}
else {
l1 = 0.4f;
l2 = 0.7f;
}
//get the flag or defend the base
rnd = random();
if (rnd < l1 && ctf_redflag.areanum && ctf_blueflag.areanum) {
bs->decisionmaker = bs->client;
bs->ordered = qfalse;
bs->ltgtype = LTG_GETFLAG;
//set the time the bot will stop getting the flag
bs->teamgoal_time = FloatTime() + CTF_GETFLAG_TIME;
//get an alternative route goal towards the enemy base
BotGetAlternateRouteGoal(bs, BotOppositeTeam(bs));
BotSetTeamStatus(bs);
}
else if (rnd < l2 && ctf_redflag.areanum && ctf_blueflag.areanum) {
bs->decisionmaker = bs->client;
bs->ordered = qfalse;
//
if (BotTeam(bs) == TEAM_RED) memcpy(&bs->teamgoal, &ctf_redflag, sizeof(bot_goal_t));
else memcpy(&bs->teamgoal, &ctf_blueflag, sizeof(bot_goal_t));
//set the ltg type
bs->ltgtype = LTG_DEFENDKEYAREA;
//set the time the bot stops defending the base
bs->teamgoal_time = FloatTime() + TEAM_DEFENDKEYAREA_TIME;
bs->defendaway_time = 0;
BotSetTeamStatus(bs);
}
else {
bs->ltgtype = 0;
//set the time the bot will stop roaming
bs->ctfroam_time = FloatTime() + CTF_ROAM_TIME;
BotSetTeamStatus(bs);
}
bs->owndecision_time = FloatTime() + 5;
#ifdef DEBUG
BotPrintTeamGoal(bs);
#endif //DEBUG
}
/*
==================
BotCTFRetreatGoals
==================
*/
void BotCTFRetreatGoals(bot_state_t *bs) {
//when carrying a flag in ctf the bot should rush to the base
if (BotCTFCarryingFlag(bs)) {
//if not already rushing to the base
if (bs->ltgtype != LTG_RUSHBASE) {
BotRefuseOrder(bs);
bs->ltgtype = LTG_RUSHBASE;
bs->teamgoal_time = FloatTime() + CTF_RUSHBASE_TIME;
bs->rushbaseaway_time = 0;
bs->decisionmaker = bs->client;
bs->ordered = qfalse;
BotSetTeamStatus(bs);
}
}
}
#ifdef MISSIONPACK
/*
==================
Bot1FCTFSeekGoals
==================
*/
void Bot1FCTFSeekGoals(bot_state_t *bs) {
aas_entityinfo_t entinfo;
float rnd, l1, l2;
int c;
//when carrying a flag in ctf the bot should rush to the base
if (Bot1FCTFCarryingFlag(bs)) {
//if not already rushing to the base
if (bs->ltgtype != LTG_RUSHBASE) {
BotRefuseOrder(bs);
bs->ltgtype = LTG_RUSHBASE;
bs->teamgoal_time = FloatTime() + CTF_RUSHBASE_TIME;
bs->rushbaseaway_time = 0;
bs->decisionmaker = bs->client;
bs->ordered = qfalse;
//get an alternative route goal towards the enemy base
BotGetAlternateRouteGoal(bs, BotOppositeTeam(bs));
//
BotSetTeamStatus(bs);
BotVoiceChat(bs, -1, VOICECHAT_IHAVEFLAG);
}
return;
}
// if the bot decided to follow someone
if ( bs->ltgtype == LTG_TEAMACCOMPANY && !bs->ordered ) {
// if the team mate being accompanied no longer carries the flag
BotEntityInfo(bs->teammate, &entinfo);
if (!EntityCarriesFlag(&entinfo)) {
bs->ltgtype = 0;
}
}
//our team has the flag
if (bs->neutralflagstatus == 1) {
if (bs->owndecision_time < FloatTime()) {
// if not already following someone
if (bs->ltgtype != LTG_TEAMACCOMPANY) {
//if there is a visible team mate flag carrier
c = BotTeamFlagCarrierVisible(bs);
if (c >= 0) {
BotRefuseOrder(bs);
//follow the flag carrier
bs->decisionmaker = bs->client;
bs->ordered = qfalse;
//the team mate
bs->teammate = c;
//last time the team mate was visible
bs->teammatevisible_time = FloatTime();
//no message
bs->teammessage_time = 0;
//no arrive message
bs->arrive_time = 1;
//
BotVoiceChat(bs, bs->teammate, VOICECHAT_ONFOLLOW);
//get the team goal time
bs->teamgoal_time = FloatTime() + TEAM_ACCOMPANY_TIME;
bs->ltgtype = LTG_TEAMACCOMPANY;
bs->formation_dist = 3.5 * 32; //3.5 meter
BotSetTeamStatus(bs);
bs->owndecision_time = FloatTime() + 5;
return;
}
}
//if already a CTF or team goal
if (bs->ltgtype == LTG_TEAMHELP ||
bs->ltgtype == LTG_TEAMACCOMPANY ||
bs->ltgtype == LTG_DEFENDKEYAREA ||
bs->ltgtype == LTG_GETFLAG ||
bs->ltgtype == LTG_RUSHBASE ||
bs->ltgtype == LTG_CAMPORDER ||
bs->ltgtype == LTG_PATROL ||
bs->ltgtype == LTG_ATTACKENEMYBASE ||
bs->ltgtype == LTG_GETITEM ||
bs->ltgtype == LTG_MAKELOVE_UNDER ||
bs->ltgtype == LTG_MAKELOVE_ONTOP) {
return;
}
//if not already attacking the enemy base
if (bs->ltgtype != LTG_ATTACKENEMYBASE) {
BotRefuseOrder(bs);
bs->decisionmaker = bs->client;
bs->ordered = qfalse;
//
if (BotTeam(bs) == TEAM_RED) memcpy(&bs->teamgoal, &ctf_blueflag, sizeof(bot_goal_t));
else memcpy(&bs->teamgoal, &ctf_redflag, sizeof(bot_goal_t));
//set the ltg type
bs->ltgtype = LTG_ATTACKENEMYBASE;
//set the time the bot will stop getting the flag
bs->teamgoal_time = FloatTime() + TEAM_ATTACKENEMYBASE_TIME;
BotSetTeamStatus(bs);
bs->owndecision_time = FloatTime() + 5;
}
}
return;
}
//enemy team has the flag
else if (bs->neutralflagstatus == 2) {
if (bs->owndecision_time < FloatTime()) {
c = BotEnemyFlagCarrierVisible(bs);
if (c >= 0) {
//FIXME: attack enemy flag carrier
}
//if already a CTF or team goal
if (bs->ltgtype == LTG_TEAMHELP ||
bs->ltgtype == LTG_TEAMACCOMPANY ||
bs->ltgtype == LTG_CAMPORDER ||
bs->ltgtype == LTG_PATROL ||
bs->ltgtype == LTG_GETITEM) {
return;
}
// if not already defending the base
if (bs->ltgtype != LTG_DEFENDKEYAREA) {
BotRefuseOrder(bs);
bs->decisionmaker = bs->client;
bs->ordered = qfalse;
//
if (BotTeam(bs) == TEAM_RED) memcpy(&bs->teamgoal, &ctf_redflag, sizeof(bot_goal_t));
else memcpy(&bs->teamgoal, &ctf_blueflag, sizeof(bot_goal_t));
//set the ltg type
bs->ltgtype = LTG_DEFENDKEYAREA;
//set the time the bot stops defending the base
bs->teamgoal_time = FloatTime() + TEAM_DEFENDKEYAREA_TIME;
bs->defendaway_time = 0;
BotSetTeamStatus(bs);
bs->owndecision_time = FloatTime() + 5;
}
}
return;
}
// don't just do something wait for the bot team leader to give orders
if (BotTeamLeader(bs)) {
return;
}
// if the bot is ordered to do something
if ( bs->lastgoal_ltgtype ) {
bs->teamgoal_time += 60;
}
// if the bot decided to do something on it's own and has a last ordered goal
if ( !bs->ordered && bs->lastgoal_ltgtype ) {
bs->ltgtype = 0;
}
//if already a CTF or team goal
if (bs->ltgtype == LTG_TEAMHELP ||
bs->ltgtype == LTG_TEAMACCOMPANY ||
bs->ltgtype == LTG_DEFENDKEYAREA ||
bs->ltgtype == LTG_GETFLAG ||
bs->ltgtype == LTG_RUSHBASE ||
bs->ltgtype == LTG_RETURNFLAG ||
bs->ltgtype == LTG_CAMPORDER ||
bs->ltgtype == LTG_PATROL ||
bs->ltgtype == LTG_ATTACKENEMYBASE ||
bs->ltgtype == LTG_GETITEM ||
bs->ltgtype == LTG_MAKELOVE_UNDER ||
bs->ltgtype == LTG_MAKELOVE_ONTOP) {
return;
}
//
if (BotSetLastOrderedTask(bs))
return;
//
if (bs->owndecision_time > FloatTime())
return;;
//if the bot is roaming
if (bs->ctfroam_time > FloatTime())
return;
//if the bot has anough aggression to decide what to do
if (BotAggression(bs) < 50)
return;
//set the time to send a message to the team mates
bs->teammessage_time = FloatTime() + 2 * random();
//
if (bs->teamtaskpreference & (TEAMTP_ATTACKER|TEAMTP_DEFENDER)) {
if (bs->teamtaskpreference & TEAMTP_ATTACKER) {
l1 = 0.7f;
}
else {
l1 = 0.2f;
}
l2 = 0.9f;
}
else {
l1 = 0.4f;
l2 = 0.7f;
}
//get the flag or defend the base
rnd = random();
if (rnd < l1 && ctf_neutralflag.areanum) {
bs->decisionmaker = bs->client;
bs->ordered = qfalse;
bs->ltgtype = LTG_GETFLAG;
//set the time the bot will stop getting the flag
bs->teamgoal_time = FloatTime() + CTF_GETFLAG_TIME;
BotSetTeamStatus(bs);
}
else if (rnd < l2 && ctf_redflag.areanum && ctf_blueflag.areanum) {
bs->decisionmaker = bs->client;
bs->ordered = qfalse;
//
if (BotTeam(bs) == TEAM_RED) memcpy(&bs->teamgoal, &ctf_redflag, sizeof(bot_goal_t));
else memcpy(&bs->teamgoal, &ctf_blueflag, sizeof(bot_goal_t));
//set the ltg type