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