Fix tower repair ability
This commit is contained in:
parent
895888664b
commit
3811e4fc56
@ -53,10 +53,13 @@ function build(creep: Creep): boolean {
|
||||
}
|
||||
|
||||
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) {
|
||||
return false;
|
||||
}
|
||||
targets.sort((t1, t2) => t1.hits - t2.hits);
|
||||
if (creep.repair(targets[0]) == ERR_NOT_IN_RANGE) {
|
||||
creep.say('🚧 repair');
|
||||
creep.moveTo(targets[0], { visualizePathStyle: { stroke: '#ffffff' } });
|
||||
|
12
src/main.ts
12
src/main.ts
@ -135,11 +135,15 @@ function runTower(tower: StructureTower) {
|
||||
return;
|
||||
}
|
||||
|
||||
const buildings = room.find(FIND_MY_STRUCTURES, {
|
||||
filter: (s) => s.hits < s.hitsMax
|
||||
const roads = room.find(FIND_STRUCTURES, {
|
||||
filter: (s) => s.structureType === STRUCTURE_ROAD && s.hits < s.hitsMax
|
||||
});
|
||||
if (buildings.length > 0) {
|
||||
const res = tower.repair(_.first(buildings));
|
||||
if (roads.length > 0) {
|
||||
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);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user