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