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
use js_sys::JsString;
use wasm_bindgen::prelude::*;

use crate::{
    objects::{RoomObject, Store},
    prelude::*,
};

#[wasm_bindgen]
extern "C" {
    /// A [`Tombstone`], which represents a dead creep and can have resources
    /// withdrawn from it.
    ///
    /// [Screeps documentation](https://docs.screeps.com/api/#Tombstone)
    #[wasm_bindgen(extends = RoomObject)]
    #[derive(Clone, Debug)]
    pub type Tombstone;

    /// The dead [`Creep`] or [`PowerCreep`] that this tombstone represents.
    /// Note that this object is not fully safe to use, and needs to be cast
    /// into the correct type.
    ///
    /// [Screeps documentation](https://docs.screeps.com/api/#Tombstone.creep)
    #[wasm_bindgen(method, getter)]
    pub fn creep(this: &Tombstone) -> RoomObject;

    /// The tick that the creep was killed.
    ///
    /// [Screeps documentation](https://docs.screeps.com/api/#Tombstone.deathTime)
    #[wasm_bindgen(method, getter = deathTime)]
    pub fn death_time(this: &Tombstone) -> u32;

    /// Object ID of the tombstone, which can be used to efficiently fetch a
    /// fresh reference to the object on subsequent ticks.
    ///
    /// [Screeps documentation](https://docs.screeps.com/api/#Tombstone.id)
    #[wasm_bindgen(method, getter = id)]
    fn id_internal(this: &Tombstone) -> JsString;

    /// The [`Store`] of the tombstone, which contains any resources in the
    /// tombstone.
    ///
    /// [Screeps documentation](https://docs.screeps.com/api/#Tombstone.store)
    #[wasm_bindgen(method, getter)]
    pub fn store(this: &Tombstone) -> Store;

    /// The number of ticks until this tombstone disappears.
    ///
    /// [Screeps documentation](https://docs.screeps.com/api/#Tombstone.ticksToDecay)
    #[wasm_bindgen(method, getter = ticksToDecay)]
    pub fn ticks_to_decay(this: &Tombstone) -> u32;
}

impl CanDecay for Tombstone {
    fn ticks_to_decay(&self) -> u32 {
        Self::ticks_to_decay(self)
    }
}

impl HasNativeId for Tombstone {
    fn native_id(&self) -> JsString {
        Self::id_internal(self)
    }
}

impl HasStore for Tombstone {
    fn store(&self) -> Store {
        Self::store(self)
    }
}