From 3811e4fc56749deb5b71b91d9a6a86618d8089b2 Mon Sep 17 00:00:00 2001 From: Anton Vakhrushev Date: Wed, 22 Jul 2020 17:36:06 +0300 Subject: [PATCH] Fix tower repair ability --- src/creep/builder.ts | 5 ++++- src/main.ts | 12 ++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/creep/builder.ts b/src/creep/builder.ts index f10c124..9fc8c58 100644 --- a/src/creep/builder.ts +++ b/src/creep/builder.ts @@ -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' } }); diff --git a/src/main.ts b/src/main.ts index 0187f5d..cad072b 100644 --- a/src/main.ts +++ b/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; } }