Skip to content
Open
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
2 changes: 2 additions & 0 deletions data/init/onMapLoad.default.init
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
# Please do not edit this file directly. It will be overwritten with new
# defaults when you update DFHack. Instead, add your configuration to
# dfhack-config/init/onMapLoad.init

lua require('quickfix').repair_site_id()
1 change: 1 addition & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Template for new versions:
- `timestream`: deal properly with units who have breathing difficulties
- `stocks`: overlay now resets scroll position when collapsing categories so the item list is no longer left blank and unscrollable
- Fixed persistent site data API (``dfhack.persistent.saveSiteData``/``getSiteData``) failing on newly reclaimed fortresses until the first save
- ``quickfix``: repair ``plotinfo.site_id`` on load when DF leaves it unassigned on reclaimed fortresses

## Misc Improvements
- Added ``Coord2d`` and ``Coord3d`` C++ templates, providing a standard set operations for 2-tuples and 3-tuples of any numeric type
Expand Down
17 changes: 17 additions & 0 deletions library/lua/quickfix.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,21 @@ function set_entity_race_references()
print(('quickfix: fixed %d unset entity race reference(s)'):format(count))
end

-- on reclaimed fortresses DF fails to assign plotinfo.site_id until the
-- first save, breaking anything that needs the site id; fortress_site is
-- set at embark, so restore the invariant from it
-- called from onMapLoad.default.init
function repair_site_id()
local plotinfo = df.global.plotinfo
if plotinfo.site_id ~= -1 then
return
end
local site = plotinfo.main.fortress_site
if not site then
return
end
plotinfo.site_id = site.id
print(('quickfix: repaired unassigned site_id (now %d)'):format(site.id))
end

return _ENV
26 changes: 26 additions & 0 deletions test/modules/quickfix_fortress.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
config.mode = 'fortress'
config.target = 'core'

local quickfix = require('quickfix')

function test.repair_site_id_restores_fortress_site()
local plotinfo = df.global.plotinfo
local orig = plotinfo.site_id
local site = plotinfo.main.fortress_site
expect.ne(nil, site, 'no fortress site on this map')
if not site then return end

return dfhack.with_finalize(function()
plotinfo.site_id = orig
end, function()
plotinfo.site_id = -1
quickfix.repair_site_id()
expect.eq(site.id, plotinfo.site_id)
end)
end

function test.repair_site_id_noop_when_assigned()
local orig = df.global.plotinfo.site_id
quickfix.repair_site_id()
expect.eq(orig, df.global.plotinfo.site_id)
end
Loading