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 alpha, float flag)
147 position_x -= 2 / 3 * strlen(text) * scale_x;
148 drawstring(position, text, scale, rgb, alpha, flag);
151 void drawstringcenter(vector position, string text, vector scale, vector rgb, float alpha, float flag)
153 position_x = 0.5 * (vid_conwidth - 0.6025 * strlen(text) * scale_x);
154 drawstring(position, text, scale, rgb, alpha, 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));
219 cpname = _("Start line");
221 cpname = _("Finish line");
223 cpname = sprintf(_("Intermediate %d"), cp);
225 cpname = _("Finish line");
228 return strcat(col, cpname);
229 else if(hisname == "")
230 return strcat(col, sprintf(_("%s (%s)"), cpname, timestr));
232 return strcat(col, sprintf(_("%s (%s %s)"), cpname, timestr, strcat(hisname, col, lapstr)));
235 // Check if the given name already exist in race rankings? In that case, where? (otherwise return 0)
236 float race_CheckName(string net_name) {
238 for (i=RANKINGS_CNT-1;i>=0;--i)
239 if(grecordholder[i] == net_name)
250 // draw the background/borders
251 #define HUD_Panel_DrawBg(alpha)\
253 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 * alpha, '1 1 0' * (panel_bg_border/BORDER_MULTIPLIER))
255 //basically the same code of draw_ButtonPicture and draw_VertButtonPicture for the menu
256 void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, float length_ratio, float vertical, float baralign, vector theColor, float theAlpha, float drawflag)
258 if(!length_ratio || !theAlpha)
264 if(length_ratio < -1)
267 else if(length_ratio < 0)
271 vector width, height;
273 pic = strcat(hud_skin_path, "/", pic, "_vertical");
274 if(precache_pic(pic) == "") {
275 pic = "gfx/hud/default/progressbar_vertical";
278 if (baralign == 1) // bottom align
279 theOrigin_y += (1 - length_ratio) * theSize_y;
280 else if (baralign == 2) // center align
281 theOrigin_y += 0.5 * (1 - length_ratio) * theSize_y;
282 else if (baralign == 3) // center align, positive values down, negative up
285 if (length_ratio > 0)
286 theOrigin_y += theSize_y;
289 theOrigin_y += (1 + length_ratio) * theSize_y;
290 length_ratio = -length_ratio;
293 theSize_y *= length_ratio;
296 width = eX * theSize_x;
297 height = eY * theSize_y;
298 if(theSize_y <= theSize_x * 2)
300 // button not high enough
301 // draw just upper and lower part then
302 square = eY * theSize_y * 0.5;
303 bH = eY * (0.25 * theSize_y / (theSize_x * 2));
304 drawsubpic(theOrigin, square + width, pic, '0 0 0', eX + bH, theColor, theAlpha, drawflag);
305 drawsubpic(theOrigin + square, square + width, pic, eY - bH, eX + bH, theColor, theAlpha, drawflag);
309 square = eY * theSize_x;
310 drawsubpic(theOrigin, width + square, pic, '0 0 0', '1 0.25 0', theColor, theAlpha, drawflag);
311 drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0 0.25 0', '1 0.5 0', theColor, theAlpha, drawflag);
312 drawsubpic(theOrigin + height - square, width + square, pic, '0 0.75 0', '1 0.25 0', theColor, theAlpha, drawflag);
315 pic = strcat(hud_skin_path, "/", pic);
316 if(precache_pic(pic) == "") {
317 pic = "gfx/hud/default/progressbar";
320 if (baralign == 1) // right align
321 theOrigin_x += (1 - length_ratio) * theSize_x;
322 else if (baralign == 2) // center align
323 theOrigin_x += 0.5 * (1 - length_ratio) * theSize_x;
324 else if (baralign == 3) // center align, positive values on the right, negative on the left
327 if (length_ratio > 0)
328 theOrigin_x += theSize_x;
331 theOrigin_x += (1 + length_ratio) * theSize_x;
332 length_ratio = -length_ratio;
335 theSize_x *= length_ratio;
338 width = eX * theSize_x;
339 height = eY * theSize_y;
340 if(theSize_x <= theSize_y * 2)
342 // button not wide enough
343 // draw just left and right part then
344 square = eX * theSize_x * 0.5;
345 bW = eX * (0.25 * theSize_x / (theSize_y * 2));
346 drawsubpic(theOrigin, square + height, pic, '0 0 0', eY + bW, theColor, theAlpha, drawflag);
347 drawsubpic(theOrigin + square, square + height, pic, eX - bW, eY + bW, theColor, theAlpha, drawflag);
351 square = eX * theSize_y;
352 drawsubpic(theOrigin, height + square, pic, '0 0 0', '0.25 1 0', theColor, theAlpha, drawflag);
353 drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0.25 0 0', '0.5 1 0', theColor, theAlpha, drawflag);
354 drawsubpic(theOrigin + width - square, height + square, pic, '0.75 0 0', '0.25 1 0', theColor, theAlpha, drawflag);
359 void HUD_Panel_DrawHighlight(vector pos, vector mySize, vector color, float alpha, float drawflag)
365 pic = strcat(hud_skin_path, "/num_leading");
366 if(precache_pic(pic) == "") {
367 pic = "gfx/hud/default/num_leading";
370 drawsubpic(pos, eX * min(mySize_x * 0.5, mySize_y) + eY * mySize_y, pic, '0 0 0', '0.25 1 0', color, alpha, drawflag);
371 if(mySize_x/mySize_y > 2)
372 drawsubpic(pos + eX * mySize_y, eX * (mySize_x - 2 * mySize_y) + eY * mySize_y, pic, '0.25 0 0', '0.5 1 0', color, alpha, drawflag);
373 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, alpha, drawflag);
378 entity weaponorder[WEP_MAXCOUNT];
379 void weaponorder_swap(float i, float j, entity pass)
383 weaponorder[i] = weaponorder[j];
387 string weaponorder_cmp_str;
388 float weaponorder_cmp(float i, float j, entity pass)
391 ai = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[i].weapon), 0);
392 aj = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[j].weapon), 0);
393 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)
396 float GetAmmoStat(float i)
400 case 0: return STAT_SHELLS;
401 case 1: return STAT_NAILS;
402 case 2: return STAT_ROCKETS;
403 case 3: return STAT_CELLS;
404 case 4: return STAT_FUEL;
409 float GetAmmoTypeForWep(float i)
413 case WEP_SHOTGUN: return 0;
414 case WEP_UZI: return 1;
415 case WEP_GRENADE_LAUNCHER: return 2;
416 case WEP_MINE_LAYER: return 2;
417 case WEP_ELECTRO: return 3;
418 case WEP_CRYLINK: return 3;
419 case WEP_HLAC: return 3;
420 case WEP_MINSTANEX: return 3;
421 case WEP_NEX: return 3;
422 case WEP_RIFLE: return 1;
423 case WEP_HAGAR: return 2;
424 case WEP_ROCKET_LAUNCHER: return 2;
425 case WEP_SEEKER: return 2;
426 case WEP_FIREBALL: return 4;
427 case WEP_HOOK: return 3;
432 void HUD_Weapons(void)
434 float i, f, screen_ar;
435 float center_x, center_y;
436 if(hud != HUD_NORMAL) return;
437 if(!autocvar__hud_configure)
439 if(!autocvar_hud_panel_weapons) return;
440 if(spectatee_status == -1) return;
443 hud_configure_active_panel = HUD_PANEL_WEAPONS;
445 float timeout = autocvar_hud_panel_weapons_timeout;
446 float timeout_effect_length, timein_effect_length;
447 if (autocvar_hud_panel_weapons_timeout_effect == 0)
449 timeout_effect_length = 0;
450 timein_effect_length = 0;
454 timeout_effect_length = 0.75;
455 timein_effect_length = 0.375;
458 if (timeout && time >= weapontime + timeout + timeout_effect_length && !autocvar__hud_configure)
460 weaponprevtime = time;
464 HUD_Panel_UpdateCvars(weapons);
465 HUD_Panel_ApplyFadeAlpha();
467 // TODO make this configurable
468 if(weaponorder_bypriority != autocvar_cl_weaponpriority || !weaponorder[0])
471 if(weaponorder_bypriority)
472 strunzone(weaponorder_bypriority);
473 if(weaponorder_byimpulse)
474 strunzone(weaponorder_byimpulse);
476 weaponorder_bypriority = strzone(autocvar_cl_weaponpriority);
477 weaponorder_byimpulse = strzone(W_FixWeaponOrder_BuildImpulseList(W_FixWeaponOrder_ForceComplete(W_NumberWeaponOrder(weaponorder_bypriority))));
478 weaponorder_cmp_str = strcat(" ", weaponorder_byimpulse, " ");
481 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
483 self = get_weaponinfo(i);
484 if(self.impulse >= 0)
486 weaponorder[weapon_cnt] = self;
490 for(i = weapon_cnt; i < WEP_MAXCOUNT; ++i)
491 weaponorder[i] = NULL;
492 heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, world);
494 weaponorder_cmp_str = string_null;
497 float when, fadetime;
498 when = autocvar_hud_panel_weapons_complainbubble_time;
499 fadetime = autocvar_hud_panel_weapons_complainbubble_fadetime;
500 float weapons_st = getstati(STAT_WEAPONS);
502 if (autocvar_hud_panel_weapons_onlyowned)
504 if(autocvar__hud_configure && menu_enabled != 2)
505 HUD_Panel_DrawBg(1); // also draw the bg of the entire panel
507 vector old_panel_size;
508 for(i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
510 if(weapons_st & weaponorder[i].weapons)
513 if(!autocvar__hud_configure && (autocvar_hud_panel_weapons_complainbubble && time - complain_weapon_time < when + fadetime))// && complain_weapon >= 0
515 if (weapon_count == 0)
517 // reduce size of the panel
518 if (panel_size_y > panel_size_x)
520 old_panel_size_y = panel_size_y;
521 panel_size_y *= weapon_count / WEP_COUNT;
522 panel_pos_y += (old_panel_size_y - panel_size_y) / 2;
526 old_panel_size_x = panel_size_x;
527 panel_size_x *= weapon_count / WEP_COUNT;
528 panel_pos_x += (old_panel_size_x - panel_size_x) / 2;
532 weapon_count = WEP_COUNT;
534 if (timeout && time >= weapontime + timeout && !autocvar__hud_configure)
536 f = (time - (weapontime + timeout)) / timeout_effect_length;
537 if (autocvar_hud_panel_weapons_timeout_effect == 1 || autocvar_hud_panel_weapons_timeout_effect == 3)
539 panel_bg_alpha *= (1 - f);
540 panel_fg_alpha *= (1 - f);
542 if (autocvar_hud_panel_weapons_timeout_effect == 2 || autocvar_hud_panel_weapons_timeout_effect == 3)
544 f *= f; // for a cooler movement
545 center_x = panel_pos_x + panel_size_x/2;
546 center_y = panel_pos_y + panel_size_y/2;
547 screen_ar = vid_conwidth/vid_conheight;
548 if (center_x/center_y < screen_ar) //bottom left
550 if ((vid_conwidth - center_x)/center_y < screen_ar) //bottom
551 panel_pos_y += f * (vid_conheight - panel_pos_y);
553 panel_pos_x -= f * (panel_pos_x + panel_size_x);
557 if ((vid_conwidth - center_x)/center_y < screen_ar) //right
558 panel_pos_x += f * (vid_conwidth - panel_pos_x);
560 panel_pos_y -= f * (panel_pos_y + panel_size_y);
563 weaponprevtime = time - (1 - f) * timein_effect_length;
565 else if (timeout && time < weaponprevtime + timein_effect_length && !autocvar__hud_configure)
567 f = (time - weaponprevtime) / timein_effect_length;
568 if (autocvar_hud_panel_weapons_timeout_effect == 1 || autocvar_hud_panel_weapons_timeout_effect == 3)
570 panel_bg_alpha *= (f);
571 panel_fg_alpha *= (f);
573 if (autocvar_hud_panel_weapons_timeout_effect == 2 || autocvar_hud_panel_weapons_timeout_effect == 3)
575 f *= f; // for a cooler movement
577 center_x = panel_pos_x + panel_size_x/2;
578 center_y = panel_pos_y + panel_size_y/2;
579 screen_ar = vid_conwidth/vid_conheight;
580 if (center_x/center_y < screen_ar) //bottom left
582 if ((vid_conwidth - center_x)/center_y < screen_ar) //bottom
583 panel_pos_y += f * (vid_conheight - panel_pos_y);
585 panel_pos_x -= f * (panel_pos_x + panel_size_x);
589 if ((vid_conwidth - center_x)/center_y < screen_ar) //right
590 panel_pos_x += f * (vid_conwidth - panel_pos_x);
592 panel_pos_y -= f * (panel_pos_y + panel_size_y);
600 panel_pos += '1 1 0' * panel_bg_padding;
601 panel_size -= '2 2 0' * panel_bg_padding;
604 float weapid, wpnalpha;
606 if(autocvar_hud_panel_weapons_fade)
608 wpnalpha = 3.2 - 2 * (time - weapontime);
609 wpnalpha = bound(0.7, wpnalpha, 1) * panel_fg_alpha;
612 wpnalpha = panel_fg_alpha;
615 float aspect = autocvar_hud_panel_weapons_aspect;
616 rows = panel_size_y/panel_size_x;
617 rows = bound(1, floor((sqrt(4 * aspect * rows * weapon_count + rows * rows) + rows + 0.5) / 2), weapon_count);
619 columns = ceil(weapon_count/rows);
622 float a, type, fullammo;
630 wpnsize = eX * panel_size_x*(1/columns) + eY * panel_size_y*(1/rows);
631 float barsize_x, barsize_y, baroffset_x, baroffset_y;
632 if (autocvar_hud_panel_weapons_ammo)
634 ammo_color = stov(autocvar_hud_panel_weapons_ammo_color);
635 ammo_alpha = panel_fg_alpha * autocvar_hud_panel_weapons_ammo_alpha;
638 if(wpnsize_x/wpnsize_y > aspect)
640 barsize_x = aspect * wpnsize_y;
641 barsize_y = wpnsize_y;
642 baroffset_x = (wpnsize_x - barsize_x) / 2;
646 barsize_y = 1/aspect * wpnsize_x;
647 barsize_x = wpnsize_x;
648 baroffset_y = (wpnsize_y - barsize_y) / 2;
654 if(autocvar_hud_panel_weapons_accuracy && acc_levels)
656 show_accuracy = true;
657 if (acc_col_x[0] == -1)
658 for (i = 0; i < acc_levels; ++i)
659 acc_col[i] = stov(cvar_string(strcat("accuracy_color", ftos(i))));
662 for(i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
664 self = weaponorder[i];
665 if (!self || self.impulse < 0)
667 if (autocvar_hud_panel_weapons_onlyowned)
668 if (!((weapons_st & self.weapons) || (self.weapon == complain_weapon && time - complain_weapon_time < when + fadetime && autocvar_hud_panel_weapons_complainbubble)))
669 //if (!autocvar__hud_configure)
671 wpnpos = panel_pos + eX * column * wpnsize_x + eY * row * wpnsize_y;
673 weapid = self.impulse;
675 // draw background behind currently selected weapon
676 if(self.weapon == activeweapon)
677 drawpic_aspect_skin(wpnpos, "weapon_current_bg", wpnsize, '1 1 1', wpnalpha, DRAWFLAG_NORMAL);
679 // draw the weapon accuracy
682 weapon_stats = weapon_accuracy[self.weapon-WEP_FIRST];
683 if(weapon_stats >= 0)
685 // find the max level lower than weapon_stats
688 while ( j && weapon_stats < acc_lev[j] )
691 // inject color j+1 in color j, how much depending on how much weapon_stats is higher than level j
693 factor = (weapon_stats - acc_lev[j]) / (acc_lev[j+1] - acc_lev[j]);
695 color = color + factor * (acc_col[j+1] - color);
697 drawpic_aspect_skin(wpnpos, "weapon_accuracy", wpnsize, color, panel_fg_alpha, DRAWFLAG_NORMAL);
701 // draw the weapon icon
702 if(weapons_st & self.weapons)
704 drawpic_aspect_skin(wpnpos, strcat("weapon", self.netname), wpnsize, '1 1 1', wpnalpha, DRAWFLAG_NORMAL);
706 if(autocvar_hud_panel_weapons_label == 1) // weapon number
707 drawstring(wpnpos, ftos(weapid), '1 1 0' * 0.5 * wpnsize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
708 else if(autocvar_hud_panel_weapons_label == 2) // bind
709 drawstring(wpnpos, getcommandkey(ftos(weapid), strcat("impulse ", ftos(weapid))), '1 1 0' * 0.5 * wpnsize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
711 // draw ammo status bar
712 if(autocvar_hud_panel_weapons_ammo && self.weapon != WEP_TUBA && self.weapon != WEP_LASER && self.weapon != WEP_PORTO)
715 type = GetAmmoTypeForWep(self.weapon);
717 a = getstati(GetAmmoStat(type)); // how much ammo do we have?
722 case 0: fullammo = autocvar_hud_panel_weapons_ammo_full_shells; break;
723 case 1: fullammo = autocvar_hud_panel_weapons_ammo_full_nails; break;
724 case 2: fullammo = autocvar_hud_panel_weapons_ammo_full_rockets; break;
725 case 3: fullammo = autocvar_hud_panel_weapons_ammo_full_cells; break;
726 case 4: fullammo = autocvar_hud_panel_weapons_ammo_full_fuel; break;
727 default: fullammo = 60;
731 wpnpos_x + baroffset_x,
732 wpnpos_y + baroffset_y,
733 barsize_x * bound(0, a/fullammo, 1),
735 drawpic_aspect_skin(wpnpos, "weapon_ammo", wpnsize, ammo_color, ammo_alpha, DRAWFLAG_NORMAL);
741 // draw a "ghost weapon icon" if you don't have the weapon
744 drawpic_aspect_skin(wpnpos, strcat("weapon", self.netname), wpnsize, '0 0 0', panel_fg_alpha * 0.5, DRAWFLAG_NORMAL);
747 // draw the complain message
748 if(time - complain_weapon_time < when + fadetime && self.weapon == complain_weapon && autocvar_hud_panel_weapons_complainbubble)
752 if(complain_weapon_time + when > time)
755 a = bound(0, (complain_weapon_time + when + fadetime - time) / fadetime, 1);
759 if(complain_weapon_time + when > time)
766 if(complain_weapon_type == 0) {
767 s = _("Out of ammo");
768 color = stov(autocvar_hud_panel_weapons_complainbubble_color_outofammo);
770 else if(complain_weapon_type == 1) {
772 color = stov(autocvar_hud_panel_weapons_complainbubble_color_donthave);
775 s = _("Unavailable");
776 color = stov(autocvar_hud_panel_weapons_complainbubble_color_unavailable);
778 float padding = autocvar_hud_panel_weapons_complainbubble_padding;
779 drawpic_aspect_skin(wpnpos + '1 1 0' * padding, "weapon_complainbubble", wpnsize - '2 2 0' * padding, color, a * panel_fg_alpha, DRAWFLAG_NORMAL);
780 drawstring_aspect(wpnpos + '1 1 0' * padding, s, wpnsize - '2 2 0' * padding, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
796 float GetAmmoItemCode(float i)
800 case 0: return IT_SHELLS;
801 case 1: return IT_NAILS;
802 case 2: return IT_ROCKETS;
803 case 3: return IT_CELLS;
804 case 4: return IT_FUEL;
809 string GetAmmoPicture(float i)
813 case 0: return "ammo_shells";
814 case 1: return "ammo_bullets";
815 case 2: return "ammo_rockets";
816 case 3: return "ammo_cells";
817 case 4: return "ammo_fuel";
822 void DrawAmmoItem(vector myPos, vector mySize, float itemcode, float currently_selected)
825 if(autocvar__hud_configure)
827 currently_selected = (itemcode == 2); //rockets always selected
828 a = 31 + mod(itemcode*93, 128);
831 a = getstati(GetAmmoStat(itemcode)); // how much ammo do we have of type itemcode?
840 if(currently_selected)
845 vector picpos, numpos;
846 if(autocvar_hud_panel_ammo_iconalign)
849 picpos = myPos + eX * 2 * mySize_y;
853 numpos = myPos + eX * mySize_y;
857 if (currently_selected)
858 drawpic_aspect_skin(myPos, "ammo_current_bg", mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
860 if(a > 0 && autocvar_hud_panel_ammo_progressbar)
861 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 * alpha, DRAWFLAG_NORMAL);
863 if(autocvar_hud_panel_ammo_text)
866 drawstring_aspect(numpos, ftos(a), eX * (2/3) * mySize_x + eY * mySize_y, color, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
867 else // "ghost" ammo count
868 drawstring_aspect(numpos, ftos(a), eX * (2/3) * mySize_x + eY * mySize_y, '0 0 0', panel_fg_alpha * alpha * 0.5, DRAWFLAG_NORMAL);
871 drawpic_aspect_skin(picpos, GetAmmoPicture(itemcode), '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
872 else // "ghost" ammo icon
873 drawpic_aspect_skin(picpos, GetAmmoPicture(itemcode), '1 1 0' * mySize_y, '0 0 0', panel_fg_alpha * alpha * 0.5, DRAWFLAG_NORMAL);
878 if(hud != HUD_NORMAL) return;
879 if(!autocvar__hud_configure)
881 if(!autocvar_hud_panel_ammo) return;
882 if(spectatee_status == -1) return;
885 hud_configure_active_panel = HUD_PANEL_AMMO;
887 HUD_Panel_UpdateCvars(ammo);
888 HUD_Panel_ApplyFadeAlpha();
896 pos += '1 1 0' * panel_bg_padding;
897 mySize -= '2 2 0' * panel_bg_padding;
900 float rows, columns, row, column;
902 if (autocvar_hud_panel_ammo_onlycurrent)
906 rows = mySize_y/mySize_x;
907 rows = bound(1, floor((sqrt(4 * (3/1) * rows * AMMO_COUNT + rows * rows) + rows + 0.5) / 2), AMMO_COUNT);
908 // ^^^ ammo item aspect goes here
910 columns = ceil(AMMO_COUNT/rows);
912 ammo_size = eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows);
917 if(ammo_size_x/ammo_size_y > 3)
919 newSize = 3 * ammo_size_y;
920 offset_x = ammo_size_x - newSize;
922 ammo_size_x = newSize;
926 newSize = 1/3 * ammo_size_x;
927 offset_y = ammo_size_y - newSize;
929 ammo_size_y = newSize;
932 float i, stat_items, currently_selected;
933 if (autocvar_hud_panel_ammo_onlycurrent)
935 if(autocvar__hud_configure)
937 DrawAmmoItem(pos, ammo_size, 2, true); //show rockets
940 stat_items = getstati(STAT_ITEMS);
941 for (i = 0; i < AMMO_COUNT; ++i) {
942 currently_selected = stat_items & GetAmmoItemCode(i);
943 if (currently_selected)
945 DrawAmmoItem(pos, ammo_size, i, true);
949 return; // nothing to display
952 stat_items = getstati(STAT_ITEMS);
953 for (i = 0; i < AMMO_COUNT; ++i) {
954 currently_selected = stat_items & GetAmmoItemCode(i);
955 DrawAmmoItem(pos + eX * column * (ammo_size_x + offset_x) + eY * row * (ammo_size_y + offset_y), ammo_size, i, currently_selected);
965 void DrawNumIcon(vector myPos, vector mySize, float x, string icon, float vertical, float icon_right_align, vector color, float alpha)
967 vector newPos, newSize;
968 vector picpos, numpos;
972 if(mySize_y/mySize_x > 2)
974 newSize_y = 2 * mySize_x;
975 newSize_x = mySize_x;
977 newPos_y = myPos_y + (mySize_y - newSize_y) / 2;
982 newSize_x = 1/2 * mySize_y;
983 newSize_y = mySize_y;
985 newPos_x = myPos_x + (mySize_x - newSize_x) / 2;
992 picpos = newPos + eY * newSize_x;
997 numpos = newPos + eY * newSize_x;
1001 drawpic_aspect_skin(picpos, icon, newSize, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1002 // make number smaller than icon, it looks better
1003 // reduce only y to draw numbers with different number of digits with the same y size
1004 numpos_y += newSize_y * ((1 - 0.7) / 2);
1006 drawstring_aspect(numpos, ftos(x), newSize, color, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1010 if(mySize_x/mySize_y > 3)
1012 newSize_x = 3 * mySize_y;
1013 newSize_y = mySize_y;
1015 newPos_x = myPos_x + (mySize_x - newSize_x) / 2;
1020 newSize_y = 1/3 * mySize_x;
1021 newSize_x = mySize_x;
1023 newPos_y = myPos_y + (mySize_y - newSize_y) / 2;
1027 if(icon_right_align) // right align
1030 picpos = newPos + eX * 2 * newSize_y;
1034 numpos = newPos + eX * newSize_y;
1038 drawstring_aspect(numpos, ftos(x), '2 1 0' * newSize_y, color, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1039 drawpic_aspect_skin(picpos, icon, '1 1 0' * newSize_y, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1042 void DrawNumIcon_expanding(vector myPos, vector mySize, float x, string icon, float vertical, float icon_right_align, vector color, float fadelerp)
1045 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
1047 DrawNumIcon(myPos + expandingbox_resize_centered_box_offset(sz, mySize, 1), mySize * sz, x, icon, vertical, icon_right_align, color, (1 - fadelerp));
1052 void HUD_Powerups(void)
1054 float strength_time, shield_time;
1055 if(!autocvar__hud_configure)
1057 if(!autocvar_hud_panel_powerups) return;
1058 if(spectatee_status == -1) return;
1059 if not(getstati(STAT_ITEMS) & (IT_STRENGTH | IT_INVINCIBLE)) return;
1060 if (getstati(STAT_HEALTH) <= 0) return;
1062 strength_time = bound(0, getstatf(STAT_STRENGTH_FINISHED) - time, 99);
1063 shield_time = bound(0, getstatf(STAT_INVINCIBLE_FINISHED) - time, 99);
1067 hud_configure_active_panel = HUD_PANEL_POWERUPS;
1073 HUD_Panel_UpdateCvars(powerups);
1074 HUD_Panel_ApplyFadeAlpha();
1077 mySize = panel_size;
1079 HUD_Panel_DrawBg(bound(0, max(strength_time, shield_time), 1));
1080 if(panel_bg_padding)
1082 pos += '1 1 0' * panel_bg_padding;
1083 mySize -= '2 2 0' * panel_bg_padding;
1086 float panel_ar = mySize_x/mySize_y;
1087 float is_vertical = (panel_ar < 1);
1088 vector shield_offset, strength_offset;
1089 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
1092 if (autocvar_hud_panel_powerups_flip)
1093 shield_offset_x = mySize_x;
1095 strength_offset_x = mySize_x;
1100 if (autocvar_hud_panel_powerups_flip)
1101 shield_offset_y = mySize_y;
1103 strength_offset_y = mySize_y;
1106 float shield_baralign, strength_baralign;
1107 float shield_iconalign, strength_iconalign;
1108 if (autocvar_hud_panel_powerups_flip)
1110 strength_baralign = (autocvar_hud_panel_powerups_baralign == 2 || autocvar_hud_panel_powerups_baralign == 1);
1111 shield_baralign = (autocvar_hud_panel_powerups_baralign == 3 || autocvar_hud_panel_powerups_baralign == 1);
1112 strength_iconalign = (autocvar_hud_panel_powerups_iconalign == 2 || autocvar_hud_panel_powerups_iconalign == 1);
1113 shield_iconalign = (autocvar_hud_panel_powerups_iconalign == 3 || autocvar_hud_panel_powerups_iconalign == 1);
1117 shield_baralign = (autocvar_hud_panel_powerups_baralign == 2 || autocvar_hud_panel_powerups_baralign == 1);
1118 strength_baralign = (autocvar_hud_panel_powerups_baralign == 3 || autocvar_hud_panel_powerups_baralign == 1);
1119 shield_iconalign = (autocvar_hud_panel_powerups_iconalign == 2 || autocvar_hud_panel_powerups_iconalign == 1);
1120 strength_iconalign = (autocvar_hud_panel_powerups_iconalign == 3 || autocvar_hud_panel_powerups_iconalign == 1);
1125 const float maxshield = 30;
1126 float shield = ceil(shield_time);
1127 if(autocvar_hud_panel_powerups_progressbar)
1129 HUD_Panel_GetProgressBarColor(shield);
1130 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);
1132 if(autocvar_hud_panel_powerups_text)
1135 DrawNumIcon(pos + shield_offset, mySize, shield, "shield", is_vertical, shield_iconalign, '1 1 1', 1);
1137 DrawNumIcon_expanding(pos + shield_offset, mySize, shield, "shield", is_vertical, shield_iconalign, '1 1 1', bound(0, (shield - shield_time) / 0.5, 1));
1143 const float maxstrength = 30;
1144 float strength = ceil(strength_time);
1145 if(autocvar_hud_panel_powerups_progressbar)
1147 HUD_Panel_GetProgressBarColor(strength);
1148 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);
1150 if(autocvar_hud_panel_powerups_text)
1153 DrawNumIcon(pos + strength_offset, mySize, strength, "strength", is_vertical, strength_iconalign, '1 1 1', 1);
1155 DrawNumIcon_expanding(pos + strength_offset, mySize, strength, "strength", is_vertical, strength_iconalign, '1 1 1', bound(0, (strength - strength_time) / 0.5, 1));
1160 // Health/armor (#3)
1163 // prev_* vars contain the health/armor at the previous FRAME
1164 // set to -1 when player is dead or was not playing
1165 float prev_health, prev_armor;
1166 float health_damagetime, armor_damagetime;
1167 float health_beforedamage, armor_beforedamage;
1168 // old_p_* vars keep track of previous values when smoothing value changes of the progressbar
1169 float old_p_health, old_p_armor;
1170 float old_p_healthtime, old_p_armortime;
1171 // prev_p_* vars contain the health/armor progressbar value at the previous FRAME
1172 // set to -1 to forcedly stop effects when we switch spectated player (e.g. from playerX: 70h to playerY: 50h)
1173 float prev_p_health, prev_p_armor;
1175 void HUD_HealthArmor(void)
1177 float armor, health, fuel;
1178 if(!autocvar__hud_configure)
1180 if(!autocvar_hud_panel_healtharmor) return;
1181 if(hud != HUD_NORMAL) return;
1182 if(spectatee_status == -1) return;
1184 health = getstati(STAT_HEALTH);
1190 armor = getstati(STAT_ARMOR);
1192 // code to check for spectatee_status changes is in Ent_ClientData()
1193 // prev_p_health and prev_health can be set to -1 there
1195 if (prev_p_health == -1)
1198 health_beforedamage = 0;
1199 armor_beforedamage = 0;
1200 health_damagetime = 0;
1201 armor_damagetime = 0;
1202 prev_health = health;
1204 old_p_health = health;
1205 old_p_armor = armor;
1206 prev_p_health = health;
1207 prev_p_armor = armor;
1209 else if (prev_health == -1)
1211 //start the load effect
1212 health_damagetime = 0;
1213 armor_damagetime = 0;
1217 fuel = getstati(STAT_FUEL);
1221 hud_configure_active_panel = HUD_PANEL_HEALTHARMOR;
1228 HUD_Panel_UpdateCvars(healtharmor);
1229 HUD_Panel_ApplyFadeAlpha();
1232 mySize = panel_size;
1234 HUD_Panel_DrawBg(1);
1235 if(panel_bg_padding)
1237 pos += '1 1 0' * panel_bg_padding;
1238 mySize -= '2 2 0' * panel_bg_padding;
1241 float baralign = autocvar_hud_panel_healtharmor_baralign;
1242 float iconalign = autocvar_hud_panel_healtharmor_iconalign;
1244 float maxhealth = autocvar_hud_panel_healtharmor_maxhealth;
1245 float maxarmor = autocvar_hud_panel_healtharmor_maxarmor;
1246 if(autocvar_hud_panel_healtharmor == 2) // combined health and armor display
1249 v = healtharmor_maxdamage(health, armor, armorblockpercent);
1254 float maxtotal = maxhealth + maxarmor;
1256 if(v_z) // NOT fully armored
1258 biggercount = "health";
1259 if(autocvar_hud_panel_healtharmor_progressbar)
1261 HUD_Panel_GetProgressBarColor(health);
1262 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);
1265 if(autocvar_hud_panel_healtharmor_text)
1266 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);
1270 biggercount = "armor";
1271 if(autocvar_hud_panel_healtharmor_progressbar)
1273 HUD_Panel_GetProgressBarColor(armor);
1274 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);
1277 if(autocvar_hud_panel_healtharmor_text)
1278 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);
1280 if(autocvar_hud_panel_healtharmor_text)
1281 DrawNumIcon(pos, mySize, x, biggercount, 0, iconalign, HUD_Get_Num_Color(x, maxtotal), 1);
1285 HUD_Panel_GetProgressBarColor(fuel);
1286 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);
1291 float panel_ar = mySize_x/mySize_y;
1292 float is_vertical = (panel_ar < 1);
1293 vector health_offset, armor_offset;
1294 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
1297 if (autocvar_hud_panel_healtharmor_flip)
1298 health_offset_x = mySize_x;
1300 armor_offset_x = mySize_x;
1305 if (autocvar_hud_panel_healtharmor_flip)
1306 health_offset_y = mySize_y;
1308 armor_offset_y = mySize_y;
1311 float health_baralign, armor_baralign, fuel_baralign;
1312 float health_iconalign, armor_iconalign;
1313 if (autocvar_hud_panel_healtharmor_flip)
1315 armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1);
1316 health_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1);
1317 fuel_baralign = health_baralign;
1318 armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1);
1319 health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1);
1323 health_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1);
1324 armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1);
1325 fuel_baralign = armor_baralign;
1326 health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1);
1327 armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1);
1332 if(autocvar_hud_panel_healtharmor_progressbar)
1334 HUD_Panel_GetProgressBarColor(health);
1335 float p_health, pain_health_alpha;
1337 pain_health_alpha = 1;
1338 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
1340 if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0)
1342 if (fabs(prev_health - health) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth)
1344 if (time - old_p_healthtime < 1)
1345 old_p_health = prev_p_health;
1347 old_p_health = prev_health;
1348 old_p_healthtime = time;
1350 if (time - old_p_healthtime < 1)
1352 p_health += (old_p_health - health) * (1 - (time - old_p_healthtime));
1353 prev_p_health = p_health;
1356 if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0)
1358 if (prev_health - health >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
1360 if (time - health_damagetime >= 1)
1361 health_beforedamage = prev_health;
1362 health_damagetime = time;
1364 if (time - health_damagetime < 1)
1366 float health_damagealpha = 1 - (time - health_damagetime)*(time - health_damagetime);
1367 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);
1370 prev_health = health;
1372 if (health <= autocvar_hud_panel_healtharmor_progressbar_gfx_lowhealth)
1374 float BLINK_FACTOR = 0.15;
1375 float BLINK_BASE = 0.85;
1376 float BLINK_FREQ = 9;
1377 pain_health_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ);
1380 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);
1382 if(autocvar_hud_panel_healtharmor_text)
1383 DrawNumIcon(pos + health_offset, mySize, health, "health", is_vertical, health_iconalign, HUD_Get_Num_Color(health, maxhealth), 1);
1388 if(autocvar_hud_panel_healtharmor_progressbar)
1390 HUD_Panel_GetProgressBarColor(armor);
1393 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
1395 if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0)
1397 if (fabs(prev_armor - armor) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth)
1399 if (time - old_p_armortime < 1)
1400 old_p_armor = prev_p_armor;
1402 old_p_armor = prev_armor;
1403 old_p_armortime = time;
1405 if (time - old_p_armortime < 1)
1407 p_armor += (old_p_armor - armor) * (1 - (time - old_p_armortime));
1408 prev_p_armor = p_armor;
1411 if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0)
1413 if (prev_armor - armor >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
1415 if (time - armor_damagetime >= 1)
1416 armor_beforedamage = prev_armor;
1417 armor_damagetime = time;
1419 if (time - armor_damagetime < 1)
1421 float armor_damagealpha = 1 - (time - armor_damagetime)*(time - armor_damagetime);
1422 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);
1427 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);
1429 if(autocvar_hud_panel_healtharmor_text)
1430 DrawNumIcon(pos + armor_offset, mySize, armor, "armor", is_vertical, armor_iconalign, HUD_Get_Num_Color(armor, maxarmor), 1);
1436 mySize_x *= 0.2 / 2; //if vertical always halve x to not cover too much numbers with 3 digits
1440 mySize_x *= 2; //restore full panel size
1441 else if (panel_ar < 1/4)
1442 mySize_y *= 2; //restore full panel size
1443 HUD_Panel_GetProgressBarColor(fuel);
1444 HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", fuel/100, is_vertical, fuel_baralign, progressbar_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
1449 // Notification area (#4)
1452 string Weapon_SuicideMessage(float deathtype)
1454 w_deathtype = deathtype;
1455 get_weaponinfo(DEATH_WEAPONOF(deathtype)).weapon_func(WR_SUICIDEMESSAGE);
1456 return w_deathtypestring;
1459 string Weapon_KillMessage(float deathtype)
1461 w_deathtype = deathtype;
1462 get_weaponinfo(DEATH_WEAPONOF(deathtype)).weapon_func(WR_KILLMESSAGE);
1463 return w_deathtypestring;
1466 #define KN_MAX_ENTRIES 10
1468 float killnotify_times[KN_MAX_ENTRIES];
1469 float killnotify_deathtype[KN_MAX_ENTRIES];
1470 float killnotify_actiontype[KN_MAX_ENTRIES]; // 0 = "Y [used by] X", 1 = "X [did action to] Y"
1471 string killnotify_attackers[KN_MAX_ENTRIES];
1472 string killnotify_victims[KN_MAX_ENTRIES];
1473 void HUD_KillNotify_Push(string attacker, string victim, float actiontype, float wpn)
1477 kn_index = KN_MAX_ENTRIES-1;
1478 killnotify_times[kn_index] = time;
1479 killnotify_deathtype[kn_index] = wpn;
1480 killnotify_actiontype[kn_index] = actiontype;
1481 if(killnotify_attackers[kn_index])
1482 strunzone(killnotify_attackers[kn_index]);
1483 killnotify_attackers[kn_index] = strzone(attacker);
1484 if(killnotify_victims[kn_index])
1485 strunzone(killnotify_victims[kn_index]);
1486 killnotify_victims[kn_index] = strzone(victim);
1489 void HUD_KillNotify(string s1, string s2, string s3, float type, float msg) // s1 = attacker, s2 = victim
1492 float alsoprint, gentle;
1493 alsoprint = (autocvar_hud_panel_notify_print || !panel_enabled); // print message to console if: notify panel disabled, or cvar to do so enabled
1494 gentle = (autocvar_cl_gentle || autocvar_cl_gentle_messages);
1496 if ((msg == MSG_SUICIDE || msg == MSG_KILL || msg == MSG_KILL_ACTION) && gametype == GAME_CTS) // selfkill isn't interesting in CTS and only spams up the notify panel
1499 if(msg == MSG_SUICIDE) {
1500 w = DEATH_WEAPONOF(type);
1502 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1504 print("^1", sprintf(Weapon_SuicideMessage(type), strcat(s1, "^1")), "\n");
1505 } else if (type == DEATH_KILL) {
1506 HUD_KillNotify_Push(s1, "", 0, DEATH_KILL);
1508 print (sprintf(_("^1%s^1 couldn't take it anymore\n"), s1));
1509 } else if (type == DEATH_ROT) {
1510 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1512 print (sprintf(_("^1%s^1 died\n"), s1));
1513 } else if (type == DEATH_NOAMMO) {
1514 HUD_KillNotify_Push(s1, "", 0, DEATH_NOAMMO);
1516 print (sprintf(_("^7%s^7 committed suicide. What's the point of living without ammo?\n"), s1));
1517 } else if (type == DEATH_CAMP) {
1518 HUD_KillNotify_Push(s1, "", 0, DEATH_CAMP);
1520 print (sprintf(_("^1%s^1 thought they found a nice camping ground\n"), s1));
1521 } else if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
1522 HUD_KillNotify_Push(s1, "", 0, type);
1524 print (sprintf(_("^1%s^1 didn't become friends with the Lord of Teamplay\n"), s1));
1525 } else if (type == DEATH_CHEAT) {
1526 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1528 print (sprintf(_("^1%s^1 unfairly eliminated themself\n"), s1));
1529 } else if (type == DEATH_FIRE) {
1530 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1532 print (sprintf(_("^1%s^1 burned to death\n"), s1));
1533 } else if (type != DEATH_TEAMCHANGE && type != DEATH_QUIET) {
1534 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1536 print (sprintf(_("^1%s^1 couldn't resist the urge to self-destruct\n"), s1));
1539 if (stof(s2) > 2) // killcount > 2
1540 print (sprintf(_("^1%s^1 ended it all after a %d kill spree\n"), s1, stof(s2)));
1541 } else if(msg == MSG_KILL) {
1542 w = DEATH_WEAPONOF(type);
1544 if((w == WEP_RIFLE || w == WEP_MINSTANEX) && type & HITTYPE_HEADSHOT) // all headshot weapons go here
1545 HUD_KillNotify_Push(s1, s2, 1, DEATH_HEADSHOT);
1547 HUD_KillNotify_Push(s1, s2, 1, type);
1550 print("^1", sprintf(Weapon_KillMessage(type), strcat(s2, "^1"), strcat(s1, "^1")), "\n"); // default order: victim, killer
1552 else if(type == KILL_TEAM_RED || type == KILL_TEAM_BLUE || type == KILL_TEAM_SPREE) {
1553 HUD_KillNotify_Push(s1, s2, 1, type);
1557 print (sprintf(_("^1%s^1 took action against a team mate\n"), s1));
1559 print (sprintf(_("^1%s^1 mows down a team mate\n"), s1));
1562 if (stof(s2) > 2 && type == KILL_TEAM_SPREE) {
1564 print (sprintf(_("^1%s^1 ended a %d scoring spree by going against a team mate\n"), s1, stof(s3)));
1566 print (sprintf(_("^1%s^1 ended a %d kill spree by killing a team mate\n"), s1, stof(s3)));
1568 else if (stof(s2) > 2) {
1570 print (sprintf(_("^1%s^1's %s scoring spree was ended by a team mate!\n"), s1, stof(s3)));
1572 print (sprintf(_("^1%s^1's %s kill spree was ended by a team mate!\n"), s1, stof(s3)));
1575 else if(type == KILL_FIRST_BLOOD)
1576 print(sprintf(_("^1%s^1 drew first blood\n"), s1));
1577 else if (type == DEATH_TELEFRAG) {
1578 HUD_KillNotify_Push(s1, s2, 1, DEATH_TELEFRAG);
1580 print (sprintf(_("^1%s^1 tried to occupy %s^1's teleport destination space\n"), s2, s1));
1582 print (sprintf(_("^1%s^1 was telefragged by %s\n"), s2, s1));
1584 else if (type == DEATH_DROWN) {
1585 HUD_KillNotify_Push(s1, s2, 1, DEATH_DROWN);
1587 print (sprintf(_("^1%s^1 was drowned by %s\n"), s2, s1));
1589 else if (type == DEATH_SLIME) {
1590 HUD_KillNotify_Push(s1, s2, 1, DEATH_SLIME);
1592 print (sprintf(_("^1%s^1 was slimed by %s\n"), s2, s1));
1594 else if (type == DEATH_LAVA) {
1595 HUD_KillNotify_Push(s1, s2, 1, DEATH_LAVA);
1597 print (sprintf(_("^1%s^1 was cooked by %s\n"), s2, s1));
1599 else if (type == DEATH_FALL) {
1600 HUD_KillNotify_Push(s1, s2, 1, DEATH_FALL);
1602 print (sprintf(_("^1%s^1 was grounded by %s\n"), s2, s1));
1604 else if (type == DEATH_SHOOTING_STAR) {
1605 HUD_KillNotify_Push(s1, s2, 1, DEATH_SHOOTING_STAR);
1607 print (sprintf(_("^1%s^1 was shot into space by %s\n"), s2, s1));
1609 else if (type == DEATH_SWAMP) {
1610 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1612 print (sprintf(_("^1%s^1 was conserved by %s\n"), s2, s1));
1614 else if (type == DEATH_HURTTRIGGER)
1616 HUD_KillNotify_Push(s1, s2, 1, DEATH_HURTTRIGGER);
1618 print(sprintf(_("^1%s^1 was thrown into a world of hurt by %s\n"), s2, s1));
1619 } else if(type == DEATH_VHCRUSH) {
1620 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1622 print (sprintf(_("^1%s^1 was crushed by %s\n"), s2, s1));
1623 } else if(type == DEATH_SBMINIGUN) {
1624 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1626 print (sprintf(_("^1%s^1 got shredded by %s\n"), s2, s1));
1627 } else if(type == DEATH_SBROCKET) {
1628 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1630 print (sprintf(_("^1%s^1 was blasted to bits by %s\n"), s2, s1));
1631 } else if(type == DEATH_SBBLOWUP) {
1632 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1634 print (sprintf(_("^1%s^1 got caught in the destruction of %s^1's vehicle\n"), s2, s1));
1635 } else if(type == DEATH_WAKIGUN) {
1636 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1638 print (sprintf(_("^1%s^1 was bolted down by %s\n"), s2, s1));
1639 } else if(type == DEATH_WAKIROCKET) {
1640 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1642 print (sprintf(_("^1%s^1 could find no shelter from %s^1's rockets\n"), s2, s1));
1643 } else if(type == DEATH_WAKIBLOWUP) {
1644 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1646 print (sprintf(_("^1%s^1 dies when %s^1's wakizashi dies.\n"), s2, s1));
1647 } else if(type == DEATH_RAPTOR_CANNON) {
1648 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1650 print (sprintf(_("^1%s^1 nailed to hell by %s\n"), s2, s1));
1651 } else if(type == DEATH_RAPTOR_BOMB) {
1652 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1654 print (sprintf(_("^1%s^1 cluster crushed by %s\n"), s2, s1));
1655 } else if(type == DEATH_RAPTOR_DEATH) {
1656 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1658 print (sprintf(_("^1%s^1 dies when %s^1's raptor dies.\n"), s2, s1));
1659 } else if(type == DEATH_TURRET) {
1660 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1662 print (sprintf(_("^1%s^1 was pushed into the line of fire by %s\n"), s2, s1));
1663 } else if(type == DEATH_TOUCHEXPLODE) {
1664 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1666 print (sprintf(_("^1%s^1 was pushed into an accident by %s\n"), s2, s1));
1667 } else if(type == DEATH_CHEAT) {
1668 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1670 print (sprintf(_("^1%s^1 was unfairly eliminated by %s\n"), s2, s1));
1671 } else if (type == DEATH_FIRE) {
1672 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1674 print (sprintf(_("^1%s^1 was burnt to death by %s\n"), s2, s1));
1675 } else if (type == DEATH_CUSTOM) {
1676 HUD_KillNotify_Push(s1, s2, 1, DEATH_CUSTOM);
1678 print("^1", sprintf(s3, strcat(s2, "^1"), strcat(s1, "^1")), "\n");
1679 } else if (type == DEATH_HURTTRIGGER) {
1680 HUD_KillNotify_Push(s1, s2, 1, DEATH_HURTTRIGGER);
1682 print("^1", sprintf(s3, strcat(s2, "^1"), strcat(s1, "^1")), "\n");
1684 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1686 print (sprintf(_("^1%s^1 was fragged by %s\n"), s2, s1));
1688 } else if(msg == MSG_SPREE) {
1689 if(type == KILL_END_SPREE) {
1691 print (sprintf(_("^1%s^1's %s scoring spree was ended by %s\n"), s1, s2, s3));
1693 print (sprintf(_("^1%s^1's %s kill spree was ended by %s\n"), s1, s2, s3));
1694 } else if(type == KILL_SPREE) {
1696 print (sprintf(_("^1%s^1 made %s scores in a row\n"), s1, s2));
1698 print (sprintf(_("^1%s^1 has %s frags in a row\n"), s1, s2));
1699 } else if(type == KILL_SPREE_3) {
1701 print (sprintf(_("%s^7 made a ^1TRIPLE SCORE\n"), s1));
1703 print (sprintf(_("%s^7 made a ^1TRIPLE FRAG\n"), s1));
1704 } else if(type == KILL_SPREE_5) {
1706 print (sprintf(_("%s^7 unleashes ^1SCORING RAGE\n"), s1));
1708 print (sprintf(_("%s^7 unleashes ^1RAGE\n"), s1));
1709 } else if(type == KILL_SPREE_10) {
1711 print (sprintf(_("%s^7 made ^1TEN SCORES IN A ROW!\n"), s1));
1713 print (sprintf(_("%s^7 starts the ^1MASSACRE!\n"), s1));
1714 } else if(type == KILL_SPREE_15) {
1716 print (sprintf(_("%s^7 made ^1FIFTEEN SCORES IN A ROW!\n"), s1));
1718 print (sprintf(_("%s^7 executes ^1MAYHEM!\n"), s1));
1719 } else if(type == KILL_SPREE_20) {
1721 print (sprintf(_("%s^7 made ^1TWENTY SCORES IN A ROW!\n"), s1));
1723 print (sprintf(_("%s^7 is a ^1BERSERKER!\n"), s1));
1724 } else if(type == KILL_SPREE_25) {
1726 print (sprintf(_("%s^7 made ^1TWENTY FIVE SCORES IN A ROW!\n"), s1));
1728 print (sprintf(_("%s^7 inflicts ^1CARNAGE!\n"), s1));
1729 } else if(type == KILL_SPREE_30) {
1731 print (sprintf(_("%s^7 made ^1THIRTY SCORES IN A ROW!\n"), s1));
1733 print (sprintf(_("%s^7 unleashes ^1ARMAGEDDON!\n"), s1));
1735 } else if(msg == MSG_KILL_ACTION) { // wtf is this? isnt it basically the same as MSG_SUICIDE?
1736 if (type == DEATH_DROWN) {
1737 HUD_KillNotify_Push(s1, "", 0, DEATH_DROWN);
1741 print (sprintf(_("^1%s^1 was in the water for too long\n"), s1));
1743 print (sprintf(_("^1%s^1 drowned\n"), s1));
1745 } else if (type == DEATH_SLIME) {
1746 HUD_KillNotify_Push(s1, "", 0, DEATH_SLIME);
1748 print (sprintf(_("^1%s^1 was slimed\n"), s1));
1749 } else if (type == DEATH_LAVA) {
1750 HUD_KillNotify_Push(s1, "", 0, DEATH_LAVA);
1754 print (sprintf(_("^1%s^1 found a hot place\n"), s1));
1756 print (sprintf(_("^1%s^1 turned into hot slag\n"), s1));
1758 } else if (type == DEATH_FALL) {
1759 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1763 print (sprintf(_("^1%s^1 tested gravity (and it worked)\n"), s1));
1765 print (sprintf(_("^1%s^1 hit the ground with a crunch\n"), s1));
1767 } else if (type == DEATH_SHOOTING_STAR) {
1768 HUD_KillNotify_Push(s1, "", 0, DEATH_SHOOTING_STAR);
1770 print (sprintf(_("^1%s^1 became a shooting star\n"), s1));
1771 } else if (type == DEATH_SWAMP) {
1772 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1776 print (sprintf(_("^1%s^1 discovered a swamp\n"), s1));
1778 print (sprintf(_("^1%s^1 is now conserved for centuries to come\n"), s1));
1780 } else if(type == DEATH_TURRET) {
1781 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1783 print (sprintf(_("^1%s^1 was mowed down by a turret \n"), s1));
1784 } else if (type == DEATH_CUSTOM) {
1785 HUD_KillNotify_Push(s1, "", 0, DEATH_CUSTOM);
1787 print("^1", sprintf(s2, strcat(s1, "^1")), "\n");
1788 } else if (type == DEATH_HURTTRIGGER) {
1789 HUD_KillNotify_Push(s1, "", 0, DEATH_HURTTRIGGER);
1791 print("^1", sprintf(s2, strcat(s1, "^1")), "\n");
1792 } else if(type == DEATH_TOUCHEXPLODE) {
1793 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1795 print (sprintf(_("^1%s^1 died in an accident\n"), s1));
1796 } else if(type == DEATH_CHEAT) {
1797 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1799 print (sprintf(_("^1%s^1 was unfairly eliminated\n"), s1));
1800 } else if(type == DEATH_FIRE) {
1801 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1805 print (sprintf(_("^1%s^1 felt a little hot\n"), s1));
1807 print (sprintf(_("^1%s^1 burnt to death\n"), s1));
1810 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1814 print (sprintf(_("^1%s^1 needs a restart\n"), s1));
1816 print (sprintf(_("^1%s^1 died\n"), s1));
1819 } else if(msg == MSG_KILL_ACTION_SPREE) {
1821 print (sprintf(_("^1%s^1 needs a restart after a %d scoring spree\n"), s1, stof(s2)));
1823 print (sprintf(_("^1%s^1 died with a %d kill spree\n"), s1, stof(s2)));
1824 } else if(msg == MSG_INFO) {
1825 if(type == INFO_GOTFLAG) { // here, s2 is the flag name
1826 HUD_KillNotify_Push(s1, s2, 0, INFO_GOTFLAG);
1827 print(sprintf(_("%s^7 got the %s\n"), s1, s2));
1828 } else if(type == INFO_LOSTFLAG) {
1829 HUD_KillNotify_Push(s1, s2, 0, INFO_LOSTFLAG);
1830 print(sprintf(_("%s^7 lost the %s\n"), s1, s2));
1831 } else if(type == INFO_PICKUPFLAG) {
1832 HUD_KillNotify_Push(s1, s2, 0, INFO_GOTFLAG);
1833 print(sprintf(_("%s^7 picked up the %s\n"), s1, s2));
1834 } else if(type == INFO_RETURNFLAG) {
1835 HUD_KillNotify_Push(s1, s2, 0, INFO_RETURNFLAG);
1836 print(sprintf(_("%s^7 returned the %s\n"), s1, s2));
1837 } else if(type == INFO_CAPTUREFLAG) {
1838 HUD_KillNotify_Push(s1, s2, 0, INFO_CAPTUREFLAG);
1839 print(sprintf(_("%s^7 captured the %s%s\n"), s1, s2, s3));
1841 } else if(msg == MSG_RACE) {
1842 if(type == RACE_SERVER_RECORD) {
1843 HUD_KillNotify_Push(s1, s2, 1, RACE_SERVER_RECORD);
1845 else if(type == RACE_NEW_RANK) {
1846 HUD_KillNotify_Push(s1, s2, 1, RACE_NEW_RANK);
1848 else if(type == RACE_NEW_TIME) {
1849 HUD_KillNotify_Push(s1, s2, 1, RACE_NEW_TIME);
1851 else if(type == RACE_FAIL) {
1852 HUD_KillNotify_Push(s1, s2, 1, RACE_FAIL);
1854 } else if(msg == MSG_KA) {
1855 if(type == KA_PICKUPBALL) {
1856 HUD_KillNotify_Push(s1, s2, 0, KA_PICKUPBALL);
1858 print (sprintf(_("%s^7 has picked up the ball!\n"), s1));
1860 else if(type == KA_DROPBALL) {
1861 HUD_KillNotify_Push(s1, s2, 0, KA_DROPBALL);
1863 print(sprintf(_("%s^7 has dropped the ball!\n"), s1));
1868 void HUD_Centerprint(string s1, string s2, float type, float msg)
1871 gentle = (autocvar_cl_gentle || autocvar_cl_gentle_messages);
1872 if(msg == MSG_SUICIDE) {
1873 if (type == DEATH_TEAMCHANGE) {
1874 centerprint(sprintf(_("You are now on: %s"), s1));
1875 } else if (type == DEATH_AUTOTEAMCHANGE) {
1876 centerprint(sprintf(_("You have been moved into a different team to improve team balance\nYou are now on: %s"), s1));
1877 } else if (type == DEATH_CAMP) {
1879 centerprint(_("^1Reconsider your tactics, camper!"));
1881 centerprint(_("^1Die camper!"));
1882 } else if (type == DEATH_NOAMMO) {
1884 centerprint(_("^1You are reinserted into the game for running out of ammo..."));
1886 centerprint(_("^1You were killed for running out of ammo..."));
1887 } else if (type == DEATH_ROT) {
1889 centerprint(_("^1You need to preserve your health"));
1891 centerprint(_("^1You grew too old without taking your medicine"));
1892 } else if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
1894 centerprint(_("^1Don't go against team mates!"));
1896 centerprint(_("^1Don't shoot your team mates!"));
1897 } else if (type == DEATH_QUIET) {
1899 } else { // generic message
1901 centerprint(_("^1You need to be more careful!"));
1903 centerprint(_("^1You killed your own dumb self!"));
1905 } else if(msg == MSG_KILL) {
1906 if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
1908 centerprint(sprintf(_("^1Moron! You went against ^7%s^1, a team mate!"), s1));
1910 centerprint(sprintf(_("^1Moron! You fragged ^7%s^1, a team mate!"), s1));
1912 } else if (type == KILL_FIRST_BLOOD) {
1914 centerprint(_("^1First score"));
1916 centerprint(_("^1First blood"));
1918 } else if (type == KILL_FIRST_VICTIM) {
1920 centerprint(_("^1First casualty"));
1922 centerprint(_("^1First victim"));
1924 } else if (type == KILL_TYPEFRAG) { // s2 contains "advanced kill messages" such as ping, handicap...
1926 centerprint(strcat(sprintf(_("^1You scored against ^7%s^1 who was typing!"), s1), s2));
1928 centerprint(strcat(sprintf(_("^1You typefragged ^7%s"), s1), s2));
1930 } else if (type == KILL_TYPEFRAGGED) {
1932 centerprint(strcat(sprintf(_("^1You were scored against by ^7%s^1 while you were typing!"), s1), s2));
1934 centerprint(strcat(sprintf(_("^1You were typefragged by ^7%s"), s1), s2));
1936 } else if (type == KILL_FRAG) {
1938 centerprint(strcat(sprintf(_("^4You scored against ^7%s"), s1), s2));
1940 centerprint(strcat(sprintf(_("^4You fragged ^7%s"), s1), s2));
1942 } else { // generic message
1944 centerprint(strcat(sprintf(_("^1You were scored against by ^7%s"), s1), s2));
1946 centerprint(strcat(sprintf(_("^1You were fragged by ^7%s"), s1), s2));
1949 } else if(msg == MSG_KILL_ACTION) {
1950 // TODO: invent more centerprints here?
1951 centerprint(_("^1Watch your step!"));
1955 void HUD_Notify (void)
1957 if(!autocvar__hud_configure)
1959 if(!autocvar_hud_panel_notify) return;
1962 hud_configure_active_panel = HUD_PANEL_NOTIFY;
1964 HUD_Panel_UpdateCvars(notify);
1965 HUD_Panel_ApplyFadeAlpha();
1968 mySize = panel_size;
1970 HUD_Panel_DrawBg(1);
1971 if(panel_bg_padding)
1973 pos += '1 1 0' * panel_bg_padding;
1974 mySize -= '2 2 0' * panel_bg_padding;
1977 float entries, height;
1978 entries = bound(1, floor(KN_MAX_ENTRIES * mySize_y/mySize_x), KN_MAX_ENTRIES);
1979 height = mySize_y/entries;
1982 float fontheight = height * autocvar_hud_panel_notify_fontsize;
1983 fontsize = '0.5 0.5 0' * fontheight;
1987 when = autocvar_hud_panel_notify_time;
1989 fadetime = autocvar_hud_panel_notify_fadetime;
1993 vector pos_attacker, pos_victim;
1995 float width_attacker;
1996 string attacker, victim;
1998 float i, j, w, step, limit;
1999 if(autocvar_hud_panel_notify_flip) //order items from the top down
2005 else //order items from the bottom up
2012 for(j = kn_index; i != limit; i += step, ++j)
2014 if(autocvar__hud_configure)
2018 else // inverse order
2019 a = entries - 1 - i;
2020 attacker = textShortenToWidth(sprintf(_("Player %d"), a+1), 0.48 * mySize_x - height, fontsize, stringwidth_colors);
2021 victim = textShortenToWidth(sprintf(_("Player %d"), a+2), 0.48 * mySize_x - height, fontsize, stringwidth_colors);
2022 s = strcat("weapon", get_weaponinfo(WEP_FIRST + mod(floor(a*2.4), WEP_LAST)).netname);
2023 a = bound(0, (when - a) / 4, 1);
2024 goto hud_config_notifyprint;
2027 if (j == KN_MAX_ENTRIES)
2030 if(killnotify_times[j] + when > time)
2034 a = bound(0, (killnotify_times[j] + when + fadetime - time) / fadetime, 1);
2048 w = DEATH_WEAPONOF(killnotify_deathtype[j]);
2050 // TODO: maybe print in team colors?
2053 if(killnotify_actiontype[j] == 0)
2055 if(killnotify_deathtype[j] == DEATH_GENERIC)
2059 else if(killnotify_deathtype[j] == DEATH_NOAMMO)
2061 s = "notify_outofammo";
2063 else if(killnotify_deathtype[j] == DEATH_KILL)
2065 s = "notify_selfkill";
2067 else if(killnotify_deathtype[j] == DEATH_CAMP)
2069 s = "notify_camping";
2071 else if(killnotify_deathtype[j] == KILL_TEAM_RED)
2073 s = "notify_teamkill_red";
2075 else if(killnotify_deathtype[j] == KILL_TEAM_BLUE)
2077 s = "notify_teamkill_blue";
2079 else if(killnotify_deathtype[j] == DEATH_DROWN)
2083 else if(killnotify_deathtype[j] == DEATH_SLIME)
2087 else if(killnotify_deathtype[j] == DEATH_LAVA)
2091 else if(killnotify_deathtype[j] == DEATH_FALL)
2095 else if(killnotify_deathtype[j] == DEATH_SHOOTING_STAR)
2097 s = "notify_shootingstar";
2099 else if(killnotify_deathtype[j] == DEATH_HURTTRIGGER || killnotify_deathtype[j] == DEATH_CUSTOM)
2103 else if(killnotify_deathtype[j] == INFO_GOTFLAG)
2105 if(killnotify_victims[j] == "^1RED^7 flag")
2107 s = "notify_red_taken";
2111 s = "notify_blue_taken";
2114 else if(killnotify_deathtype[j] == INFO_RETURNFLAG)
2116 if(killnotify_victims[j] == "^1RED^7 flag")
2118 s = "notify_red_returned";
2122 s = "notify_blue_returned";
2125 else if(killnotify_deathtype[j] == INFO_LOSTFLAG)
2127 if(killnotify_victims[j] == "^1RED^7 flag")
2129 s = "notify_red_lost";
2133 s = "notify_blue_lost";
2136 else if(killnotify_deathtype[j] == INFO_CAPTUREFLAG)
2138 if(killnotify_victims[j] == "^1RED^7 flag")
2140 s = "notify_red_captured";
2144 s = "notify_blue_captured";
2147 else if(killnotify_deathtype[j] == KA_DROPBALL)
2149 s = "notify_balldropped";
2151 else if(killnotify_deathtype[j] == KA_PICKUPBALL)
2153 s = "notify_ballpickedup";
2156 attacker = textShortenToWidth(killnotify_attackers[j], 0.48 * mySize_x - height, fontsize, stringwidth_colors);
2157 pos_attacker = pos + eX * (0.52 * mySize_x + height) + eY * ((0.5 * fontsize_y + i * height) + (0.5 * (height - fontheight)));
2158 weap_pos = pos + eX * 0.5 * mySize_x - eX * height + eY * i * height;
2162 drawpic_aspect_skin(weap_pos, s, '2 1 0' * height, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
2163 drawcolorcodedstring(pos_attacker, attacker, fontsize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2166 // X [did action to] Y
2169 if(killnotify_deathtype[j] & HITTYPE_SECONDARY && w == WEP_LASER)
2171 s = "notify_melee_laser";
2173 else if(killnotify_deathtype[j] & HITTYPE_SECONDARY && w == WEP_SHOTGUN)
2175 s = "notify_melee_shotgun";
2177 else if(WEP_VALID(w))
2179 self = get_weaponinfo(w);
2180 s = strcat("weapon", self.netname);
2182 else if(killnotify_deathtype[j] == KILL_TEAM_RED)
2184 s = "notify_teamkill_red";
2186 else if(killnotify_deathtype[j] == KILL_TEAM_BLUE)
2188 s = "notify_teamkill_red";
2190 else if(killnotify_deathtype[j] == DEATH_TELEFRAG)
2192 s = "notify_telefrag";
2194 else if(killnotify_deathtype[j] == DEATH_DROWN)
2198 else if(killnotify_deathtype[j] == DEATH_SLIME)
2202 else if(killnotify_deathtype[j] == DEATH_LAVA)
2206 else if(killnotify_deathtype[j] == DEATH_FALL)
2210 else if(killnotify_deathtype[j] == DEATH_SHOOTING_STAR)
2212 s = "notify_shootingstar";
2214 else if(killnotify_deathtype[j] == DEATH_HURTTRIGGER || killnotify_deathtype[j] == DEATH_CUSTOM) // DEATH_CUSTOM is also void, right?
2218 else if(killnotify_deathtype[j] == DEATH_HEADSHOT)
2220 s = "notify_headshot";
2222 else if(killnotify_deathtype[j] == RACE_SERVER_RECORD)
2224 s = "race_newrecordserver";
2226 else if(killnotify_deathtype[j] == RACE_NEW_RANK)
2228 s = "race_newrankyellow";
2230 else if(killnotify_deathtype[j] == RACE_NEW_TIME)
2234 else if(killnotify_deathtype[j] == RACE_FAIL)
2239 attacker = textShortenToWidth(killnotify_attackers[j], 0.48 * mySize_x - height, fontsize, stringwidth_colors);
2240 victim = textShortenToWidth(killnotify_victims[j], 0.48 * mySize_x - height, fontsize, stringwidth_colors);
2241 :hud_config_notifyprint
2242 width_attacker = stringwidth(attacker, TRUE, fontsize);
2243 pos_attacker = pos + eX * (0.48 * mySize_x - height - width_attacker) + eY * ((0.5 * fontsize_y + i * height) + (0.5 * (height - fontheight)));
2244 pos_victim = pos + eX * (0.52 * mySize_x + height) + eY * ((0.5 * fontsize_y + i * height) + (0.5 * (height - fontheight)));
2245 weap_pos = pos + eX * 0.5 * mySize_x - eX * height + eY * i * height;
2249 drawpic_aspect_skin(weap_pos, s, '2 1 0' * height, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
2250 drawcolorcodedstring(pos_attacker, attacker, fontsize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2251 drawcolorcodedstring(pos_victim, victim, fontsize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2260 string seconds_tostring(float sec)
2263 minutes = floor(sec / 60);
2265 sec -= minutes * 60;
2266 return sprintf("%d:%02d", minutes, sec);
2269 void HUD_Timer(void)
2271 if(!autocvar__hud_configure)
2273 if(!autocvar_hud_panel_timer) return;
2276 hud_configure_active_panel = HUD_PANEL_TIMER;
2278 HUD_Panel_UpdateCvars(timer);
2279 HUD_Panel_ApplyFadeAlpha();
2282 mySize = panel_size;
2284 HUD_Panel_DrawBg(1);
2285 if(panel_bg_padding)
2287 pos += '1 1 0' * panel_bg_padding;
2288 mySize -= '2 2 0' * panel_bg_padding;
2292 float timelimit, elapsedTime, timeleft, minutesLeft;
2294 timelimit = getstatf(STAT_TIMELIMIT);
2296 timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
2297 timeleft = ceil(timeleft);
2299 minutesLeft = floor(timeleft / 60);
2302 if(minutesLeft >= 5 || warmup_stage || timelimit == 0) //don't use red or yellow in warmup or when there is no timelimit
2303 timer_color = '1 1 1'; //white
2304 else if(minutesLeft >= 1)
2305 timer_color = '1 1 0'; //yellow
2307 timer_color = '1 0 0'; //red
2309 if (autocvar_hud_panel_timer_increment || timelimit == 0 || warmup_stage) {
2310 if (time < getstatf(STAT_GAMESTARTTIME)) {
2311 //while restart is still active, show 00:00
2312 timer = seconds_tostring(0);
2314 elapsedTime = floor(time - getstatf(STAT_GAMESTARTTIME)); //127
2315 timer = seconds_tostring(elapsedTime);
2318 timer = seconds_tostring(timeleft);
2321 drawstring_aspect(pos, timer, mySize, timer_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2326 void HUD_Radar(void)
2328 if (!autocvar__hud_configure)
2330 if (autocvar_hud_panel_radar == 0) return;
2331 if (autocvar_hud_panel_radar != 2 && !teamplay) return;
2334 hud_configure_active_panel = HUD_PANEL_RADAR;
2336 HUD_Panel_UpdateCvars(radar);
2337 HUD_Panel_ApplyFadeAlpha();
2340 mySize = panel_size;
2342 HUD_Panel_DrawBg(1);
2343 if(panel_bg_padding)
2345 pos += '1 1 0' * panel_bg_padding;
2346 mySize -= '2 2 0' * panel_bg_padding;
2351 float scale2d, normalsize, bigsize;
2354 teamradar_origin2d = pos + 0.5 * mySize;
2355 teamradar_size2d = mySize;
2357 if(minimapname == "")
2360 teamradar_loadcvars();
2362 switch(hud_panel_radar_zoommode)
2366 f = current_zoomfraction;
2369 f = 1 - current_zoomfraction;
2379 switch(hud_panel_radar_rotation)
2382 teamradar_angle = view_angles_y - 90;
2385 teamradar_angle = 90 * hud_panel_radar_rotation;
2389 scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
2390 teamradar_size2d = mySize;
2392 teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0'; // we always center
2394 // pixels per world qu to match the teamradar_size2d_x range in the longest dimension
2395 if(hud_panel_radar_rotation == 0)
2397 // max-min distance must fit the radar in any rotation
2398 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen2d(mi_scale));
2402 vector c0, c1, c2, c3, span;
2403 c0 = rotate(mi_min, teamradar_angle * DEG2RAD);
2404 c1 = rotate(mi_max, teamradar_angle * DEG2RAD);
2405 c2 = rotate('1 0 0' * mi_min_x + '0 1 0' * mi_max_y, teamradar_angle * DEG2RAD);
2406 c3 = rotate('1 0 0' * mi_max_x + '0 1 0' * mi_min_y, teamradar_angle * DEG2RAD);
2408 span_x = max4(c0_x, c1_x, c2_x, c3_x) - min4(c0_x, c1_x, c2_x, c3_x);
2409 span_y = max4(c0_y, c1_y, c2_y, c3_y) - min4(c0_y, c1_y, c2_y, c3_y);
2411 // max-min distance must fit the radar in x=x, y=y
2413 teamradar_size2d_x * scale2d / (1.05 * span_x),
2414 teamradar_size2d_y * scale2d / (1.05 * span_y)
2418 normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / hud_panel_radar_scale;
2419 if(bigsize > normalsize)
2420 normalsize = bigsize;
2424 + (1 - f) * normalsize;
2425 teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
2427 + (1 - f) * view_origin);
2436 draw_teamradar_background(hud_panel_radar_foreground_alpha);
2438 for(tm = world; (tm = find(tm, classname, "radarlink")); )
2439 draw_teamradar_link(tm.origin, tm.velocity, tm.team);
2440 for(tm = world; (tm = findflags(tm, teamradar_icon, 0xFFFFFF)); )
2441 draw_teamradar_icon(tm.origin, tm.teamradar_icon, tm, tm.teamradar_color, panel_fg_alpha);
2442 for(tm = world; (tm = find(tm, classname, "entcs_receiver")); )
2444 color2 = GetPlayerColor(tm.sv_entnum);
2445 //if(color == COLOR_SPECTATOR || color == color2)
2446 draw_teamradar_player(tm.origin, tm.angles, GetTeamRGB(color2));
2448 draw_teamradar_player(view_origin, view_angles, '1 1 1');
2450 drawresetcliparea();
2455 void HUD_UpdatePlayerTeams();
2456 void HUD_Score_Rankings(vector pos, vector mySize, entity me, float team_count)
2460 #define SCOREPANEL_MAX_ENTRIES 6
2461 #define SCOREPANEL_ASPECTRATIO 2
2462 const float entries = bound(1, floor(SCOREPANEL_MAX_ENTRIES * mySize_y/mySize_x * SCOREPANEL_ASPECTRATIO), SCOREPANEL_MAX_ENTRIES);
2463 const vector fontsize = '1 1 0' * (mySize_y/entries);
2465 vector rgb, score_color;
2467 score_color = '1 1 1';
2469 const float name_size = mySize_x*0.75;
2470 const float spacing_size = mySize_x*0.04;
2471 const float highlight_alpha = 0.2;
2472 float i, me_printed, first_pl;
2475 if (autocvar__hud_configure)
2477 float players_per_team;
2480 // show team scores in the first line
2481 float score_size = mySize_x / team_count;
2482 players_per_team = max(2, ceil((entries - 1) / team_count));
2483 for(i=0; i<team_count; ++i) {
2484 if (i == floor((entries - 2) / players_per_team) || (entries == 1 && i == 0))
2485 HUD_Panel_DrawHighlight(pos + eX * score_size * i, eX * score_size + eY * fontsize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2486 drawstring_aspect(pos + eX * score_size * i, ftos(175 - 23*i), eX * score_size + eY * fontsize_y, GetTeamRGB(ColorByTeam(i)) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2489 pos_y += fontsize_y;
2491 score = 10 + SCOREPANEL_MAX_ENTRIES * 3;
2492 for (i=first_pl; i<entries; ++i)
2494 //simulate my score is lower than all displayed players,
2495 //so that I don't appear at all showing pure rankings.
2496 //This is to better show the difference between the 2 ranking views
2497 if (i == entries-1 && autocvar_hud_panel_score_rankings == 1)
2500 drawfill(pos, eX * mySize_x + eY * fontsize_y, rgb, highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2501 s = GetPlayerName(pl.sv_entnum);
2506 s = sprintf(_("Player %d"), i + 1 - first_pl);
2511 score_color = GetTeamRGB(ColorByTeam(floor((i - first_pl) / players_per_team))) * 0.8;
2512 s = textShortenToWidth(s, name_size, fontsize, stringwidth_colors);
2513 drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, TRUE, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
2514 drawstring(pos + eX * (name_size + spacing_size), ftos(score), fontsize, score_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2515 pos_y += fontsize_y;
2520 if (!scoreboard_fade_alpha) // the scoreboard too calls HUD_UpdatePlayerTeams
2521 HUD_UpdatePlayerTeams();
2524 // show team scores in the first line
2525 float score_size = mySize_x / team_count;
2526 for(tm = teams.sort_next; tm; tm = tm.sort_next) {
2527 if(tm.team == COLOR_SPECTATOR)
2529 if (tm.team == myteam)
2530 drawfill(pos + eX * score_size * i, eX * score_size + eY * fontsize_y, '1 1 1', highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2531 drawstring_aspect(pos + eX * score_size * i, ftos(tm.(teamscores[ts_primary])), eX * score_size + eY * fontsize_y, GetTeamRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2535 pos_y += fontsize_y;
2536 tm = teams.sort_next;
2541 for (pl = players.sort_next; pl && i<entries; pl = pl.sort_next)
2543 if ((team_count && pl.team != tm.team) || pl.team == COLOR_SPECTATOR)
2546 if (i == entries-1 && !me_printed && pl != me)
2547 if (autocvar_hud_panel_score_rankings == 1 && spectatee_status != -1)
2549 for (pl = me.sort_next; pl; pl = pl.sort_next)
2550 if (pl.team != COLOR_SPECTATOR)
2554 rgb = '1 1 0'; //not last but not among the leading players: yellow
2556 rgb = '1 0 0'; //last: red
2563 rgb = '0 1 0'; //first: green
2565 drawfill(pos, eX * mySize_x + eY * fontsize_y, rgb, highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2568 score_color = GetTeamRGB(pl.team) * 0.8;
2569 s = textShortenToWidth(GetPlayerName(pl.sv_entnum), name_size, fontsize, stringwidth_colors);
2570 drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, TRUE, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
2571 drawstring(pos + eX * (name_size + spacing_size), ftos(pl.(scores[ps_primary])), fontsize, score_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2572 pos_y += fontsize_y;
2575 while (i<entries && team_count && (tm = tm.sort_next) && (tm.team != COLOR_SPECTATOR || (tm = tm.sort_next)));
2578 void HUD_Score(void)
2580 if(!autocvar__hud_configure)
2582 if(!autocvar_hud_panel_score) return;
2583 if(spectatee_status == -1 && (gametype == GAME_RACE || gametype == GAME_CTS)) return;
2586 hud_configure_active_panel = HUD_PANEL_SCORE;
2588 HUD_Panel_UpdateCvars(score);
2589 HUD_Panel_ApplyFadeAlpha();
2592 mySize = panel_size;
2594 HUD_Panel_DrawBg(1);
2595 if(panel_bg_padding)
2597 pos += '1 1 0' * panel_bg_padding;
2598 mySize -= '2 2 0' * panel_bg_padding;
2601 float score, distribution;
2603 vector distribution_color;
2605 me = (spectatee_status > 0) ? playerslots[spectatee_status - 1] : playerslots[player_localentnum - 1];
2607 if((scores_flags[ps_primary] & SFL_TIME) && !teamplay) { // race/cts record display on HUD
2608 string timer, distrtimer;
2610 pl = players.sort_next;
2613 if(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)
2614 if(pl.scores[ps_primary] == 0)
2617 score = me.(scores[ps_primary]);
2618 timer = TIME_ENCODED_TOSTRING(score);
2620 if (pl && ((!(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)) || score)) {
2621 // distribution display
2622 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
2624 distrtimer = ftos_decimals(fabs(distribution/pow(10, TIME_DECIMALS)), TIME_DECIMALS);
2626 if (distribution <= 0) {
2627 distribution_color = '0 1 0';
2631 distribution_color = '1 0 0';
2634 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);
2636 // race record display
2637 if (distribution <= 0)
2638 HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2639 drawstring_aspect(pos, timer, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2640 } else if (!teamplay) { // non-teamgames
2641 if ((spectatee_status == -1 && !autocvar__hud_configure) || autocvar_hud_panel_score_rankings)
2643 HUD_Score_Rankings(pos, mySize, me, 0);
2646 // me vector := [team/connected frags id]
2647 pl = players.sort_next;
2651 if(autocvar__hud_configure)
2654 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
2658 score = me.(scores[ps_primary]);
2659 if(autocvar__hud_configure)
2662 if(distribution >= 5)
2663 distribution_color = eY;
2664 else if(distribution >= 0)
2665 distribution_color = '1 1 1';
2666 else if(distribution >= -5)
2667 distribution_color = '1 1 0';
2669 distribution_color = eX;
2671 string distribution_str;
2672 distribution_str = ftos(distribution);
2673 if (distribution >= 0)
2675 if (distribution > 0)
2676 distribution_str = strcat("+", distribution_str);
2677 HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2679 drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize_x + eY * mySize_y, distribution_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2680 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);
2681 } else { // teamgames
2682 float scores_count, row, column, rows, columns;
2684 vector score_pos, score_size; //for scores other than myteam
2685 if (spectatee_status == -1 || autocvar_hud_panel_score_rankings)
2687 for(tm = teams.sort_next; tm, tm.team != COLOR_SPECTATOR; tm = tm.sort_next)
2689 if (autocvar_hud_panel_score_rankings)
2691 HUD_Score_Rankings(pos, mySize, me, scores_count);
2694 rows = mySize_y/mySize_x;
2695 rows = bound(1, floor((sqrt(4 * (3/1) * rows * scores_count + rows * rows) + rows + 0.5) / 2), scores_count);
2696 // ^^^ ammo item aspect goes here
2698 columns = ceil(scores_count/rows);
2700 score_size = eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows);
2703 if(score_size_x/score_size_y > 3)
2705 newSize = 3 * score_size_y;
2706 offset_x = score_size_x - newSize;
2707 pos_x += offset_x/2;
2708 score_size_x = newSize;
2712 newSize = 1/3 * score_size_x;
2713 offset_y = score_size_y - newSize;
2714 pos_y += offset_y/2;
2715 score_size_y = newSize;
2719 score_size = eX * mySize_x*(1/4) + eY * mySize_y*(1/3);
2721 float max_fragcount;
2722 max_fragcount = -99;
2723 for(tm = teams.sort_next; tm; tm = tm.sort_next) {
2724 if(tm.team == COLOR_SPECTATOR)
2726 score = tm.(teamscores[ts_primary]);
2727 if(autocvar__hud_configure)
2730 if (score > max_fragcount)
2731 max_fragcount = score;
2733 if (spectatee_status == -1)
2735 score_pos = pos + eX * column * (score_size_x + offset_x) + eY * row * (score_size_y + offset_y);
2736 if (max_fragcount == score)
2737 HUD_Panel_DrawHighlight(score_pos, score_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2738 drawstring_aspect(score_pos, ftos(score), score_size, GetTeamRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2746 else if(tm.team == myteam) {
2747 if (max_fragcount == score)
2748 HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2749 drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize_x + eY * mySize_y, GetTeamRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2751 if (max_fragcount == score)
2752 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);
2753 drawstring_aspect(pos + eX * 0.75 * mySize_x + eY * (1/3) * rows * mySize_y, ftos(score), score_size, GetTeamRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2762 void HUD_RaceTimer (void)
2764 if(!autocvar__hud_configure)
2766 if(!autocvar_hud_panel_racetimer) return;
2767 if(!(gametype == GAME_RACE || gametype == GAME_CTS)) return;
2768 if(spectatee_status == -1) return;
2771 hud_configure_active_panel = HUD_PANEL_RACETIMER;
2773 HUD_Panel_UpdateCvars(racetimer);
2774 HUD_Panel_ApplyFadeAlpha();
2777 mySize = panel_size;
2779 HUD_Panel_DrawBg(1);
2780 if(panel_bg_padding)
2782 pos += '1 1 0' * panel_bg_padding;
2783 mySize -= '2 2 0' * panel_bg_padding;
2786 // always force 4:1 aspect
2788 if(mySize_x/mySize_y > 4)
2790 newSize_x = 4 * mySize_y;
2791 newSize_y = mySize_y;
2793 pos_x = pos_x + (mySize_x - newSize_x) / 2;
2797 newSize_y = 1/4 * mySize_x;
2798 newSize_x = mySize_x;
2800 pos_y = pos_y + (mySize_y - newSize_y) / 2;
2805 string s, forcetime;
2807 if(autocvar__hud_configure)
2810 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);
2811 s = _("^1Intermediate 1 (+15.42)");
2812 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);
2813 s = sprintf(_("^1PENALTY: %.1f (%s)"), 2, "missing a checkpoint");
2814 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);
2816 else if(race_checkpointtime)
2818 a = bound(0, 2 - (time - race_checkpointtime), 1);
2821 if(a > 0) // just hit a checkpoint?
2823 if(race_checkpoint != 254)
2825 if(race_time && race_previousbesttime)
2826 s = MakeRaceString(race_checkpoint, TIME_DECODE(race_time) - TIME_DECODE(race_previousbesttime), 0, 0, race_previousbestname);
2828 s = MakeRaceString(race_checkpoint, 0, -1, 0, race_previousbestname);
2830 forcetime = TIME_ENCODED_TOSTRING(race_time);
2835 if(race_laptime && race_nextbesttime && race_nextcheckpoint != 254)
2837 a = bound(0, 2 - ((race_laptime + TIME_DECODE(race_nextbesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1);
2838 if(a > 0) // next one?
2840 s = MakeRaceString(race_nextcheckpoint, (time + TIME_DECODE(race_penaltyaccumulator)) - race_laptime, TIME_DECODE(race_nextbesttime), 0, race_nextbestname);
2845 if(s != "" && a > 0)
2847 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);
2850 if(race_penaltytime)
2852 a = bound(0, 2 - (time - race_penaltyeventtime), 1);
2855 s = sprintf(_("^1PENALTY: %.1f (%s)"), race_penaltytime * 0.1, race_penaltyreason);
2856 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);
2862 a = bound(0, (time - race_checkpointtime) / 0.5, 1);
2863 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);
2868 if(race_laptime && race_checkpoint != 255)
2870 s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime));
2871 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);
2876 if(race_mycheckpointtime)
2878 a = bound(0, 2 - (time - race_mycheckpointtime), 1);
2879 s = MakeRaceString(race_mycheckpoint, TIME_DECODE(race_mycheckpointdelta), -!race_mycheckpointenemy, race_mycheckpointlapsdelta, race_mycheckpointenemy);
2880 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);
2882 if(race_othercheckpointtime && race_othercheckpointenemy != "")
2884 a = bound(0, 2 - (time - race_othercheckpointtime), 1);
2885 s = MakeRaceString(race_othercheckpoint, -TIME_DECODE(race_othercheckpointdelta), -!race_othercheckpointenemy, race_othercheckpointlapsdelta, race_othercheckpointenemy);
2886 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);
2889 if(race_penaltytime && !race_penaltyaccumulator)
2891 t = race_penaltytime * 0.1 + race_penaltyeventtime;
2892 a = bound(0, (1 + t - time), 1);
2896 s = sprintf(_("^1PENALTY: %.1f (%s)"), (t - time) * 0.1, race_penaltyreason);
2898 s = sprintf(_("^2PENALTY: %.1f (%s)"), 0, race_penaltyreason);
2899 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);
2907 float vote_yescount;
2910 float vote_highlighted; // currently selected vote
2912 float vote_active; // is there an active vote?
2913 float vote_prev; // previous state of vote_active to check for a change
2915 float vote_change; // "time" when vote_active changed
2917 void HUD_VoteWindow(void)
2919 if(autocvar_cl_allow_uid2name == -1 && (gametype == GAME_CTS || gametype == GAME_RACE))
2922 if (autocvar__hud_configure)
2926 print(_("^1You must answer before entering hud configure mode\n"));
2927 cvar_set("_hud_configure", "0");
2929 vote_called_vote = strzone(_("^2Name ^7instead of \"^1Unregistered player^7\" in stats"));
2930 uid2name_dialog = 1;
2933 if(!autocvar__hud_configure)
2935 if(!autocvar_hud_panel_vote) return;
2937 panel_fg_alpha = autocvar_hud_panel_fg_alpha;
2938 panel_bg_alpha_str = autocvar_hud_panel_vote_bg_alpha;
2940 if(panel_bg_alpha_str == "") {
2941 panel_bg_alpha_str = ftos(autocvar_hud_panel_bg_alpha);
2943 panel_bg_alpha = stof(panel_bg_alpha_str);
2947 hud_configure_active_panel = HUD_PANEL_VOTE;
2956 if(vote_active != vote_prev) {
2958 vote_prev = vote_active;
2961 if(vote_active || autocvar__hud_configure)
2962 vote_alpha = bound(0, (time - vote_change) * 2, 1);
2964 vote_alpha = bound(0, 1 - (time - vote_change) * 2, 1);
2969 HUD_Panel_UpdateCvars(vote);
2970 HUD_Panel_ApplyFadeAlpha();
2974 panel_pos = eX * 0.3 * vid_conwidth + eY * 0.1 * vid_conheight;
2975 panel_size = eX * 0.4 * vid_conwidth + eY * 0.3 * vid_conheight;
2978 // these must be below above block
2981 mySize = panel_size;
2983 a = vote_alpha * (vote_highlighted ? autocvar_hud_panel_vote_alreadyvoted_alpha : 1);
2984 HUD_Panel_DrawBg(a);
2985 a = panel_fg_alpha * a;
2987 if(panel_bg_padding)
2989 pos += '1 1 0' * panel_bg_padding;
2990 mySize -= '2 2 0' * panel_bg_padding;
2993 // always force 3:1 aspect
2995 if(mySize_x/mySize_y > 3)
2997 newSize_x = 3 * mySize_y;
2998 newSize_y = mySize_y;
3000 pos_x = pos_x + (mySize_x - newSize_x) / 2;
3004 newSize_y = 1/3 * mySize_x;
3005 newSize_x = mySize_x;
3007 pos_y = pos_y + (mySize_y - newSize_y) / 2;
3011 s = _("A vote has been called for:");
3013 s = _("Allow servers to store and display your name?");
3014 drawstring_aspect(pos, s, eX * mySize_x + eY * (2/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
3015 s = textShortenToWidth(vote_called_vote, mySize_x, '1 1 0' * mySize_y * (1/8), stringwidth_colors);
3016 if(autocvar__hud_configure)
3017 s = _("^1Configure the HUD");
3018 drawcolorcodedstring_aspect(pos + eY * (2/8) * mySize_y, s, eX * mySize_x + eY * (1.75/8) * mySize_y, a, DRAWFLAG_NORMAL);
3020 // print the yes/no counts
3021 s = sprintf(_("Yes (%s): %d"), getcommandkey("vyes", "vyes"), vote_yescount);
3022 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);
3023 s = sprintf(_("No (%s): %d"), getcommandkey("vno", "vno"), vote_nocount);
3024 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);
3026 // draw the progress bar backgrounds
3027 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_back", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
3029 // draw the highlights
3030 if(vote_highlighted == 1) {
3031 drawsetcliparea(pos_x, pos_y, mySize_x * 0.5, mySize_y);
3032 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_voted", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
3034 else if(vote_highlighted == -1) {
3035 drawsetcliparea(pos_x + 0.5 * mySize_x, pos_y, mySize_x * 0.5, mySize_y);
3036 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_voted", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
3039 // draw the progress bars
3040 if(vote_yescount && vote_needed)
3042 drawsetcliparea(pos_x, pos_y, mySize_x * 0.5 * (vote_yescount/vote_needed), mySize_y);
3043 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_prog", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
3046 if(vote_nocount && vote_needed)
3048 drawsetcliparea(pos_x + mySize_x - mySize_x * 0.5 * (vote_nocount/vote_needed), pos_y, mySize_x * 0.5, mySize_y);
3049 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_prog", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
3052 drawresetcliparea();
3055 // Mod icons panel (#10)
3058 float mod_active; // is there any active mod icon?
3060 // Clan Arena HUD modicons
3061 void HUD_Mod_CA(vector pos, vector mySize)
3063 mod_active = 1; // CA should never hide the mod icons panel
3064 float redalive, bluealive;
3065 redalive = getstati(STAT_REDALIVE);
3066 bluealive = getstati(STAT_BLUEALIVE);
3068 vector redpos, bluepos;
3069 if(mySize_x > mySize_y)
3072 bluepos = pos + eY * 0.5 * mySize_y;
3073 drawpic_aspect_skin(redpos, "player_red.tga", 0.5 * mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3074 drawstring_aspect(redpos + eX * 0.5 * mySize_x, ftos(redalive), 0.5 * mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3075 drawpic_aspect_skin(bluepos, "player_blue.tga", 0.5 * mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3076 drawstring_aspect(bluepos + eX * 0.5 * mySize_x, ftos(bluealive), 0.5 * mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3081 bluepos = pos + eY * 0.5 * mySize_y;
3082 drawpic_aspect_skin(redpos, "player_red.tga", eX * mySize_x + eY * 0.3 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3083 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);
3084 drawpic_aspect_skin(bluepos, "player_blue.tga", eX * mySize_x + eY * 0.3 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3085 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);
3089 // CTF HUD modicon section
3090 float redflag_prevframe, blueflag_prevframe; // status during previous frame
3091 float redflag_prevstatus, blueflag_prevstatus; // last remembered status
3092 float redflag_statuschange_time, blueflag_statuschange_time; // time when the status changed
3094 void HUD_Mod_CTF_Reset(void)
3096 redflag_prevstatus = blueflag_prevstatus = redflag_prevframe = blueflag_prevframe = redflag_statuschange_time = blueflag_statuschange_time = 0;
3099 void HUD_Mod_CTF(vector pos, vector mySize)
3101 vector redflag_pos, blueflag_pos;
3103 float f; // every function should have that
3105 float redflag, blueflag; // current status
3106 float redflag_statuschange_elapsedtime, blueflag_statuschange_elapsedtime; // time since the status changed
3109 stat_items = getstati(STAT_ITEMS);
3110 redflag = (stat_items/IT_RED_FLAG_TAKEN) & 3;
3111 blueflag = (stat_items/IT_BLUE_FLAG_TAKEN) & 3;
3113 if(redflag || blueflag)
3118 if(autocvar__hud_configure)
3124 // when status CHANGES, set old status into prevstatus and current status into status
3125 if (redflag != redflag_prevframe)
3127 redflag_statuschange_time = time;
3128 redflag_prevstatus = redflag_prevframe;
3129 redflag_prevframe = redflag;
3132 if (blueflag != blueflag_prevframe)
3134 blueflag_statuschange_time = time;
3135 blueflag_prevstatus = blueflag_prevframe;
3136 blueflag_prevframe = blueflag;
3139 redflag_statuschange_elapsedtime = time - redflag_statuschange_time;
3140 blueflag_statuschange_elapsedtime = time - blueflag_statuschange_time;
3142 float BLINK_FACTOR = 0.15;
3143 float BLINK_BASE = 0.85;
3145 // RMS = sqrt(BLINK_BASE^2 + 0.5 * BLINK_FACTOR^2)
3147 // BLINK_BASE = sqrt(RMS^2 - 0.5 * BLINK_FACTOR^2)
3149 float BLINK_FREQ = 5; // circle frequency, = 2*pi*frequency in hertz
3151 string red_icon, red_icon_prevstatus;
3152 float red_alpha, red_alpha_prevstatus;
3153 red_alpha = red_alpha_prevstatus = 1;
3155 case 1: red_icon = "flag_red_taken"; break;
3156 case 2: red_icon = "flag_red_lost"; break;
3157 case 3: red_icon = "flag_red_carrying"; red_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3159 if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM2))
3160 red_icon = "flag_red_shielded";
3162 red_icon = string_null;
3165 switch(redflag_prevstatus) {
3166 case 1: red_icon_prevstatus = "flag_red_taken"; break;
3167 case 2: red_icon_prevstatus = "flag_red_lost"; break;
3168 case 3: red_icon_prevstatus = "flag_red_carrying"; red_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3171 red_icon_prevstatus = "flag_red_carrying"; // make it more visible
3172 else if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM2))
3173 red_icon_prevstatus = "flag_red_shielded";
3175 red_icon_prevstatus = string_null;
3179 string blue_icon, blue_icon_prevstatus;
3180 float blue_alpha, blue_alpha_prevstatus;
3181 blue_alpha = blue_alpha_prevstatus = 1;
3183 case 1: blue_icon = "flag_blue_taken"; break;
3184 case 2: blue_icon = "flag_blue_lost"; break;
3185 case 3: blue_icon = "flag_blue_carrying"; blue_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3187 if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM1))
3188 blue_icon = "flag_blue_shielded";
3190 blue_icon = string_null;
3193 switch(blueflag_prevstatus) {
3194 case 1: blue_icon_prevstatus = "flag_blue_taken"; break;
3195 case 2: blue_icon_prevstatus = "flag_blue_lost"; break;
3196 case 3: blue_icon_prevstatus = "flag_blue_carrying"; blue_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3199 blue_icon_prevstatus = "flag_blue_carrying"; // make it more visible
3200 else if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM1))
3201 blue_icon_prevstatus = "flag_blue_shielded";
3203 blue_icon_prevstatus = string_null;
3207 if(mySize_x > mySize_y) {
3208 if (myteam == COLOR_TEAM1) { // always draw own flag on left
3210 blueflag_pos = pos + eX * 0.5 * mySize_x;
3213 redflag_pos = pos + eX * 0.5 * mySize_x;
3215 flag_size = eX * 0.5 * mySize_x + eY * mySize_y;
3217 if (myteam == COLOR_TEAM1) { // always draw own flag on left
3219 blueflag_pos = pos + eY * 0.5 * mySize_y;
3222 redflag_pos = pos + eY * 0.5 * mySize_y;
3224 flag_size = eY * 0.5 * mySize_y + eX * mySize_x;
3227 f = bound(0, redflag_statuschange_elapsedtime*2, 1);
3228 if(red_icon_prevstatus && f < 1)
3229 drawpic_aspect_skin_expanding(redflag_pos, red_icon_prevstatus, flag_size, '1 1 1', panel_fg_alpha * red_alpha_prevstatus, DRAWFLAG_NORMAL, f);
3231 drawpic_aspect_skin(redflag_pos, red_icon, flag_size, '1 1 1', panel_fg_alpha * red_alpha * f, DRAWFLAG_NORMAL);
3233 f = bound(0, blueflag_statuschange_elapsedtime*2, 1);
3234 if(blue_icon_prevstatus && f < 1)
3235 drawpic_aspect_skin_expanding(blueflag_pos, blue_icon_prevstatus, flag_size, '1 1 1', panel_fg_alpha * blue_alpha_prevstatus, DRAWFLAG_NORMAL, f);
3237 drawpic_aspect_skin(blueflag_pos, blue_icon, flag_size, '1 1 1', panel_fg_alpha * blue_alpha * f, DRAWFLAG_NORMAL);
3240 // Keyhunt HUD modicon section
3241 float kh_runheretime;
3243 void HUD_Mod_KH_Reset(void)
3248 void HUD_Mod_KH(vector pos, vector mySize)
3250 mod_active = 1; // keyhunt should never hide the mod icons panel
3254 vector p, pa, kh_size, kh_asize;
3256 kh_keys = getstati(STAT_KH_KEYS);
3259 if(mySize_x > mySize_y)
3261 p_y = pos_y + 0.25 * mySize_y;
3262 pa = p - eY * 0.25 * mySize_y;
3264 kh_size_x = mySize_x * 0.25;
3265 kh_size_y = 0.75 * mySize_y;
3266 kh_asize_x = mySize_x * 0.25;
3267 kh_asize_y = mySize_y * 0.25;
3271 p_y = pos_y + 0.125 * mySize_y;
3272 pa = p - eY * 0.125 * mySize_y;
3274 kh_size_x = mySize_x * 0.5;
3275 kh_size_y = 0.375 * mySize_y;
3276 kh_asize_x = mySize_x * 0.5;
3277 kh_asize_y = mySize_y * 0.125;
3284 for(i = 0; i < 4; ++i)
3286 key = floor(kh_keys / pow(32, i)) & 31;
3288 if(keyteam == 30 && keycount <= 4)
3290 if(keyteam == myteam || keyteam == -1 || keyteam == 30)
3294 // this yields 8 exactly if "RUN HERE" shows
3299 kh_runheretime = time;
3300 pa_y -= fabs(sin((time - kh_runheretime) * 3.5)) * 6; // make the arrows jump in case of RUN HERE
3305 for(i = 0; i < 4; ++i)
3307 key = floor(kh_keys / pow(32, i)) & 31;
3320 default: // owned or dropped
3325 a = a * panel_fg_alpha;
3326 aa = aa * panel_fg_alpha;
3332 drawpic_aspect_skin(pa, "kh_redarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
3335 drawpic_aspect_skin(pa, "kh_bluearrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
3338 drawpic_aspect_skin(pa, "kh_yellowarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
3341 drawpic_aspect_skin(pa, "kh_pinkarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
3346 switch(i) // YAY! switch(i) inside a for loop for i. DailyWTF, here we come!
3349 drawpic_aspect_skin(p, "kh_red", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
3352 drawpic_aspect_skin(p, "kh_blue", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
3355 drawpic_aspect_skin(p, "kh_yellow", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
3358 drawpic_aspect_skin(p, "kh_pink", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
3362 if(mySize_x > mySize_y)
3364 p_x += 0.25 * mySize_x;
3365 pa_x += 0.25 * mySize_x;
3371 p_y = pos_y + 0.625 * mySize_y;
3372 pa_y = pos_y + 0.5 * mySize_y;
3378 p_x += 0.5 * mySize_x;
3379 pa_x += 0.5 * mySize_x;
3385 // Keepaway HUD mod icon
3386 float kaball_prevstatus; // last remembered status
3387 float kaball_statuschange_time; // time when the status changed
3389 // we don't need to reset for keepaway since it immediately
3390 // autocorrects prevstatus as to if the player has the ball or not
3392 void HUD_Mod_Keepaway(vector pos, vector mySize)
3394 mod_active = 1; // keepaway should always show the mod HUD
3396 float BLINK_FACTOR = 0.15;
3397 float BLINK_BASE = 0.85;
3398 float BLINK_FREQ = 5;
3399 float kaball_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ);
3401 float stat_items = getstati(STAT_ITEMS);
3402 float kaball = (stat_items/IT_KEY1) & 1;
3404 if(kaball != kaball_prevstatus)
3406 kaball_statuschange_time = time;
3407 kaball_prevstatus = kaball;
3410 vector kaball_pos, kaball_size;
3412 if(mySize_x > mySize_y) {
3413 kaball_pos = pos + eX * 0.25 * mySize_x;
3414 kaball_size = eX * 0.5 * mySize_x + eY * mySize_y;
3416 kaball_pos = pos + eY * 0.25 * mySize_y;
3417 kaball_size = eY * 0.5 * mySize_y + eX * mySize_x;
3420 float kaball_statuschange_elapsedtime = time - kaball_statuschange_time;
3421 float f = bound(0, kaball_statuschange_elapsedtime*2, 1);
3423 if(kaball_prevstatus && f < 1)
3424 drawpic_aspect_skin_expanding(kaball_pos, "keepawayball_carrying", kaball_size, '1 1 1', panel_fg_alpha * kaball_alpha, DRAWFLAG_NORMAL, f);
3427 drawpic_aspect_skin(pos, "keepawayball_carrying", eX * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha * kaball_alpha * f, DRAWFLAG_NORMAL);
3431 // Nexball HUD mod icon
3432 void HUD_Mod_NexBall(vector pos, vector mySize)
3434 float stat_items, nb_pb_starttime, dt, p;
3436 stat_items = getstati(STAT_ITEMS);
3437 nb_pb_starttime = getstatf(STAT_NB_METERSTART);
3439 if (stat_items & IT_KEY1)
3444 //Manage the progress bar if any
3445 if (nb_pb_starttime > 0)
3447 dt = mod(time - nb_pb_starttime, nb_pb_period);
3448 // one period of positive triangle
3449 p = 2 * dt / nb_pb_period;
3454 HUD_Panel_GetProgressBarColor(nexball);
3455 if(mySize_x > mySize_y)
3456 HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", p, 0, 0, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
3458 HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", p, 1, 0, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
3461 if (stat_items & IT_KEY1)
3462 drawpic_aspect_skin(pos, "nexball_carrying", eX * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3465 // Race/CTS HUD mod icons
3466 float crecordtime_prev; // last remembered crecordtime
3467 float crecordtime_change_time; // time when crecordtime last changed
3468 float srecordtime_prev; // last remembered srecordtime
3469 float srecordtime_change_time; // time when srecordtime last changed
3471 float race_status_time;
3472 float race_status_prev;
3473 string race_status_name_prev;
3474 void HUD_Mod_Race(vector pos, vector mySize)
3476 mod_active = 1; // race should never hide the mod icons panel
3478 me = playerslots[player_localentnum - 1];
3480 float f; // yet another function has this
3481 score = me.(scores[ps_primary]);
3483 if not((scores_flags[ps_primary] & SFL_TIME) && !teamplay) // race/cts record display on HUD
3484 return; // no records in the actual race
3486 // clientside personal record
3488 if(gametype == GAME_CTS)
3492 t = stof(db_get(ClientProgsDB, strcat(shortmapname, rr, "time")));
3494 if(score && (score < t || !t)) {
3495 db_put(ClientProgsDB, strcat(shortmapname, rr, "time"), ftos(score));
3496 if(autocvar_cl_autodemo_delete_keeprecords)
3498 f = autocvar_cl_autodemo_delete;
3500 cvar_set("cl_autodemo_delete", ftos(f)); // don't delete demo with new record!
3504 if(t != crecordtime_prev) {
3505 crecordtime_prev = t;
3506 crecordtime_change_time = time;
3509 vector textPos, medalPos;
3511 if(mySize_x > mySize_y) {
3512 // text on left side
3513 squareSize = min(mySize_y, mySize_x/2);
3514 textPos = pos + eX * 0.5 * max(0, mySize_x/2 - squareSize) + eY * 0.5 * (mySize_y - squareSize);
3515 medalPos = pos + eX * 0.5 * max(0, mySize_x/2 - squareSize) + eX * 0.5 * mySize_x + eY * 0.5 * (mySize_y - squareSize);
3518 squareSize = min(mySize_x, mySize_y/2);
3519 textPos = pos + eY * 0.5 * max(0, mySize_y/2 - squareSize) + eX * 0.5 * (mySize_x - squareSize);
3520 medalPos = pos + eY * 0.5 * max(0, mySize_y/2 - squareSize) + eY * 0.5 * mySize_y + eX * 0.5 * (mySize_x - squareSize);
3523 f = time - crecordtime_change_time;
3526 drawstring_aspect(textPos, _("Personal best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3527 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);
3529 drawstring_aspect(textPos, _("Personal best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3530 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);
3531 drawstring_aspect_expanding(pos, _("Personal best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
3532 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);
3536 t = race_server_record;
3537 if(t != srecordtime_prev) {
3538 srecordtime_prev = t;
3539 srecordtime_change_time = time;
3541 f = time - srecordtime_change_time;
3544 drawstring_aspect(textPos + eY * 0.5 * squareSize, _("Server best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3545 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);
3547 drawstring_aspect(textPos + eY * 0.5 * squareSize, _("Server best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3548 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);
3549 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);
3550 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);
3553 if (race_status != race_status_prev || race_status_name != race_status_name_prev) {
3554 race_status_time = time + 5;
3555 race_status_prev = race_status;
3556 if (race_status_name_prev)
3557 strunzone(race_status_name_prev);
3558 race_status_name_prev = strzone(race_status_name);
3563 a = bound(0, race_status_time - time, 1);
3566 s = textShortenToWidth(race_status_name, squareSize, '1 1 0' * 0.1 * squareSize, stringwidth_colors);
3570 rank = race_CheckName(race_status_name);
3572 rankname = race_PlaceName(rank);
3575 namepos = medalPos + '0 0.8 0' * squareSize;
3577 rankpos = medalPos + '0 0.15 0' * squareSize;
3579 if(race_status == 0)
3580 drawpic_aspect_skin(medalPos, "race_newfail", '1 1 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3581 else if(race_status == 1) {
3582 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);
3583 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3584 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3585 } else if(race_status == 2) {
3586 if(race_status_name == GetPlayerName(player_localentnum -1) || !race_myrank || race_myrank < rank)
3587 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);
3589 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);
3590 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3591 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3592 } else if(race_status == 3) {
3593 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);
3594 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3595 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3598 if (race_status_time - time <= 0) {
3599 race_status_prev = -1;
3601 if(race_status_name)
3602 strunzone(race_status_name);
3603 race_status_name = string_null;
3604 if(race_status_name_prev)
3605 strunzone(race_status_name_prev);
3606 race_status_name_prev = string_null;
3610 void DrawDomItem(vector myPos, vector mySize, float aspect_ratio, float layout, float i)
3612 float stat, pps_ratio;
3618 stat = getstatf(STAT_DOM_PPS_RED);
3619 pic = "dom_icon_red";
3623 stat = getstatf(STAT_DOM_PPS_BLUE);
3624 pic = "dom_icon_blue";
3628 stat = getstatf(STAT_DOM_PPS_YELLOW);
3629 pic = "dom_icon_yellow";
3633 stat = getstatf(STAT_DOM_PPS_PINK);
3634 pic = "dom_icon_pink";
3637 pps_ratio = stat / getstatf(STAT_DOM_TOTAL_PPS);
3639 if(mySize_x/mySize_y > aspect_ratio)
3641 i = aspect_ratio * mySize_y;
3642 myPos_x = myPos_x + (mySize_x - i) / 2;
3647 i = 1/aspect_ratio * mySize_x;
3648 myPos_y = myPos_y + (mySize_y - i) / 2;
3652 if (layout) // show text too
3655 color *= 0.5 + pps_ratio * (1 - 0.5); // half saturated color at min, full saturated at max
3656 if (layout == 2) // average pps
3657 drawstring_aspect(myPos + eX * mySize_y, ftos_decimals(stat, 2), eX * (2/3) * mySize_x + eY * mySize_y, color, panel_fg_alpha, DRAWFLAG_NORMAL);
3658 else // percentage of average pps
3659 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);
3663 drawpic_aspect_skin(myPos, pic, '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3666 drawsetcliparea(myPos_x, myPos_y + mySize_y * (1 - pps_ratio), mySize_y, mySize_y * pps_ratio);
3667 drawpic_aspect_skin(myPos, strcat(pic, "-highlighted"), '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3668 drawresetcliparea();
3672 void HUD_Mod_Dom(vector myPos, vector mySize)
3674 mod_active = 1; // required in each mod function that always shows something
3677 for(tm = teams.sort_next; tm; tm = tm.sort_next)
3678 if(tm.team != COLOR_SPECTATOR)
3681 float layout = autocvar_hud_panel_modicons_dom_layout;
3682 float rows, columns, aspect_ratio;
3683 rows = mySize_y/mySize_x;
3684 aspect_ratio = (layout) ? 3 : 1;
3685 rows = bound(1, floor((sqrt((4 * aspect_ratio * teams_count + rows) * rows) + rows + 0.5) / 2), teams_count);
3686 columns = ceil(teams_count/rows);
3690 for(i=0; i<teams_count; ++i)
3692 vector pos, itemSize;
3693 pos = myPos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows);
3694 itemSize = eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows);
3696 DrawDomItem(pos, itemSize, aspect_ratio, layout, i);
3707 float mod_prev; // previous state of mod_active to check for a change
3709 float mod_change; // "time" when mod_active changed
3711 void HUD_ModIcons(void)
3713 if(!autocvar__hud_configure)
3715 if(!autocvar_hud_panel_modicons) return;
3716 if (gametype != GAME_CTF && gametype != GAME_KEYHUNT && gametype != GAME_NEXBALL && gametype != GAME_CTS && gametype != GAME_RACE && gametype != GAME_CA && gametype != GAME_FREEZETAG && gametype != GAME_KEEPAWAY && gametype != GAME_DOMINATION) return;
3719 hud_configure_active_panel = HUD_PANEL_MODICONS;
3721 HUD_Panel_UpdateCvars(modicons);
3722 HUD_Panel_ApplyFadeAlpha();
3725 mySize = panel_size;
3727 if(mod_active != mod_prev) {
3729 mod_prev = mod_active;
3732 if(mod_active || autocvar__hud_configure)
3733 mod_alpha = bound(0, (time - mod_change) * 2, 1);
3735 mod_alpha = bound(0, 1 - (time - mod_change) * 2, 1);
3738 HUD_Panel_DrawBg(mod_alpha);
3740 if(panel_bg_padding)
3742 pos += '1 1 0' * panel_bg_padding;
3743 mySize -= '2 2 0' * panel_bg_padding;
3746 // these MUST be ran in order to update mod_active
3747 if(gametype == GAME_KEYHUNT)
3748 HUD_Mod_KH(pos, mySize);
3749 else if(gametype == GAME_CTF || autocvar__hud_configure)
3750 HUD_Mod_CTF(pos, mySize); // forcealpha only needed for ctf icons, as only they are shown in config mode
3751 else if(gametype == GAME_NEXBALL)
3752 HUD_Mod_NexBall(pos, mySize);
3753 else if(gametype == GAME_CTS || gametype == GAME_RACE)
3754 HUD_Mod_Race(pos, mySize);
3755 else if(gametype == GAME_CA || gametype == GAME_FREEZETAG)
3756 HUD_Mod_CA(pos, mySize);
3757 else if(gametype == GAME_DOMINATION)
3758 HUD_Mod_Dom(pos, mySize);
3759 else if(gametype == GAME_KEEPAWAY)
3760 HUD_Mod_Keepaway(pos, mySize);
3763 // Draw pressed keys (#11)
3765 void HUD_DrawPressedKeys(void)
3767 if(!autocvar__hud_configure)
3769 if(!autocvar_hud_panel_pressedkeys) return;
3770 if(spectatee_status <= 0 && autocvar_hud_panel_pressedkeys < 2) return;
3773 hud_configure_active_panel = HUD_PANEL_PRESSEDKEYS;
3776 HUD_Panel_UpdateCvars(pressedkeys);
3777 HUD_Panel_ApplyFadeAlpha();
3780 mySize = panel_size;
3782 HUD_Panel_DrawBg(1);
3783 if(panel_bg_padding)
3785 pos += '1 1 0' * panel_bg_padding;
3786 mySize -= '2 2 0' * panel_bg_padding;
3789 // force custom aspect
3790 float aspect = autocvar_hud_panel_pressedkeys_aspect;
3794 if(mySize_x/mySize_y > aspect)
3796 newSize_x = aspect * mySize_y;
3797 newSize_y = mySize_y;
3799 pos_x = pos_x + (mySize_x - newSize_x) / 2;
3803 newSize_y = 1/aspect * mySize_x;
3804 newSize_x = mySize_x;
3806 pos_y = pos_y + (mySize_y - newSize_y) / 2;
3812 keysize = eX * mySize_x * (1/3) + eY * mySize_y * 0.5;
3814 pressedkeys = getstatf(STAT_PRESSED_KEYS);
3816 drawpic_aspect_skin(pos, ((pressedkeys & KEY_CROUCH) ? "key_crouch_inv.tga" : "key_crouch.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3817 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);
3818 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);
3820 drawpic_aspect_skin(pos, ((pressedkeys & KEY_LEFT) ? "key_left_inv.tga" : "key_left.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3821 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);
3822 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);
3825 // Handle chat as a panel (#12)
3829 if(!autocvar__hud_configure)
3831 if (!autocvar_hud_panel_chat)
3833 if (!autocvar_con_chatrect)
3834 cvar_set("con_chatrect", "0");
3839 hud_configure_active_panel = HUD_PANEL_CHAT;
3841 HUD_Panel_UpdateCvars(chat);
3842 HUD_Panel_ApplyFadeAlpha();
3844 if(autocvar__con_chat_maximized && !autocvar__hud_configure) // draw at full screen height if maximized
3846 panel_pos_y = panel_bg_border;
3847 panel_size_y = vid_conheight - panel_bg_border * 2;
3848 if(panel_bg == "0") // force a border when maximized
3850 if(precache_pic(panel_bg) == "") {
3851 panel_bg = strcat(hud_skin_path, "/border_default");
3852 if(precache_pic(panel_bg) == "") {
3853 panel_bg = "gfx/hud/default/border_default";
3857 panel_bg_alpha = max(0.75, panel_bg_alpha); // force an alpha of at least 0.75
3862 mySize = panel_size;
3864 HUD_Panel_DrawBg(1);
3866 if(panel_bg_padding)
3868 pos += '1 1 0' * panel_bg_padding;
3869 mySize -= '2 2 0' * panel_bg_padding;
3872 if (!autocvar_con_chatrect)
3873 cvar_set("con_chatrect", "1");
3875 cvar_set("con_chatrect_x", ftos(pos_x/vid_conwidth));
3876 cvar_set("con_chatrect_y", ftos(pos_y/vid_conheight));
3878 cvar_set("con_chatwidth", ftos(mySize_x/vid_conwidth));
3879 cvar_set("con_chat", ftos(floor(mySize_y/autocvar_con_chatsize - 0.5)));
3881 if(autocvar__hud_configure)
3884 chatsize = '1 1 0' * autocvar_con_chatsize;
3885 cvar_set("con_chatrect_x", "9001"); // over 9000, we'll fake it instead for more control over alpha and such
3887 for(i = 0; i < autocvar_con_chat; ++i)
3889 if(i == autocvar_con_chat - 1)
3892 a = panel_fg_alpha * floor(((i + 1) * 7 + autocvar_con_chattime)/45);
3893 drawcolorcodedstring(pos, textShortenToWidth(_("^3Player^7: This is the chat area."), mySize_x, chatsize, stringwidth_colors), chatsize, a, DRAWFLAG_NORMAL);
3894 pos_y += chatsize_y;
3899 // Engine info panel (#13)
3906 float frametimeavg1; // 1 frame ago
3907 float frametimeavg2; // 2 frames ago
3908 void HUD_EngineInfo(void)
3910 if(!autocvar__hud_configure)
3912 if(!autocvar_hud_panel_engineinfo) return;
3915 hud_configure_active_panel = HUD_PANEL_ENGINEINFO;
3917 HUD_Panel_UpdateCvars(engineinfo);
3918 HUD_Panel_ApplyFadeAlpha();
3921 mySize = panel_size;
3923 HUD_Panel_DrawBg(1);
3924 if(panel_bg_padding)
3926 pos += '1 1 0' * panel_bg_padding;
3927 mySize -= '2 2 0' * panel_bg_padding;
3930 float currentTime = gettime(GETTIME_REALTIME);
3931 if(cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage"))
3933 float currentframetime = currentTime - prevfps_time;
3934 frametimeavg = (frametimeavg + frametimeavg1 + frametimeavg2 + currentframetime)/4; // average three frametimes into framecounter for slightly more stable fps readings :P
3935 frametimeavg2 = frametimeavg1;
3936 frametimeavg1 = frametimeavg;
3939 weight = cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage_new_weight");
3940 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.
3942 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
3943 prevfps = (1/currentframetime);
3944 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"
3946 prevfps_time = currentTime;
3951 if(currentTime - prevfps_time > autocvar_hud_panel_engineinfo_framecounter_time)
3953 prevfps = framecounter/(currentTime - prevfps_time);
3955 prevfps_time = currentTime;
3960 color = HUD_Get_Num_Color (prevfps, 100);
3961 drawstring_aspect(pos, sprintf(_("FPS: %.*f"), autocvar_hud_panel_engineinfo_framecounter_decimals, prevfps), mySize, color, panel_fg_alpha, DRAWFLAG_NORMAL);
3964 // Info messages panel (#14)
3966 #define drawInfoMessage(s)\
3967 if(autocvar_hud_panel_infomessages_flip)\
3968 o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize);\
3969 drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);\
3971 void HUD_InfoMessages(void)
3973 if(!autocvar__hud_configure)
3975 if(!autocvar_hud_panel_infomessages) return;
3978 hud_configure_active_panel = HUD_PANEL_INFOMESSAGES;
3980 HUD_Panel_UpdateCvars(infomessages);
3981 HUD_Panel_ApplyFadeAlpha();
3984 mySize = panel_size;
3986 HUD_Panel_DrawBg(1);
3987 if(panel_bg_padding)
3989 pos += '1 1 0' * panel_bg_padding;
3990 mySize -= '2 2 0' * panel_bg_padding;
3993 // always force 5:1 aspect
3995 if(mySize_x/mySize_y > 5)
3997 newSize_x = 5 * mySize_y;
3998 newSize_y = mySize_y;
4000 pos_x = pos_x + (mySize_x - newSize_x) / 2;
4004 newSize_y = 1/5 * mySize_x;
4005 newSize_x = mySize_x;
4007 pos_y = pos_y + (mySize_y - newSize_y) / 2;
4016 fontsize = '0.20 0.20 0' * mySize_y;
4022 if(!autocvar__hud_configure)
4024 if(spectatee_status && !intermission)
4027 if(spectatee_status == -1)
4028 s = _("^1Observing");
4030 s = sprintf(_("^1Spectating: ^7%s"), GetPlayerName(spectatee_status - 1));
4033 if(spectatee_status == -1)
4034 s = sprintf(_("^1Press ^3%s^1 to spectate"), getcommandkey("primary fire", "+fire"));
4036 s = sprintf(_("^1Press ^3%s^1 for another player"), getcommandkey("primary fire", "+fire"));
4039 if(spectatee_status == -1)
4040 s = sprintf(_("^1Use ^3%s^1 or ^3%s^1 to change the speed"), getcommandkey("next weapon", "weapnext"), getcommandkey("previous weapon", "weapprev"));
4042 s = sprintf(_("^1Press ^3%s^1 to observe"), getcommandkey("secondary fire", "+fire2"));
4045 s = sprintf(_("^1Press ^3%s^1 for gamemode info"), getcommandkey("server info", "+show_info"));
4048 if(gametype == GAME_ARENA)
4049 s = _("^1Wait for your turn to join");
4050 else if(gametype == GAME_LMS)
4053 sk = playerslots[player_localentnum - 1];
4054 if(sk.(scores[ps_primary]) >= 666)
4055 s = _("^1Match has already begun");
4056 else if(sk.(scores[ps_primary]) > 0)
4057 s = _("^1You have no more lives left");
4059 s = sprintf(_("^1Press ^3%s^1 to join"), getcommandkey("jump", "+jump"));
4062 s = sprintf(_("^1Press ^3%s^1 to join"), getcommandkey("jump", "+jump"));
4065 //show restart countdown:
4066 if (time < getstatf(STAT_GAMESTARTTIME)) {
4068 //we need to ceil, otherwise the countdown would be off by .5 when using round()
4069 countdown = ceil(getstatf(STAT_GAMESTARTTIME) - time);
4070 s = sprintf(_("^1Game starts in ^3%d^1 seconds"), countdown);
4071 drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
4075 if(warmup_stage && !intermission)
4077 s = _("^2Currently in ^1warmup^2 stage!");
4082 if(mod(time, 1) >= 0.5)
4087 if(ready_waiting && !intermission && !spectatee_status)
4089 if(ready_waiting_for_me)
4092 s = sprintf(_("%sPress ^3%s%s to end warmup"), blinkcolor, getcommandkey("ready", "ready"), blinkcolor);
4094 s = sprintf(_("%sPress ^3%s%s once you are ready"), blinkcolor, getcommandkey("ready", "ready"), blinkcolor);
4099 s = _("^2Waiting for others to ready up to end warmup...");
4101 s = _("^2Waiting for others to ready up...");
4105 else if(warmup_stage && !intermission && !spectatee_status)
4107 s = sprintf(_("^2Press ^3%s^2 to end warmup"), getcommandkey("ready", "ready"));
4111 if(teamplay && !intermission && !spectatee_status && gametype != GAME_CA && teamnagger)
4113 float ts_min, ts_max;
4114 tm = teams.sort_next;
4117 for(; tm.sort_next; tm = tm.sort_next)
4119 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
4121 if(!ts_min) ts_min = tm.team_size;
4122 else ts_min = min(ts_min, tm.team_size);
4123 if(!ts_max) ts_max = tm.team_size;
4124 else ts_max = max(ts_max, tm.team_size);
4126 if ((ts_max - ts_min) > 1)
4128 s = strcat(blinkcolor, _("Teamnumbers are unbalanced!"));
4129 tm = GetTeam(myteam, false);
4131 if (tm.team != COLOR_SPECTATOR)
4132 if (tm.team_size == ts_max)
4133 s = strcat(s, sprintf(_(" Press ^3%s%s to adjust"), getcommandkey("team menu", "menu_showteamselect"), blinkcolor));
4141 s = _("^7Press ^3ESC ^7to show HUD options.");
4143 s = _("^3Doubleclick ^7a panel for panel-specific options.");
4145 s = _("^3CTRL ^7to disable collision testing, ^3SHIFT ^7and");
4147 s = _("^3ALT ^7+ ^3ARROW KEYS ^7for fine adjustments.");
4152 // Physics panel (#15)
4154 vector acc_prevspeed;
4155 float acc_prevtime, acc_avg, top_speed, top_speed_time;
4156 void HUD_Physics(void)
4158 if(!autocvar__hud_configure)
4160 if(!autocvar_hud_panel_physics) return;
4161 if(spectatee_status == -1 && (autocvar_hud_panel_physics == 1 || autocvar_hud_panel_physics == 3)) return;
4162 if(autocvar_hud_panel_physics == 3 && !(gametype == GAME_RACE || gametype == GAME_CTS)) return;
4165 hud_configure_active_panel = HUD_PANEL_PHYSICS;
4167 HUD_Panel_UpdateCvars(physics);
4168 HUD_Panel_ApplyFadeAlpha();
4170 HUD_Panel_DrawBg(1);
4171 if(panel_bg_padding)
4173 panel_pos += '1 1 0' * panel_bg_padding;
4174 panel_size -= '2 2 0' * panel_bg_padding;
4178 float speed, conversion_factor;
4181 switch(autocvar_hud_panel_physics_speed_unit)
4186 conversion_factor = 1.0;
4190 conversion_factor = 0.0254;
4194 conversion_factor = 0.0254 * 3.6;
4198 conversion_factor = 0.0254 * 3.6 * 0.6213711922;
4202 conversion_factor = 0.0254 * 1.943844492; // 1 m/s = 1.943844492 knots, because 1 knot = 1.852 km/h
4206 float max_speed = floor( autocvar_hud_panel_physics_speed_max * conversion_factor + 0.5 );
4207 if (autocvar__hud_configure)
4208 speed = floor( max_speed * 0.65 + 0.5 );
4209 else if(autocvar_hud_panel_physics_speed_vertical)
4210 speed = floor( vlen(pmove_vel) * conversion_factor + 0.5 );
4212 speed = floor( vlen(pmove_vel - pmove_vel_z * '0 0 1') * conversion_factor + 0.5 );
4214 //compute acceleration
4215 float acceleration, f;
4216 if (autocvar__hud_configure)
4217 acceleration = autocvar_hud_panel_physics_acceleration_max * 0.3;
4220 // 1 m/s = 0.0254 qu/s; 1 g = 9.80665 m/s^2
4221 f = time - acc_prevtime;
4222 if(autocvar_hud_panel_physics_acceleration_vertical)
4223 acceleration = (vlen(pmove_vel) - vlen(acc_prevspeed)) * (1 / f) * (0.0254 / 9.80665);
4225 acceleration = (vlen(pmove_vel - '0 0 1' * pmove_vel_z) - vlen(acc_prevspeed - '0 0 1' * acc_prevspeed_z)) * (1 / f) * (0.0254 / 9.80665);
4226 acc_prevspeed = pmove_vel;
4227 acc_prevtime = time;
4229 f = bound(0, f * 10, 1);
4230 acc_avg = acc_avg * (1 - f) + acceleration * f;
4234 float panel_ar = panel_size_x/panel_size_y;
4235 vector speed_offset, acceleration_offset;
4238 panel_size_x *= 0.5;
4239 if (autocvar_hud_panel_physics_flip)
4240 speed_offset_x = panel_size_x;
4242 acceleration_offset_x = panel_size_x;
4246 panel_size_y *= 0.5;
4247 if (autocvar_hud_panel_physics_flip)
4248 speed_offset_y = panel_size_y;
4250 acceleration_offset_y = panel_size_y;
4252 float speed_baralign, acceleration_baralign;
4253 if (autocvar_hud_panel_physics_baralign == 1)
4254 acceleration_baralign = speed_baralign = 1;
4255 else if(autocvar_hud_panel_physics_baralign == 4)
4256 acceleration_baralign = speed_baralign = 2;
4257 else if (autocvar_hud_panel_physics_flip)
4259 acceleration_baralign = (autocvar_hud_panel_physics_baralign == 2);
4260 speed_baralign = (autocvar_hud_panel_physics_baralign == 3);
4264 speed_baralign = (autocvar_hud_panel_physics_baralign == 2);
4265 acceleration_baralign = (autocvar_hud_panel_physics_baralign == 3);
4267 if (autocvar_hud_panel_physics_acceleration_progressbar_mode == 0)
4268 acceleration_baralign = 3; //override hud_panel_physics_baralign value for acceleration
4272 if(autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 2)
4274 HUD_Panel_GetProgressBarColor(speed);
4275 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);
4277 vector tmp_offset, tmp_size;
4278 if (autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 2)
4280 tmp_size_x = panel_size_x * 0.75;
4281 tmp_size_y = panel_size_y;
4283 tmp_offset_x = panel_size_x - tmp_size_x;
4286 drawstring_aspect(panel_pos + speed_offset + tmp_offset, ftos(speed), tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4292 tmp_offset_x = tmp_size_x;
4293 if (autocvar_hud_panel_physics_speed_unit_show)
4296 tmp_size_x = panel_size_x * (1 - 0.75);
4297 tmp_size_y = panel_size_y * 0.4;
4298 drawstring_aspect(panel_pos + speed_offset + tmp_offset, unit, tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4302 //compute and draw top speed
4303 if (autocvar_hud_panel_physics_topspeed)
4304 if (autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 2)
4306 if (autocvar__hud_configure)
4308 top_speed = floor( max_speed * 0.75 + 0.5 );
4313 if (speed >= top_speed)
4316 top_speed_time = time;
4320 f = max(1, autocvar_hud_panel_physics_topspeed_time);
4321 // divide by f to make it start from 1
4322 f = cos( ((time - top_speed_time) / f) * PI/2 );
4324 else //hide top speed 0, it would be stupid
4329 //top speed progressbar peak
4330 if(speed < top_speed)
4331 if(autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 2)
4333 float peak_offset_x;
4335 if (speed_baralign == 0)
4336 peak_offset_x = min(top_speed, max_speed)/max_speed * panel_size_x;
4337 else if (speed_baralign == 1)
4338 peak_offset_x = (1 - min(top_speed, max_speed)/max_speed) * panel_size_x;
4339 else if (speed_baralign == 2)
4340 peak_offset_x = min(top_speed, max_speed)/max_speed * panel_size_x * 0.5;
4341 //if speed is not 0 the speed progressbar already fetched the color
4343 HUD_Panel_GetProgressBarColor(speed);
4344 peak_size_x = floor(panel_size_x * 0.01 + 1.5);
4345 peak_size_y = panel_size_y;
4346 if (speed_baralign == 2) // draw two peaks, on both sides
4348 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);
4349 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);
4352 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);
4356 tmp_offset_y = panel_size_y * 0.4;
4357 tmp_size_x = panel_size_x * (1 - 0.75);
4358 tmp_size_y = panel_size_y - tmp_offset_y;
4359 drawstring_aspect(panel_pos + speed_offset + tmp_offset, ftos(top_speed), tmp_size, '1 0 0', f * panel_fg_alpha, DRAWFLAG_NORMAL);
4367 if(autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 3)
4369 if (acceleration < 0)
4370 HUD_Panel_GetProgressBarColor(acceleration_neg);
4372 HUD_Panel_GetProgressBarColor(acceleration);
4373 HUD_Panel_DrawProgressBar(panel_pos + acceleration_offset, panel_size, "accelbar", acceleration/autocvar_hud_panel_physics_acceleration_max, 0, acceleration_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
4375 if (autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 3)
4376 drawstring_aspect(panel_pos + acceleration_offset, strcat(ftos_decimals(acceleration, 2), "g"), panel_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4379 // CenterPrint (#16)
4381 #define CENTERPRINT_MAX_MSGS 10
4382 #define CENTERPRINT_MAX_ENTRIES 50
4383 #define CENTERPRINT_SPACING 0.7
4385 string centerprint_messages[CENTERPRINT_MAX_MSGS];
4386 float centerprint_msgID[CENTERPRINT_MAX_MSGS];
4387 float centerprint_time[CENTERPRINT_MAX_MSGS];
4388 float centerprint_expire_time[CENTERPRINT_MAX_MSGS];
4389 float centerprint_countdown_num[CENTERPRINT_MAX_MSGS];
4390 float centerprint_fadetime;
4391 float centerprint_showing;
4393 void centerprint_generic(float new_id, string strMessage, float duration, float countdown_num)
4397 if(strMessage == "" && new_id == 0)
4400 // strip trailing newlines
4401 j = strlen(strMessage) - 1;
4402 while(substring(strMessage, j, 1) == "\n" && j >= 0)
4404 if (j < strlen(strMessage) - 1)
4405 strMessage = substring(strMessage, 0, j + 1);
4407 if(strMessage == "" && new_id == 0)
4410 // strip leading newlines
4412 while(substring(strMessage, j, 1) == "\n" && j < strlen(strMessage))
4415 strMessage = substring(strMessage, j, strlen(strMessage) - j);
4417 if(strMessage == "" && new_id == 0)
4420 if (!centerprint_showing)
4421 centerprint_showing = TRUE;
4423 centerprint_fadetime = bound(0, autocvar_hud_panel_centerprint_fadetime, 1);
4425 for (i=0, j=cpm_index; i<CENTERPRINT_MAX_MSGS; ++i, ++j)
4427 if (j == CENTERPRINT_MAX_MSGS)
4429 if (new_id && new_id == centerprint_msgID[j])
4431 if (strMessage == "" && centerprint_messages[j] != "" && centerprint_countdown_num[j] == 0)
4433 // fade out the current msg (duration and countdown_num are ignored)
4434 centerprint_time[j] = centerprint_fadetime;
4435 if (centerprint_expire_time[j] > time + centerprint_fadetime || centerprint_expire_time[j] < time)
4436 centerprint_expire_time[j] = time + centerprint_fadetime;
4439 break; // found a msg with the same id, at position j
4443 if (i == CENTERPRINT_MAX_MSGS)
4445 // a msg with the same id was not found, add the msg at the next position
4447 if (cpm_index == -1)
4448 cpm_index = CENTERPRINT_MAX_MSGS - 1;
4451 if(centerprint_messages[j])
4452 strunzone(centerprint_messages[j]);
4453 centerprint_messages[j] = strzone(strMessage);
4454 centerprint_msgID[j] = new_id;
4456 centerprint_time[j] = -1;
4460 duration = max(1, autocvar_hud_panel_centerprint_time);
4461 centerprint_time[j] = duration;
4462 centerprint_expire_time[j] = time + duration;
4464 centerprint_countdown_num[j] = countdown_num;
4467 void centerprint(string strMessage)
4469 centerprint_generic(0, strMessage, autocvar_hud_panel_centerprint_time, 0);
4472 void reset_centerprint_messages(void)
4475 for (i=0; i<CENTERPRINT_MAX_MSGS; ++i)
4477 centerprint_expire_time[i] = 0;
4478 centerprint_time[i] = 1;
4479 centerprint_msgID[i] = 0;
4480 if(centerprint_messages[i])
4481 strunzone(centerprint_messages[i]);
4482 centerprint_messages[i] = string_null;
4485 float hud_configure_cp_generation_time;
4486 void HUD_CenterPrint (void)
4488 if(!autocvar__hud_configure)
4490 if(!autocvar_hud_panel_centerprint) return;
4492 if (hud_configure_prev && hud_configure_prev != -1)
4493 reset_centerprint_messages();
4497 hud_configure_active_panel = HUD_PANEL_CENTERPRINT;
4499 if (!hud_configure_prev)
4500 reset_centerprint_messages();
4501 if (time > hud_configure_cp_generation_time)
4506 centerprint_generic(floor(r*1000), strcat(sprintf("^3Countdown message at time %s", seconds_tostring(time)), ", seconds left: %d"), 1, 10);
4508 centerprint_generic(0, sprintf("^1Multiline message at time %s that\n^1lasts longer than normal", seconds_tostring(time)), 20, 0);
4510 centerprint(sprintf("Message at time %s", seconds_tostring(time)));
4511 hud_configure_cp_generation_time = time + 1 + random()*4;
4515 HUD_Panel_UpdateCvars(centerprint);
4517 // this panel doesn't fade when showing the scoreboard
4518 if(autocvar__menu_alpha)
4519 HUD_Panel_ApplyFadeAlpha();
4521 if(scoreboard_fade_alpha)
4523 // move the panel below the scoreboard
4524 if (scoreboard_bottom >= 0.96 * vid_conheight)
4527 target_pos = eY * scoreboard_bottom + eX * 0.5 * (vid_conwidth - panel_size_x);
4528 panel_pos = panel_pos + (target_pos - panel_pos) * sqrt(scoreboard_fade_alpha);
4529 panel_size_y = min(panel_size_y, vid_conheight - scoreboard_bottom);
4532 HUD_Panel_DrawBg(1);
4534 if (!centerprint_showing)
4537 if(panel_bg_padding)
4539 panel_pos += '1 1 0' * panel_bg_padding;
4540 panel_size -= '2 2 0' * panel_bg_padding;
4543 float entries, height;
4545 // entries = bound(1, floor(CENTERPRINT_MAX_ENTRIES * 4 * panel_size_y/panel_size_x), CENTERPRINT_MAX_ENTRIES);
4546 // height = panel_size_y/entries;
4547 // fontsize = '1 1 0' * height;
4548 height = vid_conheight/50 * autocvar_hud_panel_centerprint_fontscale;
4549 fontsize = '1 1 0' * height;
4550 entries = bound(1, floor(panel_size_y/height), CENTERPRINT_MAX_ENTRIES);
4553 float a, sz, align, current_msg_pos_y, msg_size;
4557 n = -1; // if no msg will be displayed, n stays -1
4560 if (autocvar_hud_panel_centerprint_flip)
4561 pos_y += panel_size_y;
4562 align = bound(0, autocvar_hud_panel_centerprint_align, 1);
4563 for (i=0, j=cpm_index; i<CENTERPRINT_MAX_MSGS; ++i, ++j)
4565 if (j == CENTERPRINT_MAX_MSGS)
4567 if (centerprint_expire_time[j] < time)
4569 if (centerprint_countdown_num[j] && centerprint_time[j] > 0)
4571 centerprint_countdown_num[j] = centerprint_countdown_num[j] - 1;
4572 if (centerprint_countdown_num[j] == 0)
4574 centerprint_expire_time[j] = centerprint_expire_time[j] + centerprint_time[j];
4579 if (centerprint_time[j] < 0 || centerprint_expire_time[j] - centerprint_fadetime > time)
4581 a = bound(0, (time - (centerprint_expire_time[j] - centerprint_time[j])) / centerprint_fadetime, 1);
4582 sz = 0.8 + a * (1 - 0.8);
4584 else if (centerprint_expire_time[j] > time)
4586 a = (centerprint_expire_time[j] - time) / centerprint_fadetime;
4587 sz = 0.8 + a * (1 - 0.8);
4590 drawfontscale = sz * '1 1 0';
4591 if (centerprint_countdown_num[j])
4592 n = tokenizebyseparator(sprintf(centerprint_messages[j], centerprint_countdown_num[j]), "\n");
4594 n = tokenizebyseparator(centerprint_messages[j], "\n");
4595 if (autocvar_hud_panel_centerprint_flip)
4597 // check if the message can be entirely shown
4598 for(k = 0; k < n; ++k)
4600 getWrappedLine_remaining = argv(k);
4601 while(getWrappedLine_remaining)
4603 ts = getWrappedLine(panel_size_x * sz, fontsize, stringwidth_colors);
4605 pos_y -= fontsize_y;
4607 pos_y -= fontsize_y * CENTERPRINT_SPACING/2;
4608 if (pos_y < panel_pos_y) // check if the next line can be shown
4610 drawfontscale = '1 1 0';
4615 current_msg_pos_y = pos_y; // save starting pos (first line) of the current message
4619 for(k = 0; k < n; ++k)
4621 getWrappedLine_remaining = argv(k);
4622 while(getWrappedLine_remaining)
4624 ts = getWrappedLine(panel_size_x * sz, fontsize, stringwidth_colors);
4628 pos_x = panel_pos_x + (panel_size_x - stringwidth(ts, TRUE, fontsize)) * align;
4629 drawcolorcodedstring(pos + eY * 0.5 * (1 - sz) * fontsize_y, ts, fontsize, a * panel_fg_alpha, DRAWFLAG_NORMAL);
4630 pos_y += fontsize_y;
4633 pos_y += fontsize_y * CENTERPRINT_SPACING/2;
4634 if (!autocvar_hud_panel_centerprint_flip && pos_y > panel_pos_y + panel_size_y - fontsize_y) // check if the next line can be shown
4636 drawfontscale = '1 1 0';
4641 msg_size = pos_y - msg_size;
4642 if (autocvar_hud_panel_centerprint_flip)
4644 pos_y = current_msg_pos_y - CENTERPRINT_SPACING * fontsize_y;
4645 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
4646 pos_y += (msg_size + CENTERPRINT_SPACING * fontsize_y) * (1 - sqrt(a));
4650 pos_y += CENTERPRINT_SPACING * fontsize_y;
4651 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
4652 pos_y -= (msg_size + CENTERPRINT_SPACING * fontsize_y) * (1 - sqrt(a));
4655 drawfontscale = '1 1 0';
4658 centerprint_showing = FALSE;
4659 reset_centerprint_messages();
4669 void HUD_Reset (void)
4671 // reset gametype specific icons
4672 if(gametype == GAME_KEYHUNT)
4674 else if(gametype == GAME_CTF)
4675 HUD_Mod_CTF_Reset();
4678 #define HUD_DrawPanel(id)\
4680 case (HUD_PANEL_RADAR):\
4681 HUD_Radar(); break;\
4682 case (HUD_PANEL_WEAPONS):\
4683 HUD_Weapons(); break;\
4684 case (HUD_PANEL_AMMO):\
4686 case (HUD_PANEL_POWERUPS):\
4687 HUD_Powerups(); break;\
4688 case (HUD_PANEL_HEALTHARMOR):\
4689 HUD_HealthArmor(); break;\
4690 case (HUD_PANEL_NOTIFY):\
4691 HUD_Notify(); break;\
4692 case (HUD_PANEL_TIMER):\
4693 HUD_Timer(); break;\
4694 case (HUD_PANEL_SCORE):\
4695 HUD_Score(); break;\
4696 case (HUD_PANEL_RACETIMER):\
4697 HUD_RaceTimer(); break;\
4698 case (HUD_PANEL_VOTE):\
4699 HUD_VoteWindow(); break;\
4700 case (HUD_PANEL_MODICONS):\
4701 HUD_ModIcons(); break;\
4702 case (HUD_PANEL_PRESSEDKEYS):\
4703 HUD_DrawPressedKeys(); break;\
4704 case (HUD_PANEL_CHAT):\
4706 case (HUD_PANEL_ENGINEINFO):\
4707 HUD_EngineInfo(); break;\
4708 case (HUD_PANEL_INFOMESSAGES):\
4709 HUD_InfoMessages(); break;\
4710 case (HUD_PANEL_PHYSICS):\
4711 HUD_Physics(); break;\
4712 case (HUD_PANEL_CENTERPRINT):\
4713 HUD_CenterPrint(); break;\
4714 } ENDS_WITH_CURLY_BRACE
4716 void HUD_Main (void)
4719 // global hud alpha fade
4720 if(menu_enabled == 1)
4723 hud_fade_alpha = (1 - autocvar__menu_alpha);
4725 if(scoreboard_fade_alpha)
4726 hud_fade_alpha = (1 - scoreboard_fade_alpha);
4728 if(intermission == 2) // no hud during mapvote
4730 if (autocvar__hud_configure) //force exit from hud config
4735 localcmd("togglemenu\n");
4737 cvar_set("_hud_configure", "0");
4741 else if(autocvar__menu_alpha == 0 && scoreboard_fade_alpha == 0)
4744 // panels that we want to be active together with the scoreboard
4745 // they must call HUD_Panel_ApplyFadeAlpha(); only when showing the menu
4746 if(scoreboard_fade_alpha == 1)
4752 if(!autocvar__hud_configure && !hud_fade_alpha)
4756 if (hud_skin_path != autocvar_hud_skin)
4759 strunzone(hud_skin_path);
4760 hud_skin_path = strzone(strcat("gfx/hud/", autocvar_hud_skin));
4763 // HUD configure visible grid
4764 if(autocvar__hud_configure && autocvar_hud_configure_grid && autocvar_hud_configure_grid_alpha)
4766 hud_configure_gridSize_x = bound(0.005, cvar("hud_configure_grid_xsize"), 0.2);
4767 hud_configure_gridSize_y = bound(0.005, cvar("hud_configure_grid_ysize"), 0.2);
4768 hud_configure_realGridSize_x = hud_configure_gridSize_x * vid_conwidth;
4769 hud_configure_realGridSize_y = hud_configure_gridSize_y * vid_conheight;
4771 for(i = 0; i < 1/hud_configure_gridSize_x; ++i)
4772 drawfill(eX * i * hud_configure_realGridSize_x, eX + eY * vid_conheight, '0.5 0.5 0.5', autocvar_hud_configure_grid_alpha, DRAWFLAG_NORMAL);
4774 for(i = 0; i < 1/hud_configure_gridSize_y; ++i)
4775 drawfill(eY * i * hud_configure_realGridSize_y, eY + eX * vid_conwidth, '0.5 0.5 0.5', autocvar_hud_configure_grid_alpha, DRAWFLAG_NORMAL);
4778 current_player = (spectatee_status > 0) ? spectatee_status : player_localentnum;
4781 if(autocvar_hud_dock != "" && autocvar_hud_dock != "0")
4785 float hud_dock_color_team = autocvar_hud_dock_color_team;
4786 if((teamplay) && hud_dock_color_team) {
4787 f = stof(getplayerkey(current_player - 1, "colors"));
4788 color = colormapPaletteColor(mod(f, 16), 1) * hud_dock_color_team;
4790 else if(autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && hud_dock_color_team) {
4791 color = '1 0 0' * hud_dock_color_team;
4795 string hud_dock_color = autocvar_hud_dock_color;
4796 if(hud_dock_color == "shirt") {
4797 f = stof(getplayerkey(current_player - 1, "colors"));
4798 color = colormapPaletteColor(floor(f / 16), 0);
4800 else if(hud_dock_color == "pants") {
4801 f = stof(getplayerkey(current_player - 1, "colors"));
4802 color = colormapPaletteColor(mod(f, 16), 1);
4805 color = stov(hud_dock_color);
4809 pic = strcat(hud_skin_path, "/", autocvar_hud_dock);
4810 if(precache_pic(pic) == "") {
4811 pic = strcat(hud_skin_path, "/dock_medium");
4812 if(precache_pic(pic) == "") {
4813 pic = "gfx/hud/default/dock_medium";
4816 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...
4819 // cache the panel order into the panel_order array
4820 if(autocvar__hud_panelorder != hud_panelorder_prev) {
4821 for(i = 0; i < HUD_PANEL_NUM; ++i)
4822 panel_order[i] = -1;
4824 float p_num, warning;
4825 float argc = tokenize_console(autocvar__hud_panelorder);
4826 if (argc > HUD_PANEL_NUM)
4828 //first detect wrong/missing panel numbers
4829 for(i = 0; i < HUD_PANEL_NUM; ++i) {
4830 p_num = stof(argv(i));
4831 if (p_num >= 0 && p_num < HUD_PANEL_NUM) { //correct panel number?
4832 if (panel_order[p_num] == -1) //found for the first time?
4833 s = strcat(s, ftos(p_num), " ");
4834 panel_order[p_num] = 1; //mark as found
4839 for(i = 0; i < HUD_PANEL_NUM; ++i) {
4840 if (panel_order[i] == -1) {
4842 s = strcat(s, ftos(i), " "); //add missing panel number
4846 print(_("Automatically fixed wrong/missing panel numbers in _hud_panelorder\n"));
4848 cvar_set("_hud_panelorder", s);
4849 if(hud_panelorder_prev)
4850 strunzone(hud_panelorder_prev);
4851 hud_panelorder_prev = strzone(s);
4853 //now properly set panel_order
4854 tokenize_console(s);
4855 for(i = 0; i < HUD_PANEL_NUM; ++i) {
4856 panel_order[i] = stof(argv(i));
4860 // draw panels in order specified by panel_order array
4861 for(i = HUD_PANEL_NUM - 1; i >= 0; --i) {
4862 if(i != HUD_PANEL_CHAT || !autocvar__con_chat_maximized) // don't draw maximized chat panel twice!
4863 HUD_DrawPanel(panel_order[i]);
4866 // draw chat panel on top if it is maximized
4867 if(autocvar__con_chat_maximized)
4868 HUD_Chat(); // HUD_DrawPanel(HUD_PANEL_CHAT);
4870 if(autocvar__hud_configure)
4874 HUD_Panel_UpdatePosSizeForId(tab_panel)
4875 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .2, DRAWFLAG_NORMAL);
4877 if(highlightedPanel != -1)
4879 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
4880 HUD_Panel_HlBorder(panel_bg_border + 1.5 * hlBorderSize, '0 0.5 1', 0.25 * (1 - autocvar__menu_alpha));
4884 hud_configure_prev = autocvar__hud_configure;
4886 if (!autocvar__hud_configure) // hud config mode disabled, enable normal alpha stuff again