save
Some checks failed
Rust Checks / checks (push) Failing after 3m58s

This commit is contained in:
CoCo_Sol 2024-03-24 08:59:55 +01:00
parent 28dffe4ce9
commit 1f4a813481

View file

@ -2,56 +2,72 @@
use crate::map::Tile;
/// A number of action points. This is decreased when you do an action.
pub struct ActionPoint(pub u32);
/// The action that you can do with a tile.
pub enum Action {
/// Build something on the tile.
Build(u32),
/// Destroy something on the tile.
Destroy(u32),
/// Recolt something on the tile.
Recolt(u32),
/// Upgrade the tile.
Upgrade(u32),
/// Manage the villages.
VillageManagement,
/// Manage the troops.
TroopManagement,
}
impl Tile {
pub fn get_action(&self, index_of_tile: u8) -> Vec<Action> {
match *self {
Self::Breeding => [
Action::Destroy(index_of_tile),
Action::Upgrade(index_of_tile),
],
Self::Casern => [
Action::Destroy(index_of_tile),
Action::Upgrade(index_of_tile),
Action::TroopManagement,
],
Self::Castle => [
Action::Upgrade(index_of_tile),
Action::VillageManagement,
],
Self::Hill => [
Action::Recolt(index_of_tile),
],
Self::Grass => [
Action::Build(index_of_tile),
],
Self::Forest => [
Action::Recolt(index_of_tile),
],
Self::Mine => [
Action::Destroy(index_of_tile),
Action::Upgrade(index_of_tile),
],
Self::Outpost => [
Action::Destroy(index_of_tile),
],
Self::Sawmill => [
Action::Destroy(index_of_tile),
Action::Recolt(index_of_tile),
],
Self::Tower => [
Action::Destroy(index_of_tile),
Action::Upgrade(index_of_tile),
],
Self::Wall => [],
/// Get the actions that you can do with the tile.
pub fn get_action(&self, index_of_tile: u32) -> Vec<Action> {
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));
}
if let Self::Breeding | Self::Casern | Self::Mine | Self::Outpost | Self::Sawmill = *self {
actions.push(Action::Destroy(index_of_tile));
}
if let Self::Breeding | Self::Casern = *self {
actions.push(Action::TroopManagement);
}
if let Self::Breeding | Self::Hill = *self {
actions.push(Action::Recolt(index_of_tile));
}
actions
}
}
impl Action {
/// Get the cost of an action.
pub 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,
})
}
}