save
All checks were successful
Rust Checks / checks (push) Successful in 2m58s

This commit is contained in:
CoCo_Sol 2024-04-06 14:23:58 +02:00
parent f609837e66
commit 5887ff57c6

View file

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