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