Skip to content

Instantly share code, notes, and snippets.

@Dessix
Forked from Hernanduer/findNearestStorage.js
Last active September 23, 2015 22:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dessix/260308e3f0a5d9cb8ec4 to your computer and use it in GitHub Desktop.
Save Dessix/260308e3f0a5d9cb8ec4 to your computer and use it in GitHub Desktop.
Creep.prototype.findNearestStorage: function() {
var pref = undefined;
if (this.room.storage != undefined) {
pref = this.room.storage;
}
for (var link in this.room.memory.energy.linkSources) {
var l = Game.getObjectById(link);
if (l != null && this.pos.getRangeTo(pref) > this.pos.getRangeTo(l)) {
pref = l;
}
}
if (pref == undefined || pref == null) {
return this.findClosestByRange(this.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