diff --git a/code/game/objects/structures/construction_console/construction_actions.dm b/code/game/objects/structures/construction_console/construction_actions.dm index f6cf35195fd..c35e49dd907 100644 --- a/code/game/objects/structures/construction_console/construction_actions.dm +++ b/code/game/objects/structures/construction_console/construction_actions.dm @@ -133,7 +133,7 @@ structure_path = /obj/structure/fans/tiny place_sound = 'sound/machines/click.ogg' -/datum/action/innate/construction/place_structure/turret/after_place(obj/placed_structure, remaining) +/datum/action/innate/construction/place_structure/fan/after_place(obj/placed_structure, remaining) to_chat(owner, span_notice("Tiny fan placed. [remaining] fans remaining.")) /datum/action/innate/construction/place_structure/turret @@ -148,5 +148,6 @@ if(!turret_controller) to_chat(owner, span_notice("Warning: Aux base controller not found. Turrets might not work properly.")) return - turret_controller.turrets += placed_structure + + LAZYADD(turret_controller.turrets, WEAKREF(placed_structure)) to_chat(owner, span_notice("You've constructed an additional turret. [remaining] turrets remaining.")) diff --git a/code/modules/mining/aux_base.dm b/code/modules/mining/aux_base.dm index 1d7ef43a424..fb6279e24a1 100644 --- a/code/modules/mining/aux_base.dm +++ b/code/modules/mining/aux_base.dm @@ -24,7 +24,7 @@ /// If we give warnings before base is launched var/launch_warning = TRUE /// List of connected turrets - var/list/turrets = list() + var/list/datum/weakref/turrets /// List of all possible destinations var/possible_destinations /// ID of the currently selected destination of the attached base @@ -40,6 +40,10 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/machinery/computer/auxiliary_base, 32) . = ..() AddComponent(/datum/component/gps, "NT_AUX") +/obj/machinery/computer/auxiliary_base/Destroy() // Shouldn't be destroyable... but just in case + LAZYCLEARLIST(turrets) + return ..() + /obj/machinery/computer/auxiliary_base/ui_interact(mob/user, datum/tgui/ui) ui = SStgui.try_update_ui(user, src, ui) if(!ui) @@ -58,28 +62,31 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/machinery/computer/auxiliary_base, 32) data["destination"] = destination data["blind_drop"] = blind_drop_ready data["turrets"] = list() - if(LAZYLEN(turrets)) - for(var/turret in turrets) - var/obj/machinery/porta_turret/aux_base/base_turret = turret - var/turret_integrity = max((base_turret.get_integrity() - base_turret.integrity_failure * base_turret.max_integrity) / (base_turret.max_integrity - base_turret.integrity_failure * max_integrity) * 100, 0) - var/turret_status - if(base_turret.machine_stat & BROKEN) - turret_status = "ERROR" - else if(!base_turret.on) - turret_status = "Disabled" - else if(base_turret.raised) - turret_status = "Firing" - else - turret_status = "All Clear" - var/list/turret_data = list( - name = base_turret.name, - integrity = turret_integrity, - status = turret_status, - direction = dir2text(get_dir(src, base_turret)), - distance = get_dist(src, base_turret), - ref = REF(base_turret) - ) - data["turrets"] += list(turret_data) + for(var/datum/weakref/turret_ref as anything in turrets) + var/obj/machinery/porta_turret/aux_base/base_turret = turret_ref.resolve() + if(!istype(base_turret)) // null or invalid in turrets list? axe it + LAZYREMOVE(turrets, turret_ref) + continue + + var/turret_integrity = max((base_turret.get_integrity() - base_turret.integrity_failure * base_turret.max_integrity) / (base_turret.max_integrity - base_turret.integrity_failure * max_integrity) * 100, 0) + var/turret_status + if(base_turret.machine_stat & BROKEN) + turret_status = "ERROR" + else if(!base_turret.on) + turret_status = "Disabled" + else if(base_turret.raised) + turret_status = "Firing" + else + turret_status = "All Clear" + var/list/turret_data = list( + name = base_turret.name, + integrity = turret_integrity, + status = turret_status, + direction = dir2text(get_dir(src, base_turret)), + distance = get_dist(src, base_turret), + ref = REF(base_turret) + ) + data["turrets"] += list(turret_data) if(!M) data["status"] = "Missing" return data @@ -171,13 +178,19 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/machinery/computer/auxiliary_base, 32) destination = target_destination return TRUE if("turrets_power") - for(var/obj/machinery/porta_turret/aux_base/base_turret in turrets) + for(var/datum/weakref/turret_ref as anything in turrets) + var/obj/machinery/porta_turret/aux_base/base_turret = turret_ref.resolve() + if(!istype(base_turret)) // null or invalid in turrets list + LAZYREMOVE(turrets, turret_ref) + continue + base_turret.toggle_on() return TRUE if("single_turret_power") - var/obj/machinery/porta_turret/aux_base/base_turret = locate(params["single_turret_power"]) in turrets - if(!istype(base_turret)) + var/obj/machinery/porta_turret/aux_base/base_turret = locate(params["single_turret_power"]) + if(!istype(base_turret) || !(WEAKREF(base_turret) in turrets)) return + base_turret.toggle_on() return TRUE @@ -237,7 +250,6 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/machinery/computer/auxiliary_base, 32) to_chat(user, span_notice("Landing zone set.")) return ZONE_SET - /obj/item/assault_pod/mining name = "Landing Field Designator" icon_state = "gangtool-purple"