Split shipstate into another file

master
Mark 2024-01-20 09:38:21 -08:00
parent 66dafa16bc
commit ade2a89a51
Signed by: Mark
GPG Key ID: C6D63995FE72FD80
3 changed files with 79 additions and 76 deletions

View File

@ -1,7 +1,9 @@
mod outfitset; mod outfitset;
mod personality; mod personality;
mod ship; mod ship;
mod shipstate;
pub use outfitset::*; pub use outfitset::*;
pub use personality::*; pub use personality::*;
pub use ship::*; pub use ship::*;
pub use shipstate::*;

View File

@ -1,84 +1,9 @@
use galactica_content::{Content, FactionHandle, GunPoint, Outfit, ShipHandle, SystemObjectHandle}; use galactica_content::{Content, FactionHandle, GunPoint, Outfit, ShipHandle, SystemObjectHandle};
use nalgebra::Isometry2; use nalgebra::Isometry2;
use rand::{rngs::ThreadRng, Rng}; use rand::{rngs::ThreadRng, Rng};
use rapier2d::math::Isometry;
use std::{collections::HashMap, time::Instant}; use std::{collections::HashMap, time::Instant};
use super::{OutfitSet, ShipPersonality}; use super::{OutfitSet, ShipAutoPilot, ShipPersonality, ShipState};
/// 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<f32>,
/// 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<SystemObjectHandle> {
match self {
Self::Landed { target } => Some(*target),
_ => None,
}
}
}
/// Represents all attributes of a single ship /// Represents all attributes of a single ship
#[derive(Debug, Clone)] #[derive(Debug, Clone)]

View File

@ -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<f32>,
/// 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<SystemObjectHandle> {
match self {
Self::Landed { target } => Some(*target),
_ => None,
}
}
}