1 #include "scoreboard.qh"
2 #include "teamradar.qh"
3 #include "../common/buffs.qh"
4 #include "../common/counting.qh"
5 #include "../common/mapinfo.qh"
6 #include "../common/nades.qh"
7 #include "../server/t_items.qh"
8 #include "../server/mutators/gamemode_ctf.qh"
16 // a border picture is a texture containing nine parts:
17 // 1/4 width: left part
18 // 1/2 width: middle part (stretched)
19 // 1/4 width: right part
21 // 1/4 height: top part
22 // 1/2 height: middle part (stretched)
23 // 1/4 height: bottom part
24 void draw_BorderPicture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha, vector theBorderSize)
26 if (theBorderSize.x < 0 && theBorderSize.y < 0) // draw whole image as it is
28 drawpic(theOrigin, pic, theSize, theColor, theAlpha, 0);
31 if (theBorderSize.x == 0 && theBorderSize.y == 0) // no border
33 // draw only the central part
34 drawsubpic(theOrigin, theSize, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0);
41 //pic = draw_UseSkinFor(pic);
42 width = eX * theSize.x;
43 height = eY * theSize.y;
44 if(theSize.x <= theBorderSize.x * 2)
46 // not wide enough... draw just left and right then
47 bW = eX * (0.25 * theSize.x / (theBorderSize.x * 2));
48 if(theSize.y <= theBorderSize.y * 2)
50 // not high enough... draw just corners
51 bH = eY * (0.25 * theSize.y / (theBorderSize.y * 2));
52 drawsubpic(theOrigin, width * 0.5 + height * 0.5, pic, '0 0 0', bW + bH, theColor, theAlpha, 0);
53 drawsubpic(theOrigin + width * 0.5, width * 0.5 + height * 0.5, pic, eX - bW, bW + bH, theColor, theAlpha, 0);
54 drawsubpic(theOrigin + height * 0.5, width * 0.5 + height * 0.5, pic, eY - bH, bW + bH, theColor, theAlpha, 0);
55 drawsubpic(theOrigin + theSize * 0.5, width * 0.5 + height * 0.5, pic, eX + eY - bW - bH, bW + bH, theColor, theAlpha, 0);
59 dY = theBorderSize.x * eY;
60 drawsubpic(theOrigin, width * 0.5 + dY, pic, '0 0 0', '0 0.25 0' + bW, theColor, theAlpha, 0);
61 drawsubpic(theOrigin + width * 0.5, width * 0.5 + dY, pic, '0 0 0' + eX - bW, '0 0.25 0' + bW, theColor, theAlpha, 0);
62 drawsubpic(theOrigin + dY, width * 0.5 + height - 2 * dY, pic, '0 0.25 0', '0 0.5 0' + bW, theColor, theAlpha, 0);
63 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);
64 drawsubpic(theOrigin + height - dY, width * 0.5 + dY, pic, '0 0.75 0', '0 0.25 0' + bW, theColor, theAlpha, 0);
65 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);
70 if(theSize.y <= theBorderSize.y * 2)
72 // not high enough... draw just top and bottom then
73 bH = eY * (0.25 * theSize.y / (theBorderSize.y * 2));
74 dX = theBorderSize.x * eX;
75 drawsubpic(theOrigin, dX + height * 0.5, pic, '0 0 0', '0.25 0 0' + bH, theColor, theAlpha, 0);
76 drawsubpic(theOrigin + dX, width - 2 * dX + height * 0.5, pic, '0.25 0 0', '0.5 0 0' + bH, theColor, theAlpha, 0);
77 drawsubpic(theOrigin + width - dX, dX + height * 0.5, pic, '0.75 0 0', '0.25 0 0' + bH, theColor, theAlpha, 0);
78 drawsubpic(theOrigin + height * 0.5, dX + height * 0.5, pic, '0 0 0' + eY - bH, '0.25 0 0' + bH, theColor, theAlpha, 0);
79 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);
80 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);
84 dX = theBorderSize.x * eX;
85 dY = theBorderSize.x * eY;
86 drawsubpic(theOrigin, dX + dY, pic, '0 0 0', '0.25 0.25 0', theColor, theAlpha, 0);
87 drawsubpic(theOrigin + dX, width - 2 * dX + dY, pic, '0.25 0 0', '0.5 0.25 0', theColor, theAlpha, 0);
88 drawsubpic(theOrigin + width - dX, dX + dY, pic, '0.75 0 0', '0.25 0.25 0', theColor, theAlpha, 0);
89 drawsubpic(theOrigin + dY, dX + height - 2 * dY, pic, '0 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0);
90 drawsubpic(theOrigin + dY + dX, width - 2 * dX + height - 2 * dY, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0);
91 drawsubpic(theOrigin + dY + width - dX, dX + height - 2 * dY, pic, '0.75 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0);
92 drawsubpic(theOrigin + height - dY, dX + dY, pic, '0 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
93 drawsubpic(theOrigin + height - dY + dX, width - 2 * dX + dY, pic, '0.25 0.75 0', '0.5 0.25 0', theColor, theAlpha, 0);
94 drawsubpic(theOrigin + height - dY + width - dX, dX + dY, pic, '0.75 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
99 vector HUD_Get_Num_Color (float x, float maxvalue)
104 color.x = sin(2*M_PI*time);
106 color.z = sin(2*M_PI*time);
108 else if(x > maxvalue * 0.75) {
109 color.x = 0.4 - (x-150)*0.02 * 0.4; //red value between 0.4 -> 0
110 color.y = 0.9 + (x-150)*0.02 * 0.1; // green value between 0.9 -> 1
113 else if(x > maxvalue * 0.5) {
114 color.x = 1 - (x-100)*0.02 * 0.6; //red value between 1 -> 0.4
115 color.y = 1 - (x-100)*0.02 * 0.1; // green value between 1 -> 0.9
116 color.z = 1 - (x-100)*0.02; // blue value between 1 -> 0
118 else if(x > maxvalue * 0.25) {
121 color.z = 0.2 + (x-50)*0.02 * 0.8; // blue value between 0.2 -> 1
123 else if(x > maxvalue * 0.1) {
125 color.y = (x-20)*90/27/100; // green value between 0 -> 1
126 color.z = (x-20)*90/27/100 * 0.2; // blue value between 0 -> 0.2
134 blinkingamt = (1 - x/maxvalue/0.25);
137 color.x = color.x - color.x * blinkingamt * sin(2*M_PI*time);
138 color.y = color.y - color.y * blinkingamt * sin(2*M_PI*time);
139 color.z = color.z - color.z * blinkingamt * sin(2*M_PI*time);
144 float HUD_GetRowCount(int item_count, vector size, float item_aspect)
146 float aspect = size_y / size_x;
147 return bound(1, floor((sqrt(4 * item_aspect * aspect * item_count + aspect * aspect) + aspect + 0.5) / 2), item_count);
150 vector HUD_GetTableSize(int item_count, vector psize, float item_aspect)
153 float ratio, best_ratio = 0;
154 float best_columns = 1, best_rows = 1;
155 bool vertical = (psize.x / psize.y >= item_aspect);
158 psize = eX * psize.y + eY * psize.x;
159 item_aspect = 1 / item_aspect;
162 rows = ceil(sqrt(item_count));
163 columns = ceil(item_count/rows);
166 ratio = (psize.x/columns) / (psize.y/rows);
167 if(ratio > item_aspect)
168 ratio = item_aspect * item_aspect / ratio;
170 if(ratio <= best_ratio)
171 break; // ratio starts decreasing by now, skip next configurations
173 best_columns = columns;
181 rows = ceil(item_count/columns);
185 return eX * best_rows + eY * best_columns;
187 return eX * best_columns + eY * best_rows;
190 float stringwidth_colors(string s, vector theSize)
192 return stringwidth(s, true, theSize);
195 float stringwidth_nocolors(string s, vector theSize)
197 return stringwidth(s, false, theSize);
200 void drawstringright(vector position, string text, vector theScale, vector rgb, float theAlpha, int flag)
202 position.x -= 2 / 3 * strlen(text) * theScale.x;
203 drawstring(position, text, theScale, rgb, theAlpha, flag);
206 void drawstringcenter(vector position, string text, vector theScale, vector rgb, float theAlpha, int flag)
208 position.x = 0.5 * (vid_conwidth - 0.6025 * strlen(text) * theScale.x);
209 drawstring(position, text, theScale, rgb, theAlpha, flag);
212 // return the string of the onscreen race timer
213 string MakeRaceString(int cp, float mytime, float theirtime, float lapdelta, string theirname)
221 if(theirtime == 0) // goal hit
225 timestr = strcat("+", ftos_decimals(+mytime, TIME_DECIMALS));
235 timestr = strcat("-", ftos_decimals(-mytime, TIME_DECIMALS));
241 lapstr = sprintf(_(" (-%dL)"), lapdelta);
244 else if(lapdelta < 0)
246 lapstr = sprintf(_(" (+%dL)"), -lapdelta);
250 else if(theirtime > 0) // anticipation
252 if(mytime >= theirtime)
253 timestr = strcat("+", ftos_decimals(mytime - theirtime, TIME_DECIMALS));
255 timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(theirtime));
265 cpname = _("Start line");
267 cpname = _("Finish line");
269 cpname = sprintf(_("Intermediate %d"), cp);
271 cpname = _("Finish line");
274 return strcat(col, cpname);
275 else if(theirname == "")
276 return strcat(col, sprintf("%s (%s)", cpname, timestr));
278 return strcat(col, sprintf("%s (%s %s)", cpname, timestr, strcat(theirname, col, lapstr)));
281 // Check if the given name already exist in race rankings? In that case, where? (otherwise return 0)
282 int race_CheckName(string net_name)
285 for (i=RANKINGS_CNT-1;i>=0;--i)
286 if(grecordholder[i] == net_name)
291 int GetPlayerColorForce(int i)
296 return stof(getplayerkeyvalue(i, "colors")) & 15;
299 int GetPlayerColor(int i)
301 if(!playerslots[i].gotscores) // unconnected
302 return NUM_SPECTATOR;
303 else if(stof(getplayerkeyvalue(i, "frags")) == FRAGS_SPECTATOR)
304 return NUM_SPECTATOR;
306 return GetPlayerColorForce(i);
309 string GetPlayerName(int i)
311 return ColorTranslateRGB(getplayerkeyvalue(i, "name"));
321 // draw the background/borders
322 #define HUD_Panel_DrawBg(theAlpha) do { \
323 if(panel.current_panel_bg != "0" && panel.current_panel_bg != "") \
324 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));\
327 //basically the same code of draw_ButtonPicture and draw_VertButtonPicture for the menu
328 void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, float length_ratio, bool vertical, float baralign, vector theColor, float theAlpha, int drawflag)
330 if(!length_ratio || !theAlpha)
336 if(length_ratio < -1)
339 else if(length_ratio < 0)
343 vector width, height;
345 pic = strcat(hud_skin_path, "/", pic, "_vertical");
346 if(precache_pic(pic) == "") {
347 pic = "gfx/hud/default/progressbar_vertical";
350 if (baralign == 1) // bottom align
351 theOrigin.y += (1 - length_ratio) * theSize.y;
352 else if (baralign == 2) // center align
353 theOrigin.y += 0.5 * (1 - length_ratio) * theSize.y;
354 else if (baralign == 3) // center align, positive values down, negative up
357 if (length_ratio > 0)
358 theOrigin.y += theSize.y;
361 theOrigin.y += (1 + length_ratio) * theSize.y;
362 length_ratio = -length_ratio;
365 theSize.y *= length_ratio;
368 width = eX * theSize.x;
369 height = eY * theSize.y;
370 if(theSize.y <= theSize.x * 2)
372 // button not high enough
373 // draw just upper and lower part then
374 square = eY * theSize.y * 0.5;
375 bH = eY * (0.25 * theSize.y / (theSize.x * 2));
376 drawsubpic(theOrigin, square + width, pic, '0 0 0', eX + bH, theColor, theAlpha, drawflag);
377 drawsubpic(theOrigin + square, square + width, pic, eY - bH, eX + bH, theColor, theAlpha, drawflag);
381 square = eY * theSize.x;
382 drawsubpic(theOrigin, width + square, pic, '0 0 0', '1 0.25 0', theColor, theAlpha, drawflag);
383 drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0 0.25 0', '1 0.5 0', theColor, theAlpha, drawflag);
384 drawsubpic(theOrigin + height - square, width + square, pic, '0 0.75 0', '1 0.25 0', theColor, theAlpha, drawflag);
387 pic = strcat(hud_skin_path, "/", pic);
388 if(precache_pic(pic) == "") {
389 pic = "gfx/hud/default/progressbar";
392 if (baralign == 1) // right align
393 theOrigin.x += (1 - length_ratio) * theSize.x;
394 else if (baralign == 2) // center align
395 theOrigin.x += 0.5 * (1 - length_ratio) * theSize.x;
396 else if (baralign == 3) // center align, positive values on the right, negative on the left
399 if (length_ratio > 0)
400 theOrigin.x += theSize.x;
403 theOrigin.x += (1 + length_ratio) * theSize.x;
404 length_ratio = -length_ratio;
407 theSize.x *= length_ratio;
410 width = eX * theSize.x;
411 height = eY * theSize.y;
412 if(theSize.x <= theSize.y * 2)
414 // button not wide enough
415 // draw just left and right part then
416 square = eX * theSize.x * 0.5;
417 bW = eX * (0.25 * theSize.x / (theSize.y * 2));
418 drawsubpic(theOrigin, square + height, pic, '0 0 0', eY + bW, theColor, theAlpha, drawflag);
419 drawsubpic(theOrigin + square, square + height, pic, eX - bW, eY + bW, theColor, theAlpha, drawflag);
423 square = eX * theSize.y;
424 drawsubpic(theOrigin, height + square, pic, '0 0 0', '0.25 1 0', theColor, theAlpha, drawflag);
425 drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0.25 0 0', '0.5 1 0', theColor, theAlpha, drawflag);
426 drawsubpic(theOrigin + width - square, height + square, pic, '0.75 0 0', '0.25 1 0', theColor, theAlpha, drawflag);
431 void HUD_Panel_DrawHighlight(vector pos, vector mySize, vector color, float theAlpha, int drawflag)
437 pic = strcat(hud_skin_path, "/num_leading");
438 if(precache_pic(pic) == "") {
439 pic = "gfx/hud/default/num_leading";
442 drawsubpic(pos, eX * min(mySize.x * 0.5, mySize.y) + eY * mySize.y, pic, '0 0 0', '0.25 1 0', color, theAlpha, drawflag);
443 if(mySize.x/mySize.y > 2)
444 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);
445 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);
450 entity weaponorder[WEP_MAXCOUNT];
451 void weaponorder_swap(int i, int j, entity pass)
453 entity h = weaponorder[i];
454 weaponorder[i] = weaponorder[j];
458 string weaponorder_cmp_str;
459 int weaponorder_cmp(int i, int j, entity pass)
462 ai = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[i].weapon), 0);
463 aj = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[j].weapon), 0);
464 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)
467 void HUD_Weapons(void)
470 WepSet weapons_stat = WepSet_GetFromStat();
474 vector center = '0 0 0';
475 int weapon_count, weapon_id;
476 int row, column, rows = 0, columns = 0;
477 bool vertical_order = true;
478 float aspect = autocvar_hud_panel_weapons_aspect;
480 float timeout = autocvar_hud_panel_weapons_timeout;
481 float timein_effect_length = autocvar_hud_panel_weapons_timeout_speed_in; //? 0.375 : 0);
482 float timeout_effect_length = autocvar_hud_panel_weapons_timeout_speed_out; //? 0.75 : 0);
484 vector barsize = '0 0 0', baroffset = '0 0 0';
485 vector ammo_color = '1 0 1';
486 float ammo_alpha = 1;
488 float when = max(1, autocvar_hud_panel_weapons_complainbubble_time);
489 float fadetime = max(0, autocvar_hud_panel_weapons_complainbubble_fadetime);
491 vector weapon_pos, weapon_size = '0 0 0';
494 // check to see if we want to continue
495 if(hud != HUD_NORMAL) { return; }
497 if(!autocvar__hud_configure)
499 if((!autocvar_hud_panel_weapons) || (spectatee_status == -1))
501 if(timeout && time >= weapontime + timeout + timeout_effect_length)
502 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)))
504 weaponprevtime = time;
509 // update generic hud functions
510 HUD_Panel_UpdateCvars();
512 draw_beginBoldFont();
514 // figure out weapon order (how the weapons are sorted) // TODO make this configurable
515 if(weaponorder_bypriority != autocvar_cl_weaponpriority || !weaponorder[0])
518 if(weaponorder_bypriority)
519 strunzone(weaponorder_bypriority);
520 if(weaponorder_byimpulse)
521 strunzone(weaponorder_byimpulse);
523 weaponorder_bypriority = strzone(autocvar_cl_weaponpriority);
524 weaponorder_byimpulse = strzone(W_FixWeaponOrder_BuildImpulseList(W_FixWeaponOrder_ForceComplete(W_NumberWeaponOrder(weaponorder_bypriority))));
525 weaponorder_cmp_str = strcat(" ", weaponorder_byimpulse, " ");
528 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
530 self = get_weaponinfo(i);
531 if(self.impulse >= 0)
533 weaponorder[weapon_cnt] = self;
537 for(i = weapon_cnt; i < WEP_MAXCOUNT; ++i)
538 weaponorder[i] = world;
539 heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, world);
541 weaponorder_cmp_str = string_null;
544 if(!autocvar_hud_panel_weapons_complainbubble || autocvar__hud_configure || time - complain_weapon_time >= when + fadetime)
547 if(autocvar__hud_configure)
550 for(i = WEP_FIRST; i <= WEP_LAST; i += floor((WEP_LAST-WEP_FIRST)/5))
551 weapons_stat |= WepSet_FromWeapon(i);
557 weapons_stat = '0 0 0';
558 float countw = 1 + floor((floor(time * cvar("wep_add"))) % WEP_COUNT);
559 for(i = WEP_FIRST; i <= countw; ++i)
560 weapons_stat |= WepSet_FromWeapon(i);
565 // determine which weapons are going to be shown
566 if (autocvar_hud_panel_weapons_onlyowned)
568 if(autocvar__hud_configure)
570 if(menu_enabled != 2)
571 HUD_Panel_DrawBg(1); // also draw the bg of the entire panel
574 // do we own this weapon?
576 for(i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
577 if((weapons_stat & WepSet_FromWeapon(weaponorder[i].weapon)) || (weaponorder[i].weapon == complain_weapon))
581 // might as well commit suicide now, no reason to live ;)
582 if (weapon_count == 0)
588 vector old_panel_size = panel_size;
589 vector padded_panel_size = panel_size - '2 2 0' * panel_bg_padding;
591 // get the all-weapons layout
592 vector table_size = HUD_GetTableSize(WEP_COUNT, padded_panel_size, aspect);
593 columns = table_size.x;
595 weapon_size.x = padded_panel_size.x / columns;
596 weapon_size.y = padded_panel_size.y / rows;
598 // NOTE: although weapons should aways look the same even if onlyowned is enabled,
599 // we enlarge them a bit when possible to better match the desired aspect ratio
600 if(padded_panel_size.x / padded_panel_size.y < aspect)
602 // maximum number of rows that allows to display items with the desired aspect ratio
603 int max_rows = floor(padded_panel_size.y / (weapon_size.x / aspect));
604 columns = min(columns, ceil(weapon_count / max_rows));
605 rows = ceil(weapon_count / columns);
606 weapon_size.y = min(padded_panel_size.y / rows, weapon_size.x / aspect);
607 weapon_size.x = min(padded_panel_size.x / columns, aspect * weapon_size.y);
608 vertical_order = false;
612 int max_columns = floor(padded_panel_size.x / (weapon_size.y * aspect));
613 rows = min(rows, ceil(weapon_count / max_columns));
614 columns = ceil(weapon_count / rows);
615 weapon_size.x = min(padded_panel_size.x / columns, aspect * weapon_size.y);
616 weapon_size.y = min(padded_panel_size.y / rows, weapon_size.x / aspect);
617 vertical_order = true;
620 // reduce size of the panel
621 panel_size.x = columns * weapon_size.x;
622 panel_size.y = rows * weapon_size.y;
623 panel_size += '2 2 0' * panel_bg_padding;
625 // center the resized panel, or snap it to the screen edge when close enough
626 if(panel_pos.x > vid_conwidth * 0.001)
628 if(panel_pos.x + old_panel_size.x > vid_conwidth * 0.999)
629 panel_pos.x += old_panel_size.x - panel_size.x;
631 panel_pos.x += (old_panel_size.x - panel_size.x) / 2;
633 else if(old_panel_size.x > vid_conwidth * 0.999)
634 panel_pos.x += (old_panel_size.x - panel_size.x) / 2;
636 if(panel_pos.y > vid_conheight * 0.001)
638 if(panel_pos.y + old_panel_size.y > vid_conheight * 0.999)
639 panel_pos.y += old_panel_size.y - panel_size.y;
641 panel_pos.y += (old_panel_size.y - panel_size.y) / 2;
643 else if(old_panel_size.y > vid_conheight * 0.999)
644 panel_pos.y += (old_panel_size.y - panel_size.y) / 2;
647 weapon_count = WEP_COUNT;
649 // animation for fading in/out the panel respectively when not in use
650 if(!autocvar__hud_configure)
652 if (timeout && time >= weapontime + timeout) // apply timeout effect if needed
654 f = bound(0, (time - (weapontime + timeout)) / timeout_effect_length, 1);
656 // fade the panel alpha
657 if(autocvar_hud_panel_weapons_timeout_effect == 1)
659 panel_bg_alpha *= (autocvar_hud_panel_weapons_timeout_fadebgmin * f + (1 - f));
660 panel_fg_alpha *= (autocvar_hud_panel_weapons_timeout_fadefgmin * f + (1 - f));
662 else if(autocvar_hud_panel_weapons_timeout_effect == 3)
664 panel_bg_alpha *= (1 - f);
665 panel_fg_alpha *= (1 - f);
668 // move the panel off the screen
669 if (autocvar_hud_panel_weapons_timeout_effect == 2 || autocvar_hud_panel_weapons_timeout_effect == 3)
671 f *= f; // for a cooler movement
672 center.x = panel_pos.x + panel_size.x/2;
673 center.y = panel_pos.y + panel_size.y/2;
674 screen_ar = vid_conwidth/vid_conheight;
675 if (center.x/center.y < screen_ar) //bottom left
677 if ((vid_conwidth - center.x)/center.y < screen_ar) //bottom
678 panel_pos.y += f * (vid_conheight - panel_pos.y);
680 panel_pos.x -= f * (panel_pos.x + panel_size.x);
684 if ((vid_conwidth - center.x)/center.y < screen_ar) //right
685 panel_pos.x += f * (vid_conwidth - panel_pos.x);
687 panel_pos.y -= f * (panel_pos.y + panel_size.y);
690 center.x = -1; // mark the panel as off screen
692 weaponprevtime = time - (1 - f) * timein_effect_length;
694 else if (timeout && time < weaponprevtime + timein_effect_length) // apply timein effect if needed
696 f = bound(0, (time - weaponprevtime) / timein_effect_length, 1);
698 // fade the panel alpha
699 if(autocvar_hud_panel_weapons_timeout_effect == 1)
701 panel_bg_alpha *= (autocvar_hud_panel_weapons_timeout_fadebgmin * (1 - f) + f);
702 panel_fg_alpha *= (autocvar_hud_panel_weapons_timeout_fadefgmin * (1 - f) + f);
704 else if(autocvar_hud_panel_weapons_timeout_effect == 3)
706 panel_bg_alpha *= (f);
707 panel_fg_alpha *= (f);
710 // move the panel back on screen
711 if (autocvar_hud_panel_weapons_timeout_effect == 2 || autocvar_hud_panel_weapons_timeout_effect == 3)
713 f *= f; // for a cooler movement
715 center.x = panel_pos.x + panel_size.x/2;
716 center.y = panel_pos.y + panel_size.y/2;
717 screen_ar = vid_conwidth/vid_conheight;
718 if (center.x/center.y < screen_ar) //bottom left
720 if ((vid_conwidth - center.x)/center.y < screen_ar) //bottom
721 panel_pos.y += f * (vid_conheight - panel_pos.y);
723 panel_pos.x -= f * (panel_pos.x + panel_size.x);
727 if ((vid_conwidth - center.x)/center.y < screen_ar) //right
728 panel_pos.x += f * (vid_conwidth - panel_pos.x);
730 panel_pos.y -= f * (panel_pos.y + panel_size.y);
736 // draw the background, then change the virtual size of it to better fit other items inside
747 panel_pos += '1 1 0' * panel_bg_padding;
748 panel_size -= '2 2 0' * panel_bg_padding;
751 // after the sizing and animations are done, update the other values
753 if(!rows) // if rows is > 0 onlyowned code has already updated these vars
755 vector table_size = HUD_GetTableSize(WEP_COUNT, panel_size, aspect);
756 columns = table_size.x;
758 weapon_size.x = panel_size.x / columns;
759 weapon_size.y = panel_size.y / rows;
760 vertical_order = (panel_size.x / panel_size.y >= aspect);
763 // calculate position/size for visual bar displaying ammount of ammo status
764 if (autocvar_hud_panel_weapons_ammo)
766 ammo_color = stov(autocvar_hud_panel_weapons_ammo_color);
767 ammo_alpha = panel_fg_alpha * autocvar_hud_panel_weapons_ammo_alpha;
769 if(weapon_size.x/weapon_size.y > aspect)
771 barsize.x = aspect * weapon_size.y;
772 barsize.y = weapon_size.y;
773 baroffset.x = (weapon_size.x - barsize.x) / 2;
777 barsize.y = 1/aspect * weapon_size.x;
778 barsize.x = weapon_size.x;
779 baroffset.y = (weapon_size.y - barsize.y) / 2;
782 if(autocvar_hud_panel_weapons_accuracy)
783 Accuracy_LoadColors();
787 vector label_size = '1 1 0' * min(weapon_size.x, weapon_size.y) * bound(0, autocvar_hud_panel_weapons_label_scale, 1);
788 for(i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
790 // retrieve information about the current weapon to be drawn
791 self = weaponorder[i];
792 weapon_id = self.impulse;
794 // skip if this weapon doesn't exist
795 if(!self || weapon_id < 0) { continue; }
797 // skip this weapon if we don't own it (and onlyowned is enabled)-- or if weapons_complainbubble is showing for this weapon
798 if(autocvar_hud_panel_weapons_onlyowned)
799 if (!((weapons_stat & WepSet_FromWeapon(self.weapon)) || (self.weapon == complain_weapon)))
802 // figure out the drawing position of weapon
803 weapon_pos = (panel_pos
804 + eX * column * weapon_size.x
805 + eY * row * weapon_size.y);
807 // draw background behind currently selected weapon
808 if(self.weapon == switchweapon)
809 drawpic_aspect_skin(weapon_pos, "weapon_current_bg", weapon_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
811 // draw the weapon accuracy
812 if(autocvar_hud_panel_weapons_accuracy)
814 float panel_weapon_accuracy = weapon_accuracy[self.weapon-WEP_FIRST];
815 if(panel_weapon_accuracy >= 0)
817 color = Accuracy_GetColor(panel_weapon_accuracy);
818 drawpic_aspect_skin(weapon_pos, "weapon_accuracy", weapon_size, color, panel_fg_alpha, DRAWFLAG_NORMAL);
822 // drawing all the weapon items
823 if(weapons_stat & WepSet_FromWeapon(self.weapon))
825 // draw the weapon image
826 drawpic_aspect_skin(weapon_pos, self.model2, weapon_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
828 // draw weapon label string
829 switch(autocvar_hud_panel_weapons_label)
831 case 1: // weapon number
832 drawstring(weapon_pos, ftos(weapon_id), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
836 drawstring(weapon_pos, getcommandkey(ftos(weapon_id), strcat("weapon_group_", ftos(weapon_id))), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
839 case 3: // weapon name
840 drawstring(weapon_pos, strtolower(self.message), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
847 // draw ammo status bar
848 if(autocvar_hud_panel_weapons_ammo && (self.ammo_field != ammo_none))
851 a = getstati(GetAmmoStat(self.ammo_field)); // how much ammo do we have?
855 switch(self.ammo_field)
857 case ammo_shells: ammo_full = autocvar_hud_panel_weapons_ammo_full_shells; break;
858 case ammo_nails: ammo_full = autocvar_hud_panel_weapons_ammo_full_nails; break;
859 case ammo_rockets: ammo_full = autocvar_hud_panel_weapons_ammo_full_rockets; break;
860 case ammo_cells: ammo_full = autocvar_hud_panel_weapons_ammo_full_cells; break;
861 case ammo_plasma: ammo_full = autocvar_hud_panel_weapons_ammo_full_plasma; break;
862 case ammo_fuel: ammo_full = autocvar_hud_panel_weapons_ammo_full_fuel; break;
863 default: ammo_full = 60;
867 weapon_pos.x + baroffset.x,
868 weapon_pos.y + baroffset.y,
869 barsize.x * bound(0, a/ammo_full, 1),
886 else // draw a "ghost weapon icon" if you don't have the weapon
888 drawpic_aspect_skin(weapon_pos, self.model2, weapon_size, '0 0 0', panel_fg_alpha * 0.5, DRAWFLAG_NORMAL);
891 // draw the complain message
892 if(self.weapon == complain_weapon)
895 a = ((complain_weapon_time + when > time) ? 1 : bound(0, (complain_weapon_time + when + fadetime - time) / fadetime, 1));
897 a = ((complain_weapon_time + when > time) ? 1 : 0);
900 if(complain_weapon_type == 0) {
901 s = _("Out of ammo");
902 color = stov(autocvar_hud_panel_weapons_complainbubble_color_outofammo);
904 else if(complain_weapon_type == 1) {
906 color = stov(autocvar_hud_panel_weapons_complainbubble_color_donthave);
909 s = _("Unavailable");
910 color = stov(autocvar_hud_panel_weapons_complainbubble_color_unavailable);
912 float padding = autocvar_hud_panel_weapons_complainbubble_padding;
913 drawpic_aspect_skin(weapon_pos + '1 1 0' * padding, "weapon_complainbubble", weapon_size - '2 2 0' * padding, color, a * panel_fg_alpha, DRAWFLAG_NORMAL);
914 drawstring_aspect(weapon_pos + '1 1 0' * padding, s, weapon_size - '2 2 0' * padding, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
919 if(!autocvar_hud_panel_weapons_onlyowned)
921 drawfill(weapon_pos + '1 1 0', weapon_size - '2 2 0', '1 1 1', panel_fg_alpha * 0.2, DRAWFLAG_NORMAL);
922 drawstring(weapon_pos, ftos(i + 1), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
926 // continue with new position for the next weapon
930 if(column >= columns)
951 void DrawNadeScoreBar(vector myPos, vector mySize, vector color)
954 HUD_Panel_DrawProgressBar(
955 myPos + eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize.x,
956 mySize - eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize.x,
957 autocvar_hud_panel_ammo_progressbar_name,
958 getstatf(STAT_NADE_BONUS_SCORE), 0, 0, color,
959 autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
963 void DrawAmmoNades(vector myPos, vector mySize, bool draw_expanding, float expand_time)
965 float theAlpha = 1, a, b;
966 vector nade_color, picpos, numpos;
968 nade_color = Nade_Color(getstati(STAT_NADE_BONUS_TYPE));
970 a = getstatf(STAT_NADE_BONUS);
971 b = getstatf(STAT_NADE_BONUS_SCORE);
973 if(autocvar_hud_panel_ammo_iconalign)
976 picpos = myPos + eX * 2 * mySize.y;
980 numpos = myPos + eX * mySize.y;
984 DrawNadeScoreBar(myPos, mySize, nade_color);
988 if(autocvar_hud_panel_ammo_text)
989 drawstring_aspect(numpos, ftos(a), eX * (2/3) * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
992 drawpic_aspect_skin_expanding(picpos, "nade_nbg", '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL, expand_time);
994 drawpic_aspect_skin(picpos, "nade_bg" , '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
995 drawpic_aspect_skin(picpos, "nade_nbg" , '1 1 0' * mySize.y, nade_color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
999 void DrawAmmoItem(vector myPos, vector mySize, .int ammoType, bool isCurrent, bool isInfinite)
1001 if(ammoType == ammo_none)
1004 // Initialize variables
1007 if(autocvar__hud_configure)
1009 isCurrent = (ammoType == ammo_rockets); // Rockets always current
1013 ammo = getstati(GetAmmoStat(ammoType));
1017 float scale = bound(0, autocvar_hud_panel_ammo_noncurrent_scale, 1);
1018 myPos = myPos + (mySize - mySize * scale) * 0.5;
1019 mySize = mySize * scale;
1022 vector iconPos, textPos;
1023 if(autocvar_hud_panel_ammo_iconalign)
1025 iconPos = myPos + eX * 2 * mySize.y;
1031 textPos = myPos + eX * mySize.y;
1034 bool isShadowed = (ammo <= 0 && !isCurrent && !isInfinite);
1036 vector iconColor = isShadowed ? '0 0 0' : '1 1 1';
1039 textColor = '0.2 0.95 0';
1041 textColor = '0 0 0';
1043 textColor = '0.8 0.04 0';
1045 textColor = '1 1 1';
1049 alpha = panel_fg_alpha;
1051 alpha = panel_fg_alpha * bound(0, autocvar_hud_panel_ammo_noncurrent_alpha, 1) * 0.5;
1053 alpha = panel_fg_alpha * bound(0, autocvar_hud_panel_ammo_noncurrent_alpha, 1);
1055 string text = isInfinite ? "\xE2\x88\x9E" : ftos(ammo); // Use infinity symbol (U+221E)
1060 drawpic_aspect_skin(myPos, "ammo_current_bg", mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
1062 if(ammo > 0 && autocvar_hud_panel_ammo_progressbar)
1063 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);
1065 if(autocvar_hud_panel_ammo_text)
1066 drawstring_aspect(textPos, text, eX * (2/3) * mySize.x + eY * mySize.y, textColor, alpha, DRAWFLAG_NORMAL);
1068 drawpic_aspect_skin(iconPos, GetAmmoPicture(ammoType), '1 1 0' * mySize.y, iconColor, alpha, DRAWFLAG_NORMAL);
1071 int nade_prevstatus;
1073 float nade_statuschange_time;
1076 if(hud != HUD_NORMAL) return;
1077 if(!autocvar__hud_configure)
1079 if(!autocvar_hud_panel_ammo) return;
1080 if(spectatee_status == -1) return;
1083 HUD_Panel_UpdateCvars();
1085 draw_beginBoldFont();
1089 mySize = panel_size;
1091 HUD_Panel_DrawBg(1);
1092 if(panel_bg_padding)
1094 pos += '1 1 0' * panel_bg_padding;
1095 mySize -= '2 2 0' * panel_bg_padding;
1098 int rows = 0, columns, row, column;
1099 float nade_cnt = getstatf(STAT_NADE_BONUS), nade_score = getstatf(STAT_NADE_BONUS_SCORE);
1100 bool draw_nades = (nade_cnt > 0 || nade_score > 0);
1101 float nade_statuschange_elapsedtime;
1102 int total_ammo_count;
1105 if (autocvar_hud_panel_ammo_onlycurrent)
1106 total_ammo_count = 1;
1108 total_ammo_count = AMMO_COUNT;
1113 if (nade_cnt != nade_prevframe)
1115 nade_statuschange_time = time;
1116 nade_prevstatus = nade_prevframe;
1117 nade_prevframe = nade_cnt;
1121 nade_prevstatus = nade_prevframe = nade_statuschange_time = 0;
1123 rows = HUD_GetRowCount(total_ammo_count, mySize, 3);
1124 columns = ceil((total_ammo_count)/rows);
1125 ammo_size = eX * mySize.x*(1/columns) + eY * mySize.y*(1/rows);
1127 vector offset = '0 0 0'; // fteqcc sucks
1129 if(ammo_size.x/ammo_size.y > 3)
1131 newSize = 3 * ammo_size.y;
1132 offset.x = ammo_size.x - newSize;
1133 pos.x += offset.x/2;
1134 ammo_size.x = newSize;
1138 newSize = 1/3 * ammo_size.x;
1139 offset.y = ammo_size.y - newSize;
1140 pos.y += offset.y/2;
1141 ammo_size.y = newSize;
1145 bool infinite_ammo = (getstati(STAT_ITEMS, 0, 24) & IT_UNLIMITED_WEAPON_AMMO);
1147 if(autocvar_hud_panel_ammo_onlycurrent)
1149 if(autocvar__hud_configure)
1151 DrawAmmoItem(pos, ammo_size, ammo_rockets, true, false);
1158 (get_weaponinfo(switchweapon)).ammo_field,
1168 column = column + 1;
1175 for(i = 0; i < AMMO_COUNT; ++i)
1177 ammotype = GetAmmoFieldFromNum(i);
1179 pos + eX * column * (ammo_size.x + offset.x) + eY * row * (ammo_size.y + offset.y),
1182 ((get_weaponinfo(switchweapon)).ammo_field == ammotype),
1190 column = column + 1;
1197 nade_statuschange_elapsedtime = time - nade_statuschange_time;
1199 float f = bound(0, nade_statuschange_elapsedtime*2, 1);
1201 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);
1207 void DrawNumIcon_expanding(vector myPos, vector mySize, float x, string icon, bool vertical, bool icon_right_align, vector color, float theAlpha, float fadelerp)
1209 vector newPos = '0 0 0', newSize = '0 0 0';
1210 vector picpos, numpos;
1214 if(mySize.y/mySize.x > 2)
1216 newSize.y = 2 * mySize.x;
1217 newSize.x = mySize.x;
1219 newPos.y = myPos.y + (mySize.y - newSize.y) / 2;
1224 newSize.x = 1/2 * mySize.y;
1225 newSize.y = mySize.y;
1227 newPos.x = myPos.x + (mySize.x - newSize.x) / 2;
1231 if(icon_right_align)
1234 picpos = newPos + eY * newSize.x;
1239 numpos = newPos + eY * newSize.x;
1243 drawpic_aspect_skin(picpos, icon, newSize, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
1244 // make number smaller than icon, it looks better
1245 // reduce only y to draw numbers with different number of digits with the same y size
1246 numpos.y += newSize.y * ((1 - 0.7) / 2);
1248 drawstring_aspect(numpos, ftos(x), newSize, color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
1252 if(mySize.x/mySize.y > 3)
1254 newSize.x = 3 * mySize.y;
1255 newSize.y = mySize.y;
1257 newPos.x = myPos.x + (mySize.x - newSize.x) / 2;
1262 newSize.y = 1/3 * mySize.x;
1263 newSize.x = mySize.x;
1265 newPos.y = myPos.y + (mySize.y - newSize.y) / 2;
1269 if(icon_right_align) // right align
1272 picpos = newPos + eX * 2 * newSize.y;
1276 numpos = newPos + eX * newSize.y;
1280 // NOTE: newSize_x is always equal to 3 * mySize_y so we can use
1281 // '2 1 0' * newSize_y instead of eX * (2/3) * newSize_x + eY * newSize_y
1282 drawstring_aspect_expanding(numpos, ftos(x), '2 1 0' * newSize.y, color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL, fadelerp);
1283 drawpic_aspect_skin_expanding(picpos, icon, '1 1 0' * newSize.y, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL, fadelerp);
1286 void DrawNumIcon(vector myPos, vector mySize, float x, string icon, bool vertical, bool icon_right_align, vector color, float theAlpha)
1288 DrawNumIcon_expanding(myPos, mySize, x, icon, vertical, icon_right_align, color, theAlpha, 0);
1293 void HUD_Powerups(void)
1295 float strength_time, shield_time, superweapons_time;
1296 if(!autocvar__hud_configure)
1298 if(!autocvar_hud_panel_powerups) return;
1299 if(spectatee_status == -1) return;
1300 if(!(getstati(STAT_ITEMS, 0, 24) & (IT_STRENGTH | IT_INVINCIBLE | IT_SUPERWEAPON))) return;
1301 if (getstati(STAT_HEALTH) <= 0) return;
1303 strength_time = bound(0, getstatf(STAT_STRENGTH_FINISHED) - time, 99);
1304 shield_time = bound(0, getstatf(STAT_INVINCIBLE_FINISHED) - time, 99);
1305 superweapons_time = bound(0, getstatf(STAT_SUPERWEAPONS_FINISHED) - time, 99);
1307 if (getstati(STAT_ITEMS, 0, 24) & IT_UNLIMITED_SUPERWEAPONS)
1308 superweapons_time = 99; // force max
1310 // prevent stuff to show up on mismatch that will be fixed next frame
1311 if (!(getstati(STAT_ITEMS, 0, 24) & IT_SUPERWEAPON))
1312 superweapons_time = 0;
1318 superweapons_time = 13;
1321 HUD_Panel_UpdateCvars();
1323 draw_beginBoldFont();
1327 mySize = panel_size;
1329 HUD_Panel_DrawBg(bound(0, max(strength_time, shield_time, superweapons_time), 1));
1330 if(panel_bg_padding)
1332 pos += '1 1 0' * panel_bg_padding;
1333 mySize -= '2 2 0' * panel_bg_padding;
1336 float panel_ar = mySize.x/mySize.y;
1337 bool is_vertical = (panel_ar < 1);
1338 vector shield_offset = '0 0 0', strength_offset = '0 0 0', superweapons_offset = '0 0 0';
1340 int superweapons_is = -1;
1342 if(superweapons_time)
1347 superweapons_is = 0;
1349 superweapons_is = 2;
1354 superweapons_is = 1;
1356 superweapons_is = 2;
1360 // FIXME handle superweapons here
1361 if(superweapons_is == 0)
1363 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
1365 mySize.x *= (1.0 / 3.0);
1366 superweapons_offset.x = mySize.x;
1367 if (autocvar_hud_panel_powerups_flip)
1368 shield_offset.x = 2*mySize.x;
1370 strength_offset.x = 2*mySize.x;
1374 mySize.y *= (1.0 / 3.0);
1375 superweapons_offset.y = mySize.y;
1376 if (autocvar_hud_panel_powerups_flip)
1377 shield_offset.y = 2*mySize.y;
1379 strength_offset.y = 2*mySize.y;
1384 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
1387 if (autocvar_hud_panel_powerups_flip)
1388 shield_offset.x = mySize.x;
1390 strength_offset.x = mySize.x;
1395 if (autocvar_hud_panel_powerups_flip)
1396 shield_offset.y = mySize.y;
1398 strength_offset.y = mySize.y;
1402 bool shield_baralign, strength_baralign, superweapons_baralign;
1403 bool shield_iconalign, strength_iconalign, superweapons_iconalign;
1405 if (autocvar_hud_panel_powerups_flip)
1407 strength_baralign = (autocvar_hud_panel_powerups_baralign == 2 || autocvar_hud_panel_powerups_baralign == 1);
1408 shield_baralign = (autocvar_hud_panel_powerups_baralign == 3 || autocvar_hud_panel_powerups_baralign == 1);
1409 strength_iconalign = (autocvar_hud_panel_powerups_iconalign == 2 || autocvar_hud_panel_powerups_iconalign == 1);
1410 shield_iconalign = (autocvar_hud_panel_powerups_iconalign == 3 || autocvar_hud_panel_powerups_iconalign == 1);
1414 shield_baralign = (autocvar_hud_panel_powerups_baralign == 2 || autocvar_hud_panel_powerups_baralign == 1);
1415 strength_baralign = (autocvar_hud_panel_powerups_baralign == 3 || autocvar_hud_panel_powerups_baralign == 1);
1416 shield_iconalign = (autocvar_hud_panel_powerups_iconalign == 2 || autocvar_hud_panel_powerups_iconalign == 1);
1417 strength_iconalign = (autocvar_hud_panel_powerups_iconalign == 3 || autocvar_hud_panel_powerups_iconalign == 1);
1420 if(superweapons_is == 0)
1422 superweapons_iconalign = strength_iconalign;
1423 superweapons_baralign = 2;
1425 else if(superweapons_is == 1)
1427 superweapons_offset = strength_offset;
1428 superweapons_iconalign = strength_iconalign;
1429 superweapons_baralign = strength_baralign;
1431 else // if(superweapons_is == 2)
1433 superweapons_offset = shield_offset;
1434 superweapons_iconalign = shield_iconalign;
1435 superweapons_baralign = shield_baralign;
1440 const float maxshield = 30;
1441 float shield = ceil(shield_time);
1442 if(autocvar_hud_panel_powerups_progressbar)
1443 HUD_Panel_DrawProgressBar(pos + shield_offset, mySize, autocvar_hud_panel_powerups_progressbar_shield, shield/maxshield, is_vertical, shield_baralign, autocvar_hud_progressbar_shield_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
1444 if(autocvar_hud_panel_powerups_text)
1447 DrawNumIcon(pos + shield_offset, mySize, shield, "shield", is_vertical, shield_iconalign, '1 1 1', 1);
1449 DrawNumIcon_expanding(pos + shield_offset, mySize, shield, "shield", is_vertical, shield_iconalign, '1 1 1', 1, bound(0, (shield - shield_time) / 0.5, 1));
1455 const float maxstrength = 30;
1456 float strength = ceil(strength_time);
1457 if(autocvar_hud_panel_powerups_progressbar)
1458 HUD_Panel_DrawProgressBar(pos + strength_offset, mySize, autocvar_hud_panel_powerups_progressbar_strength, strength/maxstrength, is_vertical, strength_baralign, autocvar_hud_progressbar_strength_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
1459 if(autocvar_hud_panel_powerups_text)
1462 DrawNumIcon(pos + strength_offset, mySize, strength, "strength", is_vertical, strength_iconalign, '1 1 1', 1);
1464 DrawNumIcon_expanding(pos + strength_offset, mySize, strength, "strength", is_vertical, strength_iconalign, '1 1 1', 1, bound(0, (strength - strength_time) / 0.5, 1));
1468 if(superweapons_time)
1470 const float maxsuperweapons = 30;
1471 float superweapons = ceil(superweapons_time);
1472 if(autocvar_hud_panel_powerups_progressbar)
1473 HUD_Panel_DrawProgressBar(pos + superweapons_offset, mySize, autocvar_hud_panel_powerups_progressbar_superweapons, superweapons/maxsuperweapons, is_vertical, superweapons_baralign, autocvar_hud_progressbar_superweapons_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
1474 if(autocvar_hud_panel_powerups_text)
1476 if(superweapons > 1)
1477 DrawNumIcon(pos + superweapons_offset, mySize, superweapons, "superweapons", is_vertical, superweapons_iconalign, '1 1 1', 1);
1478 if(superweapons <= 5)
1479 DrawNumIcon_expanding(pos + superweapons_offset, mySize, superweapons, "superweapons", is_vertical, superweapons_iconalign, '1 1 1', 1, bound(0, (superweapons - superweapons_time) / 0.5, 1));
1486 // Health/armor (#3)
1489 // prev_* vars contain the health/armor at the previous FRAME
1490 // set to -1 when player is dead or was not playing
1491 int prev_health, prev_armor;
1492 float health_damagetime, armor_damagetime;
1493 int health_beforedamage, armor_beforedamage;
1494 // old_p_* vars keep track of previous values when smoothing value changes of the progressbar
1495 int old_p_health, old_p_armor;
1496 float old_p_healthtime, old_p_armortime;
1497 // prev_p_* vars contain the health/armor progressbar value at the previous FRAME
1498 // set to -1 to forcedly stop effects when we switch spectated player (e.g. from playerX: 70h to playerY: 50h)
1499 int prev_p_health, prev_p_armor;
1501 void HUD_HealthArmor(void)
1503 int armor, health, fuel;
1504 if(!autocvar__hud_configure)
1506 if(!autocvar_hud_panel_healtharmor) return;
1507 if(hud != HUD_NORMAL) return;
1508 if(spectatee_status == -1) return;
1510 health = getstati(STAT_HEALTH);
1516 armor = getstati(STAT_ARMOR);
1518 // code to check for spectatee_status changes is in Ent_ClientData()
1519 // prev_p_health and prev_health can be set to -1 there
1521 if (prev_p_health == -1)
1524 health_beforedamage = 0;
1525 armor_beforedamage = 0;
1526 health_damagetime = 0;
1527 armor_damagetime = 0;
1528 prev_health = health;
1530 old_p_health = health;
1531 old_p_armor = armor;
1532 prev_p_health = health;
1533 prev_p_armor = armor;
1535 else if (prev_health == -1)
1537 //start the load effect
1538 health_damagetime = 0;
1539 armor_damagetime = 0;
1543 fuel = getstati(STAT_FUEL);
1552 HUD_Panel_UpdateCvars();
1555 mySize = panel_size;
1557 HUD_Panel_DrawBg(1);
1558 if(panel_bg_padding)
1560 pos += '1 1 0' * panel_bg_padding;
1561 mySize -= '2 2 0' * panel_bg_padding;
1564 int baralign = autocvar_hud_panel_healtharmor_baralign;
1565 int iconalign = autocvar_hud_panel_healtharmor_iconalign;
1567 int maxhealth = autocvar_hud_panel_healtharmor_maxhealth;
1568 int maxarmor = autocvar_hud_panel_healtharmor_maxarmor;
1569 if(autocvar_hud_panel_healtharmor == 2) // combined health and armor display
1572 v = healtharmor_maxdamage(health, armor, armorblockpercent, DEATH_WEAPON);
1577 float maxtotal = maxhealth + maxarmor;
1579 if(v.z) // NOT fully armored
1581 biggercount = "health";
1582 if(autocvar_hud_panel_healtharmor_progressbar)
1583 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);
1585 if(autocvar_hud_panel_healtharmor_text)
1586 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);
1590 biggercount = "armor";
1591 if(autocvar_hud_panel_healtharmor_progressbar)
1592 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);
1594 if(autocvar_hud_panel_healtharmor_text)
1595 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);
1597 if(autocvar_hud_panel_healtharmor_text)
1598 DrawNumIcon(pos, mySize, x, biggercount, 0, iconalign, HUD_Get_Num_Color(x, maxtotal), 1);
1601 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);
1605 float panel_ar = mySize.x/mySize.y;
1606 bool is_vertical = (panel_ar < 1);
1607 vector health_offset = '0 0 0', armor_offset = '0 0 0';
1608 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
1611 if (autocvar_hud_panel_healtharmor_flip)
1612 health_offset.x = mySize.x;
1614 armor_offset.x = mySize.x;
1619 if (autocvar_hud_panel_healtharmor_flip)
1620 health_offset.y = mySize.y;
1622 armor_offset.y = mySize.y;
1625 bool health_baralign, armor_baralign, fuel_baralign;
1626 bool health_iconalign, armor_iconalign;
1627 if (autocvar_hud_panel_healtharmor_flip)
1629 armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1);
1630 health_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1);
1631 fuel_baralign = health_baralign;
1632 armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1);
1633 health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1);
1637 health_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1);
1638 armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1);
1639 fuel_baralign = armor_baralign;
1640 health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1);
1641 armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1);
1646 if(autocvar_hud_panel_healtharmor_progressbar)
1648 float p_health, pain_health_alpha;
1650 pain_health_alpha = 1;
1651 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
1653 if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0)
1655 if (fabs(prev_health - health) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth)
1657 if (time - old_p_healthtime < 1)
1658 old_p_health = prev_p_health;
1660 old_p_health = prev_health;
1661 old_p_healthtime = time;
1663 if (time - old_p_healthtime < 1)
1665 p_health += (old_p_health - health) * (1 - (time - old_p_healthtime));
1666 prev_p_health = p_health;
1669 if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0)
1671 if (prev_health - health >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
1673 if (time - health_damagetime >= 1)
1674 health_beforedamage = prev_health;
1675 health_damagetime = time;
1677 if (time - health_damagetime < 1)
1679 float health_damagealpha = 1 - (time - health_damagetime)*(time - health_damagetime);
1680 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);
1683 prev_health = health;
1685 if (health <= autocvar_hud_panel_healtharmor_progressbar_gfx_lowhealth)
1687 float BLINK_FACTOR = 0.15;
1688 float BLINK_BASE = 0.85;
1689 float BLINK_FREQ = 9;
1690 pain_health_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ);
1693 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);
1695 if(autocvar_hud_panel_healtharmor_text)
1696 DrawNumIcon(pos + health_offset, mySize, health, "health", is_vertical, health_iconalign, HUD_Get_Num_Color(health, maxhealth), 1);
1701 if(autocvar_hud_panel_healtharmor_progressbar)
1705 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
1707 if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0)
1709 if (fabs(prev_armor - armor) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth)
1711 if (time - old_p_armortime < 1)
1712 old_p_armor = prev_p_armor;
1714 old_p_armor = prev_armor;
1715 old_p_armortime = time;
1717 if (time - old_p_armortime < 1)
1719 p_armor += (old_p_armor - armor) * (1 - (time - old_p_armortime));
1720 prev_p_armor = p_armor;
1723 if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0)
1725 if (prev_armor - armor >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
1727 if (time - armor_damagetime >= 1)
1728 armor_beforedamage = prev_armor;
1729 armor_damagetime = time;
1731 if (time - armor_damagetime < 1)
1733 float armor_damagealpha = 1 - (time - armor_damagetime)*(time - armor_damagetime);
1734 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);
1739 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);
1741 if(autocvar_hud_panel_healtharmor_text)
1742 DrawNumIcon(pos + armor_offset, mySize, armor, "armor", is_vertical, armor_iconalign, HUD_Get_Num_Color(armor, maxarmor), 1);
1748 mySize.x *= 0.2 / 2; //if vertical always halve x to not cover too much numbers with 3 digits
1752 mySize.x *= 2; //restore full panel size
1753 else if (panel_ar < 1/4)
1754 mySize.y *= 2; //restore full panel size
1755 HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", fuel/100, is_vertical, fuel_baralign, autocvar_hud_progressbar_fuel_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
1760 // Notification area (#4)
1763 void HUD_Notify_Push(string icon, string attacker, string victim)
1771 if (notify_index == -1)
1772 notify_index = NOTIFY_MAX_ENTRIES-1;
1775 if (notify_attackers[notify_index])
1776 strunzone(notify_attackers[notify_index]);
1778 if (notify_victims[notify_index])
1779 strunzone(notify_victims[notify_index]);
1781 if (notify_icons[notify_index])
1782 strunzone(notify_icons[notify_index]);
1784 // Allocate new strings
1787 notify_attackers[notify_index] = strzone(attacker);
1788 notify_victims[notify_index] = strzone(victim);
1792 // In case of a notification without a victim, the attacker
1793 // is displayed on the victim's side. Instead of special
1794 // treatment later on, we can simply switch them here.
1795 notify_attackers[notify_index] = string_null;
1796 notify_victims[notify_index] = strzone(attacker);
1799 notify_icons[notify_index] = strzone(icon);
1800 notify_times[notify_index] = time;
1803 void HUD_Notify(void)
1805 if (!autocvar__hud_configure)
1806 if (!autocvar_hud_panel_notify)
1809 HUD_Panel_UpdateCvars();
1810 HUD_Panel_DrawBg(1);
1812 if (!autocvar__hud_configure)
1813 if (notify_count == 0)
1820 if (panel_bg_padding)
1822 pos += '1 1 0' * panel_bg_padding;
1823 size -= '2 2 0' * panel_bg_padding;
1826 float fade_start = max(0, autocvar_hud_panel_notify_time);
1827 float fade_time = max(0, autocvar_hud_panel_notify_fadetime);
1828 float icon_aspect = max(1, autocvar_hud_panel_notify_icon_aspect);
1830 int entry_count = bound(1, floor(NOTIFY_MAX_ENTRIES * size.y / size.x), NOTIFY_MAX_ENTRIES);
1831 float entry_height = size.y / entry_count;
1833 float panel_width_half = size.x * 0.5;
1834 float icon_width_half = entry_height * icon_aspect / 2;
1835 float name_maxwidth = panel_width_half - icon_width_half - size.x * NOTIFY_ICON_MARGIN;
1837 vector font_size = '0.5 0.5 0' * entry_height * autocvar_hud_panel_notify_fontsize;
1838 vector icon_size = (eX * icon_aspect + eY) * entry_height;
1839 vector icon_left = eX * (panel_width_half - icon_width_half);
1840 vector attacker_right = eX * name_maxwidth;
1841 vector victim_left = eX * (size.x - name_maxwidth);
1843 vector attacker_pos, victim_pos, icon_pos;
1844 string attacker, victim, icon;
1845 int i, j, count, step, limit;
1848 if (autocvar_hud_panel_notify_flip)
1850 // Order items from the top down
1853 limit = entry_count;
1857 // Order items from the bottom up
1858 i = entry_count - 1;
1863 for (j = notify_index, count = 0; i != limit; i += step, ++j, ++count)
1865 if(autocvar__hud_configure)
1867 attacker = sprintf(_("Player %d"), count + 1);
1868 victim = sprintf(_("Player %d"), count + 2);
1869 icon = get_weaponinfo(min(WEP_FIRST + count * 2, WEP_LAST)).model2;
1870 alpha = bound(0, 1.2 - count / entry_count, 1);
1874 if (j == NOTIFY_MAX_ENTRIES)
1877 if (notify_times[j] + fade_start > time)
1879 else if (fade_time != 0)
1881 alpha = bound(0, (notify_times[j] + fade_start + fade_time - time) / fade_time, 1);
1888 attacker = notify_attackers[j];
1889 victim = notify_victims[j];
1890 icon = notify_icons[j];
1893 if (icon != "" && victim != "")
1895 vector name_top = eY * (i * entry_height + 0.5 * (entry_height - font_size.y));
1897 icon_pos = pos + icon_left + eY * i * entry_height;
1898 drawpic_aspect_skin(icon_pos, icon, icon_size, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1900 victim = textShortenToWidth(victim, name_maxwidth, font_size, stringwidth_colors);
1901 victim_pos = pos + victim_left + name_top;
1902 drawcolorcodedstring(victim_pos, victim, font_size, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1906 attacker = textShortenToWidth(attacker, name_maxwidth, font_size, stringwidth_colors);
1907 attacker_pos = pos + attacker_right - eX * stringwidth(attacker, true, font_size) + name_top;
1908 drawcolorcodedstring(attacker_pos, attacker, font_size, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1913 notify_count = count;
1919 string seconds_tostring(float sec)
1922 minutes = floor(sec / 60);
1924 sec -= minutes * 60;
1925 return sprintf("%d:%02d", minutes, sec);
1928 void HUD_Timer(void)
1930 if(!autocvar__hud_configure)
1932 if(!autocvar_hud_panel_timer) return;
1935 HUD_Panel_UpdateCvars();
1937 draw_beginBoldFont();
1941 mySize = panel_size;
1943 HUD_Panel_DrawBg(1);
1944 if(panel_bg_padding)
1946 pos += '1 1 0' * panel_bg_padding;
1947 mySize -= '2 2 0' * panel_bg_padding;
1951 float timelimit, elapsedTime, timeleft, minutesLeft;
1953 timelimit = getstatf(STAT_TIMELIMIT);
1955 timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
1956 timeleft = ceil(timeleft);
1958 minutesLeft = floor(timeleft / 60);
1961 if(minutesLeft >= 5 || warmup_stage || timelimit == 0) //don't use red or yellow in warmup or when there is no timelimit
1962 timer_color = '1 1 1'; //white
1963 else if(minutesLeft >= 1)
1964 timer_color = '1 1 0'; //yellow
1966 timer_color = '1 0 0'; //red
1968 if (autocvar_hud_panel_timer_increment || timelimit == 0 || warmup_stage) {
1969 if (time < getstatf(STAT_GAMESTARTTIME)) {
1970 //while restart is still active, show 00:00
1971 timer = seconds_tostring(0);
1973 elapsedTime = floor(time - getstatf(STAT_GAMESTARTTIME)); //127
1974 timer = seconds_tostring(elapsedTime);
1977 timer = seconds_tostring(timeleft);
1980 drawstring_aspect(pos, timer, mySize, timer_color, panel_fg_alpha, DRAWFLAG_NORMAL);
1987 void HUD_Radar(void)
1989 if (!autocvar__hud_configure)
1991 if (hud_panel_radar_maximized)
1993 if (!hud_draw_maximized) return;
1997 if (autocvar_hud_panel_radar == 0) return;
1998 if (autocvar_hud_panel_radar != 2 && !teamplay) return;
1999 if(radar_panel_modified)
2001 panel.update_time = time; // forces reload of panel attributes
2002 radar_panel_modified = false;
2007 HUD_Panel_UpdateCvars();
2011 if (hud_panel_radar_maximized && !autocvar__hud_configure)
2013 panel_size = autocvar_hud_panel_radar_maximized_size;
2014 panel_size.x = bound(0.2, panel_size.x, 1) * vid_conwidth;
2015 panel_size.y = bound(0.2, panel_size.y, 1) * vid_conheight;
2016 panel_pos.x = (vid_conwidth - panel_size.x) / 2;
2017 panel_pos.y = (vid_conheight - panel_size.y) / 2;
2020 panel_bg = strcat(hud_skin_path, "/border_default"); // always use the default border when maximized
2021 if(precache_pic(panel_bg) == "")
2022 panel_bg = "gfx/hud/default/border_default"; // fallback
2023 if(!radar_panel_modified && panel_bg != panel.current_panel_bg)
2024 radar_panel_modified = true;
2025 if(panel.current_panel_bg)
2026 strunzone(panel.current_panel_bg);
2027 panel.current_panel_bg = strzone(panel_bg);
2029 switch(hud_panel_radar_maximized_zoommode)
2033 f = current_zoomfraction;
2036 f = 1 - current_zoomfraction;
2046 switch(hud_panel_radar_maximized_rotation)
2049 teamradar_angle = view_angles.y - 90;
2052 teamradar_angle = 90 * hud_panel_radar_maximized_rotation;
2056 if (!hud_panel_radar_maximized && !autocvar__hud_configure)
2058 switch(hud_panel_radar_zoommode)
2062 f = current_zoomfraction;
2065 f = 1 - current_zoomfraction;
2075 switch(hud_panel_radar_rotation)
2078 teamradar_angle = view_angles.y - 90;
2081 teamradar_angle = 90 * hud_panel_radar_rotation;
2088 mySize = panel_size;
2090 HUD_Panel_DrawBg(1);
2091 if(panel_bg_padding)
2093 pos += '1 1 0' * panel_bg_padding;
2094 mySize -= '2 2 0' * panel_bg_padding;
2099 float scale2d, normalsize, bigsize;
2101 teamradar_origin2d = pos + 0.5 * mySize;
2102 teamradar_size2d = mySize;
2104 if(minimapname == "")
2107 teamradar_loadcvars();
2109 scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
2110 teamradar_size2d = mySize;
2112 teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0'; // we always center
2114 // pixels per world qu to match the teamradar_size2d_x range in the longest dimension
2115 if((hud_panel_radar_rotation == 0 && !hud_panel_radar_maximized) || (hud_panel_radar_maximized_rotation == 0 && hud_panel_radar_maximized))
2117 // max-min distance must fit the radar in any rotation
2118 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen2d(mi_scale));
2122 vector c0, c1, c2, c3, span;
2123 c0 = rotate(mi_min, teamradar_angle * DEG2RAD);
2124 c1 = rotate(mi_max, teamradar_angle * DEG2RAD);
2125 c2 = rotate('1 0 0' * mi_min.x + '0 1 0' * mi_max.y, teamradar_angle * DEG2RAD);
2126 c3 = rotate('1 0 0' * mi_max.x + '0 1 0' * mi_min.y, teamradar_angle * DEG2RAD);
2128 span.x = max(c0_x, c1_x, c2_x, c3_x) - min(c0_x, c1_x, c2_x, c3_x);
2129 span.y = max(c0_y, c1_y, c2_y, c3_y) - min(c0_y, c1_y, c2_y, c3_y);
2131 // max-min distance must fit the radar in x=x, y=y
2133 teamradar_size2d.x * scale2d / (1.05 * span.x),
2134 teamradar_size2d.y * scale2d / (1.05 * span.y)
2138 normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / hud_panel_radar_scale;
2139 if(bigsize > normalsize)
2140 normalsize = bigsize;
2144 + (1 - f) * normalsize;
2145 teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
2147 + (1 - f) * view_origin);
2156 draw_teamradar_background(hud_panel_radar_foreground_alpha);
2158 for(tm = world; (tm = find(tm, classname, "radarlink")); )
2159 draw_teamradar_link(tm.origin, tm.velocity, tm.team);
2160 for(tm = world; (tm = findflags(tm, teamradar_icon, 0xFFFFFF)); )
2161 draw_teamradar_icon(tm.origin, tm.teamradar_icon, tm, tm.teamradar_color, panel_fg_alpha);
2162 for(tm = world; (tm = find(tm, classname, "entcs_receiver")); )
2164 color2 = GetPlayerColor(tm.sv_entnum);
2165 //if(color == NUM_SPECTATOR || color == color2)
2166 draw_teamradar_player(tm.origin, tm.angles, Team_ColorRGB(color2));
2168 draw_teamradar_player(view_origin, view_angles, '1 1 1');
2170 drawresetcliparea();
2175 void HUD_UpdatePlayerTeams();
2176 void HUD_Score_Rankings(vector pos, vector mySize, entity me)
2179 entity tm = world, pl;
2180 int SCOREPANEL_MAX_ENTRIES = 6;
2181 float SCOREPANEL_ASPECTRATIO = 2;
2182 int entries = bound(1, floor(SCOREPANEL_MAX_ENTRIES * mySize.y/mySize.x * SCOREPANEL_ASPECTRATIO), SCOREPANEL_MAX_ENTRIES);
2183 vector fontsize = '1 1 0' * (mySize.y/entries);
2185 vector rgb, score_color;
2187 score_color = '1 1 1';
2189 float name_size = mySize.x*0.75;
2190 float spacing_size = mySize.x*0.04;
2191 const float highlight_alpha = 0.2;
2192 int i = 0, first_pl = 0;
2193 bool me_printed = false;
2195 if (autocvar__hud_configure)
2197 float players_per_team = 0;
2200 // show team scores in the first line
2201 float score_size = mySize.x / team_count;
2202 players_per_team = max(2, ceil((entries - 1) / team_count));
2203 for(i=0; i<team_count; ++i) {
2204 if (i == floor((entries - 2) / players_per_team) || (entries == 1 && i == 0))
2205 HUD_Panel_DrawHighlight(pos + eX * score_size * i, eX * score_size + eY * fontsize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2206 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);
2209 pos.y += fontsize.y;
2211 score = 10 + SCOREPANEL_MAX_ENTRIES * 3;
2212 for (i=first_pl; i<entries; ++i)
2214 //simulate my score is lower than all displayed players,
2215 //so that I don't appear at all showing pure rankings.
2216 //This is to better show the difference between the 2 ranking views
2217 if (i == entries-1 && autocvar_hud_panel_score_rankings == 1)
2220 drawfill(pos, eX * mySize.x + eY * fontsize.y, rgb, highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2221 s = GetPlayerName(player_localnum);
2226 s = sprintf(_("Player %d"), i + 1 - first_pl);
2231 score_color = Team_ColorRGB(ColorByTeam(floor((i - first_pl) / players_per_team))) * 0.8;
2232 s = textShortenToWidth(s, name_size, fontsize, stringwidth_colors);
2233 drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, true, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
2234 drawstring(pos + eX * (name_size + spacing_size), ftos(score), fontsize, score_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2235 pos.y += fontsize.y;
2240 if (!scoreboard_fade_alpha) // the scoreboard too calls HUD_UpdatePlayerTeams
2241 HUD_UpdatePlayerTeams();
2244 // show team scores in the first line
2245 float score_size = mySize.x / team_count;
2246 for(tm = teams.sort_next; tm; tm = tm.sort_next) {
2247 if(tm.team == NUM_SPECTATOR)
2249 if (tm.team == myteam)
2250 drawfill(pos + eX * score_size * i, eX * score_size + eY * fontsize.y, '1 1 1', highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2251 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);
2255 pos.y += fontsize.y;
2256 tm = teams.sort_next;
2261 for (pl = players.sort_next; pl && i<entries; pl = pl.sort_next)
2263 if ((team_count && pl.team != tm.team) || pl.team == NUM_SPECTATOR)
2266 if (i == entries-1 && !me_printed && pl != me)
2267 if (autocvar_hud_panel_score_rankings == 1 && spectatee_status != -1)
2269 for (pl = me.sort_next; pl; pl = pl.sort_next)
2270 if (pl.team != NUM_SPECTATOR)
2274 rgb = '1 1 0'; //not last but not among the leading players: yellow
2276 rgb = '1 0 0'; //last: red
2283 rgb = '0 1 0'; //first: green
2285 drawfill(pos, eX * mySize.x + eY * fontsize.y, rgb, highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2288 score_color = Team_ColorRGB(pl.team) * 0.8;
2289 s = textShortenToWidth(GetPlayerName(pl.sv_entnum), name_size, fontsize, stringwidth_colors);
2290 drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, true, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
2291 drawstring(pos + eX * (name_size + spacing_size), ftos(pl.(scores[ps_primary])), fontsize, score_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2292 pos.y += fontsize.y;
2295 while (i<entries && team_count && (tm = tm.sort_next) && (tm.team != NUM_SPECTATOR || (tm = tm.sort_next)));
2298 void HUD_Score(void)
2300 if(!autocvar__hud_configure)
2302 if(!autocvar_hud_panel_score) return;
2303 if(spectatee_status == -1 && (gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return;
2306 HUD_Panel_UpdateCvars();
2309 mySize = panel_size;
2311 HUD_Panel_DrawBg(1);
2312 if(panel_bg_padding)
2314 pos += '1 1 0' * panel_bg_padding;
2315 mySize -= '2 2 0' * panel_bg_padding;
2318 float score, distribution = 0;
2320 vector distribution_color;
2323 me = playerslots[player_localentnum - 1];
2325 if((scores_flags[ps_primary] & SFL_TIME) && !teamplay) { // race/cts record display on HUD
2326 string timer, distrtimer;
2328 pl = players.sort_next;
2331 if(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)
2332 if(pl.scores[ps_primary] == 0)
2335 score = me.(scores[ps_primary]);
2336 timer = TIME_ENCODED_TOSTRING(score);
2338 draw_beginBoldFont();
2339 if (pl && ((!(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)) || score)) {
2340 // distribution display
2341 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
2343 distrtimer = ftos_decimals(fabs(distribution/pow(10, TIME_DECIMALS)), TIME_DECIMALS);
2345 if (distribution <= 0) {
2346 distribution_color = '0 1 0';
2350 distribution_color = '1 0 0';
2353 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);
2355 // race record display
2356 if (distribution <= 0)
2357 HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2358 drawstring_aspect(pos, timer, eX * 0.75 * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2360 } else if (!teamplay) { // non-teamgames
2361 if ((spectatee_status == -1 && !autocvar__hud_configure) || autocvar_hud_panel_score_rankings)
2363 HUD_Score_Rankings(pos, mySize, me);
2366 // me vector := [team/connected frags id]
2367 pl = players.sort_next;
2371 if(autocvar__hud_configure)
2374 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
2378 score = me.(scores[ps_primary]);
2379 if(autocvar__hud_configure)
2382 if(distribution >= 5)
2383 distribution_color = eY;
2384 else if(distribution >= 0)
2385 distribution_color = '1 1 1';
2386 else if(distribution >= -5)
2387 distribution_color = '1 1 0';
2389 distribution_color = eX;
2391 string distribution_str;
2392 distribution_str = ftos(distribution);
2393 draw_beginBoldFont();
2394 if (distribution >= 0)
2396 if (distribution > 0)
2397 distribution_str = strcat("+", distribution_str);
2398 HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2400 drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize.x + eY * mySize.y, distribution_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2401 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);
2403 } else { // teamgames
2404 float row, column, rows = 0, columns = 0;
2405 vector offset = '0 0 0';
2406 vector score_pos, score_size; //for scores other than myteam
2407 if(autocvar_hud_panel_score_rankings)
2409 HUD_Score_Rankings(pos, mySize, me);
2412 if(spectatee_status == -1)
2414 rows = HUD_GetRowCount(team_count, mySize, 3);
2415 columns = ceil(team_count/rows);
2416 score_size = eX * mySize.x*(1/columns) + eY * mySize.y*(1/rows);
2419 if(score_size.x/score_size.y > 3)
2421 newSize = 3 * score_size.y;
2422 offset.x = score_size.x - newSize;
2423 pos.x += offset.x/2;
2424 score_size.x = newSize;
2428 newSize = 1/3 * score_size.x;
2429 offset.y = score_size.y - newSize;
2430 pos.y += offset.y/2;
2431 score_size.y = newSize;
2435 score_size = eX * mySize.x*(1/4) + eY * mySize.y*(1/3);
2437 float max_fragcount;
2438 max_fragcount = -99;
2439 draw_beginBoldFont();
2441 for(tm = teams.sort_next; tm; tm = tm.sort_next) {
2442 if(tm.team == NUM_SPECTATOR)
2444 score = tm.(teamscores[ts_primary]);
2445 if(autocvar__hud_configure)
2448 if (score > max_fragcount)
2449 max_fragcount = score;
2451 if (spectatee_status == -1)
2453 score_pos = pos + eX * column * (score_size.x + offset.x) + eY * row * (score_size.y + offset.y);
2454 if (max_fragcount == score)
2455 HUD_Panel_DrawHighlight(score_pos, score_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2456 drawstring_aspect(score_pos, ftos(score), score_size, Team_ColorRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2464 else if(tm.team == myteam) {
2465 if (max_fragcount == score)
2466 HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2467 drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize.x + eY * mySize.y, Team_ColorRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2469 if (max_fragcount == score)
2470 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);
2471 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);
2481 void HUD_RaceTimer (void)
2483 if(!autocvar__hud_configure)
2485 if(!autocvar_hud_panel_racetimer) return;
2486 if(!(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return;
2487 if(spectatee_status == -1) return;
2490 HUD_Panel_UpdateCvars();
2492 draw_beginBoldFont();
2496 mySize = panel_size;
2498 HUD_Panel_DrawBg(1);
2499 if(panel_bg_padding)
2501 pos += '1 1 0' * panel_bg_padding;
2502 mySize -= '2 2 0' * panel_bg_padding;
2505 // always force 4:1 aspect
2506 vector newSize = '0 0 0';
2507 if(mySize.x/mySize.y > 4)
2509 newSize.x = 4 * mySize.y;
2510 newSize.y = mySize.y;
2512 pos.x = pos.x + (mySize.x - newSize.x) / 2;
2516 newSize.y = 1/4 * mySize.x;
2517 newSize.x = mySize.x;
2519 pos.y = pos.y + (mySize.y - newSize.y) / 2;
2524 string s, forcetime;
2526 if(autocvar__hud_configure)
2529 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);
2530 s = _("^1Intermediate 1 (+15.42)");
2531 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);
2532 s = sprintf(_("^1PENALTY: %.1f (%s)"), 2, "missing a checkpoint");
2533 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);
2535 else if(race_checkpointtime)
2537 a = bound(0, 2 - (time - race_checkpointtime), 1);
2540 if(a > 0) // just hit a checkpoint?
2542 if(race_checkpoint != 254)
2544 if(race_time && race_previousbesttime)
2545 s = MakeRaceString(race_checkpoint, TIME_DECODE(race_time) - TIME_DECODE(race_previousbesttime), 0, 0, race_previousbestname);
2547 s = MakeRaceString(race_checkpoint, 0, -1, 0, race_previousbestname);
2549 forcetime = TIME_ENCODED_TOSTRING(race_time);
2554 if(race_laptime && race_nextbesttime && race_nextcheckpoint != 254)
2556 a = bound(0, 2 - ((race_laptime + TIME_DECODE(race_nextbesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1);
2557 if(a > 0) // next one?
2559 s = MakeRaceString(race_nextcheckpoint, (time + TIME_DECODE(race_penaltyaccumulator)) - race_laptime, TIME_DECODE(race_nextbesttime), 0, race_nextbestname);
2564 if(s != "" && a > 0)
2566 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);
2569 if(race_penaltytime)
2571 a = bound(0, 2 - (time - race_penaltyeventtime), 1);
2574 s = sprintf(_("^1PENALTY: %.1f (%s)"), race_penaltytime * 0.1, race_penaltyreason);
2575 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);
2581 a = bound(0, (time - race_checkpointtime) / 0.5, 1);
2582 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);
2587 if(race_laptime && race_checkpoint != 255)
2589 s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime));
2590 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);
2595 if(race_mycheckpointtime)
2597 a = bound(0, 2 - (time - race_mycheckpointtime), 1);
2598 s = MakeRaceString(race_mycheckpoint, TIME_DECODE(race_mycheckpointdelta), -(race_mycheckpointenemy == ""), race_mycheckpointlapsdelta, race_mycheckpointenemy);
2599 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);
2601 if(race_othercheckpointtime && race_othercheckpointenemy != "")
2603 a = bound(0, 2 - (time - race_othercheckpointtime), 1);
2604 s = MakeRaceString(race_othercheckpoint, -TIME_DECODE(race_othercheckpointdelta), -(race_othercheckpointenemy == ""), race_othercheckpointlapsdelta, race_othercheckpointenemy);
2605 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);
2608 if(race_penaltytime && !race_penaltyaccumulator)
2610 t = race_penaltytime * 0.1 + race_penaltyeventtime;
2611 a = bound(0, (1 + t - time), 1);
2615 s = sprintf(_("^1PENALTY: %.1f (%s)"), (t - time) * 0.1, race_penaltyreason);
2617 s = sprintf(_("^2PENALTY: %.1f (%s)"), 0, race_penaltyreason);
2618 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);
2631 int vote_highlighted; // currently selected vote
2633 int vote_active; // is there an active vote?
2634 int vote_prev; // previous state of vote_active to check for a change
2636 float vote_change; // "time" when vote_active changed
2640 if(autocvar_cl_allow_uid2name == -1 && (gametype == MAPINFO_TYPE_CTS || gametype == MAPINFO_TYPE_RACE || (serverflags & SERVERFLAG_PLAYERSTATS)))
2643 if (autocvar__hud_configure)
2647 print(_("^1You must answer before entering hud configure mode\n"));
2648 cvar_set("_hud_configure", "0");
2650 if(vote_called_vote)
2651 strunzone(vote_called_vote);
2652 vote_called_vote = strzone(_("^2Name ^7instead of \"^1Anonymous player^7\" in stats"));
2653 uid2name_dialog = 1;
2656 if(!autocvar__hud_configure)
2658 if(!autocvar_hud_panel_vote) return;
2660 panel_fg_alpha = autocvar_hud_panel_fg_alpha;
2661 panel_bg_alpha_str = autocvar_hud_panel_vote_bg_alpha;
2663 if(panel_bg_alpha_str == "") {
2664 panel_bg_alpha_str = ftos(autocvar_hud_panel_bg_alpha);
2666 panel_bg_alpha = stof(panel_bg_alpha_str);
2677 if(vote_active != vote_prev) {
2679 vote_prev = vote_active;
2682 if(vote_active || autocvar__hud_configure)
2683 vote_alpha = bound(0, (time - vote_change) * 2, 1);
2685 vote_alpha = bound(0, 1 - (time - vote_change) * 2, 1);
2690 HUD_Panel_UpdateCvars();
2694 panel_pos = eX * 0.3 * vid_conwidth + eY * 0.1 * vid_conheight;
2695 panel_size = eX * 0.4 * vid_conwidth + eY * 0.3 * vid_conheight;
2698 // these must be below above block
2701 mySize = panel_size;
2703 a = vote_alpha * (vote_highlighted ? autocvar_hud_panel_vote_alreadyvoted_alpha : 1);
2704 HUD_Panel_DrawBg(a);
2705 a = panel_fg_alpha * a;
2707 if(panel_bg_padding)
2709 pos += '1 1 0' * panel_bg_padding;
2710 mySize -= '2 2 0' * panel_bg_padding;
2713 // always force 3:1 aspect
2714 vector newSize = '0 0 0';
2715 if(mySize.x/mySize.y > 3)
2717 newSize.x = 3 * mySize.y;
2718 newSize.y = mySize.y;
2720 pos.x = pos.x + (mySize.x - newSize.x) / 2;
2724 newSize.y = 1/3 * mySize.x;
2725 newSize.x = mySize.x;
2727 pos.y = pos.y + (mySize.y - newSize.y) / 2;
2731 s = _("A vote has been called for:");
2733 s = _("Allow servers to store and display your name?");
2734 drawstring_aspect(pos, s, eX * mySize.x + eY * (2/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
2735 s = textShortenToWidth(vote_called_vote, mySize.x, '1 1 0' * mySize.y * (1/8), stringwidth_colors);
2736 if(autocvar__hud_configure)
2737 s = _("^1Configure the HUD");
2738 drawcolorcodedstring_aspect(pos + eY * (2/8) * mySize.y, s, eX * mySize.x + eY * (1.75/8) * mySize.y, a, DRAWFLAG_NORMAL);
2740 // print the yes/no counts
2741 s = sprintf(_("Yes (%s): %d"), getcommandkey("vyes", "vyes"), vote_yescount);
2742 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);
2743 s = sprintf(_("No (%s): %d"), getcommandkey("vno", "vno"), vote_nocount);
2744 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);
2746 // draw the progress bar backgrounds
2747 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_back", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
2749 // draw the highlights
2750 if(vote_highlighted == 1) {
2751 drawsetcliparea(pos.x, pos.y, mySize.x * 0.5, mySize.y);
2752 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_voted", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
2754 else if(vote_highlighted == -1) {
2755 drawsetcliparea(pos.x + 0.5 * mySize.x, pos.y, mySize.x * 0.5, mySize.y);
2756 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_voted", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
2759 // draw the progress bars
2760 if(vote_yescount && vote_needed)
2762 drawsetcliparea(pos.x, pos.y, mySize.x * 0.5 * (vote_yescount/vote_needed), mySize.y);
2763 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_prog", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
2766 if(vote_nocount && vote_needed)
2768 drawsetcliparea(pos.x + mySize.x - mySize.x * 0.5 * (vote_nocount/vote_needed), pos.y, mySize.x * 0.5, mySize.y);
2769 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_prog", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
2772 drawresetcliparea();
2775 // Mod icons panel (#10)
2778 bool mod_active; // is there any active mod icon?
2780 void DrawCAItem(vector myPos, vector mySize, float aspect_ratio, int layout, int i)
2784 vector color = '0 0 0';
2788 stat = getstati(STAT_REDALIVE);
2789 pic = "player_red.tga";
2793 stat = getstati(STAT_BLUEALIVE);
2794 pic = "player_blue.tga";
2798 stat = getstati(STAT_YELLOWALIVE);
2799 pic = "player_yellow.tga";
2804 stat = getstati(STAT_PINKALIVE);
2805 pic = "player_pink.tga";
2810 if(mySize.x/mySize.y > aspect_ratio)
2812 i = aspect_ratio * mySize.y;
2813 myPos.x = myPos.x + (mySize.x - i) / 2;
2818 i = 1/aspect_ratio * mySize.x;
2819 myPos.y = myPos.y + (mySize.y - i) / 2;
2825 drawpic_aspect_skin(myPos, pic, eX * 0.7 * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2826 drawstring_aspect(myPos + eX * 0.7 * mySize.x, ftos(stat), eX * 0.3 * mySize.x + eY * mySize.y, color, panel_fg_alpha, DRAWFLAG_NORMAL);
2829 drawstring_aspect(myPos, ftos(stat), mySize, color, panel_fg_alpha, DRAWFLAG_NORMAL);
2832 // Clan Arena and Freeze Tag HUD modicons
2833 void HUD_Mod_CA(vector myPos, vector mySize)
2835 mod_active = 1; // required in each mod function that always shows something
2838 if(gametype == MAPINFO_TYPE_CA)
2839 layout = autocvar_hud_panel_modicons_ca_layout;
2840 else //if(gametype == MAPINFO_TYPE_FREEZETAG)
2841 layout = autocvar_hud_panel_modicons_freezetag_layout;
2844 aspect_ratio = (layout) ? 2 : 1;
2845 rows = HUD_GetRowCount(team_count, mySize, aspect_ratio);
2846 columns = ceil(team_count/rows);
2849 float row = 0, column = 0;
2850 vector pos, itemSize;
2851 itemSize = eX * mySize.x*(1/columns) + eY * mySize.y*(1/rows);
2852 for(i=0; i<team_count; ++i)
2854 pos = myPos + eX * column * itemSize.x + eY * row * itemSize.y;
2856 DrawCAItem(pos, itemSize, aspect_ratio, layout, i);
2867 // CTF HUD modicon section
2868 int redflag_prevframe, blueflag_prevframe, yellowflag_prevframe, pinkflag_prevframe, neutralflag_prevframe; // status during previous frame
2869 int redflag_prevstatus, blueflag_prevstatus, yellowflag_prevstatus, pinkflag_prevstatus, neutralflag_prevstatus; // last remembered status
2870 float redflag_statuschange_time, blueflag_statuschange_time, yellowflag_statuschange_time, pinkflag_statuschange_time, neutralflag_statuschange_time; // time when the status changed
2872 void HUD_Mod_CTF_Reset(void)
2874 redflag_prevstatus = blueflag_prevstatus = yellowflag_prevstatus = pinkflag_prevstatus = neutralflag_prevstatus = 0;
2875 redflag_prevframe = blueflag_prevframe = yellowflag_prevframe = pinkflag_prevframe = neutralflag_prevframe = 0;
2876 redflag_statuschange_time = blueflag_statuschange_time = yellowflag_statuschange_time = pinkflag_statuschange_time = neutralflag_statuschange_time = 0;
2879 void HUD_Mod_CTF(vector pos, vector mySize)
2881 vector redflag_pos, blueflag_pos, yellowflag_pos, pinkflag_pos, neutralflag_pos;
2883 float f; // every function should have that
2885 int redflag, blueflag, yellowflag, pinkflag, neutralflag; // current status
2886 float redflag_statuschange_elapsedtime, blueflag_statuschange_elapsedtime, yellowflag_statuschange_elapsedtime, pinkflag_statuschange_elapsedtime, neutralflag_statuschange_elapsedtime; // time since the status changed
2887 bool ctf_oneflag; // one-flag CTF mode enabled/disabled
2888 int stat_items = getstati(STAT_CTF_FLAGSTATUS, 0, 24);
2889 float fs, fs2, fs3, size1, size2;
2892 redflag = (stat_items/CTF_RED_FLAG_TAKEN) & 3;
2893 blueflag = (stat_items/CTF_BLUE_FLAG_TAKEN) & 3;
2894 yellowflag = (stat_items/CTF_YELLOW_FLAG_TAKEN) & 3;
2895 pinkflag = (stat_items/CTF_PINK_FLAG_TAKEN) & 3;
2896 neutralflag = (stat_items/CTF_NEUTRAL_FLAG_TAKEN) & 3;
2898 ctf_oneflag = (stat_items & CTF_FLAG_NEUTRAL);
2900 if(redflag || blueflag || yellowflag || pinkflag || neutralflag)
2905 if(autocvar__hud_configure)
2913 ctf_oneflag = neutralflag = 0; // disable neutral flag in hud editor?
2916 // when status CHANGES, set old status into prevstatus and current status into status
2917 if (redflag != redflag_prevframe)
2919 redflag_statuschange_time = time;
2920 redflag_prevstatus = redflag_prevframe;
2921 redflag_prevframe = redflag;
2924 if (blueflag != blueflag_prevframe)
2926 blueflag_statuschange_time = time;
2927 blueflag_prevstatus = blueflag_prevframe;
2928 blueflag_prevframe = blueflag;
2931 if (yellowflag != yellowflag_prevframe)
2933 yellowflag_statuschange_time = time;
2934 yellowflag_prevstatus = yellowflag_prevframe;
2935 yellowflag_prevframe = yellowflag;
2938 if (pinkflag != pinkflag_prevframe)
2940 pinkflag_statuschange_time = time;
2941 pinkflag_prevstatus = pinkflag_prevframe;
2942 pinkflag_prevframe = pinkflag;
2945 if (neutralflag != neutralflag_prevframe)
2947 neutralflag_statuschange_time = time;
2948 neutralflag_prevstatus = neutralflag_prevframe;
2949 neutralflag_prevframe = neutralflag;
2952 redflag_statuschange_elapsedtime = time - redflag_statuschange_time;
2953 blueflag_statuschange_elapsedtime = time - blueflag_statuschange_time;
2954 yellowflag_statuschange_elapsedtime = time - yellowflag_statuschange_time;
2955 pinkflag_statuschange_elapsedtime = time - pinkflag_statuschange_time;
2956 neutralflag_statuschange_elapsedtime = time - neutralflag_statuschange_time;
2958 const float BLINK_FACTOR = 0.15;
2959 const float BLINK_BASE = 0.85;
2961 // RMS = sqrt(BLINK_BASE^2 + 0.5 * BLINK_FACTOR^2)
2963 // BLINK_BASE = sqrt(RMS^2 - 0.5 * BLINK_FACTOR^2)
2965 const float BLINK_FREQ = 5; // circle frequency, = 2*pi*frequency in hertz
2967 string red_icon, red_icon_prevstatus;
2968 int red_alpha, red_alpha_prevstatus;
2969 red_alpha = red_alpha_prevstatus = 1;
2972 case 1: red_icon = "flag_red_taken"; break;
2973 case 2: red_icon = "flag_red_lost"; break;
2974 case 3: red_icon = "flag_red_carrying"; red_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
2976 if((stat_items & CTF_SHIELDED) && (myteam != NUM_TEAM_1))
2977 red_icon = "flag_red_shielded";
2979 red_icon = string_null;
2982 switch(redflag_prevstatus)
2984 case 1: red_icon_prevstatus = "flag_red_taken"; break;
2985 case 2: red_icon_prevstatus = "flag_red_lost"; break;
2986 case 3: red_icon_prevstatus = "flag_red_carrying"; red_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
2989 red_icon_prevstatus = "flag_red_carrying"; // make it more visible
2990 else if((stat_items & CTF_SHIELDED) && (myteam != NUM_TEAM_1))
2991 red_icon_prevstatus = "flag_red_shielded";
2993 red_icon_prevstatus = string_null;
2997 string blue_icon, blue_icon_prevstatus;
2998 int blue_alpha, blue_alpha_prevstatus;
2999 blue_alpha = blue_alpha_prevstatus = 1;
3002 case 1: blue_icon = "flag_blue_taken"; break;
3003 case 2: blue_icon = "flag_blue_lost"; break;
3004 case 3: blue_icon = "flag_blue_carrying"; blue_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3006 if((stat_items & CTF_SHIELDED) && (myteam != NUM_TEAM_2))
3007 blue_icon = "flag_blue_shielded";
3009 blue_icon = string_null;
3012 switch(blueflag_prevstatus)
3014 case 1: blue_icon_prevstatus = "flag_blue_taken"; break;
3015 case 2: blue_icon_prevstatus = "flag_blue_lost"; break;
3016 case 3: blue_icon_prevstatus = "flag_blue_carrying"; blue_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3019 blue_icon_prevstatus = "flag_blue_carrying"; // make it more visible
3020 else if((stat_items & CTF_SHIELDED) && (myteam != NUM_TEAM_2))
3021 blue_icon_prevstatus = "flag_blue_shielded";
3023 blue_icon_prevstatus = string_null;
3027 string yellow_icon, yellow_icon_prevstatus;
3028 int yellow_alpha, yellow_alpha_prevstatus;
3029 yellow_alpha = yellow_alpha_prevstatus = 1;
3032 case 1: yellow_icon = "flag_yellow_taken"; break;
3033 case 2: yellow_icon = "flag_yellow_lost"; break;
3034 case 3: yellow_icon = "flag_yellow_carrying"; yellow_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3036 if((stat_items & CTF_SHIELDED) && (myteam != NUM_TEAM_3))
3037 yellow_icon = "flag_yellow_shielded";
3039 yellow_icon = string_null;
3042 switch(yellowflag_prevstatus)
3044 case 1: yellow_icon_prevstatus = "flag_yellow_taken"; break;
3045 case 2: yellow_icon_prevstatus = "flag_yellow_lost"; break;
3046 case 3: yellow_icon_prevstatus = "flag_yellow_carrying"; yellow_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3049 yellow_icon_prevstatus = "flag_yellow_carrying"; // make it more visible
3050 else if((stat_items & CTF_SHIELDED) && (myteam != NUM_TEAM_3))
3051 yellow_icon_prevstatus = "flag_yellow_shielded";
3053 yellow_icon_prevstatus = string_null;
3057 string pink_icon, pink_icon_prevstatus;
3058 int pink_alpha, pink_alpha_prevstatus;
3059 pink_alpha = pink_alpha_prevstatus = 1;
3062 case 1: pink_icon = "flag_pink_taken"; break;
3063 case 2: pink_icon = "flag_pink_lost"; break;
3064 case 3: pink_icon = "flag_pink_carrying"; pink_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3066 if((stat_items & CTF_SHIELDED) && (myteam != NUM_TEAM_4))
3067 pink_icon = "flag_pink_shielded";
3069 pink_icon = string_null;
3072 switch(pinkflag_prevstatus)
3074 case 1: pink_icon_prevstatus = "flag_pink_taken"; break;
3075 case 2: pink_icon_prevstatus = "flag_pink_lost"; break;
3076 case 3: pink_icon_prevstatus = "flag_pink_carrying"; pink_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3079 pink_icon_prevstatus = "flag_pink_carrying"; // make it more visible
3080 else if((stat_items & CTF_SHIELDED) && (myteam != NUM_TEAM_4))
3081 pink_icon_prevstatus = "flag_pink_shielded";
3083 pink_icon_prevstatus = string_null;
3087 string neutral_icon, neutral_icon_prevstatus;
3088 int neutral_alpha, neutral_alpha_prevstatus;
3089 neutral_alpha = neutral_alpha_prevstatus = 1;
3092 case 1: neutral_icon = "flag_neutral_taken"; break;
3093 case 2: neutral_icon = "flag_neutral_lost"; break;
3094 case 3: neutral_icon = "flag_neutral_carrying"; neutral_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3096 if((stat_items & CTF_SHIELDED))
3097 neutral_icon = "flag_neutral_shielded";
3099 neutral_icon = string_null;
3102 switch(neutralflag_prevstatus)
3104 case 1: neutral_icon_prevstatus = "flag_neutral_taken"; break;
3105 case 2: neutral_icon_prevstatus = "flag_neutral_lost"; break;
3106 case 3: neutral_icon_prevstatus = "flag_neutral_carrying"; neutral_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3108 if(neutralflag == 3)
3109 neutral_icon_prevstatus = "flag_neutral_carrying"; // make it more visible
3110 else if((stat_items & CTF_SHIELDED))
3111 neutral_icon_prevstatus = "flag_neutral_shielded";
3113 neutral_icon_prevstatus = string_null;
3119 // hacky, but these aren't needed
3120 red_icon = red_icon_prevstatus = blue_icon = blue_icon_prevstatus = yellow_icon = yellow_icon_prevstatus = pink_icon = pink_icon_prevstatus = string_null;
3123 else switch(team_count)
3126 case 2: fs = 0.5; fs2 = 0.5; fs3 = 0.5; break;
3127 case 3: fs = 1; fs2 = 0.35; fs3 = 0.35; break;
3128 case 4: fs = 0.75; fs2 = 0.25; fs3 = 0.5; break;
3131 if(mySize_x > mySize_y)
3152 blueflag_pos = pos + eX * fs2 * size1;
3153 yellowflag_pos = pos - eX * fs2 * size1;
3154 pinkflag_pos = pos + eX * fs3 * size1;
3159 redflag_pos = pos + eX * fs2 * size1;
3161 yellowflag_pos = pos - eX * fs2 * size1;
3162 pinkflag_pos = pos + eX * fs3 * size1;
3167 redflag_pos = pos + eX * fs3 * size1;
3168 blueflag_pos = pos - eX * fs2 * size1;
3169 yellowflag_pos = pos;
3170 pinkflag_pos = pos + eX * fs2 * size1;
3175 redflag_pos = pos - eX * fs2 * size1;
3176 blueflag_pos = pos + eX * fs3 * size1;
3177 yellowflag_pos = pos + eX * fs2 * size1;
3182 neutralflag_pos = pos;
3183 flag_size = e1 * fs * size1 + e2 * size2;
3185 f = bound(0, redflag_statuschange_elapsedtime*2, 1);
3186 if(red_icon_prevstatus && f < 1)
3187 drawpic_aspect_skin_expanding(redflag_pos, red_icon_prevstatus, flag_size, '1 1 1', panel_fg_alpha * red_alpha_prevstatus, DRAWFLAG_NORMAL, f);
3189 drawpic_aspect_skin(redflag_pos, red_icon, flag_size, '1 1 1', panel_fg_alpha * red_alpha * f, DRAWFLAG_NORMAL);
3191 f = bound(0, blueflag_statuschange_elapsedtime*2, 1);
3192 if(blue_icon_prevstatus && f < 1)
3193 drawpic_aspect_skin_expanding(blueflag_pos, blue_icon_prevstatus, flag_size, '1 1 1', panel_fg_alpha * blue_alpha_prevstatus, DRAWFLAG_NORMAL, f);
3195 drawpic_aspect_skin(blueflag_pos, blue_icon, flag_size, '1 1 1', panel_fg_alpha * blue_alpha * f, DRAWFLAG_NORMAL);
3197 f = bound(0, yellowflag_statuschange_elapsedtime*2, 1);
3198 if(yellow_icon_prevstatus && f < 1)
3199 drawpic_aspect_skin_expanding(yellowflag_pos, yellow_icon_prevstatus, flag_size, '1 1 1', panel_fg_alpha * yellow_alpha_prevstatus, DRAWFLAG_NORMAL, f);
3201 drawpic_aspect_skin(yellowflag_pos, yellow_icon, flag_size, '1 1 1', panel_fg_alpha * yellow_alpha * f, DRAWFLAG_NORMAL);
3203 f = bound(0, pinkflag_statuschange_elapsedtime*2, 1);
3204 if(pink_icon_prevstatus && f < 1)
3205 drawpic_aspect_skin_expanding(pinkflag_pos, pink_icon_prevstatus, flag_size, '1 1 1', panel_fg_alpha * pink_alpha_prevstatus, DRAWFLAG_NORMAL, f);
3207 drawpic_aspect_skin(pinkflag_pos, pink_icon, flag_size, '1 1 1', panel_fg_alpha * pink_alpha * f, DRAWFLAG_NORMAL);
3209 f = bound(0, neutralflag_statuschange_elapsedtime*2, 1);
3210 if(neutral_icon_prevstatus && f < 1)
3211 drawpic_aspect_skin_expanding(neutralflag_pos, neutral_icon_prevstatus, flag_size, '1 1 1', panel_fg_alpha * neutral_alpha_prevstatus, DRAWFLAG_NORMAL, f);
3213 drawpic_aspect_skin(neutralflag_pos, neutral_icon, flag_size, '1 1 1', panel_fg_alpha * neutral_alpha * f, DRAWFLAG_NORMAL);
3216 // Keyhunt HUD modicon section
3219 void HUD_Mod_KH(vector pos, vector mySize)
3221 mod_active = 1; // keyhunt should never hide the mod icons panel
3223 // Read current state
3225 int state = getstati(STAT_KH_KEYS);
3227 int all_keys, team1_keys, team2_keys, team3_keys, team4_keys, dropped_keys, carrying_keys;
3228 all_keys = team1_keys = team2_keys = team3_keys = team4_keys = dropped_keys = carrying_keys = 0;
3230 for(i = 0; i < 4; ++i)
3232 key_state = (bitshift(state, i * -5) & 31) - 1;
3245 case NUM_TEAM_1: ++team1_keys; break;
3246 case NUM_TEAM_2: ++team2_keys; break;
3247 case NUM_TEAM_3: ++team3_keys; break;
3248 case NUM_TEAM_4: ++team4_keys; break;
3249 case 29: ++dropped_keys; break;
3255 // Calculate slot measurements
3259 if(all_keys == 4 && mySize.x * 0.5 < mySize.y && mySize.y * 0.5 < mySize.x)
3261 // Quadratic arrangement
3262 slot_size = eX * mySize.x * 0.5 + eY * mySize.y * 0.5;
3264 KH_SLOTS[1] = pos + eX * slot_size.x;
3265 KH_SLOTS[2] = pos + eY * slot_size.y;
3266 KH_SLOTS[3] = pos + eX * slot_size.x + eY * slot_size.y;
3270 if(mySize.x > mySize.y)
3272 // Horizontal arrangement
3273 slot_size = eX * mySize.x / all_keys + eY * mySize.y;
3274 for(i = 0; i < all_keys; ++i)
3275 KH_SLOTS[i] = pos + eX * slot_size.x * i;
3279 // Vertical arrangement
3280 slot_size = eX * mySize.x + eY * mySize.y / all_keys;
3281 for(i = 0; i < all_keys; ++i)
3282 KH_SLOTS[i] = pos + eY * slot_size.y * i;
3286 // Make icons blink in case of RUN HERE
3288 float blink = 0.6 + sin(2*M_PI*time) / 2.5; // Oscillate between 0.2 and 1
3295 case NUM_TEAM_1: if(team1_keys == all_keys) alpha = blink; break;
3296 case NUM_TEAM_2: if(team2_keys == all_keys) alpha = blink; break;
3297 case NUM_TEAM_3: if(team3_keys == all_keys) alpha = blink; break;
3298 case NUM_TEAM_4: if(team4_keys == all_keys) alpha = blink; break;
3306 if(myteam == NUM_TEAM_1 && carrying_keys)
3308 drawpic_aspect_skin(KH_SLOTS[i++], "kh_red_carrying", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3312 drawpic_aspect_skin(KH_SLOTS[i++], "kh_red_taken", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3315 if(myteam == NUM_TEAM_2 && carrying_keys)
3317 drawpic_aspect_skin(KH_SLOTS[i++], "kh_blue_carrying", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3321 drawpic_aspect_skin(KH_SLOTS[i++], "kh_blue_taken", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3324 if(myteam == NUM_TEAM_3 && carrying_keys)
3326 drawpic_aspect_skin(KH_SLOTS[i++], "kh_yellow_carrying", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3330 drawpic_aspect_skin(KH_SLOTS[i++], "kh_yellow_taken", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3333 if(myteam == NUM_TEAM_4 && carrying_keys)
3335 drawpic_aspect_skin(KH_SLOTS[i++], "kh_pink_carrying", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3339 drawpic_aspect_skin(KH_SLOTS[i++], "kh_pink_taken", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3341 while(dropped_keys--)
3342 drawpic_aspect_skin(KH_SLOTS[i++], "kh_dropped", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3345 // Keepaway HUD mod icon
3346 int kaball_prevstatus; // last remembered status
3347 float kaball_statuschange_time; // time when the status changed
3349 // we don't need to reset for keepaway since it immediately
3350 // autocorrects prevstatus as to if the player has the ball or not
3352 void HUD_Mod_Keepaway(vector pos, vector mySize)
3354 mod_active = 1; // keepaway should always show the mod HUD
3356 float BLINK_FACTOR = 0.15;
3357 float BLINK_BASE = 0.85;
3358 float BLINK_FREQ = 5;
3359 float kaball_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ);
3361 int stat_items = getstati(STAT_ITEMS, 0, 24);
3362 int kaball = (stat_items/IT_KEY1) & 1;
3364 if(kaball != kaball_prevstatus)
3366 kaball_statuschange_time = time;
3367 kaball_prevstatus = kaball;
3370 vector kaball_pos, kaball_size;
3372 if(mySize.x > mySize.y) {
3373 kaball_pos = pos + eX * 0.25 * mySize.x;
3374 kaball_size = eX * 0.5 * mySize.x + eY * mySize.y;
3376 kaball_pos = pos + eY * 0.25 * mySize.y;
3377 kaball_size = eY * 0.5 * mySize.y + eX * mySize.x;
3380 float kaball_statuschange_elapsedtime = time - kaball_statuschange_time;
3381 float f = bound(0, kaball_statuschange_elapsedtime*2, 1);
3383 if(kaball_prevstatus && f < 1)
3384 drawpic_aspect_skin_expanding(kaball_pos, "keepawayball_carrying", kaball_size, '1 1 1', panel_fg_alpha * kaball_alpha, DRAWFLAG_NORMAL, f);
3387 drawpic_aspect_skin(pos, "keepawayball_carrying", eX * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha * kaball_alpha * f, DRAWFLAG_NORMAL);
3391 // Nexball HUD mod icon
3392 void HUD_Mod_NexBall(vector pos, vector mySize)
3394 float nb_pb_starttime, dt, p;
3397 stat_items = getstati(STAT_ITEMS, 0, 24);
3398 nb_pb_starttime = getstatf(STAT_NB_METERSTART);
3400 if (stat_items & IT_KEY1)
3405 //Manage the progress bar if any
3406 if (nb_pb_starttime > 0)
3408 dt = (time - nb_pb_starttime) % nb_pb_period;
3409 // one period of positive triangle
3410 p = 2 * dt / nb_pb_period;
3414 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);
3417 if (stat_items & IT_KEY1)
3418 drawpic_aspect_skin(pos, "nexball_carrying", eX * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3421 // Race/CTS HUD mod icons
3422 float crecordtime_prev; // last remembered crecordtime
3423 float crecordtime_change_time; // time when crecordtime last changed
3424 float srecordtime_prev; // last remembered srecordtime
3425 float srecordtime_change_time; // time when srecordtime last changed
3427 float race_status_time;
3428 int race_status_prev;
3429 string race_status_name_prev;
3430 void HUD_Mod_Race(vector pos, vector mySize)
3432 mod_active = 1; // race should never hide the mod icons panel
3434 me = playerslots[player_localnum];
3436 float f; // yet another function has this
3437 score = me.(scores[ps_primary]);
3439 if(!(scores_flags[ps_primary] & SFL_TIME) || teamplay) // race/cts record display on HUD
3440 return; // no records in the actual race
3442 // clientside personal record
3444 if(gametype == MAPINFO_TYPE_CTS)
3448 t = stof(db_get(ClientProgsDB, strcat(shortmapname, rr, "time")));
3450 if(score && (score < t || !t)) {
3451 db_put(ClientProgsDB, strcat(shortmapname, rr, "time"), ftos(score));
3452 if(autocvar_cl_autodemo_delete_keeprecords)
3454 f = autocvar_cl_autodemo_delete;
3456 cvar_set("cl_autodemo_delete", ftos(f)); // don't delete demo with new record!
3460 if(t != crecordtime_prev) {
3461 crecordtime_prev = t;
3462 crecordtime_change_time = time;
3465 vector textPos, medalPos;
3467 if(mySize.x > mySize.y) {
3468 // text on left side
3469 squareSize = min(mySize.y, mySize.x/2);
3470 textPos = pos + eX * 0.5 * max(0, mySize.x/2 - squareSize) + eY * 0.5 * (mySize.y - squareSize);
3471 medalPos = pos + eX * 0.5 * max(0, mySize.x/2 - squareSize) + eX * 0.5 * mySize.x + eY * 0.5 * (mySize.y - squareSize);
3474 squareSize = min(mySize.x, mySize.y/2);
3475 textPos = pos + eY * 0.5 * max(0, mySize.y/2 - squareSize) + eX * 0.5 * (mySize.x - squareSize);
3476 medalPos = pos + eY * 0.5 * max(0, mySize.y/2 - squareSize) + eY * 0.5 * mySize.y + eX * 0.5 * (mySize.x - squareSize);
3479 f = time - crecordtime_change_time;
3482 drawstring_aspect(textPos, _("Personal best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3483 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);
3485 drawstring_aspect(textPos, _("Personal best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3486 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);
3487 drawstring_aspect_expanding(pos, _("Personal best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
3488 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);
3492 t = race_server_record;
3493 if(t != srecordtime_prev) {
3494 srecordtime_prev = t;
3495 srecordtime_change_time = time;
3497 f = time - srecordtime_change_time;
3500 drawstring_aspect(textPos + eY * 0.5 * squareSize, _("Server best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3501 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);
3503 drawstring_aspect(textPos + eY * 0.5 * squareSize, _("Server best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3504 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);
3505 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);
3506 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);
3509 if (race_status != race_status_prev || race_status_name != race_status_name_prev) {
3510 race_status_time = time + 5;
3511 race_status_prev = race_status;
3512 if (race_status_name_prev)
3513 strunzone(race_status_name_prev);
3514 race_status_name_prev = strzone(race_status_name);
3519 a = bound(0, race_status_time - time, 1);
3522 s = textShortenToWidth(race_status_name, squareSize, '1 1 0' * 0.1 * squareSize, stringwidth_colors);
3526 rank = race_CheckName(race_status_name);
3530 rankname = count_ordinal(rank);
3533 namepos = medalPos + '0 0.8 0' * squareSize;
3535 rankpos = medalPos + '0 0.15 0' * squareSize;
3537 if(race_status == 0)
3538 drawpic_aspect_skin(medalPos, "race_newfail", '1 1 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3539 else if(race_status == 1) {
3540 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);
3541 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3542 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3543 } else if(race_status == 2) {
3544 if(race_status_name == GetPlayerName(player_localnum) || !race_myrank || race_myrank < rank)
3545 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);
3547 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);
3548 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3549 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3550 } else if(race_status == 3) {
3551 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);
3552 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3553 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3556 if (race_status_time - time <= 0) {
3557 race_status_prev = -1;
3559 if(race_status_name)
3560 strunzone(race_status_name);
3561 race_status_name = string_null;
3562 if(race_status_name_prev)
3563 strunzone(race_status_name_prev);
3564 race_status_name_prev = string_null;
3568 void DrawDomItem(vector myPos, vector mySize, float aspect_ratio, int layout, int i)
3572 vector color = '0 0 0';
3576 stat = getstatf(STAT_DOM_PPS_RED);
3577 pic = "dom_icon_red";
3581 stat = getstatf(STAT_DOM_PPS_BLUE);
3582 pic = "dom_icon_blue";
3586 stat = getstatf(STAT_DOM_PPS_YELLOW);
3587 pic = "dom_icon_yellow";
3592 stat = getstatf(STAT_DOM_PPS_PINK);
3593 pic = "dom_icon_pink";
3597 float pps_ratio = stat / getstatf(STAT_DOM_TOTAL_PPS);
3599 if(mySize.x/mySize.y > aspect_ratio)
3601 i = aspect_ratio * mySize.y;
3602 myPos.x = myPos.x + (mySize.x - i) / 2;
3607 i = 1/aspect_ratio * mySize.x;
3608 myPos.y = myPos.y + (mySize.y - i) / 2;
3612 if (layout) // show text too
3615 color *= 0.5 + pps_ratio * (1 - 0.5); // half saturated color at min, full saturated at max
3616 if (layout == 2) // average pps
3617 drawstring_aspect(myPos + eX * mySize.y, ftos_decimals(stat, 2), eX * (2/3) * mySize.x + eY * mySize.y, color, panel_fg_alpha, DRAWFLAG_NORMAL);
3618 else // percentage of average pps
3619 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);
3623 drawpic_aspect_skin(myPos, pic, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3626 drawsetcliparea(myPos.x, myPos.y + mySize.y * (1 - pps_ratio), mySize.y, mySize.y * pps_ratio);
3627 drawpic_aspect_skin(myPos, strcat(pic, "-highlighted"), '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3628 drawresetcliparea();
3632 void HUD_Mod_Dom(vector myPos, vector mySize)
3634 mod_active = 1; // required in each mod function that always shows something
3636 int layout = autocvar_hud_panel_modicons_dom_layout;
3639 aspect_ratio = (layout) ? 3 : 1;
3640 rows = HUD_GetRowCount(team_count, mySize, aspect_ratio);
3641 columns = ceil(team_count/rows);
3644 float row = 0, column = 0;
3645 vector pos, itemSize;
3646 itemSize = eX * mySize.x*(1/columns) + eY * mySize.y*(1/rows);
3647 for(i=0; i<team_count; ++i)
3649 pos = myPos + eX * column * itemSize.x + eY * row * itemSize.y;
3651 DrawDomItem(pos, itemSize, aspect_ratio, layout, i);
3662 void HUD_ModIcons_SetFunc()
3666 case MAPINFO_TYPE_KEYHUNT: HUD_ModIcons_GameType = HUD_Mod_KH; break;
3667 case MAPINFO_TYPE_CTF: HUD_ModIcons_GameType = HUD_Mod_CTF; break;
3668 case MAPINFO_TYPE_NEXBALL: HUD_ModIcons_GameType = HUD_Mod_NexBall; break;
3669 case MAPINFO_TYPE_CTS:
3670 case MAPINFO_TYPE_RACE: HUD_ModIcons_GameType = HUD_Mod_Race; break;
3671 case MAPINFO_TYPE_CA:
3672 case MAPINFO_TYPE_FREEZETAG: HUD_ModIcons_GameType = HUD_Mod_CA; break;
3673 case MAPINFO_TYPE_DOMINATION: HUD_ModIcons_GameType = HUD_Mod_Dom; break;
3674 case MAPINFO_TYPE_KEEPAWAY: HUD_ModIcons_GameType = HUD_Mod_Keepaway; break;
3678 int mod_prev; // previous state of mod_active to check for a change
3680 float mod_change; // "time" when mod_active changed
3682 void HUD_ModIcons(void)
3684 if(!autocvar__hud_configure)
3686 if(!autocvar_hud_panel_modicons) return;
3687 if(!HUD_ModIcons_GameType) return;
3690 HUD_Panel_UpdateCvars();
3692 draw_beginBoldFont();
3694 if(mod_active != mod_prev) {
3696 mod_prev = mod_active;
3699 if(mod_active || autocvar__hud_configure)
3700 mod_alpha = bound(0, (time - mod_change) * 2, 1);
3702 mod_alpha = bound(0, 1 - (time - mod_change) * 2, 1);
3705 HUD_Panel_DrawBg(mod_alpha);
3707 if(panel_bg_padding)
3709 panel_pos += '1 1 0' * panel_bg_padding;
3710 panel_size -= '2 2 0' * panel_bg_padding;
3713 if(autocvar__hud_configure)
3714 HUD_Mod_CTF(panel_pos, panel_size);
3716 HUD_ModIcons_GameType(panel_pos, panel_size);
3721 // Draw pressed keys (#11)
3723 void HUD_PressedKeys(void)
3725 if(!autocvar__hud_configure)
3727 if(!autocvar_hud_panel_pressedkeys) return;
3728 if(spectatee_status <= 0 && autocvar_hud_panel_pressedkeys < 2) return;
3731 HUD_Panel_UpdateCvars();
3734 mySize = panel_size;
3736 HUD_Panel_DrawBg(1);
3737 if(panel_bg_padding)
3739 pos += '1 1 0' * panel_bg_padding;
3740 mySize -= '2 2 0' * panel_bg_padding;
3743 // force custom aspect
3744 float aspect = autocvar_hud_panel_pressedkeys_aspect;
3747 vector newSize = '0 0 0';
3748 if(mySize.x/mySize.y > aspect)
3750 newSize.x = aspect * mySize.y;
3751 newSize.y = mySize.y;
3753 pos.x = pos.x + (mySize.x - newSize.x) / 2;
3757 newSize.y = 1/aspect * mySize.x;
3758 newSize.x = mySize.x;
3760 pos.y = pos.y + (mySize.y - newSize.y) / 2;
3766 keysize = eX * mySize.x * (1/3.0) + eY * mySize.y * (1/(3.0 - !autocvar_hud_panel_pressedkeys_attack));
3768 pressedkeys = getstatf(STAT_PRESSED_KEYS);
3770 if(autocvar_hud_panel_pressedkeys_attack)
3772 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);
3773 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);
3777 drawpic_aspect_skin(pos, ((pressedkeys & KEY_CROUCH) ? "key_crouch_inv.tga" : "key_crouch.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3778 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);
3779 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);
3781 drawpic_aspect_skin(pos, ((pressedkeys & KEY_LEFT) ? "key_left_inv.tga" : "key_left.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3782 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);
3783 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);
3786 // Handle chat as a panel (#12)
3790 if(!autocvar__hud_configure)
3792 if (!autocvar_hud_panel_chat)
3794 if (!autocvar_con_chatrect)
3795 cvar_set("con_chatrect", "0");
3798 if(autocvar__con_chat_maximized)
3800 if(!hud_draw_maximized) return;
3802 else if(chat_panel_modified)
3804 panel.update_time = time; // forces reload of panel attributes
3805 chat_panel_modified = false;
3809 HUD_Panel_UpdateCvars();
3811 if(autocvar__con_chat_maximized && !autocvar__hud_configure) // draw at full screen height if maximized
3813 panel_pos.y = panel_bg_border;
3814 panel_size.y = vid_conheight - panel_bg_border * 2;
3815 if(panel.current_panel_bg == "0") // force a border when maximized
3818 panel_bg = strcat(hud_skin_path, "/border_default");
3819 if(precache_pic(panel_bg) == "")
3820 panel_bg = "gfx/hud/default/border_default";
3821 if(panel.current_panel_bg)
3822 strunzone(panel.current_panel_bg);
3823 panel.current_panel_bg = strzone(panel_bg);
3824 chat_panel_modified = true;
3826 panel_bg_alpha = max(0.75, panel_bg_alpha); // force an theAlpha of at least 0.75
3831 mySize = panel_size;
3833 HUD_Panel_DrawBg(1);
3835 if(panel_bg_padding)
3837 pos += '1 1 0' * panel_bg_padding;
3838 mySize -= '2 2 0' * panel_bg_padding;
3841 if (!autocvar_con_chatrect)
3842 cvar_set("con_chatrect", "1");
3844 cvar_set("con_chatrect_x", ftos(pos.x/vid_conwidth));
3845 cvar_set("con_chatrect_y", ftos(pos.y/vid_conheight));
3847 cvar_set("con_chatwidth", ftos(mySize.x/vid_conwidth));
3848 cvar_set("con_chat", ftos(floor(mySize.y/autocvar_con_chatsize - 0.5)));
3850 if(autocvar__hud_configure)
3853 chatsize = '1 1 0' * autocvar_con_chatsize;
3854 cvar_set("con_chatrect_x", "9001"); // over 9000, we'll fake it instead for more control over theAlpha and such
3856 for(i = 0; i < autocvar_con_chat; ++i)
3858 if(i == autocvar_con_chat - 1)
3861 a = panel_fg_alpha * floor(((i + 1) * 7 + autocvar_con_chattime)/45);
3862 drawcolorcodedstring(pos, textShortenToWidth(_("^3Player^7: This is the chat area."), mySize.x, chatsize, stringwidth_colors), chatsize, a, DRAWFLAG_NORMAL);
3863 pos.y += chatsize.y;
3868 // Engine info panel (#13)
3875 float frametimeavg1; // 1 frame ago
3876 float frametimeavg2; // 2 frames ago
3877 void HUD_EngineInfo(void)
3879 if(!autocvar__hud_configure)
3881 if(!autocvar_hud_panel_engineinfo) return;
3884 HUD_Panel_UpdateCvars();
3887 mySize = panel_size;
3889 HUD_Panel_DrawBg(1);
3890 if(panel_bg_padding)
3892 pos += '1 1 0' * panel_bg_padding;
3893 mySize -= '2 2 0' * panel_bg_padding;
3896 float currentTime = gettime(GETTIME_REALTIME);
3897 if(cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage"))
3899 float currentframetime = currentTime - prevfps_time;
3900 frametimeavg = (frametimeavg + frametimeavg1 + frametimeavg2 + currentframetime)/4; // average three frametimes into framecounter for slightly more stable fps readings :P
3901 frametimeavg2 = frametimeavg1;
3902 frametimeavg1 = frametimeavg;
3905 weight = cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage_new_weight");
3906 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.
3908 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
3909 prevfps = (1/currentframetime);
3910 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"
3912 prevfps_time = currentTime;
3917 if(currentTime - prevfps_time > autocvar_hud_panel_engineinfo_framecounter_time)
3919 prevfps = framecounter/(currentTime - prevfps_time);
3921 prevfps_time = currentTime;
3926 color = HUD_Get_Num_Color (prevfps, 100);
3927 drawstring_aspect(pos, sprintf(_("FPS: %.*f"), autocvar_hud_panel_engineinfo_framecounter_decimals, prevfps), mySize, color, panel_fg_alpha, DRAWFLAG_NORMAL);
3930 // Info messages panel (#14)
3932 #define drawInfoMessage(s) do { \
3933 if(autocvar_hud_panel_infomessages_flip) \
3934 o.x = pos.x + mySize.x - stringwidth(s, true, fontsize); \
3935 drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL); \
3936 o.y += fontsize.y; \
3938 void HUD_InfoMessages(void)
3940 if(!autocvar__hud_configure)
3942 if(!autocvar_hud_panel_infomessages) return;
3945 HUD_Panel_UpdateCvars();
3948 mySize = panel_size;
3950 HUD_Panel_DrawBg(1);
3951 if(panel_bg_padding)
3953 pos += '1 1 0' * panel_bg_padding;
3954 mySize -= '2 2 0' * panel_bg_padding;
3957 // always force 5:1 aspect
3958 vector newSize = '0 0 0';
3959 if(mySize.x/mySize.y > 5)
3961 newSize.x = 5 * mySize.y;
3962 newSize.y = mySize.y;
3964 pos.x = pos.x + (mySize.x - newSize.x) / 2;
3968 newSize.y = 1/5 * mySize.x;
3969 newSize.x = mySize.x;
3971 pos.y = pos.y + (mySize.y - newSize.y) / 2;
3980 fontsize = '0.20 0.20 0' * mySize.y;
3986 if(!autocvar__hud_configure)
3988 if(spectatee_status && !intermission)
3991 if(spectatee_status == -1)
3992 s = _("^1Observing");
3994 s = sprintf(_("^1Spectating: ^7%s"), GetPlayerName(player_localentnum - 1));
3997 if(spectatee_status == -1)
3998 s = sprintf(_("^1Press ^3%s^1 to spectate"), getcommandkey("primary fire", "+fire"));
4000 s = sprintf(_("^1Press ^3%s^1 or ^3%s^1 for next or previous player"), getcommandkey("next weapon", "weapnext"), getcommandkey("previous weapon", "weapprev"));
4003 if(spectatee_status == -1)
4004 s = sprintf(_("^1Use ^3%s^1 or ^3%s^1 to change the speed"), getcommandkey("next weapon", "weapnext"), getcommandkey("previous weapon", "weapprev"));
4006 s = sprintf(_("^1Press ^3%s^1 to observe"), getcommandkey("secondary fire", "+fire2"));
4009 s = sprintf(_("^1Press ^3%s^1 for gamemode info"), getcommandkey("server info", "+show_info"));
4012 if(gametype == MAPINFO_TYPE_LMS)
4015 sk = playerslots[player_localnum];
4016 if(sk.(scores[ps_primary]) >= 666)
4017 s = _("^1Match has already begun");
4018 else if(sk.(scores[ps_primary]) > 0)
4019 s = _("^1You have no more lives left");
4021 s = sprintf(_("^1Press ^3%s^1 to join"), getcommandkey("jump", "+jump"));
4024 s = sprintf(_("^1Press ^3%s^1 to join"), getcommandkey("jump", "+jump"));
4027 //show restart countdown:
4028 if (time < getstatf(STAT_GAMESTARTTIME)) {
4030 //we need to ceil, otherwise the countdown would be off by .5 when using round()
4031 countdown = ceil(getstatf(STAT_GAMESTARTTIME) - time);
4032 s = sprintf(_("^1Game starts in ^3%d^1 seconds"), countdown);
4033 drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
4037 if(warmup_stage && !intermission)
4039 s = _("^2Currently in ^1warmup^2 stage!");
4049 if(ready_waiting && !intermission && !spectatee_status)
4051 if(ready_waiting_for_me)
4054 s = sprintf(_("%sPress ^3%s%s to end warmup"), blinkcolor, getcommandkey("ready", "ready"), blinkcolor);
4056 s = sprintf(_("%sPress ^3%s%s once you are ready"), blinkcolor, getcommandkey("ready", "ready"), blinkcolor);
4061 s = _("^2Waiting for others to ready up to end warmup...");
4063 s = _("^2Waiting for others to ready up...");
4067 else if(warmup_stage && !intermission && !spectatee_status)
4069 s = sprintf(_("^2Press ^3%s^2 to end warmup"), getcommandkey("ready", "ready"));
4073 if(teamplay && !intermission && !spectatee_status && gametype != MAPINFO_TYPE_CA && teamnagger)
4075 float ts_min = 0, ts_max = 0;
4076 tm = teams.sort_next;
4079 for (; tm.sort_next; tm = tm.sort_next)
4081 if(!tm.team_size || tm.team == NUM_SPECTATOR)
4083 if(!ts_min) ts_min = tm.team_size;
4084 else ts_min = min(ts_min, tm.team_size);
4085 if(!ts_max) ts_max = tm.team_size;
4086 else ts_max = max(ts_max, tm.team_size);
4088 if ((ts_max - ts_min) > 1)
4090 s = strcat(blinkcolor, _("Teamnumbers are unbalanced!"));
4091 tm = GetTeam(myteam, false);
4093 if (tm.team != NUM_SPECTATOR)
4094 if (tm.team_size == ts_max)
4095 s = strcat(s, sprintf(_(" Press ^3%s%s to adjust"), getcommandkey("team menu", "menu_showteamselect"), blinkcolor));
4103 s = _("^7Press ^3ESC ^7to show HUD options.");
4105 s = _("^3Doubleclick ^7a panel for panel-specific options.");
4107 s = _("^3CTRL ^7to disable collision testing, ^3SHIFT ^7and");
4109 s = _("^3ALT ^7+ ^3ARROW KEYS ^7for fine adjustments.");
4114 // Physics panel (#15)
4116 vector acc_prevspeed;
4117 float acc_prevtime, acc_avg, top_speed, top_speed_time;
4118 void HUD_Physics(void)
4120 if(!autocvar__hud_configure)
4122 if(!autocvar_hud_panel_physics) return;
4123 if(spectatee_status == -1 && (autocvar_hud_panel_physics == 1 || autocvar_hud_panel_physics == 3)) return;
4124 if(autocvar_hud_panel_physics == 3 && !(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return;
4127 HUD_Panel_UpdateCvars();
4129 draw_beginBoldFont();
4131 HUD_Panel_DrawBg(1);
4132 if(panel_bg_padding)
4134 panel_pos += '1 1 0' * panel_bg_padding;
4135 panel_size -= '2 2 0' * panel_bg_padding;
4138 float acceleration_progressbar_scale = 0;
4139 if(autocvar_hud_panel_physics_progressbar && autocvar_hud_panel_physics_acceleration_progressbar_scale > 1)
4140 acceleration_progressbar_scale = autocvar_hud_panel_physics_acceleration_progressbar_scale;
4143 if (autocvar_hud_panel_physics_text_scale <= 0)
4146 text_scale = min(autocvar_hud_panel_physics_text_scale, 1);
4149 float speed, conversion_factor;
4152 switch(autocvar_hud_panel_physics_speed_unit)
4157 conversion_factor = 1.0;
4161 conversion_factor = 0.0254;
4165 conversion_factor = 0.0254 * 3.6;
4169 conversion_factor = 0.0254 * 3.6 * 0.6213711922;
4173 conversion_factor = 0.0254 * 1.943844492; // 1 m/s = 1.943844492 knots, because 1 knot = 1.852 km/h
4177 vector vel = (csqcplayer ? csqcplayer.velocity : pmove_vel);
4179 float max_speed = floor( autocvar_hud_panel_physics_speed_max * conversion_factor + 0.5 );
4180 if (autocvar__hud_configure)
4181 speed = floor( max_speed * 0.65 + 0.5 );
4182 else if(autocvar_hud_panel_physics_speed_vertical)
4183 speed = floor( vlen(vel) * conversion_factor + 0.5 );
4185 speed = floor( vlen(vel - vel.z * '0 0 1') * conversion_factor + 0.5 );
4187 //compute acceleration
4188 float acceleration, f;
4189 if (autocvar__hud_configure)
4190 acceleration = autocvar_hud_panel_physics_acceleration_max * 0.3;
4193 // 1 m/s = 0.0254 qu/s; 1 g = 9.80665 m/s^2
4194 f = time - acc_prevtime;
4195 if(autocvar_hud_panel_physics_acceleration_vertical)
4196 acceleration = (vlen(vel) - vlen(acc_prevspeed));
4198 acceleration = (vlen(vel - '0 0 1' * vel.z) - vlen(acc_prevspeed - '0 0 1' * acc_prevspeed.z));
4200 acceleration = acceleration * (1 / max(0.0001, f)) * (0.0254 / 9.80665);
4202 acc_prevspeed = vel;
4203 acc_prevtime = time;
4205 f = bound(0, f * 10, 1);
4206 acc_avg = acc_avg * (1 - f) + acceleration * f;
4210 float panel_ar = panel_size.x/panel_size.y;
4211 vector speed_offset = '0 0 0', acceleration_offset = '0 0 0';
4212 if (panel_ar >= 5 && !acceleration_progressbar_scale)
4214 panel_size.x *= 0.5;
4215 if (autocvar_hud_panel_physics_flip)
4216 speed_offset.x = panel_size.x;
4218 acceleration_offset.x = panel_size.x;
4222 panel_size.y *= 0.5;
4223 if (autocvar_hud_panel_physics_flip)
4224 speed_offset.y = panel_size.y;
4226 acceleration_offset.y = panel_size.y;
4228 int speed_baralign, acceleration_baralign;
4229 if (autocvar_hud_panel_physics_baralign == 1)
4230 acceleration_baralign = speed_baralign = 1;
4231 else if(autocvar_hud_panel_physics_baralign == 4)
4232 acceleration_baralign = speed_baralign = 2;
4233 else if (autocvar_hud_panel_physics_flip)
4235 acceleration_baralign = (autocvar_hud_panel_physics_baralign == 2);
4236 speed_baralign = (autocvar_hud_panel_physics_baralign == 3);
4240 speed_baralign = (autocvar_hud_panel_physics_baralign == 2);
4241 acceleration_baralign = (autocvar_hud_panel_physics_baralign == 3);
4243 if (autocvar_hud_panel_physics_acceleration_progressbar_mode == 0)
4244 acceleration_baralign = 3; //override hud_panel_physics_baralign value for acceleration
4248 if(autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 2)
4249 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);
4250 vector tmp_offset = '0 0 0', tmp_size = '0 0 0';
4251 if (autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 2)
4253 tmp_size.x = panel_size.x * 0.75;
4254 tmp_size.y = panel_size.y * text_scale;
4256 tmp_offset.x = panel_size.x - tmp_size.x;
4259 tmp_offset.y = (panel_size.y - tmp_size.y) / 2;
4260 drawstring_aspect(panel_pos + speed_offset + tmp_offset, ftos(speed), tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4266 tmp_offset.x = tmp_size.x;
4267 if (autocvar_hud_panel_physics_speed_unit_show)
4270 tmp_size.x = panel_size.x * (1 - 0.75);
4271 tmp_size.y = panel_size.y * 0.4 * text_scale;
4272 tmp_offset.y = (panel_size.y * 0.4 - tmp_size.y) / 2;
4273 drawstring_aspect(panel_pos + speed_offset + tmp_offset, unit, tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4277 //compute and draw top speed
4278 if (autocvar_hud_panel_physics_topspeed)
4279 if (autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 2)
4281 if (autocvar__hud_configure)
4283 top_speed = floor( max_speed * 0.75 + 0.5 );
4288 if (speed >= top_speed)
4291 top_speed_time = time;
4295 f = max(1, autocvar_hud_panel_physics_topspeed_time);
4296 // divide by f to make it start from 1
4297 f = cos( ((time - top_speed_time) / f) * PI/2 );
4299 else //hide top speed 0, it would be stupid
4304 //top speed progressbar peak
4305 if(speed < top_speed)
4306 if(autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 2)
4309 vector peak_size = '0 0 0';
4310 if (speed_baralign == 0)
4311 peak_offsetX = min(top_speed, max_speed)/max_speed * panel_size.x;
4312 else if (speed_baralign == 1)
4313 peak_offsetX = (1 - min(top_speed, max_speed)/max_speed) * panel_size.x;
4314 else // if (speed_baralign == 2)
4315 peak_offsetX = min(top_speed, max_speed)/max_speed * panel_size.x * 0.5;
4316 peak_size.x = floor(panel_size.x * 0.01 + 1.5);
4317 peak_size.y = panel_size.y;
4318 if (speed_baralign == 2) // draw two peaks, on both sides
4320 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);
4321 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);
4324 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);
4328 tmp_offset.y = panel_size.y * 0.4;
4329 tmp_size.x = panel_size.x * (1 - 0.75);
4330 tmp_size.y = (panel_size.y - tmp_offset.y) * text_scale;
4331 tmp_offset.y += (panel_size.y - tmp_offset.y - tmp_size.y) / 2;
4332 drawstring_aspect(panel_pos + speed_offset + tmp_offset, ftos(top_speed), tmp_size, '1 0 0', f * panel_fg_alpha, DRAWFLAG_NORMAL);
4340 if(autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 3)
4342 vector progressbar_color;
4343 if(acceleration < 0)
4344 progressbar_color = autocvar_hud_progressbar_acceleration_neg_color;
4346 progressbar_color = autocvar_hud_progressbar_acceleration_color;
4348 f = acceleration/autocvar_hud_panel_physics_acceleration_max;
4349 if (autocvar_hud_panel_physics_acceleration_progressbar_nonlinear)
4352 if (acceleration_progressbar_scale) // allow progressbar to go out of panel bounds
4354 tmp_size = acceleration_progressbar_scale * panel_size.x * eX + panel_size.y * eY;
4356 if (acceleration_baralign == 1)
4357 tmp_offset.x = panel_size.x - tmp_size.x;
4358 else if (acceleration_baralign == 2 || acceleration_baralign == 3)
4359 tmp_offset.x = (panel_size.x - tmp_size.x) / 2;
4366 tmp_size = panel_size;
4367 tmp_offset = '0 0 0';
4370 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);
4372 tmp_size.x = panel_size.x;
4373 tmp_size.y = panel_size.y * text_scale;
4375 tmp_offset.y = (panel_size.y - tmp_size.y) / 2;
4376 if (autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 3)
4377 drawstring_aspect(panel_pos + acceleration_offset + tmp_offset, strcat(ftos_decimals(acceleration, 2), "g"), tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4382 // CenterPrint (#16)
4384 const int CENTERPRINT_MAX_MSGS = 10;
4385 const int CENTERPRINT_MAX_ENTRIES = 50;
4386 const float CENTERPRINT_SPACING = 0.7;
4388 string centerprint_messages[CENTERPRINT_MAX_MSGS];
4389 int centerprint_msgID[CENTERPRINT_MAX_MSGS];
4390 float centerprint_time[CENTERPRINT_MAX_MSGS];
4391 float centerprint_expire_time[CENTERPRINT_MAX_MSGS];
4392 int centerprint_countdown_num[CENTERPRINT_MAX_MSGS];
4393 bool centerprint_showing;
4395 void centerprint_generic(int new_id, string strMessage, float duration, int countdown_num)
4397 //printf("centerprint_generic(%d, '%s^7', %d, %d);\n", new_id, strMessage, duration, countdown_num);
4400 if(strMessage == "" && new_id == 0)
4403 // strip trailing newlines
4404 j = strlen(strMessage) - 1;
4405 while(substring(strMessage, j, 1) == "\n" && j >= 0)
4407 if (j < strlen(strMessage) - 1)
4408 strMessage = substring(strMessage, 0, j + 1);
4410 if(strMessage == "" && new_id == 0)
4413 // strip leading newlines
4415 while(substring(strMessage, j, 1) == "\n" && j < strlen(strMessage))
4418 strMessage = substring(strMessage, j, strlen(strMessage) - j);
4420 if(strMessage == "" && new_id == 0)
4423 if (!centerprint_showing)
4424 centerprint_showing = true;
4426 for (i=0, j=cpm_index; i<CENTERPRINT_MAX_MSGS; ++i, ++j)
4428 if (j == CENTERPRINT_MAX_MSGS)
4430 if (new_id && new_id == centerprint_msgID[j])
4432 if (strMessage == "" && centerprint_messages[j] != "" && centerprint_countdown_num[j] == 0)
4434 // fade out the current msg (duration and countdown_num are ignored)
4435 centerprint_time[j] = min(5, autocvar_hud_panel_centerprint_fade_out);
4436 if (centerprint_expire_time[j] > time + min(5, autocvar_hud_panel_centerprint_fade_out) || centerprint_expire_time[j] < time)
4437 centerprint_expire_time[j] = time + min(5, autocvar_hud_panel_centerprint_fade_out);
4440 break; // found a msg with the same id, at position j
4444 if (i == CENTERPRINT_MAX_MSGS)
4446 // a msg with the same id was not found, add the msg at the next position
4448 if (cpm_index == -1)
4449 cpm_index = CENTERPRINT_MAX_MSGS - 1;
4452 if(centerprint_messages[j])
4453 strunzone(centerprint_messages[j]);
4454 centerprint_messages[j] = strzone(strMessage);
4455 centerprint_msgID[j] = new_id;
4458 centerprint_time[j] = -1;
4459 centerprint_expire_time[j] = time;
4464 duration = max(1, autocvar_hud_panel_centerprint_time);
4465 centerprint_time[j] = duration;
4466 centerprint_expire_time[j] = time + duration;
4468 centerprint_countdown_num[j] = countdown_num;
4471 void centerprint_hud(string strMessage)
4473 centerprint_generic(0, strMessage, autocvar_hud_panel_centerprint_time, 0);
4476 void reset_centerprint_messages(void)
4479 for (i=0; i<CENTERPRINT_MAX_MSGS; ++i)
4481 centerprint_expire_time[i] = 0;
4482 centerprint_time[i] = 1;
4483 centerprint_msgID[i] = 0;
4484 if(centerprint_messages[i])
4485 strunzone(centerprint_messages[i]);
4486 centerprint_messages[i] = string_null;
4489 float hud_configure_cp_generation_time;
4490 void HUD_CenterPrint (void)
4492 if(!autocvar__hud_configure)
4494 if(!autocvar_hud_panel_centerprint) return;
4496 if(hud_configure_prev)
4497 reset_centerprint_messages();
4501 if(!hud_configure_prev)
4502 reset_centerprint_messages();
4503 if (time > hud_configure_cp_generation_time)
4508 centerprint_generic(floor(r*1000), strcat(sprintf("^3Countdown message at time %s", seconds_tostring(time)), ", seconds left: ^COUNT"), 1, 10);
4510 centerprint_generic(0, sprintf("^1Multiline message at time %s that\n^1lasts longer than normal", seconds_tostring(time)), 20, 0);
4512 centerprint_hud(sprintf("Message at time %s", seconds_tostring(time)));
4513 hud_configure_cp_generation_time = time + 1 + random()*4;
4517 // this panel fades only when the menu does
4518 float hud_fade_alpha_save = 0;
4519 if(scoreboard_fade_alpha)
4521 hud_fade_alpha_save = hud_fade_alpha;
4522 hud_fade_alpha = 1 - autocvar__menu_alpha;
4524 HUD_Panel_UpdateCvars();
4526 if(scoreboard_fade_alpha)
4528 hud_fade_alpha = hud_fade_alpha_save;
4530 // move the panel below the scoreboard
4531 if (scoreboard_bottom >= 0.96 * vid_conheight)
4535 target_pos = eY * scoreboard_bottom + eX * 0.5 * (vid_conwidth - panel_size.x);
4537 if(target_pos.y > panel_pos.y)
4539 panel_pos = panel_pos + (target_pos - panel_pos) * sqrt(scoreboard_fade_alpha);
4540 panel_size.y = min(panel_size.y, vid_conheight - scoreboard_bottom);
4544 HUD_Panel_DrawBg(1);
4546 if (!centerprint_showing)
4549 if(panel_bg_padding)
4551 panel_pos += '1 1 0' * panel_bg_padding;
4552 panel_size -= '2 2 0' * panel_bg_padding;
4558 // entries = bound(1, floor(CENTERPRINT_MAX_ENTRIES * 4 * panel_size_y/panel_size_x), CENTERPRINT_MAX_ENTRIES);
4559 // height = panel_size_y/entries;
4560 // fontsize = '1 1 0' * height;
4561 height = vid_conheight/50 * autocvar_hud_panel_centerprint_fontscale;
4562 fontsize = '1 1 0' * height;
4563 entries = bound(1, floor(panel_size.y/height), CENTERPRINT_MAX_ENTRIES);
4566 float a, sz, align, current_msg_posY = 0, msg_size;
4569 bool all_messages_expired = true;
4572 if (autocvar_hud_panel_centerprint_flip)
4573 pos.y += panel_size.y;
4574 align = bound(0, autocvar_hud_panel_centerprint_align, 1);
4575 for (g=0, i=0, j=cpm_index; i<CENTERPRINT_MAX_MSGS; ++i, ++j)
4577 if (j == CENTERPRINT_MAX_MSGS)
4579 if (centerprint_expire_time[j] <= time)
4581 if (centerprint_countdown_num[j] && centerprint_time[j] > 0)
4583 centerprint_countdown_num[j] = centerprint_countdown_num[j] - 1;
4584 if (centerprint_countdown_num[j] == 0)
4586 centerprint_expire_time[j] = centerprint_expire_time[j] + centerprint_time[j];
4588 else if(centerprint_time[j] != -1)
4592 all_messages_expired = false;
4594 // fade the centerprint_hud in/out
4595 if(centerprint_time[j] < 0) // Expired but forced. Expire time is the fade-in time.
4596 a = (time - centerprint_expire_time[j]) / max(0.0001, autocvar_hud_panel_centerprint_fade_in);
4597 else if(centerprint_expire_time[j] - autocvar_hud_panel_centerprint_fade_out > time) // Regularily printed. Not fading out yet.
4598 a = (time - (centerprint_expire_time[j] - centerprint_time[j])) / max(0.0001, autocvar_hud_panel_centerprint_fade_in);
4599 else // Expiring soon, so fade it out.
4600 a = (centerprint_expire_time[j] - time) / max(0.0001, autocvar_hud_panel_centerprint_fade_out);
4602 // while counting down show it anyway in order to hold the current message position
4603 if (a <= 0.5/255.0 && centerprint_countdown_num[j] == 0) // Guaranteed invisible - don't show.
4608 // set the size from fading in/out before subsequent fading
4609 sz = autocvar_hud_panel_centerprint_fade_minfontsize + a * (1 - autocvar_hud_panel_centerprint_fade_minfontsize);
4611 // also fade it based on positioning
4612 if(autocvar_hud_panel_centerprint_fade_subsequent)
4614 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
4615 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
4617 a *= panel_fg_alpha;
4619 // finally set the size based on the new theAlpha from subsequent fading
4620 sz = sz * (autocvar_hud_panel_centerprint_fade_subsequent_minfontsize + a * (1 - autocvar_hud_panel_centerprint_fade_subsequent_minfontsize));
4621 drawfontscale = sz * '1 1 0';
4623 if (centerprint_countdown_num[j])
4624 n = tokenizebyseparator(strreplace("^COUNT", count_seconds(centerprint_countdown_num[j]), centerprint_messages[j]), "\n");
4626 n = tokenizebyseparator(centerprint_messages[j], "\n");
4628 if (autocvar_hud_panel_centerprint_flip)
4630 // check if the message can be entirely shown
4631 for(k = 0; k < n; ++k)
4633 getWrappedLine_remaining = argv(k);
4634 while(getWrappedLine_remaining)
4636 ts = getWrappedLine(panel_size.x * sz, fontsize, stringwidth_colors);
4638 pos.y -= fontsize.y;
4640 pos.y -= fontsize.y * CENTERPRINT_SPACING/2;
4643 current_msg_posY = pos.y; // save starting pos (first line) of the current message
4647 for(k = 0; k < n; ++k)
4649 getWrappedLine_remaining = argv(k);
4650 while(getWrappedLine_remaining)
4652 ts = getWrappedLine(panel_size.x * sz, fontsize, stringwidth_colors);
4656 pos.x = panel_pos.x + (panel_size.x - stringwidth(ts, true, fontsize)) * align;
4657 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.
4658 drawcolorcodedstring(pos + eY * 0.5 * (1 - sz) * fontsize.y, ts, fontsize, a, DRAWFLAG_NORMAL);
4659 pos.y += fontsize.y;
4662 pos.y += fontsize.y * CENTERPRINT_SPACING/2;
4666 ++g; // move next position number up
4668 msg_size = pos.y - msg_size;
4669 if (autocvar_hud_panel_centerprint_flip)
4671 pos.y = current_msg_posY - CENTERPRINT_SPACING * fontsize.y;
4672 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
4673 pos.y += (msg_size + CENTERPRINT_SPACING * fontsize.y) * (1 - sqrt(sz));
4675 if (pos.y < panel_pos.y) // check if the next message can be shown
4677 drawfontscale = '1 1 0';
4683 pos.y += CENTERPRINT_SPACING * fontsize.y;
4684 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
4685 pos.y -= (msg_size + CENTERPRINT_SPACING * fontsize.y) * (1 - sqrt(sz));
4687 if(pos.y > panel_pos.y + panel_size.y - fontsize.y) // check if the next message can be shown
4689 drawfontscale = '1 1 0';
4694 drawfontscale = '1 1 0';
4695 if (all_messages_expired)
4697 centerprint_showing = false;
4698 reset_centerprint_messages();
4704 void HUD_Buffs(void)
4706 int buffs = getstati(STAT_BUFFS, 0, 24);
4707 if(!autocvar__hud_configure)
4709 if(!autocvar_hud_panel_buffs) return;
4710 if(spectatee_status == -1) return;
4711 if(getstati(STAT_HEALTH) <= 0) return;
4716 buffs = Buff_Type_first.items; // force first buff
4719 int b = 0; // counter to tell other functions that we have buffs
4722 for(e = Buff_Type_first; e; e = e.enemy) if(buffs & e.items)
4725 string o = strcat(rgb_to_hexcolor(Buff_Color(e.items)), Buff_PrettyName(e.items));
4729 s = strcat(s, " ", o);
4732 HUD_Panel_UpdateCvars();
4734 draw_beginBoldFont();
4738 mySize = panel_size;
4740 HUD_Panel_DrawBg(bound(0, b, 1));
4741 if(panel_bg_padding)
4743 pos += '1 1 0' * panel_bg_padding;
4744 mySize -= '2 2 0' * panel_bg_padding;
4747 //float panel_ar = mySize_x/mySize_y;
4748 //bool is_vertical = (panel_ar < 1);
4749 //float buff_iconalign = autocvar_hud_panel_buffs_iconalign;
4750 vector buff_offset = '0 0 0';
4752 for(e = Buff_Type_first; e; e = e.enemy) if(buffs & e.items)
4754 //DrawNumIcon(pos + buff_offset, mySize, shield, "shield", is_vertical, buff_iconalign, '1 1 1', 1);
4755 drawcolorcodedstring_aspect(pos + buff_offset, s, mySize, panel_fg_alpha * 0.5, DRAWFLAG_NORMAL);
4768 void HUD_Reset (void)
4770 // reset gametype specific icons
4771 if(gametype == MAPINFO_TYPE_CTF)
4772 HUD_Mod_CTF_Reset();
4775 void HUD_Main (void)
4778 // global hud theAlpha fade
4779 if(menu_enabled == 1)
4782 hud_fade_alpha = (1 - autocvar__menu_alpha);
4784 if(scoreboard_fade_alpha)
4785 hud_fade_alpha = (1 - scoreboard_fade_alpha);
4787 HUD_Configure_Frame();
4789 if(intermission == 2) // no hud during mapvote
4792 // panels that we want to be active together with the scoreboard
4793 // they must fade only when the menu does
4794 if(scoreboard_fade_alpha == 1)
4796 (panel = HUD_PANEL(CENTERPRINT)).panel_draw();
4800 if(!autocvar__hud_configure && !hud_fade_alpha)
4804 if (hud_skin_prev != autocvar_hud_skin)
4807 strunzone(hud_skin_path);
4808 hud_skin_path = strzone(strcat("gfx/hud/", autocvar_hud_skin));
4810 strunzone(hud_skin_prev);
4811 hud_skin_prev = strzone(autocvar_hud_skin);
4814 current_player = player_localentnum;
4817 if(autocvar_hud_dock != "" && autocvar_hud_dock != "0")
4821 float hud_dock_color_team = autocvar_hud_dock_color_team;
4822 if((teamplay) && hud_dock_color_team) {
4823 if(autocvar__hud_configure && myteam == NUM_SPECTATOR)
4824 color = '1 0 0' * hud_dock_color_team;
4826 color = myteamcolors * hud_dock_color_team;
4828 else if(autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && hud_dock_color_team) {
4829 color = '1 0 0' * hud_dock_color_team;
4833 string hud_dock_color = autocvar_hud_dock_color;
4834 if(hud_dock_color == "shirt") {
4835 f = stof(getplayerkeyvalue(current_player - 1, "colors"));
4836 color = colormapPaletteColor(floor(f / 16), 0);
4838 else if(hud_dock_color == "pants") {
4839 f = stof(getplayerkeyvalue(current_player - 1, "colors"));
4840 color = colormapPaletteColor(f % 16, 1);
4843 color = stov(hud_dock_color);
4847 pic = strcat(hud_skin_path, "/", autocvar_hud_dock);
4848 if(precache_pic(pic) == "") {
4849 pic = strcat(hud_skin_path, "/dock_medium");
4850 if(precache_pic(pic) == "") {
4851 pic = "gfx/hud/default/dock_medium";
4854 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...
4857 // cache the panel order into the panel_order array
4858 if(autocvar__hud_panelorder != hud_panelorder_prev) {
4859 for(i = 0; i < HUD_PANEL_NUM; ++i)
4860 panel_order[i] = -1;
4863 bool warning = false;
4864 int argc = tokenize_console(autocvar__hud_panelorder);
4865 if (argc > HUD_PANEL_NUM)
4867 //first detect wrong/missing panel numbers
4868 for(i = 0; i < HUD_PANEL_NUM; ++i) {
4869 p_num = stoi(argv(i));
4870 if (p_num >= 0 && p_num < HUD_PANEL_NUM) { //correct panel number?
4871 if (panel_order[p_num] == -1) //found for the first time?
4872 s = strcat(s, ftos(p_num), " ");
4873 panel_order[p_num] = 1; //mark as found
4878 for(i = 0; i < HUD_PANEL_NUM; ++i) {
4879 if (panel_order[i] == -1) {
4881 s = strcat(s, ftos(i), " "); //add missing panel number
4885 dprint("Automatically fixed wrong/missing panel numbers in _hud_panelorder\n");
4887 cvar_set("_hud_panelorder", s);
4888 if(hud_panelorder_prev)
4889 strunzone(hud_panelorder_prev);
4890 hud_panelorder_prev = strzone(s);
4892 //now properly set panel_order
4893 tokenize_console(s);
4894 for(i = 0; i < HUD_PANEL_NUM; ++i) {
4895 panel_order[i] = stof(argv(i));
4899 hud_draw_maximized = 0;
4900 // draw panels in order specified by panel_order array
4901 for(i = HUD_PANEL_NUM - 1; i >= 0; --i)
4902 (panel = hud_panel[panel_order[i]]).panel_draw();
4904 hud_draw_maximized = 1; // panels that may be maximized must check this var
4905 // draw maximized panels on top
4906 if(hud_panel_radar_maximized)
4907 (panel = HUD_PANEL(RADAR)).panel_draw();
4908 if(autocvar__con_chat_maximized)
4909 (panel = HUD_PANEL(CHAT)).panel_draw();
4911 HUD_Configure_PostDraw();
4913 hud_configure_prev = autocvar__hud_configure;