From 6506bd864a07bd0845348c5ea93058e871246361 Mon Sep 17 00:00:00 2001 From: Juhu <5894800-Juhu_@users.noreply.gitlab.com> Date: Sun, 5 Jul 2020 01:36:06 +0200 Subject: [PATCH] strafehud: add slick detector --- _hud_common.cfg | 5 +++ qcsrc/client/autocvars.qh | 5 +++ qcsrc/client/hud/panel/strafehud.qc | 48 +++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/_hud_common.cfg b/_hud_common.cfg index f01198377..88f9af892 100644 --- a/_hud_common.cfg +++ b/_hud_common.cfg @@ -150,6 +150,11 @@ seta hud_panel_strafehud_direction_color "0 0.5 1" "color of the direction caps seta hud_panel_strafehud_direction_alpha "1" "opacity of the direction caps which indicate the direction the player is currently strafing towards" seta hud_panel_strafehud_direction_width "0.25" "stroke width of the direction caps which indicate the direction the player is currently strafing towards (relative to the panel height)" seta hud_panel_strafehud_direction_length "0.02" "length of the horizontal component of the direction caps which indicate the direction the player is currently strafing towards (relative to the panel width)" +seta hud_panel_strafehud_slickdetector_range "0" "range of the slick detector in qu, \"0\" to disable" +seta hud_panel_strafehud_slickdetector_granularity "2" "value from 0 to 4 which defines how exact the search for slick should be, higher values may yield better results but require more computation" +seta hud_panel_strafehud_slickdetector_color "0 1 1" "color of the slick detector indicator" +seta hud_panel_strafehud_slickdetector_alpha "0.5" "opacity of the slick detector indicator" +seta hud_panel_strafehud_slickdetector_height "0.125" "height of the slick detector indicator (relative to the panel height)" seta hud_panel_strafehud_timeout_air "0.1" "time after take off before changing to air strafe physics when not jumping (visually more consistent hud while on slick downwards ramps)" seta hud_panel_strafehud_timeout_ground "0.03333333" "time after landing before changing to non-air strafe physics (visually more consistent hud while strafe turning when touching the floor after every hop)" seta hud_panel_strafehud_timeout_turn "0.1" "time after releasing the strafe keys before changing mode (visually more consistent hud while switching between left/right strafe turning)" diff --git a/qcsrc/client/autocvars.qh b/qcsrc/client/autocvars.qh index 63c224045..753ff24d9 100644 --- a/qcsrc/client/autocvars.qh +++ b/qcsrc/client/autocvars.qh @@ -348,6 +348,11 @@ vector autocvar_hud_panel_strafehud_direction_color = '0 0.5 1'; float autocvar_hud_panel_strafehud_direction_alpha = 1; float autocvar_hud_panel_strafehud_direction_width = 0.25; float autocvar_hud_panel_strafehud_direction_length = 0.02; +float autocvar_hud_panel_strafehud_slickdetector_range = 0; +int autocvar_hud_panel_strafehud_slickdetector_granularity = 2; +vector autocvar_hud_panel_strafehud_slickdetector_color = '0 1 1'; +float autocvar_hud_panel_strafehud_slickdetector_alpha = 0.5; +float autocvar_hud_panel_strafehud_slickdetector_height = 0.125; float autocvar_hud_panel_strafehud_timeout_air = 0.1; float autocvar_hud_panel_strafehud_timeout_ground = 0.03333333; float autocvar_hud_panel_strafehud_timeout_turn = 0.1; diff --git a/qcsrc/client/hud/panel/strafehud.qc b/qcsrc/client/hud/panel/strafehud.qc index e48462451..d71318e7c 100644 --- a/qcsrc/client/hud/panel/strafehud.qc +++ b/qcsrc/client/hud/panel/strafehud.qc @@ -137,6 +137,7 @@ void HUD_StrafeHUD() float accelzone_width; float overturn_offset; float overturn_width; + float slickdetector_height; vector direction_size_vertical = '0 0 0'; vector direction_size_horizontal = '0 0 0'; float range_minangle; @@ -556,6 +557,53 @@ void HUD_StrafeHUD() } } + slickdetector_height = panel_size.y * bound(0, autocvar_hud_panel_strafehud_slickdetector_height, 0.5); + if(autocvar_hud_panel_strafehud_slickdetector_range > 0 && autocvar_hud_panel_strafehud_slickdetector_alpha > 0 && slickdetector_height > 0 && panel_size.x > 0) // dunno if slick detection works in spectate + { + float slicksteps = 90 / pow(2, bound(0, autocvar_hud_panel_strafehud_slickdetector_granularity, 4)); + vector slickoffset; + bool slickdetected = false; + + slickdetected = IS_ONSLICK(strafeplayer); // don't need to traceline if already touching slick + + // traceline into every direction + trace_dphitq3surfaceflags = 0; + for(float i = 0; i < 360 && !slickdetected; i += slicksteps) + { + float slickrotate; + slickoffset.z = -cos(i * DEG2RAD) * autocvar_hud_panel_strafehud_slickdetector_range; + slickrotate = sin(i * DEG2RAD) * autocvar_hud_panel_strafehud_slickdetector_range; + if(i != 0 && i != 180) + { + for(float j = 0; j < 180 && !slickdetected; j += slicksteps) + { + slickoffset.x = sin(j * DEG2RAD) * slickrotate; + slickoffset.y = cos(j * DEG2RAD) * slickrotate; + + traceline(strafeplayer.origin, strafeplayer.origin + slickoffset, MOVE_WORLDONLY, NULL); + if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK) slickdetected = true; + } + } + else + { + slickoffset.x = slickoffset.y = 0; + traceline(strafeplayer.origin, strafeplayer.origin + slickoffset, MOVE_WORLDONLY, NULL); + if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK) slickdetected = true; + } + } + + // if one traceline hit a slick surface + if(slickdetected) + { + vector slickdetector_size = panel_size; + slickdetector_size.y = slickdetector_height; + // top horizontal line + drawfill(panel_pos - eY * slickdetector_size.y, slickdetector_size, autocvar_hud_panel_strafehud_slickdetector_color, autocvar_hud_panel_strafehud_slickdetector_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); + // bottom horizontal line + drawfill(panel_pos + eY * panel_size.y, slickdetector_size, autocvar_hud_panel_strafehud_slickdetector_color, autocvar_hud_panel_strafehud_slickdetector_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); + } + } + if(speed < (maxspeed + antiflicker_speed) && !immobile) { bestangle_anywhere = true; // moving forward should suffice to gain speed -- 2.39.2