Skip to content

Commit c799c3f

Browse files
authored
Merge pull request #46 from LoireLab/0aur88-codex/implement-finish_jobs_without_wheelbarrow-helper
Add multihaul job cleanup helper
2 parents bbead11 + 9410045 commit c799c3f

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

docs/multihaul.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@ Usage
2424
multihaul disable
2525
multihaul status
2626
multihaul config [<options>]
27+
multihaul finish
2728

2829
The script can also be enabled persistently with ``enable multihaul``.
2930

31+
``multihaul finish`` cancels any ``StoreItemInStockpile`` jobs that have lost
32+
their wheelbarrows, freeing attached items.
33+
3034
Options
3135
-------
3236

multihaul.lua

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ local function emptyContainedItems(wheelbarrow)
102102
end
103103
dfhack.items.moveToGround(item, wheelbarrow.pos)
104104
end
105+
finish_jobs_without_wheelbarrow()
105106
end
106107

107108
local function add_nearby_items(job)
@@ -191,6 +192,15 @@ local function clear_job_items(job)
191192
job.items:resize(0)
192193
end
193194

195+
local function finish_jobs_without_wheelbarrow()
196+
for _, job in utils.listpairs(df.global.world.jobs.list) do
197+
if job.job_type == df.job_type.StoreItemInStockpile and
198+
not find_attached_wheelbarrow(job) then
199+
dfhack.job.removeJob(job)
200+
end
201+
end
202+
end
203+
194204
local function on_new_job(job)
195205
if job.job_type ~= df.job_type.StoreItemInStockpile then return end
196206
local wheelbarrow = find_attached_wheelbarrow(job)
@@ -303,6 +313,8 @@ elseif cmd == 'config' then
303313
persist_state()
304314
print(('multihaul config: radius=%d max-items=%d mode=%s autowheelbarrows=%s debug=%s')
305315
:format(state.radius, state.max_items, state.mode, state.autowheelbarrows and 'on' or 'off', state.debug_enabled and 'on' or 'off'))
316+
elseif cmd == 'finish' then
317+
finish_jobs_without_wheelbarrow()
306318
else
307-
qerror('Usage: multihaul [enable|disable|status|config] [--radius N] [--max-items N] [--mode MODE] [--autowheelbarrows on|off] [--debug on|off]')
319+
qerror('Usage: multihaul [enable|disable|status|config|finish] [--radius N] [--max-items N] [--mode MODE] [--autowheelbarrows on|off] [--debug on|off]')
308320
end

0 commit comments

Comments
 (0)