mirror of
https://github.com/ioquake/ioq3.git
synced 2024-11-10 07:11:46 +00:00
Stop caching sv_maxclients in bot code
This commit is contained in:
parent
d1631d6ea3
commit
74aa4268b2
5 changed files with 28 additions and 83 deletions
|
@ -68,13 +68,9 @@ 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++) {
|
||||
for (i = 0; i < level.maxclients; 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;
|
||||
|
@ -94,14 +90,10 @@ 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++) {
|
||||
for (i = 0; i < level.maxclients; 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;
|
||||
|
@ -122,14 +114,10 @@ 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++) {
|
||||
for (i = 0; i < level.maxclients; 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;
|
||||
|
@ -151,15 +139,11 @@ 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++) {
|
||||
for (i = 0; i < level.maxclients; 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;
|
||||
|
@ -185,15 +169,11 @@ 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++) {
|
||||
for (i = 0; i < level.maxclients; 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;
|
||||
|
@ -219,15 +199,11 @@ 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++) {
|
||||
for (i = 0; i < level.maxclients; i++) {
|
||||
if (i == bs->client) continue;
|
||||
//
|
||||
trap_GetConfigstring(CS_PLAYERS+i, buf, sizeof(buf));
|
||||
|
|
|
@ -237,15 +237,12 @@ FindClientByName
|
|||
int FindClientByName(char *name) {
|
||||
int i;
|
||||
char buf[MAX_INFO_STRING];
|
||||
static int maxclients;
|
||||
|
||||
if (!maxclients)
|
||||
maxclients = trap_Cvar_VariableIntegerValue("sv_maxclients");
|
||||
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) {
|
||||
for (i = 0; i < level.maxclients; i++) {
|
||||
ClientName(i, buf, sizeof(buf));
|
||||
if (!Q_stricmp(buf, name)) return i;
|
||||
}
|
||||
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) {
|
||||
for (i = 0; i < level.maxclients; i++) {
|
||||
ClientName(i, buf, sizeof(buf));
|
||||
if (stristr(buf, name)) return i;
|
||||
}
|
||||
|
@ -260,16 +257,13 @@ FindEnemyByName
|
|||
int FindEnemyByName(bot_state_t *bs, char *name) {
|
||||
int i;
|
||||
char buf[MAX_INFO_STRING];
|
||||
static int maxclients;
|
||||
|
||||
if (!maxclients)
|
||||
maxclients = trap_Cvar_VariableIntegerValue("sv_maxclients");
|
||||
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) {
|
||||
for (i = 0; i < level.maxclients; i++) {
|
||||
if (BotSameTeam(bs, i)) continue;
|
||||
ClientName(i, buf, sizeof(buf));
|
||||
if (!Q_stricmp(buf, name)) return i;
|
||||
}
|
||||
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) {
|
||||
for (i = 0; i < level.maxclients; i++) {
|
||||
if (BotSameTeam(bs, i)) continue;
|
||||
ClientName(i, buf, sizeof(buf));
|
||||
if (stristr(buf, name)) return i;
|
||||
|
@ -285,13 +279,9 @@ NumPlayersOnSameTeam
|
|||
int NumPlayersOnSameTeam(bot_state_t *bs) {
|
||||
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++) {
|
||||
for (i = 0; i < level.maxclients; i++) {
|
||||
trap_GetConfigstring(CS_PLAYERS+i, buf, MAX_INFO_STRING);
|
||||
if (strlen(buf)) {
|
||||
if (BotSameTeam(bs, i+1)) num++;
|
||||
|
|
|
@ -72,7 +72,6 @@ bot_waypoint_t *botai_freewaypoints;
|
|||
|
||||
//NOTE: not using a cvars which can be updated because the game should be reloaded anyway
|
||||
int gametype; //game type
|
||||
int maxclients; //maximum number of clients
|
||||
|
||||
vmCvar_t bot_grapple;
|
||||
vmCvar_t bot_rocketjump;
|
||||
|
@ -1427,11 +1426,8 @@ ClientFromName
|
|||
int ClientFromName(char *name) {
|
||||
int i;
|
||||
char buf[MAX_INFO_STRING];
|
||||
static int maxclients;
|
||||
|
||||
if (!maxclients)
|
||||
maxclients = trap_Cvar_VariableIntegerValue("sv_maxclients");
|
||||
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) {
|
||||
for (i = 0; i < level.maxclients; i++) {
|
||||
trap_GetConfigstring(CS_PLAYERS+i, buf, sizeof(buf));
|
||||
Q_CleanStr( buf );
|
||||
if (!Q_stricmp(Info_ValueForKey(buf, "n"), name)) return i;
|
||||
|
@ -1447,11 +1443,8 @@ ClientOnSameTeamFromName
|
|||
int ClientOnSameTeamFromName(bot_state_t *bs, char *name) {
|
||||
int i;
|
||||
char buf[MAX_INFO_STRING];
|
||||
static int maxclients;
|
||||
|
||||
if (!maxclients)
|
||||
maxclients = trap_Cvar_VariableIntegerValue("sv_maxclients");
|
||||
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) {
|
||||
for (i = 0; i < level.maxclients; i++) {
|
||||
if (!BotSameTeam(bs, i))
|
||||
continue;
|
||||
trap_GetConfigstring(CS_PLAYERS+i, buf, sizeof(buf));
|
||||
|
@ -2983,7 +2976,7 @@ int BotFindEnemy(bot_state_t *bs, int curenemy) {
|
|||
}
|
||||
#endif
|
||||
//
|
||||
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) {
|
||||
for (i = 0; i < level.maxclients; i++) {
|
||||
|
||||
if (i == bs->client) continue;
|
||||
//if it's the current enemy
|
||||
|
@ -3062,7 +3055,7 @@ int BotTeamFlagCarrierVisible(bot_state_t *bs) {
|
|||
float vis;
|
||||
aas_entityinfo_t entinfo;
|
||||
|
||||
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) {
|
||||
for (i = 0; i < level.maxclients; i++) {
|
||||
if (i == bs->client)
|
||||
continue;
|
||||
//
|
||||
|
@ -3095,7 +3088,7 @@ int BotTeamFlagCarrier(bot_state_t *bs) {
|
|||
int i;
|
||||
aas_entityinfo_t entinfo;
|
||||
|
||||
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) {
|
||||
for (i = 0; i < level.maxclients; i++) {
|
||||
if (i == bs->client)
|
||||
continue;
|
||||
//
|
||||
|
@ -3125,7 +3118,7 @@ int BotEnemyFlagCarrierVisible(bot_state_t *bs) {
|
|||
float vis;
|
||||
aas_entityinfo_t entinfo;
|
||||
|
||||
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) {
|
||||
for (i = 0; i < level.maxclients; i++) {
|
||||
if (i == bs->client)
|
||||
continue;
|
||||
//
|
||||
|
@ -3164,7 +3157,7 @@ void BotVisibleTeamMatesAndEnemies(bot_state_t *bs, int *teammates, int *enemies
|
|||
*teammates = 0;
|
||||
if (enemies)
|
||||
*enemies = 0;
|
||||
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) {
|
||||
for (i = 0; i < level.maxclients; i++) {
|
||||
if (i == bs->client)
|
||||
continue;
|
||||
//
|
||||
|
@ -3206,7 +3199,7 @@ int BotTeamCubeCarrierVisible(bot_state_t *bs) {
|
|||
float vis;
|
||||
aas_entityinfo_t entinfo;
|
||||
|
||||
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) {
|
||||
for (i = 0; i < level.maxclients; i++) {
|
||||
if (i == bs->client) continue;
|
||||
//
|
||||
BotEntityInfo(i, &entinfo);
|
||||
|
@ -3235,7 +3228,7 @@ int BotEnemyCubeCarrierVisible(bot_state_t *bs) {
|
|||
float vis;
|
||||
aas_entityinfo_t entinfo;
|
||||
|
||||
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) {
|
||||
for (i = 0; i < level.maxclients; i++) {
|
||||
if (i == bs->client)
|
||||
continue;
|
||||
//
|
||||
|
@ -3706,7 +3699,7 @@ void BotMapScripts(bot_state_t *bs) {
|
|||
}
|
||||
shootbutton = qfalse;
|
||||
//if an enemy is below this bounding box then shoot the button
|
||||
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) {
|
||||
for (i = 0; i < level.maxclients; i++) {
|
||||
|
||||
if (i == bs->client) continue;
|
||||
//
|
||||
|
@ -5403,7 +5396,6 @@ void BotSetupDeathmatchAI(void) {
|
|||
char model[128];
|
||||
|
||||
gametype = trap_Cvar_VariableIntegerValue("g_gametype");
|
||||
maxclients = trap_Cvar_VariableIntegerValue("sv_maxclients");
|
||||
|
||||
trap_Cvar_Register(&bot_rocketjump, "bot_rocketjump", "1", 0);
|
||||
trap_Cvar_Register(&bot_grapple, "bot_grapple", "0", 0);
|
||||
|
|
|
@ -392,7 +392,7 @@ void BotTeamplayReport(void) {
|
|||
char buf[MAX_INFO_STRING];
|
||||
|
||||
BotAI_Print(PRT_MESSAGE, S_COLOR_RED"RED\n");
|
||||
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) {
|
||||
for (i = 0; i < level.maxclients; i++) {
|
||||
//
|
||||
if ( !botstates[i] || !botstates[i]->inuse ) continue;
|
||||
//
|
||||
|
@ -405,7 +405,7 @@ void BotTeamplayReport(void) {
|
|||
}
|
||||
}
|
||||
BotAI_Print(PRT_MESSAGE, S_COLOR_BLUE"BLUE\n");
|
||||
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) {
|
||||
for (i = 0; i < level.maxclients; i++) {
|
||||
//
|
||||
if ( !botstates[i] || !botstates[i]->inuse ) continue;
|
||||
//
|
||||
|
@ -546,7 +546,7 @@ void BotUpdateInfoConfigStrings(void) {
|
|||
int i;
|
||||
char buf[MAX_INFO_STRING];
|
||||
|
||||
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) {
|
||||
for (i = 0; i < level.maxclients; i++) {
|
||||
//
|
||||
if ( !botstates[i] || !botstates[i]->inuse )
|
||||
continue;
|
||||
|
@ -1597,8 +1597,7 @@ int BotInitLibrary(void) {
|
|||
char buf[144];
|
||||
|
||||
//set the maxclients and maxentities library variables before calling BotSetupLibrary
|
||||
trap_Cvar_VariableStringBuffer("sv_maxclients", buf, sizeof(buf));
|
||||
if (!strlen(buf)) strcpy(buf, "8");
|
||||
Com_sprintf(buf, sizeof(buf), "%d", level.maxclients);
|
||||
trap_BotLibVarSet("maxclients", buf);
|
||||
Com_sprintf(buf, sizeof(buf), "%d", MAX_GENTITIES);
|
||||
trap_BotLibVarSet("maxentities", buf);
|
||||
|
|
|
@ -83,13 +83,9 @@ BotNumTeamMates
|
|||
int BotNumTeamMates(bot_state_t *bs) {
|
||||
int i, numplayers;
|
||||
char buf[MAX_INFO_STRING];
|
||||
static int maxclients;
|
||||
|
||||
if (!maxclients)
|
||||
maxclients = trap_Cvar_VariableIntegerValue("sv_maxclients");
|
||||
|
||||
numplayers = 0;
|
||||
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) {
|
||||
for (i = 0; i < level.maxclients; 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;
|
||||
|
@ -127,7 +123,6 @@ int BotSortTeamMatesByBaseTravelTime(bot_state_t *bs, int *teammates, int maxtea
|
|||
|
||||
int i, j, k, numteammates, traveltime;
|
||||
char buf[MAX_INFO_STRING];
|
||||
static int maxclients;
|
||||
int traveltimes[MAX_CLIENTS];
|
||||
bot_goal_t *goal = NULL;
|
||||
|
||||
|
@ -150,11 +145,8 @@ int BotSortTeamMatesByBaseTravelTime(bot_state_t *bs, int *teammates, int maxtea
|
|||
goal = &blueobelisk;
|
||||
}
|
||||
#endif
|
||||
if (!maxclients)
|
||||
maxclients = trap_Cvar_VariableIntegerValue("sv_maxclients");
|
||||
|
||||
numteammates = 0;
|
||||
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) {
|
||||
for (i = 0; i < level.maxclients; 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;
|
||||
|
@ -885,13 +877,9 @@ void BotTeamOrders(bot_state_t *bs) {
|
|||
int teammates[MAX_CLIENTS];
|
||||
int numteammates, i;
|
||||
char buf[MAX_INFO_STRING];
|
||||
static int maxclients;
|
||||
|
||||
if (!maxclients)
|
||||
maxclients = trap_Cvar_VariableIntegerValue("sv_maxclients");
|
||||
|
||||
numteammates = 0;
|
||||
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) {
|
||||
for (i = 0; i < level.maxclients; 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;
|
||||
|
|
Loading…
Reference in a new issue