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