Skip to content

Instantly share code, notes, and snippets.

@Hernanduer
Created September 23, 2015 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Hernanduer/24a022efaa5795b50326 to your computer and use it in GitHub Desktop.
Save Hernanduer/24a022efaa5795b50326 to your computer and use it in GitHub Desktop.
findNearestStorage: function(creep) {
var pref = undefined;
if (creep.room.storage != undefined)
pref = creep.room.storage;
for (var link in creep.room.memory.energy.linkSources) {
var l = Game.getObjectById(link);
if (l != null && creep.pos.getRangeTo(pref) > creep.pos.getRangeTo(l))
pref = l;
}
if (pref == undefined || pref == null)
return this.findClosest(creep, creep.room.memory.structs.spawns, true);
else
return pref.id;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment