screeps/objects/impls/
structure_nuker.rs

1use wasm_bindgen::prelude::*;
2
3use crate::{
4    enums::action_error_codes::structure_nuker::*,
5    objects::{OwnedStructure, RoomObject, RoomPosition, Store, Structure},
6    prelude::*,
7};
8
9#[wasm_bindgen]
10extern "C" {
11    /// An object representing a [`StructureNuker`], which consumes energy and
12    /// ghodium to fire [`Nuke`]s.
13    ///
14    /// [Screeps documentation](https://docs.screeps.com/api/#StructureNuker)
15    ///
16    /// [`Nuke`]: crate::objects::Nuke
17    #[wasm_bindgen(extends = RoomObject, extends = Structure, extends = OwnedStructure)]
18    #[derive(Clone, Debug)]
19    pub type StructureNuker;
20
21    /// The number of ticks until the [`StructureNuker`] can use
22    /// [`StructureNuker::launch_nuke`] again.
23    ///
24    /// [Screeps documentation](https://docs.screeps.com/api/#StructureNuker.cooldown)
25    #[wasm_bindgen(method, getter)]
26    pub fn cooldown(this: &StructureNuker) -> u32;
27
28    /// The [`Store`] of the nuker, which can have energy and ghodium
29    /// transferred in (but not withdrawn).
30    ///
31    /// [Screeps documentation](https://docs.screeps.com/api/#StructureNuker.store)
32    #[wasm_bindgen(method, getter)]
33    pub fn store(this: &StructureNuker) -> Store;
34
35    #[wasm_bindgen(method, js_name = launchNuke)]
36    fn launch_nuke_internal(this: &StructureNuker, target: &RoomPosition) -> i8;
37}
38
39impl StructureNuker {
40    /// Launch a nuke at a target [`RoomPosition`].
41    ///
42    /// [Screeps documentation](https://docs.screeps.com/api/#StructureNuker.launchNuke)
43    pub fn launch_nuke(&self, target: &RoomPosition) -> Result<(), LaunchNukeErrorCode> {
44        LaunchNukeErrorCode::result_from_i8(self.launch_nuke_internal(target))
45    }
46}
47
48impl HasCooldown for StructureNuker {
49    fn cooldown(&self) -> u32 {
50        Self::cooldown(self)
51    }
52}
53
54impl HasStore for StructureNuker {
55    fn store(&self) -> Store {
56        Self::store(self)
57    }
58}
59
60impl Attackable for StructureNuker {}
61impl Dismantleable for StructureNuker {}
62impl Repairable for StructureNuker {}
63impl Transferable for StructureNuker {}