Reachability

Group
scene
Methods
18
Fields
None

Getting one

scene:reachability()
scene:reachabilityFrom(…)

Methods

MethodReturnsDescription
tilesWithinCost(number){ WorldPoint }Every tile within a step budget of the local player.
reachable(WorldPoint)booleanWhether a tile can be walked to from where the player stands.
source()WorldPointThe tile the flood was run from.
pathLength(WorldPoint)number?Step cost to a tile.
pathTo(WorldPoint){ WorldPoint }The full walk to a tile.
tilesAtCost(number){ WorldPoint }Every tile at EXACTLY this step cost -- the ring. tilesWithinCost is the disc.
reachableAdjacentTiles(WorldArea){ WorldPoint }Every reachable tile touching an area -- the tiles to stand on to use it.
pathToArea(WorldArea){ WorldPoint }The walk to a tile that fronts an area.
pathLengthToArea(WorldArea)number?Step cost to the nearest tile that fronts an area.
reachableTileWithinRange(WorldArea, number, boolean)WorldPoint?A tile to stand on to attack an area from within a range.
frontsArea(WorldPoint, WorldArea)booleanWhether a tile is one of reachableAdjacentTiles(area): the flood reached it, and it touches the area across no wall. Standing there is en…
seesArea(WorldPoint, WorldArea)booleanWhether a tile has a clear line of sight to an area.
canStep(WorldPoint, WorldPoint)booleanWhether one step between adjacent tiles is legal.
hasLineOfSight(WorldPoint, WorldPoint)booleanWhether one tile can see another.
pathToward(WorldPoint){ WorldPoint }The walk toward a tile: the path to it, or when it cannot be reached the path to the closest tile the flood did reach. pathTo is the one…
reachabilityMap(){ ReachedTile }The whole flood: every reached tile, its step cost, and the tile it was stepped from.
cameFrom(WorldPoint)WorldPoint?The tile stepped from to reach one tile, for walking a path back without holding the whole map.
tilesInSight(WorldPoint, number){ WorldPoint }Every tile within a radius that an origin can see.

Returned by

MethodReturnsDescription
SceneDomain.reachabilityReachability?Reachability flood from the local player: where you can GET.
SceneDomain.reachabilityFromReachability?The same flood seeded somewhere other than the local player -- "could I reach that from over there", which is what a route or a safespot ch…

Method details

source

source: (Reachability) -> WorldPoint

The tile the flood was run from.

A handle outlives the call that made it, and reachabilityFrom can seed one somewhere other than the player, so "reachable from where?" is not answerable without this.

tilesAtCost

tilesAtCost: (Reachability, number) -> { WorldPoint }

Every tile at EXACTLY this step cost -- the ring. tilesWithinCost is the disc.

cost
The step cost to match.

pathLengthToArea

pathLengthToArea: (Reachability, WorldArea) -> number?

Step cost to the nearest tile that fronts an area.

area
The area to measure to.
Returns
nil when nothing fronting it can be reached.

reachableTileWithinRange

reachableTileWithinRange: (Reachability, WorldArea, number, boolean) -> WorldPoint?

A tile to stand on to attack an area from within a range.

area
The target's footprint.
range
How far away, in tiles.
requireLineOfSight
Whether the line of sight must be clear.
Returns
nil when no such tile is reachable.

frontsArea

frontsArea: (Reachability, WorldPoint, WorldArea) -> boolean

Whether a tile is one of reachableAdjacentTiles(area): the flood reached it, and it touches the area across no wall. Standing there is enough to act on the area, with no line of sight asked; seesArea is the other way to act on one.

from
The tile to stand on.
area
The target's footprint.

pathToward

pathToward: (Reachability, WorldPoint) -> { WorldPoint }

The walk toward a tile: the path to it, or when it cannot be reached the path to the closest tile the flood did reach. pathTo is the one that answers empty instead.

local path = scene:reachability():pathToward(tile)
local stop = path[#path]
tile
The destination.
Returns
An empty array off the flood's plane, or with nothing reached.

reachabilityMap

reachabilityMap: (Reachability) -> { ReachedTile }

The whole flood: every reached tile, its step cost, and the tile it was stepped from.

This is what a reachability map is -- costs and came-froms from the source. Cost and came-from are what the flood computes, and what a caller cannot recover afterwards without searching again.

One call, because the alternative is a pathLength and a cameFrom per tile and a scene flood is thousands of them.

cameFrom

cameFrom: (Reachability, WorldPoint) -> WorldPoint?

The tile stepped from to reach one tile, for walking a path back without holding the whole map.

tile
Where to.
Returns
nil at the source, or when the tile is unreachable.