Files
screeps/controller_towers.js
2022-04-15 14:29:07 +02:00

37 lines
1.7 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: (s)=>(s.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 )
|| ( s.structureType == STRUCTURE_RAMPART && s.hits < 10000 ))});
if(structure == null) structure = tower.pos.findClosestByRange(FIND_STRUCTURES,
{filter: (s)=>((s.structureType == STRUCTURE_RAMPART) && s.hits < 1000)});
if(structure == null) structure = tower.pos.findClosestByRange(FIND_STRUCTURES,
{filter: (s)=>((s.structureType == STRUCTURE_WALL) && s.hits < 1000)});
tower.repair(structure);
}
}
}
}
}
};