diff --git a/src/Actions/Action.ts b/src/Actions/Action.ts index 2007405..3774858 100644 --- a/src/Actions/Action.ts +++ b/src/Actions/Action.ts @@ -51,7 +51,7 @@ export const createAction = (name: string, action: (creep: Creep) => Action): Ac if ((creep.memory.state ?? 0) > state) { return Success(creep, state); } - console.log(`[${creep.name}] Running action ${name}`) + //console.log(`[${creep.name}] Running action ${name}`) return action(creep)(creep, state); } } diff --git a/src/Actions/buildConstructionSite.ts b/src/Actions/buildConstructionSite.ts new file mode 100644 index 0000000..db3f6c9 --- /dev/null +++ b/src/Actions/buildConstructionSite.ts @@ -0,0 +1,23 @@ +import { createAction, Fail, InProgress, Success } from "./Action"; +import { moveTo } from "./moveTo"; + +export const buildConstructionSite = () => createAction('buildConstructionSite', (creep: Creep) => { + const cs = creep.pos.findClosestByRange(FIND_CONSTRUCTION_SITES); + if (!cs) { + return Fail; + } + switch (creep.build(cs)) { + case OK: { + return InProgress; + } + case ERR_NOT_ENOUGH_RESOURCES: { + return Success; + } + case ERR_NOT_IN_RANGE: { + return moveTo(cs); + } + default: { + return Fail; + } + } +}) \ No newline at end of file diff --git a/src/RoomPlanner/Blueprints/Extensions.ts b/src/RoomPlanner/Blueprints/Extensions.ts new file mode 100644 index 0000000..025a295 --- /dev/null +++ b/src/RoomPlanner/Blueprints/Extensions.ts @@ -0,0 +1,16 @@ +const extentionsAvailable = (roomlevel: number) => { + return roomlevel > 2 ? roomlevel * 10 - 20 : (roomlevel - 1) * 5; +} + +export const buildExtentions = (room: Room) => { + const spawns = room.find(FIND_MY_SPAWNS); + if (spawns.length < 1) return; + const spawn = spawns[0]; + const exts = extentionsAvailable(room.controller?.level ?? 0) + for (let x = -Math.floor(Math.sqrt(exts) / 2); x < Math.sqrt(exts) / 2; x++) { + for (let y = -Math.floor(Math.sqrt(exts) / 2); y < Math.sqrt(exts) / 2; y++) { + room.visual.circle(spawn.pos.x + x * 2, spawn.pos.y + y * 2); + room.createConstructionSite(spawn.pos.x + x * 2, spawn.pos.y + y * 2, STRUCTURE_EXTENSION); + } + } +} \ No newline at end of file diff --git a/src/RoomPlanner/Blueprints/Roads.ts b/src/RoomPlanner/Blueprints/Roads.ts index 2ff0cac..3350459 100644 --- a/src/RoomPlanner/Blueprints/Roads.ts +++ b/src/RoomPlanner/Blueprints/Roads.ts @@ -2,9 +2,10 @@ export const buildRoads = (room: Room) => { if ((room.controller?.level ?? 0) < 2) { return; } - const sources = room.find(FIND_SOURCES); + const sources: _HasRoomPosition[] = room.find(FIND_SOURCES); + const sourcesAndSpawns = sources.concat(room.find(FIND_MY_SPAWNS)); room.visual.clear(); - for (const source of sources) { + for (const source of sourcesAndSpawns) { for (const source2 of sources) { const path = source.pos.findPathTo(source2, { ignoreCreeps: true, diff --git a/src/index.ts b/src/index.ts index a7a1e11..4c77da9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,9 @@ import { runAction } from "./Actions/Action"; +import { buildConstructionSite } from "./Actions/buildConstructionSite"; import { harvestFromClosestActiveSource } from "./Actions/harvest"; import { transferEnergy } from "./Actions/transferEnergy"; import { upgradeController } from "./Actions/upgradeController"; +import { buildExtentions } from "./RoomPlanner/Blueprints/Extensions"; import { buildRoads } from "./RoomPlanner/Blueprints/Roads"; export function loop() { @@ -10,21 +12,31 @@ export function loop() { if (!controller) { return; } - spawn.spawnCreep([WORK, CARRY, CARRY, MOVE], 'w6'); - spawn.spawnCreep([WORK, CARRY, CARRY, MOVE], 'w5'); - spawn.spawnCreep([WORK, CARRY, CARRY, MOVE], 'w4'); - spawn.spawnCreep([WORK, CARRY, CARRY, MOVE], 'w3'); - spawn.spawnCreep([WORK, CARRY, CARRY, MOVE], 'w2'); - spawn.spawnCreep([WORK, CARRY, CARRY, MOVE], 'w1'); + spawn.spawnCreep([WORK, CARRY, CARRY, MOVE], 'builder6'); + spawn.spawnCreep([WORK, CARRY, CARRY, MOVE], 'uprader5'); + spawn.spawnCreep([WORK, CARRY, CARRY, MOVE], 'builder4'); + spawn.spawnCreep([WORK, CARRY, CARRY, MOVE], 'builder3'); + spawn.spawnCreep([WORK, CARRY, CARRY, MOVE], 'upgrader2'); + spawn.spawnCreep([WORK, CARRY, CARRY, MOVE], 'upgrader1'); for (const creep of Object.values(Game.creeps)) { - runAction(creep, harvestFromClosestActiveSource()) + if (creep.name.startsWith('u') || creep.name.startsWith('w')) { + runAction(creep, harvestFromClosestActiveSource()) .andThen(transferEnergy(spawn)) .or(upgradeController(controller)) .repeat() + } else if (creep.name.startsWith('b')) { + runAction(creep, harvestFromClosestActiveSource()) + .andThen(buildConstructionSite()) + .or(upgradeController(controller)) + .repeat() + } } if (Game.time % 100 === 0) { buildRoads(spawn.room); } + if (Game.time % 100 === 50) { + buildExtentions(spawn.room) + } if (Game.cpu.bucket === 10000) { Game.cpu.generatePixel(); }