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: Fix nil access of tile type and map block #849

Merged
merged 1 commit into from
Oct 3, 2023
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
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Template for new versions:
## New Features

## Fixes
- `suspendmanager`: fix errors when constructing near the map edge

## Misc Improvements

Expand Down
10 changes: 9 additions & 1 deletion suspendmanager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,20 @@ 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
local tileblock = dfhack.maps.getTileBlock(pos)
return tileblock and tileblock.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
-- no tiletype, likely out of bound
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.
Expand Down Expand Up @@ -425,6 +432,7 @@ local function tileHasSupportFloor(pos)
local attrs = df.tiletype.attrs[tt]
if TILETYPE_SHAPE_FLOOR_SUPPORT[attrs.shape] then return true end
end
return false
end

local function tileHasSupportBuilding(pos)
Expand Down