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
63
64
65
66
67
68
69
70
71
72
73
74
75
use wasm_bindgen::prelude::*;
use crate::{
enums::action_error_codes::structure_link::*,
objects::{OwnedStructure, RoomObject, Store, Structure},
prelude::*,
};
#[wasm_bindgen]
extern "C" {
/// An object representing a [`StructureLink`], which can hold energy and
/// transfer it to other links within the room.
///
/// [Screeps documentation](https://docs.screeps.com/api/#StructureLink)
#[wasm_bindgen(extends = RoomObject, extends = Structure, extends = OwnedStructure)]
#[derive(Clone, Debug)]
pub type StructureLink;
/// The number of ticks until the [`StructureLink`] can use
/// [`StructureLink::transfer`] again.
///
/// [Screeps documentation](https://docs.screeps.com/api/#StructureLink.cooldown)
#[wasm_bindgen(method, getter)]
pub fn cooldown(this: &StructureLink) -> u32;
/// The [`Store`] of the extension, which contains information about the
/// amount of energy in it.
///
/// [Screeps documentation](https://docs.screeps.com/api/#StructureLink.store)
#[wasm_bindgen(method, getter)]
pub fn store(this: &StructureLink) -> Store;
#[wasm_bindgen(method, js_name = transferEnergy)]
fn transfer_energy_internal(
this: &StructureLink,
target: &StructureLink,
amount: Option<u32>,
) -> i8;
}
impl StructureLink {
/// Transfer energy from this [`StructureLink`] to another, losing
/// [`LINK_LOSS_RATIO`] percent of the energt and incurring a cooldown of
/// [`LINK_COOLDOWN`] tick per range to the target.
///
/// [Screeps documentation](https://docs.screeps.com/api/#StructureLink.transferEnergy)
///
/// [`LINK_LOSS_RATIO`]: crate::constants::LINK_LOSS_RATIO
/// [`LINK_COOLDOWN`]: crate::constants::LINK_COOLDOWN
pub fn transfer_energy(
&self,
target: &StructureLink,
amount: Option<u32>,
) -> Result<(), TransferEnergyErrorCode> {
TransferEnergyErrorCode::result_from_i8(self.transfer_energy_internal(target, amount))
}
}
impl HasCooldown for StructureLink {
fn cooldown(&self) -> u32 {
Self::cooldown(self)
}
}
impl HasStore for StructureLink {
fn store(&self) -> Store {
Self::store(self)
}
}
impl Attackable for StructureLink {}
impl Dismantleable for StructureLink {}
impl Repairable for StructureLink {}
impl Transferable for StructureLink {}
impl Withdrawable for StructureLink {}