From 886e91b4eaedf28da3324d5c1c670f809a0d3986 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Fri, 6 Sep 2024 16:11:31 -0700 Subject: [PATCH 1/3] clean up algorithm so it only scans relevant items --- docs/fix/dry-buckets.rst | 4 ++++ fix/dry-buckets.lua | 44 ++++++++++++++++++++++++---------------- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/docs/fix/dry-buckets.rst b/docs/fix/dry-buckets.rst index 311e3e6c2e..9d3a7d4e0b 100644 --- a/docs/fix/dry-buckets.rst +++ b/docs/fix/dry-buckets.rst @@ -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 ----- diff --git a/fix/dry-buckets.lua b/fix/dry-buckets.lua index 27834abb82..db98f0f719 100644 --- a/fix/dry-buckets.lua +++ b/fix/dry-buckets.lua @@ -1,35 +1,43 @@ 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 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 From db96f839ccb95aadb46b6f5b137c2b5f19b36e50 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Fri, 6 Sep 2024 16:14:30 -0700 Subject: [PATCH 2/3] prompt DF to recheck requests for give water jobs --- fix/dry-buckets.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/fix/dry-buckets.lua b/fix/dry-buckets.lua index db98f0f719..71d2c50468 100644 --- a/fix/dry-buckets.lua +++ b/fix/dry-buckets.lua @@ -28,6 +28,7 @@ for _,item in ipairs(df.global.world.items.other.BUCKET) do 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 From 836ad2faf0323509cf47d7915272e27a5d0b78bb Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Fri, 6 Sep 2024 16:19:11 -0700 Subject: [PATCH 3/3] update changelog --- changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.txt b/changelog.txt index 50b06fbbd9..5181b1d3a3 100644 --- a/changelog.txt +++ b/changelog.txt @@ -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