From 54df920ba159842fb13c5a984976e83de933789f Mon Sep 17 00:00:00 2001 From: JIe Date: Mon, 4 Nov 2024 16:59:12 +0800 Subject: [PATCH] =?UTF-8?q?carry=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/carry.ts | 20 ++++++++++++++++++++ src/modules/creepApi.ts | 2 +- src/modules/setting.ts | 3 +++ src/modules/spawnCreep.ts | 9 +++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/modules/carry.ts diff --git a/src/modules/carry.ts b/src/modules/carry.ts new file mode 100644 index 0000000..c5e617d --- /dev/null +++ b/src/modules/carry.ts @@ -0,0 +1,20 @@ +import * as creepApi from "./creepApi" + + +export function Carry(creep: Creep) { + var containers = creepApi.GetContainer(creep); + var targets = creepApi.GetConstructure(creep, STRUCTURE_EXTENSION); + if (creep.store.getFreeCapacity(RESOURCE_ENERGY) > 0) { + for (var container of containers) { + if (container.store.getFreeCapacity(RESOURCE_ENERGY) == 0) { + if (creep.withdraw(container, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { + creep.moveTo(container, { visualizePathStyle: { stroke: "#00ffxx" } }); + } + } + } + } else { + if (creep.transfer(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { + creep.moveTo(targets[0], { visualizePathStyle: { stroke: "#00ffxx" } }); + } + } +} \ No newline at end of file diff --git a/src/modules/creepApi.ts b/src/modules/creepApi.ts index 83b96a8..1ff6d25 100644 --- a/src/modules/creepApi.ts +++ b/src/modules/creepApi.ts @@ -31,7 +31,7 @@ export function RoleToString(role: Role): string { export function SpawnCreep(spawn: StructureSpawn, body: Part[], opt?: SpawnOptions): number { const name = "Creep" + Game.time; - return spawn.spawnCreep(body, name, opt);//{ memory: { role: RoleToString(role) } }); + return spawn.spawnCreep(body, name, opt); } export function FindCapacity(creep: Creep): AnyStructure[] { diff --git a/src/modules/setting.ts b/src/modules/setting.ts index 7e6b50d..fe7d1b2 100644 --- a/src/modules/setting.ts +++ b/src/modules/setting.ts @@ -1,6 +1,7 @@ export let HARVESTER_COUNT: number = 0; export let BUILDER_COUNT: number = 1; export let UPGRADER_COUNT: number = 4; +export let CARRYER_COUNT: number = 2; export let MAIN_SOURCE_ID: Id = "ef990774d80108c" as Id; export const enum Role { @@ -9,8 +10,10 @@ export const enum Role { Builder, Upgrader, Repairer, + Carryer, } export let mk1Body: Part[] = [WORK, CARRY, MOVE]; export let mk2Body: Part[] = [WORK, WORK, CARRY, CARRY, MOVE, MOVE]; +export let mk1CarryerBody: Part[] = [CARRY, CARRY, MOVE, MOVE]; export let Mk2harvesterBody: Part[] = [WORK, WORK, WORK, WORK, MOVE]; diff --git a/src/modules/spawnCreep.ts b/src/modules/spawnCreep.ts index aa31273..2a9252e 100644 --- a/src/modules/spawnCreep.ts +++ b/src/modules/spawnCreep.ts @@ -16,6 +16,10 @@ const createMk2Harvester = (spawn: StructureSpawn, container: StructureContainer return creepApi.SpawnCreep(spawn, setting.Mk2harvesterBody, { memory: { role: creepApi.RoleToString(setting.Role.BigHarvester), workTarget: container.id } }); } +const createMk1Carryer = (spawn: StructureSpawn) => { + return creepApi.SpawnCreep(spawn, setting.mk1CarryerBody, { memory: { role: creepApi.RoleToString(setting.Role.Carryer) } }); +} + export function SpawnCreep(spawn: StructureSpawn) { if (spawn.spawning) return; @@ -36,6 +40,11 @@ export function SpawnCreep(spawn: StructureSpawn) { console.log("Spawn Builder") } } + if (currentCreeps.get(creepApi.RoleToString(setting.Role.Carryer)) < setting.CARRYER_COUNT) { + if (createMk1Carryer(spawn) == 0) { + console.log("Spawn Carryer") + } + } if (currentCreeps.get(creepApi.RoleToString(setting.Role.BigHarvester)) < currentContainer.length) { for (var structure of Memory.structures) { if (structure.structureType == STRUCTURE_CONTAINER && structure.creep == null)