1 void drawstringright(vector, string, vector, vector, float, float);
2 void drawstringcenter(vector, string, vector, vector, float, float);
3 void Sbar_DrawAccuracyStats();
4 void Sbar_DrawAccuracyStats_Description_Splash(vector);
5 void Sbar_DrawAccuracyStats_Description_Hitscan(vector);
6 float weapon_hits[WEP_COUNT];
7 float weapon_fired[WEP_COUNT];
15 float sbar_hudselector;
16 float sbar_hud_accuracy;
18 float ps_primary, ps_secondary;
19 float ts_primary, ts_secondary;
22 vector element_offset = '0 6 0'; // global item offset from the bottom edge
28 void Sbar_FinaleOverlay()
31 pos_x = (vid_conwidth - 1)/2;
35 //drawpic(pos, "gfx/finale", '0 0 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
37 //drawstring(pos, "END", sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
41 float weaponspace[10];
42 float weapon_first, weapon_last;
43 void Sbar_DrawWeapon_Clear()
48 for(idx = 0; idx < 10; ++idx)
50 for(idx = 0; idx <= 23; ++idx)
52 if(weaponimpulse[idx] >= 0)
60 void Sbar_DrawWeapon(float nr, float fade, float active, float wc)
62 vector pos, vsize, fill_colour;
63 float value, idx, imp, sp, weapon_hit, weapon_damage, weapon_stats;
65 imp = weaponimpulse[nr];
66 weapon_hit = weapon_hits[wc];
67 weapon_damage = weapon_fired[wc];
73 value = (active) ? 1 : 0.6;
74 color_x = color_y = color_z = value;
76 // width = 300, height = 100
77 const float w_width = 25, w_height = 12, w_space = 2, font_size = 8;
79 sp = weaponspace[idx] + 1;
80 weaponspace[idx] = sp;
82 pos_x = (vid_conwidth + 10 - w_width * 9) * 0.5 + w_width * idx;
83 pos_y = (vid_conheight - w_height * sp) - 38; // move 38 pixels up
89 drawpic(pos, "gfx/hud/sb_ammobg", vsize, color, value * fade * sbar_alpha_fg, DRAWFLAG_NORMAL);
90 drawpic(pos, strcat("gfx/hud/inv_weapon", ftos(nr)), vsize, color, value * fade * sbar_alpha_fg, DRAWFLAG_NORMAL);
96 drawstring(pos, ftos(imp), vsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
98 // draw the weapon accuracy on the HUD
101 weapon_stats = rint(100*weapon_hit/weapon_damage);
102 fill_colour_x = 1 - 0.015 * weapon_stats;
103 fill_colour_y = 1 - 0.015 * (100 - weapon_stats);
104 drawstringright(pos + '22 0 0', strcat(ftos(weapon_stats),"%"), '6 6 0', fill_colour, sbar_alpha_fg, 0);
108 void Sbar_DrawXNum (vector pos, float num, float digits, float lettersize, vector rgb, float highlighted, float stroke, float a, float dflags)
111 string str, tmp, l_length;
113 vector vsize, num_color;
116 vsize_x = vsize_y = lettersize;
131 str = strcat(substring("0000000000", 0, digits - strlen(tmp)), tmp);
140 str = substring(str, l-digits, 999);
142 } else if(l < digits)
143 pos_x += (digits-l) * lettersize;
145 if (highlighted == 1) {
147 hl_size_x = vsize_x * l + vsize_x * 0.2;
148 hl_size_y = vsize_y * 1.1;
151 hl_size_x = hl_size_x + vsize_x;
154 hl_pos_x = pos_x - lettersize/10;
155 hl_pos_y = pos_y - lettersize/20;
158 drawpic(hl_pos, strcat("gfx/hud/sb_highlight_", l_length), hl_size, '1 1 1', sbar_alpha_fg, dflags);
166 drawpic(pos, "gfx/hud/num_minus", vsize, num_color, a * sbar_alpha_fg, dflags);
168 drawpic(pos, "gfx/hud/num_minus_stroke", vsize, rgb, a * sbar_alpha_fg, dflags);
172 for(i = 0; i < l; ++i)
174 drawpic(pos, strcat("gfx/hud/num_", substring(str, i, 1)), vsize, num_color, a * sbar_alpha_fg, dflags);
176 drawpic(pos, strcat("gfx/hud/num_", substring(str, i, 1), "_stroke"), vsize, rgb, a * sbar_alpha_fg, dflags);
181 void Sbar_DrawXNum_Colored (vector pos, float x, float lettersize, float alpha)
189 color_x = 0.4 - (x-150)*0.02 * 0.4; //red value between 0.4 -> 0
190 color_y = 0.9 + (x-150)*0.02 * 0.1; // green value between 0.9 -> 1
194 color_x = 1 - (x-100)*0.02 * 0.6; //red value between 1 -> 0.4
195 color_y = 1 - (x-100)*0.02 * 0.1; // green value between 1 -> 0.9
196 color_z = 1 - (x-100)*0.02; // blue value between 1 -> 0
201 color_z = 0.2 + (x-50)*0.02 * 0.8; // blue value between 0.2 -> 1
205 color_y = (x-20)*90/27/100; // green value between 0 -> 1
206 color_z = (x-20)*90/27/100 * 0.2; // blue value between 0 -> 0.2
213 Sbar_DrawXNum(pos, x, 3, lettersize, color, 0, 0, alpha, DRAWFLAG_NORMAL);
216 void Cmd_Sbar_SetFields(float argc);
217 void Sbar_InitScores()
221 ps_primary = ps_secondary = ts_primary = ts_secondary = -1;
222 for(i = 0; i < MAX_SCORE; ++i)
224 f = (scores_flags[i] & SFL_SORT_PRIO_MASK);
225 if(f == SFL_SORT_PRIO_PRIMARY)
227 if(f == SFL_SORT_PRIO_SECONDARY)
230 if(ps_secondary == -1)
231 ps_secondary = ps_primary;
233 for(i = 0; i < MAX_TEAMSCORE; ++i)
235 f = (teamscores_flags[i] & SFL_SORT_PRIO_MASK);
236 if(f == SFL_SORT_PRIO_PRIMARY)
238 if(f == SFL_SORT_PRIO_SECONDARY)
241 if(ts_secondary == -1)
242 ts_secondary = ts_primary;
244 Cmd_Sbar_SetFields(0);
247 void Sbar_UpdatePlayerPos(entity pl);
248 float SetTeam(entity pl, float Team);
250 void Sbar_UpdatePlayerTeams()
257 for(pl = players.sort_next; pl; pl = pl.sort_next)
260 Team = GetPlayerColor(pl.sv_entnum);
261 if(SetTeam(pl, Team))
264 Sbar_UpdatePlayerPos(pl);
268 pl = players.sort_next;
273 print(strcat("PNUM: ", ftos(num), "\n"));
278 float Sbar_ComparePlayerScores(entity left, entity right)
281 vl = GetPlayerColor(left.sv_entnum);
282 vr = GetPlayerColor(right.sv_entnum);
285 vl = COLOR_SPECTATOR;
287 vr = COLOR_SPECTATOR;
294 if(vl == COLOR_SPECTATOR)
296 // FIRST the one with scores (spectators), THEN the ones without (downloaders)
298 if(!left.gotscores && right.gotscores)
303 vl = left.scores[ps_primary];
304 vr = right.scores[ps_primary];
305 if(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)
307 if(vl == 0 && vr != 0)
309 if(vl != 0 && vr == 0)
313 return IS_INCREASING(scores_flags[ps_primary]);
315 return IS_DECREASING(scores_flags[ps_primary]);
317 vl = left.scores[ps_secondary];
318 vr = right.scores[ps_secondary];
319 if(scores_flags[ps_secondary] & SFL_ZERO_IS_WORST)
321 if(vl == 0 && vr != 0)
323 if(vl != 0 && vr == 0)
327 return IS_INCREASING(scores_flags[ps_secondary]);
329 return IS_DECREASING(scores_flags[ps_secondary]);
334 void Sbar_UpdatePlayerPos(entity player)
336 for(other = player.sort_next; other && Sbar_ComparePlayerScores(player, other); other = player.sort_next)
338 SORT_SWAP(player, other);
340 for(other = player.sort_prev; other != players && Sbar_ComparePlayerScores(other, player); other = player.sort_prev)
342 SORT_SWAP(other, player);
346 float Sbar_CompareTeamScores(entity left, entity right)
350 if(left.team == COLOR_SPECTATOR)
352 if(right.team == COLOR_SPECTATOR)
355 vl = left.teamscores[ts_primary];
356 vr = right.teamscores[ts_primary];
358 return IS_INCREASING(teamscores_flags[ts_primary]);
360 return IS_DECREASING(teamscores_flags[ts_primary]);
362 vl = left.teamscores[ts_secondary];
363 vr = right.teamscores[ts_secondary];
365 return IS_INCREASING(teamscores_flags[ts_secondary]);
367 return IS_DECREASING(teamscores_flags[ts_secondary]);
372 void Sbar_UpdateTeamPos(entity Team)
374 for(other = Team.sort_next; other && Sbar_CompareTeamScores(Team, other); other = Team.sort_next)
376 SORT_SWAP(Team, other);
378 for(other = Team.sort_prev; other != teams && Sbar_CompareTeamScores(other, Team); other = Team.sort_prev)
380 SORT_SWAP(other, Team);
384 void Cmd_Sbar_Help(float argc)
386 print("You can modify the scoreboard using the\n");
387 print("^3|---------------------------------------------------------------|\n");
388 print("^1 TO BE DONE\n");
390 print("^2sbar_columns_set default\n");
391 print("^2sbar_columns_set ^7filed1 field2 ...\n");
392 print("The following field names are recognized (case INsensitive):\n");
393 print("You can use a ^3|^7 to start the right-aligned fields.\n");
395 print("^3name^7 or ^3nick^7 Name of a player\n");
396 print("^3ping^7 Ping time\n\n");
397 print("^3kd^7 or ^3kdr^7 or ^3kdratio^7 or ^3k/d\n");
398 print(" The kill-death ratio\n");
400 print("Before a field you can put a + or - sign, then a comma separated list\n");
401 print("of game types, then a slash, to make the field show up only in these\n");
402 print("or in all but these game types.\n");
404 print("The special game type names 'teams' and 'noteams' can be used to\n");
405 print("include/exclude ALL teams/noteams game modes.\n");
408 print("Additional columns:\n");
409 for(i = 0; i < MAX_SCORE; ++i)
411 if(scores_label[i] != "")
412 print(strcat(scores_label[i], "\n"));
416 #define MIN_NAMELEN 24
417 #define MAX_NAMELEN 24
419 string Sbar_DefaultColumnLayout()
421 return strcat( // fteqcc sucks
423 "-teams,race,lms/kills -teams,lms/deaths -teams,lms,race/suicides -race,dm,tdm/frags ", // tdm already has this in "score"
424 "+ctf/caps +ctf/pickups +ctf/fckills +ctf/returns ",
425 "+lms/lives +lms/rank ",
426 "+/caps +kh/pushes +kh/destroyed ",
427 "?+race/laps ?+race/time ?+race/fastest ",
428 "+as/objectives +nexball/faults +nexball/goals ",
429 "-lms,race,nexball/score");
432 void Cmd_Sbar_SetFields(float argc)
437 float have_name, have_primary, have_secondary, have_separator;
440 // TODO: re enable with gametype dependant cvars?
441 if(argc < 2) // no arguments provided
442 argc = tokenizebyseparator(strcat("x ", cvar_string("sbar_columns")), " ");
445 argc = tokenizebyseparator(strcat("x ", Sbar_DefaultColumnLayout()), " ");
449 if(argv(1) == "default")
450 argc = tokenizebyseparator(strcat("x ", Sbar_DefaultColumnLayout()), " ");
451 else if(argv(1) == "all")
454 s = "ping pl color name |";
455 for(i = 0; i < MAX_SCORE; ++i)
458 if(i != ps_secondary)
459 if(scores_label[i] != "")
460 s = strcat(s, " ", scores_label[i]);
462 if(ps_secondary != ps_primary)
463 s = strcat(s, " ", scores_label[ps_secondary]);
464 s = strcat(s, " ", scores_label[ps_primary]);
465 argc = tokenizebyseparator(strcat("x ", s), " ");
472 drawfont = sbar_font;
473 digit = stringwidth("0123456789", FALSE) / 10;
475 for(i = 0; i < argc - 1; ++i)
481 if(substring(str, 0, 1) == "?")
484 str = substring(str, 1, strlen(str) - 1);
487 slash = strstrofs(str, "/", 0);
490 pattern = substring(str, 0, slash);
491 str = substring(str, slash + 1, strlen(str) - (slash + 1));
493 if not(isGametypeInFilter(gametype, teamplay, pattern))
497 strunzone(sbar_title[sbar_num_fields]);
498 sbar_title[sbar_num_fields] = strzone(str);
499 sbar_size[sbar_num_fields] = stringwidth(str, FALSE);
500 str = strtolower(str);
503 sbar_field[sbar_num_fields] = SP_PING;
504 } else if(str == "pl") {
505 sbar_field[sbar_num_fields] = SP_PL;
506 } else if(str == "kd" || str == "kdr" || str == "kdratio" || str == "k/d") {
507 sbar_field[sbar_num_fields] = SP_KDRATIO;
508 } else if(str == "name" || str == "nick") {
509 sbar_field[sbar_num_fields] = SP_NAME;
510 sbar_size[sbar_num_fields] = MIN_NAMELEN; // minimum size? any use?
512 } else if(str == "|") {
513 sbar_field[sbar_num_fields] = SP_SEPARATOR;
516 for(j = 0; j < MAX_SCORE; ++j)
517 if(str == strtolower(scores_label[j]))
518 goto found; // sorry, but otherwise fteqcc -O3 miscompiles this and warns about "unreachable code"
527 print(strcat("^1Error:^7 Unknown score field: '", str, "'\n"));
531 sbar_field[sbar_num_fields] = j;
534 if(j == ps_secondary)
538 if(sbar_num_fields >= MAX_SBAR_FIELDS)
542 if(scores_flags[ps_primary] & SFL_ALLOW_HIDE)
544 if(scores_flags[ps_secondary] & SFL_ALLOW_HIDE)
546 if(ps_primary == ps_secondary)
548 missing = !have_primary + !have_secondary + !have_separator + !have_name;
550 if(sbar_num_fields+missing < MAX_SBAR_FIELDS)
554 strunzone(sbar_title[sbar_num_fields]);
555 for(i = sbar_num_fields; i > 0; --i)
557 sbar_title[i] = sbar_title[i-1];
558 sbar_size[i] = sbar_size[i-1];
559 sbar_field[i] = sbar_field[i-1];
561 sbar_title[0] = strzone("name");
562 sbar_field[0] = SP_NAME;
563 sbar_size[0] = MIN_NAMELEN; // minimum size? any use?
565 print("fixed missing field 'name'\n");
569 strunzone(sbar_title[sbar_num_fields]);
570 for(i = sbar_num_fields; i > 1; --i)
572 sbar_title[i] = sbar_title[i-1];
573 sbar_size[i] = sbar_size[i-1];
574 sbar_field[i] = sbar_field[i-1];
576 sbar_title[1] = strzone("|");
577 sbar_field[1] = SP_SEPARATOR;
578 sbar_size[1] = stringwidth("|", FALSE);
580 print("fixed missing field '|'\n");
583 else if(!have_separator)
585 strunzone(sbar_title[sbar_num_fields]);
586 sbar_title[sbar_num_fields] = strzone("|");
587 sbar_size[sbar_num_fields] = stringwidth("|", FALSE);
588 sbar_field[sbar_num_fields] = SP_SEPARATOR;
590 print("fixed missing field '|'\n");
595 strunzone(sbar_title[sbar_num_fields]);
596 sbar_title[sbar_num_fields] = strzone(scores_label[ps_secondary]);
597 sbar_size[sbar_num_fields] = stringwidth(sbar_title[sbar_num_fields], FALSE);
598 sbar_field[sbar_num_fields] = ps_secondary;
600 print("fixed missing field '", scores_label[ps_secondary], "'\n");
605 strunzone(sbar_title[sbar_num_fields]);
606 sbar_title[sbar_num_fields] = strzone(scores_label[ps_primary]);
607 sbar_size[sbar_num_fields] = stringwidth(sbar_title[sbar_num_fields], FALSE);
608 sbar_field[sbar_num_fields] = ps_primary;
610 print("fixed missing field '", scores_label[ps_primary], "'\n");
614 sbar_field[sbar_num_fields] = SP_END;
618 vector sbar_field_rgb;
619 string sbar_field_icon0;
620 string sbar_field_icon1;
621 string sbar_field_icon2;
622 vector sbar_field_icon0_rgb;
623 vector sbar_field_icon1_rgb;
624 vector sbar_field_icon2_rgb;
625 float sbar_field_icon0_alpha;
626 float sbar_field_icon1_alpha;
627 float sbar_field_icon2_alpha;
628 string Sbar_GetField(entity pl, float field)
630 float tmp, num, denom, f;
632 sbar_field_rgb = '1 1 1';
633 sbar_field_icon0 = "";
634 sbar_field_icon1 = "";
635 sbar_field_icon2 = "";
636 sbar_field_icon0_rgb = '1 1 1';
637 sbar_field_icon1_rgb = '1 1 1';
638 sbar_field_icon2_rgb = '1 1 1';
639 sbar_field_icon0_alpha = 1;
640 sbar_field_icon1_alpha = 1;
641 sbar_field_icon2_alpha = 1;
646 return "\x8D\x8D\x8D"; // >>> sign
647 str = getplayerkey(pl.sv_entnum, "ping");
650 tmp = max(0, min(220, stof(str)-80)) / 220;
651 sbar_field_rgb = '1 1 1' - '0 1 1'*tmp;
657 str = getplayerkey(pl.sv_entnum, "pl");
660 tmp = bound(0, stof(str), 20) / 20; // 20% is REALLY BAD pl
661 sbar_field_rgb = '1 0.5 0.5' - '0 0.5 0.5'*tmp;
665 if(ready_waiting && pl.ready)
667 sbar_field_icon0 = "gfx/sb_player_ready";
671 f = stof(getplayerkey(pl.sv_entnum, "colors"));
673 sbar_field_icon0 = "gfx/sb_playercolor_base";
674 sbar_field_icon1 = "gfx/sb_playercolor_shirt";
675 sbar_field_icon1_rgb = colormapPaletteColor(floor(f / 16), 0);
676 sbar_field_icon2 = "gfx/sb_playercolor_pants";
677 sbar_field_icon2_rgb = colormapPaletteColor(mod(f, 16), 1);
680 return GetPlayerName(pl.sv_entnum);
683 f = pl.(scores[SP_KILLS]);
684 f -= pl.(scores[SP_SUICIDES]);
688 num = pl.(scores[SP_KILLS]);
689 denom = pl.(scores[SP_DEATHS]);
692 sbar_field_rgb = '0 1 0';
694 } else if(num <= 0) {
695 sbar_field_rgb = '1 0 0';
696 str = ftos(num/denom);
698 str = ftos(num/denom);
700 tmp = strstrofs(str, ".", 0);
702 str = substring(str, 0, tmp+2);
706 tmp = pl.(scores[field]);
707 f = scores_flags[field];
708 if(field == ps_primary)
709 sbar_field_rgb = '1 1 0';
710 else if(field == ps_secondary)
711 sbar_field_rgb = '0 1 1';
713 sbar_field_rgb = '1 1 1';
714 return ScoreString(f, tmp);
719 float xmin, xmax, ymin, ymax, sbwidth;
720 float sbar_fixscoreboardcolumnwidth_len;
721 float sbar_fixscoreboardcolumnwidth_iconlen;
722 float sbar_fixscoreboardcolumnwidth_marginlen;
724 float stringwidth_colors(string s)
726 return stringwidth(s, TRUE);
729 float stringwidth_nocolors(string s)
731 return stringwidth(s, FALSE);
734 string Sbar_FixScoreboardColumnWidth(float i, string str)
736 float field, maxsize, j, f;
738 field = sbar_field[i];
740 if(field == SP_NAME) // name gets all remaining space
742 maxsize = (xmax - xmin) / sbar_fontsize_x;
743 for(j = 0; j < sbar_num_fields; ++j) if(j != i) if(sbar_field[j] != SP_SEPARATOR)
744 maxsize -= sbar_size[j] + 1;
746 str = textShortenToWidth(str, maxsize, stringwidth_colors);
747 sbar_fixscoreboardcolumnwidth_len = stringwidth(str, TRUE);
750 sbar_fixscoreboardcolumnwidth_len = stringwidth(str, FALSE);
752 sbar_fixscoreboardcolumnwidth_iconlen = 0;
754 if(sbar_field_icon0 != "")
756 sz = drawgetimagesize(sbar_field_icon0);
758 if(sbar_fixscoreboardcolumnwidth_iconlen < f)
759 sbar_fixscoreboardcolumnwidth_iconlen = f;
762 if(sbar_field_icon1 != "")
764 sz = drawgetimagesize(sbar_field_icon1);
766 if(sbar_fixscoreboardcolumnwidth_iconlen < f)
767 sbar_fixscoreboardcolumnwidth_iconlen = f;
770 if(sbar_field_icon2 != "")
772 sz = drawgetimagesize(sbar_field_icon2);
774 if(sbar_fixscoreboardcolumnwidth_iconlen < f)
775 sbar_fixscoreboardcolumnwidth_iconlen = f;
778 sbar_fixscoreboardcolumnwidth_iconlen *= sbar_fontsize_y / sbar_fontsize_x; // fix icon aspect
780 if(sbar_fixscoreboardcolumnwidth_iconlen != 0 && sbar_fixscoreboardcolumnwidth_len != 0)
781 sbar_fixscoreboardcolumnwidth_marginlen = stringwidth(" ", FALSE);
783 sbar_fixscoreboardcolumnwidth_marginlen = 0;
785 f = sbar_fixscoreboardcolumnwidth_len + sbar_fixscoreboardcolumnwidth_marginlen + sbar_fixscoreboardcolumnwidth_iconlen;
792 void Sbar_PrintScoreboardItem(vector pos, entity pl, float is_self)
798 is_spec = (GetPlayerColor(pl.sv_entnum) == COLOR_SPECTATOR);
805 tmp_y = sbar_fontsize_y;
806 drawfill(pos - '1 1 0', tmp + '2 2 0', '1 1 1', 0.3, DRAWFLAG_NORMAL);
810 for(i = 0; i < sbar_num_fields; ++i)
812 field = sbar_field[i];
813 if(field == SP_SEPARATOR)
816 if(is_spec && field != SP_NAME && field != SP_PING) {
817 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
820 str = Sbar_GetField(pl, field);
821 str = Sbar_FixScoreboardColumnWidth(i, str);
823 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
825 if(field == SP_NAME) {
826 tmp_x = sbar_fontsize_x*(sbar_size[i] - sbar_fixscoreboardcolumnwidth_iconlen - sbar_fixscoreboardcolumnwidth_marginlen) + sbar_fontsize_x;
827 drawcolorcodedstring(pos - tmp, str, sbar_fontsize, 1, DRAWFLAG_NORMAL);
829 tmp_x = sbar_fixscoreboardcolumnwidth_len*sbar_fontsize_x + sbar_fontsize_x;
830 drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, 1, DRAWFLAG_NORMAL);
833 tmp_x = sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
834 if(sbar_field_icon0 != "")
835 drawpic(pos - tmp, sbar_field_icon0, '0 1 0' * sbar_fontsize_y + '1 0 0' * sbar_fontsize_x * sbar_fixscoreboardcolumnwidth_iconlen, sbar_field_icon1_rgb, sbar_field_icon0_alpha, DRAWFLAG_NORMAL);
836 if(sbar_field_icon1 != "")
837 drawpic(pos - tmp, sbar_field_icon1, '0 1 0' * sbar_fontsize_y + '1 0 0' * sbar_fontsize_x * sbar_fixscoreboardcolumnwidth_iconlen, sbar_field_icon1_rgb, sbar_field_icon1_alpha, DRAWFLAG_NORMAL);
838 if(sbar_field_icon2 != "")
839 drawpic(pos - tmp, sbar_field_icon2, '0 1 0' * sbar_fontsize_y + '1 0 0' * sbar_fontsize_x * sbar_fixscoreboardcolumnwidth_iconlen, sbar_field_icon2_rgb, sbar_field_icon2_alpha, DRAWFLAG_NORMAL);
842 if(sbar_field[i] == SP_SEPARATOR)
845 for(i = sbar_num_fields-1; i > 0; --i)
847 field = sbar_field[i];
848 if(field == SP_SEPARATOR)
851 if(is_spec && field != SP_NAME && field != SP_PING) {
852 pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
856 str = Sbar_GetField(pl, field);
857 str = Sbar_FixScoreboardColumnWidth(i, str);
859 if(field == SP_NAME) {
860 tmp_x = sbar_fontsize_x*sbar_fixscoreboardcolumnwidth_len; // left or right aligned? let's put it right...
861 drawcolorcodedstring(pos - tmp, str, sbar_fontsize, 1, DRAWFLAG_NORMAL);
863 tmp_x = sbar_fontsize_x*sbar_fixscoreboardcolumnwidth_len; //strlen(str);
864 drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, 1, DRAWFLAG_NORMAL);
867 tmp_x = sbar_fontsize_x*sbar_size[i];
868 if(sbar_field_icon0 != "")
869 drawpic(pos - tmp, sbar_field_icon0, '0 1 0' * sbar_fontsize_y + '1 0 0' * sbar_fontsize_x * sbar_fixscoreboardcolumnwidth_iconlen, sbar_field_icon1_rgb, sbar_field_icon0_alpha, DRAWFLAG_NORMAL);
870 if(sbar_field_icon1 != "")
871 drawpic(pos - tmp, sbar_field_icon1, '0 1 0' * sbar_fontsize_y + '1 0 0' * sbar_fontsize_x * sbar_fixscoreboardcolumnwidth_iconlen, sbar_field_icon1_rgb, sbar_field_icon1_alpha, DRAWFLAG_NORMAL);
872 if(sbar_field_icon2 != "")
873 drawpic(pos - tmp, sbar_field_icon2, '0 1 0' * sbar_fontsize_y + '1 0 0' * sbar_fontsize_x * sbar_fixscoreboardcolumnwidth_iconlen, sbar_field_icon2_rgb, sbar_field_icon2_alpha, DRAWFLAG_NORMAL);
875 pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
881 float scoreboard_bottom;
882 void Sbar_DrawScoreboard()
884 //float xmin, ymin, xmax, ymax;
885 vector rgb, pos, tmp, sbar_save;
890 if(time > lastpingstime + 10)
893 lastpingstime = time;
896 sbwidth = Sbar_GetWidth(6.5 * sbar_fontsize_y);
898 xmin = 0.5 * (vid_conwidth - sbwidth);
901 xmax = vid_conwidth - xmin;
902 ymax = vid_conheight - 0.2*vid_conheight;
904 center_x = xmin + 0.5*sbwidth;
906 //Sbar_UpdateFields();
908 // Initializes position
914 drawfont = sbar_bigfont;
915 pos_x = center_x - stringwidth("Scoreboard", TRUE)*0.5*24;
916 drawstring(pos, "Scoreboard", '24 24 0', '1 1 1', 1, DRAWFLAG_NORMAL);
920 // Titlebar background:
922 tmp_y = sbar_fontsize_y;
923 drawfill(pos - '1 1 0', tmp + '2 2 0', '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
925 drawfont = sbar_font;
927 for(i = 0; i < sbar_num_fields; ++i)
929 if(sbar_field[i] == SP_SEPARATOR)
931 drawstring(pos, sbar_title[i], sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
932 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
935 if(sbar_field[i] == SP_SEPARATOR)
937 pos_x = xmax + sbar_fontsize_x;
939 for(i = sbar_num_fields-1; i > 0; --i)
941 if(sbar_field[i] == SP_SEPARATOR)
944 pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
947 * Using the following line will mess it all up:
949 * tmp_x = sbar_size[i] - strlen(sbar_title[i])*8;
951 tmp_x = sbar_fontsize_x*sbar_size[i];
952 tmp_x -= stringwidth(sbar_title[i], FALSE)*sbar_fontsize_x;
953 drawstring(pos + tmp, sbar_title[i], sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
958 pos_y += 1.5 * sbar_fontsize_y;
965 //for(tm = sortedTeams.sort_next; tm; tm = tm.sort_next)
966 for(tm = teams.sort_next; tm; tm = tm.sort_next)
968 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
971 rgb = GetTeamRGB(tm.team);
975 Sbar_DrawXNum(sbar + pos - '6.5 0 0' * sbar_fontsize_y, tm.(teamscores[ts_primary]), 4, sbar_fontsize_y * 1.5, rgb, 0, 0, 1, DRAWFLAG_NORMAL);
977 if(ts_primary != ts_secondary)
978 Sbar_DrawXNum(sbar + pos - '4.5 0 0' * sbar_fontsize_y + '0 1.5 0' * sbar_fontsize_y, tm.(teamscores[ts_secondary]), 4, sbar_fontsize_y * 1, rgb, 0, 0, 1, DRAWFLAG_NORMAL);
980 specs = tm.team_size;
986 tmp_y = 1.25 * sbar_fontsize_y * specs;
987 drawfill(pos - '1 1 0', tmp + '2 0 0', rgb, 0.2, DRAWFLAG_NORMAL);
989 for(pl = players.sort_next; pl; pl = pl.sort_next)
991 if(pl.team != tm.team)
993 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
994 pos_y += 1.25 * sbar_fontsize_y;
995 tmp_y -= 1.25 * sbar_fontsize_y;
997 pos_y += tmp_y + 1.5 * sbar_fontsize_y;
999 // rgb := tempvector :)
1000 rgb = pos + '0 1.5 0' * sbar_fontsize_y;
1001 pos_y += 3 * sbar_fontsize_y;
1003 for(pl = players.sort_next; pl; pl = pl.sort_next)
1005 if(pl.team != COLOR_SPECTATOR)
1007 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
1008 pos += '0 1.25 0' * sbar_fontsize_y;
1013 drawstring(rgb, "Spectators", sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
1016 for(pl = players.sort_next; pl; pl = pl.sort_next)
1018 if(pl.team == COLOR_SPECTATOR)
1020 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
1021 pos_y += 1.25 * sbar_fontsize_y;
1022 tmp_y -= 1.25 * sbar_fontsize_y;
1025 // rgb := tempvector :)
1026 rgb = pos + '0 1.5 0' * sbar_fontsize_y;
1027 pos_y += 3 * sbar_fontsize_y;
1029 for(pl = players.sort_next; pl; pl = pl.sort_next)
1031 if(pl.team != COLOR_SPECTATOR)
1033 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
1034 pos += '0 1.25 0' * sbar_fontsize_y;
1039 drawstring(rgb, "Spectators", sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
1044 str = strcat("playing on ^2", shortmapname, "^7");
1045 tl = getstatf(STAT_TIMELIMIT);
1046 fl = getstatf(STAT_FRAGLIMIT);
1047 ll = getstatf(STAT_LEADLIMIT);
1048 if(gametype == GAME_LMS)
1051 str = strcat(str, " for up to ^1", ftos(tl), " minutes^7");
1056 str = strcat(str, " for ^1", ftos(tl), " minutes^7");
1060 str = strcat(str, " or");
1063 str = strcat(str, " until ^3", ScoreString(teamscores_flags[ts_primary], fl));
1064 if(teamscores_label[ts_primary] == "score")
1065 str = strcat(str, " points^7");
1066 else if(teamscores_label[ts_primary] == "fastest")
1067 str = strcat(str, " is beaten^7");
1069 str = strcat(str, " ", teamscores_label[ts_primary]);
1073 str = strcat(str, " until ^3", ScoreString(scores_flags[ps_primary], fl));
1074 if(scores_label[ps_primary] == "score")
1075 str = strcat(str, " points^7");
1076 else if(scores_label[ps_primary] == "fastest")
1077 str = strcat(str, " is beaten^7");
1079 str = strcat(str, " ", scores_label[ps_primary]);
1084 if(tl > 0 || fl > 0)
1085 str = strcat(str, " or");
1088 str = strcat(str, " until a lead of ^3", ScoreString(teamscores_flags[ts_primary], ll));
1089 if(teamscores_label[ts_primary] == "score")
1090 str = strcat(str, " points^7");
1091 else if(teamscores_label[ts_primary] == "fastest")
1092 str = strcat(str, " is beaten^7");
1094 str = strcat(str, " ", teamscores_label[ts_primary]);
1098 str = strcat(str, " until a lead of ^3", ScoreString(scores_flags[ps_primary], ll));
1099 if(scores_label[ps_primary] == "score")
1100 str = strcat(str, " points^7");
1101 else if(scores_label[ps_primary] == "fastest")
1102 str = strcat(str, " is beaten^7");
1104 str = strcat(str, " ", scores_label[ps_primary]);
1110 pos_y += 1.2 * sbar_fontsize_y;
1111 drawcolorcodedstring(pos + '0.5 0 0' * (sbwidth - sbar_fontsize_x * stringwidth(str, TRUE)), str, sbar_fontsize, 0.8, DRAWFLAG_NORMAL);
1114 scoreboard_bottom = pos_y + 2 * sbar_fontsize_y;
1117 string MakeRaceString(float cp, float mytime, float histime, float lapdelta, string hisname)
1125 if(histime == 0) // goal hit
1129 timestr = strcat("+", ftos_decimals(+mytime, 1));
1132 else if(mytime == 0)
1139 timestr = strcat("-", ftos_decimals(-mytime, 1));
1145 lapstr = strcat(" (-", ftos(lapdelta), "L)");
1148 else if(lapdelta < 0)
1150 lapstr = strcat(" (+", ftos(-lapdelta), "L)");
1154 else if(histime > 0) // anticipation
1156 if(mytime >= histime)
1157 timestr = strcat("+", ftos_decimals(mytime - histime, 1));
1159 timestr = mmsss(histime * 10);
1166 cpname = strcat("Intermediate ", ftos(cp));
1168 cpname = "Finish line";
1171 return strcat(col, cpname);
1172 else if(hisname == "")
1173 return strcat(col, cpname, " (", timestr, ")");
1175 return strcat(col, cpname, " (", timestr, " ", strcat(hisname, col, lapstr), ")");
1178 void Sbar_Score(float margin)
1180 float timelimit, minutes, seconds, timeleft, minutesLeft, secondsLeft, distribution, myplace, score, desiredPlayerId;
1181 vector sbar_save, place, timer_color, offset;
1186 bottomright_x = vid_conwidth;
1187 bottomright_y = vid_conheight;
1191 topright_x = vid_conwidth;
1195 //get the ID (could be "me", or the player I'm spectating)
1196 desiredPlayerId = player_localentnum - 1;
1197 if (spectatee_status) {
1198 if (spectatee_status != -1) {
1199 desiredPlayerId = spectatee_status - 1;
1203 sbar_y = vid_conheight - (32+12);
1212 // team1 team3 team4
1215 //for(i = 0; i < 4; ++i)
1216 if (cvar("vid_conwidth") >= 800) {
1226 float max_fragcount;
1227 max_fragcount = -999;
1229 for(tm = teams.sort_next; tm; tm = tm.sort_next)
1231 if(tm.team == COLOR_SPECTATOR || !tm.team_size) // no players? don't display
1234 score = tm.(teamscores[ts_primary]);
1236 if (score > max_fragcount)
1237 max_fragcount = score;
1239 if(tm.team == myteam) {
1240 if (max_fragcount == score)
1241 Sbar_DrawXNum(bottomright - element_offset - place, score, 4, 34, GetTeamRGB(tm.team) * 0.8, 1, 1, sbar_alpha_fg, DRAWFLAG_NORMAL);
1243 Sbar_DrawXNum(bottomright - element_offset - place, score, 4, 34, GetTeamRGB(tm.team) * 0.8, 0, 1, sbar_alpha_fg, DRAWFLAG_NORMAL);
1247 if (max_fragcount == score)
1248 Sbar_DrawXNum(bottomright - element_offset - place + '132 -6 0' - offset, score, 4, 16, GetTeamRGB(tm.team) * 0.8, 1, 1, sbar_alpha_fg, DRAWFLAG_NORMAL);
1250 Sbar_DrawXNum(bottomright - element_offset - place + '132 -6 0' - offset, score, 4, 16, GetTeamRGB(tm.team) * 0.8, 0, 1, sbar_alpha_fg, DRAWFLAG_NORMAL);
1255 // me vector := [team/connected frags id]
1258 for(me = players.sort_next; me; me = me.sort_next)
1260 if(me.team != COLOR_SPECTATOR)
1262 if(me.sv_entnum == desiredPlayerId)
1266 pl = players.sort_next;
1271 distribution = me.(scores[ps_primary]);
1272 distribution -= pl.(scores[ps_primary]);
1276 if (cvar("vid_conwidth") >= 800) {
1281 else { // move the scores if vid_conwidth < 800
1285 score = me.(scores[ps_primary]);
1287 if(distribution >= 0)
1289 if (distribution != 0) {
1290 // draw a + sign in front of the score
1291 if (distribution < 10) { drawpic(bottomright - element_offset - place + '132 -6 0' + '32 0 0', "gfx/hud/num_plus", '16 16 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE); }
1292 else if (distribution < 100) { drawpic(bottomright - element_offset - place + '132 -6 0' + '16 0 0', "gfx/hud/num_plus", '16 16 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE); }
1293 else if (distribution < 1000) { drawpic(bottomright - element_offset - place + '132 -6 0', "gfx/hud/num_plus", '16 16 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE); }
1296 Sbar_DrawXNum(bottomright - element_offset - place + '132 -6 0', distribution, 4, 16, ' 1 1 1', 0, 0, sbar_alpha_fg, DRAWFLAG_NORMAL);
1297 Sbar_DrawXNum(bottomright - element_offset - place, score, 4, 34, '1 1 1', 1, 0, sbar_alpha_fg, DRAWFLAG_NORMAL);
1299 else if(distribution >= -5)
1301 Sbar_DrawXNum(bottomright - element_offset - place + '132 -6 0', distribution, 4, 16, ' 1 1 0', 0, 0, sbar_alpha_fg, DRAWFLAG_NORMAL);
1302 Sbar_DrawXNum(bottomright - element_offset - place, score, 4, 34, '1 1 0', 0, 0, sbar_alpha_fg, DRAWFLAG_NORMAL);
1305 Sbar_DrawXNum(bottomright - element_offset - place + '132 -6 0', distribution, 4, 16, ' 1 0 0', 0, 0, sbar_alpha_fg, DRAWFLAG_NORMAL);
1306 Sbar_DrawXNum(bottomright - element_offset - place, score, 4, 34, '1 0 0', 0, 0, sbar_alpha_fg, DRAWFLAG_NORMAL);
1310 //draw the remaining or elapsed time
1311 timelimit = getstatf(STAT_TIMELIMIT);
1316 timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
1317 timeleft = ceil(timeleft);
1318 minutesLeft = floor(timeleft / 60);
1319 secondsLeft = timeleft - minutesLeft*60;
1321 if(minutesLeft >= 5 || warmup_stage) //don't use red or yellow for timer during warmup
1322 timer_color = '1 1 1'; //white
1323 else if(minutesLeft >= 1)
1324 timer_color = '1 1 0'; //yellow
1326 timer_color = '1 0 0'; //red
1328 if (cvar("sbar_increment_maptime")) {
1329 if (time < getstatf(STAT_GAMESTARTTIME)) {
1330 //while restart is still active, show negative counter
1332 seconds = ceil(getstatf(STAT_GAMESTARTTIME) - time);
1335 elapsedTime = floor(time - getstatf(STAT_GAMESTARTTIME)); //127
1336 minutes = floor(elapsedTime / 60);
1337 seconds = elapsedTime - minutes*60;
1340 minutes = minutesLeft;
1341 seconds = secondsLeft;
1345 if (cvar("sbar_increment_maptime") == 1)
1346 bgpos_x = topright_x - 54 - 17 - 12;
1348 bgpos_x = topright_x - 36 - 7 - 12;
1350 else if (minutes < 10) // nudge the timer background left if more digits are drawn
1351 bgpos_x = topright_x - 54 - 17 - 12;
1352 else if (minutes < 100)
1353 bgpos_x = topright_x - 72 - 17 - 12;
1355 bgpos_x = topright_x - 90 - 17 - 12;
1359 if (cvar("viewsize") <= 100) { // draw timer background when viewsize <= 100
1361 drawpic(bgpos, "gfx/hud/sb_timerbg", '120 30 0', GetTeamRGB(myteam) * cvar("sbar_color_bg_team"), sbar_alpha_bg, DRAWFLAG_NORMAL); // timer bg color = myteam color
1363 color_x = cvar("sbar_color_bg_r");
1364 color_y = cvar("sbar_color_bg_g");
1365 color_z = cvar("sbar_color_bg_b");
1367 drawpic(bgpos, "gfx/hud/sb_timerbg", '120 30 0', color, sbar_alpha_bg, DRAWFLAG_NORMAL);
1371 if(minutesLeft >= 1) {
1372 Sbar_DrawXNum(topright - '103 0 0' + '0 2 0', minutes, 3, 18, timer_color, 0, 0, sbar_alpha_fg, DRAWFLAG_NORMAL);
1373 drawpic(topright - '53 0 0' + '0 1 0', "gfx/hud/num_colon", '18 18 0', timer_color, sbar_alpha_fg, DRAWFLAG_NORMAL);
1375 Sbar_DrawXNum(topright - '36 0 0' - '3 0 0' + '0 2 0', seconds, -2, 18, timer_color, 0, 0, sbar_alpha_fg, DRAWFLAG_NORMAL);
1378 timer_color = '1 1 1'; //white
1379 minutes = floor(time / 60);
1380 seconds = floor(time - minutes*60);
1383 bgpos_x = topright_x - 54 - 17 - 12;
1384 else if (minutes < 100) // nudge the timer background left if more digits are drawn
1385 bgpos_x = topright_x - 72 - 17 - 12;
1387 bgpos_x = topright_x - 90 - 17 - 12;
1391 if (cvar("viewsize") <= 100) { // draw timer background when viewsize <= 100
1393 drawpic(bgpos, "gfx/hud/sb_timerbg", '120 30 0', GetTeamRGB(myteam) * cvar("sbar_color_bg_team"), sbar_alpha_bg, DRAWFLAG_NORMAL); // timer bg color = myteam color
1395 color_x = cvar("sbar_color_bg_r");
1396 color_y = cvar("sbar_color_bg_g");
1397 color_z = cvar("sbar_color_bg_b");
1399 drawpic(bgpos, "gfx/hud/sb_timerbg", '120 30 0', color, sbar_alpha_bg, DRAWFLAG_NORMAL);
1403 Sbar_DrawXNum(topright - '103 0 0' + '0 2 0', minutes, 3, 18, timer_color, 0, 0, sbar_alpha_fg, DRAWFLAG_NORMAL);
1404 drawpic(topright - '53 0 0' + '0 1 0', "gfx/hud/num_colon", '18 18 0', timer_color, sbar_alpha_fg, DRAWFLAG_NORMAL);
1405 Sbar_DrawXNum(topright - '36 0 0' - '3 0 0' + '0 2 0', seconds, -2, 18, timer_color, 0, 0, sbar_alpha_fg, DRAWFLAG_NORMAL);
1408 if(gametype == GAME_RACE)
1410 drawfont = sbar_bigfont;
1413 string s, forcetime;
1415 m = '0.5 0 0' * vid_conwidth + '0 0.25 0' * vid_conheight;
1417 if(race_checkpointtime)
1419 a = bound(0, 2 - (time - race_checkpointtime), 1);
1422 if(a > 0) // just hit a checkpoint?
1424 if(race_time && race_previousbesttime)
1425 s = MakeRaceString(race_checkpoint, race_time / 10 - race_previousbesttime / 10, 0, 0, race_previousbestname);
1427 s = MakeRaceString(race_checkpoint, 0, -1, 0, race_previousbestname);
1429 forcetime = mmsss(race_time);
1433 if(race_laptime && race_nextbesttime)
1435 a = bound(0, 2 - ((race_laptime + race_nextbesttime/10) - time), 1);
1436 if(a > 0) // next one?
1438 s = MakeRaceString(race_nextcheckpoint, time - race_laptime, race_nextbesttime / 10, 0, race_nextbestname);
1443 if(s != "" && a > 0)
1445 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
1446 drawcolorcodedstring(m - '0 16 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', sbar_alpha_fg * a, DRAWFLAG_NORMAL);
1451 a = bound(0, (time - race_checkpointtime) / 0.5, 1);
1452 drawstring_expanding(m - '16 0 0' * stringwidth(forcetime, FALSE), forcetime, '32 32 0', '1 1 1', sbar_alpha_fg, 0, a);
1459 s = mmsss(10*(time - race_laptime));
1460 drawstring(m - '16 0 0' * stringwidth(s, FALSE), s, '32 32 0', '1 1 1', sbar_alpha_fg * a, DRAWFLAG_NORMAL);
1465 if(race_mycheckpointtime)
1467 a = bound(0, 2 - (time - race_mycheckpointtime), 1);
1468 s = MakeRaceString(race_mycheckpoint, race_mycheckpointdelta / 10, -!race_mycheckpointenemy, race_mycheckpointlapsdelta, race_mycheckpointenemy);
1469 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
1470 drawcolorcodedstring(m - '0 16 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', sbar_alpha_fg * a, DRAWFLAG_NORMAL);
1472 if(race_othercheckpointtime && race_othercheckpointenemy != "")
1474 a = bound(0, 2 - (time - race_othercheckpointtime), 1);
1475 s = MakeRaceString(race_othercheckpoint, -race_othercheckpointdelta / 10, -!race_othercheckpointenemy, race_othercheckpointlapsdelta, race_othercheckpointenemy);
1476 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
1477 drawcolorcodedstring(m - '0 0 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', sbar_alpha_fg * a, DRAWFLAG_NORMAL);
1481 drawfont = sbar_font;
1487 float Sbar_WouldDrawScoreboard ()
1491 else if (intermission == 1)
1493 else if (intermission == 2)
1495 else if (getstati(STAT_HEALTH) <= 0 && cvar("cl_deathscoreboard"))
1497 else if(sb_showscores_force)
1502 void CSQC_Strength_Timer() {
1505 bottom_x = vid_conwidth/2;
1506 bottom_y = vid_conheight;
1509 float stat_items, dt;
1510 stat_items = getstati(STAT_ITEMS);
1512 if not(stat_items & IT_STRENGTH)
1513 if not(stat_items & IT_INVINCIBLE)
1517 if (getstati(STAT_HEALTH) <= 0)
1521 float strength_time, invincibility_time, countdown_fontsize;
1523 picsize = '22 22 0';
1524 countdown_fontsize = 18;
1527 strength_time = getstatf(STAT_STRENGTH_FINISHED);
1528 invincibility_time = getstatf(STAT_INVINCIBLE_FINISHED);
1530 if (strength_time) {
1531 dt = strength_time - time;
1536 drawpic_expanding_two(bottom + '192 -46 0', "gfx/hud/sb_str", picsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE,
1537 bound(0, (ceil(dt) - dt) / 0.5, 1));
1541 drawpic(bottom + '192 -46 0', "gfx/hud/sb_str", picsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE);
1543 Sbar_DrawXNum(bottom + '152 -44 0', ceil(dt), 2, countdown_fontsize, '1 1 1', 0, 0, sbar_alpha_fg, DRAWFLAG_NORMAL);
1547 drawpic_expanding(bottom + '192 -46 0', "gfx/hud/sb_str", picsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE,
1548 bound(0, -dt / 0.5, 1));
1553 if (invincibility_time) {
1554 dt = invincibility_time - time;
1559 drawpic_expanding_two(bottom + '192 -24 0', "gfx/hud/sb_invinc", picsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE,
1560 bound(0, (ceil(dt) - dt) / 0.5, 1));
1564 drawpic(bottom + '192 -24 0', "gfx/hud/sb_invinc", picsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE);
1566 Sbar_DrawXNum(bottom + '152 -22 0', ceil(dt), 2, countdown_fontsize, '1 1 1', 0, 0, 1, DRAWFLAG_NORMAL);
1570 drawpic_expanding(bottom + '192 -24 0', "gfx/hud/sb_invinc", picsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE,
1571 bound(0, -dt / 0.5, 1));
1576 #define CENTERPRINT_MAX_LINES 30
1577 string centerprint_messages[CENTERPRINT_MAX_LINES];
1578 float centerprint_width[CENTERPRINT_MAX_LINES];
1579 vector centerprint_start;
1580 float centerprint_expire;
1581 float centerprint_num;
1582 float centerprint_offset_hint;
1583 vector centerprint_fontsize;
1585 void centerprint(string strMessage)
1587 float i, j, n, hcount;
1590 centerprint_fontsize = Sbar_GetFontsize("scr_centersize");
1592 centerprint_expire = min(centerprint_expire, time); // if any of the returns happens, this message will fade out
1594 if(cvar("scr_centertime") <= 0)
1597 if(strMessage == "")
1600 // strip trailing newlines
1601 j = strlen(strMessage) - 1;
1602 while(substring(strMessage, j, 1) == "\n" && j >= 0)
1604 strMessage = substring(strMessage, 0, j + 1);
1606 if(strMessage == "")
1609 // strip leading newlines and remember them, they are a hint that the message should be lower on the screen
1611 while(substring(strMessage, j, 1) == "\n" && j < strlen(strMessage))
1613 strMessage = substring(strMessage, j, strlen(strMessage) - j);
1614 centerprint_offset_hint = j;
1616 if(strMessage == "")
1619 // if we get here, we have a message. Initialize its height.
1620 centerprint_num = 0;
1622 n = tokenizebyseparator(strMessage, "\n");
1624 for(j = 0; j < n; ++j)
1626 getWrappedLine_remaining = argv(j);
1627 while(getWrappedLine_remaining)
1629 s = getWrappedLine(vid_conwidth * 0.75 / centerprint_fontsize_x, stringwidth_colors);
1630 if(centerprint_messages[i])
1631 strunzone(centerprint_messages[i]);
1632 centerprint_messages[i] = strzone(s);
1633 centerprint_width[i] = stringwidth(s, TRUE);
1636 // half height for empty lines looks better
1642 if(i >= CENTERPRINT_MAX_LINES)
1648 h = centerprint_fontsize_y*hcount;
1650 havail = vid_conheight;
1651 if(cvar("con_chatpos") < 0)
1652 havail -= (-cvar("con_chatpos") + cvar("con_chat")) * cvar("con_chatsize"); // avoid overlapping chat
1654 centerprint_start_x = 0;
1657 float forbiddenmin, forbiddenmax, allowedmin, allowedmax, preferred;
1659 // here, the centerprint would cover the crosshair. REALLY BAD.
1660 forbiddenmin = vid_conheight * 0.5 - h - 16;
1661 forbiddenmax = vid_conheight * 0.5 + 16;
1663 allowedmin = scoreboard_bottom;
1664 allowedmax = havail - h;
1665 preferred = (havail - h)/2;
1668 // possible orderings (total: 4! / 4 = 6)
1669 // allowedmin allowedmax forbiddenmin forbiddenmax
1670 // forbiddenmin forbiddenmax allowedmin allowedmax
1671 if(allowedmax < forbiddenmin || allowedmin > forbiddenmax)
1673 // forbidden doesn't matter in this case
1674 centerprint_start_y = bound(allowedmin, preferred, allowedmax);
1676 // allowedmin forbiddenmin allowedmax forbiddenmax
1677 else if(allowedmin < forbiddenmin && allowedmax < forbiddenmax)
1679 centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
1681 // allowedmin forbiddenmin forbiddenmax allowedmax
1682 else if(allowedmin < forbiddenmin)
1684 // make sure the forbidden zone is not covered
1685 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
1686 centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
1688 centerprint_start_y = bound(forbiddenmax, preferred, allowedmin);
1690 // forbiddenmin allowedmin allowedmax forbiddenmax
1691 else if(allowedmax < forbiddenmax)
1693 // it's better to leave the allowed zone (overlap with scoreboard) than
1694 // to cover the forbidden zone (crosshair)
1695 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
1696 centerprint_start_y = forbiddenmax;
1698 centerprint_start_y = forbiddenmin;
1700 // forbiddenmin allowedmin forbiddenmax allowedmax
1703 centerprint_start_y = bound(forbiddenmax, preferred, allowedmax);
1706 centerprint_start_y =
1709 max(scoreboard_bottom, vid_conheight * 0.5 + 16),
1716 centerprint_num = i;
1717 centerprint_expire = time + cvar("scr_centertime");
1720 void Sbar_DrawCenterPrint (void)
1727 //if(time > centerprint_expire)
1730 //a = bound(0, 1 - 2 * (time - centerprint_expire), 1);
1731 a = bound(0, 1 - 4 * (time - centerprint_expire), 1);
1732 //sz = 1.2 / (a + 0.2);
1737 pos = centerprint_start;
1738 for (i=0; i<centerprint_num; i = i + 1)
1740 pos_x = (vid_conwidth - centerprint_fontsize_x * centerprint_width[i]) * 0.5;
1741 ts = centerprint_messages[i];
1744 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
1745 drawcolorcodedstring(pos, ts, centerprint_fontsize, a, DRAWFLAG_NORMAL);
1746 // - '0 0.5 0' * (sz - 1) * centerprint_fontsize_x - '0.5 0 0' * (sz - 1) * centerprint_width[i] * centerprint_fontsize_y, centerprint_fontsize * sz
1747 pos_y = pos_y + centerprint_fontsize_y;
1750 // half height for empty lines looks better
1751 pos_y = pos_y + centerprint_fontsize_y * 0.5;
1755 vector Sbar_DrawNoteLine(vector offset, string s)
1757 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
1758 drawcolorcodedstring(
1759 offset - sbar_fontsize_x * '1 0 0' * stringwidth(s, TRUE),
1765 return offset + sbar_fontsize_y * '0 1 0';
1768 void Sbar_DrawPressedKeys(void)
1773 pos = stov(cvar_string("cl_showpressedkeys_position"));
1775 bgsize = '126 75 0';
1777 pos = '1 0 0' * (vid_conwidth - bgsize_x) * pos_x
1778 + '0 1 0' * (vid_conheight - bgsize_y) * pos_y;
1779 pos -= '-15 -6 0'; // adjust to the origin of these numbers
1781 pressedkeys = getstatf(STAT_PRESSED_KEYS);
1782 drawpic(pos + '-15 -6 0', "gfx/hud/keys/key_bg.tga", bgsize, '1 1 1', .1, DRAWFLAG_NORMAL);
1783 drawpic(pos + ' 83.5 9 0', ((pressedkeys & KEY_CROUCH) ? "gfx/hud/keys/key_crouch_inv.tga" : "gfx/hud/keys/key_crouch.tga"), ' 24 24 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1784 drawpic(pos + ' 32 -1.5 0', ((pressedkeys & KEY_FORWARD) ? "gfx/hud/keys/key_forward_inv.tga" : "gfx/hud/keys/key_forward.tga"), ' 32 32 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1785 drawpic(pos + '-11.5 9 0', ((pressedkeys & KEY_JUMP) ? "gfx/hud/keys/key_jump_inv.tga" : "gfx/hud/keys/key_jump.tga"), ' 24 24 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1786 drawpic(pos + ' -1 32 0', ((pressedkeys & KEY_LEFT) ? "gfx/hud/keys/key_left_inv.tga" : "gfx/hud/keys/key_left.tga"), ' 32 32 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1787 drawpic(pos + ' 32 32 0', ((pressedkeys & KEY_BACKWARD) ? "gfx/hud/keys/key_backward_inv.tga" : "gfx/hud/keys/key_backward.tga"), ' 32 32 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1788 drawpic(pos + ' 65 32 0', ((pressedkeys & KEY_RIGHT) ? "gfx/hud/keys/key_right_inv.tga" : "gfx/hud/keys/key_right.tga"), ' 32 32 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1791 void Sbar_ShowSpeed(void)
1797 if (cvar("cl_showspeed_z") == 1)
1798 speed = ftos(floor(vlen(pmove_vel) + 0.5));
1800 speed = ftos(floor(vlen(pmove_vel - pmove_vel_z * '0 0 1') + 0.5));
1802 pos = cvar("cl_showspeed_position");
1803 numsize_x = numsize_y = cvar("cl_showspeed_size");
1804 pos = (vid_conheight - numsize_y) * pos;
1806 drawstringcenter('1 0 0' + pos * '0 1 0', speed, numsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
1809 void Sbar_DrawAccuracyStats()
1811 float i, count_hitscan, count_splash, row; // count is the number of 'colums'
1812 float weapon_hit, weapon_damage, weapon_stats;
1813 float left_border; // position where the weapons start, the description is in the border
1814 float border_thickness = 2;
1815 vector fill_colour, fill_size;
1818 float col_margin = 20; // pixels between the columns
1819 float row_margin = 20; // pixels between the rows
1820 float top_border; // position where the first row starts: pixels down the screen
1822 fill_size_x = 5 * sbar_fontsize_x; // width of the background
1823 fill_size_y = 10 * sbar_fontsize_y; // height of the background
1825 // 45 pixels is the same as the 'Scoreboard' heading
1826 drawfont = sbar_bigfont;
1827 drawstringcenter('0 45 0', "Weapon Accuracy", 2 * sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
1828 left_border = col_margin + 11 * sbar_fontsize_x;
1831 Sbar_DrawAccuracyStats_Description_Hitscan('1 0 0' * col_margin + '0 1 0' * top_border);
1834 Sbar_DrawAccuracyStats_Description_Splash('1 0 0' * col_margin + '0 1 0' * top_border);
1837 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1839 weapon_hit = weapon_hits[i];
1840 weapon_damage = weapon_fired[i];
1841 self = get_weaponinfo(i);
1843 //if ((weapon_number != 42)) // print them all :)
1844 if ((self.weapon_type == WEP_TYPE_SPLASH) && (weapon_damage))
1847 weapon_stats = rint(100 * weapon_hit / weapon_damage);
1849 fill_colour_x = 1 - 0.015 * weapon_stats;
1850 fill_colour_y = 1 - 0.015 * (100 - weapon_stats);
1852 // how the background colour is calculated
1853 // % red green red_2 green_2
1854 // 0 1 0 1 - % * 0.015 1 - (100 - %) * 0.015
1855 // 10 0.85 0 1 - % * 0.015 1 - (100 - %) * 0.015
1856 // 20 0.70 0 1 - % * 0.015 1 - (100 - %) * 0.015
1857 // 30 0.55 0 1 - % * 0.015 1 - (100 - %) * 0.015
1858 // 40 0.40 0.10 1 - % * 0.015 1 - (100 - %) * 0.015
1859 // 50 0.25 0.25 1 - % * 0.015 1 - (100 - %) * 0.015
1860 // 60 0.10 0.40 1 - % * 0.015 1 - (100 - %) * 0.015
1861 // 70 0 0.55 1 - % * 0.015 1 - (100 - %) * 0.015
1862 // 80 0 0.70 1 - % * 0.015 1 - (100 - %) * 0.015
1863 // 90 0 0.85 1 - % * 0.015 1 - (100 - %) * 0.015
1864 // 100 0 1 1 - % * 0.015 1 - (100 - %) * 0.015
1866 if ((left_border + count_splash * (fill_size_x + col_margin) + fill_size_x) >= vid_conwidth)
1870 Sbar_DrawAccuracyStats_Description_Splash('1 0 0' * col_margin + '0 1 0' * (top_border + row * (fill_size_y + row_margin)));
1873 pos_x = left_border + count_splash * (fill_size_x + col_margin);
1874 pos_y = top_border + row * (fill_size_y + row_margin);
1877 drawpic(pos, "gfx/hud/sb_accuracy", fill_size , fill_colour, sbar_alpha_bg, DRAWFLAG_NORMAL);
1878 drawline(border_thickness, pos, pos + '1 0 0' * fill_size_x, '0 0 0', sbar_alpha_bg, DRAWFLAG_NORMAL);
1879 drawline(border_thickness, pos, pos + '0 1 0' * fill_size_y, '0 0 0', sbar_alpha_bg, DRAWFLAG_NORMAL);
1880 drawline(border_thickness, pos + '1 0 0' * fill_size_x, pos + '1 0 0' * fill_size_x + '0 1 0' * fill_size_y, '0 0 0', sbar_alpha_bg, DRAWFLAG_NORMAL);
1881 drawline(border_thickness, pos + '0 1 0' * fill_size_y, pos + '0 1 0' * fill_size_y + '1 0 0' * fill_size_x, '0 0 0', sbar_alpha_bg, DRAWFLAG_NORMAL);
1884 drawpic(pos, strcat("gfx/hud/inv_weapon", ftos(i-1)), '1 0.5 0' * fill_size_x , '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
1886 // the amount of shots fired or max damage
1887 drawstringright(pos + '4.5 0 0' * sbar_fontsize_x + '0 3 0' * sbar_fontsize_y, ftos(weapon_damage), sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
1889 // the amount of hits or actual damage
1890 drawstringright(pos + '4.5 0 0' * sbar_fontsize_x + '0 5 0' * sbar_fontsize_y, ftos(weapon_hit), sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
1893 drawstringright(pos + '4.5 0 0' * sbar_fontsize_x + '0 7 0' * sbar_fontsize_y, strcat(ftos(weapon_stats),"%"), sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
1895 // the amount of shots missed or damage wasted
1896 drawstringright(pos + '4.5 0 0' * sbar_fontsize_x + '0 9 0' * sbar_fontsize_y, ftos(weapon_damage - weapon_hit), sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
1900 else if ((self.weapon_type == WEP_TYPE_HITSCAN) && (weapon_damage))
1903 weapon_stats = rint(100 * weapon_hit / weapon_damage);
1905 fill_colour_x = 1 - 0.015 * weapon_stats;
1906 fill_colour_y = 1 - 0.015 * (100 - weapon_stats);
1908 // how the background colour is calculated
1909 // % red green red_2 green_2
1910 // 0 1 0 1 - % * 0.015 1 - (100 - %) * 0.015
1911 // 10 0.85 0 1 - % * 0.015 1 - (100 - %) * 0.015
1912 // 20 0.70 0 1 - % * 0.015 1 - (100 - %) * 0.015
1913 // 30 0.55 0 1 - % * 0.015 1 - (100 - %) * 0.015
1914 // 40 0.40 0.10 1 - % * 0.015 1 - (100 - %) * 0.015
1915 // 50 0.25 0.25 1 - % * 0.015 1 - (100 - %) * 0.015
1916 // 60 0.10 0.40 1 - % * 0.015 1 - (100 - %) * 0.015
1917 // 70 0 0.55 1 - % * 0.015 1 - (100 - %) * 0.015
1918 // 80 0 0.70 1 - % * 0.015 1 - (100 - %) * 0.015
1919 // 90 0 0.85 1 - % * 0.015 1 - (100 - %) * 0.015
1920 // 100 0 1 1 - % * 0.015 1 - (100 - %) * 0.015
1922 if ((left_border + count_hitscan * (fill_size_x + col_margin) + fill_size_x + cvar("stats_right_margin")) >= vid_conwidth)
1926 Sbar_DrawAccuracyStats_Description_Hitscan('1 0 0' * col_margin + '0 1 0' * (top_border + row * (fill_size_y + row_margin)));
1929 pos_x = left_border + count_hitscan * (fill_size_x + col_margin);
1930 pos_y = top_border + row * (fill_size_y + row_margin);
1933 drawpic(pos, "gfx/hud/sb_accuracy", fill_size , fill_colour, sbar_alpha_bg, DRAWFLAG_NORMAL);
1934 drawline(border_thickness, pos, pos + '1 0 0' * fill_size_x, '0 0 0', sbar_alpha_bg, DRAWFLAG_NORMAL);
1935 drawline(border_thickness, pos, pos + '0 1 0' * fill_size_y, '0 0 0', sbar_alpha_bg, DRAWFLAG_NORMAL);
1936 drawline(border_thickness, pos + '1 0 0' * fill_size_x, pos + '1 0 0' * fill_size_x + '0 1 0' * fill_size_y, '0 0 0', sbar_alpha_bg, DRAWFLAG_NORMAL);
1937 drawline(border_thickness, pos + '0 1 0' * fill_size_y, pos + '0 1 0' * fill_size_y + '1 0 0' * fill_size_x, '0 0 0', sbar_alpha_bg, DRAWFLAG_NORMAL);
1940 drawpic(pos, strcat("gfx/hud/inv_weapon", ftos(i-1)), '1 0.5 0' * fill_size_x , '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
1942 // the amount of shots fired or max damage
1943 drawstringright(pos + '4.5 0 0' * sbar_fontsize_x + '0 3 0' * sbar_fontsize_y, ftos(weapon_damage), sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
1945 // the amount of hits or actual damage
1946 drawstringright(pos + '4.5 0 0' * sbar_fontsize_x + '0 5 0' * sbar_fontsize_y, ftos(weapon_hit), sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
1949 drawstringright(pos + '4.5 0 0' * sbar_fontsize_x + '0 7 0' * sbar_fontsize_y, strcat(ftos(weapon_stats),"%"), sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
1951 // the amount of shots missed or damage wasted
1952 drawstringright(pos + '4.5 0 0' * sbar_fontsize_x + '0 9 0' * sbar_fontsize_y, ftos(weapon_damage - weapon_hit), sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
1959 void Sbar_DrawAccuracyStats_Description_Hitscan(vector position)
1961 drawfont = sbar_font;
1963 drawstring(position + '0 3 0' * sbar_fontsize_y, "Shots fired:", sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
1964 drawstring(position + '0 5 0' * sbar_fontsize_y, "Shots hit:", sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
1965 drawstring(position + '0 7 0' * sbar_fontsize_y, "Accuracy:", sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
1966 drawstring(position + '0 9 0' * sbar_fontsize_y, "Shots missed:", sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
1969 void Sbar_DrawAccuracyStats_Description_Splash(vector position)
1972 drawfont = sbar_font;
1973 drawstring(position + '0 3 0' * sbar_fontsize_y, "Maximum damage:", sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
1974 drawstring(position + '0 5 0' * sbar_fontsize_y, "Actual damage:", sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
1975 drawstring(position + '0 7 0' * sbar_fontsize_y, "Accuracy:", sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
1976 drawstring(position + '0 9 0' * sbar_fontsize_y, "Damage wasted:", sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
1979 void drawstringright(vector position, string text, vector scale, vector rgb, float alpha, float flag)
1981 position_x -= 2 / 3 * strlen(text) * scale_x;
1982 drawstring(position, text, scale, rgb, alpha, flag);
1985 void drawstringcenter(vector position, string text, vector scale, vector rgb, float alpha, float flag)
1987 position_x = 0.5 * (vid_conwidth - 0.6025 * strlen(text) * scale_x);
1988 drawstring(position, text, scale, rgb, alpha, flag);
1991 float GetAmmoStat(float i)
1995 case 0: return STAT_SHELLS;
1996 case 1: return STAT_NAILS;
1997 case 2: return STAT_ROCKETS;
1998 case 3: return STAT_CELLS;
1999 case 4: return STAT_FUEL;
2004 float GetAmmoItemCode(float i)
2008 case 0: return IT_SHELLS;
2009 case 1: return IT_NAILS;
2010 case 2: return IT_ROCKETS;
2011 case 3: return IT_CELLS;
2012 case 4: return IT_FUEL;
2017 string GetAmmoPicture(float i)
2021 case 0: return "gfx/hud/sb_shells";
2022 case 1: return "gfx/hud/sb_bullets";
2023 case 2: return "gfx/hud/sb_rocket";
2024 case 3: return "gfx/hud/sb_cells";
2025 case 4: return "gfx/hud/sb_fuel";
2030 void Sbar_Draw (void)
2032 // vectors for top right, bottom right, bottom and bottom left corners
2039 topright_x = vid_conwidth;
2043 bottom_x = vid_conwidth/2;
2044 bottom_y = vid_conheight;
2047 bottomright_x = vid_conwidth;
2048 bottomright_y = vid_conheight;
2052 bottomleft_y = vid_conheight;
2055 sbar_alpha_bg = cvar("sbar_alpha_bg");
2060 float stat_items, stat_weapons;
2062 weapon_stats = getstati(STAT_DAMAGE_HITS);
2063 weapon_number = weapon_stats & 63;
2064 weapon_hits[weapon_number] = rint(weapon_stats / 64);
2066 weapon_stats = getstati(STAT_DAMAGE_FIRED);
2067 weapon_number = weapon_stats & 63;
2068 weapon_fired[weapon_number] = rint(weapon_stats / 64);
2070 vector o; o = '1 0 0' * vid_conwidth;
2071 o_y = 28; // move spectator text slightly down to prevent overlapping the timer
2075 sbar_fontsize = Sbar_GetFontsize("sbar_fontsize");
2077 if(spectatee_status && !intermission)
2079 if(spectatee_status == -1)
2082 s = strcat("^1Spectating ^7", GetPlayerName(spectatee_status - 1));
2083 o = Sbar_DrawNoteLine(o, s);
2085 if(spectatee_status == -1)
2086 s = strcat("^1Press ^3", getcommandkey("primary fire", "+attack"), "^1 to spectate");
2088 s = strcat("^1Press ^3", getcommandkey("primary fire", "+attack"), "^1 for another player");
2089 o = Sbar_DrawNoteLine(o, s);
2091 if(spectatee_status == -1)
2092 s = strcat("^1Use ^3", getcommandkey("next weapon", "weapnext"), "^1 or ^3", getcommandkey("previous weapon", "weapprev"), "^1 to change the speed");
2094 s = strcat("^1Press ^3", getcommandkey("secondary fire", "+attack2"), "^1 to observe");
2095 o = Sbar_DrawNoteLine(o, s);
2097 s = strcat("^1Press ^3", getcommandkey("server info", "+show_info"), "^1 for gamemode info");
2098 o = Sbar_DrawNoteLine(o, s);
2100 if(gametype == GAME_ARENA)
2101 s = "^1Wait for your turn to join";
2102 else if(gametype == GAME_LMS)
2105 sk = playerslots[player_localentnum - 1];
2106 if(sk.(scores[ps_primary]) >= 666)
2107 s = "^1Match has already begun";
2108 else if(sk.(scores[ps_primary]) > 0)
2109 s = "^1You have no more lives left";
2111 s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
2114 s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
2115 o = Sbar_DrawNoteLine(o, s);
2117 //show restart countdown:
2118 if (time < getstatf(STAT_GAMESTARTTIME)) {
2120 //we need to ceil, otherwise the countdown would be off by .5 when using round()
2121 countdown = ceil(getstatf(STAT_GAMESTARTTIME) - time);
2122 s = strcat("^1Game starts in ^3", ftos(countdown), "^1 seconds");
2123 o = Sbar_DrawNoteLine(o, s);
2126 if(warmup_stage && !intermission)
2128 s = "^2Currently in ^1warmup^2 stage!";
2129 o = Sbar_DrawNoteLine(o, s);
2132 // move more important stuff more to the middle so its more visible
2133 o_y = vid_conheight * 0.66;
2136 if(mod(time, 1) >= 0.5)
2141 if(ready_waiting && !intermission)
2143 if(ready_waiting_for_me)
2146 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " to end warmup");
2148 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " once you are ready");
2153 s = strcat("^2Waiting for others to ready up to end warmup...");
2155 s = strcat("^2Waiting for others to ready up...");
2157 o = Sbar_DrawNoteLine(o, s);
2159 else if(warmup_stage && !intermission)
2161 s = strcat("^2Press ^3", getcommandkey("ready", "ready"), "^2 to end warmup");
2162 o = Sbar_DrawNoteLine(o, s);
2166 s = strcat("^2A vote has been called for ^1", vote_called_vote);
2167 o = Sbar_DrawNoteLine(o, s);
2169 if(vote_waiting_for_me)
2171 s = strcat(blinkcolor, "Press ^3", getcommandkey("vote yes", "vyes"), blinkcolor, " to accept");
2172 o = Sbar_DrawNoteLine(o, s);
2174 s = strcat(blinkcolor, "Press ^3", getcommandkey("vote no", "vno"), blinkcolor, " to reject");
2175 o = Sbar_DrawNoteLine(o, s);
2177 s = strcat(blinkcolor, "Press ^3", getcommandkey("vote abstain", "vabstain"), blinkcolor, " to abstain");
2178 o = Sbar_DrawNoteLine(o, s);
2182 s = strcat("^2Waiting for others to vote...");
2183 o = Sbar_DrawNoteLine(o, s);
2186 if(teamplay && !intermission)
2189 float ts_min, ts_max;
2190 tm = teams.sort_next;
2193 for(; tm.sort_next; tm = tm.sort_next)
2195 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
2197 if(!ts_min) ts_min = tm.team_size;
2198 else ts_min = min(ts_min, tm.team_size);
2199 if(!ts_max) ts_max = tm.team_size;
2200 else ts_max = max(ts_max, tm.team_size);
2202 if ((ts_max - ts_min) > 1)
2204 s = strcat(blinkcolor, "Teamnumbers are unbalanced!");
2205 tm = GetTeam(myteam, false);
2207 if (tm.team != COLOR_SPECTATOR)
2208 if (tm.team_size == ts_max)
2209 s = strcat(s, " Press ^3", getcommandkey("team menu", "menu_showteamselect"), blinkcolor, " to adjust");
2211 o = Sbar_DrawNoteLine(o, s);
2216 Sbar_UpdatePlayerTeams();
2218 if (intermission == 2) // map voting screen
2221 Sbar_DrawScoreboard();
2224 else if(sb_showaccuracy) {
2225 Sbar_DrawAccuracyStats();
2229 Sbar_FinaleOverlay();
2231 else if (sb_showscores_force || getstati(STAT_HEALTH) <= 0 || intermission == 1)
2234 Sbar_DrawAccuracyStats();
2236 Sbar_DrawScoreboard();
2242 Sbar_DrawScoreboard();
2243 else if(sb_showaccuracy)
2244 Sbar_DrawAccuracyStats();
2246 float armor, health;
2247 armor = getstati(STAT_ARMOR);
2248 health = getstati(STAT_HEALTH);
2250 stat_items = getstati(STAT_ITEMS);
2251 stat_weapons = getstati(STAT_WEAPONS);
2253 fade = 3.2 - 2 * (time - weapontime);
2254 fade = bound(0.7, fade, 1);
2256 vector bg_size; // hud background size
2258 if (vid_conwidth > 800) // if conwidth > 800, resize the background image
2259 bg_size_x = vid_conwidth;
2263 vector bgoffset; // hud background offset
2267 if (vid_conwidth < 800) // if conwidth < 800 we need to offset the background image to keep it centered, as it will be scaled up
2268 bgoffset_x = (vid_conwidth - 800) / 2;
2270 if (cvar("viewsize") <= 100) {
2272 drawpic(bottomleft - '0 58 0' + bgoffset, "gfx/hud/sbar", bg_size, GetTeamRGB(myteam) * cvar("sbar_color_bg_team"), sbar_alpha_bg, DRAWFLAG_NORMAL); // hud color = myteam color
2274 // allow for custom HUD colors in non-teamgames
2275 color_x = cvar("sbar_color_bg_r");
2276 color_y = cvar("sbar_color_bg_g");
2277 color_z = cvar("sbar_color_bg_b");
2279 drawpic(bottomleft - '0 58 0' + bgoffset, "gfx/hud/sbar", bg_size, color, sbar_alpha_bg, DRAWFLAG_NORMAL);
2283 if(sbar_hudselector == 2) // combined health and armor display
2286 v = healtharmor_maxdamage(health, armor, armorblockpercent);
2289 num_pos = bottom - element_offset - '0 22 0' + '-96 0 0';
2293 if(v_z) // fully armored
2295 // here, armorideal > armor
2296 drawpic(num_pos + '78 -4.5 0', "gfx/hud/sb_health", '32 32 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
2297 drawpic(num_pos + '108 -4.5 0', "gfx/hud/sb_armor", '20 20 0', '1 1 1', sbar_alpha_fg * armor / v_y, DRAWFLAG_NORMAL);
2301 drawpic(num_pos + '108 -4.5 0', "gfx/hud/sb_health", '20 20 0', '1 1 1', sbar_alpha_fg * v_y / armor, DRAWFLAG_NORMAL);
2302 drawpic(num_pos + '78 -4.5 0', "gfx/hud/sb_armor", '32 32 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
2304 Sbar_DrawXNum_Colored(num_pos, x, 24, sbar_alpha_fg); // draw the combined health and armor
2309 vector health_pos, armor_pos;
2311 if (sbar_hudselector == 0) { // old style layout with armor left of health
2312 health_pos = bottom - element_offset - '0 22 0' + '14 0 0';
2313 armor_pos = bottom - element_offset - '0 22 0' + '-96 0 0';
2317 health_pos = bottom - element_offset - '0 22 0' + '-96 0 0';
2318 armor_pos = bottom - element_offset - '0 22 0' + '14 0 0';
2325 drawpic(armor_pos + '78 -4.5 0', "gfx/hud/sb_armor", '32 32 0', '1 1 1', (x+10)/55 * sbar_alpha_fg, DRAWFLAG_NORMAL);
2327 Sbar_DrawXNum_Colored(armor_pos, x, 24, sbar_alpha_fg);
2329 Sbar_DrawXNum_Colored(armor_pos, x, 24, (x+10)/55 * sbar_alpha_fg);
2334 drawpic(health_pos + '78 -4.5 0', "gfx/hud/sb_health", '32 32 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
2335 Sbar_DrawXNum_Colored(health_pos, x, 24, sbar_alpha_fg);
2340 Sbar_DrawWeapon_Clear();
2341 for(i = 1; i <= 24; ++i)
2343 if(weaponimpulse[i-1] >= 0)
2344 if(stat_weapons & x)
2346 Sbar_DrawWeapon(i-1, fade, (i == activeweapon), i);
2352 float a; // i will be the ammo type (already declared), a will contain how much ammo there is of type i
2356 for (i = 0; i < 4; ++i) {
2357 a = getstati(GetAmmoStat(i)); // how much ammo do we have of type i?
2359 if(sbar_currentammo)
2362 if (stat_items & GetAmmoItemCode(i))
2364 if(cvar("vid_conwidth") >= 800) {
2369 pos_x = vid_conwidth - 110;
2373 drawpic(bottomleft + pos + '0 1.5 0', "gfx/hud/sb_ammobg", '107 29 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
2374 drawpic(bottomleft + pos + '76 3 0', GetAmmoPicture(i), '24 24 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
2376 Sbar_DrawXNum(bottomleft + pos + '5 5 0', a, 3, 24, '0.7 0 0', 0, 0, sbar_alpha_fg, DRAWFLAG_NORMAL);
2378 Sbar_DrawXNum(bottomleft + pos + '5 5 0', a, 3, 24, '1 1 1', 0, 0, sbar_alpha_fg, DRAWFLAG_NORMAL);
2385 if (cvar("vid_conwidth") >= 800)
2387 case 0: pos_x = 114; pos_y = -48; break; // shells
2388 case 1: pos_x = 114; pos_y = -26; break; // bullets
2389 case 2: pos_x = 200; pos_y = -48; break; // rockets
2390 case 3: pos_x = 200; pos_y = -26; break; // cells
2392 else // if vid_conwidth is lower than 800, ammo will overlap with weapon icons and health so we'll move it to the right
2394 case 0: pos_x = vid_conwidth - 158; pos_y = -150; break; // shells
2395 case 1: pos_x = vid_conwidth - 158; pos_y = -128; break; // bullets
2396 case 2: pos_x = vid_conwidth - 84; pos_y = -150; break; // rockets
2397 case 3: pos_x = vid_conwidth - 84; pos_y = -128; break; // cells
2400 if (stat_items & GetAmmoItemCode(i))
2401 drawpic(bottomleft + pos + '0 1.5 0', "gfx/hud/sb_ammobg", '80 22 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
2402 drawpic(bottomleft + pos + '56 3 0', GetAmmoPicture(i), '18 18 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
2404 if(stat_items & GetAmmoItemCode(i))
2405 Sbar_DrawXNum(bottomleft + pos + '6 4.5 0', a, 3, 16, '0.7 0 0', 0, 0, sbar_alpha_fg, DRAWFLAG_NORMAL);
2407 Sbar_DrawXNum(bottomleft + pos + '6 4.5 0', a, 3, 16, '0.7 0 0', 0, 0, sbar_alpha_fg * 0.7, DRAWFLAG_NORMAL);
2409 if(stat_items & GetAmmoItemCode(i))
2410 Sbar_DrawXNum(bottomleft + pos + '6 4.5 0', a, 3, 16, '1 1 1', 0, 0, sbar_alpha_fg, DRAWFLAG_NORMAL);
2412 Sbar_DrawXNum(bottomleft + pos + '6 4.5 0', a, 3, 16, '0.7 0.7 0.7', 0, 0, sbar_alpha_fg * 0.7, DRAWFLAG_NORMAL);
2419 a = getstati(GetAmmoStat(4)); // how much fuel do we have?
2421 if (a > 0) { // if we have fuel, draw the amount
2422 float invincibility_time, dt;
2423 invincibility_time = getstatf(STAT_INVINCIBLE_FINISHED);
2424 dt = invincibility_time - time;
2425 if (dt > 0) { // if the invincibility timer is active, draw fuel ammo elsewhere
2426 pos_x = bottom_x + 140;
2427 pos_y = bottom_y - 72;
2429 else { // if the invincibility timer is inactive, draw the fuel ammo there (it's rare to have invincibility + fuel anyway)
2430 pos_x = bottom_x + 140;
2431 pos_y = bottom_y - 22;
2433 drawpic(pos - '0 2 0' + '52 0 0', GetAmmoPicture(4), '20 20 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
2435 Sbar_DrawXNum(pos, a, 3, 16, '1 1 1', 0, 0, 1, DRAWFLAG_NORMAL);
2437 Sbar_DrawXNum(pos, a, 3, 16, '0.7 0 0', 0, 0, 1, DRAWFLAG_NORMAL);
2440 // draw scores and timer
2443 //show strength/invincibility ICON and timer:
2444 CSQC_Strength_Timer();
2446 if(gametype == GAME_KEYHUNT)
2449 } else if(gametype == GAME_CTF)
2452 } else if(gametype == GAME_NEXBALL)
2460 void CSQC_ctf_hud(void)
2462 vector bottomleft, redflag_pos, blueflag_pos;
2464 bottomleft_y = vid_conheight;
2467 float redflag, blueflag;
2470 stat_items = getstati(STAT_ITEMS);
2471 redflag = (stat_items/IT_RED_FLAG_TAKEN) & 3;
2472 blueflag = (stat_items/IT_BLUE_FLAG_TAKEN) & 3;
2474 if (myteam == COLOR_TEAM1) { // always draw own flag on left
2475 redflag_pos = bottomleft - element_offset - '-4 36 0';
2476 blueflag_pos = bottomleft - element_offset - '-68 36 0';
2480 blueflag_pos = bottomleft - element_offset - '-4 36 0';
2481 redflag_pos = bottomleft - element_offset - '-68 36 0';
2486 case 1: drawpic(redflag_pos, "gfx/hud/sb_flag_red_taken", '48 48 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); break;
2487 case 2: drawpic(redflag_pos, "gfx/hud/sb_flag_red_lost", '48 48 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); break;
2488 case 3: drawpic(redflag_pos, "gfx/hud/sb_flag_red_carrying", '48 48 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); break;
2490 if(stat_items & IT_CTF_SHIELDED)
2491 if(myteam == COLOR_TEAM2)
2492 drawpic(redflag_pos, "gfx/hud/sb_flag_red_shielded", '48 48 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); break;
2497 case 1: drawpic(blueflag_pos, "gfx/hud/sb_flag_blue_taken", '48 48 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); break;
2498 case 2: drawpic(blueflag_pos, "gfx/hud/sb_flag_blue_lost", '48 48 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); break;
2499 case 3: drawpic(blueflag_pos, "gfx/hud/sb_flag_blue_carrying", '48 48 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); break;
2501 if(stat_items & IT_CTF_SHIELDED)
2502 if(myteam == COLOR_TEAM1)
2503 drawpic(blueflag_pos, "gfx/hud/sb_flag_blue_shielded", '48 48 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); break;
2508 void CSQC_kh_hud(void)
2510 float kh_keys, kh_keys_status, kh_teams_set;
2511 vector red_pos, blue_pos, yellow_pos, pink_pos, kh_size;
2515 bottomleft_y = vid_conheight;
2519 red_pos_y = vid_conheight - 35 - 6;
2522 blue_pos_x = 6 + (24 * 1);
2523 blue_pos_y = vid_conheight - 35 - 6;
2526 yellow_pos_x = 6 + (24 * 2);
2527 yellow_pos_y = vid_conheight - 35 - 6;
2530 pink_pos_x = 6 + (24 * 3);
2531 pink_pos_y = vid_conheight - 35 - 6;
2534 kh_keys = getstati(STAT_KH_KEYS);
2535 kh_keys_status = kh_keys / 256;
2536 kh_teams_set = cvar("_teams_available"); // set in keyhunt.qc
2538 kh_size = '22 35 0';
2540 if (kh_keys_status & 1) // red
2541 drawpic (red_pos, "gfx/hud/sb_kh_red", kh_size, '1 1 1', 0.3, DRAWFLAG_NORMAL); // show 30% alpha key
2543 drawpic (red_pos, "gfx/hud/sb_kh_red", kh_size, '1 1 1', 1.0, DRAWFLAG_NORMAL); // show solid key 100% alpha
2545 if (kh_keys_status & 2) // blue
2546 drawpic (blue_pos, "gfx/hud/sb_kh_blue", kh_size, '1 1 1', 0.3, DRAWFLAG_NORMAL);
2548 drawpic (blue_pos, "gfx/hud/sb_kh_blue", kh_size, '1 1 1', 1.0, DRAWFLAG_NORMAL);
2550 if (kh_teams_set & 4) // yellow
2552 if (kh_keys_status & 4)
2553 drawpic (yellow_pos, "gfx/hud/sb_kh_yellow", kh_size, '1 1 1', 0.3, DRAWFLAG_NORMAL);
2555 drawpic (yellow_pos, "gfx/hud/sb_kh_yellow", kh_size, '1 1 1', 1.0, DRAWFLAG_NORMAL);
2558 if (kh_teams_set & 8) // pink
2560 if (kh_keys_status & 8)
2561 drawpic (pink_pos, "gfx/hud/sb_kh_pink", kh_size, '1 1 1', 0.3, DRAWFLAG_NORMAL);
2563 drawpic (pink_pos, "gfx/hud/sb_kh_pink", kh_size, '1 1 1', 1.0, DRAWFLAG_NORMAL);
2568 #define NBPB_SIZE '96 38 0'
2569 #define NBPB_BT 2 //thickness
2570 #define NBPB_BRGB '1 1 1'
2571 #define NBPB_BALPH 1 //alpha
2572 #define NBPB_BFLAG DRAWFLAG_NORMAL
2573 #define NBPB_IALPH 0.4
2574 #define NBPB_IFLAG DRAWFLAG_NORMAL
2575 #define NBPB_IRGB '0.7 0.1 0'
2577 void CSQC_nb_hud(void)
2579 float stat_items, nb_pb_starttime, dt, p;
2582 stat_items = getstati(STAT_ITEMS);
2583 nb_pb_starttime = getstatf(STAT_NB_METERSTART);
2586 pos_y = vid_conheight - 42;
2589 //Manage the progress bar if any
2590 if (nb_pb_starttime > 0)
2593 dt = mod(time - nb_pb_starttime, nb_pb_period);
2594 // one period of positive triangle
2595 p = 2 * dt / nb_pb_period;
2601 drawfill(pos, p * s_x * '1 0 0' + s_y * '0 1 0', NBPB_IRGB, NBPB_IALPH, NBPB_IFLAG);
2605 drawline(NBPB_BT, pos , pos + '1 0 0' * s_x, NBPB_BRGB, NBPB_BALPH, NBPB_BFLAG);
2606 drawline(NBPB_BT, pos , pos + '0 1 0' * s_y, NBPB_BRGB, NBPB_BALPH, NBPB_BFLAG);
2607 drawline(NBPB_BT, pos + s, pos + '1 0 0' * s_x, NBPB_BRGB, NBPB_BALPH, NBPB_BFLAG);
2608 drawline(NBPB_BT, pos + s, pos + '0 1 0' * s_y, NBPB_BRGB, NBPB_BALPH, NBPB_BFLAG);
2611 pos_x += 12; //horizontal margin to the picture
2612 pos_y += 2; //vertical margin to the picture
2614 if (stat_items & IT_KEY1)
2615 drawpic(pos, "gfx/hud/sb_nexball_carrying", '80 34 0', '1 1 1', 1, DRAWFLAG_NORMAL);