pub enum Structure {
Show 21 variants
Container(StructureContainer),
Controller(StructureController),
Extension(StructureExtension),
Extractor(StructureExtractor),
Factory(StructureFactory),
InvaderCore(StructureInvaderCore),
KeeperLair(StructureKeeperLair),
Lab(StructureLab),
Link(StructureLink),
Nuker(StructureNuker),
Observer(StructureObserver),
PowerBank(StructurePowerBank),
PowerSpawn(StructurePowerSpawn),
Portal(StructurePortal),
Rampart(StructureRampart),
Road(StructureRoad),
Spawn(StructureSpawn),
Storage(StructureStorage),
Terminal(StructureTerminal),
Tower(StructureTower),
Wall(StructureWall),
}
Expand description
Wrapper which can be any of the game Structures.
This is somewhat useful by itself, but has additional utility methods. Some tricks:
To get a particular type, match
on the structure:
use screeps::Structure;
match my_struct {
Structure::Container(cont) => {
// cont here is StructureContainer
}
_ => {
// other structure
}
}
To use structures of a particular type, like something that can be attacked, or something that can be transferred to, use helper methods:
use screeps::Structure;
match my_struct.as_transferable() {
Some(transf) => {
// transf is a reference to `dyn Transferable`, and you can transfer to it.
}
None => {
// my_struct is not transferable
}
}
See method documentation for a full list of possible helpers.
Variants
Container(StructureContainer)
Controller(StructureController)
Extension(StructureExtension)
Extractor(StructureExtractor)
Factory(StructureFactory)
InvaderCore(StructureInvaderCore)
KeeperLair(StructureKeeperLair)
Lab(StructureLab)
Link(StructureLink)
Nuker(StructureNuker)
Observer(StructureObserver)
PowerBank(StructurePowerBank)
PowerSpawn(StructurePowerSpawn)
Portal(StructurePortal)
Rampart(StructureRampart)
Road(StructureRoad)
Spawn(StructureSpawn)
Storage(StructureStorage)
Terminal(StructureTerminal)
Tower(StructureTower)
Wall(StructureWall)
Implementations
sourceimpl Structure
impl Structure
sourcepub fn as_transferable(&self) -> Option<&dyn Transferable>
pub fn as_transferable(&self) -> Option<&dyn Transferable>
Cast this structure as something Transferable, or return None if it isn’t.
Example usage:
use screeps::{Creep, ResourceType, Structure};
match my_struct.as_transferable() {
Some(transf) => {
// transf is a reference to `dyn Transferable`, and you can transfer to it.
my_creep.transfer_all(transf, ResourceType::Energy);
}
None => {
// my_struct cannot be transferred to
}
}
sourcepub fn as_withdrawable(&self) -> Option<&dyn Withdrawable>
pub fn as_withdrawable(&self) -> Option<&dyn Withdrawable>
Cast this as something which can be withdrawn from
sourcepub fn as_attackable(&self) -> Option<&dyn Attackable>
pub fn as_attackable(&self) -> Option<&dyn Attackable>
Cast this as something which can be attacked and has hit points.
The only Structure which cannot be attacked is StructureController
.
sourcepub fn as_owned(&self) -> Option<&dyn OwnedStructureProperties>
pub fn as_owned(&self) -> Option<&dyn OwnedStructureProperties>
Cast this as something which can be owned.
Example:
use screeps::Structure;
let is_my = my_struct.as_owned().map(|os| os.my()).unwrap_or(false);
pub fn as_can_decay(&self) -> Option<&dyn CanDecay>
pub fn as_has_cooldown(&self) -> Option<&dyn HasCooldown>
pub fn as_has_energy_for_spawn(&self) -> Option<&dyn HasEnergyForSpawn>
pub fn as_has_store(&self) -> Option<&dyn HasStore>
Trait Implementations
sourceimpl FromExpectedType<Reference> for Structure
impl FromExpectedType<Reference> for Structure
fn from_expected_type(reference: Reference) -> Result<Self, ConversionError>
sourceimpl HasId for Structure
impl HasId for Structure
sourcefn untyped_id(&self) -> RawObjectId
fn untyped_id(&self) -> RawObjectId
Retrieves this object’s id as an untyped, packed value. Read more
sourceimpl InstanceOf for Structure
impl InstanceOf for Structure
sourcefn instance_of(reference: &Reference) -> bool
fn instance_of(reference: &Reference) -> bool
Checks whenever a given Reference if of type Self
.
sourceimpl PartialEq<Structure> for Structure
impl PartialEq<Structure> for Structure
sourceimpl ReferenceType for Structure
impl ReferenceType for Structure
sourceunsafe fn from_reference_unchecked(reference: Reference) -> Self
unsafe fn from_reference_unchecked(reference: Reference) -> Self
Converts a given reference into a concrete reference-like wrapper. Doesn’t do any type checking; highly unsafe to use! Read more
sourceimpl RoomObjectProperties for Structure
impl RoomObjectProperties for Structure
sourceimpl StructureProperties for Structure
impl StructureProperties for Structure
fn structure_type(&self) -> StructureType
fn destroy(&self) -> ReturnCode
fn is_active(&self) -> bool
sourcefn notify_when_attacked(&self, notify_when_attacked: bool) -> ReturnCode
fn notify_when_attacked(&self, notify_when_attacked: bool) -> ReturnCode
Usable on either owned structures or neutral structures in owned rooms,
returns ReturnCode::NotOwner
otherwise. Read more
fn as_structure(self) -> Structurewhere
Self: SizedRoomObject,
impl Eq for Structure
Auto Trait Implementations
impl RefUnwindSafe for Structure
impl Send for Structure
impl Sync for Structure
impl Unpin for Structure
impl UnwindSafe for Structure
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> FromExpectedType<Value> for Twhere
T: FromExpectedType<Reference>,
impl<T> FromExpectedType<Value> for Twhere
T: FromExpectedType<Reference>,
fn from_expected_type(v: Value) -> Result<T, ConversionError>
sourceimpl<T> HasPosition for Twhere
T: RoomObjectProperties,
impl<T> HasPosition for Twhere
T: RoomObjectProperties,
sourceimpl<T, U> IntoExpectedType<U> for Twhere
U: FromExpectedType<T>,
impl<T, U> IntoExpectedType<U> for Twhere
U: FromExpectedType<T>,
sourcefn into_expected_type(self) -> Result<U, ConversionError>
fn into_expected_type(self) -> Result<U, ConversionError>
Casts this value as the target type, making the assumption that the types are correct. Read more