Skip to content

Commit

Permalink
Merge pull request #849 from plule/suspendmanager-map-edge
Browse files Browse the repository at this point in the history
suspendmanager: Fix nil access of tile type and map block
  • Loading branch information
myk002 authored Oct 3, 2023
2 parents 28bcd6e + 76ba6e9 commit a8a7ec8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
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

0 comments on commit a8a7ec8

Please sign in to comment.