Add a Road planner

This commit is contained in:
uwap 2022-12-21 13:40:06 +01:00
parent a73f1f7004
commit ed73f8330b
2 changed files with 26 additions and 1 deletions

View file

@ -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);
}
}
}
}

View file

@ -2,6 +2,7 @@ import { runAction } from "./Actions/Action";
import { harvestFromClosestActiveSource } from "./Actions/harvest"; import { harvestFromClosestActiveSource } from "./Actions/harvest";
import { transferEnergy } from "./Actions/transferEnergy"; import { transferEnergy } from "./Actions/transferEnergy";
import { upgradeController } from "./Actions/upgradeController"; import { upgradeController } from "./Actions/upgradeController";
import { buildRoads } from "./RoomPlanner/Blueprints/Roads";
export function loop() { export function loop() {
const spawn = Game.spawns.Spawn1; const spawn = Game.spawns.Spawn1;
@ -20,6 +21,11 @@ export function loop() {
.andThen(transferEnergy(spawn)) .andThen(transferEnergy(spawn))
.or(upgradeController(controller)) .or(upgradeController(controller))
.repeat() .repeat()
}
if (Game.time % 100 === 0) {
buildRoads(spawn.room);
}
if (Game.cpu.bucket === 10000) {
Game.cpu.generatePixel();
} }
} }