import { GroundType, groundDefinition } from "../definitions/tiles.js";

/**
 * A* step cost into a path tile when preferring roads (out of combat).
 * Slightly cheaper than grass so equal-ish routes favour the path without
 * accepting long detours.
 */
export const PATH_GROUND_STEP_COST = 0.40;

/**
 * How long an entity must remain on a tile before pathfinding treats it as soft-occupied.
 */
export const SOFT_OCCUPIED_DWELL_MS = 10_000;

/**
 * Extra A* cost for stepping onto a soft-occupied tile.
 * Slightly weaker than the path preference (1 − PATH_GROUND_STEP_COST).
 */
export const SOFT_OCCUPIED_STEP_PENALTY = 0.45;

/**
 * Extra A* cost for pathing through a requirement door the mover cannot pass.
 * High enough that a moderate detour is preferred, but still reachable when
 * the gated door is the only route (soft-path, then block on enter).
 */
export const DOOR_REQUIREMENT_FAIL_STEP_COST = 32;

export function isPathGround (typeId)
{
	return typeId === GroundType.path || !!groundDefinition(typeId)?.pathSurface;
}

/**
 * @param {number} typeId
 * @param {{ preferPaths?: boolean, softOccupied?: boolean }} [options]
 */
export function stepCostForGround (typeId, { preferPaths = false, softOccupied = false } = {})
{
	let cost = preferPaths && isPathGround(typeId) ? PATH_GROUND_STEP_COST : 1;
	if (softOccupied)
	{ cost += SOFT_OCCUPIED_STEP_PENALTY; }
	return cost;
}
