old source files of 2018-2020.
This commit is contained in:
37
controller_towers.js
Normal file
37
controller_towers.js
Normal file
@@ -0,0 +1,37 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user