Skip to content

Commit

Permalink
Merge pull request #1294 from myk002/myk_buckets
Browse files Browse the repository at this point in the history
`fix/dry-buckets`: prompt DF to recheck aid requests when we empty a bucket
  • Loading branch information
myk002 authored Sep 6, 2024
2 parents 66e169e + 836ad2f commit d762217
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Template for new versions:
- `gui/control-panel`: include option for turning off dumping of old clothes for `tailor`, for players who have magma pit dumps and want to save old clothes from being dumped into the magma
- `position`: report current historical era (e.g., "Age of Myth"), site/adventurer world coords, and mouse map tile coords
- `assign-minecarts`: reassign vehicles to routes where the vehicle has been destroyed (or has otherwise gone missing)
- `fix/dry-buckets`: prompt DF to recheck requests for aid (e.g. "bring water" jobs) when a bucket is unclogged and becomes available for use

## Documentation
- `gui/embark-anywhere`: add information about how the game determines world tile pathability and instructions for bridging two landmasses
Expand Down
4 changes: 4 additions & 0 deletions docs/fix/dry-buckets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ water from them.

This tool also fixes over-full buckets that are blocking well operations.

If enabled in `gui/control-panel` (it is enabled by default), this fix is
periodically run automaticaly, so you should not normally need to run it
manually.

Usage
-----

Expand Down
45 changes: 27 additions & 18 deletions fix/dry-buckets.lua
Original file line number Diff line number Diff line change
@@ -1,35 +1,44 @@
local argparse = require("argparse")

local quiet = false

local emptied = 0
local in_building = 0
local water_type = dfhack.matinfo.find('WATER').type

local quiet = false
argparse.processArgsGetopt({...}, {
{'q', 'quiet', handler=function() quiet = true end},
})

for _,item in ipairs(df.global.world.items.other.IN_PLAY) do
local container = dfhack.items.getContainer(item)
if container
and container:getType() == df.item_type.BUCKET
and not (container.flags.in_job)
and item:getMaterial() == water_type
and item:getType() == df.item_type.LIQUID_MISC
and not (item.flags.in_job)
then
if container.flags.in_building or item.flags.in_building then
in_building = in_building + 1
local emptied = 0
local in_building = 0
for _,item in ipairs(df.global.world.items.other.BUCKET) do
if item.flags.in_job then goto continue end
local emptied_bucket = false
local freed_in_building = false
for _,contained_item in ipairs(dfhack.items.getContainedItems(item)) do
if not contained_item.flags.in_job and
contained_item:getMaterial() == water_type and
contained_item:getType() == df.item_type.LIQUID_MISC
then
if item.flags.in_building or contained_item.flags.in_building then
freed_in_building = true
end
-- ok to remove item while iterating since we're iterating through copy of the vector
dfhack.items.remove(contained_item)
emptied_bucket = true
end
dfhack.items.remove(item)
end
if emptied_bucket then
emptied = emptied + 1
df.global.plotinfo.flags.recheck_aid_requests = true
end
if freed_in_building then
in_building = in_building + 1
end
::continue::
end

if not quiet then
print('Emptied '..emptied..' buckets.')
if emptied > 0 then
print(('Emptied %d buckets.'):format(emptied))
if in_building > 0 then
print(('Unclogged %d wells.'):format(in_building))
end
end

0 comments on commit d762217

Please sign in to comment.