Skip to content

GridWalls

namespace Griff.Scenes;
public sealed class GridWalls

Where a grid mover can’t go, gathered once so a search can ask about many cells: off its map (when it has to stay on), solid tiles on any tilemap, solid colliders over a cell’s middle, a solid conveyor’s belts (not its crossings), and the cells other grid movers are in or heading into. Layers either side passes through don’t count. FindWay searches it for the shortest way somewhere.

public GridCells Grid { get; }

The cells it’s about.

public ValueTuple<int, int>? Size { get; }

The width and height of its map in cells (its widest layer), or null with no map.

public List<ValueTuple<int, int>>? FindWay(ValueTuple<int, int> start, ValueTuple<int, int>[] goals, bool diagonal, bool avoidMovers, IReadOnlySet<ValueTuple<int, int>>? avoid = null)

A* over cells from start to the nearest of goals: the cells to step into after the start, ending at the goal it reaches; empty if the start is one; null if none can be reached. It never goes through walls or avoid’s cells, nor, with avoidMovers, other grid movers (but into a goal, whoever stands there). Four ways, or eight with diagonal (never cutting a corner); six on a hex map.

public static GridWalls Gather(Scene scene, GridMovement m, GridCells grid, Entity? except = null)

Gathers where m can’t go on grid in scene (only solid colliders on its BlockingLayers, if it has any), leaving out the mover except (the one searching).

public bool IsFree(ValueTuple<int, int> cell)

True if nothing blocks a cell: no wall and no grid mover in it or heading into it.

public bool IsWall(ValueTuple<int, int> cell)

Off the map it has to stay on, a solid tile, or under a solid collider.

public Entity? MoverIn(ValueTuple<int, int> cell)

The grid mover in a cell, or heading into it.

public const int SearchLimit

The most cells a search for a way looks at before it gives up.

public const int SearchMargin

How far past the ends a search for a way goes with no map to keep it in, in cells.