Fix tower repair ability

This commit is contained in:
Anton Vakhrushev 2020-07-22 17:36:06 +03:00
parent 895888664b
commit 3811e4fc56
2 changed files with 12 additions and 5 deletions

View File

@ -53,10 +53,13 @@ function build(creep: Creep): boolean {
} }
function repair(creep: Creep) { function repair(creep: Creep) {
const targets = creep.room.find(FIND_STRUCTURES).filter((t) => t.hits < t.hitsMax); const targets = creep.room.find(FIND_STRUCTURES, {
filter: (t) => t.hits < t.hitsMax
});
if (targets.length === 0) { if (targets.length === 0) {
return false; return false;
} }
targets.sort((t1, t2) => t1.hits - t2.hits);
if (creep.repair(targets[0]) == ERR_NOT_IN_RANGE) { if (creep.repair(targets[0]) == ERR_NOT_IN_RANGE) {
creep.say('🚧 repair'); creep.say('🚧 repair');
creep.moveTo(targets[0], { visualizePathStyle: { stroke: '#ffffff' } }); creep.moveTo(targets[0], { visualizePathStyle: { stroke: '#ffffff' } });

View File

@ -135,11 +135,15 @@ function runTower(tower: StructureTower) {
return; return;
} }
const buildings = room.find(FIND_MY_STRUCTURES, { const roads = room.find(FIND_STRUCTURES, {
filter: (s) => s.hits < s.hitsMax filter: (s) => s.structureType === STRUCTURE_ROAD && s.hits < s.hitsMax
}); });
if (buildings.length > 0) { if (roads.length > 0) {
const res = tower.repair(_.first(buildings)); roads.sort((r1, r2) => r1.hits - r2.hits);
let road = _.first(roads);
console.log('Broken road', road.hits);
const res = tower.repair(road);
console.log('Repair', res); console.log('Repair', res);
return;
} }
} }