summaryrefslogtreecommitdiff
path: root/src/json.rs
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2018-05-16 23:45:36 +0200
committerJustin Worthe <justin@worthe-it.co.za>2018-05-16 23:45:36 +0200
commit8c611df4d8bc412588b25ca09577827cc32971e9 (patch)
treebf4c7d094c3956ebafda448d7839581e0499f411 /src/json.rs
parent484310110410f26dc0de538855c8a9c20f03d5bf (diff)
Tracked energy production on the player
This cuts out an iteration over the buildings each turn.
Diffstat (limited to 'src/json.rs')
-rw-r--r--src/json.rs17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/json.rs b/src/json.rs
index 5dc65f6..02dbe1b 100644
--- a/src/json.rs
+++ b/src/json.rs
@@ -119,13 +119,15 @@ impl State {
}
fn to_engine(&self, settings: &engine::settings::GameSettings) -> engine::GameState {
+ let player_buildings = self.buildings_to_engine('A');
+ let opponent_buildings = self.buildings_to_engine('B');
engine::GameState::new(
- self.player().to_engine(),
- self.opponent().to_engine(),
+ self.player().to_engine(settings, &player_buildings),
+ self.opponent().to_engine(settings, &opponent_buildings),
self.unconstructed_buildings_to_engine('A'),
- self.buildings_to_engine('A'),
+ player_buildings,
self.unconstructed_buildings_to_engine('B'),
- self.buildings_to_engine('B'),
+ opponent_buildings,
self.missiles_to_engine('A'),
self.missiles_to_engine('B'),
settings
@@ -195,11 +197,8 @@ impl BuildingBlueprint {
}
impl Player {
- fn to_engine(&self) -> engine::Player {
- engine::Player {
- energy: self.energy,
- health: self.health,
- }
+ fn to_engine(&self, settings: &engine::settings::GameSettings, buildings: &[engine::Building]) -> engine::Player {
+ engine::Player::new(self.energy, self.health, settings, buildings)
}
}