pub struct Creep { /* private fields */ }
Expand description
A Creep
unit in the game world.
Implementations§
source§impl Creep
impl Creep
sourcepub fn body(&self) -> Vec<BodyPart>
pub fn body(&self) -> Vec<BodyPart>
Retrieve a Vec<BodyPart>
containing details about the creep’s body
parts and boosts.
sourcepub fn fatigue(&self) -> u32
pub fn fatigue(&self) -> u32
The amount of fatigue the creep has. If greater than 0, it cannot move this tick without being pulled.
sourcepub fn hits_max(&self) -> u32
pub fn hits_max(&self) -> u32
Retrieve the maximum hits of this creep, which generally equals 50 per body part.
sourcepub fn set_memory(&self, val: &JsValue)
pub fn set_memory(&self, val: &JsValue)
Sets a new value to Memory.creeps[creep.name]
.
sourcepub fn store(&self) -> Store
pub fn store(&self) -> Store
The Store
of the creep, which contains information about what
resources it is it carrying.
sourcepub fn ticks_to_live(&self) -> Option<u32>
pub fn ticks_to_live(&self) -> Option<u32>
The number of ticks the creep has left to live
sourcepub fn attack<T>(&self, target: &T) -> Result<(), ErrorCode>where
T: ?Sized + Attackable,
pub fn attack<T>(&self, target: &T) -> Result<(), ErrorCode>where
T: ?Sized + Attackable,
Attack a target in melee range using a creep’s attack parts.
sourcepub fn attack_controller(
&self,
target: &StructureController
) -> Result<(), ErrorCode>
pub fn attack_controller( &self, target: &StructureController ) -> Result<(), ErrorCode>
Attack a StructureController
in melee range using a creep’s claim
parts.
sourcepub fn build(&self, target: &ConstructionSite) -> Result<(), ErrorCode>
pub fn build(&self, target: &ConstructionSite) -> Result<(), ErrorCode>
Use a creep’s work parts to consume carried energy, putting it toward
progress in a ConstructionSite
in range 3.
sourcepub fn cancel_order(&self, target: &JsString) -> Result<(), ErrorCode>
pub fn cancel_order(&self, target: &JsString) -> Result<(), ErrorCode>
Cancel an a successfully called creep function from earlier in the tick,
with a JsString
that must contain the JS version of the function
name.
sourcepub fn claim_controller(
&self,
target: &StructureController
) -> Result<(), ErrorCode>
pub fn claim_controller( &self, target: &StructureController ) -> Result<(), ErrorCode>
Claim an unowned StructureController
in melee range as your own
using a creep’s claim parts.
sourcepub fn claim_reactor(&self, target: &Reactor) -> Result<(), ErrorCode>
Available on crate feature seasonal-season-5
only.
pub fn claim_reactor(&self, target: &Reactor) -> Result<(), ErrorCode>
seasonal-season-5
only.Claim a Reactor
in melee range as your own using a creep’s claim
parts.
sourcepub fn dismantle<T>(&self, target: &T) -> Result<(), ErrorCode>where
T: ?Sized + Dismantleable,
pub fn dismantle<T>(&self, target: &T) -> Result<(), ErrorCode>where
T: ?Sized + Dismantleable,
Dismantle a Structure
in melee range, removing DISMANTLE_POWER
hits per effective work part, giving the creep energy equivalent to half
of the cost to repair the same hits. Can only be used against types
of structures that can be constructed; if
StructureType::construction_cost
is None
, dismantling is
impossible.
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 creep’s Store
.
sourcepub fn generate_safe_mode(
&self,
target: &StructureController
) -> Result<(), ErrorCode>
pub fn generate_safe_mode( &self, target: &StructureController ) -> Result<(), ErrorCode>
Consume ResourceType::Ghodium
(in the amount of SAFE_MODE_COST
)
from the creep’s Store
to add a safe mode activation to a
StructureController
in melee range.
sourcepub fn get_active_bodyparts(&self, ty: Part) -> u8
pub fn get_active_bodyparts(&self, ty: Part) -> u8
Get the number of parts of the given type the creep has in its body, excluding fully damaged parts.
sourcepub fn harvest<T>(&self, target: &T) -> Result<(), ErrorCode>where
T: ?Sized + Harvestable,
pub fn harvest<T>(&self, target: &T) -> Result<(), ErrorCode>where
T: ?Sized + Harvestable,
sourcepub fn heal<T>(&self, target: &T) -> Result<(), ErrorCode>
pub fn heal<T>(&self, target: &T) -> Result<(), ErrorCode>
Heal a Creep
or PowerCreep
in melee range, including itself.
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_pulled_by(&self, target: &Creep) -> Result<(), ErrorCode>
pub fn move_pulled_by(&self, target: &Creep) -> Result<(), ErrorCode>
Accept an attempt by another creep to pull this one.
sourcepub fn move_by_path(&self, path: &JsValue) -> Result<(), ErrorCode>
pub fn move_by_path(&self, path: &JsValue) -> Result<(), ErrorCode>
Move the 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 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 pull(&self, target: &Creep) -> Result<(), ErrorCode>
pub fn pull(&self, target: &Creep) -> Result<(), ErrorCode>
Help another creep to move by pulling, if the second creep accepts.
sourcepub fn ranged_attack<T>(&self, target: &T) -> Result<(), ErrorCode>where
T: ?Sized + Attackable,
pub fn ranged_attack<T>(&self, target: &T) -> Result<(), ErrorCode>where
T: ?Sized + Attackable,
Attack a target in range 3 using a creep’s ranged attack parts.
sourcepub fn ranged_heal<T>(&self, target: &T) -> Result<(), ErrorCode>
pub fn ranged_heal<T>(&self, target: &T) -> Result<(), ErrorCode>
Heal a target in range 3 using a creep’s heal parts.
sourcepub fn ranged_mass_attack(&self) -> Result<(), ErrorCode>
pub fn ranged_mass_attack(&self) -> Result<(), ErrorCode>
Attack all enemy targets in range using a creep’s ranged attack parts, with lower damage depending on range.
sourcepub fn repair<T>(&self, target: &T) -> Result<(), ErrorCode>where
T: ?Sized + Repairable,
pub fn repair<T>(&self, target: &T) -> Result<(), ErrorCode>where
T: ?Sized + Repairable,
Repair a target in range 3 using carried energy and the creep’s work parts.
sourcepub fn reserve_controller(
&self,
target: &StructureController
) -> Result<(), ErrorCode>
pub fn reserve_controller( &self, target: &StructureController ) -> Result<(), ErrorCode>
Reserve an unowned StructureController
in melee range using a
creep’s claim parts.
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 creep next tick. 10 character limit.
sourcepub fn sign_controller(
&self,
target: &StructureController,
text: &str
) -> Result<(), ErrorCode>
pub fn sign_controller( &self, target: &StructureController, text: &str ) -> Result<(), ErrorCode>
Add (or remove, using an empty string) a sign to a
StructureController
in melee range.
sourcepub fn suicide(&self) -> Result<(), ErrorCode>
pub fn suicide(&self) -> Result<(), ErrorCode>
Immediately kill the creep.
Actions taken by the creep earlier in the tick may be cancelled.
sourcepub fn upgrade_controller(
&self,
target: &StructureController
) -> Result<(), ErrorCode>
pub fn upgrade_controller( &self, target: &StructureController ) -> Result<(), ErrorCode>
Upgrade a StructureController
in range 3 using carried energy and
the creep’s work parts.
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<RoomObject> for Creep
impl AsRef<RoomObject> for Creep
source§fn as_ref(&self) -> &RoomObject
fn as_ref(&self) -> &RoomObject
source§impl Deref for Creep
impl Deref for Creep
§type Target = RoomObject
type Target = RoomObject
source§fn deref(&self) -> &RoomObject
fn deref(&self) -> &RoomObject
source§impl From<Creep> for MovableObject
impl From<Creep> for MovableObject
source§fn from(v: Creep) -> MovableObject
fn from(v: Creep) -> MovableObject
source§impl From<Creep> for ObjectWithPosition
impl From<Creep> for ObjectWithPosition
source§fn from(v: Creep) -> ObjectWithPosition
fn from(v: Creep) -> ObjectWithPosition
source§impl From<Creep> for RoomObject
impl From<Creep> for RoomObject
source§fn from(obj: Creep) -> RoomObject
fn from(obj: Creep) -> RoomObject
source§impl From<Creep> for StoreObject
impl From<Creep> for StoreObject
source§fn from(v: Creep) -> StoreObject
fn from(v: Creep) -> StoreObject
source§impl From<Creep> for TransferableObject
impl From<Creep> for TransferableObject
source§fn from(v: Creep) -> TransferableObject
fn from(v: Creep) -> TransferableObject
source§impl From<Creep> for TypedRoomObject
impl From<Creep> for TypedRoomObject
source§fn from(v: Creep) -> TypedRoomObject
fn from(v: Creep) -> TypedRoomObject
source§impl FromWasmAbi for Creep
impl FromWasmAbi for Creep
source§impl<'a> IntoWasmAbi for &'a Creep
impl<'a> IntoWasmAbi for &'a Creep
source§impl IntoWasmAbi for Creep
impl IntoWasmAbi for Creep
source§impl JsCast for Creep
impl JsCast for Creep
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 JsCollectionFromValue for Creep
impl JsCollectionFromValue for Creep
fn from_value(val: JsValue) -> Self
source§impl LongRefFromWasmAbi for Creep
impl LongRefFromWasmAbi for Creep
source§impl MaybeHasId for Creep
impl MaybeHasId for Creep
source§fn try_js_raw_id(&self) -> Option<JsString>
fn try_js_raw_id(&self) -> Option<JsString>
The Object ID of the Creep
, or None
if it began spawning this
tick.
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 OptionFromWasmAbi for Creep
impl OptionFromWasmAbi for Creep
source§impl<'a> OptionIntoWasmAbi for &'a Creep
impl<'a> OptionIntoWasmAbi for &'a Creep
source§impl OptionIntoWasmAbi for Creep
impl OptionIntoWasmAbi for Creep
source§impl RefFromWasmAbi for Creep
impl RefFromWasmAbi for Creep
§type Abi = <JsValue as RefFromWasmAbi>::Abi
type Abi = <JsValue as RefFromWasmAbi>::Abi
Self
are recovered from.§type Anchor = ManuallyDrop<Creep>
type Anchor = ManuallyDrop<Creep>
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 TryInto<Creep> for MovableObject
impl TryInto<Creep> for MovableObject
source§impl TryInto<Creep> for ObjectWithPosition
impl TryInto<Creep> for ObjectWithPosition
source§impl TryInto<Creep> for StoreObject
impl TryInto<Creep> for StoreObject
source§impl TryInto<Creep> for TransferableObject
impl TryInto<Creep> for TransferableObject
source§impl TryInto<Creep> for TypedRoomObject
impl TryInto<Creep> for TypedRoomObject
impl Attackable for Creep
impl Healable for Creep
impl Transferable for Creep
Auto Trait Implementations§
impl RefUnwindSafe for Creep
impl !Send for Creep
impl !Sync for Creep
impl Unpin for Creep
impl UnwindSafe for Creep
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> 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
.