static crosshair is now drawn during sbar stage (where it should be), fixes the bug...
[divverent/darkplaces.git] / sbar.c
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20 // sbar.c -- status bar code
21
22 #include "quakedef.h"
23
24 typedef struct
25 {
26         char name[32];
27 }
28 sbarpic_t;
29
30 static sbarpic_t sbarpics[256];
31 static int numsbarpics;
32
33 static sbarpic_t *Sbar_NewPic(const char *name)
34 {
35         strcpy(sbarpics[numsbarpics].name, name);
36         // precache it
37         // FIXME: precache on every renderer restart (or move this to client)
38         Draw_CachePic(sbarpics[numsbarpics].name);
39         return sbarpics + (numsbarpics++);
40 }
41
42 sbarpic_t *sb_disc;
43
44 #define STAT_MINUS 10 // num frame for '-' stats digit
45 sbarpic_t *sb_nums[2][11];
46 sbarpic_t *sb_colon, *sb_slash;
47 sbarpic_t *sb_ibar;
48 sbarpic_t *sb_sbar;
49 sbarpic_t *sb_scorebar;
50
51 sbarpic_t *sb_weapons[7][8]; // 0 is active, 1 is owned, 2-5 are flashes
52 sbarpic_t *sb_ammo[4];
53 sbarpic_t *sb_sigil[4];
54 sbarpic_t *sb_armor[3];
55 sbarpic_t *sb_items[32];
56
57 // 0-4 are based on health (in 20 increments)
58 // 0 is static, 1 is temporary animation
59 sbarpic_t *sb_faces[5][2];
60
61 sbarpic_t *sb_face_invis;
62 sbarpic_t *sb_face_quad;
63 sbarpic_t *sb_face_invuln;
64 sbarpic_t *sb_face_invis_invuln;
65
66 qboolean sb_showscores;
67
68 int sb_lines;                   // scan lines to draw
69
70 sbarpic_t *rsb_invbar[2];
71 sbarpic_t *rsb_weapons[5];
72 sbarpic_t *rsb_items[2];
73 sbarpic_t *rsb_ammo[3];
74 sbarpic_t *rsb_teambord;                // PGM 01/19/97 - team color border
75
76 //MED 01/04/97 added two more weapons + 3 alternates for grenade launcher
77 sbarpic_t *hsb_weapons[7][5];   // 0 is active, 1 is owned, 2-5 are flashes
78 //MED 01/04/97 added array to simplify weapon parsing
79 int hipweapons[4] = {HIT_LASER_CANNON_BIT,HIT_MJOLNIR_BIT,4,HIT_PROXIMITY_GUN_BIT};
80 //MED 01/04/97 added hipnotic items array
81 sbarpic_t *hsb_items[2];
82
83 cvar_t  showfps = {CVAR_SAVE, "showfps", "0"};
84
85 void Sbar_MiniDeathmatchOverlay (void);
86 void Sbar_DeathmatchOverlay (void);
87 void Sbar_IntermissionOverlay (void);
88 void Sbar_FinaleOverlay (void);
89
90
91 /*
92 ===============
93 Sbar_ShowScores
94
95 Tab key down
96 ===============
97 */
98 void Sbar_ShowScores (void)
99 {
100         if (sb_showscores)
101                 return;
102         sb_showscores = true;
103 }
104
105 /*
106 ===============
107 Sbar_DontShowScores
108
109 Tab key up
110 ===============
111 */
112 void Sbar_DontShowScores (void)
113 {
114         sb_showscores = false;
115 }
116
117 void sbar_start(void)
118 {
119         int i;
120
121         numsbarpics = 0;
122
123         sb_disc = Sbar_NewPic("gfx/disc");
124
125         for (i = 0;i < 10;i++)
126         {
127                 sb_nums[0][i] = Sbar_NewPic (va("gfx/num_%i",i));
128                 sb_nums[1][i] = Sbar_NewPic (va("gfx/anum_%i",i));
129         }
130
131         sb_nums[0][10] = Sbar_NewPic ("gfx/num_minus");
132         sb_nums[1][10] = Sbar_NewPic ("gfx/anum_minus");
133
134         sb_colon = Sbar_NewPic ("gfx/num_colon");
135         sb_slash = Sbar_NewPic ("gfx/num_slash");
136
137         sb_weapons[0][0] = Sbar_NewPic ("gfx/inv_shotgun");
138         sb_weapons[0][1] = Sbar_NewPic ("gfx/inv_sshotgun");
139         sb_weapons[0][2] = Sbar_NewPic ("gfx/inv_nailgun");
140         sb_weapons[0][3] = Sbar_NewPic ("gfx/inv_snailgun");
141         sb_weapons[0][4] = Sbar_NewPic ("gfx/inv_rlaunch");
142         sb_weapons[0][5] = Sbar_NewPic ("gfx/inv_srlaunch");
143         sb_weapons[0][6] = Sbar_NewPic ("gfx/inv_lightng");
144
145         sb_weapons[1][0] = Sbar_NewPic ("gfx/inv2_shotgun");
146         sb_weapons[1][1] = Sbar_NewPic ("gfx/inv2_sshotgun");
147         sb_weapons[1][2] = Sbar_NewPic ("gfx/inv2_nailgun");
148         sb_weapons[1][3] = Sbar_NewPic ("gfx/inv2_snailgun");
149         sb_weapons[1][4] = Sbar_NewPic ("gfx/inv2_rlaunch");
150         sb_weapons[1][5] = Sbar_NewPic ("gfx/inv2_srlaunch");
151         sb_weapons[1][6] = Sbar_NewPic ("gfx/inv2_lightng");
152
153         for (i = 0;i < 5;i++)
154         {
155                 sb_weapons[2+i][0] = Sbar_NewPic (va("gfx/inva%i_shotgun",i+1));
156                 sb_weapons[2+i][1] = Sbar_NewPic (va("gfx/inva%i_sshotgun",i+1));
157                 sb_weapons[2+i][2] = Sbar_NewPic (va("gfx/inva%i_nailgun",i+1));
158                 sb_weapons[2+i][3] = Sbar_NewPic (va("gfx/inva%i_snailgun",i+1));
159                 sb_weapons[2+i][4] = Sbar_NewPic (va("gfx/inva%i_rlaunch",i+1));
160                 sb_weapons[2+i][5] = Sbar_NewPic (va("gfx/inva%i_srlaunch",i+1));
161                 sb_weapons[2+i][6] = Sbar_NewPic (va("gfx/inva%i_lightng",i+1));
162         }
163
164         sb_ammo[0] = Sbar_NewPic ("gfx/sb_shells");
165         sb_ammo[1] = Sbar_NewPic ("gfx/sb_nails");
166         sb_ammo[2] = Sbar_NewPic ("gfx/sb_rocket");
167         sb_ammo[3] = Sbar_NewPic ("gfx/sb_cells");
168
169         sb_armor[0] = Sbar_NewPic ("gfx/sb_armor1");
170         sb_armor[1] = Sbar_NewPic ("gfx/sb_armor2");
171         sb_armor[2] = Sbar_NewPic ("gfx/sb_armor3");
172
173         sb_items[0] = Sbar_NewPic ("gfx/sb_key1");
174         sb_items[1] = Sbar_NewPic ("gfx/sb_key2");
175         sb_items[2] = Sbar_NewPic ("gfx/sb_invis");
176         sb_items[3] = Sbar_NewPic ("gfx/sb_invuln");
177         sb_items[4] = Sbar_NewPic ("gfx/sb_suit");
178         sb_items[5] = Sbar_NewPic ("gfx/sb_quad");
179
180         sb_sigil[0] = Sbar_NewPic ("gfx/sb_sigil1");
181         sb_sigil[1] = Sbar_NewPic ("gfx/sb_sigil2");
182         sb_sigil[2] = Sbar_NewPic ("gfx/sb_sigil3");
183         sb_sigil[3] = Sbar_NewPic ("gfx/sb_sigil4");
184
185         sb_faces[4][0] = Sbar_NewPic ("gfx/face1");
186         sb_faces[4][1] = Sbar_NewPic ("gfx/face_p1");
187         sb_faces[3][0] = Sbar_NewPic ("gfx/face2");
188         sb_faces[3][1] = Sbar_NewPic ("gfx/face_p2");
189         sb_faces[2][0] = Sbar_NewPic ("gfx/face3");
190         sb_faces[2][1] = Sbar_NewPic ("gfx/face_p3");
191         sb_faces[1][0] = Sbar_NewPic ("gfx/face4");
192         sb_faces[1][1] = Sbar_NewPic ("gfx/face_p4");
193         sb_faces[0][0] = Sbar_NewPic ("gfx/face5");
194         sb_faces[0][1] = Sbar_NewPic ("gfx/face_p5");
195
196         sb_face_invis = Sbar_NewPic ("gfx/face_invis");
197         sb_face_invuln = Sbar_NewPic ("gfx/face_invul2");
198         sb_face_invis_invuln = Sbar_NewPic ("gfx/face_inv2");
199         sb_face_quad = Sbar_NewPic ("gfx/face_quad");
200
201         sb_sbar = Sbar_NewPic ("gfx/sbar");
202         sb_ibar = Sbar_NewPic ("gfx/ibar");
203         sb_scorebar = Sbar_NewPic ("gfx/scorebar");
204
205 //MED 01/04/97 added new hipnotic weapons
206         if (gamemode == GAME_HIPNOTIC)
207         {
208                 hsb_weapons[0][0] = Sbar_NewPic ("gfx/inv_laser");
209                 hsb_weapons[0][1] = Sbar_NewPic ("gfx/inv_mjolnir");
210                 hsb_weapons[0][2] = Sbar_NewPic ("gfx/inv_gren_prox");
211                 hsb_weapons[0][3] = Sbar_NewPic ("gfx/inv_prox_gren");
212                 hsb_weapons[0][4] = Sbar_NewPic ("gfx/inv_prox");
213
214                 hsb_weapons[1][0] = Sbar_NewPic ("gfx/inv2_laser");
215                 hsb_weapons[1][1] = Sbar_NewPic ("gfx/inv2_mjolnir");
216                 hsb_weapons[1][2] = Sbar_NewPic ("gfx/inv2_gren_prox");
217                 hsb_weapons[1][3] = Sbar_NewPic ("gfx/inv2_prox_gren");
218                 hsb_weapons[1][4] = Sbar_NewPic ("gfx/inv2_prox");
219
220                 for (i = 0;i < 5;i++)
221                 {
222                         hsb_weapons[2+i][0] = Sbar_NewPic (va("gfx/inva%i_laser",i+1));
223                         hsb_weapons[2+i][1] = Sbar_NewPic (va("gfx/inva%i_mjolnir",i+1));
224                         hsb_weapons[2+i][2] = Sbar_NewPic (va("gfx/inva%i_gren_prox",i+1));
225                         hsb_weapons[2+i][3] = Sbar_NewPic (va("gfx/inva%i_prox_gren",i+1));
226                         hsb_weapons[2+i][4] = Sbar_NewPic (va("gfx/inva%i_prox",i+1));
227                 }
228
229                 hsb_items[0] = Sbar_NewPic ("gfx/sb_wsuit");
230                 hsb_items[1] = Sbar_NewPic ("gfx/sb_eshld");
231         }
232         else if (gamemode == GAME_ROGUE)
233         {
234                 rsb_invbar[0] = Sbar_NewPic ("gfx/r_invbar1");
235                 rsb_invbar[1] = Sbar_NewPic ("gfx/r_invbar2");
236
237                 rsb_weapons[0] = Sbar_NewPic ("gfx/r_lava");
238                 rsb_weapons[1] = Sbar_NewPic ("gfx/r_superlava");
239                 rsb_weapons[2] = Sbar_NewPic ("gfx/r_gren");
240                 rsb_weapons[3] = Sbar_NewPic ("gfx/r_multirock");
241                 rsb_weapons[4] = Sbar_NewPic ("gfx/r_plasma");
242
243                 rsb_items[0] = Sbar_NewPic ("gfx/r_shield1");
244                 rsb_items[1] = Sbar_NewPic ("gfx/r_agrav1");
245
246 // PGM 01/19/97 - team color border
247                 rsb_teambord = Sbar_NewPic ("gfx/r_teambord");
248 // PGM 01/19/97 - team color border
249
250                 rsb_ammo[0] = Sbar_NewPic ("gfx/r_ammolava");
251                 rsb_ammo[1] = Sbar_NewPic ("gfx/r_ammomulti");
252                 rsb_ammo[2] = Sbar_NewPic ("gfx/r_ammoplasma");
253         }
254 }
255
256 void sbar_shutdown(void)
257 {
258 }
259
260 void sbar_newmap(void)
261 {
262 }
263
264 void Sbar_Init (void)
265 {
266         Cmd_AddCommand ("+showscores", Sbar_ShowScores);
267         Cmd_AddCommand ("-showscores", Sbar_DontShowScores);
268         Cvar_RegisterVariable (&showfps);
269
270         R_RegisterModule("sbar", sbar_start, sbar_shutdown, sbar_newmap);
271 }
272
273
274 //=============================================================================
275
276 // drawing routines are relative to the status bar location
277
278 int sbar_x, sbar_y;
279
280 /*
281 =============
282 Sbar_DrawPic
283 =============
284 */
285 void Sbar_DrawPic (int x, int y, sbarpic_t *sbarpic)
286 {
287         DrawQ_Pic (sbar_x + x, sbar_y + y, sbarpic->name, 0, 0, 1, 1, 1, 1, 0);
288 }
289
290 void Sbar_DrawAlphaPic (int x, int y, sbarpic_t *sbarpic, float alpha)
291 {
292         DrawQ_Pic (sbar_x + x, sbar_y + y, sbarpic->name, 0, 0, 1, 1, 1, alpha, 0);
293 }
294
295 /*
296 ================
297 Sbar_DrawCharacter
298
299 Draws one solid graphics character
300 ================
301 */
302 void Sbar_DrawCharacter (int x, int y, int num)
303 {
304         DrawQ_String (sbar_x + x + 4 , sbar_y + y, va("%c", num), 0, 8, 8, 1, 1, 1, 1, 0);
305 }
306
307 /*
308 ================
309 Sbar_DrawString
310 ================
311 */
312 void Sbar_DrawString (int x, int y, char *str)
313 {
314         DrawQ_String (sbar_x + x, sbar_y + y, str, 0, 8, 8, 1, 1, 1, 1, 0);
315 }
316
317 /*
318 =============
319 Sbar_DrawNum
320 =============
321 */
322 void Sbar_DrawNum (int x, int y, int num, int digits, int color)
323 {
324         char str[32], *ptr;
325         int l, frame;
326
327         l = sprintf(str, "%i", num);
328         ptr = str;
329         if (l > digits)
330                 ptr += (l-digits);
331         if (l < digits)
332                 x += (digits-l)*24;
333
334         while (*ptr)
335         {
336                 if (*ptr == '-')
337                         frame = STAT_MINUS;
338                 else
339                         frame = *ptr -'0';
340
341                 Sbar_DrawPic (x, y, sb_nums[color][frame]);
342                 x += 24;
343                 ptr++;
344         }
345 }
346
347 //=============================================================================
348
349 int             fragsort[MAX_SCOREBOARD];
350
351 char    scoreboardtext[MAX_SCOREBOARD][20];
352 int             scoreboardtop[MAX_SCOREBOARD];
353 int             scoreboardbottom[MAX_SCOREBOARD];
354 int             scoreboardcount[MAX_SCOREBOARD];
355 int             scoreboardlines;
356
357 /*
358 ===============
359 Sbar_SortFrags
360 ===============
361 */
362 void Sbar_SortFrags (void)
363 {
364         int             i, j, k;
365
366 // sort by frags
367         scoreboardlines = 0;
368         for (i=0 ; i<cl.maxclients ; i++)
369         {
370                 if (cl.scores[i].name[0])
371                 {
372                         fragsort[scoreboardlines] = i;
373                         scoreboardlines++;
374                 }
375         }
376
377         for (i=0 ; i<scoreboardlines ; i++)
378                 for (j=0 ; j<scoreboardlines-1-i ; j++)
379                         if (cl.scores[fragsort[j]].frags < cl.scores[fragsort[j+1]].frags)
380                         {
381                                 k = fragsort[j];
382                                 fragsort[j] = fragsort[j+1];
383                                 fragsort[j+1] = k;
384                         }
385 }
386
387 /*
388 ===============
389 Sbar_UpdateScoreboard
390 ===============
391 */
392 void Sbar_UpdateScoreboard (void)
393 {
394         int             i, k;
395         int             top, bottom;
396         scoreboard_t    *s;
397
398         Sbar_SortFrags ();
399
400 // draw the text
401         memset (scoreboardtext, 0, sizeof(scoreboardtext));
402
403         for (i=0 ; i<scoreboardlines; i++)
404         {
405                 k = fragsort[i];
406                 s = &cl.scores[k];
407                 sprintf (&scoreboardtext[i][1], "%3i %s", s->frags, s->name);
408
409                 top = s->colors & 0xf0;
410                 bottom = (s->colors & 15) <<4;
411                 scoreboardtop[i] = top + 8;
412                 scoreboardbottom[i] = bottom + 8;
413         }
414 }
415
416
417 /*
418 ===============
419 Sbar_SoloScoreboard
420 ===============
421 */
422 void Sbar_SoloScoreboard (void)
423 {
424         char    str[80];
425         int             minutes, seconds, tens, units;
426         int             l;
427
428         sprintf (str,"Monsters:%3i /%3i", cl.stats[STAT_MONSTERS], cl.stats[STAT_TOTALMONSTERS]);
429         Sbar_DrawString (8, 4, str);
430
431         sprintf (str,"Secrets :%3i /%3i", cl.stats[STAT_SECRETS], cl.stats[STAT_TOTALSECRETS]);
432         Sbar_DrawString (8, 12, str);
433
434 // time
435         minutes = cl.time / 60;
436         seconds = cl.time - 60*minutes;
437         tens = seconds / 10;
438         units = seconds - 10*tens;
439         sprintf (str,"Time :%3i:%i%i", minutes, tens, units);
440         Sbar_DrawString (184, 4, str);
441
442 // draw level name
443         l = strlen (cl.levelname);
444         Sbar_DrawString (232 - l*4, 12, cl.levelname);
445 }
446
447 /*
448 ===============
449 Sbar_DrawScoreboard
450 ===============
451 */
452 void Sbar_DrawScoreboard (void)
453 {
454         Sbar_SoloScoreboard ();
455         if (cl.gametype == GAME_DEATHMATCH)
456                 Sbar_DeathmatchOverlay ();
457 }
458
459 //=============================================================================
460
461 /*
462 ===============
463 Sbar_DrawInventory
464 ===============
465 */
466 void Sbar_DrawInventory (void)
467 {
468         int             i;
469         char    num[6];
470         float   time;
471         int             flashon;
472
473         if (gamemode == GAME_ROGUE)
474         {
475                 if ( cl.stats[STAT_ACTIVEWEAPON] >= RIT_LAVA_NAILGUN )
476                         Sbar_DrawAlphaPic (0, -24, rsb_invbar[0], 0.4);
477                 else
478                         Sbar_DrawAlphaPic (0, -24, rsb_invbar[1], 0.4);
479         }
480         else
481                 Sbar_DrawAlphaPic (0, -24, sb_ibar, 0.4);
482
483         // weapons
484         for (i=0 ; i<7 ; i++)
485         {
486                 if (cl.items & (IT_SHOTGUN<<i) )
487                 {
488                         time = cl.item_gettime[i];
489                         flashon = (int)((cl.time - time)*10);
490                         if (flashon >= 10)
491                         {
492                                 if ( cl.stats[STAT_ACTIVEWEAPON] == (IT_SHOTGUN<<i)  )
493                                         flashon = 1;
494                                 else
495                                         flashon = 0;
496                         }
497                         else
498                                 flashon = (flashon%5) + 2;
499
500                         Sbar_DrawAlphaPic (i*24, -16, sb_weapons[flashon][i], 0.4);
501                 }
502         }
503
504         // MED 01/04/97
505         // hipnotic weapons
506         if (gamemode == GAME_HIPNOTIC)
507         {
508                 int grenadeflashing=0;
509                 for (i=0 ; i<4 ; i++)
510                 {
511                         if (cl.items & (1<<hipweapons[i]) )
512                         {
513                                 time = cl.item_gettime[hipweapons[i]];
514                                 flashon = (int)((cl.time - time)*10);
515                                 if (flashon >= 10)
516                                 {
517                                         if ( cl.stats[STAT_ACTIVEWEAPON] == (1<<hipweapons[i])  )
518                                                 flashon = 1;
519                                         else
520                                                 flashon = 0;
521                                 }
522                                 else
523                                         flashon = (flashon%5) + 2;
524
525                                 // check grenade launcher
526                                 if (i==2)
527                                 {
528                                         if (cl.items & HIT_PROXIMITY_GUN)
529                                         {
530                                                 if (flashon)
531                                                 {
532                                                         grenadeflashing = 1;
533                                                         Sbar_DrawPic (96, -16, hsb_weapons[flashon][2]);
534                                                 }
535                                         }
536                                 }
537                                 else if (i==3)
538                                 {
539                                         if (cl.items & (IT_SHOTGUN<<4))
540                                         {
541                                                 if (!grenadeflashing)
542                                                         Sbar_DrawPic (96, -16, hsb_weapons[flashon][3]);
543                                         }
544                                         else
545                                                 Sbar_DrawPic (96, -16, hsb_weapons[flashon][4]);
546                                 }
547                                 else
548                                         Sbar_DrawPic (176 + (i*24), -16, hsb_weapons[flashon][i]);
549                         }
550                 }
551         }
552
553         if (gamemode == GAME_ROGUE)
554         {
555                 // check for powered up weapon.
556                 if ( cl.stats[STAT_ACTIVEWEAPON] >= RIT_LAVA_NAILGUN )
557                         for (i=0;i<5;i++)
558                                 if (cl.stats[STAT_ACTIVEWEAPON] == (RIT_LAVA_NAILGUN << i))
559                                         Sbar_DrawPic ((i+2)*24, -16, rsb_weapons[i]);
560         }
561
562         // ammo counts
563         for (i=0 ; i<4 ; i++)
564         {
565                 sprintf (num, "%3i",cl.stats[STAT_SHELLS+i] );
566                 if (num[0] != ' ')
567                         Sbar_DrawCharacter ( (6*i+1)*8 - 2, -24, 18 + num[0] - '0');
568                 if (num[1] != ' ')
569                         Sbar_DrawCharacter ( (6*i+2)*8 - 2, -24, 18 + num[1] - '0');
570                 if (num[2] != ' ')
571                         Sbar_DrawCharacter ( (6*i+3)*8 - 2, -24, 18 + num[2] - '0');
572         }
573
574         // items
575         for (i=0 ; i<6 ; i++)
576                 if (cl.items & (1<<(17+i)))
577                 {
578                         //MED 01/04/97 changed keys
579                         if (gamemode != GAME_HIPNOTIC || (i>1))
580                                 Sbar_DrawPic (192 + i*16, -16, sb_items[i]);
581                 }
582
583         //MED 01/04/97 added hipnotic items
584         // hipnotic items
585         if (gamemode == GAME_HIPNOTIC)
586         {
587                 for (i=0 ; i<2 ; i++)
588                         if (cl.items & (1<<(24+i)))
589                                 Sbar_DrawPic (288 + i*16, -16, hsb_items[i]);
590         }
591
592         if (gamemode == GAME_ROGUE)
593         {
594                 // new rogue items
595                 for (i=0 ; i<2 ; i++)
596                         if (cl.items & (1<<(29+i)))
597                                 Sbar_DrawPic (288 + i*16, -16, rsb_items[i]);
598         }
599         else
600         {
601                 // sigils
602                 for (i=0 ; i<4 ; i++)
603                         if (cl.items & (1<<(28+i)))
604                                 Sbar_DrawPic (320-32 + i*8, -16, sb_sigil[i]);
605         }
606 }
607
608 //=============================================================================
609
610 /*
611 ===============
612 Sbar_DrawFrags
613 ===============
614 */
615 void Sbar_DrawFrags (void)
616 {
617         int i, k, l, x, f;
618         char num[12];
619         scoreboard_t *s;
620         qbyte *c;
621
622         Sbar_SortFrags ();
623
624         // draw the text
625         l = scoreboardlines <= 4 ? scoreboardlines : 4;
626
627         x = 23 * 8;
628
629         for (i = 0;i < l;i++)
630         {
631                 k = fragsort[i];
632                 s = &cl.scores[k];
633                 if (!s->name[0])
634                         continue;
635
636                 // draw background
637                 c = (qbyte *)&d_8to24table[(s->colors & 0xf0) + 8];
638                 DrawQ_Fill (sbar_x + x + 10, sbar_y     - 23, 28, 4, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), c[3] * (1.0f / 255.0f), 0);
639                 c = (qbyte *)&d_8to24table[((s->colors & 15)<<4) + 8];
640                 DrawQ_Fill (sbar_x + x + 10, sbar_y + 4 - 23, 28, 3, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), c[3] * (1.0f / 255.0f), 0);
641
642                 // draw number
643                 f = s->frags;
644                 sprintf (num, "%3i",f);
645
646                 Sbar_DrawCharacter (x +  8, -24, num[0]);
647                 Sbar_DrawCharacter (x + 16, -24, num[1]);
648                 Sbar_DrawCharacter (x + 24, -24, num[2]);
649
650                 if (k == cl.viewentity - 1)
651                 {
652                         Sbar_DrawCharacter ( x      + 2, -24, 16);
653                         Sbar_DrawCharacter ( x + 32 - 4, -24, 17);
654                 }
655                 x += 32;
656         }
657 }
658
659 //=============================================================================
660
661
662 /*
663 ===============
664 Sbar_DrawFace
665 ===============
666 */
667 void Sbar_DrawFace (void)
668 {
669         int f;
670
671 // PGM 01/19/97 - team color drawing
672 // PGM 03/02/97 - fixed so color swatch only appears in CTF modes
673         if (gamemode == GAME_ROGUE && (cl.maxclients != 1) && (teamplay.integer > 3) && (teamplay.integer < 7))
674         {
675                 char num[12];
676                 scoreboard_t *s;
677                 qbyte *c;
678
679                 s = &cl.scores[cl.viewentity - 1];
680                 // draw background
681                 Sbar_DrawPic (112, 0, rsb_teambord);
682                 c = (qbyte *)&d_8to24table[(s->colors & 0xf0) + 8];
683                 DrawQ_Fill (sbar_x + 113, vid.conheight-SBAR_HEIGHT+3, 22, 9, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), c[3] * (1.0f / 255.0f), 0);
684                 c = (qbyte *)&d_8to24table[((s->colors & 15)<<4) + 8];
685                 DrawQ_Fill (sbar_x + 113, vid.conheight-SBAR_HEIGHT+12, 22, 9, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), c[3] * (1.0f / 255.0f), 0);
686
687                 // draw number
688                 f = s->frags;
689                 sprintf (num, "%3i",f);
690
691                 if ((s->colors & 0xf0)==0)
692                 {
693                         if (num[0] != ' ')
694                                 Sbar_DrawCharacter(109, 3, 18 + num[0] - '0');
695                         if (num[1] != ' ')
696                                 Sbar_DrawCharacter(116, 3, 18 + num[1] - '0');
697                         if (num[2] != ' ')
698                                 Sbar_DrawCharacter(123, 3, 18 + num[2] - '0');
699                 }
700                 else
701                 {
702                         Sbar_DrawCharacter ( 109, 3, num[0]);
703                         Sbar_DrawCharacter ( 116, 3, num[1]);
704                         Sbar_DrawCharacter ( 123, 3, num[2]);
705                 }
706
707                 return;
708         }
709 // PGM 01/19/97 - team color drawing
710
711         if ( (cl.items & (IT_INVISIBILITY | IT_INVULNERABILITY) ) == (IT_INVISIBILITY | IT_INVULNERABILITY) )
712                 Sbar_DrawPic (112, 0, sb_face_invis_invuln);
713         else if (cl.items & IT_QUAD)
714                 Sbar_DrawPic (112, 0, sb_face_quad );
715         else if (cl.items & IT_INVISIBILITY)
716                 Sbar_DrawPic (112, 0, sb_face_invis );
717         else if (cl.items & IT_INVULNERABILITY)
718                 Sbar_DrawPic (112, 0, sb_face_invuln);
719         else
720         {
721                 f = cl.stats[STAT_HEALTH] / 20;
722                 f = bound(0, f, 4);
723                 Sbar_DrawPic (112, 0, sb_faces[f][cl.time <= cl.faceanimtime]);
724         }
725 }
726
727 void Sbar_ShowFPS(void)
728 {
729         if (showfps.integer)
730         {
731                 int calc;
732                 char temp[32];
733                 float fps_x, fps_y, fps_scalex, fps_scaley;
734                 if (showfps.integer > 1)
735                 {
736                         static double currtime, frametimes[32];
737                         double newtime, total;
738                         int count, i;
739                         static int framecycle = 0;
740
741                         newtime = Sys_DoubleTime();
742                         frametimes[framecycle] = newtime - currtime;
743                         total = 0;
744                         count = 0;
745                         while(total < 0.2 && count < 32 && frametimes[i = (framecycle - count) & 31])
746                         {
747                                 total += frametimes[i];
748                                 count++;
749                         }
750                         framecycle++;
751                         framecycle &= 31;
752                         if (showfps.integer == 2)
753                                 calc = (int) (((double) count / total) + 0.5);
754                         else // showfps 3, rapid update
755                                 calc = (int) ((1.0 / (newtime - currtime)) + 0.5);
756                         currtime = newtime;
757                 }
758                 else
759                 {
760                         static double nexttime = 0, lasttime = 0;
761                         static int framerate = 0, framecount = 0;
762                         double newtime;
763                         newtime = Sys_DoubleTime();
764                         if (newtime < nexttime)
765                                 framecount++;
766                         else
767                         {
768                                 framerate = (int) (framecount / (newtime - lasttime) + 0.5);
769                                 lasttime = newtime;
770                                 nexttime = lasttime + 0.2;
771                                 framecount = 1;
772                         }
773                         calc = framerate;
774                 }
775                 sprintf(temp, "%4i", calc);
776                 fps_scalex = 12;
777                 fps_scaley = 12;
778                 fps_x = vid.conwidth - (fps_scalex * strlen(temp));
779                 fps_y = vid.conheight - sb_lines/* - 8*/; // yes this might draw over the sbar
780                 if (fps_y > vid.conheight - fps_scaley)
781                         fps_y = vid.conheight - fps_scaley;
782                 DrawQ_Fill(fps_x, fps_y, fps_scalex * strlen(temp), fps_scaley, 0, 0, 0, 0.5, 0);
783                 DrawQ_String(fps_x, fps_y, temp, 0, fps_scalex, fps_scaley, 1, 1, 1, 1, 0);
784         }
785 }
786
787 /*
788 ===============
789 Sbar_Draw
790 ===============
791 */
792 void Sbar_Draw (void)
793 {
794         if (scr_con_current == vid.conheight)
795                 return;         // console is full screen
796
797         if (cl.intermission == 1)
798         {
799                 Sbar_IntermissionOverlay();
800                 return;
801         }
802         else if (cl.intermission == 2)
803         {
804                 Sbar_FinaleOverlay();
805                 return;
806         }
807
808         sbar_y = vid.conheight - SBAR_HEIGHT;
809         if (cl.gametype == GAME_DEATHMATCH)
810                 sbar_x = 0;
811         else
812                 sbar_x = (vid.conwidth - 320)/2;
813
814         if (sb_lines > 24)
815         {
816                 Sbar_DrawInventory ();
817                 if (cl.maxclients != 1)
818                         Sbar_DrawFrags ();
819         }
820
821         if (sb_showscores || cl.stats[STAT_HEALTH] <= 0)
822         {
823                 Sbar_DrawAlphaPic (0, 0, sb_scorebar, 0.4);
824                 Sbar_DrawScoreboard ();
825         }
826         else if (sb_lines)
827         {
828                 Sbar_DrawAlphaPic (0, 0, sb_sbar, 0.4);
829
830 // keys (hipnotic only)
831                 //MED 01/04/97 moved keys here so they would not be overwritten
832                 if (gamemode == GAME_HIPNOTIC)
833                 {
834                         if (cl.items & IT_KEY1)
835                                 Sbar_DrawPic (209, 3, sb_items[0]);
836                         if (cl.items & IT_KEY2)
837                                 Sbar_DrawPic (209, 12, sb_items[1]);
838                 }
839 // armor
840                 if (cl.items & IT_INVULNERABILITY)
841                 {
842                         Sbar_DrawNum (24, 0, 666, 3, 1);
843                         Sbar_DrawPic (0, 0, sb_disc);
844                 }
845                 else
846                 {
847                         if (gamemode == GAME_ROGUE)
848                         {
849                                 Sbar_DrawNum (24, 0, cl.stats[STAT_ARMOR], 3, cl.stats[STAT_ARMOR] <= 25);
850                                 if (cl.items & RIT_ARMOR3)
851                                         Sbar_DrawPic (0, 0, sb_armor[2]);
852                                 else if (cl.items & RIT_ARMOR2)
853                                         Sbar_DrawPic (0, 0, sb_armor[1]);
854                                 else if (cl.items & RIT_ARMOR1)
855                                         Sbar_DrawPic (0, 0, sb_armor[0]);
856                         }
857                         else
858                         {
859                                 Sbar_DrawNum (24, 0, cl.stats[STAT_ARMOR], 3, cl.stats[STAT_ARMOR] <= 25);
860                                 if (cl.items & IT_ARMOR3)
861                                         Sbar_DrawPic (0, 0, sb_armor[2]);
862                                 else if (cl.items & IT_ARMOR2)
863                                         Sbar_DrawPic (0, 0, sb_armor[1]);
864                                 else if (cl.items & IT_ARMOR1)
865                                         Sbar_DrawPic (0, 0, sb_armor[0]);
866                         }
867                 }
868
869         // face
870                 Sbar_DrawFace ();
871
872         // health
873                 Sbar_DrawNum (136, 0, cl.stats[STAT_HEALTH], 3, cl.stats[STAT_HEALTH] <= 25);
874
875         // ammo icon
876                 if (gamemode == GAME_ROGUE)
877                 {
878                         if (cl.items & RIT_SHELLS)
879                                 Sbar_DrawPic (224, 0, sb_ammo[0]);
880                         else if (cl.items & RIT_NAILS)
881                                 Sbar_DrawPic (224, 0, sb_ammo[1]);
882                         else if (cl.items & RIT_ROCKETS)
883                                 Sbar_DrawPic (224, 0, sb_ammo[2]);
884                         else if (cl.items & RIT_CELLS)
885                                 Sbar_DrawPic (224, 0, sb_ammo[3]);
886                         else if (cl.items & RIT_LAVA_NAILS)
887                                 Sbar_DrawPic (224, 0, rsb_ammo[0]);
888                         else if (cl.items & RIT_PLASMA_AMMO)
889                                 Sbar_DrawPic (224, 0, rsb_ammo[1]);
890                         else if (cl.items & RIT_MULTI_ROCKETS)
891                                 Sbar_DrawPic (224, 0, rsb_ammo[2]);
892                 }
893                 else
894                 {
895                         if (cl.items & IT_SHELLS)
896                                 Sbar_DrawPic (224, 0, sb_ammo[0]);
897                         else if (cl.items & IT_NAILS)
898                                 Sbar_DrawPic (224, 0, sb_ammo[1]);
899                         else if (cl.items & IT_ROCKETS)
900                                 Sbar_DrawPic (224, 0, sb_ammo[2]);
901                         else if (cl.items & IT_CELLS)
902                                 Sbar_DrawPic (224, 0, sb_ammo[3]);
903                 }
904
905                 Sbar_DrawNum (248, 0, cl.stats[STAT_AMMO], 3, cl.stats[STAT_AMMO] <= 10);
906         }
907
908         if (vid.conwidth > 320 && cl.gametype == GAME_DEATHMATCH)
909                 Sbar_MiniDeathmatchOverlay ();
910
911         Sbar_ShowFPS();
912
913         R_Draw2DCrosshair();
914 }
915
916 //=============================================================================
917
918 /*
919 ==================
920 Sbar_DeathmatchOverlay
921
922 ==================
923 */
924 void Sbar_DeathmatchOverlay (void)
925 {
926         cachepic_t *pic;
927         int i, k, l, x, y, total, n, minutes, tens, units, fph;
928         char num[128];
929         scoreboard_t *s;
930         qbyte *c;
931
932         pic = Draw_CachePic ("gfx/ranking.lmp");
933         DrawQ_Pic ((vid.conwidth - pic->width)/2, 8, "gfx/ranking.lmp", 0, 0, 1, 1, 1, 1, 0);
934
935 // scores
936         Sbar_SortFrags ();
937
938 // draw the text
939         l = scoreboardlines;
940
941         x = (vid.conwidth - 280)>>1;
942         y = 40;
943         for (i = 0;i < l;i++)
944         {
945                 k = fragsort[i];
946                 s = &cl.scores[k];
947                 if (!s->name[0])
948                         continue;
949
950         // draw background
951                 c = (qbyte *)&d_8to24table[(s->colors & 0xf0) + 8];
952                 DrawQ_Fill ( x + 8, y+1, 88, 3, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), c[3] * (1.0f / 255.0f), 0);
953                 c = (qbyte *)&d_8to24table[((s->colors & 15)<<4) + 8];
954                 DrawQ_Fill ( x + 8, y+4, 88, 3, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), c[3] * (1.0f / 255.0f), 0);
955
956                 total = cl.time - s->entertime;
957                 minutes = (int)total/60;
958                 n = total - minutes*60;
959                 tens = '0' + n/10;
960                 units = '0' + n%10;
961
962                 fph = total ? (int) ((float) s->frags * 3600.0 / total) : 0;
963                 if (fph < -999) fph = -999;
964                 if (fph > 9999) fph = 9999;
965
966                 // put it together
967                 sprintf (num, "%c %4i:%4i %4i:%c%c %s", k == cl.viewentity - 1 ? 12 : ' ', (int) s->frags, fph, minutes, tens, units, s->name);
968                 DrawQ_String(x, y, num, 0, 8, 8, 1, 1, 1, 1, 0);
969
970                 y += 8;
971         }
972 }
973
974 /*
975 ==================
976 Sbar_DeathmatchOverlay
977
978 ==================
979 */
980 void Sbar_MiniDeathmatchOverlay (void)
981 {
982         int i, l, k, x, y, fph, numlines;
983         char num[128];
984         scoreboard_t *s;
985         qbyte *c;
986
987         if (vid.conwidth < 512 || !sb_lines)
988                 return;
989
990         // scores
991         Sbar_SortFrags ();
992
993         // draw the text
994         l = scoreboardlines;
995         y = vid.conheight - sb_lines;
996         numlines = sb_lines/8;
997         if (numlines < 3)
998                 return;
999
1000         //find us
1001         for (i = 0; i < scoreboardlines; i++)
1002                 if (fragsort[i] == cl.viewentity - 1)
1003                         break;
1004
1005         if (i == scoreboardlines) // we're not there
1006                 i = 0;
1007         else // figure out start
1008                 i = i - numlines/2;
1009
1010         if (i > scoreboardlines - numlines)
1011                 i = scoreboardlines - numlines;
1012         if (i < 0)
1013                 i = 0;
1014
1015         x = 324;
1016         for (;i < scoreboardlines && y < vid.conheight - 8;i++)
1017         {
1018                 k = fragsort[i];
1019                 s = &cl.scores[k];
1020                 if (!s->name[0])
1021                         continue;
1022
1023                 // draw background
1024                 c = (qbyte *)&d_8to24table[(s->colors & 0xf0) + 8];
1025                 DrawQ_Fill ( x, y+1, 72, 3, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), c[3] * (1.0f / 255.0f), 0);
1026                 c = (qbyte *)&d_8to24table[((s->colors & 15)<<4) + 8];
1027                 DrawQ_Fill ( x, y+4, 72, 3, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), c[3] * (1.0f / 255.0f), 0);
1028
1029                 fph = (cl.time - s->entertime) ? (int) ((float) s->frags * 3600.0 / (cl.time - s->entertime)) : 0;
1030                 if (fph < -999) fph = -999;
1031                 if (fph > 9999) fph = 9999;
1032
1033                 // put it together
1034                 sprintf (num, "%c%4i:%4i%c %s", k == cl.viewentity - 1 ? 16 : ' ', (int) s->frags, fph, k == cl.viewentity - 1 ? 17 : ' ', s->name);
1035                 DrawQ_String(x - 8, y, num, 0, 8, 8, 1, 1, 1, 1, 0);
1036
1037                 y += 8;
1038         }
1039 }
1040
1041 /*
1042 ==================
1043 Sbar_IntermissionOverlay
1044
1045 ==================
1046 */
1047 void Sbar_IntermissionOverlay (void)
1048 {
1049         int             dig;
1050         int             num;
1051
1052         if (cl.gametype == GAME_DEATHMATCH)
1053         {
1054                 Sbar_DeathmatchOverlay ();
1055                 return;
1056         }
1057
1058         sbar_x = (vid.conwidth - 320) >> 1;
1059         sbar_y = (vid.conheight - 200) >> 1;
1060
1061         DrawQ_Pic (sbar_x + 64, sbar_y + 24, "gfx/complete.lmp", 0, 0, 1, 1, 1, 1, 0);
1062         DrawQ_Pic (sbar_x + 0, sbar_y + 56, "gfx/inter.lmp", 0, 0, 1, 1, 1, 1, 0);
1063
1064 // time
1065         dig = cl.completed_time/60;
1066         Sbar_DrawNum (160, 64, dig, 3, 0);
1067         num = cl.completed_time - dig*60;
1068         Sbar_DrawPic (234,64,sb_colon);
1069         Sbar_DrawPic (246,64,sb_nums[0][num/10]);
1070         Sbar_DrawPic (266,64,sb_nums[0][num%10]);
1071
1072         Sbar_DrawNum (160, 104, cl.stats[STAT_SECRETS], 3, 0);
1073         Sbar_DrawPic (232, 104, sb_slash);
1074         Sbar_DrawNum (240, 104, cl.stats[STAT_TOTALSECRETS], 3, 0);
1075
1076         Sbar_DrawNum (160, 144, cl.stats[STAT_MONSTERS], 3, 0);
1077         Sbar_DrawPic (232, 144, sb_slash);
1078         Sbar_DrawNum (240, 144, cl.stats[STAT_TOTALMONSTERS], 3, 0);
1079
1080 }
1081
1082
1083 /*
1084 ==================
1085 Sbar_FinaleOverlay
1086
1087 ==================
1088 */
1089 void Sbar_FinaleOverlay (void)
1090 {
1091         cachepic_t      *pic;
1092
1093         pic = Draw_CachePic ("gfx/finale.lmp");
1094         DrawQ_Pic((vid.conwidth - pic->width)/2, 16, "gfx/finale.lmp", 0, 0, 1, 1, 1, 1, 0);
1095 }
1096