Skip to content

Commit

Permalink
Merge pull request #862 from BranislavSetlak/corrupt_job_fix
Browse files Browse the repository at this point in the history
Corrupt job fix
  • Loading branch information
myk002 authored Oct 14, 2023
2 parents 7f2c3e5 + 12961d1 commit ad8fa00
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
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

0 comments on commit ad8fa00

Please sign in to comment.