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