starbase_tools/lib.rs
1//! # Starbase Ship Building Tools
2//!
3//! This library contains a set of tools that ship builders in the game Starbase will
4//! find useful while creating or updating their ships. The functions that are provided here
5//! are sourced from the community and from Collective.
6//!
7//! Starbase Tools is a work in progress. New functionality will likely be added as the community
8//! discovers more useful calculations. Starbase is in early access and so it is also likely that
9//! some of the values could change as things are balanced (ex: thruster values could change).
10//!
11//! This crate will not reach a stable v1 until Starbase has left early access and reaches a stable
12//! version. The crate should still be perfectly usable in the current state though.
13
14const BOX_THRUSTER_THRUST: f64 = 500_000.0;
15const TRIANGLE_THRUSTER_THRUST: f64 = 300_000.0;
16const DRAG_COEFFICIENT: f64 = -3.5503;
17const SPEED_COEFFICIENT: f64 = 46.1538;
18
19/// # Calculate a Potential Ship Speed
20///
21/// The `calculate_potential_ship_speed` function is used to calculate a potential speed for a ship
22/// based on the number of box thrusters, triangle thrusters, and the weight of the ship.
23///
24/// It is important to note that this is a possible speed because the actual speed may differ depending
25/// on how well balanced the ship is and whether or not thrusters are placed at an angle. If your
26/// ship is symmetrical and all thrusters are aligned forwards or backwards, then the speed should be
27/// relatively accurate.
28///
29/// There are no guarantees that your ship will match this speed, but it is a
30/// good tool to try and get an estimate of how many thrusters you may need based on ship weight.
31pub fn calculate_potential_ship_speed(num_of_box: &u32, num_of_tri: &u32, weight: &f64) -> f64 {
32 let thrust = calculate_thrust(num_of_box, num_of_tri);
33 let thrust_divided_by_weight = thrust / weight;
34
35 let raw_speed = DRAG_COEFFICIENT * thrust_divided_by_weight.powi(2)
36 + SPEED_COEFFICIENT * thrust_divided_by_weight;
37
38 let rounded_speed = (raw_speed * 100.0).round() / 100.0;
39
40 return rounded_speed;
41}
42
43fn calculate_thrust(num_of_box: &u32, num_of_tri: &u32) -> f64 {
44 let num_of_box = *num_of_box as f64;
45 let num_of_tri = *num_of_tri as f64;
46
47 (num_of_box * &BOX_THRUSTER_THRUST) + (num_of_tri * &TRIANGLE_THRUSTER_THRUST)
48}
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn function_name_test() {
56 let num_of_box = 1;
57 let num_of_tri = 1;
58 let expected_thrust = &BOX_THRUSTER_THRUST + &TRIANGLE_THRUSTER_THRUST;
59
60 let thrust = calculate_thrust(&num_of_box, &num_of_tri);
61
62 assert_eq!(thrust, expected_thrust)
63 }
64}