5 float sb_lines; // still don't know what to do with that NOTE: check dp's sbar.c to see what that should be
9 float sbar_hudselector;
11 float ps_primary, ps_secondary;
12 float ts_primary, ts_secondary;
18 void Sbar_FinaleOverlay()
21 pos_x = (vid_conwidth - 1)/2;
25 //drawpic(pos, "gfx/finale", '0 0 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
27 //drawstring(pos, "END", sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
31 float weaponspace[10];
32 float weapon_first, weapon_last;
33 void Sbar_DrawWeapon_Clear()
38 for(idx = 0; idx < 10; ++idx)
40 for(idx = 0; idx <= 23; ++idx)
42 if(weaponimpulse[idx] >= 0)
50 void Sbar_DrawWeapon(float nr, float fade, float active)
52 vector pos, vsize, color;
53 float value, idx, imp, sp;
55 imp = weaponimpulse[nr];
61 value = (active) ? 1 : 0.6;
62 color_x = color_y = color_z = value;
64 if(sbar_hudselector == 1)
66 // width = 300, height = 100
67 const float w_width = 32, w_height = 12, w_space = 2, font_size = 8;
69 sp = weaponspace[idx] + 1;
70 weaponspace[idx] = sp;
72 pos_x = (vid_conwidth - w_width * 9) * 0.5 + w_width * idx;
73 pos_y = (vid_conheight - w_height * sp);
78 drawpic(pos, strcat("gfx/inv_weapon", ftos(nr)), vsize, color, value * fade * sbar_alpha_fg, 0);
84 drawstring(pos, ftos(imp), vsize, '1 1 0', sbar_alpha_fg, 0);
88 // width = 300, height = 100
89 const float w2_width = 300, w2_height = 100, w2_space = 10;
90 const float w2_scale = 0.4;
93 f = 9 / (weapon_last + 1 - weapon_first);
95 pos_x = vid_conwidth - (w2_width + w2_space) * w2_scale * f;
96 pos_y = (w2_height + w2_space) * w2_scale * nr * f + w2_space;
98 vsize_x = w2_width * w2_scale * f;
99 vsize_y = w2_height * w2_scale * f;
102 drawpic(pos, strcat("gfx/inv_weapon", ftos(nr)), vsize, color, value * fade * sbar_alpha_fg, 0);
105 void Sbar_DrawXNum (vector pos, float num, float digits, float lettersize, vector rgb, float a, float dflags)
112 vsize_x = vsize_y = lettersize;
127 str = strcat(substring("0000000000", 0, digits - strlen(tmp)), tmp);
135 str = substring(str, l-digits, 999);
137 } else if(l < digits)
138 pos_x += (digits-l) * lettersize;
142 drawpic(sbar + pos, "gfx/num_minus", vsize, rgb, a * sbar_alpha_fg, dflags);
146 for(i = 0; i < l; ++i)
148 drawpic(sbar + pos, strcat("gfx/num_", substring(str, i, 1)), vsize, rgb, a * sbar_alpha_fg, dflags);
153 void Cmd_Sbar_SetFields(float argc);
154 void Sbar_InitScores()
158 ps_primary = ps_secondary = ts_primary = ts_secondary = -1;
159 for(i = 0; i < MAX_SCORE; ++i)
161 f = (scores_flags[i] & SFL_SORT_PRIO_MASK);
162 if(f == SFL_SORT_PRIO_PRIMARY)
164 if(f == SFL_SORT_PRIO_SECONDARY)
167 if(ps_secondary == -1)
168 ps_secondary = ps_primary;
170 for(i = 0; i < MAX_TEAMSCORE; ++i)
172 f = (teamscores_flags[i] & SFL_SORT_PRIO_MASK);
173 if(f == SFL_SORT_PRIO_PRIMARY)
175 if(f == SFL_SORT_PRIO_SECONDARY)
178 if(ts_secondary == -1)
179 ts_secondary = ts_primary;
181 Cmd_Sbar_SetFields(0);
184 void Sbar_UpdatePlayerPos(entity pl);
185 float SetTeam(entity pl, float Team);
187 void Sbar_UpdatePlayerTeams()
194 for(pl = players.sort_next; pl; pl = pl.sort_next)
197 Team = GetPlayerColor(pl.sv_entnum);
198 if(SetTeam(pl, Team))
201 Sbar_UpdatePlayerPos(pl);
205 pl = players.sort_next;
210 print(strcat("PNUM: ", ftos(num), "\n"));
215 float Sbar_ComparePlayerScores(entity left, entity right)
218 vl = GetPlayerColor(left.sv_entnum);
219 vr = GetPlayerColor(right.sv_entnum);
222 vl = COLOR_SPECTATOR;
224 vr = COLOR_SPECTATOR;
231 if(vl == COLOR_SPECTATOR)
233 // FIRST the one with scores (spectators), THEN the ones without (downloaders)
235 if(!left.gotscores && right.gotscores)
240 vl = left.scores[ps_primary];
241 vr = right.scores[ps_primary];
242 if(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)
244 if(vl == 0 && vr != 0)
246 if(vl != 0 && vr == 0)
250 return IS_INCREASING(scores_flags[ps_primary]);
252 return IS_DECREASING(scores_flags[ps_primary]);
254 vl = left.scores[ps_secondary];
255 vr = right.scores[ps_secondary];
256 if(scores_flags[ps_secondary] & SFL_ZERO_IS_WORST)
258 if(vl == 0 && vr != 0)
260 if(vl != 0 && vr == 0)
264 return IS_INCREASING(scores_flags[ps_secondary]);
266 return IS_DECREASING(scores_flags[ps_secondary]);
271 void Sbar_UpdatePlayerPos(entity player)
273 for(other = player.sort_next; other && Sbar_ComparePlayerScores(player, other); other = player.sort_next)
275 SORT_SWAP(player, other);
277 for(other = player.sort_prev; other != players && Sbar_ComparePlayerScores(other, player); other = player.sort_prev)
279 SORT_SWAP(other, player);
283 float Sbar_CompareTeamScores(entity left, entity right)
287 if(left.team == COLOR_SPECTATOR)
289 if(right.team == COLOR_SPECTATOR)
292 vl = left.teamscores[ts_primary];
293 vr = right.teamscores[ts_primary];
295 return IS_INCREASING(teamscores_flags[ts_primary]);
297 return IS_DECREASING(teamscores_flags[ts_primary]);
299 vl = left.teamscores[ts_secondary];
300 vr = right.teamscores[ts_secondary];
302 return IS_INCREASING(teamscores_flags[ts_secondary]);
304 return IS_DECREASING(teamscores_flags[ts_secondary]);
309 void Sbar_UpdateTeamPos(entity Team)
311 for(other = Team.sort_next; other && Sbar_CompareTeamScores(Team, other); other = Team.sort_next)
313 SORT_SWAP(Team, other);
315 for(other = Team.sort_prev; other != teams && Sbar_CompareTeamScores(other, Team); other = Team.sort_prev)
317 SORT_SWAP(other, Team);
321 void Cmd_Sbar_Help(float argc)
323 print("You can modify the scoreboard using the\n");
324 print("^3|---------------------------------------------------------------|\n");
325 print("^1 TO BE DONE\n");
327 print("^2sbar_columns_set default\n");
328 print("^2sbar_columns_set ^7filed1 field2 ...\n");
329 print("The following field names are recognized (case INsensitive):\n");
330 print("You can use a ^3|^7 to start the right-aligned fields.\n");
332 print("^3name^7 or ^3nick^7 Name of a player\n");
333 print("^3ping^7 Ping time\n\n");
334 print("^3kd^7 or ^3kdr^7 or ^3kdratio^7 or ^3k/d\n");
335 print(" The kill-death ratio\n");
337 print("Before a field you can put a + or - sign, then a comma separated list\n");
338 print("of game types, then a slash, to make the field show up only in these\n");
339 print("or in all but these game types.\n");
341 print("The special game type names 'teams' and 'noteams' can be used to\n");
342 print("include/exclude ALL teams/noteams game modes.\n");
345 print("Additional columns:\n");
346 for(i = 0; i < MAX_SCORE; ++i)
348 if(scores_label[i] != "")
349 print(strcat(scores_label[i], "\n"));
353 #define MIN_NAMELEN 24
354 #define MAX_NAMELEN 24
356 string Sbar_DefaultColumnLayout()
358 return strcat( // fteqcc sucks
360 "-teams,race,lms/kills -teams,lms/deaths -teams,lms,race/suicides -race,dm,tdm/frags ", // tdm already has this in "score"
361 "+ctf/caps +ctf/pickups +ctf/fckills +ctf/returns ",
362 "+lms/lives +lms/rank ",
363 "+kh/caps +kh/pushes +kh/destroyed ",
364 "?+race/laps ?+race/time ?+race/fastest ",
365 "+as/objectives +nexball/faults +nexball/goals ",
366 "-lms,race,nexball/score");
369 void Cmd_Sbar_SetFields(float argc)
374 float have_name, have_primary, have_secondary, have_separator;
377 // TODO: re enable with gametype dependant cvars?
378 if(argc < 2) // no arguments provided
379 argc = tokenizebyseparator(strcat("x ", cvar_string("sbar_columns")), " ");
382 argc = tokenizebyseparator(strcat("x ", Sbar_DefaultColumnLayout()), " ");
386 if(argv(1) == "default")
387 argc = tokenizebyseparator(strcat("x ", Sbar_DefaultColumnLayout()), " ");
388 else if(argv(1) == "all")
391 s = "ping pl color name |";
392 for(i = 0; i < MAX_SCORE; ++i)
395 if(i != ps_secondary)
396 if(scores_label[i] != "")
397 s = strcat(s, " ", scores_label[i]);
399 if(ps_secondary != ps_primary)
400 s = strcat(s, " ", scores_label[ps_secondary]);
401 s = strcat(s, " ", scores_label[ps_primary]);
402 argc = tokenizebyseparator(strcat("x ", s), " ");
409 drawfont = sbar_font;
410 digit = stringwidth("0123456789", FALSE) / 10;
412 for(i = 0; i < argc - 1; ++i)
418 if(substring(str, 0, 1) == "?")
421 str = substring(str, 1, strlen(str) - 1);
424 slash = strstrofs(str, "/", 0);
427 pattern = substring(str, 0, slash);
428 str = substring(str, slash + 1, strlen(str) - (slash + 1));
430 if not(isGametypeInFilter(gametype, teamplay, pattern))
434 strunzone(sbar_title[sbar_num_fields]);
435 sbar_title[sbar_num_fields] = strzone(str);
436 sbar_size[sbar_num_fields] = stringwidth(str, FALSE);
437 str = strtolower(str);
440 sbar_field[sbar_num_fields] = SP_PING;
441 } else if(str == "pl") {
442 sbar_field[sbar_num_fields] = SP_PL;
443 } else if(str == "kd" || str == "kdr" || str == "kdratio" || str == "k/d") {
444 sbar_field[sbar_num_fields] = SP_KDRATIO;
445 } else if(str == "name" || str == "nick") {
446 sbar_field[sbar_num_fields] = SP_NAME;
447 sbar_size[sbar_num_fields] = MIN_NAMELEN; // minimum size? any use?
449 } else if(str == "|") {
450 sbar_field[sbar_num_fields] = SP_SEPARATOR;
453 for(j = 0; j < MAX_SCORE; ++j)
454 if(str == strtolower(scores_label[j]))
455 goto found; // sorry, but otherwise fteqcc -O3 miscompiles this and warns about "unreachable code"
464 print(strcat("^1Error:^7 Unknown score field: '", str, "'\n"));
468 sbar_field[sbar_num_fields] = j;
471 if(j == ps_secondary)
475 if(sbar_num_fields >= MAX_SBAR_FIELDS)
479 if(scores_flags[ps_primary] & SFL_ALLOW_HIDE)
481 if(scores_flags[ps_secondary] & SFL_ALLOW_HIDE)
483 if(ps_primary == ps_secondary)
485 missing = !have_primary + !have_secondary + !have_separator + !have_name;
487 if(sbar_num_fields+missing < MAX_SBAR_FIELDS)
491 strunzone(sbar_title[sbar_num_fields]);
492 for(i = sbar_num_fields; i > 0; --i)
494 sbar_title[i] = sbar_title[i-1];
495 sbar_size[i] = sbar_size[i-1];
496 sbar_field[i] = sbar_field[i-1];
498 sbar_title[0] = strzone("name");
499 sbar_field[0] = SP_NAME;
500 sbar_size[0] = MIN_NAMELEN; // minimum size? any use?
502 print("fixed missing field 'name'\n");
506 strunzone(sbar_title[sbar_num_fields]);
507 for(i = sbar_num_fields; i > 1; --i)
509 sbar_title[i] = sbar_title[i-1];
510 sbar_size[i] = sbar_size[i-1];
511 sbar_field[i] = sbar_field[i-1];
513 sbar_title[1] = strzone("|");
514 sbar_field[1] = SP_SEPARATOR;
515 sbar_size[1] = stringwidth("|", FALSE);
517 print("fixed missing field '|'\n");
520 else if(!have_separator)
522 strunzone(sbar_title[sbar_num_fields]);
523 sbar_title[sbar_num_fields] = strzone("|");
524 sbar_size[sbar_num_fields] = stringwidth("|", FALSE);
525 sbar_field[sbar_num_fields] = SP_SEPARATOR;
527 print("fixed missing field '|'\n");
532 strunzone(sbar_title[sbar_num_fields]);
533 sbar_title[sbar_num_fields] = strzone(scores_label[ps_secondary]);
534 sbar_size[sbar_num_fields] = stringwidth(sbar_title[sbar_num_fields], FALSE);
535 sbar_field[sbar_num_fields] = ps_secondary;
537 print("fixed missing field '", scores_label[ps_secondary], "'\n");
542 strunzone(sbar_title[sbar_num_fields]);
543 sbar_title[sbar_num_fields] = strzone(scores_label[ps_primary]);
544 sbar_size[sbar_num_fields] = stringwidth(sbar_title[sbar_num_fields], FALSE);
545 sbar_field[sbar_num_fields] = ps_primary;
547 print("fixed missing field '", scores_label[ps_primary], "'\n");
551 sbar_field[sbar_num_fields] = SP_END;
555 vector sbar_field_rgb;
556 string sbar_field_icon0;
557 string sbar_field_icon1;
558 string sbar_field_icon2;
559 vector sbar_field_icon0_rgb;
560 vector sbar_field_icon1_rgb;
561 vector sbar_field_icon2_rgb;
562 float sbar_field_icon0_alpha;
563 float sbar_field_icon1_alpha;
564 float sbar_field_icon2_alpha;
565 string Sbar_GetField(entity pl, float field)
567 float tmp, num, denom, f;
569 sbar_field_rgb = '1 1 1';
570 sbar_field_icon0 = "";
571 sbar_field_icon1 = "";
572 sbar_field_icon2 = "";
573 sbar_field_icon0_rgb = '1 1 1';
574 sbar_field_icon1_rgb = '1 1 1';
575 sbar_field_icon2_rgb = '1 1 1';
576 sbar_field_icon0_alpha = 1;
577 sbar_field_icon1_alpha = 1;
578 sbar_field_icon2_alpha = 1;
583 return "\x8D\x8D\x8D"; // >>> sign
584 str = getplayerkey(pl.sv_entnum, "ping");
587 tmp = max(0, min(220, stof(str)-80)) / 220;
588 sbar_field_rgb = '1 1 1' - '0 1 1'*tmp;
594 str = getplayerkey(pl.sv_entnum, "pl");
597 tmp = bound(0, stof(str), 20) / 20; // 20% is REALLY BAD pl
598 sbar_field_rgb = '1 0.5 0.5' - '0 0.5 0.5'*tmp;
602 if(ready_waiting && pl.ready)
604 sbar_field_icon0 = "gfx/sb_player_ready";
608 f = stof(getplayerkey(pl.sv_entnum, "colors"));
610 sbar_field_icon0 = "gfx/sb_playercolor_base";
611 sbar_field_icon1 = "gfx/sb_playercolor_shirt";
612 sbar_field_icon1_rgb = colormapPaletteColor(floor(f / 16), 0);
613 sbar_field_icon2 = "gfx/sb_playercolor_pants";
614 sbar_field_icon2_rgb = colormapPaletteColor(mod(f, 16), 1);
617 return GetPlayerName(pl.sv_entnum);
620 f = pl.(scores[SP_KILLS]);
621 f -= pl.(scores[SP_SUICIDES]);
625 num = pl.(scores[SP_KILLS]);
626 denom = pl.(scores[SP_DEATHS]);
629 sbar_field_rgb = '0 1 0';
631 } else if(num <= 0) {
632 sbar_field_rgb = '1 0 0';
633 str = ftos(num/denom);
635 str = ftos(num/denom);
637 tmp = strstrofs(str, ".", 0);
639 str = substring(str, 0, tmp+2);
643 tmp = pl.(scores[field]);
644 f = scores_flags[field];
645 if(field == ps_primary)
646 sbar_field_rgb = '1 1 0';
647 else if(field == ps_secondary)
648 sbar_field_rgb = '0 1 1';
650 sbar_field_rgb = '1 1 1';
651 return ScoreString(f, tmp);
656 float xmin, xmax, ymin, ymax, sbwidth;
657 float sbar_fixscoreboardcolumnwidth_len;
658 float sbar_fixscoreboardcolumnwidth_iconlen;
659 float sbar_fixscoreboardcolumnwidth_marginlen;
661 float stringwidth_colors(string s)
663 return stringwidth(s, TRUE);
666 float stringwidth_nocolors(string s)
668 return stringwidth(s, FALSE);
671 string Sbar_FixScoreboardColumnWidth(float i, string str)
673 float field, maxsize, j, f;
675 field = sbar_field[i];
677 if(field == SP_NAME) // name gets all remaining space
679 maxsize = (xmax - xmin) / sbar_fontsize_x;
680 for(j = 0; j < sbar_num_fields; ++j) if(j != i) if(sbar_field[j] != SP_SEPARATOR)
681 maxsize -= sbar_size[j] + 1;
683 str = textShortenToWidth(str, maxsize, stringwidth_colors);
684 sbar_fixscoreboardcolumnwidth_len = stringwidth(str, TRUE);
687 sbar_fixscoreboardcolumnwidth_len = stringwidth(str, FALSE);
689 sbar_fixscoreboardcolumnwidth_iconlen = 0;
691 if(sbar_field_icon0 != "")
693 sz = drawgetimagesize(sbar_field_icon0);
695 if(sbar_fixscoreboardcolumnwidth_iconlen < f)
696 sbar_fixscoreboardcolumnwidth_iconlen = f;
699 if(sbar_field_icon1 != "")
701 sz = drawgetimagesize(sbar_field_icon1);
703 if(sbar_fixscoreboardcolumnwidth_iconlen < f)
704 sbar_fixscoreboardcolumnwidth_iconlen = f;
707 if(sbar_field_icon2 != "")
709 sz = drawgetimagesize(sbar_field_icon2);
711 if(sbar_fixscoreboardcolumnwidth_iconlen < f)
712 sbar_fixscoreboardcolumnwidth_iconlen = f;
715 sbar_fixscoreboardcolumnwidth_iconlen *= sbar_fontsize_y / sbar_fontsize_x; // fix icon aspect
717 if(sbar_fixscoreboardcolumnwidth_iconlen != 0 && sbar_fixscoreboardcolumnwidth_len != 0)
718 sbar_fixscoreboardcolumnwidth_marginlen = stringwidth(" ", FALSE);
720 sbar_fixscoreboardcolumnwidth_marginlen = 0;
722 f = sbar_fixscoreboardcolumnwidth_len + sbar_fixscoreboardcolumnwidth_marginlen + sbar_fixscoreboardcolumnwidth_iconlen;
729 void Sbar_PrintScoreboardItem(vector pos, entity pl, float is_self)
735 is_spec = (GetPlayerColor(pl.sv_entnum) == COLOR_SPECTATOR);
742 tmp_y = sbar_fontsize_y;
743 drawfill(pos - '1 1 0', tmp + '2 2 0', '1 1 1', 0.3, DRAWFLAG_NORMAL);
747 for(i = 0; i < sbar_num_fields; ++i)
749 field = sbar_field[i];
750 if(field == SP_SEPARATOR)
753 if(is_spec && field != SP_NAME && field != SP_PING) {
754 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
757 str = Sbar_GetField(pl, field);
758 str = Sbar_FixScoreboardColumnWidth(i, str);
760 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
762 if(field == SP_NAME) {
763 tmp_x = sbar_fontsize_x*(sbar_size[i] - sbar_fixscoreboardcolumnwidth_iconlen - sbar_fixscoreboardcolumnwidth_marginlen) + sbar_fontsize_x;
764 drawcolorcodedstring(pos - tmp, str, sbar_fontsize, 1, DRAWFLAG_NORMAL);
766 tmp_x = sbar_fixscoreboardcolumnwidth_len*sbar_fontsize_x + sbar_fontsize_x;
767 drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, 1, DRAWFLAG_NORMAL);
770 tmp_x = sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
771 if(sbar_field_icon0 != "")
772 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);
773 if(sbar_field_icon1 != "")
774 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);
775 if(sbar_field_icon2 != "")
776 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);
779 if(sbar_field[i] == SP_SEPARATOR)
782 for(i = sbar_num_fields-1; i > 0; --i)
784 field = sbar_field[i];
785 if(field == SP_SEPARATOR)
788 if(is_spec && field != SP_NAME && field != SP_PING) {
789 pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
793 str = Sbar_GetField(pl, field);
794 str = Sbar_FixScoreboardColumnWidth(i, str);
796 if(field == SP_NAME) {
797 tmp_x = sbar_fontsize_x*sbar_fixscoreboardcolumnwidth_len; // left or right aligned? let's put it right...
798 drawcolorcodedstring(pos - tmp, str, sbar_fontsize, 1, DRAWFLAG_NORMAL);
800 tmp_x = sbar_fontsize_x*sbar_fixscoreboardcolumnwidth_len; //strlen(str);
801 drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, 1, DRAWFLAG_NORMAL);
804 tmp_x = sbar_fontsize_x*sbar_size[i];
805 if(sbar_field_icon0 != "")
806 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);
807 if(sbar_field_icon1 != "")
808 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);
809 if(sbar_field_icon2 != "")
810 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);
812 pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
818 float scoreboard_bottom;
819 void Sbar_DrawScoreboard()
821 //float xmin, ymin, xmax, ymax;
822 vector rgb, pos, tmp, sbar_save;
827 if(time > lastpingstime + 10)
830 lastpingstime = time;
833 sbwidth = Sbar_GetWidth(6.5 * sbar_fontsize_y);
835 xmin = 0.5 * (vid_conwidth - sbwidth);
838 xmax = vid_conwidth - xmin;
839 ymax = vid_conheight - 0.2*vid_conheight;
841 center_x = xmin + 0.5*sbwidth;
843 //Sbar_UpdateFields();
845 // Initializes position
851 drawfont = sbar_bigfont;
852 pos_x = center_x - stringwidth("Scoreboard", TRUE)*0.5*24;
853 drawstring(pos, "Scoreboard", '24 24 0', '1 1 1', 1, DRAWFLAG_NORMAL);
857 // Titlebar background:
859 tmp_y = sbar_fontsize_y;
860 drawfill(pos - '1 1 0', tmp + '2 2 0', '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
862 drawfont = sbar_font;
864 for(i = 0; i < sbar_num_fields; ++i)
866 if(sbar_field[i] == SP_SEPARATOR)
868 drawstring(pos, sbar_title[i], sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
869 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
872 if(sbar_field[i] == SP_SEPARATOR)
874 pos_x = xmax + sbar_fontsize_x;
876 for(i = sbar_num_fields-1; i > 0; --i)
878 if(sbar_field[i] == SP_SEPARATOR)
881 pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
884 * Using the following line will mess it all up:
886 * tmp_x = sbar_size[i] - strlen(sbar_title[i])*8;
888 tmp_x = sbar_fontsize_x*sbar_size[i];
889 tmp_x -= stringwidth(sbar_title[i], FALSE)*sbar_fontsize_x;
890 drawstring(pos + tmp, sbar_title[i], sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
895 pos_y += 1.5 * sbar_fontsize_y;
902 //for(tm = sortedTeams.sort_next; tm; tm = tm.sort_next)
903 for(tm = teams.sort_next; tm; tm = tm.sort_next)
905 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
908 rgb = GetTeamRGB(tm.team);
913 pos - '6.5 0 0' * sbar_fontsize_y,
914 tm.(teamscores[ts_primary]),
915 4, sbar_fontsize_y * 1.5, rgb, 1, DRAWFLAG_NORMAL);
917 if(ts_primary != ts_secondary)
919 pos - '4.5 0 0' * sbar_fontsize_y + '0 1.5 0' * sbar_fontsize_y,
920 tm.(teamscores[ts_secondary]),
921 4, sbar_fontsize_y * 1, rgb, 1, DRAWFLAG_NORMAL);
923 specs = tm.team_size;
929 tmp_y = 1.25 * sbar_fontsize_y * specs;
930 drawfill(pos - '1 1 0', tmp + '2 0 0', rgb, 0.2, DRAWFLAG_NORMAL);
932 for(pl = players.sort_next; pl; pl = pl.sort_next)
934 if(pl.team != tm.team)
936 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
937 pos_y += 1.25 * sbar_fontsize_y;
938 tmp_y -= 1.25 * sbar_fontsize_y;
940 pos_y += tmp_y + 1.5 * sbar_fontsize_y;
942 // rgb := tempvector :)
943 rgb = pos + '0 1.5 0' * sbar_fontsize_y;
944 pos_y += 3 * sbar_fontsize_y;
946 for(pl = players.sort_next; pl; pl = pl.sort_next)
948 if(pl.team != COLOR_SPECTATOR)
950 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
951 pos += '0 1.25 0' * sbar_fontsize_y;
956 drawstring(rgb, "Spectators", sbar_fontsize, '1 1 1', 1, 0);
959 for(pl = players.sort_next; pl; pl = pl.sort_next)
961 if(pl.team == COLOR_SPECTATOR)
963 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
964 pos_y += 1.25 * sbar_fontsize_y;
965 tmp_y -= 1.25 * sbar_fontsize_y;
968 // rgb := tempvector :)
969 rgb = pos + '0 1.5 0' * sbar_fontsize_y;
970 pos_y += 3 * sbar_fontsize_y;
972 for(pl = players.sort_next; pl; pl = pl.sort_next)
974 if(pl.team != COLOR_SPECTATOR)
976 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
977 pos += '0 1.25 0' * sbar_fontsize_y;
982 drawstring(rgb, "Spectators", sbar_fontsize, '1 1 1', 1, 0);
987 str = strcat("playing on ^2", shortmapname, "^7");
988 tl = getstatf(STAT_TIMELIMIT);
989 fl = getstatf(STAT_FRAGLIMIT);
990 if(gametype == GAME_LMS)
993 str = strcat(str, " for up to ^1", ftos(tl), " minutes^7");
998 str = strcat(str, " for ^1", ftos(tl), " minutes^7");
1002 str = strcat(str, " or");
1005 str = strcat(str, " until ^3", ScoreString(teamscores_flags[ts_primary], fl));
1006 if(teamscores_label[ts_primary] == "score")
1007 str = strcat(str, " points^7");
1008 else if(teamscores_label[ts_primary] == "fastest")
1009 str = strcat(str, " is beaten^7");
1011 str = strcat(str, " ", teamscores_label[ts_primary]);
1015 str = strcat(str, " until ^3", ScoreString(scores_flags[ps_primary], fl));
1016 if(scores_label[ps_primary] == "score")
1017 str = strcat(str, " points^7");
1018 else if(scores_label[ps_primary] == "fastest")
1019 str = strcat(str, " is beaten^7");
1021 str = strcat(str, " ", scores_label[ps_primary]);
1027 pos_y += 1.2 * sbar_fontsize_y;
1028 drawcolorcodedstring(pos + '0.5 0 0' * (sbwidth - sbar_fontsize_x * stringwidth(str, TRUE)), str, sbar_fontsize, 0.8, 0);
1031 scoreboard_bottom = pos_y + 2 * sbar_fontsize_y;
1034 string MakeRaceString(float cp, float mytime, float histime, float lapdelta, string hisname)
1042 if(histime == 0) // goal hit
1046 timestr = strcat("+", ftos_decimals(+mytime, 1));
1049 else if(mytime == 0)
1056 timestr = strcat("-", ftos_decimals(-mytime, 1));
1062 lapstr = strcat(" (-", ftos(lapdelta), "L)");
1065 else if(lapdelta < 0)
1067 lapstr = strcat(" (+", ftos(-lapdelta), "L)");
1071 else if(histime > 0) // anticipation
1073 if(mytime >= histime)
1074 timestr = strcat("+", ftos_decimals(mytime - histime, 1));
1076 timestr = mmsss(histime * 10);
1083 cpname = strcat("Intermediate ", ftos(cp));
1085 cpname = "Finish line";
1088 return strcat(col, cpname);
1089 else if(hisname == "")
1090 return strcat(col, cpname, " (", timestr, ")");
1092 return strcat(col, cpname, " (", timestr, " ", strcat(hisname, col, lapstr), ")");
1095 void Sbar_Score(float margin)
1097 float timelimit, minutes, seconds, timeleft, minutesLeft, secondsLeft, distribution, myplace, score;
1098 vector sbar_save, place, timer_color;
1102 myteam = GetPlayerColor(player_localentnum - 1);
1104 sbar_y = vid_conheight - (32+12);
1107 place = '-48 -12 0';
1112 // team1 team3 team4
1115 //for(i = 0; i < 4; ++i)
1116 for(tm = teams.sort_next; tm; tm = tm.sort_next)
1118 if(tm.team == COLOR_SPECTATOR || !tm.team_size) // no players? don't display
1121 score = tm.(teamscores[ts_primary]);
1122 if(tm.team == myteam)
1123 Sbar_DrawXNum('-128 0 0', score, 4, 32, GetTeamRGB(tm.team), 1, DRAWFLAG_NORMAL);
1126 Sbar_DrawXNum(place, score, 4, 12, GetTeamRGB(tm.team), 1, DRAWFLAG_NORMAL);
1131 // me vector := [team/connected frags id]
1133 for(me = players.sort_next; me; me = me.sort_next)
1135 if(me.team != COLOR_SPECTATOR)
1137 if(me.sv_entnum == player_localentnum - 1)
1140 pl = players.sort_next;
1145 distribution = me.(scores[ps_primary]);
1146 distribution -= pl.(scores[ps_primary]);
1151 Sbar_DrawXNum('-36 -12 0', myplace, 3, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
1152 else if(myplace == 2)
1153 Sbar_DrawXNum('-36 -12 0', myplace, 3, 12, '1 1 0', 1, DRAWFLAG_NORMAL);
1155 Sbar_DrawXNum('-36 -12 0', myplace, 3, 12, '1 0 0', 1, DRAWFLAG_NORMAL);
1157 score = me.(scores[ps_primary]);
1158 if(distribution >= 0)
1160 Sbar_DrawXNum('-84 -12 0', distribution, 4, 12, ' 1 1 1', 1, DRAWFLAG_NORMAL);
1161 Sbar_DrawXNum('-128 0 0', score, 4, 32, '1 1 1', 1, DRAWFLAG_NORMAL);
1162 } else if(distribution >= -5)
1164 Sbar_DrawXNum('-84 -12 0', distribution, 4, 12, ' 1 1 0', 1, DRAWFLAG_NORMAL);
1165 Sbar_DrawXNum('-128 0 0', score, 4, 32, '1 1 0', 1, DRAWFLAG_NORMAL);
1167 Sbar_DrawXNum('-84 -12 0', distribution, 4, 12, ' 1 0 0', 1, DRAWFLAG_NORMAL);
1168 Sbar_DrawXNum('-128 0 0', score, 4, 32, '1 0 0', 1, DRAWFLAG_NORMAL);
1172 //draw the remaining or elapsed time
1173 timelimit = getstatf(STAT_TIMELIMIT);
1176 timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
1177 timeleft = ceil(timeleft);
1178 minutesLeft = floor(timeleft / 60);
1179 secondsLeft = timeleft - minutesLeft*60;
1181 if(minutesLeft >= 5) {
1182 timer_color = '1 1 1'; //white
1183 } else if(minutesLeft >= 1) {
1184 timer_color = '1 1 0'; //yellow
1186 timer_color = '1 0 0'; //red
1190 timer_color = '1 1 1'; //don't use red or yellow for timer during warmup
1193 if (cvar("sbar_increment_maptime")) {
1194 if (time < getstatf(STAT_GAMESTARTTIME)) {
1195 //while restart is still active, show negative counter
1197 seconds = ceil(getstatf(STAT_GAMESTARTTIME) - time);
1200 elapsedTime = floor(time - getstatf(STAT_GAMESTARTTIME)); //127
1201 minutes = floor(elapsedTime / 60);
1202 seconds = elapsedTime - minutes*60;
1205 minutes = minutesLeft;
1206 seconds = secondsLeft;
1209 if(minutesLeft >= 1 || (cvar("sbar_increment_maptime") && minutes >= 1) ) {
1210 Sbar_DrawXNum('-72 32 0', minutes, 3, 12, timer_color, 1, DRAWFLAG_NORMAL);
1211 drawpic(sbar + '-36 32 0', "gfx/num_colon", '12 12 0', timer_color, sbar_alpha_fg, 0);
1213 Sbar_DrawXNum('-24 32 0', seconds, -2, 12, timer_color, 1, DRAWFLAG_NORMAL);
1215 timer_color = '1 1 1'; //white
1216 minutes = floor(time / 60);
1217 seconds = floor(time - minutes*60);
1218 Sbar_DrawXNum('-72 32 0', minutes, 3, 12, timer_color, 1, DRAWFLAG_NORMAL);
1219 drawpic(sbar + '-36 32 0', "gfx/num_colon", '12 12 0', timer_color, sbar_alpha_fg, 0);
1220 Sbar_DrawXNum('-24 32 0', seconds, -2, 12, timer_color, 1, DRAWFLAG_NORMAL);
1223 if(gametype == GAME_RACE)
1225 drawfont = sbar_bigfont;
1228 string s, forcetime;
1230 m = '0.5 0 0' * vid_conwidth + '0 0.25 0' * vid_conheight;
1232 if(race_checkpointtime)
1234 a = bound(0, 2 - (time - race_checkpointtime), 1);
1237 if(a > 0) // just hit a checkpoint?
1239 if(race_time && race_previousbesttime)
1240 s = MakeRaceString(race_checkpoint, race_time / 10 - race_previousbesttime / 10, 0, 0, race_previousbestname);
1242 s = MakeRaceString(race_checkpoint, 0, -1, 0, race_previousbestname);
1244 forcetime = mmsss(race_time);
1248 if(race_laptime && race_nextbesttime)
1250 a = bound(0, 2 - ((race_laptime + race_nextbesttime/10) - time), 1);
1251 if(a > 0) // next one?
1253 s = MakeRaceString(race_nextcheckpoint, time - race_laptime, race_nextbesttime / 10, 0, race_nextbestname);
1258 if(s != "" && a > 0)
1260 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
1261 drawcolorcodedstring(m - '0 16 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', sbar_alpha_fg * a, 0);
1266 a = bound(0, (time - race_checkpointtime) / 0.5, 1);
1267 drawstring_expanding(m - '16 0 0' * stringwidth(forcetime, FALSE), forcetime, '32 32 0', '1 1 1', sbar_alpha_fg, 0, a);
1274 s = mmsss(10*(time - race_laptime));
1275 drawstring(m - '16 0 0' * stringwidth(s, FALSE), s, '32 32 0', '1 1 1', sbar_alpha_fg * a, 0);
1280 if(race_mycheckpointtime)
1282 a = bound(0, 2 - (time - race_mycheckpointtime), 1);
1283 s = MakeRaceString(race_mycheckpoint, race_mycheckpointdelta / 10, -!race_mycheckpointenemy, race_mycheckpointlapsdelta, race_mycheckpointenemy);
1284 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
1285 drawcolorcodedstring(m - '0 16 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', sbar_alpha_fg * a, 0);
1287 if(race_othercheckpointtime && race_othercheckpointenemy != "")
1289 a = bound(0, 2 - (time - race_othercheckpointtime), 1);
1290 s = MakeRaceString(race_othercheckpoint, -race_othercheckpointdelta / 10, -!race_othercheckpointenemy, race_othercheckpointlapsdelta, race_othercheckpointenemy);
1291 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
1292 drawcolorcodedstring(m - '0 0 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', sbar_alpha_fg * a, 0);
1296 drawfont = sbar_font;
1302 void Sbar_MiniscoreItem(vector pos, entity pl, float is_self)
1308 drawfill(pos + '0 1 0', '40 6 0', GetTeamRGB(pl.team)*0.5, 1, DRAWFLAG_NORMAL);
1310 drawfill(pos + '0 1 0', '40 6 0', '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
1313 score = pl.(scores[ps_primary]);
1314 pos_x -= stringwidth(ftos(score), FALSE)*8;
1315 drawstring(pos, ftos(score), '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1320 drawstring(pos, "\x0D", '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1324 drawcolorcodedstring(pos, GetPlayerName(pl.sv_entnum), '8 8 0', 1, 0);
1327 void Sbar_MiniscoreTeamItem(vector pos, float color, float frags, float is_self)
1333 drawfill(pos + '0 1 0', '40 6 0', GetTeamRGB(color)*0.5, 1, DRAWFLAG_NORMAL);
1335 drawfill(pos + '0 1 0', '40 6 0', '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
1338 pos_x -= stringwidth(ftos(frags), FALSE)*8;
1339 drawstring(pos, ftos(frags), '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1344 drawstring(pos, "\x0D", '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1348 drawstring(pos, GetTeamName(color), '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1351 void Sbar_MiniDeathmatchOverlay(vector pos)
1353 float numlines, up, down, score;
1355 float miniscoreboard_size;
1356 miniscoreboard_size = cvar("sbar_miniscoreboard_size");
1358 if(miniscoreboard_size == 0)
1360 pos_y = vid_conheight - 8;
1362 if(miniscoreboard_size < 0)
1363 numlines = (vid_conheight - sbar_y + 7) / 8;
1365 numlines = miniscoreboard_size;
1367 // give up if there isn't enough room
1368 if(pos_x >= vid_conwidth || pos_y >= vid_conheight || numlines < 1)
1371 // me vector := [team/connected frags id]
1372 for(me = players.sort_next; me; me = me.sort_next)
1374 if(me.sv_entnum == player_localentnum - 1)
1379 numlines -= numteams;
1381 // figure out how many players above and below we can show
1382 up = floor(numlines/2);
1384 if((up + down) > numlines)
1385 down = numlines - up;
1388 for(pl = me.sort_next; pl && down > 0; pl = pl.sort_next)
1390 if(pl.team == COLOR_SPECTATOR)
1392 Sbar_MiniscoreItem(pos, pl, false);
1396 Sbar_MiniscoreItem(pos, me, true);
1398 up += down; // if there weren't enough lines below... add them
1399 for(pl = me.sort_prev; pl && up > 0; pl = pl.sort_prev)
1401 if(pl.team == COLOR_SPECTATOR)
1403 Sbar_MiniscoreItem(pos, pl, false);
1410 for(tm = teams.sort_next; tm.sort_next; tm = tm.sort_next);
1411 for(; tm; tm = tm.sort_prev)
1413 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
1415 score = tm.(teamscores[ts_primary]);
1416 Sbar_MiniscoreTeamItem(pos, tm.team, score, (tm.team == me.team));
1422 float Sbar_WouldDrawScoreboard ()
1426 else if (intermission == 1)
1428 else if (intermission == 2)
1430 else if (getstati(STAT_HEALTH) <= 0 && cvar("cl_deathscoreboard"))
1432 else if(sb_showscores_force)
1437 void CSQC_Strength_Timer() {
1438 float stat_items, dt;
1439 stat_items = getstati(STAT_ITEMS);
1441 if not(stat_items & IT_STRENGTH)
1442 if not(stat_items & IT_INVINCIBLE)
1446 if (getstati(STAT_HEALTH) <= 0)
1449 vector pos, picsize, number_position;
1450 float strength_time, invincibility_time, countdown_fontsize;
1452 picsize = '40 40 0';
1453 countdown_fontsize = 22;
1455 //element will be positioned on the right side of the screen:
1456 pos_x = vid_conwidth - picsize_x - 10; //margin 10 from right border
1457 number_position_x = pos_x - 5/*margin to the left from image*/ - countdown_fontsize*2/*width of text*/;
1460 number_position_y = pos_y;
1462 //now calculate the values Sbar_DrawXNum() will be called with:
1463 number_position_x = number_position_x - sbar_x; //relative to sbar coordinates
1464 number_position_y = number_position_y - sbar_y; //relative to sbar coordinates
1465 number_position_y += 10; //center number vertically to the icon
1467 pos_z = number_position_z = 0;
1470 strength_time = getstatf(STAT_STRENGTH_FINISHED);
1471 invincibility_time = getstatf(STAT_INVINCIBLE_FINISHED);
1473 if (strength_time) {
1474 dt = strength_time - time;
1479 drawpic_expanding_two(pos, "gfx/sb_str", picsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE,
1480 bound(0, (ceil(dt) - dt) / 0.5, 1));
1484 drawpic(pos, "gfx/sb_str", picsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE);
1486 Sbar_DrawXNum(number_position, ceil(dt), 2, countdown_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
1490 drawpic_expanding(pos, "gfx/sb_str", picsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE,
1491 bound(0, -dt / 0.5, 1));
1495 //add some margin to the invincibility icon
1496 pos_y += picsize_y + 10;
1497 number_position_y += picsize_y + 10;
1500 if (invincibility_time) {
1501 dt = invincibility_time - time;
1506 drawpic_expanding_two(pos, "gfx/sb_invinc", picsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE,
1507 bound(0, (ceil(dt) - dt) / 0.5, 1));
1511 drawpic(pos, "gfx/sb_invinc", picsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE);
1513 Sbar_DrawXNum(number_position, ceil(dt), 2, countdown_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
1517 drawpic_expanding(pos, "gfx/sb_invinc", picsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE,
1518 bound(0, -dt / 0.5, 1));
1523 #define CENTERPRINT_MAX_LINES 30
1524 string centerprint_messages[CENTERPRINT_MAX_LINES];
1525 float centerprint_width[CENTERPRINT_MAX_LINES];
1526 vector centerprint_start;
1527 float centerprint_expire;
1528 float centerprint_num;
1529 float centerprint_offset_hint;
1530 vector centerprint_fontsize;
1532 void centerprint(string strMessage)
1534 float i, j, n, hcount;
1537 centerprint_fontsize = Sbar_GetFontsize("scr_centersize");
1539 centerprint_expire = min(centerprint_expire, time); // if any of the returns happens, this message will fade out
1541 if(cvar("scr_centertime") <= 0)
1544 if(strMessage == "")
1547 // strip trailing newlines
1548 j = strlen(strMessage) - 1;
1549 while(substring(strMessage, j, 1) == "\n" && j >= 0)
1551 strMessage = substring(strMessage, 0, j + 1);
1553 if(strMessage == "")
1556 // strip leading newlines and remember them, they are a hint that the message should be lower on the screen
1558 while(substring(strMessage, j, 1) == "\n" && j < strlen(strMessage))
1560 strMessage = substring(strMessage, j, strlen(strMessage) - j);
1561 centerprint_offset_hint = j;
1563 if(strMessage == "")
1566 // if we get here, we have a message. Initialize its height.
1567 centerprint_num = 0;
1569 n = tokenizebyseparator(strMessage, "\n");
1571 for(j = 0; j < n; ++j)
1573 getWrappedLine_remaining = argv(j);
1574 while(getWrappedLine_remaining)
1576 s = getWrappedLine(vid_conwidth * 0.75 / centerprint_fontsize_x, stringwidth_colors);
1577 if(centerprint_messages[i])
1578 strunzone(centerprint_messages[i]);
1579 centerprint_messages[i] = strzone(s);
1580 centerprint_width[i] = stringwidth(s, TRUE);
1583 // half height for empty lines looks better
1589 if(i >= CENTERPRINT_MAX_LINES)
1595 h = centerprint_fontsize_y*hcount;
1597 havail = vid_conheight;
1598 if(cvar("con_chatpos") < 0)
1599 havail -= (-cvar("con_chatpos") + cvar("con_chat")) * cvar("con_chatsize"); // avoid overlapping chat
1601 centerprint_start_x = 0;
1604 float forbiddenmin, forbiddenmax, allowedmin, allowedmax, preferred;
1606 // here, the centerprint would cover the crosshair. REALLY BAD.
1607 forbiddenmin = vid_conheight * 0.5 - h - 16;
1608 forbiddenmax = vid_conheight * 0.5 + 16;
1610 allowedmin = scoreboard_bottom;
1611 allowedmax = havail - h;
1612 preferred = (havail - h)/2;
1615 // possible orderings (total: 4! / 4 = 6)
1616 // allowedmin allowedmax forbiddenmin forbiddenmax
1617 // forbiddenmin forbiddenmax allowedmin allowedmax
1618 if(allowedmax < forbiddenmin || allowedmin > forbiddenmax)
1620 // forbidden doesn't matter in this case
1621 centerprint_start_y = bound(allowedmin, preferred, allowedmax);
1623 // allowedmin forbiddenmin allowedmax forbiddenmax
1624 else if(allowedmin < forbiddenmin && allowedmax < forbiddenmax)
1626 centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
1628 // allowedmin forbiddenmin forbiddenmax allowedmax
1629 else if(allowedmin < forbiddenmin)
1631 // make sure the forbidden zone is not covered
1632 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
1633 centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
1635 centerprint_start_y = bound(forbiddenmax, preferred, allowedmin);
1637 // forbiddenmin allowedmin allowedmax forbiddenmax
1638 else if(allowedmax < forbiddenmax)
1640 // it's better to leave the allowed zone (overlap with scoreboard) than
1641 // to cover the forbidden zone (crosshair)
1642 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
1643 centerprint_start_y = forbiddenmax;
1645 centerprint_start_y = forbiddenmin;
1647 // forbiddenmin allowedmin forbiddenmax allowedmax
1650 centerprint_start_y = bound(forbiddenmax, preferred, allowedmax);
1653 centerprint_start_y =
1656 max(scoreboard_bottom, vid_conheight * 0.5 + 16),
1663 centerprint_num = i;
1664 centerprint_expire = time + cvar("scr_centertime");
1667 void Sbar_DrawCenterPrint (void)
1674 //if(time > centerprint_expire)
1677 //a = bound(0, 1 - 2 * (time - centerprint_expire), 1);
1678 a = bound(0, 1 - 4 * (time - centerprint_expire), 1);
1679 //sz = 1.2 / (a + 0.2);
1684 pos = centerprint_start;
1685 for (i=0; i<centerprint_num; i = i + 1)
1687 pos_x = (vid_conwidth - centerprint_fontsize_x * centerprint_width[i]) * 0.5;
1688 ts = centerprint_messages[i];
1691 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
1692 drawcolorcodedstring(pos, ts, centerprint_fontsize, a, DRAWFLAG_NORMAL);
1693 // - '0 0.5 0' * (sz - 1) * centerprint_fontsize_x - '0.5 0 0' * (sz - 1) * centerprint_width[i] * centerprint_fontsize_y, centerprint_fontsize * sz
1694 pos_y = pos_y + centerprint_fontsize_y;
1697 // half height for empty lines looks better
1698 pos_y = pos_y + centerprint_fontsize_y * 0.5;
1702 vector Sbar_DrawNoteLine(vector offset, string s)
1704 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
1705 drawcolorcodedstring(
1706 offset - sbar_fontsize_x * '1 0 0' * stringwidth(s, TRUE),
1712 return offset + sbar_fontsize_y * '0 1 0';
1715 void Sbar_DrawPressedKeys(void)
1720 pos = stov(cvar_string("cl_showpressedkeys_position"));
1722 bgsize = '126 75 0';
1724 pos = '1 0 0' * (vid_conwidth - bgsize_x) * pos_x
1725 + '0 1 0' * (vid_conheight - bgsize_y) * pos_y;
1726 pos -= '-15 -6 0'; // adjust to the origin of these numbers
1728 pressedkeys = getstatf(STAT_PRESSED_KEYS);
1729 drawpic(pos + '-15 -6 0', "gfx/keys/key_bg.tga", bgsize, '1 1 1', .1, DRAWFLAG_NORMAL);
1730 drawpic(pos + ' 83.5 9 0', "gfx/keys/key_crouch.tga", ' 24 24 0', '1 1 1', .5 * ((pressedkeys & KEY_CROUCH) + 1), DRAWFLAG_NORMAL);
1731 drawpic(pos + ' 32 -1.5 0', "gfx/keys/key_forward.tga", ' 32 32 0', '1 1 1', .5 * ((pressedkeys & KEY_FORWARD) + 1), DRAWFLAG_NORMAL);
1732 drawpic(pos + '-11.5 9 0', "gfx/keys/key_jump.tga", ' 24 24 0', '1 1 1', .5 * ((pressedkeys & KEY_JUMP) + 1), DRAWFLAG_NORMAL);
1733 drawpic(pos + ' -1 32 0', "gfx/keys/key_left.tga", ' 32 32 0', '1 1 1', .5 * ((pressedkeys & KEY_LEFT) + 1), DRAWFLAG_NORMAL);
1734 drawpic(pos + ' 32 32 0', "gfx/keys/key_backward.tga", ' 32 32 0', '1 1 1', .5 * ((pressedkeys & KEY_BACKWARD) + 1), DRAWFLAG_NORMAL);
1735 drawpic(pos + ' 65 32 0', "gfx/keys/key_right.tga", ' 32 32 0', '1 1 1', .5 * ((pressedkeys & KEY_RIGHT) + 1), DRAWFLAG_NORMAL);
1738 float GetAmmoStat(float i)
1742 case 0: return STAT_SHELLS;
1743 case 1: return STAT_NAILS;
1744 case 2: return STAT_ROCKETS;
1745 case 3: return STAT_CELLS;
1746 case 4: return STAT_FUEL;
1751 float GetAmmoItemCode(float i)
1755 case 0: return IT_SHELLS;
1756 case 1: return IT_NAILS;
1757 case 2: return IT_ROCKETS;
1758 case 3: return IT_CELLS;
1759 case 4: return IT_FUEL;
1764 string GetAmmoPicture(float i)
1768 case 0: return "gfx/sb_shells";
1769 case 1: return "gfx/sb_bullets";
1770 case 2: return "gfx/sb_rocket";
1771 case 3: return "gfx/sb_cells";
1772 case 4: return "gfx/sb_fuel";
1777 void Sbar_Draw (void)
1781 float stat_items, stat_weapons;
1782 vector o; o = '1 0 0' * vid_conwidth;
1786 sbar_fontsize = Sbar_GetFontsize("sbar_fontsize");
1788 if(spectatee_status && !intermission)
1790 if(spectatee_status == -1)
1793 s = strcat("^1Spectating ^7", GetPlayerName(spectatee_status - 1));
1794 o = Sbar_DrawNoteLine(o, s);
1796 if(spectatee_status == -1)
1797 s = strcat("^1Press ^3", getcommandkey("primary fire", "+attack"), "^1 to spectate");
1799 s = strcat("^1Press ^3", getcommandkey("primary fire", "+attack"), "^1 for another player");
1800 o = Sbar_DrawNoteLine(o, s);
1802 if(spectatee_status == -1)
1803 s = strcat("^1Use ^3", getcommandkey("next weapon", "weapnext"), "^1 or ^3", getcommandkey("previous weapon", "weapprev"), "^1 to change the speed");
1805 s = strcat("^1Press ^3", getcommandkey("secondary fire", "+attack2"), "^1 to observe");
1806 o = Sbar_DrawNoteLine(o, s);
1808 s = strcat("^1Press ^3", getcommandkey("server info", "+show_info"), "^1 for gamemode info");
1809 o = Sbar_DrawNoteLine(o, s);
1811 if(gametype == GAME_ARENA)
1812 s = "^1Wait for your turn to join";
1813 else if(gametype == GAME_LMS)
1816 sk = playerslots[player_localentnum - 1];
1817 if(sk.(scores[ps_primary]) >= 666)
1818 s = "^1Match has already begun";
1819 else if(sk.(scores[ps_primary]) > 0)
1820 s = "^1You have no more lives left";
1822 s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
1825 s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
1826 o = Sbar_DrawNoteLine(o, s);
1828 //show restart countdown:
1829 if (time < getstatf(STAT_GAMESTARTTIME)) {
1831 //we need to ceil, otherwise the countdown would be off by .5 when using round()
1832 countdown = ceil(getstatf(STAT_GAMESTARTTIME) - time);
1833 s = strcat("^1Game starts in ^3", ftos(countdown), "^1 seconds");
1834 o = Sbar_DrawNoteLine(o, s);
1837 if(warmup_stage && !intermission)
1839 s = "^2Currently in ^1warmup^2 stage!";
1840 o = Sbar_DrawNoteLine(o, s);
1843 // move more important stuff more to the middle so its more visible
1844 o_y = vid_conheight * 0.66;
1847 if(mod(time, 1) >= 0.5)
1852 if(ready_waiting && !intermission)
1854 if(ready_waiting_for_me)
1857 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " to end warmup");
1859 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " once you are ready");
1864 s = strcat("^2Waiting for others to ready up to end warmup...");
1866 s = strcat("^2Waiting for others to ready up...");
1868 o = Sbar_DrawNoteLine(o, s);
1870 else if(warmup_stage && !intermission)
1872 s = strcat("^2Press ^3", getcommandkey("ready", "ready"), "^2 to end warmup");
1873 o = Sbar_DrawNoteLine(o, s);
1877 s = strcat("^2A vote has been called for ^1", vote_called_vote);
1878 o = Sbar_DrawNoteLine(o, s);
1880 if(vote_waiting_for_me)
1882 s = strcat(blinkcolor, "Press ^3", getcommandkey("vote yes", "vyes"), blinkcolor, " to accept");
1883 o = Sbar_DrawNoteLine(o, s);
1885 s = strcat(blinkcolor, "Press ^3", getcommandkey("vote no", "vno"), blinkcolor, " to reject");
1886 o = Sbar_DrawNoteLine(o, s);
1888 s = strcat(blinkcolor, "Press ^3", getcommandkey("vote abstain", "vabstain"), blinkcolor, " to abstain");
1889 o = Sbar_DrawNoteLine(o, s);
1893 s = strcat("^2Waiting for others to vote...");
1894 o = Sbar_DrawNoteLine(o, s);
1897 if(teamplay && !intermission)
1900 float ts_min, ts_max;
1901 tm = teams.sort_next;
1904 for(; tm.sort_next; tm = tm.sort_next)
1906 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
1908 if(!ts_min) ts_min = tm.team_size;
1909 else ts_min = min(ts_min, tm.team_size);
1910 if(!ts_max) ts_max = tm.team_size;
1911 else ts_max = max(ts_max, tm.team_size);
1913 if ((ts_max - ts_min) > 1)
1915 s = strcat(blinkcolor, "Teamnumbers are unbalanced!");
1916 tm = GetTeam(myteam, false);
1918 if (tm.team != COLOR_SPECTATOR)
1919 if (tm.team_size == ts_max)
1920 s = strcat(s, " Press ^3", getcommandkey("team menu", "menu_showteamselect"), blinkcolor, " to adjust");
1922 o = Sbar_DrawNoteLine(o, s);
1928 Sbar_UpdatePlayerTeams();
1934 Sbar_DrawScoreboard();
1935 Sbar_DrawCenterPrint();
1937 else if (intermission == 1)
1939 Sbar_DrawScoreboard();
1940 Sbar_DrawCenterPrint();
1943 else if (intermission == 2)
1945 Sbar_FinaleOverlay();
1946 Sbar_DrawCenterPrint();
1950 if (sb_showscores || sb_showscores_force || (getstati(STAT_HEALTH) <= 0 && cvar("cl_deathscoreboard")))
1952 sbar_x = (vid_conwidth - 640.0)*0.5;
1953 sbar_y = vid_conheight - 47;
1954 //Sbar_DrawAlphaPic (sbar_x, sbar_y, sb_scorebar, sbar_alpha_bg.value);
1955 //drawpic('0 0 0', "gfx/scorebar", '0 0 0', '1 1 1', cvar("sbar_alpha_bg"), 0);
1956 Sbar_DrawScoreboard ();
1960 if (sb_lines && sbar_hudselector == 1)
1962 stat_items = getstati(STAT_ITEMS);
1963 stat_weapons = getstati(STAT_WEAPONS);
1965 sbar_x = (vid_conwidth - 320.0)*0.5;
1966 sbar_y = vid_conheight - 24.0 - 16.0;
1969 fade = 3.2 - 2 * (time - weapontime);
1970 fade = bound(0.7, fade, 1);
1973 Sbar_DrawWeapon_Clear();
1974 for(i = 1; i <= 24; ++i)
1976 if(weaponimpulse[i-1] >= 0)
1977 if(stat_weapons & x)
1979 Sbar_DrawWeapon(i-1, fade, (i == activeweapon));
1985 x = getstati(STAT_ARMOR);
1989 //Sbar_DrawStretchPic (72, 0, sb_armor[0], sbar_alpha_fg.value, 24, 24);
1990 drawpic(sbar + '72 0 0', "gfx/sb_armor", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1992 Sbar_DrawXNum('0 0 0', x, 3, 24, '0 1 0', 1, 0);
1994 Sbar_DrawXNum('0 0 0', x, 3, 24, '0.2 1 0', 1, 0);
1996 Sbar_DrawXNum('0 0 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1998 Sbar_DrawXNum('0 0 0', x, 3, 24, '1 1 0.2', 1, 0);
2000 Sbar_DrawXNum('0 0 0', x, 3, 24, '0.7 0 0', 1, 0);
2004 x = getstati(STAT_HEALTH);
2008 //Sbar_DrawStretchPic (184, 0, sb_health, sbar_alpha_fg.value, 24, 24);
2009 drawpic(sbar + '184 0 0', "gfx/sb_health", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
2011 Sbar_DrawXNum('112 0 0', x, 3, 24, '0 1 0', 1, 0);
2013 Sbar_DrawXNum('112 0 0', x, 3, 24, '0.2 1 0', 1, 0);
2015 Sbar_DrawXNum('112 0 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
2017 Sbar_DrawXNum('112 0 0', x, 3, 24, '1 1 0.2', 1, 0);
2019 Sbar_DrawXNum('112 0 0', x, 3, 24, '0.7 0 0', 1, 0);
2023 for(i = 0, v = '0 0 0'; (x = GetAmmoStat(i)) >= 0; ++i)
2024 if(stat_items & GetAmmoItemCode(i))
2027 drawpic(sbar + '296 0 0' + v, GetAmmoPicture(i), '24 24 0', '1 1 1', sbar_alpha_fg, 0);
2029 Sbar_DrawXNum('224 0 0' + v, x, 3, 24, '0.6 0.7 0.8', 1, 0);
2031 Sbar_DrawXNum('224 0 0' + v, x, 3, 24, '0.7 0 0', 1, 0);
2035 if (sbar_x + 320 + 160 <= vid_conwidth)
2036 Sbar_MiniDeathmatchOverlay(sbar + '320 0 0');
2039 // The margin can be at most 8 to support 640x480 console size:
2040 // 320 + 2 * (144 + 16) = 640
2045 stat_items = getstati(STAT_ITEMS);
2046 stat_weapons = getstati(STAT_WEAPONS);
2048 sbar_x = (vid_conwidth - 640.0)*0.5;
2049 sbar_y = vid_conheight - 47;
2052 fade = 3 - 2 * (time - weapontime);
2055 Sbar_DrawWeapon_Clear();
2056 for(i = 1; i <= 24; ++i)
2058 if(weaponimpulse[i-1] >= 0)
2059 if(stat_weapons & x)
2061 Sbar_DrawWeapon(i-1, fade, (i == activeweapon));
2067 drawpic(sbar, "gfx/sbar", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
2069 drawpic(sbar, "gfx/sbar_minimal", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
2073 Sbar_DrawXNum('268 12 0', getstati(STAT_ARMOR), 3, 24, '0.6 0.7 0.8', 1, 0);
2077 x = getstati(STAT_HEALTH);
2079 Sbar_DrawXNum('82 12 0', x, 3, 24, '1 1 1', 1, 0);
2080 else if(x <= 25 && time - floor(time) > 0.5)
2081 Sbar_DrawXNum('82 12 0', x, 3, 24, '0.7 0 0', 1, 0);
2083 Sbar_DrawXNum('81 12 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
2086 for(i = 0, v = '0 0 0'; (x = GetAmmoStat(i)) >= 0; ++i)
2087 if(stat_items & GetAmmoItemCode(i))
2090 drawpic(sbar + '519 0 0' + v, GetAmmoPicture(i), '0 0 0', '1 1 1', sbar_alpha_fg, 0);
2092 Sbar_DrawXNum('447 12 0' + v, x, 3, 24, '0.6 0.7 0.8', 1, 0);
2094 Sbar_DrawXNum('447 12 0' + v, x, 3, 24, '0.7 0 0', 1, 0);
2099 drawpic(sbar, "gfx/sbar_overlay", '0 0 0', '1 1 1', 1, DRAWFLAG_MODULATE);
2101 if (sbar_x + 600 + 160 <= vid_conwidth)
2102 Sbar_MiniDeathmatchOverlay (sbar + '600 0 0');
2107 // Mini scoreboard uses 12*4 per other team, that is, 144
2108 // pixels when there are four teams...
2109 // Nexuiz by default sets vid_conwidth to 800... makes
2111 // so we need to shift it by 64 pixels to the right to fit
2112 // BUT: then it overlaps with the image that gets drawn
2113 // for viewsize 100! Therefore, just account for 3 teams,
2114 // that is, 96 pixels mini scoreboard size, needing 16 pixels
2118 //show strength/invincibility ICON and timer:
2119 CSQC_Strength_Timer();
2121 if(gametype == GAME_KEYHUNT)
2124 } else if(gametype == GAME_CTF)
2127 } else if(gametype == GAME_NEXBALL)
2132 Sbar_DrawCenterPrint();
2136 void CSQC_ctf_hud(void)
2138 // cvar("sbar_flagstatus_right") move the flag icons right
2139 // cvar("sbar_flagstatus_pos") pixel position of the nexuiz flagstatus icons
2140 float redflag, blueflag;
2144 stat_items = getstati(STAT_ITEMS);
2145 redflag = (stat_items/IT_RED_FLAG_TAKEN) & 3;
2146 blueflag = (stat_items/IT_BLUE_FLAG_TAKEN) & 3;
2150 * For some reason now not even THAT works there...
2151 * Maybe the minus' precedence screws it up? The last one there, maybe I should use brackets
2153 * pos_x = (cvar("sbar_flagstatus_right")) ? vid_conwidth - 10 - sbar_x - 64 : 10 - sbar_x;
2154 ** Should try those later:
2155 * pos_x = (cvar("sbar_flagstatus_right")) ? (vid_conwidth - 10 - sbar_x - 64) : (10 - sbar_x);
2156 * pos_x = ( (cvar("sbar_flagstatus_right")) ? vid_conwidth - 10 - 64 : 10 ) - sbar_x;
2159 if(cvar("sbar_flagstatus_right"))
2160 pos_x = vid_conwidth - 10 - sbar_x - 64;
2162 pos_x = 10 - sbar_x;
2166 if(sbar_hudselector == 1)
2167 pos_y = (vid_conheight - sbar_y) - cvar("sbar_flagstatus_pos") - 64;
2175 case 1: drawpic(pos, "gfx/sb_flag_red_taken", '128 64 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); break;
2176 case 2: drawpic(pos, "gfx/sb_flag_red_lost", '128 64 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); break;
2177 case 3: drawpic(pos, "gfx/sb_flag_red_carrying", '128 64 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); break;
2179 if(stat_items & IT_CTF_SHIELDED)
2180 if(myteam == COLOR_TEAM2)
2181 drawpic(pos, "gfx/sb_flag_red_shielded", '128 64 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); break;
2188 case 1: drawpic(pos, "gfx/sb_flag_blue_taken", '128 64 0', '1 1 1', sbar_alpha_fg, 0); break;
2189 case 2: drawpic(pos, "gfx/sb_flag_blue_lost", '128 64 0', '1 1 1', sbar_alpha_fg, 0); break;
2190 case 3: drawpic(pos, "gfx/sb_flag_blue_carrying", '128 64 0', '1 1 1', sbar_alpha_fg, 0); break;
2192 if(stat_items & IT_CTF_SHIELDED)
2193 if(myteam == COLOR_TEAM1)
2194 drawpic(pos, "gfx/sb_flag_blue_shielded", '128 64 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); break;
2199 #define NBPB_SIZE '128 66 0'
2200 #define NBPB_BT 2 //thickness
2201 #define NBPB_BRGB '1 1 1'
2202 #define NBPB_BALPH 1 //alpha
2203 #define NBPB_BFLAG DRAWFLAG_NORMAL
2204 #define NBPB_IALPH 0.4
2205 #define NBPB_IFLAG DRAWFLAG_NORMAL
2206 #define NBPB_IRGB '0.7 0.1 0'
2208 void CSQC_nb_hud(void)
2210 float stat_items, nb_pb_starttime, dt, p;
2213 stat_items = getstati(STAT_ITEMS);
2214 nb_pb_starttime = getstatf(STAT_NB_METERSTART);
2216 if(cvar_or("sbar_ballstatus_right", cvar("sbar_flagstatus_right")))
2217 pos_x = vid_conwidth - 66 - sbar_x - 64; // the 66 comes from trial and error, no idea about the 64 (see CTF)
2219 pos_x = 10 - sbar_x;
2223 if(sbar_hudselector == 1)
2224 pos_y = (vid_conheight - sbar_y) - cvar_or("sbar_ballstatus_pos", 123) - 64;
2226 pos_y = -124; // 17 more than flag icons
2229 pos_y -= 1; //vertical margin to the picture
2231 //Manage the progress bar if any
2232 if (nb_pb_starttime > 0)
2235 dt = mod(time - nb_pb_starttime, nb_pb_period);
2236 // one period of positive triangle
2237 p = 2 * dt / nb_pb_period;
2243 drawfill(pos, p * s_x * '1 0 0' + s_y * '0 1 0', NBPB_IRGB, NBPB_IALPH, NBPB_IFLAG);
2247 drawline(NBPB_BT, pos , pos + '1 0 0' * s_x, NBPB_BRGB, NBPB_BALPH, NBPB_BFLAG);
2248 drawline(NBPB_BT, pos , pos + '0 1 0' * s_y, NBPB_BRGB, NBPB_BALPH, NBPB_BFLAG);
2249 drawline(NBPB_BT, pos + s, pos + '1 0 0' * s_x, NBPB_BRGB, NBPB_BALPH, NBPB_BFLAG);
2250 drawline(NBPB_BT, pos + s, pos + '0 1 0' * s_y, NBPB_BRGB, NBPB_BALPH, NBPB_BFLAG);
2253 pos_y += 1; //vertical margin to the picture
2255 if (stat_items & IT_KEY1)
2256 drawpic(pos, "gfx/sb_nexball_carrying", '128 64 0', '1 1 1', 1, DRAWFLAG_NORMAL);