forked from tgstation/tgstation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipe_filter.dm
243 lines (214 loc) · 8.32 KB
/
pipe_filter.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
// *** pipefilter
/obj/machinery/pipefilter/New()
..()
p_dir = (NORTH|SOUTH|EAST|WEST) ^ turn(dir, 180)
src.gas = new /datum/gas_mixture/()
src.ngas = new /datum/gas_mixture/()
src.f_gas = new /datum/gas_mixture/()
src.f_ngas = new /datum/gas_mixture/()
gasflowlist += src
/obj/machinery/pipefilter/buildnodes()
var/turf/T = src.loc
n1dir = turn(dir, 90)
n2dir = turn(dir,-90)
node1 = get_machine( level, T , n1dir ) // the main flow dir
node2 = get_machine( level, T , n2dir )
node3 = get_machine( level, T, dir ) // the ejector port
if(node1) vnode1 = node1.getline()
if(node2) vnode2 = node2.getline()
if(node3) vnode3 = node3.getline()
/obj/machinery/pipefilter/gas_flow()
gas.copy_from(ngas)
f_gas.copy_from(f_ngas)
/obj/machinery/pipefilter/process()
/* var/delta_gt
if(vnode1)
delta_gt = FLOWFRAC * ( vnode1.get_gas_val(src) - gas.total_moles() / capmult)
calc_delta( src, gas, ngas, vnode1, delta_gt)
else
leak_to_turf(1)
if(vnode2)
delta_gt = FLOWFRAC * ( vnode2.get_gas_val(src) - gas.total_moles() / capmult)
calc_delta( src, gas, ngas, vnode2, delta_gt)
else
leak_to_turf(2)
if(vnode3)
delta_gt = FLOWFRAC * ( vnode3.get_gas_val(src) - f_gas.total_moles() / capmult)
calc_delta( src, f_gas, f_ngas, vnode3, delta_gt)
else
leak_to_turf(3)
// transfer gas from ngas->f_ngas according to extraction rate, but only if we have power
if(! (stat & NOPOWER) )
use_power(min(src.f_per, 100),ENVIRON)
var/datum/gas_mixture/ndelta = src.get_extract()
ngas.sub_delta(ndelta)
f_ngas.add_delta(ndelta)
AutoUpdateAI(src)
src.updateUsrDialog()*/ //TODO: FIX
/obj/machinery/pipefilter/get_gas_val(from)
return ((from == vnode3) ? f_gas.total_moles() : gas.total_moles())/capmult
/obj/machinery/pipefilter/get_gas(from)
return (from == vnode3) ? f_gas : gas
/obj/machinery/pipefilter/proc/leak_to_turf(var/port)
var/turf/T
switch(port)
if(1)
T = get_step(src, n1dir)
if(2)
T = get_step(src, n2dir)
if(3)
T = get_step(src, dir)
if(T.density)
T = src.loc
if(T.density)
return
flow_to_turf(f_gas, f_ngas, T)
return
if(T.density)
T = src.loc
if(T.density)
return
flow_to_turf(gas, ngas, T)
/obj/machinery/pipefilter/proc/get_extract()
/*
var/datum/gas_mixture/ndelta = new()
if (src.f_mask & GAS_O2)
ndelta.oxygen = min(src.f_per, src.ngas.oxygen)
if (src.f_mask & GAS_N2)
ndelta.n2 = min(src.f_per, src.ngas.n2)
if (src.f_mask & GAS_PL)
ndelta.plasma = min(src.f_per, src.ngas.plasma)
if (src.f_mask & GAS_CO2)
ndelta.co2 = min(src.f_per, src.ngas.co2)
if (src.f_mask & GAS_N2O)
ndelta.sl_gas = min(src.f_per, src.ngas.sl_gas)
return ndelta
*/ //TODO: FIX
/obj/machinery/pipefilter/attackby(obj/item/weapon/W, mob/user as mob)
if(istype(W, /obj/item/weapon/detective_scanner))
return ..()
if(istype(W, /obj/item/weapon/screwdriver))
if(bypassed)
user.show_message(text("\red Remove the foreign wires first!"), 1)
return
src.add_fingerprint(user)
user.show_message(text("\red Now []securing the access system panel...", (src.locked) ? "un" : "re"), 1)
sleep(30)
locked =! locked
user.show_message(text("\red Done!"),1)
src.updateicon()
return
if(istype(W, /obj/item/weapon/cable_coil) && !bypassed)
if(src.locked)
user.show_message(text("\red You must remove the panel first!"),1)
return
var/obj/item/weapon/cable_coil/C = W
if(C.use(4))
user.show_message(text("\red You unravel some cable.."),1)
else
user.show_message(text("\red Not enough cable! <I>(Requires four pieces)</I>"),1)
src.add_fingerprint(user)
user.show_message(text("\red Now bypassing the access system... <I>(This may take a while)</I>"), 1)
sleep(100)
bypassed = 1
src.updateicon()
return
if(istype(W, /obj/item/weapon/wirecutters) && bypassed)
src.add_fingerprint(user)
user.show_message(text("\red Now removing the bypass wires... <I>(This may take a while)</I>"), 1)
sleep(50)
bypassed = 0
src.updateicon()
return
if(istype(W, /obj/item/weapon/card/emag) && (!emagged))
emagged++
src.add_fingerprint(user)
for(var/mob/O in viewers(user, null))
O.show_message(text("\red [] has shorted out the [] with an electromagnetic card!", user, src), 1)
src.overlays += image('icons/obj/pipes2.dmi', "filter-spark")
sleep(6)
src.updateicon()
return src.attack_hand(user)
return src.attack_hand(user)
// pipefilter interact/topic
/obj/machinery/pipefilter/attack_paw(mob/user as mob)
return src.attack_hand(user)
/obj/machinery/pipefilter/attack_ai(mob/user as mob)
return src.attack_hand(user)
/obj/machinery/pipefilter/attack_hand(mob/user as mob)
/* if(stat & NOPOWER)
user << browse(null, "window=pipefilter")
user.machine = null
return
var/list/gases = list("O2", "N2", "Plasma", "CO2", "N2O")
user.machine = src
var/dat = "Filter Release Rate:<BR>\n<A href='?src=\ref[src];fp=-[num2text(src.maxrate, 9)]'>M</A> <A href='?src=\ref[src];fp=-100000'>-</A> <A href='?src=\ref[src];fp=-10000'>-</A> <A href='?src=\ref[src];fp=-1000'>-</A> <A href='?src=\ref[src];fp=-100'>-</A> <A href='?src=\ref[src];fp=-1'>-</A> [src.f_per] <A href='?src=\ref[src];fp=1'>+</A> <A href='?src=\ref[src];fp=100'>+</A> <A href='?src=\ref[src];fp=1000'>+</A> <A href='?src=\ref[src];fp=10000'>+</A> <A href='?src=\ref[src];fp=100000'>+</A> <A href='?src=\ref[src];fp=[num2text(src.maxrate, 9)]'>M</A><BR>\n"
for (var/i = 1; i <= gases.len; i++)
dat += "[gases[i]]: <A HREF='?src=\ref[src];tg=[1 << (i - 1)]'>[(src.f_mask & 1 << (i - 1)) ? "Releasing" : "Passing"]</A><BR>\n"
if(gas.total_moles())
var/totalgas = gas.total_moles()
var/pressure = round(totalgas / gas.maximum * 100)
var/nitrogen = gas.n2 / totalgas * 100
var/oxygen = gas.oxygen / totalgas * 100
var/plasma = gas.plasma / totalgas * 100
var/co2 = gas.co2 / totalgas * 100
var/no2 = gas.sl_gas / totalgas * 100
dat += "<BR>Gas Levels: <BR>\nPressure: [pressure]%<BR>\nNitrogen: [nitrogen]%<BR>\nOxygen: [oxygen]%<BR>\nPlasma: [plasma]%<BR>\nCO2: [co2]%<BR>\nN2O: [no2]%<BR>\n"
else
dat += "<BR>Gas Levels: <BR>\nPressure: 0%<BR>\nNitrogen: 0%<BR>\nOxygen: 0%<BR>\nPlasma: 0%<BR>\nCO2: 0%<BR>\nN2O: 0%<BR>\n"
dat += "<BR>\n<A href='?src=\ref[src];close=1'>Close</A><BR>\n"
user << browse(dat, "window=pipefilter;size=300x365")*/ //TODO: FIX
//onclose(user, "pipefilter")
/obj/machinery/pipefilter/Topic(href, href_list)
..()
if(usr.restrained() || usr.lying)
return
if ((((get_dist(src, usr) <= 1 || usr.telekinesis == 1) || istype(usr, /mob/living/silicon/ai)) && istype(src.loc, /turf)))
usr.machine = src
if (href_list["close"])
usr << browse(null, "window=pipefilter;")
usr.machine = null
return
if (src.allowed(usr) || src.emagged || src.bypassed)
if (href_list["fp"])
src.f_per = min(max(round(src.f_per + text2num(href_list["fp"])), 0), src.maxrate)
else if (href_list["tg"])
// toggle gas
src.f_mask ^= text2num(href_list["tg"])
src.updateicon()
else
usr.see("\red Access Denied ([src.name] operation restricted to authorized atmospheric technicians.)")
AutoUpdateAI(src)
src.updateUsrDialog()
src.add_fingerprint(usr)
else
usr << browse(null, "window=pipefilter")
usr.machine = null
return
/obj/machinery/pipefilter/power_change()
if(powered(ENVIRON))
stat &= ~NOPOWER
else
stat |= NOPOWER
spawn(rand(1,15)) //so all the filters don't come on at once
updateicon()
/obj/machinery/pipefilter/proc/updateicon()
src.overlays.Cut()
if(stat & NOPOWER)
icon_state = "filter-off"
else
icon_state = "filter"
if(emagged) //only show if powered because presumeably its the interface that has been fried
src.overlays += image('icons/obj/pipes2.dmi', "filter-emag")
if (src.f_mask & (GAS_N2O|GAS_PL))
src.overlays += image('icons/obj/pipes2.dmi', "filter-tox")
if (src.f_mask & GAS_O2)
src.overlays += image('icons/obj/pipes2.dmi', "filter-o2")
if (src.f_mask & GAS_N2)
src.overlays += image('icons/obj/pipes2.dmi', "filter-n2")
if (src.f_mask & GAS_CO2)
src.overlays += image('icons/obj/pipes2.dmi', "filter-co2")
if(!locked)
src.overlays += image('icons/obj/pipes2.dmi', "filter-open")
if(bypassed) //should only be bypassed if unlocked
src.overlays += image('icons/obj/pipes2.dmi', "filter-bypass")