Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrupt job fix #862

Merged
merged 9 commits into from
Oct 14, 2023
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
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Template for new versions:

## New Tools
- `add-recipe`: (reinstated) add reactions to your civ (e.g. for high boots if your civ didn't start with the ability to make high boots)
- `fix/corrupt-jobs`: prevents crashes by automatically removing corrupted jobs
- `burial`: (reinstated) create tomb zones for unzoned coffins

## New Features
Expand Down
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 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
29 changes: 29 additions & 0 deletions fix/corrupt-jobs.lua
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