From fb61488ef45611d22027923e36746903b266f6b6 Mon Sep 17 00:00:00 2001 From: Andrey Lesnikov Date: Sun, 29 Jan 2017 18:26:51 +0300 Subject: [PATCH] #239: Fixed weird bug with CreateUnit/ShowUnit events --- core/src/game_state.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core/src/game_state.rs b/core/src/game_state.rs index fbc7f3b..72fe871 100644 --- a/core/src/game_state.rs +++ b/core/src/game_state.rs @@ -210,13 +210,6 @@ impl State { fn add_unit(&mut self, unit: &Unit) { assert!(self.units.get(&unit.id).is_none()); - let unit_type = self.db.unit_type(unit.type_id); - let reinforcement_points = self.reinforcement_points - .get_mut(&unit.player_id).unwrap(); - if *reinforcement_points < unit_type.cost { - return; - } - reinforcement_points.n -= unit_type.cost.n; self.units.insert(unit.id, unit.clone()); } @@ -337,6 +330,13 @@ impl State { } }, CoreEvent::CreateUnit{ref unit_info} => { + { + let unit_type = self.db.unit_type(unit_info.type_id); + let reinforcement_points = self.reinforcement_points + .get_mut(&unit_info.player_id).unwrap(); + assert!(*reinforcement_points >= unit_type.cost); + reinforcement_points.n -= unit_type.cost.n; + } self.add_unit(unit_info); }, CoreEvent::AttackUnit{ref attack_info} => {