From 233aa5d803e8015f78f663bc9af6bb33e56eb96e Mon Sep 17 00:00:00 2001 From: tom barrett Date: Thu, 1 Mar 2018 03:51:36 -0600 Subject: -added copying of mass vector, fixed buildmass bug, and allow giving of target --- src/ship.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/ship.rs') diff --git a/src/ship.rs b/src/ship.rs index 08b4d93..2482db1 100644 --- a/src/ship.rs +++ b/src/ship.rs @@ -1,7 +1,7 @@ use mass::{Mass, Type}; extern crate serde_json; -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, Clone)] pub struct Ship { name : String, position : (f64, f64, f64), @@ -22,14 +22,6 @@ impl Ship { target : None, } } - - pub fn give_target(&mut self, target : Option) { - self.target = target; - } - - pub fn range(&self) -> f64 { - self.r - } } impl Mass for Ship { @@ -45,6 +37,14 @@ impl Mass for Ship { serde_json::to_string(self).unwrap() } + fn range(&self) -> f64 { + self.r + } + + fn give_target(&mut self, target : Option) { + self.target = target; + } + fn slow(&mut self) { if self.velocity.0 > 0.01 { self.velocity.0 += -1.0 * self.velocity.0 * 0.1; @@ -68,6 +68,10 @@ impl Mass for Ship { } } + fn box_clone(&self) -> Box { + Box::new((*self).clone()) + } + fn process(&mut self) { self.position.0 += self.velocity.0; self.position.1 += self.velocity.1; -- cgit v1.2.3