From 3ae6eaf7329de8a1c88a159321ca7272f397c72f Mon Sep 17 00:00:00 2001 From: Walter Julius Hennecke Date: Mon, 10 Nov 2014 21:17:30 +0100 Subject: [PATCH] various fixes --- code/game/g_bot.c | 573 +++++++++++++++++++++++--------------------- code/game/g_local.h | 2 +- 2 files changed, 297 insertions(+), 278 deletions(-) diff --git a/code/game/g_bot.c b/code/game/g_bot.c index a01a5ff..e3d8fae 100644 --- a/code/game/g_bot.c +++ b/code/game/g_bot.c @@ -19,7 +19,10 @@ static char* g_arenaInfos[MAX_ARENAS]; static const uint16_t BOT_BEGIN_DELAY_BASE = 2000; static const uint16_t BOT_BEGIN_DELAY_INCREMENT = 2000; -static const uint8_t BOT_SPAWN_QUEUE_DEPTH = 16; + +enum g_botLimits_e { + BOT_SPAWN_QUEUE_DEPTH = 16 +}; typedef struct { int32_t clientNum; @@ -41,7 +44,7 @@ extern gentity_t* podium3; G_ParseInfos =============== */ -int32_t G_ParseInfos( char* buf, int32_t max, char* infos[] ) { +int32_t G_ParseInfos(char* buf, int32_t max, char* infos[]) { char* token = NULL; int32_t count = 0; char key[MAX_TOKEN_CHARS]; @@ -49,40 +52,40 @@ int32_t G_ParseInfos( char* buf, int32_t max, char* infos[] ) { count = 0; - while ( qtrue ) { - token = COM_Parse( &buf ); - if ( token == NULL || token[0] == 0 ) { + while (qtrue) { + token = COM_Parse(&buf); + if (token == NULL || token[0] == 0) { break; } - if ( strcmp( token, "{" ) != 0 ) { - Com_Printf( "Missing { in info file\n" ); + if (strcmp(token, "{") != 0) { + Com_Printf("Missing { in info file\n"); break; } - if ( count == max ) { - Com_Printf( "Max infos exceeded\n" ); + if (count == max) { + Com_Printf("Max infos exceeded\n"); break; } info[0] = '\0'; - while ( qtrue ) { - token = COM_ParseExt( &buf, qtrue ); - if ( token == NULL || token[0] == 0 ) { - Com_Printf( "Unexpected end of info file\n" ); + while (qtrue) { + token = COM_ParseExt(&buf, qtrue); + if (token == NULL || token[0] == 0) { + Com_Printf("Unexpected end of info file\n"); break; } - if ( strcmp( token, "}" ) == 0 ) { + if (strcmp(token, "}") == 0) { break; } strncpy(key, token, sizeof(key)); - token = COM_ParseExt( &buf, qfalse ); - if ( token == NULL || token[0] == 0 ) { - strcpy( token, "" ); + token = COM_ParseExt(&buf, qfalse); + if (token == NULL || token[0] == 0) { + strcpy(token, ""); } - Info_SetValueForKey( info, key, token ); + Info_SetValueForKey(info, key, token); } //NOTE: extra space for arena number infos[count] = G_Alloc(strlen(info) + strlen("\\num\\") + strlen(va("%d", MAX_ARENAS)) + 1); @@ -99,28 +102,28 @@ int32_t G_ParseInfos( char* buf, int32_t max, char* infos[] ) { G_LoadArenasFromFile =============== */ -static void G_LoadArenasFromFile( char* filename ) { +static void G_LoadArenasFromFile(char* filename) { int32_t len = 0; fileHandle_t f = 0; char buf[MAX_ARENAS_TEXT]; - len = trap_FS_FOpenFile( filename, &f, FS_READ ); - if ( f == 0 ) { - trap_Printf( va( S_COLOR_RED "file not found: %s\n", filename ) ); + len = trap_FS_FOpenFile(filename, &f, FS_READ); + if (f == 0) { + trap_Printf(va(S_COLOR_RED "file not found: %s\n", filename)); return; } - if ( len >= MAX_ARENAS_TEXT ) { - trap_Printf( va( S_COLOR_RED "file too large: %s is %i, max allowed is %i", filename, len, MAX_ARENAS_TEXT ) ); - trap_FS_FCloseFile( f ); + if (len >= MAX_ARENAS_TEXT) { + trap_Printf(va(S_COLOR_RED "file too large: %s is %i, max allowed is %i", filename, len, MAX_ARENAS_TEXT)); + trap_FS_FCloseFile(f); return; } - trap_FS_Read( buf, len, f ); + trap_FS_Read(buf, len, f); buf[len] = 0; - trap_FS_FCloseFile( f ); + trap_FS_FCloseFile(f); - g_numArenas += G_ParseInfos( buf, MAX_ARENAS - g_numArenas, &g_arenaInfos[g_numArenas] ); + g_numArenas += G_ParseInfos(buf, MAX_ARENAS - g_numArenas, &g_arenaInfos[g_numArenas]); } /* @@ -128,7 +131,7 @@ static void G_LoadArenasFromFile( char* filename ) { G_LoadArenas =============== */ -static void G_LoadArenas( void ) { +static void G_LoadArenas(void) { int32_t numdirs = 0; vmCvar_t arenasFile; char filename[128]; @@ -140,27 +143,28 @@ static void G_LoadArenas( void ) { g_numArenas = 0; - trap_Cvar_Register( &arenasFile, "g_arenasFile", "", CVAR_INIT|CVAR_ROM ); - if( *arenasFile.string ) { + trap_Cvar_Register(&arenasFile, "g_arenasFile", "", CVAR_INIT | CVAR_ROM); + if (*arenasFile.string) { G_LoadArenasFromFile(arenasFile.string); - } else { + } + else { G_LoadArenasFromFile("scripts/arenas.txt"); } // get all arenas from .arena files - numdirs = trap_FS_GetFileList("scripts", ".arena", dirlist, sizeof(dirlist) ); - dirptr = dirlist; - for (i = 0; i < numdirs; i++, dirptr += dirlen+1) + numdirs = trap_FS_GetFileList("scripts", ".arena", dirlist, sizeof(dirlist)); + dirptr = dirlist; + for (i = 0; i < numdirs; i++, dirptr += dirlen + 1) { dirlen = strlen(dirptr); strcpy(filename, "scripts/"); strcat(filename, dirptr); G_LoadArenasFromFile(filename); } - trap_Printf( va( "%i arenas parsed\n", g_numArenas ) ); - - for( n = 0; n < g_numArenas; n++ ) { - Info_SetValueForKey( g_arenaInfos[n], "num", va( "%i", n ) ); + trap_Printf(va("%i arenas parsed\n", g_numArenas)); + + for (n = 0; n < g_numArenas; n++) { + Info_SetValueForKey(g_arenaInfos[n], "num", va("%i", n)); } } @@ -170,11 +174,11 @@ static void G_LoadArenas( void ) { G_GetArenaInfoByNumber =============== */ -const char* G_GetArenaInfoByMap( const char* map ) { +const char* G_GetArenaInfoByMap(const char* map) { int32_t n = 0; - for( n = 0; n < g_numArenas; n++ ) { - if( Q_stricmp( Info_ValueForKey( g_arenaInfos[n], "map" ), map ) == 0 ) { + for (n = 0; n < g_numArenas; n++) { + if (Q_stricmp(Info_ValueForKey(g_arenaInfos[n], "map"), map) == 0) { return g_arenaInfos[n]; } } @@ -188,29 +192,30 @@ const char* G_GetArenaInfoByMap( const char* map ) { PlayerIntroSound ================= */ -static void PlayerIntroSound( const char* modelAndSkin ) { +static void PlayerIntroSound(const char* modelAndSkin) { char model[MAX_QPATH]; char* skin = NULL; strncpy(model, modelAndSkin, sizeof(model)); skin = strchr(model, '/'); - if ( skin != NULL ) { + if (skin != NULL) { *skin++ = '\0'; - } else { + } + else { skin = model; } - if( Q_stricmp( skin, "default" ) == 0 ) { + if (Q_stricmp(skin, "default") == 0) { skin = model; } - if( Q_stricmp( skin, "red" ) == 0 ) { + if (Q_stricmp(skin, "red") == 0) { skin = model; } - if( Q_stricmp( skin, "blue" ) == 0 ) { + if (Q_stricmp(skin, "blue") == 0) { skin = model; } //precached in cg_info.c, CG_LoadingClient - trap_SendConsoleCommand( EXEC_APPEND, va( "play sound/voice/computer/misc/%s.wav\n", skin ) ); + trap_SendConsoleCommand(EXEC_APPEND, va("play sound/voice/computer/misc/%s.wav\n", skin)); } /* @@ -218,7 +223,7 @@ static void PlayerIntroSound( const char* modelAndSkin ) { G_AddRandomBot =============== */ -void G_AddRandomBot( int32_t team ) { +void G_AddRandomBot(int32_t team) { int32_t i = 0; int32_t n = 0; int32_t num = 0; @@ -229,21 +234,21 @@ void G_AddRandomBot( int32_t team ) { gclient_t* cl = NULL; num = 0; - for ( n = 0; n < g_numBots ; n++ ) { - value = Info_ValueForKey( g_botInfos[n], "name" ); + for (n = 0; n < g_numBots; n++) { + value = Info_ValueForKey(g_botInfos[n], "name"); // - for ( i=0 ; i< g_maxclients.integer ; i++ ) { + for (i = 0; i < g_maxclients.integer; i++) { cl = level.clients + i; - if ( cl->pers.connected != CON_CONNECTED ) { + if (cl->pers.connected != CON_CONNECTED) { continue; } - if ( (g_entities[cl->ps.clientNum].r.svFlags & SVF_BOT) == 0 ) { + if ((g_entities[cl->ps.clientNum].r.svFlags & SVF_BOT) == 0) { continue; } - if ( team >= 0 && cl->sess.sessionTeam != team ) { + if (team >= 0 && cl->sess.sessionTeam != team) { continue; } - if ( Q_stricmp( value, cl->pers.netname ) == 0 ) { + if (Q_stricmp(value, cl->pers.netname) == 0) { break; } } @@ -252,41 +257,43 @@ void G_AddRandomBot( int32_t team ) { } } num = random() * num; - for ( n = 0; n < g_numBots ; n++ ) { - value = Info_ValueForKey( g_botInfos[n], "name" ); + for (n = 0; n < g_numBots; n++) { + value = Info_ValueForKey(g_botInfos[n], "name"); // - for ( i=0 ; i< g_maxclients.integer ; i++ ) { + for (i = 0; i < g_maxclients.integer; i++) { cl = level.clients + i; - if ( cl->pers.connected != CON_CONNECTED ) { + if (cl->pers.connected != CON_CONNECTED) { continue; } - if ( (g_entities[cl->ps.clientNum].r.svFlags & SVF_BOT) == 0 ) { + if ((g_entities[cl->ps.clientNum].r.svFlags & SVF_BOT) == 0) { continue; } - if ( team >= 0 && cl->sess.sessionTeam != team ) { + if (team >= 0 && cl->sess.sessionTeam != team) { continue; } - if ( Q_stricmp( value, cl->pers.netname ) == 0 ) { + if (Q_stricmp(value, cl->pers.netname) == 0) { break; } } if (i >= g_maxclients.integer) { num--; if (num <= 0) { - skill = trap_Cvar_VariableIntegerValue( "g_spSkill" ); + skill = trap_Cvar_VariableIntegerValue("g_spSkill"); if (team == TEAM_RED) { teamstr = "red"; - } else if (team == TEAM_BLUE) { + } + else if (team == TEAM_BLUE) { teamstr = "blue"; - } else { + } + else { teamstr = ""; } strncpy(netname, value, sizeof(netname)-1); netname[sizeof(netname)-1] = '\0'; Q_CleanStr(netname); - trap_SendConsoleCommand( EXEC_INSERT, va("addbot %s %i %s %i\n", netname, skill, teamstr, 0) ); + trap_SendConsoleCommand(EXEC_INSERT, va("addbot %s %i %s %i\n", netname, skill, teamstr, 0)); return; } @@ -299,29 +306,29 @@ void G_AddRandomBot( int32_t team ) { G_RemoveRandomBot =============== */ -qboolean G_RemoveRandomBot( int32_t team ) { +qboolean G_RemoveRandomBot(int32_t team) { int32_t i = 0; char netname[36]; gclient_t* cl = NULL; - for ( i=0 ; i< g_maxclients.integer ; i++ ) { + for (i = 0; i < g_maxclients.integer; i++) { cl = level.clients + i; - if ( cl->pers.connected != CON_CONNECTED ) { + if (cl->pers.connected != CON_CONNECTED) { continue; } - if ( !(g_entities[cl->ps.clientNum].r.svFlags & SVF_BOT) ) { + if (!(g_entities[cl->ps.clientNum].r.svFlags & SVF_BOT)) { continue; } - if ( team >= 0 && cl->sess.sessionTeam != team ) { + if (team >= 0 && cl->sess.sessionTeam != team) { continue; } strcpy(netname, cl->pers.netname); Q_CleanStr(netname); - trap_SendConsoleCommand( EXEC_INSERT, va("kick \"%s\"\n", netname) ); + trap_SendConsoleCommand(EXEC_INSERT, va("kick \"%s\"\n", netname)); return qtrue; } @@ -333,24 +340,24 @@ qboolean G_RemoveRandomBot( int32_t team ) { G_CountHumanPlayers =============== */ -int32_t G_CountHumanPlayers( int32_t team ) { - int32_t i = 0; +int32_t G_CountHumanPlayers(int32_t team) { + int32_t i = 0; int32_t num = 0; gclient_t* cl = NULL; num = 0; - for ( i=0 ; i< g_maxclients.integer ; i++ ) { + for (i = 0; i < g_maxclients.integer; i++) { cl = level.clients + i; - if ( cl->pers.connected != CON_CONNECTED ) { + if (cl->pers.connected != CON_CONNECTED) { continue; } - if ( g_entities[cl->ps.clientNum].r.svFlags & SVF_BOT ) { + if (g_entities[cl->ps.clientNum].r.svFlags & SVF_BOT) { continue; } - if ( team >= 0 && cl->sess.sessionTeam != team ) { + if (team >= 0 && cl->sess.sessionTeam != team) { continue; } num++; @@ -364,35 +371,35 @@ int32_t G_CountHumanPlayers( int32_t team ) { G_CountBotPlayers =============== */ -int32_t G_CountBotPlayers( int32_t team ) { +int32_t G_CountBotPlayers(int32_t team) { int32_t i = 0; int32_t n = 0; int32_t num = 0; gclient_t* cl = NULL; - for ( ; i< g_maxclients.integer ; i++ ) { + for (; i < g_maxclients.integer; i++) { cl = level.clients + i; - if ( cl->pers.connected != CON_CONNECTED ) { + if (cl->pers.connected != CON_CONNECTED) { continue; } - if ( (g_entities[cl->ps.clientNum].r.svFlags & SVF_BOT) == 0 ) { + if ((g_entities[cl->ps.clientNum].r.svFlags & SVF_BOT) == 0) { continue; } - if ( team >= 0 && cl->sess.sessionTeam != team ) { + if (team >= 0 && cl->sess.sessionTeam != team) { continue; } num++; } - for( ; n < BOT_SPAWN_QUEUE_DEPTH; n++ ) { - if( botSpawnQueue[n].spawnTime == 0 ) { + for (; n < BOT_SPAWN_QUEUE_DEPTH; n++) { + if (botSpawnQueue[n].spawnTime == 0) { continue; } - if ( botSpawnQueue[n].spawnTime > level.time ) { + if (botSpawnQueue[n].spawnTime > level.time) { continue; } num++; @@ -405,13 +412,13 @@ int32_t G_CountBotPlayers( int32_t team ) { G_CheckMinimumPlayers =============== */ -void G_CheckMinimumPlayers( void ) { +void G_CheckMinimumPlayers(void) { int32_t minplayers = 0; int32_t humanplayers = 0; int32_t botplayers = 0; static int32_t checkminimumplayers_time = 0; - if(level.intermissiontime != 0) { + if (level.intermissiontime != 0) { return; } @@ -428,60 +435,66 @@ void G_CheckMinimumPlayers( void ) { } if (g_gametype.integer != GT_TOURNAMENT) { - botplayers = G_CountBotPlayers( TEAM_SPECTATOR ); - if ( botplayers > 0 ) { - G_RemoveRandomBot( TEAM_SPECTATOR ); + botplayers = G_CountBotPlayers(TEAM_SPECTATOR); + if (botplayers > 0) { + G_RemoveRandomBot(TEAM_SPECTATOR); } } if (g_gametype.integer >= GT_TEAM) { if (minplayers >= g_maxclients.integer / 2) { - minplayers = (g_maxclients.integer / 2) -1; + minplayers = (g_maxclients.integer / 2) - 1; } - humanplayers = G_CountHumanPlayers( TEAM_RED ); - botplayers = G_CountBotPlayers( TEAM_RED ); + humanplayers = G_CountHumanPlayers(TEAM_RED); + botplayers = G_CountBotPlayers(TEAM_RED); // if (humanplayers + botplayers < minplayers) { - G_AddRandomBot( TEAM_RED ); - } else if (humanplayers + botplayers > minplayers && botplayers) { - G_RemoveRandomBot( TEAM_RED ); + G_AddRandomBot(TEAM_RED); + } + else if (humanplayers + botplayers > minplayers && botplayers) { + G_RemoveRandomBot(TEAM_RED); } // - humanplayers = G_CountHumanPlayers( TEAM_BLUE ); - botplayers = G_CountBotPlayers( TEAM_BLUE ); + humanplayers = G_CountHumanPlayers(TEAM_BLUE); + botplayers = G_CountBotPlayers(TEAM_BLUE); // if (humanplayers + botplayers < minplayers) { - G_AddRandomBot( TEAM_BLUE ); - } else if (humanplayers + botplayers > minplayers && botplayers) { - G_RemoveRandomBot( TEAM_BLUE ); + G_AddRandomBot(TEAM_BLUE); } - } else if (g_gametype.integer == GT_TOURNAMENT) { + else if (humanplayers + botplayers > minplayers && botplayers) { + G_RemoveRandomBot(TEAM_BLUE); + } + } + else if (g_gametype.integer == GT_TOURNAMENT) { if (minplayers >= g_maxclients.integer) { - minplayers = g_maxclients.integer-1; + minplayers = g_maxclients.integer - 1; } - humanplayers = G_CountHumanPlayers( -1 ); - botplayers = G_CountBotPlayers( -1 ); + humanplayers = G_CountHumanPlayers(-1); + botplayers = G_CountBotPlayers(-1); // if (humanplayers + botplayers < minplayers) { - G_AddRandomBot( TEAM_FREE ); - } else if (humanplayers + botplayers > minplayers && botplayers) { + G_AddRandomBot(TEAM_FREE); + } + else if (humanplayers + botplayers > minplayers && botplayers) { // try to remove spectators first - if (!G_RemoveRandomBot( TEAM_SPECTATOR )) { + if (!G_RemoveRandomBot(TEAM_SPECTATOR)) { // just remove the bot that is playing - G_RemoveRandomBot( -1 ); + G_RemoveRandomBot(-1); } } - } else if (g_gametype.integer == GT_FFA) { + } + else if (g_gametype.integer == GT_FFA) { if (minplayers >= g_maxclients.integer) { - minplayers = g_maxclients.integer-1; + minplayers = g_maxclients.integer - 1; } - humanplayers = G_CountHumanPlayers( TEAM_FREE ); - botplayers = G_CountBotPlayers( TEAM_FREE ); + humanplayers = G_CountHumanPlayers(TEAM_FREE); + botplayers = G_CountBotPlayers(TEAM_FREE); // if (humanplayers + botplayers < minplayers) { - G_AddRandomBot( TEAM_FREE ); - } else if (humanplayers + botplayers > minplayers && botplayers) { - G_RemoveRandomBot( TEAM_FREE ); + G_AddRandomBot(TEAM_FREE); + } + else if (humanplayers + botplayers > minplayers && botplayers) { + G_RemoveRandomBot(TEAM_FREE); } } } @@ -491,27 +504,27 @@ void G_CheckMinimumPlayers( void ) { G_CheckBotSpawn =============== */ -void G_CheckBotSpawn( void ) { +void G_CheckBotSpawn(void) { int32_t n = 0; char userinfo[MAX_INFO_VALUE]; G_CheckMinimumPlayers(); - for( ; n < BOT_SPAWN_QUEUE_DEPTH; n++ ) { - if( botSpawnQueue[n].spawnTime == 0 ) { + for (; n < BOT_SPAWN_QUEUE_DEPTH; n++) { + if (botSpawnQueue[n].spawnTime == 0) { continue; } - if ( botSpawnQueue[n].spawnTime > level.time ) { + if (botSpawnQueue[n].spawnTime > level.time) { continue; } - G_Client_Begin( botSpawnQueue[n].clientNum, qfalse, qtrue, qfalse ); + G_Client_Begin(botSpawnQueue[n].clientNum, qfalse, qtrue, qfalse); botSpawnQueue[n].spawnTime = 0; - if( g_gametype.integer == GT_SINGLE_PLAYER ) { - trap_GetUserinfo( botSpawnQueue[n].clientNum, userinfo, sizeof(userinfo) ); - PlayerIntroSound( Info_ValueForKey (userinfo, "model") ); + if (g_gametype.integer == GT_SINGLE_PLAYER) { + trap_GetUserinfo(botSpawnQueue[n].clientNum, userinfo, sizeof(userinfo)); + PlayerIntroSound(Info_ValueForKey(userinfo, "model")); } } } @@ -522,19 +535,19 @@ void G_CheckBotSpawn( void ) { AddBotToSpawnQueue =============== */ -static void AddBotToSpawnQueue( int32_t clientNum, int32_t delay ) { +static void AddBotToSpawnQueue(int32_t clientNum, int32_t delay) { int32_t n = 0; - for( ; n < BOT_SPAWN_QUEUE_DEPTH; n++ ) { - if( botSpawnQueue[n].spawnTime == 0 ) { + for (; n < BOT_SPAWN_QUEUE_DEPTH; n++) { + if (botSpawnQueue[n].spawnTime == 0) { botSpawnQueue[n].spawnTime = level.time + delay; botSpawnQueue[n].clientNum = clientNum; return; } } - G_Printf( S_COLOR_YELLOW "Unable to delay spawn\n" ); - G_Client_Begin( clientNum, qfalse, qtrue, qfalse ); + G_Printf(S_COLOR_YELLOW "Unable to delay spawn\n"); + G_Client_Begin(clientNum, qfalse, qtrue, qfalse); } @@ -543,8 +556,8 @@ static void AddBotToSpawnQueue( int32_t clientNum, int32_t delay ) { G_QueueBotBegin =============== */ -void G_QueueBotBegin( int32_t clientNum ) { - AddBotToSpawnQueue( clientNum, botBeginDelay ); +void G_QueueBotBegin(int32_t clientNum) { + AddBotToSpawnQueue(clientNum, botBeginDelay); botBeginDelay += BOT_BEGIN_DELAY_INCREMENT; } @@ -554,25 +567,26 @@ void G_QueueBotBegin( int32_t clientNum ) { G_BotConnect =============== */ -qboolean G_BotConnect( int32_t clientNum, qboolean restart ) { +qboolean G_BotConnect(int32_t clientNum, qboolean restart) { bot_settings_t settings; char userinfo[MAX_INFO_STRING]; - trap_GetUserinfo( clientNum, userinfo, sizeof(userinfo) ); + trap_GetUserinfo(clientNum, userinfo, sizeof(userinfo)); strncpy(settings.characterfile, Info_ValueForKey(userinfo, "characterfile"), sizeof(settings.characterfile)); - settings.skill = atoi( Info_ValueForKey( userinfo, "skill" ) ); - strncpy( settings.team, Info_ValueForKey( userinfo, "team" ), sizeof(settings.team) ); - strncpy( settings.pclass, Info_ValueForKey( userinfo, "class" ), sizeof(settings.pclass) ); + settings.skill = atoi(Info_ValueForKey(userinfo, "skill")); + strncpy(settings.team, Info_ValueForKey(userinfo, "team"), sizeof(settings.team)); + strncpy(settings.pclass, Info_ValueForKey(userinfo, "class"), sizeof(settings.pclass)); - if (AI_main_BotAISetupClient( clientNum, &settings ) == 0) { - trap_DropClient( clientNum, "BotAISetupClient failed" ); + if (AI_main_BotAISetupClient(clientNum, &settings) == 0) { + trap_DropClient(clientNum, "BotAISetupClient failed"); return qfalse; } - if( restart && (g_gametype.integer == GT_SINGLE_PLAYER) ) { + if (restart && (g_gametype.integer == GT_SINGLE_PLAYER)) { g_entities[clientNum].botDelayBegin = qtrue; - } else { + } + else { g_entities[clientNum].botDelayBegin = qfalse; } @@ -585,7 +599,7 @@ qboolean G_BotConnect( int32_t clientNum, qboolean restart ) { G_AddBot =============== */ -static void G_AddBot( const char* name, double skill, const char* team, const char* pclass, int32_t delay, char* altname) { +static void G_AddBot(const char* name, double skill, const char* team, const char* pclass, int32_t delay, char* altname) { int32_t clientNum = 0; char* botinfo = NULL; gentity_t* bot = NULL; @@ -597,67 +611,67 @@ static void G_AddBot( const char* name, double skill, const char* team, const ch int32_t preTeam = 0; // get the botinfo from bots.txt - botinfo = G_GetBotInfoByName( name ); - if ( botinfo == NULL || botinfo[0] == 0 ) { - G_Printf( S_COLOR_RED "Error: Bot '%s' not defined\n", name ); + botinfo = G_GetBotInfoByName(name); + if (botinfo == NULL || botinfo[0] == 0) { + G_Printf(S_COLOR_RED "Error: Bot '%s' not defined\n", name); return; } // create the bot's userinfo userinfo[0] = '\0'; - botname = Info_ValueForKey( botinfo, "funname" ); - if( botname == NULL || botname[0] == 0 ) { - botname = Info_ValueForKey( botinfo, "name" ); + botname = Info_ValueForKey(botinfo, "funname"); + if (botname == NULL || botname[0] == 0) { + botname = Info_ValueForKey(botinfo, "name"); } // check for an alternative name if ((altname != NULL) && (altname[0] != 0)) { botname = altname; } - Info_SetValueForKey( userinfo, "name", botname ); - Info_SetValueForKey( userinfo, "rate", "25000" ); - Info_SetValueForKey( userinfo, "snaps", "20" ); - Info_SetValueForKey( userinfo, "skill", va("%1.2f", skill) ); + Info_SetValueForKey(userinfo, "name", botname); + Info_SetValueForKey(userinfo, "rate", "25000"); + Info_SetValueForKey(userinfo, "snaps", "20"); + Info_SetValueForKey(userinfo, "skill", va("%1.2f", skill)); key = "model"; - model = Info_ValueForKey( botinfo, key ); - if ( *model ) { + model = Info_ValueForKey(botinfo, key); + if (*model) { model = "munro/main/default"; //RPG-X MODEL SYSTEM } - Info_SetValueForKey( userinfo, key, model ); + Info_SetValueForKey(userinfo, key, model); key = "gender"; - s = Info_ValueForKey( botinfo, key ); - if ( !*s ) { + s = Info_ValueForKey(botinfo, key); + if (!*s) { s = "male"; } - Info_SetValueForKey( userinfo, "sex", s ); + Info_SetValueForKey(userinfo, "sex", s); key = "color"; - s = Info_ValueForKey( botinfo, key ); - if ( !*s ) { + s = Info_ValueForKey(botinfo, key); + if (!*s) { s = "4"; } - Info_SetValueForKey( userinfo, key, s ); + Info_SetValueForKey(userinfo, key, s); s = Info_ValueForKey(botinfo, "aifile"); - if (!*s ) { - trap_Printf( S_COLOR_RED "Error: bot has no aifile specified\n" ); + if (!*s) { + trap_Printf(S_COLOR_RED "Error: bot has no aifile specified\n"); return; } // have the server allocate a client slot clientNum = trap_BotAllocateClient(); - if ( clientNum == -1 ) { - G_Printf( S_COLOR_RED "Unable to add bot. All player slots are in use.\n" ); - G_Printf( S_COLOR_RED "Start server with more 'open' slots (or check setting of sv_maxclients cvar).\n" ); + if (clientNum == -1) { + G_Printf(S_COLOR_RED "Unable to add bot. All player slots are in use.\n"); + G_Printf(S_COLOR_RED "Start server with more 'open' slots (or check setting of sv_maxclients cvar).\n"); return; } // initialize the bot settings - if( team == NULL || !*team ) { - if( g_gametype.integer >= GT_TEAM ) { - if( G_Client_PickTeam(clientNum) == TEAM_RED) { + if (team == NULL || !*team) { + if (g_gametype.integer >= GT_TEAM) { + if (G_Client_PickTeam(clientNum) == TEAM_RED) { team = "red"; } else { @@ -668,16 +682,16 @@ static void G_AddBot( const char* name, double skill, const char* team, const ch team = "red"; } } - Info_SetValueForKey( userinfo, "characterfile", Info_ValueForKey( botinfo, "aifile" ) ); - Info_SetValueForKey( userinfo, "skill", va( "%5.2f", skill ) ); - Info_SetValueForKey( userinfo, "team", team ); + Info_SetValueForKey(userinfo, "characterfile", Info_ValueForKey(botinfo, "aifile")); + Info_SetValueForKey(userinfo, "skill", va("%5.2f", skill)); + Info_SetValueForKey(userinfo, "team", team); - bot = &g_entities[ clientNum ]; + bot = &g_entities[clientNum]; bot->r.svFlags |= SVF_BOT; bot->inuse = qtrue; // register the userinfo - trap_SetUserinfo( clientNum, userinfo ); + trap_SetUserinfo(clientNum, userinfo); if (g_gametype.integer >= GT_TEAM) { @@ -691,14 +705,14 @@ static void G_AddBot( const char* name, double skill, const char* team, const ch } else { - bot->client->sess.sessionTeam = G_Client_PickTeam( -1 ); + bot->client->sess.sessionTeam = G_Client_PickTeam(-1); } } preTeam = bot->client->sess.sessionTeam; // have it connect to the game as a normal client - if ( G_Client_Connect( clientNum, qtrue, qtrue ) ) { + if (G_Client_Connect(clientNum, qtrue, qtrue)) { return; } @@ -720,22 +734,22 @@ static void G_AddBot( const char* name, double skill, const char* team, const ch team = "Blue"; } - Info_SetValueForKey( userinfo, "team", team ); + Info_SetValueForKey(userinfo, "team", team); - trap_SetUserinfo( clientNum, userinfo ); + trap_SetUserinfo(clientNum, userinfo); - bot->client->ps.persistant[ PERS_TEAM ] = bot->client->sess.sessionTeam; + bot->client->ps.persistant[PERS_TEAM] = bot->client->sess.sessionTeam; - G_ReadSessionData( bot->client ); - G_Client_UserinfoChanged( clientNum ); + G_ReadSessionData(bot->client); + G_Client_UserinfoChanged(clientNum); } - if( delay == 0 ) { - G_Client_Begin( clientNum, qfalse, qfalse, qfalse ); + if (delay == 0) { + G_Client_Begin(clientNum, qfalse, qfalse, qfalse); return; } - AddBotToSpawnQueue( clientNum, delay ); + AddBotToSpawnQueue(clientNum, delay); } @@ -744,7 +758,7 @@ static void G_AddBot( const char* name, double skill, const char* team, const ch Svcmd_AddBot_f =============== */ -void Svcmd_AddBot_f( void ) { +void Svcmd_AddBot_f(void) { int32_t skill = 0; int32_t delay = 0; char name[MAX_TOKEN_CHARS]; @@ -754,7 +768,7 @@ void Svcmd_AddBot_f( void ) { char pclass[MAX_TOKEN_CHARS]; // are bots enabled? - if ( trap_Cvar_VariableIntegerValue( "bot_enable" ) == 0 ) { + if (trap_Cvar_VariableIntegerValue("bot_enable") == 0) { return; } @@ -765,44 +779,46 @@ void Svcmd_AddBot_f( void ) { memset(pclass, 0, sizeof(pclass)); // name - trap_Argv( 1, name, sizeof( name ) ); - if ( name[0] == 0 ) { - trap_Printf( "Usage: Addbot [skill 1-4] [team] [class] [msec delay] [altname]\n" ); + trap_Argv(1, name, sizeof(name)); + if (name[0] == 0) { + trap_Printf("Usage: Addbot [skill 1-4] [team] [class] [msec delay] [altname]\n"); return; } // skill - trap_Argv( 2, string, sizeof( string ) ); - if ( string[0] == 0 ) { + trap_Argv(2, string, sizeof(string)); + if (string[0] == 0) { skill = 4; - } else { - skill = atoi( string ); + } + else { + skill = atoi(string); } // team - trap_Argv( 3, team, sizeof( team ) ); + trap_Argv(3, team, sizeof(team)); // class - trap_Argv( 4, pclass, sizeof( pclass ) ); + trap_Argv(4, pclass, sizeof(pclass)); // delay - trap_Argv( 5, string, sizeof( string ) ); - if ( string[0] == 0 ) { + trap_Argv(5, string, sizeof(string)); + if (string[0] == 0) { delay = 0; - } else { - delay = atoi( string ); + } + else { + delay = atoi(string); } // alternative name - trap_Argv( 6, altname, sizeof( altname ) ); + trap_Argv(6, altname, sizeof(altname)); - G_AddBot( name, skill, team, pclass, delay, altname ); + G_AddBot(name, skill, team, pclass, delay, altname); // if this was issued during gameplay and we are playing locally, // go ahead and load the bot's media immediately - if ( (level.time - level.startTime > 1000) && - trap_Cvar_VariableIntegerValue( "cl_running" ) ) { - trap_SendServerCommand( -1, "loaddeferred\n" ); // FIXME: spelled wrong, but not changing for demo + if ((level.time - level.startTime > 1000) && + trap_Cvar_VariableIntegerValue("cl_running")) { + trap_SendServerCommand(-1, "loaddeferred\n"); // FIXME: spelled wrong, but not changing for demo } } @@ -811,7 +827,7 @@ void Svcmd_AddBot_f( void ) { Svcmd_BotList_f =============== */ -void Svcmd_BotList_f( void ) { +void Svcmd_BotList_f(void) { int32_t i = 0; char name[MAX_TOKEN_CHARS]; char funname[MAX_TOKEN_CHARS]; @@ -825,20 +841,20 @@ void Svcmd_BotList_f( void ) { trap_Printf("^1name model aifile funname\n"); for (i = 0; i < g_numBots; i++) { - strcpy(name, Info_ValueForKey( g_botInfos[i], "name" )); - if ( !*name ) { + strcpy(name, Info_ValueForKey(g_botInfos[i], "name")); + if (!*name) { strcpy(name, "RedShirt"); } - strcpy(funname, Info_ValueForKey( g_botInfos[i], "funname" )); - if ( !*funname ) { + strcpy(funname, Info_ValueForKey(g_botInfos[i], "funname")); + if (!*funname) { strcpy(funname, ""); } - strcpy(model, Info_ValueForKey( g_botInfos[i], "model" )); - if ( !*model ) { + strcpy(model, Info_ValueForKey(g_botInfos[i], "model")); + if (!*model) { strcpy(model, "munro/main/default"); //RPG-X MODEL SYSTEM } - strcpy(aifile, Info_ValueForKey( g_botInfos[i], "aifile")); - if (!*aifile ) { + strcpy(aifile, Info_ValueForKey(g_botInfos[i], "aifile")); + if (!*aifile) { strcpy(aifile, "bots/default_c.c"); } trap_Printf(va("%-16s %-16s %-20s %-20s\n", name, model, aifile, funname)); @@ -851,7 +867,7 @@ void Svcmd_BotList_f( void ) { G_SpawnBots =============== */ -static void G_SpawnBots( char* botList, int32_t baseDelay ) { +static void G_SpawnBots(char* botList, int32_t baseDelay) { char* bot; char* p; int32_t skill = 0; @@ -863,21 +879,21 @@ static void G_SpawnBots( char* botList, int32_t baseDelay ) { podium3 = NULL; memset(bots, 0, sizeof(bots)); - skill = trap_Cvar_VariableIntegerValue( "g_spSkill" ); - if( skill < 1 || skill > 5 ) { - trap_Cvar_Set( "g_spSkill", "2" ); + skill = trap_Cvar_VariableIntegerValue("g_spSkill"); + if (skill < 1 || skill > 5) { + trap_Cvar_Set("g_spSkill", "2"); skill = 2; } strncpy(bots, botList, sizeof(bots)); p = &bots[0]; delay = baseDelay; - while( *p ) { + while (*p) { //skip spaces - while( *p && *p == ' ' ) { + while (*p && *p == ' ') { p++; } - if( !p ) { + if (!p) { break; } @@ -885,16 +901,16 @@ static void G_SpawnBots( char* botList, int32_t baseDelay ) { bot = p; // skip until space of null - while( *p && *p != ' ' ) { + while (*p && *p != ' ') { p++; } - if( *p ) { + if (*p) { *p++ = 0; } // we must add the bot this way, calling G_AddBot directly at this stage // does "Bad Things" - trap_SendConsoleCommand( EXEC_INSERT, va("addbot %s %i free %i\n", bot, skill, delay) ); + trap_SendConsoleCommand(EXEC_INSERT, va("addbot %s %i free %i\n", bot, skill, delay)); delay += BOT_BEGIN_DELAY_INCREMENT; } @@ -906,28 +922,28 @@ static void G_SpawnBots( char* botList, int32_t baseDelay ) { G_LoadBotsFromFile =============== */ -static void G_LoadBotsFromFile( char* filename ) { +static void G_LoadBotsFromFile(char* filename) { int32_t len = 0; fileHandle_t f = 0; char buf[MAX_BOTS_TEXT]; - len = trap_FS_FOpenFile( filename, &f, FS_READ ); - if ( f == 0 ) { - trap_Printf( va( S_COLOR_RED "file not found: %s\n", filename ) ); + len = trap_FS_FOpenFile(filename, &f, FS_READ); + if (f == 0) { + trap_Printf(va(S_COLOR_RED "file not found: %s\n", filename)); return; } - if ( len >= MAX_BOTS_TEXT ) { - trap_Printf( va( S_COLOR_RED "file too large: %s is %i, max allowed is %i", filename, len, MAX_BOTS_TEXT ) ); - trap_FS_FCloseFile( f ); + if (len >= MAX_BOTS_TEXT) { + trap_Printf(va(S_COLOR_RED "file too large: %s is %i, max allowed is %i", filename, len, MAX_BOTS_TEXT)); + trap_FS_FCloseFile(f); return; } memset(buf, 0, sizeof(buf)); - trap_FS_Read( buf, len, f ); + trap_FS_Read(buf, len, f); buf[len] = 0; - trap_FS_FCloseFile( f ); + trap_FS_FCloseFile(f); - g_numBots += G_ParseInfos( buf, MAX_BOTS - g_numBots, &g_botInfos[g_numBots] ); + g_numBots += G_ParseInfos(buf, MAX_BOTS - g_numBots, &g_botInfos[g_numBots]); } @@ -936,7 +952,7 @@ static void G_LoadBotsFromFile( char* filename ) { G_LoadBots =============== */ -static void G_LoadBots( void ) { +static void G_LoadBots(void) { vmCvar_t botsFile; int32_t numdirs = 0; char filename[128]; @@ -945,7 +961,7 @@ static void G_LoadBots( void ) { int32_t i = 0; int32_t dirlen = 0; - if ( trap_Cvar_VariableIntegerValue( "bot_enable" ) == 0 ) { + if (trap_Cvar_VariableIntegerValue("bot_enable") == 0) { return; } @@ -953,8 +969,8 @@ static void G_LoadBots( void ) { memset(dirlist, 0, sizeof(dirlist)); g_numBots = 0; - trap_Cvar_Register( &botsFile, "g_botsFile", "", CVAR_INIT|CVAR_ROM ); - if( *botsFile.string ) { + trap_Cvar_Register(&botsFile, "g_botsFile", "", CVAR_INIT | CVAR_ROM); + if (*botsFile.string) { G_LoadBotsFromFile(botsFile.string); } else { @@ -962,16 +978,16 @@ static void G_LoadBots( void ) { } // get all bots from .bot files - numdirs = trap_FS_GetFileList("scripts", ".bot", dirlist, sizeof(dirlist) ); - dirptr = dirlist; - for (i = 0; i < numdirs; i++, dirptr += dirlen+1) + numdirs = trap_FS_GetFileList("scripts", ".bot", dirlist, sizeof(dirlist)); + dirptr = dirlist; + for (i = 0; i < numdirs; i++, dirptr += dirlen + 1) { dirlen = strlen(dirptr); strcpy(filename, "scripts/"); strcat(filename, dirptr); G_LoadBotsFromFile(filename); } - trap_Printf( va( "%i bots parsed\n", g_numBots ) ); + trap_Printf(va("%i bots parsed\n", g_numBots)); } @@ -981,9 +997,9 @@ static void G_LoadBots( void ) { G_GetBotInfoByNumber =============== */ -char* G_GetBotInfoByNumber( int32_t num ) { - if( num < 0 || num >= g_numBots ) { - trap_Printf( va( S_COLOR_RED "Invalid bot number: %i\n", num ) ); +char* G_GetBotInfoByNumber(int32_t num) { + if (num < 0 || num >= g_numBots) { + trap_Printf(va(S_COLOR_RED "Invalid bot number: %i\n", num)); return NULL; } return g_botInfos[num]; @@ -995,13 +1011,13 @@ char* G_GetBotInfoByNumber( int32_t num ) { G_GetBotInfoByName =============== */ -char* G_GetBotInfoByName( const char* name ) { +char* G_GetBotInfoByName(const char* name) { int32_t n = 0; char* value = NULL; - for ( n = 0; n < g_numBots ; n++ ) { - value = Info_ValueForKey( g_botInfos[n], "name" ); - if ( Q_stricmp( value, name ) == 0 ) { + for (n = 0; n < g_numBots; n++) { + value = Info_ValueForKey(g_botInfos[n], "name"); + if (Q_stricmp(value, name) == 0) { return g_botInfos[n]; } } @@ -1009,7 +1025,7 @@ char* G_GetBotInfoByName( const char* name ) { return NULL; } -void G_InitBots( qboolean restart ) { +void G_InitBots(qboolean restart) { const char* arenainfo = NULL; char* strValue = NULL; char map[MAX_QPATH]; @@ -1021,54 +1037,57 @@ void G_InitBots( qboolean restart ) { G_LoadBots(); G_LoadArenas(); - trap_Cvar_Register( &bot_minplayers, "bot_minplayers", "0", CVAR_SERVERINFO ); + trap_Cvar_Register(&bot_minplayers, "bot_minplayers", "0", CVAR_SERVERINFO); - if( g_gametype.integer == GT_SINGLE_PLAYER ) { + if (g_gametype.integer == GT_SINGLE_PLAYER) { int32_t fragLimit = 0; int32_t timeLimit = 0; int32_t basedelay = 0; - trap_GetServerinfo( serverinfo, sizeof(serverinfo) ); - Q_strncpyz( map, Info_ValueForKey( serverinfo, "mapname" ), sizeof(map) ); - arenainfo = G_GetArenaInfoByMap( map ); - if ( arenainfo == NULL ) { + trap_GetServerinfo(serverinfo, sizeof(serverinfo)); + Q_strncpyz(map, Info_ValueForKey(serverinfo, "mapname"), sizeof(map)); + arenainfo = G_GetArenaInfoByMap(map); + if (arenainfo == NULL) { return; } - strValue = Info_ValueForKey( arenainfo, "fraglimit" ); - fragLimit = atoi( strValue ); - if ( fragLimit != 0 ) { - trap_Cvar_Set( "fraglimit", strValue ); - } else { - trap_Cvar_Set( "fraglimit", "0" ); + strValue = Info_ValueForKey(arenainfo, "fraglimit"); + fragLimit = atoi(strValue); + if (fragLimit != 0) { + trap_Cvar_Set("fraglimit", strValue); + } + else { + trap_Cvar_Set("fraglimit", "0"); } - strValue = Info_ValueForKey( arenainfo, "timelimit" ); - timeLimit = atoi( strValue ); - if ( timeLimit != 0 ) { - trap_Cvar_Set( "timelimit", strValue ); - } else { - trap_Cvar_Set( "timelimit", "0" ); + strValue = Info_ValueForKey(arenainfo, "timelimit"); + timeLimit = atoi(strValue); + if (timeLimit != 0) { + trap_Cvar_Set("timelimit", strValue); + } + else { + trap_Cvar_Set("timelimit", "0"); } - if ( fragLimit == 0 && timeLimit == 0 ) { - trap_Cvar_Set( "fraglimit", "10" ); - trap_Cvar_Set( "timelimit", "0" ); + if (fragLimit == 0 && timeLimit == 0) { + trap_Cvar_Set("fraglimit", "10"); + trap_Cvar_Set("timelimit", "0"); } if (g_holoIntro.integer != 0) { // The player will be looking at the holodeck doors for the first five seconds, so take that into account. basedelay = BOT_BEGIN_DELAY_BASE + TIME_INTRO; - } else { + } + else { basedelay = BOT_BEGIN_DELAY_BASE; } - strValue = Info_ValueForKey( arenainfo, "special" ); - if( Q_stricmp( strValue, "training" ) == 0 ) { + strValue = Info_ValueForKey(arenainfo, "special"); + if (Q_stricmp(strValue, "training") == 0) { basedelay += 10000; } - if( !restart ) { - G_SpawnBots( Info_ValueForKey( arenainfo, "bots" ), basedelay ); + if (!restart) { + G_SpawnBots(Info_ValueForKey(arenainfo, "bots"), basedelay); } } } diff --git a/code/game/g_local.h b/code/game/g_local.h index 896b92a..7c2e957 100644 --- a/code/game/g_local.h +++ b/code/game/g_local.h @@ -1909,7 +1909,7 @@ extern gentity_t g_entities[MAX_GENTITIES]; //RPG-X: RedTechie //extern int shaketimer; //Global shake timer varible //TiM: NOT NECESSARY! -extern int RPGEntityCount; //Global entity count varible +extern uint32_t RPGEntityCount; //Global entity count varible extern vmCvar_t g_logLevel; extern vmCvar_t g_gametype;