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) // draw whole image as it is
19 drawpic(theOrigin, pic, theSize, theColor, theAlpha, 0);
22 if (theBorderSize_x == 0 && theBorderSize_y == 0) // no border
24 // draw only the central part
25 drawsubpic(theOrigin, theSize, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0);
32 //pic = draw_UseSkinFor(pic);
33 width = eX * theSize_x;
34 height = eY * theSize_y;
35 if(theSize_x <= theBorderSize_x * 2)
37 // not wide enough... draw just left and right then
38 bW = eX * (0.25 * theSize_x / (theBorderSize_x * 2));
39 if(theSize_y <= theBorderSize_y * 2)
41 // not high enough... draw just corners
42 bH = eY * (0.25 * theSize_y / (theBorderSize_y * 2));
43 drawsubpic(theOrigin, width * 0.5 + height * 0.5, pic, '0 0 0', bW + bH, theColor, theAlpha, 0);
44 drawsubpic(theOrigin + width * 0.5, width * 0.5 + height * 0.5, pic, eX - bW, bW + bH, theColor, theAlpha, 0);
45 drawsubpic(theOrigin + height * 0.5, width * 0.5 + height * 0.5, pic, eY - bH, bW + bH, theColor, theAlpha, 0);
46 drawsubpic(theOrigin + theSize * 0.5, width * 0.5 + height * 0.5, pic, eX + eY - bW - bH, bW + bH, theColor, theAlpha, 0);
50 dY = theBorderSize_x * eY;
51 drawsubpic(theOrigin, width * 0.5 + dY, pic, '0 0 0', '0 0.25 0' + bW, theColor, theAlpha, 0);
52 drawsubpic(theOrigin + width * 0.5, width * 0.5 + dY, pic, '0 0 0' + eX - bW, '0 0.25 0' + bW, theColor, theAlpha, 0);
53 drawsubpic(theOrigin + dY, width * 0.5 + height - 2 * dY, pic, '0 0.25 0', '0 0.5 0' + bW, theColor, theAlpha, 0);
54 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);
55 drawsubpic(theOrigin + height - dY, width * 0.5 + dY, pic, '0 0.75 0', '0 0.25 0' + bW, theColor, theAlpha, 0);
56 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);
61 if(theSize_y <= theBorderSize_y * 2)
63 // not high enough... draw just top and bottom then
64 bH = eY * (0.25 * theSize_y / (theBorderSize_y * 2));
65 dX = theBorderSize_x * eX;
66 drawsubpic(theOrigin, dX + height * 0.5, pic, '0 0 0', '0.25 0 0' + bH, theColor, theAlpha, 0);
67 drawsubpic(theOrigin + dX, width - 2 * dX + height * 0.5, pic, '0.25 0 0', '0.5 0 0' + bH, theColor, theAlpha, 0);
68 drawsubpic(theOrigin + width - dX, dX + height * 0.5, pic, '0.75 0 0', '0.25 0 0' + bH, theColor, theAlpha, 0);
69 drawsubpic(theOrigin + height * 0.5, dX + height * 0.5, pic, '0 0 0' + eY - bH, '0.25 0 0' + bH, theColor, theAlpha, 0);
70 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);
71 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);
75 dX = theBorderSize_x * eX;
76 dY = theBorderSize_x * eY;
77 drawsubpic(theOrigin, dX + dY, pic, '0 0 0', '0.25 0.25 0', theColor, theAlpha, 0);
78 drawsubpic(theOrigin + dX, width - 2 * dX + dY, pic, '0.25 0 0', '0.5 0.25 0', theColor, theAlpha, 0);
79 drawsubpic(theOrigin + width - dX, dX + dY, pic, '0.75 0 0', '0.25 0.25 0', theColor, theAlpha, 0);
80 drawsubpic(theOrigin + dY, dX + height - 2 * dY, pic, '0 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0);
81 drawsubpic(theOrigin + dY + dX, width - 2 * dX + height - 2 * dY, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0);
82 drawsubpic(theOrigin + dY + width - dX, dX + height - 2 * dY, pic, '0.75 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0);
83 drawsubpic(theOrigin + height - dY, dX + dY, pic, '0 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
84 drawsubpic(theOrigin + height - dY + dX, width - 2 * dX + dY, pic, '0.25 0.75 0', '0.5 0.25 0', theColor, theAlpha, 0);
85 drawsubpic(theOrigin + height - dY + width - dX, dX + dY, pic, '0.75 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
90 vector HUD_Get_Num_Color (float x, float maxvalue)
95 color_x = sin(2*M_PI*time);
97 color_z = sin(2*M_PI*time);
99 else if(x > maxvalue * 0.75) {
100 color_x = 0.4 - (x-150)*0.02 * 0.4; //red value between 0.4 -> 0
101 color_y = 0.9 + (x-150)*0.02 * 0.1; // green value between 0.9 -> 1
104 else if(x > maxvalue * 0.5) {
105 color_x = 1 - (x-100)*0.02 * 0.6; //red value between 1 -> 0.4
106 color_y = 1 - (x-100)*0.02 * 0.1; // green value between 1 -> 0.9
107 color_z = 1 - (x-100)*0.02; // blue value between 1 -> 0
109 else if(x > maxvalue * 0.25) {
112 color_z = 0.2 + (x-50)*0.02 * 0.8; // blue value between 0.2 -> 1
114 else if(x > maxvalue * 0.1) {
116 color_y = (x-20)*90/27/100; // green value between 0 -> 1
117 color_z = (x-20)*90/27/100 * 0.2; // blue value between 0 -> 0.2
125 blinkingamt = (1 - x/maxvalue/0.25);
128 color_x = color_x - color_x * blinkingamt * sin(2*M_PI*time);
129 color_y = color_y - color_y * blinkingamt * sin(2*M_PI*time);
130 color_z = color_z - color_z * blinkingamt * sin(2*M_PI*time);
135 float stringwidth_colors(string s, vector theSize)
137 return stringwidth(s, TRUE, theSize);
140 float stringwidth_nocolors(string s, vector theSize)
142 return stringwidth(s, FALSE, theSize);
145 void drawstringright(vector position, string text, vector scale, vector rgb, float theAlpha, float flag)
147 position_x -= 2 / 3 * strlen(text) * scale_x;
148 drawstring(position, text, scale, rgb, theAlpha, flag);
151 void drawstringcenter(vector position, string text, vector scale, vector rgb, float theAlpha, float flag)
153 position_x = 0.5 * (vid_conwidth - 0.6025 * strlen(text) * scale_x);
154 drawstring(position, text, scale, rgb, theAlpha, flag);
157 // return the string of the given race place
158 string race_PlaceName(float pos) {
166 return sprintf(_("%dth"), pos);
169 // return the string of the onscreen race timer
170 string MakeRaceString(float cp, float mytime, float histime, float lapdelta, string hisname)
178 if(histime == 0) // goal hit
182 timestr = strcat("+", ftos_decimals(+mytime, TIME_DECIMALS));
192 timestr = strcat("-", ftos_decimals(-mytime, TIME_DECIMALS));
198 lapstr = sprintf(_(" (-%dL)"), lapdelta);
201 else if(lapdelta < 0)
203 lapstr = sprintf(_(" (+%dL)"), -lapdelta);
207 else if(histime > 0) // anticipation
209 if(mytime >= histime)
210 timestr = strcat("+", ftos_decimals(mytime - histime, TIME_DECIMALS));
212 timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(histime));
222 cpname = _("Start line");
224 cpname = _("Finish line");
226 cpname = sprintf(_("Intermediate %d"), cp);
228 cpname = _("Finish line");
231 return strcat(col, cpname);
232 else if(hisname == "")
233 return strcat(col, sprintf(_("%s (%s)"), cpname, timestr));
235 return strcat(col, sprintf(_("%s (%s %s)"), cpname, timestr, strcat(hisname, col, lapstr)));
238 // Check if the given name already exist in race rankings? In that case, where? (otherwise return 0)
239 float race_CheckName(string net_name) {
241 for (i=RANKINGS_CNT-1;i>=0;--i)
242 if(grecordholder[i] == net_name)
247 float GetPlayerColorForce(float i)
252 return stof(getplayerkeyvalue(i, "colors")) & 15;
255 float GetPlayerColor(float i)
257 if not(playerslots[i].gotscores) // unconnected
259 else if(stof(getplayerkeyvalue(i, "frags")) == FRAGS_SPECTATOR)
262 return GetPlayerColorForce(i);
265 string GetPlayerName(float i)
267 return ColorTranslateRGB(getplayerkeyvalue(i, "name"));
277 // draw the background/borders
278 #define HUD_Panel_DrawBg(theAlpha)\
280 draw_BorderPicture(panel_pos - '1 1 0' * panel_bg_border, panel_bg, panel_size + '1 1 0' * 2 * panel_bg_border, panel_bg_color, panel_bg_alpha * theAlpha, '1 1 0' * (panel_bg_border/BORDER_MULTIPLIER))
282 //basically the same code of draw_ButtonPicture and draw_VertButtonPicture for the menu
283 void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, float length_ratio, float vertical, float baralign, vector theColor, float theAlpha, float drawflag)
285 if(!length_ratio || !theAlpha)
291 if(length_ratio < -1)
294 else if(length_ratio < 0)
298 vector width, height;
300 pic = strcat(hud_skin_path, "/", pic, "_vertical");
301 if(precache_pic(pic) == "") {
302 pic = "gfx/hud/default/progressbar_vertical";
305 if (baralign == 1) // bottom align
306 theOrigin_y += (1 - length_ratio) * theSize_y;
307 else if (baralign == 2) // center align
308 theOrigin_y += 0.5 * (1 - length_ratio) * theSize_y;
309 else if (baralign == 3) // center align, positive values down, negative up
312 if (length_ratio > 0)
313 theOrigin_y += theSize_y;
316 theOrigin_y += (1 + length_ratio) * theSize_y;
317 length_ratio = -length_ratio;
320 theSize_y *= length_ratio;
323 width = eX * theSize_x;
324 height = eY * theSize_y;
325 if(theSize_y <= theSize_x * 2)
327 // button not high enough
328 // draw just upper and lower part then
329 square = eY * theSize_y * 0.5;
330 bH = eY * (0.25 * theSize_y / (theSize_x * 2));
331 drawsubpic(theOrigin, square + width, pic, '0 0 0', eX + bH, theColor, theAlpha, drawflag);
332 drawsubpic(theOrigin + square, square + width, pic, eY - bH, eX + bH, theColor, theAlpha, drawflag);
336 square = eY * theSize_x;
337 drawsubpic(theOrigin, width + square, pic, '0 0 0', '1 0.25 0', theColor, theAlpha, drawflag);
338 drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0 0.25 0', '1 0.5 0', theColor, theAlpha, drawflag);
339 drawsubpic(theOrigin + height - square, width + square, pic, '0 0.75 0', '1 0.25 0', theColor, theAlpha, drawflag);
342 pic = strcat(hud_skin_path, "/", pic);
343 if(precache_pic(pic) == "") {
344 pic = "gfx/hud/default/progressbar";
347 if (baralign == 1) // right align
348 theOrigin_x += (1 - length_ratio) * theSize_x;
349 else if (baralign == 2) // center align
350 theOrigin_x += 0.5 * (1 - length_ratio) * theSize_x;
351 else if (baralign == 3) // center align, positive values on the right, negative on the left
354 if (length_ratio > 0)
355 theOrigin_x += theSize_x;
358 theOrigin_x += (1 + length_ratio) * theSize_x;
359 length_ratio = -length_ratio;
362 theSize_x *= length_ratio;
365 width = eX * theSize_x;
366 height = eY * theSize_y;
367 if(theSize_x <= theSize_y * 2)
369 // button not wide enough
370 // draw just left and right part then
371 square = eX * theSize_x * 0.5;
372 bW = eX * (0.25 * theSize_x / (theSize_y * 2));
373 drawsubpic(theOrigin, square + height, pic, '0 0 0', eY + bW, theColor, theAlpha, drawflag);
374 drawsubpic(theOrigin + square, square + height, pic, eX - bW, eY + bW, theColor, theAlpha, drawflag);
378 square = eX * theSize_y;
379 drawsubpic(theOrigin, height + square, pic, '0 0 0', '0.25 1 0', theColor, theAlpha, drawflag);
380 drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0.25 0 0', '0.5 1 0', theColor, theAlpha, drawflag);
381 drawsubpic(theOrigin + width - square, height + square, pic, '0.75 0 0', '0.25 1 0', theColor, theAlpha, drawflag);
386 void HUD_Panel_DrawHighlight(vector pos, vector mySize, vector color, float theAlpha, float drawflag)
392 pic = strcat(hud_skin_path, "/num_leading");
393 if(precache_pic(pic) == "") {
394 pic = "gfx/hud/default/num_leading";
397 drawsubpic(pos, eX * min(mySize_x * 0.5, mySize_y) + eY * mySize_y, pic, '0 0 0', '0.25 1 0', color, theAlpha, drawflag);
398 if(mySize_x/mySize_y > 2)
399 drawsubpic(pos + eX * mySize_y, eX * (mySize_x - 2 * mySize_y) + eY * mySize_y, pic, '0.25 0 0', '0.5 1 0', color, theAlpha, drawflag);
400 drawsubpic(pos + eX * mySize_x - eX * min(mySize_x * 0.5, mySize_y), eX * min(mySize_x * 0.5, mySize_y) + eY * mySize_y, pic, '0.75 0 0', '0.25 1 0', color, theAlpha, drawflag);
405 entity weaponorder[WEP_MAXCOUNT];
406 void weaponorder_swap(float i, float j, entity pass)
410 weaponorder[i] = weaponorder[j];
414 string weaponorder_cmp_str;
415 float weaponorder_cmp(float i, float j, entity pass)
418 ai = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[i].weapon), 0);
419 aj = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[j].weapon), 0);
420 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)
423 float GetAmmoStat(float i)
427 case 0: return STAT_SHELLS;
428 case 1: return STAT_NAILS;
429 case 2: return STAT_ROCKETS;
430 case 3: return STAT_CELLS;
431 case 4: return STAT_FUEL;
436 float GetAmmoTypeForWep(float i)
440 case WEP_SHOTGUN: return 0;
441 case WEP_UZI: return 1;
442 case WEP_GRENADE_LAUNCHER: return 2;
443 case WEP_MINE_LAYER: return 2;
444 case WEP_ELECTRO: return 3;
445 case WEP_CRYLINK: return 3;
446 case WEP_HLAC: return 3;
447 case WEP_MINSTANEX: return 3;
448 case WEP_NEX: return 3;
449 case WEP_RIFLE: return 1;
450 case WEP_HAGAR: return 2;
451 case WEP_ROCKET_LAUNCHER: return 2;
452 case WEP_SEEKER: return 2;
453 case WEP_FIREBALL: return 4;
454 case WEP_HOOK: return 3;
459 void HUD_Weapons(void)
462 WEPSET_DECLARE_A(weapons_stat);
463 WEPSET_COPY_AS(weapons_stat);
464 float i, f, a, j, factor;
465 float screen_ar, center_x, center_y;
466 float weapon_count, weapon_id;
467 float row, column, rows, columns;
468 float aspect = autocvar_hud_panel_weapons_aspect;
470 float show_accuracy = false, panel_weapon_accuracy;
472 float timeout = autocvar_hud_panel_weapons_timeout;
473 float timein_effect_length = autocvar_hud_panel_weapons_timeout_speed_in; //? 0.375 : 0);
474 float timeout_effect_length = autocvar_hud_panel_weapons_timeout_speed_out; //? 0.75 : 0);
476 float ammo_type, ammo_full;
477 float barsize_x = 0, barsize_y = 0, baroffset_x = 0, baroffset_y = 0;
478 vector ammo_color = '1 0 1';
479 float ammo_alpha = 1;
481 float when = autocvar_hud_panel_weapons_complainbubble_time;
482 float fadetime = autocvar_hud_panel_weapons_complainbubble_fadetime;
484 vector weapon_pos, weapon_size;
485 local noref vector old_panel_size; // fteqcc sucks
488 // check to see if we want to continue
489 if(hud != HUD_NORMAL) { return; }
491 if(!autocvar__hud_configure)
493 if((!autocvar_hud_panel_weapons) || (spectatee_status == -1))
495 else if(timeout && time >= weapontime + timeout + timeout_effect_length && ((autocvar_hud_panel_weapons_timeout_effect != 1) && !(autocvar_hud_panel_weapons_timeout_fadebgmin + autocvar_hud_panel_weapons_timeout_fadefgmin)))
497 weaponprevtime = time;
502 hud_configure_active_panel = HUD_PANEL_WEAPONS;
504 // update generic hud functions
505 HUD_Panel_UpdateCvars(weapons);
506 HUD_Panel_ApplyFadeAlpha();
508 draw_beginBoldFont();
510 // figure out weapon order (how the weapons are sorted) // TODO make this configurable
511 if(weaponorder_bypriority != autocvar_cl_weaponpriority || !weaponorder[0])
514 if(weaponorder_bypriority)
515 strunzone(weaponorder_bypriority);
516 if(weaponorder_byimpulse)
517 strunzone(weaponorder_byimpulse);
519 weaponorder_bypriority = strzone(autocvar_cl_weaponpriority);
520 weaponorder_byimpulse = strzone(W_FixWeaponOrder_BuildImpulseList(W_FixWeaponOrder_ForceComplete(W_NumberWeaponOrder(weaponorder_bypriority))));
521 weaponorder_cmp_str = strcat(" ", weaponorder_byimpulse, " ");
524 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
526 self = get_weaponinfo(i);
527 if(self.impulse >= 0)
529 weaponorder[weapon_cnt] = self;
533 for(i = weapon_cnt; i < WEP_MAXCOUNT; ++i)
534 weaponorder[i] = world;
535 heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, world);
537 weaponorder_cmp_str = string_null;
540 // determine which weapons are going to be shown
541 if (autocvar_hud_panel_weapons_onlyowned)
543 if(autocvar__hud_configure)
545 if (WEPSET_EMPTY_A(weapons_stat))
546 for(i = WEP_FIRST; i <= WEP_LAST; i += floor((WEP_LAST-WEP_FIRST)/5))
547 WEPSET_OR_AW(weapons_stat, i);
549 if(menu_enabled != 2)
550 HUD_Panel_DrawBg(1); // also draw the bg of the entire panel
553 // do we own this weapon?
555 for(i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
556 if(WEPSET_CONTAINS_AW(weapons_stat, weaponorder[i].weapon))
559 // add it anyway if weaponcomplain is shown
560 if((!autocvar__hud_configure)
561 && (autocvar_hud_panel_weapons_complainbubble
562 && time - complain_weapon_time < when + fadetime))
565 // might as well commit suicide now, no reason to live ;)
566 if (weapon_count == 0) { return; }
568 // reduce size of the panel
569 if (panel_size_y > panel_size_x)
571 old_panel_size_y = panel_size_y;
572 panel_size_y *= weapon_count / WEP_COUNT;
573 panel_pos_y += (old_panel_size_y - panel_size_y) / 2;
577 old_panel_size_x = panel_size_x;
578 panel_size_x *= weapon_count / WEP_COUNT;
579 panel_pos_x += (old_panel_size_x - panel_size_x) / 2;
583 weapon_count = WEP_COUNT;
585 // animation for fading in/out the panel respectively when not in use
586 if(!autocvar__hud_configure)
588 if (timeout && time >= weapontime + timeout) // apply timeout effect if needed
590 f = bound(0, (time - (weapontime + timeout)) / timeout_effect_length, 1);
592 // fade the panel alpha
593 if(autocvar_hud_panel_weapons_timeout_effect == 1)
595 panel_bg_alpha *= (autocvar_hud_panel_weapons_timeout_fadebgmin * f + (1 - f));
596 panel_fg_alpha *= (autocvar_hud_panel_weapons_timeout_fadefgmin * f + (1 - f));
598 else if(autocvar_hud_panel_weapons_timeout_effect == 3)
600 panel_bg_alpha *= (1 - f);
601 panel_fg_alpha *= (1 - f);
604 // move the panel off the screen
605 if (autocvar_hud_panel_weapons_timeout_effect == 2 || autocvar_hud_panel_weapons_timeout_effect == 3)
607 f *= f; // for a cooler movement
608 center_x = panel_pos_x + panel_size_x/2;
609 center_y = panel_pos_y + panel_size_y/2;
610 screen_ar = vid_conwidth/vid_conheight;
611 if (center_x/center_y < screen_ar) //bottom left
613 if ((vid_conwidth - center_x)/center_y < screen_ar) //bottom
614 panel_pos_y += f * (vid_conheight - panel_pos_y);
616 panel_pos_x -= f * (panel_pos_x + panel_size_x);
620 if ((vid_conwidth - center_x)/center_y < screen_ar) //right
621 panel_pos_x += f * (vid_conwidth - panel_pos_x);
623 panel_pos_y -= f * (panel_pos_y + panel_size_y);
626 weaponprevtime = time - (1 - f) * timein_effect_length;
628 else if (timeout && time < weaponprevtime + timein_effect_length) // apply timein effect if needed
630 f = bound(0, (time - weaponprevtime) / timein_effect_length, 1);
632 // fade the panel alpha
633 if(autocvar_hud_panel_weapons_timeout_effect == 1)
635 panel_bg_alpha *= (autocvar_hud_panel_weapons_timeout_fadebgmin * (1 - f) + f);
636 panel_fg_alpha *= (autocvar_hud_panel_weapons_timeout_fadefgmin * (1 - f) + f);
638 else if(autocvar_hud_panel_weapons_timeout_effect == 3)
640 panel_bg_alpha *= (f);
641 panel_fg_alpha *= (f);
644 // move the panel back on screen
645 if (autocvar_hud_panel_weapons_timeout_effect == 2 || autocvar_hud_panel_weapons_timeout_effect == 3)
647 f *= f; // for a cooler movement
649 center_x = panel_pos_x + panel_size_x/2;
650 center_y = panel_pos_y + panel_size_y/2;
651 screen_ar = vid_conwidth/vid_conheight;
652 if (center_x/center_y < screen_ar) //bottom left
654 if ((vid_conwidth - center_x)/center_y < screen_ar) //bottom
655 panel_pos_y += f * (vid_conheight - panel_pos_y);
657 panel_pos_x -= f * (panel_pos_x + panel_size_x);
661 if ((vid_conwidth - center_x)/center_y < screen_ar) //right
662 panel_pos_x += f * (vid_conwidth - panel_pos_x);
664 panel_pos_y -= f * (panel_pos_y + panel_size_y);
670 // draw the background, then change the virtual size of it to better fit other items inside
674 panel_pos += '1 1 0' * panel_bg_padding;
675 panel_size -= '2 2 0' * panel_bg_padding;
678 // after the sizing and animations are done, update the other values
679 rows = panel_size_y/panel_size_x;
680 rows = bound(1, floor((sqrt(4 * aspect * rows * weapon_count + rows * rows) + rows + 0.5) / 2), weapon_count);
681 columns = ceil(weapon_count/rows);
682 weapon_size = eX * panel_size_x*(1/columns) + eY * panel_size_y*(1/rows);
684 // calculate position/size for visual bar displaying ammount of ammo status
685 if (autocvar_hud_panel_weapons_ammo)
687 ammo_color = stov(autocvar_hud_panel_weapons_ammo_color);
688 ammo_alpha = panel_fg_alpha * autocvar_hud_panel_weapons_ammo_alpha;
690 if(weapon_size_x/weapon_size_y > aspect)
692 barsize_x = aspect * weapon_size_y;
693 barsize_y = weapon_size_y;
694 baroffset_x = (weapon_size_x - barsize_x) / 2;
698 barsize_y = 1/aspect * weapon_size_x;
699 barsize_x = weapon_size_x;
700 baroffset_y = (weapon_size_y - barsize_y) / 2;
704 if(autocvar_hud_panel_weapons_accuracy && acc_levels)
706 show_accuracy = true;
707 if (acc_col[0] == '-1 0 0')
708 for (i = 0; i < acc_levels; ++i)
709 acc_col[i] = stov(cvar_string(strcat("accuracy_color", ftos(i))));
713 for(i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
715 // retrieve information about the current weapon to be drawn
716 self = weaponorder[i];
717 weapon_id = self.impulse;
719 // skip if this weapon doesn't exist
720 if (!self || self.impulse < 0) { continue; }
722 // skip this weapon if we don't own it (and onlyowned is enabled)-- or if weapons_complainbubble is showing for this weapon
723 if (autocvar_hud_panel_weapons_onlyowned
724 && !(WEPSET_CONTAINS_AW(weapons_stat, self.weapon)
725 || (self.weapon == complain_weapon
726 && time - complain_weapon_time < when + fadetime
727 && autocvar_hud_panel_weapons_complainbubble)))
730 // figure out the drawing position of weapon
731 weapon_pos = (panel_pos
732 + eX * column * weapon_size_x
733 + eY * row * weapon_size_y);
735 // draw background behind currently selected weapon
736 if(self.weapon == switchweapon)
737 drawpic_aspect_skin(weapon_pos, "weapon_current_bg", weapon_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
739 // draw the weapon accuracy
742 panel_weapon_accuracy = weapon_accuracy[self.weapon-WEP_FIRST];
743 if(panel_weapon_accuracy >= 0)
745 // find the max level lower than weapon_accuracy
747 while ( j && panel_weapon_accuracy < acc_lev[j] )
750 // inject color j+1 in color j, how much depending on how much weapon_accuracy is higher than level j
751 factor = (panel_weapon_accuracy - acc_lev[j]) / (acc_lev[j+1] - acc_lev[j]);
753 color = color + factor * (acc_col[j+1] - color);
755 drawpic_aspect_skin(weapon_pos, "weapon_accuracy", weapon_size, color, panel_fg_alpha, DRAWFLAG_NORMAL);
759 // drawing all the weapon items
760 if(WEPSET_CONTAINS_AW(weapons_stat, self.weapon))
762 // draw the weapon image
763 drawpic_aspect_skin(weapon_pos, strcat("weapon", self.netname), weapon_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
765 // draw weapon label string
766 switch(autocvar_hud_panel_weapons_label)
768 case 1: // weapon number
769 drawstring(weapon_pos, ftos(weapon_id), '1 1 0' * 0.5 * weapon_size_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
773 drawstring(weapon_pos, getcommandkey(ftos(weapon_id), strcat("weapon_group_", ftos(weapon_id))), '1 1 0' * 0.5 * weapon_size_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
776 case 3: // weapon name
777 drawstring(weapon_pos, self.netname, '1 1 0' * 0.5 * weapon_size_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
784 // draw ammo status bar
785 if(autocvar_hud_panel_weapons_ammo && self.weapon != WEP_TUBA && self.weapon != WEP_LASER && self.weapon != WEP_PORTO)
788 ammo_type = GetAmmoTypeForWep(self.weapon);
790 a = getstati(GetAmmoStat(ammo_type)); // how much ammo do we have?
795 case 0: ammo_full = autocvar_hud_panel_weapons_ammo_full_shells; break;
796 case 1: ammo_full = autocvar_hud_panel_weapons_ammo_full_nails; break;
797 case 2: ammo_full = autocvar_hud_panel_weapons_ammo_full_rockets; break;
798 case 3: ammo_full = autocvar_hud_panel_weapons_ammo_full_cells; break;
799 case 4: ammo_full = autocvar_hud_panel_weapons_ammo_full_fuel; break;
800 default: ammo_full = 60;
804 weapon_pos_x + baroffset_x,
805 weapon_pos_y + baroffset_y,
806 barsize_x * bound(0, a/ammo_full, 1),
808 drawpic_aspect_skin(weapon_pos, "weapon_ammo", weapon_size, ammo_color, ammo_alpha, DRAWFLAG_NORMAL);
813 else // draw a "ghost weapon icon" if you don't have the weapon
815 drawpic_aspect_skin(weapon_pos, strcat("weapon", self.netname), weapon_size, '0 0 0', panel_fg_alpha * 0.5, DRAWFLAG_NORMAL);
818 // draw the complain message
819 if(time - complain_weapon_time < when + fadetime && self.weapon == complain_weapon && autocvar_hud_panel_weapons_complainbubble)
822 a = ((complain_weapon_time + when > time) ? 1 : bound(0, (complain_weapon_time + when + fadetime - time) / fadetime, 1));
824 a = ((complain_weapon_time + when > time) ? 1 : 0);
828 if(complain_weapon_type == 0) {
829 s = _("Out of ammo");
830 color = stov(autocvar_hud_panel_weapons_complainbubble_color_outofammo);
832 else if(complain_weapon_type == 1) {
834 color = stov(autocvar_hud_panel_weapons_complainbubble_color_donthave);
837 s = _("Unavailable");
838 color = stov(autocvar_hud_panel_weapons_complainbubble_color_unavailable);
840 float padding = autocvar_hud_panel_weapons_complainbubble_padding;
841 drawpic_aspect_skin(weapon_pos + '1 1 0' * padding, "weapon_complainbubble", weapon_size - '2 2 0' * padding, color, a * panel_fg_alpha, DRAWFLAG_NORMAL);
842 drawstring_aspect(weapon_pos + '1 1 0' * padding, s, weapon_size - '2 2 0' * padding, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
845 // continue with new position for the next weapon
860 float GetAmmoItemCode(float i)
864 case 0: return IT_SHELLS;
865 case 1: return IT_NAILS;
866 case 2: return IT_ROCKETS;
867 case 3: return IT_CELLS;
868 case 4: return IT_FUEL;
873 string GetAmmoPicture(float i)
877 case 0: return "ammo_shells";
878 case 1: return "ammo_bullets";
879 case 2: return "ammo_rockets";
880 case 3: return "ammo_cells";
881 case 4: return "ammo_fuel";
886 void DrawAmmoItem(vector myPos, vector mySize, float itemcode, float currently_selected, float infinite_ammo)
889 if(autocvar__hud_configure)
891 currently_selected = (itemcode == 2); //rockets always selected
892 a = 31 + mod(itemcode*93, 128);
895 a = getstati(GetAmmoStat(itemcode)); // how much ammo do we have of type itemcode?
899 color = '0 0.5 0.75';
906 if(currently_selected)
911 vector picpos, numpos;
912 if(autocvar_hud_panel_ammo_iconalign)
915 picpos = myPos + eX * 2 * mySize_y;
919 numpos = myPos + eX * mySize_y;
923 if (currently_selected)
924 drawpic_aspect_skin(myPos, "ammo_current_bg", mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
926 if(a > 0 && autocvar_hud_panel_ammo_progressbar)
927 HUD_Panel_DrawProgressBar(myPos + eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize_x, mySize - eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize_x, autocvar_hud_panel_ammo_progressbar_name, a/autocvar_hud_panel_ammo_maxammo, 0, 0, color, autocvar_hud_progressbar_alpha * panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
929 if(autocvar_hud_panel_ammo_text)
931 if(a > 0 || infinite_ammo)
932 drawstring_aspect(numpos, ftos(a), eX * (2/3) * mySize_x + eY * mySize_y, color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
933 else // "ghost" ammo count
934 drawstring_aspect(numpos, ftos(a), eX * (2/3) * mySize_x + eY * mySize_y, '0 0 0', panel_fg_alpha * theAlpha * 0.5, DRAWFLAG_NORMAL);
936 if(a > 0 || infinite_ammo)
937 drawpic_aspect_skin(picpos, GetAmmoPicture(itemcode), '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
938 else // "ghost" ammo icon
939 drawpic_aspect_skin(picpos, GetAmmoPicture(itemcode), '1 1 0' * mySize_y, '0 0 0', panel_fg_alpha * theAlpha * 0.5, DRAWFLAG_NORMAL);
944 if(hud != HUD_NORMAL) return;
945 if(!autocvar__hud_configure)
947 if(!autocvar_hud_panel_ammo) return;
948 if(spectatee_status == -1) return;
951 hud_configure_active_panel = HUD_PANEL_AMMO;
953 HUD_Panel_UpdateCvars(ammo);
954 HUD_Panel_ApplyFadeAlpha();
956 draw_beginBoldFont();
965 pos += '1 1 0' * panel_bg_padding;
966 mySize -= '2 2 0' * panel_bg_padding;
969 float rows = 0, columns, row, column;
971 if (autocvar_hud_panel_ammo_onlycurrent)
975 rows = mySize_y/mySize_x;
976 rows = bound(1, floor((sqrt(4 * (3/1) * rows * AMMO_COUNT + rows * rows) + rows + 0.5) / 2), AMMO_COUNT);
977 // ^^^ ammo item aspect goes here
979 columns = ceil(AMMO_COUNT/rows);
981 ammo_size = eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows);
984 local vector offset = '0 0 0'; // fteqcc sucks
986 if(ammo_size_x/ammo_size_y > 3)
988 newSize = 3 * ammo_size_y;
989 offset_x = ammo_size_x - newSize;
991 ammo_size_x = newSize;
995 newSize = 1/3 * ammo_size_x;
996 offset_y = ammo_size_y - newSize;
998 ammo_size_y = newSize;
1001 float i, stat_items, currently_selected, infinite_ammo;
1002 infinite_ammo = FALSE;
1003 if (autocvar_hud_panel_ammo_onlycurrent)
1005 if(autocvar__hud_configure)
1007 DrawAmmoItem(pos, ammo_size, 2, true, FALSE); //show rockets
1011 stat_items = getstati(STAT_ITEMS, 0, 24);
1012 if (stat_items & IT_UNLIMITED_WEAPON_AMMO)
1013 infinite_ammo = TRUE;
1014 for (i = 0; i < AMMO_COUNT; ++i) {
1015 currently_selected = stat_items & GetAmmoItemCode(i);
1016 if (currently_selected)
1018 DrawAmmoItem(pos, ammo_size, i, true, infinite_ammo);
1026 stat_items = getstati(STAT_ITEMS, 0, 24);
1027 if (stat_items & IT_UNLIMITED_WEAPON_AMMO)
1028 infinite_ammo = TRUE;
1030 for (i = 0; i < AMMO_COUNT; ++i) {
1031 currently_selected = stat_items & GetAmmoItemCode(i);
1032 DrawAmmoItem(pos + eX * column * (ammo_size_x + offset_x) + eY * row * (ammo_size_y + offset_y), ammo_size, i, currently_selected, infinite_ammo);
1037 column = column + 1;
1045 void DrawNumIcon_expanding(vector myPos, vector mySize, float x, string icon, float vertical, float icon_right_align, vector color, float theAlpha, float fadelerp)
1047 vector newPos = '0 0 0', newSize = '0 0 0';
1048 vector picpos, numpos;
1052 if(mySize_y/mySize_x > 2)
1054 newSize_y = 2 * mySize_x;
1055 newSize_x = mySize_x;
1057 newPos_y = myPos_y + (mySize_y - newSize_y) / 2;
1062 newSize_x = 1/2 * mySize_y;
1063 newSize_y = mySize_y;
1065 newPos_x = myPos_x + (mySize_x - newSize_x) / 2;
1069 if(icon_right_align)
1072 picpos = newPos + eY * newSize_x;
1077 numpos = newPos + eY * newSize_x;
1081 drawpic_aspect_skin(picpos, icon, newSize, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
1082 // make number smaller than icon, it looks better
1083 // reduce only y to draw numbers with different number of digits with the same y size
1084 numpos_y += newSize_y * ((1 - 0.7) / 2);
1086 drawstring_aspect(numpos, ftos(x), newSize, color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
1090 if(mySize_x/mySize_y > 3)
1092 newSize_x = 3 * mySize_y;
1093 newSize_y = mySize_y;
1095 newPos_x = myPos_x + (mySize_x - newSize_x) / 2;
1100 newSize_y = 1/3 * mySize_x;
1101 newSize_x = mySize_x;
1103 newPos_y = myPos_y + (mySize_y - newSize_y) / 2;
1107 if(icon_right_align) // right align
1110 picpos = newPos + eX * 2 * newSize_y;
1114 numpos = newPos + eX * newSize_y;
1118 // NOTE: newSize_x is always equal to 3 * mySize_y so we can use
1119 // '2 1 0' * newSize_y instead of eX * (2/3) * newSize_x + eY * newSize_y
1120 drawstring_aspect_expanding(numpos, ftos(x), '2 1 0' * newSize_y, color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL, fadelerp);
1121 drawpic_aspect_skin_expanding(picpos, icon, '1 1 0' * newSize_y, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL, fadelerp);
1124 void DrawNumIcon(vector myPos, vector mySize, float x, string icon, float vertical, float icon_right_align, vector color, float theAlpha)
1126 DrawNumIcon_expanding(myPos, mySize, x, icon, vertical, icon_right_align, color, theAlpha, 0);
1131 void HUD_Powerups(void)
1133 float strength_time, shield_time, superweapons_time;
1134 if(!autocvar__hud_configure)
1136 if(!autocvar_hud_panel_powerups) return;
1137 if(spectatee_status == -1) return;
1138 if not(getstati(STAT_ITEMS, 0, 24) & (IT_STRENGTH | IT_INVINCIBLE | IT_SUPERWEAPON)) return;
1139 if (getstati(STAT_HEALTH) <= 0) return;
1141 strength_time = bound(0, getstatf(STAT_STRENGTH_FINISHED) - time, 99);
1142 shield_time = bound(0, getstatf(STAT_INVINCIBLE_FINISHED) - time, 99);
1143 superweapons_time = bound(0, getstatf(STAT_SUPERWEAPONS_FINISHED) - time, 99);
1145 if (getstati(STAT_ITEMS, 0, 24) & IT_UNLIMITED_SUPERWEAPONS)
1146 superweapons_time = 99; // force max
1148 // prevent stuff to show up on mismatch that will be fixed next frame
1149 if (!(getstati(STAT_ITEMS, 0, 24) & IT_SUPERWEAPON))
1150 superweapons_time = 0;
1154 hud_configure_active_panel = HUD_PANEL_POWERUPS;
1158 superweapons_time = 13;
1161 HUD_Panel_UpdateCvars(powerups);
1162 HUD_Panel_ApplyFadeAlpha();
1164 draw_beginBoldFont();
1168 mySize = panel_size;
1170 HUD_Panel_DrawBg(bound(0, max(strength_time, shield_time, superweapons_time), 1));
1171 if(panel_bg_padding)
1173 pos += '1 1 0' * panel_bg_padding;
1174 mySize -= '2 2 0' * panel_bg_padding;
1177 float panel_ar = mySize_x/mySize_y;
1178 float is_vertical = (panel_ar < 1);
1179 vector shield_offset = '0 0 0', strength_offset = '0 0 0', superweapons_offset = '0 0 0';
1181 float superweapons_is = -1;
1183 if(superweapons_time)
1188 superweapons_is = 0;
1190 superweapons_is = 2;
1195 superweapons_is = 1;
1197 superweapons_is = 2;
1201 // FIXME handle superweapons here
1202 if(superweapons_is == 0)
1204 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
1206 mySize_x *= (1.0 / 3.0);
1207 superweapons_offset_x = mySize_x;
1208 if (autocvar_hud_panel_powerups_flip)
1209 shield_offset_x = 2*mySize_x;
1211 strength_offset_x = 2*mySize_x;
1215 mySize_y *= (1.0 / 3.0);
1216 superweapons_offset_y = mySize_y;
1217 if (autocvar_hud_panel_powerups_flip)
1218 shield_offset_y = 2*mySize_y;
1220 strength_offset_y = 2*mySize_y;
1225 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
1228 if (autocvar_hud_panel_powerups_flip)
1229 shield_offset_x = mySize_x;
1231 strength_offset_x = mySize_x;
1236 if (autocvar_hud_panel_powerups_flip)
1237 shield_offset_y = mySize_y;
1239 strength_offset_y = mySize_y;
1243 float shield_baralign, strength_baralign, superweapons_baralign;
1244 float shield_iconalign, strength_iconalign, superweapons_iconalign;
1246 if (autocvar_hud_panel_powerups_flip)
1248 strength_baralign = (autocvar_hud_panel_powerups_baralign == 2 || autocvar_hud_panel_powerups_baralign == 1);
1249 shield_baralign = (autocvar_hud_panel_powerups_baralign == 3 || autocvar_hud_panel_powerups_baralign == 1);
1250 strength_iconalign = (autocvar_hud_panel_powerups_iconalign == 2 || autocvar_hud_panel_powerups_iconalign == 1);
1251 shield_iconalign = (autocvar_hud_panel_powerups_iconalign == 3 || autocvar_hud_panel_powerups_iconalign == 1);
1255 shield_baralign = (autocvar_hud_panel_powerups_baralign == 2 || autocvar_hud_panel_powerups_baralign == 1);
1256 strength_baralign = (autocvar_hud_panel_powerups_baralign == 3 || autocvar_hud_panel_powerups_baralign == 1);
1257 shield_iconalign = (autocvar_hud_panel_powerups_iconalign == 2 || autocvar_hud_panel_powerups_iconalign == 1);
1258 strength_iconalign = (autocvar_hud_panel_powerups_iconalign == 3 || autocvar_hud_panel_powerups_iconalign == 1);
1261 if(superweapons_is == 0)
1263 superweapons_iconalign = strength_iconalign;
1264 superweapons_baralign = 2;
1266 else if(superweapons_is == 1)
1268 superweapons_offset = strength_offset;
1269 superweapons_iconalign = strength_iconalign;
1270 superweapons_baralign = strength_baralign;
1272 else // if(superweapons_is == 2)
1274 superweapons_offset = shield_offset;
1275 superweapons_iconalign = shield_iconalign;
1276 superweapons_baralign = shield_baralign;
1281 const float maxshield = 30;
1282 float shield = ceil(shield_time);
1283 if(autocvar_hud_panel_powerups_progressbar)
1285 HUD_Panel_GetProgressBarColor(shield);
1286 HUD_Panel_DrawProgressBar(pos + shield_offset, mySize, autocvar_hud_panel_powerups_progressbar_shield, shield/maxshield, is_vertical, shield_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
1288 if(autocvar_hud_panel_powerups_text)
1291 DrawNumIcon(pos + shield_offset, mySize, shield, "shield", is_vertical, shield_iconalign, '1 1 1', 1);
1293 DrawNumIcon_expanding(pos + shield_offset, mySize, shield, "shield", is_vertical, shield_iconalign, '1 1 1', 1, bound(0, (shield - shield_time) / 0.5, 1));
1299 const float maxstrength = 30;
1300 float strength = ceil(strength_time);
1301 if(autocvar_hud_panel_powerups_progressbar)
1303 HUD_Panel_GetProgressBarColor(strength);
1304 HUD_Panel_DrawProgressBar(pos + strength_offset, mySize, autocvar_hud_panel_powerups_progressbar_strength, strength/maxstrength, is_vertical, strength_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
1306 if(autocvar_hud_panel_powerups_text)
1309 DrawNumIcon(pos + strength_offset, mySize, strength, "strength", is_vertical, strength_iconalign, '1 1 1', 1);
1311 DrawNumIcon_expanding(pos + strength_offset, mySize, strength, "strength", is_vertical, strength_iconalign, '1 1 1', 1, bound(0, (strength - strength_time) / 0.5, 1));
1315 if(superweapons_time)
1317 const float maxsuperweapons = 30;
1318 float superweapons = ceil(superweapons_time);
1319 if(autocvar_hud_panel_powerups_progressbar)
1321 HUD_Panel_GetProgressBarColor(superweapons);
1322 HUD_Panel_DrawProgressBar(pos + superweapons_offset, mySize, autocvar_hud_panel_powerups_progressbar_superweapons, superweapons/maxsuperweapons, is_vertical, superweapons_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
1324 if(autocvar_hud_panel_powerups_text)
1326 if(superweapons > 1)
1327 DrawNumIcon(pos + superweapons_offset, mySize, superweapons, "superweapons", is_vertical, superweapons_iconalign, '1 1 1', 1);
1328 if(superweapons <= 5)
1329 DrawNumIcon_expanding(pos + superweapons_offset, mySize, superweapons, "superweapons", is_vertical, superweapons_iconalign, '1 1 1', 1, bound(0, (superweapons - superweapons_time) / 0.5, 1));
1336 // Health/armor (#3)
1339 // prev_* vars contain the health/armor at the previous FRAME
1340 // set to -1 when player is dead or was not playing
1341 float prev_health, prev_armor;
1342 float health_damagetime, armor_damagetime;
1343 float health_beforedamage, armor_beforedamage;
1344 // old_p_* vars keep track of previous values when smoothing value changes of the progressbar
1345 float old_p_health, old_p_armor;
1346 float old_p_healthtime, old_p_armortime;
1347 // prev_p_* vars contain the health/armor progressbar value at the previous FRAME
1348 // set to -1 to forcedly stop effects when we switch spectated player (e.g. from playerX: 70h to playerY: 50h)
1349 float prev_p_health, prev_p_armor;
1351 void HUD_HealthArmor(void)
1353 float armor, health, fuel;
1354 if(!autocvar__hud_configure)
1356 if(!autocvar_hud_panel_healtharmor) return;
1357 if(hud != HUD_NORMAL) return;
1358 if(spectatee_status == -1) return;
1360 health = getstati(STAT_HEALTH);
1366 armor = getstati(STAT_ARMOR);
1368 // code to check for spectatee_status changes is in Ent_ClientData()
1369 // prev_p_health and prev_health can be set to -1 there
1371 if (prev_p_health == -1)
1374 health_beforedamage = 0;
1375 armor_beforedamage = 0;
1376 health_damagetime = 0;
1377 armor_damagetime = 0;
1378 prev_health = health;
1380 old_p_health = health;
1381 old_p_armor = armor;
1382 prev_p_health = health;
1383 prev_p_armor = armor;
1385 else if (prev_health == -1)
1387 //start the load effect
1388 health_damagetime = 0;
1389 armor_damagetime = 0;
1393 fuel = getstati(STAT_FUEL);
1397 hud_configure_active_panel = HUD_PANEL_HEALTHARMOR;
1404 HUD_Panel_UpdateCvars(healtharmor);
1405 HUD_Panel_ApplyFadeAlpha();
1408 mySize = panel_size;
1410 HUD_Panel_DrawBg(1);
1411 if(panel_bg_padding)
1413 pos += '1 1 0' * panel_bg_padding;
1414 mySize -= '2 2 0' * panel_bg_padding;
1417 float baralign = autocvar_hud_panel_healtharmor_baralign;
1418 float iconalign = autocvar_hud_panel_healtharmor_iconalign;
1420 float maxhealth = autocvar_hud_panel_healtharmor_maxhealth;
1421 float maxarmor = autocvar_hud_panel_healtharmor_maxarmor;
1422 if(autocvar_hud_panel_healtharmor == 2) // combined health and armor display
1425 v = healtharmor_maxdamage(health, armor, armorblockpercent);
1430 float maxtotal = maxhealth + maxarmor;
1432 if(v_z) // NOT fully armored
1434 biggercount = "health";
1435 if(autocvar_hud_panel_healtharmor_progressbar)
1437 HUD_Panel_GetProgressBarColor(health);
1438 HUD_Panel_DrawProgressBar(pos, mySize, autocvar_hud_panel_healtharmor_progressbar_health, x/maxtotal, 0, (baralign == 1 || baralign == 2), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
1441 if(autocvar_hud_panel_healtharmor_text)
1442 drawpic_aspect_skin(pos + eX * mySize_x - eX * 0.5 * mySize_y, "armor", '0.5 0.5 0' * mySize_y, '1 1 1', panel_fg_alpha * armor / health, DRAWFLAG_NORMAL);
1446 biggercount = "armor";
1447 if(autocvar_hud_panel_healtharmor_progressbar)
1449 HUD_Panel_GetProgressBarColor(armor);
1450 HUD_Panel_DrawProgressBar(pos, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, x/maxtotal, 0, (baralign == 1 || baralign == 2), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
1453 if(autocvar_hud_panel_healtharmor_text)
1454 drawpic_aspect_skin(pos + eX * mySize_x - eX * 0.5 * mySize_y, "health", '0.5 0.5 0' * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
1456 if(autocvar_hud_panel_healtharmor_text)
1457 DrawNumIcon(pos, mySize, x, biggercount, 0, iconalign, HUD_Get_Num_Color(x, maxtotal), 1);
1461 HUD_Panel_GetProgressBarColor(fuel);
1462 HUD_Panel_DrawProgressBar(pos, eX * mySize_x + eY * 0.2 * mySize_y, "progressbar", fuel/100, 0, (baralign == 1 || baralign == 3), progressbar_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
1467 float panel_ar = mySize_x/mySize_y;
1468 float is_vertical = (panel_ar < 1);
1469 vector health_offset = '0 0 0', armor_offset = '0 0 0';
1470 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
1473 if (autocvar_hud_panel_healtharmor_flip)
1474 health_offset_x = mySize_x;
1476 armor_offset_x = mySize_x;
1481 if (autocvar_hud_panel_healtharmor_flip)
1482 health_offset_y = mySize_y;
1484 armor_offset_y = mySize_y;
1487 float health_baralign, armor_baralign, fuel_baralign;
1488 float health_iconalign, armor_iconalign;
1489 if (autocvar_hud_panel_healtharmor_flip)
1491 armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1);
1492 health_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1);
1493 fuel_baralign = health_baralign;
1494 armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1);
1495 health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1);
1499 health_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1);
1500 armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1);
1501 fuel_baralign = armor_baralign;
1502 health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1);
1503 armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1);
1508 if(autocvar_hud_panel_healtharmor_progressbar)
1510 HUD_Panel_GetProgressBarColor(health);
1511 float p_health, pain_health_alpha;
1513 pain_health_alpha = 1;
1514 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
1516 if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0)
1518 if (fabs(prev_health - health) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth)
1520 if (time - old_p_healthtime < 1)
1521 old_p_health = prev_p_health;
1523 old_p_health = prev_health;
1524 old_p_healthtime = time;
1526 if (time - old_p_healthtime < 1)
1528 p_health += (old_p_health - health) * (1 - (time - old_p_healthtime));
1529 prev_p_health = p_health;
1532 if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0)
1534 if (prev_health - health >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
1536 if (time - health_damagetime >= 1)
1537 health_beforedamage = prev_health;
1538 health_damagetime = time;
1540 if (time - health_damagetime < 1)
1542 float health_damagealpha = 1 - (time - health_damagetime)*(time - health_damagetime);
1543 HUD_Panel_DrawProgressBar(pos + health_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_health, health_beforedamage/maxhealth, is_vertical, health_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * health_damagealpha, DRAWFLAG_NORMAL);
1546 prev_health = health;
1548 if (health <= autocvar_hud_panel_healtharmor_progressbar_gfx_lowhealth)
1550 float BLINK_FACTOR = 0.15;
1551 float BLINK_BASE = 0.85;
1552 float BLINK_FREQ = 9;
1553 pain_health_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ);
1556 HUD_Panel_DrawProgressBar(pos + health_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_health, p_health/maxhealth, is_vertical, health_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * pain_health_alpha, DRAWFLAG_NORMAL);
1558 if(autocvar_hud_panel_healtharmor_text)
1559 DrawNumIcon(pos + health_offset, mySize, health, "health", is_vertical, health_iconalign, HUD_Get_Num_Color(health, maxhealth), 1);
1564 if(autocvar_hud_panel_healtharmor_progressbar)
1566 HUD_Panel_GetProgressBarColor(armor);
1569 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
1571 if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0)
1573 if (fabs(prev_armor - armor) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth)
1575 if (time - old_p_armortime < 1)
1576 old_p_armor = prev_p_armor;
1578 old_p_armor = prev_armor;
1579 old_p_armortime = time;
1581 if (time - old_p_armortime < 1)
1583 p_armor += (old_p_armor - armor) * (1 - (time - old_p_armortime));
1584 prev_p_armor = p_armor;
1587 if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0)
1589 if (prev_armor - armor >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
1591 if (time - armor_damagetime >= 1)
1592 armor_beforedamage = prev_armor;
1593 armor_damagetime = time;
1595 if (time - armor_damagetime < 1)
1597 float armor_damagealpha = 1 - (time - armor_damagetime)*(time - armor_damagetime);
1598 HUD_Panel_DrawProgressBar(pos + armor_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, armor_beforedamage/maxarmor, is_vertical, armor_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * armor_damagealpha, DRAWFLAG_NORMAL);
1603 HUD_Panel_DrawProgressBar(pos + armor_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, p_armor/maxarmor, is_vertical, armor_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
1605 if(autocvar_hud_panel_healtharmor_text)
1606 DrawNumIcon(pos + armor_offset, mySize, armor, "armor", is_vertical, armor_iconalign, HUD_Get_Num_Color(armor, maxarmor), 1);
1612 mySize_x *= 0.2 / 2; //if vertical always halve x to not cover too much numbers with 3 digits
1616 mySize_x *= 2; //restore full panel size
1617 else if (panel_ar < 1/4)
1618 mySize_y *= 2; //restore full panel size
1619 HUD_Panel_GetProgressBarColor(fuel);
1620 HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", fuel/100, is_vertical, fuel_baralign, progressbar_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
1625 // Notification area (#4)
1628 string Weapon_SuicideMessage(float deathtype)
1630 w_deathtype = deathtype;
1631 get_weaponinfo(DEATH_WEAPONOF(deathtype)).weapon_func(WR_SUICIDEMESSAGE);
1632 return w_deathtypestring;
1635 string Weapon_KillMessage(float deathtype)
1637 w_deathtype = deathtype;
1638 get_weaponinfo(DEATH_WEAPONOF(deathtype)).weapon_func(WR_KILLMESSAGE);
1639 return w_deathtypestring;
1643 void HUD_KillNotify(string s1, string s2, string s3, float type, float msg) // s1 = attacker, s2 = victim
1647 float alsoprint, gentle;
1648 alsoprint = (autocvar_hud_panel_notify_print || !panel_enabled); // print message to console if: notify panel disabled, or cvar to do so enabled
1649 gentle = (autocvar_cl_gentle || autocvar_cl_gentle_messages);
1651 if ((msg == MSG_SUICIDE || msg == MSG_KILL || msg == MSG_KILL_ACTION) && gametype == MAPINFO_TYPE_CTS) // selfkill isn't interesting in CTS and only spams up the notify panel
1654 if(msg == MSG_SUICIDE) {
1655 w = DEATH_WEAPONOF(type);
1657 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1659 print("^1", sprintf(Weapon_SuicideMessage(type), strcat(s1, "^1")), "\n");
1660 } else if (type == DEATH_KILL) {
1661 HUD_KillNotify_Push(s1, "", 0, DEATH_KILL);
1663 print (sprintf(_("^1%s^1 couldn't take it anymore\n"), s1));
1664 } else if (type == DEATH_ROT) {
1665 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1667 print (sprintf(_("^1%s^1 died\n"), s1));
1668 } else if (type == DEATH_NOAMMO) {
1669 HUD_KillNotify_Push(s1, "", 0, DEATH_NOAMMO);
1671 print (sprintf(_("^7%s^7 committed suicide. What's the point of living without ammo?\n"), s1));
1672 } else if (type == DEATH_CAMP) {
1673 HUD_KillNotify_Push(s1, "", 0, DEATH_CAMP);
1675 print (sprintf(_("^1%s^1 thought they found a nice camping ground\n"), s1));
1676 } else if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
1677 HUD_KillNotify_Push(s1, "", 0, type);
1679 print (sprintf(_("^1%s^1 didn't become friends with the Lord of Teamplay\n"), s1));
1680 } else if (type == DEATH_CHEAT) {
1681 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1683 print (sprintf(_("^1%s^1 unfairly eliminated themself\n"), s1));
1684 } else if (type == DEATH_FIRE) {
1685 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1687 print (sprintf(_("^1%s^1 burned to death\n"), s1));
1688 } else if (type != DEATH_TEAMCHANGE && type != DEATH_QUIET) {
1689 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1691 print (sprintf(_("^1%s^1 couldn't resist the urge to self-destruct\n"), s1));
1694 if (stof(s2) > 2) // killcount > 2
1695 print (sprintf(_("^1%s^1 ended it all after a %d kill spree\n"), s1, stof(s2)));
1696 } else if(msg == MSG_KILL) {
1697 w = DEATH_WEAPONOF(type);
1699 HUD_KillNotify_Push(s1, s2, 1, type);
1701 print("^1", sprintf(Weapon_KillMessage(type), strcat(s2, "^1"), strcat(s1, "^1")), "\n"); // default order: victim, killer
1703 else if(type == KILL_TEAM_RED || type == KILL_TEAM_BLUE || type == KILL_TEAM_SPREE) {
1704 HUD_KillNotify_Push(s1, s2, 1, type);
1708 print (sprintf(_("^1%s^1 took action against a team mate\n"), s1));
1710 print (sprintf(_("^1%s^1 mows down a team mate\n"), s1));
1713 if (stof(s2) > 2 && type == KILL_TEAM_SPREE) {
1715 print (sprintf(_("^1%s^1 ended a %d scoring spree by going against a team mate\n"), s1, stof(s3)));
1717 print (sprintf(_("^1%s^1 ended a %d kill spree by killing a team mate\n"), s1, stof(s3)));
1719 else if (stof(s2) > 2) {
1721 print (sprintf(_("^1%s^1's %s scoring spree was ended by a team mate!\n"), s1, stof(s3)));
1723 print (sprintf(_("^1%s^1's %s kill spree was ended by a team mate!\n"), s1, stof(s3)));
1726 else if(type == KILL_FIRST_BLOOD)
1727 print(sprintf(_("^1%s^1 drew first blood\n"), s1));
1728 else if (type == DEATH_TELEFRAG) {
1729 HUD_KillNotify_Push(s1, s2, 1, DEATH_TELEFRAG);
1731 print (sprintf(_("^1%s^1 tried to occupy %s^1's teleport destination space\n"), s2, s1));
1733 print (sprintf(_("^1%s^1 was telefragged by %s\n"), s2, s1));
1735 else if (type == DEATH_DROWN) {
1736 HUD_KillNotify_Push(s1, s2, 1, DEATH_DROWN);
1738 print (sprintf(_("^1%s^1 was drowned by %s\n"), s2, s1));
1740 else if (type == DEATH_SLIME) {
1741 HUD_KillNotify_Push(s1, s2, 1, DEATH_SLIME);
1743 print (sprintf(_("^1%s^1 was slimed by %s\n"), s2, s1));
1745 else if (type == DEATH_LAVA) {
1746 HUD_KillNotify_Push(s1, s2, 1, DEATH_LAVA);
1748 print (sprintf(_("^1%s^1 was cooked by %s\n"), s2, s1));
1750 else if (type == DEATH_FALL) {
1751 HUD_KillNotify_Push(s1, s2, 1, DEATH_FALL);
1753 print (sprintf(_("^1%s^1 was grounded by %s\n"), s2, s1));
1755 else if (type == DEATH_SHOOTING_STAR) {
1756 HUD_KillNotify_Push(s1, s2, 1, DEATH_SHOOTING_STAR);
1758 print (sprintf(_("^1%s^1 was shot into space by %s\n"), s2, s1));
1760 else if (type == DEATH_SWAMP) {
1761 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1763 print (sprintf(_("^1%s^1 was conserved by %s\n"), s2, s1));
1765 else if (type == DEATH_HURTTRIGGER)
1767 HUD_KillNotify_Push(s1, s2, 1, DEATH_HURTTRIGGER);
1769 print(sprintf(_("^1%s^1 was thrown into a world of hurt by %s\n"), s2, s1));
1770 } else if(type == DEATH_VHCRUSH) {
1771 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1773 print (sprintf(_("^1%s^1 was crushed by %s\n"), s2, s1));
1774 } else if(type == DEATH_SBMINIGUN) {
1775 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1777 print (sprintf(_("^1%s^1 got shredded by %s\n"), s2, s1));
1778 } else if(type == DEATH_SBROCKET) {
1779 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1781 print (sprintf(_("^1%s^1 was blasted to bits by %s\n"), s2, s1));
1782 } else if(type == DEATH_SBBLOWUP) {
1783 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1785 print (sprintf(_("^1%s^1 got caught in the blast when %s^1's destroys a vehicle\n"), s2, s1));
1786 } else if(type == DEATH_WAKIGUN) {
1787 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1789 print (sprintf(_("^1%s^1 was bolted down by %s\n"), s2, s1));
1790 } else if(type == DEATH_BUMB_GUN) {
1791 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1793 print (sprintf(_("^1%s^1 saw %s's preddy lights.\n"), s2, s1));
1794 } else if(type == DEATH_WAKIROCKET) {
1795 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1797 print (sprintf(_("^1%s^1 could find no shelter from %s^1's rockets\n"), s2, s1));
1798 } else if(type == DEATH_WAKIBLOWUP) {
1799 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1801 print (sprintf(_("^1%s^1 got caught in the blast when %s^1's destroys a vehicle\n"), s2, s1));
1802 } else if(type == DEATH_RAPTOR_CANNON) {
1803 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1805 print (sprintf(_("^1%s^1 nailed to hell by %s\n"), s2, s1));
1806 } else if(type == DEATH_RAPTOR_BOMB) {
1807 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1809 print (sprintf(_("^1%s^1 cluster crushed by %s\n"), s2, s1));
1810 } else if(type == DEATH_RAPTOR_DEATH) {
1811 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1813 print (sprintf(_("^1%s^1 got caught in the blast when %s^1's destroys a vehicle\n"), s2, s1));
1814 } else if(type == DEATH_TURRET) {
1815 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1817 print (sprintf(_("^1%s^1 was pushed into the line of fire by %s\n"), s2, s1));
1818 } else if(type == DEATH_TOUCHEXPLODE) {
1819 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1821 print (sprintf(_("^1%s^1 was pushed into an accident by %s\n"), s2, s1));
1822 } else if(type == DEATH_CHEAT) {
1823 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1825 print (sprintf(_("^1%s^1 was unfairly eliminated by %s\n"), s2, s1));
1826 } else if (type == DEATH_FIRE) {
1827 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1829 print (sprintf(_("^1%s^1 was burnt to death by %s\n"), s2, s1));
1830 } else if (type == DEATH_CUSTOM) {
1831 HUD_KillNotify_Push(s1, s2, 1, DEATH_CUSTOM);
1833 print("^1", sprintf(s3, strcat(s2, "^1"), strcat(s1, "^1")), "\n");
1834 } else if (type == DEATH_HURTTRIGGER) {
1835 HUD_KillNotify_Push(s1, s2, 1, DEATH_HURTTRIGGER);
1837 print("^1", sprintf(s3, strcat(s2, "^1"), strcat(s1, "^1")), "\n");
1839 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1841 print (sprintf(_("^1%s^1 was fragged by %s\n"), s2, s1));
1843 } else if(msg == MSG_SPREE) {
1844 if(type == KILL_END_SPREE) {
1846 print (sprintf(_("^1%s^1's %s scoring spree was ended by %s\n"), s1, s2, s3));
1848 print (sprintf(_("^1%s^1's %s kill spree was ended by %s\n"), s1, s2, s3));
1849 } else if(type == KILL_SPREE) {
1851 print (sprintf(_("^1%s^1 made %s scores in a row\n"), s1, s2));
1853 print (sprintf(_("^1%s^1 has %s frags in a row\n"), s1, s2));
1854 } else if(type == KILL_SPREE_3) {
1856 print (sprintf(_("%s^7 made a ^1TRIPLE SCORE\n"), s1));
1858 print (sprintf(_("%s^7 made a ^1TRIPLE FRAG\n"), s1));
1859 } else if(type == KILL_SPREE_5) {
1861 print (sprintf(_("%s^7 unleashes ^1SCORING RAGE\n"), s1));
1863 print (sprintf(_("%s^7 unleashes ^1RAGE\n"), s1));
1864 } else if(type == KILL_SPREE_10) {
1866 print (sprintf(_("%s^7 made ^1TEN SCORES IN A ROW!\n"), s1));
1868 print (sprintf(_("%s^7 starts the ^1MASSACRE!\n"), s1));
1869 } else if(type == KILL_SPREE_15) {
1871 print (sprintf(_("%s^7 made ^1FIFTEEN SCORES IN A ROW!\n"), s1));
1873 print (sprintf(_("%s^7 executes ^1MAYHEM!\n"), s1));
1874 } else if(type == KILL_SPREE_20) {
1876 print (sprintf(_("%s^7 made ^1TWENTY SCORES IN A ROW!\n"), s1));
1878 print (sprintf(_("%s^7 is a ^1BERSERKER!\n"), s1));
1879 } else if(type == KILL_SPREE_25) {
1881 print (sprintf(_("%s^7 made ^1TWENTY FIVE SCORES IN A ROW!\n"), s1));
1883 print (sprintf(_("%s^7 inflicts ^1CARNAGE!\n"), s1));
1884 } else if(type == KILL_SPREE_30) {
1886 print (sprintf(_("%s^7 made ^1THIRTY SCORES IN A ROW!\n"), s1));
1888 print (sprintf(_("%s^7 unleashes ^1ARMAGEDDON!\n"), s1));
1890 } else if(msg == MSG_KILL_ACTION) { // wtf is this? isnt it basically the same as MSG_SUICIDE?
1891 if (type == DEATH_DROWN) {
1892 HUD_KillNotify_Push(s1, "", 0, DEATH_DROWN);
1896 print (sprintf(_("^1%s^1 was in the water for too long\n"), s1));
1898 print (sprintf(_("^1%s^1 drowned\n"), s1));
1900 } else if (type == DEATH_SLIME) {
1901 HUD_KillNotify_Push(s1, "", 0, DEATH_SLIME);
1903 print (sprintf(_("^1%s^1 was slimed\n"), s1));
1904 } else if (type == DEATH_LAVA) {
1905 HUD_KillNotify_Push(s1, "", 0, DEATH_LAVA);
1909 print (sprintf(_("^1%s^1 found a hot place\n"), s1));
1911 print (sprintf(_("^1%s^1 turned into hot slag\n"), s1));
1913 } else if (type == DEATH_FALL) {
1914 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1918 print (sprintf(_("^1%s^1 tested gravity (and it worked)\n"), s1));
1920 print (sprintf(_("^1%s^1 hit the ground with a crunch\n"), s1));
1922 } else if (type == DEATH_SHOOTING_STAR) {
1923 HUD_KillNotify_Push(s1, "", 0, DEATH_SHOOTING_STAR);
1925 print (sprintf(_("^1%s^1 became a shooting star\n"), s1));
1926 } else if (type == DEATH_SWAMP) {
1927 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1931 print (sprintf(_("^1%s^1 discovered a swamp\n"), s1));
1933 print (sprintf(_("^1%s^1 is now conserved for centuries to come\n"), s1));
1935 } else if(DEATH_ISTURRET(type)) {
1936 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1940 print (sprintf(_("^1%s^1 ran into a turret\n"), s1));
1945 case DEATH_TURRET_EWHEEL:
1946 print (sprintf(_("^1%s^1 was laserd down by a eWheel turret \n"), s1));
1948 case DEATH_TURRET_FLAC:
1949 print (sprintf(_("^1%s^1 got caught in the flac \n"), s1));
1951 case DEATH_TURRET_MACHINEGUN:
1952 print (sprintf(_("^1%s^1 was riddeld full of riddled by a machinegun turret \n"), s1));
1954 case DEATH_TURRET_WALKER_GUN:
1955 print (sprintf(_("^1%s^1 got served a led enrichment by a walker turret \n"), s1));
1957 case DEATH_TURRET_WALKER_MEELE:
1958 print (sprintf(_("^1%s^1 was impaled by a walker turret \n"), s1));
1960 case DEATH_TURRET_WALKER_ROCKET:
1961 print (sprintf(_("^1%s^1 was rocketed to hell by a walker turret \n"), s1));
1963 case DEATH_TURRET_HELLION:
1964 print (sprintf(_("^1%s^1 was blasted away hellion turret \n"), s1));
1966 case DEATH_TURRET_HK:
1967 print (sprintf(_("^1%s^1 could not hide from the hunter turret \n"), s1));
1969 case DEATH_TURRET_MLRS:
1970 print (sprintf(_("^1%s^1 got turned into smoldering gibs by a mlrs turret \n"), s1));
1972 case DEATH_TURRET_PLASMA:
1973 print (sprintf(_("^1%s^1 got served some superheated plasma from a plasma turret \n"), s1));
1975 case DEATH_TURRET_PHASER:
1976 print (sprintf(_("^1%s^1 was phased out \n"), s1));
1978 case DEATH_TURRET_TESLA:
1979 print (sprintf(_("^1%s^1 was electrocuted by a tesla turret \n"), s1));
1984 } else if (type == DEATH_CUSTOM) {
1985 HUD_KillNotify_Push(s1, "", 0, DEATH_CUSTOM);
1987 print("^1", sprintf(s2, strcat(s1, "^1")), "\n");
1988 } else if (type == DEATH_HURTTRIGGER) {
1989 HUD_KillNotify_Push(s1, "", 0, DEATH_HURTTRIGGER);
1991 print("^1", sprintf(s2, strcat(s1, "^1")), "\n");
1992 } else if(type == DEATH_TOUCHEXPLODE) {
1993 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1995 print (sprintf(_("^1%s^1 died in an accident\n"), s1));
1996 } else if(type == DEATH_CHEAT) {
1997 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1999 print (sprintf(_("^1%s^1 was unfairly eliminated\n"), s1));
2000 } else if(type == DEATH_FIRE) {
2001 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2005 print (sprintf(_("^1%s^1 felt a little hot\n"), s1));
2007 print (sprintf(_("^1%s^1 burnt to death\n"), s1));
2010 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2014 print (sprintf(_("^1%s^1 needs a restart\n"), s1));
2016 print (sprintf(_("^1%s^1 died\n"), s1));
2019 } else if(msg == MSG_KILL_ACTION_SPREE) {
2021 print (sprintf(_("^1%s^1 needs a restart after a %d scoring spree\n"), s1, stof(s2)));
2023 print (sprintf(_("^1%s^1 died with a %d kill spree\n"), s1, stof(s2)));
2024 } else if(msg == MSG_INFO) {
2025 if(type == INFO_GOTFLAG) { // here, s2 is the flag name
2026 HUD_KillNotify_Push(s1, s2, 0, INFO_GOTFLAG);
2027 print(sprintf(_("%s^7 got the %s\n"), s1, s2));
2028 } else if(type == INFO_LOSTFLAG) {
2029 HUD_KillNotify_Push(s1, s2, 0, INFO_LOSTFLAG);
2030 print(sprintf(_("%s^7 lost the %s\n"), s1, s2));
2031 } else if(type == INFO_PICKUPFLAG) {
2032 HUD_KillNotify_Push(s1, s2, 0, INFO_GOTFLAG);
2033 print(sprintf(_("%s^7 picked up the %s\n"), s1, s2));
2034 } else if(type == INFO_RETURNFLAG) {
2035 HUD_KillNotify_Push(s1, s2, 0, INFO_RETURNFLAG);
2036 print(sprintf(_("%s^7 returned the %s\n"), s1, s2));
2037 } else if(type == INFO_CAPTUREFLAG) {
2038 HUD_KillNotify_Push(s1, s2, 0, INFO_CAPTUREFLAG);
2039 print(sprintf(_("%s^7 captured the %s%s\n"), s1, s2, s3));
2041 } else if(msg == MSG_RACE) {
2042 if(type == RACE_SERVER_RECORD) {
2043 HUD_KillNotify_Push(s1, s2, 1, RACE_SERVER_RECORD);
2045 else if(type == RACE_NEW_RANK) {
2046 HUD_KillNotify_Push(s1, s2, 1, RACE_NEW_RANK);
2048 else if(type == RACE_NEW_TIME) {
2049 HUD_KillNotify_Push(s1, s2, 1, RACE_NEW_TIME);
2051 else if(type == RACE_FAIL) {
2052 HUD_KillNotify_Push(s1, s2, 1, RACE_FAIL);
2054 } else if(msg == MSG_KA) {
2055 if(type == KA_PICKUPBALL) {
2056 HUD_KillNotify_Push(s1, s2, 0, KA_PICKUPBALL);
2058 print (sprintf(_("%s^7 has picked up the ball!\n"), s1));
2060 else if(type == KA_DROPBALL) {
2061 HUD_KillNotify_Push(s1, s2, 0, KA_DROPBALL);
2063 print(sprintf(_("%s^7 has dropped the ball!\n"), s1));
2068 void HUD_Notify(void)
2070 if(!autocvar__hud_configure)
2072 if(!autocvar_hud_panel_notify) return;
2075 hud_configure_active_panel = HUD_PANEL_NOTIFY;
2077 HUD_Panel_UpdateCvars(notify);
2078 HUD_Panel_ApplyFadeAlpha();
2081 mySize = panel_size;
2083 HUD_Panel_DrawBg(1);
2084 if(panel_bg_padding)
2086 pos += '1 1 0' * panel_bg_padding;
2087 mySize -= '2 2 0' * panel_bg_padding;
2090 float entries, height;
2091 entries = bound(1, floor(KN_MAX_ENTRIES * mySize_y/mySize_x), KN_MAX_ENTRIES);
2092 height = mySize_y/entries;
2095 float fontheight = height * autocvar_hud_panel_notify_fontsize;
2096 fontsize = '0.5 0.5 0' * fontheight;
2100 when = autocvar_hud_panel_notify_time;
2102 fadetime = autocvar_hud_panel_notify_fadetime;
2104 vector pos_attacker, pos_victim, pos_icon;
2105 float width_attacker;
2106 string attacker, victim, icon;
2108 float i, j, step, limit;
2109 if(autocvar_hud_panel_notify_flip) //order items from the top down
2115 else //order items from the bottom up
2122 for(j = kn_index; i != limit; i += step, ++j)
2124 if(autocvar__hud_configure)
2128 else // inverse order
2129 a = entries - 1 - i;
2130 attacker = textShortenToWidth(sprintf(_("Player %d"), a+1), 0.48 * mySize_x - height, fontsize, stringwidth_colors);
2131 victim = textShortenToWidth(sprintf(_("Player %d"), a+2), 0.48 * mySize_x - height, fontsize, stringwidth_colors);
2132 icon = strcat("weapon", get_weaponinfo(WEP_FIRST + mod(floor(a*2.4), WEP_LAST)).netname);
2133 a = bound(0, (when - a) / 4, 1);
2134 goto hud_config_notifyprint;
2138 if (j == KN_MAX_ENTRIES)
2141 if(killnotify_times[j] + when > time)
2145 a = bound(0, (killnotify_times[j] + when + fadetime - time) / fadetime, 1);
2156 attacker = killnotify_attackers[j];
2157 victim = killnotify_victims[j];
2158 icon = killnotify_icon[j];
2161 //type = killnotify_deathtype[j];
2162 //w = DEATH_WEAPONOF(type);
2166 if((attacker != "") && (victim == ""))
2169 attacker = textShortenToWidth(attacker, 0.73 * mySize_x - height, fontsize, stringwidth_colors);
2170 pos_attacker = pos + eX * (0.27 * mySize_x + height) + eY * ((0.5 * fontsize_y + i * height) + (0.5 * (height - fontheight)));
2171 pos_icon = pos + eX * 0.25 * mySize_x - eX * height + eY * i * height;
2173 drawpic_aspect_skin(pos_icon, icon, '2 1 0' * height, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
2174 drawcolorcodedstring(pos_attacker, attacker, fontsize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2176 else if((attacker != "") && (victim != ""))
2178 // X [did action to] Y
2179 attacker = textShortenToWidth(attacker, 0.48 * mySize_x - height, fontsize, stringwidth_colors);
2180 victim = textShortenToWidth(victim, 0.48 * mySize_x - height, fontsize, stringwidth_colors);
2181 :hud_config_notifyprint
2182 width_attacker = stringwidth(attacker, TRUE, fontsize);
2183 pos_attacker = pos + eX * (0.48 * mySize_x - height - width_attacker) + eY * ((0.5 * fontsize_y + i * height) + (0.5 * (height - fontheight)));
2184 pos_victim = pos + eX * (0.52 * mySize_x + height) + eY * ((0.5 * fontsize_y + i * height) + (0.5 * (height - fontheight)));
2185 pos_icon = pos + eX * 0.5 * mySize_x - eX * height + eY * i * height;
2187 drawpic_aspect_skin(pos_icon, icon, '2 1 0' * height, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
2188 drawcolorcodedstring(pos_attacker, attacker, fontsize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2189 drawcolorcodedstring(pos_victim, victim, fontsize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2198 string seconds_tostring(float sec)
2201 minutes = floor(sec / 60);
2203 sec -= minutes * 60;
2204 return sprintf("%d:%02d", minutes, sec);
2207 void HUD_Timer(void)
2209 if(!autocvar__hud_configure)
2211 if(!autocvar_hud_panel_timer) return;
2214 hud_configure_active_panel = HUD_PANEL_TIMER;
2216 HUD_Panel_UpdateCvars(timer);
2217 HUD_Panel_ApplyFadeAlpha();
2219 draw_beginBoldFont();
2223 mySize = panel_size;
2225 HUD_Panel_DrawBg(1);
2226 if(panel_bg_padding)
2228 pos += '1 1 0' * panel_bg_padding;
2229 mySize -= '2 2 0' * panel_bg_padding;
2233 float timelimit, elapsedTime, timeleft, minutesLeft;
2235 timelimit = getstatf(STAT_TIMELIMIT);
2237 timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
2238 timeleft = ceil(timeleft);
2240 minutesLeft = floor(timeleft / 60);
2243 if(minutesLeft >= 5 || warmup_stage || timelimit == 0) //don't use red or yellow in warmup or when there is no timelimit
2244 timer_color = '1 1 1'; //white
2245 else if(minutesLeft >= 1)
2246 timer_color = '1 1 0'; //yellow
2248 timer_color = '1 0 0'; //red
2250 if (autocvar_hud_panel_timer_increment || timelimit == 0 || warmup_stage) {
2251 if (time < getstatf(STAT_GAMESTARTTIME)) {
2252 //while restart is still active, show 00:00
2253 timer = seconds_tostring(0);
2255 elapsedTime = floor(time - getstatf(STAT_GAMESTARTTIME)); //127
2256 timer = seconds_tostring(elapsedTime);
2259 timer = seconds_tostring(timeleft);
2262 drawstring_aspect(pos, timer, mySize, timer_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2269 void HUD_Radar(void)
2271 if (!autocvar__hud_configure)
2273 if (hud_panel_radar_maximized)
2275 if (!hud_draw_maximized) return;
2279 if (autocvar_hud_panel_radar == 0) return;
2280 if (autocvar_hud_panel_radar != 2 && !teamplay) return;
2284 hud_configure_active_panel = HUD_PANEL_RADAR;
2286 HUD_Panel_UpdateCvars(radar);
2287 HUD_Panel_ApplyFadeAlpha();
2289 if (hud_panel_radar_maximized && !autocvar__hud_configure)
2291 panel_size = autocvar_hud_panel_radar_maximized_size;
2292 panel_size_x = bound(0.2, panel_size_x, 1) * vid_conwidth;
2293 panel_size_y = bound(0.2, panel_size_y, 1) * vid_conheight;
2294 panel_pos_x = (vid_conwidth - panel_size_x) / 2;
2295 panel_pos_y = (vid_conheight - panel_size_y) / 2;
2297 panel_bg = strcat(hud_skin_path, "/border_default"); // always use the default border when maximized
2298 if(precache_pic(panel_bg) == "") { panel_bg = "gfx/hud/default/border_default"; } // fallback
2303 mySize = panel_size;
2305 HUD_Panel_DrawBg(1);
2306 if(panel_bg_padding)
2308 pos += '1 1 0' * panel_bg_padding;
2309 mySize -= '2 2 0' * panel_bg_padding;
2314 float scale2d, normalsize, bigsize;
2317 teamradar_origin2d = pos + 0.5 * mySize;
2318 teamradar_size2d = mySize;
2320 if(minimapname == "")
2323 teamradar_loadcvars();
2325 switch(hud_panel_radar_zoommode)
2329 f = current_zoomfraction;
2332 f = 1 - current_zoomfraction;
2342 switch(hud_panel_radar_rotation)
2345 teamradar_angle = view_angles_y - 90;
2348 teamradar_angle = 90 * hud_panel_radar_rotation;
2352 scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
2353 teamradar_size2d = mySize;
2355 teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0'; // we always center
2357 // pixels per world qu to match the teamradar_size2d_x range in the longest dimension
2358 if(hud_panel_radar_rotation == 0)
2360 // max-min distance must fit the radar in any rotation
2361 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen2d(mi_scale));
2365 vector c0, c1, c2, c3, span;
2366 c0 = rotate(mi_min, teamradar_angle * DEG2RAD);
2367 c1 = rotate(mi_max, teamradar_angle * DEG2RAD);
2368 c2 = rotate('1 0 0' * mi_min_x + '0 1 0' * mi_max_y, teamradar_angle * DEG2RAD);
2369 c3 = rotate('1 0 0' * mi_max_x + '0 1 0' * mi_min_y, teamradar_angle * DEG2RAD);
2371 span_x = max(c0_x, c1_x, c2_x, c3_x) - min(c0_x, c1_x, c2_x, c3_x);
2372 span_y = max(c0_y, c1_y, c2_y, c3_y) - min(c0_y, c1_y, c2_y, c3_y);
2374 // max-min distance must fit the radar in x=x, y=y
2376 teamradar_size2d_x * scale2d / (1.05 * span_x),
2377 teamradar_size2d_y * scale2d / (1.05 * span_y)
2381 normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / hud_panel_radar_scale;
2382 if(bigsize > normalsize)
2383 normalsize = bigsize;
2387 + (1 - f) * normalsize;
2388 teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
2390 + (1 - f) * view_origin);
2399 draw_teamradar_background(hud_panel_radar_foreground_alpha);
2401 for(tm = world; (tm = find(tm, classname, "radarlink")); )
2402 draw_teamradar_link(tm.origin, tm.velocity, tm.team);
2403 for(tm = world; (tm = findflags(tm, teamradar_icon, 0xFFFFFF)); )
2404 draw_teamradar_icon(tm.origin, tm.teamradar_icon, tm, tm.teamradar_color, panel_fg_alpha);
2405 for(tm = world; (tm = find(tm, classname, "entcs_receiver")); )
2407 color2 = GetPlayerColor(tm.sv_entnum);
2408 //if(color == FL_SPECTATOR || color == color2)
2409 draw_teamradar_player(tm.origin, tm.angles, Team_ColorRGB(color2));
2411 draw_teamradar_player(view_origin, view_angles, '1 1 1');
2413 drawresetcliparea();
2418 void HUD_UpdatePlayerTeams();
2419 void HUD_Score_Rankings(vector pos, vector mySize, entity me, float team_count)
2422 entity tm = world, pl;
2423 #define SCOREPANEL_MAX_ENTRIES 6
2424 #define SCOREPANEL_ASPECTRATIO 2
2425 float entries = bound(1, floor(SCOREPANEL_MAX_ENTRIES * mySize_y/mySize_x * SCOREPANEL_ASPECTRATIO), SCOREPANEL_MAX_ENTRIES);
2426 vector fontsize = '1 1 0' * (mySize_y/entries);
2428 vector rgb, score_color;
2430 score_color = '1 1 1';
2432 float name_size = mySize_x*0.75;
2433 float spacing_size = mySize_x*0.04;
2434 const float highlight_alpha = 0.2;
2435 float i = 0, me_printed = 0, first_pl = 0;
2437 if (autocvar__hud_configure)
2439 float players_per_team = 0;
2442 // show team scores in the first line
2443 float score_size = mySize_x / team_count;
2444 players_per_team = max(2, ceil((entries - 1) / team_count));
2445 for(i=0; i<team_count; ++i) {
2446 if (i == floor((entries - 2) / players_per_team) || (entries == 1 && i == 0))
2447 HUD_Panel_DrawHighlight(pos + eX * score_size * i, eX * score_size + eY * fontsize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2448 drawstring_aspect(pos + eX * score_size * i, ftos(175 - 23*i), eX * score_size + eY * fontsize_y, Team_ColorRGB(ColorByTeam(i)) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2451 pos_y += fontsize_y;
2453 score = 10 + SCOREPANEL_MAX_ENTRIES * 3;
2454 for (i=first_pl; i<entries; ++i)
2456 //simulate my score is lower than all displayed players,
2457 //so that I don't appear at all showing pure rankings.
2458 //This is to better show the difference between the 2 ranking views
2459 if (i == entries-1 && autocvar_hud_panel_score_rankings == 1)
2462 drawfill(pos, eX * mySize_x + eY * fontsize_y, rgb, highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2463 s = GetPlayerName(player_localnum);
2468 s = sprintf(_("Player %d"), i + 1 - first_pl);
2473 score_color = Team_ColorRGB(ColorByTeam(floor((i - first_pl) / players_per_team))) * 0.8;
2474 s = textShortenToWidth(s, name_size, fontsize, stringwidth_colors);
2475 drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, TRUE, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
2476 drawstring(pos + eX * (name_size + spacing_size), ftos(score), fontsize, score_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2477 pos_y += fontsize_y;
2482 if (!scoreboard_fade_alpha) // the scoreboard too calls HUD_UpdatePlayerTeams
2483 HUD_UpdatePlayerTeams();
2486 // show team scores in the first line
2487 float score_size = mySize_x / team_count;
2488 for(tm = teams.sort_next; tm; tm = tm.sort_next) {
2489 if(tm.team == FL_SPECTATOR)
2491 if (tm.team == myteam)
2492 drawfill(pos + eX * score_size * i, eX * score_size + eY * fontsize_y, '1 1 1', highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2493 drawstring_aspect(pos + eX * score_size * i, ftos(tm.(teamscores[ts_primary])), eX * score_size + eY * fontsize_y, Team_ColorRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2497 pos_y += fontsize_y;
2498 tm = teams.sort_next;
2503 for (pl = players.sort_next; pl && i<entries; pl = pl.sort_next)
2505 if ((team_count && pl.team != tm.team) || pl.team == FL_SPECTATOR)
2508 if (i == entries-1 && !me_printed && pl != me)
2509 if (autocvar_hud_panel_score_rankings == 1 && spectatee_status != -1)
2511 for (pl = me.sort_next; pl; pl = pl.sort_next)
2512 if (pl.team != FL_SPECTATOR)
2516 rgb = '1 1 0'; //not last but not among the leading players: yellow
2518 rgb = '1 0 0'; //last: red
2525 rgb = '0 1 0'; //first: green
2527 drawfill(pos, eX * mySize_x + eY * fontsize_y, rgb, highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2530 score_color = Team_ColorRGB(pl.team) * 0.8;
2531 s = textShortenToWidth(GetPlayerName(pl.sv_entnum), name_size, fontsize, stringwidth_colors);
2532 drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, TRUE, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
2533 drawstring(pos + eX * (name_size + spacing_size), ftos(pl.(scores[ps_primary])), fontsize, score_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2534 pos_y += fontsize_y;
2537 while (i<entries && team_count && (tm = tm.sort_next) && (tm.team != FL_SPECTATOR || (tm = tm.sort_next)));
2540 void HUD_Score(void)
2542 if(!autocvar__hud_configure)
2544 if(!autocvar_hud_panel_score) return;
2545 if(spectatee_status == -1 && (gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return;
2548 hud_configure_active_panel = HUD_PANEL_SCORE;
2550 HUD_Panel_UpdateCvars(score);
2551 HUD_Panel_ApplyFadeAlpha();
2554 mySize = panel_size;
2556 HUD_Panel_DrawBg(1);
2557 if(panel_bg_padding)
2559 pos += '1 1 0' * panel_bg_padding;
2560 mySize -= '2 2 0' * panel_bg_padding;
2563 float score, distribution = 0;
2565 vector distribution_color;
2568 #ifdef COMPAT_XON050_ENGINE
2569 me = (spectatee_status > 0) ? playerslots[spectatee_status - 1] : playerslots[player_localentnum - 1];
2571 me = playerslots[player_localentnum - 1];
2574 if((scores_flags[ps_primary] & SFL_TIME) && !teamplay) { // race/cts record display on HUD
2575 string timer, distrtimer;
2577 pl = players.sort_next;
2580 if(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)
2581 if(pl.scores[ps_primary] == 0)
2584 score = me.(scores[ps_primary]);
2585 timer = TIME_ENCODED_TOSTRING(score);
2587 draw_beginBoldFont();
2588 if (pl && ((!(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)) || score)) {
2589 // distribution display
2590 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
2592 distrtimer = ftos_decimals(fabs(distribution/pow(10, TIME_DECIMALS)), TIME_DECIMALS);
2594 if (distribution <= 0) {
2595 distribution_color = '0 1 0';
2599 distribution_color = '1 0 0';
2602 drawstring_aspect(pos + eX * 0.75 * mySize_x, strcat(sign, distrtimer), eX * 0.25 * mySize_x + eY * (1/3) * mySize_y, distribution_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2604 // race record display
2605 if (distribution <= 0)
2606 HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2607 drawstring_aspect(pos, timer, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2609 } else if (!teamplay) { // non-teamgames
2610 if ((spectatee_status == -1 && !autocvar__hud_configure) || autocvar_hud_panel_score_rankings)
2612 HUD_Score_Rankings(pos, mySize, me, 0);
2615 // me vector := [team/connected frags id]
2616 pl = players.sort_next;
2620 if(autocvar__hud_configure)
2623 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
2627 score = me.(scores[ps_primary]);
2628 if(autocvar__hud_configure)
2631 if(distribution >= 5)
2632 distribution_color = eY;
2633 else if(distribution >= 0)
2634 distribution_color = '1 1 1';
2635 else if(distribution >= -5)
2636 distribution_color = '1 1 0';
2638 distribution_color = eX;
2640 string distribution_str;
2641 distribution_str = ftos(distribution);
2642 draw_beginBoldFont();
2643 if (distribution >= 0)
2645 if (distribution > 0)
2646 distribution_str = strcat("+", distribution_str);
2647 HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2649 drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize_x + eY * mySize_y, distribution_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2650 drawstring_aspect(pos + eX * 0.75 * mySize_x, distribution_str, eX * 0.25 * mySize_x + eY * (1/3) * mySize_y, distribution_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2652 } else { // teamgames
2653 float scores_count = 0, row, column, rows = 0, columns = 0;
2654 local noref vector offset = '0 0 0';
2655 vector score_pos, score_size; //for scores other than myteam
2656 if (spectatee_status == -1 || autocvar_hud_panel_score_rankings)
2658 for(tm = teams.sort_next; tm, tm.team != FL_SPECTATOR; tm = tm.sort_next)
2660 if (autocvar_hud_panel_score_rankings)
2662 HUD_Score_Rankings(pos, mySize, me, scores_count);
2665 rows = mySize_y/mySize_x;
2666 rows = bound(1, floor((sqrt(4 * (3/1) * rows * scores_count + rows * rows) + rows + 0.5) / 2), scores_count);
2667 // ^^^ ammo item aspect goes here
2669 columns = ceil(scores_count/rows);
2671 score_size = eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows);
2674 if(score_size_x/score_size_y > 3)
2676 newSize = 3 * score_size_y;
2677 offset_x = score_size_x - newSize;
2678 pos_x += offset_x/2;
2679 score_size_x = newSize;
2683 newSize = 1/3 * score_size_x;
2684 offset_y = score_size_y - newSize;
2685 pos_y += offset_y/2;
2686 score_size_y = newSize;
2690 score_size = eX * mySize_x*(1/4) + eY * mySize_y*(1/3);
2692 float max_fragcount;
2693 max_fragcount = -99;
2694 draw_beginBoldFont();
2696 for(tm = teams.sort_next; tm; tm = tm.sort_next) {
2697 if(tm.team == FL_SPECTATOR)
2699 score = tm.(teamscores[ts_primary]);
2700 if(autocvar__hud_configure)
2703 if (score > max_fragcount)
2704 max_fragcount = score;
2706 if (spectatee_status == -1)
2708 score_pos = pos + eX * column * (score_size_x + offset_x) + eY * row * (score_size_y + offset_y);
2709 if (max_fragcount == score)
2710 HUD_Panel_DrawHighlight(score_pos, score_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2711 drawstring_aspect(score_pos, ftos(score), score_size, Team_ColorRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2719 else if(tm.team == myteam) {
2720 if (max_fragcount == score)
2721 HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2722 drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize_x + eY * mySize_y, Team_ColorRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2724 if (max_fragcount == score)
2725 HUD_Panel_DrawHighlight(pos + eX * 0.75 * mySize_x + eY * (1/3) * rows * mySize_y, score_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2726 drawstring_aspect(pos + eX * 0.75 * mySize_x + eY * (1/3) * rows * mySize_y, ftos(score), score_size, Team_ColorRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2736 void HUD_RaceTimer (void)
2738 if(!autocvar__hud_configure)
2740 if(!autocvar_hud_panel_racetimer) return;
2741 if(!(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return;
2742 if(spectatee_status == -1) return;
2745 hud_configure_active_panel = HUD_PANEL_RACETIMER;
2747 HUD_Panel_UpdateCvars(racetimer);
2748 HUD_Panel_ApplyFadeAlpha();
2750 draw_beginBoldFont();
2754 mySize = panel_size;
2756 HUD_Panel_DrawBg(1);
2757 if(panel_bg_padding)
2759 pos += '1 1 0' * panel_bg_padding;
2760 mySize -= '2 2 0' * panel_bg_padding;
2763 // always force 4:1 aspect
2764 vector newSize = '0 0 0';
2765 if(mySize_x/mySize_y > 4)
2767 newSize_x = 4 * mySize_y;
2768 newSize_y = mySize_y;
2770 pos_x = pos_x + (mySize_x - newSize_x) / 2;
2774 newSize_y = 1/4 * mySize_x;
2775 newSize_x = mySize_x;
2777 pos_y = pos_y + (mySize_y - newSize_y) / 2;
2782 string s, forcetime;
2784 if(autocvar__hud_configure)
2787 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', panel_fg_alpha, DRAWFLAG_NORMAL);
2788 s = _("^1Intermediate 1 (+15.42)");
2789 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, panel_fg_alpha, DRAWFLAG_NORMAL);
2790 s = sprintf(_("^1PENALTY: %.1f (%s)"), 2, "missing a checkpoint");
2791 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, panel_fg_alpha, DRAWFLAG_NORMAL);
2793 else if(race_checkpointtime)
2795 a = bound(0, 2 - (time - race_checkpointtime), 1);
2798 if(a > 0) // just hit a checkpoint?
2800 if(race_checkpoint != 254)
2802 if(race_time && race_previousbesttime)
2803 s = MakeRaceString(race_checkpoint, TIME_DECODE(race_time) - TIME_DECODE(race_previousbesttime), 0, 0, race_previousbestname);
2805 s = MakeRaceString(race_checkpoint, 0, -1, 0, race_previousbestname);
2807 forcetime = TIME_ENCODED_TOSTRING(race_time);
2812 if(race_laptime && race_nextbesttime && race_nextcheckpoint != 254)
2814 a = bound(0, 2 - ((race_laptime + TIME_DECODE(race_nextbesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1);
2815 if(a > 0) // next one?
2817 s = MakeRaceString(race_nextcheckpoint, (time + TIME_DECODE(race_penaltyaccumulator)) - race_laptime, TIME_DECODE(race_nextbesttime), 0, race_nextbestname);
2822 if(s != "" && a > 0)
2824 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, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2827 if(race_penaltytime)
2829 a = bound(0, 2 - (time - race_penaltyeventtime), 1);
2832 s = sprintf(_("^1PENALTY: %.1f (%s)"), race_penaltytime * 0.1, race_penaltyreason);
2833 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, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2839 a = bound(0, (time - race_checkpointtime) / 0.5, 1);
2840 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', panel_fg_alpha, 0, a);
2845 if(race_laptime && race_checkpoint != 255)
2847 s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime));
2848 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', panel_fg_alpha * a, DRAWFLAG_NORMAL);
2853 if(race_mycheckpointtime)
2855 a = bound(0, 2 - (time - race_mycheckpointtime), 1);
2856 s = MakeRaceString(race_mycheckpoint, TIME_DECODE(race_mycheckpointdelta), -(race_mycheckpointenemy == ""), race_mycheckpointlapsdelta, race_mycheckpointenemy);
2857 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, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2859 if(race_othercheckpointtime && race_othercheckpointenemy != "")
2861 a = bound(0, 2 - (time - race_othercheckpointtime), 1);
2862 s = MakeRaceString(race_othercheckpoint, -TIME_DECODE(race_othercheckpointdelta), -(race_othercheckpointenemy == ""), race_othercheckpointlapsdelta, race_othercheckpointenemy);
2863 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, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2866 if(race_penaltytime && !race_penaltyaccumulator)
2868 t = race_penaltytime * 0.1 + race_penaltyeventtime;
2869 a = bound(0, (1 + t - time), 1);
2873 s = sprintf(_("^1PENALTY: %.1f (%s)"), (t - time) * 0.1, race_penaltyreason);
2875 s = sprintf(_("^2PENALTY: %.1f (%s)"), 0, race_penaltyreason);
2876 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, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2886 float vote_yescount;
2889 float vote_highlighted; // currently selected vote
2891 float vote_active; // is there an active vote?
2892 float vote_prev; // previous state of vote_active to check for a change
2894 float vote_change; // "time" when vote_active changed
2896 void HUD_VoteWindow(void)
2898 if(autocvar_cl_allow_uid2name == -1 && (gametype == MAPINFO_TYPE_CTS || gametype == MAPINFO_TYPE_RACE || (serverflags & SERVERFLAG_PLAYERSTATS)))
2901 if (autocvar__hud_configure)
2905 print(_("^1You must answer before entering hud configure mode\n"));
2906 cvar_set("_hud_configure", "0");
2908 if(vote_called_vote)
2909 strunzone(vote_called_vote);
2910 vote_called_vote = strzone(_("^2Name ^7instead of \"^1Anonymous player^7\" in stats"));
2911 uid2name_dialog = 1;
2914 if(!autocvar__hud_configure)
2916 if(!autocvar_hud_panel_vote) return;
2918 panel_fg_alpha = autocvar_hud_panel_fg_alpha;
2919 panel_bg_alpha_str = autocvar_hud_panel_vote_bg_alpha;
2921 if(panel_bg_alpha_str == "") {
2922 panel_bg_alpha_str = ftos(autocvar_hud_panel_bg_alpha);
2924 panel_bg_alpha = stof(panel_bg_alpha_str);
2928 hud_configure_active_panel = HUD_PANEL_VOTE;
2937 if(vote_active != vote_prev) {
2939 vote_prev = vote_active;
2942 if(vote_active || autocvar__hud_configure)
2943 vote_alpha = bound(0, (time - vote_change) * 2, 1);
2945 vote_alpha = bound(0, 1 - (time - vote_change) * 2, 1);
2950 HUD_Panel_UpdateCvars(vote);
2951 HUD_Panel_ApplyFadeAlpha();
2955 panel_pos = eX * 0.3 * vid_conwidth + eY * 0.1 * vid_conheight;
2956 panel_size = eX * 0.4 * vid_conwidth + eY * 0.3 * vid_conheight;
2959 // these must be below above block
2962 mySize = panel_size;
2964 a = vote_alpha * (vote_highlighted ? autocvar_hud_panel_vote_alreadyvoted_alpha : 1);
2965 HUD_Panel_DrawBg(a);
2966 a = panel_fg_alpha * a;
2968 if(panel_bg_padding)
2970 pos += '1 1 0' * panel_bg_padding;
2971 mySize -= '2 2 0' * panel_bg_padding;
2974 // always force 3:1 aspect
2975 vector newSize = '0 0 0';
2976 if(mySize_x/mySize_y > 3)
2978 newSize_x = 3 * mySize_y;
2979 newSize_y = mySize_y;
2981 pos_x = pos_x + (mySize_x - newSize_x) / 2;
2985 newSize_y = 1/3 * mySize_x;
2986 newSize_x = mySize_x;
2988 pos_y = pos_y + (mySize_y - newSize_y) / 2;
2992 s = _("A vote has been called for:");
2994 s = _("Allow servers to store and display your name?");
2995 drawstring_aspect(pos, s, eX * mySize_x + eY * (2/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
2996 s = textShortenToWidth(vote_called_vote, mySize_x, '1 1 0' * mySize_y * (1/8), stringwidth_colors);
2997 if(autocvar__hud_configure)
2998 s = _("^1Configure the HUD");
2999 drawcolorcodedstring_aspect(pos + eY * (2/8) * mySize_y, s, eX * mySize_x + eY * (1.75/8) * mySize_y, a, DRAWFLAG_NORMAL);
3001 // print the yes/no counts
3002 s = sprintf(_("Yes (%s): %d"), getcommandkey("vyes", "vyes"), vote_yescount);
3003 drawstring_aspect(pos + eY * (4/8) * mySize_y, s, eX * 0.5 * mySize_x + eY * (1.5/8) * mySize_y, '0 1 0', a, DRAWFLAG_NORMAL);
3004 s = sprintf(_("No (%s): %d"), getcommandkey("vno", "vno"), vote_nocount);
3005 drawstring_aspect(pos + eX * 0.5 * mySize_x + eY * (4/8) * mySize_y, s, eX * 0.5 * mySize_x + eY * (1.5/8) * mySize_y, '1 0 0', a, DRAWFLAG_NORMAL);
3007 // draw the progress bar backgrounds
3008 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_back", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
3010 // draw the highlights
3011 if(vote_highlighted == 1) {
3012 drawsetcliparea(pos_x, pos_y, mySize_x * 0.5, mySize_y);
3013 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_voted", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
3015 else if(vote_highlighted == -1) {
3016 drawsetcliparea(pos_x + 0.5 * mySize_x, pos_y, mySize_x * 0.5, mySize_y);
3017 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_voted", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
3020 // draw the progress bars
3021 if(vote_yescount && vote_needed)
3023 drawsetcliparea(pos_x, pos_y, mySize_x * 0.5 * (vote_yescount/vote_needed), mySize_y);
3024 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_prog", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
3027 if(vote_nocount && vote_needed)
3029 drawsetcliparea(pos_x + mySize_x - mySize_x * 0.5 * (vote_nocount/vote_needed), pos_y, mySize_x * 0.5, mySize_y);
3030 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_prog", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
3033 drawresetcliparea();
3036 // Mod icons panel (#10)
3039 float mod_active; // is there any active mod icon?
3041 // Clan Arena HUD modicons
3042 void HUD_Mod_CA(vector pos, vector mySize)
3044 mod_active = 1; // CA should never hide the mod icons panel
3045 float redalive, bluealive;
3046 redalive = getstati(STAT_REDALIVE);
3047 bluealive = getstati(STAT_BLUEALIVE);
3049 vector redpos, bluepos;
3050 if(mySize_x > mySize_y)
3053 bluepos = pos + eY * 0.5 * mySize_y;
3054 drawpic_aspect_skin(redpos, "player_red.tga", 0.5 * mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3055 drawstring_aspect(redpos + eX * 0.5 * mySize_x, ftos(redalive), 0.5 * mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3056 drawpic_aspect_skin(bluepos, "player_blue.tga", 0.5 * mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3057 drawstring_aspect(bluepos + eX * 0.5 * mySize_x, ftos(bluealive), 0.5 * mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3062 bluepos = pos + eY * 0.5 * mySize_y;
3063 drawpic_aspect_skin(redpos, "player_red.tga", eX * mySize_x + eY * 0.3 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3064 drawstring_aspect(redpos + eY * 0.3 * mySize_y, ftos(redalive), eX * mySize_x + eY * 0.2 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3065 drawpic_aspect_skin(bluepos, "player_blue.tga", eX * mySize_x + eY * 0.3 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3066 drawstring_aspect(bluepos + eY * 0.3 * mySize_y, ftos(bluealive), eX * mySize_x + eY * 0.2 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3070 // CTF HUD modicon section
3071 float redflag_prevframe, blueflag_prevframe; // status during previous frame
3072 float redflag_prevstatus, blueflag_prevstatus; // last remembered status
3073 float redflag_statuschange_time, blueflag_statuschange_time; // time when the status changed
3075 void HUD_Mod_CTF_Reset(void)
3077 redflag_prevstatus = blueflag_prevstatus = redflag_prevframe = blueflag_prevframe = redflag_statuschange_time = blueflag_statuschange_time = 0;
3080 void HUD_Mod_CTF(vector pos, vector mySize)
3082 vector redflag_pos, blueflag_pos;
3084 float f; // every function should have that
3086 float redflag, blueflag; // current status
3087 float redflag_statuschange_elapsedtime, blueflag_statuschange_elapsedtime; // time since the status changed
3090 stat_items = getstati(STAT_ITEMS, 0, 24);
3091 redflag = (stat_items/IT_RED_FLAG_TAKEN) & 3;
3092 blueflag = (stat_items/IT_BLUE_FLAG_TAKEN) & 3;
3094 if(redflag || blueflag)
3099 if(autocvar__hud_configure)
3105 // when status CHANGES, set old status into prevstatus and current status into status
3106 if (redflag != redflag_prevframe)
3108 redflag_statuschange_time = time;
3109 redflag_prevstatus = redflag_prevframe;
3110 redflag_prevframe = redflag;
3113 if (blueflag != blueflag_prevframe)
3115 blueflag_statuschange_time = time;
3116 blueflag_prevstatus = blueflag_prevframe;
3117 blueflag_prevframe = blueflag;
3120 redflag_statuschange_elapsedtime = time - redflag_statuschange_time;
3121 blueflag_statuschange_elapsedtime = time - blueflag_statuschange_time;
3123 float BLINK_FACTOR = 0.15;
3124 float BLINK_BASE = 0.85;
3126 // RMS = sqrt(BLINK_BASE^2 + 0.5 * BLINK_FACTOR^2)
3128 // BLINK_BASE = sqrt(RMS^2 - 0.5 * BLINK_FACTOR^2)
3130 float BLINK_FREQ = 5; // circle frequency, = 2*pi*frequency in hertz
3132 string red_icon, red_icon_prevstatus;
3133 float red_alpha, red_alpha_prevstatus;
3134 red_alpha = red_alpha_prevstatus = 1;
3136 case 1: red_icon = "flag_red_taken"; break;
3137 case 2: red_icon = "flag_red_lost"; break;
3138 case 3: red_icon = "flag_red_carrying"; red_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3140 if((stat_items & IT_CTF_SHIELDED) && (myteam == FL_TEAM_2))
3141 red_icon = "flag_red_shielded";
3143 red_icon = string_null;
3146 switch(redflag_prevstatus) {
3147 case 1: red_icon_prevstatus = "flag_red_taken"; break;
3148 case 2: red_icon_prevstatus = "flag_red_lost"; break;
3149 case 3: red_icon_prevstatus = "flag_red_carrying"; red_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3152 red_icon_prevstatus = "flag_red_carrying"; // make it more visible
3153 else if((stat_items & IT_CTF_SHIELDED) && (myteam == FL_TEAM_2))
3154 red_icon_prevstatus = "flag_red_shielded";
3156 red_icon_prevstatus = string_null;
3160 string blue_icon, blue_icon_prevstatus;
3161 float blue_alpha, blue_alpha_prevstatus;
3162 blue_alpha = blue_alpha_prevstatus = 1;
3164 case 1: blue_icon = "flag_blue_taken"; break;
3165 case 2: blue_icon = "flag_blue_lost"; break;
3166 case 3: blue_icon = "flag_blue_carrying"; blue_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3168 if((stat_items & IT_CTF_SHIELDED) && (myteam == FL_TEAM_1))
3169 blue_icon = "flag_blue_shielded";
3171 blue_icon = string_null;
3174 switch(blueflag_prevstatus) {
3175 case 1: blue_icon_prevstatus = "flag_blue_taken"; break;
3176 case 2: blue_icon_prevstatus = "flag_blue_lost"; break;
3177 case 3: blue_icon_prevstatus = "flag_blue_carrying"; blue_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3180 blue_icon_prevstatus = "flag_blue_carrying"; // make it more visible
3181 else if((stat_items & IT_CTF_SHIELDED) && (myteam == FL_TEAM_1))
3182 blue_icon_prevstatus = "flag_blue_shielded";
3184 blue_icon_prevstatus = string_null;
3188 if(mySize_x > mySize_y) {
3189 if (myteam == FL_TEAM_1) { // always draw own flag on left
3191 blueflag_pos = pos + eX * 0.5 * mySize_x;
3194 redflag_pos = pos + eX * 0.5 * mySize_x;
3196 flag_size = eX * 0.5 * mySize_x + eY * mySize_y;
3198 if (myteam == FL_TEAM_1) { // always draw own flag on left
3200 blueflag_pos = pos + eY * 0.5 * mySize_y;
3203 redflag_pos = pos + eY * 0.5 * mySize_y;
3205 flag_size = eY * 0.5 * mySize_y + eX * mySize_x;
3208 f = bound(0, redflag_statuschange_elapsedtime*2, 1);
3209 if(red_icon_prevstatus && f < 1)
3210 drawpic_aspect_skin_expanding(redflag_pos, red_icon_prevstatus, flag_size, '1 1 1', panel_fg_alpha * red_alpha_prevstatus, DRAWFLAG_NORMAL, f);
3212 drawpic_aspect_skin(redflag_pos, red_icon, flag_size, '1 1 1', panel_fg_alpha * red_alpha * f, DRAWFLAG_NORMAL);
3214 f = bound(0, blueflag_statuschange_elapsedtime*2, 1);
3215 if(blue_icon_prevstatus && f < 1)
3216 drawpic_aspect_skin_expanding(blueflag_pos, blue_icon_prevstatus, flag_size, '1 1 1', panel_fg_alpha * blue_alpha_prevstatus, DRAWFLAG_NORMAL, f);
3218 drawpic_aspect_skin(blueflag_pos, blue_icon, flag_size, '1 1 1', panel_fg_alpha * blue_alpha * f, DRAWFLAG_NORMAL);
3221 // Keyhunt HUD modicon section
3222 float kh_runheretime;
3224 void HUD_Mod_KH_Reset(void)
3229 void HUD_Mod_KH(vector pos, vector mySize)
3231 mod_active = 1; // keyhunt should never hide the mod icons panel
3235 vector p = '0 0 0', pa, kh_size = '0 0 0', kh_asize = '0 0 0';
3237 kh_keys = getstati(STAT_KH_KEYS);
3240 if(mySize_x > mySize_y)
3242 p_y = pos_y + 0.25 * mySize_y;
3243 pa = p - eY * 0.25 * mySize_y;
3245 kh_size_x = mySize_x * 0.25;
3246 kh_size_y = 0.75 * mySize_y;
3247 kh_asize_x = mySize_x * 0.25;
3248 kh_asize_y = mySize_y * 0.25;
3252 p_y = pos_y + 0.125 * mySize_y;
3253 pa = p - eY * 0.125 * mySize_y;
3255 kh_size_x = mySize_x * 0.5;
3256 kh_size_y = 0.375 * mySize_y;
3257 kh_asize_x = mySize_x * 0.5;
3258 kh_asize_y = mySize_y * 0.125;
3265 for(i = 0; i < 4; ++i)
3267 key = floor(kh_keys / pow(32, i)) & 31;
3269 if(keyteam == 30 && keycount <= 4)
3271 if(keyteam == myteam || keyteam == -1 || keyteam == 30)
3275 // this yields 8 exactly if "RUN HERE" shows
3280 kh_runheretime = time;
3281 pa_y -= fabs(sin((time - kh_runheretime) * 3.5)) * 6; // make the arrows jump in case of RUN HERE
3286 for(i = 0; i < 4; ++i)
3288 key = floor(kh_keys / pow(32, i)) & 31;
3301 default: // owned or dropped
3306 a = a * panel_fg_alpha;
3307 aa = aa * panel_fg_alpha;
3313 drawpic_aspect_skin(pa, "kh_redarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% theAlpha key
3316 drawpic_aspect_skin(pa, "kh_bluearrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% theAlpha key
3319 drawpic_aspect_skin(pa, "kh_yellowarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% theAlpha key
3322 drawpic_aspect_skin(pa, "kh_pinkarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% theAlpha key
3327 switch(i) // YAY! switch(i) inside a for loop for i. DailyWTF, here we come!
3330 drawpic_aspect_skin(p, "kh_red", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% theAlpha key
3333 drawpic_aspect_skin(p, "kh_blue", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% theAlpha key
3336 drawpic_aspect_skin(p, "kh_yellow", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% theAlpha key
3339 drawpic_aspect_skin(p, "kh_pink", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% theAlpha key
3343 if(mySize_x > mySize_y)
3345 p_x += 0.25 * mySize_x;
3346 pa_x += 0.25 * mySize_x;
3352 p_y = pos_y + 0.625 * mySize_y;
3353 pa_y = pos_y + 0.5 * mySize_y;
3359 p_x += 0.5 * mySize_x;
3360 pa_x += 0.5 * mySize_x;
3366 // Keepaway HUD mod icon
3367 float kaball_prevstatus; // last remembered status
3368 float kaball_statuschange_time; // time when the status changed
3370 // we don't need to reset for keepaway since it immediately
3371 // autocorrects prevstatus as to if the player has the ball or not
3373 void HUD_Mod_Keepaway(vector pos, vector mySize)
3375 mod_active = 1; // keepaway should always show the mod HUD
3377 float BLINK_FACTOR = 0.15;
3378 float BLINK_BASE = 0.85;
3379 float BLINK_FREQ = 5;
3380 float kaball_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ);
3382 float stat_items = getstati(STAT_ITEMS, 0, 24);
3383 float kaball = (stat_items/IT_KEY1) & 1;
3385 if(kaball != kaball_prevstatus)
3387 kaball_statuschange_time = time;
3388 kaball_prevstatus = kaball;
3391 vector kaball_pos, kaball_size;
3393 if(mySize_x > mySize_y) {
3394 kaball_pos = pos + eX * 0.25 * mySize_x;
3395 kaball_size = eX * 0.5 * mySize_x + eY * mySize_y;
3397 kaball_pos = pos + eY * 0.25 * mySize_y;
3398 kaball_size = eY * 0.5 * mySize_y + eX * mySize_x;
3401 float kaball_statuschange_elapsedtime = time - kaball_statuschange_time;
3402 float f = bound(0, kaball_statuschange_elapsedtime*2, 1);
3404 if(kaball_prevstatus && f < 1)
3405 drawpic_aspect_skin_expanding(kaball_pos, "keepawayball_carrying", kaball_size, '1 1 1', panel_fg_alpha * kaball_alpha, DRAWFLAG_NORMAL, f);
3408 drawpic_aspect_skin(pos, "keepawayball_carrying", eX * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha * kaball_alpha * f, DRAWFLAG_NORMAL);
3412 // Nexball HUD mod icon
3413 void HUD_Mod_NexBall(vector pos, vector mySize)
3415 float stat_items, nb_pb_starttime, dt, p;
3417 stat_items = getstati(STAT_ITEMS, 0, 24);
3418 nb_pb_starttime = getstatf(STAT_NB_METERSTART);
3420 if (stat_items & IT_KEY1)
3425 //Manage the progress bar if any
3426 if (nb_pb_starttime > 0)
3428 dt = mod(time - nb_pb_starttime, nb_pb_period);
3429 // one period of positive triangle
3430 p = 2 * dt / nb_pb_period;
3435 HUD_Panel_GetProgressBarColor(nexball);
3436 if(mySize_x > mySize_y)
3437 HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", p, 0, 0, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
3439 HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", p, 1, 0, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
3442 if (stat_items & IT_KEY1)
3443 drawpic_aspect_skin(pos, "nexball_carrying", eX * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3446 // Race/CTS HUD mod icons
3447 float crecordtime_prev; // last remembered crecordtime
3448 float crecordtime_change_time; // time when crecordtime last changed
3449 float srecordtime_prev; // last remembered srecordtime
3450 float srecordtime_change_time; // time when srecordtime last changed
3452 float race_status_time;
3453 float race_status_prev;
3454 string race_status_name_prev;
3455 void HUD_Mod_Race(vector pos, vector mySize)
3457 mod_active = 1; // race should never hide the mod icons panel
3459 me = playerslots[player_localnum];
3461 float f; // yet another function has this
3462 score = me.(scores[ps_primary]);
3464 if not((scores_flags[ps_primary] & SFL_TIME) && !teamplay) // race/cts record display on HUD
3465 return; // no records in the actual race
3467 // clientside personal record
3469 if(gametype == MAPINFO_TYPE_CTS)
3473 t = stof(db_get(ClientProgsDB, strcat(shortmapname, rr, "time")));
3475 if(score && (score < t || !t)) {
3476 db_put(ClientProgsDB, strcat(shortmapname, rr, "time"), ftos(score));
3477 if(autocvar_cl_autodemo_delete_keeprecords)
3479 f = autocvar_cl_autodemo_delete;
3481 cvar_set("cl_autodemo_delete", ftos(f)); // don't delete demo with new record!
3485 if(t != crecordtime_prev) {
3486 crecordtime_prev = t;
3487 crecordtime_change_time = time;
3490 vector textPos, medalPos;
3492 if(mySize_x > mySize_y) {
3493 // text on left side
3494 squareSize = min(mySize_y, mySize_x/2);
3495 textPos = pos + eX * 0.5 * max(0, mySize_x/2 - squareSize) + eY * 0.5 * (mySize_y - squareSize);
3496 medalPos = pos + eX * 0.5 * max(0, mySize_x/2 - squareSize) + eX * 0.5 * mySize_x + eY * 0.5 * (mySize_y - squareSize);
3499 squareSize = min(mySize_x, mySize_y/2);
3500 textPos = pos + eY * 0.5 * max(0, mySize_y/2 - squareSize) + eX * 0.5 * (mySize_x - squareSize);
3501 medalPos = pos + eY * 0.5 * max(0, mySize_y/2 - squareSize) + eY * 0.5 * mySize_y + eX * 0.5 * (mySize_x - squareSize);
3504 f = time - crecordtime_change_time;
3507 drawstring_aspect(textPos, _("Personal best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3508 drawstring_aspect(textPos + eY * 0.25 * squareSize, TIME_ENCODED_TOSTRING(t), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3510 drawstring_aspect(textPos, _("Personal best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3511 drawstring_aspect(textPos + eY * 0.25 * squareSize, TIME_ENCODED_TOSTRING(t), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3512 drawstring_aspect_expanding(pos, _("Personal best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
3513 drawstring_aspect_expanding(pos + eY * 0.25 * squareSize, TIME_ENCODED_TOSTRING(t), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
3517 t = race_server_record;
3518 if(t != srecordtime_prev) {
3519 srecordtime_prev = t;
3520 srecordtime_change_time = time;
3522 f = time - srecordtime_change_time;
3525 drawstring_aspect(textPos + eY * 0.5 * squareSize, _("Server best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3526 drawstring_aspect(textPos + eY * 0.75 * squareSize, TIME_ENCODED_TOSTRING(t), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3528 drawstring_aspect(textPos + eY * 0.5 * squareSize, _("Server best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3529 drawstring_aspect(textPos + eY * 0.75 * squareSize, TIME_ENCODED_TOSTRING(t), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3530 drawstring_aspect_expanding(textPos + eY * 0.5 * squareSize, _("Server best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
3531 drawstring_aspect_expanding(textPos + eY * 0.75 * squareSize, TIME_ENCODED_TOSTRING(t), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
3534 if (race_status != race_status_prev || race_status_name != race_status_name_prev) {
3535 race_status_time = time + 5;
3536 race_status_prev = race_status;
3537 if (race_status_name_prev)
3538 strunzone(race_status_name_prev);
3539 race_status_name_prev = strzone(race_status_name);
3544 a = bound(0, race_status_time - time, 1);
3547 s = textShortenToWidth(race_status_name, squareSize, '1 1 0' * 0.1 * squareSize, stringwidth_colors);
3551 rank = race_CheckName(race_status_name);
3555 rankname = race_PlaceName(rank);
3558 namepos = medalPos + '0 0.8 0' * squareSize;
3560 rankpos = medalPos + '0 0.15 0' * squareSize;
3562 if(race_status == 0)
3563 drawpic_aspect_skin(medalPos, "race_newfail", '1 1 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3564 else if(race_status == 1) {
3565 drawpic_aspect_skin(medalPos + '0.1 0 0' * squareSize, "race_newtime", '1 1 0' * 0.8 * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3566 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3567 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3568 } else if(race_status == 2) {
3569 if(race_status_name == GetPlayerName(player_localnum) || !race_myrank || race_myrank < rank)
3570 drawpic_aspect_skin(medalPos + '0.1 0 0' * squareSize, "race_newrankgreen", '1 1 0' * 0.8 * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3572 drawpic_aspect_skin(medalPos + '0.1 0 0' * squareSize, "race_newrankyellow", '1 1 0' * 0.8 * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3573 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3574 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3575 } else if(race_status == 3) {
3576 drawpic_aspect_skin(medalPos + '0.1 0 0' * squareSize, "race_newrecordserver", '1 1 0' * 0.8 * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3577 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3578 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3581 if (race_status_time - time <= 0) {
3582 race_status_prev = -1;
3584 if(race_status_name)
3585 strunzone(race_status_name);
3586 race_status_name = string_null;
3587 if(race_status_name_prev)
3588 strunzone(race_status_name_prev);
3589 race_status_name_prev = string_null;
3593 void DrawDomItem(vector myPos, vector mySize, float aspect_ratio, float layout, float i)
3595 float stat, pps_ratio;
3606 stat = getstatf(STAT_DOM_PPS_RED);
3607 pic = "dom_icon_red";
3611 stat = getstatf(STAT_DOM_PPS_BLUE);
3612 pic = "dom_icon_blue";
3616 stat = getstatf(STAT_DOM_PPS_YELLOW);
3617 pic = "dom_icon_yellow";
3622 stat = getstatf(STAT_DOM_PPS_PINK);
3623 pic = "dom_icon_pink";
3627 pps_ratio = stat / getstatf(STAT_DOM_TOTAL_PPS);
3629 if(mySize_x/mySize_y > aspect_ratio)
3631 i = aspect_ratio * mySize_y;
3632 myPos_x = myPos_x + (mySize_x - i) / 2;
3637 i = 1/aspect_ratio * mySize_x;
3638 myPos_y = myPos_y + (mySize_y - i) / 2;
3642 if (layout) // show text too
3645 color *= 0.5 + pps_ratio * (1 - 0.5); // half saturated color at min, full saturated at max
3646 if (layout == 2) // average pps
3647 drawstring_aspect(myPos + eX * mySize_y, ftos_decimals(stat, 2), eX * (2/3) * mySize_x + eY * mySize_y, color, panel_fg_alpha, DRAWFLAG_NORMAL);
3648 else // percentage of average pps
3649 drawstring_aspect(myPos + eX * mySize_y, strcat( ftos(floor(pps_ratio*100 + 0.5)), "%" ), eX * (2/3) * mySize_x + eY * mySize_y, color, panel_fg_alpha, DRAWFLAG_NORMAL);
3653 drawpic_aspect_skin(myPos, pic, '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3656 drawsetcliparea(myPos_x, myPos_y + mySize_y * (1 - pps_ratio), mySize_y, mySize_y * pps_ratio);
3657 drawpic_aspect_skin(myPos, strcat(pic, "-highlighted"), '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3658 drawresetcliparea();
3662 void HUD_Mod_Dom(vector myPos, vector mySize)
3664 mod_active = 1; // required in each mod function that always shows something
3666 float teams_count = 0;
3667 for(tm = teams.sort_next; tm; tm = tm.sort_next)
3668 if(tm.team != FL_SPECTATOR)
3671 float layout = autocvar_hud_panel_modicons_dom_layout;
3672 float rows, columns, aspect_ratio;
3673 rows = mySize_y/mySize_x;
3674 aspect_ratio = (layout) ? 3 : 1;
3675 rows = bound(1, floor((sqrt((4 * aspect_ratio * teams_count + rows) * rows) + rows + 0.5) / 2), teams_count);
3676 columns = ceil(teams_count/rows);
3679 float row = 0, column = 0;
3680 for(i=0; i<teams_count; ++i)
3682 vector pos, itemSize;
3683 pos = myPos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows);
3684 itemSize = eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows);
3686 DrawDomItem(pos, itemSize, aspect_ratio, layout, i);
3697 float mod_prev; // previous state of mod_active to check for a change
3699 float mod_change; // "time" when mod_active changed
3701 void HUD_ModIcons(void)
3703 if(!autocvar__hud_configure)
3705 if(!autocvar_hud_panel_modicons) return;
3706 if (gametype != MAPINFO_TYPE_CTF && gametype != MAPINFO_TYPE_KEYHUNT && gametype != MAPINFO_TYPE_NEXBALL && gametype != MAPINFO_TYPE_CTS && gametype != MAPINFO_TYPE_RACE && gametype != MAPINFO_TYPE_CA && gametype != MAPINFO_TYPE_FREEZETAG && gametype != MAPINFO_TYPE_KEEPAWAY && gametype != MAPINFO_TYPE_DOMINATION) return;
3709 hud_configure_active_panel = HUD_PANEL_MODICONS;
3711 HUD_Panel_UpdateCvars(modicons);
3712 HUD_Panel_ApplyFadeAlpha();
3714 draw_beginBoldFont();
3718 mySize = panel_size;
3720 if(mod_active != mod_prev) {
3722 mod_prev = mod_active;
3725 if(mod_active || autocvar__hud_configure)
3726 mod_alpha = bound(0, (time - mod_change) * 2, 1);
3728 mod_alpha = bound(0, 1 - (time - mod_change) * 2, 1);
3731 HUD_Panel_DrawBg(mod_alpha);
3733 if(panel_bg_padding)
3735 pos += '1 1 0' * panel_bg_padding;
3736 mySize -= '2 2 0' * panel_bg_padding;
3739 // these MUST be ran in order to update mod_active
3740 if(gametype == MAPINFO_TYPE_KEYHUNT)
3741 HUD_Mod_KH(pos, mySize);
3742 else if(gametype == MAPINFO_TYPE_CTF || autocvar__hud_configure)
3743 HUD_Mod_CTF(pos, mySize); // forcealpha only needed for ctf icons, as only they are shown in config mode
3744 else if(gametype == MAPINFO_TYPE_NEXBALL)
3745 HUD_Mod_NexBall(pos, mySize);
3746 else if(gametype == MAPINFO_TYPE_CTS || gametype == MAPINFO_TYPE_RACE)
3747 HUD_Mod_Race(pos, mySize);
3748 else if(gametype == MAPINFO_TYPE_CA || gametype == MAPINFO_TYPE_FREEZETAG)
3749 HUD_Mod_CA(pos, mySize);
3750 else if(gametype == MAPINFO_TYPE_DOMINATION)
3751 HUD_Mod_Dom(pos, mySize);
3752 else if(gametype == MAPINFO_TYPE_KEEPAWAY)
3753 HUD_Mod_Keepaway(pos, mySize);
3758 // Draw pressed keys (#11)
3760 void HUD_DrawPressedKeys(void)
3762 if(!autocvar__hud_configure)
3764 if(!autocvar_hud_panel_pressedkeys) return;
3765 if(spectatee_status <= 0 && autocvar_hud_panel_pressedkeys < 2) return;
3768 hud_configure_active_panel = HUD_PANEL_PRESSEDKEYS;
3771 HUD_Panel_UpdateCvars(pressedkeys);
3772 HUD_Panel_ApplyFadeAlpha();
3775 mySize = panel_size;
3777 HUD_Panel_DrawBg(1);
3778 if(panel_bg_padding)
3780 pos += '1 1 0' * panel_bg_padding;
3781 mySize -= '2 2 0' * panel_bg_padding;
3784 // force custom aspect
3785 float aspect = autocvar_hud_panel_pressedkeys_aspect;
3788 vector newSize = '0 0 0';
3789 if(mySize_x/mySize_y > aspect)
3791 newSize_x = aspect * mySize_y;
3792 newSize_y = mySize_y;
3794 pos_x = pos_x + (mySize_x - newSize_x) / 2;
3798 newSize_y = 1/aspect * mySize_x;
3799 newSize_x = mySize_x;
3801 pos_y = pos_y + (mySize_y - newSize_y) / 2;
3807 keysize = eX * mySize_x * (1/3.0) + eY * mySize_y * (1/(3.0 - !autocvar_hud_panel_pressedkeys_attack));
3809 pressedkeys = getstatf(STAT_PRESSED_KEYS);
3811 if(autocvar_hud_panel_pressedkeys_attack)
3813 drawpic_aspect_skin(pos + eX * keysize_x * 0.5, ((pressedkeys & KEY_ATCK) ? "key_atck_inv.tga" : "key_atck.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3814 drawpic_aspect_skin(pos + eX * keysize_x * 1.5, ((pressedkeys & KEY_ATCK2) ? "key_atck_inv.tga" : "key_atck.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3818 drawpic_aspect_skin(pos, ((pressedkeys & KEY_CROUCH) ? "key_crouch_inv.tga" : "key_crouch.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3819 drawpic_aspect_skin(pos + eX * keysize_x, ((pressedkeys & KEY_FORWARD) ? "key_forward_inv.tga" : "key_forward.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3820 drawpic_aspect_skin(pos + eX * keysize_x * 2, ((pressedkeys & KEY_JUMP) ? "key_jump_inv.tga" : "key_jump.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3822 drawpic_aspect_skin(pos, ((pressedkeys & KEY_LEFT) ? "key_left_inv.tga" : "key_left.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3823 drawpic_aspect_skin(pos + eX * keysize_x, ((pressedkeys & KEY_BACKWARD) ? "key_backward_inv.tga" : "key_backward.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3824 drawpic_aspect_skin(pos + eX * keysize_x * 2, ((pressedkeys & KEY_RIGHT) ? "key_right_inv.tga" : "key_right.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3827 // Handle chat as a panel (#12)
3831 if(!autocvar__hud_configure)
3833 if (!autocvar_hud_panel_chat)
3835 if (!autocvar_con_chatrect)
3836 cvar_set("con_chatrect", "0");
3839 if(autocvar__con_chat_maximized)
3840 if(!hud_draw_maximized) return;
3843 hud_configure_active_panel = HUD_PANEL_CHAT;
3845 HUD_Panel_UpdateCvars(chat);
3846 HUD_Panel_ApplyFadeAlpha();
3848 if(autocvar__con_chat_maximized && !autocvar__hud_configure) // draw at full screen height if maximized
3850 panel_pos_y = panel_bg_border;
3851 panel_size_y = vid_conheight - panel_bg_border * 2;
3852 if(panel_bg == "0") // force a border when maximized
3854 if(precache_pic(panel_bg) == "") {
3855 panel_bg = strcat(hud_skin_path, "/border_default");
3856 if(precache_pic(panel_bg) == "") {
3857 panel_bg = "gfx/hud/default/border_default";
3861 panel_bg_alpha = max(0.75, panel_bg_alpha); // force an theAlpha of at least 0.75
3866 mySize = panel_size;
3868 HUD_Panel_DrawBg(1);
3870 if(panel_bg_padding)
3872 pos += '1 1 0' * panel_bg_padding;
3873 mySize -= '2 2 0' * panel_bg_padding;
3876 if (!autocvar_con_chatrect)
3877 cvar_set("con_chatrect", "1");
3879 cvar_set("con_chatrect_x", ftos(pos_x/vid_conwidth));
3880 cvar_set("con_chatrect_y", ftos(pos_y/vid_conheight));
3882 cvar_set("con_chatwidth", ftos(mySize_x/vid_conwidth));
3883 cvar_set("con_chat", ftos(floor(mySize_y/autocvar_con_chatsize - 0.5)));
3885 if(autocvar__hud_configure)
3888 chatsize = '1 1 0' * autocvar_con_chatsize;
3889 cvar_set("con_chatrect_x", "9001"); // over 9000, we'll fake it instead for more control over theAlpha and such
3891 for(i = 0; i < autocvar_con_chat; ++i)
3893 if(i == autocvar_con_chat - 1)
3896 a = panel_fg_alpha * floor(((i + 1) * 7 + autocvar_con_chattime)/45);
3897 drawcolorcodedstring(pos, textShortenToWidth(_("^3Player^7: This is the chat area."), mySize_x, chatsize, stringwidth_colors), chatsize, a, DRAWFLAG_NORMAL);
3898 pos_y += chatsize_y;
3903 // Engine info panel (#13)
3910 float frametimeavg1; // 1 frame ago
3911 float frametimeavg2; // 2 frames ago
3912 void HUD_EngineInfo(void)
3914 if(!autocvar__hud_configure)
3916 if(!autocvar_hud_panel_engineinfo) return;
3919 hud_configure_active_panel = HUD_PANEL_ENGINEINFO;
3921 HUD_Panel_UpdateCvars(engineinfo);
3922 HUD_Panel_ApplyFadeAlpha();
3925 mySize = panel_size;
3927 HUD_Panel_DrawBg(1);
3928 if(panel_bg_padding)
3930 pos += '1 1 0' * panel_bg_padding;
3931 mySize -= '2 2 0' * panel_bg_padding;
3934 float currentTime = gettime(GETTIME_REALTIME);
3935 if(cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage"))
3937 float currentframetime = currentTime - prevfps_time;
3938 frametimeavg = (frametimeavg + frametimeavg1 + frametimeavg2 + currentframetime)/4; // average three frametimes into framecounter for slightly more stable fps readings :P
3939 frametimeavg2 = frametimeavg1;
3940 frametimeavg1 = frametimeavg;
3943 weight = cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage_new_weight");
3944 if(currentframetime > 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.
3946 if(fabs(prevfps - (1/frametimeavg)) > prevfps * cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage_instantupdate_change_threshold")) // if there was a big jump in fps, just force prevfps at current (1/currentframetime) to make big updates instant
3947 prevfps = (1/currentframetime);
3948 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"
3950 prevfps_time = currentTime;
3955 if(currentTime - prevfps_time > autocvar_hud_panel_engineinfo_framecounter_time)
3957 prevfps = framecounter/(currentTime - prevfps_time);
3959 prevfps_time = currentTime;
3964 color = HUD_Get_Num_Color (prevfps, 100);
3965 drawstring_aspect(pos, sprintf(_("FPS: %.*f"), autocvar_hud_panel_engineinfo_framecounter_decimals, prevfps), mySize, color, panel_fg_alpha, DRAWFLAG_NORMAL);
3968 // Info messages panel (#14)
3970 #define drawInfoMessage(s)\
3971 if(autocvar_hud_panel_infomessages_flip)\
3972 o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize);\
3973 drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);\
3975 void HUD_InfoMessages(void)
3977 if(!autocvar__hud_configure)
3979 if(!autocvar_hud_panel_infomessages) return;
3982 hud_configure_active_panel = HUD_PANEL_INFOMESSAGES;
3984 HUD_Panel_UpdateCvars(infomessages);
3985 HUD_Panel_ApplyFadeAlpha();
3988 mySize = panel_size;
3990 HUD_Panel_DrawBg(1);
3991 if(panel_bg_padding)
3993 pos += '1 1 0' * panel_bg_padding;
3994 mySize -= '2 2 0' * panel_bg_padding;
3997 // always force 5:1 aspect
3998 vector newSize = '0 0 0';
3999 if(mySize_x/mySize_y > 5)
4001 newSize_x = 5 * mySize_y;
4002 newSize_y = mySize_y;
4004 pos_x = pos_x + (mySize_x - newSize_x) / 2;
4008 newSize_y = 1/5 * mySize_x;
4009 newSize_x = mySize_x;
4011 pos_y = pos_y + (mySize_y - newSize_y) / 2;
4020 fontsize = '0.20 0.20 0' * mySize_y;
4026 if(!autocvar__hud_configure)
4028 if(spectatee_status && !intermission)
4031 if(spectatee_status == -1)
4032 s = _("^1Observing");
4034 #ifdef COMPAT_XON050_ENGINE
4035 s = sprintf(_("^1Spectating: ^7%s"), GetPlayerName(spectatee_status - 1));
4037 s = sprintf(_("^1Spectating: ^7%s"), GetPlayerName(player_localentnum - 1));
4041 if(spectatee_status == -1)
4042 s = sprintf(_("^1Press ^3%s^1 to spectate"), getcommandkey("primary fire", "+fire"));
4044 s = sprintf(_("^1Press ^3%s^1 for another player"), getcommandkey("primary fire", "+fire"));
4047 if(spectatee_status == -1)
4048 s = sprintf(_("^1Use ^3%s^1 or ^3%s^1 to change the speed"), getcommandkey("next weapon", "weapnext"), getcommandkey("previous weapon", "weapprev"));
4050 s = sprintf(_("^1Press ^3%s^1 to observe"), getcommandkey("secondary fire", "+fire2"));
4053 s = sprintf(_("^1Press ^3%s^1 for gamemode info"), getcommandkey("server info", "+show_info"));
4056 if(gametype == MAPINFO_TYPE_ARENA)
4057 s = _("^1Wait for your turn to join");
4058 else if(gametype == MAPINFO_TYPE_LMS)
4061 sk = playerslots[player_localnum];
4062 if(sk.(scores[ps_primary]) >= 666)
4063 s = _("^1Match has already begun");
4064 else if(sk.(scores[ps_primary]) > 0)
4065 s = _("^1You have no more lives left");
4067 s = sprintf(_("^1Press ^3%s^1 to join"), getcommandkey("jump", "+jump"));
4070 s = sprintf(_("^1Press ^3%s^1 to join"), getcommandkey("jump", "+jump"));
4073 //show restart countdown:
4074 if (time < getstatf(STAT_GAMESTARTTIME)) {
4076 //we need to ceil, otherwise the countdown would be off by .5 when using round()
4077 countdown = ceil(getstatf(STAT_GAMESTARTTIME) - time);
4078 s = sprintf(_("^1Game starts in ^3%d^1 seconds"), countdown);
4079 drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
4083 if(warmup_stage && !intermission)
4085 s = _("^2Currently in ^1warmup^2 stage!");
4090 if(mod(time, 1) >= 0.5)
4095 if(ready_waiting && !intermission && !spectatee_status)
4097 if(ready_waiting_for_me)
4100 s = sprintf(_("%sPress ^3%s%s to end warmup"), blinkcolor, getcommandkey("ready", "ready"), blinkcolor);
4102 s = sprintf(_("%sPress ^3%s%s once you are ready"), blinkcolor, getcommandkey("ready", "ready"), blinkcolor);
4107 s = _("^2Waiting for others to ready up to end warmup...");
4109 s = _("^2Waiting for others to ready up...");
4113 else if(warmup_stage && !intermission && !spectatee_status)
4115 s = sprintf(_("^2Press ^3%s^2 to end warmup"), getcommandkey("ready", "ready"));
4119 if(teamplay && !intermission && !spectatee_status && gametype != MAPINFO_TYPE_CA && teamnagger)
4121 float ts_min = 0, ts_max = 0;
4122 tm = teams.sort_next;
4125 for(; tm.sort_next; tm = tm.sort_next)
4127 if(!tm.team_size || tm.team == FL_SPECTATOR)
4129 if(!ts_min) ts_min = tm.team_size;
4130 else ts_min = min(ts_min, tm.team_size);
4131 if(!ts_max) ts_max = tm.team_size;
4132 else ts_max = max(ts_max, tm.team_size);
4134 if ((ts_max - ts_min) > 1)
4136 s = strcat(blinkcolor, _("Teamnumbers are unbalanced!"));
4137 tm = GetTeam(myteam, false);
4139 if (tm.team != FL_SPECTATOR)
4140 if (tm.team_size == ts_max)
4141 s = strcat(s, sprintf(_(" Press ^3%s%s to adjust"), getcommandkey("team menu", "menu_showteamselect"), blinkcolor));
4149 s = _("^7Press ^3ESC ^7to show HUD options.");
4151 s = _("^3Doubleclick ^7a panel for panel-specific options.");
4153 s = _("^3CTRL ^7to disable collision testing, ^3SHIFT ^7and");
4155 s = _("^3ALT ^7+ ^3ARROW KEYS ^7for fine adjustments.");
4160 // Physics panel (#15)
4162 vector acc_prevspeed;
4163 float acc_prevtime, acc_avg, top_speed, top_speed_time;
4164 void HUD_Physics(void)
4166 if(!autocvar__hud_configure)
4168 if(!autocvar_hud_panel_physics) return;
4169 if(spectatee_status == -1 && (autocvar_hud_panel_physics == 1 || autocvar_hud_panel_physics == 3)) return;
4170 if(autocvar_hud_panel_physics == 3 && !(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return;
4173 hud_configure_active_panel = HUD_PANEL_PHYSICS;
4175 HUD_Panel_UpdateCvars(physics);
4176 HUD_Panel_ApplyFadeAlpha();
4178 draw_beginBoldFont();
4180 HUD_Panel_DrawBg(1);
4181 if(panel_bg_padding)
4183 panel_pos += '1 1 0' * panel_bg_padding;
4184 panel_size -= '2 2 0' * panel_bg_padding;
4187 float acceleration_progressbar_scale = 0;
4188 if(autocvar_hud_panel_physics_progressbar && autocvar_hud_panel_physics_acceleration_progressbar_scale > 1)
4189 acceleration_progressbar_scale = autocvar_hud_panel_physics_acceleration_progressbar_scale;
4192 if (autocvar_hud_panel_physics_text_scale <= 0)
4195 text_scale = min(autocvar_hud_panel_physics_text_scale, 1);
4198 float speed, conversion_factor;
4201 switch(autocvar_hud_panel_physics_speed_unit)
4206 conversion_factor = 1.0;
4210 conversion_factor = 0.0254;
4214 conversion_factor = 0.0254 * 3.6;
4218 conversion_factor = 0.0254 * 3.6 * 0.6213711922;
4222 conversion_factor = 0.0254 * 1.943844492; // 1 m/s = 1.943844492 knots, because 1 knot = 1.852 km/h
4226 vector vel = (csqcplayer ? csqcplayer.velocity : pmove_vel);
4228 float max_speed = floor( autocvar_hud_panel_physics_speed_max * conversion_factor + 0.5 );
4229 if (autocvar__hud_configure)
4230 speed = floor( max_speed * 0.65 + 0.5 );
4231 else if(autocvar_hud_panel_physics_speed_vertical)
4232 speed = floor( vlen(vel) * conversion_factor + 0.5 );
4234 speed = floor( vlen(vel - vel_z * '0 0 1') * conversion_factor + 0.5 );
4236 //compute acceleration
4237 float acceleration, f;
4238 if (autocvar__hud_configure)
4239 acceleration = autocvar_hud_panel_physics_acceleration_max * 0.3;
4242 // 1 m/s = 0.0254 qu/s; 1 g = 9.80665 m/s^2
4243 f = time - acc_prevtime;
4244 if(autocvar_hud_panel_physics_acceleration_vertical)
4245 acceleration = (vlen(vel) - vlen(acc_prevspeed));
4247 acceleration = (vlen(vel - '0 0 1' * vel_z) - vlen(acc_prevspeed - '0 0 1' * acc_prevspeed_z));
4249 acceleration = acceleration * (1 / max(0.0001, f)) * (0.0254 / 9.80665);
4251 acc_prevspeed = vel;
4252 acc_prevtime = time;
4254 f = bound(0, f * 10, 1);
4255 acc_avg = acc_avg * (1 - f) + acceleration * f;
4259 float panel_ar = panel_size_x/panel_size_y;
4260 vector speed_offset = '0 0 0', acceleration_offset = '0 0 0';
4261 if (panel_ar >= 5 && !acceleration_progressbar_scale)
4263 panel_size_x *= 0.5;
4264 if (autocvar_hud_panel_physics_flip)
4265 speed_offset_x = panel_size_x;
4267 acceleration_offset_x = panel_size_x;
4271 panel_size_y *= 0.5;
4272 if (autocvar_hud_panel_physics_flip)
4273 speed_offset_y = panel_size_y;
4275 acceleration_offset_y = panel_size_y;
4277 float speed_baralign, acceleration_baralign;
4278 if (autocvar_hud_panel_physics_baralign == 1)
4279 acceleration_baralign = speed_baralign = 1;
4280 else if(autocvar_hud_panel_physics_baralign == 4)
4281 acceleration_baralign = speed_baralign = 2;
4282 else if (autocvar_hud_panel_physics_flip)
4284 acceleration_baralign = (autocvar_hud_panel_physics_baralign == 2);
4285 speed_baralign = (autocvar_hud_panel_physics_baralign == 3);
4289 speed_baralign = (autocvar_hud_panel_physics_baralign == 2);
4290 acceleration_baralign = (autocvar_hud_panel_physics_baralign == 3);
4292 if (autocvar_hud_panel_physics_acceleration_progressbar_mode == 0)
4293 acceleration_baralign = 3; //override hud_panel_physics_baralign value for acceleration
4297 if(autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 2)
4299 HUD_Panel_GetProgressBarColor(speed);
4300 HUD_Panel_DrawProgressBar(panel_pos + speed_offset, panel_size, "progressbar", speed/max_speed, 0, speed_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
4302 vector tmp_offset = '0 0 0', tmp_size = '0 0 0';
4303 if (autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 2)
4305 tmp_size_x = panel_size_x * 0.75;
4306 tmp_size_y = panel_size_y * text_scale;
4308 tmp_offset_x = panel_size_x - tmp_size_x;
4311 tmp_offset_y = (panel_size_y - tmp_size_y) / 2;
4312 drawstring_aspect(panel_pos + speed_offset + tmp_offset, ftos(speed), tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4318 tmp_offset_x = tmp_size_x;
4319 if (autocvar_hud_panel_physics_speed_unit_show)
4322 tmp_size_x = panel_size_x * (1 - 0.75);
4323 tmp_size_y = panel_size_y * 0.4 * text_scale;
4324 tmp_offset_y = (panel_size_y * 0.4 - tmp_size_y) / 2;
4325 drawstring_aspect(panel_pos + speed_offset + tmp_offset, unit, tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4329 //compute and draw top speed
4330 if (autocvar_hud_panel_physics_topspeed)
4331 if (autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 2)
4333 if (autocvar__hud_configure)
4335 top_speed = floor( max_speed * 0.75 + 0.5 );
4340 if (speed >= top_speed)
4343 top_speed_time = time;
4347 f = max(1, autocvar_hud_panel_physics_topspeed_time);
4348 // divide by f to make it start from 1
4349 f = cos( ((time - top_speed_time) / f) * PI/2 );
4351 else //hide top speed 0, it would be stupid
4356 //top speed progressbar peak
4357 if(speed < top_speed)
4358 if(autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 2)
4360 float peak_offset_x;
4361 vector peak_size = '0 0 0';
4362 if (speed_baralign == 0)
4363 peak_offset_x = min(top_speed, max_speed)/max_speed * panel_size_x;
4364 else if (speed_baralign == 1)
4365 peak_offset_x = (1 - min(top_speed, max_speed)/max_speed) * panel_size_x;
4366 else // if (speed_baralign == 2)
4367 peak_offset_x = min(top_speed, max_speed)/max_speed * panel_size_x * 0.5;
4368 //if speed is not 0 the speed progressbar already fetched the color
4370 HUD_Panel_GetProgressBarColor(speed);
4371 peak_size_x = floor(panel_size_x * 0.01 + 1.5);
4372 peak_size_y = panel_size_y;
4373 if (speed_baralign == 2) // draw two peaks, on both sides
4375 drawfill(panel_pos + speed_offset + eX * (0.5 * panel_size_x + peak_offset_x - peak_size_x), peak_size, progressbar_color, f * autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
4376 drawfill(panel_pos + speed_offset + eX * (0.5 * panel_size_x - peak_offset_x + peak_size_x), peak_size, progressbar_color, f * autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
4379 drawfill(panel_pos + speed_offset + eX * (peak_offset_x - peak_size_x), peak_size, progressbar_color, f * autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
4383 tmp_offset_y = panel_size_y * 0.4;
4384 tmp_size_x = panel_size_x * (1 - 0.75);
4385 tmp_size_y = (panel_size_y - tmp_offset_y) * text_scale;
4386 tmp_offset_y += (panel_size_y - tmp_offset_y - tmp_size_y) / 2;
4387 drawstring_aspect(panel_pos + speed_offset + tmp_offset, ftos(top_speed), tmp_size, '1 0 0', f * panel_fg_alpha, DRAWFLAG_NORMAL);
4395 if(autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 3)
4397 if (acceleration < 0)
4398 HUD_Panel_GetProgressBarColor(acceleration_neg);
4400 HUD_Panel_GetProgressBarColor(acceleration);
4402 f = acceleration/autocvar_hud_panel_physics_acceleration_max;
4403 if (autocvar_hud_panel_physics_acceleration_progressbar_nonlinear)
4406 if (acceleration_progressbar_scale) // allow progressbar to go out of panel bounds
4408 tmp_size = acceleration_progressbar_scale * panel_size_x * eX + panel_size_y * eY;
4410 if (acceleration_baralign == 1)
4411 tmp_offset_x = panel_size_x - tmp_size_x;
4412 else if (acceleration_baralign == 2 || acceleration_baralign == 3)
4413 tmp_offset_x = (panel_size_x - tmp_size_x) / 2;
4420 tmp_size = panel_size;
4421 tmp_offset = '0 0 0';
4424 HUD_Panel_DrawProgressBar(panel_pos + acceleration_offset + tmp_offset, tmp_size, "accelbar", f, 0, acceleration_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
4426 tmp_size_x = panel_size_x;
4427 tmp_size_y = panel_size_y * text_scale;
4429 tmp_offset_y = (panel_size_y - tmp_size_y) / 2;
4430 if (autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 3)
4431 drawstring_aspect(panel_pos + acceleration_offset + tmp_offset, strcat(ftos_decimals(acceleration, 2), "g"), tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4436 // CenterPrint (#16)
4438 #define CENTERPRINT_MAX_MSGS 10
4439 #define CENTERPRINT_MAX_ENTRIES 50
4440 #define CENTERPRINT_SPACING 0.7
4442 string centerprint_messages[CENTERPRINT_MAX_MSGS];
4443 float centerprint_msgID[CENTERPRINT_MAX_MSGS];
4444 float centerprint_time[CENTERPRINT_MAX_MSGS];
4445 float centerprint_expire_time[CENTERPRINT_MAX_MSGS];
4446 float centerprint_countdown_num[CENTERPRINT_MAX_MSGS];
4447 float centerprint_showing;
4449 void centerprint_generic(float new_id, string strMessage, float duration, float countdown_num)
4453 if(strMessage == "" && new_id == 0)
4456 // strip trailing newlines
4457 j = strlen(strMessage) - 1;
4458 while(substring(strMessage, j, 1) == "\n" && j >= 0)
4460 if (j < strlen(strMessage) - 1)
4461 strMessage = substring(strMessage, 0, j + 1);
4463 if(strMessage == "" && new_id == 0)
4466 // strip leading newlines
4468 while(substring(strMessage, j, 1) == "\n" && j < strlen(strMessage))
4471 strMessage = substring(strMessage, j, strlen(strMessage) - j);
4473 if(strMessage == "" && new_id == 0)
4476 if (!centerprint_showing)
4477 centerprint_showing = TRUE;
4479 for (i=0, j=cpm_index; i<CENTERPRINT_MAX_MSGS; ++i, ++j)
4481 if (j == CENTERPRINT_MAX_MSGS)
4483 if (new_id && new_id == centerprint_msgID[j])
4485 if (strMessage == "" && centerprint_messages[j] != "" && centerprint_countdown_num[j] == 0)
4487 // fade out the current msg (duration and countdown_num are ignored)
4488 centerprint_time[j] = min(5, autocvar_hud_panel_centerprint_fade_out);
4489 if (centerprint_expire_time[j] > time + min(5, autocvar_hud_panel_centerprint_fade_out) || centerprint_expire_time[j] < time)
4490 centerprint_expire_time[j] = time + min(5, autocvar_hud_panel_centerprint_fade_out);
4493 break; // found a msg with the same id, at position j
4497 if (i == CENTERPRINT_MAX_MSGS)
4499 // a msg with the same id was not found, add the msg at the next position
4501 if (cpm_index == -1)
4502 cpm_index = CENTERPRINT_MAX_MSGS - 1;
4505 if(centerprint_messages[j])
4506 strunzone(centerprint_messages[j]);
4507 centerprint_messages[j] = strzone(strMessage);
4508 centerprint_msgID[j] = new_id;
4510 centerprint_time[j] = -1;
4514 duration = max(1, autocvar_hud_panel_centerprint_time);
4515 centerprint_time[j] = duration;
4516 centerprint_expire_time[j] = time + duration;
4518 centerprint_countdown_num[j] = countdown_num;
4521 void centerprint_hud(string strMessage)
4523 centerprint_generic(0, strMessage, autocvar_hud_panel_centerprint_time, 0);
4526 void reset_centerprint_messages(void)
4529 for (i=0; i<CENTERPRINT_MAX_MSGS; ++i)
4531 centerprint_expire_time[i] = 0;
4532 centerprint_time[i] = 1;
4533 centerprint_msgID[i] = 0;
4534 if(centerprint_messages[i])
4535 strunzone(centerprint_messages[i]);
4536 centerprint_messages[i] = string_null;
4539 float hud_configure_cp_generation_time;
4540 void HUD_CenterPrint (void)
4542 if(!autocvar__hud_configure)
4544 if(!autocvar_hud_panel_centerprint) return;
4546 if (hud_configure_prev && hud_configure_prev != -1)
4547 reset_centerprint_messages();
4551 hud_configure_active_panel = HUD_PANEL_CENTERPRINT;
4553 if (!hud_configure_prev)
4554 reset_centerprint_messages();
4555 if (time > hud_configure_cp_generation_time)
4560 centerprint_generic(floor(r*1000), strcat(sprintf("^3Countdown message at time %s", seconds_tostring(time)), ", seconds left: %d"), 1, 10);
4562 centerprint_generic(0, sprintf("^1Multiline message at time %s that\n^1lasts longer than normal", seconds_tostring(time)), 20, 0);
4564 centerprint_hud(sprintf("Message at time %s", seconds_tostring(time)));
4565 hud_configure_cp_generation_time = time + 1 + random()*4;
4569 HUD_Panel_UpdateCvars(centerprint);
4571 // this panel doesn't fade when showing the scoreboard
4572 if(autocvar__menu_alpha)
4573 HUD_Panel_ApplyFadeAlpha();
4575 if(scoreboard_fade_alpha)
4577 // move the panel below the scoreboard
4578 if (scoreboard_bottom >= 0.96 * vid_conheight)
4582 target_pos = eY * scoreboard_bottom + eX * 0.5 * (vid_conwidth - panel_size_x);
4584 if(target_pos_y > panel_pos_y)
4586 panel_pos = panel_pos + (target_pos - panel_pos) * sqrt(scoreboard_fade_alpha);
4587 panel_size_y = min(panel_size_y, vid_conheight - scoreboard_bottom);
4591 HUD_Panel_DrawBg(1);
4593 if (!centerprint_showing)
4596 if(panel_bg_padding)
4598 panel_pos += '1 1 0' * panel_bg_padding;
4599 panel_size -= '2 2 0' * panel_bg_padding;
4602 float entries, height;
4604 // entries = bound(1, floor(CENTERPRINT_MAX_ENTRIES * 4 * panel_size_y/panel_size_x), CENTERPRINT_MAX_ENTRIES);
4605 // height = panel_size_y/entries;
4606 // fontsize = '1 1 0' * height;
4607 height = vid_conheight/50 * autocvar_hud_panel_centerprint_fontscale;
4608 fontsize = '1 1 0' * height;
4609 entries = bound(1, floor(panel_size_y/height), CENTERPRINT_MAX_ENTRIES);
4612 float a, sz, align, current_msg_pos_y = 0, msg_size;
4616 n = -1; // if no msg will be displayed, n stays -1
4619 if (autocvar_hud_panel_centerprint_flip)
4620 pos_y += panel_size_y;
4621 align = bound(0, autocvar_hud_panel_centerprint_align, 1);
4622 for (i=0, j=cpm_index; i<CENTERPRINT_MAX_MSGS; ++i, ++j)
4624 if (j == CENTERPRINT_MAX_MSGS)
4626 if (centerprint_expire_time[j] <= time)
4628 if (centerprint_countdown_num[j] && centerprint_time[j] > 0)
4630 centerprint_countdown_num[j] = centerprint_countdown_num[j] - 1;
4631 if (centerprint_countdown_num[j] == 0)
4633 centerprint_expire_time[j] = centerprint_expire_time[j] + centerprint_time[j];
4639 // fade the centerprint_hud in/out
4640 if (centerprint_time[j] < 0 || centerprint_expire_time[j] - autocvar_hud_panel_centerprint_fade_out > time)
4641 a = bound(0, (time - (centerprint_expire_time[j] - centerprint_time[j])) / max(0.0001, autocvar_hud_panel_centerprint_fade_in), 1);
4642 else if (centerprint_expire_time[j] > time)
4643 a = (centerprint_expire_time[j] - time) / max(0.0001, autocvar_hud_panel_centerprint_fade_out);
4647 // set the size from fading in/out before subsequent fading
4648 sz = autocvar_hud_panel_centerprint_fade_minfontsize + a * (1 - autocvar_hud_panel_centerprint_fade_minfontsize);
4650 // also fade it based on positioning
4651 if(autocvar_hud_panel_centerprint_fade_subsequent)
4653 a = a * bound(autocvar_hud_panel_centerprint_fade_subsequent_passone_minalpha, (1 - (i / max(1, autocvar_hud_panel_centerprint_fade_subsequent_passone))), 1); // pass one: all messages after the first have half theAlpha
4654 a = a * bound(autocvar_hud_panel_centerprint_fade_subsequent_passtwo_minalpha, (1 - (i / max(1, autocvar_hud_panel_centerprint_fade_subsequent_passtwo))), 1); // pass two: after that, gradually lower theAlpha even more for each message
4657 // finally set the size based on the new theAlpha from subsequent fading
4658 sz = sz * (autocvar_hud_panel_centerprint_fade_subsequent_minfontsize + a * (1 - autocvar_hud_panel_centerprint_fade_subsequent_minfontsize));
4659 drawfontscale = sz * '1 1 0';
4661 if (centerprint_countdown_num[j])
4662 n = tokenizebyseparator(sprintf(centerprint_messages[j], centerprint_countdown_num[j]), "\n");
4664 n = tokenizebyseparator(centerprint_messages[j], "\n");
4666 if (autocvar_hud_panel_centerprint_flip)
4668 // check if the message can be entirely shown
4669 for(k = 0; k < n; ++k)
4671 getWrappedLine_remaining = argv(k);
4672 while(getWrappedLine_remaining)
4674 ts = getWrappedLine(panel_size_x * sz, fontsize, stringwidth_colors);
4676 pos_y -= fontsize_y;
4678 pos_y -= fontsize_y * CENTERPRINT_SPACING/2;
4681 current_msg_pos_y = pos_y; // save starting pos (first line) of the current message
4685 for(k = 0; k < n; ++k)
4687 getWrappedLine_remaining = argv(k);
4688 while(getWrappedLine_remaining)
4690 ts = getWrappedLine(panel_size_x * sz, fontsize, stringwidth_colors);
4694 pos_x = panel_pos_x + (panel_size_x - stringwidth(ts, TRUE, fontsize)) * align;
4695 drawcolorcodedstring(pos + eY * 0.5 * (1 - sz) * fontsize_y, ts, fontsize, a * panel_fg_alpha, DRAWFLAG_NORMAL);
4696 pos_y += fontsize_y;
4699 pos_y += fontsize_y * CENTERPRINT_SPACING/2;
4702 msg_size = pos_y - msg_size;
4703 if (autocvar_hud_panel_centerprint_flip)
4705 pos_y = current_msg_pos_y - CENTERPRINT_SPACING * fontsize_y;
4706 if (a < 1 && centerprint_msgID[j] == 0) // messages with id can be replaced just after they are faded out, so never move over them the next messages
4707 pos_y += (msg_size + CENTERPRINT_SPACING * fontsize_y) * (1 - sqrt(sz));
4709 if (pos_y < panel_pos_y) // check if the next message can be shown
4711 drawfontscale = '1 1 0';
4717 pos_y += CENTERPRINT_SPACING * fontsize_y;
4718 if (a < 1 && centerprint_msgID[j] == 0) // messages with id can be replaced just after they are faded out, so never move over them the next messages
4719 pos_y -= (msg_size + CENTERPRINT_SPACING * fontsize_y) * (1 - sqrt(sz));
4721 if(pos_y > panel_pos_y + panel_size_y - fontsize_y) // check if the next message can be shown
4723 drawfontscale = '1 1 0';
4728 drawfontscale = '1 1 0';
4731 centerprint_showing = FALSE;
4732 reset_centerprint_messages();
4742 void HUD_Reset (void)
4744 // reset gametype specific icons
4745 if(gametype == MAPINFO_TYPE_KEYHUNT)
4747 else if(gametype == MAPINFO_TYPE_CTF)
4748 HUD_Mod_CTF_Reset();
4751 #define HUD_DrawPanel(id)\
4753 case (HUD_PANEL_RADAR):\
4754 HUD_Radar(); break;\
4755 case (HUD_PANEL_WEAPONS):\
4756 HUD_Weapons(); break;\
4757 case (HUD_PANEL_AMMO):\
4759 case (HUD_PANEL_POWERUPS):\
4760 HUD_Powerups(); break;\
4761 case (HUD_PANEL_HEALTHARMOR):\
4762 HUD_HealthArmor(); break;\
4763 case (HUD_PANEL_NOTIFY):\
4764 HUD_Notify(); break;\
4765 case (HUD_PANEL_TIMER):\
4766 HUD_Timer(); break;\
4767 case (HUD_PANEL_SCORE):\
4768 HUD_Score(); break;\
4769 case (HUD_PANEL_RACETIMER):\
4770 HUD_RaceTimer(); break;\
4771 case (HUD_PANEL_VOTE):\
4772 HUD_VoteWindow(); break;\
4773 case (HUD_PANEL_MODICONS):\
4774 HUD_ModIcons(); break;\
4775 case (HUD_PANEL_PRESSEDKEYS):\
4776 HUD_DrawPressedKeys(); break;\
4777 case (HUD_PANEL_CHAT):\
4779 case (HUD_PANEL_ENGINEINFO):\
4780 HUD_EngineInfo(); break;\
4781 case (HUD_PANEL_INFOMESSAGES):\
4782 HUD_InfoMessages(); break;\
4783 case (HUD_PANEL_PHYSICS):\
4784 HUD_Physics(); break;\
4785 case (HUD_PANEL_CENTERPRINT):\
4786 HUD_CenterPrint(); break;\
4787 } ENDS_WITH_CURLY_BRACE
4789 void HUD_Main (void)
4792 // global hud theAlpha fade
4793 if(menu_enabled == 1)
4796 hud_fade_alpha = (1 - autocvar__menu_alpha);
4798 if(scoreboard_fade_alpha)
4799 hud_fade_alpha = (1 - scoreboard_fade_alpha);
4801 if(autocvar__hud_configure)
4803 HUD_Configure_Exit_Force();
4805 if(intermission == 2) // no hud during mapvote
4807 if (autocvar__hud_configure)
4808 HUD_Configure_Exit_Force();
4811 else if(autocvar__menu_alpha == 0 && scoreboard_fade_alpha == 0)
4814 // panels that we want to be active together with the scoreboard
4815 // they must call HUD_Panel_ApplyFadeAlpha(); only when showing the menu
4816 if(scoreboard_fade_alpha == 1)
4822 if(!autocvar__hud_configure && !hud_fade_alpha)
4826 if (hud_skin_path != autocvar_hud_skin)
4829 strunzone(hud_skin_path);
4830 hud_skin_path = strzone(strcat("gfx/hud/", autocvar_hud_skin));
4833 // HUD configure visible grid
4834 if(autocvar__hud_configure && autocvar_hud_configure_grid && autocvar_hud_configure_grid_alpha)
4836 hud_configure_gridSize_x = bound(0.005, cvar("hud_configure_grid_xsize"), 0.2);
4837 hud_configure_gridSize_y = bound(0.005, cvar("hud_configure_grid_ysize"), 0.2);
4838 hud_configure_realGridSize_x = hud_configure_gridSize_x * vid_conwidth;
4839 hud_configure_realGridSize_y = hud_configure_gridSize_y * vid_conheight;
4842 s = eX + eY * vid_conheight;
4843 for(i = 1; i < 1/hud_configure_gridSize_x; ++i)
4844 drawfill(eX * i * hud_configure_realGridSize_x, s, '0.5 0.5 0.5', autocvar_hud_configure_grid_alpha, DRAWFLAG_NORMAL);
4846 s = eY + eX * vid_conwidth;
4847 for(i = 1; i < 1/hud_configure_gridSize_y; ++i)
4848 drawfill(eY * i * hud_configure_realGridSize_y, s, '0.5 0.5 0.5', autocvar_hud_configure_grid_alpha, DRAWFLAG_NORMAL);
4851 #ifdef COMPAT_XON050_ENGINE
4852 current_player = (spectatee_status > 0) ? spectatee_status : player_localentnum;
4854 current_player = player_localentnum;
4858 if(autocvar_hud_dock != "" && autocvar_hud_dock != "0")
4862 float hud_dock_color_team = autocvar_hud_dock_color_team;
4863 if((teamplay) && hud_dock_color_team) {
4864 f = stof(getplayerkeyvalue(current_player - 1, "colors"));
4865 color = colormapPaletteColor(mod(f, 16), 1) * hud_dock_color_team;
4867 else if(autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && hud_dock_color_team) {
4868 color = '1 0 0' * hud_dock_color_team;
4872 string hud_dock_color = autocvar_hud_dock_color;
4873 if(hud_dock_color == "shirt") {
4874 f = stof(getplayerkeyvalue(current_player - 1, "colors"));
4875 color = colormapPaletteColor(floor(f / 16), 0);
4877 else if(hud_dock_color == "pants") {
4878 f = stof(getplayerkeyvalue(current_player - 1, "colors"));
4879 color = colormapPaletteColor(mod(f, 16), 1);
4882 color = stov(hud_dock_color);
4886 pic = strcat(hud_skin_path, "/", autocvar_hud_dock);
4887 if(precache_pic(pic) == "") {
4888 pic = strcat(hud_skin_path, "/dock_medium");
4889 if(precache_pic(pic) == "") {
4890 pic = "gfx/hud/default/dock_medium";
4893 drawpic('0 0 0', pic, eX * vid_conwidth + eY * vid_conheight, color, autocvar_hud_dock_alpha * hud_fade_alpha, DRAWFLAG_NORMAL); // no aspect ratio forcing on dock...
4896 // cache the panel order into the panel_order array
4897 if(autocvar__hud_panelorder != hud_panelorder_prev) {
4898 for(i = 0; i < HUD_PANEL_NUM; ++i)
4899 panel_order[i] = -1;
4901 float p_num, warning = false;
4902 float argc = tokenize_console(autocvar__hud_panelorder);
4903 if (argc > HUD_PANEL_NUM)
4905 //first detect wrong/missing panel numbers
4906 for(i = 0; i < HUD_PANEL_NUM; ++i) {
4907 p_num = stof(argv(i));
4908 if (p_num >= 0 && p_num < HUD_PANEL_NUM) { //correct panel number?
4909 if (panel_order[p_num] == -1) //found for the first time?
4910 s = strcat(s, ftos(p_num), " ");
4911 panel_order[p_num] = 1; //mark as found
4916 for(i = 0; i < HUD_PANEL_NUM; ++i) {
4917 if (panel_order[i] == -1) {
4919 s = strcat(s, ftos(i), " "); //add missing panel number
4923 print(_("Automatically fixed wrong/missing panel numbers in _hud_panelorder\n"));
4925 cvar_set("_hud_panelorder", s);
4926 if(hud_panelorder_prev)
4927 strunzone(hud_panelorder_prev);
4928 hud_panelorder_prev = strzone(s);
4930 //now properly set panel_order
4931 tokenize_console(s);
4932 for(i = 0; i < HUD_PANEL_NUM; ++i) {
4933 panel_order[i] = stof(argv(i));
4937 hud_draw_maximized = 0;
4938 // draw panels in order specified by panel_order array
4939 for(i = HUD_PANEL_NUM - 1; i >= 0; --i)
4940 HUD_DrawPanel(panel_order[i]);
4942 hud_draw_maximized = 1; // panels that may be maximized must check this var
4943 // draw maximized panels on top
4944 if(hud_panel_radar_maximized)
4946 if(autocvar__con_chat_maximized)
4949 if(autocvar__hud_configure)
4953 HUD_Panel_UpdatePosSizeForId(tab_panel)
4954 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .2, DRAWFLAG_NORMAL);
4956 if(highlightedPanel != -1)
4958 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
4959 HUD_Panel_HlBorder(panel_bg_border + 1.5 * hlBorderSize, '0 0.5 1', 0.25 * (1 - autocvar__menu_alpha));
4961 if (!hud_configure_prev)
4963 if(autocvar_hud_cursormode) { setcursormode(1); }
4967 else if (hud_configure_prev && autocvar_hud_cursormode)
4970 hud_configure_prev = autocvar__hud_configure;
4972 if (!autocvar__hud_configure) // hud config mode disabled, enable normal theAlpha stuff again