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 " .. .. " attempting to idle outside chained area.")

for i, chain in pairs ( do
	if chain.assigned and chain.assigned == chain.chained then
		checkPathing(chain.chained, chain)

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