diff options
author | tom barrett <spalf0@gmail.com> | 2018-04-05 04:48:50 -0500 |
---|---|---|
committer | tom barrett <spalf0@gmail.com> | 2018-04-05 04:48:50 -0500 |
commit | 9c094a4ef0a8db67e0f58904d46e6ad076415278 (patch) | |
tree | c9336249cb252a6ca75ed5981e3ef391827611a9 | |
parent | 9bbd8b1c7039c046ca3992e4a9e1ceefda80f816 (diff) |
-cleanup of targeting vars
-rw-r--r-- | src/ship.rs | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/ship.rs b/src/ship.rs index 090cd7d..f97e4d2 100644 --- a/src/ship.rs +++ b/src/ship.rs @@ -1,4 +1,4 @@ -use std::time::{Duration, Instant, SystemTime}; +use std::time::SystemTime; use module::Module; use mass::{Mass, Type}; @@ -89,8 +89,16 @@ impl Ship { pub fn give_target(&mut self, target : Option<usize>) { self.targeting.target = target; - self.targeting.status = TargetingStatus::Targeting; - self.targeting.start = Some(SystemTime::now()); + match self.targeting.target { + Some(_) => { + self.targeting.status = TargetingStatus::Targeting; + self.targeting.start = Some(SystemTime::now()); + }, + None => { + self.targeting.status = TargetingStatus::None; + self.targeting.start = None; + } + } } pub fn recv_target(&self) -> Option<usize> { @@ -114,11 +122,13 @@ impl Mass for Ship { self.position.0 += self.velocity.0; self.position.1 += self.velocity.1; self.position.2 += self.velocity.2; + match self.targeting.start { Some(time) => { - if time.elapsed().unwrap().as_secs() > self.targeting.time { - self.targeting.status = TargetingStatus::Targeted; - } + if time.elapsed().unwrap().as_secs() > self.targeting.time { + self.targeting.status = TargetingStatus::Targeted; + self.targeting.start = None; + } } None => (), } |