-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #853 from myk002/myk_drain_aquifer
[drain-aquifer] more control over which levels get drained
- Loading branch information
Showing
4 changed files
with
86 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,68 @@ | ||
-- Remove all aquifers from the map | ||
--[====[ | ||
local argparse = require('argparse') | ||
|
||
drain-aquifer | ||
============= | ||
Remove all 'aquifer' tags from the map blocks. Irreversible. | ||
]====] | ||
local zmin = 0 | ||
local zmax = df.global.world.map.z_count - 1 | ||
|
||
local function drain() | ||
local layers = {} --as:bool[] | ||
local layer_count = 0 | ||
local tile_count = 0 | ||
|
||
for k, block in ipairs(df.global.world.map.map_blocks) do | ||
if block.flags.has_aquifer then | ||
block.flags.has_aquifer = false | ||
block.flags.check_aquifer = false | ||
|
||
for x, row in ipairs(block.designation) do | ||
for y, tile in ipairs(row) do | ||
if tile.water_table then | ||
tile.water_table = false | ||
tile_count = tile_count + 1 | ||
end | ||
for _, block in ipairs(df.global.world.map.map_blocks) do | ||
if not block.flags.has_aquifer then goto continue end | ||
if block.map_pos.z < zmin or block.map_pos.z > zmax then goto continue end | ||
|
||
block.flags.has_aquifer = false | ||
block.flags.check_aquifer = false | ||
|
||
for _, row in ipairs(block.designation) do | ||
for _, tile in ipairs(row) do | ||
if tile.water_table then | ||
tile.water_table = false | ||
tile_count = tile_count + 1 | ||
end | ||
end | ||
end | ||
|
||
if not layers[block.map_pos.z] then | ||
layers[block.map_pos.z] = true | ||
layer_count = layer_count + 1 | ||
end | ||
if not layers[block.map_pos.z] then | ||
layers[block.map_pos.z] = true | ||
layer_count = layer_count + 1 | ||
end | ||
::continue:: | ||
end | ||
|
||
print("Cleared "..tile_count.." aquifer tile"..((tile_count ~= 1) and "s" or "").. | ||
" in "..layer_count.." layer"..((layer_count ~= 1) and "s" or "")..".") | ||
print(('Cleared %d aquifer tile%s in %d layer%s.'):format( | ||
tile_count, (tile_count ~= 1) and 's' or '', layer_count, (layer_count ~= 1) and 's' or '')) | ||
end | ||
|
||
local help = false | ||
local top = 0 | ||
|
||
local positionals = argparse.processArgsGetopt({...}, { | ||
{'h', 'help', handler=function() help = true end}, | ||
{'t', 'top', hasArg=true, handler=function(optarg) top = argparse.nonnegativeInt(optarg, 'top') end}, | ||
{'d', 'zdown', handler=function() zmax = df.global.window_z end}, | ||
{'u', 'zup', handler=function() zmin = df.global.window_z end}, | ||
{'z', 'cur-zlevel', handler=function() zmax, zmin = df.global.window_z, df.global.window_z end}, | ||
}) | ||
|
||
if help or positionals[1] == 'help' then | ||
print(dfhack.script_help()) | ||
return | ||
end | ||
|
||
if top > 0 then | ||
zmax = -1 | ||
for _, block in ipairs(df.global.world.map.map_blocks) do | ||
if block.flags.has_aquifer and zmax < block.map_pos.z then | ||
zmax = block.map_pos.z | ||
end | ||
end | ||
zmax = zmax - top | ||
if zmax < zmin then | ||
print('No aquifer levels need draining') | ||
return | ||
end | ||
end | ||
|
||
drain(...) | ||
drain() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters