Initial revision
[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
25 //int                   sb_updates;             // if >= vid.numpages, no update needed
26
27 #define STAT_MINUS              10      // num frame for '-' stats digit
28 qpic_t          *sb_nums[2][11];
29 qpic_t          *sb_colon, *sb_slash;
30 qpic_t          *sb_ibar;
31 qpic_t          *sb_sbar;
32 qpic_t          *sb_scorebar;
33
34 qpic_t      *sb_weapons[7][8];   // 0 is active, 1 is owned, 2-5 are flashes
35 qpic_t      *sb_ammo[4];
36 qpic_t          *sb_sigil[4];
37 qpic_t          *sb_armor[3];
38 qpic_t          *sb_items[32];
39
40 qpic_t  *sb_faces[7][2];                // 0 is gibbed, 1 is dead, 2-6 are alive
41                                                         // 0 is static, 1 is temporary animation
42 qpic_t  *sb_face_invis;
43 qpic_t  *sb_face_quad;
44 qpic_t  *sb_face_invuln;
45 qpic_t  *sb_face_invis_invuln;
46
47 qboolean        sb_showscores;
48
49 int                     sb_lines;                       // scan lines to draw
50
51 qpic_t      *rsb_invbar[2];
52 qpic_t      *rsb_weapons[5];
53 qpic_t      *rsb_items[2];
54 qpic_t      *rsb_ammo[3];
55 qpic_t      *rsb_teambord;              // PGM 01/19/97 - team color border
56
57 //MED 01/04/97 added two more weapons + 3 alternates for grenade launcher
58 qpic_t      *hsb_weapons[7][5];   // 0 is active, 1 is owned, 2-5 are flashes
59 //MED 01/04/97 added array to simplify weapon parsing
60 int         hipweapons[4] = {HIT_LASER_CANNON_BIT,HIT_MJOLNIR_BIT,4,HIT_PROXIMITY_GUN_BIT};
61 //MED 01/04/97 added hipnotic items array
62 qpic_t      *hsb_items[2];
63
64 void Sbar_MiniDeathmatchOverlay (void);
65 void Sbar_DeathmatchOverlay (void);
66 void M_DrawPic (int x, int y, qpic_t *pic);
67
68 /*
69 ===============
70 Sbar_ShowScores
71
72 Tab key down
73 ===============
74 */
75 void Sbar_ShowScores (void)
76 {
77         if (sb_showscores)
78                 return;
79         sb_showscores = true;
80 //      sb_updates = 0;
81 }
82
83 /*
84 ===============
85 Sbar_DontShowScores
86
87 Tab key up
88 ===============
89 */
90 void Sbar_DontShowScores (void)
91 {
92         sb_showscores = false;
93 //      sb_updates = 0;
94 }
95
96 /*
97 ===============
98 Sbar_Changed
99 ===============
100 */
101 //void Sbar_Changed (void)
102 //{
103 //      sb_updates = 0; // update next frame
104 //}
105
106 /*
107 ===============
108 Sbar_Init
109 ===============
110 */
111 void Sbar_Init (void)
112 {
113         int             i;
114
115         for (i=0 ; i<10 ; i++)
116         {
117                 sb_nums[0][i] = Draw_PicFromWad (va("num_%i",i));
118                 sb_nums[1][i] = Draw_PicFromWad (va("anum_%i",i));
119         }
120
121         sb_nums[0][10] = Draw_PicFromWad ("num_minus");
122         sb_nums[1][10] = Draw_PicFromWad ("anum_minus");
123
124         sb_colon = Draw_PicFromWad ("num_colon");
125         sb_slash = Draw_PicFromWad ("num_slash");
126
127         sb_weapons[0][0] = Draw_PicFromWad ("inv_shotgun");
128         sb_weapons[0][1] = Draw_PicFromWad ("inv_sshotgun");
129         sb_weapons[0][2] = Draw_PicFromWad ("inv_nailgun");
130         sb_weapons[0][3] = Draw_PicFromWad ("inv_snailgun");
131         sb_weapons[0][4] = Draw_PicFromWad ("inv_rlaunch");
132         sb_weapons[0][5] = Draw_PicFromWad ("inv_srlaunch");
133         sb_weapons[0][6] = Draw_PicFromWad ("inv_lightng");
134
135         sb_weapons[1][0] = Draw_PicFromWad ("inv2_shotgun");
136         sb_weapons[1][1] = Draw_PicFromWad ("inv2_sshotgun");
137         sb_weapons[1][2] = Draw_PicFromWad ("inv2_nailgun");
138         sb_weapons[1][3] = Draw_PicFromWad ("inv2_snailgun");
139         sb_weapons[1][4] = Draw_PicFromWad ("inv2_rlaunch");
140         sb_weapons[1][5] = Draw_PicFromWad ("inv2_srlaunch");
141         sb_weapons[1][6] = Draw_PicFromWad ("inv2_lightng");
142
143         for (i=0 ; i<5 ; i++)
144         {
145                 sb_weapons[2+i][0] = Draw_PicFromWad (va("inva%i_shotgun",i+1));
146                 sb_weapons[2+i][1] = Draw_PicFromWad (va("inva%i_sshotgun",i+1));
147                 sb_weapons[2+i][2] = Draw_PicFromWad (va("inva%i_nailgun",i+1));
148                 sb_weapons[2+i][3] = Draw_PicFromWad (va("inva%i_snailgun",i+1));
149                 sb_weapons[2+i][4] = Draw_PicFromWad (va("inva%i_rlaunch",i+1));
150                 sb_weapons[2+i][5] = Draw_PicFromWad (va("inva%i_srlaunch",i+1));
151                 sb_weapons[2+i][6] = Draw_PicFromWad (va("inva%i_lightng",i+1));
152         }
153
154         sb_ammo[0] = Draw_PicFromWad ("sb_shells");
155         sb_ammo[1] = Draw_PicFromWad ("sb_nails");
156         sb_ammo[2] = Draw_PicFromWad ("sb_rocket");
157         sb_ammo[3] = Draw_PicFromWad ("sb_cells");
158
159         sb_armor[0] = Draw_PicFromWad ("sb_armor1");
160         sb_armor[1] = Draw_PicFromWad ("sb_armor2");
161         sb_armor[2] = Draw_PicFromWad ("sb_armor3");
162
163         sb_items[0] = Draw_PicFromWad ("sb_key1");
164         sb_items[1] = Draw_PicFromWad ("sb_key2");
165         sb_items[2] = Draw_PicFromWad ("sb_invis");
166         sb_items[3] = Draw_PicFromWad ("sb_invuln");
167         sb_items[4] = Draw_PicFromWad ("sb_suit");
168         sb_items[5] = Draw_PicFromWad ("sb_quad");
169
170         sb_sigil[0] = Draw_PicFromWad ("sb_sigil1");
171         sb_sigil[1] = Draw_PicFromWad ("sb_sigil2");
172         sb_sigil[2] = Draw_PicFromWad ("sb_sigil3");
173         sb_sigil[3] = Draw_PicFromWad ("sb_sigil4");
174
175         sb_faces[4][0] = Draw_PicFromWad ("face1");
176         sb_faces[4][1] = Draw_PicFromWad ("face_p1");
177         sb_faces[3][0] = Draw_PicFromWad ("face2");
178         sb_faces[3][1] = Draw_PicFromWad ("face_p2");
179         sb_faces[2][0] = Draw_PicFromWad ("face3");
180         sb_faces[2][1] = Draw_PicFromWad ("face_p3");
181         sb_faces[1][0] = Draw_PicFromWad ("face4");
182         sb_faces[1][1] = Draw_PicFromWad ("face_p4");
183         sb_faces[0][0] = Draw_PicFromWad ("face5");
184         sb_faces[0][1] = Draw_PicFromWad ("face_p5");
185
186         sb_face_invis = Draw_PicFromWad ("face_invis");
187         sb_face_invuln = Draw_PicFromWad ("face_invul2");
188         sb_face_invis_invuln = Draw_PicFromWad ("face_inv2");
189         sb_face_quad = Draw_PicFromWad ("face_quad");
190
191         Cmd_AddCommand ("+showscores", Sbar_ShowScores);
192         Cmd_AddCommand ("-showscores", Sbar_DontShowScores);
193
194         sb_sbar = Draw_PicFromWad ("sbar");
195         sb_ibar = Draw_PicFromWad ("ibar");
196         sb_scorebar = Draw_PicFromWad ("scorebar");
197
198 //MED 01/04/97 added new hipnotic weapons
199         if (hipnotic)
200         {
201           hsb_weapons[0][0] = Draw_PicFromWad ("inv_laser");
202           hsb_weapons[0][1] = Draw_PicFromWad ("inv_mjolnir");
203           hsb_weapons[0][2] = Draw_PicFromWad ("inv_gren_prox");
204           hsb_weapons[0][3] = Draw_PicFromWad ("inv_prox_gren");
205           hsb_weapons[0][4] = Draw_PicFromWad ("inv_prox");
206
207           hsb_weapons[1][0] = Draw_PicFromWad ("inv2_laser");
208           hsb_weapons[1][1] = Draw_PicFromWad ("inv2_mjolnir");
209           hsb_weapons[1][2] = Draw_PicFromWad ("inv2_gren_prox");
210           hsb_weapons[1][3] = Draw_PicFromWad ("inv2_prox_gren");
211           hsb_weapons[1][4] = Draw_PicFromWad ("inv2_prox");
212
213           for (i=0 ; i<5 ; i++)
214           {
215                  hsb_weapons[2+i][0] = Draw_PicFromWad (va("inva%i_laser",i+1));
216                  hsb_weapons[2+i][1] = Draw_PicFromWad (va("inva%i_mjolnir",i+1));
217                  hsb_weapons[2+i][2] = Draw_PicFromWad (va("inva%i_gren_prox",i+1));
218                  hsb_weapons[2+i][3] = Draw_PicFromWad (va("inva%i_prox_gren",i+1));
219                  hsb_weapons[2+i][4] = Draw_PicFromWad (va("inva%i_prox",i+1));
220           }
221
222           hsb_items[0] = Draw_PicFromWad ("sb_wsuit");
223           hsb_items[1] = Draw_PicFromWad ("sb_eshld");
224         }
225
226         if (rogue)
227         {
228                 rsb_invbar[0] = Draw_PicFromWad ("r_invbar1");
229                 rsb_invbar[1] = Draw_PicFromWad ("r_invbar2");
230
231                 rsb_weapons[0] = Draw_PicFromWad ("r_lava");
232                 rsb_weapons[1] = Draw_PicFromWad ("r_superlava");
233                 rsb_weapons[2] = Draw_PicFromWad ("r_gren");
234                 rsb_weapons[3] = Draw_PicFromWad ("r_multirock");
235                 rsb_weapons[4] = Draw_PicFromWad ("r_plasma");
236
237                 rsb_items[0] = Draw_PicFromWad ("r_shield1");
238         rsb_items[1] = Draw_PicFromWad ("r_agrav1");
239
240 // PGM 01/19/97 - team color border
241         rsb_teambord = Draw_PicFromWad ("r_teambord");
242 // PGM 01/19/97 - team color border
243
244                 rsb_ammo[0] = Draw_PicFromWad ("r_ammolava");
245                 rsb_ammo[1] = Draw_PicFromWad ("r_ammomulti");
246                 rsb_ammo[2] = Draw_PicFromWad ("r_ammoplasma");
247         }
248 }
249
250
251 //=============================================================================
252
253 // drawing routines are relative to the status bar location
254
255 /*
256 =============
257 Sbar_DrawPic
258 =============
259 */
260 void Sbar_DrawPic (int x, int y, qpic_t *pic)
261 {
262         if (cl.gametype == GAME_DEATHMATCH)
263                 Draw_Pic (x /* + ((vid.width - 320)>>1)*/, y + (vid.height-SBAR_HEIGHT), pic);
264         else
265                 Draw_Pic (x + ((vid.width - 320)>>1), y + (vid.height-SBAR_HEIGHT), pic);
266 }
267
268 /*
269 =============
270 Sbar_DrawTransPic
271 =============
272 */
273 void Sbar_DrawTransPic (int x, int y, qpic_t *pic)
274 {
275         if (cl.gametype == GAME_DEATHMATCH)
276                 Draw_TransPic (x /*+ ((vid.width - 320)>>1)*/, y + (vid.height-SBAR_HEIGHT), pic);
277         else
278                 Draw_TransPic (x + ((vid.width - 320)>>1), y + (vid.height-SBAR_HEIGHT), pic);
279 }
280
281 /*
282 ================
283 Sbar_DrawCharacter
284
285 Draws one solid graphics character
286 ================
287 */
288 void Sbar_DrawCharacter (int x, int y, int num)
289 {
290         if (cl.gametype == GAME_DEATHMATCH)
291                 Draw_Character ( x /*+ ((vid.width - 320)>>1) */ + 4 , y + vid.height-SBAR_HEIGHT, num);
292         else
293                 Draw_Character ( x + ((vid.width - 320)>>1) + 4 , y + vid.height-SBAR_HEIGHT, num);
294 }
295
296 /*
297 ================
298 Sbar_DrawString
299 ================
300 */
301 void Sbar_DrawString (int x, int y, char *str)
302 {
303         if (cl.gametype == GAME_DEATHMATCH)
304                 Draw_String (x /*+ ((vid.width - 320)>>1)*/, y+ vid.height-SBAR_HEIGHT, str, 0);
305         else
306                 Draw_String (x + ((vid.width - 320)>>1), y+ vid.height-SBAR_HEIGHT, str, 0);
307 }
308
309 /*
310 =============
311 Sbar_itoa
312 =============
313 */
314 int Sbar_itoa (int num, char *buf)
315 {
316         char    *str;
317         int             pow10;
318         int             dig;
319
320         str = buf;
321
322         if (num < 0)
323         {
324                 *str++ = '-';
325                 num = -num;
326         }
327
328         for (pow10 = 10 ; num >= pow10 ; pow10 *= 10)
329         ;
330
331         do
332         {
333                 pow10 /= 10;
334                 dig = num/pow10;
335                 *str++ = '0'+dig;
336                 num -= dig*pow10;
337         } while (pow10 != 1);
338
339         *str = 0;
340
341         return str-buf;
342 }
343
344
345 /*
346 =============
347 Sbar_DrawNum
348 =============
349 */
350 void Sbar_DrawNum (int x, int y, int num, int digits, int color)
351 {
352         char                    str[12];
353         char                    *ptr;
354         int                             l, frame;
355
356         l = Sbar_itoa (num, str);
357         ptr = str;
358         if (l > digits)
359                 ptr += (l-digits);
360         if (l < digits)
361                 x += (digits-l)*24;
362
363         while (*ptr)
364         {
365                 if (*ptr == '-')
366                         frame = STAT_MINUS;
367                 else
368                         frame = *ptr -'0';
369
370                 Sbar_DrawTransPic (x,y,sb_nums[color][frame]);
371                 x += 24;
372                 ptr++;
373         }
374 }
375
376 //=============================================================================
377
378 int             fragsort[MAX_SCOREBOARD];
379
380 char    scoreboardtext[MAX_SCOREBOARD][20];
381 int             scoreboardtop[MAX_SCOREBOARD];
382 int             scoreboardbottom[MAX_SCOREBOARD];
383 int             scoreboardcount[MAX_SCOREBOARD];
384 int             scoreboardlines;
385
386 /*
387 ===============
388 Sbar_SortFrags
389 ===============
390 */
391 void Sbar_SortFrags (void)
392 {
393         int             i, j, k;
394
395 // sort by frags
396         scoreboardlines = 0;
397         for (i=0 ; i<cl.maxclients ; i++)
398         {
399                 if (cl.scores[i].name[0])
400                 {
401                         fragsort[scoreboardlines] = i;
402                         scoreboardlines++;
403                 }
404         }
405
406         for (i=0 ; i<scoreboardlines ; i++)
407                 for (j=0 ; j<scoreboardlines-1-i ; j++)
408                         if (cl.scores[fragsort[j]].frags < cl.scores[fragsort[j+1]].frags)
409                         {
410                                 k = fragsort[j];
411                                 fragsort[j] = fragsort[j+1];
412                                 fragsort[j+1] = k;
413                         }
414 }
415
416 int     Sbar_ColorForMap (int m)
417 {
418         return m < 128 ? m + 8 : m + 8;
419 }
420
421 /*
422 ===============
423 Sbar_UpdateScoreboard
424 ===============
425 */
426 void Sbar_UpdateScoreboard (void)
427 {
428         int             i, k;
429         int             top, bottom;
430         scoreboard_t    *s;
431
432         Sbar_SortFrags ();
433
434 // draw the text
435         memset (scoreboardtext, 0, sizeof(scoreboardtext));
436
437         for (i=0 ; i<scoreboardlines; i++)
438         {
439                 k = fragsort[i];
440                 s = &cl.scores[k];
441                 sprintf (&scoreboardtext[i][1], "%3i %s", s->frags, s->name);
442
443                 top = s->colors & 0xf0;
444                 bottom = (s->colors & 15) <<4;
445                 scoreboardtop[i] = Sbar_ColorForMap (top);
446                 scoreboardbottom[i] = Sbar_ColorForMap (bottom);
447         }
448 }
449
450
451
452 /*
453 ===============
454 Sbar_SoloScoreboard
455 ===============
456 */
457 void Sbar_SoloScoreboard (void)
458 {
459         char    str[80];
460         int             minutes, seconds, tens, units;
461         int             l;
462
463         sprintf (str,"Monsters:%3i /%3i", cl.stats[STAT_MONSTERS], cl.stats[STAT_TOTALMONSTERS]);
464         Sbar_DrawString (8, 4, str);
465
466         sprintf (str,"Secrets :%3i /%3i", cl.stats[STAT_SECRETS], cl.stats[STAT_TOTALSECRETS]);
467         Sbar_DrawString (8, 12, str);
468
469 // time
470         minutes = cl.time / 60;
471         seconds = cl.time - 60*minutes;
472         tens = seconds / 10;
473         units = seconds - 10*tens;
474         sprintf (str,"Time :%3i:%i%i", minutes, tens, units);
475         Sbar_DrawString (184, 4, str);
476
477 // draw level name
478         l = strlen (cl.levelname);
479         Sbar_DrawString (232 - l*4, 12, cl.levelname);
480 }
481
482 /*
483 ===============
484 Sbar_DrawScoreboard
485 ===============
486 */
487 void Sbar_DrawScoreboard (void)
488 {
489         Sbar_SoloScoreboard ();
490         if (cl.gametype == GAME_DEATHMATCH)
491                 Sbar_DeathmatchOverlay ();
492 #if 0
493         int             i, j, c;
494         int             x, y;
495         int             l;
496         int             top, bottom;
497         scoreboard_t    *s;
498
499         if (cl.gametype != GAME_DEATHMATCH)
500         {
501                 Sbar_SoloScoreboard ();
502                 return;
503         }
504
505         Sbar_UpdateScoreboard ();
506
507         l = scoreboardlines <= 6 ? scoreboardlines : 6;
508
509         for (i=0 ; i<l ; i++)
510         {
511                 x = 20*(i&1);
512                 y = i/2 * 8;
513
514                 s = &cl.scores[fragsort[i]];
515                 if (!s->name[0])
516                         continue;
517
518         // draw background
519                 top = s->colors & 0xf0;
520                 bottom = (s->colors & 15)<<4;
521                 top = Sbar_ColorForMap (top);
522                 bottom = Sbar_ColorForMap (bottom);
523
524                 Draw_Fill ( x*8+10 + ((vid.width - 320)>>1), y + vid.height - SBAR_HEIGHT, 28, 4, top);
525                 Draw_Fill ( x*8+10 + ((vid.width - 320)>>1), y+4 + vid.height - SBAR_HEIGHT, 28, 4, bottom);
526
527         // draw text
528                 for (j=0 ; j<20 ; j++)
529                 {
530                         c = scoreboardtext[i][j];
531                         if (c == 0 || c == ' ')
532                                 continue;
533                         Sbar_DrawCharacter ( (x+j)*8, y, c);
534                 }
535         }
536 #endif
537 }
538
539 //=============================================================================
540
541 /*
542 ===============
543 Sbar_DrawInventory
544 ===============
545 */
546 void Sbar_DrawInventory (void)
547 {
548         int             i;
549         char    num[6];
550         float   time;
551         int             flashon;
552
553         if (rogue)
554         {
555                 if ( cl.stats[STAT_ACTIVEWEAPON] >= RIT_LAVA_NAILGUN )
556                         Sbar_DrawPic (0, -24, rsb_invbar[0]);
557                 else
558                         Sbar_DrawPic (0, -24, rsb_invbar[1]);
559         }
560         else
561         {
562                 Sbar_DrawPic (0, -24, sb_ibar);
563         }
564
565 // weapons
566         for (i=0 ; i<7 ; i++)
567         {
568                 if (cl.items & (IT_SHOTGUN<<i) )
569                 {
570                         time = cl.item_gettime[i];
571                         flashon = (int)((cl.time - time)*10);
572                         if (flashon >= 10)
573                         {
574                                 if ( cl.stats[STAT_ACTIVEWEAPON] == (IT_SHOTGUN<<i)  )
575                                         flashon = 1;
576                                 else
577                                         flashon = 0;
578                         }
579                         else
580                                 flashon = (flashon%5) + 2;
581
582          Sbar_DrawPic (i*24, -16, sb_weapons[flashon][i]);
583
584 //                      if (flashon > 1)
585 //                              sb_updates = 0;         // force update to remove flash
586                 }
587         }
588
589 // MED 01/04/97
590 // hipnotic weapons
591     if (hipnotic)
592     {
593       int grenadeflashing=0;
594       for (i=0 ; i<4 ; i++)
595       {
596          if (cl.items & (1<<hipweapons[i]) )
597          {
598             time = cl.item_gettime[hipweapons[i]];
599             flashon = (int)((cl.time - time)*10);
600             if (flashon >= 10)
601             {
602                if ( cl.stats[STAT_ACTIVEWEAPON] == (1<<hipweapons[i])  )
603                   flashon = 1;
604                else
605                   flashon = 0;
606             }
607             else
608                flashon = (flashon%5) + 2;
609
610             // check grenade launcher
611             if (i==2)
612             {
613                if (cl.items & HIT_PROXIMITY_GUN)
614                {
615                   if (flashon)
616                   {
617                      grenadeflashing = 1;
618                      Sbar_DrawPic (96, -16, hsb_weapons[flashon][2]);
619                   }
620                }
621             }
622             else if (i==3)
623             {
624                if (cl.items & (IT_SHOTGUN<<4))
625                {
626                   if (flashon && !grenadeflashing)
627                   {
628                      Sbar_DrawPic (96, -16, hsb_weapons[flashon][3]);
629                   }
630                   else if (!grenadeflashing)
631                   {
632                      Sbar_DrawPic (96, -16, hsb_weapons[0][3]);
633                   }
634                }
635                else
636                   Sbar_DrawPic (96, -16, hsb_weapons[flashon][4]);
637             }
638             else
639                Sbar_DrawPic (176 + (i*24), -16, hsb_weapons[flashon][i]);
640 //            if (flashon > 1)
641 //               sb_updates = 0;      // force update to remove flash
642          }
643       }
644     }
645
646         if (rogue)
647         {
648     // check for powered up weapon.
649                 if ( cl.stats[STAT_ACTIVEWEAPON] >= RIT_LAVA_NAILGUN )
650                 {
651                         for (i=0;i<5;i++)
652                         {
653                                 if (cl.stats[STAT_ACTIVEWEAPON] == (RIT_LAVA_NAILGUN << i))
654                                 {
655                                         Sbar_DrawPic ((i+2)*24, -16, rsb_weapons[i]);
656                                 }
657                         }
658                 }
659         }
660
661 // ammo counts
662         for (i=0 ; i<4 ; i++)
663         {
664                 sprintf (num, "%3i",cl.stats[STAT_SHELLS+i] );
665                 if (num[0] != ' ')
666                         Sbar_DrawCharacter ( (6*i+1)*8 - 2, -24, 18 + num[0] - '0');
667                 if (num[1] != ' ')
668                         Sbar_DrawCharacter ( (6*i+2)*8 - 2, -24, 18 + num[1] - '0');
669                 if (num[2] != ' ')
670                         Sbar_DrawCharacter ( (6*i+3)*8 - 2, -24, 18 + num[2] - '0');
671         }
672
673         flashon = 0;
674    // items
675    for (i=0 ; i<6 ; i++)
676       if (cl.items & (1<<(17+i)))
677       {
678          time = cl.item_gettime[17+i];
679          if (time && time > cl.time - 2 && flashon )
680          {  // flash frame
681 //            sb_updates = 0;
682          }
683          else
684          {
685          //MED 01/04/97 changed keys
686             if (!hipnotic || (i>1))
687             {
688                Sbar_DrawPic (192 + i*16, -16, sb_items[i]);
689             }
690          }
691 //         if (time && time > cl.time - 2)
692 //            sb_updates = 0;
693       }
694    //MED 01/04/97 added hipnotic items
695    // hipnotic items
696    if (hipnotic)
697    {
698       for (i=0 ; i<2 ; i++)
699          if (cl.items & (1<<(24+i)))
700          {
701             time = cl.item_gettime[24+i];
702             if (time && time > cl.time - 2 && flashon )
703             {  // flash frame
704 //               sb_updates = 0;
705             }
706             else
707             {
708                Sbar_DrawPic (288 + i*16, -16, hsb_items[i]);
709             }
710 //            if (time && time > cl.time - 2)
711 //               sb_updates = 0;
712          }
713    }
714
715         if (rogue)
716         {
717         // new rogue items
718                 for (i=0 ; i<2 ; i++)
719                 {
720                         if (cl.items & (1<<(29+i)))
721                         {
722                                 time = cl.item_gettime[29+i];
723
724                                 if (time &&     time > cl.time - 2 && flashon )
725                                 {       // flash frame
726 //                                      sb_updates = 0;
727                                 }
728                                 else
729                                 {
730                                         Sbar_DrawPic (288 + i*16, -16, rsb_items[i]);
731                                 }
732
733 //                              if (time &&     time > cl.time - 2)
734 //                                      sb_updates = 0;
735                         }
736                 }
737         }
738         else
739         {
740         // sigils
741                 for (i=0 ; i<4 ; i++)
742                 {
743                         if (cl.items & (1<<(28+i)))
744                         {
745                                 time = cl.item_gettime[28+i];
746                                 if (time &&     time > cl.time - 2 && flashon )
747                                 {       // flash frame
748 //                                      sb_updates = 0;
749                                 }
750                                 else
751                                         Sbar_DrawPic (320-32 + i*8, -16, sb_sigil[i]);
752 //                              if (time &&     time > cl.time - 2)
753 //                                      sb_updates = 0;
754                         }
755                 }
756         }
757 }
758
759 //=============================================================================
760
761 /*
762 ===============
763 Sbar_DrawFrags
764 ===============
765 */
766 void Sbar_DrawFrags (void)
767 {
768         int                             i, k, l;
769         int                             top, bottom;
770         int                             x, y, f;
771         int                             xofs;
772         char                    num[12];
773         scoreboard_t    *s;
774
775         Sbar_SortFrags ();
776
777 // draw the text
778         l = scoreboardlines <= 4 ? scoreboardlines : 4;
779
780         x = 23;
781         if (cl.gametype == GAME_DEATHMATCH)
782                 xofs = 0;
783         else
784                 xofs = (vid.width - 320)>>1;
785         y = vid.height - SBAR_HEIGHT - 23;
786
787         for (i=0 ; i<l ; i++)
788         {
789                 k = fragsort[i];
790                 s = &cl.scores[k];
791                 if (!s->name[0])
792                         continue;
793
794         // draw background
795                 top = s->colors & 0xf0;
796                 bottom = (s->colors & 15)<<4;
797                 top = Sbar_ColorForMap (top);
798                 bottom = Sbar_ColorForMap (bottom);
799
800                 Draw_Fill (xofs + x*8 + 10, y, 28, 4, top);
801                 Draw_Fill (xofs + x*8 + 10, y+4, 28, 3, bottom);
802
803         // draw number
804                 f = s->frags;
805                 sprintf (num, "%3i",f);
806
807                 Sbar_DrawCharacter ( (x+1)*8 , -24, num[0]);
808                 Sbar_DrawCharacter ( (x+2)*8 , -24, num[1]);
809                 Sbar_DrawCharacter ( (x+3)*8 , -24, num[2]);
810
811                 if (k == cl.viewentity - 1)
812                 {
813                         Sbar_DrawCharacter (x*8+2, -24, 16);
814                         Sbar_DrawCharacter ( (x+4)*8-4, -24, 17);
815                 }
816                 x+=4;
817         }
818 }
819
820 //=============================================================================
821
822
823 /*
824 ===============
825 Sbar_DrawFace
826 ===============
827 */
828 void Sbar_DrawFace (void)
829 {
830         int             f, anim;
831
832 // PGM 01/19/97 - team color drawing
833 // PGM 03/02/97 - fixed so color swatch only appears in CTF modes
834         if (rogue &&
835         (cl.maxclients != 1) &&
836         (teamplay.value>3) &&
837         (teamplay.value<7))
838         {
839                 int                             top, bottom;
840                 int                             xofs;
841                 char                    num[12];
842                 scoreboard_t    *s;
843                 
844                 s = &cl.scores[cl.viewentity - 1];
845                 // draw background
846                 top = s->colors & 0xf0;
847                 bottom = (s->colors & 15)<<4;
848                 top = Sbar_ColorForMap (top);
849                 bottom = Sbar_ColorForMap (bottom);
850
851                 if (cl.gametype == GAME_DEATHMATCH)
852                         xofs = 113;
853                 else
854                         xofs = ((vid.width - 320)>>1) + 113;
855
856                 Sbar_DrawPic (112, 0, rsb_teambord);
857                 Draw_Fill (xofs, vid.height-SBAR_HEIGHT+3, 22, 9, top);
858                 Draw_Fill (xofs, vid.height-SBAR_HEIGHT+12, 22, 9, bottom);
859
860                 // draw number
861                 f = s->frags;
862                 sprintf (num, "%3i",f);
863
864                 if (top==8)
865                 {
866                         if (num[0] != ' ')
867                                 Sbar_DrawCharacter(109, 3, 18 + num[0] - '0');
868                         if (num[1] != ' ')
869                                 Sbar_DrawCharacter(116, 3, 18 + num[1] - '0');
870                         if (num[2] != ' ')
871                                 Sbar_DrawCharacter(123, 3, 18 + num[2] - '0');
872                 }
873                 else
874                 {
875                         Sbar_DrawCharacter ( 109, 3, num[0]);
876                         Sbar_DrawCharacter ( 116, 3, num[1]);
877                         Sbar_DrawCharacter ( 123, 3, num[2]);
878                 }
879                 
880                 return;
881         }
882 // PGM 01/19/97 - team color drawing
883
884         if ( (cl.items & (IT_INVISIBILITY | IT_INVULNERABILITY) )
885         == (IT_INVISIBILITY | IT_INVULNERABILITY) )
886         {
887                 Sbar_DrawPic (112, 0, sb_face_invis_invuln);
888                 return;
889         }
890         if (cl.items & IT_QUAD)
891         {
892                 Sbar_DrawPic (112, 0, sb_face_quad );
893                 return;
894         }
895         if (cl.items & IT_INVISIBILITY)
896         {
897                 Sbar_DrawPic (112, 0, sb_face_invis );
898                 return;
899         }
900         if (cl.items & IT_INVULNERABILITY)
901         {
902                 Sbar_DrawPic (112, 0, sb_face_invuln);
903                 return;
904         }
905
906         if (cl.stats[STAT_HEALTH] >= 100)
907                 f = 4;
908         else
909                 f = cl.stats[STAT_HEALTH] / 20;
910
911         if (cl.time <= cl.faceanimtime)
912         {
913                 anim = 1;
914 //              sb_updates = 0;         // make sure the anim gets drawn over
915         }
916         else
917                 anim = 0;
918         Sbar_DrawPic (112, 0, sb_faces[f][anim]);
919 }
920
921 /*
922 ===============
923 Sbar_Draw
924 ===============
925 */
926 void Sbar_Draw (void)
927 {
928         if (scr_con_current == vid.height)
929                 return;         // console is full screen
930
931         // LordHavoc: always redraw
932         //if (sb_updates >= vid.numpages)
933         //      return;
934
935         scr_copyeverything = 1;
936
937 //      sb_updates++;
938
939         if (sb_lines > 24)
940         {
941                 Sbar_DrawInventory ();
942                 if (cl.maxclients != 1)
943                         Sbar_DrawFrags ();
944         }
945
946         if (sb_showscores || cl.stats[STAT_HEALTH] <= 0)
947         {
948                 Sbar_DrawPic (0, 0, sb_scorebar);
949                 Sbar_DrawScoreboard ();
950 //              sb_updates = 0;
951         }
952         else if (sb_lines)
953         {
954                 Sbar_DrawPic (0, 0, sb_sbar);
955
956    // keys (hipnotic only)
957       //MED 01/04/97 moved keys here so they would not be overwritten
958       if (hipnotic)
959       {
960          if (cl.items & IT_KEY1)
961             Sbar_DrawPic (209, 3, sb_items[0]);
962          if (cl.items & IT_KEY2)
963             Sbar_DrawPic (209, 12, sb_items[1]);
964       }
965    // armor
966                 if (cl.items & IT_INVULNERABILITY)
967                 {
968                         Sbar_DrawNum (24, 0, 666, 3, 1);
969                         Sbar_DrawPic (0, 0, draw_disc);
970                 }
971                 else
972                 {
973                         if (rogue)
974                         {
975                                 Sbar_DrawNum (24, 0, cl.stats[STAT_ARMOR], 3,
976                                                                 cl.stats[STAT_ARMOR] <= 25);
977                                 if (cl.items & RIT_ARMOR3)
978                                         Sbar_DrawPic (0, 0, sb_armor[2]);
979                                 else if (cl.items & RIT_ARMOR2)
980                                         Sbar_DrawPic (0, 0, sb_armor[1]);
981                                 else if (cl.items & RIT_ARMOR1)
982                                         Sbar_DrawPic (0, 0, sb_armor[0]);
983                         }
984                         else
985                         {
986                                 Sbar_DrawNum (24, 0, cl.stats[STAT_ARMOR], 3
987                                 , cl.stats[STAT_ARMOR] <= 25);
988                                 if (cl.items & IT_ARMOR3)
989                                         Sbar_DrawPic (0, 0, sb_armor[2]);
990                                 else if (cl.items & IT_ARMOR2)
991                                         Sbar_DrawPic (0, 0, sb_armor[1]);
992                                 else if (cl.items & IT_ARMOR1)
993                                         Sbar_DrawPic (0, 0, sb_armor[0]);
994                         }
995                 }
996
997         // face
998                 Sbar_DrawFace ();
999
1000         // health
1001                 Sbar_DrawNum (136, 0, cl.stats[STAT_HEALTH], 3
1002                 , cl.stats[STAT_HEALTH] <= 25);
1003
1004         // ammo icon
1005                 if (rogue)
1006                 {
1007                         if (cl.items & RIT_SHELLS)
1008                                 Sbar_DrawPic (224, 0, sb_ammo[0]);
1009                         else if (cl.items & RIT_NAILS)
1010                                 Sbar_DrawPic (224, 0, sb_ammo[1]);
1011                         else if (cl.items & RIT_ROCKETS)
1012                                 Sbar_DrawPic (224, 0, sb_ammo[2]);
1013                         else if (cl.items & RIT_CELLS)
1014                                 Sbar_DrawPic (224, 0, sb_ammo[3]);
1015                         else if (cl.items & RIT_LAVA_NAILS)
1016                                 Sbar_DrawPic (224, 0, rsb_ammo[0]);
1017                         else if (cl.items & RIT_PLASMA_AMMO)
1018                                 Sbar_DrawPic (224, 0, rsb_ammo[1]);
1019                         else if (cl.items & RIT_MULTI_ROCKETS)
1020                                 Sbar_DrawPic (224, 0, rsb_ammo[2]);
1021                 }
1022                 else
1023                 {
1024                         if (cl.items & IT_SHELLS)
1025                                 Sbar_DrawPic (224, 0, sb_ammo[0]);
1026                         else if (cl.items & IT_NAILS)
1027                                 Sbar_DrawPic (224, 0, sb_ammo[1]);
1028                         else if (cl.items & IT_ROCKETS)
1029                                 Sbar_DrawPic (224, 0, sb_ammo[2]);
1030                         else if (cl.items & IT_CELLS)
1031                                 Sbar_DrawPic (224, 0, sb_ammo[3]);
1032                 }
1033
1034                 Sbar_DrawNum (248, 0, cl.stats[STAT_AMMO], 3,
1035                                           cl.stats[STAT_AMMO] <= 10);
1036         }
1037
1038         if (vid.width > 320) {
1039                 if (cl.gametype == GAME_DEATHMATCH)
1040                         Sbar_MiniDeathmatchOverlay ();
1041         }
1042 }
1043
1044 //=============================================================================
1045
1046 /*
1047 ==================
1048 Sbar_IntermissionNumber
1049
1050 ==================
1051 */
1052 void Sbar_IntermissionNumber (int x, int y, int num, int digits, int color)
1053 {
1054         char                    str[12];
1055         char                    *ptr;
1056         int                             l, frame;
1057
1058         l = Sbar_itoa (num, str);
1059         ptr = str;
1060         if (l > digits)
1061                 ptr += (l-digits);
1062         if (l < digits)
1063                 x += (digits-l)*24;
1064
1065         while (*ptr)
1066         {
1067                 if (*ptr == '-')
1068                         frame = STAT_MINUS;
1069                 else
1070                         frame = *ptr -'0';
1071
1072                 Draw_TransPic (x,y,sb_nums[color][frame]);
1073                 x += 24;
1074                 ptr++;
1075         }
1076 }
1077
1078 /*
1079 ==================
1080 Sbar_DeathmatchOverlay
1081
1082 ==================
1083 */
1084 void Sbar_DeathmatchOverlay (void)
1085 {
1086         qpic_t                  *pic;
1087         int                             i, k, l, top, bottom, x, y, total, n, minutes, tens, units, fph;
1088         char                    num[128];
1089         scoreboard_t    *s;
1090
1091         scr_copyeverything = 1;
1092         scr_fullupdate = 0;
1093
1094         pic = Draw_CachePic ("gfx/ranking.lmp");
1095         M_DrawPic ((320-pic->width)/2, 8, pic);
1096
1097 // scores
1098         Sbar_SortFrags ();
1099
1100 // draw the text
1101         l = scoreboardlines;
1102
1103         x = ((vid.width - 320)>>1) - 140;
1104         y = 40;
1105         for (i = 0;i < l;i++)
1106         {
1107                 k = fragsort[i];
1108                 s = &cl.scores[k];
1109                 if (!s->name[0])
1110                         continue;
1111
1112         // draw background
1113                 top = s->colors & 0xf0;
1114                 bottom = (s->colors & 15)<<4;
1115                 top = Sbar_ColorForMap (top);
1116                 bottom = Sbar_ColorForMap (bottom);
1117
1118                 Draw_Fill ( x, y+1, 88, 3, top);
1119                 Draw_Fill ( x, y+4, 88, 3, bottom);
1120
1121                 total = cl.time - s->entertime;
1122                 minutes = (int)total/60;
1123                 n = total - minutes*60;
1124                 tens = n/10;
1125                 units = n%10;
1126
1127                 fph = total ? (int) ((float) s->frags * 3600.0 / total) : 0;
1128                 if (fph < -999) fph = -999;
1129                 if (fph > 9999) fph = 9999;
1130                 
1131                 // put it together
1132                 sprintf (num, "%c %4i:%4i  %3i:%i%i %s", k == cl.viewentity - 1 ? 12 : ' ', (int) s->frags, fph, minutes, tens, units, s->name);
1133                 Draw_String(x - 8, y, num, 0);
1134
1135                 y += 8;
1136         }
1137 }
1138
1139 /*
1140 ==================
1141 Sbar_DeathmatchOverlay
1142
1143 ==================
1144 */
1145 void Sbar_MiniDeathmatchOverlay (void)
1146 {
1147         int                             i, l, k, top, bottom, x, y, fph, numlines;
1148         char                    num[128];
1149         scoreboard_t    *s;
1150
1151         if (vid.width < 512 || !sb_lines)
1152                 return;
1153
1154         scr_copyeverything = 1;
1155         scr_fullupdate = 0;
1156
1157 // scores
1158         Sbar_SortFrags ();
1159
1160 // draw the text
1161         l = scoreboardlines;
1162         y = vid.height - sb_lines;
1163         numlines = sb_lines/8;
1164         if (numlines < 3)
1165                 return;
1166
1167         //find us
1168         for (i = 0; i < scoreboardlines; i++)
1169                 if (fragsort[i] == cl.viewentity - 1)
1170                         break;
1171
1172     if (i == scoreboardlines) // we're not there
1173             i = 0;
1174     else // figure out start
1175             i = i - numlines/2;
1176
1177     if (i > scoreboardlines - numlines)
1178             i = scoreboardlines - numlines;
1179     if (i < 0)
1180             i = 0;
1181
1182         x = 324;
1183         for (;i < scoreboardlines && y < vid.height - 8;i++)
1184         {
1185                 k = fragsort[i];
1186                 s = &cl.scores[k];
1187                 if (!s->name[0])
1188                         continue;
1189
1190         // draw background
1191                 top = Sbar_ColorForMap (s->colors & 0xf0);
1192                 bottom = Sbar_ColorForMap ((s->colors & 15)<<4);
1193
1194                 Draw_Fill ( x, y+1, 72, 3, top);
1195                 Draw_Fill ( x, y+4, 72, 3, bottom);
1196
1197                 fph = (cl.time - s->entertime) ? (int) ((float) s->frags * 3600.0 / (cl.time - s->entertime)) : 0;
1198                 if (fph < -999) fph = -999;
1199                 if (fph > 9999) fph = 9999;
1200                 
1201                 // put it together
1202                 sprintf (num, "%c%4i:%4i%c %s", k == cl.viewentity - 1 ? 16 : ' ', (int) s->frags, fph, k == cl.viewentity - 1 ? 17 : ' ', s->name);
1203                 Draw_String(x - 8, y, num, 0);
1204
1205                 y += 8;
1206         }
1207 }
1208
1209 /*
1210 ==================
1211 Sbar_IntermissionOverlay
1212
1213 ==================
1214 */
1215 void Sbar_IntermissionOverlay (void)
1216 {
1217         qpic_t  *pic;
1218         int             dig;
1219         int             num;
1220
1221         scr_copyeverything = 1;
1222         scr_fullupdate = 0;
1223
1224         if (cl.gametype == GAME_DEATHMATCH)
1225         {
1226                 Sbar_DeathmatchOverlay ();
1227                 return;
1228         }
1229
1230         pic = Draw_CachePic ("gfx/complete.lmp");
1231         Draw_Pic (64, 24, pic);
1232
1233         pic = Draw_CachePic ("gfx/inter.lmp");
1234         Draw_TransPic (0, 56, pic);
1235
1236 // time
1237         dig = cl.completed_time/60;
1238         Sbar_IntermissionNumber (160, 64, dig, 3, 0);
1239         num = cl.completed_time - dig*60;
1240         Draw_TransPic (234,64,sb_colon);
1241         Draw_TransPic (246,64,sb_nums[0][num/10]);
1242         Draw_TransPic (266,64,sb_nums[0][num%10]);
1243
1244         Sbar_IntermissionNumber (160, 104, cl.stats[STAT_SECRETS], 3, 0);
1245         Draw_TransPic (232,104,sb_slash);
1246         Sbar_IntermissionNumber (240, 104, cl.stats[STAT_TOTALSECRETS], 3, 0);
1247
1248         Sbar_IntermissionNumber (160, 144, cl.stats[STAT_MONSTERS], 3, 0);
1249         Draw_TransPic (232,144,sb_slash);
1250         Sbar_IntermissionNumber (240, 144, cl.stats[STAT_TOTALMONSTERS], 3, 0);
1251
1252 }
1253
1254
1255 /*
1256 ==================
1257 Sbar_FinaleOverlay
1258
1259 ==================
1260 */
1261 void Sbar_FinaleOverlay (void)
1262 {
1263         qpic_t  *pic;
1264
1265         scr_copyeverything = 1;
1266
1267         pic = Draw_CachePic ("gfx/finale.lmp");
1268         Draw_TransPic ( (vid.width-pic->width)/2, 16, pic);
1269 }