BlueGit

timfa questward

Add path ground with soft blend, half run stamina, and mild A* bias.

Outdoor blendable path tiles cost half stamina while running and are slightly preferred by out-of-combat pathfinding so characters tend to stay on the road.

timfa Tim Falken · pushed by timfa

Authored 2026-08-31 · 2 months ago

Hash
5b325cbd8ea38d90d7c88290241b6c94159fa85d
Parent
52a512ea
8 files changed +128 −11
server/src/simulation/follow.js +2 −1
@@ -276,6 +276,7 @@ function queueCatchUp (world, entityId, handle, position, targetPos, path)
276 276 { return; }
277 277 }
278 278 const bounds = chunkBoundsAround(position.tileX, position.tileY, VISIBLE_CHUNK_RADIUS);
279 const inCombat = !!world.ecs.get(handle, Component.combat)?.targetEntityId;
279 280 const nextTiles = findPath(
280 281 position.tileX,
281 282 position.tileY,
@@ -292,7 +293,7 @@ function queueCatchUp (world, entityId, handle, position, targetPos, path)
292 293 bounds.minY,
293 294 bounds.maxX,
294 295 bounds.maxY,
295 { preferVertical: true }
296 world.pathfindOptions({ preferVertical: true, preferPaths: !inCombat })
296 297 );
297 298 const movement = world.ecs.get(handle, Component.movement);
298 299 if (movement)
@@ -276,6 +276,7 @@ function queueCatchUp (world, entityId, handle, position, targetPos, path)
276 { return; }
276 { return; }
277 }
277 }
278 const bounds = chunkBoundsAround(position.tileX, position.tileY, VISIBLE_CHUNK_RADIUS);
278 const bounds = chunkBoundsAround(position.tileX, position.tileY, VISIBLE_CHUNK_RADIUS);
279 const inCombat = !!world.ecs.get(handle, Component.combat)?.targetEntityId;
279 const nextTiles = findPath(
280 const nextTiles = findPath(
280 position.tileX,
281 position.tileX,
281 position.tileY,
282 position.tileY,
@@ -292,7 +293,7 @@ function queueCatchUp (world, entityId, handle, position, targetPos, path)
292 bounds.minY,
293 bounds.minY,
293 bounds.maxX,
294 bounds.maxX,
294 bounds.maxY,
295 bounds.maxY,
295 { preferVertical: true }
296 world.pathfindOptions({ preferVertical: true, preferPaths: !inCombat })
296 );
297 );
297 const movement = world.ecs.get(handle, Component.movement);
298 const movement = world.ecs.get(handle, Component.movement);
298 if (movement)
299 if (movement)
server/src/simulation/workerWorld.js +38 −4
@@ -8,7 +8,8 @@ import {
8 8 tileKey,
9 9 tileToChunk,
10 10 tileToLocal,
11 tileToRegion
11 tileToRegion,
12 tileIndex
12 13 } from "../world/coordinates.js";
13 14 import { cloneChunkData, createEmptyChunkData, isChunkTilePassable, isChunkTileClearForRangedAttacks } from "../world/chunkData.js";
14 15 import { closedNeighborEdges } from "../world/chunkFlags.js";
@@ -74,6 +75,8 @@ import {
74 75 staminaCostPerRunStep,
75 76 publicStaminaView
76 77 } from "../../../shared/stamina/rules.js";
78 import { stepCostForGround } from "../../../shared/navigation/pathGround.js";
79 import { GroundType, normalizeGround } from "../../../shared/definitions/tiles.js";
77 80 import { clearFollow, setFollow, stepFollow, recordFollowTrail, consumeFollowTrail } from "./follow.js";
78 81 import { ensureFlightComponent, stepFreeFlight } from "./freeFlight.js";
79 82 import { stepStatusEffects } from "../statusEffects/service.js";
@@ -865,7 +868,7 @@ export class WorkerWorld
865 868 bounds.minY,
866 869 bounds.maxX,
867 870 bounds.maxY,
868 { preferVertical: true }
871 this.pathfindOptions({ preferVertical: true, preferPaths: true })
869 872 );
870 873 movement.walkCarry = 0;
871 874 }
@@ -1172,7 +1175,11 @@ export class WorkerWorld
1172 1175 }
1173 1176 const skills = this.ecs.get(handle, Component.skills);
1174 1177 syncPlayerStamina(this.ecs, handle);
1175 const cost = staminaCostPerRunStep(this.settings?.walkTilesPerSecond);
1178 const position = this.ecs.get(handle, Component.position);
1179 const onPath = position
1180 ? this.groundTypeAt(position.tileX, position.tileY, position.dimensionId) === GroundType.path
1181 : false;
1182 const cost = staminaCostPerRunStep(this.settings?.walkTilesPerSecond, { onPath });
1176 1183 stamina.current = Math.max(0, (Number(stamina.current) || 0) - cost);
1177 1184 stamina.xpDebt = (Number(stamina.xpDebt) || 0) + cost;
1178 1185 let skillsChanged = false;
@@ -1499,6 +1506,8 @@ export class WorkerWorld
1499 1506 }
1500 1507 const bounds = chunkBoundsAround(position.tileX, position.tileY, VISIBLE_CHUNK_RADIUS);
1501 1508 const stuckHandle = this.ecs.handleOf(entityId);
1509 const inCombat = stuckHandle != null
1510 && this.ecs.get(stuckHandle, Component.combat)?.targetEntityId != null;
1502 1511 path.tiles = findPath(
1503 1512 position.tileX,
1504 1513 position.tileY,
@@ -1509,7 +1518,10 @@ export class WorkerWorld
1509 1518 bounds.minY,
1510 1519 bounds.maxX,
1511 1520 bounds.maxY,
1512 { preferVertical: stuckHandle != null && this.ecs.has(stuckHandle, Component.character) }
1521 this.pathfindOptions({
1522 preferVertical: stuckHandle != null && this.ecs.has(stuckHandle, Component.character),
1523 preferPaths: !inCombat
1524 })
1513 1525 );
1514 1526 path.stuckSince = now;
1515 1527 path.stuckTileX = position.tileX;
@@ -2080,6 +2092,28 @@ export class WorkerWorld
2080 2092 return this.isEnterable(tileX, tileY, dim);
2081 2093 }
2082 2094
2095 /** Ground type id at a world tile (defaults to world default ground). */
2096 groundTypeAt (tileX, tileY, dimensionId = OVERWORLD_ID)
2097 {
2098 const dim = normalizeDimensionId(dimensionId) ?? OVERWORLD_ID;
2099 const data = this.#chunkData(tileToChunk(tileX), tileToChunk(tileY), dim);
2100 const entry = normalizeGround(data.grounds[tileIndex(tileToLocal(tileX), tileToLocal(tileY))]);
2101 return entry?.typeId ?? this.settings.defaultGroundTypeId ?? GroundType.grass;
2102 }
2103
2104 /**
2105 * @param {{ preferVertical?: boolean, preferPaths?: boolean }} [options]
2106 */
2107 pathfindOptions ({ preferVertical = false, preferPaths = false } = {})
2108 {
2109 const options = { preferVertical: !!preferVertical };
2110 if (preferPaths)
2111 {
2112 options.stepCost = (x, y) => stepCostForGround(this.groundTypeAt(x, y), { preferPaths: true });
2113 }
2114 return options;
2115 }
2116
2083 2117 /**
2084 2118 * Standing tile with no other mob/player (self allowed). Used for wander goals
2085 2119 * and melee attack stance.
@@ -8,7 +8,8 @@ import {
8 tileKey,
8 tileKey,
9 tileToChunk,
9 tileToChunk,
10 tileToLocal,
10 tileToLocal,
11 tileToRegion
11 tileToRegion,
12 tileIndex
12} from "../world/coordinates.js";
13} from "../world/coordinates.js";
13import { cloneChunkData, createEmptyChunkData, isChunkTilePassable, isChunkTileClearForRangedAttacks } from "../world/chunkData.js";
14import { cloneChunkData, createEmptyChunkData, isChunkTilePassable, isChunkTileClearForRangedAttacks } from "../world/chunkData.js";
14import { closedNeighborEdges } from "../world/chunkFlags.js";
15import { closedNeighborEdges } from "../world/chunkFlags.js";
@@ -74,6 +75,8 @@ import {
74 staminaCostPerRunStep,
75 staminaCostPerRunStep,
75 publicStaminaView
76 publicStaminaView
76} from "../../../shared/stamina/rules.js";
77} from "../../../shared/stamina/rules.js";
78import { stepCostForGround } from "../../../shared/navigation/pathGround.js";
79import { GroundType, normalizeGround } from "../../../shared/definitions/tiles.js";
77import { clearFollow, setFollow, stepFollow, recordFollowTrail, consumeFollowTrail } from "./follow.js";
80import { clearFollow, setFollow, stepFollow, recordFollowTrail, consumeFollowTrail } from "./follow.js";
78import { ensureFlightComponent, stepFreeFlight } from "./freeFlight.js";
81import { ensureFlightComponent, stepFreeFlight } from "./freeFlight.js";
79import { stepStatusEffects } from "../statusEffects/service.js";
82import { stepStatusEffects } from "../statusEffects/service.js";
@@ -865,7 +868,7 @@ export class WorkerWorld
865 bounds.minY,
868 bounds.minY,
866 bounds.maxX,
869 bounds.maxX,
867 bounds.maxY,
870 bounds.maxY,
868 { preferVertical: true }
871 this.pathfindOptions({ preferVertical: true, preferPaths: true })
869 );
872 );
870 movement.walkCarry = 0;
873 movement.walkCarry = 0;
871 }
874 }
@@ -1172,7 +1175,11 @@ export class WorkerWorld
1172 }
1175 }
1173 const skills = this.ecs.get(handle, Component.skills);
1176 const skills = this.ecs.get(handle, Component.skills);
1174 syncPlayerStamina(this.ecs, handle);
1177 syncPlayerStamina(this.ecs, handle);
1175 const cost = staminaCostPerRunStep(this.settings?.walkTilesPerSecond);
1178 const position = this.ecs.get(handle, Component.position);
1179 const onPath = position
1180 ? this.groundTypeAt(position.tileX, position.tileY, position.dimensionId) === GroundType.path
1181 : false;
1182 const cost = staminaCostPerRunStep(this.settings?.walkTilesPerSecond, { onPath });
1176 stamina.current = Math.max(0, (Number(stamina.current) || 0) - cost);
1183 stamina.current = Math.max(0, (Number(stamina.current) || 0) - cost);
1177 stamina.xpDebt = (Number(stamina.xpDebt) || 0) + cost;
1184 stamina.xpDebt = (Number(stamina.xpDebt) || 0) + cost;
1178 let skillsChanged = false;
1185 let skillsChanged = false;
@@ -1499,6 +1506,8 @@ export class WorkerWorld
1499 }
1506 }
1500 const bounds = chunkBoundsAround(position.tileX, position.tileY, VISIBLE_CHUNK_RADIUS);
1507 const bounds = chunkBoundsAround(position.tileX, position.tileY, VISIBLE_CHUNK_RADIUS);
1501 const stuckHandle = this.ecs.handleOf(entityId);
1508 const stuckHandle = this.ecs.handleOf(entityId);
1509 const inCombat = stuckHandle != null
1510 && this.ecs.get(stuckHandle, Component.combat)?.targetEntityId != null;
1502 path.tiles = findPath(
1511 path.tiles = findPath(
1503 position.tileX,
1512 position.tileX,
1504 position.tileY,
1513 position.tileY,
@@ -1509,7 +1518,10 @@ export class WorkerWorld
1509 bounds.minY,
1518 bounds.minY,
1510 bounds.maxX,
1519 bounds.maxX,
1511 bounds.maxY,
1520 bounds.maxY,
1512 { preferVertical: stuckHandle != null && this.ecs.has(stuckHandle, Component.character) }
1521 this.pathfindOptions({
1522 preferVertical: stuckHandle != null && this.ecs.has(stuckHandle, Component.character),
1523 preferPaths: !inCombat
1524 })
1513 );
1525 );
1514 path.stuckSince = now;
1526 path.stuckSince = now;
1515 path.stuckTileX = position.tileX;
1527 path.stuckTileX = position.tileX;
@@ -2080,6 +2092,28 @@ export class WorkerWorld
2080 return this.isEnterable(tileX, tileY, dim);
2092 return this.isEnterable(tileX, tileY, dim);
2081 }
2093 }
2082
2094
2095 /** Ground type id at a world tile (defaults to world default ground). */
2096 groundTypeAt (tileX, tileY, dimensionId = OVERWORLD_ID)
2097 {
2098 const dim = normalizeDimensionId(dimensionId) ?? OVERWORLD_ID;
2099 const data = this.#chunkData(tileToChunk(tileX), tileToChunk(tileY), dim);
2100 const entry = normalizeGround(data.grounds[tileIndex(tileToLocal(tileX), tileToLocal(tileY))]);
2101 return entry?.typeId ?? this.settings.defaultGroundTypeId ?? GroundType.grass;
2102 }
2103
2104 /**
2105 * @param {{ preferVertical?: boolean, preferPaths?: boolean }} [options]
2106 */
2107 pathfindOptions ({ preferVertical = false, preferPaths = false } = {})
2108 {
2109 const options = { preferVertical: !!preferVertical };
2110 if (preferPaths)
2111 {
2112 options.stepCost = (x, y) => stepCostForGround(this.groundTypeAt(x, y), { preferPaths: true });
2113 }
2114 return options;
2115 }
2116
2083 /**
2117 /**
2084 * Standing tile with no other mob/player (self allowed). Used for wander goals
2118 * Standing tile with no other mob/player (self allowed). Used for wander goals
2085 * and melee attack stance.
2119 * and melee attack stance.
server/tests/astar.test.js +28 −0
@@ -1,6 +1,8 @@
1 1 import test from "node:test";
2 2 import assert from "node:assert/strict";
3 3 import { findPath, orderedCardinals } from "../src/navigation/astar.js";
4 import { PATH_GROUND_STEP_COST, stepCostForGround } from "../../shared/navigation/pathGround.js";
5 import { GroundType } from "../../shared/definitions/tiles.js";
4 6
5 7 test("A* walks around an impassable tile", () =>
6 8 {
@@ -72,3 +74,29 @@ test("A* stepCost prefers the cheaper route around an expensive corridor", () =>
72 74 assert.deepEqual(path.at(-1), { x: 2, y: 0 });
73 75 assert.ok(!path.some((step) => step.x === 1 && step.y === 0));
74 76 });
77
78 test("A* path-ground stepCost prefers a road of equal Manhattan length", () =>
79 {
80 // (0,0) → (1,1): via (1,0) path then (1,1), or via (0,1) grass then (1,1).
81 const pathTiles = new Set(["1,0"]);
82 const route = findPath(
83 0,
84 0,
85 1,
86 1,
87 () => true,
88 -2,
89 -2,
90 4,
91 4,
92 {
93 preferVertical: false,
94 stepCost: (x, y) => stepCostForGround(
95 pathTiles.has(`${x},${y}`) ? GroundType.path : GroundType.grass,
96 { preferPaths: true }
97 )
98 }
99 );
100 assert.ok(route.some((step) => step.x === 1 && step.y === 0), JSON.stringify(route));
101 assert.ok(PATH_GROUND_STEP_COST < 1);
102 });
@@ -1,6 +1,8 @@
1import test from "node:test";
1import test from "node:test";
2import assert from "node:assert/strict";
2import assert from "node:assert/strict";
3import { findPath, orderedCardinals } from "../src/navigation/astar.js";
3import { findPath, orderedCardinals } from "../src/navigation/astar.js";
4import { PATH_GROUND_STEP_COST, stepCostForGround } from "../../shared/navigation/pathGround.js";
5import { GroundType } from "../../shared/definitions/tiles.js";
4
6
5test("A* walks around an impassable tile", () =>
7test("A* walks around an impassable tile", () =>
6{
8{
@@ -72,3 +74,29 @@ test("A* stepCost prefers the cheaper route around an expensive corridor", () =>
72 assert.deepEqual(path.at(-1), { x: 2, y: 0 });
74 assert.deepEqual(path.at(-1), { x: 2, y: 0 });
73 assert.ok(!path.some((step) => step.x === 1 && step.y === 0));
75 assert.ok(!path.some((step) => step.x === 1 && step.y === 0));
74});
76});
77
78test("A* path-ground stepCost prefers a road of equal Manhattan length", () =>
79{
80 // (0,0) → (1,1): via (1,0) path then (1,1), or via (0,1) grass then (1,1).
81 const pathTiles = new Set(["1,0"]);
82 const route = findPath(
83 0,
84 0,
85 1,
86 1,
87 () => true,
88 -2,
89 -2,
90 4,
91 4,
92 {
93 preferVertical: false,
94 stepCost: (x, y) => stepCostForGround(
95 pathTiles.has(`${x},${y}`) ? GroundType.path : GroundType.grass,
96 { preferPaths: true }
97 )
98 }
99 );
100 assert.ok(route.some((step) => step.x === 1 && step.y === 0), JSON.stringify(route));
101 assert.ok(PATH_GROUND_STEP_COST < 1);
102});
server/tests/softTerrain.test.js +4 −1
@@ -14,11 +14,14 @@ import {
14 14 import { GroundType, GROUND_DEFINITIONS } from "../../shared/definitions/tiles.js";
15 15 import { normalizeGraphicsSettings, SoftTerrainMode, DEFAULT_GRAPHICS_SETTINGS } from "../../shared/graphics/settings.js";
16 16
17 test("grass and dirt are blendable outdoor grounds", () =>
17 test("grass, dirt, and path are blendable outdoor grounds", () =>
18 18 {
19 19 assert.equal(GROUND_DEFINITIONS[GroundType.grass].blendable, true);
20 20 assert.equal(GROUND_DEFINITIONS[GroundType.dirt].blendable, true);
21 21 assert.equal(GROUND_DEFINITIONS[GroundType.dirt].outdoor, true);
22 assert.equal(GROUND_DEFINITIONS[GroundType.path].blendable, true);
23 assert.equal(GROUND_DEFINITIONS[GroundType.path].outdoor, true);
24 assert.equal(GROUND_DEFINITIONS[GroundType.path].pathSurface, true);
22 25 assert.equal(GROUND_DEFINITIONS[GroundType.wood].blendable, undefined);
23 26 assert.equal(GROUND_DEFINITIONS[GroundType.water].blendable, undefined);
24 27 });
@@ -14,11 +14,14 @@ import {
14import { GroundType, GROUND_DEFINITIONS } from "../../shared/definitions/tiles.js";
14import { GroundType, GROUND_DEFINITIONS } from "../../shared/definitions/tiles.js";
15import { normalizeGraphicsSettings, SoftTerrainMode, DEFAULT_GRAPHICS_SETTINGS } from "../../shared/graphics/settings.js";
15import { normalizeGraphicsSettings, SoftTerrainMode, DEFAULT_GRAPHICS_SETTINGS } from "../../shared/graphics/settings.js";
16
16
17test("grass and dirt are blendable outdoor grounds", () =>
17test("grass, dirt, and path are blendable outdoor grounds", () =>
18{
18{
19 assert.equal(GROUND_DEFINITIONS[GroundType.grass].blendable, true);
19 assert.equal(GROUND_DEFINITIONS[GroundType.grass].blendable, true);
20 assert.equal(GROUND_DEFINITIONS[GroundType.dirt].blendable, true);
20 assert.equal(GROUND_DEFINITIONS[GroundType.dirt].blendable, true);
21 assert.equal(GROUND_DEFINITIONS[GroundType.dirt].outdoor, true);
21 assert.equal(GROUND_DEFINITIONS[GroundType.dirt].outdoor, true);
22 assert.equal(GROUND_DEFINITIONS[GroundType.path].blendable, true);
23 assert.equal(GROUND_DEFINITIONS[GroundType.path].outdoor, true);
24 assert.equal(GROUND_DEFINITIONS[GroundType.path].pathSurface, true);
22 assert.equal(GROUND_DEFINITIONS[GroundType.wood].blendable, undefined);
25 assert.equal(GROUND_DEFINITIONS[GroundType.wood].blendable, undefined);
23 assert.equal(GROUND_DEFINITIONS[GroundType.water].blendable, undefined);
26 assert.equal(GROUND_DEFINITIONS[GroundType.water].blendable, undefined);
24});
27});
server/tests/stamina.test.js +8 −1
@@ -5,7 +5,8 @@ import { SkillId, skillLevel } from "../../shared/definitions/skills.js";
5 5 import { totalXpForLevel } from "../../shared/skills/progression.js";
6 6 import {
7 7 staminaCostPerRunStep,
8 STAMINA_REGEN_PER_SECOND
8 STAMINA_REGEN_PER_SECOND,
9 PATH_RUN_STAMINA_FACTOR
9 10 } from "../../shared/stamina/rules.js";
10 11 import { makeCharacter, makeSimulation, stepTimes } from "./helpers/simulationHarness.js";
11 12
@@ -37,6 +38,12 @@ test("staminaCostPerRunStep drains one point per second of continuous running",
37 38 assert.equal(staminaCostPerRunStep(1), 0.5);
38 39 });
39 40
41 test("path tiles cost half stamina while running", () =>
42 {
43 assert.equal(staminaCostPerRunStep(2, { onPath: true }), 0.25 * PATH_RUN_STAMINA_FACTOR);
44 assert.equal(PATH_RUN_STAMINA_FACTOR, 0.5);
45 });
46
40 47 test("set-gait to run is rejected when stamina is empty", () =>
41 48 {
42 49 const harness = makeSimulation({ workerCount: 1 });
@@ -5,7 +5,8 @@ import { SkillId, skillLevel } from "../../shared/definitions/skills.js";
5import { totalXpForLevel } from "../../shared/skills/progression.js";
5import { totalXpForLevel } from "../../shared/skills/progression.js";
6import {
6import {
7 staminaCostPerRunStep,
7 staminaCostPerRunStep,
8 STAMINA_REGEN_PER_SECOND
8 STAMINA_REGEN_PER_SECOND,
9 PATH_RUN_STAMINA_FACTOR
9} from "../../shared/stamina/rules.js";
10} from "../../shared/stamina/rules.js";
10import { makeCharacter, makeSimulation, stepTimes } from "./helpers/simulationHarness.js";
11import { makeCharacter, makeSimulation, stepTimes } from "./helpers/simulationHarness.js";
11
12
@@ -37,6 +38,12 @@ test("staminaCostPerRunStep drains one point per second of continuous running",
37 assert.equal(staminaCostPerRunStep(1), 0.5);
38 assert.equal(staminaCostPerRunStep(1), 0.5);
38});
39});
39
40
41test("path tiles cost half stamina while running", () =>
42{
43 assert.equal(staminaCostPerRunStep(2, { onPath: true }), 0.25 * PATH_RUN_STAMINA_FACTOR);
44 assert.equal(PATH_RUN_STAMINA_FACTOR, 0.5);
45});
46
40test("set-gait to run is rejected when stamina is empty", () =>
47test("set-gait to run is rejected when stamina is empty", () =>
41{
48{
42 const harness = makeSimulation({ workerCount: 1 });
49 const harness = makeSimulation({ workerCount: 1 });
shared/definitions/tiles.js +17 −1
@@ -35,7 +35,8 @@ export const GroundType = Object.freeze({
35 35 wood: 2,
36 36 water: 3,
37 37 deepWater: 4,
38 dirt: 5
38 dirt: 5,
39 path: 6
39 40 });
40 41
41 42 export const BlockType = Object.freeze({
@@ -153,6 +154,21 @@ export const GROUND_DEFINITIONS = Object.freeze({
153 154 animationSpeed: 0,
154 155 outdoor: true,
155 156 blendable: true
157 }),
158 [GroundType.path]: Object.freeze({
159 id: GroundType.path,
160 key: "path",
161 displayName: "Path",
162 passable: true,
163 wades: false,
164 water: false,
165 frames: 1,
166 framesPerRow: 1,
167 animationSpeed: 0,
168 outdoor: true,
169 blendable: true,
170 /** Running here costs half stamina; A* prefers these slightly out of combat. */
171 pathSurface: true
156 172 })
157 173 });
158 174
@@ -35,7 +35,8 @@ export const GroundType = Object.freeze({
35 wood: 2,
35 wood: 2,
36 water: 3,
36 water: 3,
37 deepWater: 4,
37 deepWater: 4,
38 dirt: 5
38 dirt: 5,
39 path: 6
39});
40});
40
41
41export const BlockType = Object.freeze({
42export const BlockType = Object.freeze({
@@ -153,6 +154,21 @@ export const GROUND_DEFINITIONS = Object.freeze({
153 animationSpeed: 0,
154 animationSpeed: 0,
154 outdoor: true,
155 outdoor: true,
155 blendable: true
156 blendable: true
157 }),
158 [GroundType.path]: Object.freeze({
159 id: GroundType.path,
160 key: "path",
161 displayName: "Path",
162 passable: true,
163 wades: false,
164 water: false,
165 frames: 1,
166 framesPerRow: 1,
167 animationSpeed: 0,
168 outdoor: true,
169 blendable: true,
170 /** Running here costs half stamina; A* prefers these slightly out of combat. */
171 pathSurface: true
156 })
172 })
157});
173});
158
174
shared/navigation/pathGround.js added +24 −0
@@ -0,0 +1,24 @@
1 import { GroundType, groundDefinition } from "../definitions/tiles.js";
2
3 /**
4 * A* step cost into a path tile when preferring roads (out of combat).
5 * Slightly cheaper than grass so equal-ish routes favour the path without
6 * accepting long detours.
7 */
8 export const PATH_GROUND_STEP_COST = 0.92;
9
10 export function isPathGround (typeId)
11 {
12 return typeId === GroundType.path || !!groundDefinition(typeId)?.pathSurface;
13 }
14
15 /**
16 * @param {number} typeId
17 * @param {{ preferPaths?: boolean }} [options]
18 */
19 export function stepCostForGround (typeId, { preferPaths = false } = {})
20 {
21 if (preferPaths && isPathGround(typeId))
22 { return PATH_GROUND_STEP_COST; }
23 return 1;
24 }
@@ -0,0 +1,24 @@
1import { GroundType, groundDefinition } from "../definitions/tiles.js";
2
3/**
4 * A* step cost into a path tile when preferring roads (out of combat).
5 * Slightly cheaper than grass so equal-ish routes favour the path without
6 * accepting long detours.
7 */
8export const PATH_GROUND_STEP_COST = 0.92;
9
10export function isPathGround (typeId)
11{
12 return typeId === GroundType.path || !!groundDefinition(typeId)?.pathSurface;
13}
14
15/**
16 * @param {number} typeId
17 * @param {{ preferPaths?: boolean }} [options]
18 */
19export function stepCostForGround (typeId, { preferPaths = false } = {})
20{
21 if (preferPaths && isPathGround(typeId))
22 { return PATH_GROUND_STEP_COST; }
23 return 1;
24}
shared/stamina/rules.js +7 −3
@@ -9,12 +9,16 @@ export const STAMINA_XP_PER_POINT_SPENT = 1;
9 9 /**
10 10 * Stamina cost for one successful run tile step.
11 11 * Run steps once per movement tick; movementHz = walkTilesPerSecond * 2,
12 * so continuous running drains 1 stamina per second.
12 * so continuous running drains 1 stamina per second on normal ground.
13 * Path tiles use {@link PATH_RUN_STAMINA_FACTOR}.
13 14 */
14 export function staminaCostPerRunStep (walkTilesPerSecond = 2)
15 export const PATH_RUN_STAMINA_FACTOR = 0.5;
16
17 export function staminaCostPerRunStep (walkTilesPerSecond = 2, { onPath = false } = {})
15 18 {
16 19 const movementHz = Math.max(0.25, (Number(walkTilesPerSecond) || 2) * 2);
17 return 1 / movementHz;
20 const base = 1 / movementHz;
21 return onPath ? base * PATH_RUN_STAMINA_FACTOR : base;
18 22 }
19 23
20 24 export function clampStamina (stamina, skills)
@@ -9,12 +9,16 @@ export const STAMINA_XP_PER_POINT_SPENT = 1;
9/**
9/**
10 * Stamina cost for one successful run tile step.
10 * Stamina cost for one successful run tile step.
11 * Run steps once per movement tick; movementHz = walkTilesPerSecond * 2,
11 * Run steps once per movement tick; movementHz = walkTilesPerSecond * 2,
12 * so continuous running drains 1 stamina per second.
12 * so continuous running drains 1 stamina per second on normal ground.
13 * Path tiles use {@link PATH_RUN_STAMINA_FACTOR}.
13 */
14 */
14export function staminaCostPerRunStep (walkTilesPerSecond = 2)
15export const PATH_RUN_STAMINA_FACTOR = 0.5;
16
17export function staminaCostPerRunStep (walkTilesPerSecond = 2, { onPath = false } = {})
15{
18{
16 const movementHz = Math.max(0.25, (Number(walkTilesPerSecond) || 2) * 2);
19 const movementHz = Math.max(0.25, (Number(walkTilesPerSecond) || 2) * 2);
17 return 1 / movementHz;
20 const base = 1 / movementHz;
21 return onPath ? base * PATH_RUN_STAMINA_FACTOR : base;
18}
22}
19
23
20export function clampStamina (stamina, skills)
24export function clampStamina (stamina, skills)