]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud.qc
s/cvar("_hud_configure")/hud_configure
[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 // return HUD background color
79 vector HUD_GetBgColor()
80 {
81         vector color;
82         if (teamplay)
83                 GetTeamRGB(myteam) * hud_color_bg_team;
84         else {
85                 // allow custom HUD colors in non-teamgames
86                 color_x = cvar("hud_color_bg_r");
87                 color_y = cvar("hud_color_bg_g");
88                 color_z = cvar("hud_color_bg_b");
89         }
90         return color;
91 }
92
93 // return accuracy text color
94 vector HUD_AccuracyColor(float accuracy)
95 {
96         vector rgb;
97         float yellow_accuracy = cvar("hud_accuracy_yellow"); // value at which this function returns yellow
98         if(accuracy >= 100) {
99                 rgb_x = 0;
100                 rgb_y = 1;
101         }
102         else if(accuracy > yellow_accuracy) {
103                 rgb_x = 1 - (accuracy-yellow_accuracy)/(100-yellow_accuracy); // red value between 1 -> 0
104                 rgb_y = 1;
105         }
106         else {
107                 rgb_x = 1;
108                 rgb_y = accuracy/yellow_accuracy; // green value between 0 -> 1
109         }
110         rgb_z = 0;
111         return rgb;
112 }
113
114 // draw number in the XSCALE font
115 void HUD_DrawXNum (vector pos, float num, float digits, float showsign, float lettersize, vector rgb, float highlighted, float stroke, float alpha, float dflags)
116 {
117         float l, i;
118         string str, tmp, l_length;
119         float minus, plus;
120         vector vsize, num_color;
121
122         vsize_x = vsize_y = lettersize;
123         vsize_z = 0;
124
125         // showsign 1: always prefix with minus sign (useful in race distribution display)
126         // showsign 2: always prefix with plus sign (useful in race distribution display)
127         // showsign 3: prefix with minus sign if negative, plus sign if positive (useful in score distribution display)
128
129         if((showsign == 2 && num >= 0) || (num > 0 && showsign == 3))
130         {
131                 plus = true;
132                 pos_x -= lettersize;
133         } else
134                 plus = false;
135
136         if(num < 0 || (num < 0 && showsign == 3) || (showsign == 1 && num <= 0))
137         {
138                 minus = true;
139                 num = -num;
140                 pos_x -= lettersize;
141         } else
142                 minus = false;
143
144         if(digits < 0)
145         {
146                 tmp = ftos(num);
147                 digits = -digits;
148                 str = strcat(substring("0000000000", 0, digits - strlen(tmp)), tmp);
149         } else
150                 str = ftos(num);
151
152         l = strlen(str);
153         l_length = ftos(l);
154
155         if(l > digits)
156         {
157                 str = substring(str, l-digits, 999);
158                 l = strlen(str);
159         } else if(l < digits)
160                 pos_x += (digits-l) * lettersize;
161
162         if (highlighted == 1) {
163                 vector hl_size;
164                 hl_size_x = vsize_x * l + vsize_x * 0.2;
165                 hl_size_y = vsize_y * 1.1;
166                 hl_size_z = 0;
167                 if(minus)
168                         hl_size_x = hl_size_x + vsize_x;
169
170                 vector hl_pos;
171                 hl_pos_x = pos_x - lettersize/10;
172                 hl_pos_y = pos_y - lettersize/20;
173                 hl_pos_z = 0;
174
175                 drawpic(hl_pos, strcat("gfx/hud/sb_highlight_", l_length), hl_size, '1 1 1', alpha, dflags);
176         }
177
178         if (stroke == 1)
179                 num_color = '1 1 1';
180         else
181                 num_color = rgb;
182
183         if(minus)
184         {
185                 if (stroke == 1)
186                         drawpic(pos, "gfx/hud/num_minus_stroke", vsize, rgb, alpha, dflags);
187                 drawpic(pos, "gfx/hud/num_minus", vsize, num_color, alpha, dflags);
188                 pos_x += lettersize;
189         } else if(plus)
190         {
191                 if (stroke == 1)
192                         drawpic(pos, "gfx/hud/num_plus_stroke", vsize, rgb, alpha, dflags);
193                 drawpic(pos, "gfx/hud/num_plus", vsize, num_color, alpha, dflags);
194                 pos_x += lettersize;
195         }
196
197         for(i = 0; i < l; ++i)
198         {
199                 tmp = substring(str, i, 1);
200                 if (stroke == 1)
201                         drawpic(pos, strcat("gfx/hud/num_", tmp, "_stroke"), vsize, rgb, alpha, dflags);
202                 drawpic(pos, strcat("gfx/hud/num_", tmp), vsize, num_color, alpha, dflags);
203                 pos_x += lettersize;
204         }
205 }
206
207 // color the number differently based on how big it is (used in the health/armor panel)
208 void HUD_DrawXNum_Colored (vector pos, float x, float digits, float lettersize, float alpha)
209 {
210         vector color;
211         if(x > 200) {
212                 color_x = 0;
213                 color_y = 1;
214                 color_z = 0;
215         }
216         else if(x > 150) {
217                 color_x = 0.4 - (x-150)*0.02 * 0.4; //red value between 0.4 -> 0
218                 color_y = 0.9 + (x-150)*0.02 * 0.1; // green value between 0.9 -> 1
219                 color_z = 0;
220         }
221         else if(x > 100) {
222                 color_x = 1 - (x-100)*0.02 * 0.6; //red value between 1 -> 0.4
223                 color_y = 1 - (x-100)*0.02 * 0.1; // green value between 1 -> 0.9
224                 color_z = 1 - (x-100)*0.02; // blue value between 1 -> 0
225         }
226         else if(x > 50) {
227                 color_x = 1;
228                 color_y = 1;
229                 color_z = 0.2 + (x-50)*0.02 * 0.8; // blue value between 0.2 -> 1
230         }
231         else if(x > 20) {
232                 color_x = 1;
233                 color_y = (x-20)*90/27/100; // green value between 0 -> 1
234                 color_z = (x-20)*90/27/100 * 0.2; // blue value between 0 -> 0.2
235         }
236         else {
237                 color_x = 1;
238                 color_y = 0;
239                 color_z = 0;
240         }
241         HUD_DrawXNum(pos, x, digits, 0, lettersize, color, 0, 0, alpha, DRAWFLAG_NORMAL);
242 }
243
244 float stringwidth_colors(string s, vector theSize)
245 {
246         return stringwidth(s, TRUE, theSize);
247 }
248
249 float stringwidth_nocolors(string s, vector theSize)
250 {
251         return stringwidth(s, FALSE, theSize);
252 }
253
254 #define CENTERPRINT_MAX_LINES 30
255 string centerprint_messages[CENTERPRINT_MAX_LINES];
256 float centerprint_width[CENTERPRINT_MAX_LINES];
257 vector centerprint_start;
258 float centerprint_expire;
259 float centerprint_num;
260 float centerprint_offset_hint;
261 vector centerprint_fontsize;
262
263 void centerprint(string strMessage)
264 {
265         float i, j, n, hcount;
266         string s;
267
268         centerprint_fontsize = HUD_GetFontsize("scr_centersize");
269
270         centerprint_expire = min(centerprint_expire, time); // if any of the returns happens, this message will fade out
271
272         if(cvar("scr_centertime") <= 0)
273                 return;
274
275         if(strMessage == "")
276                 return;
277
278         // strip trailing newlines
279         j = strlen(strMessage) - 1;
280         while(substring(strMessage, j, 1) == "\n" && j >= 0)
281                 j = j - 1;
282         strMessage = substring(strMessage, 0, j + 1);
283
284         if(strMessage == "")
285                 return;
286
287         // strip leading newlines and remember them, they are a hint that the message should be lower on the screen
288         j = 0;
289         while(substring(strMessage, j, 1) == "\n" && j < strlen(strMessage))
290                 j = j + 1;
291         strMessage = substring(strMessage, j, strlen(strMessage) - j);
292         centerprint_offset_hint = j;
293
294         if(strMessage == "")
295                 return;
296
297         // if we get here, we have a message. Initialize its height.
298         centerprint_num = 0;
299
300         n = tokenizebyseparator(strMessage, "\n");
301         i = hcount = 0;
302         for(j = 0; j < n; ++j)
303         {
304                 getWrappedLine_remaining = argv(j);
305                 while(getWrappedLine_remaining)
306                 {
307                         s = getWrappedLine(vid_conwidth * 0.75, centerprint_fontsize, stringwidth_colors);
308                         if(centerprint_messages[i])
309                                 strunzone(centerprint_messages[i]);
310                         centerprint_messages[i] = strzone(s);
311                         centerprint_width[i] = stringwidth(s, TRUE, centerprint_fontsize);
312                         ++i;
313
314                         // half height for empty lines looks better
315                         if(s == "")
316                                 hcount += 0.5;
317                         else
318                                 hcount += 1;
319
320                         if(i >= CENTERPRINT_MAX_LINES)
321                                 break;
322                 }
323         }
324
325         float h, havail;
326         h = centerprint_fontsize_y*hcount;
327
328         havail = vid_conheight;
329         if(cvar("con_chatpos") < 0)
330                 havail -= (-cvar("con_chatpos") + cvar("con_chat")) * cvar("con_chatsize"); // avoid overlapping chat
331         if(havail > vid_conheight - 70)
332                 havail = vid_conheight - 70; // avoid overlapping HUD
333
334         centerprint_start_x = 0;
335
336 #if 0
337         float forbiddenmin, forbiddenmax, allowedmin, allowedmax, preferred;
338
339         // here, the centerprint would cover the crosshair. REALLY BAD.
340         forbiddenmin = vid_conheight * 0.5 - h - 16;
341         forbiddenmax = vid_conheight * 0.5 + 16;
342
343         allowedmin = scoreboard_bottom;
344         allowedmax = havail - h;
345         preferred = (havail - h)/2;
346
347
348         // possible orderings (total: 4! / 4 = 6)
349         //  allowedmin allowedmax forbiddenmin forbiddenmax
350         //  forbiddenmin forbiddenmax allowedmin allowedmax
351         if(allowedmax < forbiddenmin || allowedmin > forbiddenmax)
352         {
353                 // forbidden doesn't matter in this case
354                 centerprint_start_y = bound(allowedmin, preferred, allowedmax);
355         }
356         //  allowedmin forbiddenmin allowedmax forbiddenmax
357         else if(allowedmin < forbiddenmin && allowedmax < forbiddenmax)
358         {
359                 centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
360         }
361         //  allowedmin forbiddenmin forbiddenmax allowedmax
362         else if(allowedmin < forbiddenmin)
363         {
364                 // make sure the forbidden zone is not covered
365                 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
366                         centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
367                 else
368                         centerprint_start_y = bound(forbiddenmax, preferred, allowedmin);
369         }
370         //  forbiddenmin allowedmin allowedmax forbiddenmax
371         else if(allowedmax < forbiddenmax)
372         {
373                 // it's better to leave the allowed zone (overlap with scoreboard) than
374                 // to cover the forbidden zone (crosshair)
375                 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
376                         centerprint_start_y = forbiddenmax;
377                 else
378                         centerprint_start_y = forbiddenmin;
379         }
380         //  forbiddenmin allowedmin forbiddenmax allowedmax
381         else
382         {
383                 centerprint_start_y = bound(forbiddenmax, preferred, allowedmax);
384         }
385 #else
386         centerprint_start_y =
387                 min(
388                         max(
389                                 max(scoreboard_bottom, vid_conheight * 0.5 + 16),
390                                 (havail - h)/2
391                         ),
392                         havail - h
393                 );
394 #endif
395
396         centerprint_num = i;
397         centerprint_expire = time + cvar("scr_centertime");
398 }
399
400 void HUD_DrawCenterPrint (void)
401 {
402         float i;
403         vector pos;
404         string ts;
405         float a;
406
407         //if(time > centerprint_expire)
408         //      return;
409
410         //a = bound(0, 1 - 2 * (time - centerprint_expire), 1);
411         a = bound(0, 1 - 4 * (time - centerprint_expire), 1);
412         //sz = 1.2 / (a + 0.2);
413
414         if(a <= 0)
415                 return;
416
417         pos = centerprint_start;
418         for (i=0; i<centerprint_num; i = i + 1)
419         {
420                 pos_x = (vid_conwidth - centerprint_width[i]) * 0.5;
421                 ts = centerprint_messages[i];
422                 if (ts != "")
423                 {
424                         dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
425                         drawcolorcodedstring(pos, ts, centerprint_fontsize, a, DRAWFLAG_NORMAL);
426                         //  - '0 0.5 0' * (sz - 1) * centerprint_fontsize_x - '0.5 0 0' * (sz - 1) * centerprint_width[i] * centerprint_fontsize_y, centerprint_fontsize * sz
427                         pos_y = pos_y + centerprint_fontsize_y;
428                 }
429                 else
430                         // half height for empty lines looks better
431                         pos_y = pos_y + centerprint_fontsize_y * 0.5;
432         }
433 }
434
435 void drawstringright(vector position, string text, vector scale, vector rgb, float alpha, float flag)
436 {
437         position_x -= 2 / 3 * strlen(text) * scale_x;
438         drawstring(position, text, scale, rgb, alpha, flag);
439 }
440
441 void drawstringcenter(vector position, string text, vector scale, vector rgb, float alpha, float flag)
442 {
443         position_x = 0.5 * (vid_conwidth - 0.6025 * strlen(text) * scale_x);
444         drawstring(position, text, scale, rgb, alpha, flag);
445 }
446
447 // return the string of the given race place
448 string race_PlaceName(float pos) {
449         if(pos == 1)
450                 return "1st";
451         else if(pos == 2)
452                 return "2nd";
453         else if(pos == 3)
454                 return "3rd";
455         else
456                 return strcat(ftos(pos), "th");
457 }
458
459 // return the string of the onscreen race timer
460 string MakeRaceString(float cp, float mytime, float histime, float lapdelta, string hisname)
461 {
462         string col;
463         string timestr;
464         string cpname;
465         string lapstr;
466         lapstr = "";
467
468         if(histime == 0) // goal hit
469         {
470                 if(mytime > 0)
471                 {
472                         timestr = strcat("+", ftos_decimals(+mytime, TIME_DECIMALS));
473                         col = "^1";
474                 }
475                 else if(mytime == 0)
476                 {
477                         timestr = "+0.0";
478                         col = "^3";
479                 }
480                 else
481                 {
482                         timestr = strcat("-", ftos_decimals(-mytime, TIME_DECIMALS));
483                         col = "^2";
484                 }
485
486                 if(lapdelta > 0)
487                 {
488                         lapstr = strcat(" (-", ftos(lapdelta), "L)");
489                         col = "^2";
490                 }
491                 else if(lapdelta < 0)
492                 {
493                         lapstr = strcat(" (+", ftos(-lapdelta), "L)");
494                         col = "^1";
495                 }
496         }
497         else if(histime > 0) // anticipation
498         {
499                 if(mytime >= histime)
500                         timestr = strcat("+", ftos_decimals(mytime - histime, TIME_DECIMALS));
501                 else
502                         timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(histime));
503                 col = "^3";
504         }
505         else
506                 col = "^7";
507
508         if(cp == 254)
509                 cpname = "Start line";
510         else if(cp == 255)
511                 cpname = "Finish line";
512         else if(cp)
513                 cpname = strcat("Intermediate ", ftos(cp));
514         else
515                 cpname = "Finish line";
516
517         if(histime < 0)
518                 return strcat(col, cpname);
519         else if(hisname == "")
520                 return strcat(col, cpname, " (", timestr, ")");
521         else
522                 return strcat(col, cpname, " (", timestr, " ", strcat(hisname, col, lapstr), ")");
523 }
524
525 // Check if the given name already exist in race rankings? In that case, where? (otherwise return 0)
526 float race_CheckName(string net_name) {
527         float i;
528         for (i=RANKINGS_CNT-1;i>=0;--i)
529                 if(grecordholder[i] == net_name)
530                         return i+1;
531         return 0;
532 }
533
534 /*
535 ==================
536 HUD panels
537 ==================
538 */
539
540 string HUD_Panel_GetName(float id)
541 {
542         switch(id) {
543                 case 0: return "weaponicons"; break;
544                 case 1: return "inventory"; break;
545                 case 2: return "powerups"; break;
546                 case 3: return "healtharmor"; break;
547                 case 4: return "notify"; break;
548                 case 5: return "timer"; break;
549                 case 6: return "radar"; break;
550                 case 7: return "score"; break;
551                 case 8: return "racetimer"; break;
552                 case 9: return "vote"; break;
553                 case 10: return "pressedkeys"; break;
554                 default: return "";
555         }
556 }
557
558 // Save the config
559 void HUD_Panel_ExportCfg(string cfgname)
560 {
561         float fh;
562         fh = fopen(strcat("hud_", hud_skin, "_", cfgname, ".cfg"), FILE_WRITE);
563         if(fh >= 0)
564         {
565                 float i;
566                 for (i = 0; i < panel_cnt; ++i)
567                 {
568                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), " ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i))))));
569                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_pos \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_pos")), "\""));
570                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_size \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_size")), "\""));
571                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg")), "\""));
572                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_color \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg_color")), "\""));
573                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_alpha ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_bg_alpha")))));
574                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_border ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_bg_border")))));
575                         fputs(fh, "");
576                 }
577
578                 print("^2Successfully exported to hud_", hud_skin, "_", cfgname, ".cfg");
579         }
580         fclose(fh);
581 }
582
583 vector HUD_Panel_CheckLimitSize(float id, vector mySize)
584 {
585         switch(id) {
586                 case 0: 
587                         mySize_x = max(mySize_y * (1/10), mySize_x); // at least 1/10 * height
588                         mySize_y = max(mySize_x * (1/26), mySize_y); // at least 1/26 * width
589                         break;
590                 case 1: 
591                         mySize_x = max(mySize_y * 0.7, mySize_x); // at least 0.7 * height
592                         break;
593                 case 2: 
594                         mySize_x = max(mySize_y * 1.5, mySize_x); // at least 2 * height
595                         break;
596                 case 3: 
597                         mySize_x = max(mySize_y * 2, mySize_x); // at least 2 * height
598                         break;
599                 case 5: 
600                         mySize_x = max(mySize_y * 2, mySize_x); // at least 2 * height
601                         break;
602                 case 7: 
603                         mySize_y = (1/4) * mySize_x; // 1/4 * width
604                         break;
605                 case 8: 
606                         mySize_y = (1/4) * mySize_x; // 1/4 * width
607                         break;
608                 case 9: 
609                         mySize_y = (1/4) * mySize_x; // 1/4 * width
610                         break;
611                 case 10: 
612                         mySize_y = 0.5898 * mySize_x; // 0.5898 * width, reason: bg has weird dimensions...
613                         break;
614         }
615         return mySize;
616 }
617
618 // return active status of panel
619 float HUD_Panel_CheckActive(float id)
620 {
621         if (cvar_or(strcat("hud_", HUD_Panel_GetName(id)), 1))
622                 return 1;
623         return 0;
624 }
625
626 // return size of given panel
627 vector HUD_Panel_GetSize(float id)
628 {
629         vector mySize;
630         mySize = stov(cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_size")));
631
632         mySize = eX * mySize_x * vid_conwidth + eY * mySize_y * vid_conheight;
633
634         return mySize;
635 }
636
637 // return pos of given panel
638 vector HUD_Panel_GetPos(float id)
639 {
640         vector pos;
641         pos = stov(cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_pos")));
642
643         pos = eX * pos_x * vid_conwidth + eY * pos_y * vid_conheight;
644
645         if (pos_x < 0)
646                 pos_x = vid_conwidth + pos_x;
647         if (pos_y < 0)
648                 pos_y = vid_conheight + pos_y;
649         return pos;
650 }
651
652 float HUD_Panel_GetBorder(float id)
653 {
654         float border;
655         border = cvar(strcat("hud_", HUD_Panel_GetName(id), "_bg_border"));
656         if(!border)
657                 border = cvar("hud_bg_border");
658         return border;
659 }
660
661 // draw the background/borders
662 void HUD_Panel_DrawBg(float id, vector pos, vector mySize)
663 {
664         if(!hud_configure && cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg")) == "0")
665                 return;
666
667         string bg;
668         bg = cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg"));
669         if(bg == "")
670                 bg = cvar_string("hud_bg");
671
672         if(bg != "0")
673         {
674                 float border;
675                 border = HUD_Panel_GetBorder(id);
676
677                 vector color;
678                 if(cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_color")) != "")
679                         color = stov(cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_color")));
680                 else
681                         color = stov(cvar_string("hud_bg_color"));
682
683                 float alpha;
684                 alpha = cvar(strcat("hud_", HUD_Panel_GetName(id), "_bg_alpha"));
685                 if(!alpha)
686                         alpha = cvar("hud_bg_alpha");
687                 if(hud_configure)
688                         alpha = max(cvar("hud_configure_bg_minalpha"), alpha);
689
690                 draw_BorderPicture(pos - '1 1 0' * border, strcat("gfx/hud/", bg), mySize + '1 1 0' * 2 * border, color, alpha, '1 1 0' * (border/BORDER_MULTIPLIER));
691         }
692 }
693
694 vector HUD_Panel_GetProgressBarColor(string item)
695 {
696         return stov(cvar_string(strcat("hud_progressbar_", item, "_color")));
697 }
698
699 float resizeCorner; // 1 = topleft, 2 = topright, 3 = bottomleft, 4 = bottomright
700 // check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
701 vector HUD_Panel_CheckResize(float id, vector myPos, vector mySize)
702 {
703         float i;
704
705         vector myTarget;
706         myTarget = mySize;
707
708         vector targPos;
709         vector targSize;
710         vector myCenter;
711         vector targCenter;
712
713         for (i = 0; i < panel_cnt; ++i) {
714                 if(i == id || !HUD_Panel_CheckActive(i))
715                         continue;
716
717                 targPos = HUD_Panel_GetPos(i);
718                 targSize = HUD_Panel_GetSize(i);
719
720                 targPos = HUD_Panel_GetPos(i) - '1 1 0' * HUD_Panel_GetBorder(id);
721                 targSize = HUD_Panel_GetSize(i) + '2 2 0' * HUD_Panel_GetBorder(id);
722
723                 if(myPos_y + mySize_y < targPos_y)
724                         continue;
725                 if(myPos_y > targPos_y + targSize_y)
726                         continue;
727
728                 if(myPos_x + mySize_x < targPos_x)
729                         continue;
730                 if(myPos_x > targPos_x + targSize_x)
731                         continue;
732
733                 // OK, there IS a collision.
734
735                 myCenter_x = myPos_x + 0.5 * mySize_x;
736                 myCenter_y = myPos_y + 0.5 * mySize_y;
737
738                 targCenter_x = targPos_x + 0.5 * targSize_x;
739                 targCenter_y = targPos_y + 0.5 * targSize_y;
740
741                 float k, y;
742                 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y && resizeCorner != 1) // top left (of target panel)
743                 {
744                         if(myPos_x + mySize_x - targPos_x < myPos_y + mySize_y - targPos_y) // push it to the side
745                                 myTarget_x = targPos_x - myPos_x;
746                         else // push it upwards
747                                 myTarget_y = targPos_y - myPos_y;
748                 }
749                 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y && resizeCorner != 2) // top right
750                 {
751                         if(targPos_x + targSize_x - myPos_x < myPos_y + mySize_y - targPos_y) // push it to the side
752                                 myTarget_x = targPos_x + targSize_x;
753                         else // push it upwards
754                                 myTarget_y = targPos_y - myPos_y;
755                 }
756                 else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
757                 {
758                         if(myPos_x + mySize_x - targPos_x < targPos_y + targSize_y - myPos_y) // push it to the side
759                                 myTarget_x = targPos_x - myPos_x;
760                         else // push it downwards
761                                 myTarget_y = targPos_y + targSize_y;
762                 }
763                 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
764                 {
765                         if(targPos_x + targSize_x - myPos_x < targPos_y + targSize_y - myPos_y) // push it to the side
766                                 myTarget_x = targPos_x + targSize_x;
767                         else // push it downwards
768                                 myTarget_y = targPos_y + targSize_y;
769                 }
770         }
771
772         return myTarget;
773 }
774
775 // TODO: checkResize
776 float HUD_Panel_SetSize(float id, vector mySize)
777 {
778         float didntresize;
779
780         vector oldSize;
781         oldSize = stov(cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_size")));
782
783         vector myPos;
784         myPos = HUD_Panel_GetPos(id);
785
786         // check for collisions
787         if(cvar("hud_configure_checkcollisions"))
788                 mySize = HUD_Panel_CheckResize(id, HUD_Panel_GetPos(id), mySize);
789
790         mySize_x = bound(0.025 * vid_conwidth, mySize_x, vid_conwidth - myPos_x);
791         mySize_y = bound(0.025 * vid_conheight, mySize_y, vid_conheight - myPos_y);
792
793         // cap against panel's own limits
794         mySize = HUD_Panel_CheckLimitSize(id, mySize);
795
796         //mySize_x = bound(0.025 * vid_conwidth, mySize_x, vid_conwidth);
797         //mySize_y = bound(0.025 * vid_conheight, mySize_y, vid_conheight);
798
799         // TODO: is this needed?
800         // this is to check if (and how) SetPos should be called
801         if(mySize_x == oldSize_x && mySize_y == oldSize_y)
802                 didntresize = 3; // didnt resize either
803         else if(mySize_x == oldSize_x && mySize_y != oldSize_y)
804                 didntresize = 2; // resized Y
805         else if(mySize_y == oldSize_y && mySize_x != oldSize_x)
806                 didntresize = 1; // resized X
807
808         string s;
809         s = strcat(ftos(mySize_x/vid_conwidth), " ", ftos(mySize_y/vid_conheight));
810         cvar_set(strcat("hud_", HUD_Panel_GetName(id), "_size"), s);
811         return didntresize;
812 }
813
814 // check if move will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
815 vector HUD_Panel_CheckMove(float id, vector myPos, vector mySize)
816 {
817         float i;
818
819         vector myTarget;
820         myTarget = myPos;
821
822         vector targPos;
823         vector targSize;
824         vector myCenter;
825         vector targCenter;
826
827         for (i = 0; i < panel_cnt; ++i) {
828                 if(i == id || !HUD_Panel_CheckActive(i))
829                         continue;
830
831                 targPos = HUD_Panel_GetPos(i) - '1 1 0' * HUD_Panel_GetBorder(id);
832                 targSize = HUD_Panel_GetSize(i) + '2 2 0' * HUD_Panel_GetBorder(id);
833
834                 if(myPos_y + mySize_y < targPos_y)
835                         continue;
836                 if(myPos_y > targPos_y + targSize_y)
837                         continue;
838
839                 if(myPos_x + mySize_x < targPos_x)
840                         continue;
841                 if(myPos_x > targPos_x + targSize_x)
842                         continue;
843
844                 // OK, there IS a collision.
845
846                 myCenter_x = myPos_x + 0.5 * mySize_x;
847                 myCenter_y = myPos_y + 0.5 * mySize_y;
848
849                 targCenter_x = targPos_x + 0.5 * targSize_x;
850                 targCenter_y = targPos_y + 0.5 * targSize_y;
851
852                 float k, y;
853                 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // top left (of the target panel)
854                 {
855                         if(myPos_x + mySize_x - targPos_x < myPos_y + mySize_y - targPos_y) // push it to the side
856                                 myTarget_x = targPos_x - mySize_x;
857                         else // push it upwards
858                                 myTarget_y = targPos_y - mySize_y;
859                 }
860                 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y) // top right
861                 {
862                         if(targPos_x + targSize_x - myPos_x < myPos_y + mySize_y - targPos_y) // push it to the side
863                                 myTarget_x = targPos_x + targSize_x;
864                         else // push it upwards
865                                 myTarget_y = targPos_y - mySize_y;
866                 }
867                 else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
868                 {
869                         if(myPos_x + mySize_x - targPos_x < targPos_y + targSize_y - myPos_y) // push it to the side
870                                 myTarget_x = targPos_x - mySize_x;
871                         else // push it downwards
872                                 myTarget_y = targPos_y + targSize_y;
873                 }
874                 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
875                 {
876                         if(targPos_x + targSize_x - myPos_x < targPos_y + targSize_y - myPos_y) // push it to the side
877                                 myTarget_x = targPos_x + targSize_x;
878                         else // push it downwards
879                                 myTarget_y = targPos_y + targSize_y;
880                 }
881         }
882
883         return myTarget;
884 }
885
886 void HUD_Panel_SetPos(float id, vector pos, float didntresize)
887 {
888         vector oldPos;
889         oldPos = HUD_Panel_GetPos(id);
890         if(didntresize == 2)
891                 pos_x = oldPos_x;
892         else if(didntresize == 1)
893                 pos_y = oldPos_y;
894         else if(didntresize == 3)
895                 return;
896
897         vector mySize;
898         mySize = HUD_Panel_GetSize(id);
899
900         if(cvar("hud_configure_checkcollisions"))
901                 pos = HUD_Panel_CheckMove(id, pos, mySize);
902
903         pos_x = bound(0, pos_x, vid_conwidth - mySize_x);
904         pos_y = bound(0, pos_y, vid_conheight - mySize_y);
905
906         if (pos_x + 0.5 * mySize_x > 0.5 * vid_conwidth)
907                 pos_x = pos_x - vid_conwidth;
908         if (pos_y + 0.5 * mySize_y > 0.5 * vid_conheight)
909                 pos_y = pos_y - vid_conheight;
910
911         string s;
912         s = strcat(ftos(pos_x/vid_conwidth), " ", ftos(pos_y/vid_conheight));
913
914         cvar_set(strcat("hud_", HUD_Panel_GetName(id), "_pos"), s);
915 }
916
917 float mouseClicked;
918 float prevMouseClicked; // previous state
919 float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
920 {
921         prevMouseClicked = mouseClicked;
922         if(nPrimary == K_MOUSE1)
923         {
924                 if(bInputType == 0) { // key pressed
925                         mouseClicked = 1;
926                         return true;
927                 }
928                 if(bInputType == 1) {// key released
929                         mouseClicked = 0;
930                         return true;
931                 }
932         }
933         return false;
934 }
935
936 vector mousepos, mouseprevpos;
937 vector panel_click_distance; // mouse cursor distance from the top left corner of the panel (saved only upon a click)
938 vector panel_click_pos; // panel pos (saved only upon a click)
939 vector panel_click_size; // panel size (saved only upon a click)
940 float highlightedPanel;
941 float highlightedAction; // 0 = nothing, 1 = move, 2 = resize
942 void HUD_Panel_Mouse()
943 {
944         if(mouseClicked == 0) {
945                 highlightedPanel = -1;
946                 highlightedAction = 0;
947         }
948
949         mousepos = mousepos + getmousepos();
950
951         mousepos_x = bound(0, mousepos_x, vid_conwidth);
952         mousepos_y = bound(0, mousepos_y, vid_conheight);
953
954         drawpic(mousepos, "gfx/menu/default/cursor.tga", '32 32 0', '1 1 1', 1, hud_alpha_fg);
955
956         if(mouseClicked)
957         {
958                 float i, border;
959                 vector panelPos;
960                 vector panelSize;
961
962                 for(i = 0; i <= panel_cnt; ++i)
963                 {
964                         panelPos = HUD_Panel_GetPos(i);
965                         panelSize = HUD_Panel_GetSize(i);
966                         border = HUD_Panel_GetBorder(i);
967                         if(prevMouseClicked == 0) {
968                                 // move
969                                 if(mousepos_x >= panelPos_x && mousepos_y >= panelPos_y && mousepos_x <= panelPos_x + panelSize_x && mousepos_y <= panelPos_y + panelSize_y)
970                                 {
971                                         highlightedPanel = i;
972                                         highlightedAction = 1;
973                                 }
974                                 // resize from topleft border
975                                 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)
976                                 {
977                                         highlightedPanel = i;
978                                         highlightedAction = 2;
979                                         resizeCorner = 1;
980                                 }
981                                 // resize from topright border
982                                 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)
983                                 {
984                                         highlightedPanel = i;
985                                         highlightedAction = 2;
986                                         resizeCorner = 2;
987                                 }
988                                 // resize from bottomleft border
989                                 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)
990                                 {
991                                         highlightedPanel = i;
992                                         highlightedAction = 2;
993                                         resizeCorner = 3;
994                                 }
995                                 // resize from bottomright border
996                                 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)
997                                 {
998                                         highlightedPanel = i;
999                                         highlightedAction = 2;
1000                                         resizeCorner = 4;
1001                                 }
1002                         }
1003
1004                         if(highlightedPanel == i)
1005                         {
1006                                 if(prevMouseClicked == 0)
1007                                 {
1008                                         panel_click_distance = mousepos - panelPos;
1009                                         panel_click_pos = panelPos;
1010                                         panel_click_size = panelSize;
1011                                 }
1012
1013                                 if(highlightedAction == 1)
1014                                         HUD_Panel_SetPos(i, mousepos - panel_click_distance, 0);
1015                                 else if(highlightedAction == 2)
1016                                 {
1017                                         float didntresize; // panel too big/too small, dont resize (also has to affect moving)
1018                                         if(resizeCorner == 1) {
1019                                                 didntresize = HUD_Panel_SetSize(i, panelSize + mouseprevpos - mousepos);
1020                                                 HUD_Panel_SetPos(i, mousepos - panel_click_distance, didntresize);
1021                                         }
1022                                         if(resizeCorner == 2) {
1023                                                 didntresize = HUD_Panel_SetSize(i, eY * panel_click_size_y + eX * (mousepos_x - panelPos_x - (panel_click_distance_x - panel_click_size_x))
1024                                                                 + eY * (panel_click_distance_y + (panel_click_pos_y - mousepos_y)));
1025                                                 HUD_Panel_SetPos(i, eX * panelPos_x + eY * (mousepos_y - panel_click_distance_y), didntresize);
1026                                         }
1027                                         if(resizeCorner == 3) {
1028                                                 didntresize = HUD_Panel_SetSize(i, panelSize + eX * (mouseprevpos_x - mousepos_x) + eY * (mousepos_y - mouseprevpos_y));
1029                                                 HUD_Panel_SetPos(i, eX * (mousepos_x - panel_click_distance_x) + eY * panelPos_y, didntresize);
1030                                         }
1031                                         if(resizeCorner == 4) {
1032                                                 HUD_Panel_SetSize(i, mousepos - panelPos - (panel_click_distance - panel_click_size));
1033                                         }
1034                                 }
1035                         }
1036                 }
1037         }
1038         mouseprevpos = mousepos;
1039         prevMouseClicked = mouseClicked;
1040 }
1041
1042 /*void HUD_DrawDockEdge(float id, vector p1, vector p2, float target)
1043 {
1044         vector pos;
1045         vector size;
1046
1047         pos =
1048 */ // maybe one day, since this will be quite complicated
1049
1050 // Weapon icons (#0)
1051 //
1052
1053 float weaponspace[10];
1054 void HUD_WeaponIcons_Clear()
1055 {
1056         float idx;
1057         for(idx = 0; idx < 10; ++idx)
1058                 weaponspace[idx] = 0;
1059 }
1060
1061 entity weaponorder[WEP_MAXCOUNT];
1062
1063 void weaponorder_swap(float i, float j, entity pass)
1064 {
1065         entity h;
1066         h = weaponorder[i];
1067         weaponorder[i] = weaponorder[j];
1068         weaponorder[j] = h;
1069 }
1070
1071 float weaponorder_cmp(float i, float j, entity pass)
1072 {
1073         float d, ii, ij;
1074         d = mod(weaponorder[i].impulse + 9, 10) - mod(weaponorder[j].impulse + 9, 10);
1075         if(d)
1076                 return d;
1077         d = weaponorder[i].weapon - weaponorder[j].weapon;
1078         return d;
1079 }
1080
1081 void HUD_WeaponIcons()
1082 {
1083         float alpha, height, accuracybar_height, stat_weapons; // "constants"
1084         vector pos, mySize, mysize, mypos, accuracy_color;
1085         float i, id, fade, weapon_stats, weapon_hit, weapon_damage, weapon_cnt; // variables
1086
1087         pos = HUD_Panel_GetPos(0);
1088         mySize = HUD_Panel_GetSize(0);
1089         accuracybar_height = cvar_or("hud_weaponicons_accuracybar_height", 3);
1090
1091         stat_weapons = getstati(STAT_WEAPONS);
1092         for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1093         {
1094                 self = get_weaponinfo(i);
1095                 if(self.weapons && (self.impulse >= 0) && (stat_weapons & self.weapons) || hud_configure)
1096                 {
1097                         weaponorder[weapon_cnt] = self;
1098                         ++weapon_cnt;
1099                 }
1100         }
1101         heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, world);
1102
1103         HUD_Panel_DrawBg(0, pos, mySize);
1104
1105         // hits
1106         weapon_stats = getstati(STAT_DAMAGE_HITS);
1107         weapon_number = weapon_stats & 63;
1108         weapon_hits[weapon_number-WEP_FIRST] = floor(weapon_stats / 64);
1109         // fired
1110         weapon_stats = getstati(STAT_DAMAGE_FIRED);
1111         weapon_number = weapon_stats & 63;
1112         weapon_fired[weapon_number-WEP_FIRST] = floor(weapon_stats / 64);
1113
1114         if(cvar_or("hud_weaponicons_fade", 1))
1115         {
1116                 fade = 3.2 - 2 * (time - weapontime);
1117                 fade = bound(0.7, fade, 1);
1118         }
1119         else
1120                 fade = 1;
1121
1122         HUD_WeaponIcons_Clear();
1123
1124         float rows, columns;
1125         rows = mySize_y/mySize_x;
1126         rows = bound(1, floor((sqrt(4 * (2/1) * rows * WEP_COUNT + rows * rows) + rows + 0.5) / 2), WEP_COUNT);
1127         //                               ^^^ weapon icon aspect goes here
1128
1129         columns = ceil(WEP_COUNT/rows);
1130         float row, column;
1131         for(i = 0; i < weapon_cnt; ++i)
1132         {
1133                 self = weaponorder[i];
1134                 if((self.weapons && (self.impulse >= 0) && (stat_weapons & self.weapons)) || hud_configure)
1135                 {
1136                         id = self.impulse;
1137
1138                         alpha = (self.weapon == activeweapon) ? 1 : 0.6;
1139
1140                         weapon_hit = weapon_hits[self.weapon-WEP_FIRST];
1141                         weapon_damage = weapon_fired[self.weapon-WEP_FIRST];
1142
1143                         if(self.weapon == activeweapon)
1144                                 drawpic(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows), "gfx/hud/sb_ammobg", eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows), '1 1 1', fade * hud_alpha_fg, DRAWFLAG_NORMAL);
1145                         drawpic(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows), strcat("gfx/hud/inv_weapon", self.netname), eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows), '1 1 1', fade * hud_alpha_fg, DRAWFLAG_NORMAL);
1146
1147                         if(cvar_or("hud_weaponicons_number", 1))
1148                                 drawstring(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows), ftos(id), '1 1 0' * 0.5 * mySize_y*(1/rows), '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1149
1150                         // draw the weapon accuracy on the HUD
1151                         if(hud_accuracy_hud && !(gametype == GAME_RACE || gametype == GAME_CTS))
1152                         {
1153                                 if(weapon_damage)
1154                                         weapon_stats = floor(100 * weapon_hit / weapon_damage);
1155
1156                                 accuracy_color = HUD_AccuracyColor(weapon_stats);
1157                                 if(weapon_damage)
1158                                         drawpic(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows) - '2 0 0' + eY * (mySize_y/rows - accuracybar_height), "gfx/hud/sb_accuracy_bar.tga", eX * mySize_x*(1/columns) + eY * accuracybar_height, accuracy_color, hud_alpha_fg, DRAWFLAG_NORMAL);
1159                         }
1160                 }
1161
1162                 ++row;
1163                 if(row >= rows)
1164                 {
1165                         row = 0;
1166                         ++column;
1167                 }
1168         }
1169
1170 }
1171
1172 // Inventory (#1)
1173 //
1174
1175 float GetAmmoStat(float i)
1176 {
1177         switch(i)
1178         {
1179                 case 0: return STAT_SHELLS;
1180                 case 1: return STAT_NAILS;
1181                 case 2: return STAT_ROCKETS;
1182                 case 3: return STAT_CELLS;
1183                 case 4: return STAT_FUEL;
1184                 default: return -1;
1185         }
1186 }
1187
1188 float GetAmmoItemCode(float i)
1189 {
1190         switch(i)
1191         {
1192                 case 0: return IT_SHELLS;
1193                 case 1: return IT_NAILS;
1194                 case 2: return IT_ROCKETS;
1195                 case 3: return IT_CELLS;
1196                 case 4: return IT_FUEL;
1197                 default: return -1;
1198         }
1199 }
1200
1201 string GetAmmoPicture(float i)
1202 {
1203         switch(i)
1204         {
1205                 case 0: return "gfx/hud/sb_shells";
1206                 case 1: return "gfx/hud/sb_bullets";
1207                 case 2: return "gfx/hud/sb_rocket";
1208                 case 3: return "gfx/hud/sb_cells";
1209                 case 4: return "gfx/hud/sb_fuel";
1210                 default: return "";
1211         }
1212 }
1213
1214 void HUD_Inventory()
1215 {
1216         float i;
1217         float stat_items;
1218
1219         vector pos, mySize, mysize, mypos;
1220         pos = HUD_Panel_GetPos(1);
1221         mySize = HUD_Panel_GetSize(1);
1222
1223         HUD_Panel_DrawBg(1, pos, mySize);
1224
1225         // ammo
1226         stat_items = getstati(STAT_ITEMS);
1227         for (i = 0; i < 4; ++i) {
1228                 float a;
1229                 a = getstati(GetAmmoStat(i)); // how much ammo do we have of type i?
1230                 if(hud_configure)
1231                         a = 100;
1232
1233                 if(cvar("hud_inventory_onlycurrent")) {
1234                         if (stat_items & GetAmmoItemCode(i)) {
1235                                 drawpic(pos, "gfx/hud/sb_ammobg", mySize, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1236                                 drawpic(pos + eY * 0.05 * mySize_y, GetAmmoPicture(i), '1 1 0' * 0.8 * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1237                                 if(a < 10)
1238                                         HUD_DrawXNum(pos + 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);
1239                                 else
1240                                         HUD_DrawXNum(pos + 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);
1241                         }
1242                 } else {
1243                         if (a > 0) {
1244                                 if(mySize_x/mySize_y >= 10) { // arrange horizontally
1245                                         switch (i) {
1246                                                 case 0: mypos_x = pos_x;                        mypos_y = pos_y;                        break; // shells
1247                                                 case 1: mypos_x = pos_x + 0.25 * mySize_x;      mypos_y = pos_y;                        break; // bullets
1248                                                 case 2: mypos_x = pos_x + 0.5  * mySize_x;      mypos_y = pos_y;                        break; // rockets
1249                                                 case 3: mypos_x = pos_x + 0.75 * mySize_x;      mypos_y = pos_y;                        break; // cells
1250                                         }
1251                                         mysize_x = 0.25 * mySize_x;
1252                                         mysize_y = mySize_y;
1253                                 } else if(mySize_x/mySize_y >= 2.5) { // arrange in a 2x2 grid
1254                                         switch (i) {
1255                                                 case 0: mypos_x = pos_x + 0.5 * mySize_x;       mypos_y = pos_y + 0.5 * mySize_y;       break; // shells
1256                                                 case 1: mypos_x = pos_x + 0.5 * mySize_x;       mypos_y = pos_y;                        break; // bullets
1257                                                 case 2: mypos_x = pos_x;                        mypos_y = pos_y + 0.5 * mySize_y;       break; // rockets
1258                                                 case 3: mypos_x = pos_x;                        mypos_y = pos_y;                        break; // cells
1259                                         }
1260                                         mysize_x = 0.5 * mySize_x;
1261                                         mysize_y = 0.5 * mySize_y;
1262                                 } else { // arrange vertically
1263                                         switch (i) {
1264                                                 case 0: mypos_x = pos_x;                        mypos_y = pos_y;                        break; // shells
1265                                                 case 1: mypos_x = pos_x;                        mypos_y = pos_y + 0.25 * mySize_y;      break; // bullets
1266                                                 case 2: mypos_x = pos_x;                        mypos_y = pos_y + 0.5  * mySize_y;      break; // rockets
1267                                                 case 3: mypos_x = pos_x;                        mypos_y = pos_y + 0.75 * mySize_y;      break; // cells
1268                                         }
1269                                         mysize_x = mySize_x;
1270                                         mysize_y = 0.25 * mySize_y;
1271                                 }
1272
1273                                 if (stat_items & GetAmmoItemCode(i))
1274                                         drawpic(mypos, "gfx/hud/sb_ammobg", mysize, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1275                                 drawpic(mypos + eY * 0.05 * mysize_y, GetAmmoPicture(i), '1 1 0' * 0.8 * mysize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1276                                 if (a < 10) {
1277                                         if(stat_items & GetAmmoItemCode(i))
1278                                                 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);
1279                                         else
1280                                                 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);
1281                                 } else {
1282                                         if(stat_items & GetAmmoItemCode(i))
1283                                                 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);
1284                                         else
1285                                                 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);
1286                                 }
1287                         }
1288                 }
1289         }
1290 }
1291
1292
1293 // Powerups (#2)
1294 float shield_maxtime;
1295 float strength_maxtime;
1296 void HUD_Powerups() {
1297         float stat_items;
1298         stat_items = getstati(STAT_ITEMS);
1299
1300         if(!hud_configure)
1301         {
1302                 if not(stat_items & IT_STRENGTH)
1303                         if not(stat_items & IT_INVINCIBLE)
1304                                 return;
1305
1306                 if (getstati(STAT_HEALTH) <= 0)
1307                         return;
1308         }
1309
1310         vector pos, mySize;
1311         pos = HUD_Panel_GetPos(2);
1312         mySize = HUD_Panel_GetSize(2);
1313
1314         HUD_Panel_DrawBg(2, pos, mySize);
1315
1316         float strength_time, shield_time;
1317
1318         strength_time = bound(0, ceil(getstatf(STAT_STRENGTH_FINISHED) - time), 99);
1319         shield_time = bound(0, ceil(getstatf(STAT_INVINCIBLE_FINISHED) - time), 99);
1320
1321         if(hud_configure)
1322         {
1323                 strength_time = 15;
1324                 shield_time = 27;
1325         }
1326
1327         string leftname, rightname;
1328         float leftcnt, rightcnt;
1329         float leftalpha, rightalpha;
1330         if (cvar(strcat("hud_", HUD_Panel_GetName(2), "_flip"))) {
1331                 leftname = "strength";
1332                 leftcnt = strength_time;
1333
1334                 rightname = "shield";
1335                 rightcnt = shield_time;
1336         } else {
1337                 leftname = "shield";
1338                 leftcnt = shield_time;
1339
1340                 rightname = "strength";
1341                 rightcnt = strength_time;
1342         }
1343         leftalpha = bound(0, leftcnt, 1);
1344         rightalpha = bound(0, rightcnt, 1);
1345
1346         float len;
1347         if (mySize_x/mySize_y > 5)
1348         {
1349                 if(leftcnt)
1350                 {
1351                         len = strlen(ftos(leftcnt));
1352
1353                         drawpic(pos, "gfx/hud/statusbar", eX * 0.5 * mySize_x * min(1, leftcnt/30) + eY * mySize_y, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1354                         drawpic(pos, strcat("gfx/hud/sb_", leftname), '1 1 0' * mySize_y, '1 1 1', leftalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1355                         HUD_DrawXNum(pos + eX * mySize_y + eY * 0.25 * mySize_y, leftcnt, len, 0, 0.5 * mySize_y, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1356                 }
1357
1358                 if(rightcnt)
1359                 {
1360                         drawpic(pos + eX * mySize_x - eX * 0.5 * mySize_x * min(1, rightcnt/30), "gfx/hud/statusbar", eX * 0.5 * mySize_x * min(1, rightcnt/30) + eY * mySize_y, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1361                         drawpic(pos + eX * mySize_x - eX * mySize_y, strcat("gfx/hud/sb_", rightname), '1 1 0' * mySize_y, '1 1 1', rightalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1362                         HUD_DrawXNum(pos + eX * mySize_x - eX * 2.5 * mySize_y + eY * 0.25 * mySize_y, rightcnt, 3, 0, 0.5 * mySize_y, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1363                 }
1364         }
1365         else if (mySize_x/mySize_y > 3.2)
1366         {
1367                 if(leftcnt)
1368                 {
1369                         len = strlen(ftos(leftcnt));
1370
1371                         drawpic(pos + eY * mySize_y - eY * mySize_y * min(1, leftcnt/30), "gfx/hud/statusbar", eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/30), HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1372                         drawpic(pos + eX * 0.4 * mySize_y, strcat("gfx/hud/sb_", leftname), '0.7 0.7 0' * mySize_y, '1 1 1', leftalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1373                         HUD_DrawXNum(pos + eX * ((3-len)/2) * 0.5 * mySize_y + eY * 0.55 * mySize_y, leftcnt, len, 0, 0.5 * mySize_y, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1374                 }
1375
1376                 if(rightcnt)
1377                 {
1378                         len = strlen(ftos(rightcnt));
1379                         
1380                         drawpic(pos + eX * 0.5 * mySize_x + eY * mySize_y - eY * mySize_y * min(1, rightcnt/30), "gfx/hud/statusbar", eX * 0.5 * mySize_x + eY * mySize_y * min(1, rightcnt/30), HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1381                         drawpic(pos + eX * mySize_x - eX * 1.1 * mySize_y, strcat("gfx/hud/sb_", rightname), '0.7 0.7 0' * mySize_y, '1 1 1', rightalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1382                         HUD_DrawXNum(pos + eX * mySize_x - eX * len * 0.5 * mySize_y - eX * ((3-len)/2) * 0.5 * mySize_y + eY * 0.55 * mySize_y, rightcnt, len, 0, 0.5 * mySize_y, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1383                 }
1384         }
1385         else
1386         {
1387                 if(leftcnt)
1388                 {
1389                         len = strlen(ftos(leftcnt));
1390
1391                         drawpic(pos, "gfx/hud/statusbar", eX * mySize_x * min(1, leftcnt/30) + eY * 0.5 * mySize_y, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1392                         drawpic(pos, strcat("gfx/hud/sb_", leftname), '0.5 0.5 0' * mySize_y, '1 1 1', leftalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1393                         HUD_DrawXNum(pos + eX * 0.5 * mySize_y, leftcnt, len, 0, 0.5 * mySize_y, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1394                 }
1395
1396                 if(rightcnt)
1397                 {
1398                         len = strlen(ftos(rightcnt));
1399
1400                         drawpic(pos + eY * 0.5 * mySize_y, "gfx/hud/statusbar", eX * mySize_x * min(1, rightcnt/30) + eY * 0.5 * mySize_y, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1401                         drawpic(pos + eY * 0.5 * mySize_y, strcat("gfx/hud/sb_", rightname), '0.5 0.5 0' * mySize_y, '1 1 1', rightalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1402                         HUD_DrawXNum(pos + eX * 0.5 * mySize_y + eY * 0.5 * mySize_y, rightcnt, len, 0, 0.5 * mySize_y, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1403                 }
1404         }
1405
1406         /* TODO: add expand!
1407         //strength
1408         if (strength_time) {
1409                 dt = strength_time - time;
1410                 if(dt > 0)
1411                 {
1412                         if(dt < 5)
1413                         {
1414                                 drawpic_expanding_two(pos, "gfx/hud/sb_str", '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE,
1415                                         bound(0, (ceil(dt) - dt) / 0.5, 1));
1416                         }
1417                         else
1418                         {
1419                                 drawpic(pos, "gfx/hud/sb_str", '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE);
1420                         }
1421                         HUD_DrawXNum(pos - '40 -2 0', ceil(dt), 2, 0, countdown_fontsize, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1422                 }
1423                 else if(dt > -1)
1424                 {
1425                         drawpic_expanding(pos, "gfx/hud/sb_str", '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE,
1426                                 bound(0, -dt / 0.5, 1));
1427                 }
1428         }
1429
1430         //invincibility
1431         if (invincibility_time) {
1432                 dt = invincibility_time - time;
1433                 if(dt > 0)
1434                 {
1435                         if(dt < 5)
1436                         {
1437                                 drawpic_expanding_two(pos - '0 -22 0', "gfx/hud/sb_invinc", '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE,
1438                                         bound(0, (ceil(dt) - dt) / 0.5, 1));
1439                         }
1440                         else
1441                         {
1442                                 drawpic(pos - '0 -22 0', "gfx/hud/sb_invinc", '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE);
1443                         }
1444                         HUD_DrawXNum(pos - '40 -24 0', ceil(dt), 2, 0, countdown_fontsize, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1445                 }
1446                 else if(dt > -1)
1447                 {
1448                         drawpic_expanding(pos - '0 -22 0', "gfx/hud/sb_invinc", '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE,
1449                                 bound(0, -dt / 0.5, 1));
1450                 }
1451         }
1452         */
1453 }
1454
1455 // Health/armor (#3)
1456 //
1457 void HUD_HealthArmor(void)
1458 {
1459         vector pos, mySize;
1460         pos = HUD_Panel_GetPos(3);
1461         mySize = HUD_Panel_GetSize(3);
1462
1463         HUD_Panel_DrawBg(3, pos, mySize);
1464
1465         float armor, health, x;
1466         armor = getstati(STAT_ARMOR);
1467         health = getstati(STAT_HEALTH);
1468         if(hud_configure)
1469         {
1470                 armor = 150;
1471                 health = 100;
1472         }
1473
1474         if(health <= 0)
1475                 return;
1476
1477         float len;
1478
1479         // TODO!
1480         if(hud_hudselector == 2) // combined health and armor display
1481         {
1482                 vector v;
1483                 v = healtharmor_maxdamage(health, armor, armorblockpercent);
1484
1485                 vector num_pos;
1486                 num_pos = - '96 28 0';
1487
1488                 x = floor(v_x + 1);
1489
1490                 if(v_z) // fully armored
1491                 {
1492                         // here, armorideal > armor
1493                         drawpic(num_pos + '78 -4.5 0', "gfx/hud/sb_health", '32 32 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1494                         drawpic(num_pos + '108 -4.5 0', "gfx/hud/sb_armor", '20 20 0', '1 1 1', hud_alpha_fg * armor / v_y, DRAWFLAG_NORMAL);
1495                 }
1496                 else
1497                 {
1498                         drawpic(num_pos + '108 -4.5 0', "gfx/hud/sb_health", '20 20 0', '1 1 1', hud_alpha_fg * v_y / armor, DRAWFLAG_NORMAL);
1499                         drawpic(num_pos + '78 -4.5 0', "gfx/hud/sb_armor", '32 32 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1500                 }
1501                 HUD_DrawXNum_Colored(num_pos, x, 3, 24, hud_alpha_fg); // draw the combined health and armor
1502         }
1503
1504         else
1505         {
1506                 string leftname, rightname;
1507                 float leftcnt, rightcnt;
1508                 float leftactive, rightactive;
1509                 float leftalpha, rightalpha;
1510                 // TODO!
1511                 if (cvar(strcat("hud_", HUD_Panel_GetName(3), "_flip"))) { // old style layout with armor left/top of health
1512                         leftname = "armor";
1513                         leftcnt = armor;
1514                         if(leftcnt)
1515                                 leftactive = 1;
1516                         leftalpha = min((armor+10)/55, 1);
1517
1518                         rightname = "health";
1519                         rightcnt = health;
1520                         rightactive = 1;
1521                         rightalpha = 1;
1522                 } else {
1523                         leftname = "health";
1524                         leftcnt = health;
1525                         leftactive = 1;
1526                         leftalpha = 1;
1527
1528                         rightname = "armor";
1529                         rightcnt = armor;
1530                         if(rightcnt)
1531                                 rightactive = 1;
1532                         rightalpha = min((armor+10)/55, 1);
1533                 }
1534
1535                 float fuel;
1536                 fuel = getstati(GetAmmoStat(4)); // how much fuel do we have?
1537
1538                 if (mySize_x/mySize_y > 5)
1539                 {
1540                         if(leftactive)
1541                         {
1542                                 len = strlen(ftos(leftcnt));
1543
1544                                 drawpic(pos, "gfx/hud/statusbar", eX * 0.5 * mySize_x * min(1, leftcnt/200) + eY * mySize_y, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1545                                 drawpic(pos, strcat("gfx/hud/sb_", leftname), '1 1 0' * mySize_y, '1 1 1', leftalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1546                                 HUD_DrawXNum_Colored(pos + eX * mySize_y + eY * 0.25 * mySize_y, leftcnt, len, 0.5 * mySize_y, hud_alpha_fg);
1547                         }
1548
1549                         if(rightactive)
1550                         {
1551                                 drawpic(pos + eX * mySize_x - eX * 0.5 * mySize_x * min(1, rightcnt/200), "gfx/hud/statusbar", eX * 0.5 * mySize_x * min(1, rightcnt/200) + eY * mySize_y, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1552                                 drawpic(pos + eX * mySize_x - eX * mySize_y, strcat("gfx/hud/sb_", rightname), '1 1 0' * mySize_y, '1 1 1', rightalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1553                                 HUD_DrawXNum_Colored(pos + eX * mySize_x - eX * 2.5 * mySize_y + eY * 0.25 * mySize_y, rightcnt, 3, 0.5 * mySize_y, hud_alpha_fg);
1554                         }
1555
1556                         if(fuel)
1557                                 drawpic(pos, "gfx/hud/statusbar", eX * mySize_x * min(1, fuel/100) + eY * 0.2 * mySize_y, HUD_Panel_GetProgressBarColor("fuel"), hud_alpha_fg * 0.8, DRAWFLAG_NORMAL);
1558                 }
1559                 else if (mySize_x/mySize_y > 3.2)
1560                 {
1561                         if(leftactive)
1562                         {
1563                                 len = strlen(ftos(leftcnt));
1564
1565                                 drawpic(pos + eY * mySize_y - eY * mySize_y * min(1, leftcnt/200), "gfx/hud/statusbar", eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/200), HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1566                                 drawpic(pos + eX * 0.4 * mySize_y, strcat("gfx/hud/sb_", leftname), '0.7 0.7 0' * mySize_y, '1 1 1', leftalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1567                                 HUD_DrawXNum_Colored(pos + eX * ((3-len)/2) * 0.5 * mySize_y + eY * 0.55 * mySize_y, leftcnt, len, 0.5 * mySize_y, hud_alpha_fg);
1568                         }
1569
1570                         if(rightactive)
1571                         {
1572                                 len = strlen(ftos(rightcnt));
1573                                 
1574                                 drawpic(pos + eX * 0.5 * mySize_x + eY * mySize_y - eY * mySize_y * min(1, rightcnt/200), "gfx/hud/statusbar", eX * 0.5 * mySize_x + eY * mySize_y * min(1, rightcnt/200), HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1575                                 drawpic(pos + eX * mySize_x - eX * 1.1 * mySize_y, strcat("gfx/hud/sb_", rightname), '0.7 0.7 0' * mySize_y, '1 1 1', rightalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1576                                 HUD_DrawXNum_Colored(pos + eX * mySize_x - eX * len * 0.5 * mySize_y - eX * ((3-len)/2) * 0.5 * mySize_y + eY * 0.55 * mySize_y, rightcnt, len, 0.5 * mySize_y, hud_alpha_fg);
1577                         }
1578
1579                         if(fuel)
1580                                 drawpic(pos, "gfx/hud/statusbar", eX * mySize_x * min(1, fuel/100) + eY * 0.15 * mySize_y, HUD_Panel_GetProgressBarColor("fuel"), hud_alpha_fg * 0.8, DRAWFLAG_NORMAL);
1581                 }
1582                 else
1583                 {
1584                         if(leftactive)
1585                         {
1586                                 len = strlen(ftos(leftcnt));
1587
1588                                 drawpic(pos, "gfx/hud/statusbar", eX * mySize_x * min(1, leftcnt/200) + eY * 0.5 * mySize_y, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1589                                 drawpic(pos, strcat("gfx/hud/sb_", leftname), '0.5 0.5 0' * mySize_y, '1 1 1', leftalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1590                                 HUD_DrawXNum_Colored(pos + eX * 0.5 * mySize_y, leftcnt, len, 0.5 * mySize_y, hud_alpha_fg);
1591                         }
1592
1593                         if(rightactive)
1594                         {
1595                                 len = strlen(ftos(rightcnt));
1596
1597                                 drawpic(pos + eY * 0.5 * mySize_y, "gfx/hud/statusbar", eX * mySize_x * min(1, rightcnt/200) + eY * 0.5 * mySize_y, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1598                                 drawpic(pos + eY * 0.5 * mySize_y, strcat("gfx/hud/sb_", rightname), '0.5 0.5 0' * mySize_y, '1 1 1', rightalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1599                                 HUD_DrawXNum_Colored(pos + eX * 0.5 * mySize_y + eY * 0.5 * mySize_y, rightcnt, len, 0.5 * mySize_y, hud_alpha_fg);
1600                         }
1601
1602                         if(fuel)
1603                                 drawpic(pos, "gfx/hud/statusbar", eX * mySize_x * min(1, fuel/100) + eY * 0.1 * mySize_y, HUD_Panel_GetProgressBarColor("fuel"), hud_alpha_fg * 0.8, DRAWFLAG_NORMAL);
1604                 }
1605         }
1606 }
1607
1608 // Score (#7)
1609 //
1610 void HUD_Score()
1611 {
1612         vector pos, mySize;
1613         pos = HUD_Panel_GetPos(7);
1614         mySize = HUD_Panel_GetSize(7);
1615
1616         HUD_Panel_DrawBg(7, pos, mySize);
1617
1618         float score, distribution, leader;
1619         float score_len, distr_len;
1620         vector score_pos, secondary_score_pos, distribution_color;
1621         entity tm, pl, me;
1622         me = (spectatee_status > 0) ? playerslots[spectatee_status - 1] : playerslots[player_localentnum - 1];
1623
1624         if (!teamplay) { // non-teamgames
1625                 // me vector := [team/connected frags id]
1626                 pl = players.sort_next;
1627                 if(pl == me)
1628                         pl = pl.sort_next;
1629
1630                 if(hud_configure)
1631                         distribution = 42;
1632                 else if(pl)
1633                         distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
1634                 else
1635                         distribution = 0;
1636
1637                 score = me.(scores[ps_primary]);
1638                 if(hud_configure)
1639                         score = 123;
1640
1641                 if(distribution >= 5) {
1642                         distribution_color = eY;
1643                         leader = 1;
1644                 } else if(distribution >= 0) {
1645                         distribution_color = '1 1 1';
1646                         leader = 1;
1647                 } else if(distribution >= -5)
1648                         distribution_color = '1 1 0';
1649                 else
1650                         distribution_color = eX;
1651
1652                 score_len = strlen(ftos(score));
1653                 distr_len = strlen(ftos(distribution));
1654
1655                 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);
1656                 if (leader)
1657                         drawpic(pos + eX * mySize_x - eX * score_len * mySize_y - eX * 3 * 0.33 * mySize_y, strcat("gfx/hud/sb_highlight_", ftos(score_len)), eX * score_len * mySize_y + eY * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1658                 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);
1659         } else { // teamgames
1660                 float max_fragcount;
1661                 max_fragcount = -99;
1662
1663                 float teamnum;
1664                 for(tm = teams.sort_next; tm; tm = tm.sort_next) {
1665                         if(tm.team == COLOR_SPECTATOR || (!tm.team_size && !hud_configure)) // no players? don't display
1666                                 continue;
1667                         score = tm.(teamscores[ts_primary]);
1668                         if(hud_configure)
1669                                 score = 123;
1670                         leader = 0;
1671                         
1672                         score_len = strlen(ftos(score));
1673
1674                         if (score > max_fragcount)
1675                                 max_fragcount = score;
1676
1677                         if(tm.team == myteam) {
1678                                 if (max_fragcount == score)
1679                                         leader = 1;
1680                                 if (leader)
1681                                         drawpic(pos + eX * mySize_x - eX * score_len * mySize_y - eX * 3 * 0.33 * mySize_y, strcat("gfx/hud/sb_highlight_", ftos(score_len)), eX * score_len * mySize_y + eY * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1682                                 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);
1683                         } else {
1684                                 if (max_fragcount == score)
1685                                         leader = 1;
1686                                 if (leader)
1687                                         drawpic(pos + eX * mySize_x - eX * 0.33 * score_len * mySize_y + eY * 0.33 * mySize_y * teamnum, strcat("gfx/hud/sb_highlight_", ftos(score_len)), eX * 0.33 * score_len * mySize_y + eY * 0.33 * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1688                                 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);
1689                                 teamnum += 1;
1690                         }
1691                 }
1692         }
1693 }
1694
1695 // Race timer (#8)
1696 //
1697 void HUD_RaceTimer (void) {
1698         vector pos, mySize;
1699         pos = HUD_Panel_GetPos(8);
1700         mySize = HUD_Panel_GetSize(8);
1701
1702         HUD_Panel_DrawBg(8, pos, mySize);
1703
1704         drawfont = hud_bigfont;
1705         float a, t;
1706         string s, forcetime;
1707
1708         if(hud_configure)
1709         {
1710                 s = "0:13:37";
1711                 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);
1712                 s = "^1Intermediate 1 (+15.42)";
1713                 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);
1714         }
1715         else if(race_checkpointtime)
1716         {
1717                 a = bound(0, 2 - (time - race_checkpointtime), 1);
1718                 s = "";
1719                 forcetime = "";
1720                 if(a > 0) // just hit a checkpoint?
1721                 {
1722                         if(race_checkpoint != 254)
1723                         {
1724                                 if(race_time && race_previousbesttime)
1725                                         s = MakeRaceString(race_checkpoint, TIME_DECODE(race_time) - TIME_DECODE(race_previousbesttime), 0, 0, race_previousbestname);
1726                                 else
1727                                         s = MakeRaceString(race_checkpoint, 0, -1, 0, race_previousbestname);
1728                                 if(race_time)
1729                                         forcetime = TIME_ENCODED_TOSTRING(race_time);
1730                         }
1731                 }
1732                 else
1733                 {
1734                         if(race_laptime && race_nextbesttime && race_nextcheckpoint != 254)
1735                         {
1736                                 a = bound(0, 2 - ((race_laptime + TIME_DECODE(race_nextbesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1);
1737                                 if(a > 0) // next one?
1738                                 {
1739                                         s = MakeRaceString(race_nextcheckpoint, (time + TIME_DECODE(race_penaltyaccumulator)) - race_laptime, TIME_DECODE(race_nextbesttime), 0, race_nextbestname);
1740                                 }
1741                         }
1742                 }
1743
1744                 if(s != "" && a > 0)
1745                 {
1746                         dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
1747                         //drawcolorcodedstring(m - '0 16 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
1748                         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);
1749                 }
1750
1751                 if(race_penaltytime)
1752                 {
1753                         a = bound(0, 2 - (time - race_penaltyeventtime), 1);
1754                         if(a > 0)
1755                         {
1756                                 s = strcat("^1PENALTY: ", ftos_decimals(race_penaltytime * 0.1, 1), " (", race_penaltyreason, ")");
1757                                 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
1758                                 //drawcolorcodedstring(m - '0 32 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
1759                                 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);
1760                         }
1761                 }
1762
1763                 if(forcetime != "")
1764                 {
1765                         a = bound(0, (time - race_checkpointtime) / 0.5, 1);
1766                         //drawstring_expanding(m - '16 0 0' * stringwidth(forcetime, FALSE), forcetime, '32 32 0', '1 1 1', hud_alpha_fg, 0, a);
1767                         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);
1768                 }
1769                 else
1770                         a = 1;
1771
1772                 if(race_laptime && race_checkpoint != 255)
1773                 {
1774                         s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime));
1775                         //drawstring(m - '16 0 0' * stringwidth(s, FALSE), s, '32 32 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
1776                         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);
1777                 }
1778         }
1779         else
1780         {
1781                 if(race_mycheckpointtime)
1782                 {
1783                         a = bound(0, 2 - (time - race_mycheckpointtime), 1);
1784                         s = MakeRaceString(race_mycheckpoint, TIME_DECODE(race_mycheckpointdelta), -!race_mycheckpointenemy, race_mycheckpointlapsdelta, race_mycheckpointenemy);
1785                         dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
1786                         //drawcolorcodedstring(m - '0 16 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
1787                         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);
1788                 }
1789                 if(race_othercheckpointtime && race_othercheckpointenemy != "")
1790                 {
1791                         a = bound(0, 2 - (time - race_othercheckpointtime), 1);
1792                         s = MakeRaceString(race_othercheckpoint, -TIME_DECODE(race_othercheckpointdelta), -!race_othercheckpointenemy, race_othercheckpointlapsdelta, race_othercheckpointenemy);
1793                         dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
1794                         //drawcolorcodedstring(m - '0 0 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
1795                         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);
1796                 }
1797
1798                 if(race_penaltytime && !race_penaltyaccumulator)
1799                 {
1800                         t = race_penaltytime * 0.1 + race_penaltyeventtime;
1801                         a = bound(0, (1 + t - time), 1);
1802                         if(a > 0)
1803                         {
1804                                 if(time < t)
1805                                         s = strcat("^1PENALTY: ", ftos_decimals(t - time, 1), " (", race_penaltyreason, ")");
1806                                 else
1807                                         s = strcat("^2PENALTY: 0.0 (", race_penaltyreason, ")");
1808                                 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
1809                                 //drawcolorcodedstring(m - '0 32 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
1810                                 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);
1811                         }
1812                 }
1813         }
1814
1815         drawfont = hud_font;
1816 }
1817
1818 // Notification area (#4)
1819 void HUD_Notify (void)
1820 {
1821         vector pos, mySize;
1822         pos = HUD_Panel_GetPos(4);
1823         mySize = HUD_Panel_GetSize(4);
1824
1825         HUD_Panel_DrawBg(4, pos, mySize);
1826
1827         string s;
1828         entity tm;
1829         if(spectatee_status && !intermission)
1830         {
1831                 drawfont = hud_bigfont;
1832                 if(spectatee_status == -1)
1833                         s = "^1Observing";
1834                 else
1835                         s = GetPlayerName(spectatee_status - 1);
1836                 // spectated player name between HUD and chat area, aligned to the left
1837                 pos_x = 0;
1838                 pos_y = - 50 - hud_fontsize_spec_y;
1839                 s = textShortenToWidth(s, vid_conwidth/2.5, hud_fontsize_spec, stringwidth_colors);
1840                 drawcolorcodedstring(pos, s, hud_fontsize_spec, hud_alpha_fg, DRAWFLAG_NORMAL);
1841                 drawfont = hud_font;
1842
1843                 // spectator text in the upper right corner
1844                 if(spectatee_status == -1)
1845                         s = strcat("^1Press ^3", getcommandkey("primary fire", "+attack"), "^1 to spectate");
1846                 else
1847                         s = strcat("^1Press ^3", getcommandkey("primary fire", "+attack"), "^1 for another player");
1848
1849                 if(spectatee_status == -1)
1850                         s = strcat("^1Use ^3", getcommandkey("next weapon", "weapnext"), "^1 or ^3", getcommandkey("previous weapon", "weapprev"), "^1 to change the speed");
1851                 else
1852                         s = strcat("^1Press ^3", getcommandkey("secondary fire", "+attack2"), "^1 to observe");
1853
1854                 s = strcat("^1Press ^3", getcommandkey("server info", "+show_info"), "^1 for gamemode info");
1855
1856                 if(gametype == GAME_ARENA)
1857                         s = "^1Wait for your turn to join";
1858                 else if(gametype == GAME_LMS)
1859                 {
1860                         entity sk;
1861                         sk = playerslots[player_localentnum - 1];
1862                         if(sk.(scores[ps_primary]) >= 666)
1863                                 s = "^1Match has already begun";
1864                         else if(sk.(scores[ps_primary]) > 0)
1865                                 s = "^1You have no more lives left";
1866                         else
1867                                 s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
1868                 }
1869                 else
1870                         s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
1871
1872                 //show restart countdown:
1873                 if (time < getstatf(STAT_GAMESTARTTIME)) {
1874                         float countdown;
1875                         //we need to ceil, otherwise the countdown would be off by .5 when using round()
1876                         countdown = ceil(getstatf(STAT_GAMESTARTTIME) - time);
1877                         s = strcat("^1Game starts in ^3", ftos(countdown), "^1 seconds");
1878                 }
1879         }
1880         if(warmup_stage && !intermission)
1881         {
1882                 s = "^2Currently in ^1warmup^2 stage!";
1883         }
1884
1885         // move more important stuff more to the middle so its more visible
1886
1887         string blinkcolor;
1888         if(mod(time, 1) >= 0.5)
1889                 blinkcolor = "^1";
1890         else
1891                 blinkcolor = "^3";
1892
1893         if(ready_waiting && !intermission && !spectatee_status)
1894         {
1895                 if(ready_waiting_for_me)
1896                 {
1897                         if(warmup_stage)
1898                                 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " to end warmup");
1899                         else
1900                                 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " once you are ready");
1901                 }
1902                 else
1903                 {
1904                         if(warmup_stage)
1905                                 s = strcat("^2Waiting for others to ready up to end warmup...");
1906                         else
1907                                 s = strcat("^2Waiting for others to ready up...");
1908                 }
1909         }
1910         else if(warmup_stage && !intermission && !spectatee_status)
1911         {
1912                 s = strcat("^2Press ^3", getcommandkey("ready", "ready"), "^2 to end warmup");
1913         }
1914
1915         if(teamplay && !intermission && !spectatee_status && gametype != GAME_CA && teamnagger)
1916         {
1917                 float ts_min, ts_max;
1918                 tm = teams.sort_next;
1919                 if (tm)
1920                 {
1921                         for(; tm.sort_next; tm = tm.sort_next)
1922                         {
1923                                 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
1924                                         continue;
1925                                 if(!ts_min) ts_min = tm.team_size;
1926                                 else ts_min = min(ts_min, tm.team_size);
1927                                 if(!ts_max) ts_max = tm.team_size;
1928                                 else ts_max = max(ts_max, tm.team_size);
1929                         }
1930                         if ((ts_max - ts_min) > 1)
1931                         {
1932                                 s = strcat(blinkcolor, "Teamnumbers are unbalanced!");
1933                                 tm = GetTeam(myteam, false);
1934                                 if (tm)
1935                                 if (tm.team != COLOR_SPECTATOR)
1936                                 if (tm.team_size == ts_max)
1937                                         s = strcat(s, " Press ^3", getcommandkey("team menu", "menu_showteamselect"), blinkcolor, " to adjust");
1938
1939                         }
1940                 }
1941         }
1942 }
1943
1944 // Vote window (#9)
1945 float vote_yescount;
1946 float vote_nocount;
1947 float vote_needed;
1948 float vote_highlighted; // currently selected vote
1949
1950 float vote_active; // is there an active vote?
1951 float vote_prev; // previous state of vote_active to check for a change
1952 float vote_alpha;
1953 float vote_change; // "time" when vote_active changed
1954
1955 void HUD_VoteWindow(void) 
1956 {
1957         vector pos, mySize;
1958         pos = HUD_Panel_GetPos(9);
1959         mySize = HUD_Panel_GetSize(9);
1960
1961         string s;
1962         float a;
1963         if(vote_active != vote_prev) {
1964                 vote_change = time;
1965                 vote_prev = bound(0, vote_active, 1);
1966         }
1967
1968         if(vote_active)
1969                 vote_alpha = bound(0, (time - vote_change) * 2, 1);
1970         else
1971                 vote_alpha = bound(0, 1 - (time - vote_change) * 2, 1);
1972
1973         if(hud_configure)
1974         {
1975                 vote_alpha = 1;
1976                 vote_yescount = 3;
1977                 vote_nocount = 2;
1978                 vote_needed = 4;
1979         }
1980
1981         HUD_Panel_DrawBg(9, pos, mySize);
1982
1983         if(vote_alpha) {
1984                 a = vote_alpha * bound(cvar_or("hud_vote_alreadyvoted_alpha", 0.75), 1 - vote_highlighted, 1);
1985
1986                 drawpic(pos, "gfx/hud/voteprogress_back", mySize, HUD_GetBgColor(), a * hud_alpha_bg, DRAWFLAG_NORMAL);
1987
1988                 s = "A vote has been called for: ";
1989                 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);
1990                 s = textShortenToWidth(vote_called_vote, mySize_x * 0.96, '10 0 0', stringwidth_colors);
1991                 if(hud_configure)
1992                         s = "Configure the HUD";
1993                 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);
1994
1995                 // print the yes/no counts
1996                 s = strcat("Yes: ", ftos(vote_yescount));
1997                 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);
1998                 s = strcat("No: ", ftos(vote_nocount));
1999                 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);
2000
2001                 // draw the progress bars
2002                 drawsetcliparea(pos_x, pos_y, mySize_x * 0.5 * (vote_yescount/vote_needed), mySize_y);
2003                 drawpic(pos, "gfx/hud/voteprogress_prog", mySize, eY, a * hud_alpha_fg, DRAWFLAG_NORMAL);
2004
2005                 drawsetcliparea(pos_x + mySize_x - mySize_x * 0.5 * (vote_nocount/vote_needed), pos_y, mySize_x * 0.5, mySize_y);
2006                 drawpic(pos, "gfx/hud/voteprogress_prog", mySize, eX, a * hud_alpha_fg, DRAWFLAG_NORMAL);
2007
2008                 // draw the highlights
2009                 if(vote_highlighted == 1) {
2010                         drawsetcliparea(pos_x, pos_y, mySize_x * 0.5, mySize_y);
2011                         drawpic(pos, "gfx/hud/voteprogress_voted", mySize, eY, a * hud_alpha_fg, DRAWFLAG_NORMAL);
2012                 }
2013                 else if(vote_highlighted == 2) {
2014                         drawsetcliparea(pos_x + 0.5 * mySize_x, pos_y, mySize_x * 0.5, mySize_y);
2015                         drawpic(pos, "gfx/hud/voteprogress_voted", mySize, eX, a * hud_alpha_fg, DRAWFLAG_NORMAL);
2016                 }
2017
2018                 drawresetcliparea();
2019         }
2020         else if(!vote_active) {
2021                 vote_highlighted = 0;
2022         }
2023 }
2024
2025 // Awards system
2026 float race_status_time;
2027 float race_status_prev;
2028 string race_status_name_prev;
2029 void HUD_DrawRaceStatus(vector pos)
2030 {
2031         if (race_status != race_status_prev || race_status_name != race_status_name_prev) {
2032                 race_status_time = time + 5;
2033                 race_status_prev = race_status;
2034                 if (race_status_name_prev)
2035                         strunzone(race_status_name_prev);
2036                 race_status_name_prev = strzone(race_status_name);
2037         }
2038
2039         float a;
2040         a = bound(0, race_status_time - time, 1);
2041
2042         string s;
2043         s = textShortenToWidth(race_status_name, 120, '10 10 0', stringwidth_colors);
2044
2045         float rank;
2046         if(race_status > 0)
2047                 rank = race_CheckName(race_status_name);
2048         string rankname;
2049         rankname = race_PlaceName(rank);
2050
2051         if(race_status == 0)
2052                 drawpic(pos, "gfx/hud/race/newfail", '80 80 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2053         else if(race_status == 1) {
2054                 drawpic(pos, "gfx/hud/race/newtime", '80 80 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2055                 drawcolorcodedstring(pos + '40 80 0' - eX * stringwidth(s, TRUE, '5 0 0'), s, '10 10 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2056                 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);
2057         } else if(race_status == 2) {
2058                 if(race_status_name == GetPlayerName(player_localentnum -1) || !race_myrank || race_myrank < rank)
2059                         drawpic(pos, "gfx/hud/race/newrankgreen", '80 80 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2060                 else
2061                         drawpic(pos, "gfx/hud/race/newrankyellow", '80 80 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2062                 drawcolorcodedstring(pos + '40 80 0' - eX * stringwidth(s, TRUE, '5 0 0'), s, '10 10 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2063                 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);
2064         } else if(race_status == 3) {
2065                 drawpic(pos, "gfx/hud/race/newrecordserver", '80 80 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2066                 drawcolorcodedstring(pos + '40 80 0' - eX * stringwidth(s, TRUE, '5 0 0'), s, '10 10 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2067                 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);
2068         }
2069
2070         if (race_status_time - time <= 0) {
2071                 race_status_prev = -1;
2072                 race_status = -1;
2073                 if(race_status_name)
2074                         strunzone(race_status_name);
2075                 race_status_name = string_null;
2076                 if(race_status_name_prev)
2077                         strunzone(race_status_name_prev);
2078                 race_status_name_prev = string_null;
2079         }
2080 }
2081
2082 // CTF HUD modicon section
2083 float redflag_prevframe, blueflag_prevframe; // status during previous frame
2084 float redflag_prevstatus, blueflag_prevstatus; // last remembered status
2085 float redflag_statuschange_time, blueflag_statuschange_time; // time when the status changed
2086
2087 void CSQC_ctf_hudreset(void)
2088 {
2089         redflag_prevstatus = blueflag_prevstatus = redflag_prevframe = blueflag_prevframe = redflag_statuschange_time = blueflag_statuschange_time = 0;
2090 }
2091
2092 void CSQC_ctf_hud(void)
2093 {
2094         vector bottomleft, redflag_pos, blueflag_pos, sz;
2095         float f; // every function should have that
2096         bottomleft_y = vid_conheight;
2097         bottomleft_z = 0;
2098
2099         float redflag, blueflag; // current status
2100         float redflag_statuschange_elapsedtime, blueflag_statuschange_elapsedtime; // time since the status changed
2101         float stat_items;
2102
2103         stat_items = getstati(STAT_ITEMS);
2104         redflag = (stat_items/IT_RED_FLAG_TAKEN) & 3;
2105         blueflag = (stat_items/IT_BLUE_FLAG_TAKEN) & 3;
2106
2107         // when status CHANGES, set old status into prevstatus and current status into status
2108         if (redflag != redflag_prevframe)
2109         {
2110                 redflag_statuschange_time = time;
2111                 redflag_prevstatus = redflag_prevframe;
2112                 redflag_prevframe = redflag;
2113         }
2114
2115         if (blueflag != blueflag_prevframe)
2116         {
2117                 blueflag_statuschange_time = time;
2118                 blueflag_prevstatus = blueflag_prevframe;
2119                 blueflag_prevframe = blueflag;
2120         }
2121
2122         redflag_statuschange_elapsedtime = time - redflag_statuschange_time;
2123         blueflag_statuschange_elapsedtime = time - blueflag_statuschange_time;
2124
2125         float BLINK_FACTOR = 0.15;
2126         float BLINK_BASE = 0.85;
2127         // note:
2128         //   RMS = sqrt(BLINK_BASE^2 + 0.5 * BLINK_FACTOR^2)
2129         // thus
2130         //   BLINK_BASE = sqrt(RMS^2 - 0.5 * BLINK_FACTOR^2)
2131         // ensure RMS == 1
2132         float BLINK_FREQ = 5; // circle frequency, = 2*pi*frequency in hertz
2133
2134         string red_icon, red_icon_prevstatus;
2135         float red_alpha, red_alpha_prevstatus;
2136         red_alpha = red_alpha_prevstatus = 1;
2137         switch(redflag) {
2138                 case 1: red_icon = "gfx/hud/sb_flag_red_taken"; break;
2139                 case 2: red_icon = "gfx/hud/sb_flag_red_lost"; break;
2140                 case 3: red_icon = "gfx/hud/sb_flag_red_carrying"; red_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
2141                 default:
2142                         if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM2))
2143                                 red_icon = "gfx/hud/sb_flag_red_shielded";
2144                         else
2145                                 red_icon = string_null;
2146                         break;
2147         }
2148         switch(redflag_prevstatus) {
2149                 case 1: red_icon_prevstatus = "gfx/hud/sb_flag_red_taken"; break;
2150                 case 2: red_icon_prevstatus = "gfx/hud/sb_flag_red_lost"; break;
2151                 case 3: red_icon_prevstatus = "gfx/hud/sb_flag_red_carrying"; red_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
2152                 default:
2153                         if(redflag == 3)
2154                                 red_icon_prevstatus = "gfx/hud/sb_flag_red_carrying"; // make it more visible
2155                         else if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM2))
2156                                 red_icon_prevstatus = "gfx/hud/sb_flag_red_shielded";
2157                         else
2158                                 red_icon_prevstatus = string_null;
2159                         break;
2160         }
2161
2162         string blue_icon, blue_icon_prevstatus;
2163         float blue_alpha, blue_alpha_prevstatus;
2164         blue_alpha = blue_alpha_prevstatus = 1;
2165         switch(blueflag) {
2166                 case 1: blue_icon = "gfx/hud/sb_flag_blue_taken"; break;
2167                 case 2: blue_icon = "gfx/hud/sb_flag_blue_lost"; break;
2168                 case 3: blue_icon = "gfx/hud/sb_flag_blue_carrying"; blue_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
2169                 default:
2170                         if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM1))
2171                                 blue_icon = "gfx/hud/sb_flag_blue_shielded";
2172                         else
2173                                 blue_icon = string_null;
2174                         break;
2175         }
2176         switch(blueflag_prevstatus) {
2177                 case 1: blue_icon_prevstatus = "gfx/hud/sb_flag_blue_taken"; break;
2178                 case 2: blue_icon_prevstatus = "gfx/hud/sb_flag_blue_lost"; break;
2179                 case 3: blue_icon_prevstatus = "gfx/hud/sb_flag_blue_carrying"; blue_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
2180                 default:
2181                         if(blueflag == 3)
2182                                 blue_icon_prevstatus = "gfx/hud/sb_flag_blue_carrying"; // make it more visible
2183                         else if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM1))
2184                                 blue_icon_prevstatus = "gfx/hud/sb_flag_blue_shielded";
2185                         else
2186                                 blue_icon_prevstatus = string_null;
2187                         break;
2188         }
2189
2190         if (myteam == COLOR_TEAM1) { // always draw own flag on left
2191                 redflag_pos = bottomleft - '-4 50 0';
2192                 blueflag_pos = bottomleft - '-62 50 0';
2193         } else {
2194                 blueflag_pos = bottomleft - '-4 50 0';
2195                 redflag_pos = bottomleft - '-62 50 0';
2196         }
2197
2198         sz = '52 52 0';
2199
2200         f = bound(0, redflag_statuschange_elapsedtime*2, 1);
2201         if(red_icon_prevstatus && f < 1)
2202                 drawpic_expanding(redflag_pos, red_icon_prevstatus, sz, '1 1 1', hud_alpha_fg * red_alpha_prevstatus, DRAWFLAG_NORMAL, f);
2203         if(red_icon)
2204                 drawpic(redflag_pos, red_icon, sz, '1 1 1', hud_alpha_fg * red_alpha * f, DRAWFLAG_NORMAL);
2205
2206         f = bound(0, blueflag_statuschange_elapsedtime*2, 1);
2207         if(blue_icon_prevstatus && f < 1)
2208                 drawpic_expanding(blueflag_pos, blue_icon_prevstatus, sz, '1 1 1', hud_alpha_fg * blue_alpha_prevstatus, DRAWFLAG_NORMAL, f);
2209         if(blue_icon)
2210                 drawpic(blueflag_pos, blue_icon, sz, '1 1 1', hud_alpha_fg * blue_alpha * f, DRAWFLAG_NORMAL);
2211 }
2212
2213 /*void HUD_Mod_Race (void) {
2214         if((scores_flags[ps_primary] & SFL_TIME) && !teamplay) { // race/cts record display on HUD
2215                 pl = players.sort_next;
2216                 if(pl == me)
2217                         pl = pl.sort_next;
2218                 if(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)
2219                         if(pl.scores[ps_primary] == 0)
2220                                 pl = world;
2221
2222                 score = me.(scores[ps_primary]);
2223
2224                 float racemin, racesec, racemsec;
2225                 float distsec, distmsec, minusplus;
2226
2227                 racemin = floor(score/(60 * TIME_FACTOR));
2228                 racesec = floor((score - racemin*(60 * TIME_FACTOR))/TIME_FACTOR);
2229                 racemsec = score - racemin*60*TIME_FACTOR - racesec*TIME_FACTOR;
2230
2231                 if (pl && ((!(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)) || score)) {
2232                         // distribution display
2233                         distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
2234
2235                         if (distribution < TIME_FACTOR && distribution > -TIME_FACTOR)
2236                                 distmsec = fabs(distribution);
2237                         else {
2238                                 distsec = floor(fabs(distribution)/TIME_FACTOR);
2239                                 distmsec = fabs(distribution) - distsec*TIME_FACTOR;
2240                                 if (distribution < 0)
2241                                         distsec = -distsec;
2242                         }
2243
2244                         if (distribution <= 0) {
2245                                 distribution_color = eY;
2246                                 minusplus = 1; // minusplus 1: always prefix with minus sign
2247                         }
2248                         else {
2249                                 distribution_color = eX;
2250                                 minusplus = 2; // minusplus 1: always prefix with plus sign
2251                         }
2252                         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);
2253                         HUD_DrawXNum(bottomright - '68 48 0' - '16 0 0' * TIME_DECIMALS, distsec, 4, minusplus, 16, distribution_color, 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
2254                         drawpic(bottomright - '10 48 0' - '16 0 0' * TIME_DECIMALS, "gfx/hud/num_dot", '16 16 0', distribution_color, hud_alpha_fg, DRAWFLAG_ADDITIVE);
2255                 }
2256                 // race record display
2257                 if (distribution <= 0 || distribution == score) // draw the highlight background behind the timer if we have the lead
2258                         drawpic(bottomright - '0 32 0' - '32 0 0' * (4 + TIME_DECIMALS), "gfx/hud/sb_highlight_4", '0 28 0' + '32 0 0' * (4 + TIME_DECIMALS), '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2259
2260                 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);
2261                 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);
2262                 drawpic(bottomright - '0 32 0' - TIME_DECIMALS * '30 0 0' - '18 0 0', "gfx/hud/num_dot", '30 30 0', '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE);
2263
2264                 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);
2265                 drawpic(bottomright - '0 32 0' - TIME_DECIMALS * '30 0 0' - '84 0 0', "gfx/hud/num_colon", '30 30 0', '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE);
2266         }
2267 }*/
2268
2269 // Keyhunt HUD modicon section
2270 float kh_runheretime;
2271
2272 void CSQC_kh_hudreset(void)
2273 {
2274         kh_runheretime = 0;
2275 }
2276
2277 void CSQC_kh_hud(void)
2278 {
2279         float kh_keys;
2280         float keyteam;
2281         float a, aa;
2282         vector p, pa, kh_size, kh_asize;
2283
2284         p_x = 6;
2285         p_y = vid_conheight - 34 - 3;
2286         p_z = 0;
2287
2288         kh_keys = getstati(STAT_KH_KEYS);
2289
2290         kh_size = '19 34 0';
2291         kh_asize = '19 10 0';
2292         pa = p + '0 -10 0';
2293
2294         float i, key;
2295
2296         float keycount;
2297         keycount = 0;
2298         for(i = 0; i < 4; ++i)
2299         {
2300                 key = floor(kh_keys / pow(32, i)) & 31;
2301                 keyteam = key - 1;
2302                 if(keyteam == 30 && keycount <= 4)
2303                         keycount += 4;
2304                 if(keyteam == myteam || keyteam == -1 || keyteam == 30)
2305                         keycount += 1;
2306         }
2307         // this yields 8 exactly if "RUN HERE" shows
2308
2309         if(keycount == 8)
2310         {
2311                 if(!kh_runheretime)
2312                         kh_runheretime = time;
2313                 pa_y -= fabs(sin((time - kh_runheretime) * 3.5)) * 6; // make the arrows jump in case of RUN HERE
2314         }
2315         else
2316                 kh_runheretime = 0;
2317
2318         for(i = 0; i < 4; ++i)
2319         {
2320                 key = floor(kh_keys / pow(32, i)) & 31;
2321                 keyteam = key - 1;
2322                 switch(keyteam)
2323                 {
2324                         case 30: // my key
2325                                 keyteam = myteam;
2326                                 a = 1;
2327                                 aa = 1;
2328                                 break;
2329                         case -1: // no key
2330                                 a = 0;
2331                                 aa = 0;
2332                                 break;
2333                         default: // owned or dropped
2334                                 a = 0.2;
2335                                 aa = 0.5;
2336                                 break;
2337                 }
2338                 a = a * hud_alpha_fg;
2339                 aa = aa * hud_alpha_fg;
2340                 if(a > 0)
2341                 {
2342                         switch(keyteam)
2343                         {
2344                                 case COLOR_TEAM1:
2345                                         drawpic (pa, "gfx/hud/sb_kh_redarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL);  // show 30% alpha key
2346                                         break;
2347                                 case COLOR_TEAM2:
2348                                         drawpic (pa, "gfx/hud/sb_kh_bluearrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL);  // show 30% alpha key
2349                                         break;
2350                                 case COLOR_TEAM3:
2351                                         drawpic (pa, "gfx/hud/sb_kh_yellowarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL);  // show 30% alpha key
2352                                         break;
2353                                 case COLOR_TEAM4:
2354                                         drawpic (pa, "gfx/hud/sb_kh_pinkarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL);  // show 30% alpha key
2355                                         break;
2356                                 default:
2357                                         break;
2358                         }
2359                         switch(i) // YAY! switch(i) inside a for loop for i. DailyWTF, here we come!
2360                         {
2361                                 case 0:
2362                                         drawpic (p, "gfx/hud/sb_kh_red", kh_size, '1 1 1', a, DRAWFLAG_NORMAL);  // show 30% alpha key
2363                                         break;
2364                                 case 1:
2365                                         drawpic (p, "gfx/hud/sb_kh_blue", kh_size, '1 1 1', a, DRAWFLAG_NORMAL);  // show 30% alpha key
2366                                         break;
2367                                 case 2:
2368                                         drawpic (p, "gfx/hud/sb_kh_yellow", kh_size, '1 1 1', a, DRAWFLAG_NORMAL);  // show 30% alpha key
2369                                         break;
2370                                 case 3:
2371                                         drawpic (p, "gfx/hud/sb_kh_pink", kh_size, '1 1 1', a, DRAWFLAG_NORMAL);  // show 30% alpha key
2372                                         break;
2373                         }
2374                 }
2375                 p_x += 24;
2376                 pa_x += 24;
2377         }
2378 }
2379
2380 // Nexball HUD modicon section
2381 #define NBPB_SIZE '96 38 0'
2382 #define NBPB_BT 2                   //thickness
2383 #define NBPB_BRGB '1 1 1'
2384 #define NBPB_BALPH 1                //alpha
2385 #define NBPB_BFLAG DRAWFLAG_NORMAL
2386 #define NBPB_IALPH 0.4
2387 #define NBPB_IFLAG DRAWFLAG_NORMAL
2388 #define NBPB_IRGB '0.7 0.1 0'
2389
2390 void CSQC_nb_hud(void)
2391 {
2392         float stat_items, nb_pb_starttime, dt, p;
2393         vector pos;
2394
2395         stat_items = getstati(STAT_ITEMS);
2396         nb_pb_starttime = getstatf(STAT_NB_METERSTART);
2397
2398         pos_x = 4;
2399         pos_y = vid_conheight - 42;
2400         pos_z = 0;
2401
2402         //Manage the progress bar if any
2403         if (nb_pb_starttime > 0)
2404         {
2405                 vector s;
2406                 dt = mod(time - nb_pb_starttime, nb_pb_period);
2407                 // one period of positive triangle
2408                 p = 2 * dt / nb_pb_period;
2409                 if (p > 1)
2410                         p = 2 - p;
2411
2412                 s = NBPB_SIZE;
2413                 //Draw the filling
2414                 drawfill(pos, p * s_x * eX + s_y * eY, NBPB_IRGB, NBPB_IALPH, NBPB_IFLAG);
2415
2416                 //Draw the box
2417                 s = NBPB_SIZE;
2418                 drawline(NBPB_BT, pos    , pos + eX * s_x, NBPB_BRGB, NBPB_BALPH, NBPB_BFLAG);
2419                 drawline(NBPB_BT, pos    , pos + eY * s_y, NBPB_BRGB, NBPB_BALPH, NBPB_BFLAG);
2420                 drawline(NBPB_BT, pos + s, pos + eX * s_x, NBPB_BRGB, NBPB_BALPH, NBPB_BFLAG);
2421                 drawline(NBPB_BT, pos + s, pos + eY * s_y, NBPB_BRGB, NBPB_BALPH, NBPB_BFLAG);
2422         }
2423
2424         pos_x += 12; //horizontal margin to the picture
2425         pos_y += 2; //vertical margin to the picture
2426
2427         if (stat_items & IT_KEY1)
2428                 drawpic(pos, "gfx/hud/sb_nexball_carrying", '80 34 0', '1 1 1', 1, DRAWFLAG_NORMAL);
2429 }
2430
2431 // Race/CTS HUD modicon section
2432 float crecordtime_prev; // last remembered crecordtime
2433 float crecordtime_change_time; // time when crecordtime last changed
2434 float srecordtime_prev; // last remembered srecordtime
2435 float srecordtime_change_time; // time when srecordtime last changed
2436 void CSQC_race_hud(void)
2437 {
2438         entity me;
2439         me = playerslots[player_localentnum - 1];
2440         float t, score;
2441         float f; // yet another function has this
2442         score = me.(scores[ps_primary]);
2443
2444         if not((scores_flags[ps_primary] & SFL_TIME) && !teamplay) // race/cts record display on HUD
2445                 return; // no records in the actual race
2446
2447         drawfont = hud_bigfont;
2448         vector pos;
2449         pos_x = 2;
2450         pos_y = vid_conheight - 48;
2451
2452         // clientside personal record
2453         string rr;
2454         if(gametype == GAME_CTS)
2455                 rr = CTS_RECORD;
2456         else
2457                 rr = RACE_RECORD;
2458         t = stof(db_get(ClientProgsDB, strcat(shortmapname, rr, "time")));
2459
2460         if(score && (score < t || !t)) {
2461                 db_put(ClientProgsDB, strcat(shortmapname, rr, "time"), ftos(score));
2462                 if(cvar("cl_autodemo_delete_keeprecords"))
2463                 {
2464                         f = cvar("cl_autodemo_delete");
2465                         f &~= 1;
2466                         cvar_set("cl_autodemo_delete", ftos(f)); // don't delete demo with new record!
2467                 }
2468         }
2469
2470         if(t != crecordtime_prev) {
2471                 crecordtime_prev = t;
2472                 crecordtime_change_time = time;
2473         }
2474         f = time - crecordtime_change_time;
2475
2476         if (f > 1) {
2477                 drawstring(pos, "Personal best ", '10 10 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2478                 drawstring(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2479         } else {
2480                 drawstring(pos, "Personal best ", '10 10 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2481                 drawstring(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2482                 drawstring_expanding(pos, "Personal best ", '10 10 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL, f);
2483                 drawstring_expanding(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL, f);
2484         }
2485
2486         // server record
2487         pos_y += 26;
2488         t = race_server_record;
2489         if(t != srecordtime_prev) {
2490                 srecordtime_prev = t;
2491                 srecordtime_change_time = time;
2492         }
2493         f = time - srecordtime_change_time;
2494
2495         if (f > 1) {
2496                 drawstring(pos, "Server best ", '10 10 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2497                 drawstring(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2498         } else {
2499                 drawstring(pos, "Server best ", '10 10 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2500                 drawstring(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2501                 drawstring_expanding(pos, "Server best ", '10 10 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL, f);
2502                 drawstring_expanding(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL, f);
2503         }
2504         drawfont = hud_font;
2505 }
2506
2507 // Timer (#5)
2508 //
2509 void HUD_Timer()
2510 {
2511         vector pos, mySize;
2512         pos = HUD_Panel_GetPos(5);
2513         mySize = HUD_Panel_GetSize(5);
2514
2515         HUD_Panel_DrawBg(5, pos, mySize);
2516
2517         float timelimit, elapsedTime, minutes, seconds, timeleft, minutesLeft, secondsLeft;
2518
2519         timelimit = getstatf(STAT_TIMELIMIT);
2520
2521         HUD_DrawRaceStatus(pos + '0 30 0');
2522
2523         timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
2524         timeleft = ceil(timeleft);
2525         minutesLeft = floor(timeleft / 60);
2526         secondsLeft = timeleft - minutesLeft*60;
2527
2528         vector timer_color;
2529         if(minutesLeft >= 5 || warmup_stage || timelimit == 0) //don't use red or yellow in warmup or when there is no timelimit
2530                 timer_color = '1 1 1'; //white
2531         else if(minutesLeft >= 1)
2532                 timer_color = '1 1 0'; //yellow
2533         else
2534                 timer_color = '1 0 0'; //red
2535
2536         if (cvar("hud_timer_increment") || timelimit == 0 || warmup_stage) {
2537                 if (time < getstatf(STAT_GAMESTARTTIME)) {
2538                         //while restart is still active, show 00:00
2539                         minutes = seconds = 0;
2540                 } else {
2541                         elapsedTime = floor(time - getstatf(STAT_GAMESTARTTIME)); //127
2542                         minutes = floor(elapsedTime / 60);
2543                         seconds = elapsedTime - minutes*60;
2544                 }
2545         } else {
2546                 minutes = minutesLeft;
2547                 seconds = secondsLeft;
2548         }
2549
2550         if(mySize_x/mySize_y > 5.1)
2551         {
2552                 if(minutes > 999)
2553                         seconds = 99;
2554                 minutes = min(minutes, 999);
2555                 if(minutesLeft >= 1 || cvar("hud_timer_increment") || timelimit == 0 || warmup_stage) {
2556                         if(minutes < 100)
2557                                 drawpic(pos + eX * mySize_x - eX * 5.1 * mySize_y, "gfx/hud/sb_timer", '1 1 0' * mySize_y, timer_color, hud_alpha_fg, DRAWFLAG_NORMAL);
2558                         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);
2559                         drawpic(pos + eX * mySize_x - eX * 2.57 * mySize_y, "gfx/hud/num_colon", '1 1 0' * mySize_y, timer_color, hud_alpha_fg, DRAWFLAG_NORMAL);
2560                 }
2561                 HUD_DrawXNum(pos + eX * mySize_x - eX * 2 * mySize_y, seconds, -2, 0, mySize_y, timer_color, 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
2562         }
2563         else
2564         {
2565                 if(minutes > 99)
2566                         seconds = 99;
2567                 minutes = min(minutes, 99);
2568                 if(minutesLeft >= 1 || cvar("hud_timer_increment") || timelimit == 0 || warmup_stage) {
2569                         if(minutes < 100)
2570                                 drawpic(pos + eX * 0.5 * mySize_x - eX * 0.5 * 0.5 * mySize_y, "gfx/hud/sb_timer", '0.5 0.5 0' * mySize_y, timer_color, hud_alpha_fg, DRAWFLAG_NORMAL);
2571                         HUD_DrawXNum(pos + eX * 0.5 * mySize_x - eX * mySize_y + eY * 0.5 * mySize_y, minutes, -2, 0, 0.5 * mySize_y, timer_color, 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
2572                         drawpic(pos + eX * 0.5 * mySize_x - eX * 0.5 * 0.5 * mySize_y + eY * 0.5 * mySize_y, "gfx/hud/num_colon", '0.5 0.5 0' * mySize_y, timer_color, hud_alpha_fg, DRAWFLAG_NORMAL);
2573                 }
2574                 HUD_DrawXNum(pos + eX * 0.51 * mySize_x + eY * 0.5 * mySize_y, seconds, -2, 0, 0.5 * mySize_y, timer_color, 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
2575         }
2576 }
2577
2578 // Radar (#6)
2579 //
2580
2581 void HUD_Radar(void)
2582 {
2583         vector pos, mySize;
2584         pos = HUD_Panel_GetPos(6);
2585         mySize = HUD_Panel_GetSize(6);
2586
2587         HUD_Panel_DrawBg(6, pos, mySize);
2588
2589         local float color1, color2; // color already declared as a global in hud.qc
2590         local vector rgb;
2591         local entity tm;
2592         float scale2d, normalsize, bigsize;
2593         float f;
2594
2595         teamradar_origin2d = pos + 0.5 * mySize; // TODO: stupid compat, should be removed
2596         teamradar_size2d = mySize;
2597
2598         if(minimapname == "" && !ons_showmap)
2599                 return;
2600
2601         teamradar_loadcvars();
2602
2603         switch(cl_teamradar_zoommode)
2604         {
2605                 default:
2606                 case 0:
2607                         f = current_zoomfraction;
2608                         break;
2609                 case 1:
2610                         f = 1 - current_zoomfraction;
2611                         break;
2612                 case 2:
2613                         f = 0;
2614                         break;
2615                 case 3:
2616                         f = 1;
2617                         break;
2618         }
2619
2620         switch(cl_teamradar_rotation)
2621         {
2622                 case 0:
2623                         teamradar_angle = view_angles_y - 90;
2624                         break;
2625                 default:
2626                         teamradar_angle = 90 * cl_teamradar_rotation;
2627                         break;
2628         }
2629
2630         scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
2631         teamradar_size2d = mySize;
2632
2633         teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0';
2634         if(pos == eX * vid_conwidth)
2635         {
2636                 if(cl_teamradar_nohudhack < 2)
2637                         pos_y += 25;
2638                 if(cl_teamradar_nohudhack < 1)
2639                         teamradar_extraclip_mins_y -= 25;
2640         }
2641         else if(pos == eY * vid_conheight || pos == eX * vid_conwidth + eY * vid_conheight)
2642         {
2643                 if(cl_teamradar_nohudhack < 2)
2644                         pos_y -= 50;
2645                 //if(cl_teamradar_nohudhack < 1)
2646                         //teamradar_extraclip_size_y += 50; // don't, the HUD looks nice
2647         }
2648
2649         // pixels per world qu to match the teamradar_size2d_x range in the longest dimension
2650         if(cl_teamradar_rotation == 0)
2651         {
2652                 // max-min distance must fit the radar in any rotation
2653                 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen2d(mi_max - mi_min));
2654         }
2655         else
2656         {
2657                 vector c0, c1, c2, c3, span;
2658                 c0 = rotate(mi_min, teamradar_angle * DEG2RAD);
2659                 c1 = rotate(mi_max, teamradar_angle * DEG2RAD);
2660                 c2 = rotate('1 0 0' * mi_min_x + '0 1 0' * mi_max_y, teamradar_angle * DEG2RAD);
2661                 c3 = rotate('1 0 0' * mi_max_x + '0 1 0' * mi_min_y, teamradar_angle * DEG2RAD);
2662                 span = '0 0 0';
2663                 span_x = max4(c0_x, c1_x, c2_x, c3_x) - min4(c0_x, c1_x, c2_x, c3_x);
2664                 span_y = max4(c0_y, c1_y, c2_y, c3_y) - min4(c0_y, c1_y, c2_y, c3_y);
2665
2666                 // max-min distance must fit the radar in x=x, y=y
2667                 bigsize = min(
2668                         teamradar_size2d_x * scale2d / (1.05 * span_x),
2669                         teamradar_size2d_y * scale2d / (1.05 * span_y)
2670                 );
2671         }
2672
2673         normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / cl_teamradar_scale;
2674         if(bigsize > normalsize)
2675                 normalsize = bigsize;
2676
2677         teamradar_size =
2678                   f * bigsize
2679                 + (1 - f) * normalsize;
2680         teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
2681                   f * (mi_min + mi_max) * 0.5
2682                 + (1 - f) * view_origin);
2683
2684         color1 = GetPlayerColor(player_localentnum-1);
2685         rgb = GetTeamRGB(color1);
2686
2687         drawsetcliparea(
2688                 pos_x,
2689                 pos_y,
2690                 pos_x + mySize_x,
2691                 pos_y + mySize_y
2692         );
2693
2694         draw_teamradar_background(cl_teamradar_background_alpha, cl_teamradar_foreground_alpha);
2695
2696         if(ons_showmap)
2697         {
2698                 drawresetcliparea();
2699
2700                 vector frame_origin, frame_size;
2701                 frame_origin = frame_size = '0 0 0';
2702
2703                 frame_origin_x = pos_x - teamradar_size2d_x * 0.55859375; // matches the picture
2704                 frame_origin_y = pos_y - teamradar_size2d_y * 0.55859375; // matches the picture
2705                 frame_size_x = pos_x * 1.1171875; // matches the picture
2706                 frame_size_y = pos_y * 1.1171875; // matches the picture
2707                 drawpic(frame_origin, "gfx/ons-frame.tga", frame_size, '1 1 1', hud_alpha_fg, 0);
2708                 drawpic(frame_origin, "gfx/ons-frame-team.tga", frame_size, rgb, hud_alpha_fg, 0);
2709
2710                 drawsetcliparea(
2711                         pos_x - teamradar_size2d_x * 0.5,
2712                         pos_y - teamradar_size2d_y * 0.5,
2713                         teamradar_size2d_x,
2714                         teamradar_size2d_y
2715                 );
2716         }
2717
2718         for(tm = world; (tm = find(tm, classname, "radarlink")); )
2719                 draw_teamradar_link(tm.origin, tm.velocity, tm.team);
2720         for(tm = world; (tm = findflags(tm, teamradar_icon, 0xFFFFFF)); )
2721                 draw_teamradar_icon(tm.origin, tm.teamradar_icon, tm, tm.teamradar_color, hud_alpha_fg);
2722         for(tm = world; (tm = find(tm, classname, "entcs_receiver")); )
2723         {
2724                 color2 = GetPlayerColor(tm.sv_entnum);
2725                 //if(color == COLOR_SPECTATOR || color == color2)
2726                         draw_teamradar_player(tm.origin, tm.angles, GetTeamRGB(color2));
2727         }
2728         draw_teamradar_player(view_origin, view_angles, '1 1 1');
2729
2730         drawresetcliparea();
2731 };
2732
2733 /*
2734 ==================
2735 Main HUD system
2736 ==================
2737 */
2738
2739 void HUD_DrawPressedKeys(void)
2740 {
2741         vector pos, mySize;
2742         pos = HUD_Panel_GetPos(10);
2743         mySize = HUD_Panel_GetSize(10);
2744
2745         HUD_Panel_DrawBg(10, pos, mySize);
2746
2747         float pressedkeys;
2748
2749         pressedkeys = getstatf(STAT_PRESSED_KEYS);
2750         drawpic(pos, "gfx/hud/keys/key_bg.tga",           mySize, '1 1 1', 0.1 * hud_alpha_fg, DRAWFLAG_NORMAL);
2751         drawpic(pos + eX * mySize_x - eX * 0.22 * mySize_x +       eY * 0.195 * mySize_y, ((pressedkeys & KEY_CROUCH) ? "gfx/hud/keys/key_crouch_inv.tga" : "gfx/hud/keys/key_crouch.tga"),        '1 1 0' * (1/3) * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2752         drawpic(pos + eX * 0.5 * mySize_x - eX * 0.23 * mySize_y + eY * 0.040 * mySize_y, ((pressedkeys & KEY_FORWARD) ? "gfx/hud/keys/key_forward_inv.tga" : "gfx/hud/keys/key_forward.tga"),     '1 1 0' * 0.46 * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2753         drawpic(pos + eX * 0.023 * mySize_x +                      eY * 0.195 * mySize_y, ((pressedkeys & KEY_JUMP) ? "gfx/hud/keys/key_jump_inv.tga" : "gfx/hud/keys/key_jump.tga"),              '1 1 0' * (1/3) * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2754         drawpic(pos + eX * 0.1 * mySize_x +                        eY * 0.486 * mySize_y, ((pressedkeys & KEY_LEFT) ? "gfx/hud/keys/key_left_inv.tga" : "gfx/hud/keys/key_left.tga"),              '1 1 0' * 0.46 * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2755         drawpic(pos + eX * 0.5 * mySize_x - eX * 0.23 * mySize_y + eY * 0.486 * mySize_y, ((pressedkeys & KEY_BACKWARD) ? "gfx/hud/keys/key_backward_inv.tga" : "gfx/hud/keys/key_backward.tga"),  '1 1 0' * 0.46 * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2756         drawpic(pos + eX * mySize_x - eX * 0.372 * mySize_x +      eY * 0.486 * mySize_y, ((pressedkeys & KEY_RIGHT) ? "gfx/hud/keys/key_right_inv.tga" : "gfx/hud/keys/key_right.tga"),           '1 1 0' * 0.46 * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2757 }
2758
2759 void HUD_ShowSpeed(void)
2760 {
2761         vector numsize;
2762         float pos, conversion_factor;
2763         string speed, zspeed, unit;
2764
2765         switch(cvar("cl_showspeed_unit"))
2766         {
2767                 default:
2768                 case 0:
2769                         unit = "";
2770                         conversion_factor = 1.0;
2771                         break;
2772                 case 1:
2773                         unit = " qu/s";
2774                         conversion_factor = 1.0;
2775                         break;
2776                 case 2:
2777                         unit = " m/s";
2778                         conversion_factor = 0.0254;
2779                         break;
2780                 case 3:
2781                         unit = " km/h";
2782                         conversion_factor = 0.0254 * 3.6;
2783                         break;
2784                 case 4:
2785                         unit = " mph";
2786                         conversion_factor = 0.0254 * 3.6 * 0.6213711922;
2787                         break;
2788                 case 5:
2789                         unit = " knots";
2790                         conversion_factor = 0.0254 * 1.943844492; // 1 m/s = 1.943844492 knots, because 1 knot = 1.852 km/h
2791                         break;
2792         }
2793
2794         speed = strcat(ftos(floor( vlen(pmove_vel - pmove_vel_z * '0 0 1') * conversion_factor + 0.5 )), unit);
2795
2796         numsize_x = numsize_y = cvar("cl_showspeed_size");
2797         pos = (vid_conheight - numsize_y) * cvar("cl_showspeed_position");
2798
2799         drawfont = hud_bigfont;
2800         drawstringcenter(eX + pos * eY, speed, numsize, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2801
2802         if (cvar("cl_showspeed_z") == 1) {
2803                 zspeed = strcat(ftos(fabs(floor( pmove_vel_z * conversion_factor + 0.5 ))), unit);
2804                 drawstringcenter(eX + pos * eY + numsize_y * eY, zspeed, numsize * 0.5, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2805         }
2806
2807         drawfont = hud_font;
2808 }
2809
2810 vector acc_prevspeed;
2811 float acc_prevtime;
2812 float acc_avg;
2813
2814 void HUD_ShowAcceleration(void)
2815 {
2816         float acceleration, sz, scale, alpha, f;
2817         vector pos, top, rgb;
2818         top_x = vid_conwidth/2;
2819         top_y = 0;
2820
2821         f = time - acc_prevtime;
2822         if(cvar("cl_showacceleration_z"))
2823                 acceleration = (vlen(pmove_vel) - vlen(acc_prevspeed)) * (1 / f);
2824         else
2825                 acceleration = (vlen(pmove_vel - '0 0 1' * pmove_vel_z) - vlen(acc_prevspeed - '0 0 1' * acc_prevspeed_z)) * (1 / f);
2826         acc_prevspeed = pmove_vel;
2827         acc_prevtime = time;
2828
2829         f = bound(0, f * 10, 1);
2830         acc_avg = acc_avg * (1 - f) + acceleration * f;
2831         acceleration = acc_avg / getstatf(STAT_MOVEVARS_MAXSPEED);
2832
2833         pos = top - sz/2 * eY + (cvar("cl_showacceleration_position") * vid_conheight) * eY;
2834
2835         sz = cvar("cl_showacceleration_size");
2836         scale = cvar("cl_showacceleration_scale");
2837         alpha = cvar("cl_showacceleration_alpha");
2838         if (cvar("cl_showacceleration_color_custom"))
2839                 rgb = stov(cvar_string("cl_showacceleration_color"));
2840         else {
2841                 rgb = '1 1 1';
2842                 if (acceleration < 0) {
2843                         rgb = '1 .5 .5' - '0 .5 .5' * bound(0, -acceleration * 0.2, 1);
2844                 } else if (acceleration > 0) {
2845                         rgb = '.5 1 .5' - '.5 0 .5' * bound(0, +acceleration * 0.2, 1);
2846                 }
2847         }
2848
2849         if (acceleration > 0)
2850                 drawpic(pos, "gfx/hud/statusbar", acceleration * scale * '40 0 0' + sz * eY, rgb, alpha * hud_alpha_fg, DRAWFLAG_NORMAL);
2851         else if (acceleration < 0)
2852                 drawpic(pos + acceleration * scale * '40 0 0', "gfx/hud/statusbar", -acceleration * scale * '40 0 0' + sz * eY, rgb, alpha * hud_alpha_fg, DRAWFLAG_NORMAL);
2853 }
2854
2855 void HUD_Reset (void)
2856 {
2857         // reset gametype specific icons
2858         if(gametype == GAME_KEYHUNT)
2859                 CSQC_kh_hudreset();
2860         else if(gametype == GAME_CTF)
2861                 CSQC_ctf_hudreset();
2862 }
2863
2864 void HUD_Main (void)
2865 {
2866         hud_alpha_bg = cvar_or("hud_bg_alpha", 0.8) * (1 - cvar("_menu_alpha"));
2867         hud_border_thickness = bound(0, cvar("hud_border_thickness"), 5);
2868         hud_accuracy_border_thickness = bound(0, cvar_or("hud_accuracy_border_thickness", 1), 5);
2869         hud_color_bg_team = cvar("hud_color_bg_team");
2870
2871         hud_fontsize = HUD_GetFontsize("hud_fontsize");
2872         hud_fontsize_spec = HUD_GetFontsize("hud_fontsize_spec");
2873
2874         hud_configure = cvar("_hud_configure");
2875         hud_skin = cvar_string("hud_skin");
2876
2877         // Drawing stuff
2878         if(cvar_string("hud_dock") != "0")
2879                 drawpic('0 0 0', strcat("gfx/hud/", cvar_string("hud_dock")), eX * vid_conwidth + eY * vid_conheight, stov(cvar_string("hud_dock_color")), cvar("hud_dock_alpha"), DRAWFLAG_NORMAL);
2880
2881         if(HUD_Panel_CheckActive(0))
2882                 HUD_WeaponIcons();
2883         if(HUD_Panel_CheckActive(1))
2884                 HUD_Inventory();
2885         if(HUD_Panel_CheckActive(2))
2886                 HUD_Powerups();
2887         if(HUD_Panel_CheckActive(3))
2888                 HUD_HealthArmor();
2889         if(HUD_Panel_CheckActive(4))
2890                 HUD_Notify();
2891         if(HUD_Panel_CheckActive(5))
2892                 HUD_Timer();
2893         // TODO hud'ify
2894         if(HUD_Panel_CheckActive(6))
2895                 if(ons_showmap || cvar_string("cl_teamradar") != "0" && (cvar("cl_teamradar") == 2 || teamplay))
2896                         HUD_Radar();
2897         if(HUD_Panel_CheckActive(7))
2898                 HUD_Score();
2899         if(HUD_Panel_CheckActive(8))
2900                 if(gametype == GAME_RACE || gametype == GAME_CTS || hud_configure)
2901                         HUD_RaceTimer();
2902         if(HUD_Panel_CheckActive(9))
2903                 HUD_VoteWindow();
2904         // TODO hud'ify
2905         if(HUD_Panel_CheckActive(10))
2906                 if(spectatee_status > 0 || cvar("cl_showpressedkeys") >= 2 || hud_configure)
2907                         HUD_DrawPressedKeys();
2908
2909         // TODO hud_'ify these
2910         if (cvar("cl_showspeed"))
2911                 HUD_ShowSpeed();
2912         if (cvar("cl_showacceleration"))
2913                 HUD_ShowAcceleration();
2914
2915         // TODO... well make them work in a panel etc
2916         if(gametype == GAME_KEYHUNT)
2917                 CSQC_kh_hud();
2918         else if(gametype == GAME_CTF)
2919                 CSQC_ctf_hud();
2920         else if(gametype == GAME_NEXBALL)
2921                 CSQC_nb_hud();
2922         else if(gametype == GAME_CTS || gametype == GAME_RACE)
2923                 CSQC_race_hud();
2924         return;
2925 }