Split G_AddRandomBot into multiple functions

This commit is contained in:
Zack Middleton 2017-06-29 15:30:16 -05:00
parent ccfc9011e2
commit 007e250e11

View file

@ -230,71 +230,94 @@ static void PlayerIntroSound( const char *modelAndSkin ) {
/* /*
=============== ===============
G_AddRandomBot G_CountBotPlayersByName
Returns number of bots with name on specified team or whole server if team is -1.
=============== ===============
*/ */
void G_AddRandomBot( int team ) { int G_CountBotPlayersByName( const char *name, int team ) {
int i, n, num; int i, num;
float skill;
char *value, netname[36], *teamstr;
gclient_t *cl; gclient_t *cl;
num = 0;
for ( i=0 ; i< g_maxclients.integer ; i++ ) {
cl = level.clients + i;
if ( cl->pers.connected != CON_CONNECTED ) {
continue;
}
if ( !(g_entities[i].r.svFlags & SVF_BOT) ) {
continue;
}
if ( team >= 0 && cl->sess.sessionTeam != team ) {
continue;
}
if ( name && Q_stricmp( name, cl->pers.netname ) ) {
continue;
}
num++;
}
return num;
}
/*
===============
G_SelectRandomBotInfo
Get random unused bot info on team or whole server if team is -1.
===============
*/
int G_SelectRandomBotInfo( int team ) {
int selection[MAX_BOTS];
int n, num;
char *value;
num = 0; num = 0;
for ( n = 0; n < g_numBots ; n++ ) { for ( n = 0; n < g_numBots ; n++ ) {
value = Info_ValueForKey( g_botInfos[n], "name" ); value = Info_ValueForKey( g_botInfos[n], "name" );
// //
for ( i=0 ; i< g_maxclients.integer ; i++ ) { if ( G_CountBotPlayersByName( value, team ) == 0 ) {
cl = level.clients + i; selection[num++] = n;
if ( cl->pers.connected != CON_CONNECTED ) {
continue; if ( num == MAX_BOTS ) {
}
if ( !(g_entities[i].r.svFlags & SVF_BOT) ) {
continue;
}
if ( team >= 0 && cl->sess.sessionTeam != team ) {
continue;
}
if ( !Q_stricmp( value, cl->pers.netname ) ) {
break; break;
} }
} }
if (i >= g_maxclients.integer) {
num++;
}
} }
num = random() * num;
for ( n = 0; n < g_numBots ; n++ ) { if ( num > 0 ) {
value = Info_ValueForKey( g_botInfos[n], "name" ); num = random() * ( num - 1 );
// return selection[num];
for ( i=0 ; i< g_maxclients.integer ; i++ ) {
cl = level.clients + i;
if ( cl->pers.connected != CON_CONNECTED ) {
continue;
}
if ( !(g_entities[i].r.svFlags & SVF_BOT) ) {
continue;
}
if ( team >= 0 && cl->sess.sessionTeam != team ) {
continue;
}
if ( !Q_stricmp( value, cl->pers.netname ) ) {
break;
}
}
if (i >= g_maxclients.integer) {
num--;
if (num <= 0) {
skill = trap_Cvar_VariableValue( "g_spSkill" );
if (team == TEAM_RED) teamstr = "red";
else if (team == TEAM_BLUE) teamstr = "blue";
else teamstr = "";
Q_strncpyz(netname, value, sizeof(netname));
Q_CleanStr(netname);
trap_SendConsoleCommand( EXEC_INSERT, va("addbot %s %f %s %i\n", netname, skill, teamstr, 0) );
return;
}
}
} }
return -1;
}
/*
===============
G_AddRandomBot
===============
*/
void G_AddRandomBot( int team ) {
int n;
char *value, netname[36], *teamstr;
float skill;
n = G_SelectRandomBotInfo( team );
if ( n < 0 ) {
// all bot types are in use on team
return;
}
value = Info_ValueForKey( g_botInfos[n], "name" );
skill = trap_Cvar_VariableValue( "g_spSkill" );
if (team == TEAM_RED) teamstr = "red";
else if (team == TEAM_BLUE) teamstr = "blue";
else teamstr = "";
Q_strncpyz(netname, value, sizeof(netname));
Q_CleanStr(netname);
trap_SendConsoleCommand( EXEC_INSERT, va("addbot %s %f %s %i\n", netname, skill, teamstr, 0) );
} }
/* /*