Compare commits
No commits in common. "fd695a82bc31f5e991ed9cdf4efae68aae0beb12" and "bd6631781d963491e19294c9fb7c02a5d927ffeb" have entirely different histories.
fd695a82bc
...
bd6631781d
3
main.js
3
main.js
|
@ -1,5 +1,4 @@
|
||||||
var roleDispatcher = require('role_dispatcher');
|
var roleDispatcher = require('role_dispatcher');
|
||||||
var utilProgress = require('util_progress');
|
|
||||||
|
|
||||||
module.exports.loop = function () {
|
module.exports.loop = function () {
|
||||||
|
|
||||||
|
@ -11,8 +10,6 @@ module.exports.loop = function () {
|
||||||
|
|
||||||
roleDispatcher.spawnCreeps(Game.spawns['Moscow']);
|
roleDispatcher.spawnCreeps(Game.spawns['Moscow']);
|
||||||
|
|
||||||
utilProgress.checkProgress();
|
|
||||||
|
|
||||||
|
|
||||||
if(Game.spawns['Moscow'].spawning) {
|
if(Game.spawns['Moscow'].spawning) {
|
||||||
var spawningCreep = Game.creeps[Game.spawns['Moscow'].spawning.name];
|
var spawningCreep = Game.creeps[Game.spawns['Moscow'].spawning.name];
|
||||||
|
|
10
role_base.js
10
role_base.js
|
@ -1,14 +1,14 @@
|
||||||
|
var body = [ MOVE, WORK, CARRY ];
|
||||||
var name = 'Creep';
|
var name = 'Creep';
|
||||||
|
|
||||||
function run(creep) { }
|
function run(creep) { }
|
||||||
|
|
||||||
function spawn(spawnPoint, newName){
|
function spawn(spawnPoint, newBody, newName){
|
||||||
var newBody = spawnPoint.room.memory.creepBodies[newName];
|
if(typeof newBody === 'undefined') newBody = body;
|
||||||
if(typeof newName === 'undefined') newName = name;
|
if(typeof newName === 'undefined') newName = name;
|
||||||
|
spawnPoint.spawnCreep(newBody, newName + Game.time,
|
||||||
spawnPoint.spawnCreep(newBody, newName + spawnPoint.room.name + "-" + Game.time,
|
|
||||||
{memory : {role : newName}
|
{memory : {role : newName}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {name,run,spawn};
|
module.exports = {body,name,run,spawn};
|
||||||
|
|
|
@ -11,10 +11,10 @@ function run(creep) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(creep.memory.building) {
|
if(creep.memory.building) {
|
||||||
var target = creep.pos.findClosestByRange(FIND_CONSTRUCTION_SITES);
|
var targets = creep.room.find(FIND_CONSTRUCTION_SITES);
|
||||||
if(target != null) {
|
if(targets.length) {
|
||||||
if(creep.build(target) == ERR_NOT_IN_RANGE) {
|
if(creep.build(targets[0]) == ERR_NOT_IN_RANGE) {
|
||||||
creep.moveTo(target);
|
creep.moveTo(targets[0], {visualizePathStyle: {stroke: '#ffffff'}});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,99 +4,22 @@ var roleBuilder = require('role_builder');
|
||||||
var roleRepairer = require('role_repairer');
|
var roleRepairer = require('role_repairer');
|
||||||
var roleGuard = require('role_guard');
|
var roleGuard = require('role_guard');
|
||||||
var roleBase = require('role_base');
|
var roleBase = require('role_base');
|
||||||
var roleEqualizer = require('role_equalizer');
|
|
||||||
var utils = require('util_etc');
|
|
||||||
|
|
||||||
const roleMap = {
|
const roleMap = {
|
||||||
harvester: roleHarvester,
|
harvester: roleHarvester,
|
||||||
upgrader: roleUpgrader,
|
upgrader: roleUpgrader,
|
||||||
builder: roleBuilder,
|
builder: roleBuilder,
|
||||||
repairer: roleRepairer,
|
repairer: roleRepairer,
|
||||||
streltsy: roleGuard,
|
streltsy: roleGuard
|
||||||
desatilnik: roleEqualizer
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// calculates how much space there is for creeps next to
|
var creepCounts = {
|
||||||
// energy sources, in order to have the perfect amount
|
"harvester" : 3,
|
||||||
function calculateTotalSourceSpace(room){
|
"builder" : 1,
|
||||||
var sources = room.find(FIND_SOURCES);
|
"upgrader" : 2,
|
||||||
|
"repairer" : 1,
|
||||||
var count = 0;
|
"streltsy" : 2
|
||||||
|
};
|
||||||
for(const source of sources){
|
|
||||||
count += utils.calculateSourceSpace(source);
|
|
||||||
}
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
function calculateCreepCounts(room){
|
|
||||||
var creepCounts = {
|
|
||||||
"harvester" : 3,
|
|
||||||
"builder" : 1,
|
|
||||||
"upgrader" : 1,
|
|
||||||
"repairer" : 1,
|
|
||||||
"streltsy" : 0,
|
|
||||||
"desatilnik" : 0
|
|
||||||
};
|
|
||||||
|
|
||||||
// 2 harvesters per source by default
|
|
||||||
creepCounts.harvester = calculateTotalSourceSpace(room);
|
|
||||||
|
|
||||||
if(room.memory.containers == 0){
|
|
||||||
|
|
||||||
// -1 harvester until at least a container built in order
|
|
||||||
// to reduce congestion
|
|
||||||
creepCounts.harvester -= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// streltsy cost 400 energy, and thus cant be built
|
|
||||||
// you have at least 2 extensions (300+50+50)
|
|
||||||
// i guess there wouldnt be a big difference since
|
|
||||||
// they wouldnt spawn anyways, but whatever
|
|
||||||
if(room.memory.extensions >= 2){
|
|
||||||
creepCounts.streltsy += 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(room.memory.extensions >= 3){
|
|
||||||
creepCounts.builder += 1;
|
|
||||||
creepCounts.upgrader += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(room.memory.containers >= 2){
|
|
||||||
creepCounts.desatilnik += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
room.memory.creepCounts = creepCounts;
|
|
||||||
}
|
|
||||||
|
|
||||||
function calculateCreepBodies(room){
|
|
||||||
var creepBodies = {
|
|
||||||
// 200 base cost
|
|
||||||
"harvester" : [WORK, CARRY, MOVE],
|
|
||||||
"builder" : [WORK, CARRY, MOVE],
|
|
||||||
"upgrader" : [WORK, CARRY, MOVE],
|
|
||||||
"repairer" : [WORK, CARRY, MOVE],
|
|
||||||
|
|
||||||
// 400 base cost
|
|
||||||
"streltsy" : [MOVE, MOVE, RANGED_ATTACK, RANGED_ATTACK],
|
|
||||||
"desatilnik" : [CARRY, CARRY, CARRY, MOVE, MOVE, MOVE]
|
|
||||||
};
|
|
||||||
|
|
||||||
// 400 cost
|
|
||||||
if(room.memory.extensions >= 2){
|
|
||||||
creepBodies.upgrader = [MOVE, MOVE, WORK, WORK, CARRY, CARRY];
|
|
||||||
creepBodes.builder = [MOVE, MOVE, WORK, WORK, CARRY, CARRY];
|
|
||||||
}
|
|
||||||
|
|
||||||
// 450 cost
|
|
||||||
if(room.memory.extensions >= 3){
|
|
||||||
creepBodies.harvester = [MOVE, MOVE, WORK, WORK, WORK, CARRY];
|
|
||||||
}
|
|
||||||
|
|
||||||
room.memory.creepBodies = creepBodies;
|
|
||||||
}
|
|
||||||
|
|
||||||
function runRole(creep){
|
function runRole(creep){
|
||||||
const role = roleMap[creep.memory.role];
|
const role = roleMap[creep.memory.role];
|
||||||
|
@ -109,19 +32,17 @@ function runRole(creep){
|
||||||
}
|
}
|
||||||
|
|
||||||
function spawnCreeps(spawn){
|
function spawnCreeps(spawn){
|
||||||
calculateCreepCounts(spawn.room);
|
for(const [role, count] of Object.entries(creepCounts)){
|
||||||
for(const [role, count] of Object.entries(spawn.room.memory.creepCounts)){
|
|
||||||
var roleCreeps = _.filter(Game.creeps, (creep) => creep.memory.role == role);
|
var roleCreeps = _.filter(Game.creeps, (creep) => creep.memory.role == role);
|
||||||
|
|
||||||
if(roleCreeps.length < count && !spawn.spawning) {
|
if(roleCreeps.length < count && !spawn.spawning) {
|
||||||
calculateCreepBodies(spawn.room);
|
|
||||||
if(typeof roleMap[role].spawn === 'function')
|
if(typeof roleMap[role].spawn === 'function')
|
||||||
roleMap[role].spawn(spawn);
|
roleMap[role].spawn(spawn);
|
||||||
else
|
else
|
||||||
roleBase.spawn(spawn, roleMap[role].name);
|
roleBase.spawn(spawn, roleMap[role].body, roleMap[role].name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { runRole, spawnCreeps};
|
module.exports = { runRole, spawnCreeps, creepCounts};
|
||||||
|
|
|
@ -1,46 +0,0 @@
|
||||||
var energyUtils = require('util_energy');
|
|
||||||
var _ = require('lodash');
|
|
||||||
|
|
||||||
var name = 'desatilnik';
|
|
||||||
|
|
||||||
function run(creep) {
|
|
||||||
if(creep.room.memory.containers == 0) return;
|
|
||||||
|
|
||||||
if(creep.store.getFreeCapacity() > 0 ){
|
|
||||||
var containers = creep.room.find(FIND_STRUCTURES, {
|
|
||||||
filter : { structureType: STRUCTURE_CONTAINER}
|
|
||||||
});
|
|
||||||
|
|
||||||
var maxContainer = containers[0];
|
|
||||||
|
|
||||||
for(const container of containers){
|
|
||||||
if(container.store[RESOURCE_ENERGY] > maxContainer.store[RESOURCE_ENERGY]){
|
|
||||||
maxContainer = container;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if(creep.withdraw(maxContainer, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
|
||||||
creep.moveTo(maxContainer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
var containers = creep.room.find(FIND_STRUCTURES, {
|
|
||||||
filter : { structureType: STRUCTURE_CONTAINER}
|
|
||||||
});
|
|
||||||
|
|
||||||
var minContainer = containers[0];
|
|
||||||
|
|
||||||
for(const container of containers){
|
|
||||||
if(container.store[RESOURCE_ENERGY] < minContainer.store[RESOURCE_ENERGY]){
|
|
||||||
minContainer = container;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if(creep.transfer(minContainer, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
|
||||||
creep.moveTo(minContainer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {name,run};
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
var body = [ MOVE, MOVE, RANGED_ATTACK, RANGED_ATTACK ];
|
||||||
var name = 'streltsy'
|
var name = 'streltsy'
|
||||||
|
|
||||||
function run(creep) {
|
function run(creep) {
|
||||||
|
@ -22,13 +23,12 @@ function run(creep) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function spawn(spawnPoint, newWaypoints){
|
function spawn(spawnPoint, newWaypoints){
|
||||||
var newBody = spawnPoint.room.memory.creepBodies[name];
|
|
||||||
if(typeof newWaypoints === 'undefined')
|
if(typeof newWaypoints === 'undefined')
|
||||||
newWaypoints = ['A','B'];
|
newWaypoints = ['A','B'];
|
||||||
|
|
||||||
spawnPoint.spawnCreep(newBody, this.name + spawnPoint.room.name + "-" + Game.time,
|
spawnPoint.spawnCreep(this.body, this.name + Game.time,
|
||||||
{memory : {role : this.name, waypoints : newWaypoints, currentWaypoint : 0}
|
{memory : {role : this.name, waypoints : newWaypoints, currentWaypoint : 0}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {name,run,spawn};
|
module.exports = {body,name,run,spawn};
|
||||||
|
|
|
@ -3,19 +3,10 @@ var energyUtils = require('util_energy');
|
||||||
var name = 'harvester';
|
var name = 'harvester';
|
||||||
|
|
||||||
function run(creep) {
|
function run(creep) {
|
||||||
if(!creep.memory.harvesting && creep.store[RESOURCE_ENERGY] == 0){
|
if(creep.store.getFreeCapacity() > 0) {
|
||||||
creep.memory.harvesting = true;
|
var sources = creep.room.find(FIND_SOURCES);
|
||||||
}
|
if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
|
||||||
if(creep.memory.harvesting && creep.store.getFreeCapacity() == 0){
|
creep.moveTo(sources[0], {visualizePathStyle: {stroke: '#ffaa00'}});
|
||||||
creep.memory.harvesting = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(creep.memory.harvesting) {
|
|
||||||
if(typeof creep.memory.assignedSource === 'undefined') energyUtils.sourceDelegate(creep);
|
|
||||||
var source = Game.getObjectById(creep.memory.assignedSource);
|
|
||||||
|
|
||||||
if(creep.harvest(source) == ERR_NOT_IN_RANGE) {
|
|
||||||
creep.moveTo(source);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -11,14 +11,14 @@ function run(creep) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(creep.memory.building) {
|
if(creep.memory.building) {
|
||||||
var target = creep.pos.findClosestByRange(FIND_STRUCTURES, {
|
var targets = creep.room.find(FIND_STRUCTURES, {
|
||||||
filter: (structure) => {
|
filter: (structure) => {
|
||||||
return structure.hitsMax - structure.hits > 0;
|
return structure.hitsMax - structure.hits > 0;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if(target != null) {
|
if(targets.length > 0) {
|
||||||
if(creep.repair(target) == ERR_NOT_IN_RANGE) {
|
if(creep.repair(targets[0]) == ERR_NOT_IN_RANGE) {
|
||||||
creep.moveTo(target, {visualizePathStyle: {stroke: '#ffffff'}});
|
creep.moveTo(targets[0], {visualizePathStyle: {stroke: '#ffffff'}});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
var energyUtils = require('util_energy');
|
|
||||||
var name = 'upgrader';
|
var name = 'upgrader';
|
||||||
|
|
||||||
/** @param {Creep} creep **/
|
/** @param {Creep} creep **/
|
||||||
|
@ -17,7 +16,10 @@ function run(creep) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
energyUtils.gatherEnergy(creep);
|
var sources = creep.room.find(FIND_SOURCES);
|
||||||
|
if(creep.harvest(sources[1]) == ERR_NOT_IN_RANGE) {
|
||||||
|
creep.moveTo(sources[1], {visualizePathStyle: {stroke: '#ffaa00'}});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
function determineNextBlueprint(room){
|
|
||||||
return STRUCTURE_EXTENSION;
|
|
||||||
}
|
|
||||||
|
|
||||||
function addBlueprint(room){
|
|
||||||
let foundPosition = false;
|
|
||||||
let spawn = room.find(FIND_MY_SPAWNS);
|
|
||||||
let position = spawn.pos;
|
|
||||||
let spiralOffset = 1;
|
|
||||||
while(!foundPosition){
|
|
||||||
position.y -= spiralOffset++;
|
|
||||||
position.x -= spiralOffset++;
|
|
||||||
position.y += spiralOffset++;
|
|
||||||
position.x += spiralOffset++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = { addBlueprint }
|
|
109
util_energy.js
109
util_energy.js
|
@ -1,105 +1,48 @@
|
||||||
var utils = require('util_etc');
|
|
||||||
var energyUtils = {
|
var energyUtils = {
|
||||||
|
|
||||||
// get energy from a container (if available) otherwise just mine for it at
|
|
||||||
// an energy source
|
|
||||||
gatherEnergy : function(creep) {
|
gatherEnergy : function(creep) {
|
||||||
let storage;
|
var storage = creep.room.find(FIND_STRUCTURES, {
|
||||||
if(creep.room.memory.containers > 0){
|
filter: (structure) => {
|
||||||
storage = creep.pos.findClosestByRange(FIND_STRUCTURES, {
|
return (structure.structureType == STRUCTURE_CONTAINER) &&
|
||||||
filter: (structure) => {
|
structure.store.getUsedCapacity(RESOURCE_ENERGY) > 0;
|
||||||
return (structure.structureType == STRUCTURE_CONTAINER) &&
|
}
|
||||||
structure.store.getUsedCapacity(RESOURCE_ENERGY) > 0;
|
});
|
||||||
}
|
/**
|
||||||
});
|
if(storage.length == 0){
|
||||||
}
|
storage = creep.room.find(FIND_STRUCTURES, {
|
||||||
else{
|
filter: (structure) => {
|
||||||
if(typeof creep.memory.assignedSource === 'undefined') energyUtils.sourceDelegate(creep);
|
return (structure.structureType == STRUCTURE_SPAWN) &&
|
||||||
let source = Game.getObjectById(creep.memory.assignedSource);
|
structure.store.getUsedCapacity(RESOURCE_ENERGY) > 0;
|
||||||
if(creep.harvest(source) == ERR_NOT_IN_RANGE) {
|
}
|
||||||
creep.moveTo(source);
|
});
|
||||||
}
|
}
|
||||||
return;
|
**/
|
||||||
}
|
if(creep.withdraw(storage[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
||||||
|
creep.moveTo(storage[0], {visualizePathStyle: {stroke: '#ffaa00'}});
|
||||||
if(storage == null) return;
|
|
||||||
|
|
||||||
if(creep.withdraw(storage, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
|
||||||
creep.moveTo(storage);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
//assign a creep to source in the room the creep is in
|
|
||||||
sourceDelegate : function(creep){
|
|
||||||
const room = creep.room;
|
|
||||||
|
|
||||||
const sources = creep.room.find(FIND_SOURCES);
|
|
||||||
|
|
||||||
let minSource = sources[0].id;
|
|
||||||
let minSourceCount = 0;
|
|
||||||
|
|
||||||
if(typeof room.memory[sources[0].id] !== 'undefined')
|
|
||||||
minSourceCount = room.memory[sources[0].id].length;
|
|
||||||
|
|
||||||
for(const source of sources){
|
|
||||||
if(typeof room.memory[source.id] === 'undefined')
|
|
||||||
room.memory[source.id] = [];
|
|
||||||
|
|
||||||
room.memory[source.id].forEach(function(assignedCreep, index){
|
|
||||||
if(!Game.creeps[assignedCreep]){
|
|
||||||
room.memory[source.id].splice(index, 1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if(room.memory[source.id].length < minSourceCount
|
|
||||||
&& room.memory[source.id].length < utils.calculateSourceSpace(source)){
|
|
||||||
|
|
||||||
minSource = source.id;
|
|
||||||
minSourceCount = room.memory[source.id].length;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
room.memory[minSource].push(creep.name);
|
|
||||||
creep.memory.assignedSource = minSource;
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
// put energy into storage, first if possible into a spawner / extension
|
|
||||||
// otherwise put it into a container
|
|
||||||
depositEnergy : function(creep) {
|
depositEnergy : function(creep) {
|
||||||
var target = creep.pos.findClosestByRange(FIND_STRUCTURES, {
|
var targets = creep.room.find(FIND_STRUCTURES, {
|
||||||
filter: (structure) => {
|
filter: (structure) => {
|
||||||
return (structure.structureType == STRUCTURE_SPAWN ||
|
return (structure.structureType == STRUCTURE_SPAWN ||
|
||||||
structure.structureType == STRUCTURE_EXTENSION) &&
|
structure.structureType == STRUCTURE_EXTENSION) &&
|
||||||
structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0;
|
structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if(target == null){
|
if(targets.length == 0){
|
||||||
target = creep.pos.findClosestByRange(FIND_STRUCTURES, {
|
targets = creep.room.find(FIND_STRUCTURES, {
|
||||||
filter: (structure) => {
|
filter: (structure) => {
|
||||||
return (structure.structureType == STRUCTURE_CONTAINER) &&
|
return (structure.structureType == STRUCTURE_CONTAINER ||
|
||||||
|
structure.structureType == STRUCTURE_TOWER) &&
|
||||||
structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0;
|
structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if(target != null) {
|
if(targets.length > 0) {
|
||||||
if(creep.transfer(target, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
if(creep.transfer(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
||||||
creep.moveTo(target, {visualizePathStyle: {stroke: '#ffffff'}});
|
creep.moveTo(targets[0], {visualizePathStyle: {stroke: '#ffffff'}});
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if no storage anywhere, then just build something
|
|
||||||
// in order to speed up early game, since no storage
|
|
||||||
if(creep.room.memory.containers == 0){
|
|
||||||
target = creep.pos.findClosestByRange(FIND_CONSTRUCTION_SITES);
|
|
||||||
if(target != null){
|
|
||||||
if(creep.build(target) == ERR_NOT_IN_RANGE){
|
|
||||||
creep.moveTo(target);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
16
util_etc.js
16
util_etc.js
|
@ -1,16 +0,0 @@
|
||||||
function calculateSourceSpace(source){
|
|
||||||
var count = 0;
|
|
||||||
|
|
||||||
for(let y = -1; y <= 1; y++){
|
|
||||||
for(let x = -1; x <= 1; x++){
|
|
||||||
if(x == 0 && y == 0) continue;
|
|
||||||
for(var object of source.room.lookAt(source.pos.x + x, source.pos.y + y)){
|
|
||||||
if(object.type != 'terrain') continue;
|
|
||||||
if(object.terrain != 'wall') count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = { calculateSourceSpace };
|
|
|
@ -1,20 +1,5 @@
|
||||||
var progressUtils = {
|
var progressUtils = {
|
||||||
checkProgress : function() {
|
checkProgress : function() {
|
||||||
|
|
||||||
for(var roomName in Game.rooms){
|
|
||||||
const room = Game.rooms[roomName];
|
|
||||||
const structures = room.find(FIND_STRUCTURES);
|
|
||||||
room.memory.spawns = 0;
|
|
||||||
room.memory.containers = 0;
|
|
||||||
room.memory.extensions = 0;
|
|
||||||
|
|
||||||
for(const structure of structures){
|
|
||||||
if(structure.structureType == STRUCTURE_CONTAINER) room.memory.containers++;
|
|
||||||
if(structure.structureType == STRUCTURE_SPAWN) room.memory.spawns++;
|
|
||||||
|
|
||||||
if(structure.structureType == STRUCTURE_EXTENSION) room.memory.extensions++;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue