Created
August 25, 2015 23:16
-
-
Save new-guy/59f5e6f630cf5b3da520 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getCachedPath(originPosition, destinationPosition) | |
{ | |
var originString = originPosition.roomName + "x" + originPosition.x + "y" + originPosition.y; | |
var destinationString = destinationPosition.roomName + "x" + destinationPosition.x + "y" + destinationPosition.y; | |
if(Memory.pathCache === undefined) | |
{ | |
Memory.pathCache = {}; | |
} | |
if(Memory.pathCache[originString] === undefined) | |
{ | |
Memory.pathCache[originString] = {}; | |
} | |
if(Memory.pathCache[originString][destinationString] === undefined || Memory.pathCache[originString][destinationString].length === 0) | |
{ | |
Memory.pathCache[originString][destinationString] = originPosition.findPathTo(destinationPosition, {ignoreCreeps: true}); | |
//console.log('Generating path to ' + destinationString + ' from ' + originString + ' length: ' + Memory.pathCache[originString][destinationString].length); | |
} | |
else | |
{ | |
//console.log('Cache hit to ' + destinationString + ' from ' + originString + " " + Memory.pathCache[originString][destinationString].length); | |
} | |
return Memory.pathCache[originString][destinationString]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment