mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-10 10:12:45 +00:00
63 lines
1.2 KiB
Plaintext
63 lines
1.2 KiB
Plaintext
// the light switch
|
|
// can have multiple per area
|
|
// can also operate on non-loc area through "otherarea" var
|
|
|
|
/obj/machinery/light_switch/New()
|
|
..()
|
|
spawn(5)
|
|
src.area = src.loc.loc
|
|
|
|
if(otherarea)
|
|
src.area = locate(text2path("/area/[otherarea]"))
|
|
|
|
if(!name)
|
|
name = "light switch ([area.name])"
|
|
|
|
src.on = src.area.lightswitch
|
|
updateicon()
|
|
|
|
|
|
|
|
/obj/machinery/light_switch/proc/updateicon()
|
|
if(stat & NOPOWER)
|
|
icon_state = "light-p"
|
|
else
|
|
if(on)
|
|
icon_state = "light1"
|
|
else
|
|
icon_state = "light0"
|
|
|
|
/obj/machinery/light_switch/examine()
|
|
set src in oview(1)
|
|
if(usr && !usr.stat)
|
|
usr << "A light switch. It is [on? "on" : "off"]."
|
|
|
|
|
|
/obj/machinery/light_switch/attack_paw(mob/user)
|
|
src.attack_hand(user)
|
|
|
|
/obj/machinery/light_switch/attack_hand(mob/user)
|
|
|
|
on = !on
|
|
|
|
for(var/area/A in area.master.related)
|
|
A.lightswitch = on
|
|
A.updateicon()
|
|
|
|
for(var/obj/machinery/light_switch/L in A)
|
|
L.on = on
|
|
L.updateicon()
|
|
|
|
area.master.power_change()
|
|
|
|
/obj/machinery/light_switch/power_change()
|
|
|
|
if(!otherarea)
|
|
if(powered(LIGHT))
|
|
stat &= ~NOPOWER
|
|
else
|
|
stat |= NOPOWER
|
|
|
|
updateicon()
|
|
|