Skip to content

Commit 3cc28ae

Browse files
committed
suspendmanager: improve detection on "T" and "+" shapes
1 parent ff8d148 commit 3cc28ae

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Template for new versions:
3333
- `suspendmanager`: Fix the overlay enabling/disabling `suspendmanager` unexpectedly
3434
- `caravan`: Correct price adjustment values in trade agreement details screen
3535
- `caravan`: Apply both import and export trade agreement price adjustments to items being both bought or sold to align with how vanilla DF calculates prices
36+
- `suspendmanager`: Improve the detection on "T" and "+" shaped high walls
3637

3738
## Misc Improvements
3839
- `devel/lsmem`: added support for filtering by memory addresses and filenames

suspendmanager.lua

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ EXTERNAL_REASONS = {
6666
---@class SuspendManager
6767
---@field preventBlocking boolean
6868
---@field suspensions table<integer, reason>
69+
---@field leadsToDeadend table<integer, boolean>
6970
---@field lastAutoRunTick integer
7071
SuspendManager = defclass(SuspendManager)
7172
SuspendManager.ATTRS {
@@ -76,6 +77,9 @@ SuspendManager.ATTRS {
7677
--- Current job suspensions with their reasons
7778
suspensions = {},
7879

80+
--- Current job that are part of a dead-end, not worth considering as an exit
81+
leadsToDeadend = {},
82+
7983
--- Last tick where it was run automatically
8084
lastAutoRunTick = -1,
8185
}
@@ -316,11 +320,6 @@ function SuspendManager:suspendDeadend(start_job)
316320
if not building then return end
317321
local pos = {x=building.centerx,y=building.centery,z=building.z}
318322

319-
-- visited building ids of this potential dead end
320-
local visited = {
321-
[building.id] = true
322-
}
323-
324323
--- Support dead ends of a maximum length of 1000
325324
for _=0,1000 do
326325
-- building plan on the way to the exit
@@ -338,7 +337,7 @@ function SuspendManager:suspendDeadend(start_job)
338337
return
339338
end
340339

341-
if visited[impassablePlan.id] then
340+
if self.leadsToDeadend[impassablePlan.id] then
342341
-- already visited, not an exit
343342
goto continue
344343
end
@@ -356,14 +355,19 @@ function SuspendManager:suspendDeadend(start_job)
356355

357356
if not exit then return end
358357

359-
-- exit is the single exit point of this corridor, suspend its construction job
358+
-- exit is the single exit point of this corridor, suspend its construction job,
359+
-- mark the current tile of the corridor as leading to a dead-end
360360
-- and continue the exploration from its position
361361
for _,job in ipairs(exit.jobs) do
362362
if job.job_type == df.job_type.ConstructBuilding then
363363
self.suspensions[job.id] = REASON.DEADEND
364364
end
365365
end
366-
visited[exit.id] = true
366+
local building = dfhack.buildings.findAtTile(pos)
367+
if building then
368+
self.leadsToDeadend[building.id] = true
369+
end
370+
367371
pos = {x=exit.centerx,y=exit.centery,z=exit.z}
368372
end
369373
end
@@ -417,6 +421,7 @@ end
417421
--- Recompute the list of suspended jobs
418422
function SuspendManager:refresh()
419423
self.suspensions = {}
424+
self.leadsToDeadend = {}
420425

421426
for _,job in utils.listpairs(df.global.world.jobs.list) do
422427
-- External reasons to suspend a job

0 commit comments

Comments
 (0)