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