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 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 ps_primary = ps_secondary = ts_primary = ts_secondary = -1;
140 for(i = 0; i < MAX_SCORE; ++i)
142 f = (scores_flags[i] & SFL_SORT_PRIO_MASK);
143 if(f == SFL_SORT_PRIO_PRIMARY)
145 if(f == SFL_SORT_PRIO_SECONDARY)
148 if(ps_secondary == -1)
149 ps_secondary = ps_primary;
151 for(i = 0; i < MAX_TEAMSCORE; ++i)
153 f = (teamscores_flags[i] & SFL_SORT_PRIO_MASK);
154 if(f == SFL_SORT_PRIO_PRIMARY)
156 if(f == SFL_SORT_PRIO_SECONDARY)
159 if(ts_secondary == -1)
160 ts_secondary = ts_primary;
162 Cmd_Sbar_SetFields(0);
165 void Sbar_UpdatePlayerPos(entity pl);
166 void Sbar_UpdatePlayerTeams()
173 for(pl = players.sort_next; pl; pl = pl.sort_next)
176 Team = GetPlayerColor(pl.sv_entnum);
179 tmp = GetTeam(pl.team, false);
181 tmp = GetTeam(Team, true);
187 Sbar_UpdatePlayerPos(pl);
191 pl = players.sort_next;
194 //print(strcat("PNUM: ", ftos(num), "\n"));
197 float Sbar_ComparePlayerScores(entity left, entity right)
200 vl = GetPlayerColor(left.sv_entnum);
201 vr = GetPlayerColor(right.sv_entnum);
208 vl = left.scores[ps_primary];
209 vr = right.scores[ps_primary];
211 return IS_INCREASING(scores_flags[ps_primary]);
213 return IS_DECREASING(scores_flags[ps_primary]);
215 vl = left.scores[ps_secondary];
216 vr = right.scores[ps_secondary];
218 return IS_INCREASING(scores_flags[ps_secondary]);
220 return IS_DECREASING(scores_flags[ps_secondary]);
225 void Sbar_UpdatePlayerPos(entity player)
227 for(other = player.sort_next; other && Sbar_ComparePlayerScores(player, other); other = player.sort_next)
229 SORT_SWAP(player, other);
231 for(other = player.sort_prev; other != players && Sbar_ComparePlayerScores(other, player); other = player.sort_prev)
233 SORT_SWAP(other, player);
237 float Sbar_CompareTeamScores(entity left, entity right)
241 if(left.team == COLOR_SPECTATOR)
243 if(right.team == COLOR_SPECTATOR)
246 vl = left.teamscores[ts_primary];
247 vr = right.teamscores[ts_primary];
249 return IS_INCREASING(teamscores_flags[ts_primary]);
251 return IS_DECREASING(teamscores_flags[ts_primary]);
253 vl = left.teamscores[ts_secondary];
254 vr = right.teamscores[ts_secondary];
256 return IS_INCREASING(teamscores_flags[ts_secondary]);
258 return IS_DECREASING(teamscores_flags[ts_secondary]);
263 void Sbar_UpdateTeamPos(entity Team)
265 for(other = Team.sort_next; other && Sbar_CompareTeamScores(Team, other); other = Team.sort_next)
267 SORT_SWAP(Team, other);
269 for(other = Team.sort_prev; other != teams && Sbar_CompareTeamScores(other, Team); other = Team.sort_prev)
271 SORT_SWAP(other, Team);
275 void Cmd_Sbar_Help(float argc)
277 print("You can modify the scoreboard using the\n");
278 print("^3|---------------------------------------------------------------|\n");
279 print("^1 TO BE DONE\n");
281 print("^2sbar_columns_set default\n");
282 print("^2sbar_columns_set ^7filed1 field2 ...\n");
283 print("The following field names are recognized (case INsensitive):\n");
284 print("You can use a ^3|^7 to start the right-aligned fields.\n");
286 print("^3name^7 or ^3nick^7 Name of a player\n");
287 print("^3ping^7 Ping time\n\n");
288 print("^3kd^7 or ^3kdr^7 or ^3kdratio^7 or ^3k/d\n");
289 print(" The kill-death ratio\n");
291 print("Before a field you can put a + or - sign, then a comma separated list\n");
292 print("of game types, then a slash, to make the field show up only in these\n");
293 print("or in all but these game types.\n");
296 print("^3caps^7 or ^3captures^7 Number of flags captured\n");
297 print("^3rets^7 or ^3returns^7 Number of flags returned\n");
298 print("^3frags^7 or ^3kills^7 Frags\n");
299 print("^3deaths^7 or ^3dths^7 Number of deaths\n");
302 print("Additional columns:\n");
303 for(i = 0; i < MAX_SCORE; ++i)
305 if(scores_label[i] != "")
306 print(strcat(scores_label[i], "\n"));
310 #define MIN_NAMELEN 24
311 #define MAX_NAMELEN 24
313 string Sbar_DefaultColumnLayout()
315 return "ping name | +kh,ctf/caps -ctf,kh/kills -ctf,kh/deaths -lms/score +lms/lives +lms/place";
319 case GAME_CTF: return "ping name | caps score";
320 case GAME_KEYHUNT: return "ping name | caps kills score";
321 default: return "ping name | score";
322 // TODO: add other gametypes
327 void Cmd_Sbar_SetFields(float argc)
330 string str, pattern, subpattern;
333 // TODO: re enable with gametype dependant cvars?
334 if(argc < 2) // no arguments provided
335 argc = tokenizebyseparator(strcat("x ", cvar_string("sbar_columns")), " ");
338 argc = tokenizebyseparator(strcat("x ", Sbar_DefaultColumnLayout()), " ");
342 if(argv(1) == "default")
343 argc = tokenizebyseparator(strcat("x ", Sbar_DefaultColumnLayout()), " ");
344 else if(argv(1) == "all")
348 for(i = 0; i < MAX_SCORE; ++i)
351 if(i != ps_secondary)
352 if(scores_label[i] != "")
353 s = strcat(s, " ", scores_label[i]);
355 if(ps_secondary != ps_primary)
356 s = strcat(s, " ", scores_label[ps_secondary]);
357 s = strcat(s, " ", scores_label[ps_primary]);
358 argc = tokenizebyseparator(strcat("x ", s), " ");
363 argc = min(MAX_SBAR_FIELDS, argc);
366 drawfont = sbar_font;
367 digit = stringwidth("0123456789", FALSE) / 10;
369 subpattern = strcat(",", GametypeNameFromType(gametype), ",");
371 argc = min(argc-1, MAX_SBAR_FIELDS-1);
372 for(i = 0; i < argc; ++i)
376 slash = strstrofs(str, "/", 0);
379 pattern = substring(str, 0, slash);
380 str = substring(str, slash + 1, strlen(str) - (slash + 1));
382 if(substring(pattern, 0, 1) == "-")
384 pattern = substring(pattern, 1, strlen(pattern) - 1);
385 if(strstrofs(strcat(",", pattern, ","), subpattern, 0) >= 0)
390 if(substring(pattern, 0, 1) == "+")
391 pattern = substring(pattern, 1, strlen(pattern) - 1);
392 if(strstrofs(strcat(",", pattern, ","), subpattern, 0) < 0)
397 strunzone(sbar_title[sbar_num_fields]);
398 sbar_title[sbar_num_fields] = strzone(str);
399 sbar_size[sbar_num_fields] = stringwidth(str, FALSE);
400 str = strtolower(str);
403 sbar_field[sbar_num_fields] = SP_PING;
404 } else if(str == "name" || str == "nick") {
405 sbar_field[sbar_num_fields] = SP_NAME;
406 sbar_size[sbar_num_fields] = MIN_NAMELEN; // minimum size? any use?
407 } else if(str == "|") {
408 sbar_field[sbar_num_fields] = SP_SEPARATOR;
410 for(j = 0; j < MAX_SCORE; ++j)
411 if(str == strtolower(scores_label[j]))
412 goto found; // sorry, but otherwise fteqcc -O3 miscompiles this and warns about "unreachable code"
414 print(strcat("^1Error:^7 Unknown score field: '", str, "'\n"));
417 sbar_field[sbar_num_fields] = j;
421 sbar_field[sbar_num_fields] = SP_END;
425 vector sbar_field_rgb;
426 string Sbar_GetField(entity pl, float field)
428 float tmp, num, denom, f;
430 sbar_field_rgb = '1 1 1';
434 str = bufstr_get(databuf, DATABUF_PING + pl.sv_entnum);
435 tmp = max(0, min(220, stof(str)-80)) / 220;
436 sbar_field_rgb = '1 1 1' - '0 1 1'*tmp;
440 return getplayerkey(pl.sv_entnum, "name");
443 num = pl.(scores[SP_KILLS]);
444 denom = pl.(scores[SP_DEATHS]);
447 sbar_field_rgb = '0 1 0';
449 } else if(num <= 0) {
450 sbar_field_rgb = '1 0 0';
451 str = ftos(num/denom);
453 str = ftos(num/denom);
455 tmp = strstrofs(str, ".", 0);
457 str = substring(str, 0, tmp+2);
461 tmp = pl.(scores[field]);
462 f = scores_flags[field];
463 if(field == ps_primary)
464 sbar_field_rgb = '1 1 0';
465 else if(field == ps_secondary)
466 sbar_field_rgb = '0 1 1';
468 sbar_field_rgb = '1 1 1';
470 if(f & SFL_HIDE_ZERO)
477 // shamelessly stolen from menu QC :P <- as if I would steal YOUR code pfft ;)
478 float textLengthUpToWidth(string theText, float maxWidth, float handleColors)
481 // The following function is SLOW.
482 // For your safety and for the protection of those around you...
483 // DO NOT CALL THIS AT HOME.
485 if(stringwidth(theText, handleColors) <= maxWidth)
486 return strlen(theText); // yeah!
488 // binary search for right place to cut string
489 float left, right, middle; // this always works
491 right = strlen(theText); // this always fails
494 middle = floor((left + right) / 2);
495 if(stringwidth(substring(theText, 0, middle), handleColors) <= maxWidth)
500 while(left < right - 1);
502 // NOTE: when color codes are involved, this binary search is,
503 // mathematically, BROKEN. However, it is obviously guaranteed to
504 // terminate, as the range still halves each time - but nevertheless, it is
505 // guaranteed that it finds ONE valid cutoff place (where "left" is in
506 // range, and "right" is outside).
510 string textShortenToWidth(string theText, float maxWidth, float handleColors)
512 if(stringwidth(theText, handleColors) <= maxWidth)
515 return strcat(substring(theText, 0, textLengthUpToWidth(theText, maxWidth - stringwidth("...", handleColors), handleColors)), "...");
518 float xmin, xmax, ymin, ymax, sbwidth, sbheight;
520 void Sbar_PrintScoreboardItem(vector pos, entity pl, float is_self)
526 is_spec = (GetPlayerColor(pl.sv_entnum) == COLOR_SPECTATOR);
533 tmp_y = sbar_fontsize_y;
534 drawfill(pos - '1 1 0', tmp + '2 2 0', '1 1 1', 0.3, DRAWFLAG_NORMAL);
538 for(i = 0; i < sbar_num_fields; ++i)
540 field = sbar_field[i];
541 if(field == SP_SEPARATOR)
544 if(is_spec && field != SP_NAME && field != SP_PING) {
545 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
548 str = Sbar_GetField(pl, field);
554 realsize = sbar_size[i];
555 if(i+1 < sbar_num_fields)
556 if(sbar_field[i+1] == SP_SEPARATOR)
558 realsize = (xmax - xmin) / sbar_fontsize_x;
559 for(j = 0; j < sbar_num_fields; ++j) if(j != i) if(sbar_field[j] != SP_SEPARATOR)
560 realsize -= sbar_size[j] + 1;
563 str = textShortenToWidth(str, realsize, TRUE);
565 len = stringwidth(str, TRUE);
567 if(sbar_size[i] < len)
570 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
572 if(field == SP_NAME) {
573 tmp_x = sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
574 drawcolorcodedstring(pos - tmp, str, sbar_fontsize, 1, DRAWFLAG_NORMAL);
576 tmp_x = len*sbar_fontsize_x + sbar_fontsize_x;
577 drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, 1, DRAWFLAG_NORMAL);
581 if(sbar_field[i] == SP_SEPARATOR)
584 for(i = sbar_num_fields-1; i > 0; --i)
586 field = sbar_field[i];
587 if(field == SP_SEPARATOR)
590 if(is_spec && field != SP_NAME && field != SP_PING) {
591 pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
595 str = Sbar_GetField(pl, field);
598 str = textShortenToWidth(str, sbar_size[i], TRUE);
599 len = stringwidth(str, TRUE);
601 if(sbar_size[i] < len)
604 if(field == SP_NAME) {
605 tmp_x = sbar_fontsize_x*len; // left or right aligned? let's put it right...
606 drawcolorcodedstring(pos - tmp, str, sbar_fontsize, 1, DRAWFLAG_NORMAL);
608 tmp_x = sbar_fontsize_x*len; //strlen(str);
609 drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, 1, DRAWFLAG_NORMAL);
611 pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
616 void Sbar_DrawScoreboard()
618 //float xmin, ymin, xmax, ymax;
619 vector rgb, pos, tmp, sbar_save;
624 sbar_fontsize = Sbar_GetFontsize();
625 if(sbar_fontsize_x == 0)
626 sbar_fontsize = '8 8 0';
627 if(sbar_fontsize_y == 0)
628 sbar_fontsize_y = sbar_fontsize_x;
630 xmin = vid_conwidth / 5;
633 xmax = vid_conwidth - xmin;
634 ymax = vid_conheight - 0.2*vid_conheight;
636 sbwidth = xmax - xmin;
637 sbheight = ymax - ymin;
639 center_x = xmin + 0.5*sbwidth;
641 //Sbar_UpdateFields();
643 // Initializes position
649 drawfont = sbar_font;
650 pos_x = center_x - stringwidth("Scoreboard", TRUE)*0.5*24;
651 drawstring(pos, "Scoreboard", '24 24 0', '1 1 1', 1, DRAWFLAG_NORMAL);
655 // Titlebar background:
657 tmp_y = sbar_fontsize_y;
658 drawfill(pos - '1 1 0', tmp + '2 2 0', '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
660 for(i = 0; i < sbar_num_fields; ++i)
662 if(sbar_field[i] == SP_SEPARATOR)
664 drawstring(pos, sbar_title[i], sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
665 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
668 if(sbar_field[i] == SP_SEPARATOR)
670 pos_x = xmax + sbar_fontsize_x;
672 for(i = sbar_num_fields-1; i > 0; --i)
674 if(sbar_field[i] == SP_SEPARATOR)
677 pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
680 * Using the following line will fuck it all up:
682 * tmp_x = sbar_size[i] - strlen(sbar_title[i])*8;
684 tmp_x = sbar_fontsize_x*sbar_size[i];
685 tmp_x -= stringwidth(sbar_title[i], FALSE)*sbar_fontsize_x;
686 drawstring(pos + tmp, sbar_title[i], sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
691 pos_y += 1.5 * sbar_fontsize_y;
698 //for(tm = sortedTeams.sort_next; tm; tm = tm.sort_next)
699 for(tm = teams.sort_next; tm; tm = tm.sort_next)
701 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
704 rgb = GetTeamRGB(tm.team);
709 pos - '6.5 0 0' * sbar_fontsize_y,
710 tm.(teamscores[ts_primary]),
711 4, sbar_fontsize_y * 1.5, rgb, 1, DRAWFLAG_NORMAL);
713 if(ts_primary != ts_secondary)
715 pos - '4.5 0 0' * sbar_fontsize_y + '0 1.5 0' * sbar_fontsize_y,
716 tm.(teamscores[ts_secondary]),
717 4, sbar_fontsize_y * 1, rgb, 1, DRAWFLAG_NORMAL);
719 specs = tm.team_size;
725 tmp_y = 1.25 * sbar_fontsize_y * specs;
726 drawfill(pos - '1 1 0', tmp + '2 0 0', rgb, 0.2, DRAWFLAG_NORMAL);
728 for(pl = players.sort_next; pl; pl = pl.sort_next)
730 if(pl.team != tm.team)
732 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
733 pos_y += 1.25 * sbar_fontsize_y;
734 tmp_y -= 1.25 * sbar_fontsize_y;
736 pos_y += tmp_y + 1.5 * sbar_fontsize_y;
738 // rgb := tempvector :)
739 rgb = pos + '0 1.5 0' * sbar_fontsize_y;
740 pos_y += 3 * sbar_fontsize_y;
742 for(pl = players.sort_next; pl; pl = pl.sort_next)
744 if(pl.team != COLOR_SPECTATOR)
746 //drawcolorcodedstring(pos, getplayerkey(pl.sb_player, "name"), '8 8 0', 1, 0);
747 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
748 pos += '0 1.25 0' * sbar_fontsize_y;
753 drawstring(rgb, "Spectators", sbar_fontsize, '1 1 1', 1, 0);
756 for(pl = players.sort_next; pl; pl = pl.sort_next)
758 if(pl.team == COLOR_SPECTATOR)
760 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
761 pos_y += 1.25 * sbar_fontsize_y;
762 tmp_y -= 1.25 * sbar_fontsize_y;
765 // rgb := tempvector :)
766 rgb = pos + '0 1.5 0' * sbar_fontsize_y;
767 pos_y += 3 * sbar_fontsize_y;
769 for(pl = players.sort_next; pl; pl = pl.sort_next)
771 if(pl.team != COLOR_SPECTATOR)
773 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
774 pos += '0 1.25 0' * sbar_fontsize_y;
779 drawstring(rgb, "Spectators", sbar_fontsize, '1 1 1', 1, 0);
784 void Sbar_Score(float margin)
786 float timelimit, timeleft, minutes, seconds, distribution, myplace, score;
787 vector sbar_save, place;
791 sbar_y = vid_conheight - (32+12);
802 //for(i = 0; i < 4; ++i)
803 for(tm = teams.sort_next; tm; tm = tm.sort_next)
805 if(tm.team == COLOR_SPECTATOR || !tm.team_size) // no players? don't display
808 score = tm.(teamscores[ts_primary]);
809 if(tm.team == myteam)
810 Sbar_DrawXNum('-128 0 0', score, 4, 32, GetTeamRGB(tm.team), 1, DRAWFLAG_NORMAL);
813 Sbar_DrawXNum(place, score, 4, 12, GetTeamRGB(tm.team), 1, DRAWFLAG_NORMAL);
818 // me vector := [team/connected frags id]
820 for(me = players.sort_next; me; me = me.sort_next)
822 if(me.team != COLOR_SPECTATOR)
824 if(me.sv_entnum == player_localentnum - 1)
832 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
837 Sbar_DrawXNum('-36 -12 0', myplace, 3, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
838 else if(myplace == 2)
839 Sbar_DrawXNum('-36 -12 0', myplace, 3, 12, '1 1 0', 1, DRAWFLAG_NORMAL);
841 Sbar_DrawXNum('-36 -12 0', myplace, 3, 12, '1 0 0', 1, DRAWFLAG_NORMAL);
843 score = me.(scores[ps_primary]);
844 if(distribution >= 0)
846 Sbar_DrawXNum('-84 -12 0', distribution, 4, 12, ' 1 1 1', 1, DRAWFLAG_NORMAL);
847 Sbar_DrawXNum('-128 0 0', score, 4, 32, '1 1 1', 1, DRAWFLAG_NORMAL);
848 } else if(distribution >= -5)
850 Sbar_DrawXNum('-84 -12 0', distribution, 4, 12, ' 1 1 0', 1, DRAWFLAG_NORMAL);
851 Sbar_DrawXNum('-128 0 0', score, 4, 32, '1 1 0', 1, DRAWFLAG_NORMAL);
853 Sbar_DrawXNum('-84 -12 0', distribution, 4, 12, ' 1 0 0', 1, DRAWFLAG_NORMAL);
854 Sbar_DrawXNum('-128 0 0', score, 4, 32, '1 0 0', 1, DRAWFLAG_NORMAL);
857 timelimit = getstatf(STAT_TIMELIMIT);
860 timeleft = max(0, timelimit * 60 - time);
861 minutes = floor(timeleft / 60);
862 seconds = floor(timeleft - minutes*60);
865 Sbar_DrawXNum('-72 32 0', minutes, 3, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
866 drawpic(sbar + '-36 32 0', "gfx/num_colon", '12 12 0', '1 1 1', sbar_alpha_fg, 0);
867 Sbar_DrawXNum('-24 32 0', seconds, -2, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
868 } else if(minutes >= 1)
870 Sbar_DrawXNum('-72 32 0', minutes, 3, 12, '1 1 0', 1, DRAWFLAG_NORMAL);
871 drawpic(sbar + '-36 32 0', "gfx/num_colon", '12 12 0', '1 1 0', sbar_alpha_fg, 0);
872 Sbar_DrawXNum('-24 32 0', seconds, -2, 12, '1 1 0', 1, DRAWFLAG_NORMAL);
874 Sbar_DrawXNum('-24 32 0', seconds, -2, 12, '1 0 0', 1, DRAWFLAG_NORMAL);
877 minutes = floor(time / 60);
878 seconds = floor(time - minutes*60);
879 Sbar_DrawXNum('-72 32 0', minutes, 3, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
880 drawpic(sbar + '-36 32 0', "gfx/num_colon", '12 12 0', '1 1 1', sbar_alpha_fg, 0);
881 Sbar_DrawXNum('-24 32 0', seconds, -2, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
886 void Sbar_MiniscoreItem(vector pos, entity pl, float is_self)
892 drawfill(pos + '0 1 0', '40 6 0', GetTeamRGB(pl.team)*0.5, 1, DRAWFLAG_NORMAL);
894 drawfill(pos + '0 1 0', '40 6 0', '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
897 score = pl.(scores[ps_primary]);
898 pos_x -= stringwidth(ftos(score), FALSE)*8;
899 drawstring(pos, ftos(score), '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
904 drawstring(pos, "\x0D", '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
908 drawcolorcodedstring(pos, getplayerkey(pl.sv_entnum, "name"), '8 8 0', 1, 0);
911 void Sbar_MiniscoreTeamItem(vector pos, float color, float frags, float is_self)
917 drawfill(pos + '0 1 0', '40 6 0', GetTeamRGB(color)*0.5, 1, DRAWFLAG_NORMAL);
919 drawfill(pos + '0 1 0', '40 6 0', '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
922 pos_x -= stringwidth(ftos(frags), FALSE)*8;
923 drawstring(pos, ftos(frags), '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
928 drawstring(pos, "\x0D", '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
932 drawstring(pos, GetTeamName(color), '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
935 void Sbar_MiniDeathmatchOverlay(vector pos)
937 float numlines, up, down, score;
939 float miniscoreboard_size;
940 miniscoreboard_size = cvar("sbar_miniscoreboard_size");
942 if(miniscoreboard_size == 0)
944 pos_y = vid_conheight - 8;
946 if(miniscoreboard_size < 0)
947 numlines = (vid_conheight - sbar_y + 7) / 8;
949 numlines = miniscoreboard_size;
951 // give up if there isn't enough room
952 if(pos_x >= vid_conwidth || pos_y >= vid_conheight || numlines < 1)
955 // me vector := [team/connected frags id]
956 for(me = players.sort_next; me; me = me.sort_next)
958 if(me.sv_entnum == player_localentnum - 1)
963 numlines -= numteams;
965 // figure out how many players above and below we can show
966 up = floor(numlines/2);
968 if((up + down) > numlines)
969 down = numlines - up;
972 for(pl = me.sort_next; pl && down > 0; pl = pl.sort_next)
974 if(pl.team == COLOR_SPECTATOR)
976 Sbar_MiniscoreItem(pos, pl, false);
980 Sbar_MiniscoreItem(pos, me, true);
982 up += down; // if there weren't enough lines below... add them
983 for(pl = me.sort_prev; pl && up > 0; pl = pl.sort_prev)
985 if(pl.team == COLOR_SPECTATOR)
987 Sbar_MiniscoreItem(pos, pl, false);
994 for(tm = teams.sort_next; tm.sort_next; tm = tm.sort_next);
995 for(; tm; tm = tm.sort_prev)
997 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
999 score = tm.(teamscores[ts_primary]);
1000 Sbar_MiniscoreTeamItem(pos, tm.team, score, (tm.team == me.team));
1006 void Sbar_Draw (void)
1013 Sbar_UpdatePlayerTeams();
1018 Sbar_DrawScoreboard();
1019 else if (intermission == 1)
1021 Sbar_DrawScoreboard();
1024 else if (intermission == 2)
1025 Sbar_FinaleOverlay();
1028 if (sb_showscores || (getstati(STAT_HEALTH) <= 0 && cvar("cl_deathscoreboard")))
1030 sbar_x = (vid_conwidth - 640.0)*0.5;
1031 sbar_y = vid_conheight - 47;
1032 //Sbar_DrawAlphaPic (sbar_x, sbar_y, sb_scorebar, sbar_alpha_bg.value);
1033 //drawpic('0 0 0', "gfx/scorebar", '0 0 0', '1 1 1', cvar("sbar_alpha_bg"), 0);
1034 Sbar_DrawScoreboard ();
1038 if (sb_lines && sbar_hudselector == 1)
1040 stat_items = getstati(STAT_ITEMS);
1042 sbar_x = (vid_conwidth - 320.0)*0.5;
1043 sbar_y = vid_conheight - 24.0 - 16.0;
1046 fade = 3.2 - 2 * (time - weapontime);
1047 fade = bound(0.7, fade, 1);
1050 for(i = 0; i < 8; ++i)
1054 Sbar_DrawWeapon(i+1, fade, (i + 2 == activeweapon));
1061 Sbar_DrawWeapon(0, fade, (activeweapon == 1));
1065 x = getstati(STAT_ARMOR);
1069 //Sbar_DrawStretchPic (72, 0, sb_armor[0], sbar_alpha_fg.value, 24, 24);
1070 drawpic(sbar + '72 0 0', "gfx/sb_armor", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1072 Sbar_DrawXNum('0 0 0', x, 3, 24, '0 1 0', 1, 0);
1074 Sbar_DrawXNum('0 0 0', x, 3, 24, '0.2 1 0', 1, 0);
1076 Sbar_DrawXNum('0 0 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1078 Sbar_DrawXNum('0 0 0', x, 3, 24, '1 1 0.2', 1, 0);
1080 Sbar_DrawXNum('0 0 0', x, 3, 24, '0.7 0 0', 1, 0);
1084 x = getstati(STAT_HEALTH);
1088 //Sbar_DrawStretchPic (184, 0, sb_health, sbar_alpha_fg.value, 24, 24);
1089 drawpic(sbar + '184 0 0', "gfx/sb_health", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1091 Sbar_DrawXNum('112 0 0', x, 3, 24, '0 1 0', 1, 0);
1093 Sbar_DrawXNum('112 0 0', x, 3, 24, '0.2 1 0', 1, 0);
1095 Sbar_DrawXNum('112 0 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1097 Sbar_DrawXNum('112 0 0', x, 3, 24, '1 1 0.2', 1, 0);
1099 Sbar_DrawXNum('112 0 0', x, 3, 24, '0.7 0 0', 1, 0);
1103 x = getstati(STAT_AMMO);
1104 if ((stat_items & (NEX_IT_SHELLS | NEX_IT_BULLETS | NEX_IT_ROCKETS | NEX_IT_CELLS)) || x != 0)
1106 if (stat_items & NEX_IT_SHELLS)
1107 drawpic(sbar + '296 0 0', "gfx/sb_shells", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1108 else if (stat_items & NEX_IT_BULLETS)
1109 drawpic(sbar + '296 0 0', "gfx/sb_bullets", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1110 else if (stat_items & NEX_IT_ROCKETS)
1111 drawpic(sbar + '296 0 0', "gfx/sb_rocket", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1112 else if (stat_items & NEX_IT_CELLS)
1113 drawpic(sbar + '296 0 0', "gfx/sb_cells", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1115 Sbar_DrawXNum('224 0 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1117 Sbar_DrawXNum('224 0 0', x, 3, 24, '0.7 0 0', 1, 0);
1120 if (sbar_x + 320 + 160 <= vid_conwidth)
1121 Sbar_MiniDeathmatchOverlay(sbar + '320 0 0');
1124 // The margin can be at most 8 to support 640x480 console size:
1125 // 320 + 2 * (144 + 16) = 640
1130 stat_items = getstati(STAT_ITEMS);
1132 sbar_x = (vid_conwidth - 640.0)*0.5;
1133 sbar_y = vid_conheight - 47;
1136 fade = 3 - 2 * (time - weapontime);
1139 for(i = 0; i < 8; ++i)
1143 Sbar_DrawWeapon(i+1, fade, (i + 2 == activeweapon));
1150 Sbar_DrawWeapon(0, fade, (activeweapon == 1));
1154 drawpic(sbar, "gfx/sbar", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1156 drawpic(sbar, "gfx/sbar_minimal", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1160 Sbar_DrawXNum('268 12 0', getstati(STAT_ARMOR), 3, 24, '0.6 0.7 0.8', 1, 0);
1164 x = getstati(STAT_HEALTH);
1166 Sbar_DrawXNum('82 12 0', x, 3, 24, '1 1 1', 1, 0);
1167 else if(x <= 25 && time - floor(time) > 0.5)
1168 Sbar_DrawXNum('82 12 0', x, 3, 24, '0.7 0 0', 1, 0);
1170 Sbar_DrawXNum('81 12 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1172 // AK dont draw ammo for the laser
1173 x = getstati(STAT_AMMO);
1174 if(activeweapon != 12)
1177 if (stat_items & NEX_IT_SHELLS)
1178 drawpic(sbar + '519 0 0', "gfx/sb_shells", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1179 else if (stat_items & NEX_IT_BULLETS)
1180 drawpic(sbar + '519 0 0', "gfx/sb_bullets", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1181 else if (stat_items & NEX_IT_ROCKETS)
1182 drawpic(sbar + '519 0 0', "gfx/sb_rocket", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1183 else if (stat_items & NEX_IT_CELLS)
1184 drawpic(sbar + '519 0 0', "gfx/sb_cells", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1186 Sbar_DrawXNum('447 12 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1188 Sbar_DrawXNum('447 12 0', x, 3, 24, '0.7 0 0', 1, 0);
1192 drawpic(sbar, "gfx/sbar_overlay", '0 0 0', '1 1 1', 1, DRAWFLAG_MODULATE);
1194 if (sbar_x + 600 + 160 <= vid_conwidth)
1195 Sbar_MiniDeathmatchOverlay (sbar + '600 0 0');
1200 // Mini scoreboard uses 12*4 per other team, that is, 144
1201 // pixels when there are four teams...
1202 // Nexuiz by default sets vid_conwidth to 800... makes
1204 // so we need to shift it by 64 pixels to the right to fit
1205 // BUT: then it overlaps with the image that gets drawn
1206 // for viewsize 100! Therefore, just account for 3 teams,
1207 // that is, 96 pixels mini scoreboard size, needing 16 pixels
1212 if(gametype == GAME_KEYHUNT)
1215 } else if(gametype == GAME_CTF)
1223 void CSQC_ctf_hud(void)
1225 // cvar("sbar_flagstatus_right") move the flag icons right
1226 // cvar("sbar_flagstatus_pos") pixel position of the nexuiz flagstatus icons
1227 float redflag, blueflag;
1231 stat_items = getstati(STAT_ITEMS);
1232 redflag = (stat_items/32768) & 3;
1233 blueflag = (stat_items/131072) & 3;
1237 * For some reason now not even THAT works there...
1238 * Maybe the minus' precedence screws it up? The last one there, maybe I should use brackets
1240 * pos_x = (cvar("sbar_flagstatus_right")) ? vid_conwidth - 10 - sbar_x - 64 : 10 - sbar_x;
1241 ** Should try those later:
1242 * pos_x = (cvar("sbar_flagstatus_right")) ? (vid_conwidth - 10 - sbar_x - 64) : (10 - sbar_x);
1243 * pos_x = ( (cvar("sbar_flagstatus_right")) ? vid_conwidth - 10 - 64 : 10 ) - sbar_x;
1246 if(cvar("sbar_flagstatus_right"))
1247 pos_x = vid_conwidth - 10 - sbar_x - 64;
1249 pos_x = 10 - sbar_x;
1253 if(sbar_hudselector == 1)
1254 pos_y = (vid_conheight - sbar_y) - cvar("sbar_flagstatus_pos") - 64;
1262 case 1: drawpic(pos, "gfx/sb_flag_red_taken", '0 0 0', '1 1 1', 1, DRAWFLAG_NORMAL); break;
1263 case 2: drawpic(pos, "gfx/sb_flag_red_lost", '0 0 0', '1 1 1', 1, DRAWFLAG_NORMAL); break;
1264 case 3: drawpic(pos, "gfx/sb_flag_red_carrying", '0 0 0', '1 1 1', 1, DRAWFLAG_NORMAL); break;
1271 case 1: drawpic(pos, "gfx/sb_flag_blue_taken", '0 0 0', '1 1 1', 1, 0); break;
1272 case 2: drawpic(pos, "gfx/sb_flag_blue_lost", '0 0 0', '1 1 1', 1, 0); break;
1273 case 3: drawpic(pos, "gfx/sb_flag_blue_carrying", '0 0 0', '1 1 1', 1, 0); break;