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