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