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