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 vl = left.teamscores[ts_primary];
242 vr = right.teamscores[ts_primary];
244 return IS_INCREASING(teamscores_flags[ts_primary]);
246 return IS_DECREASING(teamscores_flags[ts_primary]);
248 vl = left.teamscores[ts_secondary];
249 vr = right.teamscores[ts_secondary];
251 return IS_INCREASING(teamscores_flags[ts_secondary]);
253 return IS_DECREASING(teamscores_flags[ts_secondary]);
258 void Sbar_UpdateTeamPos(entity Team)
260 for(other = Team.sort_next; other && Sbar_ComparePlayerScores(Team, other); other = Team.sort_next)
262 if(other.team == COLOR_SPECTATOR)
264 SORT_SWAP(Team, other);
266 for(other = Team.sort_prev; other != teams && Sbar_ComparePlayerScores(other, Team); other = Team.sort_prev)
268 SORT_SWAP(other, Team);
272 void Cmd_Sbar_Help(float argc)
274 print("You can modify the scoreboard using the\n");
275 print("^3|---------------------------------------------------------------|\n");
276 print("^1 TO BE DONE\n");
278 print("^2sbar_columns_set default\n");
279 print("^2sbar_columns_set ^7filed1 field2 ...\n");
280 print("The following field names are recognized (case INsensitive):\n");
281 print("You can use a ^3|^7 to start the right-aligned fields.\n");
283 print("^3name^7 or ^3nick^7 Name of a player\n");
284 print("^3ping^7 Ping time\n\n");
285 print("^3kd^7 or ^3kdr^7 or ^3kdratio^7 or ^3k/d\n");
286 print(" The kill-death ratio\n");
289 print("^3caps^7 or ^3captures^7 Number of flags captured\n");
290 print("^3rets^7 or ^3returns^7 Number of flags returned\n");
291 print("^3frags^7 or ^3kills^7 Frags\n");
292 print("^3deaths^7 or ^3dths^7 Number of deaths\n");
295 print("Additional columns:\n");
296 for(i = 0; i < MAX_SCORE; ++i)
299 print(strcat(scores_label[i], "\n"));
303 #define MIN_NAMELEN 24
304 #define MAX_NAMELEN 24
306 string Sbar_DefaultColumnLayout()
308 return "ping name | +kh,ctf/caps -ctf,kh/kills -ctf,kh/deaths score";
312 case GAME_CTF: return "ping name | caps score";
313 case GAME_KEYHUNT: return "ping name | caps kills score";
314 default: return "ping name | score";
315 // TODO: add other gametypes
320 void Cmd_Sbar_SetFields(float argc)
323 string str, pattern, subpattern;
326 // TODO: re enable with gametype dependant cvars?
327 if(argc < 2) // no arguments provided
328 argc = tokenizebyseparator(strcat("x ", cvar_string("sbar_columns")), " ");
330 if(argc < 2 || (argc == 2 && argv(1) == "default"))
331 argc = tokenizebyseparator(strcat("x ", Sbar_DefaultColumnLayout()), " ");
333 argc = min(MAX_SBAR_FIELDS, argc);
336 drawfont = sbar_font;
337 digit = stringwidth("0123456789", FALSE) / 10;
339 subpattern = strcat(",", GametypeNameFromType(gametype), ",");
341 argc = min(argc-1, MAX_SBAR_FIELDS-1);
342 for(i = 0; i < argc; ++i)
346 slash = strstrofs(str, "/", 0);
349 pattern = substring(str, 0, slash);
350 str = substring(str, slash + 1, strlen(str) - (slash + 1));
352 if(substring(pattern, 0, 1) == "-")
354 pattern = substring(pattern, 1, strlen(pattern) - 1);
355 if(strstrofs(strcat(",", pattern, ","), subpattern, 0) >= 0)
360 if(substring(pattern, 0, 1) == "+")
361 pattern = substring(pattern, 1, strlen(pattern) - 1);
362 if(strstrofs(strcat(",", pattern, ","), subpattern, 0) < 0)
367 strunzone(sbar_title[sbar_num_fields]);
368 sbar_title[sbar_num_fields] = strzone(str);
369 sbar_size[sbar_num_fields] = stringwidth(str, FALSE);
370 str = strtolower(str);
373 sbar_field[sbar_num_fields] = SP_PING;
374 } else if(str == "name" || str == "nick") {
375 sbar_field[sbar_num_fields] = SP_NAME;
376 sbar_size[sbar_num_fields] = MIN_NAMELEN; // minimum size? any use?
377 } else if(str == "|") {
378 sbar_field[sbar_num_fields] = SP_SEPARATOR;
380 for(j = 0; j < MAX_SCORE; ++j)
381 if(str == strtolower(scores_label[j]))
382 goto found; // sorry, but otherwise fteqcc -O3 miscompiles this and warns about "unreachable code"
384 print(strcat("^1Error:^7 Unknown score field: '", str, "'\n"));
387 sbar_field[sbar_num_fields] = j;
391 sbar_field[sbar_num_fields] = SP_END;
395 vector sbar_field_rgb;
396 string Sbar_GetField(entity pl, float field)
398 float tmp, num, denom, f;
400 sbar_field_rgb = '1 1 1';
404 str = bufstr_get(databuf, DATABUF_PING + pl.sv_entnum);
405 tmp = max(0, min(220, stof(str)-80)) / 220;
406 sbar_field_rgb = '1 1 1' - '0 1 1'*tmp;
410 return getplayerkey(pl.sv_entnum, "name");
413 num = pl.(scores[SP_KILLS]);
414 denom = pl.(scores[SP_DEATHS]);
417 sbar_field_rgb = '0 1 0';
419 } else if(num <= 0) {
420 sbar_field_rgb = '1 0 0';
421 str = ftos(num/denom);
423 str = ftos(num/denom);
425 tmp = strstrofs(str, ".", 0);
427 str = substring(str, 0, tmp+2);
431 tmp = pl.(scores[field]);
432 f = scores_flags[field];
433 if(field == ps_primary)
434 sbar_field_rgb = '1 1 0';
435 else if(field == ps_secondary)
436 sbar_field_rgb = '1 0 1';
438 sbar_field_rgb = '1 1 1';
440 if(f & SFL_HIDE_ZERO)
447 // shamelessly stolen from menu QC :P <- as if I would steal YOUR code pfft ;)
448 float textLengthUpToWidth(string theText, float maxWidth, float handleColors)
451 // The following function is SLOW.
452 // For your safety and for the protection of those around you...
453 // DO NOT CALL THIS AT HOME.
455 if(stringwidth(theText, handleColors) <= maxWidth)
456 return strlen(theText); // yeah!
458 // binary search for right place to cut string
459 float left, right, middle; // this always works
461 right = strlen(theText); // this always fails
464 middle = floor((left + right) / 2);
465 if(stringwidth(substring(theText, 0, middle), handleColors) <= maxWidth)
470 while(left < right - 1);
472 // NOTE: when color codes are involved, this binary search is,
473 // mathematically, BROKEN. However, it is obviously guaranteed to
474 // terminate, as the range still halves each time - but nevertheless, it is
475 // guaranteed that it finds ONE valid cutoff place (where "left" is in
476 // range, and "right" is outside).
480 string textShortenToWidth(string theText, float maxWidth, float handleColors)
482 if(stringwidth(theText, handleColors) <= maxWidth)
485 return strcat(substring(theText, 0, textLengthUpToWidth(theText, maxWidth - stringwidth("...", handleColors), handleColors)), "...");
488 float xmin, xmax, ymin, ymax, sbwidth, sbheight;
490 void Sbar_PrintScoreboardItem(vector pos, entity pl, float is_self)
496 is_spec = (GetPlayerColor(pl.sv_entnum) == COLOR_SPECTATOR);
503 tmp_y = sbar_fontsize_y;
504 drawfill(pos - '1 1 0', tmp + '2 2 0', '1 1 1', 0.3, DRAWFLAG_NORMAL);
508 for(i = 0; i < sbar_num_fields; ++i)
510 field = sbar_field[i];
511 if(field == SP_SEPARATOR)
514 if(is_spec && field != SP_NAME && field != SP_PING) {
515 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
518 str = Sbar_GetField(pl, field);
524 realsize = sbar_size[i];
525 if(i+1 < sbar_num_fields)
526 if(sbar_field[i+1] == SP_SEPARATOR)
528 realsize = (xmax - xmin) / sbar_fontsize_x;
529 for(j = 0; j < sbar_num_fields; ++j) if(j != i) if(sbar_field[j] != SP_SEPARATOR)
530 realsize -= sbar_size[j] + 1;
533 str = textShortenToWidth(str, realsize, TRUE);
535 len = stringwidth(str, TRUE);
537 if(sbar_size[i] < len)
540 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
542 if(field == SP_NAME) {
543 tmp_x = sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
544 drawcolorcodedstring(pos - tmp, str, sbar_fontsize, 1, DRAWFLAG_NORMAL);
546 tmp_x = len*sbar_fontsize_x + sbar_fontsize_x;
547 drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, 1, DRAWFLAG_NORMAL);
551 if(sbar_field[i] == SP_SEPARATOR)
554 for(i = sbar_num_fields-1; i > 0; --i)
556 field = sbar_field[i];
557 if(field == SP_SEPARATOR)
560 if(is_spec && field != SP_NAME && field != SP_PING) {
561 pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
565 str = Sbar_GetField(pl, field);
568 str = textShortenToWidth(str, sbar_size[i], TRUE);
569 len = stringwidth(str, TRUE);
571 if(sbar_size[i] < len)
574 if(field == SP_NAME) {
575 tmp_x = sbar_fontsize_x*len; // left or right aligned? let's put it right...
576 drawcolorcodedstring(pos - tmp, str, sbar_fontsize, 1, DRAWFLAG_NORMAL);
578 tmp_x = sbar_fontsize_x*len; //strlen(str);
579 drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, 1, DRAWFLAG_NORMAL);
581 pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
586 void Sbar_DrawScoreboard()
588 //float xmin, ymin, xmax, ymax;
589 vector rgb, pos, tmp, sbar_save;
594 sbar_fontsize = Sbar_GetFontsize();
595 if(sbar_fontsize_x == 0)
596 sbar_fontsize = '8 8 0';
597 if(sbar_fontsize_y == 0)
598 sbar_fontsize_y = sbar_fontsize_x;
600 xmin = vid_conwidth / 5;
603 xmax = vid_conwidth - xmin;
604 ymax = vid_conheight - 0.2*vid_conheight;
606 sbwidth = xmax - xmin;
607 sbheight = ymax - ymin;
609 center_x = xmin + 0.5*sbwidth;
611 //Sbar_UpdateFields();
613 // Initializes position
619 drawfont = sbar_font;
620 pos_x = center_x - stringwidth("Scoreboard", TRUE)*0.5*24;
621 drawstring(pos, "Scoreboard", '24 24 0', '1 1 1', 1, DRAWFLAG_NORMAL);
625 // Titlebar background:
627 tmp_y = sbar_fontsize_y;
628 drawfill(pos - '1 1 0', tmp + '2 2 0', '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
630 for(i = 0; i < sbar_num_fields; ++i)
632 if(sbar_field[i] == SP_SEPARATOR)
634 drawstring(pos, sbar_title[i], sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
635 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
638 if(sbar_field[i] == SP_SEPARATOR)
640 pos_x = xmax + sbar_fontsize_x;
642 for(i = sbar_num_fields-1; i > 0; --i)
644 if(sbar_field[i] == SP_SEPARATOR)
647 pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
650 * Using the following line will fuck it all up:
652 * tmp_x = sbar_size[i] - strlen(sbar_title[i])*8;
654 tmp_x = sbar_fontsize_x*sbar_size[i];
655 tmp_x -= stringwidth(sbar_title[i], FALSE)*sbar_fontsize_x;
656 drawstring(pos + tmp, sbar_title[i], sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
661 pos_y += 1.5 * sbar_fontsize_y;
668 //for(tm = sortedTeams.sort_next; tm; tm = tm.sort_next)
669 for(tm = teams.sort_next; tm; tm = tm.sort_next)
671 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
674 rgb = GetTeamRGB(tm.team);
677 // TODO: Print primary and secondary scores!
681 specs = tm.team_size;
687 tmp_y = 1.25 * sbar_fontsize_y * specs;
688 drawfill(pos - '1 1 0', tmp + '2 0 0', rgb, 0.2, DRAWFLAG_NORMAL);
690 for(pl = players.sort_next; pl; pl = pl.sort_next)
692 if(pl.team != tm.team)
694 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
695 pos_y += 1.25 * sbar_fontsize_y;
696 tmp_y -= 1.25 * sbar_fontsize_y;
698 pos_y += tmp_y + 1.5 * sbar_fontsize_y;
700 // rgb := tempvector :)
701 rgb = pos + '0 1.5 0' * sbar_fontsize_y;
702 pos_y += 3 * sbar_fontsize_y;
704 for(pl = players.sort_next; pl; pl = pl.sort_next)
706 if(pl.team != COLOR_SPECTATOR)
708 //drawcolorcodedstring(pos, getplayerkey(pl.sb_player, "name"), '8 8 0', 1, 0);
709 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
710 pos += '0 1.25 0' * sbar_fontsize_y;
715 drawstring(rgb, "Spectators", sbar_fontsize, '1 1 1', 1, 0);
718 for(pl = players.sort_next; pl; pl = pl.sort_next)
720 if(pl.team == COLOR_SPECTATOR)
722 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
723 pos_y += 1.25 * sbar_fontsize_y;
724 tmp_y -= 1.25 * sbar_fontsize_y;
727 // rgb := tempvector :)
728 rgb = pos + '0 1.5 0' * sbar_fontsize_y;
729 pos_y += 3 * sbar_fontsize_y;
731 for(pl = players.sort_next; pl; pl = pl.sort_next)
733 if(pl.team != COLOR_SPECTATOR)
735 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
736 pos += '0 1.25 0' * sbar_fontsize_y;
741 drawstring(rgb, "Spectators", sbar_fontsize, '1 1 1', 1, 0);
746 void Sbar_Score(float margin)
748 float timelimit, timeleft, minutes, seconds, distribution, myplace, score;
749 vector sbar_save, place;
753 sbar_y = vid_conheight - (32+12);
764 //for(i = 0; i < 4; ++i)
765 for(tm = teams.sort_next; tm; tm = tm.sort_next)
767 if(tm.team == COLOR_SPECTATOR || !tm.team_size) // no players? don't display
770 score = tm.(teamscores[ts_primary]);
771 if(tm.team == myteam)
772 Sbar_DrawXNum('-128 0 0', score, 4, 32, GetTeamRGB(tm.team), 1, DRAWFLAG_NORMAL);
775 Sbar_DrawXNum(place, score, 4, 12, GetTeamRGB(tm.team), 1, DRAWFLAG_NORMAL);
780 // me vector := [team/connected frags id]
782 for(me = players.sort_next; me; me = me.sort_next)
784 if(me.team != COLOR_SPECTATOR)
786 if(me.sv_entnum == player_localentnum - 1)
794 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
799 Sbar_DrawXNum('-36 -12 0', myplace, 3, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
800 else if(myplace == 2)
801 Sbar_DrawXNum('-36 -12 0', myplace, 3, 12, '1 1 0', 1, DRAWFLAG_NORMAL);
803 Sbar_DrawXNum('-36 -12 0', myplace, 3, 12, '1 0 0', 1, DRAWFLAG_NORMAL);
805 score = me.(scores[ps_primary]);
806 if(distribution >= 0)
808 Sbar_DrawXNum('-84 -12 0', distribution, 4, 12, ' 1 1 1', 1, DRAWFLAG_NORMAL);
809 Sbar_DrawXNum('-128 0 0', score, 4, 32, '1 1 1', 1, DRAWFLAG_NORMAL);
810 } else if(distribution >= -5)
812 Sbar_DrawXNum('-84 -12 0', distribution, 4, 12, ' 1 1 0', 1, DRAWFLAG_NORMAL);
813 Sbar_DrawXNum('-128 0 0', score, 4, 32, '1 1 0', 1, DRAWFLAG_NORMAL);
815 Sbar_DrawXNum('-84 -12 0', distribution, 4, 12, ' 1 0 0', 1, DRAWFLAG_NORMAL);
816 Sbar_DrawXNum('-128 0 0', score, 4, 32, '1 0 0', 1, DRAWFLAG_NORMAL);
819 timelimit = getstatf(STAT_TIMELIMIT);
822 timeleft = max(0, timelimit * 60 - time);
823 minutes = floor(timeleft / 60);
824 seconds = floor(timeleft - minutes*60);
827 Sbar_DrawXNum('-72 32 0', minutes, 3, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
828 drawpic(sbar + '-36 32 0', "gfx/num_colon", '12 12 0', '1 1 1', sbar_alpha_fg, 0);
829 Sbar_DrawXNum('-24 32 0', seconds, -2, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
830 } else if(minutes >= 1)
832 Sbar_DrawXNum('-72 32 0', minutes, 3, 12, '1 1 0', 1, DRAWFLAG_NORMAL);
833 drawpic(sbar + '-36 32 0', "gfx/num_colon", '12 12 0', '1 1 0', sbar_alpha_fg, 0);
834 Sbar_DrawXNum('-24 32 0', seconds, -2, 12, '1 1 0', 1, DRAWFLAG_NORMAL);
836 Sbar_DrawXNum('-24 32 0', seconds, -2, 12, '1 0 0', 1, DRAWFLAG_NORMAL);
839 minutes = floor(time / 60);
840 seconds = floor(time - minutes*60);
841 Sbar_DrawXNum('-72 32 0', minutes, 3, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
842 drawpic(sbar + '-36 32 0', "gfx/num_colon", '12 12 0', '1 1 1', sbar_alpha_fg, 0);
843 Sbar_DrawXNum('-24 32 0', seconds, -2, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
848 void Sbar_MiniscoreItem(vector pos, entity pl, float is_self)
854 drawfill(pos + '0 1 0', '40 6 0', GetTeamRGB(pl.team)*0.5, 1, DRAWFLAG_NORMAL);
856 drawfill(pos + '0 1 0', '40 6 0', '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
859 score = pl.(scores[ps_primary]);
860 pos_x -= stringwidth(ftos(score), FALSE)*8;
861 drawstring(pos, ftos(score), '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
866 drawstring(pos, "\x0D", '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
870 drawcolorcodedstring(pos, getplayerkey(pl.sv_entnum, "name"), '8 8 0', 1, 0);
873 void Sbar_MiniscoreTeamItem(vector pos, float color, float frags, float is_self)
879 drawfill(pos + '0 1 0', '40 6 0', GetTeamRGB(color)*0.5, 1, DRAWFLAG_NORMAL);
881 drawfill(pos + '0 1 0', '40 6 0', '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
884 pos_x -= stringwidth(ftos(frags), FALSE)*8;
885 drawstring(pos, ftos(frags), '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
890 drawstring(pos, "\x0D", '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
894 drawstring(pos, GetTeamName(color), '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
897 void Sbar_MiniDeathmatchOverlay(vector pos)
899 float numlines, up, down, score;
901 float miniscoreboard_size;
902 miniscoreboard_size = cvar("sbar_miniscoreboard_size");
904 if(miniscoreboard_size == 0)
906 pos_y = vid_conheight - 8;
908 if(miniscoreboard_size < 0)
909 numlines = (vid_conheight - sbar_y + 7) / 8;
911 numlines = miniscoreboard_size;
913 // give up if there isn't enough room
914 if(pos_x >= vid_conwidth || pos_y >= vid_conheight || numlines < 1)
917 // me vector := [team/connected frags id]
918 for(me = players.sort_next; me; me = me.sort_next)
920 if(me.sv_entnum == player_localentnum - 1)
925 numlines -= numteams;
927 // figure out how many players above and below we can show
928 up = floor(numlines/2);
930 if((up + down) > numlines)
931 down = numlines - up;
934 for(pl = me.sort_next; pl && down > 0; pl = pl.sort_next)
936 if(pl.team == COLOR_SPECTATOR)
938 Sbar_MiniscoreItem(pos, pl, false);
942 Sbar_MiniscoreItem(pos, me, true);
944 up += down; // if there weren't enough lines below... add them
945 for(pl = me.sort_prev; pl && up > 0; pl = pl.sort_prev)
947 if(pl.team == COLOR_SPECTATOR)
949 Sbar_MiniscoreItem(pos, pl, false);
956 for(tm = teams.sort_next; tm.sort_next; tm = tm.sort_next);
957 for(; tm; tm = tm.sort_prev)
959 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
961 score = tm.(teamscores[ts_primary]);
962 Sbar_MiniscoreTeamItem(pos, tm.team, score, (tm.team == me.team));
968 void Sbar_Draw (void)
975 Sbar_UpdatePlayerTeams();
980 Sbar_DrawScoreboard();
981 else if (intermission == 1)
983 Sbar_DrawScoreboard();
986 else if (intermission == 2)
987 Sbar_FinaleOverlay();
990 if (sb_showscores || (getstati(STAT_HEALTH) <= 0 && cvar("cl_deathscoreboard")))
992 sbar_x = (vid_conwidth - 640.0)*0.5;
993 sbar_y = vid_conheight - 47;
994 //Sbar_DrawAlphaPic (sbar_x, sbar_y, sb_scorebar, sbar_alpha_bg.value);
995 //drawpic('0 0 0', "gfx/scorebar", '0 0 0', '1 1 1', cvar("sbar_alpha_bg"), 0);
996 Sbar_DrawScoreboard ();
1000 if (sb_lines && sbar_hudselector == 1)
1002 stat_items = getstati(STAT_ITEMS);
1004 sbar_x = (vid_conwidth - 320.0)*0.5;
1005 sbar_y = vid_conheight - 24.0 - 16.0;
1008 fade = 3.2 - 2 * (time - weapontime);
1009 fade = bound(0.7, fade, 1);
1012 for(i = 0; i < 8; ++i)
1016 Sbar_DrawWeapon(i+1, fade, (i + 2 == activeweapon));
1023 Sbar_DrawWeapon(0, fade, (activeweapon == 1));
1027 x = getstati(STAT_ARMOR);
1031 //Sbar_DrawStretchPic (72, 0, sb_armor[0], sbar_alpha_fg.value, 24, 24);
1032 drawpic(sbar + '72 0 0', "gfx/sb_armor", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1034 Sbar_DrawXNum('0 0 0', x, 3, 24, '0 1 0', 1, 0);
1036 Sbar_DrawXNum('0 0 0', x, 3, 24, '0.2 1 0', 1, 0);
1038 Sbar_DrawXNum('0 0 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1040 Sbar_DrawXNum('0 0 0', x, 3, 24, '1 1 0.2', 1, 0);
1042 Sbar_DrawXNum('0 0 0', x, 3, 24, '0.7 0 0', 1, 0);
1046 x = getstati(STAT_HEALTH);
1050 //Sbar_DrawStretchPic (184, 0, sb_health, sbar_alpha_fg.value, 24, 24);
1051 drawpic(sbar + '184 0 0', "gfx/sb_health", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1053 Sbar_DrawXNum('112 0 0', x, 3, 24, '0 1 0', 1, 0);
1055 Sbar_DrawXNum('112 0 0', x, 3, 24, '0.2 1 0', 1, 0);
1057 Sbar_DrawXNum('112 0 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1059 Sbar_DrawXNum('112 0 0', x, 3, 24, '1 1 0.2', 1, 0);
1061 Sbar_DrawXNum('112 0 0', x, 3, 24, '0.7 0 0', 1, 0);
1065 x = getstati(STAT_AMMO);
1066 if ((stat_items & (NEX_IT_SHELLS | NEX_IT_BULLETS | NEX_IT_ROCKETS | NEX_IT_CELLS)) || x != 0)
1068 if (stat_items & NEX_IT_SHELLS)
1069 drawpic(sbar + '296 0 0', "gfx/sb_shells", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1070 else if (stat_items & NEX_IT_BULLETS)
1071 drawpic(sbar + '296 0 0', "gfx/sb_bullets", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1072 else if (stat_items & NEX_IT_ROCKETS)
1073 drawpic(sbar + '296 0 0', "gfx/sb_rocket", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1074 else if (stat_items & NEX_IT_CELLS)
1075 drawpic(sbar + '296 0 0', "gfx/sb_cells", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1077 Sbar_DrawXNum('224 0 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1079 Sbar_DrawXNum('224 0 0', x, 3, 24, '0.7 0 0', 1, 0);
1082 if (sbar_x + 320 + 160 <= vid_conwidth)
1083 Sbar_MiniDeathmatchOverlay(sbar + '320 0 0');
1086 // The margin can be at most 8 to support 640x480 console size:
1087 // 320 + 2 * (144 + 16) = 640
1092 stat_items = getstati(STAT_ITEMS);
1094 sbar_x = (vid_conwidth - 640.0)*0.5;
1095 sbar_y = vid_conheight - 47;
1098 fade = 3 - 2 * (time - weapontime);
1101 for(i = 0; i < 8; ++i)
1105 Sbar_DrawWeapon(i+1, fade, (i + 2 == activeweapon));
1112 Sbar_DrawWeapon(0, fade, (activeweapon == 1));
1116 drawpic(sbar, "gfx/sbar", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1118 drawpic(sbar, "gfx/sbar_minimal", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1122 Sbar_DrawXNum('268 12 0', getstati(STAT_ARMOR), 3, 24, '0.6 0.7 0.8', 1, 0);
1126 x = getstati(STAT_HEALTH);
1128 Sbar_DrawXNum('82 12 0', x, 3, 24, '1 1 1', 1, 0);
1129 else if(x <= 25 && time - floor(time) > 0.5)
1130 Sbar_DrawXNum('82 12 0', x, 3, 24, '0.7 0 0', 1, 0);
1132 Sbar_DrawXNum('81 12 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1134 // AK dont draw ammo for the laser
1135 x = getstati(STAT_AMMO);
1136 if(activeweapon != 12)
1139 if (stat_items & NEX_IT_SHELLS)
1140 drawpic(sbar + '519 0 0', "gfx/sb_shells", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1141 else if (stat_items & NEX_IT_BULLETS)
1142 drawpic(sbar + '519 0 0', "gfx/sb_bullets", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1143 else if (stat_items & NEX_IT_ROCKETS)
1144 drawpic(sbar + '519 0 0', "gfx/sb_rocket", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1145 else if (stat_items & NEX_IT_CELLS)
1146 drawpic(sbar + '519 0 0', "gfx/sb_cells", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1148 Sbar_DrawXNum('447 12 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1150 Sbar_DrawXNum('447 12 0', x, 3, 24, '0.7 0 0', 1, 0);
1154 drawpic(sbar, "gfx/sbar_overlay", '0 0 0', '1 1 1', 1, DRAWFLAG_MODULATE);
1156 if (sbar_x + 600 + 160 <= vid_conwidth)
1157 Sbar_MiniDeathmatchOverlay (sbar + '600 0 0');
1162 // Mini scoreboard uses 12*4 per other team, that is, 144
1163 // pixels when there are four teams...
1164 // Nexuiz by default sets vid_conwidth to 800... makes
1166 // so we need to shift it by 64 pixels to the right to fit
1167 // BUT: then it overlaps with the image that gets drawn
1168 // for viewsize 100! Therefore, just account for 3 teams,
1169 // that is, 96 pixels mini scoreboard size, needing 16 pixels
1174 if(gametype == GAME_KEYHUNT)
1177 } else if(gametype == GAME_CTF)
1185 void CSQC_ctf_hud(void)
1187 // cvar("sbar_flagstatus_right") move the flag icons right
1188 // cvar("sbar_flagstatus_pos") pixel position of the nexuiz flagstatus icons
1189 float redflag, blueflag;
1193 stat_items = getstati(STAT_ITEMS);
1194 redflag = (stat_items/32768) & 3;
1195 blueflag = (stat_items/131072) & 3;
1199 * For some reason now not even THAT works there...
1200 * Maybe the minus' precedence screws it up? The last one there, maybe I should use brackets
1202 * pos_x = (cvar("sbar_flagstatus_right")) ? vid_conwidth - 10 - sbar_x - 64 : 10 - sbar_x;
1203 ** Should try those later:
1204 * pos_x = (cvar("sbar_flagstatus_right")) ? (vid_conwidth - 10 - sbar_x - 64) : (10 - sbar_x);
1205 * pos_x = ( (cvar("sbar_flagstatus_right")) ? vid_conwidth - 10 - 64 : 10 ) - sbar_x;
1208 if(cvar("sbar_flagstatus_right"))
1209 pos_x = vid_conwidth - 10 - sbar_x - 64;
1211 pos_x = 10 - sbar_x;
1215 if(sbar_hudselector == 1)
1216 pos_y = (vid_conheight - sbar_y) - cvar("sbar_flagstatus_pos") - 64;
1224 case 1: drawpic(pos, "gfx/sb_flag_red_taken", '0 0 0', '1 1 1', 1, DRAWFLAG_NORMAL); break;
1225 case 2: drawpic(pos, "gfx/sb_flag_red_lost", '0 0 0', '1 1 1', 1, DRAWFLAG_NORMAL); break;
1226 case 3: drawpic(pos, "gfx/sb_flag_red_carrying", '0 0 0', '1 1 1', 1, DRAWFLAG_NORMAL); break;
1233 case 1: drawpic(pos, "gfx/sb_flag_blue_taken", '0 0 0', '1 1 1', 1, 0); break;
1234 case 2: drawpic(pos, "gfx/sb_flag_blue_lost", '0 0 0', '1 1 1', 1, 0); break;
1235 case 3: drawpic(pos, "gfx/sb_flag_blue_carrying", '0 0 0', '1 1 1', 1, 0); break;