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)
17 if (theBorderSize_x <= 0 && theBorderSize_y <= 0) // no border
19 // draw only the central part
20 drawsubpic(theOrigin, theSize, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0);
27 //pic = draw_UseSkinFor(pic);
28 width = eX * theSize_x;
29 height = eY * theSize_y;
30 if(theSize_x <= theBorderSize_x * 2)
32 // not wide enough... draw just left and right then
33 bW = eX * (0.25 * theSize_x / (theBorderSize_x * 2));
34 if(theSize_y <= theBorderSize_y * 2)
36 // not high enough... draw just corners
37 bH = eY * (0.25 * theSize_y / (theBorderSize_y * 2));
38 drawsubpic(theOrigin, width * 0.5 + height * 0.5, pic, '0 0 0', bW + bH, theColor, theAlpha, 0);
39 drawsubpic(theOrigin + width * 0.5, width * 0.5 + height * 0.5, pic, eX - bW, bW + bH, theColor, theAlpha, 0);
40 drawsubpic(theOrigin + height * 0.5, width * 0.5 + height * 0.5, pic, eY - bH, bW + bH, theColor, theAlpha, 0);
41 drawsubpic(theOrigin + theSize * 0.5, width * 0.5 + height * 0.5, pic, eX + eY - bW - bH, bW + bH, theColor, theAlpha, 0);
45 dY = theBorderSize_x * eY;
46 drawsubpic(theOrigin, width * 0.5 + dY, pic, '0 0 0', '0 0.25 0' + bW, theColor, theAlpha, 0);
47 drawsubpic(theOrigin + width * 0.5, width * 0.5 + dY, pic, '0 0 0' + eX - bW, '0 0.25 0' + bW, theColor, theAlpha, 0);
48 drawsubpic(theOrigin + dY, width * 0.5 + height - 2 * dY, pic, '0 0.25 0', '0 0.5 0' + bW, theColor, theAlpha, 0);
49 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);
50 drawsubpic(theOrigin + height - dY, width * 0.5 + dY, pic, '0 0.75 0', '0 0.25 0' + bW, theColor, theAlpha, 0);
51 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);
56 if(theSize_y <= theBorderSize_y * 2)
58 // not high enough... draw just top and bottom then
59 bH = eY * (0.25 * theSize_y / (theBorderSize_y * 2));
60 dX = theBorderSize_x * eX;
61 drawsubpic(theOrigin, dX + height * 0.5, pic, '0 0 0', '0.25 0 0' + bH, theColor, theAlpha, 0);
62 drawsubpic(theOrigin + dX, width - 2 * dX + height * 0.5, pic, '0.25 0 0', '0.5 0 0' + bH, theColor, theAlpha, 0);
63 drawsubpic(theOrigin + width - dX, dX + height * 0.5, pic, '0.75 0 0', '0.25 0 0' + bH, theColor, theAlpha, 0);
64 drawsubpic(theOrigin + height * 0.5, dX + height * 0.5, pic, '0 0 0' + eY - bH, '0.25 0 0' + bH, theColor, theAlpha, 0);
65 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);
66 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);
70 dX = theBorderSize_x * eX;
71 dY = theBorderSize_x * eY;
72 drawsubpic(theOrigin, dX + dY, pic, '0 0 0', '0.25 0.25 0', theColor, theAlpha, 0);
73 drawsubpic(theOrigin + dX, width - 2 * dX + dY, pic, '0.25 0 0', '0.5 0.25 0', theColor, theAlpha, 0);
74 drawsubpic(theOrigin + width - dX, dX + dY, pic, '0.75 0 0', '0.25 0.25 0', theColor, theAlpha, 0);
75 drawsubpic(theOrigin + dY, dX + height - 2 * dY, pic, '0 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0);
76 drawsubpic(theOrigin + dY + dX, width - 2 * dX + height - 2 * dY, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0);
77 drawsubpic(theOrigin + dY + width - dX, dX + height - 2 * dY, pic, '0.75 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0);
78 drawsubpic(theOrigin + height - dY, dX + dY, pic, '0 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
79 drawsubpic(theOrigin + height - dY + dX, width - 2 * dX + dY, pic, '0.25 0.75 0', '0.5 0.25 0', theColor, theAlpha, 0);
80 drawsubpic(theOrigin + height - dY + width - dX, dX + dY, pic, '0.75 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
85 // drawpic wrapper to draw an image as large as possible with preserved aspect ratio into a box
86 void drawpic_aspect(vector pos, string pic, vector sz, vector color, float alpha, float drawflag) {
88 imgsize = drawgetimagesize(pic);
90 imgaspect = imgsize_x/imgsize_y;
97 if(aspect > imgaspect) {
98 sz_x = sz_y * imgaspect;
99 drawpic(pos + eX * (oldsz_x - sz_x) * 0.5, pic, sz, color, alpha, drawflag);
101 sz_y = sz_x / imgaspect;
102 drawpic(pos + eY * (oldsz_y - sz_y) * 0.5, pic, sz, color, alpha, drawflag);
106 // draw HUD element with image from gfx/hud/hud_skin/foo.tga if it exists, otherwise gfx/hud/default/foo.tga
107 void drawpic_skin(vector pos, string pic, vector sz, vector color, float alpha, float drawflag) {
108 drawpic_aspect(pos, strcat("gfx/hud/", cvar_string("hud_skin"), "/", pic), sz, color, alpha, drawflag);
112 void drawpic_skin_expanding(vector pos, string pic, vector sz, vector rgb, float alpha, float flag, float fadelerp) {
113 drawpic_expanding(pos, strcat("gfx/hud/", cvar_string("hud_skin"), "/", pic), sz, rgb, alpha, flag, fadelerp);
116 void drawpic_skin_expanding_two(vector pos, string pic, vector sz, vector rgb, float alpha, float flag, float fadelerp) {
117 drawpic_expanding_two(pos, strcat("gfx/hud/", cvar_string("hud_skin"), "/", pic), sz, rgb, alpha, flag, fadelerp);
120 // return HUD background color
121 vector HUD_GetBgColor()
125 GetTeamRGB(myteam) * hud_color_bg_team;
127 // allow custom HUD colors in non-teamgames
128 color_x = cvar("hud_color_bg_r");
129 color_y = cvar("hud_color_bg_g");
130 color_z = cvar("hud_color_bg_b");
135 // return accuracy text color
136 vector HUD_AccuracyColor(float accuracy)
139 float yellow_accuracy = cvar("hud_weaponicons_accuracy_yellow"); // value at which this function returns yellow
140 if(accuracy >= 100) {
144 else if(accuracy > yellow_accuracy) {
145 rgb_x = 1 - (accuracy-yellow_accuracy)/(100-yellow_accuracy); // red value between 1 -> 0
150 rgb_y = accuracy/yellow_accuracy; // green value between 0 -> 1
156 // draw number in the XSCALE font
157 void HUD_DrawXNum (vector pos, float num, float digits, float showsign, float lettersize, vector rgb, float highlighted, float stroke, float alpha, float dflags)
160 string str, tmp, l_length;
162 vector vsize, num_color;
164 vsize_x = vsize_y = lettersize;
167 // showsign 1: always prefix with minus sign (useful in race distribution display)
168 // showsign 2: always prefix with plus sign (useful in race distribution display)
169 // showsign 3: prefix with minus sign if negative, plus sign if positive (useful in score distribution display)
171 if((showsign == 2 && num >= 0) || (num > 0 && showsign == 3))
178 if(num < 0 || (num < 0 && showsign == 3) || (showsign == 1 && num <= 0))
190 str = strcat(substring("0000000000", 0, digits - strlen(tmp)), tmp);
199 str = substring(str, l-digits, 999);
201 } else if(l < digits)
202 pos_x += (digits-l) * lettersize;
204 if (highlighted == 1) {
206 hl_size_x = vsize_x * l + vsize_x * 0.2;
207 hl_size_y = vsize_y * 1.1;
210 hl_size_x = hl_size_x + vsize_x;
213 hl_pos_x = pos_x - lettersize/10;
214 hl_pos_y = pos_y - lettersize/20;
217 drawpic_skin(hl_pos, strcat("num_leading_", l_length), hl_size, '1 1 1', alpha, dflags);
228 drawpic_skin(pos, "num_minus_stroke", vsize, rgb, alpha, dflags);
229 drawpic_skin(pos, "num_minus", vsize, num_color, alpha, dflags);
234 drawpic_skin(pos, "num_plus_stroke", vsize, rgb, alpha, dflags);
235 drawpic_skin(pos, "num_plus", vsize, num_color, alpha, dflags);
239 for(i = 0; i < l; ++i)
241 tmp = substring(str, i, 1);
243 drawpic_skin(pos, strcat("num_", tmp, "_stroke"), vsize, rgb, alpha, dflags);
244 drawpic_skin(pos, strcat("num_", tmp), vsize, num_color, alpha, dflags);
249 vector HUD_Get_Num_Color (float x, float maxvalue)
257 else if(x > maxvalue * 0.75) {
258 color_x = 0.4 - (x-150)*0.02 * 0.4; //red value between 0.4 -> 0
259 color_y = 0.9 + (x-150)*0.02 * 0.1; // green value between 0.9 -> 1
262 else if(x > maxvalue * 0.5) {
263 color_x = 1 - (x-100)*0.02 * 0.6; //red value between 1 -> 0.4
264 color_y = 1 - (x-100)*0.02 * 0.1; // green value between 1 -> 0.9
265 color_z = 1 - (x-100)*0.02; // blue value between 1 -> 0
267 else if(x > maxvalue * 0.25) {
270 color_z = 0.2 + (x-50)*0.02 * 0.8; // blue value between 0.2 -> 1
272 else if(x > maxvalue * 0.1) {
274 color_y = (x-20)*90/27/100; // green value between 0 -> 1
275 color_z = (x-20)*90/27/100 * 0.2; // blue value between 0 -> 0.2
284 // color the number differently based on how big it is (used in the health/armor panel)
285 void HUD_DrawXNum_Colored (vector pos, float x, float digits, float lettersize, float alpha)
288 color = HUD_Get_Num_Color (x, 200);
289 HUD_DrawXNum(pos, x, digits, 0, lettersize, color, 0, 0, alpha, DRAWFLAG_NORMAL);
292 float stringwidth_colors(string s, vector theSize)
294 return stringwidth(s, TRUE, theSize);
297 float stringwidth_nocolors(string s, vector theSize)
299 return stringwidth(s, FALSE, theSize);
302 #define CENTERPRINT_MAX_LINES 30
303 string centerprint_messages[CENTERPRINT_MAX_LINES];
304 float centerprint_width[CENTERPRINT_MAX_LINES];
305 vector centerprint_start;
306 float centerprint_expire;
307 float centerprint_num;
308 float centerprint_offset_hint;
309 vector centerprint_fontsize;
311 void centerprint(string strMessage)
313 float i, j, n, hcount;
316 centerprint_fontsize = HUD_GetFontsize("scr_centersize");
318 centerprint_expire = min(centerprint_expire, time); // if any of the returns happens, this message will fade out
320 if(cvar("scr_centertime") <= 0)
326 // strip trailing newlines
327 j = strlen(strMessage) - 1;
328 while(substring(strMessage, j, 1) == "\n" && j >= 0)
330 strMessage = substring(strMessage, 0, j + 1);
335 // strip leading newlines and remember them, they are a hint that the message should be lower on the screen
337 while(substring(strMessage, j, 1) == "\n" && j < strlen(strMessage))
339 strMessage = substring(strMessage, j, strlen(strMessage) - j);
340 centerprint_offset_hint = j;
345 // if we get here, we have a message. Initialize its height.
348 n = tokenizebyseparator(strMessage, "\n");
350 for(j = 0; j < n; ++j)
352 getWrappedLine_remaining = argv(j);
353 while(getWrappedLine_remaining)
355 s = getWrappedLine(vid_conwidth * 0.75, centerprint_fontsize, stringwidth_colors);
356 if(centerprint_messages[i])
357 strunzone(centerprint_messages[i]);
358 centerprint_messages[i] = strzone(s);
359 centerprint_width[i] = stringwidth(s, TRUE, centerprint_fontsize);
362 // half height for empty lines looks better
368 if(i >= CENTERPRINT_MAX_LINES)
374 h = centerprint_fontsize_y*hcount;
376 havail = vid_conheight;
377 if(cvar("con_chatpos") < 0)
378 havail -= (-cvar("con_chatpos") + cvar("con_chat")) * cvar("con_chatsize"); // avoid overlapping chat
379 if(havail > vid_conheight - 70)
380 havail = vid_conheight - 70; // avoid overlapping HUD
382 centerprint_start_x = 0;
385 float forbiddenmin, forbiddenmax, allowedmin, allowedmax, preferred;
387 // here, the centerprint would cover the crosshair. REALLY BAD.
388 forbiddenmin = vid_conheight * 0.5 - h - 16;
389 forbiddenmax = vid_conheight * 0.5 + 16;
391 allowedmin = scoreboard_bottom;
392 allowedmax = havail - h;
393 preferred = (havail - h)/2;
396 // possible orderings (total: 4! / 4 = 6)
397 // allowedmin allowedmax forbiddenmin forbiddenmax
398 // forbiddenmin forbiddenmax allowedmin allowedmax
399 if(allowedmax < forbiddenmin || allowedmin > forbiddenmax)
401 // forbidden doesn't matter in this case
402 centerprint_start_y = bound(allowedmin, preferred, allowedmax);
404 // allowedmin forbiddenmin allowedmax forbiddenmax
405 else if(allowedmin < forbiddenmin && allowedmax < forbiddenmax)
407 centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
409 // allowedmin forbiddenmin forbiddenmax allowedmax
410 else if(allowedmin < forbiddenmin)
412 // make sure the forbidden zone is not covered
413 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
414 centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
416 centerprint_start_y = bound(forbiddenmax, preferred, allowedmin);
418 // forbiddenmin allowedmin allowedmax forbiddenmax
419 else if(allowedmax < forbiddenmax)
421 // it's better to leave the allowed zone (overlap with scoreboard) than
422 // to cover the forbidden zone (crosshair)
423 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
424 centerprint_start_y = forbiddenmax;
426 centerprint_start_y = forbiddenmin;
428 // forbiddenmin allowedmin forbiddenmax allowedmax
431 centerprint_start_y = bound(forbiddenmax, preferred, allowedmax);
434 centerprint_start_y =
437 max(scoreboard_bottom, vid_conheight * 0.5 + 16),
445 centerprint_expire = time + cvar("scr_centertime");
448 void HUD_DrawCenterPrint (void)
455 //if(time > centerprint_expire)
458 //a = bound(0, 1 - 2 * (time - centerprint_expire), 1);
459 a = bound(0, 1 - 4 * (time - centerprint_expire), 1);
460 //sz = 1.2 / (a + 0.2);
465 pos = centerprint_start;
466 for (i=0; i<centerprint_num; i = i + 1)
468 pos_x = (vid_conwidth - centerprint_width[i]) * 0.5;
469 ts = centerprint_messages[i];
472 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
473 drawcolorcodedstring(pos, ts, centerprint_fontsize, a, DRAWFLAG_NORMAL);
474 // - '0 0.5 0' * (sz - 1) * centerprint_fontsize_x - '0.5 0 0' * (sz - 1) * centerprint_width[i] * centerprint_fontsize_y, centerprint_fontsize * sz
475 pos_y = pos_y + centerprint_fontsize_y;
478 // half height for empty lines looks better
479 pos_y = pos_y + centerprint_fontsize_y * 0.5;
483 void drawstringright(vector position, string text, vector scale, vector rgb, float alpha, float flag)
485 position_x -= 2 / 3 * strlen(text) * scale_x;
486 drawstring(position, text, scale, rgb, alpha, flag);
489 void drawstringcenter(vector position, string text, vector scale, vector rgb, float alpha, float flag)
491 position_x = 0.5 * (vid_conwidth - 0.6025 * strlen(text) * scale_x);
492 drawstring(position, text, scale, rgb, alpha, flag);
495 // return the string of the given race place
496 string race_PlaceName(float pos) {
504 return strcat(ftos(pos), "th");
507 // return the string of the onscreen race timer
508 string MakeRaceString(float cp, float mytime, float histime, float lapdelta, string hisname)
516 if(histime == 0) // goal hit
520 timestr = strcat("+", ftos_decimals(+mytime, TIME_DECIMALS));
530 timestr = strcat("-", ftos_decimals(-mytime, TIME_DECIMALS));
536 lapstr = strcat(" (-", ftos(lapdelta), "L)");
539 else if(lapdelta < 0)
541 lapstr = strcat(" (+", ftos(-lapdelta), "L)");
545 else if(histime > 0) // anticipation
547 if(mytime >= histime)
548 timestr = strcat("+", ftos_decimals(mytime - histime, TIME_DECIMALS));
550 timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(histime));
557 cpname = "Start line";
559 cpname = "Finish line";
561 cpname = strcat("Intermediate ", ftos(cp));
563 cpname = "Finish line";
566 return strcat(col, cpname);
567 else if(hisname == "")
568 return strcat(col, cpname, " (", timestr, ")");
570 return strcat(col, cpname, " (", timestr, " ", strcat(hisname, col, lapstr), ")");
573 // Check if the given name already exist in race rankings? In that case, where? (otherwise return 0)
574 float race_CheckName(string net_name) {
576 for (i=RANKINGS_CNT-1;i>=0;--i)
577 if(grecordholder[i] == net_name)
589 void HUD_Panel_ExportCfg(string cfgname)
592 fh = fopen(strcat("hud_", cvar_string("hud_skin"), "_", cfgname, ".cfg"), FILE_WRITE);
595 fputs(fh, strcat("seta hud_skin \"", cvar_string("hud_skin"), "\"", "\n"));
596 fputs(fh, strcat("seta hud_bg \"", cvar_string("hud_bg"), "\"", "\n"));
597 fputs(fh, strcat("seta hud_bg_color \"", cvar_string("hud_bg_color"), "\"", "\n"));
598 fputs(fh, strcat("seta hud_bg_color_team \"", cvar_string("hud_bg_color_team"), "\"", "\n"));
599 fputs(fh, strcat("seta hud_bg_alpha \"", cvar_string("hud_bg_alpha"), "\"", "\n"));
600 fputs(fh, strcat("seta hud_bg_border \"", cvar_string("hud_bg_border"), "\"", "\n"));
601 fputs(fh, strcat("seta hud_bg_padding \"", cvar_string("hud_bg_padding"), "\"", "\n"));
602 fputs(fh, strcat("seta hud_fg_alpha \"", cvar_string("hud_fg_alpha"), "\"", "\n"));
605 fputs(fh, strcat("seta hud_dock \"", cvar_string("hud_dock"), "\"", "\n"));
606 fputs(fh, strcat("seta hud_dock_color \"", cvar_string("hud_dock_color"), "\"", "\n"));
607 fputs(fh, strcat("seta hud_dock_color_team \"", cvar_string("hud_dock_color_team"), "\"", "\n"));
608 fputs(fh, strcat("seta hud_dock_alpha \"", ftos(cvar("hud_dock_alpha")), "\"", "\n"));
611 fputs(fh, strcat("seta hud_progressbar_alpha ", ftos(cvar("hud_progressbar_alpha")), "\n"));
612 fputs(fh, strcat("seta hud_progressbar_strength_color \"", cvar_string("hud_progressbar_strength_color"), "\"", "\n"));
613 fputs(fh, strcat("seta hud_progressbar_shield_color \"", cvar_string("hud_progressbar_shield_color"), "\"", "\n"));
614 fputs(fh, strcat("seta hud_progressbar_health_color \"", cvar_string("hud_progressbar_health_color"), "\"", "\n"));
615 fputs(fh, strcat("seta hud_progressbar_armor_color \"", cvar_string("hud_progressbar_armor_color"), "\"", "\n"));
616 fputs(fh, strcat("seta hud_progressbar_fuel_color \"", cvar_string("hud_progressbar_fuel_color"), "\"", "\n"));
617 fputs(fh, strcat("seta hud_progressbar_nexball_color \"", cvar_string("hud_progressbar_nexball_color"), "\"", "\n"));
620 // common cvars for all panels
622 for (i = 0; i < HUD_PANEL_NUM; ++i)
624 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), " ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i)))), "\n"));
625 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_pos \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_pos")), "\"", "\n"));
626 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_size \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_size")), "\"", "\n"));
627 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg")), "\"", "\n"));
628 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_color \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg_color")), "\"", "\n"));
629 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_color_team \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg_color_team")), "\"", "\n"));
630 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_alpha \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg_alpha")), "\"", "\n"));
631 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_border \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg_border")), "\"", "\n"));
632 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_padding \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg_padding")), "\"", "\n"));
635 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_accuracy_yellow ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_accuracy_yellow"))), "\n"));
638 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_onlycurrent ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_onlycurrent"))), "\n"));
641 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_flip ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_flip"))), "\n"));
642 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_mirror ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_mirror"))), "\n"));
645 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_flip ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_flip"))), "\n"));
646 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_mirror ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_mirror"))), "\n"));
649 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_flip ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_flip"))), "\n"));
650 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_info_top ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_info_top"))), "\n"));
653 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_foreground_alpha ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_foreground_alpha"))), "\n"));
655 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_alreadyvoted_alpha ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_alreadyvoted_alpha"))), "\n"));
661 print("^2Successfully exported to hud_", cvar_string("hud_skin"), "_", cfgname, ".cfg! (Note: It's saved in data/data/)\n");
666 // return active status of panel
667 float HUD_Panel_CheckActive(float id)
669 if (cvar_or(strcat("hud_", HUD_Panel_GetName(id)), 1))
674 // return size of given panel
675 vector HUD_Panel_GetSize(float id)
678 mySize = stov(cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_size")));
680 mySize = eX * mySize_x * vid_conwidth + eY * mySize_y * vid_conheight;
682 if(disable_menu_alphacheck == 2 && id == highlightedPanel)
684 vector menu_enable_maxsize, menu_enable_size;
685 menu_enable_maxsize = '0 0 0'; // shut up FTEQCC
686 menu_enable_maxsize_x = 0.3 * vid_conwidth;
687 menu_enable_maxsize_y = 0.18 * vid_conheight;
688 if(mySize_x > mySize_y)
690 if(mySize_y > menu_enable_maxsize_y)
692 menu_enable_size_y = menu_enable_maxsize_y;
693 menu_enable_size_x = mySize_x * (menu_enable_maxsize_y/mySize_y);
694 mySize = (1 - cvar("_menu_alpha")) * mySize + (cvar("_menu_alpha")) * menu_enable_size;
699 if(mySize_x > menu_enable_maxsize_x)
701 menu_enable_size_x = menu_enable_maxsize_x;
702 menu_enable_size_y = mySize_y * (menu_enable_maxsize_x/mySize_x);
703 mySize = (1 - cvar("_menu_alpha")) * mySize + (cvar("_menu_alpha")) * menu_enable_size;
710 // return pos of given panel
711 vector HUD_Panel_GetPos(float id)
714 pos = stov(cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_pos")));
716 pos = eX * pos_x * vid_conwidth + eY * pos_y * vid_conheight;
718 if(disable_menu_alphacheck == 2 && id == highlightedPanel)
720 vector mySize, menu_enable_panelpos;
721 mySize = HUD_Panel_GetSize(id);
722 if(mySize_x > mySize_y)
723 menu_enable_panelpos = eX * 0.5 * vid_conwidth - eX * 0.5 * mySize_x + eY * 0.82 * vid_conheight;
725 menu_enable_panelpos = eY * 0.5 * vid_conheight - eY * 0.5 * mySize_y + eX * 0.7 * vid_conwidth;
726 pos = (1 - cvar("_menu_alpha")) * pos + (cvar("_menu_alpha")) * menu_enable_panelpos;
731 float HUD_Panel_GetBorder(float id)
734 border = cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_border"));
736 border = cvar_string("hud_bg_border");
740 vector HUD_Panel_GetColor(float id)
746 // fetch per-panel color
747 if(teamplay && cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_color_team")) != "") {
748 f = stof(getplayerkey(self.sv_entnum, "colors"));
749 color = vtos(colormapPaletteColor(mod(f, 16), 1) * cvar(strcat("hud_", HUD_Panel_GetName(id), "_bg_color_team")));
752 color = cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_color"));
753 color_vec = stov(color);
755 if(color == "") { // fetch default color
756 color = cvar_string("hud_bg_color");
757 color_vec = stov(color);
758 if(teamplay && cvar(strcat("hud_bg_color_team"))) {
759 f = stof(getplayerkey(self.sv_entnum, "colors"));
760 color_vec = colormapPaletteColor(mod(f, 16), 1) * cvar("hud_bg_color_team");
762 else if(color == "shirt") {
763 f = stof(getplayerkey(self.sv_entnum, "colors"));
764 color_vec = colormapPaletteColor(floor(f / 16), 0);
766 else if(color == "pants") {
767 f = stof(getplayerkey(self.sv_entnum, "colors"));
768 color_vec = colormapPaletteColor(mod(f, 16), 1);
771 else if(color == "shirt") {
772 f = stof(getplayerkey(self.sv_entnum, "colors"));
773 color_vec = colormapPaletteColor(floor(f / 16), 0);
775 else if(color == "pants") {
776 f = stof(getplayerkey(self.sv_entnum, "colors"));
777 color_vec = colormapPaletteColor(mod(f, 16), 1);
782 vector HUD_Panel_Dock_GetColor(void)
787 color = cvar_string("hud_dock_color");
788 color_vec = stov(color);
789 if(teamplay && cvar(strcat("hud_dock_color_team"))) {
790 f = stof(getplayerkey(self.sv_entnum, "colors"));
791 color_vec = colormapPaletteColor(mod(f, 16), 1) * cvar("hud_dock_color_team");
793 else if(color == "shirt") {
794 f = stof(getplayerkey(self.sv_entnum, "colors"));
795 color_vec = colormapPaletteColor(floor(f / 16), 0);
797 else if(color == "pants") {
798 f = stof(getplayerkey(self.sv_entnum, "colors"));
799 color_vec = colormapPaletteColor(mod(f, 16), 1);
804 float HUD_Panel_GetBgAlpha(float id)
807 alpha = cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_alpha"));
809 alpha = cvar_string("hud_bg_alpha");
811 if(hud_configure && disable_menu_alphacheck == 2 && highlightedPanel == id) // do not set a minalpha cap when showing the config dialog for this panel
812 alpha = ftos((1 - cvar("_menu_alpha")) * max(cvar("hud_configure_bg_minalpha"), stof(alpha)) + (cvar("_menu_alpha")) * stof(alpha));
813 else if(hud_configure)
814 alpha = ftos(max(cvar("hud_configure_bg_minalpha"), stof(alpha)));
816 if(hud_configure && !cvar(strcat("hud_", HUD_Panel_GetName(id)))) // ALWAYS show disabled panels at 0.25 alpha when in config mode
819 if(disable_menu_alphacheck == 2 && highlightedPanel == id) // don't fade this panel when showing the panel-specific menu dialog
822 return stof(alpha) * menu_fade_alpha;
825 float HUD_Panel_GetFgAlpha(float id)
828 alpha = hud_fg_alpha;
830 if(hud_configure && !cvar(strcat("hud_", HUD_Panel_GetName(id)))) // ALWAYS show disabled panels at 0.25 alpha when in config mode
833 if(disable_menu_alphacheck == 2 && highlightedPanel == id) // don't fade this panel when showing the panel-specific menu dialog
836 return alpha * menu_fade_alpha;
839 float HUD_Panel_GetPadding(float id)
842 padding = cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_padding"));
844 padding = cvar_string("hud_bg_padding");
847 mySize = HUD_Panel_GetSize(id);
849 smallestsize = min(mySize_x, mySize_y);
850 return min(smallestsize/2 - 5, stof(padding));
853 // draw the background/borders
854 void HUD_Panel_DrawBg(float id, vector pos, vector mySize, float alpha)
856 if(!hud_configure && cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg")) == "0")
860 bg = cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg"));
862 bg = cvar_string("hud_bg");
864 if(bg == "0" && hud_configure) {
865 bg = "border"; // we probably want to see a background in config mode at all times...
871 border = HUD_Panel_GetBorder(id);
874 color = HUD_Panel_GetColor(id);
877 alpha = HUD_Panel_GetBgAlpha(id) * alpha; // allow panels to fade in/out by passing an alpha value
879 alpha = HUD_Panel_GetBgAlpha(id);
881 draw_BorderPicture(pos - '1 1 0' * border, strcat("gfx/hud/", cvar_string("hud_skin"), "/", bg), mySize + '1 1 0' * 2 * border, color, alpha, '1 1 0' * (border/BORDER_MULTIPLIER));
885 void HUD_Panel_DrawProgressBar(vector pos, float vertical, vector mySize, vector color, float alpha, float drawflag)
887 //float drawsubpic(vector position, vector size, string pic, vector srcPosition, vector srcSize, vector rgb, float alpha, float flag) = #328;
889 pic = strcat("gfx/hud/", cvar_string("hud_skin"), "/");
891 drawsubpic(pos, eY * min(mySize_y * 0.5, mySize_x) + eX * mySize_x, strcat(pic, "statusbar_vertical"), '0 0 0', '1 0.25 0', color, alpha, drawflag);
892 if(mySize_y/mySize_x > 2)
893 drawsubpic(pos + eY * mySize_x, eY * (mySize_y - 2 * mySize_x) + eX * mySize_x, strcat(pic, "statusbar_vertical"), '0 0.25 0', '1 0.5 0', color, alpha, drawflag);
894 drawsubpic(pos + eY * mySize_y - eY * min(mySize_y * 0.5, mySize_x), eY * min(mySize_y * 0.5, mySize_x) + eX * mySize_x, strcat(pic, "statusbar_vertical"), '0 0.75 0', '1 0.25 0', color, alpha, drawflag);
896 drawsubpic(pos, eX * min(mySize_x * 0.5, mySize_y) + eY * mySize_y, strcat(pic, "statusbar"), '0 0 0', '0.25 1 0', color, alpha, drawflag);
897 if(mySize_x/mySize_y > 2)
898 drawsubpic(pos + eX * mySize_y, eX * (mySize_x - 2 * mySize_y) + eY * mySize_y, strcat(pic, "statusbar"), '0.25 0 0', '0.5 1 0', color, alpha, drawflag);
899 drawsubpic(pos + eX * mySize_x - eX * min(mySize_x * 0.5, mySize_y), eX * min(mySize_x * 0.5, mySize_y) + eY * mySize_y, strcat(pic, "statusbar"), '0.75 0 0', '0.25 1 0', color, alpha, drawflag);
903 vector HUD_Panel_GetProgressBarColor(string item)
905 return stov(cvar_string(strcat("hud_progressbar_", item, "_color")));
908 // check if move will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
909 vector HUD_Panel_CheckMove(float id, vector myPos, vector mySize)
920 myCenter = '0 0 0'; // shut up fteqcc, there IS a reference
921 targCenter = '0 0 0'; // shut up fteqcc, there IS a reference
923 for (i = 0; i < HUD_PANEL_NUM; ++i) {
924 if(i == id || !HUD_Panel_CheckActive(i))
927 targPos = HUD_Panel_GetPos(i) - '1 1 0' * HUD_Panel_GetBorder(id);
928 targSize = HUD_Panel_GetSize(i) + '2 2 0' * HUD_Panel_GetBorder(id);
930 if(myPos_y + mySize_y < targPos_y)
932 if(myPos_y > targPos_y + targSize_y)
935 if(myPos_x + mySize_x < targPos_x)
937 if(myPos_x > targPos_x + targSize_x)
940 // OK, there IS a collision.
942 myCenter_x = myPos_x + 0.5 * mySize_x;
943 myCenter_y = myPos_y + 0.5 * mySize_y;
945 targCenter_x = targPos_x + 0.5 * targSize_x;
946 targCenter_y = targPos_y + 0.5 * targSize_y;
948 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // top left (of the target panel)
950 if(myPos_x + mySize_x - targPos_x < myPos_y + mySize_y - targPos_y) // push it to the side
951 myTarget_x = targPos_x - mySize_x;
952 else // push it upwards
953 myTarget_y = targPos_y - mySize_y;
955 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y) // top right
957 if(targPos_x + targSize_x - myPos_x < myPos_y + mySize_y - targPos_y) // push it to the side
958 myTarget_x = targPos_x + targSize_x;
959 else // push it upwards
960 myTarget_y = targPos_y - mySize_y;
962 else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
964 if(myPos_x + mySize_x - targPos_x < targPos_y + targSize_y - myPos_y) // push it to the side
965 myTarget_x = targPos_x - mySize_x;
966 else // push it downwards
967 myTarget_y = targPos_y + targSize_y;
969 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
971 if(targPos_x + targSize_x - myPos_x < targPos_y + targSize_y - myPos_y) // push it to the side
972 myTarget_x = targPos_x + targSize_x;
973 else // push it downwards
974 myTarget_y = targPos_y + targSize_y;
981 void HUD_Panel_SetPos(float id, vector pos)
984 oldPos = HUD_Panel_GetPos(id);
987 mySize = HUD_Panel_GetSize(id);
989 if(hud_configure_checkcollisions)
990 pos = HUD_Panel_CheckMove(id, pos, mySize);
992 pos_x = bound(0, pos_x, vid_conwidth - mySize_x);
993 pos_y = bound(0, pos_y, vid_conheight - mySize_y);
995 if(cvar("hud_configure_grid"))
997 pos_x = floor((pos_x/vid_conwidth)/bound(0.005, cvar("hud_configure_grid_x"), 0.2) + 0.5) * bound(0.005, cvar("hud_configure_grid_x"), 0.2) * vid_conwidth;
998 pos_y = floor((pos_y/vid_conheight)/bound(0.005, cvar("hud_configure_grid_y"), 0.2) + 0.5) * bound(0.005, cvar("hud_configure_grid_y"), 0.2) * vid_conheight;
1002 s = strcat(ftos(pos_x/vid_conwidth), " ", ftos(pos_y/vid_conheight));
1004 cvar_set(strcat("hud_", HUD_Panel_GetName(id), "_pos"), s);
1007 // check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
1008 vector HUD_Panel_CheckResize(float id, vector mySize, vector resizeorigin) {
1018 ratio = mySize_x/mySize_y;
1020 for (i = 0; i < HUD_PANEL_NUM; ++i) {
1021 if(i == id || !HUD_Panel_CheckActive(i))
1024 targBorder = HUD_Panel_GetBorder(i);
1025 targPos = HUD_Panel_GetPos(i) - '1 1 0' * targBorder;
1026 targSize = HUD_Panel_GetSize(i) + '2 2 0' * targBorder;
1027 targEndPos = targPos + targSize;
1029 // resizeorigin is WITHIN target panel, just abort any collision testing against that particular panel to produce expected behaviour!
1030 if(resizeorigin_x > targPos_x && resizeorigin_x < targEndPos_x && resizeorigin_y > targPos_y && resizeorigin_y < targEndPos_y)
1033 if (resizeCorner == 1)
1035 // check if this panel is on our way
1036 if (resizeorigin_x <= targPos_x)
1038 if (resizeorigin_y <= targPos_y)
1040 if (targEndPos_x <= resizeorigin_x - mySize_x)
1042 if (targEndPos_y <= resizeorigin_y - mySize_y)
1045 // there is a collision:
1046 // detect which side of the panel we are facing is actually limiting the resizing
1047 // (which side the resize direction finds for first) and reduce the size up to there
1049 // dist is the distance between resizeorigin and the "analogous" point of the panel
1050 // in this case resizeorigin (bottom-right point) and the bottom-right point of the panel
1051 dist_x = resizeorigin_x - targEndPos_x;
1052 dist_y = resizeorigin_y - targEndPos_y;
1053 if (dist_y < 0 || dist_x / dist_y > ratio)
1054 mySize_x = min(mySize_x, dist_x);
1056 mySize_y = min(mySize_y, dist_y);
1058 else if (resizeCorner == 2)
1060 if (resizeorigin_x >= targEndPos_x)
1062 if (resizeorigin_y <= targPos_y)
1064 if (targPos_x >= resizeorigin_x + mySize_x)
1066 if (targEndPos_y <= resizeorigin_y - mySize_y)
1069 dist_x = targPos_x - resizeorigin_x;
1070 dist_y = resizeorigin_y - targEndPos_y;
1071 if (dist_y < 0 || dist_x / dist_y > ratio)
1072 mySize_x = min(mySize_x, dist_x);
1074 mySize_y = min(mySize_y, dist_y);
1076 else if (resizeCorner == 3)
1078 if (resizeorigin_x <= targPos_x)
1080 if (resizeorigin_y >= targEndPos_y)
1082 if (targEndPos_x <= resizeorigin_x - mySize_x)
1084 if (targPos_y >= resizeorigin_y + mySize_y)
1087 dist_x = resizeorigin_x - targEndPos_x;
1088 dist_y = targPos_y - resizeorigin_y;
1089 if (dist_y < 0 || dist_x / dist_y > ratio)
1090 mySize_x = min(mySize_x, dist_x);
1092 mySize_y = min(mySize_y, dist_y);
1094 else if (resizeCorner == 4)
1096 if (resizeorigin_x >= targEndPos_x)
1098 if (resizeorigin_y >= targEndPos_y)
1100 if (targPos_x >= resizeorigin_x + mySize_x)
1102 if (targPos_y >= resizeorigin_y + mySize_y)
1105 dist_x = targPos_x - resizeorigin_x;
1106 dist_y = targPos_y - resizeorigin_y;
1107 if (dist_y < 0 || dist_x / dist_y > ratio)
1108 mySize_x = min(mySize_x, dist_x);
1110 mySize_y = min(mySize_y, dist_y);
1112 if(cvar("hud_configure_checkcollisions_debug"))
1113 drawfill(targPos + '1 1 0' * targBorder, targSize - '2 2 0' * targBorder, '1 1 0', .3, DRAWFLAG_NORMAL);
1119 void HUD_Panel_SetPosSize(float id, vector mySize)
1121 vector resizeorigin;
1122 resizeorigin = panel_click_resizeorigin;
1125 // minimum panel size cap
1126 mySize_x = max(0.025 * vid_conwidth, mySize_x);
1127 mySize_y = max(0.025 * vid_conheight, mySize_y);
1129 if(id == 12) // some panels have their own restrictions, like the chat panel (which actually only moves the engine chat print around). Looks bad if it's too small.
1131 mySize_x = max(17 * cvar("con_chatsize"), mySize_x);
1132 mySize_y = max(2 * cvar("con_chatsize") + 2 * HUD_Panel_GetPadding(id), mySize_y);
1135 // collision testing|
1136 // -----------------+
1138 // we need to know pos at this stage, but it might still change later if we hit a screen edge/other panel (?)
1139 if(resizeCorner == 1) {
1140 myPos_x = resizeorigin_x - mySize_x;
1141 myPos_y = resizeorigin_y - mySize_y;
1142 } else if(resizeCorner == 2) {
1143 myPos_x = resizeorigin_x;
1144 myPos_y = resizeorigin_y - mySize_y;
1145 } else if(resizeCorner == 3) {
1146 myPos_x = resizeorigin_x - mySize_x;
1147 myPos_y = resizeorigin_y;
1148 } else { // resizeCorner == 4
1149 myPos_x = resizeorigin_x;
1150 myPos_y = resizeorigin_y;
1153 // left/top screen edges
1155 mySize_x = mySize_x + myPos_x;
1157 mySize_y = mySize_y + myPos_y;
1159 // bottom/right screen edges
1160 if(myPos_x + mySize_x > vid_conwidth)
1161 mySize_x = vid_conwidth - myPos_x;
1162 if(myPos_y + mySize_y > vid_conheight)
1163 mySize_y = vid_conheight - myPos_y;
1165 if(cvar("hud_configure_checkcollisions_debug"))
1166 drawfill(myPos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
1168 // before checkresize, otherwise panel can be snapped partially inside another panel or panel aspect ratio can be broken
1169 if(cvar("hud_configure_grid"))
1171 mySize_x = floor((mySize_x/vid_conwidth)/bound(0.005, cvar("hud_configure_grid_x"), 0.2) + 0.5) * bound(0.005, cvar("hud_configure_grid_x"), 0.2) * vid_conwidth;
1172 mySize_y = floor((mySize_y/vid_conheight)/bound(0.005, cvar("hud_configure_grid_y"), 0.2) + 0.5) * bound(0.005, cvar("hud_configure_grid_y"), 0.2) * vid_conheight;
1175 if(hud_configure_checkcollisions)
1176 mySize = HUD_Panel_CheckResize(id, mySize, resizeorigin);
1178 // minimum panel size cap, do this once more so we NEVER EVER EVER have a panel smaller than this, JUST IN CASE above code still makes the panel eg negative (impossible to resize back without changing cvars manually then)
1179 mySize_x = max(0.025 * vid_conwidth, mySize_x);
1180 mySize_y = max(0.025 * vid_conheight, mySize_y);
1182 // do another pos check, as size might have changed by now
1183 if(resizeCorner == 1) {
1184 myPos_x = resizeorigin_x - mySize_x;
1185 myPos_y = resizeorigin_y - mySize_y;
1186 } else if(resizeCorner == 2) {
1187 myPos_x = resizeorigin_x;
1188 myPos_y = resizeorigin_y - mySize_y;
1189 } else if(resizeCorner == 3) {
1190 myPos_x = resizeorigin_x - mySize_x;
1191 myPos_y = resizeorigin_y;
1192 } else { // resizeCorner == 4
1193 myPos_x = resizeorigin_x;
1194 myPos_y = resizeorigin_y;
1197 if(cvar("hud_configure_checkcollisions_debug"))
1198 drawfill(myPos, mySize, '0 1 0', .3, DRAWFLAG_NORMAL);
1201 s = strcat(ftos(mySize_x/vid_conwidth), " ", ftos(mySize_y/vid_conheight));
1202 cvar_set(strcat("hud_", HUD_Panel_GetName(id), "_size"), s);
1204 s = strcat(ftos(myPos_x/vid_conwidth), " ", ftos(myPos_y/vid_conheight));
1205 cvar_set(strcat("hud_", HUD_Panel_GetName(id), "_pos"), s);
1208 float pressed_key_time;
1209 void HUD_Panel_Arrow_Action(float nPrimary)
1211 if (highlightedPanel_prev == -1)
1214 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && cvar("hud_configure_checkcollisions"));
1217 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
1218 step = vid_conheight;
1220 step = vid_conwidth;
1221 if (hudShiftState & S_SHIFT)
1222 step = (step / 256); // more precision
1224 step = (step / 64) * (1 + 2 * (time - pressed_key_time));
1226 highlightedPanel = highlightedPanel_prev;
1228 if (hudShiftState & S_ALT) // resize
1230 highlightedAction = 1;
1231 if(nPrimary == K_UPARROW)
1233 else if(nPrimary == K_RIGHTARROW)
1235 else if(nPrimary == K_LEFTARROW)
1237 else // if(nPrimary == K_DOWNARROW)
1240 // ctrl+arrow reduces the size, instead of increasing it
1241 // Note that ctrl disables collisions check too, but it's fine
1242 // since we don't collide with anything reducing the size
1243 if (hudShiftState & S_CTRL) {
1245 resizeCorner = 5 - resizeCorner;
1249 mySize = HUD_Panel_GetSize(highlightedPanel);
1250 panel_click_resizeorigin = HUD_Panel_GetPos(highlightedPanel);
1251 if(resizeCorner == 1) {
1252 panel_click_resizeorigin += mySize;
1254 } else if(resizeCorner == 2) {
1255 panel_click_resizeorigin_y += mySize_y;
1257 } else if(resizeCorner == 3) {
1258 panel_click_resizeorigin_x += mySize_x;
1260 } else { // resizeCorner == 4
1263 HUD_Panel_SetPosSize(highlightedPanel, mySize);
1267 highlightedAction = 2;
1269 pos = HUD_Panel_GetPos(highlightedPanel);
1270 if(nPrimary == K_UPARROW)
1272 else if(nPrimary == K_DOWNARROW)
1274 else if(nPrimary == K_LEFTARROW)
1276 else // if(nPrimary == K_RIGHTARROW)
1279 HUD_Panel_SetPos(highlightedPanel, pos);
1284 float prevMouseClicked; // previous state
1285 float prevMouseClickedTime; // time during previous mouse click, to check for doubleclicks
1286 vector prevMouseClickedPos; // pos during previous mouse click, to check for doubleclicks
1289 float menu_enabled_time;
1290 float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
1295 // allow console bind to work
1298 con_keys = findkeysforcommand("toggleconsole");
1299 keys = tokenize(con_keys);
1301 float hit_con_bind, i;
1302 for (i = 0; i < keys; ++i)
1304 if(nPrimary == stof(argv(i)))
1308 if(bInputType == 0) {
1309 if(nPrimary == K_ALT) hudShiftState |= S_ALT;
1310 if(nPrimary == K_CTRL) hudShiftState |= S_CTRL;
1311 if(nPrimary == K_SHIFT) hudShiftState |= S_SHIFT;
1313 else if(bInputType == 1) {
1314 if(nPrimary == K_ALT) hudShiftState -= (hudShiftState & S_ALT);
1315 if(nPrimary == K_CTRL) hudShiftState -= (hudShiftState & S_CTRL);
1316 if(nPrimary == K_SHIFT) hudShiftState -= (hudShiftState & S_SHIFT);
1319 if(nPrimary == K_MOUSE1)
1321 if(bInputType == 0) { // key pressed
1325 else if(bInputType == 1) {// key released
1330 else if(nPrimary == K_ESCAPE)
1332 if (bInputType == 1)
1334 disable_menu_alphacheck = 1;
1336 menu_enabled_time = time;
1337 localcmd("menu_showhudexit\n");
1339 else if(nPrimary == K_UPARROW || nPrimary == K_DOWNARROW || nPrimary == K_LEFTARROW || nPrimary == K_RIGHTARROW)
1341 if (bInputType == 1)
1343 pressed_key_time = 0;
1346 else if (pressed_key_time == 0)
1347 pressed_key_time = time;
1349 HUD_Panel_Arrow_Action(nPrimary); //move or resize panel
1351 else if(hit_con_bind)
1354 return true; // Suppress ALL other input
1357 void HUD_Panel_Highlight()
1363 for(i = 0; i < HUD_PANEL_NUM; ++i)
1365 panelPos = HUD_Panel_GetPos(i);
1366 panelSize = HUD_Panel_GetSize(i);
1367 border = HUD_Panel_GetBorder(i);
1370 if(mousepos_x >= panelPos_x && mousepos_y >= panelPos_y && mousepos_x <= panelPos_x + panelSize_x && mousepos_y <= panelPos_y + panelSize_y)
1372 highlightedPanel = i;
1373 highlightedAction = 1;
1374 panel_click_distance = mousepos - panelPos;
1377 // resize from topleft border
1378 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)
1380 highlightedPanel = i;
1381 highlightedAction = 2;
1383 panel_click_distance = mousepos - panelPos;
1384 panel_click_resizeorigin = panelPos + panelSize;
1387 // resize from topright border
1388 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)
1390 highlightedPanel = i;
1391 highlightedAction = 2;
1393 panel_click_distance_x = panelSize_x - mousepos_x + panelPos_x;
1394 panel_click_distance_y = mousepos_y - panelPos_y;
1395 panel_click_resizeorigin = panelPos + eY * panelSize_y;
1398 // resize from bottomleft border
1399 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)
1401 highlightedPanel = i;
1402 highlightedAction = 2;
1404 panel_click_distance_x = mousepos_x - panelPos_x;
1405 panel_click_distance_y = panelSize_y - mousepos_y + panelPos_y;
1406 panel_click_resizeorigin = panelPos + eX * panelSize_x;
1409 // resize from bottomright border
1410 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)
1412 highlightedPanel = i;
1413 highlightedAction = 2;
1415 panel_click_distance = panelSize - mousepos + panelPos;
1416 panel_click_resizeorigin = panelPos;
1422 void HUD_Panel_Mouse()
1424 // TODO: needs better check... is there any float that contains the current state of the menu? _menu_alpha isn't apparently updated the frame the menu gets enabled
1425 if (menu_enabled == 0) // menu dialog closed, enable normal alpha stuff again
1426 disable_menu_alphacheck = 0;
1427 if (cvar("_menu_alpha") == 0 && time - menu_enabled_time > 0.5)
1431 print("Disable menu_alphacheck: ", ftos(disable_menu_alphacheck), "\n");
1432 print("Highlighted: ", ftos(highlightedPanel), "\n");
1433 print("Menu alpha: ", cvar_string("_menu_alpha"), "\n");
1436 if(mouseClicked == 0 && disable_menu_alphacheck != 2 && highlightedPanel >= 0) { // don't reset these variables in disable_menu_alphacheck mode 2!
1437 highlightedPanel_prev = highlightedPanel;
1438 highlightedPanel = -1;
1439 highlightedAction = 0;
1442 mousepos = mousepos + getmousepos();
1444 mousepos_x = bound(0, mousepos_x, vid_conwidth);
1445 mousepos_y = bound(0, mousepos_y, vid_conheight);
1447 drawpic(mousepos, strcat("gfx/menu/", cvar_string("menu_skin"), "/cursor.tga"), '32 32 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1451 if(prevMouseClicked == 0)
1452 HUD_Panel_Highlight(); // sets highlightedPanel, highlightedAction, panel_click_distance, panel_click_resizeorigin
1454 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && cvar("hud_configure_checkcollisions"));
1456 if(highlightedAction == 1)
1457 HUD_Panel_SetPos(highlightedPanel, mousepos - panel_click_distance);
1458 else if(highlightedAction == 2)
1461 if(resizeCorner == 1) {
1462 mySize_x = panel_click_resizeorigin_x - (mousepos_x - panel_click_distance_x);
1463 mySize_y = panel_click_resizeorigin_y - (mousepos_y - panel_click_distance_y);
1464 } else if(resizeCorner == 2) {
1465 mySize_x = mousepos_x + panel_click_distance_x - panel_click_resizeorigin_x;
1466 mySize_y = panel_click_distance_y + panel_click_resizeorigin_y - mousepos_y;
1467 } else if(resizeCorner == 3) {
1468 mySize_x = panel_click_resizeorigin_x + panel_click_distance_x - mousepos_x;
1469 mySize_y = mousepos_y + panel_click_distance_y - panel_click_resizeorigin_y;
1470 } else { // resizeCorner == 4
1471 mySize_x = mousepos_x - (panel_click_resizeorigin_x - panel_click_distance_x);
1472 mySize_y = mousepos_y - (panel_click_resizeorigin_y - panel_click_distance_y);
1474 HUD_Panel_SetPosSize(highlightedPanel, mySize);
1477 // doubleclick check
1478 if(time - prevMouseClickedTime < 0.4 && prevMouseClicked == 0 && prevMouseClickedPos == mousepos && highlightedPanel >= 0)
1480 mouseClicked = 0; // to prevent spam, I guess.
1481 disable_menu_alphacheck = 2;
1483 menu_enabled_time = time;
1484 localcmd("menu_showhudoptions ", ftos(highlightedPanel), "\n");
1487 if(prevMouseClicked == 0)
1489 prevMouseClickedTime = time;
1490 prevMouseClickedPos = mousepos;
1493 prevMouseClicked = mouseClicked;
1496 // Weapon icons (#0)
1498 float weaponspace[10];
1499 void HUD_WeaponIcons_Clear()
1502 for(idx = 0; idx < 10; ++idx)
1503 weaponspace[idx] = 0;
1506 entity weaponorder[WEP_MAXCOUNT];
1507 void weaponorder_swap(float i, float j, entity pass)
1511 weaponorder[i] = weaponorder[j];
1515 string weaponorder_cmp_str_save;
1516 string weaponorder_cmp_str;
1517 float weaponorder_cmp(float i, float j, entity pass)
1520 ai = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[i].weapon), 0);
1521 aj = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[j].weapon), 0);
1522 return aj - ai; // the string is in REVERSE order (higher prio at the right is what we want, but higher prio first is the string)
1525 void HUD_WeaponIcons(void)
1527 float id = HUD_PANEL_WEAPONICONS;
1528 float alpha, stat_weapons; // "constants"
1529 vector pos, mySize, accuracy_color;
1530 float i, weapid, fade, weapon_stats, weapon_hit, weapon_damage, weapon_cnt; // variables
1532 pos = HUD_Panel_GetPos(id);
1533 mySize = HUD_Panel_GetSize(id);
1535 stat_weapons = getstati(STAT_WEAPONS);
1537 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1539 self = get_weaponinfo(i);
1540 if(self.impulse >= 0)
1544 // TODO make this configurable
1545 weaponorder_cmp_str = strcat(" ", weaponorder_byimpulse, " ");
1547 if(weaponorder_cmp_str != weaponorder_cmp_str_save)
1549 if(weaponorder_cmp_str_save)
1550 strunzone(weaponorder_cmp_str_save);
1551 weaponorder_cmp_str_save = strzone(weaponorder_cmp_str);
1553 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1555 self = get_weaponinfo(i);
1556 if(self.impulse >= 0)
1558 weaponorder[weapon_cnt] = self;
1562 heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, world);
1565 HUD_Panel_DrawBg(id, pos, mySize, 0);
1567 padding = HUD_Panel_GetPadding(id);
1570 pos += '1 1 0' * padding;
1571 mySize -= '2 2 0' * padding;
1575 weapon_stats = getstati(STAT_DAMAGE_HITS);
1576 weapon_number = weapon_stats & 63;
1577 weapon_hits[weapon_number-WEP_FIRST] = floor(weapon_stats / 64);
1579 weapon_stats = getstati(STAT_DAMAGE_FIRED);
1580 weapon_number = weapon_stats & 63;
1581 weapon_fired[weapon_number-WEP_FIRST] = floor(weapon_stats / 64);
1583 if(cvar_or("hud_weaponicons_fade", 1))
1585 fade = 3.2 - 2 * (time - weapontime);
1586 fade = bound(0.7, fade, 1);
1591 HUD_WeaponIcons_Clear();
1593 float rows, columns;
1594 rows = mySize_y/mySize_x;
1595 rows = bound(1, floor((sqrt(4 * (2/1) * rows * WEP_COUNT + rows * rows) + rows + 0.5) / 2), WEP_COUNT);
1596 // ^^^ weapon icon aspect goes here
1598 columns = ceil(WEP_COUNT/rows);
1600 for(i = 0; i < weapon_cnt; ++i)
1602 self = weaponorder[i];
1603 weapid = self.impulse;
1605 alpha = (self.weapon == activeweapon) ? 1 : 0.6;
1607 weapon_hit = weapon_hits[self.weapon-WEP_FIRST];
1608 weapon_damage = weapon_fired[self.weapon-WEP_FIRST];
1610 // draw background behind currently selected weapon
1611 if(self.weapon == activeweapon)
1612 drawpic_skin(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows), "weapon_current_bg", eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows), '1 1 1', fade * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1614 // draw the weapon accuracy on the HUD
1615 if(hud_accuracy_hud && !(gametype == GAME_RACE || gametype == GAME_CTS))
1618 weapon_stats = floor(100 * weapon_hit / weapon_damage);
1620 accuracy_color = HUD_AccuracyColor(weapon_stats);
1622 drawpic_skin(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows), "weapon_accuracy", eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows), accuracy_color, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1625 // draw the weapon icon
1626 if((self.impulse >= 0) && (stat_weapons & self.weapons))
1628 drawpic_skin(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows), strcat("weapon", self.netname), eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows), '1 1 1', fade * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1630 if(cvar_or("hud_weaponicons_number", 1))
1631 drawstring(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows), ftos(weapid), '1 1 0' * 0.5 * mySize_y*(1/rows), '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1635 drawpic_skin(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows), strcat("weapon", self.netname), eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows), '0 0 0', HUD_Panel_GetFgAlpha(id) * 0.5, DRAWFLAG_NORMAL);
1650 float GetAmmoStat(float i)
1654 case 0: return STAT_SHELLS;
1655 case 1: return STAT_NAILS;
1656 case 2: return STAT_ROCKETS;
1657 case 3: return STAT_CELLS;
1658 case 4: return STAT_FUEL;
1663 float GetAmmoItemCode(float i)
1667 case 0: return IT_SHELLS;
1668 case 1: return IT_NAILS;
1669 case 2: return IT_ROCKETS;
1670 case 3: return IT_CELLS;
1671 case 4: return IT_FUEL;
1676 string GetAmmoPicture(float i)
1680 case 0: return "ammo_shells";
1681 case 1: return "ammo_bullets";
1682 case 2: return "ammo_rockets";
1683 case 3: return "ammo_cells";
1684 case 4: return "ammo_fuel";
1689 void HUD_Inventory(void)
1691 float id = HUD_PANEL_INVENTORY;
1695 vector pos, mySize, mysize, mypos;
1696 pos = HUD_Panel_GetPos(id);
1697 mySize = HUD_Panel_GetSize(id);
1699 HUD_Panel_DrawBg(id, pos, mySize, 0);
1701 padding = HUD_Panel_GetPadding(id);
1704 pos += '1 1 0' * padding;
1705 mySize -= '2 2 0' * padding;
1709 stat_items = getstati(STAT_ITEMS);
1710 for (i = 0; i < 4; ++i) {
1712 a = getstati(GetAmmoStat(i)); // how much ammo do we have of type i?
1716 if(cvar("hud_inventory_onlycurrent")) {
1719 if (stat_items & GetAmmoItemCode(i) || hud_configure) {
1720 drawpic_skin(pos, GetAmmoPicture(i), '1 1 0' * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1722 HUD_DrawXNum(pos + eX * mySize_y + eY * 0.25 * mySize_y, a, strlen(ftos(a)), 0, 0.5 * mySize_y, '0.7 0 0', 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1724 HUD_DrawXNum(pos + eX * mySize_y + eY * 0.25 * mySize_y, a, strlen(ftos(a)), 0, 0.5 * mySize_y, '1 1 1', 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1730 if(mySize_x/mySize_y >= 10) { // arrange horizontally
1732 case 0: mypos_x = pos_x; mypos_y = pos_y; break; // shells
1733 case 1: mypos_x = pos_x + 0.25 * mySize_x; mypos_y = pos_y; break; // bullets
1734 case 2: mypos_x = pos_x + 0.5 * mySize_x; mypos_y = pos_y; break; // rockets
1735 case 3: mypos_x = pos_x + 0.75 * mySize_x; mypos_y = pos_y; break; // cells
1737 mysize_x = 0.25 * mySize_x;
1738 mysize_y = mySize_y;
1739 } else if(mySize_x/mySize_y >= 2.5) { // arrange in a 2x2 grid
1741 case 0: mypos_x = pos_x + 0.5 * mySize_x; mypos_y = pos_y + 0.5 * mySize_y; break; // shells
1742 case 1: mypos_x = pos_x + 0.5 * mySize_x; mypos_y = pos_y; break; // bullets
1743 case 2: mypos_x = pos_x; mypos_y = pos_y + 0.5 * mySize_y; break; // rockets
1744 case 3: mypos_x = pos_x; mypos_y = pos_y; break; // cells
1746 mysize_x = 0.5 * mySize_x;
1747 mysize_y = 0.5 * mySize_y;
1748 } else { // arrange vertically
1750 case 0: mypos_x = pos_x; mypos_y = pos_y; break; // shells
1751 case 1: mypos_x = pos_x; mypos_y = pos_y + 0.25 * mySize_y; break; // bullets
1752 case 2: mypos_x = pos_x; mypos_y = pos_y + 0.5 * mySize_y; break; // rockets
1753 case 3: mypos_x = pos_x; mypos_y = pos_y + 0.75 * mySize_y; break; // cells
1755 mysize_x = mySize_x;
1756 mysize_y = 0.25 * mySize_y;
1759 if (stat_items & GetAmmoItemCode(i))
1760 drawpic_skin(mypos, "ammo_current_bg", mysize, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1761 drawpic_skin(mypos + eY * 0.05 * mysize_y, GetAmmoPicture(i), '1 1 0' * 0.8 * mysize_y, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1763 if(stat_items & GetAmmoItemCode(i))
1764 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_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1766 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_Panel_GetFgAlpha(id) * 0.7, DRAWFLAG_NORMAL);
1768 if(stat_items & GetAmmoItemCode(i))
1769 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_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1771 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_Panel_GetFgAlpha(id) * 0.7, DRAWFLAG_NORMAL);
1781 void HUD_Powerups(void) {
1782 float id = HUD_PANEL_POWERUPS;
1784 stat_items = getstati(STAT_ITEMS);
1788 if not(stat_items & IT_STRENGTH)
1789 if not(stat_items & IT_INVINCIBLE)
1792 if (getstati(STAT_HEALTH) <= 0)
1797 pos = HUD_Panel_GetPos(id);
1798 mySize = HUD_Panel_GetSize(id);
1800 HUD_Panel_DrawBg(id, pos, mySize, 0);
1802 padding = HUD_Panel_GetPadding(id);
1805 pos += '1 1 0' * padding;
1806 mySize -= '2 2 0' * padding;
1809 float strength_time, shield_time;
1811 strength_time = bound(0, getstatf(STAT_STRENGTH_FINISHED) - time, 99);
1812 shield_time = bound(0, getstatf(STAT_INVINCIBLE_FINISHED) - time, 99);
1822 vector barpos, barsize;
1826 string leftname, rightname;
1827 float leftcnt, rightcnt;
1828 float leftexact, rightexact;
1829 float leftalpha, rightalpha;
1830 if (cvar(strcat("hud_", HUD_Panel_GetName(id), "_flip"))) {
1831 leftname = "strength";
1832 leftcnt = ceil(strength_time);
1833 leftexact = strength_time;
1835 rightname = "shield";
1836 rightcnt = ceil(shield_time);
1837 rightexact = shield_time;
1839 leftname = "shield";
1840 leftcnt = ceil(shield_time);
1841 leftexact = shield_time;
1843 rightname = "strength";
1844 rightcnt = ceil(strength_time);
1845 rightexact = strength_time;
1847 leftalpha = bound(0, leftexact, 1);
1848 rightalpha = bound(0, rightexact, 1);
1850 if (mySize_x/mySize_y > 4)
1854 len = strlen(ftos(leftcnt));
1856 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
1857 barpos = pos + eX * 0.5 * mySize_x - eX * 0.5 * mySize_x * min(1, leftcnt/30);
1858 barsize = eX * 0.5 * mySize_x * min(1, leftcnt/30) + eY * mySize_y;
1859 picpos = pos + eX * 0.5 * mySize_x - eX * mySize_y;
1860 numpos = picpos - eX * 2 * 0.5 * mySize_y + eX * (2-len) * 0.5 * mySize_y + eY * 0.25 * mySize_y;
1863 barsize = eX * 0.5 * mySize_x * min(1, leftcnt/30) + eY * mySize_y;
1865 numpos = picpos + eX * mySize_y - eX * (2-len) * 0.5 * mySize_y + eY * 0.25 * mySize_y;
1868 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1870 drawpic_skin_expanding_two(picpos, leftname, '1 1 0' * mySize_y, '1 1 1', leftalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_ADDITIVE, bound(0, (leftcnt - leftexact) / 0.5, 1));
1872 drawpic_skin(picpos, leftname, '1 1 0' * mySize_y, '1 1 1', leftalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1873 HUD_DrawXNum(numpos, leftcnt, 2, 0, 0.5 * mySize_y, '1 1 1', 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1878 len = strlen(ftos(rightcnt));
1880 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
1881 barpos = pos + eX * 0.5 * mySize_x;
1882 barsize = eX * 0.5 * mySize_x * min(1, rightcnt/30) + eY * mySize_y;
1883 picpos = pos + eX * 0.5 * mySize_x;
1884 numpos = picpos + eX * mySize_y - eX * (2-len) * 0.5 * mySize_y + eY * 0.25 * mySize_y;
1886 barpos = pos + eX * mySize_x - eX * 0.5 * mySize_x * min(1, rightcnt/30);
1887 barsize = eX * 0.5 * mySize_x * min(1, rightcnt/30) + eY * mySize_y;
1888 picpos = pos + eX * mySize_x - eX * mySize_y;
1889 numpos = picpos - eX * mySize_y + eY * 0.25 * mySize_y;
1892 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1894 drawpic_skin_expanding_two(picpos, rightname, '1 1 0' * mySize_y, '1 1 1', rightalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_ADDITIVE, bound(0, (rightcnt - rightexact) / 0.5, 1));
1896 drawpic_skin(picpos, rightname, '1 1 0' * mySize_y, '1 1 1', rightalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1897 HUD_DrawXNum(numpos, rightcnt, 2, 0, 0.5 * mySize_y, '1 1 1', 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1900 else if (mySize_x/mySize_y > 1.5)
1904 len = strlen(ftos(leftcnt));
1906 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
1907 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, leftcnt/30);
1908 barsize = eX * mySize_x * min(1, leftcnt/30) + eY * 0.5 * mySize_y;
1909 picpos = pos + eX * mySize_x - eX * 0.5 * mySize_y;
1910 numpos = picpos - eX * len * 0.5 * mySize_y;
1913 barsize = eX * mySize_x * min(1, leftcnt/30) + eY * 0.5 * mySize_y;
1915 numpos = picpos + eX * 0.5 * mySize_y;
1918 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1920 drawpic_skin_expanding_two(picpos, leftname, '0.5 0.5 0' * mySize_y, '1 1 1', leftalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_ADDITIVE, bound(0, (leftcnt - leftexact) / 0.5, 1));
1922 drawpic_skin(picpos, leftname, '0.5 0.5 0' * mySize_y, '1 1 1', leftalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1923 HUD_DrawXNum(numpos, leftcnt, len, 0, 0.5 * mySize_y, '1 1 1', 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1928 len = strlen(ftos(rightcnt));
1930 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
1931 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, rightcnt/30) + eY * 0.5 * mySize_y;
1932 barsize = eX * mySize_x * min(1, rightcnt/30) + eY * 0.5 * mySize_y;
1933 picpos = pos + eX * mySize_x - eX * 0.5 * mySize_y + eY * 0.5 * mySize_y;
1934 numpos = picpos - eX * len * 0.5 * mySize_y;
1936 barpos = pos + eY * 0.5 * mySize_y;
1937 barsize = eX * mySize_x * min(1, rightcnt/30) + eY * 0.5 * mySize_y;
1938 picpos = pos + eY * 0.5 * mySize_y;
1939 numpos = picpos + eX * 0.5 * mySize_y;
1942 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1944 drawpic_skin_expanding_two(picpos, rightname, '0.5 0.5 0' * mySize_y, '1 1 1', rightalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_ADDITIVE, bound(0, (rightcnt - rightexact) / 0.5, 1));
1946 drawpic_skin(picpos, rightname, '0.5 0.5 0' * mySize_y, '1 1 1', rightalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1947 HUD_DrawXNum(numpos, rightcnt, len, 0, 0.5 * mySize_y, '1 1 1', 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1954 len = strlen(ftos(leftcnt));
1956 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
1958 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/30);
1959 picpos = pos + eX * 0.05 * mySize_x;
1960 numpos = pos + eX * ((2-len)/2) * 0.25 * mySize_x + eY * 0.4 * mySize_x;
1962 barpos = pos + eY * mySize_y - eY * mySize_y * min(1, leftcnt/30);
1963 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/30);
1964 picpos = pos + eX * 0.05 * mySize_x + eY * mySize_y - eY * 0.65 * mySize_x;
1965 numpos = pos + eX * ((2-len)/2) * 0.25 * mySize_x + eY * mySize_y - eY * 0.25 * mySize_x;
1968 HUD_Panel_DrawProgressBar(barpos, 1, barsize, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1970 drawpic_skin_expanding_two(picpos, leftname, '0.4 0.4 0' * mySize_x, '1 1 1', leftalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_ADDITIVE, bound(0, (leftcnt - leftexact) / 0.5, 1));
1972 drawpic_skin(picpos, leftname, '0.4 0.4 0' * mySize_x, '1 1 1', leftalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1973 HUD_DrawXNum(numpos, leftcnt, len, 0, 0.25 * mySize_x, '1 1 1', 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1978 len = strlen(ftos(rightcnt));
1980 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
1981 barpos = pos + eX * 0.5 * mySize_x;
1982 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, rightcnt/30);
1983 picpos = pos + eX * 0.05 * mySize_x + eX * 0.5 * mySize_x;
1984 numpos = pos + eX * ((2-len)/2) * 0.25 * mySize_x + eY * 0.4 * mySize_x + eX * 0.5 * mySize_x;
1986 barpos = pos + eY * mySize_y - eY * mySize_y * min(1, rightcnt/30) + eX * 0.5 * mySize_x;
1987 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, rightcnt/30);
1988 picpos = pos + eX * 0.05 * mySize_x + eY * mySize_y - eY * 0.65 * mySize_x + eX * 0.5 * mySize_x;
1989 numpos = pos + eX * ((2-len)/2) * 0.25 * mySize_x + eY * mySize_y - eY * 0.25 * mySize_x + eX * 0.5 * mySize_x;
1992 HUD_Panel_DrawProgressBar(barpos, 1, barsize, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1994 drawpic_skin_expanding_two(picpos, rightname, '0.4 0.4 0' * mySize_x, '1 1 1', rightalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_ADDITIVE, bound(0, (rightcnt - rightexact) / 0.5, 1));
1996 drawpic_skin(picpos, rightname, '0.4 0.4 0' * mySize_x, '1 1 1', rightalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1997 HUD_DrawXNum(numpos, rightcnt, len, 0, 0.25 * mySize_x, '1 1 1', 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2002 // Health/armor (#3)
2004 void HUD_HealthArmor(void)
2006 float id = HUD_PANEL_HEALTHARMOR;
2008 pos = HUD_Panel_GetPos(id);
2009 mySize = HUD_Panel_GetSize(id);
2011 HUD_Panel_DrawBg(id, pos, mySize, 0);
2013 padding = HUD_Panel_GetPadding(id);
2016 pos += '1 1 0' * padding;
2017 mySize -= '2 2 0' * padding;
2020 float armor, health;
2021 armor = getstati(STAT_ARMOR);
2022 health = getstati(STAT_HEALTH);
2025 fuel = getstati(GetAmmoStat(4)); // how much fuel do we have?
2038 vector barpos, barsize;
2042 if(cvar("hud_healtharmor") == 2) // combined health and armor display
2045 v = healtharmor_maxdamage(health, armor, armorblockpercent);
2050 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
2051 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, x/400);
2052 barsize = eX * mySize_x * min(1, x/400) + eY * mySize_y;
2054 numpos = picpos + eX * 1.5 * mySize_y;
2057 barsize = eX * mySize_x * min(1, x/400) + eY * mySize_y;
2058 picpos = pos + eX * 3 * mySize_y;
2062 if(v_z) // NOT fully armored
2064 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor("health"), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2065 drawpic_skin(picpos, "health", '1 1 0' * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2067 drawpic_skin(picpos + eX * mySize_y, "armor", '0.5 0.5 0' * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id) * armor / health, DRAWFLAG_NORMAL);
2071 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor("armor"), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2072 drawpic_skin(picpos + eX * mySize_y, "health", '0.5 0.5 0' * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id) * health / armor, DRAWFLAG_NORMAL);
2074 drawpic_skin(picpos, "armor", '1 1 0' * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2076 HUD_DrawXNum_Colored(numpos, x, 3, mySize_y, HUD_Panel_GetFgAlpha(id)); // draw the combined health and armor
2079 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
2080 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, fuel/100);
2081 barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.2 * mySize_y;
2084 barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.2 * mySize_y;
2087 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor("fuel"), HUD_Panel_GetFgAlpha(id) * 0.8, DRAWFLAG_NORMAL);
2092 string leftname, rightname;
2093 float leftcnt, rightcnt;
2094 float leftactive, rightactive;
2095 float leftalpha, rightalpha;
2096 if (cvar(strcat("hud_", HUD_Panel_GetName(id), "_flip"))) { // old style layout with armor left/top of health
2101 leftalpha = min((armor+10)/55, 1);
2103 rightname = "health";
2108 leftname = "health";
2113 rightname = "armor";
2117 rightalpha = min((armor+10)/55, 1);
2120 if (mySize_x/mySize_y > 5)
2124 len = strlen(ftos(leftcnt));
2126 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
2127 barpos = pos + eX * 0.5 * mySize_x - eX * 0.5 * mySize_x * min(1, leftcnt/200);
2128 barsize = eX * 0.5 * mySize_x * min(1, leftcnt/200) + eY * mySize_y;
2129 picpos = pos + eX * 0.5 * mySize_x - eX * mySize_y;
2130 numpos = picpos - eX * 3 * 0.5 * mySize_y + eX * (3-len) * 0.5 * mySize_y + eY * 0.25 * mySize_y;
2133 barsize = eX * 0.5 * mySize_x * min(1, leftcnt/200) + eY * mySize_y;
2135 numpos = picpos + eX * mySize_y + eY * 0.25 * mySize_y;
2138 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2139 drawpic_skin(picpos, leftname, '1 1 0' * mySize_y, '1 1 1', leftalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2140 HUD_DrawXNum_Colored(numpos, leftcnt, len, 0.5 * mySize_y, HUD_Panel_GetFgAlpha(id));
2145 len = strlen(ftos(rightcnt));
2147 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
2148 barpos = pos + eX * 0.5 * mySize_x;
2149 barsize = eX * 0.5 * mySize_x * min(1, rightcnt/200) + eY * mySize_y;
2150 picpos = pos + eX * 0.5 * mySize_x;
2151 numpos = picpos + eX * mySize_y - eX * (3-len) * 0.5 * mySize_y + eY * 0.25 * mySize_y;
2153 barpos = pos + eX * mySize_x - eX * 0.5 * mySize_x * min(1, rightcnt/200);
2154 barsize = eX * 0.5 * mySize_x * min(1, rightcnt/200) + eY * mySize_y;
2155 picpos = pos + eX * mySize_x - eX * mySize_y;
2156 numpos = picpos - eX * 1.5 * mySize_y + eY * 0.25 * mySize_y;
2159 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2160 drawpic_skin(picpos, rightname, '1 1 0' * mySize_y, '1 1 1', rightalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2161 HUD_DrawXNum_Colored(numpos, rightcnt, 3, 0.5 * mySize_y, HUD_Panel_GetFgAlpha(id));
2164 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
2165 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, fuel/100);
2166 barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.2 * mySize_y;
2169 barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.2 * mySize_y;
2172 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor("fuel"), HUD_Panel_GetFgAlpha(id) * 0.8, DRAWFLAG_NORMAL);
2174 else if (mySize_x/mySize_y > 2)
2178 len = strlen(ftos(leftcnt));
2180 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
2181 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, leftcnt/200);
2182 barsize = eX * mySize_x * min(1, leftcnt/200) + eY * 0.5 * mySize_y;
2183 picpos = pos + eX * mySize_x - eX * 0.5 * mySize_y;
2184 numpos = picpos - eX * len * 0.5 * mySize_y;
2187 barsize = eX * mySize_x * min(1, leftcnt/200) + eY * 0.5 * mySize_y;
2189 numpos = picpos + eX * 0.5 * mySize_y;
2192 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2193 drawpic_skin(picpos, leftname, '0.5 0.5 0' * mySize_y, '1 1 1', leftalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2194 HUD_DrawXNum_Colored(numpos, leftcnt, len, 0.5 * mySize_y, HUD_Panel_GetFgAlpha(id));
2199 len = strlen(ftos(rightcnt));
2201 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
2202 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, rightcnt/200) + eY * 0.5 * mySize_y;
2203 barsize = eX * mySize_x * min(1, rightcnt/200) + eY * 0.5 * mySize_y;
2204 picpos = pos + eX * mySize_x - eX * 0.5 * mySize_y + eY * 0.5 * mySize_y;
2205 numpos = picpos - eX * len * 0.5 * mySize_y;
2207 barpos = pos + eY * 0.5 * mySize_y;
2208 barsize = eX * mySize_x * min(1, rightcnt/200) + eY * 0.5 * mySize_y;
2209 picpos = pos + eY * 0.5 * mySize_y;
2210 numpos = picpos + eX * 0.5 * mySize_y;
2213 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2214 drawpic_skin(picpos, rightname, '0.5 0.5 0' * mySize_y, '1 1 1', rightalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2215 HUD_DrawXNum_Colored(numpos, rightcnt, len, 0.5 * mySize_y, HUD_Panel_GetFgAlpha(id));
2218 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
2219 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, fuel/100);
2220 barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.1 * mySize_y;
2223 barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.1 * mySize_y;
2226 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor("fuel"), HUD_Panel_GetFgAlpha(id) * 0.8, DRAWFLAG_NORMAL);
2232 len = strlen(ftos(leftcnt));
2234 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
2236 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/200);
2237 picpos = pos + eX * 0.05 * mySize_x;
2238 numpos = pos + eX * ((3-len)/2) * 0.25 * mySize_x + eY * 0.4 * mySize_x;
2240 barpos = pos + eY * mySize_y - eY * mySize_y * min(1, leftcnt/200);
2241 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/200);
2242 picpos = pos + eX * 0.05 * mySize_x + eY * mySize_y - eY * 0.566 * mySize_x;
2243 numpos = pos + eX * ((3-len)/2) * 0.25 * mySize_x + eY * mySize_y - eY * 0.166 * mySize_x;
2246 HUD_Panel_DrawProgressBar(barpos, 1, barsize, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2247 drawpic_skin(picpos, leftname, '0.4 0.4 0' * mySize_x, '1 1 1', leftalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2248 HUD_DrawXNum_Colored(numpos, leftcnt, len, 0.166 * mySize_x, HUD_Panel_GetFgAlpha(id));
2253 len = strlen(ftos(rightcnt));
2255 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
2256 barpos = pos + eX * 0.5 * mySize_x;
2257 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, rightcnt/200);
2258 picpos = pos + eX * 0.05 * mySize_x + eX * 0.5 * mySize_x;
2259 numpos = pos + eX * ((3-len)/2) * 0.25 * mySize_x + eY * 0.4 * mySize_x + eX * 0.5 * mySize_x;
2261 barpos = pos + eY * mySize_y - eY * mySize_y * min(1, rightcnt/200) + eX * 0.5 * mySize_x;
2262 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, rightcnt/200);
2263 picpos = pos + eX * 0.05 * mySize_x + eY * mySize_y - eY * 0.566 * mySize_x + eX * 0.5 * mySize_x;
2264 numpos = pos + eX * ((3-len)/2) * 0.25 * mySize_x + eY * mySize_y - eY * 0.166 * mySize_x + eX * 0.5 * mySize_x;
2267 HUD_Panel_DrawProgressBar(barpos, 1, barsize, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2268 drawpic_skin(picpos, rightname, '0.4 0.4 0' * mySize_x, '1 1 1', rightalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2269 HUD_DrawXNum_Colored(numpos, rightcnt, len, 0.166 * mySize_x, HUD_Panel_GetFgAlpha(id));
2272 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
2274 barsize = eX * 0.05 * mySize_x + eY * mySize_y * min(1, fuel/100);
2276 barpos = pos + eY * mySize_y - eY * mySize_y * min(1, fuel/100);
2277 barsize = eX * 0.05 * mySize_x + eY * mySize_y * min(1, fuel/100);
2280 HUD_Panel_DrawProgressBar(barpos, 1, barsize, HUD_Panel_GetProgressBarColor("fuel"), HUD_Panel_GetFgAlpha(id) * 0.8, DRAWFLAG_NORMAL);
2286 // Notification area (#4)
2289 string Weapon_SuicideMessage(float deathtype)
2291 w_deathtype = deathtype;
2292 get_weaponinfo(DEATH_WEAPONOF(deathtype)).weapon_func(WR_SUICIDEMESSAGE);
2293 return w_deathtypestring;
2296 string Weapon_KillMessage(float deathtype)
2298 w_deathtype = deathtype;
2299 get_weaponinfo(DEATH_WEAPONOF(deathtype)).weapon_func(WR_KILLMESSAGE);
2300 return w_deathtypestring;
2303 float killnotify_times[10];
2304 float killnotify_deathtype[10];
2305 float killnotify_actiontype[10]; // 0 = "Y [used by] X", 1 = "X [did action to] Y"
2306 string killnotify_attackers[10];
2307 string killnotify_victims[10];
2308 void HUD_KillNotify_Push(string attacker, string victim, float actiontype, float wpn)
2311 for (i = 9; i > 0; --i) {
2312 killnotify_times[i] = killnotify_times[i-1];
2313 killnotify_deathtype[i] = killnotify_deathtype[i-1];
2314 killnotify_actiontype[i] = killnotify_actiontype[i-1];
2315 if(killnotify_attackers[i])
2316 strunzone(killnotify_attackers[i]);
2317 killnotify_attackers[i] = strzone(killnotify_attackers[i-1]);
2318 if(killnotify_victims[i])
2319 strunzone(killnotify_victims[i]);
2320 killnotify_victims[i] = strzone(killnotify_victims[i-1]);
2322 killnotify_times[0] = time;
2323 killnotify_deathtype[0] = wpn;
2324 killnotify_actiontype[0] = actiontype;
2325 if(killnotify_attackers[0])
2326 strunzone(killnotify_attackers[0]);
2327 killnotify_attackers[0] = strzone(attacker);
2328 if(killnotify_victims[0])
2329 strunzone(killnotify_victims[0]);
2330 killnotify_victims[0] = strzone(victim);
2333 void HUD_KillNotify(string s1, string s2, string s3, float type, float msg)
2337 alsoprint = (cvar("hud_notify_print") || !HUD_Panel_CheckActive(4)); // print message to console if: notify panel disabled, or cvar to do so enabled
2339 if(msg == MSG_SUICIDE) {
2341 w = DEATH_WEAPONOF(type);
2343 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2345 print("^1", s1, "^1 ", Weapon_SuicideMessage(type), "\n");
2346 } else if (type == DEATH_KILL) {
2347 HUD_KillNotify_Push(s1, "", 0, DEATH_KILL);
2349 print ("^1",s1, "^1 couldn't take it anymore\n");
2350 } else if (type == DEATH_ROT) {
2351 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2353 print ("^1",s1, "^1 died\n");
2354 } else if (type == DEATH_NOAMMO) {
2355 HUD_KillNotify_Push(s1, "", 0, DEATH_NOAMMO);
2357 print ("^7",s1, "^7 committed suicide. What's the point of living without ammo?\n");
2358 } else if (type == DEATH_CAMP) {
2359 HUD_KillNotify_Push(s1, "", 0, DEATH_CAMP);
2361 print ("^1",s1, "^1 thought they found a nice camping ground\n");
2362 } else if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
2363 HUD_KillNotify_Push(s1, "", 0, type);
2365 print ("^1",s1, "^1 didn't become friends with the Lord of Teamplay\n");
2366 } else if (type == DEATH_CHEAT) {
2367 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2369 print ("^1",s1, "^1 unfairly eliminated themself\n");
2370 } else if (type == DEATH_FIRE) {
2371 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2373 print ("^1",s1, "^1 burned to death\n");
2374 } else if (type != DEATH_TEAMCHANGE && type != DEATH_QUIET) {
2375 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2377 print ("^1",s1, "^1 couldn't resist the urge to self-destruct\n");
2380 if (stof(s2) > 2) // killcount > 2
2381 print ("^1",s1,"^1 ended it all after a ",s2," kill spree\n");
2382 } else if(msg == MSG_KILL) {
2383 w = DEATH_WEAPONOF(type);
2385 HUD_KillNotify_Push(s2, s1, 1, w);
2387 print("^1", s1, "^1 ", Weapon_KillMessage(type), "\n");
2389 else if(type == KILL_TEAM_RED || type == KILL_TEAM_BLUE || type == KILL_TEAM_SPREE) {
2390 HUD_KillNotify_Push(s1, s2, 1, type);
2393 if(cvar("cl_gentle")) {
2394 print ("^1", s1, "^1 took action against a team mate\n");
2396 print ("^1", s1, "^1 mows down a team mate\n");
2399 if (stof(s2) > 2 && type == KILL_TEAM_SPREE) {
2400 if(cvar("cl_gentle"))
2401 print ("^1",s1,"^1 ended a ",s3," scoring spree by going against a team mate\n");
2403 print ("^1",s1,"^1 ended a ",s3," kill spree by killing a team mate\n");
2405 else if (stof(s2) > 2) {
2406 if(cvar("cl_gentle"))
2407 print ("^1",s1,"'s ^1",s3," scoring spree was ended by a team mate!\n");
2409 print ("^1",s1,"'s ^1",s3," kill spree was ended by a team mate!\n");
2412 else if(type == KILL_FIRST_BLOOD)
2413 print("^1",s1, "^1 drew first blood", "\n");
2415 else if (type == DEATH_TELEFRAG)
2416 print ("^1",s1, "^1 was telefragged by ", s2, "\n");
2417 else if (type == DEATH_DROWN) {
2418 HUD_KillNotify_Push(s2, s1, 1, DEATH_DROWN);
2420 print ("^1",s1, "^1 was drowned by ", s2, "\n");
2422 else if (type == DEATH_SLIME) {
2423 HUD_KillNotify_Push(s2, s1, 1, DEATH_SLIME);
2425 print ("^1",s1, "^1 was slimed by ", s2, "\n");
2427 else if (type == DEATH_LAVA) {
2428 HUD_KillNotify_Push(s2, s1, 1, DEATH_LAVA);
2430 print ("^1",s1, "^1 was cooked by ", s2, "\n");
2432 else if (type == DEATH_FALL) {
2433 HUD_KillNotify_Push(s2, s1, 1, DEATH_FALL);
2435 print ("^1",s1, "^1 was grounded by ", s2, "\n");
2437 else if (type == DEATH_SHOOTING_STAR) {
2438 HUD_KillNotify_Push(s2, s1, 1, DEATH_SHOOTING_STAR);
2440 print ("^1",s1, "^1 was shot into space by ", s2, "\n");
2442 else if (type == DEATH_SWAMP) {
2443 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2445 print ("^1",s1, "^1 was conserved by ", s2, "\n");
2447 else if (type == DEATH_HURTTRIGGER)
2449 HUD_KillNotify_Push(s2, s1, 1, DEATH_HURTTRIGGER);
2451 print("^1",s1, "^1 was thrown into a world of hurt by ", s2, "\n");
2452 } else if(type == DEATH_SBCRUSH) {
2453 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2455 print ("^1",s1, "^1 was crushed by ^1", s2, "\n");
2456 } else if(type == DEATH_SBMINIGUN) {
2457 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2459 print ("^1",s1, "^1 got shredded by ^1", s2, "\n");
2460 } else if(type == DEATH_SBROCKET) {
2461 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2463 print ("^1",s1, "^1 was blased to bits by ^1", s2, "\n");
2464 } else if(type == DEATH_SBBLOWUP) {
2465 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2467 print ("^1",s1, "^1 got caught in the destruction of ^1", s2, "'s vehicle\n");
2468 } else if(type == DEATH_WAKIGUN) {
2469 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2471 print ("^1",s1, "^1 was bolted down by ^1", s2, "\n");
2472 } else if(type == DEATH_WAKIROCKET) {
2473 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2475 print ("^1",s1, "^1 could find no shelter from ^1", s2, "'s rockets\n");
2476 } else if(type == DEATH_WAKIBLOWUP) {
2477 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2479 print ("^1",s1, "^1 dies when ^1", s2, "'s wakizashi dies.\n");
2480 } else if(type == DEATH_TURRET) {
2481 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2483 print ("^1",s1, "^1 was pushed into the line of fire by ^1", s2, "\n");
2484 } else if(type == DEATH_TOUCHEXPLODE) {
2485 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2487 print ("^1",s1, "^1 was pushed into an accident by ^1", s2, "\n");
2488 } else if(type == DEATH_CHEAT) {
2489 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2491 print ("^1",s1, "^1 was unfairly eliminated by ^1", s2, "\n");
2492 } else if (type == DEATH_FIRE) {
2493 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2495 print ("^1",s1, "^1 was burnt to death by ^1", s2, "\n");
2496 } else if (type == DEATH_CUSTOM) {
2497 HUD_KillNotify_Push(s2, s1, 1, DEATH_CUSTOM);
2499 print ("^1",s1, "^1 ", s2, "\n");
2501 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2503 print ("^1",s1, "^1 was fragged by ", s2, "\n");
2505 } else if(msg == MSG_SPREE) {
2506 if(type == KILL_END_SPREE) {
2507 if(cvar("cl_gentle"))
2508 print ("^1",s1,"'s ^1", s2, " scoring spree was ended by ", s3, "\n");
2510 print ("^1",s1,"'s ^1", s2, " kill spree was ended by ", s3, "\n");
2511 } else if(type == KILL_SPREE) {
2512 if(cvar("cl_gentle"))
2513 print ("^1",s1,"^1 made ",s2," scores in a row\n");
2515 print ("^1",s1,"^1 has ",s2," frags in a row\n");
2516 } else if(type == KILL_SPREE_3) {
2517 if(cvar("cl_gentle"))
2518 print (s1,"^7 made a ^1TRIPLE SCORE\n");
2520 print (s1,"^7 made a ^1TRIPLE FRAG\n");
2521 } else if(type == KILL_SPREE_5) {
2522 if(cvar("cl_gentle"))
2523 print (s1,"^7 unleashes ^1SCORING RAGE\n");
2525 print (s1,"^7 unleashes ^1RAGE\n");
2526 } else if(type == KILL_SPREE_10) {
2527 if(cvar("cl_gentle"))
2528 print (s1,"^7 made ^1TEN SCORES IN A ROW!\n");
2530 print (s1,"^7 starts the ^1MASSACRE!\n");
2531 } else if(type == KILL_SPREE_15) {
2532 if(cvar("cl_gentle"))
2533 print (s1,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
2535 print (s1,"^7 executes ^1MAYHEM!\n");
2536 } else if(type == KILL_SPREE_20) {
2537 if(cvar("cl_gentle"))
2538 print (s1,"^7 made ^1TWENTY SCORES IN A ROW!\n");
2540 print (s1,"^7 is a ^1BERSERKER!\n");
2541 } else if(type == KILL_SPREE_25) {
2542 if(cvar("cl_gentle"))
2543 print (s1,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
2545 print (s1,"^7 inflicts ^1CARNAGE!\n");
2546 } else if(type == KILL_SPREE_30) {
2547 if(cvar("cl_gentle"))
2548 print (s1,"^7 made ^1THIRTY SCORES IN A ROW!\n");
2550 print (s1,"^7 unleashes ^1ARMAGEDDON!\n");
2552 } else if(msg == MSG_KILL_ACTION) { // wtf is this? isnt it basically the same as MSG_SUICIDE?
2553 if (type == DEATH_DROWN) {
2554 HUD_KillNotify_Push(s1, "", 0, DEATH_DROWN);
2557 if(cvar("cl_gentle"))
2558 print ("^1",s1, "^1 was in the water for too long\n");
2560 print ("^1",s1, "^1 drowned\n");
2562 } else if (type == DEATH_SLIME) {
2563 HUD_KillNotify_Push(s1, "", 0, DEATH_SLIME);
2565 print ("^1",s1, "^1 was slimed\n");
2566 } else if (type == DEATH_LAVA) {
2567 HUD_KillNotify_Push(s1, "", 0, DEATH_LAVA);
2570 if(cvar("cl_gentle"))
2571 print ("^1",s1, "^1 found a hot place\n");
2573 print ("^1",s1, "^1 turned into hot slag\n");
2575 } else if (type == DEATH_FALL) {
2576 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2579 if(cvar("cl_gentle"))
2580 print ("^1",s1, "^1 tested gravity (and it worked)\n");
2582 print ("^1",s1, "^1 hit the ground with a crunch\n");
2584 } else if (type == DEATH_SHOOTING_STAR) {
2585 HUD_KillNotify_Push(s1, "", 0, DEATH_SHOOTING_STAR);
2587 print ("^1",s1, "^1 became a shooting star\n");
2588 } else if (type == DEATH_SWAMP) {
2589 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2592 if(cvar("cl_gentle"))
2593 print ("^1",s1, "^1 discovered a swamp\n");
2595 print ("^1",s1, "^1 is now conserved for centuries to come\n");
2597 } else if(type == DEATH_TURRET) {
2598 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2600 print ("^1",s1, "^1 was mowed down by a turret \n");
2601 } else if (type == DEATH_CUSTOM) {
2602 HUD_KillNotify_Push(s1, "", 0, DEATH_CUSTOM);
2604 print ("^1",s1, "^1 ", s2, "\n");
2605 } else if (type == DEATH_HURTTRIGGER) {
2606 HUD_KillNotify_Push(s1, "", 0, DEATH_HURTTRIGGER);
2608 print ("^1",s1, "^1 was in the wrong place\n");
2609 } else if(type == DEATH_TOUCHEXPLODE) {
2610 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2612 print ("^1",s1, "^1 died in an accident\n");
2613 } else if(type == DEATH_CHEAT) {
2614 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2616 print ("^1",s1, "^1 was unfairly eliminated\n");
2617 } else if(type == DEATH_FIRE) {
2618 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2621 if(cvar("cl_gentle"))
2622 print ("^1",s1, "^1 felt a little hot\n");
2624 print ("^1",s1, "^1 burnt to death\n");
2627 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2630 if(cvar("cl_gentle"))
2631 print ("^1",s1, "^1 needs a restart\n");
2633 print ("^1",s1, "^1 died\n");
2636 } else if(msg == MSG_KILL_ACTION_SPREE) {
2637 if(cvar("cl_gentle"))
2638 print ("^1",s1,"^1 needs a restart after a ",s2," scoring spree\n");
2640 print ("^1",s1,"^1 died with a ",s2," kill spree\n");
2641 } else if(msg == MSG_INFO) {
2642 if(type == INFO_GOTFLAG) { // here, s2 is the flag name
2643 HUD_KillNotify_Push(s1, s2, 0, INFO_GOTFLAG);
2644 print(s1, "^7 got the ", s2, "\n");
2645 } else if(type == INFO_LOSTFLAG) {
2646 HUD_KillNotify_Push(s1, s2, 0, INFO_LOSTFLAG);
2647 print(s1, "^7 lost the ", s2, "\n");
2648 } else if(type == INFO_PICKUPFLAG) {
2649 HUD_KillNotify_Push(s1, s2, 0, INFO_GOTFLAG);
2650 print(s1, "^7 picked up the ", s2, "\n");
2651 } else if(type == INFO_RETURNFLAG) {
2652 HUD_KillNotify_Push(s1, s2, 0, INFO_RETURNFLAG);
2653 print(s1, "^7 returned the ", s2, "\n");
2658 #define DAMAGE_CENTERPRINT_SPACER NEWLINES
2660 void HUD_Centerprint(string s1, string s2, float type, float msg)
2662 if(msg == MSG_SUICIDE) {
2663 if (type == DEATH_TEAMCHANGE) {
2664 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "You are now on: ", s1));
2665 } else if (type == DEATH_AUTOTEAMCHANGE) {
2666 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "You have been moved into a different team to improve team balance\nYou are now on: ", s1));
2667 } else if (type == DEATH_CAMP) {
2668 if(cvar("cl_gentle"))
2669 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Reconsider your tactics, camper!"));
2671 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Die camper!"));
2672 } else if (type == DEATH_NOAMMO) {
2673 if(cvar("cl_gentle"))
2674 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You are reinserted into the game for running out of ammo..."));
2676 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were killed for running out of ammo..."));
2677 } else if (type == DEATH_ROT) {
2678 if(cvar("cl_gentle"))
2679 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to preserve your health"));
2681 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You grew too old without taking your medicine"));
2682 } else if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
2683 if(cvar("cl_gentle"))
2684 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't go against team mates!"));
2686 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't shoot your team mates!"));
2687 } else if (type == DEATH_QUIET) {
2689 } else if (type == DEATH_KILL) {
2690 if(cvar("cl_gentle"))
2691 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to be more careful!"));
2693 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You killed your own dumb self!"));
2695 } else if(msg == MSG_KILL) {
2696 if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
2697 if(cvar("cl_gentle")) {
2698 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You went against", s1, ",a team mate!"));
2700 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You fragged ", s1, ", a team mate!"));
2702 } else if (type == KILL_FIRST_BLOOD) {
2703 if(cvar("cl_gentle")) {
2704 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First score"));
2706 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First blood"));
2708 } else if (type == KILL_FIRST_VICTIM) {
2709 if(cvar("cl_gentle")) {
2710 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First casualty"));
2712 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First victim"));
2714 } else if (type == KILL_TYPEFRAG) { // s2 contains "advanced kill messages" such as ping, handicap...
2715 if(cvar("cl_gentle")) {
2716 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You scored against ^7", s1, "^1 who was typing!", s2));
2718 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You typefragged ^7", s1, s2));
2720 } else if (type == KILL_TYPEFRAGGED) {
2721 if(cvar("cl_gentle")) {
2722 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were scored against by ^7", s1, "^1 while you were typing!", s2));
2724 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were typefragged by ^7", s1, s2));
2726 } else if (type == KILL_FRAG) {
2727 if(cvar("cl_gentle")) {
2728 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^4You scored against ^7", s1, s2));
2730 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^4You fragged ^7", s1, s2));
2732 } else if (type == KILL_FRAGGED) {
2733 if(cvar("cl_gentle")) {
2734 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were scored against by ^7", s1, s2));
2736 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were fragged by ^7", s1, s2));
2739 } else if(msg == MSG_KILL_ACTION) {
2740 // TODO: invent more centerprints here?
2741 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Watch your step!"));
2745 void HUD_Notify (void)
2747 float id = HUD_PANEL_NOTIFY;
2749 pos = HUD_Panel_GetPos(id);
2750 mySize = HUD_Panel_GetSize(id);
2752 HUD_Panel_DrawBg(id, pos, mySize, 0);
2754 padding = HUD_Panel_GetPadding(id);
2757 pos += '1 1 0' * padding;
2758 mySize -= '2 2 0' * padding;
2761 float entries, height;
2762 entries = bound(1, floor(14 * mySize_y/mySize_x), 12);
2763 height = mySize_y/entries;
2764 entries -= 2; // top/bottom two lines reserved for info messaged, such as spec instructions
2767 fontsize = '0.5 0.5 0' * height;
2771 when = cvar("hud_notify_time");
2773 fadetime = cvar("hud_notify_fadetime");
2777 vector pos_attacker, pos_victim;
2779 float width_attacker, width_victim;
2780 string attacker, victim;
2783 for(j = 0; j < entries; ++j)
2785 if(cvar("hud_notify_flip"))
2787 else // rather nasty hack for ordering items from the bottom up
2788 i = entries - j - 1;
2789 if(cvar("hud_notify_info_top"))
2790 i += 2; // top/bottom two lines reserved for info messaged, such as spec instructions
2794 if(killnotify_times[j] + when > time)
2797 a = bound(0, (killnotify_times[j] + when + fadetime - time) / fadetime, 1);
2801 if(killnotify_times[j] + when > time)
2807 // TODO: maybe print in team colors?
2808 // TODO: maybe this could be cleaned up somehow...
2809 // TODO: less copypaste code below
2812 if(killnotify_actiontype[j] == 0 && !hud_configure)
2814 attacker = textShortenToWidth(killnotify_attackers[j], mySize_x - 2 * height, fontsize, stringwidth_colors);
2816 width_attacker = stringwidth(attacker, TRUE, fontsize);
2817 pos_attacker = pos + eX * 0.5 * (mySize_x - width_attacker + 2 * height) + eY * 0.5 * fontsize_y + eY * i * height;
2819 weap_pos = pos + eX * 0.5 * (mySize_x - width_attacker) - eX * height + eY * i * height;
2820 if(killnotify_deathtype[j] == DEATH_GENERIC)
2822 drawpic_skin(weap_pos, "notify_death", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2823 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2825 else if(killnotify_deathtype[j] == DEATH_NOAMMO)
2827 drawpic_skin(weap_pos, "notify_outofammo", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2828 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2830 else if(killnotify_deathtype[j] == DEATH_KILL)
2832 drawpic_skin(weap_pos, "notify_selfkill", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2833 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2835 else if(killnotify_deathtype[j] == DEATH_CAMP)
2837 drawpic_skin(weap_pos, "notify_camping", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2838 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2840 else if(killnotify_deathtype[j] == KILL_TEAM_RED)
2842 drawpic_skin(weap_pos, "notify_teamkill", '2 1 0' * height, '1 0 0', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2843 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2845 else if(killnotify_deathtype[j] == KILL_TEAM_BLUE)
2847 drawpic_skin(weap_pos, "notify_teamkill", '2 1 0' * height, '0 0 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2848 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2850 else if(killnotify_deathtype[j] == DEATH_DROWN)
2852 drawpic_skin(weap_pos, "notify_water", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2853 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2855 else if(killnotify_deathtype[j] == DEATH_SLIME)
2857 drawpic_skin(weap_pos, "notify_slime", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2858 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2860 else if(killnotify_deathtype[j] == DEATH_LAVA)
2862 drawpic_skin(weap_pos, "notify_lava", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2863 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2865 else if(killnotify_deathtype[j] == DEATH_FALL)
2867 drawpic_skin(weap_pos, "notify_fall", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2868 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2870 else if(killnotify_deathtype[j] == DEATH_SHOOTING_STAR)
2872 drawpic_skin(weap_pos, "notify_shootingstar", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2873 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2875 else if(killnotify_deathtype[j] == DEATH_HURTTRIGGER || killnotify_deathtype[j] == DEATH_CUSTOM)
2877 drawpic_skin(weap_pos, "notify_void", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2878 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2880 else if(killnotify_deathtype[j] == INFO_GOTFLAG)
2882 if(killnotify_victims[j] == "^1RED^7 flag")
2886 drawpic_skin(weap_pos, strcat("flag_", s, "_carrying"), '1 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2887 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2889 else if(killnotify_deathtype[j] == INFO_RETURNFLAG)
2891 if(killnotify_victims[j] == "^1RED^7 flag")
2895 drawpic_skin(weap_pos, strcat("flag_", s, "_taken"), '1 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2896 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2898 else if(killnotify_deathtype[j] == INFO_LOSTFLAG)
2900 if(killnotify_victims[j] == "^1RED^7 flag")
2904 drawpic_skin(weap_pos, strcat("flag_", s, "_lost"), '1 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2905 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2908 // X [did action to] Y
2913 attacker = textShortenToWidth("Player1", 0.5 * mySize_x - height, fontsize, stringwidth_colors);
2914 victim = textShortenToWidth("Player2", 0.5 * mySize_x - height, fontsize, stringwidth_colors);
2915 a = bound(0, (when - j) / 4, 1);
2919 attacker = textShortenToWidth(killnotify_attackers[j], 0.5 * mySize_x - height, fontsize, stringwidth_colors);
2920 victim = textShortenToWidth(killnotify_victims[j], 0.5 * mySize_x - height, fontsize, stringwidth_colors);
2922 width_attacker = stringwidth(attacker, TRUE, fontsize);
2923 width_victim = stringwidth(victim, TRUE, fontsize);
2924 pos_attacker = pos + eX * 0.5 * ((0.5 * mySize_x - height) - width_attacker) + eY * 0.5 * fontsize_y + eY * i * height;
2925 pos_victim = pos + eX * 0.5 * ((0.5 * mySize_x - height) - width_victim) + eY * 0.5 * fontsize_y + eX * 0.5 * mySize_x + eX * height + eY * i * height;
2926 weap_pos = pos + eX * 0.5 * mySize_x - eX * height + eY * i * height;
2928 if(hud_configure) // example actions for config mode
2930 drawpic_skin(weap_pos, strcat("weapon", "electro"), '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2931 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2932 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2934 else if(WEP_VALID(killnotify_deathtype[j]))
2936 self = get_weaponinfo(killnotify_deathtype[j]);
2937 drawpic_skin(weap_pos, strcat("weapon", self.netname), '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2938 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2939 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2941 else if(killnotify_deathtype[j] == KILL_TEAM_RED)
2943 drawpic_skin(weap_pos, "notify_teamkill", '2 1 0' * height, '1 0 0', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2944 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2945 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2947 else if(killnotify_deathtype[j] == KILL_TEAM_BLUE)
2949 drawpic_skin(weap_pos, "notify_teamkill", '2 1 0' * height, '0 0 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2950 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2951 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2953 else if(killnotify_deathtype[j] == DEATH_DROWN)
2955 drawpic_skin(weap_pos, "notify_water", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2956 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2957 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2959 else if(killnotify_deathtype[j] == DEATH_SLIME)
2961 drawpic_skin(weap_pos, "notify_slime", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2962 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2963 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2965 else if(killnotify_deathtype[j] == DEATH_LAVA)
2967 drawpic_skin(weap_pos, "notify_lava", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2968 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2969 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2971 else if(killnotify_deathtype[j] == DEATH_FALL)
2973 drawpic_skin(weap_pos, "notify_fall", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2974 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2975 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2977 else if(killnotify_deathtype[j] == DEATH_SHOOTING_STAR)
2979 drawpic_skin(weap_pos, "notify_shootingstar", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2980 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2981 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2983 else if(killnotify_deathtype[j] == DEATH_HURTTRIGGER || killnotify_deathtype[j] == DEATH_CUSTOM) // DEATH_CUSTOM is also void, right?
2985 drawpic_skin(weap_pos, "notify_void", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2986 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2987 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2998 if(cvar("hud_notify_info_top"))
3001 o = pos + eY * mySize_y - eY * 2 * height;
3003 if(spectatee_status && !intermission)
3005 //drawfont = hud_bigfont;
3006 if(spectatee_status == -1)
3009 s = GetPlayerName(spectatee_status - 1);
3011 //s = textShortenToWidth(s, mySize_y, 0.5 * height, stringwidth_colors);
3012 //drawcolorcodedstring(pos + eY * 0.25 * height, s, 0.5 * height, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3013 //drawfont = hud_font;
3015 // spectator text in the upper right corner
3016 if(spectatee_status == -1)
3017 s = strcat("^1Press ^3", getcommandkey("primary fire", "+attack"), "^1 to spectate");
3019 s = strcat("^1Press ^3", getcommandkey("primary fire", "+attack"), "^1 for another player");
3020 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3021 o += eY * fontsize_y;
3023 if(spectatee_status == -1)
3024 s = strcat("^1Use ^3", getcommandkey("next weapon", "weapnext"), "^1 or ^3", getcommandkey("previous weapon", "weapprev"), "^1 to change the speed");
3026 s = strcat("^1Press ^3", getcommandkey("secondary fire", "+attack2"), "^1 to observe");
3027 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3028 o += eY * fontsize_y;
3030 s = strcat("^1Press ^3", getcommandkey("server info", "+show_info"), "^1 for gamemode info");
3031 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3032 o += eY * fontsize_y;
3034 if(gametype == GAME_ARENA)
3035 s = "^1Wait for your turn to join";
3036 else if(gametype == GAME_LMS)
3039 sk = playerslots[player_localentnum - 1];
3040 if(sk.(scores[ps_primary]) >= 666)
3041 s = "^1Match has already begun";
3042 else if(sk.(scores[ps_primary]) > 0)
3043 s = "^1You have no more lives left";
3045 s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
3048 s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
3049 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3050 o += eY * fontsize_y;
3052 //show restart countdown:
3053 if (time < getstatf(STAT_GAMESTARTTIME)) {
3055 //we need to ceil, otherwise the countdown would be off by .5 when using round()
3056 countdown = ceil(getstatf(STAT_GAMESTARTTIME) - time);
3057 s = strcat("^1Game starts in ^3", ftos(countdown), "^1 seconds");
3058 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3059 o += eY * fontsize_y;
3062 if(warmup_stage && !intermission)
3064 s = "^2Currently in ^1warmup^2 stage!";
3065 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3066 o += eY * fontsize_y;
3070 if(mod(time, 1) >= 0.5)
3075 if(ready_waiting && !intermission && !spectatee_status)
3077 if(ready_waiting_for_me)
3080 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " to end warmup");
3082 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " once you are ready");
3087 s = strcat("^2Waiting for others to ready up to end warmup...");
3089 s = strcat("^2Waiting for others to ready up...");
3091 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3092 o += eY * fontsize_y;
3094 else if(warmup_stage && !intermission && !spectatee_status)
3096 s = strcat("^2Press ^3", getcommandkey("ready", "ready"), "^2 to end warmup");
3097 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3098 o += eY * fontsize_y;
3101 if(teamplay && !intermission && !spectatee_status && gametype != GAME_CA && teamnagger)
3103 float ts_min, ts_max;
3104 tm = teams.sort_next;
3107 for(; tm.sort_next; tm = tm.sort_next)
3109 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
3111 if(!ts_min) ts_min = tm.team_size;
3112 else ts_min = min(ts_min, tm.team_size);
3113 if(!ts_max) ts_max = tm.team_size;
3114 else ts_max = max(ts_max, tm.team_size);
3116 if ((ts_max - ts_min) > 1)
3118 s = strcat(blinkcolor, "Teamnumbers are unbalanced!");
3119 tm = GetTeam(myteam, false);
3121 if (tm.team != COLOR_SPECTATOR)
3122 if (tm.team_size == ts_max)
3123 s = strcat(s, " Press ^3", getcommandkey("team menu", "menu_showteamselect"), blinkcolor, " to adjust");
3125 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3126 o += eY * fontsize_y;
3132 s = "^7Press ^3ESC ^7to show HUD options.";
3133 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3134 o += eY * fontsize_y;
3135 s = "^3Doubleclick a panel for panel-specific options.";
3136 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3137 o += eY * fontsize_y;
3143 string seconds_tostring(float sec)
3146 minutes = floor(sec / 60);
3148 sec -= minutes * 60;
3151 s = ftos(100 + sec);
3153 return strcat(ftos(minutes), ":", substring(s, 1, 3));
3156 void HUD_Timer(void)
3158 float id = HUD_PANEL_TIMER;
3160 pos = HUD_Panel_GetPos(id);
3161 mySize = HUD_Panel_GetSize(id);
3163 HUD_Panel_DrawBg(id, pos, mySize, 0);
3165 padding = HUD_Panel_GetPadding(id);
3168 pos += '1 1 0' * padding;
3169 mySize -= '2 2 0' * padding;
3173 float timelimit, elapsedTime, timeleft, minutesLeft;
3175 timelimit = getstatf(STAT_TIMELIMIT);
3177 timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
3178 timeleft = ceil(timeleft);
3180 minutesLeft = floor(timeleft / 60);
3183 if(minutesLeft >= 5 || warmup_stage || timelimit == 0) //don't use red or yellow in warmup or when there is no timelimit
3184 timer_color = '1 1 1'; //white
3185 else if(minutesLeft >= 1)
3186 timer_color = '1 1 0'; //yellow
3188 timer_color = '1 0 0'; //red
3190 if (cvar("hud_timer_increment") || timelimit == 0 || warmup_stage) {
3191 if (time < getstatf(STAT_GAMESTARTTIME)) {
3192 //while restart is still active, show 00:00
3193 timer = seconds_tostring(0);
3195 elapsedTime = floor(time - getstatf(STAT_GAMESTARTTIME)); //127
3196 timer = seconds_tostring(elapsedTime);
3199 timer = seconds_tostring(timeleft);
3202 drawstring_aspect(pos, timer, mySize, mySize_y, timer_color, HUD_Panel_GetFgAlpha(HUD_PANEL_TIMER), DRAWFLAG_NORMAL);
3207 void HUD_Radar(void)
3209 float id = HUD_PANEL_RADAR;
3211 pos = HUD_Panel_GetPos(id);
3212 mySize = HUD_Panel_GetSize(id);
3214 HUD_Panel_DrawBg(id, pos, mySize, 0);
3216 padding = HUD_Panel_GetPadding(id);
3219 pos += '1 1 0' * padding;
3220 mySize -= '2 2 0' * padding;
3223 local float color1, color2; // color already declared as a global in hud.qc
3226 float scale2d, normalsize, bigsize;
3229 teamradar_origin2d = pos + 0.5 * mySize;
3230 teamradar_size2d = mySize;
3232 if(minimapname == "")
3235 teamradar_loadcvars();
3237 switch(hud_radar_zoommode)
3241 f = current_zoomfraction;
3244 f = 1 - current_zoomfraction;
3254 switch(hud_radar_rotation)
3257 teamradar_angle = view_angles_y - 90;
3260 teamradar_angle = 90 * hud_radar_rotation;
3264 scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
3265 teamradar_size2d = mySize;
3267 teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0'; // we always center
3269 // pixels per world qu to match the teamradar_size2d_x range in the longest dimension
3270 if(hud_radar_rotation == 0)
3272 // max-min distance must fit the radar in any rotation
3273 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen2d(mi_max - mi_min));
3277 vector c0, c1, c2, c3, span;
3278 c0 = rotate(mi_min, teamradar_angle * DEG2RAD);
3279 c1 = rotate(mi_max, teamradar_angle * DEG2RAD);
3280 c2 = rotate('1 0 0' * mi_min_x + '0 1 0' * mi_max_y, teamradar_angle * DEG2RAD);
3281 c3 = rotate('1 0 0' * mi_max_x + '0 1 0' * mi_min_y, teamradar_angle * DEG2RAD);
3283 span_x = max4(c0_x, c1_x, c2_x, c3_x) - min4(c0_x, c1_x, c2_x, c3_x);
3284 span_y = max4(c0_y, c1_y, c2_y, c3_y) - min4(c0_y, c1_y, c2_y, c3_y);
3286 // max-min distance must fit the radar in x=x, y=y
3288 teamradar_size2d_x * scale2d / (1.05 * span_x),
3289 teamradar_size2d_y * scale2d / (1.05 * span_y)
3293 normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / hud_radar_scale;
3294 if(bigsize > normalsize)
3295 normalsize = bigsize;
3299 + (1 - f) * normalsize;
3300 teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
3301 f * (mi_min + mi_max) * 0.5
3302 + (1 - f) * view_origin);
3304 color1 = GetPlayerColor(player_localentnum-1);
3305 rgb = GetTeamRGB(color1);
3314 draw_teamradar_background(hud_radar_background_alpha, hud_radar_foreground_alpha);
3316 for(tm = world; (tm = find(tm, classname, "radarlink")); )
3317 draw_teamradar_link(tm.origin, tm.velocity, tm.team);
3318 for(tm = world; (tm = findflags(tm, teamradar_icon, 0xFFFFFF)); )
3319 draw_teamradar_icon(tm.origin, tm.teamradar_icon, tm, tm.teamradar_color, HUD_Panel_GetFgAlpha(id));
3320 for(tm = world; (tm = find(tm, classname, "entcs_receiver")); )
3322 color2 = GetPlayerColor(tm.sv_entnum);
3323 //if(color == COLOR_SPECTATOR || color == color2)
3324 draw_teamradar_player(tm.origin, tm.angles, GetTeamRGB(color2));
3326 draw_teamradar_player(view_origin, view_angles, '1 1 1');
3328 drawresetcliparea();
3333 void HUD_Score(void)
3335 float id = HUD_PANEL_SCORE;
3337 pos = HUD_Panel_GetPos(id);
3338 mySize = HUD_Panel_GetSize(id);
3340 HUD_Panel_DrawBg(id, pos, mySize, 0);
3342 padding = HUD_Panel_GetPadding(id);
3345 pos += '1 1 0' * padding;
3346 mySize -= '2 2 0' * padding;
3349 float score, distribution, leader;
3350 float score_len, distr_len;
3351 vector distribution_color;
3353 me = (spectatee_status > 0) ? playerslots[spectatee_status - 1] : playerslots[player_localentnum - 1];
3355 // TODO... this (race part) still uses constant coordinates :/
3356 if((scores_flags[ps_primary] & SFL_TIME) && !teamplay) { // race/cts record display on HUD
3357 /*pl = players.sort_next;
3360 if(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)
3361 if(pl.scores[ps_primary] == 0)
3364 score = me.(scores[ps_primary]);
3366 float racemin, racesec, racemsec;
3367 float distsec, distmsec, minusplus;
3369 racemin = floor(score/(60 * TIME_FACTOR));
3370 racesec = floor((score - racemin*(60 * TIME_FACTOR))/TIME_FACTOR);
3371 racemsec = score - racemin*60*TIME_FACTOR - racesec*TIME_FACTOR;
3373 if (pl && ((!(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)) || score)) {
3374 // distribution display
3375 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
3377 if (distribution < TIME_FACTOR && distribution > -TIME_FACTOR)
3378 distmsec = fabs(distribution);
3380 distsec = floor(fabs(distribution)/TIME_FACTOR);
3381 distmsec = fabs(distribution) - distsec*TIME_FACTOR;
3382 if (distribution < 0)
3386 if (distribution <= 0) {
3387 distribution_color = eY;
3388 minusplus = 1; // minusplus 1: always prefix with minus sign
3391 distribution_color = eX;
3392 minusplus = 2; // minusplus 1: always prefix with plus sign
3394 HUD_DrawXNum(bottomright - '0 48 0' - '16 0 0' * TIME_DECIMALS, distmsec, -TIME_DECIMALS, 0, 16, distribution_color, 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3395 HUD_DrawXNum(bottomright - '68 48 0' - '16 0 0' * TIME_DECIMALS, distsec, 4, minusplus, 16, distribution_color, 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3396 drawpic_skin(bottomright - '10 48 0' - '16 0 0' * TIME_DECIMALS, "num_dot", '16 16 0', distribution_color, HUD_Panel_GetFgAlpha(id), DRAWFLAG_ADDITIVE);
3398 // race record display
3399 if (distribution <= 0 || distribution == score) // draw the highlight background behind the timer if we have the lead
3400 drawpic_skin(bottomright - '0 32 0' - '32 0 0' * (4 + TIME_DECIMALS), "num_leading_4", '0 28 0' + '32 0 0' * (4 + TIME_DECIMALS), '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3402 HUD_DrawXNum(bottomright - '0 32 0' - TIME_DECIMALS * '30 0 0', racemsec, -TIME_DECIMALS, 0, 30, '1 1 1', 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3403 HUD_DrawXNum(bottomright - '0 32 0' - TIME_DECIMALS * '30 0 0' - '66 0 0', racesec, -2, 0, 30, '1 1 1', 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3404 drawpic_skin(bottomright - '0 32 0' - TIME_DECIMALS * '30 0 0' - '18 0 0', "num_dot", '30 30 0', '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_ADDITIVE);
3406 HUD_DrawXNum(bottomright - '0 32 0' - TIME_DECIMALS * '30 0 0' - '132 0 0', racemin, -2, 0, 30, '1 1 1', 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3407 drawpic_skin(bottomright - '0 32 0' - TIME_DECIMALS * '30 0 0' - '84 0 0', "num_colon", '30 30 0', '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_ADDITIVE);
3409 } else if (!teamplay) { // non-teamgames
3410 // me vector := [team/connected frags id]
3411 pl = players.sort_next;
3418 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
3422 score = me.(scores[ps_primary]);
3426 if(distribution >= 5) {
3427 distribution_color = eY;
3429 } else if(distribution >= 0) {
3430 distribution_color = '1 1 1';
3432 } else if(distribution >= -5)
3433 distribution_color = '1 1 0';
3435 distribution_color = eX;
3437 score_len = strlen(ftos(score));
3438 distr_len = strlen(ftos(distribution));
3440 HUD_DrawXNum(pos + eX * mySize_x - eX * 3 * 0.33 * mySize_y, distribution, 3, 3, 0.33 * mySize_y, distribution_color, 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3442 drawpic_skin(pos + eX * mySize_x - eX * score_len * mySize_y - eX * 3 * 0.33 * mySize_y, strcat("num_leading_", ftos(score_len)), eX * score_len * mySize_y + eY * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3443 HUD_DrawXNum(pos + eX * mySize_x - eX * 3 * mySize_y - eX * 3 * 0.33 * mySize_y, score, 3, 0, mySize_y, distribution_color, 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3444 } else { // teamgames
3445 float max_fragcount;
3446 max_fragcount = -99;
3449 for(tm = teams.sort_next; tm; tm = tm.sort_next) {
3450 if(tm.team == COLOR_SPECTATOR || (!tm.team_size && !hud_configure)) // no players? don't display
3452 score = tm.(teamscores[ts_primary]);
3457 score_len = strlen(ftos(score));
3459 if (score > max_fragcount)
3460 max_fragcount = score;
3462 if(tm.team == myteam) {
3463 if (max_fragcount == score)
3466 drawpic_skin(pos + eX * mySize_x - eX * score_len * mySize_y - eX * 3 * 0.33 * mySize_y, strcat("num_leading_", ftos(score_len)), eX * score_len * mySize_y + eY * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3467 HUD_DrawXNum(pos + eX * mySize_x - eX * 3 * mySize_y - eX * 3 * 0.33 * mySize_y, score, 3, 0, mySize_y, GetTeamRGB(tm.team) * 0.8, 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3469 if (max_fragcount == score)
3472 drawpic_skin(pos + eX * mySize_x - eX * 0.33 * score_len * mySize_y + eY * 0.33 * mySize_y * teamnum, strcat("num_leading_", ftos(score_len)), eX * 0.33 * score_len * mySize_y + eY * 0.33 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3473 HUD_DrawXNum(pos + eX * mySize_x - eX * 3 * 0.33 * mySize_y + eY * 0.33 * mySize_y * teamnum, score, 3, 0, 0.33 * mySize_y, GetTeamRGB(tm.team) * 0.8, 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3482 void HUD_RaceTimer (void) {
3483 float id = HUD_PANEL_RACETIMER;
3485 pos = HUD_Panel_GetPos(id);
3486 mySize = HUD_Panel_GetSize(id);
3488 HUD_Panel_DrawBg(id, pos, mySize, 0);
3490 padding = HUD_Panel_GetPadding(id);
3493 pos += '1 1 0' * padding;
3494 mySize -= '2 2 0' * padding;
3497 drawfont = hud_bigfont;
3499 string s, forcetime;
3504 drawstring(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(s, FALSE, '0.60 0.60 0' * mySize_y), s, '0.60 0.60 0' * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3505 s = "^1Intermediate 1 (+15.42)";
3506 drawcolorcodedstring(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(s, TRUE, '1 1 0' * 0.20 * mySize_y) + eY * 0.60 * mySize_y, s, '1 1 0' * 0.20 * mySize_y, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3507 s = strcat("^1PENALTY: ", ftos_decimals(20 * 0.1, 1), " (missing a checkpoint)");
3508 drawcolorcodedstring(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(s, TRUE, '1 1 0' * 0.20 * mySize_y) + eY * 0.80 * mySize_y, s, '1 1 0' * 0.20 * mySize_y, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3510 else if(race_checkpointtime)
3512 a = bound(0, 2 - (time - race_checkpointtime), 1);
3515 if(a > 0) // just hit a checkpoint?
3517 if(race_checkpoint != 254)
3519 if(race_time && race_previousbesttime)
3520 s = MakeRaceString(race_checkpoint, TIME_DECODE(race_time) - TIME_DECODE(race_previousbesttime), 0, 0, race_previousbestname);
3522 s = MakeRaceString(race_checkpoint, 0, -1, 0, race_previousbestname);
3524 forcetime = TIME_ENCODED_TOSTRING(race_time);
3529 if(race_laptime && race_nextbesttime && race_nextcheckpoint != 254)
3531 a = bound(0, 2 - ((race_laptime + TIME_DECODE(race_nextbesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1);
3532 if(a > 0) // next one?
3534 s = MakeRaceString(race_nextcheckpoint, (time + TIME_DECODE(race_penaltyaccumulator)) - race_laptime, TIME_DECODE(race_nextbesttime), 0, race_nextbestname);
3539 if(s != "" && a > 0)
3541 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
3542 //drawcolorcodedstring(m - '0 16 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
3543 drawcolorcodedstring(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(s, TRUE, '1 1 0' * 0.2 * mySize_y) + eY * 0.6 * mySize_y, s, '1 1 0' * 0.2 * mySize_y, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
3546 if(race_penaltytime)
3548 a = bound(0, 2 - (time - race_penaltyeventtime), 1);
3551 s = strcat("^1PENALTY: ", ftos_decimals(race_penaltytime * 0.1, 1), " (", race_penaltyreason, ")");
3552 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
3553 //drawcolorcodedstring(m - '0 32 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
3554 drawcolorcodedstring(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(s, TRUE, '1 1 0' * 0.2 * mySize_y) + eY * 0.8 * mySize_y, s, '1 1 0' * 0.2 * mySize_y, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
3560 a = bound(0, (time - race_checkpointtime) / 0.5, 1);
3561 //drawstring_expanding(m - '16 0 0' * stringwidth(forcetime, FALSE), forcetime, '32 32 0', '1 1 1', HUD_Panel_GetFgAlpha(id), 0, a);
3562 drawstring_expanding(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(forcetime, FALSE, '1 1 0' * 0.6 * mySize_y), forcetime, '1 1 0' * 0.6 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id), 0, a);
3567 if(race_laptime && race_checkpoint != 255)
3569 s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime));
3570 //drawstring(m - '16 0 0' * stringwidth(s, FALSE), s, '32 32 0', '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
3571 drawstring(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(s, FALSE, '0.6 0.6 0' * mySize_y), s, '0.6 0.6 0' * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
3576 if(race_mycheckpointtime)
3578 a = bound(0, 2 - (time - race_mycheckpointtime), 1);
3579 s = MakeRaceString(race_mycheckpoint, TIME_DECODE(race_mycheckpointdelta), -!race_mycheckpointenemy, race_mycheckpointlapsdelta, race_mycheckpointenemy);
3580 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
3581 //drawcolorcodedstring(m - '0 16 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
3582 drawcolorcodedstring(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(s, TRUE, '1 1 0' * 0.2 * mySize_y) + eY * 0.6 * mySize_y, s, '1 1 0' * 0.2 * mySize_y, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
3584 if(race_othercheckpointtime && race_othercheckpointenemy != "")
3586 a = bound(0, 2 - (time - race_othercheckpointtime), 1);
3587 s = MakeRaceString(race_othercheckpoint, -TIME_DECODE(race_othercheckpointdelta), -!race_othercheckpointenemy, race_othercheckpointlapsdelta, race_othercheckpointenemy);
3588 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
3589 //drawcolorcodedstring(m - '0 0 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
3590 drawcolorcodedstring(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(s, TRUE, '1 1 0' * 0.2 * mySize_y) + eY * 0.6 * mySize_y, s, '1 1 0' * 0.2 * mySize_y, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
3593 if(race_penaltytime && !race_penaltyaccumulator)
3595 t = race_penaltytime * 0.1 + race_penaltyeventtime;
3596 a = bound(0, (1 + t - time), 1);
3600 s = strcat("^1PENALTY: ", ftos_decimals(t - time, 1), " (", race_penaltyreason, ")");
3602 s = strcat("^2PENALTY: 0.0 (", race_penaltyreason, ")");
3603 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
3604 //drawcolorcodedstring(m - '0 32 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
3605 drawcolorcodedstring(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(s, TRUE, '1 1 0' * 0.2 * mySize_y) + eY * 0.6 * mySize_y, s, '1 1 0' * 0.2 * mySize_y, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
3610 drawfont = hud_font;
3615 float vote_yescount;
3618 float vote_highlighted; // currently selected vote
3620 float vote_active; // is there an active vote?
3621 float vote_prev; // previous state of vote_active to check for a change
3623 float vote_change; // "time" when vote_active changed
3625 void HUD_VoteWindow(void)
3627 float id = HUD_PANEL_VOTE;
3629 pos = HUD_Panel_GetPos(id);
3630 mySize = HUD_Panel_GetSize(id);
3634 if(vote_active != vote_prev) {
3636 vote_prev = vote_active;
3639 if(vote_active || hud_configure)
3640 vote_alpha = bound(0, (time - vote_change) * 2, 1);
3642 vote_alpha = bound(0, 1 - (time - vote_change) * 2, 1);
3654 a = vote_alpha * bound(cvar_or("hud_vote_alreadyvoted_alpha", 0.75), 1 - vote_highlighted, 1);
3656 HUD_Panel_DrawBg(id, pos, mySize, a);
3658 padding = HUD_Panel_GetPadding(id);
3661 pos += '1 1 0' * padding;
3662 mySize -= '2 2 0' * padding;
3665 drawpic_skin(pos, "voteprogress_back", mySize, '1 1 1', a * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3667 s = "A vote has been called for: ";
3668 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_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3669 s = textShortenToWidth(vote_called_vote, mySize_x * 0.96, '1 1 0' * mySize_y*(1/5), stringwidth_colors); // TODO: broken?
3671 s = "Configure the HUD";
3672 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_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3674 // print the yes/no counts
3675 s = strcat("Yes: ", ftos(vote_yescount));
3676 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_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3677 s = strcat("No: ", ftos(vote_nocount));
3678 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_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3680 // draw the progress bars
3681 drawsetcliparea(pos_x, pos_y, mySize_x * 0.5 * (vote_yescount/vote_needed), mySize_y);
3682 drawpic_skin(pos, "voteprogress_prog", mySize, eY, a * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3684 drawsetcliparea(pos_x + mySize_x - mySize_x * 0.5 * (vote_nocount/vote_needed), pos_y, mySize_x * 0.5, mySize_y);
3685 drawpic_skin(pos, "voteprogress_prog", mySize, eX, a * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3687 // draw the highlights
3688 if(vote_highlighted == 1) {
3689 drawsetcliparea(pos_x, pos_y, mySize_x * 0.5, mySize_y);
3690 drawpic_skin(pos, "voteprogress_voted", mySize, eY, a * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3692 else if(vote_highlighted == 2) {
3693 drawsetcliparea(pos_x + 0.5 * mySize_x, pos_y, mySize_x * 0.5, mySize_y);
3694 drawpic_skin(pos, "voteprogress_voted", mySize, eX, a * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3697 drawresetcliparea();
3700 vote_highlighted = 0;
3704 // Mod icons panel (#10)
3707 float mod_active; // is there any active mod icon?
3709 // CTF HUD modicon section
3710 float redflag_prevframe, blueflag_prevframe; // status during previous frame
3711 float redflag_prevstatus, blueflag_prevstatus; // last remembered status
3712 float redflag_statuschange_time, blueflag_statuschange_time; // time when the status changed
3714 void HUD_Mod_CTF_Reset(void)
3716 redflag_prevstatus = blueflag_prevstatus = redflag_prevframe = blueflag_prevframe = redflag_statuschange_time = blueflag_statuschange_time = 0;
3719 void HUD_Mod_CTF(vector pos, vector mySize)
3721 vector redflag_pos, blueflag_pos;
3723 float f; // every function should have that
3725 float redflag, blueflag; // current status
3726 float redflag_statuschange_elapsedtime, blueflag_statuschange_elapsedtime; // time since the status changed
3729 stat_items = getstati(STAT_ITEMS);
3730 redflag = (stat_items/IT_RED_FLAG_TAKEN) & 3;
3731 blueflag = (stat_items/IT_BLUE_FLAG_TAKEN) & 3;
3733 if(redflag || blueflag)
3744 // when status CHANGES, set old status into prevstatus and current status into status
3745 if (redflag != redflag_prevframe)
3747 redflag_statuschange_time = time;
3748 redflag_prevstatus = redflag_prevframe;
3749 redflag_prevframe = redflag;
3752 if (blueflag != blueflag_prevframe)
3754 blueflag_statuschange_time = time;
3755 blueflag_prevstatus = blueflag_prevframe;
3756 blueflag_prevframe = blueflag;
3759 redflag_statuschange_elapsedtime = time - redflag_statuschange_time;
3760 blueflag_statuschange_elapsedtime = time - blueflag_statuschange_time;
3762 float BLINK_FACTOR = 0.15;
3763 float BLINK_BASE = 0.85;
3765 // RMS = sqrt(BLINK_BASE^2 + 0.5 * BLINK_FACTOR^2)
3767 // BLINK_BASE = sqrt(RMS^2 - 0.5 * BLINK_FACTOR^2)
3769 float BLINK_FREQ = 5; // circle frequency, = 2*pi*frequency in hertz
3771 string red_icon, red_icon_prevstatus;
3772 float red_alpha, red_alpha_prevstatus;
3773 red_alpha = red_alpha_prevstatus = 1;
3775 case 1: red_icon = "flag_red_taken"; break;
3776 case 2: red_icon = "flag_red_lost"; break;
3777 case 3: red_icon = "flag_red_carrying"; red_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3779 if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM2))
3780 red_icon = "flag_red_shielded";
3782 red_icon = string_null;
3785 switch(redflag_prevstatus) {
3786 case 1: red_icon_prevstatus = "flag_red_taken"; break;
3787 case 2: red_icon_prevstatus = "flag_red_lost"; break;
3788 case 3: red_icon_prevstatus = "flag_red_carrying"; red_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3791 red_icon_prevstatus = "flag_red_carrying"; // make it more visible
3792 else if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM2))
3793 red_icon_prevstatus = "flag_red_shielded";
3795 red_icon_prevstatus = string_null;
3799 string blue_icon, blue_icon_prevstatus;
3800 float blue_alpha, blue_alpha_prevstatus;
3801 blue_alpha = blue_alpha_prevstatus = 1;
3803 case 1: blue_icon = "flag_blue_taken"; break;
3804 case 2: blue_icon = "flag_blue_lost"; break;
3805 case 3: blue_icon = "flag_blue_carrying"; blue_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3807 if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM1))
3808 blue_icon = "flag_blue_shielded";
3810 blue_icon = string_null;
3813 switch(blueflag_prevstatus) {
3814 case 1: blue_icon_prevstatus = "flag_blue_taken"; break;
3815 case 2: blue_icon_prevstatus = "flag_blue_lost"; break;
3816 case 3: blue_icon_prevstatus = "flag_blue_carrying"; blue_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3819 blue_icon_prevstatus = "flag_blue_carrying"; // make it more visible
3820 else if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM1))
3821 blue_icon_prevstatus = "flag_blue_shielded";
3823 blue_icon_prevstatus = string_null;
3827 if(mySize_x > mySize_y) {
3828 if (myteam == COLOR_TEAM1) { // always draw own flag on left
3830 blueflag_pos = pos + eX * 0.5 * mySize_x;
3833 redflag_pos = pos + eX * 0.5 * mySize_x;
3835 flag_size = eX * 0.5 * mySize_x + eY * mySize_y;
3837 if (myteam == COLOR_TEAM1) { // always draw own flag on left
3839 blueflag_pos = pos + eY * 0.5 * mySize_y;
3842 redflag_pos = pos + eY * 0.5 * mySize_y;
3844 flag_size = eY * 0.5 * mySize_y + eX * mySize_x;
3847 f = bound(0, redflag_statuschange_elapsedtime*2, 1);
3848 if(red_icon_prevstatus && f < 1)
3849 drawpic_skin_expanding(redflag_pos, red_icon_prevstatus, flag_size, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * red_alpha_prevstatus, DRAWFLAG_NORMAL, f);
3851 drawpic_skin(redflag_pos, red_icon, flag_size, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * red_alpha * f, DRAWFLAG_NORMAL);
3853 f = bound(0, blueflag_statuschange_elapsedtime*2, 1);
3854 if(blue_icon_prevstatus && f < 1)
3855 drawpic_skin_expanding(blueflag_pos, blue_icon_prevstatus, flag_size, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * blue_alpha_prevstatus, DRAWFLAG_NORMAL, f);
3857 drawpic_skin(blueflag_pos, blue_icon, flag_size, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * blue_alpha * f, DRAWFLAG_NORMAL);
3860 // Keyhunt HUD modicon section
3861 float kh_runheretime;
3863 void HUD_Mod_KH_Reset(void)
3868 void HUD_Mod_KH(vector pos, vector mySize)
3870 mod_active = 1; // keyhunt should never hide the mod icons panel
3874 vector p, pa, kh_size, kh_asize;
3876 kh_keys = getstati(STAT_KH_KEYS);
3879 if(mySize_x > mySize_y)
3881 p_y = pos_y + 0.25 * mySize_y;
3882 pa = p - eY * 0.25 * mySize_y;
3884 kh_size_x = mySize_x * 0.25;
3885 kh_size_y = 0.75 * mySize_y;
3886 kh_asize_x = mySize_x * 0.25;
3887 kh_asize_y = mySize_y * 0.25;
3891 p_y = pos_y + 0.125 * mySize_y;
3892 pa = p - eY * 0.125 * mySize_y;
3894 kh_size_x = mySize_x * 0.5;
3895 kh_size_y = 0.375 * mySize_y;
3896 kh_asize_x = mySize_x * 0.5;
3897 kh_asize_y = mySize_y * 0.125;
3904 for(i = 0; i < 4; ++i)
3906 key = floor(kh_keys / pow(32, i)) & 31;
3908 if(keyteam == 30 && keycount <= 4)
3910 if(keyteam == myteam || keyteam == -1 || keyteam == 30)
3914 // this yields 8 exactly if "RUN HERE" shows
3919 kh_runheretime = time;
3920 pa_y -= fabs(sin((time - kh_runheretime) * 3.5)) * 6; // make the arrows jump in case of RUN HERE
3925 for(i = 0; i < 4; ++i)
3927 key = floor(kh_keys / pow(32, i)) & 31;
3940 default: // owned or dropped
3945 a = a * HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS);
3946 aa = aa * HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS);
3952 drawpic_skin(pa, "kh_redarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
3955 drawpic_skin(pa, "kh_bluearrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
3958 drawpic_skin(pa, "kh_yellowarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
3961 drawpic_skin(pa, "kh_pinkarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
3966 switch(i) // YAY! switch(i) inside a for loop for i. DailyWTF, here we come!
3969 drawpic_skin(p, "kh_red", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
3972 drawpic_skin(p, "kh_blue", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
3975 drawpic_skin(p, "kh_yellow", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
3978 drawpic_skin(p, "kh_pink", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
3982 if(mySize_x > mySize_y)
3984 p_x += 0.25 * mySize_x;
3985 pa_x += 0.25 * mySize_x;
3991 p_y = pos_y + 0.625 * mySize_y;
3992 pa_y = pos_y + 0.5 * mySize_y;
3998 p_x += 0.5 * mySize_x;
3999 pa_x += 0.5 * mySize_x;
4005 // Nexball HUD mod icon
4006 void HUD_Mod_NexBall(vector pos, vector mySize)
4008 float stat_items, nb_pb_starttime, dt, p;
4010 stat_items = getstati(STAT_ITEMS);
4011 nb_pb_starttime = getstatf(STAT_NB_METERSTART);
4013 if (stat_items & IT_KEY1)
4018 //Manage the progress bar if any
4019 if (nb_pb_starttime > 0)
4021 dt = mod(time - nb_pb_starttime, nb_pb_period);
4022 // one period of positive triangle
4023 p = 2 * dt / nb_pb_period;
4030 if(mySize_x > mySize_y)
4032 barsize = eX * p * mySize_x + eY * mySize_y;
4037 barsize = eX * mySize_x + eY * p * mySize_y;
4040 HUD_Panel_DrawProgressBar(pos, vertical, barsize, HUD_Panel_GetProgressBarColor("nexball"), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL);
4043 if (stat_items & IT_KEY1)
4044 drawpic_skin(pos, "nexball_carrying", eX * mySize_x + eY * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL);
4047 // Race/CTS HUD mod icons
4048 float crecordtime_prev; // last remembered crecordtime
4049 float crecordtime_change_time; // time when crecordtime last changed
4050 float srecordtime_prev; // last remembered srecordtime
4051 float srecordtime_change_time; // time when srecordtime last changed
4053 float race_status_time;
4054 float race_status_prev;
4055 string race_status_name_prev;
4056 void HUD_Mod_Race(vector pos, vector mySize)
4058 mod_active = 1; // race should never hide the mod icons panel
4060 me = playerslots[player_localentnum - 1];
4062 float f; // yet another function has this
4063 score = me.(scores[ps_primary]);
4065 if not((scores_flags[ps_primary] & SFL_TIME) && !teamplay) // race/cts record display on HUD
4066 return; // no records in the actual race
4068 drawfont = hud_bigfont;
4070 // clientside personal record
4072 if(gametype == GAME_CTS)
4076 t = stof(db_get(ClientProgsDB, strcat(shortmapname, rr, "time")));
4078 if(score && (score < t || !t)) {
4079 db_put(ClientProgsDB, strcat(shortmapname, rr, "time"), ftos(score));
4080 if(cvar("cl_autodemo_delete_keeprecords"))
4082 f = cvar("cl_autodemo_delete");
4084 cvar_set("cl_autodemo_delete", ftos(f)); // don't delete demo with new record!
4088 if(t != crecordtime_prev) {
4089 crecordtime_prev = t;
4090 crecordtime_change_time = time;
4092 f = time - crecordtime_change_time;
4095 drawstring_aspect(pos, "Personal best ", eX * 0.5 * mySize_x + eY * 0.25 * mySize_y, 0.15 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL);
4096 drawstring(pos + eY * 0.2 * mySize_y, TIME_ENCODED_TOSTRING(t), '1 1 0' * 0.2 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL);
4098 drawstring(pos, "Personal best ", '1 1 0' * 0.15 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL);
4099 drawstring(pos + eY * 0.2 * mySize_y, TIME_ENCODED_TOSTRING(t), '1 1 0' * 0.2 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL);
4100 drawstring_expanding(pos, "Personal best ", '1 1 0' * 0.15 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL, f);
4101 drawstring_expanding(pos + eY * 0.2 * mySize_y, TIME_ENCODED_TOSTRING(t), '1 1 0' * 0.2 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL, f);
4105 t = race_server_record;
4106 if(t != srecordtime_prev) {
4107 srecordtime_prev = t;
4108 srecordtime_change_time = time;
4110 f = time - srecordtime_change_time;
4113 drawstring(pos + eY * 0.5 * mySize_y, "Server best ", '1 1 0' * 0.15 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL);
4114 drawstring(pos + eY * 0.5 * mySize_y + eY * 0.2 * mySize_y, TIME_ENCODED_TOSTRING(t),'1 1 0' * 0.2 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL);
4116 drawstring(pos + eY * 0.5 * mySize_y, "Server best ", '1 1 0' * 0.15 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL);
4117 drawstring(pos + eY * 0.5 * mySize_y + eY * 0.2 * mySize_y, TIME_ENCODED_TOSTRING(t),'1 1 0' * 0.2 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL);
4118 drawstring_expanding(pos + eY * 0.5 * mySize_y, "Server best ", '1 1 0' * 0.15 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL, f);
4119 drawstring_expanding(pos + eY * 0.5 * mySize_y + eY * 0.2 * mySize_y, TIME_ENCODED_TOSTRING(t),'1 1 0' * 0.2 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL, f);
4122 if (race_status != race_status_prev || race_status_name != race_status_name_prev) {
4123 race_status_time = time + 5;
4124 race_status_prev = race_status;
4125 if (race_status_name_prev)
4126 strunzone(race_status_name_prev);
4127 race_status_name_prev = strzone(race_status_name);
4130 pos_x += mySize_x/2;
4133 a = bound(0, race_status_time - time, 1);
4136 s = textShortenToWidth(race_status_name, mySize_y, '1 1 0' * 0.1 * mySize_y, stringwidth_colors);
4140 rank = race_CheckName(race_status_name);
4142 rankname = race_PlaceName(rank);
4145 namepos = pos + '0.5 0.9 0' * mySize_y - eX * stringwidth(s, TRUE, '1 1 0' * 0.1 * mySize_y);
4147 rankpos = pos + '0.5 0.25 0' * mySize_y - eX * stringwidth(rankname, TRUE, '1 1 0' * 0.15 * mySize_y);
4149 if(race_status == 0)
4150 drawpic_skin(pos, "race_newfail", '1 1 0' * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * a, DRAWFLAG_NORMAL);
4151 else if(race_status == 1) {
4152 drawpic_skin(pos, "race_newtime", '1 1 0' * 0.9 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * a, DRAWFLAG_NORMAL);
4153 drawcolorcodedstring(namepos, s, '1 1 0' * 0.1 * mySize_y, HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * a, DRAWFLAG_NORMAL);
4154 drawstring(rankpos, rankname, '1 1 0' * 0.15 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * a, DRAWFLAG_NORMAL);
4155 } else if(race_status == 2) {
4156 if(race_status_name == GetPlayerName(player_localentnum -1) || !race_myrank || race_myrank < rank)
4157 drawpic_skin(pos, "race_newrankgreen", '1 1 0' * 0.9 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * a, DRAWFLAG_NORMAL);
4159 drawpic_skin(pos, "race_newrankyellow", '1 1 0' * 0.9 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * a, DRAWFLAG_NORMAL);
4160 drawcolorcodedstring(namepos, s, '1 1 0' * 0.1 * mySize_y, HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * a, DRAWFLAG_NORMAL);
4161 drawstring(rankpos, rankname, '1 1 0' * 0.15 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * a, DRAWFLAG_NORMAL);
4162 } else if(race_status == 3) {
4163 drawpic_skin(pos, "race_newrecordserver", '1 1 0' * 0.9 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * a, DRAWFLAG_NORMAL);
4164 drawcolorcodedstring(namepos, s, '1 1 0' * 0.1 * mySize_y, HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * a, DRAWFLAG_NORMAL);
4165 drawstring(rankpos, rankname, '1 1 0' * 0.15 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * a, DRAWFLAG_NORMAL);
4168 if (race_status_time - time <= 0) {
4169 race_status_prev = -1;
4171 if(race_status_name)
4172 strunzone(race_status_name);
4173 race_status_name = string_null;
4174 if(race_status_name_prev)
4175 strunzone(race_status_name_prev);
4176 race_status_name_prev = string_null;
4178 drawfont = hud_font;
4181 float mod_prev; // previous state of mod_active to check for a change
4183 float mod_change; // "time" when mod_active changed
4185 void HUD_ModIcons(void)
4187 if (gametype != GAME_KEYHUNT && gametype != GAME_CTF && gametype != GAME_NEXBALL && gametype != GAME_CTS && gametype != GAME_RACE && !hud_configure)
4190 float id = HUD_PANEL_MODICONS;
4192 pos = HUD_Panel_GetPos(id);
4193 mySize = HUD_Panel_GetSize(id);
4195 if(mod_active != mod_prev) {
4197 mod_prev = mod_active;
4200 if(mod_active || hud_configure)
4201 mod_alpha = bound(0, (time - mod_change) * 2, 1);
4203 mod_alpha = bound(0, 1 - (time - mod_change) * 2, 1);
4206 HUD_Panel_DrawBg(id, pos, mySize, mod_alpha);
4209 padding = HUD_Panel_GetPadding(id);
4212 pos += '1 1 0' * padding;
4213 mySize -= '2 2 0' * padding;
4216 // these MUST be ran in order to update mod_active
4217 if(gametype == GAME_KEYHUNT)
4218 HUD_Mod_KH(pos, mySize);
4219 else if(gametype == GAME_CTF || hud_configure)
4220 HUD_Mod_CTF(pos, mySize); // forcealpha only needed for ctf icons, as only they are shown in config mode
4221 else if(gametype == GAME_NEXBALL)
4222 HUD_Mod_NexBall(pos, mySize);
4223 else if(gametype == GAME_CTS || gametype == GAME_RACE)
4224 HUD_Mod_Race(pos, mySize);
4227 // Draw pressed keys (#11)
4229 void HUD_DrawPressedKeys(void)
4231 float id = HUD_PANEL_PRESSEDKEYS;
4233 pos = HUD_Panel_GetPos(id);
4234 mySize = HUD_Panel_GetSize(id);
4236 HUD_Panel_DrawBg(id, pos, mySize, 0);
4238 padding = HUD_Panel_GetPadding(id);
4241 pos += '1 1 0' * padding;
4242 mySize -= '2 2 0' * padding;
4246 keysize = eX * mySize_x * (1/3) + eY * mySize_y * 0.5;
4249 pressedkeys = getstatf(STAT_PRESSED_KEYS);
4250 drawpic_skin(pos, ((pressedkeys & KEY_CROUCH) ? "key_crouch_inv.tga" : "key_crouch.tga"), keysize, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
4251 drawpic_skin(pos + eX * mySize_x * (1/3), ((pressedkeys & KEY_FORWARD) ? "key_forward_inv.tga" : "key_forward.tga"), keysize, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
4252 drawpic_skin(pos + eX * mySize_x * (2/3), ((pressedkeys & KEY_JUMP) ? "key_jump_inv.tga" : "key_jump.tga"), keysize, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
4253 drawpic_skin(pos + eY * 0.5 * mySize_y, ((pressedkeys & KEY_LEFT) ? "key_left_inv.tga" : "key_left.tga"), keysize, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
4254 drawpic_skin(pos + eY * 0.5 * mySize_y + eX * mySize_x * (1/3), ((pressedkeys & KEY_BACKWARD) ? "key_backward_inv.tga" : "key_backward.tga"), keysize, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
4255 drawpic_skin(pos + eY * 0.5 * mySize_y + eX * mySize_x * (2/3), ((pressedkeys & KEY_RIGHT) ? "key_right_inv.tga" : "key_right.tga"), keysize, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
4258 // Handle chat as a panel (#12)
4262 float id = HUD_PANEL_CHAT;
4264 pos = HUD_Panel_GetPos(id);
4265 mySize = HUD_Panel_GetSize(id);
4267 HUD_Panel_DrawBg(id, pos, mySize, 0);
4269 padding = HUD_Panel_GetPadding(id);
4272 pos += '1 1 0' * padding;
4273 mySize -= '2 2 0' * padding;
4276 cvar_set("con_chatrect", "1");
4278 cvar_set("con_chatrect_x", ftos(pos_x/vid_conwidth));
4279 cvar_set("con_chatrect_y", ftos(pos_y/vid_conheight));
4281 cvar_set("con_chatwidth", ftos(mySize_x/vid_conwidth));
4282 cvar_set("con_chat", ftos(floor(mySize_y/cvar("con_chatsize") - 0.5)));
4287 chatsize = cvar("con_chatsize");
4288 cvar_set("con_chatrect_x", "9001"); // over 9000, we'll fake it instead for more control over alpha and such
4290 for(i = 0; i < cvar("con_chat"); ++i)
4292 if(i == cvar("con_chat") - 1)
4293 a = HUD_Panel_GetFgAlpha(id);
4295 a = HUD_Panel_GetFgAlpha(id) * floor(((i + 1) * 7 + cvar("con_chattime"))/45);
4296 drawcolorcodedstring(pos + eY * i * chatsize, textShortenToWidth("^3Player^7: This is the chat area.", mySize_x, '1 1 0' * chatsize, stringwidth_colors), '1 1 0' * chatsize, a, DRAWFLAG_NORMAL);
4301 // Engine info panel (#13)
4308 float frametimeavg1; // 1 frame ago
4309 float frametimeavg2; // 2 frames ago
4310 void HUD_EngineInfo(void)
4312 float id = HUD_PANEL_ENGINEINFO;
4314 pos = HUD_Panel_GetPos(id);
4315 mySize = HUD_Panel_GetSize(id);
4317 HUD_Panel_DrawBg(id, pos, mySize, 0);
4319 padding = HUD_Panel_GetPadding(id);
4322 pos += '1 1 0' * padding;
4323 mySize -= '2 2 0' * padding;
4326 if(cvar("hud_engineinfo_framecounter_exponentialmovingaverage"))
4328 frametimeavg = (frametimeavg + frametimeavg1 + frametimeavg2 + frametime)/4; // average three frametimes into framecounter for slightly more stable fps readings :P
4329 frametimeavg2 = frametimeavg1;
4330 frametimeavg1 = frametimeavg;
4333 weight = cvar("hud_engineinfo_framecounter_exponentialmovingaverage_new_weight");
4334 if(frametime > 0.0001) // filter out insane values which sometimes seem to occur and throw off the average? If you are getting 10,000 fps or more, then you don't need a framerate counter.
4336 if(fabs(prevfps - (1/frametimeavg)) > prevfps * cvar("hud_engineinfo_framecounter_exponentialmovingaverage_instantupdate_change_threshold")) // if there was a big jump in fps, just force prevfps at current (1/frametime) to make big updates instant
4337 prevfps = (1/frametime);
4338 prevfps = (1 - weight) * prevfps + weight * (1/frametimeavg); // framecounter just used so there's no need for a new variable, think of it as "frametime average"
4344 if(time - prevfps_time > cvar("hud_engineinfo_framecounter_time"))
4346 prevfps = framecounter/cvar("hud_engineinfo_framecounter_time");
4348 prevfps_time = time;
4353 color = HUD_Get_Num_Color (prevfps, 100);
4354 drawstring_aspect(pos, strcat("FPS: ", ftos_decimals(prevfps, cvar("hud_engineinfo_framecounter_decimals"))), mySize, mySize_y, color, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
4362 void HUD_ShowSpeed(void)
4365 float pos, conversion_factor;
4366 string speed, zspeed, unit;
4368 switch(cvar("cl_showspeed_unit"))
4373 conversion_factor = 1.0;
4377 conversion_factor = 1.0;
4381 conversion_factor = 0.0254;
4385 conversion_factor = 0.0254 * 3.6;
4389 conversion_factor = 0.0254 * 3.6 * 0.6213711922;
4393 conversion_factor = 0.0254 * 1.943844492; // 1 m/s = 1.943844492 knots, because 1 knot = 1.852 km/h
4397 speed = strcat(ftos(floor( vlen(pmove_vel - pmove_vel_z * '0 0 1') * conversion_factor + 0.5 )), unit);
4399 numsize_x = numsize_y = cvar("cl_showspeed_size");
4400 pos = (vid_conheight - numsize_y) * cvar("cl_showspeed_position");
4402 drawfont = hud_bigfont;
4403 drawstringcenter(eX + pos * eY, speed, numsize, '1 1 1', hud_fg_alpha, DRAWFLAG_NORMAL);
4405 if (cvar("cl_showspeed_z") == 1) {
4406 zspeed = strcat(ftos(fabs(floor( pmove_vel_z * conversion_factor + 0.5 ))), unit);
4407 drawstringcenter(eX + pos * eY + numsize_y * eY, zspeed, numsize * 0.5, '1 1 1', hud_fg_alpha, DRAWFLAG_NORMAL);
4410 drawfont = hud_font;
4413 vector acc_prevspeed;
4417 void HUD_ShowAcceleration(void)
4419 float acceleration, sz, scale, alpha, f;
4420 vector pos, top, rgb;
4421 top_x = vid_conwidth/2;
4424 f = time - acc_prevtime;
4425 if(cvar("cl_showacceleration_z"))
4426 acceleration = (vlen(pmove_vel) - vlen(acc_prevspeed)) * (1 / f);
4428 acceleration = (vlen(pmove_vel - '0 0 1' * pmove_vel_z) - vlen(acc_prevspeed - '0 0 1' * acc_prevspeed_z)) * (1 / f);
4429 acc_prevspeed = pmove_vel;
4430 acc_prevtime = time;
4432 f = bound(0, f * 10, 1);
4433 acc_avg = acc_avg * (1 - f) + acceleration * f;
4434 acceleration = acc_avg / getstatf(STAT_MOVEVARS_MAXSPEED);
4436 pos = top - sz/2 * eY + (cvar("cl_showacceleration_position") * vid_conheight) * eY;
4438 sz = cvar("cl_showacceleration_size");
4439 scale = cvar("cl_showacceleration_scale");
4440 alpha = cvar("cl_showacceleration_alpha");
4441 if (cvar("cl_showacceleration_color_custom"))
4442 rgb = stov(cvar_string("cl_showacceleration_color"));
4445 if (acceleration < 0) {
4446 rgb = '1 .5 .5' - '0 .5 .5' * bound(0, -acceleration * 0.2, 1);
4447 } else if (acceleration > 0) {
4448 rgb = '.5 1 .5' - '.5 0 .5' * bound(0, +acceleration * 0.2, 1);
4452 if (acceleration > 0)
4453 HUD_Panel_DrawProgressBar(pos, 0, acceleration * scale * '40 0 0' + sz * eY, rgb, alpha * hud_fg_alpha, DRAWFLAG_NORMAL);
4454 else if (acceleration < 0)
4455 HUD_Panel_DrawProgressBar(pos + acceleration * scale * '40 0 0', 0, -acceleration * scale * '40 0 0' + sz * eY, rgb, alpha * hud_fg_alpha, DRAWFLAG_NORMAL);
4458 void HUD_Reset (void)
4460 // reset gametype specific icons
4461 if(gametype == GAME_KEYHUNT)
4463 else if(gametype == GAME_CTF)
4464 HUD_Mod_CTF_Reset();
4467 void HUD_Main (void)
4469 if(disable_menu_alphacheck == 1)
4470 menu_fade_alpha = 1;
4472 menu_fade_alpha = (1 - cvar("_menu_alpha"));
4473 hud_fg_alpha = cvar("hud_fg_alpha");
4475 hud_border_thickness = bound(0, cvar("hud_border_thickness"), 5);
4476 hud_accuracy_border_thickness = bound(0, cvar_or("hud_accuracy_border_thickness", 1), 5);
4477 hud_color_bg_team = cvar("hud_color_bg_team");
4479 hud_fontsize = HUD_GetFontsize("hud_fontsize");
4480 hud_fontsize_spec = HUD_GetFontsize("hud_fontsize_spec");
4482 hud_configure = cvar("_hud_configure");
4486 // HUD configure visible grid
4487 if(hud_configure && cvar("hud_configure_grid") && cvar("hud_configure_grid_alpha"))
4491 for(i = 0; i < 1/bound(0.005, cvar("hud_configure_grid_x"), 0.2); ++i)
4493 drawfill(eX * i * vid_conwidth * bound(0.005, cvar("hud_configure_grid_x"), 0.2), eX + eY * vid_conheight, '0.5 0.5 0.5', cvar("hud_configure_grid_alpha"), DRAWFLAG_NORMAL);
4496 for(i = 0; i < 1/bound(0.005, cvar("hud_configure_grid_y"), 0.2); ++i)
4498 drawfill(eY * i * vid_conheight * bound(0.005, cvar("hud_configure_grid_y"), 0.2), eY + eX * vid_conwidth, '0.5 0.5 0.5', cvar("hud_configure_grid_alpha"), DRAWFLAG_NORMAL);
4502 if(cvar_string("hud_dock") != "")
4503 drawpic('0 0 0', strcat("gfx/hud/", cvar_string("hud_skin"), "/", cvar_string("hud_dock")), eX * vid_conwidth + eY * vid_conheight, HUD_Panel_Dock_GetColor(), cvar("hud_dock_alpha") * menu_fade_alpha, DRAWFLAG_NORMAL); // no aspect ratio forcing on dock...
4505 if(HUD_Panel_CheckActive(HUD_PANEL_RADAR) || hud_configure)
4506 if(cvar_string("hud_radar") != "0" && (cvar("hud_radar") == 2 || teamplay))
4508 if(HUD_Panel_CheckActive(HUD_PANEL_WEAPONICONS) || hud_configure)
4510 if(HUD_Panel_CheckActive(HUD_PANEL_INVENTORY) || hud_configure)
4512 if(HUD_Panel_CheckActive(HUD_PANEL_POWERUPS) || hud_configure)
4514 if(HUD_Panel_CheckActive(HUD_PANEL_HEALTHARMOR) || hud_configure)
4516 if(HUD_Panel_CheckActive(HUD_PANEL_NOTIFY) || hud_configure)
4518 if(HUD_Panel_CheckActive(HUD_PANEL_TIMER) || hud_configure)
4520 if(HUD_Panel_CheckActive(HUD_PANEL_SCORE) || hud_configure)
4522 if(HUD_Panel_CheckActive(HUD_PANEL_RACETIMER) || hud_configure)
4523 if(gametype == GAME_RACE || gametype == GAME_CTS || hud_configure)
4525 if(HUD_Panel_CheckActive(HUD_PANEL_VOTE) || hud_configure)
4527 if(HUD_Panel_CheckActive(HUD_PANEL_MODICONS) || hud_configure)
4530 if(HUD_Panel_CheckActive(HUD_PANEL_PRESSEDKEYS) || hud_configure)
4531 if(spectatee_status > 0 || cvar("hud_pressedkeys") >= 2 || hud_configure)
4532 HUD_DrawPressedKeys();
4533 if(HUD_Panel_CheckActive(HUD_PANEL_CHAT) || hud_configure)
4536 cvar_set("con_chatrect", "0");
4537 if(HUD_Panel_CheckActive(HUD_PANEL_ENGINEINFO) || hud_configure)
4540 // TODO hud_'ify these
4541 if (cvar("cl_showspeed"))
4543 if (cvar("cl_showacceleration"))
4544 HUD_ShowAcceleration();
4546 if (hud_configure && spectatee_status) // try to join if we are in hud_configure mode, but still spectating (in order to get rid of motd and such)
4547 localcmd("cmd selectteam auto; cmd join\n");
4549 if (!hud_configure) // hud config mode disabled, enable normal alpha stuff again
4550 disable_menu_alphacheck = 0;