-
Notifications
You must be signed in to change notification settings - Fork 200
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 #1294 from myk002/myk_buckets
`fix/dry-buckets`: prompt DF to recheck aid requests when we empty a bucket
- Loading branch information
Showing
3 changed files
with
32 additions
and
18 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,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 |