Add clerks
This commit is contained in:
parent
365fd17b01
commit
3bd6b0ac2c
9 changed files with 76 additions and 15 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import { createAction, Fail, InProgress, Success } from "./Action";
|
||||
import { moveTo } from "./moveTo";
|
||||
|
||||
export const transferEnergy = (target: Creep | StructureSpawn | StructureContainer | StructureExtension | null) => createAction('transferEnergy', (creep: Creep) => {
|
||||
export const transferEnergy = (target: Creep | StructureSpawn | StructureContainer | StructureExtension | StructureStorage | null) => createAction('transferEnergy', (creep: Creep) => {
|
||||
if (target == null) {
|
||||
return Fail;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { createAction, Fail, InProgress, Success } from "./Action";
|
||||
import { moveTo } from "./moveTo";
|
||||
|
||||
export const withdrawEnergy = (target: StructureContainer | null) => createAction('transferEnergy', (creep: Creep) => {
|
||||
export const withdrawEnergy = (target: StructureContainer | StructureStorage | null) => createAction('transferEnergy', (creep: Creep) => {
|
||||
if (target == null) {
|
||||
return Fail;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
export const buildContainers = (room: Room) => {
|
||||
if ((room.controller?.level ?? 0) < 2) {
|
||||
const controller = room.controller;
|
||||
if (controller == null) {
|
||||
return;
|
||||
}
|
||||
if (controller.level < 2) {
|
||||
return;
|
||||
}
|
||||
const sources = room.find(FIND_SOURCES);
|
||||
|
|
@ -9,4 +13,17 @@ export const buildContainers = (room: Room) => {
|
|||
room.createConstructionSite(source.pos.x, source.pos.y - 2, STRUCTURE_CONTAINER);
|
||||
room.createConstructionSite(source.pos.x, source.pos.y + 2, STRUCTURE_CONTAINER);
|
||||
}
|
||||
if (controller.level < 4) {
|
||||
return;
|
||||
}
|
||||
const terrain = room.getTerrain();
|
||||
if (terrain.get(controller.pos.x, controller.pos.y - 3) !== TERRAIN_MASK_WALL) {
|
||||
room.createConstructionSite(controller.pos.x, controller.pos.y - 3, STRUCTURE_STORAGE);
|
||||
} else if (terrain.get(controller.pos.x, controller.pos.y + 3) !== TERRAIN_MASK_WALL) {
|
||||
room.createConstructionSite(controller.pos.x, controller.pos.y + 3, STRUCTURE_STORAGE);
|
||||
} else if (terrain.get(controller.pos.x - 3, controller.pos.y) !== TERRAIN_MASK_WALL) {
|
||||
room.createConstructionSite(controller.pos.x - 3, controller.pos.y, STRUCTURE_STORAGE);
|
||||
} else if (terrain.get(controller.pos.x + 3, controller.pos.y) !== TERRAIN_MASK_WALL) {
|
||||
room.createConstructionSite(controller.pos.x + 3, controller.pos.y, STRUCTURE_STORAGE);
|
||||
}
|
||||
}
|
||||
23
src/Workers/Clerk.ts
Normal file
23
src/Workers/Clerk.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import { Fail, runAction } from "../Actions/Action";
|
||||
import { harvestFromClosestActiveSource } from "../Actions/harvest";
|
||||
import { transferEnergy } from "../Actions/transferEnergy";
|
||||
import { upgradeController } from "../Actions/upgradeController";
|
||||
import { withdrawEnergy } from "../Actions/withdrawEnergy";
|
||||
import { WorkerDefinition } from "./worker";
|
||||
|
||||
export const Clerk: WorkerDefinition = {
|
||||
runAction: (creep: Creep, spawn: StructureSpawn) => runAction(creep, withdrawEnergy(creep.pos.findClosestByRange(FIND_STRUCTURES, { filter: (str: Structure) => str.structureType === STRUCTURE_CONTAINER && (str as StructureContainer).store.getUsedCapacity(RESOURCE_ENERGY) > 0 }) as StructureContainer | null))
|
||||
.or(harvestFromClosestActiveSource())
|
||||
.andThen(transferEnergy(spawn))
|
||||
.or(transferEnergy(creep.pos.findClosestByRange(FIND_MY_STRUCTURES, { filter: (structure: AnyOwnedStructure) => structure.structureType === STRUCTURE_EXTENSION && structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0}) as StructureExtension | null))
|
||||
.or(transferEnergy(creep.pos.findClosestByRange(FIND_STRUCTURES, { filter: (str: Structure) => str.structureType === STRUCTURE_STORAGE && (str as StructureStorage).store.getFreeCapacity(RESOURCE_ENERGY) > 0 }) as StructureStorage | null))
|
||||
.or(creep.room.controller ? upgradeController(creep.room.controller) : Fail)
|
||||
.repeat(),
|
||||
name: 'clerk',
|
||||
requiredCreeps: (room: Room) => 2,
|
||||
bodyDefinition: (energy: number) => [WORK].concat(new Array(Math.floor(energy / 150)).fill([MOVE, CARRY, CARRY]).reduce((x, y) => x.concat(y), [])),
|
||||
motivationalThougts: [
|
||||
"Carrying 🎒",
|
||||
"💗 working"
|
||||
]
|
||||
}
|
||||
|
|
@ -7,13 +7,18 @@ import { withdrawEnergy } from "../Actions/withdrawEnergy";
|
|||
import { WorkerDefinition } from "./worker";
|
||||
|
||||
export const Constructor: WorkerDefinition = {
|
||||
runAction: (creep: Creep) => runAction(creep, withdrawEnergy(creep.pos.findClosestByRange(FIND_STRUCTURES, { filter: (str: Structure) => str.structureType === STRUCTURE_CONTAINER && (str as StructureContainer).store.getUsedCapacity(RESOURCE_ENERGY) > 0 }) as StructureContainer | null))
|
||||
runAction: (creep: Creep) => runAction(creep, withdrawEnergy(creep.pos.findClosestByRange(FIND_STRUCTURES, { filter: (str: Structure) => str.structureType === STRUCTURE_STORAGE && (str as StructureStorage).store.getUsedCapacity(RESOURCE_ENERGY) > 0 }) as StructureStorage | null))
|
||||
.or(withdrawEnergy(creep.pos.findClosestByRange(FIND_STRUCTURES, { filter: (str: Structure) => str.structureType === STRUCTURE_CONTAINER && (str as StructureContainer).store.getUsedCapacity(RESOURCE_ENERGY) > 0 }) as StructureContainer | null))
|
||||
.or(harvestFromClosestActiveSource())
|
||||
.andThen(buildConstructionSite())
|
||||
.or(repairStructure())
|
||||
.or(creep.room.controller ? upgradeController(creep.room.controller) : Fail)
|
||||
.repeat(),
|
||||
name: 'constructor',
|
||||
requiredCreeps: (room: Room) => room.find(FIND_MY_CONSTRUCTION_SITES).length / 5 + 1,
|
||||
bodyDefinition: (energy: number) => new Array(Math.floor(energy / 250)).fill([WORK, MOVE, CARRY, CARRY]).reduce((x, y) => x.concat(y), [])
|
||||
requiredCreeps: (room: Room) => 1,
|
||||
bodyDefinition: (energy: number) => new Array(Math.floor(energy / 250)).fill([WORK, MOVE, CARRY, CARRY]).reduce((x, y) => x.concat(y), []),
|
||||
motivationalThougts: [
|
||||
"I 💗 making",
|
||||
"Fixin' 🔧"
|
||||
]
|
||||
}
|
||||
|
|
@ -9,5 +9,8 @@ export const Miner: WorkerDefinition = {
|
|||
.repeat(),
|
||||
name: 'miner',
|
||||
requiredCreeps: (room: Room) => room.find(FIND_STRUCTURES, { filter: { structureType: STRUCTURE_CONTAINER }}).length > 0 ? 4 : 0,
|
||||
bodyDefinition: (energy: number) => [WORK, WORK, MOVE, CARRY].concat(new Array(Math.floor((energy - 300) / 100)).fill(WORK))
|
||||
bodyDefinition: (energy: number) => [WORK, WORK, MOVE, CARRY].concat(new Array(Math.floor((energy - 300) / 100)).fill(WORK)),
|
||||
motivationalThougts: [
|
||||
"RocknStone"
|
||||
]
|
||||
}
|
||||
|
|
@ -6,13 +6,15 @@ import { withdrawEnergy } from "../Actions/withdrawEnergy";
|
|||
import { WorkerDefinition } from "./worker";
|
||||
|
||||
export const Upgrader: WorkerDefinition = {
|
||||
runAction: (creep: Creep, spawn: StructureSpawn) => runAction(creep, withdrawEnergy(creep.pos.findClosestByRange(FIND_STRUCTURES, { filter: (str: Structure) => str.structureType === STRUCTURE_CONTAINER && (str as StructureContainer).store.getUsedCapacity(RESOURCE_ENERGY) > 0 }) as StructureContainer | null))
|
||||
runAction: (creep: Creep, spawn: StructureSpawn) => runAction(creep, withdrawEnergy(creep.pos.findClosestByRange(FIND_STRUCTURES, { filter: (str: Structure) => str.structureType === STRUCTURE_STORAGE && (str as StructureStorage).store.getUsedCapacity(RESOURCE_ENERGY) > 0 }) as StructureStorage | null))
|
||||
.or(withdrawEnergy(creep.pos.findClosestByRange(FIND_STRUCTURES, { filter: (str: Structure) => str.structureType === STRUCTURE_CONTAINER && (str as StructureContainer).store.getUsedCapacity(RESOURCE_ENERGY) > 0 }) as StructureContainer | null))
|
||||
.or(harvestFromClosestActiveSource())
|
||||
.andThen(transferEnergy(spawn))
|
||||
.or(transferEnergy(creep.pos.findClosestByRange(FIND_MY_STRUCTURES, { filter: (structure: AnyOwnedStructure) => structure.structureType === STRUCTURE_EXTENSION && structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0}) as StructureExtension | null))
|
||||
.or(creep.room.controller ? upgradeController(creep.room.controller) : Fail)
|
||||
.andThen(creep.room.controller ? upgradeController(creep.room.controller) : Fail)
|
||||
.repeat(),
|
||||
name: 'upgrader',
|
||||
requiredCreeps: (room: Room) => 4,
|
||||
bodyDefinition: (energy: number) => new Array(Math.floor(energy / 300)).fill([WORK, WORK, MOVE, CARRY]).reduce((x, y) => x.concat(y), [])
|
||||
requiredCreeps: (room: Room) => 1,
|
||||
bodyDefinition: (energy: number) => new Array(Math.floor(energy / 300)).fill([WORK, WORK, MOVE, CARRY]).reduce((x, y) => x.concat(y), []),
|
||||
motivationalThougts: [
|
||||
'🏳️⚧️'
|
||||
]
|
||||
}
|
||||
|
|
@ -2,13 +2,17 @@ export interface WorkerDefinition {
|
|||
runAction: (creep: Creep, spawn: StructureSpawn) => void,
|
||||
name: string,
|
||||
requiredCreeps: (room: Room) => number,
|
||||
bodyDefinition: (energy: number, spawn: StructureSpawn) => BodyPartConstant[]
|
||||
bodyDefinition: (energy: number, spawn: StructureSpawn) => BodyPartConstant[],
|
||||
motivationalThougts?: Array<string>
|
||||
}
|
||||
|
||||
export const spawnWorkers = (spawn: StructureSpawn, workers: WorkerDefinition[]): void => {
|
||||
for (const worker of workers) {
|
||||
for (let i = 0; i < worker.requiredCreeps(spawn.room); i++) {
|
||||
const ret = spawn.spawnCreep(worker.bodyDefinition(spawn.store.getCapacity(RESOURCE_ENERGY) + spawn.room.find(FIND_MY_STRUCTURES, { filter: { structureType: STRUCTURE_EXTENSION }}).length * 50, spawn), worker.name + i.toString());
|
||||
if (ret === OK || ret === ERR_NOT_ENOUGH_ENERGY) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -16,8 +20,14 @@ export const spawnWorkers = (spawn: StructureSpawn, workers: WorkerDefinition[])
|
|||
export const runWorkers = (spawn: StructureSpawn, workers: WorkerDefinition[]): void => {
|
||||
for (const worker of workers) {
|
||||
for (const creep of Object.values(Game.creeps)) {
|
||||
if (creep.spawning) {
|
||||
continue;
|
||||
}
|
||||
if (creep.name.startsWith(worker.name)) {
|
||||
worker.runAction(creep, spawn);
|
||||
if (worker.motivationalThougts != null && Math.random() < 0.1) {
|
||||
creep.say(worker.motivationalThougts[Math.floor(worker.motivationalThougts.length * Math.random())], true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import { upgradeController } from "./Actions/upgradeController";
|
|||
import { buildContainers } from "./RoomPlanner/Blueprints/Containers";
|
||||
import { buildExtentions } from "./RoomPlanner/Blueprints/Extensions";
|
||||
import { buildRoads } from "./RoomPlanner/Blueprints/Roads";
|
||||
import { Clerk } from "./Workers/Clerk";
|
||||
import { Constructor } from "./Workers/Constructor";
|
||||
import { Miner } from "./Workers/Miner";
|
||||
import { Upgrader } from "./Workers/Upgrader";
|
||||
|
|
@ -17,7 +18,7 @@ export function loop() {
|
|||
if (!controller) {
|
||||
return;
|
||||
}
|
||||
const workerTypes = [Upgrader, Miner, Constructor];
|
||||
const workerTypes = [Clerk, Upgrader, Miner, Constructor];
|
||||
spawnWorkers(spawn, workerTypes);
|
||||
runWorkers(spawn, workerTypes);
|
||||
if (Game.time % 100 === 0) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue