From f6c9fbea8f535febaf51dc08c353e985aa73988d Mon Sep 17 00:00:00 2001 From: tom barrett Date: Tue, 5 Jun 2018 02:21:04 -0500 Subject: frail implementation of mining --- src/server/mining.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src/server') diff --git a/src/server/mining.rs b/src/server/mining.rs index c64f03e..91210f8 100644 --- a/src/server/mining.rs +++ b/src/server/mining.rs @@ -14,8 +14,8 @@ use server::connection::ServerConnection; pub struct MiningData { pub has_astroid_target : bool, pub is_within_range : bool, - pub range : f64, pub status : bool, + pub range : f64, } impl ServerConnection { @@ -23,6 +23,7 @@ impl ServerConnection { let mut ship = masses.remove(&self.name).unwrap(); let ship_clone = ship.clone(); let mut connection_good = true; + let mut item = None; if let MassType::Ship{ref mut mining, ref navigation, ..} = ship.mass_type { let mut mining = mining.as_mut().unwrap(); @@ -51,6 +52,27 @@ impl ServerConnection { } Err(_error) => (), } + + if !mining_data.is_within_range { + mining.off(); + } + else { + if mining.status && mining.ready { + mining.take(); + match navigation.target_name.clone() { + Some(name) => { + let target = masses.get_mut(&name).unwrap(); + item = target.take("Iron"); + } + _ => (), + } + } + } + } + + match item { + Some(item) => ship.give(item), + None => (), } masses.insert(self.name.clone(), ship); -- cgit v1.2.3