]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud.qc
Remove some old junk
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud.qc
1 /*
2 ==================
3 Misc HUD functions
4 ==================
5 */
6
7 // a border picture is a texture containing nine parts:
8 //   1/4 width: left part
9 //   1/2 width: middle part (stretched)
10 //   1/4 width: right part
11 // divided into
12 //   1/4 height: top part
13 //   1/2 height: middle part (stretched)
14 //   1/4 height: bottom part
15 void draw_BorderPicture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha, vector theBorderSize)
16 {
17     if (theBorderSize_x < 0 && theBorderSize_y < 0) // draw whole image as it is
18     {
19                 drawpic(theOrigin, pic, theSize, theColor, theAlpha, 0);
20                 return;
21     }
22         if (theBorderSize_x == 0 && theBorderSize_y == 0) // no border
23         {
24                 // draw only the central part
25                 drawsubpic(theOrigin, theSize, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0);
26                 return;
27         }
28
29         vector dX, dY;
30         vector width, height;
31         vector bW, bH;
32         //pic = draw_UseSkinFor(pic);
33         width = eX * theSize_x;
34         height = eY * theSize_y;
35         if(theSize_x <= theBorderSize_x * 2)
36         {
37                 // not wide enough... draw just left and right then
38                 bW = eX * (0.25 * theSize_x / (theBorderSize_x * 2));
39                 if(theSize_y <= theBorderSize_y * 2)
40                 {
41                         // not high enough... draw just corners
42                         bH = eY * (0.25 * theSize_y / (theBorderSize_y * 2));
43                         drawsubpic(theOrigin,                 width * 0.5 + height * 0.5, pic, '0 0 0',           bW + bH, theColor, theAlpha, 0);
44                         drawsubpic(theOrigin + width   * 0.5, width * 0.5 + height * 0.5, pic, eX - bW,           bW + bH, theColor, theAlpha, 0);
45                         drawsubpic(theOrigin + height  * 0.5, width * 0.5 + height * 0.5, pic, eY - bH,           bW + bH, theColor, theAlpha, 0);
46                         drawsubpic(theOrigin + theSize * 0.5, width * 0.5 + height * 0.5, pic, eX + eY - bW - bH, bW + bH, theColor, theAlpha, 0);
47                 }
48                 else
49                 {
50                         dY = theBorderSize_x * eY;
51                         drawsubpic(theOrigin,                             width * 0.5          +     dY, pic, '0 0    0',           '0 0.25 0' + bW, theColor, theAlpha, 0);
52                         drawsubpic(theOrigin + width * 0.5,               width * 0.5          +     dY, pic, '0 0    0' + eX - bW, '0 0.25 0' + bW, theColor, theAlpha, 0);
53                         drawsubpic(theOrigin                        + dY, width * 0.5 + height - 2 * dY, pic, '0 0.25 0',           '0 0.5  0' + bW, theColor, theAlpha, 0);
54                         drawsubpic(theOrigin + width * 0.5          + dY, width * 0.5 + height - 2 * dY, pic, '0 0.25 0' + eX - bW, '0 0.5  0' + bW, theColor, theAlpha, 0);
55                         drawsubpic(theOrigin               + height - dY, width * 0.5          +     dY, pic, '0 0.75 0',           '0 0.25 0' + bW, theColor, theAlpha, 0);
56                         drawsubpic(theOrigin + width * 0.5 + height - dY, width * 0.5          +     dY, pic, '0 0.75 0' + eX - bW, '0 0.25 0' + bW, theColor, theAlpha, 0);
57                 }
58         }
59         else
60         {
61                 if(theSize_y <= theBorderSize_y * 2)
62                 {
63                         // not high enough... draw just top and bottom then
64                         bH = eY * (0.25 * theSize_y / (theBorderSize_y * 2));
65                         dX = theBorderSize_x * eX;
66                         drawsubpic(theOrigin,                                         dX + height * 0.5, pic, '0    0 0',           '0.25 0 0' + bH, theColor, theAlpha, 0);
67                         drawsubpic(theOrigin + dX,                        width - 2 * dX + height * 0.5, pic, '0.25 0 0',           '0.5  0 0' + bH, theColor, theAlpha, 0);
68                         drawsubpic(theOrigin + width - dX,                            dX + height * 0.5, pic, '0.75 0 0',           '0.25 0 0' + bH, theColor, theAlpha, 0);
69                         drawsubpic(theOrigin              + height * 0.5,             dX + height * 0.5, pic, '0    0 0' + eY - bH, '0.25 0 0' + bH, theColor, theAlpha, 0);
70                         drawsubpic(theOrigin + dX         + height * 0.5, width - 2 * dX + height * 0.5, pic, '0.25 0 0' + eY - bH, '0.5  0 0' + bH, theColor, theAlpha, 0);
71                         drawsubpic(theOrigin + width - dX + height * 0.5,             dX + height * 0.5, pic, '0.75 0 0' + eY - bH, '0.25 0 0' + bH, theColor, theAlpha, 0);
72                 }
73                 else
74                 {
75                         dX = theBorderSize_x * eX;
76                         dY = theBorderSize_x * eY;
77                         drawsubpic(theOrigin,                                        dX          +     dY, pic, '0    0    0', '0.25 0.25 0', theColor, theAlpha, 0);
78                         drawsubpic(theOrigin                  + dX,      width - 2 * dX          +     dY, pic, '0.25 0    0', '0.5  0.25 0', theColor, theAlpha, 0);
79                         drawsubpic(theOrigin          + width - dX,                  dX          +     dY, pic, '0.75 0    0', '0.25 0.25 0', theColor, theAlpha, 0);
80                         drawsubpic(theOrigin          + dY,                          dX + height - 2 * dY, pic, '0    0.25 0', '0.25 0.5  0', theColor, theAlpha, 0);
81                         drawsubpic(theOrigin          + dY         + dX, width - 2 * dX + height - 2 * dY, pic, '0.25 0.25 0', '0.5  0.5  0', theColor, theAlpha, 0);
82                         drawsubpic(theOrigin          + dY + width - dX,             dX + height - 2 * dY, pic, '0.75 0.25 0', '0.25 0.5  0', theColor, theAlpha, 0);
83                         drawsubpic(theOrigin + height - dY,                          dX          +     dY, pic, '0    0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
84                         drawsubpic(theOrigin + height - dY         + dX, width - 2 * dX          +     dY, pic, '0.25 0.75 0', '0.5  0.25 0', theColor, theAlpha, 0);
85                         drawsubpic(theOrigin + height - dY + width - dX,             dX          +     dY, pic, '0.75 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
86                 }
87         }
88 }
89
90 vector HUD_Get_Num_Color (float x, float maxvalue)
91 {
92         float blinkingamt;
93         vector color;
94         if(x >= maxvalue) {
95                 color_x = sin(2*M_PI*time);
96                 color_y = 1;
97                 color_z = sin(2*M_PI*time);
98         }
99         else if(x > maxvalue * 0.75) {
100                 color_x = 0.4 - (x-150)*0.02 * 0.4; //red value between 0.4 -> 0
101                 color_y = 0.9 + (x-150)*0.02 * 0.1; // green value between 0.9 -> 1
102                 color_z = 0;
103         }
104         else if(x > maxvalue * 0.5) {
105                 color_x = 1 - (x-100)*0.02 * 0.6; //red value between 1 -> 0.4
106                 color_y = 1 - (x-100)*0.02 * 0.1; // green value between 1 -> 0.9
107                 color_z = 1 - (x-100)*0.02; // blue value between 1 -> 0
108         }
109         else if(x > maxvalue * 0.25) {
110                 color_x = 1;
111                 color_y = 1;
112                 color_z = 0.2 + (x-50)*0.02 * 0.8; // blue value between 0.2 -> 1
113         }
114         else if(x > maxvalue * 0.1) {
115                 color_x = 1;
116                 color_y = (x-20)*90/27/100; // green value between 0 -> 1
117                 color_z = (x-20)*90/27/100 * 0.2; // blue value between 0 -> 0.2
118         }
119         else {
120                 color_x = 1;
121                 color_y = 0;
122                 color_z = 0;
123         }
124
125         blinkingamt = (1 - x/maxvalue/0.25);
126         if(blinkingamt > 0)
127         {
128                 color_x = color_x - color_x * blinkingamt * sin(2*M_PI*time);
129                 color_y = color_y - color_y * blinkingamt * sin(2*M_PI*time);
130                 color_z = color_z - color_z * blinkingamt * sin(2*M_PI*time);
131         }
132         return color;
133 }
134
135 float stringwidth_colors(string s, vector theSize)
136 {
137         return stringwidth(s, TRUE, theSize);
138 }
139
140 float stringwidth_nocolors(string s, vector theSize)
141 {
142         return stringwidth(s, FALSE, theSize);
143 }
144
145 void drawstringright(vector position, string text, vector scale, vector rgb, float theAlpha, float flag)
146 {
147         position_x -= 2 / 3 * strlen(text) * scale_x;
148         drawstring(position, text, scale, rgb, theAlpha, flag);
149 }
150
151 void drawstringcenter(vector position, string text, vector scale, vector rgb, float theAlpha, float flag)
152 {
153         position_x = 0.5 * (vid_conwidth - 0.6025 * strlen(text) * scale_x);
154         drawstring(position, text, scale, rgb, theAlpha, flag);
155 }
156
157 // return the string of the given race place
158 string race_PlaceName(float pos) {
159         if(pos == 1)
160                 return _("1st");
161         else if(pos == 2)
162                 return _("2nd");
163         else if(pos == 3)
164                 return _("3rd");
165         else
166                 return sprintf(_("%dth"), pos);
167 }
168
169 // return the string of the onscreen race timer
170 string MakeRaceString(float cp, float mytime, float histime, float lapdelta, string hisname)
171 {
172         string col;
173         string timestr;
174         string cpname;
175         string lapstr;
176         lapstr = "";
177
178         if(histime == 0) // goal hit
179         {
180                 if(mytime > 0)
181                 {
182                         timestr = strcat("+", ftos_decimals(+mytime, TIME_DECIMALS));
183                         col = "^1";
184                 }
185                 else if(mytime == 0)
186                 {
187                         timestr = "+0.0";
188                         col = "^3";
189                 }
190                 else
191                 {
192                         timestr = strcat("-", ftos_decimals(-mytime, TIME_DECIMALS));
193                         col = "^2";
194                 }
195
196                 if(lapdelta > 0)
197                 {
198                         lapstr = sprintf(_(" (-%dL)"), lapdelta);
199                         col = "^2";
200                 }
201                 else if(lapdelta < 0)
202                 {
203                         lapstr = sprintf(_(" (+%dL)"), -lapdelta);
204                         col = "^1";
205                 }
206         }
207         else if(histime > 0) // anticipation
208         {
209                 if(mytime >= histime)
210                         timestr = strcat("+", ftos_decimals(mytime - histime, TIME_DECIMALS));
211                 else
212                         timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(histime));
213                 col = "^3";
214         }
215         else
216         {
217                 col = "^7";
218                 timestr = "";
219         }
220
221         if(cp == 254)
222                 cpname = _("Start line");
223         else if(cp == 255)
224                 cpname = _("Finish line");
225         else if(cp)
226                 cpname = sprintf(_("Intermediate %d"), cp);
227         else
228                 cpname = _("Finish line");
229
230         if(histime < 0)
231                 return strcat(col, cpname);
232         else if(hisname == "")
233                 return strcat(col, sprintf(_("%s (%s)"), cpname, timestr));
234         else
235                 return strcat(col, sprintf(_("%s (%s %s)"), cpname, timestr, strcat(hisname, col, lapstr)));
236 }
237
238 // Check if the given name already exist in race rankings? In that case, where? (otherwise return 0)
239 float race_CheckName(string net_name) {
240         float i;
241         for (i=RANKINGS_CNT-1;i>=0;--i)
242                 if(grecordholder[i] == net_name)
243                         return i+1;
244         return 0;
245 }
246
247 float GetPlayerColorForce(float i)
248 {
249         if(!teamplay)
250                 return 0;
251         else
252                 return stof(getplayerkeyvalue(i, "colors")) & 15;
253 }
254
255 float GetPlayerColor(float i)
256 {
257         if not(playerslots[i].gotscores) // unconnected
258                 return FL_SPECTATOR;
259         else if(stof(getplayerkeyvalue(i, "frags")) == FRAGS_SPECTATOR)
260                 return FL_SPECTATOR;
261         else
262                 return GetPlayerColorForce(i);
263 }
264
265 string GetPlayerName(float i)
266 {
267         return ColorTranslateRGB(getplayerkeyvalue(i, "name"));
268 }
269
270
271 /*
272 ==================
273 HUD panels
274 ==================
275 */
276
277 // draw the background/borders
278 #define HUD_Panel_DrawBg(theAlpha)\
279 if(panel_bg != "0")\
280         draw_BorderPicture(panel_pos - '1 1 0' * panel_bg_border, panel_bg, panel_size + '1 1 0' * 2 * panel_bg_border, panel_bg_color, panel_bg_alpha * theAlpha, '1 1 0' * (panel_bg_border/BORDER_MULTIPLIER))
281
282 //basically the same code of draw_ButtonPicture and draw_VertButtonPicture for the menu
283 void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, float length_ratio, float vertical, float baralign, vector theColor, float theAlpha, float drawflag)
284 {
285         if(!length_ratio || !theAlpha)
286                 return;
287         if(length_ratio > 1)
288                 length_ratio = 1;
289         if (baralign == 3)
290         {
291                 if(length_ratio < -1)
292                         length_ratio = -1;
293         }
294         else if(length_ratio < 0)
295                 return;
296
297         vector square;
298         vector width, height;
299         if(vertical) {
300                 pic = strcat(hud_skin_path, "/", pic, "_vertical");
301                 if(precache_pic(pic) == "") {
302                         pic = "gfx/hud/default/progressbar_vertical";
303                 }
304
305         if (baralign == 1) // bottom align
306                         theOrigin_y += (1 - length_ratio) * theSize_y;
307         else if (baralign == 2) // center align
308             theOrigin_y += 0.5 * (1 - length_ratio) * theSize_y;
309         else if (baralign == 3) // center align, positive values down, negative up
310                 {
311                         theSize_y *= 0.5;
312                         if (length_ratio > 0)
313                                 theOrigin_y += theSize_y;
314                         else
315                         {
316                                 theOrigin_y += (1 + length_ratio) * theSize_y;
317                                 length_ratio = -length_ratio;
318                         }
319                 }
320                 theSize_y *= length_ratio;
321
322                 vector bH;
323                 width = eX * theSize_x;
324                 height = eY * theSize_y;
325                 if(theSize_y <= theSize_x * 2)
326                 {
327                         // button not high enough
328                         // draw just upper and lower part then
329                         square = eY * theSize_y * 0.5;
330                         bH = eY * (0.25 * theSize_y / (theSize_x * 2));
331                         drawsubpic(theOrigin,          square + width, pic, '0 0 0', eX + bH, theColor, theAlpha, drawflag);
332                         drawsubpic(theOrigin + square, square + width, pic, eY - bH, eX + bH, theColor, theAlpha, drawflag);
333                 }
334                 else
335                 {
336                         square = eY * theSize_x;
337                         drawsubpic(theOrigin,                   width   +     square, pic, '0 0    0', '1 0.25 0', theColor, theAlpha, drawflag);
338                         drawsubpic(theOrigin +          square, theSize - 2 * square, pic, '0 0.25 0', '1 0.5  0', theColor, theAlpha, drawflag);
339                         drawsubpic(theOrigin + height - square, width   +     square, pic, '0 0.75 0', '1 0.25 0', theColor, theAlpha, drawflag);
340                 }
341         } else {
342                 pic = strcat(hud_skin_path, "/", pic);
343                 if(precache_pic(pic) == "") {
344                         pic = "gfx/hud/default/progressbar";
345                 }
346
347                 if (baralign == 1) // right align
348                         theOrigin_x += (1 - length_ratio) * theSize_x;
349         else if (baralign == 2) // center align
350             theOrigin_x += 0.5 * (1 - length_ratio) * theSize_x;
351         else if (baralign == 3) // center align, positive values on the right, negative on the left
352                 {
353                         theSize_x *= 0.5;
354                         if (length_ratio > 0)
355                                 theOrigin_x += theSize_x;
356                         else
357                         {
358                                 theOrigin_x += (1 + length_ratio) * theSize_x;
359                                 length_ratio = -length_ratio;
360                         }
361                 }
362                 theSize_x *= length_ratio;
363
364                 vector bW;
365                 width = eX * theSize_x;
366                 height = eY * theSize_y;
367                 if(theSize_x <= theSize_y * 2)
368                 {
369                         // button not wide enough
370                         // draw just left and right part then
371                         square = eX * theSize_x * 0.5;
372                         bW = eX * (0.25 * theSize_x / (theSize_y * 2));
373                         drawsubpic(theOrigin,          square + height, pic, '0 0 0', eY + bW, theColor, theAlpha, drawflag);
374                         drawsubpic(theOrigin + square, square + height, pic, eX - bW, eY + bW, theColor, theAlpha, drawflag);
375                 }
376                 else
377                 {
378                         square = eX * theSize_y;
379                         drawsubpic(theOrigin,                  height  +     square, pic, '0    0 0', '0.25 1 0', theColor, theAlpha, drawflag);
380                         drawsubpic(theOrigin +         square, theSize - 2 * square, pic, '0.25 0 0', '0.5  1 0', theColor, theAlpha, drawflag);
381                         drawsubpic(theOrigin + width - square, height  +     square, pic, '0.75 0 0', '0.25 1 0', theColor, theAlpha, drawflag);
382                 }
383         }
384 }
385
386 void HUD_Panel_DrawHighlight(vector pos, vector mySize, vector color, float theAlpha, float drawflag)
387 {
388         if(!theAlpha)
389                 return;
390
391         string pic;
392         pic = strcat(hud_skin_path, "/num_leading");
393         if(precache_pic(pic) == "") {
394                 pic = "gfx/hud/default/num_leading";
395         }
396
397         drawsubpic(pos, eX * min(mySize_x * 0.5, mySize_y) + eY * mySize_y, pic, '0 0 0', '0.25 1 0', color, theAlpha, drawflag);
398         if(mySize_x/mySize_y > 2)
399                 drawsubpic(pos + eX * mySize_y, eX * (mySize_x - 2 * mySize_y) + eY * mySize_y, pic, '0.25 0 0', '0.5 1 0', color, theAlpha, drawflag);
400         drawsubpic(pos + eX * mySize_x - eX * min(mySize_x * 0.5, mySize_y), eX * min(mySize_x * 0.5, mySize_y) + eY * mySize_y, pic, '0.75 0 0', '0.25 1 0', color, theAlpha, drawflag);
401 }
402
403 // Weapon icons (#0)
404 //
405 entity weaponorder[WEP_MAXCOUNT];
406 void weaponorder_swap(float i, float j, entity pass)
407 {
408         entity h;
409         h = weaponorder[i];
410         weaponorder[i] = weaponorder[j];
411         weaponorder[j] = h;
412 }
413
414 string weaponorder_cmp_str;
415 float weaponorder_cmp(float i, float j, entity pass)
416 {
417         float ai, aj;
418         ai = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[i].weapon), 0);
419         aj = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[j].weapon), 0);
420         return aj - ai; // the string is in REVERSE order (higher prio at the right is what we want, but higher prio first is the string)
421 }
422
423 float GetAmmoStat(float i)
424 {
425         switch(i)
426         {
427                 case 0: return STAT_SHELLS;
428                 case 1: return STAT_NAILS;
429                 case 2: return STAT_ROCKETS;
430                 case 3: return STAT_CELLS;
431                 case 4: return STAT_FUEL;
432                 default: return -1;
433         }
434 }
435
436 float GetAmmoTypeForWep(float i)
437 {
438         switch(i)
439         {
440                 case WEP_SHOTGUN: return 0;
441                 case WEP_UZI: return 1;
442                 case WEP_GRENADE_LAUNCHER: return 2;
443                 case WEP_MINE_LAYER: return 2;
444                 case WEP_ELECTRO: return 3;
445                 case WEP_CRYLINK: return 3;
446                 case WEP_HLAC: return 3;
447                 case WEP_MINSTANEX: return 3;
448                 case WEP_NEX: return 3;
449                 case WEP_RIFLE: return 1;
450                 case WEP_HAGAR: return 2;
451                 case WEP_ROCKET_LAUNCHER: return 2;
452                 case WEP_SEEKER: return 2;
453                 case WEP_FIREBALL: return 4;
454                 case WEP_HOOK: return 3;
455                 default: return -1;
456         }
457 }
458
459 void HUD_Weapons(void)
460 {
461         // declarations
462         WEPSET_DECLARE_A(weapons_stat);
463         WEPSET_COPY_AS(weapons_stat);
464         float i, f, a, j, factor;
465         float screen_ar, center_x, center_y;
466         float weapon_count, weapon_id;
467         float row, column, rows, columns;
468         float aspect = autocvar_hud_panel_weapons_aspect;
469
470         float show_accuracy = false, panel_weapon_accuracy;
471
472         float timeout = autocvar_hud_panel_weapons_timeout;
473         float timein_effect_length = autocvar_hud_panel_weapons_timeout_speed_in; //? 0.375 : 0);
474         float timeout_effect_length = autocvar_hud_panel_weapons_timeout_speed_out; //? 0.75 : 0);
475
476         float ammo_type, ammo_full;
477         float barsize_x = 0, barsize_y = 0, baroffset_x = 0, baroffset_y = 0;
478         vector ammo_color = '1 0 1';
479         float ammo_alpha = 1;
480
481         float when = autocvar_hud_panel_weapons_complainbubble_time;
482         float fadetime = autocvar_hud_panel_weapons_complainbubble_fadetime;
483
484         vector weapon_pos, weapon_size;
485         local noref vector old_panel_size; // fteqcc sucks
486         vector color;
487
488         // check to see if we want to continue
489         if(hud != HUD_NORMAL) { return; }
490
491         if(!autocvar__hud_configure)
492         {
493                 if((!autocvar_hud_panel_weapons) || (spectatee_status == -1))
494                         return;
495                 else if(timeout && time >= weapontime + timeout + timeout_effect_length && ((autocvar_hud_panel_weapons_timeout_effect != 1) && !(autocvar_hud_panel_weapons_timeout_fadebgmin + autocvar_hud_panel_weapons_timeout_fadefgmin)))
496                 {
497                         weaponprevtime = time;
498                         return;
499                 }
500         }
501         else
502                 hud_configure_active_panel = HUD_PANEL_WEAPONS;
503
504         // update generic hud functions
505         HUD_Panel_UpdateCvars(weapons);
506         HUD_Panel_ApplyFadeAlpha();
507
508         draw_beginBoldFont();
509
510         // figure out weapon order (how the weapons are sorted) // TODO make this configurable
511         if(weaponorder_bypriority != autocvar_cl_weaponpriority || !weaponorder[0])
512         {
513                 float weapon_cnt;
514                 if(weaponorder_bypriority)
515                         strunzone(weaponorder_bypriority);
516                 if(weaponorder_byimpulse)
517                         strunzone(weaponorder_byimpulse);
518
519                 weaponorder_bypriority = strzone(autocvar_cl_weaponpriority);
520                 weaponorder_byimpulse = strzone(W_FixWeaponOrder_BuildImpulseList(W_FixWeaponOrder_ForceComplete(W_NumberWeaponOrder(weaponorder_bypriority))));
521                 weaponorder_cmp_str = strcat(" ", weaponorder_byimpulse, " ");
522
523                 weapon_cnt = 0;
524                 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
525                 {
526                         self = get_weaponinfo(i);
527                         if(self.impulse >= 0)
528                         {
529                                 weaponorder[weapon_cnt] = self;
530                                 ++weapon_cnt;
531                         }
532                 }
533                 for(i = weapon_cnt; i < WEP_MAXCOUNT; ++i)
534                         weaponorder[i] = world;
535                 heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, world);
536
537                 weaponorder_cmp_str = string_null;
538         }
539
540         // determine which weapons are going to be shown
541         if (autocvar_hud_panel_weapons_onlyowned)
542         {
543                 if(autocvar__hud_configure)
544                 {
545                         if (WEPSET_EMPTY_A(weapons_stat))
546                                 for(i = WEP_FIRST; i <= WEP_LAST; i += floor((WEP_LAST-WEP_FIRST)/5))
547                                         WEPSET_OR_AW(weapons_stat, i);
548
549                         if(menu_enabled != 2)
550                                 HUD_Panel_DrawBg(1); // also draw the bg of the entire panel
551                 }
552
553                 // do we own this weapon?
554                 weapon_count = 0;
555                 for(i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
556                         if(WEPSET_CONTAINS_AW(weapons_stat, weaponorder[i].weapon))
557                                 ++weapon_count;
558
559                 // add it anyway if weaponcomplain is shown
560                 if((!autocvar__hud_configure) 
561                         && (autocvar_hud_panel_weapons_complainbubble 
562                                 && time - complain_weapon_time < when + fadetime))
563                                         ++weapon_count;
564
565                 // might as well commit suicide now, no reason to live ;)
566                 if (weapon_count == 0) { return; }
567
568                 // reduce size of the panel
569                 if (panel_size_y > panel_size_x)
570                 {
571                         old_panel_size_y = panel_size_y;
572                         panel_size_y *= weapon_count / WEP_COUNT;
573                         panel_pos_y += (old_panel_size_y - panel_size_y) / 2;
574                 }
575                 else
576                 {
577                         old_panel_size_x = panel_size_x;
578                         panel_size_x *= weapon_count / WEP_COUNT;
579                         panel_pos_x += (old_panel_size_x - panel_size_x) / 2;
580                 }
581         }
582         else
583                 weapon_count = WEP_COUNT;
584
585         // animation for fading in/out the panel respectively when not in use
586         if(!autocvar__hud_configure)
587         {
588                 if (timeout && time >= weapontime + timeout) // apply timeout effect if needed
589                 {
590                         f = bound(0, (time - (weapontime + timeout)) / timeout_effect_length, 1);
591
592                         // fade the panel alpha
593                         if(autocvar_hud_panel_weapons_timeout_effect == 1)
594                         {
595                                 panel_bg_alpha *= (autocvar_hud_panel_weapons_timeout_fadebgmin * f + (1 - f));
596                                 panel_fg_alpha *= (autocvar_hud_panel_weapons_timeout_fadefgmin * f + (1 - f));
597                         }
598                         else if(autocvar_hud_panel_weapons_timeout_effect == 3)
599                         {
600                                 panel_bg_alpha *= (1 - f);
601                                 panel_fg_alpha *= (1 - f);
602                         }
603
604                         // move the panel off the screen
605                         if (autocvar_hud_panel_weapons_timeout_effect == 2 || autocvar_hud_panel_weapons_timeout_effect == 3)
606                         {
607                                 f *= f; // for a cooler movement
608                                 center_x = panel_pos_x + panel_size_x/2;
609                                 center_y = panel_pos_y + panel_size_y/2;
610                                 screen_ar = vid_conwidth/vid_conheight;
611                                 if (center_x/center_y < screen_ar) //bottom left
612                                 {
613                                         if ((vid_conwidth - center_x)/center_y < screen_ar) //bottom
614                                                 panel_pos_y += f * (vid_conheight - panel_pos_y);
615                                         else //left
616                                                 panel_pos_x -= f * (panel_pos_x + panel_size_x);
617                                 }
618                                 else //top right
619                                 {
620                                         if ((vid_conwidth - center_x)/center_y < screen_ar) //right
621                                                 panel_pos_x += f * (vid_conwidth - panel_pos_x);
622                                         else //top
623                                                 panel_pos_y -= f * (panel_pos_y + panel_size_y);
624                                 }
625                         }
626                         weaponprevtime = time - (1 - f) * timein_effect_length;
627                 }
628                 else if (timeout && time < weaponprevtime + timein_effect_length) // apply timein effect if needed
629                 {
630                         f = bound(0, (time - weaponprevtime) / timein_effect_length, 1);
631
632                         // fade the panel alpha
633                         if(autocvar_hud_panel_weapons_timeout_effect == 1)
634                         {
635                                 panel_bg_alpha *= (autocvar_hud_panel_weapons_timeout_fadebgmin * (1 - f) + f);
636                                 panel_fg_alpha *= (autocvar_hud_panel_weapons_timeout_fadefgmin * (1 - f) + f);
637                         }
638                         else if(autocvar_hud_panel_weapons_timeout_effect == 3)
639                         {
640                                 panel_bg_alpha *= (f);
641                                 panel_fg_alpha *= (f);
642                         }
643
644                         // move the panel back on screen
645                         if (autocvar_hud_panel_weapons_timeout_effect == 2 || autocvar_hud_panel_weapons_timeout_effect == 3)
646                         {
647                                 f *= f; // for a cooler movement
648                                 f = 1 - f;
649                                 center_x = panel_pos_x + panel_size_x/2;
650                                 center_y = panel_pos_y + panel_size_y/2;
651                                 screen_ar = vid_conwidth/vid_conheight;
652                                 if (center_x/center_y < screen_ar) //bottom left
653                                 {
654                                         if ((vid_conwidth - center_x)/center_y < screen_ar) //bottom
655                                                 panel_pos_y += f * (vid_conheight - panel_pos_y);
656                                         else //left
657                                                 panel_pos_x -= f * (panel_pos_x + panel_size_x);
658                                 }
659                                 else //top right
660                                 {
661                                         if ((vid_conwidth - center_x)/center_y < screen_ar) //right
662                                                 panel_pos_x += f * (vid_conwidth - panel_pos_x);
663                                         else //top
664                                                 panel_pos_y -= f * (panel_pos_y + panel_size_y);
665                                 }
666                         }
667                 }
668         }
669
670         // draw the background, then change the virtual size of it to better fit other items inside
671         HUD_Panel_DrawBg(1);
672         if(panel_bg_padding)
673         {
674                 panel_pos += '1 1 0' * panel_bg_padding;
675                 panel_size -= '2 2 0' * panel_bg_padding;
676         }
677
678         // after the sizing and animations are done, update the other values
679         rows = panel_size_y/panel_size_x;
680         rows = bound(1, floor((sqrt(4 * aspect * rows * weapon_count + rows * rows) + rows + 0.5) / 2), weapon_count);
681         columns = ceil(weapon_count/rows);
682         weapon_size = eX * panel_size_x*(1/columns) + eY * panel_size_y*(1/rows);
683
684         // calculate position/size for visual bar displaying ammount of ammo status
685         if (autocvar_hud_panel_weapons_ammo)
686         {
687                 ammo_color = stov(autocvar_hud_panel_weapons_ammo_color);
688                 ammo_alpha = panel_fg_alpha * autocvar_hud_panel_weapons_ammo_alpha;
689
690                 if(weapon_size_x/weapon_size_y > aspect)
691                 {
692                         barsize_x = aspect * weapon_size_y;
693                         barsize_y = weapon_size_y;
694                         baroffset_x = (weapon_size_x - barsize_x) / 2;
695                 }
696                 else
697                 {
698                         barsize_y = 1/aspect * weapon_size_x;
699                         barsize_x = weapon_size_x;
700                         baroffset_y = (weapon_size_y - barsize_y) / 2;
701                 }
702         }
703
704         if(autocvar_hud_panel_weapons_accuracy && acc_levels)
705         {
706                 show_accuracy = true;
707                 if (acc_col[0] == '-1 0 0')
708                         for (i = 0; i < acc_levels; ++i)
709                                 acc_col[i] = stov(cvar_string(strcat("accuracy_color", ftos(i))));
710         }
711
712         row = column = 0;
713         for(i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
714         {
715                 // retrieve information about the current weapon to be drawn
716                 self = weaponorder[i];
717                 weapon_id = self.impulse;
718
719                 // skip if this weapon doesn't exist
720                 if (!self || self.impulse < 0) { continue; }
721
722                 // skip this weapon if we don't own it (and onlyowned is enabled)-- or if weapons_complainbubble is showing for this weapon
723                 if (autocvar_hud_panel_weapons_onlyowned
724                         && !(WEPSET_CONTAINS_AW(weapons_stat, self.weapon) 
725                         || (self.weapon == complain_weapon 
726                                 && time - complain_weapon_time < when + fadetime 
727                                 && autocvar_hud_panel_weapons_complainbubble)))
728                                         continue;
729
730                 // figure out the drawing position of weapon
731                 weapon_pos = (panel_pos 
732                         + eX * column * weapon_size_x 
733                         + eY * row * weapon_size_y);
734
735                 // draw background behind currently selected weapon
736                 if(self.weapon == switchweapon)
737                         drawpic_aspect_skin(weapon_pos, "weapon_current_bg", weapon_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
738
739                 // draw the weapon accuracy
740                 if(show_accuracy)
741                 {
742                         panel_weapon_accuracy = weapon_accuracy[self.weapon-WEP_FIRST];
743                         if(panel_weapon_accuracy >= 0)
744                         {
745                                 // find the max level lower than weapon_accuracy
746                                 j = acc_levels-1;
747                                 while ( j && panel_weapon_accuracy < acc_lev[j] )
748                                         --j;
749
750                                 // inject color j+1 in color j, how much depending on how much weapon_accuracy is higher than level j
751                                 factor = (panel_weapon_accuracy - acc_lev[j]) / (acc_lev[j+1] - acc_lev[j]);
752                                 color = acc_col[j];
753                                 color = color + factor * (acc_col[j+1] - color);
754
755                                 drawpic_aspect_skin(weapon_pos, "weapon_accuracy", weapon_size, color, panel_fg_alpha, DRAWFLAG_NORMAL);
756                         }
757                 }
758
759                 // drawing all the weapon items
760                 if(WEPSET_CONTAINS_AW(weapons_stat, self.weapon))
761                 {
762                         // draw the weapon image
763                         drawpic_aspect_skin(weapon_pos, strcat("weapon", self.netname), weapon_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
764
765                         // draw weapon label string
766                         switch(autocvar_hud_panel_weapons_label)
767                         {
768                                 case 1: // weapon number
769                                         drawstring(weapon_pos, ftos(weapon_id), '1 1 0' * 0.5 * weapon_size_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
770                                         break;
771
772                                 case 2: // bind
773                                         drawstring(weapon_pos, getcommandkey(ftos(weapon_id), strcat("weapon_group_", ftos(weapon_id))), '1 1 0' * 0.5 * weapon_size_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
774                                         break;
775
776                                 case 3: // weapon name
777                                         drawstring(weapon_pos, self.netname, '1 1 0' * 0.5 * weapon_size_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
778                                         break;
779
780                                 default: // nothing
781                                         break;
782                         }
783
784                         // draw ammo status bar
785                         if(autocvar_hud_panel_weapons_ammo && self.weapon != WEP_TUBA && self.weapon != WEP_LASER && self.weapon != WEP_PORTO)
786                         {
787                                 a = 0;
788                                 ammo_type = GetAmmoTypeForWep(self.weapon);
789                                 if(ammo_type != -1)
790                                         a = getstati(GetAmmoStat(ammo_type)); // how much ammo do we have?
791
792                                 if(a > 0)
793                                 {
794                                         switch(ammo_type) {
795                                                 case 0: ammo_full = autocvar_hud_panel_weapons_ammo_full_shells; break;
796                                                 case 1: ammo_full = autocvar_hud_panel_weapons_ammo_full_nails; break;
797                                                 case 2: ammo_full = autocvar_hud_panel_weapons_ammo_full_rockets; break;
798                                                 case 3: ammo_full = autocvar_hud_panel_weapons_ammo_full_cells; break;
799                                                 case 4: ammo_full = autocvar_hud_panel_weapons_ammo_full_fuel; break;
800                                                 default: ammo_full = 60;
801                                         }
802
803                                         drawsetcliparea(
804                                                 weapon_pos_x + baroffset_x,
805                                                 weapon_pos_y + baroffset_y,
806                                                 barsize_x * bound(0, a/ammo_full, 1),
807                                                 barsize_y);
808                                         drawpic_aspect_skin(weapon_pos, "weapon_ammo", weapon_size, ammo_color, ammo_alpha, DRAWFLAG_NORMAL);
809                                         drawresetcliparea();
810                                 }
811                         }
812                 }
813                 else // draw a "ghost weapon icon" if you don't have the weapon
814                 {
815                         drawpic_aspect_skin(weapon_pos, strcat("weapon", self.netname), weapon_size, '0 0 0', panel_fg_alpha * 0.5, DRAWFLAG_NORMAL);
816                 }
817
818                 // draw the complain message
819                 if(time - complain_weapon_time < when + fadetime && self.weapon == complain_weapon && autocvar_hud_panel_weapons_complainbubble)
820                 {
821                         if(fadetime)
822                                 a = ((complain_weapon_time + when > time) ? 1 : bound(0, (complain_weapon_time + when + fadetime - time) / fadetime, 1));
823                         else
824                                 a = ((complain_weapon_time + when > time) ? 1 : 0);
825
826
827                         string s;
828                         if(complain_weapon_type == 0) {
829                                 s = _("Out of ammo");
830                                 color = stov(autocvar_hud_panel_weapons_complainbubble_color_outofammo);
831                         }
832                         else if(complain_weapon_type == 1) {
833                                 s = _("Don't have");
834                                 color = stov(autocvar_hud_panel_weapons_complainbubble_color_donthave);
835                         }
836                         else {
837                                 s = _("Unavailable");
838                                 color = stov(autocvar_hud_panel_weapons_complainbubble_color_unavailable);
839                         }
840                         float padding = autocvar_hud_panel_weapons_complainbubble_padding;
841                         drawpic_aspect_skin(weapon_pos + '1 1 0' * padding, "weapon_complainbubble", weapon_size - '2 2 0' * padding, color, a * panel_fg_alpha, DRAWFLAG_NORMAL);
842                         drawstring_aspect(weapon_pos + '1 1 0' * padding, s, weapon_size - '2 2 0' * padding, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
843                 }
844
845                 // continue with new position for the next weapon
846                 ++row;
847                 if(row >= rows)
848                 {
849                         row = 0;
850                         ++column;
851                 }
852         }
853
854         draw_endBoldFont();
855 }
856
857 // Ammo (#1)
858 //
859 // TODO: macro
860 float GetAmmoItemCode(float i)
861 {
862         switch(i)
863         {
864                 case 0: return IT_SHELLS;
865                 case 1: return IT_NAILS;
866                 case 2: return IT_ROCKETS;
867                 case 3: return IT_CELLS;
868                 case 4: return IT_FUEL;
869                 default: return -1;
870         }
871 }
872
873 string GetAmmoPicture(float i)
874 {
875         switch(i)
876         {
877                 case 0: return "ammo_shells";
878                 case 1: return "ammo_bullets";
879                 case 2: return "ammo_rockets";
880                 case 3: return "ammo_cells";
881                 case 4: return "ammo_fuel";
882                 default: return "";
883         }
884 }
885
886 void DrawAmmoItem(vector myPos, vector mySize, float itemcode, float currently_selected, float infinite_ammo)
887 {
888         float a;
889         if(autocvar__hud_configure)
890         {
891                 currently_selected = (itemcode == 2); //rockets always selected
892                 a = 31 + mod(itemcode*93, 128);
893         }
894         else
895                 a = getstati(GetAmmoStat(itemcode)); // how much ammo do we have of type itemcode?
896
897         vector color;
898         if(infinite_ammo)
899                 color = '0 0.5 0.75';
900         else if(a < 10)
901                 color = '0.7 0 0';
902         else
903                 color = '1 1 1';
904
905         float theAlpha;
906         if(currently_selected)
907                 theAlpha = 1;
908         else
909                 theAlpha = 0.7;
910
911         vector picpos, numpos;
912         if(autocvar_hud_panel_ammo_iconalign)
913         {
914                 numpos = myPos;
915                 picpos = myPos + eX * 2 * mySize_y;
916         }
917         else
918         {
919                 numpos = myPos + eX * mySize_y;
920                 picpos = myPos;
921         }
922
923         if (currently_selected)
924                 drawpic_aspect_skin(myPos, "ammo_current_bg", mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
925
926     if(a > 0 && autocvar_hud_panel_ammo_progressbar)
927         HUD_Panel_DrawProgressBar(myPos + eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize_x, mySize - eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize_x, autocvar_hud_panel_ammo_progressbar_name, a/autocvar_hud_panel_ammo_maxammo, 0, 0, color, autocvar_hud_progressbar_alpha * panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
928
929     if(autocvar_hud_panel_ammo_text)
930     {
931         if(a > 0 || infinite_ammo)
932             drawstring_aspect(numpos, ftos(a), eX * (2/3) * mySize_x + eY * mySize_y, color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
933         else // "ghost" ammo count
934             drawstring_aspect(numpos, ftos(a), eX * (2/3) * mySize_x + eY * mySize_y, '0 0 0', panel_fg_alpha * theAlpha * 0.5, DRAWFLAG_NORMAL);
935     }
936         if(a > 0 || infinite_ammo)
937                 drawpic_aspect_skin(picpos, GetAmmoPicture(itemcode), '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
938         else // "ghost" ammo icon
939                 drawpic_aspect_skin(picpos, GetAmmoPicture(itemcode), '1 1 0' * mySize_y, '0 0 0', panel_fg_alpha * theAlpha * 0.5, DRAWFLAG_NORMAL);
940 }
941
942 void HUD_Ammo(void)
943 {
944     if(hud != HUD_NORMAL) return;
945         if(!autocvar__hud_configure)
946         {
947                 if(!autocvar_hud_panel_ammo) return;
948                 if(spectatee_status == -1) return;
949         }
950         else
951                 hud_configure_active_panel = HUD_PANEL_AMMO;
952
953         HUD_Panel_UpdateCvars(ammo);
954         HUD_Panel_ApplyFadeAlpha();
955
956         draw_beginBoldFont();
957
958         vector pos, mySize;
959         pos = panel_pos;
960         mySize = panel_size;
961
962         HUD_Panel_DrawBg(1);
963         if(panel_bg_padding)
964         {
965                 pos += '1 1 0' * panel_bg_padding;
966                 mySize -= '2 2 0' * panel_bg_padding;
967         }
968
969         float rows = 0, columns, row, column;
970         vector ammo_size;
971         if (autocvar_hud_panel_ammo_onlycurrent)
972                 ammo_size = mySize;
973         else
974         {
975                 rows = mySize_y/mySize_x;
976                 rows = bound(1, floor((sqrt(4 * (3/1) * rows * AMMO_COUNT + rows * rows) + rows + 0.5) / 2), AMMO_COUNT);
977                 //                               ^^^ ammo item aspect goes here
978
979                 columns = ceil(AMMO_COUNT/rows);
980
981                 ammo_size = eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows);
982         }
983
984         local vector offset = '0 0 0'; // fteqcc sucks
985         float newSize;
986         if(ammo_size_x/ammo_size_y > 3)
987         {
988                 newSize = 3 * ammo_size_y;
989                 offset_x = ammo_size_x - newSize;
990                 pos_x += offset_x/2;
991                 ammo_size_x = newSize;
992         }
993         else
994         {
995                 newSize = 1/3 * ammo_size_x;
996                 offset_y = ammo_size_y - newSize;
997                 pos_y += offset_y/2;
998                 ammo_size_y = newSize;
999         }
1000
1001         float i, stat_items, currently_selected, infinite_ammo;
1002         infinite_ammo = FALSE;
1003         if (autocvar_hud_panel_ammo_onlycurrent)
1004         {
1005                 if(autocvar__hud_configure)
1006                 {
1007                         DrawAmmoItem(pos, ammo_size, 2, true, FALSE); //show rockets
1008                 }
1009                 else
1010                 {
1011                         stat_items = getstati(STAT_ITEMS, 0, 24);
1012                         if (stat_items & IT_UNLIMITED_WEAPON_AMMO)
1013                                 infinite_ammo = TRUE;
1014                         for (i = 0; i < AMMO_COUNT; ++i) {
1015                                 currently_selected = stat_items & GetAmmoItemCode(i);
1016                                 if (currently_selected)
1017                                 {
1018                                         DrawAmmoItem(pos, ammo_size, i, true, infinite_ammo);
1019                                         break;
1020                                 }
1021                         }
1022                 }
1023         }
1024         else
1025         {
1026                 stat_items = getstati(STAT_ITEMS, 0, 24);
1027                 if (stat_items & IT_UNLIMITED_WEAPON_AMMO)
1028                         infinite_ammo = TRUE;
1029                 row = column = 0;
1030                 for (i = 0; i < AMMO_COUNT; ++i) {
1031                         currently_selected = stat_items & GetAmmoItemCode(i);
1032                         DrawAmmoItem(pos + eX * column * (ammo_size_x + offset_x) + eY * row * (ammo_size_y + offset_y), ammo_size, i, currently_selected, infinite_ammo);
1033                         ++row;
1034                         if(row >= rows)
1035                         {
1036                                 row = 0;
1037                                 column = column + 1;
1038                         }
1039                 }
1040         }
1041
1042         draw_endBoldFont();
1043 }
1044
1045 void DrawNumIcon_expanding(vector myPos, vector mySize, float x, string icon, float vertical, float icon_right_align, vector color, float theAlpha, float fadelerp)
1046 {
1047         vector newPos = '0 0 0', newSize = '0 0 0';
1048         vector picpos, numpos;
1049
1050         if (vertical)
1051         {
1052                 if(mySize_y/mySize_x > 2)
1053                 {
1054                         newSize_y = 2 * mySize_x;
1055                         newSize_x = mySize_x;
1056
1057                         newPos_y = myPos_y + (mySize_y - newSize_y) / 2;
1058                         newPos_x = myPos_x;
1059                 }
1060                 else
1061                 {
1062                         newSize_x = 1/2 * mySize_y;
1063                         newSize_y = mySize_y;
1064
1065                         newPos_x = myPos_x + (mySize_x - newSize_x) / 2;
1066                         newPos_y = myPos_y;
1067                 }
1068
1069                 if(icon_right_align)
1070                 {
1071                         numpos = newPos;
1072                         picpos = newPos + eY * newSize_x;
1073                 }
1074                 else
1075                 {
1076                         picpos = newPos;
1077                         numpos = newPos + eY * newSize_x;
1078                 }
1079
1080                 newSize_y /= 2;
1081                 drawpic_aspect_skin(picpos, icon, newSize, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
1082                 // make number smaller than icon, it looks better
1083                 // reduce only y to draw numbers with different number of digits with the same y size
1084                 numpos_y += newSize_y * ((1 - 0.7) / 2);
1085                 newSize_y *= 0.7;
1086                 drawstring_aspect(numpos, ftos(x), newSize, color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
1087                 return;
1088         }
1089
1090         if(mySize_x/mySize_y > 3)
1091         {
1092                 newSize_x = 3 * mySize_y;
1093                 newSize_y = mySize_y;
1094
1095                 newPos_x = myPos_x + (mySize_x - newSize_x) / 2;
1096                 newPos_y = myPos_y;
1097         }
1098         else
1099         {
1100                 newSize_y = 1/3 * mySize_x;
1101                 newSize_x = mySize_x;
1102
1103                 newPos_y = myPos_y + (mySize_y - newSize_y) / 2;
1104                 newPos_x = myPos_x;
1105         }
1106
1107         if(icon_right_align) // right align
1108         {
1109                 numpos = newPos;
1110                 picpos = newPos + eX * 2 * newSize_y;
1111         }
1112         else // left align
1113         {
1114                 numpos = newPos + eX * newSize_y;
1115                 picpos = newPos;
1116         }
1117
1118         // NOTE: newSize_x is always equal to 3 * mySize_y so we can use
1119         // '2 1 0' * newSize_y instead of eX * (2/3) * newSize_x + eY * newSize_y
1120         drawstring_aspect_expanding(numpos, ftos(x), '2 1 0' * newSize_y, color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL, fadelerp);
1121         drawpic_aspect_skin_expanding(picpos, icon, '1 1 0' * newSize_y, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL, fadelerp);
1122 }
1123
1124 void DrawNumIcon(vector myPos, vector mySize, float x, string icon, float vertical, float icon_right_align, vector color, float theAlpha)
1125 {
1126         DrawNumIcon_expanding(myPos, mySize, x, icon, vertical, icon_right_align, color, theAlpha, 0);
1127 }
1128
1129 // Powerups (#2)
1130 //
1131 void HUD_Powerups(void)
1132 {
1133         float strength_time, shield_time, superweapons_time;
1134         if(!autocvar__hud_configure)
1135         {
1136                 if(!autocvar_hud_panel_powerups) return;
1137                 if(spectatee_status == -1) return;
1138                 if not(getstati(STAT_ITEMS, 0, 24) & (IT_STRENGTH | IT_INVINCIBLE | IT_SUPERWEAPON)) return;
1139                 if (getstati(STAT_HEALTH) <= 0) return;
1140
1141                 strength_time = bound(0, getstatf(STAT_STRENGTH_FINISHED) - time, 99);
1142                 shield_time = bound(0, getstatf(STAT_INVINCIBLE_FINISHED) - time, 99);
1143                 superweapons_time = bound(0, getstatf(STAT_SUPERWEAPONS_FINISHED) - time, 99);
1144
1145                 if (getstati(STAT_ITEMS, 0, 24) & IT_UNLIMITED_SUPERWEAPONS)
1146                         superweapons_time = 99; // force max
1147
1148                 // prevent stuff to show up on mismatch that will be fixed next frame
1149                 if (!(getstati(STAT_ITEMS, 0, 24) & IT_SUPERWEAPON))
1150                         superweapons_time = 0;
1151         }
1152         else
1153         {
1154                 hud_configure_active_panel = HUD_PANEL_POWERUPS;
1155
1156                 strength_time = 15;
1157                 shield_time = 27;
1158                 superweapons_time = 13;
1159         }
1160
1161         HUD_Panel_UpdateCvars(powerups);
1162         HUD_Panel_ApplyFadeAlpha();
1163
1164         draw_beginBoldFont();
1165
1166         vector pos, mySize;
1167         pos = panel_pos;
1168         mySize = panel_size;
1169
1170         HUD_Panel_DrawBg(bound(0, max(strength_time, shield_time, superweapons_time), 1));
1171         if(panel_bg_padding)
1172         {
1173                 pos += '1 1 0' * panel_bg_padding;
1174                 mySize -= '2 2 0' * panel_bg_padding;
1175         }
1176
1177         float panel_ar = mySize_x/mySize_y;
1178         float is_vertical = (panel_ar < 1);
1179         vector shield_offset = '0 0 0', strength_offset = '0 0 0', superweapons_offset = '0 0 0';
1180
1181         float superweapons_is = -1;
1182
1183         if(superweapons_time)
1184         {
1185                 if(strength_time)
1186                 {
1187                         if(shield_time)
1188                                 superweapons_is = 0;
1189                         else
1190                                 superweapons_is = 2;
1191                 }
1192                 else
1193                 {
1194                         if(shield_time)
1195                                 superweapons_is = 1;
1196                         else
1197                                 superweapons_is = 2;
1198                 }
1199         }
1200
1201         // FIXME handle superweapons here
1202         if(superweapons_is == 0)
1203         {
1204                 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
1205                 {
1206                         mySize_x *= (1.0 / 3.0);
1207                         superweapons_offset_x = mySize_x;
1208                         if (autocvar_hud_panel_powerups_flip)
1209                                 shield_offset_x = 2*mySize_x;
1210                         else
1211                                 strength_offset_x = 2*mySize_x;
1212                 }
1213                 else
1214                 {
1215                         mySize_y *= (1.0 / 3.0);
1216                         superweapons_offset_y = mySize_y;
1217                         if (autocvar_hud_panel_powerups_flip)
1218                                 shield_offset_y = 2*mySize_y;
1219                         else
1220                                 strength_offset_y = 2*mySize_y;
1221                 }
1222         }
1223         else
1224         {
1225                 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
1226                 {
1227                         mySize_x *= 0.5;
1228                         if (autocvar_hud_panel_powerups_flip)
1229                                 shield_offset_x = mySize_x;
1230                         else
1231                                 strength_offset_x = mySize_x;
1232                 }
1233                 else
1234                 {
1235                         mySize_y *= 0.5;
1236                         if (autocvar_hud_panel_powerups_flip)
1237                                 shield_offset_y = mySize_y;
1238                         else
1239                                 strength_offset_y = mySize_y;
1240                 }
1241         }
1242
1243         float shield_baralign, strength_baralign, superweapons_baralign;
1244         float shield_iconalign, strength_iconalign, superweapons_iconalign;
1245
1246         if (autocvar_hud_panel_powerups_flip)
1247         {
1248                 strength_baralign = (autocvar_hud_panel_powerups_baralign == 2 || autocvar_hud_panel_powerups_baralign == 1);
1249                 shield_baralign = (autocvar_hud_panel_powerups_baralign == 3 || autocvar_hud_panel_powerups_baralign == 1);
1250                 strength_iconalign = (autocvar_hud_panel_powerups_iconalign == 2 || autocvar_hud_panel_powerups_iconalign == 1);
1251                 shield_iconalign = (autocvar_hud_panel_powerups_iconalign == 3 || autocvar_hud_panel_powerups_iconalign == 1);
1252         }
1253         else
1254         {
1255                 shield_baralign = (autocvar_hud_panel_powerups_baralign == 2 || autocvar_hud_panel_powerups_baralign == 1);
1256                 strength_baralign = (autocvar_hud_panel_powerups_baralign == 3 || autocvar_hud_panel_powerups_baralign == 1);
1257                 shield_iconalign = (autocvar_hud_panel_powerups_iconalign == 2 || autocvar_hud_panel_powerups_iconalign == 1);
1258                 strength_iconalign = (autocvar_hud_panel_powerups_iconalign == 3 || autocvar_hud_panel_powerups_iconalign == 1);
1259         }
1260
1261         if(superweapons_is == 0)
1262         {
1263                 superweapons_iconalign = strength_iconalign;
1264                 superweapons_baralign = 2;
1265         }
1266         else if(superweapons_is == 1)
1267         {
1268                 superweapons_offset = strength_offset;
1269                 superweapons_iconalign = strength_iconalign;
1270                 superweapons_baralign = strength_baralign;
1271         }
1272         else // if(superweapons_is == 2)
1273         {
1274                 superweapons_offset = shield_offset;
1275                 superweapons_iconalign = shield_iconalign;
1276                 superweapons_baralign = shield_baralign;
1277         }
1278
1279         if(shield_time)
1280         {
1281                 const float maxshield = 30;
1282                 float shield = ceil(shield_time);
1283                 if(autocvar_hud_panel_powerups_progressbar)
1284                 {
1285                         HUD_Panel_GetProgressBarColor(shield);
1286                         HUD_Panel_DrawProgressBar(pos + shield_offset, mySize, autocvar_hud_panel_powerups_progressbar_shield, shield/maxshield, is_vertical, shield_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
1287                 }
1288                 if(autocvar_hud_panel_powerups_text)
1289                 {
1290                         if(shield > 1)
1291                                 DrawNumIcon(pos + shield_offset, mySize, shield, "shield", is_vertical, shield_iconalign, '1 1 1', 1);
1292                         if(shield <= 5)
1293                                 DrawNumIcon_expanding(pos + shield_offset, mySize, shield, "shield", is_vertical, shield_iconalign, '1 1 1', 1, bound(0, (shield - shield_time) / 0.5, 1));
1294                 }
1295         }
1296
1297         if(strength_time)
1298         {
1299                 const float maxstrength = 30;
1300                 float strength = ceil(strength_time);
1301                 if(autocvar_hud_panel_powerups_progressbar)
1302                 {
1303                         HUD_Panel_GetProgressBarColor(strength);
1304                         HUD_Panel_DrawProgressBar(pos + strength_offset, mySize, autocvar_hud_panel_powerups_progressbar_strength, strength/maxstrength, is_vertical, strength_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
1305                 }
1306                 if(autocvar_hud_panel_powerups_text)
1307                 {
1308                         if(strength > 1)
1309                                 DrawNumIcon(pos + strength_offset, mySize, strength, "strength", is_vertical, strength_iconalign, '1 1 1', 1);
1310                         if(strength <= 5)
1311                                 DrawNumIcon_expanding(pos + strength_offset, mySize, strength, "strength", is_vertical, strength_iconalign, '1 1 1', 1, bound(0, (strength - strength_time) / 0.5, 1));
1312                 }
1313         }
1314
1315         if(superweapons_time)
1316         {
1317                 const float maxsuperweapons = 30;
1318                 float superweapons = ceil(superweapons_time);
1319                 if(autocvar_hud_panel_powerups_progressbar)
1320                 {
1321                         HUD_Panel_GetProgressBarColor(superweapons);
1322                         HUD_Panel_DrawProgressBar(pos + superweapons_offset, mySize, autocvar_hud_panel_powerups_progressbar_superweapons, superweapons/maxsuperweapons, is_vertical, superweapons_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
1323                 }
1324                 if(autocvar_hud_panel_powerups_text)
1325                 {
1326                         if(superweapons > 1)
1327                                 DrawNumIcon(pos + superweapons_offset, mySize, superweapons, "superweapons", is_vertical, superweapons_iconalign, '1 1 1', 1);
1328                         if(superweapons <= 5)
1329                                 DrawNumIcon_expanding(pos + superweapons_offset, mySize, superweapons, "superweapons", is_vertical, superweapons_iconalign, '1 1 1', 1, bound(0, (superweapons - superweapons_time) / 0.5, 1));
1330                 }
1331         }
1332
1333         draw_endBoldFont();
1334 }
1335
1336 // Health/armor (#3)
1337 //
1338
1339 // prev_* vars contain the health/armor at the previous FRAME
1340 // set to -1 when player is dead or was not playing
1341 float prev_health, prev_armor;
1342 float health_damagetime, armor_damagetime;
1343 float health_beforedamage, armor_beforedamage;
1344 // old_p_* vars keep track of previous values when smoothing value changes of the progressbar
1345 float old_p_health, old_p_armor;
1346 float old_p_healthtime, old_p_armortime;
1347 // prev_p_* vars contain the health/armor progressbar value at the previous FRAME
1348 // set to -1 to forcedly stop effects when we switch spectated player (e.g. from playerX: 70h to playerY: 50h)
1349 float prev_p_health, prev_p_armor;
1350
1351 void HUD_HealthArmor(void)
1352 {
1353         float armor, health, fuel;
1354         if(!autocvar__hud_configure)
1355         {
1356                 if(!autocvar_hud_panel_healtharmor) return;
1357                 if(hud != HUD_NORMAL) return;
1358                 if(spectatee_status == -1) return;
1359
1360                 health = getstati(STAT_HEALTH);
1361                 if(health <= 0)
1362                 {
1363                         prev_health = -1;
1364                         return;
1365                 }
1366                 armor = getstati(STAT_ARMOR);
1367
1368                 // code to check for spectatee_status changes is in Ent_ClientData()
1369                 // prev_p_health and prev_health can be set to -1 there
1370
1371                 if (prev_p_health == -1)
1372                 {
1373                         // no effect
1374                         health_beforedamage = 0;
1375                         armor_beforedamage = 0;
1376                         health_damagetime = 0;
1377                         armor_damagetime = 0;
1378                         prev_health = health;
1379                         prev_armor = armor;
1380                         old_p_health = health;
1381                         old_p_armor = armor;
1382                         prev_p_health = health;
1383                         prev_p_armor = armor;
1384                 }
1385                 else if (prev_health == -1)
1386                 {
1387                         //start the load effect
1388                         health_damagetime = 0;
1389                         armor_damagetime = 0;
1390                         prev_health = 0;
1391                         prev_armor = 0;
1392                 }
1393                 fuel = getstati(STAT_FUEL);
1394         }
1395         else
1396         {
1397                 hud_configure_active_panel = HUD_PANEL_HEALTHARMOR;
1398
1399                 health = 150;
1400                 armor = 75;
1401                 fuel = 20;
1402         }
1403
1404         HUD_Panel_UpdateCvars(healtharmor);
1405         HUD_Panel_ApplyFadeAlpha();
1406         vector pos, mySize;
1407         pos = panel_pos;
1408         mySize = panel_size;
1409
1410         HUD_Panel_DrawBg(1);
1411         if(panel_bg_padding)
1412         {
1413                 pos += '1 1 0' * panel_bg_padding;
1414                 mySize -= '2 2 0' * panel_bg_padding;
1415         }
1416
1417         float baralign = autocvar_hud_panel_healtharmor_baralign;
1418         float iconalign = autocvar_hud_panel_healtharmor_iconalign;
1419
1420     float maxhealth = autocvar_hud_panel_healtharmor_maxhealth;
1421     float maxarmor = autocvar_hud_panel_healtharmor_maxarmor;
1422         if(autocvar_hud_panel_healtharmor == 2) // combined health and armor display
1423         {
1424                 vector v;
1425                 v = healtharmor_maxdamage(health, armor, armorblockpercent);
1426
1427                 float x;
1428                 x = floor(v_x + 1);
1429
1430         float maxtotal = maxhealth + maxarmor;
1431                 string biggercount;
1432                 if(v_z) // NOT fully armored
1433                 {
1434                         biggercount = "health";
1435                         if(autocvar_hud_panel_healtharmor_progressbar)
1436                         {
1437                                 HUD_Panel_GetProgressBarColor(health);
1438                                 HUD_Panel_DrawProgressBar(pos, mySize, autocvar_hud_panel_healtharmor_progressbar_health, x/maxtotal, 0, (baralign == 1 || baralign == 2), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
1439                         }
1440                         if(armor)
1441             if(autocvar_hud_panel_healtharmor_text)
1442                                 drawpic_aspect_skin(pos + eX * mySize_x - eX * 0.5 * mySize_y, "armor", '0.5 0.5 0' * mySize_y, '1 1 1', panel_fg_alpha * armor / health, DRAWFLAG_NORMAL);
1443                 }
1444                 else
1445                 {
1446                         biggercount = "armor";
1447                         if(autocvar_hud_panel_healtharmor_progressbar)
1448                         {
1449                                 HUD_Panel_GetProgressBarColor(armor);
1450                                 HUD_Panel_DrawProgressBar(pos, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, x/maxtotal, 0, (baralign == 1 || baralign == 2), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
1451                         }
1452                         if(health)
1453             if(autocvar_hud_panel_healtharmor_text)
1454                                 drawpic_aspect_skin(pos + eX * mySize_x - eX * 0.5 * mySize_y, "health", '0.5 0.5 0' * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
1455                 }
1456         if(autocvar_hud_panel_healtharmor_text)
1457                         DrawNumIcon(pos, mySize, x, biggercount, 0, iconalign, HUD_Get_Num_Color(x, maxtotal), 1);
1458
1459                 if(fuel)
1460                 {
1461                         HUD_Panel_GetProgressBarColor(fuel);
1462                         HUD_Panel_DrawProgressBar(pos, eX * mySize_x + eY * 0.2 * mySize_y, "progressbar", fuel/100, 0, (baralign == 1 || baralign == 3), progressbar_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
1463                 }
1464         }
1465         else
1466         {
1467                 float panel_ar = mySize_x/mySize_y;
1468                 float is_vertical = (panel_ar < 1);
1469                 vector health_offset = '0 0 0', armor_offset = '0 0 0';
1470                 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
1471                 {
1472                         mySize_x *= 0.5;
1473                         if (autocvar_hud_panel_healtharmor_flip)
1474                                 health_offset_x = mySize_x;
1475                         else
1476                                 armor_offset_x = mySize_x;
1477                 }
1478                 else
1479                 {
1480                         mySize_y *= 0.5;
1481                         if (autocvar_hud_panel_healtharmor_flip)
1482                                 health_offset_y = mySize_y;
1483                         else
1484                                 armor_offset_y = mySize_y;
1485                 }
1486
1487                 float health_baralign, armor_baralign, fuel_baralign;
1488                 float health_iconalign, armor_iconalign;
1489                 if (autocvar_hud_panel_healtharmor_flip)
1490                 {
1491                         armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1);
1492                         health_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1);
1493                         fuel_baralign = health_baralign;
1494                         armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1);
1495                         health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1);
1496                 }
1497                 else
1498                 {
1499                         health_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1);
1500                         armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1);
1501                         fuel_baralign = armor_baralign;
1502                         health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1);
1503                         armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1);
1504                 }
1505
1506                 //if(health)
1507                 {
1508                         if(autocvar_hud_panel_healtharmor_progressbar)
1509                         {
1510                                 HUD_Panel_GetProgressBarColor(health);
1511                                 float p_health, pain_health_alpha;
1512                                 p_health = health;
1513                                 pain_health_alpha = 1;
1514                                 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
1515                                 {
1516                                         if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0)
1517                                         {
1518                                                 if (fabs(prev_health - health) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth)
1519                                                 {
1520                                                         if (time - old_p_healthtime < 1)
1521                                                                 old_p_health = prev_p_health;
1522                                                         else
1523                                                                 old_p_health = prev_health;
1524                                                         old_p_healthtime = time;
1525                                                 }
1526                                                 if (time - old_p_healthtime < 1)
1527                                                 {
1528                                                         p_health += (old_p_health - health) * (1 - (time - old_p_healthtime));
1529                                                         prev_p_health = p_health;
1530                                                 }
1531                                         }
1532                                         if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0)
1533                                         {
1534                                                 if (prev_health - health >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
1535                                                 {
1536                                                         if (time - health_damagetime >= 1)
1537                                                                 health_beforedamage = prev_health;
1538                                                         health_damagetime = time;
1539                                                 }
1540                                                 if (time - health_damagetime < 1)
1541                                                 {
1542                                                         float health_damagealpha = 1 - (time - health_damagetime)*(time - health_damagetime);
1543                                                         HUD_Panel_DrawProgressBar(pos + health_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_health, health_beforedamage/maxhealth, is_vertical, health_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * health_damagealpha, DRAWFLAG_NORMAL);
1544                                                 }
1545                                         }
1546                                         prev_health = health;
1547
1548                                         if (health <= autocvar_hud_panel_healtharmor_progressbar_gfx_lowhealth)
1549                                         {
1550                                                 float BLINK_FACTOR = 0.15;
1551                                                 float BLINK_BASE = 0.85;
1552                                                 float BLINK_FREQ = 9; 
1553                                                 pain_health_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ);
1554                                         }
1555                                 }
1556                                 HUD_Panel_DrawProgressBar(pos + health_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_health, p_health/maxhealth, is_vertical, health_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * pain_health_alpha, DRAWFLAG_NORMAL);
1557                         }
1558                         if(autocvar_hud_panel_healtharmor_text)
1559                                 DrawNumIcon(pos + health_offset, mySize, health, "health", is_vertical, health_iconalign, HUD_Get_Num_Color(health, maxhealth), 1);
1560                 }
1561
1562                 if(armor)
1563                 {
1564                         if(autocvar_hud_panel_healtharmor_progressbar)
1565                         {
1566                                 HUD_Panel_GetProgressBarColor(armor);
1567                                 float p_armor;
1568                                 p_armor = armor;
1569                                 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
1570                                 {
1571                                         if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0)
1572                                         {
1573                                                 if (fabs(prev_armor - armor) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth)
1574                                                 {
1575                                                         if (time - old_p_armortime < 1)
1576                                                                 old_p_armor = prev_p_armor;
1577                                                         else
1578                                                                 old_p_armor = prev_armor;
1579                                                         old_p_armortime = time;
1580                                                 }
1581                                                 if (time - old_p_armortime < 1)
1582                                                 {
1583                                                         p_armor += (old_p_armor - armor) * (1 - (time - old_p_armortime));
1584                                                         prev_p_armor = p_armor;
1585                                                 }
1586                                         }
1587                                         if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0)
1588                                         {
1589                                                 if (prev_armor - armor >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
1590                                                 {
1591                                                         if (time - armor_damagetime >= 1)
1592                                                                 armor_beforedamage = prev_armor;
1593                                                         armor_damagetime = time;
1594                                                 }
1595                                                 if (time - armor_damagetime < 1)
1596                                                 {
1597                                                         float armor_damagealpha = 1 - (time - armor_damagetime)*(time - armor_damagetime);
1598                                                         HUD_Panel_DrawProgressBar(pos + armor_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, armor_beforedamage/maxarmor, is_vertical, armor_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * armor_damagealpha, DRAWFLAG_NORMAL);
1599                                                 }
1600                                         }
1601                                         prev_armor = armor;
1602                                 }
1603                                 HUD_Panel_DrawProgressBar(pos + armor_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, p_armor/maxarmor, is_vertical, armor_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
1604                         }
1605                         if(autocvar_hud_panel_healtharmor_text)
1606                                 DrawNumIcon(pos + armor_offset, mySize, armor, "armor", is_vertical, armor_iconalign, HUD_Get_Num_Color(armor, maxarmor), 1);
1607                 }
1608
1609                 if(fuel)
1610                 {
1611                         if (is_vertical)
1612                                 mySize_x *= 0.2 / 2; //if vertical always halve x to not cover too much numbers with 3 digits
1613                         else
1614                                 mySize_y *= 0.2;
1615                         if (panel_ar >= 4)
1616                                 mySize_x *= 2; //restore full panel size
1617                         else if (panel_ar < 1/4)
1618                                 mySize_y *= 2; //restore full panel size
1619                         HUD_Panel_GetProgressBarColor(fuel);
1620                         HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", fuel/100, is_vertical, fuel_baralign, progressbar_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
1621                 }
1622         }
1623 }
1624
1625 // Notification area (#4)
1626 //
1627
1628 string Weapon_SuicideMessage(float deathtype)
1629 {
1630         w_deathtype = deathtype;
1631         get_weaponinfo(DEATH_WEAPONOF(deathtype)).weapon_func(WR_SUICIDEMESSAGE);
1632         return w_deathtypestring;
1633 }
1634
1635 string Weapon_KillMessage(float deathtype)
1636 {
1637         w_deathtype = deathtype;
1638         get_weaponinfo(DEATH_WEAPONOF(deathtype)).weapon_func(WR_KILLMESSAGE);
1639         return w_deathtypestring;
1640 }
1641
1642
1643 void HUD_KillNotify(string s1, string s2, string s3, float type, float msg) // s1 = attacker, s2 = victim
1644 {
1645         /*
1646         float w;
1647         float alsoprint, gentle;
1648         alsoprint = (autocvar_hud_panel_notify_print || !panel_enabled); // print message to console if: notify panel disabled, or cvar to do so enabled
1649         gentle = (autocvar_cl_gentle || autocvar_cl_gentle_messages);
1650         
1651         if ((msg == MSG_SUICIDE || msg == MSG_KILL || msg == MSG_KILL_ACTION) && gametype == MAPINFO_TYPE_CTS) // selfkill isn't interesting in CTS and only spams up the notify panel
1652                 return;
1653
1654         if(msg == MSG_SUICIDE) {
1655                 w = DEATH_WEAPONOF(type);
1656                 if(WEP_VALID(w)) {
1657                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1658                         if (alsoprint)
1659                                 print("^1", sprintf(Weapon_SuicideMessage(type), strcat(s1, "^1")), "\n");
1660                 } else if (type == DEATH_KILL) {
1661                         HUD_KillNotify_Push(s1, "", 0, DEATH_KILL);
1662                         if (alsoprint)
1663                                 print (sprintf(_("^1%s^1 couldn't take it anymore\n"), s1));
1664                 } else if (type == DEATH_ROT) {
1665                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1666                         if (alsoprint)
1667                                 print (sprintf(_("^1%s^1 died\n"), s1));
1668                 } else if (type == DEATH_NOAMMO) {
1669                         HUD_KillNotify_Push(s1, "", 0, DEATH_NOAMMO);
1670                         if (alsoprint)
1671                                 print (sprintf(_("^7%s^7 committed suicide. What's the point of living without ammo?\n"), s1));
1672                 } else if (type == DEATH_CAMP) {
1673                         HUD_KillNotify_Push(s1, "", 0, DEATH_CAMP);
1674                         if (alsoprint)
1675                                 print (sprintf(_("^1%s^1 thought they found a nice camping ground\n"), s1));
1676                 } else if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
1677                         HUD_KillNotify_Push(s1, "", 0, type);
1678                         if (alsoprint)
1679                                 print (sprintf(_("^1%s^1 didn't become friends with the Lord of Teamplay\n"), s1));
1680                 } else if (type == DEATH_CHEAT) {
1681                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1682                         if (alsoprint)
1683                                 print (sprintf(_("^1%s^1 unfairly eliminated themself\n"), s1));
1684                 } else if (type == DEATH_FIRE) {
1685                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1686                         if (alsoprint)
1687                                 print (sprintf(_("^1%s^1 burned to death\n"), s1));
1688                 } else if (type != DEATH_TEAMCHANGE && type != DEATH_QUIET) {
1689                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1690                         if (alsoprint)
1691                                 print (sprintf(_("^1%s^1 couldn't resist the urge to self-destruct\n"), s1));
1692                 } 
1693                 
1694                 if (stof(s2) > 2) // killcount > 2
1695                         print (sprintf(_("^1%s^1 ended it all after a %d kill spree\n"), s1, stof(s2)));
1696         } else if(msg == MSG_KILL) {
1697                 w = DEATH_WEAPONOF(type);
1698                 if(WEP_VALID(w)) {
1699                         HUD_KillNotify_Push(s1, s2, 1, type);
1700                         if (alsoprint)
1701                                 print("^1", sprintf(Weapon_KillMessage(type), strcat(s2, "^1"), strcat(s1, "^1")), "\n"); // default order: victim, killer
1702                 }
1703                 else if(type == KILL_TEAM_RED || type == KILL_TEAM_BLUE || type == KILL_TEAM_SPREE) {
1704                         HUD_KillNotify_Push(s1, s2, 1, type);
1705                         if(alsoprint)
1706                         {
1707                                 if(gentle) {
1708                                         print (sprintf(_("^1%s^1 took action against a team mate\n"), s1));
1709                                 } else {
1710                                         print (sprintf(_("^1%s^1 mows down a team mate\n"), s1));
1711                                 }
1712                         }
1713                         if (stof(s2) > 2 && type == KILL_TEAM_SPREE) {
1714                                 if(gentle)
1715                                         print (sprintf(_("^1%s^1 ended a %d scoring spree by going against a team mate\n"), s1, stof(s3)));
1716                                 else
1717                                         print (sprintf(_("^1%s^1 ended a %d kill spree by killing a team mate\n"), s1, stof(s3)));
1718                         }
1719                         else if (stof(s2) > 2) {
1720                                 if(gentle)
1721                                         print (sprintf(_("^1%s^1's %s scoring spree was ended by a team mate!\n"), s1, stof(s3)));
1722                                 else
1723                                         print (sprintf(_("^1%s^1's %s kill spree was ended by a team mate!\n"), s1, stof(s3)));
1724                         }
1725                 }
1726                 else if(type == KILL_FIRST_BLOOD)
1727                         print(sprintf(_("^1%s^1 drew first blood\n"), s1));
1728                 else if (type == DEATH_TELEFRAG) {
1729                         HUD_KillNotify_Push(s1, s2, 1, DEATH_TELEFRAG);
1730                         if(gentle)
1731                                 print (sprintf(_("^1%s^1 tried to occupy %s^1's teleport destination space\n"), s2, s1));
1732                         else
1733                                 print (sprintf(_("^1%s^1 was telefragged by %s\n"), s2, s1));
1734                 }
1735                 else if (type == DEATH_DROWN) {
1736                         HUD_KillNotify_Push(s1, s2, 1, DEATH_DROWN);
1737                         if(alsoprint)
1738                                 print (sprintf(_("^1%s^1 was drowned by %s\n"), s2, s1));
1739                 }
1740                 else if (type == DEATH_SLIME) {
1741                         HUD_KillNotify_Push(s1, s2, 1, DEATH_SLIME);
1742                         if(alsoprint)
1743                                 print (sprintf(_("^1%s^1 was slimed by %s\n"), s2, s1));
1744                 }
1745                 else if (type == DEATH_LAVA) {
1746                         HUD_KillNotify_Push(s1, s2, 1, DEATH_LAVA);
1747                         if(alsoprint)
1748                                 print (sprintf(_("^1%s^1 was cooked by %s\n"), s2, s1));
1749                 }
1750                 else if (type == DEATH_FALL) {
1751                         HUD_KillNotify_Push(s1, s2, 1, DEATH_FALL);
1752                         if(alsoprint)
1753                                 print (sprintf(_("^1%s^1 was grounded by %s\n"), s2, s1));
1754                 }
1755                 else if (type == DEATH_SHOOTING_STAR) {
1756                         HUD_KillNotify_Push(s1, s2, 1, DEATH_SHOOTING_STAR);
1757                         if(alsoprint)
1758                                 print (sprintf(_("^1%s^1 was shot into space by %s\n"), s2, s1));
1759                 }
1760                 else if (type == DEATH_SWAMP) {
1761                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1762                         if(alsoprint)
1763                                 print (sprintf(_("^1%s^1 was conserved by %s\n"), s2, s1));
1764                 }
1765                 else if (type == DEATH_HURTTRIGGER)
1766                 {
1767                         HUD_KillNotify_Push(s1, s2, 1, DEATH_HURTTRIGGER);
1768                         if(alsoprint)
1769                                 print(sprintf(_("^1%s^1 was thrown into a world of hurt by %s\n"), s2, s1));
1770                 } else if(type == DEATH_VHCRUSH) {
1771                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1772                         if(alsoprint)
1773                                 print (sprintf(_("^1%s^1 was crushed by %s\n"), s2, s1));
1774                 } else if(type == DEATH_SBMINIGUN) {
1775                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1776                         if(alsoprint)
1777                                 print (sprintf(_("^1%s^1 got shredded by %s\n"), s2, s1));
1778                 } else if(type == DEATH_SBROCKET) {
1779                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1780                         if(alsoprint)
1781                                 print (sprintf(_("^1%s^1 was blasted to bits by %s\n"), s2, s1));
1782                 } else if(type == DEATH_SBBLOWUP) {
1783                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1784                         if(alsoprint)
1785                                 print (sprintf(_("^1%s^1 got caught in the blast when %s^1's destroys a vehicle\n"), s2, s1));
1786                 } else if(type == DEATH_WAKIGUN) {
1787                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1788                         if(alsoprint)
1789                                 print (sprintf(_("^1%s^1 was bolted down by %s\n"), s2, s1));
1790                 } else if(type == DEATH_BUMB_GUN) {
1791                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1792                         if(alsoprint)
1793                                 print (sprintf(_("^1%s^1 saw %s's preddy lights.\n"), s2, s1));
1794                 } else if(type == DEATH_WAKIROCKET) {
1795                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1796                         if(alsoprint)
1797                                 print (sprintf(_("^1%s^1 could find no shelter from %s^1's rockets\n"), s2, s1));
1798                 } else if(type == DEATH_WAKIBLOWUP) {
1799                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1800                         if(alsoprint)
1801                                 print (sprintf(_("^1%s^1 got caught in the blast when %s^1's destroys a vehicle\n"), s2, s1));
1802                 } else if(type == DEATH_RAPTOR_CANNON) {
1803                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1804                         if(alsoprint)
1805                                 print (sprintf(_("^1%s^1 nailed to hell by %s\n"), s2, s1));
1806                 } else if(type == DEATH_RAPTOR_BOMB) {
1807                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1808                         if(alsoprint)
1809                                 print (sprintf(_("^1%s^1 cluster crushed by %s\n"), s2, s1));
1810                 } else if(type == DEATH_RAPTOR_DEATH) {
1811                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1812                         if(alsoprint)
1813                                 print (sprintf(_("^1%s^1 got caught in the blast when %s^1's destroys a vehicle\n"), s2, s1));
1814                 } else if(type == DEATH_TURRET) {
1815                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1816                         if(alsoprint)
1817                                 print (sprintf(_("^1%s^1 was pushed into the line of fire by %s\n"), s2, s1));
1818                 } else if(type == DEATH_TOUCHEXPLODE) {
1819                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1820                         if(alsoprint)
1821                                 print (sprintf(_("^1%s^1 was pushed into an accident by %s\n"), s2, s1));
1822                 } else if(type == DEATH_CHEAT) {
1823                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1824                         if(alsoprint)
1825                                 print (sprintf(_("^1%s^1 was unfairly eliminated by %s\n"), s2, s1));
1826                 } else if (type == DEATH_FIRE) {
1827                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1828                         if(alsoprint)
1829                                 print (sprintf(_("^1%s^1 was burnt to death by %s\n"), s2, s1));
1830                 } else if (type == DEATH_CUSTOM) {
1831                         HUD_KillNotify_Push(s1, s2, 1, DEATH_CUSTOM);
1832                         if(alsoprint)
1833                                 print("^1", sprintf(s3, strcat(s2, "^1"), strcat(s1, "^1")), "\n");
1834                 } else if (type == DEATH_HURTTRIGGER) {
1835                         HUD_KillNotify_Push(s1, s2, 1, DEATH_HURTTRIGGER);
1836                         if(alsoprint)
1837                                 print("^1", sprintf(s3, strcat(s2, "^1"), strcat(s1, "^1")), "\n");
1838                 } else {
1839                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1840                         if(alsoprint)
1841                                 print (sprintf(_("^1%s^1 was fragged by %s\n"), s2, s1));
1842                 }
1843         } else if(msg == MSG_SPREE) {
1844                 if(type == KILL_END_SPREE) {
1845                         if(gentle)
1846                                 print (sprintf(_("^1%s^1's %s scoring spree was ended by %s\n"), s1, s2, s3));
1847                         else
1848                                 print (sprintf(_("^1%s^1's %s kill spree was ended by %s\n"), s1, s2, s3));
1849                 } else if(type == KILL_SPREE) {
1850                         if(gentle)
1851                                 print (sprintf(_("^1%s^1 made %s scores in a row\n"), s1, s2));
1852                         else
1853                                 print (sprintf(_("^1%s^1 has %s frags in a row\n"), s1, s2));
1854                 } else if(type == KILL_SPREE_3) {
1855                         if(gentle)
1856                                 print (sprintf(_("%s^7 made a ^1TRIPLE SCORE\n"), s1));
1857                         else
1858                                 print (sprintf(_("%s^7 made a ^1TRIPLE FRAG\n"), s1));
1859                 } else if(type == KILL_SPREE_5) {
1860                         if(gentle)
1861                                 print (sprintf(_("%s^7 unleashes ^1SCORING RAGE\n"), s1));
1862                         else
1863                                 print (sprintf(_("%s^7 unleashes ^1RAGE\n"), s1));
1864                 } else if(type == KILL_SPREE_10) {
1865                         if(gentle)
1866                                 print (sprintf(_("%s^7 made ^1TEN SCORES IN A ROW!\n"), s1));
1867                         else
1868                                 print (sprintf(_("%s^7 starts the ^1MASSACRE!\n"), s1));
1869                 } else if(type == KILL_SPREE_15) {
1870                         if(gentle)
1871                                 print (sprintf(_("%s^7 made ^1FIFTEEN SCORES IN A ROW!\n"), s1));
1872                         else
1873                                 print (sprintf(_("%s^7 executes ^1MAYHEM!\n"), s1));
1874                 } else if(type == KILL_SPREE_20) {
1875                         if(gentle)
1876                                 print (sprintf(_("%s^7 made ^1TWENTY SCORES IN A ROW!\n"), s1));
1877                         else
1878                                 print (sprintf(_("%s^7 is a ^1BERSERKER!\n"), s1));
1879                 } else if(type == KILL_SPREE_25) {
1880                         if(gentle)
1881                                 print (sprintf(_("%s^7 made ^1TWENTY FIVE SCORES IN A ROW!\n"), s1));
1882                         else
1883                                 print (sprintf(_("%s^7 inflicts ^1CARNAGE!\n"), s1));
1884                 } else if(type == KILL_SPREE_30) {
1885                         if(gentle)
1886                                 print (sprintf(_("%s^7 made ^1THIRTY SCORES IN A ROW!\n"), s1));
1887                         else
1888                                 print (sprintf(_("%s^7 unleashes ^1ARMAGEDDON!\n"), s1));
1889                 }
1890         } else if(msg == MSG_KILL_ACTION) { // wtf is this? isnt it basically the same as MSG_SUICIDE?
1891                 if (type == DEATH_DROWN) {
1892                         HUD_KillNotify_Push(s1, "", 0, DEATH_DROWN);
1893                         if(alsoprint)
1894                         {
1895                                 if(gentle)
1896                                         print (sprintf(_("^1%s^1 was in the water for too long\n"), s1));
1897                                 else
1898                                         print (sprintf(_("^1%s^1 drowned\n"), s1));
1899                         }
1900                 } else if (type == DEATH_SLIME) {
1901                         HUD_KillNotify_Push(s1, "", 0, DEATH_SLIME);
1902                         if(alsoprint)
1903                                 print (sprintf(_("^1%s^1 was slimed\n"), s1));
1904                 } else if (type == DEATH_LAVA) {
1905                         HUD_KillNotify_Push(s1, "", 0, DEATH_LAVA);
1906                         if(alsoprint)
1907                         {
1908                                 if(gentle)
1909                                         print (sprintf(_("^1%s^1 found a hot place\n"), s1));
1910                                 else
1911                                         print (sprintf(_("^1%s^1 turned into hot slag\n"), s1));
1912                         }
1913                 } else if (type == DEATH_FALL) {
1914                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1915                         if(alsoprint)
1916                         {
1917                                 if(gentle)
1918                                         print (sprintf(_("^1%s^1 tested gravity (and it worked)\n"), s1));
1919                                 else
1920                                         print (sprintf(_("^1%s^1 hit the ground with a crunch\n"), s1));
1921                         }
1922                 } else if (type == DEATH_SHOOTING_STAR) {
1923                         HUD_KillNotify_Push(s1, "", 0, DEATH_SHOOTING_STAR);
1924                         if(alsoprint)
1925                                 print (sprintf(_("^1%s^1 became a shooting star\n"), s1));
1926                 } else if (type == DEATH_SWAMP) {
1927                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1928                         if(alsoprint)
1929                         {
1930                                 if(gentle)
1931                                         print (sprintf(_("^1%s^1 discovered a swamp\n"), s1));
1932                                 else
1933                                         print (sprintf(_("^1%s^1 is now conserved for centuries to come\n"), s1));
1934                         }
1935                 } else if(DEATH_ISTURRET(type)) {
1936                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1937                         if(alsoprint)
1938                         {
1939                                 if(gentle)
1940                                         print (sprintf(_("^1%s^1 ran into a turret\n"), s1));
1941                                 else
1942                                 {
1943                                         switch(type)
1944                                         {
1945                                                 case DEATH_TURRET_EWHEEL:
1946                                                         print (sprintf(_("^1%s^1 was laserd down by a eWheel turret \n"), s1));
1947                                                         break;
1948                                                 case DEATH_TURRET_FLAC:
1949                                                         print (sprintf(_("^1%s^1 got caught in the flac \n"), s1));
1950                                                         break;
1951                                                 case DEATH_TURRET_MACHINEGUN:
1952                                                         print (sprintf(_("^1%s^1 was riddeld full of riddled by a machinegun turret \n"), s1));
1953                                                         break;
1954                                                 case DEATH_TURRET_WALKER_GUN:
1955                                                         print (sprintf(_("^1%s^1 got served a led enrichment by a walker turret \n"), s1));
1956                                                         break;
1957                                                 case DEATH_TURRET_WALKER_MEELE:
1958                                                         print (sprintf(_("^1%s^1 was impaled by a walker turret \n"), s1));
1959                                                         break;
1960                                                 case DEATH_TURRET_WALKER_ROCKET:
1961                                                         print (sprintf(_("^1%s^1 was rocketed to hell by a walker turret \n"), s1));
1962                                                         break;
1963                                                 case DEATH_TURRET_HELLION:
1964                                                         print (sprintf(_("^1%s^1 was blasted away hellion turret \n"), s1));
1965                                                         break;
1966                                                 case DEATH_TURRET_HK:
1967                                                         print (sprintf(_("^1%s^1 could not hide from the hunter turret \n"), s1));
1968                                                         break;
1969                                                 case DEATH_TURRET_MLRS:
1970                                                         print (sprintf(_("^1%s^1 got turned into smoldering gibs by a mlrs turret \n"), s1));
1971                                                         break;
1972                                                 case DEATH_TURRET_PLASMA:
1973                                                         print (sprintf(_("^1%s^1 got served some superheated plasma from a plasma turret \n"), s1));
1974                                                         break;
1975                                                 case DEATH_TURRET_PHASER:
1976                                                         print (sprintf(_("^1%s^1 was phased out \n"), s1));
1977                                                         break;
1978                                                 case DEATH_TURRET_TESLA:                        
1979                                                         print (sprintf(_("^1%s^1 was electrocuted by a tesla turret \n"), s1));
1980                                                         break;
1981                                         }
1982                                 }
1983                         }
1984                 } else if (type == DEATH_CUSTOM) {
1985                         HUD_KillNotify_Push(s1, "", 0, DEATH_CUSTOM);
1986                         if(alsoprint)
1987                                 print("^1", sprintf(s2, strcat(s1, "^1")), "\n");
1988                 } else if (type == DEATH_HURTTRIGGER) {
1989                         HUD_KillNotify_Push(s1, "", 0, DEATH_HURTTRIGGER);
1990                         if(alsoprint)
1991                                 print("^1", sprintf(s2, strcat(s1, "^1")), "\n");
1992                 } else if(type == DEATH_TOUCHEXPLODE) {
1993                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1994                         if(alsoprint)
1995                                 print (sprintf(_("^1%s^1 died in an accident\n"), s1));
1996                 } else if(type == DEATH_CHEAT) {
1997                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1998                         if(alsoprint)
1999                                 print (sprintf(_("^1%s^1 was unfairly eliminated\n"), s1));
2000                 } else if(type == DEATH_FIRE) {
2001                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2002                         if(alsoprint)
2003                         {
2004                                 if(gentle)
2005                                         print (sprintf(_("^1%s^1 felt a little hot\n"), s1));
2006                                 else
2007                                         print (sprintf(_("^1%s^1 burnt to death\n"), s1));
2008                                 }
2009                 } else {
2010                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2011                         if(alsoprint)
2012                         {
2013                                 if(gentle)
2014                                         print (sprintf(_("^1%s^1 needs a restart\n"), s1));
2015                                 else
2016                                         print (sprintf(_("^1%s^1 died\n"), s1));
2017                         }
2018                 }
2019         } else if(msg == MSG_KILL_ACTION_SPREE) {
2020                 if(gentle)
2021                         print (sprintf(_("^1%s^1 needs a restart after a %d scoring spree\n"), s1, stof(s2)));
2022                 else
2023                         print (sprintf(_("^1%s^1 died with a %d kill spree\n"), s1, stof(s2)));
2024         } else if(msg == MSG_INFO) {
2025                 if(type == INFO_GOTFLAG) { // here, s2 is the flag name
2026                         HUD_KillNotify_Push(s1, s2, 0, INFO_GOTFLAG);
2027                         print(sprintf(_("%s^7 got the %s\n"), s1, s2));
2028                 } else if(type == INFO_LOSTFLAG) {
2029                         HUD_KillNotify_Push(s1, s2, 0, INFO_LOSTFLAG);
2030                         print(sprintf(_("%s^7 lost the %s\n"), s1, s2));
2031                 } else if(type == INFO_PICKUPFLAG) {
2032                         HUD_KillNotify_Push(s1, s2, 0, INFO_GOTFLAG);
2033                         print(sprintf(_("%s^7 picked up the %s\n"), s1, s2));
2034                 } else if(type == INFO_RETURNFLAG) {
2035                         HUD_KillNotify_Push(s1, s2, 0, INFO_RETURNFLAG);
2036                         print(sprintf(_("%s^7 returned the %s\n"), s1, s2));
2037                 } else if(type == INFO_CAPTUREFLAG) {
2038                         HUD_KillNotify_Push(s1, s2, 0, INFO_CAPTUREFLAG);
2039                         print(sprintf(_("%s^7 captured the %s%s\n"), s1, s2, s3));
2040                 }
2041         } else if(msg == MSG_RACE) {
2042                 if(type == RACE_SERVER_RECORD) {
2043                         HUD_KillNotify_Push(s1, s2, 1, RACE_SERVER_RECORD);
2044                 }
2045                 else if(type == RACE_NEW_RANK) {
2046                         HUD_KillNotify_Push(s1, s2, 1, RACE_NEW_RANK);
2047                 }
2048                 else if(type == RACE_NEW_TIME) {
2049                         HUD_KillNotify_Push(s1, s2, 1, RACE_NEW_TIME);
2050                 }
2051                 else if(type == RACE_FAIL) {
2052                         HUD_KillNotify_Push(s1, s2, 1, RACE_FAIL);
2053                 }
2054         } else if(msg == MSG_KA) {
2055                 if(type == KA_PICKUPBALL) {
2056                         HUD_KillNotify_Push(s1, s2, 0, KA_PICKUPBALL);
2057                         if(alsoprint)
2058                                 print (sprintf(_("%s^7 has picked up the ball!\n"), s1));
2059                 }
2060                 else if(type == KA_DROPBALL) {
2061                         HUD_KillNotify_Push(s1, s2, 0, KA_DROPBALL);
2062                         if(alsoprint)
2063                                 print(sprintf(_("%s^7 has dropped the ball!\n"), s1));
2064                 }
2065         }*/
2066 }
2067
2068 void HUD_Notify(void)
2069 {
2070         if(!autocvar__hud_configure)
2071         {
2072                 if(!autocvar_hud_panel_notify) return;
2073         }
2074         else
2075                 hud_configure_active_panel = HUD_PANEL_NOTIFY;
2076
2077         HUD_Panel_UpdateCvars(notify);
2078         HUD_Panel_ApplyFadeAlpha();
2079         vector pos, mySize;
2080         pos = panel_pos;
2081         mySize = panel_size;
2082
2083         HUD_Panel_DrawBg(1);
2084         if(panel_bg_padding)
2085         {
2086                 pos += '1 1 0' * panel_bg_padding;
2087                 mySize -= '2 2 0' * panel_bg_padding;
2088         }
2089
2090         float entries, height;
2091         entries = bound(1, floor(KN_MAX_ENTRIES * mySize_y/mySize_x), KN_MAX_ENTRIES);
2092         height = mySize_y/entries;
2093         
2094         vector fontsize;
2095         float fontheight = height * autocvar_hud_panel_notify_fontsize;
2096         fontsize = '0.5 0.5 0' * fontheight;
2097
2098         float a;
2099         float when;
2100         when = autocvar_hud_panel_notify_time;
2101         float fadetime;
2102         fadetime = autocvar_hud_panel_notify_fadetime;
2103
2104         vector pos_attacker, pos_victim, pos_icon;
2105         float width_attacker;
2106         string attacker, victim, icon;
2107
2108         float i, j, step, limit;
2109         if(autocvar_hud_panel_notify_flip) //order items from the top down
2110         {
2111                 i = 0;
2112                 step = +1;
2113                 limit = entries;
2114         }
2115         else //order items from the bottom up
2116         {
2117                 i = entries - 1;
2118                 step = -1;
2119                 limit = -1;
2120         }
2121
2122         for(j = kn_index;  i != limit;  i += step, ++j)
2123         {
2124                 if(autocvar__hud_configure)
2125                 {
2126                         if (step == +1)
2127                                 a = i;
2128                         else // inverse order
2129                                 a = entries - 1 - i;
2130                         attacker = textShortenToWidth(sprintf(_("Player %d"), a+1), 0.48 * mySize_x - height, fontsize, stringwidth_colors);
2131                         victim = textShortenToWidth(sprintf(_("Player %d"), a+2), 0.48 * mySize_x - height, fontsize, stringwidth_colors);
2132                         icon = strcat("weapon", get_weaponinfo(WEP_FIRST + mod(floor(a*2.4), WEP_LAST)).netname);
2133                         a = bound(0, (when - a) / 4, 1);
2134                         goto hud_config_notifyprint;
2135                 }
2136                 else
2137                 {
2138                         if (j == KN_MAX_ENTRIES)
2139                                 j = 0;
2140
2141                         if(killnotify_times[j] + when > time)
2142                                 a = 1;
2143                         else if(fadetime)
2144                         {
2145                                 a = bound(0, (killnotify_times[j] + when + fadetime - time) / fadetime, 1);
2146                                 if(!a)
2147                                 {
2148                                         break;
2149                                 }
2150                         }
2151                         else
2152                         {
2153                                 break;
2154                         }
2155                         
2156                         attacker = killnotify_attackers[j];
2157                         victim = killnotify_victims[j];
2158                         icon = killnotify_icon[j];
2159                 }
2160
2161                 //type = killnotify_deathtype[j];
2162                 //w = DEATH_WEAPONOF(type);
2163
2164                 if(icon != "")
2165                 {
2166                         if((attacker != "") && (victim == ""))
2167                         {
2168                                 // Y [used by] X
2169                                 attacker = textShortenToWidth(attacker, 0.73 * mySize_x - height, fontsize, stringwidth_colors);
2170                                 pos_attacker = pos + eX * (0.27 * mySize_x + height) + eY * ((0.5 * fontsize_y + i * height) + (0.5 * (height - fontheight)));
2171                                 pos_icon = pos + eX * 0.25 * mySize_x - eX * height + eY * i * height;
2172
2173                                 drawpic_aspect_skin(pos_icon, icon, '2 1 0' * height, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
2174                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2175                         }
2176                         else if((attacker != "") && (victim != ""))
2177                         {
2178                                 // X [did action to] Y
2179                                 attacker = textShortenToWidth(attacker, 0.48 * mySize_x - height, fontsize, stringwidth_colors);
2180                                 victim = textShortenToWidth(victim, 0.48 * mySize_x - height, fontsize, stringwidth_colors);
2181 :hud_config_notifyprint
2182                                 width_attacker = stringwidth(attacker, TRUE, fontsize);
2183                                 pos_attacker = pos + eX * (0.48 * mySize_x - height - width_attacker) + eY * ((0.5 * fontsize_y + i * height) + (0.5 * (height - fontheight)));
2184                                 pos_victim = pos + eX * (0.52 * mySize_x + height) + eY * ((0.5 * fontsize_y + i * height) + (0.5 * (height - fontheight)));
2185                                 pos_icon = pos + eX * 0.5 * mySize_x - eX * height + eY * i * height;
2186
2187                                 drawpic_aspect_skin(pos_icon, icon, '2 1 0' * height, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
2188                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2189                                 drawcolorcodedstring(pos_victim, victim, fontsize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2190                         }
2191                 }
2192         }
2193 }
2194
2195 // Timer (#5)
2196 //
2197 // TODO: macro
2198 string seconds_tostring(float sec)
2199 {
2200         float minutes;
2201         minutes = floor(sec / 60);
2202
2203         sec -= minutes * 60;
2204         return sprintf("%d:%02d", minutes, sec);
2205 }
2206
2207 void HUD_Timer(void)
2208 {
2209         if(!autocvar__hud_configure)
2210         {
2211                 if(!autocvar_hud_panel_timer) return;
2212         }
2213         else
2214                 hud_configure_active_panel = HUD_PANEL_TIMER;
2215
2216         HUD_Panel_UpdateCvars(timer);
2217         HUD_Panel_ApplyFadeAlpha();
2218
2219         draw_beginBoldFont();
2220
2221         vector pos, mySize;
2222         pos = panel_pos;
2223         mySize = panel_size;
2224
2225         HUD_Panel_DrawBg(1);
2226         if(panel_bg_padding)
2227         {
2228                 pos += '1 1 0' * panel_bg_padding;
2229                 mySize -= '2 2 0' * panel_bg_padding;
2230         }
2231
2232         string timer;
2233         float timelimit, elapsedTime, timeleft, minutesLeft;
2234
2235         timelimit = getstatf(STAT_TIMELIMIT);
2236
2237         timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
2238         timeleft = ceil(timeleft);
2239
2240         minutesLeft = floor(timeleft / 60);
2241
2242         vector timer_color;
2243         if(minutesLeft >= 5 || warmup_stage || timelimit == 0) //don't use red or yellow in warmup or when there is no timelimit
2244                 timer_color = '1 1 1'; //white
2245         else if(minutesLeft >= 1)
2246                 timer_color = '1 1 0'; //yellow
2247         else
2248                 timer_color = '1 0 0'; //red
2249
2250         if (autocvar_hud_panel_timer_increment || timelimit == 0 || warmup_stage) {
2251                 if (time < getstatf(STAT_GAMESTARTTIME)) {
2252                         //while restart is still active, show 00:00
2253                         timer = seconds_tostring(0);
2254                 } else {
2255                         elapsedTime = floor(time - getstatf(STAT_GAMESTARTTIME)); //127
2256                         timer = seconds_tostring(elapsedTime);
2257                 }
2258         } else {
2259                 timer = seconds_tostring(timeleft);
2260         }
2261
2262         drawstring_aspect(pos, timer, mySize, timer_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2263
2264         draw_endBoldFont();
2265 }
2266
2267 // Radar (#6)
2268 //
2269 void HUD_Radar(void)
2270 {
2271         if (!autocvar__hud_configure)
2272         {
2273                 if (hud_panel_radar_maximized)
2274                 {
2275                         if (!hud_draw_maximized) return;
2276                 }
2277                 else
2278                 {
2279                         if (autocvar_hud_panel_radar == 0) return;
2280                         if (autocvar_hud_panel_radar != 2 && !teamplay) return;
2281                 }
2282         }
2283         else
2284                 hud_configure_active_panel = HUD_PANEL_RADAR;
2285
2286         HUD_Panel_UpdateCvars(radar);
2287         HUD_Panel_ApplyFadeAlpha();
2288
2289         if (hud_panel_radar_maximized && !autocvar__hud_configure)
2290         {
2291                 panel_size = autocvar_hud_panel_radar_maximized_size;
2292                 panel_size_x = bound(0.2, panel_size_x, 1) * vid_conwidth;
2293                 panel_size_y = bound(0.2, panel_size_y, 1) * vid_conheight;
2294                 panel_pos_x = (vid_conwidth - panel_size_x) / 2;
2295                 panel_pos_y = (vid_conheight - panel_size_y) / 2;
2296                 
2297                 panel_bg = strcat(hud_skin_path, "/border_default"); // always use the default border when maximized
2298                 if(precache_pic(panel_bg) == "") { panel_bg = "gfx/hud/default/border_default"; } // fallback
2299         }
2300
2301         vector pos, mySize;
2302         pos = panel_pos;
2303         mySize = panel_size;
2304
2305         HUD_Panel_DrawBg(1);
2306         if(panel_bg_padding)
2307         {
2308                 pos += '1 1 0' * panel_bg_padding;
2309                 mySize -= '2 2 0' * panel_bg_padding;
2310         }
2311
2312         float color2;
2313         entity tm;
2314         float scale2d, normalsize, bigsize;
2315         float f;
2316
2317         teamradar_origin2d = pos + 0.5 * mySize;
2318         teamradar_size2d = mySize;
2319
2320         if(minimapname == "")
2321                 return;
2322
2323         teamradar_loadcvars();
2324
2325         switch(hud_panel_radar_zoommode)
2326         {
2327                 default:
2328                 case 0:
2329                         f = current_zoomfraction;
2330                         break;
2331                 case 1:
2332                         f = 1 - current_zoomfraction;
2333                         break;
2334                 case 2:
2335                         f = 0;
2336                         break;
2337                 case 3:
2338                         f = 1;
2339                         break;
2340         }
2341
2342         switch(hud_panel_radar_rotation)
2343         {
2344                 case 0:
2345                         teamradar_angle = view_angles_y - 90;
2346                         break;
2347                 default:
2348                         teamradar_angle = 90 * hud_panel_radar_rotation;
2349                         break;
2350         }
2351
2352         scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
2353         teamradar_size2d = mySize;
2354
2355         teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0'; // we always center
2356
2357         // pixels per world qu to match the teamradar_size2d_x range in the longest dimension
2358         if(hud_panel_radar_rotation == 0)
2359         {
2360                 // max-min distance must fit the radar in any rotation
2361                 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen2d(mi_scale));
2362         }
2363         else
2364         {
2365                 vector c0, c1, c2, c3, span;
2366                 c0 = rotate(mi_min, teamradar_angle * DEG2RAD);
2367                 c1 = rotate(mi_max, teamradar_angle * DEG2RAD);
2368                 c2 = rotate('1 0 0' * mi_min_x + '0 1 0' * mi_max_y, teamradar_angle * DEG2RAD);
2369                 c3 = rotate('1 0 0' * mi_max_x + '0 1 0' * mi_min_y, teamradar_angle * DEG2RAD);
2370                 span = '0 0 0';
2371                 span_x = max(c0_x, c1_x, c2_x, c3_x) - min(c0_x, c1_x, c2_x, c3_x);
2372                 span_y = max(c0_y, c1_y, c2_y, c3_y) - min(c0_y, c1_y, c2_y, c3_y);
2373
2374                 // max-min distance must fit the radar in x=x, y=y
2375                 bigsize = min(
2376                         teamradar_size2d_x * scale2d / (1.05 * span_x),
2377                         teamradar_size2d_y * scale2d / (1.05 * span_y)
2378                 );
2379         }
2380
2381         normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / hud_panel_radar_scale;
2382         if(bigsize > normalsize)
2383                 normalsize = bigsize;
2384
2385         teamradar_size =
2386                   f * bigsize
2387                 + (1 - f) * normalsize;
2388         teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
2389                   f * mi_center
2390                 + (1 - f) * view_origin);
2391
2392         drawsetcliparea(
2393                 pos_x,
2394                 pos_y,
2395                 mySize_x,
2396                 mySize_y
2397         );
2398
2399         draw_teamradar_background(hud_panel_radar_foreground_alpha);
2400
2401         for(tm = world; (tm = find(tm, classname, "radarlink")); )
2402                 draw_teamradar_link(tm.origin, tm.velocity, tm.team);
2403         for(tm = world; (tm = findflags(tm, teamradar_icon, 0xFFFFFF)); )
2404                 draw_teamradar_icon(tm.origin, tm.teamradar_icon, tm, tm.teamradar_color, panel_fg_alpha);
2405         for(tm = world; (tm = find(tm, classname, "entcs_receiver")); )
2406         {
2407                 color2 = GetPlayerColor(tm.sv_entnum);
2408                 //if(color == FL_SPECTATOR || color == color2)
2409                         draw_teamradar_player(tm.origin, tm.angles, Team_ColorRGB(color2));
2410         }
2411         draw_teamradar_player(view_origin, view_angles, '1 1 1');
2412
2413         drawresetcliparea();
2414 };
2415
2416 // Score (#7)
2417 //
2418 void HUD_UpdatePlayerTeams();
2419 void HUD_Score_Rankings(vector pos, vector mySize, entity me, float team_count)
2420 {
2421         float score;
2422         entity tm = world, pl;
2423 #define SCOREPANEL_MAX_ENTRIES 6
2424 #define SCOREPANEL_ASPECTRATIO 2
2425         float entries = bound(1, floor(SCOREPANEL_MAX_ENTRIES * mySize_y/mySize_x * SCOREPANEL_ASPECTRATIO), SCOREPANEL_MAX_ENTRIES);
2426         vector fontsize = '1 1 0' * (mySize_y/entries);
2427
2428         vector rgb, score_color;
2429         rgb = '1 1 1';
2430         score_color = '1 1 1';
2431
2432         float name_size = mySize_x*0.75;
2433         float spacing_size = mySize_x*0.04;
2434         const float highlight_alpha = 0.2;
2435         float i = 0, me_printed = 0, first_pl = 0;
2436         string s;
2437         if (autocvar__hud_configure)
2438         {
2439                 float players_per_team = 0;
2440                 if (team_count)
2441                 {
2442                         // show team scores in the first line
2443                         float score_size = mySize_x / team_count;
2444                         players_per_team = max(2, ceil((entries - 1) / team_count));
2445                         for(i=0; i<team_count; ++i) {
2446                                 if (i == floor((entries - 2) / players_per_team) || (entries == 1 && i == 0))
2447                                         HUD_Panel_DrawHighlight(pos + eX * score_size * i, eX * score_size + eY * fontsize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2448                                 drawstring_aspect(pos + eX * score_size * i, ftos(175 - 23*i), eX * score_size + eY * fontsize_y, Team_ColorRGB(ColorByTeam(i)) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2449                         }
2450                         first_pl = 1;
2451                         pos_y += fontsize_y;
2452                 }
2453                 score = 10 + SCOREPANEL_MAX_ENTRIES * 3;
2454                 for (i=first_pl; i<entries; ++i)
2455                 {
2456                         //simulate my score is lower than all displayed players,
2457                         //so that I don't appear at all showing pure rankings.
2458                         //This is to better show the difference between the 2 ranking views
2459                         if (i == entries-1 && autocvar_hud_panel_score_rankings == 1)
2460                         {
2461                                 rgb = '1 1 0';
2462                                 drawfill(pos, eX * mySize_x + eY * fontsize_y, rgb, highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2463                                 s = GetPlayerName(player_localnum);
2464                                 score = 7;
2465                         }
2466                         else
2467                         {
2468                                 s = sprintf(_("Player %d"), i + 1 - first_pl);
2469                                 score -= 3;
2470                         }
2471
2472                         if (team_count)
2473                                 score_color = Team_ColorRGB(ColorByTeam(floor((i - first_pl) / players_per_team))) * 0.8;
2474                         s = textShortenToWidth(s, name_size, fontsize, stringwidth_colors);
2475                         drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, TRUE, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
2476                         drawstring(pos + eX * (name_size + spacing_size), ftos(score), fontsize, score_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2477                         pos_y += fontsize_y;
2478                 }
2479                 return;
2480         }
2481
2482         if (!scoreboard_fade_alpha) // the scoreboard too calls HUD_UpdatePlayerTeams
2483                 HUD_UpdatePlayerTeams();
2484         if (team_count)
2485         {
2486                 // show team scores in the first line
2487                 float score_size = mySize_x / team_count;
2488                 for(tm = teams.sort_next; tm; tm = tm.sort_next) {
2489                         if(tm.team == FL_SPECTATOR)
2490                                 continue;
2491                         if (tm.team == myteam)
2492                                 drawfill(pos + eX * score_size * i, eX * score_size + eY * fontsize_y, '1 1 1', highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2493                         drawstring_aspect(pos + eX * score_size * i, ftos(tm.(teamscores[ts_primary])), eX * score_size + eY * fontsize_y, Team_ColorRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2494                         ++i;
2495                 }
2496                 first_pl = 1;
2497                 pos_y += fontsize_y;
2498                 tm = teams.sort_next;
2499         }
2500         i = first_pl;
2501
2502         do
2503         for (pl = players.sort_next; pl && i<entries; pl = pl.sort_next)
2504         {
2505                 if ((team_count && pl.team != tm.team) || pl.team == FL_SPECTATOR)
2506                         continue;
2507
2508                 if (i == entries-1 && !me_printed && pl != me)
2509                 if (autocvar_hud_panel_score_rankings == 1 && spectatee_status != -1)
2510                 {
2511                         for (pl = me.sort_next; pl; pl = pl.sort_next)
2512                                 if (pl.team != FL_SPECTATOR)
2513                                         break;
2514
2515                         if (pl)
2516                                 rgb = '1 1 0'; //not last but not among the leading players: yellow
2517                         else
2518                                 rgb = '1 0 0'; //last: red
2519                         pl = me;
2520                 }
2521
2522                 if (pl == me)
2523                 {
2524                         if (i == first_pl)
2525                                 rgb = '0 1 0'; //first: green
2526                         me_printed = 1;
2527                         drawfill(pos, eX * mySize_x + eY * fontsize_y, rgb, highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2528                 }
2529                 if (team_count)
2530                         score_color = Team_ColorRGB(pl.team) * 0.8;
2531                 s = textShortenToWidth(GetPlayerName(pl.sv_entnum), name_size, fontsize, stringwidth_colors);
2532                 drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, TRUE, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
2533                 drawstring(pos + eX * (name_size + spacing_size), ftos(pl.(scores[ps_primary])), fontsize, score_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2534                 pos_y += fontsize_y;
2535                 ++i;
2536         }
2537         while (i<entries && team_count && (tm = tm.sort_next) && (tm.team != FL_SPECTATOR || (tm = tm.sort_next)));
2538 }
2539
2540 void HUD_Score(void)
2541 {
2542         if(!autocvar__hud_configure)
2543         {
2544                 if(!autocvar_hud_panel_score) return;
2545                 if(spectatee_status == -1 && (gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return;
2546         }
2547         else
2548                 hud_configure_active_panel = HUD_PANEL_SCORE;
2549
2550         HUD_Panel_UpdateCvars(score);
2551         HUD_Panel_ApplyFadeAlpha();
2552         vector pos, mySize;
2553         pos = panel_pos;
2554         mySize = panel_size;
2555
2556         HUD_Panel_DrawBg(1);
2557         if(panel_bg_padding)
2558         {
2559                 pos += '1 1 0' * panel_bg_padding;
2560                 mySize -= '2 2 0' * panel_bg_padding;
2561         }
2562
2563         float score, distribution = 0;
2564         string sign;
2565         vector distribution_color;
2566         entity tm, pl, me;
2567
2568 #ifdef COMPAT_XON050_ENGINE
2569         me = (spectatee_status > 0) ? playerslots[spectatee_status - 1] : playerslots[player_localentnum - 1];
2570 #else
2571         me = playerslots[player_localentnum - 1];
2572 #endif
2573
2574         if((scores_flags[ps_primary] & SFL_TIME) && !teamplay) { // race/cts record display on HUD
2575                 string timer, distrtimer;
2576
2577                 pl = players.sort_next;
2578                 if(pl == me)
2579                         pl = pl.sort_next;
2580                 if(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)
2581                         if(pl.scores[ps_primary] == 0)
2582                                 pl = world;
2583
2584                 score = me.(scores[ps_primary]);
2585                 timer = TIME_ENCODED_TOSTRING(score);
2586
2587                 draw_beginBoldFont();
2588                 if (pl && ((!(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)) || score)) {
2589                         // distribution display
2590                         distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
2591
2592                         distrtimer = ftos_decimals(fabs(distribution/pow(10, TIME_DECIMALS)), TIME_DECIMALS);
2593
2594                         if (distribution <= 0) {
2595                                 distribution_color = '0 1 0';
2596                                 sign = "-";
2597                         }
2598                         else {
2599                                 distribution_color = '1 0 0';
2600                                 sign = "+";
2601                         }
2602                         drawstring_aspect(pos + eX * 0.75 * mySize_x, strcat(sign, distrtimer), eX * 0.25 * mySize_x + eY * (1/3) * mySize_y, distribution_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2603                 }
2604                 // race record display
2605                 if (distribution <= 0)
2606                         HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2607                 drawstring_aspect(pos, timer, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2608                 draw_endBoldFont();
2609         } else if (!teamplay) { // non-teamgames
2610                 if ((spectatee_status == -1 && !autocvar__hud_configure) || autocvar_hud_panel_score_rankings)
2611                 {
2612                         HUD_Score_Rankings(pos, mySize, me, 0);
2613                         return;
2614                 }
2615                 // me vector := [team/connected frags id]
2616                 pl = players.sort_next;
2617                 if(pl == me)
2618                         pl = pl.sort_next;
2619
2620                 if(autocvar__hud_configure)
2621                         distribution = 42;
2622                 else if(pl)
2623                         distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
2624                 else
2625                         distribution = 0;
2626
2627                 score = me.(scores[ps_primary]);
2628                 if(autocvar__hud_configure)
2629                         score = 123;
2630
2631                 if(distribution >= 5)
2632                         distribution_color = eY;
2633                 else if(distribution >= 0)
2634                         distribution_color = '1 1 1';
2635                 else if(distribution >= -5)
2636                         distribution_color = '1 1 0';
2637                 else
2638                         distribution_color = eX;
2639
2640                 string distribution_str;
2641                 distribution_str = ftos(distribution);
2642                 draw_beginBoldFont();
2643                 if (distribution >= 0)
2644                 {
2645                         if (distribution > 0)
2646                                 distribution_str = strcat("+", distribution_str);
2647                         HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2648                 }
2649                 drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize_x + eY * mySize_y, distribution_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2650                 drawstring_aspect(pos + eX * 0.75 * mySize_x, distribution_str, eX * 0.25 * mySize_x + eY * (1/3) * mySize_y, distribution_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2651                 draw_endBoldFont();
2652         } else { // teamgames
2653                 float scores_count = 0, row, column, rows = 0, columns = 0;
2654                 local noref vector offset = '0 0 0';
2655                 vector score_pos, score_size; //for scores other than myteam
2656                 if (spectatee_status == -1 || autocvar_hud_panel_score_rankings)
2657                 {
2658                         for(tm = teams.sort_next; tm, tm.team != FL_SPECTATOR; tm = tm.sort_next)
2659                                 ++scores_count;
2660                         if (autocvar_hud_panel_score_rankings)
2661                         {
2662                                 HUD_Score_Rankings(pos, mySize, me, scores_count);
2663                                 return;
2664                         }
2665                         rows = mySize_y/mySize_x;
2666                         rows = bound(1, floor((sqrt(4 * (3/1) * rows * scores_count + rows * rows) + rows + 0.5) / 2), scores_count);
2667                         //                               ^^^ ammo item aspect goes here
2668
2669                         columns = ceil(scores_count/rows);
2670
2671                         score_size = eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows);
2672
2673                         float newSize;
2674                         if(score_size_x/score_size_y > 3)
2675                         {
2676                                 newSize = 3 * score_size_y;
2677                                 offset_x = score_size_x - newSize;
2678                                 pos_x += offset_x/2;
2679                                 score_size_x = newSize;
2680                         }
2681                         else
2682                         {
2683                                 newSize = 1/3 * score_size_x;
2684                                 offset_y = score_size_y - newSize;
2685                                 pos_y += offset_y/2;
2686                                 score_size_y = newSize;
2687                         }
2688                 }
2689                 else
2690                         score_size = eX * mySize_x*(1/4) + eY * mySize_y*(1/3);
2691
2692                 float max_fragcount;
2693                 max_fragcount = -99;
2694                 draw_beginBoldFont();
2695                 row = column = 0;
2696                 for(tm = teams.sort_next; tm; tm = tm.sort_next) {
2697                         if(tm.team == FL_SPECTATOR)
2698                                 continue;
2699                         score = tm.(teamscores[ts_primary]);
2700                         if(autocvar__hud_configure)
2701                                 score = 123;
2702                         
2703                         if (score > max_fragcount)
2704                                 max_fragcount = score;
2705
2706                         if (spectatee_status == -1)
2707                         {
2708                                 score_pos = pos + eX * column * (score_size_x + offset_x) + eY * row * (score_size_y + offset_y);
2709                                 if (max_fragcount == score)
2710                                         HUD_Panel_DrawHighlight(score_pos, score_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2711                                 drawstring_aspect(score_pos, ftos(score), score_size, Team_ColorRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2712                                 ++row;
2713                                 if(row >= rows)
2714                                 {
2715                                         row = 0;
2716                                         ++column;
2717                                 }
2718                         }
2719                         else if(tm.team == myteam) {
2720                                 if (max_fragcount == score)
2721                                         HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2722                                 drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize_x + eY * mySize_y, Team_ColorRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2723                         } else {
2724                                 if (max_fragcount == score)
2725                                         HUD_Panel_DrawHighlight(pos + eX * 0.75 * mySize_x + eY * (1/3) * rows * mySize_y, score_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2726                                 drawstring_aspect(pos + eX * 0.75 * mySize_x + eY * (1/3) * rows * mySize_y, ftos(score), score_size, Team_ColorRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2727                                 ++rows;
2728                         }
2729                 }
2730                 draw_endBoldFont();
2731         }
2732 }
2733
2734 // Race timer (#8)
2735 //
2736 void HUD_RaceTimer (void)
2737 {
2738         if(!autocvar__hud_configure)
2739         {
2740                 if(!autocvar_hud_panel_racetimer) return;
2741                 if(!(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return;
2742                 if(spectatee_status == -1) return;
2743         }
2744         else
2745                 hud_configure_active_panel = HUD_PANEL_RACETIMER;
2746
2747         HUD_Panel_UpdateCvars(racetimer);
2748         HUD_Panel_ApplyFadeAlpha();
2749
2750         draw_beginBoldFont();
2751
2752         vector pos, mySize;
2753         pos = panel_pos;
2754         mySize = panel_size;
2755
2756         HUD_Panel_DrawBg(1);
2757         if(panel_bg_padding)
2758         {
2759                 pos += '1 1 0' * panel_bg_padding;
2760                 mySize -= '2 2 0' * panel_bg_padding;
2761         }
2762
2763         // always force 4:1 aspect
2764         vector newSize = '0 0 0';
2765         if(mySize_x/mySize_y > 4)
2766         {
2767                 newSize_x = 4 * mySize_y;
2768                 newSize_y = mySize_y;
2769
2770                 pos_x = pos_x + (mySize_x - newSize_x) / 2;
2771         }
2772         else
2773         {
2774                 newSize_y = 1/4 * mySize_x;
2775                 newSize_x = mySize_x;
2776
2777                 pos_y = pos_y + (mySize_y - newSize_y) / 2;
2778         }
2779         mySize = newSize;
2780
2781         float a, t;
2782         string s, forcetime;
2783
2784         if(autocvar__hud_configure)
2785         {
2786                 s = "0:13:37";
2787                 drawstring(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(s, FALSE, '0.60 0.60 0' * mySize_y), s, '0.60 0.60 0' * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2788                 s = _("^1Intermediate 1 (+15.42)");
2789                 drawcolorcodedstring(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(s, TRUE, '1 1 0' * 0.20 * mySize_y) + eY * 0.60 * mySize_y, s, '1 1 0' * 0.20 * mySize_y, panel_fg_alpha, DRAWFLAG_NORMAL);
2790                 s = sprintf(_("^1PENALTY: %.1f (%s)"), 2, "missing a checkpoint");
2791                 drawcolorcodedstring(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(s, TRUE, '1 1 0' * 0.20 * mySize_y) + eY * 0.80 * mySize_y, s, '1 1 0' * 0.20 * mySize_y, panel_fg_alpha, DRAWFLAG_NORMAL);
2792         }
2793         else if(race_checkpointtime)
2794         {
2795                 a = bound(0, 2 - (time - race_checkpointtime), 1);
2796                 s = "";
2797                 forcetime = "";
2798                 if(a > 0) // just hit a checkpoint?
2799                 {
2800                         if(race_checkpoint != 254)
2801                         {
2802                                 if(race_time && race_previousbesttime)
2803                                         s = MakeRaceString(race_checkpoint, TIME_DECODE(race_time) - TIME_DECODE(race_previousbesttime), 0, 0, race_previousbestname);
2804                                 else
2805                                         s = MakeRaceString(race_checkpoint, 0, -1, 0, race_previousbestname);
2806                                 if(race_time)
2807                                         forcetime = TIME_ENCODED_TOSTRING(race_time);
2808                         }
2809                 }
2810                 else
2811                 {
2812                         if(race_laptime && race_nextbesttime && race_nextcheckpoint != 254)
2813                         {
2814                                 a = bound(0, 2 - ((race_laptime + TIME_DECODE(race_nextbesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1);
2815                                 if(a > 0) // next one?
2816                                 {
2817                                         s = MakeRaceString(race_nextcheckpoint, (time + TIME_DECODE(race_penaltyaccumulator)) - race_laptime, TIME_DECODE(race_nextbesttime), 0, race_nextbestname);
2818                                 }
2819                         }
2820                 }
2821
2822                 if(s != "" && a > 0)
2823                 {
2824                         drawcolorcodedstring(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(s, TRUE, '1 1 0' * 0.2 * mySize_y) + eY * 0.6 * mySize_y, s, '1 1 0' * 0.2 * mySize_y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2825                 }
2826
2827                 if(race_penaltytime)
2828                 {
2829                         a = bound(0, 2 - (time - race_penaltyeventtime), 1);
2830                         if(a > 0)
2831                         {
2832                                 s = sprintf(_("^1PENALTY: %.1f (%s)"), race_penaltytime * 0.1, race_penaltyreason);
2833                                 drawcolorcodedstring(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(s, TRUE, '1 1 0' * 0.2 * mySize_y) + eY * 0.8 * mySize_y, s, '1 1 0' * 0.2 * mySize_y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2834                         }
2835                 }
2836
2837                 if(forcetime != "")
2838                 {
2839                         a = bound(0, (time - race_checkpointtime) / 0.5, 1);
2840                         drawstring_expanding(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(forcetime, FALSE, '1 1 0' * 0.6 * mySize_y), forcetime, '1 1 0' * 0.6 * mySize_y, '1 1 1', panel_fg_alpha, 0, a);
2841                 }
2842                 else
2843                         a = 1;
2844
2845                 if(race_laptime && race_checkpoint != 255)
2846                 {
2847                         s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime));
2848                         drawstring(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(s, FALSE, '0.6 0.6 0' * mySize_y), s, '0.6 0.6 0' * mySize_y, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
2849                 }
2850         }
2851         else
2852         {
2853                 if(race_mycheckpointtime)
2854                 {
2855                         a = bound(0, 2 - (time - race_mycheckpointtime), 1);
2856                         s = MakeRaceString(race_mycheckpoint, TIME_DECODE(race_mycheckpointdelta), -(race_mycheckpointenemy == ""), race_mycheckpointlapsdelta, race_mycheckpointenemy);
2857                         drawcolorcodedstring(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(s, TRUE, '1 1 0' * 0.2 * mySize_y) + eY * 0.6 * mySize_y, s, '1 1 0' * 0.2 * mySize_y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2858                 }
2859                 if(race_othercheckpointtime && race_othercheckpointenemy != "")
2860                 {
2861                         a = bound(0, 2 - (time - race_othercheckpointtime), 1);
2862                         s = MakeRaceString(race_othercheckpoint, -TIME_DECODE(race_othercheckpointdelta), -(race_othercheckpointenemy == ""), race_othercheckpointlapsdelta, race_othercheckpointenemy);
2863                         drawcolorcodedstring(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(s, TRUE, '1 1 0' * 0.2 * mySize_y) + eY * 0.6 * mySize_y, s, '1 1 0' * 0.2 * mySize_y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2864                 }
2865
2866                 if(race_penaltytime && !race_penaltyaccumulator)
2867                 {
2868                         t = race_penaltytime * 0.1 + race_penaltyeventtime;
2869                         a = bound(0, (1 + t - time), 1);
2870                         if(a > 0)
2871                         {
2872                                 if(time < t)
2873                                         s = sprintf(_("^1PENALTY: %.1f (%s)"), (t - time) * 0.1, race_penaltyreason);
2874                                 else
2875                                         s = sprintf(_("^2PENALTY: %.1f (%s)"), 0, race_penaltyreason);
2876                                 drawcolorcodedstring(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(s, TRUE, '1 1 0' * 0.2 * mySize_y) + eY * 0.6 * mySize_y, s, '1 1 0' * 0.2 * mySize_y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2877                         }
2878                 }
2879         }
2880
2881         draw_endBoldFont();
2882 }
2883
2884 // Vote window (#9)
2885 //
2886 float vote_yescount;
2887 float vote_nocount;
2888 float vote_needed;
2889 float vote_highlighted; // currently selected vote
2890
2891 float vote_active; // is there an active vote?
2892 float vote_prev; // previous state of vote_active to check for a change
2893 float vote_alpha;
2894 float vote_change; // "time" when vote_active changed
2895
2896 void HUD_VoteWindow(void) 
2897 {
2898         if(autocvar_cl_allow_uid2name == -1 && (gametype == MAPINFO_TYPE_CTS || gametype == MAPINFO_TYPE_RACE || (serverflags & SERVERFLAG_PLAYERSTATS)))
2899         {
2900                 vote_active = 1;
2901                 if (autocvar__hud_configure)
2902                 {
2903                         vote_yescount = 0;
2904                         vote_nocount = 0;
2905                         print(_("^1You must answer before entering hud configure mode\n"));
2906                         cvar_set("_hud_configure", "0");
2907                 }
2908                 if(vote_called_vote)
2909                         strunzone(vote_called_vote);
2910                 vote_called_vote = strzone(_("^2Name ^7instead of \"^1Anonymous player^7\" in stats"));
2911                 uid2name_dialog = 1;
2912         }
2913
2914         if(!autocvar__hud_configure)
2915         {
2916                 if(!autocvar_hud_panel_vote) return;
2917
2918                 panel_fg_alpha = autocvar_hud_panel_fg_alpha;
2919                 panel_bg_alpha_str = autocvar_hud_panel_vote_bg_alpha;
2920
2921                 if(panel_bg_alpha_str == "") {
2922                         panel_bg_alpha_str = ftos(autocvar_hud_panel_bg_alpha);
2923                 }
2924                 panel_bg_alpha = stof(panel_bg_alpha_str);
2925         }
2926         else
2927         {
2928                 hud_configure_active_panel = HUD_PANEL_VOTE;
2929
2930                 vote_yescount = 3;
2931                 vote_nocount = 2;
2932                 vote_needed = 4;
2933         }
2934
2935         string s;
2936         float a;
2937         if(vote_active != vote_prev) {
2938                 vote_change = time;
2939                 vote_prev = vote_active;
2940         }
2941
2942         if(vote_active || autocvar__hud_configure)
2943                 vote_alpha = bound(0, (time - vote_change) * 2, 1);
2944         else
2945                 vote_alpha = bound(0, 1 - (time - vote_change) * 2, 1);
2946
2947         if(!vote_alpha)
2948                 return;
2949
2950         HUD_Panel_UpdateCvars(vote);
2951         HUD_Panel_ApplyFadeAlpha();
2952
2953         if(uid2name_dialog)
2954         {
2955                 panel_pos = eX * 0.3 * vid_conwidth + eY * 0.1 * vid_conheight;
2956                 panel_size = eX * 0.4 * vid_conwidth + eY * 0.3 * vid_conheight;
2957         }
2958
2959     // these must be below above block
2960         vector pos, mySize;
2961         pos = panel_pos;
2962         mySize = panel_size;
2963
2964         a = vote_alpha * (vote_highlighted ? autocvar_hud_panel_vote_alreadyvoted_alpha : 1);
2965         HUD_Panel_DrawBg(a);
2966         a = panel_fg_alpha * a;
2967
2968         if(panel_bg_padding)
2969         {
2970                 pos += '1 1 0' * panel_bg_padding;
2971                 mySize -= '2 2 0' * panel_bg_padding;
2972         }
2973
2974         // always force 3:1 aspect
2975         vector newSize = '0 0 0';
2976         if(mySize_x/mySize_y > 3)
2977         {
2978                 newSize_x = 3 * mySize_y;
2979                 newSize_y = mySize_y;
2980
2981                 pos_x = pos_x + (mySize_x - newSize_x) / 2;
2982         }
2983         else
2984         {
2985                 newSize_y = 1/3 * mySize_x;
2986                 newSize_x = mySize_x;
2987
2988                 pos_y = pos_y + (mySize_y - newSize_y) / 2;
2989         }
2990         mySize = newSize;
2991
2992         s = _("A vote has been called for:");
2993         if(uid2name_dialog)
2994                 s = _("Allow servers to store and display your name?");
2995         drawstring_aspect(pos, s, eX * mySize_x + eY * (2/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
2996         s = textShortenToWidth(vote_called_vote, mySize_x, '1 1 0' * mySize_y * (1/8), stringwidth_colors);
2997         if(autocvar__hud_configure)
2998                 s = _("^1Configure the HUD");
2999         drawcolorcodedstring_aspect(pos + eY * (2/8) * mySize_y, s, eX * mySize_x + eY * (1.75/8) * mySize_y, a, DRAWFLAG_NORMAL);
3000
3001         // print the yes/no counts
3002     s = sprintf(_("Yes (%s): %d"), getcommandkey("vyes", "vyes"), vote_yescount);
3003         drawstring_aspect(pos + eY * (4/8) * mySize_y, s, eX * 0.5 * mySize_x + eY * (1.5/8) * mySize_y, '0 1 0', a, DRAWFLAG_NORMAL);
3004     s = sprintf(_("No (%s): %d"), getcommandkey("vno", "vno"), vote_nocount);
3005         drawstring_aspect(pos + eX * 0.5 * mySize_x + eY * (4/8) * mySize_y, s, eX * 0.5 * mySize_x + eY * (1.5/8) * mySize_y, '1 0 0', a, DRAWFLAG_NORMAL);
3006
3007         // draw the progress bar backgrounds
3008         drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_back", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
3009
3010         // draw the highlights
3011         if(vote_highlighted == 1) {
3012                 drawsetcliparea(pos_x, pos_y, mySize_x * 0.5, mySize_y);
3013                 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_voted", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
3014         }
3015         else if(vote_highlighted == -1) {
3016                 drawsetcliparea(pos_x + 0.5 * mySize_x, pos_y, mySize_x * 0.5, mySize_y);
3017                 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_voted", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
3018         }
3019
3020         // draw the progress bars
3021         if(vote_yescount && vote_needed)
3022         {
3023                 drawsetcliparea(pos_x, pos_y, mySize_x * 0.5 * (vote_yescount/vote_needed), mySize_y);
3024                 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_prog", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
3025         }
3026
3027         if(vote_nocount && vote_needed)
3028         {
3029                 drawsetcliparea(pos_x + mySize_x - mySize_x * 0.5 * (vote_nocount/vote_needed), pos_y, mySize_x * 0.5, mySize_y);
3030                 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_prog", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
3031         }
3032
3033         drawresetcliparea();
3034 }
3035
3036 // Mod icons panel (#10)
3037 //
3038
3039 float mod_active; // is there any active mod icon?
3040
3041 // Clan Arena HUD modicons
3042 void HUD_Mod_CA(vector pos, vector mySize)
3043 {
3044         mod_active = 1; // CA should never hide the mod icons panel
3045         float redalive, bluealive;
3046         redalive = getstati(STAT_REDALIVE);
3047         bluealive = getstati(STAT_BLUEALIVE);
3048
3049         vector redpos, bluepos;
3050         if(mySize_x > mySize_y)
3051         {
3052                 redpos = pos;
3053                 bluepos = pos + eY * 0.5 * mySize_y;
3054                 drawpic_aspect_skin(redpos, "player_red.tga", 0.5 * mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3055                 drawstring_aspect(redpos + eX * 0.5 * mySize_x, ftos(redalive), 0.5 * mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3056                 drawpic_aspect_skin(bluepos, "player_blue.tga", 0.5 * mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3057                 drawstring_aspect(bluepos + eX * 0.5 * mySize_x, ftos(bluealive), 0.5 * mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3058         }
3059         else
3060         {
3061                 redpos = pos;
3062                 bluepos = pos + eY * 0.5 * mySize_y;
3063                 drawpic_aspect_skin(redpos, "player_red.tga", eX * mySize_x + eY * 0.3 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3064                 drawstring_aspect(redpos + eY * 0.3 * mySize_y, ftos(redalive), eX * mySize_x + eY * 0.2 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3065                 drawpic_aspect_skin(bluepos, "player_blue.tga", eX * mySize_x + eY * 0.3 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3066                 drawstring_aspect(bluepos + eY * 0.3 * mySize_y, ftos(bluealive), eX * mySize_x + eY * 0.2 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3067         }
3068 }
3069
3070 // CTF HUD modicon section
3071 float redflag_prevframe, blueflag_prevframe; // status during previous frame
3072 float redflag_prevstatus, blueflag_prevstatus; // last remembered status
3073 float redflag_statuschange_time, blueflag_statuschange_time; // time when the status changed
3074
3075 void HUD_Mod_CTF_Reset(void)
3076 {
3077         redflag_prevstatus = blueflag_prevstatus = redflag_prevframe = blueflag_prevframe = redflag_statuschange_time = blueflag_statuschange_time = 0;
3078 }
3079
3080 void HUD_Mod_CTF(vector pos, vector mySize)
3081 {
3082         vector redflag_pos, blueflag_pos;
3083         vector flag_size;
3084         float f; // every function should have that
3085
3086         float redflag, blueflag; // current status
3087         float redflag_statuschange_elapsedtime, blueflag_statuschange_elapsedtime; // time since the status changed
3088         float stat_items;
3089
3090         stat_items = getstati(STAT_ITEMS, 0, 24);
3091         redflag = (stat_items/IT_RED_FLAG_TAKEN) & 3;
3092         blueflag = (stat_items/IT_BLUE_FLAG_TAKEN) & 3;
3093         
3094         if(redflag || blueflag)
3095                 mod_active = 1;
3096         else
3097                 mod_active = 0;
3098
3099         if(autocvar__hud_configure)
3100         {
3101                 redflag = 1;
3102                 blueflag = 2;
3103         }
3104
3105         // when status CHANGES, set old status into prevstatus and current status into status
3106         if (redflag != redflag_prevframe)
3107         {
3108                 redflag_statuschange_time = time;
3109                 redflag_prevstatus = redflag_prevframe;
3110                 redflag_prevframe = redflag;
3111         }
3112
3113         if (blueflag != blueflag_prevframe)
3114         {
3115                 blueflag_statuschange_time = time;
3116                 blueflag_prevstatus = blueflag_prevframe;
3117                 blueflag_prevframe = blueflag;
3118         }
3119
3120         redflag_statuschange_elapsedtime = time - redflag_statuschange_time;
3121         blueflag_statuschange_elapsedtime = time - blueflag_statuschange_time;
3122
3123         float BLINK_FACTOR = 0.15;
3124         float BLINK_BASE = 0.85;
3125         // note:
3126         //   RMS = sqrt(BLINK_BASE^2 + 0.5 * BLINK_FACTOR^2)
3127         // thus
3128         //   BLINK_BASE = sqrt(RMS^2 - 0.5 * BLINK_FACTOR^2)
3129         // ensure RMS == 1
3130         float BLINK_FREQ = 5; // circle frequency, = 2*pi*frequency in hertz
3131
3132         string red_icon, red_icon_prevstatus;
3133         float red_alpha, red_alpha_prevstatus;
3134         red_alpha = red_alpha_prevstatus = 1;
3135         switch(redflag) {
3136                 case 1: red_icon = "flag_red_taken"; break;
3137                 case 2: red_icon = "flag_red_lost"; break;
3138                 case 3: red_icon = "flag_red_carrying"; red_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3139                 default:
3140                         if((stat_items & IT_CTF_SHIELDED) && (myteam == FL_TEAM_2))
3141                                 red_icon = "flag_red_shielded";
3142                         else
3143                                 red_icon = string_null;
3144                         break;
3145         }
3146         switch(redflag_prevstatus) {
3147                 case 1: red_icon_prevstatus = "flag_red_taken"; break;
3148                 case 2: red_icon_prevstatus = "flag_red_lost"; break;
3149                 case 3: red_icon_prevstatus = "flag_red_carrying"; red_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3150                 default:
3151                         if(redflag == 3)
3152                                 red_icon_prevstatus = "flag_red_carrying"; // make it more visible
3153                         else if((stat_items & IT_CTF_SHIELDED) && (myteam == FL_TEAM_2))
3154                                 red_icon_prevstatus = "flag_red_shielded";
3155                         else
3156                                 red_icon_prevstatus = string_null;
3157                         break;
3158         }
3159
3160         string blue_icon, blue_icon_prevstatus;
3161         float blue_alpha, blue_alpha_prevstatus;
3162         blue_alpha = blue_alpha_prevstatus = 1;
3163         switch(blueflag) {
3164                 case 1: blue_icon = "flag_blue_taken"; break;
3165                 case 2: blue_icon = "flag_blue_lost"; break;
3166                 case 3: blue_icon = "flag_blue_carrying"; blue_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3167                 default:
3168                         if((stat_items & IT_CTF_SHIELDED) && (myteam == FL_TEAM_1))
3169                                 blue_icon = "flag_blue_shielded";
3170                         else
3171                                 blue_icon = string_null;
3172                         break;
3173         }
3174         switch(blueflag_prevstatus) {
3175                 case 1: blue_icon_prevstatus = "flag_blue_taken"; break;
3176                 case 2: blue_icon_prevstatus = "flag_blue_lost"; break;
3177                 case 3: blue_icon_prevstatus = "flag_blue_carrying"; blue_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3178                 default:
3179                         if(blueflag == 3)
3180                                 blue_icon_prevstatus = "flag_blue_carrying"; // make it more visible
3181                         else if((stat_items & IT_CTF_SHIELDED) && (myteam == FL_TEAM_1))
3182                                 blue_icon_prevstatus = "flag_blue_shielded";
3183                         else
3184                                 blue_icon_prevstatus = string_null;
3185                         break;
3186         }
3187
3188         if(mySize_x > mySize_y) {
3189                 if (myteam == FL_TEAM_1) { // always draw own flag on left
3190                         redflag_pos = pos;
3191                         blueflag_pos = pos + eX * 0.5 * mySize_x;
3192                 } else {
3193                         blueflag_pos = pos;
3194                         redflag_pos = pos + eX * 0.5 * mySize_x;
3195                 }
3196                 flag_size = eX * 0.5 * mySize_x + eY * mySize_y;
3197         } else {
3198                 if (myteam == FL_TEAM_1) { // always draw own flag on left
3199                         redflag_pos = pos;
3200                         blueflag_pos = pos + eY * 0.5 * mySize_y;
3201                 } else {
3202                         blueflag_pos = pos;
3203                         redflag_pos = pos + eY * 0.5 * mySize_y;
3204                 }
3205                 flag_size = eY * 0.5 * mySize_y + eX * mySize_x;
3206         }
3207
3208         f = bound(0, redflag_statuschange_elapsedtime*2, 1);
3209         if(red_icon_prevstatus && f < 1)
3210                 drawpic_aspect_skin_expanding(redflag_pos, red_icon_prevstatus, flag_size, '1 1 1', panel_fg_alpha * red_alpha_prevstatus, DRAWFLAG_NORMAL, f);
3211         if(red_icon)
3212                 drawpic_aspect_skin(redflag_pos, red_icon, flag_size, '1 1 1', panel_fg_alpha * red_alpha * f, DRAWFLAG_NORMAL);
3213
3214         f = bound(0, blueflag_statuschange_elapsedtime*2, 1);
3215         if(blue_icon_prevstatus && f < 1)
3216                 drawpic_aspect_skin_expanding(blueflag_pos, blue_icon_prevstatus, flag_size, '1 1 1', panel_fg_alpha * blue_alpha_prevstatus, DRAWFLAG_NORMAL, f);
3217         if(blue_icon)
3218                 drawpic_aspect_skin(blueflag_pos, blue_icon, flag_size, '1 1 1', panel_fg_alpha * blue_alpha * f, DRAWFLAG_NORMAL);
3219 }
3220
3221 // Keyhunt HUD modicon section
3222 float kh_runheretime;
3223
3224 void HUD_Mod_KH_Reset(void)
3225 {
3226         kh_runheretime = 0;
3227 }
3228
3229 void HUD_Mod_KH(vector pos, vector mySize)
3230 {
3231         mod_active = 1; // keyhunt should never hide the mod icons panel
3232         float kh_keys;
3233         float keyteam;
3234         float a, aa;
3235         vector p = '0 0 0', pa, kh_size = '0 0 0', kh_asize = '0 0 0';
3236
3237         kh_keys = getstati(STAT_KH_KEYS);
3238
3239         p_x = pos_x;
3240         if(mySize_x > mySize_y)
3241         {
3242                 p_y = pos_y + 0.25 * mySize_y;
3243                 pa = p - eY * 0.25 * mySize_y;
3244
3245                 kh_size_x = mySize_x * 0.25;
3246                 kh_size_y = 0.75 * mySize_y;
3247                 kh_asize_x = mySize_x * 0.25;
3248                 kh_asize_y = mySize_y * 0.25;
3249         }
3250         else
3251         {
3252                 p_y = pos_y + 0.125 * mySize_y;
3253                 pa = p - eY * 0.125 * mySize_y;
3254
3255                 kh_size_x = mySize_x * 0.5;
3256                 kh_size_y = 0.375 * mySize_y;
3257                 kh_asize_x = mySize_x * 0.5;
3258                 kh_asize_y = mySize_y * 0.125;
3259         }
3260
3261         float i, key;
3262
3263         float keycount;
3264         keycount = 0;
3265         for(i = 0; i < 4; ++i)
3266         {
3267                 key = floor(kh_keys / pow(32, i)) & 31;
3268                 keyteam = key - 1;
3269                 if(keyteam == 30 && keycount <= 4)
3270                         keycount += 4;
3271                 if(keyteam == myteam || keyteam == -1 || keyteam == 30)
3272                         keycount += 1;
3273         }
3274
3275         // this yields 8 exactly if "RUN HERE" shows
3276
3277         if(keycount == 8)
3278         {
3279                 if(!kh_runheretime)
3280                         kh_runheretime = time;
3281                 pa_y -= fabs(sin((time - kh_runheretime) * 3.5)) * 6; // make the arrows jump in case of RUN HERE
3282         }
3283         else
3284                 kh_runheretime = 0;
3285
3286         for(i = 0; i < 4; ++i)
3287         {
3288                 key = floor(kh_keys / pow(32, i)) & 31;
3289                 keyteam = key - 1;
3290                 switch(keyteam)
3291                 {
3292                         case 30: // my key
3293                                 keyteam = myteam;
3294                                 a = 1;
3295                                 aa = 1;
3296                                 break;
3297                         case -1: // no key
3298                                 a = 0;
3299                                 aa = 0;
3300                                 break;
3301                         default: // owned or dropped
3302                                 a = 0.2;
3303                                 aa = 0.5;
3304                                 break;
3305                 }
3306                 a = a * panel_fg_alpha;
3307                 aa = aa * panel_fg_alpha;
3308                 if(a > 0)
3309                 {
3310                         switch(keyteam)
3311                         {
3312                                 case FL_TEAM_1:
3313                                         drawpic_aspect_skin(pa, "kh_redarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL);  // show 30% theAlpha key
3314                                         break;
3315                                 case FL_TEAM_2:
3316                                         drawpic_aspect_skin(pa, "kh_bluearrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL);  // show 30% theAlpha key
3317                                         break;
3318                                 case FL_TEAM_3:
3319                                         drawpic_aspect_skin(pa, "kh_yellowarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL);  // show 30% theAlpha key
3320                                         break;
3321                                 case FL_TEAM_4:
3322                                         drawpic_aspect_skin(pa, "kh_pinkarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL);  // show 30% theAlpha key
3323                                         break;
3324                                 default:
3325                                         break;
3326                         }
3327                         switch(i) // YAY! switch(i) inside a for loop for i. DailyWTF, here we come!
3328                         {
3329                                 case 0:
3330                                         drawpic_aspect_skin(p, "kh_red", kh_size, '1 1 1', a, DRAWFLAG_NORMAL);  // show 30% theAlpha key
3331                                         break;
3332                                 case 1:
3333                                         drawpic_aspect_skin(p, "kh_blue", kh_size, '1 1 1', a, DRAWFLAG_NORMAL);  // show 30% theAlpha key
3334                                         break;
3335                                 case 2:
3336                                         drawpic_aspect_skin(p, "kh_yellow", kh_size, '1 1 1', a, DRAWFLAG_NORMAL);  // show 30% theAlpha key
3337                                         break;
3338                                 case 3:
3339                                         drawpic_aspect_skin(p, "kh_pink", kh_size, '1 1 1', a, DRAWFLAG_NORMAL);  // show 30% theAlpha key
3340                                         break;
3341                         }
3342                 }
3343                 if(mySize_x > mySize_y)
3344                 {
3345                         p_x += 0.25 * mySize_x;
3346                         pa_x += 0.25 * mySize_x;
3347                 }
3348                 else
3349                 {
3350                         if(i == 1)
3351                         {
3352                                 p_y = pos_y + 0.625 * mySize_y;
3353                                 pa_y = pos_y + 0.5 * mySize_y;
3354                                 p_x = pos_x;
3355                                 pa_x = pos_x;
3356                         }
3357                         else
3358                         {
3359                                 p_x += 0.5 * mySize_x;
3360                                 pa_x += 0.5 * mySize_x;
3361                         }
3362                 }
3363         }
3364 }
3365
3366 // Keepaway HUD mod icon
3367 float kaball_prevstatus; // last remembered status
3368 float kaball_statuschange_time; // time when the status changed
3369
3370 // we don't need to reset for keepaway since it immediately 
3371 // autocorrects prevstatus as to if the player has the ball or not
3372
3373 void HUD_Mod_Keepaway(vector pos, vector mySize)
3374 {
3375         mod_active = 1; // keepaway should always show the mod HUD
3376         
3377         float BLINK_FACTOR = 0.15;
3378         float BLINK_BASE = 0.85;
3379         float BLINK_FREQ = 5; 
3380         float kaball_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ);
3381         
3382         float stat_items = getstati(STAT_ITEMS, 0, 24);
3383         float kaball = (stat_items/IT_KEY1) & 1;
3384         
3385         if(kaball != kaball_prevstatus)
3386         {
3387                 kaball_statuschange_time = time;
3388                 kaball_prevstatus = kaball;
3389         }
3390         
3391         vector kaball_pos, kaball_size;
3392         
3393         if(mySize_x > mySize_y) {
3394                 kaball_pos = pos + eX * 0.25 * mySize_x;
3395                 kaball_size = eX * 0.5 * mySize_x + eY * mySize_y;
3396         } else {
3397                 kaball_pos = pos + eY * 0.25 * mySize_y;
3398                 kaball_size = eY * 0.5 * mySize_y + eX * mySize_x;
3399         }
3400         
3401         float kaball_statuschange_elapsedtime = time - kaball_statuschange_time;
3402         float f = bound(0, kaball_statuschange_elapsedtime*2, 1);
3403         
3404         if(kaball_prevstatus && f < 1)
3405                 drawpic_aspect_skin_expanding(kaball_pos, "keepawayball_carrying", kaball_size, '1 1 1', panel_fg_alpha * kaball_alpha, DRAWFLAG_NORMAL, f);
3406         
3407         if(kaball)
3408                 drawpic_aspect_skin(pos, "keepawayball_carrying", eX * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha * kaball_alpha * f, DRAWFLAG_NORMAL);
3409 }
3410
3411
3412 // Nexball HUD mod icon
3413 void HUD_Mod_NexBall(vector pos, vector mySize)
3414 {
3415         float stat_items, nb_pb_starttime, dt, p;
3416
3417         stat_items = getstati(STAT_ITEMS, 0, 24);
3418         nb_pb_starttime = getstatf(STAT_NB_METERSTART);
3419
3420         if (stat_items & IT_KEY1)
3421                 mod_active = 1;
3422         else
3423                 mod_active = 0;
3424
3425         //Manage the progress bar if any
3426         if (nb_pb_starttime > 0)
3427         {
3428                 dt = mod(time - nb_pb_starttime, nb_pb_period);
3429                 // one period of positive triangle
3430                 p = 2 * dt / nb_pb_period;
3431                 if (p > 1)
3432                         p = 2 - p;
3433
3434                 //Draw the filling
3435                 HUD_Panel_GetProgressBarColor(nexball);
3436                 if(mySize_x > mySize_y)
3437                         HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", p, 0, 0, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
3438                 else
3439                         HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", p, 1, 0, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
3440         }
3441
3442         if (stat_items & IT_KEY1)
3443                 drawpic_aspect_skin(pos, "nexball_carrying", eX * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3444 }
3445
3446 // Race/CTS HUD mod icons
3447 float crecordtime_prev; // last remembered crecordtime
3448 float crecordtime_change_time; // time when crecordtime last changed
3449 float srecordtime_prev; // last remembered srecordtime
3450 float srecordtime_change_time; // time when srecordtime last changed
3451
3452 float race_status_time;
3453 float race_status_prev;
3454 string race_status_name_prev;
3455 void HUD_Mod_Race(vector pos, vector mySize)
3456 {
3457         mod_active = 1; // race should never hide the mod icons panel
3458         entity me;
3459         me = playerslots[player_localnum];
3460         float t, score;
3461         float f; // yet another function has this
3462         score = me.(scores[ps_primary]);
3463
3464         if not((scores_flags[ps_primary] & SFL_TIME) && !teamplay) // race/cts record display on HUD
3465                 return; // no records in the actual race
3466
3467         // clientside personal record
3468         string rr;
3469         if(gametype == MAPINFO_TYPE_CTS)
3470                 rr = CTS_RECORD;
3471         else
3472                 rr = RACE_RECORD;
3473         t = stof(db_get(ClientProgsDB, strcat(shortmapname, rr, "time")));
3474
3475         if(score && (score < t || !t)) {
3476                 db_put(ClientProgsDB, strcat(shortmapname, rr, "time"), ftos(score));
3477                 if(autocvar_cl_autodemo_delete_keeprecords)
3478                 {
3479                         f = autocvar_cl_autodemo_delete;
3480                         f &~= 1;
3481                         cvar_set("cl_autodemo_delete", ftos(f)); // don't delete demo with new record!
3482                 }
3483         }
3484
3485         if(t != crecordtime_prev) {
3486                 crecordtime_prev = t;
3487                 crecordtime_change_time = time;
3488         }
3489
3490         vector textPos, medalPos;
3491         float squareSize;
3492         if(mySize_x > mySize_y) {
3493                 // text on left side
3494                 squareSize = min(mySize_y, mySize_x/2);
3495                 textPos = pos + eX * 0.5 * max(0, mySize_x/2 - squareSize) + eY * 0.5 * (mySize_y - squareSize);
3496                 medalPos = pos + eX * 0.5 * max(0, mySize_x/2 - squareSize) + eX * 0.5 * mySize_x + eY * 0.5 * (mySize_y - squareSize);
3497         } else {
3498                 // text on top
3499                 squareSize = min(mySize_x, mySize_y/2);
3500                 textPos = pos + eY * 0.5 * max(0, mySize_y/2 - squareSize) + eX * 0.5 * (mySize_x - squareSize);
3501                 medalPos = pos + eY * 0.5 * max(0, mySize_y/2 - squareSize) + eY * 0.5 * mySize_y + eX * 0.5 * (mySize_x - squareSize);
3502         }
3503
3504         f = time - crecordtime_change_time;
3505
3506         if (f > 1) {
3507                 drawstring_aspect(textPos, _("Personal best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3508                 drawstring_aspect(textPos + eY * 0.25 * squareSize, TIME_ENCODED_TOSTRING(t), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3509         } else {
3510                 drawstring_aspect(textPos, _("Personal best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3511                 drawstring_aspect(textPos + eY * 0.25 * squareSize, TIME_ENCODED_TOSTRING(t), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3512                 drawstring_aspect_expanding(pos, _("Personal best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
3513                 drawstring_aspect_expanding(pos + eY * 0.25 * squareSize, TIME_ENCODED_TOSTRING(t), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
3514         }
3515
3516         // server record
3517         t = race_server_record;
3518         if(t != srecordtime_prev) {
3519                 srecordtime_prev = t;
3520                 srecordtime_change_time = time;
3521         }
3522         f = time - srecordtime_change_time;
3523
3524         if (f > 1) {
3525                 drawstring_aspect(textPos + eY * 0.5 * squareSize, _("Server best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3526                 drawstring_aspect(textPos + eY * 0.75 * squareSize, TIME_ENCODED_TOSTRING(t), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3527         } else {
3528                 drawstring_aspect(textPos + eY * 0.5 * squareSize, _("Server best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3529                 drawstring_aspect(textPos + eY * 0.75 * squareSize, TIME_ENCODED_TOSTRING(t), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3530                 drawstring_aspect_expanding(textPos + eY * 0.5 * squareSize, _("Server best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
3531                 drawstring_aspect_expanding(textPos + eY * 0.75 * squareSize, TIME_ENCODED_TOSTRING(t), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
3532         }
3533
3534         if (race_status != race_status_prev || race_status_name != race_status_name_prev) {
3535                 race_status_time = time + 5;
3536                 race_status_prev = race_status;
3537                 if (race_status_name_prev)
3538                         strunzone(race_status_name_prev);
3539                 race_status_name_prev = strzone(race_status_name);
3540         }
3541
3542         // race "awards"
3543         float a;
3544         a = bound(0, race_status_time - time, 1);
3545
3546         string s;
3547         s = textShortenToWidth(race_status_name, squareSize, '1 1 0' * 0.1 * squareSize, stringwidth_colors);
3548
3549         float rank;
3550         if(race_status > 0)
3551                 rank = race_CheckName(race_status_name);
3552         else
3553                 rank = 0;
3554         string rankname;
3555         rankname = race_PlaceName(rank);
3556
3557         vector namepos;
3558         namepos = medalPos + '0 0.8 0' * squareSize;
3559         vector rankpos;
3560         rankpos = medalPos + '0 0.15 0' * squareSize;
3561
3562         if(race_status == 0)
3563                 drawpic_aspect_skin(medalPos, "race_newfail", '1 1 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3564         else if(race_status == 1) {
3565                 drawpic_aspect_skin(medalPos + '0.1 0 0' * squareSize, "race_newtime", '1 1 0' * 0.8 * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3566                 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3567                 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3568         } else if(race_status == 2) {
3569                 if(race_status_name == GetPlayerName(player_localnum) || !race_myrank || race_myrank < rank)
3570                         drawpic_aspect_skin(medalPos + '0.1 0 0' * squareSize, "race_newrankgreen", '1 1 0' * 0.8 * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3571                 else
3572                         drawpic_aspect_skin(medalPos + '0.1 0 0' * squareSize, "race_newrankyellow", '1 1 0' * 0.8 * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3573                 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3574                 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3575         } else if(race_status == 3) {
3576                 drawpic_aspect_skin(medalPos + '0.1 0 0' * squareSize, "race_newrecordserver", '1 1 0' * 0.8 * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3577                 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3578                 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3579         }
3580
3581         if (race_status_time - time <= 0) {
3582                 race_status_prev = -1;
3583                 race_status = -1;
3584                 if(race_status_name)
3585                         strunzone(race_status_name);
3586                 race_status_name = string_null;
3587                 if(race_status_name_prev)
3588                         strunzone(race_status_name_prev);
3589                 race_status_name_prev = string_null;
3590         }
3591 }
3592
3593 void DrawDomItem(vector myPos, vector mySize, float aspect_ratio, float layout, float i)
3594 {
3595         float stat, pps_ratio;
3596         string pic;
3597         vector color;
3598 #ifdef GMQCC
3599         stat = -1;
3600         pic = "";
3601         color = '0 0 0';
3602 #endif
3603         switch(i)
3604         {
3605                 case 0:
3606                         stat = getstatf(STAT_DOM_PPS_RED);
3607                         pic = "dom_icon_red";
3608                         color = '1 0 0';
3609                         break;
3610                 case 1:
3611                         stat = getstatf(STAT_DOM_PPS_BLUE);
3612                         pic = "dom_icon_blue";
3613                         color = '0 0 1';
3614                         break;
3615                 case 2:
3616                         stat = getstatf(STAT_DOM_PPS_YELLOW);
3617                         pic = "dom_icon_yellow";
3618                         color = '1 1 0';
3619                         break;
3620                 default:
3621                 case 3:
3622                         stat = getstatf(STAT_DOM_PPS_PINK);
3623                         pic = "dom_icon_pink";
3624                         color = '1 0 1';
3625                         break;
3626         }
3627         pps_ratio = stat / getstatf(STAT_DOM_TOTAL_PPS);
3628
3629         if(mySize_x/mySize_y > aspect_ratio)
3630         {
3631                 i = aspect_ratio * mySize_y;
3632                 myPos_x = myPos_x + (mySize_x - i) / 2;
3633                 mySize_x = i;
3634         }
3635         else
3636         {
3637                 i = 1/aspect_ratio * mySize_x;
3638                 myPos_y = myPos_y + (mySize_y - i) / 2;
3639                 mySize_y = i;
3640         }
3641
3642         if (layout) // show text too
3643         {
3644                 //draw the text
3645                 color *= 0.5 + pps_ratio * (1 - 0.5); // half saturated color at min, full saturated at max
3646                 if (layout == 2) // average pps
3647                         drawstring_aspect(myPos + eX * mySize_y, ftos_decimals(stat, 2), eX * (2/3) * mySize_x + eY * mySize_y, color, panel_fg_alpha, DRAWFLAG_NORMAL);
3648                 else // percentage of average pps
3649                         drawstring_aspect(myPos + eX * mySize_y, strcat( ftos(floor(pps_ratio*100 + 0.5)), "%" ), eX * (2/3) * mySize_x + eY * mySize_y, color, panel_fg_alpha, DRAWFLAG_NORMAL);
3650         }
3651
3652         //draw the icon
3653         drawpic_aspect_skin(myPos, pic, '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3654         if (stat > 0)
3655         {
3656                 drawsetcliparea(myPos_x, myPos_y + mySize_y * (1 - pps_ratio), mySize_y, mySize_y * pps_ratio);
3657                 drawpic_aspect_skin(myPos, strcat(pic, "-highlighted"), '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3658                 drawresetcliparea();
3659         }
3660 }
3661
3662 void HUD_Mod_Dom(vector myPos, vector mySize)
3663 {
3664         mod_active = 1; // required in each mod function that always shows something
3665         entity tm;
3666         float teams_count = 0;
3667         for(tm = teams.sort_next; tm; tm = tm.sort_next)
3668                 if(tm.team != FL_SPECTATOR)
3669                         ++teams_count;
3670
3671         float layout = autocvar_hud_panel_modicons_dom_layout;
3672         float rows, columns, aspect_ratio;
3673         rows = mySize_y/mySize_x;
3674         aspect_ratio = (layout) ? 3 : 1;
3675         rows = bound(1, floor((sqrt((4 * aspect_ratio * teams_count + rows) * rows) + rows + 0.5) / 2), teams_count);
3676         columns = ceil(teams_count/rows);
3677
3678         int i;
3679         float row = 0, column = 0;
3680         for(i=0; i<teams_count; ++i)
3681         {
3682                 vector pos, itemSize;
3683                 pos = myPos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows);
3684                 itemSize = eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows);
3685
3686                 DrawDomItem(pos, itemSize, aspect_ratio, layout, i);
3687
3688                 ++row;
3689                 if(row >= rows)
3690                 {
3691                         row = 0;
3692                         ++column;
3693                 }
3694         }
3695 }
3696
3697 float mod_prev; // previous state of mod_active to check for a change
3698 float mod_alpha;
3699 float mod_change; // "time" when mod_active changed
3700
3701 void HUD_ModIcons(void)
3702 {
3703         if(!autocvar__hud_configure)
3704         {
3705                 if(!autocvar_hud_panel_modicons) return;
3706                 if (gametype != MAPINFO_TYPE_CTF && gametype != MAPINFO_TYPE_KEYHUNT && gametype != MAPINFO_TYPE_NEXBALL && gametype != MAPINFO_TYPE_CTS && gametype != MAPINFO_TYPE_RACE && gametype != MAPINFO_TYPE_CA && gametype != MAPINFO_TYPE_FREEZETAG && gametype != MAPINFO_TYPE_KEEPAWAY && gametype != MAPINFO_TYPE_DOMINATION) return;
3707         }
3708         else
3709                 hud_configure_active_panel = HUD_PANEL_MODICONS;
3710
3711         HUD_Panel_UpdateCvars(modicons);
3712         HUD_Panel_ApplyFadeAlpha();
3713
3714         draw_beginBoldFont();
3715
3716         vector pos, mySize;
3717         pos = panel_pos;
3718         mySize = panel_size;
3719
3720         if(mod_active != mod_prev) {
3721                 mod_change = time;
3722                 mod_prev = mod_active;
3723         }
3724
3725         if(mod_active || autocvar__hud_configure)
3726                 mod_alpha = bound(0, (time - mod_change) * 2, 1);
3727         else
3728                 mod_alpha = bound(0, 1 - (time - mod_change) * 2, 1);
3729
3730         if(mod_alpha)
3731                 HUD_Panel_DrawBg(mod_alpha);
3732
3733         if(panel_bg_padding)
3734         {
3735                 pos += '1 1 0' * panel_bg_padding;
3736                 mySize -= '2 2 0' * panel_bg_padding;
3737         }
3738
3739         // these MUST be ran in order to update mod_active
3740         if(gametype == MAPINFO_TYPE_KEYHUNT)
3741                 HUD_Mod_KH(pos, mySize);
3742         else if(gametype == MAPINFO_TYPE_CTF || autocvar__hud_configure)
3743                 HUD_Mod_CTF(pos, mySize); // forcealpha only needed for ctf icons, as only they are shown in config mode
3744         else if(gametype == MAPINFO_TYPE_NEXBALL)
3745                 HUD_Mod_NexBall(pos, mySize);
3746         else if(gametype == MAPINFO_TYPE_CTS || gametype == MAPINFO_TYPE_RACE)
3747                 HUD_Mod_Race(pos, mySize);
3748         else if(gametype == MAPINFO_TYPE_CA || gametype == MAPINFO_TYPE_FREEZETAG)
3749                 HUD_Mod_CA(pos, mySize);
3750         else if(gametype == MAPINFO_TYPE_DOMINATION)
3751                 HUD_Mod_Dom(pos, mySize);
3752         else if(gametype == MAPINFO_TYPE_KEEPAWAY)
3753                 HUD_Mod_Keepaway(pos, mySize);
3754
3755         draw_endBoldFont();
3756 }
3757
3758 // Draw pressed keys (#11)
3759 //
3760 void HUD_DrawPressedKeys(void)
3761 {
3762         if(!autocvar__hud_configure)
3763         {
3764                 if(!autocvar_hud_panel_pressedkeys) return;
3765                 if(spectatee_status <= 0 && autocvar_hud_panel_pressedkeys < 2) return;
3766         }
3767         else
3768                 hud_configure_active_panel = HUD_PANEL_PRESSEDKEYS;
3769
3770
3771         HUD_Panel_UpdateCvars(pressedkeys);
3772         HUD_Panel_ApplyFadeAlpha();
3773         vector pos, mySize;
3774         pos = panel_pos;
3775         mySize = panel_size;
3776
3777         HUD_Panel_DrawBg(1);
3778         if(panel_bg_padding)
3779         {
3780                 pos += '1 1 0' * panel_bg_padding;
3781                 mySize -= '2 2 0' * panel_bg_padding;
3782         }
3783
3784         // force custom aspect
3785         float aspect = autocvar_hud_panel_pressedkeys_aspect;
3786         if(aspect)
3787         {
3788                 vector newSize = '0 0 0';
3789                 if(mySize_x/mySize_y > aspect)
3790                 {
3791                         newSize_x = aspect * mySize_y;
3792                         newSize_y = mySize_y;
3793
3794                         pos_x = pos_x + (mySize_x - newSize_x) / 2;
3795                 }
3796                 else
3797                 {
3798                         newSize_y = 1/aspect * mySize_x;
3799                         newSize_x = mySize_x;
3800
3801                         pos_y = pos_y + (mySize_y - newSize_y) / 2;
3802                 }
3803                 mySize = newSize;
3804         }
3805
3806         vector keysize;
3807         keysize = eX * mySize_x * (1/3.0) + eY * mySize_y * (1/(3.0 - !autocvar_hud_panel_pressedkeys_attack));
3808         float pressedkeys;
3809         pressedkeys = getstatf(STAT_PRESSED_KEYS);
3810
3811         if(autocvar_hud_panel_pressedkeys_attack)
3812         {
3813                 drawpic_aspect_skin(pos + eX * keysize_x * 0.5, ((pressedkeys & KEY_ATCK) ? "key_atck_inv.tga" : "key_atck.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3814                 drawpic_aspect_skin(pos + eX * keysize_x * 1.5, ((pressedkeys & KEY_ATCK2) ? "key_atck_inv.tga" : "key_atck.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3815                 pos_y += keysize_y;
3816         }
3817
3818         drawpic_aspect_skin(pos, ((pressedkeys & KEY_CROUCH) ? "key_crouch_inv.tga" : "key_crouch.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3819         drawpic_aspect_skin(pos + eX * keysize_x, ((pressedkeys & KEY_FORWARD) ? "key_forward_inv.tga" : "key_forward.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3820         drawpic_aspect_skin(pos + eX * keysize_x * 2, ((pressedkeys & KEY_JUMP) ? "key_jump_inv.tga" : "key_jump.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3821         pos_y += keysize_y;
3822         drawpic_aspect_skin(pos, ((pressedkeys & KEY_LEFT) ? "key_left_inv.tga" : "key_left.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3823         drawpic_aspect_skin(pos + eX * keysize_x, ((pressedkeys & KEY_BACKWARD) ? "key_backward_inv.tga" : "key_backward.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3824         drawpic_aspect_skin(pos + eX * keysize_x * 2, ((pressedkeys & KEY_RIGHT) ? "key_right_inv.tga" : "key_right.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3825 }
3826
3827 // Handle chat as a panel (#12)
3828 //
3829 void HUD_Chat(void)
3830 {
3831         if(!autocvar__hud_configure)
3832         {
3833                 if (!autocvar_hud_panel_chat)
3834                 {
3835                         if (!autocvar_con_chatrect)
3836                                 cvar_set("con_chatrect", "0");
3837                         return;
3838                 }
3839                 if(autocvar__con_chat_maximized)
3840                         if(!hud_draw_maximized) return;
3841         }
3842         else
3843                 hud_configure_active_panel = HUD_PANEL_CHAT;
3844
3845         HUD_Panel_UpdateCvars(chat);
3846         HUD_Panel_ApplyFadeAlpha();
3847
3848         if(autocvar__con_chat_maximized && !autocvar__hud_configure) // draw at full screen height if maximized
3849         {
3850                 panel_pos_y = panel_bg_border;
3851                 panel_size_y = vid_conheight - panel_bg_border * 2;
3852                 if(panel_bg == "0") // force a border when maximized
3853                 {
3854                         if(precache_pic(panel_bg) == "") {
3855                                 panel_bg = strcat(hud_skin_path, "/border_default");
3856                                 if(precache_pic(panel_bg) == "") {
3857                                         panel_bg = "gfx/hud/default/border_default";
3858                                 }
3859                         }
3860                 }
3861                 panel_bg_alpha = max(0.75, panel_bg_alpha); // force an theAlpha of at least 0.75
3862         }
3863
3864         vector pos, mySize;
3865         pos = panel_pos;
3866         mySize = panel_size;
3867
3868         HUD_Panel_DrawBg(1);
3869
3870         if(panel_bg_padding)
3871         {
3872                 pos += '1 1 0' * panel_bg_padding;
3873                 mySize -= '2 2 0' * panel_bg_padding;
3874         }
3875
3876         if (!autocvar_con_chatrect)
3877                 cvar_set("con_chatrect", "1");
3878
3879         cvar_set("con_chatrect_x", ftos(pos_x/vid_conwidth));
3880         cvar_set("con_chatrect_y", ftos(pos_y/vid_conheight));
3881
3882         cvar_set("con_chatwidth", ftos(mySize_x/vid_conwidth));
3883         cvar_set("con_chat", ftos(floor(mySize_y/autocvar_con_chatsize - 0.5)));
3884
3885         if(autocvar__hud_configure)
3886         {
3887                 vector chatsize;
3888                 chatsize = '1 1 0' * autocvar_con_chatsize;
3889                 cvar_set("con_chatrect_x", "9001"); // over 9000, we'll fake it instead for more control over theAlpha and such
3890                 float i, a;
3891                 for(i = 0; i < autocvar_con_chat; ++i)
3892                 {
3893                         if(i == autocvar_con_chat - 1)
3894                                 a = panel_fg_alpha;
3895                         else
3896                                 a = panel_fg_alpha * floor(((i + 1) * 7 + autocvar_con_chattime)/45);
3897                         drawcolorcodedstring(pos, textShortenToWidth(_("^3Player^7: This is the chat area."), mySize_x, chatsize, stringwidth_colors), chatsize, a, DRAWFLAG_NORMAL);
3898                         pos_y += chatsize_y;
3899                 }
3900         }
3901 }
3902
3903 // Engine info panel (#13)
3904 //
3905 float prevfps;
3906 float prevfps_time;
3907 float framecounter;
3908
3909 float frametimeavg;
3910 float frametimeavg1; // 1 frame ago
3911 float frametimeavg2; // 2 frames ago
3912 void HUD_EngineInfo(void)
3913 {
3914         if(!autocvar__hud_configure)
3915         {
3916                 if(!autocvar_hud_panel_engineinfo) return;
3917         }
3918         else
3919                 hud_configure_active_panel = HUD_PANEL_ENGINEINFO;
3920
3921         HUD_Panel_UpdateCvars(engineinfo);
3922         HUD_Panel_ApplyFadeAlpha();
3923         vector pos, mySize;
3924         pos = panel_pos;
3925         mySize = panel_size;
3926
3927         HUD_Panel_DrawBg(1);
3928         if(panel_bg_padding)
3929         {
3930                 pos += '1 1 0' * panel_bg_padding;
3931                 mySize -= '2 2 0' * panel_bg_padding;
3932         }
3933
3934         float currentTime = gettime(GETTIME_REALTIME);
3935         if(cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage"))
3936         {
3937                 float currentframetime = currentTime - prevfps_time;
3938                 frametimeavg = (frametimeavg + frametimeavg1 + frametimeavg2 + currentframetime)/4; // average three frametimes into framecounter for slightly more stable fps readings :P
3939                 frametimeavg2 = frametimeavg1;
3940                 frametimeavg1 = frametimeavg;
3941                 
3942                 float weight;
3943                 weight = cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage_new_weight");
3944                 if(currentframetime > 0.0001) // filter out insane values which sometimes seem to occur and throw off the average? If you are getting 10,000 fps or more, then you don't need a framerate counter.
3945                 {
3946                         if(fabs(prevfps - (1/frametimeavg)) > prevfps * cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage_instantupdate_change_threshold")) // if there was a big jump in fps, just force prevfps at current (1/currentframetime) to make big updates instant
3947                                 prevfps = (1/currentframetime);
3948                         prevfps = (1 - weight) * prevfps + weight * (1/frametimeavg); // framecounter just used so there's no need for a new variable, think of it as "frametime average"
3949                 }
3950                 prevfps_time = currentTime;
3951         }
3952         else
3953         {
3954                 framecounter += 1;
3955                 if(currentTime - prevfps_time > autocvar_hud_panel_engineinfo_framecounter_time)
3956                 {
3957                         prevfps = framecounter/(currentTime - prevfps_time);
3958                         framecounter = 0;
3959                         prevfps_time = currentTime;
3960                 }
3961         }
3962
3963         vector color;
3964         color = HUD_Get_Num_Color (prevfps, 100);
3965         drawstring_aspect(pos, sprintf(_("FPS: %.*f"), autocvar_hud_panel_engineinfo_framecounter_decimals, prevfps), mySize, color, panel_fg_alpha, DRAWFLAG_NORMAL);
3966 }
3967
3968 // Info messages panel (#14)
3969 //
3970 #define drawInfoMessage(s)\
3971         if(autocvar_hud_panel_infomessages_flip)\
3972                 o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize);\
3973         drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);\
3974         o_y += fontsize_y;
3975 void HUD_InfoMessages(void)
3976 {
3977         if(!autocvar__hud_configure)
3978         {
3979                 if(!autocvar_hud_panel_infomessages) return;
3980         }
3981         else
3982                 hud_configure_active_panel = HUD_PANEL_INFOMESSAGES;
3983
3984         HUD_Panel_UpdateCvars(infomessages);
3985         HUD_Panel_ApplyFadeAlpha();
3986         vector pos, mySize;
3987         pos = panel_pos;
3988         mySize = panel_size;
3989
3990         HUD_Panel_DrawBg(1);
3991         if(panel_bg_padding)
3992         {
3993                 pos += '1 1 0' * panel_bg_padding;
3994                 mySize -= '2 2 0' * panel_bg_padding;
3995         }
3996
3997         // always force 5:1 aspect
3998         vector newSize = '0 0 0';
3999         if(mySize_x/mySize_y > 5)
4000         {
4001                 newSize_x = 5 * mySize_y;
4002                 newSize_y = mySize_y;
4003
4004                 pos_x = pos_x + (mySize_x - newSize_x) / 2;
4005         }
4006         else
4007         {
4008                 newSize_y = 1/5 * mySize_x;
4009                 newSize_x = mySize_x;
4010
4011                 pos_y = pos_y + (mySize_y - newSize_y) / 2;
4012         }
4013
4014         mySize = newSize;
4015         entity tm;
4016         vector o;
4017         o = pos;
4018
4019         vector fontsize;
4020         fontsize = '0.20 0.20 0' * mySize_y;
4021         
4022         float a;
4023         a = panel_fg_alpha;
4024
4025         string s;
4026         if(!autocvar__hud_configure)
4027         {
4028                 if(spectatee_status && !intermission)
4029                 {
4030                         a = 1;
4031                         if(spectatee_status == -1)
4032                                 s = _("^1Observing");
4033                         else
4034 #ifdef COMPAT_XON050_ENGINE
4035                                 s = sprintf(_("^1Spectating: ^7%s"), GetPlayerName(spectatee_status - 1));
4036 #else
4037                                 s = sprintf(_("^1Spectating: ^7%s"), GetPlayerName(player_localentnum - 1));
4038 #endif
4039                         drawInfoMessage(s)
4040
4041                         if(spectatee_status == -1)
4042                                 s = sprintf(_("^1Press ^3%s^1 to spectate"), getcommandkey("primary fire", "+fire"));
4043                         else
4044                                 s = sprintf(_("^1Press ^3%s^1 for another player"), getcommandkey("primary fire", "+fire"));
4045                         drawInfoMessage(s)
4046
4047                         if(spectatee_status == -1)
4048                                 s = sprintf(_("^1Use ^3%s^1 or ^3%s^1 to change the speed"), getcommandkey("next weapon", "weapnext"), getcommandkey("previous weapon", "weapprev"));
4049                         else
4050                                 s = sprintf(_("^1Press ^3%s^1 to observe"), getcommandkey("secondary fire", "+fire2"));
4051                         drawInfoMessage(s)
4052
4053                         s = sprintf(_("^1Press ^3%s^1 for gamemode info"), getcommandkey("server info", "+show_info"));
4054                         drawInfoMessage(s)
4055
4056                         if(gametype == MAPINFO_TYPE_ARENA)
4057                                 s = _("^1Wait for your turn to join");
4058                         else if(gametype == MAPINFO_TYPE_LMS)
4059                         {
4060                                 entity sk;
4061                                 sk = playerslots[player_localnum];
4062                                 if(sk.(scores[ps_primary]) >= 666)
4063                                         s = _("^1Match has already begun");
4064                                 else if(sk.(scores[ps_primary]) > 0)
4065                                         s = _("^1You have no more lives left");
4066                                 else
4067                                         s = sprintf(_("^1Press ^3%s^1 to join"), getcommandkey("jump", "+jump"));
4068                         }
4069                         else
4070                                 s = sprintf(_("^1Press ^3%s^1 to join"), getcommandkey("jump", "+jump"));
4071                         drawInfoMessage(s)
4072
4073                         //show restart countdown:
4074                         if (time < getstatf(STAT_GAMESTARTTIME)) {
4075                                 float countdown;
4076                                 //we need to ceil, otherwise the countdown would be off by .5 when using round()
4077                                 countdown = ceil(getstatf(STAT_GAMESTARTTIME) - time);
4078                                 s = sprintf(_("^1Game starts in ^3%d^1 seconds"), countdown);
4079                                 drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
4080                                 o_y += fontsize_y;
4081                         }
4082                 }
4083                 if(warmup_stage && !intermission)
4084                 {
4085                         s = _("^2Currently in ^1warmup^2 stage!");
4086                         drawInfoMessage(s)
4087                 }
4088
4089                 string blinkcolor;
4090                 if(mod(time, 1) >= 0.5)
4091                         blinkcolor = "^1";
4092                 else
4093                         blinkcolor = "^3";
4094
4095                 if(ready_waiting && !intermission && !spectatee_status)
4096                 {
4097                         if(ready_waiting_for_me)
4098                         {
4099                                 if(warmup_stage)
4100                                         s = sprintf(_("%sPress ^3%s%s to end warmup"), blinkcolor, getcommandkey("ready", "ready"), blinkcolor);
4101                                 else
4102                                         s = sprintf(_("%sPress ^3%s%s once you are ready"), blinkcolor, getcommandkey("ready", "ready"), blinkcolor);
4103                         }
4104                         else
4105                         {
4106                                 if(warmup_stage)
4107                                         s = _("^2Waiting for others to ready up to end warmup...");
4108                                 else
4109                                         s = _("^2Waiting for others to ready up...");
4110                         }
4111                         drawInfoMessage(s)
4112                 }
4113                 else if(warmup_stage && !intermission && !spectatee_status)
4114                 {
4115                         s = sprintf(_("^2Press ^3%s^2 to end warmup"), getcommandkey("ready", "ready"));
4116                         drawInfoMessage(s)
4117                 }
4118
4119                 if(teamplay && !intermission && !spectatee_status && gametype != MAPINFO_TYPE_CA && teamnagger)
4120                 {
4121                         float ts_min = 0, ts_max = 0;
4122                         tm = teams.sort_next;
4123                         if (tm)
4124                         {
4125                                 for(; tm.sort_next; tm = tm.sort_next)
4126                                 {
4127                                         if(!tm.team_size || tm.team == FL_SPECTATOR)
4128                                                 continue;
4129                                         if(!ts_min) ts_min = tm.team_size;
4130                                         else ts_min = min(ts_min, tm.team_size);
4131                                         if(!ts_max) ts_max = tm.team_size;
4132                                         else ts_max = max(ts_max, tm.team_size);
4133                                 }
4134                                 if ((ts_max - ts_min) > 1)
4135                                 {
4136                                         s = strcat(blinkcolor, _("Teamnumbers are unbalanced!"));
4137                                         tm = GetTeam(myteam, false);
4138                                         if (tm)
4139                                         if (tm.team != FL_SPECTATOR)
4140                                         if (tm.team_size == ts_max)
4141                                                 s = strcat(s, sprintf(_(" Press ^3%s%s to adjust"), getcommandkey("team menu", "menu_showteamselect"), blinkcolor));
4142                                         drawInfoMessage(s)
4143                                 }
4144                         }
4145                 }
4146         }
4147         else 
4148         {
4149                 s = _("^7Press ^3ESC ^7to show HUD options.");
4150                 drawInfoMessage(s)
4151                 s = _("^3Doubleclick ^7a panel for panel-specific options.");
4152                 drawInfoMessage(s)
4153                 s = _("^3CTRL ^7to disable collision testing, ^3SHIFT ^7and");
4154                 drawInfoMessage(s)
4155                 s = _("^3ALT ^7+ ^3ARROW KEYS ^7for fine adjustments.");
4156                 drawInfoMessage(s)
4157         }
4158 }
4159
4160 // Physics panel (#15)
4161 //
4162 vector acc_prevspeed;
4163 float acc_prevtime, acc_avg, top_speed, top_speed_time;
4164 void HUD_Physics(void)
4165 {
4166         if(!autocvar__hud_configure)
4167         {
4168                 if(!autocvar_hud_panel_physics) return;
4169                 if(spectatee_status == -1 && (autocvar_hud_panel_physics == 1 || autocvar_hud_panel_physics == 3)) return;
4170                 if(autocvar_hud_panel_physics == 3 && !(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return;
4171         }
4172         else
4173                 hud_configure_active_panel = HUD_PANEL_PHYSICS;
4174
4175         HUD_Panel_UpdateCvars(physics);
4176         HUD_Panel_ApplyFadeAlpha();
4177
4178         draw_beginBoldFont();
4179
4180         HUD_Panel_DrawBg(1);
4181         if(panel_bg_padding)
4182         {
4183                 panel_pos += '1 1 0' * panel_bg_padding;
4184                 panel_size -= '2 2 0' * panel_bg_padding;
4185         }
4186
4187         float acceleration_progressbar_scale = 0;
4188         if(autocvar_hud_panel_physics_progressbar && autocvar_hud_panel_physics_acceleration_progressbar_scale > 1)
4189                 acceleration_progressbar_scale = autocvar_hud_panel_physics_acceleration_progressbar_scale;
4190
4191         float text_scale;
4192         if (autocvar_hud_panel_physics_text_scale <= 0)
4193                 text_scale = 1;
4194         else
4195                 text_scale = min(autocvar_hud_panel_physics_text_scale, 1);
4196
4197         //compute speed
4198         float speed, conversion_factor;
4199         string unit;
4200
4201         switch(autocvar_hud_panel_physics_speed_unit)
4202         {
4203                 default:
4204                 case 1:
4205                         unit = _(" qu/s");
4206                         conversion_factor = 1.0;
4207                         break;
4208                 case 2:
4209                         unit = _(" m/s");
4210                         conversion_factor = 0.0254;
4211                         break;
4212                 case 3:
4213                         unit = _(" km/h");
4214                         conversion_factor = 0.0254 * 3.6;
4215                         break;
4216                 case 4:
4217                         unit = _(" mph");
4218                         conversion_factor = 0.0254 * 3.6 * 0.6213711922;
4219                         break;
4220                 case 5:
4221                         unit = _(" knots");
4222                         conversion_factor = 0.0254 * 1.943844492; // 1 m/s = 1.943844492 knots, because 1 knot = 1.852 km/h
4223                         break;
4224         }
4225         
4226         vector vel = (csqcplayer ? csqcplayer.velocity : pmove_vel);
4227
4228         float max_speed = floor( autocvar_hud_panel_physics_speed_max * conversion_factor + 0.5 );
4229         if (autocvar__hud_configure)
4230                 speed = floor( max_speed * 0.65 + 0.5 );
4231         else if(autocvar_hud_panel_physics_speed_vertical)
4232                 speed = floor( vlen(vel) * conversion_factor + 0.5 );
4233         else
4234                 speed = floor( vlen(vel - vel_z * '0 0 1') * conversion_factor + 0.5 );
4235
4236         //compute acceleration
4237         float acceleration, f;
4238         if (autocvar__hud_configure)
4239                 acceleration = autocvar_hud_panel_physics_acceleration_max * 0.3;
4240         else
4241         {
4242                 // 1 m/s = 0.0254 qu/s; 1 g = 9.80665 m/s^2
4243                 f = time - acc_prevtime;
4244                 if(autocvar_hud_panel_physics_acceleration_vertical)
4245                         acceleration = (vlen(vel) - vlen(acc_prevspeed));
4246                 else
4247                         acceleration = (vlen(vel - '0 0 1' * vel_z) - vlen(acc_prevspeed - '0 0 1' * acc_prevspeed_z));
4248                 
4249                 acceleration = acceleration * (1 / max(0.0001, f)) * (0.0254 / 9.80665);
4250                 
4251                 acc_prevspeed = vel;
4252                 acc_prevtime = time;
4253
4254                 f = bound(0, f * 10, 1);
4255                 acc_avg = acc_avg * (1 - f) + acceleration * f;
4256         }
4257
4258         //compute layout
4259         float panel_ar = panel_size_x/panel_size_y;
4260         vector speed_offset = '0 0 0', acceleration_offset = '0 0 0';
4261         if (panel_ar >= 5 && !acceleration_progressbar_scale)
4262         {
4263                 panel_size_x *= 0.5;
4264                 if (autocvar_hud_panel_physics_flip)
4265                         speed_offset_x = panel_size_x;
4266                 else
4267                         acceleration_offset_x = panel_size_x;
4268         }
4269         else
4270         {
4271                 panel_size_y *= 0.5;
4272                 if (autocvar_hud_panel_physics_flip)
4273                         speed_offset_y = panel_size_y;
4274                 else
4275                         acceleration_offset_y = panel_size_y;
4276         }
4277         float speed_baralign, acceleration_baralign;
4278         if (autocvar_hud_panel_physics_baralign == 1)
4279                 acceleration_baralign = speed_baralign = 1;
4280     else if(autocvar_hud_panel_physics_baralign == 4)
4281                 acceleration_baralign = speed_baralign = 2;
4282         else if (autocvar_hud_panel_physics_flip)
4283         {
4284                 acceleration_baralign = (autocvar_hud_panel_physics_baralign == 2);
4285                 speed_baralign = (autocvar_hud_panel_physics_baralign == 3);
4286         }
4287         else
4288         {
4289                 speed_baralign = (autocvar_hud_panel_physics_baralign == 2);
4290                 acceleration_baralign = (autocvar_hud_panel_physics_baralign == 3);
4291         }
4292         if (autocvar_hud_panel_physics_acceleration_progressbar_mode == 0)
4293                 acceleration_baralign = 3; //override hud_panel_physics_baralign value for acceleration
4294
4295         //draw speed
4296         if(speed)
4297         if(autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 2)
4298         {
4299                 HUD_Panel_GetProgressBarColor(speed);
4300                 HUD_Panel_DrawProgressBar(panel_pos + speed_offset, panel_size, "progressbar", speed/max_speed, 0, speed_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
4301         }
4302         vector tmp_offset = '0 0 0', tmp_size = '0 0 0';
4303         if (autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 2)
4304         {
4305                 tmp_size_x = panel_size_x * 0.75;
4306                 tmp_size_y = panel_size_y * text_scale;
4307                 if (speed_baralign)
4308                         tmp_offset_x = panel_size_x - tmp_size_x;
4309                 //else
4310                         //tmp_offset_x = 0;
4311                 tmp_offset_y = (panel_size_y - tmp_size_y) / 2;
4312                 drawstring_aspect(panel_pos + speed_offset + tmp_offset, ftos(speed), tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4313
4314                 //draw speed unit
4315                 if (speed_baralign)
4316                         tmp_offset_x = 0;
4317                 else
4318                         tmp_offset_x = tmp_size_x;
4319                 if (autocvar_hud_panel_physics_speed_unit_show)
4320                 {
4321                         //tmp_offset_y = 0;
4322                         tmp_size_x = panel_size_x * (1 - 0.75);
4323                         tmp_size_y = panel_size_y * 0.4 * text_scale;
4324                         tmp_offset_y = (panel_size_y * 0.4 - tmp_size_y) / 2;
4325                         drawstring_aspect(panel_pos + speed_offset + tmp_offset, unit, tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4326                 }
4327         }
4328
4329         //compute and draw top speed
4330         if (autocvar_hud_panel_physics_topspeed)
4331         if (autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 2)
4332         {
4333                 if (autocvar__hud_configure)
4334                 {
4335                         top_speed = floor( max_speed * 0.75 + 0.5 );
4336                         f = 1;
4337                 }
4338                 else
4339                 {
4340                         if (speed >= top_speed)
4341                         {
4342                                 top_speed = speed;
4343                                 top_speed_time = time;
4344                         }
4345                         if (top_speed != 0)
4346                         {
4347                                 f = max(1, autocvar_hud_panel_physics_topspeed_time);
4348                                 // divide by f to make it start from 1
4349                                 f = cos( ((time - top_speed_time) / f) * PI/2 );
4350                         }
4351             else //hide top speed 0, it would be stupid
4352                                 f = 0;
4353                 }
4354                 if (f > 0)
4355                 {
4356                         //top speed progressbar peak
4357                         if(speed < top_speed)
4358                         if(autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 2)
4359                         {
4360                                 float peak_offset_x;
4361                                 vector peak_size = '0 0 0';
4362                                 if (speed_baralign == 0)
4363                                         peak_offset_x = min(top_speed, max_speed)/max_speed * panel_size_x;
4364                 else if (speed_baralign == 1)
4365                                         peak_offset_x = (1 - min(top_speed, max_speed)/max_speed) * panel_size_x;
4366                 else // if (speed_baralign == 2)
4367                     peak_offset_x = min(top_speed, max_speed)/max_speed * panel_size_x * 0.5;
4368                                 //if speed is not 0 the speed progressbar already fetched the color
4369                                 if (speed == 0)
4370                                         HUD_Panel_GetProgressBarColor(speed);
4371                                 peak_size_x = floor(panel_size_x * 0.01 + 1.5);
4372                 peak_size_y = panel_size_y;
4373                 if (speed_baralign == 2) // draw two peaks, on both sides
4374                 {
4375                     drawfill(panel_pos + speed_offset + eX * (0.5 * panel_size_x + peak_offset_x - peak_size_x), peak_size, progressbar_color, f * autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
4376                     drawfill(panel_pos + speed_offset + eX * (0.5 * panel_size_x - peak_offset_x + peak_size_x), peak_size, progressbar_color, f * autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
4377                 }
4378                 else
4379                     drawfill(panel_pos + speed_offset + eX * (peak_offset_x - peak_size_x), peak_size, progressbar_color, f * autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
4380                         }
4381
4382                         //top speed
4383                         tmp_offset_y = panel_size_y * 0.4;
4384                         tmp_size_x = panel_size_x * (1 - 0.75);
4385                         tmp_size_y = (panel_size_y - tmp_offset_y) * text_scale;
4386                         tmp_offset_y += (panel_size_y - tmp_offset_y - tmp_size_y) / 2;
4387                         drawstring_aspect(panel_pos + speed_offset + tmp_offset, ftos(top_speed), tmp_size, '1 0 0', f * panel_fg_alpha, DRAWFLAG_NORMAL);
4388                 }
4389                 else
4390                         top_speed = 0;
4391         }
4392
4393         //draw acceleration
4394         if(acceleration)
4395         if(autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 3)
4396         {
4397                 if (acceleration < 0)
4398                         HUD_Panel_GetProgressBarColor(acceleration_neg);
4399                 else
4400                         HUD_Panel_GetProgressBarColor(acceleration);
4401
4402                 f = acceleration/autocvar_hud_panel_physics_acceleration_max;
4403                 if (autocvar_hud_panel_physics_acceleration_progressbar_nonlinear)
4404                         f = sqrt(f);
4405
4406                 if (acceleration_progressbar_scale) // allow progressbar to go out of panel bounds
4407                 {
4408                         tmp_size = acceleration_progressbar_scale * panel_size_x * eX + panel_size_y * eY;
4409
4410                         if (acceleration_baralign == 1)
4411                                 tmp_offset_x = panel_size_x - tmp_size_x;
4412                         else if (acceleration_baralign == 2 || acceleration_baralign == 3)
4413                                 tmp_offset_x = (panel_size_x - tmp_size_x) / 2;
4414                         else
4415                                 tmp_offset_x = 0;
4416                         tmp_offset_y = 0;
4417                 }
4418                 else
4419                 {
4420                         tmp_size = panel_size;
4421                         tmp_offset = '0 0 0';
4422                 }
4423
4424                 HUD_Panel_DrawProgressBar(panel_pos + acceleration_offset + tmp_offset, tmp_size, "accelbar", f, 0, acceleration_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
4425         }
4426         tmp_size_x = panel_size_x;
4427         tmp_size_y = panel_size_y * text_scale;
4428         tmp_offset_x = 0;
4429         tmp_offset_y = (panel_size_y - tmp_size_y) / 2;
4430         if (autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 3)
4431                 drawstring_aspect(panel_pos + acceleration_offset + tmp_offset, strcat(ftos_decimals(acceleration, 2), "g"), tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4432
4433         draw_endBoldFont();
4434 }
4435
4436 // CenterPrint (#16)
4437 //
4438 #define CENTERPRINT_MAX_MSGS 10
4439 #define CENTERPRINT_MAX_ENTRIES 50
4440 #define CENTERPRINT_SPACING 0.7
4441 float cpm_index;
4442 string centerprint_messages[CENTERPRINT_MAX_MSGS];
4443 float centerprint_msgID[CENTERPRINT_MAX_MSGS];
4444 float centerprint_time[CENTERPRINT_MAX_MSGS];
4445 float centerprint_expire_time[CENTERPRINT_MAX_MSGS];
4446 float centerprint_countdown_num[CENTERPRINT_MAX_MSGS];
4447 float centerprint_showing;
4448
4449 void centerprint_generic(float new_id, string strMessage, float duration, float countdown_num)
4450 {
4451         float i, j;
4452
4453         if(strMessage == "" && new_id == 0)
4454                 return;
4455
4456         // strip trailing newlines
4457         j = strlen(strMessage) - 1;
4458         while(substring(strMessage, j, 1) == "\n" && j >= 0)
4459                 --j;
4460         if (j < strlen(strMessage) - 1)
4461                 strMessage = substring(strMessage, 0, j + 1);
4462
4463         if(strMessage == "" && new_id == 0)
4464                 return;
4465
4466         // strip leading newlines
4467         j = 0;
4468         while(substring(strMessage, j, 1) == "\n" && j < strlen(strMessage))
4469                 ++j;
4470         if (j > 0)
4471                 strMessage = substring(strMessage, j, strlen(strMessage) - j);
4472
4473         if(strMessage == "" && new_id == 0)
4474                 return;
4475
4476         if (!centerprint_showing)
4477                 centerprint_showing = TRUE;
4478
4479         for (i=0, j=cpm_index; i<CENTERPRINT_MAX_MSGS; ++i, ++j)
4480         {
4481                 if (j == CENTERPRINT_MAX_MSGS)
4482                         j = 0;
4483                 if (new_id && new_id == centerprint_msgID[j])
4484                 {
4485                         if (strMessage == "" && centerprint_messages[j] != "" && centerprint_countdown_num[j] == 0)
4486                         {
4487                                 // fade out the current msg (duration and countdown_num are ignored)
4488                                 centerprint_time[j] = min(5, autocvar_hud_panel_centerprint_fade_out);
4489                                 if (centerprint_expire_time[j] > time + min(5, autocvar_hud_panel_centerprint_fade_out) || centerprint_expire_time[j] < time)
4490                                         centerprint_expire_time[j] = time + min(5, autocvar_hud_panel_centerprint_fade_out);
4491                                 return;
4492                         }
4493                         break; // found a msg with the same id, at position j
4494                 }
4495         }
4496
4497         if (i == CENTERPRINT_MAX_MSGS)
4498         {
4499                 // a msg with the same id was not found, add the msg at the next position
4500                 --cpm_index;
4501                 if (cpm_index == -1)
4502                         cpm_index = CENTERPRINT_MAX_MSGS - 1;
4503                 j = cpm_index;
4504         }
4505         if(centerprint_messages[j])
4506                 strunzone(centerprint_messages[j]);
4507         centerprint_messages[j] = strzone(strMessage);
4508         centerprint_msgID[j] = new_id;
4509         if (duration < 0)
4510                 centerprint_time[j] = -1;
4511         else
4512         {
4513                 if(duration == 0)
4514                         duration = max(1, autocvar_hud_panel_centerprint_time);
4515                 centerprint_time[j] = duration;
4516                 centerprint_expire_time[j] = time + duration;
4517         }
4518         centerprint_countdown_num[j] = countdown_num;
4519 }
4520
4521 void centerprint_hud(string strMessage)
4522 {
4523         centerprint_generic(0, strMessage, autocvar_hud_panel_centerprint_time, 0);
4524 }
4525
4526 void reset_centerprint_messages(void)
4527 {
4528         float i;
4529         for (i=0; i<CENTERPRINT_MAX_MSGS; ++i)
4530         {
4531                 centerprint_expire_time[i] = 0;
4532                 centerprint_time[i] = 1;
4533                 centerprint_msgID[i] = 0;
4534                 if(centerprint_messages[i])
4535                         strunzone(centerprint_messages[i]);
4536                 centerprint_messages[i] = string_null;
4537         }
4538 }
4539 float hud_configure_cp_generation_time;
4540 void HUD_CenterPrint (void)
4541 {
4542         if(!autocvar__hud_configure)
4543         {
4544                 if(!autocvar_hud_panel_centerprint) return;
4545
4546                 if (hud_configure_prev && hud_configure_prev != -1)
4547                         reset_centerprint_messages();
4548         }
4549         else
4550         {
4551                 hud_configure_active_panel = HUD_PANEL_CENTERPRINT;
4552
4553                 if (!hud_configure_prev)
4554                         reset_centerprint_messages();
4555                 if (time > hud_configure_cp_generation_time)
4556                 {
4557                         float r;
4558                         r = random();
4559                         if (r > 0.9)
4560                                 centerprint_generic(floor(r*1000), strcat(sprintf("^3Countdown message at time %s", seconds_tostring(time)), ", seconds left: %d"), 1, 10);
4561                         else if (r > 0.8)
4562                                 centerprint_generic(0, sprintf("^1Multiline message at time %s that\n^1lasts longer than normal", seconds_tostring(time)), 20, 0);
4563                         else
4564                                 centerprint_hud(sprintf("Message at time %s", seconds_tostring(time)));
4565                         hud_configure_cp_generation_time = time + 1 + random()*4;
4566                 }
4567         }
4568
4569         HUD_Panel_UpdateCvars(centerprint);
4570
4571         // this panel doesn't fade when showing the scoreboard
4572         if(autocvar__menu_alpha)
4573                 HUD_Panel_ApplyFadeAlpha();
4574
4575         if(scoreboard_fade_alpha)
4576         {
4577                 // move the panel below the scoreboard
4578                 if (scoreboard_bottom >= 0.96 * vid_conheight)
4579                         return;
4580                 vector target_pos;
4581                 
4582                 target_pos = eY * scoreboard_bottom + eX * 0.5 * (vid_conwidth - panel_size_x);
4583                 
4584                 if(target_pos_y > panel_pos_y)
4585                 {
4586                         panel_pos = panel_pos + (target_pos - panel_pos) * sqrt(scoreboard_fade_alpha);
4587                         panel_size_y = min(panel_size_y, vid_conheight - scoreboard_bottom);
4588                 }
4589         }
4590
4591         HUD_Panel_DrawBg(1);
4592
4593         if (!centerprint_showing)
4594                 return;
4595
4596         if(panel_bg_padding)
4597         {
4598                 panel_pos += '1 1 0' * panel_bg_padding;
4599                 panel_size -= '2 2 0' * panel_bg_padding;
4600         }
4601
4602         float entries, height;
4603         vector fontsize;
4604         // entries = bound(1, floor(CENTERPRINT_MAX_ENTRIES * 4 * panel_size_y/panel_size_x), CENTERPRINT_MAX_ENTRIES);
4605         // height = panel_size_y/entries;
4606         // fontsize = '1 1 0' * height;
4607         height = vid_conheight/50 * autocvar_hud_panel_centerprint_fontscale;
4608         fontsize = '1 1 0' * height;
4609         entries = bound(1, floor(panel_size_y/height), CENTERPRINT_MAX_ENTRIES);
4610
4611         float i, j, k, n;
4612         float a, sz, align, current_msg_pos_y = 0, msg_size;
4613         vector pos;
4614         string ts;
4615
4616         n = -1; // if no msg will be displayed, n stays -1
4617
4618         pos = panel_pos;
4619         if (autocvar_hud_panel_centerprint_flip)
4620                 pos_y += panel_size_y;
4621         align = bound(0, autocvar_hud_panel_centerprint_align, 1);
4622         for (i=0, j=cpm_index; i<CENTERPRINT_MAX_MSGS; ++i, ++j)
4623         {
4624                 if (j == CENTERPRINT_MAX_MSGS)
4625                         j = 0;
4626                 if (centerprint_expire_time[j] <= time)
4627                 {
4628                         if (centerprint_countdown_num[j] && centerprint_time[j] > 0)
4629                         {
4630                                 centerprint_countdown_num[j] = centerprint_countdown_num[j] - 1;
4631                                 if (centerprint_countdown_num[j] == 0)
4632                                         continue;
4633                                 centerprint_expire_time[j] = centerprint_expire_time[j] + centerprint_time[j];
4634                         }
4635                         else
4636                                 continue;
4637                 }
4638                 
4639                 // fade the centerprint_hud in/out 
4640                 if (centerprint_time[j] < 0 || centerprint_expire_time[j] - autocvar_hud_panel_centerprint_fade_out > time)
4641                         a = bound(0, (time - (centerprint_expire_time[j] - centerprint_time[j])) / max(0.0001, autocvar_hud_panel_centerprint_fade_in), 1);
4642                 else if (centerprint_expire_time[j] > time)
4643                         a = (centerprint_expire_time[j] - time) / max(0.0001, autocvar_hud_panel_centerprint_fade_out);
4644                 else
4645                         a = 0;
4646                 
4647                 // set the size from fading in/out before subsequent fading
4648                 sz = autocvar_hud_panel_centerprint_fade_minfontsize + a * (1 - autocvar_hud_panel_centerprint_fade_minfontsize); 
4649                 
4650                 // also fade it based on positioning
4651                 if(autocvar_hud_panel_centerprint_fade_subsequent)
4652                 {
4653                         a = a * bound(autocvar_hud_panel_centerprint_fade_subsequent_passone_minalpha, (1 - (i / max(1, autocvar_hud_panel_centerprint_fade_subsequent_passone))), 1); // pass one: all messages after the first have half theAlpha
4654                         a = a * bound(autocvar_hud_panel_centerprint_fade_subsequent_passtwo_minalpha, (1 - (i / max(1, autocvar_hud_panel_centerprint_fade_subsequent_passtwo))), 1); // pass two: after that, gradually lower theAlpha even more for each message
4655                 }
4656                 
4657                 // finally set the size based on the new theAlpha from subsequent fading
4658                 sz = sz * (autocvar_hud_panel_centerprint_fade_subsequent_minfontsize + a * (1 - autocvar_hud_panel_centerprint_fade_subsequent_minfontsize)); 
4659                 drawfontscale = sz * '1 1 0';
4660                 
4661                 if (centerprint_countdown_num[j])
4662                         n = tokenizebyseparator(sprintf(centerprint_messages[j], centerprint_countdown_num[j]), "\n");
4663                 else
4664                         n = tokenizebyseparator(centerprint_messages[j], "\n");
4665
4666                 if (autocvar_hud_panel_centerprint_flip)
4667                 {
4668                         // check if the message can be entirely shown
4669                         for(k = 0; k < n; ++k)
4670                         {
4671                                 getWrappedLine_remaining = argv(k);
4672                                 while(getWrappedLine_remaining)
4673                                 {
4674                                         ts = getWrappedLine(panel_size_x * sz, fontsize, stringwidth_colors);
4675                                         if (ts != "")
4676                                                 pos_y -= fontsize_y;
4677                                         else
4678                                                 pos_y -= fontsize_y * CENTERPRINT_SPACING/2;
4679                                 }
4680                         }
4681                         current_msg_pos_y = pos_y; // save starting pos (first line) of the current message
4682                 }
4683
4684                 msg_size = pos_y;
4685                 for(k = 0; k < n; ++k)
4686                 {
4687                         getWrappedLine_remaining = argv(k);
4688                         while(getWrappedLine_remaining)
4689                         {
4690                                 ts = getWrappedLine(panel_size_x * sz, fontsize, stringwidth_colors);
4691                                 if (ts != "")
4692                                 {
4693                                         if (align)
4694                                                 pos_x = panel_pos_x + (panel_size_x - stringwidth(ts, TRUE, fontsize)) * align;
4695                                         drawcolorcodedstring(pos + eY * 0.5 * (1 - sz) * fontsize_y, ts, fontsize, a * panel_fg_alpha, DRAWFLAG_NORMAL);
4696                                         pos_y += fontsize_y;
4697                                 }
4698                                 else
4699                                         pos_y += fontsize_y * CENTERPRINT_SPACING/2;
4700                         }
4701                 }
4702                 msg_size = pos_y - msg_size;
4703                 if (autocvar_hud_panel_centerprint_flip)
4704                 {
4705                         pos_y = current_msg_pos_y - CENTERPRINT_SPACING * fontsize_y;
4706                         if (a < 1 && centerprint_msgID[j] == 0) // messages with id can be replaced just after they are faded out, so never move over them the next messages
4707                                 pos_y += (msg_size + CENTERPRINT_SPACING * fontsize_y) * (1 - sqrt(sz));
4708                                 
4709                         if (pos_y < panel_pos_y) // check if the next message can be shown
4710                         {
4711                                 drawfontscale = '1 1 0';
4712                                 return;
4713                         }
4714                 }
4715                 else
4716                 {
4717                         pos_y += CENTERPRINT_SPACING * fontsize_y;
4718                         if (a < 1 && centerprint_msgID[j] == 0) // messages with id can be replaced just after they are faded out, so never move over them the next messages
4719                                 pos_y -= (msg_size + CENTERPRINT_SPACING * fontsize_y) * (1 - sqrt(sz));
4720                                 
4721                         if(pos_y > panel_pos_y + panel_size_y - fontsize_y) // check if the next message can be shown
4722                         {
4723                                 drawfontscale = '1 1 0';
4724                                 return;
4725                         }
4726                 }
4727         }
4728         drawfontscale = '1 1 0';
4729         if (n == -1)
4730         {
4731                 centerprint_showing = FALSE;
4732                 reset_centerprint_messages();
4733         }
4734 }
4735
4736 /*
4737 ==================
4738 Main HUD system
4739 ==================
4740 */
4741
4742 void HUD_Reset (void)
4743 {
4744         // reset gametype specific icons
4745         if(gametype == MAPINFO_TYPE_KEYHUNT)
4746                 HUD_Mod_KH_Reset();
4747         else if(gametype == MAPINFO_TYPE_CTF)
4748                 HUD_Mod_CTF_Reset();
4749 }
4750
4751 #define HUD_DrawPanel(id)\
4752 switch (id) {\
4753         case (HUD_PANEL_RADAR):\
4754                 HUD_Radar(); break;\
4755         case (HUD_PANEL_WEAPONS):\
4756                 HUD_Weapons(); break;\
4757         case (HUD_PANEL_AMMO):\
4758                 HUD_Ammo(); break;\
4759         case (HUD_PANEL_POWERUPS):\
4760                 HUD_Powerups(); break;\
4761         case (HUD_PANEL_HEALTHARMOR):\
4762                 HUD_HealthArmor(); break;\
4763         case (HUD_PANEL_NOTIFY):\
4764                 HUD_Notify(); break;\
4765         case (HUD_PANEL_TIMER):\
4766                 HUD_Timer(); break;\
4767         case (HUD_PANEL_SCORE):\
4768                 HUD_Score(); break;\
4769         case (HUD_PANEL_RACETIMER):\
4770                 HUD_RaceTimer(); break;\
4771         case (HUD_PANEL_VOTE):\
4772                 HUD_VoteWindow(); break;\
4773         case (HUD_PANEL_MODICONS):\
4774                 HUD_ModIcons(); break;\
4775         case (HUD_PANEL_PRESSEDKEYS):\
4776                 HUD_DrawPressedKeys(); break;\
4777         case (HUD_PANEL_CHAT):\
4778                 HUD_Chat(); break;\
4779         case (HUD_PANEL_ENGINEINFO):\
4780                 HUD_EngineInfo(); break;\
4781         case (HUD_PANEL_INFOMESSAGES):\
4782                 HUD_InfoMessages(); break;\
4783         case (HUD_PANEL_PHYSICS):\
4784                 HUD_Physics(); break;\
4785         case (HUD_PANEL_CENTERPRINT):\
4786                 HUD_CenterPrint(); break;\
4787 } ENDS_WITH_CURLY_BRACE
4788
4789 void HUD_Main (void)
4790 {
4791         float i;
4792         // global hud theAlpha fade
4793         if(menu_enabled == 1)
4794                 hud_fade_alpha = 1;
4795         else
4796                 hud_fade_alpha = (1 - autocvar__menu_alpha);
4797
4798         if(scoreboard_fade_alpha)
4799                 hud_fade_alpha = (1 - scoreboard_fade_alpha);
4800
4801         if(autocvar__hud_configure)
4802                 if(isdemo())
4803                         HUD_Configure_Exit_Force();
4804
4805         if(intermission == 2) // no hud during mapvote
4806         {
4807                 if (autocvar__hud_configure)
4808                         HUD_Configure_Exit_Force();
4809                 hud_fade_alpha = 0;
4810         }
4811         else if(autocvar__menu_alpha == 0 && scoreboard_fade_alpha == 0)
4812                 hud_fade_alpha = 1;
4813
4814         // panels that we want to be active together with the scoreboard
4815         // they must call HUD_Panel_ApplyFadeAlpha(); only when showing the menu
4816         if(scoreboard_fade_alpha == 1)
4817         {
4818                 HUD_CenterPrint();
4819                 return;
4820         }
4821
4822         if(!autocvar__hud_configure && !hud_fade_alpha)
4823                 return;
4824
4825         // Drawing stuff
4826         if (hud_skin_path != autocvar_hud_skin)
4827         {
4828                 if (hud_skin_path)
4829                         strunzone(hud_skin_path);
4830                 hud_skin_path = strzone(strcat("gfx/hud/", autocvar_hud_skin));
4831         }
4832
4833         // HUD configure visible grid
4834         if(autocvar__hud_configure && autocvar_hud_configure_grid && autocvar_hud_configure_grid_alpha)
4835         {
4836                 hud_configure_gridSize_x = bound(0.005, cvar("hud_configure_grid_xsize"), 0.2);
4837                 hud_configure_gridSize_y = bound(0.005, cvar("hud_configure_grid_ysize"), 0.2);
4838                 hud_configure_realGridSize_x = hud_configure_gridSize_x * vid_conwidth;
4839                 hud_configure_realGridSize_y = hud_configure_gridSize_y * vid_conheight;
4840                 vector s;
4841                 // x-axis
4842                 s = eX + eY * vid_conheight;
4843                 for(i = 1; i < 1/hud_configure_gridSize_x; ++i)
4844                         drawfill(eX * i * hud_configure_realGridSize_x, s, '0.5 0.5 0.5', autocvar_hud_configure_grid_alpha, DRAWFLAG_NORMAL);
4845                 // y-axis
4846                 s = eY + eX * vid_conwidth;
4847                 for(i = 1; i < 1/hud_configure_gridSize_y; ++i)
4848                         drawfill(eY * i * hud_configure_realGridSize_y, s, '0.5 0.5 0.5', autocvar_hud_configure_grid_alpha, DRAWFLAG_NORMAL);
4849         }
4850
4851 #ifdef COMPAT_XON050_ENGINE
4852     current_player = (spectatee_status > 0) ? spectatee_status : player_localentnum;
4853 #else
4854     current_player = player_localentnum;
4855 #endif
4856
4857         // draw the dock
4858         if(autocvar_hud_dock != "" && autocvar_hud_dock != "0")
4859         {
4860                 float f;
4861                 vector color;
4862                 float hud_dock_color_team = autocvar_hud_dock_color_team;
4863                 if((teamplay) && hud_dock_color_team) {
4864                         f = stof(getplayerkeyvalue(current_player - 1, "colors"));
4865                         color = colormapPaletteColor(mod(f, 16), 1) * hud_dock_color_team;
4866                 }
4867                 else if(autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && hud_dock_color_team) {
4868                         color = '1 0 0' * hud_dock_color_team;
4869                 }
4870                 else
4871                 {
4872                         string hud_dock_color = autocvar_hud_dock_color;
4873                         if(hud_dock_color == "shirt") {
4874                                 f = stof(getplayerkeyvalue(current_player - 1, "colors"));
4875                                 color = colormapPaletteColor(floor(f / 16), 0);
4876                         }
4877                         else if(hud_dock_color == "pants") {
4878                                 f = stof(getplayerkeyvalue(current_player - 1, "colors"));
4879                                 color = colormapPaletteColor(mod(f, 16), 1);
4880                         }
4881                         else
4882                                 color = stov(hud_dock_color);
4883                 }
4884
4885                 string pic;
4886                 pic = strcat(hud_skin_path, "/", autocvar_hud_dock);
4887                 if(precache_pic(pic) == "") {
4888                         pic = strcat(hud_skin_path, "/dock_medium");
4889                         if(precache_pic(pic) == "") {
4890                                 pic = "gfx/hud/default/dock_medium";
4891                         }
4892                 }
4893                 drawpic('0 0 0', pic, eX * vid_conwidth + eY * vid_conheight, color, autocvar_hud_dock_alpha * hud_fade_alpha, DRAWFLAG_NORMAL); // no aspect ratio forcing on dock...
4894         }
4895
4896         // cache the panel order into the panel_order array
4897         if(autocvar__hud_panelorder != hud_panelorder_prev) {
4898                 for(i = 0; i < HUD_PANEL_NUM; ++i)
4899                         panel_order[i] = -1;
4900                 string s = "";
4901                 float p_num, warning = false;
4902                 float argc = tokenize_console(autocvar__hud_panelorder);
4903                 if (argc > HUD_PANEL_NUM)
4904                         warning = true;
4905                 //first detect wrong/missing panel numbers
4906                 for(i = 0; i < HUD_PANEL_NUM; ++i) {
4907                         p_num = stof(argv(i));
4908                         if (p_num >= 0 && p_num < HUD_PANEL_NUM) { //correct panel number?
4909                                 if (panel_order[p_num] == -1) //found for the first time?
4910                                         s = strcat(s, ftos(p_num), " ");
4911                                 panel_order[p_num] = 1; //mark as found
4912                         }
4913                         else
4914                                 warning = true;
4915                 }
4916                 for(i = 0; i < HUD_PANEL_NUM; ++i) {
4917                         if (panel_order[i] == -1) {
4918                                 warning = true;
4919                                 s = strcat(s, ftos(i), " "); //add missing panel number
4920                         }
4921                 }
4922                 if (warning)
4923                         print(_("Automatically fixed wrong/missing panel numbers in _hud_panelorder\n"));
4924
4925                 cvar_set("_hud_panelorder", s);
4926                 if(hud_panelorder_prev)
4927                         strunzone(hud_panelorder_prev);
4928                 hud_panelorder_prev = strzone(s);
4929
4930                 //now properly set panel_order
4931                 tokenize_console(s);
4932                 for(i = 0; i < HUD_PANEL_NUM; ++i) {
4933                         panel_order[i] = stof(argv(i));
4934                 }
4935         }
4936
4937         hud_draw_maximized = 0;
4938         // draw panels in order specified by panel_order array
4939         for(i = HUD_PANEL_NUM - 1; i >= 0; --i)
4940                 HUD_DrawPanel(panel_order[i]);
4941
4942         hud_draw_maximized = 1; // panels that may be maximized must check this var
4943         // draw maximized panels on top
4944         if(hud_panel_radar_maximized)
4945                 HUD_Radar();
4946         if(autocvar__con_chat_maximized)
4947                 HUD_Chat();
4948
4949         if(autocvar__hud_configure)
4950         {
4951                 if(tab_panel != -1)
4952                 {
4953                         HUD_Panel_UpdatePosSizeForId(tab_panel)
4954                         drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .2, DRAWFLAG_NORMAL);
4955                 }
4956                 if(highlightedPanel != -1)
4957                 {
4958                         HUD_Panel_UpdatePosSizeForId(highlightedPanel);
4959                         HUD_Panel_HlBorder(panel_bg_border + 1.5 * hlBorderSize, '0 0.5 1', 0.25 * (1 - autocvar__menu_alpha));
4960                 }
4961                 if (!hud_configure_prev)
4962                 {
4963                         if(autocvar_hud_cursormode) { setcursormode(1); }
4964                         hudShiftState = 0;
4965                 }
4966         }
4967         else if (hud_configure_prev && autocvar_hud_cursormode)
4968                 setcursormode(0);
4969
4970         hud_configure_prev = autocvar__hud_configure;
4971
4972         if (!autocvar__hud_configure) // hud config mode disabled, enable normal theAlpha stuff again
4973                 if (menu_enabled)
4974                         menu_enabled = 0;
4975 }