4 #include "hud_config.qh"
5 #include "mapvoting.qh"
6 #include "scoreboard.qh"
8 #include "teamradar.qh"
11 #include "../dpdefs/keycodes.qh"
13 #include "../common/buffs.qh"
14 #include "../common/constants.qh"
15 #include "../common/counting.qh"
16 #include "../common/deathtypes.qh"
17 #include "../common/mapinfo.qh"
18 #include "../common/nades.qh"
20 #include "../server/mutators/gamemode_ctf.qh"
22 #include "../common/stats.qh"
24 #include "../csqcmodellib/cl_player.qh"
26 #include "../warpzonelib/mathlib.qh"
34 // a border picture is a texture containing nine parts:
35 // 1/4 width: left part
36 // 1/2 width: middle part (stretched)
37 // 1/4 width: right part
39 // 1/4 height: top part
40 // 1/2 height: middle part (stretched)
41 // 1/4 height: bottom part
42 void draw_BorderPicture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha, vector theBorderSize)
44 if (theBorderSize.x < 0 && theBorderSize.y < 0) // draw whole image as it is
46 drawpic(theOrigin, pic, theSize, theColor, theAlpha, 0);
49 if (theBorderSize.x == 0 && theBorderSize.y == 0) // no border
51 // draw only the central part
52 drawsubpic(theOrigin, theSize, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0);
59 //pic = draw_UseSkinFor(pic);
60 width = eX * theSize.x;
61 height = eY * theSize.y;
62 if(theSize.x <= theBorderSize.x * 2)
64 // not wide enough... draw just left and right then
65 bW = eX * (0.25 * theSize.x / (theBorderSize.x * 2));
66 if(theSize.y <= theBorderSize.y * 2)
68 // not high enough... draw just corners
69 bH = eY * (0.25 * theSize.y / (theBorderSize.y * 2));
70 drawsubpic(theOrigin, width * 0.5 + height * 0.5, pic, '0 0 0', bW + bH, theColor, theAlpha, 0);
71 drawsubpic(theOrigin + width * 0.5, width * 0.5 + height * 0.5, pic, eX - bW, bW + bH, theColor, theAlpha, 0);
72 drawsubpic(theOrigin + height * 0.5, width * 0.5 + height * 0.5, pic, eY - bH, bW + bH, theColor, theAlpha, 0);
73 drawsubpic(theOrigin + theSize * 0.5, width * 0.5 + height * 0.5, pic, eX + eY - bW - bH, bW + bH, theColor, theAlpha, 0);
77 dY = theBorderSize.x * eY;
78 drawsubpic(theOrigin, width * 0.5 + dY, pic, '0 0 0', '0 0.25 0' + bW, theColor, theAlpha, 0);
79 drawsubpic(theOrigin + width * 0.5, width * 0.5 + dY, pic, '0 0 0' + eX - bW, '0 0.25 0' + bW, theColor, theAlpha, 0);
80 drawsubpic(theOrigin + dY, width * 0.5 + height - 2 * dY, pic, '0 0.25 0', '0 0.5 0' + bW, theColor, theAlpha, 0);
81 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);
82 drawsubpic(theOrigin + height - dY, width * 0.5 + dY, pic, '0 0.75 0', '0 0.25 0' + bW, theColor, theAlpha, 0);
83 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);
88 if(theSize.y <= theBorderSize.y * 2)
90 // not high enough... draw just top and bottom then
91 bH = eY * (0.25 * theSize.y / (theBorderSize.y * 2));
92 dX = theBorderSize.x * eX;
93 drawsubpic(theOrigin, dX + height * 0.5, pic, '0 0 0', '0.25 0 0' + bH, theColor, theAlpha, 0);
94 drawsubpic(theOrigin + dX, width - 2 * dX + height * 0.5, pic, '0.25 0 0', '0.5 0 0' + bH, theColor, theAlpha, 0);
95 drawsubpic(theOrigin + width - dX, dX + height * 0.5, pic, '0.75 0 0', '0.25 0 0' + bH, theColor, theAlpha, 0);
96 drawsubpic(theOrigin + height * 0.5, dX + height * 0.5, pic, '0 0 0' + eY - bH, '0.25 0 0' + bH, theColor, theAlpha, 0);
97 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);
98 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);
102 dX = theBorderSize.x * eX;
103 dY = theBorderSize.x * eY;
104 drawsubpic(theOrigin, dX + dY, pic, '0 0 0', '0.25 0.25 0', theColor, theAlpha, 0);
105 drawsubpic(theOrigin + dX, width - 2 * dX + dY, pic, '0.25 0 0', '0.5 0.25 0', theColor, theAlpha, 0);
106 drawsubpic(theOrigin + width - dX, dX + dY, pic, '0.75 0 0', '0.25 0.25 0', theColor, theAlpha, 0);
107 drawsubpic(theOrigin + dY, dX + height - 2 * dY, pic, '0 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0);
108 drawsubpic(theOrigin + dY + dX, width - 2 * dX + height - 2 * dY, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0);
109 drawsubpic(theOrigin + dY + width - dX, dX + height - 2 * dY, pic, '0.75 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0);
110 drawsubpic(theOrigin + height - dY, dX + dY, pic, '0 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
111 drawsubpic(theOrigin + height - dY + dX, width - 2 * dX + dY, pic, '0.25 0.75 0', '0.5 0.25 0', theColor, theAlpha, 0);
112 drawsubpic(theOrigin + height - dY + width - dX, dX + dY, pic, '0.75 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
117 vector HUD_Get_Num_Color (float x, float maxvalue)
122 color.x = sin(2*M_PI*time);
124 color.z = sin(2*M_PI*time);
126 else if(x > maxvalue * 0.75) {
127 color.x = 0.4 - (x-150)*0.02 * 0.4; //red value between 0.4 -> 0
128 color.y = 0.9 + (x-150)*0.02 * 0.1; // green value between 0.9 -> 1
131 else if(x > maxvalue * 0.5) {
132 color.x = 1 - (x-100)*0.02 * 0.6; //red value between 1 -> 0.4
133 color.y = 1 - (x-100)*0.02 * 0.1; // green value between 1 -> 0.9
134 color.z = 1 - (x-100)*0.02; // blue value between 1 -> 0
136 else if(x > maxvalue * 0.25) {
139 color.z = 0.2 + (x-50)*0.02 * 0.8; // blue value between 0.2 -> 1
141 else if(x > maxvalue * 0.1) {
143 color.y = (x-20)*90/27/100; // green value between 0 -> 1
144 color.z = (x-20)*90/27/100 * 0.2; // blue value between 0 -> 0.2
152 blinkingamt = (1 - x/maxvalue/0.25);
155 color.x = color.x - color.x * blinkingamt * sin(2*M_PI*time);
156 color.y = color.y - color.y * blinkingamt * sin(2*M_PI*time);
157 color.z = color.z - color.z * blinkingamt * sin(2*M_PI*time);
162 float HUD_GetRowCount(int item_count, vector size, float item_aspect)
164 float aspect = size_y / size_x;
165 return bound(1, floor((sqrt(4 * item_aspect * aspect * item_count + aspect * aspect) + aspect + 0.5) / 2), item_count);
168 vector HUD_GetTableSize_BestItemAR(int item_count, vector psize, float item_aspect)
171 float ratio, best_ratio = 0;
172 float best_columns = 1, best_rows = 1;
173 bool vertical = (psize.x / psize.y >= item_aspect);
176 psize = eX * psize.y + eY * psize.x;
177 item_aspect = 1 / item_aspect;
180 rows = ceil(sqrt(item_count));
181 columns = ceil(item_count/rows);
184 ratio = (psize.x/columns) / (psize.y/rows);
185 if(ratio > item_aspect)
186 ratio = item_aspect * item_aspect / ratio;
188 if(ratio <= best_ratio)
189 break; // ratio starts decreasing by now, skip next configurations
191 best_columns = columns;
199 rows = ceil(item_count/columns);
203 return eX * best_rows + eY * best_columns;
205 return eX * best_columns + eY * best_rows;
208 float stringwidth_colors(string s, vector theSize)
210 return stringwidth(s, true, theSize);
213 float stringwidth_nocolors(string s, vector theSize)
215 return stringwidth(s, false, theSize);
218 void drawstringright(vector position, string text, vector theScale, vector rgb, float theAlpha, int flag)
220 position.x -= 2 / 3 * strlen(text) * theScale.x;
221 drawstring(position, text, theScale, rgb, theAlpha, flag);
224 void drawstringcenter(vector position, string text, vector theScale, vector rgb, float theAlpha, int flag)
226 position.x = 0.5 * (vid_conwidth - 0.6025 * strlen(text) * theScale.x);
227 drawstring(position, text, theScale, rgb, theAlpha, flag);
230 // return the string of the onscreen race timer
231 string MakeRaceString(int cp, float mytime, float theirtime, float lapdelta, string theirname)
239 if(theirtime == 0) // goal hit
243 timestr = strcat("+", ftos_decimals(+mytime, TIME_DECIMALS));
253 timestr = strcat("-", ftos_decimals(-mytime, TIME_DECIMALS));
259 lapstr = sprintf(_(" (-%dL)"), lapdelta);
262 else if(lapdelta < 0)
264 lapstr = sprintf(_(" (+%dL)"), -lapdelta);
268 else if(theirtime > 0) // anticipation
270 if(mytime >= theirtime)
271 timestr = strcat("+", ftos_decimals(mytime - theirtime, TIME_DECIMALS));
273 timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(theirtime));
283 cpname = _("Start line");
285 cpname = _("Finish line");
287 cpname = sprintf(_("Intermediate %d"), cp);
289 cpname = _("Finish line");
292 return strcat(col, cpname);
293 else if(theirname == "")
294 return strcat(col, sprintf("%s (%s)", cpname, timestr));
296 return strcat(col, sprintf("%s (%s %s)", cpname, timestr, strcat(theirname, col, lapstr)));
299 // Check if the given name already exist in race rankings? In that case, where? (otherwise return 0)
300 int race_CheckName(string net_name)
303 for (i=RANKINGS_CNT-1;i>=0;--i)
304 if(grecordholder[i] == net_name)
309 int GetPlayerColorForce(int i)
314 return stof(getplayerkeyvalue(i, "colors")) & 15;
317 int GetPlayerColor(int i)
319 if(!playerslots[i].gotscores) // unconnected
320 return NUM_SPECTATOR;
321 else if(stof(getplayerkeyvalue(i, "frags")) == FRAGS_SPECTATOR)
322 return NUM_SPECTATOR;
324 return GetPlayerColorForce(i);
327 string GetPlayerName(int i)
329 return ColorTranslateRGB(getplayerkeyvalue(i, "name"));
339 // draw the background/borders
340 #define HUD_Panel_DrawBg(theAlpha) do { \
341 if(panel.current_panel_bg != "0" && panel.current_panel_bg != "") \
342 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));\
345 //basically the same code of draw_ButtonPicture and draw_VertButtonPicture for the menu
346 void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, float length_ratio, bool vertical, float baralign, vector theColor, float theAlpha, int drawflag)
348 if(!length_ratio || !theAlpha)
354 if(length_ratio < -1)
357 else if(length_ratio < 0)
361 vector width, height;
363 pic = strcat(hud_skin_path, "/", pic, "_vertical");
364 if(precache_pic(pic) == "") {
365 pic = "gfx/hud/default/progressbar_vertical";
368 if (baralign == 1) // bottom align
369 theOrigin.y += (1 - length_ratio) * theSize.y;
370 else if (baralign == 2) // center align
371 theOrigin.y += 0.5 * (1 - length_ratio) * theSize.y;
372 else if (baralign == 3) // center align, positive values down, negative up
375 if (length_ratio > 0)
376 theOrigin.y += theSize.y;
379 theOrigin.y += (1 + length_ratio) * theSize.y;
380 length_ratio = -length_ratio;
383 theSize.y *= length_ratio;
386 width = eX * theSize.x;
387 height = eY * theSize.y;
388 if(theSize.y <= theSize.x * 2)
390 // button not high enough
391 // draw just upper and lower part then
392 square = eY * theSize.y * 0.5;
393 bH = eY * (0.25 * theSize.y / (theSize.x * 2));
394 drawsubpic(theOrigin, square + width, pic, '0 0 0', eX + bH, theColor, theAlpha, drawflag);
395 drawsubpic(theOrigin + square, square + width, pic, eY - bH, eX + bH, theColor, theAlpha, drawflag);
399 square = eY * theSize.x;
400 drawsubpic(theOrigin, width + square, pic, '0 0 0', '1 0.25 0', theColor, theAlpha, drawflag);
401 drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0 0.25 0', '1 0.5 0', theColor, theAlpha, drawflag);
402 drawsubpic(theOrigin + height - square, width + square, pic, '0 0.75 0', '1 0.25 0', theColor, theAlpha, drawflag);
405 pic = strcat(hud_skin_path, "/", pic);
406 if(precache_pic(pic) == "") {
407 pic = "gfx/hud/default/progressbar";
410 if (baralign == 1) // right align
411 theOrigin.x += (1 - length_ratio) * theSize.x;
412 else if (baralign == 2) // center align
413 theOrigin.x += 0.5 * (1 - length_ratio) * theSize.x;
414 else if (baralign == 3) // center align, positive values on the right, negative on the left
417 if (length_ratio > 0)
418 theOrigin.x += theSize.x;
421 theOrigin.x += (1 + length_ratio) * theSize.x;
422 length_ratio = -length_ratio;
425 theSize.x *= length_ratio;
428 width = eX * theSize.x;
429 height = eY * theSize.y;
430 if(theSize.x <= theSize.y * 2)
432 // button not wide enough
433 // draw just left and right part then
434 square = eX * theSize.x * 0.5;
435 bW = eX * (0.25 * theSize.x / (theSize.y * 2));
436 drawsubpic(theOrigin, square + height, pic, '0 0 0', eY + bW, theColor, theAlpha, drawflag);
437 drawsubpic(theOrigin + square, square + height, pic, eX - bW, eY + bW, theColor, theAlpha, drawflag);
441 square = eX * theSize.y;
442 drawsubpic(theOrigin, height + square, pic, '0 0 0', '0.25 1 0', theColor, theAlpha, drawflag);
443 drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0.25 0 0', '0.5 1 0', theColor, theAlpha, drawflag);
444 drawsubpic(theOrigin + width - square, height + square, pic, '0.75 0 0', '0.25 1 0', theColor, theAlpha, drawflag);
449 void HUD_Panel_DrawHighlight(vector pos, vector mySize, vector color, float theAlpha, int drawflag)
455 pic = strcat(hud_skin_path, "/num_leading");
456 if(precache_pic(pic) == "") {
457 pic = "gfx/hud/default/num_leading";
460 drawsubpic(pos, eX * min(mySize.x * 0.5, mySize.y) + eY * mySize.y, pic, '0 0 0', '0.25 1 0', color, theAlpha, drawflag);
461 if(mySize.x/mySize.y > 2)
462 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);
463 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);
468 entity weaponorder[WEP_MAXCOUNT];
469 void weaponorder_swap(int i, int j, entity pass)
471 entity h = weaponorder[i];
472 weaponorder[i] = weaponorder[j];
476 string weaponorder_cmp_str;
477 int weaponorder_cmp(int i, int j, entity pass)
480 ai = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[i].weapon), 0);
481 aj = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[j].weapon), 0);
482 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)
485 void HUD_Weapons(void)
488 WepSet weapons_stat = WepSet_GetFromStat();
492 vector center = '0 0 0';
493 int weapon_count, weapon_id;
494 int row, column, rows = 0, columns = 0;
495 bool vertical_order = true;
496 float aspect = autocvar_hud_panel_weapons_aspect;
498 float timeout = autocvar_hud_panel_weapons_timeout;
499 float timein_effect_length = autocvar_hud_panel_weapons_timeout_speed_in; //? 0.375 : 0);
500 float timeout_effect_length = autocvar_hud_panel_weapons_timeout_speed_out; //? 0.75 : 0);
502 vector barsize = '0 0 0', baroffset = '0 0 0';
503 vector ammo_color = '1 0 1';
504 float ammo_alpha = 1;
506 float when = max(1, autocvar_hud_panel_weapons_complainbubble_time);
507 float fadetime = max(0, autocvar_hud_panel_weapons_complainbubble_fadetime);
509 vector weapon_pos, weapon_size = '0 0 0';
512 // check to see if we want to continue
513 if(intermission == 2) return;
514 if(hud != HUD_NORMAL) return;
516 if(!autocvar__hud_configure)
518 if((!autocvar_hud_panel_weapons) || (spectatee_status == -1))
520 if(timeout && time >= weapontime + timeout + timeout_effect_length)
521 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)))
523 weaponprevtime = time;
528 // update generic hud functions
529 HUD_Panel_UpdateCvars();
531 // figure out weapon order (how the weapons are sorted) // TODO make this configurable
532 if(weaponorder_bypriority != autocvar_cl_weaponpriority || !weaponorder[0])
535 if(weaponorder_bypriority)
536 strunzone(weaponorder_bypriority);
537 if(weaponorder_byimpulse)
538 strunzone(weaponorder_byimpulse);
540 weaponorder_bypriority = strzone(autocvar_cl_weaponpriority);
541 weaponorder_byimpulse = strzone(W_FixWeaponOrder_BuildImpulseList(W_FixWeaponOrder_ForceComplete(W_NumberWeaponOrder(weaponorder_bypriority))));
542 weaponorder_cmp_str = strcat(" ", weaponorder_byimpulse, " ");
545 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
547 self = get_weaponinfo(i);
548 if(self.impulse >= 0)
550 weaponorder[weapon_cnt] = self;
554 for(i = weapon_cnt; i < WEP_MAXCOUNT; ++i)
555 weaponorder[i] = world;
556 heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, world);
558 weaponorder_cmp_str = string_null;
561 if(!autocvar_hud_panel_weapons_complainbubble || autocvar__hud_configure || time - complain_weapon_time >= when + fadetime)
564 if(autocvar__hud_configure)
567 for(i = WEP_FIRST; i <= WEP_LAST; i += floor((WEP_LAST-WEP_FIRST)/5))
568 weapons_stat |= WepSet_FromWeapon(i);
574 weapons_stat = '0 0 0';
575 float countw = 1 + floor((floor(time * cvar("wep_add"))) % WEP_COUNT);
576 for(i = WEP_FIRST; i <= countw; ++i)
577 weapons_stat |= WepSet_FromWeapon(i);
582 // determine which weapons are going to be shown
583 if (autocvar_hud_panel_weapons_onlyowned)
585 if(autocvar__hud_configure)
587 if(menu_enabled != 2)
588 HUD_Panel_DrawBg(1); // also draw the bg of the entire panel
591 // do we own this weapon?
593 for(i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
594 if((weapons_stat & WepSet_FromWeapon(weaponorder[i].weapon)) || (weaponorder[i].weapon == complain_weapon))
598 // might as well commit suicide now, no reason to live ;)
599 if (weapon_count == 0)
602 vector old_panel_size = panel_size;
603 vector padded_panel_size = panel_size - '2 2 0' * panel_bg_padding;
605 // get the all-weapons layout
606 vector table_size = HUD_GetTableSize_BestItemAR(WEP_COUNT, padded_panel_size, aspect);
607 columns = table_size.x;
609 weapon_size.x = padded_panel_size.x / columns;
610 weapon_size.y = padded_panel_size.y / rows;
612 // NOTE: although weapons should aways look the same even if onlyowned is enabled,
613 // we enlarge them a bit when possible to better match the desired aspect ratio
614 if(padded_panel_size.x / padded_panel_size.y < aspect)
616 // maximum number of rows that allows to display items with the desired aspect ratio
617 int max_rows = floor(padded_panel_size.y / (weapon_size.x / aspect));
618 columns = min(columns, ceil(weapon_count / max_rows));
619 rows = ceil(weapon_count / columns);
620 weapon_size.y = min(padded_panel_size.y / rows, weapon_size.x / aspect);
621 weapon_size.x = min(padded_panel_size.x / columns, aspect * weapon_size.y);
622 vertical_order = false;
626 int max_columns = floor(padded_panel_size.x / (weapon_size.y * aspect));
627 rows = min(rows, ceil(weapon_count / max_columns));
628 columns = ceil(weapon_count / rows);
629 weapon_size.x = min(padded_panel_size.x / columns, aspect * weapon_size.y);
630 weapon_size.y = min(padded_panel_size.y / rows, weapon_size.x / aspect);
631 vertical_order = true;
634 // reduce size of the panel
635 panel_size.x = columns * weapon_size.x;
636 panel_size.y = rows * weapon_size.y;
637 panel_size += '2 2 0' * panel_bg_padding;
639 // center the resized panel, or snap it to the screen edge when close enough
640 if(panel_pos.x > vid_conwidth * 0.001)
642 if(panel_pos.x + old_panel_size.x > vid_conwidth * 0.999)
643 panel_pos.x += old_panel_size.x - panel_size.x;
645 panel_pos.x += (old_panel_size.x - panel_size.x) / 2;
647 else if(old_panel_size.x > vid_conwidth * 0.999)
648 panel_pos.x += (old_panel_size.x - panel_size.x) / 2;
650 if(panel_pos.y > vid_conheight * 0.001)
652 if(panel_pos.y + old_panel_size.y > vid_conheight * 0.999)
653 panel_pos.y += old_panel_size.y - panel_size.y;
655 panel_pos.y += (old_panel_size.y - panel_size.y) / 2;
657 else if(old_panel_size.y > vid_conheight * 0.999)
658 panel_pos.y += (old_panel_size.y - panel_size.y) / 2;
661 weapon_count = WEP_COUNT;
663 // animation for fading in/out the panel respectively when not in use
664 if(!autocvar__hud_configure)
666 if (timeout && time >= weapontime + timeout) // apply timeout effect if needed
668 f = bound(0, (time - (weapontime + timeout)) / timeout_effect_length, 1);
670 // fade the panel alpha
671 if(autocvar_hud_panel_weapons_timeout_effect == 1)
673 panel_bg_alpha *= (autocvar_hud_panel_weapons_timeout_fadebgmin * f + (1 - f));
674 panel_fg_alpha *= (autocvar_hud_panel_weapons_timeout_fadefgmin * f + (1 - f));
676 else if(autocvar_hud_panel_weapons_timeout_effect == 3)
678 panel_bg_alpha *= (1 - f);
679 panel_fg_alpha *= (1 - f);
682 // move the panel off the screen
683 if (autocvar_hud_panel_weapons_timeout_effect == 2 || autocvar_hud_panel_weapons_timeout_effect == 3)
685 f *= f; // for a cooler movement
686 center.x = panel_pos.x + panel_size.x/2;
687 center.y = panel_pos.y + panel_size.y/2;
688 screen_ar = vid_conwidth/vid_conheight;
689 if (center.x/center.y < screen_ar) //bottom left
691 if ((vid_conwidth - center.x)/center.y < screen_ar) //bottom
692 panel_pos.y += f * (vid_conheight - panel_pos.y);
694 panel_pos.x -= f * (panel_pos.x + panel_size.x);
698 if ((vid_conwidth - center.x)/center.y < screen_ar) //right
699 panel_pos.x += f * (vid_conwidth - panel_pos.x);
701 panel_pos.y -= f * (panel_pos.y + panel_size.y);
704 center.x = -1; // mark the panel as off screen
706 weaponprevtime = time - (1 - f) * timein_effect_length;
708 else if (timeout && time < weaponprevtime + timein_effect_length) // apply timein effect if needed
710 f = bound(0, (time - weaponprevtime) / timein_effect_length, 1);
712 // fade the panel alpha
713 if(autocvar_hud_panel_weapons_timeout_effect == 1)
715 panel_bg_alpha *= (autocvar_hud_panel_weapons_timeout_fadebgmin * (1 - f) + f);
716 panel_fg_alpha *= (autocvar_hud_panel_weapons_timeout_fadefgmin * (1 - f) + f);
718 else if(autocvar_hud_panel_weapons_timeout_effect == 3)
720 panel_bg_alpha *= (f);
721 panel_fg_alpha *= (f);
724 // move the panel back on screen
725 if (autocvar_hud_panel_weapons_timeout_effect == 2 || autocvar_hud_panel_weapons_timeout_effect == 3)
727 f *= f; // for a cooler movement
729 center.x = panel_pos.x + panel_size.x/2;
730 center.y = panel_pos.y + panel_size.y/2;
731 screen_ar = vid_conwidth/vid_conheight;
732 if (center.x/center.y < screen_ar) //bottom left
734 if ((vid_conwidth - center.x)/center.y < screen_ar) //bottom
735 panel_pos.y += f * (vid_conheight - panel_pos.y);
737 panel_pos.x -= f * (panel_pos.x + panel_size.x);
741 if ((vid_conwidth - center.x)/center.y < screen_ar) //right
742 panel_pos.x += f * (vid_conwidth - panel_pos.x);
744 panel_pos.y -= f * (panel_pos.y + panel_size.y);
750 // draw the background, then change the virtual size of it to better fit other items inside
758 panel_pos += '1 1 0' * panel_bg_padding;
759 panel_size -= '2 2 0' * panel_bg_padding;
762 // after the sizing and animations are done, update the other values
764 if(!rows) // if rows is > 0 onlyowned code has already updated these vars
766 vector table_size = HUD_GetTableSize_BestItemAR(WEP_COUNT, panel_size, aspect);
767 columns = table_size.x;
769 weapon_size.x = panel_size.x / columns;
770 weapon_size.y = panel_size.y / rows;
771 vertical_order = (panel_size.x / panel_size.y >= aspect);
774 // calculate position/size for visual bar displaying ammount of ammo status
775 if (autocvar_hud_panel_weapons_ammo)
777 ammo_color = stov(autocvar_hud_panel_weapons_ammo_color);
778 ammo_alpha = panel_fg_alpha * autocvar_hud_panel_weapons_ammo_alpha;
780 if(weapon_size.x/weapon_size.y > aspect)
782 barsize.x = aspect * weapon_size.y;
783 barsize.y = weapon_size.y;
784 baroffset.x = (weapon_size.x - barsize.x) / 2;
788 barsize.y = 1/aspect * weapon_size.x;
789 barsize.x = weapon_size.x;
790 baroffset.y = (weapon_size.y - barsize.y) / 2;
793 if(autocvar_hud_panel_weapons_accuracy)
794 Accuracy_LoadColors();
798 vector label_size = '1 1 0' * min(weapon_size.x, weapon_size.y) * bound(0, autocvar_hud_panel_weapons_label_scale, 1);
799 vector noncurrent_pos = '0 0 0';
800 vector noncurrent_size = weapon_size * bound(0, autocvar_hud_panel_weapons_noncurrent_scale, 1);
801 float noncurrent_alpha = panel_fg_alpha * bound(0, autocvar_hud_panel_weapons_noncurrent_alpha, 1);
804 for(i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
806 // retrieve information about the current weapon to be drawn
807 self = weaponorder[i];
808 weapon_id = self.impulse;
809 isCurrent = (self.weapon == switchweapon);
811 // skip if this weapon doesn't exist
812 if(!self || weapon_id < 0) { continue; }
814 // skip this weapon if we don't own it (and onlyowned is enabled)-- or if weapons_complainbubble is showing for this weapon
815 if(autocvar_hud_panel_weapons_onlyowned)
816 if (!((weapons_stat & WepSet_FromWeapon(self.weapon)) || (self.weapon == complain_weapon)))
819 // figure out the drawing position of weapon
820 weapon_pos = (panel_pos + eX * column * weapon_size.x + eY * row * weapon_size.y);
821 noncurrent_pos.x = weapon_pos.x + (weapon_size.x - noncurrent_size.x) / 2;
822 noncurrent_pos.y = weapon_pos.y + (weapon_size.y - noncurrent_size.y) / 2;
824 // draw background behind currently selected weapon
826 drawpic_aspect_skin(weapon_pos, "weapon_current_bg", weapon_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
828 // draw the weapon accuracy
829 if(autocvar_hud_panel_weapons_accuracy)
831 float panel_weapon_accuracy = weapon_accuracy[self.weapon-WEP_FIRST];
832 if(panel_weapon_accuracy >= 0)
834 color = Accuracy_GetColor(panel_weapon_accuracy);
835 drawpic_aspect_skin(weapon_pos, "weapon_accuracy", weapon_size, color, panel_fg_alpha, DRAWFLAG_NORMAL);
839 // drawing all the weapon items
840 if(weapons_stat & WepSet_FromWeapon(self.weapon))
842 // draw the weapon image
844 drawpic_aspect_skin(weapon_pos, self.model2, weapon_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
846 drawpic_aspect_skin(noncurrent_pos, self.model2, noncurrent_size, '1 1 1', noncurrent_alpha, DRAWFLAG_NORMAL);
848 // draw weapon label string
849 switch(autocvar_hud_panel_weapons_label)
851 case 1: // weapon number
852 drawstring(weapon_pos, ftos(weapon_id), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
856 drawstring(weapon_pos, getcommandkey(ftos(weapon_id), strcat("weapon_group_", ftos(weapon_id))), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
859 case 3: // weapon name
860 drawstring(weapon_pos, strtolower(self.message), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
867 // draw ammo status bar
868 if(autocvar_hud_panel_weapons_ammo && (self.ammo_field != ammo_none))
871 a = getstati(GetAmmoStat(self.ammo_field)); // how much ammo do we have?
875 switch(self.ammo_field)
877 case ammo_shells: ammo_full = autocvar_hud_panel_weapons_ammo_full_shells; break;
878 case ammo_nails: ammo_full = autocvar_hud_panel_weapons_ammo_full_nails; break;
879 case ammo_rockets: ammo_full = autocvar_hud_panel_weapons_ammo_full_rockets; break;
880 case ammo_cells: ammo_full = autocvar_hud_panel_weapons_ammo_full_cells; break;
881 case ammo_plasma: ammo_full = autocvar_hud_panel_weapons_ammo_full_plasma; break;
882 case ammo_fuel: ammo_full = autocvar_hud_panel_weapons_ammo_full_fuel; break;
883 default: ammo_full = 60;
887 weapon_pos.x + baroffset.x,
888 weapon_pos.y + baroffset.y,
889 barsize.x * bound(0, a/ammo_full, 1),
906 else // draw a "ghost weapon icon" if you don't have the weapon
908 drawpic_aspect_skin(noncurrent_pos, self.model2, noncurrent_size, '0.2 0.2 0.2', panel_fg_alpha * 0.5, DRAWFLAG_NORMAL);
911 // draw the complain message
912 if(self.weapon == complain_weapon)
915 a = ((complain_weapon_time + when > time) ? 1 : bound(0, (complain_weapon_time + when + fadetime - time) / fadetime, 1));
917 a = ((complain_weapon_time + when > time) ? 1 : 0);
920 if(complain_weapon_type == 0) {
921 s = _("Out of ammo");
922 color = stov(autocvar_hud_panel_weapons_complainbubble_color_outofammo);
924 else if(complain_weapon_type == 1) {
926 color = stov(autocvar_hud_panel_weapons_complainbubble_color_donthave);
929 s = _("Unavailable");
930 color = stov(autocvar_hud_panel_weapons_complainbubble_color_unavailable);
932 float padding = autocvar_hud_panel_weapons_complainbubble_padding;
933 drawpic_aspect_skin(weapon_pos + '1 1 0' * padding, "weapon_complainbubble", weapon_size - '2 2 0' * padding, color, a * panel_fg_alpha, DRAWFLAG_NORMAL);
934 drawstring_aspect(weapon_pos + '1 1 0' * padding, s, weapon_size - '2 2 0' * padding, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
939 if(!autocvar_hud_panel_weapons_onlyowned)
941 drawfill(weapon_pos + '1 1 0', weapon_size - '2 2 0', '1 1 1', panel_fg_alpha * 0.2, DRAWFLAG_NORMAL);
942 drawstring(weapon_pos, ftos(i + 1), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
946 // continue with new position for the next weapon
950 if(column >= columns)
969 void DrawNadeProgressBar(vector myPos, vector mySize, float progress, vector color)
971 HUD_Panel_DrawProgressBar(
972 myPos + eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize.x,
973 mySize - eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize.x,
974 autocvar_hud_panel_ammo_progressbar_name,
975 progress, 0, 0, color,
976 autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
979 void DrawAmmoNades(vector myPos, vector mySize, bool draw_expanding, float expand_time)
981 float bonusNades = getstatf(STAT_NADE_BONUS);
982 float bonusProgress = getstatf(STAT_NADE_BONUS_SCORE);
983 float bonusType = getstati(STAT_NADE_BONUS_TYPE);
984 vector nadeColor = NADES[bonusType].m_color;
985 string nadeIcon = NADES[bonusType].m_icon;
987 vector iconPos, textPos;
989 if(autocvar_hud_panel_ammo_iconalign)
991 iconPos = myPos + eX * 2 * mySize.y;
997 textPos = myPos + eX * mySize.y;
1000 if(bonusNades > 0 || bonusProgress > 0)
1002 DrawNadeProgressBar(myPos, mySize, bonusProgress, nadeColor);
1004 if(autocvar_hud_panel_ammo_text)
1005 drawstring_aspect(textPos, ftos(bonusNades), eX * (2/3) * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
1008 drawpic_aspect_skin_expanding(iconPos, nadeIcon, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, expand_time);
1010 drawpic_aspect_skin(iconPos, nadeIcon, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
1014 void DrawAmmoItem(vector myPos, vector mySize, .int ammoType, bool isCurrent, bool isInfinite)
1016 if(ammoType == ammo_none)
1019 // Initialize variables
1022 if(autocvar__hud_configure)
1024 isCurrent = (ammoType == ammo_rockets); // Rockets always current
1028 ammo = getstati(GetAmmoStat(ammoType));
1032 float scale = bound(0, autocvar_hud_panel_ammo_noncurrent_scale, 1);
1033 myPos = myPos + (mySize - mySize * scale) * 0.5;
1034 mySize = mySize * scale;
1037 vector iconPos, textPos;
1038 if(autocvar_hud_panel_ammo_iconalign)
1040 iconPos = myPos + eX * 2 * mySize.y;
1046 textPos = myPos + eX * mySize.y;
1049 bool isShadowed = (ammo <= 0 && !isCurrent && !isInfinite);
1051 vector iconColor = isShadowed ? '0 0 0' : '1 1 1';
1054 textColor = '0.2 0.95 0';
1056 textColor = '0 0 0';
1058 textColor = '0.8 0.04 0';
1060 textColor = '1 1 1';
1064 alpha = panel_fg_alpha;
1066 alpha = panel_fg_alpha * bound(0, autocvar_hud_panel_ammo_noncurrent_alpha, 1) * 0.5;
1068 alpha = panel_fg_alpha * bound(0, autocvar_hud_panel_ammo_noncurrent_alpha, 1);
1070 string text = isInfinite ? "\xE2\x88\x9E" : ftos(ammo); // Use infinity symbol (U+221E)
1075 drawpic_aspect_skin(myPos, "ammo_current_bg", mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
1077 if(ammo > 0 && autocvar_hud_panel_ammo_progressbar)
1078 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);
1080 if(autocvar_hud_panel_ammo_text)
1081 drawstring_aspect(textPos, text, eX * (2/3) * mySize.x + eY * mySize.y, textColor, alpha, DRAWFLAG_NORMAL);
1083 drawpic_aspect_skin(iconPos, GetAmmoPicture(ammoType), '1 1 0' * mySize.y, iconColor, alpha, DRAWFLAG_NORMAL);
1086 int nade_prevstatus;
1088 float nade_statuschange_time;
1091 if(intermission == 2) return;
1092 if(hud != HUD_NORMAL) return;
1093 if(!autocvar__hud_configure)
1095 if(!autocvar_hud_panel_ammo) return;
1096 if(spectatee_status == -1) return;
1099 HUD_Panel_UpdateCvars();
1101 draw_beginBoldFont();
1105 mySize = panel_size;
1107 HUD_Panel_DrawBg(1);
1108 if(panel_bg_padding)
1110 pos += '1 1 0' * panel_bg_padding;
1111 mySize -= '2 2 0' * panel_bg_padding;
1114 int rows = 0, columns, row, column;
1115 float nade_cnt = getstatf(STAT_NADE_BONUS), nade_score = getstatf(STAT_NADE_BONUS_SCORE);
1116 bool draw_nades = (nade_cnt > 0 || nade_score > 0);
1117 float nade_statuschange_elapsedtime;
1118 int total_ammo_count;
1121 if (autocvar_hud_panel_ammo_onlycurrent)
1122 total_ammo_count = 1;
1124 total_ammo_count = AMMO_COUNT;
1129 if (nade_cnt != nade_prevframe)
1131 nade_statuschange_time = time;
1132 nade_prevstatus = nade_prevframe;
1133 nade_prevframe = nade_cnt;
1137 nade_prevstatus = nade_prevframe = nade_statuschange_time = 0;
1139 rows = HUD_GetRowCount(total_ammo_count, mySize, 3);
1140 columns = ceil((total_ammo_count)/rows);
1141 ammo_size = eX * mySize.x*(1/columns) + eY * mySize.y*(1/rows);
1143 vector offset = '0 0 0'; // fteqcc sucks
1145 if(ammo_size.x/ammo_size.y > 3)
1147 newSize = 3 * ammo_size.y;
1148 offset.x = ammo_size.x - newSize;
1149 pos.x += offset.x/2;
1150 ammo_size.x = newSize;
1154 newSize = 1/3 * ammo_size.x;
1155 offset.y = ammo_size.y - newSize;
1156 pos.y += offset.y/2;
1157 ammo_size.y = newSize;
1161 bool infinite_ammo = (getstati(STAT_ITEMS, 0, 24) & IT_UNLIMITED_WEAPON_AMMO);
1163 if(autocvar_hud_panel_ammo_onlycurrent)
1165 if(autocvar__hud_configure)
1167 DrawAmmoItem(pos, ammo_size, ammo_rockets, true, false);
1174 (get_weaponinfo(switchweapon)).ammo_field,
1184 column = column + 1;
1191 for(i = 0; i < AMMO_COUNT; ++i)
1193 ammotype = GetAmmoFieldFromNum(i);
1195 pos + eX * column * (ammo_size.x + offset.x) + eY * row * (ammo_size.y + offset.y),
1198 ((get_weaponinfo(switchweapon)).ammo_field == ammotype),
1206 column = column + 1;
1213 nade_statuschange_elapsedtime = time - nade_statuschange_time;
1215 float f = bound(0, nade_statuschange_elapsedtime*2, 1);
1217 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);
1223 void DrawNumIcon_expanding(vector myPos, vector mySize, float x, string icon, bool vertical, bool icon_right_align, vector color, float theAlpha, float fadelerp)
1225 vector newPos = '0 0 0', newSize = '0 0 0';
1226 vector picpos, numpos;
1230 if(mySize.y/mySize.x > 2)
1232 newSize.y = 2 * mySize.x;
1233 newSize.x = mySize.x;
1235 newPos.y = myPos.y + (mySize.y - newSize.y) / 2;
1240 newSize.x = 1/2 * mySize.y;
1241 newSize.y = mySize.y;
1243 newPos.x = myPos.x + (mySize.x - newSize.x) / 2;
1247 if(icon_right_align)
1250 picpos = newPos + eY * newSize.x;
1255 numpos = newPos + eY * newSize.x;
1259 drawpic_aspect_skin(picpos, icon, newSize, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
1260 // make number smaller than icon, it looks better
1261 // reduce only y to draw numbers with different number of digits with the same y size
1262 numpos.y += newSize.y * ((1 - 0.7) / 2);
1264 drawstring_aspect(numpos, ftos(x), newSize, color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
1268 if(mySize.x/mySize.y > 3)
1270 newSize.x = 3 * mySize.y;
1271 newSize.y = mySize.y;
1273 newPos.x = myPos.x + (mySize.x - newSize.x) / 2;
1278 newSize.y = 1/3 * mySize.x;
1279 newSize.x = mySize.x;
1281 newPos.y = myPos.y + (mySize.y - newSize.y) / 2;
1285 if(icon_right_align) // right align
1288 picpos = newPos + eX * 2 * newSize.y;
1292 numpos = newPos + eX * newSize.y;
1296 // NOTE: newSize_x is always equal to 3 * mySize_y so we can use
1297 // '2 1 0' * newSize_y instead of eX * (2/3) * newSize_x + eY * newSize_y
1298 drawstring_aspect_expanding(numpos, ftos(x), '2 1 0' * newSize.y, color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL, fadelerp);
1299 drawpic_aspect_skin_expanding(picpos, icon, '1 1 0' * newSize.y, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL, fadelerp);
1302 void DrawNumIcon(vector myPos, vector mySize, float x, string icon, bool vertical, bool icon_right_align, vector color, float theAlpha)
1304 DrawNumIcon_expanding(myPos, mySize, x, icon, vertical, icon_right_align, color, theAlpha, 0);
1310 // Powerup item fields (reusing existing fields)
1311 .string message; // Human readable name
1312 .string netname; // Icon name
1313 .vector colormod; // Color
1314 .float count; // Time left
1315 .float lifetime; // Maximum time
1317 entity powerupItems;
1318 int powerupItemsCount;
1320 void resetPowerupItems()
1323 for(item = powerupItems; item; item = item.chain)
1326 powerupItemsCount = 0;
1329 void addPowerupItem(string name, string icon, vector color, float currentTime, float lifeTime)
1332 powerupItems = spawn();
1335 for(item = powerupItems; item.count; item = item.chain)
1337 item.chain = spawn();
1339 item.message = name;
1340 item.netname = icon;
1341 item.colormod = color;
1342 item.count = currentTime;
1343 item.lifetime = lifeTime;
1345 ++powerupItemsCount;
1348 int getPowerupItemAlign(int align, int column, int row, int columns, int rows, bool isVertical)
1353 bool isTop = isVertical && rows > 1 && row == 0;
1354 bool isBottom = isVertical && rows > 1 && row == rows-1;
1355 bool isLeft = !isVertical && columns > 1 && column == 0;
1356 bool isRight = !isVertical && columns > 1 && column == columns-1;
1358 if(isTop || isLeft) return (align == 2) ? 1 : 0;
1359 if(isBottom || isRight) return (align == 2) ? 0 : 1;
1364 void HUD_Powerups(void)
1366 if(intermission == 2) return;
1368 int allItems = getstati(STAT_ITEMS, 0, 24);
1369 int allBuffs = getstati(STAT_BUFFS, 0, 24);
1370 int strengthTime, shieldTime, superTime;
1373 if(!autocvar__hud_configure)
1375 if(!autocvar_hud_panel_powerups) return;
1376 if(spectatee_status == -1) return;
1377 if(getstati(STAT_HEALTH) <= 0) return;
1378 if(!(allItems & (IT_STRENGTH | IT_INVINCIBLE | IT_SUPERWEAPON)) && !allBuffs) return;
1380 strengthTime = bound(0, getstatf(STAT_STRENGTH_FINISHED) - time, 99);
1381 shieldTime = bound(0, getstatf(STAT_INVINCIBLE_FINISHED) - time, 99);
1382 superTime = bound(0, getstatf(STAT_SUPERWEAPONS_FINISHED) - time, 99);
1384 if(allItems & IT_UNLIMITED_SUPERWEAPONS)
1387 // Prevent stuff to show up on mismatch that will be fixed next frame
1388 if(!(allItems & IT_SUPERWEAPON))
1399 // Add items to linked list
1400 resetPowerupItems();
1403 addPowerupItem("Strength", "strength", autocvar_hud_progressbar_strength_color, strengthTime, 30);
1405 addPowerupItem("Shield", "shield", autocvar_hud_progressbar_shield_color, shieldTime, 30);
1407 addPowerupItem("Superweapons", "superweapons", autocvar_hud_progressbar_superweapons_color, superTime, 30);
1409 FOREACH(BUFFS, it.m_itemid & allBuffs, LAMBDA(
1410 addPowerupItem(it.m_prettyName, strcat("buff_", it.m_name), it.m_color, bound(0, getstatf(STAT_BUFF_TIME) - time, 99), 60);
1413 if(!powerupItemsCount)
1416 // Draw panel background
1417 HUD_Panel_UpdateCvars();
1418 HUD_Panel_DrawBg(1);
1421 vector pos = panel_pos;
1422 vector size = panel_size;
1423 bool isVertical = size.y > size.x;
1425 if(panel_bg_padding)
1427 pos += '1 1 0' * panel_bg_padding;
1428 size -= '2 2 0' * panel_bg_padding;
1431 // Find best partitioning of the drawing area
1432 const float DESIRED_ASPECT = 6;
1433 float aspect = 0, a;
1440 c = floor(powerupItemsCount / i);
1441 r = ceil(powerupItemsCount / c);
1442 a = isVertical ? (size.y/r) / (size.x/c) : (size.x/c) / (size.y/r);
1444 if(i == 1 || fabs(DESIRED_ASPECT - a) < fabs(DESIRED_ASPECT - aspect))
1451 while(++i <= powerupItemsCount);
1453 // Prevent single items from getting too wide
1454 if(powerupItemsCount == 1 && aspect > DESIRED_ASPECT)
1459 pos.y += size.y * 0.5;
1464 pos.x += size.x * 0.5;
1468 // Draw items from linked list
1469 vector itemPos = pos;
1470 vector itemSize = eX * (size.x / columns) + eY * (size.y / rows);
1471 vector textColor = '1 1 1';
1473 int fullSeconds = 0;
1478 draw_beginBoldFont();
1479 for(entity item = powerupItems; item.count; item = item.chain)
1481 itemPos = eX * (pos.x + column * itemSize.x) + eY * (pos.y + row * itemSize.y);
1484 if(autocvar_hud_panel_powerups_progressbar)
1486 align = getPowerupItemAlign(autocvar_hud_panel_powerups_baralign, column, row, columns, rows, isVertical);
1487 HUD_Panel_DrawProgressBar(itemPos, itemSize, "progressbar", item.count / item.lifetime, isVertical, align, item.colormod, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
1490 // Draw icon and text
1491 if(autocvar_hud_panel_powerups_text)
1493 align = getPowerupItemAlign(autocvar_hud_panel_powerups_iconalign, column, row, columns, rows, isVertical);
1494 fullSeconds = ceil(item.count);
1495 textColor = '0.6 0.6 0.6' + (item.colormod * 0.4);
1498 DrawNumIcon(itemPos, itemSize, fullSeconds, item.netname, isVertical, align, textColor, panel_fg_alpha);
1500 DrawNumIcon_expanding(itemPos, itemSize, fullSeconds, item.netname, isVertical, align, textColor, panel_fg_alpha, bound(0, (fullSeconds - item.count) / 0.5, 1));
1503 // Determine next section
1506 if(++column >= columns)
1524 // Health/armor (#3)
1528 void HUD_HealthArmor(void)
1530 int armor, health, fuel;
1531 if(intermission == 2) return;
1532 if(!autocvar__hud_configure)
1534 if(!autocvar_hud_panel_healtharmor) return;
1535 if(hud != HUD_NORMAL) return;
1536 if(spectatee_status == -1) return;
1538 health = getstati(STAT_HEALTH);
1544 armor = getstati(STAT_ARMOR);
1546 // code to check for spectatee_status changes is in Ent_ClientData()
1547 // prev_p_health and prev_health can be set to -1 there
1549 if (prev_p_health == -1)
1552 health_beforedamage = 0;
1553 armor_beforedamage = 0;
1554 health_damagetime = 0;
1555 armor_damagetime = 0;
1556 prev_health = health;
1558 old_p_health = health;
1559 old_p_armor = armor;
1560 prev_p_health = health;
1561 prev_p_armor = armor;
1563 else if (prev_health == -1)
1565 //start the load effect
1566 health_damagetime = 0;
1567 armor_damagetime = 0;
1571 fuel = getstati(STAT_FUEL);
1580 HUD_Panel_UpdateCvars();
1582 draw_beginBoldFont();
1586 mySize = panel_size;
1588 HUD_Panel_DrawBg(1);
1589 if(panel_bg_padding)
1591 pos += '1 1 0' * panel_bg_padding;
1592 mySize -= '2 2 0' * panel_bg_padding;
1595 int baralign = autocvar_hud_panel_healtharmor_baralign;
1596 int iconalign = autocvar_hud_panel_healtharmor_iconalign;
1598 int maxhealth = autocvar_hud_panel_healtharmor_maxhealth;
1599 int maxarmor = autocvar_hud_panel_healtharmor_maxarmor;
1600 if(autocvar_hud_panel_healtharmor == 2) // combined health and armor display
1603 v = healtharmor_maxdamage(health, armor, armorblockpercent, DEATH_WEAPON);
1608 float maxtotal = maxhealth + maxarmor;
1610 if(v.z) // NOT fully armored
1612 biggercount = "health";
1613 if(autocvar_hud_panel_healtharmor_progressbar)
1614 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);
1616 if(autocvar_hud_panel_healtharmor_text)
1617 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);
1621 biggercount = "armor";
1622 if(autocvar_hud_panel_healtharmor_progressbar)
1623 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);
1625 if(autocvar_hud_panel_healtharmor_text)
1626 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);
1628 if(autocvar_hud_panel_healtharmor_text)
1629 DrawNumIcon(pos, mySize, x, biggercount, 0, iconalign, HUD_Get_Num_Color(x, maxtotal), 1);
1632 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);
1636 float panel_ar = mySize.x/mySize.y;
1637 bool is_vertical = (panel_ar < 1);
1638 vector health_offset = '0 0 0', armor_offset = '0 0 0';
1639 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
1642 if (autocvar_hud_panel_healtharmor_flip)
1643 health_offset.x = mySize.x;
1645 armor_offset.x = mySize.x;
1650 if (autocvar_hud_panel_healtharmor_flip)
1651 health_offset.y = mySize.y;
1653 armor_offset.y = mySize.y;
1656 bool health_baralign, armor_baralign, fuel_baralign;
1657 bool health_iconalign, armor_iconalign;
1658 if (autocvar_hud_panel_healtharmor_flip)
1660 armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1);
1661 health_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1);
1662 fuel_baralign = health_baralign;
1663 armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1);
1664 health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1);
1668 health_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1);
1669 armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1);
1670 fuel_baralign = armor_baralign;
1671 health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1);
1672 armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1);
1677 if(autocvar_hud_panel_healtharmor_progressbar)
1679 float p_health, pain_health_alpha;
1681 pain_health_alpha = 1;
1682 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
1684 if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0)
1686 if (fabs(prev_health - health) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth)
1688 if (time - old_p_healthtime < 1)
1689 old_p_health = prev_p_health;
1691 old_p_health = prev_health;
1692 old_p_healthtime = time;
1694 if (time - old_p_healthtime < 1)
1696 p_health += (old_p_health - health) * (1 - (time - old_p_healthtime));
1697 prev_p_health = p_health;
1700 if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0)
1702 if (prev_health - health >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
1704 if (time - health_damagetime >= 1)
1705 health_beforedamage = prev_health;
1706 health_damagetime = time;
1708 if (time - health_damagetime < 1)
1710 float health_damagealpha = 1 - (time - health_damagetime)*(time - health_damagetime);
1711 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);
1714 prev_health = health;
1716 if (health <= autocvar_hud_panel_healtharmor_progressbar_gfx_lowhealth)
1718 float BLINK_FACTOR = 0.15;
1719 float BLINK_BASE = 0.85;
1720 float BLINK_FREQ = 9;
1721 pain_health_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ);
1724 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);
1726 if(autocvar_hud_panel_healtharmor_text)
1727 DrawNumIcon(pos + health_offset, mySize, health, "health", is_vertical, health_iconalign, HUD_Get_Num_Color(health, maxhealth), 1);
1732 if(autocvar_hud_panel_healtharmor_progressbar)
1736 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
1738 if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0)
1740 if (fabs(prev_armor - armor) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth)
1742 if (time - old_p_armortime < 1)
1743 old_p_armor = prev_p_armor;
1745 old_p_armor = prev_armor;
1746 old_p_armortime = time;
1748 if (time - old_p_armortime < 1)
1750 p_armor += (old_p_armor - armor) * (1 - (time - old_p_armortime));
1751 prev_p_armor = p_armor;
1754 if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0)
1756 if (prev_armor - armor >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
1758 if (time - armor_damagetime >= 1)
1759 armor_beforedamage = prev_armor;
1760 armor_damagetime = time;
1762 if (time - armor_damagetime < 1)
1764 float armor_damagealpha = 1 - (time - armor_damagetime)*(time - armor_damagetime);
1765 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);
1770 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);
1772 if(autocvar_hud_panel_healtharmor_text)
1773 DrawNumIcon(pos + armor_offset, mySize, armor, "armor", is_vertical, armor_iconalign, HUD_Get_Num_Color(armor, maxarmor), 1);
1779 mySize.x *= 0.2 / 2; //if vertical always halve x to not cover too much numbers with 3 digits
1783 mySize.x *= 2; //restore full panel size
1784 else if (panel_ar < 1/4)
1785 mySize.y *= 2; //restore full panel size
1786 HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", fuel/100, is_vertical, fuel_baralign, autocvar_hud_progressbar_fuel_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
1793 // Notification area (#4)
1796 void HUD_Notify_Push(string icon, string attacker, string victim)
1804 if (notify_index == -1)
1805 notify_index = NOTIFY_MAX_ENTRIES-1;
1808 if (notify_attackers[notify_index])
1809 strunzone(notify_attackers[notify_index]);
1811 if (notify_victims[notify_index])
1812 strunzone(notify_victims[notify_index]);
1814 if (notify_icons[notify_index])
1815 strunzone(notify_icons[notify_index]);
1817 // Allocate new strings
1820 notify_attackers[notify_index] = strzone(attacker);
1821 notify_victims[notify_index] = strzone(victim);
1825 // In case of a notification without a victim, the attacker
1826 // is displayed on the victim's side. Instead of special
1827 // treatment later on, we can simply switch them here.
1828 notify_attackers[notify_index] = string_null;
1829 notify_victims[notify_index] = strzone(attacker);
1832 notify_icons[notify_index] = strzone(icon);
1833 notify_times[notify_index] = time;
1836 void HUD_Notify(void)
1838 if(intermission == 2) return;
1839 if (!autocvar__hud_configure)
1840 if (!autocvar_hud_panel_notify)
1843 HUD_Panel_UpdateCvars();
1844 HUD_Panel_DrawBg(1);
1846 if (!autocvar__hud_configure)
1847 if (notify_count == 0)
1854 if (panel_bg_padding)
1856 pos += '1 1 0' * panel_bg_padding;
1857 size -= '2 2 0' * panel_bg_padding;
1860 float fade_start = max(0, autocvar_hud_panel_notify_time);
1861 float fade_time = max(0, autocvar_hud_panel_notify_fadetime);
1862 float icon_aspect = max(1, autocvar_hud_panel_notify_icon_aspect);
1864 int entry_count = bound(1, floor(NOTIFY_MAX_ENTRIES * size.y / size.x), NOTIFY_MAX_ENTRIES);
1865 float entry_height = size.y / entry_count;
1867 float panel_width_half = size.x * 0.5;
1868 float icon_width_half = entry_height * icon_aspect / 2;
1869 float name_maxwidth = panel_width_half - icon_width_half - size.x * NOTIFY_ICON_MARGIN;
1871 vector font_size = '0.5 0.5 0' * entry_height * autocvar_hud_panel_notify_fontsize;
1872 vector icon_size = (eX * icon_aspect + eY) * entry_height;
1873 vector icon_left = eX * (panel_width_half - icon_width_half);
1874 vector attacker_right = eX * name_maxwidth;
1875 vector victim_left = eX * (size.x - name_maxwidth);
1877 vector attacker_pos, victim_pos, icon_pos;
1878 string attacker, victim, icon;
1879 int i, j, count, step, limit;
1882 if (autocvar_hud_panel_notify_flip)
1884 // Order items from the top down
1887 limit = entry_count;
1891 // Order items from the bottom up
1892 i = entry_count - 1;
1897 for (j = notify_index, count = 0; i != limit; i += step, ++j, ++count)
1899 if(autocvar__hud_configure)
1901 attacker = sprintf(_("Player %d"), count + 1);
1902 victim = sprintf(_("Player %d"), count + 2);
1903 icon = get_weaponinfo(min(WEP_FIRST + count * 2, WEP_LAST)).model2;
1904 alpha = bound(0, 1.2 - count / entry_count, 1);
1908 if (j == NOTIFY_MAX_ENTRIES)
1911 if (notify_times[j] + fade_start > time)
1913 else if (fade_time != 0)
1915 alpha = bound(0, (notify_times[j] + fade_start + fade_time - time) / fade_time, 1);
1922 attacker = notify_attackers[j];
1923 victim = notify_victims[j];
1924 icon = notify_icons[j];
1927 if (icon != "" && victim != "")
1929 vector name_top = eY * (i * entry_height + 0.5 * (entry_height - font_size.y));
1931 icon_pos = pos + icon_left + eY * i * entry_height;
1932 drawpic_aspect_skin(icon_pos, icon, icon_size, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1934 victim = textShortenToWidth(victim, name_maxwidth, font_size, stringwidth_colors);
1935 victim_pos = pos + victim_left + name_top;
1936 drawcolorcodedstring(victim_pos, victim, font_size, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1940 attacker = textShortenToWidth(attacker, name_maxwidth, font_size, stringwidth_colors);
1941 attacker_pos = pos + attacker_right - eX * stringwidth(attacker, true, font_size) + name_top;
1942 drawcolorcodedstring(attacker_pos, attacker, font_size, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1947 notify_count = count;
1953 string seconds_tostring(float sec)
1956 minutes = floor(sec / 60);
1958 sec -= minutes * 60;
1959 return sprintf("%d:%02d", minutes, sec);
1962 void HUD_Timer(void)
1964 if(intermission == 2) return;
1965 if(!autocvar__hud_configure)
1967 if(!autocvar_hud_panel_timer) return;
1970 HUD_Panel_UpdateCvars();
1972 draw_beginBoldFont();
1976 mySize = panel_size;
1978 HUD_Panel_DrawBg(1);
1979 if(panel_bg_padding)
1981 pos += '1 1 0' * panel_bg_padding;
1982 mySize -= '2 2 0' * panel_bg_padding;
1986 float timelimit, elapsedTime, timeleft, minutesLeft;
1988 timelimit = getstatf(STAT_TIMELIMIT);
1990 timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
1991 timeleft = ceil(timeleft);
1993 minutesLeft = floor(timeleft / 60);
1996 if(minutesLeft >= 5 || warmup_stage || timelimit == 0) //don't use red or yellow in warmup or when there is no timelimit
1997 timer_color = '1 1 1'; //white
1998 else if(minutesLeft >= 1)
1999 timer_color = '1 1 0'; //yellow
2001 timer_color = '1 0 0'; //red
2003 if (autocvar_hud_panel_timer_increment || timelimit == 0 || warmup_stage) {
2004 if (time < getstatf(STAT_GAMESTARTTIME)) {
2005 //while restart is still active, show 00:00
2006 timer = seconds_tostring(0);
2008 elapsedTime = floor(time - getstatf(STAT_GAMESTARTTIME)); //127
2009 timer = seconds_tostring(elapsedTime);
2012 timer = seconds_tostring(timeleft);
2015 drawstring_aspect(pos, timer, mySize, timer_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2023 float HUD_Radar_Clickable()
2025 return hud_panel_radar_mouse && !hud_panel_radar_temp_hidden;
2028 void HUD_Radar_Show_Maximized(bool doshow,float clickable)
2030 hud_panel_radar_maximized = doshow;
2031 hud_panel_radar_temp_hidden = 0;
2037 if(autocvar_hud_cursormode)
2039 hud_panel_radar_mouse = 1;
2042 else if ( hud_panel_radar_mouse )
2044 hud_panel_radar_mouse = 0;
2046 if(autocvar_hud_cursormode)
2051 void HUD_Radar_Hide_Maximized()
2053 HUD_Radar_Show_Maximized(false,false);
2057 float HUD_Radar_InputEvent(float bInputType, float nPrimary, float nSecondary)
2059 if(!hud_panel_radar_maximized || !hud_panel_radar_mouse ||
2060 autocvar__hud_configure || mv_active)
2065 mousepos_x = nPrimary;
2066 mousepos_y = nSecondary;
2070 if(nPrimary == K_MOUSE1)
2072 if(bInputType == 0) // key pressed
2073 mouseClicked |= S_MOUSE1;
2074 else if(bInputType == 1) // key released
2075 mouseClicked -= (mouseClicked & S_MOUSE1);
2077 else if(nPrimary == K_MOUSE2)
2079 if(bInputType == 0) // key pressed
2080 mouseClicked |= S_MOUSE2;
2081 else if(bInputType == 1) // key released
2082 mouseClicked -= (mouseClicked & S_MOUSE2);
2084 else if ( nPrimary == K_ESCAPE && bInputType == 0 )
2086 HUD_Radar_Hide_Maximized();
2090 // allow console/use binds to work without hiding the map
2094 con_keys = strcat(findkeysforcommand("toggleconsole", 0)," ",findkeysforcommand("+use", 0)) ;
2095 keys = tokenize(con_keys); // findkeysforcommand returns data for this
2096 for (i = 0; i < keys; ++i)
2098 if(nPrimary == stof(argv(i)))
2102 if ( getstati(STAT_HEALTH) <= 0 )
2105 if ( bInputType < 2 )
2107 con_keys = findkeysforcommand("+showscores", 0);
2108 keys = tokenize(con_keys);
2109 for (i = 0; i < keys; ++i)
2111 if ( nPrimary == stof(argv(i)) )
2113 hud_panel_radar_temp_hidden = bInputType == 0;
2119 else if ( bInputType == 0 )
2120 HUD_Radar_Hide_Maximized();
2128 void HUD_Radar_Mouse()
2130 if ( !hud_panel_radar_mouse ) return;
2131 if(mv_active) return;
2135 HUD_Radar_Hide_Maximized();
2139 if(mouseClicked & S_MOUSE2)
2141 HUD_Radar_Hide_Maximized();
2145 if(!autocvar_hud_cursormode)
2147 mousepos = mousepos + getmousepos() * autocvar_menu_mouse_speed;
2149 mousepos_x = bound(0, mousepos_x, vid_conwidth);
2150 mousepos_y = bound(0, mousepos_y, vid_conheight);
2153 HUD_Panel_UpdateCvars();
2156 panel_size = autocvar_hud_panel_radar_maximized_size;
2157 panel_size_x = bound(0.2, panel_size_x, 1) * vid_conwidth;
2158 panel_size_y = bound(0.2, panel_size_y, 1) * vid_conheight;
2159 panel_pos_x = (vid_conwidth - panel_size_x) / 2;
2160 panel_pos_y = (vid_conheight - panel_size_y) / 2;
2162 if(mouseClicked & S_MOUSE1)
2165 if ( mousepos_x < panel_pos_x || mousepos_x > panel_pos_x + panel_size_x ||
2166 mousepos_y < panel_pos_y || mousepos_y > panel_pos_y + panel_size_y )
2168 HUD_Radar_Hide_Maximized();
2171 vector pos = teamradar_texcoord_to_3dcoord(teamradar_2dcoord_to_texcoord(mousepos),view_origin_z);
2172 localcmd(sprintf("cmd ons_spawn %f %f %f",pos_x,pos_y,pos_z));
2174 HUD_Radar_Hide_Maximized();
2179 const vector cursor_size = '32 32 0';
2180 drawpic(mousepos-'8 4 0', strcat("gfx/menu/", autocvar_menu_skin, "/cursor.tga"), cursor_size, '1 1 1', 0.8, DRAWFLAG_NORMAL);
2183 void HUD_Radar(void)
2185 if(intermission == 2) return;
2186 if (!autocvar__hud_configure)
2188 if (hud_panel_radar_maximized)
2190 if (!hud_draw_maximized) return;
2194 if (autocvar_hud_panel_radar == 0) return;
2195 if (autocvar_hud_panel_radar != 2 && !teamplay) return;
2196 if(radar_panel_modified)
2198 panel.update_time = time; // forces reload of panel attributes
2199 radar_panel_modified = false;
2204 if ( hud_panel_radar_temp_hidden )
2207 HUD_Panel_UpdateCvars();
2211 if (hud_panel_radar_maximized && !autocvar__hud_configure)
2213 panel_size = autocvar_hud_panel_radar_maximized_size;
2214 panel_size.x = bound(0.2, panel_size.x, 1) * vid_conwidth;
2215 panel_size.y = bound(0.2, panel_size.y, 1) * vid_conheight;
2216 panel_pos.x = (vid_conwidth - panel_size.x) / 2;
2217 panel_pos.y = (vid_conheight - panel_size.y) / 2;
2220 panel_bg = strcat(hud_skin_path, "/border_default"); // always use the default border when maximized
2221 if(precache_pic(panel_bg) == "")
2222 panel_bg = "gfx/hud/default/border_default"; // fallback
2223 if(!radar_panel_modified && panel_bg != panel.current_panel_bg)
2224 radar_panel_modified = true;
2225 if(panel.current_panel_bg)
2226 strunzone(panel.current_panel_bg);
2227 panel.current_panel_bg = strzone(panel_bg);
2229 switch(hud_panel_radar_maximized_zoommode)
2233 f = current_zoomfraction;
2236 f = 1 - current_zoomfraction;
2246 switch(hud_panel_radar_maximized_rotation)
2249 teamradar_angle = view_angles.y - 90;
2252 teamradar_angle = 90 * hud_panel_radar_maximized_rotation;
2256 if (!hud_panel_radar_maximized && !autocvar__hud_configure)
2258 switch(hud_panel_radar_zoommode)
2262 f = current_zoomfraction;
2265 f = 1 - current_zoomfraction;
2275 switch(hud_panel_radar_rotation)
2278 teamradar_angle = view_angles.y - 90;
2281 teamradar_angle = 90 * hud_panel_radar_rotation;
2288 mySize = panel_size;
2290 HUD_Panel_DrawBg(1);
2291 if(panel_bg_padding)
2293 pos += '1 1 0' * panel_bg_padding;
2294 mySize -= '2 2 0' * panel_bg_padding;
2299 float scale2d, normalsize, bigsize;
2301 teamradar_origin2d = pos + 0.5 * mySize;
2302 teamradar_size2d = mySize;
2304 if(minimapname == "")
2307 teamradar_loadcvars();
2309 scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
2310 teamradar_size2d = mySize;
2312 teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0'; // we always center
2314 // pixels per world qu to match the teamradar_size2d_x range in the longest dimension
2315 if((hud_panel_radar_rotation == 0 && !hud_panel_radar_maximized) || (hud_panel_radar_maximized_rotation == 0 && hud_panel_radar_maximized))
2317 // max-min distance must fit the radar in any rotation
2318 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen2d(mi_scale));
2322 vector c0, c1, c2, c3, span;
2323 c0 = rotate(mi_min, teamradar_angle * DEG2RAD);
2324 c1 = rotate(mi_max, teamradar_angle * DEG2RAD);
2325 c2 = rotate('1 0 0' * mi_min.x + '0 1 0' * mi_max.y, teamradar_angle * DEG2RAD);
2326 c3 = rotate('1 0 0' * mi_max.x + '0 1 0' * mi_min.y, teamradar_angle * DEG2RAD);
2328 span.x = max(c0_x, c1_x, c2_x, c3_x) - min(c0_x, c1_x, c2_x, c3_x);
2329 span.y = max(c0_y, c1_y, c2_y, c3_y) - min(c0_y, c1_y, c2_y, c3_y);
2331 // max-min distance must fit the radar in x=x, y=y
2333 teamradar_size2d.x * scale2d / (1.05 * span.x),
2334 teamradar_size2d.y * scale2d / (1.05 * span.y)
2338 normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / hud_panel_radar_scale;
2339 if(bigsize > normalsize)
2340 normalsize = bigsize;
2344 + (1 - f) * normalsize;
2345 teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
2347 + (1 - f) * view_origin);
2356 draw_teamradar_background(hud_panel_radar_foreground_alpha);
2358 for(tm = world; (tm = find(tm, classname, "radarlink")); )
2359 draw_teamradar_link(tm.origin, tm.velocity, tm.team);
2363 for(tm = world; (tm = findflags(tm, teamradar_icon, 0xFFFFFF)); )
2365 if ( hud_panel_radar_mouse )
2366 if ( tm.health > 0 )
2367 if ( tm.team == myteam+1 )
2369 coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(tm.origin));
2370 if ( vlen(mousepos-coord) < 8 )
2372 brightcolor_x = min(1,tm.teamradar_color_x*1.5);
2373 brightcolor_y = min(1,tm.teamradar_color_y*1.5);
2374 brightcolor_z = min(1,tm.teamradar_color_z*1.5);
2375 drawpic(coord - '8 8 0', "gfx/teamradar_icon_glow", '16 16 0', brightcolor, panel_fg_alpha, 0);
2379 draw_teamradar_icon(tm.origin, tm.teamradar_icon, tm, tm.teamradar_color, panel_fg_alpha);
2381 for(tm = world; (tm = find(tm, classname, "entcs_receiver")); )
2383 color2 = GetPlayerColor(tm.sv_entnum);
2384 //if(color == NUM_SPECTATOR || color == color2)
2385 draw_teamradar_player(tm.origin, tm.angles, Team_ColorRGB(color2));
2387 draw_teamradar_player(view_origin, view_angles, '1 1 1');
2389 drawresetcliparea();
2391 if ( hud_panel_radar_mouse )
2393 string message = "Click to select teleport destination";
2395 if ( getstati(STAT_HEALTH) <= 0 )
2397 message = "Click to select spawn location";
2400 drawcolorcodedstring(pos + '0.5 0 0' * (mySize_x - stringwidth(message, true, hud_fontsize)) - '0 1 0' * hud_fontsize_y * 2,
2401 message, hud_fontsize, hud_panel_radar_foreground_alpha, DRAWFLAG_NORMAL);
2403 hud_panel_radar_bottom = pos_y + mySize_y + hud_fontsize_y;
2409 void HUD_UpdatePlayerTeams();
2410 void HUD_Score_Rankings(vector pos, vector mySize, entity me)
2413 entity tm = world, pl;
2414 int SCOREPANEL_MAX_ENTRIES = 6;
2415 float SCOREPANEL_ASPECTRATIO = 2;
2416 int entries = bound(1, floor(SCOREPANEL_MAX_ENTRIES * mySize.y/mySize.x * SCOREPANEL_ASPECTRATIO), SCOREPANEL_MAX_ENTRIES);
2417 vector fontsize = '1 1 0' * (mySize.y/entries);
2419 vector rgb, score_color;
2421 score_color = '1 1 1';
2423 float name_size = mySize.x*0.75;
2424 float spacing_size = mySize.x*0.04;
2425 const float highlight_alpha = 0.2;
2426 int i = 0, first_pl = 0;
2427 bool me_printed = false;
2429 if (autocvar__hud_configure)
2431 float players_per_team = 0;
2434 // show team scores in the first line
2435 float score_size = mySize.x / team_count;
2436 players_per_team = max(2, ceil((entries - 1) / team_count));
2437 for(i=0; i<team_count; ++i) {
2438 if (i == floor((entries - 2) / players_per_team) || (entries == 1 && i == 0))
2439 HUD_Panel_DrawHighlight(pos + eX * score_size * i, eX * score_size + eY * fontsize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2440 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);
2443 pos.y += fontsize.y;
2445 score = 10 + SCOREPANEL_MAX_ENTRIES * 3;
2446 for (i=first_pl; i<entries; ++i)
2448 //simulate my score is lower than all displayed players,
2449 //so that I don't appear at all showing pure rankings.
2450 //This is to better show the difference between the 2 ranking views
2451 if (i == entries-1 && autocvar_hud_panel_score_rankings == 1)
2454 drawfill(pos, eX * mySize.x + eY * fontsize.y, rgb, highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2455 s = GetPlayerName(player_localnum);
2460 s = sprintf(_("Player %d"), i + 1 - first_pl);
2465 score_color = Team_ColorRGB(ColorByTeam(floor((i - first_pl) / players_per_team))) * 0.8;
2466 s = textShortenToWidth(s, name_size, fontsize, stringwidth_colors);
2467 drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, true, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
2468 drawstring(pos + eX * (name_size + spacing_size), ftos(score), fontsize, score_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2469 pos.y += fontsize.y;
2474 if (!scoreboard_fade_alpha) // the scoreboard too calls HUD_UpdatePlayerTeams
2475 HUD_UpdatePlayerTeams();
2478 // show team scores in the first line
2479 float score_size = mySize.x / team_count;
2480 for(tm = teams.sort_next; tm; tm = tm.sort_next) {
2481 if(tm.team == NUM_SPECTATOR)
2483 if (tm.team == myteam)
2484 drawfill(pos + eX * score_size * i, eX * score_size + eY * fontsize.y, '1 1 1', highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2485 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);
2489 pos.y += fontsize.y;
2490 tm = teams.sort_next;
2495 for (pl = players.sort_next; pl && i<entries; pl = pl.sort_next)
2497 if ((team_count && pl.team != tm.team) || pl.team == NUM_SPECTATOR)
2500 if (i == entries-1 && !me_printed && pl != me)
2501 if (autocvar_hud_panel_score_rankings == 1 && spectatee_status != -1)
2503 for (pl = me.sort_next; pl; pl = pl.sort_next)
2504 if (pl.team != NUM_SPECTATOR)
2508 rgb = '1 1 0'; //not last but not among the leading players: yellow
2510 rgb = '1 0 0'; //last: red
2517 rgb = '0 1 0'; //first: green
2519 drawfill(pos, eX * mySize.x + eY * fontsize.y, rgb, highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2522 score_color = Team_ColorRGB(pl.team) * 0.8;
2523 s = textShortenToWidth(GetPlayerName(pl.sv_entnum), name_size, fontsize, stringwidth_colors);
2524 drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, true, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
2525 drawstring(pos + eX * (name_size + spacing_size), ftos(pl.(scores[ps_primary])), fontsize, score_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2526 pos.y += fontsize.y;
2529 while (i<entries && team_count && (tm = tm.sort_next) && (tm.team != NUM_SPECTATOR || (tm = tm.sort_next)));
2532 void HUD_Score(void)
2534 if(intermission == 2) return;
2535 if(!autocvar__hud_configure)
2537 if(!autocvar_hud_panel_score) return;
2538 if(spectatee_status == -1 && (gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return;
2541 HUD_Panel_UpdateCvars();
2544 mySize = panel_size;
2546 HUD_Panel_DrawBg(1);
2547 if(panel_bg_padding)
2549 pos += '1 1 0' * panel_bg_padding;
2550 mySize -= '2 2 0' * panel_bg_padding;
2553 float score, distribution = 0;
2555 vector distribution_color;
2558 me = playerslots[current_player];
2560 if((scores_flags[ps_primary] & SFL_TIME) && !teamplay) { // race/cts record display on HUD
2561 string timer, distrtimer;
2563 pl = players.sort_next;
2566 if(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)
2567 if(pl.scores[ps_primary] == 0)
2570 score = me.(scores[ps_primary]);
2571 timer = TIME_ENCODED_TOSTRING(score);
2573 draw_beginBoldFont();
2574 if (pl && ((!(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)) || score)) {
2575 // distribution display
2576 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
2578 distrtimer = ftos_decimals(fabs(distribution/pow(10, TIME_DECIMALS)), TIME_DECIMALS);
2580 if (distribution <= 0) {
2581 distribution_color = '0 1 0';
2585 distribution_color = '1 0 0';
2588 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);
2590 // race record display
2591 if (distribution <= 0)
2592 HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2593 drawstring_aspect(pos, timer, eX * 0.75 * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2595 } else if (!teamplay) { // non-teamgames
2596 if ((spectatee_status == -1 && !autocvar__hud_configure) || autocvar_hud_panel_score_rankings)
2598 HUD_Score_Rankings(pos, mySize, me);
2601 // me vector := [team/connected frags id]
2602 pl = players.sort_next;
2606 if(autocvar__hud_configure)
2609 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
2613 score = me.(scores[ps_primary]);
2614 if(autocvar__hud_configure)
2617 if(distribution >= 5)
2618 distribution_color = eY;
2619 else if(distribution >= 0)
2620 distribution_color = '1 1 1';
2621 else if(distribution >= -5)
2622 distribution_color = '1 1 0';
2624 distribution_color = eX;
2626 string distribution_str;
2627 distribution_str = ftos(distribution);
2628 draw_beginBoldFont();
2629 if (distribution >= 0)
2631 if (distribution > 0)
2632 distribution_str = strcat("+", distribution_str);
2633 HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2635 drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize.x + eY * mySize.y, distribution_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2636 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);
2638 } else { // teamgames
2639 float row, column, rows = 0, columns = 0;
2640 vector offset = '0 0 0';
2641 vector score_pos, score_size; //for scores other than myteam
2642 if(autocvar_hud_panel_score_rankings)
2644 HUD_Score_Rankings(pos, mySize, me);
2647 if(spectatee_status == -1)
2649 rows = HUD_GetRowCount(team_count, mySize, 3);
2650 columns = ceil(team_count/rows);
2651 score_size = eX * mySize.x*(1/columns) + eY * mySize.y*(1/rows);
2654 if(score_size.x/score_size.y > 3)
2656 newSize = 3 * score_size.y;
2657 offset.x = score_size.x - newSize;
2658 pos.x += offset.x/2;
2659 score_size.x = newSize;
2663 newSize = 1/3 * score_size.x;
2664 offset.y = score_size.y - newSize;
2665 pos.y += offset.y/2;
2666 score_size.y = newSize;
2670 score_size = eX * mySize.x*(1/4) + eY * mySize.y*(1/3);
2672 float max_fragcount;
2673 max_fragcount = -99;
2674 draw_beginBoldFont();
2676 for(tm = teams.sort_next; tm; tm = tm.sort_next) {
2677 if(tm.team == NUM_SPECTATOR)
2679 score = tm.(teamscores[ts_primary]);
2680 if(autocvar__hud_configure)
2683 if (score > max_fragcount)
2684 max_fragcount = score;
2686 if (spectatee_status == -1)
2688 score_pos = pos + eX * column * (score_size.x + offset.x) + eY * row * (score_size.y + offset.y);
2689 if (max_fragcount == score)
2690 HUD_Panel_DrawHighlight(score_pos, score_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2691 drawstring_aspect(score_pos, ftos(score), score_size, Team_ColorRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2699 else if(tm.team == myteam) {
2700 if (max_fragcount == score)
2701 HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2702 drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize.x + eY * mySize.y, Team_ColorRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2704 if (max_fragcount == score)
2705 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);
2706 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);
2716 void HUD_RaceTimer (void)
2718 if(intermission == 2) return;
2719 if(!autocvar__hud_configure)
2721 if(!autocvar_hud_panel_racetimer) return;
2722 if(!(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return;
2723 if(spectatee_status == -1) return;
2726 HUD_Panel_UpdateCvars();
2730 mySize = panel_size;
2732 HUD_Panel_DrawBg(1);
2733 if(panel_bg_padding)
2735 pos += '1 1 0' * panel_bg_padding;
2736 mySize -= '2 2 0' * panel_bg_padding;
2739 // always force 4:1 aspect
2740 vector newSize = '0 0 0';
2741 if(mySize.x/mySize.y > 4)
2743 newSize.x = 4 * mySize.y;
2744 newSize.y = mySize.y;
2746 pos.x = pos.x + (mySize.x - newSize.x) / 2;
2750 newSize.y = 1/4 * mySize.x;
2751 newSize.x = mySize.x;
2753 pos.y = pos.y + (mySize.y - newSize.y) / 2;
2758 string s, forcetime;
2760 if(autocvar__hud_configure)
2763 draw_beginBoldFont();
2764 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);
2766 s = _("^1Intermediate 1 (+15.42)");
2767 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);
2768 s = sprintf(_("^1PENALTY: %.1f (%s)"), 2, "missing a checkpoint");
2769 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);
2771 else if(race_checkpointtime)
2773 a = bound(0, 2 - (time - race_checkpointtime), 1);
2776 if(a > 0) // just hit a checkpoint?
2778 if(race_checkpoint != 254)
2780 if(race_time && race_previousbesttime)
2781 s = MakeRaceString(race_checkpoint, TIME_DECODE(race_time) - TIME_DECODE(race_previousbesttime), 0, 0, race_previousbestname);
2783 s = MakeRaceString(race_checkpoint, 0, -1, 0, race_previousbestname);
2785 forcetime = TIME_ENCODED_TOSTRING(race_time);
2790 if(race_laptime && race_nextbesttime && race_nextcheckpoint != 254)
2792 a = bound(0, 2 - ((race_laptime + TIME_DECODE(race_nextbesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1);
2793 if(a > 0) // next one?
2795 s = MakeRaceString(race_nextcheckpoint, (time + TIME_DECODE(race_penaltyaccumulator)) - race_laptime, TIME_DECODE(race_nextbesttime), 0, race_nextbestname);
2800 if(s != "" && a > 0)
2802 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);
2805 if(race_penaltytime)
2807 a = bound(0, 2 - (time - race_penaltyeventtime), 1);
2810 s = sprintf(_("^1PENALTY: %.1f (%s)"), race_penaltytime * 0.1, race_penaltyreason);
2811 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);
2815 draw_beginBoldFont();
2819 a = bound(0, (time - race_checkpointtime) / 0.5, 1);
2820 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);
2825 if(race_laptime && race_checkpoint != 255)
2827 s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime));
2828 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);
2835 if(race_mycheckpointtime)
2837 a = bound(0, 2 - (time - race_mycheckpointtime), 1);
2838 s = MakeRaceString(race_mycheckpoint, TIME_DECODE(race_mycheckpointdelta), -(race_mycheckpointenemy == ""), race_mycheckpointlapsdelta, race_mycheckpointenemy);
2839 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);
2841 if(race_othercheckpointtime && race_othercheckpointenemy != "")
2843 a = bound(0, 2 - (time - race_othercheckpointtime), 1);
2844 s = MakeRaceString(race_othercheckpoint, -TIME_DECODE(race_othercheckpointdelta), -(race_othercheckpointenemy == ""), race_othercheckpointlapsdelta, race_othercheckpointenemy);
2845 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);
2848 if(race_penaltytime && !race_penaltyaccumulator)
2850 t = race_penaltytime * 0.1 + race_penaltyeventtime;
2851 a = bound(0, (1 + t - time), 1);
2855 s = sprintf(_("^1PENALTY: %.1f (%s)"), (t - time) * 0.1, race_penaltyreason);
2857 s = sprintf(_("^2PENALTY: %.1f (%s)"), 0, race_penaltyreason);
2858 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);
2869 if(intermission == 2) return;
2870 if(autocvar_cl_allow_uid2name == -1 && (gametype == MAPINFO_TYPE_CTS || gametype == MAPINFO_TYPE_RACE || (serverflags & SERVERFLAG_PLAYERSTATS)))
2873 if (autocvar__hud_configure)
2877 print(_("^1You must answer before entering hud configure mode\n"));
2878 cvar_set("_hud_configure", "0");
2880 if(vote_called_vote)
2881 strunzone(vote_called_vote);
2882 vote_called_vote = strzone(_("^2Name ^7instead of \"^1Anonymous player^7\" in stats"));
2883 uid2name_dialog = 1;
2886 if(!autocvar__hud_configure)
2888 if(!autocvar_hud_panel_vote) return;
2890 panel_fg_alpha = autocvar_hud_panel_fg_alpha;
2891 panel_bg_alpha_str = autocvar_hud_panel_vote_bg_alpha;
2893 if(panel_bg_alpha_str == "") {
2894 panel_bg_alpha_str = ftos(autocvar_hud_panel_bg_alpha);
2896 panel_bg_alpha = stof(panel_bg_alpha_str);
2907 if(vote_active != vote_prev) {
2909 vote_prev = vote_active;
2912 if(vote_active || autocvar__hud_configure)
2913 vote_alpha = bound(0, (time - vote_change) * 2, 1);
2915 vote_alpha = bound(0, 1 - (time - vote_change) * 2, 1);
2920 HUD_Panel_UpdateCvars();
2924 panel_pos = eX * 0.3 * vid_conwidth + eY * 0.1 * vid_conheight;
2925 panel_size = eX * 0.4 * vid_conwidth + eY * 0.3 * vid_conheight;
2928 // these must be below above block
2931 mySize = panel_size;
2933 a = vote_alpha * (vote_highlighted ? autocvar_hud_panel_vote_alreadyvoted_alpha : 1);
2934 HUD_Panel_DrawBg(a);
2935 a = panel_fg_alpha * a;
2937 if(panel_bg_padding)
2939 pos += '1 1 0' * panel_bg_padding;
2940 mySize -= '2 2 0' * panel_bg_padding;
2943 // always force 3:1 aspect
2944 vector newSize = '0 0 0';
2945 if(mySize.x/mySize.y > 3)
2947 newSize.x = 3 * mySize.y;
2948 newSize.y = mySize.y;
2950 pos.x = pos.x + (mySize.x - newSize.x) / 2;
2954 newSize.y = 1/3 * mySize.x;
2955 newSize.x = mySize.x;
2957 pos.y = pos.y + (mySize.y - newSize.y) / 2;
2961 s = _("A vote has been called for:");
2963 s = _("Allow servers to store and display your name?");
2964 drawstring_aspect(pos, s, eX * mySize.x + eY * (2/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
2965 s = textShortenToWidth(vote_called_vote, mySize.x, '1 1 0' * mySize.y * (1/8), stringwidth_colors);
2966 if(autocvar__hud_configure)
2967 s = _("^1Configure the HUD");
2968 drawcolorcodedstring_aspect(pos + eY * (2/8) * mySize.y, s, eX * mySize.x + eY * (1.75/8) * mySize.y, a, DRAWFLAG_NORMAL);
2970 // print the yes/no counts
2971 s = sprintf(_("Yes (%s): %d"), getcommandkey("vyes", "vyes"), vote_yescount);
2972 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);
2973 s = sprintf(_("No (%s): %d"), getcommandkey("vno", "vno"), vote_nocount);
2974 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);
2976 // draw the progress bar backgrounds
2977 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_back", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
2979 // draw the highlights
2980 if(vote_highlighted == 1) {
2981 drawsetcliparea(pos.x, pos.y, mySize.x * 0.5, mySize.y);
2982 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_voted", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
2984 else if(vote_highlighted == -1) {
2985 drawsetcliparea(pos.x + 0.5 * mySize.x, pos.y, mySize.x * 0.5, mySize.y);
2986 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_voted", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
2989 // draw the progress bars
2990 if(vote_yescount && vote_needed)
2992 drawsetcliparea(pos.x, pos.y, mySize.x * 0.5 * (vote_yescount/vote_needed), mySize.y);
2993 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_prog", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
2996 if(vote_nocount && vote_needed)
2998 drawsetcliparea(pos.x + mySize.x - mySize.x * 0.5 * (vote_nocount/vote_needed), pos.y, mySize.x * 0.5, mySize.y);
2999 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_prog", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
3002 drawresetcliparea();
3005 // Mod icons panel (#10)
3008 bool mod_active; // is there any active mod icon?
3010 void DrawCAItem(vector myPos, vector mySize, float aspect_ratio, int layout, int i)
3014 vector color = '0 0 0';
3018 stat = getstati(STAT_REDALIVE);
3019 pic = "player_red.tga";
3023 stat = getstati(STAT_BLUEALIVE);
3024 pic = "player_blue.tga";
3028 stat = getstati(STAT_YELLOWALIVE);
3029 pic = "player_yellow.tga";
3034 stat = getstati(STAT_PINKALIVE);
3035 pic = "player_pink.tga";
3040 if(mySize.x/mySize.y > aspect_ratio)
3042 i = aspect_ratio * mySize.y;
3043 myPos.x = myPos.x + (mySize.x - i) / 2;
3048 i = 1/aspect_ratio * mySize.x;
3049 myPos.y = myPos.y + (mySize.y - i) / 2;
3055 drawpic_aspect_skin(myPos, pic, eX * 0.7 * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3056 drawstring_aspect(myPos + eX * 0.7 * mySize.x, ftos(stat), eX * 0.3 * mySize.x + eY * mySize.y, color, panel_fg_alpha, DRAWFLAG_NORMAL);
3059 drawstring_aspect(myPos, ftos(stat), mySize, color, panel_fg_alpha, DRAWFLAG_NORMAL);
3062 // Clan Arena and Freeze Tag HUD modicons
3063 void HUD_Mod_CA(vector myPos, vector mySize)
3065 mod_active = 1; // required in each mod function that always shows something
3068 if(gametype == MAPINFO_TYPE_CA)
3069 layout = autocvar_hud_panel_modicons_ca_layout;
3070 else //if(gametype == MAPINFO_TYPE_FREEZETAG)
3071 layout = autocvar_hud_panel_modicons_freezetag_layout;
3074 aspect_ratio = (layout) ? 2 : 1;
3075 rows = HUD_GetRowCount(team_count, mySize, aspect_ratio);
3076 columns = ceil(team_count/rows);
3079 float row = 0, column = 0;
3080 vector pos, itemSize;
3081 itemSize = eX * mySize.x*(1/columns) + eY * mySize.y*(1/rows);
3082 for(i=0; i<team_count; ++i)
3084 pos = myPos + eX * column * itemSize.x + eY * row * itemSize.y;
3086 DrawCAItem(pos, itemSize, aspect_ratio, layout, i);
3097 // CTF HUD modicon section
3098 int redflag_prevframe, blueflag_prevframe, yellowflag_prevframe, pinkflag_prevframe, neutralflag_prevframe; // status during previous frame
3099 int redflag_prevstatus, blueflag_prevstatus, yellowflag_prevstatus, pinkflag_prevstatus, neutralflag_prevstatus; // last remembered status
3100 float redflag_statuschange_time, blueflag_statuschange_time, yellowflag_statuschange_time, pinkflag_statuschange_time, neutralflag_statuschange_time; // time when the status changed
3102 void HUD_Mod_CTF_Reset(void)
3104 redflag_prevstatus = blueflag_prevstatus = yellowflag_prevstatus = pinkflag_prevstatus = neutralflag_prevstatus = 0;
3105 redflag_prevframe = blueflag_prevframe = yellowflag_prevframe = pinkflag_prevframe = neutralflag_prevframe = 0;
3106 redflag_statuschange_time = blueflag_statuschange_time = yellowflag_statuschange_time = pinkflag_statuschange_time = neutralflag_statuschange_time = 0;
3109 void HUD_Mod_CTF(vector pos, vector mySize)
3111 vector redflag_pos, blueflag_pos, yellowflag_pos, pinkflag_pos, neutralflag_pos;
3113 float f; // every function should have that
3115 int redflag, blueflag, yellowflag, pinkflag, neutralflag; // current status
3116 float redflag_statuschange_elapsedtime, blueflag_statuschange_elapsedtime, yellowflag_statuschange_elapsedtime, pinkflag_statuschange_elapsedtime, neutralflag_statuschange_elapsedtime; // time since the status changed
3117 bool ctf_oneflag; // one-flag CTF mode enabled/disabled
3118 int stat_items = getstati(STAT_CTF_FLAGSTATUS, 0, 24);
3119 float fs, fs2, fs3, size1, size2;
3122 redflag = (stat_items/CTF_RED_FLAG_TAKEN) & 3;
3123 blueflag = (stat_items/CTF_BLUE_FLAG_TAKEN) & 3;
3124 yellowflag = (stat_items/CTF_YELLOW_FLAG_TAKEN) & 3;
3125 pinkflag = (stat_items/CTF_PINK_FLAG_TAKEN) & 3;
3126 neutralflag = (stat_items/CTF_NEUTRAL_FLAG_TAKEN) & 3;
3128 ctf_oneflag = (stat_items & CTF_FLAG_NEUTRAL);
3130 mod_active = (redflag || blueflag || yellowflag || pinkflag || neutralflag);
3132 if (autocvar__hud_configure) {
3135 if (team_count >= 3)
3137 if (team_count >= 4)
3139 ctf_oneflag = neutralflag = 0; // disable neutral flag in hud editor?
3142 // when status CHANGES, set old status into prevstatus and current status into status
3143 #define X(team) do { \
3144 if (team##flag != team##flag_prevframe) { \
3145 team##flag_statuschange_time = time; \
3146 team##flag_prevstatus = team##flag_prevframe; \
3147 team##flag_prevframe = team##flag; \
3149 team##flag_statuschange_elapsedtime = time - team##flag_statuschange_time; \
3158 const float BLINK_FACTOR = 0.15;
3159 const float BLINK_BASE = 0.85;
3161 // RMS = sqrt(BLINK_BASE^2 + 0.5 * BLINK_FACTOR^2)
3163 // BLINK_BASE = sqrt(RMS^2 - 0.5 * BLINK_FACTOR^2)
3165 const float BLINK_FREQ = 5; // circle frequency, = 2*pi*frequency in hertz
3167 #define X(team, cond) \
3168 string team##_icon, team##_icon_prevstatus; \
3169 int team##_alpha, team##_alpha_prevstatus; \
3170 team##_alpha = team##_alpha_prevstatus = 1; \
3172 switch (team##flag) { \
3173 case 1: team##_icon = "flag_" #team "_taken"; break; \
3174 case 2: team##_icon = "flag_" #team "_lost"; break; \
3175 case 3: team##_icon = "flag_" #team "_carrying"; team##_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break; \
3177 if ((stat_items & CTF_SHIELDED) && (cond)) { \
3178 team##_icon = "flag_" #team "_shielded"; \
3180 team##_icon = string_null; \
3184 switch (team##flag_prevstatus) { \
3185 case 1: team##_icon_prevstatus = "flag_" #team "_taken"; break; \
3186 case 2: team##_icon_prevstatus = "flag_" #team "_lost"; break; \
3187 case 3: team##_icon_prevstatus = "flag_" #team "_carrying"; team##_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break; \
3189 if (team##flag == 3) { \
3190 team##_icon_prevstatus = "flag_" #team "_carrying"; /* make it more visible */\
3191 } else if((stat_items & CTF_SHIELDED) && (cond)) { \
3192 team##_icon_prevstatus = "flag_" #team "_shielded"; \
3194 team##_icon_prevstatus = string_null; \
3199 X(red, myteam != NUM_TEAM_1);
3200 X(blue, myteam != NUM_TEAM_2);
3201 X(yellow, myteam != NUM_TEAM_3);
3202 X(pink, myteam != NUM_TEAM_4);
3207 // hacky, but these aren't needed
3208 red_icon = red_icon_prevstatus = blue_icon = blue_icon_prevstatus = yellow_icon = yellow_icon_prevstatus = pink_icon = pink_icon_prevstatus = string_null;
3210 } else switch (team_count) {
3212 case 2: fs = 0.5; fs2 = 0.5; fs3 = 0.5; break;
3213 case 3: fs = 1; fs2 = 0.35; fs3 = 0.35; break;
3214 case 4: fs = 0.75; fs2 = 0.25; fs3 = 0.5; break;
3217 if (mySize_x > mySize_y) {
3233 blueflag_pos = pos + eX * fs2 * size1;
3234 yellowflag_pos = pos - eX * fs2 * size1;
3235 pinkflag_pos = pos + eX * fs3 * size1;
3239 redflag_pos = pos + eX * fs2 * size1;
3241 yellowflag_pos = pos - eX * fs2 * size1;
3242 pinkflag_pos = pos + eX * fs3 * size1;
3246 redflag_pos = pos + eX * fs3 * size1;
3247 blueflag_pos = pos - eX * fs2 * size1;
3248 yellowflag_pos = pos;
3249 pinkflag_pos = pos + eX * fs2 * size1;
3253 redflag_pos = pos - eX * fs2 * size1;
3254 blueflag_pos = pos + eX * fs3 * size1;
3255 yellowflag_pos = pos + eX * fs2 * size1;
3260 neutralflag_pos = pos;
3261 flag_size = e1 * fs * size1 + e2 * size2;
3263 #define X(team) do { \
3264 f = bound(0, team##flag_statuschange_elapsedtime * 2, 1); \
3265 if (team##_icon_prevstatus && f < 1) \
3266 drawpic_aspect_skin_expanding(team##flag_pos, team##_icon_prevstatus, flag_size, '1 1 1', panel_fg_alpha * team##_alpha_prevstatus, DRAWFLAG_NORMAL, f); \
3268 drawpic_aspect_skin(team##flag_pos, team##_icon, flag_size, '1 1 1', panel_fg_alpha * team##_alpha * f, DRAWFLAG_NORMAL); \
3278 // Keyhunt HUD modicon section
3281 void HUD_Mod_KH(vector pos, vector mySize)
3283 mod_active = 1; // keyhunt should never hide the mod icons panel
3285 // Read current state
3287 int state = getstati(STAT_KH_KEYS);
3289 int all_keys, team1_keys, team2_keys, team3_keys, team4_keys, dropped_keys, carrying_keys;
3290 all_keys = team1_keys = team2_keys = team3_keys = team4_keys = dropped_keys = carrying_keys = 0;
3292 for(i = 0; i < 4; ++i)
3294 key_state = (bitshift(state, i * -5) & 31) - 1;
3307 case NUM_TEAM_1: ++team1_keys; break;
3308 case NUM_TEAM_2: ++team2_keys; break;
3309 case NUM_TEAM_3: ++team3_keys; break;
3310 case NUM_TEAM_4: ++team4_keys; break;
3311 case 29: ++dropped_keys; break;
3317 // Calculate slot measurements
3321 if(all_keys == 4 && mySize.x * 0.5 < mySize.y && mySize.y * 0.5 < mySize.x)
3323 // Quadratic arrangement
3324 slot_size = eX * mySize.x * 0.5 + eY * mySize.y * 0.5;
3326 KH_SLOTS[1] = pos + eX * slot_size.x;
3327 KH_SLOTS[2] = pos + eY * slot_size.y;
3328 KH_SLOTS[3] = pos + eX * slot_size.x + eY * slot_size.y;
3332 if(mySize.x > mySize.y)
3334 // Horizontal arrangement
3335 slot_size = eX * mySize.x / all_keys + eY * mySize.y;
3336 for(i = 0; i < all_keys; ++i)
3337 KH_SLOTS[i] = pos + eX * slot_size.x * i;
3341 // Vertical arrangement
3342 slot_size = eX * mySize.x + eY * mySize.y / all_keys;
3343 for(i = 0; i < all_keys; ++i)
3344 KH_SLOTS[i] = pos + eY * slot_size.y * i;
3348 // Make icons blink in case of RUN HERE
3350 float blink = 0.6 + sin(2*M_PI*time) / 2.5; // Oscillate between 0.2 and 1
3357 case NUM_TEAM_1: if(team1_keys == all_keys) alpha = blink; break;
3358 case NUM_TEAM_2: if(team2_keys == all_keys) alpha = blink; break;
3359 case NUM_TEAM_3: if(team3_keys == all_keys) alpha = blink; break;
3360 case NUM_TEAM_4: if(team4_keys == all_keys) alpha = blink; break;
3368 if(myteam == NUM_TEAM_1 && carrying_keys)
3370 drawpic_aspect_skin(KH_SLOTS[i++], "kh_red_carrying", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3374 drawpic_aspect_skin(KH_SLOTS[i++], "kh_red_taken", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3377 if(myteam == NUM_TEAM_2 && carrying_keys)
3379 drawpic_aspect_skin(KH_SLOTS[i++], "kh_blue_carrying", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3383 drawpic_aspect_skin(KH_SLOTS[i++], "kh_blue_taken", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3386 if(myteam == NUM_TEAM_3 && carrying_keys)
3388 drawpic_aspect_skin(KH_SLOTS[i++], "kh_yellow_carrying", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3392 drawpic_aspect_skin(KH_SLOTS[i++], "kh_yellow_taken", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3395 if(myteam == NUM_TEAM_4 && carrying_keys)
3397 drawpic_aspect_skin(KH_SLOTS[i++], "kh_pink_carrying", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3401 drawpic_aspect_skin(KH_SLOTS[i++], "kh_pink_taken", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3403 while(dropped_keys--)
3404 drawpic_aspect_skin(KH_SLOTS[i++], "kh_dropped", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3407 // Keepaway HUD mod icon
3408 int kaball_prevstatus; // last remembered status
3409 float kaball_statuschange_time; // time when the status changed
3411 // we don't need to reset for keepaway since it immediately
3412 // autocorrects prevstatus as to if the player has the ball or not
3414 void HUD_Mod_Keepaway(vector pos, vector mySize)
3416 mod_active = 1; // keepaway should always show the mod HUD
3418 float BLINK_FACTOR = 0.15;
3419 float BLINK_BASE = 0.85;
3420 float BLINK_FREQ = 5;
3421 float kaball_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ);
3423 int stat_items = getstati(STAT_ITEMS, 0, 24);
3424 int kaball = (stat_items/IT_KEY1) & 1;
3426 if(kaball != kaball_prevstatus)
3428 kaball_statuschange_time = time;
3429 kaball_prevstatus = kaball;
3432 vector kaball_pos, kaball_size;
3434 if(mySize.x > mySize.y) {
3435 kaball_pos = pos + eX * 0.25 * mySize.x;
3436 kaball_size = eX * 0.5 * mySize.x + eY * mySize.y;
3438 kaball_pos = pos + eY * 0.25 * mySize.y;
3439 kaball_size = eY * 0.5 * mySize.y + eX * mySize.x;
3442 float kaball_statuschange_elapsedtime = time - kaball_statuschange_time;
3443 float f = bound(0, kaball_statuschange_elapsedtime*2, 1);
3445 if(kaball_prevstatus && f < 1)
3446 drawpic_aspect_skin_expanding(kaball_pos, "keepawayball_carrying", kaball_size, '1 1 1', panel_fg_alpha * kaball_alpha, DRAWFLAG_NORMAL, f);
3449 drawpic_aspect_skin(pos, "keepawayball_carrying", eX * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha * kaball_alpha * f, DRAWFLAG_NORMAL);
3453 // Nexball HUD mod icon
3454 void HUD_Mod_NexBall(vector pos, vector mySize)
3456 float nb_pb_starttime, dt, p;
3459 stat_items = getstati(STAT_ITEMS, 0, 24);
3460 nb_pb_starttime = getstatf(STAT_NB_METERSTART);
3462 if (stat_items & IT_KEY1)
3467 //Manage the progress bar if any
3468 if (nb_pb_starttime > 0)
3470 dt = (time - nb_pb_starttime) % nb_pb_period;
3471 // one period of positive triangle
3472 p = 2 * dt / nb_pb_period;
3476 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);
3479 if (stat_items & IT_KEY1)
3480 drawpic_aspect_skin(pos, "nexball_carrying", eX * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3483 // Race/CTS HUD mod icons
3484 float crecordtime_prev; // last remembered crecordtime
3485 float crecordtime_change_time; // time when crecordtime last changed
3486 float srecordtime_prev; // last remembered srecordtime
3487 float srecordtime_change_time; // time when srecordtime last changed
3489 float race_status_time;
3490 int race_status_prev;
3491 string race_status_name_prev;
3492 void HUD_Mod_Race(vector pos, vector mySize)
3494 mod_active = 1; // race should never hide the mod icons panel
3496 me = playerslots[player_localnum];
3498 float f; // yet another function has this
3499 score = me.(scores[ps_primary]);
3501 if(!(scores_flags[ps_primary] & SFL_TIME) || teamplay) // race/cts record display on HUD
3502 return; // no records in the actual race
3504 // clientside personal record
3506 if(gametype == MAPINFO_TYPE_CTS)
3510 t = stof(db_get(ClientProgsDB, strcat(shortmapname, rr, "time")));
3512 if(score && (score < t || !t)) {
3513 db_put(ClientProgsDB, strcat(shortmapname, rr, "time"), ftos(score));
3514 if(autocvar_cl_autodemo_delete_keeprecords)
3516 f = autocvar_cl_autodemo_delete;
3518 cvar_set("cl_autodemo_delete", ftos(f)); // don't delete demo with new record!
3522 if(t != crecordtime_prev) {
3523 crecordtime_prev = t;
3524 crecordtime_change_time = time;
3527 vector textPos, medalPos;
3529 if(mySize.x > mySize.y) {
3530 // text on left side
3531 squareSize = min(mySize.y, mySize.x/2);
3532 textPos = pos + eX * 0.5 * max(0, mySize.x/2 - squareSize) + eY * 0.5 * (mySize.y - squareSize);
3533 medalPos = pos + eX * 0.5 * max(0, mySize.x/2 - squareSize) + eX * 0.5 * mySize.x + eY * 0.5 * (mySize.y - squareSize);
3536 squareSize = min(mySize.x, mySize.y/2);
3537 textPos = pos + eY * 0.5 * max(0, mySize.y/2 - squareSize) + eX * 0.5 * (mySize.x - squareSize);
3538 medalPos = pos + eY * 0.5 * max(0, mySize.y/2 - squareSize) + eY * 0.5 * mySize.y + eX * 0.5 * (mySize.x - squareSize);
3541 f = time - crecordtime_change_time;
3544 drawstring_aspect(textPos, _("Personal best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3545 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);
3547 drawstring_aspect(textPos, _("Personal best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3548 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);
3549 drawstring_aspect_expanding(pos, _("Personal best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
3550 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);
3554 t = race_server_record;
3555 if(t != srecordtime_prev) {
3556 srecordtime_prev = t;
3557 srecordtime_change_time = time;
3559 f = time - srecordtime_change_time;
3562 drawstring_aspect(textPos + eY * 0.5 * squareSize, _("Server best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3563 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);
3565 drawstring_aspect(textPos + eY * 0.5 * squareSize, _("Server best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3566 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);
3567 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);
3568 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);
3571 if (race_status != race_status_prev || race_status_name != race_status_name_prev) {
3572 race_status_time = time + 5;
3573 race_status_prev = race_status;
3574 if (race_status_name_prev)
3575 strunzone(race_status_name_prev);
3576 race_status_name_prev = strzone(race_status_name);
3581 a = bound(0, race_status_time - time, 1);
3584 s = textShortenToWidth(race_status_name, squareSize, '1 1 0' * 0.1 * squareSize, stringwidth_colors);
3588 rank = race_CheckName(race_status_name);
3592 rankname = count_ordinal(rank);
3595 namepos = medalPos + '0 0.8 0' * squareSize;
3597 rankpos = medalPos + '0 0.15 0' * squareSize;
3599 if(race_status == 0)
3600 drawpic_aspect_skin(medalPos, "race_newfail", '1 1 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3601 else if(race_status == 1) {
3602 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);
3603 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3604 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3605 } else if(race_status == 2) {
3606 if(race_status_name == GetPlayerName(player_localnum) || !race_myrank || race_myrank < rank)
3607 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);
3609 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);
3610 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3611 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3612 } else if(race_status == 3) {
3613 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);
3614 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3615 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3618 if (race_status_time - time <= 0) {
3619 race_status_prev = -1;
3621 if(race_status_name)
3622 strunzone(race_status_name);
3623 race_status_name = string_null;
3624 if(race_status_name_prev)
3625 strunzone(race_status_name_prev);
3626 race_status_name_prev = string_null;
3630 void DrawDomItem(vector myPos, vector mySize, float aspect_ratio, int layout, int i)
3634 vector color = '0 0 0';
3638 stat = getstatf(STAT_DOM_PPS_RED);
3639 pic = "dom_icon_red";
3643 stat = getstatf(STAT_DOM_PPS_BLUE);
3644 pic = "dom_icon_blue";
3648 stat = getstatf(STAT_DOM_PPS_YELLOW);
3649 pic = "dom_icon_yellow";
3654 stat = getstatf(STAT_DOM_PPS_PINK);
3655 pic = "dom_icon_pink";
3659 float pps_ratio = stat / getstatf(STAT_DOM_TOTAL_PPS);
3661 if(mySize.x/mySize.y > aspect_ratio)
3663 i = aspect_ratio * mySize.y;
3664 myPos.x = myPos.x + (mySize.x - i) / 2;
3669 i = 1/aspect_ratio * mySize.x;
3670 myPos.y = myPos.y + (mySize.y - i) / 2;
3674 if (layout) // show text too
3677 color *= 0.5 + pps_ratio * (1 - 0.5); // half saturated color at min, full saturated at max
3678 if (layout == 2) // average pps
3679 drawstring_aspect(myPos + eX * mySize.y, ftos_decimals(stat, 2), eX * (2/3) * mySize.x + eY * mySize.y, color, panel_fg_alpha, DRAWFLAG_NORMAL);
3680 else // percentage of average pps
3681 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);
3685 drawpic_aspect_skin(myPos, pic, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3688 drawsetcliparea(myPos.x, myPos.y + mySize.y * (1 - pps_ratio), mySize.y, mySize.y * pps_ratio);
3689 drawpic_aspect_skin(myPos, strcat(pic, "-highlighted"), '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3690 drawresetcliparea();
3694 void HUD_Mod_Dom(vector myPos, vector mySize)
3696 mod_active = 1; // required in each mod function that always shows something
3698 int layout = autocvar_hud_panel_modicons_dom_layout;
3701 aspect_ratio = (layout) ? 3 : 1;
3702 rows = HUD_GetRowCount(team_count, mySize, aspect_ratio);
3703 columns = ceil(team_count/rows);
3706 float row = 0, column = 0;
3707 vector pos, itemSize;
3708 itemSize = eX * mySize.x*(1/columns) + eY * mySize.y*(1/rows);
3709 for(i=0; i<team_count; ++i)
3711 pos = myPos + eX * column * itemSize.x + eY * row * itemSize.y;
3713 DrawDomItem(pos, itemSize, aspect_ratio, layout, i);
3724 void HUD_ModIcons_SetFunc()
3728 case MAPINFO_TYPE_KEYHUNT: HUD_ModIcons_GameType = HUD_Mod_KH; break;
3729 case MAPINFO_TYPE_CTF: HUD_ModIcons_GameType = HUD_Mod_CTF; break;
3730 case MAPINFO_TYPE_NEXBALL: HUD_ModIcons_GameType = HUD_Mod_NexBall; break;
3731 case MAPINFO_TYPE_CTS:
3732 case MAPINFO_TYPE_RACE: HUD_ModIcons_GameType = HUD_Mod_Race; break;
3733 case MAPINFO_TYPE_CA:
3734 case MAPINFO_TYPE_FREEZETAG: HUD_ModIcons_GameType = HUD_Mod_CA; break;
3735 case MAPINFO_TYPE_DOMINATION: HUD_ModIcons_GameType = HUD_Mod_Dom; break;
3736 case MAPINFO_TYPE_KEEPAWAY: HUD_ModIcons_GameType = HUD_Mod_Keepaway; break;
3740 int mod_prev; // previous state of mod_active to check for a change
3742 float mod_change; // "time" when mod_active changed
3744 void HUD_ModIcons(void)
3746 if(intermission == 2) return;
3747 if(!autocvar__hud_configure)
3749 if(!autocvar_hud_panel_modicons) return;
3750 if(!HUD_ModIcons_GameType) return;
3753 HUD_Panel_UpdateCvars();
3755 draw_beginBoldFont();
3757 if(mod_active != mod_prev) {
3759 mod_prev = mod_active;
3762 if(mod_active || autocvar__hud_configure)
3763 mod_alpha = bound(0, (time - mod_change) * 2, 1);
3765 mod_alpha = bound(0, 1 - (time - mod_change) * 2, 1);
3768 HUD_Panel_DrawBg(mod_alpha);
3770 if(panel_bg_padding)
3772 panel_pos += '1 1 0' * panel_bg_padding;
3773 panel_size -= '2 2 0' * panel_bg_padding;
3776 if(autocvar__hud_configure)
3777 HUD_Mod_CTF(panel_pos, panel_size);
3779 HUD_ModIcons_GameType(panel_pos, panel_size);
3784 // Draw pressed keys (#11)
3786 void HUD_PressedKeys(void)
3788 if(intermission == 2) return;
3789 if(!autocvar__hud_configure)
3791 if(!autocvar_hud_panel_pressedkeys) return;
3792 if(spectatee_status <= 0 && autocvar_hud_panel_pressedkeys < 2) return;
3795 HUD_Panel_UpdateCvars();
3798 mySize = panel_size;
3800 HUD_Panel_DrawBg(1);
3801 if(panel_bg_padding)
3803 pos += '1 1 0' * panel_bg_padding;
3804 mySize -= '2 2 0' * panel_bg_padding;
3807 // force custom aspect
3808 float aspect = autocvar_hud_panel_pressedkeys_aspect;
3811 vector newSize = '0 0 0';
3812 if(mySize.x/mySize.y > aspect)
3814 newSize.x = aspect * mySize.y;
3815 newSize.y = mySize.y;
3817 pos.x = pos.x + (mySize.x - newSize.x) / 2;
3821 newSize.y = 1/aspect * mySize.x;
3822 newSize.x = mySize.x;
3824 pos.y = pos.y + (mySize.y - newSize.y) / 2;
3830 keysize = eX * mySize.x * (1/3.0) + eY * mySize.y * (1/(3.0 - !autocvar_hud_panel_pressedkeys_attack));
3832 pressedkeys = getstatf(STAT_PRESSED_KEYS);
3834 if(autocvar_hud_panel_pressedkeys_attack)
3836 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);
3837 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);
3841 drawpic_aspect_skin(pos, ((pressedkeys & KEY_CROUCH) ? "key_crouch_inv.tga" : "key_crouch.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3842 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);
3843 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);
3845 drawpic_aspect_skin(pos, ((pressedkeys & KEY_LEFT) ? "key_left_inv.tga" : "key_left.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3846 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);
3847 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);
3850 // Handle chat as a panel (#12)
3854 if(!autocvar__hud_configure)
3856 if (!autocvar_hud_panel_chat)
3858 if (!autocvar_con_chatrect)
3859 cvar_set("con_chatrect", "0");
3862 if(autocvar__con_chat_maximized)
3864 if(!hud_draw_maximized) return;
3866 else if(chat_panel_modified)
3868 panel.update_time = time; // forces reload of panel attributes
3869 chat_panel_modified = false;
3873 HUD_Panel_UpdateCvars();
3875 if(intermission == 2)
3877 // reserve some more space to the mapvote panel
3878 // by resizing and moving chat panel to the bottom
3879 panel_size.y = min(panel_size.y, vid_conheight * 0.2);
3880 panel_pos.y = vid_conheight - panel_size.y - panel_bg_border * 2;
3881 chat_posy = panel_pos.y;
3882 chat_sizey = panel_size.y;
3884 if(autocvar__con_chat_maximized && !autocvar__hud_configure) // draw at full screen height if maximized
3886 panel_pos.y = panel_bg_border;
3887 panel_size.y = vid_conheight - panel_bg_border * 2;
3888 if(panel.current_panel_bg == "0") // force a border when maximized
3891 panel_bg = strcat(hud_skin_path, "/border_default");
3892 if(precache_pic(panel_bg) == "")
3893 panel_bg = "gfx/hud/default/border_default";
3894 if(panel.current_panel_bg)
3895 strunzone(panel.current_panel_bg);
3896 panel.current_panel_bg = strzone(panel_bg);
3897 chat_panel_modified = true;
3899 panel_bg_alpha = max(0.75, panel_bg_alpha); // force an theAlpha of at least 0.75
3904 mySize = panel_size;
3906 HUD_Panel_DrawBg(1);
3908 if(panel_bg_padding)
3910 pos += '1 1 0' * panel_bg_padding;
3911 mySize -= '2 2 0' * panel_bg_padding;
3914 if (!autocvar_con_chatrect)
3915 cvar_set("con_chatrect", "1");
3917 cvar_set("con_chatrect_x", ftos(pos.x/vid_conwidth));
3918 cvar_set("con_chatrect_y", ftos(pos.y/vid_conheight));
3920 cvar_set("con_chatwidth", ftos(mySize.x/vid_conwidth));
3921 cvar_set("con_chat", ftos(floor(mySize.y/autocvar_con_chatsize - 0.5)));
3923 if(autocvar__hud_configure)
3926 chatsize = '1 1 0' * autocvar_con_chatsize;
3927 cvar_set("con_chatrect_x", "9001"); // over 9000, we'll fake it instead for more control over theAlpha and such
3929 for(i = 0; i < autocvar_con_chat; ++i)
3931 if(i == autocvar_con_chat - 1)
3934 a = panel_fg_alpha * floor(((i + 1) * 7 + autocvar_con_chattime)/45);
3935 drawcolorcodedstring(pos, textShortenToWidth(_("^3Player^7: This is the chat area."), mySize.x, chatsize, stringwidth_colors), chatsize, a, DRAWFLAG_NORMAL);
3936 pos.y += chatsize.y;
3941 // Engine info panel (#13)
3948 float frametimeavg1; // 1 frame ago
3949 float frametimeavg2; // 2 frames ago
3950 void HUD_EngineInfo(void)
3952 //if(intermission == 2) return;
3953 if(!autocvar__hud_configure)
3955 if(!autocvar_hud_panel_engineinfo) return;
3958 HUD_Panel_UpdateCvars();
3961 mySize = panel_size;
3963 HUD_Panel_DrawBg(1);
3964 if(panel_bg_padding)
3966 pos += '1 1 0' * panel_bg_padding;
3967 mySize -= '2 2 0' * panel_bg_padding;
3970 float currentTime = gettime(GETTIME_REALTIME);
3971 if(cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage"))
3973 float currentframetime = currentTime - prevfps_time;
3974 frametimeavg = (frametimeavg + frametimeavg1 + frametimeavg2 + currentframetime)/4; // average three frametimes into framecounter for slightly more stable fps readings :P
3975 frametimeavg2 = frametimeavg1;
3976 frametimeavg1 = frametimeavg;
3979 weight = cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage_new_weight");
3980 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.
3982 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
3983 prevfps = (1/currentframetime);
3984 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"
3986 prevfps_time = currentTime;
3991 if(currentTime - prevfps_time > autocvar_hud_panel_engineinfo_framecounter_time)
3993 prevfps = framecounter/(currentTime - prevfps_time);
3995 prevfps_time = currentTime;
4000 color = HUD_Get_Num_Color (prevfps, 100);
4001 drawstring_aspect(pos, sprintf(_("FPS: %.*f"), autocvar_hud_panel_engineinfo_framecounter_decimals, prevfps), mySize, color, panel_fg_alpha, DRAWFLAG_NORMAL);
4004 // Info messages panel (#14)
4006 #define drawInfoMessage(s) do { \
4007 if(autocvar_hud_panel_infomessages_flip) \
4008 o.x = pos.x + mySize.x - stringwidth(s, true, fontsize); \
4009 drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL); \
4010 o.y += fontsize.y; \
4012 void HUD_InfoMessages(void)
4014 if(intermission == 2) return;
4015 if(!autocvar__hud_configure)
4017 if(!autocvar_hud_panel_infomessages) return;
4020 HUD_Panel_UpdateCvars();
4023 mySize = panel_size;
4025 HUD_Panel_DrawBg(1);
4026 if(panel_bg_padding)
4028 pos += '1 1 0' * panel_bg_padding;
4029 mySize -= '2 2 0' * panel_bg_padding;
4032 // always force 5:1 aspect
4033 vector newSize = '0 0 0';
4034 if(mySize.x/mySize.y > 5)
4036 newSize.x = 5 * mySize.y;
4037 newSize.y = mySize.y;
4039 pos.x = pos.x + (mySize.x - newSize.x) / 2;
4043 newSize.y = 1/5 * mySize.x;
4044 newSize.x = mySize.x;
4046 pos.y = pos.y + (mySize.y - newSize.y) / 2;
4055 fontsize = '0.20 0.20 0' * mySize.y;
4061 if(!autocvar__hud_configure)
4063 if(spectatee_status && !intermission)
4066 if(spectatee_status == -1)
4067 s = _("^1Observing");
4069 s = sprintf(_("^1Spectating: ^7%s"), GetPlayerName(current_player));
4072 if(spectatee_status == -1)
4073 s = sprintf(_("^1Press ^3%s^1 to spectate"), getcommandkey("primary fire", "+fire"));
4075 s = sprintf(_("^1Press ^3%s^1 or ^3%s^1 for next or previous player"), getcommandkey("next weapon", "weapnext"), getcommandkey("previous weapon", "weapprev"));
4078 if(spectatee_status == -1)
4079 s = sprintf(_("^1Use ^3%s^1 or ^3%s^1 to change the speed"), getcommandkey("next weapon", "weapnext"), getcommandkey("previous weapon", "weapprev"));
4081 s = sprintf(_("^1Press ^3%s^1 to observe"), getcommandkey("secondary fire", "+fire2"));
4084 s = sprintf(_("^1Press ^3%s^1 for gamemode info"), getcommandkey("server info", "+show_info"));
4087 if(gametype == MAPINFO_TYPE_LMS)
4090 sk = playerslots[player_localnum];
4091 if(sk.(scores[ps_primary]) >= 666)
4092 s = _("^1Match has already begun");
4093 else if(sk.(scores[ps_primary]) > 0)
4094 s = _("^1You have no more lives left");
4096 s = sprintf(_("^1Press ^3%s^1 to join"), getcommandkey("jump", "+jump"));
4099 s = sprintf(_("^1Press ^3%s^1 to join"), getcommandkey("jump", "+jump"));
4102 //show restart countdown:
4103 if (time < getstatf(STAT_GAMESTARTTIME)) {
4105 //we need to ceil, otherwise the countdown would be off by .5 when using round()
4106 countdown = ceil(getstatf(STAT_GAMESTARTTIME) - time);
4107 s = sprintf(_("^1Game starts in ^3%d^1 seconds"), countdown);
4108 drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
4112 if(warmup_stage && !intermission)
4114 s = _("^2Currently in ^1warmup^2 stage!");
4124 if(ready_waiting && !intermission && !spectatee_status)
4126 if(ready_waiting_for_me)
4129 s = sprintf(_("%sPress ^3%s%s to end warmup"), blinkcolor, getcommandkey("ready", "ready"), blinkcolor);
4131 s = sprintf(_("%sPress ^3%s%s once you are ready"), blinkcolor, getcommandkey("ready", "ready"), blinkcolor);
4136 s = _("^2Waiting for others to ready up to end warmup...");
4138 s = _("^2Waiting for others to ready up...");
4142 else if(warmup_stage && !intermission && !spectatee_status)
4144 s = sprintf(_("^2Press ^3%s^2 to end warmup"), getcommandkey("ready", "ready"));
4148 if(teamplay && !intermission && !spectatee_status && gametype != MAPINFO_TYPE_CA && teamnagger)
4150 float ts_min = 0, ts_max = 0;
4151 tm = teams.sort_next;
4154 for (; tm.sort_next; tm = tm.sort_next)
4156 if(!tm.team_size || tm.team == NUM_SPECTATOR)
4158 if(!ts_min) ts_min = tm.team_size;
4159 else ts_min = min(ts_min, tm.team_size);
4160 if(!ts_max) ts_max = tm.team_size;
4161 else ts_max = max(ts_max, tm.team_size);
4163 if ((ts_max - ts_min) > 1)
4165 s = strcat(blinkcolor, _("Teamnumbers are unbalanced!"));
4166 tm = GetTeam(myteam, false);
4168 if (tm.team != NUM_SPECTATOR)
4169 if (tm.team_size == ts_max)
4170 s = strcat(s, sprintf(_(" Press ^3%s%s to adjust"), getcommandkey("team menu", "menu_showteamselect"), blinkcolor));
4178 s = _("^7Press ^3ESC ^7to show HUD options.");
4180 s = _("^3Doubleclick ^7a panel for panel-specific options.");
4182 s = _("^3CTRL ^7to disable collision testing, ^3SHIFT ^7and");
4184 s = _("^3ALT ^7+ ^3ARROW KEYS ^7for fine adjustments.");
4189 // Physics panel (#15)
4191 vector acc_prevspeed;
4192 float acc_prevtime, acc_avg, top_speed, top_speed_time;
4193 float physics_update_time, discrete_speed, discrete_acceleration;
4194 void HUD_Physics(void)
4196 if(intermission == 2) return;
4197 if(!autocvar__hud_configure)
4199 if(!autocvar_hud_panel_physics) return;
4200 if(spectatee_status == -1 && (autocvar_hud_panel_physics == 1 || autocvar_hud_panel_physics == 3)) return;
4201 if(autocvar_hud_panel_physics == 3 && !(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return;
4204 HUD_Panel_UpdateCvars();
4206 draw_beginBoldFont();
4208 HUD_Panel_DrawBg(1);
4209 if(panel_bg_padding)
4211 panel_pos += '1 1 0' * panel_bg_padding;
4212 panel_size -= '2 2 0' * panel_bg_padding;
4215 float acceleration_progressbar_scale = 0;
4216 if(autocvar_hud_panel_physics_progressbar && autocvar_hud_panel_physics_acceleration_progressbar_scale > 1)
4217 acceleration_progressbar_scale = autocvar_hud_panel_physics_acceleration_progressbar_scale;
4220 if (autocvar_hud_panel_physics_text_scale <= 0)
4223 text_scale = min(autocvar_hud_panel_physics_text_scale, 1);
4226 float speed, conversion_factor;
4229 switch(autocvar_hud_panel_physics_speed_unit)
4234 conversion_factor = 1.0;
4238 conversion_factor = 0.0254;
4242 conversion_factor = 0.0254 * 3.6;
4246 conversion_factor = 0.0254 * 3.6 * 0.6213711922;
4250 conversion_factor = 0.0254 * 1.943844492; // 1 m/s = 1.943844492 knots, because 1 knot = 1.852 km/h
4254 vector vel = (csqcplayer ? csqcplayer.velocity : pmove_vel);
4256 float max_speed = floor( autocvar_hud_panel_physics_speed_max * conversion_factor + 0.5 );
4257 if (autocvar__hud_configure)
4258 speed = floor( max_speed * 0.65 + 0.5 );
4259 else if(autocvar_hud_panel_physics_speed_vertical)
4260 speed = floor( vlen(vel) * conversion_factor + 0.5 );
4262 speed = floor( vlen(vel - vel.z * '0 0 1') * conversion_factor + 0.5 );
4264 //compute acceleration
4265 float acceleration, f;
4266 if (autocvar__hud_configure)
4267 acceleration = autocvar_hud_panel_physics_acceleration_max * 0.3;
4270 // 1 m/s = 0.0254 qu/s; 1 g = 9.80665 m/s^2
4271 f = time - acc_prevtime;
4272 if(autocvar_hud_panel_physics_acceleration_vertical)
4273 acceleration = (vlen(vel) - vlen(acc_prevspeed));
4275 acceleration = (vlen(vel - '0 0 1' * vel.z) - vlen(acc_prevspeed - '0 0 1' * acc_prevspeed.z));
4277 acceleration = acceleration * (1 / max(0.0001, f)) * (0.0254 / 9.80665);
4279 acc_prevspeed = vel;
4280 acc_prevtime = time;
4282 if(autocvar_hud_panel_physics_acceleration_movingaverage)
4284 f = bound(0, f * 10, 1);
4285 acc_avg = acc_avg * (1 - f) + acceleration * f;
4286 acceleration = acc_avg;
4290 int acc_decimals = 2;
4291 if(time > physics_update_time)
4293 // workaround for ftos_decimals returning a negative 0
4294 if(discrete_acceleration > -1 / pow(10, acc_decimals) && discrete_acceleration < 0)
4295 discrete_acceleration = 0;
4296 discrete_acceleration = acceleration;
4297 discrete_speed = speed;
4298 physics_update_time += autocvar_hud_panel_physics_update_interval;
4302 float panel_ar = panel_size.x/panel_size.y;
4303 vector speed_offset = '0 0 0', acceleration_offset = '0 0 0';
4304 if (panel_ar >= 5 && !acceleration_progressbar_scale)
4306 panel_size.x *= 0.5;
4307 if (autocvar_hud_panel_physics_flip)
4308 speed_offset.x = panel_size.x;
4310 acceleration_offset.x = panel_size.x;
4314 panel_size.y *= 0.5;
4315 if (autocvar_hud_panel_physics_flip)
4316 speed_offset.y = panel_size.y;
4318 acceleration_offset.y = panel_size.y;
4320 int speed_baralign, acceleration_baralign;
4321 if (autocvar_hud_panel_physics_baralign == 1)
4322 acceleration_baralign = speed_baralign = 1;
4323 else if(autocvar_hud_panel_physics_baralign == 4)
4324 acceleration_baralign = speed_baralign = 2;
4325 else if (autocvar_hud_panel_physics_flip)
4327 acceleration_baralign = (autocvar_hud_panel_physics_baralign == 2);
4328 speed_baralign = (autocvar_hud_panel_physics_baralign == 3);
4332 speed_baralign = (autocvar_hud_panel_physics_baralign == 2);
4333 acceleration_baralign = (autocvar_hud_panel_physics_baralign == 3);
4335 if (autocvar_hud_panel_physics_acceleration_progressbar_mode == 0)
4336 acceleration_baralign = 3; //override hud_panel_physics_baralign value for acceleration
4340 if(autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 2)
4341 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);
4342 vector tmp_offset = '0 0 0', tmp_size = '0 0 0';
4343 if (autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 2)
4345 tmp_size.x = panel_size.x * 0.75;
4346 tmp_size.y = panel_size.y * text_scale;
4348 tmp_offset.x = panel_size.x - tmp_size.x;
4351 tmp_offset.y = (panel_size.y - tmp_size.y) / 2;
4352 drawstring_aspect(panel_pos + speed_offset + tmp_offset, ftos(discrete_speed), tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4358 tmp_offset.x = tmp_size.x;
4359 if (autocvar_hud_panel_physics_speed_unit_show)
4362 tmp_size.x = panel_size.x * (1 - 0.75);
4363 tmp_size.y = panel_size.y * 0.4 * text_scale;
4364 tmp_offset.y = (panel_size.y * 0.4 - tmp_size.y) / 2;
4365 drawstring_aspect(panel_pos + speed_offset + tmp_offset, unit, tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4369 //compute and draw top speed
4370 if (autocvar_hud_panel_physics_topspeed)
4371 if (autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 2)
4373 if (autocvar__hud_configure)
4375 top_speed = floor( max_speed * 0.75 + 0.5 );
4380 if (speed >= top_speed)
4383 top_speed_time = time;
4387 f = max(1, autocvar_hud_panel_physics_topspeed_time);
4388 // divide by f to make it start from 1
4389 f = cos( ((time - top_speed_time) / f) * PI/2 );
4391 else //hide top speed 0, it would be stupid
4396 //top speed progressbar peak
4397 if(speed < top_speed)
4398 if(autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 2)
4401 vector peak_size = '0 0 0';
4402 if (speed_baralign == 0)
4403 peak_offsetX = min(top_speed, max_speed)/max_speed * panel_size.x;
4404 else if (speed_baralign == 1)
4405 peak_offsetX = (1 - min(top_speed, max_speed)/max_speed) * panel_size.x;
4406 else // if (speed_baralign == 2)
4407 peak_offsetX = min(top_speed, max_speed)/max_speed * panel_size.x * 0.5;
4408 peak_size.x = floor(panel_size.x * 0.01 + 1.5);
4409 peak_size.y = panel_size.y;
4410 if (speed_baralign == 2) // draw two peaks, on both sides
4412 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);
4413 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);
4416 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);
4420 tmp_offset.y = panel_size.y * 0.4;
4421 tmp_size.x = panel_size.x * (1 - 0.75);
4422 tmp_size.y = (panel_size.y - tmp_offset.y) * text_scale;
4423 tmp_offset.y += (panel_size.y - tmp_offset.y - tmp_size.y) / 2;
4424 drawstring_aspect(panel_pos + speed_offset + tmp_offset, ftos(top_speed), tmp_size, '1 0 0', f * panel_fg_alpha, DRAWFLAG_NORMAL);
4432 if(autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 3)
4434 vector progressbar_color;
4435 if(acceleration < 0)
4436 progressbar_color = autocvar_hud_progressbar_acceleration_neg_color;
4438 progressbar_color = autocvar_hud_progressbar_acceleration_color;
4440 f = acceleration/autocvar_hud_panel_physics_acceleration_max;
4441 if (autocvar_hud_panel_physics_acceleration_progressbar_nonlinear)
4442 f = (f >= 0 ? sqrt(f) : -sqrt(-f));
4444 if (acceleration_progressbar_scale) // allow progressbar to go out of panel bounds
4446 tmp_size = acceleration_progressbar_scale * panel_size.x * eX + panel_size.y * eY;
4448 if (acceleration_baralign == 1)
4449 tmp_offset.x = panel_size.x - tmp_size.x;
4450 else if (acceleration_baralign == 2 || acceleration_baralign == 3)
4451 tmp_offset.x = (panel_size.x - tmp_size.x) / 2;
4458 tmp_size = panel_size;
4459 tmp_offset = '0 0 0';
4462 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);
4465 if(autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 3)
4467 tmp_size.x = panel_size.x;
4468 tmp_size.y = panel_size.y * text_scale;
4470 tmp_offset.y = (panel_size.y - tmp_size.y) / 2;
4472 drawstring_aspect(panel_pos + acceleration_offset + tmp_offset, strcat(ftos_decimals(discrete_acceleration, acc_decimals), "g"), tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4478 // CenterPrint (#16)
4480 const int CENTERPRINT_MAX_MSGS = 10;
4481 const int CENTERPRINT_MAX_ENTRIES = 50;
4482 const float CENTERPRINT_SPACING = 0.7;
4484 string centerprint_messages[CENTERPRINT_MAX_MSGS];
4485 int centerprint_msgID[CENTERPRINT_MAX_MSGS];
4486 float centerprint_time[CENTERPRINT_MAX_MSGS];
4487 float centerprint_expire_time[CENTERPRINT_MAX_MSGS];
4488 int centerprint_countdown_num[CENTERPRINT_MAX_MSGS];
4489 bool centerprint_showing;
4491 void centerprint_generic(int new_id, string strMessage, float duration, int countdown_num)
4493 //printf("centerprint_generic(%d, '%s^7', %d, %d);\n", new_id, strMessage, duration, countdown_num);
4496 if(strMessage == "" && new_id == 0)
4499 // strip trailing newlines
4500 j = strlen(strMessage) - 1;
4501 while(substring(strMessage, j, 1) == "\n" && j >= 0)
4503 if (j < strlen(strMessage) - 1)
4504 strMessage = substring(strMessage, 0, j + 1);
4506 if(strMessage == "" && new_id == 0)
4509 // strip leading newlines
4511 while(substring(strMessage, j, 1) == "\n" && j < strlen(strMessage))
4514 strMessage = substring(strMessage, j, strlen(strMessage) - j);
4516 if(strMessage == "" && new_id == 0)
4519 if (!centerprint_showing)
4520 centerprint_showing = true;
4522 for (i=0, j=cpm_index; i<CENTERPRINT_MAX_MSGS; ++i, ++j)
4524 if (j == CENTERPRINT_MAX_MSGS)
4526 if (new_id && new_id == centerprint_msgID[j])
4528 if (strMessage == "" && centerprint_messages[j] != "" && centerprint_countdown_num[j] == 0)
4530 // fade out the current msg (duration and countdown_num are ignored)
4531 centerprint_time[j] = min(5, autocvar_hud_panel_centerprint_fade_out);
4532 if (centerprint_expire_time[j] > time + min(5, autocvar_hud_panel_centerprint_fade_out) || centerprint_expire_time[j] < time)
4533 centerprint_expire_time[j] = time + min(5, autocvar_hud_panel_centerprint_fade_out);
4536 break; // found a msg with the same id, at position j
4540 if (i == CENTERPRINT_MAX_MSGS)
4542 // a msg with the same id was not found, add the msg at the next position
4544 if (cpm_index == -1)
4545 cpm_index = CENTERPRINT_MAX_MSGS - 1;
4548 if(centerprint_messages[j])
4549 strunzone(centerprint_messages[j]);
4550 centerprint_messages[j] = strzone(strMessage);
4551 centerprint_msgID[j] = new_id;
4554 centerprint_time[j] = -1;
4555 centerprint_expire_time[j] = time;
4560 duration = max(1, autocvar_hud_panel_centerprint_time);
4561 centerprint_time[j] = duration;
4562 centerprint_expire_time[j] = time + duration;
4564 centerprint_countdown_num[j] = countdown_num;
4567 void centerprint_hud(string strMessage)
4569 centerprint_generic(0, strMessage, autocvar_hud_panel_centerprint_time, 0);
4572 void reset_centerprint_messages(void)
4575 for (i=0; i<CENTERPRINT_MAX_MSGS; ++i)
4577 centerprint_expire_time[i] = 0;
4578 centerprint_time[i] = 1;
4579 centerprint_msgID[i] = 0;
4580 if(centerprint_messages[i])
4581 strunzone(centerprint_messages[i]);
4582 centerprint_messages[i] = string_null;
4585 float hud_configure_cp_generation_time;
4586 void HUD_CenterPrint (void)
4588 if(intermission == 2) return;
4589 if(!autocvar__hud_configure)
4591 if(!autocvar_hud_panel_centerprint) return;
4593 if(hud_configure_prev)
4594 reset_centerprint_messages();
4598 if(!hud_configure_prev)
4599 reset_centerprint_messages();
4600 if (time > hud_configure_cp_generation_time)
4602 if(HUD_PANEL(CENTERPRINT) == highlightedPanel)
4607 centerprint_generic(floor(r*1000), strcat(sprintf("^3Countdown message at time %s", seconds_tostring(time)), ", seconds left: ^COUNT"), 1, 10);
4609 centerprint_generic(0, sprintf("^1Multiline message at time %s that\n^1lasts longer than normal", seconds_tostring(time)), 20, 0);
4611 centerprint_hud(sprintf("Message at time %s", seconds_tostring(time)));
4612 hud_configure_cp_generation_time = time + 1 + random()*4;
4616 centerprint_generic(0, sprintf("Centerprint message", seconds_tostring(time)), 10, 0);
4617 hud_configure_cp_generation_time = time + 10 - random()*3;
4622 // this panel fades only when the menu does
4623 float hud_fade_alpha_save = 0;
4624 if(scoreboard_fade_alpha)
4626 hud_fade_alpha_save = hud_fade_alpha;
4627 hud_fade_alpha = 1 - autocvar__menu_alpha;
4629 HUD_Panel_UpdateCvars();
4631 if ( HUD_Radar_Clickable() )
4633 if (hud_panel_radar_bottom >= 0.96 * vid_conheight)
4636 panel_pos = eY * hud_panel_radar_bottom + eX * 0.5 * (vid_conwidth - panel_size_x);
4637 panel_size_y = min(panel_size_y, vid_conheight - hud_panel_radar_bottom);
4639 else if(scoreboard_fade_alpha)
4641 hud_fade_alpha = hud_fade_alpha_save;
4643 // move the panel below the scoreboard
4644 if (scoreboard_bottom >= 0.96 * vid_conheight)
4648 target_pos = eY * scoreboard_bottom + eX * 0.5 * (vid_conwidth - panel_size.x);
4650 if(target_pos.y > panel_pos.y)
4652 panel_pos = panel_pos + (target_pos - panel_pos) * sqrt(scoreboard_fade_alpha);
4653 panel_size.y = min(panel_size.y, vid_conheight - scoreboard_bottom);
4657 HUD_Panel_DrawBg(1);
4659 if (!centerprint_showing)
4662 if(panel_bg_padding)
4664 panel_pos += '1 1 0' * panel_bg_padding;
4665 panel_size -= '2 2 0' * panel_bg_padding;
4671 // entries = bound(1, floor(CENTERPRINT_MAX_ENTRIES * 4 * panel_size_y/panel_size_x), CENTERPRINT_MAX_ENTRIES);
4672 // height = panel_size_y/entries;
4673 // fontsize = '1 1 0' * height;
4674 height = vid_conheight/50 * autocvar_hud_panel_centerprint_fontscale;
4675 fontsize = '1 1 0' * height;
4676 entries = bound(1, floor(panel_size.y/height), CENTERPRINT_MAX_ENTRIES);
4679 float a, sz, align, current_msg_posY = 0, msg_size;
4682 bool all_messages_expired = true;
4685 if (autocvar_hud_panel_centerprint_flip)
4686 pos.y += panel_size.y;
4687 align = bound(0, autocvar_hud_panel_centerprint_align, 1);
4688 for (g=0, i=0, j=cpm_index; i<CENTERPRINT_MAX_MSGS; ++i, ++j)
4690 if (j == CENTERPRINT_MAX_MSGS)
4692 if (centerprint_expire_time[j] <= time)
4694 if (centerprint_countdown_num[j] && centerprint_time[j] > 0)
4696 centerprint_countdown_num[j] = centerprint_countdown_num[j] - 1;
4697 if (centerprint_countdown_num[j] == 0)
4699 centerprint_expire_time[j] = centerprint_expire_time[j] + centerprint_time[j];
4701 else if(centerprint_time[j] != -1)
4705 all_messages_expired = false;
4707 // fade the centerprint_hud in/out
4708 if(centerprint_time[j] < 0) // Expired but forced. Expire time is the fade-in time.
4709 a = (time - centerprint_expire_time[j]) / max(0.0001, autocvar_hud_panel_centerprint_fade_in);
4710 else if(centerprint_expire_time[j] - autocvar_hud_panel_centerprint_fade_out > time) // Regularily printed. Not fading out yet.
4711 a = (time - (centerprint_expire_time[j] - centerprint_time[j])) / max(0.0001, autocvar_hud_panel_centerprint_fade_in);
4712 else // Expiring soon, so fade it out.
4713 a = (centerprint_expire_time[j] - time) / max(0.0001, autocvar_hud_panel_centerprint_fade_out);
4715 // while counting down show it anyway in order to hold the current message position
4716 if (a <= 0.5/255.0 && centerprint_countdown_num[j] == 0) // Guaranteed invisible - don't show.
4721 // set the size from fading in/out before subsequent fading
4722 sz = autocvar_hud_panel_centerprint_fade_minfontsize + a * (1 - autocvar_hud_panel_centerprint_fade_minfontsize);
4724 // also fade it based on positioning
4725 if(autocvar_hud_panel_centerprint_fade_subsequent)
4727 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
4728 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
4730 a *= panel_fg_alpha;
4732 // finally set the size based on the new theAlpha from subsequent fading
4733 sz = sz * (autocvar_hud_panel_centerprint_fade_subsequent_minfontsize + a * (1 - autocvar_hud_panel_centerprint_fade_subsequent_minfontsize));
4734 drawfontscale = sz * '1 1 0';
4736 if (centerprint_countdown_num[j])
4737 n = tokenizebyseparator(strreplace("^COUNT", count_seconds(centerprint_countdown_num[j]), centerprint_messages[j]), "\n");
4739 n = tokenizebyseparator(centerprint_messages[j], "\n");
4741 if (autocvar_hud_panel_centerprint_flip)
4743 // check if the message can be entirely shown
4744 for(k = 0; k < n; ++k)
4746 getWrappedLine_remaining = argv(k);
4747 while(getWrappedLine_remaining)
4749 ts = getWrappedLine(panel_size.x * sz, fontsize, stringwidth_colors);
4751 pos.y -= fontsize.y;
4753 pos.y -= fontsize.y * CENTERPRINT_SPACING/2;
4756 current_msg_posY = pos.y; // save starting pos (first line) of the current message
4760 for(k = 0; k < n; ++k)
4762 getWrappedLine_remaining = argv(k);
4763 while(getWrappedLine_remaining)
4765 ts = getWrappedLine(panel_size.x * sz, fontsize, stringwidth_colors);
4769 pos.x = panel_pos.x + (panel_size.x - stringwidth(ts, true, fontsize)) * align;
4770 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.
4771 drawcolorcodedstring(pos + eY * 0.5 * (1 - sz) * fontsize.y, ts, fontsize, a, DRAWFLAG_NORMAL);
4772 pos.y += fontsize.y;
4775 pos.y += fontsize.y * CENTERPRINT_SPACING/2;
4779 ++g; // move next position number up
4781 msg_size = pos.y - msg_size;
4782 if (autocvar_hud_panel_centerprint_flip)
4784 pos.y = current_msg_posY - CENTERPRINT_SPACING * fontsize.y;
4785 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
4786 pos.y += (msg_size + CENTERPRINT_SPACING * fontsize.y) * (1 - sqrt(sz));
4788 if (pos.y < panel_pos.y) // check if the next message can be shown
4790 drawfontscale = '1 1 0';
4796 pos.y += CENTERPRINT_SPACING * fontsize.y;
4797 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
4798 pos.y -= (msg_size + CENTERPRINT_SPACING * fontsize.y) * (1 - sqrt(sz));
4800 if(pos.y > panel_pos.y + panel_size.y - fontsize.y) // check if the next message can be shown
4802 drawfontscale = '1 1 0';
4807 drawfontscale = '1 1 0';
4808 if (all_messages_expired)
4810 centerprint_showing = false;
4811 reset_centerprint_messages();
4817 const float ITEMSTIME_MAXITEMS = 10;
4818 float ItemsTime_time[ITEMSTIME_MAXITEMS];
4819 float ItemsTime_availableTime[ITEMSTIME_MAXITEMS];
4820 string GetItemsTimePicture(float i)
4824 case 0: return "item_large_armor";
4825 case 1: return "item_mega_health";
4826 case 2: return "strength";
4827 case 3: return "shield";
4828 case 4: return "item_mega_health";
4829 case 5: return "strength";
4830 case 6: return "shield";
4831 case 7: return "fuelregen";
4832 case 8: return "jetpack";
4833 case 9: return "superweapons";
4838 void DrawItemsTimeItem(vector myPos, vector mySize, float ar, float itemcode, float item_time, bool item_available, float item_availableTime)
4841 vector color = '0 0 0';
4844 if(autocvar_hud_panel_itemstime_hidespawned == 2)
4846 else if(item_available)
4848 float BLINK_FACTOR = 0.15;
4849 float BLINK_BASE = 0.85;
4850 float BLINK_FREQ = 5;
4851 picalpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ);
4855 t = floor(item_time - time + 0.999);
4859 color = '0.7 0.7 0';
4863 vector picpos, numpos;
4864 if(autocvar_hud_panel_itemstime_iconalign)
4867 picpos = myPos + eX * (ar - 1) * mySize_y;
4871 numpos = myPos + eX * mySize_y;
4875 if(t > 0 && autocvar_hud_panel_itemstime_progressbar)
4877 vector p_pos, p_size;
4878 if(autocvar_hud_panel_itemstime_progressbar_reduced)
4881 p_size = eX * ((ar - 1)/ar) * mySize_x + eY * mySize_y;
4888 HUD_Panel_DrawProgressBar(p_pos, p_size, autocvar_hud_panel_itemstime_progressbar_name, t/autocvar_hud_panel_itemstime_progressbar_maxtime, 0, autocvar_hud_panel_itemstime_iconalign, color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
4891 if(t > 0 && autocvar_hud_panel_itemstime_text)
4892 drawstring_aspect(numpos, ftos(t), eX * ((ar - 1)/ar) * mySize_x + eY * mySize_y, color, panel_fg_alpha, DRAWFLAG_NORMAL);
4894 picpos.x = myPos.x + mySize.x / 2 - mySize.y / 2;
4895 if(item_availableTime)
4896 drawpic_aspect_skin_expanding(picpos, GetItemsTimePicture(itemcode), '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha * picalpha, DRAWFLAG_NORMAL, item_availableTime);
4897 drawpic_aspect_skin(picpos, GetItemsTimePicture(itemcode), '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha * picalpha, DRAWFLAG_NORMAL);
4900 void HUD_ItemsTime(void)
4902 if(!autocvar__hud_configure)
4905 (autocvar_hud_panel_itemstime == 1 && spectatee_status != 0)
4906 || (autocvar_hud_panel_itemstime == 2 && (spectatee_status != 0 || warmup_stage))
4909 ItemsTime_time[0] = getstatf(STAT_ARMOR_LARGE_TIME);
4910 ItemsTime_time[1] = getstatf(STAT_HEALTH_MEGA_TIME);
4911 ItemsTime_time[2] = getstatf(STAT_INVISIBLE_TIME);
4912 ItemsTime_time[3] = getstatf(STAT_SPEED_TIME);
4913 ItemsTime_time[4] = getstatf(STAT_EXTRALIFE_TIME);
4914 ItemsTime_time[5] = getstatf(STAT_STRENGTH_TIME);
4915 ItemsTime_time[6] = getstatf(STAT_SHIELD_TIME);
4916 ItemsTime_time[7] = getstatf(STAT_FUELREGEN_TIME);
4917 ItemsTime_time[8] = getstatf(STAT_JETPACK_TIME);
4918 ItemsTime_time[9] = getstatf(STAT_SUPERWEAPONS_TIME);
4922 // do not show here mutator-dependent items
4923 ItemsTime_time[0] = time + 0;
4924 ItemsTime_time[1] = time + 8;
4925 ItemsTime_time[2] = -1; // mutator-dependent
4926 ItemsTime_time[3] = -1; // mutator-dependent
4927 ItemsTime_time[4] = -1; // mutator-dependent
4928 ItemsTime_time[5] = time + 0;
4929 ItemsTime_time[6] = time + 4;
4930 ItemsTime_time[7] = time + 49;
4931 ItemsTime_time[8] = -1;
4932 ItemsTime_time[9] = time + 28;
4937 if(autocvar_hud_panel_itemstime_hidespawned == 1)
4938 for (i = 0; i < ITEMSTIME_MAXITEMS; ++i)
4939 count += (ItemsTime_time[i] > time || -ItemsTime_time[i] > time);
4940 else if(autocvar_hud_panel_itemstime_hidespawned == 2)
4941 for (i = 0; i < ITEMSTIME_MAXITEMS; ++i)
4942 count += (ItemsTime_time[i] > time);
4944 for (i = 0; i < ITEMSTIME_MAXITEMS; ++i)
4945 count += (ItemsTime_time[i] != -1);
4949 HUD_Panel_UpdateCvars();
4953 mySize = panel_size;
4955 if(panel_bg_padding)
4957 pos += '1 1 0' * panel_bg_padding;
4958 mySize -= '2 2 0' * panel_bg_padding;
4961 float rows, columns;
4962 float ar = max(2, autocvar_hud_panel_itemstime_ratio) + 1;
4963 rows = HUD_GetRowCount(count, mySize, ar);
4964 columns = ceil(count/rows);
4966 vector itemstime_size = eX * mySize.x*(1/columns) + eY * mySize.y*(1/rows);
4968 vector offset = '0 0 0';
4970 if(autocvar_hud_panel_itemstime_dynamicsize)
4972 if(autocvar__hud_configure)
4973 if(menu_enabled != 2)
4974 HUD_Panel_DrawBg(1); // also draw the bg of the entire panel
4976 // reduce panel to avoid spacing items
4977 if(itemstime_size.x / itemstime_size.y < ar)
4979 newSize = rows * itemstime_size.x / ar;
4980 pos.y += (mySize.y - newSize) / 2;
4982 itemstime_size.y = mySize.y / rows;
4986 newSize = columns * itemstime_size.y * ar;
4987 pos.x += (mySize.x - newSize) / 2;
4989 itemstime_size.x = mySize.x / columns;
4991 panel_pos = pos - '1 1 0' * panel_bg_padding;
4992 panel_size = mySize + '2 2 0' * panel_bg_padding;
4996 if(itemstime_size.x/itemstime_size.y > ar)
4998 newSize = ar * itemstime_size.y;
4999 offset.x = itemstime_size.x - newSize;
5000 pos.x += offset.x/2;
5001 itemstime_size.x = newSize;
5005 newSize = 1/ar * itemstime_size.x;
5006 offset.y = itemstime_size.y - newSize;
5007 pos.y += offset.y/2;
5008 itemstime_size.y = newSize;
5012 HUD_Panel_DrawBg(1);
5014 float row = 0, column = 0;
5015 bool item_available;
5016 for (i = 0; i < ITEMSTIME_MAXITEMS; ++i) {
5017 if (ItemsTime_time[i] == -1)
5020 float item_time = ItemsTime_time[i];
5023 item_available = true;
5024 item_time = -item_time;
5027 item_available = (item_time <= time);
5029 if(ItemsTime_time[i] >= 0)
5031 if(time <= ItemsTime_time[i])
5032 ItemsTime_availableTime[i] = 0;
5033 else if(ItemsTime_availableTime[i] == 0)
5034 ItemsTime_availableTime[i] = time;
5036 else if(ItemsTime_availableTime[i] == 0)
5037 ItemsTime_availableTime[i] = time;
5039 float f = (time - ItemsTime_availableTime[i]) * 2;
5040 f = (f > 1) ? 0 : bound(0, f, 1);
5042 if(autocvar_hud_panel_itemstime_hidespawned == 1)
5043 if(!(ItemsTime_time[i] > time || -ItemsTime_time[i] > time))
5046 if(autocvar_hud_panel_itemstime_hidespawned == 2)
5047 if(!(ItemsTime_time[i] > time))
5050 DrawItemsTimeItem(pos + eX * column * (itemstime_size.x + offset.x) + eY * row * (itemstime_size.y + offset.y), itemstime_size, ar, i, item_time, item_available, f);
5055 column = column + 1;
5067 void HUD_Reset (void)
5069 // reset gametype specific icons
5070 if(gametype == MAPINFO_TYPE_CTF)
5071 HUD_Mod_CTF_Reset();
5074 void HUD_Main (void)
5077 // global hud theAlpha fade
5078 if(menu_enabled == 1)
5081 hud_fade_alpha = (1 - autocvar__menu_alpha);
5083 if(scoreboard_fade_alpha)
5084 hud_fade_alpha = (1 - scoreboard_fade_alpha);
5086 HUD_Configure_Frame();
5088 // panels that we want to be active together with the scoreboard
5089 // they must fade only when the menu does
5090 if(scoreboard_fade_alpha == 1)
5092 (panel = HUD_PANEL(CENTERPRINT)).panel_draw();
5096 if(!autocvar__hud_configure && !hud_fade_alpha)
5100 if (hud_skin_prev != autocvar_hud_skin)
5103 strunzone(hud_skin_path);
5104 hud_skin_path = strzone(strcat("gfx/hud/", autocvar_hud_skin));
5106 strunzone(hud_skin_prev);
5107 hud_skin_prev = strzone(autocvar_hud_skin);
5111 if(autocvar_hud_dock != "" && autocvar_hud_dock != "0")
5115 float hud_dock_color_team = autocvar_hud_dock_color_team;
5116 if((teamplay) && hud_dock_color_team) {
5117 if(autocvar__hud_configure && myteam == NUM_SPECTATOR)
5118 color = '1 0 0' * hud_dock_color_team;
5120 color = myteamcolors * hud_dock_color_team;
5122 else if(autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && hud_dock_color_team) {
5123 color = '1 0 0' * hud_dock_color_team;
5127 string hud_dock_color = autocvar_hud_dock_color;
5128 if(hud_dock_color == "shirt") {
5129 f = stof(getplayerkeyvalue(current_player, "colors"));
5130 color = colormapPaletteColor(floor(f / 16), 0);
5132 else if(hud_dock_color == "pants") {
5133 f = stof(getplayerkeyvalue(current_player, "colors"));
5134 color = colormapPaletteColor(f % 16, 1);
5137 color = stov(hud_dock_color);
5141 pic = strcat(hud_skin_path, "/", autocvar_hud_dock);
5142 if(precache_pic(pic) == "") {
5143 pic = strcat(hud_skin_path, "/dock_medium");
5144 if(precache_pic(pic) == "") {
5145 pic = "gfx/hud/default/dock_medium";
5148 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...
5151 // cache the panel order into the panel_order array
5152 if(autocvar__hud_panelorder != hud_panelorder_prev) {
5153 for(i = 0; i < HUD_PANEL_NUM; ++i)
5154 panel_order[i] = -1;
5157 bool warning = false;
5158 int argc = tokenize_console(autocvar__hud_panelorder);
5159 if (argc > HUD_PANEL_NUM)
5161 //first detect wrong/missing panel numbers
5162 for(i = 0; i < HUD_PANEL_NUM; ++i) {
5163 p_num = stoi(argv(i));
5164 if (p_num >= 0 && p_num < HUD_PANEL_NUM) { //correct panel number?
5165 if (panel_order[p_num] == -1) //found for the first time?
5166 s = strcat(s, ftos(p_num), " ");
5167 panel_order[p_num] = 1; //mark as found
5172 for(i = 0; i < HUD_PANEL_NUM; ++i) {
5173 if (panel_order[i] == -1) {
5175 s = strcat(s, ftos(i), " "); //add missing panel number
5179 dprint("Automatically fixed wrong/missing panel numbers in _hud_panelorder\n");
5181 cvar_set("_hud_panelorder", s);
5182 if(hud_panelorder_prev)
5183 strunzone(hud_panelorder_prev);
5184 hud_panelorder_prev = strzone(s);
5186 //now properly set panel_order
5187 tokenize_console(s);
5188 for(i = 0; i < HUD_PANEL_NUM; ++i) {
5189 panel_order[i] = stof(argv(i));
5193 hud_draw_maximized = 0;
5194 // draw panels in the order specified by panel_order array
5195 for(i = HUD_PANEL_NUM - 1; i >= 0; --i)
5196 (panel = hud_panel[panel_order[i]]).panel_draw();
5198 hud_draw_maximized = 1; // panels that may be maximized must check this var
5199 // draw maximized panels on top
5200 if(hud_panel_radar_maximized)
5201 (panel = HUD_PANEL(RADAR)).panel_draw();
5202 if(autocvar__con_chat_maximized)
5203 (panel = HUD_PANEL(CHAT)).panel_draw();
5205 HUD_Configure_PostDraw();
5207 hud_configure_prev = autocvar__hud_configure;