BlueGit

timfa questward

Files

questward / shared / navigation / pathGround.js

pathGround.js

path bias
timfa Tim Falken · pushed by timfa · 2 months ago
b4e0ef6a History
pathGround.js 668 B Download Raw
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.10;
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}