Debian Codegraph @

code/game/ai_chat.c

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