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