Skip to content

Commit

Permalink
Merge pull request #942 from myk002/myk_instruments
Browse files Browse the repository at this point in the history
[fix/stuck-instruments] handle incorrectly set in_job flag
  • Loading branch information
myk002 authored Jan 14, 2024
2 parents e3346a3 + ef1a68e commit 45779a2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 12 additions & 1 deletion fix/stuck-instruments.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down

0 comments on commit 45779a2

Please sign in to comment.