Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
roadList = [];
for(let pos of freePOSs) {
// console.log(`Building ${this.structureType} ${howmanyToBuild}:${howmanyHere} at ${pos}`);
if (BuildOrders.schedule(room, this.structureType, pos)) {
howmanyToBuild--;
howmanyHere++;
roadList.push(pos); // build a road to the structure so creeps can charge it.
}
if (howmanyToBuild === 0 || howmanyHere === this.howmanyAtEachPoi) {
break; // we have built enough or want to move onto the next POI
}
}
Roads.connect(target, roadList);
if (howmanyToBuild === 0) {
// don't need the rest of the POI locations.
break;
}
}
if (howmanyToBuild) {
console.log(`Unable to build ${howmanyToBuild} ${this.structureType}(s) in ${room}`);
}
return howmanyToBuild === 0;
}
gc() {
console.log(`${spawner} coming online in ${spawner.room}`);
spawner.memory.setup = 1; // only setup once
spawner.memory.level = spawner.room.controller.level;
// create a creep immediately
roleHarvester.spawn(spawner);
}
if(spawner.memory.level !== spawner.room.controller.level) {
// We can build things!
spawner.memory.level = spawner.room.controller.level;
if (spawner.memory.setup < 2) {
// Create network of roads to common places
console.log('Create Network of Roads');
let sources = spawner.room.find(FIND_SOURCES);
Roads.connect(spawner, sources);
Roads.connect(spawner.room.controller, sources);
spawner.memory.setup = 2;
}
}
// Do not have all spawners run on the same tick.
if (Game.time % phase.SpawnPeriod == spawner.name[spawner.name.length-1]) {
if (spawner.spawning) return;
if (roleHarvester.shouldSpawn(spawner)) {
roleHarvester.spawn(spawner);
} else if (roleMiner.shouldSpawn(spawner)) {
roleMiner.spawn(spawner);
} else if (roleBuilder.shouldSpawn(spawner)) {
roleBuilder.spawn(spawner);
spawner.memory.setup = 1; // only setup once
spawner.memory.level = spawner.room.controller.level;
// create a creep immediately
roleHarvester.spawn(spawner);
}
if(spawner.memory.level !== spawner.room.controller.level) {
// We can build things!
spawner.memory.level = spawner.room.controller.level;
if (spawner.memory.setup < 2) {
// Create network of roads to common places
console.log('Create Network of Roads');
let sources = spawner.room.find(FIND_SOURCES);
Roads.connect(spawner, sources);
Roads.connect(spawner.room.controller, sources);
spawner.memory.setup = 2;
}
}
// Do not have all spawners run on the same tick.
if (Game.time % phase.SpawnPeriod == spawner.name[spawner.name.length-1]) {
if (spawner.spawning) return;
if (roleHarvester.shouldSpawn(spawner)) {
roleHarvester.spawn(spawner);
} else if (roleMiner.shouldSpawn(spawner)) {
roleMiner.spawn(spawner);
} else if (roleBuilder.shouldSpawn(spawner)) {
roleBuilder.spawn(spawner);
} else if (roleUpgrader.shouldSpawn(spawner)) {
if (!creep.busy) { // Upgrader, also the catch-all
roleUpgrader.run(creep);
}
if (creep.ticksToLive === 1) {
creep.say('☠️ dying');
// console.log(`${creep} ${creep.pos} died naturally.`);
for(const resourceType in creep.carry) {
creep.drop(resourceType);
}
// TODO Inform a Spawner to replace the creep.
delete Memory.creeps[creep.name];
}
}
utils.gc(); // garbage collect the recently deseased creep
Roads.gc();
Towers.gc();
Extensions.gc();
RoomUtils.gc();
BuildOrders.gc();
};
}
code = creep.moveTo(target, opts);
if (code === ERR_NO_PATH) {
// ignore these. We can't cound blocked, because they re-path after 5 turns.
creep.say(Errors.errorEmoji[ERR_NO_PATH]);
return OK;
}
Errors.check(creep, `moveTo ${target}`, code);
if (code === OK || code === ERR_TIRED) {
creep.busy = 1;
if(code === OK && creep.memory.blocked && --creep.memory.blocked >= 0) {
delete creep.memory.blocked;
}
if (! disableRoadCheck) {
Roads.shouldBuildAt(creep);
}
return OK;
} else if (code === ERR_NO_BODYPART) {
// unable to move?
this.suicide(creep);
}
return code;
}