screeps/objects/impls/
structure_lab.rs

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