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
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)
20 //pic = draw_UseSkinFor(pic);
21 width = eX * theSize_x;
22 height = eY * theSize_y;
23 if(theSize_x <= theBorderSize_x * 2)
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)
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);
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);
49 if(theSize_y <= theBorderSize_y * 2)
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);
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);
78 // draw HUD element with image from gfx/hud/hud_skin/foo.tga if it exists, otherwise gfx/hud/default/foo.tga
79 void drawpic_skin(vector pos, string pic, vector sz, vector color, float alpha, float drawflag) {
80 drawpic(pos, strcat("gfx/hud/", cvar_string("hud_skin"), "/", pic), sz, color, alpha, drawflag);
83 // return HUD background color
84 vector HUD_GetBgColor()
88 GetTeamRGB(myteam) * hud_color_bg_team;
90 // allow custom HUD colors in non-teamgames
91 color_x = cvar("hud_color_bg_r");
92 color_y = cvar("hud_color_bg_g");
93 color_z = cvar("hud_color_bg_b");
98 // return accuracy text color
99 vector HUD_AccuracyColor(float accuracy)
102 float yellow_accuracy = cvar("hud_weaponicons_accuracy_yellow"); // value at which this function returns yellow
103 if(accuracy >= 100) {
107 else if(accuracy > yellow_accuracy) {
108 rgb_x = 1 - (accuracy-yellow_accuracy)/(100-yellow_accuracy); // red value between 1 -> 0
113 rgb_y = accuracy/yellow_accuracy; // green value between 0 -> 1
119 // draw number in the XSCALE font
120 void HUD_DrawXNum (vector pos, float num, float digits, float showsign, float lettersize, vector rgb, float highlighted, float stroke, float alpha, float dflags)
123 string str, tmp, l_length;
125 vector vsize, num_color;
127 vsize_x = vsize_y = lettersize;
130 // showsign 1: always prefix with minus sign (useful in race distribution display)
131 // showsign 2: always prefix with plus sign (useful in race distribution display)
132 // showsign 3: prefix with minus sign if negative, plus sign if positive (useful in score distribution display)
134 if((showsign == 2 && num >= 0) || (num > 0 && showsign == 3))
141 if(num < 0 || (num < 0 && showsign == 3) || (showsign == 1 && num <= 0))
153 str = strcat(substring("0000000000", 0, digits - strlen(tmp)), tmp);
162 str = substring(str, l-digits, 999);
164 } else if(l < digits)
165 pos_x += (digits-l) * lettersize;
167 if (highlighted == 1) {
169 hl_size_x = vsize_x * l + vsize_x * 0.2;
170 hl_size_y = vsize_y * 1.1;
173 hl_size_x = hl_size_x + vsize_x;
176 hl_pos_x = pos_x - lettersize/10;
177 hl_pos_y = pos_y - lettersize/20;
180 drawpic_skin(hl_pos, strcat("highlight_", l_length), hl_size, '1 1 1', alpha, dflags);
191 drawpic_skin(pos, "num_minus_stroke", vsize, rgb, alpha, dflags);
192 drawpic_skin(pos, "num_minus", vsize, num_color, alpha, dflags);
197 drawpic_skin(pos, "num_plus_stroke", vsize, rgb, alpha, dflags);
198 drawpic_skin(pos, "num_plus", vsize, num_color, alpha, dflags);
202 for(i = 0; i < l; ++i)
204 tmp = substring(str, i, 1);
206 drawpic_skin(pos, strcat("num_", tmp, "_stroke"), vsize, rgb, alpha, dflags);
207 drawpic_skin(pos, strcat("num_", tmp), vsize, num_color, alpha, dflags);
212 // color the number differently based on how big it is (used in the health/armor panel)
213 void HUD_DrawXNum_Colored (vector pos, float x, float digits, float lettersize, float alpha)
222 color_x = 0.4 - (x-150)*0.02 * 0.4; //red value between 0.4 -> 0
223 color_y = 0.9 + (x-150)*0.02 * 0.1; // green value between 0.9 -> 1
227 color_x = 1 - (x-100)*0.02 * 0.6; //red value between 1 -> 0.4
228 color_y = 1 - (x-100)*0.02 * 0.1; // green value between 1 -> 0.9
229 color_z = 1 - (x-100)*0.02; // blue value between 1 -> 0
234 color_z = 0.2 + (x-50)*0.02 * 0.8; // blue value between 0.2 -> 1
238 color_y = (x-20)*90/27/100; // green value between 0 -> 1
239 color_z = (x-20)*90/27/100 * 0.2; // blue value between 0 -> 0.2
246 HUD_DrawXNum(pos, x, digits, 0, lettersize, color, 0, 0, alpha, DRAWFLAG_NORMAL);
249 float stringwidth_colors(string s, vector theSize)
251 return stringwidth(s, TRUE, theSize);
254 float stringwidth_nocolors(string s, vector theSize)
256 return stringwidth(s, FALSE, theSize);
259 #define CENTERPRINT_MAX_LINES 30
260 string centerprint_messages[CENTERPRINT_MAX_LINES];
261 float centerprint_width[CENTERPRINT_MAX_LINES];
262 vector centerprint_start;
263 float centerprint_expire;
264 float centerprint_num;
265 float centerprint_offset_hint;
266 vector centerprint_fontsize;
268 void centerprint(string strMessage)
270 float i, j, n, hcount;
273 centerprint_fontsize = HUD_GetFontsize("scr_centersize");
275 centerprint_expire = min(centerprint_expire, time); // if any of the returns happens, this message will fade out
277 if(cvar("scr_centertime") <= 0)
283 // strip trailing newlines
284 j = strlen(strMessage) - 1;
285 while(substring(strMessage, j, 1) == "\n" && j >= 0)
287 strMessage = substring(strMessage, 0, j + 1);
292 // strip leading newlines and remember them, they are a hint that the message should be lower on the screen
294 while(substring(strMessage, j, 1) == "\n" && j < strlen(strMessage))
296 strMessage = substring(strMessage, j, strlen(strMessage) - j);
297 centerprint_offset_hint = j;
302 // if we get here, we have a message. Initialize its height.
305 n = tokenizebyseparator(strMessage, "\n");
307 for(j = 0; j < n; ++j)
309 getWrappedLine_remaining = argv(j);
310 while(getWrappedLine_remaining)
312 s = getWrappedLine(vid_conwidth * 0.75, centerprint_fontsize, stringwidth_colors);
313 if(centerprint_messages[i])
314 strunzone(centerprint_messages[i]);
315 centerprint_messages[i] = strzone(s);
316 centerprint_width[i] = stringwidth(s, TRUE, centerprint_fontsize);
319 // half height for empty lines looks better
325 if(i >= CENTERPRINT_MAX_LINES)
331 h = centerprint_fontsize_y*hcount;
333 havail = vid_conheight;
334 if(cvar("con_chatpos") < 0)
335 havail -= (-cvar("con_chatpos") + cvar("con_chat")) * cvar("con_chatsize"); // avoid overlapping chat
336 if(havail > vid_conheight - 70)
337 havail = vid_conheight - 70; // avoid overlapping HUD
339 centerprint_start_x = 0;
342 float forbiddenmin, forbiddenmax, allowedmin, allowedmax, preferred;
344 // here, the centerprint would cover the crosshair. REALLY BAD.
345 forbiddenmin = vid_conheight * 0.5 - h - 16;
346 forbiddenmax = vid_conheight * 0.5 + 16;
348 allowedmin = scoreboard_bottom;
349 allowedmax = havail - h;
350 preferred = (havail - h)/2;
353 // possible orderings (total: 4! / 4 = 6)
354 // allowedmin allowedmax forbiddenmin forbiddenmax
355 // forbiddenmin forbiddenmax allowedmin allowedmax
356 if(allowedmax < forbiddenmin || allowedmin > forbiddenmax)
358 // forbidden doesn't matter in this case
359 centerprint_start_y = bound(allowedmin, preferred, allowedmax);
361 // allowedmin forbiddenmin allowedmax forbiddenmax
362 else if(allowedmin < forbiddenmin && allowedmax < forbiddenmax)
364 centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
366 // allowedmin forbiddenmin forbiddenmax allowedmax
367 else if(allowedmin < forbiddenmin)
369 // make sure the forbidden zone is not covered
370 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
371 centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
373 centerprint_start_y = bound(forbiddenmax, preferred, allowedmin);
375 // forbiddenmin allowedmin allowedmax forbiddenmax
376 else if(allowedmax < forbiddenmax)
378 // it's better to leave the allowed zone (overlap with scoreboard) than
379 // to cover the forbidden zone (crosshair)
380 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
381 centerprint_start_y = forbiddenmax;
383 centerprint_start_y = forbiddenmin;
385 // forbiddenmin allowedmin forbiddenmax allowedmax
388 centerprint_start_y = bound(forbiddenmax, preferred, allowedmax);
391 centerprint_start_y =
394 max(scoreboard_bottom, vid_conheight * 0.5 + 16),
402 centerprint_expire = time + cvar("scr_centertime");
405 void HUD_DrawCenterPrint (void)
412 //if(time > centerprint_expire)
415 //a = bound(0, 1 - 2 * (time - centerprint_expire), 1);
416 a = bound(0, 1 - 4 * (time - centerprint_expire), 1);
417 //sz = 1.2 / (a + 0.2);
422 pos = centerprint_start;
423 for (i=0; i<centerprint_num; i = i + 1)
425 pos_x = (vid_conwidth - centerprint_width[i]) * 0.5;
426 ts = centerprint_messages[i];
429 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
430 drawcolorcodedstring(pos, ts, centerprint_fontsize, a, DRAWFLAG_NORMAL);
431 // - '0 0.5 0' * (sz - 1) * centerprint_fontsize_x - '0.5 0 0' * (sz - 1) * centerprint_width[i] * centerprint_fontsize_y, centerprint_fontsize * sz
432 pos_y = pos_y + centerprint_fontsize_y;
435 // half height for empty lines looks better
436 pos_y = pos_y + centerprint_fontsize_y * 0.5;
440 void drawstringright(vector position, string text, vector scale, vector rgb, float alpha, float flag)
442 position_x -= 2 / 3 * strlen(text) * scale_x;
443 drawstring(position, text, scale, rgb, alpha, flag);
446 void drawstringcenter(vector position, string text, vector scale, vector rgb, float alpha, float flag)
448 position_x = 0.5 * (vid_conwidth - 0.6025 * strlen(text) * scale_x);
449 drawstring(position, text, scale, rgb, alpha, flag);
452 // return the string of the given race place
453 string race_PlaceName(float pos) {
461 return strcat(ftos(pos), "th");
464 // return the string of the onscreen race timer
465 string MakeRaceString(float cp, float mytime, float histime, float lapdelta, string hisname)
473 if(histime == 0) // goal hit
477 timestr = strcat("+", ftos_decimals(+mytime, TIME_DECIMALS));
487 timestr = strcat("-", ftos_decimals(-mytime, TIME_DECIMALS));
493 lapstr = strcat(" (-", ftos(lapdelta), "L)");
496 else if(lapdelta < 0)
498 lapstr = strcat(" (+", ftos(-lapdelta), "L)");
502 else if(histime > 0) // anticipation
504 if(mytime >= histime)
505 timestr = strcat("+", ftos_decimals(mytime - histime, TIME_DECIMALS));
507 timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(histime));
514 cpname = "Start line";
516 cpname = "Finish line";
518 cpname = strcat("Intermediate ", ftos(cp));
520 cpname = "Finish line";
523 return strcat(col, cpname);
524 else if(hisname == "")
525 return strcat(col, cpname, " (", timestr, ")");
527 return strcat(col, cpname, " (", timestr, " ", strcat(hisname, col, lapstr), ")");
530 // Check if the given name already exist in race rankings? In that case, where? (otherwise return 0)
531 float race_CheckName(string net_name) {
533 for (i=RANKINGS_CNT-1;i>=0;--i)
534 if(grecordholder[i] == net_name)
545 string HUD_Panel_GetName(float id)
548 case 0: return "weaponicons"; break;
549 case 1: return "inventory"; break;
550 case 2: return "powerups"; break;
551 case 3: return "healtharmor"; break;
552 case 4: return "notify"; break;
553 case 5: return "timer"; break;
554 case 6: return "radar"; break;
555 case 7: return "score"; break;
556 case 8: return "racetimer"; break;
557 case 9: return "vote"; break;
558 case 10: return "pressedkeys"; break;
564 void HUD_Panel_ExportCfg(string cfgname)
567 fh = fopen(strcat("hud_", cvar_string("hud_skin"), "_", cfgname, ".cfg"), FILE_WRITE);
570 fputs(fh, strcat("seta hud_skin \"", cvar_string("hud_skin"), "\"", "\n"));
571 fputs(fh, strcat("seta hud_bg \"", cvar_string("hud_bg"), "\"", "\n"));
572 fputs(fh, strcat("seta hud_bg_color \"", cvar_string("hud_bg_color"), "\"", "\n"));
573 fputs(fh, strcat("seta hud_bg_alpha ", ftos(cvar("hud_bg_alpha")), "\n"));
574 fputs(fh, strcat("seta hud_bg_border ", ftos(cvar("hud_bg_border")), "\n"));
575 fputs(fh, strcat("seta hud_fg_alpha ", ftos(cvar("hud_fg_alpha")), "\n"));
578 fputs(fh, strcat("seta hud_dock \"", cvar_string("hud_dock"), "\"", "\n"));
579 fputs(fh, strcat("seta hud_dock_color \"", cvar_string("hud_dock_color"), "\"", "\n"));
580 fputs(fh, strcat("seta hud_dock_alpha ", ftos(cvar("hud_dock_alpha")), "\n"));
583 fputs(fh, strcat("seta hud_progressbar_alpha ", ftos(cvar("hud_progressbar_alpha")), "\n"));
584 fputs(fh, strcat("seta hud_progressbar_strength_color \"", cvar_string("hud_progressbar_strength_color"), "\"", "\n"));
585 fputs(fh, strcat("seta hud_progressbar_shield_color \"", cvar_string("hud_progressbar_shield_color"), "\"", "\n"));
586 fputs(fh, strcat("seta hud_progressbar_health_color \"", cvar_string("hud_progressbar_health_color"), "\"", "\n"));
587 fputs(fh, strcat("seta hud_progressbar_armor_color \"", cvar_string("hud_progressbar_armor_color"), "\"", "\n"));
588 fputs(fh, strcat("seta hud_progressbar_fuel_color \"", cvar_string("hud_progressbar_fuel_color"), "\"", "\n"));
591 // common cvars for all panels
593 for (i = 0; i < panel_cnt; ++i)
595 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), " ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i)))), "\n"));
596 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_pos \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_pos")), "\"", "\n"));
597 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_size \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_size")), "\"", "\n"));
598 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg")), "\"", "\n"));
599 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_color \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg_color")), "\"", "\n"));
600 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_alpha ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_bg_alpha"))), "\n"));
601 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_border ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_bg_border"))), "\n"));
604 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_accuracy_height ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_accuracy_height"))), "\n"));
605 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_accuracy_yellow ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_accuracy_yellow"))), "\n"));
608 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_onlycurrent ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_onlycurrent"))), "\n"));
611 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_flip ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_flip"))), "\n"));
612 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_mirror ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_mirror"))), "\n"));
615 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_flip ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_flip"))), "\n"));
616 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_mirror ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_mirror"))), "\n"));
619 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_alreadyvoted_alpha ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_alreadyvoted_alpha"))), "\n"));
625 print("^2Successfully exported to hud_", cvar_string("hud_skin"), "_", cfgname, ".cfg! (Note: It's saved in data/data/)\n");
630 vector HUD_Panel_CheckLimitSize(float id, vector mySize)
634 mySize_x = max(mySize_y * (1/10), mySize_x); // at least 1/10 * height
635 mySize_y = max(mySize_x * (1/26), mySize_y); // at least 1/26 * width
638 mySize_x = max(mySize_y * 0.7, mySize_x); // at least 0.7 * height
641 // mySize_x = max(mySize_y * 1.5, mySize_x); // at least 1.5 * height
644 // mySize_x = max(mySize_y * 2, mySize_x); // at least 2 * height
647 mySize_y = (1/4.1) * mySize_x; // 1/4.1 * width, trial and error...
650 mySize_y = (1/4) * mySize_x; // 1/4 * width
653 mySize_y = (1/4) * mySize_x; // 1/4 * width
656 mySize_y = (1/4) * mySize_x; // 1/4 * width
659 mySize_y = 0.5898 * mySize_x; // 0.5898 * width, reason: bg has weird dimensions...
665 // return active status of panel
666 float HUD_Panel_CheckActive(float id)
668 if (cvar_or(strcat("hud_", HUD_Panel_GetName(id)), 1))
673 // return size of given panel
674 vector HUD_Panel_GetSize(float id)
677 mySize = stov(cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_size")));
679 mySize = eX * mySize_x * vid_conwidth + eY * mySize_y * vid_conheight;
684 // return pos of given panel
685 vector HUD_Panel_GetPos(float id)
688 pos = stov(cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_pos")));
690 pos = eX * pos_x * vid_conwidth + eY * pos_y * vid_conheight;
693 pos_x = vid_conwidth + pos_x;
695 pos_y = vid_conheight + pos_y;
699 float HUD_Panel_GetBorder(float id)
702 border = cvar(strcat("hud_", HUD_Panel_GetName(id), "_bg_border"));
704 border = cvar("hud_bg_border");
708 // draw the background/borders
709 void HUD_Panel_DrawBg(float id, vector pos, vector mySize)
711 if(!hud_configure && cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg")) == "0")
715 bg = cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg"));
717 bg = cvar_string("hud_bg");
722 border = HUD_Panel_GetBorder(id);
725 if(cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_color")) != "")
726 color = stov(cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_color")));
728 color = stov(cvar_string("hud_bg_color"));
731 alpha = cvar(strcat("hud_", HUD_Panel_GetName(id), "_bg_alpha"));
733 alpha = cvar("hud_bg_alpha");
735 alpha = max(cvar("hud_configure_bg_minalpha"), alpha);
737 draw_BorderPicture(pos - '1 1 0' * border, strcat("gfx/hud/", cvar_string("hud_skin"), "/", bg), mySize + '1 1 0' * 2 * border, color, alpha, '1 1 0' * (border/BORDER_MULTIPLIER));
741 vector HUD_Panel_GetProgressBarColor(string item)
743 return stov(cvar_string(strcat("hud_progressbar_", item, "_color")));
746 float resizeCorner; // 1 = topleft, 2 = topright, 3 = bottomleft, 4 = bottomright
747 // check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
748 vector HUD_Panel_CheckResize(float id, vector myPos, vector mySize)
760 for (i = 0; i < panel_cnt; ++i) {
761 if(i == id || !HUD_Panel_CheckActive(i))
764 targPos = HUD_Panel_GetPos(i);
765 targSize = HUD_Panel_GetSize(i);
767 targPos = HUD_Panel_GetPos(i) - '1 1 0' * HUD_Panel_GetBorder(id);
768 targSize = HUD_Panel_GetSize(i) + '2 2 0' * HUD_Panel_GetBorder(id);
770 if(myPos_y + mySize_y < targPos_y)
772 if(myPos_y > targPos_y + targSize_y)
775 if(myPos_x + mySize_x < targPos_x)
777 if(myPos_x > targPos_x + targSize_x)
780 // OK, there IS a collision.
782 myCenter_x = myPos_x + 0.5 * mySize_x;
783 myCenter_y = myPos_y + 0.5 * mySize_y;
785 targCenter_x = targPos_x + 0.5 * targSize_x;
786 targCenter_y = targPos_y + 0.5 * targSize_y;
789 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y && resizeCorner != 1) // top left (of target panel)
791 if(myPos_x + mySize_x - targPos_x < myPos_y + mySize_y - targPos_y) // push it to the side
792 myTarget_x = targPos_x - myPos_x;
793 else // push it upwards
794 myTarget_y = targPos_y - myPos_y;
796 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y && resizeCorner != 2) // top right
798 if(targPos_x + targSize_x - myPos_x < myPos_y + mySize_y - targPos_y) // push it to the side
799 myTarget_x = targPos_x + targSize_x;
800 else // push it upwards
801 myTarget_y = targPos_y - myPos_y;
803 else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
805 if(myPos_x + mySize_x - targPos_x < targPos_y + targSize_y - myPos_y) // push it to the side
806 myTarget_x = targPos_x - myPos_x;
807 else // push it downwards
808 myTarget_y = targPos_y + targSize_y;
810 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
812 if(targPos_x + targSize_x - myPos_x < targPos_y + targSize_y - myPos_y) // push it to the side
813 myTarget_x = targPos_x + targSize_x;
814 else // push it downwards
815 myTarget_y = targPos_y + targSize_y;
823 float HUD_Panel_SetSize(float id, vector mySize)
828 oldSize = stov(cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_size")));
831 myPos = HUD_Panel_GetPos(id);
833 // check for collisions
834 if(cvar("hud_configure_checkcollisions"))
835 mySize = HUD_Panel_CheckResize(id, HUD_Panel_GetPos(id), mySize);
837 mySize_x = bound(0.025 * vid_conwidth, mySize_x, vid_conwidth - myPos_x);
838 mySize_y = bound(0.025 * vid_conheight, mySize_y, vid_conheight - myPos_y);
840 // cap against panel's own limits
841 mySize = HUD_Panel_CheckLimitSize(id, mySize);
843 //mySize_x = bound(0.025 * vid_conwidth, mySize_x, vid_conwidth);
844 //mySize_y = bound(0.025 * vid_conheight, mySize_y, vid_conheight);
846 // TODO: is this needed?
847 // this is to check if (and how) SetPos should be called
848 if(mySize_x == oldSize_x && mySize_y == oldSize_y)
849 didntresize = 3; // didnt resize either
850 else if(mySize_x == oldSize_x && mySize_y != oldSize_y)
851 didntresize = 2; // resized Y
852 else if(mySize_y == oldSize_y && mySize_x != oldSize_x)
853 didntresize = 1; // resized X
856 s = strcat(ftos(mySize_x/vid_conwidth), " ", ftos(mySize_y/vid_conheight));
857 cvar_set(strcat("hud_", HUD_Panel_GetName(id), "_size"), s);
861 // check if move will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
862 vector HUD_Panel_CheckMove(float id, vector myPos, vector mySize)
874 for (i = 0; i < panel_cnt; ++i) {
875 if(i == id || !HUD_Panel_CheckActive(i))
878 targPos = HUD_Panel_GetPos(i) - '1 1 0' * HUD_Panel_GetBorder(id);
879 targSize = HUD_Panel_GetSize(i) + '2 2 0' * HUD_Panel_GetBorder(id);
881 if(myPos_y + mySize_y < targPos_y)
883 if(myPos_y > targPos_y + targSize_y)
886 if(myPos_x + mySize_x < targPos_x)
888 if(myPos_x > targPos_x + targSize_x)
891 // OK, there IS a collision.
893 myCenter_x = myPos_x + 0.5 * mySize_x;
894 myCenter_y = myPos_y + 0.5 * mySize_y;
896 targCenter_x = targPos_x + 0.5 * targSize_x;
897 targCenter_y = targPos_y + 0.5 * targSize_y;
900 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // top left (of the target panel)
902 if(myPos_x + mySize_x - targPos_x < myPos_y + mySize_y - targPos_y) // push it to the side
903 myTarget_x = targPos_x - mySize_x;
904 else // push it upwards
905 myTarget_y = targPos_y - mySize_y;
907 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y) // top right
909 if(targPos_x + targSize_x - myPos_x < myPos_y + mySize_y - targPos_y) // push it to the side
910 myTarget_x = targPos_x + targSize_x;
911 else // push it upwards
912 myTarget_y = targPos_y - mySize_y;
914 else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
916 if(myPos_x + mySize_x - targPos_x < targPos_y + targSize_y - myPos_y) // push it to the side
917 myTarget_x = targPos_x - mySize_x;
918 else // push it downwards
919 myTarget_y = targPos_y + targSize_y;
921 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
923 if(targPos_x + targSize_x - myPos_x < targPos_y + targSize_y - myPos_y) // push it to the side
924 myTarget_x = targPos_x + targSize_x;
925 else // push it downwards
926 myTarget_y = targPos_y + targSize_y;
933 void HUD_Panel_SetPos(float id, vector pos, float didntresize)
936 oldPos = HUD_Panel_GetPos(id);
939 else if(didntresize == 1)
941 else if(didntresize == 3)
945 mySize = HUD_Panel_GetSize(id);
947 if(cvar("hud_configure_checkcollisions"))
948 pos = HUD_Panel_CheckMove(id, pos, mySize);
950 pos_x = bound(0, pos_x, vid_conwidth - mySize_x);
951 pos_y = bound(0, pos_y, vid_conheight - mySize_y);
953 if (pos_x + 0.5 * mySize_x > 0.5 * vid_conwidth)
954 pos_x = pos_x - vid_conwidth;
955 if (pos_y + 0.5 * mySize_y > 0.5 * vid_conheight)
956 pos_y = pos_y - vid_conheight;
959 s = strcat(ftos(pos_x/vid_conwidth), " ", ftos(pos_y/vid_conheight));
961 cvar_set(strcat("hud_", HUD_Panel_GetName(id), "_pos"), s);
965 float prevMouseClicked; // previous state
966 float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
968 prevMouseClicked = mouseClicked;
969 if(nPrimary == K_MOUSE1)
971 if(bInputType == 0) { // key pressed
975 if(bInputType == 1) {// key released
983 vector mousepos, mouseprevpos;
984 vector panel_click_distance; // mouse cursor distance from the top left corner of the panel (saved only upon a click)
985 vector panel_click_pos; // panel pos (saved only upon a click)
986 vector panel_click_size; // panel size (saved only upon a click)
987 float highlightedPanel;
988 float highlightedAction; // 0 = nothing, 1 = move, 2 = resize
989 void HUD_Panel_Mouse()
991 if(mouseClicked == 0) {
992 highlightedPanel = -1;
993 highlightedAction = 0;
996 mousepos = mousepos + getmousepos();
998 mousepos_x = bound(0, mousepos_x, vid_conwidth);
999 mousepos_y = bound(0, mousepos_y, vid_conheight);
1001 drawpic(mousepos, strcat("gfx/menu/", cvar_string("menu_skin"), "/cursor.tga"), '32 32 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1009 for(i = 0; i <= panel_cnt; ++i)
1011 panelPos = HUD_Panel_GetPos(i);
1012 panelSize = HUD_Panel_GetSize(i);
1013 border = HUD_Panel_GetBorder(i);
1014 if(prevMouseClicked == 0) {
1016 if(mousepos_x >= panelPos_x && mousepos_y >= panelPos_y && mousepos_x <= panelPos_x + panelSize_x && mousepos_y <= panelPos_y + panelSize_y)
1018 highlightedPanel = i;
1019 highlightedAction = 1;
1021 // resize from topleft border
1022 else if(mousepos_x >= panelPos_x - border && mousepos_y >= panelPos_y - border && mousepos_x <= panelPos_x + 0.5 * panelSize_x && mousepos_y <= panelPos_y + 0.5 * panelSize_y)
1024 highlightedPanel = i;
1025 highlightedAction = 2;
1028 // resize from topright border
1029 else if(mousepos_x >= panelPos_x + 0.5 * panelSize_x && mousepos_y >= panelPos_y - border && mousepos_x <= panelPos_x + panelSize_x + border && mousepos_y <= panelPos_y + 0.5 * panelSize_y)
1031 highlightedPanel = i;
1032 highlightedAction = 2;
1035 // resize from bottomleft border
1036 else if(mousepos_x >= panelPos_x - border && mousepos_y >= panelPos_y + 0.5 * panelSize_y && mousepos_x <= panelPos_x + 0.5 * panelSize_x && mousepos_y <= panelPos_y + panelSize_y + border)
1038 highlightedPanel = i;
1039 highlightedAction = 2;
1042 // resize from bottomright border
1043 else if(mousepos_x >= panelPos_x + 0.5 * panelSize_x && mousepos_y >= panelPos_y + 0.5 * panelSize_y && mousepos_x <= panelPos_x + panelSize_x + border && mousepos_y <= panelPos_y + panelSize_y + border)
1045 highlightedPanel = i;
1046 highlightedAction = 2;
1051 if(highlightedPanel == i)
1053 if(prevMouseClicked == 0)
1055 panel_click_distance = mousepos - panelPos;
1056 panel_click_pos = panelPos;
1057 panel_click_size = panelSize;
1060 if(highlightedAction == 1)
1061 HUD_Panel_SetPos(i, mousepos - panel_click_distance, 0);
1062 else if(highlightedAction == 2)
1064 float didntresize; // panel too big/too small, dont resize (also has to affect moving)
1065 if(resizeCorner == 1) {
1066 didntresize = HUD_Panel_SetSize(i, panelSize + mouseprevpos - mousepos);
1067 HUD_Panel_SetPos(i, mousepos - panel_click_distance, didntresize);
1069 if(resizeCorner == 2) {
1070 didntresize = HUD_Panel_SetSize(i, eY * panel_click_size_y + eX * (mousepos_x - panelPos_x - (panel_click_distance_x - panel_click_size_x))
1071 + eY * (panel_click_distance_y + (panel_click_pos_y - mousepos_y)));
1072 HUD_Panel_SetPos(i, eX * panelPos_x + eY * (mousepos_y - panel_click_distance_y), didntresize);
1074 if(resizeCorner == 3) {
1075 didntresize = HUD_Panel_SetSize(i, panelSize + eX * (mouseprevpos_x - mousepos_x) + eY * (mousepos_y - mouseprevpos_y));
1076 HUD_Panel_SetPos(i, eX * (mousepos_x - panel_click_distance_x) + eY * panelPos_y, didntresize);
1078 if(resizeCorner == 4) {
1079 HUD_Panel_SetSize(i, mousepos - panelPos - (panel_click_distance - panel_click_size));
1085 mouseprevpos = mousepos;
1086 prevMouseClicked = mouseClicked;
1089 /*void HUD_DrawDockEdge(float id, vector p1, vector p2, float target)
1095 */ // maybe one day, since this will be quite complicated
1097 // Weapon icons (#0)
1100 float weaponspace[10];
1101 void HUD_WeaponIcons_Clear()
1104 for(idx = 0; idx < 10; ++idx)
1105 weaponspace[idx] = 0;
1108 entity weaponorder[WEP_MAXCOUNT];
1110 void weaponorder_swap(float i, float j, entity pass)
1114 weaponorder[i] = weaponorder[j];
1118 float weaponorder_cmp(float i, float j, entity pass)
1121 d = mod(weaponorder[i].impulse + 9, 10) - mod(weaponorder[j].impulse + 9, 10);
1124 d = weaponorder[i].weapon - weaponorder[j].weapon;
1128 void HUD_WeaponIcons()
1130 float alpha, height, accuracybar_height, stat_weapons; // "constants"
1131 vector pos, mySize, mysize, mypos, accuracy_color;
1132 float i, id, fade, weapon_stats, weapon_hit, weapon_damage, weapon_cnt; // variables
1134 pos = HUD_Panel_GetPos(0);
1135 mySize = HUD_Panel_GetSize(0);
1136 accuracybar_height = cvar_or("hud_weaponicons_accuracy_height", 3);
1138 stat_weapons = getstati(STAT_WEAPONS);
1139 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1141 self = get_weaponinfo(i);
1142 if(self.weapons && (self.impulse >= 0) && (stat_weapons & self.weapons) || hud_configure)
1144 weaponorder[weapon_cnt] = self;
1148 heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, world);
1150 HUD_Panel_DrawBg(0, pos, mySize);
1153 weapon_stats = getstati(STAT_DAMAGE_HITS);
1154 weapon_number = weapon_stats & 63;
1155 weapon_hits[weapon_number-WEP_FIRST] = floor(weapon_stats / 64);
1157 weapon_stats = getstati(STAT_DAMAGE_FIRED);
1158 weapon_number = weapon_stats & 63;
1159 weapon_fired[weapon_number-WEP_FIRST] = floor(weapon_stats / 64);
1161 if(cvar_or("hud_weaponicons_fade", 1))
1163 fade = 3.2 - 2 * (time - weapontime);
1164 fade = bound(0.7, fade, 1);
1169 HUD_WeaponIcons_Clear();
1171 float rows, columns;
1172 rows = mySize_y/mySize_x;
1173 rows = bound(1, floor((sqrt(4 * (2/1) * rows * WEP_COUNT + rows * rows) + rows + 0.5) / 2), WEP_COUNT);
1174 // ^^^ weapon icon aspect goes here
1176 columns = ceil(WEP_COUNT/rows);
1178 for(i = 0; i < weapon_cnt; ++i)
1180 self = weaponorder[i];
1181 if((self.weapons && (self.impulse >= 0) && (stat_weapons & self.weapons)) || hud_configure)
1185 alpha = (self.weapon == activeweapon) ? 1 : 0.6;
1187 weapon_hit = weapon_hits[self.weapon-WEP_FIRST];
1188 weapon_damage = weapon_fired[self.weapon-WEP_FIRST];
1190 if(self.weapon == activeweapon)
1191 drawpic_skin(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows), "weapon_current_bg", eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows), '1 1 1', fade * hud_alpha_fg, DRAWFLAG_NORMAL);
1192 drawpic(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows), strcat("gfx/weapons/weapon", self.netname), eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows), '1 1 1', fade * hud_alpha_fg, DRAWFLAG_NORMAL);
1194 if(cvar_or("hud_weaponicons_number", 1))
1195 drawstring(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows), ftos(id), '1 1 0' * 0.5 * mySize_y*(1/rows), '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1197 // draw the weapon accuracy on the HUD
1198 if(hud_accuracy_hud && !(gametype == GAME_RACE || gametype == GAME_CTS))
1201 weapon_stats = floor(100 * weapon_hit / weapon_damage);
1203 accuracy_color = HUD_AccuracyColor(weapon_stats);
1205 drawpic_skin(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows) - '2 0 0' + eY * (mySize_y/rows - accuracybar_height), "accuracy_bar.tga", eX * mySize_x*(1/columns) + eY * accuracybar_height, accuracy_color, hud_alpha_fg, DRAWFLAG_NORMAL);
1222 float GetAmmoStat(float i)
1226 case 0: return STAT_SHELLS;
1227 case 1: return STAT_NAILS;
1228 case 2: return STAT_ROCKETS;
1229 case 3: return STAT_CELLS;
1230 case 4: return STAT_FUEL;
1235 float GetAmmoItemCode(float i)
1239 case 0: return IT_SHELLS;
1240 case 1: return IT_NAILS;
1241 case 2: return IT_ROCKETS;
1242 case 3: return IT_CELLS;
1243 case 4: return IT_FUEL;
1248 string GetAmmoPicture(float i)
1252 case 0: return "ammo_shells";
1253 case 1: return "ammo_bullets";
1254 case 2: return "ammo_rocket";
1255 case 3: return "ammo_cells";
1256 case 4: return "ammo_fuel";
1261 void HUD_Inventory()
1266 vector pos, mySize, mysize, mypos;
1267 pos = HUD_Panel_GetPos(1);
1268 mySize = HUD_Panel_GetSize(1);
1270 HUD_Panel_DrawBg(1, pos, mySize);
1273 stat_items = getstati(STAT_ITEMS);
1274 for (i = 0; i < 4; ++i) {
1276 a = getstati(GetAmmoStat(i)); // how much ammo do we have of type i?
1280 if(cvar("hud_inventory_onlycurrent")) {
1281 if (stat_items & GetAmmoItemCode(i)) {
1282 drawpic_skin(pos, "ammo_current_bg", mySize, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1283 drawpic_skin(pos + eY * 0.05 * mySize_y, GetAmmoPicture(i), '1 1 0' * 0.8 * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1285 HUD_DrawXNum(pos + eX * 0.8 * mySize_y + eY * 0.25 * mySize_y, a, strlen(ftos(a)), 0, 0.5 * mySize_y, '0.7 0 0', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1287 HUD_DrawXNum(pos + eX * 0.8 * mySize_y + eY * 0.25 * mySize_y, a, strlen(ftos(a)), 0, 0.5 * mySize_y, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1291 if(mySize_x/mySize_y >= 10) { // arrange horizontally
1293 case 0: mypos_x = pos_x; mypos_y = pos_y; break; // shells
1294 case 1: mypos_x = pos_x + 0.25 * mySize_x; mypos_y = pos_y; break; // bullets
1295 case 2: mypos_x = pos_x + 0.5 * mySize_x; mypos_y = pos_y; break; // rockets
1296 case 3: mypos_x = pos_x + 0.75 * mySize_x; mypos_y = pos_y; break; // cells
1298 mysize_x = 0.25 * mySize_x;
1299 mysize_y = mySize_y;
1300 } else if(mySize_x/mySize_y >= 2.5) { // arrange in a 2x2 grid
1302 case 0: mypos_x = pos_x + 0.5 * mySize_x; mypos_y = pos_y + 0.5 * mySize_y; break; // shells
1303 case 1: mypos_x = pos_x + 0.5 * mySize_x; mypos_y = pos_y; break; // bullets
1304 case 2: mypos_x = pos_x; mypos_y = pos_y + 0.5 * mySize_y; break; // rockets
1305 case 3: mypos_x = pos_x; mypos_y = pos_y; break; // cells
1307 mysize_x = 0.5 * mySize_x;
1308 mysize_y = 0.5 * mySize_y;
1309 } else { // arrange vertically
1311 case 0: mypos_x = pos_x; mypos_y = pos_y; break; // shells
1312 case 1: mypos_x = pos_x; mypos_y = pos_y + 0.25 * mySize_y; break; // bullets
1313 case 2: mypos_x = pos_x; mypos_y = pos_y + 0.5 * mySize_y; break; // rockets
1314 case 3: mypos_x = pos_x; mypos_y = pos_y + 0.75 * mySize_y; break; // cells
1316 mysize_x = mySize_x;
1317 mysize_y = 0.25 * mySize_y;
1320 if (stat_items & GetAmmoItemCode(i))
1321 drawpic_skin(mypos, "ammo_current_bg", mysize, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1322 drawpic_skin(mypos + eY * 0.05 * mysize_y, GetAmmoPicture(i), '1 1 0' * 0.8 * mysize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1324 if(stat_items & GetAmmoItemCode(i))
1325 HUD_DrawXNum(mypos + eX * 0.8 * mysize_y + eY * 0.25 * mysize_y, a, strlen(ftos(a)), 0, 0.5 * mysize_y, '0.7 0 0', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1327 HUD_DrawXNum(mypos + eX * 0.8 * mysize_y + eY * 0.25 * mysize_y, a, strlen(ftos(a)), 0, 0.5 * mysize_y, '0.7 0 0', 0, 0, hud_alpha_fg * 0.7, DRAWFLAG_NORMAL);
1329 if(stat_items & GetAmmoItemCode(i))
1330 HUD_DrawXNum(mypos + eX * 0.8 * mysize_y + eY * 0.25 * mysize_y, a, strlen(ftos(a)), 0, 0.5 * mysize_y, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1332 HUD_DrawXNum(mypos + eX * 0.8 * mysize_y + eY * 0.25 * mysize_y, a, strlen(ftos(a)), 0, 0.5 * mysize_y, '0.7 0.7 0.7', 0, 0, hud_alpha_fg * 0.7, DRAWFLAG_NORMAL);
1341 float shield_maxtime;
1342 float strength_maxtime;
1343 void HUD_Powerups() {
1345 stat_items = getstati(STAT_ITEMS);
1349 if not(stat_items & IT_STRENGTH)
1350 if not(stat_items & IT_INVINCIBLE)
1353 if (getstati(STAT_HEALTH) <= 0)
1358 pos = HUD_Panel_GetPos(2);
1359 mySize = HUD_Panel_GetSize(2);
1361 HUD_Panel_DrawBg(2, pos, mySize);
1363 float strength_time, shield_time;
1365 strength_time = bound(0, ceil(getstatf(STAT_STRENGTH_FINISHED) - time), 99);
1366 shield_time = bound(0, ceil(getstatf(STAT_INVINCIBLE_FINISHED) - time), 99);
1376 vector barpos, barsize;
1380 string leftname, rightname;
1381 float leftcnt, rightcnt;
1382 float leftalpha, rightalpha;
1383 if (cvar(strcat("hud_", HUD_Panel_GetName(2), "_flip"))) {
1384 leftname = "strength";
1385 leftcnt = strength_time;
1387 rightname = "shield";
1388 rightcnt = shield_time;
1390 leftname = "shield";
1391 leftcnt = shield_time;
1393 rightname = "strength";
1394 rightcnt = strength_time;
1396 leftalpha = bound(0, leftcnt, 1);
1397 rightalpha = bound(0, rightcnt, 1);
1399 // TODO: tile statusbars?
1400 if (mySize_x/mySize_y > 4)
1404 len = strlen(ftos(leftcnt));
1406 if(cvar(strcat("hud_", HUD_Panel_GetName(2), "_mirror"))) {
1407 barpos = pos + eX * 0.5 * mySize_x - eX * 0.5 * mySize_x * min(1, leftcnt/30);
1408 barsize = eX * 0.5 * mySize_x * min(1, leftcnt/30) + eY * mySize_y;
1409 picpos = pos + eX * 0.5 * mySize_x - eX * mySize_y;
1410 numpos = picpos - eX * 2 * 0.5 * mySize_y + eX * (2-len) * 0.5 * mySize_y + eY * 0.25 * mySize_y;
1413 barsize = eX * 0.5 * mySize_x * min(1, leftcnt/30) + eY * mySize_y;
1415 numpos = picpos + eX * mySize_y - eX * (2-len) * 0.5 * mySize_y + eY * 0.25 * mySize_y;
1418 drawpic_skin(barpos, "statusbar", barsize, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1419 drawpic_skin(picpos, leftname, '1 1 0' * mySize_y, '1 1 1', leftalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1420 HUD_DrawXNum(numpos, leftcnt, 2, 0, 0.5 * mySize_y, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1425 len = strlen(ftos(rightcnt));
1427 if(cvar(strcat("hud_", HUD_Panel_GetName(2), "_mirror"))) {
1428 barpos = pos + eX * 0.5 * mySize_x;
1429 barsize = eX * 0.5 * mySize_x * min(1, rightcnt/30) + eY * mySize_y;
1430 picpos = pos + eX * 0.5 * mySize_x;
1431 numpos = picpos + eX * mySize_y - eX * (2-len) * 0.5 * mySize_y + eY * 0.25 * mySize_y;
1433 barpos = pos + eX * mySize_x - eX * 0.5 * mySize_x * min(1, rightcnt/30);
1434 barsize = eX * 0.5 * mySize_x * min(1, rightcnt/30) + eY * mySize_y;
1435 picpos = pos + eX * mySize_x - eX * mySize_y;
1436 numpos = picpos - eX * mySize_y + eY * 0.25 * mySize_y;
1439 drawpic_skin(barpos, "statusbar", barsize, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1440 drawpic_skin(picpos, rightname, '1 1 0' * mySize_y, '1 1 1', rightalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1441 HUD_DrawXNum(numpos, rightcnt, 2, 0, 0.5 * mySize_y, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1444 else if (mySize_x/mySize_y > 1.5)
1448 len = strlen(ftos(leftcnt));
1450 if(cvar(strcat("hud_", HUD_Panel_GetName(2), "_mirror"))) {
1451 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, leftcnt/30);
1452 barsize = eX * mySize_x * min(1, leftcnt/30) + eY * 0.5 * mySize_y;
1453 picpos = pos + eX * mySize_x - eX * 0.5 * mySize_y;
1454 numpos = picpos - eX * len * 0.5 * mySize_y;
1457 barsize = eX * mySize_x * min(1, leftcnt/30) + eY * 0.5 * mySize_y;
1459 numpos = picpos + eX * 0.5 * mySize_y;
1462 drawpic_skin(barpos, "statusbar", barsize, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1463 drawpic_skin(picpos, leftname, '0.5 0.5 0' * mySize_y, '1 1 1', leftalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1464 HUD_DrawXNum(numpos, leftcnt, len, 0, 0.5 * mySize_y, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1469 len = strlen(ftos(rightcnt));
1471 if(cvar(strcat("hud_", HUD_Panel_GetName(2), "_mirror"))) {
1472 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, rightcnt/30) + eY * 0.5 * mySize_y;
1473 barsize = eX * mySize_x * min(1, rightcnt/30) + eY * 0.5 * mySize_y;
1474 picpos = pos + eX * mySize_x - eX * 0.5 * mySize_y + eY * 0.5 * mySize_y;
1475 numpos = picpos - eX * len * 0.5 * mySize_y;
1477 barpos = pos + eY * 0.5 * mySize_y;
1478 barsize = eX * mySize_x * min(1, rightcnt/30) + eY * 0.5 * mySize_y;
1479 picpos = pos + eY * 0.5 * mySize_y;
1480 numpos = picpos + eX * 0.5 * mySize_y;
1483 drawpic_skin(barpos, "statusbar", barsize, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1484 drawpic_skin(picpos, rightname, '0.5 0.5 0' * mySize_y, '1 1 1', rightalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1485 HUD_DrawXNum(numpos, rightcnt, len, 0, 0.5 * mySize_y, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1492 len = strlen(ftos(leftcnt));
1494 if(cvar(strcat("hud_", HUD_Panel_GetName(2), "_mirror"))) {
1496 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/30);
1497 picpos = pos + eX * 0.05 * mySize_x;
1498 numpos = pos + eX * ((2-len)/2) * 0.25 * mySize_x + eY * 0.4 * mySize_x;
1500 barpos = pos + eY * mySize_y - eY * mySize_y * min(1, leftcnt/30);
1501 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/30);
1502 picpos = pos + eX * 0.05 * mySize_x + eY * mySize_y - eY * 0.65 * mySize_x;
1503 numpos = pos + eX * ((2-len)/2) * 0.25 * mySize_x + eY * mySize_y - eY * 0.25 * mySize_x;
1506 drawpic_skin(barpos, "statusbar_vertical", barsize, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1507 drawpic_skin(picpos, leftname, '0.4 0.4 0' * mySize_x, '1 1 1', leftalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1508 HUD_DrawXNum(numpos, leftcnt, len, 0, 0.25 * mySize_x, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1513 len = strlen(ftos(rightcnt));
1515 if(cvar(strcat("hud_", HUD_Panel_GetName(2), "_mirror"))) {
1516 barpos = pos + eX * 0.5 * mySize_x;
1517 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, rightcnt/30);
1518 picpos = pos + eX * 0.05 * mySize_x + eX * 0.5 * mySize_x;
1519 numpos = pos + eX * ((2-len)/2) * 0.25 * mySize_x + eY * 0.4 * mySize_x + eX * 0.5 * mySize_x;
1521 barpos = pos + eY * mySize_y - eY * mySize_y * min(1, rightcnt/30) + eX * 0.5 * mySize_x;
1522 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, rightcnt/30);
1523 picpos = pos + eX * 0.05 * mySize_x + eY * mySize_y - eY * 0.65 * mySize_x + eX * 0.5 * mySize_x;
1524 numpos = pos + eX * ((2-len)/2) * 0.25 * mySize_x + eY * mySize_y - eY * 0.25 * mySize_x + eX * 0.5 * mySize_x;
1527 drawpic_skin(barpos, "statusbar_vertical", barsize, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1528 drawpic_skin(picpos, rightname, '0.4 0.4 0' * mySize_x, '1 1 1', rightalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1529 HUD_DrawXNum(numpos, rightcnt, len, 0, 0.25 * mySize_x, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1533 /* TODO: add expand from old code!
1535 if (strength_time) {
1536 dt = strength_time - time;
1541 drawpic_expanding_two(pos, "str", '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE,
1542 bound(0, (ceil(dt) - dt) / 0.5, 1));
1546 drawpic_skin(pos, "str", '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE);
1548 HUD_DrawXNum(pos - '40 -2 0', ceil(dt), 2, 0, countdown_fontsize, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1552 drawpic_expanding(pos, "str", '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE,
1553 bound(0, -dt / 0.5, 1));
1558 if (invincibility_time) {
1559 dt = invincibility_time - time;
1564 drawpic_expanding_two(pos - '0 -22 0', "invinc", '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE,
1565 bound(0, (ceil(dt) - dt) / 0.5, 1));
1569 drawpic_skin(pos - '0 -22 0', "invinc", '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE);
1571 HUD_DrawXNum(pos - '40 -24 0', ceil(dt), 2, 0, countdown_fontsize, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1575 drawpic_expanding(pos - '0 -22 0', "invinc", '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE,
1576 bound(0, -dt / 0.5, 1));
1582 // Health/armor (#3)
1584 void HUD_HealthArmor(void)
1587 pos = HUD_Panel_GetPos(3);
1588 mySize = HUD_Panel_GetSize(3);
1590 HUD_Panel_DrawBg(3, pos, mySize);
1592 float armor, health, x;
1593 armor = getstati(STAT_ARMOR);
1594 health = getstati(STAT_HEALTH);
1597 fuel = getstati(GetAmmoStat(4)); // how much fuel do we have?
1613 if(hud_hudselector == 2) // combined health and armor display
1616 v = healtharmor_maxdamage(health, armor, armorblockpercent);
1619 num_pos = - '96 28 0';
1623 if(v_z) // fully armored
1625 // here, armorideal > armor
1626 drawpic_skin(num_pos + '78 -4.5 0', "health", '32 32 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1627 drawpic_skin(num_pos + '108 -4.5 0', "armor", '20 20 0', '1 1 1', hud_alpha_fg * armor / v_y, DRAWFLAG_NORMAL);
1631 drawpic_skin(num_pos + '108 -4.5 0', "health", '20 20 0', '1 1 1', hud_alpha_fg * v_y / armor, DRAWFLAG_NORMAL);
1632 drawpic_skin(num_pos + '78 -4.5 0', "armor", '32 32 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1634 HUD_DrawXNum_Colored(num_pos, x, 3, 24, hud_alpha_fg); // draw the combined health and armor
1640 vector barpos, barsize;
1644 string leftname, rightname;
1645 float leftcnt, rightcnt;
1646 float leftactive, rightactive;
1647 float leftalpha, rightalpha;
1649 if (cvar(strcat("hud_", HUD_Panel_GetName(3), "_flip"))) { // old style layout with armor left/top of health
1654 leftalpha = min((armor+10)/55, 1);
1656 rightname = "health";
1661 leftname = "health";
1666 rightname = "armor";
1670 rightalpha = min((armor+10)/55, 1);
1673 // TODO: tile statusbars?
1674 if (mySize_x/mySize_y > 5)
1678 len = strlen(ftos(leftcnt));
1680 if(cvar(strcat("hud_", HUD_Panel_GetName(3), "_mirror"))) {
1681 barpos = pos + eX * 0.5 * mySize_x - eX * 0.5 * mySize_x * min(1, leftcnt/200);
1682 barsize = eX * 0.5 * mySize_x * min(1, leftcnt/200) + eY * mySize_y;
1683 picpos = pos + eX * 0.5 * mySize_x - eX * mySize_y;
1684 numpos = picpos - eX * 3 * 0.5 * mySize_y + eX * (3-len) * 0.5 * mySize_y + eY * 0.25 * mySize_y;
1687 barsize = eX * 0.5 * mySize_x * min(1, leftcnt/200) + eY * mySize_y;
1689 numpos = picpos + eX * mySize_y + eY * 0.25 * mySize_y;
1692 drawpic_skin(barpos, "statusbar", barsize, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1693 drawpic_skin(picpos, leftname, '1 1 0' * mySize_y, '1 1 1', leftalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1694 HUD_DrawXNum_Colored(numpos, leftcnt, len, 0.5 * mySize_y, hud_alpha_fg);
1699 len = strlen(ftos(rightcnt));
1701 if(cvar(strcat("hud_", HUD_Panel_GetName(3), "_mirror"))) {
1702 barpos = pos + eX * 0.5 * mySize_x;
1703 barsize = eX * 0.5 * mySize_x * min(1, rightcnt/200) + eY * mySize_y;
1704 picpos = pos + eX * 0.5 * mySize_x;
1705 numpos = picpos + eX * mySize_y - eX * (3-len) * 0.5 * mySize_y + eY * 0.25 * mySize_y;
1707 barpos = pos + eX * mySize_x - eX * 0.5 * mySize_x * min(1, rightcnt/200);
1708 barsize = eX * 0.5 * mySize_x * min(1, rightcnt/200) + eY * mySize_y;
1709 picpos = pos + eX * mySize_x - eX * mySize_y;
1710 numpos = picpos - eX * 1.5 * mySize_y + eY * 0.25 * mySize_y;
1713 drawpic_skin(barpos, "statusbar", barsize, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1714 drawpic_skin(picpos, rightname, '1 1 0' * mySize_y, '1 1 1', rightalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1715 HUD_DrawXNum_Colored(numpos, rightcnt, 3, 0.5 * mySize_y, hud_alpha_fg);
1719 drawpic_skin(pos, "statusbar", eX * mySize_x * min(1, fuel/100) + eY * 0.2 * mySize_y, HUD_Panel_GetProgressBarColor("fuel"), hud_alpha_fg * 0.8, DRAWFLAG_NORMAL);
1721 else if (mySize_x/mySize_y > 2)
1725 len = strlen(ftos(leftcnt));
1727 if(cvar(strcat("hud_", HUD_Panel_GetName(3), "_mirror"))) {
1728 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, leftcnt/200);
1729 barsize = eX * mySize_x * min(1, leftcnt/200) + eY * 0.5 * mySize_y;
1730 picpos = pos + eX * mySize_x - eX * 0.5 * mySize_y;
1731 numpos = picpos - eX * len * 0.5 * mySize_y;
1734 barsize = eX * mySize_x * min(1, leftcnt/200) + eY * 0.5 * mySize_y;
1736 numpos = picpos + eX * 0.5 * mySize_y;
1739 drawpic_skin(barpos, "statusbar", barsize, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1740 drawpic_skin(picpos, leftname, '0.5 0.5 0' * mySize_y, '1 1 1', leftalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1741 HUD_DrawXNum_Colored(numpos, leftcnt, len, 0.5 * mySize_y, hud_alpha_fg);
1746 len = strlen(ftos(rightcnt));
1748 if(cvar(strcat("hud_", HUD_Panel_GetName(3), "_mirror"))) {
1749 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, rightcnt/200) + eY * 0.5 * mySize_y;
1750 barsize = eX * mySize_x * min(1, rightcnt/200) + eY * 0.5 * mySize_y;
1751 picpos = pos + eX * mySize_x - eX * 0.5 * mySize_y + eY * 0.5 * mySize_y;
1752 numpos = picpos - eX * len * 0.5 * mySize_y;
1754 barpos = pos + eY * 0.5 * mySize_y;
1755 barsize = eX * mySize_x * min(1, rightcnt/200) + eY * 0.5 * mySize_y;
1756 picpos = pos + eY * 0.5 * mySize_y;
1757 numpos = picpos + eX * 0.5 * mySize_y;
1760 drawpic_skin(barpos, "statusbar", barsize, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1761 drawpic_skin(picpos, rightname, '0.5 0.5 0' * mySize_y, '1 1 1', rightalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1762 HUD_DrawXNum_Colored(numpos, rightcnt, len, 0.5 * mySize_y, hud_alpha_fg);
1765 if(cvar(strcat("hud_", HUD_Panel_GetName(3), "_mirror"))) {
1766 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, fuel/100);
1767 barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.1 * mySize_y;
1770 barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.1 * mySize_y;
1773 drawpic_skin(barpos, "statusbar", barsize, HUD_Panel_GetProgressBarColor("fuel"), hud_alpha_fg * 0.8, DRAWFLAG_NORMAL);
1779 len = strlen(ftos(leftcnt));
1781 if(cvar(strcat("hud_", HUD_Panel_GetName(3), "_mirror"))) {
1783 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/200);
1784 picpos = pos + eX * 0.05 * mySize_x;
1785 numpos = pos + eX * ((3-len)/2) * 0.25 * mySize_x + eY * 0.4 * mySize_x;
1787 barpos = pos + eY * mySize_y - eY * mySize_y * min(1, leftcnt/200);
1788 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/200);
1789 picpos = pos + eX * 0.05 * mySize_x + eY * mySize_y - eY * 0.566 * mySize_x;
1790 numpos = pos + eX * ((3-len)/2) * 0.25 * mySize_x + eY * mySize_y - eY * 0.166 * mySize_x;
1793 drawpic_skin(barpos, "statusbar_vertical", barsize, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1794 drawpic_skin(picpos, leftname, '0.4 0.4 0' * mySize_x, '1 1 1', leftalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1795 HUD_DrawXNum_Colored(numpos, leftcnt, len, 0.166 * mySize_x, hud_alpha_fg);
1800 len = strlen(ftos(rightcnt));
1802 if(cvar(strcat("hud_", HUD_Panel_GetName(3), "_mirror"))) {
1803 barpos = pos + eX * 0.5 * mySize_x;
1804 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, rightcnt/200);
1805 picpos = pos + eX * 0.05 * mySize_x + eX * 0.5 * mySize_x;
1806 numpos = pos + eX * ((3-len)/2) * 0.25 * mySize_x + eY * 0.4 * mySize_x + eX * 0.5 * mySize_x;
1808 barpos = pos + eY * mySize_y - eY * mySize_y * min(1, rightcnt/200) + eX * 0.5 * mySize_x;
1809 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, rightcnt/200);
1810 picpos = pos + eX * 0.05 * mySize_x + eY * mySize_y - eY * 0.566 * mySize_x + eX * 0.5 * mySize_x;
1811 numpos = pos + eX * ((3-len)/2) * 0.25 * mySize_x + eY * mySize_y - eY * 0.166 * mySize_x + eX * 0.5 * mySize_x;
1814 drawpic_skin(barpos, "statusbar_vertical", barsize, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1815 drawpic_skin(picpos, rightname, '0.4 0.4 0' * mySize_x, '1 1 1', rightalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1816 HUD_DrawXNum_Colored(numpos, rightcnt, len, 0.166 * mySize_x, hud_alpha_fg);
1819 if(cvar(strcat("hud_", HUD_Panel_GetName(3), "_mirror"))) {
1821 barsize = eX * 0.05 * mySize_x + eY * mySize_y * min(1, fuel/100);
1823 barpos = pos + eY * mySize_y - eY * mySize_y * min(1, fuel/100);
1824 barsize = eX * 0.05 * mySize_x + eY * mySize_y * min(1, fuel/100);
1827 drawpic_skin(barpos, "statusbar_vertical", barsize, HUD_Panel_GetProgressBarColor("fuel"), hud_alpha_fg * 0.8, DRAWFLAG_NORMAL);
1832 // Notification area (#4)
1833 void HUD_Notify (void)
1836 pos = HUD_Panel_GetPos(4);
1837 mySize = HUD_Panel_GetSize(4);
1839 HUD_Panel_DrawBg(4, pos, mySize);
1843 if(spectatee_status && !intermission)
1845 drawfont = hud_bigfont;
1846 if(spectatee_status == -1)
1849 s = GetPlayerName(spectatee_status - 1);
1850 // spectated player name between HUD and chat area, aligned to the left
1852 pos_y = - 50 - hud_fontsize_spec_y;
1853 s = textShortenToWidth(s, vid_conwidth/2.5, hud_fontsize_spec, stringwidth_colors);
1854 drawcolorcodedstring(pos, s, hud_fontsize_spec, hud_alpha_fg, DRAWFLAG_NORMAL);
1855 drawfont = hud_font;
1857 // spectator text in the upper right corner
1858 if(spectatee_status == -1)
1859 s = strcat("^1Press ^3", getcommandkey("primary fire", "+attack"), "^1 to spectate");
1861 s = strcat("^1Press ^3", getcommandkey("primary fire", "+attack"), "^1 for another player");
1863 if(spectatee_status == -1)
1864 s = strcat("^1Use ^3", getcommandkey("next weapon", "weapnext"), "^1 or ^3", getcommandkey("previous weapon", "weapprev"), "^1 to change the speed");
1866 s = strcat("^1Press ^3", getcommandkey("secondary fire", "+attack2"), "^1 to observe");
1868 s = strcat("^1Press ^3", getcommandkey("server info", "+show_info"), "^1 for gamemode info");
1870 if(gametype == GAME_ARENA)
1871 s = "^1Wait for your turn to join";
1872 else if(gametype == GAME_LMS)
1875 sk = playerslots[player_localentnum - 1];
1876 if(sk.(scores[ps_primary]) >= 666)
1877 s = "^1Match has already begun";
1878 else if(sk.(scores[ps_primary]) > 0)
1879 s = "^1You have no more lives left";
1881 s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
1884 s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
1886 //show restart countdown:
1887 if (time < getstatf(STAT_GAMESTARTTIME)) {
1889 //we need to ceil, otherwise the countdown would be off by .5 when using round()
1890 countdown = ceil(getstatf(STAT_GAMESTARTTIME) - time);
1891 s = strcat("^1Game starts in ^3", ftos(countdown), "^1 seconds");
1894 if(warmup_stage && !intermission)
1896 s = "^2Currently in ^1warmup^2 stage!";
1899 // move more important stuff more to the middle so its more visible
1902 if(mod(time, 1) >= 0.5)
1907 if(ready_waiting && !intermission && !spectatee_status)
1909 if(ready_waiting_for_me)
1912 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " to end warmup");
1914 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " once you are ready");
1919 s = strcat("^2Waiting for others to ready up to end warmup...");
1921 s = strcat("^2Waiting for others to ready up...");
1924 else if(warmup_stage && !intermission && !spectatee_status)
1926 s = strcat("^2Press ^3", getcommandkey("ready", "ready"), "^2 to end warmup");
1929 if(teamplay && !intermission && !spectatee_status && gametype != GAME_CA && teamnagger)
1931 float ts_min, ts_max;
1932 tm = teams.sort_next;
1935 for(; tm.sort_next; tm = tm.sort_next)
1937 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
1939 if(!ts_min) ts_min = tm.team_size;
1940 else ts_min = min(ts_min, tm.team_size);
1941 if(!ts_max) ts_max = tm.team_size;
1942 else ts_max = max(ts_max, tm.team_size);
1944 if ((ts_max - ts_min) > 1)
1946 s = strcat(blinkcolor, "Teamnumbers are unbalanced!");
1947 tm = GetTeam(myteam, false);
1949 if (tm.team != COLOR_SPECTATOR)
1950 if (tm.team_size == ts_max)
1951 s = strcat(s, " Press ^3", getcommandkey("team menu", "menu_showteamselect"), blinkcolor, " to adjust");
1963 pos = HUD_Panel_GetPos(5);
1964 mySize = HUD_Panel_GetSize(5);
1966 HUD_Panel_DrawBg(5, pos, mySize);
1968 float timelimit, elapsedTime, minutes, seconds, timeleft, minutesLeft, secondsLeft;
1970 timelimit = getstatf(STAT_TIMELIMIT);
1972 timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
1973 timeleft = ceil(timeleft);
1974 minutesLeft = floor(timeleft / 60);
1975 secondsLeft = timeleft - minutesLeft*60;
1978 if(minutesLeft >= 5 || warmup_stage || timelimit == 0) //don't use red or yellow in warmup or when there is no timelimit
1979 timer_color = '1 1 1'; //white
1980 else if(minutesLeft >= 1)
1981 timer_color = '1 1 0'; //yellow
1983 timer_color = '1 0 0'; //red
1985 if (cvar("hud_timer_increment") || timelimit == 0 || warmup_stage) {
1986 if (time < getstatf(STAT_GAMESTARTTIME)) {
1987 //while restart is still active, show 00:00
1988 minutes = seconds = 0;
1990 elapsedTime = floor(time - getstatf(STAT_GAMESTARTTIME)); //127
1991 minutes = floor(elapsedTime / 60);
1992 seconds = elapsedTime - minutes*60;
1995 minutes = minutesLeft;
1996 seconds = secondsLeft;
2001 minutes = min(minutes, 999);
2002 if(minutesLeft >= 1 || cvar("hud_timer_increment") || timelimit == 0 || warmup_stage) {
2003 HUD_DrawXNum(pos + eX * mySize_x - eX * 5.1 * mySize_y, minutes, 3, 0, mySize_y, timer_color, 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
2004 drawpic_skin(pos + eX * mySize_x - eX * 2.57 * mySize_y, "num_colon", '1 1 0' * mySize_y, timer_color, hud_alpha_fg, DRAWFLAG_NORMAL);
2006 HUD_DrawXNum(pos + eX * mySize_x - eX * 2 * mySize_y, seconds, -2, 0, mySize_y, timer_color, 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
2011 void HUD_Radar(void)
2014 pos = HUD_Panel_GetPos(6);
2015 mySize = HUD_Panel_GetSize(6);
2017 HUD_Panel_DrawBg(6, pos, mySize);
2019 local float color1, color2; // color already declared as a global in hud.qc
2022 float scale2d, normalsize, bigsize;
2025 teamradar_origin2d = pos + 0.5 * mySize; // TODO: stupid compat, should be removed
2026 teamradar_size2d = mySize;
2028 if(minimapname == "" && !ons_showmap)
2031 teamradar_loadcvars();
2033 switch(cl_teamradar_zoommode)
2037 f = current_zoomfraction;
2040 f = 1 - current_zoomfraction;
2050 switch(cl_teamradar_rotation)
2053 teamradar_angle = view_angles_y - 90;
2056 teamradar_angle = 90 * cl_teamradar_rotation;
2060 scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
2061 teamradar_size2d = mySize;
2063 teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0'; // we always center
2065 // pixels per world qu to match the teamradar_size2d_x range in the longest dimension
2066 if(cl_teamradar_rotation == 0)
2068 // max-min distance must fit the radar in any rotation
2069 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen2d(mi_max - mi_min));
2073 vector c0, c1, c2, c3, span;
2074 c0 = rotate(mi_min, teamradar_angle * DEG2RAD);
2075 c1 = rotate(mi_max, teamradar_angle * DEG2RAD);
2076 c2 = rotate('1 0 0' * mi_min_x + '0 1 0' * mi_max_y, teamradar_angle * DEG2RAD);
2077 c3 = rotate('1 0 0' * mi_max_x + '0 1 0' * mi_min_y, teamradar_angle * DEG2RAD);
2079 span_x = max4(c0_x, c1_x, c2_x, c3_x) - min4(c0_x, c1_x, c2_x, c3_x);
2080 span_y = max4(c0_y, c1_y, c2_y, c3_y) - min4(c0_y, c1_y, c2_y, c3_y);
2082 // max-min distance must fit the radar in x=x, y=y
2084 teamradar_size2d_x * scale2d / (1.05 * span_x),
2085 teamradar_size2d_y * scale2d / (1.05 * span_y)
2089 normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / cl_teamradar_scale;
2090 if(bigsize > normalsize)
2091 normalsize = bigsize;
2095 + (1 - f) * normalsize;
2096 teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
2097 f * (mi_min + mi_max) * 0.5
2098 + (1 - f) * view_origin);
2100 color1 = GetPlayerColor(player_localentnum-1);
2101 rgb = GetTeamRGB(color1);
2110 draw_teamradar_background(cl_teamradar_background_alpha, cl_teamradar_foreground_alpha);
2114 drawresetcliparea();
2116 vector frame_origin, frame_size;
2117 frame_origin = frame_size = '0 0 0';
2119 frame_origin_x = pos_x - teamradar_size2d_x * 0.55859375; // matches the picture
2120 frame_origin_y = pos_y - teamradar_size2d_y * 0.55859375; // matches the picture
2121 frame_size_x = pos_x * 1.1171875; // matches the picture
2122 frame_size_y = pos_y * 1.1171875; // matches the picture
2123 drawpic_skin(frame_origin, "gfx/ons-frame.tga", frame_size, '1 1 1', hud_alpha_fg, 0);
2124 drawpic_skin(frame_origin, "gfx/ons-frame-team.tga", frame_size, rgb, hud_alpha_fg, 0);
2127 pos_x - teamradar_size2d_x * 0.5,
2128 pos_y - teamradar_size2d_y * 0.5,
2134 for(tm = world; (tm = find(tm, classname, "radarlink")); )
2135 draw_teamradar_link(tm.origin, tm.velocity, tm.team);
2136 for(tm = world; (tm = findflags(tm, teamradar_icon, 0xFFFFFF)); )
2137 draw_teamradar_icon(tm.origin, tm.teamradar_icon, tm, tm.teamradar_color, hud_alpha_fg);
2138 for(tm = world; (tm = find(tm, classname, "entcs_receiver")); )
2140 color2 = GetPlayerColor(tm.sv_entnum);
2141 //if(color == COLOR_SPECTATOR || color == color2)
2142 draw_teamradar_player(tm.origin, tm.angles, GetTeamRGB(color2));
2144 draw_teamradar_player(view_origin, view_angles, '1 1 1');
2146 drawresetcliparea();
2154 pos = HUD_Panel_GetPos(7);
2155 mySize = HUD_Panel_GetSize(7);
2157 HUD_Panel_DrawBg(7, pos, mySize);
2159 float score, distribution, leader;
2160 float score_len, distr_len;
2161 vector score_pos, secondary_score_pos, distribution_color;
2163 me = (spectatee_status > 0) ? playerslots[spectatee_status - 1] : playerslots[player_localentnum - 1];
2165 if (!teamplay) { // non-teamgames
2166 // me vector := [team/connected frags id]
2167 pl = players.sort_next;
2174 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
2178 score = me.(scores[ps_primary]);
2182 if(distribution >= 5) {
2183 distribution_color = eY;
2185 } else if(distribution >= 0) {
2186 distribution_color = '1 1 1';
2188 } else if(distribution >= -5)
2189 distribution_color = '1 1 0';
2191 distribution_color = eX;
2193 score_len = strlen(ftos(score));
2194 distr_len = strlen(ftos(distribution));
2196 HUD_DrawXNum(pos + eX * mySize_x - eX * 3 * 0.33 * mySize_y, distribution, 3, 3, 0.33 * mySize_y, distribution_color, 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
2198 drawpic_skin(pos + eX * mySize_x - eX * score_len * mySize_y - eX * 3 * 0.33 * mySize_y, strcat("highlight_", ftos(score_len)), eX * score_len * mySize_y + eY * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2199 HUD_DrawXNum(pos + eX * mySize_x - eX * 3 * mySize_y - eX * 3 * 0.33 * mySize_y, score, 3, 0, mySize_y, distribution_color, 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
2200 } else { // teamgames
2201 float max_fragcount;
2202 max_fragcount = -99;
2205 for(tm = teams.sort_next; tm; tm = tm.sort_next) {
2206 if(tm.team == COLOR_SPECTATOR || (!tm.team_size && !hud_configure)) // no players? don't display
2208 score = tm.(teamscores[ts_primary]);
2213 score_len = strlen(ftos(score));
2215 if (score > max_fragcount)
2216 max_fragcount = score;
2218 if(tm.team == myteam) {
2219 if (max_fragcount == score)
2222 drawpic_skin(pos + eX * mySize_x - eX * score_len * mySize_y - eX * 3 * 0.33 * mySize_y, strcat("highlight_", ftos(score_len)), eX * score_len * mySize_y + eY * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2223 HUD_DrawXNum(pos + eX * mySize_x - eX * 3 * mySize_y - eX * 3 * 0.33 * mySize_y, score, 3, 0, mySize_y, GetTeamRGB(tm.team) * 0.8, 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
2225 if (max_fragcount == score)
2228 drawpic_skin(pos + eX * mySize_x - eX * 0.33 * score_len * mySize_y + eY * 0.33 * mySize_y * teamnum, strcat("highlight_", ftos(score_len)), eX * 0.33 * score_len * mySize_y + eY * 0.33 * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2229 HUD_DrawXNum(pos + eX * mySize_x - eX * 3 * 0.33 * mySize_y + eY * 0.33 * mySize_y * teamnum, score, 3, 0, 0.33 * mySize_y, GetTeamRGB(tm.team) * 0.8, 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
2238 void HUD_RaceTimer (void) {
2240 pos = HUD_Panel_GetPos(8);
2241 mySize = HUD_Panel_GetSize(8);
2243 HUD_Panel_DrawBg(8, pos, mySize);
2245 drawfont = hud_bigfont;
2247 string s, forcetime;
2252 drawstring(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(s, FALSE, '0.75 0.75 0' * mySize_y), s, '0.75 0.75 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2253 s = "^1Intermediate 1 (+15.42)";
2254 drawcolorcodedstring(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(s, TRUE, '1 1 0' * 0.25 * mySize_y) + eY * 0.75 * mySize_y, s, '1 1 0' * 0.25 * mySize_y, hud_alpha_fg, DRAWFLAG_NORMAL);
2256 else if(race_checkpointtime)
2258 a = bound(0, 2 - (time - race_checkpointtime), 1);
2261 if(a > 0) // just hit a checkpoint?
2263 if(race_checkpoint != 254)
2265 if(race_time && race_previousbesttime)
2266 s = MakeRaceString(race_checkpoint, TIME_DECODE(race_time) - TIME_DECODE(race_previousbesttime), 0, 0, race_previousbestname);
2268 s = MakeRaceString(race_checkpoint, 0, -1, 0, race_previousbestname);
2270 forcetime = TIME_ENCODED_TOSTRING(race_time);
2275 if(race_laptime && race_nextbesttime && race_nextcheckpoint != 254)
2277 a = bound(0, 2 - ((race_laptime + TIME_DECODE(race_nextbesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1);
2278 if(a > 0) // next one?
2280 s = MakeRaceString(race_nextcheckpoint, (time + TIME_DECODE(race_penaltyaccumulator)) - race_laptime, TIME_DECODE(race_nextbesttime), 0, race_nextbestname);
2285 if(s != "" && a > 0)
2287 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
2288 //drawcolorcodedstring(m - '0 16 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2289 drawcolorcodedstring(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(s, TRUE, '1 1 0' * 0.25 * mySize_y) + eY * 0.75 * mySize_y, s, '1 1 0' * 0.25 * mySize_y, hud_alpha_fg * a, DRAWFLAG_NORMAL);
2292 if(race_penaltytime)
2294 a = bound(0, 2 - (time - race_penaltyeventtime), 1);
2297 s = strcat("^1PENALTY: ", ftos_decimals(race_penaltytime * 0.1, 1), " (", race_penaltyreason, ")");
2298 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
2299 //drawcolorcodedstring(m - '0 32 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2300 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);
2306 a = bound(0, (time - race_checkpointtime) / 0.5, 1);
2307 //drawstring_expanding(m - '16 0 0' * stringwidth(forcetime, FALSE), forcetime, '32 32 0', '1 1 1', hud_alpha_fg, 0, a);
2308 drawstring_expanding(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(forcetime, FALSE, '1 1 0' * 0.75 * mySize_y), forcetime, '1 1 0' * 0.75 * mySize_y, '1 1 1', hud_alpha_fg, 0, a);
2313 if(race_laptime && race_checkpoint != 255)
2315 s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime));
2316 //drawstring(m - '16 0 0' * stringwidth(s, FALSE), s, '32 32 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2317 drawstring(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(s, FALSE, '0.75 0.75 0' * mySize_y), s, '0.75 0.75 0' * mySize_y, '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2322 if(race_mycheckpointtime)
2324 a = bound(0, 2 - (time - race_mycheckpointtime), 1);
2325 s = MakeRaceString(race_mycheckpoint, TIME_DECODE(race_mycheckpointdelta), -!race_mycheckpointenemy, race_mycheckpointlapsdelta, race_mycheckpointenemy);
2326 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
2327 //drawcolorcodedstring(m - '0 16 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2328 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);
2330 if(race_othercheckpointtime && race_othercheckpointenemy != "")
2332 a = bound(0, 2 - (time - race_othercheckpointtime), 1);
2333 s = MakeRaceString(race_othercheckpoint, -TIME_DECODE(race_othercheckpointdelta), -!race_othercheckpointenemy, race_othercheckpointlapsdelta, race_othercheckpointenemy);
2334 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
2335 //drawcolorcodedstring(m - '0 0 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2336 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);
2339 if(race_penaltytime && !race_penaltyaccumulator)
2341 t = race_penaltytime * 0.1 + race_penaltyeventtime;
2342 a = bound(0, (1 + t - time), 1);
2346 s = strcat("^1PENALTY: ", ftos_decimals(t - time, 1), " (", race_penaltyreason, ")");
2348 s = strcat("^2PENALTY: 0.0 (", race_penaltyreason, ")");
2349 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
2350 //drawcolorcodedstring(m - '0 32 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2351 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);
2356 drawfont = hud_font;
2360 float vote_yescount;
2363 float vote_highlighted; // currently selected vote
2365 float vote_active; // is there an active vote?
2366 float vote_prev; // previous state of vote_active to check for a change
2368 float vote_change; // "time" when vote_active changed
2370 void HUD_VoteWindow(void)
2373 pos = HUD_Panel_GetPos(9);
2374 mySize = HUD_Panel_GetSize(9);
2378 if(vote_active != vote_prev) {
2380 vote_prev = bound(0, vote_active, 1);
2384 vote_alpha = bound(0, (time - vote_change) * 2, 1);
2386 vote_alpha = bound(0, 1 - (time - vote_change) * 2, 1);
2396 HUD_Panel_DrawBg(9, pos, mySize);
2399 a = vote_alpha * bound(cvar_or("hud_vote_alreadyvoted_alpha", 0.75), 1 - vote_highlighted, 1);
2401 drawpic_skin(pos, "voteprogress_back", mySize, HUD_GetBgColor(), a * hud_alpha_bg, DRAWFLAG_NORMAL);
2403 s = "A vote has been called for: ";
2404 drawstring(pos + '0.5 0 0' * mySize_x + '0 0.1 0' * mySize_y - eX * stringwidth(s, FALSE, '1 1 0' * 0.5 * mySize_y*(1/5)), s, '1 1 0' * mySize_y*(1/5), '1 1 1', a * hud_alpha_fg, DRAWFLAG_NORMAL);
2405 s = textShortenToWidth(vote_called_vote, mySize_x * 0.96, '10 0 0', stringwidth_colors);
2407 s = "Configure the HUD";
2408 drawcolorcodedstring(pos + '0.52 0 0' * mySize_x + '0 0.3 0' * mySize_y - eX * stringwidth(s, FALSE, '1 1 0' * 0.5 * mySize_y*(1/6)), s, '1 1 0' * mySize_y*(1/6), a * hud_alpha_fg, DRAWFLAG_NORMAL);
2410 // print the yes/no counts
2411 s = strcat("Yes: ", ftos(vote_yescount));
2412 drawstring(pos + '0 0.6 0' * mySize_y + '0.02 0 0' * mySize_x, s, '1 1 0' * mySize_y*(1/6) , eY, a * hud_alpha_fg, DRAWFLAG_NORMAL);
2413 s = strcat("No: ", ftos(vote_nocount));
2414 drawstring(pos + '0 0.6 0' * mySize_y + '0.98 0 0' * mySize_x - eX * stringwidth(s, FALSE, '1 1 0' * mySize_y*(1/6)), s, '1 1 0' * mySize_y*(1/6), eX, a * hud_alpha_fg, DRAWFLAG_NORMAL);
2416 // draw the progress bars
2417 drawsetcliparea(pos_x, pos_y, mySize_x * 0.5 * (vote_yescount/vote_needed), mySize_y);
2418 drawpic_skin(pos, "voteprogress_prog", mySize, eY, a * hud_alpha_fg, DRAWFLAG_NORMAL);
2420 drawsetcliparea(pos_x + mySize_x - mySize_x * 0.5 * (vote_nocount/vote_needed), pos_y, mySize_x * 0.5, mySize_y);
2421 drawpic_skin(pos, "voteprogress_prog", mySize, eX, a * hud_alpha_fg, DRAWFLAG_NORMAL);
2423 // draw the highlights
2424 if(vote_highlighted == 1) {
2425 drawsetcliparea(pos_x, pos_y, mySize_x * 0.5, mySize_y);
2426 drawpic_skin(pos, "voteprogress_voted", mySize, eY, a * hud_alpha_fg, DRAWFLAG_NORMAL);
2428 else if(vote_highlighted == 2) {
2429 drawsetcliparea(pos_x + 0.5 * mySize_x, pos_y, mySize_x * 0.5, mySize_y);
2430 drawpic_skin(pos, "voteprogress_voted", mySize, eX, a * hud_alpha_fg, DRAWFLAG_NORMAL);
2433 drawresetcliparea();
2435 else if(!vote_active) {
2436 vote_highlighted = 0;
2441 float race_status_time;
2442 float race_status_prev;
2443 string race_status_name_prev;
2444 void HUD_DrawRaceStatus(vector pos)
2446 if (race_status != race_status_prev || race_status_name != race_status_name_prev) {
2447 race_status_time = time + 5;
2448 race_status_prev = race_status;
2449 if (race_status_name_prev)
2450 strunzone(race_status_name_prev);
2451 race_status_name_prev = strzone(race_status_name);
2455 a = bound(0, race_status_time - time, 1);
2458 s = textShortenToWidth(race_status_name, 120, '10 10 0', stringwidth_colors);
2462 rank = race_CheckName(race_status_name);
2464 rankname = race_PlaceName(rank);
2466 if(race_status == 0)
2467 drawpic_skin(pos, "race_newfail", '80 80 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2468 else if(race_status == 1) {
2469 drawpic_skin(pos, "race_newtime", '80 80 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2470 drawcolorcodedstring(pos + '40 80 0' - eX * stringwidth(s, TRUE, '5 0 0'), s, '10 10 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2471 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);
2472 } else if(race_status == 2) {
2473 if(race_status_name == GetPlayerName(player_localentnum -1) || !race_myrank || race_myrank < rank)
2474 drawpic_skin(pos, "race_newrankgreen", '80 80 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2476 drawpic_skin(pos, "race_newrankyellow", '80 80 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2477 drawcolorcodedstring(pos + '40 80 0' - eX * stringwidth(s, TRUE, '5 0 0'), s, '10 10 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2478 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);
2479 } else if(race_status == 3) {
2480 drawpic_skin(pos, "race_newrecordserver", '80 80 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2481 drawcolorcodedstring(pos + '40 80 0' - eX * stringwidth(s, TRUE, '5 0 0'), s, '10 10 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2482 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);
2485 if (race_status_time - time <= 0) {
2486 race_status_prev = -1;
2488 if(race_status_name)
2489 strunzone(race_status_name);
2490 race_status_name = string_null;
2491 if(race_status_name_prev)
2492 strunzone(race_status_name_prev);
2493 race_status_name_prev = string_null;
2497 // CTF HUD modicon section
2498 float redflag_prevframe, blueflag_prevframe; // status during previous frame
2499 float redflag_prevstatus, blueflag_prevstatus; // last remembered status
2500 float redflag_statuschange_time, blueflag_statuschange_time; // time when the status changed
2502 void CSQC_ctf_hudreset(void)
2504 redflag_prevstatus = blueflag_prevstatus = redflag_prevframe = blueflag_prevframe = redflag_statuschange_time = blueflag_statuschange_time = 0;
2507 void CSQC_ctf_hud(void)
2509 vector bottomleft, redflag_pos, blueflag_pos, sz;
2510 float f; // every function should have that
2511 bottomleft_y = vid_conheight;
2514 float redflag, blueflag; // current status
2515 float redflag_statuschange_elapsedtime, blueflag_statuschange_elapsedtime; // time since the status changed
2518 stat_items = getstati(STAT_ITEMS);
2519 redflag = (stat_items/IT_RED_FLAG_TAKEN) & 3;
2520 blueflag = (stat_items/IT_BLUE_FLAG_TAKEN) & 3;
2522 // when status CHANGES, set old status into prevstatus and current status into status
2523 if (redflag != redflag_prevframe)
2525 redflag_statuschange_time = time;
2526 redflag_prevstatus = redflag_prevframe;
2527 redflag_prevframe = redflag;
2530 if (blueflag != blueflag_prevframe)
2532 blueflag_statuschange_time = time;
2533 blueflag_prevstatus = blueflag_prevframe;
2534 blueflag_prevframe = blueflag;
2537 redflag_statuschange_elapsedtime = time - redflag_statuschange_time;
2538 blueflag_statuschange_elapsedtime = time - blueflag_statuschange_time;
2540 float BLINK_FACTOR = 0.15;
2541 float BLINK_BASE = 0.85;
2543 // RMS = sqrt(BLINK_BASE^2 + 0.5 * BLINK_FACTOR^2)
2545 // BLINK_BASE = sqrt(RMS^2 - 0.5 * BLINK_FACTOR^2)
2547 float BLINK_FREQ = 5; // circle frequency, = 2*pi*frequency in hertz
2549 string red_icon, red_icon_prevstatus;
2550 float red_alpha, red_alpha_prevstatus;
2551 red_alpha = red_alpha_prevstatus = 1;
2553 case 1: red_icon = "flag_red_taken"; break;
2554 case 2: red_icon = "flag_red_lost"; break;
2555 case 3: red_icon = "flag_red_carrying"; red_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
2557 if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM2))
2558 red_icon = "flag_red_shielded";
2560 red_icon = string_null;
2563 switch(redflag_prevstatus) {
2564 case 1: red_icon_prevstatus = "flag_red_taken"; break;
2565 case 2: red_icon_prevstatus = "flag_red_lost"; break;
2566 case 3: red_icon_prevstatus = "flag_red_carrying"; red_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
2569 red_icon_prevstatus = "flag_red_carrying"; // make it more visible
2570 else if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM2))
2571 red_icon_prevstatus = "flag_red_shielded";
2573 red_icon_prevstatus = string_null;
2577 string blue_icon, blue_icon_prevstatus;
2578 float blue_alpha, blue_alpha_prevstatus;
2579 blue_alpha = blue_alpha_prevstatus = 1;
2581 case 1: blue_icon = "flag_blue_taken"; break;
2582 case 2: blue_icon = "flag_blue_lost"; break;
2583 case 3: blue_icon = "flag_blue_carrying"; blue_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
2585 if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM1))
2586 blue_icon = "flag_blue_shielded";
2588 blue_icon = string_null;
2591 switch(blueflag_prevstatus) {
2592 case 1: blue_icon_prevstatus = "flag_blue_taken"; break;
2593 case 2: blue_icon_prevstatus = "flag_blue_lost"; break;
2594 case 3: blue_icon_prevstatus = "flag_blue_carrying"; blue_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
2597 blue_icon_prevstatus = "flag_blue_carrying"; // make it more visible
2598 else if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM1))
2599 blue_icon_prevstatus = "flag_blue_shielded";
2601 blue_icon_prevstatus = string_null;
2605 if (myteam == COLOR_TEAM1) { // always draw own flag on left
2606 redflag_pos = bottomleft - '-4 50 0';
2607 blueflag_pos = bottomleft - '-62 50 0';
2609 blueflag_pos = bottomleft - '-4 50 0';
2610 redflag_pos = bottomleft - '-62 50 0';
2615 f = bound(0, redflag_statuschange_elapsedtime*2, 1);
2616 if(red_icon_prevstatus && f < 1)
2617 drawpic_expanding(redflag_pos, red_icon_prevstatus, sz, '1 1 1', hud_alpha_fg * red_alpha_prevstatus, DRAWFLAG_NORMAL, f);
2619 drawpic_skin(redflag_pos, red_icon, sz, '1 1 1', hud_alpha_fg * red_alpha * f, DRAWFLAG_NORMAL);
2621 f = bound(0, blueflag_statuschange_elapsedtime*2, 1);
2622 if(blue_icon_prevstatus && f < 1)
2623 drawpic_expanding(blueflag_pos, blue_icon_prevstatus, sz, '1 1 1', hud_alpha_fg * blue_alpha_prevstatus, DRAWFLAG_NORMAL, f);
2625 drawpic_skin(blueflag_pos, blue_icon, sz, '1 1 1', hud_alpha_fg * blue_alpha * f, DRAWFLAG_NORMAL);
2628 /*void HUD_Mod_Race (void) {
2629 if((scores_flags[ps_primary] & SFL_TIME) && !teamplay) { // race/cts record display on HUD
2630 pl = players.sort_next;
2633 if(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)
2634 if(pl.scores[ps_primary] == 0)
2637 score = me.(scores[ps_primary]);
2639 float racemin, racesec, racemsec;
2640 float distsec, distmsec, minusplus;
2642 racemin = floor(score/(60 * TIME_FACTOR));
2643 racesec = floor((score - racemin*(60 * TIME_FACTOR))/TIME_FACTOR);
2644 racemsec = score - racemin*60*TIME_FACTOR - racesec*TIME_FACTOR;
2646 if (pl && ((!(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)) || score)) {
2647 // distribution display
2648 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
2650 if (distribution < TIME_FACTOR && distribution > -TIME_FACTOR)
2651 distmsec = fabs(distribution);
2653 distsec = floor(fabs(distribution)/TIME_FACTOR);
2654 distmsec = fabs(distribution) - distsec*TIME_FACTOR;
2655 if (distribution < 0)
2659 if (distribution <= 0) {
2660 distribution_color = eY;
2661 minusplus = 1; // minusplus 1: always prefix with minus sign
2664 distribution_color = eX;
2665 minusplus = 2; // minusplus 1: always prefix with plus sign
2667 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);
2668 HUD_DrawXNum(bottomright - '68 48 0' - '16 0 0' * TIME_DECIMALS, distsec, 4, minusplus, 16, distribution_color, 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
2669 drawpic_skin(bottomright - '10 48 0' - '16 0 0' * TIME_DECIMALS, "num_dot", '16 16 0', distribution_color, hud_alpha_fg, DRAWFLAG_ADDITIVE);
2671 // race record display
2672 if (distribution <= 0 || distribution == score) // draw the highlight background behind the timer if we have the lead
2673 drawpic_skin(bottomright - '0 32 0' - '32 0 0' * (4 + TIME_DECIMALS), "highlight_4", '0 28 0' + '32 0 0' * (4 + TIME_DECIMALS), '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2675 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);
2676 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);
2677 drawpic_skin(bottomright - '0 32 0' - TIME_DECIMALS * '30 0 0' - '18 0 0', "num_dot", '30 30 0', '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE);
2679 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);
2680 drawpic_skin(bottomright - '0 32 0' - TIME_DECIMALS * '30 0 0' - '84 0 0', "num_colon", '30 30 0', '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE);
2684 // Keyhunt HUD modicon section
2685 float kh_runheretime;
2687 void CSQC_kh_hudreset(void)
2692 void CSQC_kh_hud(void)
2697 vector p, pa, kh_size, kh_asize;
2700 p_y = vid_conheight - 34 - 3;
2703 kh_keys = getstati(STAT_KH_KEYS);
2705 kh_size = '19 34 0';
2706 kh_asize = '19 10 0';
2713 for(i = 0; i < 4; ++i)
2715 key = floor(kh_keys / pow(32, i)) & 31;
2717 if(keyteam == 30 && keycount <= 4)
2719 if(keyteam == myteam || keyteam == -1 || keyteam == 30)
2722 // this yields 8 exactly if "RUN HERE" shows
2727 kh_runheretime = time;
2728 pa_y -= fabs(sin((time - kh_runheretime) * 3.5)) * 6; // make the arrows jump in case of RUN HERE
2733 for(i = 0; i < 4; ++i)
2735 key = floor(kh_keys / pow(32, i)) & 31;
2748 default: // owned or dropped
2753 a = a * hud_alpha_fg;
2754 aa = aa * hud_alpha_fg;
2760 drawpic (pa, "kh_redarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
2763 drawpic (pa, "kh_bluearrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
2766 drawpic (pa, "kh_yellowarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
2769 drawpic (pa, "kh_pinkarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
2774 switch(i) // YAY! switch(i) inside a for loop for i. DailyWTF, here we come!
2777 drawpic (p, "kh_red", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
2780 drawpic (p, "kh_blue", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
2783 drawpic (p, "kh_yellow", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
2786 drawpic (p, "kh_pink", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
2795 // Nexball HUD modicon section
2796 #define NBPB_SIZE '96 38 0'
2797 #define NBPB_BT 2 //thickness
2798 #define NBPB_BRGB '1 1 1'
2799 #define NBPB_BALPH 1 //alpha
2800 #define NBPB_BFLAG DRAWFLAG_NORMAL
2801 #define NBPB_IALPH 0.4
2802 #define NBPB_IFLAG DRAWFLAG_NORMAL
2803 #define NBPB_IRGB '0.7 0.1 0'
2805 void CSQC_nb_hud(void)
2807 float stat_items, nb_pb_starttime, dt, p;
2810 stat_items = getstati(STAT_ITEMS);
2811 nb_pb_starttime = getstatf(STAT_NB_METERSTART);
2814 pos_y = vid_conheight - 42;
2817 //Manage the progress bar if any
2818 if (nb_pb_starttime > 0)
2821 dt = mod(time - nb_pb_starttime, nb_pb_period);
2822 // one period of positive triangle
2823 p = 2 * dt / nb_pb_period;
2829 drawfill(pos, p * s_x * eX + s_y * eY, NBPB_IRGB, NBPB_IALPH, NBPB_IFLAG);
2833 drawline(NBPB_BT, pos , pos + eX * s_x, NBPB_BRGB, NBPB_BALPH, NBPB_BFLAG);
2834 drawline(NBPB_BT, pos , pos + eY * s_y, NBPB_BRGB, NBPB_BALPH, NBPB_BFLAG);
2835 drawline(NBPB_BT, pos + s, pos + eX * s_x, NBPB_BRGB, NBPB_BALPH, NBPB_BFLAG);
2836 drawline(NBPB_BT, pos + s, pos + eY * s_y, NBPB_BRGB, NBPB_BALPH, NBPB_BFLAG);
2839 pos_x += 12; //horizontal margin to the picture
2840 pos_y += 2; //vertical margin to the picture
2842 if (stat_items & IT_KEY1)
2843 drawpic_skin(pos, "nexball_carrying", '80 34 0', '1 1 1', 1, DRAWFLAG_NORMAL);
2846 // Race/CTS HUD modicon section
2847 float crecordtime_prev; // last remembered crecordtime
2848 float crecordtime_change_time; // time when crecordtime last changed
2849 float srecordtime_prev; // last remembered srecordtime
2850 float srecordtime_change_time; // time when srecordtime last changed
2851 void CSQC_race_hud(void)
2854 me = playerslots[player_localentnum - 1];
2856 float f; // yet another function has this
2857 score = me.(scores[ps_primary]);
2859 if not((scores_flags[ps_primary] & SFL_TIME) && !teamplay) // race/cts record display on HUD
2860 return; // no records in the actual race
2862 drawfont = hud_bigfont;
2865 pos_y = vid_conheight - 48;
2867 // clientside personal record
2869 if(gametype == GAME_CTS)
2873 t = stof(db_get(ClientProgsDB, strcat(shortmapname, rr, "time")));
2875 if(score && (score < t || !t)) {
2876 db_put(ClientProgsDB, strcat(shortmapname, rr, "time"), ftos(score));
2877 if(cvar("cl_autodemo_delete_keeprecords"))
2879 f = cvar("cl_autodemo_delete");
2881 cvar_set("cl_autodemo_delete", ftos(f)); // don't delete demo with new record!
2885 if(t != crecordtime_prev) {
2886 crecordtime_prev = t;
2887 crecordtime_change_time = time;
2889 f = time - crecordtime_change_time;
2892 drawstring(pos, "Personal best ", '10 10 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2893 drawstring(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2895 drawstring(pos, "Personal best ", '10 10 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2896 drawstring(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2897 drawstring_expanding(pos, "Personal best ", '10 10 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL, f);
2898 drawstring_expanding(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL, f);
2903 t = race_server_record;
2904 if(t != srecordtime_prev) {
2905 srecordtime_prev = t;
2906 srecordtime_change_time = time;
2908 f = time - srecordtime_change_time;
2911 drawstring(pos, "Server best ", '10 10 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2912 drawstring(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2914 drawstring(pos, "Server best ", '10 10 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2915 drawstring(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2916 drawstring_expanding(pos, "Server best ", '10 10 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL, f);
2917 drawstring_expanding(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL, f);
2919 drawfont = hud_font;
2928 void HUD_DrawPressedKeys(void)
2931 pos = HUD_Panel_GetPos(10);
2932 mySize = HUD_Panel_GetSize(10);
2934 HUD_Panel_DrawBg(10, pos, mySize);
2938 pressedkeys = getstatf(STAT_PRESSED_KEYS);
2939 drawpic_skin(pos, "key_bg.tga", mySize, '1 1 1', 0.1 * hud_alpha_fg, DRAWFLAG_NORMAL);
2940 drawpic_skin(pos + eX * mySize_x - eX * 0.22 * mySize_x + eY * 0.195 * mySize_y, ((pressedkeys & KEY_CROUCH) ? "key_crouch_inv.tga" : "key_crouch.tga"), '1 1 0' * (1/3) * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2941 drawpic_skin(pos + eX * 0.5 * mySize_x - eX * 0.23 * mySize_y + eY * 0.040 * mySize_y, ((pressedkeys & KEY_FORWARD) ? "key_forward_inv.tga" : "key_forward.tga"), '1 1 0' * 0.46 * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2942 drawpic_skin(pos + eX * 0.023 * mySize_x + eY * 0.195 * mySize_y, ((pressedkeys & KEY_JUMP) ? "key_jump_inv.tga" : "key_jump.tga"), '1 1 0' * (1/3) * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2943 drawpic_skin(pos + eX * 0.1 * mySize_x + eY * 0.486 * mySize_y, ((pressedkeys & KEY_LEFT) ? "key_left_inv.tga" : "key_left.tga"), '1 1 0' * 0.46 * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2944 drawpic_skin(pos + eX * 0.5 * mySize_x - eX * 0.23 * mySize_y + eY * 0.486 * mySize_y, ((pressedkeys & KEY_BACKWARD) ? "key_backward_inv.tga" : "key_backward.tga"), '1 1 0' * 0.46 * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2945 drawpic_skin(pos + eX * mySize_x - eX * 0.372 * mySize_x + eY * 0.486 * mySize_y, ((pressedkeys & KEY_RIGHT) ? "key_right_inv.tga" : "key_right.tga"), '1 1 0' * 0.46 * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2948 void HUD_ShowSpeed(void)
2951 float pos, conversion_factor;
2952 string speed, zspeed, unit;
2954 switch(cvar("cl_showspeed_unit"))
2959 conversion_factor = 1.0;
2963 conversion_factor = 1.0;
2967 conversion_factor = 0.0254;
2971 conversion_factor = 0.0254 * 3.6;
2975 conversion_factor = 0.0254 * 3.6 * 0.6213711922;
2979 conversion_factor = 0.0254 * 1.943844492; // 1 m/s = 1.943844492 knots, because 1 knot = 1.852 km/h
2983 speed = strcat(ftos(floor( vlen(pmove_vel - pmove_vel_z * '0 0 1') * conversion_factor + 0.5 )), unit);
2985 numsize_x = numsize_y = cvar("cl_showspeed_size");
2986 pos = (vid_conheight - numsize_y) * cvar("cl_showspeed_position");
2988 drawfont = hud_bigfont;
2989 drawstringcenter(eX + pos * eY, speed, numsize, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2991 if (cvar("cl_showspeed_z") == 1) {
2992 zspeed = strcat(ftos(fabs(floor( pmove_vel_z * conversion_factor + 0.5 ))), unit);
2993 drawstringcenter(eX + pos * eY + numsize_y * eY, zspeed, numsize * 0.5, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2996 drawfont = hud_font;
2999 vector acc_prevspeed;
3003 void HUD_ShowAcceleration(void)
3005 float acceleration, sz, scale, alpha, f;
3006 vector pos, top, rgb;
3007 top_x = vid_conwidth/2;
3010 f = time - acc_prevtime;
3011 if(cvar("cl_showacceleration_z"))
3012 acceleration = (vlen(pmove_vel) - vlen(acc_prevspeed)) * (1 / f);
3014 acceleration = (vlen(pmove_vel - '0 0 1' * pmove_vel_z) - vlen(acc_prevspeed - '0 0 1' * acc_prevspeed_z)) * (1 / f);
3015 acc_prevspeed = pmove_vel;
3016 acc_prevtime = time;
3018 f = bound(0, f * 10, 1);
3019 acc_avg = acc_avg * (1 - f) + acceleration * f;
3020 acceleration = acc_avg / getstatf(STAT_MOVEVARS_MAXSPEED);
3022 pos = top - sz/2 * eY + (cvar("cl_showacceleration_position") * vid_conheight) * eY;
3024 sz = cvar("cl_showacceleration_size");
3025 scale = cvar("cl_showacceleration_scale");
3026 alpha = cvar("cl_showacceleration_alpha");
3027 if (cvar("cl_showacceleration_color_custom"))
3028 rgb = stov(cvar_string("cl_showacceleration_color"));
3031 if (acceleration < 0) {
3032 rgb = '1 .5 .5' - '0 .5 .5' * bound(0, -acceleration * 0.2, 1);
3033 } else if (acceleration > 0) {
3034 rgb = '.5 1 .5' - '.5 0 .5' * bound(0, +acceleration * 0.2, 1);
3038 if (acceleration > 0)
3039 drawpic_skin(pos, "statusbar", acceleration * scale * '40 0 0' + sz * eY, rgb, alpha * hud_alpha_fg, DRAWFLAG_NORMAL);
3040 else if (acceleration < 0)
3041 drawpic_skin(pos + acceleration * scale * '40 0 0', "statusbar", -acceleration * scale * '40 0 0' + sz * eY, rgb, alpha * hud_alpha_fg, DRAWFLAG_NORMAL);
3044 void HUD_Reset (void)
3046 // reset gametype specific icons
3047 if(gametype == GAME_KEYHUNT)
3049 else if(gametype == GAME_CTF)
3050 CSQC_ctf_hudreset();
3053 void HUD_Main (void)
3055 hud_alpha_bg = cvar_or("hud_bg_alpha", 0.8) * (1 - cvar("_menu_alpha"));
3056 hud_border_thickness = bound(0, cvar("hud_border_thickness"), 5);
3057 hud_accuracy_border_thickness = bound(0, cvar_or("hud_accuracy_border_thickness", 1), 5);
3058 hud_color_bg_team = cvar("hud_color_bg_team");
3060 hud_fontsize = HUD_GetFontsize("hud_fontsize");
3061 hud_fontsize_spec = HUD_GetFontsize("hud_fontsize_spec");
3063 hud_configure = cvar("_hud_configure");
3066 if(cvar("hud_dock"))
3067 drawpic_skin('0 0 0', "dock", eX * vid_conwidth + eY * vid_conheight, stov(cvar_string("hud_dock_color")), cvar("hud_dock_alpha"), DRAWFLAG_NORMAL);
3069 if(HUD_Panel_CheckActive(0))
3071 if(HUD_Panel_CheckActive(1))
3073 if(HUD_Panel_CheckActive(2))
3075 if(HUD_Panel_CheckActive(3))
3077 if(HUD_Panel_CheckActive(4))
3079 if(HUD_Panel_CheckActive(5))
3082 if(HUD_Panel_CheckActive(6))
3083 if(ons_showmap || cvar_string("cl_teamradar") != "0" && (cvar("cl_teamradar") == 2 || teamplay))
3085 if(HUD_Panel_CheckActive(7))
3087 if(HUD_Panel_CheckActive(8))
3088 if(gametype == GAME_RACE || gametype == GAME_CTS || hud_configure)
3090 if(HUD_Panel_CheckActive(9))
3093 if(HUD_Panel_CheckActive(10))
3094 if(spectatee_status > 0 || cvar("cl_showpressedkeys") >= 2 || hud_configure)
3095 HUD_DrawPressedKeys();
3097 // TODO hud_'ify these
3098 if (cvar("cl_showspeed"))
3100 if (cvar("cl_showacceleration"))
3101 HUD_ShowAcceleration();
3103 // TODO... well make them work in a panel etc
3104 if(gametype == GAME_KEYHUNT)
3106 else if(gametype == GAME_CTF)
3108 else if(gametype == GAME_NEXBALL)
3110 else if(gametype == GAME_CTS || gametype == GAME_RACE)