更大的收集者收集逻辑, Container获取逻辑
This commit is contained in:
parent
182e672086
commit
57277eff2d
@ -20,7 +20,7 @@ export const loop = errorMapper(() => {
|
||||
} else if (creep.memory.role == "Upgrader") {
|
||||
Upgrade(creep);
|
||||
} else if (creep.memory.role == "Builder") {
|
||||
Build(creep, STRUCTURE_CONTAINER);
|
||||
Build(creep);
|
||||
}
|
||||
}
|
||||
})
|
@ -1,5 +1,5 @@
|
||||
import { MAIN_SOURCE_ID } from "./setting";
|
||||
import { FindCapacity, GetConstructureSet, GetSource } from "./util";
|
||||
import { FindCapacity, GetConstructureSet, GetContainer, GetSource } from "./util";
|
||||
|
||||
export function Build(creep: Creep, structureType: string | null = null) {
|
||||
if (creep.memory.working && creep.store[RESOURCE_ENERGY] == 0) {
|
||||
@ -27,9 +27,9 @@ export function Build(creep: Creep, structureType: string | null = null) {
|
||||
}
|
||||
} else {
|
||||
creep.memory.working = false
|
||||
let source = GetSource(MAIN_SOURCE_ID);
|
||||
if (creep.harvest(source) == ERR_NOT_IN_RANGE) {
|
||||
creep.moveTo(source, { visualizePathStyle: { stroke: "#ffaa00" } });
|
||||
var target = GetContainer(creep);
|
||||
if (creep.withdraw(target[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
||||
creep.moveTo(target[0], { visualizePathStyle: { stroke: '#ffaa00' } });
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +1,11 @@
|
||||
import { FindCapacity, GetSource } from "./util"
|
||||
import { FindCapacity, GetContainer, GetSource } from "./util"
|
||||
import { MAIN_SOURCE_ID } from "./setting";
|
||||
|
||||
export function Harvest(creep: Creep) {
|
||||
if (creep.store.getFreeCapacity() > 0) {
|
||||
if (creep.store.getFreeCapacity() == null) {
|
||||
BigHarvest(creep);
|
||||
}
|
||||
else if (creep.store.getFreeCapacity() > 0) {
|
||||
let source: Source = GetSource(MAIN_SOURCE_ID);
|
||||
if (creep.harvest(source) == ERR_NOT_IN_RANGE) {
|
||||
creep.moveTo(source, { visualizePathStyle: { stroke: "#ffaa00" } });
|
||||
@ -16,3 +19,12 @@ export function Harvest(creep: Creep) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function BigHarvest(creep: Creep) {
|
||||
let source: Source = GetSource(MAIN_SOURCE_ID);
|
||||
let container = GetContainer(creep);
|
||||
if (container[0].store.getFreeCapacity(RESOURCE_ENERGY) == 0) { }
|
||||
else if (creep.harvest(source) == ERR_NOT_IN_RANGE) {
|
||||
creep.moveTo(container[0], { visualizePathStyle: { stroke: "#ffaa00" } });
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
let HARVESTER_COUNT: number = 2;
|
||||
let BUILDER_COUNT: number = 3;
|
||||
let UPGRADER_COUNT: number = 5;
|
||||
let HARVESTER_COUNT: number = 0;
|
||||
let BUILDER_COUNT: number = 1;
|
||||
let UPGRADER_COUNT: number = 6;
|
||||
|
||||
let MAIN_SOURCE_ID: Id<Source> = "ef990774d80108c" as Id<Source>;
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { MAIN_SOURCE_ID } from "./setting";
|
||||
import { GetSource } from "./util";
|
||||
import { GetContainer, GetSource } from "./util";
|
||||
|
||||
/**@param {Creep} creep */
|
||||
export function Upgrade(creep: Creep) {
|
||||
if (creep.memory.working && creep.store[RESOURCE_ENERGY] == 0) {
|
||||
creep.memory.working = false;
|
||||
creep.say('🔄 harvest');
|
||||
creep.say('🔄 carry');
|
||||
}
|
||||
if (!creep.memory.working && creep.store.getFreeCapacity() == 0) {
|
||||
creep.memory.working = true;
|
||||
@ -18,9 +18,9 @@ export function Upgrade(creep: Creep) {
|
||||
}
|
||||
}
|
||||
else {
|
||||
var source = GetSource(MAIN_SOURCE_ID);
|
||||
if (creep.harvest(source) == ERR_NOT_IN_RANGE) {
|
||||
creep.moveTo(source, { visualizePathStyle: { stroke: '#ffaa00' } });
|
||||
var target = GetContainer(creep);
|
||||
if (creep.withdraw(target[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
||||
creep.moveTo(target[0], { visualizePathStyle: { stroke: '#ffaa00' } });
|
||||
}
|
||||
}
|
||||
}
|
@ -4,7 +4,8 @@ export function FindCapacity(creep: Creep): AnyStructure[] {
|
||||
let type = structure.structureType;
|
||||
return (
|
||||
(type == STRUCTURE_EXTENSION ||
|
||||
type == STRUCTURE_SPAWN) &&
|
||||
type == STRUCTURE_SPAWN||
|
||||
type == STRUCTURE_CONTAINER) &&
|
||||
structure.store.getFreeCapacity(RESOURCE_ENERGY) as number > 0
|
||||
)
|
||||
}
|
||||
@ -23,3 +24,14 @@ export function GetConstructureSet(creep: Creep, structureType: string | null =
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export function GetConstructure(creep: Creep, structureType: string, ){
|
||||
return creep.room.find(FIND_STRUCTURES, {filter:(structure: AnyStructure)=>{
|
||||
return structure.structureType == structureType;
|
||||
}})
|
||||
}
|
||||
|
||||
export function GetContainer(creep: Creep): StructureContainer[]{
|
||||
let target = GetConstructure(creep, STRUCTURE_CONTAINER) as StructureContainer[];
|
||||
return target
|
||||
}
|
Loading…
Reference in New Issue
Block a user