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