Indentation cleanup.
[AROS-Contrib.git] / Games / Quake / sbar.c
blobb1a71edab12bd984a1b01e20c274ac374a098f2e
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
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.
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.
13 See the GNU General Public License for more details.
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.
20 // sbar.c -- status bar code
22 #include "quakedef.h"
25 int sb_updates; // if >= vid.numpages, no update needed
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;
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];
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;
47 qboolean sb_showscores;
49 int sb_lines; // scan lines to draw
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
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];
64 void Sbar_MiniDeathmatchOverlay (void);
65 void Sbar_DeathmatchOverlay (void);
66 void M_DrawPic (int x, int y, qpic_t *pic);
69 ===============
70 Sbar_ShowScores
72 Tab key down
73 ===============
75 void Sbar_ShowScores (void)
77 if (sb_showscores)
78 return;
79 sb_showscores = true;
80 sb_updates = 0;
84 ===============
85 Sbar_DontShowScores
87 Tab key up
88 ===============
90 void Sbar_DontShowScores (void)
92 sb_showscores = false;
93 sb_updates = 0;
97 ===============
98 Sbar_Changed
99 ===============
101 void Sbar_Changed (void)
103 sb_updates = 0; // update next frame
107 ===============
108 Sbar_Init
109 ===============
111 void Sbar_Init (void)
113 int i;
115 for (i=0 ; i<10 ; i++)
117 sb_nums[0][i] = Draw_PicFromWad (va("num_%i",i));
118 sb_nums[1][i] = Draw_PicFromWad (va("anum_%i",i));
121 sb_nums[0][10] = Draw_PicFromWad ("num_minus");
122 sb_nums[1][10] = Draw_PicFromWad ("anum_minus");
124 sb_colon = Draw_PicFromWad ("num_colon");
125 sb_slash = Draw_PicFromWad ("num_slash");
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");
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");
143 for (i=0 ; i<5 ; i++)
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));
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");
159 sb_armor[0] = Draw_PicFromWad ("sb_armor1");
160 sb_armor[1] = Draw_PicFromWad ("sb_armor2");
161 sb_armor[2] = Draw_PicFromWad ("sb_armor3");
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");
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");
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");
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");
191 Cmd_AddCommand ("+showscores", Sbar_ShowScores);
192 Cmd_AddCommand ("-showscores", Sbar_DontShowScores);
194 sb_sbar = Draw_PicFromWad ("sbar");
195 sb_ibar = Draw_PicFromWad ("ibar");
196 sb_scorebar = Draw_PicFromWad ("scorebar");
198 //MED 01/04/97 added new hipnotic weapons
199 if (hipnotic)
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");
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");
213 for (i=0 ; i<5 ; i++)
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));
222 hsb_items[0] = Draw_PicFromWad ("sb_wsuit");
223 hsb_items[1] = Draw_PicFromWad ("sb_eshld");
226 if (rogue)
228 rsb_invbar[0] = Draw_PicFromWad ("r_invbar1");
229 rsb_invbar[1] = Draw_PicFromWad ("r_invbar2");
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");
237 rsb_items[0] = Draw_PicFromWad ("r_shield1");
238 rsb_items[1] = Draw_PicFromWad ("r_agrav1");
240 // PGM 01/19/97 - team color border
241 rsb_teambord = Draw_PicFromWad ("r_teambord");
242 // PGM 01/19/97 - team color border
244 rsb_ammo[0] = Draw_PicFromWad ("r_ammolava");
245 rsb_ammo[1] = Draw_PicFromWad ("r_ammomulti");
246 rsb_ammo[2] = Draw_PicFromWad ("r_ammoplasma");
251 //=============================================================================
253 // drawing routines are relative to the status bar location
256 =============
257 Sbar_DrawPic
258 =============
260 void Sbar_DrawPic (int x, int y, qpic_t *pic)
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);
269 =============
270 Sbar_DrawTransPic
271 =============
273 void Sbar_DrawTransPic (int x, int y, qpic_t *pic)
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);
282 ================
283 Sbar_DrawCharacter
285 Draws one solid graphics character
286 ================
288 void Sbar_DrawCharacter (int x, int y, int num)
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);
297 ================
298 Sbar_DrawString
299 ================
301 void Sbar_DrawString (int x, int y, char *str)
303 if (cl.gametype == GAME_DEATHMATCH)
304 Draw_String (x /*+ ((vid.width - 320)>>1)*/, y+ vid.height-SBAR_HEIGHT, str);
305 else
306 Draw_String (x + ((vid.width - 320)>>1), y+ vid.height-SBAR_HEIGHT, str);
310 =============
311 Sbar_itoa
312 =============
314 int Sbar_itoa (int num, char *buf)
316 char *str;
317 int pow10;
318 int dig;
320 str = buf;
322 if (num < 0)
324 *str++ = '-';
325 num = -num;
328 for (pow10 = 10 ; num >= pow10 ; pow10 *= 10)
333 pow10 /= 10;
334 dig = num/pow10;
335 *str++ = '0'+dig;
336 num -= dig*pow10;
337 } while (pow10 != 1);
339 *str = 0;
341 return str-buf;
346 =============
347 Sbar_DrawNum
348 =============
350 void Sbar_DrawNum (int x, int y, int num, int digits, int color)
352 char str[12];
353 char *ptr;
354 int l, frame;
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;
363 while (*ptr)
365 if (*ptr == '-')
366 frame = STAT_MINUS;
367 else
368 frame = *ptr -'0';
370 Sbar_DrawTransPic (x,y,sb_nums[color][frame]);
371 x += 24;
372 ptr++;
376 //=============================================================================
378 int fragsort[MAX_SCOREBOARD];
380 char scoreboardtext[MAX_SCOREBOARD][20];
381 int scoreboardtop[MAX_SCOREBOARD];
382 int scoreboardbottom[MAX_SCOREBOARD];
383 int scoreboardcount[MAX_SCOREBOARD];
384 int scoreboardlines;
387 ===============
388 Sbar_SortFrags
389 ===============
391 void Sbar_SortFrags (void)
393 int i, j, k;
395 // sort by frags
396 scoreboardlines = 0;
397 for (i=0 ; i<cl.maxclients ; i++)
399 if (cl.scores[i].name[0])
401 fragsort[scoreboardlines] = i;
402 scoreboardlines++;
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)
410 k = fragsort[j];
411 fragsort[j] = fragsort[j+1];
412 fragsort[j+1] = k;
416 int Sbar_ColorForMap (int m)
418 return m < 128 ? m + 8 : m + 8;
422 ===============
423 Sbar_UpdateScoreboard
424 ===============
426 void Sbar_UpdateScoreboard (void)
428 int i, k;
429 int top, bottom;
430 scoreboard_t *s;
432 Sbar_SortFrags ();
434 // draw the text
435 memset (scoreboardtext, 0, sizeof(scoreboardtext));
437 for (i=0 ; i<scoreboardlines; i++)
439 k = fragsort[i];
440 s = &cl.scores[k];
441 sprintf (&scoreboardtext[i][1], "%3i %s", s->frags, s->name);
443 top = s->colors & 0xf0;
444 bottom = (s->colors & 15) <<4;
445 scoreboardtop[i] = Sbar_ColorForMap (top);
446 scoreboardbottom[i] = Sbar_ColorForMap (bottom);
453 ===============
454 Sbar_SoloScoreboard
455 ===============
457 void Sbar_SoloScoreboard (void)
459 char str[80];
460 int minutes, seconds, tens, units;
461 int l;
463 sprintf (str,"Monsters:%3i /%3i", cl.stats[STAT_MONSTERS], cl.stats[STAT_TOTALMONSTERS]);
464 Sbar_DrawString (8, 4, str);
466 sprintf (str,"Secrets :%3i /%3i", cl.stats[STAT_SECRETS], cl.stats[STAT_TOTALSECRETS]);
467 Sbar_DrawString (8, 12, str);
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);
477 // draw level name
478 l = strlen (cl.levelname);
479 Sbar_DrawString (232 - l*4, 12, cl.levelname);
483 ===============
484 Sbar_DrawScoreboard
485 ===============
487 void Sbar_DrawScoreboard (void)
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;
499 if (cl.gametype != GAME_DEATHMATCH)
501 Sbar_SoloScoreboard ();
502 return;
505 Sbar_UpdateScoreboard ();
507 l = scoreboardlines <= 6 ? scoreboardlines : 6;
509 for (i=0 ; i<l ; i++)
511 x = 20*(i&1);
512 y = i/2 * 8;
514 s = &cl.scores[fragsort[i]];
515 if (!s->name[0])
516 continue;
518 // draw background
519 top = s->colors & 0xf0;
520 bottom = (s->colors & 15)<<4;
521 top = Sbar_ColorForMap (top);
522 bottom = Sbar_ColorForMap (bottom);
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);
527 // draw text
528 for (j=0 ; j<20 ; j++)
530 c = scoreboardtext[i][j];
531 if (c == 0 || c == ' ')
532 continue;
533 Sbar_DrawCharacter ( (x+j)*8, y, c);
536 #endif
539 //=============================================================================
542 ===============
543 Sbar_DrawInventory
544 ===============
546 void Sbar_DrawInventory (void)
548 int i;
549 char num[6];
550 float time;
551 int flashon;
553 if (rogue)
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]);
560 else
562 Sbar_DrawPic (0, -24, sb_ibar);
565 // weapons
566 for (i=0 ; i<7 ; i++)
568 if (cl.items & (IT_SHOTGUN<<i) )
570 time = cl.item_gettime[i];
571 flashon = (int)((cl.time - time)*10);
572 if (flashon >= 10)
574 if ( cl.stats[STAT_ACTIVEWEAPON] == (IT_SHOTGUN<<i) )
575 flashon = 1;
576 else
577 flashon = 0;
579 else
580 flashon = (flashon%5) + 2;
582 Sbar_DrawPic (i*24, -16, sb_weapons[flashon][i]);
584 if (flashon > 1)
585 sb_updates = 0; // force update to remove flash
589 // MED 01/04/97
590 // hipnotic weapons
591 if (hipnotic)
593 int grenadeflashing=0;
594 for (i=0 ; i<4 ; i++)
596 if (cl.items & (1<<hipweapons[i]) )
598 time = cl.item_gettime[hipweapons[i]];
599 flashon = (int)((cl.time - time)*10);
600 if (flashon >= 10)
602 if ( cl.stats[STAT_ACTIVEWEAPON] == (1<<hipweapons[i]) )
603 flashon = 1;
604 else
605 flashon = 0;
607 else
608 flashon = (flashon%5) + 2;
610 // check grenade launcher
611 if (i==2)
613 if (cl.items & HIT_PROXIMITY_GUN)
615 if (flashon)
617 grenadeflashing = 1;
618 Sbar_DrawPic (96, -16, hsb_weapons[flashon][2]);
622 else if (i==3)
624 if (cl.items & (IT_SHOTGUN<<4))
626 if (flashon && !grenadeflashing)
628 Sbar_DrawPic (96, -16, hsb_weapons[flashon][3]);
630 else if (!grenadeflashing)
632 Sbar_DrawPic (96, -16, hsb_weapons[0][3]);
635 else
636 Sbar_DrawPic (96, -16, hsb_weapons[flashon][4]);
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
646 if (rogue)
648 // check for powered up weapon.
649 if ( cl.stats[STAT_ACTIVEWEAPON] >= RIT_LAVA_NAILGUN )
651 for (i=0;i<5;i++)
653 if (cl.stats[STAT_ACTIVEWEAPON] == (RIT_LAVA_NAILGUN << i))
655 Sbar_DrawPic ((i+2)*24, -16, rsb_weapons[i]);
661 // ammo counts
662 for (i=0 ; i<4 ; i++)
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');
673 flashon = 0;
674 // items
675 for (i=0 ; i<6 ; i++)
676 if (cl.items & (1<<(17+i)))
678 time = cl.item_gettime[17+i];
679 if (time && time > cl.time - 2 && flashon )
680 { // flash frame
681 sb_updates = 0;
683 else
685 //MED 01/04/97 changed keys
686 if (!hipnotic || (i>1))
688 Sbar_DrawPic (192 + i*16, -16, sb_items[i]);
691 if (time && time > cl.time - 2)
692 sb_updates = 0;
694 //MED 01/04/97 added hipnotic items
695 // hipnotic items
696 if (hipnotic)
698 for (i=0 ; i<2 ; i++)
699 if (cl.items & (1<<(24+i)))
701 time = cl.item_gettime[24+i];
702 if (time && time > cl.time - 2 && flashon )
703 { // flash frame
704 sb_updates = 0;
706 else
708 Sbar_DrawPic (288 + i*16, -16, hsb_items[i]);
710 if (time && time > cl.time - 2)
711 sb_updates = 0;
715 if (rogue)
717 // new rogue items
718 for (i=0 ; i<2 ; i++)
720 if (cl.items & (1<<(29+i)))
722 time = cl.item_gettime[29+i];
724 if (time && time > cl.time - 2 && flashon )
725 { // flash frame
726 sb_updates = 0;
728 else
730 Sbar_DrawPic (288 + i*16, -16, rsb_items[i]);
733 if (time && time > cl.time - 2)
734 sb_updates = 0;
738 else
740 // sigils
741 for (i=0 ; i<4 ; i++)
743 if (cl.items & (1<<(28+i)))
745 time = cl.item_gettime[28+i];
746 if (time && time > cl.time - 2 && flashon )
747 { // flash frame
748 sb_updates = 0;
750 else
751 Sbar_DrawPic (320-32 + i*8, -16, sb_sigil[i]);
752 if (time && time > cl.time - 2)
753 sb_updates = 0;
759 //=============================================================================
762 ===============
763 Sbar_DrawFrags
764 ===============
766 void Sbar_DrawFrags (void)
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;
775 Sbar_SortFrags ();
777 // draw the text
778 l = scoreboardlines <= 4 ? scoreboardlines : 4;
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;
787 for (i=0 ; i<l ; i++)
789 k = fragsort[i];
790 s = &cl.scores[k];
791 if (!s->name[0])
792 continue;
794 // draw background
795 top = s->colors & 0xf0;
796 bottom = (s->colors & 15)<<4;
797 top = Sbar_ColorForMap (top);
798 bottom = Sbar_ColorForMap (bottom);
800 Draw_Fill (xofs + x*8 + 10, y, 28, 4, top);
801 Draw_Fill (xofs + x*8 + 10, y+4, 28, 3, bottom);
803 // draw number
804 f = s->frags;
805 sprintf (num, "%3i",f);
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]);
811 if (k == cl.viewentity - 1)
813 Sbar_DrawCharacter (x*8+2, -24, 16);
814 Sbar_DrawCharacter ( (x+4)*8-4, -24, 17);
816 x+=4;
820 //=============================================================================
824 ===============
825 Sbar_DrawFace
826 ===============
828 void Sbar_DrawFace (void)
830 int f, anim;
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))
839 int top, bottom;
840 int xofs;
841 char num[12];
842 scoreboard_t *s;
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);
851 if (cl.gametype == GAME_DEATHMATCH)
852 xofs = 113;
853 else
854 xofs = ((vid.width - 320)>>1) + 113;
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);
860 // draw number
861 f = s->frags;
862 sprintf (num, "%3i",f);
864 if (top==8)
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');
873 else
875 Sbar_DrawCharacter ( 109, 3, num[0]);
876 Sbar_DrawCharacter ( 116, 3, num[1]);
877 Sbar_DrawCharacter ( 123, 3, num[2]);
880 return;
882 // PGM 01/19/97 - team color drawing
884 if ( (cl.items & (IT_INVISIBILITY | IT_INVULNERABILITY) )
885 == (IT_INVISIBILITY | IT_INVULNERABILITY) )
887 Sbar_DrawPic (112, 0, sb_face_invis_invuln);
888 return;
890 if (cl.items & IT_QUAD)
892 Sbar_DrawPic (112, 0, sb_face_quad );
893 return;
895 if (cl.items & IT_INVISIBILITY)
897 Sbar_DrawPic (112, 0, sb_face_invis );
898 return;
900 if (cl.items & IT_INVULNERABILITY)
902 Sbar_DrawPic (112, 0, sb_face_invuln);
903 return;
906 if (cl.stats[STAT_HEALTH] >= 100)
907 f = 4;
908 else
909 f = cl.stats[STAT_HEALTH] / 20;
911 if (cl.time <= cl.faceanimtime)
913 anim = 1;
914 sb_updates = 0; // make sure the anim gets drawn over
916 else
917 anim = 0;
918 Sbar_DrawPic (112, 0, sb_faces[f][anim]);
922 ===============
923 Sbar_Draw
924 ===============
926 void Sbar_Draw (void)
928 if (scr_con_current == vid.height)
929 return; // console is full screen
931 if (sb_updates >= vid.numpages)
932 return;
934 scr_copyeverything = 1;
936 sb_updates++;
938 if (sb_lines && vid.width > 320)
939 Draw_TileClear (0, vid.height - sb_lines, vid.width, sb_lines);
941 if (sb_lines > 24)
943 Sbar_DrawInventory ();
944 if (cl.maxclients != 1)
945 Sbar_DrawFrags ();
948 if (sb_showscores || cl.stats[STAT_HEALTH] <= 0)
950 Sbar_DrawPic (0, 0, sb_scorebar);
951 Sbar_DrawScoreboard ();
952 sb_updates = 0;
954 else if (sb_lines)
956 Sbar_DrawPic (0, 0, sb_sbar);
958 // keys (hipnotic only)
959 //MED 01/04/97 moved keys here so they would not be overwritten
960 if (hipnotic)
962 if (cl.items & IT_KEY1)
963 Sbar_DrawPic (209, 3, sb_items[0]);
964 if (cl.items & IT_KEY2)
965 Sbar_DrawPic (209, 12, sb_items[1]);
967 // armor
968 if (cl.items & IT_INVULNERABILITY)
970 Sbar_DrawNum (24, 0, 666, 3, 1);
971 Sbar_DrawPic (0, 0, draw_disc);
973 else
975 if (rogue)
977 Sbar_DrawNum (24, 0, cl.stats[STAT_ARMOR], 3,
978 cl.stats[STAT_ARMOR] <= 25);
979 if (cl.items & RIT_ARMOR3)
980 Sbar_DrawPic (0, 0, sb_armor[2]);
981 else if (cl.items & RIT_ARMOR2)
982 Sbar_DrawPic (0, 0, sb_armor[1]);
983 else if (cl.items & RIT_ARMOR1)
984 Sbar_DrawPic (0, 0, sb_armor[0]);
986 else
988 Sbar_DrawNum (24, 0, cl.stats[STAT_ARMOR], 3
989 , cl.stats[STAT_ARMOR] <= 25);
990 if (cl.items & IT_ARMOR3)
991 Sbar_DrawPic (0, 0, sb_armor[2]);
992 else if (cl.items & IT_ARMOR2)
993 Sbar_DrawPic (0, 0, sb_armor[1]);
994 else if (cl.items & IT_ARMOR1)
995 Sbar_DrawPic (0, 0, sb_armor[0]);
999 // face
1000 Sbar_DrawFace ();
1002 // health
1003 Sbar_DrawNum (136, 0, cl.stats[STAT_HEALTH], 3
1004 , cl.stats[STAT_HEALTH] <= 25);
1006 // ammo icon
1007 if (rogue)
1009 if (cl.items & RIT_SHELLS)
1010 Sbar_DrawPic (224, 0, sb_ammo[0]);
1011 else if (cl.items & RIT_NAILS)
1012 Sbar_DrawPic (224, 0, sb_ammo[1]);
1013 else if (cl.items & RIT_ROCKETS)
1014 Sbar_DrawPic (224, 0, sb_ammo[2]);
1015 else if (cl.items & RIT_CELLS)
1016 Sbar_DrawPic (224, 0, sb_ammo[3]);
1017 else if (cl.items & RIT_LAVA_NAILS)
1018 Sbar_DrawPic (224, 0, rsb_ammo[0]);
1019 else if (cl.items & RIT_PLASMA_AMMO)
1020 Sbar_DrawPic (224, 0, rsb_ammo[1]);
1021 else if (cl.items & RIT_MULTI_ROCKETS)
1022 Sbar_DrawPic (224, 0, rsb_ammo[2]);
1024 else
1026 if (cl.items & IT_SHELLS)
1027 Sbar_DrawPic (224, 0, sb_ammo[0]);
1028 else if (cl.items & IT_NAILS)
1029 Sbar_DrawPic (224, 0, sb_ammo[1]);
1030 else if (cl.items & IT_ROCKETS)
1031 Sbar_DrawPic (224, 0, sb_ammo[2]);
1032 else if (cl.items & IT_CELLS)
1033 Sbar_DrawPic (224, 0, sb_ammo[3]);
1036 Sbar_DrawNum (248, 0, cl.stats[STAT_AMMO], 3,
1037 cl.stats[STAT_AMMO] <= 10);
1040 if (vid.width > 320) {
1041 if (cl.gametype == GAME_DEATHMATCH)
1042 Sbar_MiniDeathmatchOverlay ();
1046 //=============================================================================
1049 ==================
1050 Sbar_IntermissionNumber
1052 ==================
1054 void Sbar_IntermissionNumber (int x, int y, int num, int digits, int color)
1056 char str[12];
1057 char *ptr;
1058 int l, frame;
1060 l = Sbar_itoa (num, str);
1061 ptr = str;
1062 if (l > digits)
1063 ptr += (l-digits);
1064 if (l < digits)
1065 x += (digits-l)*24;
1067 while (*ptr)
1069 if (*ptr == '-')
1070 frame = STAT_MINUS;
1071 else
1072 frame = *ptr -'0';
1074 Draw_TransPic (x,y,sb_nums[color][frame]);
1075 x += 24;
1076 ptr++;
1081 ==================
1082 Sbar_DeathmatchOverlay
1084 ==================
1086 void Sbar_DeathmatchOverlay (void)
1088 qpic_t *pic;
1089 int i, k, l;
1090 int top, bottom;
1091 int x, y, f;
1092 char num[12];
1093 scoreboard_t *s;
1095 scr_copyeverything = 1;
1096 scr_fullupdate = 0;
1098 pic = Draw_CachePic ("gfx/ranking.lmp");
1099 M_DrawPic ((320-pic->width)/2, 8, pic);
1101 // scores
1102 Sbar_SortFrags ();
1104 // draw the text
1105 l = scoreboardlines;
1107 x = 80 + ((vid.width - 320)>>1);
1108 y = 40;
1109 for (i=0 ; i<l ; i++)
1111 k = fragsort[i];
1112 s = &cl.scores[k];
1113 if (!s->name[0])
1114 continue;
1116 // draw background
1117 top = s->colors & 0xf0;
1118 bottom = (s->colors & 15)<<4;
1119 top = Sbar_ColorForMap (top);
1120 bottom = Sbar_ColorForMap (bottom);
1122 Draw_Fill ( x, y, 40, 4, top);
1123 Draw_Fill ( x, y+4, 40, 4, bottom);
1125 // draw number
1126 f = s->frags;
1127 sprintf (num, "%3i",f);
1129 Draw_Character ( x+8 , y, num[0]);
1130 Draw_Character ( x+16 , y, num[1]);
1131 Draw_Character ( x+24 , y, num[2]);
1133 if (k == cl.viewentity - 1)
1134 Draw_Character ( x - 8, y, 12);
1136 #if 0
1138 int total;
1139 int n, minutes, tens, units;
1141 // draw time
1142 total = cl.completed_time - s->entertime;
1143 minutes = (int)total/60;
1144 n = total - minutes*60;
1145 tens = n/10;
1146 units = n%10;
1148 sprintf (num, "%3i:%i%i", minutes, tens, units);
1150 Draw_String ( x+48 , y, num);
1152 #endif
1154 // draw name
1155 Draw_String (x+64, y, s->name);
1157 y += 10;
1162 ==================
1163 Sbar_DeathmatchOverlay
1165 ==================
1167 void Sbar_MiniDeathmatchOverlay (void)
1169 int i, k;
1170 int top, bottom;
1171 int x, y, f;
1172 char num[12];
1173 scoreboard_t *s;
1174 int numlines;
1176 if (vid.width < 512 || !sb_lines)
1177 return;
1179 scr_copyeverything = 1;
1180 scr_fullupdate = 0;
1182 // scores
1183 Sbar_SortFrags ();
1185 // draw the text
1186 y = vid.height - sb_lines;
1187 numlines = sb_lines/8;
1188 if (numlines < 3)
1189 return;
1191 //find us
1192 for (i = 0; i < scoreboardlines; i++)
1193 if (fragsort[i] == cl.viewentity - 1)
1194 break;
1196 if (i == scoreboardlines) // we're not there
1197 i = 0;
1198 else // figure out start
1199 i = i - numlines/2;
1201 if (i > scoreboardlines - numlines)
1202 i = scoreboardlines - numlines;
1203 if (i < 0)
1204 i = 0;
1206 x = 324;
1207 for (/* */; i < scoreboardlines && y < vid.height - 8 ; i++)
1209 k = fragsort[i];
1210 s = &cl.scores[k];
1211 if (!s->name[0])
1212 continue;
1214 // draw background
1215 top = s->colors & 0xf0;
1216 bottom = (s->colors & 15)<<4;
1217 top = Sbar_ColorForMap (top);
1218 bottom = Sbar_ColorForMap (bottom);
1220 Draw_Fill ( x, y+1, 40, 3, top);
1221 Draw_Fill ( x, y+4, 40, 4, bottom);
1223 // draw number
1224 f = s->frags;
1225 sprintf (num, "%3i",f);
1227 Draw_Character ( x+8 , y, num[0]);
1228 Draw_Character ( x+16 , y, num[1]);
1229 Draw_Character ( x+24 , y, num[2]);
1231 if (k == cl.viewentity - 1) {
1232 Draw_Character ( x, y, 16);
1233 Draw_Character ( x + 32, y, 17);
1236 #if 0
1238 int total;
1239 int n, minutes, tens, units;
1241 // draw time
1242 total = cl.completed_time - s->entertime;
1243 minutes = (int)total/60;
1244 n = total - minutes*60;
1245 tens = n/10;
1246 units = n%10;
1248 sprintf (num, "%3i:%i%i", minutes, tens, units);
1250 Draw_String ( x+48 , y, num);
1252 #endif
1254 // draw name
1255 Draw_String (x+48, y, s->name);
1257 y += 8;
1262 ==================
1263 Sbar_IntermissionOverlay
1265 ==================
1267 void Sbar_IntermissionOverlay (void)
1269 qpic_t *pic;
1270 int dig;
1271 int num;
1273 scr_copyeverything = 1;
1274 scr_fullupdate = 0;
1276 if (cl.gametype == GAME_DEATHMATCH)
1278 Sbar_DeathmatchOverlay ();
1279 return;
1282 pic = Draw_CachePic ("gfx/complete.lmp");
1283 Draw_Pic (64, 24, pic);
1285 pic = Draw_CachePic ("gfx/inter.lmp");
1286 Draw_TransPic (0, 56, pic);
1288 // time
1289 dig = cl.completed_time/60;
1290 Sbar_IntermissionNumber (160, 64, dig, 3, 0);
1291 num = cl.completed_time - dig*60;
1292 Draw_TransPic (234,64,sb_colon);
1293 Draw_TransPic (246,64,sb_nums[0][num/10]);
1294 Draw_TransPic (266,64,sb_nums[0][num%10]);
1296 Sbar_IntermissionNumber (160, 104, cl.stats[STAT_SECRETS], 3, 0);
1297 Draw_TransPic (232,104,sb_slash);
1298 Sbar_IntermissionNumber (240, 104, cl.stats[STAT_TOTALSECRETS], 3, 0);
1300 Sbar_IntermissionNumber (160, 144, cl.stats[STAT_MONSTERS], 3, 0);
1301 Draw_TransPic (232,144,sb_slash);
1302 Sbar_IntermissionNumber (240, 144, cl.stats[STAT_TOTALMONSTERS], 3, 0);
1308 ==================
1309 Sbar_FinaleOverlay
1311 ==================
1313 void Sbar_FinaleOverlay (void)
1315 qpic_t *pic;
1317 scr_copyeverything = 1;
1319 pic = Draw_CachePic ("gfx/finale.lmp");
1320 Draw_TransPic ( (vid.width-pic->width)/2, 16, pic);