Added max building price to game settings
authorJustin Worthe <justin@worthe-it.co.za>
Sat, 9 Jun 2018 08:04:47 +0000 (10:04 +0200)
committerJustin Worthe <justin@worthe-it.co.za>
Sat, 9 Jun 2018 08:04:47 +0000 (10:04 +0200)
Cargo.toml
src/engine/settings.rs
src/input/json.rs
src/input/textmap.rs

index 92a7ad4..da4623f 100644 (file)
@@ -11,8 +11,6 @@ rand = "0.4.2"
 time = "0.1.4"
 rayon = "1.0.1"
 
-[profile.release]
-debug = true
 
 [features]
 benchmarking = []
index 40256d9..ec62408 100644 (file)
@@ -1,10 +1,12 @@
 use super::geometry::Point;
 use super::command::BuildingType;
+use std::cmp;
 
 #[derive(Debug)]
 pub struct GameSettings {
     pub size: Point,
     pub energy_income: u16,
+    pub max_building_price: u16,
     pub energy: BuildingSettings,
     pub defence: BuildingSettings,
     pub attack: BuildingSettings
@@ -22,6 +24,13 @@ pub struct BuildingSettings {
 }
 
 impl GameSettings {
+    pub fn new(size: Point, energy_income: u16, energy: BuildingSettings, defence: BuildingSettings, attack: BuildingSettings) -> GameSettings {
+        let max_building_price = cmp::max(cmp::max(energy.price, defence.price), attack.price);
+        GameSettings {
+            size, energy_income, max_building_price,
+            energy, defence, attack
+        }
+    }
     pub fn building_settings(&self, building: BuildingType) -> &BuildingSettings {
         match building {
             BuildingType::Defence => &self.defence,
index 3a3fbf2..ed00984 100644 (file)
@@ -110,13 +110,13 @@ struct MissileState {
 
 impl State {
     fn to_engine_settings(&self) -> engine::settings::GameSettings {
-        engine::settings::GameSettings {
-            size: engine::geometry::Point::new(self.game_details.map_width, self.game_details.map_height),
-            energy_income: self.game_details.round_income_energy,
-            energy: self.game_details.buildings_stats.energy.to_engine(),
-            defence: self.game_details.buildings_stats.defense.to_engine(),
-            attack: self.game_details.buildings_stats.attack.to_engine(),
-        }
+        engine::settings::GameSettings::new(
+            engine::geometry::Point::new(self.game_details.map_width, self.game_details.map_height),
+            self.game_details.round_income_energy,
+            self.game_details.buildings_stats.energy.to_engine(),
+            self.game_details.buildings_stats.defense.to_engine(),
+            self.game_details.buildings_stats.attack.to_engine(),
+        )
     }
     
     fn to_engine(&self, settings: &engine::settings::GameSettings) -> engine::GameState {
index 79fbe7f..5481770 100644 (file)
@@ -14,10 +14,10 @@ pub fn read_state_from_file(filename: &str) -> Result<(GameSettings, GameState),
 
     //TODO actually read the right file and parse it?
 
-    let engine_settings = GameSettings {
-        size: Point::new(8,4),
-        energy_income: 5,
-        energy: BuildingSettings {
+    let engine_settings = GameSettings::new(
+        Point::new(8,4),
+        5,
+        BuildingSettings {
             price: 20,
             health: 5,
             construction_time: 2-2,
@@ -26,7 +26,7 @@ pub fn read_state_from_file(filename: &str) -> Result<(GameSettings, GameState),
             weapon_cooldown_period: 0,
             energy_generated_per_turn: 3
         },
-        defence: BuildingSettings {
+        BuildingSettings {
             price: 30,
             health: 20,
             construction_time: 4-2,
@@ -35,7 +35,7 @@ pub fn read_state_from_file(filename: &str) -> Result<(GameSettings, GameState),
             weapon_cooldown_period: 0,
             energy_generated_per_turn: 0
         },
-        attack: BuildingSettings {
+        BuildingSettings {
             price: 30,
             health: 5,
             construction_time: 2-2,
@@ -44,7 +44,7 @@ pub fn read_state_from_file(filename: &str) -> Result<(GameSettings, GameState),
             weapon_cooldown_period: 3,
             energy_generated_per_turn: 0
         }
-    };
+    );
     let engine_state = GameState::new(
         Player {
             energy: 20,