ashscript_types/structures/
turret.rs

1use hashbrown::HashMap;
2use hexx::Hex;
3use serde::Serialize;
4use uuid::Uuid;
5
6use crate::{objects::{GameObjectKind, HasHealth, HasHex, HasId, HasStorage}, player::OwnerId, storage::Storage};
7
8pub type Turrets = HashMap<Hex, Turret>;
9
10#[derive(Serialize, Default, Clone)]
11pub struct Turret {
12    pub id: Uuid,
13    pub kind: GameObjectKind,
14    pub owner_id: OwnerId,
15    pub energy: u32,
16    pub hex: Hex,
17    pub health: u32,
18    pub storage: Storage,
19    #[serde(skip)]
20    pub future_health: u32,
21    #[serde(skip)]
22    pub future_energy: u32,
23}
24
25impl HasHealth for Turret {
26    fn health(&self) -> u32 {
27        self.health
28    }
29}
30
31impl HasId for Turret {
32    fn id(&self) -> Uuid {
33        self.id
34    }
35}
36
37impl HasHex for Turret {
38    fn hex(&self) -> Hex {
39        self.hex
40    }
41}
42
43impl HasStorage for Turret {
44    fn storage(&self) -> &Storage {
45        &self.storage
46    }
47}
48
49impl Turret {
50    pub fn attack_cost(&self) -> u32 {
51        self.range() + self.damage()
52    }
53    
54    pub fn range(&self) -> u32 {
55        1
56    }
57    
58    pub fn damage(&self) -> u32 {
59        1
60    }
61}