From bd8b5af7b9fa9c21c45480daa5b34945fb3f3311 Mon Sep 17 00:00:00 2001 From: otta8634 Date: Fri, 6 Sep 2024 23:21:12 +0800 Subject: [PATCH] Allow always showing the normal-strafing switch angles on strafehud Enable with _switch 2 for W-turning, or _switch 3 for CPMA turning too Also fixed bug where bestangle displays in wrong place Fixed bug with sv_aircontrol_backwards == 1 implementation Fixed bug with displaying _wturn indicators at wrong times Cleaned up some comments --- _hud_common.cfg | 4 +- qcsrc/client/hud/panel/strafehud.qc | 67 +++++++++++++++++++++++------ qcsrc/client/hud/panel/strafehud.qh | 2 +- 3 files changed, 57 insertions(+), 16 deletions(-) diff --git a/_hud_common.cfg b/_hud_common.cfg index 4991a6f42..2feffaa54 100644 --- a/_hud_common.cfg +++ b/_hud_common.cfg @@ -197,12 +197,12 @@ seta hud_panel_strafehud_angle_arrow_size "0.5" "size of the arrow (relative to seta hud_panel_strafehud_bestangle "1" "set to \"1\" to enable a ghost angle indicator showing the best angle to gain maximum acceleration, 2 = only when CPMA turning" seta hud_panel_strafehud_bestangle_color "1 1 1" "color of the indicator showing the best angle to gain maximum acceleration" seta hud_panel_strafehud_bestangle_alpha "0.5" "opacity of the indicator showing the best angle to gain maximum acceleration" -seta hud_panel_strafehud_switch "1" "set to \"1\" to enable the switch indicator showing the angle to move to when switching sides" +seta hud_panel_strafehud_switch "1" "set to \"1\" to enable the switch indicator showing the angle to move to when switching sides, 2 = show the normal switch indicators when W-turning, 3 = also while CPMA turning" seta hud_panel_strafehud_switch_minspeed "-1" "minimum speed in qu/s at which switch indicator(s) which are used to aid changing strafe direction will be shown (set to -1 for dynamic minspeed)" seta hud_panel_strafehud_switch_color "1 1 0" "color of the switch indicator" seta hud_panel_strafehud_switch_alpha "1" "opacity of the switch indicator" seta hud_panel_strafehud_switch_width "0.003" "width of the strafe angle indicator(s) (relative to the strafe bar width)" -seta hud_panel_strafehud_wturn "1" "enable the W-turn indicators showing the angle to rotate your velocity as fast as possible, 1 = only if W-turning, 2 = also while strafing, 3 = always" +seta hud_panel_strafehud_wturn "1" "enable the W-turn indicators showing the angle to rotate your velocity as fast as possible, 1 = only if W-turning, 2 = also while strafing normally, 3 = also while CPMA turning" seta hud_panel_strafehud_wturn_color "0 1 1" "color of the W-turn indicators" seta hud_panel_strafehud_wturn_alpha "1" "opacity of the W-turn indicators" seta hud_panel_strafehud_wturn_width "0.003" "width of the W-turn indicators (relative to the strafe bar width)" diff --git a/qcsrc/client/hud/panel/strafehud.qc b/qcsrc/client/hud/panel/strafehud.qc index 1f6902f97..3f7963362 100644 --- a/qcsrc/client/hud/panel/strafehud.qc +++ b/qcsrc/client/hud/panel/strafehud.qc @@ -182,6 +182,13 @@ void HUD_StrafeHUD() bool odd_angles = false; float odd_bestangle_offset = 0; float switch_odd_bestangle_offset = 0; + bool draw_normal = false; + float n_bestangle = 0; + float n_odd_bestangle; + float n_bestangle_offset = 0; + float n_switch_bestangle_offset = 0; + float n_odd_bestangle_offset = 0; + float n_switch_odd_bestangle_offset = 0; float switch_bestangle_width = 0; float wturn_bestangle = 0; float wturn_left_bestangle_offset = 0; @@ -634,8 +641,8 @@ void HUD_StrafeHUD() real_overturn_angle = overturn_angle; /* - * k9er: proper W-turn angle is acos(-speed/g * (cos((acos(V) + M_PI * 2) / 3) * 2 + 1)) rad, - * ... where g=dt*32*150, and V=1-(g*g)/(speed*speed), + * k9er: proper W-turn angle is acos(-speed/a * (cos((acos(V) + M_PI * 2) / 3) * 2 + 1)) rad, + * ... where a=dt*32*150, and V=1-(a*a)/(speed*speed), * ... but this very quickly loses accuracy -- should be a strictly decreasing function, yet it increases at only speed=722 with 125 fps * also note this is only valid when such angle is not in the accelzone, formula taking acceleration into account is unfathomably complicated * afaik there's no simplified version of this formula that doesn't involve complex numbers, other than one valid for only speed<27.1 roughly @@ -645,26 +652,42 @@ void HUD_StrafeHUD() * ... but the proper angle can be drawn too if the player wants (autocvar_hud_panel_strafehud_wturn_proper) * for now this is only enabled if sv_airaccel_qw == 1 && sv_aircontrol == 150, since otherwise W-turning gives acceleration */ - bool wturning = wishangle == 0 && (keys_fwd == STRAFEHUD_KEYS_FORWARD || (aircontrol_backwards && keys_fwd == STRAFEHUD_KEYS_BACKWARD)); + bool wturning = !onground && wishangle == 0 && (keys_fwd == STRAFEHUD_KEYS_FORWARD || (aircontrol_backwards && keys_fwd == STRAFEHUD_KEYS_BACKWARD)); bool wturn_check = autocvar_hud_panel_strafehud_wturn && !immobile && aircontrol && (autocvar_hud_panel_strafehud_wturn_unrestricted == 1 || airaccel_qw); if(wturn_check) { - float wturn_g = 32 * aircontrol * dt; - float wturn_V = 1 - (wturn_g * wturn_g) / (speed * speed); - if(autocvar_hud_panel_strafehud_wturn_proper == 1 && wturn_g > 1 && wturn_V < 1 && wturn_V > -1) - wturn_bestangle = acos(-speed / wturn_g * (cos((acos(wturn_V) + M_PI * 2) / 3) * 2 + 1)) * RAD2DEG; + float wturn_a = 32 * aircontrol * dt; + float wturn_V = 1 - (wturn_a * wturn_a) / (speed * speed); + if(autocvar_hud_panel_strafehud_wturn_proper == 1 && wturn_a > 1 && wturn_V < 1 && wturn_V > -1) + wturn_bestangle = acos(-speed / wturn_a * (cos((acos(wturn_V) + M_PI * 2) / 3) * 2 + 1)) * RAD2DEG; else wturn_bestangle = acos(sqrt(2 / 3)) * RAD2DEG; real_wturn_bestangle = wturn_bestangle; } + // draw the switch indicators as if strafing normally, while W-turning or CPMA turning + draw_normal = ((autocvar_hud_panel_strafehud_switch >= 2 && wturning) || (autocvar_hud_panel_strafehud_switch == 3 && turn)); + if(draw_normal) + { + // recalculate bestangle as if strafing normally + float n_maxspeed = PHYS_MAXAIRSPEED(strafeplayer) * maxspeed_mod; + float n_movespeed = n_maxspeed; + float n_maxaccel = PHYS_AIRACCELERATE(strafeplayer) * dt * n_movespeed; + float n_bestspeed = max(n_movespeed - n_maxaccel, 0); + n_bestangle = speed > n_bestspeed + ? acos(n_bestspeed / speed) * RAD2DEG - 45 + : -45; + } + if(direction == STRAFEHUD_DIRECTION_LEFT) // the angle becomes negative in case we strafe left { + n_bestangle *= -1; bestangle *= -1; prebestangle *= -1; overturn_angle *= -1; } odd_bestangle = -bestangle - wishangle; + n_odd_bestangle = -n_bestangle - wishangle; bestangle -= wishangle; prebestangle -= wishangle; overturn_angle -= wishangle; @@ -699,7 +722,7 @@ void HUD_StrafeHUD() currentangle_offset = bound(-hudangle / 2, angle, hudangle / 2) / hudangle * panel_size.x + panel_size.x / 2; // best strafe acceleration angle - if(autocvar_hud_panel_strafehud_switch && speed >= minspeed) + if((autocvar_hud_panel_strafehud_switch || autocvar_hud_panel_strafehud_bestangle) && speed >= minspeed) { bestangle_offset = bestangle / hudangle * panel_size.x + panel_size.x / 2; switch_bestangle_offset = -bestangle / hudangle * panel_size.x + panel_size.x / 2; @@ -710,15 +733,25 @@ void HUD_StrafeHUD() if((angle > -wishangle && direction == STRAFEHUD_DIRECTION_LEFT) || (angle < -wishangle && direction == STRAFEHUD_DIRECTION_RIGHT)) { odd_angles = true; - odd_bestangle_offset = odd_bestangle / hudangle * panel_size.x + panel_size.x / 2; + odd_bestangle_offset = odd_bestangle / hudangle * panel_size.x + panel_size.x / 2; switch_odd_bestangle_offset = (odd_bestangle + bestangle * 2) / hudangle * panel_size.x + panel_size.x / 2; } + if(draw_normal) + { + n_bestangle_offset = n_bestangle / hudangle * panel_size.x + panel_size.x / 2; + n_switch_bestangle_offset = -n_bestangle / hudangle * panel_size.x + panel_size.x / 2; + if(odd_angles) + { + n_odd_bestangle_offset = n_odd_bestangle / hudangle * panel_size.x + panel_size.x / 2; + n_switch_odd_bestangle_offset = (n_odd_bestangle + n_bestangle * 2) / hudangle * panel_size.x + panel_size.x / 2; + } + } } // best angle to aim at when W-turning to maximally rotate velocity vector if(wturn_check) { - bool wturn_show = autocvar_hud_panel_strafehud_wturn == 3 ? true + bool wturn_show = autocvar_hud_panel_strafehud_wturn == 3 ? (fwd || aircontrol_backwards) : autocvar_hud_panel_strafehud_wturn == 2 ? ((fwd || aircontrol_backwards) && !turn) : autocvar_hud_panel_strafehud_wturn == 0 ? false : wturning; @@ -798,6 +831,10 @@ void HUD_StrafeHUD() switch_bestangle_offset += shift_offset; odd_bestangle_offset += shift_offset; switch_odd_bestangle_offset += shift_offset; + n_bestangle_offset += shift_offset; + n_switch_bestangle_offset += shift_offset; + n_odd_bestangle_offset += shift_offset; + n_switch_odd_bestangle_offset += shift_offset; wturn_left_bestangle_offset += shift_offset; wturn_right_bestangle_offset += shift_offset; } @@ -865,8 +902,12 @@ void HUD_StrafeHUD() if(autocvar_hud_panel_strafehud_switch && switch_bestangle_width > 0 && autocvar_hud_panel_strafehud_switch_alpha > 0) { // draw the switch indicator(s) - float offset = !odd_angles ? bestangle_offset : odd_bestangle_offset; - float switch_offset = !odd_angles ? switch_bestangle_offset : switch_odd_bestangle_offset; + float offset = draw_normal + ? (odd_angles ? n_odd_bestangle_offset : n_bestangle_offset) + : (odd_angles ? odd_bestangle_offset : bestangle_offset); + float switch_offset = draw_normal + ? (odd_angles ? n_switch_odd_bestangle_offset : n_switch_bestangle_offset) + : (odd_angles ? switch_odd_bestangle_offset : switch_bestangle_offset); HUD_Panel_DrawStrafeHUD( switch_offset, switch_bestangle_width, hidden_width, @@ -874,7 +915,7 @@ void HUD_StrafeHUD() autocvar_hud_panel_strafehud_switch_alpha * panel_fg_alpha, STRAFEHUD_STYLE_DRAWFILL, STRAFEHUD_GRADIENT_NONE, true); - if(direction == STRAFEHUD_DIRECTION_NONE) + if(direction == STRAFEHUD_DIRECTION_NONE || draw_normal) HUD_Panel_DrawStrafeHUD( offset, switch_bestangle_width, hidden_width, autocvar_hud_panel_strafehud_switch_color, diff --git a/qcsrc/client/hud/panel/strafehud.qh b/qcsrc/client/hud/panel/strafehud.qh index 7ea5fe386..c624f69a6 100644 --- a/qcsrc/client/hud/panel/strafehud.qh +++ b/qcsrc/client/hud/panel/strafehud.qh @@ -35,7 +35,7 @@ float autocvar_hud_panel_strafehud_angle_arrow_size = 0.5; int autocvar_hud_panel_strafehud_bestangle = 1; vector autocvar_hud_panel_strafehud_bestangle_color = '1 1 1'; float autocvar_hud_panel_strafehud_bestangle_alpha = 0.5; -bool autocvar_hud_panel_strafehud_switch = true; +int autocvar_hud_panel_strafehud_switch = 1; float autocvar_hud_panel_strafehud_switch_minspeed = -1; vector autocvar_hud_panel_strafehud_switch_color = '1 1 0'; float autocvar_hud_panel_strafehud_switch_alpha = 1; -- 2.39.2