| 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.40; |
| 9 | |
| 10 | /** |
| 11 | * How long an entity must remain on a tile before pathfinding treats it as soft-occupied. |
| 12 | */ |
| 13 | export const SOFT_OCCUPIED_DWELL_MS = 10_000; |
| 14 | |
| 15 | /** |
| 16 | * Extra A* cost for stepping onto a soft-occupied tile. |
| 17 | * Slightly weaker than the path preference (1 − PATH_GROUND_STEP_COST). |
| 18 | */ |
| 19 | export const SOFT_OCCUPIED_STEP_PENALTY = 0.45; |
| 20 | |
| 21 | export function isPathGround (typeId) |
| 22 | { |
| 23 | return typeId === GroundType.path || !!groundDefinition(typeId)?.pathSurface; |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * @param {number} typeId |
| 28 | * @param {{ preferPaths?: boolean, softOccupied?: boolean }} [options] |
| 29 | */ |
| 30 | export function stepCostForGround (typeId, { preferPaths = false, softOccupied = false } = {}) |
| 31 | { |
| 32 | let cost = preferPaths && isPathGround(typeId) ? PATH_GROUND_STEP_COST : 1; |
| 33 | if (softOccupied) |
| 34 | { cost += SOFT_OCCUPIED_STEP_PENALTY; } |
| 35 | return cost; |
| 36 | } |