From 15de0ed49d33bfceb3b7a4539adfda45f330d6a8 Mon Sep 17 00:00:00 2001 From: CHOMPStation2StaffMirrorBot <94713762+CHOMPStation2StaffMirrorBot@users.noreply.github.com> Date: Fri, 7 Feb 2025 10:12:17 -0700 Subject: [PATCH] [MIRROR] Gets rid of sleep in Fire and Fire_userless (#10086) Co-authored-by: Cameron Lennox Co-authored-by: Kashargul <144968721+Kashargul@users.noreply.github.com> --- code/modules/projectiles/gun.dm | 224 ++++++++---------- .../projectiles/guns/energy/particle.dm | 2 +- code/modules/projectiles/guns/energy/phase.dm | 2 +- code/modules/projectiles/guns/energy/pump.dm | 2 +- .../projectiles/guns/energy/pump_ch.dm | 2 +- .../projectiles/guns/energy/special.dm | 2 +- code/modules/xenobio/items/weapons.dm | 2 +- .../code/modules/projectiles/precursor/tyr.dm | 2 +- 8 files changed, 109 insertions(+), 129 deletions(-) diff --git a/code/modules/projectiles/gun.dm b/code/modules/projectiles/gun.dm index 4d8d9f0982..adb9d81978 100644 --- a/code/modules/projectiles/gun.dm +++ b/code/modules/projectiles/gun.dm @@ -52,7 +52,6 @@ drop_sound = 'sound/items/drop/gun.ogg' pickup_sound = 'sound/items/pickup/gun.ogg' - var/recoil_mode = 1 //0 = no micro recoil, 1 = regular, anything higher than 1 is a multiplier //YAWN Addition, ported from CHOMP var/automatic = 0 var/burst = 1 var/fire_delay = 6 //delay after shooting before the gun can be used again @@ -95,6 +94,7 @@ var/obj/item/dnalockingchip/attached_lock var/last_shot = 0 //records the last shot fired + var/recoil_mode = 1 //If the gun will hurt micros if shot or not. Disabled on Virgo, used downstream. //CHOMPEDIT - Enabled //VOREStation Add - /tg/ icon system var/charge_sections = 4 @@ -311,15 +311,13 @@ if(!canremove) return - //CHOMPEdit start - move these around so that nonhumans can actually click-drag guns at all - if (istype(usr.loc,/obj/mecha)) // stops inventory actions in a mech. why? - return - - if (!( istype(over_object, /obj/screen) )) - return ..() - if (ishuman(usr) || issmall(usr)) //so monkeys can take off their backpacks -- Urist - //CHOMPEdit End + + if (istype(usr.loc,/obj/mecha)) // stops inventory actions in a mech. why? + return + + if (!( istype(over_object, /obj/screen) )) + return ..() //makes sure that the thing is equipped, so that we can't drag it into our hand from miles away. //there's got to be a better way of doing this. @@ -364,99 +362,83 @@ user.setMoveCooldown(shoot_time) //no moving while shooting either next_fire_time = world.time + shoot_time + handle_gunfire(target, user, clickparams, pointblank, reflex, 1, FALSE) - var/held_twohanded = (user.can_wield_item(src) && src.is_held_twohanded(user)) +/obj/item/gun/proc/handle_gunfire(atom/target, mob/living/user, clickparams, pointblank=0, reflex=0, var/ticker, var/recursive = FALSE) + PRIVATE_PROC(TRUE) + SHOULD_NOT_OVERRIDE(TRUE) + if(ticker > burst) + return //we're done here + if(!ismob(loc)) //We've been dropped. + return + if(user.stat) //We've been KO'd or have died. No shooting while dead. + return + if(ticker >= 250) //If you go too far above this, your game will kick you and force you to reconnect. This is already EXTREMELY leninent. + return //In testing, I reached 937 bullets out of 1000 being fired with a delay of 0.1 before being kicked. + var/held_twohanded = (user.can_wield_item(src) && is_held_twohanded(user)) //actually attempt to shoot var/turf/targloc = get_turf(target) //cache this in case target gets deleted during shooting, e.g. if it was a securitron that got destroyed. -/* // Commented out for quality control and testing. - shooting = 1 - if(automatic == 1 && auto_target && auto_target.active)//When we are going to shoot and have an auto_target AND its active meaning we clicked on it we tell it to burstfire 1000 rounds - burst = 1000//Yes its not EXACTLY full auto but when are we shooting more than 1000 normally and it can easily be made higher -*/ - for(var/i in 1 to burst) - /* // Commented out for quality control and testing. - if(!reflex && automatic)//If we are shooting automatic then check our target, however if we are shooting reflex we dont use automatic - //extra sanity checking. - if(user.incapacitated()) - return - if(user.get_active_hand() != src) - break - if(!auto_target) break//Stopped shooting - else if(auto_target.loc) - target = auto_target.loc - //Lastly just update our dir if needed - if(user.dir != get_dir(user, auto_target)) - user.face_atom(auto_target) - */ - var/obj/projectile = consume_next_projectile(user) - if(!projectile) - handle_click_empty(user) - break - - if(i == 1) // So one burst only makes one message and not 3+ messages. - handle_firing_text(user, target, pointblank, reflex) - - process_accuracy(projectile, user, target, i, held_twohanded) - - if(pointblank) - process_point_blank(projectile, user, target) - - if(process_projectile(projectile, user, target, user.zone_sel.selecting, clickparams)) - handle_post_fire(user, target, pointblank, reflex) - update_icon() - - if(i < burst) - sleep(burst_delay) - - if(!(target && target.loc)) - target = targloc - pointblank = 0 - - last_shot = world.time - -/* - // Commented out for quality control and testing. - shooting = 0 -*/ - - // We do this down here, so we don't get the message if we fire an empty gun. - if(user.item_is_in_hands(src) && user.hands_are_full()) - if(one_handed_penalty >= 20) - to_chat(user, span_warning("You struggle to keep \the [src] pointed at the correct position with just one hand!")) - //update timing - user.setClickCooldown(DEFAULT_QUICK_COOLDOWN) - user.setMoveCooldown(move_delay) - next_fire_time = world.time + fire_delay + if(recursive) + user.setClickCooldown(DEFAULT_QUICK_COOLDOWN) + next_fire_time = world.time + fire_delay + if(muzzle_flash) + if(gun_light) + set_light(light_brightness) + else + set_light(0) - accuracy = initial(accuracy) //Reset the gun's accuracy + if(ticker <= burst) + var/obj/projectile = consume_next_projectile(user) + if(!projectile) //click, out of bullets + handle_click_empty(user) + return - if(muzzle_flash) - //VOREStation Edit - Flashlights - if(gun_light) - set_light(light_brightness) else - set_light(0) - //VOREStation Edit End + if(ticker == 1) // So one burst only makes one message and not 3+ messages. + handle_firing_text(user, target, pointblank, reflex) - //YAWNEDIT: Recoil knockdown for micros, ported from CHOMPStation - if(recoil_mode && iscarbon(user)) - var/mob/living/carbon/nerd = user - var/mysize = nerd.size_multiplier - if(recoil_mode > 0) - if(mysize <= 0.60) - nerd.Weaken(1*recoil_mode) - if(!istype(src,/obj/item/gun/energy)) - nerd.adjustBruteLoss((5-mysize*4)*recoil_mode) - to_chat(nerd, span_danger("You're so tiny that you drop the gun and hurt yourself from the recoil!")) - else - to_chat(nerd, span_danger("You're so tiny that the pull of the trigger causes you to drop the gun!")) + process_accuracy(projectile, user, target, ticker, held_twohanded) + + if(pointblank) + process_point_blank(projectile, user, target) + + if(process_projectile(projectile, user, target, user.zone_sel.selecting, clickparams)) + handle_post_fire(user, target, pointblank, reflex) + update_icon() + + // We do this down here, so we don't get the message if we fire an empty gun. + if(user.item_is_in_hands(src) && user.hands_are_full()) + if(one_handed_penalty >= 20) + to_chat(user, span_warning("You struggle to keep \the [src] pointed at the correct position with just one hand!")) + + accuracy = initial(accuracy) //Reset our accuracy + last_shot = world.time + user.hud_used.update_ammo_hud(user, src) + user.setClickCooldown(DEFAULT_QUICK_COOLDOWN) + + if(recoil_mode && iscarbon(user)) + var/mob/living/carbon/micro = user + var/mysize = micro.size_multiplier + if(recoil_mode > 0) + if(mysize <= 0.60) + micro.Weaken(1*recoil_mode) + if(!istype(src,/obj/item/gun/energy)) + micro.adjustBruteLoss((5-mysize*4)*recoil_mode) + to_chat(micro, span_danger("You're so tiny that you drop the gun and hurt yourself from the recoil!")) + else + to_chat(micro, span_danger("You're so tiny that the pull of the trigger causes you to drop the gun!")) + + if(!(target && target.loc)) + target = targloc + pointblank = 0 + + if(ticker < burst) + addtimer(CALLBACK(src, PROC_REF(handle_gunfire),target, user, clickparams, pointblank, reflex, ++ticker, TRUE), burst_delay, TIMER_DELETE_ME) - //YAWNEDIT: Knockdown code end - user.hud_used.update_ammo_hud(user, src) // Similar to the above proc, but does not require a user, which is ideal for things like turrets. /obj/item/gun/proc/Fire_userless(atom/target) @@ -468,19 +450,34 @@ var/shoot_time = (burst - 1)* burst_delay next_fire_time = world.time + shoot_time + handle_userless_gunfire(target, 1, FALSE) +// This is horrible. I tried to keep the old way it had because if I try to use the fancy procs above like handle_post_fire, it expects a user. +// Which this doesn't have. It's ugly but whatever. This is used in literally one place (sawn off shotguns) and should honestly just be axed. +/obj/item/gun/proc/handle_userless_gunfire(atom/target, var/ticker, var/recursive = FALSE) + PRIVATE_PROC(TRUE) + SHOULD_NOT_OVERRIDE(TRUE) + if(ticker > burst) + return //we're done here + + //actually attempt to shoot var/turf/targloc = get_turf(target) //cache this in case target gets deleted during shooting, e.g. if it was a securitron that got destroyed. - for(var/i in 1 to burst) - var/obj/projectile = consume_next_projectile() - if(!projectile) + + //update timing + if(recursive) + next_fire_time = world.time + fire_delay + if(muzzle_flash) + set_light(0) + + if(ticker <= burst) + var/obj/item/projectile/P = consume_next_projectile() + if(!P) //click, out of bullets handle_click_empty() - break + return - if(istype(projectile, /obj/item/projectile)) - var/obj/item/projectile/P = projectile - - var/acc = burst_accuracy[min(i, burst_accuracy.len)] - var/disp = dispersion[min(i, dispersion.len)] + else + var/acc = burst_accuracy[min(ticker, burst_accuracy.len)] + var/disp = dispersion[min(ticker, dispersion.len)] P.accuracy = accuracy + acc P.dispersion = disp @@ -491,6 +488,7 @@ P.old_style_target(target) P.fire() + accuracy = initial(accuracy) last_shot = world.time play_fire_sound() @@ -499,22 +497,11 @@ set_light(muzzle_flash) update_icon() - //process_accuracy(projectile, user, target, acc, disp) + if(!(target && target.loc)) + target = targloc - // if(pointblank) - // process_point_blank(projectile, user, target) - - // if(process_projectile(projectile, null, target, user.zone_sel.selecting, clickparams)) - // handle_post_fire(null, target, pointblank, reflex) - - // update_icon() - - if(i < burst) - sleep(burst_delay) - - if(!(target && target.loc)) - target = targloc - //pointblank = 0 + if(ticker < burst) + addtimer(CALLBACK(src, PROC_REF(handle_gunfire),target, ++ticker, TRUE), burst_delay, TIMER_DELETE_ME) var/target_for_log if(ismob(target)) @@ -524,13 +511,6 @@ add_attack_logs("Unmanned",target_for_log,"Fired [src.name]") - //update timing - next_fire_time = world.time + fire_delay - - accuracy = initial(accuracy) //Reset the gun's accuracy - - if(muzzle_flash) - set_light(0) //obtains the next projectile to fire /obj/item/gun/proc/consume_next_projectile() @@ -789,7 +769,7 @@ var/datum/firemode/new_mode = firemodes[sel_mode] new_mode.apply_to(src) to_chat(user, span_notice("\The [src] is now set to [new_mode.name].")) - user.hud_used.update_ammo_hud(user, src) + user.hud_used.update_ammo_hud(user, src) // TGMC Ammo HUD return new_mode diff --git a/code/modules/projectiles/guns/energy/particle.dm b/code/modules/projectiles/guns/energy/particle.dm index 0c2ef03aa2..8c75273d6e 100644 --- a/code/modules/projectiles/guns/energy/particle.dm +++ b/code/modules/projectiles/guns/energy/particle.dm @@ -21,7 +21,7 @@ charge_cost = 200 //slightly more shots than lasers var/safetycatch = 0 //if 1, won't let you fire in pressurised environment, rather than malfunctioning var/obj/item/pressurelock/attached_safety - recoil_mode = 0 //CHOMP Addition: Removes recoil for micros. + recoil_mode = 0 /obj/item/gun/energy/particle/advanced //particle equivalent of AEG diff --git a/code/modules/projectiles/guns/energy/phase.dm b/code/modules/projectiles/guns/energy/phase.dm index 0cdf1fcea3..db54c1747a 100644 --- a/code/modules/projectiles/guns/energy/phase.dm +++ b/code/modules/projectiles/guns/energy/phase.dm @@ -13,7 +13,7 @@ charge_cost = 160 //Chompedit Bringing charge cost down for all phase weapons. 15 shots on normal cell projectile_type = /obj/item/projectile/energy/phase one_handed_penalty = 15 - recoil_mode = 0 //CHOMP Addition: Removes recoil for micros. + recoil_mode = 0 /obj/item/gun/energy/locked/phasegun/unlocked desc = "The RayZar EW26 Artemis, also known as the 'phase carbine', is a downsized energy-based weapon specifically designed for use against wildlife." //ChompEDIT diff --git a/code/modules/projectiles/guns/energy/pump.dm b/code/modules/projectiles/guns/energy/pump.dm index f413b6f386..95b40e961a 100644 --- a/code/modules/projectiles/guns/energy/pump.dm +++ b/code/modules/projectiles/guns/energy/pump.dm @@ -78,7 +78,7 @@ list(mode_name="lethal", fire_delay=12, projectile_type=/obj/item/projectile/beam/phaser, charge_cost = 300), list(mode_name="low-power", fire_delay=8, projectile_type=/obj/item/projectile/beam/phaser/light, charge_cost = 80), ) - recoil_mode = 0 //CHOMP Addition: Removes recoil for micros. + recoil_mode = 0 /obj/item/gun/energy/locked/frontier/unload_ammo(var/mob/user) if(recharging) diff --git a/code/modules/projectiles/guns/energy/pump_ch.dm b/code/modules/projectiles/guns/energy/pump_ch.dm index de07fd77c2..9ec4f24cd4 100644 --- a/code/modules/projectiles/guns/energy/pump_ch.dm +++ b/code/modules/projectiles/guns/energy/pump_ch.dm @@ -138,7 +138,7 @@ list(mode_name="lethal", fire_delay=10, projectile_type=/obj/item/projectile/beam/phaser, charge_cost = 80), //Chompedit Reduced cost list(mode_name="low-power", fire_delay=5, projectile_type=/obj/item/projectile/beam/phaser/light, charge_cost = 40), //Chompedit Reduced cost ) //CHOMPedit Adjusts cost and fire delay to match adjusted beams. - recoil_mode = 0 //CHOMP Addition: Removes recoil for micros. + recoil_mode = 0 /obj/item/gun/energy/locked/frontier/unload_ammo(var/mob/user) if(recharging) diff --git a/code/modules/projectiles/guns/energy/special.dm b/code/modules/projectiles/guns/energy/special.dm index 5f5a2169fc..ba97e975b9 100644 --- a/code/modules/projectiles/guns/energy/special.dm +++ b/code/modules/projectiles/guns/energy/special.dm @@ -54,7 +54,7 @@ battery_lock = 1 var/decl/plantgene/gene = null - recoil_mode = 0 //CHOMP Addition + recoil_mode = 0 var/obj/item/stock_parts/micro_laser/emitter firemodes = list( diff --git a/code/modules/xenobio/items/weapons.dm b/code/modules/xenobio/items/weapons.dm index dd077a47a3..ad260355e4 100644 --- a/code/modules/xenobio/items/weapons.dm +++ b/code/modules/xenobio/items/weapons.dm @@ -52,7 +52,7 @@ description_fluff = "An easy to use weapon designed by NanoTrasen, for NanoTrasen. This weapon is based on the NT Mk30 NL, \ it's core components swaped out for a new design made to subdue lesser slime-based xeno lifeforms at a distance. It is \ ineffective at stunning non-slimy lifeforms such as humanoids." - recoil_mode = 0 //CHOMP Addition + recoil_mode = 0 /obj/item/gun/energy/taser/xeno/robot // Borg version self_recharge = 1 diff --git a/modular_chomp/code/modules/projectiles/precursor/tyr.dm b/modular_chomp/code/modules/projectiles/precursor/tyr.dm index 27929f2535..a6866a2907 100644 --- a/modular_chomp/code/modules/projectiles/precursor/tyr.dm +++ b/modular_chomp/code/modules/projectiles/precursor/tyr.dm @@ -209,4 +209,4 @@ /obj/item/projectile/energy/spikeenergy_ball/slow speed = 15 - range = 20 \ No newline at end of file + range = 20