-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathcomponents_base.dm
261 lines (210 loc) · 8.15 KB
/
components_base.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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
// So much of atmospherics.dm was used solely by components, so separating this makes things all a lot cleaner.
// On top of that, now people can add component-speciic procs/vars if they want!
/obj/machinery/atmospherics/components
hide = FALSE
layer = GAS_PUMP_LAYER
///Is the component welded?
var/welded = FALSE
///Should the component should show the pipe underneath it?
var/showpipe = TRUE
///When the component is on a non default layer should we shift everything? Or just the underlay pipe
var/shift_underlay_only = TRUE
///Stores the parent pipeline, used in components
var/list/datum/pipeline/parents
///If this is queued for a rebuild this var signifies whether parents should be updated after it's done
var/update_parents_after_rebuild = FALSE
///Stores the gasmix for each node, used in components
var/list/datum/gas_mixture/airs
///Handles whether the custom reconcilation handling should be used
var/custom_reconcilation = FALSE
var/startingvolume = 200
/obj/machinery/atmospherics/components/New()
parents = new(device_type)
airs = new(device_type)
..()
for(var/i in 1 to device_type)
if(airs[i])
continue
var/datum/gas_mixture/component_mixture = new
component_mixture.set_volume(startingvolume)
airs[i] = component_mixture
/obj/machinery/atmospherics/components/Initialize(mapload)
. = ..()
if(hide)
RegisterSignal(src, COMSIG_OBJ_HIDE, PROC_REF(hide_pipe))
// Iconnery
/**
* Called by update_icon(), used individually by each component to determine the icon state without the pipe in consideration
*/
/obj/machinery/atmospherics/components/proc/update_icon_nopipes()
return
/**
* Called in Initialize(), set the showpipe var to true or false depending on the situation, calls update_icon()
*/
/obj/machinery/atmospherics/components/proc/hide_pipe(datum/source, underfloor_accessibility)
SIGNAL_HANDLER
showpipe = !!underfloor_accessibility
if(showpipe)
REMOVE_TRAIT(src, TRAIT_UNDERFLOOR, REF(src))
else
ADD_TRAIT(src, TRAIT_UNDERFLOOR, REF(src))
update_appearance()
/obj/machinery/atmospherics/components/update_icon(updates=ALL)
. = ..()
update_icon_nopipes()
underlays.Cut()
SET_PLANE_IMPLICIT(src, showpipe ? GAME_PLANE : FLOOR_PLANE)
if(!showpipe)
return
var/connected = 0 //Direction bitset
for(var/i in 1 to device_type) //adds intact pieces
if(nodes[i])
var/obj/machinery/atmospherics/node = nodes[i]
var/image/img = get_pipe_underlay("pipe_intact", get_dir(src, node), node.pipe_color)
underlays += img
connected |= img.dir
for(var/direction in GLOB.cardinals)
if((initialize_directions & direction) && !(connected & direction))
underlays += get_pipe_underlay("pipe_exposed", direction)
if(!shift_underlay_only)
PIPING_LAYER_SHIFT(src, piping_layer)
/obj/machinery/atmospherics/components/proc/get_pipe_underlay(state, dir, color = null)
if(color)
. = get_pipe_image('icons/obj/atmospherics/components/binary_devices.dmi', state, dir, color, piping_layer = shift_underlay_only ? piping_layer : 3)
else
. = get_pipe_image('icons/obj/atmospherics/components/binary_devices.dmi', state, dir, piping_layer = shift_underlay_only ? piping_layer : 3)
// Pipenet stuff; housekeeping
/obj/machinery/atmospherics/components/nullify_node(i)
if(parents[i])
nullify_pipenet(parents[i])
airs[i] = null
return ..()
/obj/machinery/atmospherics/components/on_construction()
..()
update_parents()
/obj/machinery/atmospherics/components/rebuild_pipes()
. = ..()
if(update_parents_after_rebuild)
update_parents()
/obj/machinery/atmospherics/components/get_rebuild_targets()
var/list/to_return = list()
for(var/i in 1 to device_type)
if(parents[i])
continue
parents[i] = new /datum/pipeline()
to_return += parents[i]
return to_return
/**
* Called by nullify_node(), used to remove the pipeline the component is attached to
* Arguments:
* * -reference: the pipeline the component is attached to
*/
/obj/machinery/atmospherics/components/proc/nullify_pipenet(datum/pipeline/reference)
if(!reference)
CRASH("nullify_pipenet(null) called by [type] on [COORD(src)]")
for (var/i in 1 to parents.len)
if (parents[i] == reference)
reference.other_airs -= airs[i] // Disconnects from the pipeline side
parents[i] = null // Disconnects from the machinery side.
reference.other_atmos_machines -= src
if(!length(reference.other_atmos_machines) && !length(reference.members))
if(QDESTROYING(reference))
CRASH("nullify_pipenet() called on qdeleting [reference]")
qdel(reference)
// We should return every air sharing a parent
/obj/machinery/atmospherics/components/return_pipenet_airs(datum/pipeline/reference)
var/list/returned_air = list()
for (var/i in 1 to parents.len)
if (parents[i] == reference)
returned_air += airs[i]
return returned_air
/obj/machinery/atmospherics/components/pipeline_expansion(datum/pipeline/reference)
if(reference)
return list(nodes[parents.Find(reference)])
return ..()
/obj/machinery/atmospherics/components/set_pipenet(datum/pipeline/reference, obj/machinery/atmospherics/A)
parents[nodes.Find(A)] = reference
/obj/machinery/atmospherics/components/return_pipenet(obj/machinery/atmospherics/A = nodes[1]) //returns parents[1] if called without argument
return parents[nodes.Find(A)]
/obj/machinery/atmospherics/components/replace_pipenet(datum/pipeline/Old, datum/pipeline/New)
parents[parents.Find(Old)] = New
/obj/machinery/atmospherics/components/unsafe_pressure_release(mob/user, pressures)
..()
var/turf/T = get_turf(src)
if(T)
//Remove the gas from airs and assume it
var/datum/gas_mixture/environment = T.return_air()
var/lost = null
var/times_lost = 0
for(var/i in 1 to device_type)
var/datum/gas_mixture/air = airs[i]
lost += pressures*environment.return_volume()/(air.return_temperature() * R_IDEAL_GAS_EQUATION)
times_lost++
var/shared_loss = lost/times_lost
for(var/i in 1 to device_type)
var/datum/gas_mixture/air = airs[i]
T.assume_air_moles(air, shared_loss)
/obj/machinery/atmospherics/components/proc/safe_input(title, text, default_set)
var/new_value = input(usr,text,title,default_set) as num
if(usr.canUseTopic(src))
return new_value
return default_set
// Helpers
/**
* Called in most atmos processes and gas handling situations, update the parents pipelines of the devices connected to the source component
* This way gases won't get stuck
*/
/obj/machinery/atmospherics/components/proc/update_parents()
if(!SSair.initialized)
return
if(rebuilding)
update_parents_after_rebuild = TRUE
return
for(var/i in 1 to device_type)
var/datum/pipeline/parent = parents[i]
if(!parent)
WARNING("Component is missing a pipenet! Rebuilding...")
SSair.add_to_rebuild_queue(src)
else
parent.update = TRUE
/obj/machinery/atmospherics/components/return_pipenets()
. = list()
for(var/i in 1 to device_type)
. += return_pipenet(nodes[i])
/obj/machinery/atmospherics/components/proc/return_pipenets_for_reconcilation(datum/pipeline/requester)
return list()
/obj/machinery/atmospherics/components/proc/return_airs_for_reconcilation(datum/pipeline/requester)
return list()
// UI Stuff
/obj/machinery/atmospherics/components/ui_status(mob/user)
if(allowed(user))
return ..()
to_chat(user, span_danger("Access denied."))
return UI_CLOSE
// Tool acts
/obj/machinery/atmospherics/components/proc/disconnect_nodes()
for(var/i in 1 to device_type)
var/obj/machinery/atmospherics/node = nodes[i]
if(node)
if(src in node.nodes) //Only if it's actually connected. On-pipe version would is one-sided.
node.disconnect(src)
nodes[i] = null
if(parents[i])
nullify_pipenet(parents[i])
/obj/machinery/atmospherics/components/proc/connect_nodes()
atmos_init()
for(var/i in 1 to device_type)
var/obj/machinery/atmospherics/node = nodes[i]
if(node)
node.atmos_init()
node.add_member(src)
SSair.add_to_rebuild_queue(src)
/obj/machinery/atmospherics/components/proc/change_nodes_connection(disconnect)
if(disconnect)
disconnect_nodes()
return
connect_nodes()
/obj/machinery/atmospherics/components/return_analyzable_air()
return airs
/obj/machinery/atmospherics/components/update_layer()
layer = initial(layer) + (piping_layer - PIPING_LAYER_DEFAULT) * PIPING_LAYER_LCHANGE + (GLOB.pipe_colors_ordered[pipe_color] * 0.001)