screeps/objects/impls/
structure_rampart.rs

1use wasm_bindgen::prelude::*;
2
3use crate::{
4    enums::action_error_codes::structure_rampart::*,
5    objects::{OwnedStructure, RoomObject, Structure},
6    prelude::*,
7};
8
9#[wasm_bindgen]
10extern "C" {
11    /// An object representing a [`StructureRampart`], which is selectively
12    /// walkable and protects creeps and structures at the same position.
13    ///
14    /// [Screeps documentation](https://docs.screeps.com/api/#StructureRampart)
15    #[wasm_bindgen(extends = RoomObject, extends = Structure, extends = OwnedStructure)]
16    #[derive(Clone, Debug)]
17    pub type StructureRampart;
18
19    /// Whether the [`StructureRampart`] is set to be public, allowing hostile
20    /// creeps to walk on it.
21    ///
22    /// [Screeps documentation](https://docs.screeps.com/api/#StructureRampart.isPublic)
23    #[wasm_bindgen(method, getter = isPublic)]
24    pub fn is_public(this: &StructureRampart) -> bool;
25
26    /// The number of ticks until the rampart will decay, losing
27    /// [`RAMPART_DECAY_AMOUNT`] hits.
28    ///
29    /// [Screeps documentation](https://docs.screeps.com/api/#StructureRampart.ticksToDecay)
30    ///
31    /// [`RAMPART_DECAY_AMOUNT`]:
32    /// crate::constants::numbers::RAMPART_DECAY_AMOUNT
33    #[wasm_bindgen(method, getter = ticksToDecay)]
34    pub fn ticks_to_decay(this: &StructureRampart) -> u32;
35
36    #[wasm_bindgen(method, js_name = setPublic)]
37    fn set_public_internal(this: &StructureRampart, val: bool) -> i8;
38}
39
40impl StructureRampart {
41    /// Set whether [`StructureRampart`] is public, allowing hostile creeps to
42    /// walk on it.
43    ///
44    /// [Screeps documentation](https://docs.screeps.com/api/#StructureRampart.setPublic)
45    pub fn set_public(&self, public: bool) -> Result<(), SetPublicErrorCode> {
46        SetPublicErrorCode::result_from_i8(self.set_public_internal(public))
47    }
48}
49
50impl CanDecay for StructureRampart {
51    fn ticks_to_decay(&self) -> u32 {
52        Self::ticks_to_decay(self)
53    }
54}
55
56impl Attackable for StructureRampart {}
57impl Dismantleable for StructureRampart {}
58impl Repairable for StructureRampart {}