-
Notifications
You must be signed in to change notification settings - Fork 12
creep tasks API
Ben Bartlett edited this page Apr 30, 2018
·
3 revisions
Property/Method | Type | Description |
---|---|---|
Creep.task |
Task |
(get/set) the task assigned to a creep |
Creep.isIdle |
boolean |
Returns true if the creep does not have a valid task (calls task.isValid ) |
Creep.hasValidTask |
boolean |
Returns true if the creep has a valid task (calls task.isValid ) |
Creep.run() |
void |
Calls creep.task.run() if the creep has a task. (Does not check for task validity!) |
RoomObject.targetedBy |
Creep[] |
Returns a list of all creeps with tasks (or task parents) targeting an object |
Additional helper properties and methods have been added to RoomObject.prototype
and RoomPosition.prototype
; see prototypes.ts
for details.
Property | Type | Description |
---|---|---|
name |
string |
Describes the action the task should do; acts as a switch for re-instantiation |
creep |
Creep |
The creep the task is assigned to |
target |
RoomObject 1
|
The target to perform an action on; exported as actionnameTargetType for TypeScript users |
targetPos |
RoomPosition |
The position of the target, accessible even if the target is not visible |
settings |
Object |
Settings common to a given type of task (e.g. range of an action); shouldn't be modified on a per-instance basis |
options |
Object |
Options configurable for a specific instance of a task (e.g. don't invalidate task if target visibility is lost) |
data |
Object |
Data pertaining to a task instance (e.g {resourceType: 'ghodium'} ) |
proto |
protoTask |
"Skeleton" task that can be serialized into memory |
eta |
number |
Approximate ticks until creep arrives at target location (assuming movespeed 1); requires use of Traveler
|
parent |
Task|null |
Task to revert to once the current task is finished |
manifest |
Task[] |
Recursively enumerates a list of the current task and all subsequent parents |
targetManifest |
RoomObject[] |
Recursively enumerates a list of the current task's target and all parents' targets |
targetPosManifest |
RoomPosition[] |
Recursively enumerates a list of the current tasks's targetPos and all parents' targetPos
|
Method | Return type | Description |
---|---|---|
fork(newTask: Task) |
Task |
Suspends execution of the current task and sets newTask.parent = currentTask . Returns newTask . |
isValidTask() |
boolean |
Abstract method to determine if a task itself is still valid |
isValidTarget() |
boolean |
Abstract method to determine if a task's target is still valid |
isValid() |
boolean |
Determines if a task is valid. If not, creep.task is reverted to task.parent . |
move(range?: number) |
number |
Moves the task's creep toward task.targetPos . range defaults to this.settings.targetRange . |
run() |
number|void |
Executes the task, moving the creep toward the target or performing the task.work() if in range. Parks creep if needed. |
parkCreep(creep, pos?, maintainDistance?) |
number |
Parks a creep near a position (default: creep.pos ) if settings.workOffRoad = true . |
work() |
number |
Abstract method that specifies the action to be performed once a creep is in range. |
finish() |
void |
Finalize the task and switch the assigned creep's task to task.parent . |
Task.settings
describes settings for a given type of task and shouldn't be modified on an instance basis, since it isn't serialized into Task.proto
:
Setting | Type | Description |
---|---|---|
targetRange |
number=1 |
Range required for the task action to be performed. |
workOffRoad |
boolean=false |
If true , parks the creep off-road while performing an action. Useful for long actions like building or repairing. |
Task.options
describes settings which can vary between different instances of a task and is serialized into Task.proto
:
Option | Type | Description |
---|---|---|
blind |
boolean=false |
If true , does not invalidate task if vision to task.target is lost and creep will continue to approach task.targetPos
|
Task.data
describes internal data for a task, such as optional arguments, which needs to be saved between ticks. Not all task instances will have all of these properties.
Parameter | Type | Description |
---|---|---|
resourceType? |
string="energy" |
Specifies the resourceType argument for applicable task actions |
amount? |
number |
Specifies the amount argument for applicable task actions |
signature? |
string |
Specifies the controller signature for TaskSignController
|
quiet? |
boolean=true |
(Deprecated) Silences console output if true . |
Property | Type | Description |
---|---|---|
name |
string |
Describes the action the task should do; acts as a switch for re-instantiation |
_creep |
{name: string} |
Contains information about the creep assigned to the task |
_target |
{ref: string, _pos: {x,y,roomName} 1
|
Contains information about the task target |
_parent |
protoTask|null |
ProtoTask of Task to revert to once task is finished |
options |
Object |
Options configurable for a specific instance of a task (e.g. don't invalidate task if target visibility is lost) |
data |
Object |
Data pertaining to a task instance (e.g {resourceType: 'ghodium'} ) |
1Exceptions: TaskDrop
, TaskGoTo
, TaskGoToRoom
, which all have a defined targetPos
, but have target = null
.