Debian Codegraph @

code/ui/ui_main.c

raw ◀ ▶
1 Debian patch touch this file
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 =======================================================================
25
26 USER INTERFACE MAIN
27
28 =======================================================================
29 */
30
31 // use this to get a demo build without an explicit demo build, i.e. to get the demo ui files to build
32 //#define PRE_RELEASE_TADEMO
33
34 #include "ui_local.h"
35
36 uiInfo_t uiInfo;
37
38 static const char *MonthAbbrev[] = {
39 "Jan","Feb","Mar",
40 "Apr","May","Jun",
41 "Jul","Aug","Sep",
42 "Oct","Nov","Dec"
43 };
44
45
46 static const char *skillLevels[] = {
47 "I Can Win",
48 "Bring It On",
49 "Hurt Me Plenty",
50 "Hardcore",
51 "Nightmare"
52 };
53
54 static const int numSkillLevels = sizeof(skillLevels) / sizeof(const char*);
55
56 /*
57 *These sources are currently hardcoded in the engine.
58 *
59 *Empty options will not be displayed or circled to.
60 */
61 static const char *netSources[] = {
62 "Local",
63 "",
64 "Internet",
65 "Favorites"
66 };
67 static const int numNetSources = sizeof(netSources) / sizeof(const char*);
68
69 static const serverFilter_t serverFilters[] = {
70 {"All", "" },
71 {"OpenArena", "" },
72 {"Missionpack", "missionpack" },
73 {"Rocket Arena", "arena" },
74 {"Alliance", "alliance20" },
75 {"Weapons Factory Arena", "wfa" },
76 {"OSP", "osp" },
77 };
78
79 static const char *teamArenaGameTypes[] = {
80 "FFA",
81 "TOURNAMENT",
82 "SP",
83 "TEAM DM",
84 "CTF",
85 "1FCTF",
86 "OVERLOAD",
87 "HARVESTER",
88 "ELIMINATION",
89 "CTFELIMINATION",
90 "LMS",
91 "DOUBLE D",
92 "DOMINATION"
93 };
94
95 static int const numTeamArenaGameTypes = sizeof(teamArenaGameTypes) / sizeof(const char*);
96
97
98 static const char *teamArenaGameNames[] = {
99 "Free For All",
100 "Tournament",
101 "Single Player",
102 "Team Deathmatch",
103 "Capture the Flag",
104 "One Flag CTF",
105 "Overload",
106 "Harvester",
107 "Elimination",
108 "CTF Elimination",
109 "Last Man Standing",
110 "Double Domination",
111 "Domination"
112 };
113
114 static int const numTeamArenaGameNames = sizeof(teamArenaGameNames) / sizeof(const char*);
115
116
117 static const int numServerFilters = sizeof(serverFilters) / sizeof(serverFilter_t);
118
119 static const char *sortKeys[] = {
120 "Server Name",
121 "Map Name",
122 "Open Player Spots",
123 "Game Type",
124 "Ping Time"
125 };
126 static const int numSortKeys = sizeof(sortKeys) / sizeof(const char*);
127
128 static char* netnames[] = {
129 "???",
130 "UDP",
131 NULL
132 };
133
134 #ifndef MISSIONPACK // bk001206
135 static char quake3worldMessage[] = "Visit www.openarena.ws - News, Community, Events, Files";
136 #endif
137
138 static int gamecodetoui[] = {4,2,3,0,5,1,6};
139 static int uitogamecode[] = {4,6,2,3,1,5,7};
140
141
142 static void UI_StartServerRefresh(qboolean full);
143 static void UI_StopServerRefresh( void );
144 static void UI_DoServerRefresh( void );
145 static void UI_FeederSelection(float feederID, int index);
146 static void UI_BuildServerDisplayList(qboolean force);
147 static void UI_BuildServerStatus(qboolean force);
148 static void UI_BuildFindPlayerList(qboolean force);
149 static int QDECL UI_ServersQsortCompare( const void *arg1, const void *arg2 );
150 static int UI_MapCountByGameType(qboolean singlePlayer);
151 static int UI_HeadCountByTeam( void );
152 static void UI_ParseGameInfo(const char *teamFile);
153 static void UI_ParseTeamInfo(const char *teamFile);
154 static const char *UI_SelectedMap(int index, int *actual);
155 static const char *UI_SelectedHead(int index, int *actual);
156 static int UI_GetIndexFromSelection(int actual);
157
158 int ProcessNewUI( int command, int arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6 );
159
160 /*
161 ================
162 vmMain
163
164 This is the only way control passes into the module.
165 This must be the very first function compiled into the .qvm file
166 ================
167 */
168 vmCvar_t ui_new;
169 vmCvar_t ui_debug;
170 vmCvar_t ui_initialized;
171 vmCvar_t ui_teamArenaFirstRun;
172
173 void _UI_Init( qboolean );
174 void _UI_Shutdown( void );
175 void _UI_KeyEvent( int key, qboolean down );
176 void _UI_MouseEvent( int dx, int dy );
177 void _UI_Refresh( int realtime );
178 qboolean _UI_IsFullscreen( void );
•179 Q_EXPORT intptr_t vmMain( int command, int arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10, int arg11 ) {
180 switch ( command ) {
181 case UI_GETAPIVERSION:
182 return UI_API_VERSION;
183
184 case UI_INIT:
185 _UI_Init(arg0);
186 return 0;
187
188 case UI_SHUTDOWN:
189 _UI_Shutdown();
190 return 0;
191
192 case UI_KEY_EVENT:
193 _UI_KeyEvent( arg0, arg1 );
194 return 0;
195
196 case UI_MOUSE_EVENT:
197 _UI_MouseEvent( arg0, arg1 );
198 return 0;
199
200 case UI_REFRESH:
201 _UI_Refresh( arg0 );
202 return 0;
203
204 case UI_IS_FULLSCREEN:
205 return _UI_IsFullscreen();
206
207 case UI_SET_ACTIVE_MENU:
208 _UI_SetActiveMenu( arg0 );
209 return 0;
210
211 case UI_CONSOLE_COMMAND:
212 return UI_ConsoleCommand(arg0);
213
214 case UI_DRAW_CONNECT_SCREEN:
215 UI_DrawConnectScreen( arg0 );
216 return 0;
217 case UI_HASUNIQUECDKEY: // mod authors need to observe this
218 return qtrue; // bk010117 - change this to qfalse for mods!
219
220 }
221
222 return -1;
223 }
224
225
226
227 void AssetCache( void ) {
228 int n;
229 //if (Assets.textFont == NULL) {
230 //}
231 //Assets.background = trap_R_RegisterShaderNoMip( ASSET_BACKGROUND );
232 //Com_Printf("Menu Size: %i bytes\n", sizeof(Menus));
233 uiInfo.uiDC.Assets.gradientBar = trap_R_RegisterShaderNoMip( ASSET_GRADIENTBAR );
234 uiInfo.uiDC.Assets.fxBasePic = trap_R_RegisterShaderNoMip( ART_FX_BASE );
235 uiInfo.uiDC.Assets.fxPic[0] = trap_R_RegisterShaderNoMip( ART_FX_RED );
236 uiInfo.uiDC.Assets.fxPic[1] = trap_R_RegisterShaderNoMip( ART_FX_YELLOW );
237 uiInfo.uiDC.Assets.fxPic[2] = trap_R_RegisterShaderNoMip( ART_FX_GREEN );
238 uiInfo.uiDC.Assets.fxPic[3] = trap_R_RegisterShaderNoMip( ART_FX_TEAL );
239 uiInfo.uiDC.Assets.fxPic[4] = trap_R_RegisterShaderNoMip( ART_FX_BLUE );
240 uiInfo.uiDC.Assets.fxPic[5] = trap_R_RegisterShaderNoMip( ART_FX_CYAN );
241 uiInfo.uiDC.Assets.fxPic[6] = trap_R_RegisterShaderNoMip( ART_FX_WHITE );
242 uiInfo.uiDC.Assets.scrollBar = trap_R_RegisterShaderNoMip( ASSET_SCROLLBAR );
243 uiInfo.uiDC.Assets.scrollBarArrowDown = trap_R_RegisterShaderNoMip( ASSET_SCROLLBAR_ARROWDOWN );
244 uiInfo.uiDC.Assets.scrollBarArrowUp = trap_R_RegisterShaderNoMip( ASSET_SCROLLBAR_ARROWUP );
245 uiInfo.uiDC.Assets.scrollBarArrowLeft = trap_R_RegisterShaderNoMip( ASSET_SCROLLBAR_ARROWLEFT );
246 uiInfo.uiDC.Assets.scrollBarArrowRight = trap_R_RegisterShaderNoMip( ASSET_SCROLLBAR_ARROWRIGHT );
247 uiInfo.uiDC.Assets.scrollBarThumb = trap_R_RegisterShaderNoMip( ASSET_SCROLL_THUMB );
248 uiInfo.uiDC.Assets.sliderBar = trap_R_RegisterShaderNoMip( ASSET_SLIDER_BAR );
249 uiInfo.uiDC.Assets.sliderThumb = trap_R_RegisterShaderNoMip( ASSET_SLIDER_THUMB );
250
251 for( n = 0; n < NUM_CROSSHAIRS; n++ ) {
252 uiInfo.uiDC.Assets.crosshairShader[n] = trap_R_RegisterShaderNoMip( va("gfx/2d/crosshair%c", 'a' + n ) );
253 }
254
255 uiInfo.newHighScoreSound = trap_S_RegisterSound("sound/feedback/voc_newhighscore.wav", qfalse);
256 }
257
258 void _UI_DrawSides(float x, float y, float w, float h, float size) {
259 UI_AdjustFrom640( &x, &y, &w, &h );
260 size *= uiInfo.uiDC.xscale;
261 trap_R_DrawStretchPic( x, y, size, h, 0, 0, 0, 0, uiInfo.uiDC.whiteShader );
262 trap_R_DrawStretchPic( x + w - size, y, size, h, 0, 0, 0, 0, uiInfo.uiDC.whiteShader );
263 }
264
265 void _UI_DrawTopBottom(float x, float y, float w, float h, float size) {
266 UI_AdjustFrom640( &x, &y, &w, &h );
267 size *= uiInfo.uiDC.yscale;
268 trap_R_DrawStretchPic( x, y, w, size, 0, 0, 0, 0, uiInfo.uiDC.whiteShader );
269 trap_R_DrawStretchPic( x, y + h - size, w, size, 0, 0, 0, 0, uiInfo.uiDC.whiteShader );
270 }
271 /*
272 ================
273 UI_DrawRect
274
275 Coordinates are 640*480 virtual values
276 =================
277 */
278 void _UI_DrawRect( float x, float y, float width, float height, float size, const float *color ) {
279 trap_R_SetColor( color );
280
281 _UI_DrawTopBottom(x, y, width, height, size);
282 _UI_DrawSides(x, y, width, height, size);
283
284 trap_R_SetColor( NULL );
285 }
286
287 int Text_Width(const char *text, float scale, int limit) {
288 int count,len;
289 float out;
290 glyphInfo_t *glyph;
291 float useScale;
292 const char *s = text;
293 fontInfo_t *font = &uiInfo.uiDC.Assets.textFont;
294 if (scale <= ui_smallFont.value) {
295 font = &uiInfo.uiDC.Assets.smallFont;
296 } else if (scale >= ui_bigFont.value) {
297 font = &uiInfo.uiDC.Assets.bigFont;
298 }
299 useScale = scale * font->glyphScale;
300 out = 0;
301 if (text) {
302 len = strlen(text);
303 if (limit > 0 && len > limit) {
304 len = limit;
305 }
306 count = 0;
307 while (s && *s && count < len) {
308 if ( Q_IsColorString(s) ) {
309 s += 2;
310 continue;
311 } else {
312 glyph = &font->glyphs[(int)*s];
313 out += glyph->xSkip;
314 s++;
315 count++;
316 }
317 }
318 }
319 return out * useScale;
320 }
321
322 int Text_Height(const char *text, float scale, int limit) {
323 int len, count;
324 float max;
325 glyphInfo_t *glyph;
326 float useScale;
327 const char *s = text; // bk001206 - unsigned
328 fontInfo_t *font = &uiInfo.uiDC.Assets.textFont;
329 if (scale <= ui_smallFont.value) {
330 font = &uiInfo.uiDC.Assets.smallFont;
331 } else if (scale >= ui_bigFont.value) {
332 font = &uiInfo.uiDC.Assets.bigFont;
333 }
334 useScale = scale * font->glyphScale;
335 max = 0;
336 if (text) {
337 len = strlen(text);
338 if (limit > 0 && len > limit) {
339 len = limit;
340 }
341 count = 0;
342 while (s && *s && count < len) {
343 if ( Q_IsColorString(s) ) {
344 s += 2;
345 continue;
346 } else {
347 glyph = &font->glyphs[(int)*s]; // TTimo: FIXME: getting nasty warnings without the cast, hopefully this doesn't break the VM build
348 if (max < glyph->height) {
349 max = glyph->height;
350 }
351 s++;
352 count++;
353 }
354 }
355 }
356 return max * useScale;
357 }
358
359 void Text_PaintChar(float x, float y, float width, float height, float scale, float s, float t, float s2, float t2, qhandle_t hShader) {
360 float w, h;
361 w = width * scale;
362 h = height * scale;
363 UI_AdjustFrom640( &x, &y, &w, &h );
364 trap_R_DrawStretchPic( x, y, w, h, s, t, s2, t2, hShader );
365 }
366
367 void Text_Paint(float x, float y, float scale, vec4_t color, const char *text, float adjust, int limit, int style) {
368 int len, count;
369 vec4_t newColor;
370 glyphInfo_t *glyph;
371 float useScale;
372 fontInfo_t *font = &uiInfo.uiDC.Assets.textFont;
373 if (scale <= ui_smallFont.value) {
374 font = &uiInfo.uiDC.Assets.smallFont;
375 } else if (scale >= ui_bigFont.value) {
376 font = &uiInfo.uiDC.Assets.bigFont;
377 }
378 useScale = scale * font->glyphScale;
379 if (text) {
380 const char *s = text; // bk001206 - unsigned
381 trap_R_SetColor( color );
382 memcpy(&newColor[0], &color[0], sizeof(vec4_t));
383 len = strlen(text);
384 if (limit > 0 && len > limit) {
385 len = limit;
386 }
387 count = 0;
388 while (s && *s && count < len) {
389 glyph = &font->glyphs[(int)*s]; // TTimo: FIXME: getting nasty warnings without the cast, hopefully this doesn't break the VM build
390 //int yadj = Assets.textFont.glyphs[text[i]].bottom + Assets.textFont.glyphs[text[i]].top;
391 //float yadj = scale * (Assets.textFont.glyphs[text[i]].imageHeight - Assets.textFont.glyphs[text[i]].height);
392 if ( Q_IsColorString( s ) ) {
393 memcpy( newColor, g_color_table[ColorIndex(*(s+1))], sizeof( newColor ) );
394 newColor[3] = color[3];
395 trap_R_SetColor( newColor );
396 s += 2;
397 continue;
398 } else {
399 float yadj = useScale * glyph->top;
400 if (style == ITEM_TEXTSTYLE_SHADOWED || style == ITEM_TEXTSTYLE_SHADOWEDMORE) {
401 int ofs = style == ITEM_TEXTSTYLE_SHADOWED ? 1 : 2;
402 colorBlack[3] = newColor[3];
403 trap_R_SetColor( colorBlack );
404 Text_PaintChar(x + ofs, y - yadj + ofs,
405 glyph->imageWidth,
406 glyph->imageHeight,
407 useScale,
408 glyph->s,
409 glyph->t,
410 glyph->s2,
411 glyph->t2,
412 glyph->glyph);
413 trap_R_SetColor( newColor );
414 colorBlack[3] = 1.0;
415 }
416 Text_PaintChar(x, y - yadj,
417 glyph->imageWidth,
418 glyph->imageHeight,
419 useScale,
420 glyph->s,
421 glyph->t,
422 glyph->s2,
423 glyph->t2,
424 glyph->glyph);
425
426 x += (glyph->xSkip * useScale) + adjust;
427 s++;
428 count++;
429 }
430 }
431 trap_R_SetColor( NULL );
432 }
433 }
434
435 void Text_PaintWithCursor(float x, float y, float scale, vec4_t color, const char *text, int cursorPos, char cursor, int limit, int style) {
436 int len, count;
437 vec4_t newColor;
438 glyphInfo_t *glyph, *glyph2;
439 float yadj;
440 float useScale;
441 fontInfo_t *font = &uiInfo.uiDC.Assets.textFont;
442 if (scale <= ui_smallFont.value) {
443 font = &uiInfo.uiDC.Assets.smallFont;
444 } else if (scale >= ui_bigFont.value) {
445 font = &uiInfo.uiDC.Assets.bigFont;
446 }
447 useScale = scale * font->glyphScale;
448 if (text) {
449 const char *s = text; // bk001206 - unsigned
450 trap_R_SetColor( color );
451 memcpy(&newColor[0], &color[0], sizeof(vec4_t));
452 len = strlen(text);
453 if (limit > 0 && len > limit) {
454 len = limit;
455 }
456 count = 0;
457 glyph2 = &font->glyphs[ (int) cursor]; // bk001206 - possible signed char
458 while (s && *s && count < len) {
459 glyph = &font->glyphs[(int)*s]; // TTimo: FIXME: getting nasty warnings without the cast, hopefully this doesn't break the VM build
460 //int yadj = Assets.textFont.glyphs[text[i]].bottom + Assets.textFont.glyphs[text[i]].top;
461 //float yadj = scale * (Assets.textFont.glyphs[text[i]].imageHeight - Assets.textFont.glyphs[text[i]].height);
462 if ( Q_IsColorString( s ) ) {
463 memcpy( newColor, g_color_table[ColorIndex(*(s+1))], sizeof( newColor ) );
464 newColor[3] = color[3];
465 trap_R_SetColor( newColor );
466 s += 2;
467 continue;
468 } else {
469 yadj = useScale * glyph->top;
470 if (style == ITEM_TEXTSTYLE_SHADOWED || style == ITEM_TEXTSTYLE_SHADOWEDMORE) {
471 int ofs = style == ITEM_TEXTSTYLE_SHADOWED ? 1 : 2;
472 colorBlack[3] = newColor[3];
473 trap_R_SetColor( colorBlack );
474 Text_PaintChar(x + ofs, y - yadj + ofs,
475 glyph->imageWidth,
476 glyph->imageHeight,
477 useScale,
478 glyph->s,
479 glyph->t,
480 glyph->s2,
481 glyph->t2,
482 glyph->glyph);
483 colorBlack[3] = 1.0;
484 trap_R_SetColor( newColor );
485 }
486 Text_PaintChar(x, y - yadj,
487 glyph->imageWidth,
488 glyph->imageHeight,
489 useScale,
490 glyph->s,
491 glyph->t,
492 glyph->s2,
493 glyph->t2,
494 glyph->glyph);
495
496 yadj = useScale * glyph2->top;
497 if (count == cursorPos && !((uiInfo.uiDC.realTime/BLINK_DIVISOR) & 1)) {
498 Text_PaintChar(x, y - yadj,
499 glyph2->imageWidth,
500 glyph2->imageHeight,
501 useScale,
502 glyph2->s,
503 glyph2->t,
504 glyph2->s2,
505 glyph2->t2,
506 glyph2->glyph);
507 }
508
509 x += (glyph->xSkip * useScale);
510 s++;
511 count++;
512 }
513 }
514 // need to paint cursor at end of text
515 if (cursorPos == len && !((uiInfo.uiDC.realTime/BLINK_DIVISOR) & 1)) {
516 yadj = useScale * glyph2->top;
517 Text_PaintChar(x, y - yadj,
518 glyph2->imageWidth,
519 glyph2->imageHeight,
520 useScale,
521 glyph2->s,
522 glyph2->t,
523 glyph2->s2,
524 glyph2->t2,
525 glyph2->glyph);
526
527 }
528
529 trap_R_SetColor( NULL );
530 }
531 }
532
533
534 static void Text_Paint_Limit(float *maxX, float x, float y, float scale, vec4_t color, const char* text, float adjust, int limit) {
535 int len, count;
536 vec4_t newColor;
537 glyphInfo_t *glyph;
538 if (text) {
539 const char *s = text; // bk001206 - unsigned
540 float max = *maxX;
541 float useScale;
542 fontInfo_t *font = &uiInfo.uiDC.Assets.textFont;
543 if (scale <= ui_smallFont.value) {
544 font = &uiInfo.uiDC.Assets.smallFont;
545 } else if (scale > ui_bigFont.value) {
546 font = &uiInfo.uiDC.Assets.bigFont;
547 }
548 useScale = scale * font->glyphScale;
549 trap_R_SetColor( color );
550 len = strlen(text);
551 if (limit > 0 && len > limit) {
552 len = limit;
553 }
554 count = 0;
555 while (s && *s && count < len) {
556 glyph = &font->glyphs[(int)*s]; // TTimo: FIXME: getting nasty warnings without the cast, hopefully this doesn't break the VM build
557 if ( Q_IsColorString( s ) ) {
558 memcpy( newColor, g_color_table[ColorIndex(*(s+1))], sizeof( newColor ) );
559 newColor[3] = color[3];
560 trap_R_SetColor( newColor );
561 s += 2;
562 continue;
563 } else {
564 float yadj = useScale * glyph->top;
565 if (Text_Width(s, useScale, 1) + x > max) {
566 *maxX = 0;
567 break;
568 }
569 Text_PaintChar(x, y - yadj,
570 glyph->imageWidth,
571 glyph->imageHeight,
572 useScale,
573 glyph->s,
574 glyph->t,
575 glyph->s2,
576 glyph->t2,
577 glyph->glyph);
578 x += (glyph->xSkip * useScale) + adjust;
579 *maxX = x;
580 count++;
581 s++;
582 }
583 }
584 trap_R_SetColor( NULL );
585 }
586
587 }
588
589
590 void UI_ShowPostGame(qboolean newHigh) {
591 trap_Cvar_Set ("cg_cameraOrbit", "0");
592 trap_Cvar_Set("cg_thirdPerson", "0");
593 uiInfo.soundHighScore = newHigh;
594 _UI_SetActiveMenu(UIMENU_POSTGAME);
595 }
596 /*
597 =================
598 _UI_Refresh
599 =================
600 */
601
602 void UI_DrawCenteredPic(qhandle_t image, int w, int h) {
603 int x, y;
604 x = (SCREEN_WIDTH - w) / 2;
605 y = (SCREEN_HEIGHT - h) / 2;
606 UI_DrawHandlePic(x, y, w, h, image);
607 }
608
609 int frameCount = 0;
610 int startTime;
611
612 #define UI_FPS_FRAMES 4
613 void _UI_Refresh( int realtime )
614 {
615 static int index;
616 static int previousTimes[UI_FPS_FRAMES];
617
618 //if ( !( trap_Key_GetCatcher() & KEYCATCH_UI ) ) {
619 // return;
620 //}
621
622 uiInfo.uiDC.frameTime = realtime - uiInfo.uiDC.realTime;
623 uiInfo.uiDC.realTime = realtime;
624
625 previousTimes[index % UI_FPS_FRAMES] = uiInfo.uiDC.frameTime;
626 index++;
627 if ( index > UI_FPS_FRAMES ) {
628 int i, total;
629 // average multiple frames together to smooth changes out a bit
630 total = 0;
631 for ( i = 0 ; i < UI_FPS_FRAMES ; i++ ) {
632 total += previousTimes[i];
633 }
634 if ( !total ) {
635 total = 1;
636 }
637 uiInfo.uiDC.FPS = 1000 * UI_FPS_FRAMES / total;
638 }
639
640
641
642 UI_UpdateCvars();
643
644 if (Menu_Count() > 0) {
645 // paint all the menus
646 Menu_PaintAll();
647 // refresh server browser list
648 UI_DoServerRefresh();
649 // refresh server status
650 UI_BuildServerStatus(qfalse);
651 // refresh find player list
652 UI_BuildFindPlayerList(qfalse);
653 }
654
655 // draw cursor
656 UI_SetColor( NULL );
657 if (Menu_Count() > 0) {
658 UI_DrawHandlePic( uiInfo.uiDC.cursorx-16, uiInfo.uiDC.cursory-16, 32, 32, uiInfo.uiDC.Assets.cursor);
659 }
660
661 #ifndef NDEBUG
662 if (uiInfo.uiDC.debug)
663 {
664 // cursor coordinates
665 //FIXME
666 //UI_DrawString( 0, 0, va("(%d,%d)",uis.cursorx,uis.cursory), UI_LEFT|UI_SMALLFONT, colorRed );
667 }
668 #endif
669
670 }
671
672 /*
673 =================
674 _UI_Shutdown
675 =================
676 */
677 void _UI_Shutdown( void ) {
678 trap_LAN_SaveCachedServers();
679 }
680
681 char *defaultMenu = NULL;
682
683 char *GetMenuBuffer(const char *filename) {
684 int len;
685 fileHandle_t f;
686 static char buf[MAX_MENUFILE];
687
688 len = trap_FS_FOpenFile( filename, &f, FS_READ );
689 if ( !f ) {
690 trap_Print( va( S_COLOR_RED "menu file not found: %s, using default\n", filename ) );
691 return defaultMenu;
692 }
693 if ( len >= MAX_MENUFILE ) {
694 trap_Print( va( S_COLOR_RED "menu file too large: %s is %i, max allowed is %i\n", filename, len, MAX_MENUFILE ) );
695 trap_FS_FCloseFile( f );
696 return defaultMenu;
697 }
698
699 trap_FS_Read( buf, len, f );
700 buf[len] = 0;
701 trap_FS_FCloseFile( f );
702 //COM_Compress(buf);
703 return buf;
704
705 }
706
707 qboolean Asset_Parse(int handle) {
708 pc_token_t token;
709 const char *tempStr;
710
711 if (!trap_PC_ReadToken(handle, &token))
712 return qfalse;
713 if (Q_stricmp(token.string, "{") != 0) {
714 return qfalse;
715 }
716
717 while ( 1 ) {
718
719 memset(&token, 0, sizeof(pc_token_t));
720
721 if (!trap_PC_ReadToken(handle, &token))
722 return qfalse;
723
724 if (Q_stricmp(token.string, "}") == 0) {
725 return qtrue;
726 }
727
728 // font
729 if (Q_stricmp(token.string, "font") == 0) {
730 int pointSize;
731 if (!PC_String_Parse(handle, &tempStr) || !PC_Int_Parse(handle,&pointSize)) {
732 return qfalse;
733 }
734 trap_R_RegisterFont(tempStr, pointSize, &uiInfo.uiDC.Assets.textFont);
735 uiInfo.uiDC.Assets.fontRegistered = qtrue;
736 continue;
737 }
738
739 if (Q_stricmp(token.string, "smallFont") == 0) {
740 int pointSize;
741 if (!PC_String_Parse(handle, &tempStr) || !PC_Int_Parse(handle,&pointSize)) {
742 return qfalse;
743 }
744 trap_R_RegisterFont(tempStr, pointSize, &uiInfo.uiDC.Assets.smallFont);
745 continue;
746 }
747
748 if (Q_stricmp(token.string, "bigFont") == 0) {
749 int pointSize;
750 if (!PC_String_Parse(handle, &tempStr) || !PC_Int_Parse(handle,&pointSize)) {
751 return qfalse;
752 }
753 trap_R_RegisterFont(tempStr, pointSize, &uiInfo.uiDC.Assets.bigFont);
754 continue;
755 }
756
757
758 // gradientbar
759 if (Q_stricmp(token.string, "gradientbar") == 0) {
760 if (!PC_String_Parse(handle, &tempStr)) {
761 return qfalse;
762 }
763 uiInfo.uiDC.Assets.gradientBar = trap_R_RegisterShaderNoMip(tempStr);
764 continue;
765 }
766
767 // enterMenuSound
768 if (Q_stricmp(token.string, "menuEnterSound") == 0) {
769 if (!PC_String_Parse(handle, &tempStr)) {
770 return qfalse;
771 }
772 uiInfo.uiDC.Assets.menuEnterSound = trap_S_RegisterSound( tempStr, qfalse );
773 continue;
774 }
775
776 // exitMenuSound
777 if (Q_stricmp(token.string, "menuExitSound") == 0) {
778 if (!PC_String_Parse(handle, &tempStr)) {
779 return qfalse;
780 }
781 uiInfo.uiDC.Assets.menuExitSound = trap_S_RegisterSound( tempStr, qfalse );
782 continue;
783 }
784
785 // itemFocusSound
786 if (Q_stricmp(token.string, "itemFocusSound") == 0) {
787 if (!PC_String_Parse(handle, &tempStr)) {
788 return qfalse;
789 }
790 uiInfo.uiDC.Assets.itemFocusSound = trap_S_RegisterSound( tempStr, qfalse );
791 continue;
792 }
793
794 // menuBuzzSound
795 if (Q_stricmp(token.string, "menuBuzzSound") == 0) {
796 if (!PC_String_Parse(handle, &tempStr)) {
797 return qfalse;
798 }
799 uiInfo.uiDC.Assets.menuBuzzSound = trap_S_RegisterSound( tempStr, qfalse );
800 continue;
801 }
802
803 if (Q_stricmp(token.string, "cursor") == 0) {
804 if (!PC_String_Parse(handle, &uiInfo.uiDC.Assets.cursorStr)) {
805 return qfalse;
806 }
807 uiInfo.uiDC.Assets.cursor = trap_R_RegisterShaderNoMip( uiInfo.uiDC.Assets.cursorStr);
808 continue;
809 }
810
811 if (Q_stricmp(token.string, "fadeClamp") == 0) {
812 if (!PC_Float_Parse(handle, &uiInfo.uiDC.Assets.fadeClamp)) {
813 return qfalse;
814 }
815 continue;
816 }
817
818 if (Q_stricmp(token.string, "fadeCycle") == 0) {
819 if (!PC_Int_Parse(handle, &uiInfo.uiDC.Assets.fadeCycle)) {
820 return qfalse;
821 }
822 continue;
823 }
824
825 if (Q_stricmp(token.string, "fadeAmount") == 0) {
826 if (!PC_Float_Parse(handle, &uiInfo.uiDC.Assets.fadeAmount)) {
827 return qfalse;
828 }
829 continue;
830 }
831
832 if (Q_stricmp(token.string, "shadowX") == 0) {
833 if (!PC_Float_Parse(handle, &uiInfo.uiDC.Assets.shadowX)) {
834 return qfalse;
835 }
836 continue;
837 }
838
839 if (Q_stricmp(token.string, "shadowY") == 0) {
840 if (!PC_Float_Parse(handle, &uiInfo.uiDC.Assets.shadowY)) {
841 return qfalse;
842 }
843 continue;
844 }
845
846 if (Q_stricmp(token.string, "shadowColor") == 0) {
847 if (!PC_Color_Parse(handle, &uiInfo.uiDC.Assets.shadowColor)) {
848 return qfalse;
849 }
850 uiInfo.uiDC.Assets.shadowFadeClamp = uiInfo.uiDC.Assets.shadowColor[3];
851 continue;
852 }
853
854 }
855 return qfalse;
856 }
857
858 void Font_Report( void ) {
859 int i;
860 Com_Printf("Font Info\n");
861 Com_Printf("=========\n");
862 for ( i = 32; i < 96; i++) {
863 Com_Printf("Glyph handle %i: %i\n", i, uiInfo.uiDC.Assets.textFont.glyphs[i].glyph);
864 }
865 }
866
867 void UI_Report( void ) {
868 String_Report();
869 //Font_Report();
870
871 }
872
873 void UI_ParseMenu(const char *menuFile) {
874 int handle;
875 pc_token_t token;
876
877 Com_Printf("Parsing menu file:%s\n", menuFile);
878
879 handle = trap_PC_LoadSource(menuFile);
880 if (!handle) {
881 return;
882 }
883
884 while ( 1 ) {
885 memset(&token, 0, sizeof(pc_token_t));
886 if (!trap_PC_ReadToken( handle, &token )) {
887 break;
888 }
889
890 //if ( Q_stricmp( token, "{" ) ) {
891 // Com_Printf( "Missing { in menu file\n" );
892 // break;
893 //}
894
895 //if ( menuCount == MAX_MENUS ) {
896 // Com_Printf( "Too many menus!\n" );
897 // break;
898 //}
899
900 if ( token.string[0] == '}' ) {
901 break;
902 }
903
904 if (Q_stricmp(token.string, "assetGlobalDef") == 0) {
905 if (Asset_Parse(handle)) {
906 continue;
907 } else {
908 break;
909 }
910 }
911
912 if (Q_stricmp(token.string, "menudef") == 0) {
913 // start a new menu
914 Menu_New(handle);
915 }
916 }
917 trap_PC_FreeSource(handle);
918 }
919
920 qboolean Load_Menu(int handle) {
921 pc_token_t token;
922
923 if (!trap_PC_ReadToken(handle, &token))
924 return qfalse;
925 if (token.string[0] != '{') {
926 return qfalse;
927 }
928
929 while ( 1 ) {
930
931 if (!trap_PC_ReadToken(handle, &token))
932 return qfalse;
933
934 if ( token.string[0] == 0 ) {
935 return qfalse;
936 }
937
938 if ( token.string[0] == '}' ) {
939 return qtrue;
940 }
941
942 UI_ParseMenu(token.string);
943 }
944 return qfalse;
945 }
946
947 void UI_LoadMenus(const char *menuFile, qboolean reset) {
948 pc_token_t token;
949 int handle;
950 int start;
951
952 start = trap_Milliseconds();
953
954 handle = trap_PC_LoadSource( menuFile );
955 if (!handle) {
956 trap_Error( va( S_COLOR_YELLOW "menu file not found: %s, using default\n", menuFile ) );
957 handle = trap_PC_LoadSource( "ui/menus.txt" );
958 if (!handle) {
959 trap_Error( va( S_COLOR_RED "default menu file not found: ui/menus.txt, unable to continue!\n") );
960 }
961 }
962
963 ui_new.integer = 1;
964
965 if (reset) {
966 Menu_Reset();
967 }
968
969 while ( 1 ) {
970 if (!trap_PC_ReadToken(handle, &token))
971 break;
972 if( token.string[0] == 0 || token.string[0] == '}') {
973 break;
974 }
975
976 if ( token.string[0] == '}' ) {
977 break;
978 }
979
980 if (Q_stricmp(token.string, "loadmenu") == 0) {
981 if (Load_Menu(handle)) {
982 continue;
983 } else {
984 break;
985 }
986 }
987 }
988
989 Com_Printf("UI menu load time = %d milli seconds\n", trap_Milliseconds() - start);
990
991 trap_PC_FreeSource( handle );
992 }
993
994 void UI_Load(void) {
995 char lastName[1024];
996 menuDef_t *menu = Menu_GetFocused();
997 char *menuSet = UI_Cvar_VariableString("ui_menuFiles");
998 if (menu && menu->window.name) {
999 strcpy(lastName, menu->window.name);
1000 }
1001 if (menuSet == NULL || menuSet[0] == '\0') {
1002 menuSet = "ui/menus.txt";
1003 }
1004
1005 String_Init();
1006
1007 #ifdef PRE_RELEASE_TADEMO
1008 UI_ParseGameInfo("demogameinfo.txt");
1009 #else
1010 UI_ParseGameInfo("gameinfo.txt");
1011 UI_LoadArenas();
1012 #endif
1013
1014 UI_LoadMenus(menuSet, qtrue);
1015 Menus_CloseAll();
1016 Menus_ActivateByName(lastName);
1017
1018 }
1019
1020 static const char *handicapValues[] = {"None","95","90","85","80","75","70","65","60","55","50","45","40","35","30","25","20","15","10","5",NULL};
1021 #ifndef MISSIONPACK // bk001206
1022 static int numHandicaps = sizeof(handicapValues) / sizeof(const char*);
1023 #endif
1024
1025 static void UI_DrawHandicap(rectDef_t *rect, float scale, vec4_t color, int textStyle) {
1026 int i, h;
1027
1028 h = Com_Clamp( 5, 100, trap_Cvar_VariableValue("handicap") );
1029 i = 20 - h / 5;
1030
1031 Text_Paint(rect->x, rect->y, scale, color, handicapValues[i], 0, 0, textStyle);
1032 }
1033
1034 static void UI_DrawClanName(rectDef_t *rect, float scale, vec4_t color, int textStyle) {
1035 Text_Paint(rect->x, rect->y, scale, color, UI_Cvar_VariableString("ui_teamName"), 0, 0, textStyle);
1036 }
1037
1038
1039 static void UI_SetCapFragLimits(qboolean uiVars) {
1040 int cap = 5;
1041 int frag = 10;
1042 if (uiInfo.gameTypes[ui_gameType.integer].gtEnum == GT_OBELISK) {
1043 cap = 4;
1044 } else if (uiInfo.gameTypes[ui_gameType.integer].gtEnum == GT_HARVESTER) {
1045 cap = 15;
1046 }
1047 if (uiVars) {
1048 trap_Cvar_Set("ui_captureLimit", va("%d", cap));
1049 trap_Cvar_Set("ui_fragLimit", va("%d", frag));
1050 } else {
1051 trap_Cvar_Set("capturelimit", va("%d", cap));
1052 trap_Cvar_Set("fraglimit", va("%d", frag));
1053 }
1054 }
1055 // ui_gameType assumes gametype 0 is -1 ALL and will not show
1056 static void UI_DrawGameType(rectDef_t *rect, float scale, vec4_t color, int textStyle) {
1057 Text_Paint(rect->x, rect->y, scale, color, uiInfo.gameTypes[ui_gameType.integer].gameType, 0, 0, textStyle);
1058 }
1059
1060 static void UI_DrawNetGameType(rectDef_t *rect, float scale, vec4_t color, int textStyle) {
1061 if (ui_netGameType.integer < 0 || ui_netGameType.integer > uiInfo.numGameTypes) {
1062 trap_Cvar_Set("ui_netGameType", "0");
1063 trap_Cvar_Set("ui_actualNetGameType", "0");
1064 }
1065 Text_Paint(rect->x, rect->y, scale, color, uiInfo.gameTypes[ui_netGameType.integer].gameType , 0, 0, textStyle);
1066 }
1067
1068 static void UI_DrawJoinGameType(rectDef_t *rect, float scale, vec4_t color, int textStyle) {
1069 if (ui_joinGameType.integer < 0 || ui_joinGameType.integer > uiInfo.numJoinGameTypes) {
1070 trap_Cvar_Set("ui_joinGameType", "0");
1071 }
1072 Text_Paint(rect->x, rect->y, scale, color, uiInfo.joinGameTypes[ui_joinGameType.integer].gameType , 0, 0, textStyle);
1073 }
1074
1075
1076
1077 static int UI_TeamIndexFromName(const char *name) {
1078 int i;
1079
1080 if (name && *name) {
1081 for (i = 0; i < uiInfo.teamCount; i++) {
1082 if (Q_stricmp(name, uiInfo.teamList[i].teamName) == 0) {
1083 return i;
1084 }
1085 }
1086 }
1087
1088 return 0;
1089
1090 }
1091
1092 static void UI_DrawClanLogo(rectDef_t *rect, float scale, vec4_t color) {
1093 int i;
1094 i = UI_TeamIndexFromName(UI_Cvar_VariableString("ui_teamName"));
1095 if (i >= 0 && i < uiInfo.teamCount) {
1096 trap_R_SetColor( color );
1097
1098 if (uiInfo.teamList[i].teamIcon == -1) {
1099 uiInfo.teamList[i].teamIcon = trap_R_RegisterShaderNoMip(uiInfo.teamList[i].imageName);
1100 uiInfo.teamList[i].teamIcon_Metal = trap_R_RegisterShaderNoMip(va("%s_metal",uiInfo.teamList[i].imageName));
1101 uiInfo.teamList[i].teamIcon_Name = trap_R_RegisterShaderNoMip(va("%s_name", uiInfo.teamList[i].imageName));
1102 }
1103
1104 UI_DrawHandlePic( rect->x, rect->y, rect->w, rect->h, uiInfo.teamList[i].teamIcon);
1105 trap_R_SetColor(NULL);
1106 }
1107 }
1108
1109 static void UI_DrawClanCinematic(rectDef_t *rect, float scale, vec4_t color) {
1110 int i;
1111 i = UI_TeamIndexFromName(UI_Cvar_VariableString("ui_teamName"));
1112 if (i >= 0 && i < uiInfo.teamCount) {
1113
1114 if (uiInfo.teamList[i].cinematic >= -2) {
1115 if (uiInfo.teamList[i].cinematic == -1) {
1116 uiInfo.teamList[i].cinematic = trap_CIN_PlayCinematic(va("%s.roq", uiInfo.teamList[i].imageName), 0, 0, 0, 0, (CIN_loop | CIN_silent) );
1117 }
1118 if (uiInfo.teamList[i].cinematic >= 0) {
1119 trap_CIN_RunCinematic(uiInfo.teamList[i].cinematic);
1120 trap_CIN_SetExtents(uiInfo.teamList[i].cinematic, rect->x, rect->y, rect->w, rect->h);
1121 trap_CIN_DrawCinematic(uiInfo.teamList[i].cinematic);
1122 } else {
1123 trap_R_SetColor( color );
1124 UI_DrawHandlePic( rect->x, rect->y, rect->w, rect->h, uiInfo.teamList[i].teamIcon_Metal);
1125 trap_R_SetColor(NULL);
1126 uiInfo.teamList[i].cinematic = -2;
1127 }
1128 } else {
1129 trap_R_SetColor( color );
1130 UI_DrawHandlePic( rect->x, rect->y, rect->w, rect->h, uiInfo.teamList[i].teamIcon);
1131 trap_R_SetColor(NULL);
1132 }
1133 }
1134
1135 }
1136
1137 static void UI_DrawPreviewCinematic(rectDef_t *rect, float scale, vec4_t color) {
1138 if (uiInfo.previewMovie > -2) {
1139 uiInfo.previewMovie = trap_CIN_PlayCinematic(va("%s.roq", uiInfo.movieList[uiInfo.movieIndex]), 0, 0, 0, 0, (CIN_loop | CIN_silent) );
1140 if (uiInfo.previewMovie >= 0) {
1141 trap_CIN_RunCinematic(uiInfo.previewMovie);
1142 trap_CIN_SetExtents(uiInfo.previewMovie, rect->x, rect->y, rect->w, rect->h);
1143 trap_CIN_DrawCinematic(uiInfo.previewMovie);
1144 } else {
1145 uiInfo.previewMovie = -2;
1146 }
1147 }
1148
1149 }
1150
1151
1152
1153 static void UI_DrawSkill(rectDef_t *rect, float scale, vec4_t color, int textStyle) {
1154 int i;
1155 i = trap_Cvar_VariableValue( "g_spSkill" );
1156 if (i < 1 || i > numSkillLevels) {
1157 i = 1;
1158 }
1159 Text_Paint(rect->x, rect->y, scale, color, skillLevels[i-1],0, 0, textStyle);
1160 }
1161
1162
1163 static void UI_DrawTeamName(rectDef_t *rect, float scale, vec4_t color, qboolean blue, int textStyle) {
1164 int i;
1165 i = UI_TeamIndexFromName(UI_Cvar_VariableString((blue) ? "ui_blueTeam" : "ui_redTeam"));
1166 if (i >= 0 && i < uiInfo.teamCount) {
1167 Text_Paint(rect->x, rect->y, scale, color, va("%s: %s", (blue) ? "Blue" : "Red", uiInfo.teamList[i].teamName),0, 0, textStyle);
1168 }
1169 }
1170
1171 static void UI_DrawTeamMember(rectDef_t *rect, float scale, vec4_t color, qboolean blue, int num, int textStyle) {
1172 // 0 - None
1173 // 1 - Human
1174 // 2..NumCharacters - Bot
1175 int value = trap_Cvar_VariableValue(va(blue ? "ui_blueteam%i" : "ui_redteam%i", num));
1176 const char *text;
1177 if (value <= 0) {
1178 text = "Closed";
1179 } else if (value == 1) {
1180 text = "Human";
1181 } else {
1182 value -= 2;
1183
1184 if (ui_actualNetGameType.integer >= GT_TEAM) {
1185 if (value >= uiInfo.characterCount) {
1186 value = 0;
1187 }
1188 text = uiInfo.characterList[value].name;
1189 } else {
1190 if (value >= UI_GetNumBots()) {
1191 value = 0;
1192 }
1193 text = UI_GetBotNameByNumber(value);
1194 }
1195 }
1196 Text_Paint(rect->x, rect->y, scale, color, text, 0, 0, textStyle);
1197 }
1198
1199 static void UI_DrawEffects(rectDef_t *rect, float scale, vec4_t color) {
1200 UI_DrawHandlePic( rect->x, rect->y - 14, 128, 8, uiInfo.uiDC.Assets.fxBasePic );
1201 UI_DrawHandlePic( rect->x + uiInfo.effectsColor * 16 + 8, rect->y - 16, 16, 12, uiInfo.uiDC.Assets.fxPic[uiInfo.effectsColor] );
1202 }
1203
1204 static void UI_DrawMapPreview(rectDef_t *rect, float scale, vec4_t color, qboolean net) {
1205 int map = (net) ? ui_currentNetMap.integer : ui_currentMap.integer;
1206 if (map < 0 || map > uiInfo.mapCount) {
1207 if (net) {
1208 ui_currentNetMap.integer = 0;
1209 trap_Cvar_Set("ui_currentNetMap", "0");
1210 } else {
1211 ui_currentMap.integer = 0;
1212 trap_Cvar_Set("ui_currentMap", "0");
1213 }
1214 map = 0;
1215 }
1216
1217 if (uiInfo.mapList[map].levelShot == -1) {
1218 uiInfo.mapList[map].levelShot = trap_R_RegisterShaderNoMip(uiInfo.mapList[map].imageName);
1219 }
1220
1221 if (uiInfo.mapList[map].levelShot > 0) {
1222 UI_DrawHandlePic( rect->x, rect->y, rect->w, rect->h, uiInfo.mapList[map].levelShot);
1223 } else {
1224 UI_DrawHandlePic( rect->x, rect->y, rect->w, rect->h, trap_R_RegisterShaderNoMip("menu/art/unknownmap"));
1225 }
1226 }
1227
1228
1229 static void UI_DrawMapTimeToBeat(rectDef_t *rect, float scale, vec4_t color, int textStyle) {
1230 int minutes, seconds, time;
1231 if (ui_currentMap.integer < 0 || ui_currentMap.integer > uiInfo.mapCount) {
1232 ui_currentMap.integer = 0;
1233 trap_Cvar_Set("ui_currentMap", "0");
1234 }
1235
1236 time = uiInfo.mapList[ui_currentMap.integer].timeToBeat[uiInfo.gameTypes[ui_gameType.integer].gtEnum];
1237
1238 minutes = time / 60;
1239 seconds = time % 60;
1240
1241 Text_Paint(rect->x, rect->y, scale, color, va("%02i:%02i", minutes, seconds), 0, 0, textStyle);
1242 }
1243
1244
1245
1246 static void UI_DrawMapCinematic(rectDef_t *rect, float scale, vec4_t color, qboolean net) {
1247
1248 int map = (net) ? ui_currentNetMap.integer : ui_currentMap.integer;
1249 if (map < 0 || map > uiInfo.mapCount) {
1250 if (net) {
1251 ui_currentNetMap.integer = 0;
1252 trap_Cvar_Set("ui_currentNetMap", "0");
1253 } else {
1254 ui_currentMap.integer = 0;
1255 trap_Cvar_Set("ui_currentMap", "0");
1256 }
1257 map = 0;
1258 }
1259
1260 if (uiInfo.mapList[map].cinematic >= -1) {
1261 if (uiInfo.mapList[map].cinematic == -1) {
1262 uiInfo.mapList[map].cinematic = trap_CIN_PlayCinematic(va("%s.roq", uiInfo.mapList[map].mapLoadName), 0, 0, 0, 0, (CIN_loop | CIN_silent) );
1263 }
1264 if (uiInfo.mapList[map].cinematic >= 0) {
1265 trap_CIN_RunCinematic(uiInfo.mapList[map].cinematic);
1266 trap_CIN_SetExtents(uiInfo.mapList[map].cinematic, rect->x, rect->y, rect->w, rect->h);
1267 trap_CIN_DrawCinematic(uiInfo.mapList[map].cinematic);
1268 } else {
1269 uiInfo.mapList[map].cinematic = -2;
1270 }
1271 } else {
1272 UI_DrawMapPreview(rect, scale, color, net);
1273 }
1274 }
1275
1276
1277
1278 static qboolean updateModel = qtrue;
1279 static qboolean q3Model = qfalse;
1280
1281 static void UI_DrawPlayerModel(rectDef_t *rect) {
1282 static playerInfo_t info;
1283 char model[MAX_QPATH];
1284 char team[256];
1285 char head[256];
1286 vec3_t viewangles;
1287 vec3_t moveangles;
1288
1289 if (trap_Cvar_VariableValue("ui_Q3Model")) {
1290 strcpy(model, UI_Cvar_VariableString("model"));
1291 strcpy(head, UI_Cvar_VariableString("headmodel"));
1292 if (!q3Model) {
1293 q3Model = qtrue;
1294 updateModel = qtrue;
1295 }
1296 team[0] = '\0';
1297 } else {
1298
1299 strcpy(team, UI_Cvar_VariableString("ui_teamName"));
1300 strcpy(model, UI_Cvar_VariableString("team_model"));
1301 strcpy(head, UI_Cvar_VariableString("team_headmodel"));
1302 if (q3Model) {
1303 q3Model = qfalse;
1304 updateModel = qtrue;
1305 }
1306 }
1307 if (updateModel) {
1308 memset( &info, 0, sizeof(playerInfo_t) );
1309 viewangles[YAW] = 180 - 10;
1310 viewangles[PITCH] = 0;
1311 viewangles[ROLL] = 0;
1312 VectorClear( moveangles );
1313 UI_PlayerInfo_SetModel( &info, model, head, team);
1314 UI_PlayerInfo_SetInfo( &info, LEGS_IDLE, TORSO_STAND, viewangles, vec3_origin, WP_MACHINEGUN, qfalse );
1315 // UI_RegisterClientModelname( &info, model, head, team);
1316 updateModel = qfalse;
1317 }
1318
1319 UI_DrawPlayer( rect->x, rect->y, rect->w, rect->h, &info, uiInfo.uiDC.realTime / 2);
1320
1321 }
1322
1323 static void UI_DrawPlayerModel2(rectDef_t *rect) {
1324 static playerInfo_t info;
1325 char model[MAX_QPATH];
1326 char team[256];
1327 char head[256];
1328 vec3_t viewangles;
1329 vec3_t moveangles;
1330
1331 if (trap_Cvar_VariableValue("ui_Q3Model")) {
1332 strcpy(model, UI_Cvar_VariableString("model"));
1333 strcpy(head, UI_Cvar_VariableString("headmodel"));
1334 if (!q3Model) {
1335 q3Model = qtrue;
1336 updateModel = qtrue;
1337 }
1338 team[0] = '\0';
1339 } else {
1340
1341 strcpy(team, UI_Cvar_VariableString("ui_teamName"));
1342 strcpy(model, UI_Cvar_VariableString("team_model"));
1343 strcpy(head, UI_Cvar_VariableString("team_headmodel"));
1344 if (q3Model) {
1345 q3Model = qfalse;
1346 updateModel = qtrue;
1347 }
1348 }
1349 if (updateModel) {
1350 memset( &info, 0, sizeof(playerInfo_t) );
1351 viewangles[YAW] = 180 - 10;
1352 viewangles[PITCH] = 0;
1353 viewangles[ROLL] = 0;
1354 VectorClear( moveangles );
1355 UI_PlayerInfo_SetModel( &info, model, head, team);
1356 UI_PlayerInfo_SetInfo( &info, LEGS_IDLE, TORSO_STAND, viewangles, vec3_origin, WP_MACHINEGUN, qfalse );
1357 // UI_RegisterClientModelname( &info, model, head, team);
1358 updateModel = qfalse;
1359 }
1360
1361 UI_DrawPlayerII( rect->x, rect->y, rect->w, rect->h, &info, uiInfo.uiDC.realTime / 2);
1362
1363 }
1364
1365
1366 static void UI_DrawNetSource(rectDef_t *rect, float scale, vec4_t color, int textStyle) {
1367 if (ui_netSource.integer < 0 || ui_netSource.integer > numNetSources) {
1368 ui_netSource.integer = 0;
1369 }
1370 Text_Paint(rect->x, rect->y, scale, color, va("Source: %s", netSources[ui_netSource.integer]), 0, 0, textStyle);
1371 }
1372
1373 static void UI_DrawNetMapPreview(rectDef_t *rect, float scale, vec4_t color) {
1374
1375 if (uiInfo.serverStatus.currentServerPreview > 0) {
1376 UI_DrawHandlePic( rect->x, rect->y, rect->w, rect->h, uiInfo.serverStatus.currentServerPreview);
1377 } else {
1378 UI_DrawHandlePic( rect->x, rect->y, rect->w, rect->h, trap_R_RegisterShaderNoMip("menu/art/unknownmap"));
1379 }
1380 }
1381
1382 static void UI_DrawNetMapCinematic(rectDef_t *rect, float scale, vec4_t color) {
1383 if (ui_currentNetMap.integer < 0 || ui_currentNetMap.integer > uiInfo.mapCount) {
1384 ui_currentNetMap.integer = 0;
1385 trap_Cvar_Set("ui_currentNetMap", "0");
1386 }
1387
1388 if (uiInfo.serverStatus.currentServerCinematic >= 0) {
1389 trap_CIN_RunCinematic(uiInfo.serverStatus.currentServerCinematic);
1390 trap_CIN_SetExtents(uiInfo.serverStatus.currentServerCinematic, rect->x, rect->y, rect->w, rect->h);
1391 trap_CIN_DrawCinematic(uiInfo.serverStatus.currentServerCinematic);
1392 } else {
1393 UI_DrawNetMapPreview(rect, scale, color);
1394 }
1395 }
1396
1397
1398
1399 static void UI_DrawNetFilter(rectDef_t *rect, float scale, vec4_t color, int textStyle) {
1400 if (ui_serverFilterType.integer < 0 || ui_serverFilterType.integer > numServerFilters) {
1401 ui_serverFilterType.integer = 0;
1402 }
1403 Text_Paint(rect->x, rect->y, scale, color, va("Filter: %s", serverFilters[ui_serverFilterType.integer].description), 0, 0, textStyle);
1404 }
1405
1406
1407 static void UI_DrawTier(rectDef_t *rect, float scale, vec4_t color, int textStyle) {
1408 int i;
1409 i = trap_Cvar_VariableValue( "ui_currentTier" );
1410 if (i < 0 || i >= uiInfo.tierCount) {
1411 i = 0;
1412 }
1413 Text_Paint(rect->x, rect->y, scale, color, va("Tier: %s", uiInfo.tierList[i].tierName),0, 0, textStyle);
1414 }
1415
1416 static void UI_DrawTierMap(rectDef_t *rect, int index) {
1417 int i;
1418 i = trap_Cvar_VariableValue( "ui_currentTier" );
1419 if (i < 0 || i >= uiInfo.tierCount) {
1420 i = 0;
1421 }
1422
1423 if (uiInfo.tierList[i].mapHandles[index] == -1) {
1424 uiInfo.tierList[i].mapHandles[index] = trap_R_RegisterShaderNoMip(va("levelshots/%s", uiInfo.tierList[i].maps[index]));
1425 }
1426
1427 UI_DrawHandlePic( rect->x, rect->y, rect->w, rect->h, uiInfo.tierList[i].mapHandles[index]);
1428 }
1429
1430 static const char *UI_EnglishMapName(const char *map) {
1431 int i;
1432 for (i = 0; i < uiInfo.mapCount; i++) {
1433 if (Q_stricmp(map, uiInfo.mapList[i].mapLoadName) == 0) {
1434 return uiInfo.mapList[i].mapName;
1435 }
1436 }
1437 return "";
1438 }
1439
1440 static void UI_DrawTierMapName(rectDef_t *rect, float scale, vec4_t color, int textStyle) {
1441 int i, j;
1442 i = trap_Cvar_VariableValue( "ui_currentTier" );
1443 if (i < 0 || i >= uiInfo.tierCount) {
1444 i = 0;
1445 }
1446 j = trap_Cvar_VariableValue("ui_currentMap");
1447 if (j < 0 || j > MAPS_PER_TIER) {
1448 j = 0;
1449 }
1450
1451 Text_Paint(rect->x, rect->y, scale, color, UI_EnglishMapName(uiInfo.tierList[i].maps[j]), 0, 0, textStyle);
1452 }
1453
1454 static void UI_DrawTierGameType(rectDef_t *rect, float scale, vec4_t color, int textStyle) {
1455 int i, j;
1456 i = trap_Cvar_VariableValue( "ui_currentTier" );
1457 if (i < 0 || i >= uiInfo.tierCount) {
1458 i = 0;
1459 }
1460 j = trap_Cvar_VariableValue("ui_currentMap");
1461 if (j < 0 || j > MAPS_PER_TIER) {
1462 j = 0;
1463 }
1464
1465 Text_Paint(rect->x, rect->y, scale, color, uiInfo.gameTypes[uiInfo.tierList[i].gameTypes[j]].gameType , 0, 0, textStyle);
1466 }
1467
1468
1469 #ifndef MISSIONPACK // bk001206
1470 static const char *UI_OpponentLeaderName(void) {
1471 int i = UI_TeamIndexFromName(UI_Cvar_VariableString("ui_opponentName"));
1472 return uiInfo.teamList[i].teamMembers[0];
1473 }
1474 #endif
1475
1476 static const char *UI_AIFromName(const char *name) {
1477 int j;
1478 for (j = 0; j < uiInfo.aliasCount; j++) {
1479 if (Q_stricmp(uiInfo.aliasList[j].name, name) == 0) {
1480 return uiInfo.aliasList[j].ai;
1481 }
1482 }
1483 return "sergei";
1484 }
1485
1486 #ifndef MISSIONPACK // bk001206
1487 static const int UI_AIIndex(const char *name) {
1488 int j;
1489 for (j = 0; j < uiInfo.characterCount; j++) {
1490 if (Q_stricmp(name, uiInfo.characterList[j].name) == 0) {
1491 return j;
1492 }
1493 }
1494 return 0;
1495 }
1496 #endif
1497
1498 #ifndef MISSIONPACK // bk001206
1499 static const int UI_AIIndexFromName(const char *name) {
1500 int j;
1501 for (j = 0; j < uiInfo.aliasCount; j++) {
1502 if (Q_stricmp(uiInfo.aliasList[j].name, name) == 0) {
1503 return UI_AIIndex(uiInfo.aliasList[j].ai);
1504 }
1505 }
1506 return 0;
1507 }
1508 #endif
1509
1510
1511 #ifndef MISSIONPACK // bk001206
1512 static const char *UI_OpponentLeaderHead(void) {
1513 const char *leader = UI_OpponentLeaderName();
1514 return UI_AIFromName(leader);
1515 }
1516 #endif
1517
1518 #ifndef MISSIONPACK // bk001206
1519 static const char *UI_OpponentLeaderModel(void) {
1520 int i;
1521 const char *head = UI_OpponentLeaderHead();
1522 for (i = 0; i < uiInfo.characterCount; i++) {
1523 if (Q_stricmp(head, uiInfo.characterList[i].name) == 0) {
1524 return uiInfo.characterList[i].base;
1525 }
1526 }
1527 return "sergei";
1528 }
1529 #endif
1530
1531
1532 static qboolean updateOpponentModel = qtrue;
1533 static void UI_DrawOpponent(rectDef_t *rect) {
1534 static playerInfo_t info2;
1535 char model[MAX_QPATH];
1536 char headmodel[MAX_QPATH];
1537 char team[256];
1538 vec3_t viewangles;
1539 vec3_t moveangles;
1540
1541 if (updateOpponentModel) {
1542
1543 strcpy(model, UI_Cvar_VariableString("ui_opponentModel"));
1544 strcpy(headmodel, UI_Cvar_VariableString("ui_opponentModel"));
1545 team[0] = '\0';
1546
1547 memset( &info2, 0, sizeof(playerInfo_t) );
1548 viewangles[YAW] = 180 - 10;
1549 viewangles[PITCH] = 0;
1550 viewangles[ROLL] = 0;
1551 VectorClear( moveangles );
1552 UI_PlayerInfo_SetModel( &info2, model, headmodel, "");
1553 UI_PlayerInfo_SetInfo( &info2, LEGS_IDLE, TORSO_STAND, viewangles, vec3_origin, WP_MACHINEGUN, qfalse );
1554 UI_RegisterClientModelname( &info2, model, headmodel, team);
1555 updateOpponentModel = qfalse;
1556 }
1557
1558 UI_DrawPlayer( rect->x, rect->y, rect->w, rect->h, &info2, uiInfo.uiDC.realTime / 2);
1559
1560 }
1561
1562 static void UI_DrawOpponent2(rectDef_t *rect) {
1563 static playerInfo_t info2;
1564 char model[MAX_QPATH];
1565 char headmodel[MAX_QPATH];
1566 char team[256];
1567 vec3_t viewangles;
1568 vec3_t moveangles;
1569
1570 if (updateOpponentModel) {
1571
1572 strcpy(model, UI_Cvar_VariableString("ui_opponentModel"));
1573 strcpy(headmodel, UI_Cvar_VariableString("ui_opponentModel"));
1574 team[0] = '\0';
1575
1576 memset( &info2, 0, sizeof(playerInfo_t) );
1577 viewangles[YAW] = 180 - 10;
1578 viewangles[PITCH] = 0;
1579 viewangles[ROLL] = 0;
1580 VectorClear( moveangles );
1581 UI_PlayerInfo_SetModel( &info2, model, headmodel, "");
1582 UI_PlayerInfo_SetInfo( &info2, LEGS_IDLE, TORSO_STAND, viewangles, vec3_origin, WP_MACHINEGUN, qfalse );
1583 UI_RegisterClientModelname( &info2, model, headmodel, team);
1584 updateOpponentModel = qfalse;
1585 }
1586
1587 UI_DrawPlayerII( rect->x, rect->y, rect->w, rect->h, &info2, uiInfo.uiDC.realTime / 2);
1588
1589 }
1590
1591 static void UI_NextOpponent( void ) {
1592 int i = UI_TeamIndexFromName(UI_Cvar_VariableString("ui_opponentName"));
1593 int j = UI_TeamIndexFromName(UI_Cvar_VariableString("ui_teamName"));
1594 i++;
1595 if (i >= uiInfo.teamCount) {
1596 i = 0;
1597 }
1598 if (i == j) {
1599 i++;
1600 if ( i >= uiInfo.teamCount) {
1601 i = 0;
1602 }
1603 }
1604 trap_Cvar_Set( "ui_opponentName", uiInfo.teamList[i].teamName );
1605 }
1606
1607 static void UI_PriorOpponent( void ) {
1608 int i = UI_TeamIndexFromName(UI_Cvar_VariableString("ui_opponentName"));
1609 int j = UI_TeamIndexFromName(UI_Cvar_VariableString("ui_teamName"));
1610 i--;
1611 if (i < 0) {
1612 i = uiInfo.teamCount - 1;
1613 }
1614 if (i == j) {
1615 i--;
1616 if ( i < 0) {
1617 i = uiInfo.teamCount - 1;
1618 }
1619 }
1620 trap_Cvar_Set( "ui_opponentName", uiInfo.teamList[i].teamName );
1621 }
1622
1623 static void UI_DrawPlayerLogo(rectDef_t *rect, vec3_t color) {
1624 int i = UI_TeamIndexFromName(UI_Cvar_VariableString("ui_teamName"));
1625
1626 if (uiInfo.teamList[i].teamIcon == -1) {
1627 uiInfo.teamList[i].teamIcon = trap_R_RegisterShaderNoMip(uiInfo.teamList[i].imageName);
1628 uiInfo.teamList[i].teamIcon_Metal = trap_R_RegisterShaderNoMip(va("%s_metal",uiInfo.teamList[i].imageName));
1629 uiInfo.teamList[i].teamIcon_Name = trap_R_RegisterShaderNoMip(va("%s_name", uiInfo.teamList[i].imageName));
1630 }
1631
1632 trap_R_SetColor( color );
1633 UI_DrawHandlePic( rect->x, rect->y, rect->w, rect->h, uiInfo.teamList[i].teamIcon );
1634 trap_R_SetColor( NULL );
1635 }
1636
1637 static void UI_DrawPlayerLogoMetal(rectDef_t *rect, vec3_t color) {
1638 int i = UI_TeamIndexFromName(UI_Cvar_VariableString("ui_teamName"));
1639 if (uiInfo.teamList[i].teamIcon == -1) {
1640 uiInfo.teamList[i].teamIcon = trap_R_RegisterShaderNoMip(uiInfo.teamList[i].imageName);
1641 uiInfo.teamList[i].teamIcon_Metal = trap_R_RegisterShaderNoMip(va("%s_metal",uiInfo.teamList[i].imageName));
1642 uiInfo.teamList[i].teamIcon_Name = trap_R_RegisterShaderNoMip(va("%s_name", uiInfo.teamList[i].imageName));
1643 }
1644
1645 trap_R_SetColor( color );
1646 UI_DrawHandlePic( rect->x, rect->y, rect->w, rect->h, uiInfo.teamList[i].teamIcon_Metal );
1647 trap_R_SetColor( NULL );
1648 }
1649
1650 static void UI_DrawPlayerLogoName(rectDef_t *rect, vec3_t color) {
1651 int i = UI_TeamIndexFromName(UI_Cvar_VariableString("ui_teamName"));
1652 if (uiInfo.teamList[i].teamIcon == -1) {
1653 uiInfo.teamList[i].teamIcon = trap_R_RegisterShaderNoMip(uiInfo.teamList[i].imageName);
1654 uiInfo.teamList[i].teamIcon_Metal = trap_R_RegisterShaderNoMip(va("%s_metal",uiInfo.teamList[i].imageName));
1655 uiInfo.teamList[i].teamIcon_Name = trap_R_RegisterShaderNoMip(va("%s_name", uiInfo.teamList[i].imageName));
1656 }
1657
1658 trap_R_SetColor( color );
1659 UI_DrawHandlePic( rect->x, rect->y, rect->w, rect->h, uiInfo.teamList[i].teamIcon_Name );
1660 trap_R_SetColor( NULL );
1661 }
1662
1663 static void UI_DrawOpponentLogo(rectDef_t *rect, vec3_t color) {
1664 int i = UI_TeamIndexFromName(UI_Cvar_VariableString("ui_opponentName"));
1665 if (uiInfo.teamList[i].teamIcon == -1) {
1666 uiInfo.teamList[i].teamIcon = trap_R_RegisterShaderNoMip(uiInfo.teamList[i].imageName);
1667 uiInfo.teamList[i].teamIcon_Metal = trap_R_RegisterShaderNoMip(va("%s_metal",uiInfo.teamList[i].imageName));
1668 uiInfo.teamList[i].teamIcon_Name = trap_R_RegisterShaderNoMip(va("%s_name", uiInfo.teamList[i].imageName));
1669 }
1670
1671 trap_R_SetColor( color );
1672 UI_DrawHandlePic( rect->x, rect->y, rect->w, rect->h, uiInfo.teamList[i].teamIcon );
1673 trap_R_SetColor( NULL );
1674 }
1675
1676 static void UI_DrawOpponentLogoMetal(rectDef_t *rect, vec3_t color) {
1677 int i = UI_TeamIndexFromName(UI_Cvar_VariableString("ui_opponentName"));
1678 if (uiInfo.teamList[i].teamIcon == -1) {
1679 uiInfo.teamList[i].teamIcon = trap_R_RegisterShaderNoMip(uiInfo.teamList[i].imageName);
1680 uiInfo.teamList[i].teamIcon_Metal = trap_R_RegisterShaderNoMip(va("%s_metal",uiInfo.teamList[i].imageName));
1681 uiInfo.teamList[i].teamIcon_Name = trap_R_RegisterShaderNoMip(va("%s_name", uiInfo.teamList[i].imageName));
1682 }
1683
1684 trap_R_SetColor( color );
1685 UI_DrawHandlePic( rect->x, rect->y, rect->w, rect->h, uiInfo.teamList[i].teamIcon_Metal );
1686 trap_R_SetColor( NULL );
1687 }
1688
1689 static void UI_DrawOpponentLogoName(rectDef_t *rect, vec3_t color) {
1690 int i = UI_TeamIndexFromName(UI_Cvar_VariableString("ui_opponentName"));
1691 if (uiInfo.teamList[i].teamIcon == -1) {
1692 uiInfo.teamList[i].teamIcon = trap_R_RegisterShaderNoMip(uiInfo.teamList[i].imageName);
1693 uiInfo.teamList[i].teamIcon_Metal = trap_R_RegisterShaderNoMip(va("%s_metal",uiInfo.teamList[i].imageName));
1694 uiInfo.teamList[i].teamIcon_Name = trap_R_RegisterShaderNoMip(va("%s_name", uiInfo.teamList[i].imageName));
1695 }
1696
1697 trap_R_SetColor( color );
1698 UI_DrawHandlePic( rect->x, rect->y, rect->w, rect->h, uiInfo.teamList[i].teamIcon_Name );
1699 trap_R_SetColor( NULL );
1700 }
1701
1702 static void UI_DrawAllMapsSelection(rectDef_t *rect, float scale, vec4_t color, int textStyle, qboolean net) {
1703 int map = (net) ? ui_currentNetMap.integer : ui_currentMap.integer;
1704 if (map >= 0 && map < uiInfo.mapCount) {
1705 Text_Paint(rect->x, rect->y, scale, color, uiInfo.mapList[map].mapName, 0, 0, textStyle);
1706 }
1707 }
1708
1709 static void UI_DrawOpponentName(rectDef_t *rect, float scale, vec4_t color, int textStyle) {
1710 Text_Paint(rect->x, rect->y, scale, color, UI_Cvar_VariableString("ui_opponentName"), 0, 0, textStyle);
1711 }
1712
1713
1714 static int UI_OwnerDrawWidth(int ownerDraw, float scale) {
1715 int i, h, value;
1716 const char *text;
1717 const char *s = NULL;
1718
1719 switch (ownerDraw) {
1720 case UI_HANDICAP:
1721 h = Com_Clamp( 5, 100, trap_Cvar_VariableValue("handicap") );
1722 i = 20 - h / 5;
1723 s = handicapValues[i];
1724 break;
1725 case UI_CLANNAME:
1726 s = UI_Cvar_VariableString("ui_teamName");
1727 break;
1728 case UI_GAMETYPE:
1729 s = uiInfo.gameTypes[ui_gameType.integer].gameType;
1730 break;
1731 case UI_SKILL:
1732 i = trap_Cvar_VariableValue( "g_spSkill" );
1733 if (i < 1 || i > numSkillLevels) {
1734 i = 1;
1735 }
1736 s = skillLevels[i-1];
1737 break;
1738 case UI_BLUETEAMNAME:
1739 i = UI_TeamIndexFromName(UI_Cvar_VariableString("ui_blueTeam"));
1740 if (i >= 0 && i < uiInfo.teamCount) {
1741 s = va("%s: %s", "Blue", uiInfo.teamList[i].teamName);
1742 }
1743 break;
1744 case UI_REDTEAMNAME:
1745 i = UI_TeamIndexFromName(UI_Cvar_VariableString("ui_redTeam"));
1746 if (i >= 0 && i < uiInfo.teamCount) {
1747 s = va("%s: %s", "Red", uiInfo.teamList[i].teamName);
1748 }
1749 break;
1750 case UI_BLUETEAM1:
1751 case UI_BLUETEAM2:
1752 case UI_BLUETEAM3:
1753 case UI_BLUETEAM4:
1754 case UI_BLUETEAM5:
1755 value = trap_Cvar_VariableValue(va("ui_blueteam%i", ownerDraw-UI_BLUETEAM1 + 1));
1756 if (value <= 0) {
1757 text = "Closed";
1758 } else if (value == 1) {
1759 text = "Human";
1760 } else {
1761 value -= 2;
1762 if (value >= uiInfo.aliasCount) {
1763 value = 0;
1764 }
1765 text = uiInfo.aliasList[value].name;
1766 }
1767 s = va("%i. %s", ownerDraw-UI_BLUETEAM1 + 1, text);
1768 break;
1769 case UI_REDTEAM1:
1770 case UI_REDTEAM2:
1771 case UI_REDTEAM3:
1772 case UI_REDTEAM4:
1773 case UI_REDTEAM5:
1774 value = trap_Cvar_VariableValue(va("ui_redteam%i", ownerDraw-UI_REDTEAM1 + 1));
1775 if (value <= 0) {
1776 text = "Closed";
1777 } else if (value == 1) {
1778 text = "Human";
1779 } else {
1780 value -= 2;
1781 if (value >= uiInfo.aliasCount) {
1782 value = 0;
1783 }
1784 text = uiInfo.aliasList[value].name;
1785 }
1786 s = va("%i. %s", ownerDraw-UI_REDTEAM1 + 1, text);
1787 break;
1788 case UI_NETSOURCE:
1789 if (ui_netSource.integer < 0 || ui_netSource.integer > uiInfo.numJoinGameTypes) {
1790 ui_netSource.integer = 0;
1791 }
1792 s = va("Source: %s", netSources[ui_netSource.integer]);
1793 break;
1794 case UI_NETFILTER:
1795 if (ui_serverFilterType.integer < 0 || ui_serverFilterType.integer > numServerFilters) {
1796 ui_serverFilterType.integer = 0;
1797 }
1798 s = va("Filter: %s", serverFilters[ui_serverFilterType.integer].description );
1799 break;
1800 case UI_TIER:
1801 break;
1802 case UI_TIER_MAPNAME:
1803 break;
1804 case UI_TIER_GAMETYPE:
1805 break;
1806 case UI_ALLMAPS_SELECTION:
1807 break;
1808 case UI_OPPONENT_NAME:
1809 break;
1810 case UI_KEYBINDSTATUS:
1811 if (Display_KeyBindPending()) {
1812 s = "Waiting for new key... Press ESCAPE to cancel";
1813 } else {
1814 s = "Press ENTER or CLICK to change, Press BACKSPACE to clear";
1815 }
1816 break;
1817 case UI_SERVERREFRESHDATE:
1818 s = UI_Cvar_VariableString(va("ui_lastServerRefresh_%i", ui_netSource.integer));
1819 break;
1820 default:
1821 break;
1822 }
1823
1824 if (s) {
1825 return Text_Width(s, scale, 0);
1826 }
1827 return 0;
1828 }
1829
1830 static void UI_DrawBotName(rectDef_t *rect, float scale, vec4_t color, int textStyle) {
1831 int value = uiInfo.botIndex;
1832 int game = trap_Cvar_VariableValue("g_gametype");
1833 const char *text = "";
1834 if (game >= GT_TEAM && !GT_LMS ) {
1835 if (value >= uiInfo.characterCount) {
1836 value = 0;
1837 }
1838 text = uiInfo.characterList[value].name;
1839 } else {
1840 if (value >= UI_GetNumBots()) {
1841 value = 0;
1842 }
1843 text = UI_GetBotNameByNumber(value);
1844 }
1845 Text_Paint(rect->x, rect->y, scale, color, text, 0, 0, textStyle);
1846 }
1847
1848 static void UI_DrawBotSkill(rectDef_t *rect, float scale, vec4_t color, int textStyle) {
1849 if (uiInfo.skillIndex >= 0 && uiInfo.skillIndex < numSkillLevels) {
1850 Text_Paint(rect->x, rect->y, scale, color, skillLevels[uiInfo.skillIndex], 0, 0, textStyle);
1851 }
1852 }
1853
1854 static void UI_DrawRedBlue(rectDef_t *rect, float scale, vec4_t color, int textStyle) {
1855 Text_Paint(rect->x, rect->y, scale, color, (uiInfo.redBlue == 0) ? "Red" : "Blue", 0, 0, textStyle);
1856 }
1857
1858 static void UI_DrawCrosshair(rectDef_t *rect, float scale, vec4_t color) {
1859 trap_R_SetColor( color );
1860 if (uiInfo.currentCrosshair < 0 || uiInfo.currentCrosshair >= NUM_CROSSHAIRS) {
1861 uiInfo.currentCrosshair = 0;
1862 }
1863 UI_DrawHandlePic( rect->x, rect->y - rect->h, rect->w, rect->h, uiInfo.uiDC.Assets.crosshairShader[uiInfo.currentCrosshair]);
1864 trap_R_SetColor( NULL );
1865 }
1866
1867 /*
1868 ===============
1869 UI_BuildPlayerList
1870 ===============
1871 */
1872 static void UI_BuildPlayerList( void ) {
1873 uiClientState_t cs;
1874 int n, count, team, team2, playerTeamNumber;
1875 char info[MAX_INFO_STRING];
1876
1877 trap_GetClientState( &cs );
1878 trap_GetConfigString( CS_PLAYERS + cs.clientNum, info, MAX_INFO_STRING );
1879 uiInfo.playerNumber = cs.clientNum;
1880 uiInfo.teamLeader = atoi(Info_ValueForKey(info, "tl"));
1881 team = atoi(Info_ValueForKey(info, "t"));
1882 trap_GetConfigString( CS_SERVERINFO, info, sizeof(info) );
1883 count = atoi( Info_ValueForKey( info, "sv_maxclients" ) );
1884 uiInfo.playerCount = 0;
1885 uiInfo.myTeamCount = 0;
1886 playerTeamNumber = 0;
1887 for( n = 0; n < count; n++ ) {
1888 trap_GetConfigString( CS_PLAYERS + n, info, MAX_INFO_STRING );
1889
1890 if (info[0]) {
1891 Q_strncpyz( uiInfo.playerNames[uiInfo.playerCount], Info_ValueForKey( info, "n" ), MAX_NAME_LENGTH );
1892 Q_CleanStr( uiInfo.playerNames[uiInfo.playerCount] );
1893 uiInfo.playerCount++;
1894 team2 = atoi(Info_ValueForKey(info, "t"));
1895 if (team2 == team) {
1896 Q_strncpyz( uiInfo.teamNames[uiInfo.myTeamCount], Info_ValueForKey( info, "n" ), MAX_NAME_LENGTH );
1897 Q_CleanStr( uiInfo.teamNames[uiInfo.myTeamCount] );
1898 uiInfo.teamClientNums[uiInfo.myTeamCount] = n;
1899 if (uiInfo.playerNumber == n) {
1900 playerTeamNumber = uiInfo.myTeamCount;
1901 }
1902 uiInfo.myTeamCount++;
1903 }
1904 }
1905 }
1906
1907 if (!uiInfo.teamLeader) {
1908 trap_Cvar_Set("cg_selectedPlayer", va("%d", playerTeamNumber));
1909 }
1910
1911 n = trap_Cvar_VariableValue("cg_selectedPlayer");
1912 if (n < 0 || n > uiInfo.myTeamCount) {
1913 n = 0;
1914 }
1915 if (n < uiInfo.myTeamCount) {
1916 trap_Cvar_Set("cg_selectedPlayerName", uiInfo.teamNames[n]);
1917 }
1918 }
1919
1920
1921 static void UI_DrawSelectedPlayer(rectDef_t *rect, float scale, vec4_t color, int textStyle) {
1922 if (uiInfo.uiDC.realTime > uiInfo.playerRefresh) {
1923 uiInfo.playerRefresh = uiInfo.uiDC.realTime + 3000;
1924 UI_BuildPlayerList();
1925 }
1926 Text_Paint(rect->x, rect->y, scale, color, (uiInfo.teamLeader) ? UI_Cvar_VariableString("cg_selectedPlayerName") : UI_Cvar_VariableString("name") , 0, 0, textStyle);
1927 }
1928
1929 static void UI_DrawServerRefreshDate(rectDef_t *rect, float scale, vec4_t color, int textStyle) {
1930 if (uiInfo.serverStatus.refreshActive) {
1931 vec4_t lowLight, newColor;
1932 lowLight[0] = 0.8 * color[0];
1933 lowLight[1] = 0.8 * color[1];
1934 lowLight[2] = 0.8 * color[2];
1935 lowLight[3] = 0.8 * color[3];
1936 LerpColor(color,lowLight,newColor,0.5+0.5*sin(uiInfo.uiDC.realTime / PULSE_DIVISOR));
1937 Text_Paint(rect->x, rect->y, scale, newColor, va("Getting info for %d servers (ESC to cancel)", trap_LAN_GetServerCount(ui_netSource.integer)), 0, 0, textStyle);
1938 } else {
1939 char buff[64];
1940 Q_strncpyz(buff, UI_Cvar_VariableString(va("ui_lastServerRefresh_%i", ui_netSource.integer)), 64);
1941 Text_Paint(rect->x, rect->y, scale, color, va("Refresh Time: %s", buff), 0, 0, textStyle);
1942 }
1943 }
1944
1945 static void UI_DrawServerMOTD(rectDef_t *rect, float scale, vec4_t color) {
1946 if (uiInfo.serverStatus.motdLen) {
1947 float maxX;
1948
1949 if (uiInfo.serverStatus.motdWidth == -1) {
1950 uiInfo.serverStatus.motdWidth = 0;
1951 uiInfo.serverStatus.motdPaintX = rect->x + 1;
1952 uiInfo.serverStatus.motdPaintX2 = -1;
1953 }
1954
1955 if (uiInfo.serverStatus.motdOffset > uiInfo.serverStatus.motdLen) {
1956 uiInfo.serverStatus.motdOffset = 0;
1957 uiInfo.serverStatus.motdPaintX = rect->x + 1;
1958 uiInfo.serverStatus.motdPaintX2 = -1;
1959 }
1960
1961 if (uiInfo.uiDC.realTime > uiInfo.serverStatus.motdTime) {
1962 uiInfo.serverStatus.motdTime = uiInfo.uiDC.realTime + 10;
1963 if (uiInfo.serverStatus.motdPaintX <= rect->x + 2) {
1964 if (uiInfo.serverStatus.motdOffset < uiInfo.serverStatus.motdLen) {
1965 uiInfo.serverStatus.motdPaintX += Text_Width(&uiInfo.serverStatus.motd[uiInfo.serverStatus.motdOffset], scale, 1) - 1;
1966 uiInfo.serverStatus.motdOffset++;
1967 } else {
1968 uiInfo.serverStatus.motdOffset = 0;
1969 if (uiInfo.serverStatus.motdPaintX2 >= 0) {
1970 uiInfo.serverStatus.motdPaintX = uiInfo.serverStatus.motdPaintX2;
1971 } else {
1972 uiInfo.serverStatus.motdPaintX = rect->x + rect->w - 2;
1973 }
1974 uiInfo.serverStatus.motdPaintX2 = -1;
1975 }
1976 } else {
1977 //serverStatus.motdPaintX--;
1978 uiInfo.serverStatus.motdPaintX -= 2;
1979 if (uiInfo.serverStatus.motdPaintX2 >= 0) {
1980 //serverStatus.motdPaintX2--;
1981 uiInfo.serverStatus.motdPaintX2 -= 2;
1982 }
1983 }
1984 }
1985
1986 maxX = rect->x + rect->w - 2;
1987 Text_Paint_Limit(&maxX, uiInfo.serverStatus.motdPaintX, rect->y + rect->h - 3, scale, color, &uiInfo.serverStatus.motd[uiInfo.serverStatus.motdOffset], 0, 0);
1988 if (uiInfo.serverStatus.motdPaintX2 >= 0) {
1989 float maxX2 = rect->x + rect->w - 2;
1990 Text_Paint_Limit(&maxX2, uiInfo.serverStatus.motdPaintX2, rect->y + rect->h - 3, scale, color, uiInfo.serverStatus.motd, 0, uiInfo.serverStatus.motdOffset);
1991 }
1992 if (uiInfo.serverStatus.motdOffset && maxX > 0) {
1993 // if we have an offset ( we are skipping the first part of the string ) and we fit the string
1994 if (uiInfo.serverStatus.motdPaintX2 == -1) {
1995 uiInfo.serverStatus.motdPaintX2 = rect->x + rect->w - 2;
1996 }
1997 } else {
1998 uiInfo.serverStatus.motdPaintX2 = -1;
1999 }
2000
2001 }
2002 }
2003
2004 static void UI_DrawKeyBindStatus(rectDef_t *rect, float scale, vec4_t color, int textStyle) {
2005 // int ofs = 0; TTimo: unused
2006 if (Display_KeyBindPending()) {
2007 Text_Paint(rect->x, rect->y, scale, color, "Waiting for new key... Press ESCAPE to cancel", 0, 0, textStyle);
2008 } else {
2009 Text_Paint(rect->x, rect->y, scale, color, "Press ENTER or CLICK to change, Press BACKSPACE to clear", 0, 0, textStyle);
2010 }
2011 }
2012
2013 static void UI_DrawGLInfo(rectDef_t *rect, float scale, vec4_t color, int textStyle) {
2014 char * eptr;
2015 char buff[1024];
2016 const char *lines[64];
2017 int y, numLines, i;
2018
2019 Text_Paint(rect->x + 2, rect->y, scale, color, va("VENDOR: %s", uiInfo.uiDC.glconfig.vendor_string), 0, 30, textStyle);
2020 Text_Paint(rect->x + 2, rect->y + 15, scale, color, va("VERSION: %s: %s", uiInfo.uiDC.glconfig.version_string,uiInfo.uiDC.glconfig.renderer_string), 0, 30, textStyle);
2021 Text_Paint(rect->x + 2, rect->y + 30, scale, color, va ("PIXELFORMAT: color(%d-bits) Z(%d-bits) stencil(%d-bits)", uiInfo.uiDC.glconfig.colorBits, uiInfo.uiDC.glconfig.depthBits, uiInfo.uiDC.glconfig.stencilBits), 0, 30, textStyle);
2022
2023 // build null terminated extension strings
2024 // TTimo: https://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=399
2025 // in TA this was not directly crashing, but displaying a nasty broken shader right in the middle
2026 // brought down the string size to 1024, there's not much that can be shown on the screen anyway
2027 Q_strncpyz(buff, uiInfo.uiDC.glconfig.extensions_string, 1024);
2028 eptr = buff;
2029 y = rect->y + 45;
2030 numLines = 0;
2031 while ( y < rect->y + rect->h && *eptr )
2032 {
2033 while ( *eptr && *eptr == ' ' )
2034 *eptr++ = '\0';
2035
2036 // track start of valid string
2037 if (*eptr && *eptr != ' ') {
2038 lines[numLines++] = eptr;
2039 }
2040
2041 while ( *eptr && *eptr != ' ' )
2042 eptr++;
2043 }
2044
2045 i = 0;
2046 while (i < numLines) {
2047 Text_Paint(rect->x + 2, y, scale, color, lines[i++], 0, 20, textStyle);
2048 if (i < numLines) {
2049 Text_Paint(rect->x + rect->w / 2, y, scale, color, lines[i++], 0, 20, textStyle);
2050 }
2051 y += 10;
2052 if (y > rect->y + rect->h - 11) {
2053 break;
2054 }
2055 }
2056
2057
2058 }
2059
2060 // FIXME: table drive
2061 //
2062 static void UI_OwnerDraw(float x, float y, float w, float h, float text_x, float text_y, int ownerDraw, int ownerDrawFlags, int align, float special, float scale, vec4_t color, qhandle_t shader, int textStyle) {
2063 rectDef_t rect;
2064
2065 rect.x = x + text_x;
2066 rect.y = y + text_y;
2067 rect.w = w;
2068 rect.h = h;
2069
2070 switch (ownerDraw) {
2071 case UI_HANDICAP:
2072 UI_DrawHandicap(&rect, scale, color, textStyle);
2073 break;
2074 case UI_EFFECTS:
2075 UI_DrawEffects(&rect, scale, color);
2076 break;
2077 case UI_PLAYERMODEL:
2078 UI_DrawPlayerModel(&rect);
2079 break;
2080 case UI_PLAYERMODEL2:
2081 UI_DrawPlayerModel2(&rect);
2082 break;
2083 case UI_CLANNAME:
2084 UI_DrawClanName(&rect, scale, color, textStyle);
2085 break;
2086 case UI_CLANLOGO:
2087 UI_DrawClanLogo(&rect, scale, color);
2088 break;
2089 case UI_CLANCINEMATIC:
2090 UI_DrawClanCinematic(&rect, scale, color);
2091 break;
2092 case UI_PREVIEWCINEMATIC:
2093 UI_DrawPreviewCinematic(&rect, scale, color);
2094 break;
2095 case UI_GAMETYPE:
2096 UI_DrawGameType(&rect, scale, color, textStyle);
2097 break;
2098 case UI_NETGAMETYPE:
2099 UI_DrawNetGameType(&rect, scale, color, textStyle);
2100 break;
2101 case UI_JOINGAMETYPE:
2102 UI_DrawJoinGameType(&rect, scale, color, textStyle);
2103 break;
2104 case UI_MAPPREVIEW:
2105 UI_DrawMapPreview(&rect, scale, color, qtrue);
2106 break;
2107 case UI_MAP_TIMETOBEAT:
2108 UI_DrawMapTimeToBeat(&rect, scale, color, textStyle);
2109 break;
2110 case UI_MAPCINEMATIC:
2111 UI_DrawMapCinematic(&rect, scale, color, qfalse);
2112 break;
2113 case UI_STARTMAPCINEMATIC:
2114 UI_DrawMapCinematic(&rect, scale, color, qtrue);
2115 break;
2116 case UI_SKILL:
2117 UI_DrawSkill(&rect, scale, color, textStyle);
2118 break;
2119 case UI_BLUETEAMNAME:
2120 UI_DrawTeamName(&rect, scale, color, qtrue, textStyle);
2121 break;
2122 case UI_REDTEAMNAME:
2123 UI_DrawTeamName(&rect, scale, color, qfalse, textStyle);
2124 break;
2125 case UI_BLUETEAM1:
2126 case UI_BLUETEAM2:
2127 case UI_BLUETEAM3:
2128 case UI_BLUETEAM4:
2129 case UI_BLUETEAM5:
2130 UI_DrawTeamMember(&rect, scale, color, qtrue, ownerDraw - UI_BLUETEAM1 + 1, textStyle);
2131 break;
2132 case UI_REDTEAM1:
2133 case UI_REDTEAM2:
2134 case UI_REDTEAM3:
2135 case UI_REDTEAM4:
2136 case UI_REDTEAM5:
2137 UI_DrawTeamMember(&rect, scale, color, qfalse, ownerDraw - UI_REDTEAM1 + 1, textStyle);
2138 break;
2139 case UI_NETSOURCE:
2140 UI_DrawNetSource(&rect, scale, color, textStyle);
2141 break;
2142 case UI_NETMAPPREVIEW:
2143 UI_DrawNetMapPreview(&rect, scale, color);
2144 break;
2145 case UI_NETMAPCINEMATIC:
2146 UI_DrawNetMapCinematic(&rect, scale, color);
2147 break;
2148 case UI_NETFILTER:
2149 UI_DrawNetFilter(&rect, scale, color, textStyle);
2150 break;
2151 case UI_TIER:
2152 UI_DrawTier(&rect, scale, color, textStyle);
2153 break;
2154 case UI_OPPONENTMODEL:
2155 UI_DrawOpponent(&rect);
2156 break;
2157 case UI_OPPONENTMODEL2:
2158 UI_DrawOpponent2(&rect);
2159 break;
2160 case UI_TIERMAP1:
2161 UI_DrawTierMap(&rect, 0);
2162 break;
2163 case UI_TIERMAP2:
2164 UI_DrawTierMap(&rect, 1);
2165 break;
2166 case UI_TIERMAP3:
2167 UI_DrawTierMap(&rect, 2);
2168 break;
2169 case UI_PLAYERLOGO:
2170 UI_DrawPlayerLogo(&rect, color);
2171 break;
2172 case UI_PLAYERLOGO_METAL:
2173 UI_DrawPlayerLogoMetal(&rect, color);
2174 break;
2175 case UI_PLAYERLOGO_NAME:
2176 UI_DrawPlayerLogoName(&rect, color);
2177 break;
2178 case UI_OPPONENTLOGO:
2179 UI_DrawOpponentLogo(&rect, color);
2180 break;
2181 case UI_OPPONENTLOGO_METAL:
2182 UI_DrawOpponentLogoMetal(&rect, color);
2183 break;
2184 case UI_OPPONENTLOGO_NAME:
2185 UI_DrawOpponentLogoName(&rect, color);
2186 break;
2187 case UI_TIER_MAPNAME:
2188 UI_DrawTierMapName(&rect, scale, color, textStyle);
2189 break;
2190 case UI_TIER_GAMETYPE:
2191 UI_DrawTierGameType(&rect, scale, color, textStyle);
2192 break;
2193 case UI_ALLMAPS_SELECTION:
2194 UI_DrawAllMapsSelection(&rect, scale, color, textStyle, qtrue);
2195 break;
2196 case UI_MAPS_SELECTION:
2197 UI_DrawAllMapsSelection(&rect, scale, color, textStyle, qfalse);
2198 break;
2199 case UI_OPPONENT_NAME:
2200 UI_DrawOpponentName(&rect, scale, color, textStyle);
2201 break;
2202 case UI_BOTNAME:
2203 UI_DrawBotName(&rect, scale, color, textStyle);
2204 break;
2205 case UI_BOTSKILL:
2206 UI_DrawBotSkill(&rect, scale, color, textStyle);
2207 break;
2208 case UI_REDBLUE:
2209 UI_DrawRedBlue(&rect, scale, color, textStyle);
2210 break;
2211 case UI_CROSSHAIR:
2212 UI_DrawCrosshair(&rect, scale, color);
2213 break;
2214 case UI_SELECTEDPLAYER:
2215 UI_DrawSelectedPlayer(&rect, scale, color, textStyle);
2216 break;
2217 case UI_SERVERREFRESHDATE:
2218 UI_DrawServerRefreshDate(&rect, scale, color, textStyle);
2219 break;
2220 case UI_SERVERMOTD:
2221 UI_DrawServerMOTD(&rect, scale, color);
2222 break;
2223 case UI_GLINFO:
2224 UI_DrawGLInfo(&rect,scale, color, textStyle);
2225 break;
2226 case UI_KEYBINDSTATUS:
2227 UI_DrawKeyBindStatus(&rect,scale, color, textStyle);
2228 break;
2229 default:
2230 break;
2231 }
2232
2233 }
2234
2235 static qboolean UI_OwnerDrawVisible(int flags) {
2236 qboolean vis = qtrue;
2237
2238 while (flags) {
2239
2240 if (flags & UI_SHOW_FFA) {
2241 if (trap_Cvar_VariableValue("g_gametype") != GT_FFA || trap_Cvar_VariableValue("g_gametype") != GT_LMS ) {
2242 vis = qfalse;
2243 }
2244 flags &= ~UI_SHOW_FFA;
2245 }
2246
2247 if (flags & UI_SHOW_NOTFFA) {
2248 if (trap_Cvar_VariableValue("g_gametype") == GT_FFA || trap_Cvar_VariableValue("g_gametype") == GT_LMS ) {
2249 vis = qfalse;
2250 }
2251 flags &= ~UI_SHOW_NOTFFA;
2252 }
2253
2254 if (flags & UI_SHOW_LEADER) {
2255 // these need to show when this client can give orders to a player or a group
2256 if (!uiInfo.teamLeader) {
2257 vis = qfalse;
2258 } else {
2259 // if showing yourself
2260 if (ui_selectedPlayer.integer < uiInfo.myTeamCount && uiInfo.teamClientNums[ui_selectedPlayer.integer] == uiInfo.playerNumber) {
2261 vis = qfalse;
2262 }
2263 }
2264 flags &= ~UI_SHOW_LEADER;
2265 }
2266 if (flags & UI_SHOW_NOTLEADER) {
2267 // these need to show when this client is assigning their own status or they are NOT the leader
2268 if (uiInfo.teamLeader) {
2269 // if not showing yourself
2270 if (!(ui_selectedPlayer.integer < uiInfo.myTeamCount && uiInfo.teamClientNums[ui_selectedPlayer.integer] == uiInfo.playerNumber)) {
2271 vis = qfalse;
2272 }
2273 // these need to show when this client can give orders to a player or a group
2274 }
2275 flags &= ~UI_SHOW_NOTLEADER;
2276 }
2277 if (flags & UI_SHOW_FAVORITESERVERS) {
2278 // this assumes you only put this type of display flag on something showing in the proper context
2279 if (ui_netSource.integer != AS_FAVORITES) {
2280 vis = qfalse;
2281 }
2282 flags &= ~UI_SHOW_FAVORITESERVERS;
2283 }
2284 if (flags & UI_SHOW_NOTFAVORITESERVERS) {
2285 // this assumes you only put this type of display flag on something showing in the proper context
2286 if (ui_netSource.integer == AS_FAVORITES) {
2287 vis = qfalse;
2288 }
2289 flags &= ~UI_SHOW_NOTFAVORITESERVERS;
2290 }
2291 if (flags & UI_SHOW_ANYTEAMGAME) {
2292 if (uiInfo.gameTypes[ui_gameType.integer].gtEnum <= GT_TEAM && uiInfo.gameTypes[ui_gameType.integer].gtEnum != GT_LMS ) {
2293 vis = qfalse;
2294 }
2295 flags &= ~UI_SHOW_ANYTEAMGAME;
2296 }
2297 if (flags & UI_SHOW_ANYNONTEAMGAME) {
2298 if (uiInfo.gameTypes[ui_gameType.integer].gtEnum > GT_TEAM || uiInfo.gameTypes[ui_gameType.integer].gtEnum == GT_LMS ) {
2299 vis = qfalse;
2300 }
2301 flags &= ~UI_SHOW_ANYNONTEAMGAME;
2302 }
2303 if (flags & UI_SHOW_NETANYTEAMGAME) {
2304 if (uiInfo.gameTypes[ui_netGameType.integer].gtEnum <= GT_TEAM && uiInfo.gameTypes[ui_gameType.integer].gtEnum != GT_LMS ) {
2305 vis = qfalse;
2306 }
2307 flags &= ~UI_SHOW_NETANYTEAMGAME;
2308 }
2309 if (flags & UI_SHOW_NETANYNONTEAMGAME) {
2310 if (uiInfo.gameTypes[ui_netGameType.integer].gtEnum > GT_TEAM || uiInfo.gameTypes[ui_gameType.integer].gtEnum == GT_LMS ) {
2311 vis = qfalse;
2312 }
2313 flags &= ~UI_SHOW_NETANYNONTEAMGAME;
2314 }
2315 if (flags & UI_SHOW_NEWHIGHSCORE) {
2316 if (uiInfo.newHighScoreTime < uiInfo.uiDC.realTime) {
2317 vis = qfalse;
2318 } else {
2319 if (uiInfo.soundHighScore) {
2320 if (trap_Cvar_VariableValue("sv_killserver") == 0) {
2321 // wait on server to go down before playing sound
2322 trap_S_StartLocalSound(uiInfo.newHighScoreSound, CHAN_ANNOUNCER);
2323 uiInfo.soundHighScore = qfalse;
2324 }
2325 }
2326 }
2327 flags &= ~UI_SHOW_NEWHIGHSCORE;
2328 }
2329 if (flags & UI_SHOW_NEWBESTTIME) {
2330 if (uiInfo.newBestTime < uiInfo.uiDC.realTime) {
2331 vis = qfalse;
2332 }
2333 flags &= ~UI_SHOW_NEWBESTTIME;
2334 }
2335 if (flags & UI_SHOW_DEMOAVAILABLE) {
2336 if (!uiInfo.demoAvailable) {
2337 vis = qfalse;
2338 }
2339 flags &= ~UI_SHOW_DEMOAVAILABLE;
2340 } else {
2341 flags = 0;
2342 }
2343 }
2344 return vis;
2345 }
2346
2347 static qboolean UI_Handicap_HandleKey(int flags, float *special, int key) {
2348 if (key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER) {
2349 int h;
2350 h = Com_Clamp( 5, 100, trap_Cvar_VariableValue("handicap") );
2351 if (key == K_MOUSE2) {
2352 h -= 5;
2353 } else {
2354 h += 5;
2355 }
2356 if (h > 100) {
2357 h = 5;
2358 } else if (h < 0) {
2359 h = 100;
2360 }
2361 trap_Cvar_Set( "handicap", va( "%i", h) );
2362 return qtrue;
2363 }
2364 return qfalse;
2365 }
2366
2367 static qboolean UI_Effects_HandleKey(int flags, float *special, int key) {
2368 if (key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER) {
2369
2370 if (key == K_MOUSE2) {
2371 uiInfo.effectsColor--;
2372 } else {
2373 uiInfo.effectsColor++;
2374 }
2375
2376 if( uiInfo.effectsColor > 6 ) {
2377 uiInfo.effectsColor = 0;
2378 } else if (uiInfo.effectsColor < 0) {
2379 uiInfo.effectsColor = 6;
2380 }
2381
2382 trap_Cvar_SetValue( "color1", uitogamecode[uiInfo.effectsColor] );
2383 return qtrue;
2384 }
2385 return qfalse;
2386 }
2387
2388 static qboolean UI_ClanName_HandleKey(int flags, float *special, int key) {
2389 if (key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER) {
2390 int i;
2391 i = UI_TeamIndexFromName(UI_Cvar_VariableString("ui_teamName"));
2392 if (uiInfo.teamList[i].cinematic >= 0) {
2393 trap_CIN_StopCinematic(uiInfo.teamList[i].cinematic);
2394 uiInfo.teamList[i].cinematic = -1;
2395 }
2396 if (key == K_MOUSE2) {
2397 i--;
2398 } else {
2399 i++;
2400 }
2401 if (i >= uiInfo.teamCount) {
2402 i = 0;
2403 } else if (i < 0) {
2404 i = uiInfo.teamCount - 1;
2405 }
2406 trap_Cvar_Set( "ui_teamName", uiInfo.teamList[i].teamName);
2407 UI_HeadCountByTeam();
2408 UI_FeederSelection(FEEDER_HEADS, 0);
2409 updateModel = qtrue;
2410 return qtrue;
2411 }
2412 return qfalse;
2413 }
2414
2415 static qboolean UI_GameType_HandleKey(int flags, float *special, int key, qboolean resetMap) {
2416 if (key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER) {
2417 int oldCount = UI_MapCountByGameType(qtrue);
2418
2419 // hard coded mess here
2420 if (key == K_MOUSE2) {
2421 ui_gameType.integer--;
2422 if (ui_gameType.integer == 2) {
2423 ui_gameType.integer = 1;
2424 } else if (ui_gameType.integer < 2) {
2425 ui_gameType.integer = uiInfo.numGameTypes - 1;
2426 }
2427 } else {
2428 ui_gameType.integer++;
2429 if (ui_gameType.integer >= uiInfo.numGameTypes) {
2430 ui_gameType.integer = 1;
2431 } else if (ui_gameType.integer == 2) {
2432 ui_gameType.integer = 3;
2433 }
2434 }
2435
2436 if (uiInfo.gameTypes[ui_gameType.integer].gtEnum == GT_TOURNAMENT) {
2437 trap_Cvar_Set("ui_Q3Model", "1");
2438 } else {
2439 trap_Cvar_Set("ui_Q3Model", "0");
2440 }
2441
2442 trap_Cvar_Set("ui_gameType", va("%d", ui_gameType.integer));
2443 UI_SetCapFragLimits(qtrue);
2444 UI_LoadBestScores(uiInfo.mapList[ui_currentMap.integer].mapLoadName, uiInfo.gameTypes[ui_gameType.integer].gtEnum);
2445 if (resetMap && oldCount != UI_MapCountByGameType(qtrue)) {
2446 trap_Cvar_Set( "ui_currentMap", "0");
2447 Menu_SetFeederSelection(NULL, FEEDER_MAPS, 0, NULL);
2448 }
2449 return qtrue;
2450 }
2451 return qfalse;
2452 }
2453
2454 static qboolean UI_NetGameType_HandleKey(int flags, float *special, int key) {
2455 if (key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER) {
2456
2457 if (key == K_MOUSE2) {
2458 ui_netGameType.integer--;
2459 } else {
2460 ui_netGameType.integer++;
2461 }
2462
2463 if (ui_netGameType.integer < 0) {
2464 ui_netGameType.integer = uiInfo.numGameTypes - 1;
2465 } else if (ui_netGameType.integer >= uiInfo.numGameTypes) {
2466 ui_netGameType.integer = 0;
2467 }
2468
2469 trap_Cvar_Set( "ui_netGameType", va("%d", ui_netGameType.integer));
2470 trap_Cvar_Set( "ui_actualnetGameType", va("%d", uiInfo.gameTypes[ui_netGameType.integer].gtEnum));
2471 trap_Cvar_Set( "ui_currentNetMap", "0");
2472 UI_MapCountByGameType(qfalse);
2473 Menu_SetFeederSelection(NULL, FEEDER_ALLMAPS, 0, NULL);
2474 return qtrue;
2475 }
2476 return qfalse;
2477 }
2478
2479 static qboolean UI_JoinGameType_HandleKey(int flags, float *special, int key) {
2480 if (key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER) {
2481
2482 if (key == K_MOUSE2) {
2483 ui_joinGameType.integer--;
2484 } else {
2485 ui_joinGameType.integer++;
2486 }
2487
2488 if (ui_joinGameType.integer < 0) {
2489 ui_joinGameType.integer = uiInfo.numJoinGameTypes - 1;
2490 } else if (ui_joinGameType.integer >= uiInfo.numJoinGameTypes) {
2491 ui_joinGameType.integer = 0;
2492 }
2493
2494 trap_Cvar_Set( "ui_joinGameType", va("%d", ui_joinGameType.integer));
2495 UI_BuildServerDisplayList(qtrue);
2496 return qtrue;
2497 }
2498 return qfalse;
2499 }
2500
2501
2502
2503 static qboolean UI_Skill_HandleKey(int flags, float *special, int key) {
2504 if (key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER) {
2505 int i = trap_Cvar_VariableValue( "g_spSkill" );
2506
2507 if (key == K_MOUSE2) {
2508 i--;
2509 } else {
2510 i++;
2511 }
2512
2513 if (i < 1) {
2514 i = numSkillLevels;
2515 } else if (i > numSkillLevels) {
2516 i = 1;
2517 }
2518
2519 trap_Cvar_Set("g_spSkill", va("%i", i));
2520 return qtrue;
2521 }
2522 return qfalse;
2523 }
2524
2525 static qboolean UI_TeamName_HandleKey(int flags, float *special, int key, qboolean blue) {
2526 if (key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER) {
2527 int i;
2528 i = UI_TeamIndexFromName(UI_Cvar_VariableString((blue) ? "ui_blueTeam" : "ui_redTeam"));
2529
2530 if (key == K_MOUSE2) {
2531 i--;
2532 } else {
2533 i++;
2534 }
2535
2536 if (i >= uiInfo.teamCount) {
2537 i = 0;
2538 } else if (i < 0) {
2539 i = uiInfo.teamCount - 1;
2540 }
2541
2542 trap_Cvar_Set( (blue) ? "ui_blueTeam" : "ui_redTeam", uiInfo.teamList[i].teamName);
2543
2544 return qtrue;
2545 }
2546 return qfalse;
2547 }
2548
2549 static qboolean UI_TeamMember_HandleKey(int flags, float *special, int key, qboolean blue, int num) {
2550 if (key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER) {
2551 // 0 - None
2552 // 1 - Human
2553 // 2..NumCharacters - Bot
2554 char *cvar = va(blue ? "ui_blueteam%i" : "ui_redteam%i", num);
2555 int value = trap_Cvar_VariableValue(cvar);
2556
2557 if (key == K_MOUSE2) {
2558 value--;
2559 } else {
2560 value++;
2561 }
2562
2563 if (ui_actualNetGameType.integer >= GT_TEAM) {
2564 if (value >= uiInfo.characterCount + 2) {
2565 value = 0;
2566 } else if (value < 0) {
2567 value = uiInfo.characterCount + 2 - 1;
2568 }
2569 } else {
2570 if (value >= UI_GetNumBots() + 2) {
2571 value = 0;
2572 } else if (value < 0) {
2573 value = UI_GetNumBots() + 2 - 1;
2574 }
2575 }
2576
2577 trap_Cvar_Set(cvar, va("%i", value));
2578 return qtrue;
2579 }
2580 return qfalse;
2581 }
2582
2583 static qboolean UI_NetSource_HandleKey(int flags, float *special, int key) {
2584 if (key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER) {
2585
2586 if (key == K_MOUSE2) {
2587 ui_netSource.integer--;
2588 if(strlen(netSources[ui_netSource.integer])<1)
2589 ui_netSource.integer--;
2590 } else {
2591 ui_netSource.integer++;
2592 if(strlen(netSources[ui_netSource.integer])<1)
2593 ui_netSource.integer++;
2594 }
2595
2596 if (ui_netSource.integer >= numNetSources) {
2597 ui_netSource.integer = 0;
2598 } else if (ui_netSource.integer < 0) {
2599 ui_netSource.integer = numNetSources - 1;
2600 }
2601
2602 UI_BuildServerDisplayList(qtrue);
2603 if (ui_netSource.integer != AS_GLOBAL) {
2604 UI_StartServerRefresh(qtrue);
2605 }
2606 trap_Cvar_Set( "ui_netSource", va("%d", ui_netSource.integer));
2607 return qtrue;
2608 }
2609 return qfalse;
2610 }
2611
2612 static qboolean UI_NetFilter_HandleKey(int flags, float *special, int key) {
2613 if (key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER) {
2614
2615 if (key == K_MOUSE2) {
2616 ui_serverFilterType.integer--;
2617 } else {
2618 ui_serverFilterType.integer++;
2619 }
2620
2621 if (ui_serverFilterType.integer >= numServerFilters) {
2622 ui_serverFilterType.integer = 0;
2623 } else if (ui_serverFilterType.integer < 0) {
2624 ui_serverFilterType.integer = numServerFilters - 1;
2625 }
2626 UI_BuildServerDisplayList(qtrue);
2627 return qtrue;
2628 }
2629 return qfalse;
2630 }
2631
2632 static qboolean UI_OpponentName_HandleKey(int flags, float *special, int key) {
2633 if (key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER) {
2634 if (key == K_MOUSE2) {
2635 UI_PriorOpponent();
2636 } else {
2637 UI_NextOpponent();
2638 }
2639 return qtrue;
2640 }
2641 return qfalse;
2642 }
2643
2644 static qboolean UI_BotName_HandleKey(int flags, float *special, int key) {
2645 if (key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER) {
2646 int game = trap_Cvar_VariableValue("g_gametype");
2647 int value = uiInfo.botIndex;
2648
2649 if (key == K_MOUSE2) {
2650 value--;
2651 } else {
2652 value++;
2653 }
2654
2655 if (game >= GT_TEAM && !GT_LMS) {
2656 if (value >= uiInfo.characterCount + 2) {
2657 value = 0;
2658 } else if (value < 0) {
2659 value = uiInfo.characterCount + 2 - 1;
2660 }
2661 } else {
2662 if (value >= UI_GetNumBots() + 2) {
2663 value = 0;
2664 } else if (value < 0) {
2665 value = UI_GetNumBots() + 2 - 1;
2666 }
2667 }
2668 uiInfo.botIndex = value;
2669 return qtrue;
2670 }
2671 return qfalse;
2672 }
2673
2674 static qboolean UI_BotSkill_HandleKey(int flags, float *special, int key) {
2675 if (key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER) {
2676 if (key == K_MOUSE2) {
2677 uiInfo.skillIndex--;
2678 } else {
2679 uiInfo.skillIndex++;
2680 }
2681 if (uiInfo.skillIndex >= numSkillLevels) {
2682 uiInfo.skillIndex = 0;
2683 } else if (uiInfo.skillIndex < 0) {
2684 uiInfo.skillIndex = numSkillLevels-1;
2685 }
2686 return qtrue;
2687 }
2688 return qfalse;
2689 }
2690
2691 static qboolean UI_RedBlue_HandleKey(int flags, float *special, int key) {
2692 if (key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER) {
2693 uiInfo.redBlue ^= 1;
2694 return qtrue;
2695 }
2696 return qfalse;
2697 }
2698
2699 static qboolean UI_Crosshair_HandleKey(int flags, float *special, int key) {
2700 if (key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER) {
2701 if (key == K_MOUSE2) {
2702 uiInfo.currentCrosshair--;
2703 } else {
2704 uiInfo.currentCrosshair++;
2705 }
2706
2707 if (uiInfo.currentCrosshair >= NUM_CROSSHAIRS) {
2708 uiInfo.currentCrosshair = 0;
2709 } else if (uiInfo.currentCrosshair < 0) {
2710 uiInfo.currentCrosshair = NUM_CROSSHAIRS - 1;
2711 }
2712 trap_Cvar_Set("cg_drawCrosshair", va("%d", uiInfo.currentCrosshair));
2713 return qtrue;
2714 }
2715 return qfalse;
2716 }
2717
2718
2719
2720 static qboolean UI_SelectedPlayer_HandleKey(int flags, float *special, int key) {
2721 if (key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER) {
2722 int selected;
2723
2724 UI_BuildPlayerList();
2725 if (!uiInfo.teamLeader) {
2726 return qfalse;
2727 }
2728 selected = trap_Cvar_VariableValue("cg_selectedPlayer");
2729
2730 if (key == K_MOUSE2) {
2731 selected--;
2732 } else {
2733 selected++;
2734 }
2735
2736 if (selected > uiInfo.myTeamCount) {
2737 selected = 0;
2738 } else if (selected < 0) {
2739 selected = uiInfo.myTeamCount;
2740 }
2741
2742 if (selected == uiInfo.myTeamCount) {
2743 trap_Cvar_Set( "cg_selectedPlayerName", "Everyone");
2744 } else {
2745 trap_Cvar_Set( "cg_selectedPlayerName", uiInfo.teamNames[selected]);
2746 }
2747 trap_Cvar_Set( "cg_selectedPlayer", va("%d", selected));
2748 }
2749 return qfalse;
2750 }
2751
2752
2753 static qboolean UI_OwnerDrawHandleKey(int ownerDraw, int flags, float *special, int key) {
2754 switch (ownerDraw) {
2755 case UI_HANDICAP:
2756 return UI_Handicap_HandleKey(flags, special, key);
2757 break;
2758 case UI_EFFECTS:
2759 return UI_Effects_HandleKey(flags, special, key);
2760 break;
2761 case UI_CLANNAME:
2762 return UI_ClanName_HandleKey(flags, special, key);
2763 break;
2764 case UI_GAMETYPE:
2765 return UI_GameType_HandleKey(flags, special, key, qtrue);
2766 break;
2767 case UI_NETGAMETYPE:
2768 return UI_NetGameType_HandleKey(flags, special, key);
2769 break;
2770 case UI_JOINGAMETYPE:
2771 return UI_JoinGameType_HandleKey(flags, special, key);
2772 break;
2773 case UI_SKILL:
2774 return UI_Skill_HandleKey(flags, special, key);
2775 break;
2776 case UI_BLUETEAMNAME:
2777 return UI_TeamName_HandleKey(flags, special, key, qtrue);
2778 break;
2779 case UI_REDTEAMNAME:
2780 return UI_TeamName_HandleKey(flags, special, key, qfalse);
2781 break;
2782 case UI_BLUETEAM1:
2783 case UI_BLUETEAM2:
2784 case UI_BLUETEAM3:
2785 case UI_BLUETEAM4:
2786 case UI_BLUETEAM5:
2787 UI_TeamMember_HandleKey(flags, special, key, qtrue, ownerDraw - UI_BLUETEAM1 + 1);
2788 break;
2789 case UI_REDTEAM1:
2790 case UI_REDTEAM2:
2791 case UI_REDTEAM3:
2792 case UI_REDTEAM4:
2793 case UI_REDTEAM5:
2794 UI_TeamMember_HandleKey(flags, special, key, qfalse, ownerDraw - UI_REDTEAM1 + 1);
2795 break;
2796 case UI_NETSOURCE:
2797 UI_NetSource_HandleKey(flags, special, key);
2798 break;
2799 case UI_NETFILTER:
2800 UI_NetFilter_HandleKey(flags, special, key);
2801 break;
2802 case UI_OPPONENT_NAME:
2803 UI_OpponentName_HandleKey(flags, special, key);
2804 break;
2805 case UI_BOTNAME:
2806 return UI_BotName_HandleKey(flags, special, key);
2807 break;
2808 case UI_BOTSKILL:
2809 return UI_BotSkill_HandleKey(flags, special, key);
2810 break;
2811 case UI_REDBLUE:
2812 UI_RedBlue_HandleKey(flags, special, key);
2813 break;
2814 case UI_CROSSHAIR:
2815 UI_Crosshair_HandleKey(flags, special, key);
2816 break;
2817 case UI_SELECTEDPLAYER:
2818 UI_SelectedPlayer_HandleKey(flags, special, key);
2819 break;
2820 default:
2821 break;
2822 }
2823
2824 return qfalse;
2825 }
2826
2827
2828 static float UI_GetValue(int ownerDraw) {
2829 return 0;
2830 }
2831
2832 /*
2833 =================
2834 UI_ServersQsortCompare
2835 =================
2836 */
2837 static int QDECL UI_ServersQsortCompare( const void *arg1, const void *arg2 ) {
2838 return trap_LAN_CompareServers( ui_netSource.integer, uiInfo.serverStatus.sortKey, uiInfo.serverStatus.sortDir, *(int*)arg1, *(int*)arg2);
2839 }
2840
2841
2842 /*
2843 =================
2844 UI_ServersSort
2845 =================
2846 */
2847 void UI_ServersSort(int column, qboolean force) {
2848
2849 if ( !force ) {
2850 if ( uiInfo.serverStatus.sortKey == column ) {
2851 return;
2852 }
2853 }
2854
2855 uiInfo.serverStatus.sortKey = column;
2856 qsort( &uiInfo.serverStatus.displayServers[0], uiInfo.serverStatus.numDisplayServers, sizeof(int), UI_ServersQsortCompare);
2857 }
2858
2859 /*
2860 static void UI_StartSinglePlayer(void) {
2861 int i,j, k, skill;
2862 char buff[1024];
2863 i = trap_Cvar_VariableValue( "ui_currentTier" );
2864 if (i < 0 || i >= tierCount) {
2865 i = 0;
2866 }
2867 j = trap_Cvar_VariableValue("ui_currentMap");
2868 if (j < 0 || j > MAPS_PER_TIER) {
2869 j = 0;
2870 }
2871
2872 trap_Cvar_SetValue( "singleplayer", 1 );
2873 trap_Cvar_SetValue( "g_gametype", Com_Clamp( 0, 7, tierList[i].gameTypes[j] ) );
2874 trap_Cmd_ExecuteText( EXEC_APPEND, va( "wait ; wait ; map %s\n", tierList[i].maps[j] ) );
2875 skill = trap_Cvar_VariableValue( "g_spSkill" );
2876
2877 if (j == MAPS_PER_TIER-1) {
2878 k = UI_TeamIndexFromName(UI_Cvar_VariableString("ui_opponentName"));
2879 Com_sprintf( buff, sizeof(buff), "wait ; addbot %s %i %s 250 %s\n", UI_AIFromName(teamList[k].teamMembers[0]), skill, "", teamList[k].teamMembers[0]);
2880 } else {
2881 k = UI_TeamIndexFromName(UI_Cvar_VariableString("ui_opponentName"));
2882 for (i = 0; i < PLAYERS_PER_TEAM; i++) {
2883 Com_sprintf( buff, sizeof(buff), "wait ; addbot %s %i %s 250 %s\n", UI_AIFromName(teamList[k].teamMembers[i]), skill, "Blue", teamList[k].teamMembers[i]);
2884 trap_Cmd_ExecuteText( EXEC_APPEND, buff );
2885 }
2886
2887 k = UI_TeamIndexFromName(UI_Cvar_VariableString("ui_teamName"));
2888 for (i = 1; i < PLAYERS_PER_TEAM; i++) {
2889 Com_sprintf( buff, sizeof(buff), "wait ; addbot %s %i %s 250 %s\n", UI_AIFromName(teamList[k].teamMembers[i]), skill, "Red", teamList[k].teamMembers[i]);
2890 trap_Cmd_ExecuteText( EXEC_APPEND, buff );
2891 }
2892 trap_Cmd_ExecuteText( EXEC_APPEND, "wait 5; team Red\n" );
2893 }
2894
2895
2896 }
2897 */
2898
2899 /*
2900 ===============
2901 UI_LoadMods
2902 ===============
2903 */
2904 static void UI_LoadMods( void ) {
2905 int numdirs;
2906 char dirlist[2048];
2907 char *dirptr;
2908 char *descptr;
2909 int i;
2910 int dirlen;
2911
2912 uiInfo.modCount = 0;
2913 numdirs = trap_FS_GetFileList( "$modlist", "", dirlist, sizeof(dirlist) );
2914 dirptr = dirlist;
2915 for( i = 0; i < numdirs; i++ ) {
2916 dirlen = strlen( dirptr ) + 1;
2917 descptr = dirptr + dirlen;
2918 uiInfo.modList[uiInfo.modCount].modName = String_Alloc(dirptr);
2919 uiInfo.modList[uiInfo.modCount].modDescr = String_Alloc(descptr);
2920 dirptr += dirlen + strlen(descptr) + 1;
2921 uiInfo.modCount++;
2922 if (uiInfo.modCount >= MAX_MODS) {
2923 break;
2924 }
2925 }
2926
2927 }
2928
2929
2930 /*
2931 ===============
2932 UI_LoadTeams
2933 ===============
2934 */
2935 static void UI_LoadTeams( void ) {
2936 char teamList[4096];
2937 char *teamName;
2938 int i, len, count;
2939
2940 count = trap_FS_GetFileList( "", "team", teamList, 4096 );
2941
2942 if (count) {
2943 teamName = teamList;
2944 for ( i = 0; i < count; i++ ) {
2945 len = strlen( teamName );
2946 UI_ParseTeamInfo(teamName);
2947 teamName += len + 1;
2948 }
2949 }
2950
2951 }
2952
2953
2954 /*
2955 ===============
2956 UI_LoadMovies
2957 ===============
2958 */
2959 static void UI_LoadMovies( void ) {
2960 char movielist[4096];
2961 char *moviename;
2962 int i, len;
2963
2964 uiInfo.movieCount = trap_FS_GetFileList( "video", "roq", movielist, 4096 );
2965
2966 if (uiInfo.movieCount) {
2967 if (uiInfo.movieCount > MAX_MOVIES) {
2968 uiInfo.movieCount = MAX_MOVIES;
2969 }
2970 moviename = movielist;
2971 for ( i = 0; i < uiInfo.movieCount; i++ ) {
2972 len = strlen( moviename );
2973 if (!Q_stricmp(moviename + len - 4,".roq")) {
2974 moviename[len-4] = '\0';
2975 }
2976 Q_strupr(moviename);
2977 uiInfo.movieList[i] = String_Alloc(moviename);
2978 moviename += len + 1;
2979 }
2980 }
2981
2982 }
2983
2984
2985
2986 /*
2987 ===============
2988 UI_LoadDemos
2989 ===============
2990 */
2991 static void UI_LoadDemos( void ) {
2992 char demolist[4096];
2993 char demoExt[32];
2994 char *demoname;
2995 int i, len;
2996
2997 Com_sprintf(demoExt, sizeof(demoExt), "dm_%d", (int)trap_Cvar_VariableValue("protocol"));
2998
2999 uiInfo.demoCount = trap_FS_GetFileList( "demos", demoExt, demolist, 4096 );
3000
3001 Com_sprintf(demoExt, sizeof(demoExt), ".dm_%d", (int)trap_Cvar_VariableValue("protocol"));
3002
3003 if (uiInfo.demoCount) {
3004 if (uiInfo.demoCount > MAX_DEMOS) {
3005 uiInfo.demoCount = MAX_DEMOS;
3006 }
3007 demoname = demolist;
3008 for ( i = 0; i < uiInfo.demoCount; i++ ) {
3009 len = strlen( demoname );
3010 if (!Q_stricmp(demoname + len - strlen(demoExt), demoExt)) {
3011 demoname[len-strlen(demoExt)] = '\0';
3012 }
3013 Q_strupr(demoname);
3014 uiInfo.demoList[i] = String_Alloc(demoname);
3015 demoname += len + 1;
3016 }
3017 }
3018
3019 }
3020
3021
3022 static qboolean UI_SetNextMap(int actual, int index) {
3023 int i;
3024 for (i = actual + 1; i < uiInfo.mapCount; i++) {
3025 if (uiInfo.mapList[i].active) {
3026 Menu_SetFeederSelection(NULL, FEEDER_MAPS, index + 1, "skirmish");
3027 return qtrue;
3028 }
3029 }
3030 return qfalse;
3031 }
3032
3033
3034 static void UI_StartSkirmish(qboolean next) {
3035 int i, k, g, delay, temp;
3036 float skill;
3037 char buff[MAX_STRING_CHARS];
3038
3039 if (next) {
3040 int actual;
3041 int index = trap_Cvar_VariableValue("ui_mapIndex");
3042 UI_MapCountByGameType(qtrue);
3043 UI_SelectedMap(index, &actual);
3044 if (UI_SetNextMap(actual, index)) {
3045 } else {
3046 UI_GameType_HandleKey(0, NULL, K_MOUSE1, qfalse);
3047 UI_MapCountByGameType(qtrue);
3048 Menu_SetFeederSelection(NULL, FEEDER_MAPS, 0, "skirmish");
3049 }
3050 }
3051
3052 g = uiInfo.gameTypes[ui_gameType.integer].gtEnum;
3053 trap_Cvar_SetValue( "g_gametype", g );
3054 trap_Cmd_ExecuteText( EXEC_APPEND, va( "wait ; wait ; map %s\n", uiInfo.mapList[ui_currentMap.integer].mapLoadName) );
3055 skill = trap_Cvar_VariableValue( "g_spSkill" );
3056 trap_Cvar_Set("ui_scoreMap", uiInfo.mapList[ui_currentMap.integer].mapName);
3057
3058 k = UI_TeamIndexFromName(UI_Cvar_VariableString("ui_opponentName"));
3059
3060 trap_Cvar_Set("ui_singlePlayerActive", "1");
3061
3062 // set up sp overrides, will be replaced on postgame
3063 temp = trap_Cvar_VariableValue( "capturelimit" );
3064 trap_Cvar_Set("ui_saveCaptureLimit", va("%i", temp));
3065 temp = trap_Cvar_VariableValue( "fraglimit" );
3066 trap_Cvar_Set("ui_saveFragLimit", va("%i", temp));
3067
3068 UI_SetCapFragLimits(qfalse);
3069
3070 temp = trap_Cvar_VariableValue( "cg_drawTimer" );
3071 trap_Cvar_Set("ui_drawTimer", va("%i", temp));
3072 temp = trap_Cvar_VariableValue( "g_doWarmup" );
3073 trap_Cvar_Set("ui_doWarmup", va("%i", temp));
3074 temp = trap_Cvar_VariableValue( "g_friendlyFire" );
3075 trap_Cvar_Set("ui_friendlyFire", va("%i", temp));
3076 temp = trap_Cvar_VariableValue( "sv_maxClients" );
3077 trap_Cvar_Set("ui_maxClients", va("%i", temp));
3078 temp = trap_Cvar_VariableValue( "g_warmup" );
3079 trap_Cvar_Set("ui_Warmup", va("%i", temp));
3080 temp = trap_Cvar_VariableValue( "sv_pure" );
3081 trap_Cvar_Set("ui_pure", va("%i", temp));
3082
3083 trap_Cvar_Set("cg_cameraOrbit", "0");
3084 trap_Cvar_Set("cg_thirdPerson", "0");
3085 trap_Cvar_Set("cg_drawTimer", "1");
3086 trap_Cvar_Set("g_doWarmup", "1");
3087 trap_Cvar_Set("g_warmup", "15");
3088 trap_Cvar_Set("sv_pure", "0");
3089 trap_Cvar_Set("g_friendlyFire", "0");
3090 trap_Cvar_Set("g_redTeam", UI_Cvar_VariableString("ui_teamName"));
3091 trap_Cvar_Set("g_blueTeam", UI_Cvar_VariableString("ui_opponentName"));
3092
3093 if (trap_Cvar_VariableValue("ui_recordSPDemo")) {
3094 Com_sprintf(buff, MAX_STRING_CHARS, "%s_%i", uiInfo.mapList[ui_currentMap.integer].mapLoadName, g);
3095 trap_Cvar_Set("ui_recordSPDemoName", buff);
3096 }
3097
3098 delay = 500;
3099
3100 if (g == GT_TOURNAMENT) {
3101 trap_Cvar_Set("sv_maxClients", "2");
3102 Com_sprintf( buff, sizeof(buff), "wait ; addbot %s %f "", %i \n", uiInfo.mapList[ui_currentMap.integer].opponentName, skill, delay);
3103 trap_Cmd_ExecuteText( EXEC_APPEND, buff );
3104 } else {
3105 temp = uiInfo.mapList[ui_currentMap.integer].teamMembers * 2;
3106 trap_Cvar_Set("sv_maxClients", va("%d", temp));
3107 for (i =0; i < uiInfo.mapList[ui_currentMap.integer].teamMembers; i++) {
3108 Com_sprintf( buff, sizeof(buff), "addbot %s %f %s %i %s\n", UI_AIFromName(uiInfo.teamList[k].teamMembers[i]), skill, (g == GT_FFA) ? "" : "Blue", delay, uiInfo.teamList[k].teamMembers[i]);
3109 trap_Cmd_ExecuteText( EXEC_APPEND, buff );
3110 delay += 500;
3111 }
3112 k = UI_TeamIndexFromName(UI_Cvar_VariableString("ui_teamName"));
3113 for (i =0; i < uiInfo.mapList[ui_currentMap.integer].teamMembers-1; i++) {
3114 Com_sprintf( buff, sizeof(buff), "addbot %s %f %s %i %s\n", UI_AIFromName(uiInfo.teamList[k].teamMembers[i]), skill, (g == GT_FFA) ? "" : "Red", delay, uiInfo.teamList[k].teamMembers[i]);
3115 trap_Cmd_ExecuteText( EXEC_APPEND, buff );
3116 delay += 500;
3117 }
3118 }
3119 if (g >= GT_TEAM ) {
3120 trap_Cmd_ExecuteText( EXEC_APPEND, "wait 5; team Red\n" );
3121 }
3122 }
3123
3124 static void UI_Update(const char *name) {
3125 int val = trap_Cvar_VariableValue(name);
3126
3127 if (Q_stricmp(name, "ui_SetName") == 0) {
3128 trap_Cvar_Set( "name", UI_Cvar_VariableString("ui_Name"));
3129 } else if (Q_stricmp(name, "ui_setRate") == 0) {
3130 float rate = trap_Cvar_VariableValue("rate");
3131 if (rate >= 5000) {
3132 trap_Cvar_Set("cl_maxpackets", "30");
3133 trap_Cvar_Set("cl_packetdup", "1");
3134 } else if (rate >= 4000) {
3135 trap_Cvar_Set("cl_maxpackets", "15");
3136 trap_Cvar_Set("cl_packetdup", "2"); // favor less prediction errors when there's packet loss
3137 } else {
3138 trap_Cvar_Set("cl_maxpackets", "15");
3139 trap_Cvar_Set("cl_packetdup", "1"); // favor lower bandwidth
3140 }
3141 } else if (Q_stricmp(name, "ui_GetName") == 0) {
3142 trap_Cvar_Set( "ui_Name", UI_Cvar_VariableString("name"));
3143 } else if (Q_stricmp(name, "r_colorbits") == 0) {
3144 switch (val) {
3145 case 0:
3146 trap_Cvar_SetValue( "r_depthbits", 0 );
3147 trap_Cvar_SetValue( "r_stencilbits", 0 );
3148 break;
3149 case 16:
3150 trap_Cvar_SetValue( "r_depthbits", 16 );
3151 trap_Cvar_SetValue( "r_stencilbits", 0 );
3152 break;
3153 case 32:
3154 trap_Cvar_SetValue( "r_depthbits", 24 );
3155 break;
3156 }
3157 } else if (Q_stricmp(name, "r_lodbias") == 0) {
3158 switch (val) {
3159 case 0:
3160 trap_Cvar_SetValue( "r_subdivisions", 4 );
3161 break;
3162 case 1:
3163 trap_Cvar_SetValue( "r_subdivisions", 12 );
3164 break;
3165 case 2:
3166 trap_Cvar_SetValue( "r_subdivisions", 20 );
3167 break;
3168 }
3169 } else if (Q_stricmp(name, "ui_glCustom") == 0) {
3170 switch (val) {
3171 case 0: // high quality
3172 trap_Cvar_SetValue( "r_fullScreen", 1 );
3173 trap_Cvar_SetValue( "r_subdivisions", 4 );
3174 trap_Cvar_SetValue( "r_vertexlight", 0 );
3175 trap_Cvar_SetValue( "r_lodbias", 0 );
3176 trap_Cvar_SetValue( "r_colorbits", 32 );
3177 trap_Cvar_SetValue( "r_depthbits", 24 );
3178 trap_Cvar_SetValue( "r_picmip", 0 );
3179 trap_Cvar_SetValue( "r_mode", 4 );
3180 trap_Cvar_SetValue( "r_texturebits", 32 );
3181 trap_Cvar_SetValue( "r_fastSky", 0 );
3182 trap_Cvar_SetValue( "r_inGameVideo", 1 );
3183 trap_Cvar_SetValue( "cg_shadows", 1 );
3184 trap_Cvar_SetValue( "cg_brassTime", 2500 );
3185 trap_Cvar_Set( "r_texturemode", "GL_LINEAR_MIPMAP_LINEAR" );
3186 break;
3187 case 1: // normal
3188 trap_Cvar_SetValue( "r_fullScreen", 1 );
3189 trap_Cvar_SetValue( "r_subdivisions", 12 );
3190 trap_Cvar_SetValue( "r_vertexlight", 0 );
3191 trap_Cvar_SetValue( "r_lodbias", 0 );
3192 trap_Cvar_SetValue( "r_colorbits", 0 );
3193 trap_Cvar_SetValue( "r_depthbits", 24 );
3194 trap_Cvar_SetValue( "r_picmip", 1 );
3195 trap_Cvar_SetValue( "r_mode", 3 );
3196 trap_Cvar_SetValue( "r_texturebits", 0 );
3197 trap_Cvar_SetValue( "r_fastSky", 0 );
3198 trap_Cvar_SetValue( "r_inGameVideo", 1 );
3199 trap_Cvar_SetValue( "cg_brassTime", 2500 );
3200 trap_Cvar_Set( "r_texturemode", "GL_LINEAR_MIPMAP_LINEAR" );
3201 trap_Cvar_SetValue( "cg_shadows", 0 );
3202 break;
3203 case 2: // fast
3204 trap_Cvar_SetValue( "r_fullScreen", 1 );
3205 trap_Cvar_SetValue( "r_subdivisions", 8 );
3206 trap_Cvar_SetValue( "r_vertexlight", 0 );
3207 trap_Cvar_SetValue( "r_lodbias", 1 );
3208 trap_Cvar_SetValue( "r_colorbits", 0 );
3209 trap_Cvar_SetValue( "r_depthbits", 0 );
3210 trap_Cvar_SetValue( "r_picmip", 1 );
3211 trap_Cvar_SetValue( "r_mode", 3 );
3212 trap_Cvar_SetValue( "r_texturebits", 0 );
3213 trap_Cvar_SetValue( "cg_shadows", 0 );
3214 trap_Cvar_SetValue( "r_fastSky", 1 );
3215 trap_Cvar_SetValue( "r_inGameVideo", 0 );
3216 trap_Cvar_SetValue( "cg_brassTime", 0 );
3217 trap_Cvar_Set( "r_texturemode", "GL_LINEAR_MIPMAP_NEAREST" );
3218 break;
3219 case 3: // fastest
3220 trap_Cvar_SetValue( "r_fullScreen", 1 );
3221 trap_Cvar_SetValue( "r_subdivisions", 20 );
3222 trap_Cvar_SetValue( "r_vertexlight", 1 );
3223 trap_Cvar_SetValue( "r_lodbias", 2 );
3224 trap_Cvar_SetValue( "r_colorbits", 16 );
3225 trap_Cvar_SetValue( "r_depthbits", 16 );
3226 trap_Cvar_SetValue( "r_mode", 3 );
3227 trap_Cvar_SetValue( "r_picmip", 2 );
3228 trap_Cvar_SetValue( "r_texturebits", 16 );
3229 trap_Cvar_SetValue( "cg_shadows", 0 );
3230 trap_Cvar_SetValue( "cg_brassTime", 0 );
3231 trap_Cvar_SetValue( "r_fastSky", 1 );
3232 trap_Cvar_SetValue( "r_inGameVideo", 0 );
3233 trap_Cvar_Set( "r_texturemode", "GL_LINEAR_MIPMAP_NEAREST" );
3234 break;
3235 }
3236 } else if (Q_stricmp(name, "ui_mousePitch") == 0) {
3237 if (val == 0) {
3238 trap_Cvar_SetValue( "m_pitch", 0.022f );
3239 } else {
3240 trap_Cvar_SetValue( "m_pitch", -0.022f );
3241 }
3242 }
3243 }
3244
3245 static void UI_RunMenuScript(char **args) {
3246 const char *name, *name2;
3247 char buff[1024];
3248
3249 if (String_Parse(args, &name)) {
3250 if (Q_stricmp(name, "StartServer") == 0) {
3251 int i, clients, oldclients;
3252 float skill;
3253 trap_Cvar_Set("cg_thirdPerson", "0");
3254 trap_Cvar_Set("cg_cameraOrbit", "0");
3255 trap_Cvar_Set("ui_singlePlayerActive", "0");
3256 trap_Cvar_SetValue( "dedicated", Com_Clamp( 0, 2, ui_dedicated.integer ) );
3257 trap_Cvar_SetValue( "g_gametype", Com_Clamp( 0, 13, uiInfo.gameTypes[ui_netGameType.integer].gtEnum ) );
3258 trap_Cvar_Set("g_redTeam", UI_Cvar_VariableString("ui_teamName"));
3259 trap_Cvar_Set("g_blueTeam", UI_Cvar_VariableString("ui_opponentName"));
3260 trap_Cmd_ExecuteText( EXEC_APPEND, va( "wait ; wait ; map %s\n", uiInfo.mapList[ui_currentNetMap.integer].mapLoadName ) );
3261 skill = trap_Cvar_VariableValue( "g_spSkill" );
3262 // set max clients based on spots
3263 oldclients = trap_Cvar_VariableValue( "sv_maxClients" );
3264 clients = 0;
3265 for (i = 0; i < PLAYERS_PER_TEAM; i++) {
3266 int bot = trap_Cvar_VariableValue( va("ui_blueteam%i", i+1));
3267 if (bot >= 0) {
3268 clients++;
3269 }
3270 bot = trap_Cvar_VariableValue( va("ui_redteam%i", i+1));
3271 if (bot >= 0) {
3272 clients++;
3273 }
3274 }
3275 if (clients == 0) {
3276 clients = 8;
3277 }
3278
3279 if (oldclients > clients) {
3280 clients = oldclients;
3281 }
3282
3283 trap_Cvar_Set("sv_maxClients", va("%d",clients));
3284
3285 for (i = 0; i < PLAYERS_PER_TEAM; i++) {
3286 int bot = trap_Cvar_VariableValue( va("ui_blueteam%i", i+1));
3287 if (bot > 1) {
3288 if (ui_actualNetGameType.integer >= GT_TEAM) {
3289 Com_sprintf( buff, sizeof(buff), "addbot %s %f %s\n", uiInfo.characterList[bot-2].name, skill, "Blue");
3290 } else {
3291 Com_sprintf( buff, sizeof(buff), "addbot %s %f \n", UI_GetBotNameByNumber(bot-2), skill);
3292 }
3293 trap_Cmd_ExecuteText( EXEC_APPEND, buff );
3294 }
3295 bot = trap_Cvar_VariableValue( va("ui_redteam%i", i+1));
3296 if (bot > 1) {
3297 if (ui_actualNetGameType.integer >= GT_TEAM) {
3298 Com_sprintf( buff, sizeof(buff), "addbot %s %f %s\n", uiInfo.characterList[bot-2].name, skill, "Red");
3299 } else {
3300 Com_sprintf( buff, sizeof(buff), "addbot %s %f \n", UI_GetBotNameByNumber(bot-2), skill);
3301 }
3302 trap_Cmd_ExecuteText( EXEC_APPEND, buff );
3303 }
3304 }
3305 } else if (Q_stricmp(name, "updateSPMenu") == 0) {
3306 UI_SetCapFragLimits(qtrue);
3307 UI_MapCountByGameType(qtrue);
3308 ui_mapIndex.integer = UI_GetIndexFromSelection(ui_currentMap.integer);
3309 trap_Cvar_Set("ui_mapIndex", va("%d", ui_mapIndex.integer));
3310 Menu_SetFeederSelection(NULL, FEEDER_MAPS, ui_mapIndex.integer, "skirmish");
3311 UI_GameType_HandleKey(0, NULL, K_MOUSE1, qfalse);
3312 UI_GameType_HandleKey(0, NULL, K_MOUSE2, qfalse);
3313 } else if (Q_stricmp(name, "resetDefaults") == 0) {
3314 trap_Cmd_ExecuteText( EXEC_APPEND, "exec default.cfg\n");
3315 trap_Cmd_ExecuteText( EXEC_APPEND, "cvar_restart\n");
3316 Controls_SetDefaults();
3317 trap_Cvar_Set("com_introPlayed", "1" );
3318 trap_Cmd_ExecuteText( EXEC_APPEND, "vid_restart\n" );
3319 } else if (Q_stricmp(name, "getCDKey") == 0) {
3320 char out[17];
3321 trap_GetCDKey(buff, 17);
3322 trap_Cvar_Set("cdkey1", "");
3323 trap_Cvar_Set("cdkey2", "");
3324 trap_Cvar_Set("cdkey3", "");
3325 trap_Cvar_Set("cdkey4", "");
3326 if (strlen(buff) == CDKEY_LEN) {
3327 Q_strncpyz(out, buff, 5);
3328 trap_Cvar_Set("cdkey1", out);
3329 Q_strncpyz(out, buff + 4, 5);
3330 trap_Cvar_Set("cdkey2", out);
3331 Q_strncpyz(out, buff + 8, 5);
3332 trap_Cvar_Set("cdkey3", out);
3333 Q_strncpyz(out, buff + 12, 5);
3334 trap_Cvar_Set("cdkey4", out);
3335 }
3336
3337 } else if (Q_stricmp(name, "verifyCDKey") == 0) {
3338 buff[0] = '\0';
3339 Q_strcat(buff, 1024, UI_Cvar_VariableString("cdkey1"));
3340 Q_strcat(buff, 1024, UI_Cvar_VariableString("cdkey2"));
3341 Q_strcat(buff, 1024, UI_Cvar_VariableString("cdkey3"));
3342 Q_strcat(buff, 1024, UI_Cvar_VariableString("cdkey4"));
3343 trap_Cvar_Set("cdkey", buff);
3344 if (trap_VerifyCDKey(buff, UI_Cvar_VariableString("cdkeychecksum"))) {
3345 trap_Cvar_Set("ui_cdkeyvalid", "CD Key Appears to be valid.");
3346 trap_SetCDKey(buff);
3347 } else {
3348 trap_Cvar_Set("ui_cdkeyvalid", "CD Key does not appear to be valid.");
3349 }
3350 } else if (Q_stricmp(name, "loadArenas") == 0) {
3351 UI_LoadArenas();
3352 UI_MapCountByGameType(qfalse);
3353 Menu_SetFeederSelection(NULL, FEEDER_ALLMAPS, 0, "createserver");
3354 } else if (Q_stricmp(name, "saveControls") == 0) {
3355 Controls_SetConfig(qtrue);
3356 } else if (Q_stricmp(name, "loadControls") == 0) {
3357 Controls_GetConfig();
3358 } else if (Q_stricmp(name, "clearError") == 0) {
3359 trap_Cvar_Set("com_errorMessage", "");
3360 } else if (Q_stricmp(name, "loadGameInfo") == 0) {
3361 #ifdef PRE_RELEASE_TADEMO
3362 UI_ParseGameInfo("demogameinfo.txt");
3363 #else
3364 UI_ParseGameInfo("gameinfo.txt");
3365 #endif
3366 UI_LoadBestScores(uiInfo.mapList[ui_currentMap.integer].mapLoadName, uiInfo.gameTypes[ui_gameType.integer].gtEnum);
3367 } else if (Q_stricmp(name, "resetScores") == 0) {
3368 UI_ClearScores();
3369 } else if (Q_stricmp(name, "RefreshServers") == 0) {
3370 UI_StartServerRefresh(qtrue);
3371 UI_BuildServerDisplayList(qtrue);
3372 } else if (Q_stricmp(name, "RefreshFilter") == 0) {
3373 UI_StartServerRefresh(qfalse);
3374 UI_BuildServerDisplayList(qtrue);
3375 } else if (Q_stricmp(name, "RunSPDemo") == 0) {
3376 if (uiInfo.demoAvailable) {
3377 trap_Cmd_ExecuteText( EXEC_APPEND, va("demo %s_%i\n", uiInfo.mapList[ui_currentMap.integer].mapLoadName, uiInfo.gameTypes[ui_gameType.integer].gtEnum));
3378 }
3379 } else if (Q_stricmp(name, "LoadDemos") == 0) {
3380 UI_LoadDemos();
3381 } else if (Q_stricmp(name, "LoadMovies") == 0) {
3382 UI_LoadMovies();
3383 } else if (Q_stricmp(name, "LoadMods") == 0) {
3384 UI_LoadMods();
3385 } else if (Q_stricmp(name, "playMovie") == 0) {
3386 if (uiInfo.previewMovie >= 0) {
3387 trap_CIN_StopCinematic(uiInfo.previewMovie);
3388 }
3389 trap_Cmd_ExecuteText( EXEC_APPEND, va("cinematic %s.roq 2\n", uiInfo.movieList[uiInfo.movieIndex]));
3390 } else if (Q_stricmp(name, "RunMod") == 0) {
3391 trap_Cvar_Set( "fs_game", uiInfo.modList[uiInfo.modIndex].modName);
3392 trap_Cmd_ExecuteText( EXEC_APPEND, "vid_restart;" );
3393 } else if (Q_stricmp(name, "RunDemo") == 0) {
3394 trap_Cmd_ExecuteText( EXEC_APPEND, va("demo %s\n", uiInfo.demoList[uiInfo.demoIndex]));
3395 } else if (Q_stricmp(name, "Quake3") == 0) {
3396 trap_Cvar_Set( "fs_game", "");
3397 trap_Cmd_ExecuteText( EXEC_APPEND, "vid_restart;" );
3398 } else if (Q_stricmp(name, "closeJoin") == 0) {
3399 if (uiInfo.serverStatus.refreshActive) {
3400 UI_StopServerRefresh();
3401 uiInfo.serverStatus.nextDisplayRefresh = 0;
3402 uiInfo.nextServerStatusRefresh = 0;
3403 uiInfo.nextFindPlayerRefresh = 0;
3404 UI_BuildServerDisplayList(qtrue);
3405 } else {
3406 Menus_CloseByName("joinserver");
3407 Menus_OpenByName("main");
3408 }
3409 } else if (Q_stricmp(name, "StopRefresh") == 0) {
3410 UI_StopServerRefresh();
3411 uiInfo.serverStatus.nextDisplayRefresh = 0;
3412 uiInfo.nextServerStatusRefresh = 0;
3413 uiInfo.nextFindPlayerRefresh = 0;
3414 } else if (Q_stricmp(name, "UpdateFilter") == 0) {
3415 if (ui_netSource.integer == AS_LOCAL) {
3416 UI_StartServerRefresh(qtrue);
3417 }
3418 UI_BuildServerDisplayList(qtrue);
3419 UI_FeederSelection(FEEDER_SERVERS, 0);
3420 } else if (Q_stricmp(name, "ServerStatus") == 0) {
3421 trap_LAN_GetServerAddressString(ui_netSource.integer, uiInfo.serverStatus.displayServers[uiInfo.serverStatus.currentServer], uiInfo.serverStatusAddress, sizeof(uiInfo.serverStatusAddress));
3422 UI_BuildServerStatus(qtrue);
3423 } else if (Q_stricmp(name, "FoundPlayerServerStatus") == 0) {
3424 Q_strncpyz(uiInfo.serverStatusAddress, uiInfo.foundPlayerServerAddresses[uiInfo.currentFoundPlayerServer], sizeof(uiInfo.serverStatusAddress));
3425 UI_BuildServerStatus(qtrue);
3426 Menu_SetFeederSelection(NULL, FEEDER_FINDPLAYER, 0, NULL);
3427 } else if (Q_stricmp(name, "FindPlayer") == 0) {
3428 UI_BuildFindPlayerList(qtrue);
3429 // clear the displayed server status info
3430 uiInfo.serverStatusInfo.numLines = 0;
3431 Menu_SetFeederSelection(NULL, FEEDER_FINDPLAYER, 0, NULL);
3432 } else if (Q_stricmp(name, "JoinServer") == 0) {
3433 trap_Cvar_Set("cg_thirdPerson", "0");
3434 trap_Cvar_Set("cg_cameraOrbit", "0");
3435 trap_Cvar_Set("ui_singlePlayerActive", "0");
3436 if (uiInfo.serverStatus.currentServer >= 0 && uiInfo.serverStatus.currentServer < uiInfo.serverStatus.numDisplayServers) {
3437 trap_LAN_GetServerAddressString(ui_netSource.integer, uiInfo.serverStatus.displayServers[uiInfo.serverStatus.currentServer], buff, 1024);
3438 trap_Cmd_ExecuteText( EXEC_APPEND, va( "connect %s\n", buff ) );
3439 }
3440 } else if (Q_stricmp(name, "FoundPlayerJoinServer") == 0) {
3441 trap_Cvar_Set("ui_singlePlayerActive", "0");
3442 if (uiInfo.currentFoundPlayerServer >= 0 && uiInfo.currentFoundPlayerServer < uiInfo.numFoundPlayerServers) {
3443 trap_Cmd_ExecuteText( EXEC_APPEND, va( "connect %s\n", uiInfo.foundPlayerServerAddresses[uiInfo.currentFoundPlayerServer] ) );
3444 }
3445 } else if (Q_stricmp(name, "Quit") == 0) {
3446 trap_Cvar_Set("ui_singlePlayerActive", "0");
3447 trap_Cmd_ExecuteText( EXEC_NOW, "quit");
3448 } else if (Q_stricmp(name, "Controls") == 0) {
3449 trap_Cvar_Set( "cl_paused", "1" );
3450 trap_Key_SetCatcher( KEYCATCH_UI );
3451 Menus_CloseAll();
3452 Menus_ActivateByName("setup_menu2");
3453 } else if (Q_stricmp(name, "Leave") == 0) {
3454 trap_Cmd_ExecuteText( EXEC_APPEND, "disconnect\n" );
3455 trap_Key_SetCatcher( KEYCATCH_UI );
3456 Menus_CloseAll();
3457 Menus_ActivateByName("main");
3458 } else if (Q_stricmp(name, "ServerSort") == 0) {
3459 int sortColumn;
3460 if (Int_Parse(args, &sortColumn)) {
3461 // if same column we're already sorting on then flip the direction
3462 if (sortColumn == uiInfo.serverStatus.sortKey) {
3463 uiInfo.serverStatus.sortDir = !uiInfo.serverStatus.sortDir;
3464 }
3465 // make sure we sort again
3466 UI_ServersSort(sortColumn, qtrue);
3467 }
3468 } else if (Q_stricmp(name, "nextSkirmish") == 0) {
3469 UI_StartSkirmish(qtrue);
3470 } else if (Q_stricmp(name, "SkirmishStart") == 0) {
3471 UI_StartSkirmish(qfalse);
3472 } else if (Q_stricmp(name, "closeingame") == 0) {
3473 trap_Key_SetCatcher( trap_Key_GetCatcher() & ~KEYCATCH_UI );
3474 trap_Key_ClearStates();
3475 trap_Cvar_Set( "cl_paused", "0" );
3476 Menus_CloseAll();
3477 } else if (Q_stricmp(name, "voteMap") == 0) {
3478 if (ui_currentNetMap.integer >=0 && ui_currentNetMap.integer < uiInfo.mapCount) {
3479 trap_Cmd_ExecuteText( EXEC_APPEND, va("callvote map %s\n",uiInfo.mapList[ui_currentNetMap.integer].mapLoadName) );
3480 }
3481 } else if (Q_stricmp(name, "voteKick") == 0) {
3482 if (uiInfo.playerIndex >= 0 && uiInfo.playerIndex < uiInfo.playerCount) {
3483 trap_Cmd_ExecuteText( EXEC_APPEND, va("callvote kick %s\n",uiInfo.playerNames[uiInfo.playerIndex]) );
3484 }
3485 } else if (Q_stricmp(name, "voteGame") == 0) {
3486 if (ui_netGameType.integer >= 0 && ui_netGameType.integer < uiInfo.numGameTypes) {
3487 trap_Cmd_ExecuteText( EXEC_APPEND, va("callvote g_gametype %i\n",uiInfo.gameTypes[ui_netGameType.integer].gtEnum) );
3488 }
3489 } else if (Q_stricmp(name, "voteLeader") == 0) {
3490 if (uiInfo.teamIndex >= 0 && uiInfo.teamIndex < uiInfo.myTeamCount) {
3491 trap_Cmd_ExecuteText( EXEC_APPEND, va("callteamvote leader %s\n",uiInfo.teamNames[uiInfo.teamIndex]) );
3492 }
3493 } else if (Q_stricmp(name, "addBot") == 0) {
3494 if (trap_Cvar_VariableValue("g_gametype") >= GT_TEAM && !GT_LMS ) {
3495 trap_Cmd_ExecuteText( EXEC_APPEND, va("addbot %s %i %s\n", uiInfo.characterList[uiInfo.botIndex].name, uiInfo.skillIndex+1, (uiInfo.redBlue == 0) ? "Red" : "Blue") );
3496 } else {
3497 trap_Cmd_ExecuteText( EXEC_APPEND, va("addbot %s %i %s\n", UI_GetBotNameByNumber(uiInfo.botIndex), uiInfo.skillIndex+1, (uiInfo.redBlue == 0) ? "Red" : "Blue") );
3498 }
3499 } else if (Q_stricmp(name, "addFavorite") == 0) {
3500 if (ui_netSource.integer != AS_FAVORITES) {
3501 char name[MAX_NAME_LENGTH];
3502 char addr[MAX_NAME_LENGTH];
3503 int res;
3504
3505 trap_LAN_GetServerInfo(ui_netSource.integer, uiInfo.serverStatus.displayServers[uiInfo.serverStatus.currentServer], buff, MAX_STRING_CHARS);
3506 name[0] = addr[0] = '\0';
3507 Q_strncpyz(name, Info_ValueForKey(buff, "hostname"), MAX_NAME_LENGTH);
3508 Q_strncpyz(addr, Info_ValueForKey(buff, "addr"), MAX_NAME_LENGTH);
3509 if (strlen(name) > 0 && strlen(addr) > 0) {
3510 res = trap_LAN_AddServer(AS_FAVORITES, name, addr);
3511 if (res == 0) {
3512 // server already in the list
3513 Com_Printf("Favorite already in list\n");
3514 }
3515 else if (res == -1) {
3516 // list full
3517 Com_Printf("Favorite list full\n");
3518 }
3519 else {
3520 // successfully added
3521 Com_Printf("Added favorite server %s\n", addr);
3522 }
3523 }
3524 }
3525 } else if (Q_stricmp(name, "deleteFavorite") == 0) {
3526 if (ui_netSource.integer == AS_FAVORITES) {
3527 char addr[MAX_NAME_LENGTH];
3528 trap_LAN_GetServerInfo(ui_netSource.integer, uiInfo.serverStatus.displayServers[uiInfo.serverStatus.currentServer], buff, MAX_STRING_CHARS);
3529 addr[0] = '\0';
3530 Q_strncpyz(addr, Info_ValueForKey(buff, "addr"), MAX_NAME_LENGTH);
3531 if (strlen(addr) > 0) {
3532 trap_LAN_RemoveServer(AS_FAVORITES, addr);
3533 }
3534 }
3535 } else if (Q_stricmp(name, "createFavorite") == 0) {
3536 if (ui_netSource.integer == AS_FAVORITES) {
3537 char name[MAX_NAME_LENGTH];
3538 char addr[MAX_NAME_LENGTH];
3539 int res;
3540
3541 name[0] = addr[0] = '\0';
3542 Q_strncpyz(name, UI_Cvar_VariableString("ui_favoriteName"), MAX_NAME_LENGTH);
3543 Q_strncpyz(addr, UI_Cvar_VariableString("ui_favoriteAddress"), MAX_NAME_LENGTH);
3544 if (strlen(name) > 0 && strlen(addr) > 0) {
3545 res = trap_LAN_AddServer(AS_FAVORITES, name, addr);
3546 if (res == 0) {
3547 // server already in the list
3548 Com_Printf("Favorite already in list\n");
3549 }
3550 else if (res == -1) {
3551 // list full
3552 Com_Printf("Favorite list full\n");
3553 }
3554 else {
3555 // successfully added
3556 Com_Printf("Added favorite server %s\n", addr);
3557 }
3558 }
3559 }
3560 } else if (Q_stricmp(name, "orders") == 0) {
3561 const char *orders;
3562 if (String_Parse(args, &orders)) {
3563 int selectedPlayer = trap_Cvar_VariableValue("cg_selectedPlayer");
3564 if (selectedPlayer < uiInfo.myTeamCount) {
3565 strcpy(buff, orders);
3566 trap_Cmd_ExecuteText( EXEC_APPEND, va(buff, uiInfo.teamClientNums[selectedPlayer]) );
3567 trap_Cmd_ExecuteText( EXEC_APPEND, "\n" );
3568 } else {
3569 int i;
3570 for (i = 0; i < uiInfo.myTeamCount; i++) {
3571 if (Q_stricmp(UI_Cvar_VariableString("name"), uiInfo.teamNames[i]) == 0) {
3572 continue;
3573 }
3574 strcpy(buff, orders);
3575 trap_Cmd_ExecuteText( EXEC_APPEND, va(buff, uiInfo.teamNames[i]) );
3576 trap_Cmd_ExecuteText( EXEC_APPEND, "\n" );
3577 }
3578 }
3579 trap_Key_SetCatcher( trap_Key_GetCatcher() & ~KEYCATCH_UI );
3580 trap_Key_ClearStates();
3581 trap_Cvar_Set( "cl_paused", "0" );
3582 Menus_CloseAll();
3583 }
3584 } else if (Q_stricmp(name, "voiceOrdersTeam") == 0) {
3585 const char *orders;
3586 if (String_Parse(args, &orders)) {
3587 int selectedPlayer = trap_Cvar_VariableValue("cg_selectedPlayer");
3588 if (selectedPlayer == uiInfo.myTeamCount) {
3589 trap_Cmd_ExecuteText( EXEC_APPEND, orders );
3590 trap_Cmd_ExecuteText( EXEC_APPEND, "\n" );
3591 }
3592 trap_Key_SetCatcher( trap_Key_GetCatcher() & ~KEYCATCH_UI );
3593 trap_Key_ClearStates();
3594 trap_Cvar_Set( "cl_paused", "0" );
3595 Menus_CloseAll();
3596 }
3597 } else if (Q_stricmp(name, "voiceOrders") == 0) {
3598 const char *orders;
3599 if (String_Parse(args, &orders)) {
3600 int selectedPlayer = trap_Cvar_VariableValue("cg_selectedPlayer");
3601 if (selectedPlayer < uiInfo.myTeamCount) {
3602 strcpy(buff, orders);
3603 trap_Cmd_ExecuteText( EXEC_APPEND, va(buff, uiInfo.teamClientNums[selectedPlayer]) );
3604 trap_Cmd_ExecuteText( EXEC_APPEND, "\n" );
3605 }
3606 trap_Key_SetCatcher( trap_Key_GetCatcher() & ~KEYCATCH_UI );
3607 trap_Key_ClearStates();
3608 trap_Cvar_Set( "cl_paused", "0" );
3609 Menus_CloseAll();
3610 }
3611 } else if (Q_stricmp(name, "glCustom") == 0) {
3612 trap_Cvar_Set("ui_glCustom", "4");
3613 } else if (Q_stricmp(name, "update") == 0) {
3614 if (String_Parse(args, &name2)) {
3615 UI_Update(name2);
3616 }
3617 } else if (Q_stricmp(name, "setPbClStatus") == 0) {
3618 int stat;
3619 if ( Int_Parse( args, &stat ) )
3620 trap_SetPbClStatus( stat );
3621 }
3622 else {
3623 Com_Printf("unknown UI script %s\n", name);
3624 }
3625 }
3626 }
3627
3628 static void UI_GetTeamColor(vec4_t *color) {
3629 }
3630
3631 /*
3632 ==================
3633 UI_MapCountByGameType
3634 ==================
3635 */
3636 static int UI_MapCountByGameType(qboolean singlePlayer) {
3637 int i, c, game;
3638 c = 0;
3639 game = singlePlayer ? uiInfo.gameTypes[ui_gameType.integer].gtEnum : uiInfo.gameTypes[ui_netGameType.integer].gtEnum;
3640 if (game == GT_SINGLE_PLAYER) {
3641 game++;
3642 }
3643 if (game == GT_TEAM) {
3644 game = GT_FFA;
3645 }
3646
3647 for (i = 0; i < uiInfo.mapCount; i++) {
3648 uiInfo.mapList[i].active = qfalse;
3649 if ( uiInfo.mapList[i].typeBits & (1 << game)) {
3650 if (singlePlayer) {
3651 if (!(uiInfo.mapList[i].typeBits & (1 << GT_SINGLE_PLAYER))) {
3652 continue;
3653 }
3654 }
3655 c++;
3656 uiInfo.mapList[i].active = qtrue;
3657 }
3658 }
3659 return c;
3660 }
3661
3662 qboolean UI_hasSkinForBase(const char *base, const char *team) {
3663 char test[1024];
3664
3665 Com_sprintf( test, sizeof( test ), "models/players/%s/%s/lower_default.skin", base, team );
3666
3667 if (trap_FS_FOpenFile(test, NULL, FS_READ)) {
3668 return qtrue;
3669 }
3670 Com_sprintf( test, sizeof( test ), "models/players/characters/%s/%s/lower_default.skin", base, team );
3671
3672 if (trap_FS_FOpenFile(test, NULL, FS_READ)) {
3673 return qtrue;
3674 }
3675 return qfalse;
3676 }
3677
3678 /*
3679 ==================
3680 UI_MapCountByTeam
3681 ==================
3682 */
3683 static int UI_HeadCountByTeam(void) {
3684 static int init = 0;
3685 int i, j, k, c, tIndex;
3686
3687 c = 0;
3688 if (!init) {
3689 for (i = 0; i < uiInfo.characterCount; i++) {
3690 uiInfo.characterList[i].reference = 0;
3691 for (j = 0; j < uiInfo.teamCount; j++) {
3692 if (UI_hasSkinForBase(uiInfo.characterList[i].base, uiInfo.teamList[j].teamName)) {
3693 uiInfo.characterList[i].reference |= (1<<j);
3694 }
3695 }
3696 }
3697 init = 1;
3698 }
3699
3700 tIndex = UI_TeamIndexFromName(UI_Cvar_VariableString("ui_teamName"));
3701
3702 // do names
3703 for (i = 0; i < uiInfo.characterCount; i++) {
3704 uiInfo.characterList[i].active = qfalse;
3705 for(j = 0; j < TEAM_MEMBERS; j++) {
3706 if (uiInfo.teamList[tIndex].teamMembers[j] != NULL) {
3707 if (uiInfo.characterList[i].reference&(1<<tIndex)) {// && Q_stricmp(uiInfo.teamList[tIndex].teamMembers[j], uiInfo.characterList[i].name)==0) {
3708 uiInfo.characterList[i].active = qtrue;
3709 c++;
3710 break;
3711 }
3712 }
3713 }
3714 }
3715
3716 // and then aliases
3717 for(j = 0; j < TEAM_MEMBERS; j++) {
3718 for(k = 0; k < uiInfo.aliasCount; k++) {
3719 if (uiInfo.aliasList[k].name != NULL) {
3720 if (Q_stricmp(uiInfo.teamList[tIndex].teamMembers[j], uiInfo.aliasList[k].name)==0) {
3721 for (i = 0; i < uiInfo.characterCount; i++) {
3722 if (uiInfo.characterList[i].headImage != -1 && uiInfo.characterList[i].reference&(1<<tIndex) && Q_stricmp(uiInfo.aliasList[k].ai, uiInfo.characterList[i].name)==0) {
3723 if (uiInfo.characterList[i].active == qfalse) {
3724 uiInfo.characterList[i].active = qtrue;
3725 c++;
3726 }
3727 break;
3728 }
3729 }
3730 }
3731 }
3732 }
3733 }
3734 return c;
3735 }
3736
3737 /*
3738 ==================
3739 UI_InsertServerIntoDisplayList
3740 ==================
3741 */
3742 static void UI_InsertServerIntoDisplayList(int num, int position) {
3743 int i;
3744
3745 if (position < 0 || position > uiInfo.serverStatus.numDisplayServers ) {
3746 return;
3747 }
3748 //
3749 uiInfo.serverStatus.numDisplayServers++;
3750 for (i = uiInfo.serverStatus.numDisplayServers; i > position; i--) {
3751 uiInfo.serverStatus.displayServers[i] = uiInfo.serverStatus.displayServers[i-1];
3752 }
3753 uiInfo.serverStatus.displayServers[position] = num;
3754 }
3755
3756 /*
3757 ==================
3758 UI_RemoveServerFromDisplayList
3759 ==================
3760 */
3761 static void UI_RemoveServerFromDisplayList(int num) {
3762 int i, j;
3763
3764 for (i = 0; i < uiInfo.serverStatus.numDisplayServers; i++) {
3765 if (uiInfo.serverStatus.displayServers[i] == num) {
3766 uiInfo.serverStatus.numDisplayServers--;
3767 for (j = i; j < uiInfo.serverStatus.numDisplayServers; j++) {
3768 uiInfo.serverStatus.displayServers[j] = uiInfo.serverStatus.displayServers[j+1];
3769 }
3770 return;
3771 }
3772 }
3773 }
3774
3775 /*
3776 ==================
3777 UI_BinaryServerInsertion
3778 ==================
3779 */
3780 static void UI_BinaryServerInsertion(int num) {
3781 int mid, offset, res, len;
3782
3783 // use binary search to insert server
3784 len = uiInfo.serverStatus.numDisplayServers;
3785 mid = len;
3786 offset = 0;
3787 res = 0;
3788 while(mid > 0) {
3789 mid = len >> 1;
3790 //
3791 res = trap_LAN_CompareServers( ui_netSource.integer, uiInfo.serverStatus.sortKey,
3792 uiInfo.serverStatus.sortDir, num, uiInfo.serverStatus.displayServers[offset+mid]);
3793 // if equal
3794 if (res == 0) {
3795 UI_InsertServerIntoDisplayList(num, offset+mid);
3796 return;
3797 }
3798 // if larger
3799 else if (res == 1) {
3800 offset += mid;
3801 len -= mid;
3802 }
3803 // if smaller
3804 else {
3805 len -= mid;
3806 }
3807 }
3808 if (res == 1) {
3809 offset++;
3810 }
3811 UI_InsertServerIntoDisplayList(num, offset);
3812 }
3813
3814 /*
3815 ==================
3816 UI_BuildServerDisplayList
3817 ==================
3818 */
3819 static void UI_BuildServerDisplayList(qboolean force) {
3820 int i, count, clients, maxClients, ping, game, len, visible;
3821 char info[MAX_STRING_CHARS];
3822 // qboolean startRefresh = qtrue; TTimo: unused
3823 static int numinvisible;
3824
3825 if (!(force || uiInfo.uiDC.realTime > uiInfo.serverStatus.nextDisplayRefresh)) {
3826 return;
3827 }
3828 // if we shouldn't reset
3829 if ( force == 2 ) {
3830 force = 0;
3831 }
3832
3833 // do motd updates here too
3834 trap_Cvar_VariableStringBuffer( "cl_motdString", uiInfo.serverStatus.motd, sizeof(uiInfo.serverStatus.motd) );
3835 len = strlen(uiInfo.serverStatus.motd);
3836 if (len == 0) {
3837 strcpy(uiInfo.serverStatus.motd, "Welcome to Team Arena!");
3838 len = strlen(uiInfo.serverStatus.motd);
3839 }
3840 if (len != uiInfo.serverStatus.motdLen) {
3841 uiInfo.serverStatus.motdLen = len;
3842 uiInfo.serverStatus.motdWidth = -1;
3843 }
3844
3845 if (force) {
3846 numinvisible = 0;
3847 // clear number of displayed servers
3848 uiInfo.serverStatus.numDisplayServers = 0;
3849 uiInfo.serverStatus.numPlayersOnServers = 0;
3850 // set list box index to zero
3851 Menu_SetFeederSelection(NULL, FEEDER_SERVERS, 0, NULL);
3852 // mark all servers as visible so we store ping updates for them
3853 trap_LAN_MarkServerVisible(ui_netSource.integer, -1, qtrue);
3854 }
3855
3856 // get the server count (comes from the master)
3857 count = trap_LAN_GetServerCount(ui_netSource.integer);
3858 if (count == -1 || (ui_netSource.integer == AS_LOCAL && count == 0) ) {
3859 // still waiting on a response from the master
3860 uiInfo.serverStatus.numDisplayServers = 0;
3861 uiInfo.serverStatus.numPlayersOnServers = 0;
3862 uiInfo.serverStatus.nextDisplayRefresh = uiInfo.uiDC.realTime + 500;
3863 return;
3864 }
3865
3866 visible = qfalse;
3867 for (i = 0; i < count; i++) {
3868 // if we already got info for this server
3869 if (!trap_LAN_ServerIsVisible(ui_netSource.integer, i)) {
3870 continue;
3871 }
3872 visible = qtrue;
3873 // get the ping for this server
3874 ping = trap_LAN_GetServerPing(ui_netSource.integer, i);
3875 if (ping > 0 || ui_netSource.integer == AS_FAVORITES) {
3876
3877 trap_LAN_GetServerInfo(ui_netSource.integer, i, info, MAX_STRING_CHARS);
3878
3879 if(trap_Cvar_VariableValue("ui_humansonly"))
3880 clients = atoi(Info_ValueForKey(info, "g_humanplayers"));
3881 else
3882 clients = atoi(Info_ValueForKey(info, "clients"));
3883 uiInfo.serverStatus.numPlayersOnServers += clients;
3884
3885 if (ui_browserShowEmpty.integer == 0) {
3886 if (clients == 0) {
3887 trap_LAN_MarkServerVisible(ui_netSource.integer, i, qfalse);
3888 continue;
3889 }
3890 }
3891
3892 if (ui_browserShowFull.integer == 0) {
3893 maxClients = atoi(Info_ValueForKey(info, "sv_maxclients"));
3894 if (clients == maxClients) {
3895 trap_LAN_MarkServerVisible(ui_netSource.integer, i, qfalse);
3896 continue;
3897 }
3898 }
3899
3900 if (uiInfo.joinGameTypes[ui_joinGameType.integer].gtEnum != -1) {
3901 game = atoi(Info_ValueForKey(info, "gametype"));
3902 if (game != uiInfo.joinGameTypes[ui_joinGameType.integer].gtEnum) {
3903 trap_LAN_MarkServerVisible(ui_netSource.integer, i, qfalse);
3904 continue;
3905 }
3906 }
3907
3908 if (ui_serverFilterType.integer > 0) {
3909 if (Q_stricmp(Info_ValueForKey(info, "game"), serverFilters[ui_serverFilterType.integer].basedir) != 0) {
3910 trap_LAN_MarkServerVisible(ui_netSource.integer, i, qfalse);
3911 continue;
3912 }
3913 }
3914 // make sure we never add a favorite server twice
3915 if (ui_netSource.integer == AS_FAVORITES) {
3916 UI_RemoveServerFromDisplayList(i);
3917 }
3918 // insert the server into the list
3919 UI_BinaryServerInsertion(i);
3920 // done with this server
3921 if (ping > 0) {
3922 trap_LAN_MarkServerVisible(ui_netSource.integer, i, qfalse);
3923 numinvisible++;
3924 }
3925 }
3926 }
3927
3928 uiInfo.serverStatus.refreshtime = uiInfo.uiDC.realTime;
3929
3930 // if there were no servers visible for ping updates
3931 if (!visible) {
3932 // UI_StopServerRefresh();
3933 // uiInfo.serverStatus.nextDisplayRefresh = 0;
3934 }
3935 }
3936
3937 typedef struct
3938 {
3939 char *name, *altName;
3940 } serverStatusCvar_t;
3941
3942 serverStatusCvar_t serverStatusCvars[] = {
3943 {"sv_hostname", "Name"},
3944 {"Address", ""},
3945 {"gamename", "Game name"},
3946 {"g_gametype", "Game type"},
3947 {"mapname", "Map"},
3948 {"version", ""},
3949 {"protocol", ""},
3950 {"timelimit", ""},
3951 {"fraglimit", ""},
3952 {NULL, NULL}
3953 };
3954
3955 /*
3956 ==================
3957 UI_SortServerStatusInfo
3958 ==================
3959 */
3960 static void UI_SortServerStatusInfo( serverStatusInfo_t *info ) {
3961 int i, j, index;
3962 char *tmp1, *tmp2;
3963
3964 // FIXME: if "gamename" == "baseq3" or "missionpack" then
3965 // replace the gametype number by FFA, CTF etc.
3966 //
3967 index = 0;
3968 for (i = 0; serverStatusCvars[i].name; i++) {
3969 for (j = 0; j < info->numLines; j++) {
3970 if ( !info->lines[j][1] || info->lines[j][1][0] ) {
3971 continue;
3972 }
3973 if ( !Q_stricmp(serverStatusCvars[i].name, info->lines[j][0]) ) {
3974 // swap lines
3975 tmp1 = info->lines[index][0];
3976 tmp2 = info->lines[index][3];
3977 info->lines[index][0] = info->lines[j][0];
3978 info->lines[index][3] = info->lines[j][3];
3979 info->lines[j][0] = tmp1;
3980 info->lines[j][3] = tmp2;
3981 //
3982 if ( strlen(serverStatusCvars[i].altName) ) {
3983 info->lines[index][0] = serverStatusCvars[i].altName;
3984 }
3985 index++;
3986 }
3987 }
3988 }
3989 }
3990
3991 /*
3992 ==================
3993 UI_GetServerStatusInfo
3994 ==================
3995 */
3996 static int UI_GetServerStatusInfo( const char *serverAddress, serverStatusInfo_t *info ) {
3997 char *p, *score, *ping, *name;
3998 int i, len;
3999
4000 if (!info) {
4001 trap_LAN_ServerStatus( serverAddress, NULL, 0);
4002 return qfalse;
4003 }
4004 memset(info, 0, sizeof(*info));
4005 if ( trap_LAN_ServerStatus( serverAddress, info->text, sizeof(info->text)) ) {
4006 Q_strncpyz(info->address, serverAddress, sizeof(info->address));
4007 p = info->text;
4008 info->numLines = 0;
4009 info->lines[info->numLines][0] = "Address";
4010 info->lines[info->numLines][1] = "";
4011 info->lines[info->numLines][2] = "";
4012 info->lines[info->numLines][3] = info->address;
4013 info->numLines++;
4014 // get the cvars
4015 while (p && *p) {
4016 p = strchr(p, '\\');
4017 if (!p) break;
4018 *p++ = '\0';
4019 if (*p == '\\')
4020 break;
4021 info->lines[info->numLines][0] = p;
4022 info->lines[info->numLines][1] = "";
4023 info->lines[info->numLines][2] = "";
4024 p = strchr(p, '\\');
4025 if (!p) break;
4026 *p++ = '\0';
4027 info->lines[info->numLines][3] = p;
4028
4029 info->numLines++;
4030 if (info->numLines >= MAX_SERVERSTATUS_LINES)
4031 break;
4032 }
4033 // get the player list
4034 if (info->numLines < MAX_SERVERSTATUS_LINES-3) {
4035 // empty line
4036 info->lines[info->numLines][0] = "";
4037 info->lines[info->numLines][1] = "";
4038 info->lines[info->numLines][2] = "";
4039 info->lines[info->numLines][3] = "";
4040 info->numLines++;
4041 // header
4042 info->lines[info->numLines][0] = "num";
4043 info->lines[info->numLines][1] = "score";
4044 info->lines[info->numLines][2] = "ping";
4045 info->lines[info->numLines][3] = "name";
4046 info->numLines++;
4047 // parse players
4048 i = 0;
4049 len = 0;
4050 while (p && *p) {
4051 if (*p == '\\')
4052 *p++ = '\0';
4053 if (!p)
4054 break;
4055 score = p;
4056 p = strchr(p, ' ');
4057 if (!p)
4058 break;
4059 *p++ = '\0';
4060 ping = p;
4061 p = strchr(p, ' ');
4062 if (!p)
4063 break;
4064 *p++ = '\0';
4065 name = p;
4066 Com_sprintf(&info->pings[len], sizeof(info->pings)-len, "%d", i);
4067 info->lines[info->numLines][0] = &info->pings[len];
4068 len += strlen(&info->pings[len]) + 1;
4069 info->lines[info->numLines][1] = score;
4070 info->lines[info->numLines][2] = ping;
4071 info->lines[info->numLines][3] = name;
4072 info->numLines++;
4073 if (info->numLines >= MAX_SERVERSTATUS_LINES)
4074 break;
4075 p = strchr(p, '\\');
4076 if (!p)
4077 break;
4078 *p++ = '\0';
4079 //
4080 i++;
4081 }
4082 }
4083 UI_SortServerStatusInfo( info );
4084 return qtrue;
4085 }
4086 return qfalse;
4087 }
4088
4089 /*
4090 ==================
4091 stristr
4092 ==================
4093 */
4094 static char *stristr(char *str, char *charset) {
4095 int i;
4096
4097 while(*str) {
4098 for (i = 0; charset[i] && str[i]; i++) {
4099 if (toupper(charset[i]) != toupper(str[i])) break;
4100 }
4101 if (!charset[i]) return str;
4102 str++;
4103 }
4104 return NULL;
4105 }
4106
4107 /*
4108 ==================
4109 UI_BuildFindPlayerList
4110 ==================
4111 */
4112 static void UI_BuildFindPlayerList(qboolean force) {
4113 static int numFound, numTimeOuts;
4114 int i, j, resend;
4115 serverStatusInfo_t info;
4116 char name[MAX_NAME_LENGTH+2];
4117 char infoString[MAX_STRING_CHARS];
4118
4119 if (!force) {
4120 if (!uiInfo.nextFindPlayerRefresh || uiInfo.nextFindPlayerRefresh > uiInfo.uiDC.realTime) {
4121 return;
4122 }
4123 }
4124 else {
4125 memset(&uiInfo.pendingServerStatus, 0, sizeof(uiInfo.pendingServerStatus));
4126 uiInfo.numFoundPlayerServers = 0;
4127 uiInfo.currentFoundPlayerServer = 0;
4128 trap_Cvar_VariableStringBuffer( "ui_findPlayer", uiInfo.findPlayerName, sizeof(uiInfo.findPlayerName));
4129 Q_CleanStr(uiInfo.findPlayerName);
4130 // should have a string of some length
4131 if (!strlen(uiInfo.findPlayerName)) {
4132 uiInfo.nextFindPlayerRefresh = 0;
4133 return;
4134 }
4135 // set resend time
4136 resend = ui_serverStatusTimeOut.integer / 2 - 10;
4137 if (resend < 50) {
4138 resend = 50;
4139 }
4140 trap_Cvar_Set("cl_serverStatusResendTime", va("%d", resend));
4141 // reset all server status requests
4142 trap_LAN_ServerStatus( NULL, NULL, 0);
4143 //
4144 uiInfo.numFoundPlayerServers = 1;
4145 Com_sprintf(uiInfo.foundPlayerServerNames[uiInfo.numFoundPlayerServers-1],
4146 sizeof(uiInfo.foundPlayerServerNames[uiInfo.numFoundPlayerServers-1]),
4147 "searching %d...", uiInfo.pendingServerStatus.num);
4148 numFound = 0;
4149 numTimeOuts++;
4150 }
4151 for (i = 0; i < MAX_SERVERSTATUSREQUESTS; i++) {
4152 // if this pending server is valid
4153 if (uiInfo.pendingServerStatus.server[i].valid) {
4154 // try to get the server status for this server
4155 if (UI_GetServerStatusInfo( uiInfo.pendingServerStatus.server[i].adrstr, &info ) ) {
4156 //
4157 numFound++;
4158 // parse through the server status lines
4159 for (j = 0; j < info.numLines; j++) {
4160 // should have ping info
4161 if ( !info.lines[j][2] || !info.lines[j][2][0] ) {
4162 continue;
4163 }
4164 // clean string first
4165 Q_strncpyz(name, info.lines[j][3], sizeof(name));
4166 Q_CleanStr(name);
4167 // if the player name is a substring
4168 if (stristr(name, uiInfo.findPlayerName)) {
4169 // add to found server list if we have space (always leave space for a line with the number found)
4170 if (uiInfo.numFoundPlayerServers < MAX_FOUNDPLAYER_SERVERS-1) {
4171 //
4172 Q_strncpyz(uiInfo.foundPlayerServerAddresses[uiInfo.numFoundPlayerServers-1],
4173 uiInfo.pendingServerStatus.server[i].adrstr,
4174 sizeof(uiInfo.foundPlayerServerAddresses[0]));
4175 Q_strncpyz(uiInfo.foundPlayerServerNames[uiInfo.numFoundPlayerServers-1],
4176 uiInfo.pendingServerStatus.server[i].name,
4177 sizeof(uiInfo.foundPlayerServerNames[0]));
4178 uiInfo.numFoundPlayerServers++;
4179 }
4180 else {
4181 // can't add any more so we're done
4182 uiInfo.pendingServerStatus.num = uiInfo.serverStatus.numDisplayServers;
4183 }
4184 }
4185 }
4186 Com_sprintf(uiInfo.foundPlayerServerNames[uiInfo.numFoundPlayerServers-1],
4187 sizeof(uiInfo.foundPlayerServerNames[uiInfo.numFoundPlayerServers-1]),
4188 "searching %d/%d...", uiInfo.pendingServerStatus.num, numFound);
4189 // retrieved the server status so reuse this spot
4190 uiInfo.pendingServerStatus.server[i].valid = qfalse;
4191 }
4192 }
4193 // if empty pending slot or timed out
4194 if (!uiInfo.pendingServerStatus.server[i].valid ||
4195 uiInfo.pendingServerStatus.server[i].startTime < uiInfo.uiDC.realTime - ui_serverStatusTimeOut.integer) {
4196 if (uiInfo.pendingServerStatus.server[i].valid) {
4197 numTimeOuts++;
4198 }
4199 // reset server status request for this address
4200 UI_GetServerStatusInfo( uiInfo.pendingServerStatus.server[i].adrstr, NULL );
4201 // reuse pending slot
4202 uiInfo.pendingServerStatus.server[i].valid = qfalse;
4203 // if we didn't try to get the status of all servers in the main browser yet
4204 if (uiInfo.pendingServerStatus.num < uiInfo.serverStatus.numDisplayServers) {
4205 uiInfo.pendingServerStatus.server[i].startTime = uiInfo.uiDC.realTime;
4206 trap_LAN_GetServerAddressString(ui_netSource.integer, uiInfo.serverStatus.displayServers[uiInfo.pendingServerStatus.num],
4207 uiInfo.pendingServerStatus.server[i].adrstr, sizeof(uiInfo.pendingServerStatus.server[i].adrstr));
4208 trap_LAN_GetServerInfo(ui_netSource.integer, uiInfo.serverStatus.displayServers[uiInfo.pendingServerStatus.num], infoString, sizeof(infoString));
4209 Q_strncpyz(uiInfo.pendingServerStatus.server[i].name, Info_ValueForKey(infoString, "hostname"), sizeof(uiInfo.pendingServerStatus.server[0].name));
4210 uiInfo.pendingServerStatus.server[i].valid = qtrue;
4211 uiInfo.pendingServerStatus.num++;
4212 Com_sprintf(uiInfo.foundPlayerServerNames[uiInfo.numFoundPlayerServers-1],
4213 sizeof(uiInfo.foundPlayerServerNames[uiInfo.numFoundPlayerServers-1]),
4214 "searching %d/%d...", uiInfo.pendingServerStatus.num, numFound);
4215 }
4216 }
4217 }
4218 for (i = 0; i < MAX_SERVERSTATUSREQUESTS; i++) {
4219 if (uiInfo.pendingServerStatus.server[i].valid) {
4220 break;
4221 }
4222 }
4223 // if still trying to retrieve server status info
4224 if (i < MAX_SERVERSTATUSREQUESTS) {
4225 uiInfo.nextFindPlayerRefresh = uiInfo.uiDC.realTime + 25;
4226 }
4227 else {
4228 // add a line that shows the number of servers found
4229 if (!uiInfo.numFoundPlayerServers) {
4230 Com_sprintf(uiInfo.foundPlayerServerNames[uiInfo.numFoundPlayerServers-1], sizeof(uiInfo.foundPlayerServerAddresses[0]), "no servers found");
4231 }
4232 else {
4233 Com_sprintf(uiInfo.foundPlayerServerNames[uiInfo.numFoundPlayerServers-1], sizeof(uiInfo.foundPlayerServerAddresses[0]),
4234 "%d server%s found with player %s", uiInfo.numFoundPlayerServers-1,
4235 uiInfo.numFoundPlayerServers == 2 ? "":"s", uiInfo.findPlayerName);
4236 }
4237 uiInfo.nextFindPlayerRefresh = 0;
4238 // show the server status info for the selected server
4239 UI_FeederSelection(FEEDER_FINDPLAYER, uiInfo.currentFoundPlayerServer);
4240 }
4241 }
4242
4243 /*
4244 ==================
4245 UI_BuildServerStatus
4246 ==================
4247 */
4248 static void UI_BuildServerStatus(qboolean force) {
4249
4250 if (uiInfo.nextFindPlayerRefresh) {
4251 return;
4252 }
4253 if (!force) {
4254 if (!uiInfo.nextServerStatusRefresh || uiInfo.nextServerStatusRefresh > uiInfo.uiDC.realTime) {
4255 return;
4256 }
4257 }
4258 else {
4259 Menu_SetFeederSelection(NULL, FEEDER_SERVERSTATUS, 0, NULL);
4260 uiInfo.serverStatusInfo.numLines = 0;
4261 // reset all server status requests
4262 trap_LAN_ServerStatus( NULL, NULL, 0);
4263 }
4264 if (uiInfo.serverStatus.currentServer < 0 || uiInfo.serverStatus.currentServer > uiInfo.serverStatus.numDisplayServers || uiInfo.serverStatus.numDisplayServers == 0) {
4265 return;
4266 }
4267 if (UI_GetServerStatusInfo( uiInfo.serverStatusAddress, &uiInfo.serverStatusInfo ) ) {
4268 uiInfo.nextServerStatusRefresh = 0;
4269 UI_GetServerStatusInfo( uiInfo.serverStatusAddress, NULL );
4270 }
4271 else {
4272 uiInfo.nextServerStatusRefresh = uiInfo.uiDC.realTime + 500;
4273 }
4274 }
4275
4276 /*
4277 ==================
4278 UI_FeederCount
4279 ==================
4280 */
4281 static int UI_FeederCount(float feederID) {
4282 if (feederID == FEEDER_HEADS) {
4283 return UI_HeadCountByTeam();
4284 } else if (feederID == FEEDER_Q3HEADS) {
4285 return uiInfo.q3HeadCount;
4286 } else if (feederID == FEEDER_CINEMATICS) {
4287 return uiInfo.movieCount;
4288 } else if (feederID == FEEDER_MAPS || feederID == FEEDER_ALLMAPS) {
4289 return UI_MapCountByGameType(feederID == FEEDER_MAPS ? qtrue : qfalse);
4290 } else if (feederID == FEEDER_SERVERS) {
4291 return uiInfo.serverStatus.numDisplayServers;
4292 } else if (feederID == FEEDER_SERVERSTATUS) {
4293 return uiInfo.serverStatusInfo.numLines;
4294 } else if (feederID == FEEDER_FINDPLAYER) {
4295 return uiInfo.numFoundPlayerServers;
4296 } else if (feederID == FEEDER_PLAYER_LIST) {
4297 if (uiInfo.uiDC.realTime > uiInfo.playerRefresh) {
4298 uiInfo.playerRefresh = uiInfo.uiDC.realTime + 3000;
4299 UI_BuildPlayerList();
4300 }
4301 return uiInfo.playerCount;
4302 } else if (feederID == FEEDER_TEAM_LIST) {
4303 if (uiInfo.uiDC.realTime > uiInfo.playerRefresh) {
4304 uiInfo.playerRefresh = uiInfo.uiDC.realTime + 3000;
4305 UI_BuildPlayerList();
4306 }
4307 return uiInfo.myTeamCount;
4308 } else if (feederID == FEEDER_MODS) {
4309 return uiInfo.modCount;
4310 } else if (feederID == FEEDER_DEMOS) {
4311 return uiInfo.demoCount;
4312 }
4313 return 0;
4314 }
4315
4316 static const char *UI_SelectedMap(int index, int *actual) {
4317 int i, c;
4318 c = 0;
4319 *actual = 0;
4320 for (i = 0; i < uiInfo.mapCount; i++) {
4321 if (uiInfo.mapList[i].active) {
4322 if (c == index) {
4323 *actual = i;
4324 return uiInfo.mapList[i].mapName;
4325 } else {
4326 c++;
4327 }
4328 }
4329 }
4330 return "";
4331 }
4332
4333 static const char *UI_SelectedHead(int index, int *actual) {
4334 int i, c;
4335 c = 0;
4336 *actual = 0;
4337 for (i = 0; i < uiInfo.characterCount; i++) {
4338 if (uiInfo.characterList[i].active) {
4339 if (c == index) {
4340 *actual = i;
4341 return uiInfo.characterList[i].name;
4342 } else {
4343 c++;
4344 }
4345 }
4346 }
4347 return "";
4348 }
4349
4350 static int UI_GetIndexFromSelection(int actual) {
4351 int i, c;
4352 c = 0;
4353 for (i = 0; i < uiInfo.mapCount; i++) {
4354 if (uiInfo.mapList[i].active) {
4355 if (i == actual) {
4356 return c;
4357 }
4358 c++;
4359 }
4360 }
4361 return 0;
4362 }
4363
4364 static void UI_UpdatePendingPings( void ) {
4365 trap_LAN_ResetPings(ui_netSource.integer);
4366 uiInfo.serverStatus.refreshActive = qtrue;
4367 uiInfo.serverStatus.refreshtime = uiInfo.uiDC.realTime + 1000;
4368
4369 }
4370
4371 static const char *UI_FeederItemText(float feederID, int index, int column, qhandle_t *handle) {
4372 static char info[MAX_STRING_CHARS];
4373 static char hostname[1024];
4374 static char clientBuff[32];
4375 static int lastColumn = -1;
4376 static int lastTime = 0;
4377 *handle = -1;
4378 if (feederID == FEEDER_HEADS) {
4379 int actual;
4380 return UI_SelectedHead(index, &actual);
4381 } else if (feederID == FEEDER_Q3HEADS) {
4382 if (index >= 0 && index < uiInfo.q3HeadCount) {
4383 return uiInfo.q3HeadNames[index];
4384 }
4385 } else if (feederID == FEEDER_MAPS || feederID == FEEDER_ALLMAPS) {
4386 int actual;
4387 return UI_SelectedMap(index, &actual);
4388 } else if (feederID == FEEDER_SERVERS) {
4389 if (index >= 0 && index < uiInfo.serverStatus.numDisplayServers) {
4390 int ping, game;
4391 if (lastColumn != column || lastTime > uiInfo.uiDC.realTime + 5000) {
4392 trap_LAN_GetServerInfo(ui_netSource.integer, uiInfo.serverStatus.displayServers[index], info, MAX_STRING_CHARS);
4393 lastColumn = column;
4394 lastTime = uiInfo.uiDC.realTime;
4395 }
4396 ping = atoi(Info_ValueForKey(info, "ping"));
4397 if (ping == -1) {
4398 // if we ever see a ping that is out of date, do a server refresh
4399 // UI_UpdatePendingPings();
4400 }
4401 switch (column) {
4402 case SORT_HOST :
4403 if (ping <= 0) {
4404 return Info_ValueForKey(info, "addr");
4405 } else {
4406 if ( ui_netSource.integer == AS_LOCAL ) {
4407 Com_sprintf( hostname, sizeof(hostname), "%s [%s]",
4408 Info_ValueForKey(info, "hostname"),
4409 netnames[atoi(Info_ValueForKey(info, "nettype"))] );
4410 return hostname;
4411 }
4412 else {
4413 Com_sprintf( hostname, sizeof(hostname), "%s", Info_ValueForKey(info, "hostname"));
4414 return hostname;
4415 }
4416 }
4417 case SORT_MAP : return Info_ValueForKey(info, "mapname");
4418 case SORT_CLIENTS :
4419 Com_sprintf( clientBuff, sizeof(clientBuff), "%s (%s)", trap_Cvar_VariableValue("ui_humansonly")? Info_ValueForKey(info, "g_humanplayers") : Info_ValueForKey(info, "clients"), Info_ValueForKey(info, "sv_maxclients"));
4420 return clientBuff;
4421 case SORT_GAME :
4422 game = atoi(Info_ValueForKey(info, "gametype"));
4423 if (game >= 0 && game < numTeamArenaGameTypes) {
4424 return teamArenaGameTypes[game];
4425 } else {
4426 return "Unknown";
4427 }
4428 case SORT_PING :
4429 if (ping <= 0) {
4430 return "...";
4431 } else {
4432 return Info_ValueForKey(info, "ping");
4433 }
4434 }
4435 }
4436 } else if (feederID == FEEDER_SERVERSTATUS) {
4437 if ( index >= 0 && index < uiInfo.serverStatusInfo.numLines ) {
4438 if ( column >= 0 && column < 4 ) {
4439 return uiInfo.serverStatusInfo.lines[index][column];
4440 }
4441 }
4442 } else if (feederID == FEEDER_FINDPLAYER) {
4443 if ( index >= 0 && index < uiInfo.numFoundPlayerServers ) {
4444 //return uiInfo.foundPlayerServerAddresses[index];
4445 return uiInfo.foundPlayerServerNames[index];
4446 }
4447 } else if (feederID == FEEDER_PLAYER_LIST) {
4448 if (index >= 0 && index < uiInfo.playerCount) {
4449 return uiInfo.playerNames[index];
4450 }
4451 } else if (feederID == FEEDER_TEAM_LIST) {
4452 if (index >= 0 && index < uiInfo.myTeamCount) {
4453 return uiInfo.teamNames[index];
4454 }
4455 } else if (feederID == FEEDER_MODS) {
4456 if (index >= 0 && index < uiInfo.modCount) {
4457 if (uiInfo.modList[index].modDescr && *uiInfo.modList[index].modDescr) {
4458 return uiInfo.modList[index].modDescr;
4459 } else {
4460 return uiInfo.modList[index].modName;
4461 }
4462 }
4463 } else if (feederID == FEEDER_CINEMATICS) {
4464 if (index >= 0 && index < uiInfo.movieCount) {
4465 return uiInfo.movieList[index];
4466 }
4467 } else if (feederID == FEEDER_DEMOS) {
4468 if (index >= 0 && index < uiInfo.demoCount) {
4469 return uiInfo.demoList[index];
4470 }
4471 }
4472 return "";
4473 }
4474
4475
4476 static qhandle_t UI_FeederItemImage(float feederID, int index) {
4477 if (feederID == FEEDER_HEADS) {
4478 int actual;
4479 UI_SelectedHead(index, &actual);
4480 index = actual;
4481 if (index >= 0 && index < uiInfo.characterCount) {
4482 if (uiInfo.characterList[index].headImage == -1) {
4483 uiInfo.characterList[index].headImage = trap_R_RegisterShaderNoMip(uiInfo.characterList[index].imageName);
4484 }
4485 return uiInfo.characterList[index].headImage;
4486 }
4487 } else if (feederID == FEEDER_Q3HEADS) {
4488 if (index >= 0 && index < uiInfo.q3HeadCount) {
4489 return uiInfo.q3HeadIcons[index];
4490 }
4491 } else if (feederID == FEEDER_ALLMAPS || feederID == FEEDER_MAPS) {
4492 int actual;
4493 UI_SelectedMap(index, &actual);
4494 index = actual;
4495 if (index >= 0 && index < uiInfo.mapCount) {
4496 if (uiInfo.mapList[index].levelShot == -1) {
4497 uiInfo.mapList[index].levelShot = trap_R_RegisterShaderNoMip(uiInfo.mapList[index].imageName);
4498 }
4499 return uiInfo.mapList[index].levelShot;
4500 }
4501 }
4502 return 0;
4503 }
4504
4505 static void UI_FeederSelection(float feederID, int index) {
4506 static char info[MAX_STRING_CHARS];
4507 if (feederID == FEEDER_HEADS) {
4508 int actual;
4509 UI_SelectedHead(index, &actual);
4510 index = actual;
4511 if (index >= 0 && index < uiInfo.characterCount) {
4512 trap_Cvar_Set( "team_model", va("%s", uiInfo.characterList[index].base));
4513 trap_Cvar_Set( "team_headmodel", va("*%s", uiInfo.characterList[index].name));
4514 updateModel = qtrue;
4515 }
4516 } else if (feederID == FEEDER_Q3HEADS) {
4517 if (index >= 0 && index < uiInfo.q3HeadCount) {
4518 trap_Cvar_Set( "model", uiInfo.q3HeadNames[index]);
4519 trap_Cvar_Set( "headmodel", uiInfo.q3HeadNames[index]);
4520 updateModel = qtrue;
4521 }
4522 } else if (feederID == FEEDER_MAPS || feederID == FEEDER_ALLMAPS) {
4523 int actual, map;
4524 map = (feederID == FEEDER_ALLMAPS) ? ui_currentNetMap.integer : ui_currentMap.integer;
4525 if (uiInfo.mapList[map].cinematic >= 0) {
4526 trap_CIN_StopCinematic(uiInfo.mapList[map].cinematic);
4527 uiInfo.mapList[map].cinematic = -1;
4528 }
4529 UI_SelectedMap(index, &actual);
4530 trap_Cvar_Set("ui_mapIndex", va("%d", index));
4531 ui_mapIndex.integer = index;
4532
4533 if (feederID == FEEDER_MAPS) {
4534 ui_currentMap.integer = actual;
4535 trap_Cvar_Set("ui_currentMap", va("%d", actual));
4536 uiInfo.mapList[ui_currentMap.integer].cinematic = trap_CIN_PlayCinematic(va("%s.roq", uiInfo.mapList[ui_currentMap.integer].mapLoadName), 0, 0, 0, 0, (CIN_loop | CIN_silent) );
4537 UI_LoadBestScores(uiInfo.mapList[ui_currentMap.integer].mapLoadName, uiInfo.gameTypes[ui_gameType.integer].gtEnum);
4538 trap_Cvar_Set("ui_opponentModel", uiInfo.mapList[ui_currentMap.integer].opponentName);
4539 updateOpponentModel = qtrue;
4540 } else {
4541 ui_currentNetMap.integer = actual;
4542 trap_Cvar_Set("ui_currentNetMap", va("%d", actual));
4543 uiInfo.mapList[ui_currentNetMap.integer].cinematic = trap_CIN_PlayCinematic(va("%s.roq", uiInfo.mapList[ui_currentNetMap.integer].mapLoadName), 0, 0, 0, 0, (CIN_loop | CIN_silent) );
4544 }
4545
4546 } else if (feederID == FEEDER_SERVERS) {
4547 const char *mapName = NULL;
4548 uiInfo.serverStatus.currentServer = index;
4549 trap_LAN_GetServerInfo(ui_netSource.integer, uiInfo.serverStatus.displayServers[index], info, MAX_STRING_CHARS);
4550 uiInfo.serverStatus.currentServerPreview = trap_R_RegisterShaderNoMip(va("levelshots/%s", Info_ValueForKey(info, "mapname")));
4551 if (uiInfo.serverStatus.currentServerCinematic >= 0) {
4552 trap_CIN_StopCinematic(uiInfo.serverStatus.currentServerCinematic);
4553 uiInfo.serverStatus.currentServerCinematic = -1;
4554 }
4555 mapName = Info_ValueForKey(info, "mapname");
4556 if (mapName && *mapName) {
4557 uiInfo.serverStatus.currentServerCinematic = trap_CIN_PlayCinematic(va("%s.roq", mapName), 0, 0, 0, 0, (CIN_loop | CIN_silent) );
4558 }
4559 } else if (feederID == FEEDER_SERVERSTATUS) {
4560 //
4561 } else if (feederID == FEEDER_FINDPLAYER) {
4562 uiInfo.currentFoundPlayerServer = index;
4563 //
4564 if ( index < uiInfo.numFoundPlayerServers-1) {
4565 // build a new server status for this server
4566 Q_strncpyz(uiInfo.serverStatusAddress, uiInfo.foundPlayerServerAddresses[uiInfo.currentFoundPlayerServer], sizeof(uiInfo.serverStatusAddress));
4567 Menu_SetFeederSelection(NULL, FEEDER_SERVERSTATUS, 0, NULL);
4568 UI_BuildServerStatus(qtrue);
4569 }
4570 } else if (feederID == FEEDER_PLAYER_LIST) {
4571 uiInfo.playerIndex = index;
4572 } else if (feederID == FEEDER_TEAM_LIST) {
4573 uiInfo.teamIndex = index;
4574 } else if (feederID == FEEDER_MODS) {
4575 uiInfo.modIndex = index;
4576 } else if (feederID == FEEDER_CINEMATICS) {
4577 uiInfo.movieIndex = index;
4578 if (uiInfo.previewMovie >= 0) {
4579 trap_CIN_StopCinematic(uiInfo.previewMovie);
4580 }
4581 uiInfo.previewMovie = -1;
4582 } else if (feederID == FEEDER_DEMOS) {
4583 uiInfo.demoIndex = index;
4584 }
4585 }
4586
4587 static qboolean Team_Parse(char **p) {
4588 char *token;
4589 const char *tempStr;
4590 int i;
4591
4592 token = COM_ParseExt(p, qtrue);
4593
4594 if (token[0] != '{') {
4595 return qfalse;
4596 }
4597
4598 while ( 1 ) {
4599
4600 token = COM_ParseExt(p, qtrue);
4601
4602 if (Q_stricmp(token, "}") == 0) {
4603 return qtrue;
4604 }
4605
4606 if ( !token || token[0] == 0 ) {
4607 return qfalse;
4608 }
4609
4610 if (token[0] == '{') {
4611 // seven tokens per line, team name and icon, and 5 team member names
4612 if (!String_Parse(p, &uiInfo.teamList[uiInfo.teamCount].teamName) || !String_Parse(p, &tempStr)) {
4613 return qfalse;
4614 }
4615
4616
4617 uiInfo.teamList[uiInfo.teamCount].imageName = tempStr;
4618 uiInfo.teamList[uiInfo.teamCount].teamIcon = trap_R_RegisterShaderNoMip(uiInfo.teamList[uiInfo.teamCount].imageName);
4619 uiInfo.teamList[uiInfo.teamCount].teamIcon_Metal = trap_R_RegisterShaderNoMip(va("%s_metal",uiInfo.teamList[uiInfo.teamCount].imageName));
4620 uiInfo.teamList[uiInfo.teamCount].teamIcon_Name = trap_R_RegisterShaderNoMip(va("%s_name", uiInfo.teamList[uiInfo.teamCount].imageName));
4621
4622 uiInfo.teamList[uiInfo.teamCount].cinematic = -1;
4623
4624 for (i = 0; i < TEAM_MEMBERS; i++) {
4625 uiInfo.teamList[uiInfo.teamCount].teamMembers[i] = NULL;
4626 if (!String_Parse(p, &uiInfo.teamList[uiInfo.teamCount].teamMembers[i])) {
4627 return qfalse;
4628 }
4629 }
4630
4631 Com_Printf("Loaded team %s with team icon %s.\n", uiInfo.teamList[uiInfo.teamCount].teamName, tempStr);
4632 if (uiInfo.teamCount < MAX_TEAMS) {
4633 uiInfo.teamCount++;
4634 } else {
4635 Com_Printf("Too many teams, last team replaced!\n");
4636 }
4637 token = COM_ParseExt(p, qtrue);
4638 if (token[0] != '}') {
4639 return qfalse;
4640 }
4641 }
4642 }
4643
4644 return qfalse;
4645 }
4646
4647 static qboolean Character_Parse(char **p) {
4648 char *token;
4649 const char *tempStr;
4650
4651 token = COM_ParseExt(p, qtrue);
4652
4653 if (token[0] != '{') {
4654 return qfalse;
4655 }
4656
4657
4658 while ( 1 ) {
4659 token = COM_ParseExt(p, qtrue);
4660
4661 if (Q_stricmp(token, "}") == 0) {
4662 return qtrue;
4663 }
4664
4665 if ( !token || token[0] == 0 ) {
4666 return qfalse;
4667 }
4668
4669 if (token[0] == '{') {
4670 // two tokens per line, character name and sex
4671 if (!String_Parse(p, &uiInfo.characterList[uiInfo.characterCount].name) || !String_Parse(p, &tempStr)) {
4672 return qfalse;
4673 }
4674
4675 uiInfo.characterList[uiInfo.characterCount].headImage = -1;
4676 uiInfo.characterList[uiInfo.characterCount].imageName = String_Alloc(va("models/players/heads/%s/icon_default.tga", uiInfo.characterList[uiInfo.characterCount].name));
4677
4678 if (tempStr && (!Q_stricmp(tempStr, "female"))) {
4679 uiInfo.characterList[uiInfo.characterCount].base = String_Alloc(va("kyonshi"));
4680 } else if (tempStr && (!Q_stricmp(tempStr, "male"))) {
4681 uiInfo.characterList[uiInfo.characterCount].base = String_Alloc(va("sergei"));
4682 } else {
4683 uiInfo.characterList[uiInfo.characterCount].base = String_Alloc(va("%s",tempStr));
4684 }
4685
4686 Com_Printf("Loaded %s character %s.\n", uiInfo.characterList[uiInfo.characterCount].base, uiInfo.characterList[uiInfo.characterCount].name);
4687 if (uiInfo.characterCount < MAX_HEADS) {
4688 uiInfo.characterCount++;
4689 } else {
4690 Com_Printf("Too many characters, last character replaced!\n");
4691 }
4692
4693 token = COM_ParseExt(p, qtrue);
4694 if (token[0] != '}') {
4695 return qfalse;
4696 }
4697 }
4698 }
4699
4700 return qfalse;
4701 }
4702
4703
4704 static qboolean Alias_Parse(char **p) {
4705 char *token;
4706
4707 token = COM_ParseExt(p, qtrue);
4708
4709 if (token[0] != '{') {
4710 return qfalse;
4711 }
4712
4713 while ( 1 ) {
4714 token = COM_ParseExt(p, qtrue);
4715
4716 if (Q_stricmp(token, "}") == 0) {
4717 return qtrue;
4718 }
4719
4720 if ( !token || token[0] == 0 ) {
4721 return qfalse;
4722 }
4723
4724 if (token[0] == '{') {
4725 // three tokens per line, character name, bot alias, and preferred action a - all purpose, d - defense, o - offense
4726 if (!String_Parse(p, &uiInfo.aliasList[uiInfo.aliasCount].name) || !String_Parse(p, &uiInfo.aliasList[uiInfo.aliasCount].ai) || !String_Parse(p, &uiInfo.aliasList[uiInfo.aliasCount].action)) {
4727 return qfalse;
4728 }
4729
4730 Com_Printf("Loaded character alias %s using character ai %s.\n", uiInfo.aliasList[uiInfo.aliasCount].name, uiInfo.aliasList[uiInfo.aliasCount].ai);
4731 if (uiInfo.aliasCount < MAX_ALIASES) {
4732 uiInfo.aliasCount++;
4733 } else {
4734 Com_Printf("Too many aliases, last alias replaced!\n");
4735 }
4736
4737 token = COM_ParseExt(p, qtrue);
4738 if (token[0] != '}') {
4739 return qfalse;
4740 }
4741 }
4742 }
4743
4744 return qfalse;
4745 }
4746
4747
4748
4749 // mode
4750 // 0 - high level parsing
4751 // 1 - team parsing
4752 // 2 - character parsing
4753 static void UI_ParseTeamInfo(const char *teamFile) {
4754 char *token;
4755 char *p;
4756 char *buff = NULL;
4757 //static int mode = 0; TTimo: unused
4758
4759 buff = GetMenuBuffer(teamFile);
4760 if (!buff) {
4761 return;
4762 }
4763
4764 p = buff;
4765
4766 while ( 1 ) {
4767 token = COM_ParseExt( &p, qtrue );
4768 if( !token || token[0] == 0 || token[0] == '}') {
4769 break;
4770 }
4771
4772 if ( Q_stricmp( token, "}" ) == 0 ) {
4773 break;
4774 }
4775
4776 if (Q_stricmp(token, "teams") == 0) {
4777
4778 if (Team_Parse(&p)) {
4779 continue;
4780 } else {
4781 break;
4782 }
4783 }
4784
4785 if (Q_stricmp(token, "characters") == 0) {
4786 Character_Parse(&p);
4787 }
4788
4789 if (Q_stricmp(token, "aliases") == 0) {
4790 Alias_Parse(&p);
4791 }
4792
4793 }
4794
4795 }
4796
4797
4798 static qboolean GameType_Parse(char **p, qboolean join) {
4799 char *token;
4800
4801 token = COM_ParseExt(p, qtrue);
4802
4803 if (token[0] != '{') {
4804 return qfalse;
4805 }
4806
4807 if (join) {
4808 uiInfo.numJoinGameTypes = 0;
4809 } else {
4810 uiInfo.numGameTypes = 0;
4811 }
4812
4813 while ( 1 ) {
4814 token = COM_ParseExt(p, qtrue);
4815
4816 if (Q_stricmp(token, "}") == 0) {
4817 return qtrue;
4818 }
4819
4820 if ( !token || token[0] == 0 ) {
4821 return qfalse;
4822 }
4823
4824 if (token[0] == '{') {
4825 // two tokens per line, character name and sex
4826 if (join) {
4827 if (!String_Parse(p, &uiInfo.joinGameTypes[uiInfo.numJoinGameTypes].gameType) || !Int_Parse(p, &uiInfo.joinGameTypes[uiInfo.numJoinGameTypes].gtEnum)) {
4828 return qfalse;
4829 }
4830 } else {
4831 if (!String_Parse(p, &uiInfo.gameTypes[uiInfo.numGameTypes].gameType) || !Int_Parse(p, &uiInfo.gameTypes[uiInfo.numGameTypes].gtEnum)) {
4832 return qfalse;
4833 }
4834 }
4835
4836 if (join) {
4837 if (uiInfo.numJoinGameTypes < MAX_GAMETYPES) {
4838 uiInfo.numJoinGameTypes++;
4839 } else {
4840 Com_Printf("Too many net game types, last one replace!\n");
4841 }
4842 } else {
4843 if (uiInfo.numGameTypes < MAX_GAMETYPES) {
4844 uiInfo.numGameTypes++;
4845 } else {
4846 Com_Printf("Too many game types, last one replace!\n");
4847 }
4848 }
4849
4850 token = COM_ParseExt(p, qtrue);
4851 if (token[0] != '}') {
4852 return qfalse;
4853 }
4854 }
4855 }
4856 return qfalse;
4857 }
4858
4859 static qboolean MapList_Parse(char **p) {
4860 char *token;
4861
4862 token = COM_ParseExt(p, qtrue);
4863
4864 if (token[0] != '{') {
4865 return qfalse;
4866 }
4867
4868 uiInfo.mapCount = 0;
4869
4870 while ( 1 ) {
4871 token = COM_ParseExt(p, qtrue);
4872
4873 if (Q_stricmp(token, "}") == 0) {
4874 return qtrue;
4875 }
4876
4877 if ( !token || token[0] == 0 ) {
4878 return qfalse;
4879 }
4880
4881 if (token[0] == '{') {
4882 if (!String_Parse(p, &uiInfo.mapList[uiInfo.mapCount].mapName) || !String_Parse(p, &uiInfo.mapList[uiInfo.mapCount].mapLoadName)
4883 ||!Int_Parse(p, &uiInfo.mapList[uiInfo.mapCount].teamMembers) ) {
4884 return qfalse;
4885 }
4886
4887 if (!String_Parse(p, &uiInfo.mapList[uiInfo.mapCount].opponentName)) {
4888 return qfalse;
4889 }
4890
4891 uiInfo.mapList[uiInfo.mapCount].typeBits = 0;
4892
4893 while (1) {
4894 token = COM_ParseExt(p, qtrue);
4895 if (token[0] >= '0' && token[0] <= '9') {
4896 uiInfo.mapList[uiInfo.mapCount].typeBits |= (1 << (token[0] - 0x030));
4897 if (!Int_Parse(p, &uiInfo.mapList[uiInfo.mapCount].timeToBeat[token[0] - 0x30])) {
4898 return qfalse;
4899 }
4900 } else {
4901 break;
4902 }
4903 }
4904
4905 //mapList[mapCount].imageName = String_Alloc(va("levelshots/%s", mapList[mapCount].mapLoadName));
4906 //if (uiInfo.mapCount == 0) {
4907 // only load the first cinematic, selection loads the others
4908 // uiInfo.mapList[uiInfo.mapCount].cinematic = trap_CIN_PlayCinematic(va("%s.roq",uiInfo.mapList[uiInfo.mapCount].mapLoadName), qfalse, qfalse, qtrue, 0, 0, 0, 0);
4909 //}
4910 uiInfo.mapList[uiInfo.mapCount].cinematic = -1;
4911 uiInfo.mapList[uiInfo.mapCount].levelShot = trap_R_RegisterShaderNoMip(va("levelshots/%s_small", uiInfo.mapList[uiInfo.mapCount].mapLoadName));
4912
4913 if (uiInfo.mapCount < MAX_MAPS) {
4914 uiInfo.mapCount++;
4915 } else {
4916 Com_Printf("Too many maps, last one replaced!\n");
4917 }
4918 }
4919 }
4920 return qfalse;
4921 }
4922
4923 static void UI_ParseGameInfo(const char *teamFile) {
4924 char *token;
4925 char *p;
4926 char *buff = NULL;
4927 //int mode = 0; TTimo: unused
4928
4929 buff = GetMenuBuffer(teamFile);
4930 if (!buff) {
4931 return;
4932 }
4933
4934 p = buff;
4935
4936 while ( 1 ) {
4937 token = COM_ParseExt( &p, qtrue );
4938 if( !token || token[0] == 0 || token[0] == '}') {
4939 break;
4940 }
4941
4942 if ( Q_stricmp( token, "}" ) == 0 ) {
4943 break;
4944 }
4945
4946 if (Q_stricmp(token, "gametypes") == 0) {
4947
4948 if (GameType_Parse(&p, qfalse)) {
4949 continue;
4950 } else {
4951 break;
4952 }
4953 }
4954
4955 if (Q_stricmp(token, "joingametypes") == 0) {
4956
4957 if (GameType_Parse(&p, qtrue)) {
4958 continue;
4959 } else {
4960 break;
4961 }
4962 }
4963
4964 if (Q_stricmp(token, "maps") == 0) {
4965 // start a new menu
4966 MapList_Parse(&p);
4967 }
4968
4969 }
4970 }
4971
4972 static void UI_Pause(qboolean b) {
4973 if (b) {
4974 // pause the game and set the ui keycatcher
4975 trap_Cvar_Set( "cl_paused", "1" );
4976 trap_Key_SetCatcher( KEYCATCH_UI );
4977 } else {
4978 // unpause the game and clear the ui keycatcher
4979 trap_Key_SetCatcher( trap_Key_GetCatcher() & ~KEYCATCH_UI );
4980 trap_Key_ClearStates();
4981 trap_Cvar_Set( "cl_paused", "0" );
4982 }
4983 }
4984
4985 #ifndef MISSIONPACK // bk001206
4986 static int UI_OwnerDraw_Width(int ownerDraw) {
4987 // bk001205 - LCC missing return value
4988 return 0;
4989 }
4990 #endif
4991
4992 static int UI_PlayCinematic(const char *name, float x, float y, float w, float h) {
4993 return trap_CIN_PlayCinematic(name, x, y, w, h, (CIN_loop | CIN_silent));
4994 }
4995
4996 static void UI_StopCinematic(int handle) {
4997 if (handle >= 0) {
4998 trap_CIN_StopCinematic(handle);
4999 } else {
5000 handle = abs(handle);
5001 if (handle == UI_MAPCINEMATIC) {
5002 if (uiInfo.mapList[ui_currentMap.integer].cinematic >= 0) {
5003 trap_CIN_StopCinematic(uiInfo.mapList[ui_currentMap.integer].cinematic);
5004 uiInfo.mapList[ui_currentMap.integer].cinematic = -1;
5005 }
5006 } else if (handle == UI_NETMAPCINEMATIC) {
5007 if (uiInfo.serverStatus.currentServerCinematic >= 0) {
5008 trap_CIN_StopCinematic(uiInfo.serverStatus.currentServerCinematic);
5009 uiInfo.serverStatus.currentServerCinematic = -1;
5010 }
5011 } else if (handle == UI_CLANCINEMATIC) {
5012 int i = UI_TeamIndexFromName(UI_Cvar_VariableString("ui_teamName"));
5013 if (i >= 0 && i < uiInfo.teamCount) {
5014 if (uiInfo.teamList[i].cinematic >= 0) {
5015 trap_CIN_StopCinematic(uiInfo.teamList[i].cinematic);
5016 uiInfo.teamList[i].cinematic = -1;
5017 }
5018 }
5019 }
5020 }
5021 }
5022
5023 static void UI_DrawCinematic(int handle, float x, float y, float w, float h) {
5024 trap_CIN_SetExtents(handle, x, y, w, h);
5025 trap_CIN_DrawCinematic(handle);
5026 }
5027
5028 static void UI_RunCinematicFrame(int handle) {
5029 trap_CIN_RunCinematic(handle);
5030 }
5031
5032
5033
5034 /*
5035 =================
5036 PlayerModel_BuildList
5037 =================
5038 */
5039 static void UI_BuildQ3Model_List( void )
5040 {
5041 int numdirs;
5042 int numfiles;
5043 char dirlist[2048];
5044 char filelist[2048];
5045 char skinname[MAX_QPATH];
5046 char scratch[256];
5047 char* dirptr;
5048 char* fileptr;
5049 int i;
5050 int j, k, dirty;
5051 int dirlen;
5052 int filelen;
5053
5054 uiInfo.q3HeadCount = 0;
5055
5056 // iterate directory of all player models
5057 numdirs = trap_FS_GetFileList("models/players", "/", dirlist, 32768 ); // upped from 2048
5058 dirptr = dirlist;
5059 for (i=0; i<numdirs && uiInfo.q3HeadCount < MAX_PLAYERMODELS; i++,dirptr+=dirlen+1)
5060 {
5061 dirlen = strlen(dirptr);
5062
5063 if (dirlen && dirptr[dirlen-1]=='/') dirptr[dirlen-1]='\0';
5064
5065 if (!strcmp(dirptr,".") || !strcmp(dirptr,".."))
5066 continue;
5067
5068 // iterate all skin files in directory
5069 numfiles = trap_FS_GetFileList( va("models/players/%s",dirptr), "tga", filelist, 2048 );
5070 fileptr = filelist;
5071 for (j=0; j<numfiles && uiInfo.q3HeadCount < MAX_PLAYERMODELS;j++,fileptr+=filelen+1)
5072 {
5073 filelen = strlen(fileptr);
5074
5075 COM_StripExtension(fileptr, skinname, sizeof(skinname));
5076
5077 // look for icon_????
5078 if (Q_stricmpn(skinname, "icon_", 5) == 0 && !(Q_stricmp(skinname,"icon_blue") == 0 || Q_stricmp(skinname,"icon_red") == 0))
5079 {
5080 if (Q_stricmp(skinname, "icon_default") == 0) {
5081 Com_sprintf( scratch, sizeof(scratch), "%s", dirptr);
5082 } else {
5083 Com_sprintf( scratch, sizeof(scratch), "%s/%s",dirptr, skinname + 5);
5084 }
5085 dirty = 0;
5086 for(k=0;k<uiInfo.q3HeadCount;k++) {
5087 if (!Q_stricmp(scratch, uiInfo.q3HeadNames[uiInfo.q3HeadCount])) {
5088 dirty = 1;
5089 break;
5090 }
5091 }
5092 if (!dirty) {
5093 Com_sprintf( uiInfo.q3HeadNames[uiInfo.q3HeadCount], sizeof(uiInfo.q3HeadNames[uiInfo.q3HeadCount]), "%s", scratch);
5094 uiInfo.q3HeadIcons[uiInfo.q3HeadCount++] = trap_R_RegisterShaderNoMip(va("models/players/%s/%s",dirptr,skinname));
5095 }
5096 }
5097
5098 }
5099 }
5100
5101 }
5102
5103
5104
5105 /*
5106 =================
5107 UI_Init
5108 =================
5109 */
5110 void _UI_Init( qboolean inGameLoad ) {
5111 const char *menuSet;
5112 int start;
5113
5114 //uiInfo.inGameLoad = inGameLoad;
5115
5116 UI_RegisterCvars();
5117 UI_InitMemory();
5118
5119 // cache redundant calulations
5120 trap_GetGlconfig( &uiInfo.uiDC.glconfig );
5121
5122 // for 640x480 virtualized screen
5123 uiInfo.uiDC.yscale = uiInfo.uiDC.glconfig.vidHeight * (1.0/480.0);
5124 uiInfo.uiDC.xscale = uiInfo.uiDC.glconfig.vidWidth * (1.0/640.0);
5125 if ( uiInfo.uiDC.glconfig.vidWidth * 480 > uiInfo.uiDC.glconfig.vidHeight * 640 ) {
5126 // wide screen
5127 uiInfo.uiDC.bias = 0.5 * ( uiInfo.uiDC.glconfig.vidWidth - ( uiInfo.uiDC.glconfig.vidHeight * (640.0/480.0) ) );
5128 }
5129 else {
5130 // no wide screen
5131 uiInfo.uiDC.bias = 0;
5132 }
5133
5134
5135 //UI_Load();
5136 uiInfo.uiDC.registerShaderNoMip = &trap_R_RegisterShaderNoMip;
5137 uiInfo.uiDC.setColor = &UI_SetColor;
5138 uiInfo.uiDC.drawHandlePic = &UI_DrawHandlePic;
5139 uiInfo.uiDC.drawStretchPic = &trap_R_DrawStretchPic;
5140 uiInfo.uiDC.drawText = &Text_Paint;
5141 uiInfo.uiDC.textWidth = &Text_Width;
5142 uiInfo.uiDC.textHeight = &Text_Height;
5143 uiInfo.uiDC.registerModel = &trap_R_RegisterModel;
5144 uiInfo.uiDC.modelBounds = &trap_R_ModelBounds;
5145 uiInfo.uiDC.fillRect = &UI_FillRect;
5146 uiInfo.uiDC.drawRect = &_UI_DrawRect;
5147 uiInfo.uiDC.drawSides = &_UI_DrawSides;
5148 uiInfo.uiDC.drawTopBottom = &_UI_DrawTopBottom;
5149 uiInfo.uiDC.clearScene = &trap_R_ClearScene;
5150 uiInfo.uiDC.drawSides = &_UI_DrawSides;
5151 uiInfo.uiDC.addRefEntityToScene = &trap_R_AddRefEntityToScene;
5152 uiInfo.uiDC.renderScene = &trap_R_RenderScene;
5153 uiInfo.uiDC.registerFont = &trap_R_RegisterFont;
5154 uiInfo.uiDC.ownerDrawItem = &UI_OwnerDraw;
5155 uiInfo.uiDC.getValue = &UI_GetValue;
5156 uiInfo.uiDC.ownerDrawVisible = &UI_OwnerDrawVisible;
5157 uiInfo.uiDC.runScript = &UI_RunMenuScript;
5158 uiInfo.uiDC.getTeamColor = &UI_GetTeamColor;
5159 uiInfo.uiDC.setCVar = trap_Cvar_Set;
5160 uiInfo.uiDC.getCVarString = trap_Cvar_VariableStringBuffer;
5161 uiInfo.uiDC.getCVarValue = trap_Cvar_VariableValue;
5162 uiInfo.uiDC.drawTextWithCursor = &Text_PaintWithCursor;
5163 uiInfo.uiDC.setOverstrikeMode = &trap_Key_SetOverstrikeMode;
5164 uiInfo.uiDC.getOverstrikeMode = &trap_Key_GetOverstrikeMode;
5165 uiInfo.uiDC.startLocalSound = &trap_S_StartLocalSound;
5166 uiInfo.uiDC.ownerDrawHandleKey = &UI_OwnerDrawHandleKey;
5167 uiInfo.uiDC.feederCount = &UI_FeederCount;
5168 uiInfo.uiDC.feederItemImage = &UI_FeederItemImage;
5169 uiInfo.uiDC.feederItemText = &UI_FeederItemText;
5170 uiInfo.uiDC.feederSelection = &UI_FeederSelection;
5171 uiInfo.uiDC.setBinding = &trap_Key_SetBinding;
5172 uiInfo.uiDC.getBindingBuf = &trap_Key_GetBindingBuf;
5173 uiInfo.uiDC.keynumToStringBuf = &trap_Key_KeynumToStringBuf;
5174 uiInfo.uiDC.executeText = &trap_Cmd_ExecuteText;
5175 uiInfo.uiDC.Error = &Com_Error;
5176 uiInfo.uiDC.Print = &Com_Printf;
5177 uiInfo.uiDC.Pause = &UI_Pause;
5178 uiInfo.uiDC.ownerDrawWidth = &UI_OwnerDrawWidth;
5179 uiInfo.uiDC.registerSound = &trap_S_RegisterSound;
5180 uiInfo.uiDC.startBackgroundTrack = &trap_S_StartBackgroundTrack;
5181 uiInfo.uiDC.stopBackgroundTrack = &trap_S_StopBackgroundTrack;
5182 uiInfo.uiDC.playCinematic = &UI_PlayCinematic;
5183 uiInfo.uiDC.stopCinematic = &UI_StopCinematic;
5184 uiInfo.uiDC.drawCinematic = &UI_DrawCinematic;
5185 uiInfo.uiDC.runCinematicFrame = &UI_RunCinematicFrame;
5186
5187 Init_Display(&uiInfo.uiDC);
5188
5189 String_Init();
5190
5191 uiInfo.uiDC.cursor = trap_R_RegisterShaderNoMip( "menu/art/3_cursor2" );
5192 uiInfo.uiDC.whiteShader = trap_R_RegisterShaderNoMip( "white" );
5193
5194 AssetCache();
5195
5196 start = trap_Milliseconds();
5197
5198 uiInfo.teamCount = 0;
5199 uiInfo.characterCount = 0;
5200 uiInfo.aliasCount = 0;
5201
5202 #ifdef PRE_RELEASE_TADEMO
5203 UI_ParseTeamInfo("demoteaminfo.txt");
5204 UI_ParseGameInfo("demogameinfo.txt");
5205 #else
5206 UI_ParseTeamInfo("teaminfo.txt");
5207 UI_LoadTeams();
5208 UI_ParseGameInfo("gameinfo.txt");
5209 #endif
5210
5211 menuSet = UI_Cvar_VariableString("ui_menuFiles");
5212 if (menuSet == NULL || menuSet[0] == '\0') {
5213 menuSet = "ui/menus.txt";
5214 }
5215
5216 #if 0
5217 if (uiInfo.inGameLoad) {
5218 UI_LoadMenus("ui/ingame.txt", qtrue);
5219 } else { // bk010222: left this: UI_LoadMenus(menuSet, qtrue);
5220 }
5221 #else
5222 UI_LoadMenus(menuSet, qtrue);
5223 UI_LoadMenus("ui/ingame.txt", qfalse);
5224 #endif
5225
5226 Menus_CloseAll();
5227
5228 trap_LAN_LoadCachedServers();
5229 UI_LoadBestScores(uiInfo.mapList[ui_currentMap.integer].mapLoadName, uiInfo.gameTypes[ui_gameType.integer].gtEnum);
5230
5231 UI_BuildQ3Model_List();
5232 UI_LoadBots();
5233
5234 // sets defaults for ui temp cvars
5235 uiInfo.effectsColor = gamecodetoui[(int)trap_Cvar_VariableValue("color1")-1];
5236 uiInfo.currentCrosshair = (int)trap_Cvar_VariableValue("cg_drawCrosshair");
5237 trap_Cvar_Set("ui_mousePitch", (trap_Cvar_VariableValue("m_pitch") >= 0) ? "0" : "1");
5238
5239 uiInfo.serverStatus.currentServerCinematic = -1;
5240 uiInfo.previewMovie = -1;
5241
5242 if (trap_Cvar_VariableValue("ui_TeamArenaFirstRun") == 0) {
5243 trap_Cvar_Set("s_volume", "0.8");
5244 trap_Cvar_Set("s_musicvolume", "0.5");
5245 trap_Cvar_Set("ui_TeamArenaFirstRun", "1");
5246 }
5247
5248 trap_Cvar_Register(NULL, "debug_protocol", "", 0 );
5249
5250 trap_Cvar_Set("ui_actualNetGameType", va("%d", ui_netGameType.integer));
5251 }
5252
5253
5254 /*
5255 =================
5256 UI_KeyEvent
5257 =================
5258 */
5259 void _UI_KeyEvent( int key, qboolean down ) {
5260
5261 if (Menu_Count() > 0) {
5262 menuDef_t *menu = Menu_GetFocused();
5263 if (menu) {
5264 if (key == K_ESCAPE && down && !Menus_AnyFullScreenVisible()) {
5265 Menus_CloseAll();
5266 } else {
5267 Menu_HandleKey(menu, key, down );
5268 }
5269 } else {
5270 trap_Key_SetCatcher( trap_Key_GetCatcher() & ~KEYCATCH_UI );
5271 trap_Key_ClearStates();
5272 trap_Cvar_Set( "cl_paused", "0" );
5273 }
5274 }
5275
5276 //if ((s > 0) && (s != menu_null_sound)) {
5277 // trap_S_StartLocalSound( s, CHAN_LOCAL_SOUND );
5278 //}
5279 }
5280
5281 /*
5282 =================
5283 UI_MouseEvent
5284 =================
5285 */
5286 void _UI_MouseEvent( int dx, int dy )
5287 {
5288 // update mouse screen position
5289 uiInfo.uiDC.cursorx += dx;
5290 if (uiInfo.uiDC.cursorx < 0)
5291 uiInfo.uiDC.cursorx = 0;
5292 else if (uiInfo.uiDC.cursorx > SCREEN_WIDTH)
5293 uiInfo.uiDC.cursorx = SCREEN_WIDTH;
5294
5295 uiInfo.uiDC.cursory += dy;
5296 if (uiInfo.uiDC.cursory < 0)
5297 uiInfo.uiDC.cursory = 0;
5298 else if (uiInfo.uiDC.cursory > SCREEN_HEIGHT)
5299 uiInfo.uiDC.cursory = SCREEN_HEIGHT;
5300
5301 if (Menu_Count() > 0) {
5302 //menuDef_t *menu = Menu_GetFocused();
5303 //Menu_HandleMouseMove(menu, uiInfo.uiDC.cursorx, uiInfo.uiDC.cursory);
5304 Display_MouseMove(NULL, uiInfo.uiDC.cursorx, uiInfo.uiDC.cursory);
5305 }
5306
5307 }
5308
5309 void UI_LoadNonIngame( void ) {
5310 const char *menuSet = UI_Cvar_VariableString("ui_menuFiles");
5311 if (menuSet == NULL || menuSet[0] == '\0') {
5312 menuSet = "ui/menus.txt";
5313 }
5314 UI_LoadMenus(menuSet, qfalse);
5315 uiInfo.inGameLoad = qfalse;
5316 }
5317
5318 void _UI_SetActiveMenu( uiMenuCommand_t menu ) {
5319 char buf[256];
5320
5321 // this should be the ONLY way the menu system is brought up
5322 // enusure minumum menu data is cached
5323 if (Menu_Count() > 0) {
5324 vec3_t v;
5325 v[0] = v[1] = v[2] = 0;
5326 switch ( menu ) {
5327 case UIMENU_NONE:
5328 trap_Key_SetCatcher( trap_Key_GetCatcher() & ~KEYCATCH_UI );
5329 trap_Key_ClearStates();
5330 trap_Cvar_Set( "cl_paused", "0" );
5331 Menus_CloseAll();
5332
5333 return;
5334 case UIMENU_MAIN:
5335 trap_Cvar_Set( "sv_killserver", "1" );
5336 trap_Key_SetCatcher( KEYCATCH_UI );
5337 //trap_S_StartLocalSound( trap_S_RegisterSound("sound/misc/menu_background.wav", qfalse) , CHAN_LOCAL_SOUND );
5338 //trap_S_StartBackgroundTrack("sound/misc/menu_background.wav", NULL);
5339 if (uiInfo.inGameLoad) {
5340 UI_LoadNonIngame();
5341 }
5342 Menus_CloseAll();
5343 Menus_ActivateByName("main");
5344 trap_Cvar_VariableStringBuffer("com_errorMessage", buf, sizeof(buf));
5345 if (strlen(buf)) {
5346 if (!ui_singlePlayerActive.integer) {
5347 Menus_ActivateByName("error_popmenu");
5348 } else {
5349 trap_Cvar_Set("com_errorMessage", "");
5350 }
5351 }
5352 return;
5353 case UIMENU_TEAM:
5354 trap_Key_SetCatcher( KEYCATCH_UI );
5355 Menus_ActivateByName("team");
5356 return;
5357 case UIMENU_NEED_CD:
5358 // no cd check in TA
5359 //trap_Key_SetCatcher( KEYCATCH_UI );
5360 //Menus_ActivateByName("needcd");
5361 //UI_ConfirmMenu( "Insert the CD", NULL, NeedCDAction );
5362 return;
5363 case UIMENU_BAD_CD_KEY:
5364 // no cd check in TA
5365 //trap_Key_SetCatcher( KEYCATCH_UI );
5366 //Menus_ActivateByName("badcd");
5367 //UI_ConfirmMenu( "Bad CD Key", NULL, NeedCDKeyAction );
5368 return;
5369 case UIMENU_POSTGAME:
5370 trap_Cvar_Set( "sv_killserver", "1" );
5371 trap_Key_SetCatcher( KEYCATCH_UI );
5372 if (uiInfo.inGameLoad) {
5373 UI_LoadNonIngame();
5374 }
5375 Menus_CloseAll();
5376 Menus_ActivateByName("endofgame");
5377 //UI_ConfirmMenu( "Bad CD Key", NULL, NeedCDKeyAction );
5378 return;
5379 case UIMENU_INGAME:
5380 trap_Cvar_Set( "cl_paused", "1" );
5381 trap_Key_SetCatcher( KEYCATCH_UI );
5382 UI_BuildPlayerList();
5383 Menus_CloseAll();
5384 Menus_ActivateByName("ingame");
5385 return;
5386 }
5387 }
5388 }
5389
5390 qboolean _UI_IsFullscreen( void ) {
5391 return Menus_AnyFullScreenVisible();
5392 }
5393
5394
5395
5396 static connstate_t lastConnState;
5397 static char lastLoadingText[MAX_INFO_VALUE];
5398
5399 static void UI_ReadableSize ( char *buf, int bufsize, int value )
5400 {
5401 if (value > 1024*1024*1024 ) { // gigs
5402 Com_sprintf( buf, bufsize, "%d", value / (1024*1024*1024) );
5403 Com_sprintf( buf+strlen(buf), bufsize-strlen(buf), ".%02d GB",
5404 (value % (1024*1024*1024))*100 / (1024*1024*1024) );
5405 } else if (value > 1024*1024 ) { // megs
5406 Com_sprintf( buf, bufsize, "%d", value / (1024*1024) );
5407 Com_sprintf( buf+strlen(buf), bufsize-strlen(buf), ".%02d MB",
5408 (value % (1024*1024))*100 / (1024*1024) );
5409 } else if (value > 1024 ) { // kilos
5410 Com_sprintf( buf, bufsize, "%d KB", value / 1024 );
5411 } else { // bytes
5412 Com_sprintf( buf, bufsize, "%d bytes", value );
5413 }
5414 }
5415
5416 // Assumes time is in msec
5417 static void UI_PrintTime ( char *buf, int bufsize, int time ) {
5418 time /= 1000; // change to seconds
5419
5420 if (time > 3600) { // in the hours range
5421 Com_sprintf( buf, bufsize, "%d hr %d min", time / 3600, (time % 3600) / 60 );
5422 } else if (time > 60) { // mins
5423 Com_sprintf( buf, bufsize, "%d min %d sec", time / 60, time % 60 );
5424 } else { // secs
5425 Com_sprintf( buf, bufsize, "%d sec", time );
5426 }
5427 }
5428
5429 void Text_PaintCenter(float x, float y, float scale, vec4_t color, const char *text, float adjust) {
5430 int len = Text_Width(text, scale, 0);
5431 Text_Paint(x - len / 2, y, scale, color, text, 0, 0, ITEM_TEXTSTYLE_SHADOWEDMORE);
5432 }
5433
5434 void Text_PaintCenter_AutoWrapped(float x, float y, float xmax, float ystep, float scale, vec4_t color, const char *str, float adjust) {
5435 int width;
5436 char *s1,*s2,*s3;
5437 char c_bcp;
5438 char buf[1024];
5439
5440 if (!str || str[0]=='\0')
5441 return;
5442
5443 Q_strncpyz(buf, str, sizeof(buf));
5444 s1 = s2 = s3 = buf;
5445
5446 while (1) {
5447 do {
5448 s3++;
5449 } while (*s3!=' ' && *s3!='\0');
5450 c_bcp = *s3;
5451 *s3 = '\0';
5452 width = Text_Width(s1, scale, 0);
5453 *s3 = c_bcp;
5454 if (width > xmax) {
5455 if (s1==s2)
5456 {
5457 // fuck, don't have a clean cut, we'll overflow
5458 s2 = s3;
5459 }
5460 *s2 = '\0';
5461 Text_PaintCenter(x, y, scale, color, s1, adjust);
5462 y += ystep;
5463 if (c_bcp == '\0')
5464 {
5465 // that was the last word
5466 // we could start a new loop, but that wouldn't be much use
5467 // even if the word is too long, we would overflow it (see above)
5468 // so just print it now if needed
5469 s2++;
5470 if (*s2 != '\0') // if we are printing an overflowing line we have s2 == s3
5471 Text_PaintCenter(x, y, scale, color, s2, adjust);
5472 break;
5473 }
5474 s2++;
5475 s1 = s2;
5476 s3 = s2;
5477 }
5478 else
5479 {
5480 s2 = s3;
5481 if (c_bcp == '\0') // we reached the end
5482 {
5483 Text_PaintCenter(x, y, scale, color, s1, adjust);
5484 break;
5485 }
5486 }
5487 }
5488 }
5489
5490 static void UI_DisplayDownloadInfo( const char *downloadName, float centerPoint, float yStart, float scale ) {
5491 static char dlText[] = "Downloading:";
5492 static char etaText[] = "Estimated time left:";
5493 static char xferText[] = "Transfer rate:";
5494
5495 int downloadSize, downloadCount, downloadTime;
5496 char dlSizeBuf[64], totalSizeBuf[64], xferRateBuf[64], dlTimeBuf[64];
5497 int xferRate;
5498 int leftWidth;
5499 const char *s;
5500
5501 downloadSize = trap_Cvar_VariableValue( "cl_downloadSize" );
5502 downloadCount = trap_Cvar_VariableValue( "cl_downloadCount" );
5503 downloadTime = trap_Cvar_VariableValue( "cl_downloadTime" );
5504
5505 leftWidth = 320;
5506
5507 UI_SetColor(colorWhite);
5508 Text_PaintCenter(centerPoint, yStart + 112, scale, colorWhite, dlText, 0);
5509 Text_PaintCenter(centerPoint, yStart + 192, scale, colorWhite, etaText, 0);
5510 Text_PaintCenter(centerPoint, yStart + 248, scale, colorWhite, xferText, 0);
5511
5512 if (downloadSize > 0) {
5513 s = va( "%s (%d%%)", downloadName,
5514 (int)( (float)downloadCount * 100.0f / downloadSize ) );
5515 } else {
5516 s = downloadName;
5517 }
5518
5519 Text_PaintCenter(centerPoint, yStart+136, scale, colorWhite, s, 0);
5520
5521 UI_ReadableSize( dlSizeBuf, sizeof dlSizeBuf, downloadCount );
5522 UI_ReadableSize( totalSizeBuf, sizeof totalSizeBuf, downloadSize );
5523
5524 if (downloadCount < 4096 || !downloadTime) {
5525 Text_PaintCenter(leftWidth, yStart+216, scale, colorWhite, "estimating", 0);
5526 Text_PaintCenter(leftWidth, yStart+160, scale, colorWhite, va("(%s of %s copied)", dlSizeBuf, totalSizeBuf), 0);
5527 } else {
5528 if ((uiInfo.uiDC.realTime - downloadTime) / 1000) {
5529 xferRate = downloadCount / ((uiInfo.uiDC.realTime - downloadTime) / 1000);
5530 } else {
5531 xferRate = 0;
5532 }
5533 UI_ReadableSize( xferRateBuf, sizeof xferRateBuf, xferRate );
5534
5535 // Extrapolate estimated completion time
5536 if (downloadSize && xferRate) {
5537 int n = downloadSize / xferRate; // estimated time for entire d/l in secs
5538
5539 // We do it in K (/1024) because we'd overflow around 4MB
5540 UI_PrintTime ( dlTimeBuf, sizeof dlTimeBuf,
5541 (n - (((downloadCount/1024) * n) / (downloadSize/1024))) * 1000);
5542
5543 Text_PaintCenter(leftWidth, yStart+216, scale, colorWhite, dlTimeBuf, 0);
5544 Text_PaintCenter(leftWidth, yStart+160, scale, colorWhite, va("(%s of %s copied)", dlSizeBuf, totalSizeBuf), 0);
5545 } else {
5546 Text_PaintCenter(leftWidth, yStart+216, scale, colorWhite, "estimating", 0);
5547 if (downloadSize) {
5548 Text_PaintCenter(leftWidth, yStart+160, scale, colorWhite, va("(%s of %s copied)", dlSizeBuf, totalSizeBuf), 0);
5549 } else {
5550 Text_PaintCenter(leftWidth, yStart+160, scale, colorWhite, va("(%s copied)", dlSizeBuf), 0);
5551 }
5552 }
5553
5554 if (xferRate) {
5555 Text_PaintCenter(leftWidth, yStart+272, scale, colorWhite, va("%s/Sec", xferRateBuf), 0);
5556 }
5557 }
5558 }
5559
5560 /*
5561 ========================
5562 UI_DrawConnectScreen
5563
5564 This will also be overlaid on the cgame info screen during loading
5565 to prevent it from blinking away too rapidly on local or lan games.
5566 ========================
5567 */
5568 void UI_DrawConnectScreen( qboolean overlay ) {
5569 char *s;
5570 uiClientState_t cstate;
5571 char info[MAX_INFO_VALUE];
5572 char text[256];
5573 float centerPoint, yStart, scale;
5574
5575 menuDef_t *menu = Menus_FindByName("Connect");
5576
5577
5578 if ( !overlay && menu ) {
5579 Menu_Paint(menu, qtrue);
5580 }
5581
5582 if (!overlay) {
5583 centerPoint = 320;
5584 yStart = 130;
5585 scale = 0.5f;
5586 } else {
5587 centerPoint = 320;
5588 yStart = 32;
5589 scale = 0.6f;
5590 return;
5591 }
5592
5593 // see what information we should display
5594 trap_GetClientState( &cstate );
5595
5596 info[0] = '\0';
5597 if( trap_GetConfigString( CS_SERVERINFO, info, sizeof(info) ) ) {
5598 Text_PaintCenter(centerPoint, yStart, scale, colorWhite, va( "Loading %s", Info_ValueForKey( info, "mapname" )), 0);
5599 }
5600
5601 if (!Q_stricmp(cstate.servername,"localhost")) {
5602 Text_PaintCenter(centerPoint, yStart + 48, scale, colorWhite, va("Starting up..."), ITEM_TEXTSTYLE_SHADOWEDMORE);
5603 } else {
5604 strcpy(text, va("Connecting to %s", cstate.servername));
5605 Text_PaintCenter(centerPoint, yStart + 48, scale, colorWhite,text , ITEM_TEXTSTYLE_SHADOWEDMORE);
5606 }
5607
5608 // display global MOTD at bottom
5609 Text_PaintCenter(centerPoint, 600, scale, colorWhite, Info_ValueForKey( cstate.updateInfoString, "motd" ), 0);
5610 // print any server info (server full, bad version, etc)
5611 if ( cstate.connState < CA_CONNECTED ) {
5612 Text_PaintCenter_AutoWrapped(centerPoint, yStart + 176, 630, 20, scale, colorWhite, cstate.messageString, 0);
5613 }
5614
5615 if ( lastConnState > cstate.connState ) {
5616 lastLoadingText[0] = '\0';
5617 }
5618 lastConnState = cstate.connState;
5619
5620 switch ( cstate.connState ) {
5621 case CA_CONNECTING:
5622 s = va("Awaiting connection...%i", cstate.connectPacketCount);
5623 break;
5624 case CA_CHALLENGING:
5625 s = va("Awaiting challenge...%i", cstate.connectPacketCount);
5626 break;
5627 case CA_CONNECTED: {
5628 char downloadName[MAX_INFO_VALUE];
5629
5630 trap_Cvar_VariableStringBuffer( "cl_downloadName", downloadName, sizeof(downloadName) );
5631 if (*downloadName) {
5632 UI_DisplayDownloadInfo( downloadName, centerPoint, yStart, scale );
5633 return;
5634 }
5635 }
5636 s = "Awaiting gamestate...";
5637 break;
5638 case CA_LOADING:
5639 return;
5640 case CA_PRIMED:
5641 return;
5642 default:
5643 return;
5644 }
5645
5646
5647 if (Q_stricmp(cstate.servername,"localhost")) {
5648 Text_PaintCenter(centerPoint, yStart + 80, scale, colorWhite, s, 0);
5649 }
5650
5651 // password required / connection rejected information goes here
5652 }
5653
5654
5655 /*
5656 ================
5657 cvars
5658 ================
5659 */
5660
5661 typedef struct {
5662 vmCvar_t *vmCvar;
5663 char *cvarName;
5664 char *defaultString;
5665 int cvarFlags;
5666 } cvarTable_t;
5667
5668 vmCvar_t ui_ffa_fraglimit;
5669 vmCvar_t ui_ffa_timelimit;
5670
5671 vmCvar_t ui_tourney_fraglimit;
5672 vmCvar_t ui_tourney_timelimit;
5673
5674 vmCvar_t ui_team_fraglimit;
5675 vmCvar_t ui_team_timelimit;
5676 vmCvar_t ui_team_friendly;
5677
5678 vmCvar_t ui_ctf_capturelimit;
5679 vmCvar_t ui_ctf_timelimit;
5680 vmCvar_t ui_ctf_friendly;
5681
5682 vmCvar_t ui_arenasFile;
5683 vmCvar_t ui_botsFile;
5684 vmCvar_t ui_spScores1;
5685 vmCvar_t ui_spScores2;
5686 vmCvar_t ui_spScores3;
5687 vmCvar_t ui_spScores4;
5688 vmCvar_t ui_spScores5;
5689 vmCvar_t ui_spAwards;
5690 vmCvar_t ui_spVideos;
5691 vmCvar_t ui_spSkill;
5692
5693 vmCvar_t ui_spSelection;
5694
5695 vmCvar_t ui_browserMaster;
5696 vmCvar_t ui_browserGameType;
5697 vmCvar_t ui_browserSortKey;
5698 vmCvar_t ui_browserShowFull;
5699 vmCvar_t ui_browserShowEmpty;
5700
5701 vmCvar_t ui_brassTime;
5702 vmCvar_t ui_drawCrosshair;
5703 vmCvar_t ui_drawCrosshairNames;
5704 vmCvar_t ui_marks;
5705
5706 vmCvar_t ui_server1;
5707 vmCvar_t ui_server2;
5708 vmCvar_t ui_server3;
5709 vmCvar_t ui_server4;
5710 vmCvar_t ui_server5;
5711 vmCvar_t ui_server6;
5712 vmCvar_t ui_server7;
5713 vmCvar_t ui_server8;
5714 vmCvar_t ui_server9;
5715 vmCvar_t ui_server10;
5716 vmCvar_t ui_server11;
5717 vmCvar_t ui_server12;
5718 vmCvar_t ui_server13;
5719 vmCvar_t ui_server14;
5720 vmCvar_t ui_server15;
5721 vmCvar_t ui_server16;
5722
5723 vmCvar_t ui_cdkeychecked;
5724
5725 vmCvar_t ui_redteam;
5726 vmCvar_t ui_redteam1;
5727 vmCvar_t ui_redteam2;
5728 vmCvar_t ui_redteam3;
5729 vmCvar_t ui_redteam4;
5730 vmCvar_t ui_redteam5;
5731 vmCvar_t ui_blueteam;
5732 vmCvar_t ui_blueteam1;
5733 vmCvar_t ui_blueteam2;
5734 vmCvar_t ui_blueteam3;
5735 vmCvar_t ui_blueteam4;
5736 vmCvar_t ui_blueteam5;
5737 vmCvar_t ui_teamName;
5738 vmCvar_t ui_dedicated;
5739 vmCvar_t ui_gameType;
5740 vmCvar_t ui_netGameType;
5741 vmCvar_t ui_actualNetGameType;
5742 vmCvar_t ui_joinGameType;
5743 vmCvar_t ui_netSource;
5744 vmCvar_t ui_serverFilterType;
5745 vmCvar_t ui_opponentName;
5746 vmCvar_t ui_menuFiles;
5747 vmCvar_t ui_currentTier;
5748 vmCvar_t ui_currentMap;
5749 vmCvar_t ui_currentNetMap;
5750 vmCvar_t ui_mapIndex;
5751 vmCvar_t ui_currentOpponent;
5752 vmCvar_t ui_selectedPlayer;
5753 vmCvar_t ui_selectedPlayerName;
5754 vmCvar_t ui_lastServerRefresh_0;
5755 vmCvar_t ui_lastServerRefresh_1;
5756 vmCvar_t ui_lastServerRefresh_2;
5757 vmCvar_t ui_lastServerRefresh_3;
5758 vmCvar_t ui_singlePlayerActive;
5759 vmCvar_t ui_scoreAccuracy;
5760 vmCvar_t ui_scoreImpressives;
5761 vmCvar_t ui_scoreExcellents;
5762 vmCvar_t ui_scoreCaptures;
5763 vmCvar_t ui_scoreDefends;
5764 vmCvar_t ui_scoreAssists;
5765 vmCvar_t ui_scoreGauntlets;
5766 vmCvar_t ui_scoreScore;
5767 vmCvar_t ui_scorePerfect;
5768 vmCvar_t ui_scoreTeam;
5769 vmCvar_t ui_scoreBase;
5770 vmCvar_t ui_scoreTimeBonus;
5771 vmCvar_t ui_scoreSkillBonus;
5772 vmCvar_t ui_scoreShutoutBonus;
5773 vmCvar_t ui_scoreTime;
5774 vmCvar_t ui_captureLimit;
5775 vmCvar_t ui_fragLimit;
5776 vmCvar_t ui_smallFont;
5777 vmCvar_t ui_bigFont;
5778 vmCvar_t ui_findPlayer;
5779 vmCvar_t ui_Q3Model;
5780 vmCvar_t ui_hudFiles;
5781 vmCvar_t ui_recordSPDemo;
5782 vmCvar_t ui_realCaptureLimit;
5783 vmCvar_t ui_realWarmUp;
5784 vmCvar_t ui_serverStatusTimeOut;
5785
5786 vmCvar_t ui_humansonly;
5787
5788
5789 // bk001129 - made static to avoid aliasing
5790 static cvarTable_t cvarTable[] = {
5791 { &ui_ffa_fraglimit, "ui_ffa_fraglimit", "20", CVAR_ARCHIVE },
5792 { &ui_ffa_timelimit, "ui_ffa_timelimit", "0", CVAR_ARCHIVE },
5793
5794 { &ui_tourney_fraglimit, "ui_tourney_fraglimit", "0", CVAR_ARCHIVE },
5795 { &ui_tourney_timelimit, "ui_tourney_timelimit", "15", CVAR_ARCHIVE },
5796
5797 { &ui_team_fraglimit, "ui_team_fraglimit", "0", CVAR_ARCHIVE },
5798 { &ui_team_timelimit, "ui_team_timelimit", "20", CVAR_ARCHIVE },
5799 { &ui_team_friendly, "ui_team_friendly", "1", CVAR_ARCHIVE },
5800
5801 { &ui_ctf_capturelimit, "ui_ctf_capturelimit", "8", CVAR_ARCHIVE },
5802 { &ui_ctf_timelimit, "ui_ctf_timelimit", "30", CVAR_ARCHIVE },
5803 { &ui_ctf_friendly, "ui_ctf_friendly", "0", CVAR_ARCHIVE },
5804
5805 { &ui_arenasFile, "g_arenasFile", "", CVAR_INIT|CVAR_ROM },
5806 { &ui_botsFile, "g_botsFile", "", CVAR_INIT|CVAR_ROM },
5807 { &ui_spScores1, "g_spScores1", "", CVAR_ARCHIVE | CVAR_ROM },
5808 { &ui_spScores2, "g_spScores2", "", CVAR_ARCHIVE | CVAR_ROM },
5809 { &ui_spScores3, "g_spScores3", "", CVAR_ARCHIVE | CVAR_ROM },
5810 { &ui_spScores4, "g_spScores4", "", CVAR_ARCHIVE | CVAR_ROM },
5811 { &ui_spScores5, "g_spScores5", "", CVAR_ARCHIVE | CVAR_ROM },
5812 { &ui_spAwards, "g_spAwards", "", CVAR_ARCHIVE | CVAR_ROM },
5813 { &ui_spVideos, "g_spVideos", "", CVAR_ARCHIVE | CVAR_ROM },
5814 { &ui_spSkill, "g_spSkill", "2", CVAR_ARCHIVE },
5815
5816 { &ui_spSelection, "ui_spSelection", "", CVAR_ROM },
5817
5818 { &ui_browserMaster, "ui_browserMaster", "0", CVAR_ARCHIVE },
5819 { &ui_browserGameType, "ui_browserGameType", "0", CVAR_ARCHIVE },
5820 { &ui_browserSortKey, "ui_browserSortKey", "4", CVAR_ARCHIVE },
5821 { &ui_browserShowFull, "ui_browserShowFull", "1", CVAR_ARCHIVE },
5822 { &ui_browserShowEmpty, "ui_browserShowEmpty", "1", CVAR_ARCHIVE },
5823
5824 { &ui_brassTime, "cg_brassTime", "2500", CVAR_ARCHIVE },
5825 { &ui_drawCrosshair, "cg_drawCrosshair", "4", CVAR_ARCHIVE },
5826 { &ui_drawCrosshairNames, "cg_drawCrosshairNames", "1", CVAR_ARCHIVE },
5827 { &ui_marks, "cg_marks", "1", CVAR_ARCHIVE },
5828
5829 { &ui_server1, "server1", "", CVAR_ARCHIVE },
5830 { &ui_server2, "server2", "", CVAR_ARCHIVE },
5831 { &ui_server3, "server3", "", CVAR_ARCHIVE },
5832 { &ui_server4, "server4", "", CVAR_ARCHIVE },
5833 { &ui_server5, "server5", "", CVAR_ARCHIVE },
5834 { &ui_server6, "server6", "", CVAR_ARCHIVE },
5835 { &ui_server7, "server7", "", CVAR_ARCHIVE },
5836 { &ui_server8, "server8", "", CVAR_ARCHIVE },
5837 { &ui_server9, "server9", "", CVAR_ARCHIVE },
5838 { &ui_server10, "server10", "", CVAR_ARCHIVE },
5839 { &ui_server11, "server11", "", CVAR_ARCHIVE },
5840 { &ui_server12, "server12", "", CVAR_ARCHIVE },
5841 { &ui_server13, "server13", "", CVAR_ARCHIVE },
5842 { &ui_server14, "server14", "", CVAR_ARCHIVE },
5843 { &ui_server15, "server15", "", CVAR_ARCHIVE },
5844 { &ui_server16, "server16", "", CVAR_ARCHIVE },
5845 { &ui_cdkeychecked, "ui_cdkeychecked", "0", CVAR_ROM },
5846 { &ui_new, "ui_new", "0", CVAR_TEMP },
5847 { &ui_debug, "ui_debug", "0", CVAR_TEMP },
5848 { &ui_initialized, "ui_initialized", "0", CVAR_TEMP },
5849 { &ui_teamName, "ui_teamName", "Pagans", CVAR_ARCHIVE },
5850 { &ui_opponentName, "ui_opponentName", "Stroggs", CVAR_ARCHIVE },
5851 { &ui_redteam, "ui_redteam", "Pagans", CVAR_ARCHIVE },
5852 { &ui_blueteam, "ui_blueteam", "Stroggs", CVAR_ARCHIVE },
5853 { &ui_dedicated, "ui_dedicated", "0", CVAR_ARCHIVE },
5854 { &ui_gameType, "ui_gametype", "3", CVAR_ARCHIVE },
5855 { &ui_joinGameType, "ui_joinGametype", "0", CVAR_ARCHIVE },
5856 { &ui_netGameType, "ui_netGametype", "3", CVAR_ARCHIVE },
5857 { &ui_actualNetGameType, "ui_actualNetGametype", "3", CVAR_ARCHIVE },
5858 { &ui_redteam1, "ui_redteam1", "0", CVAR_ARCHIVE },
5859 { &ui_redteam2, "ui_redteam2", "0", CVAR_ARCHIVE },
5860 { &ui_redteam3, "ui_redteam3", "0", CVAR_ARCHIVE },
5861 { &ui_redteam4, "ui_redteam4", "0", CVAR_ARCHIVE },
5862 { &ui_redteam5, "ui_redteam5", "0", CVAR_ARCHIVE },
5863 { &ui_blueteam1, "ui_blueteam1", "0", CVAR_ARCHIVE },
5864 { &ui_blueteam2, "ui_blueteam2", "0", CVAR_ARCHIVE },
5865 { &ui_blueteam3, "ui_blueteam3", "0", CVAR_ARCHIVE },
5866 { &ui_blueteam4, "ui_blueteam4", "0", CVAR_ARCHIVE },
5867 { &ui_blueteam5, "ui_blueteam5", "0", CVAR_ARCHIVE },
5868 { &ui_netSource, "ui_netSource", "0", CVAR_ARCHIVE },
5869 { &ui_menuFiles, "ui_menuFiles", "ui/menus.txt", CVAR_ARCHIVE },
5870 { &ui_currentTier, "ui_currentTier", "0", CVAR_ARCHIVE },
5871 { &ui_currentMap, "ui_currentMap", "0", CVAR_ARCHIVE },
5872 { &ui_currentNetMap, "ui_currentNetMap", "0", CVAR_ARCHIVE },
5873 { &ui_mapIndex, "ui_mapIndex", "0", CVAR_ARCHIVE },
5874 { &ui_currentOpponent, "ui_currentOpponent", "0", CVAR_ARCHIVE },
5875 { &ui_selectedPlayer, "cg_selectedPlayer", "0", CVAR_ARCHIVE},
5876 { &ui_selectedPlayerName, "cg_selectedPlayerName", "", CVAR_ARCHIVE},
5877 { &ui_lastServerRefresh_0, "ui_lastServerRefresh_0", "", CVAR_ARCHIVE},
5878 { &ui_lastServerRefresh_1, "ui_lastServerRefresh_1", "", CVAR_ARCHIVE},
5879 { &ui_lastServerRefresh_2, "ui_lastServerRefresh_2", "", CVAR_ARCHIVE},
5880 { &ui_lastServerRefresh_3, "ui_lastServerRefresh_3", "", CVAR_ARCHIVE},
5881 { &ui_singlePlayerActive, "ui_singlePlayerActive", "0", 0},
5882 { &ui_scoreAccuracy, "ui_scoreAccuracy", "0", CVAR_ARCHIVE},
5883 { &ui_scoreImpressives, "ui_scoreImpressives", "0", CVAR_ARCHIVE},
5884 { &ui_scoreExcellents, "ui_scoreExcellents", "0", CVAR_ARCHIVE},
5885 { &ui_scoreCaptures, "ui_scoreCaptures", "0", CVAR_ARCHIVE},
5886 { &ui_scoreDefends, "ui_scoreDefends", "0", CVAR_ARCHIVE},
5887 { &ui_scoreAssists, "ui_scoreAssists", "0", CVAR_ARCHIVE},
5888 { &ui_scoreGauntlets, "ui_scoreGauntlets", "0",CVAR_ARCHIVE},
5889 { &ui_scoreScore, "ui_scoreScore", "0", CVAR_ARCHIVE},
5890 { &ui_scorePerfect, "ui_scorePerfect", "0", CVAR_ARCHIVE},
5891 { &ui_scoreTeam, "ui_scoreTeam", "0 to 0", CVAR_ARCHIVE},
5892 { &ui_scoreBase, "ui_scoreBase", "0", CVAR_ARCHIVE},
5893 { &ui_scoreTime, "ui_scoreTime", "00:00", CVAR_ARCHIVE},
5894 { &ui_scoreTimeBonus, "ui_scoreTimeBonus", "0", CVAR_ARCHIVE},
5895 { &ui_scoreSkillBonus, "ui_scoreSkillBonus", "0", CVAR_ARCHIVE},
5896 { &ui_scoreShutoutBonus, "ui_scoreShutoutBonus", "0", CVAR_ARCHIVE},
5897 { &ui_fragLimit, "ui_fragLimit", "10", 0},
5898 { &ui_captureLimit, "ui_captureLimit", "5", 0},
5899 { &ui_smallFont, "ui_smallFont", "0.25", CVAR_ARCHIVE},
5900 { &ui_bigFont, "ui_bigFont", "0.4", CVAR_ARCHIVE},
5901 { &ui_findPlayer, "ui_findPlayer", "Sarge", CVAR_ARCHIVE},
5902 { &ui_Q3Model, "ui_q3model", "0", CVAR_ARCHIVE},
5903 { &ui_hudFiles, "cg_hudFiles", "ui/hud.txt", CVAR_ARCHIVE},
5904 { &ui_recordSPDemo, "ui_recordSPDemo", "0", CVAR_ARCHIVE},
5905 { &ui_teamArenaFirstRun, "ui_teamArenaFirstRun", "0", CVAR_ARCHIVE},
5906 { &ui_realWarmUp, "g_warmup", "20", CVAR_ARCHIVE},
5907 { &ui_realCaptureLimit, "capturelimit", "8", CVAR_SERVERINFO | CVAR_ARCHIVE | CVAR_NORESTART},
5908 { &ui_serverStatusTimeOut, "ui_serverStatusTimeOut", "7000", CVAR_ARCHIVE},
5909 { &ui_humansonly, "ui_humansonly", "0", CVAR_ARCHIVE},
5910 };
5911
5912 // bk001129 - made static to avoid aliasing
5913 static int cvarTableSize = sizeof(cvarTable) / sizeof(cvarTable[0]);
5914
5915
5916 /*
5917 =================
5918 UI_RegisterCvars
5919 =================
5920 */
5921 void UI_RegisterCvars( void ) {
5922 int i;
5923 cvarTable_t *cv;
5924
5925 for ( i = 0, cv = cvarTable ; i < cvarTableSize ; i++, cv++ ) {
5926 trap_Cvar_Register( cv->vmCvar, cv->cvarName, cv->defaultString, cv->cvarFlags );
5927 }
5928 }
5929
5930 /*
5931 =================
5932 UI_UpdateCvars
5933 =================
5934 */
5935 void UI_UpdateCvars( void ) {
5936 int i;
5937 cvarTable_t *cv;
5938
5939 for ( i = 0, cv = cvarTable ; i < cvarTableSize ; i++, cv++ ) {
5940 trap_Cvar_Update( cv->vmCvar );
5941 }
5942 }
5943
5944
5945 /*
5946 =================
5947 ArenaServers_StopRefresh
5948 =================
5949 */
5950 static void UI_StopServerRefresh( void )
5951 {
5952 int count;
5953
5954 if (!uiInfo.serverStatus.refreshActive) {
5955 // not currently refreshing
5956 return;
5957 }
5958 uiInfo.serverStatus.refreshActive = qfalse;
5959 Com_Printf("%d servers listed in browser with %d players.\n",
5960 uiInfo.serverStatus.numDisplayServers,
5961 uiInfo.serverStatus.numPlayersOnServers);
5962 count = trap_LAN_GetServerCount(ui_netSource.integer);
5963 if (count - uiInfo.serverStatus.numDisplayServers > 0) {
5964 Com_Printf("%d servers not listed due to packet loss or pings higher than %d\n",
5965 count - uiInfo.serverStatus.numDisplayServers,
5966 (int) trap_Cvar_VariableValue("cl_maxPing"));
5967 }
5968
5969 }
5970
5971 /*
5972 =================
5973 ArenaServers_MaxPing
5974 =================
5975 */
5976 #ifndef MISSIONPACK // bk001206
5977 static int ArenaServers_MaxPing( void ) {
5978 int maxPing;
5979
5980 maxPing = (int)trap_Cvar_VariableValue( "cl_maxPing" );
5981 if( maxPing < 100 ) {
5982 maxPing = 100;
5983 }
5984 return maxPing;
5985 }
5986 #endif
5987
5988 /*
5989 =================
5990 UI_DoServerRefresh
5991 =================
5992 */
5993 static void UI_DoServerRefresh( void )
5994 {
5995 qboolean wait = qfalse;
5996
5997 if (!uiInfo.serverStatus.refreshActive) {
5998 return;
5999 }
6000 if (ui_netSource.integer != AS_FAVORITES) {
6001 if (ui_netSource.integer == AS_LOCAL) {
6002 if (!trap_LAN_GetServerCount(ui_netSource.integer)) {
6003 wait = qtrue;
6004 }
6005 } else {
6006 if (trap_LAN_GetServerCount(ui_netSource.integer) < 0) {
6007 wait = qtrue;
6008 }
6009 }
6010 }
6011
6012 if (uiInfo.uiDC.realTime < uiInfo.serverStatus.refreshtime) {
6013 if (wait) {
6014 return;
6015 }
6016 }
6017
6018 // if still trying to retrieve pings
6019 if (trap_LAN_UpdateVisiblePings(ui_netSource.integer)) {
6020 uiInfo.serverStatus.refreshtime = uiInfo.uiDC.realTime + 1000;
6021 } else if (!wait) {
6022 // get the last servers in the list
6023 UI_BuildServerDisplayList(2);
6024 // stop the refresh
6025 UI_StopServerRefresh();
6026 }
6027 //
6028 UI_BuildServerDisplayList(qfalse);
6029 }
6030
6031 /*
6032 =================
6033 UI_StartServerRefresh
6034 =================
6035 */
6036 static void UI_StartServerRefresh(qboolean full)
6037 {
6038 char *ptr;
6039
6040 qtime_t q;
6041 trap_RealTime(&q);
6042 trap_Cvar_Set( va("ui_lastServerRefresh_%i", ui_netSource.integer), va("%s-%i, %i at %i:%i", MonthAbbrev[q.tm_mon],q.tm_mday, 1900+q.tm_year,q.tm_hour,q.tm_min));
6043
6044 if (!full) {
6045 UI_UpdatePendingPings();
6046 return;
6047 }
6048
6049 uiInfo.serverStatus.refreshActive = qtrue;
6050 uiInfo.serverStatus.nextDisplayRefresh = uiInfo.uiDC.realTime + 1000;
6051 // clear number of displayed servers
6052 uiInfo.serverStatus.numDisplayServers = 0;
6053 uiInfo.serverStatus.numPlayersOnServers = 0;
6054 // mark all servers as visible so we store ping updates for them
6055 trap_LAN_MarkServerVisible(ui_netSource.integer, -1, qtrue);
6056 // reset all the pings
6057 trap_LAN_ResetPings(ui_netSource.integer);
6058 //
6059 if( ui_netSource.integer == AS_LOCAL ) {
6060 trap_Cmd_ExecuteText( EXEC_NOW, "localservers\n" );
6061 uiInfo.serverStatus.refreshtime = uiInfo.uiDC.realTime + 1000;
6062 return;
6063 }
6064
6065 uiInfo.serverStatus.refreshtime = uiInfo.uiDC.realTime + 5000;
6066 if( ui_netSource.integer == AS_GLOBAL ) {
6067
6068 ptr = UI_Cvar_VariableString("debug_protocol");
6069 if (strlen(ptr)) {
6070 trap_Cmd_ExecuteText( EXEC_NOW, va( "globalservers 0 %s full empty\n", ptr));
6071 }
6072 else {
6073 trap_Cmd_ExecuteText( EXEC_NOW, va( "globalservers 0 %d full empty\n", (int)trap_Cvar_VariableValue( "protocol" ) ) );
6074 }
6075 }
6076 }
6077