-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #862 from BranislavSetlak/corrupt_job_fix
Corrupt job fix
- Loading branch information
Showing
3 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 cleans up corrupt jobs so they don't cause crashes. It runs automatically on fort load, so you don't have to run it manually. | ||
|
||
Usage | ||
----- | ||
|
||
:: | ||
|
||
fix/corrupt-jobs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
-- Deletes corrupted jobs from affected units | ||
--@module = true | ||
|
||
local GLOBAL_KEY = 'corrupt-jobs' | ||
|
||
function remove_bad_jobs() | ||
local count = 0 | ||
|
||
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 | ||
|
||
if count > 0 then | ||
print(('removed %d corrupted job(s) from affected units'):format(count)) | ||
end | ||
end | ||
|
||
dfhack.onStateChange[GLOBAL_KEY] = function(sc) | ||
if sc == SC_MAP_LOADED then | ||
remove_bad_jobs() | ||
end | ||
end | ||
|
||
if dfhack_flags.module then | ||
return | ||
end |