Skip to content

Instantly share code, notes, and snippets.

@Hernanduer
Created September 23, 2015 22:20
Show Gist options
  • Save Hernanduer/d54a72fb551d05edfa23 to your computer and use it in GitHub Desktop.
Save Hernanduer/d54a72fb551d05edfa23 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