Skip to content

Commit 3e9dd28

Browse files
implement @Bumber64 code
add to module
1 parent 15788a4 commit 3e9dd28

File tree

1 file changed

+29
-20
lines changed

1 file changed

+29
-20
lines changed

clear-smoke.lua

+29-20
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,37 @@
1-
local flows_to_delete = {}
1+
--@module = true
22

3-
function clearSmoke(flows)
4-
local success
5-
for i = #flows - 1, 0, -1 do
6-
local flow = flows[i]
7-
if flow.type == df.flow_type.Smoke then
8-
flows:erase(i)
9-
flows_to_delete[flow] = true
10-
success = true
11-
end
3+
function removeFlow(flow) --have DF remove the flow
4+
if not flow then
5+
return
126
end
13-
return success
14-
end
7+
flow.flags.DEAD = true
158

16-
clearSmoke(df.global.flows)
9+
local block = dfhack.maps.getTileBlock(flow.pos)
10+
if block then
11+
block.flow_pool.flags.active = true
12+
else
13+
df.global.world.orphaned_flow_pool.flags.active = true
14+
end
15+
end
1716

18-
for _,block in pairs(df.global.world.map.map_blocks) do
19-
if clearSmoke(block.flows) then
20-
dfhack.maps.enableBlockUpdates(block, true)
17+
function removeFlows(flow_type) --remove all if flow_type is nil
18+
local count = 0
19+
for _,flow in ipairs(df.global.flows) do
20+
if not flow.flags.DEAD and (flow_type == nil or flow.type == flow_type) then
21+
removeFlow(flow)
22+
count = count + 1
23+
end
2124
end
25+
26+
return count
2227
end
2328

24-
for flow,_ in pairs(flows_to_delete) do
25-
if flow then
26-
flow:delete()
29+
function clearSmoke()
30+
if dfhack.isWorldLoaded() then
31+
print(('%d smoke flows removed.'):format(removeFlows(df.flow_type.Smoke)))
32+
else
33+
qerror('World not loaded!')
2734
end
28-
end
35+
end
36+
37+
clearSmoke()

0 commit comments

Comments
 (0)