From 889907e32692cd26567db76585710be9071dfe5f Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Sat, 21 Jul 2018 23:40:46 +0200 Subject: More efficient opponent damage calc --- src/engine/bitwise_engine.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') 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); } -- cgit v1.2.3