From 13b0909f54c9ce731f7bd58a3d48bdaa143f2b6c Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Wed, 13 Sep 2023 23:33:00 +0200 Subject: [PATCH] [MIRROR] Turning off teleport beacon actually disables teleporting to it and adds unit tests for teleporter [MDB IGNORE] (#23674) * Turning off teleport beacon actually disables teleporting to it and adds unit tests for teleporter (#78183) ## About The Pull Request Teleport beacon can be turned on and off. Turning off only removes it from the list of selectable locations on the teleporter, you can still teleport to it. In this PR I add weak_ref removal on turning off the beacon (of which I'm not certain if that's a good solution, but seems to work) I use signals to handle turning off the teleportation. ## Why It's Good For The Game You can turn off the beacon to stop someone teleporting to your location and it doesn't mislead players into thinking disabled teleport beacon cannot be teleported to anymore. ## Changelog :cl: fix: You can no longer teleport to disabled beacon if the teleporter was previously locked-on to it. /:cl: * Turning off teleport beacon actually disables teleporting to it and adds unit tests for teleporter --------- Co-authored-by: MrDas <62486730+Das15@users.noreply.github.com> --- code/__DEFINES/dcs/signals/signals_object.dm | 2 ++ code/game/machinery/computer/teleporter.dm | 28 +++++++++++++++----- code/game/objects/items/devices/beacon.dm | 8 ++++-- code/modules/unit_tests/teleporters.dm | 10 ++++++- 4 files changed, 39 insertions(+), 9 deletions(-) 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.")