From 9b90d2c9aed5b44b3bb0e32edc15c259c2ac8efb Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Sun, 26 Mar 2023 09:42:35 +0200 Subject: [PATCH] [MIRROR] [NO GBP] Fixes vents & scrubbers getting assigned twice to an area when it's merged with another area via station blueprints. Code clean up. [MDB IGNORE] (#19933) * [NO GBP] Fixes vents & scrubbers getting assigned twice to an area when it's merged with another area via station blueprints. Code clean up. * vents * vents --------- Co-authored-by: SyncIt21 <110812394+SyncIt21@users.noreply.github.com> Co-authored-by: lessthnthree Co-authored-by: lessthanthree <83487515+lessthnthree@users.noreply.github.com> --- .../components/unary_devices/vent_pump.dm | 29 ++++++++++++------- .../components/unary_devices/vent_scrubber.dm | 29 ++++++++++++------- 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/code/modules/atmospherics/machinery/components/unary_devices/vent_pump.dm b/code/modules/atmospherics/machinery/components/unary_devices/vent_pump.dm index 0e542021233..00d46dfcf4f 100644 --- a/code/modules/atmospherics/machinery/components/unary_devices/vent_pump.dm +++ b/code/modules/atmospherics/machinery/components/unary_devices/vent_pump.dm @@ -28,10 +28,13 @@ // ATMOS_INTERNAL_BOUND: Do not pass internal_pressure_bound // NO_BOUND: Do not pass either - ///id of air sensor its connected to + /// id of air sensor its connected to var/chamber_id -/obj/machinery/atmospherics/components/unary/vent_pump/New() + ///area this vent is assigned to + var/area/assigned_area + +/obj/machinery/atmospherics/components/unary/vent_pump/Initialize(mapload) if(!id_tag) id_tag = SSnetworks.assign_random_name() var/static/list/tool_screentips = list( @@ -41,9 +44,6 @@ ) AddElement(/datum/element/contextual_screentip_tools, tool_screentips) . = ..() - -/obj/machinery/atmospherics/components/unary/vent_pump/Initialize(mapload) - . = ..() assign_to_area() /obj/machinery/atmospherics/components/unary/vent_pump/examine(mob/user) @@ -90,20 +90,27 @@ if (old_area == new_area) return - disconnect_from_area() - assign_to_area() + disconnect_from_area(old_area) + assign_to_area(new_area) /obj/machinery/atmospherics/components/unary/vent_pump/on_enter_area(datum/source, area/area_to_register) assign_to_area(area_to_register) . = ..() /obj/machinery/atmospherics/components/unary/vent_pump/proc/assign_to_area(area/target_area = get_area(src)) - if(!isnull(target_area)) - target_area.air_vents += src - update_appearance(UPDATE_NAME) + //this vent is already assigned to an area. Unassign it from here first before reassigning it to an new area + if(isnull(target_area) || !isnull(assigned_area)) + return + assigned_area = target_area + assigned_area.air_vents += src + update_appearance(UPDATE_NAME) /obj/machinery/atmospherics/components/unary/vent_pump/proc/disconnect_from_area(area/target_area = get_area(src)) - target_area?.air_vents -= src + //you cannot unassign from an area we never were assigned to + if(isnull(target_area) || assigned_area != target_area) + return + assigned_area.air_vents -= src + assigned_area = null /obj/machinery/atmospherics/components/unary/vent_pump/on_exit_area(datum/source, area/area_to_unregister) . = ..() diff --git a/code/modules/atmospherics/machinery/components/unary_devices/vent_scrubber.dm b/code/modules/atmospherics/machinery/components/unary_devices/vent_scrubber.dm index 810455fe0f7..f55b03190a7 100644 --- a/code/modules/atmospherics/machinery/components/unary_devices/vent_scrubber.dm +++ b/code/modules/atmospherics/machinery/components/unary_devices/vent_scrubber.dm @@ -26,23 +26,23 @@ ///List of the turfs near the scrubber, used for widenet var/list/turf/adjacent_turfs = list() - //Enables the use of plunger_act for ending the vent clog random event + ///Enables the use of plunger_act for ending the vent clog random event var/clogged = FALSE + ///The area this scrubber is assigned to + var/area/assigned_area COOLDOWN_DECLARE(check_turfs_cooldown) -/obj/machinery/atmospherics/components/unary/vent_scrubber/New() +/obj/machinery/atmospherics/components/unary/vent_scrubber/Initialize(mapload) if(!id_tag) id_tag = SSnetworks.assign_random_name() . = ..() + for(var/to_filter in filter_types) if(istext(to_filter)) filter_types -= to_filter filter_types += gas_id2path(to_filter) -/obj/machinery/atmospherics/components/unary/vent_scrubber/Initialize(mapload) - . = ..() - assign_to_area() AddElement(/datum/element/atmos_sensitive, mapload) @@ -60,20 +60,27 @@ if (old_area == new_area) return - disconnect_from_area() - assign_to_area() + disconnect_from_area(old_area) + assign_to_area(new_area) /obj/machinery/atmospherics/components/unary/vent_scrubber/on_enter_area(datum/source, area/area_to_register) assign_to_area(area_to_register) . = ..() /obj/machinery/atmospherics/components/unary/vent_scrubber/proc/assign_to_area(area/target_area = get_area(src)) - if(!isnull(target_area)) - target_area.air_scrubbers += src - update_appearance(UPDATE_NAME) + //this scrubber is already assigned to an area. Unassign it from here first before reassigning it to an new area + if(isnull(target_area) || !isnull(assigned_area)) + return + assigned_area = target_area + assigned_area.air_scrubbers += src + update_appearance(UPDATE_NAME) /obj/machinery/atmospherics/components/unary/vent_scrubber/proc/disconnect_from_area(area/target_area = get_area(src)) - target_area?.air_scrubbers -= src + //you cannot unassign from an area we never were assigned to + if(isnull(target_area) || assigned_area != target_area) + return + assigned_area.air_scrubbers -= src + assigned_area = null /obj/machinery/atmospherics/components/unary/vent_scrubber/on_exit_area(datum/source, area/area_to_unregister) . = ..()