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