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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
use stdweb::{Reference, Value}; use stdweb::unstable::{TryFrom, TryInto}; use {ReturnCode, StructureType}; #[macro_use] mod macros; mod impls; reference_wrappers!( ConstructionSite, Creep, Flag, Mineral, Nuke, OwnedStructure, Resource, Room, RoomPosition, Source, StructureContainer, StructureController, StructureExtension, StructureExtractor, StructureKeeperLair, StructureLab, StructureLink, StructureNuker, StructureObserver, StructurePowerBank, StructurePowerSpawn, StructurePortal, StructureRampart, StructureRoad, StructureSpawn, StructureStorage, StructureTerminal, StructureTower, StructureWall, Structure, RoomObject, ); pub trait HasPosition: AsRef<Reference> { fn pos(&self) -> RoomPosition; } impl HasPosition for RoomPosition { fn pos(&self) -> RoomPosition { self.clone() } } impl<T> HasPosition for T where T: RoomObjectProperties, { fn pos(&self) -> RoomPosition { RoomObjectProperties::pos(self) } } pub trait RoomObjectProperties: AsRef<Reference> { fn pos(&self) -> RoomPosition; fn room(&self) -> Room; } pub trait StructureProperties: RoomObjectProperties { fn hits(&self) -> i32; fn hits_max(&self) -> i32; fn id(&self) -> String; fn destroy(&self) -> ReturnCode; fn is_active(&self) -> bool; fn structure_type(&self) -> StructureType; } pub trait OwnedStructureProperties: RoomObjectProperties { fn my(&self) -> bool; fn owner(&self) -> Option<String>; } pub unsafe trait Transferable: RoomObjectProperties {} unsafe impl Transferable for StructureExtension {} unsafe impl Transferable for Creep {} unsafe impl Transferable for StructureContainer {} unsafe impl Transferable for StructureLab {} unsafe impl Transferable for StructureLink {} unsafe impl Transferable for StructureNuker {} unsafe impl Transferable for StructureSpawn {} unsafe impl Transferable for StructureStorage {} unsafe impl Transferable for StructureTower {} unsafe impl Transferable for StructurePowerSpawn {} unsafe impl Transferable for StructureTerminal {} pub unsafe trait Withdrawable: Transferable {} unsafe impl Withdrawable for StructureExtension {} unsafe impl Withdrawable for StructureContainer {} unsafe impl Withdrawable for StructureLab {} unsafe impl Withdrawable for StructureLink {} unsafe impl Withdrawable for StructureSpawn {} unsafe impl Withdrawable for StructureStorage {} unsafe impl Withdrawable for StructureTower {} unsafe impl Withdrawable for StructurePowerSpawn {} unsafe impl Withdrawable for StructureTerminal {} pub unsafe trait Attackable: RoomObjectProperties {} unsafe impl<T> Attackable for T where T: StructureProperties, { } unsafe impl Attackable for Creep {} impl<'a, T: RoomObjectProperties> RoomObjectProperties for &'a T { fn pos(&self) -> RoomPosition { <T as RoomObjectProperties>::pos(self) } fn room(&self) -> Room { <T as RoomObjectProperties>::room(self) } } impl_room_object!( ConstructionSite, Creep, Flag, Mineral, Nuke, OwnedStructure, Resource, RoomObject, Source, Structure, StructureContainer, StructureController, StructureExtension, StructureExtractor, StructureKeeperLair, StructureLab, StructureLink, StructureNuker, StructureObserver, StructurePowerBank, StructurePowerSpawn, StructurePortal, StructureRampart, StructureRoad, StructureSpawn, StructureStorage, StructureTerminal, StructureTower, StructureWall, ); impl_structure!( OwnedStructure, Structure, StructureContainer, StructureController, StructureExtension, StructureExtractor, StructureKeeperLair, StructureLab, StructureLink, StructureNuker, StructureObserver, StructurePowerBank, StructurePowerSpawn, StructurePortal, StructureRampart, StructureRoad, StructureSpawn, StructureStorage, StructureTerminal, StructureTower, StructureWall, ); impl_owned_structure!( OwnedStructure, StructureController, StructureExtension, StructureExtractor, StructureKeeperLair, StructureLab, StructureLink, StructureNuker, StructureObserver, StructurePowerBank, StructurePowerSpawn, StructurePortal, StructureRampart, StructureSpawn, StructureStorage, StructureTerminal, StructureTower, );