Ways across a tile grid of any size, for bodies that move through the open tiles.
coarse = Cauldron2D.Grid.Coarse.new(grid, {width, height}, wrap?: true)
{:ok, path} = Cauldron2D.Grid.Coarse.find(coarse, me.pos, enemy.pos)
goal = Cauldron2D.Grid.Coarse.waypoint(grid, me.pos, path, radius)grid is the function Cauldron2D.Collision takes, a tile coordinate to :open,
:solid or a half tile; a tile is open when it reads :open. new/3 cuts the grid
into blocks of :block tiles a side (default 8) and joins the open tiles of each
block that touch edge to edge into regions (Cauldron2D.Grid.Coarse.Regions). find/4
searches the regions for the order to cross them, then the tiles of the first few for
the steps, so a search costs what the regions crossed cost, whatever the grid's size,
and finds a way whenever there is one.
A step goes to one of the eight tiles around, diagonally only where both tiles beside the corner are open, and crossing a tile beside one that is not open costs three times as much as crossing one in the open, so ways keep off walls where there is room.
A point on a tile that is not open — in the open half of a half tile — starts from, or is sought at, the open tile around it nearest the point.
On a wrapping grid a path runs on across the edges instead of jumping back: each
point is placed nearest the one before it, the first nearest from, so points may lie
off the grid. Cauldron2D.Grid.Coarse.Space.near/3 places any position nearest
another the same way.
Summary
Functions
The way from from to to as the points to pass, as the module documentation places
them, ending at to itself when it lies within the regions searched; {:ok, [to]} when
both are on one tile. :none when either is on no open tile or no way joins them.
The regions of grid, size tiles across and down; options :block, tiles to a block side (default 8), and :wrap? (default false).
Whether any way joins from and to, each on an open tile or beside one.
A point in the middle of every region, one a region: places spread over all the open parts of the grid.
The point of path to make for from from: of its first 16, the last a body of
radius reaches in a clear straight line from from with every one before it reached
the same way, else the first.
Types
@type t() :: %Cauldron2D.Grid.Coarse{ block: pos_integer(), components: tuple(), height: pos_integer(), labels: binary(), links: tuple(), spots: tuple(), width: pos_integer(), wrap?: boolean() }
Functions
The way from from to to as the points to pass, as the module documentation places
them, ending at to itself when it lies within the regions searched; {:ok, [to]} when
both are on one tile. :none when either is on no open tile or no way joins them.
Option :ahead: how many regions past the one from is in the steps run through
(default 3). A way crossing more ends where the last of them meets the next.
@spec new(Cauldron2D.Collision.grid(), {pos_integer(), pos_integer()}, keyword()) :: t()
The regions of grid, size tiles across and down; options :block, tiles to a block side (default 8), and :wrap? (default false).
Whether any way joins from and to, each on an open tile or beside one.
A point in the middle of every region, one a region: places spread over all the open parts of the grid.
@spec waypoint(Cauldron2D.Collision.grid(), point(), [point(), ...], number()) :: point()
The point of path to make for from from: of its first 16, the last a body of
radius reaches in a clear straight line from from with every one before it reached
the same way, else the first.