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 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");
288 print("^3caps^7 or ^3captures^7 Number of flags captured\n");
289 print("^3rets^7 or ^3returns^7 Number of flags returned\n");
290 print("^3frags^7 or ^3kills^7 Frags\n");
291 print("^3deaths^7 or ^3dths^7 Number of deaths\n");
294 print("Additional columns:\n");
295 for(i = 0; i < MAX_SCORE; ++i)
298 print(strcat(scores_label[i], "\n"));
302 #define MIN_NAMELEN 24
303 #define MAX_NAMELEN 24
305 string Sbar_DefaultColumnLayout()
309 case GAME_CTF: return "ping name | caps score";
310 case GAME_KEYHUNT: return "ping name | caps kills score";
311 default: return "ping name | score";
312 // TODO: add other gametypes
316 void Cmd_Sbar_SetFields(float argc)
322 // TODO: re enable with gametype dependant cvars?
323 if(argc < 2) // no arguments provided
324 argc = tokenize(strcat("x ", cvar_string("sbar_columns")));
326 if(argc == 2 && argv(1) == "default")
327 argc = tokenize(strcat("x ", Sbar_DefaultColumnLayout()));
329 argc = min(MAX_SBAR_FIELDS, argc);
332 drawfont = sbar_font;
333 digit = stringwidth("0123456789", FALSE) / 10;
335 argc = min(argc-1, MAX_SBAR_FIELDS-1);
336 for(i = 0; i < argc; ++i)
339 strunzone(sbar_title[sbar_num_fields]);
340 sbar_title[sbar_num_fields] = strzone(str);
341 sbar_size[sbar_num_fields] = stringwidth(str, FALSE);
342 str = strtolower(str);
347 sbar_field[sbar_num_fields] = SP_PING;
348 } else if(str == "name" || str == "nick") {
349 sbar_field[sbar_num_fields] = SP_NAME;
350 sbar_size[sbar_num_fields] = MIN_NAMELEN; // minimum size? any use?
351 } else if(str == "|") {
352 sbar_field[sbar_num_fields] = SP_SEPARATOR;
354 for(j = 0; j < MAX_SCORE; ++j)
356 if(str == strtolower(scores_label[j]))
360 print(strcat("^1Error:^7 Unknown score field: '", str, "'\n"));
363 //print("field ", ftos(sbar_num_fields), " is column ", ftos(j), " (", str, ")\n");
364 sbar_field[sbar_num_fields] = j;
369 sbar_field[sbar_num_fields] = SP_END;
373 vector sbar_field_rgb;
374 string Sbar_GetField(entity pl, float field)
376 float tmp, num, denom;
378 sbar_field_rgb = '1 1 1';
382 str = bufstr_get(databuf, DATABUF_PING + pl.sv_entnum);
383 tmp = max(0, min(220, stof(str)-80)) / 220;
384 sbar_field_rgb = '1 1 1' - '0 1 1'*tmp;
388 return getplayerkey(pl.sv_entnum, "name");
391 num = pl.(scores[SP_KILLS]);
392 denom = pl.(scores[SP_DEATHS]);
395 sbar_field_rgb = '0 1 0';
397 } else if(num <= 0) {
398 sbar_field_rgb = '1 0 0';
399 str = ftos(num/denom);
401 str = ftos(num/denom);
403 tmp = strstrofs(str, ".", 0);
405 str = substring(str, 0, tmp+2);
409 return ftos(pl.(scores[field]));
414 // shamelessly stolen from menu QC :P <- as if I would steal YOUR code pfft ;)
415 float textLengthUpToWidth(string theText, float maxWidth, float handleColors)
418 // The following function is SLOW.
419 // For your safety and for the protection of those around you...
420 // DO NOT CALL THIS AT HOME.
422 if(stringwidth(theText, handleColors) <= maxWidth)
423 return strlen(theText); // yeah!
425 // binary search for right place to cut string
426 float left, right, middle; // this always works
428 right = strlen(theText); // this always fails
431 middle = floor((left + right) / 2);
432 if(stringwidth(substring(theText, 0, middle), handleColors) <= maxWidth)
437 while(left < right - 1);
439 // NOTE: when color codes are involved, this binary search is,
440 // mathematically, BROKEN. However, it is obviously guaranteed to
441 // terminate, as the range still halves each time - but nevertheless, it is
442 // guaranteed that it finds ONE valid cutoff place (where "left" is in
443 // range, and "right" is outside).
447 string textShortenToWidth(string theText, float maxWidth, float handleColors)
449 if(stringwidth(theText, handleColors) <= maxWidth)
452 return strcat(substring(theText, 0, textLengthUpToWidth(theText, maxWidth - stringwidth("...", handleColors), handleColors)), "...");
455 float xmin, xmax, ymin, ymax, sbwidth, sbheight;
457 void Sbar_PrintScoreboardItem(vector pos, entity pl, float is_self)
463 is_spec = (GetPlayerColor(pl.sv_entnum) == COLOR_SPECTATOR);
470 tmp_y = sbar_fontsize_y;
471 drawfill(pos - '1 1', tmp + '2 2', '1 1 1', 0.3, DRAWFLAG_NORMAL);
475 for(i = 0; i < sbar_num_fields; ++i)
477 field = sbar_field[i];
478 if(field == SP_SEPARATOR)
481 if(is_spec && field != SP_NAME && field != SP_PING) {
482 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
485 str = Sbar_GetField(pl, field);
491 realsize = sbar_size[i];
492 if(i+1 < sbar_num_fields)
493 if(sbar_field[i+1] == SP_SEPARATOR)
495 realsize = (xmax - xmin) / sbar_fontsize_x;
496 for(j = 0; j < sbar_num_fields; ++j) if(j != i) if(sbar_field[j] != SP_SEPARATOR)
497 realsize -= sbar_size[j] + 1;
500 str = textShortenToWidth(str, realsize, TRUE);
502 len = stringwidth(str, TRUE);
504 if(sbar_size[i] < len)
507 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
509 if(field == SP_NAME) {
510 tmp_x = sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
511 drawcolorcodedstring(pos - tmp, str, sbar_fontsize, 1, DRAWFLAG_NORMAL);
513 tmp_x = len*sbar_fontsize_x + sbar_fontsize_x;
514 drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, 1, DRAWFLAG_NORMAL);
518 if(sbar_field[i] == SP_SEPARATOR)
521 for(i = sbar_num_fields-1; i > 0; --i)
523 field = sbar_field[i];
524 if(field == SP_SEPARATOR)
527 if(is_spec && field != SP_NAME && field != SP_PING) {
528 pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
532 str = Sbar_GetField(pl, field);
535 str = textShortenToWidth(str, sbar_size[i], TRUE);
536 len = stringwidth(str, TRUE);
538 if(sbar_size[i] < len)
541 if(field == SP_NAME) {
542 tmp_x = sbar_fontsize_x*len; // left or right aligned? let's put it right...
543 drawcolorcodedstring(pos - tmp, str, sbar_fontsize, 1, DRAWFLAG_NORMAL);
545 tmp_x = sbar_fontsize_x*len; //strlen(str);
546 drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, 1, DRAWFLAG_NORMAL);
548 pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
553 void Sbar_DrawScoreboard()
555 //float xmin, ymin, xmax, ymax;
556 vector rgb, pos, tmp, sbar_save;
561 sbar_fontsize = Sbar_GetFontsize();
562 if(sbar_fontsize_x == 0)
563 sbar_fontsize = '8 8 0';
564 if(sbar_fontsize_y == 0)
565 sbar_fontsize_y = sbar_fontsize_x;
567 xmin = vid_conwidth / 5;
570 xmax = vid_conwidth - xmin;
571 ymax = vid_conheight - 0.2*vid_conheight;
573 sbwidth = xmax - xmin;
574 sbheight = ymax - ymin;
576 center_x = xmin + 0.5*sbwidth;
578 //Sbar_UpdateFields();
580 // Initializes position
586 drawfont = sbar_font;
587 pos_x = center_x - stringwidth("Scoreboard", TRUE)*0.5*24;
588 drawstring(pos, "Scoreboard", '24 24', '1 1 1', 1, DRAWFLAG_NORMAL);
592 // Titlebar background:
594 tmp_y = sbar_fontsize_y;
595 drawfill(pos - '1 1', tmp + '2 2', '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
597 for(i = 0; i < sbar_num_fields; ++i)
599 if(sbar_field[i] == SP_SEPARATOR)
601 drawstring(pos, sbar_title[i], sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
602 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
605 if(sbar_field[i] == SP_SEPARATOR)
607 pos_x = xmax + sbar_fontsize_x;
609 for(i = sbar_num_fields-1; i > 0; --i)
611 if(sbar_field[i] == SP_SEPARATOR)
614 pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
617 * Using the following line will fuck it all up:
619 * tmp_x = sbar_size[i] - strlen(sbar_title[i])*8;
621 tmp_x = sbar_fontsize_x*sbar_size[i];
622 tmp_x -= stringwidth(sbar_title[i], FALSE)*sbar_fontsize_x;
623 drawstring(pos + tmp, sbar_title[i], sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
628 pos_y += 1.5 * sbar_fontsize_y;
635 //for(tm = sortedTeams.sort_next; tm; tm = tm.sort_next)
636 for(tm = teams.sort_next; tm; tm = tm.sort_next)
638 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
641 rgb = GetTeamRGB(tm.team);
644 // TODO: Print primary and secondary scores!
648 specs = tm.team_size;
654 tmp_y = 1.25 * sbar_fontsize_y * specs;
655 drawfill(pos - '1 1', tmp + '2 0', rgb, 0.2, DRAWFLAG_NORMAL);
657 for(pl = players.sort_next; pl; pl = pl.sort_next)
659 if(pl.team != tm.team)
661 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
662 pos_y += 1.25 * sbar_fontsize_y;
663 tmp_y -= 1.25 * sbar_fontsize_y;
665 pos_y += tmp_y + 1.5 * sbar_fontsize_y;
667 // rgb := tempvector :)
668 rgb = pos + '0 1.5 0' * sbar_fontsize_y;
669 pos_y += 3 * sbar_fontsize_y;
671 for(pl = players.sort_next; pl; pl = pl.sort_next)
673 if(pl.team != COLOR_SPECTATOR)
675 //drawcolorcodedstring(pos, getplayerkey(pl.sb_player, "name"), '8 8 0', 1, 0);
676 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
677 pos += '0 1.25 0' * sbar_fontsize_y;
682 drawstring(rgb, "Spectators", sbar_fontsize, '1 1 1', 1, 0);
685 for(pl = players.sort_next; pl; pl = pl.sort_next)
687 if(pl.team == COLOR_SPECTATOR)
689 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
690 pos_y += 1.25 * sbar_fontsize_y;
691 tmp_y -= 1.25 * sbar_fontsize_y;
694 // rgb := tempvector :)
695 rgb = pos + '0 1.5 0' * sbar_fontsize_y;
696 pos_y += 3 * sbar_fontsize_y;
698 for(pl = players.sort_next; pl; pl = pl.sort_next)
700 if(pl.team != COLOR_SPECTATOR)
702 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
703 pos += '0 1.25 0' * sbar_fontsize_y;
708 drawstring(rgb, "Spectators", sbar_fontsize, '1 1 1', 1, 0);
713 void Sbar_Score(float margin)
715 float timelimit, timeleft, minutes, seconds, distribution, myplace, score;
716 vector sbar_save, place;
720 sbar_y = vid_conheight - (32+12);
731 //for(i = 0; i < 4; ++i)
732 for(tm = teams.sort_next; tm; tm = tm.sort_next)
734 if(tm.team == COLOR_SPECTATOR || !tm.team_size) // no players? don't display
737 score = tm.(teamscores[ts_primary]);
738 if(tm.team == myteam)
739 Sbar_DrawXNum('-128 0', score, 4, 32, GetTeamRGB(tm.team), 1, DRAWFLAG_NORMAL);
742 Sbar_DrawXNum(place, score, 4, 12, GetTeamRGB(tm.team), 1, DRAWFLAG_NORMAL);
747 // me vector := [team/connected frags id]
749 for(me = players.sort_next; me; me = me.sort_next)
751 if(me.team != COLOR_SPECTATOR)
753 if(me.sv_entnum == player_localentnum - 1)
761 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
766 Sbar_DrawXNum('-36 -12', myplace, 3, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
767 else if(myplace == 2)
768 Sbar_DrawXNum('-36 -12', myplace, 3, 12, '1 1 0', 1, DRAWFLAG_NORMAL);
770 Sbar_DrawXNum('-36 -12', myplace, 3, 12, '1 0 0', 1, DRAWFLAG_NORMAL);
772 score = me.(scores[ps_primary]);
773 if(distribution >= 0)
775 Sbar_DrawXNum('-84 -12', distribution, 4, 12, ' 1 1 1', 1, DRAWFLAG_NORMAL);
776 Sbar_DrawXNum('-128 0', score, 4, 32, '1 1 1', 1, DRAWFLAG_NORMAL);
777 } else if(distribution >= -5)
779 Sbar_DrawXNum('-84 -12', distribution, 4, 12, ' 1 1 0', 1, DRAWFLAG_NORMAL);
780 Sbar_DrawXNum('-128 0', score, 4, 32, '1 1 0', 1, DRAWFLAG_NORMAL);
782 Sbar_DrawXNum('-84 -12', distribution, 4, 12, ' 1 0 0', 1, DRAWFLAG_NORMAL);
783 Sbar_DrawXNum('-128 0', score, 4, 32, '1 0 0', 1, DRAWFLAG_NORMAL);
786 timelimit = getstatf(STAT_TIMELIMIT);
789 timeleft = max(0, timelimit * 60 - time);
790 minutes = floor(timeleft / 60);
791 seconds = floor(timeleft - minutes*60);
794 Sbar_DrawXNum('-72 32', minutes, 3, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
795 drawpic(sbar + '-36 32', "gfx/num_colon", '12 12', '1 1 1', sbar_alpha_fg, 0);
796 Sbar_DrawXNum('-24 32', seconds, -2, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
797 } else if(minutes >= 1)
799 Sbar_DrawXNum('-72 32', minutes, 3, 12, '1 1 0', 1, DRAWFLAG_NORMAL);
800 drawpic(sbar + '-36 32', "gfx/num_colon", '12 12', '1 1 0', sbar_alpha_fg, 0);
801 Sbar_DrawXNum('-24 32', seconds, -2, 12, '1 1 0', 1, DRAWFLAG_NORMAL);
803 Sbar_DrawXNum('-24 32', seconds, -2, 12, '1 0 0', 1, DRAWFLAG_NORMAL);
806 minutes = floor(time / 60);
807 seconds = floor(time - minutes*60);
808 Sbar_DrawXNum('-72 32', minutes, 3, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
809 drawpic(sbar + '-36 32', "gfx/num_colon", '12 12', '1 1 1', sbar_alpha_fg, 0);
810 Sbar_DrawXNum('-24 32', seconds, -2, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
815 void Sbar_MiniscoreItem(vector pos, entity pl, float is_self)
821 drawfill(pos + '0 1 0', '40 6 0', GetTeamRGB(pl.team)*0.5, 1, DRAWFLAG_NORMAL);
823 drawfill(pos + '0 1 0', '40 6 0', '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
826 score = pl.(scores[ps_primary]);
827 pos_x -= stringwidth(ftos(score), FALSE)*8;
828 drawstring(pos, ftos(score), '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
833 drawstring(pos, "\x0D", '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
837 drawcolorcodedstring(pos, getplayerkey(pl.sv_entnum, "name"), '8 8 0', 1, 0);
840 void Sbar_MiniscoreTeamItem(vector pos, float color, float frags, float is_self)
846 drawfill(pos + '0 1 0', '40 6 0', GetTeamRGB(color)*0.5, 1, DRAWFLAG_NORMAL);
848 drawfill(pos + '0 1 0', '40 6 0', '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
851 pos_x -= stringwidth(ftos(frags), FALSE)*8;
852 drawstring(pos, ftos(frags), '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
857 drawstring(pos, "\x0D", '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
861 drawstring(pos, GetTeamName(color), '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
864 void Sbar_MiniDeathmatchOverlay(vector pos)
866 float numlines, up, down, score;
868 float miniscoreboard_size;
869 miniscoreboard_size = cvar("sbar_miniscoreboard_size");
871 if(miniscoreboard_size == 0)
873 pos_y = vid_conheight - 8;
875 if(miniscoreboard_size < 0)
876 numlines = (vid_conheight - sbar_y + 7) / 8;
878 numlines = miniscoreboard_size;
880 // give up if there isn't enough room
881 if(pos_x >= vid_conwidth || pos_y >= vid_conheight || numlines < 1)
884 // me vector := [team/connected frags id]
885 for(me = players.sort_next; me; me = me.sort_next)
887 if(me.sv_entnum == player_localentnum - 1)
892 numlines -= numteams;
894 // figure out how many players above and below we can show
895 up = floor(numlines/2);
897 if((up + down) > numlines)
898 down = numlines - up;
901 for(pl = me.sort_next; pl && down > 0; pl = pl.sort_next)
903 if(pl.team == COLOR_SPECTATOR)
905 Sbar_MiniscoreItem(pos, pl, false);
909 Sbar_MiniscoreItem(pos, me, true);
911 up += down; // if there weren't enough lines below... add them
912 for(pl = me.sort_prev; pl && up > 0; pl = pl.sort_prev)
914 if(pl.team == COLOR_SPECTATOR)
916 Sbar_MiniscoreItem(pos, pl, false);
923 for(tm = teams.sort_next; tm.sort_next; tm = tm.sort_next);
924 for(; tm; tm = tm.sort_prev)
926 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
928 score = tm.(teamscores[ts_primary]);
929 Sbar_MiniscoreTeamItem(pos, tm.team, score, (tm.team == me.team));
935 void Sbar_Draw (void)
942 Sbar_UpdatePlayerTeams();
947 Sbar_DrawScoreboard();
948 else if (intermission == 1)
950 Sbar_DrawScoreboard();
953 else if (intermission == 2)
954 Sbar_FinaleOverlay();
957 if (sb_showscores || (getstati(STAT_HEALTH) <= 0 && cvar("cl_deathscoreboard")))
959 sbar_x = (vid_conwidth - 640.0)*0.5;
960 sbar_y = vid_conheight - 47;
961 //Sbar_DrawAlphaPic (sbar_x, sbar_y, sb_scorebar, sbar_alpha_bg.value);
962 //drawpic('0 0', "gfx/scorebar", '0 0 0', '1 1 1', cvar("sbar_alpha_bg"), 0);
963 Sbar_DrawScoreboard ();
967 if (sb_lines && sbar_hudselector == 1)
969 stat_items = getstati(STAT_ITEMS);
971 sbar_x = (vid_conwidth - 320.0)*0.5;
972 sbar_y = vid_conheight - 24.0 - 16.0;
975 fade = 3.2 - 2 * (time - weapontime);
976 fade = bound(0.7, fade, 1);
979 for(i = 0; i < 8; ++i)
983 Sbar_DrawWeapon(i+1, fade, (i + 2 == activeweapon));
990 Sbar_DrawWeapon(0, fade, (activeweapon == 1));
994 x = getstati(STAT_ARMOR);
998 //Sbar_DrawStretchPic (72, 0, sb_armor[0], sbar_alpha_fg.value, 24, 24);
999 drawpic(sbar + '72 0', "gfx/sb_armor", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1001 Sbar_DrawXNum('0 0', x, 3, 24, '0 1 0', 1, 0);
1003 Sbar_DrawXNum('0 0', x, 3, 24, '0.2 1 0', 1, 0);
1005 Sbar_DrawXNum('0 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1007 Sbar_DrawXNum('0 0', x, 3, 24, '1 1 0.2', 1, 0);
1009 Sbar_DrawXNum('0 0', x, 3, 24, '0.7 0 0', 1, 0);
1013 x = getstati(STAT_HEALTH);
1017 //Sbar_DrawStretchPic (184, 0, sb_health, sbar_alpha_fg.value, 24, 24);
1018 drawpic(sbar + '184 0', "gfx/sb_health", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1020 Sbar_DrawXNum('112 0', x, 3, 24, '0 1 0', 1, 0);
1022 Sbar_DrawXNum('112 0', x, 3, 24, '0.2 1 0', 1, 0);
1024 Sbar_DrawXNum('112 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1026 Sbar_DrawXNum('112 0', x, 3, 24, '1 1 0.2', 1, 0);
1028 Sbar_DrawXNum('112 0', x, 3, 24, '0.7 0 0', 1, 0);
1032 x = getstati(STAT_AMMO);
1033 if ((stat_items & (NEX_IT_SHELLS | NEX_IT_BULLETS | NEX_IT_ROCKETS | NEX_IT_CELLS)) || x != 0)
1035 if (stat_items & NEX_IT_SHELLS)
1036 drawpic(sbar + '296 0', "gfx/sb_shells", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1037 else if (stat_items & NEX_IT_BULLETS)
1038 drawpic(sbar + '296 0', "gfx/sb_bullets", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1039 else if (stat_items & NEX_IT_ROCKETS)
1040 drawpic(sbar + '296 0', "gfx/sb_rocket", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1041 else if (stat_items & NEX_IT_CELLS)
1042 drawpic(sbar + '296 0', "gfx/sb_cells", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1044 Sbar_DrawXNum('224 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1046 Sbar_DrawXNum('224 0', x, 3, 24, '0.7 0 0', 1, 0);
1049 if (sbar_x + 320 + 160 <= vid_conwidth)
1050 Sbar_MiniDeathmatchOverlay(sbar + '320 0');
1053 // The margin can be at most 8 to support 640x480 console size:
1054 // 320 + 2 * (144 + 16) = 640
1059 stat_items = getstati(STAT_ITEMS);
1061 sbar_x = (vid_conwidth - 640.0)*0.5;
1062 sbar_y = vid_conheight - 47;
1065 fade = 3 - 2 * (time - weapontime);
1068 for(i = 0; i < 8; ++i)
1072 Sbar_DrawWeapon(i+1, fade, (i + 2 == activeweapon));
1079 Sbar_DrawWeapon(0, fade, (activeweapon == 1));
1083 drawpic(sbar, "gfx/sbar", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1085 drawpic(sbar, "gfx/sbar_minimal", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1089 Sbar_DrawXNum('268 12', getstati(STAT_ARMOR), 3, 24, '0.6 0.7 0.8', 1, 0);
1093 x = getstati(STAT_HEALTH);
1095 Sbar_DrawXNum('82 12', x, 3, 24, '1 1 1', 1, 0);
1096 else if(x <= 25 && time - floor(time) > 0.5)
1097 Sbar_DrawXNum('82 12', x, 3, 24, '0.7 0 0', 1, 0);
1099 Sbar_DrawXNum('81 12', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1101 // AK dont draw ammo for the laser
1102 x = getstati(STAT_AMMO);
1103 if(activeweapon != 12)
1106 if (stat_items & NEX_IT_SHELLS)
1107 drawpic(sbar + '519 0', "gfx/sb_shells", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1108 else if (stat_items & NEX_IT_BULLETS)
1109 drawpic(sbar + '519 0', "gfx/sb_bullets", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1110 else if (stat_items & NEX_IT_ROCKETS)
1111 drawpic(sbar + '519 0', "gfx/sb_rocket", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1112 else if (stat_items & NEX_IT_CELLS)
1113 drawpic(sbar + '519 0', "gfx/sb_cells", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1115 Sbar_DrawXNum('447 12', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1117 Sbar_DrawXNum('447 12', x, 3, 24, '0.7 0 0', 1, 0);
1121 drawpic(sbar, "gfx/sbar_overlay", '0 0 0', '1 1 1', 1, DRAWFLAG_MODULATE);
1123 if (sbar_x + 600 + 160 <= vid_conwidth)
1124 Sbar_MiniDeathmatchOverlay (sbar + '600 0');
1129 // Mini scoreboard uses 12*4 per other team, that is, 144
1130 // pixels when there are four teams...
1131 // Nexuiz by default sets vid_conwidth to 800... makes
1133 // so we need to shift it by 64 pixels to the right to fit
1134 // BUT: then it overlaps with the image that gets drawn
1135 // for viewsize 100! Therefore, just account for 3 teams,
1136 // that is, 96 pixels mini scoreboard size, needing 16 pixels
1141 if(gametype == GAME_KEYHUNT)
1144 } else if(gametype == GAME_CTF)
1152 void CSQC_ctf_hud(void)
1154 // cvar("sbar_flagstatus_right") move the flag icons right
1155 // cvar("sbar_flagstatus_pos") pixel position of the nexuiz flagstatus icons
1156 float redflag, blueflag;
1160 stat_items = getstati(STAT_ITEMS);
1161 redflag = (stat_items/32768) & 3;
1162 blueflag = (stat_items/131072) & 3;
1166 * For some reason now not even THAT works there...
1167 * Maybe the minus' precedence screws it up? The last one there, maybe I should use brackets
1169 * pos_x = (cvar("sbar_flagstatus_right")) ? vid_conwidth - 10 - sbar_x - 64 : 10 - sbar_x;
1170 ** Should try those later:
1171 * pos_x = (cvar("sbar_flagstatus_right")) ? (vid_conwidth - 10 - sbar_x - 64) : (10 - sbar_x);
1172 * pos_x = ( (cvar("sbar_flagstatus_right")) ? vid_conwidth - 10 - 64 : 10 ) - sbar_x;
1175 if(cvar("sbar_flagstatus_right"))
1176 pos_x = vid_conwidth - 10 - sbar_x - 64;
1178 pos_x = 10 - sbar_x;
1182 if(sbar_hudselector == 1)
1183 pos_y = (vid_conheight - sbar_y) - cvar("sbar_flagstatus_pos") - 64;
1191 case 1: drawpic(pos, "gfx/sb_flag_red_taken", '0 0 0', '1 1 1', 1, DRAWFLAG_NORMAL); break;
1192 case 2: drawpic(pos, "gfx/sb_flag_red_lost", '0 0 0', '1 1 1', 1, DRAWFLAG_NORMAL); break;
1193 case 3: drawpic(pos, "gfx/sb_flag_red_carrying", '0 0 0', '1 1 1', 1, DRAWFLAG_NORMAL); break;
1200 case 1: drawpic(pos, "gfx/sb_flag_blue_taken", '0 0 0', '1 1 1', 1, 0); break;
1201 case 2: drawpic(pos, "gfx/sb_flag_blue_lost", '0 0 0', '1 1 1', 1, 0); break;
1202 case 3: drawpic(pos, "gfx/sb_flag_blue_carrying", '0 0 0', '1 1 1', 1, 0); break;