From 0812781cb7d71c7e559905c95e75f22a3825b15c Mon Sep 17 00:00:00 2001 From: Steam Deck User Date: Thu, 9 Mar 2023 13:58:00 -0500 Subject: [PATCH] SERVER/CLIENT/FTE: More fluid weapon zoom, instant zoom for snipers --- source/client/defs/custom.qc | 4 ++- source/client/hud.qc | 6 ++-- source/client/main.qc | 4 +-- source/server/weapons/weapon_core.qc | 50 +++++++++++++++++++--------- 4 files changed, 43 insertions(+), 21 deletions(-) diff --git a/source/client/defs/custom.qc b/source/client/defs/custom.qc index 1c95548..b12b567 100644 --- a/source/client/defs/custom.qc +++ b/source/client/defs/custom.qc @@ -231,4 +231,6 @@ float GPActive[32]; string build_datetime; #define VERSION_STRING "v1.0" -vector gun_kick; \ No newline at end of file +vector gun_kick; + +float hide_viewmodel; \ No newline at end of file diff --git a/source/client/hud.qc b/source/client/hud.qc index fd1f887..251ad6f 100644 --- a/source/client/hud.qc +++ b/source/client/hud.qc @@ -1182,15 +1182,15 @@ void() Draw_Crosshair = else crosshair_color = [1, 1, 1]; + hide_viewmodel = false; if (getstatf(STAT_WEAPONZOOM) == 2 && zoom_2_time < time) { - setmodel(vmodel, ""); - setmodel(v2model, ""); + hide_viewmodel = true; drawfill('0 0 0', [g_width/2 - g_height/2, g_height, 0], '0 0 0', 1, 0); drawpic([(g_width/2 - g_height/2),0,0], "gfx/hud/scope_nb.tga", [g_height, g_height, 1], [1,1,1], 1); drawfill([(g_width/2 + g_height/2),0,0], [g_width, g_height, 0], '0 0 0', 1, 0); } - + if (getstatf(STAT_HEALTH) < 11) return; diff --git a/source/client/main.qc b/source/client/main.qc index 7201090..07437a9 100644 --- a/source/client/main.qc +++ b/source/client/main.qc @@ -248,7 +248,7 @@ void() Update_Vmodel = local vector dir; local float ads; - if (cvar("r_drawviewmodel") == FALSE) { + if (cvar("r_drawviewmodel") == FALSE || hide_viewmodel == true) { vmodel.origin = '-10000 -10000 -10000'; return; } @@ -1095,7 +1095,7 @@ noref void() CSQC_Parse_Event = Hitmark_time = time + 0.2; break; case 4: - zoom_2_time = time + 0.20; + zoom_2_time = time + 0.05; break; case 5: crosshair_spread_time = time + 70/getWeaponRecoilReturn(getstatf(STAT_ACTIVEWEAPON)); diff --git a/source/server/weapons/weapon_core.qc b/source/server/weapons/weapon_core.qc index 092c4f8..ce2ede4 100644 --- a/source/server/weapons/weapon_core.qc +++ b/source/server/weapons/weapon_core.qc @@ -2448,11 +2448,24 @@ void () Weapon_Logic = #ifdef FTE else { - float zoom_factor = 1 - (0.018*GetWeaponZoomAmount(self.weapon)); - if (self.viewzoom > zoom_factor) - self.viewzoom -= 0.03; - else - self.viewzoom = zoom_factor; + if (self.weapon == W_KAR_SCOPE || self.weapon == W_PTRS || + self.weapon == W_HEADCRACKER || self.weapon == W_PENETRATOR) { + if (self.scopetime >= time) + self.viewzoom = 1 - (0.018*GetWeaponZoomAmount(self.weapon)); + } else { + float zoom_factor = 1 - (0.018*GetWeaponZoomAmount(self.weapon)); + float sigmoid_input = (self.viewzoom - zoom_factor) * 10; // multiply by 10 to adjust the steepness of the sigmoid + float sigmoid_output = 1 / (1 + exp(-sigmoid_input)); // apply the sigmoid function + float zoom_speed = 0.06 * (sigmoid_output + 0.5) * (frametime*40); // adjust the zoom speed based on the sigmoid output + + if (self.viewzoom > zoom_factor) { + self.viewzoom -= zoom_speed; + if (self.viewzoom < zoom_factor) + self.viewzoom = zoom_factor; + } else { + self.viewzoom = zoom_factor; + } + } } #endif // FTE @@ -2470,19 +2483,26 @@ void () Weapon_Logic = if (self.weapon == W_KAR_SCOPE || self.weapon == W_PTRS || self.weapon == W_HEADCRACKER || self.weapon == W_PENETRATOR) { - if (self.viewzoom == 0.2) { - self.viewzoom += 0.03; - ReturnWeaponModel(); - } else { - UpdateVmodel(self.weaponmodel, GetWepSkin(self.weapon)); - UpdateV2model(self.weapon2model, 0); - self.viewzoom += 0.03; - } + ReturnWeaponModel(); + UpdateVmodel(self.weaponmodel, GetWepSkin(self.weapon)); + UpdateV2model(self.weapon2model, 0); + self.viewzoom = 1; } else { - if (self.viewzoom == 0.9) { + if (self.viewzoom == 0.75) { W_AimOut(); } else { - self.viewzoom += 0.03; + float zoom_factor2 = 1 + (0.018 * GetWeaponZoomAmount(self.weapon)); // increase zoom factor + float sigmoid_input2 = (zoom_factor2 - self.viewzoom) * 10; // adjust sigmoid input + float sigmoid_output2 = 1 / (1 + exp(-sigmoid_input2)); // apply the sigmoid function + float zoom_speed2 = 0.06 * (sigmoid_output2 + 0.5) * (frametime * 40); // adjust the zoom speed based on the sigmoid output + + if (self.viewzoom < zoom_factor2) { + self.viewzoom += zoom_speed2; + if (self.viewzoom > zoom_factor2) + self.viewzoom = zoom_factor2; + } else { + self.viewzoom = zoom_factor2; + } } }