/* =============== UI_Mods_LoadModsFromFile =============== */ static void UI_Mods_LoadModsFromFile( char *filename ) { int len; fileHandle_t f; char buf[1024]; len = UI_trap_FS_FOpenFile( filename, &f, FS_READ ); if ( !f ) { UI_trap_Print( va( S_COLOR_RED "file not found: %s\n", filename ) ); return; } if ( len >= sizeof(buf) ) { UI_trap_Print( va( S_COLOR_RED "file too large: %s is %i, max allowed is %i", filename, len, sizeof(buf) ) ); UI_trap_FS_FCloseFile( f ); return; } UI_trap_FS_Read( buf, len, f ); buf[len] = 0; UI_trap_FS_FCloseFile( f ); len = strlen( filename ); if( !Q_stricmp(filename + len - 4,".mod") ) { filename[len-4] = '\0'; } UI_Mods_ParseInfos( filename, buf ); }
/* =============== UI_Mods_LoadMods =============== */ static void UI_Mods_LoadMods( void ) { int numdirs; char dirlist[2048]; char *dirptr; char *descptr; int i; int dirlen; s_mods.list.itemnames = (const char **)s_mods.descriptionList; s_mods.descriptionPtr = s_mods.description; s_mods.fs_gamePtr = s_mods.fs_game; // always start off with baseq3 s_mods.list.numitems = 1; s_mods.list.itemnames[0] = s_mods.descriptionList[0] = "Quake III Arena"; s_mods.fs_gameList[0] = ""; numdirs = UI_trap_FS_GetFileList( "$modlist", "", dirlist, sizeof(dirlist) ); dirptr = dirlist; for( i = 0; i < numdirs; i++ ) { dirlen = strlen( dirptr ) + 1; descptr = dirptr + dirlen; UI_Mods_ParseInfos( dirptr, descptr); dirptr += dirlen + strlen(descptr) + 1; } UI_trap_Print( va( "%i mods parsed\n", s_mods.list.numitems ) ); if (s_mods.list.numitems > MAX_MODS) { s_mods.list.numitems = MAX_MODS; } }
/* =============== UI_SPUnlock_f =============== */ void UI_SPUnlock_f( void ) { char arenaKey[16]; char scores[MAX_INFO_VALUE]; int level; int tier; // get scores for skill 1 UI_trap_Cvar_VariableStringBuffer( "g_spScores1", scores, MAX_INFO_VALUE ); // update scores for( level = 0; level < ui_numSinglePlayerArenas + ui_numSpecialSinglePlayerArenas; level++ ) { Com_sprintf( arenaKey, sizeof( arenaKey ), "l%i", level ); Info_SetValueForKey( scores, arenaKey, "1" ); } UI_trap_Cvar_Set( "g_spScores1", scores ); // unlock cinematics for( tier = 1; tier <= 8; tier++ ) { UI_ShowTierVideo( tier ); } UI_trap_Print( "All levels unlocked at skill level 1\n" ); UI_SPLevelMenu_ReInit(); }
/* =============== UI_GetBotInfoByNumber =============== */ char *UI_GetBotInfoByNumber( int num ) { if( num < 0 || num >= ui_numBots ) { UI_trap_Print( va( S_COLOR_RED "Invalid bot number: %i\n", num ) ); return NULL; } return ui_botInfos[num]; }
/* =============== UI_LoadBots =============== */ static void UI_LoadBots( void ) { vmCvar_t botsFile; int numdirs; char filename[128]; char dirlist[1024]; char* dirptr; int i; int dirlen; ui_numBots = 0; UI_trap_Cvar_Register( &botsFile, "g_botsFile", "", CVAR_INIT|CVAR_ROM ); if( *botsFile.string ) { UI_LoadBotsFromFile(botsFile.string); } else { UI_LoadBotsFromFile("scripts/bots.txt"); } // get all bots from .bot files numdirs = UI_trap_FS_GetFileList("scripts", ".bot", dirlist, 1024 ); dirptr = dirlist; for (i = 0; i < numdirs; i++, dirptr += dirlen+1) { dirlen = strlen(dirptr); strcpy(filename, "scripts/"); strcat(filename, dirptr); UI_LoadBotsFromFile(filename); } UI_trap_Print( va( "%i bots parsed\n", ui_numBots ) ); }
/* =============== UI_LoadArenasFromFile =============== */ static void UI_LoadArenasFromFile( char *filename ) { int len; fileHandle_t f; char buf[MAX_ARENAS_TEXT]; len = UI_trap_FS_FOpenFile( filename, &f, FS_READ ); if ( !f ) { UI_trap_Print( va( S_COLOR_RED "file not found: %s\n", filename ) ); return; } if ( len >= MAX_ARENAS_TEXT ) { UI_trap_Print( va( S_COLOR_RED "file too large: %s is %i, max allowed is %i", filename, len, MAX_ARENAS_TEXT ) ); UI_trap_FS_FCloseFile( f ); return; } UI_trap_FS_Read( buf, len, f ); buf[len] = 0; UI_trap_FS_FCloseFile( f ); ui_numArenas += UI_ParseInfos( buf, MAX_ARENAS - ui_numArenas, &ui_arenaInfos[ui_numArenas] ); }
/* =============== UI_LoadBotsFromFile =============== */ static void UI_LoadBotsFromFile( char *filename ) { int len; fileHandle_t f; char buf[MAX_BOTS_TEXT]; len = UI_trap_FS_FOpenFile( filename, &f, FS_READ ); if ( !f ) { UI_trap_Print( va( S_COLOR_RED "file not found: %s\n", filename ) ); return; } if ( len >= MAX_BOTS_TEXT ) { UI_trap_Print( va( S_COLOR_RED "file too large: %s is %i, max allowed is %i", filename, len, MAX_BOTS_TEXT ) ); UI_trap_FS_FCloseFile( f ); return; } UI_trap_FS_Read( buf, len, f ); buf[len] = 0; UI_trap_FS_FCloseFile( f ); ui_numBots += UI_ParseInfos( buf, MAX_BOTS - ui_numBots, &ui_botInfos[ui_numBots] ); if (outOfMemory) UI_trap_Print(S_COLOR_YELLOW"WARNING: not anough memory in pool to load all bots\n"); }
/* =============== UI_SPUnlockMedals_f =============== */ void UI_SPUnlockMedals_f( void ) { int n; char key[16]; char awardData[MAX_INFO_VALUE]; UI_trap_Cvar_VariableStringBuffer( "g_spAwards", awardData, MAX_INFO_VALUE ); for( n = 0; n < 6; n++ ) { Com_sprintf( key, sizeof(key), "a%i", n ); Info_SetValueForKey( awardData, key, "100" ); } UI_trap_Cvar_Set( "g_spAwards", awardData ); UI_trap_Print( "All levels unlocked at 100\n" ); }
/* =============== UI_GetArenaInfoByNumber =============== */ const char *UI_GetArenaInfoByNumber( int num ) { int n; char *value; if( num < 0 || num >= ui_numArenas ) { UI_trap_Print( va( S_COLOR_RED "Invalid arena number: %i\n", num ) ); return NULL; } for( n = 0; n < ui_numArenas; n++ ) { value = Info_ValueForKey( ui_arenaInfos[n], "num" ); if( *value && atoi(value) == num ) { return ui_arenaInfos[n]; } } return NULL; }
/* =============== UI_LogAwardData =============== */ void UI_LogAwardData( int award, int data ) { char key[16]; char awardData[MAX_INFO_VALUE]; int oldValue; if( data == 0 ) { return; } if( award > AWARD_PERFECT ) { UI_trap_Print( va( S_COLOR_RED "Bad award %i in UI_LogAwardData\n", award ) ); return; } UI_trap_Cvar_VariableStringBuffer( "g_spAwards", awardData, sizeof(awardData) ); Com_sprintf( key, sizeof(key), "a%i", award ); oldValue = atoi( Info_ValueForKey( awardData, key ) ); Info_SetValueForKey( awardData, key, va( "%i", oldValue + data ) ); UI_trap_Cvar_Set( "g_spAwards", awardData ); }
/* =============== UI_LoadArenas =============== */ static void UI_LoadArenas( void ) { int numdirs; vmCvar_t arenasFile; char filename[128]; char dirlist[1024]; char* dirptr; int i, n; int dirlen; char *type; char *tag; int singlePlayerNum, specialNum, otherNum; ui_numArenas = 0; UI_trap_Cvar_Register( &arenasFile, "g_arenasFile", "", CVAR_INIT|CVAR_ROM ); if( *arenasFile.string ) { UI_LoadArenasFromFile(arenasFile.string); } else { UI_LoadArenasFromFile("scripts/arenas.txt"); } // get all arenas from .arena files numdirs = UI_trap_FS_GetFileList("scripts", ".arena", dirlist, 1024 ); dirptr = dirlist; for (i = 0; i < numdirs; i++, dirptr += dirlen+1) { dirlen = strlen(dirptr); strcpy(filename, "scripts/"); strcat(filename, dirptr); UI_LoadArenasFromFile(filename); } UI_trap_Print( va( "%i arenas parsed\n", ui_numArenas ) ); if (outOfMemory) UI_trap_Print(S_COLOR_YELLOW"WARNING: not anough memory in pool to load all arenas\n"); // set initial numbers for( n = 0; n < ui_numArenas; n++ ) { Info_SetValueForKey( ui_arenaInfos[n], "num", va( "%i", n ) ); } // go through and count single players levels ui_numSinglePlayerArenas = 0; ui_numSpecialSinglePlayerArenas = 0; for( n = 0; n < ui_numArenas; n++ ) { // determine type type = Info_ValueForKey( ui_arenaInfos[n], "type" ); // if no type specified, it will be treated as "ffa" if( !*type ) { continue; } if( strstr( type, "single" ) ) { // check for special single player arenas (training, final) tag = Info_ValueForKey( ui_arenaInfos[n], "special" ); if( *tag ) { ui_numSpecialSinglePlayerArenas++; continue; } ui_numSinglePlayerArenas++; } } n = ui_numSinglePlayerArenas % ARENAS_PER_TIER; if( n != 0 ) { ui_numSinglePlayerArenas -= n; UI_trap_Print( va( "%i arenas ignored to make count divisible by %i\n", n, ARENAS_PER_TIER ) ); } // go through once more and assign number to the levels singlePlayerNum = 0; specialNum = singlePlayerNum + ui_numSinglePlayerArenas; otherNum = specialNum + ui_numSpecialSinglePlayerArenas; for( n = 0; n < ui_numArenas; n++ ) { // determine type type = Info_ValueForKey( ui_arenaInfos[n], "type" ); // if no type specified, it will be treated as "ffa" if( *type ) { if( strstr( type, "single" ) ) { // check for special single player arenas (training, final) tag = Info_ValueForKey( ui_arenaInfos[n], "special" ); if( *tag ) { Info_SetValueForKey( ui_arenaInfos[n], "num", va( "%i", specialNum++ ) ); continue; } Info_SetValueForKey( ui_arenaInfos[n], "num", va( "%i", singlePlayerNum++ ) ); continue; } } Info_SetValueForKey( ui_arenaInfos[n], "num", va( "%i", otherNum++ ) ); } }