7 // a border picture is a texture containing nine parts:
8 // 1/4 width: left part
9 // 1/2 width: middle part (stretched)
10 // 1/4 width: right part
12 // 1/4 height: top part
13 // 1/2 height: middle part (stretched)
14 // 1/4 height: bottom part
15 void draw_BorderPicture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha, vector theBorderSize)
20 //pic = draw_UseSkinFor(pic);
21 width = eX * theSize_x;
22 height = eY * theSize_y;
23 if(theSize_x <= theBorderSize_x * 2)
25 // not wide enough... draw just left and right then
26 bW = eX * (0.25 * theSize_x / (theBorderSize_x * 2));
27 if(theSize_y <= theBorderSize_y * 2)
29 // not high enough... draw just corners
30 bH = eY * (0.25 * theSize_y / (theBorderSize_y * 2));
31 drawsubpic(theOrigin, width * 0.5 + height * 0.5, pic, '0 0 0', bW + bH, theColor, theAlpha, 0);
32 drawsubpic(theOrigin + width * 0.5, width * 0.5 + height * 0.5, pic, eX - bW, bW + bH, theColor, theAlpha, 0);
33 drawsubpic(theOrigin + height * 0.5, width * 0.5 + height * 0.5, pic, eY - bH, bW + bH, theColor, theAlpha, 0);
34 drawsubpic(theOrigin + theSize * 0.5, width * 0.5 + height * 0.5, pic, eX + eY - bW - bH, bW + bH, theColor, theAlpha, 0);
38 dY = theBorderSize_x * eY;
39 drawsubpic(theOrigin, width * 0.5 + dY, pic, '0 0 0', '0 0.25 0' + bW, theColor, theAlpha, 0);
40 drawsubpic(theOrigin + width * 0.5, width * 0.5 + dY, pic, '0 0 0' + eX - bW, '0 0.25 0' + bW, theColor, theAlpha, 0);
41 drawsubpic(theOrigin + dY, width * 0.5 + height - 2 * dY, pic, '0 0.25 0', '0 0.5 0' + bW, theColor, theAlpha, 0);
42 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);
43 drawsubpic(theOrigin + height - dY, width * 0.5 + dY, pic, '0 0.75 0', '0 0.25 0' + bW, theColor, theAlpha, 0);
44 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);
49 if(theSize_y <= theBorderSize_y * 2)
51 // not high enough... draw just top and bottom then
52 bH = eY * (0.25 * theSize_y / (theBorderSize_y * 2));
53 dX = theBorderSize_x * eX;
54 drawsubpic(theOrigin, dX + height * 0.5, pic, '0 0 0', '0.25 0 0' + bH, theColor, theAlpha, 0);
55 drawsubpic(theOrigin + dX, width - 2 * dX + height * 0.5, pic, '0.25 0 0', '0.5 0 0' + bH, theColor, theAlpha, 0);
56 drawsubpic(theOrigin + width - dX, dX + height * 0.5, pic, '0.75 0 0', '0.25 0 0' + bH, theColor, theAlpha, 0);
57 drawsubpic(theOrigin + height * 0.5, dX + height * 0.5, pic, '0 0 0' + eY - bH, '0.25 0 0' + bH, theColor, theAlpha, 0);
58 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);
59 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);
63 dX = theBorderSize_x * eX;
64 dY = theBorderSize_x * eY;
65 drawsubpic(theOrigin, dX + dY, pic, '0 0 0', '0.25 0.25 0', theColor, theAlpha, 0);
66 drawsubpic(theOrigin + dX, width - 2 * dX + dY, pic, '0.25 0 0', '0.5 0.25 0', theColor, theAlpha, 0);
67 drawsubpic(theOrigin + width - dX, dX + dY, pic, '0.75 0 0', '0.25 0.25 0', theColor, theAlpha, 0);
68 drawsubpic(theOrigin + dY, dX + height - 2 * dY, pic, '0 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0);
69 drawsubpic(theOrigin + dY + dX, width - 2 * dX + height - 2 * dY, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0);
70 drawsubpic(theOrigin + dY + width - dX, dX + height - 2 * dY, pic, '0.75 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0);
71 drawsubpic(theOrigin + height - dY, dX + dY, pic, '0 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
72 drawsubpic(theOrigin + height - dY + dX, width - 2 * dX + dY, pic, '0.25 0.75 0', '0.5 0.25 0', theColor, theAlpha, 0);
73 drawsubpic(theOrigin + height - dY + width - dX, dX + dY, pic, '0.75 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
78 // drawpic wrapper to draw an image as large as possible with preserved aspect ratio into a box
79 void drawpic_aspect(vector pos, string pic, vector sz, vector color, float alpha, float drawflag) {
81 imgsize = drawgetimagesize(pic);
83 imgaspect = imgsize_x/imgsize_y;
90 if(aspect > imgaspect) {
91 sz_x = sz_y * imgaspect;
92 drawpic(pos + eX * (oldsz_x - sz_x) * 0.5, pic, sz, color, alpha, drawflag);
94 sz_y = sz_x / imgaspect;
95 drawpic(pos + eY * (oldsz_y - sz_y) * 0.5, pic, sz, color, alpha, drawflag);
99 // draw HUD element with image from gfx/hud/hud_skin/foo.tga if it exists, otherwise gfx/hud/default/foo.tga
100 // TODO: make a default skin, and fallback to these!
101 void drawpic_skin(vector pos, string pic, vector sz, vector color, float alpha, float drawflag) {
102 drawpic_aspect(pos, strcat("gfx/hud/", cvar_string("hud_skin"), "/", pic), sz, color, alpha, drawflag);
106 void drawpic_skin_expanding(vector pos, string pic, vector sz, vector rgb, float alpha, float flag, float fadelerp) {
108 //drawpic_aspect_expanding(pos, strcat("gfx/hud/", cvar_string("hud_skin"), "/", pic), sz, rgb, alpha, flag, fadelerp);
111 void drawpic_skin_expanding_two(vector pos, string pic, vector sz, vector rgb, float alpha, float flag, float fadelerp) {
113 //drawpic_aspect_expanding_two(pos, strcat("gfx/hud/", cvar_string("hud_skin"), "/", pic), sz, rgb, alpha, flag, fadelerp);
116 // return HUD background color
117 vector HUD_GetBgColor()
121 GetTeamRGB(myteam) * hud_color_bg_team;
123 // allow custom HUD colors in non-teamgames
124 color_x = cvar("hud_color_bg_r");
125 color_y = cvar("hud_color_bg_g");
126 color_z = cvar("hud_color_bg_b");
131 // return accuracy text color
132 vector HUD_AccuracyColor(float accuracy)
135 float yellow_accuracy = cvar("hud_weaponicons_accuracy_yellow"); // value at which this function returns yellow
136 if(accuracy >= 100) {
140 else if(accuracy > yellow_accuracy) {
141 rgb_x = 1 - (accuracy-yellow_accuracy)/(100-yellow_accuracy); // red value between 1 -> 0
146 rgb_y = accuracy/yellow_accuracy; // green value between 0 -> 1
152 vector HUD_Get_Num_Color (float x, float maxvalue)
160 else if(x > maxvalue * 0.75) {
161 color_x = 0.4 - (x-150)*0.02 * 0.4; //red value between 0.4 -> 0
162 color_y = 0.9 + (x-150)*0.02 * 0.1; // green value between 0.9 -> 1
165 else if(x > maxvalue * 0.5) {
166 color_x = 1 - (x-100)*0.02 * 0.6; //red value between 1 -> 0.4
167 color_y = 1 - (x-100)*0.02 * 0.1; // green value between 1 -> 0.9
168 color_z = 1 - (x-100)*0.02; // blue value between 1 -> 0
170 else if(x > maxvalue * 0.25) {
173 color_z = 0.2 + (x-50)*0.02 * 0.8; // blue value between 0.2 -> 1
175 else if(x > maxvalue * 0.1) {
177 color_y = (x-20)*90/27/100; // green value between 0 -> 1
178 color_z = (x-20)*90/27/100 * 0.2; // blue value between 0 -> 0.2
188 float stringwidth_colors(string s, vector theSize)
190 return stringwidth(s, TRUE, theSize);
193 float stringwidth_nocolors(string s, vector theSize)
195 return stringwidth(s, FALSE, theSize);
198 #define CENTERPRINT_MAX_LINES 30
199 string centerprint_messages[CENTERPRINT_MAX_LINES];
200 float centerprint_width[CENTERPRINT_MAX_LINES];
201 vector centerprint_start;
202 float centerprint_expire;
203 float centerprint_num;
204 float centerprint_offset_hint;
205 vector centerprint_fontsize;
207 void centerprint(string strMessage)
209 float i, j, n, hcount;
212 centerprint_fontsize = HUD_GetFontsize("scr_centersize");
214 centerprint_expire = min(centerprint_expire, time); // if any of the returns happens, this message will fade out
216 if(cvar("scr_centertime") <= 0)
222 // strip trailing newlines
223 j = strlen(strMessage) - 1;
224 while(substring(strMessage, j, 1) == "\n" && j >= 0)
226 strMessage = substring(strMessage, 0, j + 1);
231 // strip leading newlines and remember them, they are a hint that the message should be lower on the screen
233 while(substring(strMessage, j, 1) == "\n" && j < strlen(strMessage))
235 strMessage = substring(strMessage, j, strlen(strMessage) - j);
236 centerprint_offset_hint = j;
241 // if we get here, we have a message. Initialize its height.
244 n = tokenizebyseparator(strMessage, "\n");
246 for(j = 0; j < n; ++j)
248 getWrappedLine_remaining = argv(j);
249 while(getWrappedLine_remaining)
251 s = getWrappedLine(vid_conwidth * 0.75, centerprint_fontsize, stringwidth_colors);
252 if(centerprint_messages[i])
253 strunzone(centerprint_messages[i]);
254 centerprint_messages[i] = strzone(s);
255 centerprint_width[i] = stringwidth(s, TRUE, centerprint_fontsize);
258 // half height for empty lines looks better
264 if(i >= CENTERPRINT_MAX_LINES)
270 h = centerprint_fontsize_y*hcount;
272 havail = vid_conheight;
273 if(cvar("con_chatpos") < 0)
274 havail -= (-cvar("con_chatpos") + cvar("con_chat")) * cvar("con_chatsize"); // avoid overlapping chat
275 if(havail > vid_conheight - 70)
276 havail = vid_conheight - 70; // avoid overlapping HUD
278 centerprint_start_x = 0;
281 float forbiddenmin, forbiddenmax, allowedmin, allowedmax, preferred;
283 // here, the centerprint would cover the crosshair. REALLY BAD.
284 forbiddenmin = vid_conheight * 0.5 - h - 16;
285 forbiddenmax = vid_conheight * 0.5 + 16;
287 allowedmin = scoreboard_bottom;
288 allowedmax = havail - h;
289 preferred = (havail - h)/2;
292 // possible orderings (total: 4! / 4 = 6)
293 // allowedmin allowedmax forbiddenmin forbiddenmax
294 // forbiddenmin forbiddenmax allowedmin allowedmax
295 if(allowedmax < forbiddenmin || allowedmin > forbiddenmax)
297 // forbidden doesn't matter in this case
298 centerprint_start_y = bound(allowedmin, preferred, allowedmax);
300 // allowedmin forbiddenmin allowedmax forbiddenmax
301 else if(allowedmin < forbiddenmin && allowedmax < forbiddenmax)
303 centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
305 // allowedmin forbiddenmin forbiddenmax allowedmax
306 else if(allowedmin < forbiddenmin)
308 // make sure the forbidden zone is not covered
309 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
310 centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
312 centerprint_start_y = bound(forbiddenmax, preferred, allowedmin);
314 // forbiddenmin allowedmin allowedmax forbiddenmax
315 else if(allowedmax < forbiddenmax)
317 // it's better to leave the allowed zone (overlap with scoreboard) than
318 // to cover the forbidden zone (crosshair)
319 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
320 centerprint_start_y = forbiddenmax;
322 centerprint_start_y = forbiddenmin;
324 // forbiddenmin allowedmin forbiddenmax allowedmax
327 centerprint_start_y = bound(forbiddenmax, preferred, allowedmax);
330 centerprint_start_y =
333 max(scoreboard_bottom, vid_conheight * 0.5 + 16),
341 centerprint_expire = time + cvar("scr_centertime");
344 void HUD_DrawCenterPrint (void)
351 //if(time > centerprint_expire)
354 //a = bound(0, 1 - 2 * (time - centerprint_expire), 1);
355 a = bound(0, 1 - 4 * (time - centerprint_expire), 1);
356 //sz = 1.2 / (a + 0.2);
361 pos = centerprint_start;
362 for (i=0; i<centerprint_num; i = i + 1)
364 pos_x = (vid_conwidth - centerprint_width[i]) * 0.5;
365 ts = centerprint_messages[i];
368 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
369 drawcolorcodedstring(pos, ts, centerprint_fontsize, a, DRAWFLAG_NORMAL);
370 // - '0 0.5 0' * (sz - 1) * centerprint_fontsize_x - '0.5 0 0' * (sz - 1) * centerprint_width[i] * centerprint_fontsize_y, centerprint_fontsize * sz
371 pos_y = pos_y + centerprint_fontsize_y;
374 // half height for empty lines looks better
375 pos_y = pos_y + centerprint_fontsize_y * 0.5;
379 void drawstringright(vector position, string text, vector scale, vector rgb, float alpha, float flag)
381 position_x -= 2 / 3 * strlen(text) * scale_x;
382 drawstring(position, text, scale, rgb, alpha, flag);
385 void drawstringcenter(vector position, string text, vector scale, vector rgb, float alpha, float flag)
387 position_x = 0.5 * (vid_conwidth - 0.6025 * strlen(text) * scale_x);
388 drawstring(position, text, scale, rgb, alpha, flag);
391 // return the string of the given race place
392 string race_PlaceName(float pos) {
400 return strcat(ftos(pos), "th");
403 // return the string of the onscreen race timer
404 string MakeRaceString(float cp, float mytime, float histime, float lapdelta, string hisname)
412 if(histime == 0) // goal hit
416 timestr = strcat("+", ftos_decimals(+mytime, TIME_DECIMALS));
426 timestr = strcat("-", ftos_decimals(-mytime, TIME_DECIMALS));
432 lapstr = strcat(" (-", ftos(lapdelta), "L)");
435 else if(lapdelta < 0)
437 lapstr = strcat(" (+", ftos(-lapdelta), "L)");
441 else if(histime > 0) // anticipation
443 if(mytime >= histime)
444 timestr = strcat("+", ftos_decimals(mytime - histime, TIME_DECIMALS));
446 timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(histime));
453 cpname = "Start line";
455 cpname = "Finish line";
457 cpname = strcat("Intermediate ", ftos(cp));
459 cpname = "Finish line";
462 return strcat(col, cpname);
463 else if(hisname == "")
464 return strcat(col, cpname, " (", timestr, ")");
466 return strcat(col, cpname, " (", timestr, " ", strcat(hisname, col, lapstr), ")");
469 // Check if the given name already exist in race rankings? In that case, where? (otherwise return 0)
470 float race_CheckName(string net_name) {
472 for (i=RANKINGS_CNT-1;i>=0;--i)
473 if(grecordholder[i] == net_name)
485 void HUD_Panel_ExportCfg(string cfgname)
488 fh = fopen(strcat("hud_", cvar_string("hud_skin"), "_", cfgname, ".cfg"), FILE_WRITE);
491 fputs(fh, strcat("seta hud_skin \"", cvar_string("hud_skin"), "\"", "\n"));
492 fputs(fh, strcat("seta hud_bg \"", cvar_string("hud_bg"), "\"", "\n"));
493 fputs(fh, strcat("seta hud_bg_color \"", cvar_string("hud_bg_color"), "\"", "\n"));
494 fputs(fh, strcat("seta hud_bg_color_team \"", cvar_string("hud_bg_color_team"), "\"", "\n"));
495 fputs(fh, strcat("seta hud_bg_alpha \"", cvar_string("hud_bg_alpha"), "\"", "\n"));
496 fputs(fh, strcat("seta hud_bg_border \"", cvar_string("hud_bg_border"), "\"", "\n"));
497 fputs(fh, strcat("seta hud_bg_padding \"", cvar_string("hud_bg_padding"), "\"", "\n"));
498 fputs(fh, strcat("seta hud_fg_alpha \"", cvar_string("hud_fg_alpha"), "\"", "\n"));
501 fputs(fh, strcat("seta hud_dock \"", cvar_string("hud_dock"), "\"", "\n"));
502 fputs(fh, strcat("seta hud_dock_color \"", cvar_string("hud_dock_color"), "\"", "\n"));
503 fputs(fh, strcat("seta hud_dock_color_team \"", cvar_string("hud_dock_color_team"), "\"", "\n"));
504 fputs(fh, strcat("seta hud_dock_alpha \"", ftos(cvar("hud_dock_alpha")), "\"", "\n"));
507 fputs(fh, strcat("seta hud_progressbar_alpha ", ftos(cvar("hud_progressbar_alpha")), "\n"));
508 fputs(fh, strcat("seta hud_progressbar_strength_color \"", cvar_string("hud_progressbar_strength_color"), "\"", "\n"));
509 fputs(fh, strcat("seta hud_progressbar_shield_color \"", cvar_string("hud_progressbar_shield_color"), "\"", "\n"));
510 fputs(fh, strcat("seta hud_progressbar_health_color \"", cvar_string("hud_progressbar_health_color"), "\"", "\n"));
511 fputs(fh, strcat("seta hud_progressbar_armor_color \"", cvar_string("hud_progressbar_armor_color"), "\"", "\n"));
512 fputs(fh, strcat("seta hud_progressbar_fuel_color \"", cvar_string("hud_progressbar_fuel_color"), "\"", "\n"));
513 fputs(fh, strcat("seta hud_progressbar_nexball_color \"", cvar_string("hud_progressbar_nexball_color"), "\"", "\n"));
516 // common cvars for all panels
518 for (i = 0; i < HUD_PANEL_NUM; ++i)
520 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), " ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i)))), "\n"));
521 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_pos \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_pos")), "\"", "\n"));
522 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_size \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_size")), "\"", "\n"));
523 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg")), "\"", "\n"));
524 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_color \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg_color")), "\"", "\n"));
525 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_color_team \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg_color_team")), "\"", "\n"));
526 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_alpha \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg_alpha")), "\"", "\n"));
527 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_border \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg_border")), "\"", "\n"));
528 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_padding \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg_padding")), "\"", "\n"));
530 case HUD_PANEL_WEAPONICONS:
531 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_accuracy_yellow ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_accuracy_yellow"))), "\n"));
533 case HUD_PANEL_INVENTORY:
534 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_onlycurrent ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_onlycurrent"))), "\n"));
535 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_iconalign ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_mirror"))), "\n"));
537 case HUD_PANEL_POWERUPS:
538 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_flip ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_flip"))), "\n"));
539 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_iconalign ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_mirror"))), "\n"));
540 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_baralign ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_mirror"))), "\n"));
542 case HUD_PANEL_HEALTHARMOR:
543 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_flip ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_flip"))), "\n"));
544 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_iconalign ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_mirror"))), "\n"));
545 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_baralign ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_mirror"))), "\n"));
547 case HUD_PANEL_NOTIFY:
548 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_flip ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_flip"))), "\n"));
549 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_info_top ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_info_top"))), "\n"));
551 case HUD_PANEL_RADAR:
552 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_foreground_alpha ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_foreground_alpha"))), "\n"));
554 fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_alreadyvoted_alpha ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_alreadyvoted_alpha"))), "\n"));
560 print("^2Successfully exported to hud_", cvar_string("hud_skin"), "_", cfgname, ".cfg! (Note: It's saved in data/data/)\n");
565 // return active status of panel
566 float HUD_Panel_CheckActive(float id)
568 if (cvar_or(strcat("hud_", HUD_Panel_GetName(id)), 1))
573 // return size of given panel
574 vector HUD_Panel_GetSize(float id)
577 mySize = stov(cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_size")));
579 mySize = eX * mySize_x * vid_conwidth + eY * mySize_y * vid_conheight;
581 if(disable_menu_alphacheck == 2 && id == highlightedPanel)
583 vector menu_enable_maxsize, menu_enable_size;
584 menu_enable_maxsize = '0 0 0'; // shut up FTEQCC
585 menu_enable_maxsize_x = 0.3 * vid_conwidth;
586 menu_enable_maxsize_y = 0.18 * vid_conheight;
587 if(mySize_x > mySize_y)
589 if(mySize_y > menu_enable_maxsize_y)
591 menu_enable_size_y = menu_enable_maxsize_y;
592 menu_enable_size_x = mySize_x * (menu_enable_maxsize_y/mySize_y);
593 mySize = (1 - cvar("_menu_alpha")) * mySize + (cvar("_menu_alpha")) * menu_enable_size;
598 if(mySize_x > menu_enable_maxsize_x)
600 menu_enable_size_x = menu_enable_maxsize_x;
601 menu_enable_size_y = mySize_y * (menu_enable_maxsize_x/mySize_x);
602 mySize = (1 - cvar("_menu_alpha")) * mySize + (cvar("_menu_alpha")) * menu_enable_size;
609 // return pos of given panel
610 vector HUD_Panel_GetPos(float id)
613 pos = stov(cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_pos")));
615 pos = eX * pos_x * vid_conwidth + eY * pos_y * vid_conheight;
617 if(disable_menu_alphacheck == 2 && id == highlightedPanel)
619 vector mySize, menu_enable_panelpos;
620 mySize = HUD_Panel_GetSize(id);
621 if(mySize_x > mySize_y)
622 menu_enable_panelpos = eX * 0.5 * vid_conwidth - eX * 0.5 * mySize_x + eY * 0.82 * vid_conheight;
624 menu_enable_panelpos = eY * 0.5 * vid_conheight - eY * 0.5 * mySize_y + eX * 0.7 * vid_conwidth;
625 pos = (1 - cvar("_menu_alpha")) * pos + (cvar("_menu_alpha")) * menu_enable_panelpos;
630 float HUD_Panel_GetBorder(float id)
633 border = cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_border"));
635 border = cvar_string("hud_bg_border");
639 vector HUD_Panel_GetColor(float id)
645 // fetch per-panel color
646 if(teamplay && cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_color_team")) != "") {
647 f = stof(getplayerkey(self.sv_entnum, "colors"));
648 color = vtos(colormapPaletteColor(mod(f, 16), 1) * cvar(strcat("hud_", HUD_Panel_GetName(id), "_bg_color_team")));
651 color = cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_color"));
652 color_vec = stov(color);
654 if(color == "") { // fetch default color
655 color = cvar_string("hud_bg_color");
656 color_vec = stov(color);
657 if(teamplay && cvar(strcat("hud_bg_color_team"))) {
658 f = stof(getplayerkey(self.sv_entnum, "colors"));
659 color_vec = colormapPaletteColor(mod(f, 16), 1) * cvar("hud_bg_color_team");
661 else if(color == "shirt") {
662 f = stof(getplayerkey(self.sv_entnum, "colors"));
663 color_vec = colormapPaletteColor(floor(f / 16), 0);
665 else if(color == "pants") {
666 f = stof(getplayerkey(self.sv_entnum, "colors"));
667 color_vec = colormapPaletteColor(mod(f, 16), 1);
670 else if(color == "shirt") {
671 f = stof(getplayerkey(self.sv_entnum, "colors"));
672 color_vec = colormapPaletteColor(floor(f / 16), 0);
674 else if(color == "pants") {
675 f = stof(getplayerkey(self.sv_entnum, "colors"));
676 color_vec = colormapPaletteColor(mod(f, 16), 1);
681 vector HUD_Panel_Dock_GetColor(void)
686 color = cvar_string("hud_dock_color");
687 color_vec = stov(color);
688 if(teamplay && cvar(strcat("hud_dock_color_team"))) {
689 f = stof(getplayerkey(self.sv_entnum, "colors"));
690 color_vec = colormapPaletteColor(mod(f, 16), 1) * cvar("hud_dock_color_team");
692 else if(color == "shirt") {
693 f = stof(getplayerkey(self.sv_entnum, "colors"));
694 color_vec = colormapPaletteColor(floor(f / 16), 0);
696 else if(color == "pants") {
697 f = stof(getplayerkey(self.sv_entnum, "colors"));
698 color_vec = colormapPaletteColor(mod(f, 16), 1);
703 float HUD_Panel_GetBgAlpha(float id)
706 alpha = cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_alpha"));
708 alpha = cvar_string("hud_bg_alpha");
710 if(hud_configure && disable_menu_alphacheck == 2 && highlightedPanel == id) // do not set a minalpha cap when showing the config dialog for this panel
711 alpha = ftos((1 - cvar("_menu_alpha")) * max(cvar("hud_configure_bg_minalpha"), stof(alpha)) + (cvar("_menu_alpha")) * stof(alpha));
712 else if(hud_configure)
713 alpha = ftos(max(cvar("hud_configure_bg_minalpha"), stof(alpha)));
715 if(hud_configure && !cvar(strcat("hud_", HUD_Panel_GetName(id)))) // ALWAYS show disabled panels at 0.25 alpha when in config mode
718 if(disable_menu_alphacheck == 2 && highlightedPanel == id) // don't fade this panel when showing the panel-specific menu dialog
721 return stof(alpha) * menu_fade_alpha;
724 float HUD_Panel_GetFgAlpha(float id)
727 alpha = hud_fg_alpha;
729 if(hud_configure && !cvar(strcat("hud_", HUD_Panel_GetName(id)))) // ALWAYS show disabled panels at 0.25 alpha when in config mode
732 if(disable_menu_alphacheck == 2 && highlightedPanel == id) // don't fade this panel when showing the panel-specific menu dialog
735 return alpha * menu_fade_alpha;
738 float HUD_Panel_GetPadding(float id)
741 padding = cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_padding"));
743 padding = cvar_string("hud_bg_padding");
746 mySize = HUD_Panel_GetSize(id);
748 smallestsize = min(mySize_x, mySize_y);
749 return min(smallestsize/2 - 5, stof(padding));
752 // draw the background/borders
753 void HUD_Panel_DrawBg(float id, vector pos, vector mySize, float alpha)
755 if(!hud_configure && cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg")) == "0")
759 bg = cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg"));
761 bg = cvar_string("hud_bg");
763 if(bg == "0" && hud_configure) {
764 bg = "border"; // we probably want to see a background in config mode at all times...
770 border = max(0.0000001, HUD_Panel_GetBorder(id)); // draw_BorderPicture does not like border = 0
773 color = HUD_Panel_GetColor(id);
776 alpha = HUD_Panel_GetBgAlpha(id) * alpha; // allow panels to fade in/out by passing an alpha value
778 alpha = HUD_Panel_GetBgAlpha(id);
780 draw_BorderPicture(pos - '1 1 0' * border, strcat("gfx/hud/", cvar_string("hud_skin"), "/", bg), mySize + '1 1 0' * 2 * border, color, alpha, '1 1 0' * (border/BORDER_MULTIPLIER));
784 void HUD_Panel_DrawProgressBar(vector pos, float vertical, vector mySize, vector color, float alpha, float drawflag)
790 pic = strcat("gfx/hud/", cvar_string("hud_skin"), "/");
792 drawsubpic(pos, eY * min(mySize_y * 0.5, mySize_x) + eX * mySize_x, strcat(pic, "statusbar_vertical"), '0 0 0', '1 0.25 0', color, alpha, drawflag);
793 if(mySize_y/mySize_x > 2)
794 drawsubpic(pos + eY * mySize_x, eY * (mySize_y - 2 * mySize_x) + eX * mySize_x, strcat(pic, "statusbar_vertical"), '0 0.25 0', '1 0.5 0', color, alpha, drawflag);
795 drawsubpic(pos + eY * mySize_y - eY * min(mySize_y * 0.5, mySize_x), eY * min(mySize_y * 0.5, mySize_x) + eX * mySize_x, strcat(pic, "statusbar_vertical"), '0 0.75 0', '1 0.25 0', color, alpha, drawflag);
797 drawsubpic(pos, eX * min(mySize_x * 0.5, mySize_y) + eY * mySize_y, strcat(pic, "statusbar"), '0 0 0', '0.25 1 0', color, alpha, drawflag);
798 if(mySize_x/mySize_y > 2)
799 drawsubpic(pos + eX * mySize_y, eX * (mySize_x - 2 * mySize_y) + eY * mySize_y, strcat(pic, "statusbar"), '0.25 0 0', '0.5 1 0', color, alpha, drawflag);
800 drawsubpic(pos + eX * mySize_x - eX * min(mySize_x * 0.5, mySize_y), eX * min(mySize_x * 0.5, mySize_y) + eY * mySize_y, strcat(pic, "statusbar"), '0.75 0 0', '0.25 1 0', color, alpha, drawflag);
804 vector HUD_Panel_GetProgressBarColor(string item)
806 return stov(cvar_string(strcat("hud_progressbar_", item, "_color")));
809 // check if move will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
810 vector HUD_Panel_CheckMove(float id, vector myPos, vector mySize)
821 myCenter = '0 0 0'; // shut up fteqcc, there IS a reference
822 targCenter = '0 0 0'; // shut up fteqcc, there IS a reference
824 for (i = 0; i < HUD_PANEL_NUM; ++i) {
825 if(i == id || !HUD_Panel_CheckActive(i))
828 targPos = HUD_Panel_GetPos(i) - '1 1 0' * HUD_Panel_GetBorder(id);
829 targSize = HUD_Panel_GetSize(i) + '2 2 0' * HUD_Panel_GetBorder(id);
831 if(myPos_y + mySize_y < targPos_y)
833 if(myPos_y > targPos_y + targSize_y)
836 if(myPos_x + mySize_x < targPos_x)
838 if(myPos_x > targPos_x + targSize_x)
841 // OK, there IS a collision.
843 myCenter_x = myPos_x + 0.5 * mySize_x;
844 myCenter_y = myPos_y + 0.5 * mySize_y;
846 targCenter_x = targPos_x + 0.5 * targSize_x;
847 targCenter_y = targPos_y + 0.5 * targSize_y;
849 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // top left (of the target panel)
851 if(myPos_x + mySize_x - targPos_x < myPos_y + mySize_y - targPos_y) // push it to the side
852 myTarget_x = targPos_x - mySize_x;
853 else // push it upwards
854 myTarget_y = targPos_y - mySize_y;
856 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y) // top right
858 if(targPos_x + targSize_x - myPos_x < myPos_y + mySize_y - targPos_y) // push it to the side
859 myTarget_x = targPos_x + targSize_x;
860 else // push it upwards
861 myTarget_y = targPos_y - mySize_y;
863 else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
865 if(myPos_x + mySize_x - targPos_x < targPos_y + targSize_y - myPos_y) // push it to the side
866 myTarget_x = targPos_x - mySize_x;
867 else // push it downwards
868 myTarget_y = targPos_y + targSize_y;
870 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
872 if(targPos_x + targSize_x - myPos_x < targPos_y + targSize_y - myPos_y) // push it to the side
873 myTarget_x = targPos_x + targSize_x;
874 else // push it downwards
875 myTarget_y = targPos_y + targSize_y;
882 void HUD_Panel_SetPos(float id, vector pos)
885 oldPos = HUD_Panel_GetPos(id);
888 mySize = HUD_Panel_GetSize(id);
890 if(cvar("hud_configure_checkcollisions"))
891 pos = HUD_Panel_CheckMove(id, pos, mySize);
893 pos_x = bound(0, pos_x, vid_conwidth - mySize_x);
894 pos_y = bound(0, pos_y, vid_conheight - mySize_y);
896 if(cvar("hud_configure_grid"))
898 pos_x = floor((pos_x/vid_conwidth)/bound(0.005, cvar("hud_configure_grid_x"), 0.2) + 0.5) * bound(0.005, cvar("hud_configure_grid_x"), 0.2) * vid_conwidth;
899 pos_y = floor((pos_y/vid_conheight)/bound(0.005, cvar("hud_configure_grid_y"), 0.2) + 0.5) * bound(0.005, cvar("hud_configure_grid_y"), 0.2) * vid_conheight;
903 s = strcat(ftos(pos_x/vid_conwidth), " ", ftos(pos_y/vid_conheight));
905 cvar_set(strcat("hud_", HUD_Panel_GetName(id), "_pos"), s);
908 // check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
909 vector HUD_Panel_CheckResize(float id, vector mySize, vector resizeorigin) {
919 ratio = mySize_x/mySize_y;
921 for (i = 0; i < HUD_PANEL_NUM; ++i) {
922 if(i == id || !HUD_Panel_CheckActive(i))
925 targBorder = HUD_Panel_GetBorder(i);
926 targPos = HUD_Panel_GetPos(i) - '1 1 0' * targBorder;
927 targSize = HUD_Panel_GetSize(i) + '2 2 0' * targBorder;
928 targEndPos = targPos + targSize;
930 // resizeorigin is WITHIN target panel, just abort any collision testing against that particular panel to produce expected behaviour!
931 if(resizeorigin_x > targPos_x && resizeorigin_x < targEndPos_x && resizeorigin_y > targPos_y && resizeorigin_y < targEndPos_y)
934 if (resizeCorner == 1)
936 // check if this panel is on our way
937 if (resizeorigin_x <= targPos_x)
939 if (resizeorigin_y <= targPos_y)
941 if (targEndPos_x <= resizeorigin_x - mySize_x)
943 if (targEndPos_y <= resizeorigin_y - mySize_y)
946 // there is a collision:
947 // detect which side of the panel we are facing is actually limiting the resizing
948 // (which side the resize direction finds for first) and reduce the size up to there
950 // dist is the distance between resizeorigin and the "analogous" point of the panel
951 // in this case resizeorigin (bottom-right point) and the bottom-right point of the panel
952 dist_x = resizeorigin_x - targEndPos_x;
953 dist_y = resizeorigin_y - targEndPos_y;
954 if (dist_y < 0 || dist_x / dist_y > ratio)
955 mySize_x = min(mySize_x, dist_x);
957 mySize_y = min(mySize_y, dist_y);
959 else if (resizeCorner == 2)
961 if (resizeorigin_x >= targEndPos_x)
963 if (resizeorigin_y <= targPos_y)
965 if (targPos_x >= resizeorigin_x + mySize_x)
967 if (targEndPos_y <= resizeorigin_y - mySize_y)
970 dist_x = targPos_x - resizeorigin_x;
971 dist_y = resizeorigin_y - targEndPos_y;
972 if (dist_y < 0 || dist_x / dist_y > ratio)
973 mySize_x = min(mySize_x, dist_x);
975 mySize_y = min(mySize_y, dist_y);
977 else if (resizeCorner == 3)
979 if (resizeorigin_x <= targPos_x)
981 if (resizeorigin_y >= targEndPos_y)
983 if (targEndPos_x <= resizeorigin_x - mySize_x)
985 if (targPos_y >= resizeorigin_y + mySize_y)
988 dist_x = resizeorigin_x - targEndPos_x;
989 dist_y = targPos_y - resizeorigin_y;
990 if (dist_y < 0 || dist_x / dist_y > ratio)
991 mySize_x = min(mySize_x, dist_x);
993 mySize_y = min(mySize_y, dist_y);
995 else if (resizeCorner == 4)
997 if (resizeorigin_x >= targEndPos_x)
999 if (resizeorigin_y >= targEndPos_y)
1001 if (targPos_x >= resizeorigin_x + mySize_x)
1003 if (targPos_y >= resizeorigin_y + mySize_y)
1006 dist_x = targPos_x - resizeorigin_x;
1007 dist_y = targPos_y - resizeorigin_y;
1008 if (dist_y < 0 || dist_x / dist_y > ratio)
1009 mySize_x = min(mySize_x, dist_x);
1011 mySize_y = min(mySize_y, dist_y);
1013 if(cvar("hud_configure_checkcollisions_debug"))
1014 drawfill(targPos + '1 1 0' * targBorder, targSize - '2 2 0' * targBorder, '1 1 0', .3, DRAWFLAG_NORMAL);
1020 void HUD_Panel_SetPosSize(float id)
1022 vector resizeorigin;
1023 resizeorigin = panel_click_resizeorigin;
1024 vector mySize, myPos;
1026 if(resizeCorner == 1) {
1027 mySize_x = resizeorigin_x - (mousepos_x - panel_click_distance_x);
1028 mySize_y = resizeorigin_y - (mousepos_y - panel_click_distance_y);
1029 } else if(resizeCorner == 2) {
1030 mySize_x = mousepos_x + panel_click_distance_x - resizeorigin_x;
1031 mySize_y = panel_click_distance_y + resizeorigin_y - mousepos_y;
1032 } else if(resizeCorner == 3) {
1033 mySize_x = resizeorigin_x + panel_click_distance_x - mousepos_x;
1034 mySize_y = mousepos_y + panel_click_distance_y - resizeorigin_y;
1035 } else { // resizeCorner == 4
1036 mySize_x = mousepos_x - (resizeorigin_x - panel_click_distance_x);
1037 mySize_y = mousepos_y - (resizeorigin_y - panel_click_distance_y);
1040 // minimum panel size cap
1041 mySize_x = max(0.025 * vid_conwidth, mySize_x);
1042 mySize_y = max(0.025 * vid_conheight, mySize_y);
1044 if(id == HUD_PANEL_CHAT) // some panels have their own restrictions, like the chat panel (which actually only moves the engine chat print around). Looks bad if it's too small.
1046 mySize_x = max(17 * cvar("con_chatsize"), mySize_x);
1047 mySize_y = max(2 * cvar("con_chatsize") + 2 * HUD_Panel_GetPadding(id), mySize_y);
1050 // collision testing|
1051 // -----------------+
1053 // we need to know pos at this stage, but it might still change later if we hit a screen edge/other panel (?)
1054 if(resizeCorner == 1) {
1055 myPos_x = resizeorigin_x - mySize_x;
1056 myPos_y = resizeorigin_y - mySize_y;
1057 } else if(resizeCorner == 2) {
1058 myPos_x = resizeorigin_x;
1059 myPos_y = resizeorigin_y - mySize_y;
1060 } else if(resizeCorner == 3) {
1061 myPos_x = resizeorigin_x - mySize_x;
1062 myPos_y = resizeorigin_y;
1063 } else { // resizeCorner == 4
1064 myPos_x = resizeorigin_x;
1065 myPos_y = resizeorigin_y;
1068 // left/top screen edges
1070 mySize_x = mySize_x + myPos_x;
1072 mySize_y = mySize_y + myPos_y;
1074 // bottom/right screen edges
1075 if(myPos_x + mySize_x > vid_conwidth)
1076 mySize_x = vid_conwidth - myPos_x;
1077 if(myPos_y + mySize_y > vid_conheight)
1078 mySize_y = vid_conheight - myPos_y;
1080 if(cvar("hud_configure_checkcollisions_debug"))
1081 drawfill(myPos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
1083 // before checkresize, otherwise panel can be snapped partially inside another panel or panel aspect ratio can be broken
1084 if(cvar("hud_configure_grid"))
1086 mySize_x = floor((mySize_x/vid_conwidth)/bound(0.005, cvar("hud_configure_grid_x"), 0.2) + 0.5) * bound(0.005, cvar("hud_configure_grid_x"), 0.2) * vid_conwidth;
1087 mySize_y = floor((mySize_y/vid_conheight)/bound(0.005, cvar("hud_configure_grid_y"), 0.2) + 0.5) * bound(0.005, cvar("hud_configure_grid_y"), 0.2) * vid_conheight;
1090 if(cvar("hud_configure_checkcollisions"))
1092 mySize = HUD_Panel_CheckResize(id, mySize, resizeorigin);
1095 // minimum panel size cap, do this once more so we NEVER EVER EVER have a panel smaller than this, JUST IN CASE above code still makes the panel eg negative (impossible to resize back without changing cvars manually then)
1096 mySize_x = max(0.025 * vid_conwidth, mySize_x);
1097 mySize_y = max(0.025 * vid_conheight, mySize_y);
1099 // do another pos check, as size might have changed by now
1100 if(resizeCorner == 1) {
1101 myPos_x = resizeorigin_x - mySize_x;
1102 myPos_y = resizeorigin_y - mySize_y;
1103 } else if(resizeCorner == 2) {
1104 myPos_x = resizeorigin_x;
1105 myPos_y = resizeorigin_y - mySize_y;
1106 } else if(resizeCorner == 3) {
1107 myPos_x = resizeorigin_x - mySize_x;
1108 myPos_y = resizeorigin_y;
1109 } else { // resizeCorner == 4
1110 myPos_x = resizeorigin_x;
1111 myPos_y = resizeorigin_y;
1114 if(cvar("hud_configure_checkcollisions_debug"))
1115 if(cvar("hud_configure_checkcollisions"))
1116 drawfill(myPos, mySize, '0 1 0', .3, DRAWFLAG_NORMAL);
1119 s = strcat(ftos(mySize_x/vid_conwidth), " ", ftos(mySize_y/vid_conheight));
1120 cvar_set(strcat("hud_", HUD_Panel_GetName(id), "_size"), s);
1122 s = strcat(ftos(myPos_x/vid_conwidth), " ", ftos(myPos_y/vid_conheight));
1123 cvar_set(strcat("hud_", HUD_Panel_GetName(id), "_pos"), s);
1127 float prevMouseClicked; // previous state
1128 float prevMouseClickedTime; // time during previous mouse click, to check for doubleclicks
1129 vector prevMouseClickedPos; // pos during previous mouse click, to check for doubleclicks
1132 float menu_enabled_time;
1133 float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
1138 // allow console bind to work
1141 con_keys = findkeysforcommand("toggleconsole");
1142 keys = tokenize(con_keys);
1144 float hit_con_bind, i;
1145 for (i = 0; i < keys; ++i)
1147 if(nPrimary == stof(argv(i)))
1151 if(nPrimary == K_MOUSE1)
1153 if(bInputType == 0) { // key pressed
1157 else if(bInputType == 1) {// key released
1162 else if(nPrimary == K_ESCAPE)
1164 disable_menu_alphacheck = 1;
1166 menu_enabled_time = time;
1167 localcmd("menu_showhudexit\n");
1170 else if(hit_con_bind)
1173 return true; // Suppress ALL other input
1176 void HUD_Panel_Mouse()
1178 // TODO: needs better check... is there any float that contains the current state of the menu? _menu_alpha isn't apparently updated the frame the menu gets enabled
1179 if (menu_enabled == 0) // menu dialog closed, enable normal alpha stuff again
1180 disable_menu_alphacheck = 0;
1181 if (cvar("_menu_alpha") == 0 && time - menu_enabled_time > 0.5)
1185 print("Disable menu_alphacheck: ", ftos(disable_menu_alphacheck), "\n");
1186 print("Highlighted: ", ftos(highlightedPanel), "\n");
1187 print("Menu alpha: ", cvar_string("_menu_alpha"), "\n");
1190 if(mouseClicked == 0 && disable_menu_alphacheck != 2) { // don't reset these variables in disable_menu_alphacheck mode 2!
1191 highlightedPanel = -1;
1192 highlightedAction = 0;
1195 mousepos = mousepos + getmousepos();
1197 mousepos_x = bound(0, mousepos_x, vid_conwidth);
1198 mousepos_y = bound(0, mousepos_y, vid_conheight);
1200 drawpic(mousepos, strcat("gfx/menu/", cvar_string("menu_skin"), "/cursor.tga"), '32 32 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1208 for(i = 0; i < HUD_PANEL_NUM; ++i)
1210 panelPos = HUD_Panel_GetPos(i);
1211 panelSize = HUD_Panel_GetSize(i);
1212 border = HUD_Panel_GetBorder(i);
1213 if(prevMouseClicked == 0) {
1215 if(mousepos_x >= panelPos_x && mousepos_y >= panelPos_y && mousepos_x <= panelPos_x + panelSize_x && mousepos_y <= panelPos_y + panelSize_y)
1217 highlightedPanel = i;
1218 highlightedAction = 1;
1220 // resize from topleft border
1221 else if(mousepos_x >= panelPos_x - border && mousepos_y >= panelPos_y - border && mousepos_x <= panelPos_x + 0.5 * panelSize_x && mousepos_y <= panelPos_y + 0.5 * panelSize_y)
1223 highlightedPanel = i;
1224 highlightedAction = 2;
1227 // resize from topright border
1228 else if(mousepos_x >= panelPos_x + 0.5 * panelSize_x && mousepos_y >= panelPos_y - border && mousepos_x <= panelPos_x + panelSize_x + border && mousepos_y <= panelPos_y + 0.5 * panelSize_y)
1230 highlightedPanel = i;
1231 highlightedAction = 2;
1234 // resize from bottomleft border
1235 else if(mousepos_x >= panelPos_x - border && mousepos_y >= panelPos_y + 0.5 * panelSize_y && mousepos_x <= panelPos_x + 0.5 * panelSize_x && mousepos_y <= panelPos_y + panelSize_y + border)
1237 highlightedPanel = i;
1238 highlightedAction = 2;
1241 // resize from bottomright border
1242 else if(mousepos_x >= panelPos_x + 0.5 * panelSize_x && mousepos_y >= panelPos_y + 0.5 * panelSize_y && mousepos_x <= panelPos_x + panelSize_x + border && mousepos_y <= panelPos_y + panelSize_y + border)
1244 highlightedPanel = i;
1245 highlightedAction = 2;
1250 if(highlightedPanel == i)
1252 if(prevMouseClicked == 0)
1254 if(highlightedAction == 1)
1255 panel_click_distance = mousepos - panelPos;
1256 else if(highlightedAction == 2)
1258 if(resizeCorner == 1) {
1259 panel_click_distance = mousepos - panelPos;
1260 panel_click_resizeorigin = panelPos + panelSize;
1261 } else if(resizeCorner == 2) {
1262 panel_click_distance_x = panelSize_x - mousepos_x + panelPos_x;
1263 panel_click_distance_y = mousepos_y - panelPos_y;
1264 panel_click_resizeorigin = panelPos + eY * panelSize_y;
1265 } else if(resizeCorner == 3) {
1266 panel_click_distance_x = mousepos_x - panelPos_x;
1267 panel_click_distance_y = panelSize_y - mousepos_y + panelPos_y;
1268 panel_click_resizeorigin = panelPos + eX * panelSize_x;
1269 } else if(resizeCorner == 4) {
1270 panel_click_distance = panelSize - mousepos + panelPos;
1271 panel_click_resizeorigin = panelPos;
1276 if(cvar("hud_configure_checkcollisions_debug"))
1277 drawfill(panelPos, panelSize, '1 0 0', .3, DRAWFLAG_NORMAL);
1279 if(highlightedAction == 1)
1280 HUD_Panel_SetPos(i, mousepos - panel_click_distance);
1281 else if(highlightedAction == 2)
1282 HUD_Panel_SetPosSize(i);
1286 // doubleclick check
1287 if(time - prevMouseClickedTime < 0.4 && prevMouseClicked == 0 && prevMouseClickedPos == mousepos && highlightedPanel >= 0)
1289 mouseClicked = 0; // to prevent spam, I guess.
1290 disable_menu_alphacheck = 2;
1292 menu_enabled_time = time;
1293 localcmd("menu_showhudoptions ", ftos(highlightedPanel), "\n");
1296 if(prevMouseClicked == 0)
1298 prevMouseClickedTime = time;
1299 prevMouseClickedPos = mousepos;
1302 prevMouseClicked = mouseClicked;
1305 // Weapon icons (#0)
1307 float weaponspace[10];
1308 void HUD_WeaponIcons_Clear()
1311 for(idx = 0; idx < 10; ++idx)
1312 weaponspace[idx] = 0;
1315 entity weaponorder[WEP_MAXCOUNT];
1316 void weaponorder_swap(float i, float j, entity pass)
1320 weaponorder[i] = weaponorder[j];
1324 string weaponorder_cmp_str_save;
1325 string weaponorder_cmp_str;
1326 float weaponorder_cmp(float i, float j, entity pass)
1329 ai = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[i].weapon), 0);
1330 aj = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[j].weapon), 0);
1331 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)
1334 void HUD_WeaponIcons(void)
1336 float id = HUD_PANEL_WEAPONICONS;
1337 float alpha, stat_weapons; // "constants"
1338 vector pos, mySize, accuracy_color;
1339 float i, weapid, fade, weapon_stats, weapon_hit, weapon_damage, weapon_cnt; // variables
1341 pos = HUD_Panel_GetPos(id);
1342 mySize = HUD_Panel_GetSize(id);
1344 stat_weapons = getstati(STAT_WEAPONS);
1346 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1348 self = get_weaponinfo(i);
1349 if(self.impulse >= 0)
1353 // TODO make this configurable
1354 weaponorder_cmp_str = strcat(" ", weaponorder_byimpulse, " ");
1356 if(weaponorder_cmp_str != weaponorder_cmp_str_save)
1358 if(weaponorder_cmp_str_save)
1359 strunzone(weaponorder_cmp_str_save);
1360 weaponorder_cmp_str_save = strzone(weaponorder_cmp_str);
1362 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1364 self = get_weaponinfo(i);
1365 if(self.impulse >= 0)
1367 weaponorder[weapon_cnt] = self;
1371 heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, world);
1374 HUD_Panel_DrawBg(id, pos, mySize, 0);
1376 padding = HUD_Panel_GetPadding(id);
1379 pos += '1 1 0' * padding;
1380 mySize -= '2 2 0' * padding;
1384 weapon_stats = getstati(STAT_DAMAGE_HITS);
1385 weapon_number = weapon_stats & 63;
1386 weapon_hits[weapon_number-WEP_FIRST] = floor(weapon_stats / 64);
1388 weapon_stats = getstati(STAT_DAMAGE_FIRED);
1389 weapon_number = weapon_stats & 63;
1390 weapon_fired[weapon_number-WEP_FIRST] = floor(weapon_stats / 64);
1392 if(cvar_or("hud_weaponicons_fade", 1))
1394 fade = 3.2 - 2 * (time - weapontime);
1395 fade = bound(0.7, fade, 1);
1400 HUD_WeaponIcons_Clear();
1402 float rows, columns;
1403 rows = mySize_y/mySize_x;
1404 rows = bound(1, floor((sqrt(4 * (2/1) * rows * WEP_COUNT + rows * rows) + rows + 0.5) / 2), WEP_COUNT);
1405 // ^^^ weapon icon aspect goes here
1407 columns = ceil(WEP_COUNT/rows);
1409 for(i = 0; i < weapon_cnt; ++i)
1411 self = weaponorder[i];
1412 weapid = self.impulse;
1414 alpha = (self.weapon == activeweapon) ? 1 : 0.6;
1416 weapon_hit = weapon_hits[self.weapon-WEP_FIRST];
1417 weapon_damage = weapon_fired[self.weapon-WEP_FIRST];
1419 // draw background behind currently selected weapon
1420 if(self.weapon == activeweapon)
1421 drawpic_skin(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows), "weapon_current_bg", eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows), '1 1 1', fade * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1423 // draw the weapon accuracy on the HUD
1424 if(hud_accuracy_hud && !(gametype == GAME_RACE || gametype == GAME_CTS))
1427 weapon_stats = floor(100 * weapon_hit / weapon_damage);
1429 accuracy_color = HUD_AccuracyColor(weapon_stats);
1431 drawpic_skin(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows), "weapon_accuracy", eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows), accuracy_color, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1434 // draw the weapon icon
1435 if((self.impulse >= 0) && (stat_weapons & self.weapons))
1437 drawpic_skin(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows), strcat("weapon", self.netname), eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows), '1 1 1', fade * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1439 if(cvar_or("hud_weaponicons_number", 1))
1440 drawstring(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows), ftos(weapid), '1 1 0' * 0.5 * mySize_y*(1/rows), '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1442 // draw a "ghost weapon icon" if you don't have the weapon
1445 drawpic_skin(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows), strcat("weapon", self.netname), eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows), '0 0 0', HUD_Panel_GetFgAlpha(id) * 0.5, DRAWFLAG_NORMAL);
1460 float GetAmmoStat(float i)
1464 case 0: return STAT_SHELLS;
1465 case 1: return STAT_NAILS;
1466 case 2: return STAT_ROCKETS;
1467 case 3: return STAT_CELLS;
1468 case 4: return STAT_FUEL;
1473 float GetAmmoItemCode(float i)
1477 case 0: return IT_SHELLS;
1478 case 1: return IT_NAILS;
1479 case 2: return IT_ROCKETS;
1480 case 3: return IT_CELLS;
1481 case 4: return IT_FUEL;
1486 string GetAmmoPicture(float i)
1490 case 0: return "ammo_shells";
1491 case 1: return "ammo_bullets";
1492 case 2: return "ammo_rockets";
1493 case 3: return "ammo_cells";
1494 case 4: return "ammo_fuel";
1499 void DrawAmmoItem(vector myPos, vector mySize, float itemcode, float currently_selected)
1502 a = getstati(GetAmmoStat(itemcode)); // how much ammo do we have of type itemcode?
1513 if(currently_selected)
1518 vector newSize, newPos;
1519 if(mySize_x/mySize_y > 3)
1521 newSize_x = 3 * mySize_y;
1522 newSize_y = mySize_y;
1524 newPos_x = myPos_x + (mySize_x - newSize_x) / 2;
1529 newSize_y = 1/3 * mySize_x;
1530 newSize_x = mySize_x;
1532 newPos_y = myPos_y + (mySize_y - newSize_y) / 2;
1536 vector picpos, numpos;
1537 if(cvar("hud_inventory_iconalign"))
1540 picpos = newPos + eX * 2 * newSize_y;
1544 numpos = newPos + eX * newSize_y;
1548 if (currently_selected)
1549 drawpic_skin(newPos, "ammo_current_bg", newSize, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_INVENTORY), DRAWFLAG_NORMAL);
1551 drawfont = hud_bigfont;
1552 drawstring_aspect(numpos, ftos(a), eX * (2/3) * newSize_x + eY * newSize_y, newSize_y, color, HUD_Panel_GetFgAlpha(HUD_PANEL_INVENTORY) * alpha, DRAWFLAG_NORMAL);
1553 drawfont = hud_font;
1554 drawpic_skin(picpos, GetAmmoPicture(itemcode), '1 1 0' * newSize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_INVENTORY) * alpha, DRAWFLAG_NORMAL);
1557 void HUD_Inventory(void)
1559 float id = HUD_PANEL_INVENTORY;
1560 float i, currently_selected;
1563 pos = HUD_Panel_GetPos(id);
1564 mySize = HUD_Panel_GetSize(id);
1566 HUD_Panel_DrawBg(id, pos, mySize, 0);
1568 padding = HUD_Panel_GetPadding(id);
1571 pos += '1 1 0' * padding;
1572 mySize -= '2 2 0' * padding;
1575 float rows, columns;
1576 rows = mySize_y/mySize_x;
1577 rows = bound(1, floor((sqrt(4 * (3/1) * rows * AMMO_COUNT + rows * rows) + rows + 0.5) / 2), AMMO_COUNT);
1578 // ^^^ ammo item aspect goes here
1580 columns = ceil(AMMO_COUNT/rows);
1584 for (i = 0; i < AMMO_COUNT; ++i) {
1585 currently_selected = getstati(STAT_ITEMS) & GetAmmoItemCode(i);
1586 if(cvar("hud_inventory_onlycurrent")) {
1589 if (currently_selected || hud_configure)
1590 DrawAmmoItem(pos, mySize, i, currently_selected);
1593 DrawAmmoItem(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows), eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows), i, currently_selected);
1598 column = column + 1;
1604 void DrawNumIcon(float id, vector myPos, vector mySize, float x, string icon, float left, vector color)
1606 vector newSize, newPos;
1607 if(mySize_x/mySize_y > 3)
1609 newSize_x = 3 * mySize_y;
1610 newSize_y = mySize_y;
1612 newPos_x = myPos_x + (mySize_x - newSize_x) / 2;
1617 newSize_y = 1/3 * mySize_x;
1618 newSize_x = mySize_x;
1620 newPos_y = myPos_y + (mySize_y - newSize_y) / 2;
1624 vector picpos, numpos;
1626 iconalign = cvar(strcat("hud_", HUD_Panel_GetName(id), "_iconalign"));
1629 if(iconalign == 1 || iconalign == 3) // right align
1632 picpos = newPos + eX * 2 * newSize_y;
1636 numpos = newPos + eX * newSize_y;
1642 if(iconalign == 0 || iconalign == 3) // left align
1644 numpos = newPos + eX * newSize_y;
1650 picpos = newPos + eX * 2 * newSize_y;
1654 drawfont = hud_bigfont;
1655 drawstring_aspect(numpos, ftos(x), eX * (2/3) * newSize_x + eY * newSize_y, newSize_y, color, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1656 drawfont = hud_font;
1657 drawpic_skin(picpos, icon, '1 1 0' * newSize_y, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1662 void HUD_Powerups(void) {
1663 float id = HUD_PANEL_POWERUPS;
1665 stat_items = getstati(STAT_ITEMS);
1669 if not(stat_items & IT_STRENGTH)
1670 if not(stat_items & IT_INVINCIBLE)
1673 if (getstati(STAT_HEALTH) <= 0)
1678 pos = HUD_Panel_GetPos(id);
1679 mySize = HUD_Panel_GetSize(id);
1681 HUD_Panel_DrawBg(id, pos, mySize, 0);
1683 padding = HUD_Panel_GetPadding(id);
1686 pos += '1 1 0' * padding;
1687 mySize -= '2 2 0' * padding;
1690 float strength_time, shield_time;
1692 strength_time = bound(0, getstatf(STAT_STRENGTH_FINISHED) - time, 99);
1693 shield_time = bound(0, getstatf(STAT_INVINCIBLE_FINISHED) - time, 99);
1701 vector barpos, barsize;
1705 string leftname, rightname;
1706 float leftcnt, rightcnt;
1707 float leftexact, rightexact;
1708 float leftalpha, rightalpha;
1709 if (cvar(strcat("hud_", HUD_Panel_GetName(id), "_flip"))) {
1710 leftname = "strength";
1711 leftcnt = ceil(strength_time);
1712 leftexact = strength_time;
1714 rightname = "shield";
1715 rightcnt = ceil(shield_time);
1716 rightexact = shield_time;
1718 leftname = "shield";
1719 leftcnt = ceil(shield_time);
1720 leftexact = shield_time;
1722 rightname = "strength";
1723 rightcnt = ceil(strength_time);
1724 rightexact = strength_time;
1726 leftalpha = bound(0, leftexact, 1);
1727 rightalpha = bound(0, rightexact, 1);
1729 float baralign, iconalign;
1730 baralign = cvar(strcat("hud_", HUD_Panel_GetName(id), "_baralign"));
1731 iconalign = cvar(strcat("hud_", HUD_Panel_GetName(id), "_iconalign"));
1733 if (mySize_x/mySize_y > 4)
1737 if(baralign == 1 || baralign == 3) { // right align
1738 barpos = pos + eX * 0.5 * mySize_x - eX * 0.5 * mySize_x * min(1, leftcnt/30);
1739 barsize = eX * 0.5 * mySize_x * min(1, leftcnt/30) + eY * mySize_y;
1740 } else { // left align
1742 barsize = eX * 0.5 * mySize_x * min(1, leftcnt/30) + eY * mySize_y;
1745 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1746 DrawNumIcon(id, pos, eX * 0.5 * mySize_x + eY * mySize_y, leftcnt, leftname, 1, '1 1 1');
1749 // drawpic_skin_expanding_two(picpos, leftname, '1 1 0' * mySize_y, '1 1 1', leftalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_ADDITIVE, bound(0, (leftcnt - leftexact) / 0.5, 1));
1751 // drawpic_skin(picpos, leftname, eX * (1/6) * mySize_x + eY * mySize_y, '1 1 1', leftalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1756 if(baralign == 0 || baralign == 3) { // left align
1757 barpos = pos + eX * 0.5 * mySize_x;
1758 barsize = eX * 0.5 * mySize_x * min(1, rightcnt/30) + eY * mySize_y;
1759 } else { // right align
1760 barpos = pos + eX * mySize_x - eX * 0.5 * mySize_x * min(1, rightcnt/30);
1761 barsize = eX * 0.5 * mySize_x * min(1, rightcnt/30) + eY * mySize_y;
1764 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1765 DrawNumIcon(id, pos + eX * 0.5 * mySize_x, eX * 0.5 * mySize_x + eY * mySize_y, rightcnt, rightname, 0, '1 1 1');
1768 else if (mySize_x/mySize_y > 1.5)
1772 if(baralign == 1 || baralign == 3) { // right align
1773 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, leftcnt/30);
1774 barsize = eX * mySize_x * min(1, leftcnt/30) + eY * 0.5 * mySize_y;
1775 } else { // left align
1777 barsize = eX * mySize_x * min(1, leftcnt/30) + eY * 0.5 * mySize_y;
1780 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1781 DrawNumIcon(id, pos, eX * mySize_x + eY * 0.5 * mySize_y, leftcnt, leftname, 1, '1 1 1');
1786 if(baralign == 0 || baralign == 3) { // left align
1787 barpos = pos + eY * 0.5 * mySize_y;
1788 barsize = eX * mySize_x * min(1, rightcnt/30) + eY * 0.5 * mySize_y;
1789 } else { // right align
1790 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, rightcnt/30) + eY * 0.5 * mySize_y;
1791 barsize = eX * mySize_x * min(1, rightcnt/30) + eY * 0.5 * mySize_y;
1794 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1795 DrawNumIcon(id, pos + eY * 0.5 * mySize_y, eX * mySize_x + eY * 0.5 * mySize_y, rightcnt, rightname, 0, '1 1 1');
1802 if(baralign == 1 || baralign == 3) { // down align
1803 barpos = pos + eY * mySize_y - eY * mySize_y * min(1, leftcnt/30);
1804 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/30);
1805 } else { // up align
1807 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/30);
1810 if(iconalign == 1 || iconalign == 3) { // down align
1811 picpos = pos + eX * 0.05 * mySize_x + eY * (mySize_y - 0.65 * mySize_x);
1812 numpos = pos + eY * mySize_y - eY * 0.25 * mySize_x;
1813 } else { // up align
1814 picpos = pos + eX * 0.05 * mySize_x;
1815 numpos = pos + eY * 0.4 * mySize_x;
1818 HUD_Panel_DrawProgressBar(barpos, 1, barsize, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1820 drawpic_skin_expanding_two(picpos, leftname, '0.4 0.4 0' * mySize_x, '1 1 1', leftalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_ADDITIVE, bound(0, (leftcnt - leftexact) / 0.5, 1));
1822 drawpic_skin(picpos, leftname, '0.4 0.4 0' * mySize_x, '1 1 1', leftalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1823 drawstring_aspect(numpos, ftos(leftcnt), eX * 0.5 * mySize_x + eY * 0.25 * mySize_x, 0.25 * mySize_x, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1828 if(baralign == 0 || baralign == 3) { // up align
1829 barpos = pos + eX * 0.5 * mySize_x;
1830 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, rightcnt/30);
1831 } else { // down align
1832 barpos = pos + eY * mySize_y - eY * mySize_y * min(1, rightcnt/30) + eX * 0.5 * mySize_x;
1833 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, rightcnt/30);
1836 if(iconalign == 0 || iconalign == 3) { // up align
1837 picpos = pos + eX * 0.05 * mySize_x + eX * 0.5 * mySize_x;
1838 numpos = pos + eY * 0.4 * mySize_x + eX * 0.5 * mySize_x;
1839 } else { // down align
1840 picpos = pos + eX * 0.05 * mySize_x + eY * (mySize_y - 0.65 * mySize_x) + eX * 0.5 * mySize_x;
1841 numpos = pos + eY * mySize_y - eY * 0.25 * mySize_x + eX * 0.5 * mySize_x;
1844 HUD_Panel_DrawProgressBar(barpos, 1, barsize, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1846 drawpic_skin_expanding_two(picpos, rightname, '0.4 0.4 0' * mySize_x, '1 1 1', rightalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_ADDITIVE, bound(0, (rightcnt - rightexact) / 0.5, 1));
1848 drawpic_skin(picpos, rightname, '0.4 0.4 0' * mySize_x, '1 1 1', rightalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1849 drawstring_aspect(numpos, ftos(rightcnt), eX * 0.5 * mySize_x + eY * 0.25 * mySize_x, 0.25 * mySize_x, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1854 // Health/armor (#3)
1856 void HUD_HealthArmor(void)
1858 float id = HUD_PANEL_HEALTHARMOR;
1860 pos = HUD_Panel_GetPos(id);
1861 mySize = HUD_Panel_GetSize(id);
1863 HUD_Panel_DrawBg(id, pos, mySize, 0);
1865 padding = HUD_Panel_GetPadding(id);
1868 pos += '1 1 0' * padding;
1869 mySize -= '2 2 0' * padding;
1872 float armor, health;
1873 armor = getstati(STAT_ARMOR);
1874 health = getstati(STAT_HEALTH);
1877 fuel = getstati(GetAmmoStat(4)); // how much fuel do we have?
1889 vector barpos, barsize;
1893 float baralign, iconalign;
1894 baralign = cvar(strcat("hud_", HUD_Panel_GetName(id), "_baralign"));
1895 iconalign = cvar(strcat("hud_", HUD_Panel_GetName(id), "_iconalign"));
1897 if(cvar("hud_healtharmor") == 2) // combined health and armor display
1900 v = healtharmor_maxdamage(health, armor, armorblockpercent);
1905 if(baralign == 1 || baralign == 3) { // right align
1906 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, x/400);
1907 barsize = eX * mySize_x * min(1, x/400) + eY * mySize_y;
1908 } else { // left align
1910 barsize = eX * mySize_x * min(1, x/400) + eY * mySize_y;
1914 if(v_z) // NOT fully armored
1916 biggercount = "health";
1917 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor("health"), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1919 drawpic_skin(pos + eX * mySize_x - eX * 0.5 * mySize_y, "armor", '0.5 0.5 0' * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id) * armor / health, DRAWFLAG_NORMAL);
1923 biggercount = "armor";
1924 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor("armor"), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1926 drawpic_skin(pos + eX * mySize_x - eX * 0.5 * mySize_y, "health", '0.5 0.5 0' * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1928 DrawNumIcon(id, pos, mySize, x, biggercount, 1, HUD_Get_Num_Color(x, 2 * 200));
1933 if(baralign == 0 || baralign == 3) { // left align
1934 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, fuel/100);
1935 barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.2 * mySize_y;
1938 barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.2 * mySize_y;
1940 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor("fuel"), HUD_Panel_GetFgAlpha(id) * 0.8, DRAWFLAG_NORMAL);
1945 string leftname, rightname;
1946 float leftcnt, rightcnt;
1947 float leftactive, rightactive;
1948 float leftalpha, rightalpha;
1949 if (cvar(strcat("hud_", HUD_Panel_GetName(id), "_flip"))) { // old style layout with armor left/top of health
1954 leftalpha = min((armor+10)/55, 1);
1956 rightname = "health";
1961 leftname = "health";
1966 rightname = "armor";
1970 rightalpha = min((armor+10)/55, 1);
1973 if (mySize_x/mySize_y > 4)
1977 if(baralign == 1 || baralign == 3) { // right align
1978 barpos = pos + eX * 0.5 * mySize_x - eX * 0.5 * mySize_x * min(1, leftcnt/200);
1979 barsize = eX * 0.5 * mySize_x * min(1, leftcnt/200) + eY * mySize_y;
1980 } else { // left align
1982 barsize = eX * 0.5 * mySize_x * min(1, leftcnt/200) + eY * mySize_y;
1985 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1986 DrawNumIcon(id, pos, eX * 0.5 * mySize_x + eY * mySize_y, leftcnt, leftname, 1, HUD_Get_Num_Color(leftcnt, 200));
1991 if(baralign == 0 || baralign == 3) { // left align
1992 barpos = pos + eX * 0.5 * mySize_x;
1993 barsize = eX * 0.5 * mySize_x * min(1, rightcnt/200) + eY * mySize_y;
1994 } else { // right align
1995 barpos = pos + eX * mySize_x - eX * 0.5 * mySize_x * min(1, rightcnt/200);
1996 barsize = eX * 0.5 * mySize_x * min(1, rightcnt/200) + eY * mySize_y;
1999 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2000 DrawNumIcon(id, pos + eX * 0.5 * mySize_x, eX * 0.5 * mySize_x + eY * mySize_y, rightcnt, rightname, 0, HUD_Get_Num_Color(leftcnt, 200));
2005 if(baralign == 0 || baralign == 3) { // left align
2006 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, fuel/100);
2007 barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.2 * mySize_y;
2010 barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.2 * mySize_y;
2012 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor("fuel"), HUD_Panel_GetFgAlpha(id) * 0.8, DRAWFLAG_NORMAL);
2015 else if (mySize_x/mySize_y > 1.5)
2019 if(baralign == 1 || baralign == 3) { // right align
2020 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, leftcnt/200);
2021 barsize = eX * mySize_x * min(1, rightcnt/200) + eY * 0.5 * mySize_y;
2022 } else { // left align
2024 barsize = eX * mySize_x * min(1, rightcnt/200) + eY * 0.5 * mySize_y;
2027 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2028 DrawNumIcon(id, pos, eX * mySize_x + eY * 0.5 * mySize_y, leftcnt, leftname, 1, HUD_Get_Num_Color(leftcnt, 200));
2033 if(baralign == 0 || baralign == 3) { // left align
2034 barpos = pos + eY * 0.5 * mySize_y;
2035 barsize = eX * mySize_x * min(1, rightcnt/200) + eY * 0.5 * mySize_y;
2036 } else { // right align
2037 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, rightcnt/200) + eY * 0.5 * mySize_y;
2038 barsize = eX * mySize_x * min(1, rightcnt/200) + eY * 0.5 * mySize_y;
2041 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2042 DrawNumIcon(id, pos + eY * 0.5 * mySize_y, eX * mySize_x + eY * 0.5 * mySize_y, rightcnt, rightname, 0, HUD_Get_Num_Color(leftcnt, 200));
2047 if(baralign == 0 || baralign == 3) { // left align
2048 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, fuel/100);
2049 barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.1 * mySize_y;
2052 barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.1 * mySize_y;
2054 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor("fuel"), HUD_Panel_GetFgAlpha(id) * 0.8, DRAWFLAG_NORMAL);
2061 if(baralign == 1 || baralign == 3) { // down align
2062 barpos = pos + eY * mySize_y - eY * mySize_y * min(1, leftcnt/200);
2063 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/200);
2064 } else { // up align
2066 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/200);
2069 if(iconalign == 1 || iconalign == 3) { // down align
2070 picpos = pos + eX * 0.05 * mySize_x + eY * (mySize_y - 0.65 * mySize_x);
2071 numpos = pos + eY * mySize_y - eY * 0.25 * mySize_x;
2072 } else { // up align
2073 picpos = pos + eX * 0.05 * mySize_x;
2074 numpos = pos + eY * 0.4 * mySize_x;
2077 HUD_Panel_DrawProgressBar(barpos, 1, barsize, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2078 drawpic_skin(picpos, leftname, '0.4 0.4 0' * mySize_x, '1 1 1', leftalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2079 drawstring_aspect(numpos, ftos(leftcnt), eX * 0.5 * mySize_x + eY * 0.25 * mySize_x, 0.25 * mySize_x, HUD_Get_Num_Color(leftcnt, 200), HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2084 if(baralign == 0 || baralign == 3) { // up align
2085 barpos = pos + eX * 0.5 * mySize_x;
2086 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, rightcnt/200);
2087 } else { // down align
2088 barpos = pos + eY * mySize_y - eY * mySize_y * min(1, rightcnt/200) + eX * 0.5 * mySize_x;
2089 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, rightcnt/200);
2092 if(iconalign == 0 || iconalign == 3) { // up align
2093 picpos = pos + eX * 0.05 * mySize_x + eX * 0.5 * mySize_x;
2094 numpos = pos + eY * 0.4 * mySize_x + eX * 0.5 * mySize_x;
2095 } else { // down align
2096 picpos = pos + eX * 0.05 * mySize_x + eY * (mySize_y - 0.65 * mySize_x) + eX * 0.5 * mySize_x;
2097 numpos = pos + eY * mySize_y - eY * 0.25 * mySize_x + eX * 0.5 * mySize_x;
2100 HUD_Panel_DrawProgressBar(barpos, 1, barsize, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2101 drawpic_skin(picpos, rightname, '0.4 0.4 0' * mySize_x, '1 1 1', rightalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2102 drawstring_aspect(numpos, ftos(rightcnt), eX * 0.5 * mySize_x + eY * 0.25 * mySize_x, 0.25 * mySize_x, HUD_Get_Num_Color(rightcnt, 200), HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2107 if(baralign == 0 || baralign == 3) { // left align
2109 barsize = eX * 0.05 * mySize_x + eY * mySize_y * min(1, fuel/100);
2111 barpos = pos + eY * mySize_y - eY * mySize_y * min(1, fuel/100);
2112 barsize = eX * 0.05 * mySize_x + eY * mySize_y * min(1, fuel/100);
2114 HUD_Panel_DrawProgressBar(barpos, 1, barsize, HUD_Panel_GetProgressBarColor("fuel"), HUD_Panel_GetFgAlpha(id) * 0.8, DRAWFLAG_NORMAL);
2121 // Notification area (#4)
2124 string Weapon_SuicideMessage(float deathtype)
2126 w_deathtype = deathtype;
2127 get_weaponinfo(DEATH_WEAPONOF(deathtype)).weapon_func(WR_SUICIDEMESSAGE);
2128 return w_deathtypestring;
2131 string Weapon_KillMessage(float deathtype)
2133 w_deathtype = deathtype;
2134 get_weaponinfo(DEATH_WEAPONOF(deathtype)).weapon_func(WR_KILLMESSAGE);
2135 return w_deathtypestring;
2138 float killnotify_times[10];
2139 float killnotify_deathtype[10];
2140 float killnotify_actiontype[10]; // 0 = "Y [used by] X", 1 = "X [did action to] Y"
2141 string killnotify_attackers[10];
2142 string killnotify_victims[10];
2143 void HUD_KillNotify_Push(string attacker, string victim, float actiontype, float wpn)
2146 for (i = 9; i > 0; --i) {
2147 killnotify_times[i] = killnotify_times[i-1];
2148 killnotify_deathtype[i] = killnotify_deathtype[i-1];
2149 killnotify_actiontype[i] = killnotify_actiontype[i-1];
2150 if(killnotify_attackers[i])
2151 strunzone(killnotify_attackers[i]);
2152 killnotify_attackers[i] = strzone(killnotify_attackers[i-1]);
2153 if(killnotify_victims[i])
2154 strunzone(killnotify_victims[i]);
2155 killnotify_victims[i] = strzone(killnotify_victims[i-1]);
2157 killnotify_times[0] = time;
2158 killnotify_deathtype[0] = wpn;
2159 killnotify_actiontype[0] = actiontype;
2160 if(killnotify_attackers[0])
2161 strunzone(killnotify_attackers[0]);
2162 killnotify_attackers[0] = strzone(attacker);
2163 if(killnotify_victims[0])
2164 strunzone(killnotify_victims[0]);
2165 killnotify_victims[0] = strzone(victim);
2168 void HUD_KillNotify(string s1, string s2, string s3, float type, float msg)
2172 alsoprint = (cvar("hud_notify_print") || !HUD_Panel_CheckActive(4)); // print message to console if: notify panel disabled, or cvar to do so enabled
2174 if(msg == MSG_SUICIDE) {
2176 w = DEATH_WEAPONOF(type);
2178 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2180 print("^1", s1, "^1 ", Weapon_SuicideMessage(type), "\n");
2181 } else if (type == DEATH_KILL) {
2182 HUD_KillNotify_Push(s1, "", 0, DEATH_KILL);
2184 print ("^1",s1, "^1 couldn't take it anymore\n");
2185 } else if (type == DEATH_ROT) {
2186 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2188 print ("^1",s1, "^1 died\n");
2189 } else if (type == DEATH_NOAMMO) {
2190 HUD_KillNotify_Push(s1, "", 0, DEATH_NOAMMO);
2192 print ("^7",s1, "^7 committed suicide. What's the point of living without ammo?\n");
2193 } else if (type == DEATH_CAMP) {
2194 HUD_KillNotify_Push(s1, "", 0, DEATH_CAMP);
2196 print ("^1",s1, "^1 thought they found a nice camping ground\n");
2197 } else if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
2198 HUD_KillNotify_Push(s1, "", 0, type);
2200 print ("^1",s1, "^1 didn't become friends with the Lord of Teamplay\n");
2201 } else if (type == DEATH_CHEAT) {
2202 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2204 print ("^1",s1, "^1 unfairly eliminated themself\n");
2205 } else if (type == DEATH_FIRE) {
2206 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2208 print ("^1",s1, "^1 burned to death\n");
2209 } else if (type != DEATH_TEAMCHANGE && type != DEATH_QUIET) {
2210 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2212 print ("^1",s1, "^1 couldn't resist the urge to self-destruct\n");
2215 if (stof(s2) > 2) // killcount > 2
2216 print ("^1",s1,"^1 ended it all after a ",s2," kill spree\n");
2217 } else if(msg == MSG_KILL) {
2218 w = DEATH_WEAPONOF(type);
2220 HUD_KillNotify_Push(s2, s1, 1, w);
2222 print("^1", s1, "^1 ", Weapon_KillMessage(type), "\n");
2224 else if(type == KILL_TEAM_RED || type == KILL_TEAM_BLUE || type == KILL_TEAM_SPREE) {
2225 HUD_KillNotify_Push(s1, s2, 1, type);
2228 if(cvar("cl_gentle")) {
2229 print ("^1", s1, "^1 took action against a team mate\n");
2231 print ("^1", s1, "^1 mows down a team mate\n");
2234 if (stof(s2) > 2 && type == KILL_TEAM_SPREE) {
2235 if(cvar("cl_gentle"))
2236 print ("^1",s1,"^1 ended a ",s3," scoring spree by going against a team mate\n");
2238 print ("^1",s1,"^1 ended a ",s3," kill spree by killing a team mate\n");
2240 else if (stof(s2) > 2) {
2241 if(cvar("cl_gentle"))
2242 print ("^1",s1,"'s ^1",s3," scoring spree was ended by a team mate!\n");
2244 print ("^1",s1,"'s ^1",s3," kill spree was ended by a team mate!\n");
2247 else if(type == KILL_FIRST_BLOOD)
2248 print("^1",s1, "^1 drew first blood", "\n");
2250 else if (type == DEATH_TELEFRAG)
2251 print ("^1",s1, "^1 was telefragged by ", s2, "\n");
2252 else if (type == DEATH_DROWN) {
2253 HUD_KillNotify_Push(s2, s1, 1, DEATH_DROWN);
2255 print ("^1",s1, "^1 was drowned by ", s2, "\n");
2257 else if (type == DEATH_SLIME) {
2258 HUD_KillNotify_Push(s2, s1, 1, DEATH_SLIME);
2260 print ("^1",s1, "^1 was slimed by ", s2, "\n");
2262 else if (type == DEATH_LAVA) {
2263 HUD_KillNotify_Push(s2, s1, 1, DEATH_LAVA);
2265 print ("^1",s1, "^1 was cooked by ", s2, "\n");
2267 else if (type == DEATH_FALL) {
2268 HUD_KillNotify_Push(s2, s1, 1, DEATH_FALL);
2270 print ("^1",s1, "^1 was grounded by ", s2, "\n");
2272 else if (type == DEATH_SHOOTING_STAR) {
2273 HUD_KillNotify_Push(s2, s1, 1, DEATH_SHOOTING_STAR);
2275 print ("^1",s1, "^1 was shot into space by ", s2, "\n");
2277 else if (type == DEATH_SWAMP) {
2278 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2280 print ("^1",s1, "^1 was conserved by ", s2, "\n");
2282 else if (type == DEATH_HURTTRIGGER)
2284 HUD_KillNotify_Push(s2, s1, 1, DEATH_HURTTRIGGER);
2286 print("^1",s1, "^1 was thrown into a world of hurt by ", s2, "\n");
2287 } else if(type == DEATH_SBCRUSH) {
2288 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2290 print ("^1",s1, "^1 was crushed by ^1", s2, "\n");
2291 } else if(type == DEATH_SBMINIGUN) {
2292 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2294 print ("^1",s1, "^1 got shredded by ^1", s2, "\n");
2295 } else if(type == DEATH_SBROCKET) {
2296 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2298 print ("^1",s1, "^1 was blased to bits by ^1", s2, "\n");
2299 } else if(type == DEATH_SBBLOWUP) {
2300 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2302 print ("^1",s1, "^1 got caught in the destruction of ^1", s2, "'s vehicle\n");
2303 } else if(type == DEATH_WAKIGUN) {
2304 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2306 print ("^1",s1, "^1 was bolted down by ^1", s2, "\n");
2307 } else if(type == DEATH_WAKIROCKET) {
2308 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2310 print ("^1",s1, "^1 could find no shelter from ^1", s2, "'s rockets\n");
2311 } else if(type == DEATH_WAKIBLOWUP) {
2312 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2314 print ("^1",s1, "^1 dies when ^1", s2, "'s wakizashi dies.\n");
2315 } else if(type == DEATH_TURRET) {
2316 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2318 print ("^1",s1, "^1 was pushed into the line of fire by ^1", s2, "\n");
2319 } else if(type == DEATH_TOUCHEXPLODE) {
2320 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2322 print ("^1",s1, "^1 was pushed into an accident by ^1", s2, "\n");
2323 } else if(type == DEATH_CHEAT) {
2324 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2326 print ("^1",s1, "^1 was unfairly eliminated by ^1", s2, "\n");
2327 } else if (type == DEATH_FIRE) {
2328 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2330 print ("^1",s1, "^1 was burnt to death by ^1", s2, "\n");
2331 } else if (type == DEATH_CUSTOM) {
2332 HUD_KillNotify_Push(s2, s1, 1, DEATH_CUSTOM);
2334 print ("^1",s1, "^1 ", s2, "\n");
2336 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2338 print ("^1",s1, "^1 was fragged by ", s2, "\n");
2340 } else if(msg == MSG_SPREE) {
2341 if(type == KILL_END_SPREE) {
2342 if(cvar("cl_gentle"))
2343 print ("^1",s1,"'s ^1", s2, " scoring spree was ended by ", s3, "\n");
2345 print ("^1",s1,"'s ^1", s2, " kill spree was ended by ", s3, "\n");
2346 } else if(type == KILL_SPREE) {
2347 if(cvar("cl_gentle"))
2348 print ("^1",s1,"^1 made ",s2," scores in a row\n");
2350 print ("^1",s1,"^1 has ",s2," frags in a row\n");
2351 } else if(type == KILL_SPREE_3) {
2352 if(cvar("cl_gentle"))
2353 print (s1,"^7 made a ^1TRIPLE SCORE\n");
2355 print (s1,"^7 made a ^1TRIPLE FRAG\n");
2356 } else if(type == KILL_SPREE_5) {
2357 if(cvar("cl_gentle"))
2358 print (s1,"^7 unleashes ^1SCORING RAGE\n");
2360 print (s1,"^7 unleashes ^1RAGE\n");
2361 } else if(type == KILL_SPREE_10) {
2362 if(cvar("cl_gentle"))
2363 print (s1,"^7 made ^1TEN SCORES IN A ROW!\n");
2365 print (s1,"^7 starts the ^1MASSACRE!\n");
2366 } else if(type == KILL_SPREE_15) {
2367 if(cvar("cl_gentle"))
2368 print (s1,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
2370 print (s1,"^7 executes ^1MAYHEM!\n");
2371 } else if(type == KILL_SPREE_20) {
2372 if(cvar("cl_gentle"))
2373 print (s1,"^7 made ^1TWENTY SCORES IN A ROW!\n");
2375 print (s1,"^7 is a ^1BERSERKER!\n");
2376 } else if(type == KILL_SPREE_25) {
2377 if(cvar("cl_gentle"))
2378 print (s1,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
2380 print (s1,"^7 inflicts ^1CARNAGE!\n");
2381 } else if(type == KILL_SPREE_30) {
2382 if(cvar("cl_gentle"))
2383 print (s1,"^7 made ^1THIRTY SCORES IN A ROW!\n");
2385 print (s1,"^7 unleashes ^1ARMAGEDDON!\n");
2387 } else if(msg == MSG_KILL_ACTION) { // wtf is this? isnt it basically the same as MSG_SUICIDE?
2388 if (type == DEATH_DROWN) {
2389 HUD_KillNotify_Push(s1, "", 0, DEATH_DROWN);
2392 if(cvar("cl_gentle"))
2393 print ("^1",s1, "^1 was in the water for too long\n");
2395 print ("^1",s1, "^1 drowned\n");
2397 } else if (type == DEATH_SLIME) {
2398 HUD_KillNotify_Push(s1, "", 0, DEATH_SLIME);
2400 print ("^1",s1, "^1 was slimed\n");
2401 } else if (type == DEATH_LAVA) {
2402 HUD_KillNotify_Push(s1, "", 0, DEATH_LAVA);
2405 if(cvar("cl_gentle"))
2406 print ("^1",s1, "^1 found a hot place\n");
2408 print ("^1",s1, "^1 turned into hot slag\n");
2410 } else if (type == DEATH_FALL) {
2411 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2414 if(cvar("cl_gentle"))
2415 print ("^1",s1, "^1 tested gravity (and it worked)\n");
2417 print ("^1",s1, "^1 hit the ground with a crunch\n");
2419 } else if (type == DEATH_SHOOTING_STAR) {
2420 HUD_KillNotify_Push(s1, "", 0, DEATH_SHOOTING_STAR);
2422 print ("^1",s1, "^1 became a shooting star\n");
2423 } else if (type == DEATH_SWAMP) {
2424 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2427 if(cvar("cl_gentle"))
2428 print ("^1",s1, "^1 discovered a swamp\n");
2430 print ("^1",s1, "^1 is now conserved for centuries to come\n");
2432 } else if(type == DEATH_TURRET) {
2433 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2435 print ("^1",s1, "^1 was mowed down by a turret \n");
2436 } else if (type == DEATH_CUSTOM) {
2437 HUD_KillNotify_Push(s1, "", 0, DEATH_CUSTOM);
2439 print ("^1",s1, "^1 ", s2, "\n");
2440 } else if (type == DEATH_HURTTRIGGER) {
2441 HUD_KillNotify_Push(s1, "", 0, DEATH_HURTTRIGGER);
2443 print ("^1",s1, "^1 was in the wrong place\n");
2444 } else if(type == DEATH_TOUCHEXPLODE) {
2445 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2447 print ("^1",s1, "^1 died in an accident\n");
2448 } else if(type == DEATH_CHEAT) {
2449 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2451 print ("^1",s1, "^1 was unfairly eliminated\n");
2452 } else if(type == DEATH_FIRE) {
2453 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2456 if(cvar("cl_gentle"))
2457 print ("^1",s1, "^1 felt a little hot\n");
2459 print ("^1",s1, "^1 burnt to death\n");
2462 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2465 if(cvar("cl_gentle"))
2466 print ("^1",s1, "^1 needs a restart\n");
2468 print ("^1",s1, "^1 died\n");
2471 } else if(msg == MSG_KILL_ACTION_SPREE) {
2472 if(cvar("cl_gentle"))
2473 print ("^1",s1,"^1 needs a restart after a ",s2," scoring spree\n");
2475 print ("^1",s1,"^1 died with a ",s2," kill spree\n");
2476 } else if(msg == MSG_INFO) {
2477 if(type == INFO_GOTFLAG) { // here, s2 is the flag name
2478 HUD_KillNotify_Push(s1, s2, 0, INFO_GOTFLAG);
2479 print(s1, "^7 got the ", s2, "\n");
2480 } else if(type == INFO_LOSTFLAG) {
2481 HUD_KillNotify_Push(s1, s2, 0, INFO_LOSTFLAG);
2482 print(s1, "^7 lost the ", s2, "\n");
2483 } else if(type == INFO_PICKUPFLAG) {
2484 HUD_KillNotify_Push(s1, s2, 0, INFO_GOTFLAG);
2485 print(s1, "^7 picked up the ", s2, "\n");
2486 } else if(type == INFO_RETURNFLAG) {
2487 HUD_KillNotify_Push(s1, s2, 0, INFO_RETURNFLAG);
2488 print(s1, "^7 returned the ", s2, "\n");
2493 #define DAMAGE_CENTERPRINT_SPACER NEWLINES
2495 void HUD_Centerprint(string s1, string s2, float type, float msg)
2497 if(msg == MSG_SUICIDE) {
2498 if (type == DEATH_TEAMCHANGE) {
2499 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "You are now on: ", s1));
2500 } else if (type == DEATH_AUTOTEAMCHANGE) {
2501 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "You have been moved into a different team to improve team balance\nYou are now on: ", s1));
2502 } else if (type == DEATH_CAMP) {
2503 if(cvar("cl_gentle"))
2504 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Reconsider your tactics, camper!"));
2506 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Die camper!"));
2507 } else if (type == DEATH_NOAMMO) {
2508 if(cvar("cl_gentle"))
2509 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You are reinserted into the game for running out of ammo..."));
2511 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were killed for running out of ammo..."));
2512 } else if (type == DEATH_ROT) {
2513 if(cvar("cl_gentle"))
2514 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to preserve your health"));
2516 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You grew too old without taking your medicine"));
2517 } else if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
2518 if(cvar("cl_gentle"))
2519 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't go against team mates!"));
2521 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't shoot your team mates!"));
2522 } else if (type == DEATH_QUIET) {
2524 } else if (type == DEATH_KILL) {
2525 if(cvar("cl_gentle"))
2526 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to be more careful!"));
2528 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You killed your own dumb self!"));
2530 } else if(msg == MSG_KILL) {
2531 if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
2532 if(cvar("cl_gentle")) {
2533 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You went against", s1, ",a team mate!"));
2535 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You fragged ", s1, ", a team mate!"));
2537 } else if (type == KILL_FIRST_BLOOD) {
2538 if(cvar("cl_gentle")) {
2539 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First score"));
2541 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First blood"));
2543 } else if (type == KILL_FIRST_VICTIM) {
2544 if(cvar("cl_gentle")) {
2545 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First casualty"));
2547 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First victim"));
2549 } else if (type == KILL_TYPEFRAG) { // s2 contains "advanced kill messages" such as ping, handicap...
2550 if(cvar("cl_gentle")) {
2551 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You scored against ^7", s1, "^1 who was typing!", s2));
2553 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You typefragged ^7", s1, s2));
2555 } else if (type == KILL_TYPEFRAGGED) {
2556 if(cvar("cl_gentle")) {
2557 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were scored against by ^7", s1, "^1 while you were typing!", s2));
2559 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were typefragged by ^7", s1, s2));
2561 } else if (type == KILL_FRAG) {
2562 if(cvar("cl_gentle")) {
2563 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^4You scored against ^7", s1, s2));
2565 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^4You fragged ^7", s1, s2));
2567 } else if (type == KILL_FRAGGED) {
2568 if(cvar("cl_gentle")) {
2569 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were scored against by ^7", s1, s2));
2571 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were fragged by ^7", s1, s2));
2574 } else if(msg == MSG_KILL_ACTION) {
2575 // TODO: invent more centerprints here?
2576 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Watch your step!"));
2580 void HUD_Notify (void)
2582 float id = HUD_PANEL_NOTIFY;
2584 pos = HUD_Panel_GetPos(id);
2585 mySize = HUD_Panel_GetSize(id);
2587 HUD_Panel_DrawBg(id, pos, mySize, 0);
2589 padding = HUD_Panel_GetPadding(id);
2592 pos += '1 1 0' * padding;
2593 mySize -= '2 2 0' * padding;
2596 float entries, height;
2597 entries = bound(1, floor(14 * mySize_y/mySize_x), 12);
2598 height = mySize_y/entries;
2599 entries -= 2; // top/bottom two lines reserved for info messaged, such as spec instructions
2602 fontsize = '0.5 0.5 0' * height;
2606 when = cvar("hud_notify_time");
2608 fadetime = cvar("hud_notify_fadetime");
2612 vector pos_attacker, pos_victim;
2614 float width_attacker, width_victim;
2615 string attacker, victim;
2618 for(j = 0; j < entries; ++j)
2620 if(cvar("hud_notify_flip"))
2622 else // rather nasty hack for ordering items from the bottom up
2623 i = entries - j - 1;
2624 if(cvar("hud_notify_info_top"))
2625 i += 2; // top/bottom two lines reserved for info messaged, such as spec instructions
2629 if(killnotify_times[j] + when > time)
2632 a = bound(0, (killnotify_times[j] + when + fadetime - time) / fadetime, 1);
2636 if(killnotify_times[j] + when > time)
2642 // TODO: maybe print in team colors?
2643 // TODO: maybe this could be cleaned up somehow...
2644 // TODO: less copypaste code below
2647 if(killnotify_actiontype[j] == 0 && !hud_configure)
2649 attacker = textShortenToWidth(killnotify_attackers[j], mySize_x - 2 * height, fontsize, stringwidth_colors);
2651 width_attacker = stringwidth(attacker, TRUE, fontsize);
2652 pos_attacker = pos + eX * 0.5 * (mySize_x - width_attacker + 2 * height) + eY * 0.5 * fontsize_y + eY * i * height;
2654 weap_pos = pos + eX * 0.5 * (mySize_x - width_attacker) - eX * height + eY * i * height;
2655 if(killnotify_deathtype[j] == DEATH_GENERIC)
2657 drawpic_skin(weap_pos, "notify_death", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2658 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2660 else if(killnotify_deathtype[j] == DEATH_NOAMMO)
2662 drawpic_skin(weap_pos, "notify_outofammo", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2663 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2665 else if(killnotify_deathtype[j] == DEATH_KILL)
2667 drawpic_skin(weap_pos, "notify_selfkill", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2668 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2670 else if(killnotify_deathtype[j] == DEATH_CAMP)
2672 drawpic_skin(weap_pos, "notify_camping", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2673 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2675 else if(killnotify_deathtype[j] == KILL_TEAM_RED)
2677 drawpic_skin(weap_pos, "notify_teamkill", '2 1 0' * height, '1 0 0', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2678 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2680 else if(killnotify_deathtype[j] == KILL_TEAM_BLUE)
2682 drawpic_skin(weap_pos, "notify_teamkill", '2 1 0' * height, '0 0 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2683 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2685 else if(killnotify_deathtype[j] == DEATH_DROWN)
2687 drawpic_skin(weap_pos, "notify_water", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2688 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2690 else if(killnotify_deathtype[j] == DEATH_SLIME)
2692 drawpic_skin(weap_pos, "notify_slime", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2693 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2695 else if(killnotify_deathtype[j] == DEATH_LAVA)
2697 drawpic_skin(weap_pos, "notify_lava", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2698 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2700 else if(killnotify_deathtype[j] == DEATH_FALL)
2702 drawpic_skin(weap_pos, "notify_fall", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2703 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2705 else if(killnotify_deathtype[j] == DEATH_SHOOTING_STAR)
2707 drawpic_skin(weap_pos, "notify_shootingstar", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2708 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2710 else if(killnotify_deathtype[j] == DEATH_HURTTRIGGER || killnotify_deathtype[j] == DEATH_CUSTOM)
2712 drawpic_skin(weap_pos, "notify_void", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2713 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2715 else if(killnotify_deathtype[j] == INFO_GOTFLAG)
2717 if(killnotify_victims[j] == "^1RED^7 flag")
2721 drawpic_skin(weap_pos, strcat("flag_", s, "_carrying"), '1 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2722 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2724 else if(killnotify_deathtype[j] == INFO_RETURNFLAG)
2726 if(killnotify_victims[j] == "^1RED^7 flag")
2730 drawpic_skin(weap_pos, strcat("flag_", s, "_taken"), '1 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2731 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2733 else if(killnotify_deathtype[j] == INFO_LOSTFLAG)
2735 if(killnotify_victims[j] == "^1RED^7 flag")
2739 drawpic_skin(weap_pos, strcat("flag_", s, "_lost"), '1 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2740 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2743 // X [did action to] Y
2748 attacker = textShortenToWidth("Player1", 0.5 * mySize_x - height, fontsize, stringwidth_colors);
2749 victim = textShortenToWidth("Player2", 0.5 * mySize_x - height, fontsize, stringwidth_colors);
2750 a = bound(0, (when - j) / 4, 1);
2754 attacker = textShortenToWidth(killnotify_attackers[j], 0.5 * mySize_x - height, fontsize, stringwidth_colors);
2755 victim = textShortenToWidth(killnotify_victims[j], 0.5 * mySize_x - height, fontsize, stringwidth_colors);
2757 width_attacker = stringwidth(attacker, TRUE, fontsize);
2758 width_victim = stringwidth(victim, TRUE, fontsize);
2759 pos_attacker = pos + eX * 0.5 * ((0.5 * mySize_x - height) - width_attacker) + eY * 0.5 * fontsize_y + eY * i * height;
2760 pos_victim = pos + eX * 0.5 * ((0.5 * mySize_x - height) - width_victim) + eY * 0.5 * fontsize_y + eX * 0.5 * mySize_x + eX * height + eY * i * height;
2761 weap_pos = pos + eX * 0.5 * mySize_x - eX * height + eY * i * height;
2763 if(hud_configure) // example actions for config mode
2765 drawpic_skin(weap_pos, strcat("weapon", "electro"), '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2766 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2767 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2769 else if(WEP_VALID(killnotify_deathtype[j]))
2771 self = get_weaponinfo(killnotify_deathtype[j]);
2772 drawpic_skin(weap_pos, strcat("weapon", self.netname), '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2773 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2774 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2776 else if(killnotify_deathtype[j] == KILL_TEAM_RED)
2778 drawpic_skin(weap_pos, "notify_teamkill", '2 1 0' * height, '1 0 0', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2779 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2780 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2782 else if(killnotify_deathtype[j] == KILL_TEAM_BLUE)
2784 drawpic_skin(weap_pos, "notify_teamkill", '2 1 0' * height, '0 0 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2785 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2786 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2788 else if(killnotify_deathtype[j] == DEATH_DROWN)
2790 drawpic_skin(weap_pos, "notify_water", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2791 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2792 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2794 else if(killnotify_deathtype[j] == DEATH_SLIME)
2796 drawpic_skin(weap_pos, "notify_slime", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2797 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2798 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2800 else if(killnotify_deathtype[j] == DEATH_LAVA)
2802 drawpic_skin(weap_pos, "notify_lava", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2803 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2804 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2806 else if(killnotify_deathtype[j] == DEATH_FALL)
2808 drawpic_skin(weap_pos, "notify_fall", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2809 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2810 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2812 else if(killnotify_deathtype[j] == DEATH_SHOOTING_STAR)
2814 drawpic_skin(weap_pos, "notify_shootingstar", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2815 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2816 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2818 else if(killnotify_deathtype[j] == DEATH_HURTTRIGGER || killnotify_deathtype[j] == DEATH_CUSTOM) // DEATH_CUSTOM is also void, right?
2820 drawpic_skin(weap_pos, "notify_void", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2821 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2822 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2828 // TODO: separate panel for these?
2834 if(cvar("hud_notify_info_top"))
2837 o = pos + eY * mySize_y - eY * 2 * height;
2839 if(spectatee_status && !intermission)
2841 //drawfont = hud_bigfont;
2842 if(spectatee_status == -1)
2845 s = GetPlayerName(spectatee_status - 1);
2847 //s = textShortenToWidth(s, mySize_y, 0.5 * height, stringwidth_colors);
2848 //drawcolorcodedstring(pos + eY * 0.25 * height, s, 0.5 * height, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2849 //drawfont = hud_font;
2851 // spectator text in the upper right corner
2852 if(spectatee_status == -1)
2853 s = strcat("^1Press ^3", getcommandkey("primary fire", "+attack"), "^1 to spectate");
2855 s = strcat("^1Press ^3", getcommandkey("primary fire", "+attack"), "^1 for another player");
2856 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2857 o += eY * fontsize_y;
2859 if(spectatee_status == -1)
2860 s = strcat("^1Use ^3", getcommandkey("next weapon", "weapnext"), "^1 or ^3", getcommandkey("previous weapon", "weapprev"), "^1 to change the speed");
2862 s = strcat("^1Press ^3", getcommandkey("secondary fire", "+attack2"), "^1 to observe");
2863 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2864 o += eY * fontsize_y;
2866 s = strcat("^1Press ^3", getcommandkey("server info", "+show_info"), "^1 for gamemode info");
2867 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2868 o += eY * fontsize_y;
2870 if(gametype == GAME_ARENA)
2871 s = "^1Wait for your turn to join";
2872 else if(gametype == GAME_LMS)
2875 sk = playerslots[player_localentnum - 1];
2876 if(sk.(scores[ps_primary]) >= 666)
2877 s = "^1Match has already begun";
2878 else if(sk.(scores[ps_primary]) > 0)
2879 s = "^1You have no more lives left";
2881 s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
2884 s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
2885 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2886 o += eY * fontsize_y;
2888 //show restart countdown:
2889 if (time < getstatf(STAT_GAMESTARTTIME)) {
2891 //we need to ceil, otherwise the countdown would be off by .5 when using round()
2892 countdown = ceil(getstatf(STAT_GAMESTARTTIME) - time);
2893 s = strcat("^1Game starts in ^3", ftos(countdown), "^1 seconds");
2894 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2895 o += eY * fontsize_y;
2898 if(warmup_stage && !intermission)
2900 s = "^2Currently in ^1warmup^2 stage!";
2901 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2902 o += eY * fontsize_y;
2906 if(mod(time, 1) >= 0.5)
2911 if(ready_waiting && !intermission && !spectatee_status)
2913 if(ready_waiting_for_me)
2916 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " to end warmup");
2918 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " once you are ready");
2923 s = strcat("^2Waiting for others to ready up to end warmup...");
2925 s = strcat("^2Waiting for others to ready up...");
2927 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2928 o += eY * fontsize_y;
2930 else if(warmup_stage && !intermission && !spectatee_status)
2932 s = strcat("^2Press ^3", getcommandkey("ready", "ready"), "^2 to end warmup");
2933 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2934 o += eY * fontsize_y;
2937 if(teamplay && !intermission && !spectatee_status && gametype != GAME_CA && teamnagger)
2939 float ts_min, ts_max;
2940 tm = teams.sort_next;
2943 for(; tm.sort_next; tm = tm.sort_next)
2945 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
2947 if(!ts_min) ts_min = tm.team_size;
2948 else ts_min = min(ts_min, tm.team_size);
2949 if(!ts_max) ts_max = tm.team_size;
2950 else ts_max = max(ts_max, tm.team_size);
2952 if ((ts_max - ts_min) > 1)
2954 s = strcat(blinkcolor, "Teamnumbers are unbalanced!");
2955 tm = GetTeam(myteam, false);
2957 if (tm.team != COLOR_SPECTATOR)
2958 if (tm.team_size == ts_max)
2959 s = strcat(s, " Press ^3", getcommandkey("team menu", "menu_showteamselect"), blinkcolor, " to adjust");
2961 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2962 o += eY * fontsize_y;
2968 s = "^7Press ^3ESC ^7to show HUD options.";
2969 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2970 o += eY * fontsize_y;
2971 s = "^3Doubleclick a panel for panel-specific options.";
2972 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2973 o += eY * fontsize_y;
2979 string seconds_tostring(float sec)
2982 minutes = floor(sec / 60);
2984 sec -= minutes * 60;
2987 s = ftos(100 + sec);
2989 return strcat(ftos(minutes), ":", substring(s, 1, 3));
2992 void HUD_Timer(void)
2994 float id = HUD_PANEL_TIMER;
2996 pos = HUD_Panel_GetPos(id);
2997 mySize = HUD_Panel_GetSize(id);
2999 HUD_Panel_DrawBg(id, pos, mySize, 0);
3001 padding = HUD_Panel_GetPadding(id);
3004 pos += '1 1 0' * padding;
3005 mySize -= '2 2 0' * padding;
3009 float timelimit, elapsedTime, timeleft, minutesLeft;
3011 timelimit = getstatf(STAT_TIMELIMIT);
3013 timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
3014 timeleft = ceil(timeleft);
3016 minutesLeft = floor(timeleft / 60);
3019 if(minutesLeft >= 5 || warmup_stage || timelimit == 0) //don't use red or yellow in warmup or when there is no timelimit
3020 timer_color = '1 1 1'; //white
3021 else if(minutesLeft >= 1)
3022 timer_color = '1 1 0'; //yellow
3024 timer_color = '1 0 0'; //red
3026 if (cvar("hud_timer_increment") || timelimit == 0 || warmup_stage) {
3027 if (time < getstatf(STAT_GAMESTARTTIME)) {
3028 //while restart is still active, show 00:00
3029 timer = seconds_tostring(0);
3031 elapsedTime = floor(time - getstatf(STAT_GAMESTARTTIME)); //127
3032 timer = seconds_tostring(elapsedTime);
3035 timer = seconds_tostring(timeleft);
3038 drawfont = hud_bigfont;
3039 drawstring_aspect(pos, timer, mySize, mySize_y, timer_color, HUD_Panel_GetFgAlpha(HUD_PANEL_TIMER), DRAWFLAG_NORMAL);
3040 drawfont = hud_font;
3045 void HUD_Radar(void)
3047 float id = HUD_PANEL_RADAR;
3049 pos = HUD_Panel_GetPos(id);
3050 mySize = HUD_Panel_GetSize(id);
3052 HUD_Panel_DrawBg(id, pos, mySize, 0);
3054 padding = HUD_Panel_GetPadding(id);
3057 pos += '1 1 0' * padding;
3058 mySize -= '2 2 0' * padding;
3061 local float color1, color2; // color already declared as a global in hud.qc
3064 float scale2d, normalsize, bigsize;
3067 teamradar_origin2d = pos + 0.5 * mySize;
3068 teamradar_size2d = mySize;
3070 if(minimapname == "")
3073 teamradar_loadcvars();
3075 switch(hud_radar_zoommode)
3079 f = current_zoomfraction;
3082 f = 1 - current_zoomfraction;
3092 switch(hud_radar_rotation)
3095 teamradar_angle = view_angles_y - 90;
3098 teamradar_angle = 90 * hud_radar_rotation;
3102 scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
3103 teamradar_size2d = mySize;
3105 teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0'; // we always center
3107 // pixels per world qu to match the teamradar_size2d_x range in the longest dimension
3108 if(hud_radar_rotation == 0)
3110 // max-min distance must fit the radar in any rotation
3111 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen2d(mi_max - mi_min));
3115 vector c0, c1, c2, c3, span;
3116 c0 = rotate(mi_min, teamradar_angle * DEG2RAD);
3117 c1 = rotate(mi_max, teamradar_angle * DEG2RAD);
3118 c2 = rotate('1 0 0' * mi_min_x + '0 1 0' * mi_max_y, teamradar_angle * DEG2RAD);
3119 c3 = rotate('1 0 0' * mi_max_x + '0 1 0' * mi_min_y, teamradar_angle * DEG2RAD);
3121 span_x = max4(c0_x, c1_x, c2_x, c3_x) - min4(c0_x, c1_x, c2_x, c3_x);
3122 span_y = max4(c0_y, c1_y, c2_y, c3_y) - min4(c0_y, c1_y, c2_y, c3_y);
3124 // max-min distance must fit the radar in x=x, y=y
3126 teamradar_size2d_x * scale2d / (1.05 * span_x),
3127 teamradar_size2d_y * scale2d / (1.05 * span_y)
3131 normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / hud_radar_scale;
3132 if(bigsize > normalsize)
3133 normalsize = bigsize;
3137 + (1 - f) * normalsize;
3138 teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
3139 f * (mi_min + mi_max) * 0.5
3140 + (1 - f) * view_origin);
3142 color1 = GetPlayerColor(player_localentnum-1);
3143 rgb = GetTeamRGB(color1);
3152 draw_teamradar_background(hud_radar_background_alpha, hud_radar_foreground_alpha);
3154 for(tm = world; (tm = find(tm, classname, "radarlink")); )
3155 draw_teamradar_link(tm.origin, tm.velocity, tm.team);
3156 for(tm = world; (tm = findflags(tm, teamradar_icon, 0xFFFFFF)); )
3157 draw_teamradar_icon(tm.origin, tm.teamradar_icon, tm, tm.teamradar_color, HUD_Panel_GetFgAlpha(id));
3158 for(tm = world; (tm = find(tm, classname, "entcs_receiver")); )
3160 color2 = GetPlayerColor(tm.sv_entnum);
3161 //if(color == COLOR_SPECTATOR || color == color2)
3162 draw_teamradar_player(tm.origin, tm.angles, GetTeamRGB(color2));
3164 draw_teamradar_player(view_origin, view_angles, '1 1 1');
3166 drawresetcliparea();
3171 void HUD_Score(void)
3173 float id = HUD_PANEL_SCORE;
3175 pos = HUD_Panel_GetPos(id);
3176 mySize = HUD_Panel_GetSize(id);
3178 HUD_Panel_DrawBg(id, pos, mySize, 0);
3180 padding = HUD_Panel_GetPadding(id);
3183 pos += '1 1 0' * padding;
3184 mySize -= '2 2 0' * padding;
3187 float score, distribution, leader;
3189 vector distribution_color;
3191 me = (spectatee_status > 0) ? playerslots[spectatee_status - 1] : playerslots[player_localentnum - 1];
3193 // TODO... this (race part) still uses constant coordinates :/
3194 if((scores_flags[ps_primary] & SFL_TIME) && !teamplay) { // race/cts record display on HUD
3195 /*pl = players.sort_next;
3198 if(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)
3199 if(pl.scores[ps_primary] == 0)
3202 score = me.(scores[ps_primary]);
3204 float racemin, racesec, racemsec;
3205 float distsec, distmsec, minusplus;
3207 racemin = floor(score/(60 * TIME_FACTOR));
3208 racesec = floor((score - racemin*(60 * TIME_FACTOR))/TIME_FACTOR);
3209 racemsec = score - racemin*60*TIME_FACTOR - racesec*TIME_FACTOR;
3211 if (pl && ((!(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)) || score)) {
3212 // distribution display
3213 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
3215 if (distribution < TIME_FACTOR && distribution > -TIME_FACTOR)
3216 distmsec = fabs(distribution);
3218 distsec = floor(fabs(distribution)/TIME_FACTOR);
3219 distmsec = fabs(distribution) - distsec*TIME_FACTOR;
3220 if (distribution < 0)
3224 if (distribution <= 0) {
3225 distribution_color = eY;
3226 minusplus = 1; // minusplus 1: always prefix with minus sign
3229 distribution_color = eX;
3230 minusplus = 2; // minusplus 1: always prefix with plus sign
3232 //HUD_DrawXNum(bottomright - '0 48 0' - '16 0 0' * TIME_DECIMALS, distmsec, -TIME_DECIMALS, 0, 16, distribution_color, 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3233 //HUD_DrawXNum(bottomright - '68 48 0' - '16 0 0' * TIME_DECIMALS, distsec, 4, minusplus, 16, distribution_color, 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3234 drawpic_skin(bottomright - '10 48 0' - '16 0 0' * TIME_DECIMALS, "num_dot", '16 16 0', distribution_color, HUD_Panel_GetFgAlpha(id), DRAWFLAG_ADDITIVE);
3236 // race record display
3237 if (distribution <= 0 || distribution == score) // draw the highlight background behind the timer if we have the lead
3238 drawpic_skin(bottomright - '0 32 0' - '32 0 0' * (4 + TIME_DECIMALS), "num_leading_4", '0 28 0' + '32 0 0' * (4 + TIME_DECIMALS), '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3240 //HUD_DrawXNum(bottomright - '0 32 0' - TIME_DECIMALS * '30 0 0', racemsec, -TIME_DECIMALS, 0, 30, '1 1 1', 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3241 //HUD_DrawXNum(bottomright - '0 32 0' - TIME_DECIMALS * '30 0 0' - '66 0 0', racesec, -2, 0, 30, '1 1 1', 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3242 drawpic_skin(bottomright - '0 32 0' - TIME_DECIMALS * '30 0 0' - '18 0 0', "num_dot", '30 30 0', '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_ADDITIVE);
3244 //HUD_DrawXNum(bottomright - '0 32 0' - TIME_DECIMALS * '30 0 0' - '132 0 0', racemin, -2, 0, 30, '1 1 1', 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3245 drawpic_skin(bottomright - '0 32 0' - TIME_DECIMALS * '30 0 0' - '84 0 0', "num_colon", '30 30 0', '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_ADDITIVE);
3247 } else if (!teamplay) { // non-teamgames
3248 // me vector := [team/connected frags id]
3249 pl = players.sort_next;
3256 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
3260 score = me.(scores[ps_primary]);
3264 if(distribution >= 5) {
3265 distribution_color = eY;
3267 } else if(distribution >= 0) {
3268 distribution_color = '1 1 1';
3270 } else if(distribution >= -5)
3271 distribution_color = '1 1 0';
3273 distribution_color = eX;
3275 score_len = strlen(ftos(score));
3277 drawstring_aspect(pos + eX * 0.75 * mySize_x, ftos(distribution), eX * 0.25 * mySize_x + eY * (1/3) * mySize_y, (1/3) * mySize_y, distribution_color, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3279 drawpic_skin(pos, strcat("num_leading_", ftos(score_len)), eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3280 drawfont = hud_bigfont;
3281 drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize_x + eY * mySize_y, mySize_y, distribution_color, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3282 drawfont = hud_font;
3283 } else { // teamgames
3284 float max_fragcount;
3285 max_fragcount = -99;
3288 for(tm = teams.sort_next; tm; tm = tm.sort_next) {
3289 if(tm.team == COLOR_SPECTATOR || (!tm.team_size && !hud_configure)) // no players? don't display
3291 score = tm.(teamscores[ts_primary]);
3296 score_len = strlen(ftos(score));
3298 if (score > max_fragcount)
3299 max_fragcount = score;
3301 if(tm.team == myteam) {
3302 if (max_fragcount == score)
3305 drawpic_skin(pos, strcat("num_leading_", ftos(score_len)), eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3306 drawfont = hud_bigfont;
3307 drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize_x + eY * mySize_y, mySize_y, GetTeamRGB(tm.team) * 0.8, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3308 drawfont = hud_font;
3310 if (max_fragcount == score)
3313 drawpic_skin(pos + eX * 0.75 * mySize_x + eY * (1/3) * teamnum * mySize_y, strcat("num_leading_", ftos(score_len)), eX * 0.25 * mySize_x + eY * (1/3) * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3314 drawstring_aspect(pos + eX * 0.75 * mySize_x + eY * (1/3) * teamnum * mySize_y, ftos(score), eX * 0.25 * mySize_x + eY * (1/3) * mySize_y, (1/3) * mySize_y, GetTeamRGB(tm.team) * 0.8, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3323 void HUD_RaceTimer (void) {
3324 float id = HUD_PANEL_RACETIMER;
3326 pos = HUD_Panel_GetPos(id);
3327 mySize = HUD_Panel_GetSize(id);
3329 HUD_Panel_DrawBg(id, pos, mySize, 0);
3331 padding = HUD_Panel_GetPadding(id);
3334 pos += '1 1 0' * padding;
3335 mySize -= '2 2 0' * padding;
3338 // always force 2:1 aspect
3340 if(mySize_x/mySize_y > 2)
3342 newSize_x = 2 * mySize_y;
3343 newSize_y = mySize_y;
3345 pos_x = pos_x + (mySize_x - newSize_x) / 2;
3349 newSize_y = 1/2 * mySize_x;
3350 newSize_x = mySize_x;
3352 pos_y = pos_y + (mySize_y - newSize_y) / 2;
3356 drawfont = hud_bigfont;
3358 string s, forcetime;
3363 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', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3364 s = "^1Intermediate 1 (+15.42)";
3365 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, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3366 s = strcat("^1PENALTY: ", ftos_decimals(20 * 0.1, 1), " (missing a checkpoint)");
3367 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, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3369 else if(race_checkpointtime)
3371 a = bound(0, 2 - (time - race_checkpointtime), 1);
3374 if(a > 0) // just hit a checkpoint?
3376 if(race_checkpoint != 254)
3378 if(race_time && race_previousbesttime)
3379 s = MakeRaceString(race_checkpoint, TIME_DECODE(race_time) - TIME_DECODE(race_previousbesttime), 0, 0, race_previousbestname);
3381 s = MakeRaceString(race_checkpoint, 0, -1, 0, race_previousbestname);
3383 forcetime = TIME_ENCODED_TOSTRING(race_time);
3388 if(race_laptime && race_nextbesttime && race_nextcheckpoint != 254)
3390 a = bound(0, 2 - ((race_laptime + TIME_DECODE(race_nextbesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1);
3391 if(a > 0) // next one?
3393 s = MakeRaceString(race_nextcheckpoint, (time + TIME_DECODE(race_penaltyaccumulator)) - race_laptime, TIME_DECODE(race_nextbesttime), 0, race_nextbestname);
3398 if(s != "" && a > 0)
3400 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
3401 //drawcolorcodedstring(m - '0 16 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
3402 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, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
3405 if(race_penaltytime)
3407 a = bound(0, 2 - (time - race_penaltyeventtime), 1);
3410 s = strcat("^1PENALTY: ", ftos_decimals(race_penaltytime * 0.1, 1), " (", race_penaltyreason, ")");
3411 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
3412 //drawcolorcodedstring(m - '0 32 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
3413 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, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
3419 a = bound(0, (time - race_checkpointtime) / 0.5, 1);
3420 //drawstring_expanding(m - '16 0 0' * stringwidth(forcetime, FALSE), forcetime, '32 32 0', '1 1 1', HUD_Panel_GetFgAlpha(id), 0, a);
3421 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', HUD_Panel_GetFgAlpha(id), 0, a);
3426 if(race_laptime && race_checkpoint != 255)
3428 s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime));
3429 //drawstring(m - '16 0 0' * stringwidth(s, FALSE), s, '32 32 0', '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
3430 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', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
3435 if(race_mycheckpointtime)
3437 a = bound(0, 2 - (time - race_mycheckpointtime), 1);
3438 s = MakeRaceString(race_mycheckpoint, TIME_DECODE(race_mycheckpointdelta), -!race_mycheckpointenemy, race_mycheckpointlapsdelta, race_mycheckpointenemy);
3439 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
3440 //drawcolorcodedstring(m - '0 16 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
3441 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, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
3443 if(race_othercheckpointtime && race_othercheckpointenemy != "")
3445 a = bound(0, 2 - (time - race_othercheckpointtime), 1);
3446 s = MakeRaceString(race_othercheckpoint, -TIME_DECODE(race_othercheckpointdelta), -!race_othercheckpointenemy, race_othercheckpointlapsdelta, race_othercheckpointenemy);
3447 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
3448 //drawcolorcodedstring(m - '0 0 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
3449 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, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
3452 if(race_penaltytime && !race_penaltyaccumulator)
3454 t = race_penaltytime * 0.1 + race_penaltyeventtime;
3455 a = bound(0, (1 + t - time), 1);
3459 s = strcat("^1PENALTY: ", ftos_decimals(t - time, 1), " (", race_penaltyreason, ")");
3461 s = strcat("^2PENALTY: 0.0 (", race_penaltyreason, ")");
3462 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
3463 //drawcolorcodedstring(m - '0 32 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
3464 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, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
3469 drawfont = hud_font;
3474 float vote_yescount;
3477 float vote_highlighted; // currently selected vote
3479 float vote_active; // is there an active vote?
3480 float vote_prev; // previous state of vote_active to check for a change
3482 float vote_change; // "time" when vote_active changed
3484 void HUD_VoteWindow(void)
3486 float id = HUD_PANEL_VOTE;
3488 pos = HUD_Panel_GetPos(id);
3489 mySize = HUD_Panel_GetSize(id);
3493 if(vote_active != vote_prev) {
3495 vote_prev = vote_active;
3498 if(vote_active || hud_configure)
3499 vote_alpha = bound(0, (time - vote_change) * 2, 1);
3501 vote_alpha = bound(0, 1 - (time - vote_change) * 2, 1);
3513 a = vote_alpha * bound(cvar_or("hud_vote_alreadyvoted_alpha", 0.75), 1 - vote_highlighted, 1);
3515 HUD_Panel_DrawBg(id, pos, mySize, a);
3517 padding = HUD_Panel_GetPadding(id);
3520 pos += '1 1 0' * padding;
3521 mySize -= '2 2 0' * padding;
3524 // always force 2:1 aspect
3526 if(mySize_x/mySize_y > 2)
3528 newSize_x = 2 * mySize_y;
3529 newSize_y = mySize_y;
3531 pos_x = pos_x + (mySize_x - newSize_x) / 2;
3535 newSize_y = 1/2 * mySize_x;
3536 newSize_x = mySize_x;
3538 pos_y = pos_y + (mySize_y - newSize_y) / 2;
3542 drawpic_skin(pos, "voteprogress_back", mySize, '1 1 1', a * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3544 s = "A vote has been called for: ";
3545 drawstring_aspect(pos + eY * (1/12) * mySize_y, s, eX * mySize_x + eY * (3/12) * mySize_y, mySize_y*(3/12), '1 1 1', a * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3546 s = textShortenToWidth(vote_called_vote, mySize_x, '1 1 0' * mySize_y * (3/12), stringwidth_colors); // TODO: broken?
3548 s = "Configure the HUD";
3549 drawstring_aspect(pos + eY * (4/12) * mySize_y, s, eX * mySize_x + eY * (2/12) * mySize_y, mySize_y*(2/12), '1 1 1', a * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3551 // print the yes/no counts
3552 s = strcat("Yes: ", ftos(vote_yescount));
3553 drawstring(pos + '0 0.6 0' * mySize_y + '0.02 0 0' * mySize_x, s, '1 1 0' * mySize_y*(1/6) , eY, a * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3554 s = strcat("No: ", ftos(vote_nocount));
3555 drawstring(pos + '0 0.6 0' * mySize_y + '0.98 0 0' * mySize_x - eX * stringwidth(s, FALSE, '1 1 0' * mySize_y*(1/6)), s, '1 1 0' * mySize_y*(1/6), eX, a * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3557 // draw the progress bars
3558 drawsetcliparea(pos_x, pos_y, mySize_x * 0.5 * (vote_yescount/vote_needed), mySize_y);
3559 drawpic_skin(pos, "voteprogress_prog", mySize, eY, a * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3561 drawsetcliparea(pos_x + mySize_x - mySize_x * 0.5 * (vote_nocount/vote_needed), pos_y, mySize_x * 0.5, mySize_y);
3562 drawpic_skin(pos, "voteprogress_prog", mySize, eX, a * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3564 // draw the highlights
3565 if(vote_highlighted == 1) {
3566 drawsetcliparea(pos_x, pos_y, mySize_x * 0.5, mySize_y);
3567 drawpic_skin(pos, "voteprogress_voted", mySize, eY, a * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3569 else if(vote_highlighted == 2) {
3570 drawsetcliparea(pos_x + 0.5 * mySize_x, pos_y, mySize_x * 0.5, mySize_y);
3571 drawpic_skin(pos, "voteprogress_voted", mySize, eX, a * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3574 drawresetcliparea();
3577 vote_highlighted = 0;
3581 // Mod icons panel (#10)
3584 float mod_active; // is there any active mod icon?
3586 // CTF HUD modicon section
3587 float redflag_prevframe, blueflag_prevframe; // status during previous frame
3588 float redflag_prevstatus, blueflag_prevstatus; // last remembered status
3589 float redflag_statuschange_time, blueflag_statuschange_time; // time when the status changed
3591 void HUD_Mod_CTF_Reset(void)
3593 redflag_prevstatus = blueflag_prevstatus = redflag_prevframe = blueflag_prevframe = redflag_statuschange_time = blueflag_statuschange_time = 0;
3596 void HUD_Mod_CTF(vector pos, vector mySize)
3598 vector redflag_pos, blueflag_pos;
3600 float f; // every function should have that
3602 float redflag, blueflag; // current status
3603 float redflag_statuschange_elapsedtime, blueflag_statuschange_elapsedtime; // time since the status changed
3606 stat_items = getstati(STAT_ITEMS);
3607 redflag = (stat_items/IT_RED_FLAG_TAKEN) & 3;
3608 blueflag = (stat_items/IT_BLUE_FLAG_TAKEN) & 3;
3610 if(redflag || blueflag)
3621 // when status CHANGES, set old status into prevstatus and current status into status
3622 if (redflag != redflag_prevframe)
3624 redflag_statuschange_time = time;
3625 redflag_prevstatus = redflag_prevframe;
3626 redflag_prevframe = redflag;
3629 if (blueflag != blueflag_prevframe)
3631 blueflag_statuschange_time = time;
3632 blueflag_prevstatus = blueflag_prevframe;
3633 blueflag_prevframe = blueflag;
3636 redflag_statuschange_elapsedtime = time - redflag_statuschange_time;
3637 blueflag_statuschange_elapsedtime = time - blueflag_statuschange_time;
3639 float BLINK_FACTOR = 0.15;
3640 float BLINK_BASE = 0.85;
3642 // RMS = sqrt(BLINK_BASE^2 + 0.5 * BLINK_FACTOR^2)
3644 // BLINK_BASE = sqrt(RMS^2 - 0.5 * BLINK_FACTOR^2)
3646 float BLINK_FREQ = 5; // circle frequency, = 2*pi*frequency in hertz
3648 string red_icon, red_icon_prevstatus;
3649 float red_alpha, red_alpha_prevstatus;
3650 red_alpha = red_alpha_prevstatus = 1;
3652 case 1: red_icon = "flag_red_taken"; break;
3653 case 2: red_icon = "flag_red_lost"; break;
3654 case 3: red_icon = "flag_red_carrying"; red_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3656 if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM2))
3657 red_icon = "flag_red_shielded";
3659 red_icon = string_null;
3662 switch(redflag_prevstatus) {
3663 case 1: red_icon_prevstatus = "flag_red_taken"; break;
3664 case 2: red_icon_prevstatus = "flag_red_lost"; break;
3665 case 3: red_icon_prevstatus = "flag_red_carrying"; red_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3668 red_icon_prevstatus = "flag_red_carrying"; // make it more visible
3669 else if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM2))
3670 red_icon_prevstatus = "flag_red_shielded";
3672 red_icon_prevstatus = string_null;
3676 string blue_icon, blue_icon_prevstatus;
3677 float blue_alpha, blue_alpha_prevstatus;
3678 blue_alpha = blue_alpha_prevstatus = 1;
3680 case 1: blue_icon = "flag_blue_taken"; break;
3681 case 2: blue_icon = "flag_blue_lost"; break;
3682 case 3: blue_icon = "flag_blue_carrying"; blue_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3684 if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM1))
3685 blue_icon = "flag_blue_shielded";
3687 blue_icon = string_null;
3690 switch(blueflag_prevstatus) {
3691 case 1: blue_icon_prevstatus = "flag_blue_taken"; break;
3692 case 2: blue_icon_prevstatus = "flag_blue_lost"; break;
3693 case 3: blue_icon_prevstatus = "flag_blue_carrying"; blue_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3696 blue_icon_prevstatus = "flag_blue_carrying"; // make it more visible
3697 else if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM1))
3698 blue_icon_prevstatus = "flag_blue_shielded";
3700 blue_icon_prevstatus = string_null;
3704 if(mySize_x > mySize_y) {
3705 if (myteam == COLOR_TEAM1) { // always draw own flag on left
3707 blueflag_pos = pos + eX * 0.5 * mySize_x;
3710 redflag_pos = pos + eX * 0.5 * mySize_x;
3712 flag_size = eX * 0.5 * mySize_x + eY * mySize_y;
3714 if (myteam == COLOR_TEAM1) { // always draw own flag on left
3716 blueflag_pos = pos + eY * 0.5 * mySize_y;
3719 redflag_pos = pos + eY * 0.5 * mySize_y;
3721 flag_size = eY * 0.5 * mySize_y + eX * mySize_x;
3724 f = bound(0, redflag_statuschange_elapsedtime*2, 1);
3725 if(red_icon_prevstatus && f < 1)
3726 drawpic_skin_expanding(redflag_pos, red_icon_prevstatus, flag_size, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * red_alpha_prevstatus, DRAWFLAG_NORMAL, f);
3728 drawpic_skin(redflag_pos, red_icon, flag_size, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * red_alpha * f, DRAWFLAG_NORMAL);
3730 f = bound(0, blueflag_statuschange_elapsedtime*2, 1);
3731 if(blue_icon_prevstatus && f < 1)
3732 drawpic_skin_expanding(blueflag_pos, blue_icon_prevstatus, flag_size, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * blue_alpha_prevstatus, DRAWFLAG_NORMAL, f);
3734 drawpic_skin(blueflag_pos, blue_icon, flag_size, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * blue_alpha * f, DRAWFLAG_NORMAL);
3737 // Keyhunt HUD modicon section
3738 float kh_runheretime;
3740 void HUD_Mod_KH_Reset(void)
3745 void HUD_Mod_KH(vector pos, vector mySize)
3747 mod_active = 1; // keyhunt should never hide the mod icons panel
3751 vector p, pa, kh_size, kh_asize;
3753 kh_keys = getstati(STAT_KH_KEYS);
3756 if(mySize_x > mySize_y)
3758 p_y = pos_y + 0.25 * mySize_y;
3759 pa = p - eY * 0.25 * mySize_y;
3761 kh_size_x = mySize_x * 0.25;
3762 kh_size_y = 0.75 * mySize_y;
3763 kh_asize_x = mySize_x * 0.25;
3764 kh_asize_y = mySize_y * 0.25;
3768 p_y = pos_y + 0.125 * mySize_y;
3769 pa = p - eY * 0.125 * mySize_y;
3771 kh_size_x = mySize_x * 0.5;
3772 kh_size_y = 0.375 * mySize_y;
3773 kh_asize_x = mySize_x * 0.5;
3774 kh_asize_y = mySize_y * 0.125;
3781 for(i = 0; i < 4; ++i)
3783 key = floor(kh_keys / pow(32, i)) & 31;
3785 if(keyteam == 30 && keycount <= 4)
3787 if(keyteam == myteam || keyteam == -1 || keyteam == 30)
3791 // this yields 8 exactly if "RUN HERE" shows
3796 kh_runheretime = time;
3797 pa_y -= fabs(sin((time - kh_runheretime) * 3.5)) * 6; // make the arrows jump in case of RUN HERE
3802 for(i = 0; i < 4; ++i)
3804 key = floor(kh_keys / pow(32, i)) & 31;
3817 default: // owned or dropped
3822 a = a * HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS);
3823 aa = aa * HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS);
3829 drawpic_skin(pa, "kh_redarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
3832 drawpic_skin(pa, "kh_bluearrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
3835 drawpic_skin(pa, "kh_yellowarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
3838 drawpic_skin(pa, "kh_pinkarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
3843 switch(i) // YAY! switch(i) inside a for loop for i. DailyWTF, here we come!
3846 drawpic_skin(p, "kh_red", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
3849 drawpic_skin(p, "kh_blue", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
3852 drawpic_skin(p, "kh_yellow", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
3855 drawpic_skin(p, "kh_pink", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
3859 if(mySize_x > mySize_y)
3861 p_x += 0.25 * mySize_x;
3862 pa_x += 0.25 * mySize_x;
3868 p_y = pos_y + 0.625 * mySize_y;
3869 pa_y = pos_y + 0.5 * mySize_y;
3875 p_x += 0.5 * mySize_x;
3876 pa_x += 0.5 * mySize_x;
3882 // Nexball HUD mod icon
3883 void HUD_Mod_NexBall(vector pos, vector mySize)
3885 float stat_items, nb_pb_starttime, dt, p;
3887 stat_items = getstati(STAT_ITEMS);
3888 nb_pb_starttime = getstatf(STAT_NB_METERSTART);
3890 if (stat_items & IT_KEY1)
3895 //Manage the progress bar if any
3896 if (nb_pb_starttime > 0)
3898 dt = mod(time - nb_pb_starttime, nb_pb_period);
3899 // one period of positive triangle
3900 p = 2 * dt / nb_pb_period;
3907 if(mySize_x > mySize_y)
3909 barsize = eX * p * mySize_x + eY * mySize_y;
3914 barsize = eX * mySize_x + eY * p * mySize_y;
3917 HUD_Panel_DrawProgressBar(pos, vertical, barsize, HUD_Panel_GetProgressBarColor("nexball"), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL);
3920 if (stat_items & IT_KEY1)
3921 drawpic_skin(pos, "nexball_carrying", eX * mySize_x + eY * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL);
3924 // Race/CTS HUD mod icons
3925 float crecordtime_prev; // last remembered crecordtime
3926 float crecordtime_change_time; // time when crecordtime last changed
3927 float srecordtime_prev; // last remembered srecordtime
3928 float srecordtime_change_time; // time when srecordtime last changed
3930 float race_status_time;
3931 float race_status_prev;
3932 string race_status_name_prev;
3933 void HUD_Mod_Race(vector pos, vector mySize)
3935 mod_active = 1; // race should never hide the mod icons panel
3937 me = playerslots[player_localentnum - 1];
3939 float f; // yet another function has this
3940 score = me.(scores[ps_primary]);
3942 if not((scores_flags[ps_primary] & SFL_TIME) && !teamplay) // race/cts record display on HUD
3943 return; // no records in the actual race
3945 drawfont = hud_bigfont;
3947 // clientside personal record
3949 if(gametype == GAME_CTS)
3953 t = stof(db_get(ClientProgsDB, strcat(shortmapname, rr, "time")));
3955 if(score && (score < t || !t)) {
3956 db_put(ClientProgsDB, strcat(shortmapname, rr, "time"), ftos(score));
3957 if(cvar("cl_autodemo_delete_keeprecords"))
3959 f = cvar("cl_autodemo_delete");
3961 cvar_set("cl_autodemo_delete", ftos(f)); // don't delete demo with new record!
3965 if(t != crecordtime_prev) {
3966 crecordtime_prev = t;
3967 crecordtime_change_time = time;
3969 f = time - crecordtime_change_time;
3972 drawstring_aspect(pos, "Personal best ", eX * 0.5 * mySize_x + eY * 0.25 * mySize_y, 0.15 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL);
3973 drawstring(pos + eY * 0.2 * mySize_y, TIME_ENCODED_TOSTRING(t), '1 1 0' * 0.2 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL);
3975 drawstring(pos, "Personal best ", '1 1 0' * 0.15 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL);
3976 drawstring(pos + eY * 0.2 * mySize_y, TIME_ENCODED_TOSTRING(t), '1 1 0' * 0.2 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL);
3977 drawstring_expanding(pos, "Personal best ", '1 1 0' * 0.15 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL, f);
3978 drawstring_expanding(pos + eY * 0.2 * mySize_y, TIME_ENCODED_TOSTRING(t), '1 1 0' * 0.2 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL, f);
3982 t = race_server_record;
3983 if(t != srecordtime_prev) {
3984 srecordtime_prev = t;
3985 srecordtime_change_time = time;
3987 f = time - srecordtime_change_time;
3990 drawstring(pos + eY * 0.5 * mySize_y, "Server best ", '1 1 0' * 0.15 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL);
3991 drawstring(pos + eY * 0.5 * mySize_y + eY * 0.2 * mySize_y, TIME_ENCODED_TOSTRING(t),'1 1 0' * 0.2 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL);
3993 drawstring(pos + eY * 0.5 * mySize_y, "Server best ", '1 1 0' * 0.15 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL);
3994 drawstring(pos + eY * 0.5 * mySize_y + eY * 0.2 * mySize_y, TIME_ENCODED_TOSTRING(t),'1 1 0' * 0.2 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL);
3995 drawstring_expanding(pos + eY * 0.5 * mySize_y, "Server best ", '1 1 0' * 0.15 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL, f);
3996 drawstring_expanding(pos + eY * 0.5 * mySize_y + eY * 0.2 * mySize_y, TIME_ENCODED_TOSTRING(t),'1 1 0' * 0.2 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL, f);
3999 if (race_status != race_status_prev || race_status_name != race_status_name_prev) {
4000 race_status_time = time + 5;
4001 race_status_prev = race_status;
4002 if (race_status_name_prev)
4003 strunzone(race_status_name_prev);
4004 race_status_name_prev = strzone(race_status_name);
4007 pos_x += mySize_x/2;
4010 a = bound(0, race_status_time - time, 1);
4013 s = textShortenToWidth(race_status_name, mySize_y, '1 1 0' * 0.1 * mySize_y, stringwidth_colors);
4017 rank = race_CheckName(race_status_name);
4019 rankname = race_PlaceName(rank);
4022 namepos = pos + '0.5 0.9 0' * mySize_y - eX * stringwidth(s, TRUE, '1 1 0' * 0.1 * mySize_y);
4024 rankpos = pos + '0.5 0.25 0' * mySize_y - eX * stringwidth(rankname, TRUE, '1 1 0' * 0.15 * mySize_y);
4026 if(race_status == 0)
4027 drawpic_skin(pos, "race_newfail", '1 1 0' * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * a, DRAWFLAG_NORMAL);
4028 else if(race_status == 1) {
4029 drawpic_skin(pos, "race_newtime", '1 1 0' * 0.9 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * a, DRAWFLAG_NORMAL);
4030 drawcolorcodedstring(namepos, s, '1 1 0' * 0.1 * mySize_y, HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * a, DRAWFLAG_NORMAL);
4031 drawstring(rankpos, rankname, '1 1 0' * 0.15 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * a, DRAWFLAG_NORMAL);
4032 } else if(race_status == 2) {
4033 if(race_status_name == GetPlayerName(player_localentnum -1) || !race_myrank || race_myrank < rank)
4034 drawpic_skin(pos, "race_newrankgreen", '1 1 0' * 0.9 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * a, DRAWFLAG_NORMAL);
4036 drawpic_skin(pos, "race_newrankyellow", '1 1 0' * 0.9 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * a, DRAWFLAG_NORMAL);
4037 drawcolorcodedstring(namepos, s, '1 1 0' * 0.1 * mySize_y, HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * a, DRAWFLAG_NORMAL);
4038 drawstring(rankpos, rankname, '1 1 0' * 0.15 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * a, DRAWFLAG_NORMAL);
4039 } else if(race_status == 3) {
4040 drawpic_skin(pos, "race_newrecordserver", '1 1 0' * 0.9 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * a, DRAWFLAG_NORMAL);
4041 drawcolorcodedstring(namepos, s, '1 1 0' * 0.1 * mySize_y, HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * a, DRAWFLAG_NORMAL);
4042 drawstring(rankpos, rankname, '1 1 0' * 0.15 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * a, DRAWFLAG_NORMAL);
4045 if (race_status_time - time <= 0) {
4046 race_status_prev = -1;
4048 if(race_status_name)
4049 strunzone(race_status_name);
4050 race_status_name = string_null;
4051 if(race_status_name_prev)
4052 strunzone(race_status_name_prev);
4053 race_status_name_prev = string_null;
4055 drawfont = hud_font;
4058 float mod_prev; // previous state of mod_active to check for a change
4060 float mod_change; // "time" when mod_active changed
4062 void HUD_ModIcons(void)
4064 if (gametype != GAME_KEYHUNT && gametype != GAME_CTF && gametype != GAME_NEXBALL && gametype != GAME_CTS && gametype != GAME_RACE && !hud_configure)
4067 float id = HUD_PANEL_MODICONS;
4069 pos = HUD_Panel_GetPos(id);
4070 mySize = HUD_Panel_GetSize(id);
4072 if(mod_active != mod_prev) {
4074 mod_prev = mod_active;
4077 if(mod_active || hud_configure)
4078 mod_alpha = bound(0, (time - mod_change) * 2, 1);
4080 mod_alpha = bound(0, 1 - (time - mod_change) * 2, 1);
4083 HUD_Panel_DrawBg(id, pos, mySize, mod_alpha);
4086 padding = HUD_Panel_GetPadding(id);
4089 pos += '1 1 0' * padding;
4090 mySize -= '2 2 0' * padding;
4093 // these MUST be ran in order to update mod_active
4094 if(gametype == GAME_KEYHUNT)
4095 HUD_Mod_KH(pos, mySize);
4096 else if(gametype == GAME_CTF || hud_configure)
4097 HUD_Mod_CTF(pos, mySize); // forcealpha only needed for ctf icons, as only they are shown in config mode
4098 else if(gametype == GAME_NEXBALL)
4099 HUD_Mod_NexBall(pos, mySize);
4100 else if(gametype == GAME_CTS || gametype == GAME_RACE)
4101 HUD_Mod_Race(pos, mySize);
4104 // Draw pressed keys (#11)
4106 void HUD_DrawPressedKeys(void)
4108 float id = HUD_PANEL_PRESSEDKEYS;
4110 pos = HUD_Panel_GetPos(id);
4111 mySize = HUD_Panel_GetSize(id);
4113 HUD_Panel_DrawBg(id, pos, mySize, 0);
4115 padding = HUD_Panel_GetPadding(id);
4118 pos += '1 1 0' * padding;
4119 mySize -= '2 2 0' * padding;
4123 keysize = eX * mySize_x * (1/3) + eY * mySize_y * 0.5;
4126 pressedkeys = getstatf(STAT_PRESSED_KEYS);
4127 drawpic_skin(pos, ((pressedkeys & KEY_CROUCH) ? "key_crouch_inv.tga" : "key_crouch.tga"), keysize, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
4128 drawpic_skin(pos + eX * mySize_x * (1/3), ((pressedkeys & KEY_FORWARD) ? "key_forward_inv.tga" : "key_forward.tga"), keysize, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
4129 drawpic_skin(pos + eX * mySize_x * (2/3), ((pressedkeys & KEY_JUMP) ? "key_jump_inv.tga" : "key_jump.tga"), keysize, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
4130 drawpic_skin(pos + eY * 0.5 * mySize_y, ((pressedkeys & KEY_LEFT) ? "key_left_inv.tga" : "key_left.tga"), keysize, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
4131 drawpic_skin(pos + eY * 0.5 * mySize_y + eX * mySize_x * (1/3), ((pressedkeys & KEY_BACKWARD) ? "key_backward_inv.tga" : "key_backward.tga"), keysize, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
4132 drawpic_skin(pos + eY * 0.5 * mySize_y + eX * mySize_x * (2/3), ((pressedkeys & KEY_RIGHT) ? "key_right_inv.tga" : "key_right.tga"), keysize, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
4135 // Handle chat as a panel (#12)
4139 float id = HUD_PANEL_CHAT;
4141 pos = HUD_Panel_GetPos(id);
4142 mySize = HUD_Panel_GetSize(id);
4144 HUD_Panel_DrawBg(id, pos, mySize, 0);
4146 padding = HUD_Panel_GetPadding(id);
4149 pos += '1 1 0' * padding;
4150 mySize -= '2 2 0' * padding;
4153 cvar_set("con_chatrect", "1");
4155 cvar_set("con_chatrect_x", ftos(pos_x/vid_conwidth));
4156 cvar_set("con_chatrect_y", ftos(pos_y/vid_conheight));
4158 cvar_set("con_chatwidth", ftos(mySize_x/vid_conwidth));
4159 cvar_set("con_chat", ftos(floor(mySize_y/cvar("con_chatsize") - 0.5)));
4164 chatsize = cvar("con_chatsize");
4165 cvar_set("con_chatrect_x", "9001"); // over 9000, we'll fake it instead for more control over alpha and such
4167 for(i = 0; i < cvar("con_chat"); ++i)
4169 if(i == cvar("con_chat") - 1)
4170 a = HUD_Panel_GetFgAlpha(id);
4172 a = HUD_Panel_GetFgAlpha(id) * floor(((i + 1) * 7 + cvar("con_chattime"))/45);
4173 drawcolorcodedstring(pos + eY * i * chatsize, textShortenToWidth("^3Player^7: This is the chat area.", mySize_x, '1 1 0' * chatsize, stringwidth_colors), '1 1 0' * chatsize, a, DRAWFLAG_NORMAL);
4178 // Engine info panel (#13)
4185 float frametimeavg1; // 1 frame ago
4186 float frametimeavg2; // 2 frames ago
4187 void HUD_EngineInfo(void)
4189 float id = HUD_PANEL_ENGINEINFO;
4191 pos = HUD_Panel_GetPos(id);
4192 mySize = HUD_Panel_GetSize(id);
4194 HUD_Panel_DrawBg(id, pos, mySize, 0);
4196 padding = HUD_Panel_GetPadding(id);
4199 pos += '1 1 0' * padding;
4200 mySize -= '2 2 0' * padding;
4203 if(cvar("hud_engineinfo_framecounter_exponentialmovingaverage"))
4205 frametimeavg = (frametimeavg + frametimeavg1 + frametimeavg2 + frametime)/4; // average three frametimes into framecounter for slightly more stable fps readings :P
4206 frametimeavg2 = frametimeavg1;
4207 frametimeavg1 = frametimeavg;
4210 weight = cvar("hud_engineinfo_framecounter_exponentialmovingaverage_new_weight");
4211 if(frametime > 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.
4213 if(fabs(prevfps - (1/frametimeavg)) > prevfps * cvar("hud_engineinfo_framecounter_exponentialmovingaverage_instantupdate_change_threshold")) // if there was a big jump in fps, just force prevfps at current (1/frametime) to make big updates instant
4214 prevfps = (1/frametime);
4215 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"
4221 if(time - prevfps_time > cvar("hud_engineinfo_framecounter_time"))
4223 prevfps = framecounter/cvar("hud_engineinfo_framecounter_time");
4225 prevfps_time = time;
4230 color = HUD_Get_Num_Color (prevfps, 100);
4231 drawfont = hud_bigfont;
4232 drawstring_aspect(pos, strcat("FPS: ", ftos_decimals(prevfps, cvar("hud_engineinfo_framecounter_decimals"))), mySize, mySize_y, color, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
4233 drawfont = hud_font;
4241 void HUD_ShowSpeed(void)
4244 float pos, conversion_factor;
4245 string speed, zspeed, unit;
4247 switch(cvar("cl_showspeed_unit"))
4252 conversion_factor = 1.0;
4256 conversion_factor = 1.0;
4260 conversion_factor = 0.0254;
4264 conversion_factor = 0.0254 * 3.6;
4268 conversion_factor = 0.0254 * 3.6 * 0.6213711922;
4272 conversion_factor = 0.0254 * 1.943844492; // 1 m/s = 1.943844492 knots, because 1 knot = 1.852 km/h
4276 speed = strcat(ftos(floor( vlen(pmove_vel - pmove_vel_z * '0 0 1') * conversion_factor + 0.5 )), unit);
4278 numsize_x = numsize_y = cvar("cl_showspeed_size");
4279 pos = (vid_conheight - numsize_y) * cvar("cl_showspeed_position");
4281 drawfont = hud_bigfont;
4282 drawstringcenter(eX + pos * eY, speed, numsize, '1 1 1', hud_fg_alpha, DRAWFLAG_NORMAL);
4284 if (cvar("cl_showspeed_z") == 1) {
4285 zspeed = strcat(ftos(fabs(floor( pmove_vel_z * conversion_factor + 0.5 ))), unit);
4286 drawstringcenter(eX + pos * eY + numsize_y * eY, zspeed, numsize * 0.5, '1 1 1', hud_fg_alpha, DRAWFLAG_NORMAL);
4289 drawfont = hud_font;
4292 vector acc_prevspeed;
4296 void HUD_ShowAcceleration(void)
4298 float acceleration, sz, scale, alpha, f;
4299 vector pos, top, rgb;
4300 top_x = vid_conwidth/2;
4303 f = time - acc_prevtime;
4304 if(cvar("cl_showacceleration_z"))
4305 acceleration = (vlen(pmove_vel) - vlen(acc_prevspeed)) * (1 / f);
4307 acceleration = (vlen(pmove_vel - '0 0 1' * pmove_vel_z) - vlen(acc_prevspeed - '0 0 1' * acc_prevspeed_z)) * (1 / f);
4308 acc_prevspeed = pmove_vel;
4309 acc_prevtime = time;
4311 f = bound(0, f * 10, 1);
4312 acc_avg = acc_avg * (1 - f) + acceleration * f;
4313 acceleration = acc_avg / getstatf(STAT_MOVEVARS_MAXSPEED);
4315 pos = top - sz/2 * eY + (cvar("cl_showacceleration_position") * vid_conheight) * eY;
4317 sz = cvar("cl_showacceleration_size");
4318 scale = cvar("cl_showacceleration_scale");
4319 alpha = cvar("cl_showacceleration_alpha");
4320 if (cvar("cl_showacceleration_color_custom"))
4321 rgb = stov(cvar_string("cl_showacceleration_color"));
4324 if (acceleration < 0) {
4325 rgb = '1 .5 .5' - '0 .5 .5' * bound(0, -acceleration * 0.2, 1);
4326 } else if (acceleration > 0) {
4327 rgb = '.5 1 .5' - '.5 0 .5' * bound(0, +acceleration * 0.2, 1);
4331 if (acceleration > 0)
4332 HUD_Panel_DrawProgressBar(pos, 0, acceleration * scale * '40 0 0' + sz * eY, rgb, alpha * hud_fg_alpha, DRAWFLAG_NORMAL);
4333 else if (acceleration < 0)
4334 HUD_Panel_DrawProgressBar(pos + acceleration * scale * '40 0 0', 0, -acceleration * scale * '40 0 0' + sz * eY, rgb, alpha * hud_fg_alpha, DRAWFLAG_NORMAL);
4337 void HUD_Reset (void)
4339 // reset gametype specific icons
4340 if(gametype == GAME_KEYHUNT)
4342 else if(gametype == GAME_CTF)
4343 HUD_Mod_CTF_Reset();
4346 void HUD_Main (void)
4348 if(disable_menu_alphacheck == 1)
4349 menu_fade_alpha = 1;
4351 menu_fade_alpha = (1 - cvar("_menu_alpha"));
4352 hud_fg_alpha = cvar("hud_fg_alpha");
4354 hud_border_thickness = bound(0, cvar("hud_border_thickness"), 5);
4355 hud_accuracy_border_thickness = bound(0, cvar_or("hud_accuracy_border_thickness", 1), 5);
4356 hud_color_bg_team = cvar("hud_color_bg_team");
4358 hud_fontsize = HUD_GetFontsize("hud_fontsize");
4359 hud_fontsize_spec = HUD_GetFontsize("hud_fontsize_spec");
4361 hud_configure = cvar("_hud_configure");
4365 // HUD configure visible grid
4366 if(hud_configure && cvar("hud_configure_grid") && cvar("hud_configure_grid_alpha"))
4370 for(i = 0; i < 1/bound(0.005, cvar("hud_configure_grid_x"), 0.2); ++i)
4372 drawfill(eX * i * vid_conwidth * bound(0.005, cvar("hud_configure_grid_x"), 0.2), eX + eY * vid_conheight, '0.5 0.5 0.5', cvar("hud_configure_grid_alpha"), DRAWFLAG_NORMAL);
4375 for(i = 0; i < 1/bound(0.005, cvar("hud_configure_grid_y"), 0.2); ++i)
4377 drawfill(eY * i * vid_conheight * bound(0.005, cvar("hud_configure_grid_y"), 0.2), eY + eX * vid_conwidth, '0.5 0.5 0.5', cvar("hud_configure_grid_alpha"), DRAWFLAG_NORMAL);
4381 if(cvar_string("hud_dock") != "" && cvar_string("hud_dock") != "0")
4382 drawpic('0 0 0', strcat("gfx/hud/", cvar_string("hud_skin"), "/", cvar_string("hud_dock")), eX * vid_conwidth + eY * vid_conheight, HUD_Panel_Dock_GetColor(), cvar("hud_dock_alpha") * menu_fade_alpha, DRAWFLAG_NORMAL); // no aspect ratio forcing on dock...
4384 if(HUD_Panel_CheckActive(HUD_PANEL_RADAR) || hud_configure)
4385 if(cvar_string("hud_radar") != "0" && (cvar("hud_radar") == 2 || teamplay))
4387 if(HUD_Panel_CheckActive(HUD_PANEL_WEAPONICONS) || hud_configure)
4389 if(HUD_Panel_CheckActive(HUD_PANEL_INVENTORY) || hud_configure)
4391 if(HUD_Panel_CheckActive(HUD_PANEL_POWERUPS) || hud_configure)
4393 if(HUD_Panel_CheckActive(HUD_PANEL_HEALTHARMOR) || hud_configure)
4395 if(HUD_Panel_CheckActive(HUD_PANEL_NOTIFY) || hud_configure)
4397 if(HUD_Panel_CheckActive(HUD_PANEL_TIMER) || hud_configure)
4399 if(HUD_Panel_CheckActive(HUD_PANEL_SCORE) || hud_configure)
4401 if(HUD_Panel_CheckActive(HUD_PANEL_RACETIMER) || hud_configure)
4402 if(gametype == GAME_RACE || gametype == GAME_CTS || hud_configure)
4404 if(HUD_Panel_CheckActive(HUD_PANEL_VOTE) || hud_configure)
4406 if(HUD_Panel_CheckActive(HUD_PANEL_MODICONS) || hud_configure)
4409 if(HUD_Panel_CheckActive(HUD_PANEL_PRESSEDKEYS) || hud_configure)
4410 if(spectatee_status > 0 || cvar("hud_pressedkeys") >= 2 || hud_configure)
4411 HUD_DrawPressedKeys();
4412 if(HUD_Panel_CheckActive(HUD_PANEL_CHAT) || hud_configure)
4415 cvar_set("con_chatrect", "0");
4416 if(HUD_Panel_CheckActive(HUD_PANEL_ENGINEINFO) || hud_configure)
4419 // TODO hud_'ify these
4420 if (cvar("cl_showspeed"))
4422 if (cvar("cl_showacceleration"))
4423 HUD_ShowAcceleration();
4425 if (hud_configure && spectatee_status) // try to join if we are in hud_configure mode, but still spectating (in order to get rid of motd and such)
4426 localcmd("cmd selectteam auto; cmd join\n");
4428 if (!hud_configure) // hud config mode disabled, enable normal alpha stuff again
4429 disable_menu_alphacheck = 0;