Debian Codegraph @

code/game/ai_cmd.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_cmd.c
26 *
27 * desc: Quake3 bot AI
28 *
29 * $Archive: /MissionPack/code/game/ai_cmd.c $
30 *
31 *****************************************************************************/
32
33 #include "g_local.h"
34 #include "../botlib/botlib.h"
35 #include "../botlib/be_aas.h"
36 #include "../botlib/be_ea.h"
37 #include "../botlib/be_ai_char.h"
38 #include "../botlib/be_ai_chat.h"
39 #include "../botlib/be_ai_gen.h"
40 #include "../botlib/be_ai_goal.h"
41 #include "../botlib/be_ai_move.h"
42 #include "../botlib/be_ai_weap.h"
43 //
44 #include "ai_main.h"
45 #include "ai_dmq3.h"
46 #include "ai_chat.h"
47 #include "ai_cmd.h"
48 #include "ai_dmnet.h"
49 #include "ai_team.h"
50 //
51 #include "chars.h" //characteristics
52 #include "inv.h" //indexes into the inventory
53 #include "syn.h" //synonyms
54 #include "match.h" //string matching types and vars
55
56 // for the voice chats
57 #include "../../ui/menudef.h"
58
59 int notleader[MAX_CLIENTS];
60
61 #ifdef DEBUG
62 /*
63 ==================
64 BotPrintTeamGoal
65 ==================
66 */
67 void BotPrintTeamGoal(bot_state_t *bs) {
68 char netname[MAX_NETNAME];
69 float t;
70
71 ClientName(bs->client, netname, sizeof(netname));
72 t = bs->teamgoal_time - FloatTime();
73 switch(bs->ltgtype) {
74 case LTG_TEAMHELP:
75 {
76 BotAI_Print(PRT_MESSAGE, "%s: I'm gonna help a team mate for %1.0f secs\n", netname, t);
77 break;
78 }
79 case LTG_TEAMACCOMPANY:
80 {
81 BotAI_Print(PRT_MESSAGE, "%s: I'm gonna accompany a team mate for %1.0f secs\n", netname, t);
82 break;
83 }
84 case LTG_GETFLAG:
85 {
86 BotAI_Print(PRT_MESSAGE, "%s: I'm gonna get the flag for %1.0f secs\n", netname, t);
87 break;
88 }
89 case LTG_RUSHBASE:
90 {
91 BotAI_Print(PRT_MESSAGE, "%s: I'm gonna rush to the base for %1.0f secs\n", netname, t);
92 break;
93 }
94 case LTG_RETURNFLAG:
95 {
96 BotAI_Print(PRT_MESSAGE, "%s: I'm gonna try to return the flag for %1.0f secs\n", netname, t);
97 break;
98 }
99 #ifdef MISSIONPACK
100 case LTG_ATTACKENEMYBASE:
101 {
102 BotAI_Print(PRT_MESSAGE, "%s: I'm gonna attack the enemy base for %1.0f secs\n", netname, t);
103 break;
104 }
105 case LTG_HARVEST:
106 {
107 BotAI_Print(PRT_MESSAGE, "%s: I'm gonna harvest for %1.0f secs\n", netname, t);
108 break;
109 }
110 #endif
111 case LTG_DEFENDKEYAREA:
112 {
113 BotAI_Print(PRT_MESSAGE, "%s: I'm gonna defend a key area for %1.0f secs\n", netname, t);
114 break;
115 }
116 case LTG_GETITEM:
117 {
118 BotAI_Print(PRT_MESSAGE, "%s: I'm gonna get an item for %1.0f secs\n", netname, t);
119 break;
120 }
121 case LTG_KILL:
122 {
123 BotAI_Print(PRT_MESSAGE, "%s: I'm gonna kill someone for %1.0f secs\n", netname, t);
124 break;
125 }
126 case LTG_CAMP:
127 case LTG_CAMPORDER:
128 {
129 BotAI_Print(PRT_MESSAGE, "%s: I'm gonna camp for %1.0f secs\n", netname, t);
130 break;
131 }
132 case LTG_PATROL:
133 {
134 BotAI_Print(PRT_MESSAGE, "%s: I'm gonna patrol for %1.0f secs\n", netname, t);
135 break;
136 }
137 default:
138 {
139 if (bs->ctfroam_time > FloatTime()) {
140 t = bs->ctfroam_time - FloatTime();
141 BotAI_Print(PRT_MESSAGE, "%s: I'm gonna roam for %1.0f secs\n", netname, t);
142 }
143 else {
144 BotAI_Print(PRT_MESSAGE, "%s: I've got a regular goal\n", netname);
145 }
146 }
147 }
148 }
149 #endif //DEBUG
150
151 /*
152 ==================
153 BotGetItemTeamGoal
154
155 FIXME: add stuff like "upper rocket launcher"
156 "the rl near the railgun", "lower grenade launcher" etc.
157 ==================
158 */
159 int BotGetItemTeamGoal(char *goalname, bot_goal_t *goal) {
160 int i;
161
162 if (!strlen(goalname)) return qfalse;
163 i = -1;
164 do {
165 i = trap_BotGetLevelItemGoal(i, goalname, goal);
166 if (i > 0) {
167 //do NOT defend dropped items
168 if (goal->flags & GFL_DROPPED)
169 continue;
170 return qtrue;
171 }
172 } while(i > 0);
173 return qfalse;
174 }
175
176 /*
177 ==================
178 BotGetMessageTeamGoal
179 ==================
180 */
181 int BotGetMessageTeamGoal(bot_state_t *bs, char *goalname, bot_goal_t *goal) {
182 bot_waypoint_t *cp;
183
184 if (BotGetItemTeamGoal(goalname, goal)) return qtrue;
185
186 cp = BotFindWayPoint(bs->checkpoints, goalname);
187 if (cp) {
188 memcpy(goal, &cp->goal, sizeof(bot_goal_t));
189 return qtrue;
190 }
191 return qfalse;
192 }
193
194 /*
195 ==================
196 BotGetTime
197 ==================
198 */
199 float BotGetTime(bot_match_t *match) {
200 bot_match_t timematch;
201 char timestring[MAX_MESSAGE_SIZE];
202 float t;
203
204 //if the matched string has a time
205 if (match->subtype & ST_TIME) {
206 //get the time string
207 trap_BotMatchVariable(match, TIME, timestring, MAX_MESSAGE_SIZE);
208 //match it to find out if the time is in seconds or minutes
209 if (trap_BotFindMatch(timestring, &timematch, MTCONTEXT_TIME)) {
210 if (timematch.type == MSG_FOREVER) {
211 t = 99999999.0f;
212 }
213 else if (timematch.type == MSG_FORAWHILE) {
214 t = 10 * 60; // 10 minutes
215 }
216 else if (timematch.type == MSG_FORALONGTIME) {
217 t = 30 * 60; // 30 minutes
218 }
219 else {
220 trap_BotMatchVariable(&timematch, TIME, timestring, MAX_MESSAGE_SIZE);
221 if (timematch.type == MSG_MINUTES) t = atof(timestring) * 60;
222 else if (timematch.type == MSG_SECONDS) t = atof(timestring);
223 else t = 0;
224 }
225 //if there's a valid time
226 if (t > 0) return FloatTime() + t;
227 }
228 }
229 return 0;
230 }
231
232 /*
233 ==================
234 FindClientByName
235 ==================
236 */
237 int FindClientByName(char *name) {
238 int i;
239 char buf[MAX_INFO_STRING];
240
241 for (i = 0; i < level.maxclients; i++) {
242 ClientName(i, buf, sizeof(buf));
243 if (!Q_stricmp(buf, name)) return i;
244 }
245 for (i = 0; i < level.maxclients; i++) {
246 ClientName(i, buf, sizeof(buf));
247 if (stristr(buf, name)) return i;
248 }
249 return -1;
250 }
251
252 /*
253 ==================
254 FindEnemyByName
255 ==================
256 */
257 int FindEnemyByName(bot_state_t *bs, char *name) {
258 int i;
259 char buf[MAX_INFO_STRING];
260
261 for (i = 0; i < level.maxclients; i++) {
262 if (BotSameTeam(bs, i)) continue;
263 ClientName(i, buf, sizeof(buf));
264 if (!Q_stricmp(buf, name)) return i;
265 }
266 for (i = 0; i < level.maxclients; i++) {
267 if (BotSameTeam(bs, i)) continue;
268 ClientName(i, buf, sizeof(buf));
269 if (stristr(buf, name)) return i;
270 }
271 return -1;
272 }
273
274 /*
275 ==================
276 NumPlayersOnSameTeam
277 ==================
278 */
279 int NumPlayersOnSameTeam(bot_state_t *bs) {
280 int i, num;
281 char buf[MAX_INFO_STRING];
282
283 num = 0;
284 for (i = 0; i < level.maxclients; i++) {
285 trap_GetConfigstring(CS_PLAYERS+i, buf, MAX_INFO_STRING);
286 if (strlen(buf)) {
287 if (BotSameTeam(bs, i+1)) num++;
288 }
289 }
290 return num;
291 }
292
293 /*
294 ==================
295 TeamPlayIsOn
296 ==================
297 */
298 int BotGetPatrolWaypoints(bot_state_t *bs, bot_match_t *match) {
299 char keyarea[MAX_MESSAGE_SIZE];
300 int patrolflags;
301 bot_waypoint_t *wp, *newwp, *newpatrolpoints;
302 bot_match_t keyareamatch;
303 bot_goal_t goal;
304
305 newpatrolpoints = NULL;
306 patrolflags = 0;
307 //
308 trap_BotMatchVariable(match, KEYAREA, keyarea, MAX_MESSAGE_SIZE);
309 //
310 while(1) {
311 if (!trap_BotFindMatch(keyarea, &keyareamatch, MTCONTEXT_PATROLKEYAREA)) {
312 trap_EA_SayTeam(bs->client, "what do you say?");
313 BotFreeWaypoints(newpatrolpoints);
314 bs->patrolpoints = NULL;
315 return qfalse;
316 }
317 trap_BotMatchVariable(&keyareamatch, KEYAREA, keyarea, MAX_MESSAGE_SIZE);
318 if (!BotGetMessageTeamGoal(bs, keyarea, &goal)) {
319 //BotAI_BotInitialChat(bs, "cannotfind", keyarea, NULL);
320 //trap_BotEnterChat(bs->cs, 0, CHAT_TEAM);
321 BotFreeWaypoints(newpatrolpoints);
322 bs->patrolpoints = NULL;
323 return qfalse;
324 }
325 //create a new waypoint
326 newwp = BotCreateWayPoint(keyarea, goal.origin, goal.areanum);
327 if (!newwp)
328 break;
329 //add the waypoint to the patrol points
330 newwp->next = NULL;
331 for (wp = newpatrolpoints; wp && wp->next; wp = wp->next);
332 if (!wp) {
333 newpatrolpoints = newwp;
334 newwp->prev = NULL;
335 }
336 else {
337 wp->next = newwp;
338 newwp->prev = wp;
339 }
340 //
341 if (keyareamatch.subtype & ST_BACK) {
342 patrolflags = PATROL_LOOP;
343 break;
344 }
345 else if (keyareamatch.subtype & ST_REVERSE) {
346 patrolflags = PATROL_REVERSE;
347 break;
348 }
349 else if (keyareamatch.subtype & ST_MORE) {
350 trap_BotMatchVariable(&keyareamatch, MORE, keyarea, MAX_MESSAGE_SIZE);
351 }
352 else {
353 break;
354 }
355 }
356 //
357 if (!newpatrolpoints || !newpatrolpoints->next) {
358 trap_EA_SayTeam(bs->client, "I need more key points to patrol\n");
359 BotFreeWaypoints(newpatrolpoints);
360 newpatrolpoints = NULL;
361 return qfalse;
362 }
363 //
364 BotFreeWaypoints(bs->patrolpoints);
365 bs->patrolpoints = newpatrolpoints;
366 //
367 bs->curpatrolpoint = bs->patrolpoints;
368 bs->patrolflags = patrolflags;
369 //
370 return qtrue;
371 }
372
373 /*
374 ==================
375 BotAddressedToBot
376 ==================
377 */
378 int BotAddressedToBot(bot_state_t *bs, bot_match_t *match) {
379 char addressedto[MAX_MESSAGE_SIZE];
380 char netname[MAX_MESSAGE_SIZE];
381 char name[MAX_MESSAGE_SIZE];
382 char botname[128];
383 int client;
384 bot_match_t addresseematch;
385
386 trap_BotMatchVariable(match, NETNAME, netname, sizeof(netname));
387 client = ClientOnSameTeamFromName(bs, netname);
388 if (client < 0) return qfalse;
389 //if the message is addressed to someone
390 if (match->subtype & ST_ADDRESSED) {
391 trap_BotMatchVariable(match, ADDRESSEE, addressedto, sizeof(addressedto));
392 //the name of this bot
393 ClientName(bs->client, botname, 128);
394 //
395 while(trap_BotFindMatch(addressedto, &addresseematch, MTCONTEXT_ADDRESSEE)) {
396 if (addresseematch.type == MSG_EVERYONE) {
397 return qtrue;
398 }
399 else if (addresseematch.type == MSG_MULTIPLENAMES) {
400 trap_BotMatchVariable(&addresseematch, TEAMMATE, name, sizeof(name));
401 if (strlen(name)) {
402 if (stristr(botname, name)) return qtrue;
403 if (stristr(bs->subteam, name)) return qtrue;
404 }
405 trap_BotMatchVariable(&addresseematch, MORE, addressedto, MAX_MESSAGE_SIZE);
406 }
407 else {
408 trap_BotMatchVariable(&addresseematch, TEAMMATE, name, MAX_MESSAGE_SIZE);
409 if (strlen(name)) {
410 if (stristr(botname, name)) return qtrue;
411 if (stristr(bs->subteam, name)) return qtrue;
412 }
413 break;
414 }
415 }
416 //Com_sprintf(buf, sizeof(buf), "not addressed to me but %s", addressedto);
417 //trap_EA_Say(bs->client, buf);
418 return qfalse;
419 }
420 else {
421 bot_match_t tellmatch;
422
423 tellmatch.type = 0;
424 //if this message wasn't directed solely to this bot
425 if (!trap_BotFindMatch(match->string, &tellmatch, MTCONTEXT_REPLYCHAT) ||
426 tellmatch.type != MSG_CHATTELL) {
427 //make sure not everyone reacts to this message
428 if (random() > (float ) 1.0 / (NumPlayersOnSameTeam(bs)-1)) return qfalse;
429 }
430 }
431 return qtrue;
432 }
433
434 /*
435 ==================
436 BotGPSToPosition
437 ==================
438 */
439 int BotGPSToPosition(char *buf, vec3_t position) {
440 int i, j = 0;
441 int num, sign;
442
443 for (i = 0; i < 3; i++) {
444 num = 0;
445 while(buf[j] == ' ') j++;
446 if (buf[j] == '-') {
447 j++;
448 sign = -1;
449 }
450 else {
451 sign = 1;
452 }
453 while (buf[j]) {
454 if (buf[j] >= '0' && buf[j] <= '9') {
455 num = num * 10 + buf[j] - '0';
456 j++;
457 }
458 else {
459 j++;
460 break;
461 }
462 }
463 BotAI_Print(PRT_MESSAGE, "%d\n", sign * num);
464 position[i] = (float) sign * num;
465 }
466 return qtrue;
467 }
468
469 /*
470 ==================
471 BotMatch_HelpAccompany
472 ==================
473 */
474 void BotMatch_HelpAccompany(bot_state_t *bs, bot_match_t *match) {
475 int client, other, areanum;
476 char teammate[MAX_MESSAGE_SIZE];
477 char netname[MAX_MESSAGE_SIZE];
478 char itemname[MAX_MESSAGE_SIZE];
479 bot_match_t teammatematch;
480 aas_entityinfo_t entinfo;
481
482 if (!TeamPlayIsOn()) return;
483 //if not addressed to this bot
484 if (!BotAddressedToBot(bs, match)) return;
485 //get the team mate name
486 trap_BotMatchVariable(match, TEAMMATE, teammate, sizeof(teammate));
487 //get the client to help
488 if (trap_BotFindMatch(teammate, &teammatematch, MTCONTEXT_TEAMMATE) &&
489 //if someone asks for him or herself
490 teammatematch.type == MSG_ME) {
491 //get the netname
492 trap_BotMatchVariable(match, NETNAME, netname, sizeof(netname));
493 client = ClientFromName(netname);
494 other = qfalse;
495 }
496 else {
497 //asked for someone else
498 client = FindClientByName(teammate);
499 //if this is the bot self
500 if (client == bs->client) {
501 other = qfalse;
502 }
503 else if (!BotSameTeam(bs, client)) {
504 //FIXME: say "I don't help the enemy"
505 return;
506 }
507 else {
508 other = qtrue;
509 }
510 }
511 //if the bot doesn't know who to help (FindClientByName returned -1)
512 if (client < 0) {
513 if (other) BotAI_BotInitialChat(bs, "whois", teammate, NULL);
514 else BotAI_BotInitialChat(bs, "whois", netname, NULL);
515 client = ClientFromName(netname);
516 trap_BotEnterChat(bs->cs, client, CHAT_TELL);
517 return;
518 }
519 //don't help or accompany yourself
520 if (client == bs->client) {
521 return;
522 }
523 //
524 bs->teamgoal.entitynum = -1;
525 BotEntityInfo(client, &entinfo);
526 //if info is valid (in PVS)
527 if (entinfo.valid) {
528 areanum = BotPointAreaNum(entinfo.origin);
529 if (areanum) {// && trap_AAS_AreaReachability(areanum)) {
530 bs->teamgoal.entitynum = client;
531 bs->teamgoal.areanum = areanum;
532 VectorCopy(entinfo.origin, bs->teamgoal.origin);
533 VectorSet(bs->teamgoal.mins, -8, -8, -8);
534 VectorSet(bs->teamgoal.maxs, 8, 8, 8);
535 }
536 }
537 //if no teamgoal yet
538 if (bs->teamgoal.entitynum < 0) {
539 //if near an item
540 if (match->subtype & ST_NEARITEM) {
541 //get the match variable
542 trap_BotMatchVariable(match, ITEM, itemname, sizeof(itemname));
543 //
544 if (!BotGetMessageTeamGoal(bs, itemname, &bs->teamgoal)) {
545 //BotAI_BotInitialChat(bs, "cannotfind", itemname, NULL);
546 //trap_BotEnterChat(bs->cs, bs->client, CHAT_TEAM);
547 return;
548 }
549 }
550 }
551 //
552 if (bs->teamgoal.entitynum < 0) {
553 if (other) BotAI_BotInitialChat(bs, "whereis", teammate, NULL);
554 else BotAI_BotInitialChat(bs, "whereareyou", netname, NULL);
555 client = ClientFromName(netname);
556 trap_BotEnterChat(bs->cs, client, CHAT_TEAM);
557 return;
558 }
559 //the team mate
560 bs->teammate = client;
561 //
562 trap_BotMatchVariable(match, NETNAME, netname, sizeof(netname));
563 //
564 client = ClientFromName(netname);
565 //the team mate who ordered
566 bs->decisionmaker = client;
567 bs->ordered = qtrue;
568 bs->order_time = FloatTime();
569 //last time the team mate was assumed visible
570 bs->teammatevisible_time = FloatTime();
571 //set the time to send a message to the team mates
572 bs->teammessage_time = FloatTime() + 2 * random();
573 //get the team goal time
574 bs->teamgoal_time = BotGetTime(match);
575 //set the ltg type
576 if (match->type == MSG_HELP) {
577 bs->ltgtype = LTG_TEAMHELP;
578 if (!bs->teamgoal_time) bs->teamgoal_time = FloatTime() + TEAM_HELP_TIME;
579 }
580 else {
581 bs->ltgtype = LTG_TEAMACCOMPANY;
582 if (!bs->teamgoal_time) bs->teamgoal_time = FloatTime() + TEAM_ACCOMPANY_TIME;
583 bs->formation_dist = 3.5 * 32; //3.5 meter
584 bs->arrive_time = 0;
585 //
586 BotSetTeamStatus(bs);
587 // remember last ordered task
588 BotRememberLastOrderedTask(bs);
589 }
590 #ifdef DEBUG
591 BotPrintTeamGoal(bs);
592 #endif //DEBUG
593 }
594
595 /*
596 ==================
597 BotMatch_DefendKeyArea
598 ==================
599 */
600 void BotMatch_DefendKeyArea(bot_state_t *bs, bot_match_t *match) {
601 char itemname[MAX_MESSAGE_SIZE];
602 char netname[MAX_MESSAGE_SIZE];
603 int client;
604
605 if (!TeamPlayIsOn()) return;
606 //if not addressed to this bot
607 if (!BotAddressedToBot(bs, match)) return;
608 //get the match variable
609 trap_BotMatchVariable(match, KEYAREA, itemname, sizeof(itemname));
610 //
611 if (!BotGetMessageTeamGoal(bs, itemname, &bs->teamgoal)) {
612 //BotAI_BotInitialChat(bs, "cannotfind", itemname, NULL);
613 //trap_BotEnterChat(bs->cs, bs->client, CHAT_TEAM);
614 return;
615 }
616 //
617 trap_BotMatchVariable(match, NETNAME, netname, sizeof(netname));
618 //
619 client = ClientFromName(netname);
620 //the team mate who ordered
621 bs->decisionmaker = client;
622 bs->ordered = qtrue;
623 bs->order_time = FloatTime();
624 //set the time to send a message to the team mates
625 bs->teammessage_time = FloatTime() + 2 * random();
626 //set the ltg type
627 bs->ltgtype = LTG_DEFENDKEYAREA;
628 //get the team goal time
629 bs->teamgoal_time = BotGetTime(match);
630 //set the team goal time
631 if (!bs->teamgoal_time) bs->teamgoal_time = FloatTime() + TEAM_DEFENDKEYAREA_TIME;
632 //away from defending
633 bs->defendaway_time = 0;
634 //
635 BotSetTeamStatus(bs);
636 // remember last ordered task
637 BotRememberLastOrderedTask(bs);
638 #ifdef DEBUG
639 BotPrintTeamGoal(bs);
640 #endif //DEBUG
641 }
642
643 /*
644 ==================
645 BotMatch_GetItem
646 ==================
647 */
648 void BotMatch_GetItem(bot_state_t *bs, bot_match_t *match) {
649 char itemname[MAX_MESSAGE_SIZE];
650 char netname[MAX_MESSAGE_SIZE];
651 int client;
652
653 if (!TeamPlayIsOn()) return;
654 //if not addressed to this bot
655 if (!BotAddressedToBot(bs, match)) return;
656 //get the match variable
657 trap_BotMatchVariable(match, ITEM, itemname, sizeof(itemname));
658 //
659 if (!BotGetMessageTeamGoal(bs, itemname, &bs->teamgoal)) {
660 //BotAI_BotInitialChat(bs, "cannotfind", itemname, NULL);
661 //trap_BotEnterChat(bs->cs, bs->client, CHAT_TEAM);
662 return;
663 }
664 trap_BotMatchVariable(match, NETNAME, netname, sizeof(netname));
665 client = ClientOnSameTeamFromName(bs, netname);
666 //
667 bs->decisionmaker = client;
668 bs->ordered = qtrue;
669 bs->order_time = FloatTime();
670 //set the time to send a message to the team mates
671 bs->teammessage_time = FloatTime() + 2 * random();
672 //set the ltg type
673 bs->ltgtype = LTG_GETITEM;
674 //set the team goal time
675 bs->teamgoal_time = FloatTime() + TEAM_GETITEM_TIME;
676 //
677 BotSetTeamStatus(bs);
678 #ifdef DEBUG
679 BotPrintTeamGoal(bs);
680 #endif //DEBUG
681 }
682
683 /*
684 ==================
685 BotMatch_Camp
686 ==================
687 */
688 void BotMatch_Camp(bot_state_t *bs, bot_match_t *match) {
689 int client, areanum;
690 char netname[MAX_MESSAGE_SIZE];
691 char itemname[MAX_MESSAGE_SIZE];
692 aas_entityinfo_t entinfo;
693
694 if (!TeamPlayIsOn()) return;
695 //if not addressed to this bot
696 if (!BotAddressedToBot(bs, match)) return;
697 //
698 trap_BotMatchVariable(match, NETNAME, netname, sizeof(netname));
699 //asked for someone else
700 client = FindClientByName(netname);
701 //if there's no valid client with this name
702 if (client < 0) {
703 BotAI_BotInitialChat(bs, "whois", netname, NULL);
704 trap_BotEnterChat(bs->cs, bs->client, CHAT_TEAM);
705 return;
706 }
707 //get the match variable
708 trap_BotMatchVariable(match, KEYAREA, itemname, sizeof(itemname));
709 //in CTF it could be the base
710 if (match->subtype & ST_THERE) {
711 //camp at the spot the bot is currently standing
712 bs->teamgoal.entitynum = bs->entitynum;
713 bs->teamgoal.areanum = bs->areanum;
714 VectorCopy(bs->origin, bs->teamgoal.origin);
715 VectorSet(bs->teamgoal.mins, -8, -8, -8);
716 VectorSet(bs->teamgoal.maxs, 8, 8, 8);
717 }
718 else if (match->subtype & ST_HERE) {
719 //if this is the bot self
720 if (client == bs->client) return;
721 //
722 bs->teamgoal.entitynum = -1;
723 BotEntityInfo(client, &entinfo);
724 //if info is valid (in PVS)
725 if (entinfo.valid) {
726 areanum = BotPointAreaNum(entinfo.origin);
727 if (areanum) {// && trap_AAS_AreaReachability(areanum)) {
728 //NOTE: just assume the bot knows where the person is
729 //if (BotEntityVisible(bs->entitynum, bs->eye, bs->viewangles, 360, client)) {
730 bs->teamgoal.entitynum = client;
731 bs->teamgoal.areanum = areanum;
732 VectorCopy(entinfo.origin, bs->teamgoal.origin);
733 VectorSet(bs->teamgoal.mins, -8, -8, -8);
734 VectorSet(bs->teamgoal.maxs, 8, 8, 8);
735 //}
736 }
737 }
738 //if the other is not visible
739 if (bs->teamgoal.entitynum < 0) {
740 BotAI_BotInitialChat(bs, "whereareyou", netname, NULL);
741 client = ClientFromName(netname);
742 trap_BotEnterChat(bs->cs, client, CHAT_TELL);
743 return;
744 }
745 }
746 else if (!BotGetMessageTeamGoal(bs, itemname, &bs->teamgoal)) {
747 //BotAI_BotInitialChat(bs, "cannotfind", itemname, NULL);
748 //client = ClientFromName(netname);
749 //trap_BotEnterChat(bs->cs, client, CHAT_TELL);
750 return;
751 }
752 //
753 bs->decisionmaker = client;
754 bs->ordered = qtrue;
755 bs->order_time = FloatTime();
756 //set the time to send a message to the team mates
757 bs->teammessage_time = FloatTime() + 2 * random();
758 //set the ltg type
759 bs->ltgtype = LTG_CAMPORDER;
760 //get the team goal time
761 bs->teamgoal_time = BotGetTime(match);
762 //set the team goal time
763 if (!bs->teamgoal_time) bs->teamgoal_time = FloatTime() + TEAM_CAMP_TIME;
764 //not arrived yet
765 bs->arrive_time = 0;
766 //
767 BotSetTeamStatus(bs);
768 // remember last ordered task
769 BotRememberLastOrderedTask(bs);
770 #ifdef DEBUG
771 BotPrintTeamGoal(bs);
772 #endif //DEBUG
773 }
774
775 /*
776 ==================
777 BotMatch_Patrol
778 ==================
779 */
780 void BotMatch_Patrol(bot_state_t *bs, bot_match_t *match) {
781 char netname[MAX_MESSAGE_SIZE];
782 int client;
783
784 if (!TeamPlayIsOn()) return;
785 //if not addressed to this bot
786 if (!BotAddressedToBot(bs, match)) return;
787 //get the patrol waypoints
788 if (!BotGetPatrolWaypoints(bs, match)) return;
789 //
790 trap_BotMatchVariable(match, NETNAME, netname, sizeof(netname));
791 //
792 client = FindClientByName(netname);
793 //
794 bs->decisionmaker = client;
795 bs->ordered = qtrue;
796 bs->order_time = FloatTime();
797 //set the time to send a message to the team mates
798 bs->teammessage_time = FloatTime() + 2 * random();
799 //set the ltg type
800 bs->ltgtype = LTG_PATROL;
801 //get the team goal time
802 bs->teamgoal_time = BotGetTime(match);
803 //set the team goal time if not set already
804 if (!bs->teamgoal_time) bs->teamgoal_time = FloatTime() + TEAM_PATROL_TIME;
805 //
806 BotSetTeamStatus(bs);
807 // remember last ordered task
808 BotRememberLastOrderedTask(bs);
809 #ifdef DEBUG
810 BotPrintTeamGoal(bs);
811 #endif //DEBUG
812 }
813
814 /*
815 ==================
816 BotMatch_GetFlag
817 ==================
818 */
819 void BotMatch_GetFlag(bot_state_t *bs, bot_match_t *match) {
820 char netname[MAX_MESSAGE_SIZE];
821 int client;
822
823 if (gametype == GT_CTF) {
824 if (!ctf_redflag.areanum || !ctf_blueflag.areanum)
825 return;
826 }
827 #ifdef MISSIONPACK
828 else if (gametype == GT_1FCTF) {
829 if (!ctf_neutralflag.areanum || !ctf_redflag.areanum || !ctf_blueflag.areanum)
830 return;
831 }
832 #endif
833 else {
834 return;
835 }
836 //if not addressed to this bot
837 if (!BotAddressedToBot(bs, match)) return;
838 //
839 trap_BotMatchVariable(match, NETNAME, netname, sizeof(netname));
840 //
841 client = FindClientByName(netname);
842 //
843 bs->decisionmaker = client;
844 bs->ordered = qtrue;
845 bs->order_time = FloatTime();
846 //set the time to send a message to the team mates
847 bs->teammessage_time = FloatTime() + 2 * random();
848 //set the ltg type
849 bs->ltgtype = LTG_GETFLAG;
850 //set the team goal time
851 bs->teamgoal_time = FloatTime() + CTF_GETFLAG_TIME;
852 // get an alternate route in ctf
853 if (gametype == GT_CTF) {
854 //get an alternative route goal towards the enemy base
855 BotGetAlternateRouteGoal(bs, BotOppositeTeam(bs));
856 }
857 //
858 BotSetTeamStatus(bs);
859 // remember last ordered task
860 BotRememberLastOrderedTask(bs);
861 #ifdef DEBUG
862 BotPrintTeamGoal(bs);
863 #endif //DEBUG
864 }
865
866 /*
867 ==================
868 BotMatch_AttackEnemyBase
869 ==================
870 */
871 void BotMatch_AttackEnemyBase(bot_state_t *bs, bot_match_t *match) {
872 char netname[MAX_MESSAGE_SIZE];
873 int client;
874
875 if (gametype == GT_CTF) {
876 BotMatch_GetFlag(bs, match);
877 }
878 #ifdef MISSIONPACK
879 else if (gametype == GT_1FCTF || gametype == GT_OBELISK || gametype == GT_HARVESTER) {
880 if (!redobelisk.areanum || !blueobelisk.areanum)
881 return;
882 }
883 #endif
884 else {
885 return;
886 }
887 //if not addressed to this bot
888 if (!BotAddressedToBot(bs, match)) return;
889 //
890 trap_BotMatchVariable(match, NETNAME, netname, sizeof(netname));
891 //
892 client = FindClientByName(netname);
893 //
894 bs->decisionmaker = client;
895 bs->ordered = qtrue;
896 bs->order_time = FloatTime();
897 //set the time to send a message to the team mates
898 bs->teammessage_time = FloatTime() + 2 * random();
899 //set the ltg type
900 bs->ltgtype = LTG_ATTACKENEMYBASE;
901 //set the team goal time
902 bs->teamgoal_time = FloatTime() + TEAM_ATTACKENEMYBASE_TIME;
903 bs->attackaway_time = 0;
904 //
905 BotSetTeamStatus(bs);
906 // remember last ordered task
907 BotRememberLastOrderedTask(bs);
908 #ifdef DEBUG
909 BotPrintTeamGoal(bs);
910 #endif //DEBUG
911 }
912
913 #ifdef MISSIONPACK
914 /*
915 ==================
916 BotMatch_Harvest
917 ==================
918 */
919 void BotMatch_Harvest(bot_state_t *bs, bot_match_t *match) {
920 char netname[MAX_MESSAGE_SIZE];
921 int client;
922
923 if (gametype == GT_HARVESTER) {
924 if (!neutralobelisk.areanum || !redobelisk.areanum || !blueobelisk.areanum)
925 return;
926 }
927 else {
928 return;
929 }
930 //if not addressed to this bot
931 if (!BotAddressedToBot(bs, match)) return;
932 //
933 trap_BotMatchVariable(match, NETNAME, netname, sizeof(netname));
934 //
935 client = FindClientByName(netname);
936 //
937 bs->decisionmaker = client;
938 bs->ordered = qtrue;
939 bs->order_time = FloatTime();
940 //set the time to send a message to the team mates
941 bs->teammessage_time = FloatTime() + 2 * random();
942 //set the ltg type
943 bs->ltgtype = LTG_HARVEST;
944 //set the team goal time
945 bs->teamgoal_time = FloatTime() + TEAM_HARVEST_TIME;
946 bs->harvestaway_time = 0;
947 //
948 BotSetTeamStatus(bs);
949 // remember last ordered task
950 BotRememberLastOrderedTask(bs);
951 #ifdef DEBUG
952 BotPrintTeamGoal(bs);
953 #endif //DEBUG
954 }
955 #endif
956
957 /*
958 ==================
959 BotMatch_RushBase
960 ==================
961 */
962 void BotMatch_RushBase(bot_state_t *bs, bot_match_t *match) {
963 char netname[MAX_MESSAGE_SIZE];
964 int client;
965
966 if (gametype == GT_CTF) {
967 if (!ctf_redflag.areanum || !ctf_blueflag.areanum)
968 return;
969 }
970 #ifdef MISSIONPACK
971 else if (gametype == GT_1FCTF || gametype == GT_HARVESTER) {
972 if (!redobelisk.areanum || !blueobelisk.areanum)
973 return;
974 }
975 #endif
976 else {
977 return;
978 }
979 //if not addressed to this bot
980 if (!BotAddressedToBot(bs, match)) return;
981 //
982 trap_BotMatchVariable(match, NETNAME, netname, sizeof(netname));
983 //
984 client = FindClientByName(netname);
985 //
986 bs->decisionmaker = client;
987 bs->ordered = qtrue;
988 bs->order_time = FloatTime();
989 //set the time to send a message to the team mates
990 bs->teammessage_time = FloatTime() + 2 * random();
991 //set the ltg type
992 bs->ltgtype = LTG_RUSHBASE;
993 //set the team goal time
994 bs->teamgoal_time = FloatTime() + CTF_RUSHBASE_TIME;
995 bs->rushbaseaway_time = 0;
996 //
997 BotSetTeamStatus(bs);
998 #ifdef DEBUG
999 BotPrintTeamGoal(bs);
1000 #endif //DEBUG
1001 }
1002
1003 /*
1004 ==================
1005 BotMatch_TaskPreference
1006 ==================
1007 */
1008 void BotMatch_TaskPreference(bot_state_t *bs, bot_match_t *match) {
1009 char netname[MAX_NETNAME];
1010 char teammatename[MAX_MESSAGE_SIZE];
1011 int teammate, preference;
1012
1013 ClientName(bs->client, netname, sizeof(netname));
1014 if (Q_stricmp(netname, bs->teamleader) != 0) return;
1015
1016 trap_BotMatchVariable(match, NETNAME, teammatename, sizeof(teammatename));
1017 teammate = ClientFromName(teammatename);
1018 if (teammate < 0) return;
1019
1020 preference = BotGetTeamMateTaskPreference(bs, teammate);
1021 switch(match->subtype)
1022 {
1023 case ST_DEFENDER:
1024 {
1025 preference &= ~TEAMTP_ATTACKER;
1026 preference |= TEAMTP_DEFENDER;
1027 break;
1028 }
1029 case ST_ATTACKER:
1030 {
1031 preference &= ~TEAMTP_DEFENDER;
1032 preference |= TEAMTP_ATTACKER;
1033 break;
1034 }
1035 case ST_ROAMER:
1036 {
1037 preference &= ~(TEAMTP_ATTACKER|TEAMTP_DEFENDER);
1038 break;
1039 }
1040 }
1041 BotSetTeamMateTaskPreference(bs, teammate, preference);
1042 //
1043 EasyClientName(teammate, teammatename, sizeof(teammatename));
1044 BotAI_BotInitialChat(bs, "keepinmind", teammatename, NULL);
1045 trap_BotEnterChat(bs->cs, teammate, CHAT_TELL);
1046 BotVoiceChatOnly(bs, teammate, VOICECHAT_YES);
1047 trap_EA_Action(bs->client, ACTION_AFFIRMATIVE);
1048 }
1049
1050 /*
1051 ==================
1052 BotMatch_ReturnFlag
1053 ==================
1054 */
1055 void BotMatch_ReturnFlag(bot_state_t *bs, bot_match_t *match) {
1056 char netname[MAX_MESSAGE_SIZE];
1057 int client;
1058
1059 //if not in CTF mode
1060 if (
1061 gametype != GT_CTF
1062 #ifdef MISSIONPACK
1063 && gametype != GT_1FCTF
1064 #endif
1065 )
1066 return;
1067 //if not addressed to this bot
1068 if (!BotAddressedToBot(bs, match))
1069 return;
1070 //
1071 trap_BotMatchVariable(match, NETNAME, netname, sizeof(netname));
1072 //
1073 client = FindClientByName(netname);
1074 //
1075 bs->decisionmaker = client;
1076 bs->ordered = qtrue;
1077 bs->order_time = FloatTime();
1078 //set the time to send a message to the team mates
1079 bs->teammessage_time = FloatTime() + 2 * random();
1080 //set the ltg type
1081 bs->ltgtype = LTG_RETURNFLAG;
1082 //set the team goal time
1083 bs->teamgoal_time = FloatTime() + CTF_RETURNFLAG_TIME;
1084 bs->rushbaseaway_time = 0;
1085 //
1086 BotSetTeamStatus(bs);
1087 #ifdef DEBUG
1088 BotPrintTeamGoal(bs);
1089 #endif //DEBUG
1090 }
1091
1092 /*
1093 ==================
1094 BotMatch_JoinSubteam
1095 ==================
1096 */
1097 void BotMatch_JoinSubteam(bot_state_t *bs, bot_match_t *match) {
1098 char teammate[MAX_MESSAGE_SIZE];
1099 char netname[MAX_MESSAGE_SIZE];
1100 int client;
1101
1102 if (!TeamPlayIsOn()) return;
1103 //if not addressed to this bot
1104 if (!BotAddressedToBot(bs, match)) return;
1105 //get the sub team name
1106 trap_BotMatchVariable(match, TEAMNAME, teammate, sizeof(teammate));
1107 //set the sub team name
1108 Q_strncpyz(bs->subteam, teammate, sizeof(bs->subteam));
1109 //
1110 trap_BotMatchVariable(match, NETNAME, netname, sizeof(netname));
1111 BotAI_BotInitialChat(bs, "joinedteam", teammate, NULL);
1112 client = ClientFromName(netname);
1113 trap_BotEnterChat(bs->cs, client, CHAT_TELL);
1114 }
1115
1116 /*
1117 ==================
1118 BotMatch_LeaveSubteam
1119 ==================
1120 */
1121 void BotMatch_LeaveSubteam(bot_state_t *bs, bot_match_t *match) {
1122 char netname[MAX_MESSAGE_SIZE];
1123 int client;
1124
1125 if (!TeamPlayIsOn()) return;
1126 //if not addressed to this bot
1127 if (!BotAddressedToBot(bs, match)) return;
1128 //
1129 if (strlen(bs->subteam))
1130 {
1131 BotAI_BotInitialChat(bs, "leftteam", bs->subteam, NULL);
1132 trap_BotMatchVariable(match, NETNAME, netname, sizeof(netname));
1133 client = ClientFromName(netname);
1134 trap_BotEnterChat(bs->cs, client, CHAT_TELL);
1135 } //end if
1136 strcpy(bs->subteam, "");
1137 }
1138
1139 /*
1140 ==================
1141 BotMatch_LeaveSubteam
1142 ==================
1143 */
1144 void BotMatch_WhichTeam(bot_state_t *bs, bot_match_t *match) {
1145 if (!TeamPlayIsOn()) return;
1146 //if not addressed to this bot
1147 if (!BotAddressedToBot(bs, match)) return;
1148 //
1149 if (strlen(bs->subteam)) {
1150 BotAI_BotInitialChat(bs, "inteam", bs->subteam, NULL);
1151 }
1152 else {
1153 BotAI_BotInitialChat(bs, "noteam", NULL);
1154 }
1155 trap_BotEnterChat(bs->cs, bs->client, CHAT_TEAM);
1156 }
1157
1158 /*
1159 ==================
1160 BotMatch_CheckPoint
1161 ==================
1162 */
1163 void BotMatch_CheckPoint(bot_state_t *bs, bot_match_t *match) {
1164 int areanum, client;
1165 char buf[MAX_MESSAGE_SIZE];
1166 char netname[MAX_MESSAGE_SIZE];
1167 vec3_t position;
1168 bot_waypoint_t *cp;
1169
1170 if (!TeamPlayIsOn()) return;
1171 //
1172 trap_BotMatchVariable(match, POSITION, buf, MAX_MESSAGE_SIZE);
1173 VectorClear(position);
1174 //
1175 trap_BotMatchVariable(match, NETNAME, netname, sizeof(netname));
1176 client = ClientFromName(netname);
1177 //BotGPSToPosition(buf, position);
1178 sscanf(buf, "%f %f %f", &position[0], &position[1], &position[2]);
1179 position[2] += 0.5;
1180 areanum = BotPointAreaNum(position);
1181 if (!areanum) {
1182 if (BotAddressedToBot(bs, match)) {
1183 BotAI_BotInitialChat(bs, "checkpoint_invalid", NULL);
1184 trap_BotEnterChat(bs->cs, client, CHAT_TELL);
1185 }
1186 return;
1187 }
1188 //
1189 trap_BotMatchVariable(match, NAME, buf, MAX_MESSAGE_SIZE);
1190 //check if there already exists a checkpoint with this name
1191 cp = BotFindWayPoint(bs->checkpoints, buf);
1192 if (cp) {
1193 if (cp->next) cp->next->prev = cp->prev;
1194 if (cp->prev) cp->prev->next = cp->next;
1195 else bs->checkpoints = cp->next;
1196 cp->inuse = qfalse;
1197 }
1198 //create a new check point
1199 cp = BotCreateWayPoint(buf, position, areanum);
1200 //add the check point to the bot's known chech points
1201 cp->next = bs->checkpoints;
1202 if (bs->checkpoints) bs->checkpoints->prev = cp;
1203 bs->checkpoints = cp;
1204 //
1205 if (BotAddressedToBot(bs, match)) {
1206 Com_sprintf(buf, sizeof(buf), "%1.0f %1.0f %1.0f", cp->goal.origin[0],
1207 cp->goal.origin[1],
1208 cp->goal.origin[2]);
1209
1210 BotAI_BotInitialChat(bs, "checkpoint_confirm", cp->name, buf, NULL);
1211 trap_BotEnterChat(bs->cs, client, CHAT_TELL);
1212 }
1213 }
1214
1215 /*
1216 ==================
1217 BotMatch_FormationSpace
1218 ==================
1219 */
1220 void BotMatch_FormationSpace(bot_state_t *bs, bot_match_t *match) {
1221 char buf[MAX_MESSAGE_SIZE];
1222 float space;
1223
1224 if (!TeamPlayIsOn()) return;
1225 //if not addressed to this bot
1226 if (!BotAddressedToBot(bs, match)) return;
1227 //
1228 trap_BotMatchVariable(match, NUMBER, buf, MAX_MESSAGE_SIZE);
1229 //if it's the distance in feet
1230 if (match->subtype & ST_FEET) space = 0.3048 * 32 * atof(buf);
1231 //else it's in meters
1232 else space = 32 * atof(buf);
1233 //check if the formation intervening space is valid
1234 if (space < 48 || space > 500) space = 100;
1235 bs->formation_dist = space;
1236 }
1237
1238 /*
1239 ==================
1240 BotMatch_Dismiss
1241 ==================
1242 */
1243 void BotMatch_Dismiss(bot_state_t *bs, bot_match_t *match) {
1244 char netname[MAX_MESSAGE_SIZE];
1245 int client;
1246
1247 if (!TeamPlayIsOn()) return;
1248 //if not addressed to this bot
1249 if (!BotAddressedToBot(bs, match)) return;
1250 trap_BotMatchVariable(match, NETNAME, netname, sizeof(netname));
1251 client = ClientFromName(netname);
1252 //
1253 bs->decisionmaker = client;
1254 //
1255 bs->ltgtype = 0;
1256 bs->lead_time = 0;
1257 bs->lastgoal_ltgtype = 0;
1258 //
1259 BotAI_BotInitialChat(bs, "dismissed", NULL);
1260 trap_BotEnterChat(bs->cs, client, CHAT_TELL);
1261 }
1262
1263 /*
1264 ==================
1265 BotMatch_Suicide
1266 ==================
1267 */
1268 void BotMatch_Suicide(bot_state_t *bs, bot_match_t *match) {
1269 char netname[MAX_MESSAGE_SIZE];
1270 int client;
1271
1272 if (!TeamPlayIsOn()) return;
1273 //if not addressed to this bot
1274 if (!BotAddressedToBot(bs, match)) return;
1275 //
1276 trap_EA_Command(bs->client, "kill");
1277 //
1278 trap_BotMatchVariable(match, NETNAME, netname, sizeof(netname));
1279 client = ClientFromName(netname);
1280 //
1281 BotVoiceChat(bs, client, VOICECHAT_TAUNT);
1282 trap_EA_Action(bs->client, ACTION_AFFIRMATIVE);
1283 }
1284
1285 /*
1286 ==================
1287 BotMatch_StartTeamLeaderShip
1288 ==================
1289 */
1290 void BotMatch_StartTeamLeaderShip(bot_state_t *bs, bot_match_t *match) {
1291 int client;
1292 char teammate[MAX_MESSAGE_SIZE];
1293
1294 if (!TeamPlayIsOn()) return;
1295 //if chats for him or herself
1296 if (match->subtype & ST_I) {
1297 //get the team mate that will be the team leader
1298 trap_BotMatchVariable(match, NETNAME, teammate, sizeof(teammate));
1299 Q_strncpyz(bs->teamleader, teammate, sizeof(bs->teamleader));
1300 }
1301 //chats for someone else
1302 else {
1303 //get the team mate that will be the team leader
1304 trap_BotMatchVariable(match, TEAMMATE, teammate, sizeof(teammate));
1305 client = FindClientByName(teammate);
1306 if (client >= 0) ClientName(client, bs->teamleader, sizeof(bs->teamleader));
1307 }
1308 }
1309
1310 /*
1311 ==================
1312 BotMatch_StopTeamLeaderShip
1313 ==================
1314 */
1315 void BotMatch_StopTeamLeaderShip(bot_state_t *bs, bot_match_t *match) {
1316 int client;
1317 char teammate[MAX_MESSAGE_SIZE];
1318 char netname[MAX_MESSAGE_SIZE];
1319
1320 if (!TeamPlayIsOn()) return;
1321 //get the team mate that stops being the team leader
1322 trap_BotMatchVariable(match, TEAMMATE, teammate, sizeof(teammate));
1323 //if chats for him or herself
1324 if (match->subtype & ST_I) {
1325 trap_BotMatchVariable(match, NETNAME, netname, sizeof(netname));
1326 client = FindClientByName(netname);
1327 }
1328 //chats for someone else
1329 else {
1330 client = FindClientByName(teammate);
1331 } //end else
1332 if (client >= 0) {
1333 if (!Q_stricmp(bs->teamleader, ClientName(client, netname, sizeof(netname)))) {
1334 bs->teamleader[0] = '\0';
1335 notleader[client] = qtrue;
1336 }
1337 }
1338 }
1339
1340 /*
1341 ==================
1342 BotMatch_WhoIsTeamLeader
1343 ==================
1344 */
1345 void BotMatch_WhoIsTeamLeader(bot_state_t *bs, bot_match_t *match) {
1346 char netname[MAX_MESSAGE_SIZE];
1347
1348 if (!TeamPlayIsOn()) return;
1349
1350 ClientName(bs->client, netname, sizeof(netname));
1351 //if this bot IS the team leader
1352 if (!Q_stricmp(netname, bs->teamleader)) {
1353 trap_EA_SayTeam(bs->client, "I'm the team leader\n");
1354 }
1355 }
1356
1357 /*
1358 ==================
1359 BotMatch_WhatAreYouDoing
1360 ==================
1361 */
1362 void BotMatch_WhatAreYouDoing(bot_state_t *bs, bot_match_t *match) {
1363 char netname[MAX_MESSAGE_SIZE];
1364 char goalname[MAX_MESSAGE_SIZE];
1365 int client;
1366
1367 //if not addressed to this bot
1368 if (!BotAddressedToBot(bs, match)) return;
1369 //
1370 switch(bs->ltgtype) {
1371 case LTG_TEAMHELP:
1372 {
1373 EasyClientName(bs->teammate, netname, sizeof(netname));
1374 BotAI_BotInitialChat(bs, "helping", netname, NULL);
1375 break;
1376 }
1377 case LTG_TEAMACCOMPANY:
1378 {
1379 EasyClientName(bs->teammate, netname, sizeof(netname));
1380 BotAI_BotInitialChat(bs, "accompanying", netname, NULL);
1381 break;
1382 }
1383 case LTG_DEFENDKEYAREA:
1384 {
1385 trap_BotGoalName(bs->teamgoal.number, goalname, sizeof(goalname));
1386 BotAI_BotInitialChat(bs, "defending", goalname, NULL);
1387 break;
1388 }
1389 case LTG_GETITEM:
1390 {
1391 trap_BotGoalName(bs->teamgoal.number, goalname, sizeof(goalname));
1392 BotAI_BotInitialChat(bs, "gettingitem", goalname, NULL);
1393 break;
1394 }
1395 case LTG_KILL:
1396 {
1397 ClientName(bs->teamgoal.entitynum, netname, sizeof(netname));
1398 BotAI_BotInitialChat(bs, "killing", netname, NULL);
1399 break;
1400 }
1401 case LTG_CAMP:
1402 case LTG_CAMPORDER:
1403 {
1404 BotAI_BotInitialChat(bs, "camping", NULL);
1405 break;
1406 }
1407 case LTG_PATROL:
1408 {
1409 BotAI_BotInitialChat(bs, "patrolling", NULL);
1410 break;
1411 }
1412 case LTG_GETFLAG:
1413 {
1414 BotAI_BotInitialChat(bs, "capturingflag", NULL);
1415 break;
1416 }
1417 case LTG_RUSHBASE:
1418 {
1419 BotAI_BotInitialChat(bs, "rushingbase", NULL);
1420 break;
1421 }
1422 case LTG_RETURNFLAG:
1423 {
1424 BotAI_BotInitialChat(bs, "returningflag", NULL);
1425 break;
1426 }
1427 #ifdef MISSIONPACK
1428 case LTG_ATTACKENEMYBASE:
1429 {
1430 BotAI_BotInitialChat(bs, "attackingenemybase", NULL);
1431 break;
1432 }
1433 case LTG_HARVEST:
1434 {
1435 BotAI_BotInitialChat(bs, "harvesting", NULL);
1436 break;
1437 }
1438 #endif
1439 default:
1440 {
1441 BotAI_BotInitialChat(bs, "roaming", NULL);
1442 break;
1443 }
1444 }
1445 //chat what the bot is doing
1446 trap_BotMatchVariable(match, NETNAME, netname, sizeof(netname));
1447 client = ClientFromName(netname);
1448 trap_BotEnterChat(bs->cs, client, CHAT_TELL);
1449 }
1450
1451 /*
1452 ==================
1453 BotMatch_WhatIsMyCommand
1454 ==================
1455 */
1456 void BotMatch_WhatIsMyCommand(bot_state_t *bs, bot_match_t *match) {
1457 char netname[MAX_NETNAME];
1458
1459 ClientName(bs->client, netname, sizeof(netname));
1460 if (Q_stricmp(netname, bs->teamleader) != 0) return;
1461 bs->forceorders = qtrue;
1462 }
1463
1464 /*
1465 ==================
1466 BotNearestVisibleItem
1467 ==================
1468 */
1469 float BotNearestVisibleItem(bot_state_t *bs, char *itemname, bot_goal_t *goal) {
1470 int i;
1471 char name[64];
1472 bot_goal_t tmpgoal;
1473 float dist, bestdist;
1474 vec3_t dir;
1475 bsp_trace_t trace;
1476
1477 bestdist = 999999;
1478 i = -1;
1479 do {
1480 i = trap_BotGetLevelItemGoal(i, itemname, &tmpgoal);
1481 trap_BotGoalName(tmpgoal.number, name, sizeof(name));
1482 if (Q_stricmp(itemname, name) != 0)
1483 continue;
1484 VectorSubtract(tmpgoal.origin, bs->origin, dir);
1485 dist = VectorLength(dir);
1486 if (dist < bestdist) {
1487 //trace from start to end
1488 BotAI_Trace(&trace, bs->eye, NULL, NULL, tmpgoal.origin, bs->client, CONTENTS_SOLID|CONTENTS_PLAYERCLIP);
1489 if (trace.fraction >= 1.0) {
1490 bestdist = dist;
1491 memcpy(goal, &tmpgoal, sizeof(bot_goal_t));
1492 }
1493 }
1494 } while(i > 0);
1495 return bestdist;
1496 }
1497
1498 /*
1499 ==================
1500 BotMatch_WhereAreYou
1501 ==================
1502 */
1503 void BotMatch_WhereAreYou(bot_state_t *bs, bot_match_t *match) {
1504 float dist, bestdist;
1505 int i, bestitem, redtt, bluett, client;
1506 bot_goal_t goal;
1507 char netname[MAX_MESSAGE_SIZE];
1508 char *nearbyitems[] = {
1509 "Shotgun",
1510 "Grenade Launcher",
1511 "Rocket Launcher",
1512 "Plasmagun",
1513 "Railgun",
1514 "Lightning Gun",
1515 "BFG10K",
1516 "Quad Damage",
1517 "Regeneration",
1518 "Battle Suit",
1519 "Speed",
1520 "Invisibility",
1521 "Flight",
1522 "Armor",
1523 "Heavy Armor",
1524 "Red Flag",
1525 "Blue Flag",
1526 #ifdef MISSIONPACK
1527 "Nailgun",
1528 "Prox Launcher",
1529 "Chaingun",
1530 "Scout",
1531 "Guard",
1532 "Doubler",
1533 "Ammo Regen",
1534 "Neutral Flag",
1535 "Red Obelisk",
1536 "Blue Obelisk",
1537 "Neutral Obelisk",
1538 #endif
1539 NULL
1540 };
1541 //
1542 if (!TeamPlayIsOn())
1543 return;
1544 //if not addressed to this bot
1545 if (!BotAddressedToBot(bs, match))
1546 return;
1547
1548 bestitem = -1;
1549 bestdist = 999999;
1550 for (i = 0; nearbyitems[i]; i++) {
1551 dist = BotNearestVisibleItem(bs, nearbyitems[i], &goal);
1552 if (dist < bestdist) {
1553 bestdist = dist;
1554 bestitem = i;
1555 }
1556 }
1557 if (bestitem != -1) {
1558 if (gametype == GT_CTF
1559 #ifdef MISSIONPACK
1560 || gametype == GT_1FCTF
1561 #endif
1562 ) {
1563 redtt = trap_AAS_AreaTravelTimeToGoalArea(bs->areanum, bs->origin, ctf_redflag.areanum, TFL_DEFAULT);
1564 bluett = trap_AAS_AreaTravelTimeToGoalArea(bs->areanum, bs->origin, ctf_blueflag.areanum, TFL_DEFAULT);
1565 if (redtt < (redtt + bluett) * 0.4) {
1566 BotAI_BotInitialChat(bs, "teamlocation", nearbyitems[bestitem], "red", NULL);
1567 }
1568 else if (bluett < (redtt + bluett) * 0.4) {
1569 BotAI_BotInitialChat(bs, "teamlocation", nearbyitems[bestitem], "blue", NULL);
1570 }
1571 else {
1572 BotAI_BotInitialChat(bs, "location", nearbyitems[bestitem], NULL);
1573 }
1574 }
1575 #ifdef MISSIONPACK
1576 else if (gametype == GT_OBELISK || gametype == GT_HARVESTER) {
1577 redtt = trap_AAS_AreaTravelTimeToGoalArea(bs->areanum, bs->origin, redobelisk.areanum, TFL_DEFAULT);
1578 bluett = trap_AAS_AreaTravelTimeToGoalArea(bs->areanum, bs->origin, blueobelisk.areanum, TFL_DEFAULT);
1579 if (redtt < (redtt + bluett) * 0.4) {
1580 BotAI_BotInitialChat(bs, "teamlocation", nearbyitems[bestitem], "red", NULL);
1581 }
1582 else if (bluett < (redtt + bluett) * 0.4) {
1583 BotAI_BotInitialChat(bs, "teamlocation", nearbyitems[bestitem], "blue", NULL);
1584 }
1585 else {
1586 BotAI_BotInitialChat(bs, "location", nearbyitems[bestitem], NULL);
1587 }
1588 }
1589 #endif
1590 else {
1591 BotAI_BotInitialChat(bs, "location", nearbyitems[bestitem], NULL);
1592 }
1593 trap_BotMatchVariable(match, NETNAME, netname, sizeof(netname));
1594 client = ClientFromName(netname);
1595 trap_BotEnterChat(bs->cs, client, CHAT_TELL);
1596 }
1597 }
1598
1599 /*
1600 ==================
1601 BotMatch_LeadTheWay
1602 ==================
1603 */
1604 void BotMatch_LeadTheWay(bot_state_t *bs, bot_match_t *match) {
1605 aas_entityinfo_t entinfo;
1606 char netname[MAX_MESSAGE_SIZE], teammate[MAX_MESSAGE_SIZE];
1607 int client, areanum, other;
1608
1609 if (!TeamPlayIsOn()) return;
1610 //if not addressed to this bot
1611 if (!BotAddressedToBot(bs, match)) return;
1612 //if someone asks for someone else
1613 if (match->subtype & ST_SOMEONE) {
1614 //get the team mate name
1615 trap_BotMatchVariable(match, TEAMMATE, teammate, sizeof(teammate));
1616 client = FindClientByName(teammate);
1617 //if this is the bot self
1618 if (client == bs->client) {
1619 other = qfalse;
1620 }
1621 else if (!BotSameTeam(bs, client)) {
1622 //FIXME: say "I don't help the enemy"
1623 return;
1624 }
1625 else {
1626 other = qtrue;
1627 }
1628 }
1629 else {
1630 //get the netname
1631 trap_BotMatchVariable(match, NETNAME, netname, sizeof(netname));
1632 client = ClientFromName(netname);
1633 other = qfalse;
1634 }
1635 //if the bot doesn't know who to help (FindClientByName returned -1)
1636 if (client < 0) {
1637 BotAI_BotInitialChat(bs, "whois", netname, NULL);
1638 trap_BotEnterChat(bs->cs, bs->client, CHAT_TEAM);
1639 return;
1640 }
1641 //
1642 bs->lead_teamgoal.entitynum = -1;
1643 BotEntityInfo(client, &entinfo);
1644 //if info is valid (in PVS)
1645 if (entinfo.valid) {
1646 areanum = BotPointAreaNum(entinfo.origin);
1647 if (areanum) { // && trap_AAS_AreaReachability(areanum)) {
1648 bs->lead_teamgoal.entitynum = client;
1649 bs->lead_teamgoal.areanum = areanum;
1650 VectorCopy(entinfo.origin, bs->lead_teamgoal.origin);
1651 VectorSet(bs->lead_teamgoal.mins, -8, -8, -8);
1652 VectorSet(bs->lead_teamgoal.maxs, 8, 8, 8);
1653 }
1654 }
1655
1656 if (bs->teamgoal.entitynum < 0) {
1657 if (other) BotAI_BotInitialChat(bs, "whereis", teammate, NULL);
1658 else BotAI_BotInitialChat(bs, "whereareyou", netname, NULL);
1659 trap_BotEnterChat(bs->cs, bs->client, CHAT_TEAM);
1660 return;
1661 }
1662 bs->lead_teammate = client;
1663 bs->lead_time = FloatTime() + TEAM_LEAD_TIME;
1664 bs->leadvisible_time = 0;
1665 bs->leadmessage_time = -(FloatTime() + 2 * random());
1666 }
1667
1668 /*
1669 ==================
1670 BotMatch_Kill
1671 ==================
1672 */
1673 void BotMatch_Kill(bot_state_t *bs, bot_match_t *match) {
1674 char enemy[MAX_MESSAGE_SIZE];
1675 char netname[MAX_MESSAGE_SIZE];
1676 int client;
1677
1678 if (!TeamPlayIsOn()) return;
1679 //if not addressed to this bot
1680 if (!BotAddressedToBot(bs, match)) return;
1681
1682 trap_BotMatchVariable(match, ENEMY, enemy, sizeof(enemy));
1683 //
1684 client = FindEnemyByName(bs, enemy);
1685 if (client < 0) {
1686 BotAI_BotInitialChat(bs, "whois", enemy, NULL);
1687 trap_BotMatchVariable(match, NETNAME, netname, sizeof(netname));
1688 client = ClientFromName(netname);
1689 trap_BotEnterChat(bs->cs, client, CHAT_TELL);
1690 return;
1691 }
1692 bs->teamgoal.entitynum = client;
1693 //set the time to send a message to the team mates
1694 bs->teammessage_time = FloatTime() + 2 * random();
1695 //set the ltg type
1696 bs->ltgtype = LTG_KILL;
1697 //set the team goal time
1698 bs->teamgoal_time = FloatTime() + TEAM_KILL_SOMEONE;
1699 //
1700 BotSetTeamStatus(bs);
1701 #ifdef DEBUG
1702 BotPrintTeamGoal(bs);
1703 #endif //DEBUG
1704 }
1705
1706 /*
1707 ==================
1708 BotMatch_CTF
1709 ==================
1710 */
1711 void BotMatch_CTF(bot_state_t *bs, bot_match_t *match) {
1712
1713 char flag[128], netname[MAX_NETNAME];
1714
1715 if (gametype == GT_CTF) {
1716 trap_BotMatchVariable(match, FLAG, flag, sizeof(flag));
1717 if (match->subtype & ST_GOTFLAG) {
1718 if (!Q_stricmp(flag, "red")) {
1719 bs->redflagstatus = 1;
1720 if (BotTeam(bs) == TEAM_BLUE) {
1721 trap_BotMatchVariable(match, NETNAME, netname, sizeof(netname));
1722 bs->flagcarrier = ClientFromName(netname);
1723 }
1724 }
1725 else {
1726 bs->blueflagstatus = 1;
1727 if (BotTeam(bs) == TEAM_RED) {
1728 trap_BotMatchVariable(match, NETNAME, netname, sizeof(netname));
1729 bs->flagcarrier = ClientFromName(netname);
1730 }
1731 }
1732 bs->flagstatuschanged = 1;
1733 bs->lastflagcapture_time = FloatTime();
1734 }
1735 else if (match->subtype & ST_CAPTUREDFLAG) {
1736 bs->redflagstatus = 0;
1737 bs->blueflagstatus = 0;
1738 bs->flagcarrier = 0;
1739 bs->flagstatuschanged = 1;
1740 }
1741 else if (match->subtype & ST_RETURNEDFLAG) {
1742 if (!Q_stricmp(flag, "red")) bs->redflagstatus = 0;
1743 else bs->blueflagstatus = 0;
1744 bs->flagstatuschanged = 1;
1745 }
1746 }
1747 #ifdef MISSIONPACK
1748 else if (gametype == GT_1FCTF) {
1749 if (match->subtype & ST_1FCTFGOTFLAG) {
1750 trap_BotMatchVariable(match, NETNAME, netname, sizeof(netname));
1751 bs->flagcarrier = ClientFromName(netname);
1752 }
1753 }
1754 #endif
1755 }
1756
1757 void BotMatch_EnterGame(bot_state_t *bs, bot_match_t *match) {
1758 int client;
1759 char netname[MAX_NETNAME];
1760
1761 trap_BotMatchVariable(match, NETNAME, netname, sizeof(netname));
1762 client = FindClientByName(netname);
1763 if (client >= 0) {
1764 notleader[client] = qfalse;
1765 }
1766 //NOTE: eliza chats will catch this
1767 //Com_sprintf(buf, sizeof(buf), "heya %s", netname);
1768 //EA_Say(bs->client, buf);
1769 }
1770
1771 void BotMatch_NewLeader(bot_state_t *bs, bot_match_t *match) {
1772 int client;
1773 char netname[MAX_NETNAME];
1774
1775 trap_BotMatchVariable(match, NETNAME, netname, sizeof(netname));
1776 client = FindClientByName(netname);
1777 if (!BotSameTeam(bs, client))
1778 return;
1779 Q_strncpyz(bs->teamleader, netname, sizeof(bs->teamleader));
1780 }
1781
1782 /*
1783 ==================
1784 BotMatchMessage
1785 ==================
1786 */
1787 int BotMatchMessage(bot_state_t *bs, char *message) {
1788 bot_match_t match;
1789
1790 match.type = 0;
1791 //if it is an unknown message
1792 if (!trap_BotFindMatch(message, &match, MTCONTEXT_MISC
1793 |MTCONTEXT_INITIALTEAMCHAT
1794 |MTCONTEXT_CTF)) {
1795 return qfalse;
1796 }
1797 //react to the found message
1798 switch(match.type)
1799 {
1800 case MSG_HELP: //someone calling for help
1801 case MSG_ACCOMPANY: //someone calling for company
1802 {
1803 BotMatch_HelpAccompany(bs, &match);
1804 break;
1805 }
1806 case MSG_DEFENDKEYAREA: //teamplay defend a key area
1807 {
1808 BotMatch_DefendKeyArea(bs, &match);
1809 break;
1810 }
1811 case MSG_CAMP: //camp somewhere
1812 {
1813 BotMatch_Camp(bs, &match);
1814 break;
1815 }
1816 case MSG_PATROL: //patrol between several key areas
1817 {
1818 BotMatch_Patrol(bs, &match);
1819 break;
1820 }
1821 //CTF & 1FCTF
1822 case MSG_GETFLAG: //ctf get the enemy flag
1823 {
1824 BotMatch_GetFlag(bs, &match);
1825 break;
1826 }
1827 #ifdef MISSIONPACK
1828 //CTF & 1FCTF & Obelisk & Harvester
1829 case MSG_ATTACKENEMYBASE:
1830 {
1831 BotMatch_AttackEnemyBase(bs, &match);
1832 break;
1833 }
1834 //Harvester
1835 case MSG_HARVEST:
1836 {
1837 BotMatch_Harvest(bs, &match);
1838 break;
1839 }
1840 #endif
1841 //CTF & 1FCTF & Harvester
1842 case MSG_RUSHBASE: //ctf rush to the base
1843 {
1844 BotMatch_RushBase(bs, &match);
1845 break;
1846 }
1847 //CTF & 1FCTF
1848 case MSG_RETURNFLAG:
1849 {
1850 BotMatch_ReturnFlag(bs, &match);
1851 break;
1852 }
1853 //CTF & 1FCTF & Obelisk & Harvester
1854 case MSG_TASKPREFERENCE:
1855 {
1856 BotMatch_TaskPreference(bs, &match);
1857 break;
1858 }
1859 //CTF & 1FCTF
1860 case MSG_CTF:
1861 {
1862 BotMatch_CTF(bs, &match);
1863 break;
1864 }
1865 case MSG_GETITEM:
1866 {
1867 BotMatch_GetItem(bs, &match);
1868 break;
1869 }
1870 case MSG_JOINSUBTEAM: //join a sub team
1871 {
1872 BotMatch_JoinSubteam(bs, &match);
1873 break;
1874 }
1875 case MSG_LEAVESUBTEAM: //leave a sub team
1876 {
1877 BotMatch_LeaveSubteam(bs, &match);
1878 break;
1879 }
1880 case MSG_WHICHTEAM:
1881 {
1882 BotMatch_WhichTeam(bs, &match);
1883 break;
1884 }
1885 case MSG_CHECKPOINT: //remember a check point
1886 {
1887 BotMatch_CheckPoint(bs, &match);
1888 break;
1889 }
1890 case MSG_CREATENEWFORMATION: //start the creation of a new formation
1891 {
1892 trap_EA_SayTeam(bs->client, "the part of my brain to create formations has been damaged");
1893 break;
1894 }
1895 case MSG_FORMATIONPOSITION: //tell someone his/her position in the formation
1896 {
1897 trap_EA_SayTeam(bs->client, "the part of my brain to create formations has been damaged");
1898 break;
1899 }
1900 case MSG_FORMATIONSPACE: //set the formation space
1901 {
1902 BotMatch_FormationSpace(bs, &match);
1903 break;
1904 }
1905 case MSG_DOFORMATION: //form a certain formation
1906 {
1907 break;
1908 }
1909 case MSG_DISMISS: //dismiss someone
1910 {
1911 BotMatch_Dismiss(bs, &match);
1912 break;
1913 }
1914 case MSG_STARTTEAMLEADERSHIP: //someone will become the team leader
1915 {
1916 BotMatch_StartTeamLeaderShip(bs, &match);
1917 break;
1918 }
1919 case MSG_STOPTEAMLEADERSHIP: //someone will stop being the team leader
1920 {
1921 BotMatch_StopTeamLeaderShip(bs, &match);
1922 break;
1923 }
1924 case MSG_WHOISTEAMLAEDER:
1925 {
1926 BotMatch_WhoIsTeamLeader(bs, &match);
1927 break;
1928 }
1929 case MSG_WHATAREYOUDOING: //ask a bot what he/she is doing
1930 {
1931 BotMatch_WhatAreYouDoing(bs, &match);
1932 break;
1933 }
1934 case MSG_WHATISMYCOMMAND:
1935 {
1936 BotMatch_WhatIsMyCommand(bs, &match);
1937 break;
1938 }
1939 case MSG_WHEREAREYOU:
1940 {
1941 BotMatch_WhereAreYou(bs, &match);
1942 break;
1943 }
1944 case MSG_LEADTHEWAY:
1945 {
1946 BotMatch_LeadTheWay(bs, &match);
1947 break;
1948 }
1949 case MSG_KILL:
1950 {
1951 BotMatch_Kill(bs, &match);
1952 break;
1953 }
1954 case MSG_ENTERGAME: //someone entered the game
1955 {
1956 BotMatch_EnterGame(bs, &match);
1957 break;
1958 }
1959 case MSG_NEWLEADER:
1960 {
1961 BotMatch_NewLeader(bs, &match);
1962 break;
1963 }
1964 case MSG_WAIT:
1965 {
1966 break;
1967 }
1968 case MSG_SUICIDE:
1969 {
1970 BotMatch_Suicide(bs, &match);
1971 break;
1972 }
1973 default:
1974 {
1975 BotAI_Print(PRT_MESSAGE, "unknown match type\n");
1976 break;
1977 }
1978 }
1979 return qtrue;
1980 }