screeps/objects/impls/
structure_tower.rs1use wasm_bindgen::prelude::*;
2
3use crate::{
4 enums::action_error_codes::structure_tower::*,
5 objects::{OwnedStructure, RoomObject, Store, Structure},
6 prelude::*,
7};
8
9#[wasm_bindgen]
10extern "C" {
11 #[wasm_bindgen(extends = RoomObject, extends = Structure, extends = OwnedStructure)]
16 #[derive(Clone, Debug)]
17 pub type StructureTower;
18
19 #[wasm_bindgen(method, getter)]
24 pub fn store(this: &StructureTower) -> Store;
25
26 #[wasm_bindgen(method, js_name = attack)]
27 fn attack_internal(this: &StructureTower, target: &RoomObject) -> i8;
28
29 #[wasm_bindgen(method, js_name = heal)]
30 fn heal_internal(this: &StructureTower, target: &RoomObject) -> i8;
31
32 #[wasm_bindgen(method, js_name = repair)]
33 fn repair_internal(this: &StructureTower, target: &Structure) -> i8;
34}
35
36impl StructureTower {
37 pub fn attack<T>(&self, target: &T) -> Result<(), TowerAttackErrorCode>
45 where
46 T: ?Sized + Attackable,
47 {
48 TowerAttackErrorCode::result_from_i8(self.attack_internal(target.as_ref()))
49 }
50
51 pub fn heal<T>(&self, target: &T) -> Result<(), TowerHealErrorCode>
59 where
60 T: ?Sized + Healable,
61 {
62 TowerHealErrorCode::result_from_i8(self.heal_internal(target.as_ref()))
63 }
64
65 pub fn repair<T>(&self, target: &T) -> Result<(), TowerRepairErrorCode>
70 where
71 T: ?Sized + Repairable,
72 {
73 TowerRepairErrorCode::result_from_i8(self.repair_internal(target.as_ref()))
74 }
75}
76
77impl HasStore for StructureTower {
78 fn store(&self) -> Store {
79 Self::store(self)
80 }
81}
82
83impl Attackable for StructureTower {}
84impl Dismantleable for StructureTower {}
85impl Repairable for StructureTower {}
86impl Transferable for StructureTower {}
87impl Withdrawable for StructureTower {}