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

suspendmanager: walkable() now correctly identifies all walkable squares and broke out a new function to explicitly exclude cases where that tile is a tree branch #841

Merged
merged 2 commits into from
Sep 28, 2023
Merged
Changes from 1 commit
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
26 changes: 10 additions & 16 deletions suspendmanager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -308,25 +308,19 @@ end
--- Check if the tile can be walked on
---@param pos coord
local function walkable(pos)
return dfhack.maps.getTileBlock(pos).walkable[pos.x % 16][pos.y % 16] > 0
end

--- Check if the tile is suitable tile to stand on for construction (walkable & not a tree branch)
---@param pos coord
local function isSuitableAccess(pos)
local tt = dfhack.maps.getTileType(pos)
if not tt then
return false
end
local attrs = df.tiletype.attrs[tt]

if attrs.shape == df.tiletype_shape.BRANCH or attrs.shape == df.tiletype_shape.TRUNK_BRANCH then
-- Branches can be walked on, but most of the time we can assume that it's not a suitable access.
return false
end

local shape_attrs = df.tiletype_shape.attrs[attrs.shape]

if not shape_attrs.walkable then
return false
end

local building = dfhack.buildings.findAtTile(pos)
return not building or not building.flags.exists or not isImpassable(building)
return walkable(pos)
end

--- List neighbour coordinates of a position
Expand Down Expand Up @@ -452,7 +446,7 @@ local function constructionIsUnsupported(job)

-- if no neighbour is walkable it can't be constructed now anyways,
-- this early return helps reduce "spam"
-- if not hasWalkableNeighbour(pos) then return false end -- commented out pending `walkable()` fix
if not hasWalkableNeighbour(pos) then return false end

-- find out what type of construction
local constr_type = building:getSubtype()
Expand Down Expand Up @@ -516,7 +510,7 @@ local function riskBlocking(job)
local pos = {x=building.centerx,y=building.centery,z=building.z}

-- The construction is on a non walkable tile, it can't get worst
if not walkable(pos) then return false end
if not isSuitableAccess(pos) then return false end

--- Get self risk of being blocked
local risk = riskOfStuckConstructionAt(pos)
Expand Down Expand Up @@ -544,7 +538,7 @@ function SuspendManager:suspendDeadend(start_job)
---@type building?
local exit = nil
for _,neighbourPos in pairs(neighbours(pos)) do
if not walkable(neighbourPos) then
if not isSuitableAccess(neighbourPos) then
-- non walkable neighbour, not an exit
goto continue
end
Expand Down