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 vl = left.scores[ps_primary];
205 vr = right.scores[ps_primary];
207 return IS_INCREASING(scores_flags[ps_primary]);
209 return IS_DECREASING(scores_flags[ps_primary]);
211 vl = left.scores[ps_secondary];
212 vr = right.scores[ps_secondary];
214 return IS_INCREASING(scores_flags[ps_secondary]);
216 return IS_DECREASING(scores_flags[ps_secondary]);
221 void Sbar_UpdatePlayerPos(entity player)
223 for(other = player.sort_next; other && Sbar_ComparePlayerScores(player, other); other = player.sort_next)
225 SORT_SWAP(player, other);
227 for(other = player.sort_prev; other != players && Sbar_ComparePlayerScores(other, player); other = player.sort_prev)
229 SORT_SWAP(other, player);
233 float Sbar_CompareTeamScores(entity left, entity right)
237 if(left.team == COLOR_SPECTATOR)
239 if(right.team == COLOR_SPECTATOR)
242 vl = left.teamscores[ts_primary];
243 vr = right.teamscores[ts_primary];
245 return IS_INCREASING(teamscores_flags[ts_primary]);
247 return IS_DECREASING(teamscores_flags[ts_primary]);
249 vl = left.teamscores[ts_secondary];
250 vr = right.teamscores[ts_secondary];
252 return IS_INCREASING(teamscores_flags[ts_secondary]);
254 return IS_DECREASING(teamscores_flags[ts_secondary]);
259 void Sbar_UpdateTeamPos(entity Team)
261 for(other = Team.sort_next; other && Sbar_CompareTeamScores(Team, other); other = Team.sort_next)
263 SORT_SWAP(Team, other);
265 for(other = Team.sort_prev; other != teams && Sbar_CompareTeamScores(other, Team); other = Team.sort_prev)
267 SORT_SWAP(other, Team);
271 void Cmd_Sbar_Help(float argc)
273 print("You can modify the scoreboard using the\n");
274 print("^3|---------------------------------------------------------------|\n");
275 print("^1 TO BE DONE\n");
277 print("^2sbar_columns_set default\n");
278 print("^2sbar_columns_set ^7filed1 field2 ...\n");
279 print("The following field names are recognized (case INsensitive):\n");
280 print("You can use a ^3|^7 to start the right-aligned fields.\n");
282 print("^3name^7 or ^3nick^7 Name of a player\n");
283 print("^3ping^7 Ping time\n\n");
284 print("^3kd^7 or ^3kdr^7 or ^3kdratio^7 or ^3k/d\n");
285 print(" The kill-death ratio\n");
287 print("Before a field you can put a + or - sign, then a comma separated list\n");
288 print("of game types, then a slash, to make the field show up only in these\n");
289 print("or in all but these game types.\n");
292 print("Additional columns:\n");
293 for(i = 0; i < MAX_SCORE; ++i)
295 if(scores_label[i] != "")
296 print(strcat(scores_label[i], "\n"));
300 #define MIN_NAMELEN 24
301 #define MAX_NAMELEN 24
303 string Sbar_DefaultColumnLayout()
305 return "ping pl name | -ctf,kh/kills -ctf,kh/deaths +lms/lives +lms/rank +kh,ctf/caps +kh/pushes +kh/destroyed -lms/score";
308 void Cmd_Sbar_SetFields(float argc)
311 string str, pattern, subpattern;
313 float have_name, have_primary, have_secondary, have_separator;
316 // TODO: re enable with gametype dependant cvars?
317 if(argc < 2) // no arguments provided
318 argc = tokenizebyseparator(strcat("x ", cvar_string("sbar_columns")), " ");
321 argc = tokenizebyseparator(strcat("x ", Sbar_DefaultColumnLayout()), " ");
325 if(argv(1) == "default")
326 argc = tokenizebyseparator(strcat("x ", Sbar_DefaultColumnLayout()), " ");
327 else if(argv(1) == "all")
331 for(i = 0; i < MAX_SCORE; ++i)
334 if(i != ps_secondary)
335 if(scores_label[i] != "")
336 s = strcat(s, " ", scores_label[i]);
338 if(ps_secondary != ps_primary)
339 s = strcat(s, " ", scores_label[ps_secondary]);
340 s = strcat(s, " ", scores_label[ps_primary]);
341 argc = tokenizebyseparator(strcat("x ", s), " ");
346 argc = min(MAX_SBAR_FIELDS, argc);
349 drawfont = sbar_font;
350 digit = stringwidth("0123456789", FALSE) / 10;
352 subpattern = strcat(",", GametypeNameFromType(gametype), ",");
354 argc = min(argc-1, MAX_SBAR_FIELDS-1);
355 for(i = 0; i < argc; ++i)
359 slash = strstrofs(str, "/", 0);
362 pattern = substring(str, 0, slash);
363 str = substring(str, slash + 1, strlen(str) - (slash + 1));
365 if(substring(pattern, 0, 1) == "-")
367 pattern = substring(pattern, 1, strlen(pattern) - 1);
368 if(strstrofs(strcat(",", pattern, ","), subpattern, 0) >= 0)
373 if(substring(pattern, 0, 1) == "+")
374 pattern = substring(pattern, 1, strlen(pattern) - 1);
375 if(strstrofs(strcat(",", pattern, ","), subpattern, 0) < 0)
380 strunzone(sbar_title[sbar_num_fields]);
381 sbar_title[sbar_num_fields] = strzone(str);
382 sbar_size[sbar_num_fields] = stringwidth(str, FALSE);
383 str = strtolower(str);
386 sbar_field[sbar_num_fields] = SP_PING;
387 } else if(str == "pl") {
388 sbar_field[sbar_num_fields] = SP_PL;
389 } else if(str == "name" || str == "nick") {
390 sbar_field[sbar_num_fields] = SP_NAME;
391 sbar_size[sbar_num_fields] = MIN_NAMELEN; // minimum size? any use?
393 } else if(str == "|") {
394 sbar_field[sbar_num_fields] = SP_SEPARATOR;
397 for(j = 0; j < MAX_SCORE; ++j)
398 if(str == strtolower(scores_label[j]))
399 goto found; // sorry, but otherwise fteqcc -O3 miscompiles this and warns about "unreachable code"
401 print(strcat("^1Error:^7 Unknown score field: '", str, "'\n"));
404 sbar_field[sbar_num_fields] = j;
407 if(j == ps_secondary)
413 if(scores_flags[ps_primary] & SFL_ALLOW_HIDE)
415 if(scores_flags[ps_secondary] & SFL_ALLOW_HIDE)
417 if(ps_primary == ps_secondary)
419 missing = !have_primary + !have_secondary + !have_separator + !have_name;
421 if(sbar_num_fields+missing < MAX_SBAR_FIELDS)
425 strunzone(sbar_title[sbar_num_fields]);
426 for(i = sbar_num_fields; i > 0; --i)
428 sbar_title[i] = sbar_title[i-1];
429 sbar_size[i] = sbar_size[i-1];
430 sbar_field[i] = sbar_field[i-1];
432 sbar_title[0] = strzone("name");
433 sbar_field[0] = SP_NAME;
434 sbar_size[0] = MIN_NAMELEN; // minimum size? any use?
436 print("fixed missing field 'name'\n");
440 strunzone(sbar_title[sbar_num_fields]);
441 for(i = sbar_num_fields; i > 1; --i)
443 sbar_title[i] = sbar_title[i-1];
444 sbar_size[i] = sbar_size[i-1];
445 sbar_field[i] = sbar_field[i-1];
447 sbar_title[1] = strzone("|");
448 sbar_field[1] = SP_SEPARATOR;
449 sbar_size[1] = stringwidth("|", FALSE);
451 print("fixed missing field '|'\n");
454 else if(!have_separator)
456 strunzone(sbar_title[sbar_num_fields]);
457 sbar_title[sbar_num_fields] = strzone("|");
458 sbar_size[sbar_num_fields] = stringwidth("|", FALSE);
459 sbar_field[sbar_num_fields] = SP_SEPARATOR;
461 print("fixed missing field '|'\n");
466 strunzone(sbar_title[sbar_num_fields]);
467 sbar_title[sbar_num_fields] = strzone(scores_label[ps_secondary]);
468 sbar_size[sbar_num_fields] = stringwidth(sbar_title[sbar_num_fields], FALSE);
469 sbar_field[sbar_num_fields] = ps_secondary;
471 print("fixed missing field '", scores_label[ps_secondary], "'\n");
476 strunzone(sbar_title[sbar_num_fields]);
477 sbar_title[sbar_num_fields] = strzone(scores_label[ps_primary]);
478 sbar_size[sbar_num_fields] = stringwidth(sbar_title[sbar_num_fields], FALSE);
479 sbar_field[sbar_num_fields] = ps_primary;
481 print("fixed missing field '", scores_label[ps_primary], "'\n");
485 sbar_field[sbar_num_fields] = SP_END;
489 vector sbar_field_rgb;
490 string Sbar_GetField(entity pl, float field)
492 float tmp, num, denom, f;
494 sbar_field_rgb = '1 1 1';
500 str = getplayerkey(pl.sv_entnum, "ping");
501 tmp = max(0, min(220, stof(str)-80)) / 220;
502 sbar_field_rgb = '1 1 1' - '0 1 1'*tmp;
508 str = getplayerkey(pl.sv_entnum, "pl");
511 tmp = bound(0, stof(str), 20) / 20; // 20% is REALLY BAD pl
512 sbar_field_rgb = '1 0.5 0.5' - '0 0.5 0.5'*tmp;
516 return getplayerkey(pl.sv_entnum, "name");
519 num = pl.(scores[SP_KILLS]);
520 denom = pl.(scores[SP_DEATHS]);
523 sbar_field_rgb = '0 1 0';
525 } else if(num <= 0) {
526 sbar_field_rgb = '1 0 0';
527 str = ftos(num/denom);
529 str = ftos(num/denom);
531 tmp = strstrofs(str, ".", 0);
533 str = substring(str, 0, tmp+2);
537 tmp = pl.(scores[field]);
538 f = scores_flags[field];
539 if(field == ps_primary)
540 sbar_field_rgb = '1 1 0';
541 else if(field == ps_secondary)
542 sbar_field_rgb = '0 1 1';
544 sbar_field_rgb = '1 1 1';
546 if(f & (SFL_HIDE_ZERO | SFL_RANK))
550 str = ftos(floor(tmp + 0.5));
552 if((num >= 2) && (substring(str, num - 2, 1) == "1"))
553 return strcat(str, "th");
554 else if(substring(str, num - 1, 1) == "1")
555 return strcat(str, "st");
556 else if(substring(str, num - 1, 1) == "2")
557 return strcat(str, "nd");
558 else if(substring(str, num - 1, 1) == "3")
559 return strcat(str, "rd");
561 return strcat(str, "th");
568 // shamelessly stolen from menu QC :P <- as if I would steal YOUR code pfft ;)
569 float textLengthUpToWidth(string theText, float maxWidth, float handleColors)
572 // The following function is SLOW.
573 // For your safety and for the protection of those around you...
574 // DO NOT CALL THIS AT HOME.
576 if(stringwidth(theText, handleColors) <= maxWidth)
577 return strlen(theText); // yeah!
579 // binary search for right place to cut string
580 float left, right, middle; // this always works
582 right = strlen(theText); // this always fails
585 middle = floor((left + right) / 2);
586 if(stringwidth(substring(theText, 0, middle), handleColors) <= maxWidth)
591 while(left < right - 1);
593 // NOTE: when color codes are involved, this binary search is,
594 // mathematically, BROKEN. However, it is obviously guaranteed to
595 // terminate, as the range still halves each time - but nevertheless, it is
596 // guaranteed that it finds ONE valid cutoff place (where "left" is in
597 // range, and "right" is outside).
601 string textShortenToWidth(string theText, float maxWidth, float handleColors)
603 if(stringwidth(theText, handleColors) <= maxWidth)
606 return strcat(substring(theText, 0, textLengthUpToWidth(theText, maxWidth - stringwidth("...", handleColors), handleColors)), "...");
609 float xmin, xmax, ymin, ymax, sbwidth, sbheight;
611 void Sbar_PrintScoreboardItem(vector pos, entity pl, float is_self)
617 is_spec = (GetPlayerColor(pl.sv_entnum) == COLOR_SPECTATOR);
624 tmp_y = sbar_fontsize_y;
625 drawfill(pos - '1 1 0', tmp + '2 2 0', '1 1 1', 0.3, DRAWFLAG_NORMAL);
629 for(i = 0; i < sbar_num_fields; ++i)
631 field = sbar_field[i];
632 if(field == SP_SEPARATOR)
635 if(is_spec && field != SP_NAME && field != SP_PING) {
636 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
639 str = Sbar_GetField(pl, field);
645 realsize = sbar_size[i];
646 if(i+1 < sbar_num_fields)
647 if(sbar_field[i+1] == SP_SEPARATOR)
649 realsize = (xmax - xmin) / sbar_fontsize_x;
650 for(j = 0; j < sbar_num_fields; ++j) if(j != i) if(sbar_field[j] != SP_SEPARATOR)
651 realsize -= sbar_size[j] + 1;
654 str = textShortenToWidth(str, realsize, TRUE);
656 len = stringwidth(str, TRUE);
658 if(sbar_size[i] < len)
661 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
663 if(field == SP_NAME) {
664 tmp_x = sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
665 drawcolorcodedstring(pos - tmp, str, sbar_fontsize, 1, DRAWFLAG_NORMAL);
667 tmp_x = len*sbar_fontsize_x + sbar_fontsize_x;
668 drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, 1, DRAWFLAG_NORMAL);
672 if(sbar_field[i] == SP_SEPARATOR)
675 for(i = sbar_num_fields-1; i > 0; --i)
677 field = sbar_field[i];
678 if(field == SP_SEPARATOR)
681 if(is_spec && field != SP_NAME && field != SP_PING) {
682 pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
686 str = Sbar_GetField(pl, field);
689 str = textShortenToWidth(str, sbar_size[i], TRUE);
690 len = stringwidth(str, TRUE);
692 if(sbar_size[i] < len)
695 if(field == SP_NAME) {
696 tmp_x = sbar_fontsize_x*len; // left or right aligned? let's put it right...
697 drawcolorcodedstring(pos - tmp, str, sbar_fontsize, 1, DRAWFLAG_NORMAL);
699 tmp_x = sbar_fontsize_x*len; //strlen(str);
700 drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, 1, DRAWFLAG_NORMAL);
702 pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
708 void Sbar_DrawScoreboard()
710 //float xmin, ymin, xmax, ymax;
711 vector rgb, pos, tmp, sbar_save;
716 if(time > lastpingstime + 10)
719 lastpingstime = time;
722 sbar_fontsize = Sbar_GetFontsize();
723 if(sbar_fontsize_x == 0)
724 sbar_fontsize = '8 8 0';
725 if(sbar_fontsize_y == 0)
726 sbar_fontsize_y = sbar_fontsize_x;
728 xmin = vid_conwidth / 5;
731 xmax = vid_conwidth - xmin;
732 ymax = vid_conheight - 0.2*vid_conheight;
734 sbwidth = xmax - xmin;
735 sbheight = ymax - ymin;
737 center_x = xmin + 0.5*sbwidth;
739 //Sbar_UpdateFields();
741 // Initializes position
747 drawfont = sbar_bigfont;
748 pos_x = center_x - stringwidth("Scoreboard", TRUE)*0.5*24;
749 drawstring(pos, "Scoreboard", '24 24 0', '1 1 1', 1, DRAWFLAG_NORMAL);
753 // Titlebar background:
755 tmp_y = sbar_fontsize_y;
756 drawfill(pos - '1 1 0', tmp + '2 2 0', '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
758 drawfont = sbar_font;
760 for(i = 0; i < sbar_num_fields; ++i)
762 if(sbar_field[i] == SP_SEPARATOR)
764 drawstring(pos, sbar_title[i], sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
765 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
768 if(sbar_field[i] == SP_SEPARATOR)
770 pos_x = xmax + sbar_fontsize_x;
772 for(i = sbar_num_fields-1; i > 0; --i)
774 if(sbar_field[i] == SP_SEPARATOR)
777 pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
780 * Using the following line will fuck it all up:
782 * tmp_x = sbar_size[i] - strlen(sbar_title[i])*8;
784 tmp_x = sbar_fontsize_x*sbar_size[i];
785 tmp_x -= stringwidth(sbar_title[i], FALSE)*sbar_fontsize_x;
786 drawstring(pos + tmp, sbar_title[i], sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
791 pos_y += 1.5 * sbar_fontsize_y;
798 //for(tm = sortedTeams.sort_next; tm; tm = tm.sort_next)
799 for(tm = teams.sort_next; tm; tm = tm.sort_next)
801 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
804 rgb = GetTeamRGB(tm.team);
809 pos - '6.5 0 0' * sbar_fontsize_y,
810 tm.(teamscores[ts_primary]),
811 4, sbar_fontsize_y * 1.5, rgb, 1, DRAWFLAG_NORMAL);
813 if(ts_primary != ts_secondary)
815 pos - '4.5 0 0' * sbar_fontsize_y + '0 1.5 0' * sbar_fontsize_y,
816 tm.(teamscores[ts_secondary]),
817 4, sbar_fontsize_y * 1, rgb, 1, DRAWFLAG_NORMAL);
819 specs = tm.team_size;
825 tmp_y = 1.25 * sbar_fontsize_y * specs;
826 drawfill(pos - '1 1 0', tmp + '2 0 0', rgb, 0.2, DRAWFLAG_NORMAL);
828 for(pl = players.sort_next; pl; pl = pl.sort_next)
830 if(pl.team != tm.team)
832 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
833 pos_y += 1.25 * sbar_fontsize_y;
834 tmp_y -= 1.25 * sbar_fontsize_y;
836 pos_y += tmp_y + 1.5 * sbar_fontsize_y;
838 // rgb := tempvector :)
839 rgb = pos + '0 1.5 0' * sbar_fontsize_y;
840 pos_y += 3 * sbar_fontsize_y;
842 for(pl = players.sort_next; pl; pl = pl.sort_next)
844 if(pl.team != COLOR_SPECTATOR)
846 //drawcolorcodedstring(pos, getplayerkey(pl.sb_player, "name"), '8 8 0', 1, 0);
847 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
848 pos += '0 1.25 0' * sbar_fontsize_y;
853 drawstring(rgb, "Spectators", sbar_fontsize, '1 1 1', 1, 0);
856 for(pl = players.sort_next; pl; pl = pl.sort_next)
858 if(pl.team == COLOR_SPECTATOR)
860 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
861 pos_y += 1.25 * sbar_fontsize_y;
862 tmp_y -= 1.25 * sbar_fontsize_y;
865 // rgb := tempvector :)
866 rgb = pos + '0 1.5 0' * sbar_fontsize_y;
867 pos_y += 3 * sbar_fontsize_y;
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 += '0 1.25 0' * sbar_fontsize_y;
879 drawstring(rgb, "Spectators", sbar_fontsize, '1 1 1', 1, 0);
884 str = strcat("playing on ^2", shortmapname, "^7");
885 tl = getstatf(STAT_TIMELIMIT);
886 fl = getstatf(STAT_FRAGLIMIT);
887 if(gametype == GAME_LMS)
890 str = strcat(str, " for up to ^1", ftos(tl), " minutes^7");
895 str = strcat(str, " for ^1", ftos(tl), " minutes^7");
899 str = strcat(str, " or");
900 str = strcat(str, " until ^3", ftos(fl));
901 if(scores_label[ps_primary] == "score")
902 str = strcat(str, " points^7");
904 str = strcat(str, " ", scores_label[ps_primary]);
908 pos_y += 1.5 * sbar_fontsize_y;
909 drawcolorcodedstring(pos + '0.5 0 0' * (sbwidth - sbar_fontsize_x * stringwidth(str, TRUE)), str, sbar_fontsize, 0.8, 0);
914 void Sbar_Score(float margin)
916 float timelimit, timeleft, minutes, seconds, distribution, myplace, score;
917 vector sbar_save, place;
921 myteam = GetPlayerColor(player_localentnum - 1);
923 sbar_y = vid_conheight - (32+12);
934 //for(i = 0; i < 4; ++i)
935 for(tm = teams.sort_next; tm; tm = tm.sort_next)
937 if(tm.team == COLOR_SPECTATOR || !tm.team_size) // no players? don't display
940 score = tm.(teamscores[ts_primary]);
941 if(tm.team == myteam)
942 Sbar_DrawXNum('-128 0 0', score, 4, 32, GetTeamRGB(tm.team), 1, DRAWFLAG_NORMAL);
945 Sbar_DrawXNum(place, score, 4, 12, GetTeamRGB(tm.team), 1, DRAWFLAG_NORMAL);
950 // me vector := [team/connected frags id]
952 for(me = players.sort_next; me; me = me.sort_next)
954 if(me.team != COLOR_SPECTATOR)
956 if(me.sv_entnum == player_localentnum - 1)
964 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
969 Sbar_DrawXNum('-36 -12 0', myplace, 3, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
970 else if(myplace == 2)
971 Sbar_DrawXNum('-36 -12 0', myplace, 3, 12, '1 1 0', 1, DRAWFLAG_NORMAL);
973 Sbar_DrawXNum('-36 -12 0', myplace, 3, 12, '1 0 0', 1, DRAWFLAG_NORMAL);
975 score = me.(scores[ps_primary]);
976 if(distribution >= 0)
978 Sbar_DrawXNum('-84 -12 0', distribution, 4, 12, ' 1 1 1', 1, DRAWFLAG_NORMAL);
979 Sbar_DrawXNum('-128 0 0', score, 4, 32, '1 1 1', 1, DRAWFLAG_NORMAL);
980 } else if(distribution >= -5)
982 Sbar_DrawXNum('-84 -12 0', distribution, 4, 12, ' 1 1 0', 1, DRAWFLAG_NORMAL);
983 Sbar_DrawXNum('-128 0 0', score, 4, 32, '1 1 0', 1, DRAWFLAG_NORMAL);
985 Sbar_DrawXNum('-84 -12 0', distribution, 4, 12, ' 1 0 0', 1, DRAWFLAG_NORMAL);
986 Sbar_DrawXNum('-128 0 0', score, 4, 32, '1 0 0', 1, DRAWFLAG_NORMAL);
989 timelimit = getstatf(STAT_TIMELIMIT);
992 timeleft = max(0, timelimit * 60 - time);
993 minutes = floor(timeleft / 60);
994 seconds = floor(timeleft - minutes*60);
997 Sbar_DrawXNum('-72 32 0', minutes, 3, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
998 drawpic(sbar + '-36 32 0', "gfx/num_colon", '12 12 0', '1 1 1', sbar_alpha_fg, 0);
999 Sbar_DrawXNum('-24 32 0', seconds, -2, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
1000 } else if(minutes >= 1)
1002 Sbar_DrawXNum('-72 32 0', minutes, 3, 12, '1 1 0', 1, DRAWFLAG_NORMAL);
1003 drawpic(sbar + '-36 32 0', "gfx/num_colon", '12 12 0', '1 1 0', sbar_alpha_fg, 0);
1004 Sbar_DrawXNum('-24 32 0', seconds, -2, 12, '1 1 0', 1, DRAWFLAG_NORMAL);
1006 Sbar_DrawXNum('-24 32 0', seconds, -2, 12, '1 0 0', 1, DRAWFLAG_NORMAL);
1009 minutes = floor(time / 60);
1010 seconds = floor(time - minutes*60);
1011 Sbar_DrawXNum('-72 32 0', minutes, 3, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
1012 drawpic(sbar + '-36 32 0', "gfx/num_colon", '12 12 0', '1 1 1', sbar_alpha_fg, 0);
1013 Sbar_DrawXNum('-24 32 0', seconds, -2, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
1018 void Sbar_MiniscoreItem(vector pos, entity pl, float is_self)
1024 drawfill(pos + '0 1 0', '40 6 0', GetTeamRGB(pl.team)*0.5, 1, DRAWFLAG_NORMAL);
1026 drawfill(pos + '0 1 0', '40 6 0', '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
1029 score = pl.(scores[ps_primary]);
1030 pos_x -= stringwidth(ftos(score), FALSE)*8;
1031 drawstring(pos, ftos(score), '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1036 drawstring(pos, "\x0D", '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1040 drawcolorcodedstring(pos, getplayerkey(pl.sv_entnum, "name"), '8 8 0', 1, 0);
1043 void Sbar_MiniscoreTeamItem(vector pos, float color, float frags, float is_self)
1049 drawfill(pos + '0 1 0', '40 6 0', GetTeamRGB(color)*0.5, 1, DRAWFLAG_NORMAL);
1051 drawfill(pos + '0 1 0', '40 6 0', '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
1054 pos_x -= stringwidth(ftos(frags), FALSE)*8;
1055 drawstring(pos, ftos(frags), '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1060 drawstring(pos, "\x0D", '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1064 drawstring(pos, GetTeamName(color), '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1067 void Sbar_MiniDeathmatchOverlay(vector pos)
1069 float numlines, up, down, score;
1071 float miniscoreboard_size;
1072 miniscoreboard_size = cvar("sbar_miniscoreboard_size");
1074 if(miniscoreboard_size == 0)
1076 pos_y = vid_conheight - 8;
1078 if(miniscoreboard_size < 0)
1079 numlines = (vid_conheight - sbar_y + 7) / 8;
1081 numlines = miniscoreboard_size;
1083 // give up if there isn't enough room
1084 if(pos_x >= vid_conwidth || pos_y >= vid_conheight || numlines < 1)
1087 // me vector := [team/connected frags id]
1088 for(me = players.sort_next; me; me = me.sort_next)
1090 if(me.sv_entnum == player_localentnum - 1)
1095 numlines -= numteams;
1097 // figure out how many players above and below we can show
1098 up = floor(numlines/2);
1100 if((up + down) > numlines)
1101 down = numlines - up;
1104 for(pl = me.sort_next; pl && down > 0; pl = pl.sort_next)
1106 if(pl.team == COLOR_SPECTATOR)
1108 Sbar_MiniscoreItem(pos, pl, false);
1112 Sbar_MiniscoreItem(pos, me, true);
1114 up += down; // if there weren't enough lines below... add them
1115 for(pl = me.sort_prev; pl && up > 0; pl = pl.sort_prev)
1117 if(pl.team == COLOR_SPECTATOR)
1119 Sbar_MiniscoreItem(pos, pl, false);
1126 for(tm = teams.sort_next; tm.sort_next; tm = tm.sort_next);
1127 for(; tm; tm = tm.sort_prev)
1129 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
1131 score = tm.(teamscores[ts_primary]);
1132 Sbar_MiniscoreTeamItem(pos, tm.team, score, (tm.team == me.team));
1138 float Sbar_WouldDrawScoreboard ()
1142 else if (intermission == 1)
1144 else if (intermission == 2)
1149 void Sbar_Draw (void)
1156 Sbar_UpdatePlayerTeams();
1161 Sbar_DrawScoreboard();
1162 else if (intermission == 1)
1164 Sbar_DrawScoreboard();
1167 else if (intermission == 2)
1168 Sbar_FinaleOverlay();
1171 if (sb_showscores || (getstati(STAT_HEALTH) <= 0 && cvar("cl_deathscoreboard")))
1173 sbar_x = (vid_conwidth - 640.0)*0.5;
1174 sbar_y = vid_conheight - 47;
1175 //Sbar_DrawAlphaPic (sbar_x, sbar_y, sb_scorebar, sbar_alpha_bg.value);
1176 //drawpic('0 0 0', "gfx/scorebar", '0 0 0', '1 1 1', cvar("sbar_alpha_bg"), 0);
1177 Sbar_DrawScoreboard ();
1181 if (sb_lines && sbar_hudselector == 1)
1183 stat_items = getstati(STAT_ITEMS);
1185 sbar_x = (vid_conwidth - 320.0)*0.5;
1186 sbar_y = vid_conheight - 24.0 - 16.0;
1189 fade = 3.2 - 2 * (time - weapontime);
1190 fade = bound(0.7, fade, 1);
1193 for(i = 0; i < 8; ++i)
1197 Sbar_DrawWeapon(i+1, fade, (i + 2 == activeweapon));
1204 Sbar_DrawWeapon(0, fade, (activeweapon == 1));
1208 x = getstati(STAT_ARMOR);
1212 //Sbar_DrawStretchPic (72, 0, sb_armor[0], sbar_alpha_fg.value, 24, 24);
1213 drawpic(sbar + '72 0 0', "gfx/sb_armor", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1215 Sbar_DrawXNum('0 0 0', x, 3, 24, '0 1 0', 1, 0);
1217 Sbar_DrawXNum('0 0 0', x, 3, 24, '0.2 1 0', 1, 0);
1219 Sbar_DrawXNum('0 0 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1221 Sbar_DrawXNum('0 0 0', x, 3, 24, '1 1 0.2', 1, 0);
1223 Sbar_DrawXNum('0 0 0', x, 3, 24, '0.7 0 0', 1, 0);
1227 x = getstati(STAT_HEALTH);
1231 //Sbar_DrawStretchPic (184, 0, sb_health, sbar_alpha_fg.value, 24, 24);
1232 drawpic(sbar + '184 0 0', "gfx/sb_health", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1234 Sbar_DrawXNum('112 0 0', x, 3, 24, '0 1 0', 1, 0);
1236 Sbar_DrawXNum('112 0 0', x, 3, 24, '0.2 1 0', 1, 0);
1238 Sbar_DrawXNum('112 0 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1240 Sbar_DrawXNum('112 0 0', x, 3, 24, '1 1 0.2', 1, 0);
1242 Sbar_DrawXNum('112 0 0', x, 3, 24, '0.7 0 0', 1, 0);
1246 x = getstati(STAT_AMMO);
1247 if ((stat_items & (NEX_IT_SHELLS | NEX_IT_BULLETS | NEX_IT_ROCKETS | NEX_IT_CELLS)) || x != 0)
1249 if (stat_items & NEX_IT_SHELLS)
1250 drawpic(sbar + '296 0 0', "gfx/sb_shells", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1251 else if (stat_items & NEX_IT_BULLETS)
1252 drawpic(sbar + '296 0 0', "gfx/sb_bullets", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1253 else if (stat_items & NEX_IT_ROCKETS)
1254 drawpic(sbar + '296 0 0', "gfx/sb_rocket", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1255 else if (stat_items & NEX_IT_CELLS)
1256 drawpic(sbar + '296 0 0', "gfx/sb_cells", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1258 Sbar_DrawXNum('224 0 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1260 Sbar_DrawXNum('224 0 0', x, 3, 24, '0.7 0 0', 1, 0);
1263 if (sbar_x + 320 + 160 <= vid_conwidth)
1264 Sbar_MiniDeathmatchOverlay(sbar + '320 0 0');
1267 // The margin can be at most 8 to support 640x480 console size:
1268 // 320 + 2 * (144 + 16) = 640
1273 stat_items = getstati(STAT_ITEMS);
1275 sbar_x = (vid_conwidth - 640.0)*0.5;
1276 sbar_y = vid_conheight - 47;
1279 fade = 3 - 2 * (time - weapontime);
1282 for(i = 0; i < 8; ++i)
1286 Sbar_DrawWeapon(i+1, fade, (i + 2 == activeweapon));
1293 Sbar_DrawWeapon(0, fade, (activeweapon == 1));
1297 drawpic(sbar, "gfx/sbar", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1299 drawpic(sbar, "gfx/sbar_minimal", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1303 Sbar_DrawXNum('268 12 0', getstati(STAT_ARMOR), 3, 24, '0.6 0.7 0.8', 1, 0);
1307 x = getstati(STAT_HEALTH);
1309 Sbar_DrawXNum('82 12 0', x, 3, 24, '1 1 1', 1, 0);
1310 else if(x <= 25 && time - floor(time) > 0.5)
1311 Sbar_DrawXNum('82 12 0', x, 3, 24, '0.7 0 0', 1, 0);
1313 Sbar_DrawXNum('81 12 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1315 // AK dont draw ammo for the laser
1316 x = getstati(STAT_AMMO);
1317 if(activeweapon != 12)
1320 if (stat_items & NEX_IT_SHELLS)
1321 drawpic(sbar + '519 0 0', "gfx/sb_shells", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1322 else if (stat_items & NEX_IT_BULLETS)
1323 drawpic(sbar + '519 0 0', "gfx/sb_bullets", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1324 else if (stat_items & NEX_IT_ROCKETS)
1325 drawpic(sbar + '519 0 0', "gfx/sb_rocket", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1326 else if (stat_items & NEX_IT_CELLS)
1327 drawpic(sbar + '519 0 0', "gfx/sb_cells", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1329 Sbar_DrawXNum('447 12 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1331 Sbar_DrawXNum('447 12 0', x, 3, 24, '0.7 0 0', 1, 0);
1335 drawpic(sbar, "gfx/sbar_overlay", '0 0 0', '1 1 1', 1, DRAWFLAG_MODULATE);
1337 if (sbar_x + 600 + 160 <= vid_conwidth)
1338 Sbar_MiniDeathmatchOverlay (sbar + '600 0 0');
1343 // Mini scoreboard uses 12*4 per other team, that is, 144
1344 // pixels when there are four teams...
1345 // Nexuiz by default sets vid_conwidth to 800... makes
1347 // so we need to shift it by 64 pixels to the right to fit
1348 // BUT: then it overlaps with the image that gets drawn
1349 // for viewsize 100! Therefore, just account for 3 teams,
1350 // that is, 96 pixels mini scoreboard size, needing 16 pixels
1355 if(gametype == GAME_KEYHUNT)
1358 } else if(gametype == GAME_CTF)
1366 void CSQC_ctf_hud(void)
1368 // cvar("sbar_flagstatus_right") move the flag icons right
1369 // cvar("sbar_flagstatus_pos") pixel position of the nexuiz flagstatus icons
1370 float redflag, blueflag;
1374 stat_items = getstati(STAT_ITEMS);
1375 redflag = (stat_items/32768) & 3;
1376 blueflag = (stat_items/131072) & 3;
1380 * For some reason now not even THAT works there...
1381 * Maybe the minus' precedence screws it up? The last one there, maybe I should use brackets
1383 * pos_x = (cvar("sbar_flagstatus_right")) ? vid_conwidth - 10 - sbar_x - 64 : 10 - sbar_x;
1384 ** Should try those later:
1385 * pos_x = (cvar("sbar_flagstatus_right")) ? (vid_conwidth - 10 - sbar_x - 64) : (10 - sbar_x);
1386 * pos_x = ( (cvar("sbar_flagstatus_right")) ? vid_conwidth - 10 - 64 : 10 ) - sbar_x;
1389 if(cvar("sbar_flagstatus_right"))
1390 pos_x = vid_conwidth - 10 - sbar_x - 64;
1392 pos_x = 10 - sbar_x;
1396 if(sbar_hudselector == 1)
1397 pos_y = (vid_conheight - sbar_y) - cvar("sbar_flagstatus_pos") - 64;
1405 case 1: drawpic(pos, "gfx/sb_flag_red_taken", '0 0 0', '1 1 1', 1, DRAWFLAG_NORMAL); break;
1406 case 2: drawpic(pos, "gfx/sb_flag_red_lost", '0 0 0', '1 1 1', 1, DRAWFLAG_NORMAL); break;
1407 case 3: drawpic(pos, "gfx/sb_flag_red_carrying", '0 0 0', '1 1 1', 1, DRAWFLAG_NORMAL); break;
1414 case 1: drawpic(pos, "gfx/sb_flag_blue_taken", '0 0 0', '1 1 1', 1, 0); break;
1415 case 2: drawpic(pos, "gfx/sb_flag_blue_lost", '0 0 0', '1 1 1', 1, 0); break;
1416 case 3: drawpic(pos, "gfx/sb_flag_blue_carrying", '0 0 0', '1 1 1', 1, 0); break;