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