]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/scoreboard.qc
The PanelHud. Now in Xonotic git.
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / scoreboard.qc
1 float sb_alpha_bg;
2 float sb_alpha_fg;
3 float sb_highlight;
4 float sb_highlight_alpha;
5 float sb_highlight_alpha_self;
6 float sb_alpha_name;
7 float sb_alpha_name_self;
8
9 void drawstringright(vector, string, vector, vector, float, float);
10 void drawstringcenter(vector, string, vector, vector, float, float);
11
12 float SCOREBOARD_OFFSET = 50;
13
14 void MapVote_Draw();
15 void Sbar_FinaleOverlay()
16 {
17         /*vector pos;
18         pos_x = (vid_conwidth - 1)/2;
19         pos_y = 16;
20         pos_z = 0;*/
21
22         //drawpic(pos, "gfx/finale", '0 0 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
23
24         //drawstring(pos, "END", sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
25         MapVote_Draw();
26 }
27
28 void Sbar_DrawXNum (vector pos, float num, float digits, float showminusplus, float lettersize, vector rgb, float highlighted, float stroke, float alpha, float dflags)
29 {
30         float l, i;
31         string str, tmp, l_length;
32         float minus, plus;
33         vector vsize, num_color;
34
35         vsize_x = vsize_y = lettersize;
36         vsize_z = 0;
37
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)
41
42         if((showminusplus == 2 && num >= 0) || (num > 0 && showminusplus == 3))
43         {
44                 plus = true;
45                 pos_x -= lettersize;
46         } else
47                 plus = false;
48
49         if(num < 0 || (num < 0 && showminusplus == 3) || (showminusplus == 1 && num <= 0))
50         {
51                 minus = true;
52                 num = -num;
53                 pos_x -= lettersize;
54         } else
55                 minus = false;
56
57         if(digits < 0)
58         {
59                 tmp = ftos(num);
60                 digits = -digits;
61                 str = strcat(substring("0000000000", 0, digits - strlen(tmp)), tmp);
62         } else
63                 str = ftos(num);
64
65         l = strlen(str);
66         l_length = ftos(l);
67
68         if(l > digits)
69         {
70                 str = substring(str, l-digits, 999);
71                 l = strlen(str);
72         } else if(l < digits)
73                 pos_x += (digits-l) * lettersize;
74
75         if (highlighted == 1) {
76                 vector hl_size;
77                 hl_size_x = vsize_x * l + vsize_x * 0.2;
78                 hl_size_y = vsize_y * 1.1;
79                 hl_size_z = 0;
80                 if(minus)
81                         hl_size_x = hl_size_x + vsize_x;
82
83                 vector hl_pos;
84                 hl_pos_x = pos_x - lettersize/10;
85                 hl_pos_y = pos_y - lettersize/20;
86                 hl_pos_z = 0;
87
88                 drawpic(hl_pos, strcat("gfx/hud/sb_highlight_", l_length), hl_size, '1 1 1', alpha, dflags);
89         }
90
91         if (stroke == 1)
92                 num_color = '1 1 1';
93         else
94                 num_color = rgb;
95
96         if(minus)
97         {
98                 if (stroke == 1)
99                         drawpic(pos, "gfx/hud/num_minus_stroke", vsize, rgb, alpha, dflags);
100                 drawpic(pos, "gfx/hud/num_minus", vsize, num_color, alpha, dflags);
101                 pos_x += lettersize;
102         } else if(plus)
103         {
104                 if (stroke == 1)
105                         drawpic(pos, "gfx/hud/num_plus_stroke", vsize, rgb, alpha, dflags);
106                 drawpic(pos, "gfx/hud/num_plus", vsize, num_color, alpha, dflags);
107                 pos_x += lettersize;
108         }
109
110         for(i = 0; i < l; ++i)
111         {
112                 tmp = substring(str, i, 1);
113                 if (stroke == 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);
116                 pos_x += lettersize;
117         }
118 }
119
120 void Cmd_Sbar_SetFields(float argc);
121 void Sbar_InitScores()
122 {
123         float i, f;
124
125         ps_primary = ps_secondary = ts_primary = ts_secondary = -1;
126         for(i = 0; i < MAX_SCORE; ++i)
127         {
128                 f = (scores_flags[i] & SFL_SORT_PRIO_MASK);
129                 if(f == SFL_SORT_PRIO_PRIMARY)
130                         ps_primary = i;
131                 if(f == SFL_SORT_PRIO_SECONDARY)
132                         ps_secondary = i;
133         }
134         if(ps_secondary == -1)
135                 ps_secondary = ps_primary;
136
137         for(i = 0; i < MAX_TEAMSCORE; ++i)
138         {
139                 f = (teamscores_flags[i] & SFL_SORT_PRIO_MASK);
140                 if(f == SFL_SORT_PRIO_PRIMARY)
141                         ts_primary = i;
142                 if(f == SFL_SORT_PRIO_SECONDARY)
143                         ts_secondary = i;
144         }
145         if(ts_secondary == -1)
146                 ts_secondary = ts_primary;
147
148         Cmd_Sbar_SetFields(0);
149 }
150
151 void Sbar_UpdatePlayerPos(entity pl);
152 float SetTeam(entity pl, float Team);
153 //float lastpnum;
154 void Sbar_UpdatePlayerTeams()
155 {
156         float Team;
157         entity pl, tmp;
158         float num;
159
160         num = 0;
161         for(pl = players.sort_next; pl; pl = pl.sort_next)
162         {
163                 num += 1;
164                 Team = GetPlayerColor(pl.sv_entnum);
165                 if(SetTeam(pl, Team))
166                 {
167                         tmp = pl.sort_prev;
168                         Sbar_UpdatePlayerPos(pl);
169                         if(tmp)
170                                 pl = tmp;
171                         else
172                                 pl = players.sort_next;
173                 }
174         }
175         /*
176         if(num != lastpnum)
177                 print(strcat("PNUM: ", ftos(num), "\n"));
178         lastpnum = num;
179         */
180 }
181
182 float Sbar_ComparePlayerScores(entity left, entity right)
183 {
184         float vl, vr;
185         vl = GetPlayerColor(left.sv_entnum);
186         vr = GetPlayerColor(right.sv_entnum);
187
188         if(!left.gotscores)
189                 vl = COLOR_SPECTATOR;
190         if(!right.gotscores)
191                 vr = COLOR_SPECTATOR;
192
193         if(vl > vr)
194                 return true;
195         if(vl < vr)
196                 return false;
197
198         if(vl == COLOR_SPECTATOR)
199         {
200                 // FIRST the one with scores (spectators), THEN the ones without (downloaders)
201                 // no other sorting
202                 if(!left.gotscores && right.gotscores)
203                         return true;
204                 return false;
205         }
206
207         vl = left.scores[ps_primary];
208         vr = right.scores[ps_primary];
209         if(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)
210         {
211                 if(vl == 0 && vr != 0)
212                         return 1;
213                 if(vl != 0 && vr == 0)
214                         return 0;
215         }
216         if(vl > vr)
217                 return IS_INCREASING(scores_flags[ps_primary]);
218         if(vl < vr)
219                 return IS_DECREASING(scores_flags[ps_primary]);
220
221         vl = left.scores[ps_secondary];
222         vr = right.scores[ps_secondary];
223         if(scores_flags[ps_secondary] & SFL_ZERO_IS_WORST)
224         {
225                 if(vl == 0 && vr != 0)
226                         return 1;
227                 if(vl != 0 && vr == 0)
228                         return 0;
229         }
230         if(vl > vr)
231                 return IS_INCREASING(scores_flags[ps_secondary]);
232         if(vl < vr)
233                 return IS_DECREASING(scores_flags[ps_secondary]);
234
235         return false;
236 }
237
238 void Sbar_UpdatePlayerPos(entity player)
239 {
240         for(other = player.sort_next; other && Sbar_ComparePlayerScores(player, other); other = player.sort_next)
241         {
242                 SORT_SWAP(player, other);
243         }
244         for(other = player.sort_prev; other != players && Sbar_ComparePlayerScores(other, player); other = player.sort_prev)
245         {
246                 SORT_SWAP(other, player);
247         }
248 }
249
250 float Sbar_CompareTeamScores(entity left, entity right)
251 {
252         float vl, vr;
253
254         if(left.team == COLOR_SPECTATOR)
255                 return 1;
256         if(right.team == COLOR_SPECTATOR)
257                 return 0;
258
259         vl = left.teamscores[ts_primary];
260         vr = right.teamscores[ts_primary];
261         if(vl > vr)
262                 return IS_INCREASING(teamscores_flags[ts_primary]);
263         if(vl < vr)
264                 return IS_DECREASING(teamscores_flags[ts_primary]);
265
266         vl = left.teamscores[ts_secondary];
267         vr = right.teamscores[ts_secondary];
268         if(vl > vr)
269                 return IS_INCREASING(teamscores_flags[ts_secondary]);
270         if(vl < vr)
271                 return IS_DECREASING(teamscores_flags[ts_secondary]);
272
273         return false;
274 }
275
276 void Sbar_UpdateTeamPos(entity Team)
277 {
278         for(other = Team.sort_next; other && Sbar_CompareTeamScores(Team, other); other = Team.sort_next)
279         {
280                 SORT_SWAP(Team, other);
281         }
282         for(other = Team.sort_prev; other != teams && Sbar_CompareTeamScores(other, Team); other = Team.sort_prev)
283         {
284                 SORT_SWAP(other, Team);
285         }
286 }
287
288 void Cmd_Sbar_Help(float argc)
289 {
290         print("You can modify the scoreboard using the ^2sbar_columns_set command.\n");
291         print("^3|---------------------------------------------------------------|\n");
292         print("Usage:\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");
297
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");
323
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");
328
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");
331
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");
337 }
338
339 string Sbar_DefaultColumnLayout()
340 {
341         return strcat( // fteqcc sucks
342                 "ping pl name | ",
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");
350 }
351
352 void Cmd_Sbar_SetFields(float argc)
353 {
354         float i, j, slash;
355         string str, pattern;
356         float have_name, have_primary, have_secondary, have_separator;
357         float missing;
358
359         // TODO: re enable with gametype dependant cvars?
360         if(argc < 2) // no arguments provided
361                 argc = tokenizebyseparator(strcat("x ", cvar_string("sbar_columns")), " ");
362
363         if(argc < 2)
364                 argc = tokenizebyseparator(strcat("x ", Sbar_DefaultColumnLayout()), " ");
365
366         if(argc == 2)
367         {
368                 if(argv(1) == "default")
369                         argc = tokenizebyseparator(strcat("x ", Sbar_DefaultColumnLayout()), " ");
370                 else if(argv(1) == "all")
371                 {
372                         string s;
373                         s = "ping pl color name |";
374                         for(i = 0; i < MAX_SCORE; ++i)
375                         {
376                                 if(i != ps_primary)
377                                 if(i != ps_secondary)
378                                 if(scores_label[i] != "")
379                                         s = strcat(s, " ", scores_label[i]);
380                         }
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), " ");
385                 }
386         }
387
388
389         sbar_num_fields = 0;
390
391         drawfont = sbar_font;
392
393         for(i = 0; i < argc - 1; ++i)
394         {
395                 float nocomplain;
396                 str = argv(i+1);
397
398                 nocomplain = FALSE;
399                 if(substring(str, 0, 1) == "?")
400                 {
401                         nocomplain = TRUE;
402                         str = substring(str, 1, strlen(str) - 1);
403                 }
404
405                 slash = strstrofs(str, "/", 0);
406                 if(slash >= 0)
407                 {
408                         pattern = substring(str, 0, slash);
409                         str = substring(str, slash + 1, strlen(str) - (slash + 1));
410
411                         if not(isGametypeInFilter(gametype, teamplay, pattern))
412                                 continue;
413                 }
414
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);
419
420                 if(str == "ping") {
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;
428                         have_name = 1;
429                 } else if(str == "|") {
430                         sbar_field[sbar_num_fields] = SP_SEPARATOR;
431                         have_separator = 1;
432                 } else {
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"
436 :notfound
437                         if(str == "frags")
438                         {
439                                 j = SP_FRAGS;
440                         }
441                         else
442                         {
443                                 if not(nocomplain)
444                                         print(strcat("^1Error:^7 Unknown score field: '", str, "'\n"));
445                                 continue;
446                         }
447 :found
448                         sbar_field[sbar_num_fields] = j;
449                         if(j == ps_primary)
450                                 have_primary = 1;
451                         if(j == ps_secondary)
452                                 have_secondary = 1;
453                 }
454                 ++sbar_num_fields;
455                 if(sbar_num_fields >= MAX_SBAR_FIELDS)
456                         break;
457         }
458
459         if(scores_flags[ps_primary] & SFL_ALLOW_HIDE)
460                 have_primary = 1;
461         if(scores_flags[ps_secondary] & SFL_ALLOW_HIDE)
462                 have_secondary = 1;
463         if(ps_primary == ps_secondary)
464                 have_secondary = 1;
465         missing = (!have_primary) + (!have_secondary) + (!have_separator) + (!have_name);
466
467         if(sbar_num_fields+missing < MAX_SBAR_FIELDS)
468         {
469                 if(!have_name)
470                 {
471                         strunzone(sbar_title[sbar_num_fields]);
472                         for(i = sbar_num_fields; i > 0; --i)
473                         {
474                                 sbar_title[i] = sbar_title[i-1];
475                                 sbar_size[i] = sbar_size[i-1];
476                                 sbar_field[i] = sbar_field[i-1];
477                         }
478                         sbar_title[0] = strzone("name");
479                         sbar_field[0] = SP_NAME;
480                         ++sbar_num_fields;
481                         print("fixed missing field 'name'\n");
482
483                         if(!have_separator)
484                         {
485                                 strunzone(sbar_title[sbar_num_fields]);
486                                 for(i = sbar_num_fields; i > 1; --i)
487                                 {
488                                         sbar_title[i] = sbar_title[i-1];
489                                         sbar_size[i] = sbar_size[i-1];
490                                         sbar_field[i] = sbar_field[i-1];
491                                 }
492                                 sbar_title[1] = strzone("|");
493                                 sbar_field[1] = SP_SEPARATOR;
494                                 sbar_size[1] = stringwidth("|", FALSE, sbar_fontsize);
495                                 ++sbar_num_fields;
496                                 print("fixed missing field '|'\n");
497                         }
498                 }
499                 else if(!have_separator)
500                 {
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;
505                         ++sbar_num_fields;
506                         print("fixed missing field '|'\n");
507                 }
508                 if(!have_secondary)
509                 {
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;
514                         ++sbar_num_fields;
515                         print("fixed missing field '", scores_label[ps_secondary], "'\n");
516                 }
517                 if(!have_primary)
518                 {
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;
523                         ++sbar_num_fields;
524                         print("fixed missing field '", scores_label[ps_primary], "'\n");
525                 }
526         }
527
528         sbar_field[sbar_num_fields] = SP_END;
529 }
530
531 // MOVEUP::
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)
543 {
544         float tmp, num, denom, f;
545         string str;
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;
556         switch(field)
557         {
558                 case SP_PING:
559                         if not(pl.gotscores)
560                                 return "\x8D\x8D\x8D"; // >>> sign
561                         //str = getplayerkey(pl.sv_entnum, "ping");
562                         f = pl.ping;
563                         if(f == 0)
564                                 return "N/A";
565                         tmp = max(0, min(220, f-80)) / 220;
566                         sbar_field_rgb = '1 1 1' - '0 1 1'*tmp;
567                         return ftos(f);
568
569                 case SP_PL:
570                         if not(pl.gotscores)
571                                 return "N/A";
572                         f = pl.ping_packetloss;
573                         tmp = pl.ping_movementloss;
574                         if(f == 0 && tmp == 0)
575                                 return "";
576                         str = ftos(ceil(f * 100));
577                         if(tmp != 0)
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;
581                         return str;
582
583                 case SP_NAME:
584                         if(ready_waiting && pl.ready)
585                         {
586                                 sbar_field_icon0 = "gfx/sb_player_ready";
587                         }
588                         else if(!teamplay)
589                         {
590                                 f = stof(getplayerkey(pl.sv_entnum, "colors"));
591                                 {
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);
597                                 }
598                         }
599                         return GetPlayerName(pl.sv_entnum);
600
601                 case SP_FRAGS:
602                         f = pl.(scores[SP_KILLS]);
603                         f -= pl.(scores[SP_SUICIDES]);
604                         return ftos(f);
605
606                 case SP_KDRATIO:
607                         num = pl.(scores[SP_KILLS]);
608                         denom = pl.(scores[SP_DEATHS]);
609
610                         if(denom == 0) {
611                                 sbar_field_rgb = '0 1 0';
612                                 str = ftos(num);
613                         } else if(num <= 0) {
614                                 sbar_field_rgb = '1 0 0';
615                                 str = ftos(num/denom);
616                         } else
617                                 str = ftos(num/denom);
618
619                         tmp = strstrofs(str, ".", 0);
620                         if(tmp > 0)
621                                 str = substring(str, 0, tmp+2);
622                         return str;
623
624                 default:
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';
631                         else
632                                 sbar_field_rgb = '1 1 1';
633                         return ScoreString(f, tmp);
634         }
635         //return "error";
636 }
637
638 float xmin, xmax, ymin, ymax, sbwidth;
639 float sbar_fixscoreboardcolumnwidth_len;
640 float sbar_fixscoreboardcolumnwidth_iconlen;
641 float sbar_fixscoreboardcolumnwidth_marginlen;
642
643 string Sbar_FixScoreboardColumnWidth(float i, string str)
644 {
645         float field, f;
646         vector sz;
647         field = sbar_field[i];
648
649         sbar_fixscoreboardcolumnwidth_iconlen = 0;
650
651         if(sbar_field_icon0 != "")
652         {
653                 sz = drawgetimagesize(sbar_field_icon0);
654                 f = sz_x / sz_y;
655                 if(sbar_fixscoreboardcolumnwidth_iconlen < f)
656                         sbar_fixscoreboardcolumnwidth_iconlen = f;
657         }
658
659         if(sbar_field_icon1 != "")
660         {
661                 sz = drawgetimagesize(sbar_field_icon1);
662                 f = sz_x / sz_y;
663                 if(sbar_fixscoreboardcolumnwidth_iconlen < f)
664                         sbar_fixscoreboardcolumnwidth_iconlen = f;
665         }
666
667         if(sbar_field_icon2 != "")
668         {
669                 sz = drawgetimagesize(sbar_field_icon2);
670                 f = sz_x / sz_y;
671                 if(sbar_fixscoreboardcolumnwidth_iconlen < f)
672                         sbar_fixscoreboardcolumnwidth_iconlen = f;
673         }
674
675         sbar_fixscoreboardcolumnwidth_iconlen *= sbar_fontsize_y / sbar_fontsize_x; // fix icon aspect
676
677         if(sbar_fixscoreboardcolumnwidth_iconlen != 0)
678                 sbar_fixscoreboardcolumnwidth_marginlen = stringwidth(" ", FALSE, sbar_fontsize);
679         else
680                 sbar_fixscoreboardcolumnwidth_marginlen = 0;
681
682         if(field == SP_NAME) // name gets all remaining space
683         {
684                 float namesize, j;
685                 namesize = sbwidth;// / sbar_fontsize_x;
686                 for(j = 0; j < sbar_num_fields; ++j)
687                         if(j != i)
688                                 if (sbar_field[i] != SP_SEPARATOR)
689                                         namesize -= sbar_size[j] + 1;
690                 namesize += 1;
691                 sbar_size[i] = namesize;
692
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);
697         }
698         else
699                 sbar_fixscoreboardcolumnwidth_len = stringwidth(str, FALSE, sbar_fontsize);
700
701         f = sbar_fixscoreboardcolumnwidth_len + sbar_fixscoreboardcolumnwidth_marginlen + sbar_fixscoreboardcolumnwidth_iconlen;
702         if(sbar_size[i] < f)
703                 sbar_size[i] = f;
704
705         return str;
706 }
707
708 void Sbar_PrintScoreboardItem(vector pos, entity pl, float is_self, float pl_number)
709 {
710         vector tmp, rgb;
711         rgb = GetTeamRGB(pl.team);
712         string str;
713         float i, field;
714         float is_spec;
715         is_spec = (GetPlayerColor(pl.sv_entnum) == COLOR_SPECTATOR);
716
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; }
721
722         // Layout:
723         tmp_x = sbwidth;
724         tmp_y = sbar_fontsize_y * 1.25;
725         tmp_z = 0;
726
727         // alternated rows highlighting
728         if(is_self)
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);
732
733         tmp_y = 0;
734
735         for(i = 0; i < sbar_num_fields; ++i)
736         {
737                 field = sbar_field[i];
738                 if(field == SP_SEPARATOR)
739                         break;
740
741                 if(is_spec && field != SP_NAME && field != SP_PING) {
742                         pos_x += sbar_size[i] + sbar_fontsize_x;
743                         continue;
744                 }
745                 str = Sbar_GetField(pl, field);
746                 str = Sbar_FixScoreboardColumnWidth(i, str);
747
748                 pos_x += sbar_size[i] + sbar_fontsize_x;
749
750                 if(field == SP_NAME) {
751                         tmp_x = sbar_size[i] - sbar_fontsize_x*sbar_fixscoreboardcolumnwidth_iconlen - sbar_fixscoreboardcolumnwidth_marginlen + sbar_fontsize_x;
752                         if (is_self)
753                                 drawcolorcodedstring(pos - tmp, str, sbar_fontsize, sb_alpha_name_self, DRAWFLAG_NORMAL);
754                         else
755                                 drawcolorcodedstring(pos - tmp, str, sbar_fontsize, sb_alpha_name, DRAWFLAG_NORMAL);
756                 } else {
757                         tmp_x = sbar_fixscoreboardcolumnwidth_len + sbar_fontsize_x;
758                         if (is_self)
759                                 drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, sb_alpha_name_self, DRAWFLAG_NORMAL);
760                         else
761                                 drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, sb_alpha_name, DRAWFLAG_NORMAL);
762                 }
763
764                 tmp_x = sbar_size[i] + sbar_fontsize_x;
765                 if(sbar_field_icon0 != "")
766                         if (is_self)
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);
768                         else
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 != "")
771                         if (is_self)
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);
773                         else
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 != "")
776                         if (is_self)
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);
778                         else
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);
780         }
781
782         if(sbar_field[i] == SP_SEPARATOR)
783         {
784                 pos_x = xmax;
785                 for(i = sbar_num_fields-1; i > 0; --i)
786                 {
787                         field = sbar_field[i];
788                         if(field == SP_SEPARATOR)
789                                 break;
790
791                         if(is_spec && field != SP_NAME && field != SP_PING) {
792                                 pos_x -= sbar_size[i] + sbar_fontsize_x;
793                                 continue;
794                         }
795
796                         str = Sbar_GetField(pl, field);
797                         str = Sbar_FixScoreboardColumnWidth(i, str);
798
799                         if(field == SP_NAME) {
800                                 tmp_x = sbar_fixscoreboardcolumnwidth_len; // left or right aligned? let's put it right...
801                                 if(is_self)
802                                         drawcolorcodedstring(pos - tmp, str, sbar_fontsize, sb_alpha_name_self, DRAWFLAG_NORMAL);
803                                 else
804                                         drawcolorcodedstring(pos - tmp, str, sbar_fontsize, sb_alpha_name, DRAWFLAG_NORMAL);
805                         } else {
806                                 tmp_x = sbar_fixscoreboardcolumnwidth_len;
807                                 if(is_self)
808                                         drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, sb_alpha_name_self, DRAWFLAG_NORMAL);
809                                 else
810                                         drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, sb_alpha_name, DRAWFLAG_NORMAL);
811                         }
812
813                         tmp_x = sbar_size[i];
814                         if(sbar_field_icon0 != "")
815                                 if (is_self)
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);
817                                 else
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 != "")
820                                 if (is_self)
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);
822                                 else
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 != "")
825                                 if (is_self)
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);
827                                 else
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;
830                 }
831         }
832 }
833
834 /*
835  * Sbar_Scoreboard_MakeTable
836  *
837  * Makes a table for a team (for all playing players in DM) and fills it
838  */
839
840 vector Sbar_Scoreboard_MakeTable(vector pos, entity tm, vector rgb, vector bg_size)
841 {
842         float body_table_height, i;
843         vector tmp, column_dim;
844         entity pl;
845
846         body_table_height = 1.25 * sbar_fontsize_y * max(1, tm.team_size); // no player? show 1 empty line
847
848         pos -= '1 1 0';
849
850         tmp_x = sbwidth + 2;
851         tmp_y = 1.25 * sbar_fontsize_y;
852
853         // rounded header
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);
855
856         // table border
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
860
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);
865
866         pos_y += hud_border_thickness;
867
868         // table background
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);
871
872         // anyway, apply some color
873         //drawfill(pos, tmp + '2 0 0', rgb, 0.1, DRAWFLAG_NORMAL);
874
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;
878
879         pos += '1 1 0';
880
881         if (sb_highlight)
882         {
883                 column_dim_y = 1.25 * sbar_fontsize_y; // header
884                 column_dim_y += hud_border_thickness;
885                 column_dim_y += body_table_height;
886         }
887
888         // print the strings of the columns headers and draw the columns
889         for(i = 0; i < sbar_num_fields; ++i)
890         {
891                 if(sbar_field[i] == SP_SEPARATOR)
892                         break;
893                 column_dim_x = sbar_size[i] + sbar_fontsize_x;
894                 if (sb_highlight)
895                 {
896                         if (mod(i,2))
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);
898                 }
899                 drawstring(pos, sbar_title[i], sbar_fontsize, rgb * 1.5, sb_alpha_fg, DRAWFLAG_NORMAL);
900                 pos_x += column_dim_x;
901         }
902         if(sbar_field[i] == SP_SEPARATOR)
903         {
904                 pos_x = xmax;
905                 tmp_y = 0;
906                 for(i = sbar_num_fields-1; i > 0; --i)
907                 {
908                         if(sbar_field[i] == SP_SEPARATOR)
909                                 break;
910
911                         pos_x -= sbar_size[i];
912
913                         if (sb_highlight)
914                         {
915                                 if (!mod(i,2))
916                                 {
917                                         if (i == sbar_num_fields-1)
918                                                 column_dim_x = sbar_size[i] + sbar_fontsize_x / 2 + 1;
919                                         else
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);
922                                 }
923                         }
924
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;
929                 }
930         }
931
932         pos_x = xmin;
933         pos_y += 1.25 * sbar_fontsize_y; // skip the header
934         pos_y += hud_border_thickness;
935
936         // fill the table and draw the rows
937         i = 0;
938         if (teamplay)
939                 for(pl = players.sort_next; pl; pl = pl.sort_next)
940                 {
941                         if(pl.team != tm.team)
942                                 continue;
943                         Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1), i);
944                         pos_y += 1.25 * sbar_fontsize_y;
945                         ++i;
946                 }
947         else
948                 for(pl = players.sort_next; pl; pl = pl.sort_next)
949                 {
950                         if(pl.team == COLOR_SPECTATOR)
951                                 continue;
952                         Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1), i);
953                         pos_y += 1.25 * sbar_fontsize_y;
954                         ++i;
955                 }
956
957         if (i == 0)
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)
960
961         return pos;
962 }
963
964 float Sbar_WouldDrawScoreboard() {
965         if (sb_showscores)
966                 return 1;
967         else if (intermission == 1)
968                 return 1;
969         else if (intermission == 2)
970                 return 1;
971         else if (getstati(STAT_HEALTH) <= 0 && cvar("cl_deathscoreboard"))
972                 return 1;
973         else if(sb_showscores_force)
974                 return 1;
975         return 0;
976 }
977
978 float g_minstagib;
979 float average_accuracy;
980 vector Sbar_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size)
981 {
982         float i;
983         float weapon_hit, weapon_damage, weapon_stats;
984         float fontsize = 40 * 1/3;
985         float weapon_cnt = 12;
986         float rows;
987         if(cvar("sbar_accuracy_doublerows"))
988                 rows = 2;
989         else
990                 rows = 1;
991         float height = 40;
992
993         if(warmup_stage)
994         {
995                 return pos;
996         }
997
998         drawstring(pos, strcat("Accuracy stats (average ", ftos(average_accuracy), "%)"), sbar_fontsize, '1 1 1', sb_alpha_fg, DRAWFLAG_NORMAL);
999         pos_y += 18;
1000         vector tmp;
1001         tmp_x = sbwidth;
1002         tmp_y = height * rows;
1003
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);
1006
1007         // column highlighting
1008         for(i = 0; i < weapon_cnt/rows; ++i)
1009         {
1010                 if(!mod(i, 2))
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);
1012         }
1013
1014         // row highlighting
1015         for(i = 0; i < rows; ++i)
1016         {
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);
1018         }
1019
1020         drawfont = sbar_bigfont;
1021         average_accuracy = 0;
1022         float weapons_with_stats;
1023         weapons_with_stats = 0;
1024         if(rows == 2)
1025                 pos_x += sbwidth/weapon_cnt / 2;
1026
1027         if(getstati(STAT_SWITCHWEAPON) == WEP_MINSTANEX)
1028                 g_minstagib = 1; // TODO: real detection for minstagib?
1029
1030         for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1031         {
1032                 self = get_weaponinfo(i);
1033                 if not(self.weapons)
1034                         continue;
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
1036                         continue;
1037                 weapon_hit = weapon_hits[i-WEP_FIRST];
1038                 weapon_damage = weapon_fired[i-WEP_FIRST];
1039                 if(weapon_damage)
1040                         weapon_stats = bound(0, floor(100 * weapon_hit / weapon_damage), 100);
1041                 float weapon_alpha;
1042
1043                 if(weapon_damage)
1044                         weapon_alpha = sb_alpha_fg;
1045                 else
1046                         weapon_alpha = 0.2 * sb_alpha_fg;
1047
1048                 // weapon icon
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);
1050                 // the accuracy
1051                 if(weapon_damage) {
1052                         weapons_with_stats += 1;
1053                         average_accuracy += weapon_stats; // store sum of all accuracies in average_accuracy
1054
1055                         string s;
1056                         s = strcat(ftos(weapon_stats),"%");
1057
1058                         float padding;
1059                         padding = ((sbwidth/weapon_cnt) - stringwidth(s, FALSE, '1 0 0' * fontsize)) / 2; // center the accuracy value
1060
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);
1063                 }
1064                 pos_x += sbwidth/weapon_cnt * rows;
1065                 if(rows == 2 && i == 6) {
1066                         pos_x -= sbwidth;
1067                         pos_y += height;
1068                 }
1069         }
1070         drawfont = sbar_font;
1071
1072         if(weapons_with_stats)
1073                 average_accuracy = floor(average_accuracy / weapons_with_stats);
1074
1075         if(rows == 2)
1076                 pos_x -= sbwidth/weapon_cnt / 2;
1077         pos_x -= sbwidth;
1078         pos_y += height;
1079         return pos;
1080 }
1081
1082 vector Sbar_DrawScoreboardRankings(vector pos, entity pl,  vector rgb, vector bg_size)
1083 {
1084         float i;
1085         RANKINGS_RECEIVED_CNT = 0;
1086                 for (i=RANKINGS_CNT-1; i>=0; --i)
1087                         if (grecordtime[i])
1088                                 RANKINGS_RECEIVED_CNT = RANKINGS_RECEIVED_CNT + 1;
1089
1090         if (RANKINGS_RECEIVED_CNT == 0)
1091                 return pos;
1092
1093         float is_spec;
1094         is_spec = (GetPlayerColor(pl.sv_entnum) == COLOR_SPECTATOR);
1095         vector hl_rgb;
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;
1099
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;
1103         vector tmp;
1104         tmp_x = sbwidth;
1105         tmp_y = sbar_fontsize_y * RANKINGS_RECEIVED_CNT;
1106
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);
1109
1110         // row highlighting
1111         for(i = 0; i<RANKINGS_RECEIVED_CNT; ++i)
1112         {
1113                 string n, p;
1114                 float t;
1115                 t = grecordtime[i];
1116                 if (t == 0)
1117                         continue;
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;
1128         }
1129
1130         return pos;
1131 }
1132
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()
1137 {
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;
1143         }
1144
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);
1150                 else
1151                         sb_fade_alpha = 1;
1152         }
1153         else
1154                 if (scoreboard_fadeoutspeed)
1155                         sb_fade_alpha = bound (0, (1/scoreboard_fadeoutspeed - (time - sbar_woulddrawscoreboard_change)) * scoreboard_fadeoutspeed, 1);
1156                 else
1157                         sb_fade_alpha = 0;
1158
1159         if not(sb_fade_alpha)
1160                 return;
1161
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;
1169
1170         vector rgb, pos, tmp;
1171         entity pl, tm;
1172
1173         sbwidth = Sbar_GetWidth(6.5 * sbar_fontsize_y);
1174
1175         xmin = 0.5 * (vid_conwidth - sbwidth);
1176         ymin = SCOREBOARD_OFFSET;
1177
1178         xmax = vid_conwidth - xmin;
1179         ymax = vid_conheight - 0.2*vid_conheight;
1180
1181         // Initializes position
1182         pos_x = xmin;
1183         pos_y = ymin;
1184         pos_z = 0;
1185
1186         // Heading
1187         drawfont = sbar_bigfont;
1188         drawstringcenter('0 1 0' * ymin, "Scoreboard", '24 24 0', '1 1 1', sb_alpha_fg, DRAWFLAG_NORMAL);
1189
1190         pos_y += 24 + 4;
1191         pos_y += sbar_fontsize_y;
1192
1193         drawfont = sbar_font;
1194
1195         // Draw the scoreboard
1196         vector bg_size;
1197         bg_size = drawgetimagesize("gfx/hud/sb_scoreboard_bg");
1198
1199         if(teamplay)
1200         {
1201                 for(tm = teams.sort_next; tm; tm = tm.sort_next)
1202                 {
1203                         if(tm.team == COLOR_SPECTATOR)
1204                                 continue;
1205
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);
1208
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);
1211
1212                         pos = Sbar_Scoreboard_MakeTable(pos, tm, rgb, bg_size);
1213                 }
1214         }
1215         else
1216         {
1217                 rgb_x = cvar("sbar_color_bg_r");
1218                 rgb_y = cvar("sbar_color_bg_g");
1219                 rgb_z = cvar("sbar_color_bg_b");
1220
1221                 for(tm = teams.sort_next; tm; tm = tm.sort_next)
1222                 {
1223                         if(tm.team == COLOR_SPECTATOR)
1224                                 continue;
1225
1226                         pos = Sbar_Scoreboard_MakeTable(pos, tm, rgb, bg_size);
1227                 }
1228         }
1229
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;
1234                 }
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;
1238                 }
1239                 pos = Sbar_DrawScoreboardRankings(pos, pl, rgb, bg_size);
1240         }
1241         else if(cvar("sbar_accuracy") && spectatee_status != -1) {
1242                 if(teamplay)
1243                         pos = Sbar_DrawScoreboardAccuracyStats(pos, GetTeamRGB(myteam), bg_size);
1244                 else
1245                         pos = Sbar_DrawScoreboardAccuracyStats(pos, rgb, bg_size);
1246         }
1247
1248         tmp = pos + '0 1.5 0' * sbar_fontsize_y;
1249         pos_y += 3 * sbar_fontsize_y;
1250
1251         // List spectators
1252         float specs;
1253         specs = 0;
1254         for(pl = players.sort_next; pl; pl = pl.sort_next)
1255         {
1256                 if(pl.team != COLOR_SPECTATOR)
1257                         continue;
1258                 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1), specs);
1259                 pos_y += 1.25 * sbar_fontsize_y;
1260                 ++specs;
1261         }
1262
1263         if(specs)
1264                 drawstring(tmp, "Spectators", sbar_fontsize, '1 1 1', sb_alpha_fg, DRAWFLAG_NORMAL);
1265
1266         // Print info string
1267         string str;
1268         float tl, fl, ll;
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)
1274         {
1275                 if(tl > 0)
1276                         str = strcat(str, " for up to ^1", ftos(tl), " minutes^7");
1277         }
1278         else
1279         {
1280                 if(tl > 0)
1281                         str = strcat(str, " for ^1", ftos(tl), " minutes^7");
1282                 if(fl > 0)
1283                 {
1284                         if(tl > 0)
1285                                 str = strcat(str, " or");
1286                         if(teamplay)
1287                         {
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");
1293                                 else
1294                                         str = strcat(str, " ", teamscores_label[ts_primary]);
1295                         }
1296                         else
1297                         {
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");
1303                                 else
1304                                         str = strcat(str, " ", scores_label[ps_primary]);
1305                         }
1306                 }
1307                 if(ll > 0)
1308                 {
1309                         if(tl > 0 || fl > 0)
1310                                 str = strcat(str, " or");
1311                         if(teamplay)
1312                         {
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");
1318                                 else
1319                                         str = strcat(str, " ", teamscores_label[ts_primary]);
1320                         }
1321                         else
1322                         {
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");
1328                                 else
1329                                         str = strcat(str, " ", scores_label[ps_primary]);
1330                         }
1331                 }
1332         }
1333
1334
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);
1337
1338         scoreboard_bottom = pos_y + 2 * sbar_fontsize_y;
1339 }
1340
1341 void Sbar_DrawAccuracyStats_Description_Hitscan(vector position)
1342 {
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);
1347 }
1348
1349 void Sbar_DrawAccuracyStats_Description_Splash(vector position)
1350 {
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);
1355 }
1356
1357 void Sbar_DrawAccuracyStats()
1358 {
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;
1363         vector pos;
1364         vector border_colour;
1365
1366         float col_margin = 20;  // pixels between the columns
1367         float row_margin = 20;  // pixels between the rows
1368
1369         fill_size_x = 5 * sbar_fontsize_x;  // width of the background
1370         fill_size_y = 10 * sbar_fontsize_y;  // height of the background
1371
1372         drawfont = sbar_bigfont;
1373         pos_x = 0;
1374         pos_y = SCOREBOARD_OFFSET;
1375         pos_z = 0;
1376         drawstringcenter(pos, "Weapon Accuracy", 2 * sbar_fontsize, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1377
1378         left_border = col_margin + 11 * sbar_fontsize_x;
1379
1380         drawfont = sbar_font;
1381
1382         if(warmup_stage)
1383         {
1384                 pos_y += 40;
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);
1387
1388                 return;
1389         }
1390
1391         if(gametype == GAME_RACE || gametype == GAME_CTS)
1392         {
1393                 pos_y += 40;
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);
1396
1397                 return;
1398         }
1399
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);
1402
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);
1405
1406         for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1407         {
1408                 self = get_weaponinfo(i);
1409                 if not(self.weapons)
1410                         continue;
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
1414
1415                 if (weapon_damage) {
1416                         if (self.spawnflags & WEP_TYPE_SPLASH) {
1417                                 weapon_stats = bound(0, floor(100 * weapon_hit / weapon_damage), 100);
1418
1419                                 fill_colour_x = 1 - 0.015 * weapon_stats;
1420                                 fill_colour_y = 1 - 0.015 * (100 - weapon_stats);
1421
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
1435
1436                                 if ((left_border + count_splash * (fill_size_x + col_margin) + fill_size_x) >= vid_conwidth)
1437                                 {
1438                                         count_splash = 0;
1439                                         ++row;
1440                                         Sbar_DrawAccuracyStats_Description_Splash('1 0 0' * col_margin + '0 1 0' * (top_border_splash + row * (fill_size_y + row_margin)));
1441                                 }
1442
1443                                 pos_x = left_border + count_splash * (fill_size_x + col_margin);
1444                                 pos_y = top_border_splash + row * (fill_size_y + row_margin);
1445
1446                                 // background
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);
1449
1450                                 // the weapon
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);
1452
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);
1455
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);
1458
1459                                 // the accuracy
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);
1461
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);
1464
1465                                 ++count_splash;
1466                         } else if (self.spawnflags & WEP_TYPE_HITSCAN) {
1467                                 weapon_stats = bound(0, floor(100 * weapon_hit / weapon_damage), 100);
1468
1469                                 fill_colour_x = 1 - 0.015 * weapon_stats;
1470                                 fill_colour_y = 1 - 0.015 * (100 - weapon_stats);
1471
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
1485
1486                                 if ((left_border + count_hitscan * (fill_size_x + col_margin) + fill_size_x + cvar("stats_right_margin")) >= vid_conwidth)
1487                                 {
1488                                         count_hitscan = 0;
1489                                         ++row;
1490                                         Sbar_DrawAccuracyStats_Description_Hitscan('1 0 0' * col_margin + '0 1 0' * (top_border_hitscan + row * (fill_size_y + row_margin)));
1491                                 }
1492
1493                                 pos_x = left_border + count_hitscan * (fill_size_x + col_margin);
1494                                 pos_y = top_border_hitscan + row * (fill_size_y + row_margin);
1495
1496                                 // background
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);
1499
1500                                 // the weapon
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);
1502
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);
1505
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);
1508
1509                                 // the accuracy
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);
1511
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);
1514
1515                                 ++count_hitscan;
1516                         }
1517                 }
1518         }
1519 }