所以我有一个叫做蠕变的角色storer
,它应该从容器中获取能量并将其带到存储中。然而,目前,它会找到最接近 Path 且能量水平大于某个阈值的容器,因此它不会在矿工每次重新填充容器时在那里等待数小时。
我遇到的问题是,如果我降低阈值,storer
它将在同一个容器中来回运行,忽略房间内更远的任何容器并让它们填满。
而提高门槛会让他坐在那里等太久,没有给他足够的时间来清空容器,因此储藏室几乎一直都是空的。
我需要一种方法让蠕变确定具有最高能量的容器并从那里填充。
这是它运行的代码:
if ((source = creep.pos.findClosestByPath(FIND_STRUCTURES, {filter: (s) => {return (s.structureType == STRUCTURE_CONTAINER && s.store[RESOURCE_ENERGY] >= 150)}})) != undefined) {
if (creep.withdraw(source, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(source);
}
}
编辑:这是我尝试过的代码,但我觉得它使用了太多的 CPU 能力并且可以以更好的方式完成:
for (let i = 2000; i>=0; i=i-100) {
source = creep.pos.findClosestByPath(FIND_STRUCTURES, {filter: (s) => {return s.structureType == STRUCTURE_CONTAINER && s.store[RESOURCE_ENERGY] >= i}});
if (source != undefined) {
break;
}
}
if (creep.withdraw(source, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(source);
}
}