v50 Steam/Premium information for editors
  • v50 information can now be added to pages in the main namespace. v0.47 information can still be found in the DF2014 namespace. See here for more details on the new versioning policy.
  • Use this page to report any issues related to the migration.
This notice may be cached—the current version can be found here.

User:Fleeting Frames/pathchain

From Dwarf Fortress Wiki
Jump to navigation Jump to search

Save as pathchain.lua into /hack/scripts/fix folder.

Works by iterating over built chains and looking at attached units, then resetting their idle area if out of bounds.

--Fixes all chained units that want to idle elsewhere.

local chainfixes = 0

function checkPathing(unit, unitChain)
	if unitChain.z ~= unit.idle_area.z or math.abs(unitChain.x1-unit.idle_area.x)>1 or math.abs(unitChain.y1-unit.idle_area.y)>1 then
		unit.idle_area.x, unit.idle_area.y, unit.idle_area.z = unit.pos.x, unit.pos.y, unit.pos.z
		chainfixes = chainfixes + 1
		print("Fixed unit " .. unit.id .. " attempting to idle outside chained area.")
	end
end

for i, chain in pairs (df.global.world.buildings.other.CHAIN) do
	if chain.assigned and chain.assigned == chain.chained then
		checkPathing(chain.chained, chain)
	end
end

if chainfixes ~= 0 then print("Fixed " .. chainfixes .. " chained units idling.") end