ExPilot.Ship (ExPilot v0.1.1)

Copy Markdown View Source

One player's ship: its body, fuel, shield, lives and score, and what it is doing.

Positions are tiles; the ship turns through 64 headings. A dead ship keeps its place in the game with alive? false and a respawn_in countdown among its timers/0.

Summary

Types

Where the ship is in a race: the next checkpoint, laps done, and whether it has finished?.

t()

The ship's count: score, kills and deaths over the whole game, the round's streak of kills without dying and its best_streak, seconds of contact with an enemy and the round's best_contact, and what result/2 last recorded.

The ship's clocks, in the game's seconds: cooldown until it can fire, respawn_in while dead, the *_until times its immunity, phasing, emergency shield, emergency thrust and confusion end, and empty_since, when its tank ran dry, or nil.

Functions

Whether the ship has a life left to respawn with.

Credit a kill.

Mark the ship dead, counting the death and starting the respawn clock.

Fit the ship out with a kit: :fuel in the tank (the tank grows to hold it) and :items as counts by kind, given as ExPilot.Items.pick_up/2 gives them.

The number of headings a ship turns through.

Whether action is held.

Another dt seconds alive with an enemy in contact: the current stretch, and the round's longest.

The heading a ship faces on a base with dir.

A full tank.

A new ship for id named name, resting on its base facing the way :dir says (:up by default).

Give the ship its lives back for a new round, keeping its score; the round's streak and contact start over.

The ship's position.

A ship's radius in tiles.

Put the ship back on its base with a full tank, alive.

The ship's result since the last one was taken — kills, deaths and score gained, the round's best streak of kills without dying and longest contact in seconds — and the ship with those taken as recorded.

How hard action is held, 0.0 to 1.0: what an analog control said, 1.0 for a key.

What another player sees of this ship.

The ship with one of its timers/0 set.

Types

race()

@type race() :: %{
  checkpoint: non_neg_integer(),
  laps: non_neg_integer(),
  finished?: boolean()
}

Where the ship is in a race: the next checkpoint, laps done, and whether it has finished?.

t()

@type t() :: %ExPilot.Ship{
  aim: {number(), number()} | nil,
  alive?: boolean(),
  armour: non_neg_integer(),
  autopilot?: boolean(),
  ball: term(),
  base: {integer(), integer()},
  body: Cauldron2D.Body.t(),
  cloaked?: boolean(),
  deflecting?: boolean(),
  fuel: float(),
  held: MapSet.t(atom()),
  held_before: MapSet.t(atom()),
  id: term(),
  items: %{required(atom()) => pos_integer()},
  landed?: boolean(),
  launch_heading: non_neg_integer(),
  lives: integer() | :unlimited,
  max_fuel: float(),
  missile: :torpedo | :smart | :heat,
  name: String.t(),
  race: race(),
  robot?: boolean(),
  shape: String.t() | nil,
  shielding?: boolean(),
  strength: %{required(atom()) => float()},
  tally: tally(),
  team: integer() | nil,
  thrusting?: boolean(),
  timers: timers(),
  watching: term() | nil
}

tally()

@type tally() :: %{
  score: integer(),
  kills: non_neg_integer(),
  deaths: non_neg_integer(),
  streak: non_neg_integer(),
  best_streak: non_neg_integer(),
  contact: float(),
  best_contact: float(),
  recorded: %{
    kills: non_neg_integer(),
    deaths: non_neg_integer(),
    score: integer()
  }
}

The ship's count: score, kills and deaths over the whole game, the round's streak of kills without dying and its best_streak, seconds of contact with an enemy and the round's best_contact, and what result/2 last recorded.

timers()

@type timers() :: %{
  cooldown: float(),
  respawn_in: float(),
  immune_until: float(),
  phasing_until: float(),
  emergency_shield_until: float(),
  emergency_thrust_until: float(),
  ecm_until: float(),
  empty_since: float() | nil
}

The ship's clocks, in the game's seconds: cooldown until it can fire, respawn_in while dead, the *_until times its immunity, phasing, emergency shield, emergency thrust and confusion end, and empty_since, when its tank ran dry, or nil.

Functions

can_respawn?(ship)

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

Whether the ship has a life left to respawn with.

credit_kill(ship)

@spec credit_kill(t()) :: t()

Credit a kill.

die(ship, respawn_after)

@spec die(t(), float()) :: t()

Mark the ship dead, counting the death and starting the respawn clock.

equip(ship, map)

@spec equip(t(), %{fuel: float(), items: %{required(atom()) => non_neg_integer()}}) ::
  t()

Fit the ship out with a kit: :fuel in the tank (the tank grows to hold it) and :items as counts by kind, given as ExPilot.Items.pick_up/2 gives them.

headings()

@spec headings() :: pos_integer()

The number of headings a ship turns through.

holding?(ship, action)

@spec holding?(t(), atom()) :: boolean()

Whether action is held.

in_contact(ship, dt)

@spec in_contact(t(), float()) :: t()

Another dt seconds alive with an enemy in contact: the current stretch, and the round's longest.

launch_heading(atom)

@spec launch_heading(:up | :down | :left | :right) :: non_neg_integer()

The heading a ship faces on a base with dir.

max_fuel()

@spec max_fuel() :: float()

A full tank.

new(id, name, base, opts \\ [])

@spec new(term(), String.t(), {integer(), integer()}, keyword()) :: t()

A new ship for id named name, resting on its base facing the way :dir says (:up by default).

new_round(ship, lives)

@spec new_round(t(), integer() | :unlimited) :: t()

Give the ship its lives back for a new round, keeping its score; the round's streak and contact start over.

pos(ship)

@spec pos(t()) :: Cauldron2D.Body.point()

The ship's position.

radius()

@spec radius() :: float()

A ship's radius in tiles.

respawn(ship)

@spec respawn(t()) :: t()

Put the ship back on its base with a full tank, alive.

result(ship, won?)

@spec result(t(), boolean()) :: {map(), t()}

The ship's result since the last one was taken — kills, deaths and score gained, the round's best streak of kills without dying and longest contact in seconds — and the ship with those taken as recorded.

strength(ship, action)

@spec strength(t(), atom()) :: float()

How hard action is held, 0.0 to 1.0: what an analog control said, 1.0 for a key.

summary(ship)

@spec summary(t()) :: map()

What another player sees of this ship.

timer(ship, name, value)

@spec timer(t(), atom(), float() | nil) :: t()

The ship with one of its timers/0 set.