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)) .map((f) => f.slice(flagName.length))
.max(); .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 role: roleHarvester
}, },
builder: { builder: {
bodyParts: [WORK, CARRY, MOVE, MOVE], bodyParts: [WORK, CARRY, CARRY, MOVE],
minimumCreeps: 4, minimumCreeps: 5,
role: roleBuilder role: roleBuilder
}, },
upgrader: { upgrader: {
bodyParts: [WORK, CARRY, CARRY, MOVE, MOVE], bodyParts: [WORK, CARRY, CARRY, MOVE, MOVE],
minimumCreeps: 4, minimumCreeps: 2,
role: roleUpgrader role: roleUpgrader
}, },
guard: { guard: {

View File

@ -1,5 +1,5 @@
var battle = require('battle') var battle = require('battle')
//var helpers = require('helpers'); var helpers = require('helpers');
var structureTower= { var structureTower= {
run: function(structure){ run: function(structure){
@ -12,27 +12,12 @@ var structureTower= {
console.log('\t', this.structure, 'attacking:',target) console.log('\t', this.structure, 'attacking:',target)
this.structure.attack(target); this.structure.attack(target);
} else { } else {
var damagedStructure = this.findDamagedStructure(); var damagedStructure = helpers.findDamagedStructure(this.structure);
if(damagedStructure){ if(damagedStructure){
console.log("repairing", damagedStructure); console.log("repairing", damagedStructure);
this.structure.repair(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; module.exports = structureTower;