Debian Codegraph @

code/cgame/cg_draw.c

raw symbols SCIP
1 /*
2 ===========================================================================
3 Copyright (C) 1999-2005 Id Software, Inc.
4
5 This file is part of Quake III Arena source code.
6
7 Quake III Arena source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 Quake III Arena source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Quake III Arena source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
21 */
22 //
23 // cg_draw.c -- draw all of the graphical elements during
24 // active (after loading) gameplay
25
26 #include "cg_local.h"
27
28 #ifdef MISSIONPACK
29 #include "../ui/ui_shared.h"
30
31 // used for scoreboard
32 extern displayContextDef_t cgDC;
33 menuDef_t *menuScoreboard = NULL;
34 #else
35 int drawTeamOverlayModificationCount = -1;
36 #endif
37
38 int sortedTeamPlayers[TEAM_MAXOVERLAY];
39 int numSortedTeamPlayers;
40
41 char systemChat[256];
42 char teamChat1[256];
43 char teamChat2[256];
44
45 #ifdef MISSIONPACK
46
47 int CG_Text_Width(const char *text, float scale, int limit) {
48 int count,len;
49 float out;
50 glyphInfo_t *glyph;
51 float useScale;
52 const char *s = text;
53 fontInfo_t *font = &cgDC.Assets.textFont;
54 if (scale <= cg_smallFont.value) {
55 font = &cgDC.Assets.smallFont;
56 } else if (scale > cg_bigFont.value) {
57 font = &cgDC.Assets.bigFont;
58 }
59 useScale = scale * font->glyphScale;
60 out = 0;
61 if (text) {
62 len = strlen(text);
63 if (limit > 0 && len > limit) {
64 len = limit;
65 }
66 count = 0;
67 while (s && *s && count < len) {
68 if ( Q_IsColorString(s) ) {
69 s += 2;
70 continue;
71 } else {
72 glyph = &font->glyphs[*s & 255];
73 out += glyph->xSkip;
74 s++;
75 count++;
76 }
77 }
78 }
79 return out * useScale;
80 }
81
82 int CG_Text_Height(const char *text, float scale, int limit) {
83 int len, count;
84 float max;
85 glyphInfo_t *glyph;
86 float useScale;
87 const char *s = text;
88 fontInfo_t *font = &cgDC.Assets.textFont;
89 if (scale <= cg_smallFont.value) {
90 font = &cgDC.Assets.smallFont;
91 } else if (scale > cg_bigFont.value) {
92 font = &cgDC.Assets.bigFont;
93 }
94 useScale = scale * font->glyphScale;
95 max = 0;
96 if (text) {
97 len = strlen(text);
98 if (limit > 0 && len > limit) {
99 len = limit;
100 }
101 count = 0;
102 while (s && *s && count < len) {
103 if ( Q_IsColorString(s) ) {
104 s += 2;
105 continue;
106 } else {
107 glyph = &font->glyphs[*s & 255];
108 if (max < glyph->height) {
109 max = glyph->height;
110 }
111 s++;
112 count++;
113 }
114 }
115 }
116 return max * useScale;
117 }
118
119 void CG_Text_PaintChar(float x, float y, float width, float height, float scale, float s, float t, float s2, float t2, qhandle_t hShader) {
120 float w, h;
121 w = width * scale;
122 h = height * scale;
123 CG_AdjustFrom640( &x, &y, &w, &h );
124 trap_R_DrawStretchPic( x, y, w, h, s, t, s2, t2, hShader );
125 }
126
127 void CG_Text_Paint(float x, float y, float scale, vec4_t color, const char *text, float adjust, int limit, int style) {
128 int len, count;
129 vec4_t newColor;
130 glyphInfo_t *glyph;
131 float useScale;
132 fontInfo_t *font = &cgDC.Assets.textFont;
133 if (scale <= cg_smallFont.value) {
134 font = &cgDC.Assets.smallFont;
135 } else if (scale > cg_bigFont.value) {
136 font = &cgDC.Assets.bigFont;
137 }
138 useScale = scale * font->glyphScale;
139 if (text) {
140 const char *s = text;
141 trap_R_SetColor( color );
142 memcpy(&newColor[0], &color[0], sizeof(vec4_t));
143 len = strlen(text);
144 if (limit > 0 && len > limit) {
145 len = limit;
146 }
147 count = 0;
148 while (s && *s && count < len) {
149 glyph = &font->glyphs[*s & 255];
150 //int yadj = Assets.textFont.glyphs[text[i]].bottom + Assets.textFont.glyphs[text[i]].top;
151 //float yadj = scale * (Assets.textFont.glyphs[text[i]].imageHeight - Assets.textFont.glyphs[text[i]].height);
152 if ( Q_IsColorString( s ) ) {
153 memcpy( newColor, g_color_table[ColorIndex(*(s+1))], sizeof( newColor ) );
154 newColor[3] = color[3];
155 trap_R_SetColor( newColor );
156 s += 2;
157 continue;
158 } else {
159 float yadj = useScale * glyph->top;
160 if (style == ITEM_TEXTSTYLE_SHADOWED || style == ITEM_TEXTSTYLE_SHADOWEDMORE) {
161 int ofs = style == ITEM_TEXTSTYLE_SHADOWED ? 1 : 2;
162 colorBlack[3] = newColor[3];
163 trap_R_SetColor( colorBlack );
164 CG_Text_PaintChar(x + ofs, y - yadj + ofs,
165 glyph->imageWidth,
166 glyph->imageHeight,
167 useScale,
168 glyph->s,
169 glyph->t,
170 glyph->s2,
171 glyph->t2,
172 glyph->glyph);
173 colorBlack[3] = 1.0;
174 trap_R_SetColor( newColor );
175 }
176 CG_Text_PaintChar(x, y - yadj,
177 glyph->imageWidth,
178 glyph->imageHeight,
179 useScale,
180 glyph->s,
181 glyph->t,
182 glyph->s2,
183 glyph->t2,
184 glyph->glyph);
185 // CG_DrawPic(x, y - yadj, scale * cgDC.Assets.textFont.glyphs[text[i]].imageWidth, scale * cgDC.Assets.textFont.glyphs[text[i]].imageHeight, cgDC.Assets.textFont.glyphs[text[i]].glyph);
186 x += (glyph->xSkip * useScale) + adjust;
187 s++;
188 count++;
189 }
190 }
191 trap_R_SetColor( NULL );
192 }
193 }
194
195
196 #endif
197
198 /*
199 ==============
200 CG_DrawField
201
202 Draws large numbers for status bar and powerups
203 ==============
204 */
205 #ifndef MISSIONPACK
206 static void CG_DrawField (int x, int y, int width, int value) {
207 char num[16], *ptr;
208 int l;
209 int frame;
210
211 if ( width < 1 ) {
212 return;
213 }
214
215 // draw number string
216 if ( width > 5 ) {
217 width = 5;
218 }
219
220 switch ( width ) {
221 case 1:
222 value = value > 9 ? 9 : value;
223 value = value < 0 ? 0 : value;
224 break;
225 case 2:
226 value = value > 99 ? 99 : value;
227 value = value < -9 ? -9 : value;
228 break;
229 case 3:
230 value = value > 999 ? 999 : value;
231 value = value < -99 ? -99 : value;
232 break;
233 case 4:
234 value = value > 9999 ? 9999 : value;
235 value = value < -999 ? -999 : value;
236 break;
237 }
238
239 Com_sprintf (num, sizeof(num), "%i", value);
240 l = strlen(num);
241 if (l > width)
242 l = width;
243 x += 2 + CHAR_WIDTH*(width - l);
244
245 ptr = num;
246 while (*ptr && l)
247 {
248 if (*ptr == '-')
249 frame = STAT_MINUS;
250 else
251 frame = *ptr -'0';
252
253 CG_DrawPic( x,y, CHAR_WIDTH, CHAR_HEIGHT, cgs.media.numberShaders[frame] );
254 x += CHAR_WIDTH;
255 ptr++;
256 l--;
257 }
258 }
259 #endif // MISSIONPACK
260
261 /*
262 ================
263 CG_Draw3DModel
264
265 ================
266 */
267 void CG_Draw3DModel( float x, float y, float w, float h, qhandle_t model, qhandle_t skin, vec3_t origin, vec3_t angles ) {
268 refdef_t refdef;
269 refEntity_t ent;
270
271 if ( !cg_draw3dIcons.integer || !cg_drawIcons.integer ) {
272 return;
273 }
274
275 CG_AdjustFrom640( &x, &y, &w, &h );
276
277 memset( &refdef, 0, sizeof( refdef ) );
278
279 memset( &ent, 0, sizeof( ent ) );
280 AnglesToAxis( angles, ent.axis );
281 VectorCopy( origin, ent.origin );
282 ent.hModel = model;
283 ent.customSkin = skin;
284 ent.renderfx = RF_NOSHADOW; // no stencil shadows
285
286 refdef.rdflags = RDF_NOWORLDMODEL;
287
288 AxisClear( refdef.viewaxis );
289
290 refdef.fov_x = 30;
291 refdef.fov_y = 30;
292
293 refdef.x = x;
294 refdef.y = y;
295 refdef.width = w;
296 refdef.height = h;
297
298 refdef.time = cg.time;
299
300 trap_R_ClearScene();
301 trap_R_AddRefEntityToScene( &ent );
302 trap_R_RenderScene( &refdef );
303 }
304
305 /*
306 ================
307 CG_DrawHead
308
309 Used for both the status bar and the scoreboard
310 ================
311 */
312 void CG_DrawHead( float x, float y, float w, float h, int clientNum, vec3_t headAngles ) {
313 clipHandle_t cm;
314 clientInfo_t *ci;
315 float len;
316 vec3_t origin;
317 vec3_t mins, maxs;
318
319 ci = &cgs.clientinfo[ clientNum ];
320
321 if ( cg_draw3dIcons.integer ) {
322 cm = ci->headModel;
323 if ( !cm ) {
324 return;
325 }
326
327 // offset the origin y and z to center the head
328 trap_R_ModelBounds( cm, mins, maxs );
329
330 origin[2] = -0.5 * ( mins[2] + maxs[2] );
331 origin[1] = 0.5 * ( mins[1] + maxs[1] );
332
333 // calculate distance so the head nearly fills the box
334 // assume heads are taller than wide
335 len = 0.7 * ( maxs[2] - mins[2] );
336 origin[0] = len / 0.268; // len / tan( fov/2 )
337
338 // allow per-model tweaking
339 VectorAdd( origin, ci->headOffset, origin );
340
341 CG_Draw3DModel( x, y, w, h, ci->headModel, ci->headSkin, origin, headAngles );
342 } else if ( cg_drawIcons.integer ) {
343 CG_DrawPic( x, y, w, h, ci->modelIcon );
344 }
345
346 // if they are deferred, draw a cross out
347 if ( ci->deferred ) {
348 CG_DrawPic( x, y, w, h, cgs.media.deferShader );
349 }
350 }
351
352 /*
353 ================
354 CG_DrawFlagModel
355
356 Used for both the status bar and the scoreboard
357 ================
358 */
359 void CG_DrawFlagModel( float x, float y, float w, float h, int team, qboolean force2D ) {
360 qhandle_t cm;
361 float len;
362 vec3_t origin, angles;
363 vec3_t mins, maxs;
364 qhandle_t handle;
365
366 if ( !force2D && cg_draw3dIcons.integer ) {
367
368 VectorClear( angles );
369
370 cm = cgs.media.redFlagModel;
371
372 // offset the origin y and z to center the flag
373 trap_R_ModelBounds( cm, mins, maxs );
374
375 origin[2] = -0.5 * ( mins[2] + maxs[2] );
376 origin[1] = 0.5 * ( mins[1] + maxs[1] );
377
378 // calculate distance so the flag nearly fills the box
379 // assume heads are taller than wide
380 len = 0.5 * ( maxs[2] - mins[2] );
381 origin[0] = len / 0.268; // len / tan( fov/2 )
382
383 angles[YAW] = 60 * sin( cg.time / 2000.0 );;
384
385 if( team == TEAM_RED ) {
386 handle = cgs.media.redFlagModel;
387 } else if( team == TEAM_BLUE ) {
388 handle = cgs.media.blueFlagModel;
389 } else if( team == TEAM_FREE ) {
390 handle = cgs.media.neutralFlagModel;
391 } else {
392 return;
393 }
394 CG_Draw3DModel( x, y, w, h, handle, 0, origin, angles );
395 } else if ( cg_drawIcons.integer ) {
396 gitem_t *item;
397
398 if( team == TEAM_RED ) {
399 item = BG_FindItemForPowerup( PW_REDFLAG );
400 } else if( team == TEAM_BLUE ) {
401 item = BG_FindItemForPowerup( PW_BLUEFLAG );
402 } else if( team == TEAM_FREE ) {
403 item = BG_FindItemForPowerup( PW_NEUTRALFLAG );
404 } else {
405 return;
406 }
407 if (item) {
408 CG_DrawPic( x, y, w, h, cg_items[ ITEM_INDEX(item) ].icon );
409 }
410 }
411 }
412
413 /*
414 ================
415 CG_DrawStatusBarHead
416
417 ================
418 */
419 #ifndef MISSIONPACK
420
421 static void CG_DrawStatusBarHead( float x ) {
422 vec3_t angles;
423 float size, stretch;
424 float frac;
425
426 VectorClear( angles );
427
428 if ( cg.damageTime && cg.time - cg.damageTime < DAMAGE_TIME ) {
429 frac = (float)(cg.time - cg.damageTime ) / DAMAGE_TIME;
430 size = ICON_SIZE * 1.25 * ( 1.5 - frac * 0.5 );
431
432 stretch = size - ICON_SIZE * 1.25;
433 // kick in the direction of damage
434 x -= stretch * 0.5 + cg.damageX * stretch * 0.5;
435
436 cg.headStartYaw = 180 + cg.damageX * 45;
437
438 cg.headEndYaw = 180 + 20 * cos( crandom()*M_PI );
439 cg.headEndPitch = 5 * cos( crandom()*M_PI );
440
441 cg.headStartTime = cg.time;
442 cg.headEndTime = cg.time + 100 + random() * 2000;
443 } else {
444 if ( cg.time >= cg.headEndTime ) {
445 // select a new head angle
446 cg.headStartYaw = cg.headEndYaw;
447 cg.headStartPitch = cg.headEndPitch;
448 cg.headStartTime = cg.headEndTime;
449 cg.headEndTime = cg.time + 100 + random() * 2000;
450
451 cg.headEndYaw = 180 + 20 * cos( crandom()*M_PI );
452 cg.headEndPitch = 5 * cos( crandom()*M_PI );
453 }
454
455 size = ICON_SIZE * 1.25;
456 }
457
458 // if the server was frozen for a while we may have a bad head start time
459 if ( cg.headStartTime > cg.time ) {
460 cg.headStartTime = cg.time;
461 }
462
463 frac = ( cg.time - cg.headStartTime ) / (float)( cg.headEndTime - cg.headStartTime );
464 frac = frac * frac * ( 3 - 2 * frac );
465 angles[YAW] = cg.headStartYaw + ( cg.headEndYaw - cg.headStartYaw ) * frac;
466 angles[PITCH] = cg.headStartPitch + ( cg.headEndPitch - cg.headStartPitch ) * frac;
467
468 CG_DrawHead( x, 480 - size, size, size,
469 cg.snap->ps.clientNum, angles );
470 }
471 #endif // MISSIONPACK
472
473 /*
474 ================
475 CG_DrawStatusBarFlag
476
477 ================
478 */
479 #ifndef MISSIONPACK
480 static void CG_DrawStatusBarFlag( float x, int team ) {
481 CG_DrawFlagModel( x, 480 - ICON_SIZE, ICON_SIZE, ICON_SIZE, team, qfalse );
482 }
483 #endif // MISSIONPACK
484
485 /*
486 ================
487 CG_DrawTeamBackground
488
489 ================
490 */
491 void CG_DrawTeamBackground( int x, int y, int w, int h, float alpha, int team )
492 {
493 vec4_t hcolor;
494
495 hcolor[3] = alpha;
496 if ( team == TEAM_RED ) {
497 hcolor[0] = 1;
498 hcolor[1] = 0;
499 hcolor[2] = 0;
500 } else if ( team == TEAM_BLUE ) {
501 hcolor[0] = 0;
502 hcolor[1] = 0;
503 hcolor[2] = 1;
504 } else {
505 return;
506 }
507 trap_R_SetColor( hcolor );
508 CG_DrawPic( x, y, w, h, cgs.media.teamStatusBar );
509 trap_R_SetColor( NULL );
510 }
511
512 /*
513 ================
514 CG_DrawStatusBar
515
516 ================
517 */
518 #ifndef MISSIONPACK
519 static void CG_DrawStatusBar( void ) {
520 int color;
521 centity_t *cent;
522 playerState_t *ps;
523 int value;
524 vec4_t hcolor;
525 vec3_t angles;
526 vec3_t origin;
527
528 static float colors[4][4] = {
529 // { 0.2, 1.0, 0.2, 1.0 } , { 1.0, 0.2, 0.2, 1.0 }, {0.5, 0.5, 0.5, 1} };
530 { 1.0f, 0.69f, 0.0f, 1.0f }, // normal
531 { 1.0f, 0.2f, 0.2f, 1.0f }, // low health
532 { 0.5f, 0.5f, 0.5f, 1.0f }, // weapon firing
533 { 1.0f, 1.0f, 1.0f, 1.0f } }; // health > 100
534
535 if ( cg_drawStatus.integer == 0 ) {
536 return;
537 }
538
539 // draw the team background
540 CG_DrawTeamBackground( 0, 420, 640, 60, 0.33f, cg.snap->ps.persistant[PERS_TEAM] );
541
542 cent = &cg_entities[cg.snap->ps.clientNum];
543 ps = &cg.snap->ps;
544
545 VectorClear( angles );
546
547 // draw any 3D icons first, so the changes back to 2D are minimized
548 if ( cent->currentState.weapon && cg_weapons[ cent->currentState.weapon ].ammoModel ) {
549 origin[0] = 70;
550 origin[1] = 0;
551 origin[2] = 0;
552 angles[YAW] = 90 + 20 * sin( cg.time / 1000.0 );
553 CG_Draw3DModel( CHAR_WIDTH*3 + TEXT_ICON_SPACE, 432, ICON_SIZE, ICON_SIZE,
554 cg_weapons[ cent->currentState.weapon ].ammoModel, 0, origin, angles );
555 }
556
557 CG_DrawStatusBarHead( 185 + CHAR_WIDTH*3 + TEXT_ICON_SPACE );
558
559 if( cg.predictedPlayerState.powerups[PW_REDFLAG] ) {
560 CG_DrawStatusBarFlag( 185 + CHAR_WIDTH*3 + TEXT_ICON_SPACE + ICON_SIZE, TEAM_RED );
561 } else if( cg.predictedPlayerState.powerups[PW_BLUEFLAG] ) {
562 CG_DrawStatusBarFlag( 185 + CHAR_WIDTH*3 + TEXT_ICON_SPACE + ICON_SIZE, TEAM_BLUE );
563 } else if( cg.predictedPlayerState.powerups[PW_NEUTRALFLAG] ) {
564 CG_DrawStatusBarFlag( 185 + CHAR_WIDTH*3 + TEXT_ICON_SPACE + ICON_SIZE, TEAM_FREE );
565 }
566
567 if ( ps->stats[ STAT_ARMOR ] ) {
568 origin[0] = 90;
569 origin[1] = 0;
570 origin[2] = -10;
571 angles[YAW] = ( cg.time & 2047 ) * 360 / 2048.0;
572 CG_Draw3DModel( 370 + CHAR_WIDTH*3 + TEXT_ICON_SPACE, 432, ICON_SIZE, ICON_SIZE,
573 cgs.media.armorModel, 0, origin, angles );
574 }
575 //
576 // ammo
577 //
578 if ( cent->currentState.weapon ) {
579 value = ps->ammo[cent->currentState.weapon];
580 if ( value > -1 ) {
581 if ( cg.predictedPlayerState.weaponstate == WEAPON_FIRING
582 && cg.predictedPlayerState.weaponTime > 100 ) {
583 // draw as dark grey when reloading
584 color = 2; // dark grey
585 } else {
586 if ( value >= 0 ) {
587 color = 0; // green
588 } else {
589 color = 1; // red
590 }
591 }
592 trap_R_SetColor( colors[color] );
593
594 CG_DrawField (0, 432, 3, value);
595 trap_R_SetColor( NULL );
596
597 // if we didn't draw a 3D icon, draw a 2D icon for ammo
598 if ( !cg_draw3dIcons.integer && cg_drawIcons.integer ) {
599 qhandle_t icon;
600
601 icon = cg_weapons[ cg.predictedPlayerState.weapon ].ammoIcon;
602 if ( icon ) {
603 CG_DrawPic( CHAR_WIDTH*3 + TEXT_ICON_SPACE, 432, ICON_SIZE, ICON_SIZE, icon );
604 }
605 }
606 }
607 }
608
609 //
610 // health
611 //
612 value = ps->stats[STAT_HEALTH];
613 if ( value > 100 ) {
614 trap_R_SetColor( colors[3] ); // white
615 } else if (value > 25) {
616 trap_R_SetColor( colors[0] ); // green
617 } else if (value > 0) {
618 color = (cg.time >> 8) & 1; // flash
619 trap_R_SetColor( colors[color] );
620 } else {
621 trap_R_SetColor( colors[1] ); // red
622 }
623
624 // stretch the health up when taking damage
625 CG_DrawField ( 185, 432, 3, value);
626 CG_ColorForHealth( hcolor );
627 trap_R_SetColor( hcolor );
628
629
630 //
631 // armor
632 //
633 value = ps->stats[STAT_ARMOR];
634 if (value > 0 ) {
635 trap_R_SetColor( colors[0] );
636 CG_DrawField (370, 432, 3, value);
637 trap_R_SetColor( NULL );
638 // if we didn't draw a 3D icon, draw a 2D icon for armor
639 if ( !cg_draw3dIcons.integer && cg_drawIcons.integer ) {
640 CG_DrawPic( 370 + CHAR_WIDTH*3 + TEXT_ICON_SPACE, 432, ICON_SIZE, ICON_SIZE, cgs.media.armorIcon );
641 }
642
643 }
644 }
645 #endif
646
647 /*
648 ===========================================================================================
649
650 UPPER RIGHT CORNER
651
652 ===========================================================================================
653 */
654
655 /*
656 ================
657 CG_DrawAttacker
658
659 ================
660 */
661 static float CG_DrawAttacker( float y ) {
662 int t;
663 float size;
664 vec3_t angles;
665 const char *info;
666 const char *name;
667 int clientNum;
668
669 if ( cg.predictedPlayerState.stats[STAT_HEALTH] <= 0 ) {
670 return y;
671 }
672
673 if ( !cg.attackerTime ) {
674 return y;
675 }
676
677 clientNum = cg.predictedPlayerState.persistant[PERS_ATTACKER];
678 if ( clientNum < 0 || clientNum >= MAX_CLIENTS || clientNum == cg.snap->ps.clientNum ) {
679 return y;
680 }
681
682 if ( !cgs.clientinfo[clientNum].infoValid ) {
683 cg.attackerTime = 0;
684 return y;
685 }
686
687 t = cg.time - cg.attackerTime;
688 if ( t > ATTACKER_HEAD_TIME ) {
689 cg.attackerTime = 0;
690 return y;
691 }
692
693 size = ICON_SIZE * 1.25;
694
695 angles[PITCH] = 0;
696 angles[YAW] = 180;
697 angles[ROLL] = 0;
698 CG_DrawHead( 640 - size, y, size, size, clientNum, angles );
699
700 info = CG_ConfigString( CS_PLAYERS + clientNum );
701 name = Info_ValueForKey( info, "n" );
702 y += size;
703 CG_DrawBigString( 640 - ( Q_PrintStrlen( name ) * BIGCHAR_WIDTH), y, name, 0.5 );
704
705 return y + BIGCHAR_HEIGHT + 2;
706 }
707
708 /*
709 ==================
710 CG_DrawSnapshot
711 ==================
712 */
713 static float CG_DrawSnapshot( float y ) {
714 char *s;
715 int w;
716
717 s = va( "time:%i snap:%i cmd:%i", cg.snap->serverTime,
718 cg.latestSnapshotNum, cgs.serverCommandSequence );
719 w = CG_DrawStrlen( s ) * BIGCHAR_WIDTH;
720
721 CG_DrawBigString( 635 - w, y + 2, s, 1.0F);
722
723 return y + BIGCHAR_HEIGHT + 4;
724 }
725
726 /*
727 ==================
728 CG_DrawFPS
729 ==================
730 */
731 #define FPS_FRAMES 4
732 static float CG_DrawFPS( float y ) {
733 char *s;
734 int w;
735 static int previousTimes[FPS_FRAMES];
736 static int index;
737 int i, total;
738 int fps;
739 static int previous;
740 int t, frameTime;
741
742 // don't use serverTime, because that will be drifting to
743 // correct for internet lag changes, timescales, timedemos, etc
744 t = trap_Milliseconds();
745 frameTime = t - previous;
746 previous = t;
747
748 previousTimes[index % FPS_FRAMES] = frameTime;
749 index++;
750 if ( index > FPS_FRAMES ) {
751 // average multiple frames together to smooth changes out a bit
752 total = 0;
753 for ( i = 0 ; i < FPS_FRAMES ; i++ ) {
754 total += previousTimes[i];
755 }
756 if ( !total ) {
757 total = 1;
758 }
759 fps = 1000 * FPS_FRAMES / total;
760
761 s = va( "%ifps", fps );
762 w = CG_DrawStrlen( s ) * BIGCHAR_WIDTH;
763
764 CG_DrawBigString( 635 - w, y + 2, s, 1.0F);
765 }
766
767 return y + BIGCHAR_HEIGHT + 4;
768 }
769
770 /*
771 =================
772 CG_DrawTimer
773 =================
774 */
775 static float CG_DrawTimer( float y ) {
776 char *s;
777 int w;
778 int mins, seconds, tens;
779 int msec;
780
781 msec = cg.time - cgs.levelStartTime;
782
783 seconds = msec / 1000;
784 mins = seconds / 60;
785 seconds -= mins * 60;
786 tens = seconds / 10;
787 seconds -= tens * 10;
788
789 s = va( "%i:%i%i", mins, tens, seconds );
790 w = CG_DrawStrlen( s ) * BIGCHAR_WIDTH;
791
792 CG_DrawBigString( 635 - w, y + 2, s, 1.0F);
793
794 return y + BIGCHAR_HEIGHT + 4;
795 }
796
797
798 /*
799 =================
800 CG_DrawTeamOverlay
801 =================
802 */
803
804 static float CG_DrawTeamOverlay( float y, qboolean right, qboolean upper ) {
805 int x, w, h, xx;
806 int i, j, len;
807 const char *p;
808 vec4_t hcolor;
809 int pwidth, lwidth;
810 int plyrs;
811 char st[16];
812 clientInfo_t *ci;
813 gitem_t *item;
814 int ret_y, count;
815
816 if ( !cg_drawTeamOverlay.integer ) {
817 return y;
818 }
819
820 if ( cg.snap->ps.persistant[PERS_TEAM] != TEAM_RED && cg.snap->ps.persistant[PERS_TEAM] != TEAM_BLUE ) {
821 return y; // Not on any team
822 }
823
824 plyrs = 0;
825
826 // max player name width
827 pwidth = 0;
828 count = (numSortedTeamPlayers > 8) ? 8 : numSortedTeamPlayers;
829 for (i = 0; i < count; i++) {
830 ci = cgs.clientinfo + sortedTeamPlayers[i];
831 if ( ci->infoValid && ci->team == cg.snap->ps.persistant[PERS_TEAM]) {
832 plyrs++;
833 len = CG_DrawStrlen(ci->name);
834 if (len > pwidth)
835 pwidth = len;
836 }
837 }
838
839 if (!plyrs)
840 return y;
841
842 if (pwidth > TEAM_OVERLAY_MAXNAME_WIDTH)
843 pwidth = TEAM_OVERLAY_MAXNAME_WIDTH;
844
845 // max location name width
846 lwidth = 0;
847 for (i = 1; i < MAX_LOCATIONS; i++) {
848 p = CG_ConfigString(CS_LOCATIONS + i);
849 if (p && *p) {
850 len = CG_DrawStrlen(p);
851 if (len > lwidth)
852 lwidth = len;
853 }
854 }
855
856 if (lwidth > TEAM_OVERLAY_MAXLOCATION_WIDTH)
857 lwidth = TEAM_OVERLAY_MAXLOCATION_WIDTH;
858
859 w = (pwidth + lwidth + 4 + 7) * TINYCHAR_WIDTH;
860
861 if ( right )
862 x = 640 - w;
863 else
864 x = 0;
865
866 h = plyrs * TINYCHAR_HEIGHT;
867
868 if ( upper ) {
869 ret_y = y + h;
870 } else {
871 y -= h;
872 ret_y = y;
873 }
874
875 if ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_RED ) {
876 hcolor[0] = 1.0f;
877 hcolor[1] = 0.0f;
878 hcolor[2] = 0.0f;
879 hcolor[3] = 0.33f;
880 } else { // if ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_BLUE )
881 hcolor[0] = 0.0f;
882 hcolor[1] = 0.0f;
883 hcolor[2] = 1.0f;
884 hcolor[3] = 0.33f;
885 }
886 trap_R_SetColor( hcolor );
887 CG_DrawPic( x, y, w, h, cgs.media.teamStatusBar );
888 trap_R_SetColor( NULL );
889
890 for (i = 0; i < count; i++) {
891 ci = cgs.clientinfo + sortedTeamPlayers[i];
892 if ( ci->infoValid && ci->team == cg.snap->ps.persistant[PERS_TEAM]) {
893
894 hcolor[0] = hcolor[1] = hcolor[2] = hcolor[3] = 1.0;
895
896 xx = x + TINYCHAR_WIDTH;
897
898 CG_DrawStringExt( xx, y,
899 ci->name, hcolor, qfalse, qfalse,
900 TINYCHAR_WIDTH, TINYCHAR_HEIGHT, TEAM_OVERLAY_MAXNAME_WIDTH);
901
902 if (lwidth) {
903 p = CG_ConfigString(CS_LOCATIONS + ci->location);
904 if (!p || !*p)
905 p = "unknown";
906 // len = CG_DrawStrlen(p);
907 // if (len > lwidth)
908 // len = lwidth;
909
910 // xx = x + TINYCHAR_WIDTH * 2 + TINYCHAR_WIDTH * pwidth +
911 // ((lwidth/2 - len/2) * TINYCHAR_WIDTH);
912 xx = x + TINYCHAR_WIDTH * 2 + TINYCHAR_WIDTH * pwidth;
913 CG_DrawStringExt( xx, y,
914 p, hcolor, qfalse, qfalse, TINYCHAR_WIDTH, TINYCHAR_HEIGHT,
915 TEAM_OVERLAY_MAXLOCATION_WIDTH);
916 }
917
918 CG_GetColorForHealth( ci->health, ci->armor, hcolor );
919
920 Com_sprintf (st, sizeof(st), "%3i %3i", ci->health, ci->armor);
921
922 xx = x + TINYCHAR_WIDTH * 3 +
923 TINYCHAR_WIDTH * pwidth + TINYCHAR_WIDTH * lwidth;
924
925 CG_DrawStringExt( xx, y,
926 st, hcolor, qfalse, qfalse,
927 TINYCHAR_WIDTH, TINYCHAR_HEIGHT, 0 );
928
929 // draw weapon icon
930 xx += TINYCHAR_WIDTH * 3;
931
932 if ( cg_weapons[ci->curWeapon].weaponIcon ) {
933 CG_DrawPic( xx, y, TINYCHAR_WIDTH, TINYCHAR_HEIGHT,
934 cg_weapons[ci->curWeapon].weaponIcon );
935 } else {
936 CG_DrawPic( xx, y, TINYCHAR_WIDTH, TINYCHAR_HEIGHT,
937 cgs.media.deferShader );
938 }
939
940 // Draw powerup icons
941 if (right) {
942 xx = x;
943 } else {
944 xx = x + w - TINYCHAR_WIDTH;
945 }
946 for (j = 0; j <= PW_NUM_POWERUPS; j++) {
947 if (ci->powerups & (1 << j)) {
948
949 item = BG_FindItemForPowerup( j );
950
951 if (item) {
952 CG_DrawPic( xx, y, TINYCHAR_WIDTH, TINYCHAR_HEIGHT,
953 trap_R_RegisterShader( item->icon ) );
954 if (right) {
955 xx -= TINYCHAR_WIDTH;
956 } else {
957 xx += TINYCHAR_WIDTH;
958 }
959 }
960 }
961 }
962
963 y += TINYCHAR_HEIGHT;
964 }
965 }
966
967 return ret_y;
968 //#endif
969 }
970
971
972 /*
973 =====================
974 CG_DrawUpperRight
975
976 =====================
977 */
978 static void CG_DrawUpperRight(stereoFrame_t stereoFrame)
979 {
980 float y;
981
982 y = 0;
983
984 if ( cgs.gametype >= GT_TEAM && cg_drawTeamOverlay.integer == 1 ) {
985 y = CG_DrawTeamOverlay( y, qtrue, qtrue );
986 }
987 if ( cg_drawSnapshot.integer ) {
988 y = CG_DrawSnapshot( y );
989 }
990 if (cg_drawFPS.integer && (stereoFrame == STEREO_CENTER || stereoFrame == STEREO_RIGHT)) {
991 y = CG_DrawFPS( y );
992 }
993 if ( cg_drawTimer.integer ) {
994 y = CG_DrawTimer( y );
995 }
996 if ( cg_drawAttacker.integer ) {
997 CG_DrawAttacker( y );
998 }
999
1000 }
1001
1002 /*
1003 ===========================================================================================
1004
1005 LOWER RIGHT CORNER
1006
1007 ===========================================================================================
1008 */
1009
1010 /*
1011 =================
1012 CG_DrawScores
1013
1014 Draw the small two score display
1015 =================
1016 */
1017 #ifndef MISSIONPACK
1018 static float CG_DrawScores( float y ) {
1019 const char *s;
1020 int s1, s2, score;
1021 int x, w;
1022 int v;
1023 vec4_t color;
1024 float y1;
1025 gitem_t *item;
1026
1027 s1 = cgs.scores1;
1028 s2 = cgs.scores2;
1029
1030 y -= BIGCHAR_HEIGHT + 8;
1031
1032 y1 = y;
1033
1034 // draw from the right side to left
1035 if ( cgs.gametype >= GT_TEAM ) {
1036 x = 640;
1037 color[0] = 0.0f;
1038 color[1] = 0.0f;
1039 color[2] = 1.0f;
1040 color[3] = 0.33f;
1041 s = va( "%2i", s2 );
1042 w = CG_DrawStrlen( s ) * BIGCHAR_WIDTH + 8;
1043 x -= w;
1044 CG_FillRect( x, y-4, w, BIGCHAR_HEIGHT+8, color );
1045 if ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_BLUE ) {
1046 CG_DrawPic( x, y-4, w, BIGCHAR_HEIGHT+8, cgs.media.selectShader );
1047 }
1048 CG_DrawBigString( x + 4, y, s, 1.0F);
1049
1050 if ( cgs.gametype == GT_CTF ) {
1051 // Display flag status
1052 item = BG_FindItemForPowerup( PW_BLUEFLAG );
1053
1054 if (item) {
1055 y1 = y - BIGCHAR_HEIGHT - 8;
1056 if( cgs.blueflag >= 0 && cgs.blueflag <= 2 ) {
1057 CG_DrawPic( x, y1-4, w, BIGCHAR_HEIGHT+8, cgs.media.blueFlagShader[cgs.blueflag] );
1058 }
1059 }
1060 }
1061 color[0] = 1.0f;
1062 color[1] = 0.0f;
1063 color[2] = 0.0f;
1064 color[3] = 0.33f;
1065 s = va( "%2i", s1 );
1066 w = CG_DrawStrlen( s ) * BIGCHAR_WIDTH + 8;
1067 x -= w;
1068 CG_FillRect( x, y-4, w, BIGCHAR_HEIGHT+8, color );
1069 if ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_RED ) {
1070 CG_DrawPic( x, y-4, w, BIGCHAR_HEIGHT+8, cgs.media.selectShader );
1071 }
1072 CG_DrawBigString( x + 4, y, s, 1.0F);
1073
1074 if ( cgs.gametype == GT_CTF ) {
1075 // Display flag status
1076 item = BG_FindItemForPowerup( PW_REDFLAG );
1077
1078 if (item) {
1079 y1 = y - BIGCHAR_HEIGHT - 8;
1080 if( cgs.redflag >= 0 && cgs.redflag <= 2 ) {
1081 CG_DrawPic( x, y1-4, w, BIGCHAR_HEIGHT+8, cgs.media.redFlagShader[cgs.redflag] );
1082 }
1083 }
1084 }
1085
1086 if ( cgs.gametype >= GT_CTF ) {
1087 v = cgs.capturelimit;
1088 } else {
1089 v = cgs.fraglimit;
1090 }
1091 if ( v ) {
1092 s = va( "%2i", v );
1093 w = CG_DrawStrlen( s ) * BIGCHAR_WIDTH + 8;
1094 x -= w;
1095 CG_DrawBigString( x + 4, y, s, 1.0F);
1096 }
1097
1098 } else {
1099 qboolean spectator;
1100
1101 x = 640;
1102 score = cg.snap->ps.persistant[PERS_SCORE];
1103 spectator = ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_SPECTATOR );
1104
1105 // always show your score in the second box if not in first place
1106 if ( s1 != score ) {
1107 s2 = score;
1108 }
1109 if ( s2 != SCORE_NOT_PRESENT ) {
1110 s = va( "%2i", s2 );
1111 w = CG_DrawStrlen( s ) * BIGCHAR_WIDTH + 8;
1112 x -= w;
1113 if ( !spectator && score == s2 && score != s1 ) {
1114 color[0] = 1.0f;
1115 color[1] = 0.0f;
1116 color[2] = 0.0f;
1117 color[3] = 0.33f;
1118 CG_FillRect( x, y-4, w, BIGCHAR_HEIGHT+8, color );
1119 CG_DrawPic( x, y-4, w, BIGCHAR_HEIGHT+8, cgs.media.selectShader );
1120 } else {
1121 color[0] = 0.5f;
1122 color[1] = 0.5f;
1123 color[2] = 0.5f;
1124 color[3] = 0.33f;
1125 CG_FillRect( x, y-4, w, BIGCHAR_HEIGHT+8, color );
1126 }
1127 CG_DrawBigString( x + 4, y, s, 1.0F);
1128 }
1129
1130 // first place
1131 if ( s1 != SCORE_NOT_PRESENT ) {
1132 s = va( "%2i", s1 );
1133 w = CG_DrawStrlen( s ) * BIGCHAR_WIDTH + 8;
1134 x -= w;
1135 if ( !spectator && score == s1 ) {
1136 color[0] = 0.0f;
1137 color[1] = 0.0f;
1138 color[2] = 1.0f;
1139 color[3] = 0.33f;
1140 CG_FillRect( x, y-4, w, BIGCHAR_HEIGHT+8, color );
1141 CG_DrawPic( x, y-4, w, BIGCHAR_HEIGHT+8, cgs.media.selectShader );
1142 } else {
1143 color[0] = 0.5f;
1144 color[1] = 0.5f;
1145 color[2] = 0.5f;
1146 color[3] = 0.33f;
1147 CG_FillRect( x, y-4, w, BIGCHAR_HEIGHT+8, color );
1148 }
1149 CG_DrawBigString( x + 4, y, s, 1.0F);
1150 }
1151
1152 if ( cgs.fraglimit ) {
1153 s = va( "%2i", cgs.fraglimit );
1154 w = CG_DrawStrlen( s ) * BIGCHAR_WIDTH + 8;
1155 x -= w;
1156 CG_DrawBigString( x + 4, y, s, 1.0F);
1157 }
1158
1159 }
1160
1161 return y1 - 8;
1162 }
1163 #endif // MISSIONPACK
1164
1165 /*
1166 ================
1167 CG_DrawPowerups
1168 ================
1169 */
1170 #ifndef MISSIONPACK
1171 static float CG_DrawPowerups( float y ) {
1172 int sorted[MAX_POWERUPS];
1173 int sortedTime[MAX_POWERUPS];
1174 int i, j, k;
1175 int active;
1176 playerState_t *ps;
1177 int t;
1178 gitem_t *item;
1179 int x;
1180 int color;
1181 float size;
1182 float f;
1183 static float colors[2][4] = {
1184 { 0.2f, 1.0f, 0.2f, 1.0f } ,
1185 { 1.0f, 0.2f, 0.2f, 1.0f }
1186 };
1187
1188 ps = &cg.snap->ps;
1189
1190 if ( ps->stats[STAT_HEALTH] <= 0 ) {
1191 return y;
1192 }
1193
1194 // sort the list by time remaining
1195 active = 0;
1196 for ( i = 0 ; i < MAX_POWERUPS ; i++ ) {
1197 if ( !ps->powerups[ i ] ) {
1198 continue;
1199 }
1200
1201 // ZOID--don't draw if the power up has unlimited time
1202 // This is true of the CTF flags
1203 if ( ps->powerups[ i ] == INT_MAX ) {
1204 continue;
1205 }
1206
1207 t = ps->powerups[ i ] - cg.time;
1208 if ( t <= 0 ) {
1209 continue;
1210 }
1211
1212 // insert into the list
1213 for ( j = 0 ; j < active ; j++ ) {
1214 if ( sortedTime[j] >= t ) {
1215 for ( k = active - 1 ; k >= j ; k-- ) {
1216 sorted[k+1] = sorted[k];
1217 sortedTime[k+1] = sortedTime[k];
1218 }
1219 break;
1220 }
1221 }
1222 sorted[j] = i;
1223 sortedTime[j] = t;
1224 active++;
1225 }
1226
1227 // draw the icons and timers
1228 x = 640 - ICON_SIZE - CHAR_WIDTH * 2;
1229 for ( i = 0 ; i < active ; i++ ) {
1230 item = BG_FindItemForPowerup( sorted[i] );
1231
1232 if (item) {
1233
1234 color = 1;
1235
1236 y -= ICON_SIZE;
1237
1238 trap_R_SetColor( colors[color] );
1239 CG_DrawField( x, y, 2, sortedTime[ i ] / 1000 );
1240
1241 t = ps->powerups[ sorted[i] ];
1242 if ( t - cg.time >= POWERUP_BLINKS * POWERUP_BLINK_TIME ) {
1243 trap_R_SetColor( NULL );
1244 } else {
1245 vec4_t modulate;
1246
1247 f = (float)( t - cg.time ) / POWERUP_BLINK_TIME;
1248 f -= (int)f;
1249 modulate[0] = modulate[1] = modulate[2] = modulate[3] = f;
1250 trap_R_SetColor( modulate );
1251 }
1252
1253 if ( cg.powerupActive == sorted[i] &&
1254 cg.time - cg.powerupTime < PULSE_TIME ) {
1255 f = 1.0 - ( ( (float)cg.time - cg.powerupTime ) / PULSE_TIME );
1256 size = ICON_SIZE * ( 1.0 + ( PULSE_SCALE - 1.0 ) * f );
1257 } else {
1258 size = ICON_SIZE;
1259 }
1260
1261 CG_DrawPic( 640 - size, y + ICON_SIZE / 2 - size / 2,
1262 size, size, trap_R_RegisterShader( item->icon ) );
1263 }
1264 }
1265 trap_R_SetColor( NULL );
1266
1267 return y;
1268 }
1269 #endif // MISSIONPACK
1270
1271 /*
1272 =====================
1273 CG_DrawLowerRight
1274
1275 =====================
1276 */
1277 #ifndef MISSIONPACK
1278 static void CG_DrawLowerRight( void ) {
1279 float y;
1280
1281 y = 480 - ICON_SIZE;
1282
1283 if ( cgs.gametype >= GT_TEAM && cg_drawTeamOverlay.integer == 2 ) {
1284 y = CG_DrawTeamOverlay( y, qtrue, qfalse );
1285 }
1286
1287 y = CG_DrawScores( y );
1288 CG_DrawPowerups( y );
1289 }
1290 #endif // MISSIONPACK
1291
1292 /*
1293 ===================
1294 CG_DrawPickupItem
1295 ===================
1296 */
1297 #ifndef MISSIONPACK
1298 static int CG_DrawPickupItem( int y ) {
1299 int value;
1300 float *fadeColor;
1301
1302 if ( cg.snap->ps.stats[STAT_HEALTH] <= 0 ) {
1303 return y;
1304 }
1305
1306 y -= ICON_SIZE;
1307
1308 value = cg.itemPickup;
1309 if ( value ) {
1310 fadeColor = CG_FadeColor( cg.itemPickupTime, 3000 );
1311 if ( fadeColor ) {
1312 CG_RegisterItemVisuals( value );
1313 trap_R_SetColor( fadeColor );
1314 CG_DrawPic( 8, y, ICON_SIZE, ICON_SIZE, cg_items[ value ].icon );
1315 CG_DrawBigString( ICON_SIZE + 16, y + (ICON_SIZE/2 - BIGCHAR_HEIGHT/2), bg_itemlist[ value ].pickup_name, fadeColor[0] );
1316 trap_R_SetColor( NULL );
1317 }
1318 }
1319
1320 return y;
1321 }
1322 #endif // MISSIONPACK
1323
1324 /*
1325 =====================
1326 CG_DrawLowerLeft
1327
1328 =====================
1329 */
1330 #ifndef MISSIONPACK
1331 static void CG_DrawLowerLeft( void ) {
1332 float y;
1333
1334 y = 480 - ICON_SIZE;
1335
1336 if ( cgs.gametype >= GT_TEAM && cg_drawTeamOverlay.integer == 3 ) {
1337 y = CG_DrawTeamOverlay( y, qfalse, qfalse );
1338 }
1339
1340
1341 CG_DrawPickupItem( y );
1342 }
1343 #endif // MISSIONPACK
1344
1345
1346 //===========================================================================================
1347
1348 /*
1349 =================
1350 CG_DrawTeamInfo
1351 =================
1352 */
1353 #ifndef MISSIONPACK
1354 static void CG_DrawTeamInfo( void ) {
1355 int h;
1356 int i;
1357 vec4_t hcolor;
1358 int chatHeight;
1359
1360 #define CHATLOC_Y 420 // bottom end
1361 #define CHATLOC_X 0
1362
1363 if (cg_teamChatHeight.integer < TEAMCHAT_HEIGHT)
1364 chatHeight = cg_teamChatHeight.integer;
1365 else
1366 chatHeight = TEAMCHAT_HEIGHT;
1367 if (chatHeight <= 0)
1368 return; // disabled
1369
1370 if (cgs.teamLastChatPos != cgs.teamChatPos) {
1371 if (cg.time - cgs.teamChatMsgTimes[cgs.teamLastChatPos % chatHeight] > cg_teamChatTime.integer) {
1372 cgs.teamLastChatPos++;
1373 }
1374
1375 h = (cgs.teamChatPos - cgs.teamLastChatPos) * TINYCHAR_HEIGHT;
1376
1377 if ( cgs.clientinfo[cg.clientNum].team == TEAM_RED ) {
1378 hcolor[0] = 1.0f;
1379 hcolor[1] = 0.0f;
1380 hcolor[2] = 0.0f;
1381 hcolor[3] = 0.33f;
1382 } else if ( cgs.clientinfo[cg.clientNum].team == TEAM_BLUE ) {
1383 hcolor[0] = 0.0f;
1384 hcolor[1] = 0.0f;
1385 hcolor[2] = 1.0f;
1386 hcolor[3] = 0.33f;
1387 } else {
1388 hcolor[0] = 0.0f;
1389 hcolor[1] = 1.0f;
1390 hcolor[2] = 0.0f;
1391 hcolor[3] = 0.33f;
1392 }
1393
1394 trap_R_SetColor( hcolor );
1395 CG_DrawPic( CHATLOC_X, CHATLOC_Y - h, 640, h, cgs.media.teamStatusBar );
1396 trap_R_SetColor( NULL );
1397
1398 hcolor[0] = hcolor[1] = hcolor[2] = 1.0f;
1399 hcolor[3] = 1.0f;
1400
1401 for (i = cgs.teamChatPos - 1; i >= cgs.teamLastChatPos; i--) {
1402 CG_DrawStringExt( CHATLOC_X + TINYCHAR_WIDTH,
1403 CHATLOC_Y - (cgs.teamChatPos - i)*TINYCHAR_HEIGHT,
1404 cgs.teamChatMsgs[i % chatHeight], hcolor, qfalse, qfalse,
1405 TINYCHAR_WIDTH, TINYCHAR_HEIGHT, 0 );
1406 }
1407 }
1408 }
1409 #endif // MISSIONPACK
1410
1411 /*
1412 ===================
1413 CG_DrawHoldableItem
1414 ===================
1415 */
1416 #ifndef MISSIONPACK
1417 static void CG_DrawHoldableItem( void ) {
1418 int value;
1419
1420 value = cg.snap->ps.stats[STAT_HOLDABLE_ITEM];
1421 if ( value ) {
1422 CG_RegisterItemVisuals( value );
1423 CG_DrawPic( 640-ICON_SIZE, (SCREEN_HEIGHT-ICON_SIZE)/2, ICON_SIZE, ICON_SIZE, cg_items[ value ].icon );
1424 }
1425
1426 }
1427 #endif // MISSIONPACK
1428
1429 #ifdef MISSIONPACK
1430 /*
1431 ===================
1432 CG_DrawPersistantPowerup
1433 ===================
1434 */
1435 #if 0 // sos001208 - DEAD
1436 static void CG_DrawPersistantPowerup( void ) {
1437 int value;
1438
1439 value = cg.snap->ps.stats[STAT_PERSISTANT_POWERUP];
1440 if ( value ) {
1441 CG_RegisterItemVisuals( value );
1442 CG_DrawPic( 640-ICON_SIZE, (SCREEN_HEIGHT-ICON_SIZE)/2 - ICON_SIZE, ICON_SIZE, ICON_SIZE, cg_items[ value ].icon );
1443 }
1444 }
1445 #endif
1446 #endif // MISSIONPACK
1447
1448
1449 /*
1450 ===================
1451 CG_DrawReward
1452 ===================
1453 */
1454 static void CG_DrawReward( void ) {
1455 float *color;
1456 int i, count;
1457 float x, y;
1458 char buf[32];
1459
1460 if ( !cg_drawRewards.integer ) {
1461 return;
1462 }
1463
1464 color = CG_FadeColor( cg.rewardTime, REWARD_TIME );
1465 if ( !color ) {
1466 if (cg.rewardStack > 0) {
1467 for(i = 0; i < cg.rewardStack; i++) {
1468 cg.rewardSound[i] = cg.rewardSound[i+1];
1469 cg.rewardShader[i] = cg.rewardShader[i+1];
1470 cg.rewardCount[i] = cg.rewardCount[i+1];
1471 }
1472 cg.rewardTime = cg.time;
1473 cg.rewardStack--;
1474 color = CG_FadeColor( cg.rewardTime, REWARD_TIME );
1475 trap_S_StartLocalSound(cg.rewardSound[0], CHAN_ANNOUNCER);
1476 } else {
1477 return;
1478 }
1479 }
1480
1481 trap_R_SetColor( color );
1482
1483 /*
1484 count = cg.rewardCount[0]/10; // number of big rewards to draw
1485
1486 if (count) {
1487 y = 4;
1488 x = 320 - count * ICON_SIZE;
1489 for ( i = 0 ; i < count ; i++ ) {
1490 CG_DrawPic( x, y, (ICON_SIZE*2)-4, (ICON_SIZE*2)-4, cg.rewardShader[0] );
1491 x += (ICON_SIZE*2);
1492 }
1493 }
1494
1495 count = cg.rewardCount[0] - count*10; // number of small rewards to draw
1496 */
1497
1498 if ( cg.rewardCount[0] >= 10 ) {
1499 y = 56;
1500 x = 320 - ICON_SIZE/2;
1501 CG_DrawPic( x, y, ICON_SIZE-4, ICON_SIZE-4, cg.rewardShader[0] );
1502 Com_sprintf(buf, sizeof(buf), "%d", cg.rewardCount[0]);
1503 x = ( SCREEN_WIDTH - SMALLCHAR_WIDTH * CG_DrawStrlen( buf ) ) / 2;
1504 CG_DrawStringExt( x, y+ICON_SIZE, buf, color, qfalse, qtrue,
1505 SMALLCHAR_WIDTH, SMALLCHAR_HEIGHT, 0 );
1506 }
1507 else {
1508
1509 count = cg.rewardCount[0];
1510
1511 y = 56;
1512 x = 320 - count * ICON_SIZE/2;
1513 for ( i = 0 ; i < count ; i++ ) {
1514 CG_DrawPic( x, y, ICON_SIZE-4, ICON_SIZE-4, cg.rewardShader[0] );
1515 x += ICON_SIZE;
1516 }
1517 }
1518 trap_R_SetColor( NULL );
1519 }
1520
1521
1522 /*
1523 ===============================================================================
1524
1525 LAGOMETER
1526
1527 ===============================================================================
1528 */
1529
1530 #define LAG_SAMPLES 128
1531
1532
1533 typedef struct {
1534 int frameSamples[LAG_SAMPLES];
1535 int frameCount;
1536 int snapshotFlags[LAG_SAMPLES];
1537 int snapshotSamples[LAG_SAMPLES];
1538 int snapshotCount;
1539 } lagometer_t;
1540
1541 lagometer_t lagometer;
1542
1543 /*
1544 ==============
1545 CG_AddLagometerFrameInfo
1546
1547 Adds the current interpolate / extrapolate bar for this frame
1548 ==============
1549 */
1550 void CG_AddLagometerFrameInfo( void ) {
1551 int offset;
1552
1553 offset = cg.time - cg.latestSnapshotTime;
1554 lagometer.frameSamples[ lagometer.frameCount & ( LAG_SAMPLES - 1) ] = offset;
1555 lagometer.frameCount++;
1556 }
1557
1558 /*
1559 ==============
1560 CG_AddLagometerSnapshotInfo
1561
1562 Each time a snapshot is received, log its ping time and
1563 the number of snapshots that were dropped before it.
1564
1565 Pass NULL for a dropped packet.
1566 ==============
1567 */
1568 void CG_AddLagometerSnapshotInfo( snapshot_t *snap ) {
1569 // dropped packet
1570 if ( !snap ) {
1571 lagometer.snapshotSamples[ lagometer.snapshotCount & ( LAG_SAMPLES - 1) ] = -1;
1572 lagometer.snapshotCount++;
1573 return;
1574 }
1575
1576 // add this snapshot's info
1577 lagometer.snapshotSamples[ lagometer.snapshotCount & ( LAG_SAMPLES - 1) ] = snap->ping;
1578 lagometer.snapshotFlags[ lagometer.snapshotCount & ( LAG_SAMPLES - 1) ] = snap->snapFlags;
1579 lagometer.snapshotCount++;
1580 }
1581
1582 /*
1583 ==============
1584 CG_DrawDisconnect
1585
1586 Should we draw something differnet for long lag vs no packets?
1587 ==============
1588 */
1589 static void CG_DrawDisconnect( void ) {
1590 float x, y;
1591 int cmdNum;
1592 usercmd_t cmd;
1593 const char *s;
1594 int w;
1595
1596 // draw the phone jack if we are completely past our buffers
1597 cmdNum = trap_GetCurrentCmdNumber() - CMD_BACKUP + 1;
1598 trap_GetUserCmd( cmdNum, &cmd );
1599 if ( cmd.serverTime <= cg.snap->ps.commandTime
1600 || cmd.serverTime > cg.time ) { // special check for map_restart
1601 return;
1602 }
1603
1604 // also add text in center of screen
1605 s = "Connection Interrupted";
1606 w = CG_DrawStrlen( s ) * BIGCHAR_WIDTH;
1607 CG_DrawBigString( 320 - w/2, 100, s, 1.0F);
1608
1609 // blink the icon
1610 if ( ( cg.time >> 9 ) & 1 ) {
1611 return;
1612 }
1613
1614 #ifdef MISSIONPACK
1615 x = 640 - 48;
1616 y = 480 - 144;
1617 #else
1618 x = 640 - 48;
1619 y = 480 - 48;
1620 #endif
1621
1622 CG_DrawPic( x, y, 48, 48, trap_R_RegisterShader("gfx/2d/net.tga" ) );
1623 }
1624
1625
1626 #define MAX_LAGOMETER_PING 900
1627 #define MAX_LAGOMETER_RANGE 300
1628
1629 /*
1630 ==============
1631 CG_DrawLagometer
1632 ==============
1633 */
1634 static void CG_DrawLagometer( void ) {
1635 int a, x, y, i;
1636 float v;
1637 float ax, ay, aw, ah, mid, range;
1638 int color;
1639 float vscale;
1640
1641 if ( !cg_lagometer.integer || cgs.localServer ) {
1642 CG_DrawDisconnect();
1643 return;
1644 }
1645
1646 //
1647 // draw the graph
1648 //
1649 #ifdef MISSIONPACK
1650 x = 640 - 48;
1651 y = 480 - 144;
1652 #else
1653 x = 640 - 48;
1654 y = 480 - 48;
1655 #endif
1656
1657 trap_R_SetColor( NULL );
1658 CG_DrawPic( x, y, 48, 48, cgs.media.lagometerShader );
1659
1660 ax = x;
1661 ay = y;
1662 aw = 48;
1663 ah = 48;
1664 CG_AdjustFrom640( &ax, &ay, &aw, &ah );
1665
1666 color = -1;
1667 range = ah / 3;
1668 mid = ay + range;
1669
1670 vscale = range / MAX_LAGOMETER_RANGE;
1671
1672 // draw the frame interpoalte / extrapolate graph
1673 for ( a = 0 ; a < aw ; a++ ) {
1674 i = ( lagometer.frameCount - 1 - a ) & (LAG_SAMPLES - 1);
1675 v = lagometer.frameSamples[i];
1676 v *= vscale;
1677 if ( v > 0 ) {
1678 if ( color != 1 ) {
1679 color = 1;
1680 trap_R_SetColor( g_color_table[ColorIndex(COLOR_YELLOW)] );
1681 }
1682 if ( v > range ) {
1683 v = range;
1684 }
1685 trap_R_DrawStretchPic ( ax + aw - a, mid - v, 1, v, 0, 0, 0, 0, cgs.media.whiteShader );
1686 } else if ( v < 0 ) {
1687 if ( color != 2 ) {
1688 color = 2;
1689 trap_R_SetColor( g_color_table[ColorIndex(COLOR_BLUE)] );
1690 }
1691 v = -v;
1692 if ( v > range ) {
1693 v = range;
1694 }
1695 trap_R_DrawStretchPic( ax + aw - a, mid, 1, v, 0, 0, 0, 0, cgs.media.whiteShader );
1696 }
1697 }
1698
1699 // draw the snapshot latency / drop graph
1700 range = ah / 2;
1701 vscale = range / MAX_LAGOMETER_PING;
1702
1703 for ( a = 0 ; a < aw ; a++ ) {
1704 i = ( lagometer.snapshotCount - 1 - a ) & (LAG_SAMPLES - 1);
1705 v = lagometer.snapshotSamples[i];
1706 if ( v > 0 ) {
1707 if ( lagometer.snapshotFlags[i] & SNAPFLAG_RATE_DELAYED ) {
1708 if ( color != 5 ) {
1709 color = 5; // YELLOW for rate delay
1710 trap_R_SetColor( g_color_table[ColorIndex(COLOR_YELLOW)] );
1711 }
1712 } else {
1713 if ( color != 3 ) {
1714 color = 3;
1715 trap_R_SetColor( g_color_table[ColorIndex(COLOR_GREEN)] );
1716 }
1717 }
1718 v = v * vscale;
1719 if ( v > range ) {
1720 v = range;
1721 }
1722 trap_R_DrawStretchPic( ax + aw - a, ay + ah - v, 1, v, 0, 0, 0, 0, cgs.media.whiteShader );
1723 } else if ( v < 0 ) {
1724 if ( color != 4 ) {
1725 color = 4; // RED for dropped snapshots
1726 trap_R_SetColor( g_color_table[ColorIndex(COLOR_RED)] );
1727 }
1728 trap_R_DrawStretchPic( ax + aw - a, ay + ah - range, 1, range, 0, 0, 0, 0, cgs.media.whiteShader );
1729 }
1730 }
1731
1732 trap_R_SetColor( NULL );
1733
1734 if ( cg_nopredict.integer || cg_synchronousClients.integer ) {
1735 CG_DrawBigString( x, y, "snc", 1.0 );
1736 }
1737
1738 CG_DrawDisconnect();
1739 }
1740
1741
1742
1743 /*
1744 ===============================================================================
1745
1746 CENTER PRINTING
1747
1748 ===============================================================================
1749 */
1750
1751
1752 /*
1753 ==============
1754 CG_CenterPrint
1755
1756 Called for important messages that should stay in the center of the screen
1757 for a few moments
1758 ==============
1759 */
1760 void CG_CenterPrint( const char *str, int y, int charWidth ) {
1761 char *s;
1762
1763 Q_strncpyz( cg.centerPrint, str, sizeof(cg.centerPrint) );
1764
1765 cg.centerPrintTime = cg.time;
1766 cg.centerPrintY = y;
1767 cg.centerPrintCharWidth = charWidth;
1768
1769 // count the number of lines for centering
1770 cg.centerPrintLines = 1;
1771 s = cg.centerPrint;
1772 while( *s ) {
1773 if (*s == '\n')
1774 cg.centerPrintLines++;
1775 s++;
1776 }
1777 }
1778
1779
1780 /*
1781 ===================
1782 CG_DrawCenterString
1783 ===================
1784 */
1785 static void CG_DrawCenterString( void ) {
1786 char *start;
1787 int l;
1788 int x, y, w;
1789 #ifdef MISSIONPACK
1790 int h;
1791 #endif
1792 float *color;
1793
1794 if ( !cg.centerPrintTime ) {
1795 return;
1796 }
1797
1798 color = CG_FadeColor( cg.centerPrintTime, 1000 * cg_centertime.value );
1799 if ( !color ) {
1800 return;
1801 }
1802
1803 trap_R_SetColor( color );
1804
1805 start = cg.centerPrint;
1806
1807 y = cg.centerPrintY - cg.centerPrintLines * BIGCHAR_HEIGHT / 2;
1808
1809 while ( 1 ) {
1810 char linebuffer[1024];
1811
1812 for ( l = 0; l < 50; l++ ) {
1813 if ( !start[l] || start[l] == '\n' ) {
1814 break;
1815 }
1816 linebuffer[l] = start[l];
1817 }
1818 linebuffer[l] = 0;
1819
1820 #ifdef MISSIONPACK
1821 w = CG_Text_Width(linebuffer, 0.5, 0);
1822 h = CG_Text_Height(linebuffer, 0.5, 0);
1823 x = (SCREEN_WIDTH - w) / 2;
1824 CG_Text_Paint(x, y + h, 0.5, color, linebuffer, 0, 0, ITEM_TEXTSTYLE_SHADOWEDMORE);
1825 y += h + 6;
1826 #else
1827 w = cg.centerPrintCharWidth * CG_DrawStrlen( linebuffer );
1828
1829 x = ( SCREEN_WIDTH - w ) / 2;
1830
1831 CG_DrawStringExt( x, y, linebuffer, color, qfalse, qtrue,
1832 cg.centerPrintCharWidth, (int)(cg.centerPrintCharWidth * 1.5), 0 );
1833
1834 y += cg.centerPrintCharWidth * 1.5;
1835 #endif
1836 while ( *start && ( *start != '\n' ) ) {
1837 start++;
1838 }
1839 if ( !*start ) {
1840 break;
1841 }
1842 start++;
1843 }
1844
1845 trap_R_SetColor( NULL );
1846 }
1847
1848
1849
1850 /*
1851 ================================================================================
1852
1853 CROSSHAIR
1854
1855 ================================================================================
1856 */
1857
1858
1859 /*
1860 =================
1861 CG_DrawCrosshair
1862 =================
1863 */
1864 static void CG_DrawCrosshair(void)
1865 {
1866 float w, h;
1867 qhandle_t hShader;
1868 float f;
1869 float x, y;
1870 int ca;
1871
1872 if ( !cg_drawCrosshair.integer ) {
1873 return;
1874 }
1875
1876 if ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_SPECTATOR) {
1877 return;
1878 }
1879
1880 if ( cg.renderingThirdPerson ) {
1881 return;
1882 }
1883
1884 // set color based on health
1885 if ( cg_crosshairHealth.integer ) {
1886 vec4_t hcolor;
1887
1888 CG_ColorForHealth( hcolor );
1889 trap_R_SetColor( hcolor );
1890 } else {
1891 trap_R_SetColor( NULL );
1892 }
1893
1894 w = h = cg_crosshairSize.value;
1895
1896 // pulse the size of the crosshair when picking up items
1897 f = cg.time - cg.itemPickupBlendTime;
1898 if ( f > 0 && f < ITEM_BLOB_TIME ) {
1899 f /= ITEM_BLOB_TIME;
1900 w *= ( 1 + f );
1901 h *= ( 1 + f );
1902 }
1903
1904 x = cg_crosshairX.integer;
1905 y = cg_crosshairY.integer;
1906 CG_AdjustFrom640( &x, &y, &w, &h );
1907
1908 ca = cg_drawCrosshair.integer;
1909 if (ca < 0) {
1910 ca = 0;
1911 }
1912 hShader = cgs.media.crosshairShader[ ca % NUM_CROSSHAIRS ];
1913
1914 trap_R_DrawStretchPic( x + cg.refdef.x + 0.5 * (cg.refdef.width - w),
1915 y + cg.refdef.y + 0.5 * (cg.refdef.height - h),
1916 w, h, 0, 0, 1, 1, hShader );
1917
1918 trap_R_SetColor( NULL );
1919 }
1920
1921 /*
1922 =================
1923 CG_DrawCrosshair3D
1924 =================
1925 */
1926 static void CG_DrawCrosshair3D(void)
1927 {
1928 float w;
1929 qhandle_t hShader;
1930 float f;
1931 int ca;
1932
1933 trace_t trace;
1934 vec3_t endpos;
1935 float stereoSep, zProj, maxdist, xmax;
1936 char rendererinfos[128];
1937 refEntity_t ent;
1938
1939 if ( !cg_drawCrosshair.integer ) {
1940 return;
1941 }
1942
1943 if ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_SPECTATOR) {
1944 return;
1945 }
1946
1947 if ( cg.renderingThirdPerson ) {
1948 return;
1949 }
1950
1951 w = cg_crosshairSize.value;
1952
1953 // pulse the size of the crosshair when picking up items
1954 f = cg.time - cg.itemPickupBlendTime;
1955 if ( f > 0 && f < ITEM_BLOB_TIME ) {
1956 f /= ITEM_BLOB_TIME;
1957 w *= ( 1 + f );
1958 }
1959
1960 ca = cg_drawCrosshair.integer;
1961 if (ca < 0) {
1962 ca = 0;
1963 }
1964 hShader = cgs.media.crosshairShader[ ca % NUM_CROSSHAIRS ];
1965
1966 // Use a different method rendering the crosshair so players don't see two of them when
1967 // focusing their eyes at distant objects with high stereo separation
1968 // We are going to trace to the next shootable object and place the crosshair in front of it.
1969
1970 // first get all the important renderer information
1971 trap_Cvar_VariableStringBuffer("r_zProj", rendererinfos, sizeof(rendererinfos));
1972 zProj = atof(rendererinfos);
1973 trap_Cvar_VariableStringBuffer("r_stereoSeparation", rendererinfos, sizeof(rendererinfos));
1974 stereoSep = zProj / atof(rendererinfos);
1975
1976 xmax = zProj * tan(cg.refdef.fov_x * M_PI / 360.0f);
1977
1978 // let the trace run through until a change in stereo separation of the crosshair becomes less than one pixel.
1979 maxdist = cgs.glconfig.vidWidth * stereoSep * zProj / (2 * xmax);
1980 VectorMA(cg.refdef.vieworg, maxdist, cg.refdef.viewaxis[0], endpos);
1981 CG_Trace(&trace, cg.refdef.vieworg, NULL, NULL, endpos, 0, MASK_SHOT);
1982
1983 memset(&ent, 0, sizeof(ent));
1984 ent.reType = RT_SPRITE;
1985 ent.renderfx = RF_DEPTHHACK | RF_CROSSHAIR;
1986
1987 VectorCopy(trace.endpos, ent.origin);
1988
1989 // scale the crosshair so it appears the same size for all distances
1990 ent.radius = w / 640 * xmax * trace.fraction * maxdist / zProj;
1991 ent.customShader = hShader;
1992
1993 trap_R_AddRefEntityToScene(&ent);
1994 }
1995
1996
1997
1998 /*
1999 =================
2000 CG_ScanForCrosshairEntity
2001 =================
2002 */
2003 static void CG_ScanForCrosshairEntity( void ) {
2004 trace_t trace;
2005 vec3_t start, end;
2006 int content;
2007
2008 VectorCopy( cg.refdef.vieworg, start );
2009 VectorMA( start, 131072, cg.refdef.viewaxis[0], end );
2010
2011 CG_Trace( &trace, start, vec3_origin, vec3_origin, end,
2012 cg.snap->ps.clientNum, CONTENTS_SOLID|CONTENTS_BODY );
2013 if ( trace.entityNum >= MAX_CLIENTS ) {
2014 return;
2015 }
2016
2017 // if the player is in fog, don't show it
2018 content = CG_PointContents( trace.endpos, 0 );
2019 if ( content & CONTENTS_FOG ) {
2020 return;
2021 }
2022
2023 // if the player is invisible, don't show it
2024 if ( cg_entities[ trace.entityNum ].currentState.powerups & ( 1 << PW_INVIS ) ) {
2025 return;
2026 }
2027
2028 // update the fade timer
2029 cg.crosshairClientNum = trace.entityNum;
2030 cg.crosshairClientTime = cg.time;
2031 }
2032
2033
2034 /*
2035 =====================
2036 CG_DrawCrosshairNames
2037 =====================
2038 */
2039 static void CG_DrawCrosshairNames( void ) {
2040 float *color;
2041 char *name;
2042 float w;
2043
2044 if ( !cg_drawCrosshair.integer ) {
2045 return;
2046 }
2047 if ( !cg_drawCrosshairNames.integer ) {
2048 return;
2049 }
2050 if ( cg.renderingThirdPerson ) {
2051 return;
2052 }
2053
2054 // scan the known entities to see if the crosshair is sighted on one
2055 CG_ScanForCrosshairEntity();
2056
2057 // draw the name of the player being looked at
2058 color = CG_FadeColor( cg.crosshairClientTime, 1000 );
2059 if ( !color ) {
2060 trap_R_SetColor( NULL );
2061 return;
2062 }
2063
2064 name = cgs.clientinfo[ cg.crosshairClientNum ].name;
2065 #ifdef MISSIONPACK
2066 color[3] *= 0.5f;
2067 w = CG_Text_Width(name, 0.3f, 0);
2068 CG_Text_Paint( 320 - w / 2, 190, 0.3f, color, name, 0, 0, ITEM_TEXTSTYLE_SHADOWED);
2069 #else
2070 w = CG_DrawStrlen( name ) * BIGCHAR_WIDTH;
2071 CG_DrawBigString( 320 - w / 2, 170, name, color[3] * 0.5f );
2072 #endif
2073 trap_R_SetColor( NULL );
2074 }
2075
2076
2077 //==============================================================================
2078
2079 /*
2080 =================
2081 CG_DrawSpectator
2082 =================
2083 */
2084 static void CG_DrawSpectator(void) {
2085 CG_DrawBigString(320 - 9 * 8, 440, "SPECTATOR", 1.0F);
2086 if ( cgs.gametype == GT_TOURNAMENT ) {
2087 CG_DrawBigString(320 - 15 * 8, 460, "waiting to play", 1.0F);
2088 }
2089 else if ( cgs.gametype >= GT_TEAM ) {
2090 CG_DrawBigString(320 - 39 * 8, 460, "press ESC and use the JOIN menu to play", 1.0F);
2091 }
2092 }
2093
2094 /*
2095 =================
2096 CG_DrawVote
2097 =================
2098 */
2099 static void CG_DrawVote(void) {
2100 char *s;
2101 int sec;
2102
2103 if ( !cgs.voteTime ) {
2104 return;
2105 }
2106
2107 // play a talk beep whenever it is modified
2108 if ( cgs.voteModified ) {
2109 cgs.voteModified = qfalse;
2110 trap_S_StartLocalSound( cgs.media.talkSound, CHAN_LOCAL_SOUND );
2111 }
2112
2113 sec = ( VOTE_TIME - ( cg.time - cgs.voteTime ) ) / 1000;
2114 if ( sec < 0 ) {
2115 sec = 0;
2116 }
2117 #ifdef MISSIONPACK
2118 s = va("VOTE(%i):%s yes:%i no:%i", sec, cgs.voteString, cgs.voteYes, cgs.voteNo);
2119 CG_DrawSmallString( 0, 58, s, 1.0F );
2120 s = "or press ESC then click Vote";
2121 CG_DrawSmallString( 0, 58 + SMALLCHAR_HEIGHT + 2, s, 1.0F );
2122 #else
2123 s = va("VOTE(%i):%s yes:%i no:%i", sec, cgs.voteString, cgs.voteYes, cgs.voteNo );
2124 CG_DrawSmallString( 0, 58, s, 1.0F );
2125 #endif
2126 }
2127
2128 /*
2129 =================
2130 CG_DrawTeamVote
2131 =================
2132 */
2133 static void CG_DrawTeamVote(void) {
2134 char *s;
2135 int sec, cs_offset;
2136
2137 if ( cgs.clientinfo[cg.clientNum].team == TEAM_RED )
2138 cs_offset = 0;
2139 else if ( cgs.clientinfo[cg.clientNum].team == TEAM_BLUE )
2140 cs_offset = 1;
2141 else
2142 return;
2143
2144 if ( !cgs.teamVoteTime[cs_offset] ) {
2145 return;
2146 }
2147
2148 // play a talk beep whenever it is modified
2149 if ( cgs.teamVoteModified[cs_offset] ) {
2150 cgs.teamVoteModified[cs_offset] = qfalse;
2151 trap_S_StartLocalSound( cgs.media.talkSound, CHAN_LOCAL_SOUND );
2152 }
2153
2154 sec = ( VOTE_TIME - ( cg.time - cgs.teamVoteTime[cs_offset] ) ) / 1000;
2155 if ( sec < 0 ) {
2156 sec = 0;
2157 }
2158 s = va("TEAMVOTE(%i):%s yes:%i no:%i", sec, cgs.teamVoteString[cs_offset],
2159 cgs.teamVoteYes[cs_offset], cgs.teamVoteNo[cs_offset] );
2160 CG_DrawSmallString( 0, 90, s, 1.0F );
2161 }
2162
2163
2164 static qboolean CG_DrawScoreboard( void ) {
2165 #ifdef MISSIONPACK
2166 static qboolean firstTime = qtrue;
2167
2168 if (menuScoreboard) {
2169 menuScoreboard->window.flags &= ~WINDOW_FORCED;
2170 }
2171 if (cg_paused.integer) {
2172 cg.deferredPlayerLoading = 0;
2173 firstTime = qtrue;
2174 return qfalse;
2175 }
2176
2177 // should never happen in Team Arena
2178 if (cgs.gametype == GT_SINGLE_PLAYER && cg.predictedPlayerState.pm_type == PM_INTERMISSION ) {
2179 cg.deferredPlayerLoading = 0;
2180 firstTime = qtrue;
2181 return qfalse;
2182 }
2183
2184 // don't draw scoreboard during death while warmup up
2185 if ( cg.warmup && !cg.showScores ) {
2186 return qfalse;
2187 }
2188
2189 if ( cg.showScores || cg.predictedPlayerState.pm_type == PM_DEAD || cg.predictedPlayerState.pm_type == PM_INTERMISSION ) {
2190 } else {
2191 if ( !CG_FadeColor( cg.scoreFadeTime, FADE_TIME ) ) {
2192 // next time scoreboard comes up, don't print killer
2193 cg.deferredPlayerLoading = 0;
2194 cg.killerName[0] = 0;
2195 firstTime = qtrue;
2196 return qfalse;
2197 }
2198 }
2199
2200 if (menuScoreboard == NULL) {
2201 if ( cgs.gametype >= GT_TEAM ) {
2202 menuScoreboard = Menus_FindByName("teamscore_menu");
2203 } else {
2204 menuScoreboard = Menus_FindByName("score_menu");
2205 }
2206 }
2207
2208 if (menuScoreboard) {
2209 if (firstTime) {
2210 CG_SetScoreSelection(menuScoreboard);
2211 firstTime = qfalse;
2212 }
2213 Menu_Paint(menuScoreboard, qtrue);
2214 }
2215
2216 // load any models that have been deferred
2217 if ( ++cg.deferredPlayerLoading > 10 ) {
2218 CG_LoadDeferredPlayers();
2219 }
2220
2221 return qtrue;
2222 #else
2223 return CG_DrawOldScoreboard();
2224 #endif
2225 }
2226
2227 /*
2228 =================
2229 CG_DrawIntermission
2230 =================
2231 */
2232 static void CG_DrawIntermission( void ) {
2233 // int key;
2234 #ifdef MISSIONPACK
2235 //if (cg_singlePlayer.integer) {
2236 // CG_DrawCenterString();
2237 // return;
2238 //}
2239 #else
2240 if ( cgs.gametype == GT_SINGLE_PLAYER ) {
2241 CG_DrawCenterString();
2242 return;
2243 }
2244 #endif
2245 cg.scoreFadeTime = cg.time;
2246 cg.scoreBoardShowing = CG_DrawScoreboard();
2247 }
2248
2249 /*
2250 =================
2251 CG_DrawFollow
2252 =================
2253 */
2254 static qboolean CG_DrawFollow( void ) {
2255 float x;
2256 vec4_t color;
2257 const char *name;
2258
2259 if ( !(cg.snap->ps.pm_flags & PMF_FOLLOW) ) {
2260 return qfalse;
2261 }
2262 color[0] = 1;
2263 color[1] = 1;
2264 color[2] = 1;
2265 color[3] = 1;
2266
2267
2268 CG_DrawBigString( 320 - 9 * 8, 24, "following", 1.0F );
2269
2270 name = cgs.clientinfo[ cg.snap->ps.clientNum ].name;
2271
2272 x = 0.5 * ( 640 - GIANT_WIDTH * CG_DrawStrlen( name ) );
2273
2274 CG_DrawStringExt( x, 40, name, color, qtrue, qtrue, GIANT_WIDTH, GIANT_HEIGHT, 0 );
2275
2276 return qtrue;
2277 }
2278
2279
2280
2281 /*
2282 =================
2283 CG_DrawAmmoWarning
2284 =================
2285 */
2286 static void CG_DrawAmmoWarning( void ) {
2287 const char *s;
2288 int w;
2289
2290 if ( cg_drawAmmoWarning.integer == 0 ) {
2291 return;
2292 }
2293
2294 if ( !cg.lowAmmoWarning ) {
2295 return;
2296 }
2297
2298 if ( cg.lowAmmoWarning == 2 ) {
2299 s = "OUT OF AMMO";
2300 } else {
2301 s = "LOW AMMO WARNING";
2302 }
2303 w = CG_DrawStrlen( s ) * BIGCHAR_WIDTH;
2304 CG_DrawBigString(320 - w / 2, 64, s, 1.0F);
2305 }
2306
2307
2308 #ifdef MISSIONPACK
2309 /*
2310 =================
2311 CG_DrawProxWarning
2312 =================
2313 */
2314 static void CG_DrawProxWarning( void ) {
2315 char s [32];
2316 int w;
2317 static int proxTime;
2318 int proxTick;
2319
2320 if( !(cg.snap->ps.eFlags & EF_TICKING ) ) {
2321 proxTime = 0;
2322 return;
2323 }
2324
2325 if (proxTime == 0) {
2326 proxTime = cg.time;
2327 }
2328
2329 proxTick = 10 - ((cg.time - proxTime) / 1000);
2330
2331 if (proxTick > 0 && proxTick <= 5) {
2332 Com_sprintf(s, sizeof(s), "INTERNAL COMBUSTION IN: %i", proxTick);
2333 } else {
2334 Com_sprintf(s, sizeof(s), "YOU HAVE BEEN MINED");
2335 }
2336
2337 w = CG_DrawStrlen( s ) * BIGCHAR_WIDTH;
2338 CG_DrawBigStringColor( 320 - w / 2, 64 + BIGCHAR_HEIGHT, s, g_color_table[ColorIndex(COLOR_RED)] );
2339 }
2340 #endif
2341
2342
2343 /*
2344 =================
2345 CG_DrawWarmup
2346 =================
2347 */
2348 static void CG_DrawWarmup( void ) {
2349 int w;
2350 int sec;
2351 int i;
2352 #ifdef MISSIONPACK
2353 float scale;
2354 #else
2355 int cw;
2356 #endif
2357 clientInfo_t *ci1, *ci2;
2358 const char *s;
2359
2360 sec = cg.warmup;
2361 if ( !sec ) {
2362 return;
2363 }
2364
2365 if ( sec < 0 ) {
2366 s = "Waiting for players";
2367 w = CG_DrawStrlen( s ) * BIGCHAR_WIDTH;
2368 CG_DrawBigString(320 - w / 2, 24, s, 1.0F);
2369 cg.warmupCount = 0;
2370 return;
2371 }
2372
2373 if (cgs.gametype == GT_TOURNAMENT) {
2374 // find the two active players
2375 ci1 = NULL;
2376 ci2 = NULL;
2377 for ( i = 0 ; i < cgs.maxclients ; i++ ) {
2378 if ( cgs.clientinfo[i].infoValid && cgs.clientinfo[i].team == TEAM_FREE ) {
2379 if ( !ci1 ) {
2380 ci1 = &cgs.clientinfo[i];
2381 } else {
2382 ci2 = &cgs.clientinfo[i];
2383 }
2384 }
2385 }
2386
2387 if ( ci1 && ci2 ) {
2388 s = va( "%s vs %s", ci1->name, ci2->name );
2389 #ifdef MISSIONPACK
2390 w = CG_Text_Width(s, 0.6f, 0);
2391 CG_Text_Paint(320 - w / 2, 60, 0.6f, colorWhite, s, 0, 0, ITEM_TEXTSTYLE_SHADOWEDMORE);
2392 #else
2393 w = CG_DrawStrlen( s );
2394 if ( w > 640 / GIANT_WIDTH ) {
2395 cw = 640 / w;
2396 } else {
2397 cw = GIANT_WIDTH;
2398 }
2399 CG_DrawStringExt( 320 - w * cw/2, 20,s, colorWhite,
2400 qfalse, qtrue, cw, (int)(cw * 1.5f), 0 );
2401 #endif
2402 }
2403 } else {
2404 if ( cgs.gametype == GT_FFA ) {
2405 s = "Free For All";
2406 } else if ( cgs.gametype == GT_TEAM ) {
2407 s = "Team Deathmatch";
2408 } else if ( cgs.gametype == GT_CTF ) {
2409 s = "Capture the Flag";
2410 #ifdef MISSIONPACK
2411 } else if ( cgs.gametype == GT_1FCTF ) {
2412 s = "One Flag CTF";
2413 } else if ( cgs.gametype == GT_OBELISK ) {
2414 s = "Overload";
2415 } else if ( cgs.gametype == GT_HARVESTER ) {
2416 s = "Harvester";
2417 #endif
2418 } else {
2419 s = "";
2420 }
2421 #ifdef MISSIONPACK
2422 w = CG_Text_Width(s, 0.6f, 0);
2423 CG_Text_Paint(320 - w / 2, 90, 0.6f, colorWhite, s, 0, 0, ITEM_TEXTSTYLE_SHADOWEDMORE);
2424 #else
2425 w = CG_DrawStrlen( s );
2426 if ( w > 640 / GIANT_WIDTH ) {
2427 cw = 640 / w;
2428 } else {
2429 cw = GIANT_WIDTH;
2430 }
2431 CG_DrawStringExt( 320 - w * cw/2, 25,s, colorWhite,
2432 qfalse, qtrue, cw, (int)(cw * 1.1f), 0 );
2433 #endif
2434 }
2435
2436 sec = ( sec - cg.time ) / 1000;
2437 if ( sec < 0 ) {
2438 cg.warmup = 0;
2439 sec = 0;
2440 }
2441 s = va( "Starts in: %i", sec + 1 );
2442 if ( sec != cg.warmupCount ) {
2443 cg.warmupCount = sec;
2444 switch ( sec ) {
2445 case 0:
2446 trap_S_StartLocalSound( cgs.media.count1Sound, CHAN_ANNOUNCER );
2447 break;
2448 case 1:
2449 trap_S_StartLocalSound( cgs.media.count2Sound, CHAN_ANNOUNCER );
2450 break;
2451 case 2:
2452 trap_S_StartLocalSound( cgs.media.count3Sound, CHAN_ANNOUNCER );
2453 break;
2454 default:
2455 break;
2456 }
2457 }
2458
2459 #ifdef MISSIONPACK
2460 switch ( cg.warmupCount ) {
2461 case 0:
2462 scale = 0.54f;
2463 break;
2464 case 1:
2465 scale = 0.51f;
2466 break;
2467 case 2:
2468 scale = 0.48f;
2469 break;
2470 default:
2471 scale = 0.45f;
2472 break;
2473 }
2474
2475 w = CG_Text_Width(s, scale, 0);
2476 CG_Text_Paint(320 - w / 2, 125, scale, colorWhite, s, 0, 0, ITEM_TEXTSTYLE_SHADOWEDMORE);
2477 #else
2478 switch ( cg.warmupCount ) {
2479 case 0:
2480 cw = 28;
2481 break;
2482 case 1:
2483 cw = 24;
2484 break;
2485 case 2:
2486 cw = 20;
2487 break;
2488 default:
2489 cw = 16;
2490 break;
2491 }
2492
2493 w = CG_DrawStrlen( s );
2494 CG_DrawStringExt( 320 - w * cw/2, 70, s, colorWhite,
2495 qfalse, qtrue, cw, (int)(cw * 1.5), 0 );
2496 #endif
2497 }
2498
2499 //==================================================================================
2500 #ifdef MISSIONPACK
2501 /*
2502 =================
2503 CG_DrawTimedMenus
2504 =================
2505 */
2506 void CG_DrawTimedMenus( void ) {
2507 if (cg.voiceTime) {
2508 int t = cg.time - cg.voiceTime;
2509 if ( t > 2500 ) {
2510 Menus_CloseByName("voiceMenu");
2511 trap_Cvar_Set("cl_conXOffset", "0");
2512 cg.voiceTime = 0;
2513 }
2514 }
2515 }
2516 #endif
2517 /*
2518 =================
2519 CG_Draw2D
2520 =================
2521 */
2522 static void CG_Draw2D(stereoFrame_t stereoFrame)
2523 {
2524 #ifdef MISSIONPACK
2525 if (cgs.orderPending && cg.time > cgs.orderTime) {
2526 CG_CheckOrderPending();
2527 }
2528 #endif
2529 // if we are taking a levelshot for the menu, don't draw anything
2530 if ( cg.levelShot ) {
2531 return;
2532 }
2533
2534 if ( cg_draw2D.integer == 0 ) {
2535 return;
2536 }
2537
2538 if ( cg.snap->ps.pm_type == PM_INTERMISSION ) {
2539 CG_DrawIntermission();
2540 return;
2541 }
2542
2543 /*
2544 if (cg.cameraMode) {
2545 return;
2546 }
2547 */
2548 if ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_SPECTATOR ) {
2549 CG_DrawSpectator();
2550
2551 if(stereoFrame == STEREO_CENTER)
2552 CG_DrawCrosshair();
2553
2554 CG_DrawCrosshairNames();
2555 } else {
2556 // don't draw any status if dead or the scoreboard is being explicitly shown
2557 if ( !cg.showScores && cg.snap->ps.stats[STAT_HEALTH] > 0 ) {
2558
2559 #ifdef MISSIONPACK
2560 if ( cg_drawStatus.integer ) {
2561 Menu_PaintAll();
2562 CG_DrawTimedMenus();
2563 }
2564 #else
2565 CG_DrawStatusBar();
2566 #endif
2567
2568 CG_DrawAmmoWarning();
2569
2570 #ifdef MISSIONPACK
2571 CG_DrawProxWarning();
2572 #endif
2573 if(stereoFrame == STEREO_CENTER)
2574 CG_DrawCrosshair();
2575 CG_DrawCrosshairNames();
2576 CG_DrawWeaponSelect();
2577
2578 #ifndef MISSIONPACK
2579 CG_DrawHoldableItem();
2580 #else
2581 //CG_DrawPersistantPowerup();
2582 #endif
2583 CG_DrawReward();
2584 }
2585 }
2586
2587 if ( cgs.gametype >= GT_TEAM ) {
2588 #ifndef MISSIONPACK
2589 CG_DrawTeamInfo();
2590 #endif
2591 }
2592
2593 CG_DrawVote();
2594 CG_DrawTeamVote();
2595
2596 CG_DrawLagometer();
2597
2598 #ifdef MISSIONPACK
2599 if (!cg_paused.integer) {
2600 CG_DrawUpperRight(stereoFrame);
2601 }
2602 #else
2603 CG_DrawUpperRight(stereoFrame);
2604 #endif
2605
2606 #ifndef MISSIONPACK
2607 CG_DrawLowerRight();
2608 CG_DrawLowerLeft();
2609 #endif
2610
2611 if ( !CG_DrawFollow() ) {
2612 CG_DrawWarmup();
2613 }
2614
2615 // don't draw center string if scoreboard is up
2616 cg.scoreBoardShowing = CG_DrawScoreboard();
2617 if ( !cg.scoreBoardShowing) {
2618 CG_DrawCenterString();
2619 }
2620 }
2621
2622
2623 /*
2624 =====================
2625 CG_DrawActive
2626
2627 Perform all drawing needed to completely fill the screen
2628 =====================
2629 */
2630 void CG_DrawActive( stereoFrame_t stereoView ) {
2631 // optionally draw the info screen instead
2632 if ( !cg.snap ) {
2633 CG_DrawInformation();
2634 return;
2635 }
2636
2637 // optionally draw the tournement scoreboard instead
2638 if ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_SPECTATOR &&
2639 ( cg.snap->ps.pm_flags & PMF_SCOREBOARD ) ) {
2640 CG_DrawTourneyScoreboard();
2641 return;
2642 }
2643
2644 // clear around the rendered view if sized down
2645 CG_TileClear();
2646
2647 if(stereoView != STEREO_CENTER)
2648 CG_DrawCrosshair3D();
2649
2650 // draw 3D view
2651 trap_R_RenderScene( &cg.refdef );
2652
2653 // draw status bar and other floating elements
2654 CG_Draw2D(stereoView);
2655 }
2656
2657
2658