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 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 == "name" || str == "nick") {
388 sbar_field[sbar_num_fields] = SP_NAME;
389 sbar_size[sbar_num_fields] = MIN_NAMELEN; // minimum size? any use?
391 } else if(str == "|") {
392 sbar_field[sbar_num_fields] = SP_SEPARATOR;
395 for(j = 0; j < MAX_SCORE; ++j)
396 if(str == strtolower(scores_label[j]))
397 goto found; // sorry, but otherwise fteqcc -O3 miscompiles this and warns about "unreachable code"
399 print(strcat("^1Error:^7 Unknown score field: '", str, "'\n"));
402 sbar_field[sbar_num_fields] = j;
405 if(j == ps_secondary)
411 if(scores_flags[ps_primary] & SFL_ALLOW_HIDE)
413 if(scores_flags[ps_secondary] & SFL_ALLOW_HIDE)
415 if(ps_primary == ps_secondary)
417 missing = !have_primary + !have_secondary + !have_separator + !have_name;
419 if(sbar_num_fields+missing < MAX_SBAR_FIELDS)
423 strunzone(sbar_title[sbar_num_fields]);
424 for(i = sbar_num_fields; i > 0; --i)
426 sbar_title[i] = sbar_title[i-1];
427 sbar_size[i] = sbar_size[i-1];
428 sbar_field[i] = sbar_field[i-1];
430 sbar_title[0] = strzone("name");
431 sbar_field[0] = SP_NAME;
432 sbar_size[0] = MIN_NAMELEN; // minimum size? any use?
434 print("fixed missing field 'name'\n");
438 strunzone(sbar_title[sbar_num_fields]);
439 for(i = sbar_num_fields; i > 1; --i)
441 sbar_title[i] = sbar_title[i-1];
442 sbar_size[i] = sbar_size[i-1];
443 sbar_field[i] = sbar_field[i-1];
445 sbar_title[1] = strzone("|");
446 sbar_field[1] = SP_SEPARATOR;
447 sbar_size[1] = stringwidth("|", FALSE);
449 print("fixed missing field '|'\n");
452 else if(!have_separator)
454 strunzone(sbar_title[sbar_num_fields]);
455 sbar_title[sbar_num_fields] = strzone("|");
456 sbar_size[sbar_num_fields] = stringwidth("|", FALSE);
457 sbar_field[sbar_num_fields] = SP_SEPARATOR;
459 print("fixed missing field '|'\n");
464 strunzone(sbar_title[sbar_num_fields]);
465 sbar_title[sbar_num_fields] = strzone(scores_label[ps_secondary]);
466 sbar_size[sbar_num_fields] = stringwidth(sbar_title[sbar_num_fields], FALSE);
467 sbar_field[sbar_num_fields] = ps_secondary;
469 print("fixed missing field '", scores_label[ps_secondary], "'\n");
474 strunzone(sbar_title[sbar_num_fields]);
475 sbar_title[sbar_num_fields] = strzone(scores_label[ps_primary]);
476 sbar_size[sbar_num_fields] = stringwidth(sbar_title[sbar_num_fields], FALSE);
477 sbar_field[sbar_num_fields] = ps_primary;
479 print("fixed missing field '", scores_label[ps_primary], "'\n");
483 sbar_field[sbar_num_fields] = SP_END;
487 vector sbar_field_rgb;
488 string Sbar_GetField(entity pl, float field)
490 float tmp, num, denom, f;
492 sbar_field_rgb = '1 1 1';
496 str = bufstr_get(databuf, DATABUF_PING + pl.sv_entnum);
497 tmp = max(0, min(220, stof(str)-80)) / 220;
498 sbar_field_rgb = '1 1 1' - '0 1 1'*tmp;
503 return strcat(getplayerkey(pl.sv_entnum, "name"), " ^7(connecting)");
504 return getplayerkey(pl.sv_entnum, "name");
507 num = pl.(scores[SP_KILLS]);
508 denom = pl.(scores[SP_DEATHS]);
511 sbar_field_rgb = '0 1 0';
513 } else if(num <= 0) {
514 sbar_field_rgb = '1 0 0';
515 str = ftos(num/denom);
517 str = ftos(num/denom);
519 tmp = strstrofs(str, ".", 0);
521 str = substring(str, 0, tmp+2);
525 tmp = pl.(scores[field]);
526 f = scores_flags[field];
527 if(field == ps_primary)
528 sbar_field_rgb = '1 1 0';
529 else if(field == ps_secondary)
530 sbar_field_rgb = '0 1 1';
532 sbar_field_rgb = '1 1 1';
534 if(f & (SFL_HIDE_ZERO | SFL_RANK))
538 str = ftos(floor(tmp + 0.5));
540 if((num >= 2) && (substring(str, num - 2, 1) == "1"))
541 return strcat(str, "th");
542 else if(substring(str, num - 1, 1) == "1")
543 return strcat(str, "st");
544 else if(substring(str, num - 1, 1) == "2")
545 return strcat(str, "nd");
546 else if(substring(str, num - 1, 1) == "3")
547 return strcat(str, "rd");
549 return strcat(str, "th");
556 // shamelessly stolen from menu QC :P <- as if I would steal YOUR code pfft ;)
557 float textLengthUpToWidth(string theText, float maxWidth, float handleColors)
560 // The following function is SLOW.
561 // For your safety and for the protection of those around you...
562 // DO NOT CALL THIS AT HOME.
564 if(stringwidth(theText, handleColors) <= maxWidth)
565 return strlen(theText); // yeah!
567 // binary search for right place to cut string
568 float left, right, middle; // this always works
570 right = strlen(theText); // this always fails
573 middle = floor((left + right) / 2);
574 if(stringwidth(substring(theText, 0, middle), handleColors) <= maxWidth)
579 while(left < right - 1);
581 // NOTE: when color codes are involved, this binary search is,
582 // mathematically, BROKEN. However, it is obviously guaranteed to
583 // terminate, as the range still halves each time - but nevertheless, it is
584 // guaranteed that it finds ONE valid cutoff place (where "left" is in
585 // range, and "right" is outside).
589 string textShortenToWidth(string theText, float maxWidth, float handleColors)
591 if(stringwidth(theText, handleColors) <= maxWidth)
594 return strcat(substring(theText, 0, textLengthUpToWidth(theText, maxWidth - stringwidth("...", handleColors), handleColors)), "...");
597 float xmin, xmax, ymin, ymax, sbwidth, sbheight;
599 void Sbar_PrintScoreboardItem(vector pos, entity pl, float is_self)
605 is_spec = (GetPlayerColor(pl.sv_entnum) == COLOR_SPECTATOR);
612 tmp_y = sbar_fontsize_y;
613 drawfill(pos - '1 1 0', tmp + '2 2 0', '1 1 1', 0.3, DRAWFLAG_NORMAL);
617 for(i = 0; i < sbar_num_fields; ++i)
619 field = sbar_field[i];
620 if(field == SP_SEPARATOR)
623 if(is_spec && field != SP_NAME && field != SP_PING) {
624 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
627 str = Sbar_GetField(pl, field);
633 realsize = sbar_size[i];
634 if(i+1 < sbar_num_fields)
635 if(sbar_field[i+1] == SP_SEPARATOR)
637 realsize = (xmax - xmin) / sbar_fontsize_x;
638 for(j = 0; j < sbar_num_fields; ++j) if(j != i) if(sbar_field[j] != SP_SEPARATOR)
639 realsize -= sbar_size[j] + 1;
642 str = textShortenToWidth(str, realsize, TRUE);
644 len = stringwidth(str, TRUE);
646 if(sbar_size[i] < len)
649 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
651 if(field == SP_NAME) {
652 tmp_x = sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
653 drawcolorcodedstring(pos - tmp, str, sbar_fontsize, 1, DRAWFLAG_NORMAL);
655 tmp_x = len*sbar_fontsize_x + sbar_fontsize_x;
656 drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, 1, DRAWFLAG_NORMAL);
660 if(sbar_field[i] == SP_SEPARATOR)
663 for(i = sbar_num_fields-1; i > 0; --i)
665 field = sbar_field[i];
666 if(field == SP_SEPARATOR)
669 if(is_spec && field != SP_NAME && field != SP_PING) {
670 pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
674 str = Sbar_GetField(pl, field);
677 str = textShortenToWidth(str, sbar_size[i], TRUE);
678 len = stringwidth(str, TRUE);
680 if(sbar_size[i] < len)
683 if(field == SP_NAME) {
684 tmp_x = sbar_fontsize_x*len; // left or right aligned? let's put it right...
685 drawcolorcodedstring(pos - tmp, str, sbar_fontsize, 1, DRAWFLAG_NORMAL);
687 tmp_x = sbar_fontsize_x*len; //strlen(str);
688 drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, 1, DRAWFLAG_NORMAL);
690 pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
695 void Sbar_DrawScoreboard()
697 //float xmin, ymin, xmax, ymax;
698 vector rgb, pos, tmp, sbar_save;
703 sbar_fontsize = Sbar_GetFontsize();
704 if(sbar_fontsize_x == 0)
705 sbar_fontsize = '8 8 0';
706 if(sbar_fontsize_y == 0)
707 sbar_fontsize_y = sbar_fontsize_x;
709 xmin = vid_conwidth / 5;
712 xmax = vid_conwidth - xmin;
713 ymax = vid_conheight - 0.2*vid_conheight;
715 sbwidth = xmax - xmin;
716 sbheight = ymax - ymin;
718 center_x = xmin + 0.5*sbwidth;
720 //Sbar_UpdateFields();
722 // Initializes position
728 drawfont = sbar_bigfont;
729 pos_x = center_x - stringwidth("Scoreboard", TRUE)*0.5*24;
730 drawstring(pos, "Scoreboard", '24 24 0', '1 1 1', 1, DRAWFLAG_NORMAL);
734 // Titlebar background:
736 tmp_y = sbar_fontsize_y;
737 drawfill(pos - '1 1 0', tmp + '2 2 0', '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
739 drawfont = sbar_font;
741 for(i = 0; i < sbar_num_fields; ++i)
743 if(sbar_field[i] == SP_SEPARATOR)
745 drawstring(pos, sbar_title[i], sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
746 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
749 if(sbar_field[i] == SP_SEPARATOR)
751 pos_x = xmax + sbar_fontsize_x;
753 for(i = sbar_num_fields-1; i > 0; --i)
755 if(sbar_field[i] == SP_SEPARATOR)
758 pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
761 * Using the following line will fuck it all up:
763 * tmp_x = sbar_size[i] - strlen(sbar_title[i])*8;
765 tmp_x = sbar_fontsize_x*sbar_size[i];
766 tmp_x -= stringwidth(sbar_title[i], FALSE)*sbar_fontsize_x;
767 drawstring(pos + tmp, sbar_title[i], sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
772 pos_y += 1.5 * sbar_fontsize_y;
779 //for(tm = sortedTeams.sort_next; tm; tm = tm.sort_next)
780 for(tm = teams.sort_next; tm; tm = tm.sort_next)
782 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
785 rgb = GetTeamRGB(tm.team);
790 pos - '6.5 0 0' * sbar_fontsize_y,
791 tm.(teamscores[ts_primary]),
792 4, sbar_fontsize_y * 1.5, rgb, 1, DRAWFLAG_NORMAL);
794 if(ts_primary != ts_secondary)
796 pos - '4.5 0 0' * sbar_fontsize_y + '0 1.5 0' * sbar_fontsize_y,
797 tm.(teamscores[ts_secondary]),
798 4, sbar_fontsize_y * 1, rgb, 1, DRAWFLAG_NORMAL);
800 specs = tm.team_size;
806 tmp_y = 1.25 * sbar_fontsize_y * specs;
807 drawfill(pos - '1 1 0', tmp + '2 0 0', rgb, 0.2, DRAWFLAG_NORMAL);
809 for(pl = players.sort_next; pl; pl = pl.sort_next)
811 if(pl.team != tm.team)
813 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
814 pos_y += 1.25 * sbar_fontsize_y;
815 tmp_y -= 1.25 * sbar_fontsize_y;
817 pos_y += tmp_y + 1.5 * sbar_fontsize_y;
819 // rgb := tempvector :)
820 rgb = pos + '0 1.5 0' * sbar_fontsize_y;
821 pos_y += 3 * sbar_fontsize_y;
823 for(pl = players.sort_next; pl; pl = pl.sort_next)
825 if(pl.team != COLOR_SPECTATOR)
827 //drawcolorcodedstring(pos, getplayerkey(pl.sb_player, "name"), '8 8 0', 1, 0);
828 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
829 pos += '0 1.25 0' * sbar_fontsize_y;
834 drawstring(rgb, "Spectators", sbar_fontsize, '1 1 1', 1, 0);
837 for(pl = players.sort_next; pl; pl = pl.sort_next)
839 if(pl.team == COLOR_SPECTATOR)
841 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
842 pos_y += 1.25 * sbar_fontsize_y;
843 tmp_y -= 1.25 * sbar_fontsize_y;
846 // rgb := tempvector :)
847 rgb = pos + '0 1.5 0' * sbar_fontsize_y;
848 pos_y += 3 * sbar_fontsize_y;
850 for(pl = players.sort_next; pl; pl = pl.sort_next)
852 if(pl.team != COLOR_SPECTATOR)
854 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
855 pos += '0 1.25 0' * sbar_fontsize_y;
860 drawstring(rgb, "Spectators", sbar_fontsize, '1 1 1', 1, 0);
865 str = strcat("playing on ^2", shortmapname, "^7");
866 tl = getstatf(STAT_TIMELIMIT);
867 fl = getstatf(STAT_FRAGLIMIT);
868 if(gametype == GAME_LMS)
871 str = strcat(str, " for up to ^1", ftos(tl), " minutes^7");
876 str = strcat(str, " for ^1", ftos(tl), " minutes^7");
880 str = strcat(str, " or");
881 str = strcat(str, " until ^3", ftos(fl));
882 if(scores_label[ps_primary] == "score")
883 str = strcat(str, " points^7");
885 str = strcat(str, " ", scores_label[ps_primary]);
889 pos_y += 1.5 * sbar_fontsize_y;
890 drawcolorcodedstring(pos + '0.5 0 0' * (sbwidth - sbar_fontsize_x * stringwidth(str, TRUE)), str, sbar_fontsize, 0.8, 0);
895 void Sbar_Score(float margin)
897 float timelimit, timeleft, minutes, seconds, distribution, myplace, score;
898 vector sbar_save, place;
902 myteam = GetPlayerColor(player_localentnum - 1);
904 sbar_y = vid_conheight - (32+12);
915 //for(i = 0; i < 4; ++i)
916 for(tm = teams.sort_next; tm; tm = tm.sort_next)
918 if(tm.team == COLOR_SPECTATOR || !tm.team_size) // no players? don't display
921 score = tm.(teamscores[ts_primary]);
922 if(tm.team == myteam)
923 Sbar_DrawXNum('-128 0 0', score, 4, 32, GetTeamRGB(tm.team), 1, DRAWFLAG_NORMAL);
926 Sbar_DrawXNum(place, score, 4, 12, GetTeamRGB(tm.team), 1, DRAWFLAG_NORMAL);
931 // me vector := [team/connected frags id]
933 for(me = players.sort_next; me; me = me.sort_next)
935 if(me.team != COLOR_SPECTATOR)
937 if(me.sv_entnum == player_localentnum - 1)
945 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
950 Sbar_DrawXNum('-36 -12 0', myplace, 3, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
951 else if(myplace == 2)
952 Sbar_DrawXNum('-36 -12 0', myplace, 3, 12, '1 1 0', 1, DRAWFLAG_NORMAL);
954 Sbar_DrawXNum('-36 -12 0', myplace, 3, 12, '1 0 0', 1, DRAWFLAG_NORMAL);
956 score = me.(scores[ps_primary]);
957 if(distribution >= 0)
959 Sbar_DrawXNum('-84 -12 0', distribution, 4, 12, ' 1 1 1', 1, DRAWFLAG_NORMAL);
960 Sbar_DrawXNum('-128 0 0', score, 4, 32, '1 1 1', 1, DRAWFLAG_NORMAL);
961 } else if(distribution >= -5)
963 Sbar_DrawXNum('-84 -12 0', distribution, 4, 12, ' 1 1 0', 1, DRAWFLAG_NORMAL);
964 Sbar_DrawXNum('-128 0 0', score, 4, 32, '1 1 0', 1, DRAWFLAG_NORMAL);
966 Sbar_DrawXNum('-84 -12 0', distribution, 4, 12, ' 1 0 0', 1, DRAWFLAG_NORMAL);
967 Sbar_DrawXNum('-128 0 0', score, 4, 32, '1 0 0', 1, DRAWFLAG_NORMAL);
970 timelimit = getstatf(STAT_TIMELIMIT);
973 timeleft = max(0, timelimit * 60 - time);
974 minutes = floor(timeleft / 60);
975 seconds = floor(timeleft - minutes*60);
978 Sbar_DrawXNum('-72 32 0', minutes, 3, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
979 drawpic(sbar + '-36 32 0', "gfx/num_colon", '12 12 0', '1 1 1', sbar_alpha_fg, 0);
980 Sbar_DrawXNum('-24 32 0', seconds, -2, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
981 } else if(minutes >= 1)
983 Sbar_DrawXNum('-72 32 0', minutes, 3, 12, '1 1 0', 1, DRAWFLAG_NORMAL);
984 drawpic(sbar + '-36 32 0', "gfx/num_colon", '12 12 0', '1 1 0', sbar_alpha_fg, 0);
985 Sbar_DrawXNum('-24 32 0', seconds, -2, 12, '1 1 0', 1, DRAWFLAG_NORMAL);
987 Sbar_DrawXNum('-24 32 0', seconds, -2, 12, '1 0 0', 1, DRAWFLAG_NORMAL);
990 minutes = floor(time / 60);
991 seconds = floor(time - minutes*60);
992 Sbar_DrawXNum('-72 32 0', minutes, 3, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
993 drawpic(sbar + '-36 32 0', "gfx/num_colon", '12 12 0', '1 1 1', sbar_alpha_fg, 0);
994 Sbar_DrawXNum('-24 32 0', seconds, -2, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
999 void Sbar_MiniscoreItem(vector pos, entity pl, float is_self)
1005 drawfill(pos + '0 1 0', '40 6 0', GetTeamRGB(pl.team)*0.5, 1, DRAWFLAG_NORMAL);
1007 drawfill(pos + '0 1 0', '40 6 0', '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
1010 score = pl.(scores[ps_primary]);
1011 pos_x -= stringwidth(ftos(score), FALSE)*8;
1012 drawstring(pos, ftos(score), '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1017 drawstring(pos, "\x0D", '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1021 drawcolorcodedstring(pos, getplayerkey(pl.sv_entnum, "name"), '8 8 0', 1, 0);
1024 void Sbar_MiniscoreTeamItem(vector pos, float color, float frags, float is_self)
1030 drawfill(pos + '0 1 0', '40 6 0', GetTeamRGB(color)*0.5, 1, DRAWFLAG_NORMAL);
1032 drawfill(pos + '0 1 0', '40 6 0', '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
1035 pos_x -= stringwidth(ftos(frags), FALSE)*8;
1036 drawstring(pos, ftos(frags), '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1041 drawstring(pos, "\x0D", '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1045 drawstring(pos, GetTeamName(color), '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1048 void Sbar_MiniDeathmatchOverlay(vector pos)
1050 float numlines, up, down, score;
1052 float miniscoreboard_size;
1053 miniscoreboard_size = cvar("sbar_miniscoreboard_size");
1055 if(miniscoreboard_size == 0)
1057 pos_y = vid_conheight - 8;
1059 if(miniscoreboard_size < 0)
1060 numlines = (vid_conheight - sbar_y + 7) / 8;
1062 numlines = miniscoreboard_size;
1064 // give up if there isn't enough room
1065 if(pos_x >= vid_conwidth || pos_y >= vid_conheight || numlines < 1)
1068 // me vector := [team/connected frags id]
1069 for(me = players.sort_next; me; me = me.sort_next)
1071 if(me.sv_entnum == player_localentnum - 1)
1076 numlines -= numteams;
1078 // figure out how many players above and below we can show
1079 up = floor(numlines/2);
1081 if((up + down) > numlines)
1082 down = numlines - up;
1085 for(pl = me.sort_next; pl && down > 0; pl = pl.sort_next)
1087 if(pl.team == COLOR_SPECTATOR)
1089 Sbar_MiniscoreItem(pos, pl, false);
1093 Sbar_MiniscoreItem(pos, me, true);
1095 up += down; // if there weren't enough lines below... add them
1096 for(pl = me.sort_prev; pl && up > 0; pl = pl.sort_prev)
1098 if(pl.team == COLOR_SPECTATOR)
1100 Sbar_MiniscoreItem(pos, pl, false);
1107 for(tm = teams.sort_next; tm.sort_next; tm = tm.sort_next);
1108 for(; tm; tm = tm.sort_prev)
1110 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
1112 score = tm.(teamscores[ts_primary]);
1113 Sbar_MiniscoreTeamItem(pos, tm.team, score, (tm.team == me.team));
1119 float Sbar_WouldDrawScoreboard ()
1123 else if (intermission == 1)
1125 else if (intermission == 2)
1130 void Sbar_Draw (void)
1137 Sbar_UpdatePlayerTeams();
1142 Sbar_DrawScoreboard();
1143 else if (intermission == 1)
1145 Sbar_DrawScoreboard();
1148 else if (intermission == 2)
1149 Sbar_FinaleOverlay();
1152 if (sb_showscores || (getstati(STAT_HEALTH) <= 0 && cvar("cl_deathscoreboard")))
1154 sbar_x = (vid_conwidth - 640.0)*0.5;
1155 sbar_y = vid_conheight - 47;
1156 //Sbar_DrawAlphaPic (sbar_x, sbar_y, sb_scorebar, sbar_alpha_bg.value);
1157 //drawpic('0 0 0', "gfx/scorebar", '0 0 0', '1 1 1', cvar("sbar_alpha_bg"), 0);
1158 Sbar_DrawScoreboard ();
1162 if (sb_lines && sbar_hudselector == 1)
1164 stat_items = getstati(STAT_ITEMS);
1166 sbar_x = (vid_conwidth - 320.0)*0.5;
1167 sbar_y = vid_conheight - 24.0 - 16.0;
1170 fade = 3.2 - 2 * (time - weapontime);
1171 fade = bound(0.7, fade, 1);
1174 for(i = 0; i < 8; ++i)
1178 Sbar_DrawWeapon(i+1, fade, (i + 2 == activeweapon));
1185 Sbar_DrawWeapon(0, fade, (activeweapon == 1));
1189 x = getstati(STAT_ARMOR);
1193 //Sbar_DrawStretchPic (72, 0, sb_armor[0], sbar_alpha_fg.value, 24, 24);
1194 drawpic(sbar + '72 0 0', "gfx/sb_armor", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1196 Sbar_DrawXNum('0 0 0', x, 3, 24, '0 1 0', 1, 0);
1198 Sbar_DrawXNum('0 0 0', x, 3, 24, '0.2 1 0', 1, 0);
1200 Sbar_DrawXNum('0 0 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1202 Sbar_DrawXNum('0 0 0', x, 3, 24, '1 1 0.2', 1, 0);
1204 Sbar_DrawXNum('0 0 0', x, 3, 24, '0.7 0 0', 1, 0);
1208 x = getstati(STAT_HEALTH);
1212 //Sbar_DrawStretchPic (184, 0, sb_health, sbar_alpha_fg.value, 24, 24);
1213 drawpic(sbar + '184 0 0', "gfx/sb_health", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1215 Sbar_DrawXNum('112 0 0', x, 3, 24, '0 1 0', 1, 0);
1217 Sbar_DrawXNum('112 0 0', x, 3, 24, '0.2 1 0', 1, 0);
1219 Sbar_DrawXNum('112 0 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1221 Sbar_DrawXNum('112 0 0', x, 3, 24, '1 1 0.2', 1, 0);
1223 Sbar_DrawXNum('112 0 0', x, 3, 24, '0.7 0 0', 1, 0);
1227 x = getstati(STAT_AMMO);
1228 if ((stat_items & (NEX_IT_SHELLS | NEX_IT_BULLETS | NEX_IT_ROCKETS | NEX_IT_CELLS)) || x != 0)
1230 if (stat_items & NEX_IT_SHELLS)
1231 drawpic(sbar + '296 0 0', "gfx/sb_shells", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1232 else if (stat_items & NEX_IT_BULLETS)
1233 drawpic(sbar + '296 0 0', "gfx/sb_bullets", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1234 else if (stat_items & NEX_IT_ROCKETS)
1235 drawpic(sbar + '296 0 0', "gfx/sb_rocket", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1236 else if (stat_items & NEX_IT_CELLS)
1237 drawpic(sbar + '296 0 0', "gfx/sb_cells", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1239 Sbar_DrawXNum('224 0 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1241 Sbar_DrawXNum('224 0 0', x, 3, 24, '0.7 0 0', 1, 0);
1244 if (sbar_x + 320 + 160 <= vid_conwidth)
1245 Sbar_MiniDeathmatchOverlay(sbar + '320 0 0');
1248 // The margin can be at most 8 to support 640x480 console size:
1249 // 320 + 2 * (144 + 16) = 640
1254 stat_items = getstati(STAT_ITEMS);
1256 sbar_x = (vid_conwidth - 640.0)*0.5;
1257 sbar_y = vid_conheight - 47;
1260 fade = 3 - 2 * (time - weapontime);
1263 for(i = 0; i < 8; ++i)
1267 Sbar_DrawWeapon(i+1, fade, (i + 2 == activeweapon));
1274 Sbar_DrawWeapon(0, fade, (activeweapon == 1));
1278 drawpic(sbar, "gfx/sbar", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1280 drawpic(sbar, "gfx/sbar_minimal", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1284 Sbar_DrawXNum('268 12 0', getstati(STAT_ARMOR), 3, 24, '0.6 0.7 0.8', 1, 0);
1288 x = getstati(STAT_HEALTH);
1290 Sbar_DrawXNum('82 12 0', x, 3, 24, '1 1 1', 1, 0);
1291 else if(x <= 25 && time - floor(time) > 0.5)
1292 Sbar_DrawXNum('82 12 0', x, 3, 24, '0.7 0 0', 1, 0);
1294 Sbar_DrawXNum('81 12 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1296 // AK dont draw ammo for the laser
1297 x = getstati(STAT_AMMO);
1298 if(activeweapon != 12)
1301 if (stat_items & NEX_IT_SHELLS)
1302 drawpic(sbar + '519 0 0', "gfx/sb_shells", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1303 else if (stat_items & NEX_IT_BULLETS)
1304 drawpic(sbar + '519 0 0', "gfx/sb_bullets", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1305 else if (stat_items & NEX_IT_ROCKETS)
1306 drawpic(sbar + '519 0 0', "gfx/sb_rocket", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1307 else if (stat_items & NEX_IT_CELLS)
1308 drawpic(sbar + '519 0 0', "gfx/sb_cells", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1310 Sbar_DrawXNum('447 12 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1312 Sbar_DrawXNum('447 12 0', x, 3, 24, '0.7 0 0', 1, 0);
1316 drawpic(sbar, "gfx/sbar_overlay", '0 0 0', '1 1 1', 1, DRAWFLAG_MODULATE);
1318 if (sbar_x + 600 + 160 <= vid_conwidth)
1319 Sbar_MiniDeathmatchOverlay (sbar + '600 0 0');
1324 // Mini scoreboard uses 12*4 per other team, that is, 144
1325 // pixels when there are four teams...
1326 // Nexuiz by default sets vid_conwidth to 800... makes
1328 // so we need to shift it by 64 pixels to the right to fit
1329 // BUT: then it overlaps with the image that gets drawn
1330 // for viewsize 100! Therefore, just account for 3 teams,
1331 // that is, 96 pixels mini scoreboard size, needing 16 pixels
1336 if(gametype == GAME_KEYHUNT)
1339 } else if(gametype == GAME_CTF)
1347 void CSQC_ctf_hud(void)
1349 // cvar("sbar_flagstatus_right") move the flag icons right
1350 // cvar("sbar_flagstatus_pos") pixel position of the nexuiz flagstatus icons
1351 float redflag, blueflag;
1355 stat_items = getstati(STAT_ITEMS);
1356 redflag = (stat_items/32768) & 3;
1357 blueflag = (stat_items/131072) & 3;
1361 * For some reason now not even THAT works there...
1362 * Maybe the minus' precedence screws it up? The last one there, maybe I should use brackets
1364 * pos_x = (cvar("sbar_flagstatus_right")) ? vid_conwidth - 10 - sbar_x - 64 : 10 - sbar_x;
1365 ** Should try those later:
1366 * pos_x = (cvar("sbar_flagstatus_right")) ? (vid_conwidth - 10 - sbar_x - 64) : (10 - sbar_x);
1367 * pos_x = ( (cvar("sbar_flagstatus_right")) ? vid_conwidth - 10 - 64 : 10 ) - sbar_x;
1370 if(cvar("sbar_flagstatus_right"))
1371 pos_x = vid_conwidth - 10 - sbar_x - 64;
1373 pos_x = 10 - sbar_x;
1377 if(sbar_hudselector == 1)
1378 pos_y = (vid_conheight - sbar_y) - cvar("sbar_flagstatus_pos") - 64;
1386 case 1: drawpic(pos, "gfx/sb_flag_red_taken", '0 0 0', '1 1 1', 1, DRAWFLAG_NORMAL); break;
1387 case 2: drawpic(pos, "gfx/sb_flag_red_lost", '0 0 0', '1 1 1', 1, DRAWFLAG_NORMAL); break;
1388 case 3: drawpic(pos, "gfx/sb_flag_red_carrying", '0 0 0', '1 1 1', 1, DRAWFLAG_NORMAL); break;
1395 case 1: drawpic(pos, "gfx/sb_flag_blue_taken", '0 0 0', '1 1 1', 1, 0); break;
1396 case 2: drawpic(pos, "gfx/sb_flag_blue_lost", '0 0 0', '1 1 1', 1, 0); break;
1397 case 3: drawpic(pos, "gfx/sb_flag_blue_carrying", '0 0 0', '1 1 1', 1, 0); break;