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