From 74aa4268b20f5b1a3ff8710cfc9ac1329d0b6934 Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Wed, 7 Jun 2017 19:00:28 -0500 Subject: [PATCH] Stop caching sv_maxclients in bot code --- code/game/ai_chat.c | 36 ++++++------------------------------ code/game/ai_cmd.c | 20 +++++--------------- code/game/ai_dmq3.c | 28 ++++++++++------------------ code/game/ai_main.c | 9 ++++----- code/game/ai_team.c | 18 +++--------------- 5 files changed, 28 insertions(+), 83 deletions(-) diff --git a/code/game/ai_chat.c b/code/game/ai_chat.c index 57166482..ecb0b9be 100644 --- a/code/game/ai_chat.c +++ b/code/game/ai_chat.c @@ -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)); diff --git a/code/game/ai_cmd.c b/code/game/ai_cmd.c index db954858..2944fb06 100644 --- a/code/game/ai_cmd.c +++ b/code/game/ai_cmd.c @@ -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++; diff --git a/code/game/ai_dmq3.c b/code/game/ai_dmq3.c index 75749229..6de1117b 100644 --- a/code/game/ai_dmq3.c +++ b/code/game/ai_dmq3.c @@ -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); diff --git a/code/game/ai_main.c b/code/game/ai_main.c index c6958318..a01e1530 100644 --- a/code/game/ai_main.c +++ b/code/game/ai_main.c @@ -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); diff --git a/code/game/ai_team.c b/code/game/ai_team.c index 925a94d6..6176bd55 100644 --- a/code/game/ai_team.c +++ b/code/game/ai_team.c @@ -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;