Files
screeps/towers.js
2022-04-15 14:27:00 +02:00

36 lines
1.6 KiB
JavaScript

module.exports = {
run: function(){
for(var spawn in Game.spawns){
var room = Game.spawns[spawn].room;
var towers = room.find(FIND_MY_STRUCTURES,
{filter: {structureType: STRUCTURE_TOWER}});
for(var tower in towers){
tower = towers[tower];
var enemy = tower.pos.findClosestByRange(FIND_HOSTILE_CREEPS);
if(enemy != null) tower.attack(enemy);
else {
var healt_creep = false;
for(var creep in Game.creeps){
creep = Game.creeps[creep];
if(creep.hits < creep.hitsMax) {
tower.heal(creep);
healt_creep = true;
}
}
if(!healt_creep && 500 < tower.energy){
var structure = tower.pos.findClosestByPath(FIND_STRUCTURES,
{filter: (s)=>(s.structureType != STRUCTURE_RAMPART && s.structureType != STRUCTURE_WALL && s.hits < s.hitsMax)});
if(750 < tower.energy && structure == null) {
var structures = tower.room.find(FIND_STRUCTURES, {filter: { structureType: STRUCTURE_RAMPART, structureType: STRUCTURE_WALL }});
structures.sort(function(a,b){return a.hits - b.hits});
structure = structures[0];
}
tower.repair(structure);
}
}
}
}
}
};