1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use js_sys::JsString;
use wasm_bindgen::prelude::*;
use crate::{objects::RoomObject, prelude::*};
#[wasm_bindgen]
extern "C" {
/// A [`Source`], which can be harvested for energy.
///
/// [Screeps documentation](https://docs.screeps.com/api/#Source)
#[wasm_bindgen(extends = RoomObject)]
#[derive(Clone, Debug)]
pub type Source;
/// Amount of energy available to be harvested from the source.
///
/// [Screeps documentation](https://docs.screeps.com/api/#Source.energy)
#[wasm_bindgen(method, getter)]
pub fn energy(this: &Source) -> u32;
/// Amount of energy this source will regenerate to after
/// [`Source::ticks_to_regeneration`] reaches 0.
///
/// Value depends on the type of room the source is in:
///
/// - Owned and reserved rooms: [`SOURCE_ENERGY_CAPACITY`]
/// - Neutral rooms: [`SOURCE_ENERGY_NEUTRAL_CAPACITY`]
/// - Source Keeper rooms: [`SOURCE_ENERGY_KEEPER_CAPACITY`]
///
/// [Screeps documentation](https://docs.screeps.com/api/#Source.energy)
///
/// [`SOURCE_ENERGY_CAPACITY`]: crate::constants::SOURCE_ENERGY_CAPACITY
/// [`SOURCE_ENERGY_NEUTRAL_CAPACITY`]:
/// crate::constants::SOURCE_ENERGY_NEUTRAL_CAPACITY
/// [`SOURCE_ENERGY_KEEPER_CAPACITY`]:
/// crate::constants::SOURCE_ENERGY_KEEPER_CAPACITY
#[wasm_bindgen(method, getter = energyCapacity)]
pub fn energy_capacity(this: &Source) -> u32;
/// Object ID of the source, which can be used to efficiently fetch a fresh
/// reference to the object on subsequent ticks.
///
/// [Screeps documentation](https://docs.screeps.com/api/#Source.id)
#[wasm_bindgen(method, getter = id)]
fn id_internal(this: &Source) -> JsString;
/// The number of ticks until this source regenerates to its
/// [`Source::energy_capacity`], or `None` if the source has not started to
/// regenerate.
///
/// [Screeps documentation](https://docs.screeps.com/api/#Source.ticksToRegeneration)
#[wasm_bindgen(method, getter = ticksToRegeneration)]
pub fn ticks_to_regeneration(this: &Source) -> Option<u32>;
}
impl HasId for Source {
fn js_raw_id(&self) -> JsString {
Self::id_internal(self)
}
}
impl Harvestable for Source {}