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

[warn-stranded] don't warn on units going down open hatches #954

Merged
merged 1 commit into from
Jan 21, 2024
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
2 changes: 1 addition & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Template for new versions:
## Fixes
- `source`: water and magma sources now persist with fort across saves and loads
- `gui/design`: fix incorrect dimensions being shown when placing stockpiles, but a start coordinate hasn't been selected yet
- `warn-stranded`: Automatically ignore citizens who are gathering plants or digging to avoid issues with gathering fruit via stepladders and weird issues with digging
- `warn-stranded`: don't warn for citizens who are only transiently stranded, like those on stepladders gathering plants or digging themselves out of a hole
- `warn-stranded`: Update onZoom to use df's centering functionality
- `ban-cooking`: fix banning creature alcohols resulting in error
- `confirm`: properly detect clicks on the remove zone button even when the unit selection screen is also open (e.g. the vanilla assign animal to pasture panel)
Expand Down
23 changes: 19 additions & 4 deletions warn-stranded.lua
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,19 @@ local function getWalkGroup(pos)
return walkGroup ~= 0 and walkGroup or nil
end

local function hasAllowlistedJob(unit)
local job = unit.job.current_job
if not job then return false end
return job.job_type == df.job_type.GatherPlants or
df.job_type_class[df.job_type.attrs[job.job_type].type] == 'Digging'
end

local function hasAllowlistedPos(pos)
local bld = dfhack.buildings.findAtTile(pos)
return bld and bld:getType() == df.building_type.Hatch and
not bld.door_flags.closed
end

local function getStrandedUnits()
local groupCount = 0
local grouped = {}
Expand Down Expand Up @@ -320,10 +333,12 @@ local function getStrandedUnits()
or 0
end

-- Ignore units who are gathering plants or digging to avoid errors with stepladders and weird digging things
if unitIgnored(unit) or (unit.job.current_job and
(unit.job.current_job.job_type == df.job_type.GatherPlants or
df.job_type_class[df.job_type.attrs[unit.job.current_job.job_type].type] == 'Digging')) then
-- Ignore units who are:
-- gathering plants (could be on stepladder)
-- digging (could be digging self out of hole)
-- standing on an open hatch (which is its own pathability group)
-- to avoid false positives
if unitIgnored(unit) or hasAllowlistedJob(unit) or hasAllowlistedPos(unitPos) then
table.insert(ensure_key(ignoredGroup, walkGroup), unit)
else
table.insert(ensure_key(grouped, walkGroup), unit)
Expand Down