codemp/ui/ui_gameinfo.c File Reference

#include "ui_local.h"

Go to the source code of this file.

Functions

int UI_ParseInfos (char *buf, int max, char *infos[])
void UI_LoadArenas (void)
void UI_LoadBots (void)
char * UI_GetBotInfoByNumber (int num)
char * UI_GetBotInfoByName (const char *name)
int UI_GetNumBots ()
char * UI_GetBotNameByNumber (int num)

Variables

int ui_numBots


Function Documentation

char* UI_GetBotInfoByName const char *  name  ) 
 

Definition at line 308 of file ui_gameinfo.c.

References Info_ValueForKey(), name, NULL, Q_stricmp(), and ui_numBots.

00308                                               {
00309         int             n;
00310         char    *value;
00311 
00312         for ( n = 0; n < ui_numBots ; n++ ) {
00313                 value = Info_ValueForKey( ui_botInfos[n], "name" );
00314                 if ( !Q_stricmp( value, name ) ) {
00315                         return ui_botInfos[n];
00316                 }
00317         }
00318 
00319         return NULL;
00320 }

char* UI_GetBotInfoByNumber int  num  ) 
 

Definition at line 294 of file ui_gameinfo.c.

References NULL, S_COLOR_RED, trap_Print(), ui_numBots, and va().

Referenced by UI_GetBotNameByNumber().

00294                                        {
00295         if( num < 0 || num >= ui_numBots ) {
00296                 trap_Print( va( S_COLOR_RED "Invalid bot number: %i\n", num ) );
00297                 return NULL;
00298         }
00299         return ui_botInfos[num];
00300 }

char* UI_GetBotNameByNumber int  num  ) 
 

Definition at line 327 of file ui_gameinfo.c.

References Info_ValueForKey(), and UI_GetBotInfoByNumber().

00327                                        {
00328         char *info = UI_GetBotInfoByNumber(num);
00329         if (info) {
00330                 return Info_ValueForKey( info, "name" );
00331         }
00332         return "Kyle";
00333 }

int UI_GetNumBots void   ) 
 

Definition at line 322 of file ui_gameinfo.c.

References ui_numBots.

00322                     {
00323         return ui_numBots;
00324 }

void UI_LoadArenas void   ) 
 

Definition at line 125 of file ui_gameinfo.c.

References GT_CTF, GT_CTY, GT_DUEL, GT_FFA, GT_HOLOCRON, GT_JEDIMASTER, GT_POWERDUEL, GT_SIEGE, Info_ValueForKey(), uiInfo_t::mapCount, uiInfo_t::mapList, MAX_MAPS, S_COLOR_YELLOW, strcat(), strcpy(), String_Alloc(), strlen(), strstr(), trap_FS_GetFileList(), trap_Print(), UI_OutOfMemory(), uiInfo, and va().

Referenced by UI_Load().

00125                            {
00126         int                     numdirs;
00127         char            filename[128];
00128         char            dirlist[1024];
00129         char*           dirptr;
00130         int                     i, n;
00131         int                     dirlen;
00132         char            *type;
00133 
00134         ui_numArenas = 0;
00135         uiInfo.mapCount = 0;
00136 
00137         // get all arenas from .arena files
00138         numdirs = trap_FS_GetFileList("scripts", ".arena", dirlist, 1024 );
00139         dirptr  = dirlist;
00140         for (i = 0; i < numdirs; i++, dirptr += dirlen+1) {
00141                 dirlen = strlen(dirptr);
00142                 strcpy(filename, "scripts/");
00143                 strcat(filename, dirptr);
00144                 UI_LoadArenasFromFile(filename);
00145         }
00146 //      trap_Print( va( "%i arenas parsed\n", ui_numArenas ) );
00147         if (UI_OutOfMemory()) {
00148                 trap_Print(S_COLOR_YELLOW"WARNING: not anough memory in pool to load all arenas\n");
00149         }
00150 
00151         for( n = 0; n < ui_numArenas; n++ ) {
00152                 // determine type
00153 
00154                 uiInfo.mapList[uiInfo.mapCount].cinematic = -1;
00155                 uiInfo.mapList[uiInfo.mapCount].mapLoadName = String_Alloc(Info_ValueForKey(ui_arenaInfos[n], "map"));
00156                 uiInfo.mapList[uiInfo.mapCount].mapName = String_Alloc(Info_ValueForKey(ui_arenaInfos[n], "longname"));
00157                 uiInfo.mapList[uiInfo.mapCount].levelShot = -1;
00158                 uiInfo.mapList[uiInfo.mapCount].imageName = String_Alloc(va("levelshots/%s", uiInfo.mapList[uiInfo.mapCount].mapLoadName));
00159                 uiInfo.mapList[uiInfo.mapCount].typeBits = 0;
00160 
00161                 type = Info_ValueForKey( ui_arenaInfos[n], "type" );
00162                 // if no type specified, it will be treated as "ffa"
00163                 if( *type ) {
00164                         if( strstr( type, "ffa" ) ) {
00165                                 uiInfo.mapList[uiInfo.mapCount].typeBits |= (1 << GT_FFA);
00166                         }
00167                         if( strstr( type, "holocron" ) ) {
00168                                 uiInfo.mapList[uiInfo.mapCount].typeBits |= (1 << GT_HOLOCRON);
00169                         }
00170                         if( strstr( type, "jedimaster" ) ) {
00171                                 uiInfo.mapList[uiInfo.mapCount].typeBits |= (1 << GT_JEDIMASTER);
00172                         }
00173                         if( strstr( type, "duel" ) ) {
00174                                 uiInfo.mapList[uiInfo.mapCount].typeBits |= (1 << GT_DUEL);
00175                                 uiInfo.mapList[uiInfo.mapCount].typeBits |= (1 << GT_POWERDUEL);
00176                         }
00177                         if( strstr( type, "powerduel" ) ) {
00178                                 uiInfo.mapList[uiInfo.mapCount].typeBits |= (1 << GT_DUEL);
00179                                 uiInfo.mapList[uiInfo.mapCount].typeBits |= (1 << GT_POWERDUEL);
00180                         }
00181                         if( strstr( type, "siege" ) ) {
00182                                 uiInfo.mapList[uiInfo.mapCount].typeBits |= (1 << GT_SIEGE);
00183                         }
00184                         if( strstr( type, "ctf" ) ) {
00185                                 uiInfo.mapList[uiInfo.mapCount].typeBits |= (1 << GT_CTF);
00186                         }
00187                         if( strstr( type, "cty" ) ) {
00188                                 uiInfo.mapList[uiInfo.mapCount].typeBits |= (1 << GT_CTY);
00189                         }
00190                 } else {
00191                         uiInfo.mapList[uiInfo.mapCount].typeBits |= (1 << GT_FFA);
00192                 }
00193 
00194                 uiInfo.mapCount++;
00195                 if (uiInfo.mapCount >= MAX_MAPS) {
00196                         break;
00197                 }
00198         }
00199 }

void UI_LoadBots void   ) 
 

Definition at line 257 of file ui_gameinfo.c.

References CVAR_INIT, CVAR_ROM, strcat(), strcpy(), vmCvar_t::string, strlen(), trap_Cvar_Register(), trap_FS_GetFileList(), and ui_numBots.

Referenced by _UI_Init(), and UI_Load().

00257                          {
00258         vmCvar_t        botsFile;
00259         int                     numdirs;
00260         char            filename[128];
00261         char            dirlist[1024];
00262         char*           dirptr;
00263         int                     i;
00264         int                     dirlen;
00265 
00266         ui_numBots = 0;
00267 
00268         trap_Cvar_Register( &botsFile, "g_botsFile", "", CVAR_INIT|CVAR_ROM );
00269         if( *botsFile.string ) {
00270                 UI_LoadBotsFromFile(botsFile.string);
00271         }
00272         else {
00273                 UI_LoadBotsFromFile("botfiles/bots.txt");
00274         }
00275 
00276         // get all bots from .bot files
00277         numdirs = trap_FS_GetFileList("scripts", ".bot", dirlist, 1024 );
00278         dirptr  = dirlist;
00279         for (i = 0; i < numdirs; i++, dirptr += dirlen+1) {
00280                 dirlen = strlen(dirptr);
00281                 strcpy(filename, "scripts/");
00282                 strcat(filename, dirptr);
00283                 UI_LoadBotsFromFile(filename);
00284         }
00285 //      trap_Print( va( "%i bots parsed\n", ui_numBots ) );
00286 }

int UI_ParseInfos char *  buf,
int  max,
char *  infos[]
 

Definition at line 26 of file ui_gameinfo.c.

References COM_Parse(), COM_ParseExt(), Com_Printf(), FS_READ, Info_SetValueForKey(), Info_ValueForKey(), MAX_ARENAS, MAX_INFO_STRING, MAX_TOKEN_CHARS, Q_strncpyz(), qfalse, qtrue, strcmp(), strcpy(), strlen(), trap_Cvar_VariableValue(), trap_FS_FCloseFile(), trap_FS_FOpenFile(), UI_Alloc(), and va().

00026                                                        {
00027         char    *token;
00028         int             count;
00029         char    key[MAX_TOKEN_CHARS];
00030         char    info[MAX_INFO_STRING];
00031 
00032         count = 0;
00033 
00034         while ( 1 ) {
00035                 token = COM_Parse( (const char **)&buf );
00036                 if ( !token[0] ) {
00037                         break;
00038                 }
00039                 if ( strcmp( token, "{" ) ) {
00040                         Com_Printf( "Missing { in info file\n" );
00041                         break;
00042                 }
00043 
00044                 if ( count == max ) {
00045                         Com_Printf( "Max infos exceeded\n" );
00046                         break;
00047                 }
00048 
00049                 info[0] = '\0';
00050                 while ( 1 ) {
00051                         token = COM_ParseExt( (const char **)&buf, qtrue );
00052                         if ( !token[0] ) {
00053                                 Com_Printf( "Unexpected end of info file\n" );
00054                                 break;
00055                         }
00056                         if ( !strcmp( token, "}" ) ) {
00057                                 break;
00058                         }
00059                         Q_strncpyz( key, token, sizeof( key ) );
00060 
00061                         token = COM_ParseExt( (const char **)&buf, qfalse );
00062                         if ( !token[0] ) {
00063                                 strcpy( token, "<NULL>" );
00064                         }
00065                         Info_SetValueForKey( info, key, token );
00066                 }
00067                 //NOTE: extra space for arena number
00068                 infos[count] = (char *) UI_Alloc(strlen(info) + strlen("\\num\\") + strlen(va("%d", MAX_ARENAS)) + 1);
00069                 if (infos[count]) {
00070                         strcpy(infos[count], info);
00071 #ifndef FINAL_BUILD
00072                         if (trap_Cvar_VariableValue("com_buildScript"))
00073                         {
00074                                 char *botFile = Info_ValueForKey(info, "personality");
00075                                 if (botFile && botFile[0])
00076                                 {
00077                                         int fh = 0;
00078                                         trap_FS_FOpenFile(botFile, &fh, FS_READ);
00079                                         if (fh)
00080                                         {
00081                                                 trap_FS_FCloseFile(fh);
00082                                         }
00083                                 }
00084                         }
00085 #endif
00086                         count++;
00087                 }
00088         }
00089         return count;
00090 }


Variable Documentation

int ui_numBots
 

Definition at line 15 of file ui_gameinfo.c.

Referenced by UI_GetBotInfoByName(), UI_GetBotInfoByNumber(), UI_GetNumBots(), and UI_LoadBots().