summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortom barrett <spalf0@gmail.com>2018-06-25 08:36:57 -0500
committertom barrett <spalf0@gmail.com>2018-06-25 08:36:57 -0500
commit39b16e379fb679aa56ded8ab5463569e5633a656 (patch)
tree446c1f2e609836c61109aa27400ac4bf2155c7dc
parent7094849bf164ff6f853c8f6812a0e831a66762f3 (diff)
added item mass, allow stopping of ship, if storage is full item goes into space
-rw-r--r--README.md7
-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
7 files changed, 66 insertions, 13 deletions
diff --git a/README.md b/README.md
index 700827e..23a26ae 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,12 @@ ideas
- tiers of minerals, modules
- pretty dashboard
- better client cli parsing (e.g. ability to do ./client navigation)
-- some sort of energy / fuel mechanic
+- some sort of energy / fuel mechanic for all processes, solar panels if stranded
- server ability to quit and import/export all data
- collisions
- figure how position floats overflow and how to improve it
+- figure out spawning
+- figure out some sort of dynamic zone system
+- figure out other bodies (planets, suns, n-body simulation?)
+- bookmarking objects (e.g. stations, estimates position & velocity outside navigation)
+- maybe create interface with masses data
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,
+ }
}
}