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

add automatic fixing of DF beta-specific caravan crash bug #5181

Merged
merged 1 commit into from
Jan 9, 2025
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
2 changes: 2 additions & 0 deletions data/init/onLoad.default.init
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,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/onLoad.init

lua require('quickfix').set_entity_race_references()
30 changes: 30 additions & 0 deletions library/lua/quickfix.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-- short-term urgent bugfixes

local _ENV = mkmodule("quickfix")

local function get_dwarf_race()
for k,v in ipairs(df.global.world.raws.creatures.all) do
-- dwarves are always the first entity race
if v.flags.OCCURS_AS_ENTITY_RACE then return k end
end
end

-- entities can send caravans, and if the race is -1, then DF crashes
-- called from onLoad.default.init
function set_entity_race_references()
local race = get_dwarf_race()
if not race then
return
end

local count = 0
for _,v in ipairs(df.global.world.entities.all) do
if v.race == -1 then
count = count + 1
v.race = race
end
end
print(('quickfix: fixed %d unset entity race reference(s)'):format(count))
end

return _ENV
Loading