Skip to content

Commit

Permalink
fixed broken suspend script / remove --onlyblocking option (fixes #4717)
Browse files Browse the repository at this point in the history
  • Loading branch information
chdoc committed Jun 17, 2024
1 parent 32bf2af commit 924a7ba
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 38 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Template for new versions:
- `control-panel`: restore non-default values of per-save enabled/disabled settings for repeat-based commands
- `confirm`: fix confirmation prompt for overwriting a hotkey zoom location
- `quickfort`: allow farm plots to be built on muddy stone
- `suspend`: remove broken ``--onlyblocking`` option; restore functionality to suspend all construction jobs

## Misc Improvements
- `gui/launcher`: "space space to toggle pause" behavior is skipped if the game was paused when `gui/launcher` came up to prevent accidental unpausing
Expand Down
26 changes: 4 additions & 22 deletions docs/suspend.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,15 @@ suspend

.. dfhack-tool::
:summary: Suspends building construction jobs.
:tags: fort productivity jobs
:tags: fort jobs

This tool will suspend jobs. It can either suspend all the current jobs, or only
construction jobs that are likely to block other jobs. When building walls, it's
common that wall corners get stuck because dwarves build the two adjacent walls
before the corner. The ``--onlyblocking`` option will only suspend jobs that can
potentially lead to this situation.

See `suspendmanager` in `gui/control-panel` to automatically suspend and
unsuspend jobs.
This tool will suspend jobs all construction jobs. This is mainly useful as an
emergency measure. Consider using `suspendmanager` from `gui/control-panel` to
automatically suspend and unsuspend jobs.

Usage
-----

::

suspend

Options
-------

``-b``, ``--onlyblocking``
Only suspend jobs that are likely to block other jobs.

.. note::

``--onlyblocking`` does not check pathing (which would be very expensive); it only
looks at immediate neighbours. As such, it is possible that this tool will miss
suspending some jobs that prevent access to other farther away jobs, for example
when building a large rectangle of solid walls.
32 changes: 16 additions & 16 deletions suspend.lua
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
-- Suspend jobs

-- It can either suspend all jobs, or just jobs that risk blocking others.
-- Suspend all construction jobs

local utils = require('utils')
local argparse = require('argparse')
local suspendmanager = reqscript('suspendmanager')

local help, onlyblocking = false, false
local help = false
argparse.processArgsGetopt({...}, {
{'h', 'help', handler=function() help = true end},
{'b', 'onlyblocking', handler=function() onlyblocking = true end},
})

---cancel job and remove worker
---@param job df.job
local function suspend(job)
job.flags.suspend = true
job.flags.working = false
dfhack.job.removeWorker(job, 0);
end


if help then
print(dfhack.script_help())
return
end

-- Only initialize suspendmanager if we want to suspend blocking jobs
manager = onlyblocking and suspendmanager.SuspendManager{preventBlocking=true} or nil
if manager then
manager:refresh()
end

suspendmanager.foreach_construction_job(function (job)
if not manager or manager:shouldBeSuspended(job) then
suspendmanager.suspend(job)
for _,job in utils.listpairs(df.global.world.jobs.list) do
if job.job_type == df.job_type.ConstructBuilding then
suspend(job)
end
end)
end

0 comments on commit 924a7ba

Please sign in to comment.