summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2018-07-21 23:40:46 +0200
committerJustin Worthe <justin@worthe-it.co.za>2018-07-21 23:40:46 +0200
commit889907e32692cd26567db76585710be9071dfe5f (patch)
treebb616d1b87a88d23ad04037d300950022c3a3e26 /src
parent8fdd6e813c4b88332f0e91350dab7d080087aee2 (diff)
More efficient opponent damage calc
Diffstat (limited to 'src')
-rw-r--r--src/engine/bitwise_engine.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/engine/bitwise_engine.rs b/src/engine/bitwise_engine.rs
index 8a3157e..49b780d 100644
--- a/src/engine/bitwise_engine.rs
+++ b/src/engine/bitwise_engine.rs
@@ -366,11 +366,12 @@ impl BitwiseGameState {
fn move_and_collide_missiles(opponent: &mut Player, opponent_buildings: &mut PlayerBuildings, player_missiles: &mut [(u64, u64); MISSILE_MAX_SINGLE_CELL]) {
let mut destroyed = 0;
+ let mut damaging = 0;
for _ in 0..MISSILE_SPEED {
for i in 0..MISSILE_MAX_SINGLE_CELL {
let about_to_hit_opponent = player_missiles[i].1 & LEFT_COL_MASK;
- let damage = about_to_hit_opponent.count_ones() as u8 * MISSILE_DAMAGE;
- opponent.health = opponent.health.saturating_sub(damage);
+ damaging = damaging << 1;
+ damaging |= about_to_hit_opponent;
player_missiles[i].1 = (player_missiles[i].1 & !LEFT_COL_MASK) >> 1;
let swapping_sides = player_missiles[i].0 & RIGHT_COL_MASK;
@@ -386,6 +387,9 @@ impl BitwiseGameState {
destroyed |= hits;
}
}
+ let damage = damaging.count_ones() as u8 * MISSILE_DAMAGE;
+ opponent.health = opponent.health.saturating_sub(damage);
+
BitwiseGameState::destroy_buildings(opponent_buildings, destroyed);
BitwiseGameState::update_tesla_activity(opponent_buildings);
}