From ed73f8330b02f9b553ebba4ea1378a8a54369396 Mon Sep 17 00:00:00 2001 From: uwap Date: Wed, 21 Dec 2022 13:40:06 +0100 Subject: [PATCH] Add a Road planner --- src/RoomPlanner/Blueprints/Roads.ts | 19 +++++++++++++++++++ src/index.ts | 8 +++++++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/RoomPlanner/Blueprints/Roads.ts diff --git a/src/RoomPlanner/Blueprints/Roads.ts b/src/RoomPlanner/Blueprints/Roads.ts new file mode 100644 index 0000000..083d12f --- /dev/null +++ b/src/RoomPlanner/Blueprints/Roads.ts @@ -0,0 +1,19 @@ +export const buildRoads = (room: Room) => { + if (room.controller?.level ?? 0 < 2) { + return; + } + const sources = room.find(FIND_SOURCES); + room.visual.clear(); + for (const source of sources) { + for (const source2 of sources) { + const path = source.pos.findPathTo(source2, { + ignoreCreeps: true, + ignoreRoads: true + }); + for (const point of path) { + room.visual.line(point.x, point.y, point.x - point.dx, point.y - point.dy); + room.createConstructionSite(point.x, point.y, STRUCTURE_ROAD); + } + } + } +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 0ef7bc5..a7a1e11 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,6 +2,7 @@ import { runAction } from "./Actions/Action"; import { harvestFromClosestActiveSource } from "./Actions/harvest"; import { transferEnergy } from "./Actions/transferEnergy"; import { upgradeController } from "./Actions/upgradeController"; +import { buildRoads } from "./RoomPlanner/Blueprints/Roads"; export function loop() { const spawn = Game.spawns.Spawn1; @@ -20,6 +21,11 @@ export function loop() { .andThen(transferEnergy(spawn)) .or(upgradeController(controller)) .repeat() - + } + if (Game.time % 100 === 0) { + buildRoads(spawn.room); + } + if (Game.cpu.bucket === 10000) { + Game.cpu.generatePixel(); } } \ No newline at end of file