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