summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/engines.rs7
-rw-r--r--src/item.rs11
-rw-r--r--src/mass.rs18
-rw-r--r--src/modules/engines.rs6
-rw-r--r--src/server/mining.rs9
-rw-r--r--src/storage.rs21
6 files changed, 60 insertions, 12 deletions
diff --git a/src/client/engines.rs b/src/client/engines.rs
index b6f5f93..6c6b384 100644
--- a/src/client/engines.rs
+++ b/src/client/engines.rs
@@ -22,11 +22,12 @@ pub fn client_engines(mut stream : TcpStream, mut buff_r : BufReader<TcpStream>)
write!(stdout, "{}{}use numpad to freely move\n", termion::clear::All, termion::cursor::Goto(1, 1)).unwrap();
write!(stdout, "{}+ : speedup", termion::cursor::Goto(1, 2)).unwrap();
write!(stdout, "{}- : slowdown", termion::cursor::Goto(1, 3)).unwrap();
- write!(stdout, "{}q : quit", termion::cursor::Goto(1, 4)).unwrap();
+ write!(stdout, "{}s : stop", termion::cursor::Goto(1, 4)).unwrap();
+ write!(stdout, "{}q : quit", termion::cursor::Goto(1, 5)).unwrap();
if has_target {
- write!(stdout, "{}c : mimic targets velocity vector", termion::cursor::Goto(1,5)).unwrap();
- write!(stdout, "{}t : accelerate torwards target", termion::cursor::Goto(1,6)).unwrap();
+ write!(stdout, "{}c : mimic targets velocity vector", termion::cursor::Goto(1, 6)).unwrap();
+ write!(stdout, "{}t : accelerate torwards target", termion::cursor::Goto(1, 7)).unwrap();
}
match stdin.next() {
diff --git a/src/item.rs b/src/item.rs
index 90c9ed8..f9c7490 100644
--- a/src/item.rs
+++ b/src/item.rs
@@ -1,7 +1,7 @@
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Item {
pub name : String,
- size : usize,
+ pub size : usize,
}
impl Item {
@@ -11,4 +11,13 @@ impl Item {
size : size,
}
}
+
+ pub fn is_mineral(&self) -> bool {
+ if self.name == "Iron" {
+ true
+ }
+ else {
+ false
+ }
+ }
}
diff --git a/src/mass.rs b/src/mass.rs
index 96244c0..252de49 100644
--- a/src/mass.rs
+++ b/src/mass.rs
@@ -29,9 +29,12 @@ pub enum MassType {
dashboard : Option<Dashboard>,
navigation : Option<Navigation>,
},
- Astroid{
+ Astroid {
resources : Storage,
},
+ Item {
+ item : Item,
+ }
}
impl Mass {
@@ -78,6 +81,14 @@ impl Mass {
}
}
+ pub fn new_item(item : Item, position : (f64, f64, f64), velocity : (f64, f64, f64)) -> Mass {
+ Mass {
+ mass_type : MassType::Item{item : item},
+ position : position,
+ velocity : velocity,
+ }
+ }
+
pub fn get_modules(&self) -> Vec<ModuleType> {
let mut modules = Vec::new();
modules.push(ModuleType::Mining);
@@ -115,6 +126,7 @@ impl Mass {
match self.mass_type {
MassType::Ship{ref storage, ..} => storage.has_minerals(),
MassType::Astroid{ref resources, ..} => resources.has_minerals(),
+ _ => false,
}
}
@@ -122,13 +134,15 @@ impl Mass {
match self.mass_type {
MassType::Ship{ref mut storage, ..} => storage.take(name),
MassType::Astroid{ref mut resources, ..} => resources.take(name),
+ _ => None,
}
}
- pub fn give(&mut self, item : Item) {
+ pub fn give(&mut self, item : Item) -> bool {
match self.mass_type {
MassType::Ship{ref mut storage, ..} => storage.give(item),
MassType::Astroid{ref mut resources, ..} => resources.give(item),
+ _ => false,
}
}
}
diff --git a/src/modules/engines.rs b/src/modules/engines.rs
index 10e4c85..4741a03 100644
--- a/src/modules/engines.rs
+++ b/src/modules/engines.rs
@@ -39,6 +39,12 @@ impl Engines {
-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);
+ },
b"c\n" => {
match target {
Some(target) => {
diff --git a/src/server/mining.rs b/src/server/mining.rs
index a54ce33..3cf5f0b 100644
--- a/src/server/mining.rs
+++ b/src/server/mining.rs
@@ -56,7 +56,13 @@ impl ServerConnection {
}
match item {
- Some(item) => ship.give(item),
+ Some(item) => match ship.give(item.clone()) {
+ false => {
+ let mass = Mass::new_item(item.clone(), ship.position, ship.velocity);
+ masses.insert(item.name.clone(), mass);
+ }
+ true => (),
+ }
None => (),
}
@@ -84,7 +90,6 @@ impl ServerConnection {
}
_ => (),
}
-
false
}
}
diff --git a/src/storage.rs b/src/storage.rs
index 6aa8417..3c6e684 100644
--- a/src/storage.rs
+++ b/src/storage.rs
@@ -3,19 +3,25 @@ use item::Item;
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Storage {
items : Vec<Item>,
+ carrying : usize,
capacity : usize,
}
impl Storage {
pub fn new(items : Vec<Item>) -> Storage {
+ let mut carrying = 0;
+ for item in items.iter() {
+ carrying += item.size;
+ }
Storage {
items : items,
- capacity : 100,
+ capacity : 10,
+ carrying : carrying,
}
}
pub fn has_minerals(&self) -> bool {
- match self.items.iter().position(|item| item.name == "Iron") {
+ match self.items.iter().position(|item| item.is_mineral()) {
Some(_) => true,
None => false,
}
@@ -28,7 +34,14 @@ impl Storage {
}
}
- pub fn give(&mut self, item : Item) {
- self.items.push(item);
+ pub fn give(&mut self, item : Item) -> bool {
+ match self.capacity >= self.carrying + item.size {
+ true => {
+ self.carrying += item.size;
+ self.items.push(item);
+ true
+ },
+ false => false,
+ }
}
}