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