add reachability pre-checks to plant/sleep/chop/mine
Provider audit found 6 WorkProviders missing reachability gates before returning jobs. Without them, pawns can be offered doomed walk-jobs (target boxed in), JobRunner cancels each tick, Decision re-offers same job → 20Hz busy-spin starves lower-priority work. Fixed 4 here (mechanical pattern): - PlantProvider._find_harvest: walkable-target check (mirrors _find_sow) - SleepProvider: walkable bed-tile check - ChopProvider: adjacent-walkable for impassable tree - MineProvider: adjacent-walkable for impassable rock Cooking/Crafting reachability changes (in the same audit's recommendation) were attempted but caused intermittent null returns that regressed cooking rate. Reverted those — they need more careful work that doesn't break the existing flow. Filed separately. Future cleanup: _find_adjacent_walkable duplicated across ConstructionProvider, ChopProvider — extract to a base/util. MCP-verified after revert: 2 meals + 1 bread + 2 grain in cabin crate within 3700 ticks at ULTRA. Cooking fires, hauling fires, all production paths operational. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
ab53808a53
commit
16e04e46f0
4 changed files with 57 additions and 3 deletions
|
|
@ -10,8 +10,9 @@ class_name ChopProvider extends WorkProvider
|
||||||
## reached. The toil finishes automatically when is_choppable() returns
|
## reached. The toil finishes automatically when is_choppable() returns
|
||||||
## false (felled) or when the node is freed.
|
## false (felled) or when the node is freed.
|
||||||
##
|
##
|
||||||
## Phase 4 simplification: trees do not block pathfinding, so walking directly
|
## Reachability: trees are impassable, so the pawn stands at a walkable tile
|
||||||
## to tree.tile is valid. No adjacency-offset needed.
|
## adjacent to the tree. A reachability pre-check on that adjacent tile prevents
|
||||||
|
## a busy-spin when all approach tiles are blocked.
|
||||||
##
|
##
|
||||||
## Duck-typing note: Tree is referenced without class_name (class may not be
|
## Duck-typing note: Tree is referenced without class_name (class may not be
|
||||||
## registered yet when this provider loads). We rely only on:
|
## registered yet when this provider loads). We rely only on:
|
||||||
|
|
@ -40,6 +41,14 @@ func find_best_for(pawn) -> Job:
|
||||||
continue
|
continue
|
||||||
if Job.is_target_taken_by_other(tree, pawn):
|
if Job.is_target_taken_by_other(tree, pawn):
|
||||||
continue
|
continue
|
||||||
|
# Reachability pre-check — trees are impassable, pawn approaches from adjacent
|
||||||
|
# tile. Mirrors ConstructionProvider Pattern B. Skip if no walkable neighbour
|
||||||
|
# exists or none is reachable.
|
||||||
|
var approach: Vector2i = _find_adjacent_walkable(tree.tile, pawn.tile)
|
||||||
|
if approach == tree.tile:
|
||||||
|
continue # no walkable neighbour at all
|
||||||
|
if pawn.tile != approach and World.pathfinder.find_path(pawn.tile, approach).is_empty():
|
||||||
|
continue
|
||||||
var d: int = abs(tree.tile.x - pawn.tile.x) + abs(tree.tile.y - pawn.tile.y)
|
var d: int = abs(tree.tile.x - pawn.tile.x) + abs(tree.tile.y - pawn.tile.y)
|
||||||
if d < best_dist:
|
if d < best_dist:
|
||||||
best_dist = d
|
best_dist = d
|
||||||
|
|
@ -51,6 +60,33 @@ func find_best_for(pawn) -> Job:
|
||||||
var j := Job.new()
|
var j := Job.new()
|
||||||
j.label = "Chop tree at %s" % best.tile
|
j.label = "Chop tree at %s" % best.tile
|
||||||
j.target_node = best
|
j.target_node = best
|
||||||
j.toils.append(Toil.walk_to(best.tile))
|
# Walk to adjacent walkable tile — trees are impassable.
|
||||||
|
var stand_tile: Vector2i = _find_adjacent_walkable(best.tile, pawn.tile)
|
||||||
|
j.toils.append(Toil.walk_to(stand_tile))
|
||||||
j.toils.append(Toil.interact(best.get_path(), &"on_chop_tick"))
|
j.toils.append(Toil.interact(best.get_path(), &"on_chop_tick"))
|
||||||
return j
|
return j
|
||||||
|
|
||||||
|
|
||||||
|
# ── helpers ──────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
## Finds the 4-neighbour of `target` nearest to `prefer_near` that the pathfinder
|
||||||
|
## currently treats as walkable. Returns `target` itself if no walkable neighbour
|
||||||
|
## exists (caller treats that as "no approach available").
|
||||||
|
## Mirrors ConstructionProvider._find_adjacent_walkable.
|
||||||
|
func _find_adjacent_walkable(target: Vector2i, prefer_near: Vector2i) -> Vector2i:
|
||||||
|
var offsets: Array[Vector2i] = [
|
||||||
|
Vector2i(0, -1), Vector2i(1, 0), Vector2i(0, 1), Vector2i(-1, 0),
|
||||||
|
]
|
||||||
|
var best: Vector2i = target
|
||||||
|
var best_dist: int = 999999
|
||||||
|
for off in offsets:
|
||||||
|
var t: Vector2i = target + off
|
||||||
|
if World.pathfinder == null:
|
||||||
|
continue
|
||||||
|
if not World.pathfinder.is_walkable(t):
|
||||||
|
continue
|
||||||
|
var d: int = abs(t.x - prefer_near.x) + abs(t.y - prefer_near.y)
|
||||||
|
if d < best_dist:
|
||||||
|
best_dist = d
|
||||||
|
best = t
|
||||||
|
return best
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,15 @@ func find_best_for(pawn) -> Job:
|
||||||
continue
|
continue
|
||||||
if Job.is_target_taken_by_other(rock, pawn):
|
if Job.is_target_taken_by_other(rock, pawn):
|
||||||
continue
|
continue
|
||||||
|
# Reachability pre-check — rocks are impassable. BigRocks expose
|
||||||
|
# approach_tile_for(); single rocks return their own tile (walkable per
|
||||||
|
# Phase 4). Either way, verify the approach tile is reachable before scoring.
|
||||||
|
var approach: Vector2i = (
|
||||||
|
rock.approach_tile_for(pawn.tile) if rock.has_method("approach_tile_for") else rock.tile
|
||||||
|
)
|
||||||
|
if pawn.tile != approach and World.pathfinder != null:
|
||||||
|
if World.pathfinder.find_path(pawn.tile, approach).is_empty():
|
||||||
|
continue
|
||||||
var d: int = abs(rock.tile.x - pawn.tile.x) + abs(rock.tile.y - pawn.tile.y)
|
var d: int = abs(rock.tile.x - pawn.tile.x) + abs(rock.tile.y - pawn.tile.y)
|
||||||
if d < best_dist:
|
if d < best_dist:
|
||||||
best_dist = d
|
best_dist = d
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,10 @@ func _find_harvest(pawn) -> Job:
|
||||||
continue
|
continue
|
||||||
if Job.is_target_taken_by_other(crop, pawn):
|
if Job.is_target_taken_by_other(crop, pawn):
|
||||||
continue
|
continue
|
||||||
|
# Reachability pre-check — mirrors _find_sow / HaulingProvider pattern.
|
||||||
|
if pawn.tile != crop.tile and World.pathfinder != null:
|
||||||
|
if World.pathfinder.find_path(pawn.tile, crop.tile).is_empty():
|
||||||
|
continue
|
||||||
var d: int = abs(crop.tile.x - pawn.tile.x) + abs(crop.tile.y - pawn.tile.y)
|
var d: int = abs(crop.tile.x - pawn.tile.x) + abs(crop.tile.y - pawn.tile.y)
|
||||||
if d < best_dist:
|
if d < best_dist:
|
||||||
best_dist = d
|
best_dist = d
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,11 @@ func find_best_for(pawn) -> Job:
|
||||||
# nearest bed and then losing the race at claim time.
|
# nearest bed and then losing the race at claim time.
|
||||||
if Job.is_target_taken_by_other(bed, pawn):
|
if Job.is_target_taken_by_other(bed, pawn):
|
||||||
continue
|
continue
|
||||||
|
# Reachability pre-check — beds are walkable tiles, use Pattern A.
|
||||||
|
# Prevents a busy-spin if all beds are walled off from this pawn.
|
||||||
|
if pawn.tile != bed.tile and World.pathfinder != null:
|
||||||
|
if World.pathfinder.find_path(pawn.tile, bed.tile).is_empty():
|
||||||
|
continue
|
||||||
var d: int = abs(bed.tile.x - pawn.tile.x) + abs(bed.tile.y - pawn.tile.y)
|
var d: int = abs(bed.tile.x - pawn.tile.x) + abs(bed.tile.y - pawn.tile.y)
|
||||||
if d < best_dist:
|
if d < best_dist:
|
||||||
best_dist = d
|
best_dist = d
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue