screeps/objects/impls/
structure_power_spawn.rs

1use wasm_bindgen::prelude::*;
2
3use crate::{
4    enums::action_error_codes::structure_powerspawn::*,
5    objects::{OwnedStructure, RoomObject, Store, Structure},
6    prelude::*,
7};
8
9#[wasm_bindgen]
10extern "C" {
11    /// An object representing a [`StructurePowerSpawn`], which can process
12    /// power to contribute to your GPL as well as renewing power creeps.
13    ///
14    /// [Screeps documentation](https://docs.screeps.com/api/#StructurePowerSpawn)
15    #[wasm_bindgen(extends = RoomObject, extends = Structure, extends = OwnedStructure)]
16    #[derive(Clone, Debug)]
17    pub type StructurePowerSpawn;
18
19    /// The [`Store`] of the power spawn, which can contain power and energy.
20    ///
21    /// [Screeps documentation](https://docs.screeps.com/api/#StructurePowerSpawn.store)
22    #[wasm_bindgen(method, getter)]
23    pub fn store(this: &StructurePowerSpawn) -> Store;
24
25    /// Process power, consuming 1 power and [`POWER_SPAWN_ENERGY_RATIO`] energy
26    /// and increasing your GPL by one point.
27    ///
28    /// [Screeps documentation](https://docs.screeps.com/api/#StructurePowerSpawn.processPower)
29    ///
30    /// [`POWER_SPAWN_ENERGY_RATIO`]:
31    /// crate::constants::numbers::POWER_SPAWN_ENERGY_RATIO
32    #[wasm_bindgen(method, js_name = processPower)]
33    fn process_power_internal(this: &StructurePowerSpawn) -> i8;
34}
35
36impl StructurePowerSpawn {
37    /// Process power, consuming 1 power and [`POWER_SPAWN_ENERGY_RATIO`] energy
38    /// and increasing your GPL by one point.
39    ///
40    /// [Screeps documentation](https://docs.screeps.com/api/#StructurePowerSpawn.processPower)
41    ///
42    /// [`POWER_SPAWN_ENERGY_RATIO`]: crate::constants::POWER_SPAWN_ENERGY_RATIO
43    pub fn process_power(&self) -> Result<(), ProcessPowerErrorCode> {
44        ProcessPowerErrorCode::result_from_i8(self.process_power_internal())
45    }
46}
47
48impl HasStore for StructurePowerSpawn {
49    fn store(&self) -> Store {
50        Self::store(self)
51    }
52}
53
54impl Attackable for StructurePowerSpawn {}
55impl Dismantleable for StructurePowerSpawn {}
56impl Repairable for StructurePowerSpawn {}
57impl Transferable for StructurePowerSpawn {}
58impl Withdrawable for StructurePowerSpawn {}