-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathapc_power_proc.dm
119 lines (105 loc) · 4.29 KB
/
apc_power_proc.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/obj/machinery/power/apc/get_cell()
return cell
/obj/machinery/power/apc/connect_to_network()
//Override because the APC does not directly connect to the network; it goes through a terminal.
//The terminal is what the power computer looks for anyway.
if(terminal)
terminal.connect_to_network()
/obj/machinery/power/apc/proc/make_terminal()
// create a terminal object at the same position as original turf loc
// wires will attach to this
terminal = new(loc)
terminal.setDir(dir)
terminal.master = src
/obj/machinery/power/apc/proc/update()
if(operating && !shorted && !failure_timer)
area.power_light = (lighting > APC_CHANNEL_AUTO_OFF)
area.power_equip = (equipment > APC_CHANNEL_AUTO_OFF)
area.power_environ = (environ > APC_CHANNEL_AUTO_OFF)
playsound(src.loc, 'sound/machines/terminal_on.ogg', 50, FALSE)
else
area.power_light = FALSE
area.power_equip = FALSE
area.power_environ = FALSE
playsound(src.loc, 'sound/machines/terminal_off.ogg', 50, FALSE)
area.power_change()
/obj/machinery/power/apc/proc/toggle_breaker(mob/user)
if(!is_operational || failure_timer)
return
operating = !operating
add_fingerprint(user)
log_game("[key_name(user)] turned [operating ? "on" : "off"] the [src] in [AREACOORD(src)]")
update()
update_appearance()
/obj/machinery/power/apc/surplus()
if(terminal)
return terminal.surplus()
return 0
/obj/machinery/power/apc/add_load(amount)
if(terminal?.powernet)
terminal.add_load(amount)
/obj/machinery/power/apc/avail(amount)
if(terminal)
return terminal.avail(amount)
return 0
/**
* Returns the new status value for an APC channel.
*
* // val 0=off, 1=off(auto) 2=on 3=on(auto)
* // on 0=off, 1=on, 2=autooff
* TODO: Make this use bitflags instead. It should take at most three lines, but it's out of scope for now.
*
* Arguments:
* - val: The current status of the power channel.
* - [APC_CHANNEL_OFF]: The APCs channel has been manually set to off. This channel will not automatically change.
* - [APC_CHANNEL_AUTO_OFF]: The APCs channel is running on automatic and is currently off. Can be automatically set to [APC_CHANNEL_AUTO_ON].
* - [APC_CHANNEL_ON]: The APCs channel has been manually set to on. This will be automatically changed only if the APC runs completely out of power or is disabled.
* - [APC_CHANNEL_AUTO_ON]: The APCs channel is running on automatic and is currently on. Can be automatically set to [APC_CHANNEL_AUTO_OFF].
* - on: An enum dictating how to change the channel's status.
* - [AUTOSET_FORCE_OFF]: The APC forces the channel to turn off. This includes manually set channels.
* - [AUTOSET_ON]: The APC allows automatic channels to turn back on.
* - [AUTOSET_OFF]: The APC turns automatic channels off.
*/
/obj/machinery/power/apc/proc/autoset(val, on)
switch(on)
if(AUTOSET_FORCE_OFF)
if(val == APC_CHANNEL_ON) // if on, return off
return APC_CHANNEL_OFF
else if(val == APC_CHANNEL_AUTO_ON) // if auto-on, return auto-off
return APC_CHANNEL_AUTO_OFF
if(AUTOSET_ON)
if(val == APC_CHANNEL_AUTO_OFF) // if auto-off, return auto-on
return APC_CHANNEL_AUTO_ON
if(AUTOSET_OFF)
if(val == APC_CHANNEL_AUTO_ON) // if auto-on, return auto-off
return APC_CHANNEL_AUTO_OFF
return val
/**
* Used by external forces to set the APCs channel status's.
*
* Arguments:
* - val: The desired value of the subsystem:
* - 1: Manually sets the APCs channel to be [APC_CHANNEL_OFF].
* - 2: Manually sets the APCs channel to be [APC_CHANNEL_AUTO_ON]. If the APC doesn't have any power this defaults to [APC_CHANNEL_OFF] instead.
* - 3: Sets the APCs channel to be [APC_CHANNEL_AUTO_ON]. If the APC doesn't have enough power this defaults to [APC_CHANNEL_AUTO_OFF] instead.
*/
/obj/machinery/power/apc/proc/setsubsystem(val)
if(cell && cell.charge > 0)
return (val == 1) ? APC_CHANNEL_OFF : val
if(val == 3)
return APC_CHANNEL_AUTO_OFF
return APC_CHANNEL_OFF
/obj/machinery/power/apc/disconnect_terminal()
if(terminal)
terminal.master = null
terminal = null
/obj/machinery/power/apc/proc/energy_fail(duration)
for(var/obj/machinery/failing_machine in area.contents)
if(failing_machine.critical_machine)
return
for(var/mob/living/silicon/ai as anything in GLOB.ai_list)
if(get_area(ai) == area)
return
failure_timer = max(failure_timer, round(duration))
update()
queue_icon_update()