This is the API reference for Oort. For more general information see the wiki.
Oort expects your code to have a Ship
type with a tick
method. Each
tutorial provides some starter code which includes this:
```rust use oort_api::prelude::*;
pub struct Ship {}
impl Ship { pub fn new() -> Ship { Ship {} }
pub fn tick(&mut self) {
}
} ```
The game will call your new
function when a ship is created and then call
tick
60 times per second during the simulation.
struct Ship
is useful for storing any state that needs to persist between
ticks. enum Ship
works too and can be helpful when this state differs between
ship classes.
The statement use oort_api::prelude::*
imports all the APIs so that you can use
them simply as e.g. position()
. See the [prelude] module documentation for
the details on everything this imports. The important APIs are covered below.
class() → Class
: Returns the ship class.position() → Vec2
: Get the current position in meters.velocity() → Vec2
: Get the current velocity in m/s.heading() → f64
: Get the current heading in radians.angular_velocity() → f64
: Get the current angular velocity in radians/s.accelerate(acceleration: Vec2)
: Linear acceleration. X axis is forward/back, Y axis is left/right. Units are m/s².max_acceleration() -> Vec2
: Maximum linear acceleration.torque(acceleration: f64)
: Angular acceleration. Unit is radians/s².max_angular_acceleration() -> f64
: Maximum angular acceleration.energy() -> f64
: Available energy in Joules.fire_gun(index: usize)
: Fire a gun.aim_gun(index: usize, angle: f64)
: Aim a gun (for guns on a turret).launch_missile(index: usize, orders: f64)
: Launch a missile.explode()
: Self-destruct.set_radar_heading(angle: f64)
: Point the radar at the given heading.radar_heading() -> f64
: Get current radar heading.set_radar_width(width: f64)
: Adjust the width of the radar beam (in radians).radar_width() -> f64
: Get current radar width.set_radar_min_distance(dist: f64)
: Set the minimum distance filter.radar_min_distance() -> f64
: Get current minimum distance filter.set_radar_max_distance(dist: f64)
: Set the maximum distance filter.radar_max_distance() -> f64
: Get current maximum distance filter.scan() → Option<ScanResult>
: Find an enemy ship illuminated by the radar.struct ScanResult { position: Vec2, velocity: Vec2, class: Class }
: Structure returned by scan()
.set_radio_channel(channel: usize)
: Change the radio channel (0 to 9). Takes effect next tick.get_radio_channel() -> usize
: Get the radio channel.send(data: f64)
: Send a message on a channel.receive() -> f64
: Receive a message from the channel. The message with the strongest signal is returned.PI
, TAU
: Constants.x.abs()
: Absolute value.x.sqrt()
: Square root.x.sin()
, x.cos()
, x.tan()
: Trignometry.See the Rust documentation for the full list of f64 methods.
Two-dimensional floating point vectors (Vec2) are ubiquitous in Oort and are used to represent positions, velocities, accelerations, etc.
vec2(x: f64, y: f64) → Vec2
: Create a vector.v.x, v.y → f64
: Get a component of a vector.v1 +- v2 → Vec2
: Basic arithmetic between vectors.v */ f64 → Vec2
: Basic arithmetic between vectors and scalars.-v → Vec2
: Negate a vector.v.length() → f64
: Length.v.normalize() → Vec2
: Normalize to a unit vector.v.rotate(angle: f64) → Vec2
: Rotate counter-clockwise.v.angle() → f64
: Angle of a vector.v1.dot(v2: Vec2) → f64
: Dot product.v1.distance(v2: Vec2) → f64
: Distance between two points.debug!(...)
: Add text to be displayed when the ship is selected by clicking on it. Works just like [println!
].debug_line(v0: Vec2, v1: Vec2, color: u32)
: Draw a line visible when the ship is selected. Color is 24-bit RGB.debug_triangle(center: Vec2, radius: f64, color: u32)
: Draw a triangle visible when the ship is selected.debug_square(center: Vec2, radius: f64, color: u32)
: Draw a square visible when the ship is selected.debug_diamond(center: Vec2, radius: f64, color: u32)
: Draw a diamond visible when the ship is selected.debug_polygon(center: Vec2, radius: f64, sides: i32, angle: f64, color: u32)
: Draw a regular polygon visible when the ship is selected.current_tick() → f64
: Returns the number of ticks elapsed since the simulation started.current_time() → f64
: Returns the number of seconds elapsed since the simulation started.angle_diff(a: f64, b: f64) → f64
: Returns the shortest (possibly negative) distance between two angles.rand(low: f64, high: f64) → f64
: Get a random number.orders() → f64
: Returns the orders passed to launch_missile.seed() → u128
: Returns a seed useful for initializing a random number generator.Fighter
: Small, fast, and lightly armored. One forward-facing gun and one missile launcher.Frigate
: Medium size with heavy armor. One forward-facing high-velocity gun, two turreted guns, and one missile launcher.Cruiser
: Large, slow, and heavily armored. One turreted flak gun, two missile launchers, and one torpedo launcher.Missile
: Highly maneuverable but unarmored. Explodes on contact or after an explode() call.Torpedo
: Better armor, larger warhead, but less maneuverable than a missile. Explodes on contact or after an explode() call.