Split shipstate into another file
parent
66dafa16bc
commit
ade2a89a51
|
@ -1,7 +1,9 @@
|
|||
mod outfitset;
|
||||
mod personality;
|
||||
mod ship;
|
||||
mod shipstate;
|
||||
|
||||
pub use outfitset::*;
|
||||
pub use personality::*;
|
||||
pub use ship::*;
|
||||
pub use shipstate::*;
|
||||
|
|
|
@ -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<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,
|
||||
}
|
||||
}
|
||||
}
|
||||
use super::{OutfitSet, ShipAutoPilot, ShipPersonality, ShipState};
|
||||
|
||||
/// Represents all attributes of a single ship
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue