move things into helpers
This commit is contained in:
parent
856706ae28
commit
b34776552a
15
helpers.js
15
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;
|
6
main.js
6
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: {
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user