Debian Codegraph @

code/game/ai_team.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_team.c
26 *
27 * desc: Quake3 bot AI
28 *
29 * $Archive: /MissionPack/code/game/ai_team.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 #include "ai_vcmd.h"
51
52 #include "match.h"
53
54 // for the voice chats
55 #include "../../ui/menudef.h"
56
57 //ctf task preferences for a client
58 typedef struct bot_ctftaskpreference_s
59 {
60 char name[36];
61 int preference;
62 } bot_ctftaskpreference_t;
63
64 bot_ctftaskpreference_t ctftaskpreferences[MAX_CLIENTS];
65
66
67 /*
68 ==================
69 BotValidTeamLeader
70 ==================
71 */
72 int BotValidTeamLeader(bot_state_t *bs) {
73 if (!strlen(bs->teamleader)) return qfalse;
74 if (ClientFromName(bs->teamleader) == -1) return qfalse;
75 return qtrue;
76 }
77
78 /*
79 ==================
80 BotNumTeamMates
81 ==================
82 */
83 int BotNumTeamMates(bot_state_t *bs) {
84 int i, numplayers;
85 char buf[MAX_INFO_STRING];
86
87 numplayers = 0;
88 for (i = 0; i < level.maxclients; i++) {
89 trap_GetConfigstring(CS_PLAYERS+i, buf, sizeof(buf));
90 //if no config string or no name
91 if (!strlen(buf) || !strlen(Info_ValueForKey(buf, "n"))) continue;
92 //skip spectators
93 if (atoi(Info_ValueForKey(buf, "t")) == TEAM_SPECTATOR) continue;
94 //
95 if (BotSameTeam(bs, i)) {
96 numplayers++;
97 }
98 }
99 return numplayers;
100 }
101
102 /*
103 ==================
104 BotClientTravelTimeToGoal
105 ==================
106 */
107 int BotClientTravelTimeToGoal(int client, bot_goal_t *goal) {
108 playerState_t ps;
109 int areanum;
110
111 if (BotAI_GetClientState(client, &ps)) {
112 areanum = BotPointAreaNum(ps.origin);
113 } else {
114 areanum = 0;
115 }
116
117 if (!areanum) return 1;
118 return trap_AAS_AreaTravelTimeToGoalArea(areanum, ps.origin, goal->areanum, TFL_DEFAULT);
119 }
120
121 /*
122 ==================
123 BotSortTeamMatesByBaseTravelTime
124 ==================
125 */
126 int BotSortTeamMatesByBaseTravelTime(bot_state_t *bs, int *teammates, int maxteammates) {
127
128 int i, j, k, numteammates, traveltime;
129 char buf[MAX_INFO_STRING];
130 int traveltimes[MAX_CLIENTS];
131 bot_goal_t *goal = NULL;
132
133 #ifdef MISSIONPACK
134 if (gametype == GT_CTF || gametype == GT_1FCTF)
135 #else
136 if (gametype == GT_CTF)
137 #endif
138 {
139 if (BotTeam(bs) == TEAM_RED)
140 goal = &ctf_redflag;
141 else
142 goal = &ctf_blueflag;
143 }
144 #ifdef MISSIONPACK
145 else {
146 if (BotTeam(bs) == TEAM_RED)
147 goal = &redobelisk;
148 else
149 goal = &blueobelisk;
150 }
151 #endif
152 numteammates = 0;
153 for (i = 0; i < level.maxclients; i++) {
154 trap_GetConfigstring(CS_PLAYERS+i, buf, sizeof(buf));
155 //if no config string or no name
156 if (!strlen(buf) || !strlen(Info_ValueForKey(buf, "n"))) continue;
157 //skip spectators
158 if (atoi(Info_ValueForKey(buf, "t")) == TEAM_SPECTATOR) continue;
159 //
160 if (BotSameTeam(bs, i) && goal) {
161 //
162 traveltime = BotClientTravelTimeToGoal(i, goal);
163 //
164 for (j = 0; j < numteammates; j++) {
165 if (traveltime < traveltimes[j]) {
166 for (k = numteammates; k > j; k--) {
167 traveltimes[k] = traveltimes[k-1];
168 teammates[k] = teammates[k-1];
169 }
170 break;
171 }
172 }
173 traveltimes[j] = traveltime;
174 teammates[j] = i;
175 numteammates++;
176 if (numteammates >= maxteammates) break;
177 }
178 }
179 return numteammates;
180 }
181
182 /*
183 ==================
184 BotSetTeamMateTaskPreference
185 ==================
186 */
187 void BotSetTeamMateTaskPreference(bot_state_t *bs, int teammate, int preference) {
188 char teammatename[MAX_NETNAME];
189
190 ctftaskpreferences[teammate].preference = preference;
191 ClientName(teammate, teammatename, sizeof(teammatename));
192 strcpy(ctftaskpreferences[teammate].name, teammatename);
193 }
194
195 /*
196 ==================
197 BotGetTeamMateTaskPreference
198 ==================
199 */
200 int BotGetTeamMateTaskPreference(bot_state_t *bs, int teammate) {
201 char teammatename[MAX_NETNAME];
202
203 if (!ctftaskpreferences[teammate].preference) return 0;
204 ClientName(teammate, teammatename, sizeof(teammatename));
205 if (Q_stricmp(teammatename, ctftaskpreferences[teammate].name)) return 0;
206 return ctftaskpreferences[teammate].preference;
207 }
208
209 /*
210 ==================
211 BotSortTeamMatesByTaskPreference
212 ==================
213 */
214 int BotSortTeamMatesByTaskPreference(bot_state_t *bs, int *teammates, int numteammates) {
215 int defenders[MAX_CLIENTS], numdefenders;
216 int attackers[MAX_CLIENTS], numattackers;
217 int roamers[MAX_CLIENTS], numroamers;
218 int i, preference;
219
220 numdefenders = numattackers = numroamers = 0;
221 for (i = 0; i < numteammates; i++) {
222 preference = BotGetTeamMateTaskPreference(bs, teammates[i]);
223 if (preference & TEAMTP_DEFENDER) {
224 defenders[numdefenders++] = teammates[i];
225 }
226 else if (preference & TEAMTP_ATTACKER) {
227 attackers[numattackers++] = teammates[i];
228 }
229 else {
230 roamers[numroamers++] = teammates[i];
231 }
232 }
233 numteammates = 0;
234 //defenders at the front of the list
235 memcpy(&teammates[numteammates], defenders, numdefenders * sizeof(int));
236 numteammates += numdefenders;
237 //roamers in the middle
238 memcpy(&teammates[numteammates], roamers, numroamers * sizeof(int));
239 numteammates += numroamers;
240 //attacker in the back of the list
241 memcpy(&teammates[numteammates], attackers, numattackers * sizeof(int));
242 numteammates += numattackers;
243
244 return numteammates;
245 }
246
247 /*
248 ==================
249 BotSayTeamOrders
250 ==================
251 */
252 void BotSayTeamOrderAlways(bot_state_t *bs, int toclient) {
253 char teamchat[MAX_MESSAGE_SIZE];
254 char buf[MAX_MESSAGE_SIZE];
255 char name[MAX_NETNAME];
256
257 //if the bot is talking to itself
258 if (bs->client == toclient) {
259 //don't show the message just put it in the console message queue
260 trap_BotGetChatMessage(bs->cs, buf, sizeof(buf));
261 ClientName(bs->client, name, sizeof(name));
262 Com_sprintf(teamchat, sizeof(teamchat), EC"(%s"EC")"EC": %s", name, buf);
263 trap_BotQueueConsoleMessage(bs->cs, CMS_CHAT, teamchat);
264 }
265 else {
266 trap_BotEnterChat(bs->cs, toclient, CHAT_TELL);
267 }
268 }
269
270 /*
271 ==================
272 BotSayTeamOrders
273 ==================
274 */
275 void BotSayTeamOrder(bot_state_t *bs, int toclient) {
276 #ifdef MISSIONPACK
277 // voice chats only
278 char buf[MAX_MESSAGE_SIZE];
279
280 trap_BotGetChatMessage(bs->cs, buf, sizeof(buf));
281 #else
282 BotSayTeamOrderAlways(bs, toclient);
283 #endif
284 }
285
286 /*
287 ==================
288 BotVoiceChat
289 ==================
290 */
291 void BotVoiceChat(bot_state_t *bs, int toclient, char *voicechat) {
292 #ifdef MISSIONPACK
293 if (toclient == -1)
294 // voice only say team
295 trap_EA_Command(bs->client, va("vsay_team %s", voicechat));
296 else
297 // voice only tell single player
298 trap_EA_Command(bs->client, va("vtell %d %s", toclient, voicechat));
299 #endif
300 }
301
302 /*
303 ==================
304 BotVoiceChatOnly
305 ==================
306 */
307 void BotVoiceChatOnly(bot_state_t *bs, int toclient, char *voicechat) {
308 #ifdef MISSIONPACK
309 if (toclient == -1)
310 // voice only say team
311 trap_EA_Command(bs->client, va("vosay_team %s", voicechat));
312 else
313 // voice only tell single player
314 trap_EA_Command(bs->client, va("votell %d %s", toclient, voicechat));
315 #endif
316 }
317
318 /*
319 ==================
320 BotSayVoiceTeamOrder
321 ==================
322 */
323 void BotSayVoiceTeamOrder(bot_state_t *bs, int toclient, char *voicechat) {
324 #ifdef MISSIONPACK
325 BotVoiceChat(bs, toclient, voicechat);
326 #endif
327 }
328
329 /*
330 ==================
331 BotCTFOrders
332 ==================
333 */
334 void BotCTFOrders_BothFlagsNotAtBase(bot_state_t *bs) {
335 int numteammates, defenders, attackers, i, other;
336 int teammates[MAX_CLIENTS] = {0};
337 char name[MAX_NETNAME], carriername[MAX_NETNAME];
338
339 numteammates = BotSortTeamMatesByBaseTravelTime(bs, teammates, sizeof(teammates));
340 BotSortTeamMatesByTaskPreference(bs, teammates, numteammates);
341 //different orders based on the number of team mates
342 switch(bs->numteammates) {
343 case 1: break;
344 case 2:
345 {
346 //tell the one not carrying the flag to attack the enemy base
347 if (teammates[0] != bs->flagcarrier) other = teammates[0];
348 else other = teammates[1];
349 ClientName(other, name, sizeof(name));
350 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
351 BotSayTeamOrder(bs, other);
352 BotSayVoiceTeamOrder(bs, other, VOICECHAT_GETFLAG);
353 break;
354 }
355 case 3:
356 {
357 //tell the one closest to the base not carrying the flag to accompany the flag carrier
358 if (teammates[0] != bs->flagcarrier) other = teammates[0];
359 else other = teammates[1];
360 ClientName(other, name, sizeof(name));
361 if ( bs->flagcarrier != -1 ) {
362 ClientName(bs->flagcarrier, carriername, sizeof(carriername));
363 if (bs->flagcarrier == bs->client) {
364 BotAI_BotInitialChat(bs, "cmd_accompanyme", name, NULL);
365 BotSayVoiceTeamOrder(bs, other, VOICECHAT_FOLLOWME);
366 }
367 else {
368 BotAI_BotInitialChat(bs, "cmd_accompany", name, carriername, NULL);
369 BotSayVoiceTeamOrder(bs, other, VOICECHAT_FOLLOWFLAGCARRIER);
370 }
371 }
372 else {
373 //
374 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
375 BotSayVoiceTeamOrder(bs, other, VOICECHAT_GETFLAG);
376 }
377 BotSayTeamOrder(bs, other);
378 //tell the one furthest from the the base not carrying the flag to get the enemy flag
379 if (teammates[2] != bs->flagcarrier) other = teammates[2];
380 else other = teammates[1];
381 ClientName(other, name, sizeof(name));
382 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
383 BotSayTeamOrder(bs, other);
384 BotSayVoiceTeamOrder(bs, other, VOICECHAT_RETURNFLAG);
385 break;
386 }
387 default:
388 {
389 defenders = (int) (float) numteammates * 0.4 + 0.5;
390 if (defenders > 4) defenders = 4;
391 attackers = (int) (float) numteammates * 0.5 + 0.5;
392 if (attackers > 5) attackers = 5;
393 if (bs->flagcarrier != -1) {
394 ClientName(bs->flagcarrier, carriername, sizeof(carriername));
395 for (i = 0; i < defenders; i++) {
396 //
397 if (teammates[i] == bs->flagcarrier) {
398 continue;
399 }
400 //
401 ClientName(teammates[i], name, sizeof(name));
402 if (bs->flagcarrier == bs->client) {
403 BotAI_BotInitialChat(bs, "cmd_accompanyme", name, NULL);
404 BotSayVoiceTeamOrder(bs, teammates[i], VOICECHAT_FOLLOWME);
405 }
406 else {
407 BotAI_BotInitialChat(bs, "cmd_accompany", name, carriername, NULL);
408 BotSayVoiceTeamOrder(bs, teammates[i], VOICECHAT_FOLLOWFLAGCARRIER);
409 }
410 BotSayTeamOrder(bs, teammates[i]);
411 }
412 }
413 else {
414 for (i = 0; i < defenders; i++) {
415 //
416 if (teammates[i] == bs->flagcarrier) {
417 continue;
418 }
419 //
420 ClientName(teammates[i], name, sizeof(name));
421 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
422 BotSayVoiceTeamOrder(bs, teammates[i], VOICECHAT_GETFLAG);
423 BotSayTeamOrder(bs, teammates[i]);
424 }
425 }
426 for (i = 0; i < attackers; i++) {
427 //
428 if (teammates[numteammates - i - 1] == bs->flagcarrier) {
429 continue;
430 }
431 //
432 ClientName(teammates[numteammates - i - 1], name, sizeof(name));
433 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
434 BotSayTeamOrder(bs, teammates[numteammates - i - 1]);
435 BotSayVoiceTeamOrder(bs, teammates[numteammates - i - 1], VOICECHAT_RETURNFLAG);
436 }
437 //
438 break;
439 }
440 }
441 }
442
443 /*
444 ==================
445 BotCTFOrders
446 ==================
447 */
448 void BotCTFOrders_FlagNotAtBase(bot_state_t *bs) {
449 int numteammates, defenders, attackers, i;
450 int teammates[MAX_CLIENTS];
451 char name[MAX_NETNAME];
452
453 numteammates = BotSortTeamMatesByBaseTravelTime(bs, teammates, sizeof(teammates));
454 BotSortTeamMatesByTaskPreference(bs, teammates, numteammates);
455 //passive strategy
456 if (!(bs->ctfstrategy & CTFS_AGRESSIVE)) {
457 //different orders based on the number of team mates
458 switch(bs->numteammates) {
459 case 1: break;
460 case 2:
461 {
462 // keep one near the base for when the flag is returned
463 ClientName(teammates[0], name, sizeof(name));
464 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
465 BotSayTeamOrder(bs, teammates[0]);
466 BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_DEFEND);
467 //
468 ClientName(teammates[1], name, sizeof(name));
469 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
470 BotSayTeamOrder(bs, teammates[1]);
471 BotSayVoiceTeamOrder(bs, teammates[1], VOICECHAT_GETFLAG);
472 break;
473 }
474 case 3:
475 {
476 //keep one near the base for when the flag is returned
477 ClientName(teammates[0], name, sizeof(name));
478 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
479 BotSayTeamOrder(bs, teammates[0]);
480 BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_DEFEND);
481 //the other two get the flag
482 ClientName(teammates[1], name, sizeof(name));
483 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
484 BotSayTeamOrder(bs, teammates[1]);
485 BotSayVoiceTeamOrder(bs, teammates[1], VOICECHAT_GETFLAG);
486 //
487 ClientName(teammates[2], name, sizeof(name));
488 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
489 BotSayTeamOrder(bs, teammates[2]);
490 BotSayVoiceTeamOrder(bs, teammates[2], VOICECHAT_GETFLAG);
491 break;
492 }
493 default:
494 {
495 //keep some people near the base for when the flag is returned
496 defenders = (int) (float) numteammates * 0.3 + 0.5;
497 if (defenders > 3) defenders = 3;
498 attackers = (int) (float) numteammates * 0.6 + 0.5;
499 if (attackers > 6) attackers = 6;
500 for (i = 0; i < defenders; i++) {
501 //
502 ClientName(teammates[i], name, sizeof(name));
503 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
504 BotSayTeamOrder(bs, teammates[i]);
505 BotSayVoiceTeamOrder(bs, teammates[i], VOICECHAT_DEFEND);
506 }
507 for (i = 0; i < attackers; i++) {
508 //
509 ClientName(teammates[numteammates - i - 1], name, sizeof(name));
510 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
511 BotSayTeamOrder(bs, teammates[numteammates - i - 1]);
512 BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_GETFLAG);
513 }
514 //
515 break;
516 }
517 }
518 }
519 else {
520 //different orders based on the number of team mates
521 switch(bs->numteammates) {
522 case 1: break;
523 case 2:
524 {
525 //both will go for the enemy flag
526 ClientName(teammates[0], name, sizeof(name));
527 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
528 BotSayTeamOrder(bs, teammates[0]);
529 BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_GETFLAG);
530 //
531 ClientName(teammates[1], name, sizeof(name));
532 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
533 BotSayTeamOrder(bs, teammates[1]);
534 BotSayVoiceTeamOrder(bs, teammates[1], VOICECHAT_GETFLAG);
535 break;
536 }
537 case 3:
538 {
539 //everyone go for the flag
540 ClientName(teammates[0], name, sizeof(name));
541 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
542 BotSayTeamOrder(bs, teammates[0]);
543 BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_GETFLAG);
544 //
545 ClientName(teammates[1], name, sizeof(name));
546 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
547 BotSayTeamOrder(bs, teammates[1]);
548 BotSayVoiceTeamOrder(bs, teammates[1], VOICECHAT_GETFLAG);
549 //
550 ClientName(teammates[2], name, sizeof(name));
551 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
552 BotSayTeamOrder(bs, teammates[2]);
553 BotSayVoiceTeamOrder(bs, teammates[2], VOICECHAT_GETFLAG);
554 break;
555 }
556 default:
557 {
558 //keep some people near the base for when the flag is returned
559 defenders = (int) (float) numteammates * 0.2 + 0.5;
560 if (defenders > 2) defenders = 2;
561 attackers = (int) (float) numteammates * 0.7 + 0.5;
562 if (attackers > 7) attackers = 7;
563 for (i = 0; i < defenders; i++) {
564 //
565 ClientName(teammates[i], name, sizeof(name));
566 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
567 BotSayTeamOrder(bs, teammates[i]);
568 BotSayVoiceTeamOrder(bs, teammates[i], VOICECHAT_DEFEND);
569 }
570 for (i = 0; i < attackers; i++) {
571 //
572 ClientName(teammates[numteammates - i - 1], name, sizeof(name));
573 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
574 BotSayTeamOrder(bs, teammates[numteammates - i - 1]);
575 BotSayVoiceTeamOrder(bs, teammates[numteammates - i - 1], VOICECHAT_GETFLAG);
576 }
577 //
578 break;
579 }
580 }
581 }
582 }
583
584 /*
585 ==================
586 BotCTFOrders
587 ==================
588 */
589 void BotCTFOrders_EnemyFlagNotAtBase(bot_state_t *bs) {
590 int numteammates, defenders, attackers, i, other;
591 int teammates[MAX_CLIENTS];
592 char name[MAX_NETNAME], carriername[MAX_NETNAME];
593
594 numteammates = BotSortTeamMatesByBaseTravelTime(bs, teammates, sizeof(teammates));
595 BotSortTeamMatesByTaskPreference(bs, teammates, numteammates);
596 //different orders based on the number of team mates
597 switch(numteammates) {
598 case 1: break;
599 case 2:
600 {
601 //tell the one not carrying the flag to defend the base
602 if (teammates[0] == bs->flagcarrier) other = teammates[1];
603 else other = teammates[0];
604 ClientName(other, name, sizeof(name));
605 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
606 BotSayTeamOrder(bs, other);
607 BotSayVoiceTeamOrder(bs, other, VOICECHAT_DEFEND);
608 break;
609 }
610 case 3:
611 {
612 //tell the one closest to the base not carrying the flag to defend the base
613 if (teammates[0] != bs->flagcarrier) other = teammates[0];
614 else other = teammates[1];
615 ClientName(other, name, sizeof(name));
616 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
617 BotSayTeamOrder(bs, other);
618 BotSayVoiceTeamOrder(bs, other, VOICECHAT_DEFEND);
619 //tell the other also to defend the base
620 if (teammates[2] != bs->flagcarrier) other = teammates[2];
621 else other = teammates[1];
622 ClientName(other, name, sizeof(name));
623 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
624 BotSayTeamOrder(bs, other);
625 BotSayVoiceTeamOrder(bs, other, VOICECHAT_DEFEND);
626 break;
627 }
628 default:
629 {
630 //60% will defend the base
631 defenders = (int) (float) numteammates * 0.6 + 0.5;
632 if (defenders > 6) defenders = 6;
633 //30% accompanies the flag carrier
634 attackers = (int) (float) numteammates * 0.3 + 0.5;
635 if (attackers > 3) attackers = 3;
636 for (i = 0; i < defenders; i++) {
637 //
638 if (teammates[i] == bs->flagcarrier) {
639 continue;
640 }
641 ClientName(teammates[i], name, sizeof(name));
642 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
643 BotSayTeamOrder(bs, teammates[i]);
644 BotSayVoiceTeamOrder(bs, teammates[i], VOICECHAT_DEFEND);
645 }
646 // if we have a flag carrier
647 if ( bs->flagcarrier != -1 ) {
648 ClientName(bs->flagcarrier, carriername, sizeof(carriername));
649 for (i = 0; i < attackers; i++) {
650 //
651 if (teammates[numteammates - i - 1] == bs->flagcarrier) {
652 continue;
653 }
654 //
655 ClientName(teammates[numteammates - i - 1], name, sizeof(name));
656 if (bs->flagcarrier == bs->client) {
657 BotAI_BotInitialChat(bs, "cmd_accompanyme", name, NULL);
658 BotSayVoiceTeamOrder(bs, teammates[numteammates - i - 1], VOICECHAT_FOLLOWME);
659 }
660 else {
661 BotAI_BotInitialChat(bs, "cmd_accompany", name, carriername, NULL);
662 BotSayVoiceTeamOrder(bs, teammates[numteammates - i - 1], VOICECHAT_FOLLOWFLAGCARRIER);
663 }
664 BotSayTeamOrder(bs, teammates[numteammates - i - 1]);
665 }
666 }
667 else {
668 for (i = 0; i < attackers; i++) {
669 //
670 if (teammates[numteammates - i - 1] == bs->flagcarrier) {
671 continue;
672 }
673 //
674 ClientName(teammates[numteammates - i - 1], name, sizeof(name));
675 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
676 BotSayVoiceTeamOrder(bs, teammates[numteammates - i - 1], VOICECHAT_GETFLAG);
677 BotSayTeamOrder(bs, teammates[numteammates - i - 1]);
678 }
679 }
680 //
681 break;
682 }
683 }
684 }
685
686
687 /*
688 ==================
689 BotCTFOrders
690 ==================
691 */
692 void BotCTFOrders_BothFlagsAtBase(bot_state_t *bs) {
693 int numteammates, defenders, attackers, i;
694 int teammates[MAX_CLIENTS] = {0};
695 char name[MAX_NETNAME];
696
697 //sort team mates by travel time to base
698 numteammates = BotSortTeamMatesByBaseTravelTime(bs, teammates, sizeof(teammates));
699 //sort team mates by CTF preference
700 BotSortTeamMatesByTaskPreference(bs, teammates, numteammates);
701 //passive strategy
702 if (!(bs->ctfstrategy & CTFS_AGRESSIVE)) {
703 //different orders based on the number of team mates
704 switch(numteammates) {
705 case 1: break;
706 case 2:
707 {
708 //the one closest to the base will defend the base
709 ClientName(teammates[0], name, sizeof(name));
710 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
711 BotSayTeamOrder(bs, teammates[0]);
712 BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_DEFEND);
713 //the other will get the flag
714 ClientName(teammates[1], name, sizeof(name));
715 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
716 BotSayTeamOrder(bs, teammates[1]);
717 BotSayVoiceTeamOrder(bs, teammates[1], VOICECHAT_GETFLAG);
718 break;
719 }
720 case 3:
721 {
722 //the one closest to the base will defend the base
723 ClientName(teammates[0], name, sizeof(name));
724 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
725 BotSayTeamOrder(bs, teammates[0]);
726 BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_DEFEND);
727 //the second one closest to the base will defend the base
728 ClientName(teammates[1], name, sizeof(name));
729 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
730 BotSayTeamOrder(bs, teammates[1]);
731 BotSayVoiceTeamOrder(bs, teammates[1], VOICECHAT_DEFEND);
732 //the other will get the flag
733 ClientName(teammates[2], name, sizeof(name));
734 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
735 BotSayTeamOrder(bs, teammates[2]);
736 BotSayVoiceTeamOrder(bs, teammates[2], VOICECHAT_GETFLAG);
737 break;
738 }
739 default:
740 {
741 defenders = (int) (float) numteammates * 0.5 + 0.5;
742 if (defenders > 5) defenders = 5;
743 attackers = (int) (float) numteammates * 0.4 + 0.5;
744 if (attackers > 4) attackers = 4;
745 for (i = 0; i < defenders; i++) {
746 //
747 ClientName(teammates[i], name, sizeof(name));
748 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
749 BotSayTeamOrder(bs, teammates[i]);
750 BotSayVoiceTeamOrder(bs, teammates[i], VOICECHAT_DEFEND);
751 }
752 for (i = 0; i < attackers; i++) {
753 //
754 ClientName(teammates[numteammates - i - 1], name, sizeof(name));
755 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
756 BotSayTeamOrder(bs, teammates[numteammates - i - 1]);
757 BotSayVoiceTeamOrder(bs, teammates[numteammates - i - 1], VOICECHAT_GETFLAG);
758 }
759 //
760 break;
761 }
762 }
763 }
764 else {
765 //different orders based on the number of team mates
766 switch(numteammates) {
767 case 1: break;
768 case 2:
769 {
770 //the one closest to the base will defend the base
771 ClientName(teammates[0], name, sizeof(name));
772 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
773 BotSayTeamOrder(bs, teammates[0]);
774 BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_DEFEND);
775 //the other will get the flag
776 ClientName(teammates[1], name, sizeof(name));
777 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
778 BotSayTeamOrder(bs, teammates[1]);
779 BotSayVoiceTeamOrder(bs, teammates[1], VOICECHAT_GETFLAG);
780 break;
781 }
782 case 3:
783 {
784 //the one closest to the base will defend the base
785 ClientName(teammates[0], name, sizeof(name));
786 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
787 BotSayTeamOrder(bs, teammates[0]);
788 BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_DEFEND);
789 //the others should go for the enemy flag
790 ClientName(teammates[1], name, sizeof(name));
791 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
792 BotSayTeamOrder(bs, teammates[1]);
793 BotSayVoiceTeamOrder(bs, teammates[1], VOICECHAT_GETFLAG);
794 //
795 ClientName(teammates[2], name, sizeof(name));
796 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
797 BotSayTeamOrder(bs, teammates[2]);
798 BotSayVoiceTeamOrder(bs, teammates[2], VOICECHAT_GETFLAG);
799 break;
800 }
801 default:
802 {
803 defenders = (int) (float) numteammates * 0.4 + 0.5;
804 if (defenders > 4) defenders = 4;
805 attackers = (int) (float) numteammates * 0.5 + 0.5;
806 if (attackers > 5) attackers = 5;
807 for (i = 0; i < defenders; i++) {
808 //
809 ClientName(teammates[i], name, sizeof(name));
810 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
811 BotSayTeamOrder(bs, teammates[i]);
812 BotSayVoiceTeamOrder(bs, teammates[i], VOICECHAT_DEFEND);
813 }
814 for (i = 0; i < attackers; i++) {
815 //
816 ClientName(teammates[numteammates - i - 1], name, sizeof(name));
817 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
818 BotSayTeamOrder(bs, teammates[numteammates - i - 1]);
819 BotSayVoiceTeamOrder(bs, teammates[numteammates - i - 1], VOICECHAT_GETFLAG);
820 }
821 //
822 break;
823 }
824 }
825 }
826 }
827
828 /*
829 ==================
830 BotCTFOrders
831 ==================
832 */
833 void BotCTFOrders(bot_state_t *bs) {
834 int flagstatus;
835
836 //
837 if (BotTeam(bs) == TEAM_RED) flagstatus = bs->redflagstatus * 2 + bs->blueflagstatus;
838 else flagstatus = bs->blueflagstatus * 2 + bs->redflagstatus;
839 //
840 switch(flagstatus) {
841 case 0: BotCTFOrders_BothFlagsAtBase(bs); break;
842 case 1: BotCTFOrders_EnemyFlagNotAtBase(bs); break;
843 case 2: BotCTFOrders_FlagNotAtBase(bs); break;
844 case 3: BotCTFOrders_BothFlagsNotAtBase(bs); break;
845 }
846 }
847
848
849 /*
850 ==================
851 BotCreateGroup
852 ==================
853 */
854 void BotCreateGroup(bot_state_t *bs, int *teammates, int groupsize) {
855 char name[MAX_NETNAME], leadername[MAX_NETNAME];
856 int i;
857
858 // the others in the group will follow the teammates[0]
859 ClientName(teammates[0], leadername, sizeof(leadername));
860 for (i = 1; i < groupsize; i++)
861 {
862 ClientName(teammates[i], name, sizeof(name));
863 if (teammates[0] == bs->client) {
864 BotAI_BotInitialChat(bs, "cmd_accompanyme", name, NULL);
865 }
866 else {
867 BotAI_BotInitialChat(bs, "cmd_accompany", name, leadername, NULL);
868 }
869 BotSayTeamOrderAlways(bs, teammates[i]);
870 }
871 }
872
873 /*
874 ==================
875 BotTeamOrders
876
877 FIXME: defend key areas?
878 ==================
879 */
880 void BotTeamOrders(bot_state_t *bs) {
881 int teammates[MAX_CLIENTS];
882 int numteammates, i;
883 char buf[MAX_INFO_STRING];
884
885 numteammates = 0;
886 for (i = 0; i < level.maxclients; i++) {
887 trap_GetConfigstring(CS_PLAYERS+i, buf, sizeof(buf));
888 //if no config string or no name
889 if (!strlen(buf) || !strlen(Info_ValueForKey(buf, "n"))) continue;
890 //skip spectators
891 if (atoi(Info_ValueForKey(buf, "t")) == TEAM_SPECTATOR) continue;
892 //
893 if (BotSameTeam(bs, i)) {
894 teammates[numteammates] = i;
895 numteammates++;
896 }
897 }
898 //
899 switch(numteammates) {
900 case 1: break;
901 case 2:
902 {
903 //nothing special
904 break;
905 }
906 case 3:
907 {
908 //have one follow another and one free roaming
909 BotCreateGroup(bs, teammates, 2);
910 break;
911 }
912 case 4:
913 {
914 BotCreateGroup(bs, teammates, 2); //a group of 2
915 BotCreateGroup(bs, &teammates[2], 2); //a group of 2
916 break;
917 }
918 case 5:
919 {
920 BotCreateGroup(bs, teammates, 2); //a group of 2
921 BotCreateGroup(bs, &teammates[2], 3); //a group of 3
922 break;
923 }
924 default:
925 {
926 if (numteammates <= 10) {
927 for (i = 0; i < numteammates / 2; i++) {
928 BotCreateGroup(bs, &teammates[i*2], 2); //groups of 2
929 }
930 }
931 break;
932 }
933 }
934 }
935
936 #ifdef MISSIONPACK
937
938 /*
939 ==================
940 Bot1FCTFOrders_FlagAtCenter
941
942 X% defend the base, Y% get the flag
943 ==================
944 */
945 void Bot1FCTFOrders_FlagAtCenter(bot_state_t *bs) {
946 int numteammates, defenders, attackers, i;
947 int teammates[MAX_CLIENTS];
948 char name[MAX_NETNAME];
949
950 //sort team mates by travel time to base
951 numteammates = BotSortTeamMatesByBaseTravelTime(bs, teammates, sizeof(teammates));
952 //sort team mates by CTF preference
953 BotSortTeamMatesByTaskPreference(bs, teammates, numteammates);
954 //passive strategy
955 if (!(bs->ctfstrategy & CTFS_AGRESSIVE)) {
956 //different orders based on the number of team mates
957 switch(numteammates) {
958 case 1: break;
959 case 2:
960 {
961 //the one closest to the base will defend the base
962 ClientName(teammates[0], name, sizeof(name));
963 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
964 BotSayTeamOrder(bs, teammates[0]);
965 BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_DEFEND);
966 //the other will get the flag
967 ClientName(teammates[1], name, sizeof(name));
968 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
969 BotSayTeamOrder(bs, teammates[1]);
970 BotSayVoiceTeamOrder(bs, teammates[1], VOICECHAT_GETFLAG);
971 break;
972 }
973 case 3:
974 {
975 //the one closest to the base will defend the base
976 ClientName(teammates[0], name, sizeof(name));
977 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
978 BotSayTeamOrder(bs, teammates[0]);
979 BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_DEFEND);
980 //the second one closest to the base will defend the base
981 ClientName(teammates[1], name, sizeof(name));
982 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
983 BotSayTeamOrder(bs, teammates[1]);
984 BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_DEFEND);
985 //the other will get the flag
986 ClientName(teammates[2], name, sizeof(name));
987 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
988 BotSayTeamOrder(bs, teammates[2]);
989 BotSayVoiceTeamOrder(bs, teammates[2], VOICECHAT_GETFLAG);
990 break;
991 }
992 default:
993 {
994 //50% defend the base
995 defenders = (int) (float) numteammates * 0.5 + 0.5;
996 if (defenders > 5) defenders = 5;
997 //40% get the flag
998 attackers = (int) (float) numteammates * 0.4 + 0.5;
999 if (attackers > 4) attackers = 4;
1000 for (i = 0; i < defenders; i++) {
1001 //
1002 ClientName(teammates[i], name, sizeof(name));
1003 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1004 BotSayTeamOrder(bs, teammates[i]);
1005 BotSayVoiceTeamOrder(bs, teammates[i], VOICECHAT_DEFEND);
1006 }
1007 for (i = 0; i < attackers; i++) {
1008 //
1009 ClientName(teammates[numteammates - i - 1], name, sizeof(name));
1010 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
1011 BotSayTeamOrder(bs, teammates[numteammates - i - 1]);
1012 BotSayVoiceTeamOrder(bs, teammates[numteammates - i - 1], VOICECHAT_GETFLAG);
1013 }
1014 //
1015 break;
1016 }
1017 }
1018 }
1019 else { //aggressive
1020 //different orders based on the number of team mates
1021 switch(numteammates) {
1022 case 1: break;
1023 case 2:
1024 {
1025 //the one closest to the base will defend the base
1026 ClientName(teammates[0], name, sizeof(name));
1027 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1028 BotSayTeamOrder(bs, teammates[0]);
1029 BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_DEFEND);
1030 //the other will get the flag
1031 ClientName(teammates[1], name, sizeof(name));
1032 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
1033 BotSayTeamOrder(bs, teammates[1]);
1034 BotSayVoiceTeamOrder(bs, teammates[1], VOICECHAT_GETFLAG);
1035 break;
1036 }
1037 case 3:
1038 {
1039 //the one closest to the base will defend the base
1040 ClientName(teammates[0], name, sizeof(name));
1041 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1042 BotSayTeamOrder(bs, teammates[0]);
1043 BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_DEFEND);
1044 //the others should go for the enemy flag
1045 ClientName(teammates[1], name, sizeof(name));
1046 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
1047 BotSayTeamOrder(bs, teammates[1]);
1048 BotSayVoiceTeamOrder(bs, teammates[1], VOICECHAT_GETFLAG);
1049 //
1050 ClientName(teammates[2], name, sizeof(name));
1051 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
1052 BotSayTeamOrder(bs, teammates[2]);
1053 BotSayVoiceTeamOrder(bs, teammates[2], VOICECHAT_GETFLAG);
1054 break;
1055 }
1056 default:
1057 {
1058 //30% defend the base
1059 defenders = (int) (float) numteammates * 0.3 + 0.5;
1060 if (defenders > 3) defenders = 3;
1061 //60% get the flag
1062 attackers = (int) (float) numteammates * 0.6 + 0.5;
1063 if (attackers > 6) attackers = 6;
1064 for (i = 0; i < defenders; i++) {
1065 //
1066 ClientName(teammates[i], name, sizeof(name));
1067 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1068 BotSayTeamOrder(bs, teammates[i]);
1069 BotSayVoiceTeamOrder(bs, teammates[i], VOICECHAT_DEFEND);
1070 }
1071 for (i = 0; i < attackers; i++) {
1072 //
1073 ClientName(teammates[numteammates - i - 1], name, sizeof(name));
1074 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
1075 BotSayTeamOrder(bs, teammates[numteammates - i - 1]);
1076 BotSayVoiceTeamOrder(bs, teammates[numteammates - i - 1], VOICECHAT_GETFLAG);
1077 }
1078 //
1079 break;
1080 }
1081 }
1082 }
1083 }
1084
1085 /*
1086 ==================
1087 Bot1FCTFOrders_TeamHasFlag
1088
1089 X% towards neutral flag, Y% go towards enemy base and accompany flag carrier if visible
1090 ==================
1091 */
1092 void Bot1FCTFOrders_TeamHasFlag(bot_state_t *bs) {
1093 int numteammates, defenders, attackers, i, other;
1094 int teammates[MAX_CLIENTS];
1095 char name[MAX_NETNAME], carriername[MAX_NETNAME];
1096
1097 //sort team mates by travel time to base
1098 numteammates = BotSortTeamMatesByBaseTravelTime(bs, teammates, sizeof(teammates));
1099 //sort team mates by CTF preference
1100 BotSortTeamMatesByTaskPreference(bs, teammates, numteammates);
1101 //passive strategy
1102 if (!(bs->ctfstrategy & CTFS_AGRESSIVE)) {
1103 //different orders based on the number of team mates
1104 switch(numteammates) {
1105 case 1: break;
1106 case 2:
1107 {
1108 //tell the one not carrying the flag to attack the enemy base
1109 if (teammates[0] == bs->flagcarrier) other = teammates[1];
1110 else other = teammates[0];
1111 ClientName(other, name, sizeof(name));
1112 BotAI_BotInitialChat(bs, "cmd_attackenemybase", name, NULL);
1113 BotSayTeamOrder(bs, other);
1114 BotSayVoiceTeamOrder(bs, other, VOICECHAT_OFFENSE);
1115 break;
1116 }
1117 case 3:
1118 {
1119 //tell the one closest to the base not carrying the flag to defend the base
1120 if (teammates[0] != bs->flagcarrier) other = teammates[0];
1121 else other = teammates[1];
1122 ClientName(other, name, sizeof(name));
1123 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1124 BotSayTeamOrder(bs, other);
1125 BotSayVoiceTeamOrder(bs, other, VOICECHAT_DEFEND);
1126 //tell the one furthest from the base not carrying the flag to accompany the flag carrier
1127 if (teammates[2] != bs->flagcarrier) other = teammates[2];
1128 else other = teammates[1];
1129 ClientName(other, name, sizeof(name));
1130 if ( bs->flagcarrier != -1 ) {
1131 ClientName(bs->flagcarrier, carriername, sizeof(carriername));
1132 if (bs->flagcarrier == bs->client) {
1133 BotAI_BotInitialChat(bs, "cmd_accompanyme", name, NULL);
1134 BotSayVoiceTeamOrder(bs, other, VOICECHAT_FOLLOWME);
1135 }
1136 else {
1137 BotAI_BotInitialChat(bs, "cmd_accompany", name, carriername, NULL);
1138 BotSayVoiceTeamOrder(bs, other, VOICECHAT_FOLLOWFLAGCARRIER);
1139 }
1140 }
1141 else {
1142 //
1143 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
1144 BotSayVoiceTeamOrder(bs, other, VOICECHAT_GETFLAG);
1145 }
1146 BotSayTeamOrder(bs, other);
1147 break;
1148 }
1149 default:
1150 {
1151 //30% will defend the base
1152 defenders = (int) (float) numteammates * 0.3 + 0.5;
1153 if (defenders > 3) defenders = 3;
1154 //70% accompanies the flag carrier
1155 attackers = (int) (float) numteammates * 0.7 + 0.5;
1156 if (attackers > 7) attackers = 7;
1157 for (i = 0; i < defenders; i++) {
1158 //
1159 if (teammates[i] == bs->flagcarrier) {
1160 continue;
1161 }
1162 ClientName(teammates[i], name, sizeof(name));
1163 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1164 BotSayTeamOrder(bs, teammates[i]);
1165 BotSayVoiceTeamOrder(bs, teammates[i], VOICECHAT_DEFEND);
1166 }
1167 if (bs->flagcarrier != -1) {
1168 ClientName(bs->flagcarrier, carriername, sizeof(carriername));
1169 for (i = 0; i < attackers; i++) {
1170 //
1171 if (teammates[numteammates - i - 1] == bs->flagcarrier) {
1172 continue;
1173 }
1174 //
1175 ClientName(teammates[numteammates - i - 1], name, sizeof(name));
1176 if (bs->flagcarrier == bs->client) {
1177 BotAI_BotInitialChat(bs, "cmd_accompanyme", name, NULL);
1178 BotSayVoiceTeamOrder(bs, teammates[numteammates - i - 1], VOICECHAT_FOLLOWME);
1179 }
1180 else {
1181 BotAI_BotInitialChat(bs, "cmd_accompany", name, carriername, NULL);
1182 BotSayVoiceTeamOrder(bs, teammates[numteammates - i - 1], VOICECHAT_FOLLOWFLAGCARRIER);
1183 }
1184 BotSayTeamOrder(bs, teammates[numteammates - i - 1]);
1185 }
1186 }
1187 else {
1188 for (i = 0; i < attackers; i++) {
1189 //
1190 if (teammates[numteammates - i - 1] == bs->flagcarrier) {
1191 continue;
1192 }
1193 //
1194 ClientName(teammates[numteammates - i - 1], name, sizeof(name));
1195 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
1196 BotSayTeamOrder(bs, teammates[numteammates - i - 1]);
1197 BotSayVoiceTeamOrder(bs, teammates[numteammates - i - 1], VOICECHAT_GETFLAG);
1198 }
1199 }
1200 //
1201 break;
1202 }
1203 }
1204 }
1205 else { //aggressive
1206 //different orders based on the number of team mates
1207 switch(numteammates) {
1208 case 1: break;
1209 case 2:
1210 {
1211 //tell the one not carrying the flag to defend the base
1212 if (teammates[0] == bs->flagcarrier) other = teammates[1];
1213 else other = teammates[0];
1214 ClientName(other, name, sizeof(name));
1215 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1216 BotSayTeamOrder(bs, other);
1217 BotSayVoiceTeamOrder(bs, other, VOICECHAT_DEFEND);
1218 break;
1219 }
1220 case 3:
1221 {
1222 //tell the one closest to the base not carrying the flag to defend the base
1223 if (teammates[0] != bs->flagcarrier) other = teammates[0];
1224 else other = teammates[1];
1225 ClientName(other, name, sizeof(name));
1226 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1227 BotSayTeamOrder(bs, other);
1228 BotSayVoiceTeamOrder(bs, other, VOICECHAT_DEFEND);
1229 //tell the one furthest from the base not carrying the flag to accompany the flag carrier
1230 if (teammates[2] != bs->flagcarrier) other = teammates[2];
1231 else other = teammates[1];
1232 ClientName(other, name, sizeof(name));
1233 ClientName(bs->flagcarrier, carriername, sizeof(carriername));
1234 if (bs->flagcarrier == bs->client) {
1235 BotAI_BotInitialChat(bs, "cmd_accompanyme", name, NULL);
1236 BotSayVoiceTeamOrder(bs, other, VOICECHAT_FOLLOWME);
1237 }
1238 else {
1239 BotAI_BotInitialChat(bs, "cmd_accompany", name, carriername, NULL);
1240 BotSayVoiceTeamOrder(bs, other, VOICECHAT_FOLLOWFLAGCARRIER);
1241 }
1242 BotSayTeamOrder(bs, other);
1243 break;
1244 }
1245 default:
1246 {
1247 //20% will defend the base
1248 defenders = (int) (float) numteammates * 0.2 + 0.5;
1249 if (defenders > 2) defenders = 2;
1250 //80% accompanies the flag carrier
1251 attackers = (int) (float) numteammates * 0.8 + 0.5;
1252 if (attackers > 8) attackers = 8;
1253 for (i = 0; i < defenders; i++) {
1254 //
1255 if (teammates[i] == bs->flagcarrier) {
1256 continue;
1257 }
1258 ClientName(teammates[i], name, sizeof(name));
1259 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1260 BotSayTeamOrder(bs, teammates[i]);
1261 BotSayVoiceTeamOrder(bs, teammates[i], VOICECHAT_DEFEND);
1262 }
1263 ClientName(bs->flagcarrier, carriername, sizeof(carriername));
1264 for (i = 0; i < attackers; i++) {
1265 //
1266 if (teammates[numteammates - i - 1] == bs->flagcarrier) {
1267 continue;
1268 }
1269 //
1270 ClientName(teammates[numteammates - i - 1], name, sizeof(name));
1271 if (bs->flagcarrier == bs->client) {
1272 BotAI_BotInitialChat(bs, "cmd_accompanyme", name, NULL);
1273 BotSayVoiceTeamOrder(bs, teammates[numteammates - i - 1], VOICECHAT_FOLLOWME);
1274 }
1275 else {
1276 BotAI_BotInitialChat(bs, "cmd_accompany", name, carriername, NULL);
1277 BotSayVoiceTeamOrder(bs, teammates[numteammates - i - 1], VOICECHAT_FOLLOWFLAGCARRIER);
1278 }
1279 BotSayTeamOrder(bs, teammates[numteammates - i - 1]);
1280 }
1281 //
1282 break;
1283 }
1284 }
1285 }
1286 }
1287
1288 /*
1289 ==================
1290 Bot1FCTFOrders_EnemyHasFlag
1291
1292 X% defend the base, Y% towards neutral flag
1293 ==================
1294 */
1295 void Bot1FCTFOrders_EnemyHasFlag(bot_state_t *bs) {
1296 int numteammates, defenders, attackers, i;
1297 int teammates[MAX_CLIENTS];
1298 char name[MAX_NETNAME];
1299
1300 //sort team mates by travel time to base
1301 numteammates = BotSortTeamMatesByBaseTravelTime(bs, teammates, sizeof(teammates));
1302 //sort team mates by CTF preference
1303 BotSortTeamMatesByTaskPreference(bs, teammates, numteammates);
1304 //passive strategy
1305 if (!(bs->ctfstrategy & CTFS_AGRESSIVE)) {
1306 //different orders based on the number of team mates
1307 switch(numteammates) {
1308 case 1: break;
1309 case 2:
1310 {
1311 //both defend the base
1312 ClientName(teammates[0], name, sizeof(name));
1313 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1314 BotSayTeamOrder(bs, teammates[0]);
1315 BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_DEFEND);
1316 //
1317 ClientName(teammates[1], name, sizeof(name));
1318 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1319 BotSayTeamOrder(bs, teammates[1]);
1320 BotSayVoiceTeamOrder(bs, teammates[1], VOICECHAT_DEFEND);
1321 break;
1322 }
1323 case 3:
1324 {
1325 //the one closest to the base will defend the base
1326 ClientName(teammates[0], name, sizeof(name));
1327 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1328 BotSayTeamOrder(bs, teammates[0]);
1329 BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_DEFEND);
1330 //the second one closest to the base will defend the base
1331 ClientName(teammates[1], name, sizeof(name));
1332 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1333 BotSayTeamOrder(bs, teammates[1]);
1334 BotSayVoiceTeamOrder(bs, teammates[1], VOICECHAT_DEFEND);
1335 //the other will also defend the base
1336 ClientName(teammates[2], name, sizeof(name));
1337 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1338 BotSayTeamOrder(bs, teammates[2]);
1339 BotSayVoiceTeamOrder(bs, teammates[2], VOICECHAT_DEFEND);
1340 break;
1341 }
1342 default:
1343 {
1344 //80% will defend the base
1345 defenders = (int) (float) numteammates * 0.8 + 0.5;
1346 if (defenders > 8) defenders = 8;
1347 //10% will try to return the flag
1348 attackers = (int) (float) numteammates * 0.1 + 0.5;
1349 if (attackers > 1) attackers = 1;
1350 for (i = 0; i < defenders; i++) {
1351 //
1352 ClientName(teammates[i], name, sizeof(name));
1353 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1354 BotSayTeamOrder(bs, teammates[i]);
1355 BotSayVoiceTeamOrder(bs, teammates[i], VOICECHAT_DEFEND);
1356 }
1357 for (i = 0; i < attackers; i++) {
1358 //
1359 ClientName(teammates[numteammates - i - 1], name, sizeof(name));
1360 BotAI_BotInitialChat(bs, "cmd_returnflag", name, NULL);
1361 BotSayTeamOrder(bs, teammates[numteammates - i - 1]);
1362 BotSayVoiceTeamOrder(bs, teammates[numteammates - i - 1], VOICECHAT_GETFLAG);
1363 }
1364 //
1365 break;
1366 }
1367 }
1368 }
1369 else { //aggressive
1370 //different orders based on the number of team mates
1371 switch(numteammates) {
1372 case 1: break;
1373 case 2:
1374 {
1375 //the one closest to the base will defend the base
1376 ClientName(teammates[0], name, sizeof(name));
1377 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1378 BotSayTeamOrder(bs, teammates[0]);
1379 BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_DEFEND);
1380 //the other will get the flag
1381 ClientName(teammates[1], name, sizeof(name));
1382 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1383 BotSayTeamOrder(bs, teammates[1]);
1384 BotSayVoiceTeamOrder(bs, teammates[1], VOICECHAT_DEFEND);
1385 break;
1386 }
1387 case 3:
1388 {
1389 //the one closest to the base will defend the base
1390 ClientName(teammates[0], name, sizeof(name));
1391 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1392 BotSayTeamOrder(bs, teammates[0]);
1393 BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_DEFEND);
1394 //the others should go for the enemy flag
1395 ClientName(teammates[1], name, sizeof(name));
1396 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1397 BotSayTeamOrder(bs, teammates[1]);
1398 BotSayVoiceTeamOrder(bs, teammates[1], VOICECHAT_DEFEND);
1399 //
1400 ClientName(teammates[2], name, sizeof(name));
1401 BotAI_BotInitialChat(bs, "cmd_returnflag", name, NULL);
1402 BotSayTeamOrder(bs, teammates[2]);
1403 BotSayVoiceTeamOrder(bs, teammates[2], VOICECHAT_GETFLAG);
1404 break;
1405 }
1406 default:
1407 {
1408 //70% defend the base
1409 defenders = (int) (float) numteammates * 0.7 + 0.5;
1410 if (defenders > 7) defenders = 7;
1411 //20% try to return the flag
1412 attackers = (int) (float) numteammates * 0.2 + 0.5;
1413 if (attackers > 2) attackers = 2;
1414 for (i = 0; i < defenders; i++) {
1415 //
1416 ClientName(teammates[i], name, sizeof(name));
1417 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1418 BotSayTeamOrder(bs, teammates[i]);
1419 BotSayVoiceTeamOrder(bs, teammates[i], VOICECHAT_DEFEND);
1420 }
1421 for (i = 0; i < attackers; i++) {
1422 //
1423 ClientName(teammates[numteammates - i - 1], name, sizeof(name));
1424 BotAI_BotInitialChat(bs, "cmd_returnflag", name, NULL);
1425 BotSayTeamOrder(bs, teammates[numteammates - i - 1]);
1426 BotSayVoiceTeamOrder(bs, teammates[numteammates - i - 1], VOICECHAT_GETFLAG);
1427 }
1428 //
1429 break;
1430 }
1431 }
1432 }
1433 }
1434
1435 /*
1436 ==================
1437 Bot1FCTFOrders_EnemyDroppedFlag
1438
1439 X% defend the base, Y% get the flag
1440 ==================
1441 */
1442 void Bot1FCTFOrders_EnemyDroppedFlag(bot_state_t *bs) {
1443 int numteammates, defenders, attackers, i;
1444 int teammates[MAX_CLIENTS];
1445 char name[MAX_NETNAME];
1446
1447 //sort team mates by travel time to base
1448 numteammates = BotSortTeamMatesByBaseTravelTime(bs, teammates, sizeof(teammates));
1449 //sort team mates by CTF preference
1450 BotSortTeamMatesByTaskPreference(bs, teammates, numteammates);
1451 //passive strategy
1452 if (!(bs->ctfstrategy & CTFS_AGRESSIVE)) {
1453 //different orders based on the number of team mates
1454 switch(numteammates) {
1455 case 1: break;
1456 case 2:
1457 {
1458 //the one closest to the base will defend the base
1459 ClientName(teammates[0], name, sizeof(name));
1460 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1461 BotSayTeamOrder(bs, teammates[0]);
1462 BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_DEFEND);
1463 //the other will get the flag
1464 ClientName(teammates[1], name, sizeof(name));
1465 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
1466 BotSayTeamOrder(bs, teammates[1]);
1467 BotSayVoiceTeamOrder(bs, teammates[1], VOICECHAT_GETFLAG);
1468 break;
1469 }
1470 case 3:
1471 {
1472 //the one closest to the base will defend the base
1473 ClientName(teammates[0], name, sizeof(name));
1474 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1475 BotSayTeamOrder(bs, teammates[0]);
1476 BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_DEFEND);
1477 //the second one closest to the base will defend the base
1478 ClientName(teammates[1], name, sizeof(name));
1479 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1480 BotSayTeamOrder(bs, teammates[1]);
1481 BotSayVoiceTeamOrder(bs, teammates[1], VOICECHAT_DEFEND);
1482 //the other will get the flag
1483 ClientName(teammates[2], name, sizeof(name));
1484 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
1485 BotSayTeamOrder(bs, teammates[2]);
1486 BotSayVoiceTeamOrder(bs, teammates[2], VOICECHAT_GETFLAG);
1487 break;
1488 }
1489 default:
1490 {
1491 //50% defend the base
1492 defenders = (int) (float) numteammates * 0.5 + 0.5;
1493 if (defenders > 5) defenders = 5;
1494 //40% get the flag
1495 attackers = (int) (float) numteammates * 0.4 + 0.5;
1496 if (attackers > 4) attackers = 4;
1497 for (i = 0; i < defenders; i++) {
1498 //
1499 ClientName(teammates[i], name, sizeof(name));
1500 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1501 BotSayTeamOrder(bs, teammates[i]);
1502 BotSayVoiceTeamOrder(bs, teammates[i], VOICECHAT_DEFEND);
1503 }
1504 for (i = 0; i < attackers; i++) {
1505 //
1506 ClientName(teammates[numteammates - i - 1], name, sizeof(name));
1507 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
1508 BotSayTeamOrder(bs, teammates[numteammates - i - 1]);
1509 BotSayVoiceTeamOrder(bs, teammates[numteammates - i - 1], VOICECHAT_GETFLAG);
1510 }
1511 //
1512 break;
1513 }
1514 }
1515 }
1516 else { //aggressive
1517 //different orders based on the number of team mates
1518 switch(numteammates) {
1519 case 1: break;
1520 case 2:
1521 {
1522 //the one closest to the base will defend the base
1523 ClientName(teammates[0], name, sizeof(name));
1524 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1525 BotSayTeamOrder(bs, teammates[0]);
1526 BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_DEFEND);
1527 //the other will get the flag
1528 ClientName(teammates[1], name, sizeof(name));
1529 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
1530 BotSayTeamOrder(bs, teammates[1]);
1531 BotSayVoiceTeamOrder(bs, teammates[1], VOICECHAT_GETFLAG);
1532 break;
1533 }
1534 case 3:
1535 {
1536 //the one closest to the base will defend the base
1537 ClientName(teammates[0], name, sizeof(name));
1538 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1539 BotSayTeamOrder(bs, teammates[0]);
1540 BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_DEFEND);
1541 //the others should go for the enemy flag
1542 ClientName(teammates[1], name, sizeof(name));
1543 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
1544 BotSayTeamOrder(bs, teammates[1]);
1545 BotSayVoiceTeamOrder(bs, teammates[1], VOICECHAT_GETFLAG);
1546 //
1547 ClientName(teammates[2], name, sizeof(name));
1548 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
1549 BotSayTeamOrder(bs, teammates[2]);
1550 BotSayVoiceTeamOrder(bs, teammates[2], VOICECHAT_GETFLAG);
1551 break;
1552 }
1553 default:
1554 {
1555 //30% defend the base
1556 defenders = (int) (float) numteammates * 0.3 + 0.5;
1557 if (defenders > 3) defenders = 3;
1558 //60% get the flag
1559 attackers = (int) (float) numteammates * 0.6 + 0.5;
1560 if (attackers > 6) attackers = 6;
1561 for (i = 0; i < defenders; i++) {
1562 //
1563 ClientName(teammates[i], name, sizeof(name));
1564 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1565 BotSayTeamOrder(bs, teammates[i]);
1566 BotSayVoiceTeamOrder(bs, teammates[i], VOICECHAT_DEFEND);
1567 }
1568 for (i = 0; i < attackers; i++) {
1569 //
1570 ClientName(teammates[numteammates - i - 1], name, sizeof(name));
1571 BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
1572 BotSayTeamOrder(bs, teammates[numteammates - i - 1]);
1573 BotSayVoiceTeamOrder(bs, teammates[numteammates - i - 1], VOICECHAT_GETFLAG);
1574 }
1575 //
1576 break;
1577 }
1578 }
1579 }
1580 }
1581
1582 /*
1583 ==================
1584 Bot1FCTFOrders
1585 ==================
1586 */
1587 void Bot1FCTFOrders(bot_state_t *bs) {
1588 switch(bs->neutralflagstatus) {
1589 case 0: Bot1FCTFOrders_FlagAtCenter(bs); break;
1590 case 1: Bot1FCTFOrders_TeamHasFlag(bs); break;
1591 case 2: Bot1FCTFOrders_EnemyHasFlag(bs); break;
1592 case 3: Bot1FCTFOrders_EnemyDroppedFlag(bs); break;
1593 }
1594 }
1595
1596 /*
1597 ==================
1598 BotObeliskOrders
1599
1600 X% in defence Y% in offence
1601 ==================
1602 */
1603 void BotObeliskOrders(bot_state_t *bs) {
1604 int numteammates, defenders, attackers, i;
1605 int teammates[MAX_CLIENTS];
1606 char name[MAX_NETNAME];
1607
1608 //sort team mates by travel time to base
1609 numteammates = BotSortTeamMatesByBaseTravelTime(bs, teammates, sizeof(teammates));
1610 //sort team mates by CTF preference
1611 BotSortTeamMatesByTaskPreference(bs, teammates, numteammates);
1612 //passive strategy
1613 if (!(bs->ctfstrategy & CTFS_AGRESSIVE)) {
1614 //different orders based on the number of team mates
1615 switch(numteammates) {
1616 case 1: break;
1617 case 2:
1618 {
1619 //the one closest to the base will defend the base
1620 ClientName(teammates[0], name, sizeof(name));
1621 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1622 BotSayTeamOrder(bs, teammates[0]);
1623 BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_DEFEND);
1624 //the other will attack the enemy base
1625 ClientName(teammates[1], name, sizeof(name));
1626 BotAI_BotInitialChat(bs, "cmd_attackenemybase", name, NULL);
1627 BotSayTeamOrder(bs, teammates[1]);
1628 BotSayVoiceTeamOrder(bs, teammates[1], VOICECHAT_OFFENSE);
1629 break;
1630 }
1631 case 3:
1632 {
1633 //the one closest to the base will defend the base
1634 ClientName(teammates[0], name, sizeof(name));
1635 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1636 BotSayTeamOrder(bs, teammates[0]);
1637 BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_DEFEND);
1638 //the one second closest to the base also defends the base
1639 ClientName(teammates[1], name, sizeof(name));
1640 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1641 BotSayTeamOrder(bs, teammates[1]);
1642 BotSayVoiceTeamOrder(bs, teammates[1], VOICECHAT_DEFEND);
1643 //the other one attacks the enemy base
1644 ClientName(teammates[2], name, sizeof(name));
1645 BotAI_BotInitialChat(bs, "cmd_attackenemybase", name, NULL);
1646 BotSayTeamOrder(bs, teammates[2]);
1647 BotSayVoiceTeamOrder(bs, teammates[2], VOICECHAT_OFFENSE);
1648 break;
1649 }
1650 default:
1651 {
1652 //50% defend the base
1653 defenders = (int) (float) numteammates * 0.5 + 0.5;
1654 if (defenders > 5) defenders = 5;
1655 //40% attack the enemy base
1656 attackers = (int) (float) numteammates * 0.4 + 0.5;
1657 if (attackers > 4) attackers = 4;
1658 for (i = 0; i < defenders; i++) {
1659 //
1660 ClientName(teammates[i], name, sizeof(name));
1661 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1662 BotSayTeamOrder(bs, teammates[i]);
1663 BotSayVoiceTeamOrder(bs, teammates[i], VOICECHAT_DEFEND);
1664 }
1665 for (i = 0; i < attackers; i++) {
1666 //
1667 ClientName(teammates[numteammates - i - 1], name, sizeof(name));
1668 BotAI_BotInitialChat(bs, "cmd_attackenemybase", name, NULL);
1669 BotSayTeamOrder(bs, teammates[numteammates - i - 1]);
1670 BotSayVoiceTeamOrder(bs, teammates[numteammates - i - 1], VOICECHAT_OFFENSE);
1671 }
1672 //
1673 break;
1674 }
1675 }
1676 }
1677 else {
1678 //different orders based on the number of team mates
1679 switch(numteammates) {
1680 case 1: break;
1681 case 2:
1682 {
1683 //the one closest to the base will defend the base
1684 ClientName(teammates[0], name, sizeof(name));
1685 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1686 BotSayTeamOrder(bs, teammates[0]);
1687 BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_DEFEND);
1688 //the other will attack the enemy base
1689 ClientName(teammates[1], name, sizeof(name));
1690 BotAI_BotInitialChat(bs, "cmd_attackenemybase", name, NULL);
1691 BotSayTeamOrder(bs, teammates[1]);
1692 BotSayVoiceTeamOrder(bs, teammates[1], VOICECHAT_OFFENSE);
1693 break;
1694 }
1695 case 3:
1696 {
1697 //the one closest to the base will defend the base
1698 ClientName(teammates[0], name, sizeof(name));
1699 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1700 BotSayTeamOrder(bs, teammates[0]);
1701 BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_DEFEND);
1702 //the others attack the enemy base
1703 ClientName(teammates[1], name, sizeof(name));
1704 BotAI_BotInitialChat(bs, "cmd_attackenemybase", name, NULL);
1705 BotSayTeamOrder(bs, teammates[1]);
1706 BotSayVoiceTeamOrder(bs, teammates[1], VOICECHAT_OFFENSE);
1707 //
1708 ClientName(teammates[2], name, sizeof(name));
1709 BotAI_BotInitialChat(bs, "cmd_attackenemybase", name, NULL);
1710 BotSayTeamOrder(bs, teammates[2]);
1711 BotSayVoiceTeamOrder(bs, teammates[2], VOICECHAT_OFFENSE);
1712 break;
1713 }
1714 default:
1715 {
1716 //30% defend the base
1717 defenders = (int) (float) numteammates * 0.3 + 0.5;
1718 if (defenders > 3) defenders = 3;
1719 //70% attack the enemy base
1720 attackers = (int) (float) numteammates * 0.7 + 0.5;
1721 if (attackers > 7) attackers = 7;
1722 for (i = 0; i < defenders; i++) {
1723 //
1724 ClientName(teammates[i], name, sizeof(name));
1725 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1726 BotSayTeamOrder(bs, teammates[i]);
1727 BotSayVoiceTeamOrder(bs, teammates[i], VOICECHAT_DEFEND);
1728 }
1729 for (i = 0; i < attackers; i++) {
1730 //
1731 ClientName(teammates[numteammates - i - 1], name, sizeof(name));
1732 BotAI_BotInitialChat(bs, "cmd_attackenemybase", name, NULL);
1733 BotSayTeamOrder(bs, teammates[numteammates - i - 1]);
1734 BotSayVoiceTeamOrder(bs, teammates[numteammates - i - 1], VOICECHAT_OFFENSE);
1735 }
1736 //
1737 break;
1738 }
1739 }
1740 }
1741 }
1742
1743 /*
1744 ==================
1745 BotHarvesterOrders
1746
1747 X% defend the base, Y% harvest
1748 ==================
1749 */
1750 void BotHarvesterOrders(bot_state_t *bs) {
1751 int numteammates, defenders, attackers, i;
1752 int teammates[MAX_CLIENTS] = {0};
1753 char name[MAX_NETNAME];
1754
1755 //sort team mates by travel time to base
1756 numteammates = BotSortTeamMatesByBaseTravelTime(bs, teammates, sizeof(teammates));
1757 //sort team mates by CTF preference
1758 BotSortTeamMatesByTaskPreference(bs, teammates, numteammates);
1759 //passive strategy
1760 if (!(bs->ctfstrategy & CTFS_AGRESSIVE)) {
1761 //different orders based on the number of team mates
1762 switch(numteammates) {
1763 case 1: break;
1764 case 2:
1765 {
1766 //the one closest to the base will defend the base
1767 ClientName(teammates[0], name, sizeof(name));
1768 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1769 BotSayTeamOrder(bs, teammates[0]);
1770 BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_DEFEND);
1771 //the other will harvest
1772 ClientName(teammates[1], name, sizeof(name));
1773 BotAI_BotInitialChat(bs, "cmd_harvest", name, NULL);
1774 BotSayTeamOrder(bs, teammates[1]);
1775 BotSayVoiceTeamOrder(bs, teammates[1], VOICECHAT_OFFENSE);
1776 break;
1777 }
1778 case 3:
1779 {
1780 //the one closest to the base will defend the base
1781 ClientName(teammates[0], name, sizeof(name));
1782 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1783 BotSayTeamOrder(bs, teammates[0]);
1784 BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_DEFEND);
1785 //the one second closest to the base also defends the base
1786 ClientName(teammates[1], name, sizeof(name));
1787 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1788 BotSayTeamOrder(bs, teammates[1]);
1789 BotSayVoiceTeamOrder(bs, teammates[1], VOICECHAT_DEFEND);
1790 //the other one goes harvesting
1791 ClientName(teammates[2], name, sizeof(name));
1792 BotAI_BotInitialChat(bs, "cmd_harvest", name, NULL);
1793 BotSayTeamOrder(bs, teammates[2]);
1794 BotSayVoiceTeamOrder(bs, teammates[2], VOICECHAT_OFFENSE);
1795 break;
1796 }
1797 default:
1798 {
1799 //50% defend the base
1800 defenders = (int) (float) numteammates * 0.5 + 0.5;
1801 if (defenders > 5) defenders = 5;
1802 //40% goes harvesting
1803 attackers = (int) (float) numteammates * 0.4 + 0.5;
1804 if (attackers > 4) attackers = 4;
1805 for (i = 0; i < defenders; i++) {
1806 //
1807 ClientName(teammates[i], name, sizeof(name));
1808 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1809 BotSayTeamOrder(bs, teammates[i]);
1810 BotSayVoiceTeamOrder(bs, teammates[i], VOICECHAT_DEFEND);
1811 }
1812 for (i = 0; i < attackers; i++) {
1813 //
1814 ClientName(teammates[numteammates - i - 1], name, sizeof(name));
1815 BotAI_BotInitialChat(bs, "cmd_harvest", name, NULL);
1816 BotSayTeamOrder(bs, teammates[numteammates - i - 1]);
1817 BotSayVoiceTeamOrder(bs, teammates[numteammates - i - 1], VOICECHAT_OFFENSE);
1818 }
1819 //
1820 break;
1821 }
1822 }
1823 }
1824 else {
1825 //different orders based on the number of team mates
1826 switch(numteammates) {
1827 case 1: break;
1828 case 2:
1829 {
1830 //the one closest to the base will defend the base
1831 ClientName(teammates[0], name, sizeof(name));
1832 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1833 BotSayTeamOrder(bs, teammates[0]);
1834 BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_DEFEND);
1835 //the other will harvest
1836 ClientName(teammates[1], name, sizeof(name));
1837 BotAI_BotInitialChat(bs, "cmd_harvest", name, NULL);
1838 BotSayTeamOrder(bs, teammates[1]);
1839 BotSayVoiceTeamOrder(bs, teammates[1], VOICECHAT_OFFENSE);
1840 break;
1841 }
1842 case 3:
1843 {
1844 //the one closest to the base will defend the base
1845 ClientName(teammates[0], name, sizeof(name));
1846 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1847 BotSayTeamOrder(bs, teammates[0]);
1848 BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_DEFEND);
1849 //the others go harvesting
1850 ClientName(teammates[1], name, sizeof(name));
1851 BotAI_BotInitialChat(bs, "cmd_harvest", name, NULL);
1852 BotSayTeamOrder(bs, teammates[1]);
1853 BotSayVoiceTeamOrder(bs, teammates[1], VOICECHAT_OFFENSE);
1854 //
1855 ClientName(teammates[2], name, sizeof(name));
1856 BotAI_BotInitialChat(bs, "cmd_harvest", name, NULL);
1857 BotSayTeamOrder(bs, teammates[2]);
1858 BotSayVoiceTeamOrder(bs, teammates[2], VOICECHAT_OFFENSE);
1859 break;
1860 }
1861 default:
1862 {
1863 //30% defend the base
1864 defenders = (int) (float) numteammates * 0.3 + 0.5;
1865 if (defenders > 3) defenders = 3;
1866 //70% go harvesting
1867 attackers = (int) (float) numteammates * 0.7 + 0.5;
1868 if (attackers > 7) attackers = 7;
1869 for (i = 0; i < defenders; i++) {
1870 //
1871 ClientName(teammates[i], name, sizeof(name));
1872 BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
1873 BotSayTeamOrder(bs, teammates[i]);
1874 BotSayVoiceTeamOrder(bs, teammates[i], VOICECHAT_DEFEND);
1875 }
1876 for (i = 0; i < attackers; i++) {
1877 //
1878 ClientName(teammates[numteammates - i - 1], name, sizeof(name));
1879 BotAI_BotInitialChat(bs, "cmd_harvest", name, NULL);
1880 BotSayTeamOrder(bs, teammates[numteammates - i - 1]);
1881 BotSayVoiceTeamOrder(bs, teammates[numteammates - i - 1], VOICECHAT_OFFENSE);
1882 }
1883 //
1884 break;
1885 }
1886 }
1887 }
1888 }
1889 #endif
1890
1891 /*
1892 ==================
1893 FindHumanTeamLeader
1894 ==================
1895 */
1896 int FindHumanTeamLeader(bot_state_t *bs) {
1897 int i;
1898
1899 for (i = 0; i < MAX_CLIENTS; i++) {
1900 if ( g_entities[i].inuse ) {
1901 // if this player is not a bot
1902 if ( !(g_entities[i].r.svFlags & SVF_BOT) ) {
1903 // if this player is ok with being the leader
1904 if (!notleader[i]) {
1905 // if this player is on the same team
1906 if ( BotSameTeam(bs, i) ) {
1907 ClientName(i, bs->teamleader, sizeof(bs->teamleader));
1908 // if not yet ordered to do anything
1909 if ( !BotSetLastOrderedTask(bs) ) {
1910 // go on defense by default
1911 BotVoiceChat_Defend(bs, i, SAY_TELL);
1912 }
1913 return qtrue;
1914 }
1915 }
1916 }
1917 }
1918 }
1919 return qfalse;
1920 }
1921
1922 /*
1923 ==================
1924 BotTeamAI
1925 ==================
1926 */
1927 void BotTeamAI(bot_state_t *bs) {
1928 int numteammates;
1929 char netname[MAX_NETNAME];
1930
1931 //
1932 if ( gametype < GT_TEAM )
1933 return;
1934 // make sure we've got a valid team leader
1935 if (!BotValidTeamLeader(bs)) {
1936 //
1937 if (!FindHumanTeamLeader(bs)) {
1938 //
1939 if (!bs->askteamleader_time && !bs->becometeamleader_time) {
1940 if (bs->entergame_time + 10 > FloatTime()) {
1941 bs->askteamleader_time = FloatTime() + 5 + random() * 10;
1942 }
1943 else {
1944 bs->becometeamleader_time = FloatTime() + 5 + random() * 10;
1945 }
1946 }
1947 if (bs->askteamleader_time && bs->askteamleader_time < FloatTime()) {
1948 // if asked for a team leader and no response
1949 BotAI_BotInitialChat(bs, "whoisteamleader", NULL);
1950 trap_BotEnterChat(bs->cs, 0, CHAT_TEAM);
1951 bs->askteamleader_time = 0;
1952 bs->becometeamleader_time = FloatTime() + 8 + random() * 10;
1953 }
1954 if (bs->becometeamleader_time && bs->becometeamleader_time < FloatTime()) {
1955 BotAI_BotInitialChat(bs, "iamteamleader", NULL);
1956 trap_BotEnterChat(bs->cs, 0, CHAT_TEAM);
1957 BotSayVoiceTeamOrder(bs, -1, VOICECHAT_STARTLEADER);
1958 ClientName(bs->client, netname, sizeof(netname));
1959 Q_strncpyz(bs->teamleader, netname, sizeof(bs->teamleader));
1960 bs->becometeamleader_time = 0;
1961 }
1962 return;
1963 }
1964 }
1965 bs->askteamleader_time = 0;
1966 bs->becometeamleader_time = 0;
1967
1968 //return if this bot is NOT the team leader
1969 ClientName(bs->client, netname, sizeof(netname));
1970 if (Q_stricmp(netname, bs->teamleader) != 0) return;
1971 //
1972 numteammates = BotNumTeamMates(bs);
1973 //give orders
1974 switch(gametype) {
1975 case GT_TEAM:
1976 {
1977 if (bs->numteammates != numteammates || bs->forceorders) {
1978 bs->teamgiveorders_time = FloatTime();
1979 bs->numteammates = numteammates;
1980 bs->forceorders = qfalse;
1981 }
1982 //if it's time to give orders
1983 if (bs->teamgiveorders_time && bs->teamgiveorders_time < FloatTime() - 5) {
1984 BotTeamOrders(bs);
1985 //give orders again after 120 seconds
1986 bs->teamgiveorders_time = FloatTime() + 120;
1987 }
1988 break;
1989 }
1990 case GT_CTF:
1991 {
1992 //if the number of team mates changed or the flag status changed
1993 //or someone wants to know what to do
1994 if (bs->numteammates != numteammates || bs->flagstatuschanged || bs->forceorders) {
1995 bs->teamgiveorders_time = FloatTime();
1996 bs->numteammates = numteammates;
1997 bs->flagstatuschanged = qfalse;
1998 bs->forceorders = qfalse;
1999 }
2000 //if there were no flag captures the last 3 minutes
2001 if (bs->lastflagcapture_time < FloatTime() - 240) {
2002 bs->lastflagcapture_time = FloatTime();
2003 //randomly change the CTF strategy
2004 if (random() < 0.4) {
2005 bs->ctfstrategy ^= CTFS_AGRESSIVE;
2006 bs->teamgiveorders_time = FloatTime();
2007 }
2008 }
2009 //if it's time to give orders
2010 if (bs->teamgiveorders_time && bs->teamgiveorders_time < FloatTime() - 3) {
2011 BotCTFOrders(bs);
2012 //
2013 bs->teamgiveorders_time = 0;
2014 }
2015 break;
2016 }
2017 #ifdef MISSIONPACK
2018 case GT_1FCTF:
2019 {
2020 if (bs->numteammates != numteammates || bs->flagstatuschanged || bs->forceorders) {
2021 bs->teamgiveorders_time = FloatTime();
2022 bs->numteammates = numteammates;
2023 bs->flagstatuschanged = qfalse;
2024 bs->forceorders = qfalse;
2025 }
2026 //if there were no flag captures the last 4 minutes
2027 if (bs->lastflagcapture_time < FloatTime() - 240) {
2028 bs->lastflagcapture_time = FloatTime();
2029 //randomly change the CTF strategy
2030 if (random() < 0.4) {
2031 bs->ctfstrategy ^= CTFS_AGRESSIVE;
2032 bs->teamgiveorders_time = FloatTime();
2033 }
2034 }
2035 //if it's time to give orders
2036 if (bs->teamgiveorders_time && bs->teamgiveorders_time < FloatTime() - 2) {
2037 Bot1FCTFOrders(bs);
2038 //
2039 bs->teamgiveorders_time = 0;
2040 }
2041 break;
2042 }
2043 case GT_OBELISK:
2044 {
2045 if (bs->numteammates != numteammates || bs->forceorders) {
2046 bs->teamgiveorders_time = FloatTime();
2047 bs->numteammates = numteammates;
2048 bs->forceorders = qfalse;
2049 }
2050 //if it's time to give orders
2051 if (bs->teamgiveorders_time && bs->teamgiveorders_time < FloatTime() - 5) {
2052 BotObeliskOrders(bs);
2053 //give orders again after 30 seconds
2054 bs->teamgiveorders_time = FloatTime() + 30;
2055 }
2056 break;
2057 }
2058 case GT_HARVESTER:
2059 {
2060 if (bs->numteammates != numteammates || bs->forceorders) {
2061 bs->teamgiveorders_time = FloatTime();
2062 bs->numteammates = numteammates;
2063 bs->forceorders = qfalse;
2064 }
2065 //if it's time to give orders
2066 if (bs->teamgiveorders_time && bs->teamgiveorders_time < FloatTime() - 5) {
2067 BotHarvesterOrders(bs);
2068 //give orders again after 30 seconds
2069 bs->teamgiveorders_time = FloatTime() + 30;
2070 }
2071 break;
2072 }
2073 #endif
2074 }
2075 }
2076