From ade2a89a51b5be35c1381ecb4a07e5f80eef234a Mon Sep 17 00:00:00 2001 From: Mark Date: Sat, 20 Jan 2024 09:38:21 -0800 Subject: [PATCH] Split shipstate into another file --- crates/system/src/data/ship/mod.rs | 2 + crates/system/src/data/ship/ship.rs | 77 +----------------------- crates/system/src/data/ship/shipstate.rs | 76 +++++++++++++++++++++++ 3 files changed, 79 insertions(+), 76 deletions(-) create mode 100644 crates/system/src/data/ship/shipstate.rs diff --git a/crates/system/src/data/ship/mod.rs b/crates/system/src/data/ship/mod.rs index e1b4d54..5c5b20e 100644 --- a/crates/system/src/data/ship/mod.rs +++ b/crates/system/src/data/ship/mod.rs @@ -1,7 +1,9 @@ mod outfitset; mod personality; mod ship; +mod shipstate; pub use outfitset::*; pub use personality::*; pub use ship::*; +pub use shipstate::*; diff --git a/crates/system/src/data/ship/ship.rs b/crates/system/src/data/ship/ship.rs index 3d28e55..8bc6d20 100644 --- a/crates/system/src/data/ship/ship.rs +++ b/crates/system/src/data/ship/ship.rs @@ -1,84 +1,9 @@ use galactica_content::{Content, FactionHandle, GunPoint, Outfit, ShipHandle, SystemObjectHandle}; use nalgebra::Isometry2; use rand::{rngs::ThreadRng, Rng}; -use rapier2d::math::Isometry; use std::{collections::HashMap, time::Instant}; -use super::{OutfitSet, ShipPersonality}; - -/// A ship autopilot. -/// An autopilot is a lightweight ShipController that -/// temporarily has control over a ship. -#[derive(Debug, Clone)] -pub enum ShipAutoPilot { - /// No autopilot, use usual behavior. - None, - - /// Automatically arrange for landing on the given object - Landing { - /// The body we want to land on - target: SystemObjectHandle, - }, -} - -/// Ship state machine. -/// Any ship we keep track of is in one of these states. -/// Dead ships don't exist---they removed once their collapse -/// sequence fully plays out. -#[derive(Debug, Clone)] -pub enum ShipState { - /// This ship is dead, and should be removed from the game. - Dead, - - /// This ship is alive and well in open space - Flying { - /// The autopilot we're using. - /// Overrides ship controller. - autopilot: ShipAutoPilot, - }, - - /// This ship has been destroyed, and is playing its collapse sequence. - Collapsing, - - /// This ship is landed on a planet - Landed { - /// The planet this ship is landed on - target: SystemObjectHandle, - }, - - /// This ship is landing on a planet - /// (playing the animation) - Landing { - /// The planet we're landing on - target: SystemObjectHandle, - - /// Our current z-coordinate - current_z: f32, - }, - - /// This ship is taking off from a planet - /// (playing the animation) - UnLanding { - /// The point to which we're going, in world coordinates - to_position: Isometry, - - /// The planet we're taking off from - from: SystemObjectHandle, - - /// Our current z-coordinate - current_z: f32, - }, -} - -impl ShipState { - /// What planet is this ship landed on? - pub fn landed_on(&self) -> Option { - match self { - Self::Landed { target } => Some(*target), - _ => None, - } - } -} +use super::{OutfitSet, ShipAutoPilot, ShipPersonality, ShipState}; /// Represents all attributes of a single ship #[derive(Debug, Clone)] diff --git a/crates/system/src/data/ship/shipstate.rs b/crates/system/src/data/ship/shipstate.rs new file mode 100644 index 0000000..a2535de --- /dev/null +++ b/crates/system/src/data/ship/shipstate.rs @@ -0,0 +1,76 @@ +use galactica_content::SystemObjectHandle; +use rapier2d::math::Isometry; + +/// A ship autopilot. +/// An autopilot is a lightweight ShipController that +/// temporarily has control over a ship. +#[derive(Debug, Clone)] +pub enum ShipAutoPilot { + /// No autopilot, use usual behavior. + None, + + /// Automatically arrange for landing on the given object + Landing { + /// The body we want to land on + target: SystemObjectHandle, + }, +} + +/// Ship state machine. +/// Any ship we keep track of is in one of these states. +/// Dead ships don't exist---they removed once their collapse +/// sequence fully plays out. +#[derive(Debug, Clone)] +pub enum ShipState { + /// This ship is dead, and should be removed from the game. + Dead, + + /// This ship is alive and well in open space + Flying { + /// The autopilot we're using. + /// Overrides ship controller. + autopilot: ShipAutoPilot, + }, + + /// This ship has been destroyed, and is playing its collapse sequence. + Collapsing, + + /// This ship is landed on a planet + Landed { + /// The planet this ship is landed on + target: SystemObjectHandle, + }, + + /// This ship is landing on a planet + /// (playing the animation) + Landing { + /// The planet we're landing on + target: SystemObjectHandle, + + /// Our current z-coordinate + current_z: f32, + }, + + /// This ship is taking off from a planet + /// (playing the animation) + UnLanding { + /// The point to which we're going, in world coordinates + to_position: Isometry, + + /// The planet we're taking off from + from: SystemObjectHandle, + + /// Our current z-coordinate + current_z: f32, + }, +} + +impl ShipState { + /// What planet is this ship landed on? + pub fn landed_on(&self) -> Option { + match self { + Self::Landed { target } => Some(*target), + _ => None, + } + } +}