Skip to content

Commit

Permalink
Use pathability groups (thanks @myk002) to detect stranded citizens
Browse files Browse the repository at this point in the history
  • Loading branch information
azrazalea committed Sep 11, 2023
1 parent 2b16f8d commit f7b7b0b
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions warn-stranded.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
-- Detects and alerts when a citizen is stranded
-- by Azrazalea

-- Taken from warn-starving
local function getSexString(sex)
local sym = df.pronoun_type.attrs[sex].symbol
if not sym then
return ""
end
return "("..sym..")"
end

function doCheck()
local grouped = {}
local citizens = dfhack.units.getCitizens()

-- Pathability group calculation is from gui/pathable
for _, unit in pairs(citizens) do
local target = unit.pos
local block = dfhack.maps.getTileBlock(target)
local walkGroup = block and block.walkable[target.x % 16][target.y % 16] or 0
local groupTable = grouped[walkGroup]

if groupTable == nil then
grouped[walkGroup] = { unit }
else
table.insert(groupTable, unit)
end
end

local strandedUnits = {}

for _, units in pairs(grouped) do
if #units == 1 then
table.insert(strandedUnits, units[1])
end
end

print("Number of stranded: ")
print(#strandedUnits)
for _, unit in pairs(strandedUnits) do
print('['..dfhack.units.getProfessionName(unit)..'] '..dfhack.TranslateName(dfhack.units.getVisibleName(unit))..' '..getSexString(unit.sex)..' Stress category: '..dfhack.units.getStressCategory(unit))
end
end

doCheck()

0 comments on commit f7b7b0b

Please sign in to comment.