### 69 releases (40 breaking)

new 0.46.0 | Mar 27, 2023 |
---|---|

0.44.0 | Mar 13, 2023 |

0.29.0 | Dec 17, 2022 |

0.27.0 | Nov 29, 2022 |

#**27** in Games

**215** downloads per month

**GPL-3.0-or-later**

39KB

776 lines

This is the API reference for Oort. For more general information see the wiki.

# Starter Code

Oort expects your code to have a

type with a `Ship`

method. Each
tutorial provides some starter code which includes this:`tick`

`use` `oort_api``::``prelude``::``*``;`
`pub` `struct` `Ship` `{``}`
`impl` `Ship` `{`
`pub` `fn` `new``(``)`` ``->` Ship `{`
Ship `{``}`
`}`
`pub` `fn` `tick``(``&``mut` `self``)`` ``{`
`}`
`}`

The game will call your

function when a ship is created and then call
`new`

60 times per second during the simulation.`tick`

is useful for storing any state that needs to persist between
ticks. `struct` `Ship`

works too and can be helpful when this state differs between
ship classes.`enum` `Ship`

The statement

imports all the APIs so that you can use
them simply as e.g. `use` `oort_api ::`

`prelude`

`::``*`

`position``(``)`

. See the [prelude] module documentation for
the details on everything this imports. The important APIs are covered below.# Subsystems

All actions performed by a ship (such as firing weapons or scanning the radar) occur between ticks. In particular, setting the radar heading or the radio channel will affect the scan results or messages received on the next tick.

## Ship Status and Control

Basic status:

: Get the ship class (Fighter, Cruiser, etc).`class``(``)`→ Class

: Get the current position in meters.`position``(``)`→ Vec2

: Get the current velocity in m/s.`velocity``(``)`→ Vec2

: Get the current heading in radians.`heading``(``)`→`f64`

: Get the current angular velocity in radians/s.`angular_velocity``(``)`→`f64`

Engine control:

: Linear acceleration. X axis is forward/back, Y axis is left/right. Units are m/s².`accelerate``(`acceleration`:`Vec2`)`

: Rotate the ship. Unit is radians/s.`turn``(`speed`:``f64``)`

: Angular acceleration. Unit is radians/s².`torque``(`acceleration`:``f64``)`

Engine limits:

: Maximum forward acceleration.`max_forward_acceleration``(``)``->``f64`

: Maximum backward acceleration.`max_backward_acceleration``(``)``->``f64`

: Maximum lateral acceleration.`max_lateral_acceleration``(``)``->``f64`

: Maximum angular acceleration.`max_angular_acceleration``(``)``->``f64`

## Weapons

Guns:

: Fire a weapon (gun or missile).`fire``(`index`:``usize``)`

: Aim a weapon (for weapons on a turret).`aim``(`index`:``usize``,`angle`:``f64``)`

: Self-destruct.`explode``(``)`

## Radar

Radar in Oort is modeled as a beam that can be pointed in any direction and which has a width between 1/360 of a circle to a full circle. Enemy ships illuminated by this beam reflect an amount of energy proportional to their radar cross section (larger for larger ships). The radar can return one contact per tick. Any changes to heading/width/filtering take effect on the next tick.

The position and velocity returned for a contact will have error inversely related to the signal strength.

Basic operation:

: Point the radar at the given heading, relative to the ship heading.`set_radar_heading``(`angle`:``f64``)`

: Adjust the beam width (in radians).`set_radar_width``(`width`:``f64``)`

: Get the radar contact with the highest signal strength.`scan``(``)`→`Option``<`ScanResult`>`

: Structure returned by`struct``ScanResult``{``position``:`Vec2,`velocity``:`Vec2,`class``:`Class`}`

.`scan`

Advanced filtering:

: Set the minimum distance filter.`set_radar_min_distance``(`dist`:``f64``)`

: Set the maximum distance filter.`set_radar_max_distance``(`dist`:``f64``)`

Retrieving current state:

: Get current radar heading.`radar_heading``(``)``->``f64`

: Get current radar width.`radar_width``(``)``->``f64`

: Get current minimum distance filter.`radar_min_distance``(``)``->``f64`

: Get current maximum distance filter.`radar_max_distance``(``)``->``f64`

## Radio

The radio can be used to send or receive a single value per tick. There are 10 channels available (0 to 9), shared between all teams.

: Change the radio channel. Takes effect next tick.`set_radio_channel``(`channel`:``usize``)`

: Get the radio channel.`get_radio_channel``(``)``->``usize`

: Send a message on a channel.`send``(`data`:``f64``)`

: Receive a message from the channel. The message with the strongest signal is returned.`receive``(``)``->``f64`

: Select the radio to control with subsequent API calls. Frigates have 4 radios and cruisers have 8.`select_radio``(`index`:``usize``)`

## Special Abilities

Some ship classes have a unique special ability. These abilities are activated for a certain time and then need to reload.

: Activates a special ability.`activate_ability``(`ability`:`Ability`)`- Available abilities:

: Fighter and missile only. Applies a 100 m/s² forward acceleration for 2s. Reloads in 10s.`Ability`Boost`::`

: Missile only. [`Ability`ShapedCharge`::`

][prelude::explode] will create a jet of shrapnel instead of a circle.`explode``(``)`

: Torpedo only. Mimics the radar signature of a Cruiser for 0.5s. Reloads in 10s.`Ability`Decoy`::`

: Cruiser only. Deflects damage for 1s. Reloads in 5s.`Ability`Shield`::`

## Scalar Math

,`PI`

: Constants.`TAU`

: Absolute value.`x``.``abs``(``)`

: Square root.`x``.``sqrt``(``)`

,`x``.``sin``(``)`

,`x``.``cos``(``)`

: Trigonometry.`x``.``tan``(``)`

See the Rust documentation for the full list of f64 methods.

## Vector Math

Two-dimensional floating point vectors (Vec2) are ubiquitous in Oort and are used to represent positions, velocities, accelerations, etc.

: Create a vector.`vec2``(`x`:``f64``,`y`:``f64``)`→ Vec2

: Get a component of a vector.`v``.`x`,`v`.`y →`f64`

: Basic arithmetic between vectors.`v1``+``-`v2 → Vec2

: Basic arithmetic between vectors and scalars.`v``*``/``f64`→ Vec2

: Negate a vector.`-`v → Vec2

: Length.`v``.``length``(``)`→`f64`

: Normalize to a unit vector.`v``.``normalize``(``)`→ Vec2

: Rotate counter-clockwise.`v``.``rotate``(`angle`:``f64``)`→ Vec2

: Angle of a vector.`v``.``angle``(``)`→`f64`

: Dot product.`v1``.``dot``(`v2`:`Vec2`)`→`f64`

: Cross product.`v1``.``cross``(`v2`:`Vec2`)`→`f64`

: Distance between two points.`v1``.``distance``(`v2`:`Vec2`)`→`f64`

## Debugging

Clicking on a ship in the UI displays status information and graphics indicating its acceleration, radar cone, etc. You can add to this with the functions below.

: Add status text.`debug!``(``...``)`

: Draw a line.`draw_line``(`v0`:`Vec2`,`v1`:`Vec2`,`color`:``u32``)`

: Draw a triangle.`draw_triangle``(`center`:`Vec2`,`radius`:``f64``,`color`:``u32``)`

: Draw a square.`draw_square``(`center`:`Vec2`,`radius`:``f64``,`color`:``u32``)`

: Draw a diamond.`draw_diamond``(`center`:`Vec2`,`radius`:``f64``,`color`:``u32``)`

: Draw a regular polygon.`draw_polygon``(`center`:`Vec2`,`radius`:``f64``,`sides`:``i32``,`angle`:``f64``,`color`:``u32``)`

: Draw text.`draw_text!``(`topleft`:`Vec2`,`color`:``u32``,``...``)`

Entering debug mode by pressing the 'g' key also displays debug graphics from all ships.

## Miscellaneous

: Returns the number of ticks elapsed since the simulation started.`current_tick``(``)`→`f64`

: Returns the number of seconds elapsed since the simulation started.`current_time``(``)`→`f64`

: Returns the shortest (possibly negative) distance between two angles.`angle_diff``(`a`:``f64``,`b`:``f64``)`→`f64`

: Get a random number.`rand``(`low`:``f64``,`high`:``f64``)`→`f64`

: Returns a seed useful for initializing a random number generator.`seed``(``)`→`u128`

## Ship Classes

: Small, fast, and lightly armored.`Fighter`- Health: 100
- Acceleration: Forward/Reverse: 60 m/s², Lateral: 30 m/s², Angular: 2π rad/s²
- Weapon 0: Gun, Damage: 7, Speed: 1000 m/s, Reload: 66ms
- Weapon 1: Torpedo, Reload: 5s

: Medium size with heavy armor and an extremely powerful main gun.`Frigate`- Health: 10000
- Acceleration: Forward/Reverse: 10 m/s², Lateral: 5 m/s², Angular: π/4 rad/s²
- Weapon 0: Gun, Damage: 1000, Speed: 4000 m/s, Reload: 1 second
- Weapon 1: Gun, Damage: 7, Speed: 1000 m/s, Reload: 66ms, Turreted
- Weapon 2: Gun, Damage: 7, Speed: 1000 m/s, Reload: 66ms, Turreted
- Weapon 3: Missile, Reload: 2s

: Large, slow, and heavily armored. Rapid fire missile launchers and devastating torpedos.`Cruiser`- Health: 20000
- Acceleration: Forward/Reverse: 5 m/s², Lateral: 2.5 m/s², Angular: π/8 rad/s²
- Weapon 0: Gun, Damage: 6×7, Speed: 1000 m/s, Reload: 0.4s, Turreted
- Weapon 1: Missile, Reload: 1.2s
- Weapon 2: Missile, Reload: 1.2s
- Weapon 3: Torpedo, Reload: 3s

: Highly maneuverable but unarmored. Explodes on contact or after an`Missile`

call.`explode`- Health: 20
- Acceleration: Forward/Reverse: 200 m/s², Lateral: 50 m/s², Angular: 4π rad/s²
- Warhead: 20×15

: Better armor, larger warhead, but less maneuverable than a missile. Explodes on contact or after an`Torpedo`

call.`explode`- Health: 100
- Acceleration: Forward/Reverse: 70 m/s², Lateral: 20 m/s², Angular: 4π rad/s²
- Warhead: 100×50

#### Dependencies

~94KB