This repository has been archived by the owner on Sep 12, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 66
/
lightswitch.dm
72 lines (60 loc) · 1.72 KB
/
lightswitch.dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/// The light switch. Can have multiple per area.
/obj/machinery/light_switch
name = "light switch"
icon = 'icons/obj/power.dmi'
icon_state = "light1"
desc = "Make dark."
power_channel = AREA_USAGE_LIGHT
/// Set this to a string, path, or area instance to control that area
/// instead of the switch's location.
var/area/area = null
FASTDMM_PROP(\
set_instance_vars(\
pixel_x = dir & EAST ? 23 : (dir & WEST ? -23 : INSTANCE_VAR_DEFAULT),\
pixel_y = dir & NORTH ? 23 : (dir & SOUTH ? -23 : INSTANCE_VAR_DEFAULT)\
),\
dir_amount = 8\
)
/obj/machinery/light_switch/Initialize()
. = ..()
if(istext(area))
area = text2path(area)
if(ispath(area))
area = GLOB.areas_by_type[area]
if(!area)
area = get_area(src)
if(!name)
name = "light switch ([area.name])"
update_icon()
/obj/machinery/light_switch/update_icon_state()
SSvis_overlays.remove_vis_overlay(src, managed_vis_overlays)
luminosity = 0
if(machine_stat & NOPOWER)
icon_state = "light-p"
else
luminosity = 1
SSvis_overlays.add_vis_overlay(src, icon, "light-glow", EMISSIVE_LAYER, EMISSIVE_PLANE, dir, alpha)
if(area.lightswitch)
icon_state = "light1"
else
icon_state = "light0"
/obj/machinery/light_switch/examine(mob/user)
. = ..()
. += "It is [area.lightswitch ? "on" : "off"]."
/obj/machinery/light_switch/interact(mob/user)
. = ..()
area.lightswitch = !area.lightswitch
area.update_icon()
for(var/obj/machinery/light_switch/L in area)
L.update_icon()
area.power_change()
/obj/machinery/light_switch/power_change()
SHOULD_CALL_PARENT(0)
if(area == get_area(src))
return ..()
/obj/machinery/light_switch/emp_act(severity)
. = ..()
if (. & EMP_PROTECT_SELF)
return
if(!(machine_stat & (BROKEN|NOPOWER)))
power_change()