Debian Codegraph @

code/ui/ui_gameinfo.c

raw symbols SCIP
1 /*
2 ===========================================================================
3 Copyright (C) 1999-2005 Id Software, Inc.
4
5 This file is part of Quake III Arena source code.
6
7 Quake III Arena source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 Quake III Arena source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Quake III Arena source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
21 */
22 //
23 //
24 // gameinfo.c
25 //
26
27 #include "ui_local.h"
28
29
30 //
31 // arena and bot info
32 //
33
34
35 int ui_numBots;
36 static char *ui_botInfos[MAX_BOTS];
37
38 static int ui_numArenas;
39 static char *ui_arenaInfos[MAX_ARENAS];
40
41 #ifndef MISSIONPACK
42 static int ui_numSinglePlayerArenas;
43 static int ui_numSpecialSinglePlayerArenas;
44 #endif
45
46 /*
47 ===============
48 UI_ParseInfos
49 ===============
50 */
51 int UI_ParseInfos( char *buf, int max, char *infos[] ) {
52 char *token;
53 int count;
54 char key[MAX_TOKEN_CHARS];
55 char info[MAX_INFO_STRING];
56
57 count = 0;
58
59 while ( 1 ) {
60 token = COM_Parse( &buf );
61 if ( !token[0] ) {
62 break;
63 }
64 if ( strcmp( token, "{" ) ) {
65 Com_Printf( "Missing { in info file\n" );
66 break;
67 }
68
69 if ( count == max ) {
70 Com_Printf( "Max infos exceeded\n" );
71 break;
72 }
73
74 info[0] = '\0';
75 while ( 1 ) {
76 token = COM_ParseExt( &buf, qtrue );
77 if ( !token[0] ) {
78 Com_Printf( "Unexpected end of info file\n" );
79 break;
80 }
81 if ( !strcmp( token, "}" ) ) {
82 break;
83 }
84 Q_strncpyz( key, token, sizeof( key ) );
85
86 token = COM_ParseExt( &buf, qfalse );
87 if ( !token[0] ) {
88 strcpy( token, "<NULL>" );
89 }
90 Info_SetValueForKey( info, key, token );
91 }
92 //NOTE: extra space for arena number
93 infos[count] = UI_Alloc(strlen(info) + strlen("\\num\\") + strlen(va("%d", MAX_ARENAS)) + 1);
94 if (infos[count]) {
95 strcpy(infos[count], info);
96 count++;
97 }
98 }
99 return count;
100 }
101
102 /*
103 ===============
104 UI_LoadArenasFromFile
105 ===============
106 */
107 static void UI_LoadArenasFromFile( char *filename ) {
108 int len;
109 fileHandle_t f;
110 char buf[MAX_ARENAS_TEXT];
111
112 len = trap_FS_FOpenFile( filename, &f, FS_READ );
113 if ( !f ) {
114 trap_Print( va( S_COLOR_RED "file not found: %s\n", filename ) );
115 return;
116 }
117 if ( len >= MAX_ARENAS_TEXT ) {
118 trap_Print( va( S_COLOR_RED "file too large: %s is %i, max allowed is %i\n", filename, len, MAX_ARENAS_TEXT ) );
119 trap_FS_FCloseFile( f );
120 return;
121 }
122
123 trap_FS_Read( buf, len, f );
124 buf[len] = 0;
125 trap_FS_FCloseFile( f );
126
127 ui_numArenas += UI_ParseInfos( buf, MAX_ARENAS - ui_numArenas, &ui_arenaInfos[ui_numArenas] );
128 }
129
130 /*
131 ===============
132 UI_LoadArenas
133 ===============
134 */
135 void UI_LoadArenas( void ) {
136 int numdirs;
137 vmCvar_t arenasFile;
138 char filename[128];
139 char dirlist[4096];
140 char* dirptr;
141 int i;
142 int dirlen;
143
144 ui_numArenas = 0;
145
146 trap_Cvar_Register( &arenasFile, "g_arenasFile", "", CVAR_INIT|CVAR_ROM );
147 if( *arenasFile.string ) {
148 UI_LoadArenasFromFile(arenasFile.string);
149 }
150 else {
151 UI_LoadArenasFromFile("scripts/arenas.txt");
152 }
153
154 // get all arenas from .arena files
155 numdirs = trap_FS_GetFileList("scripts", ".arena", dirlist, 4096 );
156 dirptr = dirlist;
157 for (i = 0; i < numdirs; i++, dirptr += dirlen+1) {
158 dirlen = strlen(dirptr);
159 strcpy(filename, "scripts/");
160 strcat(filename, dirptr);
161 UI_LoadArenasFromFile(filename);
162 }
163 trap_Print( va( "%i arenas parsed\n", ui_numArenas ) );
164 if (UI_OutOfMemory()) {
165 trap_Print(S_COLOR_YELLOW"WARNING: not enough memory in pool to load all arenas\n");
166 }
167 }
168
169 /*
170 ===============
171 UI_LoadArenasIntoMapList
172 ===============
173 */
174 void UI_LoadArenasIntoMapList( void ) {
175 int n;
176 char *type;
177
178 uiInfo.mapCount = 0;
179
180 for( n = 0; n < ui_numArenas; n++ ) {
181 // determine type
182
183 uiInfo.mapList[uiInfo.mapCount].cinematic = -1;
184 uiInfo.mapList[uiInfo.mapCount].mapLoadName = String_Alloc(Info_ValueForKey(ui_arenaInfos[n], "map"));
185 uiInfo.mapList[uiInfo.mapCount].mapName = String_Alloc(Info_ValueForKey(ui_arenaInfos[n], "longname"));
186 uiInfo.mapList[uiInfo.mapCount].levelShot = -1;
187 uiInfo.mapList[uiInfo.mapCount].imageName = String_Alloc(va("levelshots/%s", uiInfo.mapList[uiInfo.mapCount].mapLoadName));
188 uiInfo.mapList[uiInfo.mapCount].typeBits = 0;
189
190 type = Info_ValueForKey( ui_arenaInfos[n], "type" );
191 // if no type specified, it will be treated as "ffa"
192 if( *type ) {
193 if( strstr( type, "ffa" ) ) {
194 uiInfo.mapList[uiInfo.mapCount].typeBits |= (1 << GT_FFA);
195 }
196 if( strstr( type, "tourney" ) ) {
197 uiInfo.mapList[uiInfo.mapCount].typeBits |= (1 << GT_TOURNAMENT);
198 }
199 if( strstr( type, "ctf" ) ) {
200 uiInfo.mapList[uiInfo.mapCount].typeBits |= (1 << GT_CTF);
201 }
202 if( strstr( type, "oneflag" ) ) {
203 uiInfo.mapList[uiInfo.mapCount].typeBits |= (1 << GT_1FCTF);
204 }
205 if( strstr( type, "overload" ) ) {
206 uiInfo.mapList[uiInfo.mapCount].typeBits |= (1 << GT_OBELISK);
207 }
208 if( strstr( type, "harvester" ) ) {
209 uiInfo.mapList[uiInfo.mapCount].typeBits |= (1 << GT_HARVESTER);
210 }
211 } else {
212 uiInfo.mapList[uiInfo.mapCount].typeBits |= (1 << GT_FFA);
213 }
214
215 uiInfo.mapCount++;
216 if (uiInfo.mapCount >= MAX_MAPS) {
217 break;
218 }
219 }
220 }
221
222
223 /*
224 ===============
225 UI_LoadBotsFromFile
226 ===============
227 */
228 static void UI_LoadBotsFromFile( char *filename ) {
229 int len;
230 fileHandle_t f;
231 char buf[MAX_BOTS_TEXT];
232
233 len = trap_FS_FOpenFile( filename, &f, FS_READ );
234 if ( !f ) {
235 trap_Print( va( S_COLOR_RED "file not found: %s\n", filename ) );
236 return;
237 }
238 if ( len >= MAX_BOTS_TEXT ) {
239 trap_Print( va( S_COLOR_RED "file too large: %s is %i, max allowed is %i\n", filename, len, MAX_BOTS_TEXT ) );
240 trap_FS_FCloseFile( f );
241 return;
242 }
243
244 trap_FS_Read( buf, len, f );
245 buf[len] = 0;
246 trap_FS_FCloseFile( f );
247
248 COM_Compress(buf);
249
250 ui_numBots += UI_ParseInfos( buf, MAX_BOTS - ui_numBots, &ui_botInfos[ui_numBots] );
251 }
252
253 /*
254 ===============
255 UI_LoadBots
256 ===============
257 */
258 void UI_LoadBots( void ) {
259 vmCvar_t botsFile;
260 int numdirs;
261 char filename[128];
262 char dirlist[1024];
263 char* dirptr;
264 int i;
265 int dirlen;
266
267 ui_numBots = 0;
268
269 trap_Cvar_Register( &botsFile, "g_botsFile", "", CVAR_INIT|CVAR_ROM );
270 if( *botsFile.string ) {
271 UI_LoadBotsFromFile(botsFile.string);
272 }
273 else {
274 UI_LoadBotsFromFile("scripts/bots.txt");
275 }
276
277 // get all bots from .bot files
278 numdirs = trap_FS_GetFileList("scripts", ".bot", dirlist, 1024 );
279 dirptr = dirlist;
280 for (i = 0; i < numdirs; i++, dirptr += dirlen+1) {
281 dirlen = strlen(dirptr);
282 strcpy(filename, "scripts/");
283 strcat(filename, dirptr);
284 UI_LoadBotsFromFile(filename);
285 }
286 trap_Print( va( "%i bots parsed\n", ui_numBots ) );
287 }
288
289
290 /*
291 ===============
292 UI_GetBotInfoByNumber
293 ===============
294 */
295 char *UI_GetBotInfoByNumber( int num ) {
296 if( num < 0 || num >= ui_numBots ) {
297 trap_Print( va( S_COLOR_RED "Invalid bot number: %i\n", num ) );
298 return NULL;
299 }
300 return ui_botInfos[num];
301 }
302
303
304 /*
305 ===============
306 UI_GetBotInfoByName
307 ===============
308 */
309 char *UI_GetBotInfoByName( const char *name ) {
310 int n;
311 char *value;
312
313 for ( n = 0; n < ui_numBots ; n++ ) {
314 value = Info_ValueForKey( ui_botInfos[n], "name" );
315 if ( !Q_stricmp( value, name ) ) {
316 return ui_botInfos[n];
317 }
318 }
319
320 return NULL;
321 }
322
323 int UI_GetNumBots( void ) {
324 return ui_numBots;
325 }
326
327
328 char *UI_GetBotNameByNumber( int num ) {
329 char *info = UI_GetBotInfoByNumber(num);
330 if (info) {
331 return Info_ValueForKey( info, "name" );
332 }
333 return "Sarge";
334 }