The main global game object containing all the game play information.
A hash containing all your construction sites with their id as hash keys.
An object containing information about your CPU usage with the following properties:
parameter | type | description |
---|---|---|
limit | number | Your assigned CPU limit for the current shard. |
tickLimit | number | An amount of available CPU time at the current game tick. |
bucket | number | An amount of unused CPU accumulated in your bucket. |
shardLimits | object <string,number> | An object with limits for each shard with shard names as keys. You can use |
unlocked | boolean | Whether full CPU is currently unlocked for your account. |
unlockedTime | number | The time in milliseconds since UNIX epoch time until full CPU is unlocked for your account. This property is not defined when full CPU is not unlocked for your account or it's unlocked with a subscription. |
for(const i in Game.creeps) {
Game.creeps[i].moveTo(flag);
}
A hash containing all your creeps with creep names as hash keys.
creep.moveTo(Game.flags.Flag1);
A hash containing all your flags with flag names as hash keys.
Your Global Control Level, an object with the following properties :
parameter | type | description |
---|---|---|
level | number | The current level. |
progress | number | The current progress to the next level. |
progressTotal | number | The progress required to reach the next level. |
Your Global Power Level, an object with the following properties :
parameter | type | description |
---|---|---|
level | number | The current level. |
progress | number | The current progress to the next level. |
progressTotal | number | The progress required to reach the next level. |
A global object representing world map. See the documentation below.
A global object representing the in-game market. See the documentation below.
Game.powerCreeps['PC1'].moveTo(flag);
A hash containing all your power creeps with their names as hash keys. Even power creeps not spawned in the world can be accessed here.
An object with your global resources that are bound to the account, like pixels or cpu unlocks. Each object key is a resource constant, values are resources amounts.
A hash containing all the rooms available to you with room names as hash keys. A room is visible if you have a creep or an owned structure in it.
An object describing the world shard where your script is currently being executed in.
parameter | type | description |
---|---|---|
name | string | The name of the shard. |
type | string | Currently always equals to |
ptr | boolean | Whether this shard belongs to the PTR. |
for(const i in Game.spawns) {
Game.spawns[i].createCreep(body);
}
A hash containing all your spawns with spawn names as hash keys.
A hash containing all your structures with structure id as hash keys.
console.log(Game.time);
System game tick counter. It is automatically incremented on every tick. Learn more
let heap = Game.cpu.getHeapStatistics();
console.log(`Used ${heap.total_heap_size} / ${heap.heap_size_limit}`);
This method is only available when Virtual machine is set to Isolated in your account runtime settings.
Use this method to get heap statistics for your virtual machine. The return value is almost identical to the Node.js function v8.getHeapStatistics()
. This function returns one additional property: externally_allocated_size
which is the total amount of currently allocated memory which is not included in the v8 heap but counts against this isolate's memory limit. ArrayBuffer
instances over a certain size are externally allocated and will be counted here.
Returns an objects with heap statistics in the following format:
{
"total_heap_size": 29085696,
"total_heap_size_executable": 3670016,
"total_physical_size": 26447928,
"total_available_size": 319649520,
"used_heap_size": 17493824,
"heap_size_limit": 343932928,
"malloced_memory": 8192,
"peak_malloced_memory": 1060096,
"does_zap_garbage": 0,
"externally_allocated_size": 38430000
}
if(Game.cpu.getUsed() > Game.cpu.tickLimit / 2) {
console.log("Used half of CPU already!");
}
for(const name in Game.creeps) {
const startCpu = Game.cpu.getUsed();
// creep logic goes here
const elapsed = Game.cpu.getUsed() - startCpu;
console.log('Creep '+name+' has used '+elapsed+' CPU time');
}
Get amount of CPU time used from the beginning of the current game tick. Always returns 0 in the Simulation mode.
Returns currently used CPU time as a float number.
Game.cpu.halt();
This method is only available when Virtual machine is set to Isolated in your account runtime settings.
Reset your runtime environment and wipe all data in heap memory.
Game.cpu.setShardLimits({shard0: 20, shard1: 10});
Allocate CPU limits to different shards. Total amount of CPU should remain equal to
Game.cpu.shardLimits
. This method can be used only once per 12 hours.
parameter | type | description |
---|---|---|
limits | object<string, number> | An object with CPU values for each shard in the same format as |
One of the following codes:
constant | value | description |
---|---|---|
OK | 0 | The operation has been scheduled successfully. |
ERR_BUSY | -4 | 12-hours cooldown period is not over yet. |
ERR_INVALID_ARGS | -10 | The argument is not a valid shard limits object. |
if(Game.cpu.unlockedTime && ((Game.cpu.unlockedTime - Date.now()) < 1000*60*60*24)) {
Game.cpu.unlock();
}
Unlock full CPU for your account for additional 24 hours. This method will consume 1 CPU unlock bound to your account (See Game.resources
).
If full CPU is not currently unlocked for your account, it may take some time (up to 5 minutes) before unlock is applied to your account.
One of the following codes:
constant | value | description |
---|---|---|
OK | 0 | The operation has been scheduled successfully. |
ERR_NOT_ENOUGH_RESOURCES | -6 | Your account does not have enough |
ERR_FULL | -8 | Your CPU is unlocked with a subscription. |
if(Game.cpu.bucket == 10000) {
Game.cpu.generatePixel();
}
Generate 1 pixel resource unit for 10000 CPU from your bucket.
constant | value | description |
---|---|---|
OK | 0 | The operation has been scheduled successfully. |
ERR_NOT_ENOUGH_RESOURCES | -6 | Your bucket does not have enough CPU. |
creep.memory.sourceId = creep.pos.findClosestByRange(FIND_SOURCES).id;
const source = Game.getObjectById(creep.memory.sourceId);
Get an object with the specified unique ID. It may be a game object of any type. Only objects from the rooms which are visible to you can be accessed.
parameter | type | description |
---|---|---|
id | string | The unique identificator. |
Returns an object instance or null if it cannot be found.
if(creep.hits < creep.memory.lastHits) {
Game.notify('Creep '+creep+' has been attacked at '+creep.pos+'!');
}
creep.memory.lastHits = creep.hits;
if(Game.spawns['Spawn1'].energy == 0) {
Game.notify(
'Spawn1 is out of energy',
180 // group these notifications for 3 hours
);
}
Send a custom message at your profile email. This way, you can set up notifications to yourself on any occasion within the game. You can schedule up to 20 notifications during one game tick. Not available in the Simulation Room.
parameter | type | description |
---|---|---|
message | string | Custom text which will be sent in the message. Maximum length is 1000 characters. |
groupInterval | number | If set to 0 (default), the notification will be scheduled immediately. Otherwise, it will be grouped with other notifications and mailed out later using the specified time in minutes. |
InterShardMemory
object provides an interface for communicating between shards. Your script is executed separatedly
on each shard, and their Memory
objects are isolated from each other. In order to pass messages and
data between shards, you need to use InterShardMemory
instead.
Every shard can have its own 100 KB of data in string format that can be accessed by all other shards. A shard can write only to its own data, other shards' data is read-only.
This data has nothing to do with Memory
contents, it's a separate data container.
Returns the string contents of the current shard's data.
var data = JSON.parse(InterShardMemory.getLocal() || "{}");
data.message = "hello from another shard!";
InterShardMemory.setLocal(JSON.stringify(data));
Replace the current shard's data with the new value.
parameter | type | description |
---|---|---|
value | string | New data value in string format. |
var data = JSON.parse(InterShardMemory.getRemote('shard0') || "{}");
console.log(data.message);
Returns the string contents of another shard's data.
parameter | type | description |
---|---|---|
shard | string | Shard name. |
A global object representing world map. Use it to navigate between rooms.
const exits = Game.map.describeExits('W8N3');
List all exits available from the room with the given name.
parameter | type | description |
---|---|---|
roomName | string | The room name. |
The exits information in the following format, or null if the room not found.
{
"1": "W8N4", // TOP
"3": "W7N3", // RIGHT
"5": "W8N2", // BOTTOM
"7": "W9N3" // LEFT
}
if(creep.room != anotherRoomName) {
const exitDir = Game.map.findExit(creep.room, anotherRoomName);
const exit = creep.pos.findClosestByRange(exitDir);
creep.moveTo(exit);
}
else {
// go to some place in another room
}
creep.moveTo(new RoomPosition(25, 25, anotherRoomName));
Find the exit direction from the given room en route to another room.
parameter | type | description |
---|---|---|
fromRoom | string, Room | Start room name or room object. |
toRoom | string, Room | Finish room name or room object. |
opts optional | object | An object with the pathfinding options. See |
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 route = Game.map.findRoute(creep.room, anotherRoomName);
if(route.length > 0) {
console.log('Now heading to room '+route[0].room);
const exit = creep.pos.findClosestByRange(route[0].exit);
creep.moveTo(exit);
}
const route = Game.map.findRoute(creep.room, anotherRoomName, {
routeCallback(roomName, fromRoomName) {
if(roomName == 'W10S10') { // avoid this room
return Infinity;
}
return 1;
}});
let from = new RoomPosition(25, 25, 'E1N1');
let to = new RoomPosition(25, 25, 'E4N1');
// Use `findRoute` to calculate a high-level plan for this path,
// prioritizing highways and owned rooms
let allowedRooms = { [ from.roomName ]: true };
Game.map.findRoute(from.roomName, to.roomName, {
routeCallback(roomName) {
let parsed = /^[WE]([0-9]+)[NS]([0-9]+)$/.exec(roomName);
let isHighway = (parsed[1] % 10 === 0) ||
(parsed[2] % 10 === 0);
let isMyRoom = Game.rooms[roomName] &&
Game.rooms[roomName].controller &&
Game.rooms[roomName].controller.my;
if (isHighway || isMyRoom) {
return 1;
} else {
return 2.5;
}
}
}).forEach(function(info) {
allowedRooms[info.room] = true;
});
// Invoke PathFinder, allowing access only to rooms from `findRoute`
let ret = PathFinder.search(from, to, {
roomCallback(roomName) {
if (allowedRooms[roomName] === undefined) {
return false;
}
}
});
console.log(ret.path);
Find route from the given room to another room.
parameter | type | description |
---|---|---|
fromRoom | string, Room | Start room name or room object. |
toRoom | string, Room | Finish room name or room object. |
opts optional | object | An object with the following options:
|
The route array in the following format:
[
{ exit: FIND_EXIT_RIGHT, room: 'arena21' },
{ exit: FIND_EXIT_BOTTOM, room: 'arena22' },
...
]
Or one of the following error codes:
constant | value | description |
---|---|---|
ERR_NO_PATH | -2 | Path can not be found. |
Game.map.getRoomLinearDistance('W1N1', 'W4N2'); // 3
Game.map.getRoomLinearDistance('E65S55','W65S55', false) // 131
Game.map.getRoomLinearDistance('E65S55','W65S55', true) // 11
Get the linear distance (in rooms) between two rooms. You can use this function to estimate the energy cost of sending resources through terminals, or using observers and nukes.
parameter | type | description |
---|---|---|
roomName1 | string | The name of the first room. |
roomName2 | string | The name of the second room. |
continuous optional | boolean | Whether to treat the world map continuous on borders. Set to true if you want to calculate the trade or terminal send cost. Default is false. |
A number of rooms between the given two rooms.
const terrain = Game.map.getRoomTerrain("E2S7");
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.
parameter | type | description |
---|---|---|
roomName | string | The room name. |
Returns new Room.Terrain
object.
This method is deprecated and will be removed soon. Please use a faster method Game.map.getRoomTerrain
instead.
console.log(Game.map.getTerrainAt(25,20,'W10N10'));
console.log(Game.map.getTerrainAt(new RoomPosition(25,20,'W10N10'));
Get terrain type at the specified room position. This method works for any room in the world even if you have no access to it.
parameter | type | description |
---|---|---|
x | number | X position in the room. |
y | number | Y position in the room. |
roomName | string | The room name. |
pos | RoomPosition | The position object. |
One of the following string values:
plain
swamp
wall
Returns the world size as a number of rooms between world corners. For example, for a world with rooms from W50N50 to E50S50 this method will return 102.
This method is deprecated and will be removed soon. Please use Game.map.getRoomStatus
instead.
if(Game.map.isRoomAvailable(room.name)) {
creep.moveTo(room.getPositionAt(25,25));
}
Check if the room is available to move into.
parameter | type | description |
---|---|---|
roomName | string | The room name. |
A boolean value.
if(Game.map.getRoomStatus(room.name).status == 'normal') {
nuker.launchNuke(room.getPositionAt(25,25));
}
Gets availablity status of the room with the specified name. Learn more about starting areas from this article.
parameter | type | description |
---|---|---|
roomName | string | The room name. |
An object containing the following properties:
property | type | description |
---|---|---|
status |
string | One of the following string values:
|
timestamp |
number | Status expiration time in milliseconds since UNIX epoch time. This property is null if the status is permanent. |
Map visuals provide a way to show various visual debug info on the game map. You can use the Game.map.visual
object to draw simple shapes that are visible only to you.
Map visuals are not stored in the database, their only purpose is to display something in your browser. All drawings will persist for one tick and will disappear if not updated. All Game.map.visual
calls have no added CPU cost (their cost is natural and mostly related to simple JSON.serialize
calls). However, there is a usage limit: you cannot post more than 1000 KB of serialized data.
All draw coordinates are measured in global game coordinates (RoomPosition
).
Game.map.visual.line(creep.pos, target.pos,
{color: '#ff0000', lineStyle: 'dashed'});
Draw a line.
parameter | type | description |
---|---|---|
pos1 | RoomPosition | The start position object. |
pos2 | RoomPosition | The finish position object. |
style optional | object | An object with the following properties:
|
The MapVisual
object itself, so that you can chain calls.
Game.map.visual.circle(new RoomPosition(25,25,'E2S7'));
Game.map.visual.circle(nuker.pos, {fill: 'transparent', radius: NUKE_RANGE*50, stroke: '#ff0000'});
Draw a circle.
parameter | type | description |
---|---|---|
pos | RoomPosition | The position object of the center. |
style optional | object | An object with the following properties:
|
The MapVisual
object itself, so that you can chain calls.
// the max efficiency area of the tower
Game.map.visual.rect(new RoomPosition(tower.pos.x - 5, tower.pos.y - 5, tower.pos.roomName),
11, 11,
{fill: 'transparent', stroke: '#ff0000'});
Draw a rectangle.
parameter | type | description |
---|---|---|
topLeftPos | RoomPosition | The position object of the top-left corner. |
width | number | The width of the rectangle. |
height | number | The height of the rectangle. |
style optional | object | An object with the following properties:
|
The MapVisual
object itself, so that you can chain calls.
const points = [];
points.push(creep1.pos);
points.push(Game.rooms.E2S7.storage.pos);
points.push(new RoomPosition(20,21,'W1N1'));
Game.map.visual.poly(points, {fill: 'aqua'});
// visualize the path
const path = PathFinder.search(creep.pos, creep.room.storage.pos).path;
Game.map.visual.poly(path, {stroke: '#ffffff', strokeWidth: .8, opacity: .2, lineStyle: 'dashed'});
Draw a polyline.
parameter | type | description |
---|---|---|
points | array | An array of points. Every item should be a |
style optional | object | An object with the following properties:
|
The MapVisual
object itself, so that you can chain calls.
Game.map.visual.text("Target💥", new RoomPosition(11,14,'E2S7'), {color: '#FF0000', fontSize: 10});
Draw a text label. You can use any valid Unicode characters, including emoji.
parameter | type | description |
---|---|---|
text | string | The text message. |
pos | RoomPosition | The position object of the label baseline. |
style optional | object | An object with the following properties:
|
The MapVisual
object itself, so that you can chain calls.
Game.map.visual.clear();
Remove all visuals from the map.
The MapVisual
object itself, so that you can chain calls.
if(Game.map.visual.getSize() >= 1024000) {
// cannot add more visuals in this tick
}
Get the stored size of all visuals added on the map in the current tick. It must not exceed 1024,000 (1000 KB).
The size of the visuals in bytes.
Memory.MapVisualData = Game.map.visual.export();
Returns a compact representation of all visuals added on the map in the current tick.
A string with visuals data. There's not much you can do with the string besides store them for later.
Game.map.visual.import(Memory.MapVisualData);
Add previously exported (with Game.map.visual.export) map visuals to the map visual data of the current tick.
parameter | type | description |
---|---|---|
val | string | The string returned from Game.map.visual.export. |
The MapVisual
object itself, so that you can chain calls.
A global object representing the in-game market. You can use this object to track resource transactions to/from your terminals, and your buy/sell orders.
Learn more about the market system from this article.
Your current credits balance.
[{
transactionId : "56dec546a180ce641dd65960",
time : 10390687,
sender : {username: "Sender"},
recipient : {username: "Me"},
resourceType : "U",
amount : 100,
from : "W0N0",
to : "W10N10",
description : "trade contract #1",
order: { // optional
id : "55c34a6b5be41a0a6e80c68b",
type : "sell",
price : 2.95
}
}]
An array of the last 100 incoming transactions to your terminals with the following format:
[{
transactionId : "56dec546a180ce641dd65960",
time : 10390687,
sender : {username: "Me"},
recipient : {username: "Recipient"},
resourceType : "U",
amount : 100,
from : "W0N0",
to : "W10N10",
description : "trade contract #1",
order: { // optional
id : "55c34a6b5be41a0a6e80c68b",
type : "sell",
price : 2.95
}
}]
An array of the last 100 outgoing transactions from your terminals with the following format:
{
"55c34a6b5be41a0a6e80c68b": {
id : "55c34a6b5be41a0a6e80c68b",
created : 13131117,
active: true,
type : "sell"
resourceType : "OH",
roomName : "W1N1",
amount : 15821,
remainingAmount : 30000,
totalAmount : 50000,
price : 2.95
},
"55c34a6b52411a0a6e80693a": {
id : "55c34a6b52411a0a6e80693a",
created : 13134122,
active: true,
type : "buy"
resourceType : "energy",
roomName : "W1N1",
amount : 94000,
remainingAmount : 94000,
totalAmount : 94000
price : 0.45
},
"55c34a6b5be41a0a6e80c123": {
id : "55c34a6b5be41a0a6e80c123",
created : 13105123,
active: false,
type : "sell"
resourceType : "token",
amount : 0,
remainingAmount : 10,
totalAmount : 10,
price : 50000
}
}
An object with your active and inactive buy/sell orders on the market.
See
getAllOrders
for properties explanation.
const cost = Game.market.calcTransactionCost(1000, 'W0N0', 'W10N5');
// -> 284 energy units
Estimate the energy transaction cost of StructureTerminal.send
and Game.market.deal
methods.
The formula:
Math.ceil( amount * ( 1 - Math.exp(-distanceBetweenRooms/30) ) )
parameter | type | description |
---|---|---|
amount | number | Amount of resources to be sent. |
roomName1 | string | The name of the first room. |
roomName2 | string | The name of the second room. |
The amount of energy required to perform the transaction.
for(const id in Game.market.orders) {
Game.market.cancelOrder(id);
}
Cancel a previously created order. The 5% fee is not returned.
parameter | type | description |
---|---|---|
orderId | string | The order ID as provided in |
One of the following codes:
constant | value | description |
---|---|---|
OK | 0 | The operation has been scheduled successfully. |
ERR_INVALID_ARGS | -10 | The order ID is not valid. |
Game.market.changeOrderPrice('57bec1bf77f4d17c4c011960', 9.95);
Change the price of an existing order. If newPrice
is greater than old price, you will be charged (newPrice-oldPrice)*remainingAmount*0.05
credits.
parameter | type | description |
---|---|---|
orderId | string | The order ID as provided in |
newPrice | number | The new order price. |
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 room's terminal or there is no terminal. |
ERR_NOT_ENOUGH_RESOURCES | -6 | You don't have enough credits to pay a fee. |
ERR_INVALID_ARGS | -10 | The arguments provided are invalid. |
Game.market.createOrder({
type: ORDER_SELL,
resourceType: RESOURCE_GHODIUM,
price: 9.95,
totalAmount: 10000,
roomName: "W1N1"
});
Create a market order in your terminal. You will be charged price*amount*0.05
credits when the order is placed. The maximum orders count is 300 per player. You can create an order at any time with any amount, it will be automatically activated and deactivated depending on the resource/credits availability.
parameter | type | description |
---|---|---|
params | object | An object with the following params:
|
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 room's terminal or there is no terminal. |
ERR_NOT_ENOUGH_RESOURCES | -6 | You don't have enough credits to pay a fee. |
ERR_FULL | -8 | You cannot create more than 50 orders. |
ERR_INVALID_ARGS | -10 | The arguments provided are invalid. |
Game.market.deal('57cd2b12cda69a004ae223a3', 1000, "W1N1");
const amountToBuy = 2000, maxTransferEnergyCost = 500;
const orders = Game.market.getAllOrders({type: ORDER_SELL, resourceType: RESOURCE_GHODIUM});
for(let i=0; i<orders.length; i++) {
const transferEnergyCost = Game.market.calcTransactionCost(
amountToBuy, 'W1N1', orders[i].roomName);
if(transferEnergyCost < maxTransferEnergyCost) {
Game.market.deal(orders[i].id, amountToBuy, "W1N1");
break;
}
}
Execute a trade deal from your Terminal in yourRoomName
to another player's Terminal using the specified buy/sell order. Your Terminal will be charged energy units of transfer cost regardless of the order resource type. You can use Game.market.calcTransactionCost
method to estimate it. When multiple players try to execute the same deal, the one with the shortest distance takes precedence. You cannot execute more than 10 deals during one tick.
parameter | type | description |
---|---|---|
orderId | string | The order ID as provided in |
amount | number | The amount of resources to transfer. |
yourRoomName optional | string | The name of your room which has to contain an active Terminal with enough amount of energy. This argument is not used when the order resource type is one of account-bound resources (See |
One of the following codes:
constant | value | description |
---|---|---|
OK | 0 | The operation has been scheduled successfully. |
ERR_NOT_OWNER | -1 | You don't have a terminal in the target room. |
ERR_NOT_ENOUGH_RESOURCES | -6 | You don't have enough credits or resource units. |
ERR_FULL | -8 | You cannot execute more than 10 deals during one tick. |
ERR_INVALID_ARGS | -10 | The arguments provided are invalid. |
ERR_TIRED | -11 | The target terminal is still cooling down. |
Game.market.extendOrder('57bec1bf77f4d17c4c011960', 10000);
Add more capacity to an existing order. It will affect remainingAmount
and totalAmount
properties. You will be charged price*addAmount*0.05
credits.
parameter | type | description |
---|---|---|
orderId | string | The order ID as provided in |
addAmount | number | How much capacity to add. Cannot be a negative value. |
One of the following codes:
constant | value | description |
---|---|---|
OK | 0 | The operation has been scheduled successfully. |
ERR_NOT_ENOUGH_RESOURCES | -6 | You don't have enough credits to pay a fee. |
ERR_INVALID_ARGS | -10 | The arguments provided are invalid. |
Game.market.getAllOrders(); // slow
Game.market.getAllOrders({type: ORDER_SELL, resourceType: RESOURCE_GHODIUM}); // fast
const targetRoom = "W1N1";
Game.market.getAllOrders(order => order.resourceType == RESOURCE_GHODIUM &&
order.type == ORDER_SELL &&
Game.market.calcTransactionCost(1000, targetRoom, order.roomName) < 500); // slow
// Output:
[{
id : "55c34a6b5be41a0a6e80c68b",
created : 13131117,
type : "sell",
resourceType : "OH",
roomName : "W1N1",
amount : 15821,
remainingAmount : 30000,
price : 2.95
}, {
createdTimestamp: 1543253147522,
type: "sell",
amount: 1000,
remainingAmount: 1000,
resourceType: "O",
price: 1,
roomName: "E2S7",
created: 12010056,
id: "5bfc2c9bd719fb605037c06d"
}, {
id : "55c34a6b5be41a0a6e80c123",
createdTimestamp: 1543253155580,
type : "sell",
resourceType : "token",
amount : 3,
remainingAmount : 10,
price : 50000
}]
Get other players' orders currently active on the market. This method supports internal indexing by resourceType
.
parameter | type | description |
---|---|---|
filter optional | object, function | An object or function that will filter the resulting list using the |
An orders array in the following form:
property | description |
---|---|
id |
The unique order ID. |
created |
The order creation time in game ticks. This property is absent for orders of the inter-shard market. |
createdTimestamp |
The order creation time in milliseconds since UNIX epoch time. This property is absent for old orders. |
type |
Either ORDER_SELL or ORDER_BUY . |
resourceType |
Either one of the RESOURCE_* constants or one of account-bound resources (See INTERSHARD_RESOURCES constant). |
roomName |
The room where this order is placed. |
amount |
Currently available amount to trade. |
remainingAmount |
How many resources are left to trade via this order. |
price |
The current price per unit. |
Get daily price history of the specified resource on the market for the last 14 days.
parameter | type | description |
---|---|---|
resourceType optional | string | One of the |
Returns an array of objects with the following format:
[{
"resourceType": "L",
"date": "2019-06-24",
"transactions": 4,
"volume": 400,
"avgPrice": 3.63,
"stddevPrice": 0.27
}]
const order = Game.market.getOrderById('55c34a6b5be41a0a6e80c123');
Retrieve info for specific market order.
parameter | type | description |
---|---|---|
id | string | The order ID. |
An object with the order info. See
getAllOrders
for properties explanation.
A global plain object which can contain arbitrary data. You can access it both using the API and the Memory UI in the game editor. Learn how to work with memory from this article.
Contains powerful methods for pathfinding in the game world. This module is written in fast native C++ code and supports custom navigation costs and paths which span multiple rooms.
let creep = Game.creeps.John;
let goals = _.map(creep.room.find(FIND_SOURCES), function(source) {
// We can't actually walk on sources-- set `range` to 1
// so we path next to it.
return { pos: source.pos, range: 1 };
});
let ret = PathFinder.search(
creep.pos, goals,
{
// We need to set the defaults costs higher so that we
// can set the road cost lower in `roomCallback`
plainCost: 2,
swampCost: 10,
roomCallback: function(roomName) {
let room = Game.rooms[roomName];
// In this example `room` will always exist, but since
// PathFinder supports searches which span multiple rooms
// you should be careful!
if (!room) return;
let costs = new PathFinder.CostMatrix;
room.find(FIND_STRUCTURES).forEach(function(struct) {
if (struct.structureType === STRUCTURE_ROAD) {
// Favor roads over plain tiles
costs.set(struct.pos.x, struct.pos.y, 1);
} else if (struct.structureType !== STRUCTURE_CONTAINER &&
(struct.structureType !== STRUCTURE_RAMPART ||
!struct.my)) {
// Can't walk through non-walkable buildings
costs.set(struct.pos.x, struct.pos.y, 0xff);
}
});
// Avoid creeps in the room
room.find(FIND_CREEPS).forEach(function(creep) {
costs.set(creep.pos.x, creep.pos.y, 0xff);
});
return costs;
},
}
);
let pos = ret.path[0];
creep.move(creep.pos.getDirectionTo(pos));
Find an optimal path between origin
and goal
.
parameter | type | description |
---|---|---|
origin | RoomPosition | The start position. |
goal | object | A goal or an array of goals. If more than one goal is supplied then the cheapest path found out of all the goals will be returned. A goal is either a RoomPosition or an object as defined below. Important: Please note that if your goal is not walkable (for instance, a source) then you should set
|
opts optional | object | An object containing additional pathfinding flags.
|
An object containing the following properties:
property | description |
---|---|
path |
An array of RoomPosition objects. |
ops |
Total number of operations performed before this path was calculated. |
cost |
The total cost of the path as derived from plainCost , swampCost and any given CostMatrix instances. |
incomplete |
If the pathfinder fails to find a complete path, this will be true. Note that path will still be populated with a partial path which represents the closest path it could find given the search parameters. |
This method is deprecated and will be removed soon.
PathFinder.use(true);
Game.creeps.John.moveTo(Game.spawns['Spawn1']);
Specify whether to use this new experimental pathfinder in game objects methods. This method should be invoked every tick. It affects the following methods behavior: Room.findPath
, RoomPosition.findPathTo
, RoomPosition.findClosestByPath
, Creep.moveTo
.
parameter | type | description |
---|---|---|
isEnabled | boolean | Whether to activate the new pathfinder or deactivate. The default is |
RawMemory object allows to implement your own memory stringifier instead of built-in serializer
based on JSON.stringify
. It also allows to request up to 10 MB of additional memory
using asynchronous memory segments feature.
You can also access memory segments of other players using methods below.
RawMemory.setActiveSegments([0,3]);
// on the next tick
console.log(RawMemory.segments[0]);
console.log(RawMemory.segments[3]);
RawMemory.segments[3] = '{"foo": "bar", "counter": 15}';
An object with asynchronous memory segments available on this tick. Each object key is the segment ID with data in string values. Use setActiveSegments
to fetch segments on the next tick. Segments data is saved automatically in the end of the tick. The maximum size per segment is 100 KB.
RawMemory.setActiveForeignSegment('player');
// on the next tick
console.log(RawMemory.foreignSegment);
// --> {"username": "player", "id": 40, "data": "Hello!"}
An object with a memory segment of another player available on this tick. Use setActiveForeignSegment
to fetch segments on the next tick.
The object consists of the following properties:
parameter | type | description |
---|---|---|
username | string | Another player's name. |
id | number | The ID of the requested memory segment. |
data | string | The segment contents. |
This property is deprecated and will be removed soon. Please use InterShardMemory
instead.
RawMemory.interShardSegment = JSON.stringify({
creeps: {
Bob: {role: 'claimer'}
}
});
// on another shard
var interShardData = JSON.parse(RawMemory.interShardSegment);
if(interShardData.creeps[creep.name]) {
creep.memory = interShardData[creep.name];
delete interShardData.creeps[creep.name];
}
RawMemory.interShardSegment = JSON.stringify(interShardData);
A string with a shared memory segment available on every world shard. Maximum string length is 100 KB.
Warning: this segment is not safe for concurrent usage! All shards have shared access to the same instance of data. When the segment contents is changed by two shards simultaneously, you may lose some data, since the segment string value is written all at once atomically. You must implement your own system to determine when each shard is allowed to rewrite the inter-shard memory, e.g. based on mutual exclusions.
const myMemory = JSON.parse(RawMemory.get());
Get a raw string representation of the Memory
object.
Returns a string value.
RawMemory.set(JSON.stringify(myMemory));
Set new Memory
value.
parameter | type | description |
---|---|---|
value | string | New memory value as a string. |
RawMemory.setActiveSegments([0,3]);
Request memory segments using the list of their IDs. Memory segments will become available on the next tick in segments
object.
parameter | type | description |
---|---|---|
ids | array | An array of segment IDs. Each ID should be a number from 0 to 99. Maximum 10 segments can be active at the same time. Subsequent calls of |
RawMemory.setActiveForeignSegment('player');
RawMemory.setActiveForeignSegment('player', 10);
RawMemory.setActiveForeignSegment(null);
Request a memory segment of another user. The segment should be marked by its owner as public using setPublicSegments
.
The segment data will become available on the next tick in foreignSegment
object.
You can only have access to one foreign segment at the same time.
parameter | type | description |
---|---|---|
username | string | null | The name of another user. Pass |
id optional | number | The ID of the requested segment from 0 to 99. If undefined, the user's default public segment is requested as set by |
RawMemory.setPublicSegments([5,20,21]);
RawMemory.setDefaultPublicSegment(5);
RawMemory.setDefaultPublicSegment(null);
Set the specified segment as your default public segment. It will be returned if no id
parameter is passed to setActiveForeignSegment
by another user.
parameter | type | description |
---|---|---|
id | number | null | The ID of the memory segment from 0 to 99. Pass |
RawMemory.setPublicSegments([5,3]);
RawMemory.setPublicSegments([]);
Set specified segments as public. Other users will be able to request access to them using setActiveForeignSegment
.
parameter | type | description |
---|---|---|
ids | array | An array of segment IDs. Each ID should be a number from 0 to 99. Subsequent calls of |
All the following constant names are available in the global scope:
Object.assign(exports, {
OK: 0,
ERR_NOT_OWNER: -1,
ERR_NO_PATH: -2,
ERR_NAME_EXISTS: -3,
ERR_BUSY: -4,
ERR_NOT_FOUND: -5,
ERR_NOT_ENOUGH_ENERGY: -6,
ERR_NOT_ENOUGH_RESOURCES: -6,
ERR_INVALID_TARGET: -7,
ERR_FULL: -8,
ERR_NOT_IN_RANGE: -9,
ERR_INVALID_ARGS: -10,
ERR_TIRED: -11,
ERR_NO_BODYPART: -12,
ERR_NOT_ENOUGH_EXTENSIONS: -6,
ERR_RCL_NOT_ENOUGH: -14,
ERR_GCL_NOT_ENOUGH: -15,
FIND_EXIT_TOP: 1,
FIND_EXIT_RIGHT: 3,
FIND_EXIT_BOTTOM: 5,
FIND_EXIT_LEFT: 7,
FIND_EXIT: 10,
FIND_CREEPS: 101,
FIND_MY_CREEPS: 102,
FIND_HOSTILE_CREEPS: 103,
FIND_SOURCES_ACTIVE: 104,
FIND_SOURCES: 105,
FIND_DROPPED_RESOURCES: 106,
FIND_STRUCTURES: 107,
FIND_MY_STRUCTURES: 108,
FIND_HOSTILE_STRUCTURES: 109,
FIND_FLAGS: 110,
FIND_CONSTRUCTION_SITES: 111,
FIND_MY_SPAWNS: 112,
FIND_HOSTILE_SPAWNS: 113,
FIND_MY_CONSTRUCTION_SITES: 114,
FIND_HOSTILE_CONSTRUCTION_SITES: 115,
FIND_MINERALS: 116,
FIND_NUKES: 117,
FIND_TOMBSTONES: 118,
FIND_POWER_CREEPS: 119,
FIND_MY_POWER_CREEPS: 120,
FIND_HOSTILE_POWER_CREEPS: 121,
FIND_DEPOSITS: 122,
FIND_RUINS: 123,
TOP: 1,
TOP_RIGHT: 2,
RIGHT: 3,
BOTTOM_RIGHT: 4,
BOTTOM: 5,
BOTTOM_LEFT: 6,
LEFT: 7,
TOP_LEFT: 8,
COLOR_RED: 1,
COLOR_PURPLE: 2,
COLOR_BLUE: 3,
COLOR_CYAN: 4,
COLOR_GREEN: 5,
COLOR_YELLOW: 6,
COLOR_ORANGE: 7,
COLOR_BROWN: 8,
COLOR_GREY: 9,
COLOR_WHITE: 10,
LOOK_CREEPS: "creep",
LOOK_ENERGY: "energy",
LOOK_RESOURCES: "resource",
LOOK_SOURCES: "source",
LOOK_MINERALS: "mineral",
LOOK_DEPOSITS: "deposit",
LOOK_STRUCTURES: "structure",
LOOK_FLAGS: "flag",
LOOK_CONSTRUCTION_SITES: "constructionSite",
LOOK_NUKES: "nuke",
LOOK_TERRAIN: "terrain",
LOOK_TOMBSTONES: "tombstone",
LOOK_POWER_CREEPS: "powerCreep",
LOOK_RUINS: "ruin",
OBSTACLE_OBJECT_TYPES: ["spawn", "creep", "powerCreep", "source", "mineral", "deposit", "controller", "constructedWall", "extension", "link", "storage", "tower", "observer", "powerSpawn", "powerBank", "lab", "terminal", "nuker", "factory", "invaderCore"],
MOVE: "move",
WORK: "work",
CARRY: "carry",
ATTACK: "attack",
RANGED_ATTACK: "ranged_attack",
TOUGH: "tough",
HEAL: "heal",
CLAIM: "claim",
BODYPART_COST: {
"move": 50,
"work": 100,
"attack": 80,
"carry": 50,
"heal": 250,
"ranged_attack": 150,
"tough": 10,
"claim": 600
},
// WORLD_WIDTH and WORLD_HEIGHT constants are deprecated, please use Game.map.getWorldSize() instead
WORLD_WIDTH: 202,
WORLD_HEIGHT: 202,
CREEP_LIFE_TIME: 1500,
CREEP_CLAIM_LIFE_TIME: 600,
CREEP_CORPSE_RATE: 0.2,
CREEP_PART_MAX_ENERGY: 125,
CARRY_CAPACITY: 50,
HARVEST_POWER: 2,
HARVEST_MINERAL_POWER: 1,
HARVEST_DEPOSIT_POWER: 1,
REPAIR_POWER: 100,
DISMANTLE_POWER: 50,
BUILD_POWER: 5,
ATTACK_POWER: 30,
UPGRADE_CONTROLLER_POWER: 1,
RANGED_ATTACK_POWER: 10,
HEAL_POWER: 12,
RANGED_HEAL_POWER: 4,
REPAIR_COST: 0.01,
DISMANTLE_COST: 0.005,
RAMPART_DECAY_AMOUNT: 300,
RAMPART_DECAY_TIME: 100,
RAMPART_HITS: 1,
RAMPART_HITS_MAX: {2: 300000, 3: 1000000, 4: 3000000, 5: 10000000, 6: 30000000, 7: 100000000, 8: 300000000},
ENERGY_REGEN_TIME: 300,
ENERGY_DECAY: 1000,
SPAWN_HITS: 5000,
SPAWN_ENERGY_START: 300,
SPAWN_ENERGY_CAPACITY: 300,
CREEP_SPAWN_TIME: 3,
SPAWN_RENEW_RATIO: 1.2,
SOURCE_ENERGY_CAPACITY: 3000,
SOURCE_ENERGY_NEUTRAL_CAPACITY: 1500,
SOURCE_ENERGY_KEEPER_CAPACITY: 4000,
WALL_HITS: 1,
WALL_HITS_MAX: 300000000,
EXTENSION_HITS: 1000,
EXTENSION_ENERGY_CAPACITY: {0: 50, 1: 50, 2: 50, 3: 50, 4: 50, 5: 50, 6: 50, 7: 100, 8: 200},
ROAD_HITS: 5000,
ROAD_WEAROUT: 1,
ROAD_WEAROUT_POWER_CREEP: 100,
ROAD_DECAY_AMOUNT: 100,
ROAD_DECAY_TIME: 1000,
LINK_HITS: 1000,
LINK_HITS_MAX: 1000,
LINK_CAPACITY: 800,
LINK_COOLDOWN: 1,
LINK_LOSS_RATIO: 0.03,
STORAGE_CAPACITY: 1000000,
STORAGE_HITS: 10000,
STRUCTURE_SPAWN: "spawn",
STRUCTURE_EXTENSION: "extension",
STRUCTURE_ROAD: "road",
STRUCTURE_WALL: "constructedWall",
STRUCTURE_RAMPART: "rampart",
STRUCTURE_KEEPER_LAIR: "keeperLair",
STRUCTURE_PORTAL: "portal",
STRUCTURE_CONTROLLER: "controller",
STRUCTURE_LINK: "link",
STRUCTURE_STORAGE: "storage",
STRUCTURE_TOWER: "tower",
STRUCTURE_OBSERVER: "observer",
STRUCTURE_POWER_BANK: "powerBank",
STRUCTURE_POWER_SPAWN: "powerSpawn",
STRUCTURE_EXTRACTOR: "extractor",
STRUCTURE_LAB: "lab",
STRUCTURE_TERMINAL: "terminal",
STRUCTURE_CONTAINER: "container",
STRUCTURE_NUKER: "nuker",
STRUCTURE_FACTORY: "factory",
STRUCTURE_INVADER_CORE: "invaderCore",
CONSTRUCTION_COST: {
"spawn": 15000,
"extension": 3000,
"road": 300,
"constructedWall": 1,
"rampart": 1,
"link": 5000,
"storage": 30000,
"tower": 5000,
"observer": 8000,
"powerSpawn": 100000,
"extractor": 5000,
"lab": 50000,
"terminal": 100000,
"container": 5000,
"nuker": 100000,
"factory": 100000
},
CONSTRUCTION_COST_ROAD_SWAMP_RATIO: 5,
CONSTRUCTION_COST_ROAD_WALL_RATIO: 150,
CONTROLLER_LEVELS: {1: 200, 2: 45000, 3: 135000, 4: 405000, 5: 1215000, 6: 3645000, 7: 10935000},
CONTROLLER_STRUCTURES: {
"spawn": {0: 0, 1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1, 7: 2, 8: 3},
"extension": {0: 0, 1: 0, 2: 5, 3: 10, 4: 20, 5: 30, 6: 40, 7: 50, 8: 60},
"link": {1: 0, 2: 0, 3: 0, 4: 0, 5: 2, 6: 3, 7: 4, 8: 6},
"road": {0: 2500, 1: 2500, 2: 2500, 3: 2500, 4: 2500, 5: 2500, 6: 2500, 7: 2500, 8: 2500},
"constructedWall": {1: 0, 2: 2500, 3: 2500, 4: 2500, 5: 2500, 6: 2500, 7: 2500, 8: 2500},
"rampart": {1: 0, 2: 2500, 3: 2500, 4: 2500, 5: 2500, 6: 2500, 7: 2500, 8: 2500},
"storage": {1: 0, 2: 0, 3: 0, 4: 1, 5: 1, 6: 1, 7: 1, 8: 1},
"tower": {1: 0, 2: 0, 3: 1, 4: 1, 5: 2, 6: 2, 7: 3, 8: 6},
"observer": {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 1},
"powerSpawn": {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 1},
"extractor": {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 1, 7: 1, 8: 1},
"terminal": {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 1, 7: 1, 8: 1},
"lab": {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 3, 7: 6, 8: 10},
"container": {0: 5, 1: 5, 2: 5, 3: 5, 4: 5, 5: 5, 6: 5, 7: 5, 8: 5},
"nuker": {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 1},
"factory": {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 1, 8: 1}
},
CONTROLLER_DOWNGRADE: {1: 20000, 2: 10000, 3: 20000, 4: 40000, 5: 80000, 6: 120000, 7: 150000, 8: 200000},
CONTROLLER_DOWNGRADE_RESTORE: 100,
CONTROLLER_DOWNGRADE_SAFEMODE_THRESHOLD: 5000,
CONTROLLER_CLAIM_DOWNGRADE: 300,
CONTROLLER_RESERVE: 1,
CONTROLLER_RESERVE_MAX: 5000,
CONTROLLER_MAX_UPGRADE_PER_TICK: 15,
CONTROLLER_ATTACK_BLOCKED_UPGRADE: 1000,
CONTROLLER_NUKE_BLOCKED_UPGRADE: 200,
SAFE_MODE_DURATION: 20000,
SAFE_MODE_COOLDOWN: 50000,
SAFE_MODE_COST: 1000,
TOWER_HITS: 3000,
TOWER_CAPACITY: 1000,
TOWER_ENERGY_COST: 10,
TOWER_POWER_ATTACK: 600,
TOWER_POWER_HEAL: 400,
TOWER_POWER_REPAIR: 800,
TOWER_OPTIMAL_RANGE: 5,
TOWER_FALLOFF_RANGE: 20,
TOWER_FALLOFF: 0.75,
OBSERVER_HITS: 500,
OBSERVER_RANGE: 10,
POWER_BANK_HITS: 2000000,
POWER_BANK_CAPACITY_MAX: 5000,
POWER_BANK_CAPACITY_MIN: 500,
POWER_BANK_CAPACITY_CRIT: 0.3,
POWER_BANK_DECAY: 5000,
POWER_BANK_HIT_BACK: 0.5,
POWER_SPAWN_HITS: 5000,
POWER_SPAWN_ENERGY_CAPACITY: 5000,
POWER_SPAWN_POWER_CAPACITY: 100,
POWER_SPAWN_ENERGY_RATIO: 50,
EXTRACTOR_HITS: 500,
EXTRACTOR_COOLDOWN: 5,
LAB_HITS: 500,
LAB_MINERAL_CAPACITY: 3000,
LAB_ENERGY_CAPACITY: 2000,
LAB_BOOST_ENERGY: 20,
LAB_BOOST_MINERAL: 30,
LAB_COOLDOWN: 10, // not used
LAB_REACTION_AMOUNT: 5,
LAB_UNBOOST_ENERGY: 0,
LAB_UNBOOST_MINERAL: 15,
GCL_POW: 2.4,
GCL_MULTIPLY: 1000000,
GCL_NOVICE: 3,
MODE_SIMULATION: null,
MODE_WORLD: null,
TERRAIN_MASK_WALL: 1,
TERRAIN_MASK_SWAMP: 2,
TERRAIN_MASK_LAVA: 4,
MAX_CONSTRUCTION_SITES: 100,
MAX_CREEP_SIZE: 50,
MINERAL_REGEN_TIME: 50000,
MINERAL_MIN_AMOUNT: {
"H": 35000,
"O": 35000,
"L": 35000,
"K": 35000,
"Z": 35000,
"U": 35000,
"X": 35000
},
MINERAL_RANDOM_FACTOR: 2,
MINERAL_DENSITY: {
1: 15000,
2: 35000,
3: 70000,
4: 100000
},
MINERAL_DENSITY_PROBABILITY : {
1: 0.1,
2: 0.5,
3: 0.9,
4: 1.0
},
MINERAL_DENSITY_CHANGE: 0.05,
DENSITY_LOW: 1,
DENSITY_MODERATE: 2,
DENSITY_HIGH: 3,
DENSITY_ULTRA: 4,
DEPOSIT_EXHAUST_MULTIPLY: 0.001,
DEPOSIT_EXHAUST_POW: 1.2,
DEPOSIT_DECAY_TIME: 50000,
TERMINAL_CAPACITY: 300000,
TERMINAL_HITS: 3000,
TERMINAL_SEND_COST: 0.1,
TERMINAL_MIN_SEND: 100,
TERMINAL_COOLDOWN: 10,
CONTAINER_HITS: 250000,
CONTAINER_CAPACITY: 2000,
CONTAINER_DECAY: 5000,
CONTAINER_DECAY_TIME: 100,
CONTAINER_DECAY_TIME_OWNED: 500,
NUKER_HITS: 1000,
NUKER_COOLDOWN: 100000,
NUKER_ENERGY_CAPACITY: 300000,
NUKER_GHODIUM_CAPACITY: 5000,
NUKE_LAND_TIME: 50000,
NUKE_RANGE: 10,
NUKE_DAMAGE: {
0: 10000000,
2: 5000000
},
FACTORY_HITS: 1000,
FACTORY_CAPACITY: 50000,
TOMBSTONE_DECAY_PER_PART: 5,
TOMBSTONE_DECAY_POWER_CREEP: 500,
RUIN_DECAY: 500,
RUIN_DECAY_STRUCTURES: {
'powerBank': 10
},
PORTAL_DECAY: 30000,
ORDER_SELL: "sell",
ORDER_BUY: "buy",
MARKET_FEE: 0.05,
MARKET_MAX_ORDERS: 300,
MARKET_ORDER_LIFE_TIME: 1000*60*60*24*30,
FLAGS_LIMIT: 10000,
SUBSCRIPTION_TOKEN: "token",
CPU_UNLOCK: "cpuUnlock",
PIXEL: "pixel",
ACCESS_KEY: "accessKey",
PIXEL_CPU_COST: 10000,
RESOURCE_ENERGY: "energy",
RESOURCE_POWER: "power",
RESOURCE_HYDROGEN: "H",
RESOURCE_OXYGEN: "O",
RESOURCE_UTRIUM: "U",
RESOURCE_LEMERGIUM: "L",
RESOURCE_KEANIUM: "K",
RESOURCE_ZYNTHIUM: "Z",
RESOURCE_CATALYST: "X",
RESOURCE_GHODIUM: "G",
RESOURCE_SILICON: 'silicon',
RESOURCE_METAL: 'metal',
RESOURCE_BIOMASS: 'biomass',
RESOURCE_MIST: 'mist',
RESOURCE_HYDROXIDE: "OH",
RESOURCE_ZYNTHIUM_KEANITE: "ZK",
RESOURCE_UTRIUM_LEMERGITE: "UL",
RESOURCE_UTRIUM_HYDRIDE: "UH",
RESOURCE_UTRIUM_OXIDE: "UO",
RESOURCE_KEANIUM_HYDRIDE: "KH",
RESOURCE_KEANIUM_OXIDE: "KO",
RESOURCE_LEMERGIUM_HYDRIDE: "LH",
RESOURCE_LEMERGIUM_OXIDE: "LO",
RESOURCE_ZYNTHIUM_HYDRIDE: "ZH",
RESOURCE_ZYNTHIUM_OXIDE: "ZO",
RESOURCE_GHODIUM_HYDRIDE: "GH",
RESOURCE_GHODIUM_OXIDE: "GO",
RESOURCE_UTRIUM_ACID: "UH2O",
RESOURCE_UTRIUM_ALKALIDE: "UHO2",
RESOURCE_KEANIUM_ACID: "KH2O",
RESOURCE_KEANIUM_ALKALIDE: "KHO2",
RESOURCE_LEMERGIUM_ACID: "LH2O",
RESOURCE_LEMERGIUM_ALKALIDE: "LHO2",
RESOURCE_ZYNTHIUM_ACID: "ZH2O",
RESOURCE_ZYNTHIUM_ALKALIDE: "ZHO2",
RESOURCE_GHODIUM_ACID: "GH2O",
RESOURCE_GHODIUM_ALKALIDE: "GHO2",
RESOURCE_CATALYZED_UTRIUM_ACID: "XUH2O",
RESOURCE_CATALYZED_UTRIUM_ALKALIDE: "XUHO2",
RESOURCE_CATALYZED_KEANIUM_ACID: "XKH2O",
RESOURCE_CATALYZED_KEANIUM_ALKALIDE: "XKHO2",
RESOURCE_CATALYZED_LEMERGIUM_ACID: "XLH2O",
RESOURCE_CATALYZED_LEMERGIUM_ALKALIDE: "XLHO2",
RESOURCE_CATALYZED_ZYNTHIUM_ACID: "XZH2O",
RESOURCE_CATALYZED_ZYNTHIUM_ALKALIDE: "XZHO2",
RESOURCE_CATALYZED_GHODIUM_ACID: "XGH2O",
RESOURCE_CATALYZED_GHODIUM_ALKALIDE: "XGHO2",
RESOURCE_OPS: "ops",
RESOURCE_UTRIUM_BAR: 'utrium_bar',
RESOURCE_LEMERGIUM_BAR: 'lemergium_bar',
RESOURCE_ZYNTHIUM_BAR: 'zynthium_bar',
RESOURCE_KEANIUM_BAR: 'keanium_bar',
RESOURCE_GHODIUM_MELT: 'ghodium_melt',
RESOURCE_OXIDANT: 'oxidant',
RESOURCE_REDUCTANT: 'reductant',
RESOURCE_PURIFIER: 'purifier',
RESOURCE_BATTERY: 'battery',
RESOURCE_COMPOSITE: 'composite',
RESOURCE_CRYSTAL: 'crystal',
RESOURCE_LIQUID: 'liquid',
RESOURCE_WIRE: 'wire',
RESOURCE_SWITCH: 'switch',
RESOURCE_TRANSISTOR: 'transistor',
RESOURCE_MICROCHIP: 'microchip',
RESOURCE_CIRCUIT: 'circuit',
RESOURCE_DEVICE: 'device',
RESOURCE_CELL: 'cell',
RESOURCE_PHLEGM: 'phlegm',
RESOURCE_TISSUE: 'tissue',
RESOURCE_MUSCLE: 'muscle',
RESOURCE_ORGANOID: 'organoid',
RESOURCE_ORGANISM: 'organism',
RESOURCE_ALLOY: 'alloy',
RESOURCE_TUBE: 'tube',
RESOURCE_FIXTURES: 'fixtures',
RESOURCE_FRAME: 'frame',
RESOURCE_HYDRAULICS: 'hydraulics',
RESOURCE_MACHINE: 'machine',
RESOURCE_CONDENSATE: 'condensate',
RESOURCE_CONCENTRATE: 'concentrate',
RESOURCE_EXTRACT: 'extract',
RESOURCE_SPIRIT: 'spirit',
RESOURCE_EMANATION: 'emanation',
RESOURCE_ESSENCE: 'essence',
REACTIONS: {
H: {
O: "OH",
L: "LH",
K: "KH",
U: "UH",
Z: "ZH",
G: "GH"
},
O: {
H: "OH",
L: "LO",
K: "KO",
U: "UO",
Z: "ZO",
G: "GO"
},
Z: {
K: "ZK",
H: "ZH",
O: "ZO"
},
L: {
U: "UL",
H: "LH",
O: "LO"
},
K: {
Z: "ZK",
H: "KH",
O: "KO"
},
G: {
H: "GH",
O: "GO"
},
U: {
L: "UL",
H: "UH",
O: "UO"
},
OH: {
UH: "UH2O",
UO: "UHO2",
ZH: "ZH2O",
ZO: "ZHO2",
KH: "KH2O",
KO: "KHO2",
LH: "LH2O",
LO: "LHO2",
GH: "GH2O",
GO: "GHO2"
},
X: {
UH2O: "XUH2O",
UHO2: "XUHO2",
LH2O: "XLH2O",
LHO2: "XLHO2",
KH2O: "XKH2O",
KHO2: "XKHO2",
ZH2O: "XZH2O",
ZHO2: "XZHO2",
GH2O: "XGH2O",
GHO2: "XGHO2"
},
ZK: {
UL: "G"
},
UL: {
ZK: "G"
},
LH: {
OH: "LH2O"
},
ZH: {
OH: "ZH2O"
},
GH: {
OH: "GH2O"
},
KH: {
OH: "KH2O"
},
UH: {
OH: "UH2O"
},
LO: {
OH: "LHO2"
},
ZO: {
OH: "ZHO2"
},
KO: {
OH: "KHO2"
},
UO: {
OH: "UHO2"
},
GO: {
OH: "GHO2"
},
LH2O: {
X: "XLH2O"
},
KH2O: {
X: "XKH2O"
},
ZH2O: {
X: "XZH2O"
},
UH2O: {
X: "XUH2O"
},
GH2O: {
X: "XGH2O"
},
LHO2: {
X: "XLHO2"
},
UHO2: {
X: "XUHO2"
},
KHO2: {
X: "XKHO2"
},
ZHO2: {
X: "XZHO2"
},
GHO2: {
X: "XGHO2"
}
},
BOOSTS: {
work: {
UO: {
harvest: 3
},
UHO2: {
harvest: 5
},
XUHO2: {
harvest: 7
},
LH: {
build: 1.5,
repair: 1.5
},
LH2O: {
build: 1.8,
repair: 1.8
},
XLH2O: {
build: 2,
repair: 2
},
ZH: {
dismantle: 2
},
ZH2O: {
dismantle: 3
},
XZH2O: {
dismantle: 4
},
GH: {
upgradeController: 1.5
},
GH2O: {
upgradeController: 1.8
},
XGH2O: {
upgradeController: 2
}
},
attack: {
UH: {
attack: 2
},
UH2O: {
attack: 3
},
XUH2O: {
attack: 4
}
},
ranged_attack: {
KO: {
rangedAttack: 2,
rangedMassAttack: 2
},
KHO2: {
rangedAttack: 3,
rangedMassAttack: 3
},
XKHO2: {
rangedAttack: 4,
rangedMassAttack: 4
}
},
heal: {
LO: {
heal: 2,
rangedHeal: 2
},
LHO2: {
heal: 3,
rangedHeal: 3
},
XLHO2: {
heal: 4,
rangedHeal: 4
}
},
carry: {
KH: {
capacity: 2
},
KH2O: {
capacity: 3
},
XKH2O: {
capacity: 4
}
},
move: {
ZO: {
fatigue: 2
},
ZHO2: {
fatigue: 3
},
XZHO2: {
fatigue: 4
}
},
tough: {
GO: {
damage: .7
},
GHO2: {
damage: .5
},
XGHO2: {
damage: .3
}
}
},
REACTION_TIME: {
OH: 20,
ZK: 5,
UL: 5,
G: 5,
UH: 10,
UH2O: 5,
XUH2O: 60,
UO: 10,
UHO2: 5,
XUHO2: 60,
KH: 10,
KH2O: 5,
XKH2O: 60,
KO: 10,
KHO2: 5,
XKHO2: 60,
LH: 15,
LH2O: 10,
XLH2O: 65,
LO: 10,
LHO2: 5,
XLHO2: 60,
ZH: 20,
ZH2O: 40,
XZH2O: 160,
ZO: 10,
ZHO2: 5,
XZHO2: 60,
GH: 10,
GH2O: 15,
XGH2O: 80,
GO: 10,
GHO2: 30,
XGHO2: 150,
},
PORTAL_UNSTABLE: 10*24*3600*1000,
PORTAL_MIN_TIMEOUT: 12*24*3600*1000,
PORTAL_MAX_TIMEOUT: 22*24*3600*1000,
POWER_BANK_RESPAWN_TIME: 50000,
INVADERS_ENERGY_GOAL: 100000,
SYSTEM_USERNAME: 'Screeps',
// SIGN_NOVICE_AREA and SIGN_RESPAWN_AREA constants are deprecated, please use SIGN_PLANNED_AREA instead
SIGN_NOVICE_AREA: 'A new Novice or Respawn Area is being planned somewhere in this sector. Please make sure all important rooms are reserved.',
SIGN_RESPAWN_AREA: 'A new Novice or Respawn Area is being planned somewhere in this sector. Please make sure all important rooms are reserved.',
SIGN_PLANNED_AREA: 'A new Novice or Respawn Area is being planned somewhere in this sector. Please make sure all important rooms are reserved.',
EVENT_ATTACK: 1,
EVENT_OBJECT_DESTROYED: 2,
EVENT_ATTACK_CONTROLLER: 3,
EVENT_BUILD: 4,
EVENT_HARVEST: 5,
EVENT_HEAL: 6,
EVENT_REPAIR: 7,
EVENT_RESERVE_CONTROLLER: 8,
EVENT_UPGRADE_CONTROLLER: 9,
EVENT_EXIT: 10,
EVENT_POWER: 11,
EVENT_TRANSFER: 12,
EVENT_ATTACK_TYPE_MELEE: 1,
EVENT_ATTACK_TYPE_RANGED: 2,
EVENT_ATTACK_TYPE_RANGED_MASS: 3,
EVENT_ATTACK_TYPE_DISMANTLE: 4,
EVENT_ATTACK_TYPE_HIT_BACK: 5,
EVENT_ATTACK_TYPE_NUKE: 6,
EVENT_HEAL_TYPE_MELEE: 1,
EVENT_HEAL_TYPE_RANGED: 2,
POWER_LEVEL_MULTIPLY: 1000,
POWER_LEVEL_POW: 2,
POWER_CREEP_SPAWN_COOLDOWN: 8*3600*1000,
POWER_CREEP_DELETE_COOLDOWN: 24*3600*1000,
POWER_CREEP_MAX_LEVEL: 25,
POWER_CREEP_LIFE_TIME: 5000,
POWER_CLASS: {
OPERATOR: 'operator'
},
PWR_GENERATE_OPS: 1,
PWR_OPERATE_SPAWN: 2,
PWR_OPERATE_TOWER: 3,
PWR_OPERATE_STORAGE: 4,
PWR_OPERATE_LAB: 5,
PWR_OPERATE_EXTENSION: 6,
PWR_OPERATE_OBSERVER: 7,
PWR_OPERATE_TERMINAL: 8,
PWR_DISRUPT_SPAWN: 9,
PWR_DISRUPT_TOWER: 10,
PWR_DISRUPT_SOURCE: 11,
PWR_SHIELD: 12,
PWR_REGEN_SOURCE: 13,
PWR_REGEN_MINERAL: 14,
PWR_DISRUPT_TERMINAL: 15,
PWR_OPERATE_POWER: 16,
PWR_FORTIFY: 17,
PWR_OPERATE_CONTROLLER: 18,
PWR_OPERATE_FACTORY: 19,
EFFECT_INVULNERABILITY: 1001,
EFFECT_COLLAPSE_TIMER: 1002,
INVADER_CORE_HITS: 100000,
INVADER_CORE_CREEP_SPAWN_TIME: {
0: 0, 1: 0, 2: 6, 3: 3, 4: 2, 5: 1
},
INVADER_CORE_EXPAND_TIME: { 1: 4000, 2: 3500, 3: 3000, 4: 2500, 5: 2000 },
INVADER_CORE_CONTROLLER_POWER: 2,
INVADER_CORE_CONTROLLER_DOWNGRADE: 5000,
STRONGHOLD_RAMPART_HITS: { 0: 0, 1: 100000, 2: 200000, 3: 500000, 4: 1000000, 5: 2000000 },
STRONGHOLD_DECAY_TICKS: 75000
});
Object.assign(exports, {
POWER_INFO: {
[exports.PWR_GENERATE_OPS]: {
className: exports.POWER_CLASS.OPERATOR,
level: [0, 2, 7, 14, 22],
cooldown: 50,
effect: [1, 2, 4, 6, 8]
},
[exports.PWR_OPERATE_SPAWN]: {
className: exports.POWER_CLASS.OPERATOR,
level: [0, 2, 7, 14, 22],
cooldown: 300,
duration: 1000,
range: 3,
ops: 100,
effect: [0.9, 0.7, 0.5, 0.35, 0.2]
},
[exports.PWR_OPERATE_TOWER]: {
className: exports.POWER_CLASS.OPERATOR,
level: [0, 2, 7, 14, 22],
cooldown: 10,
duration: 100,
range: 3,
ops: 10,
effect: [1.1, 1.2, 1.3, 1.4, 1.5]
},
[exports.PWR_OPERATE_STORAGE]: {
className: exports.POWER_CLASS.OPERATOR,
level: [0, 2, 7, 14, 22],
cooldown: 800,
duration: 1000,
range: 3,
ops: 100,
effect: [500000,1000000,2000000,4000000,7000000]
},
[exports.PWR_OPERATE_LAB]: {
className: exports.POWER_CLASS.OPERATOR,
level: [0, 2, 7, 14, 22],
cooldown: 50,
duration: 1000,
range: 3,
ops: 10,
effect: [2,4,6,8,10]
},
[exports.PWR_OPERATE_EXTENSION]: {
className: exports.POWER_CLASS.OPERATOR,
level: [0, 2, 7, 14, 22],
cooldown: 50,
range: 3,
ops: 2,
effect: [0.2, 0.4, 0.6, 0.8, 1.0]
},
[exports.PWR_OPERATE_OBSERVER]: {
className: exports.POWER_CLASS.OPERATOR,
level: [0, 2, 7, 14, 22],
cooldown: 400,
duration: [200,400,600,800,1000],
range: 3,
ops: 10,
},
[exports.PWR_OPERATE_TERMINAL]: {
className: exports.POWER_CLASS.OPERATOR,
level: [0, 2, 7, 14, 22],
cooldown: 500,
duration: 1000,
range: 3,
ops: 100,
effect: [0.9, 0.8, 0.7, 0.6, 0.5]
},
[exports.PWR_DISRUPT_SPAWN]: {
className: exports.POWER_CLASS.OPERATOR,
level: [0, 2, 7, 14, 22],
cooldown: 5,
range: 20,
ops: 10,
duration: [1,2,3,4,5]
},
[exports.PWR_DISRUPT_TOWER]: {
className: exports.POWER_CLASS.OPERATOR,
level: [0, 2, 7, 14, 22],
cooldown: 0,
duration: 5,
range: 50,
ops: 10,
effect: [0.9, 0.8, 0.7, 0.6, 0.5],
},
[exports.PWR_DISRUPT_SOURCE]: {
className: exports.POWER_CLASS.OPERATOR,
level: [0, 2, 7, 14, 22],
cooldown: 100,
range: 3,
ops: 100,
duration: [100, 200, 300, 400, 500]
},
[exports.PWR_SHIELD]: {
className: exports.POWER_CLASS.OPERATOR,
level: [0, 2, 7, 14, 22],
effect: [5000, 10000, 15000, 20000, 25000],
duration: 50,
cooldown: 20,
energy: 100,
},
[exports.PWR_REGEN_SOURCE]: {
className: exports.POWER_CLASS.OPERATOR,
level: [10, 11, 12, 14, 22],
cooldown: 100,
duration: 300,
range: 3,
effect: [50,100,150,200,250],
period: 15
},
[exports.PWR_REGEN_MINERAL]: {
className: exports.POWER_CLASS.OPERATOR,
level: [10, 11, 12, 14, 22],
cooldown: 100,
duration: 100,
range: 3,
effect: [2,4,6,8,10],
period: 10
},
[exports.PWR_DISRUPT_TERMINAL]: {
className: exports.POWER_CLASS.OPERATOR,
level: [20, 21, 22, 23, 24],
cooldown: 8,
duration: 10,
range: 50,
ops: [50,40,30,20,10]
},
[exports.PWR_FORTIFY]: {
className: exports.POWER_CLASS.OPERATOR,
level: [0, 2, 7, 14, 22],
cooldown: 5,
range: 3,
ops: 5,
duration: [1, 2, 3, 4, 5]
},
[exports.PWR_OPERATE_POWER]: {
className: exports.POWER_CLASS.OPERATOR,
level: [10, 11, 12, 14, 22],
cooldown: 800,
range: 3,
duration: 1000,
ops: 200,
effect: [1, 2, 3, 4, 5]
},
[exports.PWR_OPERATE_CONTROLLER]: {
className: exports.POWER_CLASS.OPERATOR,
level: [20, 21, 22, 23, 24],
cooldown: 800,
range: 3,
duration: 1000,
ops: 200,
effect: [10, 20, 30, 40, 50]
},
[exports.PWR_OPERATE_FACTORY]: {
className: exports.POWER_CLASS.OPERATOR,
level: [0, 2, 7, 14, 22],
cooldown: 800,
range: 3,
duration: 1000,
ops: 100
},
},
BODYPARTS_ALL: [
exports.MOVE,
exports.WORK,
exports.CARRY,
exports.ATTACK,
exports.RANGED_ATTACK,
exports.TOUGH,
exports.HEAL,
exports.CLAIM
],
RESOURCES_ALL: [
exports.RESOURCE_ENERGY,
exports.RESOURCE_POWER,
exports.RESOURCE_HYDROGEN,
exports.RESOURCE_OXYGEN,
exports.RESOURCE_UTRIUM,
exports.RESOURCE_KEANIUM,
exports.RESOURCE_LEMERGIUM,
exports.RESOURCE_ZYNTHIUM,
exports.RESOURCE_CATALYST,
exports.RESOURCE_GHODIUM,
exports.RESOURCE_HYDROXIDE,
exports.RESOURCE_ZYNTHIUM_KEANITE,
exports.RESOURCE_UTRIUM_LEMERGITE,
exports.RESOURCE_UTRIUM_HYDRIDE,
exports.RESOURCE_UTRIUM_OXIDE,
exports.RESOURCE_KEANIUM_HYDRIDE,
exports.RESOURCE_KEANIUM_OXIDE,
exports.RESOURCE_LEMERGIUM_HYDRIDE,
exports.RESOURCE_LEMERGIUM_OXIDE,
exports.RESOURCE_ZYNTHIUM_HYDRIDE,
exports.RESOURCE_ZYNTHIUM_OXIDE,
exports.RESOURCE_GHODIUM_HYDRIDE,
exports.RESOURCE_GHODIUM_OXIDE,
exports.RESOURCE_UTRIUM_ACID,
exports.RESOURCE_UTRIUM_ALKALIDE,
exports.RESOURCE_KEANIUM_ACID,
exports.RESOURCE_KEANIUM_ALKALIDE,
exports.RESOURCE_LEMERGIUM_ACID,
exports.RESOURCE_LEMERGIUM_ALKALIDE,
exports.RESOURCE_ZYNTHIUM_ACID,
exports.RESOURCE_ZYNTHIUM_ALKALIDE,
exports.RESOURCE_GHODIUM_ACID,
exports.RESOURCE_GHODIUM_ALKALIDE,
exports.RESOURCE_CATALYZED_UTRIUM_ACID,
exports.RESOURCE_CATALYZED_UTRIUM_ALKALIDE,
exports.RESOURCE_CATALYZED_KEANIUM_ACID,
exports.RESOURCE_CATALYZED_KEANIUM_ALKALIDE,
exports.RESOURCE_CATALYZED_LEMERGIUM_ACID,
exports.RESOURCE_CATALYZED_LEMERGIUM_ALKALIDE,
exports.RESOURCE_CATALYZED_ZYNTHIUM_ACID,
exports.RESOURCE_CATALYZED_ZYNTHIUM_ALKALIDE,
exports.RESOURCE_CATALYZED_GHODIUM_ACID,
exports.RESOURCE_CATALYZED_GHODIUM_ALKALIDE,
exports.RESOURCE_OPS,
exports.RESOURCE_SILICON,
exports.RESOURCE_METAL,
exports.RESOURCE_BIOMASS,
exports.RESOURCE_MIST,
exports.RESOURCE_UTRIUM_BAR,
exports.RESOURCE_LEMERGIUM_BAR,
exports.RESOURCE_ZYNTHIUM_BAR,
exports.RESOURCE_KEANIUM_BAR,
exports.RESOURCE_GHODIUM_MELT,
exports.RESOURCE_OXIDANT,
exports.RESOURCE_REDUCTANT,
exports.RESOURCE_PURIFIER,
exports.RESOURCE_BATTERY,
exports.RESOURCE_COMPOSITE,
exports.RESOURCE_CRYSTAL,
exports.RESOURCE_LIQUID,
exports.RESOURCE_WIRE,
exports.RESOURCE_SWITCH,
exports.RESOURCE_TRANSISTOR,
exports.RESOURCE_MICROCHIP,
exports.RESOURCE_CIRCUIT,
exports.RESOURCE_DEVICE,
exports.RESOURCE_CELL,
exports.RESOURCE_PHLEGM,
exports.RESOURCE_TISSUE,
exports.RESOURCE_MUSCLE,
exports.RESOURCE_ORGANOID,
exports.RESOURCE_ORGANISM,
exports.RESOURCE_ALLOY,
exports.RESOURCE_TUBE,
exports.RESOURCE_FIXTURES,
exports.RESOURCE_FRAME,
exports.RESOURCE_HYDRAULICS,
exports.RESOURCE_MACHINE,
exports.RESOURCE_CONDENSATE,
exports.RESOURCE_CONCENTRATE,
exports.RESOURCE_EXTRACT,
exports.RESOURCE_SPIRIT,
exports.RESOURCE_EMANATION,
exports.RESOURCE_ESSENCE
],
COLORS_ALL: [
exports.COLOR_RED,
exports.COLOR_PURPLE,
exports.COLOR_BLUE,
exports.COLOR_CYAN,
exports.COLOR_GREEN,
exports.COLOR_YELLOW,
exports.COLOR_ORANGE,
exports.COLOR_BROWN,
exports.COLOR_GREY,
exports.COLOR_WHITE
],
INTERSHARD_RESOURCES: [
exports.SUBSCRIPTION_TOKEN,
exports.CPU_UNLOCK,
exports.PIXEL,
exports.ACCESS_KEY
],
COMMODITIES: {
[exports.RESOURCE_UTRIUM_BAR]: {
amount: 100,
cooldown: 20,
components: {
[exports.RESOURCE_UTRIUM]: 500,
[exports.RESOURCE_ENERGY]: 200
}
},
[exports.RESOURCE_UTRIUM]: {
amount: 500,
cooldown: 20,
components: {
[exports.RESOURCE_UTRIUM_BAR]: 100,
[exports.RESOURCE_ENERGY]: 200
}
},
[exports.RESOURCE_LEMERGIUM_BAR]: {
amount: 100,
cooldown: 20,
components: {
[exports.RESOURCE_LEMERGIUM]: 500,
[exports.RESOURCE_ENERGY]: 200
}
},
[exports.RESOURCE_LEMERGIUM]: {
amount: 500,
cooldown: 20,
components: {
[exports.RESOURCE_LEMERGIUM_BAR]: 100,
[exports.RESOURCE_ENERGY]: 200
}
},
[exports.RESOURCE_ZYNTHIUM_BAR]: {
amount: 100,
cooldown: 20,
components: {
[exports.RESOURCE_ZYNTHIUM]: 500,
[exports.RESOURCE_ENERGY]: 200
}
},
[exports.RESOURCE_ZYNTHIUM]: {
amount: 500,
cooldown: 20,
components: {
[exports.RESOURCE_ZYNTHIUM_BAR]: 100,
[exports.RESOURCE_ENERGY]: 200
}
},
[exports.RESOURCE_KEANIUM_BAR]: {
amount: 100,
cooldown: 20,
components: {
[exports.RESOURCE_KEANIUM]: 500,
[exports.RESOURCE_ENERGY]: 200
}
},
[exports.RESOURCE_KEANIUM]: {
amount: 500,
cooldown: 20,
components: {
[exports.RESOURCE_KEANIUM_BAR]: 100,
[exports.RESOURCE_ENERGY]: 200
}
},
[exports.RESOURCE_GHODIUM_MELT]: {
amount: 100,
cooldown: 20,
components: {
[exports.RESOURCE_GHODIUM]: 500,
[exports.RESOURCE_ENERGY]: 200
}
},
[exports.RESOURCE_GHODIUM]: {
amount: 500,
cooldown: 20,
components: {
[exports.RESOURCE_GHODIUM_MELT]: 100,
[exports.RESOURCE_ENERGY]: 200
}
},
[exports.RESOURCE_OXIDANT]: {
amount: 100,
cooldown: 20,
components: {
[exports.RESOURCE_OXYGEN]: 500,
[exports.RESOURCE_ENERGY]: 200
}
},
[exports.RESOURCE_OXYGEN]: {
amount: 500,
cooldown: 20,
components: {
[exports.RESOURCE_OXIDANT]: 100,
[exports.RESOURCE_ENERGY]: 200
}
},
[exports.RESOURCE_REDUCTANT]: {
amount: 100,
cooldown: 20,
components: {
[exports.RESOURCE_HYDROGEN]: 500,
[exports.RESOURCE_ENERGY]: 200
}
},
[exports.RESOURCE_HYDROGEN]: {
amount: 500,
cooldown: 20,
components: {
[exports.RESOURCE_REDUCTANT]: 100,
[exports.RESOURCE_ENERGY]: 200
}
},
[exports.RESOURCE_PURIFIER]: {
amount: 100,
cooldown: 20,
components: {
[exports.RESOURCE_CATALYST]: 500,
[exports.RESOURCE_ENERGY]: 200
}
},
[exports.RESOURCE_CATALYST]: {
amount: 500,
cooldown: 20,
components: {
[exports.RESOURCE_PURIFIER]: 100,
[exports.RESOURCE_ENERGY]: 200
}
},
[exports.RESOURCE_BATTERY]: {
amount: 50,
cooldown: 10,
components: {
[exports.RESOURCE_ENERGY]: 600
}
},
[exports.RESOURCE_ENERGY]: {
amount: 500,
cooldown: 10,
components: {
[exports.RESOURCE_BATTERY]: 50
}
},
[exports.RESOURCE_COMPOSITE]: {
level: 1,
amount: 20,
cooldown: 50,
components: {
[exports.RESOURCE_UTRIUM_BAR]: 20,
[exports.RESOURCE_ZYNTHIUM_BAR]: 20,
[exports.RESOURCE_ENERGY]: 20
}
},
[exports.RESOURCE_CRYSTAL]: {
level: 2,
amount: 6,
cooldown: 21,
components: {
[exports.RESOURCE_LEMERGIUM_BAR]: 6,
[exports.RESOURCE_KEANIUM_BAR]: 6,
[exports.RESOURCE_PURIFIER]: 6,
[exports.RESOURCE_ENERGY]: 45
}
},
[exports.RESOURCE_LIQUID]: {
level: 3,
amount: 12,
cooldown: 60,
components: {
[exports.RESOURCE_OXIDANT]: 12,
[exports.RESOURCE_REDUCTANT]: 12,
[exports.RESOURCE_GHODIUM_MELT]: 12,
[exports.RESOURCE_ENERGY]: 90
}
},
[exports.RESOURCE_WIRE]: {
amount: 20,
cooldown: 8,
components: {
[exports.RESOURCE_UTRIUM_BAR]: 20,
[exports.RESOURCE_SILICON]: 100,
[exports.RESOURCE_ENERGY]: 40
}
},
[exports.RESOURCE_SWITCH]: {
level: 1,
amount: 5,
cooldown: 70,
components: {
[exports.RESOURCE_WIRE]: 40,
[exports.RESOURCE_OXIDANT]: 95,
[exports.RESOURCE_UTRIUM_BAR]: 35,
[exports.RESOURCE_ENERGY]: 20
}
},
[exports.RESOURCE_TRANSISTOR]: {
level: 2,
amount: 1,
cooldown: 59,
components: {
[exports.RESOURCE_SWITCH]: 4,
[exports.RESOURCE_WIRE]: 15,
[exports.RESOURCE_REDUCTANT]: 85,
[exports.RESOURCE_ENERGY]: 8
}
},
[exports.RESOURCE_MICROCHIP]: {
level: 3,
amount: 1,
cooldown: 250,
components: {
[exports.RESOURCE_TRANSISTOR]: 2,
[exports.RESOURCE_COMPOSITE]: 50,
[exports.RESOURCE_WIRE]: 117,
[exports.RESOURCE_PURIFIER]: 25,
[exports.RESOURCE_ENERGY]: 16
}
},
[exports.RESOURCE_CIRCUIT]: {
level: 4,
amount: 1,
cooldown: 800,
components: {
[exports.RESOURCE_MICROCHIP]: 1,
[exports.RESOURCE_TRANSISTOR]: 5,
[exports.RESOURCE_SWITCH]: 4,
[exports.RESOURCE_OXIDANT]: 115,
[exports.RESOURCE_ENERGY]: 32
}
},
[exports.RESOURCE_DEVICE]: {
level: 5,
amount: 1,
cooldown: 600,
components: {
[exports.RESOURCE_CIRCUIT]: 1,
[exports.RESOURCE_MICROCHIP]: 3,
[exports.RESOURCE_CRYSTAL]: 110,
[exports.RESOURCE_GHODIUM_MELT]: 150,
[exports.RESOURCE_ENERGY]: 64
}
},
[exports.RESOURCE_CELL]: {
amount: 20,
cooldown: 8,
components: {
[exports.RESOURCE_LEMERGIUM_BAR]: 20,
[exports.RESOURCE_BIOMASS]: 100,
[exports.RESOURCE_ENERGY]: 40
}
},
[exports.RESOURCE_PHLEGM]: {
level: 1,
amount: 2,
cooldown: 35,
components: {
[exports.RESOURCE_CELL]: 20,
[exports.RESOURCE_OXIDANT]: 36,
[exports.RESOURCE_LEMERGIUM_BAR]: 16,
[exports.RESOURCE_ENERGY]: 8
}
},
[exports.RESOURCE_TISSUE]: {
level: 2,
amount: 2,
cooldown: 164,
components: {
[exports.RESOURCE_PHLEGM]: 10,
[exports.RESOURCE_CELL]: 10,
[exports.RESOURCE_REDUCTANT]: 110,
[exports.RESOURCE_ENERGY]: 16
}
},
[exports.RESOURCE_MUSCLE]: {
level: 3,
amount: 1,
cooldown: 250,
components: {
[exports.RESOURCE_TISSUE]: 3,
[exports.RESOURCE_PHLEGM]: 3,
[exports.RESOURCE_ZYNTHIUM_BAR]: 50,
[exports.RESOURCE_REDUCTANT]: 50,
[exports.RESOURCE_ENERGY]: 16
}
},
[exports.RESOURCE_ORGANOID]: {
level: 4,
amount: 1,
cooldown: 800,
components: {
[exports.RESOURCE_MUSCLE]: 1,
[exports.RESOURCE_TISSUE]: 5,
[exports.RESOURCE_PURIFIER]: 208,
[exports.RESOURCE_OXIDANT]: 256,
[exports.RESOURCE_ENERGY]: 32
}
},
[exports.RESOURCE_ORGANISM]: {
level: 5,
amount: 1,
cooldown: 600,
components: {
[exports.RESOURCE_ORGANOID]: 1,
[exports.RESOURCE_LIQUID]: 150,
[exports.RESOURCE_TISSUE]: 6,
[exports.RESOURCE_CELL]: 310,
[exports.RESOURCE_ENERGY]: 64
}
},
[exports.RESOURCE_ALLOY]: {
amount: 20,
cooldown: 8,
components: {
[exports.RESOURCE_ZYNTHIUM_BAR]: 20,
[exports.RESOURCE_METAL]: 100,
[exports.RESOURCE_ENERGY]: 40
}
},
[exports.RESOURCE_TUBE]: {
level: 1,
amount: 2,
cooldown: 45,
components: {
[exports.RESOURCE_ALLOY]: 40,
[exports.RESOURCE_ZYNTHIUM_BAR]: 16,
[exports.RESOURCE_ENERGY]: 8
}
},
[exports.RESOURCE_FIXTURES]: {
level: 2,
amount: 1,
cooldown: 115,
components: {
[exports.RESOURCE_COMPOSITE]: 20,
[exports.RESOURCE_ALLOY]: 41,
[exports.RESOURCE_OXIDANT]: 161,
[exports.RESOURCE_ENERGY]: 8
}
},
[exports.RESOURCE_FRAME]: {
level: 3,
amount: 1,
cooldown: 125,
components: {
[exports.RESOURCE_FIXTURES]: 2,
[exports.RESOURCE_TUBE]: 4,
[exports.RESOURCE_REDUCTANT]: 330,
[exports.RESOURCE_ZYNTHIUM_BAR]: 31,
[exports.RESOURCE_ENERGY]: 16
}
},
[exports.RESOURCE_HYDRAULICS]: {
level: 4,
amount: 1,
cooldown: 800,
components: {
[exports.RESOURCE_LIQUID]: 150,
[exports.RESOURCE_FIXTURES]: 3,
[exports.RESOURCE_TUBE]: 15,
[exports.RESOURCE_PURIFIER]: 208,
[exports.RESOURCE_ENERGY]: 32
}
},
[exports.RESOURCE_MACHINE]: {
level: 5,
amount: 1,
cooldown: 600,
components: {
[exports.RESOURCE_HYDRAULICS]: 1,
[exports.RESOURCE_FRAME]: 2,
[exports.RESOURCE_FIXTURES]: 3,
[exports.RESOURCE_TUBE]: 12,
[exports.RESOURCE_ENERGY]: 64
}
},
[exports.RESOURCE_CONDENSATE]: {
amount: 20,
cooldown: 8,
components: {
[exports.RESOURCE_KEANIUM_BAR]: 20,
[exports.RESOURCE_MIST]: 100,
[exports.RESOURCE_ENERGY]: 40
}
},
[exports.RESOURCE_CONCENTRATE]: {
level: 1,
amount: 3,
cooldown: 41,
components: {
[exports.RESOURCE_CONDENSATE]: 30,
[exports.RESOURCE_KEANIUM_BAR]: 15,
[exports.RESOURCE_REDUCTANT]: 54,
[exports.RESOURCE_ENERGY]: 12
}
},
[exports.RESOURCE_EXTRACT]: {
level: 2,
amount: 2,
cooldown: 128,
components: {
[exports.RESOURCE_CONCENTRATE]: 10,
[exports.RESOURCE_CONDENSATE]: 30,
[exports.RESOURCE_OXIDANT]: 60,
[exports.RESOURCE_ENERGY]: 16
}
},
[exports.RESOURCE_SPIRIT]: {
level: 3,
amount: 1,
cooldown: 200,
components: {
[exports.RESOURCE_EXTRACT]: 2,
[exports.RESOURCE_CONCENTRATE]: 6,
[exports.RESOURCE_REDUCTANT]: 90,
[exports.RESOURCE_PURIFIER]: 20,
[exports.RESOURCE_ENERGY]: 16
}
},
[exports.RESOURCE_EMANATION]: {
level: 4,
amount: 1,
cooldown: 800,
components: {
[exports.RESOURCE_SPIRIT]: 2,
[exports.RESOURCE_EXTRACT]: 2,
[exports.RESOURCE_CONCENTRATE]: 3,
[exports.RESOURCE_KEANIUM_BAR]: 112,
[exports.RESOURCE_ENERGY]: 32
}
},
[exports.RESOURCE_ESSENCE]: {
level: 5,
amount: 1,
cooldown: 600,
components: {
[exports.RESOURCE_EMANATION]: 1,
[exports.RESOURCE_SPIRIT]: 3,
[exports.RESOURCE_CRYSTAL]: 110,
[exports.RESOURCE_GHODIUM_MELT]: 150,
[exports.RESOURCE_ENERGY]: 64
}
},
}
});
A site of a structure which is currently under construction. A construction site can be created using the 'Construct' button at the left of the game field or the Room.createConstructionSite
method.
To build a structure on the construction site, give a worker creep some amount of energy and perform Creep.build
action.
You can remove enemy construction sites by moving a creep on it.
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.
A unique object identificator. You can use Game.getObjectById
method to retrieve an object instance by its id
.
Whether this is your own construction site.
An object with the structure’s owner info containing the following properties:
parameter | type | description |
---|---|---|
username | string | The name of the owner user. |
The current construction progress.
The total construction progress needed for the structure to be built.
One of the STRUCTURE_*
constants.
Remove the construction site.
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 construction site, and it's not in your room. |
Creeps are your units. Creeps can move, harvest energy, construct structures, attack another creeps, and perform other actions. Each creep consists of up to 50 body parts with the following possible types:
Body part | Build cost | Effect per one body part |
---|---|---|
MOVE |
50 | Decreases fatigue by 2 points per tick. |
WORK |
100 |
Harvests 2 energy units from a source per tick. Harvests 1 resource unit from a mineral or a deposit per tick. Builds a structure for 5 energy units per tick. Repairs a structure for 100 hits per tick consuming 1 energy unit per tick. Dismantles a structure for 50 hits per tick returning 0.25 energy unit per tick. Upgrades a controller for 1 energy unit per tick. |
CARRY |
50 | Can contain up to 50 resource units. |
ATTACK |
80 | Attacks another creep/structure with 30 hits per tick in a short-ranged attack. |
RANGED_ATTACK |
150 |
Attacks another single creep/structure with 10 hits per tick in a long-range attack up to 3 squares long. Attacks all hostile creeps/structures within 3 squares range with 1-4-10 hits (depending on the range). |
HEAL |
250 | Heals self or another creep restoring 12 hits per tick in short range or 4 hits per tick at a distance. |
CLAIM |
600 |
Claims a neutral room controller. Reserves a neutral room controller for 1 tick per body part. Attacks a hostile room controller downgrading its timer by 300 ticks per body parts. Attacks a neutral room controller reservation timer by 1 tick per body parts. A creep with this body part will have a reduced life time of 600 ticks and cannot be renewed. |
TOUGH |
10 | No effect, just additional hit points to the creep's body. Can be boosted to resist damage. |
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.
An array describing the creep’s body. Each element contains the following properties:
parameter | type | description |
---|---|---|
boost | string | undefined | If the body part is boosted, this property specifies the mineral type which is used for boosting. One of the |
type | string | One of the body part types constants. |
hits | number | The remaining amount of hit points of this body part. |
This property is deprecated and will be removed soon.
An alias for Creep.store
.
This property is deprecated and will be removed soon.
An alias for Creep.store.getCapacity()
.
The movement fatigue indicator. If it is greater than zero, the creep cannot move.
The current amount of hit points of the creep.
The maximum amount of hit points of the creep.
A unique object identificator. You can use Game.getObjectById
method to retrieve an object instance by its id
.
creep.memory.task = 'building';
A shorthand to Memory.creeps[creep.name]
. You can use it for quick access the creep’s specific memory data object. Learn more about memory
Whether it is your creep or foe.
Creep’s name. You can choose the name while creating a new creep, and it cannot be changed later. This name is a hash key to access the creep via the Game.creeps object.
An object with the creep’s owner info containing the following properties:
parameter | type | description |
---|---|---|
username | string | The name of the owner user. |
The text message that the creep was saying at the last tick.
Whether this creep is still being spawned.
if(creep.store[RESOURCE_ENERGY] < creep.store.getCapacity()) {
goHarvest(creep);
}
A Store
object that contains cargo of this creep.
The remaining amount of game ticks after which the creep will die.
const target = creep.pos.findClosestByRange(FIND_HOSTILE_CREEPS);
if(target) {
if(creep.attack(target) == ERR_NOT_IN_RANGE) {
creep.moveTo(target);
}
}
Attack another creep, power creep, or structure in a short-ranged attack. Requires the ATTACK
body part. If the target is inside a rampart, then the rampart is attacked instead. The target has to be at adjacent square to the creep. If the target is a creep with ATTACK
body parts and is not inside a rampart, it will automatically hit back at the attacker.
parameter | type | description |
---|---|---|
target | Creep, PowerCreep, Structure | The target object to be attacked. |
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 creep. |
ERR_BUSY | -4 | The creep is still being spawned. |
ERR_INVALID_TARGET | -7 | The target is not a valid attackable object. |
ERR_NOT_IN_RANGE | -9 | The target is too far away. |
ERR_NO_BODYPART | -12 | There are no |
if(creep.room.controller && !creep.room.controller.my) {
if(creep.attackController(creep.room.controller) == ERR_NOT_IN_RANGE) {
creep.moveTo(creep.room.controller);
}
}
Decreases the controller's downgrade timer by 300 ticks per every CLAIM
body part, or reservation timer by 1 tick per every CLAIM
body part. If the controller under attack is owned, it cannot be upgraded or attacked again for the next 1,000 ticks. The target has to be at adjacent square to the creep.
parameter | type | description |
---|---|---|
target | StructureController | The target controller 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 creep. |
ERR_BUSY | -4 | The creep is still being spawned. |
ERR_INVALID_TARGET | -7 | The target is not a valid owned or reserved controller object. |
ERR_NOT_IN_RANGE | -9 | The target is too far away. |
ERR_TIRED | -11 | You have to wait until the next attack is possible. |
ERR_NO_BODYPART | -12 | There are not enough |
const target = creep.pos.findClosestByRange(FIND_CONSTRUCTION_SITES);
if(target) {
if(creep.build(target) == ERR_NOT_IN_RANGE) {
creep.moveTo(target);
}
}
Build a structure at the target construction site using carried energy. Requires WORK
and CARRY
body parts. The target has to be within 3 squares range of the creep.
parameter | type | description |
---|---|---|
target | ConstructionSite | The target construction site to be built. |
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 creep. |
ERR_BUSY | -4 | The creep is still being spawned. |
ERR_NOT_ENOUGH_RESOURCES | -6 | The creep does not have any carried energy. |
ERR_INVALID_TARGET | -7 | The target is not a valid construction site object or the structure cannot be built here (probably because of a creep at the same square). |
ERR_NOT_IN_RANGE | -9 | The target is too far away. |
ERR_NO_BODYPART | -12 | There are no |
creep.move(LEFT);
creep.cancelOrder('move');
//The creep will not move in this game tick
Cancel the order given during the current game tick.
parameter | type | description |
---|---|---|
methodName | string | The name of a creep's method to be cancelled. |
One of the following codes:
constant | value | description |
---|---|---|
OK | 0 | The operation has been cancelled successfully. |
ERR_NOT_FOUND | -5 | The order with the specified name is not found. |
if(creep.room.controller) {
if(creep.claimController(creep.room.controller) == ERR_NOT_IN_RANGE) {
creep.moveTo(creep.room.controller);
}
}
Claims a neutral controller under your control. Requires the CLAIM
body part. The target has to be at adjacent square to the creep. You need to have the corresponding Global Control Level in order to claim a new room. If you don't have enough GCL, consider reserving this room instead. Learn more
parameter | type | description |
---|---|---|
target | StructureController | The target controller 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 creep. |
ERR_BUSY | -4 | The creep is still being spawned. |
ERR_INVALID_TARGET | -7 | The target is not a valid neutral controller object. |
ERR_FULL | -8 | You cannot claim more than 3 rooms in the Novice Area. |
ERR_NOT_IN_RANGE | -9 | The target is too far away. |
ERR_NO_BODYPART | -12 | There are no |
ERR_GCL_NOT_ENOUGH | -15 | Your Global Control Level is not enough. |
const target = creep.pos.findClosestByRange(FIND_STRUCTURES,
{filter: {structureType: STRUCTURE_WALL}});
if(target) {
if(creep.dismantle(target) == ERR_NOT_IN_RANGE) {
creep.moveTo(target);
}
}
Dismantles any structure that can be constructed (even hostile) returning 50% of the energy spent on its repair. Requires the WORK
body part. If the creep has an empty CARRY
body part, the energy is put into it; otherwise it is dropped on the ground. The target has to be at adjacent square to the creep.
parameter | type | description |
---|---|---|
target | Structure | The target structure. |
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 creep. |
ERR_BUSY | -4 | The creep is still being spawned. |
ERR_INVALID_TARGET | -7 | The target is not a valid structure object. |
ERR_NOT_IN_RANGE | -9 | The target is too far away. |
ERR_NO_BODYPART | -12 | There are no |
creep.drop(RESOURCE_ENERGY);
// drop all resources
for(const resourceType in creep.carry) {
creep.drop(resourceType);
}
Drop this resource on the ground.
parameter | type | description |
---|---|---|
resourceType | string | One of the |
amount optional | number | The amount of resource units to be dropped. If omitted, all the available carried amount is used. |
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 creep. |
ERR_BUSY | -4 | The creep is still being spawned. |
ERR_NOT_ENOUGH_RESOURCES | -6 | The creep does not have the given amount of resources. |
ERR_INVALID_ARGS | -10 | The resourceType is not a valid |
if(creep.generateSafeMode(creep.room.controller) == ERR_NOT_IN_RANGE) {
creep.moveTo(creep.room.controller);
}
Add one more available safe mode activation to a room controller. The creep has to be at adjacent square to the target room controller and have 1000 ghodium resource.
parameter | type | description |
---|---|---|
target | StructureController | The target room controller. |
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 creep. |
ERR_BUSY | -4 | The creep is still being spawned. |
ERR_NOT_ENOUGH_RESOURCES | -6 | The creep does not have enough ghodium. |
ERR_INVALID_TARGET | -7 | The target is not a valid controller object. |
ERR_NOT_IN_RANGE | -9 | The target is too far away. |
const target = creep.pos.findClosestByRange(FIND_HOSTILE_CREEPS, {
filter: function(object) {
return object.getActiveBodyparts(ATTACK) == 0;
}
});
if(target) {
creep.moveTo(target);
}
Get the quantity of live body parts of the given type. Fully damaged parts do not count.
parameter | type | description |
---|---|---|
type | string | A body part type, one of the following body part constants:
|
A number representing the quantity of body parts.
const target = creep.pos.findClosestByRange(FIND_SOURCES_ACTIVE);
if(target) {
if(creep.harvest(target) == ERR_NOT_IN_RANGE) {
creep.moveTo(target);
}
}
Harvest energy from the source or resources from minerals and deposits. Requires the WORK
body part. If the creep has an empty CARRY
body part, the harvested resource is put into it; otherwise it is dropped on the ground. The target has to be at an adjacent square to the creep.
parameter | type | description |
---|---|---|
target | Source, Mineral, Deposit | The object to be harvested. |
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 creep, or the room controller is owned or reserved by another player. |
ERR_BUSY | -4 | The creep is still being spawned. |
ERR_NOT_FOUND | -5 | Extractor not found. You must build an extractor structure to harvest minerals. Learn more |
ERR_NOT_ENOUGH_RESOURCES | -6 | The target does not contain any harvestable energy or mineral. |
ERR_INVALID_TARGET | -7 | The target is not a valid source or mineral object. |
ERR_NOT_IN_RANGE | -9 | The target is too far away. |
ERR_TIRED | -11 | The extractor or the deposit is still cooling down. |
ERR_NO_BODYPART | -12 | There are no |
const target = creep.pos.findClosestByRange(FIND_MY_CREEPS, {
filter: function(object) {
return object.hits < object.hitsMax;
}
});
if(target) {
if(creep.heal(target) == ERR_NOT_IN_RANGE) {
creep.moveTo(target);
}
}
Heal self or another creep. It will restore the target creep’s damaged body parts function and increase the hits counter. Requires the HEAL
body part. The target has to be at adjacent square to the creep.
parameter | type | description |
---|---|---|
target | Creep, PowerCreep | 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 creep. |
ERR_BUSY | -4 | The creep is still being spawned. |
ERR_INVALID_TARGET | -7 | The target is not a valid creep object. |
ERR_NOT_IN_RANGE | -9 | The target is too far away. |
ERR_NO_BODYPART | -12 | There are no |
creep.move(RIGHT);
const path = creep.pos.findPathTo(Game.flags.Flag1);
if(path.length > 0) {
creep.move(path[0].direction);
}
creep1.move(TOP);
creep1.pull(creep2);
creep2.move(creep1);
Move the creep one square in the specified direction. Requires the MOVE
body part, or another creep nearby pulling the creep. In case if you call move
on a creep nearby, the ERR_TIRED
and the ERR_NO_BODYPART
checks will be bypassed; otherwise, the ERR_NOT_IN_RANGE
check will be bypassed.
parameter | type | description |
---|---|---|
direction | Creep|number | A creep nearby, or one of the following constants:
|
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 creep. |
ERR_BUSY | -4 | The creep is still being spawned. |
ERR_NOT_IN_RANGE | -9 | The target creep is too far away |
ERR_INVALID_ARGS | -10 | The provided direction is incorrect. |
ERR_TIRED | -11 | The fatigue indicator of the creep is non-zero. |
ERR_NO_BODYPART | -12 | There are no MOVE body parts in this creep’s body. |
const path = spawn.room.findPath(spawn, source);
creep.moveByPath(path);
if(!creep.memory.path) {
creep.memory.path = creep.pos.findPathTo(target);
}
creep.moveByPath(creep.memory.path);
Move the creep using the specified predefined path. Requires the MOVE
body part.
parameter | type | description |
---|---|---|
path | array|string | A path value as returned from |
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 creep. |
ERR_BUSY | -4 | The creep is still being spawned. |
ERR_NOT_FOUND | -5 | The specified path doesn't match the creep's location. |
ERR_INVALID_ARGS | -10 |
|
ERR_TIRED | -11 | The fatigue indicator of the creep is non-zero. |
ERR_NO_BODYPART | -12 | There are no |
creep.moveTo(10, 20);
creep.moveTo(Game.flags.Flag1);
creep.moveTo(new RoomPosition(25, 20, 'W10N5'));
creep.moveTo(pos, {reusePath: 50});
// Execute moves by cached paths at first
for(const name in Game.creeps) {
Game.creeps[name].moveTo(target, {noPathFinding: true});
}
// Perform pathfinding only if we have enough CPU
if(Game.cpu.tickLimit - Game.cpu.getUsed() > 20) {
for(const name in Game.creeps) {
Game.creeps[name].moveTo(target);
}
}
Find the optimal path to the target within the same room and move to it. A shorthand to consequent calls of pos.findPathTo() and move() methods. If the target is in another room, then the corresponding exit will be used as a target. Requires the MOVE
body part.
parameter | type | description |
---|---|---|
x | number | X position of the target in the same room. |
y | number | Y position of the target in the same room. |
target | object | Can be a RoomPosition object or any object containing RoomPosition. The position doesn't have to be in the same room with the creep. |
opts optional | object | An object containing additional options:
|
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 creep. |
ERR_NO_PATH | -2 | No path to the target could be found. |
ERR_BUSY | -4 | The creep is still being spawned. |
ERR_NOT_FOUND | -5 | The creep has no memorized path to reuse. |
ERR_INVALID_TARGET | -7 | The target provided is invalid. |
ERR_TIRED | -11 | The fatigue indicator of the creep is non-zero. |
ERR_NO_BODYPART | -12 | There are no MOVE body parts in this creep’s body. |
if(creep.memory.role == 'scout') {
creep.notifyWhenAttacked(false);
}
else {
creep.notifyWhenAttacked(true);
}
Toggle auto notification when the creep 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 creep. |
ERR_BUSY | -4 | The creep is still being spawned. |
ERR_INVALID_ARGS | -10 |
|
const target = creep.pos.findClosestByRange(FIND_DROPPED_RESOURCES);
if(target) {
if(creep.pickup(target) == ERR_NOT_IN_RANGE) {
creep.moveTo(target);
}
}
Pick up an item (a dropped piece of energy). Requires the CARRY
body part. The target has to be at adjacent square to the creep or at the same square.
parameter | type | description |
---|---|---|
target | Resource | The target object to be picked up. |
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 creep. |
ERR_BUSY | -4 | The creep is still being spawned. |
ERR_INVALID_TARGET | -7 | The target is not a valid object to pick up. |
ERR_FULL | -8 | The creep cannot receive any more resource. |
ERR_NOT_IN_RANGE | -9 | The target is too far away. |
creep1.move(TOP);
creep1.pull(creep2);
creep2.move(creep1);
const target = creep.pos.findClosestByRange(FIND_MY_CREEPS, {
filter: function(object) {
return (object.getActiveBodyparts(MOVE) == 0) &&
object.memory.destinationId &&
!object.pos.isNearTo(Game.getObjectById(object.memory.destinationId));
}
});
if(target) {
if(creep.pull(target) == ERR_NOT_IN_RANGE) {
creep.moveTo(target);
} else {
target.move(creep);
if(creep.pos.isNearTo(Game.getObjectById(target.memory.destinationId))) {
creep.move(creep.pos.getDirectionTo(target));
} else {
creep.moveTo(Game.getObjectById(target.memory.destinationId));
}
}
}
Help another creep to follow this creep. The fatigue generated for the target's move will be added to the creep instead of the target. Requires the MOVE
body part. The target has to be at adjacent square to the creep. The creep must move elsewhere, and the target must move towards the creep.
parameter | type | description |
---|---|---|
target | Creep | The target creep. |
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 creep. |
ERR_BUSY | -4 | The creep is still being spawned. |
ERR_INVALID_TARGET | -7 | The target provided is invalid. |
ERR_NOT_IN_RANGE | -9 | The target is too far away. |
const targets = creep.pos.findInRange(FIND_HOSTILE_CREEPS, 3);
if(targets.length > 0) {
creep.rangedAttack(targets[0]);
}
A ranged attack against another creep or structure. Requires the RANGED_ATTACK
body part. If the target is inside a rampart, the rampart is attacked instead. The target has to be within 3 squares range of the creep.
parameter | type | description |
---|---|---|
target | Creep, PowerCreep, Structure | The target object to be attacked. |
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 creep. |
ERR_BUSY | -4 | The creep is still being spawned. |
ERR_INVALID_TARGET | -7 | The target is not a valid attackable object. |
ERR_NOT_IN_RANGE | -9 | The target is too far away. |
ERR_NO_BODYPART | -12 | There are no |
const target = creep.pos.findClosestByRange(FIND_MY_CREEPS, {
filter: function(object) {
return object.hits < object.hitsMax;
}
});
if(target) {
creep.moveTo(target);
if(creep.pos.isNearTo(target)) {
creep.heal(target);
}
else {
creep.rangedHeal(target);
}
}
Heal another creep at a distance. It will restore the target creep’s damaged body parts function and increase the hits counter. Requires the HEAL
body part. The target has to be within 3 squares range of the creep.
parameter | type | description |
---|---|---|
target | Creep, PowerCreep | 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 creep. |
ERR_BUSY | -4 | The creep is still being spawned. |
ERR_INVALID_TARGET | -7 | The target is not a valid creep object. |
ERR_NOT_IN_RANGE | -9 | The target is too far away. |
ERR_NO_BODYPART | -12 | There are no |
const targets = creep.pos.findInRange(FIND_HOSTILE_CREEPS, 3);
if(targets.length > 0) {
creep.rangedMassAttack();
}
A ranged attack against all hostile creeps or structures within 3 squares range. Requires the RANGED_ATTACK
body part. The attack power depends on the range to each target. Friendly units are not affected.
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 creep. |
ERR_BUSY | -4 | The creep is still being spawned. |
ERR_NO_BODYPART | -12 | There are no |
const targets = creep.room.find(FIND_STRUCTURES, {
filter: object => object.hits < object.hitsMax
});
targets.sort((a,b) => a.hits - b.hits);
if(targets.length > 0) {
if(creep.repair(targets[0]) == ERR_NOT_IN_RANGE) {
creep.moveTo(targets[0]);
}
}
Repair a damaged structure using carried energy. Requires the WORK
and CARRY
body parts. The target has to be within 3 squares range of the creep.
parameter | type | description |
---|---|---|
target | Structure | The target structure to be repaired. |
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 creep. |
ERR_BUSY | -4 | The creep is still being spawned. |
ERR_NOT_ENOUGH_RESOURCES | -6 | The creep does not carry any energy. |
ERR_INVALID_TARGET | -7 | The target is not a valid structure object. |
ERR_NOT_IN_RANGE | -9 | The target is too far away. |
ERR_NO_BODYPART | -12 | There are no |
if(creep.room.controller) {
if(creep.reserveController(creep.room.controller) == ERR_NOT_IN_RANGE) {
creep.moveTo(creep.room.controller);
}
}
Temporarily block a neutral controller from claiming by other players and restore energy sources to their full capacity. Each tick, this command increases the counter of the period during which the controller is unavailable by 1 tick per each CLAIM
body part. The maximum reservation period to maintain is 5,000 ticks. The target has to be at adjacent square to the creep.
parameter | type | description |
---|---|---|
target | StructureController | The target controller object to be reserved. |
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 creep. |
ERR_BUSY | -4 | The creep is still being spawned. |
ERR_INVALID_TARGET | -7 | The target is not a valid neutral controller object. |
ERR_NOT_IN_RANGE | -9 | The target is too far away. |
ERR_NO_BODYPART | -12 | There are no |
const hostiles = creep.pos.findInRange(FIND_HOSTILE_CREEPS, 10);
if(hostiles.length > 0) {
creep.say('OMG!😨');
creep.moveTo(Game.spawns['Spawn1']);
}
else {
doWork(creep);
}
Display a visual speech balloon above the creep with the specified message. The message will be available for one tick. You can read the last message using the saying
property. Any valid Unicode characters are allowed, including emoji.
parameter | type | description |
---|---|---|
message | string | The message to be displayed. Maximum length is 10 characters. |
public optional | boolean | Set to true to allow other players to see this message. Default is false. |
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 creep. |
ERR_BUSY | -4 | The creep is still being spawned. |
if(creep.room.controller) {
if(creep.signController(creep.room.controller, "I'm going to claim this room in a few days. I warned ya!") == ERR_NOT_IN_RANGE) {
creep.moveTo(creep.room.controller);
}
}
Sign a controller with an arbitrary text visible to all players. This text will appear in the room UI, in the world map, and can be accessed via the API. You can sign unowned and hostile controllers. The target has to be at adjacent square to the creep. Pass an empty string to remove the sign.
parameter | type | description |
---|---|---|
target | StructureController | The target controller object to be signed. |
text | string | The sign text. The string is cut off after 100 characters. |
One of the following codes:
constant | value | description |
---|---|---|
OK | 0 | The operation has been scheduled successfully. |
ERR_BUSY | -4 | The creep is still being spawned. |
ERR_INVALID_TARGET | -7 | The target is not a valid controller object. |
ERR_NOT_IN_RANGE | -9 | The target is too far away. |
Kill the creep 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 creep. |
ERR_BUSY | -4 | The creep is still being spawned. |
if(creep.transfer(storage, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(storage);
}
// transfer all resources
for(const resourceType in creep.carry) {
creep.transfer(storage, resourceType);
}
Transfer resource from the creep to another object. The target has to be at adjacent square to the creep.
parameter | type | description |
---|---|---|
target | Creep, PowerCreep, Structure | The target object. |
resourceType | string | One of the |
amount optional | number | The amount of resources to be transferred. If omitted, all the available carried amount is used. |
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 creep. |
ERR_BUSY | -4 | The creep is still being spawned. |
ERR_NOT_ENOUGH_RESOURCES | -6 | The creep does not have the given amount of resources. |
ERR_INVALID_TARGET | -7 | The target is not a valid object which can contain the specified resource. |
ERR_FULL | -8 | The target cannot receive any more resources. |
ERR_NOT_IN_RANGE | -9 | The target is too far away. |
ERR_INVALID_ARGS | -10 | The resourceType is not one of the |
if(creep.room.controller) {
if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
creep.moveTo(creep.room.controller);
}
}
Upgrade your controller to the next level using carried energy. Upgrading controllers raises your Global Control Level in parallel. Requires WORK
and CARRY
body parts. The target has to be within 3 squares range of the creep.
A fully upgraded level 8 controller can't be upgraded over 15 energy units per tick regardless of creeps abilities. The cumulative effect of all the creeps performing upgradeController
in the current tick is taken into account. This limit can be increased by using ghodium mineral boost.
Upgrading the controller raises its ticksToDowngrade
timer by 100. The timer must be full in order for controller to be levelled up.
parameter | type | description |
---|---|---|
target | StructureController | The target controller object to be upgraded. |
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 creep or the target controller. |
ERR_BUSY | -4 | The creep is still being spawned. |
ERR_NOT_ENOUGH_RESOURCES | -6 | The creep does not have any carried energy. |
ERR_INVALID_TARGET | -7 | The target is not a valid controller object, or the controller upgrading is blocked. |
ERR_NOT_IN_RANGE | -9 | The target is too far away. |
ERR_NO_BODYPART | -12 | There are no |
if(creep.withdraw(storage, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(storage);
}
Withdraw resources from a structure or tombstone. The target has to be at adjacent square to the creep. Multiple creeps can withdraw from the same object in the same tick. Your creeps can withdraw resources from hostile structures/tombstones as well, in case if there is no hostile rampart on top of it.
This method should not be used to transfer resources between creeps. To transfer between creeps, use the transfer
method on the original creep.
parameter | type | description |
---|---|---|
target | Structure, Tombstone, Ruin | The target object. |
resourceType | string | One of the |
amount optional | number | The amount of resources to be transferred. If omitted, all the available amount is used. |
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 creep, or there is a hostile rampart on top of the target. |
ERR_BUSY | -4 | The creep is still being spawned. |
ERR_NOT_ENOUGH_RESOURCES | -6 | The target does not have the given amount of resources. |
ERR_INVALID_TARGET | -7 | The target is not a valid object which can contain the specified resource. |
ERR_FULL | -8 | The creep's carry is full. |
ERR_NOT_IN_RANGE | -9 | The target is too far away. |
ERR_INVALID_ARGS | -10 | The resourceType is not one of the |
A rare resource deposit needed for producing commodities. Can be harvested by creeps with a WORK
body part.
Each harvest operation triggers a cooldown period, which becomes longer and longer over time.
Learn more about deposits from this article.
Cooldown | 0.001 * totalHarvested ^ 1.2 | |
Decay | 50,000 ticks after appearing or last harvest operation |
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 amount of game ticks until the next harvest action is possible.
The deposit type, one of the following constants:
RESOURCE_MIST
RESOURCE_BIOMASS
RESOURCE_METAL
RESOURCE_SILICON
A unique object identificator. You can use Game.getObjectById
method to retrieve an object instance by its id
.
The cooldown of the last harvest operation on this deposit.
The amount of game ticks when this deposit will disappear.
A flag. Flags can be used to mark particular spots in a room. Flags are visible to their owners only. You cannot have more than 10,000 flags.
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.
Flag primary color. One of the COLOR_*
constants.
A shorthand to Memory.flags[flag.name]
. You can use it for quick access the flag's specific memory data object.
Flag’s name. You can choose the name while creating a new flag, and it cannot be changed later. This name is a hash key to access the flag via the Game.flags object. The maximum name length is 100 charactes.
Flag secondary color. One of the COLOR_*
constants.
Remove the flag.
Always returns OK .
Game.flags.Flag1.setColor(COLOR_GREEN, COLOR_WHITE);
Set new color of the flag.
parameter | type | description |
---|---|---|
color | string | Primary color of the flag. One of the |
secondaryColor optional | string | Secondary color of the flag. One of the |
One of the following codes:
constant | value | description |
---|---|---|
OK | 0 | The operation has been scheduled successfully. |
ERR_INVALID_ARGS | -10 |
|
Game.flags.Flag1.setPosition(10,20);
Game.flags.Flag1.setPosition( new RoomPosition(10, 20, 'W3S5') );
Set new position of the flag.
parameter | type | description |
---|---|---|
x | number | The X position in the room. |
y | number | The Y position in the room. |
pos | object | Can be a RoomPosition object or any object containing RoomPosition. |
One of the following codes:
constant | value | description |
---|---|---|
OK | 0 | The operation has been scheduled successfully. |
ERR_INVALID_TARGET | -7 | The target provided is invalid. |
A mineral deposit. Can be harvested by creeps with a WORK
body part using the extractor structure.
Learn more about minerals from this article.
Regeneration amount | DENSITY_LOW : 15,000 DENSITY_MODERATE : 35,000DENSITY_HIGH : 70,000 DENSITY_ULTRA : 100,000 |
Regeneration time | 50,000 ticks |
Density change probability | DENSITY_LOW : 100% chance DENSITY_MODERATE : 5% chanceDENSITY_HIGH : 5% chance DENSITY_ULTRA : 100% chance |
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 density that this mineral deposit will be refilled to once ticksToRegeneration
reaches 0. This is one of the DENSITY_*
constants.
The remaining amount of resources.
The resource type, one of the RESOURCE_*
constants.
A unique object identificator. You can use Game.getObjectById
method to retrieve an object instance by its id
.
The remaining time after which the deposit will be refilled.
A nuke landing position. This object cannot be removed or modified. You can find incoming nukes in the room using the FIND_NUKES
constant.
Landing time | 50,000 ticks |
Effect | All creeps, construction sites and dropped resources in the room are removed immediately, even inside ramparts. Damage to structures:
Note that you can stack multiple nukes from different rooms at the same target position to increase damage. Nuke landing does not generate tombstones and ruins, and destroys all existing tombstones and ruins in the room If the room is in safe mode, then the safe mode is cancelled immediately, and the safe mode cooldown is reset to 0. The room controller is hit by triggering |
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.
A unique object identificator. You can use Game.getObjectById
method to retrieve an object instance by its id
.
The name of the room where this nuke has been launched from.
The remaining landing time.
The base prototype for a structure that has an owner.
Such structures can be found using FIND_MY_STRUCTURES
and FIND_HOSTILE_STRUCTURES
constants.
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. |
Container for custom navigation cost data. By default PathFinder
will only consider
terrain data (plain, swamp, wall) — if you need to route around obstacles such as buildings
or creeps you must put them into a CostMatrix
. Generally you will create your CostMatrix
from within roomCallback
. If a non-0 value is found in a room's CostMatrix then that value
will be used instead of the default terrain cost. You should avoid using large values in your
CostMatrix and terrain cost flags. For example, running PathFinder.search
with
{ plainCost: 1, swampCost: 5 }
is faster than running it with {plainCost: 2, swampCost: 10 }
even though your paths will be the same.
let costs = new PathFinder.CostMatrix;
Creates a new CostMatrix containing 0's for all positions.
let costs = new PathFinder.CostMatrix;
let pos = Game.spawns['Spawn1'].pos;
costs.set(pos.x, pos.y, 255); // Can't walk over a building
Set the cost of a position in this CostMatrix.
parameter | type | description |
---|---|---|
x | number | X position in the room. |
y | number | Y position in the room. |
cost | number | Cost of this position. Must be a whole number. A cost of 0 will use the terrain cost for that tile. A cost greater than or equal to 255 will be treated as unwalkable. |
Get the cost of a position in this CostMatrix.
parameter | type | description |
---|---|---|
x | number | X position in the room. |
y | number | Y position in the room. |
Copy this CostMatrix into a new CostMatrix with the same data.
A new CostMatrix instance.
let costs = new PathFinder.CostMatrix;
Memory.savedMatrix = costs.serialize();
Returns a compact representation of this CostMatrix which can be stored via JSON.stringify
.
An array of numbers. There's not much you can do with the numbers besides store them for later.
let costs = PathFinder.CostMatrix.deserialize(Memory.savedMatrix)
Static method which deserializes a new CostMatrix using the return value of serialize
.
parameter | type | description |
---|---|---|
val | object | Whatever |
Returns new
CostMatrix
instance.
Power Creeps are immortal "heroes" that are tied to your account and can be respawned in any PowerSpawn
after death.
You can upgrade their abilities ("powers") up to your account Global Power Level (see Game.gpl
).
Time to live | 5,000 |
Hits | 1,000 per level |
Capacity | 100 per level |
PowerCreep.create('PowerCreep1', POWER_CLASS.OPERATOR);
A static method to create new Power Creep instance in your account. It will be added in an unspawned state,
use spawn
method to spawn it in the world.
You need one free Power Level in your account to perform this action.
parameter | type | description |
---|---|---|
name | string | The name of the new power creep. The name length limit is 100 characters. |
className | string | The class of the new power creep, one of the |
One of the following codes:
constant | value | description |
---|---|---|
OK | 0 | The operation has been scheduled successfully. |
ERR_NAME_EXISTS | -3 | A power creep with the specified name already exists. |
ERR_NOT_ENOUGH_RESOURCES | -6 | You don't have free Power Levels in your account. |
ERR_INVALID_ARGS | -10 | The provided power creep name is exceeds the limit, or the power creep class is invalid. |
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.
This property is deprecated and will be removed soon.
An alias for Creep.store
.
This property is deprecated and will be removed soon.
An alias for Creep.store.getCapacity()
.
The power creep's class, one of the POWER_CLASS
constants.
A timestamp when this creep is marked to be permanently deleted from the account, or undefined otherwise.
The current amount of hit points of the creep.
The maximum amount of hit points of the creep.
A unique object identificator. You can use Game.getObjectById
method to retrieve an object instance by its id
.
The power creep's level.
creep.memory.task = 'building';
A shorthand to Memory.powerCreeps[creep.name]
. You can use it for quick access the creep’s specific memory data object. Learn more about memory
Whether it is your creep or foe.
Power creep’s name. You can choose the name while creating a new power creep, and it cannot be changed later. This name is a hash key to access the creep via the Game.powerCreeps object.
An object with the creep’s owner info containing the following properties:
if(creep.store[RESOURCE_ENERGY] < creep.store.getCapacity()) {
goHarvest(creep);
}
A Store
object that contains cargo of this creep.
parameter | type | description |
---|---|---|
username | string | The name of the owner user. |
Available powers, an object with power ID as a key, and the following properties:
parameter | type | description |
---|---|---|
level | number | Current level of the power. |
cooldown | number | Cooldown ticks remaining, or undefined if the power creep is not spawned in the world. |
The text message that the creep was saying at the last tick.
The name of the shard where the power creep is spawned, or undefined.
if(!(Game.powerCreeps['PowerCreep1'].spawnCooldownTime > Date.now())) {
Game.powerCreeps['PowerCreep1'].spawn(powerSpawn);
}
The timestamp when spawning or deleting this creep will become available. Undefined if the power creep is spawned in the world.
The remaining amount of game ticks after which the creep will die and become unspawned. Undefined if the creep is not spawned in the world.
creep.move(LEFT);
creep.cancelOrder('move');
//The creep will not move in this game tick
Cancel the order given during the current game tick.
parameter | type | description |
---|---|---|
methodName | string | The name of a creep's method to be cancelled. |
One of the following codes:
constant | value | description |
---|---|---|
OK | 0 | The operation has been cancelled successfully. |
ERR_NOT_OWNER | -1 | You are not the owner of the creep. |
ERR_BUSY | -4 | The power creep is not spawned in the world. |
ERR_NOT_FOUND | -5 | The order with the specified name is not found. |
Game.powerCreeps['PowerCreep1'].delete();
Delete the power creep permanently from your account. It should NOT be spawned in the world. The creep is not deleted
immediately, but a 24-hours delete timer is started instead (see deleteTime
). You can cancel deletion by calling delete(true)
.
parameter | type | description |
---|---|---|
cancel | boolean | Set this to true to cancel previously scheduled deletion. |
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 creep. |
ERR_BUSY | -4 | The power creep is spawned in the world. |
creep.drop(RESOURCE_ENERGY);
// drop all resources
for(const resourceType in creep.carry) {
creep.drop(resourceType);
}
Drop this resource on the ground.
parameter | type | description |
---|---|---|
resourceType | string | One of the |
amount optional | number | The amount of resource units to be dropped. If omitted, all the available carried amount is used. |
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 creep. |
ERR_BUSY | -4 | The power creep is not spawned in the world. |
ERR_NOT_ENOUGH_RESOURCES | -6 | The creep does not have the given amount of energy. |
ERR_INVALID_ARGS | -10 | The resourceType is not a valid |
Game.powerCreeps['PowerCreep1'].usePower(PWR_GENERATE_OPS);
powerCreep.enableRoom(powerCreep.room.controller);
Enable powers usage in this room. The room controller should be at adjacent tile.
parameter | type | description |
---|---|---|
controller | StructureController | The room controller. |
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 creep. |
ERR_INVALID_TARGET | -7 | The target is not a controller structure. |
ERR_NOT_IN_RANGE | -9 | The target is too far away. |
creep.move(RIGHT);
const path = creep.pos.findPathTo(Game.flags.Flag1);
if(path.length > 0) {
creep.move(path[0].direction);
}
creep1.move(TOP);
creep1.pull(creep2);
creep2.move(creep1);
Move the creep one square in the specified direction.
parameter | type | description |
---|---|---|
direction | Creep|number | A creep nearby, or one of the following constants:
|
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 creep. |
ERR_BUSY | -4 | The power creep is not spawned in the world. |
ERR_NOT_IN_RANGE | -9 | The target creep is too far away |
ERR_INVALID_ARGS | -10 | The provided direction is incorrect. |
ERR_TIRED | -11 | The fatigue indicator of the creep is non-zero. |
const path = spawn.room.findPath(spawn, source);
creep.moveByPath(path);
if(!creep.memory.path) {
creep.memory.path = creep.pos.findPathTo(target);
}
creep.moveByPath(creep.memory.path);
Move the creep using the specified predefined path.
parameter | type | description |
---|---|---|
path | array|string | A path value as returned from |
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 creep. |
ERR_BUSY | -4 | The power creep is not spawned in the world. |
ERR_NOT_FOUND | -5 | The specified path doesn't match the creep's location. |
ERR_INVALID_ARGS | -10 |
|
ERR_TIRED | -11 | The fatigue indicator of the creep is non-zero. |
creep.moveTo(10, 20);
creep.moveTo(Game.flags.Flag1);
creep.moveTo(new RoomPosition(25, 20, 'W10N5'));
creep.moveTo(pos, {reusePath: 50});
// Execute moves by cached paths at first
for(const name in Game.creeps) {
Game.creeps[name].moveTo(target, {noPathFinding: true});
}
// Perform pathfinding only if we have enough CPU
if(Game.cpu.tickLimit - Game.cpu.getUsed() > 20) {
for(const name in Game.creeps) {
Game.creeps[name].moveTo(target);
}
}
Find the optimal path to the target within the same room and move to it. A shorthand to consequent calls of pos.findPathTo() and move() methods. If the target is in another room, then the corresponding exit will be used as a target.
parameter | type | description |
---|---|---|
x | number | X position of the target in the same room. |
y | number | Y position of the target in the same room. |
target | object | Can be a RoomPosition object or any object containing RoomPosition. The position doesn't have to be in the same room with the creep. |
opts optional | object | An object containing additional options:
|
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 creep. |
ERR_NO_PATH | -2 | No path to the target could be found. |
ERR_BUSY | -4 | The power creep is not spawned in the world. |
ERR_NOT_FOUND | -5 | The creep has no memorized path to reuse. |
ERR_INVALID_TARGET | -7 | The target provided is invalid. |
ERR_TIRED | -11 | The fatigue indicator of the creep is non-zero. |
Game.powerCreeps['PC1'].notifyWhenAttacked(true);
Toggle auto notification when the creep 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 creep. |
ERR_BUSY | -4 | The power creep is not spawned in the world. |
ERR_INVALID_ARGS | -10 |
|
const target = creep.pos.findClosestByRange(FIND_DROPPED_RESOURCES);
if(target) {
if(creep.pickup(target) == ERR_NOT_IN_RANGE) {
creep.moveTo(target);
}
}
Pick up an item (a dropped piece of energy). The target has to be at adjacent square to the creep or at the same square.
parameter | type | description |
---|---|---|
target | Resource | The target object to be picked up. |
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 creep. |
ERR_BUSY | -4 | The power creep is not spawned in the world. |
ERR_INVALID_TARGET | -7 | The target is not a valid object to pick up. |
ERR_FULL | -8 | The creep cannot receive any more resource. |
ERR_NOT_IN_RANGE | -9 | The target is too far away. |
Game.powerCreeps['PC1'].rename('PC1X');
Rename the power creep. It must not be spawned in the world.
parameter | type | description |
---|---|---|
name | string | The new name of the power creep. |
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 creep. |
ERR_NAME_EXISTS | -3 | A power creep with the specified name already exists. |
ERR_BUSY | -4 | The power creep is spawned in the world. |
let powerBank = Game.getObjectById('XXX');
Game.powerCreeps['PowerCreep1'].renew(powerBank);
Instantly restore time to live to the maximum using a Power Spawn or a Power Bank nearby. It has to be at adjacent tile.
parameter | type | description |
---|---|---|
target | StructurePowerBank | StructurePowerSpawn | The target structure. |
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 creep. |
ERR_BUSY | -4 | The power creep is not spawned in the world. |
ERR_INVALID_TARGET | -7 | The target is not a valid power bank object. |
ERR_NOT_IN_RANGE | -9 | The target is too far away. |
const hostiles = creep.pos.findInRange(FIND_HOSTILE_CREEPS, 10);
if(hostiles.length > 0) {
creep.say('OMG!😨');
creep.moveTo(Game.spawns['Spawn1']);
}
else {
doWork(creep);
}
Display a visual speech balloon above the creep with the specified message. The message will be available for one tick. You can read the last message using the saying
property. Any valid Unicode characters are allowed, including emoji.
parameter | type | description |
---|---|---|
message | string | The message to be displayed. Maximum length is 10 characters. |
public optional | boolean | Set to true to allow other players to see this message. Default is false. |
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 creep. |
ERR_BUSY | -4 | The power creep is not spawned in the world. |
Game.powerCreeps['PowerCreep1'].spawn(Game.getObjectById('XXX'));
Spawn this power creep in the specified Power Spawn.
parameter | type | description |
---|---|---|
powerSpawn | StructurePowerSpawn | Your Power Spawn structure. |
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 creep or the spawn. |
ERR_BUSY | -4 | The power creep is already spawned in the world. |
ERR_INVALID_TARGET | -7 | The specified object is not a Power Spawn. |
ERR_TIRED | -11 | The power creep cannot be spawned because of the cooldown. |
ERR_RCL_NOT_ENOUGH | -14 | Room Controller Level insufficient to use the spawn. |
Kill the power creep immediately. It will not be destroyed permanently, but will become unspawned,
so that you can spawn
it again.
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 creep. |
ERR_BUSY | -4 | The power creep is not spawned in the world. |
if(creep.transfer(storage, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(storage);
}
// transfer all resources
for(const resourceType in creep.carry) {
creep.transfer(storage, resourceType);
}
Transfer resource from the creep to another object. The target has to be at adjacent square to the creep.
parameter | type | description |
---|---|---|
target | Creep, Structure | The target object. |
resourceType | string | One of the |
amount optional | number | The amount of resources to be transferred. If omitted, all the available carried amount is used. |
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 creep. |
ERR_BUSY | -4 | The power creep is not spawned in the world. |
ERR_NOT_ENOUGH_RESOURCES | -6 | The creep does not have the given amount of resources. |
ERR_INVALID_TARGET | -7 | The target is not a valid object which can contain the specified resource. |
ERR_FULL | -8 | The target cannot receive any more resources. |
ERR_NOT_IN_RANGE | -9 | The target is too far away. |
ERR_INVALID_ARGS | -10 | The resourceType is not one of the |
Game.powerCreeps['PowerCreep1'].upgrade(PWR_GENERATE_OPS);
Upgrade the creep, adding a new power ability to it or increasing level of the existing power. You need one free Power Level in your account to perform this action.
parameter | type | description |
---|---|---|
power | number | The power ability to upgrade, one of the |
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 creep. |
ERR_NOT_ENOUGH_RESOURCES | -6 | You account Power Level is not enough. |
ERR_FULL | -8 | The specified power cannot be upgraded on this creep's level, or the creep reached the maximum level. |
ERR_INVALID_ARGS | -10 | The specified power ID is not valid. |
Game.powerCreeps['PowerCreep1'].usePower(PWR_GENERATE_OPS);
Game.powerCreeps['PowerCreep1'].usePower(PWR_OPERATE_SPAWN, Game.spawns['Spawn1']);
Apply one the creep's powers on the specified target.
You can only use powers in rooms either without a controller, or with a power-enabled controller.
Only one power can be used during the same tick, each usePower
call will override the previous one.
If the target has the same effect of a lower or equal level, it is overridden. If the existing effect level is higher, an error is returned.
parameter | type | description |
---|---|---|
power | number | The power ability to use, one of the |
target | RoomObject | A target object in the room. |
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 creep. |
ERR_BUSY | -4 | The creep is not spawned in the world. |
ERR_NOT_ENOUGH_RESOURCES | -6 | The creep doesn't have enough resources to use the power. |
ERR_INVALID_TARGET | -7 | The specified target is not valid. |
ERR_FULL | -8 | The target has the same active effect of a higher level. |
ERR_NOT_IN_RANGE | -9 | The specified target is too far away. |
ERR_INVALID_ARGS | -10 | Using powers is not enabled on the Room Controller. |
ERR_TIRED | -11 | The power ability is still on cooldown. |
ERR_NO_BODYPART | -12 | The creep doesn't have the specified power ability. |
if(creep.withdraw(storage, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(storage);
}
Withdraw resources from a structure or tombstone. The target has to be at adjacent square to the creep. Multiple creeps can withdraw from the same object in the same tick. Your creeps can withdraw resources from hostile structures/tombstones as well, in case if there is no hostile rampart on top of it.
This method should not be used to transfer resources between creeps. To transfer between creeps, use the transfer
method on the original creep.
parameter | type | description |
---|---|---|
target | Structure, Tombstone | The target object. |
resourceType | string | One of the |
amount optional | number | The amount of resources to be transferred. If omitted, all the available amount is used. |
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 creep, or there is a hostile rampart on top of the target. |
ERR_BUSY | -4 | The power creep is not spawned in the world. |
ERR_NOT_ENOUGH_RESOURCES | -6 | The target does not have the given amount of resources. |
ERR_INVALID_TARGET | -7 | The target is not a valid object which can contain the specified resource. |
ERR_FULL | -8 | The creep's carry is full. |
ERR_NOT_IN_RANGE | -9 | The target is too far away. |
ERR_INVALID_ARGS | -10 | The resourceType is not one of the |
A dropped piece of resource. It will decay after a while if not picked up.
Dropped resource pile decays for ceil(amount/1000)
units per tick.
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 amount of resource units containing.
A unique object identificator. You can use Game.getObjectById
method to retrieve an object instance by its id
.
One of the RESOURCE_*
constants.
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). The name length limit is 100 characters. |
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 name 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_POWER_CREEPS |
PowerCreep | All power creeps. |
FIND_MY_POWER_CREEPS |
PowerCreep | Only power creeps owned by you. |
FIND_HOSTILE_POWER_CREEPS |
PowerCreep | Only power 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. |
FIND_RUINS |
Ruin | All ruins |
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: {...}}
]
An object which provides fast access to room terrain data. These objects can be constructed for any room in the world even if you have no access to it.
Technically every Room.Terrain
object is a very lightweight adapter to underlying static terrain buffers with corresponding minimal accessors.
const terrain = new Room.Terrain("E2S7");
const terrain = new Room.Terrain(Game.creeps.John.room.name);
Creates a new Terrain
of room by its name. Terrain
objects can be constructed for any room in the world even if you have no access to it.
parameter | type | description |
---|---|---|
roomName | string | The room name. |
switch(terrain.get(10,15)) {
case TERRAIN_MASK_WALL:
break;
case TERRAIN_MASK_SWAMP:
break;
case 0:
break;
}
const roomName = "E2S7";
const terrain = new Room.Terrain(roomName);
const matrix = new PathFinder.CostMatrix;
const visual = new RoomVisual(roomName);
// Fill CostMatrix with default terrain costs for future analysis:
for(let y = 0; y < 50; y++) {
for(let x = 0; x < 50; x++) {
const tile = terrain.get(x, y);
const weight =
tile === TERRAIN_MASK_WALL ? 255 : // wall => unwalkable
tile === TERRAIN_MASK_SWAMP ? 5 : // swamp => weight: 5
1 ; // plain => weight: 1
matrix.set(x, y, weight);
visual.text(weight, x, y);
}
}
// bound to WASM module heap
const heapView = new Uint8Array(wasmModule.HEAPU8.buffer, ...);
const terrain = new Room.Terrain("E2S7");
// Copy terrain data to binary WASM module heap:
for(let y = 0; y < 50; y++) {
for(let x = 0; x < 50; x++) {
heapView[y * 50 + x] = terrain.get(x, y);
}
}
Get terrain type at the specified room position by (x,y)
coordinates. Unlike the Game.map.getTerrainAt(...)
method, this one doesn't perform any string operations and returns integer terrain type values (see below).
parameter | type | description |
---|---|---|
x | number | X position in the room. |
y | number | Y position in the room. |
One of the following integer values:
value | constant (if exists) | description |
---|---|---|
0 | doesn't exist | terrain is plain |
1 | TERRAIN_MASK_WALL |
terrain is wall |
2 | TERRAIN_MASK_SWAMP |
terrain is swamp |
function myPrintRawTerain(raw) {
const visual = new RoomVisual();
for(let y = 0; y < 50; y++) {
for(let x = 0; x < 50; x++) {
const code = raw[y * 50 + x];
const color =
(code & TERRAIN_MASK_WALL ) ? "gray" :
(code & TERRAIN_MASK_SWAMP) ? "green" : "white" ;
visual.circle(x, y, {fill: color, radius: 0.5});
}
}
}
const raw = (new Room.Terrain("E2S7")).getRawBuffer();
myPrintRawTerain(raw);
// bound to WASM module heap
const heapView = new Uint8Array(wasmModule.HEAPU8.buffer, ...);
const terrain = new Room.Terrain("E2S7");
// Fast direct copy terrain data to binary WASM module heap:
const t = Game.cpu.getUsed();
const result = terrain.getRawBuffer(heapView);
if(result !== ERR_INVALID_ARGS) {
// Copy succeeded, call WASM functions here:
// wasmModule.myFunc(...); // modifies raw memory of "heapView"
console.log("Distance transform done in", Game.cpu.getUsed() - t);
myPrintRawTerain(heapView);
}
// Somewhere inside binary module source code...
void myFunc(void* ptr) {
auto u8ptr = static_cast<uint8_t*>(ptr);
// computations here...
}
Get copy of underlying static terrain buffer. Current underlying representation is Uint8Array
.
parameter | type | description |
---|---|---|
destinationArray optional | Uint8Array | A typed array view in which terrain will be copied to. |
WARNING: this method relies on underlying representation of terrain data. This is the fastest way to obtain terrain data of the whole room (2500 tiles), but users should keep in mind that it can be marked as deprecated anytime in the future, or return value type can be changed due to underlying data representation changing.
See usage examples. Learn more about binary modules.
Copy of underlying room terrain representations as a new Uint8Array
typed array of size 2500.
Each element is an integer number, terrain type can be obtained by applying bitwise AND (&
) operator with appropriate TERRAIN_MASK_*
constant. Room tiles are stored row by row.
If destinationArray
is specified, function returns reference to this filled destinationArray
if coping succeeded, or error code otherwise:
constant | value | description |
---|---|---|
ERR_INVALID_ARGS | -10 |
|
Any object with a position in a room. Almost all game objects prototypes are derived from RoomObject
.
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.
An object representing the specified position in the room. Every RoomObject
in the room
contains RoomPosition
as the pos
property. The position object of a custom location
can be obtained using the Room.getPositionAt
method or using the constructor.
const pos = new RoomPosition(10, 25, 'sim');
You can create new RoomPosition
object using its constructor.
parameter | type | description |
---|---|---|
x | number | X position in the room. |
y | number | Y position in the room. |
roomName | string | The room name. |
The name of the room.
X position in the room.
Y position in the room.
Game.flags['Flag1'].pos.createConstructionSite(STRUCTURE_ROAD);
Game.flags['Flag1'].pos.createConstructionSite(STRUCTURE_SPAWN, 'MySpawn2');
Create new ConstructionSite at the specified location.
parameter | type | description |
---|---|---|
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_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 |
creep.pos.createFlag('Flag1');
Create new Flag at the specified location.
parameter | type | description |
---|---|---|
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_INVALID_ARGS | -10 | The location or the color constant is incorrect. |
const target = creep.pos.findClosestByPath(FIND_MY_SPAWNS);
creep.moveTo(target);
const target = creep.pos.findClosestByPath(FIND_MY_SPAWNS, {maxOps: 500});
creep.moveTo(target);
const target = creep.pos.findClosestByPath(FIND_HOSTILE_CREEPS, {
filter: function(object) {
return object.getActiveBodyparts(ATTACK) == 0;
}
});
const target = creep.pos.findClosestByPath(FIND_HOSTILE_CREEPS, {
filter: { owner: { username: 'Invader' } }
});
const targets = [
Game.creeps.John,
Game.creeps.Mike,
room.getPositionAt(10,10)
];
const closest = creep.pos.findClosestByPath(targets);
Find an object with the shortest path from the given position. Uses Jump Point Search algorithm and Dijkstra's algorithm.
parameter | type | description |
---|---|---|
type | number | See Room.find. |
objects | array | An array of room's objects or RoomPosition objects that the search should be executed against. |
opts optional | object | An object containing pathfinding options (see Room.findPath), or one of the following:
|
The closest object if found, null otherwise.
const target = creep.pos.findClosestByRange(FIND_MY_SPAWNS);
creep.moveTo(target);
const target = creep.pos.findClosestByRange(FIND_HOSTILE_CREEPS, {
filter: function(object) {
return object.getActiveBodyparts(ATTACK) == 0;
}
});
const target = creep.pos.findClosestByRange(FIND_HOSTILE_CREEPS, {
filter: { owner: { username: 'Invader' } }
});
const targets = [
Game.creeps.John,
Game.creeps.Mike,
room.getPositionAt(10,10)
];
const closest = creep.pos.findClosestByRange(targets);
Find an object with the shortest linear distance from the given position.
parameter | type | description |
---|---|---|
type | number | See Room.find. |
objects | array | An array of room's objects or RoomPosition objects that the search should be executed against. |
opts optional | object | An object containing one of the following options:
|
The closest object if found, null otherwise.
const targets = creep.pos.findInRange(FIND_HOSTILE_CREEPS, 3);
if(targets.length > 0) {
creep.rangedAttack(targets[0]);
}
const targets = [
Game.creeps.John,
Game.creeps.Mike,
room.getPositionAt(10,10)
];
const inRangeTargets = creep.pos.findInRange(targets, 3);
Find all objects in the specified linear range.
parameter | type | description |
---|---|---|
type | number | See Room.find. |
objects | array | An array of room's objects or RoomPosition objects that the search should be executed against. |
range | number | The range distance. |
opts optional | object | See Room.find. |
An array with the objects found.
const path = creep.pos.findPathTo(target);
creep.move(path[0].direction);
let path = creep.pos.findPathTo(target, {maxOps: 200});
if( !path.length || !target.equalsTo(path[path.length - 1]) ) {
path = creep.pos.findPathTo(target,
{maxOps: 1000, ignoreDestructibleStructures: true});
}
if( path.length ) {
creep.move(path[0].direction);
}
Find an optimal path to the specified position using Jump Point Search algorithm. This method is a shorthand for Room.findPath. If the target is in another room, then the corresponding exit will be used as a target.
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. |
opts optional | object | An object containing pathfinding options flags (see Room.findPath for more details). |
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 },
...
]
const direction = creep.pos.getDirectionTo(target);
creep.move(direction);
Get linear direction to the specified 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. |
A number representing one of the direction constants.
const range = creep.pos.getRangeTo(target);
if(range <= 3) {
creep.rangedAttack(target);
}
Get linear range to the specified 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. |
A number of squares to the given position.
if(creep.pos.inRangeTo(target, 3)) {
creep.rangedAttack(target);
}
Check whether this position is in the given range of another position.
parameter | type | description |
---|---|---|
x | number | X position in the same room. |
y | number | Y position in the same room. |
target | RoomPosition | The target position. |
range | number | The range distance. |
A boolean value.
if(creep.pos.isEqualTo(10,25)) {
creep.move(RIGHT);
}
if(creep.pos.isEqualTo(Game.flags.Flag1)) {
creep.move(RIGHT);
}
Check whether this position is the same as the specified 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. |
A boolean value.
if(creep.pos.isNearTo(target)) {
creep.transfer(target, RESOURCE_ENERGY);
}
Check whether this position is on the adjacent square to the specified position. The same as inRangeTo(target, 1)
.
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. |
A boolean value.
const look = Game.flags.Flag1.pos.look();
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.
An array with objects at the specified position in the following format:
[
{ type: 'creep', creep: {...} },
{ type: 'structure', structure: {...} },
...
{ type: 'terrain', terrain: 'swamp' }
]
const found = Game.flags.Flag1.pos.lookFor(LOOK_CREEPS);
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 |
An array of objects of the given type at the specified position if found.
Room visuals provide a way to show various visual debug info in game rooms.
You can use the RoomVisual
object to draw simple shapes that are visible only to you.
Every existing Room
object already contains the
visual
property,
but you also can create new RoomVisual
objects for any room (even without visibility)
using the constructor.
Room visuals are not stored in the database, their only purpose is to display something in
your browser. All drawings will persist for one tick and will disappear if not updated. All
RoomVisual
API calls have no added CPU cost (their cost is natural and mostly related to simple
JSON.serialize
calls). However, there is a usage limit: you cannot post more than 500 KB
of serialized data per one room (see getSize
method).
All draw coordinates are measured in game coordinates and centered to tile centers, i.e. (10,10)
will point to the center of the creep at x:10; y:10
position. Fractional coordinates are allowed.
Game.rooms['W10N10'].visual.circle(10,20).line(0,0,10,20);
// the same as:
new RoomVisual('W10N10').circle(10,20).line(0,0,10,20);
// this text will be displayed in all rooms
new RoomVisual().text('Some text', 1, 1, {align: 'left'});
You can directly create new RoomVisual
object in any room, even if it's invisible to your script.
parameter | type | description |
---|---|---|
roomName optional | string | The room name. If undefined, visuals will be posted to all rooms simultaneously. |
The name of the room.
new RoomVisual('W1N1').line(10,15, 20,20);
creep.room.visual.line(creep.pos, target.pos,
{color: 'red', lineStyle: 'dashed'});
Draw a line.
parameter | type | description |
---|---|---|
x1 | number | The start X coordinate. |
y1 | number | The start Y coordinate. |
x2 | number | The finish X coordinate. |
y2 | number | The finish Y coordinate. |
pos1 | RoomPosition | The start position object. |
pos2 | RoomPosition | The finish position object. |
style optional | object | An object with the following properties:
|
The
RoomVisual
object itself, so that you can chain calls.
new RoomVisual('W1N1').circle(10,15);
creep.room.visual.circle(creep.pos,
{fill: 'transparent', radius: 0.55, stroke: 'red'});
Draw a circle.
parameter | type | description |
---|---|---|
x | number | The X coordinate of the center. |
y | number | The Y coordinate of the center. |
pos | RoomPosition | The position object of the center. |
style optional | object | An object with the following properties:
|
The
RoomVisual
object itself, so that you can chain calls.
// 9x9 area from (2,2) to (10,10)
new RoomVisual('W1N1').rect(1.5, 1.5, 9, 9);
// a rectangle border on creep
creep.room.visual.rect(creep.pos.x - 0.6, creep.pos.y - 0.6,
1.2, 1.2,
{fill: 'transparent', stroke: '#f00'});
Draw a rectangle.
parameter | type | description |
---|---|---|
x | number | The X coordinate of the top-left corner. |
y | number | The Y coordinate of the top-left corner. |
topLeftPos | RoomPosition | The position object of the top-left corner. |
width | number | The width of the rectangle. |
height | number | The height of the rectangle. |
style optional | object | An object with the following properties:
|
The
RoomVisual
object itself, so that you can chain calls.
const points = [];
points.push(creep1.pos);
points.push([10,15]);
points.push(new RoomPosition(20,21,'W1N1'));
new RoomVisual('W1N1').poly(points, {fill: 'aqua'});
// visualize the path
const path = Game.rooms['W1N1'].findPath(from, to);
new RoomVisual('W1N1').poly(path, {stroke: '#fff', strokeWidth: .15,
opacity: .2, lineStyle: 'dashed'});
Draw a polyline.
parameter | type | description |
---|---|---|
points | array | An array of points. Every item should be either an array with 2 numbers (i.e. |
style optional | object | An object with the following properties:
|
The
RoomVisual
object itself, so that you can chain calls.
new RoomVisual('W1N1').text("Target💥", 10, 15, {color: 'green', font: 0.8});
Draw a text label. You can use any valid Unicode characters, including emoji.
parameter | type | description |
---|---|---|
text | string | The text message. |
x | number | The X coordinate of the label baseline point. |
y | number | The Y coordinate of the label baseline point. |
pos | RoomPosition | The position object of the label baseline. |
style optional | object | An object with the following properties:
|
The
RoomVisual
object itself, so that you can chain calls.
new RoomVisual('W1N1').clear();
Remove all visuals from the room.
The
RoomVisual
object itself, so that you can chain calls.
if(creep.room.visual.getSize() >= 512000) {
// cannot add more visuals in this tick
}
Get the stored size of all visuals added in the room in the current tick. It must not exceed 512,000 (500 KB).
The size of the visuals in bytes.
Memory.RoomVisualData['E2S7'] = Game.rooms.E2S7.visual.export();
Returns a compact representation of all visuals added in the room in the current tick.
A string with visuals data. There's not much you can do with the string besides store them for later.
if(Memory.RoomVisualData['E2S7']) {
Game.rooms.E2S7.visual.import(Memory.RoomVisualData['E2S7']);
}
Add previously exported (with RoomVisual.export) room visuals to the room visual data of the current tick.
parameter | type | description |
---|---|---|
val | string | The string returned from RoomVisual.export. |
The RoomVisual
object itself, so that you can chain calls.
A destroyed structure. This is a walkable object.
Decay | 500 ticks except some special cases |
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 time when the structure has been destroyed.
A unique object identificator. You can use Game.getObjectById
method to retrieve an object instance by its id
.
A Store
object that contains resources of this structure.
An object containing basic data of the destroyed structure.
The amount of game ticks before this ruin decays.
An energy source object. Can be harvested by creeps with a WORK
body part.
Energy amount | 4000 in center rooms 3000 in an owned or reserved room 1500 in an unreserved room |
Energy regeneration | Every 300 game ticks |
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 remaining amount of energy.
The total amount of energy in the source.
A unique object identificator. You can use Game.getObjectById
method to retrieve an object instance by its id
.
The remaining time after which the source will be refilled.
An object that can contain resources in its cargo.
There are two types of stores in the game: general purpose stores and limited stores.
General purpose stores can contain any resource within its capacity (e.g. creeps, containers, storages, terminals).
Limited stores can contain only a few types of resources needed for that particular object (e.g. spawns, extensions, labs, nukers).
The Store
prototype is the same for both types of stores, but they have different behavior depending on the resource
argument in its methods.
You can get specific resources from the store by addressing them as object properties:
console.log(creep.store[RESOURCE_ENERGY]);
if(creep.store[RESOURCE_ENERGY] < creep.store.getCapacity()) {
goHarvest(creep);
}
Returns capacity of this store for the specified resource. For a general purpose store, it returns total capacity if resource
is undefined.
parameter | type | description |
---|---|---|
resource optional | string | The type of the resource. |
Returns capacity number, or null
in case of an invalid resource
for this store type.
if(structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0) {
creep.transfer(structure, RESOURCE_ENERGY);
}
Returns free capacity for the store. For a limited store, it returns the capacity available for the specified resource if resource
is defined and valid for this store.
parameter | type | description |
---|---|---|
resource optional | string | The type of the resource. |
Returns available capacity number, or null
in case of an invalid resource
for this store type.
if(Game.rooms['W1N1'].terminal.store.getUsedCapacity() == 0) {
// terminal is empty
}
Returns the capacity used by the specified resource. For a general purpose store, it returns total used capacity if resource
is undefined.
parameter | type | description |
---|---|---|
resource optional | string | The type of the resource. |
Returns used capacity number, or null
in case of a not valid resource
for this store type.
The base prototype object of all structures.
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, and it's not in your room. |
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 |
|
A small container that can be used to store resources. This is a walkable structure. All dropped resources automatically goes to the container at the same tile.
Controller level | Any (including neutral rooms) |
Available per room | 5 |
Capacity | 2,000 |
Cost | 5,000 |
Hits | 250,000 |
Decay | Loses 5,000 hits every 500 ticks in an owned room, and every 100 ticks in an unowned room. |
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 |
|
const containersWithEnergy = room.find(FIND_STRUCTURES, {
filter: (i) => i.structureType == STRUCTURE_CONTAINER &&
i.store[RESOURCE_ENERGY] > 0
});
A Store
object that contains cargo of this structure.
This property is deprecated and will be removed soon.
An alias for .store.getCapacity()
.
The amount of game ticks when this container will lose some hit points.
Claim this structure to take control over the room. The controller structure cannot be damaged or destroyed.
It can be addressed by Room.controller
property.
Level | Upgrade to next level | Downgrade timer |
---|---|---|
1 | 200 energy | 20,000 ticks |
2 | 45,000 energy | 10,000 ticks |
3 | 135,000 energy | 20,000 ticks |
4 | 405,000 energy | 40,000 ticks |
5 | 1,215,000 energy | 80,000 ticks |
6 | 3,645,000 energy | 120,000 ticks |
7 | 10,935,000 energy | 150,000 ticks |
8 | — | 200,000 ticks |
Effect | Blocks attack , rangedAttack , rangedMassAttack , dismantle , heal , rangedHeal , attackController , and withdraw methods of all hostile creeps in the room, plus enableRoom and usePower methods of hostile Power Creeps. Only one room can be in safe mode at the same time.When safe mode is active, all hostile creeps become visually transparent and passable - your creeps can move through them freely (but not vice versa). |
Duration | 20,000 ticks |
Cooldown | 50,000 ticks (no cooldown in Novice Areas, also no cooldown for initial Safe Mode in your first room) |
Generation |
|
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.