4 float sb_highlight_alpha;
5 float sb_highlight_alpha_self;
7 float sb_alpha_name_self;
9 void drawstringright(vector, string, vector, vector, float, float);
10 void drawstringcenter(vector, string, vector, vector, float, float);
12 float SCOREBOARD_OFFSET = 50;
15 void Sbar_FinaleOverlay()
18 pos_x = (vid_conwidth - 1)/2;
22 //drawpic(pos, "gfx/finale", '0 0 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
24 //drawstring(pos, "END", sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
28 void Sbar_DrawXNum (vector pos, float num, float digits, float showminusplus, float lettersize, vector rgb, float highlighted, float stroke, float alpha, float dflags)
31 string str, tmp, l_length;
33 vector vsize, num_color;
35 vsize_x = vsize_y = lettersize;
38 // showminusplus 1: always prefix with minus sign (useful in race distribution display)
39 // showminusplus 2: always prefix with plus sign (useful in race distribution display)
40 // showminusplus 3: prefix with minus sign if negative, plus sign if positive (useful in score distribution display)
42 if((showminusplus == 2 && num >= 0) || (num > 0 && showminusplus == 3))
49 if(num < 0 || (num < 0 && showminusplus == 3) || (showminusplus == 1 && num <= 0))
61 str = strcat(substring("0000000000", 0, digits - strlen(tmp)), tmp);
70 str = substring(str, l-digits, 999);
73 pos_x += (digits-l) * lettersize;
75 if (highlighted == 1) {
77 hl_size_x = vsize_x * l + vsize_x * 0.2;
78 hl_size_y = vsize_y * 1.1;
81 hl_size_x = hl_size_x + vsize_x;
84 hl_pos_x = pos_x - lettersize/10;
85 hl_pos_y = pos_y - lettersize/20;
88 drawpic(hl_pos, strcat("gfx/hud/sb_highlight_", l_length), hl_size, '1 1 1', alpha, dflags);
99 drawpic(pos, "gfx/hud/num_minus_stroke", vsize, rgb, alpha, dflags);
100 drawpic(pos, "gfx/hud/num_minus", vsize, num_color, alpha, dflags);
105 drawpic(pos, "gfx/hud/num_plus_stroke", vsize, rgb, alpha, dflags);
106 drawpic(pos, "gfx/hud/num_plus", vsize, num_color, alpha, dflags);
110 for(i = 0; i < l; ++i)
112 tmp = substring(str, i, 1);
114 drawpic(pos, strcat("gfx/hud/num_", tmp, "_stroke"), vsize, rgb, alpha, dflags);
115 drawpic(pos, strcat("gfx/hud/num_", tmp), vsize, num_color, alpha, dflags);
120 void Cmd_Sbar_SetFields(float argc);
121 void Sbar_InitScores()
125 ps_primary = ps_secondary = ts_primary = ts_secondary = -1;
126 for(i = 0; i < MAX_SCORE; ++i)
128 f = (scores_flags[i] & SFL_SORT_PRIO_MASK);
129 if(f == SFL_SORT_PRIO_PRIMARY)
131 if(f == SFL_SORT_PRIO_SECONDARY)
134 if(ps_secondary == -1)
135 ps_secondary = ps_primary;
137 for(i = 0; i < MAX_TEAMSCORE; ++i)
139 f = (teamscores_flags[i] & SFL_SORT_PRIO_MASK);
140 if(f == SFL_SORT_PRIO_PRIMARY)
142 if(f == SFL_SORT_PRIO_SECONDARY)
145 if(ts_secondary == -1)
146 ts_secondary = ts_primary;
148 Cmd_Sbar_SetFields(0);
151 void Sbar_UpdatePlayerPos(entity pl);
152 float SetTeam(entity pl, float Team);
154 void Sbar_UpdatePlayerTeams()
161 for(pl = players.sort_next; pl; pl = pl.sort_next)
164 Team = GetPlayerColor(pl.sv_entnum);
165 if(SetTeam(pl, Team))
168 Sbar_UpdatePlayerPos(pl);
172 pl = players.sort_next;
177 print(strcat("PNUM: ", ftos(num), "\n"));
182 float Sbar_ComparePlayerScores(entity left, entity right)
185 vl = GetPlayerColor(left.sv_entnum);
186 vr = GetPlayerColor(right.sv_entnum);
189 vl = COLOR_SPECTATOR;
191 vr = COLOR_SPECTATOR;
198 if(vl == COLOR_SPECTATOR)
200 // FIRST the one with scores (spectators), THEN the ones without (downloaders)
202 if(!left.gotscores && right.gotscores)
207 vl = left.scores[ps_primary];
208 vr = right.scores[ps_primary];
209 if(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)
211 if(vl == 0 && vr != 0)
213 if(vl != 0 && vr == 0)
217 return IS_INCREASING(scores_flags[ps_primary]);
219 return IS_DECREASING(scores_flags[ps_primary]);
221 vl = left.scores[ps_secondary];
222 vr = right.scores[ps_secondary];
223 if(scores_flags[ps_secondary] & SFL_ZERO_IS_WORST)
225 if(vl == 0 && vr != 0)
227 if(vl != 0 && vr == 0)
231 return IS_INCREASING(scores_flags[ps_secondary]);
233 return IS_DECREASING(scores_flags[ps_secondary]);
238 void Sbar_UpdatePlayerPos(entity player)
240 for(other = player.sort_next; other && Sbar_ComparePlayerScores(player, other); other = player.sort_next)
242 SORT_SWAP(player, other);
244 for(other = player.sort_prev; other != players && Sbar_ComparePlayerScores(other, player); other = player.sort_prev)
246 SORT_SWAP(other, player);
250 float Sbar_CompareTeamScores(entity left, entity right)
254 if(left.team == COLOR_SPECTATOR)
256 if(right.team == COLOR_SPECTATOR)
259 vl = left.teamscores[ts_primary];
260 vr = right.teamscores[ts_primary];
262 return IS_INCREASING(teamscores_flags[ts_primary]);
264 return IS_DECREASING(teamscores_flags[ts_primary]);
266 vl = left.teamscores[ts_secondary];
267 vr = right.teamscores[ts_secondary];
269 return IS_INCREASING(teamscores_flags[ts_secondary]);
271 return IS_DECREASING(teamscores_flags[ts_secondary]);
276 void Sbar_UpdateTeamPos(entity Team)
278 for(other = Team.sort_next; other && Sbar_CompareTeamScores(Team, other); other = Team.sort_next)
280 SORT_SWAP(Team, other);
282 for(other = Team.sort_prev; other != teams && Sbar_CompareTeamScores(other, Team); other = Team.sort_prev)
284 SORT_SWAP(other, Team);
288 void Cmd_Sbar_Help(float argc)
290 print("You can modify the scoreboard using the ^2sbar_columns_set command.\n");
291 print("^3|---------------------------------------------------------------|\n");
293 print("^2sbar_columns_set default\n");
294 print("^2sbar_columns_set ^7filed1 field2 ...\n");
295 print("The following field names are recognized (case insensitive):\n");
296 print("You can use a ^3|^7 to start the right-aligned fields.\n\n");
298 print("^3name^7 or ^3nick^7 Name of a player\n");
299 print("^3ping^7 Ping time\n");
300 print("^3pl^7 Packet loss\n");
301 print("^3kills^7 Number of kills\n");
302 print("^3deaths^7 Number of deaths\n");
303 print("^3suicides^7 Number of suicides\n");
304 print("^3frags^7 kills - suicides\n");
305 print("^3kd^7 The kill-death ratio\n");
306 print("^3caps^7 How often a flag (CTF) or a key (KeyHunt) was captured\n");
307 print("^3pickups^7 How often a flag (CTF) or a key (KeyHunt) was picked up\n");
308 print("^3fckills^7 Number of flag carrier kills\n");
309 print("^3returns^7 Number of flag returns\n");
310 print("^3drops^7 Number of flag drops\n");
311 print("^3lives^7 Number of lives (LMS)\n");
312 print("^3rank^7 Player rank\n");
313 print("^3pushes^7 Number of players pushed into void\n");
314 print("^3destroyed^7 Number of keys destroyed by pushing them into void\n");
315 print("^3kckills^7 Number of keys carrier kills\n");
316 print("^3losses^7 Number of times a key was lost\n");
317 print("^3laps^7 Number of laps finished (race/cts)\n");
318 print("^3time^7 Total time raced (race/cts)\n");
319 print("^3fastest^7 Time of fastest lap (race/cts)\n");
320 print("^3ticks^7 Number of ticks (DOM)\n");
321 print("^3takes^7 Number of domination points taken (DOM)\n");
322 print("^3score^7 Total score\n\n");
324 print("Before a field you can put a + or - sign, then a comma separated list\n");
325 print("of game types, then a slash, to make the field show up only in these\n");
326 print("or in all but these game types. You can also specify 'all' as a\n");
327 print("field to show all fields available for the current game mode.\n\n");
329 print("The special game type names 'teams' and 'noteams' can be used to\n");
330 print("include/exclude ALL teams/noteams game modes.\n\n");
332 print("Example: sbar_columns_set name ping pl | +ctf/field3 -dm/field4\n");
333 print("will display name, ping and pl aligned to the left, and the fields\n");
334 print("right of the vertical bar aligned to the right.\n");
335 print("'field3' will only be shown in CTF, and 'field4' will be shown in all\n");
336 print("other gamemodes except DM.\n");
339 string Sbar_DefaultColumnLayout()
341 return strcat( // fteqcc sucks
343 "-teams,race,lms/kills -teams,lms/deaths -teams,lms,race/suicides -race,dm,tdm/frags ", // tdm already has this in "score"
344 "+ctf/caps +ctf/pickups +ctf/fckills +ctf/returns ",
345 "+lms/lives +lms/rank ",
346 "+kh/caps +kh/pushes +kh/destroyed ",
347 "?+race/laps ?+race/time ?+race/fastest ",
348 "+as/objectives +nexball/faults +nexball/goals ",
349 "-lms,race,nexball/score");
352 void Cmd_Sbar_SetFields(float argc)
356 float have_name, have_primary, have_secondary, have_separator;
359 // TODO: re enable with gametype dependant cvars?
360 if(argc < 2) // no arguments provided
361 argc = tokenizebyseparator(strcat("x ", cvar_string("sbar_columns")), " ");
364 argc = tokenizebyseparator(strcat("x ", Sbar_DefaultColumnLayout()), " ");
368 if(argv(1) == "default")
369 argc = tokenizebyseparator(strcat("x ", Sbar_DefaultColumnLayout()), " ");
370 else if(argv(1) == "all")
373 s = "ping pl color name |";
374 for(i = 0; i < MAX_SCORE; ++i)
377 if(i != ps_secondary)
378 if(scores_label[i] != "")
379 s = strcat(s, " ", scores_label[i]);
381 if(ps_secondary != ps_primary)
382 s = strcat(s, " ", scores_label[ps_secondary]);
383 s = strcat(s, " ", scores_label[ps_primary]);
384 argc = tokenizebyseparator(strcat("x ", s), " ");
391 drawfont = sbar_font;
393 for(i = 0; i < argc - 1; ++i)
399 if(substring(str, 0, 1) == "?")
402 str = substring(str, 1, strlen(str) - 1);
405 slash = strstrofs(str, "/", 0);
408 pattern = substring(str, 0, slash);
409 str = substring(str, slash + 1, strlen(str) - (slash + 1));
411 if not(isGametypeInFilter(gametype, teamplay, pattern))
415 strunzone(sbar_title[sbar_num_fields]);
416 sbar_title[sbar_num_fields] = strzone(str);
417 sbar_size[sbar_num_fields] = stringwidth(str, FALSE, sbar_fontsize);
418 str = strtolower(str);
421 sbar_field[sbar_num_fields] = SP_PING;
422 } else if(str == "pl") {
423 sbar_field[sbar_num_fields] = SP_PL;
424 } else if(str == "kd" || str == "kdr" || str == "kdratio" || str == "k/d") {
425 sbar_field[sbar_num_fields] = SP_KDRATIO;
426 } else if(str == "name" || str == "nick") {
427 sbar_field[sbar_num_fields] = SP_NAME;
429 } else if(str == "|") {
430 sbar_field[sbar_num_fields] = SP_SEPARATOR;
433 for(j = 0; j < MAX_SCORE; ++j)
434 if(str == strtolower(scores_label[j]))
435 goto found; // sorry, but otherwise fteqcc -O3 miscompiles this and warns about "unreachable code"
444 print(strcat("^1Error:^7 Unknown score field: '", str, "'\n"));
448 sbar_field[sbar_num_fields] = j;
451 if(j == ps_secondary)
455 if(sbar_num_fields >= MAX_SBAR_FIELDS)
459 if(scores_flags[ps_primary] & SFL_ALLOW_HIDE)
461 if(scores_flags[ps_secondary] & SFL_ALLOW_HIDE)
463 if(ps_primary == ps_secondary)
465 missing = (!have_primary) + (!have_secondary) + (!have_separator) + (!have_name);
467 if(sbar_num_fields+missing < MAX_SBAR_FIELDS)
471 strunzone(sbar_title[sbar_num_fields]);
472 for(i = sbar_num_fields; i > 0; --i)
474 sbar_title[i] = sbar_title[i-1];
475 sbar_size[i] = sbar_size[i-1];
476 sbar_field[i] = sbar_field[i-1];
478 sbar_title[0] = strzone("name");
479 sbar_field[0] = SP_NAME;
481 print("fixed missing field 'name'\n");
485 strunzone(sbar_title[sbar_num_fields]);
486 for(i = sbar_num_fields; i > 1; --i)
488 sbar_title[i] = sbar_title[i-1];
489 sbar_size[i] = sbar_size[i-1];
490 sbar_field[i] = sbar_field[i-1];
492 sbar_title[1] = strzone("|");
493 sbar_field[1] = SP_SEPARATOR;
494 sbar_size[1] = stringwidth("|", FALSE, sbar_fontsize);
496 print("fixed missing field '|'\n");
499 else if(!have_separator)
501 strunzone(sbar_title[sbar_num_fields]);
502 sbar_title[sbar_num_fields] = strzone("|");
503 sbar_size[sbar_num_fields] = stringwidth("|", FALSE, sbar_fontsize);
504 sbar_field[sbar_num_fields] = SP_SEPARATOR;
506 print("fixed missing field '|'\n");
510 strunzone(sbar_title[sbar_num_fields]);
511 sbar_title[sbar_num_fields] = strzone(scores_label[ps_secondary]);
512 sbar_size[sbar_num_fields] = stringwidth(sbar_title[sbar_num_fields], FALSE, sbar_fontsize);
513 sbar_field[sbar_num_fields] = ps_secondary;
515 print("fixed missing field '", scores_label[ps_secondary], "'\n");
519 strunzone(sbar_title[sbar_num_fields]);
520 sbar_title[sbar_num_fields] = strzone(scores_label[ps_primary]);
521 sbar_size[sbar_num_fields] = stringwidth(sbar_title[sbar_num_fields], FALSE, sbar_fontsize);
522 sbar_field[sbar_num_fields] = ps_primary;
524 print("fixed missing field '", scores_label[ps_primary], "'\n");
528 sbar_field[sbar_num_fields] = SP_END;
532 vector sbar_field_rgb;
533 string sbar_field_icon0;
534 string sbar_field_icon1;
535 string sbar_field_icon2;
536 vector sbar_field_icon0_rgb;
537 vector sbar_field_icon1_rgb;
538 vector sbar_field_icon2_rgb;
539 float sbar_field_icon0_alpha;
540 float sbar_field_icon1_alpha;
541 float sbar_field_icon2_alpha;
542 string Sbar_GetField(entity pl, float field)
544 float tmp, num, denom, f;
546 sbar_field_rgb = '1 1 1';
547 sbar_field_icon0 = "";
548 sbar_field_icon1 = "";
549 sbar_field_icon2 = "";
550 sbar_field_icon0_rgb = '1 1 1';
551 sbar_field_icon1_rgb = '1 1 1';
552 sbar_field_icon2_rgb = '1 1 1';
553 sbar_field_icon0_alpha = 1;
554 sbar_field_icon1_alpha = 1;
555 sbar_field_icon2_alpha = 1;
560 return "\x8D\x8D\x8D"; // >>> sign
561 //str = getplayerkey(pl.sv_entnum, "ping");
565 tmp = max(0, min(220, f-80)) / 220;
566 sbar_field_rgb = '1 1 1' - '0 1 1'*tmp;
572 f = pl.ping_packetloss;
573 tmp = pl.ping_movementloss;
574 if(f == 0 && tmp == 0)
576 str = ftos(ceil(f * 100));
578 str = strcat(str, "~", ftos(ceil(tmp * 100)));
579 tmp = bound(0, f / 0.2 + tmp / 0.04, 1); // 20% is REALLY BAD pl
580 sbar_field_rgb = '1 0.5 0.5' - '0 0.5 0.5'*tmp;
584 if(ready_waiting && pl.ready)
586 sbar_field_icon0 = "gfx/sb_player_ready";
590 f = stof(getplayerkey(pl.sv_entnum, "colors"));
592 sbar_field_icon0 = "gfx/sb_playercolor_base";
593 sbar_field_icon1 = "gfx/sb_playercolor_shirt";
594 sbar_field_icon1_rgb = colormapPaletteColor(floor(f / 16), 0);
595 sbar_field_icon2 = "gfx/sb_playercolor_pants";
596 sbar_field_icon2_rgb = colormapPaletteColor(mod(f, 16), 1);
599 return GetPlayerName(pl.sv_entnum);
602 f = pl.(scores[SP_KILLS]);
603 f -= pl.(scores[SP_SUICIDES]);
607 num = pl.(scores[SP_KILLS]);
608 denom = pl.(scores[SP_DEATHS]);
611 sbar_field_rgb = '0 1 0';
613 } else if(num <= 0) {
614 sbar_field_rgb = '1 0 0';
615 str = ftos(num/denom);
617 str = ftos(num/denom);
619 tmp = strstrofs(str, ".", 0);
621 str = substring(str, 0, tmp+2);
625 tmp = pl.(scores[field]);
626 f = scores_flags[field];
627 if(field == ps_primary)
628 sbar_field_rgb = '1 1 0';
629 else if(field == ps_secondary)
630 sbar_field_rgb = '0 1 1';
632 sbar_field_rgb = '1 1 1';
633 return ScoreString(f, tmp);
638 float xmin, xmax, ymin, ymax, sbwidth;
639 float sbar_fixscoreboardcolumnwidth_len;
640 float sbar_fixscoreboardcolumnwidth_iconlen;
641 float sbar_fixscoreboardcolumnwidth_marginlen;
643 string Sbar_FixScoreboardColumnWidth(float i, string str)
647 field = sbar_field[i];
649 sbar_fixscoreboardcolumnwidth_iconlen = 0;
651 if(sbar_field_icon0 != "")
653 sz = drawgetimagesize(sbar_field_icon0);
655 if(sbar_fixscoreboardcolumnwidth_iconlen < f)
656 sbar_fixscoreboardcolumnwidth_iconlen = f;
659 if(sbar_field_icon1 != "")
661 sz = drawgetimagesize(sbar_field_icon1);
663 if(sbar_fixscoreboardcolumnwidth_iconlen < f)
664 sbar_fixscoreboardcolumnwidth_iconlen = f;
667 if(sbar_field_icon2 != "")
669 sz = drawgetimagesize(sbar_field_icon2);
671 if(sbar_fixscoreboardcolumnwidth_iconlen < f)
672 sbar_fixscoreboardcolumnwidth_iconlen = f;
675 sbar_fixscoreboardcolumnwidth_iconlen *= sbar_fontsize_y / sbar_fontsize_x; // fix icon aspect
677 if(sbar_fixscoreboardcolumnwidth_iconlen != 0)
678 sbar_fixscoreboardcolumnwidth_marginlen = stringwidth(" ", FALSE, sbar_fontsize);
680 sbar_fixscoreboardcolumnwidth_marginlen = 0;
682 if(field == SP_NAME) // name gets all remaining space
685 namesize = sbwidth;// / sbar_fontsize_x;
686 for(j = 0; j < sbar_num_fields; ++j)
688 if (sbar_field[i] != SP_SEPARATOR)
689 namesize -= sbar_size[j] + 1;
691 sbar_size[i] = namesize;
693 if (sbar_fixscoreboardcolumnwidth_iconlen != 0)
694 namesize -= sbar_fixscoreboardcolumnwidth_marginlen + sbar_fixscoreboardcolumnwidth_iconlen;
695 str = textShortenToWidth(str, namesize, sbar_fontsize, stringwidth_colors);
696 sbar_fixscoreboardcolumnwidth_len = stringwidth(str, TRUE, sbar_fontsize);
699 sbar_fixscoreboardcolumnwidth_len = stringwidth(str, FALSE, sbar_fontsize);
701 f = sbar_fixscoreboardcolumnwidth_len + sbar_fixscoreboardcolumnwidth_marginlen + sbar_fixscoreboardcolumnwidth_iconlen;
708 void Sbar_PrintScoreboardItem(vector pos, entity pl, float is_self, float pl_number)
711 rgb = GetTeamRGB(pl.team);
715 is_spec = (GetPlayerColor(pl.sv_entnum) == COLOR_SPECTATOR);
717 if((rgb == '1 1 1') && (!is_spec)) {
718 rgb_x = cvar("sbar_color_bg_r") + 0.5;
719 rgb_y = cvar("sbar_color_bg_g") + 0.5;
720 rgb_z = cvar("sbar_color_bg_b") + 0.5; }
724 tmp_y = sbar_fontsize_y * 1.25;
727 // alternated rows highlighting
729 drawfill(pos - '1 1 0', tmp + '2 0 0', rgb, sb_highlight_alpha_self, DRAWFLAG_NORMAL);
730 else if((sb_highlight) && (!mod(pl_number,2)))
731 drawfill(pos - '1 1 0', tmp + '2 0 0', rgb, sb_highlight_alpha, DRAWFLAG_NORMAL);
735 for(i = 0; i < sbar_num_fields; ++i)
737 field = sbar_field[i];
738 if(field == SP_SEPARATOR)
741 if(is_spec && field != SP_NAME && field != SP_PING) {
742 pos_x += sbar_size[i] + sbar_fontsize_x;
745 str = Sbar_GetField(pl, field);
746 str = Sbar_FixScoreboardColumnWidth(i, str);
748 pos_x += sbar_size[i] + sbar_fontsize_x;
750 if(field == SP_NAME) {
751 tmp_x = sbar_size[i] - sbar_fontsize_x*sbar_fixscoreboardcolumnwidth_iconlen - sbar_fixscoreboardcolumnwidth_marginlen + sbar_fontsize_x;
753 drawcolorcodedstring(pos - tmp, str, sbar_fontsize, sb_alpha_name_self, DRAWFLAG_NORMAL);
755 drawcolorcodedstring(pos - tmp, str, sbar_fontsize, sb_alpha_name, DRAWFLAG_NORMAL);
757 tmp_x = sbar_fixscoreboardcolumnwidth_len + sbar_fontsize_x;
759 drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, sb_alpha_name_self, DRAWFLAG_NORMAL);
761 drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, sb_alpha_name, DRAWFLAG_NORMAL);
764 tmp_x = sbar_size[i] + sbar_fontsize_x;
765 if(sbar_field_icon0 != "")
767 drawpic(pos - tmp, sbar_field_icon0, '0 1 0' * sbar_fontsize_y + '1 0 0' * sbar_fontsize_x * sbar_fixscoreboardcolumnwidth_iconlen, sbar_field_icon1_rgb, sbar_field_icon0_alpha * sb_alpha_name_self, DRAWFLAG_NORMAL);
769 drawpic(pos - tmp, sbar_field_icon0, '0 1 0' * sbar_fontsize_y + '1 0 0' * sbar_fontsize_x * sbar_fixscoreboardcolumnwidth_iconlen, sbar_field_icon1_rgb, sbar_field_icon0_alpha * sb_alpha_name, DRAWFLAG_NORMAL);
770 if(sbar_field_icon1 != "")
772 drawpic(pos - tmp, sbar_field_icon1, '0 1 0' * sbar_fontsize_y + '1 0 0' * sbar_fontsize_x * sbar_fixscoreboardcolumnwidth_iconlen, sbar_field_icon1_rgb, sbar_field_icon1_alpha * sb_alpha_name_self, DRAWFLAG_NORMAL);
774 drawpic(pos - tmp, sbar_field_icon1, '0 1 0' * sbar_fontsize_y + '1 0 0' * sbar_fontsize_x * sbar_fixscoreboardcolumnwidth_iconlen, sbar_field_icon1_rgb, sbar_field_icon1_alpha * sb_alpha_name, DRAWFLAG_NORMAL);
775 if(sbar_field_icon2 != "")
777 drawpic(pos - tmp, sbar_field_icon2, '0 1 0' * sbar_fontsize_y + '1 0 0' * sbar_fontsize_x * sbar_fixscoreboardcolumnwidth_iconlen, sbar_field_icon2_rgb, sbar_field_icon2_alpha * sb_alpha_name_self, DRAWFLAG_NORMAL);
779 drawpic(pos - tmp, sbar_field_icon2, '0 1 0' * sbar_fontsize_y + '1 0 0' * sbar_fontsize_x * sbar_fixscoreboardcolumnwidth_iconlen, sbar_field_icon2_rgb, sbar_field_icon2_alpha * sb_alpha_name, DRAWFLAG_NORMAL);
782 if(sbar_field[i] == SP_SEPARATOR)
785 for(i = sbar_num_fields-1; i > 0; --i)
787 field = sbar_field[i];
788 if(field == SP_SEPARATOR)
791 if(is_spec && field != SP_NAME && field != SP_PING) {
792 pos_x -= sbar_size[i] + sbar_fontsize_x;
796 str = Sbar_GetField(pl, field);
797 str = Sbar_FixScoreboardColumnWidth(i, str);
799 if(field == SP_NAME) {
800 tmp_x = sbar_fixscoreboardcolumnwidth_len; // left or right aligned? let's put it right...
802 drawcolorcodedstring(pos - tmp, str, sbar_fontsize, sb_alpha_name_self, DRAWFLAG_NORMAL);
804 drawcolorcodedstring(pos - tmp, str, sbar_fontsize, sb_alpha_name, DRAWFLAG_NORMAL);
806 tmp_x = sbar_fixscoreboardcolumnwidth_len;
808 drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, sb_alpha_name_self, DRAWFLAG_NORMAL);
810 drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, sb_alpha_name, DRAWFLAG_NORMAL);
813 tmp_x = sbar_size[i];
814 if(sbar_field_icon0 != "")
816 drawpic(pos - tmp, sbar_field_icon0, '0 1 0' * sbar_fontsize_y + '1 0 0' * sbar_fontsize_x * sbar_fixscoreboardcolumnwidth_iconlen, sbar_field_icon1_rgb, sbar_field_icon0_alpha * sb_alpha_name_self, DRAWFLAG_NORMAL);
818 drawpic(pos - tmp, sbar_field_icon0, '0 1 0' * sbar_fontsize_y + '1 0 0' * sbar_fontsize_x * sbar_fixscoreboardcolumnwidth_iconlen, sbar_field_icon1_rgb, sbar_field_icon0_alpha * sb_alpha_name, DRAWFLAG_NORMAL);
819 if(sbar_field_icon1 != "")
821 drawpic(pos - tmp, sbar_field_icon1, '0 1 0' * sbar_fontsize_y + '1 0 0' * sbar_fontsize_x * sbar_fixscoreboardcolumnwidth_iconlen, sbar_field_icon1_rgb, sbar_field_icon1_alpha * sb_alpha_name_self, DRAWFLAG_NORMAL);
823 drawpic(pos - tmp, sbar_field_icon1, '0 1 0' * sbar_fontsize_y + '1 0 0' * sbar_fontsize_x * sbar_fixscoreboardcolumnwidth_iconlen, sbar_field_icon1_rgb, sbar_field_icon1_alpha * sb_alpha_name, DRAWFLAG_NORMAL);
824 if(sbar_field_icon2 != "")
826 drawpic(pos - tmp, sbar_field_icon2, '0 1 0' * sbar_fontsize_y + '1 0 0' * sbar_fontsize_x * sbar_fixscoreboardcolumnwidth_iconlen, sbar_field_icon2_rgb, sbar_field_icon2_alpha * sb_alpha_name_self, DRAWFLAG_NORMAL);
828 drawpic(pos - tmp, sbar_field_icon2, '0 1 0' * sbar_fontsize_y + '1 0 0' * sbar_fontsize_x * sbar_fixscoreboardcolumnwidth_iconlen, sbar_field_icon2_rgb, sbar_field_icon2_alpha * sb_alpha_name, DRAWFLAG_NORMAL);
829 pos_x -= sbar_size[i] + sbar_fontsize_x;
835 * Sbar_Scoreboard_MakeTable
837 * Makes a table for a team (for all playing players in DM) and fills it
840 vector Sbar_Scoreboard_MakeTable(vector pos, entity tm, vector rgb, vector bg_size)
842 float body_table_height, i;
843 vector tmp, column_dim;
846 body_table_height = 1.25 * sbar_fontsize_y * max(1, tm.team_size); // no player? show 1 empty line
851 tmp_y = 1.25 * sbar_fontsize_y;
854 drawpic(pos, "gfx/hud/sb_scoreboard_tableheader", tmp, (rgb * hud_color_bg_team) + '0.5 0.5 0.5', sb_alpha_bg, DRAWFLAG_NORMAL);
857 tmp_y += hud_border_thickness;
858 tmp_y += body_table_height;
859 drawborderlines(hud_border_thickness, pos, tmp, '0 0 0', sb_alpha_bg, DRAWFLAG_NORMAL); // more transparency for the scoreboard
861 // separator header/table
862 pos_y += 1.25 * sbar_fontsize_y;
863 tmp_y = hud_border_thickness;
864 drawfill(pos, tmp, '0 0 0', sb_alpha_bg, DRAWFLAG_NORMAL);
866 pos_y += hud_border_thickness;
869 tmp_y = body_table_height;
870 drawpic_tiled(pos, "gfx/hud/sb_scoreboard_bg", bg_size, tmp, rgb * hud_color_bg_team, sb_alpha_bg, DRAWFLAG_NORMAL);
872 // anyway, apply some color
873 //drawfill(pos, tmp + '2 0 0', rgb, 0.1, DRAWFLAG_NORMAL);
875 // go back to the top to make alternated columns highlighting and to print the strings
876 pos_y -= 1.25 * sbar_fontsize_y;
877 pos_y -= hud_border_thickness;
883 column_dim_y = 1.25 * sbar_fontsize_y; // header
884 column_dim_y += hud_border_thickness;
885 column_dim_y += body_table_height;
888 // print the strings of the columns headers and draw the columns
889 for(i = 0; i < sbar_num_fields; ++i)
891 if(sbar_field[i] == SP_SEPARATOR)
893 column_dim_x = sbar_size[i] + sbar_fontsize_x;
897 drawfill(pos - '0 1 0' - sbar_fontsize_x / 2 * '1 0 0', column_dim, '0 0 0', sb_alpha_bg * 0.2, DRAWFLAG_NORMAL);
899 drawstring(pos, sbar_title[i], sbar_fontsize, rgb * 1.5, sb_alpha_fg, DRAWFLAG_NORMAL);
900 pos_x += column_dim_x;
902 if(sbar_field[i] == SP_SEPARATOR)
906 for(i = sbar_num_fields-1; i > 0; --i)
908 if(sbar_field[i] == SP_SEPARATOR)
911 pos_x -= sbar_size[i];
917 if (i == sbar_num_fields-1)
918 column_dim_x = sbar_size[i] + sbar_fontsize_x / 2 + 1;
920 column_dim_x = sbar_size[i] + sbar_fontsize_x;
921 drawfill(pos - '0 1 0' - sbar_fontsize_x / 2 * '1 0 0', column_dim, '0 0 0', sb_alpha_bg * 0.2, DRAWFLAG_NORMAL);
925 tmp_x = stringwidth(sbar_title[i], FALSE, sbar_fontsize);
926 tmp_x = (sbar_size[i] - tmp_x) * sbar_fontsize_x;
927 drawstring(pos + tmp, sbar_title[i], sbar_fontsize, rgb * 1.5, sb_alpha_fg, DRAWFLAG_NORMAL);
928 pos_x -= sbar_fontsize_x;
933 pos_y += 1.25 * sbar_fontsize_y; // skip the header
934 pos_y += hud_border_thickness;
936 // fill the table and draw the rows
939 for(pl = players.sort_next; pl; pl = pl.sort_next)
941 if(pl.team != tm.team)
943 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1), i);
944 pos_y += 1.25 * sbar_fontsize_y;
948 for(pl = players.sort_next; pl; pl = pl.sort_next)
950 if(pl.team == COLOR_SPECTATOR)
952 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1), i);
953 pos_y += 1.25 * sbar_fontsize_y;
958 pos_y += 1.25 * sbar_fontsize_y; // move to the end of the table
959 pos_y += 1.25 * sbar_fontsize_y; // move empty row (out of the table)
964 float Sbar_WouldDrawScoreboard() {
967 else if (intermission == 1)
969 else if (intermission == 2)
971 else if (getstati(STAT_HEALTH) <= 0 && cvar("cl_deathscoreboard"))
973 else if(sb_showscores_force)
979 float average_accuracy;
980 vector Sbar_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size)
983 float weapon_hit, weapon_damage, weapon_stats;
984 float fontsize = 40 * 1/3;
985 float weapon_cnt = 12;
987 if(cvar("sbar_accuracy_doublerows"))
998 drawstring(pos, strcat("Accuracy stats (average ", ftos(average_accuracy), "%)"), sbar_fontsize, '1 1 1', sb_alpha_fg, DRAWFLAG_NORMAL);
1002 tmp_y = height * rows;
1004 drawpic_tiled(pos, "gfx/hud/sb_scoreboard_bg", bg_size, tmp, rgb * hud_color_bg_team, sb_alpha_bg, DRAWFLAG_NORMAL);
1005 drawborderlines(hud_accuracy_border_thickness, pos, tmp, '0 0 0', sb_alpha_bg * 0.75, DRAWFLAG_NORMAL);
1007 // column highlighting
1008 for(i = 0; i < weapon_cnt/rows; ++i)
1011 drawfill(pos + '1 0 0' * (sbwidth/weapon_cnt) * rows * i, '0 1 0' * height * rows + '1 0 0' * (sbwidth/weapon_cnt) * rows, '0 0 0', sb_alpha_bg * 0.2, DRAWFLAG_NORMAL);
1015 for(i = 0; i < rows; ++i)
1017 drawfill(pos + '0 1 0' * height * (2/3) + '0 1 0' * height * i, '1 0 0' * sbwidth + '0 1 0' * fontsize, '1 1 1', sb_highlight_alpha, DRAWFLAG_NORMAL);
1020 drawfont = sbar_bigfont;
1021 average_accuracy = 0;
1022 float weapons_with_stats;
1023 weapons_with_stats = 0;
1025 pos_x += sbwidth/weapon_cnt / 2;
1027 if(getstati(STAT_SWITCHWEAPON) == WEP_MINSTANEX)
1028 g_minstagib = 1; // TODO: real detection for minstagib?
1030 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1032 self = get_weaponinfo(i);
1033 if not(self.weapons)
1035 if ((i == WEP_NEX && g_minstagib) || i == WEP_PORTO || (i == WEP_MINSTANEX && !g_minstagib) || i == WEP_TUBA || i == WEP_FIREBALL) // skip port-o-launch, nex || minstanex, tuba and fireball
1037 weapon_hit = weapon_hits[i-WEP_FIRST];
1038 weapon_damage = weapon_fired[i-WEP_FIRST];
1040 weapon_stats = bound(0, floor(100 * weapon_hit / weapon_damage), 100);
1044 weapon_alpha = sb_alpha_fg;
1046 weapon_alpha = 0.2 * sb_alpha_fg;
1049 drawpic(pos, strcat("gfx/hud/inv_weapon", self.netname), '1 0 0' * sbwidth * (1/weapon_cnt) + '0 1 0' * height * (2/3), '1 1 1', weapon_alpha, DRAWFLAG_NORMAL);
1052 weapons_with_stats += 1;
1053 average_accuracy += weapon_stats; // store sum of all accuracies in average_accuracy
1056 s = strcat(ftos(weapon_stats),"%");
1059 padding = ((sbwidth/weapon_cnt) - stringwidth(s, FALSE, '1 0 0' * fontsize)) / 2; // center the accuracy value
1061 rgb = HUD_AccuracyColor(weapon_stats);
1062 drawstring(pos + '1 0 0' * padding + '0 1 0' * height * (2/3), s, '1 1 0' * fontsize, rgb, sb_alpha_fg, DRAWFLAG_NORMAL);
1064 pos_x += sbwidth/weapon_cnt * rows;
1065 if(rows == 2 && i == 6) {
1070 drawfont = sbar_font;
1072 if(weapons_with_stats)
1073 average_accuracy = floor(average_accuracy / weapons_with_stats);
1076 pos_x -= sbwidth/weapon_cnt / 2;
1082 vector Sbar_DrawScoreboardRankings(vector pos, entity pl, vector rgb, vector bg_size)
1085 RANKINGS_RECEIVED_CNT = 0;
1086 for (i=RANKINGS_CNT-1; i>=0; --i)
1088 RANKINGS_RECEIVED_CNT = RANKINGS_RECEIVED_CNT + 1;
1090 if (RANKINGS_RECEIVED_CNT == 0)
1094 is_spec = (GetPlayerColor(pl.sv_entnum) == COLOR_SPECTATOR);
1096 hl_rgb_x = cvar("sbar_color_bg_r") + 0.5;
1097 hl_rgb_y = cvar("sbar_color_bg_g") + 0.5;
1098 hl_rgb_z = cvar("sbar_color_bg_b") + 0.5;
1100 pos_y += sbar_fontsize_y;
1101 drawstring(pos, strcat("Rankings"), sbar_fontsize, '1 1 1', sb_alpha_fg, DRAWFLAG_NORMAL);
1102 pos_y += sbar_fontsize_y;
1105 tmp_y = sbar_fontsize_y * RANKINGS_RECEIVED_CNT;
1107 drawpic_tiled(pos, "gfx/hud/sb_scoreboard_bg", bg_size, tmp, rgb * hud_color_bg_team, sb_alpha_bg, DRAWFLAG_NORMAL);
1108 drawborderlines(hud_border_thickness, pos, tmp, '0 0 0', sb_alpha_bg * 0.75, DRAWFLAG_NORMAL);
1111 for(i = 0; i<RANKINGS_RECEIVED_CNT; ++i)
1118 n = grecordholder[i];
1119 p = race_PlaceName(i+1);
1120 if(grecordholder[i] == GetPlayerName(player_localentnum - 1))
1121 drawfill(pos, '1 0 0' * sbwidth + '0 1 0' * sbar_fontsize_y, hl_rgb, sb_highlight_alpha_self, DRAWFLAG_NORMAL);
1122 else if(!mod(i, 2) && sb_highlight)
1123 drawfill(pos, '1 0 0' * sbwidth + '0 1 0' * sbar_fontsize_y, hl_rgb, sb_highlight_alpha, DRAWFLAG_NORMAL);
1124 drawstring(pos, p, sbar_fontsize, '1 1 1', sb_alpha_fg, DRAWFLAG_NORMAL);
1125 drawstring(pos + '3 0 0' * sbar_fontsize_x, TIME_ENCODED_TOSTRING(t), sbar_fontsize, '1 1 1', sb_alpha_fg, DRAWFLAG_NORMAL);
1126 drawcolorcodedstring(pos + '8 0 0' * sbar_fontsize_x, n, sbar_fontsize, sb_alpha_fg, DRAWFLAG_NORMAL);
1127 pos += '0 1 0' * sbar_fontsize_y;
1133 float sb_fade_alpha;
1134 float sbar_woulddrawscoreboard_prev;
1135 float sbar_woulddrawscoreboard_change; // "time" at which Sbar_WouldDrawScoreboard() changed
1136 void Sbar_DrawScoreboard()
1138 float sbar_woulddrawscoreboard;
1139 sbar_woulddrawscoreboard = Sbar_WouldDrawScoreboard();
1140 if(sbar_woulddrawscoreboard != sbar_woulddrawscoreboard_prev) {
1141 sbar_woulddrawscoreboard_change = time;
1142 sbar_woulddrawscoreboard_prev = sbar_woulddrawscoreboard;
1145 float scoreboard_fadeinspeed = cvar_or("sb_fadeinspeed", 10);
1146 float scoreboard_fadeoutspeed = cvar_or("sb_fadeoutspeed", 5);
1147 if(sbar_woulddrawscoreboard) {
1148 if (scoreboard_fadeinspeed)
1149 sb_fade_alpha = bound (0, (time - sbar_woulddrawscoreboard_change) * scoreboard_fadeinspeed, 1);
1154 if (scoreboard_fadeoutspeed)
1155 sb_fade_alpha = bound (0, (1/scoreboard_fadeoutspeed - (time - sbar_woulddrawscoreboard_change)) * scoreboard_fadeoutspeed, 1);
1159 if not(sb_fade_alpha)
1162 sb_alpha_bg = cvar("sb_alpha_bg") * sb_fade_alpha;
1163 sb_alpha_fg = cvar_or("sb_alpha_fg", 1.0) * sb_fade_alpha;
1164 sb_highlight = cvar("sb_highlight");
1165 sb_highlight_alpha = cvar_or("sb_highlight_alpha", 0.10) * sb_alpha_fg;
1166 sb_highlight_alpha_self = cvar_or("sb_highlight_alpha_self", 0.25) * sb_alpha_fg;
1167 sb_alpha_name = cvar_or("sb_alpha_name", 0.9) * sb_alpha_fg;
1168 sb_alpha_name_self = cvar_or("sb_alpha_name_self", 1) * sb_alpha_fg;
1170 vector rgb, pos, tmp;
1173 sbwidth = Sbar_GetWidth(6.5 * sbar_fontsize_y);
1175 xmin = 0.5 * (vid_conwidth - sbwidth);
1176 ymin = SCOREBOARD_OFFSET;
1178 xmax = vid_conwidth - xmin;
1179 ymax = vid_conheight - 0.2*vid_conheight;
1181 // Initializes position
1187 drawfont = sbar_bigfont;
1188 drawstringcenter('0 1 0' * ymin, "Scoreboard", '24 24 0', '1 1 1', sb_alpha_fg, DRAWFLAG_NORMAL);
1191 pos_y += sbar_fontsize_y;
1193 drawfont = sbar_font;
1195 // Draw the scoreboard
1197 bg_size = drawgetimagesize("gfx/hud/sb_scoreboard_bg");
1201 for(tm = teams.sort_next; tm; tm = tm.sort_next)
1203 if(tm.team == COLOR_SPECTATOR)
1206 rgb = GetTeamRGB(tm.team);
1207 Sbar_DrawXNum(pos - '9.5 0 0' * sbar_fontsize_y + '0 1 0' * sbar_fontsize_y, tm.(teamscores[ts_primary]), 6, 0, sbar_fontsize_y * 1.5, rgb, 0, 1, sb_alpha_fg, DRAWFLAG_NORMAL);
1209 if(ts_primary != ts_secondary)
1210 Sbar_DrawXNum(pos - '7.5 0 0' * sbar_fontsize_y + '0 2.5 0' * sbar_fontsize_y, tm.(teamscores[ts_secondary]), 6, 0, sbar_fontsize_y * 1, rgb, 0, 1, sb_alpha_fg, DRAWFLAG_NORMAL);
1212 pos = Sbar_Scoreboard_MakeTable(pos, tm, rgb, bg_size);
1217 rgb_x = cvar("sbar_color_bg_r");
1218 rgb_y = cvar("sbar_color_bg_g");
1219 rgb_z = cvar("sbar_color_bg_b");
1221 for(tm = teams.sort_next; tm; tm = tm.sort_next)
1223 if(tm.team == COLOR_SPECTATOR)
1226 pos = Sbar_Scoreboard_MakeTable(pos, tm, rgb, bg_size);
1230 if(gametype == GAME_CTS || gametype == GAME_RACE) {
1231 if(race_speedaward) {
1232 drawcolorcodedstring(pos, strcat("Speed award: ", ftos(race_speedaward), " (", race_speedaward_holder, ")"), sbar_fontsize, sb_alpha_fg, DRAWFLAG_NORMAL);
1233 pos_y += 1.25 * sbar_fontsize_y;
1235 if(race_speedaward_alltimebest) {
1236 drawcolorcodedstring(pos, strcat("All-time fastest: ", ftos(race_speedaward_alltimebest), " (", race_speedaward_alltimebest_holder, ")"), sbar_fontsize, sb_alpha_fg, DRAWFLAG_NORMAL);
1237 pos_y += 1.25 * sbar_fontsize_y;
1239 pos = Sbar_DrawScoreboardRankings(pos, pl, rgb, bg_size);
1241 else if(cvar("sbar_accuracy") && spectatee_status != -1) {
1243 pos = Sbar_DrawScoreboardAccuracyStats(pos, GetTeamRGB(myteam), bg_size);
1245 pos = Sbar_DrawScoreboardAccuracyStats(pos, rgb, bg_size);
1248 tmp = pos + '0 1.5 0' * sbar_fontsize_y;
1249 pos_y += 3 * sbar_fontsize_y;
1254 for(pl = players.sort_next; pl; pl = pl.sort_next)
1256 if(pl.team != COLOR_SPECTATOR)
1258 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1), specs);
1259 pos_y += 1.25 * sbar_fontsize_y;
1264 drawstring(tmp, "Spectators", sbar_fontsize, '1 1 1', sb_alpha_fg, DRAWFLAG_NORMAL);
1266 // Print info string
1269 str = strcat("playing on ^2", shortmapname, "^7");
1270 tl = getstatf(STAT_TIMELIMIT);
1271 fl = getstatf(STAT_FRAGLIMIT);
1272 ll = getstatf(STAT_LEADLIMIT);
1273 if(gametype == GAME_LMS)
1276 str = strcat(str, " for up to ^1", ftos(tl), " minutes^7");
1281 str = strcat(str, " for ^1", ftos(tl), " minutes^7");
1285 str = strcat(str, " or");
1288 str = strcat(str, " until ^3", ScoreString(teamscores_flags[ts_primary], fl));
1289 if(teamscores_label[ts_primary] == "score")
1290 str = strcat(str, " points^7");
1291 else if(teamscores_label[ts_primary] == "fastest")
1292 str = strcat(str, " is beaten^7");
1294 str = strcat(str, " ", teamscores_label[ts_primary]);
1298 str = strcat(str, " until ^3", ScoreString(scores_flags[ps_primary], fl));
1299 if(scores_label[ps_primary] == "score")
1300 str = strcat(str, " points^7");
1301 else if(scores_label[ps_primary] == "fastest")
1302 str = strcat(str, " is beaten^7");
1304 str = strcat(str, " ", scores_label[ps_primary]);
1309 if(tl > 0 || fl > 0)
1310 str = strcat(str, " or");
1313 str = strcat(str, " until a lead of ^3", ScoreString(teamscores_flags[ts_primary], ll));
1314 if(teamscores_label[ts_primary] == "score")
1315 str = strcat(str, " points^7");
1316 else if(teamscores_label[ts_primary] == "fastest")
1317 str = strcat(str, " is beaten^7");
1319 str = strcat(str, " ", teamscores_label[ts_primary]);
1323 str = strcat(str, " until a lead of ^3", ScoreString(scores_flags[ps_primary], ll));
1324 if(scores_label[ps_primary] == "score")
1325 str = strcat(str, " points^7");
1326 else if(scores_label[ps_primary] == "fastest")
1327 str = strcat(str, " is beaten^7");
1329 str = strcat(str, " ", scores_label[ps_primary]);
1335 pos_y += 1.2 * sbar_fontsize_y;
1336 drawcolorcodedstring(pos + '0.5 0 0' * (sbwidth - stringwidth(str, TRUE, sbar_fontsize)), str, sbar_fontsize, sb_alpha_fg, DRAWFLAG_NORMAL);
1338 scoreboard_bottom = pos_y + 2 * sbar_fontsize_y;
1341 void Sbar_DrawAccuracyStats_Description_Hitscan(vector position)
1343 drawstring(position + '0 3 0' * sbar_fontsize_y, "Shots fired:", sbar_fontsize, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1344 drawstring(position + '0 5 0' * sbar_fontsize_y, "Shots hit:", sbar_fontsize, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1345 drawstring(position + '0 7 0' * sbar_fontsize_y, "Accuracy:", sbar_fontsize, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1346 drawstring(position + '0 9 0' * sbar_fontsize_y, "Shots missed:", sbar_fontsize, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1349 void Sbar_DrawAccuracyStats_Description_Splash(vector position)
1351 drawstring(position + '0 3 0' * sbar_fontsize_y, "Maximum damage:", sbar_fontsize, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1352 drawstring(position + '0 5 0' * sbar_fontsize_y, "Actual damage:", sbar_fontsize, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1353 drawstring(position + '0 7 0' * sbar_fontsize_y, "Accuracy:", sbar_fontsize, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1354 drawstring(position + '0 9 0' * sbar_fontsize_y, "Damage wasted:", sbar_fontsize, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1357 void Sbar_DrawAccuracyStats()
1359 float i, count_hitscan, count_splash, row; // count is the number of 'colums'
1360 float weapon_hit, weapon_damage, weapon_stats;
1361 float left_border; // position where the weapons start, the description is in the border
1362 vector fill_colour, fill_size;
1364 vector border_colour;
1366 float col_margin = 20; // pixels between the columns
1367 float row_margin = 20; // pixels between the rows
1369 fill_size_x = 5 * sbar_fontsize_x; // width of the background
1370 fill_size_y = 10 * sbar_fontsize_y; // height of the background
1372 drawfont = sbar_bigfont;
1374 pos_y = SCOREBOARD_OFFSET;
1376 drawstringcenter(pos, "Weapon Accuracy", 2 * sbar_fontsize, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1378 left_border = col_margin + 11 * sbar_fontsize_x;
1380 drawfont = sbar_font;
1385 if(mod(time, 1) >= 0.4)
1386 drawstringcenter(pos, "Stats are not tracked during warmup stage", sbar_fontsize, '1 1 0', hud_alpha_fg, DRAWFLAG_NORMAL);
1391 if(gametype == GAME_RACE || gametype == GAME_CTS)
1394 if(mod(time, 1) >= 0.4)
1395 drawstringcenter(pos, "Stats are not tracked in Race/CTS", sbar_fontsize, '1 1 0', hud_alpha_fg, DRAWFLAG_NORMAL);
1400 float top_border_hitscan = SCOREBOARD_OFFSET + 55; // position where the hitscan row starts: pixels down the screen
1401 Sbar_DrawAccuracyStats_Description_Hitscan('1 0 0' * col_margin + '0 1 0' * top_border_hitscan);
1403 float top_border_splash = SCOREBOARD_OFFSET + 175; // position where the splash row starts: pixels down the screen
1404 Sbar_DrawAccuracyStats_Description_Splash('1 0 0' * col_margin + '0 1 0' * top_border_splash);
1406 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1408 self = get_weaponinfo(i);
1409 if not(self.weapons)
1411 weapon_hit = weapon_hits[i-WEP_FIRST];
1412 weapon_damage = weapon_fired[i-WEP_FIRST];
1413 border_colour = (i == activeweapon) ? '1 1 1' : '0 0 0'; // white or black border
1415 if (weapon_damage) {
1416 if (self.spawnflags & WEP_TYPE_SPLASH) {
1417 weapon_stats = bound(0, floor(100 * weapon_hit / weapon_damage), 100);
1419 fill_colour_x = 1 - 0.015 * weapon_stats;
1420 fill_colour_y = 1 - 0.015 * (100 - weapon_stats);
1422 // how the background colour is calculated
1423 // % red green red_2 green_2
1424 // 0 1 0 1 - % * 0.015 1 - (100 - %) * 0.015
1425 // 10 0.85 0 1 - % * 0.015 1 - (100 - %) * 0.015
1426 // 20 0.70 0 1 - % * 0.015 1 - (100 - %) * 0.015
1427 // 30 0.55 0 1 - % * 0.015 1 - (100 - %) * 0.015
1428 // 40 0.40 0.10 1 - % * 0.015 1 - (100 - %) * 0.015
1429 // 50 0.25 0.25 1 - % * 0.015 1 - (100 - %) * 0.015
1430 // 60 0.10 0.40 1 - % * 0.015 1 - (100 - %) * 0.015
1431 // 70 0 0.55 1 - % * 0.015 1 - (100 - %) * 0.015
1432 // 80 0 0.70 1 - % * 0.015 1 - (100 - %) * 0.015
1433 // 90 0 0.85 1 - % * 0.015 1 - (100 - %) * 0.015
1434 // 100 0 1 1 - % * 0.015 1 - (100 - %) * 0.015
1436 if ((left_border + count_splash * (fill_size_x + col_margin) + fill_size_x) >= vid_conwidth)
1440 Sbar_DrawAccuracyStats_Description_Splash('1 0 0' * col_margin + '0 1 0' * (top_border_splash + row * (fill_size_y + row_margin)));
1443 pos_x = left_border + count_splash * (fill_size_x + col_margin);
1444 pos_y = top_border_splash + row * (fill_size_y + row_margin);
1447 drawpic(pos, "gfx/hud/sb_accuracy", fill_size , fill_colour, hud_alpha_bg, DRAWFLAG_NORMAL);
1448 drawborderlines(hud_border_thickness, pos, fill_size, border_colour, hud_alpha_bg, DRAWFLAG_NORMAL);
1451 drawpic(pos, strcat("gfx/hud/inv_weapon", self.netname), '1 0.5 0' * fill_size_x , '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1453 // the amount of shots fired or max damage
1454 drawstringright(pos + '4.5 0 0' * sbar_fontsize_x + '0 3 0' * sbar_fontsize_y, ftos(weapon_damage), sbar_fontsize, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1456 // the amount of hits or actual damage
1457 drawstringright(pos + '4.5 0 0' * sbar_fontsize_x + '0 5 0' * sbar_fontsize_y, ftos(weapon_hit), sbar_fontsize, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1460 drawstringright(pos + '4.5 0 0' * sbar_fontsize_x + '0 7 0' * sbar_fontsize_y, strcat(ftos(weapon_stats),"%"), sbar_fontsize, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1462 // the amount of shots missed or damage wasted
1463 drawstringright(pos + '4.5 0 0' * sbar_fontsize_x + '0 9 0' * sbar_fontsize_y, ftos(max(0, weapon_damage - weapon_hit)), sbar_fontsize, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1466 } else if (self.spawnflags & WEP_TYPE_HITSCAN) {
1467 weapon_stats = bound(0, floor(100 * weapon_hit / weapon_damage), 100);
1469 fill_colour_x = 1 - 0.015 * weapon_stats;
1470 fill_colour_y = 1 - 0.015 * (100 - weapon_stats);
1472 // how the background colour is calculated
1473 // % red green red_2 green_2
1474 // 0 1 0 1 - % * 0.015 1 - (100 - %) * 0.015
1475 // 10 0.850 0 1 - % * 0.015 1 - (100 - %) * 0.015
1476 // 20 0.70 0 1 - % * 0.015 1 - (100 - %) * 0.015
1477 // 30 0.55 0 1 - % * 0.015 1 - (100 - %) * 0.015
1478 // 40 0.40 0.10 1 - % * 0.015 1 - (100 - %) * 0.015
1479 // 50 0.25 0.25 1 - % * 0.015 1 - (100 - %) * 0.015
1480 // 60 0.10 0.40 1 - % * 0.015 1 - (100 - %) * 0.015
1481 // 70 0 0.55 1 - % * 0.015 1 - (100 - %) * 0.015
1482 // 80 0 0.70 1 - % * 0.015 1 - (100 - %) * 0.015
1483 // 90 0 0.85 1 - % * 0.015 1 - (100 - %) * 0.015
1484 // 100 0 1 1 - % * 0.015 1 - (100 - %) * 0.015
1486 if ((left_border + count_hitscan * (fill_size_x + col_margin) + fill_size_x + cvar("stats_right_margin")) >= vid_conwidth)
1490 Sbar_DrawAccuracyStats_Description_Hitscan('1 0 0' * col_margin + '0 1 0' * (top_border_hitscan + row * (fill_size_y + row_margin)));
1493 pos_x = left_border + count_hitscan * (fill_size_x + col_margin);
1494 pos_y = top_border_hitscan + row * (fill_size_y + row_margin);
1497 drawpic(pos, "gfx/hud/sb_accuracy", fill_size , fill_colour, hud_alpha_bg, DRAWFLAG_NORMAL);
1498 drawborderlines(hud_border_thickness, pos, fill_size, border_colour, hud_alpha_bg, DRAWFLAG_NORMAL);
1501 drawpic(pos, strcat("gfx/hud/inv_weapon", self.netname), '1 0.5 0' * fill_size_x , '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1503 // the amount of shots fired or max damage
1504 drawstringright(pos + '4.5 0 0' * sbar_fontsize_x + '0 3 0' * sbar_fontsize_y, ftos(weapon_damage), sbar_fontsize, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1506 // the amount of hits or actual damage
1507 drawstringright(pos + '4.5 0 0' * sbar_fontsize_x + '0 5 0' * sbar_fontsize_y, ftos(weapon_hit), sbar_fontsize, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1510 drawstringright(pos + '4.5 0 0' * sbar_fontsize_x + '0 7 0' * sbar_fontsize_y, strcat(ftos(weapon_stats),"%"), sbar_fontsize, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1512 // the amount of shots missed or damage wasted
1513 drawstringright(pos + '4.5 0 0' * sbar_fontsize_x + '0 9 0' * sbar_fontsize_y, ftos(max(0, weapon_damage - weapon_hit)), sbar_fontsize, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);