Debian Codegraph @

code/game/ai_chat.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_chat.c
26 *
27 * desc: Quake3 bot AI
28 *
29 * $Archive: /MissionPack/code/game/ai_chat.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 //
50 #include "chars.h" //characteristics
51 #include "inv.h" //indexes into the inventory
52 #include "syn.h" //synonyms
53 #include "match.h" //string matching types and vars
54
55 // for the voice chats
56 #ifdef MISSIONPACK // bk001205
57 #include "../../ui/menudef.h"
58 #endif
59
60 #define TIME_BETWEENCHATTING 25
61
62
63 /*
64 ==================
65 BotNumActivePlayers
66 ==================
67 */
68 int BotNumActivePlayers(void) {
69 int i, num;
70 char buf[MAX_INFO_STRING];
71 static int maxclients;
72
73 if (!maxclients)
74 maxclients = trap_Cvar_VariableIntegerValue("sv_maxclients");
75
76 num = 0;
77 for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) {
78 trap_GetConfigstring(CS_PLAYERS+i, buf, sizeof(buf));
79 //if no config string or no name
80 if (!strlen(buf) || !strlen(Info_ValueForKey(buf, "n"))) continue;
81 //skip spectators
82 if (atoi(Info_ValueForKey(buf, "t")) == TEAM_SPECTATOR) continue;
83 //
84 num++;
85 }
86 return num;
87 }
88
89 /*
90 ==================
91 BotIsFirstInRankings
92 ==================
93 */
94 int BotIsFirstInRankings(bot_state_t *bs) {
95 int i, score;
96 char buf[MAX_INFO_STRING];
97 static int maxclients;
98 playerState_t ps;
99
100 if (!maxclients)
101 maxclients = trap_Cvar_VariableIntegerValue("sv_maxclients");
102
103 score = bs->cur_ps.persistant[PERS_SCORE];
104 for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) {
105 trap_GetConfigstring(CS_PLAYERS+i, buf, sizeof(buf));
106 //if no config string or no name
107 if (!strlen(buf) || !strlen(Info_ValueForKey(buf, "n"))) continue;
108 //skip spectators
109 if (atoi(Info_ValueForKey(buf, "t")) == TEAM_SPECTATOR) continue;
110 //
111 BotAI_GetClientState(i, &ps);
112 if (score < ps.persistant[PERS_SCORE]) return qfalse;
113 }
114 return qtrue;
115 }
116
117 /*
118 ==================
119 BotIsLastInRankings
120 ==================
121 */
122 int BotIsLastInRankings(bot_state_t *bs) {
123 int i, score;
124 char buf[MAX_INFO_STRING];
125 static int maxclients;
126 playerState_t ps;
127
128 if (!maxclients)
129 maxclients = trap_Cvar_VariableIntegerValue("sv_maxclients");
130
131 score = bs->cur_ps.persistant[PERS_SCORE];
132 for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) {
133 trap_GetConfigstring(CS_PLAYERS+i, buf, sizeof(buf));
134 //if no config string or no name
135 if (!strlen(buf) || !strlen(Info_ValueForKey(buf, "n"))) continue;
136 //skip spectators
137 if (atoi(Info_ValueForKey(buf, "t")) == TEAM_SPECTATOR) continue;
138 //
139 BotAI_GetClientState(i, &ps);
140 if (score > ps.persistant[PERS_SCORE]) return qfalse;
141 }
142 return qtrue;
143 }
144
145 /*
146 ==================
147 BotFirstClientInRankings
148 ==================
149 */
150 char *BotFirstClientInRankings(void) {
151 int i, bestscore, bestclient;
152 char buf[MAX_INFO_STRING];
153 static char name[32];
154 static int maxclients;
155 playerState_t ps;
156
157 if (!maxclients)
158 maxclients = trap_Cvar_VariableIntegerValue("sv_maxclients");
159
160 bestscore = -999999;
161 bestclient = 0;
162 for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) {
163 trap_GetConfigstring(CS_PLAYERS+i, buf, sizeof(buf));
164 //if no config string or no name
165 if (!strlen(buf) || !strlen(Info_ValueForKey(buf, "n"))) continue;
166 //skip spectators
167 if (atoi(Info_ValueForKey(buf, "t")) == TEAM_SPECTATOR) continue;
168 //
169 BotAI_GetClientState(i, &ps);
170 if (ps.persistant[PERS_SCORE] > bestscore) {
171 bestscore = ps.persistant[PERS_SCORE];
172 bestclient = i;
173 }
174 }
175 EasyClientName(bestclient, name, 32);
176 return name;
177 }
178
179 /*
180 ==================
181 BotLastClientInRankings
182 ==================
183 */
184 char *BotLastClientInRankings(void) {
185 int i, worstscore, bestclient;
186 char buf[MAX_INFO_STRING];
187 static char name[32];
188 static int maxclients;
189 playerState_t ps;
190
191 if (!maxclients)
192 maxclients = trap_Cvar_VariableIntegerValue("sv_maxclients");
193
194 worstscore = 999999;
195 bestclient = 0;
196 for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) {
197 trap_GetConfigstring(CS_PLAYERS+i, buf, sizeof(buf));
198 //if no config string or no name
199 if (!strlen(buf) || !strlen(Info_ValueForKey(buf, "n"))) continue;
200 //skip spectators
201 if (atoi(Info_ValueForKey(buf, "t")) == TEAM_SPECTATOR) continue;
202 //
203 BotAI_GetClientState(i, &ps);
204 if (ps.persistant[PERS_SCORE] < worstscore) {
205 worstscore = ps.persistant[PERS_SCORE];
206 bestclient = i;
207 }
208 }
209 EasyClientName(bestclient, name, 32);
210 return name;
211 }
212
213 /*
214 ==================
215 BotRandomOpponentName
216 ==================
217 */
218 char *BotRandomOpponentName(bot_state_t *bs) {
219 int i, count;
220 char buf[MAX_INFO_STRING];
221 int opponents[MAX_CLIENTS], numopponents;
222 static int maxclients;
223 static char name[32];
224
225 if (!maxclients)
226 maxclients = trap_Cvar_VariableIntegerValue("sv_maxclients");
227
228 numopponents = 0;
229 opponents[0] = 0;
230 for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) {
231 if (i == bs->client) continue;
232 //
233 trap_GetConfigstring(CS_PLAYERS+i, buf, sizeof(buf));
234 //if no config string or no name
235 if (!strlen(buf) || !strlen(Info_ValueForKey(buf, "n"))) continue;
236 //skip spectators
237 if (atoi(Info_ValueForKey(buf, "t")) == TEAM_SPECTATOR) continue;
238 //skip team mates
239 if (BotSameTeam(bs, i)) continue;
240 //
241 opponents[numopponents] = i;
242 numopponents++;
243 }
244 count = random() * numopponents;
245 for (i = 0; i < numopponents; i++) {
246 count--;
247 if (count <= 0) {
248 EasyClientName(opponents[i], name, sizeof(name));
249 return name;
250 }
251 }
252 EasyClientName(opponents[0], name, sizeof(name));
253 return name;
254 }
255
256 /*
257 ==================
258 BotMapTitle
259 ==================
260 */
261
262 char *BotMapTitle(void) {
263 char info[1024];
264 static char mapname[128];
265
266 trap_GetServerinfo(info, sizeof(info));
267
•268 Q_strncpyz(mapname, Info_ValueForKey( info, "mapname" ), sizeof(mapname));
269
270 return mapname;
271 }
272
273
274 /*
275 ==================
276 BotWeaponNameForMeansOfDeath
277 ==================
278 */
279
280 char *BotWeaponNameForMeansOfDeath(int mod) {
281 switch(mod) {
282 case MOD_SHOTGUN: return "Shotgun";
283 case MOD_GAUNTLET: return "Gauntlet";
284 case MOD_MACHINEGUN: return "Machinegun";
285 case MOD_GRENADE:
286 case MOD_GRENADE_SPLASH: return "Grenade Launcher";
287 case MOD_ROCKET:
288 case MOD_ROCKET_SPLASH: return "Rocket Launcher";
289 case MOD_PLASMA:
290 case MOD_PLASMA_SPLASH: return "Plasmagun";
291 case MOD_RAILGUN: return "Railgun";
292 case MOD_LIGHTNING: return "Lightning Gun";
293 case MOD_BFG:
294 case MOD_BFG_SPLASH: return "BFG10K";
295 case MOD_NAIL: return "Nailgun";
296 case MOD_CHAINGUN: return "Chaingun";
297 case MOD_PROXIMITY_MINE: return "Proximity Launcher";
298 case MOD_KAMIKAZE: return "Kamikaze";
299 case MOD_JUICED: return "Prox mine";
300 case MOD_GRAPPLE: return "Grapple";
301 default: return "[unknown weapon]";
302 }
303 }
304
305 /*
306 ==================
307 BotRandomWeaponName
308 ==================
309 */
310 char *BotRandomWeaponName(void) {
311 int rnd;
312
313 rnd = random() * 11.9;
314 switch(rnd) {
315 case 0: return "Gauntlet";
316 case 1: return "Shotgun";
317 case 2: return "Machinegun";
318 case 3: return "Grenade Launcher";
319 case 4: return "Rocket Launcher";
320 case 5: return "Plasmagun";
321 case 6: return "Railgun";
322 case 7: return "Lightning Gun";
323 case 8: return "Nailgun";
324 case 9: return "Chaingun";
325 case 10: return "Proximity Launcher";
326 default: return "BFG10K";
327 }
328 }
329
330 /*
331 ==================
332 BotVisibleEnemies
333 ==================
334 */
335 int BotVisibleEnemies(bot_state_t *bs) {
336 float vis;
337 int i;
338 aas_entityinfo_t entinfo;
339
340 for (i = 0; i < MAX_CLIENTS; i++) {
341
342 if (i == bs->client) continue;
343 //
344 BotEntityInfo(i, &entinfo);
345 //
346 if (!entinfo.valid) continue;
347 //if the enemy isn't dead and the enemy isn't the bot self
348 if (EntityIsDead(&entinfo) || entinfo.number == bs->entitynum) continue;
349 //if the enemy is invisible and not shooting
350 if (EntityIsInvisible(&entinfo) && !EntityIsShooting(&entinfo)) {
351 continue;
352 }
353 //if on the same team
354 if (BotSameTeam(bs, i)) continue;
355 //check if the enemy is visible
356 vis = BotEntityVisible(bs->entitynum, bs->eye, bs->viewangles, 360, i);
357 if (vis > 0) return qtrue;
358 }
359 return qfalse;
360 }
361
362 /*
363 ==================
364 BotValidChatPosition
365 ==================
366 */
367 int BotValidChatPosition(bot_state_t *bs) {
368 vec3_t point, start, end, mins, maxs;
369 bsp_trace_t trace;
370
371 //if the bot is dead all positions are valid
372 if (BotIsDead(bs)) return qtrue;
373 if (BotIsObserver(bs)) return qtrue;
374 //never start chatting with a powerup
375 if (bs->inventory[INVENTORY_QUAD] ||
376 bs->inventory[INVENTORY_ENVIRONMENTSUIT] ||
377 bs->inventory[INVENTORY_HASTE] ||
378 bs->inventory[INVENTORY_INVISIBILITY] ||
379 bs->inventory[INVENTORY_REGEN] ||
380 bs->inventory[INVENTORY_FLIGHT]) return qfalse;
381 //must be on the ground
382 //if (bs->cur_ps.groundEntityNum != ENTITYNUM_NONE) return qfalse;
383 //do not chat if in lava or slime
384 VectorCopy(bs->origin, point);
385 point[2] -= 24;
386 if (trap_PointContents(point,bs->entitynum) & (CONTENTS_LAVA|CONTENTS_SLIME)) return qfalse;
387 //do not chat if under water
388 VectorCopy(bs->origin, point);
389 point[2] += 32;
390 if (trap_PointContents(point,bs->entitynum) & MASK_WATER) return qfalse;
391 //must be standing on the world entity
392 VectorCopy(bs->origin, start);
393 VectorCopy(bs->origin, end);
394 start[2] += 1;
395 end[2] -= 10;
396 trap_AAS_PresenceTypeBoundingBox(PRESENCE_CROUCH, mins, maxs);
397 BotAI_Trace(&trace, start, mins, maxs, end, bs->client, MASK_SOLID);
398 if (trace.ent != ENTITYNUM_WORLD) return qfalse;
399 //the bot is in a position where it can chat
400 return qtrue;
401 }
402
403 /*
404 ==================
405 BotChat_EnterGame
406 ==================
407 */
408 int BotChat_EnterGame(bot_state_t *bs) {
409 char name[32];
410 float rnd;
411
412 if (bot_nochat.integer) return qfalse;
413 if (bs->lastchat_time > FloatTime() - TIME_BETWEENCHATTING) return qfalse;
414 //don't chat in teamplay
415 if (TeamPlayIsOn()) return qfalse;
416 // don't chat in tournament mode
417 if (gametype == GT_TOURNAMENT) return qfalse;
418 rnd = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_CHAT_ENTEREXITGAME, 0, 1);
419 if (!bot_fastchat.integer) {
420 if (random() > rnd) return qfalse;
421 }
422 if (BotNumActivePlayers() <= 1) return qfalse;
423 if (!BotValidChatPosition(bs)) return qfalse;
424 BotAI_BotInitialChat(bs, "game_enter",
425 EasyClientName(bs->client, name, 32), // 0
426 BotRandomOpponentName(bs), // 1
427 "[invalid var]", // 2
428 "[invalid var]", // 3
429 BotMapTitle(), // 4
430 NULL);
431 bs->lastchat_time = FloatTime();
432 bs->chatto = CHAT_ALL;
433 return qtrue;
434 }
435
436 /*
437 ==================
438 BotChat_ExitGame
439 ==================
440 */
441 int BotChat_ExitGame(bot_state_t *bs) {
442 char name[32];
443 float rnd;
444
445 if (bot_nochat.integer) return qfalse;
446 if (bs->lastchat_time > FloatTime() - TIME_BETWEENCHATTING) return qfalse;
447 //don't chat in teamplay
448 if (TeamPlayIsOn()) return qfalse;
449 // don't chat in tournament mode
450 if (gametype == GT_TOURNAMENT) return qfalse;
451 rnd = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_CHAT_ENTEREXITGAME, 0, 1);
452 if (!bot_fastchat.integer) {
453 if (random() > rnd) return qfalse;
454 }
455 if (BotNumActivePlayers() <= 1) return qfalse;
456 //
457 BotAI_BotInitialChat(bs, "game_exit",
458 EasyClientName(bs->client, name, 32), // 0
459 BotRandomOpponentName(bs), // 1
460 "[invalid var]", // 2
461 "[invalid var]", // 3
462 BotMapTitle(), // 4
463 NULL);
464 bs->lastchat_time = FloatTime();
465 bs->chatto = CHAT_ALL;
466 return qtrue;
467 }
468
469 /*
470 ==================
471 BotChat_StartLevel
472 ==================
473 */
474 int BotChat_StartLevel(bot_state_t *bs) {
475 char name[32];
476 float rnd;
477
478 if (bot_nochat.integer) return qfalse;
479 if (BotIsObserver(bs)) return qfalse;
480 if (bs->lastchat_time > FloatTime() - TIME_BETWEENCHATTING) return qfalse;
481 //don't chat in teamplay
482 if (TeamPlayIsOn()) {
483 trap_EA_Command(bs->client, "vtaunt");
484 return qfalse;
485 }
486 // don't chat in tournament mode
487 if (gametype == GT_TOURNAMENT) return qfalse;
488 rnd = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_CHAT_STARTENDLEVEL, 0, 1);
489 if (!bot_fastchat.integer) {
490 if (random() > rnd) return qfalse;
491 }
492 if (BotNumActivePlayers() <= 1) return qfalse;
493 BotAI_BotInitialChat(bs, "level_start",
494 EasyClientName(bs->client, name, 32), // 0
495 NULL);
496 bs->lastchat_time = FloatTime();
497 bs->chatto = CHAT_ALL;
498 return qtrue;
499 }
500
501 /*
502 ==================
503 BotChat_EndLevel
504 ==================
505 */
506 int BotChat_EndLevel(bot_state_t *bs) {
507 char name[32];
508 float rnd;
509
510 if (bot_nochat.integer) return qfalse;
511 if (BotIsObserver(bs)) return qfalse;
512 if (bs->lastchat_time > FloatTime() - TIME_BETWEENCHATTING) return qfalse;
513 // teamplay
514 if (TeamPlayIsOn())
515 {
516 if (BotIsFirstInRankings(bs)) {
517 trap_EA_Command(bs->client, "vtaunt");
518 }
519 return qtrue;
520 }
521 // don't chat in tournament mode
522 if (gametype == GT_TOURNAMENT) return qfalse;
523 rnd = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_CHAT_STARTENDLEVEL, 0, 1);
524 if (!bot_fastchat.integer) {
525 if (random() > rnd) return qfalse;
526 }
527 if (BotNumActivePlayers() <= 1) return qfalse;
528 //
529 if (BotIsFirstInRankings(bs)) {
530 BotAI_BotInitialChat(bs, "level_end_victory",
531 EasyClientName(bs->client, name, 32), // 0
532 BotRandomOpponentName(bs), // 1
533 "[invalid var]", // 2
534 BotLastClientInRankings(), // 3
535 BotMapTitle(), // 4
536 NULL);
537 }
538 else if (BotIsLastInRankings(bs)) {
539 BotAI_BotInitialChat(bs, "level_end_lose",
540 EasyClientName(bs->client, name, 32), // 0
541 BotRandomOpponentName(bs), // 1
542 BotFirstClientInRankings(), // 2
543 "[invalid var]", // 3
544 BotMapTitle(), // 4
545 NULL);
546 }
547 else {
548 BotAI_BotInitialChat(bs, "level_end",
549 EasyClientName(bs->client, name, 32), // 0
550 BotRandomOpponentName(bs), // 1
551 BotFirstClientInRankings(), // 2
552 BotLastClientInRankings(), // 3
553 BotMapTitle(), // 4
554 NULL);
555 }
556 bs->lastchat_time = FloatTime();
557 bs->chatto = CHAT_ALL;
558 return qtrue;
559 }
560
561 /*
562 ==================
563 BotChat_Death
564 ==================
565 */
566 int BotChat_Death(bot_state_t *bs) {
567 char name[32];
568 float rnd;
569
570 if (bot_nochat.integer) return qfalse;
571 if (bs->lastchat_time > FloatTime() - TIME_BETWEENCHATTING) return qfalse;
572 rnd = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_CHAT_DEATH, 0, 1);
573 // don't chat in tournament mode
574 if (gametype == GT_TOURNAMENT) return qfalse;
575 //if fast chatting is off
576 if (!bot_fastchat.integer) {
577 if (random() > rnd) return qfalse;
578 }
579 if (BotNumActivePlayers() <= 1) return qfalse;
580 //
581 if (bs->lastkilledby >= 0 && bs->lastkilledby < MAX_CLIENTS)
582 EasyClientName(bs->lastkilledby, name, 32);
583 else
584 strcpy(name, "[world]");
585 //
586 if (TeamPlayIsOn() && BotSameTeam(bs, bs->lastkilledby)) {
587 if (bs->lastkilledby == bs->client) return qfalse;
588 BotAI_BotInitialChat(bs, "death_teammate", name, NULL);
589 bs->chatto = CHAT_TEAM;
590 }
591 else
592 {
593 //teamplay
594 if (TeamPlayIsOn()) {
595 trap_EA_Command(bs->client, "vtaunt");
596 return qtrue;
597 }
598 //
599 if (bs->botdeathtype == MOD_WATER)
600 BotAI_BotInitialChat(bs, "death_drown", BotRandomOpponentName(bs), NULL);
601 else if (bs->botdeathtype == MOD_SLIME)
602 BotAI_BotInitialChat(bs, "death_slime", BotRandomOpponentName(bs), NULL);
603 else if (bs->botdeathtype == MOD_LAVA)
604 BotAI_BotInitialChat(bs, "death_lava", BotRandomOpponentName(bs), NULL);
605 else if (bs->botdeathtype == MOD_FALLING)
606 BotAI_BotInitialChat(bs, "death_cratered", BotRandomOpponentName(bs), NULL);
607 else if (bs->botsuicide || //all other suicides by own weapon
608 bs->botdeathtype == MOD_CRUSH ||
609 bs->botdeathtype == MOD_SUICIDE ||
610 bs->botdeathtype == MOD_TARGET_LASER ||
611 bs->botdeathtype == MOD_TRIGGER_HURT ||
612 bs->botdeathtype == MOD_UNKNOWN)
613 BotAI_BotInitialChat(bs, "death_suicide", BotRandomOpponentName(bs), NULL);
614 else if (bs->botdeathtype == MOD_TELEFRAG)
615 BotAI_BotInitialChat(bs, "death_telefrag", name, NULL);
616 else if (bs->botdeathtype == MOD_KAMIKAZE && trap_BotNumInitialChats(bs->cs, "death_kamikaze"))
617 BotAI_BotInitialChat(bs, "death_kamikaze", name, NULL);
618 else {
619 if ((bs->botdeathtype == MOD_GAUNTLET ||
620 bs->botdeathtype == MOD_RAILGUN ||
621 bs->botdeathtype == MOD_BFG ||
622 bs->botdeathtype == MOD_BFG_SPLASH) && random() < 0.5) {
623
624 if (bs->botdeathtype == MOD_GAUNTLET)
625 BotAI_BotInitialChat(bs, "death_gauntlet",
626 name, // 0
627 BotWeaponNameForMeansOfDeath(bs->botdeathtype), // 1
628 NULL);
629 else if (bs->botdeathtype == MOD_RAILGUN)
630 BotAI_BotInitialChat(bs, "death_rail",
631 name, // 0
632 BotWeaponNameForMeansOfDeath(bs->botdeathtype), // 1
633 NULL);
634 else
635 BotAI_BotInitialChat(bs, "death_bfg",
636 name, // 0
637 BotWeaponNameForMeansOfDeath(bs->botdeathtype), // 1
638 NULL);
639 }
640 //choose between insult and praise
641 else if (random() < trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_CHAT_INSULT, 0, 1)) {
642 BotAI_BotInitialChat(bs, "death_insult",
643 name, // 0
644 BotWeaponNameForMeansOfDeath(bs->botdeathtype), // 1
645 NULL);
646 }
647 else {
648 BotAI_BotInitialChat(bs, "death_praise",
649 name, // 0
650 BotWeaponNameForMeansOfDeath(bs->botdeathtype), // 1
651 NULL);
652 }
653 }
654 bs->chatto = CHAT_ALL;
655 }
656 bs->lastchat_time = FloatTime();
657 return qtrue;
658 }
659
660 /*
661 ==================
662 BotChat_Kill
663 ==================
664 */
665 int BotChat_Kill(bot_state_t *bs) {
666 char name[32];
667 float rnd;
668
669 if (bot_nochat.integer) return qfalse;
670 if (bs->lastchat_time > FloatTime() - TIME_BETWEENCHATTING) return qfalse;
671 rnd = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_CHAT_KILL, 0, 1);
672 // don't chat in tournament mode
673 if (gametype == GT_TOURNAMENT) return qfalse;
674 //if fast chat is off
675 if (!bot_fastchat.integer) {
676 if (random() > rnd) return qfalse;
677 }
678 if (bs->lastkilledplayer == bs->client) return qfalse;
679 if (BotNumActivePlayers() <= 1) return qfalse;
680 if (!BotValidChatPosition(bs)) return qfalse;
681 //
682 if (BotVisibleEnemies(bs)) return qfalse;
683 //
684 EasyClientName(bs->lastkilledplayer, name, 32);
685 //
686 bs->chatto = CHAT_ALL;
687 if (TeamPlayIsOn() && BotSameTeam(bs, bs->lastkilledplayer)) {
688 BotAI_BotInitialChat(bs, "kill_teammate", name, NULL);
689 bs->chatto = CHAT_TEAM;
690 }
691 else
692 {
693 //don't chat in teamplay
694 if (TeamPlayIsOn()) {
695 trap_EA_Command(bs->client, "vtaunt");
696 return qfalse; // don't wait
697 }
698 //
699 if (bs->enemydeathtype == MOD_GAUNTLET) {
700 BotAI_BotInitialChat(bs, "kill_gauntlet", name, NULL);
701 }
702 else if (bs->enemydeathtype == MOD_RAILGUN) {
703 BotAI_BotInitialChat(bs, "kill_rail", name, NULL);
704 }
705 else if (bs->enemydeathtype == MOD_TELEFRAG) {
706 BotAI_BotInitialChat(bs, "kill_telefrag", name, NULL);
707 }
708 else if (bs->botdeathtype == MOD_KAMIKAZE && trap_BotNumInitialChats(bs->cs, "kill_kamikaze"))
709 BotAI_BotInitialChat(bs, "kill_kamikaze", name, NULL);
710 //choose between insult and praise
711 else if (random() < trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_CHAT_INSULT, 0, 1)) {
712 BotAI_BotInitialChat(bs, "kill_insult", name, NULL);
713 }
714 else {
715 BotAI_BotInitialChat(bs, "kill_praise", name, NULL);
716 }
717 }
718 bs->lastchat_time = FloatTime();
719 return qtrue;
720 }
721
722 /*
723 ==================
724 BotChat_EnemySuicide
725 ==================
726 */
727 int BotChat_EnemySuicide(bot_state_t *bs) {
728 char name[32];
729 float rnd;
730
731 if (bot_nochat.integer) return qfalse;
732 if (bs->lastchat_time > FloatTime() - TIME_BETWEENCHATTING) return qfalse;
733 if (BotNumActivePlayers() <= 1) return qfalse;
734 //
735 rnd = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_CHAT_ENEMYSUICIDE, 0, 1);
736 //don't chat in teamplay
737 if (TeamPlayIsOn()) return qfalse;
738 // don't chat in tournament mode
739 if (gametype == GT_TOURNAMENT) return qfalse;
740 //if fast chat is off
741 if (!bot_fastchat.integer) {
742 if (random() > rnd) return qfalse;
743 }
744 if (!BotValidChatPosition(bs)) return qfalse;
745 //
746 if (BotVisibleEnemies(bs)) return qfalse;
747 //
748 if (bs->enemy >= 0) EasyClientName(bs->enemy, name, 32);
749 else strcpy(name, "");
750 BotAI_BotInitialChat(bs, "enemy_suicide", name, NULL);
751 bs->lastchat_time = FloatTime();
752 bs->chatto = CHAT_ALL;
753 return qtrue;
754 }
755
756 /*
757 ==================
758 BotChat_HitTalking
759 ==================
760 */
761 int BotChat_HitTalking(bot_state_t *bs) {
762 char name[32], *weap;
763 int lasthurt_client;
764 float rnd;
765
766 if (bot_nochat.integer) return qfalse;
767 if (bs->lastchat_time > FloatTime() - TIME_BETWEENCHATTING) return qfalse;
768 if (BotNumActivePlayers() <= 1) return qfalse;
769 lasthurt_client = g_entities[bs->client].client->lasthurt_client;
770 if (!lasthurt_client) return qfalse;
771 if (lasthurt_client == bs->client) return qfalse;
772 //
773 if (lasthurt_client < 0 || lasthurt_client >= MAX_CLIENTS) return qfalse;
774 //
775 rnd = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_CHAT_HITTALKING, 0, 1);
776 //don't chat in teamplay
777 if (TeamPlayIsOn()) return qfalse;
778 // don't chat in tournament mode
779 if (gametype == GT_TOURNAMENT) return qfalse;
780 //if fast chat is off
781 if (!bot_fastchat.integer) {
782 if (random() > rnd * 0.5) return qfalse;
783 }
784 if (!BotValidChatPosition(bs)) return qfalse;
785 //
786 ClientName(g_entities[bs->client].client->lasthurt_client, name, sizeof(name));
787 weap = BotWeaponNameForMeansOfDeath(g_entities[bs->client].client->lasthurt_mod);
788 //
789 BotAI_BotInitialChat(bs, "hit_talking", name, weap, NULL);
790 bs->lastchat_time = FloatTime();
791 bs->chatto = CHAT_ALL;
792 return qtrue;
793 }
794
795 /*
796 ==================
797 BotChat_HitNoDeath
798 ==================
799 */
800 int BotChat_HitNoDeath(bot_state_t *bs) {
801 char name[32], *weap;
802 float rnd;
803 int lasthurt_client;
804 aas_entityinfo_t entinfo;
805
806 lasthurt_client = g_entities[bs->client].client->lasthurt_client;
807 if (!lasthurt_client) return qfalse;
808 if (lasthurt_client == bs->client) return qfalse;
809 //
810 if (lasthurt_client < 0 || lasthurt_client >= MAX_CLIENTS) return qfalse;
811 //
812 if (bot_nochat.integer) return qfalse;
813 if (bs->lastchat_time > FloatTime() - TIME_BETWEENCHATTING) return qfalse;
814 if (BotNumActivePlayers() <= 1) return qfalse;
815 rnd = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_CHAT_HITNODEATH, 0, 1);
816 //don't chat in teamplay
817 if (TeamPlayIsOn()) return qfalse;
818 // don't chat in tournament mode
819 if (gametype == GT_TOURNAMENT) return qfalse;
820 //if fast chat is off
821 if (!bot_fastchat.integer) {
822 if (random() > rnd * 0.5) return qfalse;
823 }
824 if (!BotValidChatPosition(bs)) return qfalse;
825 //
826 if (BotVisibleEnemies(bs)) return qfalse;
827 //
828 BotEntityInfo(bs->enemy, &entinfo);
829 if (EntityIsShooting(&entinfo)) return qfalse;
830 //
831 ClientName(lasthurt_client, name, sizeof(name));
832 weap = BotWeaponNameForMeansOfDeath(g_entities[bs->client].client->lasthurt_mod);
833 //
834 BotAI_BotInitialChat(bs, "hit_nodeath", name, weap, NULL);
835 bs->lastchat_time = FloatTime();
836 bs->chatto = CHAT_ALL;
837 return qtrue;
838 }
839
840 /*
841 ==================
842 BotChat_HitNoKill
843 ==================
844 */
845 int BotChat_HitNoKill(bot_state_t *bs) {
846 char name[32], *weap;
847 float rnd;
848 aas_entityinfo_t entinfo;
849
850 if (bot_nochat.integer) return qfalse;
851 if (bs->lastchat_time > FloatTime() - TIME_BETWEENCHATTING) return qfalse;
852 if (BotNumActivePlayers() <= 1) return qfalse;
853 rnd = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_CHAT_HITNOKILL, 0, 1);
854 //don't chat in teamplay
855 if (TeamPlayIsOn()) return qfalse;
856 // don't chat in tournament mode
857 if (gametype == GT_TOURNAMENT) return qfalse;
858 //if fast chat is off
859 if (!bot_fastchat.integer) {
860 if (random() > rnd * 0.5) return qfalse;
861 }
862 if (!BotValidChatPosition(bs)) return qfalse;
863 //
864 if (BotVisibleEnemies(bs)) return qfalse;
865 //
866 BotEntityInfo(bs->enemy, &entinfo);
867 if (EntityIsShooting(&entinfo)) return qfalse;
868 //
869 ClientName(bs->enemy, name, sizeof(name));
870 weap = BotWeaponNameForMeansOfDeath(g_entities[bs->enemy].client->lasthurt_mod);
871 //
872 BotAI_BotInitialChat(bs, "hit_nokill", name, weap, NULL);
873 bs->lastchat_time = FloatTime();
874 bs->chatto = CHAT_ALL;
875 return qtrue;
876 }
877
878 /*
879 ==================
880 BotChat_Random
881 ==================
882 */
883 int BotChat_Random(bot_state_t *bs) {
884 float rnd;
885 char name[32];
886
887 if (bot_nochat.integer) return qfalse;
888 if (BotIsObserver(bs)) return qfalse;
889 if (bs->lastchat_time > FloatTime() - TIME_BETWEENCHATTING) return qfalse;
890 // don't chat in tournament mode
891 if (gametype == GT_TOURNAMENT) return qfalse;
892 //don't chat when doing something important :)
893 if (bs->ltgtype == LTG_TEAMHELP ||
894 bs->ltgtype == LTG_TEAMACCOMPANY ||
895 bs->ltgtype == LTG_RUSHBASE) return qfalse;
896 //
897 rnd = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_CHAT_RANDOM, 0, 1);
898 if (random() > bs->thinktime * 0.1) return qfalse;
899 if (!bot_fastchat.integer) {
900 if (random() > rnd) return qfalse;
901 if (random() > 0.25) return qfalse;
902 }
903 if (BotNumActivePlayers() <= 1) return qfalse;
904 //
905 if (!BotValidChatPosition(bs)) return qfalse;
906 //
907 if (BotVisibleEnemies(bs)) return qfalse;
908 //
909 if (bs->lastkilledplayer == bs->client) {
910 Q_strncpyz(name, BotRandomOpponentName(bs),sizeof(name));
911 }
912 else {
913 EasyClientName(bs->lastkilledplayer, name, sizeof(name));
914 }
915 if (TeamPlayIsOn()) {
916 trap_EA_Command(bs->client, "vtaunt");
917 return qfalse; // don't wait
918 }
919 //
920 if (random() < trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_CHAT_MISC, 0, 1)) {
921 BotAI_BotInitialChat(bs, "random_misc",
922 BotRandomOpponentName(bs), // 0
923 name, // 1
924 "[invalid var]", // 2
925 "[invalid var]", // 3
926 BotMapTitle(), // 4
927 BotRandomWeaponName(), // 5
928 NULL);
929 }
930 else {
931 BotAI_BotInitialChat(bs, "random_insult",
932 BotRandomOpponentName(bs), // 0
933 name, // 1
934 "[invalid var]", // 2
935 "[invalid var]", // 3
936 BotMapTitle(), // 4
937 BotRandomWeaponName(), // 5
938 NULL);
939 }
940 bs->lastchat_time = FloatTime();
941 bs->chatto = CHAT_ALL;
942 return qtrue;
943 }
944
945 /*
946 ==================
947 BotChatTime
948 ==================
949 */
950 float BotChatTime(bot_state_t *bs) {
951 int cpm;
952
953 cpm = trap_Characteristic_BInteger(bs->character, CHARACTERISTIC_CHAT_CPM, 1, 4000);
954
955 return 2.0; //(float) trap_BotChatLength(bs->cs) * 30 / cpm;
956 }
957
958 /*
959 ==================
960 BotChatTest
961 ==================
962 */
963 void BotChatTest(bot_state_t *bs) {
964
965 char name[32];
966 char *weap;
967 int num, i;
968
969 if (bot_nochat.integer) return;
970
971 num = trap_BotNumInitialChats(bs->cs, "game_enter");
972 for (i = 0; i < num; i++)
973 {
974 BotAI_BotInitialChat(bs, "game_enter",
975 EasyClientName(bs->client, name, 32), // 0
976 BotRandomOpponentName(bs), // 1
977 "[invalid var]", // 2
978 "[invalid var]", // 3
979 BotMapTitle(), // 4
980 NULL);
981 trap_BotEnterChat(bs->cs, 0, CHAT_ALL);
982 }
983 num = trap_BotNumInitialChats(bs->cs, "game_exit");
984 for (i = 0; i < num; i++)
985 {
986 BotAI_BotInitialChat(bs, "game_exit",
987 EasyClientName(bs->client, name, 32), // 0
988 BotRandomOpponentName(bs), // 1
989 "[invalid var]", // 2
990 "[invalid var]", // 3
991 BotMapTitle(), // 4
992 NULL);
993 trap_BotEnterChat(bs->cs, 0, CHAT_ALL);
994 }
995 num = trap_BotNumInitialChats(bs->cs, "level_start");
996 for (i = 0; i < num; i++)
997 {
998 BotAI_BotInitialChat(bs, "level_start",
999 EasyClientName(bs->client, name, 32), // 0
1000 NULL);
1001 trap_BotEnterChat(bs->cs, 0, CHAT_ALL);
1002 }
1003 num = trap_BotNumInitialChats(bs->cs, "level_end_victory");
1004 for (i = 0; i < num; i++)
1005 {
1006 BotAI_BotInitialChat(bs, "level_end_victory",
1007 EasyClientName(bs->client, name, 32), // 0
1008 BotRandomOpponentName(bs), // 1
1009 BotFirstClientInRankings(), // 2
1010 BotLastClientInRankings(), // 3
1011 BotMapTitle(), // 4
1012 NULL);
1013 trap_BotEnterChat(bs->cs, 0, CHAT_ALL);
1014 }
1015 num = trap_BotNumInitialChats(bs->cs, "level_end_lose");
1016 for (i = 0; i < num; i++)
1017 {
1018 BotAI_BotInitialChat(bs, "level_end_lose",
1019 EasyClientName(bs->client, name, 32), // 0
1020 BotRandomOpponentName(bs), // 1
1021 BotFirstClientInRankings(), // 2
1022 BotLastClientInRankings(), // 3
1023 BotMapTitle(), // 4
1024 NULL);
1025 trap_BotEnterChat(bs->cs, 0, CHAT_ALL);
1026 }
1027 num = trap_BotNumInitialChats(bs->cs, "level_end");
1028 for (i = 0; i < num; i++)
1029 {
1030 BotAI_BotInitialChat(bs, "level_end",
1031 EasyClientName(bs->client, name, 32), // 0
1032 BotRandomOpponentName(bs), // 1
1033 BotFirstClientInRankings(), // 2
1034 BotLastClientInRankings(), // 3
1035 BotMapTitle(), // 4
1036 NULL);
1037 trap_BotEnterChat(bs->cs, 0, CHAT_ALL);
1038 }
1039 EasyClientName(bs->lastkilledby, name, sizeof(name));
1040 num = trap_BotNumInitialChats(bs->cs, "death_drown");
1041 for (i = 0; i < num; i++)
1042 {
1043 //
1044 BotAI_BotInitialChat(bs, "death_drown", name, NULL);
1045 trap_BotEnterChat(bs->cs, 0, CHAT_ALL);
1046 }
1047 num = trap_BotNumInitialChats(bs->cs, "death_slime");
1048 for (i = 0; i < num; i++)
1049 {
1050 BotAI_BotInitialChat(bs, "death_slime", name, NULL);
1051 trap_BotEnterChat(bs->cs, 0, CHAT_ALL);
1052 }
1053 num = trap_BotNumInitialChats(bs->cs, "death_lava");
1054 for (i = 0; i < num; i++)
1055 {
1056 BotAI_BotInitialChat(bs, "death_lava", name, NULL);
1057 trap_BotEnterChat(bs->cs, 0, CHAT_ALL);
1058 }
1059 num = trap_BotNumInitialChats(bs->cs, "death_cratered");
1060 for (i = 0; i < num; i++)
1061 {
1062 BotAI_BotInitialChat(bs, "death_cratered", name, NULL);
1063 trap_BotEnterChat(bs->cs, 0, CHAT_ALL);
1064 }
1065 num = trap_BotNumInitialChats(bs->cs, "death_suicide");
1066 for (i = 0; i < num; i++)
1067 {
1068 BotAI_BotInitialChat(bs, "death_suicide", name, NULL);
1069 trap_BotEnterChat(bs->cs, 0, CHAT_ALL);
1070 }
1071 num = trap_BotNumInitialChats(bs->cs, "death_telefrag");
1072 for (i = 0; i < num; i++)
1073 {
1074 BotAI_BotInitialChat(bs, "death_telefrag", name, NULL);
1075 trap_BotEnterChat(bs->cs, 0, CHAT_ALL);
1076 }
1077 num = trap_BotNumInitialChats(bs->cs, "death_gauntlet");
1078 for (i = 0; i < num; i++)
1079 {
1080 BotAI_BotInitialChat(bs, "death_gauntlet",
1081 name, // 0
1082 BotWeaponNameForMeansOfDeath(bs->botdeathtype), // 1
1083 NULL);
1084 trap_BotEnterChat(bs->cs, 0, CHAT_ALL);
1085 }
1086 num = trap_BotNumInitialChats(bs->cs, "death_rail");
1087 for (i = 0; i < num; i++)
1088 {
1089 BotAI_BotInitialChat(bs, "death_rail",
1090 name, // 0
1091 BotWeaponNameForMeansOfDeath(bs->botdeathtype), // 1
1092 NULL);
1093 trap_BotEnterChat(bs->cs, 0, CHAT_ALL);
1094 }
1095 num = trap_BotNumInitialChats(bs->cs, "death_bfg");
1096 for (i = 0; i < num; i++)
1097 {
1098 BotAI_BotInitialChat(bs, "death_bfg",
1099 name, // 0
1100 BotWeaponNameForMeansOfDeath(bs->botdeathtype), // 1
1101 NULL);
1102 trap_BotEnterChat(bs->cs, 0, CHAT_ALL);
1103 }
1104 num = trap_BotNumInitialChats(bs->cs, "death_insult");
1105 for (i = 0; i < num; i++)
1106 {
1107 BotAI_BotInitialChat(bs, "death_insult",
1108 name, // 0
1109 BotWeaponNameForMeansOfDeath(bs->botdeathtype), // 1
1110 NULL);
1111 trap_BotEnterChat(bs->cs, 0, CHAT_ALL);
1112 }
1113 num = trap_BotNumInitialChats(bs->cs, "death_praise");
1114 for (i = 0; i < num; i++)
1115 {
1116 BotAI_BotInitialChat(bs, "death_praise",
1117 name, // 0
1118 BotWeaponNameForMeansOfDeath(bs->botdeathtype), // 1
1119 NULL);
1120 trap_BotEnterChat(bs->cs, 0, CHAT_ALL);
1121 }
1122 //
1123 EasyClientName(bs->lastkilledplayer, name, 32);
1124 //
1125 num = trap_BotNumInitialChats(bs->cs, "kill_gauntlet");
1126 for (i = 0; i < num; i++)
1127 {
1128 //
1129 BotAI_BotInitialChat(bs, "kill_gauntlet", name, NULL);
1130 trap_BotEnterChat(bs->cs, 0, CHAT_ALL);
1131 }
1132 num = trap_BotNumInitialChats(bs->cs, "kill_rail");
1133 for (i = 0; i < num; i++)
1134 {
1135 BotAI_BotInitialChat(bs, "kill_rail", name, NULL);
1136 trap_BotEnterChat(bs->cs, 0, CHAT_ALL);
1137 }
1138 num = trap_BotNumInitialChats(bs->cs, "kill_telefrag");
1139 for (i = 0; i < num; i++)
1140 {
1141 BotAI_BotInitialChat(bs, "kill_telefrag", name, NULL);
1142 trap_BotEnterChat(bs->cs, 0, CHAT_ALL);
1143 }
1144 num = trap_BotNumInitialChats(bs->cs, "kill_insult");
1145 for (i = 0; i < num; i++)
1146 {
1147 BotAI_BotInitialChat(bs, "kill_insult", name, NULL);
1148 trap_BotEnterChat(bs->cs, 0, CHAT_ALL);
1149 }
1150 num = trap_BotNumInitialChats(bs->cs, "kill_praise");
1151 for (i = 0; i < num; i++)
1152 {
1153 BotAI_BotInitialChat(bs, "kill_praise", name, NULL);
1154 trap_BotEnterChat(bs->cs, 0, CHAT_ALL);
1155 }
1156 num = trap_BotNumInitialChats(bs->cs, "enemy_suicide");
1157 for (i = 0; i < num; i++)
1158 {
1159 BotAI_BotInitialChat(bs, "enemy_suicide", name, NULL);
1160 trap_BotEnterChat(bs->cs, 0, CHAT_ALL);
1161 }
1162 ClientName(g_entities[bs->client].client->lasthurt_client, name, sizeof(name));
1163 weap = BotWeaponNameForMeansOfDeath(g_entities[bs->client].client->lasthurt_client);
1164 num = trap_BotNumInitialChats(bs->cs, "hit_talking");
1165 for (i = 0; i < num; i++)
1166 {
1167 BotAI_BotInitialChat(bs, "hit_talking", name, weap, NULL);
1168 trap_BotEnterChat(bs->cs, 0, CHAT_ALL);
1169 }
1170 num = trap_BotNumInitialChats(bs->cs, "hit_nodeath");
1171 for (i = 0; i < num; i++)
1172 {
1173 BotAI_BotInitialChat(bs, "hit_nodeath", name, weap, NULL);
1174 trap_BotEnterChat(bs->cs, 0, CHAT_ALL);
1175 }
1176 num = trap_BotNumInitialChats(bs->cs, "hit_nokill");
1177 for (i = 0; i < num; i++)
1178 {
1179 BotAI_BotInitialChat(bs, "hit_nokill", name, weap, NULL);
1180 trap_BotEnterChat(bs->cs, 0, CHAT_ALL);
1181 }
1182 //
1183 if (bs->lastkilledplayer == bs->client) {
1184 Q_strncpyz(name, BotRandomOpponentName(bs), sizeof(name));
1185 }
1186 else {
1187 EasyClientName(bs->lastkilledplayer, name, sizeof(name));
1188 }
1189 //
1190 num = trap_BotNumInitialChats(bs->cs, "random_misc");
1191 for (i = 0; i < num; i++)
1192 {
1193 //
1194 BotAI_BotInitialChat(bs, "random_misc",
1195 BotRandomOpponentName(bs), // 0
1196 name, // 1
1197 "[invalid var]", // 2
1198 "[invalid var]", // 3
1199 BotMapTitle(), // 4
1200 BotRandomWeaponName(), // 5
1201 NULL);
1202 trap_BotEnterChat(bs->cs, 0, CHAT_ALL);
1203 }
1204 num = trap_BotNumInitialChats(bs->cs, "random_insult");
1205 for (i = 0; i < num; i++)
1206 {
1207 BotAI_BotInitialChat(bs, "random_insult",
1208 BotRandomOpponentName(bs), // 0
1209 name, // 1
1210 "[invalid var]", // 2
1211 "[invalid var]", // 3
1212 BotMapTitle(), // 4
1213 BotRandomWeaponName(), // 5
1214 NULL);
1215 trap_BotEnterChat(bs->cs, 0, CHAT_ALL);
1216 }
1217 }