Debian Codegraph @

code/game/ai_chat.c

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