summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authortom barrett <spalf0@gmail.com>2019-02-14 12:05:57 -0600
committertom barrett <spalf0@gmail.com>2019-02-14 12:05:57 -0600
commit35b43264c09405c987b48de78b6ca19f29dc7849 (patch)
treee57fd46c3147d4ab1227d8688ebb23778dd3d21c /src/modules
parent284cac8f4034f15e7edeba5c8232a770fc082e20 (diff)
simplified receive pattern even more and moved all controls to the module
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/construction.rs9
-rw-r--r--src/modules/engines.rs30
-rw-r--r--src/modules/mining.rs9
-rw-r--r--src/modules/navigation.rs6
-rw-r--r--src/modules/refinery.rs9
-rw-r--r--src/modules/tractorbeam.rs9
6 files changed, 54 insertions, 18 deletions
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,