【问题标题】:Finding closest creep to a given creep寻找最接近给定蠕变的蠕变
【发布时间】:2017-02-07 17:38:43
【问题描述】:

很难找到最接近小兵的小兵,因为它必须有一组特定的角色并且必须没有指定的伙伴。

这是为了设置专用矿工和专用能源载体(它们必须找到最近的矿工或收割机并携带它们的能量)。

我试过了(其中cree变量是运行脚本的cree):

var nearestMinerCreep = creep.pos.findNearest(Game.MY_CREEPS, {
                filter: function(creep) {
                    return (creep.memory.role == "miner" 
                    || creep.memory.role == "harvester") 
                    && !creep.memory.partner;
                }
            });

但 findNearest() 似乎已被贬低。用 findClosestByPath() 和 findClosestByRange() 的变体替换它也不起作用。我能做的最好的就是用这个来获得一个cree的位置:

var nearestPos = (creep.pos.findfindClosestByPath(FIND_MY_CREEPS)).pos;

但是由于需要转移能量,这是未经过滤的,并且不够具体。提前感谢您的帮助!

【问题讨论】:

    标签: screeps


    【解决方案1】:

    Game.MY_CREEPS 不是一个正确的常数,所以我认为这可能是问题的一部分。

    API 中所写,pos.findClosestByPath 接受额外的参数,包括过滤功能。所以正确的代码可能是

     let nMCreep = creep.pos.findClosestByPath(FIND_MY_CREEPS, {
       filter: function(creep) {
         return (creep.memory.role == "miner" 
           || creep.memory.role == "harvester") 
         && !creep.memory.partner;
       }
     });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-16
      • 2015-01-19
      • 1970-01-01
      • 2018-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多