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_y = (1/4) * mySize_x; // 1/4 * width
578 mySize_y = (1/4) * mySize_x; // 1/4 * width
581 mySize_y = 0.5898 * mySize_x; // 0.5898 * width, reason: bg has weird dimensions...
587 // return active status of panel
588 float HUD_Panel_CheckActive(float id)
590 if (cvar_or(strcat("hud_", HUD_Panel_GetName(id)), 1))
595 // return size of given panel
596 vector HUD_Panel_GetSize(float id)
598 return stov(cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_size")));
601 // return pos of given panel
602 vector HUD_Panel_GetPos(float id)
605 pos = stov(cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_pos")));
608 pos_x = vid_conwidth + pos_x;
610 pos_y = vid_conheight + pos_y;
614 float HUD_Panel_GetMarigin(float id)
616 return bound(1, MARIGIN_MULTIPLIER * cvar_or(strcat("hud_", HUD_Panel_GetName(id), "_marigin"), 30), 200);
619 vector HUD_Panel_GetColor(float id)
621 if(cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_color")) != "")
622 return stov(cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_color")));
624 return stov(cvar_string("hud_color"));
627 float HUD_Panel_GetBgActive(float id)
629 if(cvar("_hud_configure"))
632 return cvar_or(strcat("hud_", HUD_Panel_GetName(id), "_bg"), 1);
635 vector HUD_Panel_GetProgressBarColor(string item)
637 return stov(cvar_string(strcat("hud_progressbar_", item, "_color")));
640 float resizeCorner; // 1 = topleft, 2 = topright, 3 = bottomleft, 4 = bottomright
641 // check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
642 vector HUD_Panel_CheckResize(float id, vector myPos, vector mySize)
654 for (i = 0; i < panel_cnt; ++i) {
655 if(i == id || !HUD_Panel_CheckActive(i))
658 targPos = HUD_Panel_GetPos(i);
659 targSize = HUD_Panel_GetSize(i);
661 targPos = HUD_Panel_GetPos(i) - '1 1 0' * HUD_Panel_GetMarigin(id);
662 targSize = HUD_Panel_GetSize(i) + '2 2 0' * HUD_Panel_GetMarigin(id);
664 if(myPos_y + mySize_y < targPos_y)
666 if(myPos_y > targPos_y + targSize_y)
669 if(myPos_x + mySize_x < targPos_x)
671 if(myPos_x > targPos_x + targSize_x)
674 // OK, there IS a collision.
676 myCenter_x = myPos_x + 0.5 * mySize_x;
677 myCenter_y = myPos_y + 0.5 * mySize_y;
679 targCenter_x = targPos_x + 0.5 * targSize_x;
680 targCenter_y = targPos_y + 0.5 * targSize_y;
683 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y && resizeCorner != 1) // top left (of target panel)
685 if(myPos_x + mySize_x - targPos_x < myPos_y + mySize_y - targPos_y) // push it to the side
686 myTarget_x = targPos_x - myPos_x;
687 else // push it upwards
688 myTarget_y = targPos_y - myPos_y;
690 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y && resizeCorner != 2) // top right
692 if(targPos_x + targSize_x - myPos_x < myPos_y + mySize_y - targPos_y) // push it to the side
693 myTarget_x = targPos_x + targSize_x;
694 else // push it upwards
695 myTarget_y = targPos_y - myPos_y;
697 else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
699 if(myPos_x + mySize_x - targPos_x < targPos_y + targSize_y - myPos_y) // push it to the side
700 myTarget_x = targPos_x - myPos_x;
701 else // push it downwards
702 myTarget_y = targPos_y + targSize_y;
704 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
706 if(targPos_x + targSize_x - myPos_x < targPos_y + targSize_y - myPos_y) // push it to the side
707 myTarget_x = targPos_x + targSize_x;
708 else // push it downwards
709 myTarget_y = targPos_y + targSize_y;
717 float HUD_Panel_SetSize(float id, vector mySize)
722 oldSize = stov(cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_size")));
725 myPos = HUD_Panel_GetPos(id);
727 // check for collisions
728 mySize = HUD_Panel_CheckResize(id, HUD_Panel_GetPos(id), mySize);
730 mySize_x = bound(0.025 * vid_conwidth, mySize_x, vid_conwidth - myPos_x);
731 mySize_y = bound(0.025 * vid_conheight, mySize_y, vid_conheight - myPos_y);
733 // cap against panel's own limits
734 mySize = HUD_Panel_CheckLimitSize(id, mySize);
736 //mySize_x = bound(0.025 * vid_conwidth, mySize_x, vid_conwidth);
737 //mySize_y = bound(0.025 * vid_conheight, mySize_y, vid_conheight);
739 // TODO: is this needed?
740 // this is to check if (and how) SetPos should be called
741 if(mySize_x == oldSize_x && mySize_y == oldSize_y)
742 didntresize = 3; // didnt resize either
743 else if(mySize_x == oldSize_x && mySize_y != oldSize_y)
744 didntresize = 2; // resized Y
745 else if(mySize_y == oldSize_y && mySize_x != oldSize_x)
746 didntresize = 1; // resized X
749 s = strcat(ftos(mySize_x), " ", ftos(mySize_y));
750 cvar_set(strcat("hud_", HUD_Panel_GetName(id), "_size"), s);
754 // check if move will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
755 vector HUD_Panel_CheckMove(float id, vector myPos, vector mySize)
767 for (i = 0; i < panel_cnt; ++i) {
768 if(i == id || !HUD_Panel_CheckActive(i))
771 targPos = HUD_Panel_GetPos(i) - '1 1 0' * HUD_Panel_GetMarigin(id);
772 targSize = HUD_Panel_GetSize(i) + '2 2 0' * HUD_Panel_GetMarigin(id);
774 if(myPos_y + mySize_y < targPos_y)
776 if(myPos_y > targPos_y + targSize_y)
779 if(myPos_x + mySize_x < targPos_x)
781 if(myPos_x > targPos_x + targSize_x)
784 // OK, there IS a collision.
786 myCenter_x = myPos_x + 0.5 * mySize_x;
787 myCenter_y = myPos_y + 0.5 * mySize_y;
789 targCenter_x = targPos_x + 0.5 * targSize_x;
790 targCenter_y = targPos_y + 0.5 * targSize_y;
793 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // top left (of the target panel)
795 if(myPos_x + mySize_x - targPos_x < myPos_y + mySize_y - targPos_y) // push it to the side
796 myTarget_x = targPos_x - mySize_x;
797 else // push it upwards
798 myTarget_y = targPos_y - mySize_y;
800 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y) // top right
802 if(targPos_x + targSize_x - myPos_x < myPos_y + mySize_y - targPos_y) // push it to the side
803 myTarget_x = targPos_x + targSize_x;
804 else // push it upwards
805 myTarget_y = targPos_y - mySize_y;
807 else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
809 if(myPos_x + mySize_x - targPos_x < targPos_y + targSize_y - myPos_y) // push it to the side
810 myTarget_x = targPos_x - mySize_x;
811 else // push it downwards
812 myTarget_y = targPos_y + targSize_y;
814 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
816 if(targPos_x + targSize_x - myPos_x < targPos_y + targSize_y - myPos_y) // push it to the side
817 myTarget_x = targPos_x + targSize_x;
818 else // push it downwards
819 myTarget_y = targPos_y + targSize_y;
826 void HUD_Panel_SetPos(float id, vector pos, float didntresize)
829 oldPos = HUD_Panel_GetPos(id);
832 else if(didntresize == 1)
834 else if(didntresize == 3)
838 mySize = HUD_Panel_GetSize(id);
840 pos = HUD_Panel_CheckMove(id, pos, mySize);
842 pos_x = bound(0, pos_x, vid_conwidth - mySize_x);
843 pos_y = bound(0, pos_y, vid_conheight - mySize_y);
845 if (pos_x + 0.5 * mySize_x > 0.5 * vid_conwidth)
846 pos_x = pos_x - vid_conwidth;
847 if (pos_y + 0.5 * mySize_y > 0.5 * vid_conheight)
848 pos_y = pos_y - vid_conheight;
851 s = strcat(ftos(pos_x), " ", ftos(pos_y));
853 cvar_set(strcat("hud_", HUD_Panel_GetName(id), "_pos"), s);
857 float prevMouseClicked; // previous state
858 float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
860 prevMouseClicked = mouseClicked;
861 if(nPrimary == K_MOUSE1)
863 if(bInputType == 0) { // key pressed
867 if(bInputType == 1) {// key released
875 vector mousepos, mouseprevpos;
876 vector panel_click_distance; // mouse cursor distance from the top left corner of the panel (saved only upon a click)
877 vector panel_click_pos; // panel pos (saved only upon a click)
878 vector panel_click_size; // panel size (saved only upon a click)
879 float highlightedPanel;
880 float highlightedAction; // 0 = nothing, 1 = move, 2 = resize
881 void HUD_Panel_Mouse()
883 if(mouseClicked == 0) {
884 highlightedPanel = -1;
885 highlightedAction = 0;
888 mousepos = mousepos + getmousepos();
890 mousepos_x = bound(0, mousepos_x, vid_conwidth);
891 mousepos_y = bound(0, mousepos_y, vid_conheight);
893 drawpic(mousepos, "gfx/menu/default/cursor.tga", '32 32 0', '1 1 1', 1, hud_alpha_fg);
901 for(i = 0; i <= panel_cnt; ++i)
903 panelPos = HUD_Panel_GetPos(i);
904 panelSize = HUD_Panel_GetSize(i);
905 marigin = HUD_Panel_GetMarigin(i);
906 if(prevMouseClicked == 0) {
908 if(mousepos_x >= panelPos_x && mousepos_y >= panelPos_y && mousepos_x <= panelPos_x + panelSize_x && mousepos_y <= panelPos_y + panelSize_y)
910 highlightedPanel = i;
911 highlightedAction = 1;
913 // resize from topleft border
914 else if(mousepos_x >= panelPos_x - marigin && mousepos_y >= panelPos_y - marigin && mousepos_x <= panelPos_x + 0.5 * panelSize_x && mousepos_y <= panelPos_y + 0.5 * panelSize_y)
916 highlightedPanel = i;
917 highlightedAction = 2;
920 // resize from topright border
921 else if(mousepos_x >= panelPos_x + 0.5 * panelSize_x && mousepos_y >= panelPos_y - marigin && mousepos_x <= panelPos_x + panelSize_x + marigin && mousepos_y <= panelPos_y + 0.5 * panelSize_y)
923 highlightedPanel = i;
924 highlightedAction = 2;
927 // resize from bottomleft border
928 else if(mousepos_x >= panelPos_x - marigin && mousepos_y >= panelPos_y + 0.5 * panelSize_y && mousepos_x <= panelPos_x + 0.5 * panelSize_x && mousepos_y <= panelPos_y + panelSize_y + marigin)
930 highlightedPanel = i;
931 highlightedAction = 2;
934 // resize from bottomright border
935 else if(mousepos_x >= panelPos_x + 0.5 * panelSize_x && mousepos_y >= panelPos_y + 0.5 * panelSize_y && mousepos_x <= panelPos_x + panelSize_x + marigin && mousepos_y <= panelPos_y + panelSize_y + marigin)
937 highlightedPanel = i;
938 highlightedAction = 2;
943 if(highlightedPanel == i)
945 if(prevMouseClicked == 0)
947 panel_click_distance = mousepos - panelPos;
948 panel_click_pos = panelPos;
949 panel_click_size = panelSize;
952 if(highlightedAction == 1)
953 HUD_Panel_SetPos(i, mousepos - panel_click_distance, 0);
954 else if(highlightedAction == 2)
956 float didntresize; // panel too big/too small, dont resize (also has to affect moving)
957 if(resizeCorner == 1) {
958 didntresize = HUD_Panel_SetSize(i, panelSize + mouseprevpos - mousepos);
959 HUD_Panel_SetPos(i, mousepos - panel_click_distance, didntresize);
961 if(resizeCorner == 2) {
962 didntresize = HUD_Panel_SetSize(i, eY * panel_click_size_y + eX * (mousepos_x - panelPos_x - (panel_click_distance_x - panel_click_size_x))
963 + eY * (panel_click_distance_y + (panel_click_pos_y - mousepos_y)));
964 HUD_Panel_SetPos(i, eX * panelPos_x + eY * (mousepos_y - panel_click_distance_y), didntresize);
966 if(resizeCorner == 3) {
967 didntresize = HUD_Panel_SetSize(i, panelSize + eX * (mouseprevpos_x - mousepos_x) + eY * (mousepos_y - mouseprevpos_y));
968 HUD_Panel_SetPos(i, eX * (mousepos_x - panel_click_distance_x) + eY * panelPos_y, didntresize);
970 if(resizeCorner == 4) {
971 HUD_Panel_SetSize(i, mousepos - panelPos - (panel_click_distance - panel_click_size));
977 mouseprevpos = mousepos;
978 prevMouseClicked = mouseClicked;
981 /*void HUD_DrawDockEdge(float id, vector p1, vector p2, float target)
987 */ // maybe one day, since this will be quite complicated
992 float weaponspace[10];
993 void HUD_WeaponIcons_Clear()
996 for(idx = 0; idx < 10; ++idx)
997 weaponspace[idx] = 0;
1000 void HUD_WeaponIcons()
1002 float alpha, height, marigin, accuracybar_height, stat_weapons; // "constants"
1003 vector pos, mySize, mysize, mypos, color, accuracy_color;
1004 float i, id, fade, weapon_stats, weapon_hit, weapon_damage, weapon_cnt; // variables
1006 marigin = HUD_Panel_GetMarigin(0);
1007 pos = HUD_Panel_GetPos(0);
1008 mySize = HUD_Panel_GetSize(0);
1009 color = HUD_Panel_GetColor(0);
1010 accuracybar_height = cvar_or("hud_weaponicons_accuracybar_height", 3);
1012 stat_weapons = getstati(STAT_WEAPONS);
1013 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1015 self = get_weaponinfo(i);
1016 if(self.weapons && self.impulse >= 0 && stat_weapons & self.weapons)
1020 if(HUD_Panel_GetBgActive(0) && weapon_cnt)
1021 draw_BorderPicture(pos - '1 1 0' * marigin, "gfx/hud/border", mySize + '1 1 0' * 2 * marigin, color, hud_alpha_bg, '1 1 0' * (marigin/MARIGIN_MULTIPLIER));
1024 weapon_stats = getstati(STAT_DAMAGE_HITS);
1025 weapon_number = weapon_stats & 63;
1026 weapon_hits[weapon_number-WEP_FIRST] = floor(weapon_stats / 64);
1028 weapon_stats = getstati(STAT_DAMAGE_FIRED);
1029 weapon_number = weapon_stats & 63;
1030 weapon_fired[weapon_number-WEP_FIRST] = floor(weapon_stats / 64);
1032 if(cvar_or("hud_weaponicons_fade", 1))
1034 fade = 3.2 - 2 * (time - weapontime);
1035 fade = bound(0.7, fade, 1);
1040 HUD_WeaponIcons_Clear();
1042 float rows, columns;
1043 //TODO: yuck. there must be a better way :)
1044 //rows = ceil(4 * mySize_y/mySize_x);
1045 if(mySize_y/mySize_x < 0.08)
1047 else if(mySize_y/mySize_x < 0.25)
1049 else if(mySize_y/mySize_x < 0.5)
1051 else if(mySize_y/mySize_x < 0.7)
1053 else if(mySize_y/mySize_x < 0.9)
1055 else if(mySize_y/mySize_x < 1.25)
1057 else if(mySize_y/mySize_x < 1.7)
1059 else if(mySize_y/mySize_x < 2.5)
1061 else if(mySize_y/mySize_x < 4)
1063 else if(mySize_y/mySize_x < 6)
1068 columns = ceil(16/rows);
1070 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1072 self = get_weaponinfo(i);
1073 if((self.weapons && self.impulse >= 0 && stat_weapons & self.weapons) || cvar("_hud_configure"))
1077 alpha = (id == activeweapon) ? 1 : 0.6;
1079 weapon_hit = weapon_hits[self.weapon-WEP_FIRST];
1080 weapon_damage = weapon_fired[self.weapon-WEP_FIRST];
1081 if(id == 0) // porto and hook should be last
1086 if(id+1 == activeweapon)
1087 drawpic(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows), "gfx/hud/sb_ammobg", eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows), color, fade * hud_alpha_fg, DRAWFLAG_NORMAL);
1088 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);
1090 if(cvar_or("hud_weaponicons_number", 1))
1091 drawstring(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows), ftos(id+1), '1 1 0' * 0.5 * mySize_y*(1/rows), '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1093 // draw the weapon accuracy on the HUD
1094 if(hud_accuracy_hud && !(gametype == GAME_RACE || gametype == GAME_CTS))
1097 weapon_stats = floor(100 * weapon_hit / weapon_damage);
1099 accuracy_color = HUD_AccuracyColor(weapon_stats);
1101 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);
1118 float GetAmmoStat(float i)
1122 case 0: return STAT_SHELLS;
1123 case 1: return STAT_NAILS;
1124 case 2: return STAT_ROCKETS;
1125 case 3: return STAT_CELLS;
1126 case 4: return STAT_FUEL;
1131 float GetAmmoItemCode(float i)
1135 case 0: return IT_SHELLS;
1136 case 1: return IT_NAILS;
1137 case 2: return IT_ROCKETS;
1138 case 3: return IT_CELLS;
1139 case 4: return IT_FUEL;
1144 string GetAmmoPicture(float i)
1148 case 0: return "gfx/hud/sb_shells";
1149 case 1: return "gfx/hud/sb_bullets";
1150 case 2: return "gfx/hud/sb_rocket";
1151 case 3: return "gfx/hud/sb_cells";
1152 case 4: return "gfx/hud/sb_fuel";
1157 void HUD_Inventory()
1163 vector pos, mySize, mysize, mypos, color;
1164 marigin = HUD_Panel_GetMarigin(1);
1165 pos = HUD_Panel_GetPos(1);
1166 mySize = HUD_Panel_GetSize(1);
1167 color = HUD_Panel_GetColor(1);
1169 if(HUD_Panel_GetBgActive(1))
1170 draw_BorderPicture(pos - '1 1 0' * marigin, "gfx/hud/border", mySize + '1 1 0' * 2 * marigin, color, hud_alpha_bg, '1 1 0' * (marigin/MARIGIN_MULTIPLIER));
1173 stat_items = getstati(STAT_ITEMS);
1174 for (i = 0; i < 4; ++i) {
1176 a = getstati(GetAmmoStat(i)); // how much ammo do we have of type i?
1177 if(cvar("_hud_configure"))
1180 if(cvar("hud_ammo_onlycurrent")) {
1181 if (stat_items & GetAmmoItemCode(i)) {
1182 drawpic(pos - '1 1 0' * marigin, "gfx/hud/sb_ammobg", mysize + '1 1 0' * marigin, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1183 drawpic(pos + eX * mysize_x * 1.7, GetAmmoPicture(i), '24 24 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1185 HUD_DrawXNum(pos + '5 5 0', a, 3, 0, 24, '0.7 0 0', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1187 HUD_DrawXNum(pos + '5 5 0', a, 3, 0, 24, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1191 if(mySize_x/mySize_y >= 10) { // arrange horizontally
1193 case 0: mypos_x = pos_x; mypos_y = pos_y; break; // shells
1194 case 1: mypos_x = pos_x + 0.25 * mySize_x; mypos_y = pos_y; break; // bullets
1195 case 2: mypos_x = pos_x + 0.5 * mySize_x; mypos_y = pos_y; break; // rockets
1196 case 3: mypos_x = pos_x + 0.75 * mySize_x; mypos_y = pos_y; break; // cells
1198 mysize_x = 0.25 * mySize_x;
1199 mysize_y = mySize_y;
1200 } else if(mySize_x/mySize_y >= 2.5) { // arrange in a 2x2 grid
1202 case 0: mypos_x = pos_x + 0.5 * mySize_x; mypos_y = pos_y + 0.5 * mySize_y; break; // shells
1203 case 1: mypos_x = pos_x + 0.5 * mySize_x; mypos_y = pos_y; break; // bullets
1204 case 2: mypos_x = pos_x; mypos_y = pos_y + 0.5 * mySize_y; break; // rockets
1205 case 3: mypos_x = pos_x; mypos_y = pos_y; break; // cells
1207 mysize_x = 0.5 * mySize_x;
1208 mysize_y = 0.5 * mySize_y;
1209 } else { // arrange vertically
1211 case 0: mypos_x = pos_x; mypos_y = pos_y; break; // shells
1212 case 1: mypos_x = pos_x; mypos_y = pos_y + 0.25 * mySize_y; break; // bullets
1213 case 2: mypos_x = pos_x; mypos_y = pos_y + 0.5 * mySize_y; break; // rockets
1214 case 3: mypos_x = pos_x; mypos_y = pos_y + 0.75 * mySize_y; break; // cells
1216 mysize_x = mySize_x;
1217 mysize_y = 0.25 * mySize_y;
1220 if (stat_items & GetAmmoItemCode(i))
1221 drawpic(mypos, "gfx/hud/sb_ammobg", mysize, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1222 drawpic(mypos + eY * 0.05 * mysize_y, GetAmmoPicture(i), '1 1 0' * 0.8 * mysize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1224 if(stat_items & GetAmmoItemCode(i))
1225 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);
1227 HUD_DrawXNum(mypos + eX * 0.8 * mysize_y + eY * 0.25 * mysize_y, a, strlen(ftos(a)), 0, 0.5 * mysize_y, '0.7 0 0', 0, 0, hud_alpha_fg * 0.7, DRAWFLAG_NORMAL);
1229 if(stat_items & GetAmmoItemCode(i))
1230 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);
1232 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);
1239 a = getstati(GetAmmoStat(4)); // how much fuel do we have?
1241 if (a > 0) { // if we have fuel, draw the amount
1242 if(pos_x + 0.5 * mySize_x > 0.5 * vid_conwidth)
1243 mypos_x += pos_x + mySize_x - 0; // TODO!
1245 drawpic(mypos - '0 2 0' + '52 0 0', GetAmmoPicture(4), '20 20 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1247 HUD_DrawXNum(mypos, a, 3, 0, 16, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1249 HUD_DrawXNum(mypos, a, 3, 0, 16, '0.7 0 0', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1256 void HUD_Powerups() {
1257 float stat_items, dt;
1260 vector pos, mySize, color;
1261 marigin = HUD_Panel_GetMarigin(2);
1262 pos = HUD_Panel_GetPos(2);
1263 mySize = HUD_Panel_GetSize(2);
1264 color = HUD_Panel_GetColor(2);
1266 if(HUD_Panel_GetBgActive(2))
1267 draw_BorderPicture(pos - '1 1 0' * marigin, "gfx/hud/border", mySize + '1 1 0' * 2 * marigin, color, hud_alpha_bg, '1 1 0' * (marigin/MARIGIN_MULTIPLIER));
1269 stat_items = getstati(STAT_ITEMS);
1271 if not(stat_items & IT_STRENGTH)
1272 if not(stat_items & IT_INVINCIBLE)
1276 if (getstati(STAT_HEALTH) <= 0)
1279 float strength_time, invincibility_time, countdown_fontsize;
1282 strength_time = getstatf(STAT_STRENGTH_FINISHED);
1283 invincibility_time = getstatf(STAT_INVINCIBLE_FINISHED);
1285 if (strength_time) {
1286 dt = strength_time - time;
1291 drawpic_expanding_two(pos, "gfx/hud/sb_str", '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE,
1292 bound(0, (ceil(dt) - dt) / 0.5, 1));
1296 drawpic(pos, "gfx/hud/sb_str", '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE);
1298 HUD_DrawXNum(pos - '40 -2 0', ceil(dt), 2, 0, countdown_fontsize, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1302 drawpic_expanding(pos, "gfx/hud/sb_str", '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE,
1303 bound(0, -dt / 0.5, 1));
1308 if (invincibility_time) {
1309 dt = invincibility_time - time;
1314 drawpic_expanding_two(pos - '0 -22 0', "gfx/hud/sb_invinc", '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE,
1315 bound(0, (ceil(dt) - dt) / 0.5, 1));
1319 drawpic(pos - '0 -22 0', "gfx/hud/sb_invinc", '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE);
1321 HUD_DrawXNum(pos - '40 -24 0', ceil(dt), 2, 0, countdown_fontsize, '1 1 1', 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1325 drawpic_expanding(pos - '0 -22 0', "gfx/hud/sb_invinc", '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_ADDITIVE,
1326 bound(0, -dt / 0.5, 1));
1331 // Health/armor (#3)
1333 void HUD_HealthArmor(void)
1337 vector pos, mySize, color;
1338 marigin = HUD_Panel_GetMarigin(3);
1339 pos = HUD_Panel_GetPos(3);
1340 mySize = HUD_Panel_GetSize(3);
1341 color = HUD_Panel_GetColor(3);
1343 if(HUD_Panel_GetBgActive(3))
1344 draw_BorderPicture(pos - '1 1 0' * marigin, "gfx/hud/border", mySize + '1 1 0' * 2 * marigin, color, hud_alpha_bg, '1 1 0' * (marigin/MARIGIN_MULTIPLIER));
1346 float armor, health, x;
1347 armor = getstati(STAT_ARMOR);
1348 health = getstati(STAT_HEALTH);
1349 if(cvar("_hud_configure"))
1361 if(hud_hudselector == 2) // combined health and armor display
1364 v = healtharmor_maxdamage(health, armor, armorblockpercent);
1367 num_pos = - '96 28 0';
1371 if(v_z) // fully armored
1373 // here, armorideal > armor
1374 drawpic(num_pos + '78 -4.5 0', "gfx/hud/sb_health", '32 32 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1375 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);
1379 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);
1380 drawpic(num_pos + '78 -4.5 0', "gfx/hud/sb_armor", '32 32 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1382 HUD_DrawXNum_Colored(num_pos, x, 3, 24, hud_alpha_fg); // draw the combined health and armor
1387 vector health_pos, armor_pos;
1390 if (hud_hudselector == 0) { // old style layout with armor left of health
1392 health_pos = pos + eX * 0.5 * mySize_x;
1395 armor_pos = pos + eX * 0.5 * mySize_x;
1399 if (mySize_x/mySize_y > 5)
1403 numbers = strlen(ftos(x));
1407 drawpic(pos, "gfx/hud/statusbar", eX * 0.5 * mySize_x * min(1, x/200) + eY * mySize_y, HUD_Panel_GetProgressBarColor("armor"), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1409 drawpic(pos, "gfx/hud/sb_armor", '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1411 drawpic(pos, "gfx/hud/sb_armor", '1 1 0' * mySize_y, '1 1 1', (x+10)/55 * hud_alpha_fg, DRAWFLAG_NORMAL);
1412 HUD_DrawXNum_Colored(pos + eX * mySize_y + eY * 0.25 * mySize_y, x, numbers, 0.5 * mySize_y, hud_alpha_fg);
1417 drawpic(pos + eX * mySize_x - eX * 0.5 * mySize_x * min(1, x/200), "gfx/hud/statusbar", eX * 0.5 * mySize_x * min(1, x/200) + eY * mySize_y, HUD_Panel_GetProgressBarColor("health"), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1418 drawpic(pos + eX * mySize_x - eX * mySize_y, "gfx/hud/sb_health", '1 1 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1419 HUD_DrawXNum_Colored(pos + eX * mySize_x - eX * 2.5 * mySize_y + eY * 0.25 * mySize_y, x, 3, 0.5 * mySize_y, hud_alpha_fg);
1421 else if (mySize_x/mySize_y > 3.2)
1425 numbers = strlen(ftos(x));
1429 drawpic(pos + eY * mySize_y - eY * mySize_y * min(1, x/200), "gfx/hud/statusbar", eX * 0.5 * mySize_x + eY * mySize_y * min(1, x/200), HUD_Panel_GetProgressBarColor("armor"), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1431 drawpic(pos + eX * 0.4 * mySize_y, "gfx/hud/sb_armor", '0.7 0.7 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1433 drawpic(pos + eX * 0.4 * mySize_y, "gfx/hud/sb_armor", '0.7 0.7 0' * mySize_y, '1 1 1', (x+10)/55 * hud_alpha_fg, DRAWFLAG_NORMAL);
1434 HUD_DrawXNum_Colored(pos + eY * 0.55 * mySize_y, x, numbers, 0.5 * mySize_y, hud_alpha_fg);
1439 numbers = strlen(ftos(x));
1441 drawpic(pos + eX * 0.5 * mySize_x + eY * mySize_y - eY * mySize_y * min(1, x/200), "gfx/hud/statusbar", eX * 0.5 * mySize_x + eY * mySize_y * min(1, x/200), HUD_Panel_GetProgressBarColor("health"), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1442 drawpic(pos + eX * mySize_x - eX * 1.1 * mySize_y, "gfx/hud/sb_health", '0.7 0.7 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1443 HUD_DrawXNum_Colored(pos + eX * mySize_x - eX * numbers * 0.5 * mySize_y + eY * 0.55 * mySize_y, x, numbers, 0.5 * mySize_y, hud_alpha_fg);
1449 numbers = strlen(ftos(x));
1453 drawpic(pos, "gfx/hud/statusbar", eX * mySize_x * min(1, x/200) + eY * 0.5 * mySize_y, HUD_Panel_GetProgressBarColor("armor"), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1455 drawpic(pos, "gfx/hud/sb_armor", '0.5 0.5 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1457 drawpic(pos, "gfx/hud/sb_armor", '0.5 0.5 0' * mySize_y, '1 1 1', (x+10)/55 * hud_alpha_fg, DRAWFLAG_NORMAL);
1458 HUD_DrawXNum_Colored(pos + eX * 0.5 * mySize_y, x, numbers, 0.5 * mySize_y, hud_alpha_fg);
1463 numbers = strlen(ftos(x));
1465 drawpic(pos + eY * 0.5 * mySize_y, "gfx/hud/statusbar", eX * mySize_x * min(1, x/200) + eY * 0.5 * mySize_y, HUD_Panel_GetProgressBarColor("health"), cvar("hud_progressbar_alpha"), DRAWFLAG_NORMAL);
1466 drawpic(pos + eY * 0.5 * mySize_y, "gfx/hud/sb_health", '0.5 0.5 0' * mySize_y, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
1467 HUD_DrawXNum_Colored(pos + eX * 0.5 * mySize_y + eY * 0.5 * mySize_y, x, numbers, 0.5 * mySize_y, hud_alpha_fg);
1478 vector pos, mySize, color;
1479 marigin = HUD_Panel_GetMarigin(7);
1480 pos = HUD_Panel_GetPos(7);
1481 mySize = HUD_Panel_GetSize(7);
1482 color = HUD_Panel_GetColor(7);
1484 if(HUD_Panel_GetBgActive(7))
1485 draw_BorderPicture(pos - '1 1 0' * marigin, "gfx/hud/border", mySize + '1 1 0' * 2 * marigin, color, hud_alpha_bg, '1 1 0' * (marigin/MARIGIN_MULTIPLIER));
1487 float score, distribution, leader;
1488 vector score_pos, secondary_score_pos, distribution_color;
1490 me = (spectatee_status > 0) ? playerslots[spectatee_status - 1] : playerslots[player_localentnum - 1];
1492 if (!teamplay) { // non-teamgames
1493 // me vector := [team/connected frags id]
1494 pl = players.sort_next;
1499 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
1503 score = me.(scores[ps_primary]);
1505 if(distribution >= 5) {
1506 distribution_color = eY;
1508 } else if(distribution >= 0) {
1509 distribution_color = '1 1 1';
1511 } else if(distribution >= -5)
1512 distribution_color = '1 1 0';
1514 distribution_color = eX;
1516 HUD_DrawXNum(pos + eX * mySize_x - eX * 6 * 0.3 * mySize_y, distribution, 6, 3, 0.3 * mySize_y, distribution_color, 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1517 HUD_DrawXNum(pos + eX * mySize_x - eX * 6 * 0.75 * mySize_y + eY * 0.35 * mySize_y, score, 6, 0, 0.75 * mySize_y, distribution_color, leader, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
1518 } else { // teamgames
1519 float max_fragcount;
1520 max_fragcount = -999;
1522 for(tm = teams.sort_next; tm; tm = tm.sort_next) {
1523 if(tm.team == COLOR_SPECTATOR || !tm.team_size) // no players? don't display
1525 score = tm.(teamscores[ts_primary]);
1528 if (score > max_fragcount)
1529 max_fragcount = score;
1531 if(tm.team == myteam) {
1532 if (max_fragcount == score)
1534 HUD_DrawXNum(score_pos, score, 4, 0, 34, GetTeamRGB(tm.team) * 0.8, leader, 1, hud_alpha_fg, DRAWFLAG_NORMAL);
1536 if (max_fragcount == score)
1538 HUD_DrawXNum(secondary_score_pos, score, 6, 0, 16, GetTeamRGB(tm.team) * 0.8, leader, 1, hud_alpha_fg, DRAWFLAG_NORMAL);
1539 secondary_score_pos = secondary_score_pos + '0 16 0';
1547 void HUD_RaceTimer (void) {
1550 vector pos, mySize, color;
1551 marigin = HUD_Panel_GetMarigin(8);
1552 pos = HUD_Panel_GetPos(8);
1553 mySize = HUD_Panel_GetSize(8);
1554 color = HUD_Panel_GetColor(8);
1556 if(HUD_Panel_GetBgActive(8))
1557 draw_BorderPicture(pos - '1 1 0' * marigin, "gfx/hud/border", mySize + '1 1 0' * 2 * marigin, color, hud_alpha_bg, '1 1 0' * (marigin/MARIGIN_MULTIPLIER));
1559 drawfont = hud_bigfont;
1561 string s, forcetime;
1563 if(cvar("_hud_configure"))
1566 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);
1567 s = "^1Intermediate 1 (+15.42)";
1568 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);
1570 else if(race_checkpointtime)
1572 a = bound(0, 2 - (time - race_checkpointtime), 1);
1575 if(a > 0) // just hit a checkpoint?
1577 if(race_checkpoint != 254)
1579 if(race_time && race_previousbesttime)
1580 s = MakeRaceString(race_checkpoint, TIME_DECODE(race_time) - TIME_DECODE(race_previousbesttime), 0, 0, race_previousbestname);
1582 s = MakeRaceString(race_checkpoint, 0, -1, 0, race_previousbestname);
1584 forcetime = TIME_ENCODED_TOSTRING(race_time);
1589 if(race_laptime && race_nextbesttime && race_nextcheckpoint != 254)
1591 a = bound(0, 2 - ((race_laptime + TIME_DECODE(race_nextbesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1);
1592 if(a > 0) // next one?
1594 s = MakeRaceString(race_nextcheckpoint, (time + TIME_DECODE(race_penaltyaccumulator)) - race_laptime, TIME_DECODE(race_nextbesttime), 0, race_nextbestname);
1599 if(s != "" && a > 0)
1601 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
1602 //drawcolorcodedstring(m - '0 16 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
1603 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);
1606 if(race_penaltytime)
1608 a = bound(0, 2 - (time - race_penaltyeventtime), 1);
1611 s = strcat("^1PENALTY: ", ftos_decimals(race_penaltytime * 0.1, 1), " (", race_penaltyreason, ")");
1612 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
1613 //drawcolorcodedstring(m - '0 32 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
1614 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);
1620 a = bound(0, (time - race_checkpointtime) / 0.5, 1);
1621 //drawstring_expanding(m - '16 0 0' * stringwidth(forcetime, FALSE), forcetime, '32 32 0', '1 1 1', hud_alpha_fg, 0, a);
1622 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);
1627 if(race_laptime && race_checkpoint != 255)
1629 s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime));
1630 //drawstring(m - '16 0 0' * stringwidth(s, FALSE), s, '32 32 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
1631 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);
1636 if(race_mycheckpointtime)
1638 a = bound(0, 2 - (time - race_mycheckpointtime), 1);
1639 s = MakeRaceString(race_mycheckpoint, TIME_DECODE(race_mycheckpointdelta), -!race_mycheckpointenemy, race_mycheckpointlapsdelta, race_mycheckpointenemy);
1640 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
1641 //drawcolorcodedstring(m - '0 16 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
1642 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);
1644 if(race_othercheckpointtime && race_othercheckpointenemy != "")
1646 a = bound(0, 2 - (time - race_othercheckpointtime), 1);
1647 s = MakeRaceString(race_othercheckpoint, -TIME_DECODE(race_othercheckpointdelta), -!race_othercheckpointenemy, race_othercheckpointlapsdelta, race_othercheckpointenemy);
1648 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
1649 //drawcolorcodedstring(m - '0 0 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
1650 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);
1653 if(race_penaltytime && !race_penaltyaccumulator)
1655 t = race_penaltytime * 0.1 + race_penaltyeventtime;
1656 a = bound(0, (1 + t - time), 1);
1660 s = strcat("^1PENALTY: ", ftos_decimals(t - time, 1), " (", race_penaltyreason, ")");
1662 s = strcat("^2PENALTY: 0.0 (", race_penaltyreason, ")");
1663 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
1664 //drawcolorcodedstring(m - '0 32 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
1665 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);
1670 drawfont = hud_font;
1673 // Notification area (#4)
1674 void HUD_Notify (void)
1678 vector pos, mySize, color;
1679 marigin = HUD_Panel_GetMarigin(4);
1680 pos = HUD_Panel_GetPos(4);
1681 mySize = HUD_Panel_GetSize(4);
1682 color = HUD_Panel_GetColor(4);
1684 if(HUD_Panel_GetBgActive(4))
1685 draw_BorderPicture(pos - '1 1 0' * marigin, "gfx/hud/border", mySize + '1 1 0' * 2 * marigin, color, hud_alpha_bg, '1 1 0' * (marigin/MARIGIN_MULTIPLIER));
1689 if(spectatee_status && !intermission)
1691 drawfont = hud_bigfont;
1692 if(spectatee_status == -1)
1695 s = GetPlayerName(spectatee_status - 1);
1696 // spectated player name between HUD and chat area, aligned to the left
1698 pos_y = - 50 - hud_fontsize_spec_y;
1699 s = textShortenToWidth(s, vid_conwidth/2.5, hud_fontsize_spec, stringwidth_colors);
1700 drawcolorcodedstring(pos, s, hud_fontsize_spec, hud_alpha_fg, DRAWFLAG_NORMAL);
1701 drawfont = hud_font;
1703 // spectator text in the upper right corner
1704 if(spectatee_status == -1)
1705 s = strcat("^1Press ^3", getcommandkey("primary fire", "+attack"), "^1 to spectate");
1707 s = strcat("^1Press ^3", getcommandkey("primary fire", "+attack"), "^1 for another player");
1709 if(spectatee_status == -1)
1710 s = strcat("^1Use ^3", getcommandkey("next weapon", "weapnext"), "^1 or ^3", getcommandkey("previous weapon", "weapprev"), "^1 to change the speed");
1712 s = strcat("^1Press ^3", getcommandkey("secondary fire", "+attack2"), "^1 to observe");
1714 s = strcat("^1Press ^3", getcommandkey("server info", "+show_info"), "^1 for gamemode info");
1716 if(gametype == GAME_ARENA)
1717 s = "^1Wait for your turn to join";
1718 else if(gametype == GAME_LMS)
1721 sk = playerslots[player_localentnum - 1];
1722 if(sk.(scores[ps_primary]) >= 666)
1723 s = "^1Match has already begun";
1724 else if(sk.(scores[ps_primary]) > 0)
1725 s = "^1You have no more lives left";
1727 s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
1730 s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
1732 //show restart countdown:
1733 if (time < getstatf(STAT_GAMESTARTTIME)) {
1735 //we need to ceil, otherwise the countdown would be off by .5 when using round()
1736 countdown = ceil(getstatf(STAT_GAMESTARTTIME) - time);
1737 s = strcat("^1Game starts in ^3", ftos(countdown), "^1 seconds");
1740 if(warmup_stage && !intermission)
1742 s = "^2Currently in ^1warmup^2 stage!";
1745 // move more important stuff more to the middle so its more visible
1748 if(mod(time, 1) >= 0.5)
1753 if(ready_waiting && !intermission && !spectatee_status)
1755 if(ready_waiting_for_me)
1758 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " to end warmup");
1760 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " once you are ready");
1765 s = strcat("^2Waiting for others to ready up to end warmup...");
1767 s = strcat("^2Waiting for others to ready up...");
1770 else if(warmup_stage && !intermission && !spectatee_status)
1772 s = strcat("^2Press ^3", getcommandkey("ready", "ready"), "^2 to end warmup");
1775 if(teamplay && !intermission && !spectatee_status && gametype != GAME_CA && teamnagger)
1777 float ts_min, ts_max;
1778 tm = teams.sort_next;
1781 for(; tm.sort_next; tm = tm.sort_next)
1783 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
1785 if(!ts_min) ts_min = tm.team_size;
1786 else ts_min = min(ts_min, tm.team_size);
1787 if(!ts_max) ts_max = tm.team_size;
1788 else ts_max = max(ts_max, tm.team_size);
1790 if ((ts_max - ts_min) > 1)
1792 s = strcat(blinkcolor, "Teamnumbers are unbalanced!");
1793 tm = GetTeam(myteam, false);
1795 if (tm.team != COLOR_SPECTATOR)
1796 if (tm.team_size == ts_max)
1797 s = strcat(s, " Press ^3", getcommandkey("team menu", "menu_showteamselect"), blinkcolor, " to adjust");
1805 float vote_yescount;
1808 float vote_highlighted; // currently selected vote
1810 float vote_active; // is there an active vote?
1811 float vote_prev; // previous state of vote_active to check for a change
1813 float vote_change; // "time" when vote_active changed
1815 void HUD_VoteWindow(void)
1819 vector pos, mySize, color;
1820 marigin = HUD_Panel_GetMarigin(9);
1821 pos = HUD_Panel_GetPos(9);
1822 mySize = HUD_Panel_GetSize(9);
1823 color = HUD_Panel_GetColor(9);
1827 if(vote_active != vote_prev) {
1829 vote_prev = bound(0, vote_active, 1);
1833 vote_alpha = bound(0, (time - vote_change) * 2, 1);
1835 vote_alpha = bound(0, 1 - (time - vote_change) * 2, 1);
1837 if(cvar("_hud_configure"))
1845 if(HUD_Panel_GetBgActive(9))
1846 draw_BorderPicture(pos - '1 1 0' * marigin, "gfx/hud/border", mySize + '1 1 0' * 2 * marigin, color, hud_alpha_bg * vote_alpha, '1 1 0' * (marigin/MARIGIN_MULTIPLIER));
1849 a = vote_alpha * bound(cvar_or("hud_vote_alreadyvoted_alpha", 0.75), 1 - vote_highlighted, 1);
1851 drawpic(pos, "gfx/hud/voteprogress_back", mySize, HUD_GetBgColor(), a * hud_alpha_bg, DRAWFLAG_NORMAL);
1853 s = "A vote has been called for: ";
1854 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);
1855 s = textShortenToWidth(vote_called_vote, mySize_x * 0.96, '10 0 0', stringwidth_colors);
1856 if(cvar("_hud_configure"))
1857 s = "Configure the HUD";
1858 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);
1860 // print the yes/no counts
1861 s = strcat("Yes: ", ftos(vote_yescount));
1862 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);
1863 s = strcat("No: ", ftos(vote_nocount));
1864 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);
1866 // draw the progress bars
1867 drawsetcliparea(pos_x, pos_y, mySize_x * 0.5 * (vote_yescount/vote_needed), mySize_y);
1868 drawpic(pos, "gfx/hud/voteprogress_prog", mySize, eY, a * hud_alpha_fg, DRAWFLAG_NORMAL);
1870 drawsetcliparea(pos_x + mySize_x - mySize_x * 0.5 * (vote_nocount/vote_needed), pos_y, mySize_x * 0.5, mySize_y);
1871 drawpic(pos, "gfx/hud/voteprogress_prog", mySize, eX, a * hud_alpha_fg, DRAWFLAG_NORMAL);
1873 // draw the highlights
1874 if(vote_highlighted == 1) {
1875 drawsetcliparea(pos_x, pos_y, mySize_x * 0.5, mySize_y);
1876 drawpic(pos, "gfx/hud/voteprogress_voted", mySize, eY, a * hud_alpha_fg, DRAWFLAG_NORMAL);
1878 else if(vote_highlighted == 2) {
1879 drawsetcliparea(pos_x + 0.5 * mySize_x, pos_y, mySize_x * 0.5, mySize_y);
1880 drawpic(pos, "gfx/hud/voteprogress_voted", mySize, eX, a * hud_alpha_fg, DRAWFLAG_NORMAL);
1883 drawresetcliparea();
1885 else if(!vote_active) {
1886 vote_highlighted = 0;
1891 float race_status_time;
1892 float race_status_prev;
1893 string race_status_name_prev;
1894 void HUD_DrawRaceStatus(vector pos)
1896 if (race_status != race_status_prev || race_status_name != race_status_name_prev) {
1897 race_status_time = time + 5;
1898 race_status_prev = race_status;
1899 if (race_status_name_prev)
1900 strunzone(race_status_name_prev);
1901 race_status_name_prev = strzone(race_status_name);
1905 a = bound(0, race_status_time - time, 1);
1908 s = textShortenToWidth(race_status_name, 120, '10 10 0', stringwidth_colors);
1912 rank = race_CheckName(race_status_name);
1914 rankname = race_PlaceName(rank);
1916 if(race_status == 0)
1917 drawpic(pos, "gfx/hud/race/newfail", '80 80 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
1918 else if(race_status == 1) {
1919 drawpic(pos, "gfx/hud/race/newtime", '80 80 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
1920 drawcolorcodedstring(pos + '40 80 0' - eX * stringwidth(s, TRUE, '5 0 0'), s, '10 10 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
1921 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);
1922 } else if(race_status == 2) {
1923 if(race_status_name == GetPlayerName(player_localentnum -1) || !race_myrank || race_myrank < rank)
1924 drawpic(pos, "gfx/hud/race/newrankgreen", '80 80 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
1926 drawpic(pos, "gfx/hud/race/newrankyellow", '80 80 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
1927 drawcolorcodedstring(pos + '40 80 0' - eX * stringwidth(s, TRUE, '5 0 0'), s, '10 10 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
1928 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);
1929 } else if(race_status == 3) {
1930 drawpic(pos, "gfx/hud/race/newrecordserver", '80 80 0', '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
1931 drawcolorcodedstring(pos + '40 80 0' - eX * stringwidth(s, TRUE, '5 0 0'), s, '10 10 0', hud_alpha_fg * a, DRAWFLAG_NORMAL);
1932 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);
1935 if (race_status_time - time <= 0) {
1936 race_status_prev = -1;
1938 if(race_status_name)
1939 strunzone(race_status_name);
1940 race_status_name = string_null;
1941 if(race_status_name_prev)
1942 strunzone(race_status_name_prev);
1943 race_status_name_prev = string_null;
1947 // CTF HUD modicon section
1948 float redflag_prevframe, blueflag_prevframe; // status during previous frame
1949 float redflag_prevstatus, blueflag_prevstatus; // last remembered status
1950 float redflag_statuschange_time, blueflag_statuschange_time; // time when the status changed
1952 void CSQC_ctf_hudreset(void)
1954 redflag_prevstatus = blueflag_prevstatus = redflag_prevframe = blueflag_prevframe = redflag_statuschange_time = blueflag_statuschange_time = 0;
1957 void CSQC_ctf_hud(void)
1959 vector bottomleft, redflag_pos, blueflag_pos, sz;
1960 float f; // every function should have that
1961 bottomleft_y = vid_conheight;
1964 float redflag, blueflag; // current status
1965 float redflag_statuschange_elapsedtime, blueflag_statuschange_elapsedtime; // time since the status changed
1968 stat_items = getstati(STAT_ITEMS);
1969 redflag = (stat_items/IT_RED_FLAG_TAKEN) & 3;
1970 blueflag = (stat_items/IT_BLUE_FLAG_TAKEN) & 3;
1972 // when status CHANGES, set old status into prevstatus and current status into status
1973 if (redflag != redflag_prevframe)
1975 redflag_statuschange_time = time;
1976 redflag_prevstatus = redflag_prevframe;
1977 redflag_prevframe = redflag;
1980 if (blueflag != blueflag_prevframe)
1982 blueflag_statuschange_time = time;
1983 blueflag_prevstatus = blueflag_prevframe;
1984 blueflag_prevframe = blueflag;
1987 redflag_statuschange_elapsedtime = time - redflag_statuschange_time;
1988 blueflag_statuschange_elapsedtime = time - blueflag_statuschange_time;
1990 float BLINK_FACTOR = 0.15;
1991 float BLINK_BASE = 0.85;
1993 // RMS = sqrt(BLINK_BASE^2 + 0.5 * BLINK_FACTOR^2)
1995 // BLINK_BASE = sqrt(RMS^2 - 0.5 * BLINK_FACTOR^2)
1997 float BLINK_FREQ = 5; // circle frequency, = 2*pi*frequency in hertz
1999 string red_icon, red_icon_prevstatus;
2000 float red_alpha, red_alpha_prevstatus;
2001 red_alpha = red_alpha_prevstatus = 1;
2003 case 1: red_icon = "gfx/hud/sb_flag_red_taken"; break;
2004 case 2: red_icon = "gfx/hud/sb_flag_red_lost"; break;
2005 case 3: red_icon = "gfx/hud/sb_flag_red_carrying"; red_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
2007 if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM2))
2008 red_icon = "gfx/hud/sb_flag_red_shielded";
2010 red_icon = string_null;
2013 switch(redflag_prevstatus) {
2014 case 1: red_icon_prevstatus = "gfx/hud/sb_flag_red_taken"; break;
2015 case 2: red_icon_prevstatus = "gfx/hud/sb_flag_red_lost"; break;
2016 case 3: red_icon_prevstatus = "gfx/hud/sb_flag_red_carrying"; red_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
2019 red_icon_prevstatus = "gfx/hud/sb_flag_red_carrying"; // make it more visible
2020 else if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM2))
2021 red_icon_prevstatus = "gfx/hud/sb_flag_red_shielded";
2023 red_icon_prevstatus = string_null;
2027 string blue_icon, blue_icon_prevstatus;
2028 float blue_alpha, blue_alpha_prevstatus;
2029 blue_alpha = blue_alpha_prevstatus = 1;
2031 case 1: blue_icon = "gfx/hud/sb_flag_blue_taken"; break;
2032 case 2: blue_icon = "gfx/hud/sb_flag_blue_lost"; break;
2033 case 3: blue_icon = "gfx/hud/sb_flag_blue_carrying"; blue_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
2035 if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM1))
2036 blue_icon = "gfx/hud/sb_flag_blue_shielded";
2038 blue_icon = string_null;
2041 switch(blueflag_prevstatus) {
2042 case 1: blue_icon_prevstatus = "gfx/hud/sb_flag_blue_taken"; break;
2043 case 2: blue_icon_prevstatus = "gfx/hud/sb_flag_blue_lost"; break;
2044 case 3: blue_icon_prevstatus = "gfx/hud/sb_flag_blue_carrying"; blue_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
2047 blue_icon_prevstatus = "gfx/hud/sb_flag_blue_carrying"; // make it more visible
2048 else if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM1))
2049 blue_icon_prevstatus = "gfx/hud/sb_flag_blue_shielded";
2051 blue_icon_prevstatus = string_null;
2055 if (myteam == COLOR_TEAM1) { // always draw own flag on left
2056 redflag_pos = bottomleft - '-4 50 0';
2057 blueflag_pos = bottomleft - '-62 50 0';
2059 blueflag_pos = bottomleft - '-4 50 0';
2060 redflag_pos = bottomleft - '-62 50 0';
2065 f = bound(0, redflag_statuschange_elapsedtime*2, 1);
2066 if(red_icon_prevstatus && f < 1)
2067 drawpic_expanding(redflag_pos, red_icon_prevstatus, sz, '1 1 1', hud_alpha_fg * red_alpha_prevstatus, DRAWFLAG_NORMAL, f);
2069 drawpic(redflag_pos, red_icon, sz, '1 1 1', hud_alpha_fg * red_alpha * f, DRAWFLAG_NORMAL);
2071 f = bound(0, blueflag_statuschange_elapsedtime*2, 1);
2072 if(blue_icon_prevstatus && f < 1)
2073 drawpic_expanding(blueflag_pos, blue_icon_prevstatus, sz, '1 1 1', hud_alpha_fg * blue_alpha_prevstatus, DRAWFLAG_NORMAL, f);
2075 drawpic(blueflag_pos, blue_icon, sz, '1 1 1', hud_alpha_fg * blue_alpha * f, DRAWFLAG_NORMAL);
2078 /*void HUD_Mod_Race (void) {
2079 if((scores_flags[ps_primary] & SFL_TIME) && !teamplay) { // race/cts record display on HUD
2080 pl = players.sort_next;
2083 if(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)
2084 if(pl.scores[ps_primary] == 0)
2087 score = me.(scores[ps_primary]);
2089 float racemin, racesec, racemsec;
2090 float distsec, distmsec, minusplus;
2092 racemin = floor(score/(60 * TIME_FACTOR));
2093 racesec = floor((score - racemin*(60 * TIME_FACTOR))/TIME_FACTOR);
2094 racemsec = score - racemin*60*TIME_FACTOR - racesec*TIME_FACTOR;
2096 if (pl && ((!(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)) || score)) {
2097 // distribution display
2098 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
2100 if (distribution < TIME_FACTOR && distribution > -TIME_FACTOR)
2101 distmsec = fabs(distribution);
2103 distsec = floor(fabs(distribution)/TIME_FACTOR);
2104 distmsec = fabs(distribution) - distsec*TIME_FACTOR;
2105 if (distribution < 0)
2109 if (distribution <= 0) {
2110 distribution_color = eY;
2111 minusplus = 1; // minusplus 1: always prefix with minus sign
2114 distribution_color = eX;
2115 minusplus = 2; // minusplus 1: always prefix with plus sign
2117 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);
2118 HUD_DrawXNum(bottomright - '68 48 0' - '16 0 0' * TIME_DECIMALS, distsec, 4, minusplus, 16, distribution_color, 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
2119 drawpic(bottomright - '10 48 0' - '16 0 0' * TIME_DECIMALS, "gfx/hud/num_dot", '16 16 0', distribution_color, hud_alpha_fg, DRAWFLAG_ADDITIVE);
2121 // race record display
2122 if (distribution <= 0 || distribution == score) // draw the highlight background behind the timer if we have the lead
2123 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);
2125 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);
2126 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);
2127 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);
2129 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);
2130 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);
2134 // Keyhunt HUD modicon section
2135 float kh_runheretime;
2137 void CSQC_kh_hudreset(void)
2142 void CSQC_kh_hud(void)
2147 vector p, pa, kh_size, kh_asize;
2150 p_y = vid_conheight - 34 - 3;
2153 kh_keys = getstati(STAT_KH_KEYS);
2155 kh_size = '19 34 0';
2156 kh_asize = '19 10 0';
2163 for(i = 0; i < 4; ++i)
2165 key = floor(kh_keys / pow(32, i)) & 31;
2167 if(keyteam == 30 && keycount <= 4)
2169 if(keyteam == myteam || keyteam == -1 || keyteam == 30)
2172 // this yields 8 exactly if "RUN HERE" shows
2177 kh_runheretime = time;
2178 pa_y -= fabs(sin((time - kh_runheretime) * 3.5)) * 6; // make the arrows jump in case of RUN HERE
2183 for(i = 0; i < 4; ++i)
2185 key = floor(kh_keys / pow(32, i)) & 31;
2198 default: // owned or dropped
2203 a = a * hud_alpha_fg;
2204 aa = aa * hud_alpha_fg;
2210 drawpic (pa, "gfx/hud/sb_kh_redarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
2213 drawpic (pa, "gfx/hud/sb_kh_bluearrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
2216 drawpic (pa, "gfx/hud/sb_kh_yellowarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
2219 drawpic (pa, "gfx/hud/sb_kh_pinkarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
2224 switch(i) // YAY! switch(i) inside a for loop for i. DailyWTF, here we come!
2227 drawpic (p, "gfx/hud/sb_kh_red", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
2230 drawpic (p, "gfx/hud/sb_kh_blue", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
2233 drawpic (p, "gfx/hud/sb_kh_yellow", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
2236 drawpic (p, "gfx/hud/sb_kh_pink", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
2245 // Nexball HUD modicon section
2246 #define NBPB_SIZE '96 38 0'
2247 #define NBPB_BT 2 //thickness
2248 #define NBPB_BRGB '1 1 1'
2249 #define NBPB_BALPH 1 //alpha
2250 #define NBPB_BFLAG DRAWFLAG_NORMAL
2251 #define NBPB_IALPH 0.4
2252 #define NBPB_IFLAG DRAWFLAG_NORMAL
2253 #define NBPB_IRGB '0.7 0.1 0'
2255 void CSQC_nb_hud(void)
2257 float stat_items, nb_pb_starttime, dt, p;
2260 stat_items = getstati(STAT_ITEMS);
2261 nb_pb_starttime = getstatf(STAT_NB_METERSTART);
2264 pos_y = vid_conheight - 42;
2267 //Manage the progress bar if any
2268 if (nb_pb_starttime > 0)
2271 dt = mod(time - nb_pb_starttime, nb_pb_period);
2272 // one period of positive triangle
2273 p = 2 * dt / nb_pb_period;
2279 drawfill(pos, p * s_x * eX + s_y * eY, NBPB_IRGB, NBPB_IALPH, NBPB_IFLAG);
2283 drawline(NBPB_BT, pos , pos + eX * s_x, NBPB_BRGB, NBPB_BALPH, NBPB_BFLAG);
2284 drawline(NBPB_BT, pos , pos + eY * s_y, NBPB_BRGB, NBPB_BALPH, NBPB_BFLAG);
2285 drawline(NBPB_BT, pos + s, pos + eX * s_x, NBPB_BRGB, NBPB_BALPH, NBPB_BFLAG);
2286 drawline(NBPB_BT, pos + s, pos + eY * s_y, NBPB_BRGB, NBPB_BALPH, NBPB_BFLAG);
2289 pos_x += 12; //horizontal margin to the picture
2290 pos_y += 2; //vertical margin to the picture
2292 if (stat_items & IT_KEY1)
2293 drawpic(pos, "gfx/hud/sb_nexball_carrying", '80 34 0', '1 1 1', 1, DRAWFLAG_NORMAL);
2296 // Race/CTS HUD modicon section
2297 float crecordtime_prev; // last remembered crecordtime
2298 float crecordtime_change_time; // time when crecordtime last changed
2299 float srecordtime_prev; // last remembered srecordtime
2300 float srecordtime_change_time; // time when srecordtime last changed
2301 void CSQC_race_hud(void)
2304 me = playerslots[player_localentnum - 1];
2306 float f; // yet another function has this
2307 score = me.(scores[ps_primary]);
2309 if not((scores_flags[ps_primary] & SFL_TIME) && !teamplay) // race/cts record display on HUD
2310 return; // no records in the actual race
2312 drawfont = hud_bigfont;
2315 pos_y = vid_conheight - 48;
2317 // clientside personal record
2319 if(gametype == GAME_CTS)
2323 t = stof(db_get(ClientProgsDB, strcat(shortmapname, rr, "time")));
2325 if(score && (score < t || !t)) {
2326 db_put(ClientProgsDB, strcat(shortmapname, rr, "time"), ftos(score));
2327 if(cvar("cl_autodemo_delete_keeprecords"))
2329 f = cvar("cl_autodemo_delete");
2331 cvar_set("cl_autodemo_delete", ftos(f)); // don't delete demo with new record!
2335 if(t != crecordtime_prev) {
2336 crecordtime_prev = t;
2337 crecordtime_change_time = time;
2339 f = time - crecordtime_change_time;
2342 drawstring(pos, "Personal best ", '10 10 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2343 drawstring(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2345 drawstring(pos, "Personal best ", '10 10 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2346 drawstring(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2347 drawstring_expanding(pos, "Personal best ", '10 10 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL, f);
2348 drawstring_expanding(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL, f);
2353 t = race_server_record;
2354 if(t != srecordtime_prev) {
2355 srecordtime_prev = t;
2356 srecordtime_change_time = time;
2358 f = time - srecordtime_change_time;
2361 drawstring(pos, "Server best ", '10 10 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2362 drawstring(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2364 drawstring(pos, "Server best ", '10 10 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2365 drawstring(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2366 drawstring_expanding(pos, "Server best ", '10 10 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL, f);
2367 drawstring_expanding(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL, f);
2369 drawfont = hud_font;
2378 vector pos, mySize, color;
2379 marigin = HUD_Panel_GetMarigin(5);
2380 pos = HUD_Panel_GetPos(5);
2381 mySize = HUD_Panel_GetSize(5);
2382 color = HUD_Panel_GetColor(5);
2384 if(HUD_Panel_GetBgActive(5))
2385 draw_BorderPicture(pos - '1 1 0' * marigin, "gfx/hud/border", mySize + '1 1 0' * 2 * marigin, color, hud_alpha_bg, '1 1 0' * (marigin/MARIGIN_MULTIPLIER));
2387 float timelimit, elapsedTime, minutes, seconds, timeleft, minutesLeft, secondsLeft;
2389 timelimit = getstatf(STAT_TIMELIMIT);
2391 HUD_DrawRaceStatus(pos + '0 30 0');
2393 timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
2394 timeleft = ceil(timeleft);
2395 minutesLeft = floor(timeleft / 60);
2396 secondsLeft = timeleft - minutesLeft*60;
2399 if(minutesLeft >= 5 || warmup_stage || timelimit == 0) //don't use red or yellow in warmup or when there is no timelimit
2400 timer_color = '1 1 1'; //white
2401 else if(minutesLeft >= 1)
2402 timer_color = '1 1 0'; //yellow
2404 timer_color = '1 0 0'; //red
2406 if (cvar("hud_timer_increment") || timelimit == 0 || warmup_stage) {
2407 if (time < getstatf(STAT_GAMESTARTTIME)) {
2408 //while restart is still active, show 00:00
2409 minutes = seconds = 0;
2411 elapsedTime = floor(time - getstatf(STAT_GAMESTARTTIME)); //127
2412 minutes = floor(elapsedTime / 60);
2413 seconds = elapsedTime - minutes*60;
2416 minutes = minutesLeft;
2417 seconds = secondsLeft;
2420 if(mySize_x/mySize_y > 5.1)
2424 minutes = min(minutes, 999);
2425 if(minutesLeft >= 1 || cvar("hud_timer_increment") || timelimit == 0 || warmup_stage) {
2427 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);
2428 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);
2429 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);
2431 HUD_DrawXNum(pos + eX * mySize_x - eX * 2 * mySize_y, seconds, -2, 0, mySize_y, timer_color, 0, 0, hud_alpha_fg, DRAWFLAG_NORMAL);
2437 minutes = min(minutes, 99);
2438 if(minutesLeft >= 1 || cvar("hud_timer_increment") || timelimit == 0 || warmup_stage) {
2440 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);
2441 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);
2442 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);
2444 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);
2451 void HUD_Radar(void)
2455 vector pos, mySize, color;
2456 marigin = HUD_Panel_GetMarigin(6);
2457 pos = HUD_Panel_GetPos(6);
2458 mySize = HUD_Panel_GetSize(6);
2459 color = HUD_Panel_GetColor(6);
2461 if(HUD_Panel_GetBgActive(6))
2462 draw_BorderPicture(pos - '1 1 0' * marigin, "gfx/hud/border", mySize + '1 1 0' * 2 * marigin, color, hud_alpha_bg, '1 1 0' * (marigin/MARIGIN_MULTIPLIER));
2464 local float color1, color2; // color already declared as a global in hud.qc
2467 float scale2d, normalsize, bigsize;
2470 teamradar_origin2d = pos + 0.5 * mySize; // TODO: stupid compat, should be removed
2471 teamradar_size2d = mySize;
2473 if(minimapname == "" && !ons_showmap)
2476 teamradar_loadcvars();
2478 switch(cl_teamradar_zoommode)
2482 f = current_zoomfraction;
2485 f = 1 - current_zoomfraction;
2495 switch(cl_teamradar_rotation)
2498 teamradar_angle = view_angles_y - 90;
2501 teamradar_angle = 90 * cl_teamradar_rotation;
2505 scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
2506 teamradar_size2d = mySize;
2508 teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0';
2509 if(pos == eX * vid_conwidth)
2511 if(cl_teamradar_nohudhack < 2)
2513 if(cl_teamradar_nohudhack < 1)
2514 teamradar_extraclip_mins_y -= 25;
2516 else if(pos == eY * vid_conheight || pos == eX * vid_conwidth + eY * vid_conheight)
2518 if(cl_teamradar_nohudhack < 2)
2520 //if(cl_teamradar_nohudhack < 1)
2521 //teamradar_extraclip_size_y += 50; // don't, the HUD looks nice
2524 // pixels per world qu to match the teamradar_size2d_x range in the longest dimension
2525 if(cl_teamradar_rotation == 0)
2527 // max-min distance must fit the radar in any rotation
2528 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen2d(mi_max - mi_min));
2532 vector c0, c1, c2, c3, span;
2533 c0 = rotate(mi_min, teamradar_angle * DEG2RAD);
2534 c1 = rotate(mi_max, teamradar_angle * DEG2RAD);
2535 c2 = rotate('1 0 0' * mi_min_x + '0 1 0' * mi_max_y, teamradar_angle * DEG2RAD);
2536 c3 = rotate('1 0 0' * mi_max_x + '0 1 0' * mi_min_y, teamradar_angle * DEG2RAD);
2538 span_x = max4(c0_x, c1_x, c2_x, c3_x) - min4(c0_x, c1_x, c2_x, c3_x);
2539 span_y = max4(c0_y, c1_y, c2_y, c3_y) - min4(c0_y, c1_y, c2_y, c3_y);
2541 // max-min distance must fit the radar in x=x, y=y
2543 teamradar_size2d_x * scale2d / (1.05 * span_x),
2544 teamradar_size2d_y * scale2d / (1.05 * span_y)
2548 normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / cl_teamradar_scale;
2549 if(bigsize > normalsize)
2550 normalsize = bigsize;
2554 + (1 - f) * normalsize;
2555 teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
2556 f * (mi_min + mi_max) * 0.5
2557 + (1 - f) * view_origin);
2559 color1 = GetPlayerColor(player_localentnum-1);
2560 rgb = GetTeamRGB(color1);
2569 draw_teamradar_background(cl_teamradar_background_alpha, cl_teamradar_foreground_alpha);
2573 drawresetcliparea();
2575 vector frame_origin, frame_size;
2576 frame_origin = frame_size = '0 0 0';
2578 frame_origin_x = pos_x - teamradar_size2d_x * 0.55859375; // matches the picture
2579 frame_origin_y = pos_y - teamradar_size2d_y * 0.55859375; // matches the picture
2580 frame_size_x = pos_x * 1.1171875; // matches the picture
2581 frame_size_y = pos_y * 1.1171875; // matches the picture
2582 drawpic(frame_origin, "gfx/ons-frame.tga", frame_size, '1 1 1', hud_alpha_fg, 0);
2583 drawpic(frame_origin, "gfx/ons-frame-team.tga", frame_size, rgb, hud_alpha_fg, 0);
2586 pos_x - teamradar_size2d_x * 0.5,
2587 pos_y - teamradar_size2d_y * 0.5,
2593 for(tm = world; (tm = find(tm, classname, "radarlink")); )
2594 draw_teamradar_link(tm.origin, tm.velocity, tm.team);
2595 for(tm = world; (tm = findflags(tm, teamradar_icon, 0xFFFFFF)); )
2596 draw_teamradar_icon(tm.origin, tm.teamradar_icon, tm, tm.teamradar_color, hud_alpha_fg);
2597 for(tm = world; (tm = find(tm, classname, "entcs_receiver")); )
2599 color2 = GetPlayerColor(tm.sv_entnum);
2600 //if(color == COLOR_SPECTATOR || color == color2)
2601 draw_teamradar_player(tm.origin, tm.angles, GetTeamRGB(color2));
2603 draw_teamradar_player(view_origin, view_angles, '1 1 1');
2605 drawresetcliparea();
2614 void HUD_DrawPressedKeys(void)
2618 vector pos, mySize, color;
2619 marigin = HUD_Panel_GetMarigin(10);
2620 pos = HUD_Panel_GetPos(10);
2621 mySize = HUD_Panel_GetSize(10);
2622 color = HUD_Panel_GetColor(10);
2624 if(HUD_Panel_GetBgActive(10))
2625 draw_BorderPicture(pos - '1 1 0' * marigin, "gfx/hud/border", mySize + '1 1 0' * 2 * marigin, color, hud_alpha_bg, '1 1 0' * (marigin/MARIGIN_MULTIPLIER));
2629 pressedkeys = getstatf(STAT_PRESSED_KEYS);
2630 drawpic(pos, "gfx/hud/keys/key_bg.tga", mySize, '1 1 1', 0.1 * hud_alpha_fg, DRAWFLAG_NORMAL);
2631 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);
2632 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);
2633 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);
2634 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);
2635 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);
2636 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);
2639 void HUD_ShowSpeed(void)
2642 float pos, conversion_factor;
2643 string speed, zspeed, unit;
2645 switch(cvar("cl_showspeed_unit"))
2650 conversion_factor = 1.0;
2654 conversion_factor = 1.0;
2658 conversion_factor = 0.0254;
2662 conversion_factor = 0.0254 * 3.6;
2666 conversion_factor = 0.0254 * 3.6 * 0.6213711922;
2670 conversion_factor = 0.0254 * 1.943844492; // 1 m/s = 1.943844492 knots, because 1 knot = 1.852 km/h
2674 speed = strcat(ftos(floor( vlen(pmove_vel - pmove_vel_z * '0 0 1') * conversion_factor + 0.5 )), unit);
2676 numsize_x = numsize_y = cvar("cl_showspeed_size");
2677 pos = (vid_conheight - numsize_y) * cvar("cl_showspeed_position");
2679 drawfont = hud_bigfont;
2680 drawstringcenter(eX + pos * eY, speed, numsize, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2682 if (cvar("cl_showspeed_z") == 1) {
2683 zspeed = strcat(ftos(fabs(floor( pmove_vel_z * conversion_factor + 0.5 ))), unit);
2684 drawstringcenter(eX + pos * eY + numsize_y * eY, zspeed, numsize * 0.5, '1 1 1', hud_alpha_fg, DRAWFLAG_NORMAL);
2687 drawfont = hud_font;
2690 vector acc_prevspeed;
2694 void HUD_ShowAcceleration(void)
2696 float acceleration, sz, scale, alpha, f;
2697 vector pos, top, rgb;
2698 top_x = vid_conwidth/2;
2701 f = time - acc_prevtime;
2702 if(cvar("cl_showacceleration_z"))
2703 acceleration = (vlen(pmove_vel) - vlen(acc_prevspeed)) * (1 / f);
2705 acceleration = (vlen(pmove_vel - '0 0 1' * pmove_vel_z) - vlen(acc_prevspeed - '0 0 1' * acc_prevspeed_z)) * (1 / f);
2706 acc_prevspeed = pmove_vel;
2707 acc_prevtime = time;
2709 f = bound(0, f * 10, 1);
2710 acc_avg = acc_avg * (1 - f) + acceleration * f;
2711 acceleration = acc_avg / getstatf(STAT_MOVEVARS_MAXSPEED);
2713 pos = top - sz/2 * eY + (cvar("cl_showacceleration_position") * vid_conheight) * eY;
2715 sz = cvar("cl_showacceleration_size");
2716 scale = cvar("cl_showacceleration_scale");
2717 alpha = cvar("cl_showacceleration_alpha");
2718 if (cvar("cl_showacceleration_color_custom"))
2719 rgb = stov(cvar_string("cl_showacceleration_color"));
2722 if (acceleration < 0) {
2723 rgb = '1 .5 .5' - '0 .5 .5' * bound(0, -acceleration * 0.2, 1);
2724 } else if (acceleration > 0) {
2725 rgb = '.5 1 .5' - '.5 0 .5' * bound(0, +acceleration * 0.2, 1);
2729 if (acceleration > 0)
2730 drawpic(pos, "gfx/hud/statusbar", acceleration * scale * '40 0 0' + sz * eY, rgb, alpha * hud_alpha_fg, DRAWFLAG_NORMAL);
2731 else if (acceleration < 0)
2732 drawpic(pos + acceleration * scale * '40 0 0', "gfx/hud/statusbar", -acceleration * scale * '40 0 0' + sz * eY, rgb, alpha * hud_alpha_fg, DRAWFLAG_NORMAL);
2735 void HUD_Reset (void)
2737 // reset gametype specific icons
2738 if(gametype == GAME_KEYHUNT)
2740 else if(gametype == GAME_CTF)
2741 CSQC_ctf_hudreset();
2744 void HUD_Main (void)
2746 hud_alpha_bg = cvar_or("hud_alpha_bg", 0.8) * (1 - cvar("_menu_alpha"));
2747 hud_border_thickness = bound(0, cvar("hud_border_thickness"), 5);
2748 hud_accuracy_border_thickness = bound(0, cvar_or("hud_accuracy_border_thickness", 1), 5);
2749 hud_color_bg_team = cvar("hud_color_bg_team");
2751 hud_fontsize = HUD_GetFontsize("hud_fontsize");
2752 hud_fontsize_spec = HUD_GetFontsize("hud_fontsize_spec");
2754 if(HUD_Panel_CheckActive(0))
2756 if(HUD_Panel_CheckActive(1))
2758 if(HUD_Panel_CheckActive(2))
2760 if(HUD_Panel_CheckActive(3))
2762 if(HUD_Panel_CheckActive(4))
2764 if(HUD_Panel_CheckActive(5))
2767 if(HUD_Panel_CheckActive(6))
2768 if(ons_showmap || cvar_string("cl_teamradar") != "0" && (cvar("cl_teamradar") == 2 || teamplay))
2770 if(HUD_Panel_CheckActive(7))
2772 if(HUD_Panel_CheckActive(8))
2773 if(gametype == GAME_RACE || gametype == GAME_CTS || cvar("_hud_configure"))
2775 if(HUD_Panel_CheckActive(9))
2778 if(HUD_Panel_CheckActive(10))
2779 if(spectatee_status > 0 || cvar("cl_showpressedkeys") >= 2 || cvar("_hud_configure"))
2780 HUD_DrawPressedKeys();
2782 // TODO hud_'ify these
2783 if (cvar("cl_showspeed"))
2785 if (cvar("cl_showacceleration"))
2786 HUD_ShowAcceleration();
2788 // TODO... well make them work in a panel etc
2789 if(gametype == GAME_KEYHUNT)
2791 else if(gametype == GAME_CTF)
2793 else if(gametype == GAME_NEXBALL)
2795 else if(gametype == GAME_CTS || gametype == GAME_RACE)