arenaInfo object
import { arenaInfo } from 'game';
export function loop() {
console.log(arenaInfo.name);
}
import { arenaInfo } from 'game';
export function loop() {
console.log(arenaInfo.name);
}
import { CostMatrix } from 'game/path-finder';
export function loop() {
let costs = new CostMatrix;
}
parameter | type | description |
---|---|---|
x | number | The X position in the game |
y | number | The Y position in the game |
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. |
import { CostMatrix } from 'game/path-finder';
export function loop() {
let costs = new CostMatrix;
costs.set(constructionSite.x, constructionSite.y, 10); // avoid walking over a construction site
}
parameter | type | description |
---|---|---|
x | number | The X position in the game |
y | number | The Y position in the game |
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 | 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. Builds a structure for 5 energy units 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. |
TOUGH | 10 | No effect, just additional hit points to the creep's body. |
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 valid attackable object. |
ERR_NOT_IN_RANGE | -9 | The target is too far away. |
ERR_NO_BODYPART | -12 | There are no ATTACK body parts in this creep’s body. |
let hostileCreeps = getObjectsByPrototype(Creep).filter(i => !i.my);
let target = creep.findClosestByRange(hostileCreeps);
if (target){
creep.move(target);
creep.attack(target);
}
parameter | type | description |
---|---|---|
target | The target construction site to be built. |
OK | 0 | The operation has been scheduled successfully. |
ERR_NOT_OWNER | -1 | You are not the owner of this creep. |
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 an obstacle at the same square). |
ERR_NOT_IN_RANGE | -9 | The target is too far away. |
ERR_NO_BODYPART | -12 | There are no WORK body parts in this creep’s body. |
let myConstructionSites = getObjectsByPrototype(ConstructionSite).filter(i => i.my);
let target = creep.findClosestByRange(myConstructionSites);
if (target) {
if (creep.build(target) == ERR_NOT_IN_RANGE) {
creep.move(target);
}
}
parameter | type | description |
---|---|---|
resourceType | string | One of the RESOURCE_* constants. |
amount (optional) | number | The amount of resource units to be dropped. If omitted, all the available carried amount is used. |
OK | 0 | The operation has been scheduled successfully. |
ERR_NOT_OWNER | -1 | You are not the owner of this creep. |
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 RESOURCE_* constant. |
creep.drop(RESOURCE_ENERGY);
parameter | type | description |
---|---|---|
target | The object to be harvested. |
OK | 0 | The operation has been scheduled successfully. |
ERR_NOT_OWNER | -1 | You are not the owner of this creep. |
ERR_NOT_ENOUGH_RESOURCES | -6 | The target does not contain any harvestable resource. |
ERR_INVALID_TARGET | -7 | The target is not a valid source object. |
ERR_NOT_IN_RANGE | -9 | The target is too far away. |
ERR_NO_BODYPART | -12 | There are no WORK body parts in this creep’s body. |
let activeSources = getObjectsByPrototype(Source).filter(i => i.energy > 0);
let source = creep.findClosestByRange(activeSources);
if(source){
if (creep.harvest(source) == ERR_NOT_IN_RANGE) {
creep.move(source);
}
}
parameter | type | description |
---|---|---|
target | The target creep object. |
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 valid creep object. |
ERR_NOT_IN_RANGE | -9 | The target is too far away. |
ERR_NO_BODYPART | -12 | There are no HEAL body parts in this creep’s body. |
let creeps = getObjectsByPrototype(Creep);
let myDamagedCreeps = creeps.filter(i => i.my && i.hits < i.hitsMax);
let target = tower.findClosestByRange(myDamagedCreeps);
if (creep.heal(target) == ERR_NOT_IN_RANGE) {
creep.moveTo(target);
}
parameter | type | description |
---|---|---|
direction | number | one of the following constants: TOP TOP_RIGHT RIGHT BOTTOM_RIGHT BOTTOM BOTTOM_LEFT LEFT TOP_LEFT |
OK | 0 | The operation has been scheduled successfully. |
ERR_NOT_OWNER | -1 | You are not the owner of this creep. |
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. |
creep.move(RIGHT);
parameter | type | description |
---|---|---|
target | object | Can be a GameObject or any object containing x and y properties. |
opts | object | An object with additional options that are passed to findPath. |
OK | 0 | The operation has been scheduled successfully. |
ERR_NOT_OWNER | -1 | You are not the owner of this creep. |
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. |
creep1.moveTo(creep2);
creep2.moveTo({x: 50, y: 50});
parameter | type | description |
---|---|---|
target | The target object to be picked up. |
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 valid creep object. |
ERR_FULL | -8 | The creep cannot receive any more resource. |
ERR_NOT_IN_RANGE | -9 | The target is too far away. |
let resources = getObjectsByPrototype(Resource);
let target = creep.findClosestByRange(resources);
if (target) {
if (creep.pickup(target) == ERR_NOT_IN_RANGE) {
creep.moveTo(target);
}
}
parameter | type | description |
---|---|---|
target | The target creep. |
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 valid creep object. |
ERR_NOT_IN_RANGE | -9 | The target is too far away. |
creep1.move(TOP);
creep1.pull(creep2);
creep2.moveTo(creep1);
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 valid attackable object. |
ERR_NOT_IN_RANGE | -9 | The target is too far away. |
ERR_NO_BODYPART | -12 | There are no RANGED_ATTACK body parts in this creep’s body. |
let hostileCreeps = getObjectsByPrototype(Creep).filter(i => !i.my);
let targets = creep.findInRange(hostileCreeps);
if (targets.length) {
creep.rangedAttack(targets[0]);
}
parameter | type | description |
---|---|---|
target | The target creep object. |
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 valid attackable object. |
ERR_NOT_IN_RANGE | -9 | The target is too far away. |
ERR_NO_BODYPART | -12 | There are no HEAL body parts in this creep’s body. |
let creeps = getObjectsByPrototype(Creep);
let myDamagedCreeps = creeps.filter(i => i.my && i.hits < i.hitsMax);
let targets = creep.findInRange(myDamagedCreeps);
if (targets.length) {
creep.rangedHeal(targets[0]);
}
OK | 0 | The operation has been scheduled successfully. |
ERR_NOT_OWNER | -1 | You are not the owner of this creep. |
ERR_NO_BODYPART | -12 | There are no RANGED_ATTACK body parts in this creep’s body. |
parameter | type | description |
---|---|---|
target | The target object. | |
resourceType | string | One of the RESOURCE_* constants. |
amount (optional) | number | The amount of resources to be transferred. If omitted, all the available carried amount is used. |
OK | 0 | The operation has been scheduled successfully. |
ERR_NOT_OWNER | -1 | You are not the owner of this creep. |
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 RESOURCE_* constants, or the amount is incorrect. |
if (creep.transfer(tower, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(tower);
}
parameter | type | description |
---|---|---|
target | The target structure. | |
resourceType | string | One of the RESOURCE_* constants. |
amount (optional) | number | The amount of resources to be transferred. If omitted, all the available carried amount is used. |
OK | 0 | The operation has been scheduled successfully. |
ERR_NOT_OWNER | -1 | You are not the owner of this creep. |
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 store is full. |
ERR_NOT_IN_RANGE | -9 | The target is too far away. |
ERR_INVALID_ARGS | -10 | The resourceType is not one of the RESOURCE_* constants, or the amount is incorrect. |
if (creep.withdraw(container, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(container);
}
Basic prototype for game objects. All objects and classes are inherited from this class.
parameter | type | description |
---|---|---|
positions | array | The positions to search among. An array with GameObjects or any objects containing x and y properties. |
opts (optional) | object | An object containing additional pathfinding flags supported by searchPath method. |
parameter | type | description |
---|---|---|
positions | array | The positions to search among. An array with GameObjects or any objects containing x and y properties. |
parameter | type | description |
---|---|---|
positions | array | The positions to search. An array with GameObjects or any objects containing x and y properties. |
range | number | The range distance. |
parameter | type | description |
---|---|---|
pos | object | An object containing x and y. |
opts (optional) | object | An object with additional options that are passed to findPath. |
let path = creep.findPathTo(spawn);
console.log(path.length);
parameter | type | description |
---|---|---|
pos | object | An object containing x and y. |
The base prototype for a structure that has an owner.
import { getObjectsByPrototype } from 'game/utils';
import { Creep, StructureSpawn } from 'game/prototypes';
export function loop() {
let target = getObjectsByPrototype(StructureSpawn).find(i => !i.my);
}
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.
An energy source object. Can be harvested by creeps with a WORK body part.
Energy amount | 1000 |
Energy regeneration | 10 energy per tick |
OK | 0 | The operation has been scheduled successfully. |
ERR_NOT_OWNER | -1 | You are not the owner of this spawn. |
console.log(creep.store[RESOURCE_ENERGY]);
parameter | type | description |
---|---|---|
resource (optional) |
if (creep.store[RESOURCE_ENERGY] < creep.store.getCapacity()) {
creep.harvest(source);
}
parameter | type | description |
---|---|---|
resource (optional) |
if (tower.store.getFreeCapacity(RESOURCE_ENERGY) > 0) {
creep.transfer(tower, RESOURCE_ENERGY);
}
parameter | type | description |
---|---|---|
resource (optional) |
if (container.store.getUsedCapacity() == 0) {
// the container is empty
}
import { getObjectsByPrototype } from 'game/utils';
import { Structure } from 'game/prototypes';
export function loop() {
let structures = getObjectsByPrototype(Structure).filter(i => i.hits < i.hitsMax);
console.log(structures.length);
}
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.
capacity | 2000 |
cost | 100 |
hits | 300 |
Contains energy that can be spent on spawning bigger creeps. Extensions can be placed anywhere, any spawns will be able to use them regardless of distance.
cost | 200 |
hits | 100 |
capacity | 100 |
let allExtensions = getObjectsByPrototype(StructureExtension);
let myEmptyExtensions = allExtensions.filter(e => e.my && e.store.getUsedCapacity(RESOURCE_ENERGY) == 0)
let closestEmptyExtension = creep.findClosestByRange(myEmptyExtensions);
creep.moveTo(closestEmptyExtension);
Blocks movement of hostile creeps, and defends your creeps and structures on the same position.
cost | 200 |
hits | 10000 |
cost | 3000 |
hits | 3000 |
capacity | 1000 |
Spawn time | 3 ticks per each body part |
parameter | type | description |
---|---|---|
body | array<string> | An array describing the new creep’s body. Should contain 1 to 50 elements with one of these constants: WORK MOVE CARRY ATTACK RANGED_ATTACK HEAL TOUGH |
error | number | One of the ERR_* constants |
object | Creep | Instance of the creep being spawned |
ERR_NOT_OWNER | -1 | You are not the owner of this structure. |
ERR_BUSY | -4 | The spawn is already in process of spawning another creep. |
ERR_NOT_ENOUGH_ENERGY | -6 | The spawn and its extensions contain not enough energy to create a creep with the given body. |
ERR_INVALID_ARGS | -10 | Body is not properly described. |
import { getObjectsByPrototype } from 'game/utils';
import { StructureSpawn } from 'game/prototypes';
export function loop() {
const mySpawn = getObjectsByPrototype(StructureSpawn).find(s => s.my);
const creep = mySpawn.spawnCreep([WORK, CARRY, MOVE]).object;
}
parameter | type | description |
---|---|---|
directions | array<number> | An array with the direction constants:TOP TOP_RIGHT RIGHT BOTTOM_RIGHT BOTTOM BOTTOM_LEFT LEFT TOP_LEFT |
OK | 0 | The operation has been scheduled successfully. |
ERR_NOT_OWNER | -1 | You are not the owner of this structure. |
ERR_INVALID_ARGS | -10 | The array contains invalid directions. |
import { getObjectsByPrototype } from 'game/utils';
import { StructureSpawn } from 'game/prototypes';
export function loop() {
const mySpawn = getObjectsByPrototype(StructureSpawn).find(s => s.my);
mySpawn.setDirections([TOP, TOP_RIGHT, RIGHT]);
}
Remotely attacks game objects or heals creeps within its range. Its effectiveness linearly depends on the distance. Each action consumes energy.
cost | 1250 |
hits | 3000 |
capacity | 50 |
cooldown | 10 ticks |
Action maximum range | 50 |
Energy per action | 10 |
Attack effectiveness | 150 hits at range ≤5 to 37 hits at range ≥20 |
Heal effectiveness | 100 hits at range ≤5 to 25 hits at range ≥20 |
OK | 0 | The operation has been scheduled successfully. |
ERR_NOT_OWNER | -1 | You are not the owner of this structure. |
ERR_NOT_ENOUGH_ENERGY | -6 | The tower does not have enough energy. |
ERR_INVALID_TARGET | -7 | The arguments provided are incorrect. |
ERR_TIRED | -11 | The tower is still cooling down. |
import { getObjectsByPrototype } from 'game/utils';
import { Creep } from 'game/prototypes';
import { TOWER_RANGE } from 'game/constants';
export function loop() {
let target = tower.findClosestByRange(getObjectsByPrototype(Creep).filter(i => !i.my));
if (tower.getRangeTo(target) <= TOWER_RANGE) {
tower.attack(target);
}
}
parameter | type | description |
---|---|---|
target | The target creep. |
OK | 0 | The operation has been scheduled successfully. |
ERR_NOT_OWNER | -1 | You are not the owner of this structure. |
ERR_NOT_ENOUGH_ENERGY | -6 | The tower does not have enough energy. |
ERR_INVALID_TARGET | -7 | The arguments provided are incorrect. |
ERR_TIRED | -11 | The tower is still cooling down. |
let creeps = getObjectsByPrototype(Creep);
let myDamagedCreeps = creeps.filter(i => i.my && i.hits < i.hitsMax);
let target = tower.findClosestByRange(myDamagedCreeps);
if (creep.heal(target) == ERR_NOT_IN_RANGE) {
creep.moveTo(target);
}
Blocks movement of all creeps.
cost | 100 |
hits | 10000 |
parameter | type | description |
---|---|---|
layer (optional) | number | The layer of visuals in this object. Visuals of higher layer overlaps visuals of lower layer. Default is 0. |
persistent | boolean | Whether visuals in this object are persistent. Non-persistent visuals are visible during the current tick only. |
for(const creep of creeps) {
if(!creep.hitsVisual) {
creep.hitsVisual = new Visual(10, true);
}
creep.hitsVisual.clear().text(
creep.hits,
{ x: creep.x, y: creep.y - 0.5 }, // above the creep
{
font: '0.5',
opacity: 0.7,
backgroundColor: '#808080',
backgroundPadding: '0.03'
});
}
parameter | type | description |
---|---|---|
pos | object | The position object of the center. May be GameObject or any object containing x and y properties. |
style (optional) | object | An object with the following properties:
|
parameter | type | description |
---|---|---|
pos1 | object | The start position object. May be GameObject or any object containing x and y properties. |
pos2 | object | The finish position object. May be GameObject or any object containing x and y properties. |
style (optional) | object | An object with the following properties:
|
new Visual().line({x: 1, y: 99}, {x: 99, y: 1}, {color: '#ff0000'});
new Visual().line(creep, tower, {lineStyle: 'dashed'});
parameter | type | description |
---|---|---|
points | array | An array of points. Every item may be GameObject or any object containing x and y properties. |
style (optional) | object | An object with the following properties:
|
parameter | type | description |
---|---|---|
pos | object | The position object of the top-left corner. May be GameObject or any object containing x and y properties. |
w | number | The width of the rectangle. |
h | number | The height of the rectangle. |
style (optional) | object | An object with the following properties:
|
parameter | type | description |
---|---|---|
text | string | The text message. |
pos | object | The position object of the label baseline. May be GameObject or any object containing x and y properties. |
style (optional) | object | An object with the following properties:
|
parameter | type | description |
---|---|---|
position | object | An object with x and y properties. |
prototype | class | A prototype that extends GameObject. |
ERR_INVALID_ARGS | -10 | The location or the structure prototype is incorrect. |
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 10. |
parameter | type | description |
---|---|---|
fromPos | object | The position to search from. May be GameObject or any object containing x and y properties. |
positions | array | The positions to search among. An array with GameObjects or any objects containing x and y properties. |
opts (optional) | object | An object containing additional pathfinding flags supported by searchPath method. |
let targets = getObjectsByPrototype(Creep).filter(c => !c.my);
let closestTarget = findClosestByPath(creep, targets);
creep.moveTo(closestTarget);
creep.attack(closestTarget);
parameter | type | description |
---|---|---|
fromPos | object | The position to search from. May be GameObject or any object containing x and y properties. |
positions | array | The positions to search among. An array with GameObjects or any objects containing x and y properties. |
let targets = getObjectsByPrototype(Creep).filter(c => !c.my);
let closestTarget = findClosestByRange(tower, targets);
tower.attack(closestTarget);
parameter | type | description |
---|---|---|
fromPos | object | The origin position. May be GameObject or any object containing x and y properties. |
positions | array | The positions to search. An array with GameObjects or any objects containing x and y properties. |
range | number | The range distance. |
let targets = getObjectsByPrototype(Creep).filter(c => !c.my);
let targetsInRange = findInRange(creep, targets, 3);
if (targetsInRange.length >= 3) {
creep.rangedMassAttack();
} else if (targetsInRange.length > 0) {
creep.rangedAttack(targetsInRange[0]);
}
parameter | type | description |
---|---|---|
fromPos | object | The start position. May be GameObject or any object containing x and y properties. |
toPos | object | The target position. May be GameObject or any object containing x and y properties. |
opts (optional) | object | An object containing additional pathfinding flags:
|
import { getCpuTime } from 'game/utils';
import { arenaInfo } from 'game';
export function loop() {
if( arenaInfo.cpuTimeLimit - getCpuTime() < 1000000) {
// Less than 1 ms left before timeout!
}
}
parameter | type | description |
---|---|---|
dx | number | The difference of X coordinate. |
dy | number | The difference of Y coordinate. |
let pos = path.findIndex(p => p.x == creep.x && p.y == creep.y);
let direction = getDirection(path[pos+1].x-path[pos].x, path[pos+1].y-path[pos].y);
creep.move(direction);
import { getHeapStatistics } from 'game/utils';
export function loop() {
let heap = getHeapStatistics();
console.log(`Used ${heap.total_heap_size} / ${heap.heap_size_limit}`);
}
parameter | type | description |
---|---|---|
id | string | The id property of the needed object. See GameObject prototype. |
import { getObjectById } from 'game/utils';
export function loop() {
runCreep(myCreep.id);
}
function runCreep(id) {
let creep = getObjectById(id);
creep.move(RIGHT);
}
parameter | type | description |
---|---|---|
prototype | class | A prototype that extends GameObject. |
import { getObjectsByPrototype } from 'game/utils';
import { Creep } from 'game/prototypes';
export function loop() {
const creeps = getObjectsByPrototype(Creep);
creeps.forEach(function(myCreep) {
runCreep(myCreep);
});
}
function runCreep(creep) {
if(creep.my) {
creep.move(RIGHT);
}
}
parameter | type | description |
---|---|---|
a | object | The first of two objects. May be GameObject or any object containing x and y properties. |
b | object | The second of two objects. May be GameObject or any object containing x and y properties. |
let range = getRange(creep, target);
if(range <= 3) {
creep.rangedAttack(target);
}
parameter | type | description |
---|---|---|
pos | object | The position as an object containing x and y properties. |
let matrix = new CostMatrix;
// Fill CostMatrix with full-speed terrain costs for future analysis:
for(let y = 0; y < 100; y++) {
for(let x = 0; x < 100; x++) {
let tile = getTerrainAt({x: x, y: y});
let weight =
tile === TERRAIN_WALL ? 255 : // wall => unwalkable
tile === TERRAIN_SWAMP ? 5 : // swamp => weight: 5
1 ; // plain => weight: 1
matrix.set(x, y, weight);
}
}
import { getTicks } from 'game';
export function loop() {
console.log(getTicks());
}
parameter | type | description |
---|---|---|
origin | object | See below |
goal | object | See below |
opts (optional) | object | See below |
property | type | description |
---|---|---|
pos | object | an object containing x and y properties |
range | number | range to pos before the goal is considered reached. The default is 0 |
property | type | description |
---|---|---|
costMatrix | CostMatrix | Custom navigation cost data |
plainCost | number | Cost for walking on plain positions. The default is 2 |
swampCost | number | Cost for walking on swamp positions. The default is 10 |
flee | boolean | Instead of searching for a path to the goals this will search for a path away from the goals. The cheapest path that is out of range of every goal will be returned. The default is false |
maxOps | number | The maximum allowed pathfinding operations. The default value is 50000 |
maxCost | number | The maximum allowed cost of the path returned. The default is Infinity |
heuristicWeight | number | Weight from 1 to 9 to apply to the heuristic in the A* formula F = G + weight * H. The default value is 1.2 |
path | array | The path found as an array of objects containing x and y properties |
ops | number | Total number of operations performed before this path was calculated |
cost | number | The total cost of the path as derived from plainCost, swampCost, and given CostMatrix instance |
incomplete | boolean | If the pathfinder fails to find a complete path, this will be true |
import { searchPath } from 'game/path-finder';
import { getObjectsByPrototype } from 'game/utils';
export function loop() {
let target = getObjectsByPrototype(StructureSpawn).find(i => !i.my);
let creep = getObjectsByPrototype(Creep).find(i => i.my);
let ret = searchPath(creep, target);
console.log(ret.cost); // total cost
console.log(ret.path.length); // tiles count
}
cooldown | 0 |
Energy regeneration | 1 energy per tick |