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) {
|
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' } });
|
||||||
|
12
src/main.ts
12
src/main.ts
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user