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