Skip to content

Commit

Permalink
Fixes 2 gun runtime sources (#4817)
Browse files Browse the repository at this point in the history
# About the pull request

<!-- Remove this text and explain what the purpose of your PR is.

Mention if you have tested your changes. If you changed a map, make sure
you used the mapmerge tool.
If this is an Issue Correction, you can type "Fixes Issue #169420" to
link the PR to the corresponding Issue number #169420.

Remember: something that is self-evident to you might not be to others.
Explain your rationale fully, even if you feel it goes without saying.
-->

This fixes two issues happening on live game:

* The XM88 does not check for successful wielding before registering
signals, presumably causing overriding errors in logs.
* M56D/M2C HMGs do not correctly reset the autofire component when the
operator is removed. This causes it to try to keep firing without an
operator which generates runtimes (presumably in burst fire mode). In
addition this may solve other issues such as the fabled "can use HMG
while dead" one, but I can't confirm it.

# Explain why it's good for the game
Readable logs and less clunky interactions down the line

# Changelog
:cl:
fix: M56D/M2C should now properly stop firing when they stop being used.
/:cl:
  • Loading branch information
fira authored Nov 3, 2023
1 parent 4142fcc commit c6a152b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
10 changes: 5 additions & 5 deletions code/datums/components/autofire/autofire.dm
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,19 @@
if(GUN_FIREMODE_BURSTFIRE)
shots_fired++
if(shots_fired == burst_shots_to_fire)
callback_bursting.Invoke(FALSE)
callback_display_ammo.Invoke()
callback_bursting?.Invoke(FALSE)
callback_display_ammo?.Invoke()
bursting = FALSE
stop_firing()
if(have_to_reset_at_burst_end)//We failed to reset because we were bursting, we do it now
callback_reset_fire.Invoke()
callback_reset_fire?.Invoke()
have_to_reset_at_burst_end = FALSE
return
callback_bursting.Invoke(TRUE)
callback_bursting?.Invoke(TRUE)
bursting = TRUE
next_fire = world.time + burstfire_shot_delay
if(GUN_FIREMODE_AUTOMATIC)
callback_set_firing.Invoke(TRUE)
callback_set_firing?.Invoke(TRUE)
next_fire = world.time + (auto_fire_shot_delay * automatic_delay_mult)
if(GUN_FIREMODE_SEMIAUTO)
return
Expand Down
21 changes: 9 additions & 12 deletions code/modules/cm_marines/smartgun_mount.dm
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,6 @@
var/autofire_slow_mult = 1
/// If the gun is currently burst firing
VAR_PROTECTED/burst_firing = FALSE
/// If the gun is currently auto firing
VAR_PROTECTED/auto_firing = FALSE
/// If the gun should display its ammo count
var/display_ammo = TRUE
/// How many degrees in each direction the gun should be able to fire
Expand Down Expand Up @@ -514,13 +512,14 @@
ammo = GLOB.ammo_list[ammo] //dunno how this works but just sliding this in from sentry-code.
burst_scatter_mult = SCATTER_AMOUNT_TIER_7
update_icon()
AddComponent(/datum/component/automatedfire/autofire, fire_delay, burst_fire_delay, burst_amount, gun_firemode, autofire_slow_mult, CALLBACK(src, PROC_REF(set_burst_firing)), CALLBACK(src, PROC_REF(reset_fire)), CALLBACK(src, PROC_REF(try_fire)), CALLBACK(src, PROC_REF(display_ammo)), CALLBACK(src, PROC_REF(set_auto_firing)))
AddComponent(/datum/component/automatedfire/autofire, fire_delay, burst_fire_delay, burst_amount, gun_firemode, autofire_slow_mult, CALLBACK(src, PROC_REF(set_burst_firing)), CALLBACK(src, PROC_REF(reset_fire)), CALLBACK(src, PROC_REF(try_fire)), CALLBACK(src, PROC_REF(display_ammo)))

/obj/structure/machinery/m56d_hmg/Destroy() //Make sure we pick up our trash.
if(operator)
operator.unset_interaction()
/obj/structure/machinery/m56d_hmg/Destroy(force) //Make sure we pick up our trash.
operator?.unset_interaction()
operator = null
QDEL_NULL(in_chamber)
STOP_PROCESSING(SSobj, src)
. = ..()
return ..()

/obj/structure/machinery/m56d_hmg/get_examine_text(mob/user) //Let us see how much ammo we got in this thing.
. = ..()
Expand Down Expand Up @@ -751,6 +750,8 @@
update_icon() //final safeguard.

/obj/structure/machinery/m56d_hmg/proc/try_fire()
if(!operator)
return
if(!rounds)
to_chat(operator, SPAN_WARNING("<b>*click*</b>"))
playsound(src, 'sound/weapons/gun_empty.ogg', 25, 1, 5)
Expand Down Expand Up @@ -855,6 +856,7 @@

/obj/structure/machinery/m56d_hmg/on_unset_interaction(mob/user)
flags_atom &= ~RELAY_CLICK
SEND_SIGNAL(src, COMSIG_GUN_INTERRUPT_FIRE)
user.status_flags &= ~IMMOBILE_ACTION
user.visible_message(SPAN_NOTICE("[user] lets go of \the [src]."),SPAN_NOTICE("You let go of \the [src], letting the gun rest."))
user.unfreeze()
Expand Down Expand Up @@ -947,7 +949,6 @@
/// Clean up the target, shots fired, and other things related to when you stop firing
/obj/structure/machinery/m56d_hmg/proc/reset_fire()
set_target(null)
set_auto_firing(FALSE)
shots_fired = 0

///Set the target and take care of hard delete
Expand All @@ -960,10 +961,6 @@
if(target)
RegisterSignal(target, COMSIG_PARENT_QDELETING, PROC_REF(clean_target))

/// Setter for auto_firing
/obj/structure/machinery/m56d_hmg/proc/set_auto_firing(auto = FALSE)
auto_firing = auto

/// Print how much ammo is left to chat
/obj/structure/machinery/m56d_hmg/proc/display_ammo()
if(!operator)
Expand Down
1 change: 1 addition & 0 deletions code/modules/projectiles/gun.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1963,6 +1963,7 @@ not all weapons use normal magazines etc. load_into_chamber() itself is designed

/// Setter proc for fa_firing
/obj/item/weapon/gun/proc/set_auto_firing(auto = FALSE)
SIGNAL_HANDLER
fa_firing = auto

/// Getter for gun_user
Expand Down
6 changes: 3 additions & 3 deletions code/modules/projectiles/guns/lever_action.dm
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,9 @@ their unique feature is that a direct hit will buff your damage and firerate

/obj/item/weapon/gun/lever_action/xm88/wield(mob/user)
. = ..()

RegisterSignal(src, COMSIG_ITEM_ZOOM, PROC_REF(scope_on))
RegisterSignal(src, COMSIG_ITEM_UNZOOM, PROC_REF(scope_off))
if(.)
RegisterSignal(src, COMSIG_ITEM_ZOOM, PROC_REF(scope_on))
RegisterSignal(src, COMSIG_ITEM_UNZOOM, PROC_REF(scope_off))

/obj/item/weapon/gun/lever_action/xm88/proc/scope_on(atom/source, mob/current_user)
SIGNAL_HANDLER
Expand Down

0 comments on commit c6a152b

Please sign in to comment.