Debian Codegraph @

code/game/ai_team.c

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