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"));
614 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_flip ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_flip"))), "\n"));
617 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_alreadyvoted_alpha ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_alreadyvoted_alpha"))), "\n"));
623 print("^2Successfully exported to hud_", cvar_string("hud_skin"), "_", cfgname, ".cfg! (Note: It's saved in data/data/)\n");
628 vector HUD_Panel_CheckLimitSize(float id, vector mySize)
632 mySize_x = max(mySize_y * (1/10), mySize_x); // at least 1/10 * height
633 mySize_y = max(mySize_x * (1/26), mySize_y); // at least 1/26 * width
636 mySize_x = max(mySize_y * 0.7, mySize_x); // at least 0.7 * height
639 mySize_x = max(mySize_y * 1.5, mySize_x); // at least 2 * height
642 mySize_x = max(mySize_y * 2, mySize_x); // at least 2 * height
645 mySize_x = max(mySize_y * 2, mySize_x); // at least 2 * height
648 mySize_y = (1/4) * mySize_x; // 1/4 * width
651 mySize_y = (1/4) * mySize_x; // 1/4 * width
654 mySize_y = (1/4) * mySize_x; // 1/4 * width
657 mySize_y = 0.5898 * mySize_x; // 0.5898 * width, reason: bg has weird dimensions...
663 // return active status of panel
664 float HUD_Panel_CheckActive(float id)
666 if (cvar_or(strcat("hud_", HUD_Panel_GetName(id)), 1))
671 // return size of given panel
672 vector HUD_Panel_GetSize(float id)
675 mySize = stov(cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_size")));
677 mySize = eX * mySize_x * vid_conwidth + eY * mySize_y * vid_conheight;
682 // return pos of given panel
683 vector HUD_Panel_GetPos(float id)
686 pos = stov(cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_pos")));
688 pos = eX * pos_x * vid_conwidth + eY * pos_y * vid_conheight;
691 pos_x = vid_conwidth + pos_x;
693 pos_y = vid_conheight + pos_y;
697 float HUD_Panel_GetBorder(float id)
700 border = cvar(strcat("hud_", HUD_Panel_GetName(id), "_bg_border"));
702 border = cvar("hud_bg_border");
706 // draw the background/borders
707 void HUD_Panel_DrawBg(float id, vector pos, vector mySize)
709 if(!hud_configure && cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg")) == "0")
713 bg = cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg"));
715 bg = cvar_string("hud_bg");
720 border = HUD_Panel_GetBorder(id);
723 if(cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_color")) != "")
724 color = stov(cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_color")));
726 color = stov(cvar_string("hud_bg_color"));
729 alpha = cvar(strcat("hud_", HUD_Panel_GetName(id), "_bg_alpha"));
731 alpha = cvar("hud_bg_alpha");
733 alpha = max(cvar("hud_configure_bg_minalpha"), alpha);
735 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));
739 vector HUD_Panel_GetProgressBarColor(string item)
741 return stov(cvar_string(strcat("hud_progressbar_", item, "_color")));
744 float resizeCorner; // 1 = topleft, 2 = topright, 3 = bottomleft, 4 = bottomright
745 // check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
746 vector HUD_Panel_CheckResize(float id, vector myPos, vector mySize)
758 for (i = 0; i < panel_cnt; ++i) {
759 if(i == id || !HUD_Panel_CheckActive(i))
762 targPos = HUD_Panel_GetPos(i);
763 targSize = HUD_Panel_GetSize(i);
765 targPos = HUD_Panel_GetPos(i) - '1 1 0' * HUD_Panel_GetBorder(id);
766 targSize = HUD_Panel_GetSize(i) + '2 2 0' * HUD_Panel_GetBorder(id);
768 if(myPos_y + mySize_y < targPos_y)
770 if(myPos_y > targPos_y + targSize_y)
773 if(myPos_x + mySize_x < targPos_x)
775 if(myPos_x > targPos_x + targSize_x)
778 // OK, there IS a collision.
780 myCenter_x = myPos_x + 0.5 * mySize_x;
781 myCenter_y = myPos_y + 0.5 * mySize_y;
783 targCenter_x = targPos_x + 0.5 * targSize_x;
784 targCenter_y = targPos_y + 0.5 * targSize_y;
787 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y && resizeCorner != 1) // top left (of target panel)
789 if(myPos_x + mySize_x - targPos_x < myPos_y + mySize_y - targPos_y) // push it to the side
790 myTarget_x = targPos_x - myPos_x;
791 else // push it upwards
792 myTarget_y = targPos_y - myPos_y;
794 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y && resizeCorner != 2) // top right
796 if(targPos_x + targSize_x - myPos_x < myPos_y + mySize_y - targPos_y) // push it to the side
797 myTarget_x = targPos_x + targSize_x;
798 else // push it upwards
799 myTarget_y = targPos_y - myPos_y;
801 else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
803 if(myPos_x + mySize_x - targPos_x < targPos_y + targSize_y - myPos_y) // push it to the side
804 myTarget_x = targPos_x - myPos_x;
805 else // push it downwards
806 myTarget_y = targPos_y + targSize_y;
808 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
810 if(targPos_x + targSize_x - myPos_x < targPos_y + targSize_y - myPos_y) // push it to the side
811 myTarget_x = targPos_x + targSize_x;
812 else // push it downwards
813 myTarget_y = targPos_y + targSize_y;
821 float HUD_Panel_SetSize(float id, vector mySize)
826 oldSize = stov(cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_size")));
829 myPos = HUD_Panel_GetPos(id);
831 // check for collisions
832 if(cvar("hud_configure_checkcollisions"))
833 mySize = HUD_Panel_CheckResize(id, HUD_Panel_GetPos(id), mySize);
835 mySize_x = bound(0.025 * vid_conwidth, mySize_x, vid_conwidth - myPos_x);
836 mySize_y = bound(0.025 * vid_conheight, mySize_y, vid_conheight - myPos_y);
838 // cap against panel's own limits
839 mySize = HUD_Panel_CheckLimitSize(id, mySize);
841 //mySize_x = bound(0.025 * vid_conwidth, mySize_x, vid_conwidth);
842 //mySize_y = bound(0.025 * vid_conheight, mySize_y, vid_conheight);
844 // TODO: is this needed?
845 // this is to check if (and how) SetPos should be called
846 if(mySize_x == oldSize_x && mySize_y == oldSize_y)
847 didntresize = 3; // didnt resize either
848 else if(mySize_x == oldSize_x && mySize_y != oldSize_y)
849 didntresize = 2; // resized Y
850 else if(mySize_y == oldSize_y && mySize_x != oldSize_x)
851 didntresize = 1; // resized X
854 s = strcat(ftos(mySize_x/vid_conwidth), " ", ftos(mySize_y/vid_conheight));
855 cvar_set(strcat("hud_", HUD_Panel_GetName(id), "_size"), s);
859 // check if move will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
860 vector HUD_Panel_CheckMove(float id, vector myPos, vector mySize)
872 for (i = 0; i < panel_cnt; ++i) {
873 if(i == id || !HUD_Panel_CheckActive(i))
876 targPos = HUD_Panel_GetPos(i) - '1 1 0' * HUD_Panel_GetBorder(id);
877 targSize = HUD_Panel_GetSize(i) + '2 2 0' * HUD_Panel_GetBorder(id);
879 if(myPos_y + mySize_y < targPos_y)
881 if(myPos_y > targPos_y + targSize_y)
884 if(myPos_x + mySize_x < targPos_x)
886 if(myPos_x > targPos_x + targSize_x)
889 // OK, there IS a collision.
891 myCenter_x = myPos_x + 0.5 * mySize_x;
892 myCenter_y = myPos_y + 0.5 * mySize_y;
894 targCenter_x = targPos_x + 0.5 * targSize_x;
895 targCenter_y = targPos_y + 0.5 * targSize_y;
898 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // top left (of the target panel)
900 if(myPos_x + mySize_x - targPos_x < myPos_y + mySize_y - targPos_y) // push it to the side
901 myTarget_x = targPos_x - mySize_x;
902 else // push it upwards
903 myTarget_y = targPos_y - mySize_y;
905 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y) // top right
907 if(targPos_x + targSize_x - myPos_x < myPos_y + mySize_y - targPos_y) // push it to the side
908 myTarget_x = targPos_x + targSize_x;
909 else // push it upwards
910 myTarget_y = targPos_y - mySize_y;
912 else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
914 if(myPos_x + mySize_x - targPos_x < targPos_y + targSize_y - myPos_y) // push it to the side
915 myTarget_x = targPos_x - mySize_x;
916 else // push it downwards
917 myTarget_y = targPos_y + targSize_y;
919 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
921 if(targPos_x + targSize_x - myPos_x < targPos_y + targSize_y - myPos_y) // push it to the side
922 myTarget_x = targPos_x + targSize_x;
923 else // push it downwards
924 myTarget_y = targPos_y + targSize_y;
931 void HUD_Panel_SetPos(float id, vector pos, float didntresize)
934 oldPos = HUD_Panel_GetPos(id);
937 else if(didntresize == 1)
939 else if(didntresize == 3)
943 mySize = HUD_Panel_GetSize(id);
945 if(cvar("hud_configure_checkcollisions"))
946 pos = HUD_Panel_CheckMove(id, pos, mySize);
948 pos_x = bound(0, pos_x, vid_conwidth - mySize_x);
949 pos_y = bound(0, pos_y, vid_conheight - mySize_y);
951 if (pos_x + 0.5 * mySize_x > 0.5 * vid_conwidth)
952 pos_x = pos_x - vid_conwidth;
953 if (pos_y + 0.5 * mySize_y > 0.5 * vid_conheight)
954 pos_y = pos_y - vid_conheight;
957 s = strcat(ftos(pos_x/vid_conwidth), " ", ftos(pos_y/vid_conheight));
959 cvar_set(strcat("hud_", HUD_Panel_GetName(id), "_pos"), s);
963 float prevMouseClicked; // previous state
964 float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
966 prevMouseClicked = mouseClicked;
967 if(nPrimary == K_MOUSE1)
969 if(bInputType == 0) { // key pressed
973 if(bInputType == 1) {// key released
981 vector mousepos, mouseprevpos;
982 vector panel_click_distance; // mouse cursor distance from the top left corner of the panel (saved only upon a click)
983 vector panel_click_pos; // panel pos (saved only upon a click)
984 vector panel_click_size; // panel size (saved only upon a click)
985 float highlightedPanel;
986 float highlightedAction; // 0 = nothing, 1 = move, 2 = resize
987 void HUD_Panel_Mouse()
989 if(mouseClicked == 0) {
990 highlightedPanel = -1;
991 highlightedAction = 0;
994 mousepos = mousepos + getmousepos();
996 mousepos_x = bound(0, mousepos_x, vid_conwidth);
997 mousepos_y = bound(0, mousepos_y, vid_conheight);
999 drawpic_skin(mousepos, "gfx/menu/default/cursor.tga", '32 32 0', '1 1 1', 1, hud_alpha_fg);
1007 for(i = 0; i <= panel_cnt; ++i)
1009 panelPos = HUD_Panel_GetPos(i);
1010 panelSize = HUD_Panel_GetSize(i);
1011 border = HUD_Panel_GetBorder(i);
1012 if(prevMouseClicked == 0) {
1014 if(mousepos_x >= panelPos_x && mousepos_y >= panelPos_y && mousepos_x <= panelPos_x + panelSize_x && mousepos_y <= panelPos_y + panelSize_y)
1016 highlightedPanel = i;
1017 highlightedAction = 1;
1019 // resize from topleft border
1020 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)
1022 highlightedPanel = i;
1023 highlightedAction = 2;
1026 // resize from topright border
1027 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)
1029 highlightedPanel = i;
1030 highlightedAction = 2;
1033 // resize from bottomleft border
1034 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)
1036 highlightedPanel = i;
1037 highlightedAction = 2;
1040 // resize from bottomright border
1041 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)
1043 highlightedPanel = i;
1044 highlightedAction = 2;
1049 if(highlightedPanel == i)
1051 if(prevMouseClicked == 0)
1053 panel_click_distance = mousepos - panelPos;
1054 panel_click_pos = panelPos;
1055 panel_click_size = panelSize;
1058 if(highlightedAction == 1)
1059 HUD_Panel_SetPos(i, mousepos - panel_click_distance, 0);
1060 else if(highlightedAction == 2)
1062 float didntresize; // panel too big/too small, dont resize (also has to affect moving)
1063 if(resizeCorner == 1) {
1064 didntresize = HUD_Panel_SetSize(i, panelSize + mouseprevpos - mousepos);
1065 HUD_Panel_SetPos(i, mousepos - panel_click_distance, didntresize);
1067 if(resizeCorner == 2) {
1068 didntresize = HUD_Panel_SetSize(i, eY * panel_click_size_y + eX * (mousepos_x - panelPos_x - (panel_click_distance_x - panel_click_size_x))
1069 + eY * (panel_click_distance_y + (panel_click_pos_y - mousepos_y)));
1070 HUD_Panel_SetPos(i, eX * panelPos_x + eY * (mousepos_y - panel_click_distance_y), didntresize);
1072 if(resizeCorner == 3) {
1073 didntresize = HUD_Panel_SetSize(i, panelSize + eX * (mouseprevpos_x - mousepos_x) + eY * (mousepos_y - mouseprevpos_y));
1074 HUD_Panel_SetPos(i, eX * (mousepos_x - panel_click_distance_x) + eY * panelPos_y, didntresize);
1076 if(resizeCorner == 4) {
1077 HUD_Panel_SetSize(i, mousepos - panelPos - (panel_click_distance - panel_click_size));
1083 mouseprevpos = mousepos;
1084 prevMouseClicked = mouseClicked;
1087 /*void HUD_DrawDockEdge(float id, vector p1, vector p2, float target)
1093 */ // maybe one day, since this will be quite complicated
1095 // Weapon icons (#0)
1098 float weaponspace[10];
1099 void HUD_WeaponIcons_Clear()
1102 for(idx = 0; idx < 10; ++idx)
1103 weaponspace[idx] = 0;
1106 entity weaponorder[WEP_MAXCOUNT];
1108 void weaponorder_swap(float i, float j, entity pass)
1112 weaponorder[i] = weaponorder[j];
1116 float weaponorder_cmp(float i, float j, entity pass)
1119 d = mod(weaponorder[i].impulse + 9, 10) - mod(weaponorder[j].impulse + 9, 10);
1122 d = weaponorder[i].weapon - weaponorder[j].weapon;
1126 void HUD_WeaponIcons()
1128 float alpha, height, accuracybar_height, stat_weapons; // "constants"
1129 vector pos, mySize, mysize, mypos, accuracy_color;
1130 float i, id, fade, weapon_stats, weapon_hit, weapon_damage, weapon_cnt; // variables
1132 pos = HUD_Panel_GetPos(0);
1133 mySize = HUD_Panel_GetSize(0);
1134 accuracybar_height = cvar_or("hud_weaponicons_accuracy_height", 3);
1136 stat_weapons = getstati(STAT_WEAPONS);
1137 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1139 self = get_weaponinfo(i);
1140 if(self.weapons && (self.impulse >= 0) && (stat_weapons & self.weapons) || hud_configure)
1142 weaponorder[weapon_cnt] = self;
1146 heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, world);
1148 HUD_Panel_DrawBg(0, pos, mySize);
1151 weapon_stats = getstati(STAT_DAMAGE_HITS);
1152 weapon_number = weapon_stats & 63;
1153 weapon_hits[weapon_number-WEP_FIRST] = floor(weapon_stats / 64);
1155 weapon_stats = getstati(STAT_DAMAGE_FIRED);
1156 weapon_number = weapon_stats & 63;
1157 weapon_fired[weapon_number-WEP_FIRST] = floor(weapon_stats / 64);
1159 if(cvar_or("hud_weaponicons_fade", 1))
1161 fade = 3.2 - 2 * (time - weapontime);
1162 fade = bound(0.7, fade, 1);
1167 HUD_WeaponIcons_Clear();
1169 float rows, columns;
1170 rows = mySize_y/mySize_x;
1171 rows = bound(1, floor((sqrt(4 * (2/1) * rows * WEP_COUNT + rows * rows) + rows + 0.5) / 2), WEP_COUNT);
1172 // ^^^ weapon icon aspect goes here
1174 columns = ceil(WEP_COUNT/rows);
1176 for(i = 0; i < weapon_cnt; ++i)
1178 self = weaponorder[i];
1179 if((self.weapons && (self.impulse >= 0) && (stat_weapons & self.weapons)) || hud_configure)
1183 alpha = (self.weapon == activeweapon) ? 1 : 0.6;
1185 weapon_hit = weapon_hits[self.weapon-WEP_FIRST];
1186 weapon_damage = weapon_fired[self.weapon-WEP_FIRST];
1188 if(self.weapon == activeweapon)
1189 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);
1190 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);
1192 if(cvar_or("hud_weaponicons_number", 1))
1193 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);
1195 // draw the weapon accuracy on the HUD
1196 if(hud_accuracy_hud && !(gametype == GAME_RACE || gametype == GAME_CTS))
1199 weapon_stats = floor(100 * weapon_hit / weapon_damage);
1201 accuracy_color = HUD_AccuracyColor(weapon_stats);
1203 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);
1220 float GetAmmoStat(float i)
1224 case 0: return STAT_SHELLS;
1225 case 1: return STAT_NAILS;
1226 case 2: return STAT_ROCKETS;
1227 case 3: return STAT_CELLS;
1228 case 4: return STAT_FUEL;
1233 float GetAmmoItemCode(float i)
1237 case 0: return IT_SHELLS;
1238 case 1: return IT_NAILS;
1239 case 2: return IT_ROCKETS;
1240 case 3: return IT_CELLS;
1241 case 4: return IT_FUEL;
1246 string GetAmmoPicture(float i)
1250 case 0: return "ammo_shells";
1251 case 1: return "ammo_bullets";
1252 case 2: return "ammo_rocket";
1253 case 3: return "ammo_cells";
1254 case 4: return "ammo_fuel";
1259 void HUD_Inventory()
1264 vector pos, mySize, mysize, mypos;
1265 pos = HUD_Panel_GetPos(1);
1266 mySize = HUD_Panel_GetSize(1);
1268 HUD_Panel_DrawBg(1, pos, mySize);
1271 stat_items = getstati(STAT_ITEMS);
1272 for (i = 0; i < 4; ++i) {
1274 a = getstati(GetAmmoStat(i)); // how much ammo do we have of type i?
1278 if(cvar("hud_inventory_onlycurrent")) {
1279 if (stat_items & GetAmmoItemCode(i)) {
1280 drawpic_skin(pos, "ammo_current_bg", mySize, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1281 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);
1283 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);
1285 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);
1289 if(mySize_x/mySize_y >= 10) { // arrange horizontally
1291 case 0: mypos_x = pos_x; mypos_y = pos_y; break; // shells
1292 case 1: mypos_x = pos_x + 0.25 * mySize_x; mypos_y = pos_y; break; // bullets
1293 case 2: mypos_x = pos_x + 0.5 * mySize_x; mypos_y = pos_y; break; // rockets
1294 case 3: mypos_x = pos_x + 0.75 * mySize_x; mypos_y = pos_y; break; // cells
1296 mysize_x = 0.25 * mySize_x;
1297 mysize_y = mySize_y;
1298 } else if(mySize_x/mySize_y >= 2.5) { // arrange in a 2x2 grid
1300 case 0: mypos_x = pos_x + 0.5 * mySize_x; mypos_y = pos_y + 0.5 * mySize_y; break; // shells
1301 case 1: mypos_x = pos_x + 0.5 * mySize_x; mypos_y = pos_y; break; // bullets
1302 case 2: mypos_x = pos_x; mypos_y = pos_y + 0.5 * mySize_y; break; // rockets
1303 case 3: mypos_x = pos_x; mypos_y = pos_y; break; // cells
1305 mysize_x = 0.5 * mySize_x;
1306 mysize_y = 0.5 * mySize_y;
1307 } else { // arrange vertically
1309 case 0: mypos_x = pos_x; mypos_y = pos_y; break; // shells
1310 case 1: mypos_x = pos_x; mypos_y = pos_y + 0.25 * mySize_y; break; // bullets
1311 case 2: mypos_x = pos_x; mypos_y = pos_y + 0.5 * mySize_y; break; // rockets
1312 case 3: mypos_x = pos_x; mypos_y = pos_y + 0.75 * mySize_y; break; // cells
1314 mysize_x = mySize_x;
1315 mysize_y = 0.25 * mySize_y;
1318 if (stat_items & GetAmmoItemCode(i))
1319 drawpic_skin(mypos, "ammo_current_bg", mysize, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1320 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);
1322 if(stat_items & GetAmmoItemCode(i))
1323 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);
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 * 0.7, DRAWFLAG_NORMAL);
1327 if(stat_items & GetAmmoItemCode(i))
1328 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);
1330 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);
1339 float shield_maxtime;
1340 float strength_maxtime;
1341 void HUD_Powerups() {
1343 stat_items = getstati(STAT_ITEMS);
1347 if not(stat_items & IT_STRENGTH)
1348 if not(stat_items & IT_INVINCIBLE)
1351 if (getstati(STAT_HEALTH) <= 0)
1356 pos = HUD_Panel_GetPos(2);
1357 mySize = HUD_Panel_GetSize(2);
1359 HUD_Panel_DrawBg(2, pos, mySize);
1361 float strength_time, shield_time;
1363 strength_time = bound(0, ceil(getstatf(STAT_STRENGTH_FINISHED) - time), 99);
1364 shield_time = bound(0, ceil(getstatf(STAT_INVINCIBLE_FINISHED) - time), 99);
1372 string leftname, rightname;
1373 float leftcnt, rightcnt;
1374 float leftalpha, rightalpha;
1375 if (cvar(strcat("hud_", HUD_Panel_GetName(2), "_flip"))) {
1376 leftname = "strength";
1377 leftcnt = strength_time;
1379 rightname = "shield";
1380 rightcnt = shield_time;
1382 leftname = "shield";
1383 leftcnt = shield_time;
1385 rightname = "strength";
1386 rightcnt = strength_time;
1388 leftalpha = bound(0, leftcnt, 1);
1389 rightalpha = bound(0, rightcnt, 1);
1392 if (mySize_x/mySize_y > 5)
1396 len = strlen(ftos(leftcnt));
1398 drawpic_skin(pos, "statusbar", eX * 0.5 * mySize_x * min(1, leftcnt/30) + eY * mySize_y, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1399 drawpic_skin(pos, strcat("", leftname), '1 1 0' * mySize_y, '1 1 1', leftalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1400 HUD_DrawXNum(pos + eX * mySize_y + eY * 0.25 * mySize_y, leftcnt, len, 0, 0.5 * mySize_y, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1405 drawpic_skin(pos + eX * mySize_x - eX * 0.5 * mySize_x * min(1, rightcnt/30), "statusbar", eX * 0.5 * mySize_x * min(1, rightcnt/30) + eY * mySize_y, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1406 drawpic_skin(pos + eX * mySize_x - eX * mySize_y, strcat("", rightname), '1 1 0' * mySize_y, '1 1 1', rightalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1407 HUD_DrawXNum(pos + eX * mySize_x - eX * 2.5 * mySize_y + eY * 0.25 * mySize_y, rightcnt, 3, 0, 0.5 * mySize_y, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1410 else if (mySize_x/mySize_y > 3.2)
1414 len = strlen(ftos(leftcnt));
1416 drawpic_skin(pos + eY * mySize_y - eY * mySize_y * min(1, leftcnt/30), "statusbar", eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/30), HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1417 drawpic_skin(pos + eX * 0.4 * mySize_y, strcat("", leftname), '0.7 0.7 0' * mySize_y, '1 1 1', leftalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1418 HUD_DrawXNum(pos + eX * ((3-len)/2) * 0.5 * mySize_y + eY * 0.55 * mySize_y, leftcnt, len, 0, 0.5 * mySize_y, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1423 len = strlen(ftos(rightcnt));
1425 drawpic_skin(pos + eX * 0.5 * mySize_x + eY * mySize_y - eY * mySize_y * min(1, rightcnt/30), "statusbar", eX * 0.5 * mySize_x + eY * mySize_y * min(1, rightcnt/30), HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1426 drawpic_skin(pos + eX * mySize_x - eX * 1.1 * mySize_y, strcat("", rightname), '0.7 0.7 0' * mySize_y, '1 1 1', rightalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1427 HUD_DrawXNum(pos + eX * mySize_x - eX * len * 0.5 * mySize_y - eX * ((3-len)/2) * 0.5 * mySize_y + eY * 0.55 * mySize_y, rightcnt, len, 0, 0.5 * mySize_y, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1434 len = strlen(ftos(leftcnt));
1436 drawpic_skin(pos, "statusbar", eX * mySize_x * min(1, leftcnt/30) + eY * 0.5 * mySize_y, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1437 drawpic_skin(pos, strcat("", leftname), '0.5 0.5 0' * mySize_y, '1 1 1', leftalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1438 HUD_DrawXNum(pos + eX * 0.5 * mySize_y, leftcnt, len, 0, 0.5 * mySize_y, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1443 len = strlen(ftos(rightcnt));
1445 drawpic_skin(pos + eY * 0.5 * mySize_y, "statusbar", eX * mySize_x * min(1, rightcnt/30) + eY * 0.5 * mySize_y, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1446 drawpic_skin(pos + eY * 0.5 * mySize_y, strcat("", rightname), '0.5 0.5 0' * mySize_y, '1 1 1', rightalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1447 HUD_DrawXNum(pos + eX * 0.5 * mySize_y + eY * 0.5 * mySize_y, rightcnt, len, 0, 0.5 * mySize_y, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1451 /* TODO: add expand!
1453 if (strength_time) {
1454 dt = strength_time - time;
1459 drawpic_expanding_two(pos, "str", '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE,
1460 bound(0, (ceil(dt) - dt) / 0.5, 1));
1464 drawpic_skin(pos, "str", '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE);
1466 HUD_DrawXNum(pos - '40 -2 0', ceil(dt), 2, 0, countdown_fontsize, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1470 drawpic_expanding(pos, "str", '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE,
1471 bound(0, -dt / 0.5, 1));
1476 if (invincibility_time) {
1477 dt = invincibility_time - time;
1482 drawpic_expanding_two(pos - '0 -22 0', "invinc", '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE,
1483 bound(0, (ceil(dt) - dt) / 0.5, 1));
1487 drawpic_skin(pos - '0 -22 0', "invinc", '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE);
1489 HUD_DrawXNum(pos - '40 -24 0', ceil(dt), 2, 0, countdown_fontsize, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1493 drawpic_expanding(pos - '0 -22 0', "invinc", '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE,
1494 bound(0, -dt / 0.5, 1));
1500 // Health/armor (#3)
1502 void HUD_HealthArmor(void)
1505 pos = HUD_Panel_GetPos(3);
1506 mySize = HUD_Panel_GetSize(3);
1508 HUD_Panel_DrawBg(3, pos, mySize);
1510 float armor, health, x;
1511 armor = getstati(STAT_ARMOR);
1512 health = getstati(STAT_HEALTH);
1526 if(hud_hudselector == 2) // combined health and armor display
1529 v = healtharmor_maxdamage(health, armor, armorblockpercent);
1532 num_pos = - '96 28 0';
1536 if(v_z) // fully armored
1538 // here, armorideal > armor
1539 drawpic_skin(num_pos + '78 -4.5 0', "health", '32 32 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1540 drawpic_skin(num_pos + '108 -4.5 0', "armor", '20 20 0', '1 1 1', hud_alpha_fg * armor / v_y, DRAWFLAG_NORMAL);
1544 drawpic_skin(num_pos + '108 -4.5 0', "health", '20 20 0', '1 1 1', hud_alpha_fg * v_y / armor, DRAWFLAG_NORMAL);
1545 drawpic_skin(num_pos + '78 -4.5 0', "armor", '32 32 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1547 HUD_DrawXNum_Colored(num_pos, x, 3, 24, hud_alpha_fg); // draw the combined health and armor
1553 string leftname, rightname;
1554 float leftcnt, rightcnt;
1555 float leftactive, rightactive;
1556 float leftalpha, rightalpha;
1558 if (cvar(strcat("hud_", HUD_Panel_GetName(3), "_flip"))) { // old style layout with armor left/top of health
1563 leftalpha = min((armor+10)/55, 1);
1565 rightname = "health";
1570 leftname = "health";
1575 rightname = "armor";
1579 rightalpha = min((armor+10)/55, 1);
1583 fuel = getstati(GetAmmoStat(4)); // how much fuel do we have?
1585 if (mySize_x/mySize_y > 5)
1589 len = strlen(ftos(leftcnt));
1591 drawpic_skin(pos, "statusbar", eX * 0.5 * mySize_x * min(1, leftcnt/200) + eY * mySize_y, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1592 drawpic_skin(pos, strcat("", leftname), '1 1 0' * mySize_y, '1 1 1', leftalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1593 HUD_DrawXNum_Colored(pos + eX * mySize_y + eY * 0.25 * mySize_y, leftcnt, len, 0.5 * mySize_y, hud_alpha_fg);
1598 drawpic_skin(pos + eX * mySize_x - eX * 0.5 * mySize_x * min(1, rightcnt/200), "statusbar", eX * 0.5 * mySize_x * min(1, rightcnt/200) + eY * mySize_y, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1599 drawpic_skin(pos + eX * mySize_x - eX * mySize_y, strcat("", rightname), '1 1 0' * mySize_y, '1 1 1', rightalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1600 HUD_DrawXNum_Colored(pos + eX * mySize_x - eX * 2.5 * mySize_y + eY * 0.25 * mySize_y, rightcnt, 3, 0.5 * mySize_y, hud_alpha_fg);
1604 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);
1606 else if (mySize_x/mySize_y > 3.2)
1610 len = strlen(ftos(leftcnt));
1612 drawpic_skin(pos + eY * mySize_y - eY * mySize_y * min(1, leftcnt/200), "statusbar", eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/200), HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1613 drawpic_skin(pos + eX * 0.4 * mySize_y, strcat("", leftname), '0.7 0.7 0' * mySize_y, '1 1 1', leftalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1614 HUD_DrawXNum_Colored(pos + eX * ((3-len)/2) * 0.5 * mySize_y + eY * 0.55 * mySize_y, leftcnt, len, 0.5 * mySize_y, hud_alpha_fg);
1619 len = strlen(ftos(rightcnt));
1621 drawpic_skin(pos + eX * 0.5 * mySize_x + eY * mySize_y - eY * mySize_y * min(1, rightcnt/200), "statusbar", eX * 0.5 * mySize_x + eY * mySize_y * min(1, rightcnt/200), HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1622 drawpic_skin(pos + eX * mySize_x - eX * 1.1 * mySize_y, strcat("", rightname), '0.7 0.7 0' * mySize_y, '1 1 1', rightalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1623 HUD_DrawXNum_Colored(pos + eX * mySize_x - eX * len * 0.5 * mySize_y - eX * ((3-len)/2) * 0.5 * mySize_y + eY * 0.55 * mySize_y, rightcnt, len, 0.5 * mySize_y, hud_alpha_fg);
1627 drawpic_skin(pos, "statusbar", eX * mySize_x * min(1, fuel/100) + eY * 0.15 * mySize_y, HUD_Panel_GetProgressBarColor("fuel"), hud_alpha_fg * 0.8, DRAWFLAG_NORMAL);
1633 len = strlen(ftos(leftcnt));
1635 drawpic_skin(pos, "statusbar", eX * mySize_x * min(1, leftcnt/200) + eY * 0.5 * mySize_y, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1636 drawpic_skin(pos, strcat("", leftname), '0.5 0.5 0' * mySize_y, '1 1 1', leftalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1637 HUD_DrawXNum_Colored(pos + eX * 0.5 * mySize_y, leftcnt, len, 0.5 * mySize_y, hud_alpha_fg);
1642 len = strlen(ftos(rightcnt));
1644 drawpic_skin(pos + eY * 0.5 * mySize_y, "statusbar", eX * mySize_x * min(1, rightcnt/200) + eY * 0.5 * mySize_y, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1645 drawpic_skin(pos + eY * 0.5 * mySize_y, strcat("", rightname), '0.5 0.5 0' * mySize_y, '1 1 1', rightalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1646 HUD_DrawXNum_Colored(pos + eX * 0.5 * mySize_y + eY * 0.5 * mySize_y, rightcnt, len, 0.5 * mySize_y, hud_alpha_fg);
1650 drawpic_skin(pos, "statusbar", eX * mySize_x * min(1, fuel/100) + eY * 0.1 * mySize_y, HUD_Panel_GetProgressBarColor("fuel"), hud_alpha_fg * 0.8, DRAWFLAG_NORMAL);
1656 // Notification area (#4)
1657 void HUD_Notify (void)
1660 pos = HUD_Panel_GetPos(4);
1661 mySize = HUD_Panel_GetSize(4);
1663 HUD_Panel_DrawBg(4, pos, mySize);
1667 if(spectatee_status && !intermission)
1669 drawfont = hud_bigfont;
1670 if(spectatee_status == -1)
1673 s = GetPlayerName(spectatee_status - 1);
1674 // spectated player name between HUD and chat area, aligned to the left
1676 pos_y = - 50 - hud_fontsize_spec_y;
1677 s = textShortenToWidth(s, vid_conwidth/2.5, hud_fontsize_spec, stringwidth_colors);
1678 drawcolorcodedstring(pos, s, hud_fontsize_spec, hud_alpha_fg, DRAWFLAG_NORMAL);
1679 drawfont = hud_font;
1681 // spectator text in the upper right corner
1682 if(spectatee_status == -1)
1683 s = strcat("^1Press ^3", getcommandkey("primary fire", "+attack"), "^1 to spectate");
1685 s = strcat("^1Press ^3", getcommandkey("primary fire", "+attack"), "^1 for another player");
1687 if(spectatee_status == -1)
1688 s = strcat("^1Use ^3", getcommandkey("next weapon", "weapnext"), "^1 or ^3", getcommandkey("previous weapon", "weapprev"), "^1 to change the speed");
1690 s = strcat("^1Press ^3", getcommandkey("secondary fire", "+attack2"), "^1 to observe");
1692 s = strcat("^1Press ^3", getcommandkey("server info", "+show_info"), "^1 for gamemode info");
1694 if(gametype == GAME_ARENA)
1695 s = "^1Wait for your turn to join";
1696 else if(gametype == GAME_LMS)
1699 sk = playerslots[player_localentnum - 1];
1700 if(sk.(scores[ps_primary]) >= 666)
1701 s = "^1Match has already begun";
1702 else if(sk.(scores[ps_primary]) > 0)
1703 s = "^1You have no more lives left";
1705 s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
1708 s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
1710 //show restart countdown:
1711 if (time < getstatf(STAT_GAMESTARTTIME)) {
1713 //we need to ceil, otherwise the countdown would be off by .5 when using round()
1714 countdown = ceil(getstatf(STAT_GAMESTARTTIME) - time);
1715 s = strcat("^1Game starts in ^3", ftos(countdown), "^1 seconds");
1718 if(warmup_stage && !intermission)
1720 s = "^2Currently in ^1warmup^2 stage!";
1723 // move more important stuff more to the middle so its more visible
1726 if(mod(time, 1) >= 0.5)
1731 if(ready_waiting && !intermission && !spectatee_status)
1733 if(ready_waiting_for_me)
1736 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " to end warmup");
1738 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " once you are ready");
1743 s = strcat("^2Waiting for others to ready up to end warmup...");
1745 s = strcat("^2Waiting for others to ready up...");
1748 else if(warmup_stage && !intermission && !spectatee_status)
1750 s = strcat("^2Press ^3", getcommandkey("ready", "ready"), "^2 to end warmup");
1753 if(teamplay && !intermission && !spectatee_status && gametype != GAME_CA && teamnagger)
1755 float ts_min, ts_max;
1756 tm = teams.sort_next;
1759 for(; tm.sort_next; tm = tm.sort_next)
1761 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
1763 if(!ts_min) ts_min = tm.team_size;
1764 else ts_min = min(ts_min, tm.team_size);
1765 if(!ts_max) ts_max = tm.team_size;
1766 else ts_max = max(ts_max, tm.team_size);
1768 if ((ts_max - ts_min) > 1)
1770 s = strcat(blinkcolor, "Teamnumbers are unbalanced!");
1771 tm = GetTeam(myteam, false);
1773 if (tm.team != COLOR_SPECTATOR)
1774 if (tm.team_size == ts_max)
1775 s = strcat(s, " Press ^3", getcommandkey("team menu", "menu_showteamselect"), blinkcolor, " to adjust");
1787 pos = HUD_Panel_GetPos(5);
1788 mySize = HUD_Panel_GetSize(5);
1790 HUD_Panel_DrawBg(5, pos, mySize);
1792 float timelimit, elapsedTime, minutes, seconds, timeleft, minutesLeft, secondsLeft;
1794 timelimit = getstatf(STAT_TIMELIMIT);
1796 timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
1797 timeleft = ceil(timeleft);
1798 minutesLeft = floor(timeleft / 60);
1799 secondsLeft = timeleft - minutesLeft*60;
1802 if(minutesLeft >= 5 || warmup_stage || timelimit == 0) //don't use red or yellow in warmup or when there is no timelimit
1803 timer_color = '1 1 1'; //white
1804 else if(minutesLeft >= 1)
1805 timer_color = '1 1 0'; //yellow
1807 timer_color = '1 0 0'; //red
1809 if (cvar("hud_timer_increment") || timelimit == 0 || warmup_stage) {
1810 if (time < getstatf(STAT_GAMESTARTTIME)) {
1811 //while restart is still active, show 00:00
1812 minutes = seconds = 0;
1814 elapsedTime = floor(time - getstatf(STAT_GAMESTARTTIME)); //127
1815 minutes = floor(elapsedTime / 60);
1816 seconds = elapsedTime - minutes*60;
1819 minutes = minutesLeft;
1820 seconds = secondsLeft;
1823 if(mySize_x/mySize_y > 5.1)
1827 minutes = min(minutes, 999);
1828 if(minutesLeft >= 1 || cvar("hud_timer_increment") || timelimit == 0 || warmup_stage) {
1830 drawpic_skin(pos + eX * mySize_x - eX * 5.1 * mySize_y, "timer", '1 1 0' * mySize_y, timer_color, hud_alpha_fg, DRAWFLAG_NORMAL);
1831 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);
1832 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);
1834 HUD_DrawXNum(pos + eX * mySize_x - eX * 2 * mySize_y, seconds, -2, 0, mySize_y, timer_color, 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1840 minutes = min(minutes, 99);
1841 if(minutesLeft >= 1 || cvar("hud_timer_increment") || timelimit == 0 || warmup_stage) {
1843 drawpic_skin(pos + eX * 0.5 * mySize_x - eX * 0.5 * 0.5 * mySize_y, "timer", '0.5 0.5 0' * mySize_y, timer_color, hud_alpha_fg, DRAWFLAG_NORMAL);
1844 HUD_DrawXNum(pos + eX * 0.5 * mySize_x - eX * mySize_y + eY * 0.5 * mySize_y, minutes, -2, 0, 0.5 * mySize_y, timer_color, 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1845 drawpic_skin(pos + eX * 0.5 * mySize_x - eX * 0.5 * 0.5 * mySize_y + eY * 0.5 * mySize_y, "num_colon", '0.5 0.5 0' * mySize_y, timer_color, hud_alpha_fg, DRAWFLAG_NORMAL);
1847 HUD_DrawXNum(pos + eX * 0.51 * mySize_x + eY * 0.5 * mySize_y, seconds, -2, 0, 0.5 * mySize_y, timer_color, 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1853 void HUD_Radar(void)
1856 pos = HUD_Panel_GetPos(6);
1857 mySize = HUD_Panel_GetSize(6);
1859 HUD_Panel_DrawBg(6, pos, mySize);
1861 local float color1, color2; // color already declared as a global in hud.qc
1864 float scale2d, normalsize, bigsize;
1867 teamradar_origin2d = pos + 0.5 * mySize; // TODO: stupid compat, should be removed
1868 teamradar_size2d = mySize;
1870 if(minimapname == "" && !ons_showmap)
1873 teamradar_loadcvars();
1875 switch(cl_teamradar_zoommode)
1879 f = current_zoomfraction;
1882 f = 1 - current_zoomfraction;
1892 switch(cl_teamradar_rotation)
1895 teamradar_angle = view_angles_y - 90;
1898 teamradar_angle = 90 * cl_teamradar_rotation;
1902 scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
1903 teamradar_size2d = mySize;
1905 teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0'; // we always center
1907 // pixels per world qu to match the teamradar_size2d_x range in the longest dimension
1908 if(cl_teamradar_rotation == 0)
1910 // max-min distance must fit the radar in any rotation
1911 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen2d(mi_max - mi_min));
1915 vector c0, c1, c2, c3, span;
1916 c0 = rotate(mi_min, teamradar_angle * DEG2RAD);
1917 c1 = rotate(mi_max, teamradar_angle * DEG2RAD);
1918 c2 = rotate('1 0 0' * mi_min_x + '0 1 0' * mi_max_y, teamradar_angle * DEG2RAD);
1919 c3 = rotate('1 0 0' * mi_max_x + '0 1 0' * mi_min_y, teamradar_angle * DEG2RAD);
1921 span_x = max4(c0_x, c1_x, c2_x, c3_x) - min4(c0_x, c1_x, c2_x, c3_x);
1922 span_y = max4(c0_y, c1_y, c2_y, c3_y) - min4(c0_y, c1_y, c2_y, c3_y);
1924 // max-min distance must fit the radar in x=x, y=y
1926 teamradar_size2d_x * scale2d / (1.05 * span_x),
1927 teamradar_size2d_y * scale2d / (1.05 * span_y)
1931 normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / cl_teamradar_scale;
1932 if(bigsize > normalsize)
1933 normalsize = bigsize;
1937 + (1 - f) * normalsize;
1938 teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
1939 f * (mi_min + mi_max) * 0.5
1940 + (1 - f) * view_origin);
1942 color1 = GetPlayerColor(player_localentnum-1);
1943 rgb = GetTeamRGB(color1);
1952 draw_teamradar_background(cl_teamradar_background_alpha, cl_teamradar_foreground_alpha);
1956 drawresetcliparea();
1958 vector frame_origin, frame_size;
1959 frame_origin = frame_size = '0 0 0';
1961 frame_origin_x = pos_x - teamradar_size2d_x * 0.55859375; // matches the picture
1962 frame_origin_y = pos_y - teamradar_size2d_y * 0.55859375; // matches the picture
1963 frame_size_x = pos_x * 1.1171875; // matches the picture
1964 frame_size_y = pos_y * 1.1171875; // matches the picture
1965 drawpic_skin(frame_origin, "gfx/ons-frame.tga", frame_size, '1 1 1', hud_alpha_fg, 0);
1966 drawpic_skin(frame_origin, "gfx/ons-frame-team.tga", frame_size, rgb, hud_alpha_fg, 0);
1969 pos_x - teamradar_size2d_x * 0.5,
1970 pos_y - teamradar_size2d_y * 0.5,
1976 for(tm = world; (tm = find(tm, classname, "radarlink")); )
1977 draw_teamradar_link(tm.origin, tm.velocity, tm.team);
1978 for(tm = world; (tm = findflags(tm, teamradar_icon, 0xFFFFFF)); )
1979 draw_teamradar_icon(tm.origin, tm.teamradar_icon, tm, tm.teamradar_color, hud_alpha_fg);
1980 for(tm = world; (tm = find(tm, classname, "entcs_receiver")); )
1982 color2 = GetPlayerColor(tm.sv_entnum);
1983 //if(color == COLOR_SPECTATOR || color == color2)
1984 draw_teamradar_player(tm.origin, tm.angles, GetTeamRGB(color2));
1986 draw_teamradar_player(view_origin, view_angles, '1 1 1');
1988 drawresetcliparea();
1996 pos = HUD_Panel_GetPos(7);
1997 mySize = HUD_Panel_GetSize(7);
1999 HUD_Panel_DrawBg(7, pos, mySize);
2001 float score, distribution, leader;
2002 float score_len, distr_len;
2003 vector score_pos, secondary_score_pos, distribution_color;
2005 me = (spectatee_status > 0) ? playerslots[spectatee_status - 1] : playerslots[player_localentnum - 1];
2007 if (!teamplay) { // non-teamgames
2008 // me vector := [team/connected frags id]
2009 pl = players.sort_next;
2016 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
2020 score = me.(scores[ps_primary]);
2024 if(distribution >= 5) {
2025 distribution_color = eY;
2027 } else if(distribution >= 0) {
2028 distribution_color = '1 1 1';
2030 } else if(distribution >= -5)
2031 distribution_color = '1 1 0';
2033 distribution_color = eX;
2035 score_len = strlen(ftos(score));
2036 distr_len = strlen(ftos(distribution));
2038 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);
2040 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);
2041 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);
2042 } else { // teamgames
2043 float max_fragcount;
2044 max_fragcount = -99;
2047 for(tm = teams.sort_next; tm; tm = tm.sort_next) {
2048 if(tm.team == COLOR_SPECTATOR || (!tm.team_size && !hud_configure)) // no players? don't display
2050 score = tm.(teamscores[ts_primary]);
2055 score_len = strlen(ftos(score));
2057 if (score > max_fragcount)
2058 max_fragcount = score;
2060 if(tm.team == myteam) {
2061 if (max_fragcount == score)
2064 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);
2065 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);
2067 if (max_fragcount == score)
2070 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);
2071 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);
2080 void HUD_RaceTimer (void) {
2082 pos = HUD_Panel_GetPos(8);
2083 mySize = HUD_Panel_GetSize(8);
2085 HUD_Panel_DrawBg(8, pos, mySize);
2087 drawfont = hud_bigfont;
2089 string s, forcetime;
2094 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);
2095 s = "^1Intermediate 1 (+15.42)";
2096 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);
2098 else if(race_checkpointtime)
2100 a = bound(0, 2 - (time - race_checkpointtime), 1);
2103 if(a > 0) // just hit a checkpoint?
2105 if(race_checkpoint != 254)
2107 if(race_time && race_previousbesttime)
2108 s = MakeRaceString(race_checkpoint, TIME_DECODE(race_time) - TIME_DECODE(race_previousbesttime), 0, 0, race_previousbestname);
2110 s = MakeRaceString(race_checkpoint, 0, -1, 0, race_previousbestname);
2112 forcetime = TIME_ENCODED_TOSTRING(race_time);
2117 if(race_laptime && race_nextbesttime && race_nextcheckpoint != 254)
2119 a = bound(0, 2 - ((race_laptime + TIME_DECODE(race_nextbesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1);
2120 if(a > 0) // next one?
2122 s = MakeRaceString(race_nextcheckpoint, (time + TIME_DECODE(race_penaltyaccumulator)) - race_laptime, TIME_DECODE(race_nextbesttime), 0, race_nextbestname);
2127 if(s != "" && a > 0)
2129 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
2130 //drawcolorcodedstring(m - '0 16 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2131 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);
2134 if(race_penaltytime)
2136 a = bound(0, 2 - (time - race_penaltyeventtime), 1);
2139 s = strcat("^1PENALTY: ", ftos_decimals(race_penaltytime * 0.1, 1), " (", race_penaltyreason, ")");
2140 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
2141 //drawcolorcodedstring(m - '0 32 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2142 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);
2148 a = bound(0, (time - race_checkpointtime) / 0.5, 1);
2149 //drawstring_expanding(m - '16 0 0' * stringwidth(forcetime, FALSE), forcetime, '32 32 0', '1 1 1', hud_alpha_fg, 0, a);
2150 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);
2155 if(race_laptime && race_checkpoint != 255)
2157 s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime));
2158 //drawstring(m - '16 0 0' * stringwidth(s, FALSE), s, '32 32 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2159 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);
2164 if(race_mycheckpointtime)
2166 a = bound(0, 2 - (time - race_mycheckpointtime), 1);
2167 s = MakeRaceString(race_mycheckpoint, TIME_DECODE(race_mycheckpointdelta), -!race_mycheckpointenemy, race_mycheckpointlapsdelta, race_mycheckpointenemy);
2168 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
2169 //drawcolorcodedstring(m - '0 16 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2170 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);
2172 if(race_othercheckpointtime && race_othercheckpointenemy != "")
2174 a = bound(0, 2 - (time - race_othercheckpointtime), 1);
2175 s = MakeRaceString(race_othercheckpoint, -TIME_DECODE(race_othercheckpointdelta), -!race_othercheckpointenemy, race_othercheckpointlapsdelta, race_othercheckpointenemy);
2176 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
2177 //drawcolorcodedstring(m - '0 0 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2178 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);
2181 if(race_penaltytime && !race_penaltyaccumulator)
2183 t = race_penaltytime * 0.1 + race_penaltyeventtime;
2184 a = bound(0, (1 + t - time), 1);
2188 s = strcat("^1PENALTY: ", ftos_decimals(t - time, 1), " (", race_penaltyreason, ")");
2190 s = strcat("^2PENALTY: 0.0 (", race_penaltyreason, ")");
2191 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
2192 //drawcolorcodedstring(m - '0 32 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2193 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);
2198 drawfont = hud_font;
2202 float vote_yescount;
2205 float vote_highlighted; // currently selected vote
2207 float vote_active; // is there an active vote?
2208 float vote_prev; // previous state of vote_active to check for a change
2210 float vote_change; // "time" when vote_active changed
2212 void HUD_VoteWindow(void)
2215 pos = HUD_Panel_GetPos(9);
2216 mySize = HUD_Panel_GetSize(9);
2220 if(vote_active != vote_prev) {
2222 vote_prev = bound(0, vote_active, 1);
2226 vote_alpha = bound(0, (time - vote_change) * 2, 1);
2228 vote_alpha = bound(0, 1 - (time - vote_change) * 2, 1);
2238 HUD_Panel_DrawBg(9, pos, mySize);
2241 a = vote_alpha * bound(cvar_or("hud_vote_alreadyvoted_alpha", 0.75), 1 - vote_highlighted, 1);
2243 drawpic_skin(pos, "voteprogress_back", mySize, HUD_GetBgColor(), a * hud_alpha_bg, DRAWFLAG_NORMAL);
2245 s = "A vote has been called for: ";
2246 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);
2247 s = textShortenToWidth(vote_called_vote, mySize_x * 0.96, '10 0 0', stringwidth_colors);
2249 s = "Configure the HUD";
2250 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);
2252 // print the yes/no counts
2253 s = strcat("Yes: ", ftos(vote_yescount));
2254 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);
2255 s = strcat("No: ", ftos(vote_nocount));
2256 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);
2258 // draw the progress bars
2259 drawsetcliparea(pos_x, pos_y, mySize_x * 0.5 * (vote_yescount/vote_needed), mySize_y);
2260 drawpic_skin(pos, "voteprogress_prog", mySize, eY, a * hud_alpha_fg, DRAWFLAG_NORMAL);
2262 drawsetcliparea(pos_x + mySize_x - mySize_x * 0.5 * (vote_nocount/vote_needed), pos_y, mySize_x * 0.5, mySize_y);
2263 drawpic_skin(pos, "voteprogress_prog", mySize, eX, a * hud_alpha_fg, DRAWFLAG_NORMAL);
2265 // draw the highlights
2266 if(vote_highlighted == 1) {
2267 drawsetcliparea(pos_x, pos_y, mySize_x * 0.5, mySize_y);
2268 drawpic_skin(pos, "voteprogress_voted", mySize, eY, a * hud_alpha_fg, DRAWFLAG_NORMAL);
2270 else if(vote_highlighted == 2) {
2271 drawsetcliparea(pos_x + 0.5 * mySize_x, pos_y, mySize_x * 0.5, mySize_y);
2272 drawpic_skin(pos, "voteprogress_voted", mySize, eX, a * hud_alpha_fg, DRAWFLAG_NORMAL);
2275 drawresetcliparea();
2277 else if(!vote_active) {
2278 vote_highlighted = 0;
2283 float race_status_time;
2284 float race_status_prev;
2285 string race_status_name_prev;
2286 void HUD_DrawRaceStatus(vector pos)
2288 if (race_status != race_status_prev || race_status_name != race_status_name_prev) {
2289 race_status_time = time + 5;
2290 race_status_prev = race_status;
2291 if (race_status_name_prev)
2292 strunzone(race_status_name_prev);
2293 race_status_name_prev = strzone(race_status_name);
2297 a = bound(0, race_status_time - time, 1);
2300 s = textShortenToWidth(race_status_name, 120, '10 10 0', stringwidth_colors);
2304 rank = race_CheckName(race_status_name);
2306 rankname = race_PlaceName(rank);
2308 if(race_status == 0)
2309 drawpic_skin(pos, "race_newfail", '80 80 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2310 else if(race_status == 1) {
2311 drawpic_skin(pos, "race_newtime", '80 80 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2312 drawcolorcodedstring(pos + '40 80 0' - eX * stringwidth(s, TRUE, '5 0 0'), s, '10 10 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2313 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);
2314 } else if(race_status == 2) {
2315 if(race_status_name == GetPlayerName(player_localentnum -1) || !race_myrank || race_myrank < rank)
2316 drawpic_skin(pos, "race_newrankgreen", '80 80 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2318 drawpic_skin(pos, "race_newrankyellow", '80 80 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2319 drawcolorcodedstring(pos + '40 80 0' - eX * stringwidth(s, TRUE, '5 0 0'), s, '10 10 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2320 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);
2321 } else if(race_status == 3) {
2322 drawpic_skin(pos, "race_newrecordserver", '80 80 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2323 drawcolorcodedstring(pos + '40 80 0' - eX * stringwidth(s, TRUE, '5 0 0'), s, '10 10 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2324 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);
2327 if (race_status_time - time <= 0) {
2328 race_status_prev = -1;
2330 if(race_status_name)
2331 strunzone(race_status_name);
2332 race_status_name = string_null;
2333 if(race_status_name_prev)
2334 strunzone(race_status_name_prev);
2335 race_status_name_prev = string_null;
2339 // CTF HUD modicon section
2340 float redflag_prevframe, blueflag_prevframe; // status during previous frame
2341 float redflag_prevstatus, blueflag_prevstatus; // last remembered status
2342 float redflag_statuschange_time, blueflag_statuschange_time; // time when the status changed
2344 void CSQC_ctf_hudreset(void)
2346 redflag_prevstatus = blueflag_prevstatus = redflag_prevframe = blueflag_prevframe = redflag_statuschange_time = blueflag_statuschange_time = 0;
2349 void CSQC_ctf_hud(void)
2351 vector bottomleft, redflag_pos, blueflag_pos, sz;
2352 float f; // every function should have that
2353 bottomleft_y = vid_conheight;
2356 float redflag, blueflag; // current status
2357 float redflag_statuschange_elapsedtime, blueflag_statuschange_elapsedtime; // time since the status changed
2360 stat_items = getstati(STAT_ITEMS);
2361 redflag = (stat_items/IT_RED_FLAG_TAKEN) & 3;
2362 blueflag = (stat_items/IT_BLUE_FLAG_TAKEN) & 3;
2364 // when status CHANGES, set old status into prevstatus and current status into status
2365 if (redflag != redflag_prevframe)
2367 redflag_statuschange_time = time;
2368 redflag_prevstatus = redflag_prevframe;
2369 redflag_prevframe = redflag;
2372 if (blueflag != blueflag_prevframe)
2374 blueflag_statuschange_time = time;
2375 blueflag_prevstatus = blueflag_prevframe;
2376 blueflag_prevframe = blueflag;
2379 redflag_statuschange_elapsedtime = time - redflag_statuschange_time;
2380 blueflag_statuschange_elapsedtime = time - blueflag_statuschange_time;
2382 float BLINK_FACTOR = 0.15;
2383 float BLINK_BASE = 0.85;
2385 // RMS = sqrt(BLINK_BASE^2 + 0.5 * BLINK_FACTOR^2)
2387 // BLINK_BASE = sqrt(RMS^2 - 0.5 * BLINK_FACTOR^2)
2389 float BLINK_FREQ = 5; // circle frequency, = 2*pi*frequency in hertz
2391 string red_icon, red_icon_prevstatus;
2392 float red_alpha, red_alpha_prevstatus;
2393 red_alpha = red_alpha_prevstatus = 1;
2395 case 1: red_icon = "flag_red_taken"; break;
2396 case 2: red_icon = "flag_red_lost"; break;
2397 case 3: red_icon = "flag_red_carrying"; red_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
2399 if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM2))
2400 red_icon = "flag_red_shielded";
2402 red_icon = string_null;
2405 switch(redflag_prevstatus) {
2406 case 1: red_icon_prevstatus = "flag_red_taken"; break;
2407 case 2: red_icon_prevstatus = "flag_red_lost"; break;
2408 case 3: red_icon_prevstatus = "flag_red_carrying"; red_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
2411 red_icon_prevstatus = "flag_red_carrying"; // make it more visible
2412 else if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM2))
2413 red_icon_prevstatus = "flag_red_shielded";
2415 red_icon_prevstatus = string_null;
2419 string blue_icon, blue_icon_prevstatus;
2420 float blue_alpha, blue_alpha_prevstatus;
2421 blue_alpha = blue_alpha_prevstatus = 1;
2423 case 1: blue_icon = "flag_blue_taken"; break;
2424 case 2: blue_icon = "flag_blue_lost"; break;
2425 case 3: blue_icon = "flag_blue_carrying"; blue_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
2427 if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM1))
2428 blue_icon = "flag_blue_shielded";
2430 blue_icon = string_null;
2433 switch(blueflag_prevstatus) {
2434 case 1: blue_icon_prevstatus = "flag_blue_taken"; break;
2435 case 2: blue_icon_prevstatus = "flag_blue_lost"; break;
2436 case 3: blue_icon_prevstatus = "flag_blue_carrying"; blue_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
2439 blue_icon_prevstatus = "flag_blue_carrying"; // make it more visible
2440 else if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM1))
2441 blue_icon_prevstatus = "flag_blue_shielded";
2443 blue_icon_prevstatus = string_null;
2447 if (myteam == COLOR_TEAM1) { // always draw own flag on left
2448 redflag_pos = bottomleft - '-4 50 0';
2449 blueflag_pos = bottomleft - '-62 50 0';
2451 blueflag_pos = bottomleft - '-4 50 0';
2452 redflag_pos = bottomleft - '-62 50 0';
2457 f = bound(0, redflag_statuschange_elapsedtime*2, 1);
2458 if(red_icon_prevstatus && f < 1)
2459 drawpic_expanding(redflag_pos, red_icon_prevstatus, sz, '1 1 1', hud_alpha_fg * red_alpha_prevstatus, DRAWFLAG_NORMAL, f);
2461 drawpic_skin(redflag_pos, red_icon, sz, '1 1 1', hud_alpha_fg * red_alpha * f, DRAWFLAG_NORMAL);
2463 f = bound(0, blueflag_statuschange_elapsedtime*2, 1);
2464 if(blue_icon_prevstatus && f < 1)
2465 drawpic_expanding(blueflag_pos, blue_icon_prevstatus, sz, '1 1 1', hud_alpha_fg * blue_alpha_prevstatus, DRAWFLAG_NORMAL, f);
2467 drawpic_skin(blueflag_pos, blue_icon, sz, '1 1 1', hud_alpha_fg * blue_alpha * f, DRAWFLAG_NORMAL);
2470 /*void HUD_Mod_Race (void) {
2471 if((scores_flags[ps_primary] & SFL_TIME) && !teamplay) { // race/cts record display on HUD
2472 pl = players.sort_next;
2475 if(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)
2476 if(pl.scores[ps_primary] == 0)
2479 score = me.(scores[ps_primary]);
2481 float racemin, racesec, racemsec;
2482 float distsec, distmsec, minusplus;
2484 racemin = floor(score/(60 * TIME_FACTOR));
2485 racesec = floor((score - racemin*(60 * TIME_FACTOR))/TIME_FACTOR);
2486 racemsec = score - racemin*60*TIME_FACTOR - racesec*TIME_FACTOR;
2488 if (pl && ((!(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)) || score)) {
2489 // distribution display
2490 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
2492 if (distribution < TIME_FACTOR && distribution > -TIME_FACTOR)
2493 distmsec = fabs(distribution);
2495 distsec = floor(fabs(distribution)/TIME_FACTOR);
2496 distmsec = fabs(distribution) - distsec*TIME_FACTOR;
2497 if (distribution < 0)
2501 if (distribution <= 0) {
2502 distribution_color = eY;
2503 minusplus = 1; // minusplus 1: always prefix with minus sign
2506 distribution_color = eX;
2507 minusplus = 2; // minusplus 1: always prefix with plus sign
2509 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);
2510 HUD_DrawXNum(bottomright - '68 48 0' - '16 0 0' * TIME_DECIMALS, distsec, 4, minusplus, 16, distribution_color, 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
2511 drawpic_skin(bottomright - '10 48 0' - '16 0 0' * TIME_DECIMALS, "num_dot", '16 16 0', distribution_color, hud_alpha_fg, DRAWFLAG_ADDITIVE);
2513 // race record display
2514 if (distribution <= 0 || distribution == score) // draw the highlight background behind the timer if we have the lead
2515 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);
2517 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);
2518 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);
2519 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);
2521 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);
2522 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);
2526 // Keyhunt HUD modicon section
2527 float kh_runheretime;
2529 void CSQC_kh_hudreset(void)
2534 void CSQC_kh_hud(void)
2539 vector p, pa, kh_size, kh_asize;
2542 p_y = vid_conheight - 34 - 3;
2545 kh_keys = getstati(STAT_KH_KEYS);
2547 kh_size = '19 34 0';
2548 kh_asize = '19 10 0';
2555 for(i = 0; i < 4; ++i)
2557 key = floor(kh_keys / pow(32, i)) & 31;
2559 if(keyteam == 30 && keycount <= 4)
2561 if(keyteam == myteam || keyteam == -1 || keyteam == 30)
2564 // this yields 8 exactly if "RUN HERE" shows
2569 kh_runheretime = time;
2570 pa_y -= fabs(sin((time - kh_runheretime) * 3.5)) * 6; // make the arrows jump in case of RUN HERE
2575 for(i = 0; i < 4; ++i)
2577 key = floor(kh_keys / pow(32, i)) & 31;
2590 default: // owned or dropped
2595 a = a * hud_alpha_fg;
2596 aa = aa * hud_alpha_fg;
2602 drawpic (pa, "kh_redarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
2605 drawpic (pa, "kh_bluearrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
2608 drawpic (pa, "kh_yellowarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
2611 drawpic (pa, "kh_pinkarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
2616 switch(i) // YAY! switch(i) inside a for loop for i. DailyWTF, here we come!
2619 drawpic (p, "kh_red", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
2622 drawpic (p, "kh_blue", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
2625 drawpic (p, "kh_yellow", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
2628 drawpic (p, "kh_pink", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
2637 // Nexball HUD modicon section
2638 #define NBPB_SIZE '96 38 0'
2639 #define NBPB_BT 2 //thickness
2640 #define NBPB_BRGB '1 1 1'
2641 #define NBPB_BALPH 1 //alpha
2642 #define NBPB_BFLAG DRAWFLAG_NORMAL
2643 #define NBPB_IALPH 0.4
2644 #define NBPB_IFLAG DRAWFLAG_NORMAL
2645 #define NBPB_IRGB '0.7 0.1 0'
2647 void CSQC_nb_hud(void)
2649 float stat_items, nb_pb_starttime, dt, p;
2652 stat_items = getstati(STAT_ITEMS);
2653 nb_pb_starttime = getstatf(STAT_NB_METERSTART);
2656 pos_y = vid_conheight - 42;
2659 //Manage the progress bar if any
2660 if (nb_pb_starttime > 0)
2663 dt = mod(time - nb_pb_starttime, nb_pb_period);
2664 // one period of positive triangle
2665 p = 2 * dt / nb_pb_period;
2671 drawfill(pos, p * s_x * eX + s_y * eY, NBPB_IRGB, NBPB_IALPH, NBPB_IFLAG);
2675 drawline(NBPB_BT, pos , pos + eX * s_x, NBPB_BRGB, NBPB_BALPH, NBPB_BFLAG);
2676 drawline(NBPB_BT, pos , pos + eY * s_y, NBPB_BRGB, NBPB_BALPH, NBPB_BFLAG);
2677 drawline(NBPB_BT, pos + s, pos + eX * s_x, NBPB_BRGB, NBPB_BALPH, NBPB_BFLAG);
2678 drawline(NBPB_BT, pos + s, pos + eY * s_y, NBPB_BRGB, NBPB_BALPH, NBPB_BFLAG);
2681 pos_x += 12; //horizontal margin to the picture
2682 pos_y += 2; //vertical margin to the picture
2684 if (stat_items & IT_KEY1)
2685 drawpic_skin(pos, "nexball_carrying", '80 34 0', '1 1 1', 1, DRAWFLAG_NORMAL);
2688 // Race/CTS HUD modicon section
2689 float crecordtime_prev; // last remembered crecordtime
2690 float crecordtime_change_time; // time when crecordtime last changed
2691 float srecordtime_prev; // last remembered srecordtime
2692 float srecordtime_change_time; // time when srecordtime last changed
2693 void CSQC_race_hud(void)
2696 me = playerslots[player_localentnum - 1];
2698 float f; // yet another function has this
2699 score = me.(scores[ps_primary]);
2701 if not((scores_flags[ps_primary] & SFL_TIME) && !teamplay) // race/cts record display on HUD
2702 return; // no records in the actual race
2704 drawfont = hud_bigfont;
2707 pos_y = vid_conheight - 48;
2709 // clientside personal record
2711 if(gametype == GAME_CTS)
2715 t = stof(db_get(ClientProgsDB, strcat(shortmapname, rr, "time")));
2717 if(score && (score < t || !t)) {
2718 db_put(ClientProgsDB, strcat(shortmapname, rr, "time"), ftos(score));
2719 if(cvar("cl_autodemo_delete_keeprecords"))
2721 f = cvar("cl_autodemo_delete");
2723 cvar_set("cl_autodemo_delete", ftos(f)); // don't delete demo with new record!
2727 if(t != crecordtime_prev) {
2728 crecordtime_prev = t;
2729 crecordtime_change_time = time;
2731 f = time - crecordtime_change_time;
2734 drawstring(pos, "Personal best ", '10 10 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2735 drawstring(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2737 drawstring(pos, "Personal best ", '10 10 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2738 drawstring(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2739 drawstring_expanding(pos, "Personal best ", '10 10 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL, f);
2740 drawstring_expanding(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL, f);
2745 t = race_server_record;
2746 if(t != srecordtime_prev) {
2747 srecordtime_prev = t;
2748 srecordtime_change_time = time;
2750 f = time - srecordtime_change_time;
2753 drawstring(pos, "Server best ", '10 10 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2754 drawstring(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2756 drawstring(pos, "Server best ", '10 10 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2757 drawstring(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2758 drawstring_expanding(pos, "Server best ", '10 10 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL, f);
2759 drawstring_expanding(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL, f);
2761 drawfont = hud_font;
2770 void HUD_DrawPressedKeys(void)
2773 pos = HUD_Panel_GetPos(10);
2774 mySize = HUD_Panel_GetSize(10);
2776 HUD_Panel_DrawBg(10, pos, mySize);
2780 pressedkeys = getstatf(STAT_PRESSED_KEYS);
2781 drawpic_skin(pos, "keys/key_bg.tga", mySize, '1 1 1', 0.1 * hud_alpha_fg, DRAWFLAG_NORMAL);
2782 drawpic_skin(pos + eX * mySize_x - eX * 0.22 * mySize_x + eY * 0.195 * mySize_y, ((pressedkeys & KEY_CROUCH) ? "keys/key_crouch_inv.tga" : "keys/key_crouch.tga"), '1 1 0' * (1/3) * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2783 drawpic_skin(pos + eX * 0.5 * mySize_x - eX * 0.23 * mySize_y + eY * 0.040 * mySize_y, ((pressedkeys & KEY_FORWARD) ? "keys/key_forward_inv.tga" : "keys/key_forward.tga"), '1 1 0' * 0.46 * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2784 drawpic_skin(pos + eX * 0.023 * mySize_x + eY * 0.195 * mySize_y, ((pressedkeys & KEY_JUMP) ? "keys/key_jump_inv.tga" : "keys/key_jump.tga"), '1 1 0' * (1/3) * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2785 drawpic_skin(pos + eX * 0.1 * mySize_x + eY * 0.486 * mySize_y, ((pressedkeys & KEY_LEFT) ? "keys/key_left_inv.tga" : "keys/key_left.tga"), '1 1 0' * 0.46 * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2786 drawpic_skin(pos + eX * 0.5 * mySize_x - eX * 0.23 * mySize_y + eY * 0.486 * mySize_y, ((pressedkeys & KEY_BACKWARD) ? "keys/key_backward_inv.tga" : "keys/key_backward.tga"), '1 1 0' * 0.46 * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2787 drawpic_skin(pos + eX * mySize_x - eX * 0.372 * mySize_x + eY * 0.486 * mySize_y, ((pressedkeys & KEY_RIGHT) ? "keys/key_right_inv.tga" : "keys/key_right.tga"), '1 1 0' * 0.46 * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2790 void HUD_ShowSpeed(void)
2793 float pos, conversion_factor;
2794 string speed, zspeed, unit;
2796 switch(cvar("cl_showspeed_unit"))
2801 conversion_factor = 1.0;
2805 conversion_factor = 1.0;
2809 conversion_factor = 0.0254;
2813 conversion_factor = 0.0254 * 3.6;
2817 conversion_factor = 0.0254 * 3.6 * 0.6213711922;
2821 conversion_factor = 0.0254 * 1.943844492; // 1 m/s = 1.943844492 knots, because 1 knot = 1.852 km/h
2825 speed = strcat(ftos(floor( vlen(pmove_vel - pmove_vel_z * '0 0 1') * conversion_factor + 0.5 )), unit);
2827 numsize_x = numsize_y = cvar("cl_showspeed_size");
2828 pos = (vid_conheight - numsize_y) * cvar("cl_showspeed_position");
2830 drawfont = hud_bigfont;
2831 drawstringcenter(eX + pos * eY, speed, numsize, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2833 if (cvar("cl_showspeed_z") == 1) {
2834 zspeed = strcat(ftos(fabs(floor( pmove_vel_z * conversion_factor + 0.5 ))), unit);
2835 drawstringcenter(eX + pos * eY + numsize_y * eY, zspeed, numsize * 0.5, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2838 drawfont = hud_font;
2841 vector acc_prevspeed;
2845 void HUD_ShowAcceleration(void)
2847 float acceleration, sz, scale, alpha, f;
2848 vector pos, top, rgb;
2849 top_x = vid_conwidth/2;
2852 f = time - acc_prevtime;
2853 if(cvar("cl_showacceleration_z"))
2854 acceleration = (vlen(pmove_vel) - vlen(acc_prevspeed)) * (1 / f);
2856 acceleration = (vlen(pmove_vel - '0 0 1' * pmove_vel_z) - vlen(acc_prevspeed - '0 0 1' * acc_prevspeed_z)) * (1 / f);
2857 acc_prevspeed = pmove_vel;
2858 acc_prevtime = time;
2860 f = bound(0, f * 10, 1);
2861 acc_avg = acc_avg * (1 - f) + acceleration * f;
2862 acceleration = acc_avg / getstatf(STAT_MOVEVARS_MAXSPEED);
2864 pos = top - sz/2 * eY + (cvar("cl_showacceleration_position") * vid_conheight) * eY;
2866 sz = cvar("cl_showacceleration_size");
2867 scale = cvar("cl_showacceleration_scale");
2868 alpha = cvar("cl_showacceleration_alpha");
2869 if (cvar("cl_showacceleration_color_custom"))
2870 rgb = stov(cvar_string("cl_showacceleration_color"));
2873 if (acceleration < 0) {
2874 rgb = '1 .5 .5' - '0 .5 .5' * bound(0, -acceleration * 0.2, 1);
2875 } else if (acceleration > 0) {
2876 rgb = '.5 1 .5' - '.5 0 .5' * bound(0, +acceleration * 0.2, 1);
2880 if (acceleration > 0)
2881 drawpic_skin(pos, "statusbar", acceleration * scale * '40 0 0' + sz * eY, rgb, alpha * hud_alpha_fg, DRAWFLAG_NORMAL);
2882 else if (acceleration < 0)
2883 drawpic_skin(pos + acceleration * scale * '40 0 0', "statusbar", -acceleration * scale * '40 0 0' + sz * eY, rgb, alpha * hud_alpha_fg, DRAWFLAG_NORMAL);
2886 void HUD_Reset (void)
2888 // reset gametype specific icons
2889 if(gametype == GAME_KEYHUNT)
2891 else if(gametype == GAME_CTF)
2892 CSQC_ctf_hudreset();
2895 void HUD_Main (void)
2897 hud_alpha_bg = cvar_or("hud_bg_alpha", 0.8) * (1 - cvar("_menu_alpha"));
2898 hud_border_thickness = bound(0, cvar("hud_border_thickness"), 5);
2899 hud_accuracy_border_thickness = bound(0, cvar_or("hud_accuracy_border_thickness", 1), 5);
2900 hud_color_bg_team = cvar("hud_color_bg_team");
2902 hud_fontsize = HUD_GetFontsize("hud_fontsize");
2903 hud_fontsize_spec = HUD_GetFontsize("hud_fontsize_spec");
2905 hud_configure = cvar("_hud_configure");
2908 if(cvar("hud_dock"))
2909 drawpic_skin('0 0 0', "dock", eX * vid_conwidth + eY * vid_conheight, stov(cvar_string("hud_dock_color")), cvar("hud_dock_alpha"), DRAWFLAG_NORMAL);
2911 if(HUD_Panel_CheckActive(0))
2913 if(HUD_Panel_CheckActive(1))
2915 if(HUD_Panel_CheckActive(2))
2917 if(HUD_Panel_CheckActive(3))
2919 if(HUD_Panel_CheckActive(4))
2921 if(HUD_Panel_CheckActive(5))
2924 if(HUD_Panel_CheckActive(6))
2925 if(ons_showmap || cvar_string("cl_teamradar") != "0" && (cvar("cl_teamradar") == 2 || teamplay))
2927 if(HUD_Panel_CheckActive(7))
2929 if(HUD_Panel_CheckActive(8))
2930 if(gametype == GAME_RACE || gametype == GAME_CTS || hud_configure)
2932 if(HUD_Panel_CheckActive(9))
2935 if(HUD_Panel_CheckActive(10))
2936 if(spectatee_status > 0 || cvar("cl_showpressedkeys") >= 2 || hud_configure)
2937 HUD_DrawPressedKeys();
2939 // TODO hud_'ify these
2940 if (cvar("cl_showspeed"))
2942 if (cvar("cl_showacceleration"))
2943 HUD_ShowAcceleration();
2945 // TODO... well make them work in a panel etc
2946 if(gametype == GAME_KEYHUNT)
2948 else if(gametype == GAME_CTF)
2950 else if(gametype == GAME_NEXBALL)
2952 else if(gametype == GAME_CTS || gametype == GAME_RACE)