| 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 | /** |
| 22 | * Extra A* cost for pathing through a requirement door the mover cannot pass. |
| 23 | * High enough that a moderate detour is preferred, but still reachable when |
| 24 | * the gated door is the only route (soft-path, then block on enter). |
| 25 | */ |
| 26 | export const DOOR_REQUIREMENT_FAIL_STEP_COST = 32; |
| 27 | |
| 28 | export function isPathGround (typeId) |
| 29 | { |
| 30 | return typeId === GroundType.path || !!groundDefinition(typeId)?.pathSurface; |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * @param {number} typeId |
| 35 | * @param {{ preferPaths?: boolean, softOccupied?: boolean }} [options] |
| 36 | */ |
| 37 | export function stepCostForGround (typeId, { preferPaths = false, softOccupied = false } = {}) |
| 38 | { |
| 39 | let cost = preferPaths && isPathGround(typeId) ? PATH_GROUND_STEP_COST : 1; |
| 40 | if (softOccupied) |
| 41 | { cost += SOFT_OCCUPIED_STEP_PENALTY; } |
| 42 | return cost; |
| 43 | } |