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 // return HUD background color
79 vector HUD_GetBgColor()
83 GetTeamRGB(myteam) * hud_color_bg_team;
85 // allow custom HUD colors in non-teamgames
86 color_x = cvar("hud_color_bg_r");
87 color_y = cvar("hud_color_bg_g");
88 color_z = cvar("hud_color_bg_b");
93 // return accuracy text color
94 vector HUD_AccuracyColor(float accuracy)
97 float yellow_accuracy = cvar("hud_accuracy_yellow"); // value at which this function returns yellow
102 else if(accuracy > yellow_accuracy) {
103 rgb_x = 1 - (accuracy-yellow_accuracy)/(100-yellow_accuracy); // red value between 1 -> 0
108 rgb_y = accuracy/yellow_accuracy; // green value between 0 -> 1
114 // draw number in the XSCALE font
115 void HUD_DrawXNum (vector pos, float num, float digits, float showsign, float lettersize, vector rgb, float highlighted, float stroke, float alpha, float dflags)
118 string str, tmp, l_length;
120 vector vsize, num_color;
122 vsize_x = vsize_y = lettersize;
125 // showsign 1: always prefix with minus sign (useful in race distribution display)
126 // showsign 2: always prefix with plus sign (useful in race distribution display)
127 // showsign 3: prefix with minus sign if negative, plus sign if positive (useful in score distribution display)
129 if((showsign == 2 && num >= 0) || (num > 0 && showsign == 3))
136 if(num < 0 || (num < 0 && showsign == 3) || (showsign == 1 && num <= 0))
148 str = strcat(substring("0000000000", 0, digits - strlen(tmp)), tmp);
157 str = substring(str, l-digits, 999);
159 } else if(l < digits)
160 pos_x += (digits-l) * lettersize;
162 if (highlighted == 1) {
164 hl_size_x = vsize_x * l + vsize_x * 0.2;
165 hl_size_y = vsize_y * 1.1;
168 hl_size_x = hl_size_x + vsize_x;
171 hl_pos_x = pos_x - lettersize/10;
172 hl_pos_y = pos_y - lettersize/20;
175 drawpic(hl_pos, strcat("gfx/hud/sb_highlight_", l_length), hl_size, '1 1 1', alpha, dflags);
186 drawpic(pos, "gfx/hud/num_minus_stroke", vsize, rgb, alpha, dflags);
187 drawpic(pos, "gfx/hud/num_minus", vsize, num_color, alpha, dflags);
192 drawpic(pos, "gfx/hud/num_plus_stroke", vsize, rgb, alpha, dflags);
193 drawpic(pos, "gfx/hud/num_plus", vsize, num_color, alpha, dflags);
197 for(i = 0; i < l; ++i)
199 tmp = substring(str, i, 1);
201 drawpic(pos, strcat("gfx/hud/num_", tmp, "_stroke"), vsize, rgb, alpha, dflags);
202 drawpic(pos, strcat("gfx/hud/num_", tmp), vsize, num_color, alpha, dflags);
207 // color the number differently based on how big it is (used in the health/armor panel)
208 void HUD_DrawXNum_Colored (vector pos, float x, float digits, float lettersize, float alpha)
217 color_x = 0.4 - (x-150)*0.02 * 0.4; //red value between 0.4 -> 0
218 color_y = 0.9 + (x-150)*0.02 * 0.1; // green value between 0.9 -> 1
222 color_x = 1 - (x-100)*0.02 * 0.6; //red value between 1 -> 0.4
223 color_y = 1 - (x-100)*0.02 * 0.1; // green value between 1 -> 0.9
224 color_z = 1 - (x-100)*0.02; // blue value between 1 -> 0
229 color_z = 0.2 + (x-50)*0.02 * 0.8; // blue value between 0.2 -> 1
233 color_y = (x-20)*90/27/100; // green value between 0 -> 1
234 color_z = (x-20)*90/27/100 * 0.2; // blue value between 0 -> 0.2
241 HUD_DrawXNum(pos, x, digits, 0, lettersize, color, 0, 0, alpha, DRAWFLAG_NORMAL);
244 float stringwidth_colors(string s, vector theSize)
246 return stringwidth(s, TRUE, theSize);
249 float stringwidth_nocolors(string s, vector theSize)
251 return stringwidth(s, FALSE, theSize);
254 #define CENTERPRINT_MAX_LINES 30
255 string centerprint_messages[CENTERPRINT_MAX_LINES];
256 float centerprint_width[CENTERPRINT_MAX_LINES];
257 vector centerprint_start;
258 float centerprint_expire;
259 float centerprint_num;
260 float centerprint_offset_hint;
261 vector centerprint_fontsize;
263 void centerprint(string strMessage)
265 float i, j, n, hcount;
268 centerprint_fontsize = HUD_GetFontsize("scr_centersize");
270 centerprint_expire = min(centerprint_expire, time); // if any of the returns happens, this message will fade out
272 if(cvar("scr_centertime") <= 0)
278 // strip trailing newlines
279 j = strlen(strMessage) - 1;
280 while(substring(strMessage, j, 1) == "\n" && j >= 0)
282 strMessage = substring(strMessage, 0, j + 1);
287 // strip leading newlines and remember them, they are a hint that the message should be lower on the screen
289 while(substring(strMessage, j, 1) == "\n" && j < strlen(strMessage))
291 strMessage = substring(strMessage, j, strlen(strMessage) - j);
292 centerprint_offset_hint = j;
297 // if we get here, we have a message. Initialize its height.
300 n = tokenizebyseparator(strMessage, "\n");
302 for(j = 0; j < n; ++j)
304 getWrappedLine_remaining = argv(j);
305 while(getWrappedLine_remaining)
307 s = getWrappedLine(vid_conwidth * 0.75, centerprint_fontsize, stringwidth_colors);
308 if(centerprint_messages[i])
309 strunzone(centerprint_messages[i]);
310 centerprint_messages[i] = strzone(s);
311 centerprint_width[i] = stringwidth(s, TRUE, centerprint_fontsize);
314 // half height for empty lines looks better
320 if(i >= CENTERPRINT_MAX_LINES)
326 h = centerprint_fontsize_y*hcount;
328 havail = vid_conheight;
329 if(cvar("con_chatpos") < 0)
330 havail -= (-cvar("con_chatpos") + cvar("con_chat")) * cvar("con_chatsize"); // avoid overlapping chat
331 if(havail > vid_conheight - 70)
332 havail = vid_conheight - 70; // avoid overlapping HUD
334 centerprint_start_x = 0;
337 float forbiddenmin, forbiddenmax, allowedmin, allowedmax, preferred;
339 // here, the centerprint would cover the crosshair. REALLY BAD.
340 forbiddenmin = vid_conheight * 0.5 - h - 16;
341 forbiddenmax = vid_conheight * 0.5 + 16;
343 allowedmin = scoreboard_bottom;
344 allowedmax = havail - h;
345 preferred = (havail - h)/2;
348 // possible orderings (total: 4! / 4 = 6)
349 // allowedmin allowedmax forbiddenmin forbiddenmax
350 // forbiddenmin forbiddenmax allowedmin allowedmax
351 if(allowedmax < forbiddenmin || allowedmin > forbiddenmax)
353 // forbidden doesn't matter in this case
354 centerprint_start_y = bound(allowedmin, preferred, allowedmax);
356 // allowedmin forbiddenmin allowedmax forbiddenmax
357 else if(allowedmin < forbiddenmin && allowedmax < forbiddenmax)
359 centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
361 // allowedmin forbiddenmin forbiddenmax allowedmax
362 else if(allowedmin < forbiddenmin)
364 // make sure the forbidden zone is not covered
365 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
366 centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
368 centerprint_start_y = bound(forbiddenmax, preferred, allowedmin);
370 // forbiddenmin allowedmin allowedmax forbiddenmax
371 else if(allowedmax < forbiddenmax)
373 // it's better to leave the allowed zone (overlap with scoreboard) than
374 // to cover the forbidden zone (crosshair)
375 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
376 centerprint_start_y = forbiddenmax;
378 centerprint_start_y = forbiddenmin;
380 // forbiddenmin allowedmin forbiddenmax allowedmax
383 centerprint_start_y = bound(forbiddenmax, preferred, allowedmax);
386 centerprint_start_y =
389 max(scoreboard_bottom, vid_conheight * 0.5 + 16),
397 centerprint_expire = time + cvar("scr_centertime");
400 void HUD_DrawCenterPrint (void)
407 //if(time > centerprint_expire)
410 //a = bound(0, 1 - 2 * (time - centerprint_expire), 1);
411 a = bound(0, 1 - 4 * (time - centerprint_expire), 1);
412 //sz = 1.2 / (a + 0.2);
417 pos = centerprint_start;
418 for (i=0; i<centerprint_num; i = i + 1)
420 pos_x = (vid_conwidth - centerprint_width[i]) * 0.5;
421 ts = centerprint_messages[i];
424 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
425 drawcolorcodedstring(pos, ts, centerprint_fontsize, a, DRAWFLAG_NORMAL);
426 // - '0 0.5 0' * (sz - 1) * centerprint_fontsize_x - '0.5 0 0' * (sz - 1) * centerprint_width[i] * centerprint_fontsize_y, centerprint_fontsize * sz
427 pos_y = pos_y + centerprint_fontsize_y;
430 // half height for empty lines looks better
431 pos_y = pos_y + centerprint_fontsize_y * 0.5;
435 void drawstringright(vector position, string text, vector scale, vector rgb, float alpha, float flag)
437 position_x -= 2 / 3 * strlen(text) * scale_x;
438 drawstring(position, text, scale, rgb, alpha, flag);
441 void drawstringcenter(vector position, string text, vector scale, vector rgb, float alpha, float flag)
443 position_x = 0.5 * (vid_conwidth - 0.6025 * strlen(text) * scale_x);
444 drawstring(position, text, scale, rgb, alpha, flag);
447 // return the string of the given race place
448 string race_PlaceName(float pos) {
456 return strcat(ftos(pos), "th");
459 // return the string of the onscreen race timer
460 string MakeRaceString(float cp, float mytime, float histime, float lapdelta, string hisname)
468 if(histime == 0) // goal hit
472 timestr = strcat("+", ftos_decimals(+mytime, TIME_DECIMALS));
482 timestr = strcat("-", ftos_decimals(-mytime, TIME_DECIMALS));
488 lapstr = strcat(" (-", ftos(lapdelta), "L)");
491 else if(lapdelta < 0)
493 lapstr = strcat(" (+", ftos(-lapdelta), "L)");
497 else if(histime > 0) // anticipation
499 if(mytime >= histime)
500 timestr = strcat("+", ftos_decimals(mytime - histime, TIME_DECIMALS));
502 timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(histime));
509 cpname = "Start line";
511 cpname = "Finish line";
513 cpname = strcat("Intermediate ", ftos(cp));
515 cpname = "Finish line";
518 return strcat(col, cpname);
519 else if(hisname == "")
520 return strcat(col, cpname, " (", timestr, ")");
522 return strcat(col, cpname, " (", timestr, " ", strcat(hisname, col, lapstr), ")");
525 // Check if the given name already exist in race rankings? In that case, where? (otherwise return 0)
526 float race_CheckName(string net_name) {
528 for (i=RANKINGS_CNT-1;i>=0;--i)
529 if(grecordholder[i] == net_name)
540 string HUD_Panel_GetName(float id)
543 case 0: return "weaponicons"; break;
544 case 1: return "inventory"; break;
545 case 2: return "powerups"; break;
546 case 3: return "healtharmor"; break;
547 case 4: return "notify"; break;
548 case 5: return "timer"; break;
549 case 6: return "radar"; break;
550 case 7: return "score"; break;
551 case 8: return "racetimer"; break;
552 case 9: return "vote"; break;
553 case 10: return "pressedkeys"; break;
558 vector HUD_Panel_CheckLimitSize(float id, vector mySize)
562 mySize_x = max(mySize_y * (1/10), mySize_x); // at least 1/10 * height
563 mySize_y = max(mySize_x * (1/26), mySize_y); // at least 1/26 * width
566 mySize_x = max(mySize_y * 0.7, mySize_x); // at least 0.7 * height
569 mySize_x = max(mySize_y * 2, mySize_x); // at least 2 * height
572 mySize_x = max(mySize_y * 2, mySize_x); // at least 2 * height
575 mySize_x = max(mySize_y * 2, mySize_x); // at least 2 * height
578 mySize_y = (17/90) * mySize_x; // 17/90 * width
581 mySize_y = (1/4) * mySize_x; // 1/4 * width
584 mySize_y = (1/4) * mySize_x; // 1/4 * width
587 mySize_y = 0.5898 * mySize_x; // 0.5898 * width, reason: bg has weird dimensions...
593 // return active status of panel
594 float HUD_Panel_CheckActive(float id)
596 if (cvar_or(strcat("hud_", HUD_Panel_GetName(id)), 1))
601 // return size of given panel
602 vector HUD_Panel_GetSize(float id)
604 return stov(cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_size")));
607 // return pos of given panel
608 vector HUD_Panel_GetPos(float id)
611 pos = stov(cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_pos")));
614 pos_x = vid_conwidth + pos_x;
616 pos_y = vid_conheight + pos_y;
620 float HUD_Panel_GetBorder(float id)
623 border = cvar(strcat("hud_", HUD_Panel_GetName(id), "_bg_border"));
625 border = cvar("hud_bg_border");
629 // draw the background/borders
630 void HUD_Panel_DrawBg(float id, vector pos, vector mySize)
632 if(!cvar("_hud_configure") && cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg")) == "0")
636 bg = cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg"));
638 bg = cvar_string("hud_bg");
643 border = HUD_Panel_GetBorder(id);
646 if(cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_color")) != "")
647 color = stov(cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_color")));
649 color = stov(cvar_string("hud_bg_color"));
652 alpha = cvar(strcat("hud_", HUD_Panel_GetName(id), "_bg_alpha"));
654 alpha = cvar("hud_bg_alpha");
655 if(cvar("_hud_configure"))
656 alpha = max(cvar("hud_configure_bg_minalpha"), alpha);
658 draw_BorderPicture(pos - '1 1 0' * border, strcat("gfx/hud/", bg), mySize + '1 1 0' * 2 * border, color, alpha, '1 1 0' * (border/BORDER_MULTIPLIER));
662 vector HUD_Panel_GetProgressBarColor(string item)
664 return stov(cvar_string(strcat("hud_progressbar_", item, "_color")));
667 float resizeCorner; // 1 = topleft, 2 = topright, 3 = bottomleft, 4 = bottomright
668 // check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
669 vector HUD_Panel_CheckResize(float id, vector myPos, vector mySize)
681 for (i = 0; i < panel_cnt; ++i) {
682 if(i == id || !HUD_Panel_CheckActive(i))
685 targPos = HUD_Panel_GetPos(i);
686 targSize = HUD_Panel_GetSize(i);
688 targPos = HUD_Panel_GetPos(i) - '1 1 0' * HUD_Panel_GetBorder(id);
689 targSize = HUD_Panel_GetSize(i) + '2 2 0' * HUD_Panel_GetBorder(id);
691 if(myPos_y + mySize_y < targPos_y)
693 if(myPos_y > targPos_y + targSize_y)
696 if(myPos_x + mySize_x < targPos_x)
698 if(myPos_x > targPos_x + targSize_x)
701 // OK, there IS a collision.
703 myCenter_x = myPos_x + 0.5 * mySize_x;
704 myCenter_y = myPos_y + 0.5 * mySize_y;
706 targCenter_x = targPos_x + 0.5 * targSize_x;
707 targCenter_y = targPos_y + 0.5 * targSize_y;
710 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y && resizeCorner != 1) // top left (of target panel)
712 if(myPos_x + mySize_x - targPos_x < myPos_y + mySize_y - targPos_y) // push it to the side
713 myTarget_x = targPos_x - myPos_x;
714 else // push it upwards
715 myTarget_y = targPos_y - myPos_y;
717 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y && resizeCorner != 2) // top right
719 if(targPos_x + targSize_x - myPos_x < myPos_y + mySize_y - targPos_y) // push it to the side
720 myTarget_x = targPos_x + targSize_x;
721 else // push it upwards
722 myTarget_y = targPos_y - myPos_y;
724 else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
726 if(myPos_x + mySize_x - targPos_x < targPos_y + targSize_y - myPos_y) // push it to the side
727 myTarget_x = targPos_x - myPos_x;
728 else // push it downwards
729 myTarget_y = targPos_y + targSize_y;
731 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
733 if(targPos_x + targSize_x - myPos_x < targPos_y + targSize_y - myPos_y) // push it to the side
734 myTarget_x = targPos_x + targSize_x;
735 else // push it downwards
736 myTarget_y = targPos_y + targSize_y;
744 float HUD_Panel_SetSize(float id, vector mySize)
749 oldSize = stov(cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_size")));
752 myPos = HUD_Panel_GetPos(id);
754 // check for collisions
755 mySize = HUD_Panel_CheckResize(id, HUD_Panel_GetPos(id), mySize);
757 mySize_x = bound(0.025 * vid_conwidth, mySize_x, vid_conwidth - myPos_x);
758 mySize_y = bound(0.025 * vid_conheight, mySize_y, vid_conheight - myPos_y);
760 // cap against panel's own limits
761 mySize = HUD_Panel_CheckLimitSize(id, mySize);
763 //mySize_x = bound(0.025 * vid_conwidth, mySize_x, vid_conwidth);
764 //mySize_y = bound(0.025 * vid_conheight, mySize_y, vid_conheight);
766 // TODO: is this needed?
767 // this is to check if (and how) SetPos should be called
768 if(mySize_x == oldSize_x && mySize_y == oldSize_y)
769 didntresize = 3; // didnt resize either
770 else if(mySize_x == oldSize_x && mySize_y != oldSize_y)
771 didntresize = 2; // resized Y
772 else if(mySize_y == oldSize_y && mySize_x != oldSize_x)
773 didntresize = 1; // resized X
776 s = strcat(ftos(mySize_x), " ", ftos(mySize_y));
777 cvar_set(strcat("hud_", HUD_Panel_GetName(id), "_size"), s);
781 // check if move will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
782 vector HUD_Panel_CheckMove(float id, vector myPos, vector mySize)
794 for (i = 0; i < panel_cnt; ++i) {
795 if(i == id || !HUD_Panel_CheckActive(i))
798 targPos = HUD_Panel_GetPos(i) - '1 1 0' * HUD_Panel_GetBorder(id);
799 targSize = HUD_Panel_GetSize(i) + '2 2 0' * HUD_Panel_GetBorder(id);
801 if(myPos_y + mySize_y < targPos_y)
803 if(myPos_y > targPos_y + targSize_y)
806 if(myPos_x + mySize_x < targPos_x)
808 if(myPos_x > targPos_x + targSize_x)
811 // OK, there IS a collision.
813 myCenter_x = myPos_x + 0.5 * mySize_x;
814 myCenter_y = myPos_y + 0.5 * mySize_y;
816 targCenter_x = targPos_x + 0.5 * targSize_x;
817 targCenter_y = targPos_y + 0.5 * targSize_y;
820 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // top left (of the target panel)
822 if(myPos_x + mySize_x - targPos_x < myPos_y + mySize_y - targPos_y) // push it to the side
823 myTarget_x = targPos_x - mySize_x;
824 else // push it upwards
825 myTarget_y = targPos_y - mySize_y;
827 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y) // top right
829 if(targPos_x + targSize_x - myPos_x < myPos_y + mySize_y - targPos_y) // push it to the side
830 myTarget_x = targPos_x + targSize_x;
831 else // push it upwards
832 myTarget_y = targPos_y - mySize_y;
834 else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
836 if(myPos_x + mySize_x - targPos_x < targPos_y + targSize_y - myPos_y) // push it to the side
837 myTarget_x = targPos_x - mySize_x;
838 else // push it downwards
839 myTarget_y = targPos_y + targSize_y;
841 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
843 if(targPos_x + targSize_x - myPos_x < targPos_y + targSize_y - myPos_y) // push it to the side
844 myTarget_x = targPos_x + targSize_x;
845 else // push it downwards
846 myTarget_y = targPos_y + targSize_y;
853 void HUD_Panel_SetPos(float id, vector pos, float didntresize)
856 oldPos = HUD_Panel_GetPos(id);
859 else if(didntresize == 1)
861 else if(didntresize == 3)
865 mySize = HUD_Panel_GetSize(id);
867 pos = HUD_Panel_CheckMove(id, pos, mySize);
869 pos_x = bound(0, pos_x, vid_conwidth - mySize_x);
870 pos_y = bound(0, pos_y, vid_conheight - mySize_y);
872 if (pos_x + 0.5 * mySize_x > 0.5 * vid_conwidth)
873 pos_x = pos_x - vid_conwidth;
874 if (pos_y + 0.5 * mySize_y > 0.5 * vid_conheight)
875 pos_y = pos_y - vid_conheight;
878 s = strcat(ftos(pos_x), " ", ftos(pos_y));
880 cvar_set(strcat("hud_", HUD_Panel_GetName(id), "_pos"), s);
884 float prevMouseClicked; // previous state
885 float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
887 prevMouseClicked = mouseClicked;
888 if(nPrimary == K_MOUSE1)
890 if(bInputType == 0) { // key pressed
894 if(bInputType == 1) {// key released
902 vector mousepos, mouseprevpos;
903 vector panel_click_distance; // mouse cursor distance from the top left corner of the panel (saved only upon a click)
904 vector panel_click_pos; // panel pos (saved only upon a click)
905 vector panel_click_size; // panel size (saved only upon a click)
906 float highlightedPanel;
907 float highlightedAction; // 0 = nothing, 1 = move, 2 = resize
908 void HUD_Panel_Mouse()
910 if(mouseClicked == 0) {
911 highlightedPanel = -1;
912 highlightedAction = 0;
915 mousepos = mousepos + getmousepos();
917 mousepos_x = bound(0, mousepos_x, vid_conwidth);
918 mousepos_y = bound(0, mousepos_y, vid_conheight);
920 drawpic(mousepos, "gfx/menu/default/cursor.tga", '32 32 0', '1 1 1', 1, hud_alpha_fg);
928 for(i = 0; i <= panel_cnt; ++i)
930 panelPos = HUD_Panel_GetPos(i);
931 panelSize = HUD_Panel_GetSize(i);
932 border = HUD_Panel_GetBorder(i);
933 if(prevMouseClicked == 0) {
935 if(mousepos_x >= panelPos_x && mousepos_y >= panelPos_y && mousepos_x <= panelPos_x + panelSize_x && mousepos_y <= panelPos_y + panelSize_y)
937 highlightedPanel = i;
938 highlightedAction = 1;
940 // resize from topleft border
941 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)
943 highlightedPanel = i;
944 highlightedAction = 2;
947 // resize from topright border
948 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)
950 highlightedPanel = i;
951 highlightedAction = 2;
954 // resize from bottomleft border
955 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)
957 highlightedPanel = i;
958 highlightedAction = 2;
961 // resize from bottomright border
962 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)
964 highlightedPanel = i;
965 highlightedAction = 2;
970 if(highlightedPanel == i)
972 if(prevMouseClicked == 0)
974 panel_click_distance = mousepos - panelPos;
975 panel_click_pos = panelPos;
976 panel_click_size = panelSize;
979 if(highlightedAction == 1)
980 HUD_Panel_SetPos(i, mousepos - panel_click_distance, 0);
981 else if(highlightedAction == 2)
983 float didntresize; // panel too big/too small, dont resize (also has to affect moving)
984 if(resizeCorner == 1) {
985 didntresize = HUD_Panel_SetSize(i, panelSize + mouseprevpos - mousepos);
986 HUD_Panel_SetPos(i, mousepos - panel_click_distance, didntresize);
988 if(resizeCorner == 2) {
989 didntresize = HUD_Panel_SetSize(i, eY * panel_click_size_y + eX * (mousepos_x - panelPos_x - (panel_click_distance_x - panel_click_size_x))
990 + eY * (panel_click_distance_y + (panel_click_pos_y - mousepos_y)));
991 HUD_Panel_SetPos(i, eX * panelPos_x + eY * (mousepos_y - panel_click_distance_y), didntresize);
993 if(resizeCorner == 3) {
994 didntresize = HUD_Panel_SetSize(i, panelSize + eX * (mouseprevpos_x - mousepos_x) + eY * (mousepos_y - mouseprevpos_y));
995 HUD_Panel_SetPos(i, eX * (mousepos_x - panel_click_distance_x) + eY * panelPos_y, didntresize);
997 if(resizeCorner == 4) {
998 HUD_Panel_SetSize(i, mousepos - panelPos - (panel_click_distance - panel_click_size));
1004 mouseprevpos = mousepos;
1005 prevMouseClicked = mouseClicked;
1008 /*void HUD_DrawDockEdge(float id, vector p1, vector p2, float target)
1014 */ // maybe one day, since this will be quite complicated
1016 // Weapon icons (#0)
1019 float weaponspace[10];
1020 void HUD_WeaponIcons_Clear()
1023 for(idx = 0; idx < 10; ++idx)
1024 weaponspace[idx] = 0;
1027 entity weaponorder[WEP_MAXCOUNT];
1029 void weaponorder_swap(float i, float j, entity pass)
1033 weaponorder[i] = weaponorder[j];
1037 float weaponorder_cmp(float i, float j, entity pass)
1040 d = mod(weaponorder[i].impulse + 9, 10) - mod(weaponorder[j].impulse + 9, 10);
1043 d = weaponorder[i].weapon - weaponorder[j].weapon;
1047 void HUD_WeaponIcons()
1049 float alpha, height, accuracybar_height, stat_weapons; // "constants"
1050 vector pos, mySize, mysize, mypos, accuracy_color;
1051 float i, id, fade, weapon_stats, weapon_hit, weapon_damage, weapon_cnt; // variables
1053 pos = HUD_Panel_GetPos(0);
1054 mySize = HUD_Panel_GetSize(0);
1055 accuracybar_height = cvar_or("hud_weaponicons_accuracybar_height", 3);
1057 stat_weapons = getstati(STAT_WEAPONS);
1058 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1060 self = get_weaponinfo(i);
1061 if(self.weapons && (self.impulse >= 0) && (stat_weapons & self.weapons) || cvar("_hud_configure"))
1063 weaponorder[weapon_cnt] = self;
1067 heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, world);
1069 HUD_Panel_DrawBg(0, pos, mySize);
1072 weapon_stats = getstati(STAT_DAMAGE_HITS);
1073 weapon_number = weapon_stats & 63;
1074 weapon_hits[weapon_number-WEP_FIRST] = floor(weapon_stats / 64);
1076 weapon_stats = getstati(STAT_DAMAGE_FIRED);
1077 weapon_number = weapon_stats & 63;
1078 weapon_fired[weapon_number-WEP_FIRST] = floor(weapon_stats / 64);
1080 if(cvar_or("hud_weaponicons_fade", 1))
1082 fade = 3.2 - 2 * (time - weapontime);
1083 fade = bound(0.7, fade, 1);
1088 HUD_WeaponIcons_Clear();
1090 float rows, columns;
1091 rows = mySize_y/mySize_x;
1092 rows = bound(1, floor((sqrt(4 * (2/1) * rows * WEP_COUNT + rows * rows) + rows + 0.5) / 2), WEP_COUNT);
1093 // ^^^ weapon icon aspect goes here
1095 columns = ceil(WEP_COUNT/rows);
1097 for(i = 0; i < weapon_cnt; ++i)
1099 self = weaponorder[i];
1100 if((self.weapons && (self.impulse >= 0) && (stat_weapons & self.weapons)) || cvar("_hud_configure"))
1104 alpha = (self.weapon == activeweapon) ? 1 : 0.6;
1106 weapon_hit = weapon_hits[self.weapon-WEP_FIRST];
1107 weapon_damage = weapon_fired[self.weapon-WEP_FIRST];
1109 if(self.weapon == activeweapon)
1110 drawpic(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows), "gfx/hud/sb_ammobg", eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows), '1 1 1', fade * hud_alpha_fg, DRAWFLAG_NORMAL);
1111 drawpic(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows), strcat("gfx/hud/inv_weapon", self.netname), eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows), '1 1 1', fade * hud_alpha_fg, DRAWFLAG_NORMAL);
1113 if(cvar_or("hud_weaponicons_number", 1))
1114 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);
1116 // draw the weapon accuracy on the HUD
1117 if(hud_accuracy_hud && !(gametype == GAME_RACE || gametype == GAME_CTS))
1120 weapon_stats = floor(100 * weapon_hit / weapon_damage);
1122 accuracy_color = HUD_AccuracyColor(weapon_stats);
1124 drawpic(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows) - '2 0 0' + eY * (mySize_y/rows - accuracybar_height), "gfx/hud/sb_accuracy_bar.tga", eX * mySize_x*(1/columns) + eY * accuracybar_height, accuracy_color, hud_alpha_fg, DRAWFLAG_NORMAL);
1141 float GetAmmoStat(float i)
1145 case 0: return STAT_SHELLS;
1146 case 1: return STAT_NAILS;
1147 case 2: return STAT_ROCKETS;
1148 case 3: return STAT_CELLS;
1149 case 4: return STAT_FUEL;
1154 float GetAmmoItemCode(float i)
1158 case 0: return IT_SHELLS;
1159 case 1: return IT_NAILS;
1160 case 2: return IT_ROCKETS;
1161 case 3: return IT_CELLS;
1162 case 4: return IT_FUEL;
1167 string GetAmmoPicture(float i)
1171 case 0: return "gfx/hud/sb_shells";
1172 case 1: return "gfx/hud/sb_bullets";
1173 case 2: return "gfx/hud/sb_rocket";
1174 case 3: return "gfx/hud/sb_cells";
1175 case 4: return "gfx/hud/sb_fuel";
1180 void HUD_Inventory()
1185 vector pos, mySize, mysize, mypos;
1186 pos = HUD_Panel_GetPos(1);
1187 mySize = HUD_Panel_GetSize(1);
1189 HUD_Panel_DrawBg(1, pos, mySize);
1192 stat_items = getstati(STAT_ITEMS);
1193 for (i = 0; i < 4; ++i) {
1195 a = getstati(GetAmmoStat(i)); // how much ammo do we have of type i?
1196 if(cvar("_hud_configure"))
1199 if(cvar("hud_inventory_onlycurrent")) {
1200 if (stat_items & GetAmmoItemCode(i)) {
1201 drawpic(pos, "gfx/hud/sb_ammobg", mySize, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1202 drawpic(pos + eY * 0.05 * mySize_y, GetAmmoPicture(i), '1 1 0' * 0.8 * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1204 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);
1206 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);
1210 if(mySize_x/mySize_y >= 10) { // arrange horizontally
1212 case 0: mypos_x = pos_x; mypos_y = pos_y; break; // shells
1213 case 1: mypos_x = pos_x + 0.25 * mySize_x; mypos_y = pos_y; break; // bullets
1214 case 2: mypos_x = pos_x + 0.5 * mySize_x; mypos_y = pos_y; break; // rockets
1215 case 3: mypos_x = pos_x + 0.75 * mySize_x; mypos_y = pos_y; break; // cells
1217 mysize_x = 0.25 * mySize_x;
1218 mysize_y = mySize_y;
1219 } else if(mySize_x/mySize_y >= 2.5) { // arrange in a 2x2 grid
1221 case 0: mypos_x = pos_x + 0.5 * mySize_x; mypos_y = pos_y + 0.5 * mySize_y; break; // shells
1222 case 1: mypos_x = pos_x + 0.5 * mySize_x; mypos_y = pos_y; break; // bullets
1223 case 2: mypos_x = pos_x; mypos_y = pos_y + 0.5 * mySize_y; break; // rockets
1224 case 3: mypos_x = pos_x; mypos_y = pos_y; break; // cells
1226 mysize_x = 0.5 * mySize_x;
1227 mysize_y = 0.5 * mySize_y;
1228 } else { // arrange vertically
1230 case 0: mypos_x = pos_x; mypos_y = pos_y; break; // shells
1231 case 1: mypos_x = pos_x; mypos_y = pos_y + 0.25 * mySize_y; break; // bullets
1232 case 2: mypos_x = pos_x; mypos_y = pos_y + 0.5 * mySize_y; break; // rockets
1233 case 3: mypos_x = pos_x; mypos_y = pos_y + 0.75 * mySize_y; break; // cells
1235 mysize_x = mySize_x;
1236 mysize_y = 0.25 * mySize_y;
1239 if (stat_items & GetAmmoItemCode(i))
1240 drawpic(mypos, "gfx/hud/sb_ammobg", mysize, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1241 drawpic(mypos + eY * 0.05 * mysize_y, GetAmmoPicture(i), '1 1 0' * 0.8 * mysize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1243 if(stat_items & GetAmmoItemCode(i))
1244 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);
1246 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);
1248 if(stat_items & GetAmmoItemCode(i))
1249 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);
1251 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);
1260 float shield_maxtime;
1261 float strength_maxtime;
1262 void HUD_Powerups() {
1264 stat_items = getstati(STAT_ITEMS);
1266 if(!cvar("_hud_configure"))
1268 if not(stat_items & IT_STRENGTH)
1269 if not(stat_items & IT_INVINCIBLE)
1272 if (getstati(STAT_HEALTH) <= 0)
1277 pos = HUD_Panel_GetPos(2);
1278 mySize = HUD_Panel_GetSize(2);
1280 HUD_Panel_DrawBg(2, pos, mySize);
1282 float strength_time, shield_time;
1284 strength_time = bound(0, ceil(getstatf(STAT_STRENGTH_FINISHED) - time), 999);
1285 shield_time = bound(0, ceil(getstatf(STAT_INVINCIBLE_FINISHED) - time), 999);
1287 if(cvar("_hud_configure"))
1293 string leftname, rightname;
1294 float leftcnt, rightcnt;
1295 float leftalpha, rightalpha;
1296 if (cvar(strcat("hud_", HUD_Panel_GetName(2), "_flip"))) {
1297 leftname = "strength";
1298 leftcnt = strength_time;
1300 rightname = "shield";
1301 rightcnt = shield_time;
1303 leftname = "shield";
1304 leftcnt = shield_time;
1306 rightname = "strength";
1307 rightcnt = strength_time;
1309 leftalpha = bound(0, leftcnt, 1);
1310 rightalpha = bound(0, rightcnt, 1);
1313 if (mySize_x/mySize_y > 5)
1317 len = strlen(ftos(leftcnt));
1319 drawpic(pos, "gfx/hud/statusbar", eX * 0.5 * mySize_x * min(1, leftcnt/30) + eY * mySize_y, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1320 drawpic(pos, strcat("gfx/hud/sb_", leftname), '1 1 0' * mySize_y, '1 1 1', leftalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1321 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);
1326 drawpic(pos + eX * mySize_x - eX * 0.5 * mySize_x * min(1, rightcnt/30), "gfx/hud/statusbar", eX * 0.5 * mySize_x * min(1, rightcnt/30) + eY * mySize_y, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1327 drawpic(pos + eX * mySize_x - eX * mySize_y, strcat("gfx/hud/sb_", rightname), '1 1 0' * mySize_y, '1 1 1', rightalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1328 HUD_DrawXNum(pos + eX * mySize_x - eX * 2.5 * mySize_y + eY * 0.25 * mySize_y, rightcnt, 3, 0, 0.5 * mySize_y, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1331 else if (mySize_x/mySize_y > 3.2)
1335 len = strlen(ftos(leftcnt));
1337 drawpic(pos + eY * mySize_y - eY * mySize_y * min(1, leftcnt/30), "gfx/hud/statusbar", eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/30), HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1338 drawpic(pos + eX * 0.4 * mySize_y, strcat("gfx/hud/sb_", leftname), '0.7 0.7 0' * mySize_y, '1 1 1', leftalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1339 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);
1344 len = strlen(ftos(rightcnt));
1346 drawpic(pos + eX * 0.5 * mySize_x + eY * mySize_y - eY * mySize_y * min(1, rightcnt/30), "gfx/hud/statusbar", eX * 0.5 * mySize_x + eY * mySize_y * min(1, rightcnt/30), HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1347 drawpic(pos + eX * mySize_x - eX * 1.1 * mySize_y, strcat("gfx/hud/sb_", rightname), '0.7 0.7 0' * mySize_y, '1 1 1', rightalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1348 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);
1355 len = strlen(ftos(leftcnt));
1357 drawpic(pos, "gfx/hud/statusbar", eX * mySize_x * min(1, leftcnt/30) + eY * 0.5 * mySize_y, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1358 drawpic(pos, strcat("gfx/hud/sb_", leftname), '0.5 0.5 0' * mySize_y, '1 1 1', leftalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1359 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);
1364 len = strlen(ftos(rightcnt));
1366 drawpic(pos + eY * 0.5 * mySize_y, "gfx/hud/statusbar", eX * mySize_x * min(1, rightcnt/30) + eY * 0.5 * mySize_y, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1367 drawpic(pos + eY * 0.5 * mySize_y, strcat("gfx/hud/sb_", rightname), '0.5 0.5 0' * mySize_y, '1 1 1', rightalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1368 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);
1372 /* TODO: add expand!
1374 if (strength_time) {
1375 dt = strength_time - time;
1380 drawpic_expanding_two(pos, "gfx/hud/sb_str", '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE,
1381 bound(0, (ceil(dt) - dt) / 0.5, 1));
1385 drawpic(pos, "gfx/hud/sb_str", '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE);
1387 HUD_DrawXNum(pos - '40 -2 0', ceil(dt), 2, 0, countdown_fontsize, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1391 drawpic_expanding(pos, "gfx/hud/sb_str", '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE,
1392 bound(0, -dt / 0.5, 1));
1397 if (invincibility_time) {
1398 dt = invincibility_time - time;
1403 drawpic_expanding_two(pos - '0 -22 0', "gfx/hud/sb_invinc", '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE,
1404 bound(0, (ceil(dt) - dt) / 0.5, 1));
1408 drawpic(pos - '0 -22 0', "gfx/hud/sb_invinc", '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE);
1410 HUD_DrawXNum(pos - '40 -24 0', ceil(dt), 2, 0, countdown_fontsize, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1414 drawpic_expanding(pos - '0 -22 0', "gfx/hud/sb_invinc", '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE,
1415 bound(0, -dt / 0.5, 1));
1421 // Health/armor (#3)
1423 void HUD_HealthArmor(void)
1426 pos = HUD_Panel_GetPos(3);
1427 mySize = HUD_Panel_GetSize(3);
1429 HUD_Panel_DrawBg(3, pos, mySize);
1431 float armor, health, x;
1432 armor = getstati(STAT_ARMOR);
1433 health = getstati(STAT_HEALTH);
1434 if(cvar("_hud_configure"))
1446 if(hud_hudselector == 2) // combined health and armor display
1449 v = healtharmor_maxdamage(health, armor, armorblockpercent);
1452 num_pos = - '96 28 0';
1456 if(v_z) // fully armored
1458 // here, armorideal > armor
1459 drawpic(num_pos + '78 -4.5 0', "gfx/hud/sb_health", '32 32 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1460 drawpic(num_pos + '108 -4.5 0', "gfx/hud/sb_armor", '20 20 0', '1 1 1', hud_alpha_fg * armor / v_y, DRAWFLAG_NORMAL);
1464 drawpic(num_pos + '108 -4.5 0', "gfx/hud/sb_health", '20 20 0', '1 1 1', hud_alpha_fg * v_y / armor, DRAWFLAG_NORMAL);
1465 drawpic(num_pos + '78 -4.5 0', "gfx/hud/sb_armor", '32 32 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1467 HUD_DrawXNum_Colored(num_pos, x, 3, 24, hud_alpha_fg); // draw the combined health and armor
1472 string leftname, rightname;
1473 float leftcnt, rightcnt;
1474 float leftactive, rightactive;
1475 float leftalpha, rightalpha;
1477 if (cvar(strcat("hud_", HUD_Panel_GetName(3), "_flip"))) { // old style layout with armor left/top of health
1482 leftalpha = min((armor+10)/55, 1);
1484 rightname = "health";
1489 leftname = "health";
1494 rightname = "armor";
1498 rightalpha = min((armor+10)/55, 1);
1502 fuel = getstati(GetAmmoStat(4)); // how much fuel do we have?
1504 if (mySize_x/mySize_y > 5)
1508 len = strlen(ftos(leftcnt));
1510 drawpic(pos, "gfx/hud/statusbar", eX * 0.5 * mySize_x * min(1, leftcnt/200) + eY * mySize_y, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1511 drawpic(pos, strcat("gfx/hud/sb_", leftname), '1 1 0' * mySize_y, '1 1 1', leftalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1512 HUD_DrawXNum_Colored(pos + eX * mySize_y + eY * 0.25 * mySize_y, leftcnt, len, 0.5 * mySize_y, hud_alpha_fg);
1517 drawpic(pos + eX * mySize_x - eX * 0.5 * mySize_x * min(1, rightcnt/200), "gfx/hud/statusbar", eX * 0.5 * mySize_x * min(1, rightcnt/200) + eY * mySize_y, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1518 drawpic(pos + eX * mySize_x - eX * mySize_y, strcat("gfx/hud/sb_", rightname), '1 1 0' * mySize_y, '1 1 1', rightalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1519 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);
1523 drawpic(pos, "gfx/hud/statusbar", eX * mySize_x * min(1, fuel/100) + eY * 0.2 * mySize_y, HUD_Panel_GetProgressBarColor("fuel"), hud_alpha_fg * 0.8, DRAWFLAG_NORMAL);
1525 else if (mySize_x/mySize_y > 3.2)
1529 len = strlen(ftos(leftcnt));
1531 drawpic(pos + eY * mySize_y - eY * mySize_y * min(1, leftcnt/200), "gfx/hud/statusbar", eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/200), HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1532 drawpic(pos + eX * 0.4 * mySize_y, strcat("gfx/hud/sb_", leftname), '0.7 0.7 0' * mySize_y, '1 1 1', leftalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1533 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);
1538 len = strlen(ftos(rightcnt));
1540 drawpic(pos + eX * 0.5 * mySize_x + eY * mySize_y - eY * mySize_y * min(1, rightcnt/200), "gfx/hud/statusbar", eX * 0.5 * mySize_x + eY * mySize_y * min(1, rightcnt/200), HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1541 drawpic(pos + eX * mySize_x - eX * 1.1 * mySize_y, strcat("gfx/hud/sb_", rightname), '0.7 0.7 0' * mySize_y, '1 1 1', rightalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1542 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);
1546 drawpic(pos, "gfx/hud/statusbar", eX * mySize_x * min(1, fuel/100) + eY * 0.15 * mySize_y, HUD_Panel_GetProgressBarColor("fuel"), hud_alpha_fg * 0.8, DRAWFLAG_NORMAL);
1552 len = strlen(ftos(leftcnt));
1554 drawpic(pos, "gfx/hud/statusbar", eX * mySize_x * min(1, leftcnt/200) + eY * 0.5 * mySize_y, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1555 drawpic(pos, strcat("gfx/hud/sb_", leftname), '0.5 0.5 0' * mySize_y, '1 1 1', leftalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1556 HUD_DrawXNum_Colored(pos + eX * 0.5 * mySize_y, leftcnt, len, 0.5 * mySize_y, hud_alpha_fg);
1561 len = strlen(ftos(rightcnt));
1563 drawpic(pos + eY * 0.5 * mySize_y, "gfx/hud/statusbar", eX * mySize_x * min(1, rightcnt/200) + eY * 0.5 * mySize_y, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1564 drawpic(pos + eY * 0.5 * mySize_y, strcat("gfx/hud/sb_", rightname), '0.5 0.5 0' * mySize_y, '1 1 1', rightalpha * hud_alpha_fg, DRAWFLAG_NORMAL);
1565 HUD_DrawXNum_Colored(pos + eX * 0.5 * mySize_y + eY * 0.5 * mySize_y, rightcnt, len, 0.5 * mySize_y, hud_alpha_fg);
1569 drawpic(pos, "gfx/hud/statusbar", eX * mySize_x * min(1, fuel/100) + eY * 0.1 * mySize_y, HUD_Panel_GetProgressBarColor("fuel"), hud_alpha_fg * 0.8, DRAWFLAG_NORMAL);
1579 pos = HUD_Panel_GetPos(7);
1580 mySize = HUD_Panel_GetSize(7);
1582 HUD_Panel_DrawBg(7, pos, mySize);
1584 float score, distribution, leader;
1585 float score_len, distr_len;
1586 vector score_pos, secondary_score_pos, distribution_color;
1588 me = (spectatee_status > 0) ? playerslots[spectatee_status - 1] : playerslots[player_localentnum - 1];
1590 if (!teamplay) { // non-teamgames
1591 // me vector := [team/connected frags id]
1592 pl = players.sort_next;
1596 if(cvar("_hud_configure"))
1599 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
1603 score = me.(scores[ps_primary]);
1604 if(cvar("_hud_configure"))
1607 if(distribution >= 5) {
1608 distribution_color = eY;
1610 } else if(distribution >= 0) {
1611 distribution_color = '1 1 1';
1613 } else if(distribution >= -5)
1614 distribution_color = '1 1 0';
1616 distribution_color = eX;
1618 score_len = strlen(ftos(score));
1619 distr_len = strlen(ftos(distribution));
1621 HUD_DrawXNum(pos + eX * mySize_x - eX * 4 * 0.33 * mySize_y, distribution, 4, 3, 0.33 * mySize_y, distribution_color, 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1623 drawpic(pos + eX * mySize_x - eX * score_len * mySize_y - eX * 4 * 0.33 * mySize_y, strcat("gfx/hud/sb_highlight_", ftos(score_len)), eX * score_len * mySize_y + eY * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1624 HUD_DrawXNum(pos + eX * mySize_x - eX * 4 * mySize_y - eX * 4 * 0.33 * mySize_y, score, 4, 0, mySize_y, distribution_color, 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1625 } else { // teamgames
1626 float max_fragcount;
1627 max_fragcount = -999;
1630 for(tm = teams.sort_next; tm; tm = tm.sort_next) {
1631 if(tm.team == COLOR_SPECTATOR || (!tm.team_size && !cvar("_hud_configure"))) // no players? don't display
1633 score = tm.(teamscores[ts_primary]);
1634 if(cvar("_hud_configure"))
1638 score_len = strlen(ftos(score));
1640 if (score > max_fragcount)
1641 max_fragcount = score;
1643 if(tm.team == myteam) {
1644 if (max_fragcount == score)
1647 drawpic(pos + eX * mySize_x - eX * score_len * mySize_y - eX * 4 * 0.33 * mySize_y, strcat("gfx/hud/sb_highlight_", ftos(score_len)), eX * score_len * mySize_y + eY * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1648 HUD_DrawXNum(pos + eX * mySize_x - eX * 4 * mySize_y - eX * 4 * 0.33 * mySize_y, score, 4, 0, mySize_y, GetTeamRGB(tm.team) * 0.8, 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1650 if (max_fragcount == score)
1653 drawpic(pos + eX * mySize_x - eX * 0.33 * score_len * mySize_y + eY * 0.33 * mySize_y * teamnum, strcat("gfx/hud/sb_highlight_", ftos(score_len)), eX * 0.33 * score_len * mySize_y + eY * 0.33 * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1654 HUD_DrawXNum(pos + eX * mySize_x - eX * 4 * 0.33 * mySize_y + eY * 0.33 * mySize_y * teamnum, score, 4, 0, 0.33 * mySize_y, GetTeamRGB(tm.team) * 0.8, 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1663 void HUD_RaceTimer (void) {
1665 pos = HUD_Panel_GetPos(8);
1666 mySize = HUD_Panel_GetSize(8);
1668 HUD_Panel_DrawBg(8, pos, mySize);
1670 drawfont = hud_bigfont;
1672 string s, forcetime;
1674 if(cvar("_hud_configure"))
1677 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);
1678 s = "^1Intermediate 1 (+15.42)";
1679 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);
1681 else if(race_checkpointtime)
1683 a = bound(0, 2 - (time - race_checkpointtime), 1);
1686 if(a > 0) // just hit a checkpoint?
1688 if(race_checkpoint != 254)
1690 if(race_time && race_previousbesttime)
1691 s = MakeRaceString(race_checkpoint, TIME_DECODE(race_time) - TIME_DECODE(race_previousbesttime), 0, 0, race_previousbestname);
1693 s = MakeRaceString(race_checkpoint, 0, -1, 0, race_previousbestname);
1695 forcetime = TIME_ENCODED_TOSTRING(race_time);
1700 if(race_laptime && race_nextbesttime && race_nextcheckpoint != 254)
1702 a = bound(0, 2 - ((race_laptime + TIME_DECODE(race_nextbesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1);
1703 if(a > 0) // next one?
1705 s = MakeRaceString(race_nextcheckpoint, (time + TIME_DECODE(race_penaltyaccumulator)) - race_laptime, TIME_DECODE(race_nextbesttime), 0, race_nextbestname);
1710 if(s != "" && a > 0)
1712 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
1713 //drawcolorcodedstring(m - '0 16 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
1714 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);
1717 if(race_penaltytime)
1719 a = bound(0, 2 - (time - race_penaltyeventtime), 1);
1722 s = strcat("^1PENALTY: ", ftos_decimals(race_penaltytime * 0.1, 1), " (", race_penaltyreason, ")");
1723 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
1724 //drawcolorcodedstring(m - '0 32 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
1725 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);
1731 a = bound(0, (time - race_checkpointtime) / 0.5, 1);
1732 //drawstring_expanding(m - '16 0 0' * stringwidth(forcetime, FALSE), forcetime, '32 32 0', '1 1 1', hud_alpha_fg, 0, a);
1733 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);
1738 if(race_laptime && race_checkpoint != 255)
1740 s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime));
1741 //drawstring(m - '16 0 0' * stringwidth(s, FALSE), s, '32 32 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
1742 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);
1747 if(race_mycheckpointtime)
1749 a = bound(0, 2 - (time - race_mycheckpointtime), 1);
1750 s = MakeRaceString(race_mycheckpoint, TIME_DECODE(race_mycheckpointdelta), -!race_mycheckpointenemy, race_mycheckpointlapsdelta, race_mycheckpointenemy);
1751 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
1752 //drawcolorcodedstring(m - '0 16 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
1753 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);
1755 if(race_othercheckpointtime && race_othercheckpointenemy != "")
1757 a = bound(0, 2 - (time - race_othercheckpointtime), 1);
1758 s = MakeRaceString(race_othercheckpoint, -TIME_DECODE(race_othercheckpointdelta), -!race_othercheckpointenemy, race_othercheckpointlapsdelta, race_othercheckpointenemy);
1759 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
1760 //drawcolorcodedstring(m - '0 0 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
1761 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);
1764 if(race_penaltytime && !race_penaltyaccumulator)
1766 t = race_penaltytime * 0.1 + race_penaltyeventtime;
1767 a = bound(0, (1 + t - time), 1);
1771 s = strcat("^1PENALTY: ", ftos_decimals(t - time, 1), " (", race_penaltyreason, ")");
1773 s = strcat("^2PENALTY: 0.0 (", race_penaltyreason, ")");
1774 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
1775 //drawcolorcodedstring(m - '0 32 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
1776 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);
1781 drawfont = hud_font;
1784 // Notification area (#4)
1785 void HUD_Notify (void)
1788 pos = HUD_Panel_GetPos(4);
1789 mySize = HUD_Panel_GetSize(4);
1791 HUD_Panel_DrawBg(4, pos, mySize);
1795 if(spectatee_status && !intermission)
1797 drawfont = hud_bigfont;
1798 if(spectatee_status == -1)
1801 s = GetPlayerName(spectatee_status - 1);
1802 // spectated player name between HUD and chat area, aligned to the left
1804 pos_y = - 50 - hud_fontsize_spec_y;
1805 s = textShortenToWidth(s, vid_conwidth/2.5, hud_fontsize_spec, stringwidth_colors);
1806 drawcolorcodedstring(pos, s, hud_fontsize_spec, hud_alpha_fg, DRAWFLAG_NORMAL);
1807 drawfont = hud_font;
1809 // spectator text in the upper right corner
1810 if(spectatee_status == -1)
1811 s = strcat("^1Press ^3", getcommandkey("primary fire", "+attack"), "^1 to spectate");
1813 s = strcat("^1Press ^3", getcommandkey("primary fire", "+attack"), "^1 for another player");
1815 if(spectatee_status == -1)
1816 s = strcat("^1Use ^3", getcommandkey("next weapon", "weapnext"), "^1 or ^3", getcommandkey("previous weapon", "weapprev"), "^1 to change the speed");
1818 s = strcat("^1Press ^3", getcommandkey("secondary fire", "+attack2"), "^1 to observe");
1820 s = strcat("^1Press ^3", getcommandkey("server info", "+show_info"), "^1 for gamemode info");
1822 if(gametype == GAME_ARENA)
1823 s = "^1Wait for your turn to join";
1824 else if(gametype == GAME_LMS)
1827 sk = playerslots[player_localentnum - 1];
1828 if(sk.(scores[ps_primary]) >= 666)
1829 s = "^1Match has already begun";
1830 else if(sk.(scores[ps_primary]) > 0)
1831 s = "^1You have no more lives left";
1833 s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
1836 s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
1838 //show restart countdown:
1839 if (time < getstatf(STAT_GAMESTARTTIME)) {
1841 //we need to ceil, otherwise the countdown would be off by .5 when using round()
1842 countdown = ceil(getstatf(STAT_GAMESTARTTIME) - time);
1843 s = strcat("^1Game starts in ^3", ftos(countdown), "^1 seconds");
1846 if(warmup_stage && !intermission)
1848 s = "^2Currently in ^1warmup^2 stage!";
1851 // move more important stuff more to the middle so its more visible
1854 if(mod(time, 1) >= 0.5)
1859 if(ready_waiting && !intermission && !spectatee_status)
1861 if(ready_waiting_for_me)
1864 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " to end warmup");
1866 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " once you are ready");
1871 s = strcat("^2Waiting for others to ready up to end warmup...");
1873 s = strcat("^2Waiting for others to ready up...");
1876 else if(warmup_stage && !intermission && !spectatee_status)
1878 s = strcat("^2Press ^3", getcommandkey("ready", "ready"), "^2 to end warmup");
1881 if(teamplay && !intermission && !spectatee_status && gametype != GAME_CA && teamnagger)
1883 float ts_min, ts_max;
1884 tm = teams.sort_next;
1887 for(; tm.sort_next; tm = tm.sort_next)
1889 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
1891 if(!ts_min) ts_min = tm.team_size;
1892 else ts_min = min(ts_min, tm.team_size);
1893 if(!ts_max) ts_max = tm.team_size;
1894 else ts_max = max(ts_max, tm.team_size);
1896 if ((ts_max - ts_min) > 1)
1898 s = strcat(blinkcolor, "Teamnumbers are unbalanced!");
1899 tm = GetTeam(myteam, false);
1901 if (tm.team != COLOR_SPECTATOR)
1902 if (tm.team_size == ts_max)
1903 s = strcat(s, " Press ^3", getcommandkey("team menu", "menu_showteamselect"), blinkcolor, " to adjust");
1911 float vote_yescount;
1914 float vote_highlighted; // currently selected vote
1916 float vote_active; // is there an active vote?
1917 float vote_prev; // previous state of vote_active to check for a change
1919 float vote_change; // "time" when vote_active changed
1921 void HUD_VoteWindow(void)
1924 pos = HUD_Panel_GetPos(9);
1925 mySize = HUD_Panel_GetSize(9);
1929 if(vote_active != vote_prev) {
1931 vote_prev = bound(0, vote_active, 1);
1935 vote_alpha = bound(0, (time - vote_change) * 2, 1);
1937 vote_alpha = bound(0, 1 - (time - vote_change) * 2, 1);
1939 if(cvar("_hud_configure"))
1947 HUD_Panel_DrawBg(9, pos, mySize);
1950 a = vote_alpha * bound(cvar_or("hud_vote_alreadyvoted_alpha", 0.75), 1 - vote_highlighted, 1);
1952 drawpic(pos, "gfx/hud/voteprogress_back", mySize, HUD_GetBgColor(), a * hud_alpha_bg, DRAWFLAG_NORMAL);
1954 s = "A vote has been called for: ";
1955 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);
1956 s = textShortenToWidth(vote_called_vote, mySize_x * 0.96, '10 0 0', stringwidth_colors);
1957 if(cvar("_hud_configure"))
1958 s = "Configure the HUD";
1959 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);
1961 // print the yes/no counts
1962 s = strcat("Yes: ", ftos(vote_yescount));
1963 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);
1964 s = strcat("No: ", ftos(vote_nocount));
1965 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);
1967 // draw the progress bars
1968 drawsetcliparea(pos_x, pos_y, mySize_x * 0.5 * (vote_yescount/vote_needed), mySize_y);
1969 drawpic(pos, "gfx/hud/voteprogress_prog", mySize, eY, a * hud_alpha_fg, DRAWFLAG_NORMAL);
1971 drawsetcliparea(pos_x + mySize_x - mySize_x * 0.5 * (vote_nocount/vote_needed), pos_y, mySize_x * 0.5, mySize_y);
1972 drawpic(pos, "gfx/hud/voteprogress_prog", mySize, eX, a * hud_alpha_fg, DRAWFLAG_NORMAL);
1974 // draw the highlights
1975 if(vote_highlighted == 1) {
1976 drawsetcliparea(pos_x, pos_y, mySize_x * 0.5, mySize_y);
1977 drawpic(pos, "gfx/hud/voteprogress_voted", mySize, eY, a * hud_alpha_fg, DRAWFLAG_NORMAL);
1979 else if(vote_highlighted == 2) {
1980 drawsetcliparea(pos_x + 0.5 * mySize_x, pos_y, mySize_x * 0.5, mySize_y);
1981 drawpic(pos, "gfx/hud/voteprogress_voted", mySize, eX, a * hud_alpha_fg, DRAWFLAG_NORMAL);
1984 drawresetcliparea();
1986 else if(!vote_active) {
1987 vote_highlighted = 0;
1992 float race_status_time;
1993 float race_status_prev;
1994 string race_status_name_prev;
1995 void HUD_DrawRaceStatus(vector pos)
1997 if (race_status != race_status_prev || race_status_name != race_status_name_prev) {
1998 race_status_time = time + 5;
1999 race_status_prev = race_status;
2000 if (race_status_name_prev)
2001 strunzone(race_status_name_prev);
2002 race_status_name_prev = strzone(race_status_name);
2006 a = bound(0, race_status_time - time, 1);
2009 s = textShortenToWidth(race_status_name, 120, '10 10 0', stringwidth_colors);
2013 rank = race_CheckName(race_status_name);
2015 rankname = race_PlaceName(rank);
2017 if(race_status == 0)
2018 drawpic(pos, "gfx/hud/race/newfail", '80 80 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2019 else if(race_status == 1) {
2020 drawpic(pos, "gfx/hud/race/newtime", '80 80 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2021 drawcolorcodedstring(pos + '40 80 0' - eX * stringwidth(s, TRUE, '5 0 0'), s, '10 10 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2022 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);
2023 } else if(race_status == 2) {
2024 if(race_status_name == GetPlayerName(player_localentnum -1) || !race_myrank || race_myrank < rank)
2025 drawpic(pos, "gfx/hud/race/newrankgreen", '80 80 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2027 drawpic(pos, "gfx/hud/race/newrankyellow", '80 80 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2028 drawcolorcodedstring(pos + '40 80 0' - eX * stringwidth(s, TRUE, '5 0 0'), s, '10 10 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2029 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);
2030 } else if(race_status == 3) {
2031 drawpic(pos, "gfx/hud/race/newrecordserver", '80 80 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2032 drawcolorcodedstring(pos + '40 80 0' - eX * stringwidth(s, TRUE, '5 0 0'), s, '10 10 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
2033 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);
2036 if (race_status_time - time <= 0) {
2037 race_status_prev = -1;
2039 if(race_status_name)
2040 strunzone(race_status_name);
2041 race_status_name = string_null;
2042 if(race_status_name_prev)
2043 strunzone(race_status_name_prev);
2044 race_status_name_prev = string_null;
2048 // CTF HUD modicon section
2049 float redflag_prevframe, blueflag_prevframe; // status during previous frame
2050 float redflag_prevstatus, blueflag_prevstatus; // last remembered status
2051 float redflag_statuschange_time, blueflag_statuschange_time; // time when the status changed
2053 void CSQC_ctf_hudreset(void)
2055 redflag_prevstatus = blueflag_prevstatus = redflag_prevframe = blueflag_prevframe = redflag_statuschange_time = blueflag_statuschange_time = 0;
2058 void CSQC_ctf_hud(void)
2060 vector bottomleft, redflag_pos, blueflag_pos, sz;
2061 float f; // every function should have that
2062 bottomleft_y = vid_conheight;
2065 float redflag, blueflag; // current status
2066 float redflag_statuschange_elapsedtime, blueflag_statuschange_elapsedtime; // time since the status changed
2069 stat_items = getstati(STAT_ITEMS);
2070 redflag = (stat_items/IT_RED_FLAG_TAKEN) & 3;
2071 blueflag = (stat_items/IT_BLUE_FLAG_TAKEN) & 3;
2073 // when status CHANGES, set old status into prevstatus and current status into status
2074 if (redflag != redflag_prevframe)
2076 redflag_statuschange_time = time;
2077 redflag_prevstatus = redflag_prevframe;
2078 redflag_prevframe = redflag;
2081 if (blueflag != blueflag_prevframe)
2083 blueflag_statuschange_time = time;
2084 blueflag_prevstatus = blueflag_prevframe;
2085 blueflag_prevframe = blueflag;
2088 redflag_statuschange_elapsedtime = time - redflag_statuschange_time;
2089 blueflag_statuschange_elapsedtime = time - blueflag_statuschange_time;
2091 float BLINK_FACTOR = 0.15;
2092 float BLINK_BASE = 0.85;
2094 // RMS = sqrt(BLINK_BASE^2 + 0.5 * BLINK_FACTOR^2)
2096 // BLINK_BASE = sqrt(RMS^2 - 0.5 * BLINK_FACTOR^2)
2098 float BLINK_FREQ = 5; // circle frequency, = 2*pi*frequency in hertz
2100 string red_icon, red_icon_prevstatus;
2101 float red_alpha, red_alpha_prevstatus;
2102 red_alpha = red_alpha_prevstatus = 1;
2104 case 1: red_icon = "gfx/hud/sb_flag_red_taken"; break;
2105 case 2: red_icon = "gfx/hud/sb_flag_red_lost"; break;
2106 case 3: red_icon = "gfx/hud/sb_flag_red_carrying"; red_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
2108 if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM2))
2109 red_icon = "gfx/hud/sb_flag_red_shielded";
2111 red_icon = string_null;
2114 switch(redflag_prevstatus) {
2115 case 1: red_icon_prevstatus = "gfx/hud/sb_flag_red_taken"; break;
2116 case 2: red_icon_prevstatus = "gfx/hud/sb_flag_red_lost"; break;
2117 case 3: red_icon_prevstatus = "gfx/hud/sb_flag_red_carrying"; red_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
2120 red_icon_prevstatus = "gfx/hud/sb_flag_red_carrying"; // make it more visible
2121 else if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM2))
2122 red_icon_prevstatus = "gfx/hud/sb_flag_red_shielded";
2124 red_icon_prevstatus = string_null;
2128 string blue_icon, blue_icon_prevstatus;
2129 float blue_alpha, blue_alpha_prevstatus;
2130 blue_alpha = blue_alpha_prevstatus = 1;
2132 case 1: blue_icon = "gfx/hud/sb_flag_blue_taken"; break;
2133 case 2: blue_icon = "gfx/hud/sb_flag_blue_lost"; break;
2134 case 3: blue_icon = "gfx/hud/sb_flag_blue_carrying"; blue_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
2136 if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM1))
2137 blue_icon = "gfx/hud/sb_flag_blue_shielded";
2139 blue_icon = string_null;
2142 switch(blueflag_prevstatus) {
2143 case 1: blue_icon_prevstatus = "gfx/hud/sb_flag_blue_taken"; break;
2144 case 2: blue_icon_prevstatus = "gfx/hud/sb_flag_blue_lost"; break;
2145 case 3: blue_icon_prevstatus = "gfx/hud/sb_flag_blue_carrying"; blue_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
2148 blue_icon_prevstatus = "gfx/hud/sb_flag_blue_carrying"; // make it more visible
2149 else if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM1))
2150 blue_icon_prevstatus = "gfx/hud/sb_flag_blue_shielded";
2152 blue_icon_prevstatus = string_null;
2156 if (myteam == COLOR_TEAM1) { // always draw own flag on left
2157 redflag_pos = bottomleft - '-4 50 0';
2158 blueflag_pos = bottomleft - '-62 50 0';
2160 blueflag_pos = bottomleft - '-4 50 0';
2161 redflag_pos = bottomleft - '-62 50 0';
2166 f = bound(0, redflag_statuschange_elapsedtime*2, 1);
2167 if(red_icon_prevstatus && f < 1)
2168 drawpic_expanding(redflag_pos, red_icon_prevstatus, sz, '1 1 1', hud_alpha_fg * red_alpha_prevstatus, DRAWFLAG_NORMAL, f);
2170 drawpic(redflag_pos, red_icon, sz, '1 1 1', hud_alpha_fg * red_alpha * f, DRAWFLAG_NORMAL);
2172 f = bound(0, blueflag_statuschange_elapsedtime*2, 1);
2173 if(blue_icon_prevstatus && f < 1)
2174 drawpic_expanding(blueflag_pos, blue_icon_prevstatus, sz, '1 1 1', hud_alpha_fg * blue_alpha_prevstatus, DRAWFLAG_NORMAL, f);
2176 drawpic(blueflag_pos, blue_icon, sz, '1 1 1', hud_alpha_fg * blue_alpha * f, DRAWFLAG_NORMAL);
2179 /*void HUD_Mod_Race (void) {
2180 if((scores_flags[ps_primary] & SFL_TIME) && !teamplay) { // race/cts record display on HUD
2181 pl = players.sort_next;
2184 if(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)
2185 if(pl.scores[ps_primary] == 0)
2188 score = me.(scores[ps_primary]);
2190 float racemin, racesec, racemsec;
2191 float distsec, distmsec, minusplus;
2193 racemin = floor(score/(60 * TIME_FACTOR));
2194 racesec = floor((score - racemin*(60 * TIME_FACTOR))/TIME_FACTOR);
2195 racemsec = score - racemin*60*TIME_FACTOR - racesec*TIME_FACTOR;
2197 if (pl && ((!(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)) || score)) {
2198 // distribution display
2199 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
2201 if (distribution < TIME_FACTOR && distribution > -TIME_FACTOR)
2202 distmsec = fabs(distribution);
2204 distsec = floor(fabs(distribution)/TIME_FACTOR);
2205 distmsec = fabs(distribution) - distsec*TIME_FACTOR;
2206 if (distribution < 0)
2210 if (distribution <= 0) {
2211 distribution_color = eY;
2212 minusplus = 1; // minusplus 1: always prefix with minus sign
2215 distribution_color = eX;
2216 minusplus = 2; // minusplus 1: always prefix with plus sign
2218 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);
2219 HUD_DrawXNum(bottomright - '68 48 0' - '16 0 0' * TIME_DECIMALS, distsec, 4, minusplus, 16, distribution_color, 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
2220 drawpic(bottomright - '10 48 0' - '16 0 0' * TIME_DECIMALS, "gfx/hud/num_dot", '16 16 0', distribution_color, hud_alpha_fg, DRAWFLAG_ADDITIVE);
2222 // race record display
2223 if (distribution <= 0 || distribution == score) // draw the highlight background behind the timer if we have the lead
2224 drawpic(bottomright - '0 32 0' - '32 0 0' * (4 + TIME_DECIMALS), "gfx/hud/sb_highlight_4", '0 28 0' + '32 0 0' * (4 + TIME_DECIMALS), '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2226 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);
2227 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);
2228 drawpic(bottomright - '0 32 0' - TIME_DECIMALS * '30 0 0' - '18 0 0', "gfx/hud/num_dot", '30 30 0', '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE);
2230 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);
2231 drawpic(bottomright - '0 32 0' - TIME_DECIMALS * '30 0 0' - '84 0 0', "gfx/hud/num_colon", '30 30 0', '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE);
2235 // Keyhunt HUD modicon section
2236 float kh_runheretime;
2238 void CSQC_kh_hudreset(void)
2243 void CSQC_kh_hud(void)
2248 vector p, pa, kh_size, kh_asize;
2251 p_y = vid_conheight - 34 - 3;
2254 kh_keys = getstati(STAT_KH_KEYS);
2256 kh_size = '19 34 0';
2257 kh_asize = '19 10 0';
2264 for(i = 0; i < 4; ++i)
2266 key = floor(kh_keys / pow(32, i)) & 31;
2268 if(keyteam == 30 && keycount <= 4)
2270 if(keyteam == myteam || keyteam == -1 || keyteam == 30)
2273 // this yields 8 exactly if "RUN HERE" shows
2278 kh_runheretime = time;
2279 pa_y -= fabs(sin((time - kh_runheretime) * 3.5)) * 6; // make the arrows jump in case of RUN HERE
2284 for(i = 0; i < 4; ++i)
2286 key = floor(kh_keys / pow(32, i)) & 31;
2299 default: // owned or dropped
2304 a = a * hud_alpha_fg;
2305 aa = aa * hud_alpha_fg;
2311 drawpic (pa, "gfx/hud/sb_kh_redarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
2314 drawpic (pa, "gfx/hud/sb_kh_bluearrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
2317 drawpic (pa, "gfx/hud/sb_kh_yellowarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
2320 drawpic (pa, "gfx/hud/sb_kh_pinkarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
2325 switch(i) // YAY! switch(i) inside a for loop for i. DailyWTF, here we come!
2328 drawpic (p, "gfx/hud/sb_kh_red", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
2331 drawpic (p, "gfx/hud/sb_kh_blue", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
2334 drawpic (p, "gfx/hud/sb_kh_yellow", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
2337 drawpic (p, "gfx/hud/sb_kh_pink", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
2346 // Nexball HUD modicon section
2347 #define NBPB_SIZE '96 38 0'
2348 #define NBPB_BT 2 //thickness
2349 #define NBPB_BRGB '1 1 1'
2350 #define NBPB_BALPH 1 //alpha
2351 #define NBPB_BFLAG DRAWFLAG_NORMAL
2352 #define NBPB_IALPH 0.4
2353 #define NBPB_IFLAG DRAWFLAG_NORMAL
2354 #define NBPB_IRGB '0.7 0.1 0'
2356 void CSQC_nb_hud(void)
2358 float stat_items, nb_pb_starttime, dt, p;
2361 stat_items = getstati(STAT_ITEMS);
2362 nb_pb_starttime = getstatf(STAT_NB_METERSTART);
2365 pos_y = vid_conheight - 42;
2368 //Manage the progress bar if any
2369 if (nb_pb_starttime > 0)
2372 dt = mod(time - nb_pb_starttime, nb_pb_period);
2373 // one period of positive triangle
2374 p = 2 * dt / nb_pb_period;
2380 drawfill(pos, p * s_x * eX + s_y * eY, NBPB_IRGB, NBPB_IALPH, NBPB_IFLAG);
2384 drawline(NBPB_BT, pos , pos + eX * s_x, NBPB_BRGB, NBPB_BALPH, NBPB_BFLAG);
2385 drawline(NBPB_BT, pos , pos + eY * s_y, NBPB_BRGB, NBPB_BALPH, NBPB_BFLAG);
2386 drawline(NBPB_BT, pos + s, pos + eX * s_x, NBPB_BRGB, NBPB_BALPH, NBPB_BFLAG);
2387 drawline(NBPB_BT, pos + s, pos + eY * s_y, NBPB_BRGB, NBPB_BALPH, NBPB_BFLAG);
2390 pos_x += 12; //horizontal margin to the picture
2391 pos_y += 2; //vertical margin to the picture
2393 if (stat_items & IT_KEY1)
2394 drawpic(pos, "gfx/hud/sb_nexball_carrying", '80 34 0', '1 1 1', 1, DRAWFLAG_NORMAL);
2397 // Race/CTS HUD modicon section
2398 float crecordtime_prev; // last remembered crecordtime
2399 float crecordtime_change_time; // time when crecordtime last changed
2400 float srecordtime_prev; // last remembered srecordtime
2401 float srecordtime_change_time; // time when srecordtime last changed
2402 void CSQC_race_hud(void)
2405 me = playerslots[player_localentnum - 1];
2407 float f; // yet another function has this
2408 score = me.(scores[ps_primary]);
2410 if not((scores_flags[ps_primary] & SFL_TIME) && !teamplay) // race/cts record display on HUD
2411 return; // no records in the actual race
2413 drawfont = hud_bigfont;
2416 pos_y = vid_conheight - 48;
2418 // clientside personal record
2420 if(gametype == GAME_CTS)
2424 t = stof(db_get(ClientProgsDB, strcat(shortmapname, rr, "time")));
2426 if(score && (score < t || !t)) {
2427 db_put(ClientProgsDB, strcat(shortmapname, rr, "time"), ftos(score));
2428 if(cvar("cl_autodemo_delete_keeprecords"))
2430 f = cvar("cl_autodemo_delete");
2432 cvar_set("cl_autodemo_delete", ftos(f)); // don't delete demo with new record!
2436 if(t != crecordtime_prev) {
2437 crecordtime_prev = t;
2438 crecordtime_change_time = time;
2440 f = time - crecordtime_change_time;
2443 drawstring(pos, "Personal best ", '10 10 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2444 drawstring(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2446 drawstring(pos, "Personal best ", '10 10 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2447 drawstring(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2448 drawstring_expanding(pos, "Personal best ", '10 10 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL, f);
2449 drawstring_expanding(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL, f);
2454 t = race_server_record;
2455 if(t != srecordtime_prev) {
2456 srecordtime_prev = t;
2457 srecordtime_change_time = time;
2459 f = time - srecordtime_change_time;
2462 drawstring(pos, "Server best ", '10 10 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2463 drawstring(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2465 drawstring(pos, "Server best ", '10 10 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2466 drawstring(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2467 drawstring_expanding(pos, "Server best ", '10 10 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL, f);
2468 drawstring_expanding(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL, f);
2470 drawfont = hud_font;
2478 pos = HUD_Panel_GetPos(5);
2479 mySize = HUD_Panel_GetSize(5);
2481 HUD_Panel_DrawBg(5, pos, mySize);
2483 float timelimit, elapsedTime, minutes, seconds, timeleft, minutesLeft, secondsLeft;
2485 timelimit = getstatf(STAT_TIMELIMIT);
2487 HUD_DrawRaceStatus(pos + '0 30 0');
2489 timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
2490 timeleft = ceil(timeleft);
2491 minutesLeft = floor(timeleft / 60);
2492 secondsLeft = timeleft - minutesLeft*60;
2495 if(minutesLeft >= 5 || warmup_stage || timelimit == 0) //don't use red or yellow in warmup or when there is no timelimit
2496 timer_color = '1 1 1'; //white
2497 else if(minutesLeft >= 1)
2498 timer_color = '1 1 0'; //yellow
2500 timer_color = '1 0 0'; //red
2502 if (cvar("hud_timer_increment") || timelimit == 0 || warmup_stage) {
2503 if (time < getstatf(STAT_GAMESTARTTIME)) {
2504 //while restart is still active, show 00:00
2505 minutes = seconds = 0;
2507 elapsedTime = floor(time - getstatf(STAT_GAMESTARTTIME)); //127
2508 minutes = floor(elapsedTime / 60);
2509 seconds = elapsedTime - minutes*60;
2512 minutes = minutesLeft;
2513 seconds = secondsLeft;
2516 if(mySize_x/mySize_y > 5.1)
2520 minutes = min(minutes, 999);
2521 if(minutesLeft >= 1 || cvar("hud_timer_increment") || timelimit == 0 || warmup_stage) {
2523 drawpic(pos + eX * mySize_x - eX * 5.1 * mySize_y, "gfx/hud/sb_timer", '1 1 0' * mySize_y, timer_color, hud_alpha_fg, DRAWFLAG_NORMAL);
2524 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);
2525 drawpic(pos + eX * mySize_x - eX * 2.57 * mySize_y, "gfx/hud/num_colon", '1 1 0' * mySize_y, timer_color, hud_alpha_fg, DRAWFLAG_NORMAL);
2527 HUD_DrawXNum(pos + eX * mySize_x - eX * 2 * mySize_y, seconds, -2, 0, mySize_y, timer_color, 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
2533 minutes = min(minutes, 99);
2534 if(minutesLeft >= 1 || cvar("hud_timer_increment") || timelimit == 0 || warmup_stage) {
2536 drawpic(pos + eX * 0.5 * mySize_x - eX * 0.5 * 0.5 * mySize_y, "gfx/hud/sb_timer", '0.5 0.5 0' * mySize_y, timer_color, hud_alpha_fg, DRAWFLAG_NORMAL);
2537 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);
2538 drawpic(pos + eX * 0.5 * mySize_x - eX * 0.5 * 0.5 * mySize_y + eY * 0.5 * mySize_y, "gfx/hud/num_colon", '0.5 0.5 0' * mySize_y, timer_color, hud_alpha_fg, DRAWFLAG_NORMAL);
2540 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);
2547 void HUD_Radar(void)
2550 pos = HUD_Panel_GetPos(6);
2551 mySize = HUD_Panel_GetSize(6);
2553 HUD_Panel_DrawBg(6, pos, mySize);
2555 local float color1, color2; // color already declared as a global in hud.qc
2558 float scale2d, normalsize, bigsize;
2561 teamradar_origin2d = pos + 0.5 * mySize; // TODO: stupid compat, should be removed
2562 teamradar_size2d = mySize;
2564 if(minimapname == "" && !ons_showmap)
2567 teamradar_loadcvars();
2569 switch(cl_teamradar_zoommode)
2573 f = current_zoomfraction;
2576 f = 1 - current_zoomfraction;
2586 switch(cl_teamradar_rotation)
2589 teamradar_angle = view_angles_y - 90;
2592 teamradar_angle = 90 * cl_teamradar_rotation;
2596 scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
2597 teamradar_size2d = mySize;
2599 teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0';
2600 if(pos == eX * vid_conwidth)
2602 if(cl_teamradar_nohudhack < 2)
2604 if(cl_teamradar_nohudhack < 1)
2605 teamradar_extraclip_mins_y -= 25;
2607 else if(pos == eY * vid_conheight || pos == eX * vid_conwidth + eY * vid_conheight)
2609 if(cl_teamradar_nohudhack < 2)
2611 //if(cl_teamradar_nohudhack < 1)
2612 //teamradar_extraclip_size_y += 50; // don't, the HUD looks nice
2615 // pixels per world qu to match the teamradar_size2d_x range in the longest dimension
2616 if(cl_teamradar_rotation == 0)
2618 // max-min distance must fit the radar in any rotation
2619 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen2d(mi_max - mi_min));
2623 vector c0, c1, c2, c3, span;
2624 c0 = rotate(mi_min, teamradar_angle * DEG2RAD);
2625 c1 = rotate(mi_max, teamradar_angle * DEG2RAD);
2626 c2 = rotate('1 0 0' * mi_min_x + '0 1 0' * mi_max_y, teamradar_angle * DEG2RAD);
2627 c3 = rotate('1 0 0' * mi_max_x + '0 1 0' * mi_min_y, teamradar_angle * DEG2RAD);
2629 span_x = max4(c0_x, c1_x, c2_x, c3_x) - min4(c0_x, c1_x, c2_x, c3_x);
2630 span_y = max4(c0_y, c1_y, c2_y, c3_y) - min4(c0_y, c1_y, c2_y, c3_y);
2632 // max-min distance must fit the radar in x=x, y=y
2634 teamradar_size2d_x * scale2d / (1.05 * span_x),
2635 teamradar_size2d_y * scale2d / (1.05 * span_y)
2639 normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / cl_teamradar_scale;
2640 if(bigsize > normalsize)
2641 normalsize = bigsize;
2645 + (1 - f) * normalsize;
2646 teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
2647 f * (mi_min + mi_max) * 0.5
2648 + (1 - f) * view_origin);
2650 color1 = GetPlayerColor(player_localentnum-1);
2651 rgb = GetTeamRGB(color1);
2660 draw_teamradar_background(cl_teamradar_background_alpha, cl_teamradar_foreground_alpha);
2664 drawresetcliparea();
2666 vector frame_origin, frame_size;
2667 frame_origin = frame_size = '0 0 0';
2669 frame_origin_x = pos_x - teamradar_size2d_x * 0.55859375; // matches the picture
2670 frame_origin_y = pos_y - teamradar_size2d_y * 0.55859375; // matches the picture
2671 frame_size_x = pos_x * 1.1171875; // matches the picture
2672 frame_size_y = pos_y * 1.1171875; // matches the picture
2673 drawpic(frame_origin, "gfx/ons-frame.tga", frame_size, '1 1 1', hud_alpha_fg, 0);
2674 drawpic(frame_origin, "gfx/ons-frame-team.tga", frame_size, rgb, hud_alpha_fg, 0);
2677 pos_x - teamradar_size2d_x * 0.5,
2678 pos_y - teamradar_size2d_y * 0.5,
2684 for(tm = world; (tm = find(tm, classname, "radarlink")); )
2685 draw_teamradar_link(tm.origin, tm.velocity, tm.team);
2686 for(tm = world; (tm = findflags(tm, teamradar_icon, 0xFFFFFF)); )
2687 draw_teamradar_icon(tm.origin, tm.teamradar_icon, tm, tm.teamradar_color, hud_alpha_fg);
2688 for(tm = world; (tm = find(tm, classname, "entcs_receiver")); )
2690 color2 = GetPlayerColor(tm.sv_entnum);
2691 //if(color == COLOR_SPECTATOR || color == color2)
2692 draw_teamradar_player(tm.origin, tm.angles, GetTeamRGB(color2));
2694 draw_teamradar_player(view_origin, view_angles, '1 1 1');
2696 drawresetcliparea();
2705 void HUD_DrawPressedKeys(void)
2708 pos = HUD_Panel_GetPos(10);
2709 mySize = HUD_Panel_GetSize(10);
2711 HUD_Panel_DrawBg(10, pos, mySize);
2715 pressedkeys = getstatf(STAT_PRESSED_KEYS);
2716 drawpic(pos, "gfx/hud/keys/key_bg.tga", mySize, '1 1 1', 0.1 * hud_alpha_fg, DRAWFLAG_NORMAL);
2717 drawpic(pos + eX * mySize_x - eX * 0.22 * mySize_x + eY * 0.195 * mySize_y, ((pressedkeys & KEY_CROUCH) ? "gfx/hud/keys/key_crouch_inv.tga" : "gfx/hud/keys/key_crouch.tga"), '1 1 0' * (1/3) * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2718 drawpic(pos + eX * 0.5 * mySize_x - eX * 0.23 * mySize_y + eY * 0.040 * mySize_y, ((pressedkeys & KEY_FORWARD) ? "gfx/hud/keys/key_forward_inv.tga" : "gfx/hud/keys/key_forward.tga"), '1 1 0' * 0.46 * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2719 drawpic(pos + eX * 0.023 * mySize_x + eY * 0.195 * mySize_y, ((pressedkeys & KEY_JUMP) ? "gfx/hud/keys/key_jump_inv.tga" : "gfx/hud/keys/key_jump.tga"), '1 1 0' * (1/3) * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2720 drawpic(pos + eX * 0.1 * mySize_x + eY * 0.486 * mySize_y, ((pressedkeys & KEY_LEFT) ? "gfx/hud/keys/key_left_inv.tga" : "gfx/hud/keys/key_left.tga"), '1 1 0' * 0.46 * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2721 drawpic(pos + eX * 0.5 * mySize_x - eX * 0.23 * mySize_y + eY * 0.486 * mySize_y, ((pressedkeys & KEY_BACKWARD) ? "gfx/hud/keys/key_backward_inv.tga" : "gfx/hud/keys/key_backward.tga"), '1 1 0' * 0.46 * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2722 drawpic(pos + eX * mySize_x - eX * 0.372 * mySize_x + eY * 0.486 * mySize_y, ((pressedkeys & KEY_RIGHT) ? "gfx/hud/keys/key_right_inv.tga" : "gfx/hud/keys/key_right.tga"), '1 1 0' * 0.46 * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2725 void HUD_ShowSpeed(void)
2728 float pos, conversion_factor;
2729 string speed, zspeed, unit;
2731 switch(cvar("cl_showspeed_unit"))
2736 conversion_factor = 1.0;
2740 conversion_factor = 1.0;
2744 conversion_factor = 0.0254;
2748 conversion_factor = 0.0254 * 3.6;
2752 conversion_factor = 0.0254 * 3.6 * 0.6213711922;
2756 conversion_factor = 0.0254 * 1.943844492; // 1 m/s = 1.943844492 knots, because 1 knot = 1.852 km/h
2760 speed = strcat(ftos(floor( vlen(pmove_vel - pmove_vel_z * '0 0 1') * conversion_factor + 0.5 )), unit);
2762 numsize_x = numsize_y = cvar("cl_showspeed_size");
2763 pos = (vid_conheight - numsize_y) * cvar("cl_showspeed_position");
2765 drawfont = hud_bigfont;
2766 drawstringcenter(eX + pos * eY, speed, numsize, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2768 if (cvar("cl_showspeed_z") == 1) {
2769 zspeed = strcat(ftos(fabs(floor( pmove_vel_z * conversion_factor + 0.5 ))), unit);
2770 drawstringcenter(eX + pos * eY + numsize_y * eY, zspeed, numsize * 0.5, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2773 drawfont = hud_font;
2776 vector acc_prevspeed;
2780 void HUD_ShowAcceleration(void)
2782 float acceleration, sz, scale, alpha, f;
2783 vector pos, top, rgb;
2784 top_x = vid_conwidth/2;
2787 f = time - acc_prevtime;
2788 if(cvar("cl_showacceleration_z"))
2789 acceleration = (vlen(pmove_vel) - vlen(acc_prevspeed)) * (1 / f);
2791 acceleration = (vlen(pmove_vel - '0 0 1' * pmove_vel_z) - vlen(acc_prevspeed - '0 0 1' * acc_prevspeed_z)) * (1 / f);
2792 acc_prevspeed = pmove_vel;
2793 acc_prevtime = time;
2795 f = bound(0, f * 10, 1);
2796 acc_avg = acc_avg * (1 - f) + acceleration * f;
2797 acceleration = acc_avg / getstatf(STAT_MOVEVARS_MAXSPEED);
2799 pos = top - sz/2 * eY + (cvar("cl_showacceleration_position") * vid_conheight) * eY;
2801 sz = cvar("cl_showacceleration_size");
2802 scale = cvar("cl_showacceleration_scale");
2803 alpha = cvar("cl_showacceleration_alpha");
2804 if (cvar("cl_showacceleration_color_custom"))
2805 rgb = stov(cvar_string("cl_showacceleration_color"));
2808 if (acceleration < 0) {
2809 rgb = '1 .5 .5' - '0 .5 .5' * bound(0, -acceleration * 0.2, 1);
2810 } else if (acceleration > 0) {
2811 rgb = '.5 1 .5' - '.5 0 .5' * bound(0, +acceleration * 0.2, 1);
2815 if (acceleration > 0)
2816 drawpic(pos, "gfx/hud/statusbar", acceleration * scale * '40 0 0' + sz * eY, rgb, alpha * hud_alpha_fg, DRAWFLAG_NORMAL);
2817 else if (acceleration < 0)
2818 drawpic(pos + acceleration * scale * '40 0 0', "gfx/hud/statusbar", -acceleration * scale * '40 0 0' + sz * eY, rgb, alpha * hud_alpha_fg, DRAWFLAG_NORMAL);
2821 void HUD_Reset (void)
2823 // reset gametype specific icons
2824 if(gametype == GAME_KEYHUNT)
2826 else if(gametype == GAME_CTF)
2827 CSQC_ctf_hudreset();
2830 void HUD_Main (void)
2832 hud_alpha_bg = cvar_or("hud_bg_alpha", 0.8) * (1 - cvar("_menu_alpha"));
2833 hud_border_thickness = bound(0, cvar("hud_border_thickness"), 5);
2834 hud_accuracy_border_thickness = bound(0, cvar_or("hud_accuracy_border_thickness", 1), 5);
2835 hud_color_bg_team = cvar("hud_color_bg_team");
2837 hud_fontsize = HUD_GetFontsize("hud_fontsize");
2838 hud_fontsize_spec = HUD_GetFontsize("hud_fontsize_spec");
2840 if(cvar_string("hud_dock") != "0")
2841 drawpic('0 0 0', strcat("gfx/hud/", cvar_string("hud_dock")), eX * vid_conwidth + eY * vid_conheight, stov(cvar_string("hud_dock_color")), cvar("hud_dock_alpha"), DRAWFLAG_NORMAL);
2843 if(HUD_Panel_CheckActive(0))
2845 if(HUD_Panel_CheckActive(1))
2847 if(HUD_Panel_CheckActive(2))
2849 if(HUD_Panel_CheckActive(3))
2851 if(HUD_Panel_CheckActive(4))
2853 if(HUD_Panel_CheckActive(5))
2856 if(HUD_Panel_CheckActive(6))
2857 if(ons_showmap || cvar_string("cl_teamradar") != "0" && (cvar("cl_teamradar") == 2 || teamplay))
2859 if(HUD_Panel_CheckActive(7))
2861 if(HUD_Panel_CheckActive(8))
2862 if(gametype == GAME_RACE || gametype == GAME_CTS || cvar("_hud_configure"))
2864 if(HUD_Panel_CheckActive(9))
2867 if(HUD_Panel_CheckActive(10))
2868 if(spectatee_status > 0 || cvar("cl_showpressedkeys") >= 2 || cvar("_hud_configure"))
2869 HUD_DrawPressedKeys();
2871 // TODO hud_'ify these
2872 if (cvar("cl_showspeed"))
2874 if (cvar("cl_showacceleration"))
2875 HUD_ShowAcceleration();
2877 // TODO... well make them work in a panel etc
2878 if(gametype == GAME_KEYHUNT)
2880 else if(gametype == GAME_CTF)
2882 else if(gametype == GAME_NEXBALL)
2884 else if(gametype == GAME_CTS || gametype == GAME_RACE)