move things into helpers

This commit is contained in:
Tyrel Souza 2016-06-30 10:59:43 -04:00
parent 856706ae28
commit b34776552a
No known key found for this signature in database
GPG Key ID: 2EECB5087209E6A5
3 changed files with 21 additions and 21 deletions

View File

@ -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;
module.exports = helpers;

View File

@ -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: {

View File

@ -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;