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