1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
use wasm_bindgen::prelude::*;
use crate::{
    constants::ErrorCode,
    objects::{OwnedStructure, RoomObject, Store, Structure},
    prelude::*,
};
#[wasm_bindgen]
extern "C" {
    /// An object representing a [`StructureTower`], which can heal, repair, or
    /// attack anywhere in the room.
    ///
    /// [Screeps documentation](https://docs.screeps.com/api/#StructureTower)
    #[wasm_bindgen(extends = RoomObject, extends = Structure, extends = OwnedStructure)]
    #[derive(Clone, Debug)]
    pub type StructureTower;
    /// The [`Store`] of the tower, which contains energy which is consumed when
    /// it takes actions.
    ///
    /// [Screeps documentation](https://docs.screeps.com/api/#StructureTower.store)
    #[wasm_bindgen(method, getter)]
    pub fn store(this: &StructureTower) -> Store;
    #[wasm_bindgen(method, js_name = attack)]
    fn attack_internal(this: &StructureTower, target: &RoomObject) -> i8;
    #[wasm_bindgen(method, js_name = heal)]
    fn heal_internal(this: &StructureTower, target: &RoomObject) -> i8;
    #[wasm_bindgen(method, js_name = repair)]
    fn repair_internal(this: &StructureTower, target: &Structure) -> i8;
}
impl StructureTower {
    /// Attack a [`Creep`], [`PowerCreep`], or [`Structure`] in the room,
    /// dealing damage depending on range.
    ///
    /// [Screeps documentation](https://docs.screeps.com/api/#StructureTower.attack)
    ///
    /// [`Creep`]: crate::objects::Creep
    /// [`PowerCreep`]: crate::objects::PowerCreep
    pub fn attack<T>(&self, target: &T) -> Result<(), ErrorCode>
    where
        T: ?Sized + Attackable,
    {
        ErrorCode::result_from_i8(self.attack_internal(target.as_ref()))
    }
    /// Heal a [`Creep`] or [`PowerCreep`] in the room, adding hit points
    /// depending on range.
    ///
    /// [Screeps documentation](https://docs.screeps.com/api/#StructureTower.heal)
    ///
    /// [`Creep`]: crate::objects::Creep
    /// [`PowerCreep`]: crate::objects::PowerCreep
    pub fn heal<T>(&self, target: &T) -> Result<(), ErrorCode>
    where
        T: ?Sized + Healable,
    {
        ErrorCode::result_from_i8(self.heal_internal(target.as_ref()))
    }
    /// Repair a [`Structure`] in the room, adding hit points depending on
    /// range.
    ///
    /// [Screeps documentation](https://docs.screeps.com/api/#StructureTower.repair)
    pub fn repair<T>(&self, target: &T) -> Result<(), ErrorCode>
    where
        T: ?Sized + Repairable,
    {
        ErrorCode::result_from_i8(self.repair_internal(target.as_ref()))
    }
}
impl HasStore for StructureTower {
    fn store(&self) -> Store {
        Self::store(self)
    }
}
impl Attackable for StructureTower {}
impl Dismantleable for StructureTower {}
impl Repairable for StructureTower {}
impl Transferable for StructureTower {}
impl Withdrawable for StructureTower {}