Some tweaks to show-minus-plus
[voretournament/voretournament.git] / data / qcsrc / client / sbar.qc
1 void drawstringright(vector, string, vector, vector, float, float);\r
2 void drawstringcenter(vector, string, vector, vector, float, float);\r
3 \r
4 float teamnagger;\r
5 \r
6 float weapon_hits[WEP_MAXCOUNT];\r
7 float weapon_fired[WEP_MAXCOUNT];\r
8 float weapon_number;\r
9 \r
10 float last_weapon;\r
11 float weapontime;\r
12 \r
13 float sbar_alpha_fg;\r
14 float sbar_alpha_bg;\r
15 float sbar_color_bg_team;\r
16 float sbar_border_thickness;\r
17 float sbar_accuracy_border_thickness;\r
18 float sbar_scoreboard_alpha_bg;\r
19 float sbar_scoreboard_alpha_fg;\r
20 float sbar_scoreboard_highlight;\r
21 float sbar_scoreboard_highlight_alpha;\r
22 float sbar_scoreboard_highlight_alpha_self;\r
23 float sbar_hudselector;\r
24 float sbar_accuracy_hud;\r
25 float sbar_scoreboard_alpha_name;\r
26 float sbar_scoreboard_alpha_name_self;\r
27 \r
28 float ps_primary, ps_secondary;\r
29 float ts_primary, ts_secondary;\r
30 \r
31 vector color;\r
32 \r
33 void CSQC_kh_hudreset();\r
34 void CSQC_kh_hud();\r
35 void CSQC_ctf_hudreset();\r
36 void CSQC_ctf_hud();\r
37 void CSQC_race_hud();\r
38 void MapVote_Draw();\r
39 void Sbar_FinaleOverlay()\r
40 {\r
41         /*vector pos;\r
42         pos_x = (vid_conwidth - 1)/2;\r
43         pos_y = 16;\r
44         pos_z = 0;*/\r
45 \r
46         //drawpic(pos, "gfx/finale", '0 0 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
47 \r
48         //drawstring(pos, "END", sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);\r
49         MapVote_Draw();\r
50 }\r
51 \r
52 vector Sbar_AccuracyColor(float accuracy)\r
53 {\r
54         vector rgb;\r
55         float yellow_accuracy = cvar("sbar_accuracy_yellow"); // value at which this function returns yellow\r
56         if(accuracy >= 100) {\r
57                 rgb_x = 0;\r
58                 rgb_y = 1;\r
59         }\r
60         else if(accuracy > yellow_accuracy) {\r
61                 rgb_x = 1 - (accuracy-yellow_accuracy)/(100-yellow_accuracy); // red value between 1 -> 0\r
62                 rgb_y = 1;\r
63         }\r
64         else {\r
65                 rgb_x = 1;\r
66                 rgb_y = accuracy/yellow_accuracy; // green value between 0 -> 1\r
67         }\r
68         rgb_z = 0;\r
69         return rgb;\r
70 }\r
71 \r
72 void Sbar_DrawXNum (vector pos, float num, float digits, float showminusplus, float lettersize, vector rgb, float alpha, float dflags)\r
73 {\r
74         float l;\r
75         string str, tmp, l_length, final_num;\r
76         float minus, plus;\r
77         vector vsize;\r
78 \r
79         vsize_x = vsize_y = lettersize;\r
80         vsize_z = 0;\r
81 \r
82         // showminusplus 1: always prefix with minus sign (useful in race distribution display)\r
83         // showminusplus 2: always prefix with plus sign (useful in race distribution display)\r
84         // showminusplus 3: prefix with minus sign if negative, plus sign if positive (useful in score distribution display)\r
85 \r
86         if((showminusplus == 2 && num >= 0) || (num > 0 && showminusplus == 3))\r
87         {\r
88                 plus = true;\r
89         } else\r
90                 plus = false;   \r
91 \r
92         if(num < 0 || (num < 0 && showminusplus == 3) || (showminusplus == 1 && num <= 0))\r
93         {\r
94                 minus = true;\r
95                 num = -num;\r
96         } else\r
97                 minus = false;\r
98 \r
99         if(digits < 0)\r
100         {\r
101                 tmp = ftos(num);\r
102                 digits = -digits;\r
103                 str = strcat(substring("0000000000", 0, digits - strlen(tmp)), tmp);\r
104         } else\r
105                 str = ftos(num);\r
106 \r
107         l = strlen(str);\r
108         l_length = ftos(l);\r
109 \r
110         if(l > digits)\r
111         {\r
112                 str = substring(str, l - digits, 999);\r
113                 l = strlen(str);\r
114         }\r
115 \r
116         if(minus)\r
117                 final_num = "-";\r
118         else if(plus)\r
119                 final_num = "+";\r
120 \r
121         final_num = strcat(final_num, str);\r
122         drawstring(pos, final_num, vsize, rgb, alpha, dflags);\r
123 }\r
124 \r
125 void Sbar_DrawXNum_Colored (vector pos, float x, float lettersize, float alpha)\r
126 {\r
127         if(x > 200) {\r
128                 color_x = 0;\r
129                 color_y = 1;\r
130                 color_z = 0;\r
131         }\r
132         else if(x > 150) {\r
133                 color_x = 0.4 - (x-150)*0.02 * 0.4; //red value between 0.4 -> 0\r
134                 color_y = 0.9 + (x-150)*0.02 * 0.1; // green value between 0.9 -> 1\r
135                 color_z = 0;\r
136         }\r
137         else if(x > 100) {\r
138                 color_x = 1 - (x-100)*0.02 * 0.6; //red value between 1 -> 0.4\r
139                 color_y = 1 - (x-100)*0.02 * 0.1; // green value between 1 -> 0.9\r
140                 color_z = 1 - (x-100)*0.02; // blue value between 1 -> 0\r
141         }\r
142         else if(x > 50) {\r
143                 color_x = 1;\r
144                 color_y = 1;\r
145                 color_z = 0.2 + (x-50)*0.02 * 0.8; // blue value between 0.2 -> 1\r
146         }\r
147         else if(x > 20) {\r
148                 color_x = 1;\r
149                 color_y = (x-20)*90/27/100; // green value between 0 -> 1\r
150                 color_z = (x-20)*90/27/100 * 0.2; // blue value between 0 -> 0.2\r
151         }\r
152         else {\r
153                 color_x = 1;\r
154                 color_y = 0;\r
155                 color_z = 0;\r
156         }\r
157         Sbar_DrawXNum(pos, x, 3, 0, lettersize, color, alpha, DRAWFLAG_NORMAL);\r
158 }\r
159 \r
160 void Cmd_Sbar_SetFields(float argc);\r
161 void Sbar_InitScores()\r
162 {\r
163         float i, f;\r
164 \r
165         ps_primary = ps_secondary = ts_primary = ts_secondary = -1;\r
166         for(i = 0; i < MAX_SCORE; ++i)\r
167         {\r
168                 f = (scores_flags[i] & SFL_SORT_PRIO_MASK);\r
169                 if(f == SFL_SORT_PRIO_PRIMARY)\r
170                         ps_primary = i;\r
171                 if(f == SFL_SORT_PRIO_SECONDARY)\r
172                         ps_secondary = i;\r
173         }\r
174         if(ps_secondary == -1)\r
175                 ps_secondary = ps_primary;\r
176 \r
177         for(i = 0; i < MAX_TEAMSCORE; ++i)\r
178         {\r
179                 f = (teamscores_flags[i] & SFL_SORT_PRIO_MASK);\r
180                 if(f == SFL_SORT_PRIO_PRIMARY)\r
181                         ts_primary = i;\r
182                 if(f == SFL_SORT_PRIO_SECONDARY)\r
183                         ts_secondary = i;\r
184         }\r
185         if(ts_secondary == -1)\r
186                 ts_secondary = ts_primary;\r
187 \r
188         Cmd_Sbar_SetFields(0);\r
189 }\r
190 \r
191 void Sbar_UpdatePlayerPos(entity pl);\r
192 float SetTeam(entity pl, float Team);\r
193 //float lastpnum;\r
194 void Sbar_UpdatePlayerTeams()\r
195 {\r
196         float Team;\r
197         entity pl, tmp;\r
198         float num;\r
199 \r
200         num = 0;\r
201         for(pl = players.sort_next; pl; pl = pl.sort_next)\r
202         {\r
203                 num += 1;\r
204                 Team = GetPlayerColor(pl.sv_entnum);\r
205                 if(SetTeam(pl, Team))\r
206                 {\r
207                         tmp = pl.sort_prev;\r
208                         Sbar_UpdatePlayerPos(pl);\r
209                         if(tmp)\r
210                                 pl = tmp;\r
211                         else\r
212                                 pl = players.sort_next;\r
213                 }\r
214         }\r
215         /*\r
216         if(num != lastpnum)\r
217                 print(strcat("PNUM: ", ftos(num), "\n"));\r
218         lastpnum = num;\r
219         */\r
220 }\r
221 \r
222 float Sbar_ComparePlayerScores(entity left, entity right)\r
223 {\r
224         float vl, vr;\r
225         vl = GetPlayerColor(left.sv_entnum);\r
226         vr = GetPlayerColor(right.sv_entnum);\r
227 \r
228         if(!left.gotscores)\r
229                 vl = COLOR_SPECTATOR;\r
230         if(!right.gotscores)\r
231                 vr = COLOR_SPECTATOR;\r
232 \r
233         if(vl > vr)\r
234                 return true;\r
235         if(vl < vr)\r
236                 return false;\r
237 \r
238         if(vl == COLOR_SPECTATOR)\r
239         {\r
240                 // FIRST the one with scores (spectators), THEN the ones without (downloaders)\r
241                 // no other sorting\r
242                 if(!left.gotscores && right.gotscores)\r
243                         return true;\r
244                 return false;\r
245         }\r
246 \r
247         vl = left.scores[ps_primary];\r
248         vr = right.scores[ps_primary];\r
249         if(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)\r
250         {\r
251                 if(vl == 0 && vr != 0)\r
252                         return 1;\r
253                 if(vl != 0 && vr == 0)\r
254                         return 0;\r
255         }\r
256         if(vl > vr)\r
257                 return IS_INCREASING(scores_flags[ps_primary]);\r
258         if(vl < vr)\r
259                 return IS_DECREASING(scores_flags[ps_primary]);\r
260 \r
261         vl = left.scores[ps_secondary];\r
262         vr = right.scores[ps_secondary];\r
263         if(scores_flags[ps_secondary] & SFL_ZERO_IS_WORST)\r
264         {\r
265                 if(vl == 0 && vr != 0)\r
266                         return 1;\r
267                 if(vl != 0 && vr == 0)\r
268                         return 0;\r
269         }\r
270         if(vl > vr)\r
271                 return IS_INCREASING(scores_flags[ps_secondary]);\r
272         if(vl < vr)\r
273                 return IS_DECREASING(scores_flags[ps_secondary]);\r
274 \r
275         return false;\r
276 }\r
277 \r
278 void Sbar_UpdatePlayerPos(entity player)\r
279 {\r
280         for(other = player.sort_next; other && Sbar_ComparePlayerScores(player, other); other = player.sort_next)\r
281         {\r
282                 SORT_SWAP(player, other);\r
283         }\r
284         for(other = player.sort_prev; other != players && Sbar_ComparePlayerScores(other, player); other = player.sort_prev)\r
285         {\r
286                 SORT_SWAP(other, player);\r
287         }\r
288 }\r
289 \r
290 float Sbar_CompareTeamScores(entity left, entity right)\r
291 {\r
292         float vl, vr;\r
293 \r
294         if(left.team == COLOR_SPECTATOR)\r
295                 return 1;\r
296         if(right.team == COLOR_SPECTATOR)\r
297                 return 0;\r
298 \r
299         vl = left.teamscores[ts_primary];\r
300         vr = right.teamscores[ts_primary];\r
301         if(vl > vr)\r
302                 return IS_INCREASING(teamscores_flags[ts_primary]);\r
303         if(vl < vr)\r
304                 return IS_DECREASING(teamscores_flags[ts_primary]);\r
305 \r
306         vl = left.teamscores[ts_secondary];\r
307         vr = right.teamscores[ts_secondary];\r
308         if(vl > vr)\r
309                 return IS_INCREASING(teamscores_flags[ts_secondary]);\r
310         if(vl < vr)\r
311                 return IS_DECREASING(teamscores_flags[ts_secondary]);\r
312 \r
313         return false;\r
314 }\r
315 \r
316 void Sbar_UpdateTeamPos(entity Team)\r
317 {\r
318         for(other = Team.sort_next; other && Sbar_CompareTeamScores(Team, other); other = Team.sort_next)\r
319         {\r
320                 SORT_SWAP(Team, other);\r
321         }\r
322         for(other = Team.sort_prev; other != teams && Sbar_CompareTeamScores(other, Team); other = Team.sort_prev)\r
323         {\r
324                 SORT_SWAP(other, Team);\r
325         }\r
326 }\r
327 \r
328 void Cmd_Sbar_Help(float argc)\r
329 {\r
330         print("You can modify the scoreboard using the ^2sbar_columns_set command.\n");\r
331         print("^3|---------------------------------------------------------------|\n");\r
332         print("Usage:\n");\r
333         print("^2sbar_columns_set default\n");\r
334         print("^2sbar_columns_set ^7filed1 field2 ...\n");\r
335         print("The following field names are recognized (case insensitive):\n");\r
336         print("You can use a ^3|^7 to start the right-aligned fields.\n\n");\r
337 \r
338         print("^3name^7 or ^3nick^7         Name of a player\n");\r
339         print("^3ping^7                     Ping time\n");\r
340         print("^3pl^7                       Packet loss\n");\r
341         print("^3kills^7                    Number of kills\n");\r
342         print("^3deaths^7                   Number of deaths\n");\r
343         print("^3suicides^7                 Number of suicides\n");\r
344         print("^3frags^7                    kills - suicides\n");\r
345         print("^3kd^7                       The kill-death ratio\n");\r
346         print("^3caps^7                     How often a flag (CTF) or a key (KeyHunt) was captured\n");\r
347         print("^3pickups^7                  How often a flag (CTF) or a key (KeyHunt) was picked up\n");\r
348         print("^3fckills^7                  Number of flag carrier kills\n");\r
349         print("^3returns^7                  Number of flag returns\n");\r
350         print("^3drops^7                    Number of flag drops\n");\r
351         print("^3lives^7                    Number of lives (LMS)\n");\r
352         print("^3rank^7                     Player rank\n");\r
353         print("^3pushes^7                   Number of players pushed into void\n");\r
354         print("^3destroyed^7                Number of keys destroyed by pushing them into void\n");\r
355         print("^3kckills^7                  Number of keys carrier kills\n");\r
356         print("^3losses^7                   Number of times a key was lost\n");\r
357         print("^3laps^7                     Number of laps finished (race/cts)\n");\r
358         print("^3time^7                     Total time raced (race/cts)\n");\r
359         print("^3fastest^7                  Time of fastest lap (race/cts)\n");\r
360         print("^3ticks^7                    Number of ticks (DOM)\n");\r
361         print("^3takes^7                    Number of domination points taken (DOM)\n");\r
362         print("^3score^7                    Total score\n\n");\r
363 \r
364         print("Before a field you can put a + or - sign, then a comma separated list\n");\r
365         print("of game types, then a slash, to make the field show up only in these\n");\r
366         print("or in all but these game types. You can also specify 'all' as a\n");\r
367         print("field to show all fields available for the current game mode.\n\n");\r
368         \r
369         print("The special game type names 'teams' and 'noteams' can be used to\n");\r
370         print("include/exclude ALL teams/noteams game modes.\n\n");\r
371 \r
372         print("Example: sbar_columns_set name ping pl | +ctf/field3 -dm/field4\n");\r
373         print("will display name, ping and pl aligned to the left, and the fields\n");\r
374         print("right of the vertical bar aligned to the right.\n");\r
375         print("'field3' will only be shown in CTF, and 'field4' will be shown in all\n");\r
376         print("other gamemodes except DM.\n");\r
377 }\r
378 \r
379 string Sbar_DefaultColumnLayout()\r
380 {\r
381         return strcat( // fteqcc sucks\r
382                 "ping pl name | ",\r
383                 "-teams,race,lms/kills -teams,lms/deaths -teams,lms,race/suicides -race,dm,tdm/frags ", // tdm already has this in "score"\r
384                 "+ctf/caps +ctf/pickups +ctf/fckills +ctf/returns ",\r
385                 "+lms/lives +lms/rank ",\r
386                 "+kh/caps +kh/pushes +kh/destroyed ",\r
387                 "?+race/laps ?+race/time ?+race/fastest ",\r
388                 "-lms,race");\r
389 }\r
390 \r
391 void Cmd_Sbar_SetFields(float argc)\r
392 {\r
393         float i, j, slash;\r
394         string str, pattern;\r
395         float have_name, have_primary, have_secondary, have_separator;\r
396         float missing;\r
397 \r
398         // TODO: re enable with gametype dependant cvars?\r
399         if(argc < 2) // no arguments provided\r
400                 argc = tokenizebyseparator(strcat("x ", cvar_string("sbar_columns")), " ");\r
401 \r
402         if(argc < 2)\r
403                 argc = tokenizebyseparator(strcat("x ", Sbar_DefaultColumnLayout()), " ");\r
404 \r
405         if(argc == 2)\r
406         {\r
407                 if(argv(1) == "default")\r
408                         argc = tokenizebyseparator(strcat("x ", Sbar_DefaultColumnLayout()), " ");\r
409                 else if(argv(1) == "all")\r
410                 {\r
411                         string s;\r
412                         s = "ping pl color name |";\r
413                         for(i = 0; i < MAX_SCORE; ++i)\r
414                         {\r
415                                 if(i != ps_primary)\r
416                                 if(i != ps_secondary)\r
417                                 if(scores_label[i] != "")\r
418                                         s = strcat(s, " ", scores_label[i]);\r
419                         }\r
420                         if(ps_secondary != ps_primary)\r
421                                 s = strcat(s, " ", scores_label[ps_secondary]);\r
422                         s = strcat(s, " ", scores_label[ps_primary]);\r
423                         argc = tokenizebyseparator(strcat("x ", s), " ");\r
424                 }\r
425         }\r
426 \r
427 \r
428         sbar_num_fields = 0;\r
429 \r
430         drawfont = sbar_font;\r
431 \r
432         for(i = 0; i < argc - 1; ++i)\r
433         {\r
434                 float nocomplain;\r
435                 str = argv(i+1);\r
436 \r
437                 nocomplain = FALSE;\r
438                 if(substring(str, 0, 1) == "?")\r
439                 {\r
440                         nocomplain = TRUE;\r
441                         str = substring(str, 1, strlen(str) - 1);\r
442                 }\r
443 \r
444                 slash = strstrofs(str, "/", 0);\r
445                 if(slash >= 0)\r
446                 {\r
447                         pattern = substring(str, 0, slash);\r
448                         str = substring(str, slash + 1, strlen(str) - (slash + 1));\r
449 \r
450                         if not(isGametypeInFilter(gametype, teamplay, pattern))\r
451                                 continue;\r
452                 }\r
453 \r
454                 strunzone(sbar_title[sbar_num_fields]);\r
455                 sbar_title[sbar_num_fields] = strzone(str);\r
456                 sbar_size[sbar_num_fields] = stringwidth(str, FALSE, sbar_fontsize);\r
457                 str = strtolower(str);\r
458 \r
459                 if(str == "ping") {\r
460                         sbar_field[sbar_num_fields] = SP_PING;\r
461                 } else if(str == "pl") {\r
462                         sbar_field[sbar_num_fields] = SP_PL;\r
463                 } else if(str == "kd" || str == "kdr" || str == "kdratio" || str == "k/d") {\r
464                         sbar_field[sbar_num_fields] = SP_KDRATIO;\r
465                 } else if(str == "name" || str == "nick") {\r
466                         sbar_field[sbar_num_fields] = SP_NAME;\r
467                         have_name = 1;\r
468                 } else if(str == "|") {\r
469                         sbar_field[sbar_num_fields] = SP_SEPARATOR;\r
470                         have_separator = 1;\r
471                 } else {\r
472                         if(gametype == GAME_RPG)\r
473                                 return;\r
474 \r
475                         for(j = 0; j < MAX_SCORE; ++j)\r
476                                 if(str == strtolower(scores_label[j]))\r
477                                         goto found; // sorry, but otherwise fteqcc -O3 miscompiles this and warns about "unreachable code"\r
478 :notfound\r
479                         if(str == "frags")\r
480                                 j = SP_FRAGS;\r
481                         else\r
482                         {\r
483                                 if not(nocomplain)\r
484                                         print(strcat("^1Error:^7 Unknown score field: '", str, "'\n"));\r
485                                 continue;\r
486                         }\r
487 :found\r
488                         sbar_field[sbar_num_fields] = j;\r
489                         if(j == ps_primary)\r
490                                 have_primary = 1;\r
491                         if(j == ps_secondary)\r
492                                 have_secondary = 1;\r
493                 }\r
494                 ++sbar_num_fields;\r
495                 if(sbar_num_fields >= MAX_SBAR_FIELDS)\r
496                         break;\r
497         }\r
498 \r
499         if(scores_flags[ps_primary] & SFL_ALLOW_HIDE)\r
500                 have_primary = 1;\r
501         if(scores_flags[ps_secondary] & SFL_ALLOW_HIDE)\r
502                 have_secondary = 1;\r
503         if(ps_primary == ps_secondary)\r
504                 have_secondary = 1;\r
505         missing = (!have_primary) + (!have_secondary) + (!have_separator) + (!have_name);\r
506 \r
507         if(sbar_num_fields+missing < MAX_SBAR_FIELDS)\r
508         {\r
509                 if(!have_name)\r
510                 {\r
511                         strunzone(sbar_title[sbar_num_fields]);\r
512                         for(i = sbar_num_fields; i > 0; --i)\r
513                         {\r
514                                 sbar_title[i] = sbar_title[i-1];\r
515                                 sbar_size[i] = sbar_size[i-1];\r
516                                 sbar_field[i] = sbar_field[i-1];\r
517                         }\r
518                         sbar_title[0] = strzone("name");\r
519                         sbar_field[0] = SP_NAME;\r
520                         ++sbar_num_fields;\r
521                         print("fixed missing field 'name'\n");\r
522 \r
523                         if(!have_separator)\r
524                         {\r
525                                 strunzone(sbar_title[sbar_num_fields]);\r
526                                 for(i = sbar_num_fields; i > 1; --i)\r
527                                 {\r
528                                         sbar_title[i] = sbar_title[i-1];\r
529                                         sbar_size[i] = sbar_size[i-1];\r
530                                         sbar_field[i] = sbar_field[i-1];\r
531                                 }\r
532                                 sbar_title[1] = strzone("|");\r
533                                 sbar_field[1] = SP_SEPARATOR;\r
534                                 sbar_size[1] = stringwidth("|", FALSE, sbar_fontsize);\r
535                                 ++sbar_num_fields;\r
536                                 print("fixed missing field '|'\n");\r
537                         }\r
538                 }\r
539                 else if(!have_separator)\r
540                 {\r
541                         strunzone(sbar_title[sbar_num_fields]);\r
542                         sbar_title[sbar_num_fields] = strzone("|");\r
543                         sbar_size[sbar_num_fields] = stringwidth("|", FALSE, sbar_fontsize);\r
544                         sbar_field[sbar_num_fields] = SP_SEPARATOR;\r
545                         ++sbar_num_fields;\r
546                         print("fixed missing field '|'\n");\r
547                 }\r
548                 if(!have_secondary)\r
549                 {\r
550                         strunzone(sbar_title[sbar_num_fields]);\r
551                         sbar_title[sbar_num_fields] = strzone(scores_label[ps_secondary]);\r
552                         sbar_size[sbar_num_fields] = stringwidth(sbar_title[sbar_num_fields], FALSE, sbar_fontsize);\r
553                         sbar_field[sbar_num_fields] = ps_secondary;\r
554                         ++sbar_num_fields;\r
555                         print("fixed missing field '", scores_label[ps_secondary], "'\n");\r
556                 }\r
557                 if(!have_primary)\r
558                 {\r
559                         strunzone(sbar_title[sbar_num_fields]);\r
560                         sbar_title[sbar_num_fields] = strzone(scores_label[ps_primary]);\r
561                         sbar_size[sbar_num_fields] = stringwidth(sbar_title[sbar_num_fields], FALSE, sbar_fontsize);\r
562                         sbar_field[sbar_num_fields] = ps_primary;\r
563                         ++sbar_num_fields;\r
564                         print("fixed missing field '", scores_label[ps_primary], "'\n");\r
565                 }\r
566         }\r
567 \r
568         sbar_field[sbar_num_fields] = SP_END;\r
569 }\r
570 \r
571 // MOVEUP::\r
572 vector sbar_field_rgb;\r
573 string sbar_field_icon0;\r
574 string sbar_field_icon1;\r
575 string sbar_field_icon2;\r
576 vector sbar_field_icon0_rgb;\r
577 vector sbar_field_icon1_rgb;\r
578 vector sbar_field_icon2_rgb;\r
579 float sbar_field_icon0_alpha;\r
580 float sbar_field_icon1_alpha;\r
581 float sbar_field_icon2_alpha;\r
582 string Sbar_GetField(entity pl, float field)\r
583 {\r
584         float tmp, num, denom, f;\r
585         string str;\r
586         sbar_field_rgb = '1 1 1';\r
587         sbar_field_icon0 = "";\r
588         sbar_field_icon1 = "";\r
589         sbar_field_icon2 = "";\r
590         sbar_field_icon0_rgb = '1 1 1';\r
591         sbar_field_icon1_rgb = '1 1 1';\r
592         sbar_field_icon2_rgb = '1 1 1';\r
593         sbar_field_icon0_alpha = 1;\r
594         sbar_field_icon1_alpha = 1;\r
595         sbar_field_icon2_alpha = 1;\r
596         switch(field)\r
597         {\r
598                 case SP_PING:\r
599                         if not(pl.gotscores)\r
600                                 return "\x8D\x8D\x8D"; // >>> sign\r
601                         //str = getplayerkey(pl.sv_entnum, "ping");\r
602                         f = pl.ping;\r
603                         if(f == 0)\r
604                                 return "N/A";\r
605                         tmp = max(0, min(220, f-80)) / 220;\r
606                         sbar_field_rgb = '1 1 1' - '0 1 1'*tmp;\r
607                         return ftos(f);\r
608 \r
609                 case SP_PL:\r
610                         if not(pl.gotscores)\r
611                                 return "N/A";\r
612                         f = pl.ping_packetloss;\r
613                         tmp = pl.ping_movementloss;\r
614                         if(f == 0 && tmp == 0)\r
615                                 return "";\r
616                         str = ftos(ceil(f * 100));\r
617                         if(tmp != 0)\r
618                                 str = strcat(str, "~", ftos(ceil(tmp * 100)));\r
619                         tmp = bound(0, f / 0.2 + tmp / 0.04, 1); // 20% is REALLY BAD pl\r
620                         sbar_field_rgb = '1 0.5 0.5' - '0 0.5 0.5'*tmp;\r
621                         return str;\r
622 \r
623                 case SP_NAME:\r
624                         if(ready_waiting && pl.ready)\r
625                         {\r
626                                 sbar_field_icon0 = "gfx/sb_player_ready";\r
627                         }\r
628                         else if(!teamplay)\r
629                         {\r
630                                 f = stof(getplayerkey(pl.sv_entnum, "colors"));\r
631                                 {\r
632                                         sbar_field_icon0 = "gfx/sb_playercolor_base";\r
633                                         sbar_field_icon1 = "gfx/sb_playercolor_shirt";\r
634                                         sbar_field_icon1_rgb = colormapPaletteColor(floor(f / 16), 0);\r
635                                         sbar_field_icon2 = "gfx/sb_playercolor_pants";\r
636                                         sbar_field_icon2_rgb = colormapPaletteColor(mod(f, 16), 1);\r
637                                 }\r
638                         }\r
639                         return GetPlayerName(pl.sv_entnum);\r
640 \r
641                 case SP_FRAGS:\r
642                         f = pl.(scores[SP_KILLS]);\r
643                         f -= pl.(scores[SP_SUICIDES]);\r
644                         return ftos(f);\r
645 \r
646                 case SP_KDRATIO:\r
647                         num = pl.(scores[SP_KILLS]);\r
648                         denom = pl.(scores[SP_DEATHS]);\r
649 \r
650                         if(denom == 0) {\r
651                                 sbar_field_rgb = '0 1 0';\r
652                                 str = ftos(num);\r
653                         } else if(num <= 0) {\r
654                                 sbar_field_rgb = '1 0 0';\r
655                                 str = ftos(num/denom);\r
656                         } else\r
657                                 str = ftos(num/denom);\r
658 \r
659                         tmp = strstrofs(str, ".", 0);\r
660                         if(tmp > 0)\r
661                                 str = substring(str, 0, tmp+2);\r
662                         return str;\r
663 \r
664                 default:\r
665                         tmp = pl.(scores[field]);\r
666                         f = scores_flags[field];\r
667                         if(field == ps_primary)\r
668                                 sbar_field_rgb = '1 1 0';\r
669                         else if(field == ps_secondary)\r
670                                 sbar_field_rgb = '0 1 1';\r
671                         else\r
672                                 sbar_field_rgb = '1 1 1';\r
673                         return ScoreString(f, tmp);\r
674         }\r
675         //return "error";\r
676 }\r
677 \r
678 string Sbar_GetStomachField(entity pl, float field)\r
679 {\r
680         switch(field)\r
681         {\r
682                 case ST_HIGHLIGHT:\r
683                         return ""; // the returned value is not used, we only need the field\r
684 \r
685                 case ST_NAME:\r
686                         return GetPlayerName(pl.sv_entnum);\r
687 \r
688                 case ST_HEALTH:\r
689                         return ftos(pl.plhealth);\r
690 \r
691                 default:\r
692                         return "N/A";\r
693         }\r
694         //return "error";\r
695 }\r
696 \r
697 string Sbar_GetStomachFieldPred(entity pl, float field)\r
698 {\r
699         switch(field)\r
700         {\r
701                 case STP_NAME:\r
702                         return GetPlayerName(pl.sv_entnum);\r
703                 default:\r
704                         return "N/A";\r
705         }\r
706         //return "error";\r
707 }\r
708 \r
709 float xmin, xmax, ymin, ymax, sbwidth;\r
710 float sbar_fixscoreboardcolumnwidth_len;\r
711 float sbar_fixscoreboardcolumnwidth_iconlen;\r
712 float sbar_fixscoreboardcolumnwidth_marginlen;\r
713 \r
714 float stringwidth_colors(string s, vector theSize)\r
715 {\r
716         return stringwidth(s, TRUE, theSize);\r
717 }\r
718 \r
719 float stringwidth_nocolors(string s, vector theSize)\r
720 {\r
721         return stringwidth(s, FALSE, theSize);\r
722 }\r
723 \r
724 string Sbar_FixScoreboardColumnWidth(float i, string str)\r
725 {\r
726         float field, f;\r
727         vector sz;\r
728         field = sbar_field[i];\r
729 \r
730         sbar_fixscoreboardcolumnwidth_iconlen = 0;\r
731 \r
732         if(sbar_field_icon0 != "")\r
733         {\r
734                 sz = drawgetimagesize(sbar_field_icon0);\r
735                 f = sz_x / sz_y;\r
736                 if(sbar_fixscoreboardcolumnwidth_iconlen < f)\r
737                         sbar_fixscoreboardcolumnwidth_iconlen = f;\r
738         }\r
739 \r
740         if(sbar_field_icon1 != "")\r
741         {\r
742                 sz = drawgetimagesize(sbar_field_icon1);\r
743                 f = sz_x / sz_y;\r
744                 if(sbar_fixscoreboardcolumnwidth_iconlen < f)\r
745                         sbar_fixscoreboardcolumnwidth_iconlen = f;\r
746         }\r
747 \r
748         if(sbar_field_icon2 != "")\r
749         {\r
750                 sz = drawgetimagesize(sbar_field_icon2);\r
751                 f = sz_x / sz_y;\r
752                 if(sbar_fixscoreboardcolumnwidth_iconlen < f)\r
753                         sbar_fixscoreboardcolumnwidth_iconlen = f;\r
754         }\r
755 \r
756         sbar_fixscoreboardcolumnwidth_iconlen *= sbar_fontsize_y / sbar_fontsize_x; // fix icon aspect\r
757 \r
758         if(sbar_fixscoreboardcolumnwidth_iconlen != 0)\r
759                 sbar_fixscoreboardcolumnwidth_marginlen = stringwidth(" ", FALSE, sbar_fontsize);\r
760         else\r
761                 sbar_fixscoreboardcolumnwidth_marginlen = 0;\r
762 \r
763         if(field == SP_NAME) // name gets all remaining space\r
764         {\r
765                 float namesize, j;\r
766                 namesize = sbwidth;// / sbar_fontsize_x;\r
767                 for(j = 0; j < sbar_num_fields; ++j)\r
768                         if(j != i)\r
769                                 if (sbar_field[i] != SP_SEPARATOR)\r
770                                         namesize -= sbar_size[j] + 1;\r
771                 namesize += 1;\r
772                 sbar_size[i] = namesize;\r
773                 \r
774                 if (sbar_fixscoreboardcolumnwidth_iconlen != 0)\r
775                         namesize -= sbar_fixscoreboardcolumnwidth_marginlen + sbar_fixscoreboardcolumnwidth_iconlen;\r
776                 str = textShortenToWidth(str, namesize, sbar_fontsize, stringwidth_colors);\r
777                 sbar_fixscoreboardcolumnwidth_len = stringwidth(str, TRUE, sbar_fontsize);\r
778         }\r
779         else\r
780                 sbar_fixscoreboardcolumnwidth_len = stringwidth(str, FALSE, sbar_fontsize);\r
781         \r
782         f = sbar_fixscoreboardcolumnwidth_len + sbar_fixscoreboardcolumnwidth_marginlen + sbar_fixscoreboardcolumnwidth_iconlen;\r
783         if(sbar_size[i] < f)\r
784                 sbar_size[i] = f;\r
785 \r
786         return str;\r
787 }\r
788 \r
789 void Sbar_PrintScoreboardItem(vector pos, entity pl, float is_self, float pl_number)\r
790 {\r
791         vector tmp, rgb;\r
792         rgb = GetTeamRGB(pl.team);\r
793         string str;\r
794         float i, field;\r
795         float is_spec;\r
796         is_spec = (GetPlayerColor(pl.sv_entnum) == COLOR_SPECTATOR);\r
797         \r
798         if((rgb == '1 1 1') && (!is_spec)) {\r
799                 rgb_x = cvar("sbar_color_bg_r") + 0.5;\r
800                 rgb_y = cvar("sbar_color_bg_g") + 0.5;\r
801                 rgb_z = cvar("sbar_color_bg_b") + 0.5; }\r
802                 \r
803         // Layout:\r
804         tmp_x = sbwidth;\r
805         tmp_y = sbar_fontsize_y * 1.25;\r
806         tmp_z = 0;\r
807 \r
808         // alternated rows highlighting\r
809         if(is_self)\r
810                 drawfill(pos - '1 1 0', tmp + '2 0 0', rgb, sbar_scoreboard_highlight_alpha_self, DRAWFLAG_NORMAL);\r
811         else if((sbar_scoreboard_highlight) && (!mod(pl_number,2)))\r
812                 drawfill(pos - '1 1 0', tmp + '2 0 0', rgb, sbar_scoreboard_highlight_alpha, DRAWFLAG_NORMAL);\r
813 \r
814         tmp_y = 0;\r
815 \r
816         for(i = 0; i < sbar_num_fields; ++i)\r
817         {\r
818                 field = sbar_field[i];\r
819                 if(field == SP_SEPARATOR)\r
820                         break;\r
821 \r
822                 if(is_spec && field != SP_NAME && field != SP_PING) {\r
823                         pos_x += sbar_size[i] + sbar_fontsize_x;\r
824                         continue;\r
825                 }\r
826                 str = Sbar_GetField(pl, field);\r
827                 str = Sbar_FixScoreboardColumnWidth(i, str);\r
828 \r
829                 pos_x += sbar_size[i] + sbar_fontsize_x;\r
830 \r
831                 if(field == SP_NAME) {\r
832                         tmp_x = sbar_size[i] - sbar_fontsize_x*sbar_fixscoreboardcolumnwidth_iconlen - sbar_fixscoreboardcolumnwidth_marginlen + sbar_fontsize_x;\r
833                         if (is_self)\r
834                                 drawcolorcodedstring(pos - tmp, str, sbar_fontsize, sbar_scoreboard_alpha_name_self, DRAWFLAG_NORMAL);\r
835                         else\r
836                                 drawcolorcodedstring(pos - tmp, str, sbar_fontsize, sbar_scoreboard_alpha_name, DRAWFLAG_NORMAL);\r
837                 } else {\r
838                         tmp_x = sbar_fixscoreboardcolumnwidth_len + sbar_fontsize_x;\r
839                         if (is_self)\r
840                                 drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, sbar_scoreboard_alpha_name_self, DRAWFLAG_NORMAL);\r
841                         else\r
842                                 drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, sbar_scoreboard_alpha_name, DRAWFLAG_NORMAL);\r
843                 }\r
844 \r
845                 tmp_x = sbar_size[i] + sbar_fontsize_x;\r
846                 if(sbar_field_icon0 != "")\r
847                         if (is_self)\r
848                                 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 * sbar_scoreboard_alpha_name_self, DRAWFLAG_NORMAL);\r
849                         else\r
850                                 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 * sbar_scoreboard_alpha_name, DRAWFLAG_NORMAL);\r
851                 if(sbar_field_icon1 != "")\r
852                         if (is_self)\r
853                                 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 * sbar_scoreboard_alpha_name_self, DRAWFLAG_NORMAL);\r
854                         else\r
855                                 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 * sbar_scoreboard_alpha_name, DRAWFLAG_NORMAL);\r
856                 if(sbar_field_icon2 != "")\r
857                         if (is_self)\r
858                                 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 * sbar_scoreboard_alpha_name_self, DRAWFLAG_NORMAL);\r
859                         else\r
860                                 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 * sbar_scoreboard_alpha_name, DRAWFLAG_NORMAL);\r
861         }\r
862 \r
863         if(sbar_field[i] == SP_SEPARATOR)\r
864         {\r
865                 pos_x = xmax;\r
866                 for(i = sbar_num_fields-1; i > 0; --i)\r
867                 {\r
868                         field = sbar_field[i];\r
869                         if(field == SP_SEPARATOR)\r
870                                 break;\r
871 \r
872                         if(is_spec && field != SP_NAME && field != SP_PING) {\r
873                                 pos_x -= sbar_size[i] + sbar_fontsize_x;\r
874                                 continue;\r
875                         }\r
876 \r
877                         str = Sbar_GetField(pl, field);\r
878                         str = Sbar_FixScoreboardColumnWidth(i, str);\r
879 \r
880                         if(field == SP_NAME) {\r
881                                 tmp_x = sbar_fixscoreboardcolumnwidth_len; // left or right aligned? let's put it right...\r
882                                 if(is_self)\r
883                                         drawcolorcodedstring(pos - tmp, str, sbar_fontsize, sbar_scoreboard_alpha_name_self, DRAWFLAG_NORMAL);\r
884                                 else\r
885                                         drawcolorcodedstring(pos - tmp, str, sbar_fontsize, sbar_scoreboard_alpha_name, DRAWFLAG_NORMAL);\r
886                         } else {\r
887                                 tmp_x = sbar_fixscoreboardcolumnwidth_len;\r
888                                 if(is_self)\r
889                                         drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, sbar_scoreboard_alpha_name_self, DRAWFLAG_NORMAL);\r
890                                 else\r
891                                         drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, sbar_scoreboard_alpha_name, DRAWFLAG_NORMAL);\r
892                         }\r
893 \r
894                         tmp_x = sbar_size[i];\r
895                         if(sbar_field_icon0 != "")\r
896                                 if (is_self)\r
897                                         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 * sbar_scoreboard_alpha_name_self, DRAWFLAG_NORMAL);\r
898                                 else\r
899                                         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 * sbar_scoreboard_alpha_name, DRAWFLAG_NORMAL);\r
900                         if(sbar_field_icon1 != "")\r
901                                 if (is_self)\r
902                                         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 * sbar_scoreboard_alpha_name_self, DRAWFLAG_NORMAL);\r
903                                 else\r
904                                         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 * sbar_scoreboard_alpha_name, DRAWFLAG_NORMAL);\r
905                         if(sbar_field_icon2 != "")\r
906                                 if (is_self)\r
907                                         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 * sbar_scoreboard_alpha_name_self, DRAWFLAG_NORMAL);\r
908                                 else\r
909                                         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 * sbar_scoreboard_alpha_name, DRAWFLAG_NORMAL);\r
910                         pos_x -= sbar_size[i] + sbar_fontsize_x;\r
911                 }\r
912         }\r
913 }\r
914 \r
915 float fieldcounter;\r
916 void Sbar_PrintStomachboardItem(vector pos, entity pl)\r
917 {\r
918         // lists all players in the stomach\r
919 \r
920         string str;\r
921         float f, field, field_number;\r
922         field_number = 3; // the number of components each row has\r
923 \r
924         for(fieldcounter = 1; fieldcounter <= field_number; ++fieldcounter)\r
925         {\r
926                 field = -fieldcounter;\r
927                 str = Sbar_GetStomachField(pl, field);\r
928 \r
929                 // row highlighting\r
930                 if(field == ST_HIGHLIGHT)\r
931                 {\r
932                         if(getstati(STAT_VORE_EATEN))\r
933                                 drawfill(pos - '0 0 0', '193 11 0', stov(cvar_string("sbar_stomachboard_color2")), cvar("sbar_stomachboard_highlight_alpha") * sbar_alpha_fg, DRAWFLAG_NORMAL);\r
934                         else\r
935                                 drawfill(pos - '0 0 0', '193 11 0', stov(cvar_string("sbar_stomachboard_color1")), cvar("sbar_stomachboard_highlight_alpha") * sbar_alpha_fg, DRAWFLAG_NORMAL);\r
936                 }\r
937 \r
938                 if(field == ST_NAME) {\r
939                         f = stof(getplayerkey(pl.sv_entnum, "colors"));\r
940                         drawpic(pos, "gfx/sb_playercolor_base", '22 11 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
941                         drawpic(pos, "gfx/sb_playercolor_shirt", '22 11 0', colormapPaletteColor(floor(f / 16), 0), sbar_alpha_fg, DRAWFLAG_NORMAL);\r
942                         drawpic(pos, "gfx/sb_playercolor_pants", '22 11 0', colormapPaletteColor(mod(f, 16), 1), sbar_alpha_fg, DRAWFLAG_NORMAL);\r
943 \r
944                         pos_x += 24;\r
945                         drawcolorcodedstring(pos, textShortenToWidth(str, 138, '11 11 0', stringwidth_colors), '11 11 0', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
946                 }\r
947 \r
948                 if(field == ST_HEALTH)\r
949                 if(stof(str) > 0) {\r
950                         pos_x += 138;\r
951                                 if(pl.sv_entnum == player_localentnum - 1 || (spectatee_status && pl.sv_entnum == spectatee_status - 1))\r
952                                         drawcolorcodedstring(pos, "self", '11 11 0', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
953                                 else\r
954                                 {\r
955                                         drawpic(pos, "gfx/hud/sb_health", '11 11 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
956 \r
957                                         pos_x += 9;\r
958                                                 drawcolorcodedstring(pos, str, '11 11 0', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
959                                 }\r
960                 }\r
961         }\r
962 }\r
963 \r
964 float fieldcounter2;\r
965 void Sbar_PrintStomachboardItemPred(vector pos, entity pl)\r
966 {\r
967         // shows the name of our predator\r
968 \r
969         string str;\r
970         float f, field, field_number;\r
971         field_number = 1; // the number of components each row has\r
972 \r
973         for(fieldcounter2 = 1; fieldcounter2 <= field_number; ++fieldcounter2)\r
974         {\r
975                 field = -fieldcounter2;\r
976                 str = Sbar_GetStomachFieldPred(pl, field);\r
977 \r
978                 if(field == STP_NAME) {\r
979                         f = stof(getplayerkey(pl.sv_entnum, "colors"));\r
980                         drawpic(pos, "gfx/sb_playercolor_base", '22 11 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
981                         drawpic(pos, "gfx/sb_playercolor_shirt", '22 11 0', colormapPaletteColor(floor(f / 16), 0), sbar_alpha_fg, DRAWFLAG_NORMAL);\r
982                         drawpic(pos, "gfx/sb_playercolor_pants", '22 11 0', colormapPaletteColor(mod(f, 16), 1), sbar_alpha_fg, DRAWFLAG_NORMAL);\r
983 \r
984                         pos_x += 24;\r
985                         drawcolorcodedstring(pos, textShortenToWidth(str, 122, '11 11 0', stringwidth_colors), '11 11 0', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
986                 }\r
987         }\r
988 }\r
989 \r
990 /*\r
991  * Sbar_Scoreboard_MakeTable\r
992  *\r
993  * Makes a table for a team (for all playing players in DM) and fills it\r
994  */\r
995 \r
996 vector Sbar_Scoreboard_MakeTable(vector pos, entity tm, vector rgb, vector bg_size)\r
997 {\r
998         float body_table_height, i;\r
999         vector tmp, column_dim;\r
1000         entity pl;\r
1001 \r
1002         body_table_height = 1.25 * sbar_fontsize_y * max(1, tm.team_size); // no player? show 1 empty line\r
1003 \r
1004         pos -= '1 1 0';\r
1005 \r
1006         tmp_x = sbwidth + 2;\r
1007         tmp_y = 1.25 * sbar_fontsize_y;\r
1008 \r
1009         // rounded header\r
1010         drawpic(pos, "gfx/hud/sb_scoreboard_tableheader", tmp, (rgb * sbar_color_bg_team) + '0.5 0.5 0.5', sbar_scoreboard_alpha_bg, DRAWFLAG_NORMAL);\r
1011 \r
1012         // table border\r
1013         tmp_y += sbar_border_thickness;\r
1014         tmp_y += body_table_height;\r
1015         drawborderlines(sbar_border_thickness, pos, tmp, '0 0 0', sbar_scoreboard_alpha_bg, DRAWFLAG_NORMAL); // more transparency for the scoreboard\r
1016 \r
1017         // separator header/table\r
1018         pos_y += 1.25 * sbar_fontsize_y;\r
1019         tmp_y = sbar_border_thickness;\r
1020         drawfill(pos, tmp, '0 0 0', sbar_scoreboard_alpha_bg, DRAWFLAG_NORMAL);\r
1021 \r
1022         pos_y += sbar_border_thickness;\r
1023 \r
1024         // table background\r
1025         tmp_y = body_table_height;\r
1026         drawpic_tiled(pos, "gfx/hud/sb_scoreboard_bg", bg_size, tmp, rgb * sbar_color_bg_team, sbar_scoreboard_alpha_bg, DRAWFLAG_NORMAL);\r
1027 \r
1028         // anyway, apply some color\r
1029         //drawfill(pos, tmp + '2 0 0', rgb, 0.1, DRAWFLAG_NORMAL);\r
1030 \r
1031         // go back to the top to make alternated columns highlighting and to print the strings\r
1032         pos_y -= 1.25 * sbar_fontsize_y;\r
1033         pos_y -= sbar_border_thickness;\r
1034 \r
1035         pos += '1 1 0';\r
1036 \r
1037         if (sbar_scoreboard_highlight)\r
1038         {\r
1039                 column_dim_y = 1.25 * sbar_fontsize_y; // header\r
1040                 column_dim_y += sbar_border_thickness;\r
1041                 column_dim_y += body_table_height;\r
1042         }\r
1043 \r
1044         // print the strings of the columns headers and draw the columns\r
1045         for(i = 0; i < sbar_num_fields; ++i)\r
1046         {\r
1047                 if(sbar_field[i] == SP_SEPARATOR)\r
1048                         break;\r
1049                 column_dim_x = sbar_size[i] + sbar_fontsize_x;\r
1050                 if (sbar_scoreboard_highlight)\r
1051                 {\r
1052                         if (mod(i,2))\r
1053                                 drawfill(pos - '0 1 0' - sbar_fontsize_x / 2 * '1 0 0', column_dim, '0 0 0', sbar_scoreboard_alpha_bg * 0.2, DRAWFLAG_NORMAL);\r
1054                 }\r
1055                 drawstring(pos, sbar_title[i], sbar_fontsize, rgb * 1.5, sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1056                 pos_x += column_dim_x;\r
1057         }\r
1058         if(sbar_field[i] == SP_SEPARATOR)\r
1059         {\r
1060                 pos_x = xmax;\r
1061                 tmp_y = 0;\r
1062                 for(i = sbar_num_fields-1; i > 0; --i)\r
1063                 {\r
1064                         if(sbar_field[i] == SP_SEPARATOR)\r
1065                                 break;\r
1066 \r
1067                         pos_x -= sbar_size[i];\r
1068 \r
1069                         if (sbar_scoreboard_highlight)\r
1070                         {\r
1071                                 if (!mod(i,2))\r
1072                                 {\r
1073                                         if (i == sbar_num_fields-1)\r
1074                                                 column_dim_x = sbar_size[i] + sbar_fontsize_x / 2 + 1;\r
1075                                         else\r
1076                                                 column_dim_x = sbar_size[i] + sbar_fontsize_x;\r
1077                                         drawfill(pos - '0 1 0' - sbar_fontsize_x / 2 * '1 0 0', column_dim, '0 0 0', sbar_scoreboard_alpha_bg * 0.2, DRAWFLAG_NORMAL);\r
1078                                 }\r
1079                         }\r
1080 \r
1081                         tmp_x = stringwidth(sbar_title[i], FALSE, sbar_fontsize);\r
1082                         tmp_x = sbar_size[i] - tmp_x;\r
1083                         drawstring(pos + tmp, sbar_title[i], sbar_fontsize, rgb * 1.5, sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1084                         pos_x -= sbar_fontsize_x;\r
1085                 }\r
1086         }\r
1087         \r
1088         pos_x = xmin;\r
1089         pos_y += 1.25 * sbar_fontsize_y; // skip the header\r
1090         pos_y += sbar_border_thickness;\r
1091 \r
1092         // fill the table and draw the rows\r
1093         i = 0;\r
1094         if (teamplay)\r
1095                 for(pl = players.sort_next; pl; pl = pl.sort_next)\r
1096                 {\r
1097                         if(pl.team != tm.team)\r
1098                                 continue;\r
1099                         Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1), i);\r
1100                         pos_y += 1.25 * sbar_fontsize_y;\r
1101                         ++i;\r
1102                 }\r
1103         else\r
1104                 for(pl = players.sort_next; pl; pl = pl.sort_next)\r
1105                 {\r
1106                         if(pl.team == COLOR_SPECTATOR)\r
1107                                 continue;\r
1108                         Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1), i);\r
1109                         pos_y += 1.25 * sbar_fontsize_y;\r
1110                         ++i;\r
1111                 }\r
1112         \r
1113         if (i == 0)\r
1114                 pos_y += 1.25 * sbar_fontsize_y; // move to the end of the table\r
1115         pos_y += 1.25 * sbar_fontsize_y; // move empty row (out of the table)\r
1116 \r
1117         return pos;\r
1118 }\r
1119 \r
1120 float Sbar_WouldDrawScoreboard() {\r
1121         if (sb_showscores)\r
1122                 return 1;\r
1123         else if (intermission == 1)\r
1124                 return 1;\r
1125         else if (intermission == 2)\r
1126                 return 1;\r
1127         else if (getstati(STAT_HEALTH) <= 0 && cvar("cl_deathscoreboard"))\r
1128                 return 1;\r
1129         else if(sb_showscores_force)\r
1130                 return 1;\r
1131         return 0;\r
1132 }\r
1133 \r
1134 float average_accuracy;\r
1135 vector Sbar_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size)\r
1136 {\r
1137         float i;\r
1138         float weapon_hit, weapon_damage, weapon_stats;\r
1139         float fontsize = 40 * 1/3;\r
1140         float xsave;\r
1141         float weapon_cnt;\r
1142         float rows;\r
1143         if(cvar("sbar_accuracy_doublerows"))\r
1144                 rows = 2;\r
1145         else\r
1146                 rows = 1;\r
1147         float height = 40;\r
1148 \r
1149         if(warmup_stage)\r
1150         {\r
1151                 return pos;\r
1152         }\r
1153 \r
1154         xsave = pos_x;\r
1155         drawstring(pos, strcat("Accuracy stats (average ", ftos(average_accuracy), "%)"), sbar_fontsize, '1 1 1', sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1156         pos_y += 18;\r
1157         vector tmp;\r
1158         tmp_x = sbwidth;\r
1159         tmp_y = height * rows;\r
1160 \r
1161         drawpic_tiled(pos, "gfx/hud/sb_scoreboard_bg", bg_size, tmp, rgb * sbar_color_bg_team, sbar_scoreboard_alpha_bg, DRAWFLAG_NORMAL);\r
1162         drawborderlines(sbar_accuracy_border_thickness, pos, tmp, '0 0 0', sbar_scoreboard_alpha_bg * 0.75, DRAWFLAG_NORMAL);\r
1163 \r
1164         // column highlighting\r
1165         for(i = 0; i < weapon_cnt/rows; ++i)\r
1166         {\r
1167                 if(!mod(i, 2))\r
1168                         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', sbar_scoreboard_alpha_bg * 0.2, DRAWFLAG_NORMAL);\r
1169         }\r
1170 \r
1171         // row highlighting\r
1172         for(i = 0; i < rows; ++i)\r
1173         {\r
1174                 drawfill(pos + '0 1 0' * height * (2/3) + '0 1 0' * height * i, '1 0 0' * sbwidth + '0 1 0' * fontsize, '1 1 1', sbar_scoreboard_highlight_alpha, DRAWFLAG_NORMAL);     \r
1175         }\r
1176 \r
1177         // skip useless weapons\r
1178         weapon_cnt = 0;\r
1179         for(i = WEP_FIRST; i <= WEP_LAST; ++i)\r
1180         {\r
1181                 self = get_weaponinfo(i);\r
1182                 if not(self.weapons)\r
1183                         continue;\r
1184                 ++weapon_cnt;\r
1185         }\r
1186 \r
1187         drawfont = sbar_bigfont;\r
1188         average_accuracy = 0;\r
1189         float weapons_with_stats;\r
1190         weapons_with_stats = 0;\r
1191         if(rows == 2)\r
1192                 pos_x += sbwidth/weapon_cnt / 2;\r
1193 \r
1194         for(i = WEP_FIRST; i <= WEP_LAST; ++i)\r
1195         {\r
1196                 self = get_weaponinfo(i);\r
1197                 if not(self.weapons)\r
1198                         continue;\r
1199                 weapon_hit = weapon_hits[i-WEP_FIRST];\r
1200                 weapon_damage = weapon_fired[i-WEP_FIRST];\r
1201                 if(weapon_damage)\r
1202                         weapon_stats = bound(0, floor(100 * weapon_hit / weapon_damage), 100);\r
1203                 float weapon_alpha;\r
1204 \r
1205                 if(weapon_damage)\r
1206                         weapon_alpha = sbar_scoreboard_alpha_fg;\r
1207                 else\r
1208                         weapon_alpha = 0.2 * sbar_scoreboard_alpha_fg;\r
1209 \r
1210                 // weapon icon\r
1211                 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);\r
1212                 // the accuracy\r
1213                 if(weapon_damage) {\r
1214                         weapons_with_stats += 1;\r
1215                         average_accuracy += weapon_stats; // store sum of all accuracies in average_accuracy\r
1216 \r
1217                         string s;\r
1218                         s = strcat(ftos(weapon_stats),"%");\r
1219 \r
1220                         float padding;\r
1221                         padding = ((sbwidth/weapon_cnt) - stringwidth(s, FALSE, '1 0 0' * fontsize)) / 2; // center the accuracy value\r
1222 \r
1223                         rgb = Sbar_AccuracyColor(weapon_stats);\r
1224                         drawstring(pos + '1 0 0' * padding + '0 1 0' * height * (2/3), s, '1 1 0' * fontsize, rgb, sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1225                 }\r
1226                 pos_x += sbwidth/weapon_cnt * rows;\r
1227                 if(rows == 2 && i == 6) {\r
1228                         pos_x -= sbwidth;\r
1229                         pos_y += height;\r
1230                 }\r
1231         }\r
1232         drawfont = sbar_font;\r
1233 \r
1234         if(weapons_with_stats)\r
1235                 average_accuracy = floor(average_accuracy / weapons_with_stats);\r
1236 \r
1237         pos_x = xsave;\r
1238         pos_y += height;\r
1239         return pos;\r
1240 }\r
1241 \r
1242 string race_PlaceName(float pos) {\r
1243         if(pos == 1)\r
1244                 return "1st";\r
1245         else if(pos == 2)\r
1246                 return "2nd";\r
1247         else if(pos == 3)\r
1248                 return "3rd";\r
1249         else\r
1250                 return strcat(ftos(pos), "th");\r
1251 }\r
1252 \r
1253 vector Sbar_DrawScoreboardRankings(vector pos, entity pl,  vector rgb, vector bg_size)\r
1254 {\r
1255         float i;\r
1256         RANKINGS_RECEIVED_CNT = 0;\r
1257                 for (i=RANKINGS_CNT-1; i>=0; --i)\r
1258                         if (grecordtime[i])\r
1259                                 RANKINGS_RECEIVED_CNT = RANKINGS_RECEIVED_CNT + 1;\r
1260 \r
1261         if (RANKINGS_RECEIVED_CNT == 0)\r
1262                 return pos;\r
1263 \r
1264         float is_spec;\r
1265         is_spec = (GetPlayerColor(pl.sv_entnum) == COLOR_SPECTATOR);\r
1266         vector hl_rgb;\r
1267                 hl_rgb_x = cvar("sbar_color_bg_r") + 0.5;\r
1268                 hl_rgb_y = cvar("sbar_color_bg_g") + 0.5;\r
1269                 hl_rgb_z = cvar("sbar_color_bg_b") + 0.5;\r
1270 \r
1271         pos_y += sbar_fontsize_y;\r
1272         drawstring(pos, strcat("Rankings"), sbar_fontsize, '1 1 1', sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1273         pos_y += sbar_fontsize_y;\r
1274         vector tmp;\r
1275         tmp_x = sbwidth;\r
1276         tmp_y = sbar_fontsize_y * RANKINGS_RECEIVED_CNT;\r
1277 \r
1278         drawpic_tiled(pos, "gfx/hud/sb_scoreboard_bg", bg_size, tmp, rgb * sbar_color_bg_team, sbar_scoreboard_alpha_bg, DRAWFLAG_NORMAL);\r
1279         drawborderlines(sbar_border_thickness, pos, tmp, '0 0 0', sbar_scoreboard_alpha_bg * 0.75, DRAWFLAG_NORMAL);\r
1280 \r
1281         // row highlighting\r
1282         for(i = 0; i<RANKINGS_RECEIVED_CNT; ++i)\r
1283         {\r
1284                 string n, p;\r
1285                 float t;\r
1286                 t = grecordtime[i];\r
1287                 if (t == 0)\r
1288                         continue;\r
1289                 n = grecordholder[i];\r
1290                 p = race_PlaceName(i+1);\r
1291                 if(grecordholder[i] == GetPlayerName(player_localentnum - 1))\r
1292                         drawfill(pos, '1 0 0' * sbwidth + '0 1 0' * sbar_fontsize_y, hl_rgb, sbar_scoreboard_highlight_alpha_self, DRAWFLAG_NORMAL);    \r
1293                 else if(!mod(i, 2) && sbar_scoreboard_highlight)\r
1294                         drawfill(pos, '1 0 0' * sbwidth + '0 1 0' * sbar_fontsize_y, hl_rgb, sbar_scoreboard_highlight_alpha, DRAWFLAG_NORMAL); \r
1295                 drawstring(pos, p, sbar_fontsize, '1 1 1', sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1296                 drawstring(pos + '3 0 0' * sbar_fontsize_x, TIME_ENCODED_TOSTRING(t), sbar_fontsize, '1 1 1', sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1297                 drawcolorcodedstring(pos + '8 0 0' * sbar_fontsize_x, n, sbar_fontsize, sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1298                 pos += '0 1 0' * sbar_fontsize_y;\r
1299         }\r
1300 \r
1301         return pos;\r
1302 }\r
1303 \r
1304 float scoreboard_bottom;\r
1305 float sbar_scoreboard_fade_alpha;\r
1306 float sbar_woulddrawscoreboard_prev;\r
1307 float sbar_woulddrawscoreboard_change; // "time" at which Sbar_WouldDrawScoreboard() changed\r
1308 void Sbar_DrawScoreboard()\r
1309 {\r
1310         float sbar_woulddrawscoreboard; \r
1311         sbar_woulddrawscoreboard = Sbar_WouldDrawScoreboard();\r
1312         if(sbar_woulddrawscoreboard != sbar_woulddrawscoreboard_prev) {\r
1313                 sbar_woulddrawscoreboard_change = time;\r
1314                 sbar_woulddrawscoreboard_prev = sbar_woulddrawscoreboard;\r
1315         }\r
1316 \r
1317         float scoreboard_fadeinspeed = cvar_or("sbar_scoreboard_fadeinspeed", 10);\r
1318         float scoreboard_fadeoutspeed = cvar_or("sbar_scoreboard_fadeoutspeed", 5);\r
1319         if(sbar_woulddrawscoreboard) {\r
1320                 if (scoreboard_fadeinspeed)\r
1321                         sbar_scoreboard_fade_alpha = bound (0, (time - sbar_woulddrawscoreboard_change) * scoreboard_fadeinspeed, 1);\r
1322                 else\r
1323                         sbar_scoreboard_fade_alpha = 1;\r
1324         }\r
1325         else\r
1326                 if (scoreboard_fadeoutspeed)\r
1327                         sbar_scoreboard_fade_alpha = bound (0, (1/scoreboard_fadeoutspeed - (time - sbar_woulddrawscoreboard_change)) * scoreboard_fadeoutspeed, 1);\r
1328                 else\r
1329                         sbar_scoreboard_fade_alpha = 0;\r
1330 \r
1331         if not(sbar_scoreboard_fade_alpha)\r
1332                 return;\r
1333                 \r
1334         sbar_scoreboard_alpha_bg = cvar("sbar_scoreboard_alpha_bg") * sbar_scoreboard_fade_alpha;\r
1335         sbar_scoreboard_alpha_fg = cvar_or("sbar_scoreboard_alpha_fg", 1.0) * sbar_scoreboard_fade_alpha;\r
1336         sbar_scoreboard_highlight = cvar("sbar_scoreboard_highlight");\r
1337         sbar_scoreboard_highlight_alpha = cvar_or("sbar_scoreboard_highlight_alpha", 0.10) * sbar_scoreboard_alpha_fg;\r
1338         sbar_scoreboard_highlight_alpha_self = cvar_or("sbar_scoreboard_highlight_alpha_self", 0.25) * sbar_scoreboard_alpha_fg;\r
1339         sbar_scoreboard_alpha_name = cvar_or("sbar_scoreboard_alpha_name", 0.9) * sbar_scoreboard_alpha_fg;\r
1340         sbar_scoreboard_alpha_name_self = cvar_or("sbar_scoreboard_alpha_name_self", 1) * sbar_scoreboard_alpha_fg;\r
1341         \r
1342         vector rgb, pos, tmp;\r
1343         entity pl, tm;\r
1344 \r
1345         sbwidth = Sbar_GetWidth(6.5 * sbar_fontsize_y);\r
1346 \r
1347         xmin = 0.5 * (vid_conwidth - sbwidth);\r
1348         ymin = cvar("sbar_scoreboard_offset");\r
1349 \r
1350         xmax = vid_conwidth - xmin;\r
1351         ymax = vid_conheight - 0.2*vid_conheight;\r
1352 \r
1353         // Initializes position\r
1354         pos_x = xmin;\r
1355         pos_y = ymin;\r
1356         pos_z = 0;\r
1357 \r
1358         // Heading\r
1359         drawfont = sbar_bigfont;\r
1360         if(gametype == GAME_RPG)\r
1361                 drawstringcenter('0 1 0' * ymin, "Players", '24 24 0', '1 1 1', sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1362         else\r
1363                 drawstringcenter('0 1 0' * ymin, "Scoreboard", '24 24 0', '1 1 1', sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1364 \r
1365         pos_y += 24 + 4;\r
1366         pos_y += sbar_fontsize_y;\r
1367 \r
1368         drawfont = sbar_font;\r
1369 \r
1370         // Draw the scoreboard\r
1371         vector bg_size;\r
1372         bg_size = drawgetimagesize("gfx/hud/sb_scoreboard_bg");\r
1373 \r
1374         if(teamplay)\r
1375         {\r
1376                 for(tm = teams.sort_next; tm; tm = tm.sort_next)\r
1377                 {\r
1378                         if(tm.team == COLOR_SPECTATOR)\r
1379                                 continue;\r
1380 \r
1381                         rgb = GetTeamRGB(tm.team);\r
1382                         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, sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1383                                 \r
1384                         if(ts_primary != ts_secondary)\r
1385                                 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, sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1386 \r
1387                         pos = Sbar_Scoreboard_MakeTable(pos, tm, rgb, bg_size);\r
1388                 }\r
1389         }\r
1390         else\r
1391         {\r
1392                 rgb_x = cvar("sbar_color_bg_r");\r
1393                 rgb_y = cvar("sbar_color_bg_g");\r
1394                 rgb_z = cvar("sbar_color_bg_b");\r
1395 \r
1396                 for(tm = teams.sort_next; tm; tm = tm.sort_next)\r
1397                 {\r
1398                         if(tm.team == COLOR_SPECTATOR)\r
1399                                 continue;\r
1400 \r
1401                         pos = Sbar_Scoreboard_MakeTable(pos, tm, rgb, bg_size);\r
1402                 }\r
1403         }\r
1404 \r
1405         if(gametype == GAME_CTS || gametype == GAME_RACE) {\r
1406                 if(race_speedaward) {\r
1407                         drawcolorcodedstring(pos, strcat("Speed award: ", ftos(race_speedaward), " (", race_speedaward_holder, ")"), sbar_fontsize, sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1408                         pos_y += 1.25 * sbar_fontsize_y;\r
1409                 }\r
1410                 if(race_speedaward_alltimebest) {\r
1411                         drawcolorcodedstring(pos, strcat("All-time fastest: ", ftos(race_speedaward_alltimebest), " (", race_speedaward_alltimebest_holder, ")"), sbar_fontsize, sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1412                         pos_y += 1.25 * sbar_fontsize_y;\r
1413                 }\r
1414                 pos = Sbar_DrawScoreboardRankings(pos, pl, rgb, bg_size);\r
1415         }\r
1416         else if(cvar("sbar_accuracy") && spectatee_status != -1) {\r
1417                 if(teamplay)\r
1418                         pos = Sbar_DrawScoreboardAccuracyStats(pos, GetTeamRGB(myteam), bg_size);\r
1419                 else\r
1420                         pos = Sbar_DrawScoreboardAccuracyStats(pos, rgb, bg_size);\r
1421         }\r
1422 \r
1423         tmp = pos + '0 1.5 0' * sbar_fontsize_y;\r
1424         pos_y += 3 * sbar_fontsize_y;\r
1425 \r
1426         // List spectators\r
1427         float specs;\r
1428         specs = 0;\r
1429         for(pl = players.sort_next; pl; pl = pl.sort_next)\r
1430         {\r
1431                 if(pl.team != COLOR_SPECTATOR)\r
1432                         continue;\r
1433                 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1), specs);\r
1434                 pos_y += 1.25 * sbar_fontsize_y;\r
1435                 ++specs;\r
1436         }\r
1437 \r
1438         if(specs)\r
1439                 drawstring(tmp, "Spectators", sbar_fontsize, '1 1 1', sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1440 \r
1441         // Print info string\r
1442         string str;\r
1443         float tl, fl, ll;\r
1444         if(gametype == GAME_RPG)\r
1445                 str = strcat("you are in ^2", shortmapname, "^7");\r
1446         else\r
1447                 str = strcat("playing on ^2", shortmapname, "^7");\r
1448         tl = getstatf(STAT_TIMELIMIT);\r
1449         fl = getstatf(STAT_FRAGLIMIT);\r
1450         ll = getstatf(STAT_LEADLIMIT);\r
1451         if(gametype == GAME_LMS)\r
1452         {\r
1453                 if(tl > 0)\r
1454                         str = strcat(str, " for up to ^1", ftos(tl), " minutes^7");\r
1455         }\r
1456         else\r
1457         {\r
1458                 if(tl > 0)\r
1459                         str = strcat(str, " for ^1", ftos(tl), " minutes^7");\r
1460                 if(fl > 0 && !(gametype == GAME_RPG))\r
1461                 {\r
1462                         if(tl > 0)\r
1463                                 str = strcat(str, " or");\r
1464                         if(teamplay)\r
1465                         {\r
1466                                 str = strcat(str, " until ^3", ScoreString(teamscores_flags[ts_primary], fl));\r
1467                                 if(teamscores_label[ts_primary] == "score")\r
1468                                         str = strcat(str, " points^7");\r
1469                                 else if(teamscores_label[ts_primary] == "fastest")\r
1470                                         str = strcat(str, " is beaten^7");\r
1471                                 else\r
1472                                         str = strcat(str, " ", teamscores_label[ts_primary]);\r
1473                         }\r
1474                         else\r
1475                         {\r
1476                                 str = strcat(str, " until ^3", ScoreString(scores_flags[ps_primary], fl));\r
1477                                 if(scores_label[ps_primary] == "score")\r
1478                                         str = strcat(str, " points^7");\r
1479                                 else if(scores_label[ps_primary] == "fastest")\r
1480                                         str = strcat(str, " is beaten^7");\r
1481                                 else\r
1482                                         str = strcat(str, " ", scores_label[ps_primary]);\r
1483                         }\r
1484                 }\r
1485                 if(ll > 0)\r
1486                 {\r
1487                         if(tl > 0 || fl > 0)\r
1488                                 str = strcat(str, " or");\r
1489                         if(teamplay)\r
1490                         {\r
1491                                 str = strcat(str, " until a lead of ^3", ScoreString(teamscores_flags[ts_primary], ll));\r
1492                                 if(teamscores_label[ts_primary] == "score")\r
1493                                         str = strcat(str, " points^7");\r
1494                                 else if(teamscores_label[ts_primary] == "fastest")\r
1495                                         str = strcat(str, " is beaten^7");\r
1496                                 else\r
1497                                         str = strcat(str, " ", teamscores_label[ts_primary]);\r
1498                         }\r
1499                         else\r
1500                         {\r
1501                                 str = strcat(str, " until a lead of ^3", ScoreString(scores_flags[ps_primary], ll));\r
1502                                 if(scores_label[ps_primary] == "score")\r
1503                                         str = strcat(str, " points^7");\r
1504                                 else if(scores_label[ps_primary] == "fastest")\r
1505                                         str = strcat(str, " is beaten^7");\r
1506                                 else\r
1507                                         str = strcat(str, " ", scores_label[ps_primary]);\r
1508                         }\r
1509                 }\r
1510         }\r
1511 \r
1512 \r
1513         pos_y += 1.2 * sbar_fontsize_y;\r
1514         drawcolorcodedstring(pos + '0.5 0 0' * (sbwidth - stringwidth(str, TRUE, sbar_fontsize)), str, sbar_fontsize, sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1515 \r
1516         scoreboard_bottom = pos_y + 2 * sbar_fontsize_y;\r
1517 }\r
1518 \r
1519 string MakeRaceString(float cp, float mytime, float histime, float lapdelta, string hisname)\r
1520 {\r
1521         string col;\r
1522         string timestr;\r
1523         string cpname;\r
1524         string lapstr;\r
1525         lapstr = "";\r
1526 \r
1527         if(histime == 0) // goal hit\r
1528         {\r
1529                 if(mytime > 0)\r
1530                 {\r
1531                         timestr = strcat("+", ftos_decimals(+mytime, TIME_DECIMALS));\r
1532                         col = "^1";\r
1533                 }\r
1534                 else if(mytime == 0)\r
1535                 {\r
1536                         timestr = "+0.0";\r
1537                         col = "^3";\r
1538                 }\r
1539                 else\r
1540                 {\r
1541                         timestr = strcat("-", ftos_decimals(-mytime, TIME_DECIMALS));\r
1542                         col = "^2";\r
1543                 }\r
1544 \r
1545                 if(lapdelta > 0)\r
1546                 {\r
1547                         lapstr = strcat(" (-", ftos(lapdelta), "L)");\r
1548                         col = "^2";\r
1549                 }\r
1550                 else if(lapdelta < 0)\r
1551                 {\r
1552                         lapstr = strcat(" (+", ftos(-lapdelta), "L)");\r
1553                         col = "^1";\r
1554                 }\r
1555         }\r
1556         else if(histime > 0) // anticipation\r
1557         {\r
1558                 if(mytime >= histime)\r
1559                         timestr = strcat("+", ftos_decimals(mytime - histime, TIME_DECIMALS));\r
1560                 else\r
1561                         timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(histime));\r
1562                 col = "^3";\r
1563         }\r
1564         else\r
1565                 col = "^7";\r
1566 \r
1567         if(cp == 254)\r
1568                 cpname = "Start line";\r
1569         else if(cp == 255)\r
1570                 cpname = "Finish line";\r
1571         else if(cp)\r
1572                 cpname = strcat("Intermediate ", ftos(cp));\r
1573         else\r
1574                 cpname = "Finish line";\r
1575 \r
1576         if(histime < 0)\r
1577                 return strcat(col, cpname);\r
1578         else if(hisname == "")\r
1579                 return strcat(col, cpname, " (", timestr, ")");\r
1580         else\r
1581                 return strcat(col, cpname, " (", timestr, " ", strcat(hisname, col, lapstr), ")");\r
1582 }\r
1583 \r
1584 float race_CheckName(string net_name) { // Does the name already exist in rankings? In that case, where? (otherwise 0)\r
1585         float i;\r
1586         for (i=RANKINGS_CNT-1;i>=0;--i)\r
1587                 if(grecordholder[i] == net_name)\r
1588                         return i+1;\r
1589         return 0;\r
1590 }\r
1591 \r
1592 float race_status_time;\r
1593 float race_status_prev;\r
1594 string race_status_name_prev;\r
1595 void Sbar_DrawRaceStatus(vector pos)\r
1596 {\r
1597         if (race_status != race_status_prev || race_status_name != race_status_name_prev) {\r
1598                 race_status_time = time + 5;\r
1599                 race_status_prev = race_status;\r
1600                 if (race_status_name_prev)\r
1601                         strunzone(race_status_name_prev);\r
1602                 race_status_name_prev = strzone(race_status_name);\r
1603         }\r
1604 \r
1605         float a;\r
1606         a = bound(0, race_status_time - time, 1);\r
1607 \r
1608         string s;\r
1609         s = textShortenToWidth(race_status_name, 120, '10 10 0', stringwidth_colors);\r
1610 \r
1611         float rank;\r
1612         if(race_status > 0)\r
1613                 rank = race_CheckName(race_status_name);\r
1614         string rankname;\r
1615         rankname = race_PlaceName(rank);\r
1616 \r
1617         if(race_status == 0)\r
1618                 drawpic(pos, "gfx/hud/race/newfail", '80 80 0', '1 1 1', sbar_alpha_fg * a, DRAWFLAG_NORMAL);\r
1619         else if(race_status == 1) {\r
1620                 drawpic(pos, "gfx/hud/race/newtime", '80 80 0', '1 1 1', sbar_alpha_fg * a, DRAWFLAG_NORMAL);   \r
1621                 drawcolorcodedstring(pos + '40 80 0' - '1 0 0' * stringwidth(s, TRUE, '5 0 0'), s, '10 10 0', sbar_alpha_fg * a, DRAWFLAG_NORMAL);\r
1622                 drawstring(pos + '40 20 0' - '1 0 0' * stringwidth(rankname, TRUE, '7 0 0'), rankname, '14 14 0', '1 1 1', sbar_alpha_fg * a, DRAWFLAG_NORMAL);\r
1623         } else if(race_status == 2) {\r
1624                 if(race_status_name == GetPlayerName(player_localentnum -1) || !race_myrank || race_myrank < rank)\r
1625                         drawpic(pos, "gfx/hud/race/newrankgreen", '80 80 0', '1 1 1', sbar_alpha_fg * a, DRAWFLAG_NORMAL);\r
1626                 else\r
1627                         drawpic(pos, "gfx/hud/race/newrankyellow", '80 80 0', '1 1 1', sbar_alpha_fg * a, DRAWFLAG_NORMAL);\r
1628                 drawcolorcodedstring(pos + '40 80 0' - '1 0 0' * stringwidth(s, TRUE, '5 0 0'), s, '10 10 0', sbar_alpha_fg * a, DRAWFLAG_NORMAL);\r
1629                 drawstring(pos + '40 20 0' - '1 0 0' * stringwidth(rankname, TRUE, '7 0 0'), rankname, '14 14 0', '1 1 1', sbar_alpha_fg * a, DRAWFLAG_NORMAL);\r
1630         } else if(race_status == 3) {\r
1631                 drawpic(pos, "gfx/hud/race/newrecordserver", '80 80 0', '1 1 1', sbar_alpha_fg * a, DRAWFLAG_NORMAL);\r
1632                 drawcolorcodedstring(pos + '40 80 0' - '1 0 0' * stringwidth(s, TRUE, '5 0 0'), s, '10 10 0', sbar_alpha_fg * a, DRAWFLAG_NORMAL);\r
1633                 drawstring(pos + '40 20 0' - '1 0 0' * stringwidth(rankname, TRUE, '7 0 0'), rankname, '14 14 0', '1 1 1', sbar_alpha_fg * a, DRAWFLAG_NORMAL);\r
1634         }\r
1635 \r
1636         if (race_status_time - time <= 0) {\r
1637                 race_status_prev = -1;\r
1638                 race_status = -1;\r
1639                 if(race_status_name)\r
1640                         strunzone(race_status_name);\r
1641                 race_status_name = string_null;\r
1642                 if(race_status_name_prev)\r
1643                         strunzone(race_status_name_prev);\r
1644                 race_status_name_prev = string_null;\r
1645         }\r
1646 }\r
1647 \r
1648 void Sbar_Score()\r
1649 {\r
1650         float score, distribution, leader;\r
1651         vector score_pos, secondary_score_pos, race_score_pos, distribution_color;\r
1652         string racetime;\r
1653         entity tm, pl, me;\r
1654         me = (spectatee_status > 0) ? playerslots[spectatee_status - 1] : playerslots[player_localentnum - 1];\r
1655 \r
1656         vector top;\r
1657         top_x = vid_conwidth / 2;\r
1658         top_y = 0;\r
1659         top_z = 0;\r
1660 \r
1661         if(gametype == GAME_RPG)\r
1662                 return;\r
1663 \r
1664         score_pos = top + '-80 8 0';\r
1665         secondary_score_pos = score_pos + '80 -6 0';\r
1666 \r
1667         if((scores_flags[ps_primary] & SFL_TIME) && !teamplay) { // race/cts record display on HUD\r
1668                 pl = players.sort_next;\r
1669                 if(pl == me)\r
1670                         pl = pl.sort_next;\r
1671                 if(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)\r
1672                         if(pl.scores[ps_primary] == 0)\r
1673                                 pl = world;\r
1674 \r
1675                 score = me.(scores[ps_primary]);\r
1676 \r
1677                 float racemin, racesec, racemsec;\r
1678                 float distsec, distmsec, minusplus;\r
1679                 string s_racemin, s_racesec, s_racemsec;\r
1680                 \r
1681                 racemin = floor(score/(60 * TIME_FACTOR));\r
1682                 racesec = floor((score - racemin*(60 * TIME_FACTOR))/TIME_FACTOR);\r
1683                 racemsec = score - racemin*60*TIME_FACTOR - racesec*TIME_FACTOR;\r
1684 \r
1685                 if(racemin < 10) s_racemin = strcat("0", ftos(racemin));\r
1686                 else s_racemin = ftos(racemin);\r
1687                 if(racesec < 10) s_racesec = strcat("0", ftos(racesec));\r
1688                 else s_racesec = ftos(racesec);\r
1689                 if(racemsec < 10) s_racemsec = strcat("0", ftos(racemsec));\r
1690                 else s_racemsec = ftos(racemsec);\r
1691 \r
1692                 if (pl && ((!(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)) || score)) {\r
1693                         // distribution display\r
1694                         distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);\r
1695 \r
1696                         if (distribution < TIME_FACTOR && distribution > -TIME_FACTOR)\r
1697                                 distmsec = fabs(distribution);\r
1698                         else {\r
1699                                 distsec = floor(fabs(distribution)/TIME_FACTOR);\r
1700                                 distmsec = fabs(distribution) - distsec*TIME_FACTOR;\r
1701                                 if (distribution < 0)\r
1702                                         distsec = -distsec;\r
1703                         }\r
1704 \r
1705                         if (distribution <= 0) {\r
1706                                 distribution_color = '0 1 0';\r
1707                                 minusplus = 1; // minusplus 1: always prefix with minus sign\r
1708                         }\r
1709                         else {\r
1710                                 distribution_color = '1 0 0';\r
1711                                 minusplus = 2; // minusplus 1: always prefix with plus sign\r
1712                         }\r
1713                         Sbar_DrawXNum(score_pos + '222 -6 0' - '14 0 0' * TIME_DECIMALS, distmsec, -TIME_DECIMALS, 0, 14, distribution_color, sbar_alpha_fg, DRAWFLAG_NORMAL);\r
1714                         Sbar_DrawXNum(score_pos + '222 6 0' - '14 0 0' * TIME_DECIMALS, distsec, 4, minusplus, 14, distribution_color, sbar_alpha_fg, DRAWFLAG_NORMAL);\r
1715                 }\r
1716 \r
1717                 racetime = strcat(s_racemin, " : ", s_racesec, " . ", s_racemsec);\r
1718                 race_score_pos = top + '0 0 0';\r
1719                 race_score_pos -= '1 0 0' * stringwidth(racetime, FALSE, '30 30 0') * 0.5;\r
1720                 drawstring(race_score_pos, racetime, '30 30 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE);\r
1721 \r
1722         } else if (!teamplay) { // non-teamgames, except race/cts\r
1723                 // me vector := [team/connected frags id]\r
1724                 pl = players.sort_next;\r
1725                 if(pl == me)\r
1726                         pl = pl.sort_next;\r
1727 \r
1728                 if(pl)\r
1729                         distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);\r
1730                 else\r
1731                         distribution = 0;\r
1732 \r
1733                 score = me.(scores[ps_primary]);\r
1734                 \r
1735                 if(distribution >= 5) {\r
1736                         distribution_color = '0 1 0';\r
1737                         leader = 1;\r
1738                 } else if(distribution >= 0) {\r
1739                         distribution_color = '1 1 1';\r
1740                         leader = 1;\r
1741                 } else if(distribution >= -5)\r
1742                         distribution_color = '1 1 0';\r
1743                 else\r
1744                         distribution_color = '1 0 0';\r
1745                 \r
1746                 Sbar_DrawXNum(secondary_score_pos, distribution, 6, 3, 16, distribution_color, sbar_alpha_fg, DRAWFLAG_NORMAL);\r
1747                 Sbar_DrawXNum(score_pos, score, 6, 0, 34, distribution_color, sbar_alpha_fg, DRAWFLAG_NORMAL);\r
1748         } else { // teamgames\r
1749                 float max_fragcount;\r
1750                 max_fragcount = -999;\r
1751 \r
1752                 for(tm = teams.sort_next; tm; tm = tm.sort_next) {\r
1753                         if(tm.team == COLOR_SPECTATOR || !tm.team_size) // no players? don't display\r
1754                                 continue;\r
1755                         score = tm.(teamscores[ts_primary]);\r
1756                         leader = 0;\r
1757 \r
1758                         if (score > max_fragcount)\r
1759                                 max_fragcount = score;\r
1760         \r
1761                         if(tm.team == myteam) {\r
1762                                 if (max_fragcount == score)\r
1763                                         leader = 1;\r
1764                                 Sbar_DrawXNum(score_pos, score, 6, 0, 34, GetTeamRGB(tm.team) * 0.4 + '0.6 0.6 0.6', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
1765                         } else {\r
1766                                 if (max_fragcount == score)\r
1767                                         leader = 1;\r
1768                                 Sbar_DrawXNum(secondary_score_pos, score, 6, 3, 16, GetTeamRGB(tm.team) * 0.4 + '0.6 0.6 0.6', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
1769                                 secondary_score_pos = secondary_score_pos + '0 16 0';\r
1770                         }\r
1771                 }\r
1772         }\r
1773 \r
1774         if(gametype == GAME_RACE || gametype == GAME_CTS)\r
1775         {\r
1776                 drawfont = sbar_bigfont;\r
1777                 float a, t;\r
1778                 vector m;\r
1779                 string s, forcetime;\r
1780 \r
1781                 m = '0.5 0 0' * vid_conwidth + '0 1 0' * cvar_or("cl_racetimer_position", 0.25) * vid_conheight;\r
1782 \r
1783                 if(race_checkpointtime)\r
1784                 {\r
1785                         a = bound(0, 2 - (time - race_checkpointtime), 1);\r
1786                         s = "";\r
1787                         forcetime = "";\r
1788                         if(a > 0) // just hit a checkpoint?\r
1789                         {\r
1790                                 if(race_checkpoint != 254)\r
1791                                 {\r
1792                                         if(race_time && race_previousbesttime)\r
1793                                                 s = MakeRaceString(race_checkpoint, TIME_DECODE(race_time) - TIME_DECODE(race_previousbesttime), 0, 0, race_previousbestname);\r
1794                                         else\r
1795                                                 s = MakeRaceString(race_checkpoint, 0, -1, 0, race_previousbestname);\r
1796                                         if(race_time)\r
1797                                                 forcetime = TIME_ENCODED_TOSTRING(race_time);\r
1798                                 }\r
1799                         }\r
1800                         else\r
1801                         {\r
1802                                 if(race_laptime && race_nextbesttime && race_nextcheckpoint != 254)\r
1803                                 {\r
1804                                         a = bound(0, 2 - ((race_laptime + TIME_DECODE(race_nextbesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1);\r
1805                                         if(a > 0) // next one?\r
1806                                         {\r
1807                                                 s = MakeRaceString(race_nextcheckpoint, (time + TIME_DECODE(race_penaltyaccumulator)) - race_laptime, TIME_DECODE(race_nextbesttime), 0, race_nextbestname);\r
1808                                         }\r
1809                                 }\r
1810                         }\r
1811 \r
1812                         if(s != "" && a > 0)\r
1813                         {\r
1814                                 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)\r
1815                                 //drawcolorcodedstring(m - '0 16 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', sbar_alpha_fg * a, DRAWFLAG_NORMAL);\r
1816                                 drawcolorcodedstring(m - '0 16 0' - '0.5 0 0' * stringwidth(s, TRUE, '16 16 0'), s, '16 16 0', sbar_alpha_fg * a, DRAWFLAG_NORMAL);\r
1817                         }\r
1818 \r
1819                         if(race_penaltytime)\r
1820                         {\r
1821                                 a = bound(0, 2 - (time - race_penaltyeventtime), 1);\r
1822                                 if(a > 0)\r
1823                                 {\r
1824                                         s = strcat("^1PENALTY: ", ftos_decimals(race_penaltytime * 0.1, 1), " (", race_penaltyreason, ")");\r
1825                                         dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)\r
1826                                         //drawcolorcodedstring(m - '0 32 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', sbar_alpha_fg * a, DRAWFLAG_NORMAL);\r
1827                                         drawcolorcodedstring(m - '0 32 0' - '0.5 0 0' * stringwidth(s, TRUE, '16 16 0'), s, '16 16 0', sbar_alpha_fg * a, DRAWFLAG_NORMAL);\r
1828                                 }\r
1829                         }\r
1830 \r
1831                         if(forcetime != "")\r
1832                         {\r
1833                                 a = bound(0, (time - race_checkpointtime) / 0.5, 1);\r
1834                                 //drawstring_expanding(m - '16 0 0' * stringwidth(forcetime, FALSE), forcetime, '32 32 0', '1 1 1', sbar_alpha_fg, 0, a);\r
1835                                 drawstring_expanding(m - '1 0 0' * stringwidth(forcetime, FALSE, '16 0 0'), forcetime, '32 32 0', '1 1 1', sbar_alpha_fg, 0, a);\r
1836                         }\r
1837                         else\r
1838                                 a = 1;\r
1839 \r
1840                         if(race_laptime && race_checkpoint != 255)\r
1841                         {\r
1842                                 s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime));\r
1843                                 //drawstring(m - '16 0 0' * stringwidth(s, FALSE), s, '32 32 0', '1 1 1', sbar_alpha_fg * a, DRAWFLAG_NORMAL);\r
1844                                 drawstring(m - '0.5 0 0' * stringwidth(s, FALSE, '32 32 0'), s, '32 32 0', '1 1 1', sbar_alpha_fg * a, DRAWFLAG_NORMAL);\r
1845                         }\r
1846                 }\r
1847                 else\r
1848                 {\r
1849                         if(race_mycheckpointtime)\r
1850                         {\r
1851                                 a = bound(0, 2 - (time - race_mycheckpointtime), 1);\r
1852                                 s = MakeRaceString(race_mycheckpoint, TIME_DECODE(race_mycheckpointdelta), -!race_mycheckpointenemy, race_mycheckpointlapsdelta, race_mycheckpointenemy);\r
1853                                 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)\r
1854                                 //drawcolorcodedstring(m - '0 16 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', sbar_alpha_fg * a, DRAWFLAG_NORMAL);\r
1855                                 drawcolorcodedstring(m - '0 16 0' - '0.5 0 0' * stringwidth(s, TRUE, '16 16 0'), s, '16 16 0', sbar_alpha_fg * a, DRAWFLAG_NORMAL);\r
1856                         }\r
1857                         if(race_othercheckpointtime && race_othercheckpointenemy != "")\r
1858                         {\r
1859                                 a = bound(0, 2 - (time - race_othercheckpointtime), 1);\r
1860                                 s = MakeRaceString(race_othercheckpoint, -TIME_DECODE(race_othercheckpointdelta), -!race_othercheckpointenemy, race_othercheckpointlapsdelta, race_othercheckpointenemy);\r
1861                                 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)\r
1862                                 //drawcolorcodedstring(m - '0 0 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', sbar_alpha_fg * a, DRAWFLAG_NORMAL);\r
1863                                 drawcolorcodedstring(m - '0 0 0' - '0.5 0 0' * stringwidth(s, TRUE, '16 16 0'), s, '16 16 0', sbar_alpha_fg * a, DRAWFLAG_NORMAL);\r
1864                         }\r
1865 \r
1866                         if(race_penaltytime && !race_penaltyaccumulator)\r
1867                         {\r
1868                                 t = race_penaltytime * 0.1 + race_penaltyeventtime;\r
1869                                 a = bound(0, (1 + t - time), 1);\r
1870                                 if(a > 0)\r
1871                                 {\r
1872                                         if(time < t)\r
1873                                                 s = strcat("^1PENALTY: ", ftos_decimals(t - time, 1), " (", race_penaltyreason, ")");\r
1874                                         else\r
1875                                                 s = strcat("^2PENALTY: 0.0 (", race_penaltyreason, ")");\r
1876                                         dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)\r
1877                                         //drawcolorcodedstring(m - '0 32 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', sbar_alpha_fg * a, DRAWFLAG_NORMAL);\r
1878                                         drawcolorcodedstring(m - '0 32 0' - '0.5 0 0' * stringwidth(s, TRUE, '16 16 0'), s, '16 16 0', sbar_alpha_fg * a, DRAWFLAG_NORMAL);\r
1879                                 }\r
1880                         }\r
1881                 }\r
1882 \r
1883                 drawfont = sbar_font;\r
1884         }\r
1885 }\r
1886 \r
1887 void Sbar_Timer()\r
1888 {\r
1889         float timelimit, elapsedTime, minutes, seconds, timeleft, minutesLeft, secondsLeft;\r
1890         vector pos, bgpos, timer_color;\r
1891         string finaltime;\r
1892         bgpos = '0 0 0';\r
1893         \r
1894         vector topright;\r
1895         topright = '0 0 0';\r
1896         topright_x = vid_conwidth;\r
1897         \r
1898         float scale;\r
1899         scale = cvar_or("sbar_timer_scale", 1);\r
1900         timelimit = getstatf(STAT_TIMELIMIT);\r
1901 \r
1902         if(gametype == GAME_RPG && !timelimit) // don't draw the timer in rpg if there's no time limit\r
1903                 return;\r
1904 \r
1905         Sbar_DrawRaceStatus((topright_x - 100) * '1 0 0' + '0 30 0' * scale);\r
1906         \r
1907         timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);\r
1908         timeleft = ceil(timeleft);\r
1909         minutesLeft = floor(timeleft / 60);\r
1910         secondsLeft = timeleft - minutesLeft*60;\r
1911 \r
1912         if(minutesLeft >= 5 || warmup_stage || timelimit == 0) //don't use red or yellow in warmup or when there is no timelimit\r
1913                 timer_color = '1 1 1'; //white\r
1914         else if(minutesLeft >= 1)\r
1915                 timer_color = '1 1 0'; //yellow\r
1916         else\r
1917                 timer_color = '1 0 0'; //red\r
1918 \r
1919         if (cvar("sbar_increment_maptime") || timelimit == 0 || warmup_stage) {\r
1920                 if (time < getstatf(STAT_GAMESTARTTIME)) {\r
1921                         //while restart is still active, show 00:00\r
1922                         minutes = seconds = 0;\r
1923                 } else {\r
1924                         elapsedTime = floor(time - getstatf(STAT_GAMESTARTTIME)); //127\r
1925                         minutes = floor(elapsedTime / 60);\r
1926                         seconds = elapsedTime - minutes*60;\r
1927                 }\r
1928                 if (minutes < 10)\r
1929                         bgpos_x = topright_x - (54 + 17 + 12) * scale;\r
1930                 else if (minutes < 100) // nudge the timer background left if more digits are drawn\r
1931                         bgpos_x = topright_x - (62 + 17 + 12) * scale;\r
1932                 else\r
1933                         bgpos_x = topright_x - (70 + 17 + 12) * scale;\r
1934                 bgpos_y = 0;\r
1935                 bgpos_z = 0;\r
1936         } else {\r
1937                 minutes = minutesLeft;\r
1938                 seconds = secondsLeft;\r
1939                 if (minutes == 0)\r
1940                         bgpos_x = topright_x - (58 + 7 + 12) * scale;\r
1941                 else if (minutes < 10) // nudge the timer background left if more digits are drawn\r
1942                         bgpos_x = topright_x - (66 + 17 + 12) * scale;\r
1943                 else if (minutes < 100)\r
1944                         bgpos_x = topright_x - (74 + 17 + 12) * scale;\r
1945                 else\r
1946                         bgpos_x = topright_x - (82 + 17 + 12) * scale;\r
1947                 bgpos_y = 0;\r
1948                 bgpos_z = 0;\r
1949         }\r
1950 \r
1951         if (cvar("viewsize") <= 100) { // draw timer background when viewsize <= 100\r
1952                 if (teamplay)\r
1953                         drawpic(bgpos, "gfx/hud/bg_timer", '120 30 0' * scale, GetTeamRGB(myteam) * sbar_color_bg_team, sbar_alpha_bg, DRAWFLAG_NORMAL); // timer bg color = myteam color\r
1954                 else {\r
1955                         color_x = cvar("sbar_color_bg_r");\r
1956                         color_y = cvar("sbar_color_bg_g");\r
1957                         color_z = cvar("sbar_color_bg_b");\r
1958 \r
1959                         drawpic(bgpos, "gfx/hud/bg_timer", '120 30 0' * scale, color, sbar_alpha_bg, DRAWFLAG_NORMAL);\r
1960                 }\r
1961         }\r
1962 \r
1963         drawpic(topright - ('19 0 0' + '3 0 0' - '0 2 0'), "gfx/hud/sb_time", '22 22 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
1964         if(minutesLeft >= 1 || cvar("sbar_increment_maptime") || timelimit == 0 || warmup_stage) {\r
1965                 finaltime = strcat(ftos(minutes), ":");\r
1966         }\r
1967         if(seconds < 10)\r
1968                 finaltime = strcat(finaltime, "0", ftos(seconds));\r
1969         else\r
1970                 finaltime = strcat(finaltime, ftos(seconds));\r
1971 \r
1972         pos = topright - ('24 -2 0' + '3 0 0' - '0 2 0');\r
1973         pos -= '1 0 0' * stringwidth(finaltime, FALSE, 18 * scale * '1 1 0');\r
1974         drawstring(pos, finaltime, 18 * scale * '1 1 0', timer_color, sbar_alpha_fg, DRAWFLAG_NORMAL);\r
1975 }\r
1976 \r
1977 void CSQC_Strength_Timer() {\r
1978         vector pos;\r
1979         vector bottomright;\r
1980 \r
1981         bottomright_x = vid_conwidth;\r
1982         bottomright_y = vid_conheight;\r
1983         bottomright_z = 0;\r
1984 \r
1985         float stat_items, dt;\r
1986         stat_items = getstati(STAT_ITEMS);\r
1987         /*\r
1988         if not(stat_items & IT_STRENGTH)\r
1989                 if not(stat_items & IT_INVINCIBLE)\r
1990                         return;\r
1991         */\r
1992 \r
1993         if (getstati(STAT_HEALTH) <= 0)\r
1994                 return;\r
1995 \r
1996         vector picsize;\r
1997         float strength_time, invincibility_time, countdown_fontsize;\r
1998 \r
1999         picsize = '22 22 0';\r
2000         countdown_fontsize = 18;\r
2001 \r
2002         pos = bottomright - '34 48 0';\r
2003 \r
2004         //strength\r
2005         strength_time = getstatf(STAT_STRENGTH_FINISHED);\r
2006         invincibility_time = getstatf(STAT_INVINCIBLE_FINISHED);\r
2007 \r
2008         if (strength_time) {\r
2009                 dt = strength_time - time;\r
2010                 if(dt > 0)\r
2011                 {\r
2012                         if(dt < 5)\r
2013                         {\r
2014                                 drawpic_expanding_two(pos, "gfx/hud/sb_str", picsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE,\r
2015                                         bound(0, (ceil(dt) - dt) / 0.5, 1));\r
2016                         }\r
2017                         else\r
2018                         {\r
2019                                 drawpic(pos, "gfx/hud/sb_str", picsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE);\r
2020                         }\r
2021                         Sbar_DrawXNum(pos - '30 -2 0', ceil(dt), 2, 0, countdown_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2022                 }\r
2023                 else if(dt > -1)\r
2024                 {\r
2025                         drawpic_expanding(pos, "gfx/hud/sb_str", picsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE,\r
2026                                 bound(0, -dt / 0.5, 1));\r
2027                 }\r
2028         }\r
2029 \r
2030         //invincibility\r
2031         if (invincibility_time) {\r
2032                 dt = invincibility_time - time;\r
2033                 if(dt > 0)\r
2034                 {\r
2035                         if(dt < 5)\r
2036                         {\r
2037                                 drawpic_expanding_two(pos - '0 -22 0', "gfx/hud/sb_invinc", picsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE,\r
2038                                         bound(0, (ceil(dt) - dt) / 0.5, 1));\r
2039                         }\r
2040                         else\r
2041                         {\r
2042                                 drawpic(pos - '0 -22 0', "gfx/hud/sb_invinc", picsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE);\r
2043                         }\r
2044                         Sbar_DrawXNum(pos - '30 -24 0', ceil(dt), 2, 0, countdown_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2045                 }\r
2046                 else if(dt > -1)\r
2047                 {\r
2048                         drawpic_expanding(pos - '0 -22 0', "gfx/hud/sb_invinc", picsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE,\r
2049                                 bound(0, -dt / 0.5, 1));\r
2050                 }\r
2051         }\r
2052 }\r
2053 \r
2054 #define CENTERPRINT_MAX_LINES 30\r
2055 string centerprint_messages[CENTERPRINT_MAX_LINES];\r
2056 float centerprint_width[CENTERPRINT_MAX_LINES];\r
2057 vector centerprint_start;\r
2058 float centerprint_expire;\r
2059 float centerprint_num;\r
2060 float centerprint_offset_hint;\r
2061 vector centerprint_fontsize;\r
2062 \r
2063 void centerprint(string strMessage)\r
2064 {\r
2065         float i, j, n, hcount;\r
2066         string s;\r
2067 \r
2068         centerprint_fontsize = Sbar_GetFontsize("scr_centersize");\r
2069 \r
2070         centerprint_expire = min(centerprint_expire, time); // if any of the returns happens, this message will fade out\r
2071 \r
2072         if(cvar("scr_centertime") <= 0)\r
2073                 return;\r
2074 \r
2075         if(strMessage == "")\r
2076                 return;\r
2077 \r
2078         // strip trailing newlines\r
2079         j = strlen(strMessage) - 1;\r
2080         while(substring(strMessage, j, 1) == "\n" && j >= 0)\r
2081                 j = j - 1;\r
2082         strMessage = substring(strMessage, 0, j + 1);\r
2083 \r
2084         if(strMessage == "")\r
2085                 return;\r
2086 \r
2087         // strip leading newlines and remember them, they are a hint that the message should be lower on the screen\r
2088         j = 0;\r
2089         while(substring(strMessage, j, 1) == "\n" && j < strlen(strMessage))\r
2090                 j = j + 1;\r
2091         strMessage = substring(strMessage, j, strlen(strMessage) - j);\r
2092         centerprint_offset_hint = j;\r
2093 \r
2094         if(strMessage == "")\r
2095                 return;\r
2096 \r
2097         // if we get here, we have a message. Initialize its height.\r
2098         centerprint_num = 0;\r
2099 \r
2100         n = tokenizebyseparator(strMessage, "\n");\r
2101         i = hcount = 0;\r
2102         for(j = 0; j < n; ++j)\r
2103         {\r
2104                 getWrappedLine_remaining = argv(j);\r
2105                 while(getWrappedLine_remaining)\r
2106                 {\r
2107                         s = getWrappedLine(vid_conwidth * 0.75, centerprint_fontsize, stringwidth_colors);\r
2108                         if(centerprint_messages[i])\r
2109                                 strunzone(centerprint_messages[i]);\r
2110                         centerprint_messages[i] = strzone(s);\r
2111                         centerprint_width[i] = stringwidth(s, TRUE, centerprint_fontsize);\r
2112                         ++i;\r
2113 \r
2114                         // half height for empty lines looks better\r
2115                         if(s == "")\r
2116                                 hcount += 0.5;\r
2117                         else\r
2118                                 hcount += 1;\r
2119 \r
2120                         if(i >= CENTERPRINT_MAX_LINES)\r
2121                                 break;\r
2122                 }\r
2123         }\r
2124 \r
2125         float h, havail;\r
2126         h = centerprint_fontsize_y*hcount;\r
2127 \r
2128         havail = vid_conheight;\r
2129         if(cvar("con_chatpos") < 0)\r
2130                 havail -= (-cvar("con_chatpos") + cvar("con_chat")) * cvar("con_chatsize"); // avoid overlapping chat\r
2131         if(havail > vid_conheight - 70)\r
2132                 havail = vid_conheight - 70; // avoid overlapping HUD\r
2133 \r
2134         centerprint_start_x = 0;\r
2135 \r
2136 #if 0\r
2137         float forbiddenmin, forbiddenmax, allowedmin, allowedmax, preferred;\r
2138 \r
2139         // here, the centerprint would cover the crosshair. REALLY BAD.\r
2140         forbiddenmin = vid_conheight * 0.5 - h - 16;\r
2141         forbiddenmax = vid_conheight * 0.5 + 16;\r
2142 \r
2143         allowedmin = scoreboard_bottom;\r
2144         allowedmax = havail - h;\r
2145         preferred = (havail - h)/2;\r
2146 \r
2147 \r
2148         // possible orderings (total: 4! / 4 = 6)\r
2149         //  allowedmin allowedmax forbiddenmin forbiddenmax\r
2150         //  forbiddenmin forbiddenmax allowedmin allowedmax\r
2151         if(allowedmax < forbiddenmin || allowedmin > forbiddenmax)\r
2152         {\r
2153                 // forbidden doesn't matter in this case\r
2154                 centerprint_start_y = bound(allowedmin, preferred, allowedmax);\r
2155         }\r
2156         //  allowedmin forbiddenmin allowedmax forbiddenmax\r
2157         else if(allowedmin < forbiddenmin && allowedmax < forbiddenmax)\r
2158         {\r
2159                 centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);\r
2160         }\r
2161         //  allowedmin forbiddenmin forbiddenmax allowedmax\r
2162         else if(allowedmin < forbiddenmin)\r
2163         {\r
2164                 // make sure the forbidden zone is not covered\r
2165                 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)\r
2166                         centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);\r
2167                 else\r
2168                         centerprint_start_y = bound(forbiddenmax, preferred, allowedmin);\r
2169         }\r
2170         //  forbiddenmin allowedmin allowedmax forbiddenmax\r
2171         else if(allowedmax < forbiddenmax)\r
2172         {\r
2173                 // it's better to leave the allowed zone (overlap with scoreboard) than\r
2174                 // to cover the forbidden zone (crosshair)\r
2175                 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)\r
2176                         centerprint_start_y = forbiddenmax;\r
2177                 else\r
2178                         centerprint_start_y = forbiddenmin;\r
2179         }\r
2180         //  forbiddenmin allowedmin forbiddenmax allowedmax\r
2181         else\r
2182         {\r
2183                 centerprint_start_y = bound(forbiddenmax, preferred, allowedmax);\r
2184         }\r
2185 #else\r
2186         centerprint_start_y =\r
2187                 min(\r
2188                         max(\r
2189                                 max(scoreboard_bottom, vid_conheight * 0.5 + 16),\r
2190                                 (havail - h)/2\r
2191                         ),\r
2192                         havail - h\r
2193                 );\r
2194 #endif\r
2195 \r
2196         centerprint_num = i;\r
2197         centerprint_expire = time + cvar("scr_centertime");\r
2198 }\r
2199 \r
2200 void Sbar_DrawCenterPrint (void)\r
2201 {\r
2202         float i;\r
2203         vector pos;\r
2204         string ts;\r
2205         float a;\r
2206 \r
2207         //if(time > centerprint_expire)\r
2208         //      return;\r
2209 \r
2210         //a = bound(0, 1 - 2 * (time - centerprint_expire), 1);\r
2211         a = bound(0, 1 - 4 * (time - centerprint_expire), 1);\r
2212         //sz = 1.2 / (a + 0.2);\r
2213 \r
2214         if(a <= 0)\r
2215                 return;\r
2216 \r
2217         pos = centerprint_start;\r
2218         for (i=0; i<centerprint_num; i = i + 1)\r
2219         {\r
2220                 pos_x = (vid_conwidth - centerprint_width[i]) * 0.5;\r
2221                 ts = centerprint_messages[i];\r
2222                 if (ts != "")\r
2223                 {\r
2224                         dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)\r
2225                         drawcolorcodedstring(pos, ts, centerprint_fontsize, a, DRAWFLAG_NORMAL);\r
2226                         //  - '0 0.5 0' * (sz - 1) * centerprint_fontsize_x - '0.5 0 0' * (sz - 1) * centerprint_width[i] * centerprint_fontsize_y, centerprint_fontsize * sz\r
2227                         pos_y = pos_y + centerprint_fontsize_y;\r
2228                 }\r
2229                 else\r
2230                         // half height for empty lines looks better\r
2231                         pos_y = pos_y + centerprint_fontsize_y * 0.5;\r
2232         }\r
2233 }\r
2234 \r
2235 vector Sbar_DrawNoteLine(vector offset, string s)\r
2236 {\r
2237         dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)\r
2238         drawcolorcodedstring(\r
2239                 offset - '1 0 0' * stringwidth(s, TRUE, sbar_fontsize),\r
2240                 s,\r
2241                 sbar_fontsize,\r
2242                 sbar_alpha_fg,\r
2243                 0\r
2244         );\r
2245         return offset + sbar_fontsize_y * '0 1 0';\r
2246 }\r
2247 \r
2248 void Sbar_DrawPressedKeys(void)\r
2249 {\r
2250         vector pos, bgsize;\r
2251         float pressedkeys;\r
2252 \r
2253         pos = stov(cvar_string("cl_showpressedkeys_position"));\r
2254 \r
2255         bgsize = '126 75 0';\r
2256 \r
2257         pos = '1 0 0' * (vid_conwidth - bgsize_x) * pos_x\r
2258             + '0 1 0' * (vid_conheight - bgsize_y) * pos_y;\r
2259         pos -= '-15 -6 0'; // adjust to the origin of these numbers\r
2260 \r
2261         pressedkeys = getstatf(STAT_PRESSED_KEYS);\r
2262         drawpic(pos + '-15   -6   0', "gfx/hud/keys/key_bg.tga",           bgsize, '1 1 1', 0.1 * sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2263         drawpic(pos + ' 83.5  9   0', ((pressedkeys & KEY_CROUCH) ? "gfx/hud/keys/key_crouch_inv.tga" : "gfx/hud/keys/key_crouch.tga"), ' 24 24 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2264         drawpic(pos + ' 32   -1.5 0', ((pressedkeys & KEY_FORWARD) ? "gfx/hud/keys/key_forward_inv.tga" : "gfx/hud/keys/key_forward.tga"),  ' 32 32 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2265         drawpic(pos + '-11.5  9   0', ((pressedkeys & KEY_JUMP) ? "gfx/hud/keys/key_jump_inv.tga" : "gfx/hud/keys/key_jump.tga"),     ' 24 24 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2266         drawpic(pos + ' -1   32   0', ((pressedkeys & KEY_LEFT) ? "gfx/hud/keys/key_left_inv.tga" : "gfx/hud/keys/key_left.tga"),     ' 32 32 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2267         drawpic(pos + ' 32   32   0', ((pressedkeys & KEY_BACKWARD) ? "gfx/hud/keys/key_backward_inv.tga" : "gfx/hud/keys/key_backward.tga"), ' 32 32 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2268         drawpic(pos + ' 65   32   0', ((pressedkeys & KEY_RIGHT) ? "gfx/hud/keys/key_right_inv.tga" : "gfx/hud/keys/key_right.tga"),    ' 32 32 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2269 }\r
2270 \r
2271 void Sbar_ShowSpeed(void)\r
2272 {\r
2273         vector numsize;\r
2274         float pos, conversion_factor;\r
2275         string speed, zspeed, unit;\r
2276 \r
2277         switch(cvar("cl_showspeed_unit"))\r
2278         {\r
2279                 default:\r
2280                 case 0:\r
2281                         unit = "";\r
2282                         conversion_factor = 1.0;\r
2283                         break;\r
2284                 case 1:\r
2285                         unit = " qu/s";\r
2286                         conversion_factor = 1.0;\r
2287                         break;\r
2288                 case 2:\r
2289                         unit = " m/s";\r
2290                         conversion_factor = 0.0254;\r
2291                         break;\r
2292                 case 3:\r
2293                         unit = " km/h";\r
2294                         conversion_factor = 0.0254 * 3.6;\r
2295                         break;\r
2296                 case 4:\r
2297                         unit = " mph";\r
2298                         conversion_factor = 0.0254 * 3.6 * 0.6213711922;\r
2299                         break;\r
2300                 case 5:\r
2301                         unit = " knots";\r
2302                         conversion_factor = 0.0254 * 1.943844492; // 1 m/s = 1.943844492 knots, because 1 knot = 1.852 km/h\r
2303                         break;\r
2304         }\r
2305 \r
2306         speed = strcat(ftos(floor( vlen(pmove_vel - pmove_vel_z * '0 0 1') * conversion_factor + 0.5 )), unit);\r
2307 \r
2308         numsize_x = numsize_y = cvar("cl_showspeed_size");\r
2309         pos = (vid_conheight - numsize_y) * cvar("cl_showspeed_position");\r
2310         \r
2311         drawfont = sbar_bigfont;\r
2312         drawstringcenter('1 0 0' + pos * '0 1 0', speed, numsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2313 \r
2314         if (cvar("cl_showspeed_z") == 1) {\r
2315                 zspeed = strcat(ftos(fabs(floor( pmove_vel_z * conversion_factor + 0.5 ))), unit);\r
2316                 drawstringcenter('1 0 0' + pos * '0 1 0' + numsize_y * '0 1 0', zspeed, numsize * 0.5, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2317         }\r
2318 \r
2319         drawfont = sbar_font;\r
2320 }\r
2321 \r
2322 vector acc_prevspeed;\r
2323 float acc_prevtime;\r
2324 float acc_avg;\r
2325 \r
2326 void Sbar_ShowAcceleration(void)\r
2327 {\r
2328         float acceleration, sz, scale, alpha, f;\r
2329         vector pos, top, rgb;\r
2330         top_x = vid_conwidth/2;\r
2331         top_y = 0;\r
2332 \r
2333         f = time - acc_prevtime;\r
2334         if(cvar("cl_showacceleration_z"))\r
2335                 acceleration = (vlen(pmove_vel) - vlen(acc_prevspeed)) * (1 / f);\r
2336         else\r
2337                 acceleration = (vlen(pmove_vel - '0 0 1' * pmove_vel_z) - vlen(acc_prevspeed - '0 0 1' * acc_prevspeed_z)) * (1 / f);\r
2338         acc_prevspeed = pmove_vel;\r
2339         acc_prevtime = time;\r
2340 \r
2341         f = bound(0, f * 10, 1);\r
2342         acc_avg = acc_avg * (1 - f) + acceleration * f;\r
2343         acceleration = acc_avg / getstatf(STAT_MOVEVARS_MAXSPEED);\r
2344 \r
2345         pos = top - sz/2 * '0 1 0' + (cvar("cl_showacceleration_position") * vid_conheight) * '0 1 0';\r
2346 \r
2347         sz = cvar("cl_showacceleration_size");\r
2348         scale = cvar("cl_showacceleration_scale");\r
2349         alpha = cvar("cl_showacceleration_alpha");\r
2350         if (cvar("cl_showacceleration_color_custom"))\r
2351                 rgb = stov(cvar_string("cl_showacceleration_color"));\r
2352         else {\r
2353                 rgb = '1 1 1';\r
2354                 if (acceleration < 0) {\r
2355                         rgb = '1 .5 .5' - '0 .5 .5' * bound(0, -acceleration * 0.2, 1);\r
2356                 } else if (acceleration > 0) {\r
2357                         rgb = '.5 1 .5' - '.5 0 .5' * bound(0, +acceleration * 0.2, 1);\r
2358                 }\r
2359         }\r
2360                 \r
2361         if (acceleration > 0)\r
2362                 drawpic(pos, "gfx/hud/accelerometer_gradient", acceleration * scale * '40 0 0' + sz * '0 1 0', rgb, alpha * sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2363         else if (acceleration < 0)\r
2364                 drawpic(pos + acceleration * scale * '40 0 0', "gfx/hud/accelerometer_gradient", -acceleration * scale * '40 0 0' + sz * '0 1 0', rgb, alpha * sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2365 }\r
2366 \r
2367 void Sbar_DrawAccuracyStats_Description_Hitscan(vector position)\r
2368 {\r
2369         drawstring(position + '0 3 0' * sbar_fontsize_y, "Shots fired:", sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2370         drawstring(position + '0 5 0' * sbar_fontsize_y, "Shots hit:", sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2371         drawstring(position + '0 7 0' * sbar_fontsize_y, "Accuracy:", sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2372         drawstring(position + '0 9 0' * sbar_fontsize_y, "Shots missed:", sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2373 }\r
2374 \r
2375 /*void Sbar_DrawAccuracyStats_Description_Splash(vector position)\r
2376 {\r
2377         drawstring(position + '0 3 0' * sbar_fontsize_y, "Maximum damage:", sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2378         drawstring(position + '0 5 0' * sbar_fontsize_y, "Actual damage:", sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2379         drawstring(position + '0 7 0' * sbar_fontsize_y, "Accuracy:", sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2380         drawstring(position + '0 9 0' * sbar_fontsize_y, "Damage wasted:", sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2381 }*/ // we have no splash damage weapons, but keep this code just in case\r
2382 \r
2383 void Sbar_DrawAccuracyStats()\r
2384 {\r
2385         float i, count_hitscan, /*count_splash,*/ row_hitscan/*, row_splash*/;  // count is the number of 'colums'\r
2386         float weapon_hit, weapon_damage, weapon_stats;\r
2387         float left_border;  // position where the weapons start, the description is in the border\r
2388         vector fill_colour, fill_size;\r
2389         vector pos;\r
2390         vector border_colour;\r
2391 \r
2392         float col_margin = 20;  // pixels between the columns\r
2393         float row_margin = 20;  // pixels between the rows\r
2394 \r
2395         fill_size_x = 5 * sbar_fontsize_x;  // width of the background\r
2396         fill_size_y = 10 * sbar_fontsize_y;  // height of the background\r
2397 \r
2398         drawfont = sbar_bigfont;\r
2399         pos_x = 0;\r
2400         pos_y = cvar("sbar_scoreboard_offset");\r
2401         pos_z = 0;\r
2402         drawstringcenter(pos, "Weapon Accuracy", 2 * sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2403 \r
2404         left_border = col_margin + 11 * sbar_fontsize_x;\r
2405 \r
2406         drawfont = sbar_font;\r
2407 \r
2408         if(warmup_stage)\r
2409         {\r
2410                 pos_y += 40;\r
2411                 if(mod(time, 1) >= 0.4)\r
2412                         drawstringcenter(pos, "Stats are not tracked during warmup stage", sbar_fontsize, '1 1 0', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2413 \r
2414                 return;\r
2415         }\r
2416 \r
2417         if(gametype == GAME_RACE || gametype == GAME_CTS)\r
2418         {\r
2419                 pos_y += 40;\r
2420                 if(mod(time, 1) >= 0.4)\r
2421                         drawstringcenter(pos, "Stats are not tracked in Race/CTS", sbar_fontsize, '1 1 0', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2422 \r
2423                 return;\r
2424         }\r
2425 \r
2426         float top_border_hitscan = cvar("sbar_scoreboard_offset") + 55;  // position where the hitscan row starts: pixels down the screen\r
2427         Sbar_DrawAccuracyStats_Description_Hitscan('1 0 0' * col_margin + '0 1 0' * top_border_hitscan);\r
2428 \r
2429 //      float top_border_splash = cvar("sbar_scoreboard_offset") + 175;  // position where the splash row starts: pixels down the screen\r
2430 //      Sbar_DrawAccuracyStats_Description_Splash('1 0 0' * col_margin + '0 1 0' * top_border_splash);\r
2431 \r
2432         for(i = WEP_FIRST; i <= WEP_LAST; ++i)\r
2433         {\r
2434                 self = get_weaponinfo(i);\r
2435                 if not(self.weapons)\r
2436                         continue;\r
2437                 weapon_hit = weapon_hits[i-WEP_FIRST];\r
2438                 weapon_damage = weapon_fired[i-WEP_FIRST];\r
2439                 border_colour = (i == activeweapon) ? '1 1 1' : '0 0 0';  // white or black border\r
2440 \r
2441                 if (weapon_damage) {\r
2442                         /*if (self.spawnflags & WEP_TYPE_SPLASH) {\r
2443                                 weapon_stats = bound(0, floor(100 * weapon_hit / weapon_damage), 100);\r
2444 \r
2445                                 fill_colour_x = 1 - 0.015 * weapon_stats;\r
2446                                 fill_colour_y = 1 - 0.015 * (100 - weapon_stats);\r
2447 \r
2448                                 // how the background colour is calculated\r
2449                                 // %    red             green   red_2                   green_2\r
2450                                 // 0    1               0               1 - % * 0.015   1 - (100 - %) * 0.015\r
2451                                 // 10   0.85    0               1 - % * 0.015   1 - (100 - %) * 0.015\r
2452                                 // 20   0.70    0               1 - % * 0.015   1 - (100 - %) * 0.015\r
2453                                 // 30   0.55    0               1 - % * 0.015   1 - (100 - %) * 0.015\r
2454                                 // 40   0.40    0.10    1 - % * 0.015   1 - (100 - %) * 0.015\r
2455                                 // 50   0.25    0.25    1 - % * 0.015   1 - (100 - %) * 0.015\r
2456                                 // 60   0.10    0.40    1 - % * 0.015   1 - (100 - %) * 0.015\r
2457                                 // 70   0               0.55    1 - % * 0.015   1 - (100 - %) * 0.015\r
2458                                 // 80   0               0.70    1 - % * 0.015   1 - (100 - %) * 0.015\r
2459                                 // 90   0               0.85    1 - % * 0.015   1 - (100 - %) * 0.015\r
2460                                 // 100  0               1               1 - % * 0.015   1 - (100 - %) * 0.015\r
2461 \r
2462                                 if ((left_border + count_splash * (fill_size_x + col_margin) + fill_size_x) >= vid_conwidth)\r
2463                                 {\r
2464                                         count_splash = 0;\r
2465                                         ++row_splash;\r
2466                                         Sbar_DrawAccuracyStats_Description_Splash('1 0 0' * col_margin + '0 1 0' * (top_border_splash + row_splash * (fill_size_y + row_margin)));\r
2467                                 }\r
2468 \r
2469                                 pos_x = left_border + count_splash * (fill_size_x + col_margin);\r
2470                                 pos_y = top_border_splash + row_splash * (fill_size_y + row_margin);\r
2471 \r
2472                                 // background\r
2473                                 drawpic(pos, "gfx/hud/sb_accuracy", fill_size , fill_colour, sbar_alpha_bg, DRAWFLAG_NORMAL);\r
2474                                 drawborderlines(sbar_border_thickness, pos, fill_size, border_colour, sbar_alpha_bg, DRAWFLAG_NORMAL);\r
2475 \r
2476                                 // the weapon\r
2477                                 drawpic(pos, strcat("gfx/hud/inv_weapon", self.netname), '1 0.5 0' * fill_size_x , '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2478 \r
2479                                 // the amount of shots fired or max damage\r
2480                                 drawstringright(pos + '4.5 0 0' * sbar_fontsize_x + '0 3 0' * sbar_fontsize_y, ftos(weapon_damage), sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2481 \r
2482                                 // the amount of hits or actual damage\r
2483                                 drawstringright(pos + '4.5 0 0' * sbar_fontsize_x + '0 5 0' * sbar_fontsize_y, ftos(weapon_hit), sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2484 \r
2485                                 // the accuracy\r
2486                                 drawstringright(pos + '4.5 0 0' * sbar_fontsize_x + '0 7 0' * sbar_fontsize_y, strcat(ftos(weapon_stats),"%"), sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2487 \r
2488                                 // the amount of shots missed or damage wasted\r
2489                                 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', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2490 \r
2491                                 ++count_splash;\r
2492                         } else*/ // we have no splash damage weapons, but keep this code just in case\r
2493 \r
2494                         if (self.spawnflags & WEP_TYPE_HITSCAN) {\r
2495                                 weapon_stats = bound(0, floor(100 * weapon_hit / weapon_damage), 100);\r
2496 \r
2497                                 fill_colour_x = 1 - 0.015 * weapon_stats;\r
2498                                 fill_colour_y = 1 - 0.015 * (100 - weapon_stats);\r
2499 \r
2500                                 // how the background colour is calculated\r
2501                                 // %    red             green   red_2                   green_2\r
2502                                 // 0    1               0               1 - % * 0.015   1 - (100 - %) * 0.015\r
2503                                 // 10   0.850   0               1 - % * 0.015   1 - (100 - %) * 0.015\r
2504                                 // 20   0.70    0               1 - % * 0.015   1 - (100 - %) * 0.015\r
2505                                 // 30   0.55    0               1 - % * 0.015   1 - (100 - %) * 0.015\r
2506                                 // 40   0.40    0.10    1 - % * 0.015   1 - (100 - %) * 0.015\r
2507                                 // 50   0.25    0.25    1 - % * 0.015   1 - (100 - %) * 0.015\r
2508                                 // 60   0.10    0.40    1 - % * 0.015   1 - (100 - %) * 0.015\r
2509                                 // 70   0               0.55    1 - % * 0.015   1 - (100 - %) * 0.015\r
2510                                 // 80   0               0.70    1 - % * 0.015   1 - (100 - %) * 0.015\r
2511                                 // 90   0               0.85    1 - % * 0.015   1 - (100 - %) * 0.015\r
2512                                 // 100  0               1               1 - % * 0.015   1 - (100 - %) * 0.015\r
2513 \r
2514                                 if ((left_border + count_hitscan * (fill_size_x + col_margin) + fill_size_x + cvar("stats_right_margin")) >= vid_conwidth)\r
2515                                 {\r
2516                                         count_hitscan = 0;\r
2517                                         ++row_hitscan;\r
2518                                         Sbar_DrawAccuracyStats_Description_Hitscan('1 0 0' * col_margin + '0 1 0' * (top_border_hitscan + row_hitscan * (fill_size_y + row_margin)));\r
2519                                 }\r
2520 \r
2521                                 pos_x = left_border + count_hitscan * (fill_size_x + col_margin);\r
2522                                 pos_y = top_border_hitscan + row_hitscan * (fill_size_y + row_margin);\r
2523 \r
2524                                 // background\r
2525                                 drawpic(pos, "gfx/hud/sb_accuracy", fill_size , fill_colour, sbar_alpha_bg, DRAWFLAG_NORMAL);\r
2526                                 drawborderlines(sbar_border_thickness, pos, fill_size, border_colour, sbar_alpha_bg, DRAWFLAG_NORMAL);\r
2527 \r
2528                                 // the weapon\r
2529                                 drawpic(pos, strcat("gfx/hud/inv_weapon", self.netname), '1 0.5 0' * fill_size_x , '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2530 \r
2531                                 // the amount of shots fired or max damage\r
2532                                 drawstringright(pos + '4.5 0 0' * sbar_fontsize_x + '0 3 0' * sbar_fontsize_y, ftos(weapon_damage), sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2533 \r
2534                                 // the amount of hits or actual damage\r
2535                                 drawstringright(pos + '4.5 0 0' * sbar_fontsize_x + '0 5 0' * sbar_fontsize_y, ftos(weapon_hit), sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2536 \r
2537                                 // the accuracy\r
2538                                 drawstringright(pos + '4.5 0 0' * sbar_fontsize_x + '0 7 0' * sbar_fontsize_y, strcat(ftos(weapon_stats),"%"), sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2539 \r
2540                                 // the amount of shots missed or damage wasted\r
2541                                 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', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2542 \r
2543                                 ++count_hitscan;\r
2544                         }\r
2545                 }\r
2546         }\r
2547 }\r
2548 \r
2549 void drawstringright(vector position, string text, vector scale, vector rgb, float alpha, float flag)\r
2550 {\r
2551         position_x -= 2 / 3 * strlen(text) * scale_x;\r
2552         drawstring(position, text, scale, rgb, alpha, flag);\r
2553 }\r
2554 \r
2555 void drawstringcenter(vector position, string text, vector scale, vector rgb, float alpha, float flag)\r
2556 {\r
2557         position_x = 0.5 * (vid_conwidth - 0.6025 * strlen(text) * scale_x);\r
2558         drawstring(position, text, scale, rgb, alpha, flag);\r
2559 }\r
2560 \r
2561 float GetAmmoStat(float i)\r
2562 {\r
2563         switch(i)\r
2564         {\r
2565                 case 0: return STAT_FUEL;\r
2566                 default: return -1;\r
2567         }\r
2568 }\r
2569 \r
2570 float GetAmmoItemCode(float i)\r
2571 {\r
2572         switch(i)\r
2573         {\r
2574                 case 0: return IT_FUEL;\r
2575                 default: return -1;\r
2576         }\r
2577 }\r
2578 \r
2579 string GetAmmoPicture(float i)\r
2580 {\r
2581         switch(i)\r
2582         {\r
2583                 case 0: return "gfx/hud/sb_fuel";\r
2584                 default: return "";\r
2585         }\r
2586 }\r
2587 \r
2588 void Sbar_Reset (void)\r
2589 {\r
2590         // reset gametype specific icons\r
2591         if(gametype == GAME_KEYHUNT)\r
2592                 CSQC_kh_hudreset();\r
2593         else if(gametype == GAME_CTF)\r
2594                 CSQC_ctf_hudreset();\r
2595 }\r
2596 \r
2597 float vote_yescount;\r
2598 float vote_nocount;\r
2599 float vote_needed;\r
2600 float vote_highlighted; // currently selected vote\r
2601 \r
2602 float vote_active; // is there an active vote?\r
2603 float vote_prev; // previous state of vote_active to check for a change\r
2604 float vote_alpha;\r
2605 float vote_change; // "time" when vote_active changed\r
2606 \r
2607 vector stomachstatus_colorfade_current;\r
2608 vector StomachStatus_ColorFade(vector target_color)\r
2609 {\r
2610         local float step;\r
2611         step = cvar("sbar_stomachboard_status_fade") * frametime;\r
2612 \r
2613         if(stomachstatus_colorfade_current_x >= target_color_x + step)\r
2614                 stomachstatus_colorfade_current_x -= step;\r
2615         else if(stomachstatus_colorfade_current_x <= target_color_x - step)\r
2616                 stomachstatus_colorfade_current_x += step;\r
2617 \r
2618         if(stomachstatus_colorfade_current_y >= target_color_y + step)\r
2619                 stomachstatus_colorfade_current_y -= step;\r
2620         else if(stomachstatus_colorfade_current_y <= target_color_y - step)\r
2621                 stomachstatus_colorfade_current_y += step;\r
2622 \r
2623         if(stomachstatus_colorfade_current_z >= target_color_z + step)\r
2624                 stomachstatus_colorfade_current_z -= step;\r
2625         else if(stomachstatus_colorfade_current_z <= target_color_z - step)\r
2626                 stomachstatus_colorfade_current_z += step;\r
2627 \r
2628         return stomachstatus_colorfade_current;\r
2629 }\r
2630 \r
2631 void Sbar_Draw (void)\r
2632 {\r
2633         // vectors for top right, bottom right, bottom and bottom left corners\r
2634         vector topright;\r
2635         vector bottom;\r
2636         vector bottomright;\r
2637         vector bottomleft;\r
2638 \r
2639         topright_x = vid_conwidth;\r
2640         topright_y = 0;\r
2641         topright_z = 0;\r
2642 \r
2643         bottom_x = vid_conwidth/2;\r
2644         bottom_y = vid_conheight;\r
2645         bottom_z = 0;\r
2646 \r
2647         bottomright_x = vid_conwidth;\r
2648         bottomright_y = vid_conheight;\r
2649         bottomright_z = 0;\r
2650 \r