Debian Codegraph @

code/game/ai_dmq3.c

raw symbols SCIP
1 /*
2 ===========================================================================
3 Copyright (C) 1999-2005 Id Software, Inc.
4
5 This file is part of Quake III Arena source code.
6
7 Quake III Arena source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 Quake III Arena source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Quake III Arena source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
21 */
22 //
23
24 /*****************************************************************************
25 * name: ai_dmq3.c
26 *
27 * desc: Quake3 bot AI
28 *
29 * $Archive: /MissionPack/code/game/ai_dmq3.c $
30 *
31 *****************************************************************************/
32
33
34 #include "g_local.h"
35 #include "../botlib/botlib.h"
36 #include "../botlib/be_aas.h"
37 #include "../botlib/be_ea.h"
38 #include "../botlib/be_ai_char.h"
39 #include "../botlib/be_ai_chat.h"
40 #include "../botlib/be_ai_gen.h"
41 #include "../botlib/be_ai_goal.h"
42 #include "../botlib/be_ai_move.h"
43 #include "../botlib/be_ai_weap.h"
44 //
45 #include "ai_main.h"
46 #include "ai_dmq3.h"
47 #include "ai_chat.h"
48 #include "ai_cmd.h"
49 #include "ai_dmnet.h"
50 #include "ai_team.h"
51 //
52 #include "chars.h" //characteristics
53 #include "inv.h" //indexes into the inventory
54 #include "syn.h" //synonyms
55 #include "match.h" //string matching types and vars
56
57 // for the voice chats
58 #include "../../ui/menudef.h" // sos001205 - for q3_ui also
59
60 // from aasfile.h
61 #define AREACONTENTS_MOVER 1024
62 #define AREACONTENTS_MODELNUMSHIFT 24
63 #define AREACONTENTS_MAXMODELNUM 0xFF
64 #define AREACONTENTS_MODELNUM (AREACONTENTS_MAXMODELNUM << AREACONTENTS_MODELNUMSHIFT)
65
66 #define IDEAL_ATTACKDIST 140
67
68 #define MAX_WAYPOINTS 128
69 //
70 bot_waypoint_t botai_waypoints[MAX_WAYPOINTS];
71 bot_waypoint_t *botai_freewaypoints;
72
73 //NOTE: not using a cvars which can be updated because the game should be reloaded anyway
74 int gametype; //game type
75
76 vmCvar_t bot_grapple;
77 vmCvar_t bot_rocketjump;
78 vmCvar_t bot_fastchat;
79 vmCvar_t bot_nochat;
80 vmCvar_t bot_testrchat;
81 vmCvar_t bot_challenge;
82 vmCvar_t bot_predictobstacles;
83 vmCvar_t g_spSkill;
84
85 extern vmCvar_t bot_developer;
86
87 vec3_t lastteleport_origin; //last teleport event origin
88 float lastteleport_time; //last teleport event time
89 int max_bspmodelindex; //maximum BSP model index
90
91 //CTF flag goals
92 bot_goal_t ctf_redflag;
93 bot_goal_t ctf_blueflag;
94 #ifdef MISSIONPACK
95 bot_goal_t ctf_neutralflag;
96 bot_goal_t redobelisk;
97 bot_goal_t blueobelisk;
98 bot_goal_t neutralobelisk;
99 #endif
100
101 #define MAX_ALTROUTEGOALS 32
102
103 int altroutegoals_setup;
104 aas_altroutegoal_t red_altroutegoals[MAX_ALTROUTEGOALS];
105 int red_numaltroutegoals;
106 aas_altroutegoal_t blue_altroutegoals[MAX_ALTROUTEGOALS];
107 int blue_numaltroutegoals;
108
109
110 /*
111 ==================
112 BotSetUserInfo
113 ==================
114 */
115 void BotSetUserInfo(bot_state_t *bs, char *key, char *value) {
116 char userinfo[MAX_INFO_STRING];
117
118 trap_GetUserinfo(bs->client, userinfo, sizeof(userinfo));
119 Info_SetValueForKey(userinfo, key, value);
120 trap_SetUserinfo(bs->client, userinfo);
121 ClientUserinfoChanged( bs->client );
122 }
123
124 /*
125 ==================
126 BotCTFCarryingFlag
127 ==================
128 */
129 int BotCTFCarryingFlag(bot_state_t *bs) {
130 if (gametype != GT_CTF) return CTF_FLAG_NONE;
131
132 if (bs->inventory[INVENTORY_REDFLAG] > 0) return CTF_FLAG_RED;
133 else if (bs->inventory[INVENTORY_BLUEFLAG] > 0) return CTF_FLAG_BLUE;
134 return CTF_FLAG_NONE;
135 }
136
137 /*
138 ==================
139 BotTeam
140 ==================
141 */
142 int BotTeam(bot_state_t *bs) {
143
144 if (bs->client < 0 || bs->client >= MAX_CLIENTS) {
145 return qfalse;
146 }
147
148 if (level.clients[bs->client].sess.sessionTeam == TEAM_RED) {
149 return TEAM_RED;
150 } else if (level.clients[bs->client].sess.sessionTeam == TEAM_BLUE) {
151 return TEAM_BLUE;
152 }
153
154 return TEAM_FREE;
155 }
156
157 /*
158 ==================
159 BotOppositeTeam
160 ==================
161 */
162 int BotOppositeTeam(bot_state_t *bs) {
163 switch(BotTeam(bs)) {
164 case TEAM_RED: return TEAM_BLUE;
165 case TEAM_BLUE: return TEAM_RED;
166 default: return TEAM_FREE;
167 }
168 }
169
170 /*
171 ==================
172 BotEnemyFlag
173 ==================
174 */
175 bot_goal_t *BotEnemyFlag(bot_state_t *bs) {
176 if (BotTeam(bs) == TEAM_RED) {
177 return &ctf_blueflag;
178 }
179 else {
180 return &ctf_redflag;
181 }
182 }
183
184 /*
185 ==================
186 BotTeamFlag
187 ==================
188 */
189 bot_goal_t *BotTeamFlag(bot_state_t *bs) {
190 if (BotTeam(bs) == TEAM_RED) {
191 return &ctf_redflag;
192 }
193 else {
194 return &ctf_blueflag;
195 }
196 }
197
198
199 /*
200 ==================
201 EntityIsDead
202 ==================
203 */
204 qboolean EntityIsDead(aas_entityinfo_t *entinfo) {
205 playerState_t ps;
206
207 if (entinfo->number >= 0 && entinfo->number < MAX_CLIENTS) {
208 //retrieve the current client state
209 if (!BotAI_GetClientState(entinfo->number, &ps)) {
210 return qfalse;
211 }
212
213 if (ps.pm_type != PM_NORMAL) return qtrue;
214 }
215 return qfalse;
216 }
217
218 /*
219 ==================
220 EntityCarriesFlag
221 ==================
222 */
223 qboolean EntityCarriesFlag(aas_entityinfo_t *entinfo) {
224 if ( entinfo->powerups & ( 1 << PW_REDFLAG ) )
225 return qtrue;
226 if ( entinfo->powerups & ( 1 << PW_BLUEFLAG ) )
227 return qtrue;
228 #ifdef MISSIONPACK
229 if ( entinfo->powerups & ( 1 << PW_NEUTRALFLAG ) )
230 return qtrue;
231 #endif
232 return qfalse;
233 }
234
235 /*
236 ==================
237 EntityIsInvisible
238 ==================
239 */
240 qboolean EntityIsInvisible(aas_entityinfo_t *entinfo) {
241 // the flag is always visible
242 if (EntityCarriesFlag(entinfo)) {
243 return qfalse;
244 }
245 if (entinfo->powerups & (1 << PW_INVIS)) {
246 return qtrue;
247 }
248 return qfalse;
249 }
250
251 /*
252 ==================
253 EntityIsShooting
254 ==================
255 */
256 qboolean EntityIsShooting(aas_entityinfo_t *entinfo) {
257 if (entinfo->flags & EF_FIRING) {
258 return qtrue;
259 }
260 return qfalse;
261 }
262
263 /*
264 ==================
265 EntityIsChatting
266 ==================
267 */
268 qboolean EntityIsChatting(aas_entityinfo_t *entinfo) {
269 if (entinfo->flags & EF_TALK) {
270 return qtrue;
271 }
272 return qfalse;
273 }
274
275 /*
276 ==================
277 EntityHasQuad
278 ==================
279 */
280 qboolean EntityHasQuad(aas_entityinfo_t *entinfo) {
281 if (entinfo->powerups & (1 << PW_QUAD)) {
282 return qtrue;
283 }
284 return qfalse;
285 }
286
287 #ifdef MISSIONPACK
288 /*
289 ==================
290 EntityHasKamikze
291 ==================
292 */
293 qboolean EntityHasKamikaze(aas_entityinfo_t *entinfo) {
294 if (entinfo->flags & EF_KAMIKAZE) {
295 return qtrue;
296 }
297 return qfalse;
298 }
299
300 /*
301 ==================
302 EntityCarriesCubes
303 ==================
304 */
305 qboolean EntityCarriesCubes(aas_entityinfo_t *entinfo) {
306 entityState_t state;
307
308 if (gametype != GT_HARVESTER)
309 return qfalse;
310 //FIXME: get this info from the aas_entityinfo_t ?
311 BotAI_GetEntityState(entinfo->number, &state);
312 if (state.generic1 > 0)
313 return qtrue;
314 return qfalse;
315 }
316
317 /*
318 ==================
319 Bot1FCTFCarryingFlag
320 ==================
321 */
322 int Bot1FCTFCarryingFlag(bot_state_t *bs) {
323 if (gametype != GT_1FCTF) return qfalse;
324
325 if (bs->inventory[INVENTORY_NEUTRALFLAG] > 0) return qtrue;
326 return qfalse;
327 }
328
329 /*
330 ==================
331 BotHarvesterCarryingCubes
332 ==================
333 */
334 int BotHarvesterCarryingCubes(bot_state_t *bs) {
335 if (gametype != GT_HARVESTER) return qfalse;
336
337 if (bs->inventory[INVENTORY_REDCUBE] > 0) return qtrue;
338 if (bs->inventory[INVENTORY_BLUECUBE] > 0) return qtrue;
339 return qfalse;
340 }
341 #endif
342
343 /*
344 ==================
345 BotRememberLastOrderedTask
346 ==================
347 */
348 void BotRememberLastOrderedTask(bot_state_t *bs) {
349 if (!bs->ordered) {
350 return;
351 }
352 bs->lastgoal_decisionmaker = bs->decisionmaker;
353 bs->lastgoal_ltgtype = bs->ltgtype;
354 memcpy(&bs->lastgoal_teamgoal, &bs->teamgoal, sizeof(bot_goal_t));
355 bs->lastgoal_teammate = bs->teammate;
356 }
357
358 /*
359 ==================
360 BotSetTeamStatus
361 ==================
362 */
363 void BotSetTeamStatus(bot_state_t *bs) {
364 #ifdef MISSIONPACK
365 int teamtask;
366 aas_entityinfo_t entinfo;
367
368 teamtask = TEAMTASK_PATROL;
369
370 switch(bs->ltgtype) {
371 case LTG_TEAMHELP:
372 break;
373 case LTG_TEAMACCOMPANY:
374 BotEntityInfo(bs->teammate, &entinfo);
375 if ( ( (gametype == GT_CTF || gametype == GT_1FCTF) && EntityCarriesFlag(&entinfo))
376 || ( gametype == GT_HARVESTER && EntityCarriesCubes(&entinfo)) ) {
377 teamtask = TEAMTASK_ESCORT;
378 }
379 else {
380 teamtask = TEAMTASK_FOLLOW;
381 }
382 break;
383 case LTG_DEFENDKEYAREA:
384 teamtask = TEAMTASK_DEFENSE;
385 break;
386 case LTG_GETFLAG:
387 teamtask = TEAMTASK_OFFENSE;
388 break;
389 case LTG_RUSHBASE:
390 teamtask = TEAMTASK_DEFENSE;
391 break;
392 case LTG_RETURNFLAG:
393 teamtask = TEAMTASK_RETRIEVE;
394 break;
395 case LTG_CAMP:
396 case LTG_CAMPORDER:
397 teamtask = TEAMTASK_CAMP;
398 break;
399 case LTG_PATROL:
400 teamtask = TEAMTASK_PATROL;
401 break;
402 case LTG_GETITEM:
403 teamtask = TEAMTASK_PATROL;
404 break;
405 case LTG_KILL:
406 teamtask = TEAMTASK_PATROL;
407 break;
408 case LTG_HARVEST:
409 teamtask = TEAMTASK_OFFENSE;
410 break;
411 case LTG_ATTACKENEMYBASE:
412 teamtask = TEAMTASK_OFFENSE;
413 break;
414 default:
415 teamtask = TEAMTASK_PATROL;
416 break;
417 }
418 BotSetUserInfo(bs, "teamtask", va("%d", teamtask));
419 #endif
420 }
421
422 /*
423 ==================
424 BotSetLastOrderedTask
425 ==================
426 */
427 int BotSetLastOrderedTask(bot_state_t *bs) {
428
429 if (gametype == GT_CTF) {
430 // don't go back to returning the flag if it's at the base
431 if ( bs->lastgoal_ltgtype == LTG_RETURNFLAG ) {
432 if ( BotTeam(bs) == TEAM_RED ) {
433 if ( bs->redflagstatus == 0 ) {
434 bs->lastgoal_ltgtype = 0;
435 }
436 }
437 else {
438 if ( bs->blueflagstatus == 0 ) {
439 bs->lastgoal_ltgtype = 0;
440 }
441 }
442 }
443 }
444
445 if ( bs->lastgoal_ltgtype ) {
446 bs->decisionmaker = bs->lastgoal_decisionmaker;
447 bs->ordered = qtrue;
448 bs->ltgtype = bs->lastgoal_ltgtype;
449 memcpy(&bs->teamgoal, &bs->lastgoal_teamgoal, sizeof(bot_goal_t));
450 bs->teammate = bs->lastgoal_teammate;
451 bs->teamgoal_time = FloatTime() + 300;
452 BotSetTeamStatus(bs);
453 //
454 if ( gametype == GT_CTF ) {
455 if ( bs->ltgtype == LTG_GETFLAG ) {
456 bot_goal_t *tb, *eb;
457 int tt, et;
458
459 tb = BotTeamFlag(bs);
460 eb = BotEnemyFlag(bs);
461 tt = trap_AAS_AreaTravelTimeToGoalArea(bs->areanum, bs->origin, tb->areanum, TFL_DEFAULT);
462 et = trap_AAS_AreaTravelTimeToGoalArea(bs->areanum, bs->origin, eb->areanum, TFL_DEFAULT);
463 // if the travel time towards the enemy base is larger than towards our base
464 if (et > tt) {
465 //get an alternative route goal towards the enemy base
466 BotGetAlternateRouteGoal(bs, BotOppositeTeam(bs));
467 }
468 }
469 }
470 return qtrue;
471 }
472 return qfalse;
473 }
474
475 /*
476 ==================
477 BotRefuseOrder
478 ==================
479 */
480 void BotRefuseOrder(bot_state_t *bs) {
481 if (!bs->ordered)
482 return;
483 // if the bot was ordered to do something
484 if ( bs->order_time && bs->order_time > FloatTime() - 10 ) {
485 trap_EA_Action(bs->client, ACTION_NEGATIVE);
486 BotVoiceChat(bs, bs->decisionmaker, VOICECHAT_NO);
487 bs->order_time = 0;
488 }
489 }
490
491 /*
492 ==================
493 BotCTFSeekGoals
494 ==================
495 */
496 void BotCTFSeekGoals(bot_state_t *bs) {
497 float rnd, l1, l2;
498 int flagstatus, c;
499 vec3_t dir;
500 aas_entityinfo_t entinfo;
501
502 //when carrying a flag in ctf the bot should rush to the base
503 if (BotCTFCarryingFlag(bs)) {
504 //if not already rushing to the base
505 if (bs->ltgtype != LTG_RUSHBASE) {
506 BotRefuseOrder(bs);
507 bs->ltgtype = LTG_RUSHBASE;
508 bs->teamgoal_time = FloatTime() + CTF_RUSHBASE_TIME;
509 bs->rushbaseaway_time = 0;
510 bs->decisionmaker = bs->client;
511 bs->ordered = qfalse;
512 //
513 switch(BotTeam(bs)) {
514 case TEAM_RED: VectorSubtract(bs->origin, ctf_blueflag.origin, dir); break;
515 case TEAM_BLUE: VectorSubtract(bs->origin, ctf_redflag.origin, dir); break;
516 default: VectorSet(dir, 999, 999, 999); break;
517 }
518 // if the bot picked up the flag very close to the enemy base
519 if ( VectorLength(dir) < 128 ) {
520 // get an alternative route goal through the enemy base
521 BotGetAlternateRouteGoal(bs, BotOppositeTeam(bs));
522 } else {
523 // don't use any alt route goal, just get the hell out of the base
524 bs->altroutegoal.areanum = 0;
525 }
526 BotSetUserInfo(bs, "teamtask", va("%d", TEAMTASK_OFFENSE));
527 BotVoiceChat(bs, -1, VOICECHAT_IHAVEFLAG);
528 }
529 else if (bs->rushbaseaway_time > FloatTime()) {
530 if (BotTeam(bs) == TEAM_RED) flagstatus = bs->redflagstatus;
531 else flagstatus = bs->blueflagstatus;
532 //if the flag is back
533 if (flagstatus == 0) {
534 bs->rushbaseaway_time = 0;
535 }
536 }
537 return;
538 }
539 // if the bot decided to follow someone
540 if ( bs->ltgtype == LTG_TEAMACCOMPANY && !bs->ordered ) {
541 // if the team mate being accompanied no longer carries the flag
542 BotEntityInfo(bs->teammate, &entinfo);
543 if (!EntityCarriesFlag(&entinfo)) {
544 bs->ltgtype = 0;
545 }
546 }
547 //
548 if (BotTeam(bs) == TEAM_RED) flagstatus = bs->redflagstatus * 2 + bs->blueflagstatus;
549 else flagstatus = bs->blueflagstatus * 2 + bs->redflagstatus;
550 //if our team has the enemy flag and our flag is at the base
551 if (flagstatus == 1) {
552 //
553 if (bs->owndecision_time < FloatTime()) {
554 //if Not defending the base already
555 if (!(bs->ltgtype == LTG_DEFENDKEYAREA &&
556 (bs->teamgoal.number == ctf_redflag.number ||
557 bs->teamgoal.number == ctf_blueflag.number))) {
558 //if there is a visible team mate flag carrier
559 c = BotTeamFlagCarrierVisible(bs);
560 if (c >= 0 &&
561 // and not already following the team mate flag carrier
562 (bs->ltgtype != LTG_TEAMACCOMPANY || bs->teammate != c)) {
563 //
564 BotRefuseOrder(bs);
565 //follow the flag carrier
566 bs->decisionmaker = bs->client;
567 bs->ordered = qfalse;
568 //the team mate
569 bs->teammate = c;
570 //last time the team mate was visible
571 bs->teammatevisible_time = FloatTime();
572 //no message
573 bs->teammessage_time = 0;
574 //no arrive message
575 bs->arrive_time = 1;
576 //
577 BotVoiceChat(bs, bs->teammate, VOICECHAT_ONFOLLOW);
578 //get the team goal time
579 bs->teamgoal_time = FloatTime() + TEAM_ACCOMPANY_TIME;
580 bs->ltgtype = LTG_TEAMACCOMPANY;
581 bs->formation_dist = 3.5 * 32; //3.5 meter
582 BotSetTeamStatus(bs);
583 bs->owndecision_time = FloatTime() + 5;
584 }
585 }
586 }
587 return;
588 }
589 //if the enemy has our flag
590 else if (flagstatus == 2) {
591 //
592 if (bs->owndecision_time < FloatTime()) {
593 //if enemy flag carrier is visible
594 c = BotEnemyFlagCarrierVisible(bs);
595 if (c >= 0) {
596 //FIXME: fight enemy flag carrier
597 }
598 //if not already doing something important
599 if (bs->ltgtype != LTG_GETFLAG &&
600 bs->ltgtype != LTG_RETURNFLAG &&
601 bs->ltgtype != LTG_TEAMHELP &&
602 bs->ltgtype != LTG_TEAMACCOMPANY &&
603 bs->ltgtype != LTG_CAMPORDER &&
604 bs->ltgtype != LTG_PATROL &&
605 bs->ltgtype != LTG_GETITEM) {
606
607 BotRefuseOrder(bs);
608 bs->decisionmaker = bs->client;
609 bs->ordered = qfalse;
610 //
611 if (random() < 0.5) {
612 //go for the enemy flag
613 bs->ltgtype = LTG_GETFLAG;
614 }
615 else {
616 bs->ltgtype = LTG_RETURNFLAG;
617 }
618 //no team message
619 bs->teammessage_time = 0;
620 //set the time the bot will stop getting the flag
621 bs->teamgoal_time = FloatTime() + CTF_GETFLAG_TIME;
622 //get an alternative route goal towards the enemy base
623 BotGetAlternateRouteGoal(bs, BotOppositeTeam(bs));
624 //
625 BotSetTeamStatus(bs);
626 bs->owndecision_time = FloatTime() + 5;
627 }
628 }
629 return;
630 }
631 //if both flags Not at their bases
632 else if (flagstatus == 3) {
633 //
634 if (bs->owndecision_time < FloatTime()) {
635 // if not trying to return the flag and not following the team flag carrier
636 if ( bs->ltgtype != LTG_RETURNFLAG && bs->ltgtype != LTG_TEAMACCOMPANY ) {
637 //
638 c = BotTeamFlagCarrierVisible(bs);
639 // if there is a visible team mate flag carrier
640 if (c >= 0) {
641 BotRefuseOrder(bs);
642 //follow the flag carrier
643 bs->decisionmaker = bs->client;
644 bs->ordered = qfalse;
645 //the team mate
646 bs->teammate = c;
647 //last time the team mate was visible
648 bs->teammatevisible_time = FloatTime();
649 //no message
650 bs->teammessage_time = 0;
651 //no arrive message
652 bs->arrive_time = 1;
653 //
654 BotVoiceChat(bs, bs->teammate, VOICECHAT_ONFOLLOW);
655 //get the team goal time
656 bs->teamgoal_time = FloatTime() + TEAM_ACCOMPANY_TIME;
657 bs->ltgtype = LTG_TEAMACCOMPANY;
658 bs->formation_dist = 3.5 * 32; //3.5 meter
659 //
660 BotSetTeamStatus(bs);
661 bs->owndecision_time = FloatTime() + 5;
662 }
663 else {
664 BotRefuseOrder(bs);
665 bs->decisionmaker = bs->client;
666 bs->ordered = qfalse;
667 //get the enemy flag
668 bs->teammessage_time = FloatTime() + 2 * random();
669 //get the flag
670 bs->ltgtype = LTG_RETURNFLAG;
671 //set the time the bot will stop getting the flag
672 bs->teamgoal_time = FloatTime() + CTF_RETURNFLAG_TIME;
673 //get an alternative route goal towards the enemy base
674 BotGetAlternateRouteGoal(bs, BotOppositeTeam(bs));
675 //
676 BotSetTeamStatus(bs);
677 bs->owndecision_time = FloatTime() + 5;
678 }
679 }
680 }
681 return;
682 }
683 // don't just do something wait for the bot team leader to give orders
684 if (BotTeamLeader(bs)) {
685 return;
686 }
687 // if the bot is ordered to do something
688 if ( bs->lastgoal_ltgtype ) {
689 bs->teamgoal_time += 60;
690 }
691 // if the bot decided to do something on its own and has a last ordered goal
692 if ( !bs->ordered && bs->lastgoal_ltgtype ) {
693 bs->ltgtype = 0;
694 }
695 //if already a CTF or team goal
696 if (bs->ltgtype == LTG_TEAMHELP ||
697 bs->ltgtype == LTG_TEAMACCOMPANY ||
698 bs->ltgtype == LTG_DEFENDKEYAREA ||
699 bs->ltgtype == LTG_GETFLAG ||
700 bs->ltgtype == LTG_RUSHBASE ||
701 bs->ltgtype == LTG_RETURNFLAG ||
702 bs->ltgtype == LTG_CAMPORDER ||
703 bs->ltgtype == LTG_PATROL ||
704 bs->ltgtype == LTG_GETITEM ||
705 bs->ltgtype == LTG_MAKELOVE_UNDER ||
706 bs->ltgtype == LTG_MAKELOVE_ONTOP) {
707 return;
708 }
709 //
710 if (BotSetLastOrderedTask(bs))
711 return;
712 //
713 if (bs->owndecision_time > FloatTime())
714 return;;
715 //if the bot is roaming
716 if (bs->ctfroam_time > FloatTime())
717 return;
718 //if the bot has enough aggression to decide what to do
719 if (BotAggression(bs) < 50)
720 return;
721 //set the time to send a message to the team mates
722 bs->teammessage_time = FloatTime() + 2 * random();
723 //
724 if (bs->teamtaskpreference & (TEAMTP_ATTACKER|TEAMTP_DEFENDER)) {
725 if (bs->teamtaskpreference & TEAMTP_ATTACKER) {
726 l1 = 0.7f;
727 }
728 else {
729 l1 = 0.2f;
730 }
731 l2 = 0.9f;
732 }
733 else {
734 l1 = 0.4f;
735 l2 = 0.7f;
736 }
737 //get the flag or defend the base
738 rnd = random();
739 if (rnd < l1 && ctf_redflag.areanum && ctf_blueflag.areanum) {
740 bs->decisionmaker = bs->client;
741 bs->ordered = qfalse;
742 bs->ltgtype = LTG_GETFLAG;
743 //set the time the bot will stop getting the flag
744 bs->teamgoal_time = FloatTime() + CTF_GETFLAG_TIME;
745 //get an alternative route goal towards the enemy base
746 BotGetAlternateRouteGoal(bs, BotOppositeTeam(bs));
747 BotSetTeamStatus(bs);
748 }
749 else if (rnd < l2 && ctf_redflag.areanum && ctf_blueflag.areanum) {
750 bs->decisionmaker = bs->client;
751 bs->ordered = qfalse;
752 //
753 if (BotTeam(bs) == TEAM_RED) memcpy(&bs->teamgoal, &ctf_redflag, sizeof(bot_goal_t));
754 else memcpy(&bs->teamgoal, &ctf_blueflag, sizeof(bot_goal_t));
755 //set the ltg type
756 bs->ltgtype = LTG_DEFENDKEYAREA;
757 //set the time the bot stops defending the base
758 bs->teamgoal_time = FloatTime() + TEAM_DEFENDKEYAREA_TIME;
759 bs->defendaway_time = 0;
760 BotSetTeamStatus(bs);
761 }
762 else {
763 bs->ltgtype = 0;
764 //set the time the bot will stop roaming
765 bs->ctfroam_time = FloatTime() + CTF_ROAM_TIME;
766 BotSetTeamStatus(bs);
767 }
768 bs->owndecision_time = FloatTime() + 5;
769 #ifdef DEBUG
770 BotPrintTeamGoal(bs);
771 #endif //DEBUG
772 }
773
774 /*
775 ==================
776 BotCTFRetreatGoals
777 ==================
778 */
779 void BotCTFRetreatGoals(bot_state_t *bs) {
780 //when carrying a flag in ctf the bot should rush to the base
781 if (BotCTFCarryingFlag(bs)) {
782 //if not already rushing to the base
783 if (bs->ltgtype != LTG_RUSHBASE) {
784 BotRefuseOrder(bs);
785 bs->ltgtype = LTG_RUSHBASE;
786 bs->teamgoal_time = FloatTime() + CTF_RUSHBASE_TIME;
787 bs->rushbaseaway_time = 0;
788 bs->decisionmaker = bs->client;
789 bs->ordered = qfalse;
790 BotSetTeamStatus(bs);
791 }
792 }
793 }
794
795 #ifdef MISSIONPACK
796 /*
797 ==================
798 Bot1FCTFSeekGoals
799 ==================
800 */
801 void Bot1FCTFSeekGoals(bot_state_t *bs) {
802 aas_entityinfo_t entinfo;
803 float rnd, l1, l2;
804 int c;
805
806 //when carrying a flag in ctf the bot should rush to the base
807 if (Bot1FCTFCarryingFlag(bs)) {
808 //if not already rushing to the base
809 if (bs->ltgtype != LTG_RUSHBASE) {
810 BotRefuseOrder(bs);
811 bs->ltgtype = LTG_RUSHBASE;
812 bs->teamgoal_time = FloatTime() + CTF_RUSHBASE_TIME;
813 bs->rushbaseaway_time = 0;
814 bs->decisionmaker = bs->client;
815 bs->ordered = qfalse;
816 //get an alternative route goal towards the enemy base
817 BotGetAlternateRouteGoal(bs, BotOppositeTeam(bs));
818 //
819 BotSetTeamStatus(bs);
820 BotVoiceChat(bs, -1, VOICECHAT_IHAVEFLAG);
821 }
822 return;
823 }
824 // if the bot decided to follow someone
825 if ( bs->ltgtype == LTG_TEAMACCOMPANY && !bs->ordered ) {
826 // if the team mate being accompanied no longer carries the flag
827 BotEntityInfo(bs->teammate, &entinfo);
828 if (!EntityCarriesFlag(&entinfo)) {
829 bs->ltgtype = 0;
830 }
831 }
832 //our team has the flag
833 if (bs->neutralflagstatus == 1) {
834 if (bs->owndecision_time < FloatTime()) {
835 // if not already following someone
836 if (bs->ltgtype != LTG_TEAMACCOMPANY) {
837 //if there is a visible team mate flag carrier
838 c = BotTeamFlagCarrierVisible(bs);
839 if (c >= 0) {
840 BotRefuseOrder(bs);
841 //follow the flag carrier
842 bs->decisionmaker = bs->client;
843 bs->ordered = qfalse;
844 //the team mate
845 bs->teammate = c;
846 //last time the team mate was visible
847 bs->teammatevisible_time = FloatTime();
848 //no message
849 bs->teammessage_time = 0;
850 //no arrive message
851 bs->arrive_time = 1;
852 //
853 BotVoiceChat(bs, bs->teammate, VOICECHAT_ONFOLLOW);
854 //get the team goal time
855 bs->teamgoal_time = FloatTime() + TEAM_ACCOMPANY_TIME;
856 bs->ltgtype = LTG_TEAMACCOMPANY;
857 bs->formation_dist = 3.5 * 32; //3.5 meter
858 BotSetTeamStatus(bs);
859 bs->owndecision_time = FloatTime() + 5;
860 return;
861 }
862 }
863 //if already a CTF or team goal
864 if (bs->ltgtype == LTG_TEAMHELP ||
865 bs->ltgtype == LTG_TEAMACCOMPANY ||
866 bs->ltgtype == LTG_DEFENDKEYAREA ||
867 bs->ltgtype == LTG_GETFLAG ||
868 bs->ltgtype == LTG_RUSHBASE ||
869 bs->ltgtype == LTG_CAMPORDER ||
870 bs->ltgtype == LTG_PATROL ||
871 bs->ltgtype == LTG_ATTACKENEMYBASE ||
872 bs->ltgtype == LTG_GETITEM ||
873 bs->ltgtype == LTG_MAKELOVE_UNDER ||
874 bs->ltgtype == LTG_MAKELOVE_ONTOP) {
875 return;
876 }
877 //if not already attacking the enemy base
878 if (bs->ltgtype != LTG_ATTACKENEMYBASE) {
879 BotRefuseOrder(bs);
880 bs->decisionmaker = bs->client;
881 bs->ordered = qfalse;
882 //
883 if (BotTeam(bs) == TEAM_RED) memcpy(&bs->teamgoal, &ctf_blueflag, sizeof(bot_goal_t));
884 else memcpy(&bs->teamgoal, &ctf_redflag, sizeof(bot_goal_t));
885 //set the ltg type
886 bs->ltgtype = LTG_ATTACKENEMYBASE;
887 //set the time the bot will stop getting the flag
888 bs->teamgoal_time = FloatTime() + TEAM_ATTACKENEMYBASE_TIME;
889 BotSetTeamStatus(bs);
890 bs->owndecision_time = FloatTime() + 5;
891 }
892 }
893 return;
894 }
895 //enemy team has the flag
896 else if (bs->neutralflagstatus == 2) {
897 if (bs->owndecision_time < FloatTime()) {
898 c = BotEnemyFlagCarrierVisible(bs);
899 if (c >= 0) {
900 //FIXME: attack enemy flag carrier
901 }
902 //if already a CTF or team goal
903 if (bs->ltgtype == LTG_TEAMHELP ||
904 bs->ltgtype == LTG_TEAMACCOMPANY ||
905 bs->ltgtype == LTG_CAMPORDER ||
906 bs->ltgtype == LTG_PATROL ||
907 bs->ltgtype == LTG_GETITEM) {
908 return;
909 }
910 // if not already defending the base
911 if (bs->ltgtype != LTG_DEFENDKEYAREA) {
912 BotRefuseOrder(bs);
913 bs->decisionmaker = bs->client;
914 bs->ordered = qfalse;
915 //
916 if (BotTeam(bs) == TEAM_RED) memcpy(&bs->teamgoal, &ctf_redflag, sizeof(bot_goal_t));
917 else memcpy(&bs->teamgoal, &ctf_blueflag, sizeof(bot_goal_t));
918 //set the ltg type
919 bs->ltgtype = LTG_DEFENDKEYAREA;
920 //set the time the bot stops defending the base
921 bs->teamgoal_time = FloatTime() + TEAM_DEFENDKEYAREA_TIME;
922 bs->defendaway_time = 0;
923 BotSetTeamStatus(bs);
924 bs->owndecision_time = FloatTime() + 5;
925 }
926 }
927 return;
928 }
929 // don't just do something wait for the bot team leader to give orders
930 if (BotTeamLeader(bs)) {
931 return;
932 }
933 // if the bot is ordered to do something
934 if ( bs->lastgoal_ltgtype ) {
935 bs->teamgoal_time += 60;
936 }
937 // if the bot decided to do something on its own and has a last ordered goal
938 if ( !bs->ordered && bs->lastgoal_ltgtype ) {
939 bs->ltgtype = 0;
940 }
941 //if already a CTF or team goal
942 if (bs->ltgtype == LTG_TEAMHELP ||
943 bs->ltgtype == LTG_TEAMACCOMPANY ||
944 bs->ltgtype == LTG_DEFENDKEYAREA ||
945 bs->ltgtype == LTG_GETFLAG ||
946 bs->ltgtype == LTG_RUSHBASE ||
947 bs->ltgtype == LTG_RETURNFLAG ||
948 bs->ltgtype == LTG_CAMPORDER ||
949 bs->ltgtype == LTG_PATROL ||
950 bs->ltgtype == LTG_ATTACKENEMYBASE ||
951 bs->ltgtype == LTG_GETITEM ||
952 bs->ltgtype == LTG_MAKELOVE_UNDER ||
953 bs->ltgtype == LTG_MAKELOVE_ONTOP) {
954 return;
955 }
956 //
957 if (BotSetLastOrderedTask(bs))
958 return;
959 //
960 if (bs->owndecision_time > FloatTime())
961 return;;
962 //if the bot is roaming
963 if (bs->ctfroam_time > FloatTime())
964 return;
965 //if the bot has enough aggression to decide what to do
966 if (BotAggression(bs) < 50)
967 return;
968 //set the time to send a message to the team mates
969 bs->teammessage_time = FloatTime() + 2 * random();
970 //
971 if (bs->teamtaskpreference & (TEAMTP_ATTACKER|TEAMTP_DEFENDER)) {
972 if (bs->teamtaskpreference & TEAMTP_ATTACKER) {
973 l1 = 0.7f;
974 }
975 else {
976 l1 = 0.2f;
977 }
978 l2 = 0.9f;
979 }
980 else {
981 l1 = 0.4f;
982 l2 = 0.7f;
983 }
984 //get the flag or defend the base
985 rnd = random();
986 if (rnd < l1 && ctf_neutralflag.areanum) {
987 bs->decisionmaker = bs->client;
988 bs->ordered = qfalse;
989 bs->ltgtype = LTG_GETFLAG;
990 //set the time the bot will stop getting the flag
991 bs->teamgoal_time = FloatTime() + CTF_GETFLAG_TIME;
992 BotSetTeamStatus(bs);
993 }
994 else if (rnd < l2 && ctf_redflag.areanum && ctf_blueflag.areanum) {
995 bs->decisionmaker = bs->client;
996 bs->ordered = qfalse;
997 //
998 if (BotTeam(bs) == TEAM_RED) memcpy(&bs->teamgoal, &ctf_redflag, sizeof(bot_goal_t));
999 else memcpy(&bs->teamgoal, &ctf_blueflag, sizeof(bot_goal_t));
1000 //set the ltg type
1001 bs->ltgtype = LTG_DEFENDKEYAREA;
1002 //set the time the bot stops defending the base
1003 bs->teamgoal_time = FloatTime() + TEAM_DEFENDKEYAREA_TIME;
1004 bs->defendaway_time = 0;
1005 BotSetTeamStatus(bs);
1006 }
1007 else {
1008 bs->ltgtype = 0;
1009 //set the time the bot will stop roaming
1010 bs->ctfroam_time = FloatTime() + CTF_ROAM_TIME;
1011 BotSetTeamStatus(bs);
1012 }
1013 bs->owndecision_time = FloatTime() + 5;
1014 #ifdef DEBUG
1015 BotPrintTeamGoal(bs);
1016 #endif //DEBUG
1017 }
1018
1019 /*
1020 ==================
1021 Bot1FCTFRetreatGoals
1022 ==================
1023 */
1024 void Bot1FCTFRetreatGoals(bot_state_t *bs) {
1025 //when carrying a flag in ctf the bot should rush to the enemy base
1026 if (Bot1FCTFCarryingFlag(bs)) {
1027 //if not already rushing to the base
1028 if (bs->ltgtype != LTG_RUSHBASE) {
1029 BotRefuseOrder(bs);
1030 bs->ltgtype = LTG_RUSHBASE;
1031 bs->teamgoal_time = FloatTime() + CTF_RUSHBASE_TIME;
1032 bs->rushbaseaway_time = 0;
1033 bs->decisionmaker = bs->client;
1034 bs->ordered = qfalse;
1035 //get an alternative route goal towards the enemy base
1036 BotGetAlternateRouteGoal(bs, BotOppositeTeam(bs));
1037 BotSetTeamStatus(bs);
1038 }
1039 }
1040 }
1041
1042 /*
1043 ==================
1044 BotObeliskSeekGoals
1045 ==================
1046 */
1047 void BotObeliskSeekGoals(bot_state_t *bs) {
1048 float rnd, l1, l2;
1049
1050 // don't just do something wait for the bot team leader to give orders
1051 if (BotTeamLeader(bs)) {
1052 return;
1053 }
1054 // if the bot is ordered to do something
1055 if ( bs->lastgoal_ltgtype ) {
1056 bs->teamgoal_time += 60;
1057 }
1058 //if already a team goal
1059 if (bs->ltgtype == LTG_TEAMHELP ||
1060 bs->ltgtype == LTG_TEAMACCOMPANY ||
1061 bs->ltgtype == LTG_DEFENDKEYAREA ||
1062 bs->ltgtype == LTG_GETFLAG ||
1063 bs->ltgtype == LTG_RUSHBASE ||
1064 bs->ltgtype == LTG_RETURNFLAG ||
1065 bs->ltgtype == LTG_CAMPORDER ||
1066 bs->ltgtype == LTG_PATROL ||
1067 bs->ltgtype == LTG_ATTACKENEMYBASE ||
1068 bs->ltgtype == LTG_GETITEM ||
1069 bs->ltgtype == LTG_MAKELOVE_UNDER ||
1070 bs->ltgtype == LTG_MAKELOVE_ONTOP) {
1071 return;
1072 }
1073 //
1074 if (BotSetLastOrderedTask(bs))
1075 return;
1076 //if the bot is roaming
1077 if (bs->ctfroam_time > FloatTime())
1078 return;
1079 //if the bot has enough aggression to decide what to do
1080 if (BotAggression(bs) < 50)
1081 return;
1082 //set the time to send a message to the team mates
1083 bs->teammessage_time = FloatTime() + 2 * random();
1084 //
1085 if (bs->teamtaskpreference & (TEAMTP_ATTACKER|TEAMTP_DEFENDER)) {
1086 if (bs->teamtaskpreference & TEAMTP_ATTACKER) {
1087 l1 = 0.7f;
1088 }
1089 else {
1090 l1 = 0.2f;
1091 }
1092 l2 = 0.9f;
1093 }
1094 else {
1095 l1 = 0.4f;
1096 l2 = 0.7f;
1097 }
1098 //get the flag or defend the base
1099 rnd = random();
1100 if (rnd < l1 && redobelisk.areanum && blueobelisk.areanum) {
1101 bs->decisionmaker = bs->client;
1102 bs->ordered = qfalse;
1103 //
1104 if (BotTeam(bs) == TEAM_RED) memcpy(&bs->teamgoal, &blueobelisk, sizeof(bot_goal_t));
1105 else memcpy(&bs->teamgoal, &redobelisk, sizeof(bot_goal_t));
1106 //set the ltg type
1107 bs->ltgtype = LTG_ATTACKENEMYBASE;
1108 //set the time the bot will stop attacking the enemy base
1109 bs->teamgoal_time = FloatTime() + TEAM_ATTACKENEMYBASE_TIME;
1110 //get an alternate route goal towards the enemy base
1111 BotGetAlternateRouteGoal(bs, BotOppositeTeam(bs));
1112 BotSetTeamStatus(bs);
1113 }
1114 else if (rnd < l2 && redobelisk.areanum && blueobelisk.areanum) {
1115 bs->decisionmaker = bs->client;
1116 bs->ordered = qfalse;
1117 //
1118 if (BotTeam(bs) == TEAM_RED) memcpy(&bs->teamgoal, &redobelisk, sizeof(bot_goal_t));
1119 else memcpy(&bs->teamgoal, &blueobelisk, sizeof(bot_goal_t));
1120 //set the ltg type
1121 bs->ltgtype = LTG_DEFENDKEYAREA;
1122 //set the time the bot stops defending the base
1123 bs->teamgoal_time = FloatTime() + TEAM_DEFENDKEYAREA_TIME;
1124 bs->defendaway_time = 0;
1125 BotSetTeamStatus(bs);
1126 }
1127 else {
1128 bs->ltgtype = 0;
1129 //set the time the bot will stop roaming
1130 bs->ctfroam_time = FloatTime() + CTF_ROAM_TIME;
1131 BotSetTeamStatus(bs);
1132 }
1133 }
1134
1135 /*
1136 ==================
1137 BotGoHarvest
1138 ==================
1139 */
1140 void BotGoHarvest(bot_state_t *bs) {
1141 //
1142 if (BotTeam(bs) == TEAM_RED) memcpy(&bs->teamgoal, &blueobelisk, sizeof(bot_goal_t));
1143 else memcpy(&bs->teamgoal, &redobelisk, sizeof(bot_goal_t));
1144 //set the ltg type
1145 bs->ltgtype = LTG_HARVEST;
1146 //set the time the bot will stop harvesting
1147 bs->teamgoal_time = FloatTime() + TEAM_HARVEST_TIME;
1148 bs->harvestaway_time = 0;
1149 BotSetTeamStatus(bs);
1150 }
1151
1152 /*
1153 ==================
1154 BotObeliskRetreatGoals
1155 ==================
1156 */
1157 void BotObeliskRetreatGoals(bot_state_t *bs) {
1158 //nothing special
1159 }
1160
1161 /*
1162 ==================
1163 BotHarvesterSeekGoals
1164 ==================
1165 */
1166 void BotHarvesterSeekGoals(bot_state_t *bs) {
1167 aas_entityinfo_t entinfo;
1168 float rnd, l1, l2;
1169 int c;
1170
1171 //when carrying cubes in harvester the bot should rush to the base
1172 if (BotHarvesterCarryingCubes(bs)) {
1173 //if not already rushing to the base
1174 if (bs->ltgtype != LTG_RUSHBASE) {
1175 BotRefuseOrder(bs);
1176 bs->ltgtype = LTG_RUSHBASE;
1177 bs->teamgoal_time = FloatTime() + CTF_RUSHBASE_TIME;
1178 bs->rushbaseaway_time = 0;
1179 bs->decisionmaker = bs->client;
1180 bs->ordered = qfalse;
1181 //get an alternative route goal towards the enemy base
1182 BotGetAlternateRouteGoal(bs, BotOppositeTeam(bs));
1183 //
1184 BotSetTeamStatus(bs);
1185 }
1186 return;
1187 }
1188 // don't just do something wait for the bot team leader to give orders
1189 if (BotTeamLeader(bs)) {
1190 return;
1191 }
1192 // if the bot decided to follow someone
1193 if ( bs->ltgtype == LTG_TEAMACCOMPANY && !bs->ordered ) {
1194 // if the team mate being accompanied no longer carries the flag
1195 BotEntityInfo(bs->teammate, &entinfo);
1196 if (!EntityCarriesCubes(&entinfo)) {
1197 bs->ltgtype = 0;
1198 }
1199 }
1200 // if the bot is ordered to do something
1201 if ( bs->lastgoal_ltgtype ) {
1202 bs->teamgoal_time += 60;
1203 }
1204 //if not yet doing something
1205 if (bs->ltgtype == LTG_TEAMHELP ||
1206 bs->ltgtype == LTG_TEAMACCOMPANY ||
1207 bs->ltgtype == LTG_DEFENDKEYAREA ||
1208 bs->ltgtype == LTG_GETFLAG ||
1209 bs->ltgtype == LTG_CAMPORDER ||
1210 bs->ltgtype == LTG_PATROL ||
1211 bs->ltgtype == LTG_ATTACKENEMYBASE ||
1212 bs->ltgtype == LTG_HARVEST ||
1213 bs->ltgtype == LTG_GETITEM ||
1214 bs->ltgtype == LTG_MAKELOVE_UNDER ||
1215 bs->ltgtype == LTG_MAKELOVE_ONTOP) {
1216 return;
1217 }
1218 //
1219 if (BotSetLastOrderedTask(bs))
1220 return;
1221 //if the bot is roaming
1222 if (bs->ctfroam_time > FloatTime())
1223 return;
1224 //if the bot has enough aggression to decide what to do
1225 if (BotAggression(bs) < 50)
1226 return;
1227 //set the time to send a message to the team mates
1228 bs->teammessage_time = FloatTime() + 2 * random();
1229 //
1230 c = BotEnemyCubeCarrierVisible(bs);
1231 if (c >= 0) {
1232 //FIXME: attack enemy cube carrier
1233 }
1234 if (bs->ltgtype != LTG_TEAMACCOMPANY) {
1235 //if there is a visible team mate carrying cubes
1236 c = BotTeamCubeCarrierVisible(bs);
1237 if (c >= 0) {
1238 //follow the team mate carrying cubes
1239 bs->decisionmaker = bs->client;
1240 bs->ordered = qfalse;
1241 //the team mate
1242 bs->teammate = c;
1243 //last time the team mate was visible
1244 bs->teammatevisible_time = FloatTime();
1245 //no message
1246 bs->teammessage_time = 0;
1247 //no arrive message
1248 bs->arrive_time = 1;
1249 //
1250 BotVoiceChat(bs, bs->teammate, VOICECHAT_ONFOLLOW);
1251 //get the team goal time
1252 bs->teamgoal_time = FloatTime() + TEAM_ACCOMPANY_TIME;
1253 bs->ltgtype = LTG_TEAMACCOMPANY;
1254 bs->formation_dist = 3.5 * 32; //3.5 meter
1255 BotSetTeamStatus(bs);
1256 return;
1257 }
1258 }
1259 //
1260 if (bs->teamtaskpreference & (TEAMTP_ATTACKER|TEAMTP_DEFENDER)) {
1261 if (bs->teamtaskpreference & TEAMTP_ATTACKER) {
1262 l1 = 0.7f;
1263 }
1264 else {
1265 l1 = 0.2f;
1266 }
1267 l2 = 0.9f;
1268 }
1269 else {
1270 l1 = 0.4f;
1271 l2 = 0.7f;
1272 }
1273 //
1274 rnd = random();
1275 if (rnd < l1 && redobelisk.areanum && blueobelisk.areanum) {
1276 bs->decisionmaker = bs->client;
1277 bs->ordered = qfalse;
1278 BotGoHarvest(bs);
1279 }
1280 else if (rnd < l2 && redobelisk.areanum && blueobelisk.areanum) {
1281 bs->decisionmaker = bs->client;
1282 bs->ordered = qfalse;
1283 //
1284 if (BotTeam(bs) == TEAM_RED) memcpy(&bs->teamgoal, &redobelisk, sizeof(bot_goal_t));
1285 else memcpy(&bs->teamgoal, &blueobelisk, sizeof(bot_goal_t));
1286 //set the ltg type
1287 bs->ltgtype = LTG_DEFENDKEYAREA;
1288 //set the time the bot stops defending the base
1289 bs->teamgoal_time = FloatTime() + TEAM_DEFENDKEYAREA_TIME;
1290 bs->defendaway_time = 0;
1291 BotSetTeamStatus(bs);
1292 }
1293 else {
1294 bs->ltgtype = 0;
1295 //set the time the bot will stop roaming
1296 bs->ctfroam_time = FloatTime() + CTF_ROAM_TIME;
1297 BotSetTeamStatus(bs);
1298 }
1299 }
1300
1301 /*
1302 ==================
1303 BotHarvesterRetreatGoals
1304 ==================
1305 */
1306 void BotHarvesterRetreatGoals(bot_state_t *bs) {
1307 //when carrying cubes in harvester the bot should rush to the base
1308 if (BotHarvesterCarryingCubes(bs)) {
1309 //if not already rushing to the base
1310 if (bs->ltgtype != LTG_RUSHBASE) {
1311 BotRefuseOrder(bs);
1312 bs->ltgtype = LTG_RUSHBASE;
1313 bs->teamgoal_time = FloatTime() + CTF_RUSHBASE_TIME;
1314 bs->rushbaseaway_time = 0;
1315 bs->decisionmaker = bs->client;
1316 bs->ordered = qfalse;
1317 BotSetTeamStatus(bs);
1318 }
1319 return;
1320 }
1321 }
1322 #endif
1323
1324 /*
1325 ==================
1326 BotTeamGoals
1327 ==================
1328 */
1329 void BotTeamGoals(bot_state_t *bs, int retreat) {
1330
1331 if ( retreat ) {
1332 if (gametype == GT_CTF) {
1333 BotCTFRetreatGoals(bs);
1334 }
1335 #ifdef MISSIONPACK
1336 else if (gametype == GT_1FCTF) {
1337 Bot1FCTFRetreatGoals(bs);
1338 }
1339 else if (gametype == GT_OBELISK) {
1340 BotObeliskRetreatGoals(bs);
1341 }
1342 else if (gametype == GT_HARVESTER) {
1343 BotHarvesterRetreatGoals(bs);
1344 }
1345 #endif
1346 }
1347 else {
1348 if (gametype == GT_CTF) {
1349 //decide what to do in CTF mode
1350 BotCTFSeekGoals(bs);
1351 }
1352 #ifdef MISSIONPACK
1353 else if (gametype == GT_1FCTF) {
1354 Bot1FCTFSeekGoals(bs);
1355 }
1356 else if (gametype == GT_OBELISK) {
1357 BotObeliskSeekGoals(bs);
1358 }
1359 else if (gametype == GT_HARVESTER) {
1360 BotHarvesterSeekGoals(bs);
1361 }
1362 #endif
1363 }
1364 // reset the order time which is used to see if
1365 // we decided to refuse an order
1366 bs->order_time = 0;
1367 }
1368
1369 /*
1370 ==================
1371 BotPointAreaNum
1372 ==================
1373 */
1374 int BotPointAreaNum(vec3_t origin) {
1375 int areanum, numareas, areas[10];
1376 vec3_t end;
1377
1378 areanum = trap_AAS_PointAreaNum(origin);
1379 if (areanum) return areanum;
1380 VectorCopy(origin, end);
1381 end[2] += 10;
1382 numareas = trap_AAS_TraceAreas(origin, end, areas, NULL, 10);
1383 if (numareas > 0) return areas[0];
1384 return 0;
1385 }
1386
1387 /*
1388 ==================
1389 ClientName
1390 ==================
1391 */
1392 char *ClientName(int client, char *name, int size) {
1393 char buf[MAX_INFO_STRING];
1394
1395 if (client < 0 || client >= MAX_CLIENTS) {
1396 BotAI_Print(PRT_ERROR, "ClientName: client out of range\n");
1397 return "[client out of range]";
1398 }
1399 trap_GetConfigstring(CS_PLAYERS+client, buf, sizeof(buf));
1400 Q_strncpyz(name, Info_ValueForKey(buf, "n"), size);
1401 Q_CleanStr( name );
1402 return name;
1403 }
1404
1405 /*
1406 ==================
1407 ClientSkin
1408 ==================
1409 */
1410 char *ClientSkin(int client, char *skin, int size) {
1411 char buf[MAX_INFO_STRING];
1412
1413 if (client < 0 || client >= MAX_CLIENTS) {
1414 BotAI_Print(PRT_ERROR, "ClientSkin: client out of range\n");
1415 return "[client out of range]";
1416 }
1417 trap_GetConfigstring(CS_PLAYERS+client, buf, sizeof(buf));
1418 Q_strncpyz(skin, Info_ValueForKey(buf, "model"), size);
1419 return skin;
1420 }
1421
1422 /*
1423 ==================
1424 ClientFromName
1425 ==================
1426 */
1427 int ClientFromName(char *name) {
1428 int i;
1429 char buf[MAX_INFO_STRING];
1430
1431 for (i = 0; i < level.maxclients; i++) {
1432 trap_GetConfigstring(CS_PLAYERS+i, buf, sizeof(buf));
1433 Q_CleanStr( buf );
1434 if (!Q_stricmp(Info_ValueForKey(buf, "n"), name)) return i;
1435 }
1436 return -1;
1437 }
1438
1439 /*
1440 ==================
1441 ClientOnSameTeamFromName
1442 ==================
1443 */
1444 int ClientOnSameTeamFromName(bot_state_t *bs, char *name) {
1445 int i;
1446 char buf[MAX_INFO_STRING];
1447
1448 for (i = 0; i < level.maxclients; i++) {
1449 if (!BotSameTeam(bs, i))
1450 continue;
1451 trap_GetConfigstring(CS_PLAYERS+i, buf, sizeof(buf));
1452 Q_CleanStr( buf );
1453 if (!Q_stricmp(Info_ValueForKey(buf, "n"), name)) return i;
1454 }
1455 return -1;
1456 }
1457
1458 /*
1459 ==================
1460 stristr
1461 ==================
1462 */
1463 char *stristr(char *str, char *charset) {
1464 int i;
1465
1466 while(*str) {
1467 for (i = 0; charset[i] && str[i]; i++) {
1468 if (toupper(charset[i]) != toupper(str[i])) break;
1469 }
1470 if (!charset[i]) return str;
1471 str++;
1472 }
1473 return NULL;
1474 }
1475
1476 /*
1477 ==================
1478 EasyClientName
1479 ==================
1480 */
1481 char *EasyClientName(int client, char *buf, int size) {
1482 int i;
1483 char *str1, *str2, *ptr, c;
1484 char name[128] = {0};
1485
1486 ClientName(client, name, sizeof(name));
1487
1488 for (i = 0; name[i]; i++) name[i] &= 127;
1489 //remove all spaces
1490 for (ptr = strstr(name, " "); ptr; ptr = strstr(name, " ")) {
1491 memmove(ptr, ptr+1, strlen(ptr+1)+1);
1492 }
1493 //check for [x] and ]x[ clan names
1494 str1 = strstr(name, "[");
1495 str2 = strstr(name, "]");
1496 if (str1 && str2) {
1497 if (str2 > str1) memmove(str1, str2+1, strlen(str2+1)+1);
1498 else memmove(str2, str1+1, strlen(str1+1)+1);
1499 }
1500 //remove Mr prefix
1501 if ((name[0] == 'm' || name[0] == 'M') &&
1502 (name[1] == 'r' || name[1] == 'R')) {
1503 memmove(name, name+2, strlen(name+2)+1);
1504 }
1505 //only allow lower case alphabet characters
1506 ptr = name;
1507 while(*ptr) {
1508 c = *ptr;
1509 if ((c >= 'a' && c <= 'z') ||
1510 (c >= '0' && c <= '9') || c == '_') {
1511 ptr++;
1512 }
1513 else if (c >= 'A' && c <= 'Z') {
1514 *ptr += 'a' - 'A';
1515 ptr++;
1516 }
1517 else {
1518 memmove(ptr, ptr+1, strlen(ptr + 1)+1);
1519 }
1520 }
1521 Q_strncpyz(buf, name, size);
1522 return buf;
1523 }
1524
1525 /*
1526 ==================
1527 BotSynonymContext
1528 ==================
1529 */
1530 int BotSynonymContext(bot_state_t *bs) {
1531 int context;
1532
1533 context = CONTEXT_NORMAL|CONTEXT_NEARBYITEM|CONTEXT_NAMES;
1534 //
1535 if (gametype == GT_CTF
1536 #ifdef MISSIONPACK
1537 || gametype == GT_1FCTF
1538 #endif
1539 ) {
1540 if (BotTeam(bs) == TEAM_RED) context |= CONTEXT_CTFREDTEAM;
1541 else context |= CONTEXT_CTFBLUETEAM;
1542 }
1543 #ifdef MISSIONPACK
1544 else if (gametype == GT_OBELISK) {
1545 if (BotTeam(bs) == TEAM_RED) context |= CONTEXT_OBELISKREDTEAM;
1546 else context |= CONTEXT_OBELISKBLUETEAM;
1547 }
1548 else if (gametype == GT_HARVESTER) {
1549 if (BotTeam(bs) == TEAM_RED) context |= CONTEXT_HARVESTERREDTEAM;
1550 else context |= CONTEXT_HARVESTERBLUETEAM;
1551 }
1552 #endif
1553 return context;
1554 }
1555
1556 /*
1557 ==================
1558 BotChooseWeapon
1559 ==================
1560 */
1561 void BotChooseWeapon(bot_state_t *bs) {
1562 int newweaponnum;
1563
1564 if (bs->cur_ps.weaponstate == WEAPON_RAISING ||
1565 bs->cur_ps.weaponstate == WEAPON_DROPPING) {
1566 trap_EA_SelectWeapon(bs->client, bs->weaponnum);
1567 }
1568 else {
1569 newweaponnum = trap_BotChooseBestFightWeapon(bs->ws, bs->inventory);
1570 if (bs->weaponnum != newweaponnum) bs->weaponchange_time = FloatTime();
1571 bs->weaponnum = newweaponnum;
1572 //BotAI_Print(PRT_MESSAGE, "bs->weaponnum = %d\n", bs->weaponnum);
1573 trap_EA_SelectWeapon(bs->client, bs->weaponnum);
1574 }
1575 }
1576
1577 /*
1578 ==================
1579 BotSetupForMovement
1580 ==================
1581 */
1582 void BotSetupForMovement(bot_state_t *bs) {
1583 bot_initmove_t initmove;
1584
1585 memset(&initmove, 0, sizeof(bot_initmove_t));
1586 VectorCopy(bs->cur_ps.origin, initmove.origin);
1587 VectorCopy(bs->cur_ps.velocity, initmove.velocity);
1588 VectorClear(initmove.viewoffset);
1589 initmove.viewoffset[2] += bs->cur_ps.viewheight;
1590 initmove.entitynum = bs->entitynum;
1591 initmove.client = bs->client;
1592 initmove.thinktime = bs->thinktime;
1593 //set the onground flag
1594 if (bs->cur_ps.groundEntityNum != ENTITYNUM_NONE) initmove.or_moveflags |= MFL_ONGROUND;
1595 //set the teleported flag
1596 if ((bs->cur_ps.pm_flags & PMF_TIME_KNOCKBACK) && (bs->cur_ps.pm_time > 0)) {
1597 initmove.or_moveflags |= MFL_TELEPORTED;
1598 }
1599 //set the waterjump flag
1600 if ((bs->cur_ps.pm_flags & PMF_TIME_WATERJUMP) && (bs->cur_ps.pm_time > 0)) {
1601 initmove.or_moveflags |= MFL_WATERJUMP;
1602 }
1603 //set presence type
1604 if (bs->cur_ps.pm_flags & PMF_DUCKED) initmove.presencetype = PRESENCE_CROUCH;
1605 else initmove.presencetype = PRESENCE_NORMAL;
1606 //
1607 if (bs->walker > 0.5) initmove.or_moveflags |= MFL_WALK;
1608 //
1609 VectorCopy(bs->viewangles, initmove.viewangles);
1610 //
1611 trap_BotInitMoveState(bs->ms, &initmove);
1612 }
1613
1614 /*
1615 ==================
1616 BotCheckItemPickup
1617 ==================
1618 */
1619 void BotCheckItemPickup(bot_state_t *bs, int *oldinventory) {
1620 #ifdef MISSIONPACK
1621 int offence, leader;
1622
1623 if (gametype <= GT_TEAM)
1624 return;
1625
1626 offence = -1;
1627 // go into offence if picked up the kamikaze or invulnerability
1628 if (!oldinventory[INVENTORY_KAMIKAZE] && bs->inventory[INVENTORY_KAMIKAZE] >= 1) {
1629 offence = qtrue;
1630 }
1631 if (!oldinventory[INVENTORY_INVULNERABILITY] && bs->inventory[INVENTORY_INVULNERABILITY] >= 1) {
1632 offence = qtrue;
1633 }
1634 // if not already wearing the kamikaze or invulnerability
1635 if (!bs->inventory[INVENTORY_KAMIKAZE] && !bs->inventory[INVENTORY_INVULNERABILITY]) {
1636 if (!oldinventory[INVENTORY_SCOUT] && bs->inventory[INVENTORY_SCOUT] >= 1) {
1637 offence = qtrue;
1638 }
1639 if (!oldinventory[INVENTORY_GUARD] && bs->inventory[INVENTORY_GUARD] >= 1) {
1640 offence = qtrue;
1641 }
1642 if (!oldinventory[INVENTORY_DOUBLER] && bs->inventory[INVENTORY_DOUBLER] >= 1) {
1643 offence = qfalse;
1644 }
1645 if (!oldinventory[INVENTORY_AMMOREGEN] && bs->inventory[INVENTORY_AMMOREGEN] >= 1) {
1646 offence = qfalse;
1647 }
1648 }
1649
1650 if (offence >= 0) {
1651 leader = ClientFromName(bs->teamleader);
1652 if (offence) {
1653 if (!(bs->teamtaskpreference & TEAMTP_ATTACKER)) {
1654 // if we have a bot team leader
1655 if (BotTeamLeader(bs)) {
1656 // tell the leader we want to be on offence
1657 BotVoiceChat(bs, leader, VOICECHAT_WANTONOFFENSE);
1658 //BotAI_BotInitialChat(bs, "wantoffence", NULL);
1659 //trap_BotEnterChat(bs->cs, leader, CHAT_TELL);
1660 }
1661 else if (g_spSkill.integer <= 3) {
1662 if ( bs->ltgtype != LTG_GETFLAG &&
1663 bs->ltgtype != LTG_ATTACKENEMYBASE &&
1664 bs->ltgtype != LTG_HARVEST ) {
1665 //
1666 if ((gametype != GT_CTF || (bs->redflagstatus == 0 && bs->blueflagstatus == 0)) &&
1667 (gametype != GT_1FCTF || bs->neutralflagstatus == 0) ) {
1668 // tell the leader we want to be on offence
1669 BotVoiceChat(bs, leader, VOICECHAT_WANTONOFFENSE);
1670 //BotAI_BotInitialChat(bs, "wantoffence", NULL);
1671 //trap_BotEnterChat(bs->cs, leader, CHAT_TELL);
1672 }
1673 }
1674 }
1675 bs->teamtaskpreference |= TEAMTP_ATTACKER;
1676 }
1677 bs->teamtaskpreference &= ~TEAMTP_DEFENDER;
1678 }
1679 else {
1680 if (!(bs->teamtaskpreference & TEAMTP_DEFENDER)) {
1681 // if we have a bot team leader
1682 if (BotTeamLeader(bs)) {
1683 // tell the leader we want to be on defense
1684 BotVoiceChat(bs, -1, VOICECHAT_WANTONDEFENSE);
1685 //BotAI_BotInitialChat(bs, "wantdefence", NULL);
1686 //trap_BotEnterChat(bs->cs, leader, CHAT_TELL);
1687 }
1688 else if (g_spSkill.integer <= 3) {
1689 if ( bs->ltgtype != LTG_DEFENDKEYAREA ) {
1690 //
1691 if ((gametype != GT_CTF || (bs->redflagstatus == 0 && bs->blueflagstatus == 0)) &&
1692 (gametype != GT_1FCTF || bs->neutralflagstatus == 0) ) {
1693 // tell the leader we want to be on defense
1694 BotVoiceChat(bs, -1, VOICECHAT_WANTONDEFENSE);
1695 //BotAI_BotInitialChat(bs, "wantdefence", NULL);
1696 //trap_BotEnterChat(bs->cs, leader, CHAT_TELL);
1697 }
1698 }
1699 }
1700 bs->teamtaskpreference |= TEAMTP_DEFENDER;
1701 }
1702 bs->teamtaskpreference &= ~TEAMTP_ATTACKER;
1703 }
1704 }
1705 #endif
1706 }
1707
1708 /*
1709 ==================
1710 BotUpdateInventory
1711 ==================
1712 */
1713 void BotUpdateInventory(bot_state_t *bs) {
1714 int oldinventory[MAX_ITEMS];
1715
1716 memcpy(oldinventory, bs->inventory, sizeof(oldinventory));
1717 //armor
1718 bs->inventory[INVENTORY_ARMOR] = bs->cur_ps.stats[STAT_ARMOR];
1719 //weapons
1720 bs->inventory[INVENTORY_GAUNTLET] = (bs->cur_ps.stats[STAT_WEAPONS] & (1 << WP_GAUNTLET)) != 0;
1721 bs->inventory[INVENTORY_SHOTGUN] = (bs->cur_ps.stats[STAT_WEAPONS] & (1 << WP_SHOTGUN)) != 0;
1722 bs->inventory[INVENTORY_MACHINEGUN] = (bs->cur_ps.stats[STAT_WEAPONS] & (1 << WP_MACHINEGUN)) != 0;
1723 bs->inventory[INVENTORY_GRENADELAUNCHER] = (bs->cur_ps.stats[STAT_WEAPONS] & (1 << WP_GRENADE_LAUNCHER)) != 0;
1724 bs->inventory[INVENTORY_ROCKETLAUNCHER] = (bs->cur_ps.stats[STAT_WEAPONS] & (1 << WP_ROCKET_LAUNCHER)) != 0;
1725 bs->inventory[INVENTORY_LIGHTNING] = (bs->cur_ps.stats[STAT_WEAPONS] & (1 << WP_LIGHTNING)) != 0;
1726 bs->inventory[INVENTORY_RAILGUN] = (bs->cur_ps.stats[STAT_WEAPONS] & (1 << WP_RAILGUN)) != 0;
1727 bs->inventory[INVENTORY_PLASMAGUN] = (bs->cur_ps.stats[STAT_WEAPONS] & (1 << WP_PLASMAGUN)) != 0;
1728 bs->inventory[INVENTORY_BFG10K] = (bs->cur_ps.stats[STAT_WEAPONS] & (1 << WP_BFG)) != 0;
1729 bs->inventory[INVENTORY_GRAPPLINGHOOK] = (bs->cur_ps.stats[STAT_WEAPONS] & (1 << WP_GRAPPLING_HOOK)) != 0;
1730 #ifdef MISSIONPACK
1731 bs->inventory[INVENTORY_NAILGUN] = (bs->cur_ps.stats[STAT_WEAPONS] & (1 << WP_NAILGUN)) != 0;;
1732 bs->inventory[INVENTORY_PROXLAUNCHER] = (bs->cur_ps.stats[STAT_WEAPONS] & (1 << WP_PROX_LAUNCHER)) != 0;;
1733 bs->inventory[INVENTORY_CHAINGUN] = (bs->cur_ps.stats[STAT_WEAPONS] & (1 << WP_CHAINGUN)) != 0;;
1734 #endif
1735 //ammo
1736 bs->inventory[INVENTORY_SHELLS] = bs->cur_ps.ammo[WP_SHOTGUN];
1737 bs->inventory[INVENTORY_BULLETS] = bs->cur_ps.ammo[WP_MACHINEGUN];
1738 bs->inventory[INVENTORY_GRENADES] = bs->cur_ps.ammo[WP_GRENADE_LAUNCHER];
1739 bs->inventory[INVENTORY_CELLS] = bs->cur_ps.ammo[WP_PLASMAGUN];
1740 bs->inventory[INVENTORY_LIGHTNINGAMMO] = bs->cur_ps.ammo[WP_LIGHTNING];
1741 bs->inventory[INVENTORY_ROCKETS] = bs->cur_ps.ammo[WP_ROCKET_LAUNCHER];
1742 bs->inventory[INVENTORY_SLUGS] = bs->cur_ps.ammo[WP_RAILGUN];
1743 bs->inventory[INVENTORY_BFGAMMO] = bs->cur_ps.ammo[WP_BFG];
1744 #ifdef MISSIONPACK
1745 bs->inventory[INVENTORY_NAILS] = bs->cur_ps.ammo[WP_NAILGUN];
1746 bs->inventory[INVENTORY_MINES] = bs->cur_ps.ammo[WP_PROX_LAUNCHER];
1747 bs->inventory[INVENTORY_BELT] = bs->cur_ps.ammo[WP_CHAINGUN];
1748 #endif
1749 //powerups
1750 bs->inventory[INVENTORY_HEALTH] = bs->cur_ps.stats[STAT_HEALTH];
1751 bs->inventory[INVENTORY_TELEPORTER] = bs->cur_ps.stats[STAT_HOLDABLE_ITEM] == MODELINDEX_TELEPORTER;
1752 bs->inventory[INVENTORY_MEDKIT] = bs->cur_ps.stats[STAT_HOLDABLE_ITEM] == MODELINDEX_MEDKIT;
1753 #ifdef MISSIONPACK
1754 bs->inventory[INVENTORY_KAMIKAZE] = bs->cur_ps.stats[STAT_HOLDABLE_ITEM] == MODELINDEX_KAMIKAZE;
1755 bs->inventory[INVENTORY_PORTAL] = bs->cur_ps.stats[STAT_HOLDABLE_ITEM] == MODELINDEX_PORTAL;
1756 bs->inventory[INVENTORY_INVULNERABILITY] = bs->cur_ps.stats[STAT_HOLDABLE_ITEM] == MODELINDEX_INVULNERABILITY;
1757 #endif
1758 bs->inventory[INVENTORY_QUAD] = bs->cur_ps.powerups[PW_QUAD] != 0;
1759 bs->inventory[INVENTORY_ENVIRONMENTSUIT] = bs->cur_ps.powerups[PW_BATTLESUIT] != 0;
1760 bs->inventory[INVENTORY_HASTE] = bs->cur_ps.powerups[PW_HASTE] != 0;
1761 bs->inventory[INVENTORY_INVISIBILITY] = bs->cur_ps.powerups[PW_INVIS] != 0;
1762 bs->inventory[INVENTORY_REGEN] = bs->cur_ps.powerups[PW_REGEN] != 0;
1763 bs->inventory[INVENTORY_FLIGHT] = bs->cur_ps.powerups[PW_FLIGHT] != 0;
1764 #ifdef MISSIONPACK
1765 bs->inventory[INVENTORY_SCOUT] = bs->cur_ps.stats[STAT_PERSISTANT_POWERUP] == MODELINDEX_SCOUT;
1766 bs->inventory[INVENTORY_GUARD] = bs->cur_ps.stats[STAT_PERSISTANT_POWERUP] == MODELINDEX_GUARD;
1767 bs->inventory[INVENTORY_DOUBLER] = bs->cur_ps.stats[STAT_PERSISTANT_POWERUP] == MODELINDEX_DOUBLER;
1768 bs->inventory[INVENTORY_AMMOREGEN] = bs->cur_ps.stats[STAT_PERSISTANT_POWERUP] == MODELINDEX_AMMOREGEN;
1769 #endif
1770 bs->inventory[INVENTORY_REDFLAG] = bs->cur_ps.powerups[PW_REDFLAG] != 0;
1771 bs->inventory[INVENTORY_BLUEFLAG] = bs->cur_ps.powerups[PW_BLUEFLAG] != 0;
1772 #ifdef MISSIONPACK
1773 bs->inventory[INVENTORY_NEUTRALFLAG] = bs->cur_ps.powerups[PW_NEUTRALFLAG] != 0;
1774 if (BotTeam(bs) == TEAM_RED) {
1775 bs->inventory[INVENTORY_REDCUBE] = bs->cur_ps.generic1;
1776 bs->inventory[INVENTORY_BLUECUBE] = 0;
1777 }
1778 else {
1779 bs->inventory[INVENTORY_REDCUBE] = 0;
1780 bs->inventory[INVENTORY_BLUECUBE] = bs->cur_ps.generic1;
1781 }
1782 #endif
1783 BotCheckItemPickup(bs, oldinventory);
1784 }
1785
1786 /*
1787 ==================
1788 BotUpdateBattleInventory
1789 ==================
1790 */
1791 void BotUpdateBattleInventory(bot_state_t *bs, int enemy) {
1792 vec3_t dir;
1793 aas_entityinfo_t entinfo;
1794
1795 BotEntityInfo(enemy, &entinfo);
1796 VectorSubtract(entinfo.origin, bs->origin, dir);
1797 bs->inventory[ENEMY_HEIGHT] = (int) dir[2];
1798 dir[2] = 0;
1799 bs->inventory[ENEMY_HORIZONTAL_DIST] = (int) VectorLength(dir);
1800 //FIXME: add num visible enemies and num visible team mates to the inventory
1801 }
1802
1803 #ifdef MISSIONPACK
1804 /*
1805 ==================
1806 BotUseKamikaze
1807 ==================
1808 */
1809 #define KAMIKAZE_DIST 1024
1810
1811 void BotUseKamikaze(bot_state_t *bs) {
1812 int c, teammates, enemies;
1813 aas_entityinfo_t entinfo;
1814 vec3_t dir, target;
1815 bot_goal_t *goal;
1816 bsp_trace_t trace;
1817
1818 //if the bot has no kamikaze
1819 if (bs->inventory[INVENTORY_KAMIKAZE] <= 0)
1820 return;
1821 if (bs->kamikaze_time > FloatTime())
1822 return;
1823 bs->kamikaze_time = FloatTime() + 0.2;
1824 if (gametype == GT_CTF) {
1825 //never use kamikaze if the team flag carrier is visible
1826 if (BotCTFCarryingFlag(bs))
1827 return;
1828 c = BotTeamFlagCarrierVisible(bs);
1829 if (c >= 0) {
1830 BotEntityInfo(c, &entinfo);
1831 VectorSubtract(entinfo.origin, bs->origin, dir);
1832 if (VectorLengthSquared(dir) < Square(KAMIKAZE_DIST))
1833 return;
1834 }
1835 c = BotEnemyFlagCarrierVisible(bs);
1836 if (c >= 0) {
1837 BotEntityInfo(c, &entinfo);
1838 VectorSubtract(entinfo.origin, bs->origin, dir);
1839 if (VectorLengthSquared(dir) < Square(KAMIKAZE_DIST)) {
1840 trap_EA_Use(bs->client);
1841 return;
1842 }
1843 }
1844 }
1845 else if (gametype == GT_1FCTF) {
1846 //never use kamikaze if the team flag carrier is visible
1847 if (Bot1FCTFCarryingFlag(bs))
1848 return;
1849 c = BotTeamFlagCarrierVisible(bs);
1850 if (c >= 0) {
1851 BotEntityInfo(c, &entinfo);
1852 VectorSubtract(entinfo.origin, bs->origin, dir);
1853 if (VectorLengthSquared(dir) < Square(KAMIKAZE_DIST))
1854 return;
1855 }
1856 c = BotEnemyFlagCarrierVisible(bs);
1857 if (c >= 0) {
1858 BotEntityInfo(c, &entinfo);
1859 VectorSubtract(entinfo.origin, bs->origin, dir);
1860 if (VectorLengthSquared(dir) < Square(KAMIKAZE_DIST)) {
1861 trap_EA_Use(bs->client);
1862 return;
1863 }
1864 }
1865 }
1866 else if (gametype == GT_OBELISK) {
1867 switch(BotTeam(bs)) {
1868 case TEAM_RED: goal = &blueobelisk; break;
1869 default: goal = &redobelisk; break;
1870 }
1871 //if the obelisk is visible
1872 VectorCopy(goal->origin, target);
1873 target[2] += 1;
1874 VectorSubtract(bs->origin, target, dir);
1875 if (VectorLengthSquared(dir) < Square(KAMIKAZE_DIST * 0.9)) {
1876 BotAI_Trace(&trace, bs->eye, NULL, NULL, target, bs->client, CONTENTS_SOLID);
1877 if (trace.fraction >= 1 || trace.ent == goal->entitynum) {
1878 trap_EA_Use(bs->client);
1879 return;
1880 }
1881 }
1882 }
1883 else if (gametype == GT_HARVESTER) {
1884 //
1885 if (BotHarvesterCarryingCubes(bs))
1886 return;
1887 //never use kamikaze if a team mate carrying cubes is visible
1888 c = BotTeamCubeCarrierVisible(bs);
1889 if (c >= 0) {
1890 BotEntityInfo(c, &entinfo);
1891 VectorSubtract(entinfo.origin, bs->origin, dir);
1892 if (VectorLengthSquared(dir) < Square(KAMIKAZE_DIST))
1893 return;
1894 }
1895 c = BotEnemyCubeCarrierVisible(bs);
1896 if (c >= 0) {
1897 BotEntityInfo(c, &entinfo);
1898 VectorSubtract(entinfo.origin, bs->origin, dir);
1899 if (VectorLengthSquared(dir) < Square(KAMIKAZE_DIST)) {
1900 trap_EA_Use(bs->client);
1901 return;
1902 }
1903 }
1904 }
1905 //
1906 BotVisibleTeamMatesAndEnemies(bs, &teammates, &enemies, KAMIKAZE_DIST);
1907 //
1908 if (enemies > 2 && enemies > teammates+1) {
1909 trap_EA_Use(bs->client);
1910 return;
1911 }
1912 }
1913
1914 /*
1915 ==================
1916 BotUseInvulnerability
1917 ==================
1918 */
1919 void BotUseInvulnerability(bot_state_t *bs) {
1920 int c;
1921 vec3_t dir, target;
1922 bot_goal_t *goal;
1923 bsp_trace_t trace;
1924
1925 //if the bot has no invulnerability
1926 if (bs->inventory[INVENTORY_INVULNERABILITY] <= 0)
1927 return;
1928 if (bs->invulnerability_time > FloatTime())
1929 return;
1930 bs->invulnerability_time = FloatTime() + 0.2;
1931 if (gametype == GT_CTF) {
1932 //never use kamikaze if the team flag carrier is visible
1933 if (BotCTFCarryingFlag(bs))
1934 return;
1935 c = BotEnemyFlagCarrierVisible(bs);
1936 if (c >= 0)
1937 return;
1938 //if near enemy flag and the flag is visible
1939 switch(BotTeam(bs)) {
1940 case TEAM_RED: goal = &ctf_blueflag; break;
1941 default: goal = &ctf_redflag; break;
1942 }
1943 //if the obelisk is visible
1944 VectorCopy(goal->origin, target);
1945 target[2] += 1;
1946 VectorSubtract(bs->origin, target, dir);
1947 if (VectorLengthSquared(dir) < Square(200)) {
1948 BotAI_Trace(&trace, bs->eye, NULL, NULL, target, bs->client, CONTENTS_SOLID);
1949 if (trace.fraction >= 1 || trace.ent == goal->entitynum) {
1950 trap_EA_Use(bs->client);
1951 return;
1952 }
1953 }
1954 }
1955 else if (gametype == GT_1FCTF) {
1956 //never use kamikaze if the team flag carrier is visible
1957 if (Bot1FCTFCarryingFlag(bs))
1958 return;
1959 c = BotEnemyFlagCarrierVisible(bs);
1960 if (c >= 0)
1961 return;
1962 //if near enemy flag and the flag is visible
1963 switch(BotTeam(bs)) {
1964 case TEAM_RED: goal = &ctf_blueflag; break;
1965 default: goal = &ctf_redflag; break;
1966 }
1967 //if the obelisk is visible
1968 VectorCopy(goal->origin, target);
1969 target[2] += 1;
1970 VectorSubtract(bs->origin, target, dir);
1971 if (VectorLengthSquared(dir) < Square(200)) {
1972 BotAI_Trace(&trace, bs->eye, NULL, NULL, target, bs->client, CONTENTS_SOLID);
1973 if (trace.fraction >= 1 || trace.ent == goal->entitynum) {
1974 trap_EA_Use(bs->client);
1975 return;
1976 }
1977 }
1978 }
1979 else if (gametype == GT_OBELISK) {
1980 switch(BotTeam(bs)) {
1981 case TEAM_RED: goal = &blueobelisk; break;
1982 default: goal = &redobelisk; break;
1983 }
1984 //if the obelisk is visible
1985 VectorCopy(goal->origin, target);
1986 target[2] += 1;
1987 VectorSubtract(bs->origin, target, dir);
1988 if (VectorLengthSquared(dir) < Square(300)) {
1989 BotAI_Trace(&trace, bs->eye, NULL, NULL, target, bs->client, CONTENTS_SOLID);
1990 if (trace.fraction >= 1 || trace.ent == goal->entitynum) {
1991 trap_EA_Use(bs->client);
1992 return;
1993 }
1994 }
1995 }
1996 else if (gametype == GT_HARVESTER) {
1997 //
1998 if (BotHarvesterCarryingCubes(bs))
1999 return;
2000 c = BotEnemyCubeCarrierVisible(bs);
2001 if (c >= 0)
2002 return;
2003 //if near enemy base and enemy base is visible
2004 switch(BotTeam(bs)) {
2005 case TEAM_RED: goal = &blueobelisk; break;
2006 default: goal = &redobelisk; break;
2007 }
2008 //if the obelisk is visible
2009 VectorCopy(goal->origin, target);
2010 target[2] += 1;
2011 VectorSubtract(bs->origin, target, dir);
2012 if (VectorLengthSquared(dir) < Square(200)) {
2013 BotAI_Trace(&trace, bs->eye, NULL, NULL, target, bs->client, CONTENTS_SOLID);
2014 if (trace.fraction >= 1 || trace.ent == goal->entitynum) {
2015 trap_EA_Use(bs->client);
2016 return;
2017 }
2018 }
2019 }
2020 }
2021 #endif
2022
2023 /*
2024 ==================
2025 BotBattleUseItems
2026 ==================
2027 */
2028 void BotBattleUseItems(bot_state_t *bs) {
2029 if (bs->inventory[INVENTORY_HEALTH] < 40) {
2030 if (bs->inventory[INVENTORY_TELEPORTER] > 0) {
2031 if (!BotCTFCarryingFlag(bs)
2032 #ifdef MISSIONPACK
2033 && !Bot1FCTFCarryingFlag(bs)
2034 && !BotHarvesterCarryingCubes(bs)
2035 #endif
2036 ) {
2037 trap_EA_Use(bs->client);
2038 }
2039 }
2040 }
2041 if (bs->inventory[INVENTORY_HEALTH] < 60) {
2042 if (bs->inventory[INVENTORY_MEDKIT] > 0) {
2043 trap_EA_Use(bs->client);
2044 }
2045 }
2046 #ifdef MISSIONPACK
2047 BotUseKamikaze(bs);
2048 BotUseInvulnerability(bs);
2049 #endif
2050 }
2051
2052 /*
2053 ==================
2054 BotSetTeleportTime
2055 ==================
2056 */
2057 void BotSetTeleportTime(bot_state_t *bs) {
2058 if ((bs->cur_ps.eFlags ^ bs->last_eFlags) & EF_TELEPORT_BIT) {
2059 bs->teleport_time = FloatTime();
2060 }
2061 bs->last_eFlags = bs->cur_ps.eFlags;
2062 }
2063
2064 /*
2065 ==================
2066 BotIsDead
2067 ==================
2068 */
2069 qboolean BotIsDead(bot_state_t *bs) {
2070 return (bs->cur_ps.pm_type == PM_DEAD);
2071 }
2072
2073 /*
2074 ==================
2075 BotIsObserver
2076 ==================
2077 */
2078 qboolean BotIsObserver(bot_state_t *bs) {
2079 char buf[MAX_INFO_STRING];
2080 if (bs->cur_ps.pm_type == PM_SPECTATOR) return qtrue;
2081 trap_GetConfigstring(CS_PLAYERS+bs->client, buf, sizeof(buf));
2082 if (atoi(Info_ValueForKey(buf, "t")) == TEAM_SPECTATOR) return qtrue;
2083 return qfalse;
2084 }
2085
2086 /*
2087 ==================
2088 BotIntermission
2089 ==================
2090 */
2091 qboolean BotIntermission(bot_state_t *bs) {
2092 //NOTE: we shouldn't be looking at the game code...
2093 if (level.intermissiontime) return qtrue;
2094 return (bs->cur_ps.pm_type == PM_FREEZE || bs->cur_ps.pm_type == PM_INTERMISSION);
2095 }
2096
2097 /*
2098 ==================
2099 BotInLavaOrSlime
2100 ==================
2101 */
2102 qboolean BotInLavaOrSlime(bot_state_t *bs) {
2103 vec3_t feet;
2104
2105 VectorCopy(bs->origin, feet);
2106 feet[2] -= 23;
2107 return (trap_AAS_PointContents(feet) & (CONTENTS_LAVA|CONTENTS_SLIME));
2108 }
2109
2110 /*
2111 ==================
2112 BotCreateWayPoint
2113 ==================
2114 */
2115 bot_waypoint_t *BotCreateWayPoint(char *name, vec3_t origin, int areanum) {
2116 bot_waypoint_t *wp;
2117 vec3_t waypointmins = {-8, -8, -8}, waypointmaxs = {8, 8, 8};
2118
2119 wp = botai_freewaypoints;
2120 if ( !wp ) {
2121 BotAI_Print( PRT_WARNING, "BotCreateWayPoint: Out of waypoints\n" );
2122 return NULL;
2123 }
2124 botai_freewaypoints = botai_freewaypoints->next;
2125
2126 Q_strncpyz( wp->name, name, sizeof(wp->name) );
2127 VectorCopy(origin, wp->goal.origin);
2128 VectorCopy(waypointmins, wp->goal.mins);
2129 VectorCopy(waypointmaxs, wp->goal.maxs);
2130 wp->goal.areanum = areanum;
2131 wp->next = NULL;
2132 wp->prev = NULL;
2133 return wp;
2134 }
2135
2136 /*
2137 ==================
2138 BotFindWayPoint
2139 ==================
2140 */
2141 bot_waypoint_t *BotFindWayPoint(bot_waypoint_t *waypoints, char *name) {
2142 bot_waypoint_t *wp;
2143
2144 for (wp = waypoints; wp; wp = wp->next) {
2145 if (!Q_stricmp(wp->name, name)) return wp;
2146 }
2147 return NULL;
2148 }
2149
2150 /*
2151 ==================
2152 BotFreeWaypoints
2153 ==================
2154 */
2155 void BotFreeWaypoints(bot_waypoint_t *wp) {
2156 bot_waypoint_t *nextwp;
2157
2158 for (; wp; wp = nextwp) {
2159 nextwp = wp->next;
2160 wp->next = botai_freewaypoints;
2161 botai_freewaypoints = wp;
2162 }
2163 }
2164
2165 /*
2166 ==================
2167 BotInitWaypoints
2168 ==================
2169 */
2170 void BotInitWaypoints(void) {
2171 int i;
2172
2173 botai_freewaypoints = NULL;
2174 for (i = 0; i < MAX_WAYPOINTS; i++) {
2175 botai_waypoints[i].next = botai_freewaypoints;
2176 botai_freewaypoints = &botai_waypoints[i];
2177 }
2178 }
2179
2180 /*
2181 ==================
2182 TeamPlayIsOn
2183 ==================
2184 */
2185 int TeamPlayIsOn(void) {
2186 return ( gametype >= GT_TEAM );
2187 }
2188
2189 /*
2190 ==================
2191 BotAggression
2192 ==================
2193 */
2194 float BotAggression(bot_state_t *bs) {
2195 //if the bot has quad
2196 if (bs->inventory[INVENTORY_QUAD]) {
2197 //if the bot is not holding the gauntlet or the enemy is really nearby
2198 if (bs->weaponnum != WP_GAUNTLET ||
2199 bs->inventory[ENEMY_HORIZONTAL_DIST] < 80) {
2200 return 70;
2201 }
2202 }
2203 //if the enemy is located way higher than the bot
2204 if (bs->inventory[ENEMY_HEIGHT] > 200) return 0;
2205 //if the bot is very low on health
2206 if (bs->inventory[INVENTORY_HEALTH] < 60) return 0;
2207 //if the bot is low on health
2208 if (bs->inventory[INVENTORY_HEALTH] < 80) {
2209 //if the bot has insufficient armor
2210 if (bs->inventory[INVENTORY_ARMOR] < 40) return 0;
2211 }
2212 //if the bot can use the bfg
2213 if (bs->inventory[INVENTORY_BFG10K] > 0 &&
2214 bs->inventory[INVENTORY_BFGAMMO] > 7) return 100;
2215 //if the bot can use the railgun
2216 if (bs->inventory[INVENTORY_RAILGUN] > 0 &&
2217 bs->inventory[INVENTORY_SLUGS] > 5) return 95;
2218 //if the bot can use the lightning gun
2219 if (bs->inventory[INVENTORY_LIGHTNING] > 0 &&
2220 bs->inventory[INVENTORY_LIGHTNINGAMMO] > 50) return 90;
2221 //if the bot can use the rocketlauncher
2222 if (bs->inventory[INVENTORY_ROCKETLAUNCHER] > 0 &&
2223 bs->inventory[INVENTORY_ROCKETS] > 5) return 90;
2224 //if the bot can use the plasmagun
2225 if (bs->inventory[INVENTORY_PLASMAGUN] > 0 &&
2226 bs->inventory[INVENTORY_CELLS] > 40) return 85;
2227 //if the bot can use the grenade launcher
2228 if (bs->inventory[INVENTORY_GRENADELAUNCHER] > 0 &&
2229 bs->inventory[INVENTORY_GRENADES] > 10) return 80;
2230 //if the bot can use the shotgun
2231 if (bs->inventory[INVENTORY_SHOTGUN] > 0 &&
2232 bs->inventory[INVENTORY_SHELLS] > 10) return 50;
2233 //otherwise the bot is not feeling too good
2234 return 0;
2235 }
2236
2237 /*
2238 ==================
2239 BotFeelingBad
2240 ==================
2241 */
2242 float BotFeelingBad(bot_state_t *bs) {
2243 if (bs->weaponnum == WP_GAUNTLET) {
2244 return 100;
2245 }
2246 if (bs->inventory[INVENTORY_HEALTH] < 40) {
2247 return 100;
2248 }
2249 if (bs->weaponnum == WP_MACHINEGUN) {
2250 return 90;
2251 }
2252 if (bs->inventory[INVENTORY_HEALTH] < 60) {
2253 return 80;
2254 }
2255 return 0;
2256 }
2257
2258 /*
2259 ==================
2260 BotWantsToRetreat
2261 ==================
2262 */
2263 int BotWantsToRetreat(bot_state_t *bs) {
2264 aas_entityinfo_t entinfo;
2265
2266 if (gametype == GT_CTF) {
2267 //always retreat when carrying a CTF flag
2268 if (BotCTFCarryingFlag(bs))
2269 return qtrue;
2270 }
2271 #ifdef MISSIONPACK
2272 else if (gametype == GT_1FCTF) {
2273 //if carrying the flag then always retreat
2274 if (Bot1FCTFCarryingFlag(bs))
2275 return qtrue;
2276 }
2277 else if (gametype == GT_OBELISK) {
2278 //the bots should be dedicated to attacking the enemy obelisk
2279 if (bs->ltgtype == LTG_ATTACKENEMYBASE) {
2280 if (bs->enemy != redobelisk.entitynum &&
2281 bs->enemy != blueobelisk.entitynum) {
2282 return qtrue;
2283 }
2284 }
2285 if (BotFeelingBad(bs) > 50) {
2286 return qtrue;
2287 }
2288 return qfalse;
2289 }
2290 else if (gametype == GT_HARVESTER) {
2291 //if carrying cubes then always retreat
2292 if (BotHarvesterCarryingCubes(bs)) return qtrue;
2293 }
2294 #endif
2295 //
2296 if (bs->enemy >= 0) {
2297 BotEntityInfo(bs->enemy, &entinfo);
2298 // if the enemy is carrying a flag
2299 if (EntityCarriesFlag(&entinfo)) return qfalse;
2300 #ifdef MISSIONPACK
2301 // if the enemy is carrying cubes
2302 if (EntityCarriesCubes(&entinfo)) return qfalse;
2303 #endif
2304 }
2305 //if the bot is getting the flag
2306 if (bs->ltgtype == LTG_GETFLAG)
2307 return qtrue;
2308 //
2309 if (BotAggression(bs) < 50)
2310 return qtrue;
2311 return qfalse;
2312 }
2313
2314 /*
2315 ==================
2316 BotWantsToChase
2317 ==================
2318 */
2319 int BotWantsToChase(bot_state_t *bs) {
2320 aas_entityinfo_t entinfo;
2321
2322 if (gametype == GT_CTF) {
2323 //never chase when carrying a CTF flag
2324 if (BotCTFCarryingFlag(bs))
2325 return qfalse;
2326 //always chase if the enemy is carrying a flag
2327 BotEntityInfo(bs->enemy, &entinfo);
2328 if (EntityCarriesFlag(&entinfo))
2329 return qtrue;
2330 }
2331 #ifdef MISSIONPACK
2332 else if (gametype == GT_1FCTF) {
2333 //never chase if carrying the flag
2334 if (Bot1FCTFCarryingFlag(bs))
2335 return qfalse;
2336 //always chase if the enemy is carrying a flag
2337 BotEntityInfo(bs->enemy, &entinfo);
2338 if (EntityCarriesFlag(&entinfo))
2339 return qtrue;
2340 }
2341 else if (gametype == GT_OBELISK) {
2342 //the bots should be dedicated to attacking the enemy obelisk
2343 if (bs->ltgtype == LTG_ATTACKENEMYBASE) {
2344 if (bs->enemy != redobelisk.entitynum &&
2345 bs->enemy != blueobelisk.entitynum) {
2346 return qfalse;
2347 }
2348 }
2349 }
2350 else if (gametype == GT_HARVESTER) {
2351 //never chase if carrying cubes
2352 if (BotHarvesterCarryingCubes(bs)) return qfalse;
2353
2354 BotEntityInfo(bs->enemy, &entinfo);
2355 // always chase if the enemy is carrying cubes
2356 if (EntityCarriesCubes(&entinfo)) return qtrue;
2357 }
2358 #endif
2359 //if the bot is getting the flag
2360 if (bs->ltgtype == LTG_GETFLAG)
2361 return qfalse;
2362 //
2363 if (BotAggression(bs) > 50)
2364 return qtrue;
2365 return qfalse;
2366 }
2367
2368 /*
2369 ==================
2370 BotWantsToHelp
2371 ==================
2372 */
2373 int BotWantsToHelp(bot_state_t *bs) {
2374 return qtrue;
2375 }
2376
2377 /*
2378 ==================
2379 BotCanAndWantsToRocketJump
2380 ==================
2381 */
2382 int BotCanAndWantsToRocketJump(bot_state_t *bs) {
2383 float rocketjumper;
2384
2385 //if rocket jumping is disabled
2386 if (!bot_rocketjump.integer) return qfalse;
2387 //if no rocket launcher
2388 if (bs->inventory[INVENTORY_ROCKETLAUNCHER] <= 0) return qfalse;
2389 //if low on rockets
2390 if (bs->inventory[INVENTORY_ROCKETS] < 3) return qfalse;
2391 //never rocket jump with the Quad
2392 if (bs->inventory[INVENTORY_QUAD]) return qfalse;
2393 //if low on health
2394 if (bs->inventory[INVENTORY_HEALTH] < 60) return qfalse;
2395 //if not full health
2396 if (bs->inventory[INVENTORY_HEALTH] < 90) {
2397 //if the bot has insufficient armor
2398 if (bs->inventory[INVENTORY_ARMOR] < 40) return qfalse;
2399 }
2400 rocketjumper = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_WEAPONJUMPING, 0, 1);
2401 if (rocketjumper < 0.5) return qfalse;
2402 return qtrue;
2403 }
2404
2405 /*
2406 ==================
2407 BotHasPersistantPowerupAndWeapon
2408 ==================
2409 */
2410 int BotHasPersistantPowerupAndWeapon(bot_state_t *bs) {
2411 #ifdef MISSIONPACK
2412 // if the bot does not have a persistant powerup
2413 if (!bs->inventory[INVENTORY_SCOUT] &&
2414 !bs->inventory[INVENTORY_GUARD] &&
2415 !bs->inventory[INVENTORY_DOUBLER] &&
2416 !bs->inventory[INVENTORY_AMMOREGEN] ) {
2417 return qfalse;
2418 }
2419 #endif
2420 //if the bot is very low on health
2421 if (bs->inventory[INVENTORY_HEALTH] < 60) return qfalse;
2422 //if the bot is low on health
2423 if (bs->inventory[INVENTORY_HEALTH] < 80) {
2424 //if the bot has insufficient armor
2425 if (bs->inventory[INVENTORY_ARMOR] < 40) return qfalse;
2426 }
2427 //if the bot can use the bfg
2428 if (bs->inventory[INVENTORY_BFG10K] > 0 &&
2429 bs->inventory[INVENTORY_BFGAMMO] > 7) return qtrue;
2430 //if the bot can use the railgun
2431 if (bs->inventory[INVENTORY_RAILGUN] > 0 &&
2432 bs->inventory[INVENTORY_SLUGS] > 5) return qtrue;
2433 //if the bot can use the lightning gun
2434 if (bs->inventory[INVENTORY_LIGHTNING] > 0 &&
2435 bs->inventory[INVENTORY_LIGHTNINGAMMO] > 50) return qtrue;
2436 //if the bot can use the rocketlauncher
2437 if (bs->inventory[INVENTORY_ROCKETLAUNCHER] > 0 &&
2438 bs->inventory[INVENTORY_ROCKETS] > 5) return qtrue;
2439 //
2440 if (bs->inventory[INVENTORY_NAILGUN] > 0 &&
2441 bs->inventory[INVENTORY_NAILS] > 5) return qtrue;
2442 //
2443 if (bs->inventory[INVENTORY_PROXLAUNCHER] > 0 &&
2444 bs->inventory[INVENTORY_MINES] > 5) return qtrue;
2445 //
2446 if (bs->inventory[INVENTORY_CHAINGUN] > 0 &&
2447 bs->inventory[INVENTORY_BELT] > 40) return qtrue;
2448 //if the bot can use the plasmagun
2449 if (bs->inventory[INVENTORY_PLASMAGUN] > 0 &&
2450 bs->inventory[INVENTORY_CELLS] > 20) return qtrue;
2451 return qfalse;
2452 }
2453
2454 /*
2455 ==================
2456 BotGoCamp
2457 ==================
2458 */
2459 void BotGoCamp(bot_state_t *bs, bot_goal_t *goal) {
2460 float camper;
2461
2462 bs->decisionmaker = bs->client;
2463 //set message time to zero so bot will NOT show any message
2464 bs->teammessage_time = 0;
2465 //set the ltg type
2466 bs->ltgtype = LTG_CAMP;
2467 //set the team goal
2468 memcpy(&bs->teamgoal, goal, sizeof(bot_goal_t));
2469 //get the team goal time
2470 camper = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_CAMPER, 0, 1);
2471 if (camper > 0.99) bs->teamgoal_time = FloatTime() + 99999;
2472 else bs->teamgoal_time = FloatTime() + 120 + 180 * camper + random() * 15;
2473 //set the last time the bot started camping
2474 bs->camp_time = FloatTime();
2475 //the teammate that requested the camping
2476 bs->teammate = 0;
2477 //do NOT type arrive message
2478 bs->arrive_time = 1;
2479 }
2480
2481 /*
2482 ==================
2483 BotWantsToCamp
2484 ==================
2485 */
2486 int BotWantsToCamp(bot_state_t *bs) {
2487 float camper;
2488 int cs, traveltime, besttraveltime;
2489 bot_goal_t goal, bestgoal;
2490
2491 camper = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_CAMPER, 0, 1);
2492 if (camper < 0.1) return qfalse;
2493 //if the bot has a team goal
2494 if (bs->ltgtype == LTG_TEAMHELP ||
2495 bs->ltgtype == LTG_TEAMACCOMPANY ||
2496 bs->ltgtype == LTG_DEFENDKEYAREA ||
2497 bs->ltgtype == LTG_GETFLAG ||
2498 bs->ltgtype == LTG_RUSHBASE ||
2499 bs->ltgtype == LTG_CAMP ||
2500 bs->ltgtype == LTG_CAMPORDER ||
2501 bs->ltgtype == LTG_PATROL) {
2502 return qfalse;
2503 }
2504 //if camped recently
2505 if (bs->camp_time > FloatTime() - 60 + 300 * (1-camper)) return qfalse;
2506 //
2507 if (random() > camper) {
2508 bs->camp_time = FloatTime();
2509 return qfalse;
2510 }
2511 //if the bot isn't healthy enough
2512 if (BotAggression(bs) < 50) return qfalse;
2513 //the bot should have at least have the rocket launcher, the railgun or the bfg10k with some ammo
2514 if ((bs->inventory[INVENTORY_ROCKETLAUNCHER] <= 0 || bs->inventory[INVENTORY_ROCKETS] < 10) &&
2515 (bs->inventory[INVENTORY_RAILGUN] <= 0 || bs->inventory[INVENTORY_SLUGS] < 10) &&
2516 (bs->inventory[INVENTORY_BFG10K] <= 0 || bs->inventory[INVENTORY_BFGAMMO] < 10)) {
2517 return qfalse;
2518 }
2519 //find the closest camp spot
2520 besttraveltime = 99999;
2521 for (cs = trap_BotGetNextCampSpotGoal(0, &goal); cs; cs = trap_BotGetNextCampSpotGoal(cs, &goal)) {
2522 traveltime = trap_AAS_AreaTravelTimeToGoalArea(bs->areanum, bs->origin, goal.areanum, TFL_DEFAULT);
2523 if (traveltime && traveltime < besttraveltime) {
2524 besttraveltime = traveltime;
2525 memcpy(&bestgoal, &goal, sizeof(bot_goal_t));
2526 }
2527 }
2528 if (besttraveltime > 150) return qfalse;
2529 //ok found a camp spot, go camp there
2530 BotGoCamp(bs, &bestgoal);
2531 bs->ordered = qfalse;
2532 //
2533 return qtrue;
2534 }
2535
2536 /*
2537 ==================
2538 BotDontAvoid
2539 ==================
2540 */
2541 void BotDontAvoid(bot_state_t *bs, char *itemname) {
2542 bot_goal_t goal;
2543 int num;
2544
2545 num = trap_BotGetLevelItemGoal(-1, itemname, &goal);
2546 while(num >= 0) {
2547 trap_BotRemoveFromAvoidGoals(bs->gs, goal.number);
2548 num = trap_BotGetLevelItemGoal(num, itemname, &goal);
2549 }
2550 }
2551
2552 /*
2553 ==================
2554 BotGoForPowerups
2555 ==================
2556 */
2557 void BotGoForPowerups(bot_state_t *bs) {
2558
2559 //don't avoid any of the powerups anymore
2560 BotDontAvoid(bs, "Quad Damage");
2561 BotDontAvoid(bs, "Regeneration");
2562 BotDontAvoid(bs, "Battle Suit");
2563 BotDontAvoid(bs, "Speed");
2564 BotDontAvoid(bs, "Invisibility");
2565 //BotDontAvoid(bs, "Flight");
2566 //reset the long term goal time so the bot will go for the powerup
2567 //NOTE: the long term goal type doesn't change
2568 bs->ltg_time = 0;
2569 }
2570
2571 /*
2572 ==================
2573 BotRoamGoal
2574 ==================
2575 */
2576 void BotRoamGoal(bot_state_t *bs, vec3_t goal) {
2577 int pc, i;
2578 float len, rnd;
2579 vec3_t dir, bestorg, belowbestorg;
2580 bsp_trace_t trace;
2581
2582 for (i = 0; i < 10; i++) {
2583 //start at the bot origin
2584 VectorCopy(bs->origin, bestorg);
2585 rnd = random();
2586 if (rnd > 0.25) {
2587 //add a random value to the x-coordinate
2588 if (random() < 0.5) bestorg[0] -= 800 * random() + 100;
2589 else bestorg[0] += 800 * random() + 100;
2590 }
2591 if (rnd < 0.75) {
2592 //add a random value to the y-coordinate
2593 if (random() < 0.5) bestorg[1] -= 800 * random() + 100;
2594 else bestorg[1] += 800 * random() + 100;
2595 }
2596 //add a random value to the z-coordinate (NOTE: 48 = maxjump?)
2597 bestorg[2] += 2 * 48 * crandom();
2598 //trace a line from the origin to the roam target
2599 BotAI_Trace(&trace, bs->origin, NULL, NULL, bestorg, bs->entitynum, MASK_SOLID);
2600 //direction and length towards the roam target
2601 VectorSubtract(trace.endpos, bs->origin, dir);
2602 len = VectorNormalize(dir);
2603 //if the roam target is far away enough
2604 if (len > 200) {
2605 //the roam target is in the given direction before walls
2606 VectorScale(dir, len * trace.fraction - 40, dir);
2607 VectorAdd(bs->origin, dir, bestorg);
2608 //get the coordinates of the floor below the roam target
2609 belowbestorg[0] = bestorg[0];
2610 belowbestorg[1] = bestorg[1];
2611 belowbestorg[2] = bestorg[2] - 800;
2612 BotAI_Trace(&trace, bestorg, NULL, NULL, belowbestorg, bs->entitynum, MASK_SOLID);
2613 //
2614 if (!trace.startsolid) {
2615 trace.endpos[2]++;
2616 pc = trap_PointContents(trace.endpos, bs->entitynum);
2617 if (!(pc & (CONTENTS_LAVA | CONTENTS_SLIME))) {
2618 VectorCopy(bestorg, goal);
2619 return;
2620 }
2621 }
2622 }
2623 }
2624 VectorCopy(bestorg, goal);
2625 }
2626
2627 /*
2628 ==================
2629 BotAttackMove
2630 ==================
2631 */
2632 bot_moveresult_t BotAttackMove(bot_state_t *bs, int tfl) {
2633 int movetype, i, attackentity;
2634 float attack_skill, jumper, croucher, dist, strafechange_time;
2635 float attack_dist, attack_range;
2636 vec3_t forward, backward, sideward, hordir, up = {0, 0, 1};
2637 aas_entityinfo_t entinfo;
2638 bot_moveresult_t moveresult;
2639 bot_goal_t goal;
2640
2641 attackentity = bs->enemy;
2642 //
2643 if (bs->attackchase_time > FloatTime()) {
2644 //create the chase goal
2645 goal.entitynum = attackentity;
2646 goal.areanum = bs->lastenemyareanum;
2647 VectorCopy(bs->lastenemyorigin, goal.origin);
2648 VectorSet(goal.mins, -8, -8, -8);
2649 VectorSet(goal.maxs, 8, 8, 8);
2650 //initialize the movement state
2651 BotSetupForMovement(bs);
2652 //move towards the goal
2653 trap_BotMoveToGoal(&moveresult, bs->ms, &goal, tfl);
2654 return moveresult;
2655 }
2656 //
2657 memset(&moveresult, 0, sizeof(bot_moveresult_t));
2658 //
2659 attack_skill = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_ATTACK_SKILL, 0, 1);
2660 jumper = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_JUMPER, 0, 1);
2661 croucher = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_CROUCHER, 0, 1);
2662 //if the bot is really stupid
2663 if (attack_skill < 0.2) return moveresult;
2664 //initialize the movement state
2665 BotSetupForMovement(bs);
2666 //get the enemy entity info
2667 BotEntityInfo(attackentity, &entinfo);
2668 //direction towards the enemy
2669 VectorSubtract(entinfo.origin, bs->origin, forward);
2670 //the distance towards the enemy
2671 dist = VectorNormalize(forward);
2672 VectorNegate(forward, backward);
2673 //walk, crouch or jump
2674 movetype = MOVE_WALK;
2675 //
2676 if (bs->attackcrouch_time < FloatTime() - 1) {
2677 if (random() < jumper) {
2678 movetype = MOVE_JUMP;
2679 }
2680 //wait at least one second before crouching again
2681 else if (bs->attackcrouch_time < FloatTime() - 1 && random() < croucher) {
2682 bs->attackcrouch_time = FloatTime() + croucher * 5;
2683 }
2684 }
2685 if (bs->attackcrouch_time > FloatTime()) movetype = MOVE_CROUCH;
2686 //if the bot should jump
2687 if (movetype == MOVE_JUMP) {
2688 //if jumped last frame
2689 if (bs->attackjump_time > FloatTime()) {
2690 movetype = MOVE_WALK;
2691 }
2692 else {
2693 bs->attackjump_time = FloatTime() + 1;
2694 }
2695 }
2696 if (bs->cur_ps.weapon == WP_GAUNTLET) {
2697 attack_dist = 0;
2698 attack_range = 0;
2699 }
2700 else {
2701 attack_dist = IDEAL_ATTACKDIST;
2702 attack_range = 40;
2703 }
2704 //if the bot is stupid
2705 if (attack_skill <= 0.4) {
2706 //just walk to or away from the enemy
2707 if (dist > attack_dist + attack_range) {
2708 if (trap_BotMoveInDirection(bs->ms, forward, 400, movetype)) return moveresult;
2709 }
2710 if (dist < attack_dist - attack_range) {
2711 if (trap_BotMoveInDirection(bs->ms, backward, 400, movetype)) return moveresult;
2712 }
2713 return moveresult;
2714 }
2715 //increase the strafe time
2716 bs->attackstrafe_time += bs->thinktime;
2717 //get the strafe change time
2718 strafechange_time = 0.4 + (1 - attack_skill) * 0.2;
2719 if (attack_skill > 0.7) strafechange_time += crandom() * 0.2;
2720 //if the strafe direction should be changed
2721 if (bs->attackstrafe_time > strafechange_time) {
2722 //some magic number :)
2723 if (random() > 0.935) {
2724 //flip the strafe direction
2725 bs->flags ^= BFL_STRAFERIGHT;
2726 bs->attackstrafe_time = 0;
2727 }
2728 }
2729 //
2730 for (i = 0; i < 2; i++) {
2731 hordir[0] = forward[0];
2732 hordir[1] = forward[1];
2733 hordir[2] = 0;
2734 VectorNormalize(hordir);
2735 //get the sideward vector
2736 CrossProduct(hordir, up, sideward);
2737 //reverse the vector depending on the strafe direction
2738 if (bs->flags & BFL_STRAFERIGHT) VectorNegate(sideward, sideward);
2739 //randomly go back a little
2740 if (random() > 0.9) {
2741 VectorAdd(sideward, backward, sideward);
2742 }
2743 else {
2744 //walk forward or backward to get at the ideal attack distance
2745 if (dist > attack_dist + attack_range) {
2746 VectorAdd(sideward, forward, sideward);
2747 }
2748 else if (dist < attack_dist - attack_range) {
2749 VectorAdd(sideward, backward, sideward);
2750 }
2751 }
2752 //perform the movement
2753 if (trap_BotMoveInDirection(bs->ms, sideward, 400, movetype))
2754 return moveresult;
2755 //movement failed, flip the strafe direction
2756 bs->flags ^= BFL_STRAFERIGHT;
2757 bs->attackstrafe_time = 0;
2758 }
2759 //bot couldn't do any useful movement
2760 // bs->attackchase_time = AAS_Time() + 6;
2761 return moveresult;
2762 }
2763
2764 /*
2765 ==================
2766 BotSameTeam
2767 ==================
2768 */
2769 int BotSameTeam(bot_state_t *bs, int entnum) {
2770
2771 if (bs->client < 0 || bs->client >= MAX_CLIENTS) {
2772 return qfalse;
2773 }
2774
2775 if (entnum < 0 || entnum >= MAX_CLIENTS) {
2776 return qfalse;
2777 }
2778
2779 if (gametype >= GT_TEAM) {
2780 if (level.clients[bs->client].sess.sessionTeam == level.clients[entnum].sess.sessionTeam) return qtrue;
2781 }
2782
2783 return qfalse;
2784 }
2785
2786 /*
2787 ==================
2788 InFieldOfVision
2789 ==================
2790 */
2791 qboolean InFieldOfVision(vec3_t viewangles, float fov, vec3_t angles)
2792 {
2793 int i;
2794 float diff, angle;
2795
2796 for (i = 0; i < 2; i++) {
2797 angle = AngleMod(viewangles[i]);
2798 angles[i] = AngleMod(angles[i]);
2799 diff = angles[i] - angle;
2800 if (angles[i] > angle) {
2801 if (diff > 180.0) diff -= 360.0;
2802 }
2803 else {
2804 if (diff < -180.0) diff += 360.0;
2805 }
2806 if (diff > 0) {
2807 if (diff > fov * 0.5) return qfalse;
2808 }
2809 else {
2810 if (diff < -fov * 0.5) return qfalse;
2811 }
2812 }
2813 return qtrue;
2814 }
2815
2816 /*
2817 ==================
2818 BotEntityVisible
2819
2820 returns visibility in the range [0, 1] taking fog and water surfaces into account
2821 ==================
2822 */
2823 float BotEntityVisible(int viewer, vec3_t eye, vec3_t viewangles, float fov, int ent) {
2824 int i, contents_mask, passent, hitent, infog, inwater, otherinfog, pc;
2825 float squaredfogdist, waterfactor, vis, bestvis;
2826 bsp_trace_t trace;
2827 aas_entityinfo_t entinfo;
2828 vec3_t dir, entangles, start, end, middle;
2829
2830 BotEntityInfo(ent, &entinfo);
2831 if (!entinfo.valid) {
2832 return 0;
2833 }
2834
2835 //calculate middle of bounding box
2836 VectorAdd(entinfo.mins, entinfo.maxs, middle);
2837 VectorScale(middle, 0.5, middle);
2838 VectorAdd(entinfo.origin, middle, middle);
2839 //check if entity is within field of vision
2840 VectorSubtract(middle, eye, dir);
2841 vectoangles(dir, entangles);
2842 if (!InFieldOfVision(viewangles, fov, entangles)) return 0;
2843 //
2844 pc = trap_AAS_PointContents(eye);
2845 infog = (pc & CONTENTS_FOG);
2846 inwater = (pc & (CONTENTS_LAVA|CONTENTS_SLIME|CONTENTS_WATER));
2847 //
2848 bestvis = 0;
2849 for (i = 0; i < 3; i++) {
2850 //if the point is not in potential visible sight
2851 //if (!AAS_inPVS(eye, middle)) continue;
2852 //
2853 contents_mask = CONTENTS_SOLID|CONTENTS_PLAYERCLIP;
2854 passent = viewer;
2855 hitent = ent;
2856 VectorCopy(eye, start);
2857 VectorCopy(middle, end);
2858 //if the entity is in water, lava or slime
2859 if (trap_AAS_PointContents(middle) & (CONTENTS_LAVA|CONTENTS_SLIME|CONTENTS_WATER)) {
2860 contents_mask |= (CONTENTS_LAVA|CONTENTS_SLIME|CONTENTS_WATER);
2861 }
2862 //if eye is in water, lava or slime
2863 if (inwater) {
2864 if (!(contents_mask & (CONTENTS_LAVA|CONTENTS_SLIME|CONTENTS_WATER))) {
2865 passent = ent;
2866 hitent = viewer;
2867 VectorCopy(middle, start);
2868 VectorCopy(eye, end);
2869 }
2870 contents_mask ^= (CONTENTS_LAVA|CONTENTS_SLIME|CONTENTS_WATER);
2871 }
2872 //trace from start to end
2873 BotAI_Trace(&trace, start, NULL, NULL, end, passent, contents_mask);
2874 //if water was hit
2875 waterfactor = 1.0;
2876 //note: trace.contents is always 0, see BotAI_Trace
2877 if (trace.contents & (CONTENTS_LAVA|CONTENTS_SLIME|CONTENTS_WATER)) {
2878 //if the water surface is translucent
2879 if (1) {
2880 //trace through the water
2881 contents_mask &= ~(CONTENTS_LAVA|CONTENTS_SLIME|CONTENTS_WATER);
2882 BotAI_Trace(&trace, trace.endpos, NULL, NULL, end, passent, contents_mask);
2883 waterfactor = 0.5;
2884 }
2885 }
2886 //if a full trace or the hitent was hit
2887 if (trace.fraction >= 1 || trace.ent == hitent) {
2888 //check for fog, assuming there's only one fog brush where
2889 //either the viewer or the entity is in or both are in
2890 otherinfog = (trap_AAS_PointContents(middle) & CONTENTS_FOG);
2891 if (infog && otherinfog) {
2892 VectorSubtract(trace.endpos, eye, dir);
2893 squaredfogdist = VectorLengthSquared(dir);
2894 }
2895 else if (infog) {
2896 VectorCopy(trace.endpos, start);
2897 BotAI_Trace(&trace, start, NULL, NULL, eye, viewer, CONTENTS_FOG);
2898 VectorSubtract(eye, trace.endpos, dir);
2899 squaredfogdist = VectorLengthSquared(dir);
2900 }
2901 else if (otherinfog) {
2902 VectorCopy(trace.endpos, end);
2903 BotAI_Trace(&trace, eye, NULL, NULL, end, viewer, CONTENTS_FOG);
2904 VectorSubtract(end, trace.endpos, dir);
2905 squaredfogdist = VectorLengthSquared(dir);
2906 }
2907 else {
2908 //if the entity and the viewer are not in fog assume there's no fog in between
2909 squaredfogdist = 0;
2910 }
2911 //decrease visibility with the view distance through fog
2912 vis = 1 / ((squaredfogdist * 0.001) < 1 ? 1 : (squaredfogdist * 0.001));
2913 //if entering water visibility is reduced
2914 vis *= waterfactor;
2915 //
2916 if (vis > bestvis) bestvis = vis;
2917 //if pretty much no fog
2918 if (bestvis >= 0.95) return bestvis;
2919 }
2920 //check bottom and top of bounding box as well
2921 if (i == 0) middle[2] += entinfo.mins[2];
2922 else if (i == 1) middle[2] += entinfo.maxs[2] - entinfo.mins[2];
2923 }
2924 return bestvis;
2925 }
2926
2927 /*
2928 ==================
2929 BotFindEnemy
2930 ==================
2931 */
2932 int BotFindEnemy(bot_state_t *bs, int curenemy) {
2933 int i, healthdecrease;
2934 float f, alertness, easyfragger, vis;
2935 float squaredist, cursquaredist;
2936 aas_entityinfo_t entinfo, curenemyinfo;
2937 vec3_t dir, angles;
2938
2939 alertness = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_ALERTNESS, 0, 1);
2940 easyfragger = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_EASY_FRAGGER, 0, 1);
2941 //check if the health decreased
2942 healthdecrease = bs->lasthealth > bs->inventory[INVENTORY_HEALTH];
2943 //remember the current health value
2944 bs->lasthealth = bs->inventory[INVENTORY_HEALTH];
2945 //
2946 if (curenemy >= 0) {
2947 BotEntityInfo(curenemy, &curenemyinfo);
2948 if (EntityCarriesFlag(&curenemyinfo)) return qfalse;
2949 VectorSubtract(curenemyinfo.origin, bs->origin, dir);
2950 cursquaredist = VectorLengthSquared(dir);
2951 }
2952 else {
2953 cursquaredist = 0;
2954 }
2955 #ifdef MISSIONPACK
2956 if (gametype == GT_OBELISK) {
2957 vec3_t target;
2958 bot_goal_t *goal;
2959 bsp_trace_t trace;
2960
2961 if (BotTeam(bs) == TEAM_RED)
2962 goal = &blueobelisk;
2963 else
2964 goal = &redobelisk;
2965 //if the obelisk is visible
2966 VectorCopy(goal->origin, target);
2967 target[2] += 1;
2968 BotAI_Trace(&trace, bs->eye, NULL, NULL, target, bs->client, CONTENTS_SOLID);
2969 if (trace.fraction >= 1 || trace.ent == goal->entitynum) {
2970 if (goal->entitynum == bs->enemy) {
2971 return qfalse;
2972 }
2973 bs->enemy = goal->entitynum;
2974 bs->enemysight_time = FloatTime();
2975 bs->enemysuicide = qfalse;
2976 bs->enemydeath_time = 0;
2977 bs->enemyvisible_time = FloatTime();
2978 return qtrue;
2979 }
2980 }
2981 #endif
2982 //
2983 for (i = 0; i < level.maxclients; i++) {
2984
2985 if (i == bs->client) continue;
2986 //if it's the current enemy
2987 if (i == curenemy) continue;
2988 //if the enemy has targeting disabled
2989 if (g_entities[i].flags & FL_NOTARGET) {
2990 continue;
2991 }
2992 //
2993 BotEntityInfo(i, &entinfo);
2994 //
2995 if (!entinfo.valid) continue;
2996 //if the enemy isn't dead and the enemy isn't the bot self
2997 if (EntityIsDead(&entinfo) || entinfo.number == bs->entitynum) continue;
2998 //if the enemy is invisible and not shooting
2999 if (EntityIsInvisible(&entinfo) && !EntityIsShooting(&entinfo)) {
3000 continue;
3001 }
3002 //if not an easy fragger don't shoot at chatting players
3003 if (easyfragger < 0.5 && EntityIsChatting(&entinfo)) continue;
3004 //
3005 if (lastteleport_time > FloatTime() - 3) {
3006 VectorSubtract(entinfo.origin, lastteleport_origin, dir);
3007 if (VectorLengthSquared(dir) < Square(70)) continue;
3008 }
3009 //calculate the distance towards the enemy
3010 VectorSubtract(entinfo.origin, bs->origin, dir);
3011 squaredist = VectorLengthSquared(dir);
3012 //if this entity is not carrying a flag
3013 if (!EntityCarriesFlag(&entinfo))
3014 {
3015 //if this enemy is further away than the current one
3016 if (curenemy >= 0 && squaredist > cursquaredist) continue;
3017 } //end if
3018 //if the bot has no
3019 if (squaredist > Square(900.0 + alertness * 4000.0)) continue;
3020 //if on the same team
3021 if (BotSameTeam(bs, i)) continue;
3022 //if the bot's health decreased or the enemy is shooting
3023 if (curenemy < 0 && (healthdecrease || EntityIsShooting(&entinfo)))
3024 f = 360;
3025 else
3026 f = 90 + 90 - (90 - (squaredist > Square(810) ? Square(810) : squaredist) / (810 * 9));
3027 //check if the enemy is visible
3028 vis = BotEntityVisible(bs->entitynum, bs->eye, bs->viewangles, f, i);
3029 if (vis <= 0) continue;
3030 //if the enemy is quite far away, not shooting and the bot is not damaged
3031 if (curenemy < 0 && squaredist > Square(100) && !healthdecrease && !EntityIsShooting(&entinfo))
3032 {
3033 //check if we can avoid this enemy
3034 VectorSubtract(bs->origin, entinfo.origin, dir);
3035 vectoangles(dir, angles);
3036 //if the bot isn't in the fov of the enemy
3037 if (!InFieldOfVision(entinfo.angles, 90, angles)) {
3038 //update some stuff for this enemy
3039 BotUpdateBattleInventory(bs, i);
3040 //if the bot doesn't really want to fight
3041 if (BotWantsToRetreat(bs)) continue;
3042 }
3043 }
3044 //found an enemy
3045 bs->enemy = entinfo.number;
3046 if (curenemy >= 0) bs->enemysight_time = FloatTime() - 2;
3047 else bs->enemysight_time = FloatTime();
3048 bs->enemysuicide = qfalse;
3049 bs->enemydeath_time = 0;
3050 bs->enemyvisible_time = FloatTime();
3051 return qtrue;
3052 }
3053 return qfalse;
3054 }
3055
3056 /*
3057 ==================
3058 BotTeamFlagCarrierVisible
3059 ==================
3060 */
3061 int BotTeamFlagCarrierVisible(bot_state_t *bs) {
3062 int i;
3063 float vis;
3064 aas_entityinfo_t entinfo;
3065
3066 for (i = 0; i < level.maxclients; i++) {
3067 if (i == bs->client)
3068 continue;
3069 //
3070 BotEntityInfo(i, &entinfo);
3071 //if this player is active
3072 if (!entinfo.valid)
3073 continue;
3074 //if this player is carrying a flag
3075 if (!EntityCarriesFlag(&entinfo))
3076 continue;
3077 //if the flag carrier is not on the same team
3078 if (!BotSameTeam(bs, i))
3079 continue;
3080 //if the flag carrier is not visible
3081 vis = BotEntityVisible(bs->entitynum, bs->eye, bs->viewangles, 360, i);
3082 if (vis <= 0)
3083 continue;
3084 //
3085 return i;
3086 }
3087 return -1;
3088 }
3089
3090 /*
3091 ==================
3092 BotTeamFlagCarrier
3093 ==================
3094 */
3095 int BotTeamFlagCarrier(bot_state_t *bs) {
3096 int i;
3097 aas_entityinfo_t entinfo;
3098
3099 for (i = 0; i < level.maxclients; i++) {
3100 if (i == bs->client)
3101 continue;
3102 //
3103 BotEntityInfo(i, &entinfo);
3104 //if this player is active
3105 if (!entinfo.valid)
3106 continue;
3107 //if this player is carrying a flag
3108 if (!EntityCarriesFlag(&entinfo))
3109 continue;
3110 //if the flag carrier is not on the same team
3111 if (!BotSameTeam(bs, i))
3112 continue;
3113 //
3114 return i;
3115 }
3116 return -1;
3117 }
3118
3119 /*
3120 ==================
3121 BotEnemyFlagCarrierVisible
3122 ==================
3123 */
3124 int BotEnemyFlagCarrierVisible(bot_state_t *bs) {
3125 int i;
3126 float vis;
3127 aas_entityinfo_t entinfo;
3128
3129 for (i = 0; i < level.maxclients; i++) {
3130 if (i == bs->client)
3131 continue;
3132 //
3133 BotEntityInfo(i, &entinfo);
3134 //if this player is active
3135 if (!entinfo.valid)
3136 continue;
3137 //if this player is carrying a flag
3138 if (!EntityCarriesFlag(&entinfo))
3139 continue;
3140 //if the flag carrier is on the same team
3141 if (BotSameTeam(bs, i))
3142 continue;
3143 //if the flag carrier is not visible
3144 vis = BotEntityVisible(bs->entitynum, bs->eye, bs->viewangles, 360, i);
3145 if (vis <= 0)
3146 continue;
3147 //
3148 return i;
3149 }
3150 return -1;
3151 }
3152
3153 /*
3154 ==================
3155 BotVisibleTeamMatesAndEnemies
3156 ==================
3157 */
3158 void BotVisibleTeamMatesAndEnemies(bot_state_t *bs, int *teammates, int *enemies, float range) {
3159 int i;
3160 float vis;
3161 aas_entityinfo_t entinfo;
3162 vec3_t dir;
3163
3164 if (teammates)
3165 *teammates = 0;
3166 if (enemies)
3167 *enemies = 0;
3168 for (i = 0; i < level.maxclients; i++) {
3169 if (i == bs->client)
3170 continue;
3171 //
3172 BotEntityInfo(i, &entinfo);
3173 //if this player is active
3174 if (!entinfo.valid)
3175 continue;
3176 //if this player is carrying a flag
3177 if (!EntityCarriesFlag(&entinfo))
3178 continue;
3179 //if not within range
3180 VectorSubtract(entinfo.origin, bs->origin, dir);
3181 if (VectorLengthSquared(dir) > Square(range))
3182 continue;
3183 //if the flag carrier is not visible
3184 vis = BotEntityVisible(bs->entitynum, bs->eye, bs->viewangles, 360, i);
3185 if (vis <= 0)
3186 continue;
3187 //if the flag carrier is on the same team
3188 if (BotSameTeam(bs, i)) {
3189 if (teammates)
3190 (*teammates)++;
3191 }
3192 else {
3193 if (enemies)
3194 (*enemies)++;
3195 }
3196 }
3197 }
3198
3199 #ifdef MISSIONPACK
3200 /*
3201 ==================
3202 BotTeamCubeCarrierVisible
3203 ==================
3204 */
3205 int BotTeamCubeCarrierVisible(bot_state_t *bs) {
3206 int i;
3207 float vis;
3208 aas_entityinfo_t entinfo;
3209
3210 for (i = 0; i < level.maxclients; i++) {
3211 if (i == bs->client) continue;
3212 //
3213 BotEntityInfo(i, &entinfo);
3214 //if this player is active
3215 if (!entinfo.valid) continue;
3216 //if this player is carrying a flag
3217 if (!EntityCarriesCubes(&entinfo)) continue;
3218 //if the flag carrier is not on the same team
3219 if (!BotSameTeam(bs, i)) continue;
3220 //if the flag carrier is not visible
3221 vis = BotEntityVisible(bs->entitynum, bs->eye, bs->viewangles, 360, i);
3222 if (vis <= 0) continue;
3223 //
3224 return i;
3225 }
3226 return -1;
3227 }
3228
3229 /*
3230 ==================
3231 BotEnemyCubeCarrierVisible
3232 ==================
3233 */
3234 int BotEnemyCubeCarrierVisible(bot_state_t *bs) {
3235 int i;
3236 float vis;
3237 aas_entityinfo_t entinfo;
3238
3239 for (i = 0; i < level.maxclients; i++) {
3240 if (i == bs->client)
3241 continue;
3242 //
3243 BotEntityInfo(i, &entinfo);
3244 //if this player is active
3245 if (!entinfo.valid)
3246 continue;
3247 //if this player is carrying a flag
3248 if (!EntityCarriesCubes(&entinfo)) continue;
3249 //if the flag carrier is on the same team
3250 if (BotSameTeam(bs, i))
3251 continue;
3252 //if the flag carrier is not visible
3253 vis = BotEntityVisible(bs->entitynum, bs->eye, bs->viewangles, 360, i);
3254 if (vis <= 0)
3255 continue;
3256 //
3257 return i;
3258 }
3259 return -1;
3260 }
3261 #endif
3262
3263 /*
3264 ==================
3265 BotAimAtEnemy
3266 ==================
3267 */
3268 void BotAimAtEnemy(bot_state_t *bs) {
3269 int i, enemyvisible;
3270 float dist, f, aim_skill, aim_accuracy, speed, reactiontime;
3271 vec3_t dir, bestorigin, end, start, groundtarget, cmdmove, enemyvelocity;
3272 vec3_t mins = {-4,-4,-4}, maxs = {4, 4, 4};
3273 weaponinfo_t wi;
3274 aas_entityinfo_t entinfo;
3275 bot_goal_t goal;
3276 bsp_trace_t trace;
3277 vec3_t target;
3278
3279 //if the bot has no enemy
3280 if (bs->enemy < 0) {
3281 return;
3282 }
3283 //get the enemy entity information
3284 BotEntityInfo(bs->enemy, &entinfo);
3285 //if this is not a player (should be an obelisk)
3286 if (bs->enemy >= MAX_CLIENTS) {
3287 //if the obelisk is visible
3288 VectorCopy(entinfo.origin, target);
3289 #ifdef MISSIONPACK
3290 // if attacking an obelisk
3291 if ( bs->enemy == redobelisk.entitynum ||
3292 bs->enemy == blueobelisk.entitynum ) {
3293 target[2] += 32;
3294 }
3295 #endif
3296 //aim at the obelisk
3297 VectorSubtract(target, bs->eye, dir);
3298 vectoangles(dir, bs->ideal_viewangles);
3299 //set the aim target before trying to attack
3300 VectorCopy(target, bs->aimtarget);
3301 return;
3302 }
3303 //
3304 //BotAI_Print(PRT_MESSAGE, "client %d: aiming at client %d\n", bs->entitynum, bs->enemy);
3305 //
3306 aim_skill = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_AIM_SKILL, 0, 1);
3307 aim_accuracy = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_AIM_ACCURACY, 0, 1);
3308 //
3309 if (aim_skill > 0.95) {
3310 //don't aim too early
3311 reactiontime = 0.5 * trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_REACTIONTIME, 0, 1);
3312 if (bs->enemysight_time > FloatTime() - reactiontime) return;
3313 if (bs->teleport_time > FloatTime() - reactiontime) return;
3314 }
3315
3316 //get the weapon information
3317 trap_BotGetWeaponInfo(bs->ws, bs->weaponnum, &wi);
3318 //get the weapon specific aim accuracy and or aim skill
3319 if (wi.number == WP_MACHINEGUN) {
3320 aim_accuracy = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_AIM_ACCURACY_MACHINEGUN, 0, 1);
3321 }
3322 else if (wi.number == WP_SHOTGUN) {
3323 aim_accuracy = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_AIM_ACCURACY_SHOTGUN, 0, 1);
3324 }
3325 else if (wi.number == WP_GRENADE_LAUNCHER) {
3326 aim_accuracy = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_AIM_ACCURACY_GRENADELAUNCHER, 0, 1);
3327 aim_skill = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_AIM_SKILL_GRENADELAUNCHER, 0, 1);
3328 }
3329 else if (wi.number == WP_ROCKET_LAUNCHER) {
3330 aim_accuracy = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_AIM_ACCURACY_ROCKETLAUNCHER, 0, 1);
3331 aim_skill = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_AIM_SKILL_ROCKETLAUNCHER, 0, 1);
3332 }
3333 else if (wi.number == WP_LIGHTNING) {
3334 aim_accuracy = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_AIM_ACCURACY_LIGHTNING, 0, 1);
3335 }
3336 else if (wi.number == WP_RAILGUN) {
3337 aim_accuracy = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_AIM_ACCURACY_RAILGUN, 0, 1);
3338 }
3339 else if (wi.number == WP_PLASMAGUN) {
3340 aim_accuracy = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_AIM_ACCURACY_PLASMAGUN, 0, 1);
3341 aim_skill = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_AIM_SKILL_PLASMAGUN, 0, 1);
3342 }
3343 else if (wi.number == WP_BFG) {
3344 aim_accuracy = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_AIM_ACCURACY_BFG10K, 0, 1);
3345 aim_skill = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_AIM_SKILL_BFG10K, 0, 1);
3346 }
3347 //
3348 if (aim_accuracy <= 0) aim_accuracy = 0.0001f;
3349 //get the enemy entity information
3350 BotEntityInfo(bs->enemy, &entinfo);
3351 //if the enemy is invisible then shoot crappy most of the time
3352 if (EntityIsInvisible(&entinfo)) {
3353 if (random() > 0.1) aim_accuracy *= 0.4f;
3354 }
3355 //
3356 VectorSubtract(entinfo.origin, entinfo.lastvisorigin, enemyvelocity);
3357 VectorScale(enemyvelocity, 1 / entinfo.update_time, enemyvelocity);
3358 //enemy origin and velocity is remembered every 0.5 seconds
3359 if (bs->enemyposition_time < FloatTime()) {
3360 //
3361 bs->enemyposition_time = FloatTime() + 0.5;
3362 VectorCopy(enemyvelocity, bs->enemyvelocity);
3363 VectorCopy(entinfo.origin, bs->enemyorigin);
3364 }
3365 //if not extremely skilled
3366 if (aim_skill < 0.9) {
3367 VectorSubtract(entinfo.origin, bs->enemyorigin, dir);
3368 //if the enemy moved a bit
3369 if (VectorLengthSquared(dir) > Square(48)) {
3370 //if the enemy changed direction
3371 if (DotProduct(bs->enemyvelocity, enemyvelocity) < 0) {
3372 //aim accuracy should be worse now
3373 aim_accuracy *= 0.7f;
3374 }
3375 }
3376 }
3377 //check visibility of enemy
3378 enemyvisible = BotEntityVisible(bs->entitynum, bs->eye, bs->viewangles, 360, bs->enemy);
3379 //if the enemy is visible
3380 if (enemyvisible) {
3381 //
3382 VectorCopy(entinfo.origin, bestorigin);
3383 bestorigin[2] += 8;
3384 //get the start point shooting from
3385 //NOTE: the x and y projectile start offsets are ignored
3386 VectorCopy(bs->origin, start);
3387 start[2] += bs->cur_ps.viewheight;
3388 start[2] += wi.offset[2];
3389 //
3390 BotAI_Trace(&trace, start, mins, maxs, bestorigin, bs->entitynum, MASK_SHOT);
3391 //if the enemy is NOT hit
3392 if (trace.fraction <= 1 && trace.ent != entinfo.number) {
3393 bestorigin[2] += 16;
3394 }
3395 //if it is not an instant hit weapon the bot might want to predict the enemy
3396 if (wi.speed) {
3397 //
3398 VectorSubtract(bestorigin, bs->origin, dir);
3399 dist = VectorLength(dir);
3400 VectorSubtract(entinfo.origin, bs->enemyorigin, dir);
3401 //if the enemy is NOT pretty far away and strafing just small steps left and right
3402 if (!(dist > 100 && VectorLengthSquared(dir) < Square(32))) {
3403 //if skilled enough do exact prediction
3404 if (aim_skill > 0.8 &&
3405 //if the weapon is ready to fire
3406 bs->cur_ps.weaponstate == WEAPON_READY) {
3407 aas_clientmove_t move;
3408 vec3_t origin;
3409
3410 VectorSubtract(entinfo.origin, bs->origin, dir);
3411 //distance towards the enemy
3412 dist = VectorLength(dir);
3413 //direction the enemy is moving in
3414 VectorSubtract(entinfo.origin, entinfo.lastvisorigin, dir);
3415 //
3416 VectorScale(dir, 1 / entinfo.update_time, dir);
3417 //
3418 VectorCopy(entinfo.origin, origin);
3419 origin[2] += 1;
3420 //
3421 VectorClear(cmdmove);
3422 //AAS_ClearShownDebugLines();
3423 trap_AAS_PredictClientMovement(&move, bs->enemy, origin,
3424 PRESENCE_CROUCH, qfalse,
3425 dir, cmdmove, 0,
3426 dist * 10 / wi.speed, 0.1f, 0, 0, qfalse);
3427 VectorCopy(move.endpos, bestorigin);
3428 //BotAI_Print(PRT_MESSAGE, "%1.1f predicted speed = %f, frames = %f\n", FloatTime(), VectorLength(dir), dist * 10 / wi.speed);
3429 }
3430 //if not that skilled do linear prediction
3431 else if (aim_skill > 0.4) {
3432 VectorSubtract(entinfo.origin, bs->origin, dir);
3433 //distance towards the enemy
3434 dist = VectorLength(dir);
3435 //direction the enemy is moving in
3436 VectorSubtract(entinfo.origin, entinfo.lastvisorigin, dir);
3437 dir[2] = 0;
3438 //
3439 speed = VectorNormalize(dir) / entinfo.update_time;
3440 //botimport.Print(PRT_MESSAGE, "speed = %f, wi->speed = %f\n", speed, wi->speed);
3441 //best spot to aim at
3442 VectorMA(entinfo.origin, (dist / wi.speed) * speed, dir, bestorigin);
3443 }
3444 }
3445 }
3446 //if the projectile does radial damage
3447 if (aim_skill > 0.6 && wi.proj.damagetype & DAMAGETYPE_RADIAL) {
3448 //if the enemy isn't standing significantly higher than the bot
3449 if (entinfo.origin[2] < bs->origin[2] + 16) {
3450 //try to aim at the ground in front of the enemy
3451 VectorCopy(entinfo.origin, end);
3452 end[2] -= 64;
3453 BotAI_Trace(&trace, entinfo.origin, NULL, NULL, end, entinfo.number, MASK_SHOT);
3454 //
3455 VectorCopy(bestorigin, groundtarget);
3456 if (trace.startsolid) groundtarget[2] = entinfo.origin[2] - 16;
3457 else groundtarget[2] = trace.endpos[2] - 8;
3458 //trace a line from projectile start to ground target
3459 BotAI_Trace(&trace, start, NULL, NULL, groundtarget, bs->entitynum, MASK_SHOT);
3460 //if hitpoint is not vertically too far from the ground target
3461 if (fabs(trace.endpos[2] - groundtarget[2]) < 50) {
3462 VectorSubtract(trace.endpos, groundtarget, dir);
3463 //if the hitpoint is near enough the ground target
3464 if (VectorLengthSquared(dir) < Square(60)) {
3465 VectorSubtract(trace.endpos, start, dir);
3466 //if the hitpoint is far enough from the bot
3467 if (VectorLengthSquared(dir) > Square(100)) {
3468 //check if the bot is visible from the ground target
3469 trace.endpos[2] += 1;
3470 BotAI_Trace(&trace, trace.endpos, NULL, NULL, entinfo.origin, entinfo.number, MASK_SHOT);
3471 if (trace.fraction >= 1) {
3472 //botimport.Print(PRT_MESSAGE, "%1.1f aiming at ground\n", AAS_Time());
3473 VectorCopy(groundtarget, bestorigin);
3474 }
3475 }
3476 }
3477 }
3478 }
3479 }
3480 bestorigin[0] += 20 * crandom() * (1 - aim_accuracy);
3481 bestorigin[1] += 20 * crandom() * (1 - aim_accuracy);
3482 bestorigin[2] += 10 * crandom() * (1 - aim_accuracy);
3483 }
3484 else {
3485 //
3486 VectorCopy(bs->lastenemyorigin, bestorigin);
3487 bestorigin[2] += 8;
3488 //if the bot is skilled enough
3489 if (aim_skill > 0.5) {
3490 //do prediction shots around corners
3491 if (wi.number == WP_BFG ||
3492 wi.number == WP_ROCKET_LAUNCHER ||
3493 wi.number == WP_GRENADE_LAUNCHER) {
3494 //create the chase goal
3495 goal.entitynum = bs->client;
3496 goal.areanum = bs->areanum;
3497 VectorCopy(bs->eye, goal.origin);
3498 VectorSet(goal.mins, -8, -8, -8);
3499 VectorSet(goal.maxs, 8, 8, 8);
3500 //
3501 if (trap_BotPredictVisiblePosition(bs->lastenemyorigin, bs->lastenemyareanum, &goal, TFL_DEFAULT, target)) {
3502 VectorSubtract(target, bs->eye, dir);
3503 if (VectorLengthSquared(dir) > Square(80)) {
3504 VectorCopy(target, bestorigin);
3505 bestorigin[2] -= 20;
3506 }
3507 }
3508 aim_accuracy = 1;
3509 }
3510 }
3511 }
3512 //
3513 if (enemyvisible) {
3514 BotAI_Trace(&trace, bs->eye, NULL, NULL, bestorigin, bs->entitynum, MASK_SHOT);
3515 VectorCopy(trace.endpos, bs->aimtarget);
3516 }
3517 else {
3518 VectorCopy(bestorigin, bs->aimtarget);
3519 }
3520 //get aim direction
3521 VectorSubtract(bestorigin, bs->eye, dir);
3522 //
3523 if (wi.number == WP_MACHINEGUN ||
3524 wi.number == WP_SHOTGUN ||
3525 wi.number == WP_LIGHTNING ||
3526 wi.number == WP_RAILGUN) {
3527 //distance towards the enemy
3528 dist = VectorLength(dir);
3529 if (dist > 150) dist = 150;
3530 f = 0.6 + dist / 150 * 0.4;
3531 aim_accuracy *= f;
3532 }
3533 //add some random stuff to the aim direction depending on the aim accuracy
3534 if (aim_accuracy < 0.8) {
3535 VectorNormalize(dir);
3536 for (i = 0; i < 3; i++) dir[i] += 0.3 * crandom() * (1 - aim_accuracy);
3537 }
3538 //set the ideal view angles
3539 vectoangles(dir, bs->ideal_viewangles);
3540 //take the weapon spread into account for lower skilled bots
3541 bs->ideal_viewangles[PITCH] += 6 * wi.vspread * crandom() * (1 - aim_accuracy);
3542 bs->ideal_viewangles[PITCH] = AngleMod(bs->ideal_viewangles[PITCH]);
3543 bs->ideal_viewangles[YAW] += 6 * wi.hspread * crandom() * (1 - aim_accuracy);
3544 bs->ideal_viewangles[YAW] = AngleMod(bs->ideal_viewangles[YAW]);
3545 //if the bots should be really challenging
3546 if (bot_challenge.integer) {
3547 //if the bot is really accurate and has the enemy in view for some time
3548 if (aim_accuracy > 0.9 && bs->enemysight_time < FloatTime() - 1) {
3549 //set the view angles directly
3550 if (bs->ideal_viewangles[PITCH] > 180) bs->ideal_viewangles[PITCH] -= 360;
3551 VectorCopy(bs->ideal_viewangles, bs->viewangles);
3552 trap_EA_View(bs->client, bs->viewangles);
3553 }
3554 }
3555 }
3556
3557 /*
3558 ==================
3559 BotCheckAttack
3560 ==================
3561 */
3562 void BotCheckAttack(bot_state_t *bs) {
3563 float points, reactiontime, fov, firethrottle;
3564 int attackentity;
3565 bsp_trace_t bsptrace;
3566 //float selfpreservation;
3567 vec3_t forward, right, start, end, dir, angles;
3568 weaponinfo_t wi;
3569 bsp_trace_t trace;
3570 aas_entityinfo_t entinfo;
3571 vec3_t mins = {-8, -8, -8}, maxs = {8, 8, 8};
3572
3573 attackentity = bs->enemy;
3574 //
3575 BotEntityInfo(attackentity, &entinfo);
3576 // if not attacking a player
3577 if (attackentity >= MAX_CLIENTS) {
3578 #ifdef MISSIONPACK
3579 // if attacking an obelisk
3580 if ( entinfo.number == redobelisk.entitynum ||
3581 entinfo.number == blueobelisk.entitynum ) {
3582 // if obelisk is respawning return
3583 if ( g_entities[entinfo.number].activator &&
3584 g_entities[entinfo.number].activator->s.frame == 2 ) {
3585 return;
3586 }
3587 }
3588 #endif
3589 }
3590 //
3591 reactiontime = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_REACTIONTIME, 0, 1);
3592 if (bs->enemysight_time > FloatTime() - reactiontime) return;
3593 if (bs->teleport_time > FloatTime() - reactiontime) return;
3594 //if changing weapons
3595 if (bs->weaponchange_time > FloatTime() - 0.1) return;
3596 //check fire throttle characteristic
3597 if (bs->firethrottlewait_time > FloatTime()) return;
3598 firethrottle = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_FIRETHROTTLE, 0, 1);
3599 if (bs->firethrottleshoot_time < FloatTime()) {
3600 if (random() > firethrottle) {
3601 bs->firethrottlewait_time = FloatTime() + firethrottle;
3602 bs->firethrottleshoot_time = 0;
3603 }
3604 else {
3605 bs->firethrottleshoot_time = FloatTime() + 1 - firethrottle;
3606 bs->firethrottlewait_time = 0;
3607 }
3608 }
3609 //
3610 //
3611 VectorSubtract(bs->aimtarget, bs->eye, dir);
3612 //
3613 if (bs->weaponnum == WP_GAUNTLET) {
3614 if (VectorLengthSquared(dir) > Square(60)) {
3615 return;
3616 }
3617 }
3618 if (VectorLengthSquared(dir) < Square(100))
3619 fov = 120;
3620 else
3621 fov = 50;
3622 //
3623 vectoangles(dir, angles);
3624 if (!InFieldOfVision(bs->viewangles, fov, angles))
3625 return;
3626 BotAI_Trace(&bsptrace, bs->eye, NULL, NULL, bs->aimtarget, bs->client, CONTENTS_SOLID|CONTENTS_PLAYERCLIP);
3627 if (bsptrace.fraction < 1 && bsptrace.ent != attackentity)
3628 return;
3629
3630 //get the weapon info
3631 trap_BotGetWeaponInfo(bs->ws, bs->weaponnum, &wi);
3632 //get the start point shooting from
3633 VectorCopy(bs->origin, start);
3634 start[2] += bs->cur_ps.viewheight;
3635 AngleVectors(bs->viewangles, forward, right, NULL);
3636 start[0] += forward[0] * wi.offset[0] + right[0] * wi.offset[1];
3637 start[1] += forward[1] * wi.offset[0] + right[1] * wi.offset[1];
3638 start[2] += forward[2] * wi.offset[0] + right[2] * wi.offset[1] + wi.offset[2];
3639 //end point aiming at
3640 VectorMA(start, 1000, forward, end);
3641 //a little back to make sure not inside a very close enemy
3642 VectorMA(start, -12, forward, start);
3643 BotAI_Trace(&trace, start, mins, maxs, end, bs->entitynum, MASK_SHOT);
3644 //if the entity is a client
3645 if (trace.ent >= 0 && trace.ent < MAX_CLIENTS) {
3646 if (trace.ent != attackentity) {
3647 //if a teammate is hit
3648 if (BotSameTeam(bs, trace.ent))
3649 return;
3650 }
3651 }
3652 //if won't hit the enemy or not attacking a player (obelisk)
3653 if (trace.ent != attackentity || attackentity >= MAX_CLIENTS) {
3654 //if the projectile does radial damage
3655 if (wi.proj.damagetype & DAMAGETYPE_RADIAL) {
3656 if (trace.fraction * 1000 < wi.proj.radius) {
3657 points = (wi.proj.damage - 0.5 * trace.fraction * 1000) * 0.5;
3658 if (points > 0) {
3659 return;
3660 }
3661 }
3662 //FIXME: check if a teammate gets radial damage
3663 }
3664 }
3665 //if fire has to be release to activate weapon
3666 if (wi.flags & WFL_FIRERELEASED) {
3667 if (bs->flags & BFL_ATTACKED) {
3668 trap_EA_Attack(bs->client);
3669 }
3670 }
3671 else {
3672 trap_EA_Attack(bs->client);
3673 }
3674 bs->flags ^= BFL_ATTACKED;
3675 }
3676
3677 /*
3678 ==================
3679 BotMapScripts
3680 ==================
3681 */
3682 void BotMapScripts(bot_state_t *bs) {
3683 char info[1024];
3684 char mapname[128];
3685 int i, shootbutton;
3686 float aim_accuracy;
3687 aas_entityinfo_t entinfo;
3688 vec3_t dir;
3689
3690 trap_GetServerinfo(info, sizeof(info));
3691
3692 Q_strncpyz(mapname, Info_ValueForKey( info, "mapname" ), sizeof(mapname));
3693
3694 if (!Q_stricmp(mapname, "q3tourney6") || !Q_stricmp(mapname, "q3tourney6_ctf") || !Q_stricmp(mapname, "mpq3tourney6")) {
3695 vec3_t mins = {694, 200, 480}, maxs = {968, 472, 680};
3696 vec3_t buttonorg = {304, 352, 920};
3697 //NOTE: NEVER use the func_bobbing in q3tourney6
3698 bs->tfl &= ~TFL_FUNCBOB;
3699 //crush area is higher in mpq3tourney6
3700 if (!Q_stricmp(mapname, "mpq3tourney6")) {
3701 mins[2] += 64;
3702 maxs[2] += 64;
3703 }
3704 //if the bot is in the bounding box of the crush area
3705 if (bs->origin[0] > mins[0] && bs->origin[0] < maxs[0]) {
3706 if (bs->origin[1] > mins[1] && bs->origin[1] < maxs[1]) {
3707 if (bs->origin[2] > mins[2] && bs->origin[2] < maxs[2]) {
3708 return;
3709 }
3710 }
3711 }
3712 shootbutton = qfalse;
3713 //if an enemy is in the bounding box then shoot the button
3714 for (i = 0; i < level.maxclients; i++) {
3715
3716 if (i == bs->client) continue;
3717 //
3718 BotEntityInfo(i, &entinfo);
3719 //
3720 if (!entinfo.valid) continue;
3721 //if the enemy isn't dead and the enemy isn't the bot self
3722 if (EntityIsDead(&entinfo) || entinfo.number == bs->entitynum) continue;
3723 //
3724 if (entinfo.origin[0] > mins[0] && entinfo.origin[0] < maxs[0]) {
3725 if (entinfo.origin[1] > mins[1] && entinfo.origin[1] < maxs[1]) {
3726 if (entinfo.origin[2] > mins[2] && entinfo.origin[2] < maxs[2]) {
3727 //if there's a team mate below the crusher
3728 if (BotSameTeam(bs, i)) {
3729 shootbutton = qfalse;
3730 break;
3731 }
3732 else if (gametype < GT_CTF || bs->enemy == i) {
3733 shootbutton = qtrue;
3734 }
3735 }
3736 }
3737 }
3738 }
3739 if (shootbutton) {
3740 bs->flags |= BFL_IDEALVIEWSET;
3741 VectorSubtract(buttonorg, bs->eye, dir);
3742 vectoangles(dir, bs->ideal_viewangles);
3743 aim_accuracy = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_AIM_ACCURACY, 0, 1);
3744 bs->ideal_viewangles[PITCH] += 8 * crandom() * (1 - aim_accuracy);
3745 bs->ideal_viewangles[PITCH] = AngleMod(bs->ideal_viewangles[PITCH]);
3746 bs->ideal_viewangles[YAW] += 8 * crandom() * (1 - aim_accuracy);
3747 bs->ideal_viewangles[YAW] = AngleMod(bs->ideal_viewangles[YAW]);
3748 //
3749 if (InFieldOfVision(bs->viewangles, 20, bs->ideal_viewangles)) {
3750 trap_EA_Attack(bs->client);
3751 }
3752 }
3753 }
3754 }
3755
3756 /*
3757 ==================
3758 BotSetMovedir
3759 ==================
3760 */
3761 static vec3_t VEC_UP = {0, -1, 0};
3762 static vec3_t MOVEDIR_UP = {0, 0, 1};
3763 static vec3_t VEC_DOWN = {0, -2, 0};
3764 static vec3_t MOVEDIR_DOWN = {0, 0, -1};
3765
3766 void BotSetMovedir(vec3_t angles, vec3_t movedir) {
3767 if (VectorCompare(angles, VEC_UP)) {
3768 VectorCopy(MOVEDIR_UP, movedir);
3769 }
3770 else if (VectorCompare(angles, VEC_DOWN)) {
3771 VectorCopy(MOVEDIR_DOWN, movedir);
3772 }
3773 else {
3774 AngleVectors(angles, movedir, NULL, NULL);
3775 }
3776 }
3777
3778 /*
3779 ==================
3780 BotModelMinsMaxs
3781
3782 this is ugly
3783 ==================
3784 */
3785 int BotModelMinsMaxs(int modelindex, int eType, int contents, vec3_t mins, vec3_t maxs) {
3786 gentity_t *ent;
3787 int i;
3788
3789 ent = &g_entities[0];
3790 for (i = 0; i < level.num_entities; i++, ent++) {
3791 if ( !ent->inuse ) {
3792 continue;
3793 }
3794 if ( eType && ent->s.eType != eType) {
3795 continue;
3796 }
3797 if ( contents && ent->r.contents != contents) {
3798 continue;
3799 }
3800 if (ent->s.modelindex == modelindex) {
3801 if (mins)
3802 VectorAdd(ent->r.currentOrigin, ent->r.mins, mins);
3803 if (maxs)
3804 VectorAdd(ent->r.currentOrigin, ent->r.maxs, maxs);
3805 return i;
3806 }
3807 }
3808 if (mins)
3809 VectorClear(mins);
3810 if (maxs)
3811 VectorClear(maxs);
3812 return 0;
3813 }
3814
3815 /*
3816 ==================
3817 BotFuncButtonGoal
3818 ==================
3819 */
3820 int BotFuncButtonActivateGoal(bot_state_t *bs, int bspent, bot_activategoal_t *activategoal) {
3821 int i, areas[10], numareas, modelindex, entitynum;
3822 char model[128];
3823 float lip, dist, health, angle;
3824 vec3_t size, start, end, mins, maxs, angles, points[10];
3825 vec3_t movedir, origin, goalorigin, bboxmins, bboxmaxs;
3826 vec3_t extramins = {1, 1, 1}, extramaxs = {-1, -1, -1};
3827 bsp_trace_t bsptrace;
3828
3829 activategoal->shoot = qfalse;
3830 VectorClear(activategoal->target);
3831 //create a bot goal towards the button
3832 trap_AAS_ValueForBSPEpairKey(bspent, "model", model, sizeof(model));
3833 if (!*model)
3834 return qfalse;
3835 modelindex = atoi(model+1);
3836 if (!modelindex)
3837 return qfalse;
3838 entitynum = BotModelMinsMaxs(modelindex, ET_MOVER, 0, mins, maxs);
3839 //get the lip of the button
3840 trap_AAS_FloatForBSPEpairKey(bspent, "lip", &lip);
3841 if (!lip) lip = 4;
3842 //get the move direction from the angle
3843 trap_AAS_FloatForBSPEpairKey(bspent, "angle", &angle);
3844 VectorSet(angles, 0, angle, 0);
3845 BotSetMovedir(angles, movedir);
3846 //button size
3847 VectorSubtract(maxs, mins, size);
3848 //button origin
3849 VectorAdd(mins, maxs, origin);
3850 VectorScale(origin, 0.5, origin);
3851 //touch distance of the button
3852 dist = fabs(movedir[0]) * size[0] + fabs(movedir[1]) * size[1] + fabs(movedir[2]) * size[2];
3853 dist *= 0.5;
3854 //
3855 trap_AAS_FloatForBSPEpairKey(bspent, "health", &health);
3856 //if the button is shootable
3857 if (health) {
3858 //calculate the shoot target
3859 VectorMA(origin, -dist, movedir, goalorigin);
3860 //
3861 VectorCopy(goalorigin, activategoal->target);
3862 activategoal->shoot = qtrue;
3863 //
3864 BotAI_Trace(&bsptrace, bs->eye, NULL, NULL, goalorigin, bs->entitynum, MASK_SHOT);
3865 // if the button is visible from the current position
3866 if (bsptrace.fraction >= 1.0 || bsptrace.ent == entitynum) {
3867 //
3868 activategoal->goal.entitynum = entitynum; //NOTE: this is the entity number of the shootable button
3869 activategoal->goal.number = 0;
3870 activategoal->goal.flags = 0;
3871 VectorCopy(bs->origin, activategoal->goal.origin);
3872 activategoal->goal.areanum = bs->areanum;
3873 VectorSet(activategoal->goal.mins, -8, -8, -8);
3874 VectorSet(activategoal->goal.maxs, 8, 8, 8);
3875 //
3876 return qtrue;
3877 }
3878 else {
3879 //create a goal from where the button is visible and shoot at the button from there
3880 //add bounding box size to the dist
3881 trap_AAS_PresenceTypeBoundingBox(PRESENCE_CROUCH, bboxmins, bboxmaxs);
3882 for (i = 0; i < 3; i++) {
3883 if (movedir[i] < 0) dist += fabs(movedir[i]) * fabs(bboxmaxs[i]);
3884 else dist += fabs(movedir[i]) * fabs(bboxmins[i]);
3885 }
3886 //calculate the goal origin
3887 VectorMA(origin, -dist, movedir, goalorigin);
3888 //
3889 VectorCopy(goalorigin, start);
3890 start[2] += 24;
3891 VectorCopy(start, end);
3892 end[2] -= 512;
3893 numareas = trap_AAS_TraceAreas(start, end, areas, points, 10);
3894 //
3895 for (i = numareas-1; i >= 0; i--) {
3896 if (trap_AAS_AreaReachability(areas[i])) {
3897 break;
3898 }
3899 }
3900 if (i < 0) {
3901 // FIXME: trace forward and maybe in other directions to find a valid area
3902 }
3903 if (i >= 0) {
3904 //
3905 VectorCopy(points[i], activategoal->goal.origin);
3906 activategoal->goal.areanum = areas[i];
3907 VectorSet(activategoal->goal.mins, 8, 8, 8);
3908 VectorSet(activategoal->goal.maxs, -8, -8, -8);
3909 //
3910 for (i = 0; i < 3; i++)
3911 {
3912 if (movedir[i] < 0) activategoal->goal.maxs[i] += fabs(movedir[i]) * fabs(extramaxs[i]);
3913 else activategoal->goal.mins[i] += fabs(movedir[i]) * fabs(extramins[i]);
3914 } //end for
3915 //
3916 activategoal->goal.entitynum = entitynum;
3917 activategoal->goal.number = 0;
3918 activategoal->goal.flags = 0;
3919 return qtrue;
3920 }
3921 }
3922 return qfalse;
3923 }
3924 else {
3925 //add bounding box size to the dist
3926 trap_AAS_PresenceTypeBoundingBox(PRESENCE_CROUCH, bboxmins, bboxmaxs);
3927 for (i = 0; i < 3; i++) {
3928 if (movedir[i] < 0) dist += fabs(movedir[i]) * fabs(bboxmaxs[i]);
3929 else dist += fabs(movedir[i]) * fabs(bboxmins[i]);
3930 }
3931 //calculate the goal origin
3932 VectorMA(origin, -dist, movedir, goalorigin);
3933 //
3934 VectorCopy(goalorigin, start);
3935 start[2] += 24;
3936 VectorCopy(start, end);
3937 end[2] -= 100;
3938 numareas = trap_AAS_TraceAreas(start, end, areas, NULL, 10);
3939 //
3940 for (i = 0; i < numareas; i++) {
3941 if (trap_AAS_AreaReachability(areas[i])) {
3942 break;
3943 }
3944 }
3945 if (i < numareas) {
3946 //
3947 VectorCopy(origin, activategoal->goal.origin);
3948 activategoal->goal.areanum = areas[i];
3949 VectorSubtract(mins, origin, activategoal->goal.mins);
3950 VectorSubtract(maxs, origin, activategoal->goal.maxs);
3951 //
3952 for (i = 0; i < 3; i++)
3953 {
3954 if (movedir[i] < 0) activategoal->goal.maxs[i] += fabs(movedir[i]) * fabs(extramaxs[i]);
3955 else activategoal->goal.mins[i] += fabs(movedir[i]) * fabs(extramins[i]);
3956 } //end for
3957 //
3958 activategoal->goal.entitynum = entitynum;
3959 activategoal->goal.number = 0;
3960 activategoal->goal.flags = 0;
3961 return qtrue;
3962 }
3963 }
3964 return qfalse;
3965 }
3966
3967 /*
3968 ==================
3969 BotFuncDoorGoal
3970 ==================
3971 */
3972 int BotFuncDoorActivateGoal(bot_state_t *bs, int bspent, bot_activategoal_t *activategoal) {
3973 int modelindex, entitynum;
3974 char model[MAX_INFO_STRING];
3975 vec3_t mins, maxs, origin;
3976
3977 //shoot at the shootable door
3978 trap_AAS_ValueForBSPEpairKey(bspent, "model", model, sizeof(model));
3979 if (!*model)
3980 return qfalse;
3981 modelindex = atoi(model+1);
3982 if (!modelindex)
3983 return qfalse;
3984 entitynum = BotModelMinsMaxs(modelindex, ET_MOVER, 0, mins, maxs);
3985 //door origin
3986 VectorAdd(mins, maxs, origin);
3987 VectorScale(origin, 0.5, origin);
3988 VectorCopy(origin, activategoal->target);
3989 activategoal->shoot = qtrue;
3990 //
3991 activategoal->goal.entitynum = entitynum; //NOTE: this is the entity number of the shootable door
3992 activategoal->goal.number = 0;
3993 activategoal->goal.flags = 0;
3994 VectorCopy(bs->origin, activategoal->goal.origin);
3995 activategoal->goal.areanum = bs->areanum;
3996 VectorSet(activategoal->goal.mins, -8, -8, -8);
3997 VectorSet(activategoal->goal.maxs, 8, 8, 8);
3998 return qtrue;
3999 }
4000
4001 /*
4002 ==================
4003 BotTriggerMultipleGoal
4004 ==================
4005 */
4006 int BotTriggerMultipleActivateGoal(bot_state_t *bs, int bspent, bot_activategoal_t *activategoal) {
4007 int i, areas[10], numareas, modelindex, entitynum;
4008 char model[128];
4009 vec3_t start, end, mins, maxs;
4010 vec3_t origin, goalorigin;
4011
4012 activategoal->shoot = qfalse;
4013 VectorClear(activategoal->target);
4014 //create a bot goal towards the trigger
4015 trap_AAS_ValueForBSPEpairKey(bspent, "model", model, sizeof(model));
4016 if (!*model)
4017 return qfalse;
4018 modelindex = atoi(model+1);
4019 if (!modelindex)
4020 return qfalse;
4021 entitynum = BotModelMinsMaxs(modelindex, 0, CONTENTS_TRIGGER, mins, maxs);
4022 //trigger origin
4023 VectorAdd(mins, maxs, origin);
4024 VectorScale(origin, 0.5, origin);
4025 VectorCopy(origin, goalorigin);
4026 //
4027 VectorCopy(goalorigin, start);
4028 start[2] += 24;
4029 VectorCopy(start, end);
4030 end[2] -= 100;
4031 numareas = trap_AAS_TraceAreas(start, end, areas, NULL, 10);
4032 //
4033 for (i = 0; i < numareas; i++) {
4034 if (trap_AAS_AreaReachability(areas[i])) {
4035 break;
4036 }
4037 }
4038 if (i < numareas) {
4039 VectorCopy(origin, activategoal->goal.origin);
4040 activategoal->goal.areanum = areas[i];
4041 VectorSubtract(mins, origin, activategoal->goal.mins);
4042 VectorSubtract(maxs, origin, activategoal->goal.maxs);
4043 //
4044 activategoal->goal.entitynum = entitynum;
4045 activategoal->goal.number = 0;
4046 activategoal->goal.flags = 0;
4047 return qtrue;
4048 }
4049 return qfalse;
4050 }
4051
4052 /*
4053 ==================
4054 BotPopFromActivateGoalStack
4055 ==================
4056 */
4057 int BotPopFromActivateGoalStack(bot_state_t *bs) {
4058 if (!bs->activatestack)
4059 return qfalse;
4060 BotEnableActivateGoalAreas(bs->activatestack, qtrue);
4061 bs->activatestack->inuse = qfalse;
4062 bs->activatestack->justused_time = FloatTime();
4063 bs->activatestack = bs->activatestack->next;
4064 return qtrue;
4065 }
4066
4067 /*
4068 ==================
4069 BotPushOntoActivateGoalStack
4070 ==================
4071 */
4072 int BotPushOntoActivateGoalStack(bot_state_t *bs, bot_activategoal_t *activategoal) {
4073 int i, best;
4074 float besttime;
4075
4076 best = -1;
4077 besttime = FloatTime() + 9999;
4078 //
4079 for (i = 0; i < MAX_ACTIVATESTACK; i++) {
4080 if (!bs->activategoalheap[i].inuse) {
4081 if (bs->activategoalheap[i].justused_time < besttime) {
4082 besttime = bs->activategoalheap[i].justused_time;
4083 best = i;
4084 }
4085 }
4086 }
4087 if (best != -1) {
4088 memcpy(&bs->activategoalheap[best], activategoal, sizeof(bot_activategoal_t));
4089 bs->activategoalheap[best].inuse = qtrue;
4090 bs->activategoalheap[best].next = bs->activatestack;
4091 bs->activatestack = &bs->activategoalheap[best];
4092 return qtrue;
4093 }
4094 return qfalse;
4095 }
4096
4097 /*
4098 ==================
4099 BotClearActivateGoalStack
4100 ==================
4101 */
4102 void BotClearActivateGoalStack(bot_state_t *bs) {
4103 while(bs->activatestack)
4104 BotPopFromActivateGoalStack(bs);
4105 }
4106
4107 /*
4108 ==================
4109 BotEnableActivateGoalAreas
4110 ==================
4111 */
4112 void BotEnableActivateGoalAreas(bot_activategoal_t *activategoal, int enable) {
4113 int i;
4114
4115 if (activategoal->areasdisabled == !enable)
4116 return;
4117 for (i = 0; i < activategoal->numareas; i++)
4118 trap_AAS_EnableRoutingArea( activategoal->areas[i], enable );
4119 activategoal->areasdisabled = !enable;
4120 }
4121
4122 /*
4123 ==================
4124 BotIsGoingToActivateEntity
4125 ==================
4126 */
4127 int BotIsGoingToActivateEntity(bot_state_t *bs, int entitynum) {
4128 bot_activategoal_t *a;
4129 int i;
4130
4131 for (a = bs->activatestack; a; a = a->next) {
4132 if (a->time < FloatTime())
4133 continue;
4134 if (a->goal.entitynum == entitynum)
4135 return qtrue;
4136 }
4137 for (i = 0; i < MAX_ACTIVATESTACK; i++) {
4138 if (bs->activategoalheap[i].inuse)
4139 continue;
4140 //
4141 if (bs->activategoalheap[i].goal.entitynum == entitynum) {
4142 // if the bot went for this goal less than 2 seconds ago
4143 if (bs->activategoalheap[i].justused_time > FloatTime() - 2)
4144 return qtrue;
4145 }
4146 }
4147 return qfalse;
4148 }
4149
4150 /*
4151 ==================
4152 BotGetActivateGoal
4153
4154 returns the number of the bsp entity to activate
4155 goal->entitynum will be set to the game entity to activate
4156 ==================
4157 */
4158 //#define OBSTACLEDEBUG
4159
4160 int BotGetActivateGoal(bot_state_t *bs, int entitynum, bot_activategoal_t *activategoal) {
4161 int i, ent, cur_entities[10], spawnflags, modelindex, areas[MAX_ACTIVATEAREAS*2], numareas, t;
4162 char model[MAX_INFO_STRING], tmpmodel[128];
4163 char target[128], classname[128];
4164 float health;
4165 char targetname[10][128];
4166 aas_entityinfo_t entinfo;
4167 aas_areainfo_t areainfo;
4168 vec3_t origin, absmins, absmaxs;
4169
4170 memset(activategoal, 0, sizeof(bot_activategoal_t));
4171 BotEntityInfo(entitynum, &entinfo);
4172 Com_sprintf(model, sizeof( model ), "*%d", entinfo.modelindex);
4173 for (ent = trap_AAS_NextBSPEntity(0); ent; ent = trap_AAS_NextBSPEntity(ent)) {
4174 if (!trap_AAS_ValueForBSPEpairKey(ent, "model", tmpmodel, sizeof(tmpmodel))) continue;
4175 if (!strcmp(model, tmpmodel)) break;
4176 }
4177 if (!ent) {
4178 BotAI_Print(PRT_ERROR, "BotGetActivateGoal: no entity found with model %s\n", model);
4179 return 0;
4180 }
4181 trap_AAS_ValueForBSPEpairKey(ent, "classname", classname, sizeof(classname));
4182 if (!*classname) {
4183 BotAI_Print(PRT_ERROR, "BotGetActivateGoal: entity with model %s has no classname\n", model);
4184 return 0;
4185 }
4186 //if it is a door
4187 if (!strcmp(classname, "func_door")) {
4188 if (trap_AAS_FloatForBSPEpairKey(ent, "health", &health)) {
4189 //if the door has health then the door must be shot to open
4190 if (health) {
4191 BotFuncDoorActivateGoal(bs, ent, activategoal);
4192 return ent;
4193 }
4194 }
4195 //
4196 trap_AAS_IntForBSPEpairKey(ent, "spawnflags", &spawnflags);
4197 // if the door starts open then just wait for the door to return
4198 if ( spawnflags & 1 )
4199 return 0;
4200 //get the door origin
4201 if (!trap_AAS_VectorForBSPEpairKey(ent, "origin", origin)) {
4202 VectorClear(origin);
4203 }
4204 //if the door is open or opening already
4205 if (!VectorCompare(origin, entinfo.origin))
4206 return 0;
4207 // store all the areas the door is in
4208 trap_AAS_ValueForBSPEpairKey(ent, "model", model, sizeof(model));
4209 if (*model) {
4210 modelindex = atoi(model+1);
4211 if (modelindex) {
4212 BotModelMinsMaxs(modelindex, ET_MOVER, 0, absmins, absmaxs);
4213 //
4214 numareas = trap_AAS_BBoxAreas(absmins, absmaxs, areas, MAX_ACTIVATEAREAS*2);
4215 // store the areas with reachabilities first
4216 for (i = 0; i < numareas; i++) {
4217 if (activategoal->numareas >= MAX_ACTIVATEAREAS)
4218 break;
4219 if ( !trap_AAS_AreaReachability(areas[i]) ) {
4220 continue;
4221 }
4222 trap_AAS_AreaInfo(areas[i], &areainfo);
4223 if (areainfo.contents & AREACONTENTS_MOVER) {
4224 activategoal->areas[activategoal->numareas++] = areas[i];
4225 }
4226 }
4227 // store any remaining areas
4228 for (i = 0; i < numareas; i++) {
4229 if (activategoal->numareas >= MAX_ACTIVATEAREAS)
4230 break;
4231 if ( trap_AAS_AreaReachability(areas[i]) ) {
4232 continue;
4233 }
4234 trap_AAS_AreaInfo(areas[i], &areainfo);
4235 if (areainfo.contents & AREACONTENTS_MOVER) {
4236 activategoal->areas[activategoal->numareas++] = areas[i];
4237 }
4238 }
4239 }
4240 }
4241 }
4242 // if the bot is blocked by or standing on top of a button
4243 if (!strcmp(classname, "func_button")) {
4244 return 0;
4245 }
4246 // get the targetname so we can find an entity with a matching target
4247 if (!trap_AAS_ValueForBSPEpairKey(ent, "targetname", targetname[0], sizeof(targetname[0]))) {
4248 if (bot_developer.integer) {
4249 BotAI_Print(PRT_ERROR, "BotGetActivateGoal: entity with model \"%s\" has no targetname\n", model);
4250 }
4251 return 0;
4252 }
4253 // allow tree-like activation
4254 cur_entities[0] = trap_AAS_NextBSPEntity(0);
4255 for (i = 0; i >= 0 && i < 10;) {
4256 for (ent = cur_entities[i]; ent; ent = trap_AAS_NextBSPEntity(ent)) {
4257 if (!trap_AAS_ValueForBSPEpairKey(ent, "target", target, sizeof(target))) continue;
4258 if (!strcmp(targetname[i], target)) {
4259 cur_entities[i] = trap_AAS_NextBSPEntity(ent);
4260 break;
4261 }
4262 }
4263 if (!ent) {
4264 if (bot_developer.integer) {
4265 BotAI_Print(PRT_ERROR, "BotGetActivateGoal: no entity with target \"%s\"\n", targetname[i]);
4266 }
4267 i--;
4268 continue;
4269 }
4270 if (!trap_AAS_ValueForBSPEpairKey(ent, "classname", classname, sizeof(classname))) {
4271 if (bot_developer.integer) {
4272 BotAI_Print(PRT_ERROR, "BotGetActivateGoal: entity with target \"%s\" has no classname\n", targetname[i]);
4273 }
4274 continue;
4275 }
4276 // BSP button model
4277 if (!strcmp(classname, "func_button")) {
4278 //
4279 if (!BotFuncButtonActivateGoal(bs, ent, activategoal))
4280 continue;
4281 // if the bot tries to activate this button already
4282 if ( bs->activatestack && bs->activatestack->inuse &&
4283 bs->activatestack->goal.entitynum == activategoal->goal.entitynum &&
4284 bs->activatestack->time > FloatTime() &&
4285 bs->activatestack->start_time < FloatTime() - 2)
4286 continue;
4287 // if the bot is in a reachability area
4288 if ( trap_AAS_AreaReachability(bs->areanum) ) {
4289 // disable all areas the blocking entity is in
4290 BotEnableActivateGoalAreas( activategoal, qfalse );
4291 //
4292 t = trap_AAS_AreaTravelTimeToGoalArea(bs->areanum, bs->origin, activategoal->goal.areanum, bs->tfl);
4293 // if the button is not reachable
4294 if (!t) {
4295 continue;
4296 }
4297 activategoal->time = FloatTime() + t * 0.01 + 5;
4298 }
4299 return ent;
4300 }
4301 // invisible trigger multiple box
4302 else if (!strcmp(classname, "trigger_multiple")) {
4303 //
4304 if (!BotTriggerMultipleActivateGoal(bs, ent, activategoal))
4305 continue;
4306 // if the bot tries to activate this trigger already
4307 if ( bs->activatestack && bs->activatestack->inuse &&
4308 bs->activatestack->goal.entitynum == activategoal->goal.entitynum &&
4309 bs->activatestack->time > FloatTime() &&
4310 bs->activatestack->start_time < FloatTime() - 2)
4311 continue;
4312 // if the bot is in a reachability area
4313 if ( trap_AAS_AreaReachability(bs->areanum) ) {
4314 // disable all areas the blocking entity is in
4315 BotEnableActivateGoalAreas( activategoal, qfalse );
4316 //
4317 t = trap_AAS_AreaTravelTimeToGoalArea(bs->areanum, bs->origin, activategoal->goal.areanum, bs->tfl);
4318 // if the trigger is not reachable
4319 if (!t) {
4320 continue;
4321 }
4322 activategoal->time = FloatTime() + t * 0.01 + 5;
4323 }
4324 return ent;
4325 }
4326 else if (!strcmp(classname, "func_timer")) {
4327 // just skip the func_timer
4328 continue;
4329 }
4330 // the actual button or trigger might be linked through a target_relay or target_delay
4331 else if (!strcmp(classname, "target_relay") || !strcmp(classname, "target_delay")) {
4332 if (trap_AAS_ValueForBSPEpairKey(ent, "targetname", targetname[i+1], sizeof(targetname[0]))) {
4333 i++;
4334 cur_entities[i] = trap_AAS_NextBSPEntity(0);
4335 }
4336 }
4337 }
4338 #ifdef OBSTACLEDEBUG
4339 BotAI_Print(PRT_ERROR, "BotGetActivateGoal: no valid activator for entity with target \"%s\"\n", targetname[0]);
4340 #endif
4341 return 0;
4342 }
4343
4344 /*
4345 ==================
4346 BotGoForActivateGoal
4347 ==================
4348 */
4349 int BotGoForActivateGoal(bot_state_t *bs, bot_activategoal_t *activategoal) {
4350 aas_entityinfo_t activateinfo;
4351
4352 activategoal->inuse = qtrue;
4353 if (!activategoal->time)
4354 activategoal->time = FloatTime() + 10;
4355 activategoal->start_time = FloatTime();
4356 BotEntityInfo(activategoal->goal.entitynum, &activateinfo);
4357 VectorCopy(activateinfo.origin, activategoal->origin);
4358 //
4359 if (BotPushOntoActivateGoalStack(bs, activategoal)) {
4360 // enter the activate entity AI node
4361 AIEnter_Seek_ActivateEntity(bs, "BotGoForActivateGoal");
4362 return qtrue;
4363 }
4364 else {
4365 // enable any routing areas that were disabled
4366 BotEnableActivateGoalAreas(activategoal, qtrue);
4367 return qfalse;
4368 }
4369 }
4370
4371 /*
4372 ==================
4373 BotPrintActivateGoalInfo
4374 ==================
4375 */
4376 void BotPrintActivateGoalInfo(bot_state_t *bs, bot_activategoal_t *activategoal, int bspent) {
4377 char netname[MAX_NETNAME];
4378 char classname[128];
4379 char buf[128];
4380
4381 ClientName(bs->client, netname, sizeof(netname));
4382 trap_AAS_ValueForBSPEpairKey(bspent, "classname", classname, sizeof(classname));
4383 if (activategoal->shoot) {
4384 Com_sprintf(buf, sizeof(buf), "%s: I have to shoot at a %s from %1.1f %1.1f %1.1f in area %d\n",
4385 netname, classname,
4386 activategoal->goal.origin[0],
4387 activategoal->goal.origin[1],
4388 activategoal->goal.origin[2],
4389 activategoal->goal.areanum);
4390 }
4391 else {
4392 Com_sprintf(buf, sizeof(buf), "%s: I have to activate a %s at %1.1f %1.1f %1.1f in area %d\n",
4393 netname, classname,
4394 activategoal->goal.origin[0],
4395 activategoal->goal.origin[1],
4396 activategoal->goal.origin[2],
4397 activategoal->goal.areanum);
4398 }
4399 trap_EA_Say(bs->client, buf);
4400 }
4401
4402 /*
4403 ==================
4404 BotRandomMove
4405 ==================
4406 */
4407 void BotRandomMove(bot_state_t *bs, bot_moveresult_t *moveresult) {
4408 vec3_t dir, angles;
4409
4410 angles[0] = 0;
4411 angles[1] = random() * 360;
4412 angles[2] = 0;
4413 AngleVectors(angles, dir, NULL, NULL);
4414
4415 trap_BotMoveInDirection(bs->ms, dir, 400, MOVE_WALK);
4416
4417 moveresult->failure = qfalse;
4418 VectorCopy(dir, moveresult->movedir);
4419 }
4420
4421 /*
4422 ==================
4423 BotAIBlocked
4424
4425 Very basic handling of bots being blocked by other entities.
4426 Check what kind of entity is blocking the bot and try to activate
4427 it. If that's not an option then try to walk around or over the entity.
4428 Before the bot ends in this part of the AI it should predict which doors to
4429 open, which buttons to activate etc.
4430 ==================
4431 */
4432 void BotAIBlocked(bot_state_t *bs, bot_moveresult_t *moveresult, int activate) {
4433 #ifdef OBSTACLEDEBUG
4434 char netname[MAX_NETNAME];
4435 #endif
4436 int movetype, bspent;
4437 vec3_t hordir, sideward, angles, up = {0, 0, 1};
4438 //vec3_t start, end, mins, maxs;
4439 aas_entityinfo_t entinfo;
4440 bot_activategoal_t activategoal;
4441
4442 // if the bot is not blocked by anything
4443 if (!moveresult->blocked) {
4444 bs->notblocked_time = FloatTime();
4445 return;
4446 }
4447 // if stuck in a solid area
4448 if ( moveresult->type == RESULTTYPE_INSOLIDAREA ) {
4449 // move in a random direction in the hope to get out
4450 BotRandomMove(bs, moveresult);
4451 //
4452 return;
4453 }
4454 // get info for the entity that is blocking the bot
4455 BotEntityInfo(moveresult->blockentity, &entinfo);
4456 #ifdef OBSTACLEDEBUG
4457 ClientName(bs->client, netname, sizeof(netname));
4458 BotAI_Print(PRT_MESSAGE, "%s: I'm blocked by model %d\n", netname, entinfo.modelindex);
4459 #endif // OBSTACLEDEBUG
4460 // if blocked by a bsp model and the bot wants to activate it
4461 if (activate && entinfo.modelindex > 0 && entinfo.modelindex <= max_bspmodelindex) {
4462 // find the bsp entity which should be activated in order to get the blocking entity out of the way
4463 bspent = BotGetActivateGoal(bs, entinfo.number, &activategoal);
4464 if (bspent) {
4465 //
4466 if (bs->activatestack && !bs->activatestack->inuse)
4467 bs->activatestack = NULL;
4468 // if not already trying to activate this entity
4469 if (!BotIsGoingToActivateEntity(bs, activategoal.goal.entitynum)) {
4470 //
4471 BotGoForActivateGoal(bs, &activategoal);
4472 }
4473 // if ontop of an obstacle or
4474 // if the bot is not in a reachability area it'll still
4475 // need some dynamic obstacle avoidance, otherwise return
4476 if (!(moveresult->flags & MOVERESULT_ONTOPOFOBSTACLE) &&
4477 trap_AAS_AreaReachability(bs->areanum))
4478 return;
4479 }
4480 else {
4481 // enable any routing areas that were disabled
4482 BotEnableActivateGoalAreas(&activategoal, qtrue);
4483 }
4484 }
4485 // just some basic dynamic obstacle avoidance code
4486 hordir[0] = moveresult->movedir[0];
4487 hordir[1] = moveresult->movedir[1];
4488 hordir[2] = 0;
4489 // if no direction just take a random direction
4490 if (VectorNormalize(hordir) < 0.1) {
4491 VectorSet(angles, 0, 360 * random(), 0);
4492 AngleVectors(angles, hordir, NULL, NULL);
4493 }
4494 //
4495 //if (moveresult->flags & MOVERESULT_ONTOPOFOBSTACLE) movetype = MOVE_JUMP;
4496 //else
4497 movetype = MOVE_WALK;
4498 // if there's an obstacle at the bot's feet and head then
4499 // the bot might be able to crouch through
4500 //VectorCopy(bs->origin, start);
4501 //start[2] += 18;
4502 //VectorMA(start, 5, hordir, end);
4503 //VectorSet(mins, -16, -16, -24);
4504 //VectorSet(maxs, 16, 16, 4);
4505 //
4506 //bsptrace = AAS_Trace(start, mins, maxs, end, bs->entitynum, MASK_PLAYERSOLID);
4507 //if (bsptrace.fraction >= 1) movetype = MOVE_CROUCH;
4508 // get the sideward vector
4509 CrossProduct(hordir, up, sideward);
4510 //
4511 if (bs->flags & BFL_AVOIDRIGHT) VectorNegate(sideward, sideward);
4512 // try to crouch straight forward?
4513 if (movetype != MOVE_CROUCH || !trap_BotMoveInDirection(bs->ms, hordir, 400, movetype)) {
4514 // perform the movement
4515 if (!trap_BotMoveInDirection(bs->ms, sideward, 400, movetype)) {
4516 // flip the avoid direction flag
4517 bs->flags ^= BFL_AVOIDRIGHT;
4518 // flip the direction
4519 // VectorNegate(sideward, sideward);
4520 VectorMA(sideward, -1, hordir, sideward);
4521 // move in the other direction
4522 trap_BotMoveInDirection(bs->ms, sideward, 400, movetype);
4523 }
4524 }
4525 //
4526 if (bs->notblocked_time < FloatTime() - 0.4) {
4527 // just reset goals and hope the bot will go into another direction?
4528 // is this still needed??
4529 if (bs->ainode == AINode_Seek_NBG) bs->nbg_time = 0;
4530 else if (bs->ainode == AINode_Seek_LTG) bs->ltg_time = 0;
4531 }
4532 }
4533
4534 /*
4535 ==================
4536 BotAIPredictObstacles
4537
4538 Predict the route towards the goal and check if the bot
4539 will be blocked by certain obstacles. When the bot has obstacles
4540 on its path the bot should figure out if they can be removed
4541 by activating certain entities.
4542 ==================
4543 */
4544 int BotAIPredictObstacles(bot_state_t *bs, bot_goal_t *goal) {
4545 int modelnum, entitynum, bspent;
4546 bot_activategoal_t activategoal;
4547 aas_predictroute_t route;
4548
4549 if (!bot_predictobstacles.integer)
4550 return qfalse;
4551
4552 // always predict when the goal change or at regular intervals
4553 if (bs->predictobstacles_goalareanum == goal->areanum &&
4554 bs->predictobstacles_time > FloatTime() - 6) {
4555 return qfalse;
4556 }
4557 bs->predictobstacles_goalareanum = goal->areanum;
4558 bs->predictobstacles_time = FloatTime();
4559
4560 // predict at most 100 areas or 1 second ahead
4561 trap_AAS_PredictRoute(&route, bs->areanum, bs->origin,
4562 goal->areanum, bs->tfl, 100, 1000,
4563 RSE_USETRAVELTYPE|RSE_ENTERCONTENTS,
4564 AREACONTENTS_MOVER, TFL_BRIDGE, 0);
4565 // if bot has to travel through an area with a mover
4566 if (route.stopevent & RSE_ENTERCONTENTS) {
4567 // if the bot will run into a mover
4568 if (route.endcontents & AREACONTENTS_MOVER) {
4569 //NOTE: this only works with bspc 2.1 or higher
4570 modelnum = (route.endcontents & AREACONTENTS_MODELNUM) >> AREACONTENTS_MODELNUMSHIFT;
4571 if (modelnum) {
4572 //
4573 entitynum = BotModelMinsMaxs(modelnum, ET_MOVER, 0, NULL, NULL);
4574 if (entitynum) {
4575 //NOTE: BotGetActivateGoal already checks if the door is open or not
4576 bspent = BotGetActivateGoal(bs, entitynum, &activategoal);
4577 if (bspent) {
4578 //
4579 if (bs->activatestack && !bs->activatestack->inuse)
4580 bs->activatestack = NULL;
4581 // if not already trying to activate this entity
4582 if (!BotIsGoingToActivateEntity(bs, activategoal.goal.entitynum)) {
4583 //
4584 //BotAI_Print(PRT_MESSAGE, "blocked by mover model %d, entity %d ?\n", modelnum, entitynum);
4585 //
4586 BotGoForActivateGoal(bs, &activategoal);
4587 return qtrue;
4588 }
4589 else {
4590 // enable any routing areas that were disabled
4591 BotEnableActivateGoalAreas(&activategoal, qtrue);
4592 }
4593 }
4594 }
4595 }
4596 }
4597 }
4598 else if (route.stopevent & RSE_USETRAVELTYPE) {
4599 if (route.endtravelflags & TFL_BRIDGE) {
4600 //FIXME: check if the bridge is available to travel over
4601 }
4602 }
4603 return qfalse;
4604 }
4605
4606 /*
4607 ==================
4608 BotCheckConsoleMessages
4609 ==================
4610 */
4611 void BotCheckConsoleMessages(bot_state_t *bs) {
4612 char botname[MAX_NETNAME], message[MAX_MESSAGE_SIZE], netname[MAX_NETNAME], *ptr;
4613 float chat_reply;
4614 int context, handle;
4615 bot_consolemessage_t m;
4616 bot_match_t match;
4617
4618 //the name of this bot
4619 ClientName(bs->client, botname, sizeof(botname));
4620 //
4621 while((handle = trap_BotNextConsoleMessage(bs->cs, &m)) != 0) {
4622 //if the chat state is flooded with messages the bot will read them quickly
4623 if (trap_BotNumConsoleMessages(bs->cs) < 10) {
4624 //if it is a chat message the bot needs some time to read it
4625 if (m.type == CMS_CHAT && m.time > FloatTime() - (1 + random())) break;
4626 }
4627 //
4628 ptr = m.message;
4629 //if it is a chat message then don't unify white spaces and don't
4630 //replace synonyms in the netname
4631 if (m.type == CMS_CHAT) {
4632 //
4633 if (trap_BotFindMatch(m.message, &match, MTCONTEXT_REPLYCHAT)) {
4634 ptr = m.message + match.variables[MESSAGE].offset;
4635 }
4636 }
4637 //unify the white spaces in the message
4638 trap_UnifyWhiteSpaces(ptr);
4639 //replace synonyms in the right context
4640 context = BotSynonymContext(bs);
4641 trap_BotReplaceSynonyms(ptr, context);
4642 //if there's no match
4643 if (!BotMatchMessage(bs, m.message)) {
4644 //if it is a chat message
4645 if (m.type == CMS_CHAT && !bot_nochat.integer) {
4646 //
4647 if (!trap_BotFindMatch(m.message, &match, MTCONTEXT_REPLYCHAT)) {
4648 trap_BotRemoveConsoleMessage(bs->cs, handle);
4649 continue;
4650 }
4651 //don't use eliza chats with team messages
4652 if (match.subtype & ST_TEAM) {
4653 trap_BotRemoveConsoleMessage(bs->cs, handle);
4654 continue;
4655 }
4656 //
4657 trap_BotMatchVariable(&match, NETNAME, netname, sizeof(netname));
4658 trap_BotMatchVariable(&match, MESSAGE, message, sizeof(message));
4659 //if this is a message from the bot self
4660 if (bs->client == ClientFromName(netname)) {
4661 trap_BotRemoveConsoleMessage(bs->cs, handle);
4662 continue;
4663 }
4664 //unify the message
4665 trap_UnifyWhiteSpaces(message);
4666 //
4667 trap_Cvar_Update(&bot_testrchat);
4668 if (bot_testrchat.integer) {
4669 //
4670 trap_BotLibVarSet("bot_testrchat", "1");
4671 //if bot replies with a chat message
4672 if (trap_BotReplyChat(bs->cs, message, context, CONTEXT_REPLY,
4673 NULL, NULL,
4674 NULL, NULL,
4675 NULL, NULL,
4676 botname, netname)) {
4677 BotAI_Print(PRT_MESSAGE, "------------------------\n");
4678 }
4679 else {
4680 BotAI_Print(PRT_MESSAGE, "**** no valid reply ****\n");
4681 }
4682 }
4683 //if at a valid chat position and not chatting already and not in teamplay
4684 else if (bs->ainode != AINode_Stand && BotValidChatPosition(bs) && !TeamPlayIsOn()) {
4685 chat_reply = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_CHAT_REPLY, 0, 1);
4686 if (random() < 1.5 / (NumBots()+1) && random() < chat_reply) {
4687 //if bot replies with a chat message
4688 if (trap_BotReplyChat(bs->cs, message, context, CONTEXT_REPLY,
4689 NULL, NULL,
4690 NULL, NULL,
4691 NULL, NULL,
4692 botname, netname)) {
4693 //remove the console message
4694 trap_BotRemoveConsoleMessage(bs->cs, handle);
4695 bs->stand_time = FloatTime() + BotChatTime(bs);
4696 AIEnter_Stand(bs, "BotCheckConsoleMessages: reply chat");
4697 //EA_Say(bs->client, bs->cs.chatmessage);
4698 break;
4699 }
4700 }
4701 }
4702 }
4703 }
4704 //remove the console message
4705 trap_BotRemoveConsoleMessage(bs->cs, handle);
4706 }
4707 }
4708
4709 /*
4710 ==================
4711 BotCheckEvents
4712 ==================
4713 */
4714 void BotCheckForGrenades(bot_state_t *bs, entityState_t *state) {
4715 // if this is not a grenade
4716 if (state->eType != ET_MISSILE || state->weapon != WP_GRENADE_LAUNCHER)
4717 return;
4718 // try to avoid the grenade
4719 trap_BotAddAvoidSpot(bs->ms, state->pos.trBase, 160, AVOID_ALWAYS);
4720 }
4721
4722 #ifdef MISSIONPACK
4723 /*
4724 ==================
4725 BotCheckForProxMines
4726 ==================
4727 */
4728 void BotCheckForProxMines(bot_state_t *bs, entityState_t *state) {
4729 // if this is not a prox mine
4730 if (state->eType != ET_MISSILE || state->weapon != WP_PROX_LAUNCHER)
4731 return;
4732 // if this prox mine is from someone on our own team
4733 if (state->generic1 == BotTeam(bs))
4734 return;
4735 // if the bot doesn't have a weapon to deactivate the mine
4736 if (!(bs->inventory[INVENTORY_PLASMAGUN] > 0 && bs->inventory[INVENTORY_CELLS] > 0) &&
4737 !(bs->inventory[INVENTORY_ROCKETLAUNCHER] > 0 && bs->inventory[INVENTORY_ROCKETS] > 0) &&
4738 !(bs->inventory[INVENTORY_BFG10K] > 0 && bs->inventory[INVENTORY_BFGAMMO] > 0) ) {
4739 return;
4740 }
4741 // try to avoid the prox mine
4742 trap_BotAddAvoidSpot(bs->ms, state->pos.trBase, 160, AVOID_ALWAYS);
4743 //
4744 if (bs->numproxmines >= MAX_PROXMINES)
4745 return;
4746 bs->proxmines[bs->numproxmines] = state->number;
4747 bs->numproxmines++;
4748 }
4749
4750 /*
4751 ==================
4752 BotCheckForKamikazeBody
4753 ==================
4754 */
4755 void BotCheckForKamikazeBody(bot_state_t *bs, entityState_t *state) {
4756 // if this entity is not wearing the kamikaze
4757 if (!(state->eFlags & EF_KAMIKAZE))
4758 return;
4759 // if this entity isn't dead
4760 if (!(state->eFlags & EF_DEAD))
4761 return;
4762 //remember this kamikaze body
4763 bs->kamikazebody = state->number;
4764 }
4765 #endif
4766
4767 /*
4768 ==================
4769 BotCheckEvents
4770 ==================
4771 */
4772 void BotCheckEvents(bot_state_t *bs, entityState_t *state) {
4773 int event;
4774 char buf[128];
4775 #ifdef MISSIONPACK
4776 aas_entityinfo_t entinfo;
4777 #endif
4778
4779 //NOTE: this sucks, we're accessing the gentity_t directly
4780 //but there's no other fast way to do it right now
4781 if (bs->entityeventTime[state->number] == g_entities[state->number].eventTime) {
4782 return;
4783 }
4784 bs->entityeventTime[state->number] = g_entities[state->number].eventTime;
4785 //if it's an event only entity
4786 if (state->eType > ET_EVENTS) {
4787 event = (state->eType - ET_EVENTS) & ~EV_EVENT_BITS;
4788 }
4789 else {
4790 event = state->event & ~EV_EVENT_BITS;
4791 }
4792 //
4793 switch(event) {
4794 //client obituary event
4795 case EV_OBITUARY:
4796 {
4797 int target, attacker, mod;
4798
4799 target = state->otherEntityNum;
4800 attacker = state->otherEntityNum2;
4801 mod = state->eventParm;
4802 //
4803 if (target == bs->client) {
4804 bs->botdeathtype = mod;
4805 bs->lastkilledby = attacker;
4806 //
4807 if (target == attacker ||
4808 target == ENTITYNUM_NONE ||
4809 target == ENTITYNUM_WORLD) bs->botsuicide = qtrue;
4810 else bs->botsuicide = qfalse;
4811 //
4812 bs->num_deaths++;
4813 }
4814 //else if this client was killed by the bot
4815 else if (attacker == bs->client) {
4816 bs->enemydeathtype = mod;
4817 bs->lastkilledplayer = target;
4818 bs->killedenemy_time = FloatTime();
4819 //
4820 bs->num_kills++;
4821 }
4822 else if (attacker == bs->enemy && target == attacker) {
4823 bs->enemysuicide = qtrue;
4824 }
4825 //
4826 #ifdef MISSIONPACK
4827 if (gametype == GT_1FCTF) {
4828 //
4829 BotEntityInfo(target, &entinfo);
4830 if ( entinfo.powerups & ( 1 << PW_NEUTRALFLAG ) ) {
4831 if (!BotSameTeam(bs, target)) {
4832 bs->neutralflagstatus = 3; //enemy dropped the flag
4833 bs->flagstatuschanged = qtrue;
4834 }
4835 }
4836 }
4837 #endif
4838 break;
4839 }
4840 case EV_GLOBAL_SOUND:
4841 {
4842 if (state->eventParm < 0 || state->eventParm >= MAX_SOUNDS) {
4843 BotAI_Print(PRT_ERROR, "EV_GLOBAL_SOUND: eventParm (%d) out of range\n", state->eventParm);
4844 break;
4845 }
4846 trap_GetConfigstring(CS_SOUNDS + state->eventParm, buf, sizeof(buf));
4847 /*
4848 if (!strcmp(buf, "sound/teamplay/flagret_red.wav")) {
4849 //red flag is returned
4850 bs->redflagstatus = 0;
4851 bs->flagstatuschanged = qtrue;
4852 }
4853 else if (!strcmp(buf, "sound/teamplay/flagret_blu.wav")) {
4854 //blue flag is returned
4855 bs->blueflagstatus = 0;
4856 bs->flagstatuschanged = qtrue;
4857 }
4858 else*/
4859 #ifdef MISSIONPACK
4860 if (!strcmp(buf, "sound/items/kamikazerespawn.wav" )) {
4861 //the kamikaze respawned so don't avoid it
4862 BotDontAvoid(bs, "Kamikaze");
4863 }
4864 else
4865 #endif
4866 if (!strcmp(buf, "sound/items/poweruprespawn.wav")) {
4867 //powerup respawned... go get it
4868 BotGoForPowerups(bs);
4869 }
4870 break;
4871 }
4872 case EV_GLOBAL_TEAM_SOUND:
4873 {
4874 if (gametype == GT_CTF) {
4875 switch(state->eventParm) {
4876 case GTS_RED_CAPTURE:
4877 bs->blueflagstatus = 0;
4878 bs->redflagstatus = 0;
4879 bs->flagstatuschanged = qtrue;
4880 break; //see BotMatch_CTF
4881 case GTS_BLUE_CAPTURE:
4882 bs->blueflagstatus = 0;
4883 bs->redflagstatus = 0;
4884 bs->flagstatuschanged = qtrue;
4885 break; //see BotMatch_CTF
4886 case GTS_RED_RETURN:
4887 //blue flag is returned
4888 bs->blueflagstatus = 0;
4889 bs->flagstatuschanged = qtrue;
4890 break;
4891 case GTS_BLUE_RETURN:
4892 //red flag is returned
4893 bs->redflagstatus = 0;
4894 bs->flagstatuschanged = qtrue;
4895 break;
4896 case GTS_RED_TAKEN:
4897 //blue flag is taken
4898 bs->blueflagstatus = 1;
4899 bs->flagstatuschanged = qtrue;
4900 break; //see BotMatch_CTF
4901 case GTS_BLUE_TAKEN:
4902 //red flag is taken
4903 bs->redflagstatus = 1;
4904 bs->flagstatuschanged = qtrue;
4905 break; //see BotMatch_CTF
4906 }
4907 }
4908 #ifdef MISSIONPACK
4909 else if (gametype == GT_1FCTF) {
4910 switch(state->eventParm) {
4911 case GTS_RED_CAPTURE:
4912 bs->neutralflagstatus = 0;
4913 bs->flagstatuschanged = qtrue;
4914 break;
4915 case GTS_BLUE_CAPTURE:
4916 bs->neutralflagstatus = 0;
4917 bs->flagstatuschanged = qtrue;
4918 break;
4919 case GTS_RED_RETURN:
4920 //flag has returned
4921 bs->neutralflagstatus = 0;
4922 bs->flagstatuschanged = qtrue;
4923 break;
4924 case GTS_BLUE_RETURN:
4925 //flag has returned
4926 bs->neutralflagstatus = 0;
4927 bs->flagstatuschanged = qtrue;
4928 break;
4929 case GTS_RED_TAKEN:
4930 bs->neutralflagstatus = BotTeam(bs) == TEAM_RED ? 2 : 1; //FIXME: check Team_TakeFlagSound in g_team.c
4931 bs->flagstatuschanged = qtrue;
4932 break;
4933 case GTS_BLUE_TAKEN:
4934 bs->neutralflagstatus = BotTeam(bs) == TEAM_BLUE ? 2 : 1; //FIXME: check Team_TakeFlagSound in g_team.c
4935 bs->flagstatuschanged = qtrue;
4936 break;
4937 }
4938 }
4939 #endif
4940 break;
4941 }
4942 case EV_PLAYER_TELEPORT_IN:
4943 {
4944 VectorCopy(state->origin, lastteleport_origin);
4945 lastteleport_time = FloatTime();
4946 break;
4947 }
4948 case EV_GENERAL_SOUND:
4949 {
4950 //if this sound is played on the bot
4951 if (state->number == bs->client) {
4952 if (state->eventParm < 0 || state->eventParm >= MAX_SOUNDS) {
4953 BotAI_Print(PRT_ERROR, "EV_GENERAL_SOUND: eventParm (%d) out of range\n", state->eventParm);
4954 break;
4955 }
4956 //check out the sound
4957 trap_GetConfigstring(CS_SOUNDS + state->eventParm, buf, sizeof(buf));
4958 //if falling into a death pit
4959 if (!strcmp(buf, "*falling1.wav")) {
4960 //if the bot has a personal teleporter
4961 if (bs->inventory[INVENTORY_TELEPORTER] > 0) {
4962 //use the holdable item
4963 trap_EA_Use(bs->client);
4964 }
4965 }
4966 }
4967 break;
4968 }
4969 case EV_FOOTSTEP:
4970 case EV_FOOTSTEP_METAL:
4971 case EV_FOOTSPLASH:
4972 case EV_FOOTWADE:
4973 case EV_SWIM:
4974 case EV_FALL_SHORT:
4975 case EV_FALL_MEDIUM:
4976 case EV_FALL_FAR:
4977 case EV_STEP_4:
4978 case EV_STEP_8:
4979 case EV_STEP_12:
4980 case EV_STEP_16:
4981 case EV_JUMP_PAD:
4982 case EV_JUMP:
4983 case EV_TAUNT:
4984 case EV_WATER_TOUCH:
4985 case EV_WATER_LEAVE:
4986 case EV_WATER_UNDER:
4987 case EV_WATER_CLEAR:
4988 case EV_ITEM_PICKUP:
4989 case EV_GLOBAL_ITEM_PICKUP:
4990 case EV_NOAMMO:
4991 case EV_CHANGE_WEAPON:
4992 case EV_FIRE_WEAPON:
4993 //FIXME: either add to sound queue or mark player as someone making noise
4994 break;
4995 case EV_USE_ITEM0:
4996 case EV_USE_ITEM1:
4997 case EV_USE_ITEM2:
4998 case EV_USE_ITEM3:
4999 case EV_USE_ITEM4:
5000 case EV_USE_ITEM5:
5001 case EV_USE_ITEM6:
5002 case EV_USE_ITEM7:
5003 case EV_USE_ITEM8:
5004 case EV_USE_ITEM9:
5005 case EV_USE_ITEM10:
5006 case EV_USE_ITEM11:
5007 case EV_USE_ITEM12:
5008 case EV_USE_ITEM13:
5009 case EV_USE_ITEM14:
5010 case EV_USE_ITEM15:
5011 break;
5012 }
5013 }
5014
5015 /*
5016 ==================
5017 BotCheckSnapshot
5018 ==================
5019 */
5020 void BotCheckSnapshot(bot_state_t *bs) {
5021 int ent;
5022 entityState_t state;
5023
5024 //remove all avoid spots
5025 trap_BotAddAvoidSpot(bs->ms, vec3_origin, 0, AVOID_CLEAR);
5026 //reset kamikaze body
5027 bs->kamikazebody = 0;
5028 //reset number of proxmines
5029 bs->numproxmines = 0;
5030 //
5031 ent = 0;
5032 while( ( ent = BotAI_GetSnapshotEntity( bs->client, ent, &state ) ) != -1 ) {
5033 //check the entity state for events
5034 BotCheckEvents(bs, &state);
5035 //check for grenades the bot should avoid
5036 BotCheckForGrenades(bs, &state);
5037 //
5038 #ifdef MISSIONPACK
5039 //check for proximity mines which the bot should deactivate
5040 BotCheckForProxMines(bs, &state);
5041 //check for dead bodies with the kamikaze effect which should be gibbed
5042 BotCheckForKamikazeBody(bs, &state);
5043 #endif
5044 }
5045 //check the player state for events
5046 BotAI_GetEntityState(bs->client, &state);
5047 //copy the player state events to the entity state
5048 state.event = bs->cur_ps.externalEvent;
5049 state.eventParm = bs->cur_ps.externalEventParm;
5050 //
5051 BotCheckEvents(bs, &state);
5052 }
5053
5054 /*
5055 ==================
5056 BotCheckAir
5057 ==================
5058 */
5059 void BotCheckAir(bot_state_t *bs) {
5060 if (bs->inventory[INVENTORY_ENVIRONMENTSUIT] <= 0) {
5061 if (trap_AAS_PointContents(bs->eye) & (CONTENTS_WATER|CONTENTS_SLIME|CONTENTS_LAVA)) {
5062 return;
5063 }
5064 }
5065 bs->lastair_time = FloatTime();
5066 }
5067
5068 /*
5069 ==================
5070 BotAlternateRoute
5071 ==================
5072 */
5073 bot_goal_t *BotAlternateRoute(bot_state_t *bs, bot_goal_t *goal) {
5074 int t;
5075
5076 // if the bot has an alternative route goal
5077 if (bs->altroutegoal.areanum) {
5078 //
5079 if (bs->reachedaltroutegoal_time)
5080 return goal;
5081 // travel time towards alternative route goal
5082 t = trap_AAS_AreaTravelTimeToGoalArea(bs->areanum, bs->origin, bs->altroutegoal.areanum, bs->tfl);
5083 if (t && t < 20) {
5084 //BotAI_Print(PRT_MESSAGE, "reached alternate route goal\n");
5085 bs->reachedaltroutegoal_time = FloatTime();
5086 }
5087 memcpy(goal, &bs->altroutegoal, sizeof(bot_goal_t));
5088 return &bs->altroutegoal;
5089 }
5090 return goal;
5091 }
5092
5093 /*
5094 ==================
5095 BotGetAlternateRouteGoal
5096 ==================
5097 */
5098 int BotGetAlternateRouteGoal(bot_state_t *bs, int base) {
5099 aas_altroutegoal_t *altroutegoals;
5100 bot_goal_t *goal;
5101 int numaltroutegoals, rnd;
5102
5103 if (base == TEAM_RED) {
5104 altroutegoals = red_altroutegoals;
5105 numaltroutegoals = red_numaltroutegoals;
5106 }
5107 else {
5108 altroutegoals = blue_altroutegoals;
5109 numaltroutegoals = blue_numaltroutegoals;
5110 }
5111 if (!numaltroutegoals)
5112 return qfalse;
5113 rnd = (float) random() * numaltroutegoals;
5114 if (rnd >= numaltroutegoals)
5115 rnd = numaltroutegoals-1;
5116 goal = &bs->altroutegoal;
5117 goal->areanum = altroutegoals[rnd].areanum;
5118 VectorCopy(altroutegoals[rnd].origin, goal->origin);
5119 VectorSet(goal->mins, -8, -8, -8);
5120 VectorSet(goal->maxs, 8, 8, 8);
5121 goal->entitynum = 0;
5122 goal->iteminfo = 0;
5123 goal->number = 0;
5124 goal->flags = 0;
5125 //
5126 bs->reachedaltroutegoal_time = 0;
5127 return qtrue;
5128 }
5129
5130 /*
5131 ==================
5132 BotSetupAlternateRouteGoals
5133 ==================
5134 */
5135 void BotSetupAlternativeRouteGoals(void) {
5136
5137 if (altroutegoals_setup)
5138 return;
5139 #ifdef MISSIONPACK
5140 if (gametype == GT_CTF) {
5141 if (trap_BotGetLevelItemGoal(-1, "Neutral Flag", &ctf_neutralflag) < 0)
5142 BotAI_Print(PRT_WARNING, "No alt routes without Neutral Flag\n");
5143 if (ctf_neutralflag.areanum) {
5144 //
5145 red_numaltroutegoals = trap_AAS_AlternativeRouteGoals(
5146 ctf_neutralflag.origin, ctf_neutralflag.areanum,
5147 ctf_redflag.origin, ctf_redflag.areanum, TFL_DEFAULT,
5148 red_altroutegoals, MAX_ALTROUTEGOALS,
5149 ALTROUTEGOAL_CLUSTERPORTALS|
5150 ALTROUTEGOAL_VIEWPORTALS);
5151 blue_numaltroutegoals = trap_AAS_AlternativeRouteGoals(
5152 ctf_neutralflag.origin, ctf_neutralflag.areanum,
5153 ctf_blueflag.origin, ctf_blueflag.areanum, TFL_DEFAULT,
5154 blue_altroutegoals, MAX_ALTROUTEGOALS,
5155 ALTROUTEGOAL_CLUSTERPORTALS|
5156 ALTROUTEGOAL_VIEWPORTALS);
5157 }
5158 }
5159 else if (gametype == GT_1FCTF) {
5160 if (trap_BotGetLevelItemGoal(-1, "Neutral Obelisk", &neutralobelisk) < 0)
5161 BotAI_Print(PRT_WARNING, "One Flag CTF without Neutral Obelisk\n");
5162 red_numaltroutegoals = trap_AAS_AlternativeRouteGoals(
5163 ctf_neutralflag.origin, ctf_neutralflag.areanum,
5164 ctf_redflag.origin, ctf_redflag.areanum, TFL_DEFAULT,
5165 red_altroutegoals, MAX_ALTROUTEGOALS,
5166 ALTROUTEGOAL_CLUSTERPORTALS|
5167 ALTROUTEGOAL_VIEWPORTALS);
5168 blue_numaltroutegoals = trap_AAS_AlternativeRouteGoals(
5169 ctf_neutralflag.origin, ctf_neutralflag.areanum,
5170 ctf_blueflag.origin, ctf_blueflag.areanum, TFL_DEFAULT,
5171 blue_altroutegoals, MAX_ALTROUTEGOALS,
5172 ALTROUTEGOAL_CLUSTERPORTALS|
5173 ALTROUTEGOAL_VIEWPORTALS);
5174 }
5175 else if (gametype == GT_OBELISK) {
5176 if (trap_BotGetLevelItemGoal(-1, "Neutral Obelisk", &neutralobelisk) < 0)
5177 BotAI_Print(PRT_WARNING, "No alt routes without Neutral Obelisk\n");
5178 //
5179 red_numaltroutegoals = trap_AAS_AlternativeRouteGoals(
5180 neutralobelisk.origin, neutralobelisk.areanum,
5181 redobelisk.origin, redobelisk.areanum, TFL_DEFAULT,
5182 red_altroutegoals, MAX_ALTROUTEGOALS,
5183 ALTROUTEGOAL_CLUSTERPORTALS|
5184 ALTROUTEGOAL_VIEWPORTALS);
5185 blue_numaltroutegoals = trap_AAS_AlternativeRouteGoals(
5186 neutralobelisk.origin, neutralobelisk.areanum,
5187 blueobelisk.origin, blueobelisk.areanum, TFL_DEFAULT,
5188 blue_altroutegoals, MAX_ALTROUTEGOALS,
5189 ALTROUTEGOAL_CLUSTERPORTALS|
5190 ALTROUTEGOAL_VIEWPORTALS);
5191 }
5192 else if (gametype == GT_HARVESTER) {
5193 if (trap_BotGetLevelItemGoal(-1, "Neutral Obelisk", &neutralobelisk) < 0)
5194 BotAI_Print(PRT_WARNING, "Harvester without Neutral Obelisk\n");
5195 red_numaltroutegoals = trap_AAS_AlternativeRouteGoals(
5196 neutralobelisk.origin, neutralobelisk.areanum,
5197 redobelisk.origin, redobelisk.areanum, TFL_DEFAULT,
5198 red_altroutegoals, MAX_ALTROUTEGOALS,
5199 ALTROUTEGOAL_CLUSTERPORTALS|
5200 ALTROUTEGOAL_VIEWPORTALS);
5201 blue_numaltroutegoals = trap_AAS_AlternativeRouteGoals(
5202 neutralobelisk.origin, neutralobelisk.areanum,
5203 blueobelisk.origin, blueobelisk.areanum, TFL_DEFAULT,
5204 blue_altroutegoals, MAX_ALTROUTEGOALS,
5205 ALTROUTEGOAL_CLUSTERPORTALS|
5206 ALTROUTEGOAL_VIEWPORTALS);
5207 }
5208 #endif
5209 altroutegoals_setup = qtrue;
5210 }
5211
5212 /*
5213 ==================
5214 BotDeathmatchAI
5215 ==================
5216 */
5217 void BotDeathmatchAI(bot_state_t *bs, float thinktime) {
5218 char gender[144], name[144];
5219 char userinfo[MAX_INFO_STRING];
5220 int i;
5221
5222 //if the bot has just been setup
5223 if (bs->setupcount > 0) {
5224 bs->setupcount--;
5225 if (bs->setupcount > 0) return;
5226 //get the gender characteristic
5227 trap_Characteristic_String(bs->character, CHARACTERISTIC_GENDER, gender, sizeof(gender));
5228 //set the bot gender
5229 trap_GetUserinfo(bs->client, userinfo, sizeof(userinfo));
5230 Info_SetValueForKey(userinfo, "sex", gender);
5231 trap_SetUserinfo(bs->client, userinfo);
5232 //set the chat gender
5233 if (gender[0] == 'm') trap_BotSetChatGender(bs->cs, CHAT_GENDERMALE);
5234 else if (gender[0] == 'f') trap_BotSetChatGender(bs->cs, CHAT_GENDERFEMALE);
5235 else trap_BotSetChatGender(bs->cs, CHAT_GENDERLESS);
5236 //set the chat name
5237 ClientName(bs->client, name, sizeof(name));
5238 trap_BotSetChatName(bs->cs, name, bs->client);
5239 //
5240 bs->lastframe_health = bs->inventory[INVENTORY_HEALTH];
5241 bs->lasthitcount = bs->cur_ps.persistant[PERS_HITS];
5242 //
5243 bs->setupcount = 0;
5244 //
5245 BotSetupAlternativeRouteGoals();
5246 }
5247 //no ideal view set
5248 bs->flags &= ~BFL_IDEALVIEWSET;
5249 //
5250 if (!BotIntermission(bs)) {
5251 //set the teleport time
5252 BotSetTeleportTime(bs);
5253 //update some inventory values
5254 BotUpdateInventory(bs);
5255 //check out the snapshot
5256 BotCheckSnapshot(bs);
5257 //check for air
5258 BotCheckAir(bs);
5259 }
5260 //check the console messages
5261 BotCheckConsoleMessages(bs);
5262 //if not in the intermission and not in observer mode
5263 if (!BotIntermission(bs) && !BotIsObserver(bs)) {
5264 //do team AI
5265 BotTeamAI(bs);
5266 }
5267 //if the bot has no ai node
5268 if (!bs->ainode) {
5269 AIEnter_Seek_LTG(bs, "BotDeathmatchAI: no ai node");
5270 }
5271 //if the bot entered the game less than 8 seconds ago
5272 if (!bs->entergamechat && bs->entergame_time > FloatTime() - 8) {
5273 if (BotChat_EnterGame(bs)) {
5274 bs->stand_time = FloatTime() + BotChatTime(bs);
5275 AIEnter_Stand(bs, "BotDeathmatchAI: chat enter game");
5276 }
5277 bs->entergamechat = qtrue;
5278 }
5279 //reset the node switches from the previous frame
5280 BotResetNodeSwitches();
5281 //execute AI nodes
5282 for (i = 0; i < MAX_NODESWITCHES; i++) {
5283 if (bs->ainode(bs)) break;
5284 }
5285 //if the bot removed itself :)
5286 if (!bs->inuse) return;
5287 //if the bot executed too many AI nodes
5288 if (i >= MAX_NODESWITCHES) {
5289 trap_BotDumpGoalStack(bs->gs);
5290 trap_BotDumpAvoidGoals(bs->gs);
5291 BotDumpNodeSwitches(bs);
5292 ClientName(bs->client, name, sizeof(name));
5293 BotAI_Print(PRT_ERROR, "%s at %1.1f switched more than %d AI nodes\n", name, FloatTime(), MAX_NODESWITCHES);
5294 }
5295 //
5296 bs->lastframe_health = bs->inventory[INVENTORY_HEALTH];
5297 bs->lasthitcount = bs->cur_ps.persistant[PERS_HITS];
5298 }
5299
5300 /*
5301 ==================
5302 BotSetEntityNumForGoalWithModel
5303 ==================
5304 */
5305 void BotSetEntityNumForGoalWithModel(bot_goal_t *goal, int eType, char *modelname) {
5306 gentity_t *ent;
5307 int i, modelindex;
5308 vec3_t dir;
5309
5310 modelindex = G_ModelIndex( modelname );
5311 ent = &g_entities[0];
5312 for (i = 0; i < level.num_entities; i++, ent++) {
5313 if ( !ent->inuse ) {
5314 continue;
5315 }
5316 if ( eType && ent->s.eType != eType) {
5317 continue;
5318 }
5319 if (ent->s.modelindex != modelindex) {
5320 continue;
5321 }
5322 VectorSubtract(goal->origin, ent->s.origin, dir);
5323 if (VectorLengthSquared(dir) < Square(10)) {
5324 goal->entitynum = i;
5325 return;
5326 }
5327 }
5328 }
5329
5330 /*
5331 ==================
5332 BotSetEntityNumForGoal
5333 ==================
5334 */
5335 void BotSetEntityNumForGoal(bot_goal_t *goal, char *classname) {
5336 gentity_t *ent;
5337 int i;
5338 vec3_t dir;
5339
5340 ent = &g_entities[0];
5341 for (i = 0; i < level.num_entities; i++, ent++) {
5342 if ( !ent->inuse ) {
5343 continue;
5344 }
5345 if ( Q_stricmp(ent->classname, classname) != 0 ) {
5346 continue;
5347 }
5348 VectorSubtract(goal->origin, ent->s.origin, dir);
5349 if (VectorLengthSquared(dir) < Square(10)) {
5350 goal->entitynum = i;
5351 return;
5352 }
5353 }
5354 }
5355
5356 /*
5357 ==================
5358 BotSetEntityNumForGoalWithActivator
5359 ==================
5360 */
5361 void BotSetEntityNumForGoalWithActivator(bot_goal_t *goal, char *classname) {
5362 gentity_t *ent;
5363 int i;
5364 vec3_t dir;
5365
5366 ent = &g_entities[0];
5367 for (i = 0; i < level.num_entities; i++, ent++) {
5368 if ( !ent->inuse || !ent->activator ) {
5369 continue;
5370 }
5371 if ( Q_stricmp(ent->activator->classname, classname) != 0 ) {
5372 continue;
5373 }
5374 VectorSubtract(goal->origin, ent->s.origin, dir);
5375 if (VectorLengthSquared(dir) < Square(10)) {
5376 goal->entitynum = i;
5377 return;
5378 }
5379 }
5380 }
5381
5382 /*
5383 ==================
5384 BotGoalForBSPEntity
5385 ==================
5386 */
5387 int BotGoalForBSPEntity( char *classname, bot_goal_t *goal ) {
5388 char value[MAX_INFO_STRING];
5389 vec3_t origin, start, end;
5390 int ent, numareas, areas[10];
5391
5392 memset(goal, 0, sizeof(bot_goal_t));
5393 for (ent = trap_AAS_NextBSPEntity(0); ent; ent = trap_AAS_NextBSPEntity(ent)) {
5394 if (!trap_AAS_ValueForBSPEpairKey(ent, "classname", value, sizeof(value)))
5395 continue;
5396 if (!strcmp(value, classname)) {
5397 if (!trap_AAS_VectorForBSPEpairKey(ent, "origin", origin))
5398 return qfalse;
5399 VectorCopy(origin, goal->origin);
5400 VectorCopy(origin, start);
5401 start[2] -= 32;
5402 VectorCopy(origin, end);
5403 end[2] += 32;
5404 numareas = trap_AAS_TraceAreas(start, end, areas, NULL, 10);
5405 if (!numareas)
5406 return qfalse;
5407 goal->areanum = areas[0];
5408 return qtrue;
5409 }
5410 }
5411 return qfalse;
5412 }
5413
5414 /*
5415 ==================
5416 BotSetupDeathmatchAI
5417 ==================
5418 */
5419 void BotSetupDeathmatchAI(void) {
5420 int ent, modelnum;
5421 char model[128];
5422
5423 gametype = trap_Cvar_VariableIntegerValue("g_gametype");
5424
5425 trap_Cvar_Register(&bot_rocketjump, "bot_rocketjump", "1", 0);
5426 trap_Cvar_Register(&bot_grapple, "bot_grapple", "0", 0);
5427 trap_Cvar_Register(&bot_fastchat, "bot_fastchat", "0", 0);
5428 trap_Cvar_Register(&bot_nochat, "bot_nochat", "0", 0);
5429 trap_Cvar_Register(&bot_testrchat, "bot_testrchat", "0", 0);
5430 trap_Cvar_Register(&bot_challenge, "bot_challenge", "0", 0);
5431 trap_Cvar_Register(&bot_predictobstacles, "bot_predictobstacles", "1", 0);
5432 trap_Cvar_Register(&g_spSkill, "g_spSkill", "2", 0);
5433 //
5434 if (gametype == GT_CTF) {
5435 if (trap_BotGetLevelItemGoal(-1, "Red Flag", &ctf_redflag) < 0)
5436 BotAI_Print(PRT_WARNING, "CTF without Red Flag\n");
5437 if (trap_BotGetLevelItemGoal(-1, "Blue Flag", &ctf_blueflag) < 0)
5438 BotAI_Print(PRT_WARNING, "CTF without Blue Flag\n");
5439 }
5440 #ifdef MISSIONPACK
5441 else if (gametype == GT_1FCTF) {
5442 if (trap_BotGetLevelItemGoal(-1, "Neutral Flag", &ctf_neutralflag) < 0)
5443 BotAI_Print(PRT_WARNING, "One Flag CTF without Neutral Flag\n");
5444 if (trap_BotGetLevelItemGoal(-1, "Red Flag", &ctf_redflag) < 0)
5445 BotAI_Print(PRT_WARNING, "One Flag CTF without Red Flag\n");
5446 if (trap_BotGetLevelItemGoal(-1, "Blue Flag", &ctf_blueflag) < 0)
5447 BotAI_Print(PRT_WARNING, "One Flag CTF without Blue Flag\n");
5448 }
5449 else if (gametype == GT_OBELISK) {
5450 if (trap_BotGetLevelItemGoal(-1, "Red Obelisk", &redobelisk) < 0)
5451 BotAI_Print(PRT_WARNING, "Overload without Red Obelisk\n");
5452 BotSetEntityNumForGoalWithActivator(&redobelisk, "team_redobelisk");
5453 if (trap_BotGetLevelItemGoal(-1, "Blue Obelisk", &blueobelisk) < 0)
5454 BotAI_Print(PRT_WARNING, "Overload without Blue Obelisk\n");
5455 BotSetEntityNumForGoalWithActivator(&blueobelisk, "team_blueobelisk");
5456 }
5457 else if (gametype == GT_HARVESTER) {
5458 if (trap_BotGetLevelItemGoal(-1, "Red Obelisk", &redobelisk) < 0)
5459 BotAI_Print(PRT_WARNING, "Harvester without Red Obelisk\n");
5460 BotSetEntityNumForGoalWithActivator(&redobelisk, "team_redobelisk");
5461 if (trap_BotGetLevelItemGoal(-1, "Blue Obelisk", &blueobelisk) < 0)
5462 BotAI_Print(PRT_WARNING, "Harvester without Blue Obelisk\n");
5463 BotSetEntityNumForGoalWithActivator(&blueobelisk, "team_blueobelisk");
5464 if (trap_BotGetLevelItemGoal(-1, "Neutral Obelisk", &neutralobelisk) < 0)
5465 BotAI_Print(PRT_WARNING, "Harvester without Neutral Obelisk\n");
5466 BotSetEntityNumForGoalWithActivator(&neutralobelisk, "team_neutralobelisk");
5467 }
5468 #endif
5469
5470 max_bspmodelindex = 0;
5471 for (ent = trap_AAS_NextBSPEntity(0); ent; ent = trap_AAS_NextBSPEntity(ent)) {
5472 if (!trap_AAS_ValueForBSPEpairKey(ent, "model", model, sizeof(model))) continue;
5473 if (model[0] == '*') {
5474 modelnum = atoi(model+1);
5475 if (modelnum > max_bspmodelindex)
5476 max_bspmodelindex = modelnum;
5477 }
5478 }
5479 //initialize the waypoint heap
5480 BotInitWaypoints();
5481 }
5482
5483 /*
5484 ==================
5485 BotShutdownDeathmatchAI
5486 ==================
5487 */
5488 void BotShutdownDeathmatchAI(void) {
5489 altroutegoals_setup = qfalse;
5490 }