screeps/objects/impls/
tombstone.rs

1use js_sys::JsString;
2use wasm_bindgen::prelude::*;
3
4use crate::{
5    objects::{RoomObject, Store},
6    prelude::*,
7};
8
9#[wasm_bindgen]
10extern "C" {
11    /// A [`Tombstone`], which represents a dead creep and can have resources
12    /// withdrawn from it.
13    ///
14    /// [Screeps documentation](https://docs.screeps.com/api/#Tombstone)
15    #[wasm_bindgen(extends = RoomObject)]
16    #[derive(Clone, Debug)]
17    pub type Tombstone;
18
19    /// The dead [`Creep`] or [`PowerCreep`] that this tombstone represents.
20    /// Note that this object is not fully safe to use, and needs to be cast
21    /// into the correct type.
22    ///
23    /// [Screeps documentation](https://docs.screeps.com/api/#Tombstone.creep)
24    #[wasm_bindgen(method, getter)]
25    pub fn creep(this: &Tombstone) -> RoomObject;
26
27    /// The tick that the creep was killed.
28    ///
29    /// [Screeps documentation](https://docs.screeps.com/api/#Tombstone.deathTime)
30    #[wasm_bindgen(method, getter = deathTime)]
31    pub fn death_time(this: &Tombstone) -> u32;
32
33    /// Object ID of the tombstone, which can be used to efficiently fetch a
34    /// fresh reference to the object on subsequent ticks.
35    ///
36    /// [Screeps documentation](https://docs.screeps.com/api/#Tombstone.id)
37    #[wasm_bindgen(method, getter = id)]
38    fn id_internal(this: &Tombstone) -> JsString;
39
40    /// The [`Store`] of the tombstone, which contains any resources in the
41    /// tombstone.
42    ///
43    /// [Screeps documentation](https://docs.screeps.com/api/#Tombstone.store)
44    #[wasm_bindgen(method, getter)]
45    pub fn store(this: &Tombstone) -> Store;
46
47    /// The number of ticks until this tombstone disappears.
48    ///
49    /// [Screeps documentation](https://docs.screeps.com/api/#Tombstone.ticksToDecay)
50    #[wasm_bindgen(method, getter = ticksToDecay)]
51    pub fn ticks_to_decay(this: &Tombstone) -> u32;
52}
53
54impl CanDecay for Tombstone {
55    fn ticks_to_decay(&self) -> u32 {
56        Self::ticks_to_decay(self)
57    }
58}
59
60impl HasId for Tombstone {
61    fn js_raw_id(&self) -> JsString {
62        Self::id_internal(self)
63    }
64}
65
66impl HasStore for Tombstone {
67    fn store(&self) -> Store {
68        Self::store(self)
69    }
70}
71
72impl Withdrawable for Tombstone {}