summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authortom barrett <spalf0@gmail.com>2019-02-03 05:45:35 -0600
committertom barrett <spalf0@gmail.com>2019-02-03 05:45:35 -0600
commit46fa862e04bc43311ba79ef3db70abf9014b9104 (patch)
tree3507873ec788af1f1e0885bbb676dbb4a373d48e /src/modules
parent828f0d83dcb258a8e5efd55a7775592c6e5f77bc (diff)
bringing to 2018
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/construction.rs28
-rw-r--r--src/modules/dashboard.rs2
-rw-r--r--src/modules/engines.rs66
-rw-r--r--src/modules/mining.rs26
-rw-r--r--src/modules/mod.rs10
-rw-r--r--src/modules/navigation.rs44
-rw-r--r--src/modules/refinery.rs22
7 files changed, 109 insertions, 89 deletions
diff --git a/src/modules/construction.rs b/src/modules/construction.rs
index 46ddbb1..f55a2fb 100644
--- a/src/modules/construction.rs
+++ b/src/modules/construction.rs
@@ -1,5 +1,5 @@
+use crate::modules::types::ModuleType;
use std::time::SystemTime;
-use modules::types::ModuleType;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub enum ConstructionStatus {
@@ -8,26 +8,32 @@ pub enum ConstructionStatus {
Constructed,
}
-#[derive(Serialize, Deserialize, Debug, Clone)]
+impl Default for ConstructionStatus {
+ fn default() -> Self {
+ ConstructionStatus::None
+ }
+}
+
+#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct Construction {
- pub status : ConstructionStatus,
- construction : Option<ModuleType>,
- time : u64,
- start : Option<SystemTime>,
+ pub status: ConstructionStatus,
+ construction: Option<ModuleType>,
+ time: u64,
+ start: Option<SystemTime>,
}
impl Construction {
pub fn new() -> Construction {
Construction {
- status : ConstructionStatus::None,
- construction : None,
- time : 5,
- start : None,
+ status: ConstructionStatus::None,
+ construction: None,
+ time: 5,
+ start: None,
}
}
pub fn process(&mut self) {
- if let Some(timer) = self.start.clone() {
+ if let Some(timer) = self.start {
if timer.elapsed().unwrap().as_secs() > self.time {
self.start = Some(SystemTime::now());
self.status = ConstructionStatus::Constructed;
diff --git a/src/modules/dashboard.rs b/src/modules/dashboard.rs
index e7f739b..acc1fb8 100644
--- a/src/modules/dashboard.rs
+++ b/src/modules/dashboard.rs
@@ -1,4 +1,4 @@
-#[derive(Serialize, Deserialize, Debug, Clone)]
+#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct Dashboard {}
impl Dashboard {
diff --git a/src/modules/engines.rs b/src/modules/engines.rs
index 4741a03..a930847 100644
--- a/src/modules/engines.rs
+++ b/src/modules/engines.rs
@@ -1,14 +1,14 @@
-use mass::Mass;
+use crate::mass::Mass;
-#[derive(Serialize, Deserialize, Debug, Clone)]
+#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct Engines {
- acceleration : (f64, f64, f64),
+ acceleration: (f64, f64, f64),
}
impl Engines {
pub fn new() -> Engines {
Engines {
- acceleration : (0.0, 0.0, 0.0)
+ acceleration: (0.0, 0.0, 0.0),
}
}
@@ -18,7 +18,7 @@ impl Engines {
acceleration
}
- pub fn give_client_data(&mut self, ship : &Mass, target : Option<&Mass>, data : String) {
+ pub fn give_client_data(&mut self, ship: &Mass, target: Option<&Mass>, data: String) {
let mut acceleration = (0.0, 0.0, 0.0);
match data.as_bytes() {
b"5\n" => acceleration.0 += 0.1,
@@ -29,46 +29,38 @@ impl Engines {
b"6\n" => acceleration.2 -= 0.1,
b"+\n" => {
let m_v = ship.velocity;
- acceleration = (m_v.0 * 0.05,
- m_v.1 * 0.05,
- m_v.2 * 0.05);
- },
+ acceleration = (m_v.0 * 0.05, m_v.1 * 0.05, m_v.2 * 0.05);
+ }
b"-\n" => {
let m_v = ship.velocity;
- acceleration = (-1.0 * m_v.0 * 0.05,
- -1.0 * m_v.1 * 0.05,
- -1.0 * m_v.2 * 0.05);
- },
+ acceleration = (
+ -1.0 * m_v.0 * 0.05,
+ -1.0 * m_v.1 * 0.05,
+ -1.0 * m_v.2 * 0.05,
+ );
+ }
b"s\n" => {
let m_v = ship.velocity;
- acceleration = (-1.0 * m_v.0,
- -1.0 * m_v.1,
- -1.0 * m_v.2);
- },
+ acceleration = (-1.0 * m_v.0, -1.0 * m_v.1, -1.0 * m_v.2);
+ }
b"c\n" => {
- match target {
- Some(target) => {
- let d_v = target.velocity;
- let m_v = ship.velocity;
- acceleration = (d_v.0 - m_v.0,
- d_v.1 - m_v.1,
- d_v.2 - m_v.2);
- },
- None => (),
+ if let Some(target) = target {
+ let d_v = target.velocity;
+ let m_v = ship.velocity;
+ acceleration = (d_v.0 - m_v.0, d_v.1 - m_v.1, d_v.2 - m_v.2);
}
- },
+ }
b"t\n" => {
- match target {
- Some(target) => {
- let d_p = target.position;
- let m_p = ship.position;
- acceleration = ((d_p.0 - m_p.0) * 0.01,
- (d_p.1 - m_p.1) * 0.01,
- (d_p.2 - m_p.2) * 0.01);
- },
- None => (),
+ if let Some(target) = target {
+ let d_p = target.position;
+ let m_p = ship.position;
+ acceleration = (
+ (d_p.0 - m_p.0) * 0.01,
+ (d_p.1 - m_p.1) * 0.01,
+ (d_p.2 - m_p.2) * 0.01,
+ );
}
- },
+ }
_ => (),
}
self.acceleration = acceleration;
diff --git a/src/modules/mining.rs b/src/modules/mining.rs
index 3c091b9..b923480 100644
--- a/src/modules/mining.rs
+++ b/src/modules/mining.rs
@@ -7,26 +7,32 @@ pub enum MiningStatus {
Mined,
}
-#[derive(Serialize, Deserialize, Debug, Clone)]
+impl Default for MiningStatus {
+ fn default() -> Self {
+ MiningStatus::None
+ }
+}
+
+#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct Mining {
- pub range : f64,
- pub status : MiningStatus,
- time : u64,
- start : Option<SystemTime>,
+ pub range: f64,
+ pub status: MiningStatus,
+ time: u64,
+ start: Option<SystemTime>,
}
impl Mining {
pub fn new() -> Mining {
Mining {
- range : 10.0,
- status : MiningStatus::None,
- time : 5,
- start : None,
+ range: 10.0,
+ status: MiningStatus::None,
+ time: 5,
+ start: None,
}
}
pub fn process(&mut self) {
- if let Some(timer) = self.start.clone() {
+ if let Some(timer) = self.start {
if timer.elapsed().unwrap().as_secs() > self.time {
self.status = MiningStatus::Mined;
self.start = Some(SystemTime::now());
diff --git a/src/modules/mod.rs b/src/modules/mod.rs
index d0ffd38..3929e24 100644
--- a/src/modules/mod.rs
+++ b/src/modules/mod.rs
@@ -1,7 +1,7 @@
-pub mod types;
-pub mod mining;
-pub mod engines;
-pub mod refinery;
+pub mod construction;
pub mod dashboard;
+pub mod engines;
+pub mod mining;
pub mod navigation;
-pub mod construction;
+pub mod refinery;
+pub mod types;
diff --git a/src/modules/navigation.rs b/src/modules/navigation.rs
index 84f315c..11f3e94 100644
--- a/src/modules/navigation.rs
+++ b/src/modules/navigation.rs
@@ -1,8 +1,8 @@
-use std::time::SystemTime;
use std::collections::HashMap;
+use std::time::SystemTime;
-use mass::Mass;
-use math::distance;
+use crate::mass::Mass;
+use crate::math::distance;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub enum NavigationStatus {
@@ -11,28 +11,34 @@ pub enum NavigationStatus {
Targeted,
}
-#[derive(Serialize, Deserialize, Debug, Clone)]
+impl Default for NavigationStatus {
+ fn default() -> Self {
+ NavigationStatus::None
+ }
+}
+
+#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct Navigation {
- pub range : f64,
- pub status : NavigationStatus,
- pub target_name : Option<String>,
- time : u64,
- start : Option<SystemTime>,
+ pub range: f64,
+ pub status: NavigationStatus,
+ pub target_name: Option<String>,
+ time: u64,
+ start: Option<SystemTime>,
}
impl Navigation {
pub fn new() -> Navigation {
Navigation {
- target_name : None,
- range : 100.0,
- status : NavigationStatus::None,
- time : 3,
- start : None,
+ target_name: None,
+ range: 100.0,
+ status: NavigationStatus::None,
+ time: 3,
+ start: None,
}
}
pub fn process(&mut self) {
- if let Some(timer) = self.start.clone() {
+ if let Some(timer) = self.start {
if timer.elapsed().unwrap().as_secs() > self.time {
self.status = NavigationStatus::Targeted;
self.start = None;
@@ -40,13 +46,17 @@ impl Navigation {
}
}
- pub fn give_target(&mut self, target_name : String) {
+ pub fn give_target(&mut self, target_name: String) {
self.start = Some(SystemTime::now());
self.status = NavigationStatus::Targeting;
self.target_name = Some(target_name);
}
- pub fn verify_target(&mut self, ship_position : (f64, f64, f64), masses : &HashMap<String, Mass>) {
+ pub fn verify_target(
+ &mut self,
+ ship_position: (f64, f64, f64),
+ masses: &HashMap<String, Mass>,
+ ) {
if let Some(name) = self.target_name.clone() {
let target = masses.get(&name).unwrap();
if distance(target.position, ship_position) > self.range {
diff --git a/src/modules/refinery.rs b/src/modules/refinery.rs
index 5100f3d..5fdc10c 100644
--- a/src/modules/refinery.rs
+++ b/src/modules/refinery.rs
@@ -7,24 +7,30 @@ pub enum RefineryStatus {
Refined,
}
-#[derive(Serialize, Deserialize, Debug, Clone)]
+impl Default for RefineryStatus {
+ fn default() -> Self {
+ RefineryStatus::None
+ }
+}
+
+#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct Refinery {
- time : u64,
- start : Option<SystemTime>,
- pub status : RefineryStatus,
+ time: u64,
+ start: Option<SystemTime>,
+ pub status: RefineryStatus,
}
impl Refinery {
pub fn new() -> Refinery {
Refinery {
- time : 5,
- start : None,
- status : RefineryStatus::None,
+ time: 5,
+ start: None,
+ status: RefineryStatus::None,
}
}
pub fn process(&mut self) {
- if let Some(timer) = self.start.clone() {
+ if let Some(timer) = self.start {
if timer.elapsed().unwrap().as_secs() > self.time {
self.status = RefineryStatus::Refined;
self.start = Some(SystemTime::now());