An object representing the room in which your units and structures are in.
It can be used to look around, find paths, etc. Every
RoomObject
in the room contains
its linked
Room
instance in the
room
property.
The Controller structure of this room, if present, otherwise undefined.
Total amount of energy available in all spawns and extensions in the room.
Total amount of
energyCapacity
of all spawns and extensions in the room.
room.memory.stage = 2;
A shorthand to
Memory.rooms[room.name]
. You can use it for quick access the room’s specific memory data object.
Learn more about memory
The name of the room.
The Storage structure of this room, if present, otherwise undefined.
The Terminal structure of this room, if present, otherwise undefined.
A RoomVisual object for this room. You can use this object to draw simple shapes (lines, circles, text labels) in the room.
const path = spawn.pos.findPathTo(source);
Memory.path = Room.serializePath(path);
creep.moveByPath(Memory.path);
Serialize a path array into a short string representation, which is suitable to store in memory.
parameter | type | description |
---|---|---|
path
|
array |
A path array retrieved from
|
A serialized string form of the given path.
const path = Room.deserializePath(Memory.path);
creep.moveByPath(path);
Deserialize a short string path representation into an array form.
parameter | type | description |
---|---|---|
path
|
string |
A serialized path string. |
A path array.
Game.rooms.sim.createConstructionSite(10, 15, STRUCTURE_ROAD);
Game.rooms.sim.createConstructionSite(10, 15, STRUCTURE_SPAWN,
'MySpawn2');
Create new ConstructionSite at the specified location.
parameter | type | description |
---|---|---|
x
|
number |
The X position. |
y
|
number |
The Y position. |
pos
|
object |
Can be a RoomPosition object or any object containing RoomPosition . |
structureType
|
string |
One of the
|
name
optional |
string |
The name of the structure, for structures that support it (currently only spawns). |
One of the following codes:
constant | value | description |
---|---|---|
OK
|
0 |
The operation has been scheduled successfully. |
ERR_NOT_OWNER
|
-1 |
The room is claimed or reserved by a hostile player. |
ERR_INVALID_TARGET
|
-7 |
The structure cannot be placed at the specified location. |
ERR_FULL
|
-8 |
You have too many construction sites. The maximum number of construction sites per player is 100. |
ERR_INVALID_ARGS
|
-10 |
The location is incorrect. |
ERR_RCL_NOT_ENOUGH
|
-14 |
Room Controller Level insufficient. Learn more |
Game.rooms.sim.createFlag(5, 12, 'Flag1');
Create new Flag at the specified location.
parameter | type | description |
---|---|---|
x
|
number |
The X position. |
y
|
number |
The Y position. |
pos
|
object |
Can be a RoomPosition object or any object containing RoomPosition . |
name
optional |
string |
The name of a new flag. It should be unique, i.e. the
|
color
optional |
string |
The color of a new flag. Should be one of the
|
secondaryColor
optional |
string |
The secondary color of a new flag. Should be one of the
|
The name of a new flag, or one of the following error codes:
constant | value | description |
---|---|---|
ERR_NAME_EXISTS
|
-3 |
There is a flag with the same name already. |
ERR_FULL
|
-8 |
You have too many flags. The maximum number of flags per player is 10000. |
ERR_INVALID_ARGS
|
-10 |
The location or the color constant is incorrect. |
const targets = creep.room.find(FIND_DROPPED_RESOURCES);
if(targets.length) {
creep.moveTo(targets[0]);
creep.pickup(targets[0]);
}
const extensions = Game.spawns['Spawn1'].room.find(FIND_MY_STRUCTURES, {
filter: { structureType: STRUCTURE_EXTENSION }
});
console.log('Spawn has '+extensions.length+' extensions available');
const targets = creep.room.find(FIND_HOSTILE_CREEPS, {
filter: function(object) {
return object.getActiveBodyparts(ATTACK) == 0;
}
});
Find all objects of the specified type in the room. Results are cached automatically for the specified room and type before applying any custom filters. This automatic cache lasts until the end of the tick.
parameter | type | description |
---|---|---|
type
|
number |
One of the
|
opts
optional |
object |
An object with additional options:
|
An array with the objects found.
constant | type | description |
---|---|---|
FIND_EXIT_TOP
|
RoomPosition | Only exit positions located at the top of the room. |
FIND_EXIT_RIGHT
|
RoomPosition | Only exit positions located on the right side of the room. |
FIND_EXIT_BOTTOM
|
RoomPosition | Only exit positions located at the bottom of the room. |
FIND_EXIT_LEFT
|
RoomPosition | Only exit positions located on the left side of the room. |
FIND_EXIT
|
RoomPosition | All exit positions. |
FIND_CREEPS
|
Creep | All creeps. |
FIND_MY_CREEPS
|
Creep | Only creeps owned by you. |
FIND_HOSTILE_CREEPS
|
Creep | Only creeps not owned by you. |
FIND_SOURCES_ACTIVE
|
Source | Only sources that have energy. |
FIND_SOURCES
|
Source | All sources. |
FIND_DROPPED_RESOURCES
|
Resource | All dropped resources. |
FIND_STRUCTURES
|
Structure | All structures. |
FIND_MY_STRUCTURES
|
Structure | Only structures owned by you. Does not include neutral structures. |
FIND_HOSTILE_STRUCTURES
|
Structure | Only structures not owned by you. Does not include neutral structures. |
FIND_FLAGS
|
Flag | All flags |
FIND_MY_SPAWNS
|
StructureSpawn | Only spawns owned by you. |
FIND_HOSTILE_SPAWNS
|
StructureSpawn | Spawns not owned by you. |
FIND_CONSTRUCTION_SITES
|
ConstructionSite | All construction sites. |
FIND_MY_CONSTRUCTION_SITES
|
ConstructionSite | Only construction sites owned by you. |
FIND_HOSTILE_CONSTRUCTION_SITES
|
ConstructionSite | Only construction sites not owned by you. |
FIND_MINERALS
|
Mineral | All mineral deposits. |
FIND_NUKES
|
Nuke | All launched nukes. |
FIND_TOMBSTONES
|
Tombstone | All tombstones |
const exitDir = creep.room.findExitTo(anotherCreep.room);
const exit = creep.pos.findClosestByRange(exitDir);
creep.moveTo(exit);
// or simply:
creep.moveTo(anotherCreep);
creep.moveTo(new RoomPosition(25,25, anotherCreep.pos.roomName));
Find the exit direction en route to another room. Please note that this method is not required for inter-room movement, you can simply pass the target in another room into
Creep.moveTo
method.
parameter | type | description |
---|---|---|
room
|
string, Room |
Another room name or room object. |
The room direction constant, one of the following:
FIND_EXIT_TOP
FIND_EXIT_RIGHT
FIND_EXIT_BOTTOM
FIND_EXIT_LEFT
Or one of the following error codes:
constant | value | description |
---|---|---|
ERR_NO_PATH
|
-2 |
Path can not be found. |
ERR_INVALID_ARGS
|
-10 |
The location is incorrect. |
const path = creep.room.findPath(creep.pos, targetPos);
creep.move(path[0].direction);
PathFinder.use(true);
const path = creep.room.findPath(creep.pos, targetPos, {
costCallback: function(roomName, costMatrix) {
if(roomName == 'W1N5') {
// set anotherCreep's location as walkable
costMatrix.set(anotherCreep.pos.x, anotherCreep.pos.y, 0);
// set flag location as an obstacle
costMatrix.set(flag.pos.x, flag.pos.y, 255);
// increase cost for (25,20) location to 50
costMatrix.set(25, 20, 50);
}
}
});
let path = creep.room.findPath(creep.pos, targetPos, {maxOps: 200});
if( !path.length || !targetPos.isEqualTo(path[path.length - 1]) ) {
path = creep.room.findPath(creep.pos, targetPos, {
maxOps: 1000, ignoreDestructibleStructures: true
});
}
if( path.length ) {
creep.move(path[0].direction);
}
Find an optimal path inside the room between fromPos and toPos using Jump Point Search algorithm .
parameter | type | description |
---|---|---|
fromPos
|
RoomPosition |
The start position. |
toPos
|
RoomPosition |
The end position. |
opts
optional |
object |
An object containing additonal pathfinding flags:
|
An array with path steps in the following format:
[
{ x: 10, y: 5, dx: 1, dy: 0, direction: RIGHT },
{ x: 10, y: 6, dx: 0, dy: 1, direction: BOTTOM },
{ x: 9, y: 7, dx: -1, dy: 1, direction: BOTTOM_LEFT },
...
]
// track events performed by a particular creep
_.filter(creep.room.getEventLog(), {objectId: creep.id});
// Find all hostile actions against your creeps and structures
_.forEach(Game.rooms, room => {
let eventLog = room.getEventLog();
let attackEvents = _.filter(eventLog, {event: EVENT_ATTACK});
attackEvents.forEach(event => {
let target = Game.getObjectById(event.data.targetId);
if(target && target.my) {
console.log(event);
}
});
});
Returns an array of events happened on the previous tick in this room.
parameter | type | description |
---|---|---|
raw
|
boolean |
If this parameter is false or undefined, the method returns an object parsed using
|
An array of events. Each event represents some game action in the following format:
{
event: EVENT_ATTACK,
objectId: '54bff72ab32a10f73a57d017',
data: { /* ... */ }
}
The
data
property is different for each event type according to the following table:
event | description |
---|---|
EVENT_ATTACK
|
A creep or a structure performed an attack to another object.
|
EVENT_OBJECT_DESTROYED
|
A game object is destroyed or killed.
|
EVENT_ATTACK_CONTROLLER
|
A creep performed
attackController
in the room.
|
EVENT_BUILD
|
A creep performed
build
in the room.
|
EVENT_HARVEST
|
A creep performed
harvest
in the room.
|
EVENT_HEAL
|
A creep or a tower healed a creep.
|
EVENT_REPAIR
|
A creep or a tower repaired a structure.
|
EVENT_RESERVE_CONTROLLER
|
A creep performed
reserveController
in the room.
|
EVENT_UPGRADE_CONTROLLER
|
A creep performed
upgradeController
in the room.
|
EVENT_EXIT
|
A creep moved to another room.
|
EVENT_TRANSFER
|
A link performed
transferEnergy
or a creep performed
transfer
or
withdraw
.
|
const pos = Game.rooms.sim.getPositionAt(5,12);
const source = pos.findClosestByRange(FIND_SOURCES_ACTIVE);
Creates a RoomPosition object at the specified location.
parameter | type | description |
---|---|---|
x
|
number |
The X position. |
y
|
number |
The Y position. |
A RoomPosition object or null if it cannot be obtained.
const terrain = Game.rooms['W1N1'].getTerrain();
switch(terrain.get(10,15)) {
case TERRAIN_MASK_WALL:
break;
case TERRAIN_MASK_SWAMP:
break;
case 0:
break;
}
Get a
Room.Terrain
object which provides fast access to static terrain data. This method works for any room in the world even if you have no access to it.
Returns new
Room.Terrain
object.
const look = creep.room.lookAt(target);
look.forEach(function(lookObject) {
if(lookObject.type == LOOK_CREEPS &&
lookObject[LOOK_CREEPS].getActiveBodyparts(ATTACK) == 0) {
creep.moveTo(lookObject.creep);
}
});
Get the list of objects at the specified room position.
parameter | type | description |
---|---|---|
x
|
number |
X position in the room. |
y
|
number |
Y position in the room. |
target
|
object |
Can be a RoomPosition object or any object containing RoomPosition . |
An array with objects at the specified position in the following format:
[
{ type: 'creep', creep: {...} },
{ type: 'structure', structure: {...} },
...
{ type: 'terrain', terrain: 'swamp' }
]
const look = creep.room.lookAtArea(10,5,11,7);
Get the list of objects at the specified room area.
parameter | type | description |
---|---|---|
top
|
number |
The top Y boundary of the area. |
left
|
number |
The left X boundary of the area. |
bottom
|
number |
The bottom Y boundary of the area. |
right
|
number |
The right X boundary of the area. |
asArray
optional |
boolean |
Set to true if you want to get the result as a plain array. |
If
asArray
is set to false or undefined, the method returns
an object with all the objects in the specified area in the following format:
// 10,5,11,7
{
10: {
5: [{ type: 'creep', creep: {...} },
{ type: 'terrain', terrain: 'swamp' }],
6: [{ type: 'terrain', terrain: 'swamp' }],
7: [{ type: 'terrain', terrain: 'swamp' }]
},
11: {
5: [{ type: 'terrain', terrain: 'plain' }],
6: [{ type: 'structure', structure: {...} },
{ type: 'terrain', terrain: 'swamp' }],
7: [{ type: 'terrain', terrain: 'wall' }]
}
}
If
asArray
is set to true, the method returns an array in the following format:
[
{x: 5, y: 10, type: 'creep', creep: {...}},
{x: 5, y: 10, type: 'terrain', terrain: 'swamp'},
{x: 6, y: 10, type: 'terrain', terrain: 'swamp'},
{x: 7, y: 10, type: 'terrain', terrain: 'swamp'},
{x: 5, y: 11, type: 'terrain', terrain: 'plain'},
{x: 6, y: 11, type: 'structure', structure: {...}},
{x: 6, y: 11, type: 'terrain', terrain: 'swamp'},
{x: 7, y: 11, type: 'terrain', terrain: 'wall'}
]
const found = creep.room.lookForAt(LOOK_CREEPS, target);
if(found.length && found[0].getActiveBodyparts(ATTACK) == 0) {
creep.moveTo(found[0]);
}
Get an object with the given type at the specified room position.
parameter | type | description |
---|---|---|
type
|
string |
One of the
|
x
|
number |
X position in the room. |
y
|
number |
Y position in the room. |
target
|
object |
Can be a RoomPosition object or any object containing RoomPosition . |
An array of objects of the given type at the specified position if found.
const look = creep.room.lookForAtArea(LOOK_STRUCTURES,10,5,11,7);
Get the list of objects with the given type at the specified room area.
parameter | type | description |
---|---|---|
type
|
string |
One of the
|
top
|
number |
The top Y boundary of the area. |
left
|
number |
The left X boundary of the area. |
bottom
|
number |
The bottom Y boundary of the area. |
right
|
number |
The right X boundary of the area. |
asArray
optional |
boolean |
Set to true if you want to get the result as a plain array. |
If
asArray
is set to false or undefined, the method returns an object
with all the objects of the given type in the specified area in the following format:
// 10,5,11,7
{
10: {
5: [{...}],
6: undefined,
7: undefined
},
11: {
5: undefined,
6: [{...}, {...}],
7: undefined
}
}
If
asArray
is set to true, the method returns an array in the following format:
[
{x: 5, y: 10, structure: {...}},
{x: 6, y: 11, structure: {...}},
{x: 6, y: 11, structure: {...}}
]