Files
CHOMPStation2/code/game/machinery/lightswitch.dm
Ccomp5950 bb9a66cc3a Effeciency Project: APC / Machinery power usage.
We no longer run auto_use_power() on every machine every tick.
We now have a global list of areas, and areas that have an APC in them (all_areas and active_areas) no more looping through world bullshit.
A bunch of snowflakey as fuck machines won't use_power() in their process, you get two options, active and idle, use them!
This means a lot of machines won't double dip on power as well so power usage for the station has dropped about 20%

Because everything is snowflakey as fuck we're going to have some machines that don't force an update on their power usage.  Fuck them.
We should catch them with the root obj/machine/proc's forcing updates.
2014-03-08 03:42:44 -06:00

79 lines
1.5 KiB
Plaintext

// the light switch
// can have multiple per area
// can also operate on non-loc area through "otherarea" var
/obj/machinery/light_switch
name = "light switch"
desc = "It turns lights on and off. What are you, simple?"
icon = 'icons/obj/power.dmi'
icon_state = "light1"
anchored = 1.0
var/on = 1
var/area/area = null
var/otherarea = null
// luminosity = 1
/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()
/obj/machinery/light_switch/emp_act(severity)
if(stat & (BROKEN|NOPOWER))
..(severity)
return
power_change()
..(severity)