use crate::solar_system::{GRAVITATIONAL_CONSTANT, Kilometers, SolarSystem, body::OrbitalBody, orbit::StaticOrbit}; use crate::timeman::Second; pub type FleetId = usize; pub struct Fleet { id: FleetId, name: String, position: cgmath::Vector3, velocity: cgmath::Vector3, acceleration: cgmath::Vector3, baked_orbit: Option<(f64, StaticOrbit)>, } impl Fleet { pub fn new( id: FleetId, name: String) -> Self { Self { id, name, position: cgmath::vec3(0.0, 0.0, 0.0), velocity: cgmath::vec3(0.0, 0.0, 0.0), acceleration: cgmath::vec3(0.0, 0.0, 0.0), baked_orbit: None, } } pub fn id(&self) -> FleetId { self.id } pub fn name(&self) -> &String { &self.name } pub fn make_orbit( &mut self, body: &OrbitalBody, radius: Kilometers) { let sgp = body.mass() * GRAVITATIONAL_CONSTANT; self.baked_orbit = Some((sgp, StaticOrbit::new_circular(body, radius))); } pub fn tick( &mut self, time: Second) { match &self.baked_orbit { Some(orbit_info) => { let sgp = orbit_info.0; let orbit = &orbit_info.1; self.position = orbit.calculate_position_at(sgp, time); }, None => {} } } }