Skip to content

Navigation beta ​

Interface of @v12-engine/engine

ts
export interface Navigation

Pathfinding and local avoidance. The simulation only talks to this interface, so the backing implementation can be replaced without touching game logic.

Members ​

addAgent ​

ts
addAgent(id: number, position: Vec2, params: AgentParams): void;

Puts an agent in the crowd by its id (the entity's), at a position and with its radius, speed and the like

addObstacle ​

ts
addObstacle(key: number, rect: Rect): boolean;

Something that blocks the way, a building or a shut gate. False when there is no room for another (see obstacleRoom): it is then not in the way, and never thrown over in the middle of a tick

clearDestination ​

ts
clearDestination(id: number): void;

Forgets where the agent was sent; it stops where it is

closestPoint ​

ts
closestPoint(point: Vec2, searchRadius?: number): Vec2 | null;

Closest walkable point, or null when there is none within searchRadius.

debugGeometry ​

ts
debugGeometry(): NavDebugGeometry;

Gives the navigation mesh as triangles and lines, for the debug view

dispose ​

ts
dispose(): void;

Frees the navigation and its crowd; it is not used after

findPath ​

ts
findPath(from: Vec2, to: Vec2): Vec2[] | null;

Finds a path between two points over walkable space, as a list of corners; null when there is none

groundChanged ​

ts
groundChanged?(cells: readonly number[], walkability?: boolean): void;

A layer of cells that slows one on foot changed on these cells (World.setCells): what a path weighs there is made again (EN2), as a navigation cut now of the ground as it is would weigh it, so a world loaded from a save made after plays out the same. walkability: the change may have made cells walkable or not (a layer with a thicket among its values, FoliageStyleDef.walkable), which the ways keep their distance from beyond the cells' own part of the navigation. Nothing where a navigation weighs no ground

hasAgent ​

ts
hasAgent(id: number): boolean;

Whether an agent by this id is in the crowd

holdObstacles ​

ts
holdObstacles?(hold: boolean): void;

Many obstacles are put down at once, as a load puts back every structure: while held (true), what they change of walkable space waits, and is made once (each piece of ground once, however many obstacles are on it) when let go (false) or at the first thing asked of the navigation before that. What comes out is the same as putting them down one by one; only the work is less. Nothing where a navigation has nothing to hold

obstacleRoom ​

ts
obstacleRoom(): number;

How many more obstacles there is room for: what placing a building is refused over, before it is placed

readAgent ​

ts
readAgent(id: number, out: AgentState): boolean;

Writes the agent's position, velocity and next corners into out; returns false when there is no such agent

removeAgent ​

ts
removeAgent(id: number): void;

Takes the agent out of the crowd

removeObstacle ​

ts
removeObstacle(key: number): void;

Takes the obstacle with this key out of the way, opening the ground it covered

reseat ​

ts
reseat(agents: readonly (readonly [id: number, save: AgentSave])[]): void;

Puts the agents back as loading a save puts them (determinism D2): those given and no others, in that order, each as restoreAgent puts it, on a crowd made anew. A save does this to the world it is taken of, so the game that was saved and the game loaded from it go on from the same crowd, to the last bit

reshape ​

ts
reshape?(area?: CellArea): boolean;

The ground it is a navigation of was reshaped (World.reshapeGround): cut again from it as it is now, what is in the way and every agent kept as they were. Told the part that changed (area), it may cut again only what that part reaches. False where it will not be (a navigation of no ground); one that cannot be cut of the ground as it is now is left as it was. A navigation may do it, and groundChanged, later than asked, all together, as long as nothing asked of it before then sees the ground as it was (settleGround)

restoreAgent ​

ts
restoreAgent(id: number, save: AgentSave): void;

Puts an agent back as it was saved. As close as it gets: the path it follows is looked for again, so what it does next can differ a little from what the agent that was saved would have done

sameCrowd ​

ts
sameCrowd?(a: number, b: number): boolean;

Whether two agents are in each other's way: on the same crowd, so that each steers around the other and neither walks through. Agents of different layers (ground, air, water) are not; those of different sizes where the ground is cut for several are (SizedNavigation). Taken as yes where a navigation does not say

saveAgent ​

ts
saveAgent(id: number): AgentSave | undefined;

What a save needs of an agent, or undefined when there is none of that id

setAnchored ​

ts
setAnchored(id: number, anchored: boolean): void;

Anchored agents hold their ground: others have to walk around them instead of shoving them away.

setDestination ​

ts
setDestination(id: number, target: Vec2): boolean;

Path towards target. The target is snapped to walkable space; returns false when nothing walkable is near it.

setGhost ​

ts
setGhost(id: number, ghost: boolean): void;

Ghost agents ignore other agents (used by workers hauling resources).

setPhasing ​

ts
setPhasing?(id: number, phasing: boolean): void;

An agent that phases walks through every other agent and every other through it: neither steers round nor pushes the other (BuffDef.phasing). What blocks the ground (walls, cliffs, obstacles) still stops it. A navigation without it has the agent a ghost instead (setGhost), which others may still push aside

setSpeed ​

ts
setSpeed(id: number, speed: number): void;

Changes how fast the agent goes, in cells per second

settle ​

ts
settle(version: number): void;

After a load: brings walkable space up to date with the obstacles put back, and takes on the version it had

settleGround ​

ts
settleGround?(): void;

Does now what the ground's changes asked of it and it has not done yet (groundChanged, reshape): the world asks it as each tick ends, so that a tick's changes of the ground are done together, once, and none is left over for after the tick (a save, a screen). Nothing where a navigation does them at once

teleport ​

ts
teleport(id: number, position: Vec2): void;

Moves the agent to the position at once, without a walk

update ​

ts
update(dt: number): void;

Steps the crowd by dt seconds: agents follow their paths and steer around each other

version ​

ts
readonly version: number;

Bumped whenever walkable space changes (obstacles added or removed)