carry逻辑
This commit is contained in:
parent
2df2a171e7
commit
54df920ba1
20
src/modules/carry.ts
Normal file
20
src/modules/carry.ts
Normal file
@ -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" } });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -31,7 +31,7 @@ export function RoleToString(role: Role): string {
|
|||||||
|
|
||||||
export function SpawnCreep(spawn: StructureSpawn, body: Part[], opt?: SpawnOptions): number {
|
export function SpawnCreep(spawn: StructureSpawn, body: Part[], opt?: SpawnOptions): number {
|
||||||
const name = "Creep" + Game.time;
|
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[] {
|
export function FindCapacity(creep: Creep): AnyStructure[] {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
export let HARVESTER_COUNT: number = 0;
|
export let HARVESTER_COUNT: number = 0;
|
||||||
export let BUILDER_COUNT: number = 1;
|
export let BUILDER_COUNT: number = 1;
|
||||||
export let UPGRADER_COUNT: number = 4;
|
export let UPGRADER_COUNT: number = 4;
|
||||||
|
export let CARRYER_COUNT: number = 2;
|
||||||
|
|
||||||
export let MAIN_SOURCE_ID: Id<Source> = "ef990774d80108c" as Id<Source>;
|
export let MAIN_SOURCE_ID: Id<Source> = "ef990774d80108c" as Id<Source>;
|
||||||
export const enum Role {
|
export const enum Role {
|
||||||
@ -9,8 +10,10 @@ export const enum Role {
|
|||||||
Builder,
|
Builder,
|
||||||
Upgrader,
|
Upgrader,
|
||||||
Repairer,
|
Repairer,
|
||||||
|
Carryer,
|
||||||
}
|
}
|
||||||
|
|
||||||
export let mk1Body: Part[] = [WORK, CARRY, MOVE];
|
export let mk1Body: Part[] = [WORK, CARRY, MOVE];
|
||||||
export let mk2Body: Part[] = [WORK, WORK, CARRY, CARRY, MOVE, 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];
|
export let Mk2harvesterBody: Part[] = [WORK, WORK, WORK, WORK, MOVE];
|
||||||
|
@ -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 } });
|
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) {
|
export function SpawnCreep(spawn: StructureSpawn) {
|
||||||
if (spawn.spawning) return;
|
if (spawn.spawning) return;
|
||||||
|
|
||||||
@ -36,6 +40,11 @@ export function SpawnCreep(spawn: StructureSpawn) {
|
|||||||
console.log("Spawn Builder")
|
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) {
|
if (currentCreeps.get(creepApi.RoleToString(setting.Role.BigHarvester)) < currentContainer.length) {
|
||||||
for (var structure of Memory.structures) {
|
for (var structure of Memory.structures) {
|
||||||
if (structure.structureType == STRUCTURE_CONTAINER && structure.creep == null)
|
if (structure.structureType == STRUCTURE_CONTAINER && structure.creep == null)
|
||||||
|
Loading…
Reference in New Issue
Block a user