diff --git a/code/__DEFINES/dcs/signals/signals_object.dm b/code/__DEFINES/dcs/signals/signals_object.dm index fee0ca52781..a5ab7349fda 100644 --- a/code/__DEFINES/dcs/signals/signals_object.dm +++ b/code/__DEFINES/dcs/signals/signals_object.dm @@ -50,6 +50,8 @@ // /obj/machinery/computer/teleporter /// from /obj/machinery/computer/teleporter/proc/set_target(target, old_target) #define COMSIG_TELEPORTER_NEW_TARGET "teleporter_new_target" +/// from /obj/item/beacon/proc/turn_off() +#define COMSIG_BEACON_DISABLED "beacon_disabled" // /obj/machinery/power/supermatter_crystal /// from /obj/machinery/power/supermatter_crystal/process_atmos(); when the SM sounds an audible alarm diff --git a/code/game/machinery/computer/teleporter.dm b/code/game/machinery/computer/teleporter.dm index 7177da8f4ee..dd8a051cc8e 100644 --- a/code/game/machinery/computer/teleporter.dm +++ b/code/game/machinery/computer/teleporter.dm @@ -28,6 +28,14 @@ power_station = null return ..() +/obj/machinery/computer/teleporter/proc/check_for_disabled_beacon(datum/target) + if (!target) + return + if (target.weak_reference != target_ref) + return + turn_off() + set_teleport_target(null) + /obj/machinery/computer/teleporter/proc/link_power_station() if(power_station) return @@ -65,6 +73,11 @@ return data +/obj/machinery/computer/teleporter/proc/turn_off() + power_station.engaged = FALSE + power_station.teleporter_hub.update_appearance() + power_station.teleporter_hub.calibrated = FALSE + /obj/machinery/computer/teleporter/ui_act(action, params) . = ..() if(.) @@ -79,15 +92,11 @@ switch(action) if("regimeset") - power_station.engaged = FALSE - power_station.teleporter_hub.update_appearance() - power_station.teleporter_hub.calibrated = FALSE + turn_off() reset_regime() . = TRUE if("settarget") - power_station.engaged = FALSE - power_station.teleporter_hub.update_appearance() - power_station.teleporter_hub.calibrated = FALSE + turn_off() set_target(usr) . = TRUE if("calibrate") @@ -105,11 +114,18 @@ return TRUE /obj/machinery/computer/teleporter/proc/set_teleport_target(new_target) + var/datum/old_target var/datum/weakref/new_target_ref = WEAKREF(new_target) if (target_ref == new_target_ref) return + if (target_ref) + old_target = target_ref.resolve() SEND_SIGNAL(src, COMSIG_TELEPORTER_NEW_TARGET, new_target) target_ref = new_target_ref + if (istype(old_target, /obj/item/beacon)) + UnregisterSignal(old_target, COMSIG_BEACON_DISABLED) + if (istype(new_target, /obj/item/beacon)) + RegisterSignal(new_target, COMSIG_BEACON_DISABLED, PROC_REF(check_for_disabled_beacon)) /obj/machinery/computer/teleporter/proc/finish_calibration() calibrating = FALSE diff --git a/code/game/objects/items/devices/beacon.dm b/code/game/objects/items/devices/beacon.dm index 00517f78915..e2936c0f538 100644 --- a/code/game/objects/items/devices/beacon.dm +++ b/code/game/objects/items/devices/beacon.dm @@ -20,14 +20,18 @@ GLOB.teleportbeacons -= src return ..() +/obj/item/beacon/proc/turn_off() + icon_state = "beacon-off" + GLOB.teleportbeacons -= src + SEND_SIGNAL(src, COMSIG_BEACON_DISABLED) + /obj/item/beacon/attack_self(mob/user) enabled = !enabled if (enabled) icon_state = "beacon" GLOB.teleportbeacons += src else - icon_state = "beacon-off" - GLOB.teleportbeacons -= src + turn_off() to_chat(user, span_notice("You [enabled ? "enable" : "disable"] the beacon.")) return diff --git a/code/modules/unit_tests/teleporters.dm b/code/modules/unit_tests/teleporters.dm index 2cb047304fb..e1af0a71a35 100644 --- a/code/modules/unit_tests/teleporters.dm +++ b/code/modules/unit_tests/teleporters.dm @@ -1,10 +1,18 @@ -/datum/unit_test/auto_teleporter_linking/Run() +/datum/unit_test/teleporter/Run() // Put down the teleporter machinery var/obj/machinery/teleport/hub/hub = allocate(/obj/machinery/teleport/hub) var/obj/machinery/teleport/station/station = allocate(/obj/machinery/teleport/station, locate(run_loc_floor_bottom_left.x + 1, run_loc_floor_bottom_left.y, run_loc_floor_bottom_left.z)) var/obj/machinery/computer/teleporter/computer = allocate(/obj/machinery/computer/teleporter, locate(run_loc_floor_bottom_left.x + 2, run_loc_floor_bottom_left.y, run_loc_floor_bottom_left.z)) + var/obj/item/beacon/beacon = allocate(/obj/item/beacon) TEST_ASSERT_EQUAL(hub.power_station, station, "Hub didn't link to the station") TEST_ASSERT_EQUAL(station.teleporter_console, computer, "Station didn't link to the teleporter console") TEST_ASSERT_EQUAL(station.teleporter_hub, hub, "Station didn't link to the hub") TEST_ASSERT_EQUAL(computer.power_station, station, "Teleporter console didn't link to the hub") + + computer.set_teleport_target(beacon) + TEST_ASSERT_EQUAL(computer.target_ref, beacon.weak_reference, "Teleporter didn't target beacon correctly") + + computer.set_teleport_target(beacon) + beacon.turn_off() + TEST_ASSERT_NULL(computer.target_ref, "Teleporter beacon isn't properly turned off.")