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/mass.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/mass.rs') diff --git a/src/mass.rs b/src/mass.rs index 85651d4..4bb44b0 100644 --- a/src/mass.rs +++ b/src/mass.rs @@ -48,7 +48,6 @@ impl Mass { resources.push(Item::new("Iron", 1)); } - let astroid = MassType::Astroid { resources : Storage::new(resources), }; @@ -88,7 +87,8 @@ impl Mass { pub fn process(&mut self) { let mut acceleration = (0.0, 0.0, 0.0); match self.mass_type { - MassType::Ship{ref mut navigation, ref mut engines, ..} => { + MassType::Ship{ref mut navigation, ref mut engines, ref mut mining, ..} => { + mining.as_mut().unwrap().process(); navigation.as_mut().unwrap().process(); acceleration = engines.as_mut().unwrap().recv_acceleration(); }, @@ -105,4 +105,18 @@ impl Mass { self.velocity.1 += acceleration.1; self.velocity.2 += acceleration.2; } + + pub fn take(&mut self, name : &str) -> Option { + match self.mass_type { + MassType::Ship{ref mut storage, ..} => storage.take(name), + MassType::Astroid{ref mut resources, ..} => resources.take(name), + } + } + + pub fn give(&mut self, item : Item) { + match self.mass_type { + MassType::Ship{ref mut storage, ..} => storage.give(item), + MassType::Astroid{ref mut resources, ..} => resources.give(item), + } + } } -- cgit v1.2.3