summaryrefslogtreecommitdiff
path: root/src/game.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/game.rs')
-rw-r--r--src/game.rs35
1 files changed, 30 insertions, 5 deletions
diff --git a/src/game.rs b/src/game.rs
index ffa8cb9..a08fff2 100644
--- a/src/game.rs
+++ b/src/game.rs
@@ -14,6 +14,7 @@ use map::*;
use arrayvec::ArrayVec;
use fnv::FnvHashSet;
+// TODO: How much sense does it actually make to split the worms between the players?
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct GameBoard {
pub round: u16,
@@ -47,6 +48,7 @@ impl GameBoard {
position: Point2d::new(w.position.x, w.position.y),
weapon_damage: commando_damage,
weapon_range: commando_range,
+ bombs: w.banana_bombs.as_ref().map(|b| b.count).unwrap_or(0)
}).collect(),
};
@@ -59,7 +61,8 @@ impl GameBoard {
health: w.health,
position: Point2d::new(w.position.x, w.position.y),
weapon_damage: commando_damage,
- weapon_range: commando_range
+ weapon_range: commando_range,
+ bombs: if w.health == 100 { 3 } else { 0 } // TODO: parse and check worm type rather, move these out to constants
}).collect()
};
@@ -143,7 +146,7 @@ impl GameBoard {
self.simulate_select(moves);
self.simulate_moves(actions);
self.simulate_digs(actions);
- // TODO: simulate_bombs
+ self.simulate_bombs(actions);
self.simulate_shoots(actions);
for player in &mut self.players {
@@ -244,6 +247,28 @@ impl GameBoard {
}
}
}
+
+ fn simulate_bombs(&mut self, actions: [Action; 2]) {
+ // NB: Damage radius has the cell distance rounded UP, throwing range has the cell distance rounded DOWN
+
+ for player_index in 0..actions.len() {
+ if let Action::Bomb(p) = actions[player_index] {
+ if let Some(worm) = self.players[player_index].active_worm_mut() {
+ debug_assert!(worm.bombs > 0, "Worm is throwing a bomb it doesn't have");
+ debug_assert!((worm.position - p).magnitude_squared() < 6*6); // max range is 5, but it's 5 after rounding down
+
+ worm.bombs = worm.bombs.saturating_sub(1);
+
+ let damage_radius = 2;
+ // damage as per https://forum.entelect.co.za/uploads/default/original/2X/8/89e6e6cf35791a0448b5a6bbeb63c558ce41804a.jpeg
+
+ // TODO: Clear up dirt and give points
+ // TODO: Hurt all worm and give / remove points
+ }
+ }
+ }
+
+ }
fn simulate_shoots(&mut self, actions: [Action; 2]) {
'players_loop: for player_index in 0..actions.len() {
@@ -255,7 +280,7 @@ impl GameBoard {
let diff = dir.as_vec();
let range = if dir.is_diagonal() {
- ((weapon_range as f32 + 1.) / 2f32.sqrt()).floor() as i8
+ ((f32::from(weapon_range) + 1.) / 2f32.sqrt()).floor() as i8
} else {
weapon_range as i8
};
@@ -271,10 +296,10 @@ impl GameBoard {
if let Some(target_worm) = target_own_worm {
target_worm.health -= weapon_damage;
if target_worm.health <= 0 {
- // TODO: This will probably be changed soon https://github.com/EntelectChallenge/2019-Worms/issues/42
- self.players[player_index].moves_score += 40;
+ self.players[player_index].moves_score -= 40;
self.occupied_cells.remove(&target_worm.position);
} else {
+ // TODO: Review these points
self.players[player_index].moves_score -= 20;
}
continue 'players_loop;