summaryrefslogtreecommitdiff
path: root/src/ships.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/ships.rs')
-rw-r--r--src/ships.rs71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/ships.rs b/src/ships.rs
index 104e986..422f24e 100644
--- a/src/ships.rs
+++ b/src/ships.rs
@@ -1,6 +1,8 @@
use std::fmt;
use std::str;
+use math::*;
+
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Serialize, Deserialize)]
pub enum Weapon {
SingleShot,
@@ -61,6 +63,75 @@ impl Weapon {
//weird plus is to make the integer rounding up instead of down
(required_energy + energy_per_round - 1) / energy_per_round
}
+
+ pub fn affected_cells(&self, target: Point, map_size: u16) -> Vec<Point> {
+ use Weapon::*;
+
+ let p = target;
+ match self {
+ &SingleShot => {
+ vec!(Some(p))
+ },
+ &DoubleShotVertical => {
+ vec!(
+ p.move_point(Direction::North, 1, map_size),
+ p.move_point(Direction::South, 1, map_size)
+ )
+ },
+ &DoubleShotHorizontal => {
+ vec!(
+ p.move_point(Direction::East, 1, map_size),
+ p.move_point(Direction::West, 1, map_size)
+ )
+ },
+ &CornerShot => {
+ vec!(
+ p.move_point(Direction::NorthEast, 1, map_size),
+ p.move_point(Direction::SouthEast, 1, map_size),
+ p.move_point(Direction::NorthWest, 1, map_size),
+ p.move_point(Direction::SouthWest, 1, map_size),
+ )
+ },
+ &CrossShotDiagonal => {
+ vec!(
+ p.move_point(Direction::NorthEast, 1, map_size),
+ p.move_point(Direction::SouthEast, 1, map_size),
+ p.move_point(Direction::NorthWest, 1, map_size),
+ p.move_point(Direction::SouthWest, 1, map_size),
+ Some(p)
+ )
+ },
+ &CrossShotHorizontal => {
+ vec!(
+ p.move_point(Direction::North, 1, map_size),
+ p.move_point(Direction::East, 1, map_size),
+ p.move_point(Direction::South, 1, map_size),
+ p.move_point(Direction::West, 1, map_size),
+ Some(p)
+ )
+ },
+ &SeekerMissle => {
+ vec!(
+ Some(p),
+
+ p.move_point(Direction::North, 1, map_size),
+ p.move_point(Direction::East, 1, map_size),
+ p.move_point(Direction::South, 1, map_size),
+ p.move_point(Direction::West, 1, map_size),
+
+ p.move_point(Direction::NorthEast, 1, map_size),
+ p.move_point(Direction::SouthEast, 1, map_size),
+ p.move_point(Direction::NorthWest, 1, map_size),
+ p.move_point(Direction::SouthWest, 1, map_size),
+
+ p.move_point(Direction::North, 2, map_size),
+ p.move_point(Direction::East, 2, map_size),
+ p.move_point(Direction::South, 2, map_size),
+ p.move_point(Direction::West, 2, map_size)
+ )
+ }
+ }.iter().filter_map(|&p| p).collect::<Vec<_>>()
+ }
}