From 9c094a4ef0a8db67e0f58904d46e6ad076415278 Mon Sep 17 00:00:00 2001 From: tom barrett Date: Thu, 5 Apr 2018 04:48:50 -0500 Subject: -cleanup of targeting vars --- src/ship.rs | 22 ++++++++++++++++------ 1 file 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) { 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 { @@ -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 => (), } -- cgit v1.2.3