Worker abstraction

This commit is contained in:
uwap 2022-12-22 09:51:22 +01:00
parent 57c4ac1688
commit e2e93947b5
5 changed files with 75 additions and 22 deletions

15
src/Workers/Upgrader.ts Normal file
View file

@ -0,0 +1,15 @@
import { Fail, runAction } from "../Actions/Action";
import { harvestFromClosestActiveSource } from "../Actions/harvest";
import { transferEnergy } from "../Actions/transferEnergy";
import { upgradeController } from "../Actions/upgradeController";
import { WorkerDefinition } from "./worker";
export const Upgrader: WorkerDefinition = {
runAction: (creep: Creep, spawn: StructureSpawn) => runAction(creep, harvestFromClosestActiveSource())
.andThen(transferEnergy(spawn))
.or(creep.room.controller ? upgradeController(creep.room.controller) : Fail)
.repeat(),
name: 'upgrader',
requiredCreeps: (room: Room) => 2,
bodyDefinition: (energy: number) => [WORK, WORK, MOVE, CARRY]
}