Builder Creeps and Extension Blueprints
This commit is contained in:
parent
48350d6f33
commit
5e6618edca
5 changed files with 62 additions and 10 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
23
src/Actions/buildConstructionSite.ts
Normal file
23
src/Actions/buildConstructionSite.ts
Normal file
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
})
|
||||
16
src/RoomPlanner/Blueprints/Extensions.ts
Normal file
16
src/RoomPlanner/Blueprints/Extensions.ts
Normal file
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
26
src/index.ts
26
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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue