forked from mt-mods/vacuum
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphysics_leakage.lua
More file actions
224 lines (192 loc) · 7.92 KB
/
physics_leakage.lua
File metadata and controls
224 lines (192 loc) · 7.92 KB
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
local has_monitoring = minetest.get_modpath("monitoring")
local has_mesecons_random = minetest.get_modpath("mesecons_random")
local has_technic = minetest.get_modpath("technic")
local metric_space_vacuum_leak_abm
if has_monitoring then
metric_space_vacuum_leak_abm = monitoring.counter("vacuum_abm_leak_count", "number of space vacuum leak abm calls")
end
-- air leaking nodes
local leaky_nodes = {"group:soil", "group:sand", "group:pipe", "group:tube", "group:fence", "group:leaky"}
if has_mesecons_random then
table.insert(leaky_nodes, "mesecons_random:ghoststone_active")
end
if has_technic then
table.insert(leaky_nodes, "technic:lv_cable")
table.insert(leaky_nodes, "technic:mv_cable")
table.insert(leaky_nodes, "technic:hv_cable")
end
function vacuum.register_physics_leakage(height)
-- depressurize through leaky nodes
minetest.register_abm({
label = "space vacuum depressurize",
nodenames = leaky_nodes,
neighbors = {"vacuum:vacuum"},
interval = 2,
chance = 3,
max_y = height.end_height,
min_y = height.start_height,
action = vacuum.throttle(2500, function(pos, node)
if metric_space_vacuum_leak_abm ~= nil then
metric_space_vacuum_leak_abm.inc()
end
if vacuum.is_pos_in_spawn(pos) then
return
end
-- local node = minetest.get_node(pos)
if node.name == "pipeworks:entry_panel_empty" or node.name == "pipeworks:entry_panel_loaded" then
-- air thight pipes
return
end
if node.name == "vacuum:airpump" or node.name == "vacuum:airpump_wait" or node.name ==
"vacuum:airpump_active" then
-- pump is airtight
return
end
-- in space: replace air with vacuum
local surrounding_node = minetest.find_node_near(pos, 1, {"vacuum:atmos_thick", "air"})
if surrounding_node ~= nil then
if vacuum.debug then
-- debug mode, set
minetest.set_node(surrounding_node, {
name = "default:cobble"
})
else
-- normal case
minetest.set_node(surrounding_node, {
name = "vacuum:atmos_thin"
})
--[[minetest.set_node(surrounding_node, {
name = "vacuum:vacuum"
})]] --
end
end
local surrounding_atmos = minetest.find_node_near(pos, 1, {"vacuum:atmos_thin"})
if surrounding_atmos ~= nil then
if vacuum.debug then
-- debug mode, set
minetest.set_node(surrounding_atmos, {
name = "default:cobble"
})
else
-- normal case
-- minetest.set_node(surrounding_node, {name = "vacuum:atmos_thin"})
minetest.set_node(surrounding_atmos, {
name = "vacuum:vacuum"
})
end
end
end)
})
--[[
-- depressurize through leaky nodes
minetest.register_abm({
label = "space vacuum depressurize",
nodenames = "group:soil",
neighbors = {"vacuum:vacuum"},
interval = 3,
chance = 4, -- 3
max_y = height.end_height,
min_y = height.start_height,
action = vacuum.throttle(250, function(pos, node)
if metric_space_vacuum_leak_abm ~= nil then
metric_space_vacuum_leak_abm.inc()
end
if vacuum.is_pos_in_spawn(pos) then
return
end
if not vacuum.is_pos_in_space(pos) then -- or vacuum.near_powered_airpump(pos) then
-- on earth: TODO: replace vacuum with air
return
else
-- local node = minetest.get_node(pos)
if node.name == "pipeworks:entry_panel_empty" or node.name == "pipeworks:entry_panel_loaded" then
-- air thight pipes
return
end
if node.name == "vacuum:airpump" or node.name == "vacuum:airpump_wait" or node.name ==
"vacuum:airpump_active" then
-- pump is airtight
return
end
-- in space: replace air with vacuum
local surrounding_node = minetest.find_node_near(pos, 1, {"vacuum:atmos_thick"})
if surrounding_node ~= nil then
if vacuum.debug then
-- debug mode, set
minetest.set_node(surrounding_node, {
name = "default:cobble"
})
else
-- normal case
-- minetest.set_node(surrounding_node, {name = "vacuum:atmos_thin"})
minetest.set_node(surrounding_node, {
name = "vacuum:vacuum"
})
end
end
local surrounding_atmos = minetest.find_node_near(pos, 1, {"vacuum:atmos_thin"})
if surrounding_atmos ~= nil then
if vacuum.debug then
-- debug mode, set
minetest.set_node(surrounding_atmos, {
name = "default:cobble"
})
else
-- normal case
-- minetest.set_node(surrounding_node, {name = "vacuum:atmos_thin"})
minetest.set_node(surrounding_atmos, {
name = "vacuum:vacuum"
})
end
end
end
end)
})--]]
-- depressurize through door nodes
minetest.register_abm({
label = "space vacuum depressurize",
nodenames = "group:door",
neighbors = {"vacuum:vacuum", "vacuum:atmos_thin"},
interval = 1,
chance = 2,
max_y = height.end_height,
min_y = height.start_height,
action = vacuum.throttle(2500, function(pos, node)
if metric_space_vacuum_leak_abm ~= nil then
metric_space_vacuum_leak_abm.inc()
end
if vacuum.is_pos_in_spawn(pos) then
return
end
-- local node = minetest.get_node(pos)
local door = minetest.get_item_group(node.name, "door")
-- in space: replace air with atmos_thin
local surrounding_vac = minetest.find_node_near(pos, 1, {"vacuum:vacuum"})
local surrounding_atmos = minetest.find_node_near(pos, 1, {"vacuum:atmos_thick", "air"})
if surrounding_vac ~= nil and surrounding_atmos ~= nil then
if vacuum.debug then
-- debug mode, set
minetest.set_node(surrounding_vac, {
name = "default:cobble"
})
else
-- normal case
-- minetest.set_node(surrounding_node, {name = "vacuum:atmos_thin"})
minetest.set_node(surrounding_vac, {
name = "vacuum:atmos_thin"
})
end
end
-- if door is open
if surrounding_vac ~= nil and surrounding_atmos == nil and door == 2 then
minetest.set_node(surrounding_atmos, {
name = "vacuum:vacuum"
})
elseif surrounding_vac ~= nil and surrounding_vac ~= nil and door == 2 then
minetest.set_node(surrounding_atmos, {
name = "vacuum:atmos_thin"
})
end
end)
})
end