function buildingIsHive(building)
if not string.find(tostring(building),"hivest") then return false else return true end
end
function itemIsHive(item)
for k,v in ipairs(item.subtype.tool_use) do
if v==12 then return true end
end
return false
end
function buildingHasProductButNoBees(building)
local buildingHasProduct = false
local buildingHasNoBees = true
for k,v in ipairs(building.contained_items) do
if string.find(v.item,"verminst") then return false end
if string.find(v.item,"toolst") and not itemIsHive(v.item) then buildingHasProduct = true end
end
if buildingHasProduct then return true else return false end --already checked if bees; if bees, then false anyway.
end
function getShortestHiveProductTime()
local shortestHiveProductTime = 2^128 --get a larger number than that for your time, eh?
for _,creature in ipairs(df.global.world.raws.creatures.all) do
for k,length in ipairs(creature.hive_product_1) do
shortestHiveProductTime=(length<shortestHiveProductTime) and length or shortestHiveProductTime --neat but incomprehensible lua trick
end
end
return shortestHiveProductTime
end
function checkForBuggyHives()
for k,building in ipairs(df.global.world.buildings.all) do
if buildingIsHive(building) and buildingHasProductButNoBees(building) then
for _,v in building.contained_items do
local item = v.item
if string.find(v.item,"toolst") and itemIsHive(v.item) then item.flags.in_building=false end
end
end
end
end
function fixHiveCrashRepeater()
checkForBuggyHives()
dfhack.timeout(shortestHiveProductTime-1,'ticks',fixHiveCrashRepeater) --if someone makes a hive that goes every 1 tick i would be so mad
end
dfhack.onStateChange.fixHiveCrash = function(code) --Many thanks to Warmist for pointing this out to me!
shortestHiveProductTime=getShortestHiveProductTime()
if code==SC_WORLD_LOADED then
dfhack.timeout(1,'ticks',fixHiveCrashRepeater)
end
end
dfhack.onStateChange.fixHiveCrash()
Here's your fix, I think.