Stop caching sv_maxclients in bot code

This commit is contained in:
Zack Middleton 2017-06-07 19:00:28 -05:00
parent d1631d6ea3
commit 74aa4268b2
5 changed files with 28 additions and 83 deletions

View file

@ -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));