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