2 #include "../dpdefs/csprogsdefs.qh"
4 #include "../common/constants.qh"
5 #include "../common/stats.qh"
6 #include "../warpzonelib/mathlib.qh"
7 #include "../common/teams.qh"
8 #include "../common/util.qh"
9 #include "../common/nades.qh"
10 #include "../common/buffs.qh"
11 #include "../common/counting.qh"
12 #include "../common/weapons/weapons.qh"
13 #include "../common/mapinfo.qh"
14 #include "autocvars.qh"
15 #include "../common/deathtypes.qh"
16 #include "teamradar.qh"
18 #include "scoreboard.qh"
20 #include "../csqcmodellib/cl_player.qh"
21 #include "../server/t_items.qh"
32 // a border picture is a texture containing nine parts:
33 // 1/4 width: left part
34 // 1/2 width: middle part (stretched)
35 // 1/4 width: right part
37 // 1/4 height: top part
38 // 1/2 height: middle part (stretched)
39 // 1/4 height: bottom part
40 void draw_BorderPicture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha, vector theBorderSize)
42 if (theBorderSize.x < 0 && theBorderSize.y < 0) // draw whole image as it is
44 drawpic(theOrigin, pic, theSize, theColor, theAlpha, 0);
47 if (theBorderSize_x == 0 && theBorderSize_y == 0) // no border
49 // draw only the central part
50 drawsubpic(theOrigin, theSize, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0);
57 //pic = draw_UseSkinFor(pic);
58 width = eX * theSize.x;
59 height = eY * theSize.y;
60 if(theSize.x <= theBorderSize.x * 2)
62 // not wide enough... draw just left and right then
63 bW = eX * (0.25 * theSize.x / (theBorderSize.x * 2));
64 if(theSize.y <= theBorderSize.y * 2)
66 // not high enough... draw just corners
67 bH = eY * (0.25 * theSize.y / (theBorderSize.y * 2));
68 drawsubpic(theOrigin, width * 0.5 + height * 0.5, pic, '0 0 0', bW + bH, theColor, theAlpha, 0);
69 drawsubpic(theOrigin + width * 0.5, width * 0.5 + height * 0.5, pic, eX - bW, bW + bH, theColor, theAlpha, 0);
70 drawsubpic(theOrigin + height * 0.5, width * 0.5 + height * 0.5, pic, eY - bH, bW + bH, theColor, theAlpha, 0);
71 drawsubpic(theOrigin + theSize * 0.5, width * 0.5 + height * 0.5, pic, eX + eY - bW - bH, bW + bH, theColor, theAlpha, 0);
75 dY = theBorderSize.x * eY;
76 drawsubpic(theOrigin, width * 0.5 + dY, pic, '0 0 0', '0 0.25 0' + bW, theColor, theAlpha, 0);
77 drawsubpic(theOrigin + width * 0.5, width * 0.5 + dY, pic, '0 0 0' + eX - bW, '0 0.25 0' + bW, theColor, theAlpha, 0);
78 drawsubpic(theOrigin + dY, width * 0.5 + height - 2 * dY, pic, '0 0.25 0', '0 0.5 0' + bW, theColor, theAlpha, 0);
79 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);
80 drawsubpic(theOrigin + height - dY, width * 0.5 + dY, pic, '0 0.75 0', '0 0.25 0' + bW, theColor, theAlpha, 0);
81 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);
86 if(theSize.y <= theBorderSize.y * 2)
88 // not high enough... draw just top and bottom then
89 bH = eY * (0.25 * theSize.y / (theBorderSize.y * 2));
90 dX = theBorderSize.x * eX;
91 drawsubpic(theOrigin, dX + height * 0.5, pic, '0 0 0', '0.25 0 0' + bH, theColor, theAlpha, 0);
92 drawsubpic(theOrigin + dX, width - 2 * dX + height * 0.5, pic, '0.25 0 0', '0.5 0 0' + bH, theColor, theAlpha, 0);
93 drawsubpic(theOrigin + width - dX, dX + height * 0.5, pic, '0.75 0 0', '0.25 0 0' + bH, theColor, theAlpha, 0);
94 drawsubpic(theOrigin + height * 0.5, dX + height * 0.5, pic, '0 0 0' + eY - bH, '0.25 0 0' + bH, theColor, theAlpha, 0);
95 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);
96 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);
100 dX = theBorderSize.x * eX;
101 dY = theBorderSize.x * eY;
102 drawsubpic(theOrigin, dX + dY, pic, '0 0 0', '0.25 0.25 0', theColor, theAlpha, 0);
103 drawsubpic(theOrigin + dX, width - 2 * dX + dY, pic, '0.25 0 0', '0.5 0.25 0', theColor, theAlpha, 0);
104 drawsubpic(theOrigin + width - dX, dX + dY, pic, '0.75 0 0', '0.25 0.25 0', theColor, theAlpha, 0);
105 drawsubpic(theOrigin + dY, dX + height - 2 * dY, pic, '0 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0);
106 drawsubpic(theOrigin + dY + dX, width - 2 * dX + height - 2 * dY, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0);
107 drawsubpic(theOrigin + dY + width - dX, dX + height - 2 * dY, pic, '0.75 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0);
108 drawsubpic(theOrigin + height - dY, dX + dY, pic, '0 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
109 drawsubpic(theOrigin + height - dY + dX, width - 2 * dX + dY, pic, '0.25 0.75 0', '0.5 0.25 0', theColor, theAlpha, 0);
110 drawsubpic(theOrigin + height - dY + width - dX, dX + dY, pic, '0.75 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
115 vector HUD_Get_Num_Color (float x, float maxvalue)
120 color_x = sin(2*M_PI*time);
122 color_z = sin(2*M_PI*time);
124 else if(x > maxvalue * 0.75) {
125 color_x = 0.4 - (x-150)*0.02 * 0.4; //red value between 0.4 -> 0
126 color_y = 0.9 + (x-150)*0.02 * 0.1; // green value between 0.9 -> 1
129 else if(x > maxvalue * 0.5) {
130 color_x = 1 - (x-100)*0.02 * 0.6; //red value between 1 -> 0.4
131 color_y = 1 - (x-100)*0.02 * 0.1; // green value between 1 -> 0.9
132 color_z = 1 - (x-100)*0.02; // blue value between 1 -> 0
134 else if(x > maxvalue * 0.25) {
137 color_z = 0.2 + (x-50)*0.02 * 0.8; // blue value between 0.2 -> 1
139 else if(x > maxvalue * 0.1) {
141 color_y = (x-20)*90/27/100; // green value between 0 -> 1
142 color_z = (x-20)*90/27/100 * 0.2; // blue value between 0 -> 0.2
150 blinkingamt = (1 - x/maxvalue/0.25);
153 color_x = color.x - color.x * blinkingamt * sin(2*M_PI*time);
154 color_y = color.y - color.y * blinkingamt * sin(2*M_PI*time);
155 color_z = color.z - color.z * blinkingamt * sin(2*M_PI*time);
160 float stringwidth_colors(string s, vector theSize)
162 return stringwidth(s, true, theSize);
165 float stringwidth_nocolors(string s, vector theSize)
167 return stringwidth(s, false, theSize);
170 void drawstringright(vector position, string text, vector theScale, vector rgb, float theAlpha, float flag)
172 position.x -= 2 / 3 * strlen(text) * theScale.x;
173 drawstring(position, text, theScale, rgb, theAlpha, flag);
176 void drawstringcenter(vector position, string text, vector theScale, vector rgb, float theAlpha, float flag)
178 position_x = 0.5 * (vid_conwidth - 0.6025 * strlen(text) * theScale.x);
179 drawstring(position, text, theScale, rgb, theAlpha, flag);
182 // return the string of the onscreen race timer
183 string MakeRaceString(float cp, float mytime, float histime, float lapdelta, string hisname)
191 if(histime == 0) // goal hit
195 timestr = strcat("+", ftos_decimals(+mytime, TIME_DECIMALS));
205 timestr = strcat("-", ftos_decimals(-mytime, TIME_DECIMALS));
211 lapstr = sprintf(_(" (-%dL)"), lapdelta);
214 else if(lapdelta < 0)
216 lapstr = sprintf(_(" (+%dL)"), -lapdelta);
220 else if(histime > 0) // anticipation
222 if(mytime >= histime)
223 timestr = strcat("+", ftos_decimals(mytime - histime, TIME_DECIMALS));
225 timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(histime));
235 cpname = _("Start line");
237 cpname = _("Finish line");
239 cpname = sprintf(_("Intermediate %d"), cp);
241 cpname = _("Finish line");
244 return strcat(col, cpname);
245 else if(hisname == "")
246 return strcat(col, sprintf("%s (%s)", cpname, timestr));
248 return strcat(col, sprintf("%s (%s %s)", cpname, timestr, strcat(hisname, col, lapstr)));
251 // Check if the given name already exist in race rankings? In that case, where? (otherwise return 0)
252 float race_CheckName(string net_name) {
254 for (i=RANKINGS_CNT-1;i>=0;--i)
255 if(grecordholder[i] == net_name)
260 float GetPlayerColorForce(float i)
265 return stof(getplayerkeyvalue(i, "colors")) & 15;
268 float GetPlayerColor(float i)
270 if(!playerslots[i].gotscores) // unconnected
271 return NUM_SPECTATOR;
272 else if(stof(getplayerkeyvalue(i, "frags")) == FRAGS_SPECTATOR)
273 return NUM_SPECTATOR;
275 return GetPlayerColorForce(i);
278 string GetPlayerName(float i)
280 return ColorTranslateRGB(getplayerkeyvalue(i, "name"));
290 // draw the background/borders
291 #define HUD_Panel_DrawBg(theAlpha) do { \
292 if(panel.current_panel_bg != "0" && panel.current_panel_bg != "") \
293 draw_BorderPicture(panel_pos - '1 1 0' * panel_bg_border, panel.current_panel_bg, panel_size + '1 1 0' * 2 * panel_bg_border, panel_bg_color, panel_bg_alpha * theAlpha, '1 1 0' * (panel_bg_border/BORDER_MULTIPLIER));\
296 //basically the same code of draw_ButtonPicture and draw_VertButtonPicture for the menu
297 void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, float length_ratio, float vertical, float baralign, vector theColor, float theAlpha, float drawflag)
299 if(!length_ratio || !theAlpha)
305 if(length_ratio < -1)
308 else if(length_ratio < 0)
312 vector width, height;
314 pic = strcat(hud_skin_path, "/", pic, "_vertical");
315 if(precache_pic(pic) == "") {
316 pic = "gfx/hud/default/progressbar_vertical";
319 if (baralign == 1) // bottom align
320 theOrigin.y += (1 - length_ratio) * theSize.y;
321 else if (baralign == 2) // center align
322 theOrigin.y += 0.5 * (1 - length_ratio) * theSize.y;
323 else if (baralign == 3) // center align, positive values down, negative up
326 if (length_ratio > 0)
327 theOrigin.y += theSize.y;
330 theOrigin.y += (1 + length_ratio) * theSize.y;
331 length_ratio = -length_ratio;
334 theSize.y *= length_ratio;
337 width = eX * theSize.x;
338 height = eY * theSize.y;
339 if(theSize.y <= theSize.x * 2)
341 // button not high enough
342 // draw just upper and lower part then
343 square = eY * theSize.y * 0.5;
344 bH = eY * (0.25 * theSize.y / (theSize.x * 2));
345 drawsubpic(theOrigin, square + width, pic, '0 0 0', eX + bH, theColor, theAlpha, drawflag);
346 drawsubpic(theOrigin + square, square + width, pic, eY - bH, eX + bH, theColor, theAlpha, drawflag);
350 square = eY * theSize.x;
351 drawsubpic(theOrigin, width + square, pic, '0 0 0', '1 0.25 0', theColor, theAlpha, drawflag);
352 drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0 0.25 0', '1 0.5 0', theColor, theAlpha, drawflag);
353 drawsubpic(theOrigin + height - square, width + square, pic, '0 0.75 0', '1 0.25 0', theColor, theAlpha, drawflag);
356 pic = strcat(hud_skin_path, "/", pic);
357 if(precache_pic(pic) == "") {
358 pic = "gfx/hud/default/progressbar";
361 if (baralign == 1) // right align
362 theOrigin.x += (1 - length_ratio) * theSize.x;
363 else if (baralign == 2) // center align
364 theOrigin.x += 0.5 * (1 - length_ratio) * theSize.x;
365 else if (baralign == 3) // center align, positive values on the right, negative on the left
368 if (length_ratio > 0)
369 theOrigin.x += theSize.x;
372 theOrigin.x += (1 + length_ratio) * theSize.x;
373 length_ratio = -length_ratio;
376 theSize.x *= length_ratio;
379 width = eX * theSize.x;
380 height = eY * theSize.y;
381 if(theSize.x <= theSize.y * 2)
383 // button not wide enough
384 // draw just left and right part then
385 square = eX * theSize.x * 0.5;
386 bW = eX * (0.25 * theSize.x / (theSize.y * 2));
387 drawsubpic(theOrigin, square + height, pic, '0 0 0', eY + bW, theColor, theAlpha, drawflag);
388 drawsubpic(theOrigin + square, square + height, pic, eX - bW, eY + bW, theColor, theAlpha, drawflag);
392 square = eX * theSize.y;
393 drawsubpic(theOrigin, height + square, pic, '0 0 0', '0.25 1 0', theColor, theAlpha, drawflag);
394 drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0.25 0 0', '0.5 1 0', theColor, theAlpha, drawflag);
395 drawsubpic(theOrigin + width - square, height + square, pic, '0.75 0 0', '0.25 1 0', theColor, theAlpha, drawflag);
400 void HUD_Panel_DrawHighlight(vector pos, vector mySize, vector color, float theAlpha, float drawflag)
406 pic = strcat(hud_skin_path, "/num_leading");
407 if(precache_pic(pic) == "") {
408 pic = "gfx/hud/default/num_leading";
411 drawsubpic(pos, eX * min(mySize.x * 0.5, mySize.y) + eY * mySize.y, pic, '0 0 0', '0.25 1 0', color, theAlpha, drawflag);
412 if(mySize.x/mySize.y > 2)
413 drawsubpic(pos + eX * mySize.y, eX * (mySize.x - 2 * mySize.y) + eY * mySize.y, pic, '0.25 0 0', '0.5 1 0', color, theAlpha, drawflag);
414 drawsubpic(pos + eX * mySize.x - eX * min(mySize.x * 0.5, mySize.y), eX * min(mySize.x * 0.5, mySize.y) + eY * mySize.y, pic, '0.75 0 0', '0.25 1 0', color, theAlpha, drawflag);
419 entity weaponorder[WEP_MAXCOUNT];
420 void weaponorder_swap(float i, float j, entity pass)
424 weaponorder[i] = weaponorder[j];
428 string weaponorder_cmp_str;
429 float weaponorder_cmp(float i, float j, entity pass)
432 ai = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[i].weapon), 0);
433 aj = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[j].weapon), 0);
434 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)
437 void HUD_Weapons(void)
440 WepSet weapons_stat = WepSet_GetFromStat();
443 vector center = '0 0 0';
444 float weapon_count, weapon_id;
445 float row, column, rows = 0, columns = 0;
446 float aspect = autocvar_hud_panel_weapons_aspect;
448 float panel_weapon_accuracy;
450 float timeout = autocvar_hud_panel_weapons_timeout;
451 float timein_effect_length = autocvar_hud_panel_weapons_timeout_speed_in; //? 0.375 : 0);
452 float timeout_effect_length = autocvar_hud_panel_weapons_timeout_speed_out; //? 0.75 : 0);
455 vector barsize = '0 0 0', baroffset = '0 0 0';
456 vector ammo_color = '1 0 1';
457 float ammo_alpha = 1;
459 float when = max(1, autocvar_hud_panel_weapons_complainbubble_time);
460 float fadetime = max(0, autocvar_hud_panel_weapons_complainbubble_fadetime);
462 vector weapon_pos, weapon_size = '0 0 0';
465 // check to see if we want to continue
466 if(hud != HUD_NORMAL) { return; }
468 if(!autocvar__hud_configure)
470 if((!autocvar_hud_panel_weapons) || (spectatee_status == -1))
472 if(timeout && time >= weapontime + timeout + timeout_effect_length)
473 if(autocvar_hud_panel_weapons_timeout_effect == 3 || (autocvar_hud_panel_weapons_timeout_effect == 1 && !(autocvar_hud_panel_weapons_timeout_fadebgmin + autocvar_hud_panel_weapons_timeout_fadefgmin)))
475 weaponprevtime = time;
480 // update generic hud functions
481 HUD_Panel_UpdateCvars();
483 draw_beginBoldFont();
485 // figure out weapon order (how the weapons are sorted) // TODO make this configurable
486 if(weaponorder_bypriority != autocvar_cl_weaponpriority || !weaponorder[0])
489 if(weaponorder_bypriority)
490 strunzone(weaponorder_bypriority);
491 if(weaponorder_byimpulse)
492 strunzone(weaponorder_byimpulse);
494 weaponorder_bypriority = strzone(autocvar_cl_weaponpriority);
495 weaponorder_byimpulse = strzone(W_FixWeaponOrder_BuildImpulseList(W_FixWeaponOrder_ForceComplete(W_NumberWeaponOrder(weaponorder_bypriority))));
496 weaponorder_cmp_str = strcat(" ", weaponorder_byimpulse, " ");
499 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
501 self = get_weaponinfo(i);
502 if(self.impulse >= 0)
504 weaponorder[weapon_cnt] = self;
508 for(i = weapon_cnt; i < WEP_MAXCOUNT; ++i)
509 weaponorder[i] = world;
510 heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, world);
512 weaponorder_cmp_str = string_null;
515 if(!autocvar_hud_panel_weapons_complainbubble || autocvar__hud_configure || time - complain_weapon_time >= when + fadetime)
518 // determine which weapons are going to be shown
519 if (autocvar_hud_panel_weapons_onlyowned)
521 if(autocvar__hud_configure)
524 for(i = WEP_FIRST; i <= WEP_LAST; i += floor((WEP_LAST-WEP_FIRST)/5))
525 weapons_stat |= WepSet_FromWeapon(i);
527 if(menu_enabled != 2)
528 HUD_Panel_DrawBg(1); // also draw the bg of the entire panel
531 // do we own this weapon?
533 for(i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
534 if(weapons_stat & WepSet_FromWeapon(weaponorder[i].weapon))
537 // add it anyway if weaponcomplain is shown
541 // might as well commit suicide now, no reason to live ;)
542 if (weapon_count == 0)
548 vector max_panel_size = panel_size - '2 2 0' * panel_bg_padding;
550 // calculate distribution and size of table cells
551 if(max_panel_size.x > max_panel_size.y)
553 while(weapon_count > columns * rows)
556 columns = ceil(max_panel_size.x / (max_panel_size.y / rows * aspect));
559 weapon_size_x = max_panel_size.x / columns;
560 weapon_size_y = max_panel_size.y / rows;
561 columns = ceil(weapon_count / rows);
565 while(weapon_count > columns * rows)
568 rows = ceil(max_panel_size.y / (max_panel_size.x / columns / aspect));
571 weapon_size_x = max_panel_size.x / columns;
572 weapon_size_y = max_panel_size.y / rows;
573 rows = ceil(weapon_count / columns);
576 // reduce size of the panel
577 panel_size_x = columns * weapon_size.x;
578 panel_size_y = rows * weapon_size.y;
579 panel_pos.x += (max_panel_size.x - panel_size.x) / 2;
580 panel_pos.y += (max_panel_size.y - panel_size.y) / 2;
582 panel_size += '2 2 0' * panel_bg_padding;
585 weapon_count = WEP_COUNT;
587 // animation for fading in/out the panel respectively when not in use
588 if(!autocvar__hud_configure)
590 if (timeout && time >= weapontime + timeout) // apply timeout effect if needed
592 f = bound(0, (time - (weapontime + timeout)) / timeout_effect_length, 1);
594 // fade the panel alpha
595 if(autocvar_hud_panel_weapons_timeout_effect == 1)
597 panel_bg_alpha *= (autocvar_hud_panel_weapons_timeout_fadebgmin * f + (1 - f));
598 panel_fg_alpha *= (autocvar_hud_panel_weapons_timeout_fadefgmin * f + (1 - f));
600 else if(autocvar_hud_panel_weapons_timeout_effect == 3)
602 panel_bg_alpha *= (1 - f);
603 panel_fg_alpha *= (1 - f);
606 // move the panel off the screen
607 if (autocvar_hud_panel_weapons_timeout_effect == 2 || autocvar_hud_panel_weapons_timeout_effect == 3)
609 f *= f; // for a cooler movement
610 center_x = panel_pos.x + panel_size.x/2;
611 center_y = panel_pos.y + panel_size.y/2;
612 screen_ar = vid_conwidth/vid_conheight;
613 if (center.x/center.y < screen_ar) //bottom left
615 if ((vid_conwidth - center.x)/center.y < screen_ar) //bottom
616 panel_pos.y += f * (vid_conheight - panel_pos.y);
618 panel_pos.x -= f * (panel_pos.x + panel_size.x);
622 if ((vid_conwidth - center.x)/center.y < screen_ar) //right
623 panel_pos.x += f * (vid_conwidth - panel_pos.x);
625 panel_pos.y -= f * (panel_pos.y + panel_size.y);
628 center_x = -1; // mark the panel as off screen
630 weaponprevtime = time - (1 - f) * timein_effect_length;
632 else if (timeout && time < weaponprevtime + timein_effect_length) // apply timein effect if needed
634 f = bound(0, (time - weaponprevtime) / timein_effect_length, 1);
636 // fade the panel alpha
637 if(autocvar_hud_panel_weapons_timeout_effect == 1)
639 panel_bg_alpha *= (autocvar_hud_panel_weapons_timeout_fadebgmin * (1 - f) + f);
640 panel_fg_alpha *= (autocvar_hud_panel_weapons_timeout_fadefgmin * (1 - f) + f);
642 else if(autocvar_hud_panel_weapons_timeout_effect == 3)
644 panel_bg_alpha *= (f);
645 panel_fg_alpha *= (f);
648 // move the panel back on screen
649 if (autocvar_hud_panel_weapons_timeout_effect == 2 || autocvar_hud_panel_weapons_timeout_effect == 3)
651 f *= f; // for a cooler movement
653 center_x = panel_pos.x + panel_size.x/2;
654 center_y = panel_pos.y + panel_size.y/2;
655 screen_ar = vid_conwidth/vid_conheight;
656 if (center.x/center.y < screen_ar) //bottom left
658 if ((vid_conwidth - center.x)/center.y < screen_ar) //bottom
659 panel_pos.y += f * (vid_conheight - panel_pos.y);
661 panel_pos.x -= f * (panel_pos.x + panel_size.x);
665 if ((vid_conwidth - center.x)/center.y < screen_ar) //right
666 panel_pos.x += f * (vid_conwidth - panel_pos.x);
668 panel_pos.y -= f * (panel_pos.y + panel_size.y);
674 // draw the background, then change the virtual size of it to better fit other items inside
685 panel_pos += '1 1 0' * panel_bg_padding;
686 panel_size -= '2 2 0' * panel_bg_padding;
689 // after the sizing and animations are done, update the other values
691 if(!rows) // if rows is > 0 onlyowned code has already updated these vars
693 rows = panel_size.y/panel_size.x;
694 rows = bound(1, floor((sqrt(4 * aspect * rows * weapon_count + rows * rows) + rows + 0.5) / 2), weapon_count);
695 columns = ceil(weapon_count/rows);
696 weapon_size = eX * panel_size.x*(1/columns) + eY * panel_size.y*(1/rows);
699 // calculate position/size for visual bar displaying ammount of ammo status
700 if (autocvar_hud_panel_weapons_ammo)
702 ammo_color = stov(autocvar_hud_panel_weapons_ammo_color);
703 ammo_alpha = panel_fg_alpha * autocvar_hud_panel_weapons_ammo_alpha;
705 if(weapon_size.x/weapon_size.y > aspect)
707 barsize_x = aspect * weapon_size.y;
708 barsize_y = weapon_size.y;
709 baroffset_x = (weapon_size.x - barsize.x) / 2;
713 barsize_y = 1/aspect * weapon_size.x;
714 barsize_x = weapon_size.x;
715 baroffset_y = (weapon_size.y - barsize.y) / 2;
718 if(autocvar_hud_panel_weapons_accuracy)
719 Accuracy_LoadColors();
723 vector label_size = '1 1 0' * min(weapon_size.x, weapon_size.y) * bound(0, autocvar_hud_panel_weapons_label_scale, 1);
724 for(i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
726 // retrieve information about the current weapon to be drawn
727 self = weaponorder[i];
728 weapon_id = self.impulse;
730 // skip if this weapon doesn't exist
731 if(!self || weapon_id < 0) { continue; }
733 // skip this weapon if we don't own it (and onlyowned is enabled)-- or if weapons_complainbubble is showing for this weapon
734 if(autocvar_hud_panel_weapons_onlyowned)
735 if (!((weapons_stat & WepSet_FromWeapon(self.weapon)) || (self.weapon == complain_weapon)))
738 // figure out the drawing position of weapon
739 weapon_pos = (panel_pos
740 + eX * column * weapon_size.x
741 + eY * row * weapon_size.y);
743 // draw background behind currently selected weapon
744 if(self.weapon == switchweapon)
745 drawpic_aspect_skin(weapon_pos, "weapon_current_bg", weapon_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
747 // draw the weapon accuracy
748 if(autocvar_hud_panel_weapons_accuracy)
750 panel_weapon_accuracy = weapon_accuracy[self.weapon-WEP_FIRST];
751 if(panel_weapon_accuracy >= 0)
753 color = Accuracy_GetColor(panel_weapon_accuracy);
754 drawpic_aspect_skin(weapon_pos, "weapon_accuracy", weapon_size, color, panel_fg_alpha, DRAWFLAG_NORMAL);
758 // drawing all the weapon items
759 if(weapons_stat & WepSet_FromWeapon(self.weapon))
761 // draw the weapon image
762 drawpic_aspect_skin(weapon_pos, self.model2, weapon_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
764 // draw weapon label string
765 switch(autocvar_hud_panel_weapons_label)
767 case 1: // weapon number
768 drawstring(weapon_pos, ftos(weapon_id), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
772 drawstring(weapon_pos, getcommandkey(ftos(weapon_id), strcat("weapon_group_", ftos(weapon_id))), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
775 case 3: // weapon name
776 drawstring(weapon_pos, strtolower(self.message), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
783 // draw ammo status bar
784 if(autocvar_hud_panel_weapons_ammo && (self.ammo_field != ammo_none))
786 a = getstati(GetAmmoStat(self.ammo_field)); // how much ammo do we have?
790 switch(self.ammo_field)
792 case ammo_shells: ammo_full = autocvar_hud_panel_weapons_ammo_full_shells; break;
793 case ammo_nails: ammo_full = autocvar_hud_panel_weapons_ammo_full_nails; break;
794 case ammo_rockets: ammo_full = autocvar_hud_panel_weapons_ammo_full_rockets; break;
795 case ammo_cells: ammo_full = autocvar_hud_panel_weapons_ammo_full_cells; break;
796 case ammo_plasma: ammo_full = autocvar_hud_panel_weapons_ammo_full_plasma; break;
797 case ammo_fuel: ammo_full = autocvar_hud_panel_weapons_ammo_full_fuel; break;
798 default: ammo_full = 60;
802 weapon_pos.x + baroffset.x,
803 weapon_pos.y + baroffset.y,
804 barsize.x * bound(0, a/ammo_full, 1),
821 else // draw a "ghost weapon icon" if you don't have the weapon
823 drawpic_aspect_skin(weapon_pos, self.model2, weapon_size, '0 0 0', panel_fg_alpha * 0.5, DRAWFLAG_NORMAL);
826 // draw the complain message
827 if(self.weapon == complain_weapon)
830 a = ((complain_weapon_time + when > time) ? 1 : bound(0, (complain_weapon_time + when + fadetime - time) / fadetime, 1));
832 a = ((complain_weapon_time + when > time) ? 1 : 0);
835 if(complain_weapon_type == 0) {
836 s = _("Out of ammo");
837 color = stov(autocvar_hud_panel_weapons_complainbubble_color_outofammo);
839 else if(complain_weapon_type == 1) {
841 color = stov(autocvar_hud_panel_weapons_complainbubble_color_donthave);
844 s = _("Unavailable");
845 color = stov(autocvar_hud_panel_weapons_complainbubble_color_unavailable);
847 float padding = autocvar_hud_panel_weapons_complainbubble_padding;
848 drawpic_aspect_skin(weapon_pos + '1 1 0' * padding, "weapon_complainbubble", weapon_size - '2 2 0' * padding, color, a * panel_fg_alpha, DRAWFLAG_NORMAL);
849 drawstring_aspect(weapon_pos + '1 1 0' * padding, s, weapon_size - '2 2 0' * padding, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
852 // continue with new position for the next weapon
865 void DrawNadeScoreBar(vector myPos, vector mySize, vector color)
868 HUD_Panel_DrawProgressBar(
869 myPos + eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize.x,
870 mySize - eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize.x,
871 autocvar_hud_panel_ammo_progressbar_name,
872 getstatf(STAT_NADE_BONUS_SCORE), 0, 0, color,
873 autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
877 void DrawAmmoNades(vector myPos, vector mySize, float draw_expanding, float expand_time)
879 float theAlpha = 1, a, b;
880 vector nade_color, picpos, numpos;
882 nade_color = Nade_Color(getstati(STAT_NADE_BONUS_TYPE));
884 a = getstatf(STAT_NADE_BONUS);
885 b = getstatf(STAT_NADE_BONUS_SCORE);
887 if(autocvar_hud_panel_ammo_iconalign)
890 picpos = myPos + eX * 2 * mySize.y;
894 numpos = myPos + eX * mySize.y;
898 DrawNadeScoreBar(myPos, mySize, nade_color);
902 if(autocvar_hud_panel_ammo_text)
903 drawstring_aspect(numpos, ftos(a), eX * (2/3) * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
906 drawpic_aspect_skin_expanding(picpos, "nade_nbg", '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL, expand_time);
908 drawpic_aspect_skin(picpos, "nade_bg" , '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
909 drawpic_aspect_skin(picpos, "nade_nbg" , '1 1 0' * mySize.y, nade_color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
913 void DrawAmmoItem(vector myPos, vector mySize, .float ammoType, float isCurrent, float isInfinite)
915 if(ammoType == ammo_none)
918 // Initialize variables
921 if(autocvar__hud_configure)
923 isCurrent = (ammoType == ammo_rockets); // Rockets always current
927 ammo = getstati(GetAmmoStat(ammoType));
931 float scale = bound(0, autocvar_hud_panel_ammo_noncurrent_scale, 1);
932 myPos = myPos + (mySize - mySize * scale) * 0.5;
933 mySize = mySize * scale;
936 vector iconPos, textPos;
937 if(autocvar_hud_panel_ammo_iconalign)
939 iconPos = myPos + eX * 2 * mySize.y;
945 textPos = myPos + eX * mySize.y;
948 float isShadowed = (ammo <= 0 && !isCurrent && !isInfinite);
950 vector iconColor = isShadowed ? '0 0 0' : '1 1 1';
953 textColor = '0.2 0.95 0';
957 textColor = '0.8 0.04 0';
963 alpha = panel_fg_alpha;
965 alpha = panel_fg_alpha * bound(0, autocvar_hud_panel_ammo_noncurrent_alpha, 1) * 0.5;
967 alpha = panel_fg_alpha * bound(0, autocvar_hud_panel_ammo_noncurrent_alpha, 1);
969 string text = isInfinite ? "\xE2\x88\x9E" : ftos(ammo); // Use infinity symbol (U+221E)
974 drawpic_aspect_skin(myPos, "ammo_current_bg", mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
976 if(ammo > 0 && autocvar_hud_panel_ammo_progressbar)
977 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, ammo/autocvar_hud_panel_ammo_maxammo, 0, 0, textColor, autocvar_hud_progressbar_alpha * alpha, DRAWFLAG_NORMAL);
979 if(autocvar_hud_panel_ammo_text)
980 drawstring_aspect(textPos, text, eX * (2/3) * mySize.x + eY * mySize.y, textColor, alpha, DRAWFLAG_NORMAL);
982 drawpic_aspect_skin(iconPos, GetAmmoPicture(ammoType), '1 1 0' * mySize.y, iconColor, alpha, DRAWFLAG_NORMAL);
985 float nade_prevstatus;
986 float nade_prevframe;
987 float nade_statuschange_time;
990 if(hud != HUD_NORMAL) return;
991 if(!autocvar__hud_configure)
993 if(!autocvar_hud_panel_ammo) return;
994 if(spectatee_status == -1) return;
997 HUD_Panel_UpdateCvars();
999 draw_beginBoldFont();
1003 mySize = panel_size;
1005 HUD_Panel_DrawBg(1);
1006 if(panel_bg_padding)
1008 pos += '1 1 0' * panel_bg_padding;
1009 mySize -= '2 2 0' * panel_bg_padding;
1012 float rows = 0, columns, row, column;
1013 float nade_cnt = getstatf(STAT_NADE_BONUS), nade_score = getstatf(STAT_NADE_BONUS_SCORE);
1014 float draw_nades = (nade_cnt > 0 || nade_score > 0), nade_statuschange_elapsedtime;
1015 float total_ammo_count;
1018 if (autocvar_hud_panel_ammo_onlycurrent)
1019 total_ammo_count = 1;
1021 total_ammo_count = AMMO_COUNT;
1026 if (nade_cnt != nade_prevframe)
1028 nade_statuschange_time = time;
1029 nade_prevstatus = nade_prevframe;
1030 nade_prevframe = nade_cnt;
1034 nade_prevstatus = nade_prevframe = nade_statuschange_time = 0;
1036 rows = mySize.y/mySize.x;
1037 rows = bound(1, floor((sqrt(4 * (3/1) * rows * (total_ammo_count) + rows * rows) + rows + 0.5) / 2), (total_ammo_count));
1038 // ^^^ ammo item aspect goes here
1040 columns = ceil((total_ammo_count)/rows);
1042 ammo_size = eX * mySize.x*(1/columns) + eY * mySize.y*(1/rows);
1045 vector offset = '0 0 0'; // fteqcc sucks
1047 if(ammo_size.x/ammo_size.y > 3)
1049 newSize = 3 * ammo_size.y;
1050 offset_x = ammo_size.x - newSize;
1051 pos.x += offset.x/2;
1052 ammo_size_x = newSize;
1056 newSize = 1/3 * ammo_size.x;
1057 offset_y = ammo_size.y - newSize;
1058 pos.y += offset.y/2;
1059 ammo_size_y = newSize;
1063 float infinite_ammo = (getstati(STAT_ITEMS, 0, 24) & IT_UNLIMITED_WEAPON_AMMO);
1065 if(autocvar_hud_panel_ammo_onlycurrent)
1067 if(autocvar__hud_configure)
1069 DrawAmmoItem(pos, ammo_size, ammo_rockets, true, false);
1076 (get_weaponinfo(switchweapon)).ammo_field,
1086 column = column + 1;
1093 for(i = 0; i < AMMO_COUNT; ++i)
1095 ammotype = GetAmmoFieldFromNum(i);
1097 pos + eX * column * (ammo_size.x + offset.x) + eY * row * (ammo_size.y + offset.y),
1100 ((get_weaponinfo(switchweapon)).ammo_field == ammotype),
1108 column = column + 1;
1115 nade_statuschange_elapsedtime = time - nade_statuschange_time;
1117 float f = bound(0, nade_statuschange_elapsedtime*2, 1);
1119 DrawAmmoNades(pos + eX * column * (ammo_size.x + offset.x) + eY * row * (ammo_size.y + offset.y), ammo_size, nade_prevstatus < nade_cnt && nade_cnt != 0 && f < 1, f);
1125 void DrawNumIcon_expanding(vector myPos, vector mySize, float x, string icon, float vertical, float icon_right_align, vector color, float theAlpha, float fadelerp)
1127 vector newPos = '0 0 0', newSize = '0 0 0';
1128 vector picpos, numpos;
1132 if(mySize.y/mySize.x > 2)
1134 newSize_y = 2 * mySize.x;
1135 newSize_x = mySize.x;
1137 newPos_y = myPos.y + (mySize.y - newSize.y) / 2;
1142 newSize_x = 1/2 * mySize.y;
1143 newSize_y = mySize.y;
1145 newPos_x = myPos.x + (mySize.x - newSize.x) / 2;
1149 if(icon_right_align)
1152 picpos = newPos + eY * newSize.x;
1157 numpos = newPos + eY * newSize.x;
1161 drawpic_aspect_skin(picpos, icon, newSize, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
1162 // make number smaller than icon, it looks better
1163 // reduce only y to draw numbers with different number of digits with the same y size
1164 numpos.y += newSize.y * ((1 - 0.7) / 2);
1166 drawstring_aspect(numpos, ftos(x), newSize, color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
1170 if(mySize.x/mySize.y > 3)
1172 newSize_x = 3 * mySize.y;
1173 newSize_y = mySize.y;
1175 newPos_x = myPos.x + (mySize.x - newSize.x) / 2;
1180 newSize_y = 1/3 * mySize.x;
1181 newSize_x = mySize.x;
1183 newPos_y = myPos.y + (mySize.y - newSize.y) / 2;
1187 if(icon_right_align) // right align
1190 picpos = newPos + eX * 2 * newSize.y;
1194 numpos = newPos + eX * newSize.y;
1198 // NOTE: newSize_x is always equal to 3 * mySize_y so we can use
1199 // '2 1 0' * newSize_y instead of eX * (2/3) * newSize_x + eY * newSize_y
1200 drawstring_aspect_expanding(numpos, ftos(x), '2 1 0' * newSize.y, color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL, fadelerp);
1201 drawpic_aspect_skin_expanding(picpos, icon, '1 1 0' * newSize.y, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL, fadelerp);
1204 void DrawNumIcon(vector myPos, vector mySize, float x, string icon, float vertical, float icon_right_align, vector color, float theAlpha)
1206 DrawNumIcon_expanding(myPos, mySize, x, icon, vertical, icon_right_align, color, theAlpha, 0);
1211 void HUD_Powerups(void)
1213 float strength_time, shield_time, superweapons_time;
1214 if(!autocvar__hud_configure)
1216 if(!autocvar_hud_panel_powerups) return;
1217 if(spectatee_status == -1) return;
1218 if(!(getstati(STAT_ITEMS, 0, 24) & (IT_STRENGTH | IT_INVINCIBLE | IT_SUPERWEAPON))) return;
1219 if (getstati(STAT_HEALTH) <= 0) return;
1221 strength_time = bound(0, getstatf(STAT_STRENGTH_FINISHED) - time, 99);
1222 shield_time = bound(0, getstatf(STAT_INVINCIBLE_FINISHED) - time, 99);
1223 superweapons_time = bound(0, getstatf(STAT_SUPERWEAPONS_FINISHED) - time, 99);
1225 if (getstati(STAT_ITEMS, 0, 24) & IT_UNLIMITED_SUPERWEAPONS)
1226 superweapons_time = 99; // force max
1228 // prevent stuff to show up on mismatch that will be fixed next frame
1229 if (!(getstati(STAT_ITEMS, 0, 24) & IT_SUPERWEAPON))
1230 superweapons_time = 0;
1236 superweapons_time = 13;
1239 HUD_Panel_UpdateCvars();
1241 draw_beginBoldFont();
1245 mySize = panel_size;
1247 HUD_Panel_DrawBg(bound(0, max(strength_time, shield_time, superweapons_time), 1));
1248 if(panel_bg_padding)
1250 pos += '1 1 0' * panel_bg_padding;
1251 mySize -= '2 2 0' * panel_bg_padding;
1254 float panel_ar = mySize.x/mySize.y;
1255 float is_vertical = (panel_ar < 1);
1256 vector shield_offset = '0 0 0', strength_offset = '0 0 0', superweapons_offset = '0 0 0';
1258 float superweapons_is = -1;
1260 if(superweapons_time)
1265 superweapons_is = 0;
1267 superweapons_is = 2;
1272 superweapons_is = 1;
1274 superweapons_is = 2;
1278 // FIXME handle superweapons here
1279 if(superweapons_is == 0)
1281 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
1283 mySize.x *= (1.0 / 3.0);
1284 superweapons_offset_x = mySize.x;
1285 if (autocvar_hud_panel_powerups_flip)
1286 shield_offset_x = 2*mySize.x;
1288 strength_offset_x = 2*mySize.x;
1292 mySize.y *= (1.0 / 3.0);
1293 superweapons_offset_y = mySize.y;
1294 if (autocvar_hud_panel_powerups_flip)
1295 shield_offset_y = 2*mySize.y;
1297 strength_offset_y = 2*mySize.y;
1302 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
1305 if (autocvar_hud_panel_powerups_flip)
1306 shield_offset_x = mySize.x;
1308 strength_offset_x = mySize.x;
1313 if (autocvar_hud_panel_powerups_flip)
1314 shield_offset_y = mySize.y;
1316 strength_offset_y = mySize.y;
1320 float shield_baralign, strength_baralign, superweapons_baralign;
1321 float shield_iconalign, strength_iconalign, superweapons_iconalign;
1323 if (autocvar_hud_panel_powerups_flip)
1325 strength_baralign = (autocvar_hud_panel_powerups_baralign == 2 || autocvar_hud_panel_powerups_baralign == 1);
1326 shield_baralign = (autocvar_hud_panel_powerups_baralign == 3 || autocvar_hud_panel_powerups_baralign == 1);
1327 strength_iconalign = (autocvar_hud_panel_powerups_iconalign == 2 || autocvar_hud_panel_powerups_iconalign == 1);
1328 shield_iconalign = (autocvar_hud_panel_powerups_iconalign == 3 || autocvar_hud_panel_powerups_iconalign == 1);
1332 shield_baralign = (autocvar_hud_panel_powerups_baralign == 2 || autocvar_hud_panel_powerups_baralign == 1);
1333 strength_baralign = (autocvar_hud_panel_powerups_baralign == 3 || autocvar_hud_panel_powerups_baralign == 1);
1334 shield_iconalign = (autocvar_hud_panel_powerups_iconalign == 2 || autocvar_hud_panel_powerups_iconalign == 1);
1335 strength_iconalign = (autocvar_hud_panel_powerups_iconalign == 3 || autocvar_hud_panel_powerups_iconalign == 1);
1338 if(superweapons_is == 0)
1340 superweapons_iconalign = strength_iconalign;
1341 superweapons_baralign = 2;
1343 else if(superweapons_is == 1)
1345 superweapons_offset = strength_offset;
1346 superweapons_iconalign = strength_iconalign;
1347 superweapons_baralign = strength_baralign;
1349 else // if(superweapons_is == 2)
1351 superweapons_offset = shield_offset;
1352 superweapons_iconalign = shield_iconalign;
1353 superweapons_baralign = shield_baralign;
1358 const float maxshield = 30;
1359 float shield = ceil(shield_time);
1360 if(autocvar_hud_panel_powerups_progressbar)
1361 HUD_Panel_DrawProgressBar(pos + shield_offset, mySize, autocvar_hud_panel_powerups_progressbar_shield, shield/maxshield, is_vertical, shield_baralign, autocvar_hud_progressbar_shield_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
1362 if(autocvar_hud_panel_powerups_text)
1365 DrawNumIcon(pos + shield_offset, mySize, shield, "shield", is_vertical, shield_iconalign, '1 1 1', 1);
1367 DrawNumIcon_expanding(pos + shield_offset, mySize, shield, "shield", is_vertical, shield_iconalign, '1 1 1', 1, bound(0, (shield - shield_time) / 0.5, 1));
1373 const float maxstrength = 30;
1374 float strength = ceil(strength_time);
1375 if(autocvar_hud_panel_powerups_progressbar)
1376 HUD_Panel_DrawProgressBar(pos + strength_offset, mySize, autocvar_hud_panel_powerups_progressbar_strength, strength/maxstrength, is_vertical, strength_baralign, autocvar_hud_progressbar_strength_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
1377 if(autocvar_hud_panel_powerups_text)
1380 DrawNumIcon(pos + strength_offset, mySize, strength, "strength", is_vertical, strength_iconalign, '1 1 1', 1);
1382 DrawNumIcon_expanding(pos + strength_offset, mySize, strength, "strength", is_vertical, strength_iconalign, '1 1 1', 1, bound(0, (strength - strength_time) / 0.5, 1));
1386 if(superweapons_time)
1388 const float maxsuperweapons = 30;
1389 float superweapons = ceil(superweapons_time);
1390 if(autocvar_hud_panel_powerups_progressbar)
1391 HUD_Panel_DrawProgressBar(pos + superweapons_offset, mySize, autocvar_hud_panel_powerups_progressbar_superweapons, superweapons/maxsuperweapons, is_vertical, superweapons_baralign, autocvar_hud_progressbar_superweapons_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
1392 if(autocvar_hud_panel_powerups_text)
1394 if(superweapons > 1)
1395 DrawNumIcon(pos + superweapons_offset, mySize, superweapons, "superweapons", is_vertical, superweapons_iconalign, '1 1 1', 1);
1396 if(superweapons <= 5)
1397 DrawNumIcon_expanding(pos + superweapons_offset, mySize, superweapons, "superweapons", is_vertical, superweapons_iconalign, '1 1 1', 1, bound(0, (superweapons - superweapons_time) / 0.5, 1));
1404 // Health/armor (#3)
1407 // prev_* vars contain the health/armor at the previous FRAME
1408 // set to -1 when player is dead or was not playing
1409 float prev_health, prev_armor;
1410 float health_damagetime, armor_damagetime;
1411 float health_beforedamage, armor_beforedamage;
1412 // old_p_* vars keep track of previous values when smoothing value changes of the progressbar
1413 float old_p_health, old_p_armor;
1414 float old_p_healthtime, old_p_armortime;
1415 // prev_p_* vars contain the health/armor progressbar value at the previous FRAME
1416 // set to -1 to forcedly stop effects when we switch spectated player (e.g. from playerX: 70h to playerY: 50h)
1417 float prev_p_health, prev_p_armor;
1419 void HUD_HealthArmor(void)
1421 float armor, health, fuel;
1422 if(!autocvar__hud_configure)
1424 if(!autocvar_hud_panel_healtharmor) return;
1425 if(hud != HUD_NORMAL) return;
1426 if(spectatee_status == -1) return;
1428 health = getstati(STAT_HEALTH);
1434 armor = getstati(STAT_ARMOR);
1436 // code to check for spectatee_status changes is in Ent_ClientData()
1437 // prev_p_health and prev_health can be set to -1 there
1439 if (prev_p_health == -1)
1442 health_beforedamage = 0;
1443 armor_beforedamage = 0;
1444 health_damagetime = 0;
1445 armor_damagetime = 0;
1446 prev_health = health;
1448 old_p_health = health;
1449 old_p_armor = armor;
1450 prev_p_health = health;
1451 prev_p_armor = armor;
1453 else if (prev_health == -1)
1455 //start the load effect
1456 health_damagetime = 0;
1457 armor_damagetime = 0;
1461 fuel = getstati(STAT_FUEL);
1470 HUD_Panel_UpdateCvars();
1473 mySize = panel_size;
1475 HUD_Panel_DrawBg(1);
1476 if(panel_bg_padding)
1478 pos += '1 1 0' * panel_bg_padding;
1479 mySize -= '2 2 0' * panel_bg_padding;
1482 float baralign = autocvar_hud_panel_healtharmor_baralign;
1483 float iconalign = autocvar_hud_panel_healtharmor_iconalign;
1485 float maxhealth = autocvar_hud_panel_healtharmor_maxhealth;
1486 float maxarmor = autocvar_hud_panel_healtharmor_maxarmor;
1487 if(autocvar_hud_panel_healtharmor == 2) // combined health and armor display
1490 v = healtharmor_maxdamage(health, armor, armorblockpercent, DEATH_WEAPON);
1495 float maxtotal = maxhealth + maxarmor;
1497 if(v.z) // NOT fully armored
1499 biggercount = "health";
1500 if(autocvar_hud_panel_healtharmor_progressbar)
1501 HUD_Panel_DrawProgressBar(pos, mySize, autocvar_hud_panel_healtharmor_progressbar_health, x/maxtotal, 0, (baralign == 1 || baralign == 2), autocvar_hud_progressbar_health_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
1503 if(autocvar_hud_panel_healtharmor_text)
1504 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);
1508 biggercount = "armor";
1509 if(autocvar_hud_panel_healtharmor_progressbar)
1510 HUD_Panel_DrawProgressBar(pos, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, x/maxtotal, 0, (baralign == 1 || baralign == 2), autocvar_hud_progressbar_armor_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
1512 if(autocvar_hud_panel_healtharmor_text)
1513 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);
1515 if(autocvar_hud_panel_healtharmor_text)
1516 DrawNumIcon(pos, mySize, x, biggercount, 0, iconalign, HUD_Get_Num_Color(x, maxtotal), 1);
1519 HUD_Panel_DrawProgressBar(pos, eX * mySize.x + eY * 0.2 * mySize.y, "progressbar", fuel/100, 0, (baralign == 1 || baralign == 3), autocvar_hud_progressbar_fuel_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
1523 float panel_ar = mySize.x/mySize.y;
1524 float is_vertical = (panel_ar < 1);
1525 vector health_offset = '0 0 0', armor_offset = '0 0 0';
1526 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
1529 if (autocvar_hud_panel_healtharmor_flip)
1530 health_offset_x = mySize.x;
1532 armor_offset_x = mySize.x;
1537 if (autocvar_hud_panel_healtharmor_flip)
1538 health_offset_y = mySize.y;
1540 armor_offset_y = mySize.y;
1543 float health_baralign, armor_baralign, fuel_baralign;
1544 float health_iconalign, armor_iconalign;
1545 if (autocvar_hud_panel_healtharmor_flip)
1547 armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1);
1548 health_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1);
1549 fuel_baralign = health_baralign;
1550 armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1);
1551 health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1);
1555 health_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1);
1556 armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1);
1557 fuel_baralign = armor_baralign;
1558 health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1);
1559 armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1);
1564 if(autocvar_hud_panel_healtharmor_progressbar)
1566 float p_health, pain_health_alpha;
1568 pain_health_alpha = 1;
1569 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
1571 if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0)
1573 if (fabs(prev_health - health) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth)
1575 if (time - old_p_healthtime < 1)
1576 old_p_health = prev_p_health;
1578 old_p_health = prev_health;
1579 old_p_healthtime = time;
1581 if (time - old_p_healthtime < 1)
1583 p_health += (old_p_health - health) * (1 - (time - old_p_healthtime));
1584 prev_p_health = p_health;
1587 if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0)
1589 if (prev_health - health >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
1591 if (time - health_damagetime >= 1)
1592 health_beforedamage = prev_health;
1593 health_damagetime = time;
1595 if (time - health_damagetime < 1)
1597 float health_damagealpha = 1 - (time - health_damagetime)*(time - health_damagetime);
1598 HUD_Panel_DrawProgressBar(pos + health_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_health, health_beforedamage/maxhealth, is_vertical, health_baralign, autocvar_hud_progressbar_health_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * health_damagealpha, DRAWFLAG_NORMAL);
1601 prev_health = health;
1603 if (health <= autocvar_hud_panel_healtharmor_progressbar_gfx_lowhealth)
1605 float BLINK_FACTOR = 0.15;
1606 float BLINK_BASE = 0.85;
1607 float BLINK_FREQ = 9;
1608 pain_health_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ);
1611 HUD_Panel_DrawProgressBar(pos + health_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_health, p_health/maxhealth, is_vertical, health_baralign, autocvar_hud_progressbar_health_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * pain_health_alpha, DRAWFLAG_NORMAL);
1613 if(autocvar_hud_panel_healtharmor_text)
1614 DrawNumIcon(pos + health_offset, mySize, health, "health", is_vertical, health_iconalign, HUD_Get_Num_Color(health, maxhealth), 1);
1619 if(autocvar_hud_panel_healtharmor_progressbar)
1623 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
1625 if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0)
1627 if (fabs(prev_armor - armor) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth)
1629 if (time - old_p_armortime < 1)
1630 old_p_armor = prev_p_armor;
1632 old_p_armor = prev_armor;
1633 old_p_armortime = time;
1635 if (time - old_p_armortime < 1)
1637 p_armor += (old_p_armor - armor) * (1 - (time - old_p_armortime));
1638 prev_p_armor = p_armor;
1641 if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0)
1643 if (prev_armor - armor >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
1645 if (time - armor_damagetime >= 1)
1646 armor_beforedamage = prev_armor;
1647 armor_damagetime = time;
1649 if (time - armor_damagetime < 1)
1651 float armor_damagealpha = 1 - (time - armor_damagetime)*(time - armor_damagetime);
1652 HUD_Panel_DrawProgressBar(pos + armor_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, armor_beforedamage/maxarmor, is_vertical, armor_baralign, autocvar_hud_progressbar_armor_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * armor_damagealpha, DRAWFLAG_NORMAL);
1657 HUD_Panel_DrawProgressBar(pos + armor_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, p_armor/maxarmor, is_vertical, armor_baralign, autocvar_hud_progressbar_armor_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
1659 if(autocvar_hud_panel_healtharmor_text)
1660 DrawNumIcon(pos + armor_offset, mySize, armor, "armor", is_vertical, armor_iconalign, HUD_Get_Num_Color(armor, maxarmor), 1);
1666 mySize.x *= 0.2 / 2; //if vertical always halve x to not cover too much numbers with 3 digits
1670 mySize.x *= 2; //restore full panel size
1671 else if (panel_ar < 1/4)
1672 mySize.y *= 2; //restore full panel size
1673 HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", fuel/100, is_vertical, fuel_baralign, autocvar_hud_progressbar_fuel_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
1678 // Notification area (#4)
1681 void HUD_Notify_Push(string icon, string attacker, string victim)
1689 if (notify_index == -1)
1690 notify_index = NOTIFY_MAX_ENTRIES-1;
1693 if (notify_attackers[notify_index])
1694 strunzone(notify_attackers[notify_index]);
1696 if (notify_victims[notify_index])
1697 strunzone(notify_victims[notify_index]);
1699 if (notify_icons[notify_index])
1700 strunzone(notify_icons[notify_index]);
1702 // Allocate new strings
1705 notify_attackers[notify_index] = strzone(attacker);
1706 notify_victims[notify_index] = strzone(victim);
1710 // In case of a notification without a victim, the attacker
1711 // is displayed on the victim's side. Instead of special
1712 // treatment later on, we can simply switch them here.
1713 notify_attackers[notify_index] = string_null;
1714 notify_victims[notify_index] = strzone(attacker);
1717 notify_icons[notify_index] = strzone(icon);
1718 notify_times[notify_index] = time;
1721 void HUD_Notify(void)
1723 if (!autocvar__hud_configure)
1724 if (!autocvar_hud_panel_notify)
1727 HUD_Panel_UpdateCvars();
1728 HUD_Panel_DrawBg(1);
1730 if (!autocvar__hud_configure)
1731 if (notify_count == 0)
1738 if (panel_bg_padding)
1740 pos += '1 1 0' * panel_bg_padding;
1741 size -= '2 2 0' * panel_bg_padding;
1744 float fade_start = max(0, autocvar_hud_panel_notify_time);
1745 float fade_time = max(0, autocvar_hud_panel_notify_fadetime);
1746 float icon_aspect = max(1, autocvar_hud_panel_notify_icon_aspect);
1748 float entry_count = bound(1, floor(NOTIFY_MAX_ENTRIES * size.y / size.x), NOTIFY_MAX_ENTRIES);
1749 float entry_height = size.y / entry_count;
1751 float panel_width_half = size.x * 0.5;
1752 float icon_width_half = entry_height * icon_aspect / 2;
1753 float name_maxwidth = panel_width_half - icon_width_half - size.x * NOTIFY_ICON_MARGIN;
1755 vector font_size = '0.5 0.5 0' * entry_height * autocvar_hud_panel_notify_fontsize;
1756 vector icon_size = (eX * icon_aspect + eY) * entry_height;
1757 vector icon_left = eX * (panel_width_half - icon_width_half);
1758 vector attacker_right = eX * name_maxwidth;
1759 vector victim_left = eX * (size.x - name_maxwidth);
1761 vector attacker_pos, victim_pos, icon_pos;
1762 string attacker, victim, icon;
1763 float i, j, count, step, limit, alpha;
1765 if (autocvar_hud_panel_notify_flip)
1767 // Order items from the top down
1770 limit = entry_count;
1774 // Order items from the bottom up
1775 i = entry_count - 1;
1780 for (j = notify_index, count = 0; i != limit; i += step, ++j, ++count)
1782 if(autocvar__hud_configure)
1784 attacker = sprintf(_("Player %d"), count + 1);
1785 victim = sprintf(_("Player %d"), count + 2);
1786 icon = get_weaponinfo(min(WEP_FIRST + count * 2, WEP_LAST)).model2;
1787 alpha = bound(0, 1.2 - count / entry_count, 1);
1791 if (j == NOTIFY_MAX_ENTRIES)
1794 if (notify_times[j] + fade_start > time)
1796 else if (fade_time != 0)
1798 alpha = bound(0, (notify_times[j] + fade_start + fade_time - time) / fade_time, 1);
1805 attacker = notify_attackers[j];
1806 victim = notify_victims[j];
1807 icon = notify_icons[j];
1810 if (icon != "" && victim != "")
1812 vector name_top = eY * (i * entry_height + 0.5 * (entry_height - font_size.y));
1814 icon_pos = pos + icon_left + eY * i * entry_height;
1815 drawpic_aspect_skin(icon_pos, icon, icon_size, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1817 victim = textShortenToWidth(victim, name_maxwidth, font_size, stringwidth_colors);
1818 victim_pos = pos + victim_left + name_top;
1819 drawcolorcodedstring(victim_pos, victim, font_size, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1823 attacker = textShortenToWidth(attacker, name_maxwidth, font_size, stringwidth_colors);
1824 attacker_pos = pos + attacker_right - eX * stringwidth(attacker, true, font_size) + name_top;
1825 drawcolorcodedstring(attacker_pos, attacker, font_size, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1830 notify_count = count;
1836 string seconds_tostring(float sec)
1839 minutes = floor(sec / 60);
1841 sec -= minutes * 60;
1842 return sprintf("%d:%02d", minutes, sec);
1845 void HUD_Timer(void)
1847 if(!autocvar__hud_configure)
1849 if(!autocvar_hud_panel_timer) return;
1852 HUD_Panel_UpdateCvars();
1854 draw_beginBoldFont();
1858 mySize = panel_size;
1860 HUD_Panel_DrawBg(1);
1861 if(panel_bg_padding)
1863 pos += '1 1 0' * panel_bg_padding;
1864 mySize -= '2 2 0' * panel_bg_padding;
1868 float timelimit, elapsedTime, timeleft, minutesLeft;
1870 timelimit = getstatf(STAT_TIMELIMIT);
1872 timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
1873 timeleft = ceil(timeleft);
1875 minutesLeft = floor(timeleft / 60);
1878 if(minutesLeft >= 5 || warmup_stage || timelimit == 0) //don't use red or yellow in warmup or when there is no timelimit
1879 timer_color = '1 1 1'; //white
1880 else if(minutesLeft >= 1)
1881 timer_color = '1 1 0'; //yellow
1883 timer_color = '1 0 0'; //red
1885 if (autocvar_hud_panel_timer_increment || timelimit == 0 || warmup_stage) {
1886 if (time < getstatf(STAT_GAMESTARTTIME)) {
1887 //while restart is still active, show 00:00
1888 timer = seconds_tostring(0);
1890 elapsedTime = floor(time - getstatf(STAT_GAMESTARTTIME)); //127
1891 timer = seconds_tostring(elapsedTime);
1894 timer = seconds_tostring(timeleft);
1897 drawstring_aspect(pos, timer, mySize, timer_color, panel_fg_alpha, DRAWFLAG_NORMAL);
1904 void HUD_Radar(void)
1906 if (!autocvar__hud_configure)
1908 if (hud_panel_radar_maximized)
1910 if (!hud_draw_maximized) return;
1914 if (autocvar_hud_panel_radar == 0) return;
1915 if (autocvar_hud_panel_radar != 2 && !teamplay) return;
1916 if(radar_panel_modified)
1918 panel.update_time = time; // forces reload of panel attributes
1919 radar_panel_modified = false;
1924 HUD_Panel_UpdateCvars();
1928 if (hud_panel_radar_maximized && !autocvar__hud_configure)
1930 panel_size = autocvar_hud_panel_radar_maximized_size;
1931 panel_size_x = bound(0.2, panel_size.x, 1) * vid_conwidth;
1932 panel_size_y = bound(0.2, panel_size.y, 1) * vid_conheight;
1933 panel_pos_x = (vid_conwidth - panel_size.x) / 2;
1934 panel_pos_y = (vid_conheight - panel_size.y) / 2;
1937 panel_bg = strcat(hud_skin_path, "/border_default"); // always use the default border when maximized
1938 if(precache_pic(panel_bg) == "")
1939 panel_bg = "gfx/hud/default/border_default"; // fallback
1940 if(!radar_panel_modified && panel_bg != panel.current_panel_bg)
1941 radar_panel_modified = true;
1942 if(panel.current_panel_bg)
1943 strunzone(panel.current_panel_bg);
1944 panel.current_panel_bg = strzone(panel_bg);
1946 switch(hud_panel_radar_maximized_zoommode)
1950 f = current_zoomfraction;
1953 f = 1 - current_zoomfraction;
1963 switch(hud_panel_radar_maximized_rotation)
1966 teamradar_angle = view_angles.y - 90;
1969 teamradar_angle = 90 * hud_panel_radar_maximized_rotation;
1973 if (!hud_panel_radar_maximized && !autocvar__hud_configure)
1975 switch(hud_panel_radar_zoommode)
1979 f = current_zoomfraction;
1982 f = 1 - current_zoomfraction;
1992 switch(hud_panel_radar_rotation)
1995 teamradar_angle = view_angles.y - 90;
1998 teamradar_angle = 90 * hud_panel_radar_rotation;
2005 mySize = panel_size;
2007 HUD_Panel_DrawBg(1);
2008 if(panel_bg_padding)
2010 pos += '1 1 0' * panel_bg_padding;
2011 mySize -= '2 2 0' * panel_bg_padding;
2016 float scale2d, normalsize, bigsize;
2018 teamradar_origin2d = pos + 0.5 * mySize;
2019 teamradar_size2d = mySize;
2021 if(minimapname == "")
2024 teamradar_loadcvars();
2026 scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
2027 teamradar_size2d = mySize;
2029 teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0'; // we always center
2031 // pixels per world qu to match the teamradar_size2d_x range in the longest dimension
2032 if((hud_panel_radar_rotation == 0 && !hud_panel_radar_maximized) || (hud_panel_radar_maximized_rotation == 0 && hud_panel_radar_maximized))
2034 // max-min distance must fit the radar in any rotation
2035 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen2d(mi_scale));
2039 vector c0, c1, c2, c3, span;
2040 c0 = rotate(mi_min, teamradar_angle * DEG2RAD);
2041 c1 = rotate(mi_max, teamradar_angle * DEG2RAD);
2042 c2 = rotate('1 0 0' * mi_min.x + '0 1 0' * mi_max.y, teamradar_angle * DEG2RAD);
2043 c3 = rotate('1 0 0' * mi_max.x + '0 1 0' * mi_min.y, teamradar_angle * DEG2RAD);
2045 span_x = max(c0_x, c1_x, c2_x, c3_x) - min(c0_x, c1_x, c2_x, c3_x);
2046 span_y = max(c0_y, c1_y, c2_y, c3_y) - min(c0_y, c1_y, c2_y, c3_y);
2048 // max-min distance must fit the radar in x=x, y=y
2050 teamradar_size2d.x * scale2d / (1.05 * span.x),
2051 teamradar_size2d.y * scale2d / (1.05 * span.y)
2055 normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / hud_panel_radar_scale;
2056 if(bigsize > normalsize)
2057 normalsize = bigsize;
2061 + (1 - f) * normalsize;
2062 teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
2064 + (1 - f) * view_origin);
2073 draw_teamradar_background(hud_panel_radar_foreground_alpha);
2075 for(tm = world; (tm = find(tm, classname, "radarlink")); )
2076 draw_teamradar_link(tm.origin, tm.velocity, tm.team);
2077 for(tm = world; (tm = findflags(tm, teamradar_icon, 0xFFFFFF)); )
2078 draw_teamradar_icon(tm.origin, tm.teamradar_icon, tm, tm.teamradar_color, panel_fg_alpha);
2079 for(tm = world; (tm = find(tm, classname, "entcs_receiver")); )
2081 color2 = GetPlayerColor(tm.sv_entnum);
2082 //if(color == NUM_SPECTATOR || color == color2)
2083 draw_teamradar_player(tm.origin, tm.angles, Team_ColorRGB(color2));
2085 draw_teamradar_player(view_origin, view_angles, '1 1 1');
2087 drawresetcliparea();
2092 void HUD_UpdatePlayerTeams();
2093 void HUD_Score_Rankings(vector pos, vector mySize, entity me)
2096 entity tm = world, pl;
2097 float SCOREPANEL_MAX_ENTRIES = 6;
2098 float SCOREPANEL_ASPECTRATIO = 2;
2099 float entries = bound(1, floor(SCOREPANEL_MAX_ENTRIES * mySize.y/mySize.x * SCOREPANEL_ASPECTRATIO), SCOREPANEL_MAX_ENTRIES);
2100 vector fontsize = '1 1 0' * (mySize.y/entries);
2102 vector rgb, score_color;
2104 score_color = '1 1 1';
2106 float name_size = mySize.x*0.75;
2107 float spacing_size = mySize.x*0.04;
2108 const float highlight_alpha = 0.2;
2109 float i = 0, me_printed = 0, first_pl = 0;
2111 if (autocvar__hud_configure)
2113 float players_per_team = 0;
2116 // show team scores in the first line
2117 float score_size = mySize.x / team_count;
2118 players_per_team = max(2, ceil((entries - 1) / team_count));
2119 for(i=0; i<team_count; ++i) {
2120 if (i == floor((entries - 2) / players_per_team) || (entries == 1 && i == 0))
2121 HUD_Panel_DrawHighlight(pos + eX * score_size * i, eX * score_size + eY * fontsize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2122 drawstring_aspect(pos + eX * score_size * i, ftos(175 - 23*i), eX * score_size + eY * fontsize.y, Team_ColorRGB(ColorByTeam(i)) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2125 pos.y += fontsize.y;
2127 score = 10 + SCOREPANEL_MAX_ENTRIES * 3;
2128 for (i=first_pl; i<entries; ++i)
2130 //simulate my score is lower than all displayed players,
2131 //so that I don't appear at all showing pure rankings.
2132 //This is to better show the difference between the 2 ranking views
2133 if (i == entries-1 && autocvar_hud_panel_score_rankings == 1)
2136 drawfill(pos, eX * mySize.x + eY * fontsize.y, rgb, highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2137 s = GetPlayerName(player_localnum);
2142 s = sprintf(_("Player %d"), i + 1 - first_pl);
2147 score_color = Team_ColorRGB(ColorByTeam(floor((i - first_pl) / players_per_team))) * 0.8;
2148 s = textShortenToWidth(s, name_size, fontsize, stringwidth_colors);
2149 drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, true, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
2150 drawstring(pos + eX * (name_size + spacing_size), ftos(score), fontsize, score_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2151 pos.y += fontsize.y;
2156 if (!scoreboard_fade_alpha) // the scoreboard too calls HUD_UpdatePlayerTeams
2157 HUD_UpdatePlayerTeams();
2160 // show team scores in the first line
2161 float score_size = mySize.x / team_count;
2162 for(tm = teams.sort_next; tm; tm = tm.sort_next) {
2163 if(tm.team == NUM_SPECTATOR)
2165 if (tm.team == myteam)
2166 drawfill(pos + eX * score_size * i, eX * score_size + eY * fontsize.y, '1 1 1', highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2167 drawstring_aspect(pos + eX * score_size * i, ftos(tm.(teamscores[ts_primary])), eX * score_size + eY * fontsize.y, Team_ColorRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2171 pos.y += fontsize.y;
2172 tm = teams.sort_next;
2177 for (pl = players.sort_next; pl && i<entries; pl = pl.sort_next)
2179 if ((team_count && pl.team != tm.team) || pl.team == NUM_SPECTATOR)
2182 if (i == entries-1 && !me_printed && pl != me)
2183 if (autocvar_hud_panel_score_rankings == 1 && spectatee_status != -1)
2185 for (pl = me.sort_next; pl; pl = pl.sort_next)
2186 if (pl.team != NUM_SPECTATOR)
2190 rgb = '1 1 0'; //not last but not among the leading players: yellow
2192 rgb = '1 0 0'; //last: red
2199 rgb = '0 1 0'; //first: green
2201 drawfill(pos, eX * mySize.x + eY * fontsize.y, rgb, highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2204 score_color = Team_ColorRGB(pl.team) * 0.8;
2205 s = textShortenToWidth(GetPlayerName(pl.sv_entnum), name_size, fontsize, stringwidth_colors);
2206 drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, true, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
2207 drawstring(pos + eX * (name_size + spacing_size), ftos(pl.(scores[ps_primary])), fontsize, score_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2208 pos.y += fontsize.y;
2211 while (i<entries && team_count && (tm = tm.sort_next) && (tm.team != NUM_SPECTATOR || (tm = tm.sort_next)));
2214 void HUD_Score(void)
2216 if(!autocvar__hud_configure)
2218 if(!autocvar_hud_panel_score) return;
2219 if(spectatee_status == -1 && (gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return;
2222 HUD_Panel_UpdateCvars();
2225 mySize = panel_size;
2227 HUD_Panel_DrawBg(1);
2228 if(panel_bg_padding)
2230 pos += '1 1 0' * panel_bg_padding;
2231 mySize -= '2 2 0' * panel_bg_padding;
2234 float score, distribution = 0;
2236 vector distribution_color;
2239 me = playerslots[player_localentnum - 1];
2241 if((scores_flags[ps_primary] & SFL_TIME) && !teamplay) { // race/cts record display on HUD
2242 string timer, distrtimer;
2244 pl = players.sort_next;
2247 if(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)
2248 if(pl.scores[ps_primary] == 0)
2251 score = me.(scores[ps_primary]);
2252 timer = TIME_ENCODED_TOSTRING(score);
2254 draw_beginBoldFont();
2255 if (pl && ((!(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)) || score)) {
2256 // distribution display
2257 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
2259 distrtimer = ftos_decimals(fabs(distribution/pow(10, TIME_DECIMALS)), TIME_DECIMALS);
2261 if (distribution <= 0) {
2262 distribution_color = '0 1 0';
2266 distribution_color = '1 0 0';
2269 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);
2271 // race record display
2272 if (distribution <= 0)
2273 HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2274 drawstring_aspect(pos, timer, eX * 0.75 * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2276 } else if (!teamplay) { // non-teamgames
2277 if ((spectatee_status == -1 && !autocvar__hud_configure) || autocvar_hud_panel_score_rankings)
2279 HUD_Score_Rankings(pos, mySize, me);
2282 // me vector := [team/connected frags id]
2283 pl = players.sort_next;
2287 if(autocvar__hud_configure)
2290 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
2294 score = me.(scores[ps_primary]);
2295 if(autocvar__hud_configure)
2298 if(distribution >= 5)
2299 distribution_color = eY;
2300 else if(distribution >= 0)
2301 distribution_color = '1 1 1';
2302 else if(distribution >= -5)
2303 distribution_color = '1 1 0';
2305 distribution_color = eX;
2307 string distribution_str;
2308 distribution_str = ftos(distribution);
2309 draw_beginBoldFont();
2310 if (distribution >= 0)
2312 if (distribution > 0)
2313 distribution_str = strcat("+", distribution_str);
2314 HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2316 drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize.x + eY * mySize.y, distribution_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2317 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);
2319 } else { // teamgames
2320 float row, column, rows = 0, columns = 0;
2321 vector offset = '0 0 0';
2322 vector score_pos, score_size; //for scores other than myteam
2323 if(autocvar_hud_panel_score_rankings)
2325 HUD_Score_Rankings(pos, mySize, me);
2328 if(spectatee_status == -1)
2330 rows = mySize.y/mySize.x;
2331 rows = bound(1, floor((sqrt(4 * (3/1) * rows * team_count + rows * rows) + rows + 0.5) / 2), team_count);
2332 // ^^^ ammo item aspect goes here
2334 columns = ceil(team_count/rows);
2336 score_size = eX * mySize.x*(1/columns) + eY * mySize.y*(1/rows);
2339 if(score_size.x/score_size.y > 3)
2341 newSize = 3 * score_size.y;
2342 offset_x = score_size.x - newSize;
2343 pos.x += offset.x/2;
2344 score_size_x = newSize;
2348 newSize = 1/3 * score_size.x;
2349 offset_y = score_size.y - newSize;
2350 pos.y += offset.y/2;
2351 score_size_y = newSize;
2355 score_size = eX * mySize.x*(1/4) + eY * mySize.y*(1/3);
2357 float max_fragcount;
2358 max_fragcount = -99;
2359 draw_beginBoldFont();
2361 for(tm = teams.sort_next; tm; tm = tm.sort_next) {
2362 if(tm.team == NUM_SPECTATOR)
2364 score = tm.(teamscores[ts_primary]);
2365 if(autocvar__hud_configure)
2368 if (score > max_fragcount)
2369 max_fragcount = score;
2371 if (spectatee_status == -1)
2373 score_pos = pos + eX * column * (score_size.x + offset.x) + eY * row * (score_size.y + offset.y);
2374 if (max_fragcount == score)
2375 HUD_Panel_DrawHighlight(score_pos, score_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2376 drawstring_aspect(score_pos, ftos(score), score_size, Team_ColorRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2384 else if(tm.team == myteam) {
2385 if (max_fragcount == score)
2386 HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2387 drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize.x + eY * mySize.y, Team_ColorRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2389 if (max_fragcount == score)
2390 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);
2391 drawstring_aspect(pos + eX * 0.75 * mySize.x + eY * (1/3) * rows * mySize.y, ftos(score), score_size, Team_ColorRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2401 void HUD_RaceTimer (void)
2403 if(!autocvar__hud_configure)
2405 if(!autocvar_hud_panel_racetimer) return;
2406 if(!(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return;
2407 if(spectatee_status == -1) return;
2410 HUD_Panel_UpdateCvars();
2412 draw_beginBoldFont();
2416 mySize = panel_size;
2418 HUD_Panel_DrawBg(1);
2419 if(panel_bg_padding)
2421 pos += '1 1 0' * panel_bg_padding;
2422 mySize -= '2 2 0' * panel_bg_padding;
2425 // always force 4:1 aspect
2426 vector newSize = '0 0 0';
2427 if(mySize.x/mySize.y > 4)
2429 newSize_x = 4 * mySize.y;
2430 newSize_y = mySize.y;
2432 pos_x = pos.x + (mySize.x - newSize.x) / 2;
2436 newSize_y = 1/4 * mySize.x;
2437 newSize_x = mySize.x;
2439 pos_y = pos.y + (mySize.y - newSize.y) / 2;
2444 string s, forcetime;
2446 if(autocvar__hud_configure)
2449 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);
2450 s = _("^1Intermediate 1 (+15.42)");
2451 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);
2452 s = sprintf(_("^1PENALTY: %.1f (%s)"), 2, "missing a checkpoint");
2453 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);
2455 else if(race_checkpointtime)
2457 a = bound(0, 2 - (time - race_checkpointtime), 1);
2460 if(a > 0) // just hit a checkpoint?
2462 if(race_checkpoint != 254)
2464 if(race_time && race_previousbesttime)
2465 s = MakeRaceString(race_checkpoint, TIME_DECODE(race_time) - TIME_DECODE(race_previousbesttime), 0, 0, race_previousbestname);
2467 s = MakeRaceString(race_checkpoint, 0, -1, 0, race_previousbestname);
2469 forcetime = TIME_ENCODED_TOSTRING(race_time);
2474 if(race_laptime && race_nextbesttime && race_nextcheckpoint != 254)
2476 a = bound(0, 2 - ((race_laptime + TIME_DECODE(race_nextbesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1);
2477 if(a > 0) // next one?
2479 s = MakeRaceString(race_nextcheckpoint, (time + TIME_DECODE(race_penaltyaccumulator)) - race_laptime, TIME_DECODE(race_nextbesttime), 0, race_nextbestname);
2484 if(s != "" && a > 0)
2486 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);
2489 if(race_penaltytime)
2491 a = bound(0, 2 - (time - race_penaltyeventtime), 1);
2494 s = sprintf(_("^1PENALTY: %.1f (%s)"), race_penaltytime * 0.1, race_penaltyreason);
2495 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);
2501 a = bound(0, (time - race_checkpointtime) / 0.5, 1);
2502 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);
2507 if(race_laptime && race_checkpoint != 255)
2509 s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime));
2510 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);
2515 if(race_mycheckpointtime)
2517 a = bound(0, 2 - (time - race_mycheckpointtime), 1);
2518 s = MakeRaceString(race_mycheckpoint, TIME_DECODE(race_mycheckpointdelta), -(race_mycheckpointenemy == ""), race_mycheckpointlapsdelta, race_mycheckpointenemy);
2519 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);
2521 if(race_othercheckpointtime && race_othercheckpointenemy != "")
2523 a = bound(0, 2 - (time - race_othercheckpointtime), 1);
2524 s = MakeRaceString(race_othercheckpoint, -TIME_DECODE(race_othercheckpointdelta), -(race_othercheckpointenemy == ""), race_othercheckpointlapsdelta, race_othercheckpointenemy);
2525 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);
2528 if(race_penaltytime && !race_penaltyaccumulator)
2530 t = race_penaltytime * 0.1 + race_penaltyeventtime;
2531 a = bound(0, (1 + t - time), 1);
2535 s = sprintf(_("^1PENALTY: %.1f (%s)"), (t - time) * 0.1, race_penaltyreason);
2537 s = sprintf(_("^2PENALTY: %.1f (%s)"), 0, race_penaltyreason);
2538 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);
2548 float vote_yescount;
2551 float vote_highlighted; // currently selected vote
2553 float vote_active; // is there an active vote?
2554 float vote_prev; // previous state of vote_active to check for a change
2556 float vote_change; // "time" when vote_active changed
2560 if(autocvar_cl_allow_uid2name == -1 && (gametype == MAPINFO_TYPE_CTS || gametype == MAPINFO_TYPE_RACE || (serverflags & SERVERFLAG_PLAYERSTATS)))
2563 if (autocvar__hud_configure)
2567 print(_("^1You must answer before entering hud configure mode\n"));
2568 cvar_set("_hud_configure", "0");
2570 if(vote_called_vote)
2571 strunzone(vote_called_vote);
2572 vote_called_vote = strzone(_("^2Name ^7instead of \"^1Anonymous player^7\" in stats"));
2573 uid2name_dialog = 1;
2576 if(!autocvar__hud_configure)
2578 if(!autocvar_hud_panel_vote) return;
2580 panel_fg_alpha = autocvar_hud_panel_fg_alpha;
2581 panel_bg_alpha_str = autocvar_hud_panel_vote_bg_alpha;
2583 if(panel_bg_alpha_str == "") {
2584 panel_bg_alpha_str = ftos(autocvar_hud_panel_bg_alpha);
2586 panel_bg_alpha = stof(panel_bg_alpha_str);
2597 if(vote_active != vote_prev) {
2599 vote_prev = vote_active;
2602 if(vote_active || autocvar__hud_configure)
2603 vote_alpha = bound(0, (time - vote_change) * 2, 1);
2605 vote_alpha = bound(0, 1 - (time - vote_change) * 2, 1);
2610 HUD_Panel_UpdateCvars();
2614 panel_pos = eX * 0.3 * vid_conwidth + eY * 0.1 * vid_conheight;
2615 panel_size = eX * 0.4 * vid_conwidth + eY * 0.3 * vid_conheight;
2618 // these must be below above block
2621 mySize = panel_size;
2623 a = vote_alpha * (vote_highlighted ? autocvar_hud_panel_vote_alreadyvoted_alpha : 1);
2624 HUD_Panel_DrawBg(a);
2625 a = panel_fg_alpha * a;
2627 if(panel_bg_padding)
2629 pos += '1 1 0' * panel_bg_padding;
2630 mySize -= '2 2 0' * panel_bg_padding;
2633 // always force 3:1 aspect
2634 vector newSize = '0 0 0';
2635 if(mySize.x/mySize.y > 3)
2637 newSize_x = 3 * mySize.y;
2638 newSize_y = mySize.y;
2640 pos_x = pos.x + (mySize.x - newSize.x) / 2;
2644 newSize_y = 1/3 * mySize.x;
2645 newSize_x = mySize.x;
2647 pos_y = pos.y + (mySize.y - newSize.y) / 2;
2651 s = _("A vote has been called for:");
2653 s = _("Allow servers to store and display your name?");
2654 drawstring_aspect(pos, s, eX * mySize.x + eY * (2/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
2655 s = textShortenToWidth(vote_called_vote, mySize.x, '1 1 0' * mySize.y * (1/8), stringwidth_colors);
2656 if(autocvar__hud_configure)
2657 s = _("^1Configure the HUD");
2658 drawcolorcodedstring_aspect(pos + eY * (2/8) * mySize.y, s, eX * mySize.x + eY * (1.75/8) * mySize.y, a, DRAWFLAG_NORMAL);
2660 // print the yes/no counts
2661 s = sprintf(_("Yes (%s): %d"), getcommandkey("vyes", "vyes"), vote_yescount);
2662 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);
2663 s = sprintf(_("No (%s): %d"), getcommandkey("vno", "vno"), vote_nocount);
2664 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);
2666 // draw the progress bar backgrounds
2667 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_back", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
2669 // draw the highlights
2670 if(vote_highlighted == 1) {
2671 drawsetcliparea(pos.x, pos.y, mySize.x * 0.5, mySize.y);
2672 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_voted", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
2674 else if(vote_highlighted == -1) {
2675 drawsetcliparea(pos.x + 0.5 * mySize.x, pos.y, mySize.x * 0.5, mySize.y);
2676 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_voted", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
2679 // draw the progress bars
2680 if(vote_yescount && vote_needed)
2682 drawsetcliparea(pos.x, pos.y, mySize.x * 0.5 * (vote_yescount/vote_needed), mySize.y);
2683 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_prog", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
2686 if(vote_nocount && vote_needed)
2688 drawsetcliparea(pos.x + mySize.x - mySize.x * 0.5 * (vote_nocount/vote_needed), pos.y, mySize.x * 0.5, mySize.y);
2689 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_prog", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
2692 drawresetcliparea();
2695 // Mod icons panel (#10)
2698 float mod_active; // is there any active mod icon?
2700 void DrawCAItem(vector myPos, vector mySize, float aspect_ratio, int layout, float i)
2704 vector color = '0 0 0';
2708 stat = getstati(STAT_REDALIVE);
2709 pic = "player_red.tga";
2713 stat = getstati(STAT_BLUEALIVE);
2714 pic = "player_blue.tga";
2718 stat = getstati(STAT_YELLOWALIVE);
2719 pic = "player_yellow.tga";
2724 stat = getstati(STAT_PINKALIVE);
2725 pic = "player_pink.tga";
2730 if(mySize.x/mySize.y > aspect_ratio)
2732 i = aspect_ratio * mySize.y;
2733 myPos_x = myPos.x + (mySize.x - i) / 2;
2738 i = 1/aspect_ratio * mySize.x;
2739 myPos_y = myPos.y + (mySize.y - i) / 2;
2745 drawpic_aspect_skin(myPos, pic, eX * 0.7 * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2746 drawstring_aspect(myPos + eX * 0.7 * mySize.x, ftos(stat), eX * 0.3 * mySize.x + eY * mySize.y, color, panel_fg_alpha, DRAWFLAG_NORMAL);
2749 drawstring_aspect(myPos, ftos(stat), mySize, color, panel_fg_alpha, DRAWFLAG_NORMAL);
2752 // Clan Arena and Freeze Tag HUD modicons
2753 void HUD_Mod_CA(vector myPos, vector mySize)
2755 mod_active = 1; // required in each mod function that always shows something
2758 if(gametype == MAPINFO_TYPE_CA)
2759 layout = autocvar_hud_panel_modicons_ca_layout;
2760 else //if(gametype == MAPINFO_TYPE_FREEZETAG)
2761 layout = autocvar_hud_panel_modicons_freezetag_layout;
2762 float rows, columns, aspect_ratio;
2763 rows = mySize.y/mySize.x;
2764 aspect_ratio = (layout) ? 2 : 1;
2765 rows = bound(1, floor((sqrt((4 * aspect_ratio * team_count + rows) * rows) + rows + 0.5) / 2), team_count);
2766 columns = ceil(team_count/rows);
2769 float row = 0, column = 0;
2770 vector pos, itemSize;
2771 itemSize = eX * mySize.x*(1/columns) + eY * mySize.y*(1/rows);
2772 for(i=0; i<team_count; ++i)
2774 pos = myPos + eX * column * itemSize.x + eY * row * itemSize.y;
2776 DrawCAItem(pos, itemSize, aspect_ratio, layout, i);
2787 // CTF HUD modicon section
2788 float redflag_prevframe, blueflag_prevframe; // status during previous frame
2789 float redflag_prevstatus, blueflag_prevstatus; // last remembered status
2790 float redflag_statuschange_time, blueflag_statuschange_time; // time when the status changed
2792 void HUD_Mod_CTF_Reset(void)
2794 redflag_prevstatus = blueflag_prevstatus = redflag_prevframe = blueflag_prevframe = redflag_statuschange_time = blueflag_statuschange_time = 0;
2797 void HUD_Mod_CTF(vector pos, vector mySize)
2799 vector redflag_pos, blueflag_pos;
2801 float f; // every function should have that
2803 float redflag, blueflag; // current status
2804 float redflag_statuschange_elapsedtime, blueflag_statuschange_elapsedtime; // time since the status changed
2807 stat_items = getstati(STAT_ITEMS, 0, 24);
2808 redflag = (stat_items/IT_RED_FLAG_TAKEN) & 3;
2809 blueflag = (stat_items/IT_BLUE_FLAG_TAKEN) & 3;
2811 if(redflag || blueflag)
2816 if(autocvar__hud_configure)
2822 // when status CHANGES, set old status into prevstatus and current status into status
2823 if (redflag != redflag_prevframe)
2825 redflag_statuschange_time = time;
2826 redflag_prevstatus = redflag_prevframe;
2827 redflag_prevframe = redflag;
2830 if (blueflag != blueflag_prevframe)
2832 blueflag_statuschange_time = time;
2833 blueflag_prevstatus = blueflag_prevframe;
2834 blueflag_prevframe = blueflag;
2837 redflag_statuschange_elapsedtime = time - redflag_statuschange_time;
2838 blueflag_statuschange_elapsedtime = time - blueflag_statuschange_time;
2840 float BLINK_FACTOR = 0.15;
2841 float BLINK_BASE = 0.85;
2843 // RMS = sqrt(BLINK_BASE^2 + 0.5 * BLINK_FACTOR^2)
2845 // BLINK_BASE = sqrt(RMS^2 - 0.5 * BLINK_FACTOR^2)
2847 float BLINK_FREQ = 5; // circle frequency, = 2*pi*frequency in hertz
2849 string red_icon, red_icon_prevstatus;
2850 float red_alpha, red_alpha_prevstatus;
2851 red_alpha = red_alpha_prevstatus = 1;
2853 case 1: red_icon = "flag_red_taken"; break;
2854 case 2: red_icon = "flag_red_lost"; break;
2855 case 3: red_icon = "flag_red_carrying"; red_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
2857 if((stat_items & IT_CTF_SHIELDED) && (myteam == NUM_TEAM_2))
2858 red_icon = "flag_red_shielded";
2860 red_icon = string_null;
2863 switch(redflag_prevstatus) {
2864 case 1: red_icon_prevstatus = "flag_red_taken"; break;
2865 case 2: red_icon_prevstatus = "flag_red_lost"; break;
2866 case 3: red_icon_prevstatus = "flag_red_carrying"; red_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
2869 red_icon_prevstatus = "flag_red_carrying"; // make it more visible
2870 else if((stat_items & IT_CTF_SHIELDED) && (myteam == NUM_TEAM_2))
2871 red_icon_prevstatus = "flag_red_shielded";
2873 red_icon_prevstatus = string_null;
2877 string blue_icon, blue_icon_prevstatus;
2878 float blue_alpha, blue_alpha_prevstatus;
2879 blue_alpha = blue_alpha_prevstatus = 1;
2881 case 1: blue_icon = "flag_blue_taken"; break;
2882 case 2: blue_icon = "flag_blue_lost"; break;
2883 case 3: blue_icon = "flag_blue_carrying"; blue_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
2885 if((stat_items & IT_CTF_SHIELDED) && (myteam == NUM_TEAM_1))
2886 blue_icon = "flag_blue_shielded";
2888 blue_icon = string_null;
2891 switch(blueflag_prevstatus) {
2892 case 1: blue_icon_prevstatus = "flag_blue_taken"; break;
2893 case 2: blue_icon_prevstatus = "flag_blue_lost"; break;
2894 case 3: blue_icon_prevstatus = "flag_blue_carrying"; blue_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
2897 blue_icon_prevstatus = "flag_blue_carrying"; // make it more visible
2898 else if((stat_items & IT_CTF_SHIELDED) && (myteam == NUM_TEAM_1))
2899 blue_icon_prevstatus = "flag_blue_shielded";
2901 blue_icon_prevstatus = string_null;
2905 if(mySize.x > mySize.y) {
2906 if (myteam == NUM_TEAM_1) { // always draw own flag on left
2908 blueflag_pos = pos + eX * 0.5 * mySize.x;
2911 redflag_pos = pos + eX * 0.5 * mySize.x;
2913 flag_size = eX * 0.5 * mySize.x + eY * mySize.y;
2915 if (myteam == NUM_TEAM_1) { // always draw own flag on left
2917 blueflag_pos = pos + eY * 0.5 * mySize.y;
2920 redflag_pos = pos + eY * 0.5 * mySize.y;
2922 flag_size = eY * 0.5 * mySize.y + eX * mySize.x;
2925 f = bound(0, redflag_statuschange_elapsedtime*2, 1);
2926 if(red_icon_prevstatus && f < 1)
2927 drawpic_aspect_skin_expanding(redflag_pos, red_icon_prevstatus, flag_size, '1 1 1', panel_fg_alpha * red_alpha_prevstatus, DRAWFLAG_NORMAL, f);
2929 drawpic_aspect_skin(redflag_pos, red_icon, flag_size, '1 1 1', panel_fg_alpha * red_alpha * f, DRAWFLAG_NORMAL);
2931 f = bound(0, blueflag_statuschange_elapsedtime*2, 1);
2932 if(blue_icon_prevstatus && f < 1)
2933 drawpic_aspect_skin_expanding(blueflag_pos, blue_icon_prevstatus, flag_size, '1 1 1', panel_fg_alpha * blue_alpha_prevstatus, DRAWFLAG_NORMAL, f);
2935 drawpic_aspect_skin(blueflag_pos, blue_icon, flag_size, '1 1 1', panel_fg_alpha * blue_alpha * f, DRAWFLAG_NORMAL);
2938 // Keyhunt HUD modicon section
2941 void HUD_Mod_KH(vector pos, vector mySize)
2943 mod_active = 1; // keyhunt should never hide the mod icons panel
2945 // Read current state
2947 float state = getstati(STAT_KH_KEYS);
2949 float all_keys, team1_keys, team2_keys, team3_keys, team4_keys, dropped_keys, carrying_keys;
2950 all_keys = team1_keys = team2_keys = team3_keys = team4_keys = dropped_keys = carrying_keys = 0;
2952 for(i = 0; i < 4; ++i)
2954 key_state = (bitshift(state, i * -5) & 31) - 1;
2967 case NUM_TEAM_1: ++team1_keys; break;
2968 case NUM_TEAM_2: ++team2_keys; break;
2969 case NUM_TEAM_3: ++team3_keys; break;
2970 case NUM_TEAM_4: ++team4_keys; break;
2971 case 29: ++dropped_keys; break;
2977 // Calculate slot measurements
2981 if(all_keys == 4 && mySize.x * 0.5 < mySize.y && mySize.y * 0.5 < mySize.x)
2983 // Quadratic arrangement
2984 slot_size = eX * mySize.x * 0.5 + eY * mySize.y * 0.5;
2986 KH_SLOTS[1] = pos + eX * slot_size.x;
2987 KH_SLOTS[2] = pos + eY * slot_size.y;
2988 KH_SLOTS[3] = pos + eX * slot_size.x + eY * slot_size.y;
2992 if(mySize.x > mySize.y)
2994 // Horizontal arrangement
2995 slot_size = eX * mySize.x / all_keys + eY * mySize.y;
2996 for(i = 0; i < all_keys; ++i)
2997 KH_SLOTS[i] = pos + eX * slot_size.x * i;
3001 // Vertical arrangement
3002 slot_size = eX * mySize.x + eY * mySize.y / all_keys;
3003 for(i = 0; i < all_keys; ++i)
3004 KH_SLOTS[i] = pos + eY * slot_size.y * i;
3008 // Make icons blink in case of RUN HERE
3010 float blink = 0.6 + sin(2*M_PI*time) / 2.5; // Oscillate between 0.2 and 1
3017 case NUM_TEAM_1: if(team1_keys == all_keys) alpha = blink; break;
3018 case NUM_TEAM_2: if(team2_keys == all_keys) alpha = blink; break;
3019 case NUM_TEAM_3: if(team3_keys == all_keys) alpha = blink; break;
3020 case NUM_TEAM_4: if(team4_keys == all_keys) alpha = blink; break;
3028 if(myteam == NUM_TEAM_1 && carrying_keys)
3030 drawpic_aspect_skin(KH_SLOTS[i++], "kh_red_carrying", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3034 drawpic_aspect_skin(KH_SLOTS[i++], "kh_red_taken", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3037 if(myteam == NUM_TEAM_2 && carrying_keys)
3039 drawpic_aspect_skin(KH_SLOTS[i++], "kh_blue_carrying", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3043 drawpic_aspect_skin(KH_SLOTS[i++], "kh_blue_taken", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3046 if(myteam == NUM_TEAM_3 && carrying_keys)
3048 drawpic_aspect_skin(KH_SLOTS[i++], "kh_yellow_carrying", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3052 drawpic_aspect_skin(KH_SLOTS[i++], "kh_yellow_taken", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3055 if(myteam == NUM_TEAM_4 && carrying_keys)
3057 drawpic_aspect_skin(KH_SLOTS[i++], "kh_pink_carrying", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3061 drawpic_aspect_skin(KH_SLOTS[i++], "kh_pink_taken", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3063 while(dropped_keys--)
3064 drawpic_aspect_skin(KH_SLOTS[i++], "kh_dropped", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3067 // Keepaway HUD mod icon
3068 float kaball_prevstatus; // last remembered status
3069 float kaball_statuschange_time; // time when the status changed
3071 // we don't need to reset for keepaway since it immediately
3072 // autocorrects prevstatus as to if the player has the ball or not
3074 void HUD_Mod_Keepaway(vector pos, vector mySize)
3076 mod_active = 1; // keepaway should always show the mod HUD
3078 float BLINK_FACTOR = 0.15;
3079 float BLINK_BASE = 0.85;
3080 float BLINK_FREQ = 5;
3081 float kaball_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ);
3083 float stat_items = getstati(STAT_ITEMS, 0, 24);
3084 float kaball = (stat_items/IT_KEY1) & 1;
3086 if(kaball != kaball_prevstatus)
3088 kaball_statuschange_time = time;
3089 kaball_prevstatus = kaball;
3092 vector kaball_pos, kaball_size;
3094 if(mySize.x > mySize.y) {
3095 kaball_pos = pos + eX * 0.25 * mySize.x;
3096 kaball_size = eX * 0.5 * mySize.x + eY * mySize.y;
3098 kaball_pos = pos + eY * 0.25 * mySize.y;
3099 kaball_size = eY * 0.5 * mySize.y + eX * mySize.x;
3102 float kaball_statuschange_elapsedtime = time - kaball_statuschange_time;
3103 float f = bound(0, kaball_statuschange_elapsedtime*2, 1);
3105 if(kaball_prevstatus && f < 1)
3106 drawpic_aspect_skin_expanding(kaball_pos, "keepawayball_carrying", kaball_size, '1 1 1', panel_fg_alpha * kaball_alpha, DRAWFLAG_NORMAL, f);
3109 drawpic_aspect_skin(pos, "keepawayball_carrying", eX * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha * kaball_alpha * f, DRAWFLAG_NORMAL);
3113 // Nexball HUD mod icon
3114 void HUD_Mod_NexBall(vector pos, vector mySize)
3116 float stat_items, nb_pb_starttime, dt, p;
3118 stat_items = getstati(STAT_ITEMS, 0, 24);
3119 nb_pb_starttime = getstatf(STAT_NB_METERSTART);
3121 if (stat_items & IT_KEY1)
3126 //Manage the progress bar if any
3127 if (nb_pb_starttime > 0)
3129 dt = (time - nb_pb_starttime) % nb_pb_period;
3130 // one period of positive triangle
3131 p = 2 * dt / nb_pb_period;
3135 HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", p, (mySize.x <= mySize.y), 0, autocvar_hud_progressbar_nexball_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
3138 if (stat_items & IT_KEY1)
3139 drawpic_aspect_skin(pos, "nexball_carrying", eX * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3142 // Race/CTS HUD mod icons
3143 float crecordtime_prev; // last remembered crecordtime
3144 float crecordtime_change_time; // time when crecordtime last changed
3145 float srecordtime_prev; // last remembered srecordtime
3146 float srecordtime_change_time; // time when srecordtime last changed
3148 float race_status_time;
3149 float race_status_prev;
3150 string race_status_name_prev;
3151 void HUD_Mod_Race(vector pos, vector mySize)
3153 mod_active = 1; // race should never hide the mod icons panel
3155 me = playerslots[player_localnum];
3157 float f; // yet another function has this
3158 score = me.(scores[ps_primary]);
3160 if(!(scores_flags[ps_primary] & SFL_TIME) || teamplay) // race/cts record display on HUD
3161 return; // no records in the actual race
3163 // clientside personal record
3165 if(gametype == MAPINFO_TYPE_CTS)
3169 t = stof(db_get(ClientProgsDB, strcat(shortmapname, rr, "time")));
3171 if(score && (score < t || !t)) {
3172 db_put(ClientProgsDB, strcat(shortmapname, rr, "time"), ftos(score));
3173 if(autocvar_cl_autodemo_delete_keeprecords)
3175 f = autocvar_cl_autodemo_delete;
3177 cvar_set("cl_autodemo_delete", ftos(f)); // don't delete demo with new record!
3181 if(t != crecordtime_prev) {
3182 crecordtime_prev = t;
3183 crecordtime_change_time = time;
3186 vector textPos, medalPos;
3188 if(mySize.x > mySize.y) {
3189 // text on left side
3190 squareSize = min(mySize.y, mySize.x/2);
3191 textPos = pos + eX * 0.5 * max(0, mySize.x/2 - squareSize) + eY * 0.5 * (mySize.y - squareSize);
3192 medalPos = pos + eX * 0.5 * max(0, mySize.x/2 - squareSize) + eX * 0.5 * mySize.x + eY * 0.5 * (mySize.y - squareSize);
3195 squareSize = min(mySize.x, mySize.y/2);
3196 textPos = pos + eY * 0.5 * max(0, mySize.y/2 - squareSize) + eX * 0.5 * (mySize.x - squareSize);
3197 medalPos = pos + eY * 0.5 * max(0, mySize.y/2 - squareSize) + eY * 0.5 * mySize.y + eX * 0.5 * (mySize.x - squareSize);
3200 f = time - crecordtime_change_time;
3203 drawstring_aspect(textPos, _("Personal best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3204 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);
3206 drawstring_aspect(textPos, _("Personal best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3207 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);
3208 drawstring_aspect_expanding(pos, _("Personal best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
3209 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);
3213 t = race_server_record;
3214 if(t != srecordtime_prev) {
3215 srecordtime_prev = t;
3216 srecordtime_change_time = time;
3218 f = time - srecordtime_change_time;
3221 drawstring_aspect(textPos + eY * 0.5 * squareSize, _("Server best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3222 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);
3224 drawstring_aspect(textPos + eY * 0.5 * squareSize, _("Server best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3225 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);
3226 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);
3227 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);
3230 if (race_status != race_status_prev || race_status_name != race_status_name_prev) {
3231 race_status_time = time + 5;
3232 race_status_prev = race_status;
3233 if (race_status_name_prev)
3234 strunzone(race_status_name_prev);
3235 race_status_name_prev = strzone(race_status_name);
3240 a = bound(0, race_status_time - time, 1);
3243 s = textShortenToWidth(race_status_name, squareSize, '1 1 0' * 0.1 * squareSize, stringwidth_colors);
3247 rank = race_CheckName(race_status_name);
3251 rankname = count_ordinal(rank);
3254 namepos = medalPos + '0 0.8 0' * squareSize;
3256 rankpos = medalPos + '0 0.15 0' * squareSize;
3258 if(race_status == 0)
3259 drawpic_aspect_skin(medalPos, "race_newfail", '1 1 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3260 else if(race_status == 1) {
3261 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);
3262 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3263 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3264 } else if(race_status == 2) {
3265 if(race_status_name == GetPlayerName(player_localnum) || !race_myrank || race_myrank < rank)
3266 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);
3268 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);
3269 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3270 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3271 } else if(race_status == 3) {
3272 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);
3273 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3274 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3277 if (race_status_time - time <= 0) {
3278 race_status_prev = -1;
3280 if(race_status_name)
3281 strunzone(race_status_name);
3282 race_status_name = string_null;
3283 if(race_status_name_prev)
3284 strunzone(race_status_name_prev);
3285 race_status_name_prev = string_null;
3289 void DrawDomItem(vector myPos, vector mySize, float aspect_ratio, int layout, float i)
3293 vector color = '0 0 0';
3297 stat = getstatf(STAT_DOM_PPS_RED);
3298 pic = "dom_icon_red";
3302 stat = getstatf(STAT_DOM_PPS_BLUE);
3303 pic = "dom_icon_blue";
3307 stat = getstatf(STAT_DOM_PPS_YELLOW);
3308 pic = "dom_icon_yellow";
3313 stat = getstatf(STAT_DOM_PPS_PINK);
3314 pic = "dom_icon_pink";
3318 float pps_ratio = stat / getstatf(STAT_DOM_TOTAL_PPS);
3320 if(mySize.x/mySize.y > aspect_ratio)
3322 i = aspect_ratio * mySize.y;
3323 myPos_x = myPos.x + (mySize.x - i) / 2;
3328 i = 1/aspect_ratio * mySize.x;
3329 myPos_y = myPos.y + (mySize.y - i) / 2;
3333 if (layout) // show text too
3336 color *= 0.5 + pps_ratio * (1 - 0.5); // half saturated color at min, full saturated at max
3337 if (layout == 2) // average pps
3338 drawstring_aspect(myPos + eX * mySize.y, ftos_decimals(stat, 2), eX * (2/3) * mySize.x + eY * mySize.y, color, panel_fg_alpha, DRAWFLAG_NORMAL);
3339 else // percentage of average pps
3340 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);
3344 drawpic_aspect_skin(myPos, pic, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3347 drawsetcliparea(myPos.x, myPos.y + mySize.y * (1 - pps_ratio), mySize.y, mySize.y * pps_ratio);
3348 drawpic_aspect_skin(myPos, strcat(pic, "-highlighted"), '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3349 drawresetcliparea();
3353 void HUD_Mod_Dom(vector myPos, vector mySize)
3355 mod_active = 1; // required in each mod function that always shows something
3357 int layout = autocvar_hud_panel_modicons_dom_layout;
3358 float rows, columns, aspect_ratio;
3359 rows = mySize.y/mySize.x;
3360 aspect_ratio = (layout) ? 3 : 1;
3361 rows = bound(1, floor((sqrt((4 * aspect_ratio * team_count + rows) * rows) + rows + 0.5) / 2), team_count);
3362 columns = ceil(team_count/rows);
3365 float row = 0, column = 0;
3366 vector pos, itemSize;
3367 itemSize = eX * mySize.x*(1/columns) + eY * mySize.y*(1/rows);
3368 for(i=0; i<team_count; ++i)
3370 pos = myPos + eX * column * itemSize.x + eY * row * itemSize.y;
3372 DrawDomItem(pos, itemSize, aspect_ratio, layout, i);
3383 void HUD_ModIcons_SetFunc()
3387 case MAPINFO_TYPE_KEYHUNT: HUD_ModIcons_GameType = HUD_Mod_KH; break;
3388 case MAPINFO_TYPE_CTF: HUD_ModIcons_GameType = HUD_Mod_CTF; break;
3389 case MAPINFO_TYPE_NEXBALL: HUD_ModIcons_GameType = HUD_Mod_NexBall; break;
3390 case MAPINFO_TYPE_CTS:
3391 case MAPINFO_TYPE_RACE: HUD_ModIcons_GameType = HUD_Mod_Race; break;
3392 case MAPINFO_TYPE_CA:
3393 case MAPINFO_TYPE_FREEZETAG: HUD_ModIcons_GameType = HUD_Mod_CA; break;
3394 case MAPINFO_TYPE_DOMINATION: HUD_ModIcons_GameType = HUD_Mod_Dom; break;
3395 case MAPINFO_TYPE_KEEPAWAY: HUD_ModIcons_GameType = HUD_Mod_Keepaway; break;
3399 float mod_prev; // previous state of mod_active to check for a change
3401 float mod_change; // "time" when mod_active changed
3403 void HUD_ModIcons(void)
3405 if(!autocvar__hud_configure)
3407 if(!autocvar_hud_panel_modicons) return;
3408 if(!HUD_ModIcons_GameType) return;
3411 HUD_Panel_UpdateCvars();
3413 draw_beginBoldFont();
3415 if(mod_active != mod_prev) {
3417 mod_prev = mod_active;
3420 if(mod_active || autocvar__hud_configure)
3421 mod_alpha = bound(0, (time - mod_change) * 2, 1);
3423 mod_alpha = bound(0, 1 - (time - mod_change) * 2, 1);
3426 HUD_Panel_DrawBg(mod_alpha);
3428 if(panel_bg_padding)
3430 panel_pos += '1 1 0' * panel_bg_padding;
3431 panel_size -= '2 2 0' * panel_bg_padding;
3434 if(autocvar__hud_configure)
3435 HUD_Mod_CTF(panel_pos, panel_size);
3437 HUD_ModIcons_GameType(panel_pos, panel_size);
3442 // Draw pressed keys (#11)
3444 void HUD_PressedKeys(void)
3446 if(!autocvar__hud_configure)
3448 if(!autocvar_hud_panel_pressedkeys) return;
3449 if(spectatee_status <= 0 && autocvar_hud_panel_pressedkeys < 2) return;
3452 HUD_Panel_UpdateCvars();
3455 mySize = panel_size;
3457 HUD_Panel_DrawBg(1);
3458 if(panel_bg_padding)
3460 pos += '1 1 0' * panel_bg_padding;
3461 mySize -= '2 2 0' * panel_bg_padding;
3464 // force custom aspect
3465 float aspect = autocvar_hud_panel_pressedkeys_aspect;
3468 vector newSize = '0 0 0';
3469 if(mySize.x/mySize.y > aspect)
3471 newSize_x = aspect * mySize.y;
3472 newSize_y = mySize.y;
3474 pos_x = pos.x + (mySize.x - newSize.x) / 2;
3478 newSize_y = 1/aspect * mySize.x;
3479 newSize_x = mySize.x;
3481 pos_y = pos.y + (mySize.y - newSize.y) / 2;
3487 keysize = eX * mySize.x * (1/3.0) + eY * mySize.y * (1/(3.0 - !autocvar_hud_panel_pressedkeys_attack));
3489 pressedkeys = getstatf(STAT_PRESSED_KEYS);
3491 if(autocvar_hud_panel_pressedkeys_attack)
3493 drawpic_aspect_skin(pos + eX * keysize.x * 0.5, ((pressedkeys & KEY_ATCK) ? "key_atck_inv.tga" : "key_atck.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3494 drawpic_aspect_skin(pos + eX * keysize.x * 1.5, ((pressedkeys & KEY_ATCK2) ? "key_atck_inv.tga" : "key_atck.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3498 drawpic_aspect_skin(pos, ((pressedkeys & KEY_CROUCH) ? "key_crouch_inv.tga" : "key_crouch.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3499 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);
3500 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);
3502 drawpic_aspect_skin(pos, ((pressedkeys & KEY_LEFT) ? "key_left_inv.tga" : "key_left.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3503 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);
3504 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);
3507 // Handle chat as a panel (#12)
3511 if(!autocvar__hud_configure)
3513 if (!autocvar_hud_panel_chat)
3515 if (!autocvar_con_chatrect)
3516 cvar_set("con_chatrect", "0");
3519 if(autocvar__con_chat_maximized)
3521 if(!hud_draw_maximized) return;
3523 else if(chat_panel_modified)
3525 panel.update_time = time; // forces reload of panel attributes
3526 chat_panel_modified = false;
3530 HUD_Panel_UpdateCvars();
3532 if(autocvar__con_chat_maximized && !autocvar__hud_configure) // draw at full screen height if maximized
3534 panel_pos_y = panel_bg_border;
3535 panel_size_y = vid_conheight - panel_bg_border * 2;
3536 if(panel.current_panel_bg == "0") // force a border when maximized
3539 panel_bg = strcat(hud_skin_path, "/border_default");
3540 if(precache_pic(panel_bg) == "")
3541 panel_bg = "gfx/hud/default/border_default";
3542 if(panel.current_panel_bg)
3543 strunzone(panel.current_panel_bg);
3544 panel.current_panel_bg = strzone(panel_bg);
3545 chat_panel_modified = true;
3547 panel_bg_alpha = max(0.75, panel_bg_alpha); // force an theAlpha of at least 0.75
3552 mySize = panel_size;
3554 HUD_Panel_DrawBg(1);
3556 if(panel_bg_padding)
3558 pos += '1 1 0' * panel_bg_padding;
3559 mySize -= '2 2 0' * panel_bg_padding;
3562 if (!autocvar_con_chatrect)
3563 cvar_set("con_chatrect", "1");
3565 cvar_set("con_chatrect_x", ftos(pos.x/vid_conwidth));
3566 cvar_set("con_chatrect_y", ftos(pos.y/vid_conheight));
3568 cvar_set("con_chatwidth", ftos(mySize.x/vid_conwidth));
3569 cvar_set("con_chat", ftos(floor(mySize.y/autocvar_con_chatsize - 0.5)));
3571 if(autocvar__hud_configure)
3574 chatsize = '1 1 0' * autocvar_con_chatsize;
3575 cvar_set("con_chatrect_x", "9001"); // over 9000, we'll fake it instead for more control over theAlpha and such
3577 for(i = 0; i < autocvar_con_chat; ++i)
3579 if(i == autocvar_con_chat - 1)
3582 a = panel_fg_alpha * floor(((i + 1) * 7 + autocvar_con_chattime)/45);
3583 drawcolorcodedstring(pos, textShortenToWidth(_("^3Player^7: This is the chat area."), mySize.x, chatsize, stringwidth_colors), chatsize, a, DRAWFLAG_NORMAL);
3584 pos.y += chatsize.y;
3589 // Engine info panel (#13)
3596 float frametimeavg1; // 1 frame ago
3597 float frametimeavg2; // 2 frames ago
3598 void HUD_EngineInfo(void)
3600 if(!autocvar__hud_configure)
3602 if(!autocvar_hud_panel_engineinfo) return;
3605 HUD_Panel_UpdateCvars();
3608 mySize = panel_size;
3610 HUD_Panel_DrawBg(1);
3611 if(panel_bg_padding)
3613 pos += '1 1 0' * panel_bg_padding;
3614 mySize -= '2 2 0' * panel_bg_padding;
3617 float currentTime = gettime(GETTIME_REALTIME);
3618 if(cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage"))
3620 float currentframetime = currentTime - prevfps_time;
3621 frametimeavg = (frametimeavg + frametimeavg1 + frametimeavg2 + currentframetime)/4; // average three frametimes into framecounter for slightly more stable fps readings :P
3622 frametimeavg2 = frametimeavg1;
3623 frametimeavg1 = frametimeavg;
3626 weight = cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage_new_weight");
3627 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.
3629 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
3630 prevfps = (1/currentframetime);
3631 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"
3633 prevfps_time = currentTime;
3638 if(currentTime - prevfps_time > autocvar_hud_panel_engineinfo_framecounter_time)
3640 prevfps = framecounter/(currentTime - prevfps_time);
3642 prevfps_time = currentTime;
3647 color = HUD_Get_Num_Color (prevfps, 100);
3648 drawstring_aspect(pos, sprintf(_("FPS: %.*f"), autocvar_hud_panel_engineinfo_framecounter_decimals, prevfps), mySize, color, panel_fg_alpha, DRAWFLAG_NORMAL);
3651 // Info messages panel (#14)
3653 #define drawInfoMessage(s) do { \
3654 if(autocvar_hud_panel_infomessages_flip) \
3655 o_x = pos.x + mySize.x - stringwidth(s, true, fontsize); \
3656 drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL); \
3657 o.y += fontsize.y; \
3659 void HUD_InfoMessages(void)
3661 if(!autocvar__hud_configure)
3663 if(!autocvar_hud_panel_infomessages) return;
3666 HUD_Panel_UpdateCvars();
3669 mySize = panel_size;
3671 HUD_Panel_DrawBg(1);
3672 if(panel_bg_padding)
3674 pos += '1 1 0' * panel_bg_padding;
3675 mySize -= '2 2 0' * panel_bg_padding;
3678 // always force 5:1 aspect
3679 vector newSize = '0 0 0';
3680 if(mySize.x/mySize.y > 5)
3682 newSize_x = 5 * mySize.y;
3683 newSize_y = mySize.y;
3685 pos_x = pos.x + (mySize.x - newSize.x) / 2;
3689 newSize_y = 1/5 * mySize.x;
3690 newSize_x = mySize.x;
3692 pos_y = pos.y + (mySize.y - newSize.y) / 2;
3701 fontsize = '0.20 0.20 0' * mySize.y;
3707 if(!autocvar__hud_configure)
3709 if(spectatee_status && !intermission)
3712 if(spectatee_status == -1)
3713 s = _("^1Observing");
3715 s = sprintf(_("^1Spectating: ^7%s"), GetPlayerName(player_localentnum - 1));
3718 if(spectatee_status == -1)
3719 s = sprintf(_("^1Press ^3%s^1 to spectate"), getcommandkey("primary fire", "+fire"));
3721 s = sprintf(_("^1Press ^3%s^1 or ^3%s^1 for next or previous player"), getcommandkey("next weapon", "weapnext"), getcommandkey("previous weapon", "weapprev"));
3724 if(spectatee_status == -1)
3725 s = sprintf(_("^1Use ^3%s^1 or ^3%s^1 to change the speed"), getcommandkey("next weapon", "weapnext"), getcommandkey("previous weapon", "weapprev"));
3727 s = sprintf(_("^1Press ^3%s^1 to observe"), getcommandkey("secondary fire", "+fire2"));
3730 s = sprintf(_("^1Press ^3%s^1 for gamemode info"), getcommandkey("server info", "+show_info"));
3733 if(gametype == MAPINFO_TYPE_LMS)
3736 sk = playerslots[player_localnum];
3737 if(sk.(scores[ps_primary]) >= 666)
3738 s = _("^1Match has already begun");
3739 else if(sk.(scores[ps_primary]) > 0)
3740 s = _("^1You have no more lives left");
3742 s = sprintf(_("^1Press ^3%s^1 to join"), getcommandkey("jump", "+jump"));
3745 s = sprintf(_("^1Press ^3%s^1 to join"), getcommandkey("jump", "+jump"));
3748 //show restart countdown:
3749 if (time < getstatf(STAT_GAMESTARTTIME)) {
3751 //we need to ceil, otherwise the countdown would be off by .5 when using round()
3752 countdown = ceil(getstatf(STAT_GAMESTARTTIME) - time);
3753 s = sprintf(_("^1Game starts in ^3%d^1 seconds"), countdown);
3754 drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
3758 if(warmup_stage && !intermission)
3760 s = _("^2Currently in ^1warmup^2 stage!");
3770 if(ready_waiting && !intermission && !spectatee_status)
3772 if(ready_waiting_for_me)
3775 s = sprintf(_("%sPress ^3%s%s to end warmup"), blinkcolor, getcommandkey("ready", "ready"), blinkcolor);
3777 s = sprintf(_("%sPress ^3%s%s once you are ready"), blinkcolor, getcommandkey("ready", "ready"), blinkcolor);
3782 s = _("^2Waiting for others to ready up to end warmup...");
3784 s = _("^2Waiting for others to ready up...");
3788 else if(warmup_stage && !intermission && !spectatee_status)
3790 s = sprintf(_("^2Press ^3%s^2 to end warmup"), getcommandkey("ready", "ready"));
3794 if(teamplay && !intermission && !spectatee_status && gametype != MAPINFO_TYPE_CA && teamnagger)
3796 float ts_min = 0, ts_max = 0;
3797 tm = teams.sort_next;
3800 for(0; tm.sort_next; tm = tm.sort_next)
3802 if(!tm.team_size || tm.team == NUM_SPECTATOR)
3804 if(!ts_min) ts_min = tm.team_size;
3805 else ts_min = min(ts_min, tm.team_size);
3806 if(!ts_max) ts_max = tm.team_size;
3807 else ts_max = max(ts_max, tm.team_size);
3809 if ((ts_max - ts_min) > 1)
3811 s = strcat(blinkcolor, _("Teamnumbers are unbalanced!"));
3812 tm = GetTeam(myteam, false);
3814 if (tm.team != NUM_SPECTATOR)
3815 if (tm.team_size == ts_max)
3816 s = strcat(s, sprintf(_(" Press ^3%s%s to adjust"), getcommandkey("team menu", "menu_showteamselect"), blinkcolor));
3824 s = _("^7Press ^3ESC ^7to show HUD options.");
3826 s = _("^3Doubleclick ^7a panel for panel-specific options.");
3828 s = _("^3CTRL ^7to disable collision testing, ^3SHIFT ^7and");
3830 s = _("^3ALT ^7+ ^3ARROW KEYS ^7for fine adjustments.");
3835 // Physics panel (#15)
3837 vector acc_prevspeed;
3838 float acc_prevtime, acc_avg, top_speed, top_speed_time;
3839 void HUD_Physics(void)
3841 if(!autocvar__hud_configure)
3843 if(!autocvar_hud_panel_physics) return;
3844 if(spectatee_status == -1 && (autocvar_hud_panel_physics == 1 || autocvar_hud_panel_physics == 3)) return;
3845 if(autocvar_hud_panel_physics == 3 && !(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return;
3848 HUD_Panel_UpdateCvars();
3850 draw_beginBoldFont();
3852 HUD_Panel_DrawBg(1);
3853 if(panel_bg_padding)
3855 panel_pos += '1 1 0' * panel_bg_padding;
3856 panel_size -= '2 2 0' * panel_bg_padding;
3859 float acceleration_progressbar_scale = 0;
3860 if(autocvar_hud_panel_physics_progressbar && autocvar_hud_panel_physics_acceleration_progressbar_scale > 1)
3861 acceleration_progressbar_scale = autocvar_hud_panel_physics_acceleration_progressbar_scale;
3864 if (autocvar_hud_panel_physics_text_scale <= 0)
3867 text_scale = min(autocvar_hud_panel_physics_text_scale, 1);
3870 float speed, conversion_factor;
3873 switch(autocvar_hud_panel_physics_speed_unit)
3878 conversion_factor = 1.0;
3882 conversion_factor = 0.0254;
3886 conversion_factor = 0.0254 * 3.6;
3890 conversion_factor = 0.0254 * 3.6 * 0.6213711922;
3894 conversion_factor = 0.0254 * 1.943844492; // 1 m/s = 1.943844492 knots, because 1 knot = 1.852 km/h
3898 vector vel = (csqcplayer ? csqcplayer.velocity : pmove_vel);
3900 float max_speed = floor( autocvar_hud_panel_physics_speed_max * conversion_factor + 0.5 );
3901 if (autocvar__hud_configure)
3902 speed = floor( max_speed * 0.65 + 0.5 );
3903 else if(autocvar_hud_panel_physics_speed_vertical)
3904 speed = floor( vlen(vel) * conversion_factor + 0.5 );
3906 speed = floor( vlen(vel - vel.z * '0 0 1') * conversion_factor + 0.5 );
3908 //compute acceleration
3909 float acceleration, f;
3910 if (autocvar__hud_configure)
3911 acceleration = autocvar_hud_panel_physics_acceleration_max * 0.3;
3914 // 1 m/s = 0.0254 qu/s; 1 g = 9.80665 m/s^2
3915 f = time - acc_prevtime;
3916 if(autocvar_hud_panel_physics_acceleration_vertical)
3917 acceleration = (vlen(vel) - vlen(acc_prevspeed));
3919 acceleration = (vlen(vel - '0 0 1' * vel.z) - vlen(acc_prevspeed - '0 0 1' * acc_prevspeed.z));
3921 acceleration = acceleration * (1 / max(0.0001, f)) * (0.0254 / 9.80665);
3923 acc_prevspeed = vel;
3924 acc_prevtime = time;
3926 f = bound(0, f * 10, 1);
3927 acc_avg = acc_avg * (1 - f) + acceleration * f;
3931 float panel_ar = panel_size.x/panel_size.y;
3932 vector speed_offset = '0 0 0', acceleration_offset = '0 0 0';
3933 if (panel_ar >= 5 && !acceleration_progressbar_scale)
3935 panel_size.x *= 0.5;
3936 if (autocvar_hud_panel_physics_flip)
3937 speed_offset_x = panel_size.x;
3939 acceleration_offset_x = panel_size.x;
3943 panel_size.y *= 0.5;
3944 if (autocvar_hud_panel_physics_flip)
3945 speed_offset_y = panel_size.y;
3947 acceleration_offset_y = panel_size.y;
3949 float speed_baralign, acceleration_baralign;
3950 if (autocvar_hud_panel_physics_baralign == 1)
3951 acceleration_baralign = speed_baralign = 1;
3952 else if(autocvar_hud_panel_physics_baralign == 4)
3953 acceleration_baralign = speed_baralign = 2;
3954 else if (autocvar_hud_panel_physics_flip)
3956 acceleration_baralign = (autocvar_hud_panel_physics_baralign == 2);
3957 speed_baralign = (autocvar_hud_panel_physics_baralign == 3);
3961 speed_baralign = (autocvar_hud_panel_physics_baralign == 2);
3962 acceleration_baralign = (autocvar_hud_panel_physics_baralign == 3);
3964 if (autocvar_hud_panel_physics_acceleration_progressbar_mode == 0)
3965 acceleration_baralign = 3; //override hud_panel_physics_baralign value for acceleration
3969 if(autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 2)
3970 HUD_Panel_DrawProgressBar(panel_pos + speed_offset, panel_size, "progressbar", speed/max_speed, 0, speed_baralign, autocvar_hud_progressbar_speed_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
3971 vector tmp_offset = '0 0 0', tmp_size = '0 0 0';
3972 if (autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 2)
3974 tmp_size_x = panel_size.x * 0.75;
3975 tmp_size_y = panel_size.y * text_scale;
3977 tmp_offset_x = panel_size.x - tmp_size.x;
3980 tmp_offset_y = (panel_size.y - tmp_size.y) / 2;
3981 drawstring_aspect(panel_pos + speed_offset + tmp_offset, ftos(speed), tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3987 tmp_offset_x = tmp_size.x;
3988 if (autocvar_hud_panel_physics_speed_unit_show)
3991 tmp_size_x = panel_size.x * (1 - 0.75);
3992 tmp_size_y = panel_size.y * 0.4 * text_scale;
3993 tmp_offset_y = (panel_size.y * 0.4 - tmp_size.y) / 2;
3994 drawstring_aspect(panel_pos + speed_offset + tmp_offset, unit, tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3998 //compute and draw top speed
3999 if (autocvar_hud_panel_physics_topspeed)
4000 if (autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 2)
4002 if (autocvar__hud_configure)
4004 top_speed = floor( max_speed * 0.75 + 0.5 );
4009 if (speed >= top_speed)
4012 top_speed_time = time;
4016 f = max(1, autocvar_hud_panel_physics_topspeed_time);
4017 // divide by f to make it start from 1
4018 f = cos( ((time - top_speed_time) / f) * PI/2 );
4020 else //hide top speed 0, it would be stupid
4025 //top speed progressbar peak
4026 if(speed < top_speed)
4027 if(autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 2)
4030 vector peak_size = '0 0 0';
4031 if (speed_baralign == 0)
4032 peak_offsetX = min(top_speed, max_speed)/max_speed * panel_size.x;
4033 else if (speed_baralign == 1)
4034 peak_offsetX = (1 - min(top_speed, max_speed)/max_speed) * panel_size.x;
4035 else // if (speed_baralign == 2)
4036 peak_offsetX = min(top_speed, max_speed)/max_speed * panel_size.x * 0.5;
4037 peak_size_x = floor(panel_size.x * 0.01 + 1.5);
4038 peak_size_y = panel_size.y;
4039 if (speed_baralign == 2) // draw two peaks, on both sides
4041 drawfill(panel_pos + speed_offset + eX * (0.5 * panel_size.x + peak_offsetX - peak_size.x), peak_size, autocvar_hud_progressbar_speed_color, f * autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
4042 drawfill(panel_pos + speed_offset + eX * (0.5 * panel_size.x - peak_offsetX + peak_size.x), peak_size, autocvar_hud_progressbar_speed_color, f * autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
4045 drawfill(panel_pos + speed_offset + eX * (peak_offsetX - peak_size.x), peak_size, autocvar_hud_progressbar_speed_color, f * autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
4049 tmp_offset_y = panel_size.y * 0.4;
4050 tmp_size_x = panel_size.x * (1 - 0.75);
4051 tmp_size_y = (panel_size.y - tmp_offset.y) * text_scale;
4052 tmp_offset.y += (panel_size.y - tmp_offset.y - tmp_size.y) / 2;
4053 drawstring_aspect(panel_pos + speed_offset + tmp_offset, ftos(top_speed), tmp_size, '1 0 0', f * panel_fg_alpha, DRAWFLAG_NORMAL);
4061 if(autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 3)
4063 vector progressbar_color;
4064 if(acceleration < 0)
4065 progressbar_color = autocvar_hud_progressbar_acceleration_neg_color;
4067 progressbar_color = autocvar_hud_progressbar_acceleration_color;
4069 f = acceleration/autocvar_hud_panel_physics_acceleration_max;
4070 if (autocvar_hud_panel_physics_acceleration_progressbar_nonlinear)
4073 if (acceleration_progressbar_scale) // allow progressbar to go out of panel bounds
4075 tmp_size = acceleration_progressbar_scale * panel_size.x * eX + panel_size.y * eY;
4077 if (acceleration_baralign == 1)
4078 tmp_offset_x = panel_size.x - tmp_size.x;
4079 else if (acceleration_baralign == 2 || acceleration_baralign == 3)
4080 tmp_offset_x = (panel_size.x - tmp_size.x) / 2;
4087 tmp_size = panel_size;
4088 tmp_offset = '0 0 0';
4091 HUD_Panel_DrawProgressBar(panel_pos + acceleration_offset + tmp_offset, tmp_size, "accelbar", f, 0, acceleration_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
4093 tmp_size_x = panel_size.x;
4094 tmp_size_y = panel_size.y * text_scale;
4096 tmp_offset_y = (panel_size.y - tmp_size.y) / 2;
4097 if (autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 3)
4098 drawstring_aspect(panel_pos + acceleration_offset + tmp_offset, strcat(ftos_decimals(acceleration, 2), "g"), tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4103 // CenterPrint (#16)
4105 const float CENTERPRINT_MAX_MSGS = 10;
4106 const float CENTERPRINT_MAX_ENTRIES = 50;
4107 const float CENTERPRINT_SPACING = 0.7;
4109 string centerprint_messages[CENTERPRINT_MAX_MSGS];
4110 float centerprint_msgID[CENTERPRINT_MAX_MSGS];
4111 float centerprint_time[CENTERPRINT_MAX_MSGS];
4112 float centerprint_expire_time[CENTERPRINT_MAX_MSGS];
4113 float centerprint_countdown_num[CENTERPRINT_MAX_MSGS];
4114 float centerprint_showing;
4116 void centerprint_generic(float new_id, string strMessage, float duration, float countdown_num)
4118 //printf("centerprint_generic(%d, '%s^7', %d, %d);\n", new_id, strMessage, duration, countdown_num);
4121 if(strMessage == "" && new_id == 0)
4124 // strip trailing newlines
4125 j = strlen(strMessage) - 1;
4126 while(substring(strMessage, j, 1) == "\n" && j >= 0)
4128 if (j < strlen(strMessage) - 1)
4129 strMessage = substring(strMessage, 0, j + 1);
4131 if(strMessage == "" && new_id == 0)
4134 // strip leading newlines
4136 while(substring(strMessage, j, 1) == "\n" && j < strlen(strMessage))
4139 strMessage = substring(strMessage, j, strlen(strMessage) - j);
4141 if(strMessage == "" && new_id == 0)
4144 if (!centerprint_showing)
4145 centerprint_showing = true;
4147 for (i=0, j=cpm_index; i<CENTERPRINT_MAX_MSGS; ++i, ++j)
4149 if (j == CENTERPRINT_MAX_MSGS)
4151 if (new_id && new_id == centerprint_msgID[j])
4153 if (strMessage == "" && centerprint_messages[j] != "" && centerprint_countdown_num[j] == 0)
4155 // fade out the current msg (duration and countdown_num are ignored)
4156 centerprint_time[j] = min(5, autocvar_hud_panel_centerprint_fade_out);
4157 if (centerprint_expire_time[j] > time + min(5, autocvar_hud_panel_centerprint_fade_out) || centerprint_expire_time[j] < time)
4158 centerprint_expire_time[j] = time + min(5, autocvar_hud_panel_centerprint_fade_out);
4161 break; // found a msg with the same id, at position j
4165 if (i == CENTERPRINT_MAX_MSGS)
4167 // a msg with the same id was not found, add the msg at the next position
4169 if (cpm_index == -1)
4170 cpm_index = CENTERPRINT_MAX_MSGS - 1;
4173 if(centerprint_messages[j])
4174 strunzone(centerprint_messages[j]);
4175 centerprint_messages[j] = strzone(strMessage);
4176 centerprint_msgID[j] = new_id;
4179 centerprint_time[j] = -1;
4180 centerprint_expire_time[j] = time;
4185 duration = max(1, autocvar_hud_panel_centerprint_time);
4186 centerprint_time[j] = duration;
4187 centerprint_expire_time[j] = time + duration;
4189 centerprint_countdown_num[j] = countdown_num;
4192 void centerprint_hud(string strMessage)
4194 centerprint_generic(0, strMessage, autocvar_hud_panel_centerprint_time, 0);
4197 void reset_centerprint_messages(void)
4200 for (i=0; i<CENTERPRINT_MAX_MSGS; ++i)
4202 centerprint_expire_time[i] = 0;
4203 centerprint_time[i] = 1;
4204 centerprint_msgID[i] = 0;
4205 if(centerprint_messages[i])
4206 strunzone(centerprint_messages[i]);
4207 centerprint_messages[i] = string_null;
4210 float hud_configure_cp_generation_time;
4211 void HUD_CenterPrint (void)
4213 if(!autocvar__hud_configure)
4215 if(!autocvar_hud_panel_centerprint) return;
4217 if (hud_configure_prev && hud_configure_prev != -1)
4218 reset_centerprint_messages();
4222 if (!hud_configure_prev)
4223 reset_centerprint_messages();
4224 if (time > hud_configure_cp_generation_time)
4229 centerprint_generic(floor(r*1000), strcat(sprintf("^3Countdown message at time %s", seconds_tostring(time)), ", seconds left: ^COUNT"), 1, 10);
4231 centerprint_generic(0, sprintf("^1Multiline message at time %s that\n^1lasts longer than normal", seconds_tostring(time)), 20, 0);
4233 centerprint_hud(sprintf("Message at time %s", seconds_tostring(time)));
4234 hud_configure_cp_generation_time = time + 1 + random()*4;
4238 // this panel fades only when the menu does
4239 float hud_fade_alpha_save = 0;
4240 if(scoreboard_fade_alpha)
4242 hud_fade_alpha_save = hud_fade_alpha;
4243 hud_fade_alpha = 1 - autocvar__menu_alpha;
4245 HUD_Panel_UpdateCvars();
4247 if(scoreboard_fade_alpha)
4249 hud_fade_alpha = hud_fade_alpha_save;
4251 // move the panel below the scoreboard
4252 if (scoreboard_bottom >= 0.96 * vid_conheight)
4256 target_pos = eY * scoreboard_bottom + eX * 0.5 * (vid_conwidth - panel_size.x);
4258 if(target_pos.y > panel_pos.y)
4260 panel_pos = panel_pos + (target_pos - panel_pos) * sqrt(scoreboard_fade_alpha);
4261 panel_size_y = min(panel_size.y, vid_conheight - scoreboard_bottom);
4265 HUD_Panel_DrawBg(1);
4267 if (!centerprint_showing)
4270 if(panel_bg_padding)
4272 panel_pos += '1 1 0' * panel_bg_padding;
4273 panel_size -= '2 2 0' * panel_bg_padding;
4276 float entries, height;
4278 // entries = bound(1, floor(CENTERPRINT_MAX_ENTRIES * 4 * panel_size_y/panel_size_x), CENTERPRINT_MAX_ENTRIES);
4279 // height = panel_size_y/entries;
4280 // fontsize = '1 1 0' * height;
4281 height = vid_conheight/50 * autocvar_hud_panel_centerprint_fontscale;
4282 fontsize = '1 1 0' * height;
4283 entries = bound(1, floor(panel_size.y/height), CENTERPRINT_MAX_ENTRIES);
4285 float i, j, k, n, g;
4286 float a, sz, align, current_msg_posY = 0, msg_size;
4289 float all_messages_expired = true;
4292 if (autocvar_hud_panel_centerprint_flip)
4293 pos.y += panel_size.y;
4294 align = bound(0, autocvar_hud_panel_centerprint_align, 1);
4295 for (g=0, i=0, j=cpm_index; i<CENTERPRINT_MAX_MSGS; ++i, ++j)
4297 if (j == CENTERPRINT_MAX_MSGS)
4299 if (centerprint_expire_time[j] <= time)
4301 if (centerprint_countdown_num[j] && centerprint_time[j] > 0)
4303 centerprint_countdown_num[j] = centerprint_countdown_num[j] - 1;
4304 if (centerprint_countdown_num[j] == 0)
4306 centerprint_expire_time[j] = centerprint_expire_time[j] + centerprint_time[j];
4308 else if(centerprint_time[j] != -1)
4312 all_messages_expired = false;
4314 // fade the centerprint_hud in/out
4315 if(centerprint_time[j] < 0) // Expired but forced. Expire time is the fade-in time.
4316 a = (time - centerprint_expire_time[j]) / max(0.0001, autocvar_hud_panel_centerprint_fade_in);
4317 else if(centerprint_expire_time[j] - autocvar_hud_panel_centerprint_fade_out > time) // Regularily printed. Not fading out yet.
4318 a = (time - (centerprint_expire_time[j] - centerprint_time[j])) / max(0.0001, autocvar_hud_panel_centerprint_fade_in);
4319 else // Expiring soon, so fade it out.
4320 a = (centerprint_expire_time[j] - time) / max(0.0001, autocvar_hud_panel_centerprint_fade_out);
4322 // while counting down show it anyway in order to hold the current message position
4323 if (a <= 0.5/255.0 && centerprint_countdown_num[j] == 0) // Guaranteed invisible - don't show.
4328 // set the size from fading in/out before subsequent fading
4329 sz = autocvar_hud_panel_centerprint_fade_minfontsize + a * (1 - autocvar_hud_panel_centerprint_fade_minfontsize);
4331 // also fade it based on positioning
4332 if(autocvar_hud_panel_centerprint_fade_subsequent)
4334 a = a * bound(autocvar_hud_panel_centerprint_fade_subsequent_passone_minalpha, (1 - (g / max(1, autocvar_hud_panel_centerprint_fade_subsequent_passone))), 1); // pass one: all messages after the first have half theAlpha
4335 a = a * bound(autocvar_hud_panel_centerprint_fade_subsequent_passtwo_minalpha, (1 - (g / max(1, autocvar_hud_panel_centerprint_fade_subsequent_passtwo))), 1); // pass two: after that, gradually lower theAlpha even more for each message
4337 a *= panel_fg_alpha;
4339 // finally set the size based on the new theAlpha from subsequent fading
4340 sz = sz * (autocvar_hud_panel_centerprint_fade_subsequent_minfontsize + a * (1 - autocvar_hud_panel_centerprint_fade_subsequent_minfontsize));
4341 drawfontscale = sz * '1 1 0';
4343 if (centerprint_countdown_num[j])
4344 n = tokenizebyseparator(strreplace("^COUNT", count_seconds(centerprint_countdown_num[j]), centerprint_messages[j]), "\n");
4346 n = tokenizebyseparator(centerprint_messages[j], "\n");
4348 if (autocvar_hud_panel_centerprint_flip)
4350 // check if the message can be entirely shown
4351 for(k = 0; k < n; ++k)
4353 getWrappedLine_remaining = argv(k);
4354 while(getWrappedLine_remaining)
4356 ts = getWrappedLine(panel_size.x * sz, fontsize, stringwidth_colors);
4358 pos.y -= fontsize.y;
4360 pos.y -= fontsize.y * CENTERPRINT_SPACING/2;
4363 current_msg_posY = pos.y; // save starting pos (first line) of the current message
4367 for(k = 0; k < n; ++k)
4369 getWrappedLine_remaining = argv(k);
4370 while(getWrappedLine_remaining)
4372 ts = getWrappedLine(panel_size.x * sz, fontsize, stringwidth_colors);
4376 pos_x = panel_pos.x + (panel_size.x - stringwidth(ts, true, fontsize)) * align;
4377 if (a > 0.5/255.0) // Otherwise guaranteed invisible - don't show. This is checked a second time after some multiplications with other factors were done so temporary changes of these cannot cause flicker.
4378 drawcolorcodedstring(pos + eY * 0.5 * (1 - sz) * fontsize.y, ts, fontsize, a, DRAWFLAG_NORMAL);
4379 pos.y += fontsize.y;
4382 pos.y += fontsize.y * CENTERPRINT_SPACING/2;
4386 ++g; // move next position number up
4388 msg_size = pos.y - msg_size;
4389 if (autocvar_hud_panel_centerprint_flip)
4391 pos_y = current_msg_posY - CENTERPRINT_SPACING * fontsize.y;
4392 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
4393 pos.y += (msg_size + CENTERPRINT_SPACING * fontsize.y) * (1 - sqrt(sz));
4395 if (pos.y < panel_pos.y) // check if the next message can be shown
4397 drawfontscale = '1 1 0';
4403 pos.y += CENTERPRINT_SPACING * fontsize.y;
4404 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
4405 pos.y -= (msg_size + CENTERPRINT_SPACING * fontsize.y) * (1 - sqrt(sz));
4407 if(pos.y > panel_pos.y + panel_size.y - fontsize.y) // check if the next message can be shown
4409 drawfontscale = '1 1 0';
4414 drawfontscale = '1 1 0';
4415 if (all_messages_expired)
4417 centerprint_showing = false;
4418 reset_centerprint_messages();
4424 void HUD_Buffs(void)
4426 float buffs = getstati(STAT_BUFFS, 0, 24);
4427 if(!autocvar__hud_configure)
4429 if(!autocvar_hud_panel_buffs) return;
4430 if(spectatee_status == -1) return;
4431 if(getstati(STAT_HEALTH) <= 0) return;
4436 buffs = Buff_Type_first.items; // force first buff
4439 float b = 0; // counter to tell other functions that we have buffs
4442 for(e = Buff_Type_first; e; e = e.enemy) if(buffs & e.items)
4445 string o = strcat(rgb_to_hexcolor(Buff_Color(e.items)), Buff_PrettyName(e.items));
4449 s = strcat(s, " ", o);
4452 HUD_Panel_UpdateCvars();
4454 draw_beginBoldFont();
4458 mySize = panel_size;
4460 HUD_Panel_DrawBg(bound(0, b, 1));
4461 if(panel_bg_padding)
4463 pos += '1 1 0' * panel_bg_padding;
4464 mySize -= '2 2 0' * panel_bg_padding;
4467 //float panel_ar = mySize_x/mySize_y;
4468 //float is_vertical = (panel_ar < 1);
4469 //float buff_iconalign = autocvar_hud_panel_buffs_iconalign;
4470 vector buff_offset = '0 0 0';
4472 for(e = Buff_Type_first; e; e = e.enemy) if(buffs & e.items)
4474 //DrawNumIcon(pos + buff_offset, mySize, shield, "shield", is_vertical, buff_iconalign, '1 1 1', 1);
4475 drawcolorcodedstring_aspect(pos + buff_offset, s, mySize, panel_fg_alpha * 0.5, DRAWFLAG_NORMAL);
4488 void HUD_Reset (void)
4490 // reset gametype specific icons
4491 if(gametype == MAPINFO_TYPE_CTF)
4492 HUD_Mod_CTF_Reset();
4495 void HUD_Main (void)
4498 // global hud theAlpha fade
4499 if(menu_enabled == 1)
4502 hud_fade_alpha = (1 - autocvar__menu_alpha);
4504 if(scoreboard_fade_alpha)
4505 hud_fade_alpha = (1 - scoreboard_fade_alpha);
4507 HUD_Configure_Frame();
4509 if(intermission == 2) // no hud during mapvote
4512 // panels that we want to be active together with the scoreboard
4513 // they must fade only when the menu does
4514 if(scoreboard_fade_alpha == 1)
4516 (panel = HUD_PANEL(CENTERPRINT)).panel_draw();
4520 if(!autocvar__hud_configure && !hud_fade_alpha)
4524 if (hud_skin_prev != autocvar_hud_skin)
4527 strunzone(hud_skin_path);
4528 hud_skin_path = strzone(strcat("gfx/hud/", autocvar_hud_skin));
4530 strunzone(hud_skin_prev);
4531 hud_skin_prev = strzone(autocvar_hud_skin);
4534 current_player = player_localentnum;
4537 if(autocvar_hud_dock != "" && autocvar_hud_dock != "0")
4541 float hud_dock_color_team = autocvar_hud_dock_color_team;
4542 if((teamplay) && hud_dock_color_team) {
4543 if(autocvar__hud_configure && myteam == NUM_SPECTATOR)
4544 color = '1 0 0' * hud_dock_color_team;
4546 color = myteamcolors * hud_dock_color_team;
4548 else if(autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && hud_dock_color_team) {
4549 color = '1 0 0' * hud_dock_color_team;
4553 string hud_dock_color = autocvar_hud_dock_color;
4554 if(hud_dock_color == "shirt") {
4555 f = stof(getplayerkeyvalue(current_player - 1, "colors"));
4556 color = colormapPaletteColor(floor(f / 16), 0);
4558 else if(hud_dock_color == "pants") {
4559 f = stof(getplayerkeyvalue(current_player - 1, "colors"));
4560 color = colormapPaletteColor(f % 16, 1);
4563 color = stov(hud_dock_color);
4567 pic = strcat(hud_skin_path, "/", autocvar_hud_dock);
4568 if(precache_pic(pic) == "") {
4569 pic = strcat(hud_skin_path, "/dock_medium");
4570 if(precache_pic(pic) == "") {
4571 pic = "gfx/hud/default/dock_medium";
4574 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...
4577 // cache the panel order into the panel_order array
4578 if(autocvar__hud_panelorder != hud_panelorder_prev) {
4579 for(i = 0; i < HUD_PANEL_NUM; ++i)
4580 panel_order[i] = -1;
4582 float p_num, warning = false;
4583 float argc = tokenize_console(autocvar__hud_panelorder);
4584 if (argc > HUD_PANEL_NUM)
4586 //first detect wrong/missing panel numbers
4587 for(i = 0; i < HUD_PANEL_NUM; ++i) {
4588 p_num = stof(argv(i));
4589 if (p_num >= 0 && p_num < HUD_PANEL_NUM) { //correct panel number?
4590 if (panel_order[p_num] == -1) //found for the first time?
4591 s = strcat(s, ftos(p_num), " ");
4592 panel_order[p_num] = 1; //mark as found
4597 for(i = 0; i < HUD_PANEL_NUM; ++i) {
4598 if (panel_order[i] == -1) {
4600 s = strcat(s, ftos(i), " "); //add missing panel number
4604 dprint("Automatically fixed wrong/missing panel numbers in _hud_panelorder\n");
4606 cvar_set("_hud_panelorder", s);
4607 if(hud_panelorder_prev)
4608 strunzone(hud_panelorder_prev);
4609 hud_panelorder_prev = strzone(s);
4611 //now properly set panel_order
4612 tokenize_console(s);
4613 for(i = 0; i < HUD_PANEL_NUM; ++i) {
4614 panel_order[i] = stof(argv(i));
4618 hud_draw_maximized = 0;
4619 // draw panels in order specified by panel_order array
4620 for(i = HUD_PANEL_NUM - 1; i >= 0; --i)
4621 (panel = hud_panel[panel_order[i]]).panel_draw();
4623 hud_draw_maximized = 1; // panels that may be maximized must check this var
4624 // draw maximized panels on top
4625 if(hud_panel_radar_maximized)
4626 (panel = HUD_PANEL(RADAR)).panel_draw();
4627 if(autocvar__con_chat_maximized)
4628 (panel = HUD_PANEL(CHAT)).panel_draw();
4630 HUD_Configure_PostDraw();
4632 hud_configure_prev = autocvar__hud_configure;