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