screeps/objects/impls/
structure_lab.rs

1use wasm_bindgen::prelude::*;
2
3use crate::{
4    constants::ResourceType,
5    enums::action_error_codes::structure_lab::*,
6    objects::{Creep, OwnedStructure, RoomObject, Store, Structure},
7    prelude::*,
8};
9
10#[wasm_bindgen]
11extern "C" {
12    /// An object representing a [`StructureLab`], which can be used to create
13    /// mineral compounds.
14    ///
15    /// [Screeps documentation](https://docs.screeps.com/api/#StructureLab)
16    #[wasm_bindgen(extends = RoomObject, extends = Structure, extends = OwnedStructure)]
17    #[derive(Clone, Debug)]
18    pub type StructureLab;
19
20    /// The number of ticks until the [`StructureLab`] can use
21    /// [`StructureLab::run_reaction`] or [`StructureLab::unboost_creep`] again.
22    ///
23    /// [Screeps documentation](https://docs.screeps.com/api/#StructureLab.cooldown)
24    #[wasm_bindgen(method, getter)]
25    pub fn cooldown(this: &StructureLab) -> u32;
26
27    /// The [`Store`] of the lab, which can contain energy and one type of
28    /// resource at a time.
29    ///
30    /// [Screeps documentation](https://docs.screeps.com/api/#StructureLab.store)
31    #[wasm_bindgen(method, getter)]
32    pub fn store(this: &StructureLab) -> Store;
33
34    /// Get the type of mineral currently contained in the lab, which can only
35    /// hold one type at a time
36    ///
37    /// [Screeps documentation](https://docs.screeps.com/api/#StructureLab.mineralType)
38    #[wasm_bindgen(method, getter = mineralType)]
39    pub fn mineral_type(this: &StructureLab) -> Option<ResourceType>;
40
41    #[wasm_bindgen(method, js_name = boostCreep)]
42    fn boost_creep_internal(this: &StructureLab, creep: &Creep, body_part_count: Option<u32>)
43        -> i8;
44
45    #[wasm_bindgen(method, js_name = reverseReaction)]
46    fn reverse_reaction_internal(
47        this: &StructureLab,
48        lab1: &StructureLab,
49        lab2: &StructureLab,
50    ) -> i8;
51
52    #[wasm_bindgen(method, js_name = runReaction)]
53    fn run_reaction_internal(this: &StructureLab, lab1: &StructureLab, lab2: &StructureLab) -> i8;
54
55    #[wasm_bindgen(method, js_name = unboostCreep)]
56    fn unboost_creep_internal(this: &StructureLab, creep: &Creep) -> i8;
57}
58
59impl StructureLab {
60    /// Boost a [`Creep`] in melee range, consuming [`LAB_BOOST_ENERGY`] energy
61    /// and [`LAB_BOOST_MINERAL`] of the boost compound from the
62    /// [`StructureLab::store`] per boosted body part.
63    ///
64    /// [Screeps documentation](https://docs.screeps.com/api/#StructureLab.boostCreep)
65    ///
66    /// [`LAB_BOOST_ENERGY`]: crate::constants::LAB_BOOST_ENERGY
67    /// [`LAB_BOOST_MINERAL`]: crate::constants::LAB_BOOST_MINERAL
68    pub fn boost_creep(
69        &self,
70        creep: &Creep,
71        body_part_count: Option<u32>,
72    ) -> Result<(), BoostCreepErrorCode> {
73        BoostCreepErrorCode::result_from_i8(self.boost_creep_internal(creep, body_part_count))
74    }
75
76    /// Reverse a reaction, splitting the compound in this [`StructureLab`] into
77    /// its components in two other labs.
78    ///
79    /// [Screeps documentation](https://docs.screeps.com/api/#StructureLab.reverseReaction)
80    pub fn reverse_reaction(
81        &self,
82        lab1: &StructureLab,
83        lab2: &StructureLab,
84    ) -> Result<(), ReverseReactionErrorCode> {
85        ReverseReactionErrorCode::result_from_i8(self.reverse_reaction_internal(lab1, lab2))
86    }
87
88    /// Run a reaction, combining components from two other [`StructureLab`]s
89    /// into a new compound in this lab.
90    ///
91    /// [Screeps documentation](https://docs.screeps.com/api/#StructureLab.runReaction)
92    pub fn run_reaction(
93        &self,
94        lab1: &StructureLab,
95        lab2: &StructureLab,
96    ) -> Result<(), RunReactionErrorCode> {
97        RunReactionErrorCode::result_from_i8(self.run_reaction_internal(lab1, lab2))
98    }
99
100    /// Unboost a [`Creep`], removing all boosts from its body and dropping
101    /// [`LAB_UNBOOST_MINERAL`] per body part on the ground, with a cooldown
102    /// equal to the total time to produce the removed boosts.
103    ///
104    /// [Screeps documentation](https://docs.screeps.com/api/#StructureLab.unboostCreep)
105    ///
106    /// [`LAB_UNBOOST_MINERAL`]: crate::constants::LAB_UNBOOST_MINERAL
107    pub fn unboost_creep(&self, creep: &Creep) -> Result<(), UnboostCreepErrorCode> {
108        UnboostCreepErrorCode::result_from_i8(self.unboost_creep_internal(creep))
109    }
110}
111
112impl HasCooldown for StructureLab {
113    fn cooldown(&self) -> u32 {
114        Self::cooldown(self)
115    }
116}
117
118impl HasStore for StructureLab {
119    fn store(&self) -> Store {
120        Self::store(self)
121    }
122}
123
124impl Attackable for StructureLab {}
125impl Dismantleable for StructureLab {}
126impl Repairable for StructureLab {}
127impl Transferable for StructureLab {}
128impl Withdrawable for StructureLab {}