Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/multihaul.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ Usage
multihaul disable
multihaul status
multihaul config [<options>]
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
-------

Expand Down
14 changes: 13 additions & 1 deletion multihaul.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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