]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud.qc
centerprints
[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 // color the number differently based on how big it is (used in the health/armor panel)
221 void HUD_DrawXNum_Colored (vector pos, float x, float digits, float lettersize, float alpha)
222 {
223         vector color;
224         if(x > 200) {
225                 color_x = 0;
226                 color_y = 1;
227                 color_z = 0;
228         }
229         else if(x > 150) {
230                 color_x = 0.4 - (x-150)*0.02 * 0.4; //red value between 0.4 -> 0
231                 color_y = 0.9 + (x-150)*0.02 * 0.1; // green value between 0.9 -> 1
232                 color_z = 0;
233         }
234         else if(x > 100) {
235                 color_x = 1 - (x-100)*0.02 * 0.6; //red value between 1 -> 0.4
236                 color_y = 1 - (x-100)*0.02 * 0.1; // green value between 1 -> 0.9
237                 color_z = 1 - (x-100)*0.02; // blue value between 1 -> 0
238         }
239         else if(x > 50) {
240                 color_x = 1;
241                 color_y = 1;
242                 color_z = 0.2 + (x-50)*0.02 * 0.8; // blue value between 0.2 -> 1
243         }
244         else if(x > 20) {
245                 color_x = 1;
246                 color_y = (x-20)*90/27/100; // green value between 0 -> 1
247                 color_z = (x-20)*90/27/100 * 0.2; // blue value between 0 -> 0.2
248         }
249         else {
250                 color_x = 1;
251                 color_y = 0;
252                 color_z = 0;
253         }
254         HUD_DrawXNum(pos, x, digits, 0, lettersize, color, 0, 0, alpha, DRAWFLAG_NORMAL);
255 }
256
257 float stringwidth_colors(string s, vector theSize)
258 {
259         return stringwidth(s, TRUE, theSize);
260 }
261
262 float stringwidth_nocolors(string s, vector theSize)
263 {
264         return stringwidth(s, FALSE, theSize);
265 }
266
267 #define CENTERPRINT_MAX_LINES 30
268 string centerprint_messages[CENTERPRINT_MAX_LINES];
269 float centerprint_width[CENTERPRINT_MAX_LINES];
270 vector centerprint_start;
271 float centerprint_expire;
272 float centerprint_num;
273 float centerprint_offset_hint;
274 vector centerprint_fontsize;
275
276 void centerprint(string strMessage)
277 {
278         float i, j, n, hcount;
279         string s;
280
281         centerprint_fontsize = HUD_GetFontsize("scr_centersize");
282
283         centerprint_expire = min(centerprint_expire, time); // if any of the returns happens, this message will fade out
284
285         if(cvar("scr_centertime") <= 0)
286                 return;
287
288         if(strMessage == "")
289                 return;
290
291         // strip trailing newlines
292         j = strlen(strMessage) - 1;
293         while(substring(strMessage, j, 1) == "\n" && j >= 0)
294                 j = j - 1;
295         strMessage = substring(strMessage, 0, j + 1);
296
297         if(strMessage == "")
298                 return;
299
300         // strip leading newlines and remember them, they are a hint that the message should be lower on the screen
301         j = 0;
302         while(substring(strMessage, j, 1) == "\n" && j < strlen(strMessage))
303                 j = j + 1;
304         strMessage = substring(strMessage, j, strlen(strMessage) - j);
305         centerprint_offset_hint = j;
306
307         if(strMessage == "")
308                 return;
309
310         // if we get here, we have a message. Initialize its height.
311         centerprint_num = 0;
312
313         n = tokenizebyseparator(strMessage, "\n");
314         i = hcount = 0;
315         for(j = 0; j < n; ++j)
316         {
317                 getWrappedLine_remaining = argv(j);
318                 while(getWrappedLine_remaining)
319                 {
320                         s = getWrappedLine(vid_conwidth * 0.75, centerprint_fontsize, stringwidth_colors);
321                         if(centerprint_messages[i])
322                                 strunzone(centerprint_messages[i]);
323                         centerprint_messages[i] = strzone(s);
324                         centerprint_width[i] = stringwidth(s, TRUE, centerprint_fontsize);
325                         ++i;
326
327                         // half height for empty lines looks better
328                         if(s == "")
329                                 hcount += 0.5;
330                         else
331                                 hcount += 1;
332
333                         if(i >= CENTERPRINT_MAX_LINES)
334                                 break;
335                 }
336         }
337
338         float h, havail;
339         h = centerprint_fontsize_y*hcount;
340
341         havail = vid_conheight;
342         if(cvar("con_chatpos") < 0)
343                 havail -= (-cvar("con_chatpos") + cvar("con_chat")) * cvar("con_chatsize"); // avoid overlapping chat
344         if(havail > vid_conheight - 70)
345                 havail = vid_conheight - 70; // avoid overlapping HUD
346
347         centerprint_start_x = 0;
348
349 #if 0
350         float forbiddenmin, forbiddenmax, allowedmin, allowedmax, preferred;
351
352         // here, the centerprint would cover the crosshair. REALLY BAD.
353         forbiddenmin = vid_conheight * 0.5 - h - 16;
354         forbiddenmax = vid_conheight * 0.5 + 16;
355
356         allowedmin = scoreboard_bottom;
357         allowedmax = havail - h;
358         preferred = (havail - h)/2;
359
360
361         // possible orderings (total: 4! / 4 = 6)
362         //  allowedmin allowedmax forbiddenmin forbiddenmax
363         //  forbiddenmin forbiddenmax allowedmin allowedmax
364         if(allowedmax < forbiddenmin || allowedmin > forbiddenmax)
365         {
366                 // forbidden doesn't matter in this case
367                 centerprint_start_y = bound(allowedmin, preferred, allowedmax);
368         }
369         //  allowedmin forbiddenmin allowedmax forbiddenmax
370         else if(allowedmin < forbiddenmin && allowedmax < forbiddenmax)
371         {
372                 centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
373         }
374         //  allowedmin forbiddenmin forbiddenmax allowedmax
375         else if(allowedmin < forbiddenmin)
376         {
377                 // make sure the forbidden zone is not covered
378                 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
379                         centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
380                 else
381                         centerprint_start_y = bound(forbiddenmax, preferred, allowedmin);
382         }
383         //  forbiddenmin allowedmin allowedmax forbiddenmax
384         else if(allowedmax < forbiddenmax)
385         {
386                 // it's better to leave the allowed zone (overlap with scoreboard) than
387                 // to cover the forbidden zone (crosshair)
388                 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
389                         centerprint_start_y = forbiddenmax;
390                 else
391                         centerprint_start_y = forbiddenmin;
392         }
393         //  forbiddenmin allowedmin forbiddenmax allowedmax
394         else
395         {
396                 centerprint_start_y = bound(forbiddenmax, preferred, allowedmax);
397         }
398 #else
399         centerprint_start_y =
400                 min(
401                         max(
402                                 max(scoreboard_bottom, vid_conheight * 0.5 + 16),
403                                 (havail - h)/2
404                         ),
405                         havail - h
406                 );
407 #endif
408
409         centerprint_num = i;
410         centerprint_expire = time + cvar("scr_centertime");
411 }
412
413 void HUD_DrawCenterPrint (void)
414 {
415         float i;
416         vector pos;
417         string ts;
418         float a;
419
420         //if(time > centerprint_expire)
421         //      return;
422
423         //a = bound(0, 1 - 2 * (time - centerprint_expire), 1);
424         a = bound(0, 1 - 4 * (time - centerprint_expire), 1);
425         //sz = 1.2 / (a + 0.2);
426
427         if(a <= 0)
428                 return;
429
430         pos = centerprint_start;
431         for (i=0; i<centerprint_num; i = i + 1)
432         {
433                 pos_x = (vid_conwidth - centerprint_width[i]) * 0.5;
434                 ts = centerprint_messages[i];
435                 if (ts != "")
436                 {
437                         dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
438                         drawcolorcodedstring(pos, ts, centerprint_fontsize, a, DRAWFLAG_NORMAL);
439                         //  - '0 0.5 0' * (sz - 1) * centerprint_fontsize_x - '0.5 0 0' * (sz - 1) * centerprint_width[i] * centerprint_fontsize_y, centerprint_fontsize * sz
440                         pos_y = pos_y + centerprint_fontsize_y;
441                 }
442                 else
443                         // half height for empty lines looks better
444                         pos_y = pos_y + centerprint_fontsize_y * 0.5;
445         }
446 }
447
448 void drawstringright(vector position, string text, vector scale, vector rgb, float alpha, float flag)
449 {
450         position_x -= 2 / 3 * strlen(text) * scale_x;
451         drawstring(position, text, scale, rgb, alpha, flag);
452 }
453
454 void drawstringcenter(vector position, string text, vector scale, vector rgb, float alpha, float flag)
455 {
456         position_x = 0.5 * (vid_conwidth - 0.6025 * strlen(text) * scale_x);
457         drawstring(position, text, scale, rgb, alpha, flag);
458 }
459
460 // return the string of the given race place
461 string race_PlaceName(float pos) {
462         if(pos == 1)
463                 return "1st";
464         else if(pos == 2)
465                 return "2nd";
466         else if(pos == 3)
467                 return "3rd";
468         else
469                 return strcat(ftos(pos), "th");
470 }
471
472 // return the string of the onscreen race timer
473 string MakeRaceString(float cp, float mytime, float histime, float lapdelta, string hisname)
474 {
475         string col;
476         string timestr;
477         string cpname;
478         string lapstr;
479         lapstr = "";
480
481         if(histime == 0) // goal hit
482         {
483                 if(mytime > 0)
484                 {
485                         timestr = strcat("+", ftos_decimals(+mytime, TIME_DECIMALS));
486                         col = "^1";
487                 }
488                 else if(mytime == 0)
489                 {
490                         timestr = "+0.0";
491                         col = "^3";
492                 }
493                 else
494                 {
495                         timestr = strcat("-", ftos_decimals(-mytime, TIME_DECIMALS));
496                         col = "^2";
497                 }
498
499                 if(lapdelta > 0)
500                 {
501                         lapstr = strcat(" (-", ftos(lapdelta), "L)");
502                         col = "^2";
503                 }
504                 else if(lapdelta < 0)
505                 {
506                         lapstr = strcat(" (+", ftos(-lapdelta), "L)");
507                         col = "^1";
508                 }
509         }
510         else if(histime > 0) // anticipation
511         {
512                 if(mytime >= histime)
513                         timestr = strcat("+", ftos_decimals(mytime - histime, TIME_DECIMALS));
514                 else
515                         timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(histime));
516                 col = "^3";
517         }
518         else
519                 col = "^7";
520
521         if(cp == 254)
522                 cpname = "Start line";
523         else if(cp == 255)
524                 cpname = "Finish line";
525         else if(cp)
526                 cpname = strcat("Intermediate ", ftos(cp));
527         else
528                 cpname = "Finish line";
529
530         if(histime < 0)
531                 return strcat(col, cpname);
532         else if(hisname == "")
533                 return strcat(col, cpname, " (", timestr, ")");
534         else
535                 return strcat(col, cpname, " (", timestr, " ", strcat(hisname, col, lapstr), ")");
536 }
537
538 // Check if the given name already exist in race rankings? In that case, where? (otherwise return 0)
539 float race_CheckName(string net_name) {
540         float i;
541         for (i=RANKINGS_CNT-1;i>=0;--i)
542                 if(grecordholder[i] == net_name)
543                         return i+1;
544         return 0;
545 }
546
547 /*
548 ==================
549 HUD panels
550 ==================
551 */
552
553 string HUD_Panel_GetName(float id)
554 {
555         switch(id) {
556                 case 0: return "weaponicons"; break;
557                 case 1: return "inventory"; break;
558                 case 2: return "powerups"; break;
559                 case 3: return "healtharmor"; break;
560                 case 4: return "notify"; break;
561                 case 5: return "timer"; break;
562                 case 6: return "radar"; break;
563                 case 7: return "score"; break;
564                 case 8: return "racetimer"; break;
565                 case 9: return "vote"; break;
566                 case 10: return "modicons"; break;
567                 case 11: return "pressedkeys"; break;
568                 default: return "";
569         }
570 }
571
572 // Save the config
573 void HUD_Panel_ExportCfg(string cfgname)
574 {
575         float fh;
576         fh = fopen(strcat("hud_", cvar_string("hud_skin"), "_", cfgname, ".cfg"), FILE_WRITE);
577         if(fh >= 0)
578         {
579                 fputs(fh, strcat("seta hud_skin \"", cvar_string("hud_skin"), "\"", "\n"));
580                 fputs(fh, strcat("seta hud_bg \"", cvar_string("hud_bg"), "\"", "\n"));
581                 fputs(fh, strcat("seta hud_bg_color \"", cvar_string("hud_bg_color"), "\"", "\n"));
582                 fputs(fh, strcat("seta hud_bg_color_team \"", cvar_string("hud_bg_color_team"), "\"", "\n"));
583                 fputs(fh, strcat("seta hud_bg_alpha \"", cvar_string("hud_bg_alpha"), "\"", "\n"));
584                 fputs(fh, strcat("seta hud_bg_border \"", cvar_string("hud_bg_border"), "\"", "\n"));
585                 fputs(fh, strcat("seta hud_bg_padding \"", cvar_string("hud_bg_padding"), "\"", "\n"));
586                 fputs(fh, strcat("seta hud_fg_alpha \"", cvar_string("hud_fg_alpha"), "\"", "\n"));
587                 fputs(fh, "\n");
588
589                 fputs(fh, strcat("seta hud_dock \"", cvar_string("hud_dock"), "\"", "\n"));
590                 fputs(fh, strcat("seta hud_dock_color \"", cvar_string("hud_dock_color"), "\"", "\n"));
591                 fputs(fh, strcat("seta hud_dock_color_team \"", cvar_string("hud_dock_color_team"), "\"", "\n"));
592                 fputs(fh, strcat("seta hud_dock_alpha \"", ftos(cvar("hud_dock_alpha")), "\"", "\n"));
593                 fputs(fh, "\n");
594
595                 fputs(fh, strcat("seta hud_progressbar_alpha ", ftos(cvar("hud_progressbar_alpha")), "\n"));
596                 fputs(fh, strcat("seta hud_progressbar_strength_color \"", cvar_string("hud_progressbar_strength_color"), "\"", "\n"));
597                 fputs(fh, strcat("seta hud_progressbar_shield_color \"", cvar_string("hud_progressbar_shield_color"), "\"", "\n"));
598                 fputs(fh, strcat("seta hud_progressbar_health_color \"", cvar_string("hud_progressbar_health_color"), "\"", "\n"));
599                 fputs(fh, strcat("seta hud_progressbar_armor_color \"", cvar_string("hud_progressbar_armor_color"), "\"", "\n"));
600                 fputs(fh, strcat("seta hud_progressbar_fuel_color \"", cvar_string("hud_progressbar_fuel_color"), "\"", "\n"));
601                 fputs(fh, strcat("seta hud_progressbar_nexball_color \"", cvar_string("hud_progressbar_nexball_color"), "\"", "\n"));
602                 fputs(fh, "\n");
603
604                 // common cvars for all panels
605                 float i;
606                 for (i = 0; i < panel_cnt; ++i)
607                 {
608                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), " ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i)))), "\n"));
609                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_pos \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_pos")), "\"", "\n"));
610                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_size \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_size")), "\"", "\n"));
611                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg")), "\"", "\n"));
612                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_color \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg_color")), "\"", "\n"));
613                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_color_team \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg_color_team")), "\"", "\n"));
614                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_alpha \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg_alpha")), "\"", "\n"));
615                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_border \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg_border")), "\"", "\n"));
616                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_padding \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg_padding")), "\"", "\n"));
617                         switch(i) {
618                                 case 0:
619                                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_accuracy_height ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_accuracy_height"))), "\n"));
620                                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_accuracy_yellow ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_accuracy_yellow"))), "\n"));
621                                         break;
622                                 case 1:
623                                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_onlycurrent ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_onlycurrent"))), "\n"));
624                                         break;
625                                 case 2:
626                                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_flip ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_flip"))), "\n"));
627                                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_mirror ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_mirror"))), "\n"));
628                                         break;
629                                 case 3:
630                                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_flip ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_flip"))), "\n"));
631                                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_mirror ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_mirror"))), "\n"));
632                                         break;
633                                 case 9:
634                                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_alreadyvoted_alpha ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_alreadyvoted_alpha"))), "\n"));
635                                         break;
636                         }
637                         fputs(fh, "\n");
638                 }
639
640                 print("^2Successfully exported to hud_", cvar_string("hud_skin"), "_", cfgname, ".cfg! (Note: It's saved in data/data/)\n");
641         }
642         fclose(fh);
643 }
644
645 vector HUD_Panel_GetMinSize(float id)
646 {
647         vector mySize;
648         // note: please only set mySize_y on aspect ratio forced panels
649         switch(id) {
650                 case 0: 
651                         mySize_x = 1/10; // at least 1/10 * height
652                         mySize_y = 1/26; // at least 1/26 * width
653                         break;
654                 case 1: 
655                         if(cvar("hud_inventory_onlycurrent"))
656                                 mySize_y = 2/5; //  2/5 width
657                         else
658                                 mySize_x = 0.7; // at least 0.7 * height
659                         break;
660                 case 3: 
661                         if(cvar("hud_healtharmor") == 2)
662                                 mySize_y = 0.23; // 0.23 * width, trial and error...
663                         break;
664                 case 5: 
665                         mySize_y = 1/4.1; // 1/4.1 * width, trial and error...
666                         break;
667                 case 7: 
668                         mySize_y = 1/4; // 1/4 * width
669                         break;
670                 case 8: 
671                         mySize_y = 1/4; // 1/4 * width
672                         break;
673                 case 9: 
674                         mySize_y = 1/4; // 1/4 * width
675                         break;
676                 case 10: 
677                         mySize_y = 1/2; // 1/2 * width
678                         break;
679                 case 11: 
680                         mySize_y = 0.5898; // 0.5898 * width, reason: bg has weird dimensions...
681                         break;
682         }
683         if(!mySize_x)
684                 mySize_x = 1/mySize_y;
685         return mySize;
686 }
687
688 // return active status of panel
689 float HUD_Panel_CheckActive(float id)
690 {
691         if (cvar_or(strcat("hud_", HUD_Panel_GetName(id)), 1))
692                 return 1;
693         return 0;
694 }
695
696 // return size of given panel
697 vector HUD_Panel_GetSize(float id)
698 {
699         vector mySize;
700         mySize = stov(cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_size")));
701
702         mySize = eX * mySize_x * vid_conwidth + eY * mySize_y * vid_conheight;
703
704         return mySize;
705 }
706
707 // return pos of given panel
708 vector HUD_Panel_GetPos(float id)
709 {
710         vector pos;
711         pos = stov(cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_pos")));
712
713         pos = eX * pos_x * vid_conwidth + eY * pos_y * vid_conheight;
714
715         if (pos_x < 0)
716                 pos_x = vid_conwidth + pos_x;
717         if (pos_y < 0)
718                 pos_y = vid_conheight + pos_y;
719         return pos;
720 }
721
722 float HUD_Panel_GetBorder(float id)
723 {
724         string border;
725         border = cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_border"));
726         if(border == "")
727                 border = cvar_string("hud_bg_border");
728         return stof(border);
729 }
730
731 vector HUD_Panel_GetColor(float id)
732 {
733         float f;
734         vector color_vec;
735         string color;
736
737         // fetch per-panel color
738         if(teamplay && cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_color_team")) != "") {
739                 f = stof(getplayerkey(self.sv_entnum, "colors"));
740                 color = vtos(colormapPaletteColor(mod(f, 16), 1) * cvar(strcat("hud_", HUD_Panel_GetName(id), "_bg_color_team")));
741         }
742         else
743                 color = cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_color"));
744         color_vec = stov(color);
745
746         if(color == "") { // fetch default color
747                 color = cvar_string("hud_bg_color");
748                 color_vec = stov(color);
749                 if(teamplay && cvar(strcat("hud_bg_color_team"))) {
750                         f = stof(getplayerkey(self.sv_entnum, "colors"));
751                         color_vec = colormapPaletteColor(mod(f, 16), 1) * cvar("hud_bg_color_team");
752                 }
753                 else if(color == "shirt") {
754                         f = stof(getplayerkey(self.sv_entnum, "colors"));
755                         color_vec = colormapPaletteColor(floor(f / 16), 0);
756                 }
757                 else if(color == "pants") {
758                         f = stof(getplayerkey(self.sv_entnum, "colors"));
759                         color_vec = colormapPaletteColor(mod(f, 16), 1);
760                 }
761         }
762         else if(color == "shirt") {
763                 f = stof(getplayerkey(self.sv_entnum, "colors"));
764                 color_vec = colormapPaletteColor(floor(f / 16), 0);
765         }
766         else if(color == "pants") {
767                 f = stof(getplayerkey(self.sv_entnum, "colors"));
768                 color_vec = colormapPaletteColor(mod(f, 16), 1);
769         }
770         return color_vec;
771 }
772
773 vector HUD_Panel_Dock_GetColor(void)
774 {
775         float f;
776         vector color_vec;
777         string color;
778         color = cvar_string("hud_dock_color");
779         color_vec = stov(color);
780         if(teamplay && cvar(strcat("hud_dock_color_team"))) {
781                 f = stof(getplayerkey(self.sv_entnum, "colors"));
782                 color_vec = colormapPaletteColor(mod(f, 16), 1) * cvar("hud_dock_color_team");
783         }
784         else if(color == "shirt") {
785                 f = stof(getplayerkey(self.sv_entnum, "colors"));
786                 color_vec = colormapPaletteColor(floor(f / 16), 0);
787         }
788         else if(color == "pants") {
789                 f = stof(getplayerkey(self.sv_entnum, "colors"));
790                 color_vec = colormapPaletteColor(mod(f, 16), 1);
791         }
792         return color_vec;
793 }
794
795 float HUD_Panel_GetAlpha(float id)
796 {
797         string alpha;
798         alpha = cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_alpha"));
799         if(alpha == "")
800                 alpha = cvar_string("hud_bg_alpha");
801         return stof(alpha);
802 }
803
804 float HUD_Panel_GetPadding(float id)
805 {
806         string padding;
807         padding = cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_padding"));
808         if(padding == "")
809                 padding = cvar_string("hud_bg_padding");
810         return stof(padding);
811 }
812
813 // draw the background/borders
814 void HUD_Panel_DrawBg(float id, vector pos, vector mySize)
815 {
816         float alpha;
817
818         if(!hud_configure && cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg")) == "0")
819                 return;
820
821         string bg;
822         bg = cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg"));
823         if(bg == "")
824                 bg = cvar_string("hud_bg");
825
826         if(bg == "0" && hud_configure) {
827                 bg = "border"; // we probably want to see a background in config mode at all times...
828                 alpha = cvar("hud_configure_bg_minalpha");
829         }
830
831         if(bg != "0")
832         {
833                 float border;
834                 border = max(0.0000001, HUD_Panel_GetBorder(id)); // draw_BorderPicture does not like border = 0
835
836                 vector color;
837                 color = HUD_Panel_GetColor(id);
838
839                 if(!alpha)
840                         alpha = HUD_Panel_GetAlpha(id);
841
842                 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));
843         }
844 }
845
846 void HUD_Panel_DrawProgressBar(vector pos, float vertical, vector mySize, vector color, float alpha, float drawflag)
847 {
848 //float drawsubpic(vector position, vector size, string pic, vector srcPosition, vector srcSize, vector rgb, float alpha, float flag) = #328;
849         string pic;
850         pic = strcat("gfx/hud/", cvar_string("hud_skin"), "/");
851         if(vertical) {
852                 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);
853                 if(mySize_y/mySize_x > 2)
854                         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);
855                 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);
856         } else {
857                 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);
858                 if(mySize_x/mySize_y > 2)
859                         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);
860                 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);
861         }
862 }
863
864 vector HUD_Panel_GetProgressBarColor(string item)
865 {
866         return stov(cvar_string(strcat("hud_progressbar_", item, "_color")));
867 }
868
869 // check if move will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
870 vector HUD_Panel_CheckMove(float id, vector myPos, vector mySize)
871 {
872         float i;
873
874         vector myTarget;
875         myTarget = myPos;
876
877         vector targPos;
878         vector targSize;
879         vector myCenter;
880         vector targCenter;
881         myCenter = '0 0 0'; // shut up fteqcc, there IS a reference
882         targCenter = '0 0 0'; // shut up fteqcc, there IS a reference
883
884         for (i = 0; i < panel_cnt; ++i) {
885                 if(i == id || !HUD_Panel_CheckActive(i))
886                         continue;
887
888                 targPos = HUD_Panel_GetPos(i) - '1 1 0' * HUD_Panel_GetBorder(id);
889                 targSize = HUD_Panel_GetSize(i) + '2 2 0' * HUD_Panel_GetBorder(id);
890
891                 if(myPos_y + mySize_y < targPos_y)
892                         continue;
893                 if(myPos_y > targPos_y + targSize_y)
894                         continue;
895
896                 if(myPos_x + mySize_x < targPos_x)
897                         continue;
898                 if(myPos_x > targPos_x + targSize_x)
899                         continue;
900
901                 // OK, there IS a collision.
902
903                 myCenter_x = myPos_x + 0.5 * mySize_x;
904                 myCenter_y = myPos_y + 0.5 * mySize_y;
905
906                 targCenter_x = targPos_x + 0.5 * targSize_x;
907                 targCenter_y = targPos_y + 0.5 * targSize_y;
908
909                 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // top left (of the target panel)
910                 {
911                         if(myPos_x + mySize_x - targPos_x < myPos_y + mySize_y - targPos_y) // push it to the side
912                                 myTarget_x = targPos_x - mySize_x;
913                         else // push it upwards
914                                 myTarget_y = targPos_y - mySize_y;
915                 }
916                 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y) // top right
917                 {
918                         if(targPos_x + targSize_x - myPos_x < myPos_y + mySize_y - targPos_y) // push it to the side
919                                 myTarget_x = targPos_x + targSize_x;
920                         else // push it upwards
921                                 myTarget_y = targPos_y - mySize_y;
922                 }
923                 else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
924                 {
925                         if(myPos_x + mySize_x - targPos_x < targPos_y + targSize_y - myPos_y) // push it to the side
926                                 myTarget_x = targPos_x - mySize_x;
927                         else // push it downwards
928                                 myTarget_y = targPos_y + targSize_y;
929                 }
930                 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
931                 {
932                         if(targPos_x + targSize_x - myPos_x < targPos_y + targSize_y - myPos_y) // push it to the side
933                                 myTarget_x = targPos_x + targSize_x;
934                         else // push it downwards
935                                 myTarget_y = targPos_y + targSize_y;
936                 }
937         }
938
939         return myTarget;
940 }
941
942 void HUD_Panel_SetPos(float id, vector pos)
943 {
944         vector oldPos;
945         oldPos = HUD_Panel_GetPos(id);
946
947         vector mySize;
948         mySize = HUD_Panel_GetSize(id);
949
950         if(cvar("hud_configure_checkcollisions"))
951                 pos = HUD_Panel_CheckMove(id, pos, mySize);
952
953         pos_x = bound(0, pos_x, vid_conwidth - mySize_x);
954         pos_y = bound(0, pos_y, vid_conheight - mySize_y);
955
956         if(cvar("hud_configure_grid"))
957         {
958                 pos_x = floor(pos_x/cvar("hud_configure_grid_x") + 0.5) * cvar("hud_configure_grid_x");
959                 pos_y = floor(pos_y/cvar("hud_configure_grid_y") + 0.5) * cvar("hud_configure_grid_y");
960         }
961
962         if (pos_x + 0.5 * mySize_x > 0.5 * vid_conwidth)
963                 pos_x = pos_x - vid_conwidth;
964         if (pos_y + 0.5 * mySize_y > 0.5 * vid_conheight)
965                 pos_y = pos_y - vid_conheight;
966
967         string s;
968         s = strcat(ftos(pos_x/vid_conwidth), " ", ftos(pos_y/vid_conheight));
969
970         cvar_set(strcat("hud_", HUD_Panel_GetName(id), "_pos"), s);
971 }
972
973 // check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
974 vector HUD_Panel_CheckResize(float id, vector myPos, vector mySize)
975 {
976         float i;
977
978         vector myTarget;
979         myTarget = mySize;
980
981         vector targPos;
982         vector targSize;
983         vector myCenter;
984         vector targCenter;
985         myCenter = '0 0 0'; // shut up fteqcc, there IS a reference
986         targCenter = '0 0 0'; // shut up fteqcc, there IS a reference
987
988         for (i = 0; i < panel_cnt; ++i) {
989                 if(i == id || !HUD_Panel_CheckActive(i))
990                         continue;
991
992                 targPos = HUD_Panel_GetPos(i);
993                 targSize = HUD_Panel_GetSize(i);
994
995                 targPos = HUD_Panel_GetPos(i) - '1 1 0' * HUD_Panel_GetBorder(id);
996                 targSize = HUD_Panel_GetSize(i) + '2 2 0' * HUD_Panel_GetBorder(id);
997
998                 if(myPos_y + mySize_y < targPos_y)
999                         continue;
1000                 if(myPos_y > targPos_y + targSize_y)
1001                         continue;
1002
1003                 if(myPos_x + mySize_x < targPos_x)
1004                         continue;
1005                 if(myPos_x > targPos_x + targSize_x)
1006                         continue;
1007
1008                 // OK, there IS a collision.
1009
1010                 myCenter_x = myPos_x + 0.5 * mySize_x;
1011                 myCenter_y = myPos_y + 0.5 * mySize_y;
1012
1013                 targCenter_x = targPos_x + 0.5 * targSize_x;
1014                 targCenter_y = targPos_y + 0.5 * targSize_y;
1015
1016                 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // top left (of target panel)
1017                 {
1018                         if(myPos_x + mySize_x - targPos_x < myPos_y + mySize_y - targPos_y) // push it to the side
1019                                 myTarget_x = targPos_x - myPos_x;
1020                         else // push it upwards
1021                                 myTarget_y = targPos_y - myPos_y;
1022                 }
1023                 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y) // top right
1024                 {
1025                         if(targPos_x + targSize_x - myPos_x < myPos_y + mySize_y - targPos_y) // push it to the side
1026                                 myTarget_x = targPos_x + targSize_x;
1027                         else // push it upwards
1028                                 myTarget_y = targPos_y - myPos_y;
1029                 }
1030                 else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
1031                 {
1032                         if(myPos_x + mySize_x - targPos_x < targPos_y + targSize_y - myPos_y) // push it to the side
1033                                 myTarget_x = targPos_x - myPos_x;
1034                         else // push it downwards
1035                                 myTarget_y = targPos_y + targSize_y;
1036                 }
1037                 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
1038                 {
1039                         if(targPos_x + targSize_x - myPos_x < targPos_y + targSize_y - myPos_y) // push it to the side
1040                                 myTarget_x = targPos_x + targSize_x;
1041                         else // push it downwards
1042                                 myTarget_y = targPos_y + targSize_y;
1043                 }
1044         }
1045
1046         return myTarget;
1047 }
1048
1049 void HUD_Panel_SetPosSize(float id, vector resizeorigin)
1050 {
1051         vector mySize, myPos;
1052         vector oldPos;
1053
1054         if(resizeCorner == 1) {
1055                 mySize_x = resizeorigin_x - (mousepos_x - panel_click_distance_x);
1056                 mySize_y = resizeorigin_y - (mousepos_y - panel_click_distance_y);
1057         } else if(resizeCorner == 2) {          
1058                 mySize_x = mousepos_x + panel_click_distance_x - resizeorigin_x;
1059                 mySize_y = panel_click_distance_y + resizeorigin_y - mousepos_y;
1060         } else if(resizeCorner == 3) {
1061                 mySize_x = resizeorigin_x + panel_click_distance_x - mousepos_x;
1062                 mySize_y = mousepos_y + panel_click_distance_y - resizeorigin_y;
1063         } else { // resizeCorner == 4
1064                 mySize_x = mousepos_x - (resizeorigin_x - panel_click_distance_x);
1065                 mySize_y = mousepos_y - (resizeorigin_y - panel_click_distance_y);
1066         }
1067
1068         // minimum panel size cap
1069         mySize_x = max(0.025 * vid_conwidth, mySize_x);
1070         mySize_y = max(0.025 * vid_conheight, mySize_y);
1071
1072         // cap against panel's own limits
1073         vector minSize;
1074         minSize = HUD_Panel_GetMinSize(id); // mySize_x at least minSize_x * mySize_y, and vice versa
1075
1076         mySize_x = max(minSize_x * mySize_y, mySize_x);
1077         mySize_y = max(minSize_y * mySize_x, mySize_y);
1078
1079         // collision testing|
1080         // -----------------+
1081
1082         // we need to know pos at this stage, but it might still change later if we hit a screen edge/other panel (?)
1083         if(resizeCorner == 1) {
1084                 myPos_x = resizeorigin_x - mySize_x;
1085                 myPos_y = resizeorigin_y - mySize_y;
1086         } else if(resizeCorner == 2) {
1087                 myPos_x = resizeorigin_x;
1088                 myPos_y = resizeorigin_y - mySize_y;
1089         } else if(resizeCorner == 3) {
1090                 myPos_x = resizeorigin_x - mySize_x;
1091                 myPos_y = resizeorigin_y;
1092         } else { // resizeCorner == 4
1093                 myPos_x = resizeorigin_x;
1094                 myPos_y = resizeorigin_y;
1095         }
1096
1097         // left/top screen edges
1098         mySize_x = min(myPos_x + mySize_x, mySize_x);
1099         mySize_y = min(myPos_y + mySize_y, mySize_y);
1100
1101         // bottom/right screen edges
1102         mySize_x = min(vid_conwidth - myPos_x, mySize_x); 
1103         mySize_y = min(vid_conheight - myPos_y, mySize_y); 
1104
1105         if(cvar("hud_configure_checkcollisions")) {
1106                 oldPos = myPos;
1107                 mySize = HUD_Panel_CheckResize(id, myPos, mySize);
1108                 myPos = HUD_Panel_CheckMove(id, myPos, mySize); // touching myPos won't do anything... unless we make it change mySize somehow, see next line
1109                 mySize = mySize - myPos + oldPos; // TODO: this is still borked in some situations :(
1110         }
1111
1112         if(cvar("hud_configure_grid"))
1113         {
1114                 mySize_x = floor(mySize_x/cvar("hud_configure_grid_x") + 0.5) * cvar("hud_configure_grid_x");
1115                 mySize_y = floor(mySize_y/cvar("hud_configure_grid_y") + 0.5) * cvar("hud_configure_grid_y");
1116         }
1117
1118         // do another pos check, as size might have changed by now
1119         if(resizeCorner == 1) {
1120                 myPos_x = resizeorigin_x - mySize_x;
1121                 myPos_y = resizeorigin_y - mySize_y;
1122         } else if(resizeCorner == 2) {
1123                 myPos_x = resizeorigin_x;
1124                 myPos_y = resizeorigin_y - mySize_y;
1125         } else if(resizeCorner == 3) {
1126                 myPos_x = resizeorigin_x - mySize_x;
1127                 myPos_y = resizeorigin_y;
1128         } else { // resizeCorner == 4
1129                 myPos_x = resizeorigin_x;
1130                 myPos_y = resizeorigin_y;
1131         }
1132
1133         string s;
1134         s = strcat(ftos(mySize_x/vid_conwidth), " ", ftos(mySize_y/vid_conheight));
1135         cvar_set(strcat("hud_", HUD_Panel_GetName(id), "_size"), s);
1136
1137         s = strcat(ftos(myPos_x/vid_conwidth), " ", ftos(myPos_y/vid_conheight));
1138         cvar_set(strcat("hud_", HUD_Panel_GetName(id), "_pos"), s);
1139 }
1140
1141 float mouseClicked;
1142 float prevMouseClicked; // previous state
1143 float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
1144 {
1145         prevMouseClicked = mouseClicked;
1146         if(nPrimary == K_MOUSE1)
1147         {
1148                 if(bInputType == 0) { // key pressed
1149                         mouseClicked = 1;
1150                         return true;
1151                 }
1152                 if(bInputType == 1) {// key released
1153                         mouseClicked = 0;
1154                         return true;
1155                 }
1156         }
1157         return false;
1158 }
1159
1160 void HUD_Panel_Mouse()
1161 {
1162         if(mouseClicked == 0) {
1163                 highlightedPanel = -1;
1164                 highlightedAction = 0;
1165         }
1166
1167         mousepos = mousepos + getmousepos();
1168
1169         mousepos_x = bound(0, mousepos_x, vid_conwidth);
1170         mousepos_y = bound(0, mousepos_y, vid_conheight);
1171
1172         drawpic(mousepos, strcat("gfx/menu/", cvar_string("menu_skin"), "/cursor.tga"), '32 32 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1173
1174         if(mouseClicked)
1175         {
1176                 float i, border;
1177                 vector panelPos;
1178                 vector panelSize;
1179
1180                 for(i = 0; i <= panel_cnt; ++i)
1181                 {
1182                         panelPos = HUD_Panel_GetPos(i);
1183                         panelSize = HUD_Panel_GetSize(i);
1184                         border = HUD_Panel_GetBorder(i);
1185                         if(prevMouseClicked == 0) {
1186                                 // move
1187                                 if(mousepos_x >= panelPos_x && mousepos_y >= panelPos_y && mousepos_x <= panelPos_x + panelSize_x && mousepos_y <= panelPos_y + panelSize_y)
1188                                 {
1189                                         highlightedPanel = i;
1190                                         highlightedAction = 1;
1191                                 }
1192                                 // resize from topleft border
1193                                 else if(mousepos_x >= panelPos_x - border && mousepos_y >= panelPos_y - border && mousepos_x <= panelPos_x + 0.5 * panelSize_x && mousepos_y <= panelPos_y + 0.5 * panelSize_y)
1194                                 {
1195                                         highlightedPanel = i;
1196                                         highlightedAction = 2;
1197                                         resizeCorner = 1;
1198                                 }
1199                                 // resize from topright border
1200                                 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)
1201                                 {
1202                                         highlightedPanel = i;
1203                                         highlightedAction = 2;
1204                                         resizeCorner = 2;
1205                                 }
1206                                 // resize from bottomleft border
1207                                 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)
1208                                 {
1209                                         highlightedPanel = i;
1210                                         highlightedAction = 2;
1211                                         resizeCorner = 3;
1212                                 }
1213                                 // resize from bottomright border
1214                                 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)
1215                                 {
1216                                         highlightedPanel = i;
1217                                         highlightedAction = 2;
1218                                         resizeCorner = 4;
1219                                 }
1220                         }
1221
1222                         if(highlightedPanel == i)
1223                         {
1224                                 if(prevMouseClicked == 0)
1225                                 {
1226                                         if(highlightedAction == 1)
1227                                                 panel_click_distance = mousepos - panelPos;
1228                                         else if(highlightedAction == 2)
1229                                         {
1230                                                 if(resizeCorner == 1) {
1231                                                         panel_click_distance = mousepos - panelPos;
1232                                                         panel_click_resizeorigin = panelPos + panelSize;
1233                                                 } else if(resizeCorner == 2) {
1234                                                         panel_click_distance_x = panelSize_x - mousepos_x + panelPos_x;
1235                                                         panel_click_distance_y = mousepos_y - panelPos_y;
1236                                                         panel_click_resizeorigin = panelPos + eY * panelSize_y;
1237                                                 } else if(resizeCorner == 3) {
1238                                                         panel_click_distance_x = mousepos_x - panelPos_x;
1239                                                         panel_click_distance_y = panelSize_y - mousepos_y + panelPos_y;
1240                                                         panel_click_resizeorigin = panelPos + eX * panelSize_x;
1241                                                 } else if(resizeCorner == 4) {
1242                                                         panel_click_distance = panelSize - mousepos + panelPos;
1243                                                         panel_click_resizeorigin = panelPos;
1244                                                 }
1245                                         }       
1246                                 }
1247
1248                                 if(highlightedAction == 1)
1249                                         HUD_Panel_SetPos(i, mousepos - panel_click_distance);
1250                                 else if(highlightedAction == 2)
1251                                         HUD_Panel_SetPosSize(i, panel_click_resizeorigin);
1252                         }
1253                 }
1254         }
1255         prevMouseClicked = mouseClicked;
1256 }
1257
1258 // Weapon icons (#0)
1259 //
1260 float weaponspace[10];
1261 void HUD_WeaponIcons_Clear()
1262 {
1263         float idx;
1264         for(idx = 0; idx < 10; ++idx)
1265                 weaponspace[idx] = 0;
1266 }
1267
1268 entity weaponorder[WEP_MAXCOUNT];
1269
1270 void weaponorder_swap(float i, float j, entity pass)
1271 {
1272         entity h;
1273         h = weaponorder[i];
1274         weaponorder[i] = weaponorder[j];
1275         weaponorder[j] = h;
1276 }
1277
1278 float weaponorder_cmp(float i, float j, entity pass)
1279 {
1280         float d;
1281         d = mod(weaponorder[i].impulse + 9, 10) - mod(weaponorder[j].impulse + 9, 10);
1282         if(d)
1283                 return d;
1284         d = weaponorder[i].weapon - weaponorder[j].weapon;
1285         return d;
1286 }
1287
1288 void HUD_WeaponIcons()
1289 {
1290         float id = 0;
1291         float alpha, stat_weapons; // "constants"
1292         vector pos, mySize, accuracy_color;
1293         float i, weapid, fade, weapon_stats, weapon_hit, weapon_damage, weapon_cnt; // variables
1294
1295         pos = HUD_Panel_GetPos(id);
1296         mySize = HUD_Panel_GetSize(id);
1297
1298         stat_weapons = getstati(STAT_WEAPONS);
1299         for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1300         {
1301                 self = get_weaponinfo(i);
1302                 if(self.weapons && (self.impulse >= 0) && (stat_weapons & self.weapons) || hud_configure)
1303                 {
1304                         weaponorder[weapon_cnt] = self;
1305                         ++weapon_cnt;
1306                 }
1307         }
1308         heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, world);
1309
1310         HUD_Panel_DrawBg(id, pos, mySize);
1311         float padding;
1312         padding = HUD_Panel_GetPadding(id);
1313         if(padding)
1314         {
1315                 pos += '1 1 0' * padding;
1316                 mySize -= '2 2 0' * padding;
1317         }
1318
1319         // hits
1320         weapon_stats = getstati(STAT_DAMAGE_HITS);
1321         weapon_number = weapon_stats & 63;
1322         weapon_hits[weapon_number-WEP_FIRST] = floor(weapon_stats / 64);
1323         // fired
1324         weapon_stats = getstati(STAT_DAMAGE_FIRED);
1325         weapon_number = weapon_stats & 63;
1326         weapon_fired[weapon_number-WEP_FIRST] = floor(weapon_stats / 64);
1327
1328         if(cvar_or("hud_weaponicons_fade", 1))
1329         {
1330                 fade = 3.2 - 2 * (time - weapontime);
1331                 fade = bound(0.7, fade, 1);
1332         }
1333         else
1334                 fade = 1;
1335
1336         HUD_WeaponIcons_Clear();
1337
1338         float rows, columns;
1339         rows = mySize_y/mySize_x;
1340         rows = bound(1, floor((sqrt(4 * (2/1) * rows * WEP_COUNT + rows * rows) + rows + 0.5) / 2), WEP_COUNT);
1341         //                               ^^^ weapon icon aspect goes here
1342
1343         columns = ceil(WEP_COUNT/rows);
1344         float row, column;
1345         for(i = 0; i < weapon_cnt; ++i)
1346         {
1347                 self = weaponorder[i];
1348                 if((self.weapons && (self.impulse >= 0) && (stat_weapons & self.weapons)) || hud_configure)
1349                 {
1350                         weapid = self.impulse;
1351
1352                         alpha = (self.weapon == activeweapon) ? 1 : 0.6;
1353
1354                         weapon_hit = weapon_hits[self.weapon-WEP_FIRST];
1355                         weapon_damage = weapon_fired[self.weapon-WEP_FIRST];
1356
1357                         // draw background behind currently selected weapon
1358                         if(self.weapon == activeweapon)
1359                                 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_alpha_fg, DRAWFLAG_NORMAL);
1360
1361                         // draw the weapon accuracy on the HUD
1362                         if(hud_accuracy_hud && !(gametype == GAME_RACE || gametype == GAME_CTS))
1363                         {
1364                                 if(weapon_damage)
1365                                         weapon_stats = floor(100 * weapon_hit / weapon_damage);
1366
1367                                 accuracy_color = HUD_AccuracyColor(weapon_stats);
1368                                 if(weapon_damage)
1369                                         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_alpha_fg, DRAWFLAG_NORMAL);
1370                         }
1371
1372                         // draw the weapon icon
1373                         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_alpha_fg, DRAWFLAG_NORMAL);
1374
1375                         if(cvar_or("hud_weaponicons_number", 1))
1376                                 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_alpha_fg, DRAWFLAG_NORMAL);
1377                 }
1378
1379                 ++row;
1380                 if(row >= rows)
1381                 {
1382                         row = 0;
1383                         ++column;
1384                 }
1385         }
1386
1387 }
1388
1389 // Inventory (#1)
1390 //
1391 float GetAmmoStat(float i)
1392 {
1393         switch(i)
1394         {
1395                 case 0: return STAT_SHELLS;
1396                 case 1: return STAT_NAILS;
1397                 case 2: return STAT_ROCKETS;
1398                 case 3: return STAT_CELLS;
1399                 case 4: return STAT_FUEL;
1400                 default: return -1;
1401         }
1402 }
1403
1404 float GetAmmoItemCode(float i)
1405 {
1406         switch(i)
1407         {
1408                 case 0: return IT_SHELLS;
1409                 case 1: return IT_NAILS;
1410                 case 2: return IT_ROCKETS;
1411                 case 3: return IT_CELLS;
1412                 case 4: return IT_FUEL;
1413                 default: return -1;
1414         }
1415 }
1416
1417 string GetAmmoPicture(float i)
1418 {
1419         switch(i)
1420         {
1421                 case 0: return "ammo_shells";
1422                 case 1: return "ammo_bullets";
1423                 case 2: return "ammo_rockets";
1424                 case 3: return "ammo_cells";
1425                 case 4: return "ammo_fuel";
1426                 default: return "";
1427         }
1428 }
1429
1430 void HUD_Inventory()
1431 {
1432         float id = 1;
1433         float i;
1434         float stat_items;
1435
1436         vector pos, mySize, mysize, mypos;
1437         pos = HUD_Panel_GetPos(id);
1438         mySize = HUD_Panel_GetSize(id);
1439
1440         HUD_Panel_DrawBg(id, pos, mySize);
1441         float padding;
1442         padding = HUD_Panel_GetPadding(id);
1443         if(padding)
1444         {
1445                 pos += '1 1 0' * padding;
1446                 mySize -= '2 2 0' * padding;
1447         }
1448
1449         // ammo
1450         stat_items = getstati(STAT_ITEMS);
1451         for (i = 0; i < 4; ++i) {
1452                 float a;
1453                 a = getstati(GetAmmoStat(i)); // how much ammo do we have of type i?
1454                 if(hud_configure)
1455                         a = 100;
1456
1457                 if(cvar("hud_inventory_onlycurrent")) {
1458                         if (stat_items & GetAmmoItemCode(i)) {
1459                                 drawpic_skin(pos, GetAmmoPicture(i), '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1460                                 if(a < 10)
1461                                         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_alpha_fg, DRAWFLAG_NORMAL);
1462                                 else
1463                                         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_alpha_fg, DRAWFLAG_NORMAL);
1464                         }
1465                 } else {
1466                         if (a > 0) {
1467                                 if(mySize_x/mySize_y >= 10) { // arrange horizontally
1468                                         switch (i) {
1469                                                 case 0: mypos_x = pos_x;                        mypos_y = pos_y;                        break; // shells
1470                                                 case 1: mypos_x = pos_x + 0.25 * mySize_x;      mypos_y = pos_y;                        break; // bullets
1471                                                 case 2: mypos_x = pos_x + 0.5  * mySize_x;      mypos_y = pos_y;                        break; // rockets
1472                                                 case 3: mypos_x = pos_x + 0.75 * mySize_x;      mypos_y = pos_y;                        break; // cells
1473                                         }
1474                                         mysize_x = 0.25 * mySize_x;
1475                                         mysize_y = mySize_y;
1476                                 } else if(mySize_x/mySize_y >= 2.5) { // arrange in a 2x2 grid
1477                                         switch (i) {
1478                                                 case 0: mypos_x = pos_x + 0.5 * mySize_x;       mypos_y = pos_y + 0.5 * mySize_y;       break; // shells
1479                                                 case 1: mypos_x = pos_x + 0.5 * mySize_x;       mypos_y = pos_y;                        break; // bullets
1480                                                 case 2: mypos_x = pos_x;                        mypos_y = pos_y + 0.5 * mySize_y;       break; // rockets
1481                                                 case 3: mypos_x = pos_x;                        mypos_y = pos_y;                        break; // cells
1482                                         }
1483                                         mysize_x = 0.5 * mySize_x;
1484                                         mysize_y = 0.5 * mySize_y;
1485                                 } else { // arrange vertically
1486                                         switch (i) {
1487                                                 case 0: mypos_x = pos_x;                        mypos_y = pos_y;                        break; // shells
1488                                                 case 1: mypos_x = pos_x;                        mypos_y = pos_y + 0.25 * mySize_y;      break; // bullets
1489                                                 case 2: mypos_x = pos_x;                        mypos_y = pos_y + 0.5  * mySize_y;      break; // rockets
1490                                                 case 3: mypos_x = pos_x;                        mypos_y = pos_y + 0.75 * mySize_y;      break; // cells
1491                                         }
1492                                         mysize_x = mySize_x;
1493                                         mysize_y = 0.25 * mySize_y;
1494                                 }
1495
1496                                 if (stat_items & GetAmmoItemCode(i))
1497                                         drawpic_skin(mypos, "ammo_current_bg", mysize, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1498                                 drawpic_skin(mypos + eY * 0.05 * mysize_y, GetAmmoPicture(i), '1 1 0' * 0.8 * mysize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1499                                 if (a < 10) {
1500                                         if(stat_items & GetAmmoItemCode(i))
1501                                                 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_alpha_fg, DRAWFLAG_NORMAL);
1502                                         else
1503                                                 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_alpha_fg * 0.7, DRAWFLAG_NORMAL);
1504                                 } else {
1505                                         if(stat_items & GetAmmoItemCode(i))
1506                                                 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_alpha_fg, DRAWFLAG_NORMAL);
1507                                         else
1508                                                 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_alpha_fg * 0.7, DRAWFLAG_NORMAL);
1509                                 }
1510                         }
1511                 }
1512         }
1513 }
1514
1515
1516 // Powerups (#2)
1517 //
1518 void HUD_Powerups() {
1519         float id = 2;
1520         float stat_items;
1521         stat_items = getstati(STAT_ITEMS);
1522
1523         if(!hud_configure)
1524         {
1525                 if not(stat_items & IT_STRENGTH)
1526                         if not(stat_items & IT_INVINCIBLE)
1527                                 return;
1528
1529                 if (getstati(STAT_HEALTH) <= 0)
1530                         return;
1531         }
1532
1533         vector pos, mySize;
1534         pos = HUD_Panel_GetPos(id);
1535         mySize = HUD_Panel_GetSize(id);
1536
1537         HUD_Panel_DrawBg(id, pos, mySize);
1538         float padding;
1539         padding = HUD_Panel_GetPadding(id);
1540         if(padding)
1541         {
1542                 pos += '1 1 0' * padding;
1543                 mySize -= '2 2 0' * padding;
1544         }
1545
1546         float strength_time, shield_time;
1547
1548         strength_time = bound(0, getstatf(STAT_STRENGTH_FINISHED) - time, 99);
1549         shield_time = bound(0, getstatf(STAT_INVINCIBLE_FINISHED) - time, 99);
1550
1551         if(hud_configure)
1552         {
1553                 strength_time = 15;
1554                 shield_time = 27;
1555         }
1556
1557         float len;
1558
1559         vector barpos, barsize;
1560         vector picpos;
1561         vector numpos;
1562
1563         string leftname, rightname;
1564         float leftcnt, rightcnt;
1565         float leftexact, rightexact;
1566         float leftalpha, rightalpha;
1567         if (cvar(strcat("hud_", HUD_Panel_GetName(id), "_flip"))) {
1568                 leftname = "strength";
1569                 leftcnt = ceil(strength_time);
1570                 leftexact = strength_time;
1571
1572                 rightname = "shield";
1573                 rightcnt = ceil(shield_time);
1574                 rightexact = shield_time;
1575         } else {
1576                 leftname = "shield";
1577                 leftcnt = ceil(shield_time);
1578                 leftexact = shield_time;
1579
1580                 rightname = "strength";
1581                 rightcnt = ceil(strength_time);
1582                 rightexact = strength_time;
1583         }
1584         leftalpha = bound(0, leftexact, 1);
1585         rightalpha = bound(0, rightexact, 1);
1586
1587         if (mySize_x/mySize_y > 4)
1588         {
1589                 if(leftcnt)
1590                 {
1591                         len = strlen(ftos(leftcnt));
1592
1593                         if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
1594                                 barpos = pos + eX * 0.5 * mySize_x - eX * 0.5 * mySize_x * min(1, leftcnt/30);
1595                                 barsize = eX * 0.5 * mySize_x * min(1, leftcnt/30) + eY * mySize_y;
1596                                 picpos = pos + eX * 0.5 * mySize_x - eX * mySize_y;
1597                                 numpos = picpos - eX * 2 * 0.5 * mySize_y + eX * (2-len) * 0.5 * mySize_y + eY * 0.25 * mySize_y;
1598                         } else {
1599                                 barpos = pos;
1600                                 barsize = eX * 0.5 * mySize_x * min(1, leftcnt/30) + eY * mySize_y;
1601                                 picpos = pos;
1602                                 numpos = picpos + eX * mySize_y - eX * (2-len) * 0.5 * mySize_y + eY * 0.25 * mySize_y;
1603                         }
1604
1605                         HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1606                         if(leftcnt <= 5)
1607                                 drawpic_skin_expanding_two(picpos, leftname, '1 1 0' * mySize_y, '1 1 1', leftalpha * hud_alpha_fg, DRAWFLAG_ADDITIVE, bound(0, (leftcnt - leftexact) / 0.5, 1));
1608                         else
1609                                 drawpic_skin(picpos, leftname, '1 1 0' * mySize_y, '1 1 1', leftalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1610                         HUD_DrawXNum(numpos, leftcnt, 2, 0, 0.5 * mySize_y, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1611                 }
1612
1613                 if(rightcnt)
1614                 {
1615                         len = strlen(ftos(rightcnt));
1616
1617                         if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
1618                                 barpos = pos + eX * 0.5 * mySize_x;
1619                                 barsize = eX * 0.5 * mySize_x * min(1, rightcnt/30) + eY * mySize_y;
1620                                 picpos = pos + eX * 0.5 * mySize_x;
1621                                 numpos = picpos + eX * mySize_y - eX * (2-len) * 0.5 * mySize_y + eY * 0.25 * mySize_y;
1622                         } else {
1623                                 barpos = pos + eX * mySize_x - eX * 0.5 * mySize_x * min(1, rightcnt/30);
1624                                 barsize = eX * 0.5 * mySize_x * min(1, rightcnt/30) + eY * mySize_y;
1625                                 picpos = pos + eX * mySize_x - eX * mySize_y;
1626                                 numpos = picpos - eX * mySize_y + eY * 0.25 * mySize_y;
1627                         }
1628
1629                         HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1630                         if(rightcnt <= 5)
1631                                 drawpic_skin_expanding_two(picpos, rightname, '1 1 0' * mySize_y, '1 1 1', rightalpha * hud_alpha_fg, DRAWFLAG_ADDITIVE, bound(0, (rightcnt - rightexact) / 0.5, 1));
1632                         else
1633                                 drawpic_skin(picpos, rightname, '1 1 0' * mySize_y, '1 1 1', rightalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1634                         HUD_DrawXNum(numpos, rightcnt, 2, 0, 0.5 * mySize_y, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1635                 }
1636         }
1637         else if (mySize_x/mySize_y > 1.5)
1638         {
1639                 if(leftcnt)
1640                 {
1641                         len = strlen(ftos(leftcnt));
1642
1643                         if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
1644                                 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, leftcnt/30);
1645                                 barsize = eX * mySize_x * min(1, leftcnt/30) + eY * 0.5 * mySize_y;
1646                                 picpos = pos + eX * mySize_x - eX * 0.5 * mySize_y;
1647                                 numpos = picpos - eX * len * 0.5 * mySize_y;
1648                         } else {
1649                                 barpos = pos;
1650                                 barsize = eX * mySize_x * min(1, leftcnt/30) + eY * 0.5 * mySize_y;
1651                                 picpos = pos;
1652                                 numpos = picpos + eX * 0.5 * mySize_y;
1653                         }
1654
1655                         HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1656                         if(leftcnt <= 5)
1657                                 drawpic_skin_expanding_two(picpos, leftname, '0.5 0.5 0' * mySize_y, '1 1 1', leftalpha * hud_alpha_fg, DRAWFLAG_ADDITIVE, bound(0, (leftcnt - leftexact) / 0.5, 1));
1658                         else
1659                                 drawpic_skin(picpos, leftname, '0.5 0.5 0' * mySize_y, '1 1 1', leftalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1660                         HUD_DrawXNum(numpos, leftcnt, len, 0, 0.5 * mySize_y, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1661                 }
1662
1663                 if(rightcnt)
1664                 {
1665                         len = strlen(ftos(rightcnt));
1666
1667                         if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
1668                                 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, rightcnt/30) + eY * 0.5 * mySize_y;
1669                                 barsize = eX * mySize_x * min(1, rightcnt/30) + eY * 0.5 * mySize_y;
1670                                 picpos = pos + eX * mySize_x - eX * 0.5 * mySize_y + eY * 0.5 * mySize_y;
1671                                 numpos = picpos - eX * len * 0.5 * mySize_y;
1672                         } else {
1673                                 barpos = pos + eY * 0.5 * mySize_y;
1674                                 barsize = eX * mySize_x * min(1, rightcnt/30) + eY * 0.5 * mySize_y;
1675                                 picpos = pos + eY * 0.5 * mySize_y;
1676                                 numpos = picpos + eX * 0.5 * mySize_y;
1677                         }
1678
1679                         HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1680                         if(rightcnt <= 5)
1681                                 drawpic_skin_expanding_two(picpos, rightname, '0.5 0.5 0' * mySize_y, '1 1 1', rightalpha * hud_alpha_fg, DRAWFLAG_ADDITIVE, bound(0, (rightcnt - rightexact) / 0.5, 1));
1682                         else
1683                                 drawpic_skin(picpos, rightname, '0.5 0.5 0' * mySize_y, '1 1 1', rightalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1684                         HUD_DrawXNum(numpos, rightcnt, len, 0, 0.5 * mySize_y, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1685                 }
1686         }
1687         else
1688         {
1689                 if(leftcnt)
1690                 {
1691                         len = strlen(ftos(leftcnt));
1692
1693                         if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
1694                                 barpos = pos;
1695                                 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/30);
1696                                 picpos = pos + eX * 0.05 * mySize_x;
1697                                 numpos = pos + eX * ((2-len)/2) * 0.25 * mySize_x + eY * 0.4 * mySize_x;
1698                         } else {
1699                                 barpos = pos + eY * mySize_y - eY * mySize_y * min(1, leftcnt/30);
1700                                 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/30);
1701                                 picpos = pos + eX * 0.05 * mySize_x + eY * mySize_y - eY * 0.65 * mySize_x;
1702                                 numpos = pos + eX * ((2-len)/2) * 0.25 * mySize_x + eY * mySize_y - eY * 0.25 * mySize_x;
1703                         }
1704
1705                         HUD_Panel_DrawProgressBar(barpos, 1, barsize, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1706                         if(leftcnt <= 5)
1707                                 drawpic_skin_expanding_two(picpos, leftname, '0.4 0.4 0' * mySize_x, '1 1 1', leftalpha * hud_alpha_fg, DRAWFLAG_ADDITIVE, bound(0, (leftcnt - leftexact) / 0.5, 1));
1708                         else
1709                                 drawpic_skin(picpos, leftname, '0.4 0.4 0' * mySize_x, '1 1 1', leftalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1710                         HUD_DrawXNum(numpos, leftcnt, len, 0, 0.25 * mySize_x, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1711                 }
1712
1713                 if(rightcnt)
1714                 {
1715                         len = strlen(ftos(rightcnt));
1716
1717                         if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
1718                                 barpos = pos + eX * 0.5 * mySize_x;
1719                                 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, rightcnt/30);
1720                                 picpos = pos + eX * 0.05 * mySize_x + eX * 0.5 * mySize_x;
1721                                 numpos = pos + eX * ((2-len)/2) * 0.25 * mySize_x + eY * 0.4 * mySize_x + eX * 0.5 * mySize_x;
1722                         } else {
1723                                 barpos = pos + eY * mySize_y - eY * mySize_y * min(1, rightcnt/30) + eX * 0.5 * mySize_x;
1724                                 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, rightcnt/30);
1725                                 picpos = pos + eX * 0.05 * mySize_x + eY * mySize_y - eY * 0.65 * mySize_x + eX * 0.5 * mySize_x;
1726                                 numpos = pos + eX * ((2-len)/2) * 0.25 * mySize_x + eY * mySize_y - eY * 0.25 * mySize_x + eX * 0.5 * mySize_x;
1727                         }
1728
1729                         HUD_Panel_DrawProgressBar(barpos, 1, barsize, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1730                         if(rightcnt <= 5)
1731                                 drawpic_skin_expanding_two(picpos, rightname, '0.4 0.4 0' * mySize_x, '1 1 1', rightalpha * hud_alpha_fg, DRAWFLAG_ADDITIVE, bound(0, (rightcnt - rightexact) / 0.5, 1));
1732                         else
1733                                 drawpic_skin(picpos, rightname, '0.4 0.4 0' * mySize_x, '1 1 1', rightalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1734                         HUD_DrawXNum(numpos, rightcnt, len, 0, 0.25 * mySize_x, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1735                 }
1736         }
1737 }
1738
1739 // Health/armor (#3)
1740 //
1741 void HUD_HealthArmor(void)
1742 {
1743         float id = 3;
1744         vector pos, mySize;
1745         pos = HUD_Panel_GetPos(id);
1746         mySize = HUD_Panel_GetSize(id);
1747
1748         HUD_Panel_DrawBg(id, pos, mySize);
1749         float padding;
1750         padding = HUD_Panel_GetPadding(id);
1751         if(padding)
1752         {
1753                 pos += '1 1 0' * padding;
1754                 mySize -= '2 2 0' * padding;
1755         }
1756
1757         float armor, health;
1758         armor = getstati(STAT_ARMOR);
1759         health = getstati(STAT_HEALTH);
1760
1761         float fuel;
1762         fuel = getstati(GetAmmoStat(4)); // how much fuel do we have?
1763
1764         if(hud_configure)
1765         {
1766                 armor = 150;
1767                 health = 100;
1768                 fuel = 70;
1769         }
1770
1771         if(health <= 0)
1772                 return;
1773
1774         float len;
1775
1776         if(cvar("hud_healtharmor") == 2) // combined health and armor display
1777         {
1778                 vector v;
1779                 v = healtharmor_maxdamage(health, armor, armorblockpercent);
1780
1781                 float x;
1782                 x = floor(v_x + 1);
1783
1784                 if(v_z) // NOT fully armored
1785                 {
1786                         drawpic_skin(pos + eX * 3 * mySize_y, "health", '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1787                         if(armor)
1788                                 drawpic_skin(pos + eX * 4 * mySize_y, "armor", '0.5 0.5 0' * mySize_y, '1 1 1', hud_alpha_fg * armor / health, DRAWFLAG_NORMAL);
1789                 }
1790                 else
1791                 {
1792                         drawpic_skin(pos + eX * 4 * mySize_y, "health", '0.5 0.5 0' * mySize_y, '1 1 1', hud_alpha_fg * health / armor, DRAWFLAG_NORMAL);
1793                         if(armor)
1794                                 drawpic_skin(pos + eX * 3 * mySize_y, "armor", '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1795                 }
1796                 HUD_DrawXNum_Colored(pos, x, 3, mySize_y, hud_alpha_fg); // draw the combined health and armor
1797         }
1798
1799         else
1800         {
1801                 vector barpos, barsize;
1802                 vector picpos;
1803                 vector numpos;
1804
1805                 string leftname, rightname;
1806                 float leftcnt, rightcnt;
1807                 float leftactive, rightactive;
1808                 float leftalpha, rightalpha;
1809                 if (cvar(strcat("hud_", HUD_Panel_GetName(id), "_flip"))) { // old style layout with armor left/top of health
1810                         leftname = "armor";
1811                         leftcnt = armor;
1812                         if(leftcnt)
1813                                 leftactive = 1;
1814                         leftalpha = min((armor+10)/55, 1);
1815
1816                         rightname = "health";
1817                         rightcnt = health;
1818                         rightactive = 1;
1819                         rightalpha = 1;
1820                 } else {
1821                         leftname = "health";
1822                         leftcnt = health;
1823                         leftactive = 1;
1824                         leftalpha = 1;
1825
1826                         rightname = "armor";
1827                         rightcnt = armor;
1828                         if(rightcnt)
1829                                 rightactive = 1;
1830                         rightalpha = min((armor+10)/55, 1);
1831                 }
1832
1833                 if (mySize_x/mySize_y > 5)
1834                 {
1835                         if(leftactive)
1836                         {
1837                                 len = strlen(ftos(leftcnt));
1838
1839                                 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
1840                                         barpos = pos + eX * 0.5 * mySize_x - eX * 0.5 * mySize_x * min(1, leftcnt/200);
1841                                         barsize = eX * 0.5 * mySize_x * min(1, leftcnt/200) + eY * mySize_y;
1842                                         picpos = pos + eX * 0.5 * mySize_x - eX * mySize_y;
1843                                         numpos = picpos - eX * 3 * 0.5 * mySize_y + eX * (3-len) * 0.5 * mySize_y + eY * 0.25 * mySize_y;
1844                                 } else {
1845                                         barpos = pos;
1846                                         barsize = eX * 0.5 * mySize_x * min(1, leftcnt/200) + eY * mySize_y;
1847                                         picpos = pos;
1848                                         numpos = picpos + eX * mySize_y + eY * 0.25 * mySize_y;
1849                                 }
1850
1851                                 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1852                                 drawpic_skin(picpos, leftname, '1 1 0' * mySize_y, '1 1 1', leftalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1853                                 HUD_DrawXNum_Colored(numpos, leftcnt, len, 0.5 * mySize_y, hud_alpha_fg);
1854                         }
1855
1856                         if(rightactive)
1857                         {
1858                                 len = strlen(ftos(rightcnt));
1859
1860                                 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
1861                                         barpos = pos + eX * 0.5 * mySize_x;
1862                                         barsize = eX * 0.5 * mySize_x * min(1, rightcnt/200) + eY * mySize_y;
1863                                         picpos = pos + eX * 0.5 * mySize_x;
1864                                         numpos = picpos + eX * mySize_y - eX * (3-len) * 0.5 * mySize_y + eY * 0.25 * mySize_y;
1865                                 } else {
1866                                         barpos = pos + eX * mySize_x - eX * 0.5 * mySize_x * min(1, rightcnt/200);
1867                                         barsize = eX * 0.5 * mySize_x * min(1, rightcnt/200) + eY * mySize_y;
1868                                         picpos = pos + eX * mySize_x - eX * mySize_y;
1869                                         numpos = picpos - eX * 1.5 * mySize_y + eY * 0.25 * mySize_y;
1870                                 }
1871
1872                                 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1873                                 drawpic_skin(picpos, rightname, '1 1 0' * mySize_y, '1 1 1', rightalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1874                                 HUD_DrawXNum_Colored(numpos, rightcnt, 3, 0.5 * mySize_y, hud_alpha_fg);
1875                         }
1876
1877                         if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
1878                                 barpos = pos - eX * mySize_x * min(1, fuel/100);
1879                                 barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.2 * mySize_y;
1880                         } else {
1881                                 barpos = pos;
1882                                 barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.2 * mySize_y;
1883                         }
1884                         if(fuel)
1885                                 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor("fuel"), hud_alpha_fg * 0.8, DRAWFLAG_NORMAL);
1886                 }
1887                 else if (mySize_x/mySize_y > 2)
1888                 {
1889                         if(leftactive)
1890                         {
1891                                 len = strlen(ftos(leftcnt));
1892
1893                                 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
1894                                         barpos = pos + eX * mySize_x - eX * mySize_x * min(1, leftcnt/200);
1895                                         barsize = eX * mySize_x * min(1, leftcnt/200) + eY * 0.5 * mySize_y;
1896                                         picpos = pos + eX * mySize_x - eX * 0.5 * mySize_y;
1897                                         numpos = picpos - eX * len * 0.5 * mySize_y;
1898                                 } else {
1899                                         barpos = pos;
1900                                         barsize = eX * mySize_x * min(1, leftcnt/200) + eY * 0.5 * mySize_y;
1901                                         picpos = pos;
1902                                         numpos = picpos + eX * 0.5 * mySize_y;
1903                                 }
1904
1905                                 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1906                                 drawpic_skin(picpos, leftname, '0.5 0.5 0' * mySize_y, '1 1 1', leftalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1907                                 HUD_DrawXNum_Colored(numpos, leftcnt, len, 0.5 * mySize_y, hud_alpha_fg);
1908                         }
1909
1910                         if(rightactive)
1911                         {
1912                                 len = strlen(ftos(rightcnt));
1913
1914                                 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
1915                                         barpos = pos + eX * mySize_x - eX * mySize_x * min(1, rightcnt/200) + eY * 0.5 * mySize_y;
1916                                         barsize = eX * mySize_x * min(1, rightcnt/200) + eY * 0.5 * mySize_y;
1917                                         picpos = pos + eX * mySize_x - eX * 0.5 * mySize_y + eY * 0.5 * mySize_y;
1918                                         numpos = picpos - eX * len * 0.5 * mySize_y;
1919                                 } else {
1920                                         barpos = pos + eY * 0.5 * mySize_y;
1921                                         barsize = eX * mySize_x * min(1, rightcnt/200) + eY * 0.5 * mySize_y;
1922                                         picpos = pos + eY * 0.5 * mySize_y;
1923                                         numpos = picpos + eX * 0.5 * mySize_y;
1924                                 }
1925
1926                                 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1927                                 drawpic_skin(picpos, rightname, '0.5 0.5 0' * mySize_y, '1 1 1', rightalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1928                                 HUD_DrawXNum_Colored(numpos, rightcnt, len, 0.5 * mySize_y, hud_alpha_fg);
1929                         }
1930
1931                         if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
1932                                 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, fuel/100);
1933                                 barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.1 * mySize_y;
1934                         } else {
1935                                 barpos = pos;
1936                                 barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.1 * mySize_y;
1937                         }
1938                         if(fuel)
1939                                 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor("fuel"), hud_alpha_fg * 0.8, DRAWFLAG_NORMAL);
1940                 }
1941                 else
1942                 {
1943                         if(leftactive)
1944                         {
1945                                 len = strlen(ftos(leftcnt));
1946
1947                                 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
1948                                         barpos = pos;
1949                                         barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/200);
1950                                         picpos = pos + eX * 0.05 * mySize_x;
1951                                         numpos = pos + eX * ((3-len)/2) * 0.25 * mySize_x + eY * 0.4 * mySize_x;
1952                                 } else {
1953                                         barpos = pos + eY * mySize_y - eY * mySize_y * min(1, leftcnt/200);
1954                                         barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/200);
1955                                         picpos = pos + eX * 0.05 * mySize_x + eY * mySize_y - eY * 0.566 * mySize_x;
1956                                         numpos = pos + eX * ((3-len)/2) * 0.25 * mySize_x + eY * mySize_y - eY * 0.166 * mySize_x;
1957                                 }
1958
1959                                 HUD_Panel_DrawProgressBar(barpos, 1, barsize, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1960                                 drawpic_skin(picpos, leftname, '0.4 0.4 0' * mySize_x, '1 1 1', leftalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1961                                 HUD_DrawXNum_Colored(numpos, leftcnt, len, 0.166 * mySize_x, hud_alpha_fg);
1962                         }
1963
1964                         if(rightactive)
1965                         {
1966                                 len = strlen(ftos(rightcnt));
1967
1968                                 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
1969                                         barpos = pos + eX * 0.5 * mySize_x;
1970                                         barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, rightcnt/200);
1971                                         picpos = pos + eX * 0.05 * mySize_x + eX * 0.5 * mySize_x;
1972                                         numpos = pos + eX * ((3-len)/2) * 0.25 * mySize_x + eY * 0.4 * mySize_x + eX * 0.5 * mySize_x;
1973                                 } else {
1974                                         barpos = pos + eY * mySize_y - eY * mySize_y * min(1, rightcnt/200) + eX * 0.5 * mySize_x;
1975                                         barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, rightcnt/200);
1976                                         picpos = pos + eX * 0.05 * mySize_x + eY * mySize_y - eY * 0.566 * mySize_x + eX * 0.5 * mySize_x;
1977                                         numpos = pos + eX * ((3-len)/2) * 0.25 * mySize_x + eY * mySize_y - eY * 0.166 * mySize_x + eX * 0.5 * mySize_x;
1978                                 }
1979
1980                                 HUD_Panel_DrawProgressBar(barpos, 1, barsize, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1981                                 drawpic_skin(picpos, rightname, '0.4 0.4 0' * mySize_x, '1 1 1', rightalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1982                                 HUD_DrawXNum_Colored(numpos, rightcnt, len, 0.166 * mySize_x, hud_alpha_fg);
1983                         }
1984
1985                         if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
1986                                 barpos = pos;
1987                                 barsize = eX * 0.05 * mySize_x + eY * mySize_y * min(1, fuel/100);
1988                         } else {
1989                                 barpos = pos + eY * mySize_y - eY * mySize_y * min(1, fuel/100);
1990                                 barsize = eX * 0.05 * mySize_x + eY * mySize_y * min(1, fuel/100);
1991                         }
1992                         if(fuel)
1993                                 HUD_Panel_DrawProgressBar(barpos, 1, barsize, HUD_Panel_GetProgressBarColor("fuel"), hud_alpha_fg * 0.8, DRAWFLAG_NORMAL);
1994                 }
1995         }
1996 }
1997
1998 // ___TODO___ !!!
1999 // Notification area (#4)
2000 //
2001
2002 string Weapon_SuicideMessage(float deathtype)
2003 {
2004         float w;
2005         w = DEATH_WEAPONOF(deathtype);
2006
2007         switch (w)
2008         {
2009                 case 1:
2010                         return "lasered himself to hell";
2011                 case 2:
2012                         return "did the impossible";
2013                 case 3:
2014                         return "did the impossible";
2015                 case 4:
2016                         if(deathtype & HITTYPE_SECONDARY)
2017                                 return "tried out his own grenade";
2018                         return "detonated";
2019         }
2020         // TODO: was blasted by?
2021         return strcat("[no kill message for weapon ", ftos(w), "!]");
2022 }
2023
2024 string Weapon_KillMessage(float deathtype)
2025 {
2026         float w;
2027         w = DEATH_WEAPONOF(deathtype);
2028
2029         switch (w)
2030         {
2031                 case 1:
2032                         return "was lasered to death by";
2033                 case 2:
2034                         return "was gunned by";
2035                 case 3:
2036                         if(deathtype & HITTYPE_SECONDARY)
2037                                 return "was sniped by";
2038                         return "was riddled full of holes by";
2039                 case 4:
2040                         if(deathtype & HITTYPE_BOUNCE)
2041                                 return "didn't see #'s grenade";
2042                         return "almost dodged #'s grenade";
2043         }
2044         return strcat("[no suicide message for weapon ", ftos(w), "!]");
2045 }
2046
2047 float killnotify_times[10];
2048 float killnotify_deathtype[10];
2049 string killnotify_attackers[10];
2050 string killnotify_victims[10];
2051 void HUD_KillNotify_Push(string attacker, string victim, float wpn)
2052 {
2053         float i;
2054         for (i = 9; i > 0; --i) {
2055                 killnotify_times[i] = killnotify_times[i-1];
2056                 killnotify_deathtype[i] = killnotify_deathtype[i-1];
2057                 if(killnotify_attackers[i])
2058                         strunzone(killnotify_attackers[i]);
2059                 killnotify_attackers[i] = strzone(killnotify_attackers[i-1]);
2060                 if(killnotify_victims[i])
2061                         strunzone(killnotify_victims[i]);
2062                 killnotify_victims[i] = strzone(killnotify_victims[i-1]);
2063         }
2064         killnotify_times[0] = time;
2065         killnotify_deathtype[0] = wpn;
2066         if(killnotify_attackers[0])
2067                 strunzone(killnotify_attackers[0]);
2068         killnotify_attackers[0] = strzone(attacker);
2069         if(killnotify_victims[0])
2070                 strunzone(killnotify_victims[0]);
2071         killnotify_victims[0] = strzone(victim);
2072 }
2073
2074 void HUD_KillNotify(string s1, string s2, string s3, float type, float msg)
2075 {
2076         float w;
2077         if(msg == MSG_SUICIDE) {
2078                 HUD_KillNotify_Push(s1, "", DEATH_KILL);
2079
2080                 // TODO: cl_gentle
2081                 w = DEATH_WEAPONOF(type);
2082                 if(WEP_VALID(w)) {
2083                         if (!HUD_Panel_CheckActive(4) || cvar("hud_notify_print"))
2084                                 print("^1", s1, "^1 ", Weapon_SuicideMessage(type), "\n");
2085                 }
2086                 else if (type == DEATH_KILL)
2087                         print ("^1",s1, "^1 couldn't take it anymore\n");
2088                 else if (type == DEATH_ROT)
2089                         print ("^1",s1, "^1 died\n");
2090                 else if (type == DEATH_NOAMMO)
2091                         print ("^7",s1, "^7 committed suicide. What's the point of living without ammo?\n");
2092                 else if (type == DEATH_CAMP)
2093                         print ("^1",s1, "^1 thought they found a nice camping ground\n");
2094                 else if (type == DEATH_MIRRORDAMAGE)
2095                         print ("^1",s1, "^1 didn't become friends with the Lord of Teamplay\n");
2096                 else if (type == DEATH_CHEAT)
2097                         print ("^1",s1, "^1 unfairly eliminated themself\n");
2098                 else if (type == DEATH_FIRE)
2099                         print ("^1",s1, "^1 burned to death\n");
2100                 else if (type != DEATH_TEAMCHANGE && type != DEATH_QUIET)
2101                         print ("^1",s1, "^1 couldn't resist the urge to self-destruct\n");
2102                 if (stof(s2) > 2) // killcount > 2
2103                         print ("^1",s1,"^1 ended it all after a ",s2," kill spree\n");
2104         } else if(msg == MSG_KILL) {
2105                 w = DEATH_WEAPONOF(type);
2106                 if(WEP_VALID(w)) {
2107                         HUD_KillNotify_Push(s2, s1, w);
2108                         if (!HUD_Panel_CheckActive(4) || cvar("hud_notify_print"))
2109                                 print("^1", s1, "^1 ", Weapon_KillMessage(type), "\n");
2110                 }
2111                 else if(type == KILL_TEAM || type == KILL_TEAM_SPREE) {
2112                                 if(cvar("cl_gentle")) {
2113                                         print ("^1", s1, "^1 took action against a team mate\n");
2114                                 } else {
2115                                         print ("^1", s1, "^1 mows down a team mate\n");
2116                                 }
2117                                 if (stof(s2) > 2 && type == KILL_TEAM_SPREE) {
2118                                         if(cvar("cl_gentle"))
2119                                                 print ("^1",s1,"^1 ended a ",s2," scoring spree by going against a team mate\n");
2120                                         else
2121                                                 print ("^1",s1,"^1 ended a ",s2," kill spree by killing a team mate\n");
2122                                 }
2123                                 else if (stof(s2) > 2) {
2124                                         if(cvar("cl_gentle"))
2125                                                 print ("^1",s1,"'s ^1",s2," scoring spree was ended by a team mate!\n");
2126                                         else
2127                                                 print ("^1",s1,"'s ^1",s2," kill spree was ended by a team mate!\n");
2128                                 }
2129                 }
2130                 else if(type == KILL_FIRST_BLOOD)
2131                         print("^1",s1, "^1 drew first blood", "\n");
2132                 else if (type == DEATH_TELEFRAG)
2133                         print ("^1",s1, "^1 was telefragged by ", s2, "\n");
2134                 else if (type == DEATH_DROWN) {
2135                         HUD_KillNotify_Push(s2, s1, DEATH_FALL);
2136                         print ("^1",s1, "^1 was drowned by ", s2, "\n");
2137                 }
2138                 else if (type == DEATH_SLIME) {
2139                         HUD_KillNotify_Push(s2, s1, DEATH_FALL);
2140                         print ("^1",s1, "^1 was slimed by ", s2, "\n");
2141                 }
2142                 else if (type == DEATH_LAVA) {
2143                         HUD_KillNotify_Push(s2, s1, DEATH_FALL);
2144                         print ("^1",s1, "^1 was cooked by ", s2, "\n");
2145                 }
2146                 else if (type == DEATH_FALL) {
2147                         HUD_KillNotify_Push(s2, s1, DEATH_FALL);
2148                         print ("^1",s1, "^1 was grounded by ", s2, "\n");
2149                 }
2150                 else if (type == DEATH_SHOOTING_STAR) {
2151                         HUD_KillNotify_Push(s2, s1, DEATH_FALL);
2152                         print ("^1",s1, "^1 was shot into space by ", s2, "\n");
2153                 }
2154                 else if (type == DEATH_SWAMP) {
2155                         HUD_KillNotify_Push(s2, s1, DEATH_FALL);
2156                         print ("^1",s1, "^1 was conserved by ", s2, "\n");
2157                 }
2158                 else if (type == DEATH_HURTTRIGGER && s3 != "")
2159                 {
2160                         HUD_KillNotify_Push(s2, s1, DEATH_FALL);
2161                         // p ?!?! :o
2162                         //if(p < 0)
2163                                 print("^1", s1, "^1 ", s3, " ", s2, "\n");
2164                         //else
2165                         //      bprint("^1", s1, "^1 ", substring(s3, 0, p), s2, "^1", substring(s3, p+1, strlen(s3) - (p+1)), "\n");
2166                 }
2167                 else if(type == DEATH_SBCRUSH)
2168                         print ("^1",s1, "^1 was crushed by ^1", s2, "\n");
2169                 else if(type == DEATH_SBMINIGUN)
2170                         print ("^1",s1, "^1 got shredded by ^1", s2, "\n");
2171                 else if(type == DEATH_SBROCKET)
2172                         print ("^1",s1, "^1 was blased to bits by ^1", s2, "\n");
2173                 else if(type == DEATH_SBBLOWUP)
2174                         print ("^1",s1, "^1 got cought in the destruction of ^1", s2, "'s vehicle\n");
2175
2176                 else if(type == DEATH_WAKIGUN)
2177                         print ("^1",s1, "^1 was bolted down by ^1", s2, "\n");
2178                 else if(type == DEATH_WAKIROCKET)
2179                         print ("^1",s1, "^1 could find no shelter from ^1", s2, "'s rockets\n");
2180                 else if(type == DEATH_WAKIBLOWUP)
2181                         print ("^1",s1, "^1 dies when ^1", s2, "'s wakizashi dies.\n");
2182
2183                 else if(type == DEATH_TURRET)
2184                         print ("^1",s1, "^1 was pushed into the line of fire by ^1", s2, "\n");
2185                 else if(type == DEATH_TOUCHEXPLODE)
2186                         print ("^1",s1, "^1 was pushed into an accident by ^1", s2, "\n");
2187                 else if(type == DEATH_CHEAT)
2188                         print ("^1",s1, "^1 was unfairly eliminated by ^1", s2, "\n");
2189                 else if (type == DEATH_FIRE)
2190                         print ("^1",s1, "^1 was burnt to death by ^1", s2, "\n");
2191                 else if (type == DEATH_CUSTOM)
2192                         print ("^1",s1, "^1 ", s2, "\n");
2193                 else
2194                         print ("^1",s1, "^1 was fragged by ", s2, "\n");
2195         } else if(msg == MSG_SPREE) {
2196                 if(type == KILL_END_SPREE) {
2197                         if(cvar("cl_gentle"))
2198                                 print ("^1",s1,"'s ^1", s2, " scoring spree was ended by ", s3, "\n");
2199                         else
2200                                 print ("^1",s1,"'s ^1", s2, " kill spree was ended by ", s3, "\n");
2201                 } else if(type == KILL_SPREE) {
2202                         if(cvar("cl_gentle"))
2203                                 print ("^1",s1,"^1 made ",s2," scores in a row\n");
2204                         else
2205                                 print ("^1",s1,"^1 has ",s2," frags in a row\n");
2206                 } else if(type == KILL_SPREE_3) {
2207                         if(cvar("cl_gentle"))
2208                                 print (s1,"^7 made a ^1TRIPLE SCORE\n");
2209                         else
2210                                 print (s1,"^7 made a ^1TRIPLE FRAG\n");
2211                 } else if(type == KILL_SPREE_5) {
2212                         if(cvar("cl_gentle"))
2213                                 print (s1,"^7 unleashes ^1SCORING RAGE\n");
2214                         else
2215                                 print (s1,"^7 unleashes ^1RAGE\n");
2216                 } else if(type == KILL_SPREE_10) {
2217                         if(cvar("cl_gentle"))
2218                                 print (s1,"^7 made ^1TEN SCORES IN A ROW!\n");
2219                         else
2220                                 print (s1,"^7 starts the ^1MASSACRE!\n");
2221                 } else if(type == KILL_SPREE_15) {
2222                         if(cvar("cl_gentle"))
2223                                 print (s1,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
2224                         else
2225                                 print (s1,"^7 executes ^1MAYHEM!\n");
2226                 } else if(type == KILL_SPREE_20) {
2227                         if(cvar("cl_gentle"))
2228                                 print (s1,"^7 made ^1TWENTY SCORES IN A ROW!\n");
2229                         else
2230                                 print (s1,"^7 is a ^1BERSERKER!\n");
2231                 } else if(type == KILL_SPREE_25) {
2232                         if(cvar("cl_gentle"))
2233                                 print (s1,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
2234                         else
2235                                 print (s1,"^7 inflicts ^1CARNAGE!\n");
2236                 } else if(type == KILL_SPREE_30) {
2237                         if(cvar("cl_gentle"))
2238                                 print (s1,"^7 made ^1THIRTY SCORES IN A ROW!\n");
2239                         else
2240                                 print (s1,"^7 unleashes ^1ARMAGEDDON!\n");
2241                 }
2242         } else if(msg == MSG_KILL_ACTION) { // wtf is this? isnt it basically the same as MSG_SUICIDE?
2243                 HUD_KillNotify_Push(s1, "", DEATH_KILL);
2244                 if (type == DEATH_DROWN) {
2245                         if(cvar("cl_gentle"))
2246                                 print ("^1",s1, "^1 was in the water for too long\n");
2247                         else
2248                                 print ("^1",s1, "^1 drowned\n");
2249                 }
2250                 else if (type == DEATH_SLIME)
2251                         print ("^1",s1, "^1 was slimed\n");
2252                 else if (type == DEATH_LAVA) {
2253                         if(cvar("cl_gentle"))
2254                                 print ("^1",s1, "^1 found a hot place\n");
2255                         else
2256                                 print ("^1",s1, "^1 turned into hot slag\n");
2257                 }
2258                 else if (type == DEATH_FALL) {
2259                         if(cvar("cl_gentle"))
2260                                 print ("^1",s1, "^1 tested gravity (and it worked)\n");
2261                         else
2262                                 print ("^1",s1, "^1 hit the ground with a crunch\n");
2263                 }
2264                 else if (type == DEATH_SHOOTING_STAR)
2265                         print ("^1",s1, "^1 became a shooting star\n");
2266                 else if (type == DEATH_SWAMP) {
2267                         if(cvar("cl_gentle"))
2268                                 print ("^1",s1, "^1 discovered a swamp\n");
2269                         else
2270                                 print ("^1",s1, "^1 is now conserved for centuries to come\n");
2271                 }
2272                 else if(type == DEATH_TURRET)
2273                         print ("^1",s1, "^1 was mowed down by a turret \n");
2274                 else if (type == DEATH_CUSTOM)
2275                         print ("^1",s1, "^1 ", s2, "\n");
2276                 else if(type == DEATH_TOUCHEXPLODE)
2277                         print ("^1",s1, "^1 died in an accident\n");
2278                 else if(type == DEATH_CHEAT)
2279                         print ("^1",s1, "^1 was unfairly eliminated\n");
2280                 else if(type == DEATH_FIRE) {
2281                         if(cvar("cl_gentle"))
2282                                 print ("^1",s1, "^1 felt a little hot\n");
2283                         else
2284                                 print ("^1",s1, "^1 burnt to death\n");
2285                 }
2286                 else {
2287                         if(cvar("cl_gentle"))
2288                                 print ("^1",s1, "^1 needs a restart\n");
2289                         else
2290                                 print ("^1",s1, "^1 died\n");
2291         }
2292         } else if(msg == MSG_KILL_ACTION_SPREE) {
2293                 HUD_KillNotify_Push(s1, "", DEATH_KILL);
2294                 if(cvar("cl_gentle"))
2295                         print ("^1",s1,"^1 needs a restart after a ",s2," scoring spree\n");
2296                 else
2297                         print ("^1",s1,"^1 died with a ",s2," kill spree\n");
2298         }
2299 }
2300
2301 #define DAMAGE_CENTERPRINT_SPACER NEWLINES
2302
2303 void HUD_Centerprint(string s1, float type, float msg)
2304 {
2305         if(msg == MSG_SUICIDE) {
2306                 if (type == DEATH_TEAMCHANGE) {
2307                         centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "You are now on: ", s1));
2308                 } else if (type == DEATH_AUTOTEAMCHANGE) {
2309                         centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "You have been moved into a different team to improve team balance\nYou are now on: ", s1));
2310                 } else if (type == DEATH_CAMP) {
2311                         if(cvar("cl_gentle"))
2312                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Reconsider your tactics, camper!"));
2313                         else
2314                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Die camper!"));
2315                 } else if (type == DEATH_NOAMMO) {
2316                         if(cvar("cl_gentle"))
2317                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You are reinserted into the game for running out of ammo..."));
2318                         else
2319                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were killed for running out of ammo..."));
2320                 } else if (type == DEATH_ROT) {
2321                         if(cvar("cl_gentle"))
2322                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to preserve your health"));
2323                         else
2324                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You grew too old without taking your medicine"));
2325                 } else if (type == DEATH_MIRRORDAMAGE) {
2326                         if(cvar("cl_gentle"))
2327                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't go against team mates!"));
2328                         else
2329                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't shoot your team mates!"));
2330                 } else if (type == DEATH_QUIET) {
2331                         // do nothing
2332                 } else if (type == DEATH_KILL) {
2333                         if(cvar("cl_gentle"))
2334                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to be more careful!"));
2335                         else
2336                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You killed your own dumb self!"));
2337                 }
2338         } else if(msg == MSG_KILL) {
2339                 if (type == KILL_TEAM) {
2340                         if(cvar("cl_gentle")) {
2341                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You went against a team mate!"));
2342                         } else {
2343                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You fragged ", s1, ", a team mate!"));
2344                         }
2345                 } else if (type == KILL_FIRST_BLOOD) {
2346                         if(cvar("cl_gentle")) {
2347                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First score"));
2348                         } else {
2349                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First blood"));
2350                         }
2351                 } else if (type == KILL_FIRST_VICTIM) {
2352                         if(cvar("cl_gentle")) {
2353                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First casualty"));
2354                         } else {
2355                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First victim"));
2356                         }
2357                 } else if (type == KILL_TYPEFRAG) {
2358                         if(cvar("cl_gentle")) {
2359                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You scored against ^7", s1, "^7 who was typing!"));
2360                         } else {
2361                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You typefragged ^7", s1));
2362                         }
2363                 } else if (type == KILL_TYPEFRAGGED) {
2364                         if(cvar("cl_gentle")) {
2365                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were scored against by ^7", s1, "^7 while you were typing!"));
2366                         } else {
2367                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were typefragged by ^7", s1));
2368                         }
2369                 } else if (type == KILL_FRAG) {
2370                         if(cvar("cl_gentle")) {
2371                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^4You scored against ^7", s1));
2372                         } else {
2373                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^4You fragged ^7", s1));
2374                         }
2375                 } else if (type == KILL_FRAGGED) {
2376                         if(cvar("cl_gentle")) {
2377                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^4You were scored against by ^7", s1));
2378                         } else {
2379                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^4You were fragged by ^7", s1));
2380                         }
2381                 }
2382         } else if(msg == MSG_KILL_ACTION) {
2383                 // TODO: invent more centerprints here?
2384                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Watch your step!", s1));
2385         }
2386 }
2387
2388 void HUD_Notify (void)
2389 {
2390         float id = 4;
2391         vector pos, mySize;
2392         pos = HUD_Panel_GetPos(id);
2393         mySize = HUD_Panel_GetSize(id);
2394
2395         HUD_Panel_DrawBg(id, pos, mySize);
2396         float padding;
2397         padding = HUD_Panel_GetPadding(id);
2398         if(padding)
2399         {
2400                 pos += '1 1 0' * padding;
2401                 mySize -= '2 2 0' * padding;
2402         }
2403
2404         float entries, height;
2405         entries = 8 * mySize_y/mySize_x;
2406         height = mySize_y/entries;
2407         
2408         vector fontsize;
2409         fontsize = '0.33 0.33 0' * height;
2410
2411         float a;
2412         float when;
2413         when = 5;
2414         float fadetime;
2415         fadetime = 2;
2416
2417         float i;
2418         for(i = 0; i <= entries; ++i)
2419         {
2420                 a = bound(0, when + (fadetime - (time - killnotify_times[i]))/fadetime, 1);
2421                 drawcolorcodedstring(pos + eY * 0.33 * height + eY * i * height, textShortenToWidth(killnotify_attackers[i], 0.5 * mySize_x - height, fontsize, stringwidth_colors), fontsize, hud_alpha_fg * a, DRAWFLAG_NORMAL);
2422                 drawcolorcodedstring(pos + eY * 0.33 * height + eX * 0.5 * mySize_x + eX * height + eY * i * height, textShortenToWidth(killnotify_victims[i], 0.5 * mySize_x - height, fontsize, stringwidth_colors), fontsize, hud_alpha_fg * a, DRAWFLAG_NORMAL);
2423                 
2424                 if(WEP_VALID(killnotify_deathtype[i]))
2425                 {
2426                         self = get_weaponinfo(killnotify_deathtype[i]);
2427                         drawpic_skin(pos + eX * 0.5 * mySize_x - eX * (mySize_y/entries) + eY * i * (mySize_y/entries), strcat("weapon", self.netname), '2 1 0' * (mySize_y/entries), '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2428                 }
2429                 else if(killnotify_deathtype[i] == DEATH_KILL)
2430                 {
2431                         drawpic_skin(pos + eX * 0.5 * mySize_x - eX * (mySize_y/entries) + eY * i * (mySize_y/entries), "notify_selfkill", '2 1 0' * (mySize_y/entries), '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);   
2432                 }
2433                 else if(killnotify_deathtype[i] == DEATH_FALL)
2434                 {
2435                         drawpic_skin(pos + eX * 0.5 * mySize_x - eX * (mySize_y/entries) + eY * i * (mySize_y/entries), "notify_pushoffedge", '2 1 0' * (mySize_y/entries), '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);        
2436                 }
2437         }
2438         /* This will come later.
2439         string s;
2440         entity tm;
2441         if(spectatee_status && !intermission)
2442         {
2443                 drawfont = hud_bigfont;
2444                 if(spectatee_status == -1)
2445                         s = "^1Observing";
2446                 else
2447                         s = GetPlayerName(spectatee_status - 1);
2448                 // spectated player name between HUD and chat area, aligned to the left
2449                 pos_x = 0;
2450                 pos_y = - 50 - hud_fontsize_spec_y;
2451                 s = textShortenToWidth(s, vid_conwidth/2.5, hud_fontsize_spec, stringwidth_colors);
2452                 drawcolorcodedstring(pos, s, hud_fontsize_spec, hud_alpha_fg, DRAWFLAG_NORMAL);
2453                 drawfont = hud_font;
2454
2455                 // spectator text in the upper right corner
2456                 if(spectatee_status == -1)
2457                         s = strcat("^1Press ^3", getcommandkey("primary fire", "+attack"), "^1 to spectate");
2458                 else
2459                         s = strcat("^1Press ^3", getcommandkey("primary fire", "+attack"), "^1 for another player");
2460
2461                 if(spectatee_status == -1)
2462                         s = strcat("^1Use ^3", getcommandkey("next weapon", "weapnext"), "^1 or ^3", getcommandkey("previous weapon", "weapprev"), "^1 to change the speed");
2463                 else
2464                         s = strcat("^1Press ^3", getcommandkey("secondary fire", "+attack2"), "^1 to observe");
2465
2466                 s = strcat("^1Press ^3", getcommandkey("server info", "+show_info"), "^1 for gamemode info");
2467
2468                 if(gametype == GAME_ARENA)
2469                         s = "^1Wait for your turn to join";
2470                 else if(gametype == GAME_LMS)
2471                 {
2472                         entity sk;
2473                         sk = playerslots[player_localentnum - 1];
2474                         if(sk.(scores[ps_primary]) >= 666)
2475                                 s = "^1Match has already begun";
2476                         else if(sk.(scores[ps_primary]) > 0)
2477                                 s = "^1You have no more lives left";
2478                         else
2479                                 s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
2480                 }
2481                 else
2482                         s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
2483
2484                 //show restart countdown:
2485                 if (time < getstatf(STAT_GAMESTARTTIME)) {
2486                         float countdown;
2487                         //we need to ceil, otherwise the countdown would be off by .5 when using round()
2488                         countdown = ceil(getstatf(STAT_GAMESTARTTIME) - time);
2489                         s = strcat("^1Game starts in ^3", ftos(countdown), "^1 seconds");
2490                 }
2491         }
2492         if(warmup_stage && !intermission)
2493         {
2494                 s = "^2Currently in ^1warmup^2 stage!";
2495         }
2496
2497         // move more important stuff more to the middle so its more visible
2498
2499         string blinkcolor;
2500         if(mod(time, 1) >= 0.5)
2501                 blinkcolor = "^1";
2502         else
2503                 blinkcolor = "^3";
2504
2505         if(ready_waiting && !intermission && !spectatee_status)
2506         {
2507                 if(ready_waiting_for_me)
2508                 {
2509                         if(warmup_stage)
2510                                 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " to end warmup");
2511                         else
2512                                 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " once you are ready");
2513                 }
2514                 else
2515                 {
2516                         if(warmup_stage)
2517                                 s = strcat("^2Waiting for others to ready up to end warmup...");
2518                         else
2519                                 s = strcat("^2Waiting for others to ready up...");
2520                 }
2521         }
2522         else if(warmup_stage && !intermission && !spectatee_status)
2523         {
2524                 s = strcat("^2Press ^3", getcommandkey("ready", "ready"), "^2 to end warmup");
2525         }
2526
2527         if(teamplay && !intermission && !spectatee_status && gametype != GAME_CA && teamnagger)
2528         {
2529                 float ts_min, ts_max;
2530                 tm = teams.sort_next;
2531                 if (tm)
2532                 {
2533                         for(; tm.sort_next; tm = tm.sort_next)
2534                         {
2535                                 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
2536                                         continue;
2537                                 if(!ts_min) ts_min = tm.team_size;
2538                                 else ts_min = min(ts_min, tm.team_size);
2539                                 if(!ts_max) ts_max = tm.team_size;
2540                                 else ts_max = max(ts_max, tm.team_size);
2541                         }
2542                         if ((ts_max - ts_min) > 1)
2543                         {
2544                                 s = strcat(blinkcolor, "Teamnumbers are unbalanced!");
2545                                 tm = GetTeam(myteam, false);
2546                                 if (tm)
2547                                 if (tm.team != COLOR_SPECTATOR)
2548                                 if (tm.team_size == ts_max)
2549                                         s = strcat(s, " Press ^3", getcommandkey("team menu", "menu_showteamselect"), blinkcolor, " to adjust");
2550
2551                         }
2552                 }
2553         }
2554         */
2555 }
2556
2557 // Timer (#5)
2558 //
2559 void HUD_Timer()
2560 {
2561         float id = 5;
2562         vector pos, mySize;
2563         pos = HUD_Panel_GetPos(id);
2564         mySize = HUD_Panel_GetSize(id);
2565
2566         HUD_Panel_DrawBg(id, pos, mySize);
2567         float padding;
2568         padding = HUD_Panel_GetPadding(id);
2569         if(padding)
2570         {
2571                 pos += '1 1 0' * padding;
2572                 mySize -= '2 2 0' * padding;
2573         }
2574
2575         float timelimit, elapsedTime, minutes, seconds, timeleft, minutesLeft, secondsLeft;
2576
2577         timelimit = getstatf(STAT_TIMELIMIT);
2578
2579         timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
2580         timeleft = ceil(timeleft);
2581         minutesLeft = floor(timeleft / 60);
2582         secondsLeft = timeleft - minutesLeft*60;
2583
2584         vector timer_color;
2585         if(minutesLeft >= 5 || warmup_stage || timelimit == 0) //don't use red or yellow in warmup or when there is no timelimit
2586                 timer_color = '1 1 1'; //white
2587         else if(minutesLeft >= 1)
2588                 timer_color = '1 1 0'; //yellow
2589         else
2590                 timer_color = '1 0 0'; //red
2591
2592         if (cvar("hud_timer_increment") || timelimit == 0 || warmup_stage) {
2593                 if (time < getstatf(STAT_GAMESTARTTIME)) {
2594                         //while restart is still active, show 00:00
2595                         minutes = seconds = 0;
2596                 } else {
2597                         elapsedTime = floor(time - getstatf(STAT_GAMESTARTTIME)); //127
2598                         minutes = floor(elapsedTime / 60);
2599                         seconds = elapsedTime - minutes*60;
2600                 }
2601         } else {
2602                 minutes = minutesLeft;
2603                 seconds = secondsLeft;
2604         }
2605
2606         if(minutes > 999)
2607                 seconds = 99;
2608         minutes = min(minutes, 999);
2609         if(minutesLeft >= 1 || cvar("hud_timer_increment") || timelimit == 0 || warmup_stage) {
2610                 HUD_DrawXNum(pos + eX * mySize_x - eX * 5.1 * mySize_y, minutes, 3, 0, mySize_y, timer_color, 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
2611                 drawpic_skin(pos + eX * mySize_x - eX * 2.57 * mySize_y, "num_colon", '1 1 0' * mySize_y, timer_color, hud_alpha_fg, DRAWFLAG_NORMAL);
2612         }
2613         HUD_DrawXNum(pos + eX * mySize_x - eX * 2 * mySize_y, seconds, -2, 0, mySize_y, timer_color, 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
2614 }
2615
2616 // Radar (#6)
2617 //
2618 void HUD_Radar(void)
2619 {
2620         float id = 6;
2621         vector pos, mySize;
2622         pos = HUD_Panel_GetPos(id);
2623         mySize = HUD_Panel_GetSize(id);
2624
2625         HUD_Panel_DrawBg(id, pos, mySize);
2626         float padding;
2627         padding = HUD_Panel_GetPadding(id);
2628         if(padding)
2629         {
2630                 pos += '1 1 0' * padding;
2631                 mySize -= '2 2 0' * padding;
2632         }
2633
2634         local float color1, color2; // color already declared as a global in hud.qc
2635         local vector rgb;
2636         local entity tm;
2637         float scale2d, normalsize, bigsize;
2638         float f;
2639
2640         teamradar_origin2d = pos + 0.5 * mySize;
2641         teamradar_size2d = mySize;
2642
2643         if(minimapname == "")
2644                 return;
2645
2646         teamradar_loadcvars();
2647
2648         switch(hud_radar_zoommode)
2649         {
2650                 default:
2651                 case 0:
2652                         f = current_zoomfraction;
2653                         break;
2654                 case 1:
2655                         f = 1 - current_zoomfraction;
2656                         break;
2657                 case 2:
2658                         f = 0;
2659                         break;
2660                 case 3:
2661                         f = 1;
2662                         break;
2663         }
2664
2665         switch(hud_radar_rotation)
2666         {
2667                 case 0:
2668                         teamradar_angle = view_angles_y - 90;
2669                         break;
2670                 default:
2671                         teamradar_angle = 90 * hud_radar_rotation;
2672                         break;
2673         }
2674
2675         scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
2676         teamradar_size2d = mySize;
2677
2678         teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0'; // we always center
2679
2680         // pixels per world qu to match the teamradar_size2d_x range in the longest dimension
2681         if(hud_radar_rotation == 0)
2682         {
2683                 // max-min distance must fit the radar in any rotation
2684                 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen2d(mi_max - mi_min));
2685         }
2686         else
2687         {
2688                 vector c0, c1, c2, c3, span;
2689                 c0 = rotate(mi_min, teamradar_angle * DEG2RAD);
2690                 c1 = rotate(mi_max, teamradar_angle * DEG2RAD);
2691                 c2 = rotate('1 0 0' * mi_min_x + '0 1 0' * mi_max_y, teamradar_angle * DEG2RAD);
2692                 c3 = rotate('1 0 0' * mi_max_x + '0 1 0' * mi_min_y, teamradar_angle * DEG2RAD);
2693                 span = '0 0 0';
2694                 span_x = max4(c0_x, c1_x, c2_x, c3_x) - min4(c0_x, c1_x, c2_x, c3_x);
2695                 span_y = max4(c0_y, c1_y, c2_y, c3_y) - min4(c0_y, c1_y, c2_y, c3_y);
2696
2697                 // max-min distance must fit the radar in x=x, y=y
2698                 bigsize = min(
2699                         teamradar_size2d_x * scale2d / (1.05 * span_x),
2700                         teamradar_size2d_y * scale2d / (1.05 * span_y)
2701                 );
2702         }
2703
2704         normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / hud_radar_scale;
2705         if(bigsize > normalsize)
2706                 normalsize = bigsize;
2707
2708         teamradar_size =
2709                   f * bigsize
2710                 + (1 - f) * normalsize;
2711         teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
2712                   f * (mi_min + mi_max) * 0.5
2713                 + (1 - f) * view_origin);
2714
2715         color1 = GetPlayerColor(player_localentnum-1);
2716         rgb = GetTeamRGB(color1);
2717
2718         drawsetcliparea(
2719                 pos_x,
2720                 pos_y,
2721                 mySize_x,
2722                 mySize_y
2723         );
2724
2725         draw_teamradar_background(hud_radar_background_alpha, hud_radar_foreground_alpha);
2726
2727         for(tm = world; (tm = find(tm, classname, "radarlink")); )
2728                 draw_teamradar_link(tm.origin, tm.velocity, tm.team);
2729         for(tm = world; (tm = findflags(tm, teamradar_icon, 0xFFFFFF)); )
2730                 draw_teamradar_icon(tm.origin, tm.teamradar_icon, tm, tm.teamradar_color, hud_alpha_fg);
2731         for(tm = world; (tm = find(tm, classname, "entcs_receiver")); )
2732         {
2733                 color2 = GetPlayerColor(tm.sv_entnum);
2734                 //if(color == COLOR_SPECTATOR || color == color2)
2735                         draw_teamradar_player(tm.origin, tm.angles, GetTeamRGB(color2));
2736         }
2737         draw_teamradar_player(view_origin, view_angles, '1 1 1');
2738
2739         drawresetcliparea();
2740 };
2741
2742 // Score (#7)
2743 //
2744 void HUD_Score()
2745 {
2746         float id = 7;
2747         vector pos, mySize;
2748         pos = HUD_Panel_GetPos(id);
2749         mySize = HUD_Panel_GetSize(id);
2750
2751         HUD_Panel_DrawBg(id, pos, mySize);
2752         float padding;
2753         padding = HUD_Panel_GetPadding(id);
2754         if(padding)
2755         {
2756                 pos += '1 1 0' * padding;
2757                 mySize -= '2 2 0' * padding;
2758         }
2759
2760         float score, distribution, leader;
2761         float score_len, distr_len;
2762         vector distribution_color;
2763         entity tm, pl, me;
2764         me = (spectatee_status > 0) ? playerslots[spectatee_status - 1] : playerslots[player_localentnum - 1];
2765
2766         // TODO... this (race part) still uses constant coordinates :/
2767         if((scores_flags[ps_primary] & SFL_TIME) && !teamplay) { // race/cts record display on HUD
2768                 /*pl = players.sort_next;
2769                 if(pl == me)
2770                         pl = pl.sort_next;
2771                 if(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)
2772                         if(pl.scores[ps_primary] == 0)
2773                                 pl = world;
2774
2775                 score = me.(scores[ps_primary]);
2776
2777                 float racemin, racesec, racemsec;
2778                 float distsec, distmsec, minusplus;
2779
2780                 racemin = floor(score/(60 * TIME_FACTOR));
2781                 racesec = floor((score - racemin*(60 * TIME_FACTOR))/TIME_FACTOR);
2782                 racemsec = score - racemin*60*TIME_FACTOR - racesec*TIME_FACTOR;
2783
2784                 if (pl && ((!(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)) || score)) {
2785                         // distribution display
2786                         distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
2787
2788                         if (distribution < TIME_FACTOR && distribution > -TIME_FACTOR)
2789                                 distmsec = fabs(distribution);
2790                         else {
2791                                 distsec = floor(fabs(distribution)/TIME_FACTOR);
2792                                 distmsec = fabs(distribution) - distsec*TIME_FACTOR;
2793                                 if (distribution < 0)
2794                                         distsec = -distsec;
2795                         }
2796
2797                         if (distribution <= 0) {
2798                                 distribution_color = eY;
2799                                 minusplus = 1; // minusplus 1: always prefix with minus sign
2800                         }
2801                         else {
2802                                 distribution_color = eX;
2803                                 minusplus = 2; // minusplus 1: always prefix with plus sign
2804                         }
2805                         HUD_DrawXNum(bottomright - '0 48 0' - '16 0 0' * TIME_DECIMALS, distmsec, -TIME_DECIMALS, 0, 16, distribution_color, 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
2806                         HUD_DrawXNum(bottomright - '68 48 0' - '16 0 0' * TIME_DECIMALS, distsec, 4, minusplus, 16, distribution_color, 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
2807                         drawpic_skin(bottomright - '10 48 0' - '16 0 0' * TIME_DECIMALS, "num_dot", '16 16 0', distribution_color, hud_alpha_fg, DRAWFLAG_ADDITIVE);
2808                 }
2809                 // race record display
2810                 if (distribution <= 0 || distribution == score) // draw the highlight background behind the timer if we have the lead
2811                         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_alpha_fg, DRAWFLAG_NORMAL);
2812
2813                 HUD_DrawXNum(bottomright - '0 32 0' - TIME_DECIMALS * '30 0 0', racemsec, -TIME_DECIMALS, 0, 30, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
2814                 HUD_DrawXNum(bottomright - '0 32 0' - TIME_DECIMALS * '30 0 0'  - '66 0 0', racesec, -2, 0, 30, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
2815                 drawpic_skin(bottomright - '0 32 0' - TIME_DECIMALS * '30 0 0' - '18 0 0', "num_dot", '30 30 0', '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE);
2816
2817                 HUD_DrawXNum(bottomright - '0 32 0' - TIME_DECIMALS * '30 0 0' - '132 0 0', racemin, -2, 0, 30, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
2818                 drawpic_skin(bottomright - '0 32 0' - TIME_DECIMALS * '30 0 0' - '84 0 0', "num_colon", '30 30 0', '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE);
2819                 */
2820         } else if (!teamplay) { // non-teamgames
2821                 // me vector := [team/connected frags id]
2822                 pl = players.sort_next;
2823                 if(pl == me)
2824                         pl = pl.sort_next;
2825
2826                 if(hud_configure)
2827                         distribution = 42;
2828                 else if(pl)
2829                         distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
2830                 else
2831                         distribution = 0;
2832
2833                 score = me.(scores[ps_primary]);
2834                 if(hud_configure)
2835                         score = 123;
2836
2837                 if(distribution >= 5) {
2838                         distribution_color = eY;
2839                         leader = 1;
2840                 } else if(distribution >= 0) {
2841                         distribution_color = '1 1 1';
2842                         leader = 1;
2843                 } else if(distribution >= -5)
2844                         distribution_color = '1 1 0';
2845                 else
2846                         distribution_color = eX;
2847
2848                 score_len = strlen(ftos(score));
2849                 distr_len = strlen(ftos(distribution));
2850
2851                 HUD_DrawXNum(pos + eX * mySize_x - eX * 3 * 0.33 * mySize_y, distribution, 3, 3, 0.33 * mySize_y, distribution_color, 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
2852                 if (leader)
2853                         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_alpha_fg, DRAWFLAG_NORMAL);
2854                 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_alpha_fg, DRAWFLAG_NORMAL);
2855         } else { // teamgames
2856                 float max_fragcount;
2857                 max_fragcount = -99;
2858
2859                 float teamnum;
2860                 for(tm = teams.sort_next; tm; tm = tm.sort_next) {
2861                         if(tm.team == COLOR_SPECTATOR || (!tm.team_size && !hud_configure)) // no players? don't display
2862                                 continue;
2863                         score = tm.(teamscores[ts_primary]);
2864                         if(hud_configure)
2865                                 score = 123;
2866                         leader = 0;
2867                         
2868                         score_len = strlen(ftos(score));
2869
2870                         if (score > max_fragcount)
2871                                 max_fragcount = score;
2872
2873                         if(tm.team == myteam) {
2874                                 if (max_fragcount == score)
2875                                         leader = 1;
2876                                 if (leader)
2877                                         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_alpha_fg, DRAWFLAG_NORMAL);
2878                                 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_alpha_fg, DRAWFLAG_NORMAL);
2879                         } else {
2880                                 if (max_fragcount == score)
2881                                         leader = 1;
2882                                 if (leader)
2883                                         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_alpha_fg, DRAWFLAG_NORMAL);
2884                                 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_alpha_fg, DRAWFLAG_NORMAL);
2885                                 teamnum += 1;
2886                         }
2887                 }
2888         }
2889 }
2890
2891 // Race timer (#8)
2892 //
2893 void HUD_RaceTimer (void) {
2894         float id = 8;
2895         vector pos, mySize;
2896         pos = HUD_Panel_GetPos(id);
2897         mySize = HUD_Panel_GetSize(id);
2898
2899         HUD_Panel_DrawBg(id, pos, mySize);
2900         float padding;
2901         padding = HUD_Panel_GetPadding(id);
2902         if(padding)
2903         {
2904                 pos += '1 1 0' * padding;
2905                 mySize -= '2 2 0' * padding;
2906         }
2907
2908         drawfont = hud_bigfont;
2909         float a, t;
2910         string s, forcetime;
2911
2912         if(hud_configure)
2913         {
2914                 s = "0:13:37";
2915                 drawstring(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(s, FALSE, '0.75 0.75 0' * mySize_y), s, '0.75 0.75 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2916                 s = "^1Intermediate 1 (+15.42)";
2917                 drawcolorcodedstring(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(s, TRUE, '1 1 0' * 0.25 * mySize_y) + eY * 0.75 * mySize_y, s, '1 1 0' * 0.25 * mySize_y, hud_alpha_fg, DRAWFLAG_NORMAL);
2918         }
2919         else if(race_checkpointtime)
2920         {
2921                 a = bound(0, 2 - (time - race_checkpointtime), 1);
2922                 s = "";
2923                 forcetime = "";
2924                 if(a > 0) // just hit a checkpoint?
2925                 {
2926                         if(race_checkpoint != 254)
2927                         {
2928                                 if(race_time && race_previousbesttime)
2929                                         s = MakeRaceString(race_checkpoint, TIME_DECODE(race_time) - TIME_DECODE(race_previousbesttime), 0, 0, race_previousbestname);
2930                                 else
2931                                         s = MakeRaceString(race_checkpoint, 0, -1, 0, race_previousbestname);
2932                                 if(race_time)
2933                                         forcetime = TIME_ENCODED_TOSTRING(race_time);
2934                         }
2935                 }
2936                 else
2937                 {
2938                         if(race_laptime && race_nextbesttime && race_nextcheckpoint != 254)
2939                         {
2940                                 a = bound(0, 2 - ((race_laptime + TIME_DECODE(race_nextbesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1);
2941                                 if(a > 0) // next one?
2942                                 {
2943                                         s = MakeRaceString(race_nextcheckpoint, (time + TIME_DECODE(race_penaltyaccumulator)) - race_laptime, TIME_DECODE(race_nextbesttime), 0, race_nextbestname);
2944                                 }
2945                         }
2946                 }
2947
2948                 if(s != "" && a > 0)
2949                 {
2950                         dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
2951                         //drawcolorcodedstring(m - '0 16 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2952                         drawcolorcodedstring(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(s, TRUE, '1 1 0' * 0.25 * mySize_y) + eY * 0.75 * mySize_y, s, '1 1 0' * 0.25 * mySize_y, hud_alpha_fg * a, DRAWFLAG_NORMAL);
2953                 }
2954
2955                 // ___ TODO!!!___
2956                 if(race_penaltytime)
2957                 {
2958                         a = bound(0, 2 - (time - race_penaltyeventtime), 1);
2959                         if(a > 0)
2960                         {
2961                                 s = strcat("^1PENALTY: ", ftos_decimals(race_penaltytime * 0.1, 1), " (", race_penaltyreason, ")");
2962                                 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
2963                                 //drawcolorcodedstring(m - '0 32 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2964                                 drawcolorcodedstring(pos - '0 32 0' - '0.5 0 0' * stringwidth(s, TRUE, '16 16 0'), s, '16 16 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2965                         }
2966                 }
2967
2968                 if(forcetime != "")
2969                 {
2970                         a = bound(0, (time - race_checkpointtime) / 0.5, 1);
2971                         //drawstring_expanding(m - '16 0 0' * stringwidth(forcetime, FALSE), forcetime, '32 32 0', '1 1 1', hud_alpha_fg, 0, a);
2972                         drawstring_expanding(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(forcetime, FALSE, '1 1 0' * 0.75 * mySize_y), forcetime, '1 1 0' * 0.75 * mySize_y, '1 1 1', hud_alpha_fg, 0, a);
2973                 }
2974                 else
2975                         a = 1;
2976
2977                 if(race_laptime && race_checkpoint != 255)
2978                 {
2979                         s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime));
2980                         //drawstring(m - '16 0 0' * stringwidth(s, FALSE), s, '32 32 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2981                         drawstring(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(s, FALSE, '0.75 0.75 0' * mySize_y), s, '0.75 0.75 0' * mySize_y, '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2982                 }
2983         }
2984         else
2985         {
2986                 if(race_mycheckpointtime)
2987                 {
2988                         a = bound(0, 2 - (time - race_mycheckpointtime), 1);
2989                         s = MakeRaceString(race_mycheckpoint, TIME_DECODE(race_mycheckpointdelta), -!race_mycheckpointenemy, race_mycheckpointlapsdelta, race_mycheckpointenemy);
2990                         dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
2991                         //drawcolorcodedstring(m - '0 16 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2992                         drawcolorcodedstring(pos - '0 16 0' - '0.5 0 0' * stringwidth(s, TRUE, '16 16 0'), s, '16 16 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2993                 }
2994                 if(race_othercheckpointtime && race_othercheckpointenemy != "")
2995                 {
2996                         a = bound(0, 2 - (time - race_othercheckpointtime), 1);
2997                         s = MakeRaceString(race_othercheckpoint, -TIME_DECODE(race_othercheckpointdelta), -!race_othercheckpointenemy, race_othercheckpointlapsdelta, race_othercheckpointenemy);
2998                         dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
2999                         //drawcolorcodedstring(m - '0 0 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
3000                         drawcolorcodedstring(pos - '0 0 0' - '0.5 0 0' * stringwidth(s, TRUE, '16 16 0'), s, '16 16 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
3001                 }
3002
3003                 if(race_penaltytime && !race_penaltyaccumulator)
3004                 {
3005                         t = race_penaltytime * 0.1 + race_penaltyeventtime;
3006                         a = bound(0, (1 + t - time), 1);
3007                         if(a > 0)
3008                         {
3009                                 if(time < t)
3010                                         s = strcat("^1PENALTY: ", ftos_decimals(t - time, 1), " (", race_penaltyreason, ")");
3011                                 else
3012                                         s = strcat("^2PENALTY: 0.0 (", race_penaltyreason, ")");
3013                                 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
3014                                 //drawcolorcodedstring(m - '0 32 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
3015                                 drawcolorcodedstring(pos - '0 32 0' - '0.5 0 0' * stringwidth(s, TRUE, '16 16 0'), s, '16 16 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
3016                         }
3017                 }
3018         }
3019
3020         drawfont = hud_font;
3021 }
3022
3023 // Vote window (#9)
3024 //
3025 float vote_yescount;
3026 float vote_nocount;
3027 float vote_needed;
3028 float vote_highlighted; // currently selected vote
3029
3030 float vote_active; // is there an active vote?
3031 float vote_prev; // previous state of vote_active to check for a change
3032 float vote_alpha;
3033 float vote_change; // "time" when vote_active changed
3034
3035 void HUD_VoteWindow(void) 
3036 {
3037         float id = 9;
3038         vector pos, mySize;
3039         pos = HUD_Panel_GetPos(id);
3040         mySize = HUD_Panel_GetSize(id);
3041
3042         string s;
3043         float a;
3044         if(vote_active != vote_prev) {
3045                 vote_change = time;
3046                 vote_prev = bound(0, vote_active, 1);
3047         }
3048
3049         if(vote_active)
3050                 vote_alpha = bound(0, (time - vote_change) * 2, 1);
3051         else
3052                 vote_alpha = bound(0, 1 - (time - vote_change) * 2, 1);
3053
3054         if(hud_configure)
3055         {
3056                 vote_alpha = 1;
3057                 vote_yescount = 3;
3058                 vote_nocount = 2;
3059                 vote_needed = 4;
3060         }
3061
3062         HUD_Panel_DrawBg(id, pos, mySize);
3063         float padding;
3064         padding = HUD_Panel_GetPadding(id);
3065         if(padding)
3066         {
3067                 pos += '1 1 0' * padding;
3068                 mySize -= '2 2 0' * padding;
3069         }
3070
3071         if(vote_alpha) {
3072                 a = vote_alpha * bound(cvar_or("hud_vote_alreadyvoted_alpha", 0.75), 1 - vote_highlighted, 1);
3073
3074                 drawpic_skin(pos, "voteprogress_back", mySize, HUD_Panel_GetColor(id), a * hud_alpha_bg, DRAWFLAG_NORMAL);
3075
3076                 s = "A vote has been called for: ";
3077                 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_alpha_fg, DRAWFLAG_NORMAL);
3078                 s = textShortenToWidth(vote_called_vote, mySize_x * 0.96, '10 0 0', stringwidth_colors); // TODO: broken?
3079                 if(hud_configure)
3080                         s = "Configure the HUD";
3081                 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_alpha_fg, DRAWFLAG_NORMAL);
3082
3083                 // print the yes/no counts
3084                 s = strcat("Yes: ", ftos(vote_yescount));
3085                 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_alpha_fg, DRAWFLAG_NORMAL);
3086                 s = strcat("No: ", ftos(vote_nocount));
3087                 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_alpha_fg, DRAWFLAG_NORMAL);
3088
3089                 // draw the progress bars
3090                 drawsetcliparea(pos_x, pos_y, mySize_x * 0.5 * (vote_yescount/vote_needed), mySize_y);
3091                 drawpic_skin(pos, "voteprogress_prog", mySize, eY, a * hud_alpha_fg, DRAWFLAG_NORMAL);
3092
3093                 drawsetcliparea(pos_x + mySize_x - mySize_x * 0.5 * (vote_nocount/vote_needed), pos_y, mySize_x * 0.5, mySize_y);
3094                 drawpic_skin(pos, "voteprogress_prog", mySize, eX, a * hud_alpha_fg, DRAWFLAG_NORMAL);
3095
3096                 // draw the highlights
3097                 if(vote_highlighted == 1) {
3098                         drawsetcliparea(pos_x, pos_y, mySize_x * 0.5, mySize_y);
3099                         drawpic_skin(pos, "voteprogress_voted", mySize, eY, a * hud_alpha_fg, DRAWFLAG_NORMAL);
3100                 }
3101                 else if(vote_highlighted == 2) {
3102                         drawsetcliparea(pos_x + 0.5 * mySize_x, pos_y, mySize_x * 0.5, mySize_y);
3103                         drawpic_skin(pos, "voteprogress_voted", mySize, eX, a * hud_alpha_fg, DRAWFLAG_NORMAL);
3104                 }
3105
3106                 drawresetcliparea();
3107         }
3108         else if(!vote_active) {
3109                 vote_highlighted = 0;
3110         }
3111 }
3112
3113 // Mod icons panel (#10)
3114 //
3115
3116 // CTF HUD modicon section
3117 float redflag_prevframe, blueflag_prevframe; // status during previous frame
3118 float redflag_prevstatus, blueflag_prevstatus; // last remembered status
3119 float redflag_statuschange_time, blueflag_statuschange_time; // time when the status changed
3120
3121 void HUD_Mod_CTF_Reset(void)
3122 {
3123         redflag_prevstatus = blueflag_prevstatus = redflag_prevframe = blueflag_prevframe = redflag_statuschange_time = blueflag_statuschange_time = 0;
3124 }
3125
3126 void HUD_Mod_CTF(vector pos, vector mySize)
3127 {
3128         vector redflag_pos, blueflag_pos;
3129         float f; // every function should have that
3130
3131         float redflag, blueflag; // current status
3132         float redflag_statuschange_elapsedtime, blueflag_statuschange_elapsedtime; // time since the status changed
3133         float stat_items;
3134
3135         stat_items = getstati(STAT_ITEMS);
3136         redflag = (stat_items/IT_RED_FLAG_TAKEN) & 3;
3137         blueflag = (stat_items/IT_BLUE_FLAG_TAKEN) & 3;
3138
3139         if(hud_configure)
3140         {
3141                 redflag = 1;
3142                 blueflag = 2;
3143         }
3144
3145         // when status CHANGES, set old status into prevstatus and current status into status
3146         if (redflag != redflag_prevframe)
3147         {
3148                 redflag_statuschange_time = time;
3149                 redflag_prevstatus = redflag_prevframe;
3150                 redflag_prevframe = redflag;
3151         }
3152
3153         if (blueflag != blueflag_prevframe)
3154         {
3155                 blueflag_statuschange_time = time;
3156                 blueflag_prevstatus = blueflag_prevframe;
3157                 blueflag_prevframe = blueflag;
3158         }
3159
3160         redflag_statuschange_elapsedtime = time - redflag_statuschange_time;
3161         blueflag_statuschange_elapsedtime = time - blueflag_statuschange_time;
3162
3163         float BLINK_FACTOR = 0.15;
3164         float BLINK_BASE = 0.85;
3165         // note:
3166         //   RMS = sqrt(BLINK_BASE^2 + 0.5 * BLINK_FACTOR^2)
3167         // thus
3168         //   BLINK_BASE = sqrt(RMS^2 - 0.5 * BLINK_FACTOR^2)
3169         // ensure RMS == 1
3170         float BLINK_FREQ = 5; // circle frequency, = 2*pi*frequency in hertz
3171
3172         string red_icon, red_icon_prevstatus;
3173         float red_alpha, red_alpha_prevstatus;
3174         red_alpha = red_alpha_prevstatus = 1;
3175         switch(redflag) {
3176                 case 1: red_icon = "flag_red_taken"; break;
3177                 case 2: red_icon = "flag_red_lost"; break;
3178                 case 3: red_icon = "flag_red_carrying"; red_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3179                 default:
3180                         if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM2))
3181                                 red_icon = "flag_red_shielded";
3182                         else
3183                                 red_icon = string_null;
3184                         break;
3185         }
3186         switch(redflag_prevstatus) {
3187                 case 1: red_icon_prevstatus = "flag_red_taken"; break;
3188                 case 2: red_icon_prevstatus = "flag_red_lost"; break;
3189                 case 3: red_icon_prevstatus = "flag_red_carrying"; red_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3190                 default:
3191                         if(redflag == 3)
3192                                 red_icon_prevstatus = "flag_red_carrying"; // make it more visible
3193                         else if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM2))
3194                                 red_icon_prevstatus = "flag_red_shielded";
3195                         else
3196                                 red_icon_prevstatus = string_null;
3197                         break;
3198         }
3199
3200         string blue_icon, blue_icon_prevstatus;
3201         float blue_alpha, blue_alpha_prevstatus;
3202         blue_alpha = blue_alpha_prevstatus = 1;
3203         switch(blueflag) {
3204                 case 1: blue_icon = "flag_blue_taken"; break;
3205                 case 2: blue_icon = "flag_blue_lost"; break;
3206                 case 3: blue_icon = "flag_blue_carrying"; blue_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3207                 default:
3208                         if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM1))
3209                                 blue_icon = "flag_blue_shielded";
3210                         else
3211                                 blue_icon = string_null;
3212                         break;
3213         }
3214         switch(blueflag_prevstatus) {
3215                 case 1: blue_icon_prevstatus = "flag_blue_taken"; break;
3216                 case 2: blue_icon_prevstatus = "flag_blue_lost"; break;
3217                 case 3: blue_icon_prevstatus = "flag_blue_carrying"; blue_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3218                 default:
3219                         if(blueflag == 3)
3220                                 blue_icon_prevstatus = "flag_blue_carrying"; // make it more visible
3221                         else if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM1))
3222                                 blue_icon_prevstatus = "flag_blue_shielded";
3223                         else
3224                                 blue_icon_prevstatus = string_null;
3225                         break;
3226         }
3227
3228         if (myteam == COLOR_TEAM1) { // always draw own flag on left
3229                 redflag_pos = pos;
3230                 blueflag_pos = pos + eX * mySize_y;
3231         } else {
3232                 blueflag_pos = pos;
3233                 redflag_pos = pos + eX * mySize_y;
3234         }
3235
3236         f = bound(0, redflag_statuschange_elapsedtime*2, 1);
3237         if(red_icon_prevstatus && f < 1)
3238                 drawpic_skin_expanding(redflag_pos, red_icon_prevstatus, '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg * red_alpha_prevstatus, DRAWFLAG_NORMAL, f);
3239         if(red_icon)
3240                 drawpic_skin(redflag_pos, red_icon, '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg * red_alpha * f, DRAWFLAG_NORMAL);
3241
3242         f = bound(0, blueflag_statuschange_elapsedtime*2, 1);
3243         if(blue_icon_prevstatus && f < 1)
3244                 drawpic_skin_expanding(blueflag_pos, blue_icon_prevstatus, '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg * blue_alpha_prevstatus, DRAWFLAG_NORMAL, f);
3245         if(blue_icon)
3246                 drawpic_skin(blueflag_pos, blue_icon, '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg * blue_alpha * f, DRAWFLAG_NORMAL);
3247 }
3248
3249 // Keyhunt HUD modicon section
3250 float kh_runheretime;
3251
3252 void HUD_Mod_KH_Reset(void)
3253 {
3254         kh_runheretime = 0;
3255 }
3256
3257 void HUD_Mod_KH(vector pos, vector mySize)
3258 {
3259         float kh_keys;
3260         float keyteam;
3261         float a, aa;
3262         vector p, pa, kh_size, kh_asize;
3263
3264         p_x = pos_x;
3265         p_y = pos_y + 0.25 * mySize_y;
3266
3267         kh_keys = getstati(STAT_KH_KEYS);
3268
3269         kh_size_x = mySize_x * 0.25;
3270         kh_size_y = 0.75 * mySize_y;
3271
3272         pa = p - eY * 0.25 * mySize_y;
3273
3274         kh_asize_x = mySize_x * 0.25;
3275         kh_asize_y = mySize_y * 0.25;
3276
3277         float i, key;
3278
3279         float keycount;
3280         keycount = 0;
3281         for(i = 0; i < 4; ++i)
3282         {
3283                 key = floor(kh_keys / pow(32, i)) & 31;
3284                 keyteam = key - 1;
3285                 if(keyteam == 30 && keycount <= 4)
3286                         keycount += 4;
3287                 if(keyteam == myteam || keyteam == -1 || keyteam == 30)
3288                         keycount += 1;
3289         }
3290         // this yields 8 exactly if "RUN HERE" shows
3291
3292         if(keycount == 8)
3293         {
3294                 if(!kh_runheretime)
3295                         kh_runheretime = time;
3296                 pa_y -= fabs(sin((time - kh_runheretime) * 3.5)) * 6; // make the arrows jump in case of RUN HERE
3297         }
3298         else
3299                 kh_runheretime = 0;
3300
3301         for(i = 0; i < 4; ++i)
3302         {
3303                 key = floor(kh_keys / pow(32, i)) & 31;
3304                 keyteam = key - 1;
3305                 switch(keyteam)
3306                 {
3307                         case 30: // my key
3308                                 keyteam = myteam;
3309                                 a = 1;
3310                                 aa = 1;
3311                                 break;
3312                         case -1: // no key
3313                                 a = 0;
3314                                 aa = 0;
3315                                 break;
3316                         default: // owned or dropped
3317                                 a = 0.2;
3318                                 aa = 0.5;
3319                                 break;
3320                 }
3321                 a = a * hud_alpha_fg;
3322                 aa = aa * hud_alpha_fg;
3323                 if(a > 0)
3324                 {
3325                         switch(keyteam)
3326                         {
3327                                 case COLOR_TEAM1:
3328                                         drawpic_skin(pa, "kh_redarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL);  // show 30% alpha key
3329                                         break;
3330                                 case COLOR_TEAM2:
3331                                         drawpic_skin(pa, "kh_bluearrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL);  // show 30% alpha key
3332                                         break;
3333                                 case COLOR_TEAM3:
3334                                         drawpic_skin(pa, "kh_yellowarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL);  // show 30% alpha key
3335                                         break;
3336                                 case COLOR_TEAM4:
3337                                         drawpic_skin(pa, "kh_pinkarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL);  // show 30% alpha key
3338                                         break;
3339                                 default:
3340                                         break;
3341                         }
3342                         switch(i) // YAY! switch(i) inside a for loop for i. DailyWTF, here we come!
3343                         {
3344                                 case 0:
3345                                         drawpic_skin(p, "kh_red", kh_size, '1 1 1', a, DRAWFLAG_NORMAL);  // show 30% alpha key
3346                                         break;
3347                                 case 1:
3348                                         drawpic_skin(p, "kh_blue", kh_size, '1 1 1', a, DRAWFLAG_NORMAL);  // show 30% alpha key
3349                                         break;
3350                                 case 2:
3351                                         drawpic_skin(p, "kh_yellow", kh_size, '1 1 1', a, DRAWFLAG_NORMAL);  // show 30% alpha key
3352                                         break;
3353                                 case 3:
3354                                         drawpic_skin(p, "kh_pink", kh_size, '1 1 1', a, DRAWFLAG_NORMAL);  // show 30% alpha key
3355                                         break;
3356                         }
3357                 }
3358                 p_x += 0.25 * mySize_x;
3359                 pa_x += 0.25 * mySize_x;
3360         }
3361 }
3362
3363 // Nexball HUD mod icon
3364 void HUD_Mod_NexBall(vector pos, vector mySize)
3365 {
3366         float stat_items, nb_pb_starttime, dt, p;
3367
3368         stat_items = getstati(STAT_ITEMS);
3369         nb_pb_starttime = getstatf(STAT_NB_METERSTART);
3370
3371         //Manage the progress bar if any
3372         if (nb_pb_starttime > 0)
3373         {
3374                 dt = mod(time - nb_pb_starttime, nb_pb_period);
3375                 // one period of positive triangle
3376                 p = 2 * dt / nb_pb_period;
3377                 if (p > 1)
3378                         p = 2 - p;
3379
3380                 //Draw the filling
3381                 HUD_Panel_DrawProgressBar(pos, 0, eX * p * mySize_x + eY * mySize_y, HUD_Panel_GetProgressBarColor("nexball"), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
3382         }
3383
3384         pos_x += 0.5 * mySize_x - 0.5 * mySize_y; //horizontal margin to the picture
3385
3386         if (stat_items & IT_KEY1)
3387                 drawpic_skin(pos, "nexball_carrying", '1 1 0' * mySize_y, '1 1 1', 1, DRAWFLAG_NORMAL);
3388 }
3389
3390 // Race/CTS HUD mod icons
3391 float crecordtime_prev; // last remembered crecordtime
3392 float crecordtime_change_time; // time when crecordtime last changed
3393 float srecordtime_prev; // last remembered srecordtime
3394 float srecordtime_change_time; // time when srecordtime last changed
3395
3396 float race_status_time;
3397 float race_status_prev;
3398 string race_status_name_prev;
3399 void HUD_Mod_Race(vector pos, vector mySize)
3400 {
3401         entity me;
3402         me = playerslots[player_localentnum - 1];
3403         float t, score;
3404         float f; // yet another function has this
3405         score = me.(scores[ps_primary]);
3406
3407         if not((scores_flags[ps_primary] & SFL_TIME) && !teamplay) // race/cts record display on HUD
3408                 return; // no records in the actual race
3409
3410         drawfont = hud_bigfont;
3411
3412         // clientside personal record
3413         string rr;
3414         if(gametype == GAME_CTS)
3415                 rr = CTS_RECORD;
3416         else
3417                 rr = RACE_RECORD;
3418         t = stof(db_get(ClientProgsDB, strcat(shortmapname, rr, "time")));
3419
3420         if(score && (score < t || !t)) {
3421                 db_put(ClientProgsDB, strcat(shortmapname, rr, "time"), ftos(score));
3422                 if(cvar("cl_autodemo_delete_keeprecords"))
3423                 {
3424                         f = cvar("cl_autodemo_delete");
3425                         f &~= 1;
3426                         cvar_set("cl_autodemo_delete", ftos(f)); // don't delete demo with new record!
3427                 }
3428         }
3429
3430         if(t != crecordtime_prev) {
3431                 crecordtime_prev = t;
3432                 crecordtime_change_time = time;
3433         }
3434         f = time - crecordtime_change_time;
3435
3436         if (f > 1) {
3437                 drawstring(pos, "Personal best ", '1 1 0' * 0.15 * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
3438                 drawstring(pos + eY * 0.2 * mySize_y, TIME_ENCODED_TOSTRING(t), '1 1 0' * 0.2 * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
3439         } else {
3440                 drawstring(pos, "Personal best ", '1 1 0' * 0.15 * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
3441                 drawstring(pos + eY * 0.2 * mySize_y, TIME_ENCODED_TOSTRING(t), '1 1 0' * 0.2 * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
3442                 drawstring_expanding(pos, "Personal best ", '1 1 0' * 0.15 * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL, f);
3443                 drawstring_expanding(pos + eY * 0.2 * mySize_y, TIME_ENCODED_TOSTRING(t), '1 1 0' * 0.2 * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL, f);
3444         }
3445
3446         // server record
3447         t = race_server_record;
3448         if(t != srecordtime_prev) {
3449                 srecordtime_prev = t;
3450                 srecordtime_change_time = time;
3451         }
3452         f = time - srecordtime_change_time;
3453
3454         if (f > 1) {
3455                 drawstring(pos + eY * 0.5 * mySize_y, "Server best ", '1 1 0' * 0.15 * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
3456                 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_alpha_fg, DRAWFLAG_NORMAL);
3457         } else {
3458                 drawstring(pos + eY * 0.5 * mySize_y, "Server best ", '1 1 0' * 0.15 * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
3459                 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_alpha_fg, DRAWFLAG_NORMAL);
3460                 drawstring_expanding(pos + eY * 0.5 * mySize_y, "Server best ", '1 1 0' * 0.15 * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL, f);
3461                 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_alpha_fg, DRAWFLAG_NORMAL, f);
3462         }
3463
3464         if (race_status != race_status_prev || race_status_name != race_status_name_prev) {
3465                 race_status_time = time + 5;
3466                 race_status_prev = race_status;
3467                 if (race_status_name_prev)
3468                         strunzone(race_status_name_prev);
3469                 race_status_name_prev = strzone(race_status_name);
3470         }
3471
3472         pos_x += mySize_x/2;
3473         // race "awards"
3474         float a;
3475         a = bound(0, race_status_time - time, 1);
3476
3477         string s;
3478         s = textShortenToWidth(race_status_name, 120, '10 10 0', stringwidth_colors);
3479
3480         float rank;
3481         if(race_status > 0)
3482                 rank = race_CheckName(race_status_name);
3483         string rankname;
3484         rankname = race_PlaceName(rank);
3485
3486         if(race_status == 0)
3487                 drawpic_skin(pos, "race_newfail", '80 80 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
3488         else if(race_status == 1) {
3489                 drawpic_skin(pos, "race_newtime", '80 80 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
3490                 drawcolorcodedstring(pos + '40 80 0' - eX * stringwidth(s, TRUE, '5 0 0'), s, '10 10 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
3491                 drawstring(pos + '40 20 0' - eX * stringwidth(rankname, TRUE, '7 0 0'), rankname, '14 14 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
3492         } else if(race_status == 2) {
3493                 if(race_status_name == GetPlayerName(player_localentnum -1) || !race_myrank || race_myrank < rank)
3494                         drawpic_skin(pos, "race_newrankgreen", '80 80 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
3495                 else
3496                         drawpic_skin(pos, "race_newrankyellow", '80 80 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
3497                 drawcolorcodedstring(pos + '40 80 0' - eX * stringwidth(s, TRUE, '5 0 0'), s, '10 10 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
3498                 drawstring(pos + '40 20 0' - eX * stringwidth(rankname, TRUE, '7 0 0'), rankname, '14 14 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
3499         } else if(race_status == 3) {
3500                 drawpic_skin(pos, "race_newrecordserver", '80 80 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
3501                 drawcolorcodedstring(pos + '40 80 0' - eX * stringwidth(s, TRUE, '5 0 0'), s, '10 10 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
3502                 drawstring(pos + '40 20 0' - eX * stringwidth(rankname, TRUE, '7 0 0'), rankname, '14 14 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
3503         }
3504
3505         if (race_status_time - time <= 0) {
3506                 race_status_prev = -1;
3507                 race_status = -1;
3508                 if(race_status_name)
3509                         strunzone(race_status_name);
3510                 race_status_name = string_null;
3511                 if(race_status_name_prev)
3512                         strunzone(race_status_name_prev);
3513                 race_status_name_prev = string_null;
3514         }
3515         drawfont = hud_font;
3516 }
3517
3518 // TODO: idea: alpha fade in/out empty panels
3519 void HUD_ModIcons(void)
3520 {
3521         if (gametype != GAME_KEYHUNT && gametype != GAME_CTF && gametype != GAME_NEXBALL && gametype != GAME_CTS && gametype != GAME_RACE && !hud_configure)
3522                 return;
3523         float id = 10;
3524         vector pos, mySize;
3525         pos = HUD_Panel_GetPos(id);
3526         mySize = HUD_Panel_GetSize(id);
3527
3528         HUD_Panel_DrawBg(id, pos, mySize);
3529         float padding;
3530         padding = HUD_Panel_GetPadding(id);
3531         if(padding)
3532         {
3533                 pos += '1 1 0' * padding;
3534                 mySize -= '2 2 0' * padding;
3535         }
3536
3537         // TODO... well make them work in a panel etc
3538         if(gametype == GAME_KEYHUNT)
3539                 HUD_Mod_KH(pos, mySize);
3540         else if(gametype == GAME_CTF || hud_configure)
3541                 HUD_Mod_CTF(pos, mySize);
3542         else if(gametype == GAME_NEXBALL)
3543                 HUD_Mod_NexBall(pos, mySize);
3544         else if(gametype == GAME_CTS || gametype == GAME_RACE)
3545                 HUD_Mod_Race(pos, mySize);
3546 }
3547
3548 // Draw pressed keys (#11)
3549 //
3550 void HUD_DrawPressedKeys(void)
3551 {
3552         float id = 11;
3553         vector pos, mySize;
3554         pos = HUD_Panel_GetPos(id);
3555         mySize = HUD_Panel_GetSize(id);
3556
3557         HUD_Panel_DrawBg(id, pos, mySize);
3558         float padding;
3559         padding = HUD_Panel_GetPadding(id);
3560         if(padding)
3561         {
3562                 pos += '1 1 0' * padding;
3563                 mySize -= '2 2 0' * padding;
3564         }
3565
3566         float pressedkeys;
3567
3568         pressedkeys = getstatf(STAT_PRESSED_KEYS);
3569         drawpic_skin(pos, "key_bg.tga",           mySize, '1 1 1', 0.1 * hud_alpha_fg, DRAWFLAG_NORMAL);
3570         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_alpha_fg, DRAWFLAG_NORMAL);
3571         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_alpha_fg, DRAWFLAG_NORMAL);
3572         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_alpha_fg, DRAWFLAG_NORMAL);
3573         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_alpha_fg, DRAWFLAG_NORMAL);
3574         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_alpha_fg, DRAWFLAG_NORMAL);
3575         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_alpha_fg, DRAWFLAG_NORMAL);
3576 }
3577
3578 /*
3579 ==================
3580 Main HUD system
3581 ==================
3582 */
3583
3584 void HUD_ShowSpeed(void)
3585 {
3586         vector numsize;
3587         float pos, conversion_factor;
3588         string speed, zspeed, unit;
3589
3590         switch(cvar("cl_showspeed_unit"))
3591         {
3592                 default:
3593                 case 0:
3594                         unit = "";
3595                         conversion_factor = 1.0;
3596                         break;
3597                 case 1:
3598                         unit = " qu/s";
3599                         conversion_factor = 1.0;
3600                         break;
3601                 case 2:
3602                         unit = " m/s";
3603                         conversion_factor = 0.0254;
3604                         break;
3605                 case 3:
3606                         unit = " km/h";
3607                         conversion_factor = 0.0254 * 3.6;
3608                         break;
3609                 case 4:
3610                         unit = " mph";
3611                         conversion_factor = 0.0254 * 3.6 * 0.6213711922;
3612                         break;
3613                 case 5:
3614                         unit = " knots";
3615                         conversion_factor = 0.0254 * 1.943844492; // 1 m/s = 1.943844492 knots, because 1 knot = 1.852 km/h
3616                         break;
3617         }
3618
3619         speed = strcat(ftos(floor( vlen(pmove_vel - pmove_vel_z * '0 0 1') * conversion_factor + 0.5 )), unit);
3620
3621         numsize_x = numsize_y = cvar("cl_showspeed_size");
3622         pos = (vid_conheight - numsize_y) * cvar("cl_showspeed_position");
3623
3624         drawfont = hud_bigfont;
3625         drawstringcenter(eX + pos * eY, speed, numsize, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
3626
3627         if (cvar("cl_showspeed_z") == 1) {
3628                 zspeed = strcat(ftos(fabs(floor( pmove_vel_z * conversion_factor + 0.5 ))), unit);
3629                 drawstringcenter(eX + pos * eY + numsize_y * eY, zspeed, numsize * 0.5, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
3630         }
3631
3632         drawfont = hud_font;
3633 }
3634
3635 vector acc_prevspeed;
3636 float acc_prevtime;
3637 float acc_avg;
3638
3639 void HUD_ShowAcceleration(void)
3640 {
3641         float acceleration, sz, scale, alpha, f;
3642         vector pos, top, rgb;
3643         top_x = vid_conwidth/2;
3644         top_y = 0;
3645
3646         f = time - acc_prevtime;
3647         if(cvar("cl_showacceleration_z"))
3648                 acceleration = (vlen(pmove_vel) - vlen(acc_prevspeed)) * (1 / f);
3649         else
3650                 acceleration = (vlen(pmove_vel - '0 0 1' * pmove_vel_z) - vlen(acc_prevspeed - '0 0 1' * acc_prevspeed_z)) * (1 / f);
3651         acc_prevspeed = pmove_vel;
3652         acc_prevtime = time;
3653
3654         f = bound(0, f * 10, 1);
3655         acc_avg = acc_avg * (1 - f) + acceleration * f;
3656         acceleration = acc_avg / getstatf(STAT_MOVEVARS_MAXSPEED);
3657
3658         pos = top - sz/2 * eY + (cvar("cl_showacceleration_position") * vid_conheight) * eY;
3659
3660         sz = cvar("cl_showacceleration_size");
3661         scale = cvar("cl_showacceleration_scale");
3662         alpha = cvar("cl_showacceleration_alpha");
3663         if (cvar("cl_showacceleration_color_custom"))
3664                 rgb = stov(cvar_string("cl_showacceleration_color"));
3665         else {
3666                 rgb = '1 1 1';
3667                 if (acceleration < 0) {
3668                         rgb = '1 .5 .5' - '0 .5 .5' * bound(0, -acceleration * 0.2, 1);
3669                 } else if (acceleration > 0) {
3670                         rgb = '.5 1 .5' - '.5 0 .5' * bound(0, +acceleration * 0.2, 1);
3671                 }
3672         }
3673
3674         if (acceleration > 0)
3675                 HUD_Panel_DrawProgressBar(pos, 0, acceleration * scale * '40 0 0' + sz * eY, rgb, alpha * hud_alpha_fg, DRAWFLAG_NORMAL);
3676         else if (acceleration < 0)
3677                 HUD_Panel_DrawProgressBar(pos + acceleration * scale * '40 0 0', 0, -acceleration * scale * '40 0 0' + sz * eY, rgb, alpha * hud_alpha_fg, DRAWFLAG_NORMAL);
3678 }
3679
3680 void HUD_Reset (void)
3681 {
3682         // reset gametype specific icons
3683         if(gametype == GAME_KEYHUNT)
3684                 HUD_Mod_KH_Reset();
3685         else if(gametype == GAME_CTF)
3686                 HUD_Mod_CTF_Reset();
3687 }
3688
3689 void HUD_Main (void)
3690 {
3691         hud_alpha_bg = cvar_or("hud_bg_alpha", 0.8) * (1 - cvar("_menu_alpha"));
3692         hud_border_thickness = bound(0, cvar("hud_border_thickness"), 5);
3693         hud_accuracy_border_thickness = bound(0, cvar_or("hud_accuracy_border_thickness", 1), 5);
3694         hud_color_bg_team = cvar("hud_color_bg_team");
3695
3696         hud_fontsize = HUD_GetFontsize("hud_fontsize");
3697         hud_fontsize_spec = HUD_GetFontsize("hud_fontsize_spec");
3698
3699         hud_configure = cvar("_hud_configure");
3700
3701         // Drawing stuff
3702
3703         // HUD configure visible grid
3704         if(hud_configure && cvar("hud_configure_grid") && cvar("hud_configure_grid_alpha"))
3705         {
3706                 float i;
3707                 // x-axis
3708                 for(i = 0; i < vid_conwidth/cvar("hud_configure_grid_x"); ++i)
3709                 {
3710                         drawfill(eX * i * cvar("hud_configure_grid_x"), eX + eY * vid_conheight, '0.5 0.5 0.5', cvar("hud_configure_grid_alpha"), DRAWFLAG_NORMAL);
3711                 }
3712                 // y-axis
3713                 for(i = 0; i < vid_conheight/cvar("hud_configure_grid_y"); ++i)
3714                 {
3715                         drawfill(eY * i * cvar("hud_configure_grid_y"), eY + eX * vid_conwidth, '0.5 0.5 0.5', cvar("hud_configure_grid_alpha"), DRAWFLAG_NORMAL);
3716                 }
3717         }
3718
3719         if(cvar_string("hud_dock") != "")
3720                 drawpic_skin('0 0 0', cvar_string("hud_dock"), eX * vid_conwidth + eY * vid_conheight, HUD_Panel_Dock_GetColor(), cvar("hud_dock_alpha"), DRAWFLAG_NORMAL);
3721
3722         if(HUD_Panel_CheckActive(0))
3723                 HUD_WeaponIcons();
3724         if(HUD_Panel_CheckActive(1))
3725                 HUD_Inventory();
3726         if(HUD_Panel_CheckActive(2))
3727                 HUD_Powerups();
3728         if(HUD_Panel_CheckActive(3))
3729                 HUD_HealthArmor();
3730         if(HUD_Panel_CheckActive(4))
3731                 HUD_Notify();
3732         if(HUD_Panel_CheckActive(5))
3733                 HUD_Timer();
3734         // TODO hud'ify
3735         if(HUD_Panel_CheckActive(6))
3736                 if(cvar_string("hud_radar") != "0" && (cvar("hud_radar") == 2 || teamplay))
3737                         HUD_Radar();
3738         if(HUD_Panel_CheckActive(7))
3739                 HUD_Score();
3740         if(HUD_Panel_CheckActive(8))
3741                 if(gametype == GAME_RACE || gametype == GAME_CTS || hud_configure)
3742                         HUD_RaceTimer();
3743         if(HUD_Panel_CheckActive(9))
3744                 HUD_VoteWindow();
3745         if(HUD_Panel_CheckActive(10))
3746                 HUD_ModIcons();
3747         // TODO hud'ify
3748         if(HUD_Panel_CheckActive(11))
3749                 if(spectatee_status > 0 || cvar("hud_pressedkeys") >= 2 || hud_configure)
3750                         HUD_DrawPressedKeys();
3751
3752         // TODO hud_'ify these
3753         if (cvar("cl_showspeed"))
3754                 HUD_ShowSpeed();
3755         if (cvar("cl_showacceleration"))
3756                 HUD_ShowAcceleration();
3757 }