更大的收集者收集逻辑, Container获取逻辑
This commit is contained in:
parent
182e672086
commit
57277eff2d
@ -20,7 +20,7 @@ export const loop = errorMapper(() => {
|
|||||||
} else if (creep.memory.role == "Upgrader") {
|
} else if (creep.memory.role == "Upgrader") {
|
||||||
Upgrade(creep);
|
Upgrade(creep);
|
||||||
} else if (creep.memory.role == "Builder") {
|
} else if (creep.memory.role == "Builder") {
|
||||||
Build(creep, STRUCTURE_CONTAINER);
|
Build(creep);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
@ -1,5 +1,5 @@
|
|||||||
import { MAIN_SOURCE_ID } from "./setting";
|
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) {
|
export function Build(creep: Creep, structureType: string | null = null) {
|
||||||
if (creep.memory.working && creep.store[RESOURCE_ENERGY] == 0) {
|
if (creep.memory.working && creep.store[RESOURCE_ENERGY] == 0) {
|
||||||
@ -27,9 +27,9 @@ export function Build(creep: Creep, structureType: string | null = null) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
creep.memory.working = false
|
creep.memory.working = false
|
||||||
let source = GetSource(MAIN_SOURCE_ID);
|
var target = GetContainer(creep);
|
||||||
if (creep.harvest(source) == ERR_NOT_IN_RANGE) {
|
if (creep.withdraw(target[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
||||||
creep.moveTo(source, { visualizePathStyle: { stroke: "#ffaa00" } });
|
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";
|
import { MAIN_SOURCE_ID } from "./setting";
|
||||||
|
|
||||||
export function Harvest(creep: Creep) {
|
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);
|
let source: Source = GetSource(MAIN_SOURCE_ID);
|
||||||
if (creep.harvest(source) == ERR_NOT_IN_RANGE) {
|
if (creep.harvest(source) == ERR_NOT_IN_RANGE) {
|
||||||
creep.moveTo(source, { visualizePathStyle: { stroke: "#ffaa00" } });
|
creep.moveTo(source, { visualizePathStyle: { stroke: "#ffaa00" } });
|
||||||
@ -10,9 +13,18 @@ export function Harvest(creep: Creep) {
|
|||||||
} else {
|
} else {
|
||||||
let targets = FindCapacity(creep);
|
let targets = FindCapacity(creep);
|
||||||
if (targets.length > 0) {
|
if (targets.length > 0) {
|
||||||
if(creep.transfer(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE){
|
if (creep.transfer(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
||||||
creep.moveTo(targets[0], { visualizePathStyle: { stroke: "#ffffff" } });
|
creep.moveTo(targets[0], { visualizePathStyle: { stroke: "#ffffff" } });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 HARVESTER_COUNT: number = 0;
|
||||||
let BUILDER_COUNT: number = 3;
|
let BUILDER_COUNT: number = 1;
|
||||||
let UPGRADER_COUNT: number = 5;
|
let UPGRADER_COUNT: number = 6;
|
||||||
|
|
||||||
let MAIN_SOURCE_ID: Id<Source> = "ef990774d80108c" as Id<Source>;
|
let MAIN_SOURCE_ID: Id<Source> = "ef990774d80108c" as Id<Source>;
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { MAIN_SOURCE_ID } from "./setting";
|
import { MAIN_SOURCE_ID } from "./setting";
|
||||||
import { GetSource } from "./util";
|
import { GetContainer, GetSource } from "./util";
|
||||||
|
|
||||||
/**@param {Creep} creep */
|
/**@param {Creep} creep */
|
||||||
export function Upgrade(creep: Creep) {
|
export function Upgrade(creep: Creep) {
|
||||||
if (creep.memory.working && creep.store[RESOURCE_ENERGY] == 0) {
|
if (creep.memory.working && creep.store[RESOURCE_ENERGY] == 0) {
|
||||||
creep.memory.working = false;
|
creep.memory.working = false;
|
||||||
creep.say('🔄 harvest');
|
creep.say('🔄 carry');
|
||||||
}
|
}
|
||||||
if (!creep.memory.working && creep.store.getFreeCapacity() == 0) {
|
if (!creep.memory.working && creep.store.getFreeCapacity() == 0) {
|
||||||
creep.memory.working = true;
|
creep.memory.working = true;
|
||||||
@ -18,9 +18,9 @@ export function Upgrade(creep: Creep) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var source = GetSource(MAIN_SOURCE_ID);
|
var target = GetContainer(creep);
|
||||||
if (creep.harvest(source) == ERR_NOT_IN_RANGE) {
|
if (creep.withdraw(target[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
||||||
creep.moveTo(source, { visualizePathStyle: { stroke: '#ffaa00' } });
|
creep.moveTo(target[0], { visualizePathStyle: { stroke: '#ffaa00' } });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,7 +4,8 @@ export function FindCapacity(creep: Creep): AnyStructure[] {
|
|||||||
let type = structure.structureType;
|
let type = structure.structureType;
|
||||||
return (
|
return (
|
||||||
(type == STRUCTURE_EXTENSION ||
|
(type == STRUCTURE_EXTENSION ||
|
||||||
type == STRUCTURE_SPAWN) &&
|
type == STRUCTURE_SPAWN||
|
||||||
|
type == STRUCTURE_CONTAINER) &&
|
||||||
structure.store.getFreeCapacity(RESOURCE_ENERGY) as number > 0
|
structure.store.getFreeCapacity(RESOURCE_ENERGY) as number > 0
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -22,4 +23,15 @@ export function GetConstructureSet(creep: Creep, structureType: string | null =
|
|||||||
return structure.structureType == structureType;
|
return structure.structureType == structureType;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
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