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