Spawn is your colony center. This structure can create, renew, and recycle creeps.
All your spawns are accessible through
Game.spawns
hash list.
Spawns auto-regenerate a little amount of energy each tick, so that you can easily
recover even if all your creeps died.
Controller level | |
1-6 | 1 spawn |
7 | 2 spawns |
8 | 3 spawns |
Cost | 15,000 |
Hits | 5,000 |
Capacity | 300 |
Spawn time | 3 ticks per each body part |
Energy auto-regeneration | 1 energy unit per tick while energy available in the room (in all spawns and extensions) is less than 300 |
Applied effects, an array of objects with the following properties:
parameter | type | description |
---|---|---|
effect
|
number |
Effect ID of the applied effect. Can be either natural effect ID or Power ID. |
level
optional |
number |
Power level of the applied effect. Absent if the effect is not a Power effect. |
ticksRemaining
|
number |
How many ticks will the effect last. |
An object representing the position of this object in the room.
The link to the Room object. May be undefined in case if an object is a flag or a construction site and is placed in a room that is not visible to you.
The current amount of hit points of the structure.
The total amount of hit points of the structure.
A unique object identificator. You can use
Game.getObjectById
method to retrieve an object instance by its
id
.
One of the
STRUCTURE_*
constants.
Destroy this structure immediately.
One of the following codes:
constant | value | description |
---|---|---|
OK
|
0 |
The operation has been scheduled successfully. |
ERR_NOT_OWNER
|
-1 |
You are not the owner of this structure. |
ERR_BUSY
|
-4 |
Hostile creeps are in the room. |
Check whether this structure can be used. If room controller level is insufficient, then this method will return false, and the structure will be highlighted with red in the game.
A boolean value.
Toggle auto notification when the structure is under attack. The notification will be sent to your account email. Turned on by default.
parameter | type | description |
---|---|---|
enabled
|
boolean |
Whether to enable notification or disable. |
One of the following codes:
constant | value | description |
---|---|---|
OK
|
0 |
The operation has been scheduled successfully. |
ERR_NOT_OWNER
|
-1 |
You are not the owner of this structure. |
ERR_INVALID_ARGS
|
-10 |
|
Whether this is your own structure.
An object with the structure’s owner info containing the following properties:
parameter | type | description |
---|---|---|
username
|
string |
The name of the owner user. |
This property is deprecated and will be removed soon.
An alias for
.store[RESOURCE_ENERGY]
.
This property is deprecated and will be removed soon.
An alias for
.store.getCapacity(RESOURCE_ENERGY)
.
spawn.memory.queue = [];
A shorthand to
Memory.spawns[spawn.name]
. You can use it for quick access the spawn’s specific memory data object.
Learn more about memory
Spawn’s name. You choose the name upon creating a new spawn, and it cannot be changed later. This name is a hash key to access the spawn via the Game.spawns object.
If the spawn is in process of spawning a new creep, this object will contain a
StructureSpawn.Spawning
object, or null otherwise.
if(structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0) {
creep.transfer(structure, RESOURCE_ENERGY);
}
A
Store
object that contains cargo of this structure.
This method is deprecated and will be removed soon. Please use
StructureSpawn.spawnCreep
with
dryRun
flag instead.
if(spawn.canCreateCreep(body, name) == OK) {
spawn.createCreep(body, name);
}
Check if a creep can be created.
parameter | type | description |
---|---|---|
body
|
array<string> |
An array describing the new creep’s body. Should contain 1 to 50 elements with one of these constants:
|
name
optional |
string |
The name of a new creep. It should be unique creep name, i.e. the
|
One of the following codes:
constant | value | description |
---|---|---|
OK
|
0 |
A creep with the given body and name can be created. |
ERR_NOT_OWNER
|
-1 |
You are not the owner of this spawn. |
ERR_NAME_EXISTS
|
-3 |
There is a creep with the same name already. |
ERR_BUSY
|
-4 |
The spawn is already in process of spawning another creep. |
ERR_NOT_ENOUGH_ENERGY
|
-6 |
The spawn and its extensions contain not enough energy to create a creep with the given body. |
ERR_INVALID_ARGS
|
-10 |
Body is not properly described. |
ERR_RCL_NOT_ENOUGH
|
-14 |
Your Room Controller level is insufficient to use this spawn. |
This method is deprecated and will be removed soon. Please use
StructureSpawn.spawnCreep
instead.
Game.spawns['Spawn1'].createCreep([WORK, CARRY, MOVE], 'Worker1');
Game.spawns['Spawn1'].createCreep([WORK, CARRY, MOVE], null,
{role: 'harvester'});
const result = Game.spawns['Spawn1'].createCreep([WORK, CARRY, MOVE]);
if(_.isString(result)) {
console.log('The name is: '+result);
}
else {
console.log('Spawn error: '+result);
}
Start the creep spawning process. The required energy amount can be withdrawn from all spawns and extensions in the room.
parameter | type | description |
---|---|---|
body
|
array<string> |
An array describing the new creep’s body. Should contain 1 to 50 elements with one of these constants:
|
name
optional |
string |
The name of a new creep. It should be unique creep name, i.e. the
|
memory
optional |
any |
The memory of a new creep. If provided, it will be immediately stored into
|
The name of a new creep or one of these error codes:
constant | value | description |
---|---|---|
ERR_NOT_OWNER
|
-1 |
You are not the owner of this spawn. |
ERR_NAME_EXISTS
|
-3 |
There is a creep with the same name already. |
ERR_BUSY
|
-4 |
The spawn is already in process of spawning another creep. |
ERR_NOT_ENOUGH_ENERGY
|
-6 |
The spawn and its extensions contain not enough energy to create a creep with the given body. |
ERR_INVALID_ARGS
|
-10 |
Body is not properly described. |
ERR_RCL_NOT_ENOUGH
|
-14 |
Your Room Controller level is insufficient to use this spawn. |
Game.spawns['Spawn1'].spawnCreep([WORK, CARRY, MOVE], 'Worker1');
Game.spawns['Spawn1'].spawnCreep([WORK, CARRY, MOVE], 'Worker1', {
memory: {role: 'harvester'}
});
Game.spawns['Spawn1'].spawnCreep([WORK, CARRY, MOVE], 'Worker1', {
energyStructures: [
Game.spawns['Spawn1'],
Game.getObjectById('anExtensionId')
]
});
var testIfCanSpawn = Game.spawns['Spawn1'].spawnCreep([WORK, CARRY, MOVE],
'Worker1', { dryRun: true });
Start the creep spawning process. The required energy amount can be withdrawn from all spawns and extensions in the room.
parameter | type | description |
---|---|---|
body
|
array<string> |
An array describing the new creep’s body. Should contain 1 to 50 elements with one of these constants:
|
name
|
string |
The name of a new creep. It must be a unique creep name, i.e. the
|
opts
optional |
object |
An object with additional options for the spawning process.
|
One of the following codes:
constant | value | description |
---|---|---|
OK
|
0 |
The operation has been scheduled successfully. |
ERR_NOT_OWNER
|
-1 |
You are not the owner of this spawn. |
ERR_NAME_EXISTS
|
-3 |
There is a creep with the same name already. |
ERR_BUSY
|
-4 |
The spawn is already in process of spawning another creep. |
ERR_NOT_ENOUGH_ENERGY
|
-6 |
The spawn and its extensions contain not enough energy to create a creep with the given body. |
ERR_INVALID_ARGS
|
-10 |
Body is not properly described or name was not provided. |
ERR_RCL_NOT_ENOUGH
|
-14 |
Your Room Controller level is insufficient to use this spawn. |
Kill the creep and drop up to 100% of resources spent on its spawning and boosting depending on remaining life time. The target should be at adjacent square. Energy return is limited to 125 units per body part.
parameter | type | description |
---|---|---|
target
|
Creep |
The target creep object. |
One of the following codes:
constant | value | description |
---|---|---|
OK
|
0 |
The operation has been scheduled successfully. |
ERR_NOT_OWNER
|
-1 |
You are not the owner of this spawn or the target creep. |
ERR_INVALID_TARGET
|
-7 |
The specified target object is not a creep. |
ERR_NOT_IN_RANGE
|
-9 |
The target creep is too far away. |
ERR_RCL_NOT_ENOUGH
|
-14 |
Your Room Controller level is insufficient to use this spawn. |
Increase the remaining time to live of the target creep. The target should be at adjacent square. The spawn should not be busy with the spawning process. Each execution increases the creep's timer by amount of ticks according to this formula:
floor(600/body_size)
Energy required for each execution is determined using this formula:
ceil(creep_cost/2.5/body_size)
Renewing a creep removes all of its boosts.
parameter | type | description |
---|---|---|
target
|
Creep |
The target creep object. |
One of the following codes:
constant | value | description |
---|---|---|
OK
|
0 |
The operation has been scheduled successfully. |
ERR_NOT_OWNER
|
-1 |
You are not the owner of the spawn, or the creep. |
ERR_BUSY
|
-4 |
The spawn is spawning another creep. |
ERR_NOT_ENOUGH_ENERGY
|
-6 |
The spawn does not have enough energy. |
ERR_INVALID_TARGET
|
-7 |
The specified target object is not a creep. |
ERR_FULL
|
-8 |
The target creep's time to live timer is full. |
ERR_NOT_IN_RANGE
|
-9 |
The target creep is too far away. |
ERR_RCL_NOT_ENOUGH
|
-14 |
Your Room Controller level is insufficient to use this spawn. |