Skip to content

Commit

Permalink
finished script and added it to control panel
Browse files Browse the repository at this point in the history
  • Loading branch information
Branislav Setlák committed Oct 14, 2023
1 parent b9109af commit 5952f23
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
15 changes: 15 additions & 0 deletions docs/fix/corrupt-jobs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
fix/corrupt-jobs
==================

.. dfhack-tool::
:summary: Removes jobs with an id of -1 from units.
:tags: fort bugfix

This fix ensures that no units have a job with an id of -1 set as their current job.

Usage
-----

::

fix/corrupt-jobs
21 changes: 7 additions & 14 deletions fix/corrupt-jobs.lua
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
-- Deletes corrupted jobs from global job list

local utils = require("utils")
-- Deletes corrupted jobs from affected units

local count = 0

functioning_job_list = {}

for _, job in ipairs(df.global.job_list) do
if job.id != -1 then
functioning_job_list[#functioning_job_list+1] = job
for _, unit in ipairs(df.global.world.units.all) do
if unit.job.current_job and unit.job.current_job.id == -1 then
unit.job.current_job = nil
count = count + 1
end
end

for _, v in ipairs(df.global.world.units.all) do
if v.job.current_job then
if utils.linear_index(functioning_job_list, v.job.current_job) == nil then
v.job.current_job = nil
end
end
if count > 0 then
print(('removed %d corrupted job(s) from affected units'):format(count))
end
3 changes: 3 additions & 0 deletions gui/control-panel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ local REPEATS = {
['empty-wheelbarrows']={
desc='Empties wheelbarrows which have rocks stuck in them.',
command={'--time', '1', '--timeUnits', 'days', '--command', '[', 'fix/empty-wheelbarrows', '-q', ']'}},
['corrupt-jobs']={
desc='Removes corrupt jobs from affected units.',
command={'--time', '1', '--timeUnits', 'days', '--command', '[', 'fix/corrupt-jobs', ']'}},
}
local REPEATS_LIST = {}
for k in pairs(REPEATS) do
Expand Down

0 comments on commit 5952f23

Please sign in to comment.