summaryrefslogtreecommitdiff
path: root/src/engine/mod.rs
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2018-05-31 22:53:19 +0200
committerJustin Worthe <justin@worthe-it.co.za>2018-05-31 22:53:19 +0200
commit58753f08d5b12670625184c81f95122f356c6f9b (patch)
treeafce681b8dc0d7b5f01e1140eec9d615081513a9 /src/engine/mod.rs
parentd41a080a2c9de8d9cb46c5b9ef91270d2981a4a3 (diff)
Tighter loop for removing destroyed buildings
Diffstat (limited to 'src/engine/mod.rs')
-rw-r--r--src/engine/mod.rs24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/engine/mod.rs b/src/engine/mod.rs
index 13cb596..bd8922f 100644
--- a/src/engine/mod.rs
+++ b/src/engine/mod.rs
@@ -205,11 +205,19 @@ impl GameState {
missile.speed = 0;
}
else {
- // TODO latest game engine may be checking building health here
- if let Some(mut hit) = opponent_buildings.iter_mut().find(|b| b.pos == missile.pos) {
- let damage = cmp::min(missile.damage, hit.health);
- hit.health -= damage;
- missile.speed = 0;
+ for b in 0..opponent_buildings.len() {
+ // TODO latest game engine may be checking building health here
+ if opponent_buildings[b].pos == missile.pos {
+ let damage = cmp::min(missile.damage, opponent_buildings[b].health);
+ opponent_buildings[b].health -= damage;
+ missile.speed = 0;
+ if opponent_buildings[b].health == 0 {
+ unoccupied_cells.push(opponent_buildings[b].pos);
+ opponent.energy_generated -= opponent_buildings[b].energy_generated_per_turn;
+ opponent_buildings.swap_remove(b);
+ break;
+ }
+ }
}
}
@@ -219,12 +227,6 @@ impl GameState {
}
}
swap_retain(missiles, |m| m.speed > 0);
-
- for b in opponent_buildings.iter().filter(|b| b.health == 0) {
- unoccupied_cells.push(b.pos);
- opponent.energy_generated -= b.energy_generated_per_turn;
- }
- swap_retain(opponent_buildings, |b| b.health > 0);
}
fn add_energy(player: &mut Player) {