From ef1a68e0c58658657bda7a7cbe1ec8f56e1905fd Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sun, 14 Jan 2024 13:21:49 -0800 Subject: [PATCH] handle incorrectly set in_job flag even when there are no dangling general refs --- changelog.txt | 1 + fix/stuck-instruments.lua | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/changelog.txt b/changelog.txt index 684c5801ec..b5f4246c82 100644 --- a/changelog.txt +++ b/changelog.txt @@ -62,6 +62,7 @@ Template for new versions: - `gui/mass-remove`: can now differentiate planned constructions, stockpiles, and regular buildings - `gui/mass-remove`: can now remove zones - `gui/mass-remove`: can now cancel removal for buildings and constructions +- `fix/stuck-instruments`: now handles instruments that are left in the "in job" state but that don't have any actual jobs associated with them ## Removed diff --git a/fix/stuck-instruments.lua b/fix/stuck-instruments.lua index 0526efb769..f859c5e799 100644 --- a/fix/stuck-instruments.lua +++ b/fix/stuck-instruments.lua @@ -10,7 +10,8 @@ function fixInstruments(opts) if ref:getType() == df.general_ref_type.ACTIVITY_EVENT then local activity = df.activity_entry.find(ref.activity_id) if not activity then - print(('Found stuck instrument: %s'):format(dfhack.items.getDescription(item, 0, true))) + print(dfhack.df2console(('Found stuck instrument: %s'):format( + dfhack.items.getDescription(item, 0, true)))) if not opts.dry_run then --remove dead activity reference item.general_refs[i]:delete() @@ -22,6 +23,16 @@ function fixInstruments(opts) end end end + -- instruments can also end up in the state where they are unreferenced, but + -- still have the in_job flag set + if item.flags.in_job and #item.general_refs == 0 then + print(dfhack.df2console(('Found stuck instrument: %s'):format( + dfhack.items.getDescription(item, 0, true)))) + if not opts.dry_run then + item.flags.in_job = false + end + fixed = fixed + 1 + end end if fixed > 0 or opts.dry_run then