]> git.xonotic.org Git - voretournament/voretournament.git/blob - data/qcsrc/client/hud.qc
Include gmqcc binaries for Windows and Linux
[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 string Sbar_GetTexture(string img)\r
629 {\r
630         string path = cvar_string("hud_style");\r
631         return strcat("gfx/hud/", path, "/", img);\r
632 }\r
633 \r
634 // MOVEUP::\r
635 vector sbar_field_rgb;\r
636 string sbar_field_icon0;\r
637 string sbar_field_icon1;\r
638 string sbar_field_icon2;\r
639 vector sbar_field_icon0_rgb;\r
640 vector sbar_field_icon1_rgb;\r
641 vector sbar_field_icon2_rgb;\r
642 float sbar_field_icon0_alpha;\r
643 float sbar_field_icon1_alpha;\r
644 float sbar_field_icon2_alpha;\r
645 string Sbar_GetField(entity pl, float field)\r
646 {\r
647         float tmp, num, denom, f;\r
648         string str;\r
649         sbar_field_rgb = '1 1 1';\r
650         sbar_field_icon0 = "";\r
651         sbar_field_icon1 = "";\r
652         sbar_field_icon2 = "";\r
653         sbar_field_icon0_rgb = '1 1 1';\r
654         sbar_field_icon1_rgb = '1 1 1';\r
655         sbar_field_icon2_rgb = '1 1 1';\r
656         sbar_field_icon0_alpha = 1;\r
657         sbar_field_icon1_alpha = 1;\r
658         sbar_field_icon2_alpha = 1;\r
659         switch(field)\r
660         {\r
661                 case SP_PING:\r
662                         if not(pl.gotscores)\r
663                                 return "\x8D\x8D\x8D"; // >>> sign\r
664                         //str = getplayerkey(pl.sv_entnum, "ping");\r
665                         f = pl.ping;\r
666                         if(f == 0)\r
667                                 return "N/A";\r
668                         tmp = max(0, min(220, f-80)) / 220;\r
669                         sbar_field_rgb = '1 1 1' - '0 1 1'*tmp;\r
670                         return ftos(f);\r
671 \r
672                 case SP_PL:\r
673                         if not(pl.gotscores)\r
674                                 return "N/A";\r
675                         f = pl.ping_packetloss;\r
676                         tmp = pl.ping_movementloss;\r
677                         if(f == 0 && tmp == 0)\r
678                                 return "";\r
679                         str = ftos(ceil(f * 100));\r
680                         if(tmp != 0)\r
681                                 str = strcat(str, "~", ftos(ceil(tmp * 100)));\r
682                         tmp = bound(0, f / 0.2 + tmp / 0.04, 1); // 20% is REALLY BAD pl\r
683                         sbar_field_rgb = '1 0.5 0.5' - '0 0.5 0.5'*tmp;\r
684                         return str;\r
685 \r
686                 case SP_NAME:\r
687                         if(ready_waiting && pl.ready)\r
688                         {\r
689                                 sbar_field_icon0 = "gfx/sb_player_ready";\r
690                         }\r
691                         else if(!teamplay)\r
692                         {\r
693                                 f = stof(getplayerkey(pl.sv_entnum, "colors"));\r
694                                 {\r
695                                         sbar_field_icon0 = Sbar_GetTexture("sb_playercolor_base");\r
696                                         sbar_field_icon1 = Sbar_GetTexture("sb_playercolor_shirt");\r
697                                         sbar_field_icon1_rgb = colormapPaletteColor(floor(f / 16), 0);\r
698                                         sbar_field_icon2 = Sbar_GetTexture("sb_playercolor_pants");\r
699                                         sbar_field_icon2_rgb = colormapPaletteColor(mod(f, 16), 1);\r
700                                 }\r
701                         }\r
702                         return GetPlayerName(pl.sv_entnum);\r
703 \r
704                 case SP_FRAGS:\r
705                         f = pl.(scores[SP_KILLS]);\r
706                         f -= pl.(scores[SP_SUICIDES]);\r
707                         return ftos(f);\r
708 \r
709                 case SP_KDRATIO:\r
710                         num = pl.(scores[SP_KILLS]);\r
711                         denom = pl.(scores[SP_DEATHS]);\r
712 \r
713                         if(denom == 0) {\r
714                                 sbar_field_rgb = '0 1 0';\r
715                                 str = ftos(num);\r
716                         } else if(num <= 0) {\r
717                                 sbar_field_rgb = '1 0 0';\r
718                                 str = ftos(num/denom);\r
719                         } else\r
720                                 str = ftos(num/denom);\r
721 \r
722                         tmp = strstrofs(str, ".", 0);\r
723                         if(tmp > 0)\r
724                                 str = substring(str, 0, tmp+2);\r
725                         return str;\r
726 \r
727                 default:\r
728                         tmp = pl.(scores[field]);\r
729                         f = scores_flags[field];\r
730                         if(field == ps_primary)\r
731                                 sbar_field_rgb = '1 1 0';\r
732                         else if(field == ps_secondary)\r
733                                 sbar_field_rgb = '0 1 1';\r
734                         else\r
735                                 sbar_field_rgb = '1 1 1';\r
736                         return ScoreString(f, tmp);\r
737         }\r
738         //return "error";\r
739 }\r
740 \r
741 string Sbar_GetStomachField(entity pl, float field)\r
742 {\r
743         switch(field)\r
744         {\r
745                 case ST_HIGHLIGHT:\r
746                         return ""; // the returned value is not used, we only need the field\r
747 \r
748                 case ST_NAME:\r
749                         return GetPlayerName(pl.sv_entnum);\r
750 \r
751                 case ST_HEALTH:\r
752                         return ftos(pl.plhealth);\r
753 \r
754                 default:\r
755                         return "N/A";\r
756         }\r
757         //return "error";\r
758 }\r
759 \r
760 string Sbar_GetStomachFieldPred(entity pl, float field)\r
761 {\r
762         switch(field)\r
763         {\r
764                 case STP_NAME:\r
765                         return GetPlayerName(pl.sv_entnum);\r
766                 default:\r
767                         return "N/A";\r
768         }\r
769         //return "error";\r
770 }\r
771 \r
772 vector Sbar_GetVoreColor()\r
773 {\r
774         // gets color based on vore status\r
775         if(getstati(STAT_VORE_EATEN))\r
776         {\r
777                 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
778                         return stov(cvar_string("sbar_stomachboard_color2"));\r
779                 else\r
780                         return stov(cvar_string("sbar_stomachboard_color3"));\r
781         }\r
782         else\r
783                 return stov(cvar_string("sbar_stomachboard_color1"));\r
784 }\r
785 \r
786 vector colorfade_current;\r
787 vector Sbar_ColorFade(vector target_color)\r
788 {\r
789         local float step;\r
790         step = cvar("sbar_stomachboard_status_fade") * frametime;\r
791 \r
792         if(colorfade_current_x >= target_color_x + step)\r
793                 colorfade_current_x -= step;\r
794         else if(colorfade_current_x <= target_color_x - step)\r
795                 colorfade_current_x += step;\r
796 \r
797         if(colorfade_current_y >= target_color_y + step)\r
798                 colorfade_current_y -= step;\r
799         else if(colorfade_current_y <= target_color_y - step)\r
800                 colorfade_current_y += step;\r
801 \r
802         if(colorfade_current_z >= target_color_z + step)\r
803                 colorfade_current_z -= step;\r
804         else if(colorfade_current_z <= target_color_z - step)\r
805                 colorfade_current_z += step;\r
806 \r
807         return colorfade_current;\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, Sbar_GetTexture("sb_playercolor_base"), sz, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
1051                         drawpic(pos, Sbar_GetTexture("sb_playercolor_shirt"), sz, colormapPaletteColor(floor(f / 16), 0), sbar_alpha_fg, DRAWFLAG_NORMAL);\r
1052                         drawpic(pos, Sbar_GetTexture("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 not(pl.sv_entnum == player_localentnum - 1 || (spectatee_status && pl.sv_entnum == spectatee_status - 1))\r
1064                         {\r
1065                                 drawpic(pos, Sbar_GetTexture("sb_health"), sz, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
1066 \r
1067                                 pos_x = position_x + dimensions_x * cvar("hud_item_preylist_health_text_location");\r
1068                                 sz_x = dimensions_x * cvar("hud_item_preylist_health_text_length");\r
1069                                 drawcolorcodedstring(pos, textShortenToWidth(str, sz_x, font_sz, stringwidth_colors), font_sz, sbar_alpha_fg, DRAWFLAG_NORMAL);\r
1070                         }\r
1071                 }\r
1072         }\r
1073 }\r
1074 \r
1075 void Sbar_PrintStomachboardItemPred(entity pl, vector position, vector dimensions)\r
1076 {\r
1077         // shows the name of our predator\r
1078 \r
1079         string str;\r
1080         float f, field, field_number;\r
1081         field_number = 2; // the number of components each row has\r
1082 \r
1083         position = Sbar_ConvertToScreen_PicPosition(position, dimensions);\r
1084         dimensions = Sbar_ConvertToScreen_PicScale(dimensions);\r
1085 \r
1086         // set font size to the height of each entry\r
1087         vector font_sz;\r
1088         font_sz_x = font_sz_y = dimensions_y;\r
1089 \r
1090         float fieldcounter;\r
1091         for(fieldcounter = 1; fieldcounter <= field_number; ++fieldcounter)\r
1092         {\r
1093                 vector pos, sz;\r
1094                 field = -fieldcounter;\r
1095                 str = Sbar_GetStomachFieldPred(pl, field);\r
1096 \r
1097                 // row highlighting\r
1098                 if(field == ST_HIGHLIGHT)\r
1099                 {\r
1100                         pos = position;\r
1101                         sz = dimensions;\r
1102 \r
1103                         drawfill(pos, sz, Sbar_ColorFade(Sbar_GetVoreColor()), cvar("sbar_stomachboard_highlight_alpha") * sbar_alpha_fg, DRAWFLAG_NORMAL);\r
1104                 }\r
1105 \r
1106                 if(field == STP_NAME) {\r
1107                         pos_x = position_x + dimensions_x * cvar("hud_item_predator_colors_location");\r
1108                         sz_x = dimensions_x * cvar("hud_item_predator_colors_length");\r
1109                         f = stof(getplayerkey(pl.sv_entnum, "colors"));\r
1110                         drawpic(pos, Sbar_GetTexture("sb_playercolor_base"), sz, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
1111                         drawpic(pos, Sbar_GetTexture("sb_playercolor_shirt"), sz, colormapPaletteColor(floor(f / 16), 0), sbar_alpha_fg, DRAWFLAG_NORMAL);\r
1112                         drawpic(pos, Sbar_GetTexture("sb_playercolor_pants"), sz, colormapPaletteColor(mod(f, 16), 1), sbar_alpha_fg, DRAWFLAG_NORMAL);\r
1113 \r
1114                         pos_x = position_x + dimensions_x * cvar("hud_item_predator_name_location");\r
1115                         sz_x = dimensions_x * cvar("hud_item_predator_name_length");\r
1116                         drawcolorcodedstring(pos, textShortenToWidth(str, sz_x, font_sz, stringwidth_colors), font_sz, sbar_alpha_fg, DRAWFLAG_NORMAL);\r
1117                 }\r
1118         }\r
1119 }\r
1120 \r
1121 /*\r
1122  * Sbar_Scoreboard_MakeTable\r
1123  *\r
1124  * Makes a table for a team (for all playing players in DM) and fills it\r
1125  */\r
1126 \r
1127 vector Sbar_Scoreboard_MakeTable(vector pos, entity tm, vector rgb, vector bg_size)\r
1128 {\r
1129         float body_table_height, i;\r
1130         vector tmp, column_dim;\r
1131         entity pl;\r
1132 \r
1133         body_table_height = 1.25 * sbar_fontsize_y * max(1, tm.team_size); // no player? show 1 empty line\r
1134 \r
1135         pos -= '1 1 0';\r
1136 \r
1137         tmp_x = sbwidth + 2;\r
1138         tmp_y = 1.25 * sbar_fontsize_y;\r
1139 \r
1140         // rounded header\r
1141         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
1142 \r
1143         // table border\r
1144         tmp_y += sbar_border_thickness;\r
1145         tmp_y += body_table_height;\r
1146         drawborderlines(sbar_border_thickness, pos, tmp, '0 0 0', sbar_scoreboard_alpha_bg, DRAWFLAG_NORMAL); // more transparency for the scoreboard\r
1147 \r
1148         // separator header/table\r
1149         pos_y += 1.25 * sbar_fontsize_y;\r
1150         tmp_y = sbar_border_thickness;\r
1151         drawfill(pos, tmp, '0 0 0', sbar_scoreboard_alpha_bg, DRAWFLAG_NORMAL);\r
1152 \r
1153         pos_y += sbar_border_thickness;\r
1154 \r
1155         // table background\r
1156         tmp_y = body_table_height;\r
1157         drawpic_tiled(pos, Sbar_GetTexture("sb_scoreboard_bg"), bg_size, tmp, rgb * sbar_color_bg_team, sbar_scoreboard_alpha_bg, DRAWFLAG_NORMAL);\r
1158 \r
1159         // anyway, apply some color\r
1160         //drawfill(pos, tmp + '2 0 0', rgb, 0.1, DRAWFLAG_NORMAL);\r
1161 \r
1162         // go back to the top to make alternated columns highlighting and to print the strings\r
1163         pos_y -= 1.25 * sbar_fontsize_y;\r
1164         pos_y -= sbar_border_thickness;\r
1165 \r
1166         pos += '1 1 0';\r
1167 \r
1168         if (sbar_scoreboard_highlight)\r
1169         {\r
1170                 column_dim_y = 1.25 * sbar_fontsize_y; // header\r
1171                 column_dim_y += sbar_border_thickness;\r
1172                 column_dim_y += body_table_height;\r
1173         }\r
1174 \r
1175         // print the strings of the columns headers and draw the columns\r
1176         for(i = 0; i < sbar_num_fields; ++i)\r
1177         {\r
1178                 if(sbar_field[i] == SP_SEPARATOR)\r
1179                         break;\r
1180                 column_dim_x = sbar_size[i] + sbar_fontsize_x;\r
1181                 if (sbar_scoreboard_highlight)\r
1182                 {\r
1183                         if (mod(i,2))\r
1184                                 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
1185                 }\r
1186                 drawstring(pos, sbar_title[i], sbar_fontsize, rgb * 1.5, sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1187                 pos_x += column_dim_x;\r
1188         }\r
1189         if(sbar_field[i] == SP_SEPARATOR)\r
1190         {\r
1191                 pos_x = xmax;\r
1192                 tmp_y = 0;\r
1193                 for(i = sbar_num_fields-1; i > 0; --i)\r
1194                 {\r
1195                         if(sbar_field[i] == SP_SEPARATOR)\r
1196                                 break;\r
1197 \r
1198                         pos_x -= sbar_size[i];\r
1199 \r
1200                         if (sbar_scoreboard_highlight)\r
1201                         {\r
1202                                 if (!mod(i,2))\r
1203                                 {\r
1204                                         if (i == sbar_num_fields-1)\r
1205                                                 column_dim_x = sbar_size[i] + sbar_fontsize_x / 2 + 1;\r
1206                                         else\r
1207                                                 column_dim_x = sbar_size[i] + sbar_fontsize_x;\r
1208                                         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
1209                                 }\r
1210                         }\r
1211 \r
1212                         tmp_x = stringwidth(sbar_title[i], FALSE, sbar_fontsize);\r
1213                         tmp_x = sbar_size[i] - tmp_x;\r
1214                         drawstring(pos + tmp, sbar_title[i], sbar_fontsize, rgb * 1.5, sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1215                         pos_x -= sbar_fontsize_x;\r
1216                 }\r
1217         }\r
1218         \r
1219         pos_x = xmin;\r
1220         pos_y += 1.25 * sbar_fontsize_y; // skip the header\r
1221         pos_y += sbar_border_thickness;\r
1222 \r
1223         // fill the table and draw the rows\r
1224         i = 0;\r
1225         if (teamplay)\r
1226                 for(pl = players.sort_next; pl; pl = pl.sort_next)\r
1227                 {\r
1228                         if(pl.team != tm.team)\r
1229                                 continue;\r
1230                         Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1), i);\r
1231                         pos_y += 1.25 * sbar_fontsize_y;\r
1232                         ++i;\r
1233                 }\r
1234         else\r
1235                 for(pl = players.sort_next; pl; pl = pl.sort_next)\r
1236                 {\r
1237                         if(pl.team == COLOR_SPECTATOR)\r
1238                                 continue;\r
1239                         Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1), i);\r
1240                         pos_y += 1.25 * sbar_fontsize_y;\r
1241                         ++i;\r
1242                 }\r
1243         \r
1244         if (i == 0)\r
1245                 pos_y += 1.25 * sbar_fontsize_y; // move to the end of the table\r
1246         pos_y += 1.25 * sbar_fontsize_y; // move empty row (out of the table)\r
1247 \r
1248         return pos;\r
1249 }\r
1250 \r
1251 float Sbar_WouldDrawScoreboard() {\r
1252         if (sb_showscores)\r
1253                 return 1;\r
1254         else if (intermission == 1)\r
1255                 return 1;\r
1256         else if (intermission == 2)\r
1257                 return 1;\r
1258         else if (getstati(STAT_HEALTH) <= 0 && cvar("cl_deathscoreboard"))\r
1259                 return 1;\r
1260         else if(sb_showscores_force)\r
1261                 return 1;\r
1262         return 0;\r
1263 }\r
1264 \r
1265 float average_accuracy;\r
1266 vector Sbar_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size)\r
1267 {\r
1268         float i;\r
1269         float weapon_hit, weapon_damage, weapon_stats;\r
1270         float fontsize = 40 * 1/3;\r
1271         float xsave;\r
1272         float weapon_cnt;\r
1273         float rows;\r
1274         if(cvar("sbar_accuracy_doublerows"))\r
1275                 rows = 2;\r
1276         else\r
1277                 rows = 1;\r
1278         float height = 40;\r
1279 \r
1280         if(warmup_stage)\r
1281         {\r
1282                 return pos;\r
1283         }\r
1284 \r
1285         xsave = pos_x;\r
1286         drawstring(pos, strcat("Accuracy stats (average ", ftos(average_accuracy), "%)"), sbar_fontsize, '1 1 1', sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1287         pos_y += 18;\r
1288         vector tmp;\r
1289         tmp_x = sbwidth;\r
1290         tmp_y = height * rows;\r
1291 \r
1292         drawpic_tiled(pos, Sbar_GetTexture("sb_scoreboard_bg"), bg_size, tmp, rgb * sbar_color_bg_team, sbar_scoreboard_alpha_bg, DRAWFLAG_NORMAL);\r
1293         drawborderlines(sbar_accuracy_border_thickness, pos, tmp, '0 0 0', sbar_scoreboard_alpha_bg * 0.75, DRAWFLAG_NORMAL);\r
1294 \r
1295         // column highlighting\r
1296         for(i = 0; i < weapon_cnt/rows; ++i)\r
1297         {\r
1298                 if(!mod(i, 2))\r
1299                         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
1300         }\r
1301 \r
1302         // row highlighting\r
1303         for(i = 0; i < rows; ++i)\r
1304         {\r
1305                 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
1306         }\r
1307 \r
1308         // skip useless weapons\r
1309         weapon_cnt = 0;\r
1310         for(i = WEP_FIRST; i <= WEP_LAST; ++i)\r
1311         {\r
1312                 self = get_weaponinfo(i);\r
1313                 if not(self.weapons)\r
1314                         continue;\r
1315                 ++weapon_cnt;\r
1316         }\r
1317 \r
1318         drawfont = sbar_bigfont;\r
1319         average_accuracy = 0;\r
1320         float weapons_with_stats;\r
1321         weapons_with_stats = 0;\r
1322         if(rows == 2)\r
1323                 pos_x += sbwidth/weapon_cnt / 2;\r
1324 \r
1325         for(i = WEP_FIRST; i <= WEP_LAST; ++i)\r
1326         {\r
1327                 self = get_weaponinfo(i);\r
1328                 if not(self.weapons)\r
1329                         continue;\r
1330                 weapon_hit = weapon_hits[i-WEP_FIRST];\r
1331                 weapon_damage = weapon_fired[i-WEP_FIRST];\r
1332                 if(weapon_damage)\r
1333                         weapon_stats = bound(0, floor(100 * weapon_hit / weapon_damage), 100);\r
1334                 float weapon_alpha;\r
1335 \r
1336                 if(weapon_damage)\r
1337                         weapon_alpha = sbar_scoreboard_alpha_fg;\r
1338                 else\r
1339                         weapon_alpha = 0.2 * sbar_scoreboard_alpha_fg;\r
1340 \r
1341                 // weapon icon\r
1342                 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
1343                 // the accuracy\r
1344                 if(weapon_damage) {\r
1345                         weapons_with_stats += 1;\r
1346                         average_accuracy += weapon_stats; // store sum of all accuracies in average_accuracy\r
1347 \r
1348                         string s;\r
1349                         s = strcat(ftos(weapon_stats),"%");\r
1350 \r
1351                         float padding;\r
1352                         padding = ((sbwidth/weapon_cnt) - stringwidth(s, FALSE, '1 0 0' * fontsize)) / 2; // center the accuracy value\r
1353 \r
1354                         rgb = Sbar_AccuracyColor(weapon_stats);\r
1355                         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
1356                 }\r
1357                 pos_x += sbwidth/weapon_cnt * rows;\r
1358                 if(rows == 2 && i == 6) {\r
1359                         pos_x -= sbwidth;\r
1360                         pos_y += height;\r
1361                 }\r
1362         }\r
1363         drawfont = sbar_font;\r
1364 \r
1365         if(weapons_with_stats)\r
1366                 average_accuracy = floor(average_accuracy / weapons_with_stats);\r
1367 \r
1368         pos_x = xsave;\r
1369         pos_y += height;\r
1370         return pos;\r
1371 }\r
1372 \r
1373 string race_PlaceName(float pos) {\r
1374         if(pos == 1)\r
1375                 return "1st";\r
1376         else if(pos == 2)\r
1377                 return "2nd";\r
1378         else if(pos == 3)\r
1379                 return "3rd";\r
1380         else\r
1381                 return strcat(ftos(pos), "th");\r
1382 }\r
1383 \r
1384 vector Sbar_DrawScoreboardRankings(vector pos, entity pl,  vector rgb, vector bg_size)\r
1385 {\r
1386         float i;\r
1387         RANKINGS_RECEIVED_CNT = 0;\r
1388                 for (i=RANKINGS_CNT-1; i>=0; --i)\r
1389                         if (grecordtime[i])\r
1390                                 RANKINGS_RECEIVED_CNT = RANKINGS_RECEIVED_CNT + 1;\r
1391 \r
1392         if (RANKINGS_RECEIVED_CNT == 0)\r
1393                 return pos;\r
1394 \r
1395         float is_spec;\r
1396         is_spec = (GetPlayerColor(pl.sv_entnum) == COLOR_SPECTATOR);\r
1397         vector hl_rgb;\r
1398                 hl_rgb = stov(cvar_string("sbar_color_bg")) + '0.5 0.5 0.5';\r
1399 \r
1400         pos_y += sbar_fontsize_y;\r
1401         drawstring(pos, strcat("Rankings"), sbar_fontsize, '1 1 1', sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1402         pos_y += sbar_fontsize_y;\r
1403         vector tmp;\r
1404         tmp_x = sbwidth;\r
1405         tmp_y = sbar_fontsize_y * RANKINGS_RECEIVED_CNT;\r
1406 \r
1407         drawpic_tiled(pos, Sbar_GetTexture("sb_scoreboard_bg"), bg_size, tmp, rgb * sbar_color_bg_team, sbar_scoreboard_alpha_bg, DRAWFLAG_NORMAL);\r
1408         drawborderlines(sbar_border_thickness, pos, tmp, '0 0 0', sbar_scoreboard_alpha_bg * 0.75, DRAWFLAG_NORMAL);\r
1409 \r
1410         // row highlighting\r
1411         for(i = 0; i<RANKINGS_RECEIVED_CNT; ++i)\r
1412         {\r
1413                 string n, p;\r
1414                 float t;\r
1415                 t = grecordtime[i];\r
1416                 if (t == 0)\r
1417                         continue;\r
1418                 n = grecordholder[i];\r
1419                 p = race_PlaceName(i+1);\r
1420                 if(grecordholder[i] == GetPlayerName(player_localentnum - 1))\r
1421                         drawfill(pos, '1 0 0' * sbwidth + '0 1 0' * sbar_fontsize_y, hl_rgb, sbar_scoreboard_highlight_alpha_self, DRAWFLAG_NORMAL);    \r
1422                 else if(!mod(i, 2) && sbar_scoreboard_highlight)\r
1423                         drawfill(pos, '1 0 0' * sbwidth + '0 1 0' * sbar_fontsize_y, hl_rgb, sbar_scoreboard_highlight_alpha, DRAWFLAG_NORMAL); \r
1424                 drawstring(pos, p, sbar_fontsize, '1 1 1', sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1425                 drawstring(pos + '3 0 0' * sbar_fontsize_x, TIME_ENCODED_TOSTRING(t), sbar_fontsize, '1 1 1', sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1426                 drawcolorcodedstring(pos + '8 0 0' * sbar_fontsize_x, n, sbar_fontsize, sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1427                 pos += '0 1 0' * sbar_fontsize_y;\r
1428         }\r
1429 \r
1430         return pos;\r
1431 }\r
1432 \r
1433 float scoreboard_bottom;\r
1434 float sbar_scoreboard_fade_alpha;\r
1435 float sbar_woulddrawscoreboard_prev;\r
1436 float sbar_woulddrawscoreboard_change; // "time" at which Sbar_WouldDrawScoreboard() changed\r
1437 void Sbar_DrawScoreboard()\r
1438 {\r
1439         float sbar_woulddrawscoreboard; \r
1440         sbar_woulddrawscoreboard = Sbar_WouldDrawScoreboard();\r
1441         if(sbar_woulddrawscoreboard != sbar_woulddrawscoreboard_prev) {\r
1442                 sbar_woulddrawscoreboard_change = time;\r
1443                 sbar_woulddrawscoreboard_prev = sbar_woulddrawscoreboard;\r
1444         }\r
1445 \r
1446         float scoreboard_fadeinspeed = cvar_or("sbar_scoreboard_fadeinspeed", 10);\r
1447         float scoreboard_fadeoutspeed = cvar_or("sbar_scoreboard_fadeoutspeed", 5);\r
1448         if(sbar_woulddrawscoreboard) {\r
1449                 if (scoreboard_fadeinspeed)\r
1450                         sbar_scoreboard_fade_alpha = bound (0, (time - sbar_woulddrawscoreboard_change) * scoreboard_fadeinspeed, 1);\r
1451                 else\r
1452                         sbar_scoreboard_fade_alpha = 1;\r
1453         }\r
1454         else\r
1455                 if (scoreboard_fadeoutspeed)\r
1456                         sbar_scoreboard_fade_alpha = bound (0, (1/scoreboard_fadeoutspeed - (time - sbar_woulddrawscoreboard_change)) * scoreboard_fadeoutspeed, 1);\r
1457                 else\r
1458                         sbar_scoreboard_fade_alpha = 0;\r
1459 \r
1460         if not(sbar_scoreboard_fade_alpha)\r
1461                 return;\r
1462                 \r
1463         sbar_scoreboard_alpha_bg = cvar("sbar_scoreboard_alpha_bg") * sbar_scoreboard_fade_alpha;\r
1464         sbar_scoreboard_alpha_fg = cvar_or("sbar_scoreboard_alpha_fg", 1.0) * sbar_scoreboard_fade_alpha;\r
1465         sbar_scoreboard_highlight = cvar("sbar_scoreboard_highlight");\r
1466         sbar_scoreboard_highlight_alpha = cvar_or("sbar_scoreboard_highlight_alpha", 0.10) * sbar_scoreboard_alpha_fg;\r
1467         sbar_scoreboard_highlight_alpha_self = cvar_or("sbar_scoreboard_highlight_alpha_self", 0.25) * sbar_scoreboard_alpha_fg;\r
1468         sbar_scoreboard_alpha_name = cvar_or("sbar_scoreboard_alpha_name", 0.9) * sbar_scoreboard_alpha_fg;\r
1469         sbar_scoreboard_alpha_name_self = cvar_or("sbar_scoreboard_alpha_name_self", 1) * sbar_scoreboard_alpha_fg;\r
1470         \r
1471         vector rgb, pos, tmp;\r
1472         entity pl, tm;\r
1473 \r
1474         sbwidth = Sbar_GetWidth(6.5 * sbar_fontsize_y);\r
1475 \r
1476         xmin = 0.5 * (vid_conwidth - sbwidth);\r
1477         ymin = cvar("sbar_scoreboard_offset");\r
1478 \r
1479         xmax = vid_conwidth - xmin;\r
1480         ymax = vid_conheight - 0.2*vid_conheight;\r
1481 \r
1482         // Initializes position\r
1483         pos_x = xmin;\r
1484         pos_y = ymin;\r
1485         pos_z = 0;\r
1486 \r
1487         // Heading\r
1488         drawfont = sbar_bigfont;\r
1489         if(gametype == GAME_RPG)\r
1490                 drawstringcenter('0 1 0' * ymin, "Players", '24 24 0', '1 1 1', sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1491         else\r
1492                 drawstringcenter('0 1 0' * ymin, "Scoreboard", '24 24 0', '1 1 1', sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1493 \r
1494         pos_y += 24 + 4;\r
1495         pos_y += sbar_fontsize_y;\r
1496 \r
1497         drawfont = sbar_font;\r
1498 \r
1499         // Draw the scoreboard\r
1500         vector bg_size;\r
1501         bg_size = drawgetimagesize(Sbar_GetTexture("sb_scoreboard_bg"));\r
1502 \r
1503         if(teamplay)\r
1504         {\r
1505                 for(tm = teams.sort_next; tm; tm = tm.sort_next)\r
1506                 {\r
1507                         if(tm.team == COLOR_SPECTATOR)\r
1508                                 continue;\r
1509 \r
1510                         rgb = GetTeamRGB(tm.team);\r
1511                         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
1512                                 \r
1513                         if(ts_primary != ts_secondary)\r
1514                                 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
1515 \r
1516                         pos = Sbar_Scoreboard_MakeTable(pos, tm, rgb, bg_size);\r
1517                 }\r
1518         }\r
1519         else\r
1520         {\r
1521                 rgb = stov(cvar_string("sbar_color_bg"));\r
1522 \r
1523                 for(tm = teams.sort_next; tm; tm = tm.sort_next)\r
1524                 {\r
1525                         if(tm.team == COLOR_SPECTATOR)\r
1526                                 continue;\r
1527 \r
1528                         pos = Sbar_Scoreboard_MakeTable(pos, tm, rgb, bg_size);\r
1529                 }\r
1530         }\r
1531 \r
1532         if(gametype == GAME_CTS || gametype == GAME_RACE) {\r
1533                 if(race_speedaward) {\r
1534                         drawcolorcodedstring(pos, strcat("Speed award: ", ftos(race_speedaward), " (", race_speedaward_holder, ")"), sbar_fontsize, sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1535                         pos_y += 1.25 * sbar_fontsize_y;\r
1536                 }\r
1537                 if(race_speedaward_alltimebest) {\r
1538                         drawcolorcodedstring(pos, strcat("All-time fastest: ", ftos(race_speedaward_alltimebest), " (", race_speedaward_alltimebest_holder, ")"), sbar_fontsize, sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1539                         pos_y += 1.25 * sbar_fontsize_y;\r
1540                 }\r
1541                 pos = Sbar_DrawScoreboardRankings(pos, pl, rgb, bg_size);\r
1542         }\r
1543         else if(cvar("sbar_accuracy") && spectatee_status != -1) {\r
1544                 if(teamplay)\r
1545                         pos = Sbar_DrawScoreboardAccuracyStats(pos, GetTeamRGB(myteam), bg_size);\r
1546                 else\r
1547                         pos = Sbar_DrawScoreboardAccuracyStats(pos, rgb, bg_size);\r
1548         }\r
1549 \r
1550         tmp = pos + '0 1.5 0' * sbar_fontsize_y;\r
1551         pos_y += 3 * sbar_fontsize_y;\r
1552 \r
1553         // List spectators\r
1554         float specs;\r
1555         specs = 0;\r
1556         for(pl = players.sort_next; pl; pl = pl.sort_next)\r
1557         {\r
1558                 if(pl.team != COLOR_SPECTATOR)\r
1559                         continue;\r
1560                 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1), specs);\r
1561                 pos_y += 1.25 * sbar_fontsize_y;\r
1562                 ++specs;\r
1563         }\r
1564 \r
1565         if(specs)\r
1566                 drawstring(tmp, "Spectators", sbar_fontsize, '1 1 1', sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1567 \r
1568         // Print info string\r
1569         string str;\r
1570         float tl, fl, ll;\r
1571         if(gametype == GAME_RPG)\r
1572                 str = strcat("you are in ^2", shortmapname, "^7");\r
1573         else\r
1574                 str = strcat("playing on ^2", shortmapname, "^7");\r
1575         tl = getstatf(STAT_TIMELIMIT);\r
1576         fl = getstatf(STAT_FRAGLIMIT);\r
1577         ll = getstatf(STAT_LEADLIMIT);\r
1578         if(gametype == GAME_LMS)\r
1579         {\r
1580                 if(tl > 0)\r
1581                         str = strcat(str, " for up to ^1", ftos(tl), " minutes^7");\r
1582         }\r
1583         else\r
1584         {\r
1585                 if(tl > 0)\r
1586                         str = strcat(str, " for ^1", ftos(tl), " minutes^7");\r
1587                 if(fl > 0 && !(gametype == GAME_RPG))\r
1588                 {\r
1589                         if(tl > 0)\r
1590                                 str = strcat(str, " or");\r
1591                         if(teamplay)\r
1592                         {\r
1593                                 str = strcat(str, " until ^3", ScoreString(teamscores_flags[ts_primary], fl));\r
1594                                 if(teamscores_label[ts_primary] == "score")\r
1595                                         str = strcat(str, " points^7");\r
1596                                 else if(teamscores_label[ts_primary] == "fastest")\r
1597                                         str = strcat(str, " is beaten^7");\r
1598                                 else\r
1599                                         str = strcat(str, " ", teamscores_label[ts_primary]);\r
1600                         }\r
1601                         else\r
1602                         {\r
1603                                 str = strcat(str, " until ^3", ScoreString(scores_flags[ps_primary], fl));\r
1604                                 if(scores_label[ps_primary] == "score")\r
1605                                         str = strcat(str, " points^7");\r
1606                                 else if(scores_label[ps_primary] == "fastest")\r
1607                                         str = strcat(str, " is beaten^7");\r
1608                                 else\r
1609                                         str = strcat(str, " ", scores_label[ps_primary]);\r
1610                         }\r
1611                 }\r
1612                 if(ll > 0)\r
1613                 {\r
1614                         if(tl > 0 || fl > 0)\r
1615                                 str = strcat(str, " or");\r
1616                         if(teamplay)\r
1617                         {\r
1618                                 str = strcat(str, " until a lead of ^3", ScoreString(teamscores_flags[ts_primary], ll));\r
1619                                 if(teamscores_label[ts_primary] == "score")\r
1620                                         str = strcat(str, " points^7");\r
1621                                 else if(teamscores_label[ts_primary] == "fastest")\r
1622                                         str = strcat(str, " is beaten^7");\r
1623                                 else\r
1624                                         str = strcat(str, " ", teamscores_label[ts_primary]);\r
1625                         }\r
1626                         else\r
1627                         {\r
1628                                 str = strcat(str, " until a lead of ^3", ScoreString(scores_flags[ps_primary], ll));\r
1629                                 if(scores_label[ps_primary] == "score")\r
1630                                         str = strcat(str, " points^7");\r
1631                                 else if(scores_label[ps_primary] == "fastest")\r
1632                                         str = strcat(str, " is beaten^7");\r
1633                                 else\r
1634                                         str = strcat(str, " ", scores_label[ps_primary]);\r
1635                         }\r
1636                 }\r
1637         }\r
1638 \r
1639 \r
1640         pos_y += 1.2 * sbar_fontsize_y;\r
1641         drawcolorcodedstring(pos + '0.5 0 0' * (sbwidth - stringwidth(str, TRUE, sbar_fontsize)), str, sbar_fontsize, sbar_scoreboard_alpha_fg, DRAWFLAG_NORMAL);\r
1642 \r
1643         // print information about respawn status\r
1644         float respawn_time = getstatf(STAT_RESPAWN_TIME);\r
1645         if(respawn_time)\r
1646         {\r
1647                 if(respawn_time < 0)\r
1648                 {\r
1649                         // a negative number means we are awaiting respawn, time value is still the same\r
1650                         respawn_time *= -1; // remove mark now that we checked it\r
1651                         if(getstati(STAT_VORE_EATEN))\r
1652                                 str = strcat("^1Will respawn after leaving the stomach");\r
1653                         else 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 = Sbar_GetTexture(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
3007         if(spectatee_status && !intermission)\r
3008         {\r
3009                 drawfont = sbar_bigfont;\r
3010                 if(spectatee_status == -1)\r
3011                         s = "^1Observing";\r
3012                 else\r
3013                         s = GetPlayerName(spectatee_status - 1);\r
3014                 // spectated player name between HUD and chat area, aligned to the left\r
3015                 pos_x = bottomleft_x;\r
3016                 pos_y = bottom_y - 200 - sbar_fontsize_spec_y;\r
3017                 s = textShortenToWidth(s, vid_conwidth/2.5, sbar_fontsize_spec, stringwidth_colors);\r
3018                 drawcolorcodedstring(pos, s, sbar_fontsize_spec, sbar_alpha_fg, DRAWFLAG_NORMAL);\r
3019                 drawfont = sbar_font;\r
3020 \r
3021                 // spectator text in the upper right corner\r
3022                 if(spectatee_status == -1)\r
3023                         s = strcat("^1Press ^3", getcommandkey("primary fire", "+attack"), "^1 to spectate");\r
3024                 else\r
3025                         s = strcat("^1Press ^3", getcommandkey("primary fire", "+attack"), "^1 for another player");\r
3026                 o = Sbar_DrawNoteLine(o, s);\r
3027 \r
3028                 if(spectatee_status == -1)\r
3029                         s = strcat("^1Use ^3", getcommandkey("next weapon", "weapnext"), "^1 or ^3", getcommandkey("previous weapon", "weapprev"), "^1 to change the speed");\r
3030                 else\r
3031                         s = strcat("^1Press ^3", getcommandkey("secondary fire", "+attack2"), "^1 to observe");\r
3032                 o = Sbar_DrawNoteLine(o, s);\r
3033 \r
3034                 s = strcat("^1Press ^3", getcommandkey("server info", "+show_info"), "^1 for gamemode info");\r
3035                 o = Sbar_DrawNoteLine(o, s);\r
3036 \r
3037                 if(gametype == GAME_ARENA)\r
3038                         s = "^1Wait for your turn to join";\r
3039                 else if(gametype == GAME_LMS)\r
3040                 {\r
3041                         entity sk;\r
3042                         sk = playerslots[player_localentnum - 1];\r
3043                         if(sk.(scores[ps_primary]) >= 666)\r
3044                                 s = "^1Match has already begun";\r
3045                         else if(sk.(scores[ps_primary]) > 0)\r
3046                                 s = "^1You have no more lives left";\r
3047                         else\r
3048                                 s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");\r
3049                 }\r
3050                 else\r
3051                         s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");\r
3052                 o = Sbar_DrawNoteLine(o, s);\r
3053 \r
3054                 //show restart countdown:\r
3055                 if (time < getstatf(STAT_GAMESTARTTIME)) {\r
3056                         float countdown;\r
3057                         //we need to ceil, otherwise the countdown would be off by .5 when using round()\r
3058                         countdown = ceil(getstatf(STAT_GAMESTARTTIME) - time);\r
3059                         s = strcat("^1Game starts in ^3", ftos(countdown), "^1 seconds");\r
3060                         o = Sbar_DrawNoteLine(o, s);\r
3061                 }\r
3062         }\r
3063         if(warmup_stage && !intermission)\r
3064         {\r
3065                 s = "^2Currently in ^1warmup^2 stage!";\r
3066                 o = Sbar_DrawNoteLine(o, s);\r
3067         }\r
3068 \r
3069         // move more important stuff more to the middle so its more visible\r
3070         o_y = vid_conheight * 0.66;\r
3071 \r
3072         string blinkcolor;\r
3073         if(mod(time, 1) >= 0.5)\r
3074                 blinkcolor = "^1";\r
3075         else\r
3076                 blinkcolor = "^3";\r
3077 \r
3078         if(ready_waiting && !intermission && !spectatee_status)\r
3079         {\r
3080                 if(ready_waiting_for_me)\r
3081                 {\r
3082                         if(warmup_stage)\r
3083                                 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " to end warmup");\r
3084                         else\r
3085                                 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " once you are ready");\r
3086                 }\r
3087                 else\r
3088                 {\r
3089                         if(warmup_stage)\r
3090                                 s = strcat("^2Waiting for others to ready up to end warmup...");\r
3091                         else\r
3092                                 s = strcat("^2Waiting for others to ready up...");\r
3093                 }\r
3094                 o = Sbar_DrawNoteLine(o, s);\r
3095         }\r
3096         else if(warmup_stage && !intermission && !spectatee_status)\r
3097         {\r
3098                 s = strcat("^2Press ^3", getcommandkey("ready", "ready"), "^2 to end warmup");\r
3099                 o = Sbar_DrawNoteLine(o, s);\r
3100         }\r
3101 \r
3102         if(teamplay && !intermission && !spectatee_status && gametype != GAME_CA && teamnagger)\r
3103         {\r
3104                 entity tm;\r
3105                 float ts_min, ts_max;\r
3106                 tm = teams.sort_next;\r
3107                 if (tm)\r
3108                 {\r
3109                         for(; tm.sort_next; tm = tm.sort_next)\r
3110                         {\r
3111                                 if(!tm.team_size || tm.team == COLOR_SPECTATOR)\r
3112                                         continue;\r
3113                                 if(!ts_min) ts_min = tm.team_size;\r
3114                                 else ts_min = min(ts_min, tm.team_size);\r
3115                                 if(!ts_max) ts_max = tm.team_size;\r
3116                                 else ts_max = max(ts_max, tm.team_size);\r
3117                         }\r
3118                         if ((ts_max - ts_min) > 1)\r
3119                         {\r
3120                                 s = strcat(blinkcolor, "Teamnumbers are unbalanced!");\r
3121                                 tm = GetTeam(myteam, false);\r
3122                                 if (tm)\r
3123                                 if (tm.team != COLOR_SPECTATOR)\r
3124                                 if (tm.team_size == ts_max)\r
3125                                         s = strcat(s, " Press ^3", getcommandkey("team menu", "menu_showteamselect"), blinkcolor, " to adjust");\r
3126 \r
3127                                 o = Sbar_DrawNoteLine(o, s);\r
3128                         }\r
3129                 }\r
3130         }\r
3131 \r
3132         if(vote_active != vote_prev) {\r
3133                 vote_change = time;\r
3134                 vote_prev = bound(0, vote_active, 1);\r
3135         }\r
3136 \r
3137         if(vote_active)\r
3138                 vote_alpha = bound(0, (time - vote_change) * 2, 1);\r
3139         else\r
3140                 vote_alpha = bound(0, 1 - (time - vote_change) * 2, 1);\r
3141 \r
3142         if(vote_alpha) {\r
3143                 float a;\r
3144                 a = vote_alpha * bound(cvar_or("sbar_vote_alreadyvoted_alpha", 0.75), 1 - vote_highlighted, 1);\r
3145 \r
3146                 if (teamplay)\r
3147                         color =  GetTeamRGB(myteam) * sbar_color_bg_team;\r
3148                 else\r
3149                         color = stov(cvar_string("sbar_color_bg"));\r
3150 \r
3151                 vector voteorigin = bottomright - '290 135 0';\r
3152                 vector votesize = '280 70 0';\r
3153                 drawpic(voteorigin, Sbar_GetTexture("voteprogress_back"), votesize, color, a * sbar_alpha_bg, DRAWFLAG_NORMAL);\r
3154 \r
3155                 s = "A vote has been called for: ";\r
3156                 drawstring(voteorigin + '0.5 0 0' * votesize_x + '0 0.1 0' * votesize_y - '1 0 0' * stringwidth(s, FALSE, '6 0 0'), s, '12 12 0', '1 1 1', a * sbar_alpha_fg, DRAWFLAG_NORMAL);\r
3157                 s = textShortenToWidth(vote_called_vote, votesize_x * 0.96, '10 0 0', stringwidth_colors);\r
3158                 drawcolorcodedstring(voteorigin + '0.52 0 0' * votesize_x + '0 0.3 0' * votesize_y - '1 0 0' * stringwidth(s, FALSE, '5 0 0'), s, '10 10 0', a * sbar_alpha_fg, DRAWFLAG_NORMAL);\r
3159 \r
3160                 // print the yes/no counts\r
3161                 s = strcat("Yes: ", ftos(vote_yescount));\r
3162                 drawstring(voteorigin + '0 0.6 0' * votesize_y + '0.02 0 0' * votesize_x, s, '12 12 0', '0 1 0', a * sbar_alpha_fg, DRAWFLAG_NORMAL);\r
3163                 s = strcat("No: ", ftos(vote_nocount));\r
3164                 drawstring(voteorigin + '0 0.6 0' * votesize_y + '0.98 0 0' * votesize_x - '1 0 0' * stringwidth(s, FALSE, '12 0 0'), s, '12 12 0', '1 0 0', a * sbar_alpha_fg, DRAWFLAG_NORMAL);\r
3165 \r
3166                 // draw the progress bars\r
3167                 drawsetcliparea(voteorigin_x, voteorigin_y, votesize_x * 0.5 * (vote_yescount/vote_needed), votesize_y);\r
3168                 drawpic(voteorigin, Sbar_GetTexture("voteprogress_prog"), votesize, '0 1 0', a * sbar_alpha_fg, DRAWFLAG_NORMAL);\r
3169 \r
3170                 drawsetcliparea(voteorigin_x + votesize_x - votesize_x * 0.5 * (vote_nocount/vote_needed), voteorigin_y, votesize_x * 0.5, votesize_y);\r
3171                 drawpic(voteorigin, Sbar_GetTexture("voteprogress_prog"), votesize, '1 0 0', a * sbar_alpha_fg, DRAWFLAG_NORMAL);\r
3172 \r
3173                 // draw the highlights\r
3174                 if(vote_highlighted == 1) {\r
3175                         drawsetcliparea(voteorigin_x, voteorigin_y, votesize_x * 0.5, votesize_y);\r
3176                         drawpic(voteorigin, Sbar_GetTexture("voteprogress_voted"), votesize, '0 1 0', a * sbar_alpha_fg, DRAWFLAG_NORMAL);\r
3177                 }\r
3178                 else if(vote_highlighted == 2) {\r
3179                         drawsetcliparea(voteorigin_x + 0.5 * votesize_x, voteorigin_y, votesize_x * 0.5, votesize_y);\r
3180                         drawpic(voteorigin, Sbar_GetTexture("voteprogress_voted"), votesize, '1 0 0', a * sbar_alpha_fg, DRAWFLAG_NORMAL);\r
3181                 }\r
3182 \r
3183                 drawresetcliparea();\r
3184         }\r
3185         else if(!vote_active) {\r
3186                 vote_highlighted = 0;\r
3187         }\r
3188 \r
3189         Sbar_UpdatePlayerTeams();\r
3190         if (intermission == 2) // map voting screen\r
3191         {\r
3192                 Sbar_Timer();\r
3193                 if(sb_showscores)\r
3194                         Sbar_DrawScoreboard();\r
3195                 else\r
3196                         Sbar_FinaleOverlay();\r
3197 \r
3198                 Sbar_Reset();\r
3199         }\r
3200         else if (sb_showscores_force || getstati(STAT_HEALTH) <= 0 || intermission == 1)\r
3201         {\r
3202                 Sbar_DrawScoreboard();\r
3203                 Sbar_Score();\r
3204                 Sbar_Timer();\r
3205                 Sbar_Portrait();\r
3206                 if(getstati(STAT_VORE_EATEN))\r
3207                         Sbar_Status();\r
3208 \r
3209                 Sbar_Reset();\r
3210 \r
3211                 Sbar_ColorFade('0 0 0');\r
3212         }\r
3213         else\r
3214         {\r
3215                 if(sb_showaccuracy && spectatee_status != -1)\r
3216                         Sbar_DrawAccuracyStats();\r
3217                 else\r
3218                         Sbar_DrawScoreboard();\r
3219 \r
3220                 fade = 3.2 - 2 * (time - weapontime);\r
3221                 fade = bound(0.7, fade, 1);\r
3222 \r
3223                 // when a player's armor is below the necessary level, subsystems will not work\r
3224                 if(getstati(STAT_HEALTH) > 0)\r
3225                 {\r
3226                         vector warn_pos;\r
3227                         warn_pos_x = vid_conwidth / 2;\r
3228                         warn_pos_y = vid_conheight - vid_conheight / 2.5;\r
3229                         if(getstati(STAT_ARMOR) < g_power)\r
3230                         {\r
3231                                 // subsystems are down\r
3232                                 drawpic(warn_pos - '128 0 0', Sbar_GetTexture("sb_power_fail"), '256 256 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
3233                                 drawpic(warn_pos - '16 0 0' + '0 150 0', Sbar_GetTexture("sb_power_fail_icon"), '32 32 0', '1 1 1', sbar_alpha_fg * (0.5 + sin(time * 5) / 2), DRAWFLAG_NORMAL);\r
3234                                 power_boot = time + g_power_reboot;\r
3235                                 Sbar_Portrait(); // draw the portrait still\r
3236                                 return; // skip drawing the HUD\r
3237                         }\r
3238                         else if(time <= power_boot)\r
3239                         {\r
3240                                 // subsystems are rebooting\r
3241                                 drawpic(warn_pos - '128 0 0', Sbar_GetTexture("sb_power_reboot"), '256 256 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
3242                                 drawpic(warn_pos - '16 0 0' + '0 150 0', Sbar_GetTexture("sb_power_reboot_icon"), '32 32 0', '1 1 1', sbar_alpha_fg * (0.5 + sin(time * 5) / 2), DRAWFLAG_NORMAL);\r
3243                                 Sbar_Portrait(); // draw the portrait still\r
3244                                 return; // skip drawing the HUD\r
3245                         }\r
3246                 }\r
3247 \r
3248                 Sbar_DrawBackgrounds();\r
3249 \r
3250                 if(g_vore) // only when the vore system is active\r
3251                 {\r
3252                         // draw the stomach board\r
3253 \r
3254                         float stomach_load, stomach_maxload; // shows the predator's stomach load when we are eaten, and ours otherwise\r
3255                         stomach_load = getstati(STAT_VORE_LOAD);\r
3256                         stomach_maxload = getstati(STAT_VORE_MAXLOAD);\r
3257 \r
3258                         vector status_pos;\r
3259                         string status_text, status_color;\r
3260                         float status_size;\r
3261                         status_color = rgb_to_hexcolor('0.5 0.5 0.5' + Sbar_NumColor(stomach_maxload) * 0.5); // twice brighter than health / armor colors\r
3262                         if(stomach_load)\r
3263                         {\r
3264                                 status_text = strcat(ftos(stomach_load), "^8/", status_color, ftos(stomach_maxload));\r
3265                                 status_pos = stov(cvar_string("hud_item_stomach_load_double_text_position"));\r
3266                                 status_size = cvar("hud_item_stomach_load_double_text_scale");\r
3267                         }\r
3268                         else\r
3269                         {\r
3270                                 status_text = strcat(status_color, ftos(stomach_maxload));\r
3271                                 status_pos = stov(cvar_string("hud_item_stomach_load_single_text_position"));\r
3272                                 status_size = cvar("hud_item_stomach_load_single_text_scale");\r
3273                         }\r
3274                         Sbar_DrawString(status_text, status_pos, status_size);\r
3275 \r
3276                         if(getstati(STAT_VORE_DIGESTING)) // we are currently digesting\r
3277                                 Sbar_DrawPic(Sbar_GetTexture("sb_digestion_active"), stov(cvar_string("hud_item_digestion_icon_position")), stov(cvar_string("hud_item_digestion_icon_scale")), FALSE);\r
3278                         else if(stomach_load) // we can digest at this time\r
3279                                 Sbar_DrawPic(Sbar_GetTexture("sb_digestion_possible"), stov(cvar_string("hud_item_digestion_icon_position")), stov(cvar_string("hud_item_digestion_icon_scale")), FALSE);\r
3280                         else // we cannot digest at this time\r
3281                                 Sbar_DrawPic(Sbar_GetTexture("sb_digestion_impossible"), stov(cvar_string("hud_item_digestion_icon_position")), stov(cvar_string("hud_item_digestion_icon_scale")), FALSE);\r
3282 \r
3283                         // draw the stomach board player list\r
3284                         entity pl, pred;\r
3285                         float f, l;\r
3286 \r
3287                         hud_total_prey = 0;\r
3288                         pos = stov(cvar_string("hud_item_preylist_position"));\r
3289                         vector sz = stov(cvar_string("hud_item_preylist_scale"));\r
3290                         vector dir = stov(cvar_string("hud_item_preylist_entry_spacing")) * 2;\r
3291                         for(pl = players.sort_next; pl; pl = pl.sort_next)\r
3292                         {\r
3293                                 if(pl.team == COLOR_SPECTATOR)\r
3294                                         continue;\r
3295 \r
3296                                 if(getstati(STAT_VORE_EATEN))\r
3297                                         f = pl.plpredator == getstati(STAT_VORE_EATEN);\r
3298                                 else\r
3299                                 {\r
3300                                         if(spectatee_status)\r
3301                                                 f = pl.plpredator == spectatee_status;\r
3302                                         else\r
3303                                                 f = pl.plpredator == player_localentnum;\r
3304                                 }\r
3305 \r
3306                                 if(f)\r
3307                                 {\r
3308                                         if(l < cvar("hud_item_preylist_entry_number")) // limit the stomach board to the given number of entries\r
3309                                         {\r
3310                                                 Sbar_PrintStomachboardItem(pl, pos, sz);\r
3311 \r
3312                                                 // advance position for each entry\r
3313                                                 pos_x += sz_x * dir_x;\r
3314                                                 pos_y += sz_y * dir_y;\r
3315                                                 l += 1;\r
3316                                         }\r
3317                                         ++hud_total_prey;\r
3318                                 }\r
3319 \r
3320                                 // set the predator's name\r
3321                                 if(getstati(STAT_VORE_EATEN))\r
3322                                 {\r
3323                                         if(pl.sv_entnum == getstati(STAT_VORE_EATEN) - 1)\r
3324                                                 pred = pl;\r
3325                                 }\r
3326                                 else if(pl.sv_entnum == player_localentnum - 1 || pl.sv_entnum == spectatee_status - 1)\r
3327                                         pred = pl; // show us or the spectated player\r
3328                         }\r
3329 \r
3330                         // draw the predator's name\r
3331                         Sbar_PrintStomachboardItemPred(pred, stov(cvar_string("hud_item_predator_position")), stov(cvar_string("hud_item_predator_scale")));\r
3332                 }\r
3333 \r
3334                 // draw status, scores, timer, ring and portrait\r
3335                 Sbar_Status();\r
3336                 Sbar_Score();\r
3337                 Sbar_Timer();\r
3338                 Sbar_Ring();\r
3339                 Sbar_Portrait();\r
3340 \r
3341                 // draw strength/invincibility icon and timer\r
3342                 CSQC_Strength_Timer();\r
3343 \r
3344                 // draw gametype specific icons\r
3345                 if(gametype == GAME_KEYHUNT)\r
3346                         CSQC_kh_hud();\r
3347                 else if(gametype == GAME_CTF)\r
3348                         CSQC_ctf_hud();\r
3349                 else if(gametype == GAME_CTS || gametype == GAME_RACE)\r
3350                         CSQC_race_hud();\r
3351 \r
3352                 // draw the canleave message\r
3353                 if(getstati(STAT_VORE_CANLEAVE))\r
3354                 if not(spectatee_status) // this message doesn't address spectated players\r
3355                 {\r
3356                         s = strcat("^7Press ^3", getcommandkey("jump", "+jump"), " ^7to exit");\r
3357                         pos_x = bottom_x - stringwidth(s, TRUE, '0 0 0') * 16 / 2;\r
3358                         pos_y = bottom_y - 120;\r
3359                         drawcolorcodedstring(pos, s, '16 16 0', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
3360                 }\r
3361         }\r
3362         return;\r
3363 }\r
3364 \r
3365 // CTF HUD\r
3366 float redflag_prevframe, blueflag_prevframe; // status during previous frame\r
3367 float redflag_prevstatus, blueflag_prevstatus; // last remembered status\r
3368 float redflag_statuschange_time, blueflag_statuschange_time; // time when the status changed\r
3369 \r
3370 void CSQC_ctf_hudreset(void)\r
3371 {\r
3372         redflag_prevstatus = blueflag_prevstatus = redflag_prevframe = blueflag_prevframe = redflag_statuschange_time = blueflag_statuschange_time = 0;\r
3373 }\r
3374 \r
3375 void CSQC_ctf_hud(void)\r
3376 {\r
3377         vector top, redflag_pos, blueflag_pos, sz;\r
3378         float f; // every function should have that\r
3379         top_x = vid_conwidth / 2;\r
3380         top_y = 0;\r
3381         top_z = 0;\r
3382 \r
3383         float redflag, blueflag; // current status\r
3384         float redflag_statuschange_elapsedtime, blueflag_statuschange_elapsedtime; // time since the status changed\r
3385         float stat_items;\r
3386 \r
3387         stat_items = getstati(STAT_ITEMS);\r
3388         redflag = (stat_items/IT_RED_FLAG_TAKEN) & 3;\r
3389         blueflag = (stat_items/IT_BLUE_FLAG_TAKEN) & 3;\r
3390 \r
3391         // when status CHANGES, set old status into prevstatus and current status into status\r
3392         if (redflag != redflag_prevframe)\r
3393         {\r
3394                 redflag_statuschange_time = time;\r
3395                 redflag_prevstatus = redflag_prevframe;\r
3396                 redflag_prevframe = redflag;\r
3397         }\r
3398 \r
3399         if (blueflag != blueflag_prevframe)\r
3400         {\r
3401                 blueflag_statuschange_time = time;\r
3402                 blueflag_prevstatus = blueflag_prevframe;\r
3403                 blueflag_prevframe = blueflag;\r
3404         }\r
3405         \r
3406         redflag_statuschange_elapsedtime = time - redflag_statuschange_time;\r
3407         blueflag_statuschange_elapsedtime = time - blueflag_statuschange_time;\r
3408 \r
3409         float BLINK_FACTOR = 0.15;\r
3410         float BLINK_BASE = 0.85;\r
3411         // note:\r
3412         //   RMS = sqrt(BLINK_BASE^2 + 0.5 * BLINK_FACTOR^2)\r
3413         // thus\r
3414         //   BLINK_BASE = sqrt(RMS^2 - 0.5 * BLINK_FACTOR^2)\r
3415         // ensure RMS == 1\r
3416         float BLINK_FREQ = 5; // circle frequency, = 2*pi*frequency in hertz\r
3417 \r
3418         string red_icon, red_icon_prevstatus;\r
3419         float red_alpha, red_alpha_prevstatus;\r
3420         red_alpha = red_alpha_prevstatus = 1;\r
3421         switch(redflag) {\r
3422                 case 1: red_icon = Sbar_GetTexture("sb_flag_red_taken"); break;\r
3423                 case 2: red_icon = Sbar_GetTexture("sb_flag_red_lost"); break;\r
3424                 case 3: red_icon = Sbar_GetTexture("sb_flag_red_carrying"); red_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;\r
3425                 default:\r
3426                         if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM2))\r
3427                                 red_icon = Sbar_GetTexture("sb_flag_red_shielded");\r
3428                         else\r
3429                                 red_icon = string_null;\r
3430                         break;\r
3431         }\r
3432         switch(redflag_prevstatus) {\r
3433                 case 1: red_icon_prevstatus = Sbar_GetTexture("sb_flag_red_taken"); break;\r
3434                 case 2: red_icon_prevstatus = Sbar_GetTexture("sb_flag_red_lost"); break;\r
3435                 case 3: red_icon_prevstatus = Sbar_GetTexture("sb_flag_red_carrying"); red_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;\r
3436                 default:\r
3437                         if(redflag == 3)\r
3438                                 red_icon_prevstatus = Sbar_GetTexture("sb_flag_red_carrying"); // make it more visible\r
3439                         else if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM2))\r
3440                                 red_icon_prevstatus = Sbar_GetTexture("sb_flag_red_shielded");\r
3441                         else\r
3442                                 red_icon_prevstatus = string_null;\r
3443                         break;\r
3444         }\r
3445 \r
3446         string blue_icon, blue_icon_prevstatus;\r
3447         float blue_alpha, blue_alpha_prevstatus;\r
3448         blue_alpha = blue_alpha_prevstatus = 1;\r
3449         switch(blueflag) {\r
3450                 case 1: blue_icon = Sbar_GetTexture("sb_flag_blue_taken"); break;\r
3451                 case 2: blue_icon = Sbar_GetTexture("sb_flag_blue_lost"); break;\r
3452                 case 3: blue_icon = Sbar_GetTexture("sb_flag_blue_carrying"); blue_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;\r
3453                 default:\r
3454                         if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM1))\r
3455                                 blue_icon = Sbar_GetTexture("sb_flag_blue_shielded");\r
3456                         else\r
3457                                 blue_icon = string_null;\r
3458                         break;\r
3459         }\r
3460         switch(blueflag_prevstatus) {\r
3461                 case 1: blue_icon_prevstatus = Sbar_GetTexture("sb_flag_blue_taken"); break;\r
3462                 case 2: blue_icon_prevstatus = Sbar_GetTexture("sb_flag_blue_lost"); break;\r
3463                 case 3: blue_icon_prevstatus = Sbar_GetTexture("sb_flag_blue_carrying"); blue_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;\r
3464                 default:\r
3465                         if(blueflag == 3)\r
3466                                 blue_icon_prevstatus = Sbar_GetTexture("sb_flag_blue_carrying"); // make it more visible\r
3467                         else if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM1))\r
3468                                 blue_icon_prevstatus = Sbar_GetTexture("sb_flag_blue_shielded");\r
3469                         else\r
3470                                 blue_icon_prevstatus = string_null;\r
3471                         break;\r
3472         }\r
3473 \r
3474         if (myteam == COLOR_TEAM1) { // always draw own flag on left\r
3475                 redflag_pos = top + '-52 50 0';\r
3476                 blueflag_pos = top + '0 40 0';\r
3477         } else {\r
3478                 blueflag_pos = top + '-52 50 0';\r
3479                 redflag_pos = top + '0 40 0';\r
3480         }\r
3481         \r
3482         sz = '52 52 0';\r
3483         \r
3484         f = bound(0, redflag_statuschange_elapsedtime*2, 1);\r
3485         if(red_icon_prevstatus && f < 1)\r
3486                 drawpic_expanding(redflag_pos, red_icon_prevstatus, sz, '1 1 1', sbar_alpha_fg * red_alpha_prevstatus, DRAWFLAG_NORMAL, f);\r
3487         if(red_icon)\r
3488                 drawpic(redflag_pos, red_icon, sz, '1 1 1', sbar_alpha_fg * red_alpha * f, DRAWFLAG_NORMAL);\r
3489 \r
3490         f = bound(0, blueflag_statuschange_elapsedtime*2, 1);\r
3491         if(blue_icon_prevstatus && f < 1)\r
3492                 drawpic_expanding(blueflag_pos, blue_icon_prevstatus, sz, '1 1 1', sbar_alpha_fg * blue_alpha_prevstatus, DRAWFLAG_NORMAL, f);\r
3493         if(blue_icon)\r
3494                 drawpic(blueflag_pos, blue_icon, sz, '1 1 1', sbar_alpha_fg * blue_alpha * f, DRAWFLAG_NORMAL);\r
3495 }\r
3496 \r
3497 // Keyhunt HUD\r
3498 float kh_runheretime;\r
3499 \r
3500 void CSQC_kh_hudreset(void)\r
3501 {\r
3502         kh_runheretime = 0;\r
3503 }\r
3504 \r
3505 void CSQC_kh_hud(void)\r
3506 {\r
3507         float kh_keys;\r
3508         float keyteam;\r
3509         float a, aa;\r
3510         vector p, pa, kh_size, kh_asize;\r
3511 \r
3512         vector top;\r
3513         top_x = vid_conwidth / 2;\r
3514         top_y = 0;\r
3515         top_z = 0;\r
3516 \r
3517         p = top + '-50 64 0';\r
3518 \r
3519         kh_keys = getstati(STAT_KH_KEYS);\r
3520 \r
3521         kh_size = '19 34 0';\r
3522         kh_asize = '19 10 0';\r
3523         pa = p + '0 -10 0';\r
3524 \r
3525         float i, key;\r
3526 \r
3527         float keycount;\r
3528         keycount = 0;\r
3529         for(i = 0; i < 4; ++i)\r
3530         {\r
3531                 key = floor(kh_keys / pow(32, i)) & 31;\r
3532                 keyteam = key - 1;\r
3533                 if(keyteam == 30 && keycount <= 4)\r
3534                         keycount += 4;\r
3535                 if(keyteam == myteam || keyteam == -1 || keyteam == 30)\r
3536                         keycount += 1;\r
3537         }\r
3538         // this yields 8 exactly if "RUN HERE" shows\r
3539 \r
3540         if(keycount == 8)\r
3541         {\r
3542                 if(!kh_runheretime)\r
3543                         kh_runheretime = time;\r
3544                 pa_y -= fabs(sin((time - kh_runheretime) * 3.5)) * 6; // make the arrows jump in case of RUN HERE\r
3545         }\r
3546         else\r
3547                 kh_runheretime = 0;\r
3548 \r
3549         for(i = 0; i < 4; ++i)\r
3550         {\r
3551                 key = floor(kh_keys / pow(32, i)) & 31;\r
3552                 keyteam = key - 1;\r
3553                 switch(keyteam)\r
3554                 {\r
3555                         case 30: // my key\r
3556                                 keyteam = myteam;\r
3557                                 a = 1;\r
3558                                 aa = 1;\r
3559                                 break;\r
3560                         case -1: // no key\r
3561                                 a = 0;\r
3562                                 aa = 0;\r
3563                                 break;\r
3564                         default: // owned or dropped\r
3565                                 a = 0.2;\r
3566                                 aa = 0.5;\r
3567                                 break;\r
3568                 }\r
3569                 a = a * sbar_alpha_fg;\r
3570                 aa = aa * sbar_alpha_fg;\r
3571                 if(a > 0)\r
3572                 {\r
3573                         switch(keyteam)\r
3574                         {\r
3575                                 case COLOR_TEAM1:\r
3576                                         drawpic (pa, Sbar_GetTexture("sb_kh_redarrow"), kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL);  // show 30% alpha key\r
3577                                         break;\r
3578                                 case COLOR_TEAM2:\r
3579                                         drawpic (pa, Sbar_GetTexture("sb_kh_bluearrow"), kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL);  // show 30% alpha key\r
3580                                         break;\r
3581                                 case COLOR_TEAM3:\r
3582                                         drawpic (pa, Sbar_GetTexture("sb_kh_yellowarrow"), kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL);  // show 30% alpha key\r
3583                                         break;\r
3584                                 case COLOR_TEAM4:\r
3585                                         drawpic (pa, Sbar_GetTexture("sb_kh_pinkarrow"), kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL);  // show 30% alpha key\r
3586                                         break;\r
3587                                 default:\r
3588                                         break;\r
3589                         }\r
3590                         switch(i) // YAY! switch(i) inside a for loop for i. DailyWTF, here we come!\r
3591                         {\r
3592                                 case 0:\r
3593                                         drawpic (p, Sbar_GetTexture("sb_kh_red"), kh_size, '1 1 1', a, DRAWFLAG_NORMAL);  // show 30% alpha key\r
3594                                         break;\r
3595                                 case 1:\r
3596                                         drawpic (p, Sbar_GetTexture("sb_kh_blue"), kh_size, '1 1 1', a, DRAWFLAG_NORMAL);  // show 30% alpha key\r
3597                                         break;\r
3598                                 case 2:\r
3599                                         drawpic (p, Sbar_GetTexture("sb_kh_yellow"), kh_size, '1 1 1', a, DRAWFLAG_NORMAL);  // show 30% alpha key\r
3600                                         break;\r
3601                                 case 3:\r
3602                                         drawpic (p, Sbar_GetTexture("sb_kh_pink"), kh_size, '1 1 1', a, DRAWFLAG_NORMAL);  // show 30% alpha key\r
3603                                         break;\r
3604                         }\r
3605                 }\r
3606                 p_x += 24;\r
3607                 pa_x += 24;\r
3608         }\r
3609 }\r
3610 \r
3611 float crecordtime_prev; // last remembered crecordtime\r
3612 float crecordtime_change_time; // time when crecordtime last changed\r
3613 float srecordtime_prev; // last remembered srecordtime\r
3614 float srecordtime_change_time; // time when srecordtime last changed\r
3615 void CSQC_race_hud(void) \r
3616 {\r
3617         entity me;\r
3618         me = playerslots[player_localentnum - 1];\r
3619         float t, score;\r
3620         float f; // yet another function has this\r
3621         score = me.(scores[ps_primary]);\r
3622 \r
3623         if not((scores_flags[ps_primary] & SFL_TIME) && !teamplay) // race/cts record display on HUD\r
3624                 return; // no records in the actual race\r
3625 \r
3626         drawfont = sbar_bigfont;\r
3627         vector pos;\r
3628         pos_x = 2;\r
3629         pos_y = vid_conheight - 272;\r
3630 \r
3631         // clientside personal record\r
3632         string rr;\r
3633         if(gametype == GAME_CTS)\r
3634                 rr = CTS_RECORD;\r
3635         else\r
3636                 rr = RACE_RECORD;\r
3637         t = stof(db_get(ClientProgsDB, strcat(shortmapname, rr, "time")));\r
3638 \r
3639         if(score && score < t || !t)\r
3640                 db_put(ClientProgsDB, strcat(shortmapname, rr, "time"), ftos(score));\r
3641 \r
3642         if(t != crecordtime_prev) {\r
3643                 crecordtime_prev = t;\r
3644                 crecordtime_change_time = time;\r
3645         }\r
3646         f = time - crecordtime_change_time;\r
3647 \r
3648         if (f > 1) {\r
3649                 drawstring(pos, "Personal best ", '10 10 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
3650                 drawstring(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
3651         } else {\r
3652                 drawstring(pos, "Personal best ", '10 10 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
3653                 drawstring(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
3654                 drawstring_expanding(pos, "Personal best ", '10 10 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL, f);\r
3655                 drawstring_expanding(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL, f);\r
3656         }\r
3657 \r
3658         // server record\r
3659         pos_y += 26;\r
3660         t = race_server_record;\r
3661         if(t != srecordtime_prev) {\r
3662                 srecordtime_prev = t;\r
3663                 srecordtime_change_time = time;\r
3664         }\r
3665         f = time - srecordtime_change_time;\r
3666 \r
3667         if (f > 1) {\r
3668                 drawstring(pos, "Server best ", '10 10 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
3669                 drawstring(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
3670         } else {\r
3671                 drawstring(pos, "Server best ", '10 10 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
3672                 drawstring(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
3673                 drawstring_expanding(pos, "Server best ", '10 10 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL, f);\r
3674                 drawstring_expanding(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL, f);\r
3675         }\r
3676         drawfont = sbar_font;\r
3677 }\r
3678 \r
3679 void Ent_ReadPortrait()\r
3680 {\r
3681         // receives portrait values, which are used in Sbar_Portrait\r
3682 \r
3683         string pl_model, pl_name, img;\r
3684         float pl_skin;\r
3685 \r
3686         pl_model = ReadString();\r
3687         pl_skin = ReadByte();\r
3688         pl_name = ReadString();\r
3689 \r
3690         // update existing portraits\r
3691         if(portrait_name)\r
3692                 strunzone(portrait_name);\r
3693         if(portrait_image)\r
3694                 strunzone(portrait_image);\r
3695 \r
3696         portrait_time = time;\r
3697         portrait_name = strzone(pl_name);\r
3698 \r
3699         // obtain the image name from the text file\r
3700         float glob, i, fh;\r
3701         string fn;\r
3702 \r
3703         glob = search_begin("models/player/*.txt", TRUE, TRUE);\r
3704         if(glob < 0)\r
3705                 return;\r
3706         for(i = 0; i < search_getsize(glob); ++i)\r
3707         {\r
3708                 fn = search_getfilename(glob, i);\r
3709                 fh = fopen(fn, FILE_READ);\r
3710                 if(fh < 0)\r
3711                         continue;\r
3712 \r
3713                 fgets(fh); // skip name\r
3714                 img = fgets(fh);\r
3715                 if(pl_skin == stof(fgets(fh)))\r
3716                 if(pl_model == fgets(fh))\r
3717                         portrait_image = strzone(img);\r
3718 \r
3719                 fclose(fh);\r
3720         }\r
3721         search_end(glob);\r
3722 }\r