ExPilot.Map (ExPilot v0.1.1)

Copy Markdown View Source

A classic XPilot map read for play: the block legend, the features on it, and the options ExPilot honours.

{:ok, arena} = ExPilot.Map.parse_file("priv/maps/dogfight.map.gz")
ExPilot.Map.grid(arena).({12, 7})
ExPilot.Map.bases(arena)
ExPilot.Map.option(arena, :gravity)

Block legend

chartile
space, .open
xwall
q s a whalf walls filling the bottom-right, bottom-left, top-right and top-left corners
#fuel station
_, 09base, team bases
r d f ccannons facing up, left, down and right
@ ( )wormhole, wormhole in, wormhole out
+ - > <gravity attracting, repelling, clockwise, anticlockwise
i m k jgravity pulling up, down, right, left
*treasure
!target
b h g y tdecoration, drawn as walls but not collided with
AZrace checkpoints, in order

Anything else is open space.

Options

option/2 reads edgewrap, teamplay, teamimmunity, gravity, gravityangle, gravitypoint, gravitypointsource, friction, shotspeed, shotlife, maxrobots, maxplayershots, limitedlives, worldlives, mapname, mapauthor, maxunshieldedwallbouncespeed and maxshieldedwallbouncespeed (in XPilot's units per frame), wallbouncefueldrainmult, racemode, racelaps, targets, itemprobmult, maxitemdensity, every item…prob, initialfuel and every initial… item count, allowshields, shotswallbounce, shotsgravity, allowplayerkilling (playerkillings), allowplayercrashes, allowplayerbounces, playerwallbouncebrakefactor, targetkillteam, treasurekillteam, dropitemonkillprob, laserisstungun, minefusetime and firerepeatrate (frames), shieldeditempickup, shieldedmining, ballswallbounce, checkpointradius and playersonradar, with XPilot's defaults where the map is silent — except the unshielded bounce speed, whose default here is 3.5 units per frame so that a ship at cruising speed still crashes, the bounce brake factor (0.5) and the fire rate (4 frames).

gravity_point/1 is the gravitypoint option as a point.

Summary

Functions

The art name a tile is drawn with, or nil for open space.

Bases, each %{pos: {x, y}, team: team | nil, dir: dir}, in map order.

Cannons, each %{pos: {x, y}, facing: :up | :down | :left | :right}.

Race checkpoints in order.

Fuel station tiles.

The gravitypoint option, "x,y" in blocks, as the centre of that block.

Gravity points, each %{pos: {x, y}, kind: kind} with the kinds the legend lists.

The collision grid as Cauldron2D.Collision reads it.

What the legend makes of one character; nil for open space.

The map's name from its header.

An option ExPilot honours, converted, with XPilot's default when the map is silent.

Parse map text (edgewrap wraps it); {:error, reason} as Cauldron2D.Map.parse/2 gives it.

Read and parse a map file, gzipped or not.

The map's size in tiles.

Where the targets are.

The tile at point, wrapped when the map wraps; nil for open space.

Treasure tiles.

Wormholes, each %{pos: {x, y}, kind: :normal | :in | :out}.

Whether the map wraps at its edges.

Types

feature()

@type feature() ::
  %{pos: point(), kind: atom()}
  | %{pos: point(), team: integer() | nil}
  | %{pos: point(), facing: atom()}

point()

@type point() :: {integer(), integer()}

t()

@type t() :: %ExPilot.Map{
  features: map(),
  map: Cauldron2D.Map.t(),
  tiles: %{required(point()) => atom() | {atom(), term()}}
}

Functions

art(arena, point)

@spec art(t(), point()) :: atom() | nil

The art name a tile is drawn with, or nil for open space.

bases(map)

@spec bases(t()) :: [
  %{pos: point(), team: integer() | nil, dir: :up | :down | :left | :right}
]

Bases, each %{pos: {x, y}, team: team | nil, dir: dir}, in map order.

dir is the way a ship on the base faces: away from the wall it sits on — :up over a floor, :down under a ceiling, :right off a wall on its left, :left off one on its right — and :up with no wall touching it.

cannons(map)

@spec cannons(t()) :: [%{pos: point(), facing: atom()}]

Cannons, each %{pos: {x, y}, facing: :up | :down | :left | :right}.

checkpoints(map)

@spec checkpoints(t()) :: [point()]

Race checkpoints in order.

fuel(map)

@spec fuel(t()) :: [point()]

Fuel station tiles.

gravity_point(arena)

@spec gravity_point(t()) :: {float(), float()}

The gravitypoint option, "x,y" in blocks, as the centre of that block.

gravity_points(map)

@spec gravity_points(t()) :: [%{pos: point(), kind: atom()}]

Gravity points, each %{pos: {x, y}, kind: kind} with the kinds the legend lists.

grid(map)

@spec grid(t()) :: Cauldron2D.Collision.grid()

The collision grid as Cauldron2D.Collision reads it.

Walls and half walls are solid; everything else is open. Outside a map that does not wrap is solid; a wrapping map reads the tile on the other side.

legend(digit)

@spec legend(String.t()) :: atom() | {atom(), term()} | nil

What the legend makes of one character; nil for open space.

name(arena)

@spec name(t()) :: String.t()

The map's name from its header.

option(map, name)

@spec option(t(), atom()) :: term()

An option ExPilot honours, converted, with XPilot's default when the map is silent.

parse(text)

@spec parse(String.t()) :: {:ok, t()} | {:error, term()}

Parse map text (edgewrap wraps it); {:error, reason} as Cauldron2D.Map.parse/2 gives it.

parse_file(path)

@spec parse_file(Path.t()) :: {:ok, t()} | {:error, term()}

Read and parse a map file, gzipped or not.

size(map)

@spec size(t()) :: {pos_integer(), pos_integer()}

The map's size in tiles.

targets(map)

@spec targets(t()) :: [point()]

Where the targets are.

tile(map, arg)

@spec tile(t(), point()) :: atom() | {atom(), term()} | nil

The tile at point, wrapped when the map wraps; nil for open space.

treasures(map)

@spec treasures(t()) :: [point()]

Treasure tiles.

wormholes(map)

@spec wormholes(t()) :: [%{pos: point(), kind: atom()}]

Wormholes, each %{pos: {x, y}, kind: :normal | :in | :out}.

wrap?(map)

@spec wrap?(t()) :: boolean()

Whether the map wraps at its edges.