diff --git a/crates/border-wars/src/actions/mod.rs b/crates/border-wars/src/actions/mod.rs index 02cccda..d3d342f 100644 --- a/crates/border-wars/src/actions/mod.rs +++ b/crates/border-wars/src/actions/mod.rs @@ -1,5 +1,7 @@ //! All programs related to the actions that you can do with all tiles. +use bevy::prelude::*; + use crate::map::Tile; /// A number of action points. This is decreased when you do an action. @@ -8,50 +10,64 @@ pub struct ActionPoint(pub u32); /// The action that you can do with a tile. pub enum Action { /// Build something on the tile. - Build(u32), + Build(Entity), /// Destroy something on the tile. - Destroy(u32), + Destroy(Entity), /// Recolt something on the tile. - Recolt(u32), + Recolt(Entity), /// Upgrade the tile. - Upgrade(u32), + Upgrade(Entity), /// Manage the villages. VillageManagement, /// Manage the troops. TroopManagement, + + /// Teleport management. + TeleportManagement(Entity), } impl Tile { /// Get the actions that you can do with the tile. - pub fn get_action(&self, index_of_tile: u32) -> Vec { + pub fn get_action(&self, tile_entity: Entity) -> Vec { let mut actions = vec![]; if let Self::Breeding | Self::Casern | Self::Castle | Self::Mine - | Self::Outpost | Self::Sawmill | Self::Tower = *self { - actions.push(Action::Upgrade(index_of_tile)); + actions.push(Action::Upgrade(tile_entity)); } if let Self::Breeding | Self::Casern | Self::Mine | Self::Outpost | Self::Sawmill = *self { - actions.push(Action::Destroy(index_of_tile)); + actions.push(Action::Destroy(tile_entity)); } - if let Self::Breeding | Self::Casern = *self { + if matches!(*self, Self::Casern) { actions.push(Action::TroopManagement); } - if let Self::Breeding | Self::Hill = *self { - actions.push(Action::Recolt(index_of_tile)); + if let Self::Forest | Self::Hill = *self { + actions.push(Action::Recolt(tile_entity)); + } + + if matches!(*self, Self::Castle) { + actions.push(Action::VillageManagement); + } + + if matches!(*self, Self::Grass) { + actions.push(Action::Build(tile_entity)); + } + + if matches!(*self, Self::Outpost) { + actions.push(Action::TeleportManagement(tile_entity)); } actions @@ -60,14 +76,15 @@ impl Tile { impl Action { /// Get the cost of an action. - pub fn point_cost(&self) -> ActionPoint { + pub const fn point_cost(&self) -> ActionPoint { ActionPoint(match *self { - Action::Build(_) => 50, - Action::Destroy(_) => 10, - Action::Recolt(_) => 10, - Action::Upgrade(_) => 25, - Action::VillageManagement => 0, - Action::TroopManagement => 0, + Self::Build(_) => 50, + Self::Destroy(_) => 10, + Self::Recolt(_) => 10, + Self::Upgrade(_) => 25, + Self::VillageManagement => 0, + Self::TroopManagement => 0, + Self::TeleportManagement(_) => 0, }) } }