summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authortom barrett <spalf0@gmail.com>2018-04-23 06:25:55 -0500
committertom barrett <spalf0@gmail.com>2018-04-23 06:25:55 -0500
commit923e49d29ce2f51df608011db192cbb73e8f7345 (patch)
tree1813395ed810b3f5a810cb13abd5bf39f94349ef /src/modules
parent7211ed31e5412eb84f8fbf0e3a465305068f1d7c (diff)
-split up module.rs
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/dashboard.rs8
-rw-r--r--src/modules/engines.rs70
-rw-r--r--src/modules/mining.rs23
-rw-r--r--src/modules/mod.rs5
-rw-r--r--src/modules/navigation.rs64
-rw-r--r--src/modules/types.rs7
6 files changed, 177 insertions, 0 deletions
diff --git a/src/modules/dashboard.rs b/src/modules/dashboard.rs
new file mode 100644
index 0000000..e7f739b
--- /dev/null
+++ b/src/modules/dashboard.rs
@@ -0,0 +1,8 @@
+#[derive(Serialize, Deserialize, Debug, Clone)]
+pub struct Dashboard {}
+
+impl Dashboard {
+ pub fn new() -> Dashboard {
+ Dashboard {}
+ }
+}
diff --git a/src/modules/engines.rs b/src/modules/engines.rs
new file mode 100644
index 0000000..10e4c85
--- /dev/null
+++ b/src/modules/engines.rs
@@ -0,0 +1,70 @@
+use mass::Mass;
+
+#[derive(Serialize, Deserialize, Debug, Clone)]
+pub struct Engines {
+ acceleration : (f64, f64, f64),
+}
+
+impl Engines {
+ pub fn new() -> Engines {
+ Engines {
+ acceleration : (0.0, 0.0, 0.0)
+ }
+ }
+
+ pub fn recv_acceleration(&mut self) -> (f64, f64, f64) {
+ let acceleration = self.acceleration;
+ self.acceleration = (0.0, 0.0, 0.0);
+ acceleration
+ }
+
+ 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,
+ b"0\n" => acceleration.0 -= 0.1,
+ b"8\n" => acceleration.1 += 0.1,
+ b"2\n" => acceleration.1 -= 0.1,
+ b"4\n" => acceleration.2 += 0.1,
+ 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);
+ },
+ 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);
+ },
+ 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 => (),
+ }
+ },
+ 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 => (),
+ }
+ },
+ _ => (),
+ }
+ self.acceleration = acceleration;
+ }
+}
diff --git a/src/modules/mining.rs b/src/modules/mining.rs
new file mode 100644
index 0000000..e22918f
--- /dev/null
+++ b/src/modules/mining.rs
@@ -0,0 +1,23 @@
+use std::time::SystemTime;
+
+#[derive(Serialize, Deserialize, Debug, Clone)]
+pub struct Mining {
+ pub range : f64,
+ pub status : bool,
+ time : u64,
+ start : Option<SystemTime>,
+}
+
+
+impl Mining {
+ pub fn new() -> Mining {
+ Mining {
+ range : 10.0,
+ status : false,
+ time : 1,
+ start : None,
+ }
+ }
+
+ pub fn toggle(&self) {}
+}
diff --git a/src/modules/mod.rs b/src/modules/mod.rs
new file mode 100644
index 0000000..0c19156
--- /dev/null
+++ b/src/modules/mod.rs
@@ -0,0 +1,5 @@
+pub mod mining;
+pub mod engines;
+pub mod dashboard;
+pub mod navigation;
+pub mod types;
diff --git a/src/modules/navigation.rs b/src/modules/navigation.rs
new file mode 100644
index 0000000..179a766
--- /dev/null
+++ b/src/modules/navigation.rs
@@ -0,0 +1,64 @@
+use std::time::SystemTime;
+use std::collections::HashMap;
+
+use mass::Mass;
+use math::distance;
+
+#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
+pub enum NavigationStatus {
+ None,
+ Targeting,
+ Targeted,
+}
+
+#[derive(Serialize, Deserialize, Debug, Clone)]
+pub struct Navigation {
+ 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,
+ }
+ }
+
+ pub fn process(&mut self) {
+ match self.start.clone() {
+ Some(timer) => {
+ if timer.elapsed().unwrap().as_secs() > self.time {
+ self.status = NavigationStatus::Targeted;
+ self.start = None;
+ }
+ }
+ _ => (),
+ }
+ }
+
+ 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>) {
+ match self.target_name.clone() {
+ Some(name) => {
+ let target = masses.get(&name).unwrap();
+ if distance(target.position, ship_position) > self.range {
+ self.target_name = None;
+ self.status = NavigationStatus::None;
+ }
+ }
+ _ => (),
+ }
+ }
+}
diff --git a/src/modules/types.rs b/src/modules/types.rs
new file mode 100644
index 0000000..1af99d6
--- /dev/null
+++ b/src/modules/types.rs
@@ -0,0 +1,7 @@
+#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
+pub enum ModuleType {
+ Navigation,
+ Mining,
+ Engines,
+ Dashboard,
+}