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