From 3947ad55fb9fd3a8e2fc3cbfe8afd6fe2df02795 Mon Sep 17 00:00:00 2001 From: necromanceranne <40847847+necromanceranne@users.noreply.github.com> Date: Tue, 21 Jun 2022 23:37:05 +1000 Subject: [PATCH 1/5] Adds windup autofire functionality. The future is now. --- code/datums/components/fullauto.dm | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/code/datums/components/fullauto.dm b/code/datums/components/fullauto.dm index 425782d049882..9c212be4c186f 100644 --- a/code/datums/components/fullauto.dm +++ b/code/datums/components/fullauto.dm @@ -11,9 +11,16 @@ var/autofire_shot_delay = 0.3 SECONDS //Time between individual shots. var/mouse_status = AUTOFIRE_MOUSEUP //This seems hacky but there can be two MouseDown() without a MouseUp() in between if the user holds click and uses alt+tab, printscreen or similar. + //windup autofire vars + var/windup_autofire = FALSE //Whether the delay between shots increases over time, simulating a spooling weapon. Resets when you stop firing. + var/current_windup_reduction = 0 //the reduction to shot delay for windup. Resets when you stop firing to 0. + var/windup_autofire_reduction_multiplier = 0.3 //the percentage of autfire_shot_delay that is added to current_windup_reduction. In the default example, every shot reduces the shot delay by 30%. + var/windup_autofire_cap = 0.3 //How high of a reduction that current_windup_reduction can reach. In the default example, the delay between shots would be 30% of the original fire delay. + var/windup_spindown = 3 SECONDS //How long it takes for weapons that have spooled-up to reset back to the original firing speed + var/timerid COOLDOWN_DECLARE(next_shot_cd) -/datum/component/automatic_fire/Initialize(_autofire_shot_delay) +/datum/component/automatic_fire/Initialize(_autofire_shot_delay, _windup_autofire, _windup_autofire_reduction_multiplier, _windup_autofire_cap, _windup_spindown) . = ..() if(!isgun(parent)) return COMPONENT_INCOMPATIBLE @@ -21,6 +28,11 @@ RegisterSignal(parent, COMSIG_ITEM_EQUIPPED, .proc/wake_up) if(_autofire_shot_delay) autofire_shot_delay = _autofire_shot_delay + if(_windup_autofire) + src.windup_autofire = _windup_autofire + src.windup_autofire_reduction_multiplier = _windup_autofire_reduction_multiplier + src.windup_autofire_cap = _windup_autofire_cap + src.windup_spindown = _windup_spindown if(autofire_stat == AUTOFIRE_STAT_IDLE && ismob(gun.loc)) var/mob/user = gun.loc wake_up(src, user) @@ -233,6 +245,10 @@ return FALSE shooter.face_atom(target) var/next_delay = autofire_shot_delay + if(windup_autofire) + next_delay = clamp(next_delay - current_windup_reduction, round(autofire_shot_delay * windup_autofire_cap), autofire_shot_delay) + current_windup_reduction = (current_windup_reduction + round(autofire_shot_delay * windup_autofire_reduction_multiplier)) + timerid = addtimer(CALLBACK(src, .proc/windup_reset, FALSE), windup_spindown, TIMER_UNIQUE|TIMER_OVERRIDE|TIMER_STOPPABLE) if(HAS_TRAIT(shooter, TRAIT_DOUBLE_TAP)) next_delay = round(next_delay * 0.5) COOLDOWN_START(src, next_shot_cd, next_delay) @@ -241,6 +257,11 @@ stop_autofiring() return FALSE +/datum/component/automatic_fire/proc/windup_reset(deltimer) + current_windup_reduction = initial(current_windup_reduction) + if(deltimer && timerid) + deltimer(timerid) + // Gun procs. /obj/item/gun/proc/on_autofire_start(mob/living/shooter) From 74c6873eedb96037e57260cf8af1cc2b0d73e324 Mon Sep 17 00:00:00 2001 From: necromanceranne <40847847+necromanceranne@users.noreply.github.com> Date: Thu, 30 Jun 2022 19:07:59 +1000 Subject: [PATCH 2/5] Maint requests --- code/datums/components/fullauto.dm | 34 ++++++++++++++++++------------ 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/code/datums/components/fullauto.dm b/code/datums/components/fullauto.dm index 9c212be4c186f..aa65b979a614b 100644 --- a/code/datums/components/fullauto.dm +++ b/code/datums/components/fullauto.dm @@ -11,28 +11,33 @@ var/autofire_shot_delay = 0.3 SECONDS //Time between individual shots. var/mouse_status = AUTOFIRE_MOUSEUP //This seems hacky but there can be two MouseDown() without a MouseUp() in between if the user holds click and uses alt+tab, printscreen or similar. - //windup autofire vars - var/windup_autofire = FALSE //Whether the delay between shots increases over time, simulating a spooling weapon. Resets when you stop firing. - var/current_windup_reduction = 0 //the reduction to shot delay for windup. Resets when you stop firing to 0. - var/windup_autofire_reduction_multiplier = 0.3 //the percentage of autfire_shot_delay that is added to current_windup_reduction. In the default example, every shot reduces the shot delay by 30%. - var/windup_autofire_cap = 0.3 //How high of a reduction that current_windup_reduction can reach. In the default example, the delay between shots would be 30% of the original fire delay. - var/windup_spindown = 3 SECONDS //How long it takes for weapons that have spooled-up to reset back to the original firing speed + ///windup autofire vars + ///Whether the delay between shots increases over time, simulating a spooling weapon + var/windup_autofire = FALSE // + ///the reduction to shot delay for windup + var/current_windup_reduction = 0 + ///the percentage of autfire_shot_delay that is added to current_windup_reduction + var/windup_autofire_reduction_multiplier = 0.3 + ///How high of a reduction that current_windup_reduction can reach + var/windup_autofire_cap = 0.3 + ///How long it takes for weapons that have spooled-up to reset back to the original firing speed + var/windup_spindown = 3 SECONDS var/timerid COOLDOWN_DECLARE(next_shot_cd) -/datum/component/automatic_fire/Initialize(_autofire_shot_delay, _windup_autofire, _windup_autofire_reduction_multiplier, _windup_autofire_cap, _windup_spindown) +/datum/component/automatic_fire/Initialize(autofire_shot_delay, windup_autofire, windup_autofire_reduction_multiplier, windup_autofire_cap, windup_spindown) . = ..() if(!isgun(parent)) return COMPONENT_INCOMPATIBLE var/obj/item/gun = parent RegisterSignal(parent, COMSIG_ITEM_EQUIPPED, .proc/wake_up) - if(_autofire_shot_delay) - autofire_shot_delay = _autofire_shot_delay - if(_windup_autofire) - src.windup_autofire = _windup_autofire - src.windup_autofire_reduction_multiplier = _windup_autofire_reduction_multiplier - src.windup_autofire_cap = _windup_autofire_cap - src.windup_spindown = _windup_spindown + if(autofire_shot_delay) + src.autofire_shot_delay = autofire_shot_delay + if(windup_autofire) + src.windup_autofire = windup_autofire + src.windup_autofire_reduction_multiplier = windup_autofire_reduction_multiplier + src.windup_autofire_cap = windup_autofire_cap + src.windup_spindown = windup_spindown if(autofire_stat == AUTOFIRE_STAT_IDLE && ismob(gun.loc)) var/mob/user = gun.loc wake_up(src, user) @@ -257,6 +262,7 @@ stop_autofiring() return FALSE +// Reset for our windup, resetting everything back to initial values after a variable set amount of time (determined by var/windup_spindown). /datum/component/automatic_fire/proc/windup_reset(deltimer) current_windup_reduction = initial(current_windup_reduction) if(deltimer && timerid) From 00e9c1b3134c3d0dd43f1d569857c6049191f7cb Mon Sep 17 00:00:00 2001 From: necromanceranne <40847847+necromanceranne@users.noreply.github.com> Date: Fri, 1 Jul 2022 09:48:43 +1000 Subject: [PATCH 3/5] Update code/datums/components/fullauto.dm Co-authored-by: MrMelbert <51863163+MrMelbert@users.noreply.github.com> --- code/datums/components/fullauto.dm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/datums/components/fullauto.dm b/code/datums/components/fullauto.dm index aa65b979a614b..d8c491959358b 100644 --- a/code/datums/components/fullauto.dm +++ b/code/datums/components/fullauto.dm @@ -13,7 +13,7 @@ ///windup autofire vars ///Whether the delay between shots increases over time, simulating a spooling weapon - var/windup_autofire = FALSE // + var/windup_autofire = FALSE ///the reduction to shot delay for windup var/current_windup_reduction = 0 ///the percentage of autfire_shot_delay that is added to current_windup_reduction From 92a831755f1e9d72b5ae4c06cd1db802be33ae27 Mon Sep 17 00:00:00 2001 From: necromanceranne <40847847+necromanceranne@users.noreply.github.com> Date: Fri, 1 Jul 2022 09:49:25 +1000 Subject: [PATCH 4/5] Update code/datums/components/fullauto.dm Co-authored-by: MrMelbert <51863163+MrMelbert@users.noreply.github.com> --- code/datums/components/fullauto.dm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/datums/components/fullauto.dm b/code/datums/components/fullauto.dm index d8c491959358b..86acafb8c59de 100644 --- a/code/datums/components/fullauto.dm +++ b/code/datums/components/fullauto.dm @@ -262,7 +262,7 @@ stop_autofiring() return FALSE -// Reset for our windup, resetting everything back to initial values after a variable set amount of time (determined by var/windup_spindown). +/// Reset for our windup, resetting everything back to initial values after a variable set amount of time (determined by var/windup_spindown). /datum/component/automatic_fire/proc/windup_reset(deltimer) current_windup_reduction = initial(current_windup_reduction) if(deltimer && timerid) From 2588ed636d8c6fa423b47f410a56baa42bb85ff4 Mon Sep 17 00:00:00 2001 From: necromanceranne <40847847+necromanceranne@users.noreply.github.com> Date: Sat, 2 Jul 2022 17:04:33 +1000 Subject: [PATCH 5/5] further documenting --- code/datums/components/fullauto.dm | 1 + 1 file changed, 1 insertion(+) diff --git a/code/datums/components/fullauto.dm b/code/datums/components/fullauto.dm index 86acafb8c59de..4d1b31d0df3d0 100644 --- a/code/datums/components/fullauto.dm +++ b/code/datums/components/fullauto.dm @@ -22,6 +22,7 @@ var/windup_autofire_cap = 0.3 ///How long it takes for weapons that have spooled-up to reset back to the original firing speed var/windup_spindown = 3 SECONDS + ///Timer for tracking the spindown reset timings var/timerid COOLDOWN_DECLARE(next_shot_cd)