-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathpressure_valve.dm
171 lines (140 loc) · 5.37 KB
/
pressure_valve.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/obj/machinery/atmospherics/components/binary/pressure_valve
icon_state = "pvalve_map-3"
name = "pressure valve"
desc = "An activatable one-way valve that lets gas pass through if the pressure on the input side is higher than the set pressure."
can_unwrench = TRUE
shift_underlay_only = FALSE
///Amount of pressure needed before the valve for it to open
var/target_pressure = ONE_ATMOSPHERE
///Frequency for radio signaling
var/frequency = 0
///ID for radio signaling
var/id = null
///Connection to the radio processing
var/datum/radio_frequency/radio_connection
///Check if the gas is moving from one pipenet to the other
var/is_gas_flowing = FALSE
construction_type = /obj/item/pipe/directional
pipe_state = "pvalve"
quick_toggle = TRUE
/obj/machinery/atmospherics/components/binary/pressure_valve/AltClick(mob/user)
if(can_interact(user))
target_pressure = MAX_OUTPUT_PRESSURE
investigate_log("was set to [target_pressure] kPa by [key_name(user)]", INVESTIGATE_ATMOS)
balloon_alert(user, "pressure output set to [target_pressure] kPa")
update_appearance(UPDATE_ICON)
return ..()
/obj/machinery/atmospherics/components/binary/pressure_valve/Destroy()
SSradio.remove_object(src,frequency)
if(radio_connection)
radio_connection = null
return ..()
/obj/machinery/atmospherics/components/binary/pressure_valve/update_icon_nopipes()
if(on && is_operational() && is_gas_flowing)
icon_state = "pvalve_flow-[set_overlay_offset(piping_layer)]"
else if(on && is_operational() && !is_gas_flowing)
icon_state = "pvalve_on-[set_overlay_offset(piping_layer)]"
else
icon_state = "pvalve_off-[set_overlay_offset(piping_layer)]"
/obj/machinery/atmospherics/components/binary/pressure_valve/process_atmos()
if(!on || !is_operational())
return
var/datum/gas_mixture/air1 = airs[1]
var/datum/gas_mixture/air2 = airs[2]
if(air1.return_pressure() > target_pressure)
if(air1.release_gas_to(air2, air1.return_pressure()))
update_parents()
is_gas_flowing = TRUE
else
is_gas_flowing = FALSE //unable to release gas (valve mechanism underpressurized, or etc)
else
is_gas_flowing = FALSE //simply not enough pressure to activate
update_icon_nopipes()
/obj/machinery/atmospherics/components/binary/pressure_valve/proc/set_frequency(new_frequency)
SSradio.remove_object(src, frequency)
frequency = new_frequency
if(frequency)
radio_connection = SSradio.add_object(src, frequency, filter = RADIO_ATMOSIA)
/obj/machinery/atmospherics/components/binary/pressure_valve/proc/broadcast_status()
if(!radio_connection)
return
var/datum/signal/signal = new(list(
"tag" = id,
"device" = "AGP",
"power" = on,
"target_output" = target_pressure,
"sigtype" = "status"
))
radio_connection.post_signal(src, signal, filter = RADIO_ATMOSIA)
/obj/machinery/atmospherics/components/binary/pressure_valve/ui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "AtmosPump", name)
ui.open()
/obj/machinery/atmospherics/components/binary/pressure_valve/ui_data()
var/data = list()
data["on"] = on
data["pressure"] = round(target_pressure)
data["max_pressure"] = round(ONE_ATMOSPHERE*100)
return data
/obj/machinery/atmospherics/components/binary/pressure_valve/ui_act(action, params)
if(..())
return
switch(action)
if("power")
on = !on
investigate_log("was turned [on ? "on" : "off"] by [key_name(usr)]", INVESTIGATE_ATMOS)
. = TRUE
if("pressure")
var/pressure = params["pressure"]
if(pressure == "max")
pressure = ONE_ATMOSPHERE*100
. = TRUE
else if(text2num(pressure) != null)
pressure = text2num(pressure)
. = TRUE
if(.)
target_pressure = clamp(pressure, 0, ONE_ATMOSPHERE*100)
investigate_log("was set to [target_pressure] kPa by [key_name(usr)]", INVESTIGATE_ATMOS)
update_appearance(UPDATE_ICON)
/obj/machinery/atmospherics/components/binary/pressure_valve/atmos_init()
. = ..()
if(frequency)
set_frequency(frequency)
/obj/machinery/atmospherics/components/binary/pressure_valve/receive_signal(datum/signal/signal)
if(!signal.data["tag"] || (signal.data["tag"] != id) || (signal.data["sigtype"]!="command"))
return
var/old_on = on //for logging
if("power" in signal.data)
on = text2num(signal.data["power"])
if("power_toggle" in signal.data)
on = !on
if("set_output_pressure" in signal.data)
target_pressure = clamp(text2num(signal.data["set_output_pressure"]),0,ONE_ATMOSPHERE*100)
if(on != old_on)
investigate_log("was turned [on ? "on" : "off"] by a remote signal", INVESTIGATE_ATMOS)
if("status" in signal.data)
broadcast_status()
return
broadcast_status()
update_appearance(UPDATE_ICON)
/obj/machinery/atmospherics/components/binary/pressure_valve/can_unwrench(mob/user)
. = ..()
if(. && on && is_operational())
to_chat(user, span_warning("You cannot unwrench [src], turn it off first!"))
return FALSE
/obj/machinery/atmospherics/components/binary/pressure_valve/layer2
piping_layer = 2
icon_state= "pvalve_map-2"
/obj/machinery/atmospherics/components/binary/pressure_valve/layer4
piping_layer = 4
icon_state= "pvalve_map-4"
/obj/machinery/atmospherics/components/binary/pressure_valve/on
on = TRUE
icon_state = "pvalve_on_map-3"
/obj/machinery/atmospherics/components/binary/pressure_valve/on/layer2
piping_layer = 2
icon_state= "pvalve_on_map-2"
/obj/machinery/atmospherics/components/binary/pressure_valve/on/layer4
piping_layer = 4
icon_state= "pvalve_on_map-4"