From 0e1cedd35457bfbbbc7eaca4d1e8f78ffd16616b Mon Sep 17 00:00:00 2001 From: Antonio Tosti <5588048+atosti@users.noreply.github.com> Date: Thu, 23 Mar 2023 15:19:53 -0700 Subject: [PATCH] Machines can now be pried open multiple times and maintain their initial densities (#74163) ## About The Pull Request These changes fix how machines are pried open with crowbars. Currently, most machines can be pried open, but many of them have no method for being closed again. This means they can be pried once, and then never again (as their internal logic has them stuck in an "open" state). Additionally, the densities of these machines is also inconsistent, as density is tied to the procs for opening/closing machines (open = non-dense, closed = dense). Thus, these new changes allow desired densities to be passed to `open_machine()` and `close_machine()`, as well as `default_pry_open()`, meaning that atypical machine densities can be maintained (e.g. machines that should remain dense when open, or non-dense when closed). I've also added a `close_after_pry` boolean parameter to the `default_pry_open()` proc, which determines whether to immediately close a machine after opening it. This is useful for machines that don't really have a use case for remaining open, often lacking a sprite to represent this state as well. * Note: Opening and immediately closing machines with this boolean will still drop their contents onto the floor, but will now immediately "close" in their logic, allowing for further prying attempts in the future. It's worth noting that this implements default density values for these procs, which match the existing behavior for machines, so as to (hopefully) not disrupt existing or expected machine behavior. Two caveats to these changes currently exist: 1. On machines that immediately close after prying, the prying action can now be spammed to the chat with repeated clicking. I'm uncertain if this needs some sort of spam protection or if it's fine as is. 2. I've only been able to manually test this code. I'd love to write unit tests for it, as it affects a lot of different machines, but don't know where to begin with DM Unit Testing (or which files would be good examples to reference in the code base). * Note: I did manually test each and every machine that calls `default_pry_open()` and they all seem to be working correctly. (Except for `obj/machinery/plumbing/sender`, but that doesn't seem to need prying, as it has no contents to drop, only reagents.) As always, let me know if any improvements/changes should be made. This closes #26833. ## Why It's Good For The Game These changes allow crowbar prying to correctly occur multiple times on any machine, which is intended behavior. It prevents player confusion that could occur when a machine couldn't be pried open a second time during a shift, even though it had previously been pried before, forcing players to question themselves. (Are they missing something? Did they perform the action a different way last time? Is the machine actually still powered on instead of off? Etc.) These changes also maintain the correct density for machines after prying, preventing scenarios where a machine might behave differently once it had been pried open. (An example of this was being able to walk through a smartfridge after prying it open.) Additionally, players are no longer required to know/use workarounds (such as machine disassembly) to retrieve a powered-off machine's contents. Overall, these changes improve consistency around machines, creating more scenarios where they behave as players would expect. ## Changelog :cl: fix: machines can now be pried open more than once. fix: machines now have the correct density when pried open. /:cl: --------- Co-authored-by: san7890 --- code/game/machinery/_machinery.dm | 15 +++++++++------ code/game/machinery/dna_scanner.dm | 6 +++--- code/game/machinery/fat_sucker.dm | 4 ++-- code/game/machinery/harvester.dm | 2 +- code/game/machinery/hologram.dm | 2 +- code/game/machinery/rechargestation.dm | 8 ++++---- code/game/machinery/recycler.dm | 2 +- code/game/machinery/sleepers.dm | 4 ++-- code/game/machinery/washing_machine.dm | 4 ++-- code/game/objects/items/implants/implantchair.dm | 2 +- .../antagonists/abductor/machinery/experiment.dm | 4 ++-- .../machinery/components/unary_devices/cryo.dm | 8 ++++---- code/modules/food_and_drinks/machinery/gibber.dm | 2 +- .../food_and_drinks/machinery/monkeyrecycler.dm | 2 +- .../food_and_drinks/machinery/processor.dm | 2 +- .../food_and_drinks/machinery/smartfridge.dm | 2 +- code/modules/hydroponics/seed_extractor.dm | 2 +- .../library/skill_learning/skill_station.dm | 4 ++-- .../mapfluff/ruins/spaceruin_code/oldstation.dm | 4 ++-- .../wiremod/shell/brain_computer_interface.dm | 6 +++--- 20 files changed, 44 insertions(+), 41 deletions(-) diff --git a/code/game/machinery/_machinery.dm b/code/game/machinery/_machinery.dm index 7b2c1226650..9779ed8c783 100644 --- a/code/game/machinery/_machinery.dm +++ b/code/game/machinery/_machinery.dm @@ -326,10 +326,11 @@ * Will update the machine icon and any user interfaces currently open. * Arguments: * * drop - Boolean. Whether to drop any stored items in the machine. Does not include components. + * * density - Boolean. Whether to make the object dense when it's open. */ -/obj/machinery/proc/open_machine(drop = TRUE) +/obj/machinery/proc/open_machine(drop = TRUE, density_to_set = FALSE) state_open = TRUE - set_density(FALSE) + set_density(density_to_set) if(drop) dump_inventory_contents() update_appearance() @@ -394,9 +395,9 @@ /obj/machinery/proc/can_be_occupant(atom/movable/occupant_atom) return occupant_typecache ? is_type_in_typecache(occupant_atom, occupant_typecache) : isliving(occupant_atom) -/obj/machinery/proc/close_machine(atom/movable/target) +/obj/machinery/proc/close_machine(atom/movable/target, density_to_set = TRUE) state_open = FALSE - set_density(TRUE) + set_density(density_to_set) if(!target) for(var/atom in loc) if (!(can_be_occupant(atom))) @@ -780,13 +781,15 @@ active_power_usage = initial(active_power_usage) * (1 + parts_energy_rating) update_current_power_usage() -/obj/machinery/proc/default_pry_open(obj/item/crowbar) +/obj/machinery/proc/default_pry_open(obj/item/crowbar, close_after_pry = FALSE, open_density = FALSE, closed_density = TRUE) . = !(state_open || panel_open || is_operational || (flags_1 & NODECONSTRUCT_1)) && crowbar.tool_behaviour == TOOL_CROWBAR if(!.) return crowbar.play_tool_sound(src, 50) visible_message(span_notice("[usr] pries open \the [src]."), span_notice("You pry open \the [src].")) - open_machine() + open_machine(density_to_set = open_density) + if (close_after_pry) //Should it immediately close after prying? (If not, it must be closed elsewhere) + close_machine(density_to_set = closed_density) /obj/machinery/proc/default_deconstruction_crowbar(obj/item/crowbar, ignore_panel = 0, custom_deconstruct = FALSE) . = (panel_open || ignore_panel) && !(flags_1 & NODECONSTRUCT_1) && crowbar.tool_behaviour == TOOL_CROWBAR diff --git a/code/game/machinery/dna_scanner.dm b/code/game/machinery/dna_scanner.dm index 412a5833f4f..40e3861681f 100644 --- a/code/game/machinery/dna_scanner.dm +++ b/code/game/machinery/dna_scanner.dm @@ -91,7 +91,7 @@ return C return null -/obj/machinery/dna_scannernew/close_machine(mob/living/carbon/user) +/obj/machinery/dna_scannernew/close_machine(mob/living/carbon/user, density_to_set = TRUE) if(!state_open) return FALSE @@ -104,7 +104,7 @@ return TRUE -/obj/machinery/dna_scannernew/open_machine() +/obj/machinery/dna_scannernew/open_machine(density_to_set = FALSE) if(state_open) return FALSE @@ -129,7 +129,7 @@ update_appearance()//..since we're updating the icon here, since the scanner can be unpowered when opened/closed return - if(default_pry_open(I)) + if(default_pry_open(I, close_after_pry = FALSE, open_density = FALSE, closed_density = TRUE)) return if(default_deconstruction_crowbar(I)) diff --git a/code/game/machinery/fat_sucker.dm b/code/game/machinery/fat_sucker.dm index a893ba2d654..5c8c99d797f 100644 --- a/code/game/machinery/fat_sucker.dm +++ b/code/game/machinery/fat_sucker.dm @@ -50,7 +50,7 @@ [span_notice("Removing [bite_size] nutritional units per operation.")] [span_notice("Requires [nutrient_to_meat] nutritional units per meat slab.")]"} -/obj/machinery/fat_sucker/close_machine(mob/user) +/obj/machinery/fat_sucker/close_machine(mob/user, density_to_set = TRUE) if(panel_open) to_chat(user, span_warning("You need to close the maintenance hatch first!")) return @@ -65,7 +65,7 @@ addtimer(CALLBACK(src, PROC_REF(start_extracting)), 20, TIMER_OVERRIDE|TIMER_UNIQUE) update_appearance() -/obj/machinery/fat_sucker/open_machine(mob/user) +/obj/machinery/fat_sucker/open_machine(mob/user, density_to_set = FALSE) make_meat() playsound(src, 'sound/machines/click.ogg', 50) if(processing) diff --git a/code/game/machinery/harvester.dm b/code/game/machinery/harvester.dm index 9e0ac14928d..0374920e67e 100644 --- a/code/game/machinery/harvester.dm +++ b/code/game/machinery/harvester.dm @@ -42,7 +42,7 @@ icon_state = base_icon_state return ..() -/obj/machinery/harvester/open_machine(drop = TRUE) +/obj/machinery/harvester/open_machine(drop = TRUE, density_to_set = FALSE) if(panel_open) return . = ..() diff --git a/code/game/machinery/hologram.dm b/code/game/machinery/hologram.dm index 5c915e37516..dbbd40c175e 100644 --- a/code/game/machinery/hologram.dm +++ b/code/game/machinery/hologram.dm @@ -245,7 +245,7 @@ Possible to do for anyone motivated enough: if(default_deconstruction_screwdriver(user, "holopad_open", "holopad0", P)) return - if(default_pry_open(P)) + if(default_pry_open(P, close_after_pry = TRUE, closed_density = FALSE)) return if(default_deconstruction_crowbar(P)) diff --git a/code/game/machinery/rechargestation.dm b/code/game/machinery/rechargestation.dm index 55a7d5bc7c9..b86a2884e35 100644 --- a/code/game/machinery/rechargestation.dm +++ b/code/game/machinery/rechargestation.dm @@ -80,7 +80,7 @@ if(default_deconstruction_screwdriver(user, "borgdecon2", "borgcharger0", P)) return - if(default_pry_open(P)) + if(default_pry_open(P, close_after_pry = FALSE, open_density = FALSE, closed_density = TRUE)) return if(default_deconstruction_crowbar(P)) @@ -93,15 +93,15 @@ /obj/machinery/recharge_station/proc/toggle_open() if(state_open) - close_machine() + close_machine(density_to_set = TRUE) else open_machine() -/obj/machinery/recharge_station/open_machine() +/obj/machinery/recharge_station/open_machine(drop = TRUE, density_to_set = FALSE) . = ..() update_use_power(IDLE_POWER_USE) -/obj/machinery/recharge_station/close_machine() +/obj/machinery/recharge_station/close_machine(density_to_set = TRUE) . = ..() if(occupant) update_use_power(ACTIVE_POWER_USE) //It always tries to charge, even if it can't. diff --git a/code/game/machinery/recycler.dm b/code/game/machinery/recycler.dm index c804296b481..92440c95b65 100644 --- a/code/game/machinery/recycler.dm +++ b/code/game/machinery/recycler.dm @@ -76,7 +76,7 @@ if(default_deconstruction_screwdriver(user, "grinder-oOpen", "grinder-o0", I)) return - if(default_pry_open(I)) + if(default_pry_open(I, close_after_pry = TRUE)) return if(default_deconstruction_crowbar(I)) diff --git a/code/game/machinery/sleepers.dm b/code/game/machinery/sleepers.dm index d2dbe9aad87..044d052a3c7 100644 --- a/code/game/machinery/sleepers.dm +++ b/code/game/machinery/sleepers.dm @@ -94,12 +94,12 @@ if (!state_open) container_resist_act(user) -/obj/machinery/sleeper/open_machine() +/obj/machinery/sleeper/open_machine(density_to_set = FALSE) if(!state_open && !panel_open) flick("[initial(icon_state)]-anim", src) return ..() -/obj/machinery/sleeper/close_machine(mob/user) +/obj/machinery/sleeper/close_machine(mob/user, density_to_set = TRUE) if((isnull(user) || istype(user)) && state_open && !panel_open) flick("[initial(icon_state)]-anim", src) ..() diff --git a/code/game/machinery/washing_machine.dm b/code/game/machinery/washing_machine.dm index 0a675bec085..40a553d5132 100644 --- a/code/game/machinery/washing_machine.dm +++ b/code/game/machinery/washing_machine.dm @@ -416,7 +416,7 @@ GLOBAL_LIST_INIT(dye_registry, list( new /obj/item/stack/sheet/iron(drop_location(), 2) qdel(src) -/obj/machinery/washing_machine/open_machine(drop = 1) - ..() +/obj/machinery/washing_machine/open_machine(drop = TRUE, density_to_set = FALSE) + . = ..() set_density(TRUE) //because machinery/open_machine() sets it to FALSE color_source = null diff --git a/code/game/objects/items/implants/implantchair.dm b/code/game/objects/items/implants/implantchair.dm index 161983e4977..0cca201bea9 100644 --- a/code/game/objects/items/implants/implantchair.dm +++ b/code/game/objects/items/implants/implantchair.dm @@ -153,7 +153,7 @@ close_machine(target) -/obj/machinery/implantchair/close_machine(mob/living/user) +/obj/machinery/implantchair/close_machine(mob/living/user, density_to_set = TRUE) if((isnull(user) || istype(user)) && state_open) ..(user) if(auto_inject && ready && ready_implants > 0) diff --git a/code/modules/antagonists/abductor/machinery/experiment.dm b/code/modules/antagonists/abductor/machinery/experiment.dm index cb64d972c53..69f96789222 100644 --- a/code/modules/antagonists/abductor/machinery/experiment.dm +++ b/code/modules/antagonists/abductor/machinery/experiment.dm @@ -28,11 +28,11 @@ return close_machine(target) -/obj/machinery/abductor/experiment/open_machine() +/obj/machinery/abductor/experiment/open_machine(density_to_set = FALSE) if(!state_open && !panel_open) ..() -/obj/machinery/abductor/experiment/close_machine(mob/target) +/obj/machinery/abductor/experiment/close_machine(mob/target, density_to_set = TRUE) for(var/A in loc) if(isabductor(A)) return diff --git a/code/modules/atmospherics/machinery/components/unary_devices/cryo.dm b/code/modules/atmospherics/machinery/components/unary_devices/cryo.dm index 9f9dd4e908c..3472d7428ac 100644 --- a/code/modules/atmospherics/machinery/components/unary_devices/cryo.dm +++ b/code/modules/atmospherics/machinery/components/unary_devices/cryo.dm @@ -356,16 +356,16 @@ message_cooldown = world.time + 50 to_chat(user, span_warning("[src]'s door won't budge!")) -/obj/machinery/atmospherics/components/unary/cryo_cell/open_machine(drop = FALSE) +/obj/machinery/atmospherics/components/unary/cryo_cell/open_machine(drop = FALSE, density_to_set = FALSE) if(!state_open && !panel_open) set_on(FALSE) for(var/mob/M in contents) //only drop mobs M.forceMove(get_turf(src)) set_occupant(null) flick("pod-open-anim", src) - ..() + return ..() -/obj/machinery/atmospherics/components/unary/cryo_cell/close_machine(mob/living/carbon/user) +/obj/machinery/atmospherics/components/unary/cryo_cell/close_machine(mob/living/carbon/user, density_to_set = TRUE) treating_wounds = FALSE if((isnull(user) || istype(user)) && state_open && !panel_open) flick("pod-close-anim", src) @@ -417,7 +417,7 @@ return TOOL_ACT_TOOLTYPE_SUCCESS /obj/machinery/atmospherics/components/unary/cryo_cell/crowbar_act(mob/living/user, obj/item/tool) - if(on || occupant || state_open) + if(on || state_open) return FALSE if(default_pry_open(tool) || default_deconstruction_crowbar(tool)) return TOOL_ACT_TOOLTYPE_SUCCESS diff --git a/code/modules/food_and_drinks/machinery/gibber.dm b/code/modules/food_and_drinks/machinery/gibber.dm index 0b647e16b16..96c3b8bbb0f 100644 --- a/code/modules/food_and_drinks/machinery/gibber.dm +++ b/code/modules/food_and_drinks/machinery/gibber.dm @@ -117,7 +117,7 @@ if(default_deconstruction_screwdriver(user, "grinder_open", "grinder", P)) return - else if(default_pry_open(P)) + else if(default_pry_open(P, close_after_pry = TRUE)) return else if(default_deconstruction_crowbar(P)) diff --git a/code/modules/food_and_drinks/machinery/monkeyrecycler.dm b/code/modules/food_and_drinks/machinery/monkeyrecycler.dm index 58fe48fb106..fa5418d3030 100644 --- a/code/modules/food_and_drinks/machinery/monkeyrecycler.dm +++ b/code/modules/food_and_drinks/machinery/monkeyrecycler.dm @@ -48,7 +48,7 @@ GLOBAL_LIST_EMPTY(monkey_recyclers) if(default_deconstruction_screwdriver(user, "grinder_open", "grinder", O)) return - if(default_pry_open(O)) + if(default_pry_open(O, close_after_pry = TRUE)) return if(default_deconstruction_crowbar(O)) diff --git a/code/modules/food_and_drinks/machinery/processor.dm b/code/modules/food_and_drinks/machinery/processor.dm index a5761c90fae..b8e5f9dfebe 100644 --- a/code/modules/food_and_drinks/machinery/processor.dm +++ b/code/modules/food_and_drinks/machinery/processor.dm @@ -87,7 +87,7 @@ if(processing) to_chat(user, span_warning("[src] is in the process of processing!")) return TRUE - if(default_deconstruction_screwdriver(user, "processor", "processor1", attacking_item) || default_pry_open(attacking_item) || default_deconstruction_crowbar(attacking_item)) + if(default_deconstruction_screwdriver(user, "processor", "processor1", attacking_item) || default_pry_open(attacking_item, close_after_pry = TRUE) || default_deconstruction_crowbar(attacking_item)) return if(istype(attacking_item, /obj/item/storage/bag/tray)) diff --git a/code/modules/food_and_drinks/machinery/smartfridge.dm b/code/modules/food_and_drinks/machinery/smartfridge.dm index d7bc346ea27..58ad43ec83a 100644 --- a/code/modules/food_and_drinks/machinery/smartfridge.dm +++ b/code/modules/food_and_drinks/machinery/smartfridge.dm @@ -88,7 +88,7 @@ SStgui.update_uis(src) return - if(default_pry_open(O)) + if(default_pry_open(O, close_after_pry = TRUE)) return if(default_deconstruction_crowbar(O)) diff --git a/code/modules/hydroponics/seed_extractor.dm b/code/modules/hydroponics/seed_extractor.dm index 2f1401c9eaf..d9c445cde33 100644 --- a/code/modules/hydroponics/seed_extractor.dm +++ b/code/modules/hydroponics/seed_extractor.dm @@ -100,7 +100,7 @@ if(default_deconstruction_screwdriver(user, "sextractor_open", "sextractor", attacking_item)) return TRUE - if(default_pry_open(attacking_item)) + if(default_pry_open(attacking_item, close_after_pry = TRUE)) return TRUE if(default_deconstruction_crowbar(attacking_item)) diff --git a/code/modules/library/skill_learning/skill_station.dm b/code/modules/library/skill_learning/skill_station.dm index e8c378d7699..9e8fc99031e 100644 --- a/code/modules/library/skill_learning/skill_station.dm +++ b/code/modules/library/skill_learning/skill_station.dm @@ -48,7 +48,7 @@ /obj/machinery/skill_station/relaymove(mob/living/user, direction) open_machine() -/obj/machinery/skill_station/open_machine() +/obj/machinery/skill_station/open_machine(density_to_set = FALSE) . = ..() interrupt_operation() @@ -63,7 +63,7 @@ if(working) interrupt_operation() -/obj/machinery/skill_station/close_machine(atom/movable/target) +/obj/machinery/skill_station/close_machine(atom/movable/target, density_to_set = TRUE) . = ..() if(occupant) ui_interact(occupant) diff --git a/code/modules/mapfluff/ruins/spaceruin_code/oldstation.dm b/code/modules/mapfluff/ruins/spaceruin_code/oldstation.dm index 86154f6be85..bfd8bd6c519 100644 --- a/code/modules/mapfluff/ruins/spaceruin_code/oldstation.dm +++ b/code/modules/mapfluff/ruins/spaceruin_code/oldstation.dm @@ -173,13 +173,13 @@ mod_unit = null open_machine() -/obj/machinery/mod_installer/open_machine() +/obj/machinery/mod_installer/open_machine(density_to_set = FALSE) if(state_open) return FALSE ..() return TRUE -/obj/machinery/mod_installer/close_machine(mob/living/carbon/user) +/obj/machinery/mod_installer/close_machine(mob/living/carbon/user, density_to_set = TRUE) if(!state_open) return FALSE ..() diff --git a/code/modules/wiremod/shell/brain_computer_interface.dm b/code/modules/wiremod/shell/brain_computer_interface.dm index 8623329a6f6..362fbba4bd5 100644 --- a/code/modules/wiremod/shell/brain_computer_interface.dm +++ b/code/modules/wiremod/shell/brain_computer_interface.dm @@ -399,7 +399,7 @@ update_appearance() return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN - if (default_pry_open(weapon)) + if (default_pry_open(weapon, close_after_pry = FALSE, open_density = FALSE, closed_density = TRUE)) return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN if (default_deconstruction_crowbar(weapon)) @@ -452,7 +452,7 @@ say("Occupant has been injected with [bci_to_implant].") bci_to_implant.Insert(carbon_occupant) -/obj/machinery/bci_implanter/open_machine() +/obj/machinery/bci_implanter/open_machine(drop = TRUE, density_to_set = FALSE) if(state_open) return FALSE @@ -460,7 +460,7 @@ return TRUE -/obj/machinery/bci_implanter/close_machine(mob/living/carbon/user) +/obj/machinery/bci_implanter/close_machine(mob/living/carbon/user, density_to_set = TRUE) if(!state_open) return FALSE