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