Skip to content

Commit f764269

Browse files
authored
Merge pull request #998 from Hiranus/drain
Added aquifer filtering
2 parents 88617bb + f45ebae commit f764269

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

docs/drain-aquifer.rst

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ Examples
2424
Remove all aquifers on the map except for the top 2 levels of aquifer.
2525
``drain-aquifer -d``
2626
Remove all aquifers on the current z-level and below.
27+
``drain-aquifer -f light``
28+
Remove all light aquifers on the map, leaving any heavy aquifers untouched.
29+
2730

2831
Options
2932
-------
@@ -39,3 +42,5 @@ Options
3942
Remove all aquifers on the current z-level and above.
4043
``-z``, ``--cur-zlevel``
4144
Remove all aquifers on the current z-level.
45+
``-f``, ``--filter [light/heavy]``
46+
Remove all light or heavy aquifers.

drain-aquifer.lua

+28-7
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,52 @@ local argparse = require('argparse')
22

33
local zmin = 0
44
local zmax = df.global.world.map.z_count - 1
5+
local aqtype = null
56

67
local function drain()
78
local layers = {} --as:bool[]
89
local layer_count = 0
910
local tile_count = 0
11+
local aqTypeToDrain = 3
12+
if aqtype == "light" then
13+
aqTypeToDrain = 1
14+
elseif aqtype == "heavy" then
15+
aqTypeToDrain = 2
16+
elseif aqtype ~= nil then
17+
qerror("Invalid aquifer type "..aqtype)
18+
end
1019

1120
for _, block in ipairs(df.global.world.map.map_blocks) do
21+
local aquiferInBlock = false
22+
1223
if not block.flags.has_aquifer then goto continue end
1324
if block.map_pos.z < zmin or block.map_pos.z > zmax then goto continue end
14-
15-
block.flags.has_aquifer = false
16-
block.flags.check_aquifer = false
17-
18-
for _, row in ipairs(block.designation) do
19-
for _, tile in ipairs(row) do
20-
if tile.water_table then
25+
local oldTileCount = tile_count
26+
for i, row in ipairs(block.designation) do
27+
for j, tile in ipairs(row) do
28+
if (aqTypeToDrain == 3 or
29+
(block.occupancy[i][j].heavy_aquifer and aqTypeToDrain == 2) or
30+
(not block.occupancy[i][j].heavy_aquifer and aqTypeToDrain == 1)) and
31+
tile.water_table then
2132
tile.water_table = false
2233
tile_count = tile_count + 1
2334
end
35+
if tile.water_table then
36+
aquiferInBlock = true
37+
end
2438
end
2539
end
2640

2741
if not layers[block.map_pos.z] then
2842
layers[block.map_pos.z] = true
2943
layer_count = layer_count + 1
3044
end
45+
46+
if aquiferInBlock == false then
47+
block.flags.has_aquifer = false
48+
block.flags.check_aquifer = false
49+
end
50+
3151
::continue::
3252
end
3353

@@ -44,6 +64,7 @@ local positionals = argparse.processArgsGetopt({...}, {
4464
{'d', 'zdown', handler=function() zmax = df.global.window_z end},
4565
{'u', 'zup', handler=function() zmin = df.global.window_z end},
4666
{'z', 'cur-zlevel', handler=function() zmax, zmin = df.global.window_z, df.global.window_z end},
67+
{'f', 'filter', hasArg=true, handler=function(fil) aqtype = string.lower(fil) end},
4768
})
4869

4970
if help or positionals[1] == 'help' then

0 commit comments

Comments
 (0)