Merge remote-tracking branch 'origin/master' into samual/notification_rewrite
[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;
465         float screen_ar, center_x = 0, 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 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                 if(timeout && time >= weapontime + timeout + timeout_effect_length)
496                 if(autocvar_hud_panel_weapons_timeout_effect == 3 || (autocvar_hud_panel_weapons_timeout_effect == 1 && !(autocvar_hud_panel_weapons_timeout_fadebgmin + autocvar_hud_panel_weapons_timeout_fadefgmin)))
497                 {
498                         weaponprevtime = time;
499                         return;
500                 }
501         }
502         else
503                 hud_configure_active_panel = HUD_PANEL_WEAPONS;
504
505         // update generic hud functions
506         HUD_Panel_UpdateCvars(weapons);
507         HUD_Panel_ApplyFadeAlpha();
508
509         draw_beginBoldFont();
510
511         // figure out weapon order (how the weapons are sorted) // TODO make this configurable
512         if(weaponorder_bypriority != autocvar_cl_weaponpriority || !weaponorder[0])
513         {
514                 float weapon_cnt;
515                 if(weaponorder_bypriority)
516                         strunzone(weaponorder_bypriority);
517                 if(weaponorder_byimpulse)
518                         strunzone(weaponorder_byimpulse);
519
520                 weaponorder_bypriority = strzone(autocvar_cl_weaponpriority);
521                 weaponorder_byimpulse = strzone(W_FixWeaponOrder_BuildImpulseList(W_FixWeaponOrder_ForceComplete(W_NumberWeaponOrder(weaponorder_bypriority))));
522                 weaponorder_cmp_str = strcat(" ", weaponorder_byimpulse, " ");
523
524                 weapon_cnt = 0;
525                 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
526                 {
527                         self = get_weaponinfo(i);
528                         if(self.impulse >= 0)
529                         {
530                                 weaponorder[weapon_cnt] = self;
531                                 ++weapon_cnt;
532                         }
533                 }
534                 for(i = weapon_cnt; i < WEP_MAXCOUNT; ++i)
535                         weaponorder[i] = world;
536                 heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, world);
537
538                 weaponorder_cmp_str = string_null;
539         }
540
541         // determine which weapons are going to be shown
542         if (autocvar_hud_panel_weapons_onlyowned)
543         {
544                 if(autocvar__hud_configure)
545                 {
546                         if (WEPSET_EMPTY_A(weapons_stat))
547                                 for(i = WEP_FIRST; i <= WEP_LAST; i += floor((WEP_LAST-WEP_FIRST)/5))
548                                         WEPSET_OR_AW(weapons_stat, i);
549
550                         if(menu_enabled != 2)
551                                 HUD_Panel_DrawBg(1); // also draw the bg of the entire panel
552                 }
553
554                 // do we own this weapon?
555                 weapon_count = 0;
556                 for(i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
557                         if(WEPSET_CONTAINS_AW(weapons_stat, weaponorder[i].weapon))
558                                 ++weapon_count;
559
560                 // add it anyway if weaponcomplain is shown
561                 if((!autocvar__hud_configure) 
562                         && (autocvar_hud_panel_weapons_complainbubble 
563                                 && time - complain_weapon_time < when + fadetime))
564                                         ++weapon_count;
565
566                 // might as well commit suicide now, no reason to live ;)
567                 if (weapon_count == 0) { return; }
568
569                 // reduce size of the panel
570                 if (panel_size_y > panel_size_x)
571                 {
572                         old_panel_size_y = panel_size_y;
573                         panel_size_y *= weapon_count / WEP_COUNT;
574                         panel_pos_y += (old_panel_size_y - panel_size_y) / 2;
575                 }
576                 else
577                 {
578                         old_panel_size_x = panel_size_x;
579                         panel_size_x *= weapon_count / WEP_COUNT;
580                         panel_pos_x += (old_panel_size_x - panel_size_x) / 2;
581                 }
582         }
583         else
584                 weapon_count = WEP_COUNT;
585
586         // animation for fading in/out the panel respectively when not in use
587         if(!autocvar__hud_configure)
588         {
589                 if (timeout && time >= weapontime + timeout) // apply timeout effect if needed
590                 {
591                         f = bound(0, (time - (weapontime + timeout)) / timeout_effect_length, 1);
592
593                         // fade the panel alpha
594                         if(autocvar_hud_panel_weapons_timeout_effect == 1)
595                         {
596                                 panel_bg_alpha *= (autocvar_hud_panel_weapons_timeout_fadebgmin * f + (1 - f));
597                                 panel_fg_alpha *= (autocvar_hud_panel_weapons_timeout_fadefgmin * f + (1 - f));
598                         }
599                         else if(autocvar_hud_panel_weapons_timeout_effect == 3)
600                         {
601                                 panel_bg_alpha *= (1 - f);
602                                 panel_fg_alpha *= (1 - f);
603                         }
604
605                         // move the panel off the screen
606                         if (autocvar_hud_panel_weapons_timeout_effect == 2 || autocvar_hud_panel_weapons_timeout_effect == 3)
607                         {
608                                 f *= f; // for a cooler movement
609                                 center_x = panel_pos_x + panel_size_x/2;
610                                 center_y = panel_pos_y + panel_size_y/2;
611                                 screen_ar = vid_conwidth/vid_conheight;
612                                 if (center_x/center_y < screen_ar) //bottom left
613                                 {
614                                         if ((vid_conwidth - center_x)/center_y < screen_ar) //bottom
615                                                 panel_pos_y += f * (vid_conheight - panel_pos_y);
616                                         else //left
617                                                 panel_pos_x -= f * (panel_pos_x + panel_size_x);
618                                 }
619                                 else //top right
620                                 {
621                                         if ((vid_conwidth - center_x)/center_y < screen_ar) //right
622                                                 panel_pos_x += f * (vid_conwidth - panel_pos_x);
623                                         else //top
624                                                 panel_pos_y -= f * (panel_pos_y + panel_size_y);
625                                 }
626                                 if(f == 1)
627                                         center_x = -1; // mark the panel as off screen
628                         }
629                         weaponprevtime = time - (1 - f) * timein_effect_length;
630                 }
631                 else if (timeout && time < weaponprevtime + timein_effect_length) // apply timein effect if needed
632                 {
633                         f = bound(0, (time - weaponprevtime) / timein_effect_length, 1);
634
635                         // fade the panel alpha
636                         if(autocvar_hud_panel_weapons_timeout_effect == 1)
637                         {
638                                 panel_bg_alpha *= (autocvar_hud_panel_weapons_timeout_fadebgmin * (1 - f) + f);
639                                 panel_fg_alpha *= (autocvar_hud_panel_weapons_timeout_fadefgmin * (1 - f) + f);
640                         }
641                         else if(autocvar_hud_panel_weapons_timeout_effect == 3)
642                         {
643                                 panel_bg_alpha *= (f);
644                                 panel_fg_alpha *= (f);
645                         }
646
647                         // move the panel back on screen
648                         if (autocvar_hud_panel_weapons_timeout_effect == 2 || autocvar_hud_panel_weapons_timeout_effect == 3)
649                         {
650                                 f *= f; // for a cooler movement
651                                 f = 1 - f;
652                                 center_x = panel_pos_x + panel_size_x/2;
653                                 center_y = panel_pos_y + panel_size_y/2;
654                                 screen_ar = vid_conwidth/vid_conheight;
655                                 if (center_x/center_y < screen_ar) //bottom left
656                                 {
657                                         if ((vid_conwidth - center_x)/center_y < screen_ar) //bottom
658                                                 panel_pos_y += f * (vid_conheight - panel_pos_y);
659                                         else //left
660                                                 panel_pos_x -= f * (panel_pos_x + panel_size_x);
661                                 }
662                                 else //top right
663                                 {
664                                         if ((vid_conwidth - center_x)/center_y < screen_ar) //right
665                                                 panel_pos_x += f * (vid_conwidth - panel_pos_x);
666                                         else //top
667                                                 panel_pos_y -= f * (panel_pos_y + panel_size_y);
668                                 }
669                         }
670                 }
671         }
672
673         // draw the background, then change the virtual size of it to better fit other items inside
674         HUD_Panel_DrawBg(1);
675
676         if(center_x == -1)
677                 return;
678
679         if(panel_bg_padding)
680         {
681                 panel_pos += '1 1 0' * panel_bg_padding;
682                 panel_size -= '2 2 0' * panel_bg_padding;
683         }
684
685         // after the sizing and animations are done, update the other values
686         rows = panel_size_y/panel_size_x;
687         rows = bound(1, floor((sqrt(4 * aspect * rows * weapon_count + rows * rows) + rows + 0.5) / 2), weapon_count);
688         columns = ceil(weapon_count/rows);
689         weapon_size = eX * panel_size_x*(1/columns) + eY * panel_size_y*(1/rows);
690
691         // calculate position/size for visual bar displaying ammount of ammo status
692         if (autocvar_hud_panel_weapons_ammo)
693         {
694                 ammo_color = stov(autocvar_hud_panel_weapons_ammo_color);
695                 ammo_alpha = panel_fg_alpha * autocvar_hud_panel_weapons_ammo_alpha;
696
697                 if(weapon_size_x/weapon_size_y > aspect)
698                 {
699                         barsize_x = aspect * weapon_size_y;
700                         barsize_y = weapon_size_y;
701                         baroffset_x = (weapon_size_x - barsize_x) / 2;
702                 }
703                 else
704                 {
705                         barsize_y = 1/aspect * weapon_size_x;
706                         barsize_x = weapon_size_x;
707                         baroffset_y = (weapon_size_y - barsize_y) / 2;
708                 }
709         }
710         if(autocvar_hud_panel_weapons_accuracy)
711                 Accuracy_LoadColors();
712
713         row = column = 0;
714         for(i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
715         {
716                 // retrieve information about the current weapon to be drawn
717                 self = weaponorder[i];
718                 weapon_id = self.impulse;
719
720                 // skip if this weapon doesn't exist
721                 if (!self || self.impulse < 0) { continue; }
722
723                 // skip this weapon if we don't own it (and onlyowned is enabled)-- or if weapons_complainbubble is showing for this weapon
724                 if (autocvar_hud_panel_weapons_onlyowned
725                         && !(WEPSET_CONTAINS_AW(weapons_stat, self.weapon) 
726                         || (self.weapon == complain_weapon 
727                                 && time - complain_weapon_time < when + fadetime 
728                                 && autocvar_hud_panel_weapons_complainbubble)))
729                                         continue;
730
731                 // figure out the drawing position of weapon
732                 weapon_pos = (panel_pos 
733                         + eX * column * weapon_size_x 
734                         + eY * row * weapon_size_y);
735
736                 // draw background behind currently selected weapon
737                 if(self.weapon == switchweapon)
738                         drawpic_aspect_skin(weapon_pos, "weapon_current_bg", weapon_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
739
740                 // draw the weapon accuracy
741                 if(autocvar_hud_panel_weapons_accuracy)
742                 {
743                         panel_weapon_accuracy = weapon_accuracy[self.weapon-WEP_FIRST];
744                         if(panel_weapon_accuracy >= 0)
745                         {
746                                 color = Accuracy_GetColor(panel_weapon_accuracy);
747                                 drawpic_aspect_skin(weapon_pos, "weapon_accuracy", weapon_size, color, panel_fg_alpha, DRAWFLAG_NORMAL);
748                         }
749                 }
750
751                 // drawing all the weapon items
752                 if(WEPSET_CONTAINS_AW(weapons_stat, self.weapon))
753                 {
754                         // draw the weapon image
755                         drawpic_aspect_skin(weapon_pos, strcat("weapon", self.netname), weapon_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
756
757                         // draw weapon label string
758                         switch(autocvar_hud_panel_weapons_label)
759                         {
760                                 case 1: // weapon number
761                                         drawstring(weapon_pos, ftos(weapon_id), '1 1 0' * 0.5 * weapon_size_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
762                                         break;
763
764                                 case 2: // bind
765                                         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);
766                                         break;
767
768                                 case 3: // weapon name
769                                         drawstring(weapon_pos, self.netname, '1 1 0' * 0.5 * weapon_size_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
770                                         break;
771
772                                 default: // nothing
773                                         break;
774                         }
775
776                         // draw ammo status bar
777                         if(autocvar_hud_panel_weapons_ammo && self.weapon != WEP_TUBA && self.weapon != WEP_LASER && self.weapon != WEP_PORTO)
778                         {
779                                 a = 0;
780                                 ammo_type = GetAmmoTypeForWep(self.weapon);
781                                 if(ammo_type != -1)
782                                         a = getstati(GetAmmoStat(ammo_type)); // how much ammo do we have?
783
784                                 if(a > 0)
785                                 {
786                                         switch(ammo_type) {
787                                                 case 0: ammo_full = autocvar_hud_panel_weapons_ammo_full_shells; break;
788                                                 case 1: ammo_full = autocvar_hud_panel_weapons_ammo_full_nails; break;
789                                                 case 2: ammo_full = autocvar_hud_panel_weapons_ammo_full_rockets; break;
790                                                 case 3: ammo_full = autocvar_hud_panel_weapons_ammo_full_cells; break;
791                                                 case 4: ammo_full = autocvar_hud_panel_weapons_ammo_full_fuel; break;
792                                                 default: ammo_full = 60;
793                                         }
794
795                                         drawsetcliparea(
796                                                 weapon_pos_x + baroffset_x,
797                                                 weapon_pos_y + baroffset_y,
798                                                 barsize_x * bound(0, a/ammo_full, 1),
799                                                 barsize_y);
800                                         drawpic_aspect_skin(weapon_pos, "weapon_ammo", weapon_size, ammo_color, ammo_alpha, DRAWFLAG_NORMAL);
801                                         drawresetcliparea();
802                                 }
803                         }
804                 }
805                 else // draw a "ghost weapon icon" if you don't have the weapon
806                 {
807                         drawpic_aspect_skin(weapon_pos, strcat("weapon", self.netname), weapon_size, '0 0 0', panel_fg_alpha * 0.5, DRAWFLAG_NORMAL);
808                 }
809
810                 // draw the complain message
811                 if(time - complain_weapon_time < when + fadetime && self.weapon == complain_weapon && autocvar_hud_panel_weapons_complainbubble)
812                 {
813                         if(fadetime)
814                                 a = ((complain_weapon_time + when > time) ? 1 : bound(0, (complain_weapon_time + when + fadetime - time) / fadetime, 1));
815                         else
816                                 a = ((complain_weapon_time + when > time) ? 1 : 0);
817
818
819                         string s;
820                         if(complain_weapon_type == 0) {
821                                 s = _("Out of ammo");
822                                 color = stov(autocvar_hud_panel_weapons_complainbubble_color_outofammo);
823                         }
824                         else if(complain_weapon_type == 1) {
825                                 s = _("Don't have");
826                                 color = stov(autocvar_hud_panel_weapons_complainbubble_color_donthave);
827                         }
828                         else {
829                                 s = _("Unavailable");
830                                 color = stov(autocvar_hud_panel_weapons_complainbubble_color_unavailable);
831                         }
832                         float padding = autocvar_hud_panel_weapons_complainbubble_padding;
833                         drawpic_aspect_skin(weapon_pos + '1 1 0' * padding, "weapon_complainbubble", weapon_size - '2 2 0' * padding, color, a * panel_fg_alpha, DRAWFLAG_NORMAL);
834                         drawstring_aspect(weapon_pos + '1 1 0' * padding, s, weapon_size - '2 2 0' * padding, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
835                 }
836
837                 // continue with new position for the next weapon
838                 ++row;
839                 if(row >= rows)
840                 {
841                         row = 0;
842                         ++column;
843                 }
844         }
845
846         draw_endBoldFont();
847 }
848
849 // Ammo (#1)
850 //
851 // TODO: macro
852 float GetAmmoItemCode(float i)
853 {
854         switch(i)
855         {
856                 case 0: return IT_SHELLS;
857                 case 1: return IT_NAILS;
858                 case 2: return IT_ROCKETS;
859                 case 3: return IT_CELLS;
860                 case 4: return IT_FUEL;
861                 default: return -1;
862         }
863 }
864
865 string GetAmmoPicture(float i)
866 {
867         switch(i)
868         {
869                 case 0: return "ammo_shells";
870                 case 1: return "ammo_bullets";
871                 case 2: return "ammo_rockets";
872                 case 3: return "ammo_cells";
873                 case 4: return "ammo_fuel";
874                 default: return "";
875         }
876 }
877
878 void DrawAmmoItem(vector myPos, vector mySize, float itemcode, float currently_selected, float infinite_ammo)
879 {
880         float a;
881         if(autocvar__hud_configure)
882         {
883                 currently_selected = (itemcode == 2); //rockets always selected
884                 a = 31 + mod(itemcode*93, 128);
885         }
886         else
887                 a = getstati(GetAmmoStat(itemcode)); // how much ammo do we have of type itemcode?
888
889         vector color;
890         if(infinite_ammo)
891                 color = '0 0.5 0.75';
892         else if(a < 10)
893                 color = '0.7 0 0';
894         else
895                 color = '1 1 1';
896
897         float theAlpha;
898         if(currently_selected)
899                 theAlpha = 1;
900         else
901                 theAlpha = 0.7;
902
903         vector picpos, numpos;
904         if(autocvar_hud_panel_ammo_iconalign)
905         {
906                 numpos = myPos;
907                 picpos = myPos + eX * 2 * mySize_y;
908         }
909         else
910         {
911                 numpos = myPos + eX * mySize_y;
912                 picpos = myPos;
913         }
914
915         if (currently_selected)
916                 drawpic_aspect_skin(myPos, "ammo_current_bg", mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
917
918     if(a > 0 && autocvar_hud_panel_ammo_progressbar)
919         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);
920
921     if(autocvar_hud_panel_ammo_text)
922     {
923         if(a > 0 || infinite_ammo)
924             drawstring_aspect(numpos, ftos(a), eX * (2/3) * mySize_x + eY * mySize_y, color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
925         else // "ghost" ammo count
926             drawstring_aspect(numpos, ftos(a), eX * (2/3) * mySize_x + eY * mySize_y, '0 0 0', panel_fg_alpha * theAlpha * 0.5, DRAWFLAG_NORMAL);
927     }
928         if(a > 0 || infinite_ammo)
929                 drawpic_aspect_skin(picpos, GetAmmoPicture(itemcode), '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
930         else // "ghost" ammo icon
931                 drawpic_aspect_skin(picpos, GetAmmoPicture(itemcode), '1 1 0' * mySize_y, '0 0 0', panel_fg_alpha * theAlpha * 0.5, DRAWFLAG_NORMAL);
932 }
933
934 void HUD_Ammo(void)
935 {
936     if(hud != HUD_NORMAL) return;
937         if(!autocvar__hud_configure)
938         {
939                 if(!autocvar_hud_panel_ammo) return;
940                 if(spectatee_status == -1) return;
941         }
942         else
943                 hud_configure_active_panel = HUD_PANEL_AMMO;
944
945         HUD_Panel_UpdateCvars(ammo);
946         HUD_Panel_ApplyFadeAlpha();
947
948         draw_beginBoldFont();
949
950         vector pos, mySize;
951         pos = panel_pos;
952         mySize = panel_size;
953
954         HUD_Panel_DrawBg(1);
955         if(panel_bg_padding)
956         {
957                 pos += '1 1 0' * panel_bg_padding;
958                 mySize -= '2 2 0' * panel_bg_padding;
959         }
960
961         float rows = 0, columns, row, column;
962         vector ammo_size;
963         if (autocvar_hud_panel_ammo_onlycurrent)
964                 ammo_size = mySize;
965         else
966         {
967                 rows = mySize_y/mySize_x;
968                 rows = bound(1, floor((sqrt(4 * (3/1) * rows * AMMO_COUNT + rows * rows) + rows + 0.5) / 2), AMMO_COUNT);
969                 //                               ^^^ ammo item aspect goes here
970
971                 columns = ceil(AMMO_COUNT/rows);
972
973                 ammo_size = eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows);
974         }
975
976         local vector offset = '0 0 0'; // fteqcc sucks
977         float newSize;
978         if(ammo_size_x/ammo_size_y > 3)
979         {
980                 newSize = 3 * ammo_size_y;
981                 offset_x = ammo_size_x - newSize;
982                 pos_x += offset_x/2;
983                 ammo_size_x = newSize;
984         }
985         else
986         {
987                 newSize = 1/3 * ammo_size_x;
988                 offset_y = ammo_size_y - newSize;
989                 pos_y += offset_y/2;
990                 ammo_size_y = newSize;
991         }
992
993         float i, stat_items, currently_selected, infinite_ammo;
994         infinite_ammo = FALSE;
995         if (autocvar_hud_panel_ammo_onlycurrent)
996         {
997                 if(autocvar__hud_configure)
998                 {
999                         DrawAmmoItem(pos, ammo_size, 2, true, FALSE); //show rockets
1000                 }
1001                 else
1002                 {
1003                         stat_items = getstati(STAT_ITEMS, 0, 24);
1004                         if (stat_items & IT_UNLIMITED_WEAPON_AMMO)
1005                                 infinite_ammo = TRUE;
1006                         for (i = 0; i < AMMO_COUNT; ++i) {
1007                                 currently_selected = stat_items & GetAmmoItemCode(i);
1008                                 if (currently_selected)
1009                                 {
1010                                         DrawAmmoItem(pos, ammo_size, i, true, infinite_ammo);
1011                                         break;
1012                                 }
1013                         }
1014                 }
1015         }
1016         else
1017         {
1018                 stat_items = getstati(STAT_ITEMS, 0, 24);
1019                 if (stat_items & IT_UNLIMITED_WEAPON_AMMO)
1020                         infinite_ammo = TRUE;
1021                 row = column = 0;
1022                 for (i = 0; i < AMMO_COUNT; ++i) {
1023                         currently_selected = stat_items & GetAmmoItemCode(i);
1024                         DrawAmmoItem(pos + eX * column * (ammo_size_x + offset_x) + eY * row * (ammo_size_y + offset_y), ammo_size, i, currently_selected, infinite_ammo);
1025                         ++row;
1026                         if(row >= rows)
1027                         {
1028                                 row = 0;
1029                                 column = column + 1;
1030                         }
1031                 }
1032         }
1033
1034         draw_endBoldFont();
1035 }
1036
1037 void DrawNumIcon_expanding(vector myPos, vector mySize, float x, string icon, float vertical, float icon_right_align, vector color, float theAlpha, float fadelerp)
1038 {
1039         vector newPos = '0 0 0', newSize = '0 0 0';
1040         vector picpos, numpos;
1041
1042         if (vertical)
1043         {
1044                 if(mySize_y/mySize_x > 2)
1045                 {
1046                         newSize_y = 2 * mySize_x;
1047                         newSize_x = mySize_x;
1048
1049                         newPos_y = myPos_y + (mySize_y - newSize_y) / 2;
1050                         newPos_x = myPos_x;
1051                 }
1052                 else
1053                 {
1054                         newSize_x = 1/2 * mySize_y;
1055                         newSize_y = mySize_y;
1056
1057                         newPos_x = myPos_x + (mySize_x - newSize_x) / 2;
1058                         newPos_y = myPos_y;
1059                 }
1060
1061                 if(icon_right_align)
1062                 {
1063                         numpos = newPos;
1064                         picpos = newPos + eY * newSize_x;
1065                 }
1066                 else
1067                 {
1068                         picpos = newPos;
1069                         numpos = newPos + eY * newSize_x;
1070                 }
1071
1072                 newSize_y /= 2;
1073                 drawpic_aspect_skin(picpos, icon, newSize, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
1074                 // make number smaller than icon, it looks better
1075                 // reduce only y to draw numbers with different number of digits with the same y size
1076                 numpos_y += newSize_y * ((1 - 0.7) / 2);
1077                 newSize_y *= 0.7;
1078                 drawstring_aspect(numpos, ftos(x), newSize, color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
1079                 return;
1080         }
1081
1082         if(mySize_x/mySize_y > 3)
1083         {
1084                 newSize_x = 3 * mySize_y;
1085                 newSize_y = mySize_y;
1086
1087                 newPos_x = myPos_x + (mySize_x - newSize_x) / 2;
1088                 newPos_y = myPos_y;
1089         }
1090         else
1091         {
1092                 newSize_y = 1/3 * mySize_x;
1093                 newSize_x = mySize_x;
1094
1095                 newPos_y = myPos_y + (mySize_y - newSize_y) / 2;
1096                 newPos_x = myPos_x;
1097         }
1098
1099         if(icon_right_align) // right align
1100         {
1101                 numpos = newPos;
1102                 picpos = newPos + eX * 2 * newSize_y;
1103         }
1104         else // left align
1105         {
1106                 numpos = newPos + eX * newSize_y;
1107                 picpos = newPos;
1108         }
1109
1110         // NOTE: newSize_x is always equal to 3 * mySize_y so we can use
1111         // '2 1 0' * newSize_y instead of eX * (2/3) * newSize_x + eY * newSize_y
1112         drawstring_aspect_expanding(numpos, ftos(x), '2 1 0' * newSize_y, color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL, fadelerp);
1113         drawpic_aspect_skin_expanding(picpos, icon, '1 1 0' * newSize_y, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL, fadelerp);
1114 }
1115
1116 void DrawNumIcon(vector myPos, vector mySize, float x, string icon, float vertical, float icon_right_align, vector color, float theAlpha)
1117 {
1118         DrawNumIcon_expanding(myPos, mySize, x, icon, vertical, icon_right_align, color, theAlpha, 0);
1119 }
1120
1121 // Powerups (#2)
1122 //
1123 void HUD_Powerups(void)
1124 {
1125         float strength_time, shield_time, superweapons_time;
1126         if(!autocvar__hud_configure)
1127         {
1128                 if(!autocvar_hud_panel_powerups) return;
1129                 if(spectatee_status == -1) return;
1130                 if not(getstati(STAT_ITEMS, 0, 24) & (IT_STRENGTH | IT_INVINCIBLE | IT_SUPERWEAPON)) return;
1131                 if (getstati(STAT_HEALTH) <= 0) return;
1132
1133                 strength_time = bound(0, getstatf(STAT_STRENGTH_FINISHED) - time, 99);
1134                 shield_time = bound(0, getstatf(STAT_INVINCIBLE_FINISHED) - time, 99);
1135                 superweapons_time = bound(0, getstatf(STAT_SUPERWEAPONS_FINISHED) - time, 99);
1136
1137                 if (getstati(STAT_ITEMS, 0, 24) & IT_UNLIMITED_SUPERWEAPONS)
1138                         superweapons_time = 99; // force max
1139
1140                 // prevent stuff to show up on mismatch that will be fixed next frame
1141                 if (!(getstati(STAT_ITEMS, 0, 24) & IT_SUPERWEAPON))
1142                         superweapons_time = 0;
1143         }
1144         else
1145         {
1146                 hud_configure_active_panel = HUD_PANEL_POWERUPS;
1147
1148                 strength_time = 15;
1149                 shield_time = 27;
1150                 superweapons_time = 13;
1151         }
1152
1153         HUD_Panel_UpdateCvars(powerups);
1154         HUD_Panel_ApplyFadeAlpha();
1155
1156         draw_beginBoldFont();
1157
1158         vector pos, mySize;
1159         pos = panel_pos;
1160         mySize = panel_size;
1161
1162         HUD_Panel_DrawBg(bound(0, max(strength_time, shield_time, superweapons_time), 1));
1163         if(panel_bg_padding)
1164         {
1165                 pos += '1 1 0' * panel_bg_padding;
1166                 mySize -= '2 2 0' * panel_bg_padding;
1167         }
1168
1169         float panel_ar = mySize_x/mySize_y;
1170         float is_vertical = (panel_ar < 1);
1171         vector shield_offset = '0 0 0', strength_offset = '0 0 0', superweapons_offset = '0 0 0';
1172
1173         float superweapons_is = -1;
1174
1175         if(superweapons_time)
1176         {
1177                 if(strength_time)
1178                 {
1179                         if(shield_time)
1180                                 superweapons_is = 0;
1181                         else
1182                                 superweapons_is = 2;
1183                 }
1184                 else
1185                 {
1186                         if(shield_time)
1187                                 superweapons_is = 1;
1188                         else
1189                                 superweapons_is = 2;
1190                 }
1191         }
1192
1193         // FIXME handle superweapons here
1194         if(superweapons_is == 0)
1195         {
1196                 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
1197                 {
1198                         mySize_x *= (1.0 / 3.0);
1199                         superweapons_offset_x = mySize_x;
1200                         if (autocvar_hud_panel_powerups_flip)
1201                                 shield_offset_x = 2*mySize_x;
1202                         else
1203                                 strength_offset_x = 2*mySize_x;
1204                 }
1205                 else
1206                 {
1207                         mySize_y *= (1.0 / 3.0);
1208                         superweapons_offset_y = mySize_y;
1209                         if (autocvar_hud_panel_powerups_flip)
1210                                 shield_offset_y = 2*mySize_y;
1211                         else
1212                                 strength_offset_y = 2*mySize_y;
1213                 }
1214         }
1215         else
1216         {
1217                 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
1218                 {
1219                         mySize_x *= 0.5;
1220                         if (autocvar_hud_panel_powerups_flip)
1221                                 shield_offset_x = mySize_x;
1222                         else
1223                                 strength_offset_x = mySize_x;
1224                 }
1225                 else
1226                 {
1227                         mySize_y *= 0.5;
1228                         if (autocvar_hud_panel_powerups_flip)
1229                                 shield_offset_y = mySize_y;
1230                         else
1231                                 strength_offset_y = mySize_y;
1232                 }
1233         }
1234
1235         float shield_baralign, strength_baralign, superweapons_baralign;
1236         float shield_iconalign, strength_iconalign, superweapons_iconalign;
1237
1238         if (autocvar_hud_panel_powerups_flip)
1239         {
1240                 strength_baralign = (autocvar_hud_panel_powerups_baralign == 2 || autocvar_hud_panel_powerups_baralign == 1);
1241                 shield_baralign = (autocvar_hud_panel_powerups_baralign == 3 || autocvar_hud_panel_powerups_baralign == 1);
1242                 strength_iconalign = (autocvar_hud_panel_powerups_iconalign == 2 || autocvar_hud_panel_powerups_iconalign == 1);
1243                 shield_iconalign = (autocvar_hud_panel_powerups_iconalign == 3 || autocvar_hud_panel_powerups_iconalign == 1);
1244         }
1245         else
1246         {
1247                 shield_baralign = (autocvar_hud_panel_powerups_baralign == 2 || autocvar_hud_panel_powerups_baralign == 1);
1248                 strength_baralign = (autocvar_hud_panel_powerups_baralign == 3 || autocvar_hud_panel_powerups_baralign == 1);
1249                 shield_iconalign = (autocvar_hud_panel_powerups_iconalign == 2 || autocvar_hud_panel_powerups_iconalign == 1);
1250                 strength_iconalign = (autocvar_hud_panel_powerups_iconalign == 3 || autocvar_hud_panel_powerups_iconalign == 1);
1251         }
1252
1253         if(superweapons_is == 0)
1254         {
1255                 superweapons_iconalign = strength_iconalign;
1256                 superweapons_baralign = 2;
1257         }
1258         else if(superweapons_is == 1)
1259         {
1260                 superweapons_offset = strength_offset;
1261                 superweapons_iconalign = strength_iconalign;
1262                 superweapons_baralign = strength_baralign;
1263         }
1264         else // if(superweapons_is == 2)
1265         {
1266                 superweapons_offset = shield_offset;
1267                 superweapons_iconalign = shield_iconalign;
1268                 superweapons_baralign = shield_baralign;
1269         }
1270
1271         if(shield_time)
1272         {
1273                 const float maxshield = 30;
1274                 float shield = ceil(shield_time);
1275                 if(autocvar_hud_panel_powerups_progressbar)
1276                 {
1277                         HUD_Panel_GetProgressBarColor(shield);
1278                         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);
1279                 }
1280                 if(autocvar_hud_panel_powerups_text)
1281                 {
1282                         if(shield > 1)
1283                                 DrawNumIcon(pos + shield_offset, mySize, shield, "shield", is_vertical, shield_iconalign, '1 1 1', 1);
1284                         if(shield <= 5)
1285                                 DrawNumIcon_expanding(pos + shield_offset, mySize, shield, "shield", is_vertical, shield_iconalign, '1 1 1', 1, bound(0, (shield - shield_time) / 0.5, 1));
1286                 }
1287         }
1288
1289         if(strength_time)
1290         {
1291                 const float maxstrength = 30;
1292                 float strength = ceil(strength_time);
1293                 if(autocvar_hud_panel_powerups_progressbar)
1294                 {
1295                         HUD_Panel_GetProgressBarColor(strength);
1296                         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);
1297                 }
1298                 if(autocvar_hud_panel_powerups_text)
1299                 {
1300                         if(strength > 1)
1301                                 DrawNumIcon(pos + strength_offset, mySize, strength, "strength", is_vertical, strength_iconalign, '1 1 1', 1);
1302                         if(strength <= 5)
1303                                 DrawNumIcon_expanding(pos + strength_offset, mySize, strength, "strength", is_vertical, strength_iconalign, '1 1 1', 1, bound(0, (strength - strength_time) / 0.5, 1));
1304                 }
1305         }
1306
1307         if(superweapons_time)
1308         {
1309                 const float maxsuperweapons = 30;
1310                 float superweapons = ceil(superweapons_time);
1311                 if(autocvar_hud_panel_powerups_progressbar)
1312                 {
1313                         HUD_Panel_GetProgressBarColor(superweapons);
1314                         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);
1315                 }
1316                 if(autocvar_hud_panel_powerups_text)
1317                 {
1318                         if(superweapons > 1)
1319                                 DrawNumIcon(pos + superweapons_offset, mySize, superweapons, "superweapons", is_vertical, superweapons_iconalign, '1 1 1', 1);
1320                         if(superweapons <= 5)
1321                                 DrawNumIcon_expanding(pos + superweapons_offset, mySize, superweapons, "superweapons", is_vertical, superweapons_iconalign, '1 1 1', 1, bound(0, (superweapons - superweapons_time) / 0.5, 1));
1322                 }
1323         }
1324
1325         draw_endBoldFont();
1326 }
1327
1328 // Health/armor (#3)
1329 //
1330
1331 // prev_* vars contain the health/armor at the previous FRAME
1332 // set to -1 when player is dead or was not playing
1333 float prev_health, prev_armor;
1334 float health_damagetime, armor_damagetime;
1335 float health_beforedamage, armor_beforedamage;
1336 // old_p_* vars keep track of previous values when smoothing value changes of the progressbar
1337 float old_p_health, old_p_armor;
1338 float old_p_healthtime, old_p_armortime;
1339 // prev_p_* vars contain the health/armor progressbar value at the previous FRAME
1340 // set to -1 to forcedly stop effects when we switch spectated player (e.g. from playerX: 70h to playerY: 50h)
1341 float prev_p_health, prev_p_armor;
1342
1343 void HUD_HealthArmor(void)
1344 {
1345         float armor, health, fuel;
1346         if(!autocvar__hud_configure)
1347         {
1348                 if(!autocvar_hud_panel_healtharmor) return;
1349                 if(hud != HUD_NORMAL) return;
1350                 if(spectatee_status == -1) return;
1351
1352                 health = getstati(STAT_HEALTH);
1353                 if(health <= 0)
1354                 {
1355                         prev_health = -1;
1356                         return;
1357                 }
1358                 armor = getstati(STAT_ARMOR);
1359
1360                 // code to check for spectatee_status changes is in Ent_ClientData()
1361                 // prev_p_health and prev_health can be set to -1 there
1362
1363                 if (prev_p_health == -1)
1364                 {
1365                         // no effect
1366                         health_beforedamage = 0;
1367                         armor_beforedamage = 0;
1368                         health_damagetime = 0;
1369                         armor_damagetime = 0;
1370                         prev_health = health;
1371                         prev_armor = armor;
1372                         old_p_health = health;
1373                         old_p_armor = armor;
1374                         prev_p_health = health;
1375                         prev_p_armor = armor;
1376                 }
1377                 else if (prev_health == -1)
1378                 {
1379                         //start the load effect
1380                         health_damagetime = 0;
1381                         armor_damagetime = 0;
1382                         prev_health = 0;
1383                         prev_armor = 0;
1384                 }
1385                 fuel = getstati(STAT_FUEL);
1386         }
1387         else
1388         {
1389                 hud_configure_active_panel = HUD_PANEL_HEALTHARMOR;
1390
1391                 health = 150;
1392                 armor = 75;
1393                 fuel = 20;
1394         }
1395
1396         HUD_Panel_UpdateCvars(healtharmor);
1397         HUD_Panel_ApplyFadeAlpha();
1398         vector pos, mySize;
1399         pos = panel_pos;
1400         mySize = panel_size;
1401
1402         HUD_Panel_DrawBg(1);
1403         if(panel_bg_padding)
1404         {
1405                 pos += '1 1 0' * panel_bg_padding;
1406                 mySize -= '2 2 0' * panel_bg_padding;
1407         }
1408
1409         float baralign = autocvar_hud_panel_healtharmor_baralign;
1410         float iconalign = autocvar_hud_panel_healtharmor_iconalign;
1411
1412     float maxhealth = autocvar_hud_panel_healtharmor_maxhealth;
1413     float maxarmor = autocvar_hud_panel_healtharmor_maxarmor;
1414         if(autocvar_hud_panel_healtharmor == 2) // combined health and armor display
1415         {
1416                 vector v;
1417                 v = healtharmor_maxdamage(health, armor, armorblockpercent);
1418
1419                 float x;
1420                 x = floor(v_x + 1);
1421
1422         float maxtotal = maxhealth + maxarmor;
1423                 string biggercount;
1424                 if(v_z) // NOT fully armored
1425                 {
1426                         biggercount = "health";
1427                         if(autocvar_hud_panel_healtharmor_progressbar)
1428                         {
1429                                 HUD_Panel_GetProgressBarColor(health);
1430                                 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);
1431                         }
1432                         if(armor)
1433             if(autocvar_hud_panel_healtharmor_text)
1434                                 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);
1435                 }
1436                 else
1437                 {
1438                         biggercount = "armor";
1439                         if(autocvar_hud_panel_healtharmor_progressbar)
1440                         {
1441                                 HUD_Panel_GetProgressBarColor(armor);
1442                                 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);
1443                         }
1444                         if(health)
1445             if(autocvar_hud_panel_healtharmor_text)
1446                                 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);
1447                 }
1448         if(autocvar_hud_panel_healtharmor_text)
1449                         DrawNumIcon(pos, mySize, x, biggercount, 0, iconalign, HUD_Get_Num_Color(x, maxtotal), 1);
1450
1451                 if(fuel)
1452                 {
1453                         HUD_Panel_GetProgressBarColor(fuel);
1454                         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);
1455                 }
1456         }
1457         else
1458         {
1459                 float panel_ar = mySize_x/mySize_y;
1460                 float is_vertical = (panel_ar < 1);
1461                 vector health_offset = '0 0 0', armor_offset = '0 0 0';
1462                 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
1463                 {
1464                         mySize_x *= 0.5;
1465                         if (autocvar_hud_panel_healtharmor_flip)
1466                                 health_offset_x = mySize_x;
1467                         else
1468                                 armor_offset_x = mySize_x;
1469                 }
1470                 else
1471                 {
1472                         mySize_y *= 0.5;
1473                         if (autocvar_hud_panel_healtharmor_flip)
1474                                 health_offset_y = mySize_y;
1475                         else
1476                                 armor_offset_y = mySize_y;
1477                 }
1478
1479                 float health_baralign, armor_baralign, fuel_baralign;
1480                 float health_iconalign, armor_iconalign;
1481                 if (autocvar_hud_panel_healtharmor_flip)
1482                 {
1483                         armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1);
1484                         health_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1);
1485                         fuel_baralign = health_baralign;
1486                         armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1);
1487                         health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1);
1488                 }
1489                 else
1490                 {
1491                         health_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1);
1492                         armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1);
1493                         fuel_baralign = armor_baralign;
1494                         health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1);
1495                         armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1);
1496                 }
1497
1498                 //if(health)
1499                 {
1500                         if(autocvar_hud_panel_healtharmor_progressbar)
1501                         {
1502                                 HUD_Panel_GetProgressBarColor(health);
1503                                 float p_health, pain_health_alpha;
1504                                 p_health = health;
1505                                 pain_health_alpha = 1;
1506                                 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
1507                                 {
1508                                         if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0)
1509                                         {
1510                                                 if (fabs(prev_health - health) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth)
1511                                                 {
1512                                                         if (time - old_p_healthtime < 1)
1513                                                                 old_p_health = prev_p_health;
1514                                                         else
1515                                                                 old_p_health = prev_health;
1516                                                         old_p_healthtime = time;
1517                                                 }
1518                                                 if (time - old_p_healthtime < 1)
1519                                                 {
1520                                                         p_health += (old_p_health - health) * (1 - (time - old_p_healthtime));
1521                                                         prev_p_health = p_health;
1522                                                 }
1523                                         }
1524                                         if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0)
1525                                         {
1526                                                 if (prev_health - health >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
1527                                                 {
1528                                                         if (time - health_damagetime >= 1)
1529                                                                 health_beforedamage = prev_health;
1530                                                         health_damagetime = time;
1531                                                 }
1532                                                 if (time - health_damagetime < 1)
1533                                                 {
1534                                                         float health_damagealpha = 1 - (time - health_damagetime)*(time - health_damagetime);
1535                                                         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);
1536                                                 }
1537                                         }
1538                                         prev_health = health;
1539
1540                                         if (health <= autocvar_hud_panel_healtharmor_progressbar_gfx_lowhealth)
1541                                         {
1542                                                 float BLINK_FACTOR = 0.15;
1543                                                 float BLINK_BASE = 0.85;
1544                                                 float BLINK_FREQ = 9; 
1545                                                 pain_health_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ);
1546                                         }
1547                                 }
1548                                 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);
1549                         }
1550                         if(autocvar_hud_panel_healtharmor_text)
1551                                 DrawNumIcon(pos + health_offset, mySize, health, "health", is_vertical, health_iconalign, HUD_Get_Num_Color(health, maxhealth), 1);
1552                 }
1553
1554                 if(armor)
1555                 {
1556                         if(autocvar_hud_panel_healtharmor_progressbar)
1557                         {
1558                                 HUD_Panel_GetProgressBarColor(armor);
1559                                 float p_armor;
1560                                 p_armor = armor;
1561                                 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
1562                                 {
1563                                         if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0)
1564                                         {
1565                                                 if (fabs(prev_armor - armor) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth)
1566                                                 {
1567                                                         if (time - old_p_armortime < 1)
1568                                                                 old_p_armor = prev_p_armor;
1569                                                         else
1570                                                                 old_p_armor = prev_armor;
1571                                                         old_p_armortime = time;
1572                                                 }
1573                                                 if (time - old_p_armortime < 1)
1574                                                 {
1575                                                         p_armor += (old_p_armor - armor) * (1 - (time - old_p_armortime));
1576                                                         prev_p_armor = p_armor;
1577                                                 }
1578                                         }
1579                                         if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0)
1580                                         {
1581                                                 if (prev_armor - armor >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
1582                                                 {
1583                                                         if (time - armor_damagetime >= 1)
1584                                                                 armor_beforedamage = prev_armor;
1585                                                         armor_damagetime = time;
1586                                                 }
1587                                                 if (time - armor_damagetime < 1)
1588                                                 {
1589                                                         float armor_damagealpha = 1 - (time - armor_damagetime)*(time - armor_damagetime);
1590                                                         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);
1591                                                 }
1592                                         }
1593                                         prev_armor = armor;
1594                                 }
1595                                 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);
1596                         }
1597                         if(autocvar_hud_panel_healtharmor_text)
1598                                 DrawNumIcon(pos + armor_offset, mySize, armor, "armor", is_vertical, armor_iconalign, HUD_Get_Num_Color(armor, maxarmor), 1);
1599                 }
1600
1601                 if(fuel)
1602                 {
1603                         if (is_vertical)
1604                                 mySize_x *= 0.2 / 2; //if vertical always halve x to not cover too much numbers with 3 digits
1605                         else
1606                                 mySize_y *= 0.2;
1607                         if (panel_ar >= 4)
1608                                 mySize_x *= 2; //restore full panel size
1609                         else if (panel_ar < 1/4)
1610                                 mySize_y *= 2; //restore full panel size
1611                         HUD_Panel_GetProgressBarColor(fuel);
1612                         HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", fuel/100, is_vertical, fuel_baralign, progressbar_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
1613                 }
1614         }
1615 }
1616
1617 // Notification area (#4)
1618 //
1619
1620 string Weapon_SuicideMessage(float deathtype)
1621 {
1622         w_deathtype = deathtype;
1623         get_weaponinfo(DEATH_WEAPONOF(deathtype)).weapon_func(WR_SUICIDEMESSAGE);
1624         return w_deathtypestring;
1625 }
1626
1627 string Weapon_KillMessage(float deathtype)
1628 {
1629         w_deathtype = deathtype;
1630         get_weaponinfo(DEATH_WEAPONOF(deathtype)).weapon_func(WR_KILLMESSAGE);
1631         return w_deathtypestring;
1632 }
1633
1634
1635 void HUD_KillNotify(string s1, string s2, string s3, float type, float msg) // s1 = attacker, s2 = victim
1636 {
1637         /*
1638         float w;
1639         float alsoprint, gentle;
1640         alsoprint = (autocvar_hud_panel_notify_print || !panel_enabled); // print message to console if: notify panel disabled, or cvar to do so enabled
1641         gentle = (autocvar_cl_gentle || autocvar_cl_gentle_messages);
1642         
1643         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
1644                 return;
1645
1646         if(msg == MSG_SUICIDE) {
1647                 w = DEATH_WEAPONOF(type);
1648                 if(WEP_VALID(w)) {
1649                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1650                         if (alsoprint)
1651                                 print("^1", sprintf(Weapon_SuicideMessage(type), strcat(s1, "^1")), "\n");
1652                 } else if (type == DEATH_KILL) {
1653                         HUD_KillNotify_Push(s1, "", 0, DEATH_KILL);
1654                         if (alsoprint)
1655                                 print (sprintf(_("^1%s^1 couldn't take it anymore\n"), s1));
1656                 } else if (type == DEATH_ROT) {
1657                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1658                         if (alsoprint)
1659                                 print (sprintf(_("^1%s^1 died\n"), s1));
1660                 } else if (type == DEATH_NOAMMO) {
1661                         HUD_KillNotify_Push(s1, "", 0, DEATH_NOAMMO);
1662                         if (alsoprint)
1663                                 print (sprintf(_("^7%s^7 committed suicide. What's the point of living without ammo?\n"), s1));
1664                 } else if (type == DEATH_CAMP) {
1665                         HUD_KillNotify_Push(s1, "", 0, DEATH_CAMP);
1666                         if (alsoprint)
1667                                 print (sprintf(_("^1%s^1 thought they found a nice camping ground\n"), s1));
1668                 } else if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
1669                         HUD_KillNotify_Push(s1, "", 0, type);
1670                         if (alsoprint)
1671                                 print (sprintf(_("^1%s^1 didn't become friends with the Lord of Teamplay\n"), s1));
1672                 } else if (type == DEATH_CHEAT) {
1673                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1674                         if (alsoprint)
1675                                 print (sprintf(_("^1%s^1 unfairly eliminated themself\n"), s1));
1676                 } else if (type == DEATH_FIRE) {
1677                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1678                         if (alsoprint)
1679                                 print (sprintf(_("^1%s^1 burned to death\n"), s1));
1680                 } else if (type != DEATH_TEAMCHANGE && type != DEATH_QUIET) {
1681                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1682                         if (alsoprint)
1683                                 print (sprintf(_("^1%s^1 couldn't resist the urge to self-destruct\n"), s1));
1684                 } 
1685                 
1686                 if (stof(s2) > 2) // killcount > 2
1687                         print (sprintf(_("^1%s^1 ended it all after a %d kill spree\n"), s1, stof(s2)));
1688         } else if(msg == MSG_KILL) {
1689                 w = DEATH_WEAPONOF(type);
1690                 if(WEP_VALID(w)) {
1691                         HUD_KillNotify_Push(s1, s2, 1, type);
1692                         if (alsoprint)
1693                                 print("^1", sprintf(Weapon_KillMessage(type), strcat(s2, "^1"), strcat(s1, "^1")), "\n"); // default order: victim, killer
1694                 }
1695                 else if(type == KILL_TEAM_RED || type == KILL_TEAM_BLUE || type == KILL_TEAM_SPREE) {
1696                         HUD_KillNotify_Push(s1, s2, 1, type);
1697                         if(alsoprint)
1698                         {
1699                                 if(gentle) {
1700                                         print (sprintf(_("^1%s^1 took action against a team mate\n"), s1));
1701                                 } else {
1702                                         print (sprintf(_("^1%s^1 mows down a team mate\n"), s1));
1703                                 }
1704                         }
1705                         if (stof(s2) > 2 && type == KILL_TEAM_SPREE) {
1706                                 if(gentle)
1707                                         print (sprintf(_("^1%s^1 ended a %d scoring spree by going against a team mate\n"), s1, stof(s3)));
1708                                 else
1709                                         print (sprintf(_("^1%s^1 ended a %d kill spree by killing a team mate\n"), s1, stof(s3)));
1710                         }
1711                         else if (stof(s2) > 2) {
1712                                 if(gentle)
1713                                         print (sprintf(_("^1%s^1's %s scoring spree was ended by a team mate!\n"), s1, stof(s3)));
1714                                 else
1715                                         print (sprintf(_("^1%s^1's %s kill spree was ended by a team mate!\n"), s1, stof(s3)));
1716                         }
1717                 }
1718                 else if(type == KILL_FIRST_BLOOD)
1719                         print(sprintf(_("^1%s^1 drew first blood\n"), s1));
1720                 else if (type == DEATH_TELEFRAG) {
1721                         HUD_KillNotify_Push(s1, s2, 1, DEATH_TELEFRAG);
1722                         if(gentle)
1723                                 print (sprintf(_("^1%s^1 tried to occupy %s^1's teleport destination space\n"), s2, s1));
1724                         else
1725                                 print (sprintf(_("^1%s^1 was telefragged by %s\n"), s2, s1));
1726                 }
1727                 else if (type == DEATH_DROWN) {
1728                         HUD_KillNotify_Push(s1, s2, 1, DEATH_DROWN);
1729                         if(alsoprint)
1730                                 print (sprintf(_("^1%s^1 was drowned by %s\n"), s2, s1));
1731                 }
1732                 else if (type == DEATH_SLIME) {
1733                         HUD_KillNotify_Push(s1, s2, 1, DEATH_SLIME);
1734                         if(alsoprint)
1735                                 print (sprintf(_("^1%s^1 was slimed by %s\n"), s2, s1));
1736                 }
1737                 else if (type == DEATH_LAVA) {
1738                         HUD_KillNotify_Push(s1, s2, 1, DEATH_LAVA);
1739                         if(alsoprint)
1740                                 print (sprintf(_("^1%s^1 was cooked by %s\n"), s2, s1));
1741                 }
1742                 else if (type == DEATH_FALL) {
1743                         HUD_KillNotify_Push(s1, s2, 1, DEATH_FALL);
1744                         if(alsoprint)
1745                                 print (sprintf(_("^1%s^1 was grounded by %s\n"), s2, s1));
1746                 }
1747                 else if (type == DEATH_SHOOTING_STAR) {
1748                         HUD_KillNotify_Push(s1, s2, 1, DEATH_SHOOTING_STAR);
1749                         if(alsoprint)
1750                                 print (sprintf(_("^1%s^1 was shot into space by %s\n"), s2, s1));
1751                 }
1752                 else if (type == DEATH_SWAMP) {
1753                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1754                         if(alsoprint)
1755                                 print (sprintf(_("^1%s^1 was conserved by %s\n"), s2, s1));
1756                 }
1757                 else if (type == DEATH_HURTTRIGGER)
1758                 {
1759                         HUD_KillNotify_Push(s1, s2, 1, DEATH_HURTTRIGGER);
1760                         if(alsoprint)
1761                                 print(sprintf(_("^1%s^1 was thrown into a world of hurt by %s\n"), s2, s1));
1762                 } else if(type == DEATH_VHCRUSH) {
1763                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1764                         if(alsoprint)
1765                                 print (sprintf(_("^1%s^1 was crushed by %s\n"), s2, s1));
1766                 } else if(type == DEATH_SBMINIGUN) {
1767                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1768                         if(alsoprint)
1769                                 print (sprintf(_("^1%s^1 got shredded by %s\n"), s2, s1));
1770                 } else if(type == DEATH_SBROCKET) {
1771                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1772                         if(alsoprint)
1773                                 print (sprintf(_("^1%s^1 was blasted to bits by %s\n"), s2, s1));
1774                 } else if(type == DEATH_SBBLOWUP) {
1775                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1776                         if(alsoprint)
1777                                 print (sprintf(_("^1%s^1 got caught in the blast when %s^1's destroys a vehicle\n"), s2, s1));
1778                 } else if(type == DEATH_WAKIGUN) {
1779                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1780                         if(alsoprint)
1781                                 print (sprintf(_("^1%s^1 was bolted down by %s\n"), s2, s1));
1782                 } else if(type == DEATH_BUMB_GUN) {
1783                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1784                         if(alsoprint)
1785                                 print (sprintf(_("^1%s^1 saw %s's preddy lights.\n"), s2, s1));
1786                 } else if(type == DEATH_WAKIROCKET) {
1787                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1788                         if(alsoprint)
1789                                 print (sprintf(_("^1%s^1 could find no shelter from %s^1's rockets\n"), s2, s1));
1790                 } else if(type == DEATH_WAKIBLOWUP) {
1791                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1792                         if(alsoprint)
1793                                 print (sprintf(_("^1%s^1 got caught in the blast when %s^1's destroys a vehicle\n"), s2, s1));
1794                 } else if(type == DEATH_RAPTOR_CANNON) {
1795                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1796                         if(alsoprint)
1797                                 print (sprintf(_("^1%s^1 nailed to hell by %s\n"), s2, s1));
1798                 } else if(type == DEATH_RAPTOR_BOMB) {
1799                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1800                         if(alsoprint)
1801                                 print (sprintf(_("^1%s^1 cluster crushed by %s\n"), s2, s1));
1802                 } else if(type == DEATH_RAPTOR_DEATH) {
1803                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1804                         if(alsoprint)
1805                                 print (sprintf(_("^1%s^1 got caught in the blast when %s^1's destroys a vehicle\n"), s2, s1));
1806                 } else if(type == DEATH_TURRET) {
1807                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1808                         if(alsoprint)
1809                                 print (sprintf(_("^1%s^1 was pushed into the line of fire by %s\n"), s2, s1));
1810                 } else if(type == DEATH_TOUCHEXPLODE) {
1811                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1812                         if(alsoprint)
1813                                 print (sprintf(_("^1%s^1 was pushed into an accident by %s\n"), s2, s1));
1814                 } else if(type == DEATH_CHEAT) {
1815                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1816                         if(alsoprint)
1817                                 print (sprintf(_("^1%s^1 was unfairly eliminated by %s\n"), s2, s1));
1818                 } else if (type == DEATH_FIRE) {
1819                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1820                         if(alsoprint)
1821                                 print (sprintf(_("^1%s^1 was burnt to death by %s\n"), s2, s1));
1822                 } else if (type == DEATH_CUSTOM) {
1823                         HUD_KillNotify_Push(s1, s2, 1, DEATH_CUSTOM);
1824                         if(alsoprint)
1825                                 print("^1", sprintf(s3, strcat(s2, "^1"), strcat(s1, "^1")), "\n");
1826                 } else if (type == DEATH_HURTTRIGGER) {
1827                         HUD_KillNotify_Push(s1, s2, 1, DEATH_HURTTRIGGER);
1828                         if(alsoprint)
1829                                 print("^1", sprintf(s3, strcat(s2, "^1"), strcat(s1, "^1")), "\n");
1830                 } else {
1831                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1832                         if(alsoprint)
1833                                 print (sprintf(_("^1%s^1 was fragged by %s\n"), s2, s1));
1834                 }
1835         } else if(msg == MSG_SPREE) {
1836                 if(type == KILL_END_SPREE) {
1837                         if(gentle)
1838                                 print (sprintf(_("^1%s^1's %s scoring spree was ended by %s\n"), s1, s2, s3));
1839                         else
1840                                 print (sprintf(_("^1%s^1's %s kill spree was ended by %s\n"), s1, s2, s3));
1841                 } else if(type == KILL_SPREE) {
1842                         if(gentle)
1843                                 print (sprintf(_("^1%s^1 made %s scores in a row\n"), s1, s2));
1844                         else
1845                                 print (sprintf(_("^1%s^1 has %s frags in a row\n"), s1, s2));
1846                 } else if(type == KILL_SPREE_3) {
1847                         if(gentle)
1848                                 print (sprintf(_("%s^7 made a ^1TRIPLE SCORE\n"), s1));
1849                         else
1850                                 print (sprintf(_("%s^7 made a ^1TRIPLE FRAG\n"), s1));
1851                 } else if(type == KILL_SPREE_5) {
1852                         if(gentle)
1853                                 print (sprintf(_("%s^7 unleashes ^1SCORING RAGE\n"), s1));
1854                         else
1855                                 print (sprintf(_("%s^7 unleashes ^1RAGE\n"), s1));
1856                 } else if(type == KILL_SPREE_10) {
1857                         if(gentle)
1858                                 print (sprintf(_("%s^7 made ^1TEN SCORES IN A ROW!\n"), s1));
1859                         else
1860                                 print (sprintf(_("%s^7 starts the ^1MASSACRE!\n"), s1));
1861                 } else if(type == KILL_SPREE_15) {
1862                         if(gentle)
1863                                 print (sprintf(_("%s^7 made ^1FIFTEEN SCORES IN A ROW!\n"), s1));
1864                         else
1865                                 print (sprintf(_("%s^7 executes ^1MAYHEM!\n"), s1));
1866                 } else if(type == KILL_SPREE_20) {
1867                         if(gentle)
1868                                 print (sprintf(_("%s^7 made ^1TWENTY SCORES IN A ROW!\n"), s1));
1869                         else
1870                                 print (sprintf(_("%s^7 is a ^1BERSERKER!\n"), s1));
1871                 } else if(type == KILL_SPREE_25) {
1872                         if(gentle)
1873                                 print (sprintf(_("%s^7 made ^1TWENTY FIVE SCORES IN A ROW!\n"), s1));
1874                         else
1875                                 print (sprintf(_("%s^7 inflicts ^1CARNAGE!\n"), s1));
1876                 } else if(type == KILL_SPREE_30) {
1877                         if(gentle)
1878                                 print (sprintf(_("%s^7 made ^1THIRTY SCORES IN A ROW!\n"), s1));
1879                         else
1880                                 print (sprintf(_("%s^7 unleashes ^1ARMAGEDDON!\n"), s1));
1881                 }
1882         } else if(msg == MSG_KILL_ACTION) { // wtf is this? isnt it basically the same as MSG_SUICIDE?
1883                 if (type == DEATH_DROWN) {
1884                         HUD_KillNotify_Push(s1, "", 0, DEATH_DROWN);
1885                         if(alsoprint)
1886                         {
1887                                 if(gentle)
1888                                         print (sprintf(_("^1%s^1 was in the water for too long\n"), s1));
1889                                 else
1890                                         print (sprintf(_("^1%s^1 drowned\n"), s1));
1891                         }
1892                 } else if (type == DEATH_SLIME) {
1893                         HUD_KillNotify_Push(s1, "", 0, DEATH_SLIME);
1894                         if(alsoprint)
1895                                 print (sprintf(_("^1%s^1 was slimed\n"), s1));
1896                 } else if (type == DEATH_LAVA) {
1897                         HUD_KillNotify_Push(s1, "", 0, DEATH_LAVA);
1898                         if(alsoprint)
1899                         {
1900                                 if(gentle)
1901                                         print (sprintf(_("^1%s^1 found a hot place\n"), s1));
1902                                 else
1903                                         print (sprintf(_("^1%s^1 turned into hot slag\n"), s1));
1904                         }
1905                 } else if (type == DEATH_FALL) {
1906                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1907                         if(alsoprint)
1908                         {
1909                                 if(gentle)
1910                                         print (sprintf(_("^1%s^1 tested gravity (and it worked)\n"), s1));
1911                                 else
1912                                         print (sprintf(_("^1%s^1 hit the ground with a crunch\n"), s1));
1913                         }
1914                 } else if (type == DEATH_SHOOTING_STAR) {
1915                         HUD_KillNotify_Push(s1, "", 0, DEATH_SHOOTING_STAR);
1916                         if(alsoprint)
1917                                 print (sprintf(_("^1%s^1 became a shooting star\n"), s1));
1918                 } else if (type == DEATH_SWAMP) {
1919                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1920                         if(alsoprint)
1921                         {
1922                                 if(gentle)
1923                                         print (sprintf(_("^1%s^1 discovered a swamp\n"), s1));
1924                                 else
1925                                         print (sprintf(_("^1%s^1 is now conserved for centuries to come\n"), s1));
1926                         }
1927                 } else if(DEATH_ISTURRET(type)) {
1928                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1929                         if(alsoprint)
1930                         {
1931                                 if(gentle)
1932                                         print (sprintf(_("^1%s^1 ran into a turret\n"), s1));
1933                                 else
1934                                 {
1935                                         switch(type)
1936                                         {
1937                                                 case DEATH_TURRET_EWHEEL:
1938                                                         print (sprintf(_("^1%s^1 was laserd down by a eWheel turret \n"), s1));
1939                                                         break;
1940                                                 case DEATH_TURRET_FLAC:
1941                                                         print (sprintf(_("^1%s^1 got caught in the flac \n"), s1));
1942                                                         break;
1943                                                 case DEATH_TURRET_MACHINEGUN:
1944                                                         print (sprintf(_("^1%s^1 was riddeld full of riddled by a machinegun turret \n"), s1));
1945                                                         break;
1946                                                 case DEATH_TURRET_WALKER_GUN:
1947                                                         print (sprintf(_("^1%s^1 got served a led enrichment by a walker turret \n"), s1));
1948                                                         break;
1949                                                 case DEATH_TURRET_WALKER_MEELE:
1950                                                         print (sprintf(_("^1%s^1 was impaled by a walker turret \n"), s1));
1951                                                         break;
1952                                                 case DEATH_TURRET_WALKER_ROCKET:
1953                                                         print (sprintf(_("^1%s^1 was rocketed to hell by a walker turret \n"), s1));
1954                                                         break;
1955                                                 case DEATH_TURRET_HELLION:
1956                                                         print (sprintf(_("^1%s^1 was blasted away hellion turret \n"), s1));
1957                                                         break;
1958                                                 case DEATH_TURRET_HK:
1959                                                         print (sprintf(_("^1%s^1 could not hide from the hunter turret \n"), s1));
1960                                                         break;
1961                                                 case DEATH_TURRET_MLRS:
1962                                                         print (sprintf(_("^1%s^1 got turned into smoldering gibs by a mlrs turret \n"), s1));
1963                                                         break;
1964                                                 case DEATH_TURRET_PLASMA:
1965                                                         print (sprintf(_("^1%s^1 got served some superheated plasma from a plasma turret \n"), s1));
1966                                                         break;
1967                                                 case DEATH_TURRET_PHASER:
1968                                                         print (sprintf(_("^1%s^1 was phased out \n"), s1));
1969                                                         break;
1970                                                 case DEATH_TURRET_TESLA:                        
1971                                                         print (sprintf(_("^1%s^1 was electrocuted by a tesla turret \n"), s1));
1972                                                         break;
1973                                         }
1974                                 }
1975                         }
1976                 } else if (type == DEATH_CUSTOM) {
1977                         HUD_KillNotify_Push(s1, "", 0, DEATH_CUSTOM);
1978                         if(alsoprint)
1979                                 print("^1", sprintf(s2, strcat(s1, "^1")), "\n");
1980                 } else if (type == DEATH_HURTTRIGGER) {
1981                         HUD_KillNotify_Push(s1, "", 0, DEATH_HURTTRIGGER);
1982                         if(alsoprint)
1983                                 print("^1", sprintf(s2, strcat(s1, "^1")), "\n");
1984                 } else if(type == DEATH_TOUCHEXPLODE) {
1985                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1986                         if(alsoprint)
1987                                 print (sprintf(_("^1%s^1 died in an accident\n"), s1));
1988                 } else if(type == DEATH_CHEAT) {
1989                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1990                         if(alsoprint)
1991                                 print (sprintf(_("^1%s^1 was unfairly eliminated\n"), s1));
1992                 } else if(type == DEATH_FIRE) {
1993                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1994                         if(alsoprint)
1995                         {
1996                                 if(gentle)
1997                                         print (sprintf(_("^1%s^1 felt a little hot\n"), s1));
1998                                 else
1999                                         print (sprintf(_("^1%s^1 burnt to death\n"), s1));
2000                                 }
2001                 } else {
2002                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2003                         if(alsoprint)
2004                         {
2005                                 if(gentle)
2006                                         print (sprintf(_("^1%s^1 needs a restart\n"), s1));
2007                                 else
2008                                         print (sprintf(_("^1%s^1 died\n"), s1));
2009                         }
2010                 }
2011         } else if(msg == MSG_KILL_ACTION_SPREE) {
2012                 if(gentle)
2013                         print (sprintf(_("^1%s^1 needs a restart after a %d scoring spree\n"), s1, stof(s2)));
2014                 else
2015                         print (sprintf(_("^1%s^1 died with a %d kill spree\n"), s1, stof(s2)));
2016         } else if(msg == MSG_INFO) {
2017                 if(type == INFO_GOTFLAG) { // here, s2 is the flag name
2018                         HUD_KillNotify_Push(s1, s2, 0, INFO_GOTFLAG);
2019                         print(sprintf(_("%s^7 got the %s\n"), s1, s2));
2020                 } else if(type == INFO_LOSTFLAG) {
2021                         HUD_KillNotify_Push(s1, s2, 0, INFO_LOSTFLAG);
2022                         print(sprintf(_("%s^7 lost the %s\n"), s1, s2));
2023                 } else if(type == INFO_PICKUPFLAG) {
2024                         HUD_KillNotify_Push(s1, s2, 0, INFO_GOTFLAG);
2025                         print(sprintf(_("%s^7 picked up the %s\n"), s1, s2));
2026                 } else if(type == INFO_RETURNFLAG) {
2027                         HUD_KillNotify_Push(s1, s2, 0, INFO_RETURNFLAG);
2028                         print(sprintf(_("%s^7 returned the %s\n"), s1, s2));
2029                 } else if(type == INFO_CAPTUREFLAG) {
2030                         HUD_KillNotify_Push(s1, s2, 0, INFO_CAPTUREFLAG);
2031                         print(sprintf(_("%s^7 captured the %s%s\n"), s1, s2, s3));
2032                 }
2033         } else if(msg == MSG_RACE) {
2034                 if(type == RACE_SERVER_RECORD) {
2035                         HUD_KillNotify_Push(s1, s2, 1, RACE_SERVER_RECORD);
2036                 }
2037                 else if(type == RACE_NEW_RANK) {
2038                         HUD_KillNotify_Push(s1, s2, 1, RACE_NEW_RANK);
2039                 }
2040                 else if(type == RACE_NEW_TIME) {
2041                         HUD_KillNotify_Push(s1, s2, 1, RACE_NEW_TIME);
2042                 }
2043                 else if(type == RACE_FAIL) {
2044                         HUD_KillNotify_Push(s1, s2, 1, RACE_FAIL);
2045                 }
2046         } else if(msg == MSG_KA) {
2047                 if(type == KA_PICKUPBALL) {
2048                         HUD_KillNotify_Push(s1, s2, 0, KA_PICKUPBALL);
2049                         if(alsoprint)
2050                                 print (sprintf(_("%s^7 has picked up the ball!\n"), s1));
2051                 }
2052                 else if(type == KA_DROPBALL) {
2053                         HUD_KillNotify_Push(s1, s2, 0, KA_DROPBALL);
2054                         if(alsoprint)
2055                                 print(sprintf(_("%s^7 has dropped the ball!\n"), s1));
2056                 }
2057         }*/
2058 }
2059
2060 void HUD_Notify(void)
2061 {
2062         if(!autocvar__hud_configure)
2063         {
2064                 if(!autocvar_hud_panel_notify) return;
2065         }
2066         else
2067                 hud_configure_active_panel = HUD_PANEL_NOTIFY;
2068
2069         HUD_Panel_UpdateCvars(notify);
2070         HUD_Panel_ApplyFadeAlpha();
2071         vector pos, mySize;
2072         pos = panel_pos;
2073         mySize = panel_size;
2074
2075         HUD_Panel_DrawBg(1);
2076         if(panel_bg_padding)
2077         {
2078                 pos += '1 1 0' * panel_bg_padding;
2079                 mySize -= '2 2 0' * panel_bg_padding;
2080         }
2081
2082         float entries, height;
2083         entries = bound(1, floor(KN_MAX_ENTRIES * mySize_y/mySize_x), KN_MAX_ENTRIES);
2084         height = mySize_y/entries;
2085         
2086         vector fontsize;
2087         float fontheight = height * autocvar_hud_panel_notify_fontsize;
2088         fontsize = '0.5 0.5 0' * fontheight;
2089
2090         float a;
2091         float when;
2092         when = autocvar_hud_panel_notify_time;
2093         float fadetime;
2094         fadetime = autocvar_hud_panel_notify_fadetime;
2095
2096         vector pos_attacker, pos_victim, pos_icon;
2097         float width_attacker;
2098         string attacker, victim, icon;
2099
2100         float i, j, step, limit;
2101         if(autocvar_hud_panel_notify_flip) //order items from the top down
2102         {
2103                 i = 0;
2104                 step = +1;
2105                 limit = entries;
2106         }
2107         else //order items from the bottom up
2108         {
2109                 i = entries - 1;
2110                 step = -1;
2111                 limit = -1;
2112         }
2113
2114         for(j = kn_index;  i != limit;  i += step, ++j)
2115         {
2116                 if(autocvar__hud_configure)
2117                 {
2118                         if (step == +1)
2119                                 a = i;
2120                         else // inverse order
2121                                 a = entries - 1 - i;
2122                         attacker = textShortenToWidth(sprintf(_("Player %d"), a+1), 0.48 * mySize_x - height, fontsize, stringwidth_colors);
2123                         victim = textShortenToWidth(sprintf(_("Player %d"), a+2), 0.48 * mySize_x - height, fontsize, stringwidth_colors);
2124                         icon = strcat("weapon", get_weaponinfo(WEP_FIRST + mod(floor(a*2.4), WEP_LAST)).netname);
2125                         a = bound(0, (when - a) / 4, 1);
2126                         goto hud_config_notifyprint;
2127                 }
2128                 else
2129                 {
2130                         if (j == KN_MAX_ENTRIES)
2131                                 j = 0;
2132
2133                         if(killnotify_times[j] + when > time)
2134                                 a = 1;
2135                         else if(fadetime)
2136                         {
2137                                 a = bound(0, (killnotify_times[j] + when + fadetime - time) / fadetime, 1);
2138                                 if(!a)
2139                                 {
2140                                         break;
2141                                 }
2142                         }
2143                         else
2144                         {
2145                                 break;
2146                         }
2147                         
2148                         attacker = killnotify_attackers[j];
2149                         victim = killnotify_victims[j];
2150                         icon = killnotify_icon[j];
2151                 }
2152
2153                 //type = killnotify_deathtype[j];
2154                 //w = DEATH_WEAPONOF(type);
2155
2156                 if(icon != "")
2157                 {
2158                         if((attacker != "") && (victim == ""))
2159                         {
2160                                 // Y [used by] X
2161                                 attacker = textShortenToWidth(attacker, 0.73 * mySize_x - height, fontsize, stringwidth_colors);
2162                                 pos_attacker = pos + eX * (0.27 * mySize_x + height) + eY * ((0.5 * fontsize_y + i * height) + (0.5 * (height - fontheight)));
2163                                 pos_icon = pos + eX * 0.25 * mySize_x - eX * height + eY * i * height;
2164
2165                                 drawpic_aspect_skin(pos_icon, icon, '2 1 0' * height, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
2166                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2167                         }
2168                         else if((attacker != "") && (victim != ""))
2169                         {
2170                                 // X [did action to] Y
2171                                 attacker = textShortenToWidth(attacker, 0.48 * mySize_x - height, fontsize, stringwidth_colors);
2172                                 victim = textShortenToWidth(victim, 0.48 * mySize_x - height, fontsize, stringwidth_colors);
2173 :hud_config_notifyprint
2174                                 width_attacker = stringwidth(attacker, TRUE, fontsize);
2175                                 pos_attacker = pos + eX * (0.48 * mySize_x - height - width_attacker) + eY * ((0.5 * fontsize_y + i * height) + (0.5 * (height - fontheight)));
2176                                 pos_victim = pos + eX * (0.52 * mySize_x + height) + eY * ((0.5 * fontsize_y + i * height) + (0.5 * (height - fontheight)));
2177                                 pos_icon = pos + eX * 0.5 * mySize_x - eX * height + eY * i * height;
2178
2179                                 drawpic_aspect_skin(pos_icon, icon, '2 1 0' * height, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
2180                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2181                                 drawcolorcodedstring(pos_victim, victim, fontsize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2182                         }
2183                 }
2184         }
2185 }
2186
2187 // Timer (#5)
2188 //
2189 // TODO: macro
2190 string seconds_tostring(float sec)
2191 {
2192         float minutes;
2193         minutes = floor(sec / 60);
2194
2195         sec -= minutes * 60;
2196         return sprintf("%d:%02d", minutes, sec);
2197 }
2198
2199 void HUD_Timer(void)
2200 {
2201         if(!autocvar__hud_configure)
2202         {
2203                 if(!autocvar_hud_panel_timer) return;
2204         }
2205         else
2206                 hud_configure_active_panel = HUD_PANEL_TIMER;
2207
2208         HUD_Panel_UpdateCvars(timer);
2209         HUD_Panel_ApplyFadeAlpha();
2210
2211         draw_beginBoldFont();
2212
2213         vector pos, mySize;
2214         pos = panel_pos;
2215         mySize = panel_size;
2216
2217         HUD_Panel_DrawBg(1);
2218         if(panel_bg_padding)
2219         {
2220                 pos += '1 1 0' * panel_bg_padding;
2221                 mySize -= '2 2 0' * panel_bg_padding;
2222         }
2223
2224         string timer;
2225         float timelimit, elapsedTime, timeleft, minutesLeft;
2226
2227         timelimit = getstatf(STAT_TIMELIMIT);
2228
2229         timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
2230         timeleft = ceil(timeleft);
2231
2232         minutesLeft = floor(timeleft / 60);
2233
2234         vector timer_color;
2235         if(minutesLeft >= 5 || warmup_stage || timelimit == 0) //don't use red or yellow in warmup or when there is no timelimit
2236                 timer_color = '1 1 1'; //white
2237         else if(minutesLeft >= 1)
2238                 timer_color = '1 1 0'; //yellow
2239         else
2240                 timer_color = '1 0 0'; //red
2241
2242         if (autocvar_hud_panel_timer_increment || timelimit == 0 || warmup_stage) {
2243                 if (time < getstatf(STAT_GAMESTARTTIME)) {
2244                         //while restart is still active, show 00:00
2245                         timer = seconds_tostring(0);
2246                 } else {
2247                         elapsedTime = floor(time - getstatf(STAT_GAMESTARTTIME)); //127
2248                         timer = seconds_tostring(elapsedTime);
2249                 }
2250         } else {
2251                 timer = seconds_tostring(timeleft);
2252         }
2253
2254         drawstring_aspect(pos, timer, mySize, timer_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2255
2256         draw_endBoldFont();
2257 }
2258
2259 // Radar (#6)
2260 //
2261 void HUD_Radar(void)
2262 {
2263         if (!autocvar__hud_configure)
2264         {
2265                 if (hud_panel_radar_maximized)
2266                 {
2267                         if (!hud_draw_maximized) return;
2268                 }
2269                 else
2270                 {
2271                         if (autocvar_hud_panel_radar == 0) return;
2272                         if (autocvar_hud_panel_radar != 2 && !teamplay) return;
2273                 }
2274         }
2275         else
2276                 hud_configure_active_panel = HUD_PANEL_RADAR;
2277
2278         HUD_Panel_UpdateCvars(radar);
2279         HUD_Panel_ApplyFadeAlpha();
2280
2281         if (hud_panel_radar_maximized && !autocvar__hud_configure)
2282         {
2283                 panel_size = autocvar_hud_panel_radar_maximized_size;
2284                 panel_size_x = bound(0.2, panel_size_x, 1) * vid_conwidth;
2285                 panel_size_y = bound(0.2, panel_size_y, 1) * vid_conheight;
2286                 panel_pos_x = (vid_conwidth - panel_size_x) / 2;
2287                 panel_pos_y = (vid_conheight - panel_size_y) / 2;
2288                 
2289                 panel_bg = strcat(hud_skin_path, "/border_default"); // always use the default border when maximized
2290                 if(precache_pic(panel_bg) == "") { panel_bg = "gfx/hud/default/border_default"; } // fallback
2291         }
2292
2293         vector pos, mySize;
2294         pos = panel_pos;
2295         mySize = panel_size;
2296
2297         HUD_Panel_DrawBg(1);
2298         if(panel_bg_padding)
2299         {
2300                 pos += '1 1 0' * panel_bg_padding;
2301                 mySize -= '2 2 0' * panel_bg_padding;
2302         }
2303
2304         float color2;
2305         entity tm;
2306         float scale2d, normalsize, bigsize;
2307         float f;
2308
2309         teamradar_origin2d = pos + 0.5 * mySize;
2310         teamradar_size2d = mySize;
2311
2312         if(minimapname == "")
2313                 return;
2314
2315         teamradar_loadcvars();
2316
2317         switch(hud_panel_radar_zoommode)
2318         {
2319                 default:
2320                 case 0:
2321                         f = current_zoomfraction;
2322                         break;
2323                 case 1:
2324                         f = 1 - current_zoomfraction;
2325                         break;
2326                 case 2:
2327                         f = 0;
2328                         break;
2329                 case 3:
2330                         f = 1;
2331                         break;
2332         }
2333
2334         switch(hud_panel_radar_rotation)
2335         {
2336                 case 0:
2337                         teamradar_angle = view_angles_y - 90;
2338                         break;
2339                 default:
2340                         teamradar_angle = 90 * hud_panel_radar_rotation;
2341                         break;
2342         }
2343
2344         scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
2345         teamradar_size2d = mySize;
2346
2347         teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0'; // we always center
2348
2349         // pixels per world qu to match the teamradar_size2d_x range in the longest dimension
2350         if(hud_panel_radar_rotation == 0)
2351         {
2352                 // max-min distance must fit the radar in any rotation
2353                 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen2d(mi_scale));
2354         }
2355         else
2356         {
2357                 vector c0, c1, c2, c3, span;
2358                 c0 = rotate(mi_min, teamradar_angle * DEG2RAD);
2359                 c1 = rotate(mi_max, teamradar_angle * DEG2RAD);
2360                 c2 = rotate('1 0 0' * mi_min_x + '0 1 0' * mi_max_y, teamradar_angle * DEG2RAD);
2361                 c3 = rotate('1 0 0' * mi_max_x + '0 1 0' * mi_min_y, teamradar_angle * DEG2RAD);
2362                 span = '0 0 0';
2363                 span_x = max(c0_x, c1_x, c2_x, c3_x) - min(c0_x, c1_x, c2_x, c3_x);
2364                 span_y = max(c0_y, c1_y, c2_y, c3_y) - min(c0_y, c1_y, c2_y, c3_y);
2365
2366                 // max-min distance must fit the radar in x=x, y=y
2367                 bigsize = min(
2368                         teamradar_size2d_x * scale2d / (1.05 * span_x),
2369                         teamradar_size2d_y * scale2d / (1.05 * span_y)
2370                 );
2371         }
2372
2373         normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / hud_panel_radar_scale;
2374         if(bigsize > normalsize)
2375                 normalsize = bigsize;
2376
2377         teamradar_size =
2378                   f * bigsize
2379                 + (1 - f) * normalsize;
2380         teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
2381                   f * mi_center
2382                 + (1 - f) * view_origin);
2383
2384         drawsetcliparea(
2385                 pos_x,
2386                 pos_y,
2387                 mySize_x,
2388                 mySize_y
2389         );
2390
2391         draw_teamradar_background(hud_panel_radar_foreground_alpha);
2392
2393         for(tm = world; (tm = find(tm, classname, "radarlink")); )
2394                 draw_teamradar_link(tm.origin, tm.velocity, tm.team);
2395         for(tm = world; (tm = findflags(tm, teamradar_icon, 0xFFFFFF)); )
2396                 draw_teamradar_icon(tm.origin, tm.teamradar_icon, tm, tm.teamradar_color, panel_fg_alpha);
2397         for(tm = world; (tm = find(tm, classname, "entcs_receiver")); )
2398         {
2399                 color2 = GetPlayerColor(tm.sv_entnum);
2400                 //if(color == FL_SPECTATOR || color == color2)
2401                         draw_teamradar_player(tm.origin, tm.angles, Team_ColorRGB(color2));
2402         }
2403         draw_teamradar_player(view_origin, view_angles, '1 1 1');
2404
2405         drawresetcliparea();
2406 };
2407
2408 // Score (#7)
2409 //
2410 void HUD_UpdatePlayerTeams();
2411 void HUD_Score_Rankings(vector pos, vector mySize, entity me, float team_count)
2412 {
2413         float score;
2414         entity tm = world, pl;
2415 #define SCOREPANEL_MAX_ENTRIES 6
2416 #define SCOREPANEL_ASPECTRATIO 2
2417         float entries = bound(1, floor(SCOREPANEL_MAX_ENTRIES * mySize_y/mySize_x * SCOREPANEL_ASPECTRATIO), SCOREPANEL_MAX_ENTRIES);
2418         vector fontsize = '1 1 0' * (mySize_y/entries);
2419
2420         vector rgb, score_color;
2421         rgb = '1 1 1';
2422         score_color = '1 1 1';
2423
2424         float name_size = mySize_x*0.75;
2425         float spacing_size = mySize_x*0.04;
2426         const float highlight_alpha = 0.2;
2427         float i = 0, me_printed = 0, first_pl = 0;
2428         string s;
2429         if (autocvar__hud_configure)
2430         {
2431                 float players_per_team = 0;
2432                 if (team_count)
2433                 {
2434                         // show team scores in the first line
2435                         float score_size = mySize_x / team_count;
2436                         players_per_team = max(2, ceil((entries - 1) / team_count));
2437                         for(i=0; i<team_count; ++i) {
2438                                 if (i == floor((entries - 2) / players_per_team) || (entries == 1 && i == 0))
2439                                         HUD_Panel_DrawHighlight(pos + eX * score_size * i, eX * score_size + eY * fontsize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2440                                 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);
2441                         }
2442                         first_pl = 1;
2443                         pos_y += fontsize_y;
2444                 }
2445                 score = 10 + SCOREPANEL_MAX_ENTRIES * 3;
2446                 for (i=first_pl; i<entries; ++i)
2447                 {
2448                         //simulate my score is lower than all displayed players,
2449                         //so that I don't appear at all showing pure rankings.
2450                         //This is to better show the difference between the 2 ranking views
2451                         if (i == entries-1 && autocvar_hud_panel_score_rankings == 1)
2452                         {
2453                                 rgb = '1 1 0';
2454                                 drawfill(pos, eX * mySize_x + eY * fontsize_y, rgb, highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2455                                 s = GetPlayerName(player_localnum);
2456                                 score = 7;
2457                         }
2458                         else
2459                         {
2460                                 s = sprintf(_("Player %d"), i + 1 - first_pl);
2461                                 score -= 3;
2462                         }
2463
2464                         if (team_count)
2465                                 score_color = Team_ColorRGB(ColorByTeam(floor((i - first_pl) / players_per_team))) * 0.8;
2466                         s = textShortenToWidth(s, name_size, fontsize, stringwidth_colors);
2467                         drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, TRUE, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
2468                         drawstring(pos + eX * (name_size + spacing_size), ftos(score), fontsize, score_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2469                         pos_y += fontsize_y;
2470                 }
2471                 return;
2472         }
2473
2474         if (!scoreboard_fade_alpha) // the scoreboard too calls HUD_UpdatePlayerTeams
2475                 HUD_UpdatePlayerTeams();
2476         if (team_count)
2477         {
2478                 // show team scores in the first line
2479                 float score_size = mySize_x / team_count;
2480                 for(tm = teams.sort_next; tm; tm = tm.sort_next) {
2481                         if(tm.team == FL_SPECTATOR)
2482                                 continue;
2483                         if (tm.team == myteam)
2484                                 drawfill(pos + eX * score_size * i, eX * score_size + eY * fontsize_y, '1 1 1', highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2485                         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);
2486                         ++i;
2487                 }
2488                 first_pl = 1;
2489                 pos_y += fontsize_y;
2490                 tm = teams.sort_next;
2491         }
2492         i = first_pl;
2493
2494         do
2495         for (pl = players.sort_next; pl && i<entries; pl = pl.sort_next)
2496         {
2497                 if ((team_count && pl.team != tm.team) || pl.team == FL_SPECTATOR)
2498                         continue;
2499
2500                 if (i == entries-1 && !me_printed && pl != me)
2501                 if (autocvar_hud_panel_score_rankings == 1 && spectatee_status != -1)
2502                 {
2503                         for (pl = me.sort_next; pl; pl = pl.sort_next)
2504                                 if (pl.team != FL_SPECTATOR)
2505                                         break;
2506
2507                         if (pl)
2508                                 rgb = '1 1 0'; //not last but not among the leading players: yellow
2509                         else
2510                                 rgb = '1 0 0'; //last: red
2511                         pl = me;
2512                 }
2513
2514                 if (pl == me)
2515                 {
2516                         if (i == first_pl)
2517                                 rgb = '0 1 0'; //first: green
2518                         me_printed = 1;
2519                         drawfill(pos, eX * mySize_x + eY * fontsize_y, rgb, highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2520                 }
2521                 if (team_count)
2522                         score_color = Team_ColorRGB(pl.team) * 0.8;
2523                 s = textShortenToWidth(GetPlayerName(pl.sv_entnum), name_size, fontsize, stringwidth_colors);
2524                 drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, TRUE, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
2525                 drawstring(pos + eX * (name_size + spacing_size), ftos(pl.(scores[ps_primary])), fontsize, score_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2526                 pos_y += fontsize_y;
2527                 ++i;
2528         }
2529         while (i<entries && team_count && (tm = tm.sort_next) && (tm.team != FL_SPECTATOR || (tm = tm.sort_next)));
2530 }
2531
2532 void HUD_Score(void)
2533 {
2534         if(!autocvar__hud_configure)
2535         {
2536                 if(!autocvar_hud_panel_score) return;
2537                 if(spectatee_status == -1 && (gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return;
2538         }
2539         else
2540                 hud_configure_active_panel = HUD_PANEL_SCORE;
2541
2542         HUD_Panel_UpdateCvars(score);
2543         HUD_Panel_ApplyFadeAlpha();
2544         vector pos, mySize;
2545         pos = panel_pos;
2546         mySize = panel_size;
2547
2548         HUD_Panel_DrawBg(1);
2549         if(panel_bg_padding)
2550         {
2551                 pos += '1 1 0' * panel_bg_padding;
2552                 mySize -= '2 2 0' * panel_bg_padding;
2553         }
2554
2555         float score, distribution = 0;
2556         string sign;
2557         vector distribution_color;
2558         entity tm, pl, me;
2559
2560 #ifdef COMPAT_XON050_ENGINE
2561         me = (spectatee_status > 0) ? playerslots[spectatee_status - 1] : playerslots[player_localentnum - 1];
2562 #else
2563         me = playerslots[player_localentnum - 1];
2564 #endif
2565
2566         if((scores_flags[ps_primary] & SFL_TIME) && !teamplay) { // race/cts record display on HUD
2567                 string timer, distrtimer;
2568
2569                 pl = players.sort_next;
2570                 if(pl == me)
2571                         pl = pl.sort_next;
2572                 if(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)
2573                         if(pl.scores[ps_primary] == 0)
2574                                 pl = world;
2575
2576                 score = me.(scores[ps_primary]);
2577                 timer = TIME_ENCODED_TOSTRING(score);
2578
2579                 draw_beginBoldFont();
2580                 if (pl && ((!(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)) || score)) {
2581                         // distribution display
2582                         distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
2583
2584                         distrtimer = ftos_decimals(fabs(distribution/pow(10, TIME_DECIMALS)), TIME_DECIMALS);
2585
2586                         if (distribution <= 0) {
2587                                 distribution_color = '0 1 0';
2588                                 sign = "-";
2589                         }
2590                         else {
2591                                 distribution_color = '1 0 0';
2592                                 sign = "+";
2593                         }
2594                         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);
2595                 }
2596                 // race record display
2597                 if (distribution <= 0)
2598                         HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2599                 drawstring_aspect(pos, timer, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2600                 draw_endBoldFont();
2601         } else if (!teamplay) { // non-teamgames
2602                 if ((spectatee_status == -1 && !autocvar__hud_configure) || autocvar_hud_panel_score_rankings)
2603                 {
2604                         HUD_Score_Rankings(pos, mySize, me, 0);
2605                         return;
2606                 }
2607                 // me vector := [team/connected frags id]
2608                 pl = players.sort_next;
2609                 if(pl == me)
2610                         pl = pl.sort_next;
2611
2612                 if(autocvar__hud_configure)
2613                         distribution = 42;
2614                 else if(pl)
2615                         distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
2616                 else
2617                         distribution = 0;
2618
2619                 score = me.(scores[ps_primary]);
2620                 if(autocvar__hud_configure)
2621                         score = 123;
2622
2623                 if(distribution >= 5)
2624                         distribution_color = eY;
2625                 else if(distribution >= 0)
2626                         distribution_color = '1 1 1';
2627                 else if(distribution >= -5)
2628                         distribution_color = '1 1 0';
2629                 else
2630                         distribution_color = eX;
2631
2632                 string distribution_str;
2633                 distribution_str = ftos(distribution);
2634                 draw_beginBoldFont();
2635                 if (distribution >= 0)
2636                 {
2637                         if (distribution > 0)
2638                                 distribution_str = strcat("+", distribution_str);
2639                         HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2640                 }
2641                 drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize_x + eY * mySize_y, distribution_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2642                 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);
2643                 draw_endBoldFont();
2644         } else { // teamgames
2645                 float scores_count = 0, row, column, rows = 0, columns = 0;
2646                 local noref vector offset = '0 0 0';
2647                 vector score_pos, score_size; //for scores other than myteam
2648                 if (spectatee_status == -1 || autocvar_hud_panel_score_rankings)
2649                 {
2650                         for(tm = teams.sort_next; tm, tm.team != FL_SPECTATOR; tm = tm.sort_next)
2651                                 ++scores_count;
2652                         if (autocvar_hud_panel_score_rankings)
2653                         {
2654                                 HUD_Score_Rankings(pos, mySize, me, scores_count);
2655                                 return;
2656                         }
2657                         rows = mySize_y/mySize_x;
2658                         rows = bound(1, floor((sqrt(4 * (3/1) * rows * scores_count + rows * rows) + rows + 0.5) / 2), scores_count);
2659                         //                               ^^^ ammo item aspect goes here
2660
2661                         columns = ceil(scores_count/rows);
2662
2663                         score_size = eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows);
2664
2665                         float newSize;
2666                         if(score_size_x/score_size_y > 3)
2667                         {
2668                                 newSize = 3 * score_size_y;
2669                                 offset_x = score_size_x - newSize;
2670                                 pos_x += offset_x/2;
2671                                 score_size_x = newSize;
2672                         }
2673                         else
2674                         {
2675                                 newSize = 1/3 * score_size_x;
2676                                 offset_y = score_size_y - newSize;
2677                                 pos_y += offset_y/2;
2678                                 score_size_y = newSize;
2679                         }
2680                 }
2681                 else
2682                         score_size = eX * mySize_x*(1/4) + eY * mySize_y*(1/3);
2683
2684                 float max_fragcount;
2685                 max_fragcount = -99;
2686                 draw_beginBoldFont();
2687                 row = column = 0;
2688                 for(tm = teams.sort_next; tm; tm = tm.sort_next) {
2689                         if(tm.team == FL_SPECTATOR)
2690                                 continue;
2691                         score = tm.(teamscores[ts_primary]);
2692                         if(autocvar__hud_configure)
2693                                 score = 123;
2694                         
2695                         if (score > max_fragcount)
2696                                 max_fragcount = score;
2697
2698                         if (spectatee_status == -1)
2699                         {
2700                                 score_pos = pos + eX * column * (score_size_x + offset_x) + eY * row * (score_size_y + offset_y);
2701                                 if (max_fragcount == score)
2702                                         HUD_Panel_DrawHighlight(score_pos, score_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2703                                 drawstring_aspect(score_pos, ftos(score), score_size, Team_ColorRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2704                                 ++row;
2705                                 if(row >= rows)
2706                                 {
2707                                         row = 0;
2708                                         ++column;
2709                                 }
2710                         }
2711                         else if(tm.team == myteam) {
2712                                 if (max_fragcount == score)
2713                                         HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2714                                 drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize_x + eY * mySize_y, Team_ColorRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2715                         } else {
2716                                 if (max_fragcount == score)
2717                                         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);
2718                                 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);
2719                                 ++rows;
2720                         }
2721                 }
2722                 draw_endBoldFont();
2723         }
2724 }
2725
2726 // Race timer (#8)
2727 //
2728 void HUD_RaceTimer (void)
2729 {
2730         if(!autocvar__hud_configure)
2731         {
2732                 if(!autocvar_hud_panel_racetimer) return;
2733                 if(!(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return;
2734                 if(spectatee_status == -1) return;
2735         }
2736         else
2737                 hud_configure_active_panel = HUD_PANEL_RACETIMER;
2738
2739         HUD_Panel_UpdateCvars(racetimer);
2740         HUD_Panel_ApplyFadeAlpha();
2741
2742         draw_beginBoldFont();
2743
2744         vector pos, mySize;
2745         pos = panel_pos;
2746         mySize = panel_size;
2747
2748         HUD_Panel_DrawBg(1);
2749         if(panel_bg_padding)
2750         {
2751                 pos += '1 1 0' * panel_bg_padding;
2752                 mySize -= '2 2 0' * panel_bg_padding;
2753         }
2754
2755         // always force 4:1 aspect
2756         vector newSize = '0 0 0';
2757         if(mySize_x/mySize_y > 4)
2758         {
2759                 newSize_x = 4 * mySize_y;
2760                 newSize_y = mySize_y;
2761
2762                 pos_x = pos_x + (mySize_x - newSize_x) / 2;
2763         }
2764         else
2765         {
2766                 newSize_y = 1/4 * mySize_x;
2767                 newSize_x = mySize_x;
2768
2769                 pos_y = pos_y + (mySize_y - newSize_y) / 2;
2770         }
2771         mySize =&nb