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