From 94100455857c6450ea60a34d81606ab4d32bbd32 Mon Sep 17 00:00:00 2001 From: LOIRELAB <66545056+LoireLab@users.noreply.github.com> Date: Sun, 27 Jul 2025 00:50:08 +0200 Subject: [PATCH] multihaul: clear lost wheelbarrow jobs when emptying --- docs/multihaul.rst | 4 ++++ multihaul.lua | 14 +++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/docs/multihaul.rst b/docs/multihaul.rst index b3d3095f3..1f1475486 100644 --- a/docs/multihaul.rst +++ b/docs/multihaul.rst @@ -24,9 +24,13 @@ Usage multihaul disable multihaul status multihaul config [] + multihaul finish The script can also be enabled persistently with ``enable multihaul``. +``multihaul finish`` cancels any ``StoreItemInStockpile`` jobs that have lost +their wheelbarrows, freeing attached items. + Options ------- diff --git a/multihaul.lua b/multihaul.lua index 019c8c2f7..82c5bec08 100644 --- a/multihaul.lua +++ b/multihaul.lua @@ -102,6 +102,7 @@ local function emptyContainedItems(wheelbarrow) end dfhack.items.moveToGround(item, wheelbarrow.pos) end + finish_jobs_without_wheelbarrow() end local function add_nearby_items(job) @@ -191,6 +192,15 @@ local function clear_job_items(job) job.items:resize(0) end +local function finish_jobs_without_wheelbarrow() + for _, job in utils.listpairs(df.global.world.jobs.list) do + if job.job_type == df.job_type.StoreItemInStockpile and + not find_attached_wheelbarrow(job) then + dfhack.job.removeJob(job) + end + end +end + local function on_new_job(job) if job.job_type ~= df.job_type.StoreItemInStockpile then return end local wheelbarrow = find_attached_wheelbarrow(job) @@ -303,6 +313,8 @@ elseif cmd == 'config' then persist_state() print(('multihaul config: radius=%d max-items=%d mode=%s autowheelbarrows=%s debug=%s') :format(state.radius, state.max_items, state.mode, state.autowheelbarrows and 'on' or 'off', state.debug_enabled and 'on' or 'off')) +elseif cmd == 'finish' then + finish_jobs_without_wheelbarrow() else - qerror('Usage: multihaul [enable|disable|status|config] [--radius N] [--max-items N] [--mode MODE] [--autowheelbarrows on|off] [--debug on|off]') + qerror('Usage: multihaul [enable|disable|status|config|finish] [--radius N] [--max-items N] [--mode MODE] [--autowheelbarrows on|off] [--debug on|off]') end