📄 ai_chat.c
字号:
/*
===========================================================================
Copyright (C) 1999-2005 Id Software, Inc.
This file is part of Quake III Arena source code.
Quake III Arena source code is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
Quake III Arena source code is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
//
/*****************************************************************************
* name: ai_chat.c
*
* desc: Quake3 bot AI
*
* $Archive: /MissionPack/code/game/ai_chat.c $
*
*****************************************************************************/
#include "g_local.h"
#include "botlib.h"
#include "be_aas.h"
#include "be_ea.h"
#include "be_ai_char.h"
#include "be_ai_chat.h"
#include "be_ai_gen.h"
#include "be_ai_goal.h"
#include "be_ai_move.h"
#include "be_ai_weap.h"
//
#include "ai_main.h"
#include "ai_dmq3.h"
#include "ai_chat.h"
#include "ai_cmd.h"
#include "ai_dmnet.h"
//
#include "chars.h" //characteristics
#include "inv.h" //indexes into the inventory
#include "syn.h" //synonyms
#include "match.h" //string matching types and vars
// for the voice chats
#ifdef MISSIONPACK // bk001205
#include "../../ui/menudef.h"
#endif
#define TIME_BETWEENCHATTING 25
/*
==================
BotNumActivePlayers
==================
*/
int BotNumActivePlayers(void) {
int i, num;
char buf[MAX_INFO_STRING];
static int maxclients;
if (!maxclients)
maxclients = trap_Cvar_VariableIntegerValue("sv_maxclients");
num = 0;
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) {
trap_GetConfigstring(CS_PLAYERS+i, buf, sizeof(buf));
//if no config string or no name
if (!strlen(buf) || !strlen(Info_ValueForKey(buf, "n"))) continue;
//skip spectators
if (atoi(Info_ValueForKey(buf, "t")) == TEAM_SPECTATOR) continue;
//
num++;
}
return num;
}
/*
==================
BotIsFirstInRankings
==================
*/
int BotIsFirstInRankings(bot_state_t *bs) {
int i, score;
char buf[MAX_INFO_STRING];
static int maxclients;
playerState_t ps;
if (!maxclients)
maxclients = trap_Cvar_VariableIntegerValue("sv_maxclients");
score = bs->cur_ps.persistant[PERS_SCORE];
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) {
trap_GetConfigstring(CS_PLAYERS+i, buf, sizeof(buf));
//if no config string or no name
if (!strlen(buf) || !strlen(Info_ValueForKey(buf, "n"))) continue;
//skip spectators
if (atoi(Info_ValueForKey(buf, "t")) == TEAM_SPECTATOR) continue;
//
BotAI_GetClientState(i, &ps);
if (score < ps.persistant[PERS_SCORE]) return qfalse;
}
return qtrue;
}
/*
==================
BotIsLastInRankings
==================
*/
int BotIsLastInRankings(bot_state_t *bs) {
int i, score;
char buf[MAX_INFO_STRING];
static int maxclients;
playerState_t ps;
if (!maxclients)
maxclients = trap_Cvar_VariableIntegerValue("sv_maxclients");
score = bs->cur_ps.persistant[PERS_SCORE];
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) {
trap_GetConfigstring(CS_PLAYERS+i, buf, sizeof(buf));
//if no config string or no name
if (!strlen(buf) || !strlen(Info_ValueForKey(buf, "n"))) continue;
//skip spectators
if (atoi(Info_ValueForKey(buf, "t")) == TEAM_SPECTATOR) continue;
//
BotAI_GetClientState(i, &ps);
if (score > ps.persistant[PERS_SCORE]) return qfalse;
}
return qtrue;
}
/*
==================
BotFirstClientInRankings
==================
*/
char *BotFirstClientInRankings(void) {
int i, bestscore, bestclient;
char buf[MAX_INFO_STRING];
static char name[32];
static int maxclients;
playerState_t ps;
if (!maxclients)
maxclients = trap_Cvar_VariableIntegerValue("sv_maxclients");
bestscore = -999999;
bestclient = 0;
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) {
trap_GetConfigstring(CS_PLAYERS+i, buf, sizeof(buf));
//if no config string or no name
if (!strlen(buf) || !strlen(Info_ValueForKey(buf, "n"))) continue;
//skip spectators
if (atoi(Info_ValueForKey(buf, "t")) == TEAM_SPECTATOR) continue;
//
BotAI_GetClientState(i, &ps);
if (ps.persistant[PERS_SCORE] > bestscore) {
bestscore = ps.persistant[PERS_SCORE];
bestclient = i;
}
}
EasyClientName(bestclient, name, 32);
return name;
}
/*
==================
BotLastClientInRankings
==================
*/
char *BotLastClientInRankings(void) {
int i, worstscore, bestclient;
char buf[MAX_INFO_STRING];
static char name[32];
static int maxclients;
playerState_t ps;
if (!maxclients)
maxclients = trap_Cvar_VariableIntegerValue("sv_maxclients");
worstscore = 999999;
bestclient = 0;
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) {
trap_GetConfigstring(CS_PLAYERS+i, buf, sizeof(buf));
//if no config string or no name
if (!strlen(buf) || !strlen(Info_ValueForKey(buf, "n"))) continue;
//skip spectators
if (atoi(Info_ValueForKey(buf, "t")) == TEAM_SPECTATOR) continue;
//
BotAI_GetClientState(i, &ps);
if (ps.persistant[PERS_SCORE] < worstscore) {
worstscore = ps.persistant[PERS_SCORE];
bestclient = i;
}
}
EasyClientName(bestclient, name, 32);
return name;
}
/*
==================
BotRandomOpponentName
==================
*/
char *BotRandomOpponentName(bot_state_t *bs) {
int i, count;
char buf[MAX_INFO_STRING];
int opponents[MAX_CLIENTS], numopponents;
static int maxclients;
static char name[32];
if (!maxclients)
maxclients = trap_Cvar_VariableIntegerValue("sv_maxclients");
numopponents = 0;
opponents[0] = 0;
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) {
if (i == bs->client) continue;
//
trap_GetConfigstring(CS_PLAYERS+i, buf, sizeof(buf));
//if no config string or no name
if (!strlen(buf) || !strlen(Info_ValueForKey(buf, "n"))) continue;
//skip spectators
if (atoi(Info_ValueForKey(buf, "t")) == TEAM_SPECTATOR) continue;
//skip team mates
if (BotSameTeam(bs, i)) continue;
//
opponents[numopponents] = i;
numopponents++;
}
count = random() * numopponents;
for (i = 0; i < numopponents; i++) {
count--;
if (count <= 0) {
EasyClientName(opponents[i], name, sizeof(name));
return name;
}
}
EasyClientName(opponents[0], name, sizeof(name));
return name;
}
/*
==================
BotMapTitle
==================
*/
char *BotMapTitle(void) {
char info[1024];
static char mapname[128];
trap_GetServerinfo(info, sizeof(info));
strncpy(mapname, Info_ValueForKey( info, "mapname" ), sizeof(mapname)-1);
mapname[sizeof(mapname)-1] = '\0';
return mapname;
}
/*
==================
BotWeaponNameForMeansOfDeath
==================
*/
char *BotWeaponNameForMeansOfDeath(int mod) {
switch(mod) {
case MOD_SHOTGUN: return "Shotgun";
case MOD_GAUNTLET: return "Gauntlet";
case MOD_MACHINEGUN: return "Machinegun";
case MOD_GRENADE:
case MOD_GRENADE_SPLASH: return "Grenade Launcher";
case MOD_ROCKET:
case MOD_ROCKET_SPLASH: return "Rocket Launcher";
case MOD_PLASMA:
case MOD_PLASMA_SPLASH: return "Plasmagun";
case MOD_RAILGUN: return "Railgun";
case MOD_LIGHTNING: return "Lightning Gun";
case MOD_BFG:
case MOD_BFG_SPLASH: return "BFG10K";
#ifdef MISSIONPACK
case MOD_NAIL: return "Nailgun";
case MOD_CHAINGUN: return "Chaingun";
case MOD_PROXIMITY_MINE: return "Proximity Launcher";
case MOD_KAMIKAZE: return "Kamikaze";
case MOD_JUICED: return "Prox mine";
#endif
case MOD_GRAPPLE: return "Grapple";
default: return "[unknown weapon]";
}
}
/*
==================
BotRandomWeaponName
==================
*/
char *BotRandomWeaponName(void) {
int rnd;
#ifdef MISSIONPACK
rnd = random() * 11.9;
#else
rnd = random() * 8.9;
#endif
switch(rnd) {
case 0: return "Gauntlet";
case 1: return "Shotgun";
case 2: return "Machinegun";
case 3: return "Grenade Launcher";
case 4: return "Rocket Launcher";
case 5: return "Plasmagun";
case 6: return "Railgun";
case 7: return "Lightning Gun";
#ifdef MISSIONPACK
case 8: return "Nailgun";
case 9: return "Chaingun";
case 10: return "Proximity Launcher";
#endif
default: return "BFG10K";
}
}
/*
==================
BotVisibleEnemies
==================
*/
int BotVisibleEnemies(bot_state_t *bs) {
float vis;
int i;
aas_entityinfo_t entinfo;
for (i = 0; i < MAX_CLIENTS; i++) {
if (i == bs->client) continue;
//
BotEntityInfo(i, &entinfo);
//
if (!entinfo.valid) continue;
//if the enemy isn't dead and the enemy isn't the bot self
if (EntityIsDead(&entinfo) || entinfo.number == bs->entitynum) continue;
//if the enemy is invisible and not shooting
if (EntityIsInvisible(&entinfo) && !EntityIsShooting(&entinfo)) {
continue;
}
//if on the same team
if (BotSameTeam(bs, i)) continue;
//check if the enemy is visible
vis = BotEntityVisible(bs->entitynum, bs->eye, bs->viewangles, 360, i);
if (vis > 0) return qtrue;
}
return qfalse;
}
/*
==================
BotValidChatPosition
==================
*/
int BotValidChatPosition(bot_state_t *bs) {
vec3_t point, start, end, mins, maxs;
bsp_trace_t trace;
//if the bot is dead all positions are valid
if (BotIsDead(bs)) return qtrue;
//never start chatting with a powerup
if (bs->inventory[INVENTORY_QUAD] ||
bs->inventory[INVENTORY_HASTE] ||
bs->inventory[INVENTORY_INVISIBILITY] ||
bs->inventory[INVENTORY_REGEN] ||
bs->inventory[INVENTORY_FLIGHT]) return qfalse;
//must be on the ground
//if (bs->cur_ps.groundEntityNum != ENTITYNUM_NONE) return qfalse;
//do not chat if in lava or slime
VectorCopy(bs->origin, point);
point[2] -= 24;
if (trap_PointContents(point,bs->entitynum) & (CONTENTS_LAVA|CONTENTS_SLIME)) return qfalse;
//do not chat if under water
VectorCopy(bs->origin, point);
point[2] += 32;
if (trap_PointContents(point,bs->entitynum) & MASK_WATER) return qfalse;
//must be standing on the world entity
VectorCopy(bs->origin, start);
VectorCopy(bs->origin, end);
start[2] += 1;
end[2] -= 10;
trap_AAS_PresenceTypeBoundingBox(PRESENCE_CROUCH, mins, maxs);
BotAI_Trace(&trace, start, mins, maxs, end, bs->client, MASK_SOLID);
if (trace.ent != ENTITYNUM_WORLD) return qfalse;
//the bot is in a position where it can chat
return qtrue;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -