Added Directives to system sim
parent
f56fd7ea49
commit
5dab73ec24
|
@ -877,6 +877,7 @@ dependencies = [
|
||||||
"galactica-content",
|
"galactica-content",
|
||||||
"galactica-playeragent",
|
"galactica-playeragent",
|
||||||
"galactica-util",
|
"galactica-util",
|
||||||
|
"log",
|
||||||
"nalgebra",
|
"nalgebra",
|
||||||
"rand",
|
"rand",
|
||||||
"rapier2d",
|
"rapier2d",
|
||||||
|
|
|
@ -25,3 +25,4 @@ rapier2d = { workspace = true }
|
||||||
nalgebra = { workspace = true }
|
nalgebra = { workspace = true }
|
||||||
crossbeam = { workspace = true }
|
crossbeam = { workspace = true }
|
||||||
rand = { workspace = true }
|
rand = { workspace = true }
|
||||||
|
log = { workspace = true }
|
||||||
|
|
|
@ -78,11 +78,11 @@ impl ShipData {
|
||||||
/// That is the simulation's responsiblity.
|
/// That is the simulation's responsiblity.
|
||||||
///
|
///
|
||||||
/// Will panic if we're not flying.
|
/// Will panic if we're not flying.
|
||||||
pub fn start_land_on(&mut self, target_handle: Arc<SystemObject>) {
|
pub fn start_land_on(&mut self, target: Arc<SystemObject>) {
|
||||||
match self.state {
|
match self.state {
|
||||||
ShipState::Flying { .. } => {
|
ShipState::Flying { .. } => {
|
||||||
self.state = ShipState::Landing {
|
self.state = ShipState::Landing {
|
||||||
target: target_handle,
|
target,
|
||||||
current_z: 1.0,
|
current_z: 1.0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -285,13 +285,12 @@ impl ShipData {
|
||||||
&self.state
|
&self.state
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a handle to this ship's content
|
/// Get this ship's content
|
||||||
pub fn get_content(&self) -> &Arc<Ship> {
|
pub fn get_content(&self) -> &Arc<Ship> {
|
||||||
&self.ship
|
&self.ship
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get this ship's current hull.
|
/// Get this ship's current hull
|
||||||
/// Use content handle to get maximum hull
|
|
||||||
pub fn get_hull(&self) -> f32 {
|
pub fn get_hull(&self) -> f32 {
|
||||||
self.hull
|
self.hull
|
||||||
}
|
}
|
||||||
|
@ -316,9 +315,4 @@ impl ShipData {
|
||||||
pub fn get_faction(&self) -> &Arc<Faction> {
|
pub fn get_faction(&self) -> &Arc<Faction> {
|
||||||
&self.faction
|
&self.faction
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get this ship's content handle
|
|
||||||
pub fn get_ship(&self) -> &Arc<Ship> {
|
|
||||||
&self.ship
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,3 +6,6 @@
|
||||||
|
|
||||||
pub mod data;
|
pub mod data;
|
||||||
pub mod phys;
|
pub mod phys;
|
||||||
|
mod playerdirective;
|
||||||
|
|
||||||
|
pub use playerdirective::PlayerDirective;
|
||||||
|
|
|
@ -2,6 +2,7 @@ use galactica_content::Faction;
|
||||||
use galactica_content::Relationship;
|
use galactica_content::Relationship;
|
||||||
use galactica_content::Ship;
|
use galactica_content::Ship;
|
||||||
use galactica_playeragent::PlayerAgent;
|
use galactica_playeragent::PlayerAgent;
|
||||||
|
use log::error;
|
||||||
use nalgebra::{Isometry2, Point2, Rotation2, Vector2};
|
use nalgebra::{Isometry2, Point2, Rotation2, Vector2};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use rapier2d::{
|
use rapier2d::{
|
||||||
|
@ -17,6 +18,7 @@ use super::{
|
||||||
PhysImage, PhysProjectileImage, PhysShipImage, PhysStepResources, PhysWrapper,
|
PhysImage, PhysProjectileImage, PhysShipImage, PhysStepResources, PhysWrapper,
|
||||||
};
|
};
|
||||||
use crate::data::{ShipAutoPilot, ShipPersonality, ShipState};
|
use crate::data::{ShipAutoPilot, ShipPersonality, ShipState};
|
||||||
|
use crate::PlayerDirective;
|
||||||
|
|
||||||
// TODO: replace with a more generic handle
|
// TODO: replace with a more generic handle
|
||||||
/// A handle for a ship in this simulation
|
/// A handle for a ship in this simulation
|
||||||
|
@ -190,7 +192,7 @@ impl PhysSim {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update a player ship's controls
|
/// Update a player ship's controls
|
||||||
pub fn update_player_controls(&mut self, player: &PlayerAgent) {
|
pub fn apply_directive(&mut self, directive: PlayerDirective, player: &PlayerAgent) {
|
||||||
if player.ship.is_none() {
|
if player.ship.is_none() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -204,37 +206,49 @@ impl PhysSim {
|
||||||
|
|
||||||
ShipState::Flying {
|
ShipState::Flying {
|
||||||
autopilot: ShipAutoPilot::None,
|
autopilot: ShipAutoPilot::None,
|
||||||
} => {
|
} => match directive {
|
||||||
ship_object.controls.guns = player.input.pressed_guns();
|
PlayerDirective::None => {}
|
||||||
ship_object.controls.left = player.input.pressed_left();
|
PlayerDirective::Engine(x) => ship_object.controls.thrust = x,
|
||||||
ship_object.controls.right = player.input.pressed_right();
|
PlayerDirective::TurnLeft(x) => ship_object.controls.left = x,
|
||||||
ship_object.controls.thrust = player.input.pressed_thrust();
|
PlayerDirective::TurnRight(x) => ship_object.controls.right = x,
|
||||||
|
PlayerDirective::Guns(x) => ship_object.controls.guns = x,
|
||||||
if player.input.pressed_land() {
|
PlayerDirective::Land => {
|
||||||
if let Some(target) = player.selection.get_planet() {
|
if let Some(target) = player.selection.get_planet() {
|
||||||
ship_object.data.set_autopilot(ShipAutoPilot::Landing {
|
ship_object.data.set_autopilot(ShipAutoPilot::Landing {
|
||||||
target: target.clone(),
|
target: target.clone(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
_ => {
|
||||||
|
error!("Got an invalid directive {directive:?} in shipstate `Flying`");
|
||||||
ShipState::Flying { .. } => {
|
|
||||||
// Any input automatically releases autopilot
|
|
||||||
if player.input.pressed_left()
|
|
||||||
|| player.input.pressed_right()
|
|
||||||
|| player.input.pressed_thrust()
|
|
||||||
|| player.input.pressed_guns()
|
|
||||||
{
|
|
||||||
ship_object.data.set_autopilot(ShipAutoPilot::None);
|
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
|
||||||
ShipState::Landed { .. } => {
|
ShipState::Flying { .. } => match directive {
|
||||||
if player.input.pressed_land() {
|
PlayerDirective::None => {}
|
||||||
|
PlayerDirective::Engine(_)
|
||||||
|
| PlayerDirective::TurnLeft(_)
|
||||||
|
| PlayerDirective::TurnRight(_)
|
||||||
|
| PlayerDirective::Land
|
||||||
|
| PlayerDirective::Guns(_) => {
|
||||||
|
// Disable autopilot and apply action
|
||||||
|
ship_object.data.set_autopilot(ShipAutoPilot::None);
|
||||||
|
self.apply_directive(directive, player);
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
error!("Got an invalid directive {directive:?} in shipstate `Flying`");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
ShipState::Landed { .. } => match directive {
|
||||||
|
PlayerDirective::None => {}
|
||||||
|
PlayerDirective::UnLand => {
|
||||||
self.start_unland_ship(player.ship.unwrap());
|
self.start_unland_ship(player.ship.unwrap());
|
||||||
}
|
}
|
||||||
}
|
_ => {
|
||||||
|
error!("Got an invalid directive {directive:?} in shipstate `Landed`");
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
/// An action the player wants to take in the game.
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum PlayerDirective {
|
||||||
|
/// Do nothing
|
||||||
|
None,
|
||||||
|
|
||||||
|
/// Set main engine state
|
||||||
|
Engine(bool),
|
||||||
|
|
||||||
|
/// Set left turn thruster state
|
||||||
|
TurnLeft(bool),
|
||||||
|
|
||||||
|
/// Set right turn thruster state
|
||||||
|
TurnRight(bool),
|
||||||
|
|
||||||
|
/// Set main gun state
|
||||||
|
Guns(bool),
|
||||||
|
|
||||||
|
/// Land on the currently selected planet
|
||||||
|
Land,
|
||||||
|
|
||||||
|
/// Take off from the planet we're landed on
|
||||||
|
UnLand,
|
||||||
|
}
|
Loading…
Reference in New Issue