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