Removing all lightswitches in an area will turn the lights back on (#28497)

* lol

* yeah

* lewc review

* bam
This commit is contained in:
Contrabang
2025-02-24 17:05:14 +00:00
committed by GitHub
parent cfcc46307e
commit 20337dc94a
3 changed files with 46 additions and 12 deletions
+12
View File
@@ -0,0 +1,12 @@
/**
* Signals for /area and subtypes that have too few related signals to put in separate files.
* Doc format: `/// when the signal is called: (signal arguments)`.
* All signals send the source datum of the signal as the first argument
*/
// /area
/// From obj/machinery/light_switch/Destroy(): ()
#define COMSIG_AREA_LIGHTSWITCH_DELETING "area_lightswitch_deleting"
/// Stop all area lightswitches from turning back on.
#define COMSIG_AREA_LIGHTSWITCH_CANCEL (1<<0)
+33 -12
View File
@@ -26,6 +26,23 @@
dir = WEST
update_icon(UPDATE_ICON_STATE|UPDATE_OVERLAYS)
var/area/A = get_area(src)
// Yes, we're listening to the area to update its signal.
RegisterSignal(A, COMSIG_ATOM_UPDATED_ICON, PROC_REF(signal_lightswitch_icon_update))
RegisterSignal(A, COMSIG_AREA_LIGHTSWITCH_DELETING, PROC_REF(lightswitch_cancel_autoswitch))
/obj/machinery/light_switch/Destroy()
var/area/A = get_area(src)
UnregisterSignal(A, COMSIG_AREA_LIGHTSWITCH_DELETING) // make sure src isnt included, if we're the last light switch to go the lights will turn back on
if(SEND_SIGNAL(A, COMSIG_AREA_LIGHTSWITCH_DELETING) & COMSIG_AREA_LIGHTSWITCH_CANCEL)
return ..()
// Toggle the lights on if there are no other light switches
set_area_lightswitch(TRUE)
return ..()
/obj/machinery/light_switch/proc/signal_lightswitch_icon_update()
update_icon(UPDATE_ICON_STATE|UPDATE_OVERLAYS)
/obj/machinery/light_switch/update_icon_state()
if(stat & NOPOWER)
@@ -54,18 +71,9 @@
return attack_hand(user)
/obj/machinery/light_switch/attack_hand(mob/user)
playsound(src, 'sound/machines/lightswitch.ogg', 10, TRUE)
update_icon(UPDATE_ICON_STATE|UPDATE_OVERLAYS)
var/area/A = get_area(src)
A.lightswitch = !A.lightswitch
A.update_icon(UPDATE_ICON_STATE)
for(var/obj/machinery/light_switch/L in A)
L.update_icon(UPDATE_ICON_STATE|UPDATE_OVERLAYS)
machine_powernet.power_change()
set_area_lightswitch(!A.lightswitch)
playsound(src, 'sound/machines/lightswitch.ogg', 10, TRUE)
/obj/machinery/light_switch/power_change()
if(!..())
@@ -92,9 +100,22 @@
return
user.visible_message("<span class='notice'>[user] starts unwrenching [src] from the wall...</span>", "<span class='notice'>You are unwrenching [src] from the wall...</span>", "<span class='warning'>You hear ratcheting.</span>")
if(!I.use_tool(src, user, 30, volume = I.tool_volume))
if(!I.use_tool(src, user, 3 SECONDS, volume = I.tool_volume))
return
WRENCH_UNANCHOR_WALL_MESSAGE
new/obj/item/mounted/frame/light_switch(get_turf(src))
qdel(src)
/obj/machinery/light_switch/proc/set_area_lightswitch(new_state)
var/area/A = get_area(src)
A.lightswitch = new_state
// Sends an area signal to all lightswitches in our area to update their icons and overlays
A.update_icon(UPDATE_ICON_STATE)
// Update all the lights in our area
machine_powernet.power_change()
/obj/machinery/light_switch/proc/lightswitch_cancel_autoswitch()
SIGNAL_HANDLER // COMSIG_AREA_LIGHTSWITCH_DELETING
return COMSIG_AREA_LIGHTSWITCH_CANCEL
+1
View File
@@ -152,6 +152,7 @@
#include "code\__DEFINES\ai\ai_defines.dm"
#include "code\__DEFINES\ai\blackboard_defines.dm"
#include "code\__DEFINES\dcs\ai_signals.dm"
#include "code\__DEFINES\dcs\area_signals.dm"
#include "code\__DEFINES\dcs\atom_signals.dm"
#include "code\__DEFINES\dcs\attack_chain_signals.dm"
#include "code\__DEFINES\dcs\basetype_signals.dm"