1 void drawstringright(vector, string, vector, vector, float, float);
2 void drawstringcenter(vector, string, vector, vector, float, float);
4 void Sbar_DrawStats_Description_Splash(vector);
5 void Sbar_DrawStats_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, 0);
90 drawpic(pos, strcat("gfx/hud/inv_weapon", ftos(nr)), vsize, color, value * fade * sbar_alpha_fg, 0);
96 drawstring(pos, ftos(imp), vsize, '1 1 1', sbar_alpha_fg, 0);
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 a, float dflags)
111 string str, tmp, l_length;
115 vsize_x = vsize_y = lettersize;
130 str = strcat(substring("0000000000", 0, digits - strlen(tmp)), tmp);
139 str = substring(str, l-digits, 999);
141 } else if(l < digits)
142 pos_x += (digits-l) * lettersize;
144 if (highlighted == 1) {
146 hl_size_x = vsize_x * l + vsize_x * 0.2;
147 hl_size_y = vsize_y * 1.1;
150 hl_size_x = hl_size_x + vsize_x;
153 hl_pos_x = pos_x - lettersize/10;
154 hl_pos_y = pos_y - lettersize/30;
157 drawpic(hl_pos, strcat("gfx/hud/sb_highlight_", l_length), hl_size, '1 1 1', sbar_alpha_fg, dflags);
162 drawpic(pos, "gfx/hud/num_minus", vsize, rgb, a * sbar_alpha_fg, dflags);
166 for(i = 0; i < l; ++i)
168 drawpic(pos, strcat("gfx/hud/num_", substring(str, i, 1)), vsize, rgb, a * sbar_alpha_fg, dflags);
173 void Sbar_DrawXNum_Colored (vector pos, float x, float lettersize)
179 Sbar_DrawXNum(pos, x, 3, lettersize, color, 0, 1, 0);
182 color_x = 0.4 - ((x-150)*0.02 * 0.4); //red value between 0.4 -> 0
183 color_y = 0.9 + ((x-150)*0.02 * 0.1); // green value between 0.9 -> 1
185 Sbar_DrawXNum(pos, x, 3, lettersize, color, 0, 1, 0);
188 color_x = 0.6 - ((x-100)*0.02 * 0.2); //red value between 0.6 -> 0.4
189 color_y = 0.7 + ((x-100)*0.02 * 0.2); // green value between 0.7 -> 0.9
190 color_z = 0.8 - ((x-100)*0.02 * 0.8); // blue value between 0.8 -> 0
191 Sbar_DrawXNum(pos, x, 3, lettersize, color, 0, 1, 0);
194 color_x = 1 - ((x-50)*0.02 * 0.4); //red value between 1 -> 0.6
195 color_y = 1 - ((x-50)*0.02 * 0.3); // green value between 1 -> 0.7
196 color_z = 0.2 + ((x-50)*0.02 * 0.6); // blue value between 0.2 -> 0.8
197 Sbar_DrawXNum(pos, x, 3, lettersize, color, 0, 1, 0);
201 color_y = (x-20)*90/27/100; // green value between 0 -> 1
202 color_z = (x-20)*90/27/100 * 0.2; // blue value between 0 -> 0.2
203 Sbar_DrawXNum(pos, x, 3, lettersize, color, 0, 1, 0);
206 Sbar_DrawXNum(pos, x, 3, lettersize, '1 0 0', 0, 1, 0);
209 void Cmd_Sbar_SetFields(float argc);
210 void Sbar_InitScores()
214 ps_primary = ps_secondary = ts_primary = ts_secondary = -1;
215 for(i = 0; i < MAX_SCORE; ++i)
217 f = (scores_flags[i] & SFL_SORT_PRIO_MASK);
218 if(f == SFL_SORT_PRIO_PRIMARY)
220 if(f == SFL_SORT_PRIO_SECONDARY)
223 if(ps_secondary == -1)
224 ps_secondary = ps_primary;
226 for(i = 0; i < MAX_TEAMSCORE; ++i)
228 f = (teamscores_flags[i] & SFL_SORT_PRIO_MASK);
229 if(f == SFL_SORT_PRIO_PRIMARY)
231 if(f == SFL_SORT_PRIO_SECONDARY)
234 if(ts_secondary == -1)
235 ts_secondary = ts_primary;
237 Cmd_Sbar_SetFields(0);
240 void Sbar_UpdatePlayerPos(entity pl);
241 float SetTeam(entity pl, float Team);
243 void Sbar_UpdatePlayerTeams()
250 for(pl = players.sort_next; pl; pl = pl.sort_next)
253 Team = GetPlayerColor(pl.sv_entnum);
254 if(SetTeam(pl, Team))
257 Sbar_UpdatePlayerPos(pl);
261 pl = players.sort_next;
266 print(strcat("PNUM: ", ftos(num), "\n"));
271 float Sbar_ComparePlayerScores(entity left, entity right)
274 vl = GetPlayerColor(left.sv_entnum);
275 vr = GetPlayerColor(right.sv_entnum);
278 vl = COLOR_SPECTATOR;
280 vr = COLOR_SPECTATOR;
287 if(vl == COLOR_SPECTATOR)
289 // FIRST the one with scores (spectators), THEN the ones without (downloaders)
291 if(!left.gotscores && right.gotscores)
296 vl = left.scores[ps_primary];
297 vr = right.scores[ps_primary];
298 if(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)
300 if(vl == 0 && vr != 0)
302 if(vl != 0 && vr == 0)
306 return IS_INCREASING(scores_flags[ps_primary]);
308 return IS_DECREASING(scores_flags[ps_primary]);
310 vl = left.scores[ps_secondary];
311 vr = right.scores[ps_secondary];
312 if(scores_flags[ps_secondary] & SFL_ZERO_IS_WORST)
314 if(vl == 0 && vr != 0)
316 if(vl != 0 && vr == 0)
320 return IS_INCREASING(scores_flags[ps_secondary]);
322 return IS_DECREASING(scores_flags[ps_secondary]);
327 void Sbar_UpdatePlayerPos(entity player)
329 for(other = player.sort_next; other && Sbar_ComparePlayerScores(player, other); other = player.sort_next)
331 SORT_SWAP(player, other);
333 for(other = player.sort_prev; other != players && Sbar_ComparePlayerScores(other, player); other = player.sort_prev)
335 SORT_SWAP(other, player);
339 float Sbar_CompareTeamScores(entity left, entity right)
343 if(left.team == COLOR_SPECTATOR)
345 if(right.team == COLOR_SPECTATOR)
348 vl = left.teamscores[ts_primary];
349 vr = right.teamscores[ts_primary];
351 return IS_INCREASING(teamscores_flags[ts_primary]);
353 return IS_DECREASING(teamscores_flags[ts_primary]);
355 vl = left.teamscores[ts_secondary];
356 vr = right.teamscores[ts_secondary];
358 return IS_INCREASING(teamscores_flags[ts_secondary]);
360 return IS_DECREASING(teamscores_flags[ts_secondary]);
365 void Sbar_UpdateTeamPos(entity Team)
367 for(other = Team.sort_next; other && Sbar_CompareTeamScores(Team, other); other = Team.sort_next)
369 SORT_SWAP(Team, other);
371 for(other = Team.sort_prev; other != teams && Sbar_CompareTeamScores(other, Team); other = Team.sort_prev)
373 SORT_SWAP(other, Team);
377 void Cmd_Sbar_Help(float argc)
379 print("You can modify the scoreboard using the\n");
380 print("^3|---------------------------------------------------------------|\n");
381 print("^1 TO BE DONE\n");
383 print("^2sbar_columns_set default\n");
384 print("^2sbar_columns_set ^7filed1 field2 ...\n");
385 print("The following field names are recognized (case INsensitive):\n");
386 print("You can use a ^3|^7 to start the right-aligned fields.\n");
388 print("^3name^7 or ^3nick^7 Name of a player\n");
389 print("^3ping^7 Ping time\n\n");
390 print("^3kd^7 or ^3kdr^7 or ^3kdratio^7 or ^3k/d\n");
391 print(" The kill-death ratio\n");
393 print("Before a field you can put a + or - sign, then a comma separated list\n");
394 print("of game types, then a slash, to make the field show up only in these\n");
395 print("or in all but these game types.\n");
397 print("The special game type names 'teams' and 'noteams' can be used to\n");
398 print("include/exclude ALL teams/noteams game modes.\n");
401 print("Additional columns:\n");
402 for(i = 0; i < MAX_SCORE; ++i)
404 if(scores_label[i] != "")
405 print(strcat(scores_label[i], "\n"));
409 #define MIN_NAMELEN 24
410 #define MAX_NAMELEN 24
412 string Sbar_DefaultColumnLayout()
414 return strcat( // fteqcc sucks
416 "-teams,race,lms/kills -teams,lms/deaths -teams,lms,race/suicides -race,dm,tdm/frags ", // tdm already has this in "score"
417 "+ctf/caps +ctf/pickups +ctf/fckills +ctf/returns ",
418 "+lms/lives +lms/rank ",
419 "+/caps +kh/pushes +kh/destroyed ",
420 "?+race/laps ?+race/time ?+race/fastest ",
421 "+as/objectives +nexball/faults +nexball/goals ",
422 "-lms,race,nexball/score");
425 void Cmd_Sbar_SetFields(float argc)
430 float have_name, have_primary, have_secondary, have_separator;
433 // TODO: re enable with gametype dependant cvars?
434 if(argc < 2) // no arguments provided
435 argc = tokenizebyseparator(strcat("x ", cvar_string("sbar_columns")), " ");
438 argc = tokenizebyseparator(strcat("x ", Sbar_DefaultColumnLayout()), " ");
442 if(argv(1) == "default")
443 argc = tokenizebyseparator(strcat("x ", Sbar_DefaultColumnLayout()), " ");
444 else if(argv(1) == "all")
447 s = "ping pl color name |";
448 for(i = 0; i < MAX_SCORE; ++i)
451 if(i != ps_secondary)
452 if(scores_label[i] != "")
453 s = strcat(s, " ", scores_label[i]);
455 if(ps_secondary != ps_primary)
456 s = strcat(s, " ", scores_label[ps_secondary]);
457 s = strcat(s, " ", scores_label[ps_primary]);
458 argc = tokenizebyseparator(strcat("x ", s), " ");
465 drawfont = sbar_font;
466 digit = stringwidth("0123456789", FALSE) / 10;
468 for(i = 0; i < argc - 1; ++i)
474 if(substring(str, 0, 1) == "?")
477 str = substring(str, 1, strlen(str) - 1);
480 slash = strstrofs(str, "/", 0);
483 pattern = substring(str, 0, slash);
484 str = substring(str, slash + 1, strlen(str) - (slash + 1));
486 if not(isGametypeInFilter(gametype, teamplay, pattern))
490 strunzone(sbar_title[sbar_num_fields]);
491 sbar_title[sbar_num_fields] = strzone(str);
492 sbar_size[sbar_num_fields] = stringwidth(str, FALSE);
493 str = strtolower(str);
496 sbar_field[sbar_num_fields] = SP_PING;
497 } else if(str == "pl") {
498 sbar_field[sbar_num_fields] = SP_PL;
499 } else if(str == "kd" || str == "kdr" || str == "kdratio" || str == "k/d") {
500 sbar_field[sbar_num_fields] = SP_KDRATIO;
501 } else if(str == "name" || str == "nick") {
502 sbar_field[sbar_num_fields] = SP_NAME;
503 sbar_size[sbar_num_fields] = MIN_NAMELEN; // minimum size? any use?
505 } else if(str == "|") {
506 sbar_field[sbar_num_fields] = SP_SEPARATOR;
509 for(j = 0; j < MAX_SCORE; ++j)
510 if(str == strtolower(scores_label[j]))
511 goto found; // sorry, but otherwise fteqcc -O3 miscompiles this and warns about "unreachable code"
520 print(strcat("^1Error:^7 Unknown score field: '", str, "'\n"));
524 sbar_field[sbar_num_fields] = j;
527 if(j == ps_secondary)
531 if(sbar_num_fields >= MAX_SBAR_FIELDS)
535 if(scores_flags[ps_primary] & SFL_ALLOW_HIDE)
537 if(scores_flags[ps_secondary] & SFL_ALLOW_HIDE)
539 if(ps_primary == ps_secondary)
541 missing = !have_primary + !have_secondary + !have_separator + !have_name;
543 if(sbar_num_fields+missing < MAX_SBAR_FIELDS)
547 strunzone(sbar_title[sbar_num_fields]);
548 for(i = sbar_num_fields; i > 0; --i)
550 sbar_title[i] = sbar_title[i-1];
551 sbar_size[i] = sbar_size[i-1];
552 sbar_field[i] = sbar_field[i-1];
554 sbar_title[0] = strzone("name");
555 sbar_field[0] = SP_NAME;
556 sbar_size[0] = MIN_NAMELEN; // minimum size? any use?
558 print("fixed missing field 'name'\n");
562 strunzone(sbar_title[sbar_num_fields]);
563 for(i = sbar_num_fields; i > 1; --i)
565 sbar_title[i] = sbar_title[i-1];
566 sbar_size[i] = sbar_size[i-1];
567 sbar_field[i] = sbar_field[i-1];
569 sbar_title[1] = strzone("|");
570 sbar_field[1] = SP_SEPARATOR;
571 sbar_size[1] = stringwidth("|", FALSE);
573 print("fixed missing field '|'\n");
576 else if(!have_separator)
578 strunzone(sbar_title[sbar_num_fields]);
579 sbar_title[sbar_num_fields] = strzone("|");
580 sbar_size[sbar_num_fields] = stringwidth("|", FALSE);
581 sbar_field[sbar_num_fields] = SP_SEPARATOR;
583 print("fixed missing field '|'\n");
588 strunzone(sbar_title[sbar_num_fields]);
589 sbar_title[sbar_num_fields] = strzone(scores_label[ps_secondary]);
590 sbar_size[sbar_num_fields] = stringwidth(sbar_title[sbar_num_fields], FALSE);
591 sbar_field[sbar_num_fields] = ps_secondary;
593 print("fixed missing field '", scores_label[ps_secondary], "'\n");
598 strunzone(sbar_title[sbar_num_fields]);
599 sbar_title[sbar_num_fields] = strzone(scores_label[ps_primary]);
600 sbar_size[sbar_num_fields] = stringwidth(sbar_title[sbar_num_fields], FALSE);
601 sbar_field[sbar_num_fields] = ps_primary;
603 print("fixed missing field '", scores_label[ps_primary], "'\n");
607 sbar_field[sbar_num_fields] = SP_END;
611 vector sbar_field_rgb;
612 string sbar_field_icon0;
613 string sbar_field_icon1;
614 string sbar_field_icon2;
615 vector sbar_field_icon0_rgb;
616 vector sbar_field_icon1_rgb;
617 vector sbar_field_icon2_rgb;
618 float sbar_field_icon0_alpha;
619 float sbar_field_icon1_alpha;
620 float sbar_field_icon2_alpha;
621 string Sbar_GetField(entity pl, float field)
623 float tmp, num, denom, f;
625 sbar_field_rgb = '1 1 1';
626 sbar_field_icon0 = "";
627 sbar_field_icon1 = "";
628 sbar_field_icon2 = "";
629 sbar_field_icon0_rgb = '1 1 1';
630 sbar_field_icon1_rgb = '1 1 1';
631 sbar_field_icon2_rgb = '1 1 1';
632 sbar_field_icon0_alpha = 1;
633 sbar_field_icon1_alpha = 1;
634 sbar_field_icon2_alpha = 1;
639 return "\x8D\x8D\x8D"; // >>> sign
640 str = getplayerkey(pl.sv_entnum, "ping");
643 tmp = max(0, min(220, stof(str)-80)) / 220;
644 sbar_field_rgb = '1 1 1' - '0 1 1'*tmp;
650 str = getplayerkey(pl.sv_entnum, "pl");
653 tmp = bound(0, stof(str), 20) / 20; // 20% is REALLY BAD pl
654 sbar_field_rgb = '1 0.5 0.5' - '0 0.5 0.5'*tmp;
658 if(ready_waiting && pl.ready)
660 sbar_field_icon0 = "gfx/sb_player_ready";
664 f = stof(getplayerkey(pl.sv_entnum, "colors"));
666 sbar_field_icon0 = "gfx/sb_playercolor_base";
667 sbar_field_icon1 = "gfx/sb_playercolor_shirt";
668 sbar_field_icon1_rgb = colormapPaletteColor(floor(f / 16), 0);
669 sbar_field_icon2 = "gfx/sb_playercolor_pants";
670 sbar_field_icon2_rgb = colormapPaletteColor(mod(f, 16), 1);
673 return GetPlayerName(pl.sv_entnum);
676 f = pl.(scores[SP_KILLS]);
677 f -= pl.(scores[SP_SUICIDES]);
681 num = pl.(scores[SP_KILLS]);
682 denom = pl.(scores[SP_DEATHS]);
685 sbar_field_rgb = '0 1 0';
687 } else if(num <= 0) {
688 sbar_field_rgb = '1 0 0';
689 str = ftos(num/denom);
691 str = ftos(num/denom);
693 tmp = strstrofs(str, ".", 0);
695 str = substring(str, 0, tmp+2);
699 tmp = pl.(scores[field]);
700 f = scores_flags[field];
701 if(field == ps_primary)
702 sbar_field_rgb = '1 1 0';
703 else if(field == ps_secondary)
704 sbar_field_rgb = '0 1 1';
706 sbar_field_rgb = '1 1 1';
707 return ScoreString(f, tmp);
712 float xmin, xmax, ymin, ymax, sbwidth;
713 float sbar_fixscoreboardcolumnwidth_len;
714 float sbar_fixscoreboardcolumnwidth_iconlen;
715 float sbar_fixscoreboardcolumnwidth_marginlen;
717 float stringwidth_colors(string s)
719 return stringwidth(s, TRUE);
722 float stringwidth_nocolors(string s)
724 return stringwidth(s, FALSE);
727 string Sbar_FixScoreboardColumnWidth(float i, string str)
729 float field, maxsize, j, f;
731 field = sbar_field[i];
733 if(field == SP_NAME) // name gets all remaining space
735 maxsize = (xmax - xmin) / sbar_fontsize_x;
736 for(j = 0; j < sbar_num_fields; ++j) if(j != i) if(sbar_field[j] != SP_SEPARATOR)
737 maxsize -= sbar_size[j] + 1;
739 str = textShortenToWidth(str, maxsize, stringwidth_colors);
740 sbar_fixscoreboardcolumnwidth_len = stringwidth(str, TRUE);
743 sbar_fixscoreboardcolumnwidth_len = stringwidth(str, FALSE);
745 sbar_fixscoreboardcolumnwidth_iconlen = 0;
747 if(sbar_field_icon0 != "")
749 sz = drawgetimagesize(sbar_field_icon0);
751 if(sbar_fixscoreboardcolumnwidth_iconlen < f)
752 sbar_fixscoreboardcolumnwidth_iconlen = f;
755 if(sbar_field_icon1 != "")
757 sz = drawgetimagesize(sbar_field_icon1);
759 if(sbar_fixscoreboardcolumnwidth_iconlen < f)
760 sbar_fixscoreboardcolumnwidth_iconlen = f;
763 if(sbar_field_icon2 != "")
765 sz = drawgetimagesize(sbar_field_icon2);
767 if(sbar_fixscoreboardcolumnwidth_iconlen < f)
768 sbar_fixscoreboardcolumnwidth_iconlen = f;
771 sbar_fixscoreboardcolumnwidth_iconlen *= sbar_fontsize_y / sbar_fontsize_x; // fix icon aspect
773 if(sbar_fixscoreboardcolumnwidth_iconlen != 0 && sbar_fixscoreboardcolumnwidth_len != 0)
774 sbar_fixscoreboardcolumnwidth_marginlen = stringwidth(" ", FALSE);
776 sbar_fixscoreboardcolumnwidth_marginlen = 0;
778 f = sbar_fixscoreboardcolumnwidth_len + sbar_fixscoreboardcolumnwidth_marginlen + sbar_fixscoreboardcolumnwidth_iconlen;
785 void Sbar_PrintScoreboardItem(vector pos, entity pl, float is_self)
791 is_spec = (GetPlayerColor(pl.sv_entnum) == COLOR_SPECTATOR);
798 tmp_y = sbar_fontsize_y;
799 drawfill(pos - '1 1 0', tmp + '2 2 0', '1 1 1', 0.3, DRAWFLAG_NORMAL);
803 for(i = 0; i < sbar_num_fields; ++i)
805 field = sbar_field[i];
806 if(field == SP_SEPARATOR)
809 if(is_spec && field != SP_NAME && field != SP_PING) {
810 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
813 str = Sbar_GetField(pl, field);
814 str = Sbar_FixScoreboardColumnWidth(i, str);
816 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
818 if(field == SP_NAME) {
819 tmp_x = sbar_fontsize_x*(sbar_size[i] - sbar_fixscoreboardcolumnwidth_iconlen - sbar_fixscoreboardcolumnwidth_marginlen) + sbar_fontsize_x;
820 drawcolorcodedstring(pos - tmp, str, sbar_fontsize, 1, DRAWFLAG_NORMAL);
822 tmp_x = sbar_fixscoreboardcolumnwidth_len*sbar_fontsize_x + sbar_fontsize_x;
823 drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, 1, DRAWFLAG_NORMAL);
826 tmp_x = sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
827 if(sbar_field_icon0 != "")
828 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, 0);
829 if(sbar_field_icon1 != "")
830 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, 0);
831 if(sbar_field_icon2 != "")
832 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, 0);
835 if(sbar_field[i] == SP_SEPARATOR)
838 for(i = sbar_num_fields-1; i > 0; --i)
840 field = sbar_field[i];
841 if(field == SP_SEPARATOR)
844 if(is_spec && field != SP_NAME && field != SP_PING) {
845 pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
849 str = Sbar_GetField(pl, field);
850 str = Sbar_FixScoreboardColumnWidth(i, str);
852 if(field == SP_NAME) {
853 tmp_x = sbar_fontsize_x*sbar_fixscoreboardcolumnwidth_len; // left or right aligned? let's put it right...
854 drawcolorcodedstring(pos - tmp, str, sbar_fontsize, 1, DRAWFLAG_NORMAL);
856 tmp_x = sbar_fontsize_x*sbar_fixscoreboardcolumnwidth_len; //strlen(str);
857 drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, 1, DRAWFLAG_NORMAL);
860 tmp_x = sbar_fontsize_x*sbar_size[i];
861 if(sbar_field_icon0 != "")
862 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, 0);
863 if(sbar_field_icon1 != "")
864 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, 0);
865 if(sbar_field_icon2 != "")
866 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, 0);
868 pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
874 float scoreboard_bottom;
875 void Sbar_DrawScoreboard()
877 //float xmin, ymin, xmax, ymax;
878 vector rgb, pos, tmp, sbar_save;
883 if(time > lastpingstime + 10)
886 lastpingstime = time;
889 sbwidth = Sbar_GetWidth(6.5 * sbar_fontsize_y);
891 xmin = 0.5 * (vid_conwidth - sbwidth);
894 xmax = vid_conwidth - xmin;
895 ymax = vid_conheight - 0.2*vid_conheight;
897 center_x = xmin + 0.5*sbwidth;
899 //Sbar_UpdateFields();
901 // Initializes position
907 drawfont = sbar_bigfont;
908 pos_x = center_x - stringwidth("Scoreboard", TRUE)*0.5*24;
909 drawstring(pos, "Scoreboard", '24 24 0', '1 1 1', 1, DRAWFLAG_NORMAL);
913 // Titlebar background:
915 tmp_y = sbar_fontsize_y;
916 drawfill(pos - '1 1 0', tmp + '2 2 0', '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
918 drawfont = sbar_font;
920 for(i = 0; i < sbar_num_fields; ++i)
922 if(sbar_field[i] == SP_SEPARATOR)
924 drawstring(pos, sbar_title[i], sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
925 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
928 if(sbar_field[i] == SP_SEPARATOR)
930 pos_x = xmax + sbar_fontsize_x;
932 for(i = sbar_num_fields-1; i > 0; --i)
934 if(sbar_field[i] == SP_SEPARATOR)
937 pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
940 * Using the following line will mess it all up:
942 * tmp_x = sbar_size[i] - strlen(sbar_title[i])*8;
944 tmp_x = sbar_fontsize_x*sbar_size[i];
945 tmp_x -= stringwidth(sbar_title[i], FALSE)*sbar_fontsize_x;
946 drawstring(pos + tmp, sbar_title[i], sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
951 pos_y += 1.5 * sbar_fontsize_y;
958 //for(tm = sortedTeams.sort_next; tm; tm = tm.sort_next)
959 for(tm = teams.sort_next; tm; tm = tm.sort_next)
961 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
964 rgb = GetTeamRGB(tm.team);
968 Sbar_DrawXNum(sbar + pos - '6.5 0 0' * sbar_fontsize_y, tm.(teamscores[ts_primary]), 4, sbar_fontsize_y * 1.5, rgb, 0, 1, DRAWFLAG_NORMAL);
970 if(ts_primary != ts_secondary)
971 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, 1, DRAWFLAG_NORMAL);
973 specs = tm.team_size;
979 tmp_y = 1.25 * sbar_fontsize_y * specs;
980 drawfill(pos - '1 1 0', tmp + '2 0 0', rgb, 0.2, DRAWFLAG_NORMAL);
982 for(pl = players.sort_next; pl; pl = pl.sort_next)
984 if(pl.team != tm.team)
986 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
987 pos_y += 1.25 * sbar_fontsize_y;
988 tmp_y -= 1.25 * sbar_fontsize_y;
990 pos_y += tmp_y + 1.5 * sbar_fontsize_y;
992 // rgb := tempvector :)
993 rgb = pos + '0 1.5 0' * sbar_fontsize_y;
994 pos_y += 3 * sbar_fontsize_y;
996 for(pl = players.sort_next; pl; pl = pl.sort_next)
998 if(pl.team != COLOR_SPECTATOR)
1000 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
1001 pos += '0 1.25 0' * sbar_fontsize_y;
1006 drawstring(rgb, "Spectators", sbar_fontsize, '1 1 1', 1, 0);
1009 for(pl = players.sort_next; pl; pl = pl.sort_next)
1011 if(pl.team == COLOR_SPECTATOR)
1013 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
1014 pos_y += 1.25 * sbar_fontsize_y;
1015 tmp_y -= 1.25 * sbar_fontsize_y;
1018 // rgb := tempvector :)
1019 rgb = pos + '0 1.5 0' * sbar_fontsize_y;
1020 pos_y += 3 * sbar_fontsize_y;
1022 for(pl = players.sort_next; pl; pl = pl.sort_next)
1024 if(pl.team != COLOR_SPECTATOR)
1026 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
1027 pos += '0 1.25 0' * sbar_fontsize_y;
1032 drawstring(rgb, "Spectators", sbar_fontsize, '1 1 1', 1, 0);
1037 str = strcat("playing on ^2", shortmapname, "^7");
1038 tl = getstatf(STAT_TIMELIMIT);
1039 fl = getstatf(STAT_FRAGLIMIT);
1040 if(gametype == GAME_LMS)
1043 str = strcat(str, " for up to ^1", ftos(tl), " minutes^7");
1048 str = strcat(str, " for ^1", ftos(tl), " minutes^7");
1052 str = strcat(str, " or");
1055 str = strcat(str, " until ^3", ScoreString(teamscores_flags[ts_primary], fl));
1056 if(teamscores_label[ts_primary] == "score")
1057 str = strcat(str, " points^7");
1058 else if(teamscores_label[ts_primary] == "fastest")
1059 str = strcat(str, " is beaten^7");
1061 str = strcat(str, " ", teamscores_label[ts_primary]);
1065 str = strcat(str, " until ^3", ScoreString(scores_flags[ps_primary], fl));
1066 if(scores_label[ps_primary] == "score")
1067 str = strcat(str, " points^7");
1068 else if(scores_label[ps_primary] == "fastest")
1069 str = strcat(str, " is beaten^7");
1071 str = strcat(str, " ", scores_label[ps_primary]);
1077 pos_y += 1.2 * sbar_fontsize_y;
1078 drawcolorcodedstring(pos + '0.5 0 0' * (sbwidth - sbar_fontsize_x * stringwidth(str, TRUE)), str, sbar_fontsize, 0.8, 0);
1081 scoreboard_bottom = pos_y + 2 * sbar_fontsize_y;
1084 string MakeRaceString(float cp, float mytime, float histime, float lapdelta, string hisname)
1092 if(histime == 0) // goal hit
1096 timestr = strcat("+", ftos_decimals(+mytime, 1));
1099 else if(mytime == 0)
1106 timestr = strcat("-", ftos_decimals(-mytime, 1));
1112 lapstr = strcat(" (-", ftos(lapdelta), "L)");
1115 else if(lapdelta < 0)
1117 lapstr = strcat(" (+", ftos(-lapdelta), "L)");
1121 else if(histime > 0) // anticipation
1123 if(mytime >= histime)
1124 timestr = strcat("+", ftos_decimals(mytime - histime, 1));
1126 timestr = mmsss(histime * 10);
1133 cpname = strcat("Intermediate ", ftos(cp));
1135 cpname = "Finish line";
1138 return strcat(col, cpname);
1139 else if(hisname == "")
1140 return strcat(col, cpname, " (", timestr, ")");
1142 return strcat(col, cpname, " (", timestr, " ", strcat(hisname, col, lapstr), ")");
1145 void Sbar_Score(float margin)
1147 float timelimit, minutes, seconds, timeleft, minutesLeft, secondsLeft, distribution, myplace, score, desiredPlayerId;
1148 vector sbar_save, place, timer_color, offset;
1153 bottomright_x = vid_conwidth;
1154 bottomright_y = vid_conheight;
1158 topright_x = vid_conwidth;
1162 sbar_alpha_bg = cvar("sbar_alpha_bg");
\r
1163 //get the ID (could be "me", or the player I'm spectating)
\r
1164 desiredPlayerId = player_localentnum - 1;
\r
1165 if (spectatee_status) {
\r
1166 if (spectatee_status != -1) {
\r
1167 desiredPlayerId = spectatee_status - 1;
\r
1171 myteam = GetPlayerColor(desiredPlayerId);
1173 sbar_y = vid_conheight - (32+12);
1182 // team1 team3 team4
1185 //for(i = 0; i < 4; ++i)
1186 if (cvar("vid_conwidth") >= 800) {
1196 float max_fragcount;
1197 max_fragcount = -999;
1199 for(tm = teams.sort_next; tm; tm = tm.sort_next)
1201 if(tm.team == COLOR_SPECTATOR || !tm.team_size) // no players? don't display
1204 score = tm.(teamscores[ts_primary]);
1206 if (score > max_fragcount)
1207 max_fragcount = score;
1209 if(tm.team == myteam) {
1210 if (max_fragcount == score)
1211 Sbar_DrawXNum(bottomright - element_offset - place, score, 4, 34, GetTeamRGB(tm.team) * 0.8, 1, 1, DRAWFLAG_NORMAL);
1213 Sbar_DrawXNum(bottomright - element_offset - place, score, 4, 34, GetTeamRGB(tm.team) * 0.8, 0, 1, DRAWFLAG_NORMAL);
1217 if (max_fragcount == score)
1218 Sbar_DrawXNum(bottomright - element_offset - place + '132 -6 0' - offset, score, 4, 16, GetTeamRGB(tm.team) * 0.8, 1, 1, DRAWFLAG_NORMAL);
1220 Sbar_DrawXNum(bottomright - element_offset - place + '132 -6 0' - offset, score, 4, 16, GetTeamRGB(tm.team) * 0.8, 0, 1, DRAWFLAG_NORMAL);
1225 // me vector := [team/connected frags id]
1228 for(me = players.sort_next; me; me = me.sort_next)
1230 if(me.team != COLOR_SPECTATOR)
1232 if(me.sv_entnum == desiredPlayerId)
1236 pl = players.sort_next;
1241 distribution = me.(scores[ps_primary]);
1242 distribution -= pl.(scores[ps_primary]);
1246 if (cvar("vid_conwidth") >= 800) {
1251 else { // move the scores if vid_conwidth < 800
1255 score = me.(scores[ps_primary]);
1257 if(distribution >= 0)
1259 if (distribution != 0) {
1260 // draw a + sign in front of the score
1261 if (distribution < 10) { drawpic(bottomright - element_offset - place + '132 -5 0' + '32 0 0', "gfx/hud/num_plus", '16 16 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE); }
1262 else if (distribution < 100) { drawpic(bottomright - element_offset - place + '132 -5 0' + '16 0 0', "gfx/hud/num_plus", '16 16 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE); }
1263 else if (distribution < 1000) { drawpic(bottomright - element_offset - place + '132 -5 0', "gfx/hud/num_plus", '16 16 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE); }
1266 Sbar_DrawXNum(bottomright - element_offset - place + '132 -6 0', distribution, 4, 16, ' 1 1 1', 0, 1, DRAWFLAG_NORMAL);
1267 Sbar_DrawXNum(bottomright - element_offset - place, score, 4, 34, '1 1 1', 1, 1, DRAWFLAG_NORMAL);
1269 else if(distribution >= -5)
1271 Sbar_DrawXNum(bottomright - element_offset - place + '132 -6 0', distribution, 4, 16, ' 1 1 0', 0, 1, DRAWFLAG_NORMAL);
1272 Sbar_DrawXNum(bottomright - element_offset - place, score, 4, 34, '1 1 0', 0, 1, DRAWFLAG_NORMAL);
1275 Sbar_DrawXNum(bottomright - element_offset - place + '132 -6 0', distribution, 4, 16, ' 1 0 0', 0, 1, DRAWFLAG_NORMAL);
1276 Sbar_DrawXNum(bottomright - element_offset - place, score, 4, 34, '1 0 0', 0, 1, DRAWFLAG_NORMAL);
1280 //draw the remaining or elapsed time
1281 timelimit = getstatf(STAT_TIMELIMIT);
1286 timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
1287 timeleft = ceil(timeleft);
1288 minutesLeft = floor(timeleft / 60);
1289 secondsLeft = timeleft - minutesLeft*60;
1291 if(minutesLeft >= 5) {
1292 timer_color = '1 1 1'; //white
1293 } else if(minutesLeft >= 1) {
1294 timer_color = '1 1 0'; //yellow
1296 timer_color = '1 0 0'; //red
1300 timer_color = '1 1 1'; //don't use red or yellow for timer during warmup
1303 if (cvar("sbar_increment_maptime")) {
1304 if (time < getstatf(STAT_GAMESTARTTIME)) {
1305 //while restart is still active, show negative counter
1307 seconds = ceil(getstatf(STAT_GAMESTARTTIME) - time);
1310 elapsedTime = floor(time - getstatf(STAT_GAMESTARTTIME)); //127
1311 minutes = floor(elapsedTime / 60);
1312 seconds = elapsedTime - minutes*60;
1315 minutes = minutesLeft;
1316 seconds = secondsLeft;
1320 bgpos_x = topright_x - 36 - 7 - 12;
1321 else if (minutes < 10) // nudge the timer background left if more digits are drawn
1322 bgpos_x = topright_x - 54 - 17 - 12;
1323 else if (minutes < 100)
1324 bgpos_x = topright_x - 72 - 17 - 12;
1326 bgpos_x = topright_x - 90 - 17 - 12;
1330 if (cvar("viewsize") <= 100) { // draw timer background when viewsize <= 100
1332 drawpic(bgpos, "gfx/hud/sb_timerbg", '120 30 0', GetTeamRGB(myteam) * cvar("sbar_color_bg_team"), sbar_alpha_bg, 0); // timer bg color = myteam color
1334 color_x = cvar("sbar_color_bg_r");
1335 color_y = cvar("sbar_color_bg_g");
1336 color_z = cvar("sbar_color_bg_b");
1338 drawpic(bgpos, "gfx/hud/sb_timerbg", '120 30 0', color, sbar_alpha_bg, 0);
1342 if(minutesLeft >= 1 || (cvar("sbar_increment_maptime") && minutes >= 1) ) {
1343 Sbar_DrawXNum(topright - '103 0 0', minutes, 3, 18, timer_color, 0, sbar_alpha_fg, 0);
1344 drawpic(topright - '53 0 0', "gfx/hud/num_colon", '18 18 0', timer_color, sbar_alpha_fg, 0);
1346 Sbar_DrawXNum(topright - '36 0 0' - '3 0 0', seconds, -2, 18, timer_color, 0, 1, DRAWFLAG_NORMAL);
1349 timer_color = '1 1 1'; //white
1350 minutes = floor(time / 60);
1351 seconds = floor(time - minutes*60);
1354 bgpos_x = topright_x - 54 - 17 - 12;
1355 else if (minutes < 100) // nudge the timer background left if more digits are drawn
1356 bgpos_x = topright_x - 72 - 17 - 12;
1358 bgpos_x = topright_x - 90 - 17 - 12;
1362 if (cvar("viewsize") <= 100) { // draw timer background when viewsize <= 100
1364 drawpic(bgpos, "gfx/hud/sb_timerbg", '120 30 0', GetTeamRGB(myteam), sbar_alpha_bg, 0); // timer bg color = myteam color
1366 color_x = cvar("sbar_color_bg_r");
1367 color_y = cvar("sbar_color_bg_g");
1368 color_z = cvar("sbar_color_bg_b");
1370 drawpic(bgpos, "gfx/hud/sb_timerbg", '120 30 0', color, sbar_alpha_bg, 0);
1374 Sbar_DrawXNum(topright - '103 0 0', minutes, 3, 18, timer_color, 0, 1, DRAWFLAG_NORMAL);
1375 drawpic(topright - '53 0 0', "gfx/hud/num_colon", '18 18 0', timer_color, sbar_alpha_fg, 0);
1376 Sbar_DrawXNum(topright - '36 0 0' - '3 0 0', seconds, -2, 18, timer_color, 0, 1, DRAWFLAG_NORMAL);
1379 if(gametype == GAME_RACE)
1381 drawfont = sbar_bigfont;
1384 string s, forcetime;
1386 m = '0.5 0 0' * vid_conwidth + '0 0.25 0' * vid_conheight;
1388 if(race_checkpointtime)
1390 a = bound(0, 2 - (time - race_checkpointtime), 1);
1393 if(a > 0) // just hit a checkpoint?
1395 if(race_time && race_previousbesttime)
1396 s = MakeRaceString(race_checkpoint, race_time / 10 - race_previousbesttime / 10, 0, 0, race_previousbestname);
1398 s = MakeRaceString(race_checkpoint, 0, -1, 0, race_previousbestname);
1400 forcetime = mmsss(race_time);
1404 if(race_laptime && race_nextbesttime)
1406 a = bound(0, 2 - ((race_laptime + race_nextbesttime/10) - time), 1);
1407 if(a > 0) // next one?
1409 s = MakeRaceString(race_nextcheckpoint, time - race_laptime, race_nextbesttime / 10, 0, race_nextbestname);
1414 if(s != "" && a > 0)
1416 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
1417 drawcolorcodedstring(m - '0 16 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', sbar_alpha_fg * a, 0);
1422 a = bound(0, (time - race_checkpointtime) / 0.5, 1);
1423 drawstring_expanding(m - '16 0 0' * stringwidth(forcetime, FALSE), forcetime, '32 32 0', '1 1 1', sbar_alpha_fg, 0, a);
1430 s = mmsss(10*(time - race_laptime));
1431 drawstring(m - '16 0 0' * stringwidth(s, FALSE), s, '32 32 0', '1 1 1', sbar_alpha_fg * a, 0);
1436 if(race_mycheckpointtime)
1438 a = bound(0, 2 - (time - race_mycheckpointtime), 1);
1439 s = MakeRaceString(race_mycheckpoint, race_mycheckpointdelta / 10, -!race_mycheckpointenemy, race_mycheckpointlapsdelta, race_mycheckpointenemy);
1440 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
1441 drawcolorcodedstring(m - '0 16 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', sbar_alpha_fg * a, 0);
1443 if(race_othercheckpointtime && race_othercheckpointenemy != "")
1445 a = bound(0, 2 - (time - race_othercheckpointtime), 1);
1446 s = MakeRaceString(race_othercheckpoint, -race_othercheckpointdelta / 10, -!race_othercheckpointenemy, race_othercheckpointlapsdelta, race_othercheckpointenemy);
1447 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
1448 drawcolorcodedstring(m - '0 0 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', sbar_alpha_fg * a, 0);
1452 drawfont = sbar_font;
1458 float Sbar_WouldDrawScoreboard ()
1462 else if (intermission == 1)
1464 else if (intermission == 2)
1466 else if (getstati(STAT_HEALTH) <= 0 && cvar("cl_deathscoreboard"))
1468 else if(sb_showscores_force)
1473 void CSQC_Strength_Timer() {
1476 bottom_x = vid_conwidth/2;
1477 bottom_y = vid_conheight;
1480 float stat_items, dt;
1481 stat_items = getstati(STAT_ITEMS);
1483 if not(stat_items & IT_STRENGTH)
1484 if not(stat_items & IT_INVINCIBLE)
1488 if (getstati(STAT_HEALTH) <= 0)
1492 float strength_time, invincibility_time, countdown_fontsize;
1494 picsize = '22 22 0';
1495 countdown_fontsize = 18;
1498 strength_time = getstatf(STAT_STRENGTH_FINISHED);
1499 invincibility_time = getstatf(STAT_INVINCIBLE_FINISHED);
1501 if (strength_time) {
1502 dt = strength_time - time;
1507 drawpic_expanding_two(bottom + '192 -46 0', "gfx/hud/sb_str", picsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE,
1508 bound(0, (ceil(dt) - dt) / 0.5, 1));
1512 drawpic(bottom + '192 -46 0', "gfx/hud/sb_str", picsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE);
1514 Sbar_DrawXNum(bottom + '152 -44 0', ceil(dt), 2, countdown_fontsize, '1 1 1', 0, 1, DRAWFLAG_NORMAL);
1518 drawpic_expanding(bottom + '192 -46 0', "gfx/hud/sb_str", picsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE,
1519 bound(0, -dt / 0.5, 1));
1524 if (invincibility_time) {
1525 dt = invincibility_time - time;
1530 drawpic_expanding_two(bottom + '192 -24 0', "gfx/hud/sb_invinc", picsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE,
1531 bound(0, (ceil(dt) - dt) / 0.5, 1));
1535 drawpic(bottom + '192 -24 0', "gfx/hud/sb_invinc", picsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE);
1537 Sbar_DrawXNum(bottom + '152 -22 0', ceil(dt), 2, countdown_fontsize, '1 1 1', 0, 1, DRAWFLAG_NORMAL);
1541 drawpic_expanding(bottom + '192 -24 0', "gfx/hud/sb_invinc", picsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE,
1542 bound(0, -dt / 0.5, 1));
1547 #define CENTERPRINT_MAX_LINES 30
1548 string centerprint_messages[CENTERPRINT_MAX_LINES];
1549 float centerprint_width[CENTERPRINT_MAX_LINES];
1550 vector centerprint_start;
1551 float centerprint_expire;
1552 float centerprint_num;
1553 float centerprint_offset_hint;
1554 vector centerprint_fontsize;
1556 void centerprint(string strMessage)
1558 float i, j, n, hcount;
1561 centerprint_fontsize = Sbar_GetFontsize("scr_centersize");
1563 centerprint_expire = min(centerprint_expire, time); // if any of the returns happens, this message will fade out
1565 if(cvar("scr_centertime") <= 0)
1568 if(strMessage == "")
1571 // strip trailing newlines
1572 j = strlen(strMessage) - 1;
1573 while(substring(strMessage, j, 1) == "\n" && j >= 0)
1575 strMessage = substring(strMessage, 0, j + 1);
1577 if(strMessage == "")
1580 // strip leading newlines and remember them, they are a hint that the message should be lower on the screen
1582 while(substring(strMessage, j, 1) == "\n" && j < strlen(strMessage))
1584 strMessage = substring(strMessage, j, strlen(strMessage) - j);
1585 centerprint_offset_hint = j;
1587 if(strMessage == "")
1590 // if we get here, we have a message. Initialize its height.
1591 centerprint_num = 0;
1593 n = tokenizebyseparator(strMessage, "\n");
1595 for(j = 0; j < n; ++j)
1597 getWrappedLine_remaining = argv(j);
1598 while(getWrappedLine_remaining)
1600 s = getWrappedLine(vid_conwidth * 0.75 / centerprint_fontsize_x, stringwidth_colors);
1601 if(centerprint_messages[i])
1602 strunzone(centerprint_messages[i]);
1603 centerprint_messages[i] = strzone(s);
1604 centerprint_width[i] = stringwidth(s, TRUE);
1607 // half height for empty lines looks better
1613 if(i >= CENTERPRINT_MAX_LINES)
1619 h = centerprint_fontsize_y*hcount;
1621 havail = vid_conheight;
1622 if(cvar("con_chatpos") < 0)
1623 havail -= (-cvar("con_chatpos") + cvar("con_chat")) * cvar("con_chatsize"); // avoid overlapping chat
1625 centerprint_start_x = 0;
1628 float forbiddenmin, forbiddenmax, allowedmin, allowedmax, preferred;
1630 // here, the centerprint would cover the crosshair. REALLY BAD.
1631 forbiddenmin = vid_conheight * 0.5 - h - 16;
1632 forbiddenmax = vid_conheight * 0.5 + 16;
1634 allowedmin = scoreboard_bottom;
1635 allowedmax = havail - h;
1636 preferred = (havail - h)/2;
1639 // possible orderings (total: 4! / 4 = 6)
1640 // allowedmin allowedmax forbiddenmin forbiddenmax
1641 // forbiddenmin forbiddenmax allowedmin allowedmax
1642 if(allowedmax < forbiddenmin || allowedmin > forbiddenmax)
1644 // forbidden doesn't matter in this case
1645 centerprint_start_y = bound(allowedmin, preferred, allowedmax);
1647 // allowedmin forbiddenmin allowedmax forbiddenmax
1648 else if(allowedmin < forbiddenmin && allowedmax < forbiddenmax)
1650 centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
1652 // allowedmin forbiddenmin forbiddenmax allowedmax
1653 else if(allowedmin < forbiddenmin)
1655 // make sure the forbidden zone is not covered
1656 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
1657 centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
1659 centerprint_start_y = bound(forbiddenmax, preferred, allowedmin);
1661 // forbiddenmin allowedmin allowedmax forbiddenmax
1662 else if(allowedmax < forbiddenmax)
1664 // it's better to leave the allowed zone (overlap with scoreboard) than
1665 // to cover the forbidden zone (crosshair)
1666 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
1667 centerprint_start_y = forbiddenmax;
1669 centerprint_start_y = forbiddenmin;
1671 // forbiddenmin allowedmin forbiddenmax allowedmax
1674 centerprint_start_y = bound(forbiddenmax, preferred, allowedmax);
1677 centerprint_start_y =
1680 max(scoreboard_bottom, vid_conheight * 0.5 + 16),
1687 centerprint_num = i;
1688 centerprint_expire = time + cvar("scr_centertime");
1691 void Sbar_DrawCenterPrint (void)
1698 //if(time > centerprint_expire)
1701 //a = bound(0, 1 - 2 * (time - centerprint_expire), 1);
1702 a = bound(0, 1 - 4 * (time - centerprint_expire), 1);
1703 //sz = 1.2 / (a + 0.2);
1708 pos = centerprint_start;
1709 for (i=0; i<centerprint_num; i = i + 1)
1711 pos_x = (vid_conwidth - centerprint_fontsize_x * centerprint_width[i]) * 0.5;
1712 ts = centerprint_messages[i];
1715 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
1716 drawcolorcodedstring(pos, ts, centerprint_fontsize, a, DRAWFLAG_NORMAL);
1717 // - '0 0.5 0' * (sz - 1) * centerprint_fontsize_x - '0.5 0 0' * (sz - 1) * centerprint_width[i] * centerprint_fontsize_y, centerprint_fontsize * sz
1718 pos_y = pos_y + centerprint_fontsize_y;
1721 // half height for empty lines looks better
1722 pos_y = pos_y + centerprint_fontsize_y * 0.5;
1726 vector Sbar_DrawNoteLine(vector offset, string s)
1728 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
1729 drawcolorcodedstring(
1730 offset - sbar_fontsize_x * '1 0 0' * stringwidth(s, TRUE),
1736 return offset + sbar_fontsize_y * '0 1 0';
1739 void Sbar_DrawPressedKeys(void)
1744 pos = stov(cvar_string("cl_showpressedkeys_position"));
1746 bgsize = '126 75 0';
1748 pos = '1 0 0' * (vid_conwidth - bgsize_x) * pos_x
1749 + '0 1 0' * (vid_conheight - bgsize_y) * pos_y;
1750 pos -= '-15 -6 0'; // adjust to the origin of these numbers
1752 pressedkeys = getstatf(STAT_PRESSED_KEYS);
1753 drawpic(pos + '-15 -6 0', "gfx/hud/keys/key_bg.tga", bgsize, '1 1 1', .1, DRAWFLAG_NORMAL);
1754 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);
1755 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);
1756 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);
1757 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);
1758 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);
1759 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);
1762 void Sbar_DrawStats()
1764 float i, count_hitscan, count_splash, row; // count is the number of 'colums'
1765 float weapon_hit, weapon_damage, weapon_stats;
1766 float left_border; // position where the weapons start, the description is in the border
1767 vector fill_colour, fill_size;
1770 float col_margin = 20; // pixels between the columns
1771 float row_margin = 20; // pixels between the rows
1772 float top_border; // position where the first row starts: pixels down the screen
1774 fill_size_x = 5 * sbar_fontsize_x; // width of the background
1775 fill_size_y = 10 * sbar_fontsize_y; // height of the background
1777 // 45 pixels is the same as the 'Scoreboard' heading
1778 drawfont = sbar_bigfont;
1779 drawstringcenter('0 45 0', "Weapon Accuracy", 2 * sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
1780 left_border = col_margin + 11 * sbar_fontsize_x;
1783 Sbar_DrawStats_Description_Hitscan('1 0 0' * col_margin + '0 1 0' * top_border);
1786 Sbar_DrawStats_Description_Splash('1 0 0' * col_margin + '0 1 0' * top_border);
1789 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1791 weapon_hit = weapon_hits[i];
1792 weapon_damage = weapon_fired[i];
1793 self = get_weaponinfo(i);
1795 //if ((weapon_number != 42)) // print them all :)
1796 if ((self.weapon_type == WEP_TYPE_SPLASH) && (weapon_damage))
1799 weapon_stats = rint(100 * weapon_hit / weapon_damage);
1801 fill_colour_x = 1 - 0.015 * weapon_stats;
1802 fill_colour_y = 1 - 0.015 * (100 - weapon_stats);
1804 // how the background colour is calculated
1805 // % red green red_2 green_2
1806 // 0 1 0 1 - % * 0.015 1 - (100 - %) * 0.015
1807 // 10 0.85 0 1 - % * 0.015 1 - (100 - %) * 0.015
1808 // 20 0.70 0 1 - % * 0.015 1 - (100 - %) * 0.015
1809 // 30 0.55 0 1 - % * 0.015 1 - (100 - %) * 0.015
1810 // 40 0.40 0.10 1 - % * 0.015 1 - (100 - %) * 0.015
1811 // 50 0.25 0.25 1 - % * 0.015 1 - (100 - %) * 0.015
1812 // 60 0.10 0.40 1 - % * 0.015 1 - (100 - %) * 0.015
1813 // 70 0 0.55 1 - % * 0.015 1 - (100 - %) * 0.015
1814 // 80 0 0.70 1 - % * 0.015 1 - (100 - %) * 0.015
1815 // 90 0 0.85 1 - % * 0.015 1 - (100 - %) * 0.015
1816 // 100 0 1 1 - % * 0.015 1 - (100 - %) * 0.015
1818 if ((left_border + count_splash * (fill_size_x + col_margin) + fill_size_x) >= vid_conwidth)
1822 Sbar_DrawStats_Description_Splash('1 0 0' * col_margin + '0 1 0' * (top_border + row * (fill_size_y + row_margin)));
1825 pos_x = left_border + count_splash * (fill_size_x + col_margin);
1826 pos_y = top_border + row * (fill_size_y + row_margin);
1829 drawfill(pos, fill_size , fill_colour, 0.4 * sbar_alpha_fg, DRAWFLAG_NORMAL);
1832 drawpic(pos, strcat("gfx/inv_weapon", ftos(i-1)), '1 0.5 0' * fill_size_x , '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
1834 // the amount of shots fired or max damage
1835 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);
1837 // the amount of hits or actual damage
1838 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);
1841 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);
1843 // the amount of shots missed or damage wasted
1844 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);
1848 else if ((self.weapon_type == WEP_TYPE_HITSCAN) && (weapon_damage))
1851 weapon_stats = rint(100 * weapon_hit / weapon_damage);
1853 fill_colour_x = 1 - 0.015 * weapon_stats;
1854 fill_colour_y = 1 - 0.015 * (100 - weapon_stats);
1856 // how the background colour is calculated
1857 // % red green red_2 green_2
1858 // 0 1 0 1 - % * 0.015 1 - (100 - %) * 0.015
1859 // 10 0.85 0 1 - % * 0.015 1 - (100 - %) * 0.015
1860 // 20 0.70 0 1 - % * 0.015 1 - (100 - %) * 0.015
1861 // 30 0.55 0 1 - % * 0.015 1 - (100 - %) * 0.015
1862 // 40 0.40 0.10 1 - % * 0.015 1 - (100 - %) * 0.015
1863 // 50 0.25 0.25 1 - % * 0.015 1 - (100 - %) * 0.015
1864 // 60 0.10 0.40 1 - % * 0.015 1 - (100 - %) * 0.015
1865 // 70 0 0.55 1 - % * 0.015 1 - (100 - %) * 0.015
1866 // 80 0 0.70 1 - % * 0.015 1 - (100 - %) * 0.015
1867 // 90 0 0.85 1 - % * 0.015 1 - (100 - %) * 0.015
1868 // 100 0 1 1 - % * 0.015 1 - (100 - %) * 0.015
1870 if ((left_border + count_hitscan * (fill_size_x + col_margin) + fill_size_x + cvar("stats_right_margin")) >= vid_conwidth)
1874 Sbar_DrawStats_Description_Hitscan('1 0 0' * col_margin + '0 1 0' * (top_border + row * (fill_size_y + row_margin)));
1877 pos_x = left_border + count_hitscan * (fill_size_x + col_margin);
1878 pos_y = top_border + row * (fill_size_y + row_margin);
1881 drawfill(pos, fill_size , fill_colour, 0.4 * sbar_alpha_fg, DRAWFLAG_NORMAL);
1884 drawpic(pos, strcat("gfx/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);
1903 void Sbar_DrawStats_Description_Hitscan(vector position)
1905 drawfont = sbar_font;
1907 drawstring(position + '0 3 0' * sbar_fontsize_y, "Shots fired:", sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
1908 drawstring(position + '0 5 0' * sbar_fontsize_y, "Shots hit:", sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
1909 drawstring(position + '0 7 0' * sbar_fontsize_y, "Accuracy:", sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
1910 drawstring(position + '0 9 0' * sbar_fontsize_y, "Shots missed:", sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
1913 void Sbar_DrawStats_Description_Splash(vector position)
1916 drawfont = sbar_font;
1917 drawstring(position + '0 3 0' * sbar_fontsize_y, "Maximum damage:", sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
1918 drawstring(position + '0 5 0' * sbar_fontsize_y, "Actual damage:", sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
1919 drawstring(position + '0 7 0' * sbar_fontsize_y, "Accuracy:", sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
1920 drawstring(position + '0 9 0' * sbar_fontsize_y, "Damage wasted:", sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
1923 void drawstringright(vector position, string text, vector scale, vector rgb, float alpha, float flag)
1925 position_x -= 2 / 3 * strlen(text) * scale_x;
1926 drawstring(position, text, scale, rgb, alpha, flag);
1929 void drawstringcenter(vector position, string text, vector scale, vector rgb, float alpha, float flag)
1931 position_x = 0.5 * (vid_conwidth - 0.6025 * strlen(text) * scale_x);
1932 drawstring(position, text, scale, rgb, alpha, flag);
1935 float GetAmmoStat(float i)
1939 case 0: return STAT_SHELLS;
1940 case 1: return STAT_NAILS;
1941 case 2: return STAT_ROCKETS;
1942 case 3: return STAT_CELLS;
1943 case 4: return STAT_FUEL;
1948 float GetAmmoItemCode(float i)
1952 case 0: return IT_SHELLS;
1953 case 1: return IT_NAILS;
1954 case 2: return IT_ROCKETS;
1955 case 3: return IT_CELLS;
1956 case 4: return IT_FUEL;
1961 string GetAmmoPicture(float i)
1965 case 0: return "gfx/hud/sb_shells";
1966 case 1: return "gfx/hud/sb_bullets";
1967 case 2: return "gfx/hud/sb_rocket";
1968 case 3: return "gfx/hud/sb_cells";
1969 case 4: return "gfx/hud/sb_fuel";
1974 void Sbar_Draw (void)
1976 // vectors for top right, bottom right, bottom and bottom left corners
1983 topright_x = vid_conwidth;
1987 bottom_x = vid_conwidth/2;
1988 bottom_y = vid_conheight;
1991 bottomright_x = vid_conwidth;
1992 bottomright_y = vid_conheight;
1996 bottomleft_y = vid_conheight;
1999 sbar_alpha_bg = cvar("sbar_alpha_bg");
2004 float stat_items, stat_weapons;
2006 weapon_stats = getstati(STAT_DAMAGE_HITS);
2007 weapon_number = weapon_stats & 63;
2008 weapon_hits[weapon_number] = rint(weapon_stats / 64);
2010 weapon_stats = getstati(STAT_DAMAGE_FIRED);
2011 weapon_number = weapon_stats & 63;
2012 weapon_fired[weapon_number] = rint(weapon_stats / 64);
2014 vector o; o = '1 0 0' * vid_conwidth;
2015 o_y = 28; // move spectator text slightly down to prevent overlapping the timer
2019 sbar_fontsize = Sbar_GetFontsize("sbar_fontsize");
2021 if(spectatee_status && !intermission)
2023 if(spectatee_status == -1)
2026 s = strcat("^1Spectating ^7", GetPlayerName(spectatee_status - 1));
2027 o = Sbar_DrawNoteLine(o, s);
2029 if(spectatee_status == -1)
2030 s = strcat("^1Press ^3", getcommandkey("primary fire", "+attack"), "^1 to spectate");
2032 s = strcat("^1Press ^3", getcommandkey("primary fire", "+attack"), "^1 for another player");
2033 o = Sbar_DrawNoteLine(o, s);
2035 if(spectatee_status == -1)
2036 s = strcat("^1Use ^3", getcommandkey("next weapon", "weapnext"), "^1 or ^3", getcommandkey("previous weapon", "weapprev"), "^1 to change the speed");
2038 s = strcat("^1Press ^3", getcommandkey("secondary fire", "+attack2"), "^1 to observe");
2039 o = Sbar_DrawNoteLine(o, s);
2041 s = strcat("^1Press ^3", getcommandkey("server info", "+show_info"), "^1 for gamemode info");
2042 o = Sbar_DrawNoteLine(o, s);
2044 if(gametype == GAME_ARENA)
2045 s = "^1Wait for your turn to join";
2046 else if(gametype == GAME_LMS)
2049 sk = playerslots[player_localentnum - 1];
2050 if(sk.(scores[ps_primary]) >= 666)
2051 s = "^1Match has already begun";
2052 else if(sk.(scores[ps_primary]) > 0)
2053 s = "^1You have no more lives left";
2055 s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
2058 s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
2059 o = Sbar_DrawNoteLine(o, s);
2061 //show restart countdown:
2062 if (time < getstatf(STAT_GAMESTARTTIME)) {
2064 //we need to ceil, otherwise the countdown would be off by .5 when using round()
2065 countdown = ceil(getstatf(STAT_GAMESTARTTIME) - time);
2066 s = strcat("^1Game starts in ^3", ftos(countdown), "^1 seconds");
2067 o = Sbar_DrawNoteLine(o, s);
2070 if(warmup_stage && !intermission)
2072 s = "^2Currently in ^1warmup^2 stage!";
2073 o = Sbar_DrawNoteLine(o, s);
2076 // move more important stuff more to the middle so its more visible
2077 o_y = vid_conheight * 0.66;
2080 if(mod(time, 1) >= 0.5)
2085 if(ready_waiting && !intermission)
2087 if(ready_waiting_for_me)
2090 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " to end warmup");
2092 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " once you are ready");
2097 s = strcat("^2Waiting for others to ready up to end warmup...");
2099 s = strcat("^2Waiting for others to ready up...");
2101 o = Sbar_DrawNoteLine(o, s);
2103 else if(warmup_stage && !intermission)
2105 s = strcat("^2Press ^3", getcommandkey("ready", "ready"), "^2 to end warmup");
2106 o = Sbar_DrawNoteLine(o, s);
2110 s = strcat("^2A vote has been called for ^1", vote_called_vote);
2111 o = Sbar_DrawNoteLine(o, s);
2113 if(vote_waiting_for_me)
2115 s = strcat(blinkcolor, "Press ^3", getcommandkey("vote yes", "vyes"), blinkcolor, " to accept");
2116 o = Sbar_DrawNoteLine(o, s);
2118 s = strcat(blinkcolor, "Press ^3", getcommandkey("vote no", "vno"), blinkcolor, " to reject");
2119 o = Sbar_DrawNoteLine(o, s);
2121 s = strcat(blinkcolor, "Press ^3", getcommandkey("vote abstain", "vabstain"), blinkcolor, " to abstain");
2122 o = Sbar_DrawNoteLine(o, s);
2126 s = strcat("^2Waiting for others to vote...");
2127 o = Sbar_DrawNoteLine(o, s);
2130 if(teamplay && !intermission)
2133 float ts_min, ts_max;
2134 tm = teams.sort_next;
2137 for(; tm.sort_next; tm = tm.sort_next)
2139 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
2141 if(!ts_min) ts_min = tm.team_size;
2142 else ts_min = min(ts_min, tm.team_size);
2143 if(!ts_max) ts_max = tm.team_size;
2144 else ts_max = max(ts_max, tm.team_size);
2146 if ((ts_max - ts_min) > 1)
2148 s = strcat(blinkcolor, "Teamnumbers are unbalanced!");
2149 tm = GetTeam(myteam, false);
2151 if (tm.team != COLOR_SPECTATOR)
2152 if (tm.team_size == ts_max)
2153 s = strcat(s, " Press ^3", getcommandkey("team menu", "menu_showteamselect"), blinkcolor, " to adjust");
2155 o = Sbar_DrawNoteLine(o, s);
2160 Sbar_UpdatePlayerTeams();
2162 if (intermission == 1)
2164 Sbar_DrawScoreboard();
2165 Sbar_DrawCenterPrint();
2168 else if (intermission == 2)
2170 Sbar_FinaleOverlay();
2171 Sbar_DrawCenterPrint();
2173 else if(sb_showaccuracy == 1)
2179 if (sb_showscores_force || (getstati(STAT_HEALTH) <= 0 && cvar("cl_deathscoreboard")))
2181 sbar_x = (vid_conwidth - 640.0)*0.5;
2182 sbar_y = vid_conheight - 47;
2183 //Sbar_DrawAlphaPic (sbar_x, sbar_y, sb_scorebar, sbar_alpha_bg.value);
2184 //drawpic('0 0 0', "gfx/hud/scorebar", '0 0 0', '1 1 1', cvar("sbar_alpha_bg"), 0);
2185 Sbar_DrawScoreboard ();
2189 if (sb_showscores) // do not hide the hud if sb_showscores is shown
2191 Sbar_DrawScoreboard();
2192 Sbar_DrawCenterPrint();
2195 float armor, health;
2196 armor = getstati(STAT_ARMOR);
2197 health = getstati(STAT_HEALTH);
2199 stat_items = getstati(STAT_ITEMS);
2200 stat_weapons = getstati(STAT_WEAPONS);
2202 fade = 3.2 - 2 * (time - weapontime);
2203 fade = bound(0.7, fade, 1);
2205 vector bg_size; // hud background size
2207 if (vid_conwidth > 800) // if conwidth > 800, resize the background image
2208 bg_size_x = vid_conwidth;
2212 vector bgoffset; // hud background offset
2216 if (vid_conwidth < 800) // if conwidth < 800 we need to offset the background image to keep it centered, as it will be scaled up
2217 bgoffset_x = (vid_conwidth - 800) / 2;
2219 if (cvar("viewsize") <= 100) {
2221 //if (myteam == 13) // 13 = blue shirt color
2222 // drawpic(bottomleft - '0 58 0' + bgoffset, "gfx/hud/sbar", bg_size, '0 0.3 1', sbar_alpha_bg, 0); // blue hud is too dark at '0 0 1'
2224 drawpic(bottomleft - '0 58 0' + bgoffset, "gfx/hud/sbar", bg_size, GetTeamRGB(myteam) * cvar("sbar_color_bg_team"), sbar_alpha_bg, 0); // hud color = myteam color
2227 // allow for custom HUD colors in non-teamgames
2228 color_x = cvar("sbar_color_bg_r");
2229 color_y = cvar("sbar_color_bg_g");
2230 color_z = cvar("sbar_color_bg_b");
2232 drawpic(bottomleft - '0 58 0' + bgoffset, "gfx/hud/sbar", bg_size, color, sbar_alpha_bg, 0);
2238 if(sbar_hudselector == 2) // combined health and armor display
2240 // NOTE: we'll always choose the SMALLER value...
2241 float healthdamage, armordamage, armorideal;
2242 healthdamage = (health - 1) / (1 - armorblockpercent); // damage we can take if we could use more health
2243 armordamage = armor + (health - 1); // damage we can take if we could use more armor
2244 armorideal = healthdamage * armorblockpercent;
2247 num_pos = bottom - element_offset - '0 24 0' + '-96 0 0';
2249 if(armordamage < healthdamage)
2251 // here, armorideal > armor
2252 x = floor(armordamage + 1);
2253 drawpic(num_pos + '78 -3 0', "gfx/hud/sb_health", '32 32 0', '1 1 1', sbar_alpha_fg, 0);
2254 drawpic(num_pos + '108 -3 0', "gfx/hud/sb_armor", '20 20 0', '1 1 1', sbar_alpha_fg * armor / armorideal, 0);
2258 x = floor(healthdamage + 1);
2259 drawpic(num_pos + '108 -3 0', "gfx/hud/sb_health", '20 20 0', '1 1 1', sbar_alpha_fg * armorideal / armor, 0);
2260 drawpic(num_pos + '78 -3 0', "gfx/hud/sb_armor", '32 32 0', '1 1 1', sbar_alpha_fg, 0);
2262 Sbar_DrawXNum_Colored(num_pos, x, 24); // draw the combined health and armor
2267 vector health_pos, armor_pos;
2269 if (sbar_hudselector == 0) { // old style layout with armor left of health
2270 health_pos = bottom - element_offset - '0 24 0' + '14 0 0';
2271 armor_pos = bottom - element_offset - '0 24 0' + '-96 0 0';
2275 health_pos = bottom - element_offset - '0 24 0' + '-96 0 0';
2276 armor_pos = bottom - element_offset - '0 24 0' + '14 0 0';
2283 drawpic(armor_pos + '78 -3 0', "gfx/hud/sb_armor", '32 32 0', '1 1 1', sbar_alpha_fg, 0);
2285 Sbar_DrawXNum_Colored(armor_pos, x, 24);
2290 drawpic(health_pos + '78 -3 0', "gfx/hud/sb_health", '32 32 0', '1 1 1', sbar_alpha_fg, 0);
2292 Sbar_DrawXNum_Colored(health_pos, x, 24);
2297 Sbar_DrawWeapon_Clear();
2298 for(i = 1; i <= 24; ++i)
2300 if(weaponimpulse[i-1] >= 0)
2301 if(stat_weapons & x)
2303 Sbar_DrawWeapon(i-1, fade, (i == activeweapon), i);
2309 float a; // i will be the ammo type (already declared), a will contain how much ammo there is of type i
2313 for (i = 0; i < 4; ++i) {
2314 a = getstati(GetAmmoStat(i)); // how much ammo do we have of type i?
2318 if (cvar("vid_conwidth") >= 800)
2320 case 0: pos_x = 114; pos_y = -48; break; // shells
2321 case 1: pos_x = 114; pos_y = -26; break; // bullets
2322 case 2: pos_x = 200; pos_y = -48; break; // rockets
2323 case 3: pos_x = 200; pos_y = -26; break; // cells
2325 else // if vid_conwidth is lower than 800, ammo will overlap with weapon icons and health so we'll move it to the right
2327 case 0: pos_x = vid_conwidth - 158; pos_y = -150; break; // shells
2328 case 1: pos_x = vid_conwidth - 158; pos_y = -128; break; // bullets
2329 case 2: pos_x = vid_conwidth - 84; pos_y = -150; break; // rockets
2330 case 3: pos_x = vid_conwidth - 84; pos_y = -128; break; // cells
2333 if (stat_items & GetAmmoItemCode(i))
2334 drawpic(bottomleft + pos + '0 1.5 0', "gfx/hud/sb_ammobg", '80 22 0', '1 1 1', sbar_alpha_fg, 0);
2335 drawpic(bottomleft + pos + '56 3 0', GetAmmoPicture(i), '18 18 0', '1 1 1', sbar_alpha_fg, 0);
2337 Sbar_DrawXNum(bottomleft + pos + '6 4 0', a, 3, 16, '0.6 0.7 0.8', 0, 1, 0);
2339 Sbar_DrawXNum(bottomleft + pos + '6 4 0', a, 3, 16, '0.7 0 0', 0, 1, 0);
2344 a = getstati(GetAmmoStat(4)); // how much fuel do we have?
2346 if (a > 0) { // if we have fuel, draw the amount
2347 float invincibility_time, dt;
2348 invincibility_time = getstatf(STAT_INVINCIBLE_FINISHED);
2349 dt = invincibility_time - time;
2350 if (dt > 0) { // if the invincibility timer is active, draw fuel ammo elsewhere
2351 pos_x = bottom_x + 140;
2352 pos_y = bottom_y - 72;
2354 else { // if the invincibility timer is inactive, draw the fuel ammo there (it's rare to have invincibility + fuel anyway)
2355 pos_x = bottom_x + 140;
2356 pos_y = bottom_y - 22;
2358 drawpic(pos - '0 2 0' + '52 0 0', GetAmmoPicture(4), '20 20 0', '1 1 1', sbar_alpha_fg, 0);
2360 Sbar_DrawXNum(pos, a, 3, 16, '0.6 0.7 0.8', 0, 1, 0);
2362 Sbar_DrawXNum(pos, a, 3, 16, '0.7 0 0', 0, 1, 0);
2365 // draw scores and timer
2369 //show strength/invincibility ICON and timer:
2370 CSQC_Strength_Timer();
2372 if(gametype == GAME_KEYHUNT)
2375 } else if(gametype == GAME_CTF)
2378 } else if(gametype == GAME_NEXBALL)
2387 void CSQC_ctf_hud(void)
2391 bottomleft_y = vid_conheight;
2394 float redflag, blueflag;
2397 stat_items = getstati(STAT_ITEMS);
2398 redflag = (stat_items/IT_RED_FLAG_TAKEN) & 3;
2399 blueflag = (stat_items/IT_BLUE_FLAG_TAKEN) & 3;
2401 if (myteam == COLOR_TEAM1) { // always draw own flag on left
2404 case 1: drawpic(bottomleft - element_offset - '-4 36 0', "gfx/hud/sb_flag_red_taken", '48 48 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); break;
2405 case 2: drawpic(bottomleft - element_offset - '-4 36 0', "gfx/hud/sb_flag_red_lost", '48 48 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); break;
2406 case 3: drawpic(bottomleft - element_offset - '-4 36 0', "gfx/hud/sb_flag_red_carrying", '48 48 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); break;
2408 if(stat_items & IT_CTF_SHIELDED)
2409 if(myteam == COLOR_TEAM2)
2410 drawpic(bottomleft - element_offset - '-4 36 0', "gfx/hud/sb_flag_red_shielded", '48 48 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); break;
2415 case 1: drawpic(bottomleft - element_offset - '-72 36 0', "gfx/hud/sb_flag_blue_taken", '48 48 0', '1 1 1', sbar_alpha_fg, 0); break;
2416 case 2: drawpic(bottomleft - element_offset - '-72 36 0', "gfx/hud/sb_flag_blue_lost", '48 48 0', '1 1 1', sbar_alpha_fg, 0); break;
2417 case 3: drawpic(bottomleft - element_offset - '-72 36 0', "gfx/hud/sb_flag_blue_carrying", '48 48 0', '1 1 1', sbar_alpha_fg, 0); break;
2419 if(stat_items & IT_CTF_SHIELDED)
2420 if(myteam == COLOR_TEAM1)
2421 drawpic(bottomleft - element_offset - '-72 36 0', "gfx/hud/sb_flag_blue_shielded", '48 48 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); break;
2428 case 1: drawpic(bottomleft - element_offset - '-4 36 0', "gfx/hud/sb_flag_blue_taken", '48 48 0', '1 1 1', sbar_alpha_fg, 0); break;
2429 case 2: drawpic(bottomleft - element_offset - '-4 36 0', "gfx/hud/sb_flag_blue_lost", '48 48 0', '1 1 1', sbar_alpha_fg, 0); break;
2430 case 3: drawpic(bottomleft - element_offset - '-4 36 0', "gfx/hud/sb_flag_blue_carrying", '48 48 0', '1 1 1', sbar_alpha_fg, 0); break;
2432 if(stat_items & IT_CTF_SHIELDED)
2433 if(myteam == COLOR_TEAM1)
2434 drawpic(bottomleft - element_offset - '-4 36 0', "gfx/hud/sb_flag_blue_shielded", '48 48 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); break;
2439 case 1: drawpic(bottomleft - element_offset - '-72 36 0', "gfx/hud/sb_flag_red_taken", '48 48 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); break;
2440 case 2: drawpic(bottomleft - element_offset - '-72 36 0', "gfx/hud/sb_flag_red_lost", '48 48 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); break;
2441 case 3: drawpic(bottomleft - element_offset - '-72 36 0', "gfx/hud/sb_flag_red_carrying", '48 48 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); break;
2443 if(stat_items & IT_CTF_SHIELDED)
2444 if(myteam == COLOR_TEAM2)
2445 drawpic(bottomleft - element_offset - '-72 36 0', "gfx/hud/sb_flag_red_shielded", '48 48 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); break;
2451 void CSQC_kh_hud(void)
2453 float kh_keys, kh_keys_status, kh_teams_set;
2454 vector red_pos, blue_pos, yellow_pos, pink_pos, kh_size;
2458 bottomleft_y = vid_conheight;
2462 red_pos_y = vid_conheight - 35 - 6;
2465 blue_pos_x = 6 + (24 * 1);
2466 blue_pos_y = vid_conheight - 35 - 6;
2469 yellow_pos_x = 6 + (24 * 2);
2470 yellow_pos_y = vid_conheight - 35 - 6;
2473 pink_pos_x = 6 + (24 * 3);
2474 pink_pos_y = vid_conheight - 35 - 6;
2477 kh_keys = getstati(STAT_KH_KEYS);
2478 kh_keys_status = kh_keys / 256;
2479 kh_teams_set = cvar("_teams_available"); // set in keyhunt.qc
2481 kh_size = '22 35 0';
2483 if (kh_keys_status & 1) // red
2484 drawpic (red_pos, "gfx/hud/sb_kh_red", kh_size, '1 1 1', 0.3, 0); // show 30% alpha key
2486 drawpic (red_pos, "gfx/hud/sb_kh_red", kh_size, '1 1 1', 1.0, 0); // show solid key 100% alpha
2488 if (kh_keys_status & 2) // blue
2489 drawpic (blue_pos, "gfx/hud/sb_kh_blue", kh_size, '1 1 1', 0.3, 0);
2491 drawpic (blue_pos, "gfx/hud/sb_kh_blue", kh_size, '1 1 1', 1.0, 0);
2493 if (kh_teams_set & 4) // yellow
2495 if (kh_keys_status & 4)
2496 drawpic (yellow_pos, "gfx/hud/sb_kh_yellow", kh_size, '1 1 1', 0.3, 0);
2498 drawpic (yellow_pos, "gfx/hud/sb_kh_yellow", kh_size, '1 1 1', 1.0, 0);
2501 if (kh_teams_set & 8) // pink
2503 if (kh_keys_status & 8)
2504 drawpic (pink_pos, "gfx/hud/sb_kh_pink", kh_size, '1 1 1', 0.3, 0);
2506 drawpic (pink_pos, "gfx/hud/sb_kh_pink", kh_size, '1 1 1', 1.0, 0);
2511 #define NBPB_SIZE '96 38 0'
2512 #define NBPB_BT 2 //thickness
2513 #define NBPB_BRGB '1 1 1'
2514 #define NBPB_BALPH 1 //alpha
2515 #define NBPB_BFLAG DRAWFLAG_NORMAL
2516 #define NBPB_IALPH 0.4
2517 #define NBPB_IFLAG DRAWFLAG_NORMAL
2518 #define NBPB_IRGB '0.7 0.1 0'
2520 void CSQC_nb_hud(void)
2522 float stat_items, nb_pb_starttime, dt, p;
2525 stat_items = getstati(STAT_ITEMS);
2526 nb_pb_starttime = getstatf(STAT_NB_METERSTART);
2529 pos_y = vid_conheight - 42;
2532 //Manage the progress bar if any
2533 if (nb_pb_starttime > 0)
2536 dt = mod(time - nb_pb_starttime, nb_pb_period);
2537 // one period of positive triangle
2538 p = 2 * dt / nb_pb_period;
2544 drawfill(pos, p * s_x * '1 0 0' + s_y * '0 1 0', NBPB_IRGB, NBPB_IALPH, NBPB_IFLAG);
2548 drawline(NBPB_BT, pos , pos + '1 0 0' * s_x, NBPB_BRGB, NBPB_BALPH, NBPB_BFLAG);
2549 drawline(NBPB_BT, pos , pos + '0 1 0' * s_y, NBPB_BRGB, NBPB_BALPH, NBPB_BFLAG);
2550 drawline(NBPB_BT, pos + s, pos + '1 0 0' * s_x, NBPB_BRGB, NBPB_BALPH, NBPB_BFLAG);
2551 drawline(NBPB_BT, pos + s, pos + '0 1 0' * s_y, NBPB_BRGB, NBPB_BALPH, NBPB_BFLAG);
2554 pos_x += 12; //horizontal margin to the picture
2555 pos_y += 2; //vertical margin to the picture
2557 if (stat_items & IT_KEY1)
2558 drawpic(pos, "gfx/hud/sb_nexball_carrying", '80 34 0', '1 1 1', 1, DRAWFLAG_NORMAL);