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 == "name" || str == "nick") {
399 sbar_field[sbar_num_fields] = SP_NAME;
400 sbar_size[sbar_num_fields] = MIN_NAMELEN; // minimum size? any use?
402 } else if(str == "|") {
403 sbar_field[sbar_num_fields] = SP_SEPARATOR;
406 for(j = 0; j < MAX_SCORE; ++j)
407 if(str == strtolower(scores_label[j]))
408 goto found; // sorry, but otherwise fteqcc -O3 miscompiles this and warns about "unreachable code"
410 print(strcat("^1Error:^7 Unknown score field: '", str, "'\n"));
413 sbar_field[sbar_num_fields] = j;
416 if(j == ps_secondary)
422 if(scores_flags[ps_primary] & SFL_ALLOW_HIDE)
424 if(scores_flags[ps_secondary] & SFL_ALLOW_HIDE)
426 if(ps_primary == ps_secondary)
428 missing = !have_primary + !have_secondary + !have_separator + !have_name;
430 if(sbar_num_fields+missing < MAX_SBAR_FIELDS)
434 strunzone(sbar_title[sbar_num_fields]);
435 for(i = sbar_num_fields; i > 0; --i)
437 sbar_title[i] = sbar_title[i-1];
438 sbar_size[i] = sbar_size[i-1];
439 sbar_field[i] = sbar_field[i-1];
441 sbar_title[0] = strzone("name");
442 sbar_field[0] = SP_NAME;
443 sbar_size[0] = MIN_NAMELEN; // minimum size? any use?
445 print("fixed missing field 'name'\n");
449 strunzone(sbar_title[sbar_num_fields]);
450 for(i = sbar_num_fields; i > 1; --i)
452 sbar_title[i] = sbar_title[i-1];
453 sbar_size[i] = sbar_size[i-1];
454 sbar_field[i] = sbar_field[i-1];
456 sbar_title[1] = strzone("|");
457 sbar_field[1] = SP_SEPARATOR;
458 sbar_size[1] = stringwidth("|", FALSE);
460 print("fixed missing field '|'\n");
463 else if(!have_separator)
465 strunzone(sbar_title[sbar_num_fields]);
466 sbar_title[sbar_num_fields] = strzone("|");
467 sbar_size[sbar_num_fields] = stringwidth("|", FALSE);
468 sbar_field[sbar_num_fields] = SP_SEPARATOR;
470 print("fixed missing field '|'\n");
475 strunzone(sbar_title[sbar_num_fields]);
476 sbar_title[sbar_num_fields] = strzone(scores_label[ps_secondary]);
477 sbar_size[sbar_num_fields] = stringwidth(sbar_title[sbar_num_fields], FALSE);
478 sbar_field[sbar_num_fields] = ps_secondary;
480 print("fixed missing field '", scores_label[ps_secondary], "'\n");
485 strunzone(sbar_title[sbar_num_fields]);
486 sbar_title[sbar_num_fields] = strzone(scores_label[ps_primary]);
487 sbar_size[sbar_num_fields] = stringwidth(sbar_title[sbar_num_fields], FALSE);
488 sbar_field[sbar_num_fields] = ps_primary;
490 print("fixed missing field '", scores_label[ps_primary], "'\n");
494 sbar_field[sbar_num_fields] = SP_END;
498 vector sbar_field_rgb;
499 string Sbar_GetField(entity pl, float field)
501 float tmp, num, denom, f;
503 sbar_field_rgb = '1 1 1';
508 return "\x8D\x8D\x8D"; // >>> sign
509 str = getplayerkey(pl.sv_entnum, "ping");
512 tmp = max(0, min(220, stof(str)-80)) / 220;
513 sbar_field_rgb = '1 1 1' - '0 1 1'*tmp;
519 str = getplayerkey(pl.sv_entnum, "pl");
522 tmp = bound(0, stof(str), 20) / 20; // 20% is REALLY BAD pl
523 sbar_field_rgb = '1 0.5 0.5' - '0 0.5 0.5'*tmp;
527 return getplayerkey(pl.sv_entnum, "name");
530 num = pl.(scores[SP_KILLS]);
531 denom = pl.(scores[SP_DEATHS]);
534 sbar_field_rgb = '0 1 0';
536 } else if(num <= 0) {
537 sbar_field_rgb = '1 0 0';
538 str = ftos(num/denom);
540 str = ftos(num/denom);
542 tmp = strstrofs(str, ".", 0);
544 str = substring(str, 0, tmp+2);
548 tmp = pl.(scores[field]);
549 f = scores_flags[field];
550 if(field == ps_primary)
551 sbar_field_rgb = '1 1 0';
552 else if(field == ps_secondary)
553 sbar_field_rgb = '0 1 1';
555 sbar_field_rgb = '1 1 1';
557 if(f & (SFL_HIDE_ZERO | SFL_RANK))
561 str = ftos(floor(tmp + 0.5));
563 if((num >= 2) && (substring(str, num - 2, 1) == "1"))
564 return strcat(str, "th");
565 else if(substring(str, num - 1, 1) == "1")
566 return strcat(str, "st");
567 else if(substring(str, num - 1, 1) == "2")
568 return strcat(str, "nd");
569 else if(substring(str, num - 1, 1) == "3")
570 return strcat(str, "rd");
572 return strcat(str, "th");
579 // shamelessly stolen from menu QC :P <- as if I would steal YOUR code pfft ;)
580 float textLengthUpToWidth(string theText, float maxWidth, float handleColors)
583 // The following function is SLOW.
584 // For your safety and for the protection of those around you...
585 // DO NOT CALL THIS AT HOME.
587 if(stringwidth(theText, handleColors) <= maxWidth)
588 return strlen(theText); // yeah!
590 // binary search for right place to cut string
591 float left, right, middle; // this always works
593 right = strlen(theText); // this always fails
596 middle = floor((left + right) / 2);
597 if(stringwidth(substring(theText, 0, middle), handleColors) <= maxWidth)
602 while(left < right - 1);
604 // NOTE: when color codes are involved, this binary search is,
605 // mathematically, BROKEN. However, it is obviously guaranteed to
606 // terminate, as the range still halves each time - but nevertheless, it is
607 // guaranteed that it finds ONE valid cutoff place (where "left" is in
608 // range, and "right" is outside).
612 string textShortenToWidth(string theText, float maxWidth, float handleColors)
614 if(stringwidth(theText, handleColors) <= maxWidth)
617 return strcat(substring(theText, 0, textLengthUpToWidth(theText, maxWidth - stringwidth("...", handleColors), handleColors)), "...");
620 float xmin, xmax, ymin, ymax, sbwidth, sbheight;
622 void Sbar_PrintScoreboardItem(vector pos, entity pl, float is_self)
628 is_spec = (GetPlayerColor(pl.sv_entnum) == COLOR_SPECTATOR);
635 tmp_y = sbar_fontsize_y;
636 drawfill(pos - '1 1 0', tmp + '2 2 0', '1 1 1', 0.3, DRAWFLAG_NORMAL);
640 for(i = 0; i < sbar_num_fields; ++i)
642 field = sbar_field[i];
643 if(field == SP_SEPARATOR)
646 if(is_spec && field != SP_NAME && field != SP_PING) {
647 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
650 str = Sbar_GetField(pl, field);
656 realsize = sbar_size[i];
657 if(i+1 < sbar_num_fields)
658 if(sbar_field[i+1] == SP_SEPARATOR)
660 realsize = (xmax - xmin) / sbar_fontsize_x;
661 for(j = 0; j < sbar_num_fields; ++j) if(j != i) if(sbar_field[j] != SP_SEPARATOR)
662 realsize -= sbar_size[j] + 1;
665 str = textShortenToWidth(str, realsize, TRUE);
667 len = stringwidth(str, TRUE);
669 if(sbar_size[i] < len)
672 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
674 if(field == SP_NAME) {
675 tmp_x = sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
676 drawcolorcodedstring(pos - tmp, str, sbar_fontsize, 1, DRAWFLAG_NORMAL);
678 tmp_x = len*sbar_fontsize_x + sbar_fontsize_x;
679 drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, 1, DRAWFLAG_NORMAL);
683 if(sbar_field[i] == SP_SEPARATOR)
686 for(i = sbar_num_fields-1; i > 0; --i)
688 field = sbar_field[i];
689 if(field == SP_SEPARATOR)
692 if(is_spec && field != SP_NAME && field != SP_PING) {
693 pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
697 str = Sbar_GetField(pl, field);
700 str = textShortenToWidth(str, sbar_size[i], TRUE);
701 len = stringwidth(str, TRUE);
703 if(sbar_size[i] < len)
706 if(field == SP_NAME) {
707 tmp_x = sbar_fontsize_x*len; // left or right aligned? let's put it right...
708 drawcolorcodedstring(pos - tmp, str, sbar_fontsize, 1, DRAWFLAG_NORMAL);
710 tmp_x = sbar_fontsize_x*len; //strlen(str);
711 drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, 1, DRAWFLAG_NORMAL);
713 pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
719 void Sbar_DrawScoreboard()
721 //float xmin, ymin, xmax, ymax;
722 vector rgb, pos, tmp, sbar_save;
727 if(time > lastpingstime + 10)
730 lastpingstime = time;
733 sbar_fontsize = Sbar_GetFontsize();
734 if(sbar_fontsize_x == 0)
735 sbar_fontsize = '8 8 0';
736 if(sbar_fontsize_y == 0)
737 sbar_fontsize_y = sbar_fontsize_x;
739 xmin = vid_conwidth / 5;
742 xmax = vid_conwidth - xmin;
743 ymax = vid_conheight - 0.2*vid_conheight;
745 sbwidth = xmax - xmin;
746 sbheight = ymax - ymin;
748 center_x = xmin + 0.5*sbwidth;
750 //Sbar_UpdateFields();
752 // Initializes position
758 drawfont = sbar_bigfont;
759 pos_x = center_x - stringwidth("Scoreboard", TRUE)*0.5*24;
760 drawstring(pos, "Scoreboard", '24 24 0', '1 1 1', 1, DRAWFLAG_NORMAL);
764 // Titlebar background:
766 tmp_y = sbar_fontsize_y;
767 drawfill(pos - '1 1 0', tmp + '2 2 0', '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
769 drawfont = sbar_font;
771 for(i = 0; i < sbar_num_fields; ++i)
773 if(sbar_field[i] == SP_SEPARATOR)
775 drawstring(pos, sbar_title[i], sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
776 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
779 if(sbar_field[i] == SP_SEPARATOR)
781 pos_x = xmax + sbar_fontsize_x;
783 for(i = sbar_num_fields-1; i > 0; --i)
785 if(sbar_field[i] == SP_SEPARATOR)
788 pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
791 * Using the following line will fuck it all up:
793 * tmp_x = sbar_size[i] - strlen(sbar_title[i])*8;
795 tmp_x = sbar_fontsize_x*sbar_size[i];
796 tmp_x -= stringwidth(sbar_title[i], FALSE)*sbar_fontsize_x;
797 drawstring(pos + tmp, sbar_title[i], sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
802 pos_y += 1.5 * sbar_fontsize_y;
809 //for(tm = sortedTeams.sort_next; tm; tm = tm.sort_next)
810 for(tm = teams.sort_next; tm; tm = tm.sort_next)
812 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
815 rgb = GetTeamRGB(tm.team);
820 pos - '6.5 0 0' * sbar_fontsize_y,
821 tm.(teamscores[ts_primary]),
822 4, sbar_fontsize_y * 1.5, rgb, 1, DRAWFLAG_NORMAL);
824 if(ts_primary != ts_secondary)
826 pos - '4.5 0 0' * sbar_fontsize_y + '0 1.5 0' * sbar_fontsize_y,
827 tm.(teamscores[ts_secondary]),
828 4, sbar_fontsize_y * 1, rgb, 1, DRAWFLAG_NORMAL);
830 specs = tm.team_size;
836 tmp_y = 1.25 * sbar_fontsize_y * specs;
837 drawfill(pos - '1 1 0', tmp + '2 0 0', rgb, 0.2, DRAWFLAG_NORMAL);
839 for(pl = players.sort_next; pl; pl = pl.sort_next)
841 if(pl.team != tm.team)
843 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
844 pos_y += 1.25 * sbar_fontsize_y;
845 tmp_y -= 1.25 * sbar_fontsize_y;
847 pos_y += tmp_y + 1.5 * sbar_fontsize_y;
849 // rgb := tempvector :)
850 rgb = pos + '0 1.5 0' * sbar_fontsize_y;
851 pos_y += 3 * sbar_fontsize_y;
853 for(pl = players.sort_next; pl; pl = pl.sort_next)
855 if(pl.team != COLOR_SPECTATOR)
857 //drawcolorcodedstring(pos, getplayerkey(pl.sb_player, "name"), '8 8 0', 1, 0);
858 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
859 pos += '0 1.25 0' * sbar_fontsize_y;
864 drawstring(rgb, "Spectators", sbar_fontsize, '1 1 1', 1, 0);
867 for(pl = players.sort_next; pl; pl = pl.sort_next)
869 if(pl.team == COLOR_SPECTATOR)
871 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
872 pos_y += 1.25 * sbar_fontsize_y;
873 tmp_y -= 1.25 * sbar_fontsize_y;
876 // rgb := tempvector :)
877 rgb = pos + '0 1.5 0' * sbar_fontsize_y;
878 pos_y += 3 * sbar_fontsize_y;
880 for(pl = players.sort_next; pl; pl = pl.sort_next)
882 if(pl.team != COLOR_SPECTATOR)
884 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
885 pos += '0 1.25 0' * sbar_fontsize_y;
890 drawstring(rgb, "Spectators", sbar_fontsize, '1 1 1', 1, 0);
895 str = strcat("playing on ^2", shortmapname, "^7");
896 tl = getstatf(STAT_TIMELIMIT);
897 fl = getstatf(STAT_FRAGLIMIT);
898 if(gametype == GAME_LMS)
901 str = strcat(str, " for up to ^1", ftos(tl), " minutes^7");
906 str = strcat(str, " for ^1", ftos(tl), " minutes^7");
910 str = strcat(str, " or");
911 str = strcat(str, " until ^3", ftos(fl));
912 if(scores_label[ps_primary] == "score")
913 str = strcat(str, " points^7");
915 str = strcat(str, " ", scores_label[ps_primary]);
919 pos_y += 1.5 * sbar_fontsize_y;
920 drawcolorcodedstring(pos + '0.5 0 0' * (sbwidth - sbar_fontsize_x * stringwidth(str, TRUE)), str, sbar_fontsize, 0.8, 0);
925 void Sbar_Score(float margin)
927 float timelimit, timeleft, minutes, seconds, distribution, myplace, score;
928 vector sbar_save, place;
932 myteam = GetPlayerColor(player_localentnum - 1);
934 sbar_y = vid_conheight - (32+12);
945 //for(i = 0; i < 4; ++i)
946 for(tm = teams.sort_next; tm; tm = tm.sort_next)
948 if(tm.team == COLOR_SPECTATOR || !tm.team_size) // no players? don't display
951 score = tm.(teamscores[ts_primary]);
952 if(tm.team == myteam)
953 Sbar_DrawXNum('-128 0 0', score, 4, 32, GetTeamRGB(tm.team), 1, DRAWFLAG_NORMAL);
956 Sbar_DrawXNum(place, score, 4, 12, GetTeamRGB(tm.team), 1, DRAWFLAG_NORMAL);
961 // me vector := [team/connected frags id]
963 for(me = players.sort_next; me; me = me.sort_next)
965 if(me.team != COLOR_SPECTATOR)
967 if(me.sv_entnum == player_localentnum - 1)
975 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
980 Sbar_DrawXNum('-36 -12 0', myplace, 3, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
981 else if(myplace == 2)
982 Sbar_DrawXNum('-36 -12 0', myplace, 3, 12, '1 1 0', 1, DRAWFLAG_NORMAL);
984 Sbar_DrawXNum('-36 -12 0', myplace, 3, 12, '1 0 0', 1, DRAWFLAG_NORMAL);
986 score = me.(scores[ps_primary]);
987 if(distribution >= 0)
989 Sbar_DrawXNum('-84 -12 0', distribution, 4, 12, ' 1 1 1', 1, DRAWFLAG_NORMAL);
990 Sbar_DrawXNum('-128 0 0', score, 4, 32, '1 1 1', 1, DRAWFLAG_NORMAL);
991 } else if(distribution >= -5)
993 Sbar_DrawXNum('-84 -12 0', distribution, 4, 12, ' 1 1 0', 1, DRAWFLAG_NORMAL);
994 Sbar_DrawXNum('-128 0 0', score, 4, 32, '1 1 0', 1, DRAWFLAG_NORMAL);
996 Sbar_DrawXNum('-84 -12 0', distribution, 4, 12, ' 1 0 0', 1, DRAWFLAG_NORMAL);
997 Sbar_DrawXNum('-128 0 0', score, 4, 32, '1 0 0', 1, DRAWFLAG_NORMAL);
1000 timelimit = getstatf(STAT_TIMELIMIT);
1003 timeleft = max(0, timelimit * 60 - time);
1004 minutes = floor(timeleft / 60);
1005 seconds = floor(timeleft - minutes*60);
1008 Sbar_DrawXNum('-72 32 0', minutes, 3, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
1009 drawpic(sbar + '-36 32 0', "gfx/num_colon", '12 12 0', '1 1 1', sbar_alpha_fg, 0);
1010 Sbar_DrawXNum('-24 32 0', seconds, -2, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
1011 } else if(minutes >= 1)
1013 Sbar_DrawXNum('-72 32 0', minutes, 3, 12, '1 1 0', 1, DRAWFLAG_NORMAL);
1014 drawpic(sbar + '-36 32 0', "gfx/num_colon", '12 12 0', '1 1 0', sbar_alpha_fg, 0);
1015 Sbar_DrawXNum('-24 32 0', seconds, -2, 12, '1 1 0', 1, DRAWFLAG_NORMAL);
1017 Sbar_DrawXNum('-24 32 0', seconds, -2, 12, '1 0 0', 1, DRAWFLAG_NORMAL);
1020 minutes = floor(time / 60);
1021 seconds = floor(time - minutes*60);
1022 Sbar_DrawXNum('-72 32 0', minutes, 3, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
1023 drawpic(sbar + '-36 32 0', "gfx/num_colon", '12 12 0', '1 1 1', sbar_alpha_fg, 0);
1024 Sbar_DrawXNum('-24 32 0', seconds, -2, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
1029 void Sbar_MiniscoreItem(vector pos, entity pl, float is_self)
1035 drawfill(pos + '0 1 0', '40 6 0', GetTeamRGB(pl.team)*0.5, 1, DRAWFLAG_NORMAL);
1037 drawfill(pos + '0 1 0', '40 6 0', '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
1040 score = pl.(scores[ps_primary]);
1041 pos_x -= stringwidth(ftos(score), FALSE)*8;
1042 drawstring(pos, ftos(score), '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1047 drawstring(pos, "\x0D", '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1051 drawcolorcodedstring(pos, getplayerkey(pl.sv_entnum, "name"), '8 8 0', 1, 0);
1054 void Sbar_MiniscoreTeamItem(vector pos, float color, float frags, float is_self)
1060 drawfill(pos + '0 1 0', '40 6 0', GetTeamRGB(color)*0.5, 1, DRAWFLAG_NORMAL);
1062 drawfill(pos + '0 1 0', '40 6 0', '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
1065 pos_x -= stringwidth(ftos(frags), FALSE)*8;
1066 drawstring(pos, ftos(frags), '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1071 drawstring(pos, "\x0D", '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1075 drawstring(pos, GetTeamName(color), '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1078 void Sbar_MiniDeathmatchOverlay(vector pos)
1080 float numlines, up, down, score;
1082 float miniscoreboard_size;
1083 miniscoreboard_size = cvar("sbar_miniscoreboard_size");
1085 if(miniscoreboard_size == 0)
1087 pos_y = vid_conheight - 8;
1089 if(miniscoreboard_size < 0)
1090 numlines = (vid_conheight - sbar_y + 7) / 8;
1092 numlines = miniscoreboard_size;
1094 // give up if there isn't enough room
1095 if(pos_x >= vid_conwidth || pos_y >= vid_conheight || numlines < 1)
1098 // me vector := [team/connected frags id]
1099 for(me = players.sort_next; me; me = me.sort_next)
1101 if(me.sv_entnum == player_localentnum - 1)
1106 numlines -= numteams;
1108 // figure out how many players above and below we can show
1109 up = floor(numlines/2);
1111 if((up + down) > numlines)
1112 down = numlines - up;
1115 for(pl = me.sort_next; pl && down > 0; pl = pl.sort_next)
1117 if(pl.team == COLOR_SPECTATOR)
1119 Sbar_MiniscoreItem(pos, pl, false);
1123 Sbar_MiniscoreItem(pos, me, true);
1125 up += down; // if there weren't enough lines below... add them
1126 for(pl = me.sort_prev; pl && up > 0; pl = pl.sort_prev)
1128 if(pl.team == COLOR_SPECTATOR)
1130 Sbar_MiniscoreItem(pos, pl, false);
1137 for(tm = teams.sort_next; tm.sort_next; tm = tm.sort_next);
1138 for(; tm; tm = tm.sort_prev)
1140 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
1142 score = tm.(teamscores[ts_primary]);
1143 Sbar_MiniscoreTeamItem(pos, tm.team, score, (tm.team == me.team));
1149 float Sbar_WouldDrawScoreboard ()
1153 else if (intermission == 1)
1155 else if (intermission == 2)
1157 else if (getstati(STAT_HEALTH) <= 0 && cvar("cl_deathscoreboard"))
1162 void Sbar_Draw (void)
1169 Sbar_UpdatePlayerTeams();
1174 Sbar_DrawScoreboard();
1175 else if (intermission == 1)
1177 Sbar_DrawScoreboard();
1180 else if (intermission == 2)
1181 Sbar_FinaleOverlay();
1184 if (sb_showscores || (getstati(STAT_HEALTH) <= 0 && cvar("cl_deathscoreboard")))
1186 sbar_x = (vid_conwidth - 640.0)*0.5;
1187 sbar_y = vid_conheight - 47;
1188 //Sbar_DrawAlphaPic (sbar_x, sbar_y, sb_scorebar, sbar_alpha_bg.value);
1189 //drawpic('0 0 0', "gfx/scorebar", '0 0 0', '1 1 1', cvar("sbar_alpha_bg"), 0);
1190 Sbar_DrawScoreboard ();
1194 if (sb_lines && sbar_hudselector == 1)
1196 stat_items = getstati(STAT_ITEMS);
1198 sbar_x = (vid_conwidth - 320.0)*0.5;
1199 sbar_y = vid_conheight - 24.0 - 16.0;
1202 fade = 3.2 - 2 * (time - weapontime);
1203 fade = bound(0.7, fade, 1);
1206 for(i = 0; i < 8; ++i)
1210 Sbar_DrawWeapon(i+1, fade, (i + 2 == activeweapon));
1217 Sbar_DrawWeapon(0, fade, (activeweapon == 1));
1221 x = getstati(STAT_ARMOR);
1225 //Sbar_DrawStretchPic (72, 0, sb_armor[0], sbar_alpha_fg.value, 24, 24);
1226 drawpic(sbar + '72 0 0', "gfx/sb_armor", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1228 Sbar_DrawXNum('0 0 0', x, 3, 24, '0 1 0', 1, 0);
1230 Sbar_DrawXNum('0 0 0', x, 3, 24, '0.2 1 0', 1, 0);
1232 Sbar_DrawXNum('0 0 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1234 Sbar_DrawXNum('0 0 0', x, 3, 24, '1 1 0.2', 1, 0);
1236 Sbar_DrawXNum('0 0 0', x, 3, 24, '0.7 0 0', 1, 0);
1240 x = getstati(STAT_HEALTH);
1244 //Sbar_DrawStretchPic (184, 0, sb_health, sbar_alpha_fg.value, 24, 24);
1245 drawpic(sbar + '184 0 0', "gfx/sb_health", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1247 Sbar_DrawXNum('112 0 0', x, 3, 24, '0 1 0', 1, 0);
1249 Sbar_DrawXNum('112 0 0', x, 3, 24, '0.2 1 0', 1, 0);
1251 Sbar_DrawXNum('112 0 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1253 Sbar_DrawXNum('112 0 0', x, 3, 24, '1 1 0.2', 1, 0);
1255 Sbar_DrawXNum('112 0 0', x, 3, 24, '0.7 0 0', 1, 0);
1259 x = getstati(STAT_AMMO);
1260 if ((stat_items & (NEX_IT_SHELLS | NEX_IT_BULLETS | NEX_IT_ROCKETS | NEX_IT_CELLS)) || x != 0)
1262 if (stat_items & NEX_IT_SHELLS)
1263 drawpic(sbar + '296 0 0', "gfx/sb_shells", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1264 else if (stat_items & NEX_IT_BULLETS)
1265 drawpic(sbar + '296 0 0', "gfx/sb_bullets", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1266 else if (stat_items & NEX_IT_ROCKETS)
1267 drawpic(sbar + '296 0 0', "gfx/sb_rocket", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1268 else if (stat_items & NEX_IT_CELLS)
1269 drawpic(sbar + '296 0 0', "gfx/sb_cells", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1271 Sbar_DrawXNum('224 0 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1273 Sbar_DrawXNum('224 0 0', x, 3, 24, '0.7 0 0', 1, 0);
1276 if (sbar_x + 320 + 160 <= vid_conwidth)
1277 Sbar_MiniDeathmatchOverlay(sbar + '320 0 0');
1280 // The margin can be at most 8 to support 640x480 console size:
1281 // 320 + 2 * (144 + 16) = 640
1286 stat_items = getstati(STAT_ITEMS);
1288 sbar_x = (vid_conwidth - 640.0)*0.5;
1289 sbar_y = vid_conheight - 47;
1292 fade = 3 - 2 * (time - weapontime);
1295 for(i = 0; i < 8; ++i)
1299 Sbar_DrawWeapon(i+1, fade, (i + 2 == activeweapon));
1306 Sbar_DrawWeapon(0, fade, (activeweapon == 1));
1310 drawpic(sbar, "gfx/sbar", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1312 drawpic(sbar, "gfx/sbar_minimal", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1316 Sbar_DrawXNum('268 12 0', getstati(STAT_ARMOR), 3, 24, '0.6 0.7 0.8', 1, 0);
1320 x = getstati(STAT_HEALTH);
1322 Sbar_DrawXNum('82 12 0', x, 3, 24, '1 1 1', 1, 0);
1323 else if(x <= 25 && time - floor(time) > 0.5)
1324 Sbar_DrawXNum('82 12 0', x, 3, 24, '0.7 0 0', 1, 0);
1326 Sbar_DrawXNum('81 12 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1328 // AK dont draw ammo for the laser
1329 x = getstati(STAT_AMMO);
1330 if(activeweapon != 12)
1333 if (stat_items & NEX_IT_SHELLS)
1334 drawpic(sbar + '519 0 0', "gfx/sb_shells", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1335 else if (stat_items & NEX_IT_BULLETS)
1336 drawpic(sbar + '519 0 0', "gfx/sb_bullets", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1337 else if (stat_items & NEX_IT_ROCKETS)
1338 drawpic(sbar + '519 0 0', "gfx/sb_rocket", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1339 else if (stat_items & NEX_IT_CELLS)
1340 drawpic(sbar + '519 0 0', "gfx/sb_cells", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1342 Sbar_DrawXNum('447 12 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1344 Sbar_DrawXNum('447 12 0', x, 3, 24, '0.7 0 0', 1, 0);
1348 drawpic(sbar, "gfx/sbar_overlay", '0 0 0', '1 1 1', 1, DRAWFLAG_MODULATE);
1350 if (sbar_x + 600 + 160 <= vid_conwidth)
1351 Sbar_MiniDeathmatchOverlay (sbar + '600 0 0');
1356 // Mini scoreboard uses 12*4 per other team, that is, 144
1357 // pixels when there are four teams...
1358 // Nexuiz by default sets vid_conwidth to 800... makes
1360 // so we need to shift it by 64 pixels to the right to fit
1361 // BUT: then it overlaps with the image that gets drawn
1362 // for viewsize 100! Therefore, just account for 3 teams,
1363 // that is, 96 pixels mini scoreboard size, needing 16 pixels
1368 if(gametype == GAME_KEYHUNT)
1371 } else if(gametype == GAME_CTF)
1379 void CSQC_ctf_hud(void)
1381 // cvar("sbar_flagstatus_right") move the flag icons right
1382 // cvar("sbar_flagstatus_pos") pixel position of the nexuiz flagstatus icons
1383 float redflag, blueflag;
1387 stat_items = getstati(STAT_ITEMS);
1388 redflag = (stat_items/32768) & 3;
1389 blueflag = (stat_items/131072) & 3;
1393 * For some reason now not even THAT works there...
1394 * Maybe the minus' precedence screws it up? The last one there, maybe I should use brackets
1396 * pos_x = (cvar("sbar_flagstatus_right")) ? vid_conwidth - 10 - sbar_x - 64 : 10 - sbar_x;
1397 ** Should try those later:
1398 * pos_x = (cvar("sbar_flagstatus_right")) ? (vid_conwidth - 10 - sbar_x - 64) : (10 - sbar_x);
1399 * pos_x = ( (cvar("sbar_flagstatus_right")) ? vid_conwidth - 10 - 64 : 10 ) - sbar_x;
1402 if(cvar("sbar_flagstatus_right"))
1403 pos_x = vid_conwidth - 10 - sbar_x - 64;
1405 pos_x = 10 - sbar_x;
1409 if(sbar_hudselector == 1)
1410 pos_y = (vid_conheight - sbar_y) - cvar("sbar_flagstatus_pos") - 64;
1418 case 1: drawpic(pos, "gfx/sb_flag_red_taken", '0 0 0', '1 1 1', 1, DRAWFLAG_NORMAL); break;
1419 case 2: drawpic(pos, "gfx/sb_flag_red_lost", '0 0 0', '1 1 1', 1, DRAWFLAG_NORMAL); break;
1420 case 3: drawpic(pos, "gfx/sb_flag_red_carrying", '0 0 0', '1 1 1', 1, DRAWFLAG_NORMAL); break;
1427 case 1: drawpic(pos, "gfx/sb_flag_blue_taken", '0 0 0', '1 1 1', 1, 0); break;
1428 case 2: drawpic(pos, "gfx/sb_flag_blue_lost", '0 0 0', '1 1 1', 1, 0); break;
1429 case 3: drawpic(pos, "gfx/sb_flag_blue_carrying", '0 0 0', '1 1 1', 1, 0); break;