Skip to content

Commit

Permalink
tweaks to recoil and spread (shiptest-ss13#3094)
Browse files Browse the repository at this point in the history
<!-- Write **BELOW** The Headers and **ABOVE** The comments else it may
not be viewable. -->
<!-- You can view Contributing.MD for a detailed description of the pull
request process. -->

## 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

<!-- Describe The Pull Request. Please be sure every change is
documented or this can delay review and even discourage maintainers from
merging your PR! -->
thgvr edit: cleaned up changelog.
## Changelog

:cl:
balance: Ballistic weapons now have a minimum camera shake.
fix: Gunslinger now functions as intended.
/:cl:

<!-- Both :cl:'s are required for the changelog to work! You can put
your name to the right of the first :cl: if you want to overwrite your
GitHub username as author ingame. -->
<!-- You can use multiple of the same prefix (they're only used for the
icon ingame) and delete the unneeded ones. Despite some of the tags,
changelogs should generally represent how a player might be affected by
the changes rather than a summary of the PR's contents. -->

---------

Co-authored-by: retlaw34 <[email protected]>
  • Loading branch information
2 people authored and MysticalFaceLesS committed Aug 27, 2024
1 parent 153f733 commit 88a0ea3
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 124 deletions.
56 changes: 20 additions & 36 deletions code/modules/projectiles/gun.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down
19 changes: 2 additions & 17 deletions code/modules/projectiles/guns/ballistic/assault.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
26 changes: 3 additions & 23 deletions code/modules/projectiles/guns/ballistic/hmg.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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" : ""]"
Expand Down
24 changes: 4 additions & 20 deletions code/modules/projectiles/guns/ballistic/revolver.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -418,7 +421,7 @@
fire_delay = src::fire_delay
if(fan)
rack()
to_chat(user, "<span class='notice'>You fan the [bolt_wording] of \the [src]!</span>")
to_chat(user, span_notice("You fan the [bolt_wording] of \the [src]!"))
balloon_alert_to_viewers("fans revolver!")
fire_delay = 0 SECONDS

Expand All @@ -436,25 +439,6 @@
return
to_chat(user, "<span class='danger'>The hammer is up on [src]! Pull it down to fire!</span>")

/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)
Expand Down
11 changes: 2 additions & 9 deletions code/modules/projectiles/guns/ballistic/shotgun.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
21 changes: 2 additions & 19 deletions code/modules/projectiles/guns/ballistic/smg.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 88a0ea3

Please sign in to comment.