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