Adding source code to respository.

This commit is contained in:
Douwe Ravers
2022-04-15 14:27:00 +02:00
parent ffc5d3df13
commit 0985358150
11 changed files with 876 additions and 0 deletions

36
towers.js Normal file
View File

@@ -0,0 +1,36 @@
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);
}
}
}
}
}
};