6 float sb_lines; // still don't know what to do with that NOTE: check dp's sbar.c to see what that should be
10 float sbar_hudselector;
20 float ps_primary, ps_secondary;
21 float ts_primary, ts_secondary;
26 void Sbar_FinaleOverlay()
29 pos_x = (vid_conwidth - 1)/2;
33 //drawpic(pos, "gfx/finale", '0 0 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
35 //drawstring(pos, "END", sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
39 void Sbar_DrawWeapon(float nr, float fade, float active)
41 vector pos, vsize, color;
44 value = (active) ? 1 : 0.6;
45 color_x = color_y = color_z = value;
47 if(sbar_hudselector == 1)
49 // width = 300, height = 100
50 const float w_width = 32, w_height = 12, w_space = 2, font_size = 8;
52 pos_x = (vid_conwidth - w_width * 9) * 0.5 + w_width * nr;
53 pos_y = (vid_conheight - w_height);
58 drawpic(pos, strcat("gfx/inv_weapon", ftos(nr)), vsize, color, value * fade * sbar_alpha_fg, 0);
64 drawstring(pos, ftos(nr+1), vsize, '1 1 0', sbar_alpha_fg, 0);
69 // width = 300, height = 100
70 const float w2_width = 300, w2_height = 100, w2_space = 10;
71 const float w2_scale = 0.4;
73 pos_x = vid_conwidth - (w2_width + w2_space) * w2_scale;
74 pos_y = (w2_height + w2_space) * w2_scale * nr + w2_space;
76 vsize_x = w2_width * w2_scale;
77 vsize_y = w2_height * w2_scale;
80 drawpic(pos, strcat("gfx/inv_weapon", ftos(nr)), vsize, color, value * fade * sbar_alpha_fg, 0);
83 void Sbar_DrawXNum (vector pos, float num, float digits, float lettersize, vector rgb, float a, float dflags)
90 vsize_x = vsize_y = lettersize;
105 str = strcat(substring("0000000000", 0, digits - strlen(tmp)), tmp);
113 str = substring(str, l-digits, 999);
115 } else if(l < digits)
116 pos_x += (digits-l) * lettersize;
120 drawpic(sbar + pos, "gfx/num_minus", vsize, rgb, a * sbar_alpha_fg, dflags);
124 for(i = 0; i < l; ++i)
126 drawpic(sbar + pos, strcat("gfx/num_", substring(str, i, 1)), vsize, rgb, a * sbar_alpha_fg, dflags);
131 void Cmd_Sbar_SetFields(float argc);
132 void Sbar_InitScores()
134 float i, f, primary_prio, secondary_prio;
136 ps_primary = ps_secondary = ts_primary = ts_secondary = -1;
137 for(i = 0; i < MAX_SCORE; ++i)
139 f = (scores_flags[i] & SFL_SORT_PRIO_MASK);
140 if(f == SFL_SORT_PRIO_PRIMARY)
142 if(f == SFL_SORT_PRIO_SECONDARY)
145 if(ps_secondary == -1)
146 ps_secondary = ps_primary;
148 for(i = 0; i < MAX_TEAMSCORE; ++i)
150 f = (teamscores_flags[i] & SFL_SORT_PRIO_MASK);
151 if(f == SFL_SORT_PRIO_PRIMARY)
153 if(f == SFL_SORT_PRIO_SECONDARY)
156 if(ts_secondary == -1)
157 ts_secondary = ts_primary;
159 Cmd_Sbar_SetFields(0);
162 void Sbar_UpdatePlayerPos(entity pl);
163 float SetTeam(entity pl, float Team);
165 void Sbar_UpdatePlayerTeams()
172 for(pl = players.sort_next; pl; pl = pl.sort_next)
175 Team = GetPlayerColor(pl.sv_entnum);
176 if(SetTeam(pl, Team))
179 Sbar_UpdatePlayerPos(pl);
183 pl = players.sort_next;
188 print(strcat("PNUM: ", ftos(num), "\n"));
193 float Sbar_ComparePlayerScores(entity left, entity right)
196 vl = GetPlayerColor(left.sv_entnum);
197 vr = GetPlayerColor(right.sv_entnum);
204 if(vl == COLOR_SPECTATOR)
206 // FIRST the one with scores (spectators), THEN the ones without (downloaders)
208 if(!left.gotscores && right.gotscores)
213 vl = left.scores[ps_primary];
214 vr = right.scores[ps_primary];
216 return IS_INCREASING(scores_flags[ps_primary]);
218 return IS_DECREASING(scores_flags[ps_primary]);
220 vl = left.scores[ps_secondary];
221 vr = right.scores[ps_secondary];
223 return IS_INCREASING(scores_flags[ps_secondary]);
225 return IS_DECREASING(scores_flags[ps_secondary]);
230 void Sbar_UpdatePlayerPos(entity player)
232 for(other = player.sort_next; other && Sbar_ComparePlayerScores(player, other); other = player.sort_next)
234 SORT_SWAP(player, other);
236 for(other = player.sort_prev; other != players && Sbar_ComparePlayerScores(other, player); other = player.sort_prev)
238 SORT_SWAP(other, player);
242 float Sbar_CompareTeamScores(entity left, entity right)
246 if(left.team == COLOR_SPECTATOR)
248 if(right.team == COLOR_SPECTATOR)
251 vl = left.teamscores[ts_primary];
252 vr = right.teamscores[ts_primary];
254 return IS_INCREASING(teamscores_flags[ts_primary]);
256 return IS_DECREASING(teamscores_flags[ts_primary]);
258 vl = left.teamscores[ts_secondary];
259 vr = right.teamscores[ts_secondary];
261 return IS_INCREASING(teamscores_flags[ts_secondary]);
263 return IS_DECREASING(teamscores_flags[ts_secondary]);
268 void Sbar_UpdateTeamPos(entity Team)
270 for(other = Team.sort_next; other && Sbar_CompareTeamScores(Team, other); other = Team.sort_next)
272 SORT_SWAP(Team, other);
274 for(other = Team.sort_prev; other != teams && Sbar_CompareTeamScores(other, Team); other = Team.sort_prev)
276 SORT_SWAP(other, Team);
280 void Cmd_Sbar_Help(float argc)
282 print("You can modify the scoreboard using the\n");
283 print("^3|---------------------------------------------------------------|\n");
284 print("^1 TO BE DONE\n");
286 print("^2sbar_columns_set default\n");
287 print("^2sbar_columns_set ^7filed1 field2 ...\n");
288 print("The following field names are recognized (case INsensitive):\n");
289 print("You can use a ^3|^7 to start the right-aligned fields.\n");
291 print("^3name^7 or ^3nick^7 Name of a player\n");
292 print("^3ping^7 Ping time\n\n");
293 print("^3kd^7 or ^3kdr^7 or ^3kdratio^7 or ^3k/d\n");
294 print(" The kill-death ratio\n");
296 print("Before a field you can put a + or - sign, then a comma separated list\n");
297 print("of game types, then a slash, to make the field show up only in these\n");
298 print("or in all but these game types.\n");
301 print("Additional columns:\n");
302 for(i = 0; i < MAX_SCORE; ++i)
304 if(scores_label[i] != "")
305 print(strcat(scores_label[i], "\n"));
309 #define MIN_NAMELEN 24
310 #define MAX_NAMELEN 24
312 string Sbar_DefaultColumnLayout()
314 return "ping pl name | -ctf,kh/kills -ctf,kh/deaths +lms/lives +lms/rank +kh,ctf/caps +kh/pushes +kh/destroyed -lms/score";
317 void Cmd_Sbar_SetFields(float argc)
320 string str, pattern, subpattern;
322 float have_name, have_primary, have_secondary, have_separator;
325 // TODO: re enable with gametype dependant cvars?
326 if(argc < 2) // no arguments provided
327 argc = tokenizebyseparator(strcat("x ", cvar_string("sbar_columns")), " ");
330 argc = tokenizebyseparator(strcat("x ", Sbar_DefaultColumnLayout()), " ");
334 if(argv(1) == "default")
335 argc = tokenizebyseparator(strcat("x ", Sbar_DefaultColumnLayout()), " ");
336 else if(argv(1) == "all")
340 for(i = 0; i < MAX_SCORE; ++i)
343 if(i != ps_secondary)
344 if(scores_label[i] != "")
345 s = strcat(s, " ", scores_label[i]);
347 if(ps_secondary != ps_primary)
348 s = strcat(s, " ", scores_label[ps_secondary]);
349 s = strcat(s, " ", scores_label[ps_primary]);
350 argc = tokenizebyseparator(strcat("x ", s), " ");
355 argc = min(MAX_SBAR_FIELDS, argc);
358 drawfont = sbar_font;
359 digit = stringwidth("0123456789", FALSE) / 10;
361 subpattern = strcat(",", GametypeNameFromType(gametype), ",");
363 argc = min(argc-1, MAX_SBAR_FIELDS-1);
364 for(i = 0; i < argc; ++i)
368 slash = strstrofs(str, "/", 0);
371 pattern = substring(str, 0, slash);
372 str = substring(str, slash + 1, strlen(str) - (slash + 1));
374 if(substring(pattern, 0, 1) == "-")
376 pattern = substring(pattern, 1, strlen(pattern) - 1);
377 if(strstrofs(strcat(",", pattern, ","), subpattern, 0) >= 0)
382 if(substring(pattern, 0, 1) == "+")
383 pattern = substring(pattern, 1, strlen(pattern) - 1);
384 if(strstrofs(strcat(",", pattern, ","), subpattern, 0) < 0)
389 strunzone(sbar_title[sbar_num_fields]);
390 sbar_title[sbar_num_fields] = strzone(str);
391 sbar_size[sbar_num_fields] = stringwidth(str, FALSE);
392 str = strtolower(str);
395 sbar_field[sbar_num_fields] = SP_PING;
396 } else if(str == "pl") {
397 sbar_field[sbar_num_fields] = SP_PL;
398 } else if(str == "kd" || str == "kdr" || str == "kdratio" || str == "k/d") {
399 sbar_field[sbar_num_fields] = SP_KDRATIO;
400 } else if(str == "name" || str == "nick") {
401 sbar_field[sbar_num_fields] = SP_NAME;
402 sbar_size[sbar_num_fields] = MIN_NAMELEN; // minimum size? any use?
404 } else if(str == "|") {
405 sbar_field[sbar_num_fields] = SP_SEPARATOR;
408 for(j = 0; j < MAX_SCORE; ++j)
409 if(str == strtolower(scores_label[j]))
410 goto found; // sorry, but otherwise fteqcc -O3 miscompiles this and warns about "unreachable code"
412 print(strcat("^1Error:^7 Unknown score field: '", str, "'\n"));
415 sbar_field[sbar_num_fields] = j;
418 if(j == ps_secondary)
424 if(scores_flags[ps_primary] & SFL_ALLOW_HIDE)
426 if(scores_flags[ps_secondary] & SFL_ALLOW_HIDE)
428 if(ps_primary == ps_secondary)
430 missing = !have_primary + !have_secondary + !have_separator + !have_name;
432 if(sbar_num_fields+missing < MAX_SBAR_FIELDS)
436 strunzone(sbar_title[sbar_num_fields]);
437 for(i = sbar_num_fields; i > 0; --i)
439 sbar_title[i] = sbar_title[i-1];
440 sbar_size[i] = sbar_size[i-1];
441 sbar_field[i] = sbar_field[i-1];
443 sbar_title[0] = strzone("name");
444 sbar_field[0] = SP_NAME;
445 sbar_size[0] = MIN_NAMELEN; // minimum size? any use?
447 print("fixed missing field 'name'\n");
451 strunzone(sbar_title[sbar_num_fields]);
452 for(i = sbar_num_fields; i > 1; --i)
454 sbar_title[i] = sbar_title[i-1];
455 sbar_size[i] = sbar_size[i-1];
456 sbar_field[i] = sbar_field[i-1];
458 sbar_title[1] = strzone("|");
459 sbar_field[1] = SP_SEPARATOR;
460 sbar_size[1] = stringwidth("|", FALSE);
462 print("fixed missing field '|'\n");
465 else if(!have_separator)
467 strunzone(sbar_title[sbar_num_fields]);
468 sbar_title[sbar_num_fields] = strzone("|");
469 sbar_size[sbar_num_fields] = stringwidth("|", FALSE);
470 sbar_field[sbar_num_fields] = SP_SEPARATOR;
472 print("fixed missing field '|'\n");
477 strunzone(sbar_title[sbar_num_fields]);
478 sbar_title[sbar_num_fields] = strzone(scores_label[ps_secondary]);
479 sbar_size[sbar_num_fields] = stringwidth(sbar_title[sbar_num_fields], FALSE);
480 sbar_field[sbar_num_fields] = ps_secondary;
482 print("fixed missing field '", scores_label[ps_secondary], "'\n");
487 strunzone(sbar_title[sbar_num_fields]);
488 sbar_title[sbar_num_fields] = strzone(scores_label[ps_primary]);
489 sbar_size[sbar_num_fields] = stringwidth(sbar_title[sbar_num_fields], FALSE);
490 sbar_field[sbar_num_fields] = ps_primary;
492 print("fixed missing field '", scores_label[ps_primary], "'\n");
496 sbar_field[sbar_num_fields] = SP_END;
500 vector sbar_field_rgb;
501 string Sbar_GetField(entity pl, float field)
503 float tmp, num, denom, f;
505 sbar_field_rgb = '1 1 1';
510 return "\x8D\x8D\x8D"; // >>> sign
511 str = getplayerkey(pl.sv_entnum, "ping");
514 tmp = max(0, min(220, stof(str)-80)) / 220;
515 sbar_field_rgb = '1 1 1' - '0 1 1'*tmp;
521 str = getplayerkey(pl.sv_entnum, "pl");
524 tmp = bound(0, stof(str), 20) / 20; // 20% is REALLY BAD pl
525 sbar_field_rgb = '1 0.5 0.5' - '0 0.5 0.5'*tmp;
529 return getplayerkey(pl.sv_entnum, "name");
532 num = pl.(scores[SP_KILLS]);
533 denom = pl.(scores[SP_DEATHS]);
536 sbar_field_rgb = '0 1 0';
538 } else if(num <= 0) {
539 sbar_field_rgb = '1 0 0';
540 str = ftos(num/denom);
542 str = ftos(num/denom);
544 tmp = strstrofs(str, ".", 0);
546 str = substring(str, 0, tmp+2);
550 tmp = pl.(scores[field]);
551 f = scores_flags[field];
552 if(field == ps_primary)
553 sbar_field_rgb = '1 1 0';
554 else if(field == ps_secondary)
555 sbar_field_rgb = '0 1 1';
557 sbar_field_rgb = '1 1 1';
559 if(f & (SFL_HIDE_ZERO | SFL_RANK))
563 str = ftos(floor(tmp + 0.5));
565 if((num >= 2) && (substring(str, num - 2, 1) == "1"))
566 return strcat(str, "th");
567 else if(substring(str, num - 1, 1) == "1")
568 return strcat(str, "st");
569 else if(substring(str, num - 1, 1) == "2")
570 return strcat(str, "nd");
571 else if(substring(str, num - 1, 1) == "3")
572 return strcat(str, "rd");
574 return strcat(str, "th");
581 // shamelessly stolen from menu QC :P <- as if I would steal YOUR code pfft ;)
582 float textLengthUpToWidth(string theText, float maxWidth, float handleColors)
585 // The following function is SLOW.
586 // For your safety and for the protection of those around you...
587 // DO NOT CALL THIS AT HOME.
589 if(stringwidth(theText, handleColors) <= maxWidth)
590 return strlen(theText); // yeah!
592 // binary search for right place to cut string
593 float left, right, middle; // this always works
595 right = strlen(theText); // this always fails
598 middle = floor((left + right) / 2);
599 if(stringwidth(substring(theText, 0, middle), handleColors) <= maxWidth)
604 while(left < right - 1);
606 // NOTE: when color codes are involved, this binary search is,
607 // mathematically, BROKEN. However, it is obviously guaranteed to
608 // terminate, as the range still halves each time - but nevertheless, it is
609 // guaranteed that it finds ONE valid cutoff place (where "left" is in
610 // range, and "right" is outside).
614 string textShortenToWidth(string theText, float maxWidth, float handleColors)
616 if(stringwidth(theText, handleColors) <= maxWidth)
619 return strcat(substring(theText, 0, textLengthUpToWidth(theText, maxWidth - stringwidth("...", handleColors), handleColors)), "...");
622 float xmin, xmax, ymin, ymax, sbwidth, sbheight;
624 void Sbar_PrintScoreboardItem(vector pos, entity pl, float is_self)
630 is_spec = (GetPlayerColor(pl.sv_entnum) == COLOR_SPECTATOR);
637 tmp_y = sbar_fontsize_y;
638 drawfill(pos - '1 1 0', tmp + '2 2 0', '1 1 1', 0.3, DRAWFLAG_NORMAL);
642 for(i = 0; i < sbar_num_fields; ++i)
644 field = sbar_field[i];
645 if(field == SP_SEPARATOR)
648 if(is_spec && field != SP_NAME && field != SP_PING) {
649 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
652 str = Sbar_GetField(pl, field);
658 realsize = sbar_size[i];
659 if(i+1 < sbar_num_fields)
660 if(sbar_field[i+1] == SP_SEPARATOR)
662 realsize = (xmax - xmin) / sbar_fontsize_x;
663 for(j = 0; j < sbar_num_fields; ++j) if(j != i) if(sbar_field[j] != SP_SEPARATOR)
664 realsize -= sbar_size[j] + 1;
667 str = textShortenToWidth(str, realsize, TRUE);
669 len = stringwidth(str, TRUE);
671 if(sbar_size[i] < len)
674 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
676 if(field == SP_NAME) {
677 tmp_x = sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
678 drawcolorcodedstring(pos - tmp, str, sbar_fontsize, 1, DRAWFLAG_NORMAL);
680 tmp_x = len*sbar_fontsize_x + sbar_fontsize_x;
681 drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, 1, DRAWFLAG_NORMAL);
685 if(sbar_field[i] == SP_SEPARATOR)
688 for(i = sbar_num_fields-1; i > 0; --i)
690 field = sbar_field[i];
691 if(field == SP_SEPARATOR)
694 if(is_spec && field != SP_NAME && field != SP_PING) {
695 pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
699 str = Sbar_GetField(pl, field);
702 str = textShortenToWidth(str, sbar_size[i], TRUE);
703 len = stringwidth(str, TRUE);
705 if(sbar_size[i] < len)
708 if(field == SP_NAME) {
709 tmp_x = sbar_fontsize_x*len; // left or right aligned? let's put it right...
710 drawcolorcodedstring(pos - tmp, str, sbar_fontsize, 1, DRAWFLAG_NORMAL);
712 tmp_x = sbar_fontsize_x*len; //strlen(str);
713 drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, 1, DRAWFLAG_NORMAL);
715 pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
721 void Sbar_DrawScoreboard()
723 //float xmin, ymin, xmax, ymax;
724 vector rgb, pos, tmp, sbar_save;
729 if(time > lastpingstime + 10)
732 lastpingstime = time;
735 sbar_fontsize = Sbar_GetFontsize();
736 if(sbar_fontsize_x == 0)
737 sbar_fontsize = '8 8 0';
738 if(sbar_fontsize_y == 0)
739 sbar_fontsize_y = sbar_fontsize_x;
741 xmin = vid_conwidth / 5;
744 xmax = vid_conwidth - xmin;
745 ymax = vid_conheight - 0.2*vid_conheight;
747 sbwidth = xmax - xmin;
748 sbheight = ymax - ymin;
750 center_x = xmin + 0.5*sbwidth;
752 //Sbar_UpdateFields();
754 // Initializes position
760 drawfont = sbar_bigfont;
761 pos_x = center_x - stringwidth("Scoreboard", TRUE)*0.5*24;
762 drawstring(pos, "Scoreboard", '24 24 0', '1 1 1', 1, DRAWFLAG_NORMAL);
766 // Titlebar background:
768 tmp_y = sbar_fontsize_y;
769 drawfill(pos - '1 1 0', tmp + '2 2 0', '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
771 drawfont = sbar_font;
773 for(i = 0; i < sbar_num_fields; ++i)
775 if(sbar_field[i] == SP_SEPARATOR)
777 drawstring(pos, sbar_title[i], sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
778 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
781 if(sbar_field[i] == SP_SEPARATOR)
783 pos_x = xmax + sbar_fontsize_x;
785 for(i = sbar_num_fields-1; i > 0; --i)
787 if(sbar_field[i] == SP_SEPARATOR)
790 pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
793 * Using the following line will fuck it all up:
795 * tmp_x = sbar_size[i] - strlen(sbar_title[i])*8;
797 tmp_x = sbar_fontsize_x*sbar_size[i];
798 tmp_x -= stringwidth(sbar_title[i], FALSE)*sbar_fontsize_x;
799 drawstring(pos + tmp, sbar_title[i], sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
804 pos_y += 1.5 * sbar_fontsize_y;
811 //for(tm = sortedTeams.sort_next; tm; tm = tm.sort_next)
812 for(tm = teams.sort_next; tm; tm = tm.sort_next)
814 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
817 rgb = GetTeamRGB(tm.team);
822 pos - '6.5 0 0' * sbar_fontsize_y,
823 tm.(teamscores[ts_primary]),
824 4, sbar_fontsize_y * 1.5, rgb, 1, DRAWFLAG_NORMAL);
826 if(ts_primary != ts_secondary)
828 pos - '4.5 0 0' * sbar_fontsize_y + '0 1.5 0' * sbar_fontsize_y,
829 tm.(teamscores[ts_secondary]),
830 4, sbar_fontsize_y * 1, rgb, 1, DRAWFLAG_NORMAL);
832 specs = tm.team_size;
838 tmp_y = 1.25 * sbar_fontsize_y * specs;
839 drawfill(pos - '1 1 0', tmp + '2 0 0', rgb, 0.2, DRAWFLAG_NORMAL);
841 for(pl = players.sort_next; pl; pl = pl.sort_next)
843 if(pl.team != tm.team)
845 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
846 pos_y += 1.25 * sbar_fontsize_y;
847 tmp_y -= 1.25 * sbar_fontsize_y;
849 pos_y += tmp_y + 1.5 * sbar_fontsize_y;
851 // rgb := tempvector :)
852 rgb = pos + '0 1.5 0' * sbar_fontsize_y;
853 pos_y += 3 * sbar_fontsize_y;
855 for(pl = players.sort_next; pl; pl = pl.sort_next)
857 if(pl.team != COLOR_SPECTATOR)
859 //drawcolorcodedstring(pos, getplayerkey(pl.sb_player, "name"), '8 8 0', 1, 0);
860 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
861 pos += '0 1.25 0' * sbar_fontsize_y;
866 drawstring(rgb, "Spectators", sbar_fontsize, '1 1 1', 1, 0);
869 for(pl = players.sort_next; pl; pl = pl.sort_next)
871 if(pl.team == COLOR_SPECTATOR)
873 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
874 pos_y += 1.25 * sbar_fontsize_y;
875 tmp_y -= 1.25 * sbar_fontsize_y;
878 // rgb := tempvector :)
879 rgb = pos + '0 1.5 0' * sbar_fontsize_y;
880 pos_y += 3 * sbar_fontsize_y;
882 for(pl = players.sort_next; pl; pl = pl.sort_next)
884 if(pl.team != COLOR_SPECTATOR)
886 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
887 pos += '0 1.25 0' * sbar_fontsize_y;
892 drawstring(rgb, "Spectators", sbar_fontsize, '1 1 1', 1, 0);
897 str = strcat("playing on ^2", shortmapname, "^7");
898 tl = getstatf(STAT_TIMELIMIT);
899 fl = getstatf(STAT_FRAGLIMIT);
900 if(gametype == GAME_LMS)
903 str = strcat(str, " for up to ^1", ftos(tl), " minutes^7");
908 str = strcat(str, " for ^1", ftos(tl), " minutes^7");
912 str = strcat(str, " or");
913 str = strcat(str, " until ^3", ftos(fl));
914 if(scores_label[ps_primary] == "score")
915 str = strcat(str, " points^7");
917 str = strcat(str, " ", scores_label[ps_primary]);
921 pos_y += 1.5 * sbar_fontsize_y;
922 drawcolorcodedstring(pos + '0.5 0 0' * (sbwidth - sbar_fontsize_x * stringwidth(str, TRUE)), str, sbar_fontsize, 0.8, 0);
927 void Sbar_Score(float margin)
929 float timelimit, timeleft, minutes, seconds, distribution, myplace, score;
930 vector sbar_save, place;
934 myteam = GetPlayerColor(player_localentnum - 1);
936 sbar_y = vid_conheight - (32+12);
947 //for(i = 0; i < 4; ++i)
948 for(tm = teams.sort_next; tm; tm = tm.sort_next)
950 if(tm.team == COLOR_SPECTATOR || !tm.team_size) // no players? don't display
953 score = tm.(teamscores[ts_primary]);
954 if(tm.team == myteam)
955 Sbar_DrawXNum('-128 0 0', score, 4, 32, GetTeamRGB(tm.team), 1, DRAWFLAG_NORMAL);
958 Sbar_DrawXNum(place, score, 4, 12, GetTeamRGB(tm.team), 1, DRAWFLAG_NORMAL);
963 // me vector := [team/connected frags id]
965 for(me = players.sort_next; me; me = me.sort_next)
967 if(me.team != COLOR_SPECTATOR)
969 if(me.sv_entnum == player_localentnum - 1)
977 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
982 Sbar_DrawXNum('-36 -12 0', myplace, 3, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
983 else if(myplace == 2)
984 Sbar_DrawXNum('-36 -12 0', myplace, 3, 12, '1 1 0', 1, DRAWFLAG_NORMAL);
986 Sbar_DrawXNum('-36 -12 0', myplace, 3, 12, '1 0 0', 1, DRAWFLAG_NORMAL);
988 score = me.(scores[ps_primary]);
989 if(distribution >= 0)
991 Sbar_DrawXNum('-84 -12 0', distribution, 4, 12, ' 1 1 1', 1, DRAWFLAG_NORMAL);
992 Sbar_DrawXNum('-128 0 0', score, 4, 32, '1 1 1', 1, DRAWFLAG_NORMAL);
993 } else if(distribution >= -5)
995 Sbar_DrawXNum('-84 -12 0', distribution, 4, 12, ' 1 1 0', 1, DRAWFLAG_NORMAL);
996 Sbar_DrawXNum('-128 0 0', score, 4, 32, '1 1 0', 1, DRAWFLAG_NORMAL);
998 Sbar_DrawXNum('-84 -12 0', distribution, 4, 12, ' 1 0 0', 1, DRAWFLAG_NORMAL);
999 Sbar_DrawXNum('-128 0 0', score, 4, 32, '1 0 0', 1, DRAWFLAG_NORMAL);
1002 timelimit = getstatf(STAT_TIMELIMIT);
1005 timeleft = max(0, timelimit * 60 - time);
1006 minutes = floor(timeleft / 60);
1007 seconds = floor(timeleft - minutes*60);
1010 Sbar_DrawXNum('-72 32 0', minutes, 3, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
1011 drawpic(sbar + '-36 32 0', "gfx/num_colon", '12 12 0', '1 1 1', sbar_alpha_fg, 0);
1012 Sbar_DrawXNum('-24 32 0', seconds, -2, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
1013 } else if(minutes >= 1)
1015 Sbar_DrawXNum('-72 32 0', minutes, 3, 12, '1 1 0', 1, DRAWFLAG_NORMAL);
1016 drawpic(sbar + '-36 32 0', "gfx/num_colon", '12 12 0', '1 1 0', sbar_alpha_fg, 0);
1017 Sbar_DrawXNum('-24 32 0', seconds, -2, 12, '1 1 0', 1, DRAWFLAG_NORMAL);
1019 Sbar_DrawXNum('-24 32 0', seconds, -2, 12, '1 0 0', 1, DRAWFLAG_NORMAL);
1022 minutes = floor(time / 60);
1023 seconds = floor(time - minutes*60);
1024 Sbar_DrawXNum('-72 32 0', minutes, 3, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
1025 drawpic(sbar + '-36 32 0', "gfx/num_colon", '12 12 0', '1 1 1', sbar_alpha_fg, 0);
1026 Sbar_DrawXNum('-24 32 0', seconds, -2, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
1031 void Sbar_MiniscoreItem(vector pos, entity pl, float is_self)
1037 drawfill(pos + '0 1 0', '40 6 0', GetTeamRGB(pl.team)*0.5, 1, DRAWFLAG_NORMAL);
1039 drawfill(pos + '0 1 0', '40 6 0', '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
1042 score = pl.(scores[ps_primary]);
1043 pos_x -= stringwidth(ftos(score), FALSE)*8;
1044 drawstring(pos, ftos(score), '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1049 drawstring(pos, "\x0D", '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1053 drawcolorcodedstring(pos, getplayerkey(pl.sv_entnum, "name"), '8 8 0', 1, 0);
1056 void Sbar_MiniscoreTeamItem(vector pos, float color, float frags, float is_self)
1062 drawfill(pos + '0 1 0', '40 6 0', GetTeamRGB(color)*0.5, 1, DRAWFLAG_NORMAL);
1064 drawfill(pos + '0 1 0', '40 6 0', '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
1067 pos_x -= stringwidth(ftos(frags), FALSE)*8;
1068 drawstring(pos, ftos(frags), '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1073 drawstring(pos, "\x0D", '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1077 drawstring(pos, GetTeamName(color), '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1080 void Sbar_MiniDeathmatchOverlay(vector pos)
1082 float numlines, up, down, score;
1084 float miniscoreboard_size;
1085 miniscoreboard_size = cvar("sbar_miniscoreboard_size");
1087 if(miniscoreboard_size == 0)
1089 pos_y = vid_conheight - 8;
1091 if(miniscoreboard_size < 0)
1092 numlines = (vid_conheight - sbar_y + 7) / 8;
1094 numlines = miniscoreboard_size;
1096 // give up if there isn't enough room
1097 if(pos_x >= vid_conwidth || pos_y >= vid_conheight || numlines < 1)
1100 // me vector := [team/connected frags id]
1101 for(me = players.sort_next; me; me = me.sort_next)
1103 if(me.sv_entnum == player_localentnum - 1)
1108 numlines -= numteams;
1110 // figure out how many players above and below we can show
1111 up = floor(numlines/2);
1113 if((up + down) > numlines)
1114 down = numlines - up;
1117 for(pl = me.sort_next; pl && down > 0; pl = pl.sort_next)
1119 if(pl.team == COLOR_SPECTATOR)
1121 Sbar_MiniscoreItem(pos, pl, false);
1125 Sbar_MiniscoreItem(pos, me, true);
1127 up += down; // if there weren't enough lines below... add them
1128 for(pl = me.sort_prev; pl && up > 0; pl = pl.sort_prev)
1130 if(pl.team == COLOR_SPECTATOR)
1132 Sbar_MiniscoreItem(pos, pl, false);
1139 for(tm = teams.sort_next; tm.sort_next; tm = tm.sort_next);
1140 for(; tm; tm = tm.sort_prev)
1142 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
1144 score = tm.(teamscores[ts_primary]);
1145 Sbar_MiniscoreTeamItem(pos, tm.team, score, (tm.team == me.team));
1151 float Sbar_WouldDrawScoreboard ()
1155 else if (intermission == 1)
1157 else if (intermission == 2)
1159 else if (getstati(STAT_HEALTH) <= 0 && cvar("cl_deathscoreboard"))
1164 void Sbar_Draw (void)
1171 Sbar_UpdatePlayerTeams();
1176 Sbar_DrawScoreboard();
1177 else if (intermission == 1)
1179 Sbar_DrawScoreboard();
1182 else if (intermission == 2)
1183 Sbar_FinaleOverlay();
1186 if (sb_showscores || (getstati(STAT_HEALTH) <= 0 && cvar("cl_deathscoreboard")))
1188 sbar_x = (vid_conwidth - 640.0)*0.5;
1189 sbar_y = vid_conheight - 47;
1190 //Sbar_DrawAlphaPic (sbar_x, sbar_y, sb_scorebar, sbar_alpha_bg.value);
1191 //drawpic('0 0 0', "gfx/scorebar", '0 0 0', '1 1 1', cvar("sbar_alpha_bg"), 0);
1192 Sbar_DrawScoreboard ();
1196 if (sb_lines && sbar_hudselector == 1)
1198 stat_items = getstati(STAT_ITEMS);
1200 sbar_x = (vid_conwidth - 320.0)*0.5;
1201 sbar_y = vid_conheight - 24.0 - 16.0;
1204 fade = 3.2 - 2 * (time - weapontime);
1205 fade = bound(0.7, fade, 1);
1208 for(i = 0; i < 8; ++i)
1212 Sbar_DrawWeapon(i+1, fade, (i + 2 == activeweapon));
1219 Sbar_DrawWeapon(0, fade, (activeweapon == 1));
1223 x = getstati(STAT_ARMOR);
1227 //Sbar_DrawStretchPic (72, 0, sb_armor[0], sbar_alpha_fg.value, 24, 24);
1228 drawpic(sbar + '72 0 0', "gfx/sb_armor", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1230 Sbar_DrawXNum('0 0 0', x, 3, 24, '0 1 0', 1, 0);
1232 Sbar_DrawXNum('0 0 0', x, 3, 24, '0.2 1 0', 1, 0);
1234 Sbar_DrawXNum('0 0 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1236 Sbar_DrawXNum('0 0 0', x, 3, 24, '1 1 0.2', 1, 0);
1238 Sbar_DrawXNum('0 0 0', x, 3, 24, '0.7 0 0', 1, 0);
1242 x = getstati(STAT_HEALTH);
1246 //Sbar_DrawStretchPic (184, 0, sb_health, sbar_alpha_fg.value, 24, 24);
1247 drawpic(sbar + '184 0 0', "gfx/sb_health", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1249 Sbar_DrawXNum('112 0 0', x, 3, 24, '0 1 0', 1, 0);
1251 Sbar_DrawXNum('112 0 0', x, 3, 24, '0.2 1 0', 1, 0);
1253 Sbar_DrawXNum('112 0 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1255 Sbar_DrawXNum('112 0 0', x, 3, 24, '1 1 0.2', 1, 0);
1257 Sbar_DrawXNum('112 0 0', x, 3, 24, '0.7 0 0', 1, 0);
1261 x = getstati(STAT_AMMO);
1262 if ((stat_items & (NEX_IT_SHELLS | NEX_IT_BULLETS | NEX_IT_ROCKETS | NEX_IT_CELLS)) || x != 0)
1264 if (stat_items & NEX_IT_SHELLS)
1265 drawpic(sbar + '296 0 0', "gfx/sb_shells", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1266 else if (stat_items & NEX_IT_BULLETS)
1267 drawpic(sbar + '296 0 0', "gfx/sb_bullets", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1268 else if (stat_items & NEX_IT_ROCKETS)
1269 drawpic(sbar + '296 0 0', "gfx/sb_rocket", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1270 else if (stat_items & NEX_IT_CELLS)
1271 drawpic(sbar + '296 0 0', "gfx/sb_cells", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1273 Sbar_DrawXNum('224 0 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1275 Sbar_DrawXNum('224 0 0', x, 3, 24, '0.7 0 0', 1, 0);
1278 if (sbar_x + 320 + 160 <= vid_conwidth)
1279 Sbar_MiniDeathmatchOverlay(sbar + '320 0 0');
1282 // The margin can be at most 8 to support 640x480 console size:
1283 // 320 + 2 * (144 + 16) = 640
1288 stat_items = getstati(STAT_ITEMS);
1290 sbar_x = (vid_conwidth - 640.0)*0.5;
1291 sbar_y = vid_conheight - 47;
1294 fade = 3 - 2 * (time - weapontime);
1297 for(i = 0; i < 8; ++i)
1301 Sbar_DrawWeapon(i+1, fade, (i + 2 == activeweapon));
1308 Sbar_DrawWeapon(0, fade, (activeweapon == 1));
1312 drawpic(sbar, "gfx/sbar", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1314 drawpic(sbar, "gfx/sbar_minimal", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1318 Sbar_DrawXNum('268 12 0', getstati(STAT_ARMOR), 3, 24, '0.6 0.7 0.8', 1, 0);
1322 x = getstati(STAT_HEALTH);
1324 Sbar_DrawXNum('82 12 0', x, 3, 24, '1 1 1', 1, 0);
1325 else if(x <= 25 && time - floor(time) > 0.5)
1326 Sbar_DrawXNum('82 12 0', x, 3, 24, '0.7 0 0', 1, 0);
1328 Sbar_DrawXNum('81 12 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1330 // AK dont draw ammo for the laser
1331 x = getstati(STAT_AMMO);
1332 if(activeweapon != 12)
1335 if (stat_items & NEX_IT_SHELLS)
1336 drawpic(sbar + '519 0 0', "gfx/sb_shells", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1337 else if (stat_items & NEX_IT_BULLETS)
1338 drawpic(sbar + '519 0 0', "gfx/sb_bullets", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1339 else if (stat_items & NEX_IT_ROCKETS)
1340 drawpic(sbar + '519 0 0', "gfx/sb_rocket", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1341 else if (stat_items & NEX_IT_CELLS)
1342 drawpic(sbar + '519 0 0', "gfx/sb_cells", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1344 Sbar_DrawXNum('447 12 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1346 Sbar_DrawXNum('447 12 0', x, 3, 24, '0.7 0 0', 1, 0);
1350 drawpic(sbar, "gfx/sbar_overlay", '0 0 0', '1 1 1', 1, DRAWFLAG_MODULATE);
1352 if (sbar_x + 600 + 160 <= vid_conwidth)
1353 Sbar_MiniDeathmatchOverlay (sbar + '600 0 0');
1358 // Mini scoreboard uses 12*4 per other team, that is, 144
1359 // pixels when there are four teams...
1360 // Nexuiz by default sets vid_conwidth to 800... makes
1362 // so we need to shift it by 64 pixels to the right to fit
1363 // BUT: then it overlaps with the image that gets drawn
1364 // for viewsize 100! Therefore, just account for 3 teams,
1365 // that is, 96 pixels mini scoreboard size, needing 16 pixels
1370 if(gametype == GAME_KEYHUNT)
1373 } else if(gametype == GAME_CTF)
1381 void CSQC_ctf_hud(void)
1383 // cvar("sbar_flagstatus_right") move the flag icons right
1384 // cvar("sbar_flagstatus_pos") pixel position of the nexuiz flagstatus icons
1385 float redflag, blueflag;
1389 stat_items = getstati(STAT_ITEMS);
1390 redflag = (stat_items/32768) & 3;
1391 blueflag = (stat_items/131072) & 3;
1395 * For some reason now not even THAT works there...
1396 * Maybe the minus' precedence screws it up? The last one there, maybe I should use brackets
1398 * pos_x = (cvar("sbar_flagstatus_right")) ? vid_conwidth - 10 - sbar_x - 64 : 10 - sbar_x;
1399 ** Should try those later:
1400 * pos_x = (cvar("sbar_flagstatus_right")) ? (vid_conwidth - 10 - sbar_x - 64) : (10 - sbar_x);
1401 * pos_x = ( (cvar("sbar_flagstatus_right")) ? vid_conwidth - 10 - 64 : 10 ) - sbar_x;
1404 if(cvar("sbar_flagstatus_right"))
1405 pos_x = vid_conwidth - 10 - sbar_x - 64;
1407 pos_x = 10 - sbar_x;
1411 if(sbar_hudselector == 1)
1412 pos_y = (vid_conheight - sbar_y) - cvar("sbar_flagstatus_pos") - 64;
1420 case 1: drawpic(pos, "gfx/sb_flag_red_taken", '0 0 0', '1 1 1', 1, DRAWFLAG_NORMAL); break;
1421 case 2: drawpic(pos, "gfx/sb_flag_red_lost", '0 0 0', '1 1 1', 1, DRAWFLAG_NORMAL); break;
1422 case 3: drawpic(pos, "gfx/sb_flag_red_carrying", '0 0 0', '1 1 1', 1, DRAWFLAG_NORMAL); break;
1429 case 1: drawpic(pos, "gfx/sb_flag_blue_taken", '0 0 0', '1 1 1', 1, 0); break;
1430 case 2: drawpic(pos, "gfx/sb_flag_blue_lost", '0 0 0', '1 1 1', 1, 0); break;
1431 case 3: drawpic(pos, "gfx/sb_flag_blue_carrying", '0 0 0', '1 1 1', 1, 0); break;