forked from mt-mods/vacuum
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphysics_leakage_air.lua
More file actions
148 lines (125 loc) · 5.06 KB
/
physics_leakage_air.lua
File metadata and controls
148 lines (125 loc) · 5.06 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
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: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_leakage2(height)
-- depressurize through leaky nodes
minetest.register_abm({
label = "air vacuum depressurize",
nodenames = leaky_nodes,
neighbors = {"air", "vacuum:atmos_thick"},
interval = 5,
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
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 = "air"
})
end
end
-- on ground: replace vacuum with atmos_thin
local surrounding_node = minetest.find_node_near(pos, 9, {"vacuum:vacuum"})
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 = "air"
})
end
end
end)
})
-- depressurize through door nodes
minetest.register_abm({
label = "air space vacuum depressurize",
nodenames = "group:door",
neighbors = {"air", "vacuum:atmos_thick"},
interval = 1,
chance = 2,
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
-- 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, {"air"})
local surrounding_atmos = minetest.find_node_near(pos, 1, {"vacuum:atmos_thin"})
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 = "air"
})
elseif surrounding_vac ~= nil and surrounding_vac ~= nil and door == 2 then
minetest.set_node(surrounding_atmos, {
name = "vacuum:atmos_thick"
})
end
end)
})
end