04a51543c3df0dba2938c831043f4ff6542b026b
[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, TRUE, 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         drawcolorcodedstring(pos, text, sz, 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 string Sbar_GetTexture(string img)\r
805 {\r
806         string path = cvar_string("hud_style");\r
807         return strcat("gfx/hud/", path, "/", img);\r
808 }\r
809 \r
810 float xmin, xmax, ymin, ymax, sbwidth;\r
811 float sbar_fixscoreboardcolumnwidth_len;\r
812 float sbar_fixscoreboardcolumnwidth_iconlen;\r
813 float sbar_fixscoreboardcolumnwidth_marginlen;\r
814 \r
815 float stringwidth_colors(string s, vector theSize)\r
816 {\r
817         return stringwidth(s, TRUE, theSize);\r
818 }\r
819 \r
820 float stringwidth_nocolors(string s, vector theSize)\r
821 {\r
822         return stringwidth(s, FALSE, theSize);\r
823 }\r
824 \r
825 string Sbar_FixScoreboardColumnWidth(float i, string str)\r
826 {\r
827         float field, f;\r
828         vector sz;\r
829         field = sbar_field[i];\r
830 \r
831         sbar_fixscoreboardcolumnwidth_iconlen = 0;\r
832 \r
833         if(sbar_field_icon0 != "")\r
834         {\r
835                 sz = drawgetimagesize(sbar_field_icon0);\r
836                 f = sz_x / sz_y;\r
837                 if(sbar_fixscoreboardcolumnwidth_iconlen < f)\r
838                         sbar_fixscoreboardcolumnwidth_iconlen = f;\r
839         }\r
840 \r
841         if(sbar_field_icon1 != "")\r
842         {\r
843                 sz = drawgetimagesize(sbar_field_icon1);\r
844                 f = sz_x / sz_y;\r
845                 if(sbar_fixscoreboardcolumnwidth_iconlen < f)\r
846                         sbar_fixscoreboardcolumnwidth_iconlen = f;\r
847         }\r
848 \r
849         if(sbar_field_icon2 != "")\r
850         {\r
851                 sz = drawgetimagesize(sbar_field_icon2);\r
852                 f = sz_x / sz_y;\r
853                 if(sbar_fixscoreboardcolumnwidth_iconlen < f)\r
854                         sbar_fixscoreboardcolumnwidth_iconlen = f;\r
855         }\r
856 \r
857         sbar_fixscoreboardcolumnwidth_iconlen *= sbar_fontsize_y / sbar_fontsize_x; // fix icon aspect\r
858 \r
859         if(sbar_fixscoreboardcolumnwidth_iconlen != 0)\r
860                 sbar_fixscoreboardcolumnwidth_marginlen = stringwidth(" ", FALSE, sbar_fontsize);\r
861         else\r
862                 sbar_fixscoreboardcolumnwidth_marginlen = 0;\r
863 \r
864         if(field == SP_NAME) // name gets all remaining space\r
865         {\r
866                 float namesize, j;\r
867                 namesize = sbwidth;// / sbar_fontsize_x;\r
868                 for(j = 0; j < sbar_num_fields; ++j)\r
869                         if(j != i)\r
870                                 if (sbar_field[i] != SP_SEPARATOR)\r
871                                         namesize -= sbar_size[j] + 1;\r
872                 namesize += 1;\r
873                 sbar_size[i] = namesize;\r
874                 \r
875                 if (sbar_fixscoreboardcolumnwidth_iconlen != 0)\r
876                         namesize -= sbar_fixscoreboardcolumnwidth_marginlen + sbar_fixscoreboardcolumnwidth_iconlen;\r
877                 str = textShortenToWidth(str, namesize, sbar_fontsize, stringwidth_colors);\r
878                 sbar_fixscoreboardcolumnwidth_len = stringwidth(str, TRUE, sbar_fontsize);\r
879         }\r
880         else\r
881                 sbar_fixscoreboardcolumnwidth_len = stringwidth(str, FALSE, sbar_fontsize);\r
882         \r
883         f = sbar_fixscoreboardcolumnwidth_len + sbar_fixscoreboardcolumnwidth_marginlen + sbar_fixscoreboardcolumnwidth_iconlen;\r
884         if(sbar_size[i] < f)\r
885                 sbar_size[i] = f;\r
886 \r
887         return str;\r
888 }\r
889 \r
890 void Sbar_PrintScoreboardItem(vector pos, entity pl, float is_self, float pl_number)\r
891 {\r
892         vector tmp, rgb;\r
893         rgb = GetTeamRGB(pl.team);\r
894         string str;\r
895         float i, field;\r
896         float is_spec;\r
897         is_spec = (GetPlayerColor(pl.sv_entnum) == COLOR_SPECTATOR);\r
898         \r
899         if((rgb == '1 1 1') && (!is_spec))\r
900                 rgb = stov(cvar_string("sbar_color_bg")) + '0.5 0.5 0.5';\r
901 \r
902         // Layout:\r
903         tmp_x = sbwidth;\r
904         tmp_y = sbar_fontsize_y * 1.25;\r
905         tmp_z = 0;\r
906 \r
907         // alternated rows highlighting\r
908         if(is_self)\r
909                 drawfill(pos - '1 1 0', tmp + '2 0 0', rgb, sbar_scoreboard_highlight_alpha_self, DRAWFLAG_NORMAL);\r
910         else if((sbar_scoreboard_highlight) && (!mod(pl_number,2)))\r
911                 drawfill(pos - '1 1 0', tmp + '2 0 0', rgb, sbar_scoreboard_highlight_alpha, DRAWFLAG_NORMAL);\r
912 \r
913         tmp_y = 0;\r
914 \r
915         for(i = 0; i < sbar_num_fields; ++i)\r
916         {\r
917                 field = sbar_field[i];\r
918                 if(field == SP_SEPARATOR)\r
919                         break;\r
920 \r
921                 if(is_spec && field != SP_NAME && field != SP_PING) {\r
922                         pos_x += sbar_size[i] + sbar_fontsize_x;\r
923                         continue;\r
924                 }\r
925                 str = Sbar_GetField(pl, field);\r
926                 str = Sbar_FixScoreboardColumnWidth(i, str);\r
927 \r
928                 pos_x += sbar_size[i] + sbar_fontsize_x;\r
929 \r
930                 if(field == SP_NAME) {\r
931                         tmp_x = sbar_size[i] - sbar_fontsize_x*sbar_fixscoreboardcolumnwidth_iconlen - sbar_fixscoreboardcolumnwidth_marginlen + sbar_fontsize_x;\r
932                         if (is_self)\r
933                                 drawcolorcodedstring(pos - tmp, str, sbar_fontsize, sbar_scoreboard_alpha_name_self, DRAWFLAG_NORMAL);\r
934                         else\r
935                                 drawcolorcodedstring(pos - tmp, str, sbar_fontsize, sbar_scoreboard_alpha_name, DRAWFLAG_NORMAL);\r
936                 } else {\r
937                         tmp_x = sbar_fixscoreboardcolumnwidth_len + sbar_fontsize_x;\r
938                         if (is_self)\r
939                                 drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, sbar_scoreboard_alpha_name_self, DRAWFLAG_NORMAL);\r
940                         else\r
941                                 drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, sbar_scoreboard_alpha_name, DRAWFLAG_NORMAL);\r
942                 }\r
943 \r
944                 tmp_x = sbar_size[i] + sbar_fontsize_x;\r
945                 if(sbar_field_icon0 != "")\r
946                         if (is_self)\r
947                                 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
948                         else\r
949                                 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
950                 if(sbar_field_icon1 != "")\r
951                         if (is_self)\r
952                                 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
953                         else\r
954                                 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
955                 if(sbar_field_icon2 != "")\r
956                         if (is_self)\r
957                                 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
958                         else\r
959                                 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
960         }\r
961 \r
962         if(sbar_field[i] == SP_SEPARATOR)\r
963         {\r
964                 pos_x = xmax;\r
965                 for(i = sbar_num_fields-1; i > 0; --i)\r
966                 {\r
967                         field = sbar_field[i];\r
968                         if(field == SP_SEPARATOR)\r
969                                 break;\r
970 \r
971                         if(is_spec && field != SP_NAME && field != SP_PING) {\r
972                                 pos_x -= sbar_size[i] + sbar_fontsize_x;\r
973                                 continue;\r
974                         }\r
975 \r
976                         str = Sbar_GetField(pl, field);\r
977                         str = Sbar_FixScoreboardColumnWidth(i, str);\r
978 \r
979                         if(field == SP_NAME) {\r
980                                 tmp_x = sbar_fixscoreboardcolumnwidth_len; // left or right aligned? let's put it right...\r
981                                 if(is_self)\r
982                                         drawcolorcodedstring(pos - tmp, str, sbar_fontsize, sbar_scoreboard_alpha_name_self, DRAWFLAG_NORMAL);\r
983                                 else\r
984                                         drawcolorcodedstring(pos - tmp, str, sbar_fontsize, sbar_scoreboard_alpha_name, DRAWFLAG_NORMAL);\r
985                         } else {\r
986                                 tmp_x = sbar_fixscoreboardcolumnwidth_len;\r
987                                 if(is_self)\r
988                                         drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, sbar_scoreboard_alpha_name_self, DRAWFLAG_NORMAL);\r
989                                 else\r
990                                         drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, sbar_scoreboard_alpha_name, DRAWFLAG_NORMAL);\r
991                         }\r
992 \r
993                         tmp_x = sbar_size[i];\r
994                         if(sbar_field_icon0 != "")\r
995                                 if (is_self)\r
996                                         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
997                                 else\r
998                                         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
999                         if(sbar_field_icon1 != "")\r
1000                                 if (is_self)\r
1001                                         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
1002                                 else\r
1003                                         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
1004                         if(sbar_field_icon2 != "")\r
1005                                 if (is_self)\r
1006                                         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
1007                                 else\r
1008                                         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
1009                         pos_x -= sbar_size[i] + sbar_fontsize_x;\r
1010                 }\r
1011         }\r
1012 }\r
1013 \r
1014 void Sbar_PrintStomachboardItem(entity pl, vector position, vector dimensions)\r
1015 {\r
1016         // lists all players in the stomach\r
1017 \r
1018         string str;\r
1019         float f, field, field_number;\r
1020         field_number = 3; // the number of components each row has\r
1021 \r
1022         position = Sbar_ConvertToScreen_PicPosition(position, dimensions);\r
1023         dimensions = Sbar_ConvertToScreen_PicScale(dimensions);\r
1024 \r
1025         // set font size to the height of each entry\r
1026         vector font_sz;\r
1027         font_sz_x = font_sz_y = dimensions_y;\r
1028 \r
1029         float fieldcounter;\r
1030         for(fieldcounter = 1; fieldcounter <= field_number; ++fieldcounter)\r
1031         {\r
1032                 vector pos, sz;\r
1033                 field = -fieldcounter;\r
1034                 str = Sbar_GetStomachField(pl, field);\r
1035 \r
1036                 // row highlighting\r
1037                 if(field == ST_HIGHLIGHT)\r
1038                 {\r
1039                         pos = position;\r
1040                         sz = dimensions;\r
1041 \r
1042                         drawfill(pos, sz, Sbar_ColorFade(Sbar_GetVoreColor()), cvar("sbar_stomachboard_highlight_alpha") * sbar_alpha_fg, DRAWFLAG_NORMAL);\r
1043                 }\r
1044 \r
1045                 if(field == ST_NAME) {\r
1046                         pos_x = position_x + dimensions_x * cvar("hud_item_preylist_colors_location");\r
1047                         sz_x = dimensions_x * cvar("hud_item_preylist_colors_length");\r
1048 \r
1049                         f = stof(getplayerkey(pl.sv_entnum, "colors"));\r
1050                         drawpic(pos, "gfx/sb_playercolor_base", sz, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
1051                         drawpic(pos, "gfx/sb_playercolor_shirt", sz, colormapPaletteColor(floor(f / 16), 0), sbar_alpha_fg, DRAWFLAG_NORMAL);\r
1052                         drawpic(pos, "gfx/sb_playercolor_pants", sz, colormapPaletteColor(mod(f, 16), 1), sbar_alpha_fg, DRAWFLAG_NORMAL);\r
1053 \r
1054                         pos_x = position_x + dimensions_x * cvar("hud_item_preylist_name_location");\r
1055                         sz_x = dimensions_x * cvar("hud_item_preylist_name_length");\r
1056                         drawcolorcodedstring(pos, textShortenToWidth(str, sz_x, font_sz, stringwidth_colors), font_sz, sbar_alpha_fg, DRAWFLAG_NORMAL);\r
1057                 }\r
1058 \r
1059                 if(field == ST_HEALTH) {\r
1060                         pos_x = position_x + dimensions_x * cvar("hud_item_preylist_health_icon_location");\r
1061                         sz_x = dimensions_x * cvar("hud_item_preylist_health_icon_length");\r
1062 \r
1063                         if(pl.sv_entnum == player_localentnum - 1 || (spectatee_status && pl.sv_entnum == spectatee_status - 1))\r
1064                                 drawcolorcodedstring(pos, textShortenToWidth("self", sz_x, font_sz, stringwidth_colors), font_sz, sbar_alpha_fg, DRAWFLAG_NORMAL);\r
1065                         else\r
1066                         {\r
1067                                 drawpic(pos, Sbar_GetTexture("sb_health"), sz, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
1068 \r
1069                                 pos_x = position_x + dimensions_x * cvar("hud_item_preylist_health_text_location");\r
1070                                 sz_x = dimensions_x * cvar("hud_item_preylist_health_text_length");\r
1071                                 drawcolorcodedstring(pos, textShortenToWidth(str, sz_x, font_sz, stringwidth_colors), font_sz, sbar_alpha_fg, DRAWFLAG_NORMAL);\r
1072                         }\r
1073                 }\r
1074         }\r
1075 }\r
1076 \r
1077 void Sbar_PrintStomachboardItemPred(entity pl, vector position, vector dimensions)\r
1078 {\r
1079         // shows the name of our predator\r
1080 \r
1081         string str;\r
1082         float f, field, field_number;\r
1083         field_number = 2; // the number of components each row has\r
1084 \r
1085         position = Sbar_ConvertToScreen_PicPosition(position, dimensions);\r
1086         dimensions = Sbar_ConvertToScreen_PicScale(dimensions);\r
1087 \r
1088         // set font size to the height of each entry\r
1089         vector font_sz;\r
1090         font_sz_x = font_sz_y = dimensions_y;\r
1091 \r
1092         float fieldcounter;\r
1093         for(fieldcounter = 1; fieldcounter <= field_number; ++fieldcounter)\r
1094         {\r
1095                 vector pos, sz;\r
1096                 field = -fieldcounter;\r
1097                 str = Sbar_GetStomachFieldPred(pl, field);\r
1098 \r
1099                 // row highlighting\r
1100                 if(field == ST_HIGHLIGHT)\r
1101                 {\r
1102                         pos = position;\r
1103                         sz = dimensions;\r
1104 \r
1105                         drawfill(pos, sz, Sbar_ColorFade(Sbar_GetVoreColor()), cvar("sbar_stomachboard_highlight_alpha") * sbar_alpha_fg, DRAWFLAG_NORMAL);\r
1106                 }\r
1107 \r
1108                 if(field == STP_NAME) {\r
1109                         pos_x = position_x + dimensions_x * cvar("hud_item_predator_colors_location");\r
1110                         sz_x = dimensions_x * cvar("hud_item_predator_colors_length");\r
1111                         f = stof(getplayerkey(pl.sv_entnum, "colors"));\r
1112                         drawpic(pos, "gfx/sb_playercolor_base", sz, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
1113                         drawpic(pos, "gfx/sb_playercolor_shirt", sz, colormapPaletteColor(floor(f / 16), 0), sbar_alpha_fg, DRAWFLAG_NORMAL);\r
1114                         drawpic(pos, "gfx/sb_playercolor_pants", sz, colormapPaletteColor(mod(f, 16), 1), sbar_alpha_fg, DRAWFLAG_NORMAL);\r
1115 \r
1116                         pos_x = position_x + dimensions_x * cvar("hud_item_predator_name_location");\r
1117                         sz_x = dimensions_x * cvar("hud_item_predator_name_length");\r
1118                         drawcolorcodedstring(pos, textShortenToWidth(str, sz_x, font_sz, stringwidth_colors), font_sz, sbar_alpha_fg, DRAWFLAG_NORMAL);\r
1119                 }\r
1120         }\r
1121 }\r
1122 \r
1123 /*\r
1124  * Sbar_Scoreboard_MakeTable\r
1125  *\r
1126  * Makes a table for a team (for all playing players in DM) and fills it\r
1127  */\r
1128 \r
1129 vector Sbar_Scoreboard_MakeTable(vector pos, entity tm, vector rgb, vector bg_size)\r
1130 {\r
1131         float body_table_height, i;\r
1132         vector tmp, column_dim;\r
1133         entity pl;\r
1134 \r
1135         body_table_height = 1.25 * sbar_fontsize_y * max(1, tm.team_size); // no player? show 1 empty line\r
1136 \r
1137         pos -= '1 1 0';\r
1138 \r
1139         tmp_x = sbwidth + 2;\r
1140         tmp_y = 1.25 * sbar_fontsize_y;\r
1141 \r
1142         // rounded header\r
1143         drawpic(pos, Sbar_GetTexture("sb_scoreboard_tableheader"), tmp, (rgb * sbar_color_bg_team) + '0.5 0.5 0.5', sbar_scoreboard_alpha_bg, DRAWFLAG_NORMAL);\r
1144 \r
1145         // table border\r
1146         tmp_y += sbar_border_thickness;\r
1147         tmp_y += body_table_height;\r
1148         drawborderlines(sbar_border_thickness, pos, tmp, '0 0 0', sbar_scoreboard_alpha_bg, DRAWFLAG_NORMAL); // more transparency for the scoreboard\r
1149 \r
1150         // separator header/table\r
1151         pos_y += 1.25 * sbar_fontsize_y;\r
1152         tmp_y = sbar_border_thickness;\r
1153         drawfill(pos, tmp, '0 0 0', sbar_scoreboard_alpha_bg, DRAWFLAG_NORMAL);\r
1154 \r
1155         pos_y += sbar_border_thickness;\r
1156 \r
1157         // table background\r
1158         tmp_y = body_table_height;\r
1159         drawpic_tiled(pos, Sbar_GetTexture("sb_scoreboard_bg"), bg_size, tmp, rgb * sbar_color_bg_team, sbar_scoreboard_alpha_bg, DRAWFLAG_NORMAL);\r
1160 \r
1161         // anyway, apply some color\r
1162         //drawfill(pos, tmp + '2 0 0', rgb, 0.1, DRAWFLAG_NORMAL);\r
1163 \r
1164         // go back to the top to make alternated columns highlighting and to print the strings\r
1165         pos_y -= 1.25 * sbar_fontsize_y;\r
1166         pos_y -= sbar_border_thickness;\r
1167 \r
1168         pos += '1 1 0';\r
1169 \r
1170         if (sbar_scoreboard_highlight)\r
1171         {\r
1172                 column_dim_y = 1.25 * sbar_fontsize_y; // header\r
1173                 column_dim_y += sbar_border_thickness;\r
1174                 column_dim_y += body_table_height;\r
1175         }\r
1176 \r
1177         // print the strings of the columns headers and draw the columns\r
1178         for(i = 0; i < sbar_num_fields; ++i)\r
1179         {\r
1180                 if(sbar_field[i] == SP_SEPARATOR)\r
1181                         break;\r
1182                 column_dim_x = sbar_size[i] + sbar_fontsize_x;\r
1183                 if (sbar_scoreboard_highlight)\r
1184                 {\r
1185                         if (mod(i,2))\r
1186                                 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
1187                 }\r
1188                 drawstring(pos, sbar_title[i], sbar_fontsize, rgb * 1.5, sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1189                 pos_x += column_dim_x;\r
1190         }\r
1191         if(sbar_field[i] == SP_SEPARATOR)\r
1192         {\r
1193                 pos_x = xmax;\r
1194                 tmp_y = 0;\r
1195                 for(i = sbar_num_fields-1; i > 0; --i)\r
1196                 {\r
1197                         if(sbar_field[i] == SP_SEPARATOR)\r
1198                                 break;\r
1199 \r
1200                         pos_x -= sbar_size[i];\r
1201 \r
1202                         if (sbar_scoreboard_highlight)\r
1203                         {\r
1204                                 if (!mod(i,2))\r
1205                                 {\r
1206                                         if (i == sbar_num_fields-1)\r
1207                                                 column_dim_x = sbar_size[i] + sbar_fontsize_x / 2 + 1;\r
1208                                         else\r
1209                                                 column_dim_x = sbar_size[i] + sbar_fontsize_x;\r
1210                                         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
1211                                 }\r
1212                         }\r
1213 \r
1214                         tmp_x = stringwidth(sbar_title[i], FALSE, sbar_fontsize);\r
1215                         tmp_x = sbar_size[i] - tmp_x;\r
1216                         drawstring(pos + tmp, sbar_title[i], sbar_fontsize, rgb * 1.5, sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1217                         pos_x -= sbar_fontsize_x;\r
1218                 }\r
1219         }\r
1220         \r
1221         pos_x = xmin;\r
1222         pos_y += 1.25 * sbar_fontsize_y; // skip the header\r
1223         pos_y += sbar_border_thickness;\r
1224 \r
1225         // fill the table and draw the rows\r
1226         i = 0;\r
1227         if (teamplay)\r
1228                 for(pl = players.sort_next; pl; pl = pl.sort_next)\r
1229                 {\r
1230                         if(pl.team != tm.team)\r
1231                                 continue;\r
1232                         Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1), i);\r
1233                         pos_y += 1.25 * sbar_fontsize_y;\r
1234                         ++i;\r
1235                 }\r
1236         else\r
1237                 for(pl = players.sort_next; pl; pl = pl.sort_next)\r
1238                 {\r
1239                         if(pl.team == COLOR_SPECTATOR)\r
1240                                 continue;\r
1241                         Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1), i);\r
1242                         pos_y += 1.25 * sbar_fontsize_y;\r
1243                         ++i;\r
1244                 }\r
1245         \r
1246         if (i == 0)\r
1247                 pos_y += 1.25 * sbar_fontsize_y; // move to the end of the table\r
1248         pos_y += 1.25 * sbar_fontsize_y; // move empty row (out of the table)\r
1249 \r
1250         return pos;\r
1251 }\r
1252 \r
1253 float Sbar_WouldDrawScoreboard() {\r
1254         if (sb_showscores)\r
1255                 return 1;\r
1256         else if (intermission == 1)\r
1257                 return 1;\r
1258         else if (intermission == 2)\r
1259                 return 1;\r
1260         else if (getstati(STAT_HEALTH) <= 0 && cvar("cl_deathscoreboard"))\r
1261                 return 1;\r
1262         else if(sb_showscores_force)\r
1263                 return 1;\r
1264         return 0;\r
1265 }\r
1266 \r
1267 float average_accuracy;\r
1268 vector Sbar_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size)\r
1269 {\r
1270         float i;\r
1271         float weapon_hit, weapon_damage, weapon_stats;\r
1272         float fontsize = 40 * 1/3;\r
1273         float xsave;\r
1274         float weapon_cnt;\r
1275         float rows;\r
1276         if(cvar("sbar_accuracy_doublerows"))\r
1277                 rows = 2;\r
1278         else\r
1279                 rows = 1;\r
1280         float height = 40;\r
1281 \r
1282         if(warmup_stage)\r
1283         {\r
1284                 return pos;\r
1285         }\r
1286 \r
1287         xsave = pos_x;\r
1288         drawstring(pos, strcat("Accuracy stats (average ", ftos(average_accuracy), "%)"), sbar_fontsize, '1 1 1', sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1289         pos_y += 18;\r
1290         vector tmp;\r
1291         tmp_x = sbwidth;\r
1292         tmp_y = height * rows;\r
1293 \r
1294         drawpic_tiled(pos, Sbar_GetTexture("sb_scoreboard_bg"), bg_size, tmp, rgb * sbar_color_bg_team, sbar_scoreboard_alpha_bg, DRAWFLAG_NORMAL);\r
1295         drawborderlines(sbar_accuracy_border_thickness, pos, tmp, '0 0 0', sbar_scoreboard_alpha_bg * 0.75, DRAWFLAG_NORMAL);\r
1296 \r
1297         // column highlighting\r
1298         for(i = 0; i < weapon_cnt/rows; ++i)\r
1299         {\r
1300                 if(!mod(i, 2))\r
1301                         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
1302         }\r
1303 \r
1304         // row highlighting\r
1305         for(i = 0; i < rows; ++i)\r
1306         {\r
1307                 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
1308         }\r
1309 \r
1310         // skip useless weapons\r
1311         weapon_cnt = 0;\r
1312         for(i = WEP_FIRST; i <= WEP_LAST; ++i)\r
1313         {\r
1314                 self = get_weaponinfo(i);\r
1315                 if not(self.weapons)\r
1316                         continue;\r
1317                 ++weapon_cnt;\r
1318         }\r
1319 \r
1320         drawfont = sbar_bigfont;\r
1321         average_accuracy = 0;\r
1322         float weapons_with_stats;\r
1323         weapons_with_stats = 0;\r
1324         if(rows == 2)\r
1325                 pos_x += sbwidth/weapon_cnt / 2;\r
1326 \r
1327         for(i = WEP_FIRST; i <= WEP_LAST; ++i)\r
1328         {\r
1329                 self = get_weaponinfo(i);\r
1330                 if not(self.weapons)\r
1331                         continue;\r
1332                 weapon_hit = weapon_hits[i-WEP_FIRST];\r
1333                 weapon_damage = weapon_fired[i-WEP_FIRST];\r
1334                 if(weapon_damage)\r
1335                         weapon_stats = bound(0, floor(100 * weapon_hit / weapon_damage), 100);\r
1336                 float weapon_alpha;\r
1337 \r
1338                 if(weapon_damage)\r
1339                         weapon_alpha = sbar_scoreboard_alpha_fg;\r
1340                 else\r
1341                         weapon_alpha = 0.2 * sbar_scoreboard_alpha_fg;\r
1342 \r
1343                 // weapon icon\r
1344                 drawpic(pos,  Sbar_GetTexture(strcat("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
1345                 // the accuracy\r
1346                 if(weapon_damage) {\r
1347                         weapons_with_stats += 1;\r
1348                         average_accuracy += weapon_stats; // store sum of all accuracies in average_accuracy\r
1349 \r
1350                         string s;\r
1351                         s = strcat(ftos(weapon_stats),"%");\r
1352 \r
1353                         float padding;\r
1354                         padding = ((sbwidth/weapon_cnt) - stringwidth(s, FALSE, '1 0 0' * fontsize)) / 2; // center the accuracy value\r
1355 \r
1356                         rgb = Sbar_AccuracyColor(weapon_stats);\r
1357                         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
1358                 }\r
1359                 pos_x += sbwidth/weapon_cnt * rows;\r
1360                 if(rows == 2 && i == 6) {\r
1361                         pos_x -= sbwidth;\r
1362                         pos_y += height;\r
1363                 }\r
1364         }\r
1365         drawfont = sbar_font;\r
1366 \r
1367         if(weapons_with_stats)\r
1368                 average_accuracy = floor(average_accuracy / weapons_with_stats);\r
1369 \r
1370         pos_x = xsave;\r
1371         pos_y += height;\r
1372         return pos;\r
1373 }\r
1374 \r
1375 string race_PlaceName(float pos) {\r
1376         if(pos == 1)\r
1377                 return "1st";\r
1378         else if(pos == 2)\r
1379                 return "2nd";\r
1380         else if(pos == 3)\r
1381                 return "3rd";\r
1382         else\r
1383                 return strcat(ftos(pos), "th");\r
1384 }\r
1385 \r
1386 vector Sbar_DrawScoreboardRankings(vector pos, entity pl,  vector rgb, vector bg_size)\r
1387 {\r
1388         float i;\r
1389         RANKINGS_RECEIVED_CNT = 0;\r
1390                 for (i=RANKINGS_CNT-1; i>=0; --i)\r
1391                         if (grecordtime[i])\r
1392                                 RANKINGS_RECEIVED_CNT = RANKINGS_RECEIVED_CNT + 1;\r
1393 \r
1394         if (RANKINGS_RECEIVED_CNT == 0)\r
1395                 return pos;\r
1396 \r
1397         float is_spec;\r
1398         is_spec = (GetPlayerColor(pl.sv_entnum) == COLOR_SPECTATOR);\r
1399         vector hl_rgb;\r
1400                 hl_rgb = stov(cvar_string("sbar_color_bg")) + '0.5 0.5 0.5';\r
1401 \r
1402         pos_y += sbar_fontsize_y;\r
1403         drawstring(pos, strcat("Rankings"), sbar_fontsize, '1 1 1', sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1404         pos_y += sbar_fontsize_y;\r
1405         vector tmp;\r
1406         tmp_x = sbwidth;\r
1407         tmp_y = sbar_fontsize_y * RANKINGS_RECEIVED_CNT;\r
1408 \r
1409         drawpic_tiled(pos, Sbar_GetTexture("sb_scoreboard_bg"), bg_size, tmp, rgb * sbar_color_bg_team, sbar_scoreboard_alpha_bg, DRAWFLAG_NORMAL);\r
1410         drawborderlines(sbar_border_thickness, pos, tmp, '0 0 0', sbar_scoreboard_alpha_bg * 0.75, DRAWFLAG_NORMAL);\r
1411 \r
1412         // row highlighting\r
1413         for(i = 0; i<RANKINGS_RECEIVED_CNT; ++i)\r
1414         {\r
1415                 string n, p;\r
1416                 float t;\r
1417                 t = grecordtime[i];\r
1418                 if (t == 0)\r
1419                         continue;\r
1420                 n = grecordholder[i];\r
1421                 p = race_PlaceName(i+1);\r
1422                 if(grecordholder[i] == GetPlayerName(player_localentnum - 1))\r
1423                         drawfill(pos, '1 0 0' * sbwidth + '0 1 0' * sbar_fontsize_y, hl_rgb, sbar_scoreboard_highlight_alpha_self, DRAWFLAG_NORMAL);    \r
1424                 else if(!mod(i, 2) && sbar_scoreboard_highlight)\r
1425                         drawfill(pos, '1 0 0' * sbwidth + '0 1 0' * sbar_fontsize_y, hl_rgb, sbar_scoreboard_highlight_alpha, DRAWFLAG_NORMAL); \r
1426                 drawstring(pos, p, sbar_fontsize, '1 1 1', sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1427                 drawstring(pos + '3 0 0' * sbar_fontsize_x, TIME_ENCODED_TOSTRING(t), sbar_fontsize, '1 1 1', sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1428                 drawcolorcodedstring(pos + '8 0 0' * sbar_fontsize_x, n, sbar_fontsize, sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1429                 pos += '0 1 0' * sbar_fontsize_y;\r
1430         }\r
1431 \r
1432         return pos;\r
1433 }\r
1434 \r
1435 float scoreboard_bottom;\r
1436 float sbar_scoreboard_fade_alpha;\r
1437 float sbar_woulddrawscoreboard_prev;\r
1438 float sbar_woulddrawscoreboard_change; // "time" at which Sbar_WouldDrawScoreboard() changed\r
1439 void Sbar_DrawScoreboard()\r
1440 {\r
1441         float sbar_woulddrawscoreboard; \r
1442         sbar_woulddrawscoreboard = Sbar_WouldDrawScoreboard();\r
1443         if(sbar_woulddrawscoreboard != sbar_woulddrawscoreboard_prev) {\r
1444                 sbar_woulddrawscoreboard_change = time;\r
1445                 sbar_woulddrawscoreboard_prev = sbar_woulddrawscoreboard;\r
1446         }\r
1447 \r
1448         float scoreboard_fadeinspeed = cvar_or("sbar_scoreboard_fadeinspeed", 10);\r
1449         float scoreboard_fadeoutspeed = cvar_or("sbar_scoreboard_fadeoutspeed", 5);\r
1450         if(sbar_woulddrawscoreboard) {\r
1451                 if (scoreboard_fadeinspeed)\r
1452                         sbar_scoreboard_fade_alpha = bound (0, (time - sbar_woulddrawscoreboard_change) * scoreboard_fadeinspeed, 1);\r
1453                 else\r
1454                         sbar_scoreboard_fade_alpha = 1;\r
1455         }\r
1456         else\r
1457                 if (scoreboard_fadeoutspeed)\r
1458                         sbar_scoreboard_fade_alpha = bound (0, (1/scoreboard_fadeoutspeed - (time - sbar_woulddrawscoreboard_change)) * scoreboard_fadeoutspeed, 1);\r
1459                 else\r
1460                         sbar_scoreboard_fade_alpha = 0;\r
1461 \r
1462         if not(sbar_scoreboard_fade_alpha)\r
1463                 return;\r
1464                 \r
1465         sbar_scoreboard_alpha_bg = cvar("sbar_scoreboard_alpha_bg") * sbar_scoreboard_fade_alpha;\r
1466         sbar_scoreboard_alpha_fg = cvar_or("sbar_scoreboard_alpha_fg", 1.0) * sbar_scoreboard_fade_alpha;\r
1467         sbar_scoreboard_highlight = cvar("sbar_scoreboard_highlight");\r
1468         sbar_scoreboard_highlight_alpha = cvar_or("sbar_scoreboard_highlight_alpha", 0.10) * sbar_scoreboard_alpha_fg;\r
1469         sbar_scoreboard_highlight_alpha_self = cvar_or("sbar_scoreboard_highlight_alpha_self", 0.25) * sbar_scoreboard_alpha_fg;\r
1470         sbar_scoreboard_alpha_name = cvar_or("sbar_scoreboard_alpha_name", 0.9) * sbar_scoreboard_alpha_fg;\r
1471         sbar_scoreboard_alpha_name_self = cvar_or("sbar_scoreboard_alpha_name_self", 1) * sbar_scoreboard_alpha_fg;\r
1472         \r
1473         vector rgb, pos, tmp;\r
1474         entity pl, tm;\r
1475 \r
1476         sbwidth = Sbar_GetWidth(6.5 * sbar_fontsize_y);\r
1477 \r
1478         xmin = 0.5 * (vid_conwidth - sbwidth);\r
1479         ymin = cvar("sbar_scoreboard_offset");\r
1480 \r
1481         xmax = vid_conwidth - xmin;\r
1482         ymax = vid_conheight - 0.2*vid_conheight;\r
1483 \r
1484         // Initializes position\r
1485         pos_x = xmin;\r
1486         pos_y = ymin;\r
1487         pos_z = 0;\r
1488 \r
1489         // Heading\r
1490         drawfont = sbar_bigfont;\r
1491         if(gametype == GAME_RPG)\r
1492                 drawstringcenter('0 1 0' * ymin, "Players", '24 24 0', '1 1 1', sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1493         else\r
1494                 drawstringcenter('0 1 0' * ymin, "Scoreboard", '24 24 0', '1 1 1', sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1495 \r
1496         pos_y += 24 + 4;\r
1497         pos_y += sbar_fontsize_y;\r
1498 \r
1499         drawfont = sbar_font;\r
1500 \r
1501         // Draw the scoreboard\r
1502         vector bg_size;\r
1503         bg_size = drawgetimagesize(Sbar_GetTexture("sb_scoreboard_bg"));\r
1504 \r
1505         if(teamplay)\r
1506         {\r
1507                 for(tm = teams.sort_next; tm; tm = tm.sort_next)\r
1508                 {\r
1509                         if(tm.team == COLOR_SPECTATOR)\r
1510                                 continue;\r
1511 \r
1512                         rgb = GetTeamRGB(tm.team);\r
1513                         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
1514                                 \r
1515                         if(ts_primary != ts_secondary)\r
1516                                 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
1517 \r
1518                         pos = Sbar_Scoreboard_MakeTable(pos, tm, rgb, bg_size);\r
1519                 }\r
1520         }\r
1521         else\r
1522         {\r
1523                 rgb = stov(cvar_string("sbar_color_bg"));\r
1524 \r
1525                 for(tm = teams.sort_next; tm; tm = tm.sort_next)\r
1526                 {\r
1527                         if(tm.team == COLOR_SPECTATOR)\r
1528                                 continue;\r
1529 \r
1530                         pos = Sbar_Scoreboard_MakeTable(pos, tm, rgb, bg_size);\r
1531                 }\r
1532         }\r
1533 \r
1534         if(gametype == GAME_CTS || gametype == GAME_RACE) {\r
1535                 if(race_speedaward) {\r
1536                         drawcolorcodedstring(pos, strcat("Speed award: ", ftos(race_speedaward), " (", race_speedaward_holder, ")"), sbar_fontsize, sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1537                         pos_y += 1.25 * sbar_fontsize_y;\r
1538                 }\r
1539                 if(race_speedaward_alltimebest) {\r
1540                         drawcolorcodedstring(pos, strcat("All-time fastest: ", ftos(race_speedaward_alltimebest), " (", race_speedaward_alltimebest_holder, ")"), sbar_fontsize, sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1541                         pos_y += 1.25 * sbar_fontsize_y;\r
1542                 }\r
1543                 pos = Sbar_DrawScoreboardRankings(pos, pl, rgb, bg_size);\r
1544         }\r
1545         else if(cvar("sbar_accuracy") && spectatee_status != -1) {\r
1546                 if(teamplay)\r
1547                         pos = Sbar_DrawScoreboardAccuracyStats(pos, GetTeamRGB(myteam), bg_size);\r
1548                 else\r
1549                         pos = Sbar_DrawScoreboardAccuracyStats(pos, rgb, bg_size);\r
1550         }\r
1551 \r
1552         tmp = pos + '0 1.5 0' * sbar_fontsize_y;\r
1553         pos_y += 3 * sbar_fontsize_y;\r
1554 \r
1555         // List spectators\r
1556         float specs;\r
1557         specs = 0;\r
1558         for(pl = players.sort_next; pl; pl = pl.sort_next)\r
1559         {\r
1560                 if(pl.team != COLOR_SPECTATOR)\r
1561                         continue;\r
1562                 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1), specs);\r
1563                 pos_y += 1.25 * sbar_fontsize_y;\r
1564                 ++specs;\r
1565         }\r
1566 \r
1567         if(specs)\r
1568                 drawstring(tmp, "Spectators", sbar_fontsize, '1 1 1', sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1569 \r
1570         // Print info string\r
1571         string str;\r
1572         float tl, fl, ll;\r
1573         if(gametype == GAME_RPG)\r
1574                 str = strcat("you are in ^2", shortmapname, "^7");\r
1575         else\r
1576                 str = strcat("playing on ^2", shortmapname, "^7");\r
1577         tl = getstatf(STAT_TIMELIMIT);\r
1578         fl = getstatf(STAT_FRAGLIMIT);\r
1579         ll = getstatf(STAT_LEADLIMIT);\r
1580         if(gametype == GAME_LMS)\r
1581         {\r
1582                 if(tl > 0)\r
1583                         str = strcat(str, " for up to ^1", ftos(tl), " minutes^7");\r
1584         }\r
1585         else\r
1586         {\r
1587                 if(tl > 0)\r
1588                         str = strcat(str, " for ^1", ftos(tl), " minutes^7");\r
1589                 if(fl > 0 && !(gametype == GAME_RPG))\r
1590                 {\r
1591                         if(tl > 0)\r
1592                                 str = strcat(str, " or");\r
1593                         if(teamplay)\r
1594                         {\r
1595                                 str = strcat(str, " until ^3", ScoreString(teamscores_flags[ts_primary], fl));\r
1596                                 if(teamscores_label[ts_primary] == "score")\r
1597                                         str = strcat(str, " points^7");\r
1598                                 else if(teamscores_label[ts_primary] == "fastest")\r
1599                                         str = strcat(str, " is beaten^7");\r
1600                                 else\r
1601                                         str = strcat(str, " ", teamscores_label[ts_primary]);\r
1602                         }\r
1603                         else\r
1604                         {\r
1605                                 str = strcat(str, " until ^3", ScoreString(scores_flags[ps_primary], fl));\r
1606                                 if(scores_label[ps_primary] == "score")\r
1607                                         str = strcat(str, " points^7");\r
1608                                 else if(scores_label[ps_primary] == "fastest")\r
1609                                         str = strcat(str, " is beaten^7");\r
1610                                 else\r
1611                                         str = strcat(str, " ", scores_label[ps_primary]);\r
1612                         }\r
1613                 }\r
1614                 if(ll > 0)\r
1615                 {\r
1616                         if(tl > 0 || fl > 0)\r
1617                                 str = strcat(str, " or");\r
1618                         if(teamplay)\r
1619                         {\r
1620                                 str = strcat(str, " until a lead of ^3", ScoreString(teamscores_flags[ts_primary], ll));\r
1621                                 if(teamscores_label[ts_primary] == "score")\r
1622                                         str = strcat(str, " points^7");\r
1623                                 else if(teamscores_label[ts_primary] == "fastest")\r
1624                                         str = strcat(str, " is beaten^7");\r
1625                                 else\r
1626                                         str = strcat(str, " ", teamscores_label[ts_primary]);\r
1627                         }\r
1628                         else\r
1629                         {\r
1630                                 str = strcat(str, " until a lead of ^3", ScoreString(scores_flags[ps_primary], ll));\r
1631                                 if(scores_label[ps_primary] == "score")\r
1632                                         str = strcat(str, " points^7");\r
1633                                 else if(scores_label[ps_primary] == "fastest")\r
1634                                         str = strcat(str, " is beaten^7");\r
1635                                 else\r
1636                                         str = strcat(str, " ", scores_label[ps_primary]);\r
1637                         }\r
1638                 }\r
1639         }\r
1640 \r
1641 \r
1642         pos_y += 1.2 * sbar_fontsize_y;\r
1643         drawcolorcodedstring(pos + '0.5 0 0' * (sbwidth - stringwidth(str, TRUE, sbar_fontsize)), str, sbar_fontsize, sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1644 \r
1645         // print information about respawn status\r
1646         float respawn_time = getstatf(STAT_RESPAWN_TIME);\r
1647         if(respawn_time)\r
1648         {\r
1649                 if(respawn_time < 0)\r
1650                 {\r
1651                         // a negative number means we are awaiting respawn, time value is still the same\r
1652                         respawn_time *= -1; // remove mark now that we checked it\r
1653                         if(time >= respawn_time) // don't show a negative value while the server is respawning the player (lag)\r
1654                                 str = strcat("^1Respawning...");\r
1655                         else\r
1656                                 str = strcat("^1Respawning in ^3", ftos_decimals(respawn_time - time, 2), "^1 seconds...");\r
1657                 }\r
1658                 else if(time < respawn_time)\r
1659                         str = strcat("You are dead, wait ^3", ftos_decimals(respawn_time - time, 2), "^7 seconds before respawning");\r
1660                 else if(time >= respawn_time)\r
1661                         str = strcat("You are dead, press ^2", getcommandkey("primary fire", "+fire"), "^7 to respawn");\r
1662 \r
1663                 pos_y += 1.2 * sbar_fontsize_y;\r
1664                 drawcolorcodedstring(pos + '0.5 0 0' * (sbwidth - stringwidth(str, TRUE, sbar_fontsize)), str, sbar_fontsize, sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1665         }\r
1666 \r
1667         scoreboard_bottom = pos_y + 2 * sbar_fontsize_y;\r
1668 }\r
1669 \r
1670 string MakeRaceString(float cp, float mytime, float histime, float lapdelta, string hisname)\r
1671 {\r
1672         string col;\r
1673         string timestr;\r
1674         string cpname;\r
1675         string lapstr;\r
1676         lapstr = "";\r
1677 \r
1678         if(histime == 0) // goal hit\r
1679         {\r
1680                 if(mytime > 0)\r
1681                 {\r
1682                         timestr = strcat("+", ftos_decimals(+mytime, TIME_DECIMALS));\r
1683                         col = "^1";\r
1684                 }\r
1685                 else if(mytime == 0)\r
1686                 {\r
1687                         timestr = "+0.0";\r
1688                         col = "^3";\r
1689                 }\r
1690                 else\r
1691                 {\r
1692                         timestr = strcat("-", ftos_decimals(-mytime, TIME_DECIMALS));\r
1693                         col = "^2";\r
1694                 }\r
1695 \r
1696                 if(lapdelta > 0)\r
1697                 {\r
1698                         lapstr = strcat(" (-", ftos(lapdelta), "L)");\r
1699                         col = "^2";\r
1700                 }\r
1701                 else if(lapdelta < 0)\r
1702                 {\r
1703                         lapstr = strcat(" (+", ftos(-lapdelta), "L)");\r
1704                         col = "^1";\r
1705                 }\r
1706         }\r
1707         else if(histime > 0) // anticipation\r
1708         {\r
1709                 if(mytime >= histime)\r
1710                         timestr = strcat("+", ftos_decimals(mytime - histime, TIME_DECIMALS));\r
1711                 else\r
1712                         timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(histime));\r
1713                 col = "^3";\r
1714         }\r
1715         else\r
1716                 col = "^7";\r
1717 \r
1718         if(cp == 254)\r
1719                 cpname = "Start line";\r
1720         else if(cp == 255)\r
1721                 cpname = "Finish line";\r
1722         else if(cp)\r
1723                 cpname = strcat("Intermediate ", ftos(cp));\r
1724         else\r
1725                 cpname = "Finish line";\r
1726 \r
1727         if(histime < 0)\r
1728                 return strcat(col, cpname);\r
1729         else if(hisname == "")\r
1730                 return strcat(col, cpname, " (", timestr, ")");\r
1731         else\r
1732                 return strcat(col, cpname, " (", timestr, " ", strcat(hisname, col, lapstr), ")");\r
1733 }\r
1734 \r
1735 float race_CheckName(string net_name) { // Does the name already exist in rankings? In that case, where? (otherwise 0)\r
1736         float i;\r
1737         for (i=RANKINGS_CNT-1;i>=0;--i)\r
1738                 if(grecordholder[i] == net_name)\r
1739                         return i+1;\r
1740         return 0;\r
1741 }\r
1742 \r
1743 float GetAmmoStat(float i)\r
1744 {\r
1745         switch(i)\r
1746         {\r
1747                 case 0: return STAT_FUEL;\r
1748                 default: return -1;\r
1749         }\r
1750 }\r
1751 \r
1752 float GetAmmoItemCode(float i)\r
1753 {\r
1754         switch(i)\r
1755         {\r
1756                 case 0: return IT_FUEL;\r
1757                 default: return -1;\r
1758         }\r
1759 }\r
1760 \r
1761 string GetAmmoPicture(float i)\r
1762 {\r
1763         switch(i)\r
1764         {\r
1765                 case 0:\r
1766                         if(getstati(STAT_ITEMS) & IT_FUEL_REGEN)\r
1767                                 return Sbar_GetTexture("sb_fuel_regen");\r
1768                         else\r
1769                                 return Sbar_GetTexture("sb_fuel");\r
1770                 default:\r
1771                         return "";\r
1772         }\r
1773 }\r
1774 \r
1775 void Sbar_DrawBackgrounds()\r
1776 {\r
1777         // Draw all backgrounds defined by our HUD setup\r
1778         if (cvar("viewsize") > 100 || !sbar_hudselector)\r
1779                 return;\r
1780 \r
1781         float total = cvar("hud_backgrounds");\r
1782         float i;\r
1783         for(i = 1; i <= total; i++)\r
1784         {\r
1785                 string img = cvar_string(strcat("hud_background_", ftos(i), "_texture"));\r
1786                 vector pos = stov(cvar_string(strcat("hud_background_", ftos(i), "_position")));\r
1787                 vector sz = stov(cvar_string(strcat("hud_background_", ftos(i), "_scale")));\r
1788 \r
1789                 pos = Sbar_ConvertToScreen_PicPosition(pos, sz);\r
1790                 sz = Sbar_ConvertToScreen_PicScale(sz);\r
1791 \r
1792                 vector col;\r
1793                 switch(cvar(strcat("hud_background_", ftos(i), "_colortype")))\r
1794                 {\r
1795                         case 1:\r
1796                                 if(teamplay)\r
1797                                         col = GetTeamRGB(myteam) * sbar_color_bg_team;\r
1798                                 else\r
1799                                         col = stov(cvar_string("sbar_color_bg"));\r
1800                                 break;\r
1801                         case 2:\r
1802                                 col = Sbar_ColorFade(Sbar_GetVoreColor());\r
1803                                 break;\r
1804                         default:\r
1805                                 col = '1 1 1';\r
1806                                 break;\r
1807                 }\r
1808 \r
1809                 drawpic(pos, img, sz, col, sbar_alpha_bg, DRAWFLAG_NORMAL);\r
1810         }\r
1811 }\r
1812 \r
1813 float race_status_time;\r
1814 float race_status_prev;\r
1815 string race_status_name_prev;\r
1816 void Sbar_DrawRaceStatus(vector pos)\r
1817 {\r
1818         if (race_status != race_status_prev || race_status_name != race_status_name_prev) {\r
1819                 race_status_time = time + 5;\r
1820                 race_status_prev = race_status;\r
1821                 if (race_status_name_prev)\r
1822                         strunzone(race_status_name_prev);\r
1823                 race_status_name_prev = strzone(race_status_name);\r
1824         }\r
1825 \r
1826         float a;\r
1827         a = bound(0, race_status_time - time, 1);\r
1828 \r
1829         string s;\r
1830         s = textShortenToWidth(race_status_name, 120, '10 10 0', stringwidth_colors);\r
1831 \r
1832         float rank;\r
1833         if(race_status > 0)\r
1834                 rank = race_CheckName(race_status_name);\r
1835         string rankname;\r
1836         rankname = race_PlaceName(rank);\r
1837 \r
1838         if(race_status == 0)\r
1839                 drawpic(pos, Sbar_GetTexture("race/newfail"), '80 80 0', '1 1 1', sbar_alpha_fg * a, DRAWFLAG_NORMAL);\r
1840         else if(race_status == 1) {\r
1841                 drawpic(pos, Sbar_GetTexture("race/newtime"), '80 80 0', '1 1 1', sbar_alpha_fg * a, DRAWFLAG_NORMAL);  \r
1842                 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
1843                 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
1844         } else if(race_status == 2) {\r
1845                 if(race_status_name == GetPlayerName(player_localentnum -1) || !race_myrank || race_myrank < rank)\r
1846                         drawpic(pos, Sbar_GetTexture("race/newrankgreen"), '80 80 0', '1 1 1', sbar_alpha_fg * a, DRAWFLAG_NORMAL);\r
1847                 else\r
1848                         drawpic(pos, Sbar_GetTexture("race/newrankyellow"), '80 80 0', '1 1 1', sbar_alpha_fg * a, DRAWFLAG_NORMAL);\r
1849                 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
1850                 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
1851         } else if(race_status == 3) {\r
1852                 drawpic(pos, Sbar_GetTexture("race/newrecordserver"), '80 80 0', '1 1 1', sbar_alpha_fg * a, DRAWFLAG_NORMAL);\r
1853                 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
1854                 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
1855         }\r
1856 \r
1857         if (race_status_time - time <= 0) {\r
1858                 race_status_prev = -1;\r
1859                 race_status = -1;\r
1860                 if(race_status_name)\r
1861                         strunzone(race_status_name);\r
1862                 race_status_name = string_null;\r
1863                 if(race_status_name_prev)\r
1864                         strunzone(race_status_name_prev);\r
1865                 race_status_name_prev = string_null;\r
1866         }\r
1867 }\r
1868 \r
1869 void Sbar_Portrait()\r
1870 {\r
1871         // draws the portrait, using the values set in Ent_ReadPortrait\r
1872 \r
1873         // make the portrait slide in and out of the left edge\r
1874         float fade_time;\r
1875         float fade1_start, fade1_end, fade2_start, fade2_end;\r
1876         float fade_in, fade_out;\r
1877 \r
1878         fade_time = cvar("sbar_portrait_time") * bound(0, cvar("sbar_portrait_fade"), 0.5);\r
1879 \r
1880         fade1_start = portrait_time + cvar("sbar_portrait_time") - fade_time;\r
1881         fade1_end = portrait_time + cvar("sbar_portrait_time");\r
1882         fade2_start = portrait_time;\r
1883         fade2_end = portrait_time + fade_time;\r
1884 \r
1885         fade_in = bound(0, (time / fade1_end - 1) / (fade1_start / fade1_end - 1), 1);\r
1886         fade_out = 1 - bound(0, (time / fade2_end - 1) / (fade2_start / fade2_end - 1), 1);\r
1887 \r
1888         vector left, fade_pos;\r
1889         left_x = 0;\r
1890         left_y = vid_conheight / 2;\r
1891         fade_pos_x = -130 * fade_in * fade_out;\r
1892 \r
1893         if(!cvar("sbar_portrait"))\r
1894                 return;\r
1895 \r
1896         if(portrait_time + cvar("sbar_portrait_time") >= time)\r
1897         {\r
1898                 if(portrait_image && portrait_name) // prevent using bad strings\r
1899                 {\r
1900                         drawpic(left - '120 80 0' - fade_pos, portrait_image, '120 160 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
1901                         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
1902                 }\r
1903         }\r
1904         else\r
1905         {\r
1906                 // free unused strings from memory\r
1907                 if(portrait_image)\r
1908                 {\r
1909                         strunzone(portrait_image);\r
1910                         portrait_image = string_null;\r
1911                 }\r
1912                 if(portrait_name)\r
1913                 {\r
1914                         strunzone(portrait_name);\r
1915                         portrait_name = string_null;\r
1916                 }\r
1917         }\r
1918 }\r
1919 \r
1920 void Sbar_Score()\r
1921 {\r
1922         float score, distribution, leader;\r
1923         vector distribution_color;\r
1924         string racetime, secondary_racetime;\r
1925         entity tm, pl, me;\r
1926         me = (spectatee_status > 0) ? playerslots[spectatee_status - 1] : playerslots[player_localentnum - 1];\r
1927 \r
1928         if(gametype == GAME_RPG)\r
1929                 return;\r
1930 \r
1931         if((scores_flags[ps_primary] & SFL_TIME) && !teamplay) { // race/cts record display on HUD\r
1932                 pl = players.sort_next;\r
1933                 if(pl == me)\r
1934                         pl = pl.sort_next;\r
1935                 if(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)\r
1936                         if(pl.scores[ps_primary] == 0)\r
1937                                 pl = world;\r
1938 \r
1939                 score = me.(scores[ps_primary]);\r
1940 \r
1941                 float racemin, racesec, racemsec;\r
1942                 float distsec, distmsec;\r
1943                 string s_racemin, s_racesec, s_racemsec;\r
1944                 \r
1945                 racemin = floor(score/(60 * TIME_FACTOR));\r
1946                 racesec = floor((score - racemin*(60 * TIME_FACTOR))/TIME_FACTOR);\r
1947                 racemsec = score - racemin*60*TIME_FACTOR - racesec*TIME_FACTOR;\r
1948 \r
1949                 if(racemin < 10) s_racemin = strcat("0", ftos(racemin));\r
1950                 else s_racemin = ftos(racemin);\r
1951                 if(racesec < 10) s_racesec = strcat("0", ftos(racesec));\r
1952                 else s_racesec = ftos(racesec);\r
1953                 if(racemsec < 10) s_racemsec = strcat("0", ftos(racemsec));\r
1954                 else s_racemsec = ftos(racemsec);\r
1955 \r
1956                 if (pl && ((!(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)) || score)) {\r
1957                         // distribution display\r
1958                         distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);\r
1959 \r
1960                         if (distribution < TIME_FACTOR && distribution > -TIME_FACTOR)\r
1961                                 distmsec = fabs(distribution);\r
1962                         else {\r
1963                                 distsec = floor(fabs(distribution) / TIME_FACTOR);\r
1964                                 distmsec = fabs(distribution) - distsec * TIME_FACTOR;\r
1965                         }\r
1966 \r
1967                         if (distribution < 0) {\r
1968                                 distribution_color = '0 1 0';\r
1969                                 secondary_racetime = "-"; // always prefix with minus sign\r
1970                         }\r
1971                         else if (distribution > 0) {\r
1972                                 distribution_color = '1 0 0';\r
1973                                 secondary_racetime = "+"; // minusplus 1: always prefix with plus sign\r
1974                         }\r
1975                         else\r
1976                                 distribution_color = '1 1 1';\r
1977 \r
1978                         secondary_racetime = strcat(secondary_racetime, ftos(distsec), ".", ftos(distmsec));\r
1979                         drawstring(Sbar_ConvertToScreen_TextPosition(secondary_racetime, stov(cvar_string("hud_item_score_race_secondary_text_position")), cvar("hud_item_score_race_secondary_text_scale")), secondary_racetime, '1 1 0' * cvar("hud_item_score_race_secondary_text_scale"), distribution_color, sbar_alpha_fg, DRAWFLAG_NORMAL);\r
1980                 }\r
1981 \r
1982                 racetime = strcat(s_racemin, " : ", s_racesec, " . ", s_racemsec);\r
1983                 Sbar_DrawString(racetime, stov(cvar_string("hud_item_score_race_primary_text_position")), cvar("hud_item_score_race_primary_text_scale"));\r
1984 \r
1985         } else if (!teamplay) { // non-teamgames, except race/cts\r
1986                 // me vector := [team/connected frags id]\r
1987                 pl = players.sort_next;\r
1988                 if(pl == me)\r
1989                         pl = pl.sort_next;\r
1990 \r
1991                 if(pl)\r
1992                         distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);\r
1993                 else\r
1994                         distribution = 0;\r
1995 \r
1996                 score = me.(scores[ps_primary]);\r
1997                 \r
1998                 if(distribution >= 5) {\r
1999                         distribution_color = '0 1 0';\r
2000                         leader = 1;\r
2001                 } else if(distribution >= 0) {\r
2002                         distribution_color = '1 1 1';\r
2003                         leader = 1;\r
2004                 } else if(distribution >= -5)\r
2005                         distribution_color = '1 1 0';\r
2006                 else\r
2007                         distribution_color = '1 0 0';\r
2008                 \r
2009                 Sbar_DrawXNum(stov(cvar_string("hud_item_score_nonteam_secondary_text_position")), distribution, 6, 3, cvar("hud_item_score_nonteam_secondary_text_scale"), distribution_color, sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2010                 Sbar_DrawXNum(stov(cvar_string("hud_item_score_nonteam_primary_text_position")), score, 6, 0, cvar("hud_item_score_nonteam_primary_text_scale"), distribution_color, sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2011         } else { // teamgames\r
2012                 float max_fragcount;\r
2013                 max_fragcount = -999;\r
2014 \r
2015                 vector pos = stov(cvar_string("hud_item_score_team_secondary_text_position"));\r
2016                 vector sz = '1 1 0' * cvar("hud_item_score_team_secondary_text_scale");\r
2017                 sz_x = sz_x / vid_conwidth;\r
2018                 sz_y = sz_y / vid_height * 2;\r
2019                 vector dir = stov(cvar_string("hud_item_score_team_secondary_entry_spacing"));\r
2020                 for(tm = teams.sort_next; tm; tm = tm.sort_next) {\r
2021                         if(tm.team == COLOR_SPECTATOR || !tm.team_size) // no players? don't display\r
2022                                 continue;\r
2023                         score = tm.(teamscores[ts_primary]);\r
2024                         leader = 0;\r
2025 \r
2026                         if (score > max_fragcount)\r
2027                                 max_fragcount = score;\r
2028 \r
2029                         if(tm.team == myteam) {\r
2030                                 if (max_fragcount == score)\r
2031                                         leader = 1;\r
2032                                 Sbar_DrawXNum(stov(cvar_string("hud_item_score_team_primary_text_position")), score, 6, 0, cvar("hud_item_score_team_primary_text_scale"), GetTeamRGB(tm.team), sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2033                         } else {\r
2034                                 if (max_fragcount == score)\r
2035                                         leader = 1;\r
2036                                 Sbar_DrawXNum(pos, score, 6, 3, cvar("hud_item_score_team_secondary_text_scale"), GetTeamRGB(tm.team), sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2037                                 pos_x += sz_x * dir_x;\r
2038                                 pos_y += sz_y * dir_y;\r
2039                         }\r
2040                 }\r
2041         }\r
2042 \r
2043         if(gametype == GAME_RACE || gametype == GAME_CTS)\r
2044         {\r
2045                 drawfont = sbar_bigfont;\r
2046                 float a, t;\r
2047                 vector m;\r
2048                 string s, forcetime;\r
2049 \r
2050                 m = '0.5 0 0' * vid_conwidth + '0 1 0' * cvar_or("cl_racetimer_position", 0.25) * vid_conheight;\r
2051 \r
2052                 if(race_checkpointtime)\r
2053                 {\r
2054                         a = bound(0, 2 - (time - race_checkpointtime), 1);\r
2055                         s = "";\r
2056                         forcetime = "";\r
2057                         if(a > 0) // just hit a checkpoint?\r
2058                         {\r
2059                                 if(race_checkpoint != 254)\r
2060                                 {\r
2061                                         if(race_time && race_previousbesttime)\r
2062                                                 s = MakeRaceString(race_checkpoint, TIME_DECODE(race_time) - TIME_DECODE(race_previousbesttime), 0, 0, race_previousbestname);\r
2063                                         else\r
2064                                                 s = MakeRaceString(race_checkpoint, 0, -1, 0, race_previousbestname);\r
2065                                         if(race_time)\r
2066                                                 forcetime = TIME_ENCODED_TOSTRING(race_time);\r
2067                                 }\r
2068                         }\r
2069                         else\r
2070                         {\r
2071                                 if(race_laptime && race_nextbesttime && race_nextcheckpoint != 254)\r
2072                                 {\r
2073                                         a = bound(0, 2 - ((race_laptime + TIME_DECODE(race_nextbesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1);\r
2074                                         if(a > 0) // next one?\r
2075                                         {\r
2076                                                 s = MakeRaceString(race_nextcheckpoint, (time + TIME_DECODE(race_penaltyaccumulator)) - race_laptime, TIME_DECODE(race_nextbesttime), 0, race_nextbestname);\r
2077                                         }\r
2078                                 }\r
2079                         }\r
2080 \r
2081                         if(s != "" && a > 0)\r
2082                         {\r
2083                                 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)\r
2084                                 //drawcolorcodedstring(m - '0 16 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', sbar_alpha_fg * a, DRAWFLAG_NORMAL);\r
2085                                 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
2086                         }\r
2087 \r
2088                         if(race_penaltytime)\r
2089                         {\r
2090                                 a = bound(0, 2 - (time - race_penaltyeventtime), 1);\r
2091                                 if(a > 0)\r
2092                                 {\r
2093                                         s = strcat("^1PENALTY: ", ftos_decimals(race_penaltytime * 0.1, 1), " (", race_penaltyreason, ")");\r
2094                                         dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)\r
2095                                         //drawcolorcodedstring(m - '0 32 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', sbar_alpha_fg * a, DRAWFLAG_NORMAL);\r
2096                                         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
2097                                 }\r
2098                         }\r
2099 \r
2100                         if(forcetime != "")\r
2101                         {\r
2102                                 a = bound(0, (time - race_checkpointtime) / 0.5, 1);\r
2103                                 //drawstring_expanding(m - '16 0 0' * stringwidth(forcetime, FALSE), forcetime, '32 32 0', '1 1 1', sbar_alpha_fg, 0, a);\r
2104                                 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
2105                         }\r
2106                         else\r
2107                                 a = 1;\r
2108 \r
2109                         if(race_laptime && race_checkpoint != 255)\r
2110                         {\r
2111                                 s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime));\r
2112                                 //drawstring(m - '16 0 0' * stringwidth(s, FALSE), s, '32 32 0', '1 1 1', sbar_alpha_fg * a, DRAWFLAG_NORMAL);\r
2113                                 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
2114                         }\r
2115                 }\r
2116                 else\r
2117                 {\r
2118                         if(race_mycheckpointtime)\r
2119                         {\r
2120                                 a = bound(0, 2 - (time - race_mycheckpointtime), 1);\r
2121                                 s = MakeRaceString(race_mycheckpoint, TIME_DECODE(race_mycheckpointdelta), -!race_mycheckpointenemy, race_mycheckpointlapsdelta, race_mycheckpointenemy);\r
2122                                 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)\r
2123                                 //drawcolorcodedstring(m - '0 16 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', sbar_alpha_fg * a, DRAWFLAG_NORMAL);\r
2124                                 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
2125                         }\r
2126                         if(race_othercheckpointtime && race_othercheckpointenemy != "")\r
2127                         {\r
2128                                 a = bound(0, 2 - (time - race_othercheckpointtime), 1);\r
2129                                 s = MakeRaceString(race_othercheckpoint, -TIME_DECODE(race_othercheckpointdelta), -!race_othercheckpointenemy, race_othercheckpointlapsdelta, race_othercheckpointenemy);\r
2130                                 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)\r
2131                                 //drawcolorcodedstring(m - '0 0 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', sbar_alpha_fg * a, DRAWFLAG_NORMAL);\r
2132                                 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
2133                         }\r
2134 \r
2135                         if(race_penaltytime && !race_penaltyaccumulator)\r
2136                         {\r
2137                                 t = race_penaltytime * 0.1 + race_penaltyeventtime;\r
2138                                 a = bound(0, (1 + t - time), 1);\r
2139                                 if(a > 0)\r
2140                                 {\r
2141                                         if(time < t)\r
2142                                                 s = strcat("^1PENALTY: ", ftos_decimals(t - time, 1), " (", race_penaltyreason, ")");\r
2143                                         else\r
2144                                                 s = strcat("^2PENALTY: 0.0 (", race_penaltyreason, ")");\r
2145                                         dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)\r
2146                                         //drawcolorcodedstring(m - '0 32 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', sbar_alpha_fg * a, DRAWFLAG_NORMAL);\r
2147                                         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
2148                                 }\r
2149                         }\r
2150                 }\r
2151 \r
2152                 drawfont = sbar_font;\r
2153         }\r
2154 }\r
2155 \r
2156 void Sbar_Status()\r
2157 {\r
2158         float armor, health, x, a;\r
2159         armor = getstati(STAT_ARMOR);\r
2160         health = getstati(STAT_HEALTH);\r
2161 \r
2162         float stat_items;\r
2163         stat_items = getstati(STAT_ITEMS);\r
2164 \r
2165         // armor\r
2166         x = armor;\r
2167         if (x > 0)\r
2168         {\r
2169                 Sbar_DrawPic(Sbar_GetTexture("sb_armor"), stov(cvar_string("hud_item_armor_icon_position")), stov(cvar_string("hud_item_armor_icon_scale")), FALSE);\r
2170                 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
2171         }\r
2172 \r
2173         // health\r
2174         x = health;\r
2175         Sbar_DrawPic(Sbar_GetTexture("sb_health"), stov(cvar_string("hud_item_health_icon_position")), stov(cvar_string("hud_item_health_icon_scale")), FALSE);\r
2176         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
2177 \r
2178         // if we are dead, we can skip the HUD from here\r
2179         if(health <= 0)\r
2180                 return;\r
2181 \r
2182         // ammo\r
2183         float weapon_clipload, weapon_clipsize;\r
2184 \r
2185         // if we are using the jetpack, show fuel ammo. Otherwise show the ammo of our weapon\r
2186         if(stat_items & IT_JETPACK && button_jetpack)\r
2187         {\r
2188                 a = getstati(GetAmmoStat(0)); // how much fuel do we have?\r
2189                 Sbar_DrawPic(GetAmmoPicture(0), stov(cvar_string("hud_item_ammo_icon_position")), stov(cvar_string("hud_item_ammo_noload_icon_scale")), FALSE);\r
2190                 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
2191         }\r
2192         else\r
2193         {\r
2194                 float i;\r
2195                 for (i = 0; i < 1; ++i)\r
2196                 {\r
2197                         // Since fuel is currently the only ammo, always show it on the HUD.\r
2198                         // In case we ever get more ammos, comment the line below back in.\r
2199                         // if (stat_items & GetAmmoItemCode(i))\r
2200                         {\r
2201                                 a = getstati(GetAmmoStat(i)); // how much ammo do we have of type i?\r
2202                                 Sbar_DrawPic(GetAmmoPicture(i), stov(cvar_string("hud_item_ammo_icon_position")), stov(cvar_string("hud_item_ammo_icon_scale")), FALSE);\r
2203                                 weapon_clipsize = getstati(STAT_WEAPON_CLIPSIZE);\r
2204 \r
2205                                 // if the weapon we're holding is reloadable, show both its ammo and load\r
2206                                 if(weapon_clipsize)\r
2207                                 {\r
2208                                         weapon_clipload = getstati(STAT_WEAPON_CLIPLOAD);\r
2209                                         if(weapon_clipload < 0) // we're reloading\r
2210                                                 Sbar_DrawString("- -", stov(cvar_string("hud_item_ammo_load_clip_text_position")), cvar("hud_item_ammo_load_clip_text_scale"));\r
2211                                         else\r
2212                                                 Sbar_DrawXNum(stov(cvar_string("hud_item_ammo_load_clip_text_position")), weapon_clipload, 2, 0, cvar("hud_item_ammo_load_clip_text_scale"), '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2213                                         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
2214                                 }\r
2215                                 else\r
2216                                 {\r
2217                                         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
2218                                 }\r
2219                         }\r
2220                 }\r
2221         }\r
2222 \r
2223         // weapon icon\r
2224         entity e;\r
2225         e = get_weaponinfo(activeweapon);\r
2226         if (e && e.netname != "" && e.netname != "N/A")\r
2227                 Sbar_DrawPic(Sbar_GetTexture(strcat("sb_activeweapon_", e.netname)), stov(cvar_string("hud_item_weapon_position")), stov(cvar_string("hud_item_weapon_scale")), FALSE);\r
2228 }\r
2229 \r
2230 void Sbar_Timer()\r
2231 {\r
2232         float timelimit, elapsedTime, minutes, seconds, timeleft, minutesLeft, secondsLeft;\r
2233         vector timer_color;\r
2234         string finaltime;\r
2235 \r
2236         timelimit = getstatf(STAT_TIMELIMIT);\r
2237 \r
2238         if(gametype == GAME_RPG && !timelimit) // don't draw the timer in rpg if there's no time limit\r
2239                 return;\r
2240 \r
2241         Sbar_DrawRaceStatus('0 20 0');\r
2242         \r
2243         timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);\r
2244         timeleft = ceil(timeleft);\r
2245         minutesLeft = floor(timeleft / 60);\r
2246         secondsLeft = timeleft - minutesLeft*60;\r
2247 \r
2248         if(minutesLeft >= 5 || warmup_stage || timelimit == 0) //don't use red or yellow in warmup or when there is no timelimit\r
2249                 timer_color = '1 1 1'; //white\r
2250         else if(minutesLeft >= 1)\r
2251                 timer_color = '1 1 0'; //yellow\r
2252         else\r
2253                 timer_color = '1 0 0'; //red\r
2254 \r
2255         if (cvar("sbar_increment_maptime") || timelimit == 0 || warmup_stage) {\r
2256                 if (time < getstatf(STAT_GAMESTARTTIME)) {\r
2257                         //while restart is still active, show 00:00\r
2258                         minutes = seconds = 0;\r
2259                 } else {\r
2260                         elapsedTime = floor(time - getstatf(STAT_GAMESTARTTIME)); //127\r
2261                         minutes = floor(elapsedTime / 60);\r
2262                         seconds = elapsedTime - minutes*60;\r
2263                 }\r
2264         } else {\r
2265                 minutes = minutesLeft;\r
2266                 seconds = secondsLeft;\r
2267         }\r
2268 \r
2269         Sbar_DrawPic(Sbar_GetTexture("sb_time"), stov(cvar_string("hud_item_timer_icon_position")), stov(cvar_string("hud_item_timer_icon_scale")), FALSE);\r
2270 \r
2271         finaltime = strcat(ftos(minutes), ":");\r
2272         if(seconds < 10)\r
2273                 finaltime = strcat(finaltime, "0", ftos(seconds));\r
2274         else\r
2275                 finaltime = strcat(finaltime, ftos(seconds));\r
2276 \r
2277         drawstring(Sbar_ConvertToScreen_TextPosition(finaltime, stov(cvar_string("hud_item_timer_text_position")), cvar("hud_item_timer_text_scale")), finaltime, '1 1 0' * cvar("hud_item_timer_text_scale"), timer_color, sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2278 }\r
2279 \r
2280 void Sbar_Ring()\r
2281 {\r
2282         vector ring_pos, ring1_color, ring2_color;\r
2283         vector text_pos, text1_size, text2_size;\r
2284         float ring1_alpha, ring2_alpha, ring1_size, ring1_clip, ring2_size, ring2_clip;\r
2285         string text1_msg, text2_msg;\r
2286 \r
2287         ring_pos_x = vid_conwidth / 2;\r
2288         ring_pos_y = vid_conheight - vid_conheight / 3.5;\r
2289         ring1_size = cvar("sbar_ring1_scale");\r
2290         ring2_size = cvar("sbar_ring2_scale");\r
2291         ring1_alpha = sbar_alpha_fg * cvar("sbar_ring1_alpha");\r
2292         ring2_alpha = sbar_alpha_fg * cvar("sbar_ring2_alpha");\r
2293         text1_size = '1 1 0' * cvar("sbar_ring1_text_scale");\r
2294         text2_size = '1 1 0' * cvar("sbar_ring2_text_scale");\r
2295 \r
2296         switch(getstati(STAT_SBRING1_TYPE))\r
2297         {\r
2298                 case 0:\r
2299                         // ring disabled\r
2300                         break;\r
2301                 case 1:\r
2302                         // ring shows predator swallow progress, fills with progress\r
2303                         ring1_color = '0.5 1 0.5';\r
2304                         text1_msg = "Swallowing...";\r
2305                         break;\r
2306                 case 2:\r
2307                         // ring shows vore system delay, empties with progress\r
2308                         ring1_color = '0.5 0.5 1';\r
2309                         text1_msg = "Vore delay";\r
2310                         break;\r
2311                 case 3:\r
2312                         // ring shows stomach kick delay, empties with progress\r
2313                         ring1_color = '1 1 0.5';\r
2314                         text1_msg = "Kick delay";\r
2315                         break;\r
2316                 default:\r
2317                         print(strcat("^1Error:^7 Unknown ring type: ", ftos(getstati(STAT_SBRING1_TYPE)), "\n"));\r
2318                         break;\r
2319         }\r
2320         switch(getstati(STAT_SBRING2_TYPE))\r
2321         {\r
2322                 case 0:\r
2323                         // ring disabled\r
2324                         break;\r
2325                 case 1:\r
2326                         // ring shows prey swallow progress, fills with progress\r
2327                         ring2_color = '1 0.5 0.5';\r
2328                         text2_msg = "Swallowed...";\r
2329                         break;\r
2330                 case 2:\r
2331                         // ring shows regurgitation preparing, fills with progress\r
2332                         ring2_color = '1 0.5 1';\r
2333                         text2_msg = "Regurgitating...";\r
2334                         break;\r
2335                 default:\r
2336                         print(strcat("^1Error:^7 Unknown ring type: ", ftos(getstati(STAT_SBRING1_TYPE)), "\n"));\r
2337                         break;\r
2338         }\r
2339         ring1_clip = getstatf(STAT_SBRING1_CLIP);\r
2340         ring2_clip = getstatf(STAT_SBRING2_CLIP);\r
2341 \r
2342         if(text1_msg != "" && cvar("sbar_ring1"))\r
2343         {\r
2344                 DrawCircleClippedPic(ring_pos, ring1_size, Sbar_GetTexture("sb_ring.tga"), ring1_clip, ring1_color, ring1_alpha, DRAWFLAG_ADDITIVE);\r
2345                 text_pos_x = ring_pos_x - stringwidth(text1_msg, FALSE, text1_size) / 2;\r
2346                 text_pos_y = ring_pos_y - ring1_size / 2;\r
2347                 drawstring(text_pos, text1_msg, text1_size, ring1_color, sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2348         }\r
2349         if(text2_msg != "" && cvar("sbar_ring2"))\r
2350         {\r
2351                 DrawCircleClippedPic(ring_pos, ring2_size, Sbar_GetTexture("sb_ring.tga"), ring2_clip, ring2_color, ring2_alpha, DRAWFLAG_ADDITIVE);\r
2352                 text_pos_x = ring_pos_x - stringwidth(text2_msg, FALSE, text2_size) / 2;\r
2353                 text_pos_y = ring_pos_y + ring1_size / 2;\r
2354                 drawstring(text_pos, text2_msg, text2_size, ring2_color, sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2355         }\r
2356 }\r
2357 \r
2358 void CSQC_Strength_Timer() {\r
2359         float stat_items, dt;\r
2360         stat_items = getstati(STAT_ITEMS);\r
2361         /*\r
2362         if not(stat_items & IT_STRENGTH)\r
2363                 if not(stat_items & IT_INVINCIBLE)\r
2364                         return;\r
2365         */\r
2366 \r
2367         if (getstati(STAT_HEALTH) <= 0)\r
2368                 return;\r
2369 \r
2370         vector pos, sz;\r
2371         float strength_time, invincibility_time;\r
2372 \r
2373         //strength\r
2374         strength_time = getstatf(STAT_STRENGTH_FINISHED);\r
2375         if (strength_time) {\r
2376                 dt = strength_time - time;\r
2377                 pos = Sbar_ConvertToScreen_PicPosition(stov(cvar_string("hud_item_strength_icon_position")), stov(cvar_string("hud_item_strength_icon_scale")));\r
2378                 sz = Sbar_ConvertToScreen_PicScale(stov(cvar_string("hud_item_strength_icon_scale")));\r
2379                 if(dt > 0)\r
2380                 {\r
2381                         if(dt < 5)\r
2382                         {\r
2383                                 drawpic_expanding_two(pos, Sbar_GetTexture("sb_str"), sz, '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE,\r
2384                                         bound(0, (ceil(dt) - dt) / 0.5, 1));\r
2385                         }\r
2386                         else\r
2387                         {\r
2388                                 drawpic(pos, Sbar_GetTexture("sb_str"), sz, '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE);\r
2389                         }\r
2390                         Sbar_DrawXNum(stov(cvar_string("hud_item_strength_text_position")), ceil(dt), 2, 0, cvar("hud_item_strength_text_scale"), '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2391                 }\r
2392                 else if(dt > -1)\r
2393                 {\r
2394                         drawpic_expanding(pos, Sbar_GetTexture("sb_str"), sz, '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE,\r
2395                                 bound(0, -dt / 0.5, 1));\r
2396                 }\r
2397         }\r
2398 \r
2399         //invincibility\r
2400         invincibility_time = getstatf(STAT_INVINCIBLE_FINISHED);\r
2401         if (invincibility_time) {\r
2402                 dt = invincibility_time - time;\r
2403                 pos = Sbar_ConvertToScreen_PicPosition(stov(cvar_string("hud_item_invincible_icon_position")), stov(cvar_string("hud_item_invincible_icon_scale")));\r
2404                 sz = Sbar_ConvertToScreen_PicScale(stov(cvar_string("hud_item_invincible_icon_scale")));\r
2405                 if(dt > 0)\r
2406                 {\r
2407                         if(dt < 5)\r
2408                         {\r
2409                                 drawpic_expanding_two(pos, Sbar_GetTexture("sb_invinc"), sz, '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE,\r
2410                                         bound(0, (ceil(dt) - dt) / 0.5, 1));\r
2411                         }\r
2412                         else\r
2413                         {\r
2414                                 drawpic(pos, Sbar_GetTexture("sb_invinc"), sz, '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE);\r
2415                         }\r
2416                         Sbar_DrawXNum(stov(cvar_string("hud_item_invincible_text_position")), ceil(dt), 2, 0, cvar("hud_item_invincible_text_scale"), '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2417                 }\r
2418                 else if(dt > -1)\r
2419                 {\r
2420                         drawpic_expanding(pos, Sbar_GetTexture("sb_invinc"), sz, '1 1 1', sbar_alpha_fg, DRAWFLAG_ADDITIVE,\r
2421                                 bound(0, -dt / 0.5, 1));\r
2422                 }\r
2423         }\r
2424 }\r
2425 \r
2426 #define CENTERPRINT_MAX_LINES 30\r
2427 string centerprint_messages[CENTERPRINT_MAX_LINES];\r
2428 float centerprint_width[CENTERPRINT_MAX_LINES];\r
2429 vector centerprint_start;\r
2430 float centerprint_expire;\r
2431 float centerprint_num;\r
2432 float centerprint_offset_hint;\r
2433 vector centerprint_fontsize;\r
2434 \r
2435 void centerprint(string strMessage)\r
2436 {\r
2437         float i, j, n, hcount;\r
2438         string s;\r
2439 \r
2440         centerprint_fontsize = Sbar_GetFontsize("scr_centersize");\r
2441 \r
2442         centerprint_expire = min(centerprint_expire, time); // if any of the returns happens, this message will fade out\r
2443 \r
2444         if(cvar("scr_centertime") <= 0)\r
2445                 return;\r
2446 \r
2447         if(strMessage == "")\r
2448                 return;\r
2449 \r
2450         // strip trailing newlines\r
2451         j = strlen(strMessage) - 1;\r
2452         while(substring(strMessage, j, 1) == "\n" && j >= 0)\r
2453                 j = j - 1;\r
2454         strMessage = substring(strMessage, 0, j + 1);\r
2455 \r
2456         if(strMessage == "")\r
2457                 return;\r
2458 \r
2459         // strip leading newlines and remember them, they are a hint that the message should be lower on the screen\r
2460         j = 0;\r
2461         while(substring(strMessage, j, 1) == "\n" && j < strlen(strMessage))\r
2462                 j = j + 1;\r
2463         strMessage = substring(strMessage, j, strlen(strMessage) - j);\r
2464         centerprint_offset_hint = j;\r
2465 \r
2466         if(strMessage == "")\r
2467                 return;\r
2468 \r
2469         // if we get here, we have a message. Initialize its height.\r
2470         centerprint_num = 0;\r
2471 \r
2472         n = tokenizebyseparator(strMessage, "\n");\r
2473         i = hcount = 0;\r
2474         for(j = 0; j < n; ++j)\r
2475         {\r
2476                 getWrappedLine_remaining = argv(j);\r
2477                 while(getWrappedLine_remaining)\r
2478                 {\r
2479                         s = getWrappedLine(vid_conwidth * 0.75, centerprint_fontsize, stringwidth_colors);\r
2480                         if(centerprint_messages[i])\r
2481                                 strunzone(centerprint_messages[i]);\r
2482                         centerprint_messages[i] = strzone(s);\r
2483                         centerprint_width[i] = stringwidth(s, TRUE, centerprint_fontsize);\r
2484                         ++i;\r
2485 \r
2486                         // half height for empty lines looks better\r
2487                         if(s == "")\r
2488                                 hcount += 0.5;\r
2489                         else\r
2490                                 hcount += 1;\r
2491 \r
2492                         if(i >= CENTERPRINT_MAX_LINES)\r
2493                                 break;\r
2494                 }\r
2495         }\r
2496 \r
2497         float h, havail;\r
2498         h = centerprint_fontsize_y*hcount;\r
2499 \r
2500         havail = vid_conheight;\r
2501         if(cvar("con_chatpos") < 0)\r
2502                 havail -= (-cvar("con_chatpos") + cvar("con_chat")) * cvar("con_chatsize"); // avoid overlapping chat\r
2503         if(havail > vid_conheight / 4)\r
2504                 havail = vid_conheight / 4; // avoid overlapping HUD\r
2505 \r
2506         centerprint_start_x = 0;\r
2507 \r
2508 #if 0\r
2509         float forbiddenmin, forbiddenmax, allowedmin, allowedmax, preferred;\r
2510 \r
2511         // here, the centerprint would cover the crosshair. REALLY BAD.\r
2512         forbiddenmin = vid_conheight * 0.5 - h - 16;\r
2513         forbiddenmax = vid_conheight * 0.5 + 16;\r
2514 \r
2515         allowedmin = scoreboard_bottom;\r
2516         allowedmax = havail - h;\r
2517         preferred = (havail - h)/2;\r
2518 \r
2519 \r
2520         // possible orderings (total: 4! / 4 = 6)\r
2521         //  allowedmin allowedmax forbiddenmin forbiddenmax\r
2522         //  forbiddenmin forbiddenmax allowedmin allowedmax\r
2523         if(allowedmax < forbiddenmin || allowedmin > forbiddenmax)\r
2524         {\r
2525                 // forbidden doesn't matter in this case\r
2526                 centerprint_start_y = bound(allowedmin, preferred, allowedmax);\r
2527         }\r
2528         //  allowedmin forbiddenmin allowedmax forbiddenmax\r
2529         else if(allowedmin < forbiddenmin && allowedmax < forbiddenmax)\r
2530         {\r
2531                 centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);\r
2532         }\r
2533         //  allowedmin forbiddenmin forbiddenmax allowedmax\r
2534         else if(allowedmin < forbiddenmin)\r
2535         {\r
2536                 // make sure the forbidden zone is not covered\r
2537                 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)\r
2538                         centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);\r
2539                 else\r
2540                         centerprint_start_y = bound(forbiddenmax, preferred, allowedmin);\r
2541         }\r
2542         //  forbiddenmin allowedmin allowedmax forbiddenmax\r
2543         else if(allowedmax < forbiddenmax)\r
2544         {\r
2545                 // it's better to leave the allowed zone (overlap with scoreboard) than\r
2546                 // to cover the forbidden zone (crosshair)\r
2547                 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)\r
2548                         centerprint_start_y = forbiddenmax;\r
2549                 else\r
2550                         centerprint_start_y = forbiddenmin;\r
2551         }\r
2552         //  forbiddenmin allowedmin forbiddenmax allowedmax\r
2553         else\r
2554         {\r
2555                 centerprint_start_y = bound(forbiddenmax, preferred, allowedmax);\r
2556         }\r
2557 #else\r
2558         centerprint_start_y =\r
2559                 min(\r
2560                         max(\r
2561                                 max(scoreboard_bottom, vid_conheight * 0.5 + 16),\r
2562                                 (havail - h)/2\r
2563                         ),\r
2564                         havail - h\r
2565                 );\r
2566 #endif\r
2567 \r
2568         centerprint_num = i;\r
2569         centerprint_expire = time + cvar("scr_centertime");\r
2570 }\r
2571 \r
2572 void Sbar_DrawCenterPrint (void)\r
2573 {\r
2574         float i;\r
2575         vector pos;\r
2576         string ts;\r
2577         float a;\r
2578 \r
2579         //if(time > centerprint_expire)\r
2580         //      return;\r
2581 \r
2582         //a = bound(0, 1 - 2 * (time - centerprint_expire), 1);\r
2583         a = bound(0, 1 - 4 * (time - centerprint_expire), 1);\r
2584         //sz = 1.2 / (a + 0.2);\r
2585 \r
2586         if(a <= 0)\r
2587                 return;\r
2588 \r
2589         pos = centerprint_start;\r
2590         for (i=0; i<centerprint_num; i = i + 1)\r
2591         {\r
2592                 pos_x = (vid_conwidth - centerprint_width[i]) * 0.5;\r
2593                 ts = centerprint_messages[i];\r
2594                 if (ts != "")\r
2595                 {\r
2596                         dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)\r
2597                         drawcolorcodedstring(pos, ts, centerprint_fontsize, a, DRAWFLAG_NORMAL);\r
2598                         //  - '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
2599                         pos_y = pos_y + centerprint_fontsize_y;\r
2600                 }\r
2601                 else\r
2602                         // half height for empty lines looks better\r
2603                         pos_y = pos_y + centerprint_fontsize_y * 0.5;\r
2604         }\r
2605 }\r
2606 \r
2607 vector Sbar_DrawNoteLine(vector offset, string s)\r
2608 {\r
2609         dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)\r
2610         drawcolorcodedstring(\r
2611                 offset - '1 0 0' * stringwidth(s, TRUE, sbar_fontsize),\r
2612                 s,\r
2613                 sbar_fontsize,\r
2614                 sbar_alpha_fg,\r
2615                 0\r
2616         );\r
2617         return offset + sbar_fontsize_y * '0 1 0';\r
2618 }\r
2619 \r
2620 void Sbar_DrawPressedKeys(void)\r
2621 {\r
2622         vector pos, bgsize;\r
2623         float pressedkeys;\r
2624 \r
2625         pos = stov(cvar_string("cl_showpressedkeys_position"));\r
2626 \r
2627         bgsize = '126 75 0';\r
2628 \r
2629         pos = '1 0 0' * (vid_conwidth - bgsize_x) * pos_x\r
2630             + '0 1 0' * (vid_conheight - bgsize_y) * pos_y;\r
2631         pos -= '-15 -6 0'; // adjust to the origin of these numbers\r
2632 \r
2633         pressedkeys = getstatf(STAT_PRESSED_KEYS);\r
2634         drawpic(pos + '-15   -6   0', Sbar_GetTexture("keys/key_bg.tga"),           bgsize, '1 1 1', 0.1 * sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2635         drawpic(pos + ' 83.5  9   0', Sbar_GetTexture((pressedkeys & KEY_CROUCH) ? "keys/key_crouch_inv.tga" : "keys/key_crouch.tga"), ' 24 24 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2636         drawpic(pos + ' 32   -1.5 0', Sbar_GetTexture((pressedkeys & KEY_FORWARD) ? "keys/key_forward_inv.tga" : "keys/key_forward.tga"),  ' 32 32 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2637         drawpic(pos + '-11.5  9   0', Sbar_GetTexture((pressedkeys & KEY_JUMP) ? "keys/key_jump_inv.tga" : "keys/key_jump.tga"),     ' 24 24 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2638         drawpic(pos + ' -1   32   0', Sbar_GetTexture((pressedkeys & KEY_LEFT) ? "keys/key_left_inv.tga" : "keys/key_left.tga"),     ' 32 32 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2639         drawpic(pos + ' 32   32   0', Sbar_GetTexture((pressedkeys & KEY_BACKWARD) ? "keys/key_backward_inv.tga" : "keys/key_backward.tga"), ' 32 32 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2640         drawpic(pos + ' 65   32   0', Sbar_GetTexture((pressedkeys & KEY_RIGHT) ? "keys/key_right_inv.tga" : "keys/key_right.tga"),    ' 32 32 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2641 }\r
2642 \r
2643 void Sbar_ShowSpeed(void)\r
2644 {\r
2645         vector numsize;\r
2646         float pos, conversion_factor;\r
2647         string speed, zspeed, unit;\r
2648 \r
2649         switch(cvar("cl_showspeed_unit"))\r
2650         {\r
2651                 default:\r
2652                 case 0:\r
2653                         unit = "";\r
2654                         conversion_factor = 1.0;\r
2655                         break;\r
2656                 case 1:\r
2657                         unit = " qu/s";\r
2658                         conversion_factor = 1.0;\r
2659                         break;\r
2660                 case 2:\r
2661                         unit = " m/s";\r
2662                         conversion_factor = 0.0254;\r
2663                         break;\r
2664                 case 3:\r
2665                         unit = " km/h";\r
2666                         conversion_factor = 0.0254 * 3.6;\r
2667                         break;\r
2668                 case 4:\r
2669                         unit = " mph";\r
2670                         conversion_factor = 0.0254 * 3.6 * 0.6213711922;\r
2671                         break;\r
2672                 case 5:\r
2673                         unit = " knots";\r
2674                         conversion_factor = 0.0254 * 1.943844492; // 1 m/s = 1.943844492 knots, because 1 knot = 1.852 km/h\r
2675                         break;\r
2676         }\r
2677 \r
2678         speed = strcat(ftos(floor( vlen(pmove_vel - pmove_vel_z * '0 0 1') * conversion_factor + 0.5 )), unit);\r
2679 \r
2680         numsize_x = numsize_y = cvar("cl_showspeed_size");\r
2681         pos = (vid_conheight - numsize_y) * cvar("cl_showspeed_position");\r
2682         \r
2683         drawfont = sbar_bigfont;\r
2684         drawstringcenter('1 0 0' + pos * '0 1 0', speed, numsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2685 \r
2686         if (cvar("cl_showspeed_z") == 1) {\r
2687                 zspeed = strcat(ftos(fabs(floor( pmove_vel_z * conversion_factor + 0.5 ))), unit);\r
2688                 drawstringcenter('1 0 0' + pos * '0 1 0' + numsize_y * '0 1 0', zspeed, numsize * 0.5, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2689         }\r
2690 \r
2691         drawfont = sbar_font;\r
2692 }\r
2693 \r
2694 vector acc_prevspeed;\r
2695 float acc_prevtime;\r
2696 float acc_avg;\r
2697 \r
2698 void Sbar_ShowAcceleration(void)\r
2699 {\r
2700         float acceleration, sz, scale, alpha, f;\r
2701         vector pos, top, rgb;\r
2702         top_x = vid_conwidth/2;\r
2703         top_y = 0;\r
2704 \r
2705         f = time - acc_prevtime;\r
2706         if(cvar("cl_showacceleration_z"))\r
2707                 acceleration = (vlen(pmove_vel) - vlen(acc_prevspeed)) * (1 / f);\r
2708         else\r
2709                 acceleration = (vlen(pmove_vel - '0 0 1' * pmove_vel_z) - vlen(acc_prevspeed - '0 0 1' * acc_prevspeed_z)) * (1 / f);\r
2710         acc_prevspeed = pmove_vel;\r
2711         acc_prevtime = time;\r
2712 \r
2713         f = bound(0, f * 10, 1);\r
2714         acc_avg = acc_avg * (1 - f) + acceleration * f;\r
2715         acceleration = acc_avg / getstatf(STAT_MOVEVARS_MAXSPEED);\r
2716 \r
2717         pos = top - sz/2 * '0 1 0' + (cvar("cl_showacceleration_position") * vid_conheight) * '0 1 0';\r
2718 \r
2719         sz = cvar("cl_showacceleration_size");\r
2720         scale = cvar("cl_showacceleration_scale");\r
2721         alpha = cvar("cl_showacceleration_alpha");\r
2722         if (cvar("cl_showacceleration_color_custom"))\r
2723                 rgb = stov(cvar_string("cl_showacceleration_color"));\r
2724         else {\r
2725                 rgb = '1 1 1';\r
2726                 if (acceleration < 0) {\r
2727                         rgb = '1 .5 .5' - '0 .5 .5' * bound(0, -acceleration * 0.2, 1);\r
2728                 } else if (acceleration > 0) {\r
2729                         rgb = '.5 1 .5' - '.5 0 .5' * bound(0, +acceleration * 0.2, 1);\r
2730                 }\r
2731         }\r
2732                 \r
2733         if (acceleration > 0)\r
2734                 drawpic(pos, Sbar_GetTexture("accelerometer_gradient"), acceleration * scale * '40 0 0' + sz * '0 1 0', rgb, alpha * sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2735         else if (acceleration < 0)\r
2736                 drawpic(pos + acceleration * scale * '40 0 0', Sbar_GetTexture("accelerometer_gradient"), -acceleration * scale * '40 0 0' + sz * '0 1 0', rgb, alpha * sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2737 }\r
2738 \r
2739 void Sbar_DrawAccuracyStats_Description_Hitscan(vector position)\r
2740 {\r
2741         drawstring(position + '0 3 0' * sbar_fontsize_y, "Shots fired:", sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2742         drawstring(position + '0 5 0' * sbar_fontsize_y, "Shots hit:", sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2743         drawstring(position + '0 7 0' * sbar_fontsize_y, "Accuracy:", sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2744         drawstring(position + '0 9 0' * sbar_fontsize_y, "Shots missed:", sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2745 }\r
2746 \r
2747 /*void Sbar_DrawAccuracyStats_Description_Splash(vector position)\r
2748 {\r
2749         drawstring(position + '0 3 0' * sbar_fontsize_y, "Maximum damage:", sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2750         drawstring(position + '0 5 0' * sbar_fontsize_y, "Actual damage:", sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2751         drawstring(position + '0 7 0' * sbar_fontsize_y, "Accuracy:", sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2752         drawstring(position + '0 9 0' * sbar_fontsize_y, "Damage wasted:", sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2753 }*/ // we have no splash damage weapons, but keep this code just in case\r
2754 \r
2755 void Sbar_DrawAccuracyStats()\r
2756 {\r
2757         float i, count_hitscan, /*count_splash,*/ row_hitscan/*, row_splash*/;  // count is the number of 'colums'\r
2758         float weapon_hit, weapon_damage, weapon_stats;\r
2759         float left_border;  // position where the weapons start, the description is in the border\r
2760         vector fill_colour, fill_size;\r
2761         vector pos;\r
2762         vector border_colour;\r
2763 \r
2764         float col_margin = 20;  // pixels between the columns\r
2765         float row_margin = 20;  // pixels between the rows\r
2766 \r
2767         fill_size_x = 5 * sbar_fontsize_x;  // width of the background\r
2768         fill_size_y = 10 * sbar_fontsize_y;  // height of the background\r
2769 \r
2770         drawfont = sbar_bigfont;\r
2771         pos_x = 0;\r
2772         pos_y = cvar("sbar_scoreboard_offset");\r
2773         pos_z = 0;\r
2774         drawstringcenter(pos, "Weapon Accuracy", 2 * sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2775 \r
2776         left_border = col_margin + 11 * sbar_fontsize_x;\r
2777 \r
2778         drawfont = sbar_font;\r
2779 \r
2780         if(warmup_stage)\r
2781         {\r
2782                 pos_y += 40;\r
2783                 if(mod(time, 1) >= 0.4)\r
2784                         drawstringcenter(pos, "Stats are not tracked during warmup stage", sbar_fontsize, '1 1 0', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2785 \r
2786                 return;\r
2787         }\r
2788 \r
2789         if(gametype == GAME_RACE || gametype == GAME_CTS)\r
2790         {\r
2791                 pos_y += 40;\r
2792                 if(mod(time, 1) >= 0.4)\r
2793                         drawstringcenter(pos, "Stats are not tracked in Race/CTS", sbar_fontsize, '1 1 0', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2794 \r
2795                 return;\r
2796         }\r
2797 \r
2798         float top_border_hitscan = cvar("sbar_scoreboard_offset") + 55;  // position where the hitscan row starts: pixels down the screen\r
2799         Sbar_DrawAccuracyStats_Description_Hitscan('1 0 0' * col_margin + '0 1 0' * top_border_hitscan);\r
2800 \r
2801 //      float top_border_splash = cvar("sbar_scoreboard_offset") + 175;  // position where the splash row starts: pixels down the screen\r
2802 //      Sbar_DrawAccuracyStats_Description_Splash('1 0 0' * col_margin + '0 1 0' * top_border_splash);\r
2803 \r
2804         for(i = WEP_FIRST; i <= WEP_LAST; ++i)\r
2805         {\r
2806                 self = get_weaponinfo(i);\r
2807                 if not(self.weapons)\r
2808                         continue;\r
2809                 weapon_hit = weapon_hits[i-WEP_FIRST];\r
2810                 weapon_damage = weapon_fired[i-WEP_FIRST];\r
2811                 border_colour = (i == activeweapon) ? '1 1 1' : '0 0 0';  // white or black border\r
2812 \r
2813                 if (weapon_damage) {\r
2814                         /*if (self.spawnflags & WEP_TYPE_SPLASH) {\r
2815                                 weapon_stats = bound(0, floor(100 * weapon_hit / weapon_damage), 100);\r
2816 \r
2817                                 fill_colour_x = 1 - 0.015 * weapon_stats;\r
2818                                 fill_colour_y = 1 - 0.015 * (100 - weapon_stats);\r
2819 \r
2820                                 // how the background colour is calculated\r
2821                                 // %    red             green   red_2                   green_2\r
2822                                 // 0    1               0               1 - % * 0.015   1 - (100 - %) * 0.015\r
2823                                 // 10   0.85    0               1 - % * 0.015   1 - (100 - %) * 0.015\r
2824                                 // 20   0.70    0               1 - % * 0.015   1 - (100 - %) * 0.015\r
2825                                 // 30   0.55    0               1 - % * 0.015   1 - (100 - %) * 0.015\r
2826                                 // 40   0.40    0.10    1 - % * 0.015   1 - (100 - %) * 0.015\r
2827                                 // 50   0.25    0.25    1 - % * 0.015   1 - (100 - %) * 0.015\r
2828                                 // 60   0.10    0.40    1 - % * 0.015   1 - (100 - %) * 0.015\r
2829                                 // 70   0               0.55    1 - % * 0.015   1 - (100 - %) * 0.015\r
2830                                 // 80   0               0.70    1 - % * 0.015   1 - (100 - %) * 0.015\r
2831                                 // 90   0               0.85    1 - % * 0.015   1 - (100 - %) * 0.015\r
2832                                 // 100  0               1               1 - % * 0.015   1 - (100 - %) * 0.015\r
2833 \r
2834                                 if ((left_border + count_splash * (fill_size_x + col_margin) + fill_size_x) >= vid_conwidth)\r
2835                                 {\r
2836                                         count_splash = 0;\r
2837                                         ++row_splash;\r
2838                                         Sbar_DrawAccuracyStats_Description_Splash('1 0 0' * col_margin + '0 1 0' * (top_border_splash + row_splash * (fill_size_y + row_margin)));\r
2839                                 }\r
2840 \r
2841                                 pos_x = left_border + count_splash * (fill_size_x + col_margin);\r
2842                                 pos_y = top_border_splash + row_splash * (fill_size_y + row_margin);\r
2843 \r
2844                                 // background\r
2845                                 drawpic(pos, Sbar_GetTexture("sb_accuracy"), fill_size , fill_colour, sbar_alpha_bg, DRAWFLAG_NORMAL);\r
2846                                 drawborderlines(sbar_border_thickness, pos, fill_size, border_colour, sbar_alpha_bg, DRAWFLAG_NORMAL);\r
2847 \r
2848                                 // the weapon\r
2849                                 drawpic(pos, Sbar_GetTexture("inv_weapon"), self.netname), '1 0.5 0' * fill_size_x , '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2850 \r
2851                                 // the amount of shots fired or max damage\r
2852                                 drawstringright(pos + '4.5 0 0' * sbar_fontsize_x + '0 3 0' * sbar_fontsize_y, ftos(weapon_damage), sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2853 \r
2854                                 // the amount of hits or actual damage\r
2855                                 drawstringright(pos + '4.5 0 0' * sbar_fontsize_x + '0 5 0' * sbar_fontsize_y, ftos(weapon_hit), sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2856 \r
2857                                 // the accuracy\r
2858                                 drawstringright(pos + '4.5 0 0' * sbar_fontsize_x + '0 7 0' * sbar_fontsize_y, strcat(ftos(weapon_stats),"%"), sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2859 \r
2860                                 // the amount of shots missed or damage wasted\r
2861                                 drawstringright(pos + '4.5 0 0' * sbar_fontsize_x + '0 9 0' * sbar_fontsize_y, ftos(max(0, weapon_damage - weapon_hit)), sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2862 \r
2863                                 ++count_splash;\r
2864                         } else*/ // we have no splash damage weapons, but keep this code just in case\r
2865 \r
2866                         if (self.spawnflags & WEP_TYPE_HITSCAN) {\r
2867                                 weapon_stats = bound(0, floor(100 * weapon_hit / weapon_damage), 100);\r
2868 \r
2869                                 fill_colour_x = 1 - 0.015 * weapon_stats;\r
2870                                 fill_colour_y = 1 - 0.015 * (100 - weapon_stats);\r
2871 \r
2872                                 // how the background colour is calculated\r
2873                                 // %    red             green   red_2                   green_2\r
2874                                 // 0    1               0               1 - % * 0.015   1 - (100 - %) * 0.015\r
2875                                 // 10   0.850   0               1 - % * 0.015   1 - (100 - %) * 0.015\r
2876                                 // 20   0.70    0               1 - % * 0.015   1 - (100 - %) * 0.015\r
2877                                 // 30   0.55    0               1 - % * 0.015   1 - (100 - %) * 0.015\r
2878                                 // 40   0.40    0.10    1 - % * 0.015   1 - (100 - %) * 0.015\r
2879                                 // 50   0.25    0.25    1 - % * 0.015   1 - (100 - %) * 0.015\r
2880                                 // 60   0.10    0.40    1 - % * 0.015   1 - (100 - %) * 0.015\r
2881                                 // 70   0               0.55    1 - % * 0.015   1 - (100 - %) * 0.015\r
2882                                 // 80   0               0.70    1 - % * 0.015   1 - (100 - %) * 0.015\r
2883                                 // 90   0               0.85    1 - % * 0.015   1 - (100 - %) * 0.015\r
2884                                 // 100  0               1               1 - % * 0.015   1 - (100 - %) * 0.015\r
2885 \r
2886                                 if ((left_border + count_hitscan * (fill_size_x + col_margin) + fill_size_x + cvar("stats_right_margin")) >= vid_conwidth)\r
2887                                 {\r
2888                                         count_hitscan = 0;\r
2889                                         ++row_hitscan;\r
2890                                         Sbar_DrawAccuracyStats_Description_Hitscan('1 0 0' * col_margin + '0 1 0' * (top_border_hitscan + row_hitscan * (fill_size_y + row_margin)));\r
2891                                 }\r
2892 \r
2893                                 pos_x = left_border + count_hitscan * (fill_size_x + col_margin);\r
2894                                 pos_y = top_border_hitscan + row_hitscan * (fill_size_y + row_margin);\r
2895 \r
2896                                 // background\r
2897                                 drawpic(pos, Sbar_GetTexture("sb_accuracy"), fill_size , fill_colour, sbar_alpha_bg, DRAWFLAG_NORMAL);\r
2898                                 drawborderlines(sbar_border_thickness, pos, fill_size, border_colour, sbar_alpha_bg, DRAWFLAG_NORMAL);\r
2899 \r
2900                                 // the weapon\r
2901                                 drawpic(pos, Sbar_GetTexture(strcat("inv_weapon", self.netname)), '1 0.5 0' * fill_size_x , '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2902 \r
2903                                 // the amount of shots fired or max damage\r
2904                                 drawstringright(pos + '4.5 0 0' * sbar_fontsize_x + '0 3 0' * sbar_fontsize_y, ftos(weapon_damage), sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2905 \r
2906                                 // the amount of hits or actual damage\r
2907                                 drawstringright(pos + '4.5 0 0' * sbar_fontsize_x + '0 5 0' * sbar_fontsize_y, ftos(weapon_hit), sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2908 \r
2909                                 // the accuracy\r
2910                                 drawstringright(pos + '4.5 0 0' * sbar_fontsize_x + '0 7 0' * sbar_fontsize_y, strcat(ftos(weapon_stats),"%"), sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2911 \r
2912                                 // the amount of shots missed or damage wasted\r
2913                                 drawstringright(pos + '4.5 0 0' * sbar_fontsize_x + '0 9 0' * sbar_fontsize_y, ftos(max(0, weapon_damage - weapon_hit)), sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
2914 \r
2915                                 ++count_hitscan;\r
2916                         }\r
2917                 }\r
2918         }\r
2919 }\r
2920 \r
2921 void drawstringright(vector position, string text, vector scale, vector rgb, float alpha, float flag)\r
2922 {\r
2923         position_x -= 2 / 3 * strlen(text) * scale_x;\r
2924         drawstring(position, text, scale, rgb, alpha, flag);\r
2925 }\r
2926 \r
2927 void drawstringcenter(vector position, string text, vector scale, vector rgb, float alpha, float flag)\r
2928 {\r
2929         position_x = 0.5 * (vid_conwidth - 0.6025 * strlen(text) * scale_x);\r
2930         drawstring(position, text, scale, rgb, alpha, flag);\r
2931 }\r
2932 \r
2933 void Sbar_Reset (void)\r
2934 {\r
2935         // reset gametype specific icons\r
2936         if(gametype == GAME_KEYHUNT)\r
2937                 CSQC_kh_hudreset();\r
2938         else if(gametype == GAME_CTF)\r
2939                 CSQC_ctf_hudreset();\r
2940 }\r
2941 \r
2942 float vote_yescount;\r
2943 float vote_nocount;\r
2944 float vote_needed;\r
2945 float vote_highlighted; // currently selected vote\r
2946 \r
2947 float vote_active; // is there an active vote?\r
2948 float vote_prev; // previous state of vote_active to check for a change\r
2949 float vote_alpha;\r
2950 float vote_change; // "time" when vote_active changed\r
2951 \r
2952 void Sbar_Draw (void)\r
2953 {\r
2954         // vectors for top right, bottom right, bottom and bottom left corners\r
2955         vector topright;\r
2956         vector bottom;\r
2957         vector bottomright;\r
2958         vector bottomleft;\r
2959 \r
2960         topright_x = vid_conwidth;\r
2961         topright_y = 0;\r
2962         topright_z = 0;\r
2963 \r
2964         bottom_x = vid_conwidth/2;\r
2965         bottom_y = vid_conheight;\r
2966         bottom_z = 0;\r
2967 \r
2968         bottomright_x = vid_conwidth;\r
2969         bottomright_y = vid_conheight;\r
2970         bottomright_z = 0;\r
2971 \r
2972         bottomleft_x = 0;\r
2973         bottomleft_y = vid_conheight;\r
2974         bottomleft_z = 0;\r
2975 \r
2976         sbar_alpha_bg = cvar("sbar_alpha_bg") * (1 - cvar("_menu_alpha"));\r
2977         sbar_border_thickness = bound(0, cvar("sbar_border_thickness"), 5);\r
2978         sbar_accuracy_border_thickness = bound(0, cvar_or("sbar_accuracy_border_thickness", 1), 5);\r
2979         sbar_color_bg_team = cvar("sbar_color_bg_team");\r
2980 \r
2981         float weapon_stats;\r
2982         float fade;\r
2983 \r
2984         weapon_stats = getstati(STAT_DAMAGE_HITS);\r
2985         weapon_number = weapon_stats & 63;\r
2986         weapon_hits[weapon_number-WEP_FIRST] = floor(weapon_stats / 64);\r
2987 \r
2988         weapon_stats = getstati(STAT_DAMAGE_FIRED);\r
2989         weapon_number = weapon_stats & 63;\r
2990         weapon_fired[weapon_number-WEP_FIRST] = floor(weapon_stats / 64);\r
2991 \r
2992         vector o; o = '1 0 0' * vid_conwidth;\r
2993         o_y = 28; // move spectator text slightly down to prevent overlapping the timer\r
2994 \r
2995         string s;\r
2996         vector pos;\r
2997         pos = '0 0 0';\r
2998 \r
2999         sbar_fontsize = Sbar_GetFontsize("sbar_fontsize");\r
3000         sbar_fontsize_spec = Sbar_GetFontsize("sbar_fontsize_spec");\r
3001         if(sbar_fontsize != sbar_oldfontsize)\r
3002         {\r
3003                 Cmd_Sbar_SetFields(0);\r
3004                 sbar_oldfontsize = sbar_fontsize;\r
3005         }\r
3006 \r