Fix not adding random bot when all bot info are in use on team

If there are two bot infos in scripts/bots.txt then each team can
only add two random bots via bot_minplayers or addbot random.

Pick random bot info from least used bot infos instead of only ones
that are used by zero players. That way a random bot can always be
added to the game.

This rarely affected Quake 3 since there is 32 bot infos. It could
easily affect new games though.
This commit is contained in:
Zack Middleton 2017-06-29 15:59:09 -05:00
parent d0d1fe1b7c
commit 7c601da651

View file

@ -263,22 +263,31 @@ int G_CountBotPlayersByName( const char *name, int team ) {
===============
G_SelectRandomBotInfo
Get random unused bot info on team or whole server if team is -1.
Get random least used bot info on team or whole server if team is -1.
===============
*/
int G_SelectRandomBotInfo( int team ) {
int selection[MAX_BOTS];
int n, num;
int count, bestCount;
char *value;
num = 0;
bestCount = MAX_CLIENTS;
for ( n = 0; n < g_numBots ; n++ ) {
value = Info_ValueForKey( g_botInfos[n], "funname" );
if ( !value[0] ) {
value = Info_ValueForKey( g_botInfos[n], "name" );
}
//
if ( G_CountBotPlayersByName( value, team ) == 0 ) {
count = G_CountBotPlayersByName( value, team );
if ( count < bestCount ) {
bestCount = count;
num = 0;
}
if ( count == bestCount ) {
selection[num++] = n;
if ( num == MAX_BOTS ) {
@ -308,7 +317,7 @@ void G_AddRandomBot( int team ) {
n = G_SelectRandomBotInfo( team );
if ( n < 0 ) {
// all bot types are in use on team
// no bot info available
return;
}
@ -636,7 +645,7 @@ static void G_AddBot( const char *name, float skill, const char *team, int delay
botinfoNum = G_SelectRandomBotInfo( teamNum );
if ( botinfoNum < 0 ) {
G_Printf( S_COLOR_YELLOW "WARNING: Cannot add random bot: all bot types in use on team '%s'.\n", team );
G_Printf( S_COLOR_RED "Error: Cannot add random bot, no bot info available.\n" );
trap_BotFreeClient( clientNum );
return;
}