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