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))
|
.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;
|
6
main.js
6
main.js
@ -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: {
|
||||||
|
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user