From e5a09e11e8a99440d22d9f4cbde97f0e3d6fca7b Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Wed, 29 Aug 2018 20:52:15 +0200 Subject: Added targeted waiting to evaluated moves --- src/engine/command.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/engine/command.rs') diff --git a/src/engine/command.rs b/src/engine/command.rs index d026bca..764e3cb 100644 --- a/src/engine/command.rs +++ b/src/engine/command.rs @@ -1,4 +1,5 @@ use std::fmt; +use super::constants::*; use super::geometry::Point; #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -18,6 +19,19 @@ impl fmt::Display for Command { } } +impl Command { + pub fn cant_build_yet(&self, energy: u16) -> bool { + use self::Command::*; + + match self { + Nothing => false, + Build(_, b) => b.cant_build_yet(energy), + IronCurtain => energy < IRON_CURTAIN_PRICE + } + } +} + + #[repr(u8)] #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum BuildingType { @@ -38,4 +52,15 @@ impl BuildingType { if id <= 4 && id != 3 { Some(unsafe { mem::transmute(id) }) } else { None } } + pub fn cant_build_yet(&self, energy: u16) -> bool { + use self::BuildingType::*; + + let required = match self { + Defence => DEFENCE_PRICE, + Attack => MISSILE_PRICE, + Energy => ENERGY_PRICE, + Tesla => TESLA_PRICE + }; + energy < required + } } -- cgit v1.2.3