Struct screeps::objects::PowerCreep
source · pub struct PowerCreep { /* private fields */ }
Expand description
A PowerCreep
unit in the game world.
Implementations§
source§impl PowerCreep
impl PowerCreep
sourcepub fn create(name: &JsString, class: PowerCreepClass) -> Result<(), ErrorCode>
pub fn create(name: &JsString, class: PowerCreepClass) -> Result<(), ErrorCode>
Create a new power creep in your account. Note that it will not initially be spawned.
sourcepub fn class(&self) -> PowerCreepClass
pub fn class(&self) -> PowerCreepClass
Retrieve this power creep’s PowerCreepClass
.
sourcepub fn level(&self) -> u32
pub fn level(&self) -> u32
Current level of the power creep, which can be increased with
AccountPowerCreep::upgrade
if you have unspent GPL.
sourcepub fn set_memory(&self, val: &JsValue)
pub fn set_memory(&self, val: &JsValue)
Sets a new value to Memory.powerCreeps[power_creep.name]
.
sourcepub fn powers(&self) -> JsHashMap<PowerType, PowerInfo>
pub fn powers(&self) -> JsHashMap<PowerType, PowerInfo>
The levels of this power creep’s abilities, with PowerType
keys and
values containing power level and cooldown.
sourcepub fn store(&self) -> Store
pub fn store(&self) -> Store
The Store
of the power creep, which contains information about what
resources it is it carrying.
sourcepub fn shard(&self) -> Option<JsString>
pub fn shard(&self) -> Option<JsString>
The shard the power creep is currently spawned on, if spawned.
sourcepub fn ticks_to_live(&self) -> Option<u32>
pub fn ticks_to_live(&self) -> Option<u32>
The number of ticks the power creep has left to live, which can be
renewed at a StructurePowerSpawn
or StructurePowerBank
sourcepub fn cancel_order(&self, target: &JsString) -> Result<(), ErrorCode>
pub fn cancel_order(&self, target: &JsString) -> Result<(), ErrorCode>
Cancel an a successfully called power creep function from earlier in the
tick, with a JsString
that must contain the JS version of the
function name.
sourcepub fn drop(
&self,
ty: ResourceType,
amount: Option<u32>
) -> Result<(), ErrorCode>
pub fn drop( &self, ty: ResourceType, amount: Option<u32> ) -> Result<(), ErrorCode>
Drop a resource on the ground from the power creep’s Store
.
sourcepub fn enable_room(&self, target: &StructureController) -> Result<(), ErrorCode>
pub fn enable_room(&self, target: &StructureController) -> Result<(), ErrorCode>
Enable powers to be used in this room on a StructureController
in
melee range. You do not need to own the controller.
sourcepub fn move_direction(&self, direction: Direction) -> Result<(), ErrorCode>
pub fn move_direction(&self, direction: Direction) -> Result<(), ErrorCode>
Move one square in the specified direction.
sourcepub fn move_by_path(&self, path: &JsValue) -> Result<(), ErrorCode>
pub fn move_by_path(&self, path: &JsValue) -> Result<(), ErrorCode>
Move the power creep along a previously determined path returned from a pathfinding function, in array or serialized string form.
sourcepub fn notify_when_attacked(&self, enabled: bool) -> Result<(), ErrorCode>
pub fn notify_when_attacked(&self, enabled: bool) -> Result<(), ErrorCode>
Whether to send an email notification when this power creep is attacked.
sourcepub fn pickup(&self, target: &Resource) -> Result<(), ErrorCode>
pub fn pickup(&self, target: &Resource) -> Result<(), ErrorCode>
Pick up a Resource
in melee range (or at the same position as the
creep).
sourcepub fn renew(&self, target: &RoomObject) -> Result<(), ErrorCode>
pub fn renew(&self, target: &RoomObject) -> Result<(), ErrorCode>
Renew the power creep’s TTL using a StructurePowerSpawn
or
StructurePowerBank
in melee range.
sourcepub fn say(&self, message: &str, public: bool) -> Result<(), ErrorCode>
pub fn say(&self, message: &str, public: bool) -> Result<(), ErrorCode>
Display a string in a bubble above the power creep next tick. 10 character limit.
Methods from Deref<Target = RoomObject>§
sourcepub fn js_pos(&self) -> RoomPosition
pub fn js_pos(&self) -> RoomPosition
Gets the RoomPosition
of an object, which is a reference to an
object in the javascript heap. In most cases, you’ll likely want a
native Position
instead of using this function (see
HasPosition::pos
), there may be cases where this can provide
some slight performance benefits due to reducing object churn in the js
heap, so this is kept public.
Methods from Deref<Target = JsValue>§
pub const NULL: JsValue = _
pub const UNDEFINED: JsValue = _
pub const TRUE: JsValue = _
pub const FALSE: JsValue = _
sourcepub fn as_f64(&self) -> Option<f64>
pub fn as_f64(&self) -> Option<f64>
Returns the f64
value of this JS value if it’s an instance of a
number.
If this JS value is not an instance of a number then this returns
None
.
sourcepub fn as_string(&self) -> Option<String>
Available on crate feature std
only.
pub fn as_string(&self) -> Option<String>
std
only.If this JS value is a string value, this function copies the JS string
value into wasm linear memory, encoded as UTF-8, and returns it as a
Rust String
.
To avoid the copying and re-encoding, consider the
JsString::try_from()
function from js-sys
instead.
If this JS value is not an instance of a string or if it’s not valid
utf-8 then this returns None
.
UTF-16 vs UTF-8
JavaScript strings in general are encoded as UTF-16, but Rust strings
are encoded as UTF-8. This can cause the Rust string to look a bit
different than the JS string sometimes. For more details see the
documentation about the str
type which contains a few
caveats about the encodings.
sourcepub fn as_bool(&self) -> Option<bool>
pub fn as_bool(&self) -> Option<bool>
Returns the bool
value of this JS value if it’s an instance of a
boolean.
If this JS value is not an instance of a boolean then this returns
None
.
sourcepub fn is_undefined(&self) -> bool
pub fn is_undefined(&self) -> bool
Tests whether this JS value is undefined
sourcepub fn is_function(&self) -> bool
pub fn is_function(&self) -> bool
Tests whether the type of this JS value is function
.
sourcepub fn js_in(&self, obj: &JsValue) -> bool
pub fn js_in(&self, obj: &JsValue) -> bool
Applies the binary in
JS operator on the two JsValue
s.
sourcepub fn loose_eq(&self, other: &JsValue) -> bool
pub fn loose_eq(&self, other: &JsValue) -> bool
Compare two JsValue
s for equality, using the ==
operator in JS.
sourcepub fn unsigned_shr(&self, rhs: &JsValue) -> u32
pub fn unsigned_shr(&self, rhs: &JsValue) -> u32
Applies the binary >>>
JS operator on the two JsValue
s.
sourcepub fn checked_div(&self, rhs: &JsValue) -> JsValue
pub fn checked_div(&self, rhs: &JsValue) -> JsValue
Applies the binary /
JS operator on two JsValue
s, catching and returning any RangeError
thrown.
sourcepub fn pow(&self, rhs: &JsValue) -> JsValue
pub fn pow(&self, rhs: &JsValue) -> JsValue
Applies the binary **
JS operator on the two JsValue
s.
sourcepub fn lt(&self, other: &JsValue) -> bool
pub fn lt(&self, other: &JsValue) -> bool
Applies the binary <
JS operator on the two JsValue
s.
sourcepub fn le(&self, other: &JsValue) -> bool
pub fn le(&self, other: &JsValue) -> bool
Applies the binary <=
JS operator on the two JsValue
s.
sourcepub fn ge(&self, other: &JsValue) -> bool
pub fn ge(&self, other: &JsValue) -> bool
Applies the binary >=
JS operator on the two JsValue
s.
sourcepub fn gt(&self, other: &JsValue) -> bool
pub fn gt(&self, other: &JsValue) -> bool
Applies the binary >
JS operator on the two JsValue
s.
sourcepub fn unchecked_into_f64(&self) -> f64
pub fn unchecked_into_f64(&self) -> f64
Applies the unary +
JS operator on a JsValue
. Can throw.
Trait Implementations§
source§impl AsRef<AccountPowerCreep> for PowerCreep
impl AsRef<AccountPowerCreep> for PowerCreep
source§fn as_ref(&self) -> &AccountPowerCreep
fn as_ref(&self) -> &AccountPowerCreep
source§impl AsRef<JsValue> for PowerCreep
impl AsRef<JsValue> for PowerCreep
source§impl AsRef<PowerCreep> for PowerCreep
impl AsRef<PowerCreep> for PowerCreep
source§fn as_ref(&self) -> &PowerCreep
fn as_ref(&self) -> &PowerCreep
source§impl AsRef<RoomObject> for PowerCreep
impl AsRef<RoomObject> for PowerCreep
source§fn as_ref(&self) -> &RoomObject
fn as_ref(&self) -> &RoomObject
source§impl Clone for PowerCreep
impl Clone for PowerCreep
source§fn clone(&self) -> PowerCreep
fn clone(&self) -> PowerCreep
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for PowerCreep
impl Debug for PowerCreep
source§impl Deref for PowerCreep
impl Deref for PowerCreep
§type Target = RoomObject
type Target = RoomObject
source§fn deref(&self) -> &RoomObject
fn deref(&self) -> &RoomObject
source§impl From<JsValue> for PowerCreep
impl From<JsValue> for PowerCreep
source§fn from(obj: JsValue) -> PowerCreep
fn from(obj: JsValue) -> PowerCreep
source§impl From<PowerCreep> for AccountPowerCreep
impl From<PowerCreep> for AccountPowerCreep
source§fn from(power_creep: PowerCreep) -> Self
fn from(power_creep: PowerCreep) -> Self
source§impl From<PowerCreep> for JsValue
impl From<PowerCreep> for JsValue
source§fn from(obj: PowerCreep) -> JsValue
fn from(obj: PowerCreep) -> JsValue
source§impl From<PowerCreep> for MovableObject
impl From<PowerCreep> for MovableObject
source§fn from(v: PowerCreep) -> MovableObject
fn from(v: PowerCreep) -> MovableObject
source§impl From<PowerCreep> for ObjectWithPosition
impl From<PowerCreep> for ObjectWithPosition
source§fn from(v: PowerCreep) -> ObjectWithPosition
fn from(v: PowerCreep) -> ObjectWithPosition
source§impl From<PowerCreep> for RoomObject
impl From<PowerCreep> for RoomObject
source§fn from(obj: PowerCreep) -> RoomObject
fn from(obj: PowerCreep) -> RoomObject
source§impl From<PowerCreep> for StoreObject
impl From<PowerCreep> for StoreObject
source§fn from(v: PowerCreep) -> StoreObject
fn from(v: PowerCreep) -> StoreObject
source§impl From<PowerCreep> for TransferableObject
impl From<PowerCreep> for TransferableObject
source§fn from(v: PowerCreep) -> TransferableObject
fn from(v: PowerCreep) -> TransferableObject
source§impl From<PowerCreep> for TypedRoomObject
impl From<PowerCreep> for TypedRoomObject
source§fn from(v: PowerCreep) -> TypedRoomObject
fn from(v: PowerCreep) -> TypedRoomObject
source§impl FromWasmAbi for PowerCreep
impl FromWasmAbi for PowerCreep
source§impl HasHits for PowerCreep
impl HasHits for PowerCreep
source§impl HasId for PowerCreep
impl HasId for PowerCreep
source§fn js_raw_id(&self) -> JsString
fn js_raw_id(&self) -> JsString
source§fn id(&self) -> ObjectId<Self>where
Self: Sized,
fn id(&self) -> ObjectId<Self>where
Self: Sized,
source§fn raw_id(&self) -> RawObjectId
fn raw_id(&self) -> RawObjectId
source§fn js_id(&self) -> JsObjectId<Self>where
Self: Sized,
fn js_id(&self) -> JsObjectId<Self>where
Self: Sized,
source§impl HasStore for PowerCreep
impl HasStore for PowerCreep
source§impl<'a> IntoWasmAbi for &'a PowerCreep
impl<'a> IntoWasmAbi for &'a PowerCreep
source§impl IntoWasmAbi for PowerCreep
impl IntoWasmAbi for PowerCreep
source§impl JsCast for PowerCreep
impl JsCast for PowerCreep
source§fn instanceof(val: &JsValue) -> bool
fn instanceof(val: &JsValue) -> bool
instanceof
check to see whether the JsValue
provided is an instance of this type. Read moresource§fn unchecked_from_js(val: JsValue) -> Self
fn unchecked_from_js(val: JsValue) -> Self
source§fn unchecked_from_js_ref(val: &JsValue) -> &Self
fn unchecked_from_js_ref(val: &JsValue) -> &Self
source§fn has_type<T>(&self) -> boolwhere
T: JsCast,
fn has_type<T>(&self) -> boolwhere
T: JsCast,
T
. Read moresource§fn dyn_into<T>(self) -> Result<T, Self>where
T: JsCast,
fn dyn_into<T>(self) -> Result<T, Self>where
T: JsCast,
T
. Read moresource§fn dyn_ref<T>(&self) -> Option<&T>where
T: JsCast,
fn dyn_ref<T>(&self) -> Option<&T>where
T: JsCast,
T
. Read moresource§fn unchecked_into<T>(self) -> Twhere
T: JsCast,
fn unchecked_into<T>(self) -> Twhere
T: JsCast,
source§fn unchecked_ref<T>(&self) -> &Twhere
T: JsCast,
fn unchecked_ref<T>(&self) -> &Twhere
T: JsCast,
source§impl LongRefFromWasmAbi for PowerCreep
impl LongRefFromWasmAbi for PowerCreep
§type Abi = <JsValue as LongRefFromWasmAbi>::Abi
type Abi = <JsValue as LongRefFromWasmAbi>::Abi
RefFromWasmAbi::Abi
§type Anchor = PowerCreep
type Anchor = PowerCreep
RefFromWasmAbi::Anchor
source§unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor
unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor
RefFromWasmAbi::ref_from_abi
source§impl OptionFromWasmAbi for PowerCreep
impl OptionFromWasmAbi for PowerCreep
source§impl<'a> OptionIntoWasmAbi for &'a PowerCreep
impl<'a> OptionIntoWasmAbi for &'a PowerCreep
source§impl OptionIntoWasmAbi for PowerCreep
impl OptionIntoWasmAbi for PowerCreep
source§impl RefFromWasmAbi for PowerCreep
impl RefFromWasmAbi for PowerCreep
§type Abi = <JsValue as RefFromWasmAbi>::Abi
type Abi = <JsValue as RefFromWasmAbi>::Abi
Self
are recovered from.§type Anchor = ManuallyDrop<PowerCreep>
type Anchor = ManuallyDrop<PowerCreep>
Self
for the duration of the
invocation of the function that has an &Self
parameter. This is
required to ensure that the lifetimes don’t persist beyond one function
call, and so that they remain anonymous.source§fn memory(&self) -> JsValue
fn memory(&self) -> JsValue
Memory
tree used for this creep by
defaultsource§fn set_memory(&self, val: &JsValue)
fn set_memory(&self, val: &JsValue)
source§fn ticks_to_live(&self) -> Option<u32>
fn ticks_to_live(&self) -> Option<u32>
source§fn cancel_order(&self, target: &JsString) -> Result<(), ErrorCode>
fn cancel_order(&self, target: &JsString) -> Result<(), ErrorCode>
JsString
that must contain the JS version of the function
name.source§fn drop(&self, ty: ResourceType, amount: Option<u32>) -> Result<(), ErrorCode>
fn drop(&self, ty: ResourceType, amount: Option<u32>) -> Result<(), ErrorCode>
Store
.source§fn move_direction(&self, direction: Direction) -> Result<(), ErrorCode>
fn move_direction(&self, direction: Direction) -> Result<(), ErrorCode>
source§fn move_by_path(&self, path: &JsValue) -> Result<(), ErrorCode>
fn move_by_path(&self, path: &JsValue) -> Result<(), ErrorCode>
source§fn move_to<T>(&self, target: T) -> Result<(), ErrorCode>where
T: HasPosition,
fn move_to<T>(&self, target: T) -> Result<(), ErrorCode>where
T: HasPosition,
RoomPosition
or
RoomObject
. Note that using this function will store data in
Memory.creeps[creep_name]
and enable the default serialization
behavior of the Memory
object, which may hamper attempts to directly
use RawMemory
.source§fn move_to_with_options<T, F>(
&self,
target: T,
options: Option<MoveToOptions<F>>
) -> Result<(), ErrorCode>
fn move_to_with_options<T, F>( &self, target: T, options: Option<MoveToOptions<F>> ) -> Result<(), ErrorCode>
RoomPosition
or
RoomObject
. Note that using this function will store data in
Memory.creeps[creep_name]
and enable the default serialization
behavior of the Memory
object, which may hamper attempts to directly
use RawMemory
.source§fn notify_when_attacked(&self, enabled: bool) -> Result<(), ErrorCode>
fn notify_when_attacked(&self, enabled: bool) -> Result<(), ErrorCode>
source§fn pickup(&self, target: &Resource) -> Result<(), ErrorCode>
fn pickup(&self, target: &Resource) -> Result<(), ErrorCode>
Resource
in melee range (or at the same position as the
creep).source§fn say(&self, message: &str, public: bool) -> Result<(), ErrorCode>
fn say(&self, message: &str, public: bool) -> Result<(), ErrorCode>
source§impl TryFrom<AccountPowerCreep> for PowerCreep
impl TryFrom<AccountPowerCreep> for PowerCreep
source§impl TryInto<PowerCreep> for MovableObject
impl TryInto<PowerCreep> for MovableObject
source§impl TryInto<PowerCreep> for ObjectWithPosition
impl TryInto<PowerCreep> for ObjectWithPosition
source§impl TryInto<PowerCreep> for StoreObject
impl TryInto<PowerCreep> for StoreObject
source§impl TryInto<PowerCreep> for TransferableObject
impl TryInto<PowerCreep> for TransferableObject
source§impl TryInto<PowerCreep> for TypedRoomObject
impl TryInto<PowerCreep> for TypedRoomObject
impl Attackable for PowerCreep
impl Healable for PowerCreep
impl Transferable for PowerCreep
Auto Trait Implementations§
impl RefUnwindSafe for PowerCreep
impl !Send for PowerCreep
impl !Sync for PowerCreep
impl Unpin for PowerCreep
impl UnwindSafe for PowerCreep
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> HasPosition for Twhere
T: AsRef<RoomObject>,
impl<T> HasPosition for Twhere
T: AsRef<RoomObject>,
source§impl<T> MaybeHasId for Twhere
T: HasId,
impl<T> MaybeHasId for Twhere
T: HasId,
source§fn try_js_raw_id(&self) -> Option<JsString>
fn try_js_raw_id(&self) -> Option<JsString>
None
if the object doesn’t currently
have an ID.source§fn try_id(&self) -> Option<ObjectId<Self>>where
Self: Sized,
fn try_id(&self) -> Option<ObjectId<Self>>where
Self: Sized,
None
if the
object doesn’t currently have an ID.source§fn try_raw_id(&self) -> Option<RawObjectId>
fn try_raw_id(&self) -> Option<RawObjectId>
None
if the object doesn’t currently have an ID.source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
IntoWasmAbi::Abi
source§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
IntoWasmAbi::into_abi
, except that it may throw and never
return in the case of Err
.