diff --git a/changelog.txt b/changelog.txt index 4dbea9f8bb..ba1435d045 100644 --- a/changelog.txt +++ b/changelog.txt @@ -34,6 +34,7 @@ Template for new versions: - `gui/unit-syndromes`: show the syndrome names properly in the UI ## Misc Improvements +- `warn-stranded`: don't warn for units that are temporarily on unwalkable tiles (e.g. as they pass under a waterfall) ## Removed diff --git a/warn-stranded.lua b/warn-stranded.lua index 81bdef5de4..24235093f5 100644 --- a/warn-stranded.lua +++ b/warn-stranded.lua @@ -4,7 +4,6 @@ --@module = true local gui = require 'gui' -local utils = require 'utils' local widgets = require 'gui.widgets' local argparse = require 'argparse' local args = {...} @@ -266,7 +265,7 @@ function WarningWindow:onClear() end function WarningWindow:onZoom() - local index, choice = self.subviews.list:getSelected() + local _, choice = self.subviews.list:getSelected() local unit = choice.data['unit'] local target = xyz2pos(dfhack.units.getPosition(unit)) @@ -299,6 +298,11 @@ local function compareGroups(group_one, group_two) return #group_one['units'] < #group_two['units'] end +local function getWalkGroup(pos) + local block = dfhack.maps.getTileBlock(pos) + return block and block.walkable[pos.x % 16][pos.y % 16] +end + local function getStrandedUnits() local groupCount = 0 local grouped = {} @@ -310,9 +314,22 @@ local function getStrandedUnits() -- Pathability group calculation is from gui/pathable for _, unit in ipairs(citizens) do - local target = xyz2pos(dfhack.units.getPosition(unit)) - local block = dfhack.maps.getTileBlock(target) - local walkGroup = block and block.walkable[target.x % 16][target.y % 16] or 0 + local unitPos = xyz2pos(dfhack.units.getPosition(unit)) + local walkGroup = getWalkGroup(unitPos) or 0 + + -- if on an unpathable tile, use the walkGroup of an adjacent tile. this prevents + -- warnings for units that are walking under falling water, which sometimes makes + -- a tile unwalkable while the unit is standing on it + if walkGroup == 0 then + walkGroup = getWalkGroup(xyz2pos(unitPos.x-1, unitPos.y-1, unitPos.z)) + or getWalkGroup(xyz2pos(unitPos.x, unitPos.y-1, unitPos.z)) + or getWalkGroup(xyz2pos(unitPos.x+1, unitPos.y-1, unitPos.z)) + or getWalkGroup(xyz2pos(unitPos.x-1, unitPos.y, unitPos.z)) + or getWalkGroup(xyz2pos(unitPos.x+1, unitPos.y, unitPos.z)) + or getWalkGroup(xyz2pos(unitPos.x-1, unitPos.y+1, unitPos.z)) + or getWalkGroup(xyz2pos(unitPos.x, unitPos.y+1, unitPos.z)) + or getWalkGroup(xyz2pos(unitPos.x+1, unitPos.y+1, unitPos.z)) + end if unitIgnored(unit) then table.insert(ensure_key(ignoredGroup, walkGroup), unit)