Files
OpenSS13/main-src/Code/Machinery/light_switch.dm
T
hobnob13 033520c334 Continued code reorganization of /obj/machinery/
Added pipelaying system, /obj/item/weapon/pipe.
Added burning icon for labcoat
Fixed a minor airsystem bug for /obj/moves
Engine ejection now carries over firelevel of turfs
Fixed bug with aux engine not working if started too quickly.
Updated autolathe to make pipe fittings
Lowered maximum circulator rates to give a better range of working values.
Fixed firealarm triggering when unpowered.
Made a temporary fix to runtime errors when blob attacks pipes (until full pipe damage system implemented).
2008-04-14 20:36:45 +00:00

95 lines
2.2 KiB
Plaintext

/*
* Light_switch - Controls the lighting of an area
* Can have multiple switches per area, they will interact correctly
* Set the "otherarea" var to control the lighting of a remote area (non-loc)
*/
obj/machinery/light_switch
desc = "A light switch"
name = null
icon = 'power.dmi'
icon_state = "light1"
anchored = 1.0
var
on = 1 // true if currently switched on
area/area = null // holds the area object that this switch controls
otherarea = null // By default, the switch controls the area it is located in.
// By setting this string, the switch will control the area
// matching the path "/area/(otherarea)"
// this allows remote light switches located outside the area controlled (e.g. brig)
// Create a new switch
New()
..()
spawn(5) // wait for world to completely load
src.area = src.loc.loc // by default, switch contains the area it is in
if(otherarea) // setting this var to control a different area
src.area = locate(text2path("/area/[otherarea]"))
if(!name)
name = "light switch ([area.name])"
src.on = src.area.lightswitch // default on/off state is set by the area vars
updateicon()
// Update the icon state to on, off, or unpowered
proc/updateicon()
if(stat & NOPOWER)
icon_state = "light-p"
else
if(on)
icon_state = "light1"
else
icon_state = "light0"
// Examine verb
examine()
set src in oview(1)
if(usr && !usr.stat)
usr << "A light switch. It is [on? "on" : "off"]."
// Monkey interact same as human
attack_paw(mob/user)
src.attack_hand(user)
// Interact, switch the switch
attack_hand(mob/user)
on = !on
area.lightswitch = on
updateicon()
// Update all other light switches in this area to same state
for(var/obj/machinery/light_switch/L in area)
L.on = on
L.updateicon()
area.updateicon() // update the area icon_state to set the darkness overlay
// When area power status of the lighting channel changes, update the switch status
power_change()
if(!otherarea)
if(powered(LIGHT))
stat &= ~NOPOWER
else
stat |= NOPOWER
updateicon()