From 88a0ea361f69a690d7a83f82e5013ed135edb5bc Mon Sep 17 00:00:00 2001
From: FalloutFalcon <86381784+FalloutFalcon@users.noreply.github.com>
Date: Mon, 26 Aug 2024 16:00:37 -0500
Subject: [PATCH] tweaks to recoil and spread (#3094)
## About The Pull Request
gunslingers work now, min recoil for ballistic, much cleaner and clearer
code
gunslingers and poor aim can SOMETIMES hit a clean shot
thgvr edit: cleaned up changelog.
## Changelog
:cl:
balance: Ballistic weapons now have a minimum camera shake.
fix: Gunslinger now functions as intended.
/:cl:
---------
Co-authored-by: retlaw34 <58402542+retlaw34@users.noreply.github.com>
---
code/modules/projectiles/gun.dm | 56 +++++++------------
.../projectiles/guns/ballistic/assault.dm | 19 +------
.../modules/projectiles/guns/ballistic/hmg.dm | 26 +--------
.../projectiles/guns/ballistic/revolver.dm | 24 ++------
.../projectiles/guns/ballistic/shotgun.dm | 11 +---
.../modules/projectiles/guns/ballistic/smg.dm | 21 +------
6 files changed, 33 insertions(+), 124 deletions(-)
diff --git a/code/modules/projectiles/gun.dm b/code/modules/projectiles/gun.dm
index ca1a1a89b8c9..023f6212e06f 100644
--- a/code/modules/projectiles/gun.dm
+++ b/code/modules/projectiles/gun.dm
@@ -316,6 +316,9 @@
///This prevents gun from firing until the coodown is done, affected by lag
var/current_cooldown = 0
+ var/gunslinger_recoil_bonus = 0
+ var/gunslinger_spread_bonus = 0
+
/obj/item/gun/Initialize()
. = ..()
RegisterSignal(src, COMSIG_TWOHANDED_WIELD, PROC_REF(on_wield))
@@ -802,61 +805,42 @@
/obj/item/gun/proc/before_firing(atom/target,mob/user)
return
-// We do it like this in case theres some specific gun behavior for adjusting recoil, like bipods or folded stocks
/obj/item/gun/proc/calculate_recoil(mob/user, recoil_bonus = 0)
- return recoil_bonus
+ if(HAS_TRAIT(user, TRAIT_GUNSLINGER))
+ recoil_bonus += gunslinger_recoil_bonus
+ return clamp(recoil_bonus, 0 , INFINITY)
-// We do it like this in case theres some specific gun behavior for adjusting spread, like bipods or folded stocks
/obj/item/gun/proc/calculate_spread(mob/user, bonus_spread)
- ///our final spread value
- var/sprd = 0
- ///our randomized value after checking if we are wielded or not
+ var/final_spread = 0
var/randomized_gun_spread = 0
- ///bonus
- var/randomized_bonus_spread
- // do we have poor aim
- var/poor_aim = FALSE
+ var/randomized_bonus_spread = 0
- //do we have bonus_spread ? If so, set sprd to it because it means a subtype's proc messed with it
- sprd += bonus_spread
+ final_spread += bonus_spread
- //reset bonus_spread for poor aim...
- bonus_spread = 0
+ if(HAS_TRAIT(user, TRAIT_GUNSLINGER))
+ randomized_bonus_spread += rand(0, gunslinger_spread_bonus)
- // if we have poor aim, we fuck the shooter over
if(HAS_TRAIT(user, TRAIT_POOR_AIM))
- bonus_spread += 25
- poor_aim = TRUE
- // then we randomize the bonus spread
- randomized_bonus_spread = rand(poor_aim ? 10 : 0, bonus_spread) //poor aim is no longer just a nusiance
-
- //then, we mutiply previous bonus spread as it means dual wielding usually, it also means poor aim is also even more severe
- randomized_bonus_spread *= DUALWIELD_PENALTY_EXTRA_MULTIPLIER
+ randomized_bonus_spread += rand(0, 25)
- // we will then calculate gun spread depending on if we are fully wielding (after do_after) the gun or not
+ //We will then calculate gun spread depending on if we are fully wielding (after do_after) the gun or not
randomized_gun_spread = rand(0, wielded_fully ? spread : spread_unwielded)
- //finally, we put it all together including if sprd has a value
- sprd += randomized_gun_spread + randomized_bonus_spread
-
- //clamp it down to avoid guns with negative spread to have worse recoil...
- sprd = clamp(sprd, 0, INFINITY)
+ final_spread += randomized_gun_spread + randomized_bonus_spread
- // im not sure what this does, i beleive its meant to make it so bullet spread goes in the opposite direction? get back to me on this - update,i have commented it out, however it appears be dapening spread. weird.
- //sprd *= (rand() - 0.5)
+ //Clamp it down to avoid guns with negative spread to have worse recoil...
+ final_spread = clamp(final_spread, 0, INFINITY)
- //coin flip if we mutiply output by -1 so spread isn't JUST to the right
+ //So spread isn't JUST to the right
if(prob(50))
- sprd *= -1
+ final_spread *= -1
- // then we round it up and send it!
- sprd = round(sprd)
+ final_spread = round(final_spread)
- return sprd
+ return final_spread
/obj/item/gun/proc/simulate_recoil(mob/living/user, recoil_bonus = 0, firing_angle)
var/total_recoil = calculate_recoil(user, recoil_bonus)
- total_recoil = clamp(total_recoil, 0 , INFINITY)
var/actual_angle = firing_angle + rand(-recoil_deviation, recoil_deviation) + 180
if(actual_angle > 360)
diff --git a/code/modules/projectiles/guns/ballistic/assault.dm b/code/modules/projectiles/guns/ballistic/assault.dm
index e29196b3401a..d5ed7a8225bf 100644
--- a/code/modules/projectiles/guns/ballistic/assault.dm
+++ b/code/modules/projectiles/guns/ballistic/assault.dm
@@ -14,23 +14,8 @@
rack_sound = 'sound/weapons/gun/rifle/ar_cock.ogg'
spread_unwielded = 20
-/obj/item/gun/ballistic/automatic/assault/calculate_recoil(mob/user, recoil_bonus = 0)
- var/gunslinger_bonus = 2
- var/total_recoil = recoil_bonus
-
- if(HAS_TRAIT(user, TRAIT_GUNSLINGER)) //gunslinger penalty
- total_recoil += gunslinger_bonus
-
- return ..(user, total_recoil)
-
-/obj/item/gun/ballistic/automatic/assault/calculate_spread(mob/user, bonus_spread)
- var/gunslinger_bonus = 16
- var/total_spread = bonus_spread
-
- if(HAS_TRAIT(user, TRAIT_GUNSLINGER)) //gunslinger penalty
- total_spread += gunslinger_bonus
-
- return ..(user, total_spread)
+ gunslinger_recoil_bonus = 2
+ gunslinger_spread_bonus = 16
/obj/item/gun/ballistic/automatic/assault/skm
name = "\improper SKM-24"
diff --git a/code/modules/projectiles/guns/ballistic/hmg.dm b/code/modules/projectiles/guns/ballistic/hmg.dm
index 8d614958de4f..ccf21a2c7c0e 100644
--- a/code/modules/projectiles/guns/ballistic/hmg.dm
+++ b/code/modules/projectiles/guns/ballistic/hmg.dm
@@ -18,6 +18,9 @@
recoil_unwielded = 4
wield_slowdown = 3
+ gunslinger_recoil_bonus = 2
+ gunslinger_spread_bonus = 20
+
///does this have a bipod?
var/has_bipod = FALSE
///is the bipod deployed?
@@ -116,29 +119,6 @@
. = ..()
retract_bipod(user=user)
-/obj/item/gun/ballistic/automatic/hmg/calculate_recoil(mob/user, recoil_bonus = 0)
- var/gunslinger_bonus = 2
- var/total_recoil = recoil_bonus
-
- if(bipod_deployed)
- total_recoil += deploy_recoil_bonus
- if(HAS_TRAIT(user, TRAIT_GUNSLINGER)) //gunslinger penalty
- total_recoil += gunslinger_bonus
-
- return ..(user, total_recoil)
-
-/obj/item/gun/ballistic/automatic/hmg/calculate_spread(mob/user, bonus_spread)
- var/gunslinger_bonus = 20
- var/total_spread = bonus_spread
-
- if(bipod_deployed)
- total_spread += deploy_spread_bonus
- if(HAS_TRAIT(user, TRAIT_GUNSLINGER)) //gunslinger penalty
- total_spread += gunslinger_bonus
-
- return ..(user, total_spread)
-
-
/obj/item/gun/ballistic/automatic/hmg/update_icon_state()
. = ..()
item_state = "[initial(item_state)][bipod_deployed ? "_deployed" : ""]"
diff --git a/code/modules/projectiles/guns/ballistic/revolver.dm b/code/modules/projectiles/guns/ballistic/revolver.dm
index 545cbf8bf117..6a2e30c9cddb 100644
--- a/code/modules/projectiles/guns/ballistic/revolver.dm
+++ b/code/modules/projectiles/guns/ballistic/revolver.dm
@@ -40,6 +40,9 @@
safety_wording = "hammer"
+ gunslinger_recoil_bonus = -1
+ gunslinger_spread_bonus = -8
+
var/gate_loaded = FALSE //for stupid wild west shit
var/gate_offset = 5 //for wild west shit 2: instead of ejecting the chambered round, eject the next round if 1
var/gate_load_direction = REVOLVER_AUTO_ROTATE_RIGHT_LOADING //when we load ammo with a box, which direction do we rotate the cylinder? unused with normal revolvers
@@ -418,7 +421,7 @@
fire_delay = src::fire_delay
if(fan)
rack()
- to_chat(user, "You fan the [bolt_wording] of \the [src]!")
+ to_chat(user, span_notice("You fan the [bolt_wording] of \the [src]!"))
balloon_alert_to_viewers("fans revolver!")
fire_delay = 0 SECONDS
@@ -436,25 +439,6 @@
return
to_chat(user, "The hammer is up on [src]! Pull it down to fire!")
-/obj/item/gun/ballistic/revolver/calculate_recoil(mob/user, recoil_bonus = 0)
- var/gunslinger_bonus = -1
- var/total_recoil = recoil_bonus
-
- if(HAS_TRAIT(user, TRAIT_GUNSLINGER)) //gunslinger bonus
- total_recoil += gunslinger_bonus
- total_recoil = clamp(total_recoil,0,INFINITY)
-
- return ..(user, total_recoil)
-
-/obj/item/gun/ballistic/revolver/calculate_spread(mob/user, bonus_spread)
- var/gunslinger_bonus = -8
- var/total_spread = bonus_spread
-
- if(HAS_TRAIT(user, TRAIT_GUNSLINGER)) //gunslinger bonus
- total_spread += gunslinger_bonus
-
- return ..(user, total_spread)
-
/obj/item/gun/ballistic/revolver/pickup(mob/user)
. = ..()
tryflip(user)
diff --git a/code/modules/projectiles/guns/ballistic/shotgun.dm b/code/modules/projectiles/guns/ballistic/shotgun.dm
index 9172b919adaa..f63328035959 100644
--- a/code/modules/projectiles/guns/ballistic/shotgun.dm
+++ b/code/modules/projectiles/guns/ballistic/shotgun.dm
@@ -35,6 +35,8 @@
recoil = 1
recoil_unwielded = 4
+ gunslinger_recoil_bonus = -1
+
/obj/item/gun/ballistic/shotgun/blow_up(mob/user)
if(chambered && chambered.BB)
process_fire(user, user, FALSE)
@@ -46,15 +48,6 @@
return TRUE
return FALSE
-/obj/item/gun/ballistic/shotgun/calculate_recoil(mob/user, recoil_bonus = 0)
- var/gunslinger_bonus = -1
- var/total_recoil = recoil_bonus
- if(HAS_TRAIT(user, TRAIT_GUNSLINGER)) //gunslinger bonus
- total_recoil += gunslinger_bonus
- total_recoil = clamp(total_recoil,0,INFINITY)
-
- return ..(user, total_recoil)
-
// BRIMSTONE SHOTGUN //
/obj/item/gun/ballistic/shotgun/brimstone
diff --git a/code/modules/projectiles/guns/ballistic/smg.dm b/code/modules/projectiles/guns/ballistic/smg.dm
index fbc2fc4d11bc..d43e324cfacd 100644
--- a/code/modules/projectiles/guns/ballistic/smg.dm
+++ b/code/modules/projectiles/guns/ballistic/smg.dm
@@ -19,25 +19,8 @@
eject_sound = 'sound/weapons/gun/smg/smg_unload.ogg'
eject_empty_sound = 'sound/weapons/gun/smg/smg_unload.ogg'
-/obj/item/gun/ballistic/automatic/smg/calculate_recoil(mob/user, recoil_bonus = 0)
- var/gunslinger_bonus = 2
- var/total_recoil
- if(.)
- total_recoil += .
- if(HAS_TRAIT(user, TRAIT_GUNSLINGER)) //gunslinger penalty
- total_recoil += gunslinger_bonus
- . = total_recoil
- return ..()
-
-/obj/item/gun/ballistic/automatic/smg/calculate_spread(mob/user, bonus_spread)
- var/gunslinger_bonus = 16
- var/total_spread = bonus_spread
- if(.)
- total_spread += .
- if(HAS_TRAIT(user, TRAIT_GUNSLINGER)) //gunslinger penalty
- total_spread += gunslinger_bonus
- . = total_spread
- return ..()
+ gunslinger_recoil_bonus = 2
+ gunslinger_spread_bonus = 16
/obj/item/gun/ballistic/automatic/smg/c20r
name = "\improper C-20r SMG"