你如何用转移能量(蠕变)来瞄准房间控制器

How do you target the room controller with transferEnergy(creep)

本文关键字:房间 控制器 蠕变 何用 转移 能量      更新时间:2023-09-26

就像标题所说的那样。我已经尝试了很多不同的方式,但"爬行。transferenergy (Game.controller);"是唯一一个没有返回错误。

我很确定transferEnergy()不适合控制器,这里是我发现的代码,用于升级过程的简单自动化。

if(creep.carry.energy < creep.carryCapacity) {
    var sources = creep.room.find(FIND_SOURCES);
    creep.moveTo(sources[0]);
    creep.harvest(sources[0]);
} 
else {
    creep.moveTo(creep.room.controller);
    creep.upgradeController(creep.room.controller)
}

我遇到了真正的麻烦。所提供的答案确实是你想要的,但是……每个游戏标记检查当前蠕变所携带的能量水平是否低于当前蠕变所能承受的能力。

所以,升级一次后,第一次检查,使蠕变寻求能量。你的线人可能在很远的地方。我们要做的是耗尽当前存储的能量,然后在空的时候寻找能量。

    if(creep.memory.upgrader && creep.carry.energy == 0) {
        creep.memory.upgrader = false;
    }
    if(!creep.memory.upgrader && creep.carry.energy == creep.carryCapacity) {
        creep.memory.upgrader = true;
    }
    if(creep.memory.upgrader) {
        if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
            creep.moveTo(creep.room.controller);
        }
    } else {
            var source = creep.pos.findClosestByRange(FIND_SOURCES);
            if(creep.harvest(source) == ERR_NOT_IN_RANGE) {
                creep.moveTo(source);
            }
        }
    }
};

也增加了一个检查最近的来源范围。这将返回最接近爬虫当前位置的源。