Soft-path gated doors, then block with toast and shove.
Pathfinding treats requirement doors as walkable with a high step cost so detours win when available; entering still enforces requirements.
@@ -1521,7 +1521,7 @@ function findCoverMeleeApproachPath (world, entityId, handle, position, targetPo
1521
1521
return world.isClearStanding?.(entityId, x, y)
1522
1522
?? world.walkableFor(entityId, x, y);
1523
1523
}
1524
return world.walkableFor(entityId, x, y);
1524
return world.pathWalkableFor?.(entityId, x, y) ?? world.walkableFor(entityId, x, y, { softDoorRequirements: true });
1525
1525
};
1526
1526
let bestTiles = null;
1527
1527
let bestScore = Infinity;
@@ -1569,7 +1569,7 @@ function queueFleeToCover (world, entityId, handle, position, threatPos)
1569
1569
if (!path)
1570
1570
{ path = world.ecs.add(handle, Component.path, { tiles: [] }); }
1571
1571
const bounds = chunkBoundsAround(position.tileX, position.tileY, VISIBLE_CHUNK_RADIUS);
1572
const isWalkable = (x, y) => world.walkableFor(entityId, x, y);
1572
const isWalkable = (x, y) => world.pathWalkableFor?.(entityId, x, y) ?? world.walkableFor(entityId, x, y, { softDoorRequirements: true });
1573
1573
const isGoal = (x, y) =>
1574
1574
{
1575
1575
if (!(world.isClearStanding?.(entityId, x, y) ?? world.walkableFor(entityId, x, y)))
@@ -1629,7 +1629,7 @@ function queueFleeFromHitSource (world, entityId, handle, position, source, minD
1629
1629
return;
1630
1630
}
1631
1631
const bounds = chunkBoundsAround(position.tileX, position.tileY, VISIBLE_CHUNK_RADIUS);
1632
const isWalkable = (x, y) => world.walkableFor(entityId, x, y);
1632
const isWalkable = (x, y) => world.pathWalkableFor?.(entityId, x, y) ?? world.walkableFor(entityId, x, y, { softDoorRequirements: true });
1633
1633
const isGoal = (x, y) =>
1634
1634
{
1635
1635
if (chebyshev(x, y, source.tileX, source.tileY) < minDist)
@@ -1749,7 +1749,7 @@ export function queueMeleeApproach (world, entityId, handle, position, targetPos
1749
1749
return world.isClearStanding?.(entityId, x, y)
1750
1750
?? world.walkableFor(entityId, x, y);
1751
1751
}
1752
return world.walkableFor(entityId, x, y);
1752
return world.pathWalkableFor?.(entityId, x, y) ?? world.walkableFor(entityId, x, y, { softDoorRequirements: true });
1753
1753
},
1754
1754
bounds.minX,
1755
1755
bounds.minY,
@@ -1807,7 +1807,7 @@ export function queueStandInRangeApproach (
1807
1807
const combat = world.ecs.get(handle, Component.combat);
1808
1808
const reserved = collectCombatAllyReservations(world, entityId, combat?.targetEntityId ?? null);
1809
1809
const bounds = chunkBoundsAround(position.tileX, position.tileY, VISIBLE_CHUNK_RADIUS);
1810
const isWalkable = (x, y) => world.walkableFor(entityId, x, y);
1810
const isWalkable = (x, y) => world.pathWalkableFor?.(entityId, x, y) ?? world.walkableFor(entityId, x, y, { softDoorRequirements: true });
1811
1811
const isGoal = (x, y) =>
1812
1812
{
1813
1813
const standOff = chebyshev(x, y, targetTileX, targetTileY);
@@ -1521,7 +1521,7 @@ function findCoverMeleeApproachPath (world, entityId, handle, position, targetPo1521
return world.isClearStanding?.(entityId, x, y)1521
return world.isClearStanding?.(entityId, x, y)1522
?? world.walkableFor(entityId, x, y);1522
?? world.walkableFor(entityId, x, y);1523
}1523
}1524
return world.walkableFor(entityId, x, y);1524
return world.pathWalkableFor?.(entityId, x, y) ?? world.walkableFor(entityId, x, y, { softDoorRequirements: true });1525
};1525
};1526
let bestTiles = null;1526
let bestTiles = null;1527
let bestScore = Infinity;1527
let bestScore = Infinity;@@ -1569,7 +1569,7 @@ function queueFleeToCover (world, entityId, handle, position, threatPos)1569
if (!path)1569
if (!path)1570
{ path = world.ecs.add(handle, Component.path, { tiles: [] }); }1570
{ path = world.ecs.add(handle, Component.path, { tiles: [] }); }1571
const bounds = chunkBoundsAround(position.tileX, position.tileY, VISIBLE_CHUNK_RADIUS);1571
const bounds = chunkBoundsAround(position.tileX, position.tileY, VISIBLE_CHUNK_RADIUS);1572
const isWalkable = (x, y) => world.walkableFor(entityId, x, y);1572
const isWalkable = (x, y) => world.pathWalkableFor?.(entityId, x, y) ?? world.walkableFor(entityId, x, y, { softDoorRequirements: true });1573
const isGoal = (x, y) =>1573
const isGoal = (x, y) =>1574
{1574
{1575
if (!(world.isClearStanding?.(entityId, x, y) ?? world.walkableFor(entityId, x, y)))1575
if (!(world.isClearStanding?.(entityId, x, y) ?? world.walkableFor(entityId, x, y)))@@ -1629,7 +1629,7 @@ function queueFleeFromHitSource (world, entityId, handle, position, source, minD1629
return;1629
return;1630
}1630
}1631
const bounds = chunkBoundsAround(position.tileX, position.tileY, VISIBLE_CHUNK_RADIUS);1631
const bounds = chunkBoundsAround(position.tileX, position.tileY, VISIBLE_CHUNK_RADIUS);1632
const isWalkable = (x, y) => world.walkableFor(entityId, x, y);1632
const isWalkable = (x, y) => world.pathWalkableFor?.(entityId, x, y) ?? world.walkableFor(entityId, x, y, { softDoorRequirements: true });1633
const isGoal = (x, y) =>1633
const isGoal = (x, y) =>1634
{1634
{1635
if (chebyshev(x, y, source.tileX, source.tileY) < minDist)1635
if (chebyshev(x, y, source.tileX, source.tileY) < minDist)@@ -1749,7 +1749,7 @@ export function queueMeleeApproach (world, entityId, handle, position, targetPos1749
return world.isClearStanding?.(entityId, x, y)1749
return world.isClearStanding?.(entityId, x, y)1750
?? world.walkableFor(entityId, x, y);1750
?? world.walkableFor(entityId, x, y);1751
}1751
}1752
return world.walkableFor(entityId, x, y);1752
return world.pathWalkableFor?.(entityId, x, y) ?? world.walkableFor(entityId, x, y, { softDoorRequirements: true });1753
},1753
},1754
bounds.minX,1754
bounds.minX,1755
bounds.minY,1755
bounds.minY,@@ -1807,7 +1807,7 @@ export function queueStandInRangeApproach (1807
const combat = world.ecs.get(handle, Component.combat);1807
const combat = world.ecs.get(handle, Component.combat);1808
const reserved = collectCombatAllyReservations(world, entityId, combat?.targetEntityId ?? null);1808
const reserved = collectCombatAllyReservations(world, entityId, combat?.targetEntityId ?? null);1809
const bounds = chunkBoundsAround(position.tileX, position.tileY, VISIBLE_CHUNK_RADIUS);1809
const bounds = chunkBoundsAround(position.tileX, position.tileY, VISIBLE_CHUNK_RADIUS);1810
const isWalkable = (x, y) => world.walkableFor(entityId, x, y);1810
const isWalkable = (x, y) => world.pathWalkableFor?.(entityId, x, y) ?? world.walkableFor(entityId, x, y, { softDoorRequirements: true });1811
const isGoal = (x, y) =>1811
const isGoal = (x, y) =>1812
{1812
{1813
const standOff = chebyshev(x, y, targetTileX, targetTileY);1813
const standOff = chebyshev(x, y, targetTileX, targetTileY);@@ -285,7 +285,7 @@ function queueCatchUp (world, entityId, handle, position, targetPos, path)
285
285
(x, y) =>
286
286
{
287
287
// Plan onto the target tile; movement still waits while they occupy it.
288
return world.walkableFor(entityId, x, y);
288
return world.pathWalkableFor?.(entityId, x, y) ?? world.walkableFor(entityId, x, y, { softDoorRequirements: true });
289
289
},
290
290
bounds.minX,
291
291
bounds.minY,
@@ -285,7 +285,7 @@ function queueCatchUp (world, entityId, handle, position, targetPos, path)285
(x, y) =>285
(x, y) =>286
{286
{287
// Plan onto the target tile; movement still waits while they occupy it.287
// Plan onto the target tile; movement still waits while they occupy it.288
return world.walkableFor(entityId, x, y);288
return world.pathWalkableFor?.(entityId, x, y) ?? world.walkableFor(entityId, x, y, { softDoorRequirements: true });289
},289
},290
bounds.minX,290
bounds.minX,291
bounds.minY,291
bounds.minY,@@ -100,7 +100,8 @@ import {
100
100
import {
101
101
stepCostForGround,
102
102
PATH_GROUND_STEP_COST,
103
SOFT_OCCUPIED_DWELL_MS
103
SOFT_OCCUPIED_DWELL_MS,
104
DOOR_REQUIREMENT_FAIL_STEP_COST
104
105
} from "../../../shared/navigation/pathGround.js";
105
106
import { canTalkOrShopNear } from "../../../shared/navigation/adjacency.js";
106
107
import { objectPronoun } from "../../../shared/speech/pronouns.js";
@@ -110,6 +111,7 @@ import { clearFollow, setFollow, stepFollow, recordFollowTrail, consumeFollowTra
110
111
import { ensureFlightComponent, stepFreeFlight } from "./freeFlight.js";
111
112
import { stepStatusEffects } from "../statusEffects/service.js";
112
113
import { hasStatusEffect, StatusEffectType } from "../../../shared/statusEffects/rules.js";
114
import { tileShoveEvent } from "./tileInteract.js";
113
115
114
116
export class WorkerWorld
115
117
{
@@ -1089,7 +1091,7 @@ export class WorkerWorld
1089
1091
position.tileY,
1090
1092
tileX,
1091
1093
tileY,
1092
(x, y) => this.walkableFor(entityId, x, y),
1094
(x, y) => this.pathWalkableFor(entityId, x, y),
1093
1095
bounds.minX,
1094
1096
bounds.minY,
1095
1097
bounds.maxX,
@@ -1711,6 +1713,14 @@ export class WorkerWorld
1711
1713
if (blockedToast)
1712
1714
{
1713
1715
events.push(blockedToast);
1716
events.push(tileShoveEvent(
1717
entityId,
1718
position.tileX,
1719
position.tileY,
1720
next.x,
1721
next.y,
1722
dimensionId
1723
));
1714
1724
path.tiles = [];
1715
1725
continue;
1716
1726
}
@@ -1809,7 +1819,8 @@ export class WorkerWorld
1809
1819
position.tileY,
1810
1820
goal.x,
1811
1821
goal.y,
1812
(x, y) => this.isClearStanding(entityId, x, y),
1822
(x, y) => this.pathWalkableFor(entityId, x, y)
1823
&& !this.#hasOtherOccupant(entityId, x, y, normalizeDimensionId(position.dimensionId ?? OVERWORLD_ID)),
1813
1824
bounds.minX,
1814
1825
bounds.minY,
1815
1826
bounds.maxX,
@@ -1922,7 +1933,7 @@ export class WorkerWorld
1922
1933
entity.position.tileY,
1923
1934
goal.tileX,
1924
1935
goal.tileY,
1925
(x, y) => this.walkableFor(entity.entityId, x, y),
1936
(x, y) => this.pathWalkableFor(entity.entityId, x, y),
1926
1937
bounds.minX,
1927
1938
bounds.minY,
1928
1939
bounds.maxX,
@@ -1960,7 +1971,7 @@ export class WorkerWorld
1960
1971
position.tileY,
1961
1972
goal.tileX,
1962
1973
goal.tileY,
1963
(x, y) => this.walkableFor(entityId, x, y),
1974
(x, y) => this.pathWalkableFor(entityId, x, y),
1964
1975
bounds.minX,
1965
1976
bounds.minY,
1966
1977
bounds.maxX,
@@ -2030,7 +2041,7 @@ export class WorkerWorld
2030
2041
best.position.tileY,
2031
2042
stationTileX,
2032
2043
stationTileY,
2033
(x, y) => this.walkableFor(best.entityId, x, y),
2044
(x, y) => this.pathWalkableFor(best.entityId, x, y),
2034
2045
bounds.minX,
2035
2046
bounds.minY,
2036
2047
bounds.maxX,
@@ -2201,7 +2212,7 @@ export class WorkerWorld
2201
2212
entity.position.tileY,
2202
2213
sx,
2203
2214
sy,
2204
(x, y) => this.walkableFor(entity.entityId, x, y),
2215
(x, y) => this.pathWalkableFor(entity.entityId, x, y),
2205
2216
bounds.minX,
2206
2217
bounds.minY,
2207
2218
bounds.maxX,
@@ -2391,7 +2402,7 @@ export class WorkerWorld
2391
2402
return !!chunk && !chunk.replica && chunk.simulating;
2392
2403
}
2393
2404
2394
walkableFor (entityId, tileX, tileY)
2405
walkableFor (entityId, tileX, tileY, { softDoorRequirements = false } = {})
2395
2406
{
2396
2407
const dim = this.#entityDimensionId(entityId);
2397
2408
const handle = this.ecs.handleOf(entityId);
@@ -2400,13 +2411,22 @@ export class WorkerWorld
2400
2411
const data = this.#chunkData(tileToChunk(tileX), tileToChunk(tileY), dim);
2401
2412
return !!data?.open;
2402
2413
}
2403
// Entities pass through each other; only terrain / closed chunks block movement.
2414
// Soft pathing treats gated doors as walkable; movement still enforces requirements.
2415
const requirementsAllow = softDoorRequirements
2416
? true
2417
: entityDoorRequirementsAllow(this, entityId, tileX, tileY);
2404
2418
return this.isEnterable(tileX, tileY, dim, {
2405
2419
canOpenDoors: entityCanOpenDoors(this.ecs, entityId),
2406
requirementsAllow: entityDoorRequirementsAllow(this, entityId, tileX, tileY)
2420
requirementsAllow
2407
2421
});
2408
2422
}
2409
2423
2424
/** Pathfinding walkability: may route through requirement doors (cost-penalized). */
2425
pathWalkableFor (entityId, tileX, tileY)
2426
{
2427
return this.walkableFor(entityId, tileX, tileY, { softDoorRequirements: true });
2428
}
2429
2410
2430
/** Ground type id at a world tile (defaults to world default ground). */
2411
2431
groundTypeAt (tileX, tileY, dimensionId = OVERWORLD_ID)
2412
2432
{
@@ -2438,19 +2458,37 @@ export class WorkerWorld
2438
2458
}
2439
2459
options.stepCost = (x, y) =>
2440
2460
{
2441
const base = stepCostForGround(
2461
let cost = stepCostForGround(
2442
2462
this.groundTypeAt(x, y, dimensionId),
2443
2463
{
2444
2464
preferPaths: !!preferPaths,
2445
2465
softOccupied: entityId != null && this.#isSoftOccupiedTile(x, y, dimensionId, entityId, now)
2446
2466
}
2447
2467
);
2448
return withCombatBackstepCost(base, x, y, prevTileX, prevTileY);
2468
if (entityId != null)
2469
{ cost += this.#doorRequirementPathPenalty(entityId, x, y); }
2470
return withCombatBackstepCost(cost, x, y, prevTileX, prevTileY);
2449
2471
};
2450
2472
options.minStepCost = preferPaths ? PATH_GROUND_STEP_COST : 1;
2451
2473
return options;
2452
2474
}
2453
2475
2476
/** Extra path cost for gated doors the player cannot pass. */
2477
#doorRequirementPathPenalty (entityId, tileX, tileY)
2478
{
2479
const handle = this.ecs.handleOf(entityId);
2480
if (handle == null || !this.ecs.get(handle, Component.character))
2481
{ return 0; }
2482
const dimensionId = this.#entityDimensionId(entityId);
2483
const data = this.#chunkData(tileToChunk(tileX), tileToChunk(tileY), dimensionId);
2484
const block = data?.blocks?.[tileIndex(tileToLocal(tileX), tileToLocal(tileY))];
2485
if (!isDoorBlock(block) || !doorHasRequirements(block))
2486
{ return 0; }
2487
if (entityDoorRequirementsAllow(this, entityId, tileX, tileY))
2488
{ return 0; }
2489
return DOOR_REQUIREMENT_FAIL_STEP_COST;
2490
}
2491
2454
2492
/**
2455
2493
* True when another living occupant has stood on this tile for SOFT_OCCUPIED_DWELL_MS+.
2456
2494
* Soft cost only — never blocks pathing.
@@ -100,7 +100,8 @@ import {100
import {100
import {101
stepCostForGround,101
stepCostForGround,102
PATH_GROUND_STEP_COST,102
PATH_GROUND_STEP_COST,103
SOFT_OCCUPIED_DWELL_MS103
SOFT_OCCUPIED_DWELL_MS,104
DOOR_REQUIREMENT_FAIL_STEP_COST104
} from "../../../shared/navigation/pathGround.js";105
} from "../../../shared/navigation/pathGround.js";105
import { canTalkOrShopNear } from "../../../shared/navigation/adjacency.js";106
import { canTalkOrShopNear } from "../../../shared/navigation/adjacency.js";106
import { objectPronoun } from "../../../shared/speech/pronouns.js";107
import { objectPronoun } from "../../../shared/speech/pronouns.js";@@ -110,6 +111,7 @@ import { clearFollow, setFollow, stepFollow, recordFollowTrail, consumeFollowTra110
import { ensureFlightComponent, stepFreeFlight } from "./freeFlight.js";111
import { ensureFlightComponent, stepFreeFlight } from "./freeFlight.js";111
import { stepStatusEffects } from "../statusEffects/service.js";112
import { stepStatusEffects } from "../statusEffects/service.js";112
import { hasStatusEffect, StatusEffectType } from "../../../shared/statusEffects/rules.js";113
import { hasStatusEffect, StatusEffectType } from "../../../shared/statusEffects/rules.js";114
import { tileShoveEvent } from "./tileInteract.js";113
115
114
export class WorkerWorld116
export class WorkerWorld115
{117
{@@ -1089,7 +1091,7 @@ export class WorkerWorld1089
position.tileY,1091
position.tileY,1090
tileX,1092
tileX,1091
tileY,1093
tileY,1092
(x, y) => this.walkableFor(entityId, x, y),1094
(x, y) => this.pathWalkableFor(entityId, x, y),1093
bounds.minX,1095
bounds.minX,1094
bounds.minY,1096
bounds.minY,1095
bounds.maxX,1097
bounds.maxX,@@ -1711,6 +1713,14 @@ export class WorkerWorld1711
if (blockedToast)1713
if (blockedToast)1712
{1714
{1713
events.push(blockedToast);1715
events.push(blockedToast);1716
events.push(tileShoveEvent(1717
entityId,1718
position.tileX,1719
position.tileY,1720
next.x,1721
next.y,1722
dimensionId1723
));1714
path.tiles = [];1724
path.tiles = [];1715
continue;1725
continue;1716
}1726
}@@ -1809,7 +1819,8 @@ export class WorkerWorld1809
position.tileY,1819
position.tileY,1810
goal.x,1820
goal.x,1811
goal.y,1821
goal.y,1812
(x, y) => this.isClearStanding(entityId, x, y),1822
(x, y) => this.pathWalkableFor(entityId, x, y)1823
&& !this.#hasOtherOccupant(entityId, x, y, normalizeDimensionId(position.dimensionId ?? OVERWORLD_ID)),1813
bounds.minX,1824
bounds.minX,1814
bounds.minY,1825
bounds.minY,1815
bounds.maxX,1826
bounds.maxX,@@ -1922,7 +1933,7 @@ export class WorkerWorld1922
entity.position.tileY,1933
entity.position.tileY,1923
goal.tileX,1934
goal.tileX,1924
goal.tileY,1935
goal.tileY,1925
(x, y) => this.walkableFor(entity.entityId, x, y),1936
(x, y) => this.pathWalkableFor(entity.entityId, x, y),1926
bounds.minX,1937
bounds.minX,1927
bounds.minY,1938
bounds.minY,1928
bounds.maxX,1939
bounds.maxX,@@ -1960,7 +1971,7 @@ export class WorkerWorld1960
position.tileY,1971
position.tileY,1961
goal.tileX,1972
goal.tileX,1962
goal.tileY,1973
goal.tileY,1963
(x, y) => this.walkableFor(entityId, x, y),1974
(x, y) => this.pathWalkableFor(entityId, x, y),1964
bounds.minX,1975
bounds.minX,1965
bounds.minY,1976
bounds.minY,1966
bounds.maxX,1977
bounds.maxX,@@ -2030,7 +2041,7 @@ export class WorkerWorld2030
best.position.tileY,2041
best.position.tileY,2031
stationTileX,2042
stationTileX,2032
stationTileY,2043
stationTileY,2033
(x, y) => this.walkableFor(best.entityId, x, y),2044
(x, y) => this.pathWalkableFor(best.entityId, x, y),2034
bounds.minX,2045
bounds.minX,2035
bounds.minY,2046
bounds.minY,2036
bounds.maxX,2047
bounds.maxX,@@ -2201,7 +2212,7 @@ export class WorkerWorld2201
entity.position.tileY,2212
entity.position.tileY,2202
sx,2213
sx,2203
sy,2214
sy,2204
(x, y) => this.walkableFor(entity.entityId, x, y),2215
(x, y) => this.pathWalkableFor(entity.entityId, x, y),2205
bounds.minX,2216
bounds.minX,2206
bounds.minY,2217
bounds.minY,2207
bounds.maxX,2218
bounds.maxX,@@ -2391,7 +2402,7 @@ export class WorkerWorld2391
return !!chunk && !chunk.replica && chunk.simulating;2402
return !!chunk && !chunk.replica && chunk.simulating;2392
}2403
}2393
2404
2394
walkableFor (entityId, tileX, tileY)2405
walkableFor (entityId, tileX, tileY, { softDoorRequirements = false } = {})2395
{2406
{2396
const dim = this.#entityDimensionId(entityId);2407
const dim = this.#entityDimensionId(entityId);2397
const handle = this.ecs.handleOf(entityId);2408
const handle = this.ecs.handleOf(entityId);@@ -2400,13 +2411,22 @@ export class WorkerWorld2400
const data = this.#chunkData(tileToChunk(tileX), tileToChunk(tileY), dim);2411
const data = this.#chunkData(tileToChunk(tileX), tileToChunk(tileY), dim);2401
return !!data?.open;2412
return !!data?.open;2402
}2413
}2403
// Entities pass through each other; only terrain / closed chunks block movement.2414
// Soft pathing treats gated doors as walkable; movement still enforces requirements.2415
const requirementsAllow = softDoorRequirements2416
? true2417
: entityDoorRequirementsAllow(this, entityId, tileX, tileY);2404
return this.isEnterable(tileX, tileY, dim, {2418
return this.isEnterable(tileX, tileY, dim, {2405
canOpenDoors: entityCanOpenDoors(this.ecs, entityId),2419
canOpenDoors: entityCanOpenDoors(this.ecs, entityId),2406
requirementsAllow: entityDoorRequirementsAllow(this, entityId, tileX, tileY)2420
requirementsAllow2407
});2421
});2408
}2422
}2409
2423
2424
/** Pathfinding walkability: may route through requirement doors (cost-penalized). */2425
pathWalkableFor (entityId, tileX, tileY)2426
{2427
return this.walkableFor(entityId, tileX, tileY, { softDoorRequirements: true });2428
}2429
2410
/** Ground type id at a world tile (defaults to world default ground). */2430
/** Ground type id at a world tile (defaults to world default ground). */2411
groundTypeAt (tileX, tileY, dimensionId = OVERWORLD_ID)2431
groundTypeAt (tileX, tileY, dimensionId = OVERWORLD_ID)2412
{2432
{@@ -2438,19 +2458,37 @@ export class WorkerWorld2438
}2458
}2439
options.stepCost = (x, y) =>2459
options.stepCost = (x, y) =>2440
{2460
{2441
const base = stepCostForGround(2461
let cost = stepCostForGround(2442
this.groundTypeAt(x, y, dimensionId),2462
this.groundTypeAt(x, y, dimensionId),2443
{2463
{2444
preferPaths: !!preferPaths,2464
preferPaths: !!preferPaths,2445
softOccupied: entityId != null && this.#isSoftOccupiedTile(x, y, dimensionId, entityId, now)2465
softOccupied: entityId != null && this.#isSoftOccupiedTile(x, y, dimensionId, entityId, now)2446
}2466
}2447
);2467
);2448
return withCombatBackstepCost(base, x, y, prevTileX, prevTileY);2468
if (entityId != null)2469
{ cost += this.#doorRequirementPathPenalty(entityId, x, y); }2470
return withCombatBackstepCost(cost, x, y, prevTileX, prevTileY);2449
};2471
};2450
options.minStepCost = preferPaths ? PATH_GROUND_STEP_COST : 1;2472
options.minStepCost = preferPaths ? PATH_GROUND_STEP_COST : 1;2451
return options;2473
return options;2452
}2474
}2453
2475
2476
/** Extra path cost for gated doors the player cannot pass. */2477
#doorRequirementPathPenalty (entityId, tileX, tileY)2478
{2479
const handle = this.ecs.handleOf(entityId);2480
if (handle == null || !this.ecs.get(handle, Component.character))2481
{ return 0; }2482
const dimensionId = this.#entityDimensionId(entityId);2483
const data = this.#chunkData(tileToChunk(tileX), tileToChunk(tileY), dimensionId);2484
const block = data?.blocks?.[tileIndex(tileToLocal(tileX), tileToLocal(tileY))];2485
if (!isDoorBlock(block) || !doorHasRequirements(block))2486
{ return 0; }2487
if (entityDoorRequirementsAllow(this, entityId, tileX, tileY))2488
{ return 0; }2489
return DOOR_REQUIREMENT_FAIL_STEP_COST;2490
}2491
2454
/**2492
/**2455
* True when another living occupant has stood on this tile for SOFT_OCCUPIED_DWELL_MS+.2493
* True when another living occupant has stood on this tile for SOFT_OCCUPIED_DWELL_MS+.2456
* Soft cost only — never blocks pathing.2494
* Soft cost only — never blocks pathing.@@ -51,6 +51,30 @@ function placeDoor (worker, tileX, tileY, state, config = null)
51
51
};
52
52
}
53
53
54
function placeWall (worker, tileX, tileY)
55
{
56
const data = worker.world.chunkData(Math.floor(tileX / 16), Math.floor(tileY / 16));
57
const localX = ((tileX % 16) + 16) % 16;
58
const localY = ((tileY % 16) + 16) % 16;
59
data.blocks[localY * 16 + localX] = {
60
typeId: BlockType.stoneWall,
61
state: null,
62
config: null
63
};
64
}
65
66
/** One-tile corridor through (8,8)-(9,8)-(10,8) so pathing cannot detour. */
67
function placeGatedCorridor (worker)
68
{
69
for (let x = 7; x <= 11; x++)
70
{
71
placeWall(worker, x, 7);
72
placeWall(worker, x, 9);
73
}
74
placeWall(worker, 7, 8);
75
placeWall(worker, 11, 8);
76
}
77
54
78
function doorAt (worker, tileX, tileY)
55
79
{
56
80
const data = worker.world.chunkData(Math.floor(tileX / 16), Math.floor(tileY / 16));
@@ -291,6 +315,7 @@ test("gated doors stay impassable for players who fail requirements even when he
291
315
placeDoor(worker, 9, 8, "pine-s-closed", gate);
292
316
293
317
assert.equal(worker.world.walkableFor(entityId, 9, 8), false);
318
assert.equal(worker.world.pathWalkableFor(entityId, 9, 8), true);
294
319
assert.equal(maybeOpenDoorOnApproach(worker.world, entityId, 9, 8), null);
295
320
296
321
/** Another player holds the door open — still blocked for the gated character. */
@@ -299,17 +324,19 @@ test("gated doors stay impassable for players who fail requirements even when he
299
324
restingState: "pine-s-closed"
300
325
});
301
326
assert.equal(worker.world.walkableFor(entityId, 9, 8), false);
327
assert.equal(worker.world.pathWalkableFor(entityId, 9, 8), true);
302
328
303
329
const bag = harness.simulation.bagOf(entityId);
304
330
bag.inventory[0] = { itemId: ItemId.bones, quantity: 1 };
305
331
harness.simulation.applyBag(entityId, bag);
306
332
assert.equal(worker.world.walkableFor(entityId, 9, 8), true);
333
assert.equal(worker.world.pathWalkableFor(entityId, 9, 8), true);
307
334
}
308
335
finally
309
336
{ harness.close(); }
310
337
});
311
338
312
test("walking into a gated door emits a blocked toast", () =>
339
test("walking into a gated door emits a blocked toast and shove", () =>
313
340
{
314
341
const harness = makeSimulation({ workerCount: 1 });
315
342
try
@@ -322,24 +349,73 @@ test("walking into a gated door emits a blocked toast", () =>
322
349
when: { all: [{ condition: { kind: ConditionKind.hasItem, itemId: ItemId.bones, quantity: 1 } }] },
323
350
blockedMessage: "Members only."
324
351
});
352
placeGatedCorridor(worker);
325
353
placeDoor(worker, 9, 8, "pine-s-closed", gate);
326
354
355
harness.simulation.enqueue(1, {
356
type: "move-to",
357
characterId: character.character_id,
358
tileX: 10,
359
tileY: 8
360
});
361
harness.simulation.step();
327
362
const handle = worker.world.ecs.handleOf(entityId);
328
const path = worker.world.ecs.get(handle, Component.path);
329
path.tiles = [{ x: 9, y: 8 }, { x: 10, y: 8 }];
363
const planned = worker.world.ecs.get(handle, Component.path);
364
assert.ok(planned.tiles.some((t) => t.x === 9 && t.y === 8), "soft-path includes gated door");
330
365
331
366
let toast = null;
332
for (let i = 0; i < walkTicks(2); i++)
367
let shove = null;
368
for (let i = 0; i < walkTicks(4); i++)
333
369
{
334
370
harness.advance(50);
335
371
const result = harness.simulation.step();
336
372
toast ??= (result.events ?? []).find((e) => e.type === "toast" && e.message === "Members only.");
373
shove ??= (result.events ?? []).find((e) => e.type === "tile-shove" && e.tileX === 9 && e.tileY === 8);
337
374
}
338
375
assert.ok(toast);
339
376
assert.equal(toast.characterId, character.character_id);
377
assert.ok(shove);
378
assert.equal(shove.attackerId, entityId);
340
379
const position = worker.world.ecs.get(handle, Component.position);
341
380
assert.equal(position.tileX, 8);
342
381
assert.equal(position.tileY, 8);
382
assert.deepEqual(planned.tiles, []);
383
}
384
finally
385
{ harness.close(); }
386
});
387
388
test("gated door path cost prefers an open detour when available", () =>
389
{
390
const harness = makeSimulation({ workerCount: 1 });
391
try
392
{
393
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
394
const entityId = harness.simulation.spawnCharacter(1, character);
395
harness.simulation.step();
396
const worker = workerOf(harness.simulation, entityId);
397
placeDoor(worker, 9, 8, "pine-s-closed", normalizeDoorConfig({
398
when: { all: [{ condition: { kind: ConditionKind.hasItem, itemId: ItemId.bones, quantity: 1 } }] },
399
blockedMessage: "Members only."
400
}));
401
402
harness.simulation.enqueue(1, {
403
type: "move-to",
404
characterId: character.character_id,
405
tileX: 10,
406
tileY: 8
407
});
408
harness.simulation.step();
409
const handle = worker.world.ecs.handleOf(entityId);
410
const path = worker.world.ecs.get(handle, Component.path);
411
assert.ok(path.tiles.length > 0);
412
assert.equal(
413
path.tiles.some((t) => t.x === 9 && t.y === 8),
414
false,
415
"should detour around gated door when cheaper"
416
);
417
assert.equal(path.tiles[path.tiles.length - 1].x, 10);
418
assert.equal(path.tiles[path.tiles.length - 1].y, 8);
343
419
}
344
420
finally
345
421
{ harness.close(); }
@@ -51,6 +51,30 @@ function placeDoor (worker, tileX, tileY, state, config = null)51
};51
};52
}52
}53
53
54
function placeWall (worker, tileX, tileY)55
{56
const data = worker.world.chunkData(Math.floor(tileX / 16), Math.floor(tileY / 16));57
const localX = ((tileX % 16) + 16) % 16;58
const localY = ((tileY % 16) + 16) % 16;59
data.blocks[localY * 16 + localX] = {60
typeId: BlockType.stoneWall,61
state: null,62
config: null63
};64
}65
66
/** One-tile corridor through (8,8)-(9,8)-(10,8) so pathing cannot detour. */67
function placeGatedCorridor (worker)68
{69
for (let x = 7; x <= 11; x++)70
{71
placeWall(worker, x, 7);72
placeWall(worker, x, 9);73
}74
placeWall(worker, 7, 8);75
placeWall(worker, 11, 8);76
}77
54
function doorAt (worker, tileX, tileY)78
function doorAt (worker, tileX, tileY)55
{79
{56
const data = worker.world.chunkData(Math.floor(tileX / 16), Math.floor(tileY / 16));80
const data = worker.world.chunkData(Math.floor(tileX / 16), Math.floor(tileY / 16));@@ -291,6 +315,7 @@ test("gated doors stay impassable for players who fail requirements even when he291
placeDoor(worker, 9, 8, "pine-s-closed", gate);315
placeDoor(worker, 9, 8, "pine-s-closed", gate);292
316
293
assert.equal(worker.world.walkableFor(entityId, 9, 8), false);317
assert.equal(worker.world.walkableFor(entityId, 9, 8), false);318
assert.equal(worker.world.pathWalkableFor(entityId, 9, 8), true);294
assert.equal(maybeOpenDoorOnApproach(worker.world, entityId, 9, 8), null);319
assert.equal(maybeOpenDoorOnApproach(worker.world, entityId, 9, 8), null);295
320
296
/** Another player holds the door open — still blocked for the gated character. */321
/** Another player holds the door open — still blocked for the gated character. */@@ -299,17 +324,19 @@ test("gated doors stay impassable for players who fail requirements even when he299
restingState: "pine-s-closed"324
restingState: "pine-s-closed"300
});325
});301
assert.equal(worker.world.walkableFor(entityId, 9, 8), false);326
assert.equal(worker.world.walkableFor(entityId, 9, 8), false);327
assert.equal(worker.world.pathWalkableFor(entityId, 9, 8), true);302
328
303
const bag = harness.simulation.bagOf(entityId);329
const bag = harness.simulation.bagOf(entityId);304
bag.inventory[0] = { itemId: ItemId.bones, quantity: 1 };330
bag.inventory[0] = { itemId: ItemId.bones, quantity: 1 };305
harness.simulation.applyBag(entityId, bag);331
harness.simulation.applyBag(entityId, bag);306
assert.equal(worker.world.walkableFor(entityId, 9, 8), true);332
assert.equal(worker.world.walkableFor(entityId, 9, 8), true);333
assert.equal(worker.world.pathWalkableFor(entityId, 9, 8), true);307
}334
}308
finally335
finally309
{ harness.close(); }336
{ harness.close(); }310
});337
});311
338
312
test("walking into a gated door emits a blocked toast", () =>339
test("walking into a gated door emits a blocked toast and shove", () =>313
{340
{314
const harness = makeSimulation({ workerCount: 1 });341
const harness = makeSimulation({ workerCount: 1 });315
try342
try@@ -322,24 +349,73 @@ test("walking into a gated door emits a blocked toast", () =>322
when: { all: [{ condition: { kind: ConditionKind.hasItem, itemId: ItemId.bones, quantity: 1 } }] },349
when: { all: [{ condition: { kind: ConditionKind.hasItem, itemId: ItemId.bones, quantity: 1 } }] },323
blockedMessage: "Members only."350
blockedMessage: "Members only."324
});351
});352
placeGatedCorridor(worker);325
placeDoor(worker, 9, 8, "pine-s-closed", gate);353
placeDoor(worker, 9, 8, "pine-s-closed", gate);326
354
355
harness.simulation.enqueue(1, {356
type: "move-to",357
characterId: character.character_id,358
tileX: 10,359
tileY: 8360
});361
harness.simulation.step();327
const handle = worker.world.ecs.handleOf(entityId);362
const handle = worker.world.ecs.handleOf(entityId);328
const path = worker.world.ecs.get(handle, Component.path);363
const planned = worker.world.ecs.get(handle, Component.path);329
path.tiles = [{ x: 9, y: 8 }, { x: 10, y: 8 }];364
assert.ok(planned.tiles.some((t) => t.x === 9 && t.y === 8), "soft-path includes gated door");330
365
331
let toast = null;366
let toast = null;332
for (let i = 0; i < walkTicks(2); i++)367
let shove = null;368
for (let i = 0; i < walkTicks(4); i++)333
{369
{334
harness.advance(50);370
harness.advance(50);335
const result = harness.simulation.step();371
const result = harness.simulation.step();336
toast ??= (result.events ?? []).find((e) => e.type === "toast" && e.message === "Members only.");372
toast ??= (result.events ?? []).find((e) => e.type === "toast" && e.message === "Members only.");373
shove ??= (result.events ?? []).find((e) => e.type === "tile-shove" && e.tileX === 9 && e.tileY === 8);337
}374
}338
assert.ok(toast);375
assert.ok(toast);339
assert.equal(toast.characterId, character.character_id);376
assert.equal(toast.characterId, character.character_id);377
assert.ok(shove);378
assert.equal(shove.attackerId, entityId);340
const position = worker.world.ecs.get(handle, Component.position);379
const position = worker.world.ecs.get(handle, Component.position);341
assert.equal(position.tileX, 8);380
assert.equal(position.tileX, 8);342
assert.equal(position.tileY, 8);381
assert.equal(position.tileY, 8);382
assert.deepEqual(planned.tiles, []);383
}384
finally385
{ harness.close(); }386
});387
388
test("gated door path cost prefers an open detour when available", () =>389
{390
const harness = makeSimulation({ workerCount: 1 });391
try392
{393
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });394
const entityId = harness.simulation.spawnCharacter(1, character);395
harness.simulation.step();396
const worker = workerOf(harness.simulation, entityId);397
placeDoor(worker, 9, 8, "pine-s-closed", normalizeDoorConfig({398
when: { all: [{ condition: { kind: ConditionKind.hasItem, itemId: ItemId.bones, quantity: 1 } }] },399
blockedMessage: "Members only."400
}));401
402
harness.simulation.enqueue(1, {403
type: "move-to",404
characterId: character.character_id,405
tileX: 10,406
tileY: 8407
});408
harness.simulation.step();409
const handle = worker.world.ecs.handleOf(entityId);410
const path = worker.world.ecs.get(handle, Component.path);411
assert.ok(path.tiles.length > 0);412
assert.equal(413
path.tiles.some((t) => t.x === 9 && t.y === 8),414
false,415
"should detour around gated door when cheaper"416
);417
assert.equal(path.tiles[path.tiles.length - 1].x, 10);418
assert.equal(path.tiles[path.tiles.length - 1].y, 8);343
}419
}344
finally420
finally345
{ harness.close(); }421
{ harness.close(); }