From 35b43264c09405c987b48de78b6ca19f29dc7849 Mon Sep 17 00:00:00 2001 From: tom barrett Date: Thu, 14 Feb 2019 12:05:57 -0600 Subject: simplified receive pattern even more and moved all controls to the module --- src/modules/construction.rs | 9 +++++++++ src/modules/engines.rs | 30 +++++++++++++++--------------- src/modules/mining.rs | 9 +++++++++ src/modules/navigation.rs | 6 +++--- src/modules/refinery.rs | 9 +++++++++ src/modules/tractorbeam.rs | 9 +++++++++ 6 files changed, 54 insertions(+), 18 deletions(-) (limited to 'src/modules') diff --git a/src/modules/construction.rs b/src/modules/construction.rs index 20f1688..6c27db5 100644 --- a/src/modules/construction.rs +++ b/src/modules/construction.rs @@ -2,6 +2,7 @@ use std::time::SystemTime; use crate::constants; use crate::modules::types::ModuleType; +use crate::server::construction::ConstructionData; #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] pub enum ConstructionStatus { @@ -43,6 +44,14 @@ impl Construction { } } + pub fn give_recv(&mut self, recv: String, construction_data: &ConstructionData) { + if let "c" = recv.as_str() { + if construction_data.has_enough { + self.toggle() + } + } + } + pub fn toggle(&mut self) { match self.status { ConstructionStatus::None => self.on(), diff --git a/src/modules/engines.rs b/src/modules/engines.rs index fa16bf9..ab6335a 100644 --- a/src/modules/engines.rs +++ b/src/modules/engines.rs @@ -30,27 +30,15 @@ impl Engines { } } - pub fn recv_acceleration(&mut self) -> Vector { - let acceleration = self.acceleration.clone(); - self.acceleration = Vector::default(); - - if self.fuel - acceleration.magnitude() >= 0.0 { - self.fuel -= acceleration.magnitude(); - acceleration - } else { - Vector::default() - } - } - - pub fn give_client_data( + pub fn give_recv( &mut self, + recv: String, position: Vector, velocity: Vector, target: Option<&Mass>, - data: String, ) { let mut acceleration = Vector::default(); - match data.as_str() { + match recv.as_str() { "5" => acceleration.x += 0.1, "0" => acceleration.x -= 0.1, "8" => acceleration.y += 0.1, @@ -78,4 +66,16 @@ impl Engines { } self.acceleration = acceleration; } + + pub fn take_acceleration(&mut self) -> Vector { + let acceleration = self.acceleration.clone(); + self.acceleration = Vector::default(); + + if self.fuel - acceleration.magnitude() >= 0.0 { + self.fuel -= acceleration.magnitude(); + acceleration + } else { + Vector::default() + } + } } diff --git a/src/modules/mining.rs b/src/modules/mining.rs index 1295593..120ba8c 100644 --- a/src/modules/mining.rs +++ b/src/modules/mining.rs @@ -1,6 +1,7 @@ use std::time::SystemTime; use crate::constants; +use crate::server::mining::MiningData; #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] pub enum MiningStatus { @@ -42,6 +43,14 @@ impl Mining { } } + pub fn give_recv(&mut self, recv: String, mining_data: MiningData) { + if !mining_data.is_within_range { + self.off(); + } else if let "F" = recv.as_str() { + self.toggle() + } + } + pub fn toggle(&mut self) { match self.status { MiningStatus::None => self.on(), diff --git a/src/modules/navigation.rs b/src/modules/navigation.rs index 0e010cb..5fcf89f 100644 --- a/src/modules/navigation.rs +++ b/src/modules/navigation.rs @@ -47,11 +47,11 @@ impl Navigation { } } - pub fn give_target(&mut self, target_name: String) { - if !target_name.is_empty() { + pub fn give_recv(&mut self, recv: String) { + if !recv.is_empty() { self.start = Some(SystemTime::now()); self.status = NavigationStatus::Targeting; - self.target_name = Some(target_name); + self.target_name = Some(recv); } } diff --git a/src/modules/refinery.rs b/src/modules/refinery.rs index 5760306..4a4ca85 100644 --- a/src/modules/refinery.rs +++ b/src/modules/refinery.rs @@ -1,6 +1,7 @@ use std::time::SystemTime; use crate::constants; +use crate::server::refinery::RefineryData; #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] pub enum RefineryStatus { @@ -40,6 +41,14 @@ impl Refinery { } } + pub fn give_recv(&mut self, recv: String, refinery_data: RefineryData) { + if !refinery_data.has_crude_minerals { + self.off(); + } else if let "R" = recv.as_str() { + self.toggle(); + } + } + pub fn toggle(&mut self) { match self.status { RefineryStatus::None => self.on(), diff --git a/src/modules/tractorbeam.rs b/src/modules/tractorbeam.rs index 445b066..c77ea1f 100644 --- a/src/modules/tractorbeam.rs +++ b/src/modules/tractorbeam.rs @@ -32,6 +32,15 @@ impl Tractorbeam { } } + pub fn give_recv(&mut self, recv: String) { + match recv.as_str() { + "o" => self.toggle_pull(), + "p" => self.toggle_push(), + "b" => self.toggle_bring(5.0), + _ => (), + } + } + pub fn toggle_pull(&mut self) { self.status = match self.status { TractorbeamStatus::None => TractorbeamStatus::Pull, -- cgit v1.2.3