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
11 float sbar_hudselector;
21 float ps_primary, ps_secondary;
22 float ts_primary, ts_secondary;
24 entity team1, team2, team3, team4, teamspec;
29 void Sbar_FinaleOverlay()
32 pos_x = (vid_conwidth - 1)/2;
36 //drawpic(pos, "gfx/finale", '0 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
38 //drawstring(pos, "END", sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
42 void Sbar_DrawWeapon(float nr, float fade, float active)
44 vector pos, vsize, color;
47 value = (active) ? 1 : 0.6;
48 color_x = color_y = color_z = value;
50 if(sbar_hudselector == 1)
52 // width = 300, height = 100
53 const float w_width = 32, w_height = 12, w_space = 2, font_size = 8;
55 pos_x = (vid_conwidth - w_width * 9) * 0.5 + w_width * nr;
56 pos_y = (vid_conheight - w_height);
61 drawpic(pos, strcat("gfx/inv_weapon", ftos(nr)), vsize, color, value * fade * sbar_alpha_fg, 0);
67 drawstring(pos, ftos(nr+1), vsize, '1 1 0', sbar_alpha_fg, 0);
72 // width = 300, height = 100
73 const float w2_width = 300, w2_height = 100, w2_space = 10;
74 const float w2_scale = 0.4;
76 pos_x = vid_conwidth - (w2_width + w2_space) * w2_scale;
77 pos_y = (w2_height + w2_space) * w2_scale * nr + w2_space;
79 vsize_x = w2_width * w2_scale;
80 vsize_y = w2_height * w2_scale;
83 drawpic(pos, strcat("gfx/inv_weapon", ftos(nr)), vsize, color, value * fade * sbar_alpha_fg, 0);
86 void Sbar_DrawXNum (vector pos, float num, float digits, float lettersize, vector rgb, float a, float dflags)
93 vsize_x = vsize_y = lettersize;
108 str = strcat(substring("0000000000", 0, digits - strlen(tmp)), tmp);
116 str = substring(str, l-digits, 999);
118 } else if(l < digits)
119 pos_x += (digits-l) * lettersize;
123 drawpic(sbar + pos, "gfx/num_minus", vsize, rgb, a * sbar_alpha_fg, dflags);
127 for(i = 0; i < l; ++i)
129 drawpic(sbar + pos, strcat("gfx/num_", substring(str, i, 1)), vsize, rgb, a * sbar_alpha_fg, dflags);
134 void Cmd_Sbar_SetFields(float argc);
135 void Sbar_InitScores()
137 float i, f, primary_prio, secondary_prio;
139 primary_prio = secondary_prio = -1;
140 for(i = 0; i < MAX_SCORE; ++i)
142 f = (scores_flags[i] & SFL_SORT_PRIO_MASK);
143 if(f > primary_prio) {
144 ps_secondary = ps_primary;
146 } else if(f > secondary_prio)
150 primary_prio = secondary_prio = -1;
151 for(i = 0; i < MAX_TEAMSCORE; ++i)
153 f = (teamscores_flags[i] & SFL_SORT_PRIO_MASK);
154 if(f > primary_prio) {
155 ts_secondary = ts_primary;
157 } else if(f > secondary_prio)
161 Cmd_Sbar_SetFields(0);
164 void Sbar_UpdatePlayerPos(entity pl);
165 void Sbar_UpdatePlayerTeams()
172 for(pl = players.sort_next; pl; pl = pl.sort_next)
175 Team = GetPlayerColor(pl.sv_entnum);
178 tmp = GetTeam(pl.team, false);
180 tmp = GetTeam(Team, true);
186 Sbar_UpdatePlayerPos(pl);
190 pl = players.sort_next;
193 //print(strcat("PNUM: ", ftos(num), "\n"));
196 float Sbar_ComparePlayerScores(entity left, entity right)
199 vl = GetPlayerColor(left.sv_entnum);
200 vr = GetPlayerColor(right.sv_entnum);
207 vl = left.scores[ps_primary];
208 vr = right.scores[ps_primary];
210 return IS_INCREASING(scores_flags[ps_primary]);
212 return IS_DECREASING(scores_flags[ps_primary]);
214 vl = left.scores[ps_secondary];
215 vr = right.scores[ps_secondary];
217 return IS_INCREASING(scores_flags[ps_secondary]);
219 return IS_DECREASING(scores_flags[ps_secondary]);
224 void Sbar_UpdatePlayerPos(entity player)
226 for(other = player.sort_next; other && Sbar_ComparePlayerScores(player, other); other = player.sort_next)
228 SORT_SWAP(player, other);
230 for(other = player.sort_prev; other != players && Sbar_ComparePlayerScores(other, player); other = player.sort_prev)
232 SORT_SWAP(other, player);
236 float Sbar_CompareTeamScores(entity left, entity right)
240 vl = left.teamscores[ts_primary];
241 vr = right.teamscores[ts_primary];
243 return IS_INCREASING(teamscores_flags[ts_primary]);
245 return IS_DECREASING(teamscores_flags[ts_primary]);
247 vl = left.teamscores[ts_secondary];
248 vr = right.teamscores[ts_secondary];
250 return IS_INCREASING(teamscores_flags[ts_secondary]);
252 return IS_DECREASING(teamscores_flags[ts_secondary]);
257 void Sbar_UpdateTeamPos(entity Team)
259 for(other = Team.sort_next; other && Sbar_ComparePlayerScores(Team, other); other = Team.sort_next)
261 if(other.team == COLOR_SPECTATOR)
263 SORT_SWAP(Team, other);
265 for(other = Team.sort_prev; other != teams && Sbar_ComparePlayerScores(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 ^7filed1 field2 ...\n");
278 print("The following field names are recognized (case INsensitive):\n");
279 print("You can use a ^3|^7 to start the right-aligned fields.\n");
281 print("^3name^7 or ^3nick^7 Name of a player\n");
282 print("^3ping^7 Ping time\n\n");
283 print("^3kd^7 or ^3kdr^7 or ^3kdratio^7 or ^3k/d\n");
284 print(" The kill-death ratio\n");
287 print("^3caps^7 or ^3captures^7 Number of flags captured\n");
288 print("^3rets^7 or ^3returns^7 Number of flags returned\n");
289 print("^3frags^7 or ^3kills^7 Frags\n");
290 print("^3deaths^7 or ^3dths^7 Number of deaths\n");
293 print("Additional columns:\n");
294 for(i = 0; i < MAX_SCORE; ++i)
297 print(strcat(scores_label[i], "\n"));
301 #define MIN_NAMELEN 24
302 #define MAX_NAMELEN 24
304 string Sbar_DefaultColumnLayout()
308 case GAME_CTF: return "ping name | caps frags";
309 case GAME_KEYHUNT: return "ping name | score caps kills";
310 default: return "ping name | frags";
311 // TODO: add other gametypes
315 void Cmd_Sbar_SetFields(float argc)
321 // TODO: re enable with gametype dependant cvars?
322 if(argc < 2) // no arguments provided
323 argc = tokenize(strcat("x ", cvar_string("sbar_columns")));
326 argc = tokenize(strcat("x ", Sbar_DefaultColumnLayout()));
328 argc = min(MAX_SBAR_FIELDS, argc);
331 drawfont = sbar_font;
332 digit = stringwidth("0123456789", FALSE) / 10;
334 argc = min(argc-1, MAX_SBAR_FIELDS-1);
335 for(i = 0; i < argc; ++i)
338 strunzone(sbar_title[i]);
339 sbar_title[i] = strzone(str);
340 sbar_size[i] = stringwidth(str, FALSE);
341 str = strtolower(str);
346 sbar_field[i] = SP_PING;
347 } else if(str == "name" || str == "nick") {
348 sbar_field[i] = SP_NAME;
349 sbar_size[i] = MIN_NAMELEN; // minimum size? any use?
350 } else if(str == "|") {
351 sbar_field[i] = SP_SEPARATOR;
353 for(j = 0; j < MAX_SCORE; ++j)
355 if(str == strtolower(scores_label[j]))
359 print(strcat("^1Error:^7 Unknown score field: '", str, "'\n"));
366 sbar_field[i] = SP_END;
370 vector sbar_field_rgb;
371 string Sbar_GetField(entity pl, float field)
373 float tmp, num, denom;
375 sbar_field_rgb = '1 1 1';
379 str = bufstr_get(databuf, DATABUF_PING + pl.sv_entnum);
380 tmp = max(0, min(220, stof(str)-80)) / 220;
381 sbar_field_rgb = '1 1 1' - '0 1 1'*tmp;
385 return getplayerkey(pl.sv_entnum, "name");
388 num = pl.(scores[SP_KILLS]);
389 denom = pl.(scores[SP_DEATHS]);
392 sbar_field_rgb = '0 1 0';
394 } else if(num <= 0) {
395 sbar_field_rgb = '1 0 0';
396 str = ftos(num/denom);
398 str = ftos(num/denom);
400 tmp = strstrofs(str, ".", 0);
402 str = substring(str, 0, tmp+2);
406 return ftos(pl.(scores[field]));
411 // shamelessly stolen from menu QC :P <- as if I would steal YOUR code pfft ;)
412 float textLengthUpToWidth(string theText, float maxWidth, float handleColors)
415 // The following function is SLOW.
416 // For your safety and for the protection of those around you...
417 // DO NOT CALL THIS AT HOME.
419 if(stringwidth(theText, handleColors) <= maxWidth)
420 return strlen(theText); // yeah!
422 // binary search for right place to cut string
423 float left, right, middle; // this always works
425 right = strlen(theText); // this always fails
428 middle = floor((left + right) / 2);
429 if(stringwidth(substring(theText, 0, middle), handleColors) <= maxWidth)
434 while(left < right - 1);
436 // NOTE: when color codes are involved, this binary search is,
437 // mathematically, BROKEN. However, it is obviously guaranteed to
438 // terminate, as the range still halves each time - but nevertheless, it is
439 // guaranteed that it finds ONE valid cutoff place (where "left" is in
440 // range, and "right" is outside).
444 string textShortenToWidth(string theText, float maxWidth, float handleColors)
446 if(stringwidth(theText, handleColors) <= maxWidth)
449 return strcat(substring(theText, 0, textLengthUpToWidth(theText, maxWidth - stringwidth("...", handleColors), handleColors)), "...");
452 float xmin, xmax, ymin, ymax, sbwidth, sbheight;
454 void Sbar_PrintScoreboardItem(vector pos, entity pl, float is_self)
460 is_spec = (GetPlayerColor(pl.sv_entnum) == COLOR_SPECTATOR);
467 tmp_y = sbar_fontsize_y;
468 drawfill(pos - '1 1', tmp + '2 2', '1 1 1', 0.3, DRAWFLAG_NORMAL);
472 for(i = 0; i < sbar_num_fields; ++i)
474 field = sbar_field[i];
475 if(field == SP_SEPARATOR)
478 if(is_spec && field != SP_NAME && field != SP_PING) {
479 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
482 str = Sbar_GetField(pl, field);
488 realsize = sbar_size[i];
489 if(i+1 < sbar_num_fields)
490 if(sbar_field[i+1] == SP_SEPARATOR)
492 realsize = (xmax - xmin) / sbar_fontsize_x;
493 for(j = 0; j < sbar_num_fields; ++j) if(j != i) if(sbar_field[j] != SP_SEPARATOR)
494 realsize -= sbar_size[j] + 1;
497 str = textShortenToWidth(str, realsize, TRUE);
499 len = stringwidth(str, TRUE);
501 if(sbar_size[i] < len)
504 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
506 if(field == SP_NAME) {
507 tmp_x = sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
508 drawcolorcodedstring(pos - tmp, str, sbar_fontsize, 1, DRAWFLAG_NORMAL);
510 tmp_x = len*sbar_fontsize_x + sbar_fontsize_x;
511 drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, 1, DRAWFLAG_NORMAL);
515 if(sbar_field[i] == SP_SEPARATOR)
518 for(i = sbar_num_fields-1; i > 0; --i)
520 field = sbar_field[i];
521 if(field == SP_SEPARATOR)
524 if(is_spec && field != SP_NAME && field != SP_PING) {
525 pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
529 str = Sbar_GetField(pl, field);
532 str = textShortenToWidth(str, sbar_size[i], TRUE);
533 len = stringwidth(str, TRUE);
535 if(sbar_size[i] < len)
538 if(field == SP_NAME) {
539 tmp_x = sbar_fontsize_x*len; // left or right aligned? let's put it right...
540 drawcolorcodedstring(pos - tmp, str, sbar_fontsize, 1, DRAWFLAG_NORMAL);
542 tmp_x = sbar_fontsize_x*len; //strlen(str);
543 drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, 1, DRAWFLAG_NORMAL);
545 pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
550 void Sbar_DrawScoreboard()
552 //float xmin, ymin, xmax, ymax;
553 vector rgb, pos, tmp, sbar_save;
558 sbar_fontsize = Sbar_GetFontsize();
559 if(sbar_fontsize_x == 0)
560 sbar_fontsize = '8 8 0';
561 if(sbar_fontsize_y == 0)
562 sbar_fontsize_y = sbar_fontsize_x;
564 xmin = vid_conwidth / 5;
567 xmax = vid_conwidth - xmin;
568 ymax = vid_conheight - 0.2*vid_conheight;
570 sbwidth = xmax - xmin;
571 sbheight = ymax - ymin;
573 center_x = xmin + 0.5*sbwidth;
575 //Sbar_UpdateFields();
577 // Initializes position
583 drawfont = sbar_font;
584 pos_x = center_x - stringwidth("Scoreboard", TRUE)*0.5*24;
585 drawstring(pos, "Scoreboard", '24 24', '1 1 1', 1, DRAWFLAG_NORMAL);
589 // Titlebar background:
591 tmp_y = sbar_fontsize_y;
592 drawfill(pos - '1 1', tmp + '2 2', '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
594 for(i = 0; i < sbar_num_fields; ++i)
596 if(sbar_field[i] == SP_SEPARATOR)
598 drawstring(pos, sbar_title[i], sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
599 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
602 if(sbar_field[i] == SP_SEPARATOR)
604 pos_x = xmax + sbar_fontsize_x;
606 for(i = sbar_num_fields-1; i > 0; --i)
608 if(sbar_field[i] == SP_SEPARATOR)
611 pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
614 * Using the following line will fuck it all up:
616 * tmp_x = sbar_size[i] - strlen(sbar_title[i])*8;
618 tmp_x = sbar_fontsize_x*sbar_size[i];
619 tmp_x -= stringwidth(sbar_title[i], FALSE)*sbar_fontsize_x;
620 drawstring(pos + tmp, sbar_title[i], sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
625 pos_y += 1.5 * sbar_fontsize_y;
632 //for(tm = sortedTeams.sort_next; tm; tm = tm.sort_next)
633 for(tm = teams.sort_next; tm; tm = tm.sort_next)
635 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
638 rgb = GetTeamRGB(tm.team);
641 // TODO: Print primary and secondary scores!
645 specs = tm.team_size;
651 tmp_y = 1.25 * sbar_fontsize_y * specs;
652 drawfill(pos - '1 1', tmp + '2 0', rgb, 0.2, DRAWFLAG_NORMAL);
654 for(pl = players.sort_next; pl; pl = pl.sort_next)
656 if(pl.team != tm.team)
658 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
659 pos_y += 1.25 * sbar_fontsize_y;
660 tmp_y -= 1.25 * sbar_fontsize_y;
662 pos_y += tmp_y + 1.5 * sbar_fontsize_y;
664 // rgb := tempvector :)
665 rgb = pos + '0 1.5 0' * sbar_fontsize_y;
666 pos_y += 3 * sbar_fontsize_y;
668 for(pl = players.sort_next; pl; pl = pl.sort_next)
670 if(pl.team != COLOR_SPECTATOR)
672 //drawcolorcodedstring(pos, getplayerkey(pl.sb_player, "name"), '8 8 0', 1, 0);
673 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
674 pos += '0 1.25 0' * sbar_fontsize_y;
679 drawstring(rgb, "Spectators", sbar_fontsize, '1 1 1', 1, 0);
682 for(pl = players.sort_next; pl; pl = pl.sort_next)
684 if(pl.team == COLOR_SPECTATOR)
686 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
687 pos_y += 1.25 * sbar_fontsize_y;
688 tmp_y -= 1.25 * sbar_fontsize_y;
691 // rgb := tempvector :)
692 rgb = pos + '0 1.5 0' * sbar_fontsize_y;
693 pos_y += 3 * sbar_fontsize_y;
695 for(pl = players.sort_next; pl; pl = pl.sort_next)
697 if(pl.team != COLOR_SPECTATOR)
699 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
700 pos += '0 1.25 0' * sbar_fontsize_y;
705 drawstring(rgb, "Spectators", sbar_fontsize, '1 1 1', 1, 0);
710 void Sbar_Score(float margin)
712 float timelimit, timeleft, minutes, seconds, distribution, myplace, score;
713 vector sbar_save, place;
717 sbar_y = vid_conheight - (32+12);
728 //for(i = 0; i < 4; ++i)
729 for(tm = teams.sort_next; tm; tm = tm.sort_next)
731 if(tm.team == COLOR_SPECTATOR || !tm.team_size) // no players? don't display
734 score = tm.(teamscores[ts_primary]);
735 if(tm.team == myteam)
736 Sbar_DrawXNum('-128 0', score, 4, 32, GetTeamRGB(tm.team), 1, DRAWFLAG_NORMAL);
739 Sbar_DrawXNum(place, score, 4, 12, GetTeamRGB(tm.team), 1, DRAWFLAG_NORMAL);
744 // me vector := [team/connected frags id]
746 for(me = players.sort_next; me; me = me.sort_next)
748 if(me.team != COLOR_SPECTATOR)
750 if(me.sv_entnum == player_localentnum - 1)
758 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
763 Sbar_DrawXNum('-36 -12', myplace, 3, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
764 else if(myplace == 2)
765 Sbar_DrawXNum('-36 -12', myplace, 3, 12, '1 1 0', 1, DRAWFLAG_NORMAL);
767 Sbar_DrawXNum('-36 -12', myplace, 3, 12, '1 0 0', 1, DRAWFLAG_NORMAL);
769 score = me.(scores[ps_primary]);
770 if(distribution >= 0)
772 Sbar_DrawXNum('-84 -12', distribution, 4, 12, ' 1 1 1', 1, DRAWFLAG_NORMAL);
773 Sbar_DrawXNum('-128 0', score, 4, 32, '1 1 1', 1, DRAWFLAG_NORMAL);
774 } else if(distribution >= -5)
776 Sbar_DrawXNum('-84 -12', distribution, 4, 12, ' 1 1 0', 1, DRAWFLAG_NORMAL);
777 Sbar_DrawXNum('-128 0', score, 4, 32, '1 1 0', 1, DRAWFLAG_NORMAL);
779 Sbar_DrawXNum('-84 -12', distribution, 4, 12, ' 1 0 0', 1, DRAWFLAG_NORMAL);
780 Sbar_DrawXNum('-128 0', score, 4, 32, '1 0 0', 1, DRAWFLAG_NORMAL);
783 timelimit = getstatf(STAT_TIMELIMIT);
786 timeleft = max(0, timelimit * 60 - time);
787 minutes = floor(timeleft / 60);
788 seconds = floor(timeleft - minutes*60);
791 Sbar_DrawXNum('-72 32', minutes, 3, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
792 drawpic(sbar + '-36 32', "gfx/num_colon", '12 12', '1 1 1', sbar_alpha_fg, 0);
793 Sbar_DrawXNum('-24 32', seconds, -2, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
794 } else if(minutes >= 1)
796 Sbar_DrawXNum('-72 32', minutes, 3, 12, '1 1 0', 1, DRAWFLAG_NORMAL);
797 drawpic(sbar + '-36 32', "gfx/num_colon", '12 12', '1 1 0', sbar_alpha_fg, 0);
798 Sbar_DrawXNum('-24 32', seconds, -2, 12, '1 1 0', 1, DRAWFLAG_NORMAL);
800 Sbar_DrawXNum('-24 32', seconds, -2, 12, '1 0 0', 1, DRAWFLAG_NORMAL);
803 minutes = floor(time / 60);
804 seconds = floor(time - minutes*60);
805 Sbar_DrawXNum('-72 32', minutes, 3, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
806 drawpic(sbar + '-36 32', "gfx/num_colon", '12 12', '1 1 1', sbar_alpha_fg, 0);
807 Sbar_DrawXNum('-24 32', seconds, -2, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
812 void Sbar_MiniscoreItem(vector pos, entity pl, float is_self)
818 drawfill(pos + '0 1 0', '40 6 0', GetTeamRGB(pl.team)*0.5, 1, DRAWFLAG_NORMAL);
820 drawfill(pos + '0 1 0', '40 6 0', '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
823 score = pl.(scores[ps_primary]);
824 pos_x -= stringwidth(ftos(score), FALSE)*8;
825 drawstring(pos, ftos(score), '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
830 drawstring(pos, "\x0D", '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
834 drawcolorcodedstring(pos, getplayerkey(pl.sv_entnum, "name"), '8 8 0', 1, 0);
837 void Sbar_MiniscoreTeamItem(vector pos, float color, float frags, float is_self)
843 drawfill(pos + '0 1 0', '40 6 0', GetTeamRGB(color)*0.5, 1, DRAWFLAG_NORMAL);
845 drawfill(pos + '0 1 0', '40 6 0', '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
848 pos_x -= stringwidth(ftos(frags), FALSE)*8;
849 drawstring(pos, ftos(frags), '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
854 drawstring(pos, "\x0D", '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
858 drawstring(pos, GetTeamName(color), '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
861 void Sbar_MiniDeathmatchOverlay(vector pos)
863 float numlines, up, down, score;
865 float miniscoreboard_size;
866 miniscoreboard_size = cvar("sbar_miniscoreboard_size");
868 if(miniscoreboard_size == 0)
870 pos_y = vid_conheight - 8;
872 if(miniscoreboard_size < 0)
873 numlines = (vid_conheight - sbar_y + 7) / 8;
875 numlines = miniscoreboard_size;
877 // give up if there isn't enough room
878 if(pos_x >= vid_conwidth || pos_y >= vid_conheight || numlines < 1)
881 // me vector := [team/connected frags id]
882 for(me = players.sort_next; me; me = me.sort_next)
884 if(me.sv_entnum == player_localentnum - 1)
889 numlines -= numteams;
891 // figure out how many players above and below we can show
892 up = floor(numlines/2);
894 if((up + down) > numlines)
895 down = numlines - up;
898 for(pl = me.sort_next; pl && down > 0; pl = pl.sort_next)
900 if(pl.team == COLOR_SPECTATOR)
902 Sbar_MiniscoreItem(pos, pl, false);
906 Sbar_MiniscoreItem(pos, me, true);
908 up += down; // if there weren't enough lines below... add them
909 for(pl = me.sort_prev; pl && up > 0; pl = pl.sort_prev)
911 if(pl.team == COLOR_SPECTATOR)
913 Sbar_MiniscoreItem(pos, pl, false);
920 for(tm = teams.sort_next; tm.sort_next; tm = tm.sort_next);
921 for(; tm; tm = tm.sort_prev)
923 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
925 score = tm.(teamscores[ts_primary]);
926 Sbar_MiniscoreTeamItem(pos, tm.team, score, (tm.team == me.team));
932 void Sbar_Draw (void)
939 Sbar_UpdatePlayerTeams();
944 Sbar_DrawScoreboard();
945 else if (intermission == 1)
947 Sbar_DrawScoreboard();
950 else if (intermission == 2)
951 Sbar_FinaleOverlay();
954 if (sb_showscores || (getstati(STAT_HEALTH) <= 0 && cvar("cl_deathscoreboard")))
956 sbar_x = (vid_conwidth - 640.0)*0.5;
957 sbar_y = vid_conheight - 47;
958 //Sbar_DrawAlphaPic (sbar_x, sbar_y, sb_scorebar, sbar_alpha_bg.value);
959 //drawpic('0 0', "gfx/scorebar", '0 0 0', '1 1 1', cvar("sbar_alpha_bg"), 0);
960 Sbar_DrawScoreboard ();
964 if (sb_lines && sbar_hudselector == 1)
966 stat_items = getstati(STAT_ITEMS);
968 sbar_x = (vid_conwidth - 320.0)*0.5;
969 sbar_y = vid_conheight - 24.0 - 16.0;
972 fade = 3.2 - 2 * (time - weapontime);
973 fade = bound(0.7, fade, 1);
976 for(i = 0; i < 8; ++i)
980 Sbar_DrawWeapon(i+1, fade, (i + 2 == activeweapon));
987 Sbar_DrawWeapon(0, fade, (activeweapon == 1));
991 x = getstati(STAT_ARMOR);
995 //Sbar_DrawStretchPic (72, 0, sb_armor[0], sbar_alpha_fg.value, 24, 24);
996 drawpic(sbar + '72 0', "gfx/sb_armor", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
998 Sbar_DrawXNum('0 0', x, 3, 24, '0 1 0', 1, 0);
1000 Sbar_DrawXNum('0 0', x, 3, 24, '0.2 1 0', 1, 0);
1002 Sbar_DrawXNum('0 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1004 Sbar_DrawXNum('0 0', x, 3, 24, '1 1 0.2', 1, 0);
1006 Sbar_DrawXNum('0 0', x, 3, 24, '0.7 0 0', 1, 0);
1010 x = getstati(STAT_HEALTH);
1014 //Sbar_DrawStretchPic (184, 0, sb_health, sbar_alpha_fg.value, 24, 24);
1015 drawpic(sbar + '184 0', "gfx/sb_health", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1017 Sbar_DrawXNum('112 0', x, 3, 24, '0 1 0', 1, 0);
1019 Sbar_DrawXNum('112 0', x, 3, 24, '0.2 1 0', 1, 0);
1021 Sbar_DrawXNum('112 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1023 Sbar_DrawXNum('112 0', x, 3, 24, '1 1 0.2', 1, 0);
1025 Sbar_DrawXNum('112 0', x, 3, 24, '0.7 0 0', 1, 0);
1029 x = getstati(STAT_AMMO);
1030 if ((stat_items & (NEX_IT_SHELLS | NEX_IT_BULLETS | NEX_IT_ROCKETS | NEX_IT_CELLS)) || x != 0)
1032 if (stat_items & NEX_IT_SHELLS)
1033 drawpic(sbar + '296 0', "gfx/sb_shells", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1034 else if (stat_items & NEX_IT_BULLETS)
1035 drawpic(sbar + '296 0', "gfx/sb_bullets", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1036 else if (stat_items & NEX_IT_ROCKETS)
1037 drawpic(sbar + '296 0', "gfx/sb_rocket", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1038 else if (stat_items & NEX_IT_CELLS)
1039 drawpic(sbar + '296 0', "gfx/sb_cells", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1041 Sbar_DrawXNum('224 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1043 Sbar_DrawXNum('224 0', x, 3, 24, '0.7 0 0', 1, 0);
1046 if (sbar_x + 320 + 160 <= vid_conwidth)
1047 Sbar_MiniDeathmatchOverlay(sbar + '320 0');
1050 // The margin can be at most 8 to support 640x480 console size:
1051 // 320 + 2 * (144 + 16) = 640
1056 stat_items = getstati(STAT_ITEMS);
1058 sbar_x = (vid_conwidth - 640.0)*0.5;
1059 sbar_y = vid_conheight - 47;
1062 fade = 3 - 2 * (time - weapontime);
1065 for(i = 0; i < 8; ++i)
1069 Sbar_DrawWeapon(i+1, fade, (i + 2 == activeweapon));
1076 Sbar_DrawWeapon(0, fade, (activeweapon == 1));
1080 drawpic(sbar, "gfx/sbar", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1082 drawpic(sbar, "gfx/sbar_minimal", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1086 Sbar_DrawXNum('268 12', getstati(STAT_ARMOR), 3, 24, '0.6 0.7 0.8', 1, 0);
1090 x = getstati(STAT_HEALTH);
1092 Sbar_DrawXNum('82 12', x, 3, 24, '1 1 1', 1, 0);
1093 else if(x <= 25 && time - floor(time) > 0.5)
1094 Sbar_DrawXNum('82 12', x, 3, 24, '0.7 0 0', 1, 0);
1096 Sbar_DrawXNum('81 12', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1098 // AK dont draw ammo for the laser
1099 x = getstati(STAT_AMMO);
1100 if(activeweapon != 12)
1103 if (stat_items & NEX_IT_SHELLS)
1104 drawpic(sbar + '519 0', "gfx/sb_shells", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1105 else if (stat_items & NEX_IT_BULLETS)
1106 drawpic(sbar + '519 0', "gfx/sb_bullets", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1107 else if (stat_items & NEX_IT_ROCKETS)
1108 drawpic(sbar + '519 0', "gfx/sb_rocket", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1109 else if (stat_items & NEX_IT_CELLS)
1110 drawpic(sbar + '519 0', "gfx/sb_cells", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1112 Sbar_DrawXNum('447 12', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1114 Sbar_DrawXNum('447 12', x, 3, 24, '0.7 0 0', 1, 0);
1118 drawpic(sbar, "gfx/sbar_overlay", '0 0 0', '1 1 1', 1, DRAWFLAG_MODULATE);
1120 if (sbar_x + 600 + 160 <= vid_conwidth)
1121 Sbar_MiniDeathmatchOverlay (sbar + '600 0');
1126 // Mini scoreboard uses 12*4 per other team, that is, 144
1127 // pixels when there are four teams...
1128 // Nexuiz by default sets vid_conwidth to 800... makes
1130 // so we need to shift it by 64 pixels to the right to fit
1131 // BUT: then it overlaps with the image that gets drawn
1132 // for viewsize 100! Therefore, just account for 3 teams,
1133 // that is, 96 pixels mini scoreboard size, needing 16 pixels
1138 if(gametype == GAME_KEYHUNT)
1141 } else if(gametype == GAME_CTF)
1149 void CSQC_ctf_hud(void)
1151 // cvar("sbar_flagstatus_right") move the flag icons right
1152 // cvar("sbar_flagstatus_pos") pixel position of the nexuiz flagstatus icons
1153 float redflag, blueflag;
1157 stat_items = getstati(STAT_ITEMS);
1158 redflag = (stat_items/32768) & 3;
1159 blueflag = (stat_items/131072) & 3;
1163 * For some reason now not even THAT works there...
1164 * Maybe the minus' precedence screws it up? The last one there, maybe I should use brackets
1166 * pos_x = (cvar("sbar_flagstatus_right")) ? vid_conwidth - 10 - sbar_x - 64 : 10 - sbar_x;
1167 ** Should try those later:
1168 * pos_x = (cvar("sbar_flagstatus_right")) ? (vid_conwidth - 10 - sbar_x - 64) : (10 - sbar_x);
1169 * pos_x = ( (cvar("sbar_flagstatus_right")) ? vid_conwidth - 10 - 64 : 10 ) - sbar_x;
1172 if(cvar("sbar_flagstatus_right"))
1173 pos_x = vid_conwidth - 10 - sbar_x - 64;
1175 pos_x = 10 - sbar_x;
1179 if(sbar_hudselector == 1)
1180 pos_y = (vid_conheight - sbar_y) - cvar("sbar_flagstatus_pos") - 64;
1188 case 1: drawpic(pos, "gfx/sb_flag_red_taken", '0 0 0', '1 1 1', 1, DRAWFLAG_NORMAL); break;
1189 case 2: drawpic(pos, "gfx/sb_flag_red_lost", '0 0 0', '1 1 1', 1, DRAWFLAG_NORMAL); break;
1190 case 3: drawpic(pos, "gfx/sb_flag_red_carrying", '0 0 0', '1 1 1', 1, DRAWFLAG_NORMAL); break;
1197 case 1: drawpic(pos, "gfx/sb_flag_blue_taken", '0 0 0', '1 1 1', 1, 0); break;
1198 case 2: drawpic(pos, "gfx/sb_flag_blue_lost", '0 0 0', '1 1 1', 1, 0); break;
1199 case 3: drawpic(pos, "gfx/sb_flag_blue_carrying", '0 0 0', '1 1 1', 1, 0); break;