diff --git a/helpers.js b/helpers.js index b18e345..f854ce6 100644 --- a/helpers.js +++ b/helpers.js @@ -11,6 +11,21 @@ var helpers = { .map((f) => f.slice(flagName.length)) .max(); }, + findDamagedStructure: function(searcher){ + var targets = searcher.room.find(FIND_STRUCTURES, { + filter: function(s){ + if(s.id == searcher.id){ + return false; + } + if (s.hits < s.hitsMax){ + return true; + } + return false; + } + }); + return searcher.pos.findClosestByPath(targets); + } + }; -module.exports = helpers; \ No newline at end of file +module.exports = helpers; diff --git a/main.js b/main.js index 0b679a1..76b6c40 100644 --- a/main.js +++ b/main.js @@ -12,13 +12,13 @@ var creepsConfig = { role: roleHarvester }, builder: { - bodyParts: [WORK, CARRY, MOVE, MOVE], - minimumCreeps: 4, + bodyParts: [WORK, CARRY, CARRY, MOVE], + minimumCreeps: 5, role: roleBuilder }, upgrader: { bodyParts: [WORK, CARRY, CARRY, MOVE, MOVE], - minimumCreeps: 4, + minimumCreeps: 2, role: roleUpgrader }, guard: { diff --git a/structure.tower.js b/structure.tower.js index af383fc..562a3a6 100644 --- a/structure.tower.js +++ b/structure.tower.js @@ -1,5 +1,5 @@ var battle = require('battle') -//var helpers = require('helpers'); +var helpers = require('helpers'); var structureTower= { run: function(structure){ @@ -12,27 +12,12 @@ var structureTower= { console.log('\t', this.structure, 'attacking:',target) this.structure.attack(target); } else { - var damagedStructure = this.findDamagedStructure(); + var damagedStructure = helpers.findDamagedStructure(this.structure); if(damagedStructure){ console.log("repairing", damagedStructure); this.structure.repair(damagedStructure); } } - - }, - findDamagedStructure: function(searcher){ - var targets = searcher.room.find(FIND_STRUCTURES, { - filter: function(s){ - if(s.structureType == STRUCTURE_TOWER){ - return false; - } - if (s.hits < s.hitsMax){ - return true; - } - return false; - } - }); - return searcher.pos.findClosestByPath(targets); } } module.exports = structureTower;