Last active
August 29, 2015 14:28
-
-
Save vanhouc/234969a97e5390eaf8d6 to your computer and use it in GitHub Desktop.
Find pathable tiles
This file contains 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
findPathableAround(target: RoomPosition): RoomPosition[] | |
findPathableAround(target: { pos: RoomPosition }): RoomPosition[] | |
findPathableAround(target: any, ignoreCreeps: boolean = false): RoomPosition[] { | |
var pos: RoomPosition = target.pos ? target.pos : target; | |
var room = Game.rooms[pos.roomName]; | |
var pathableTiles: RoomPosition[] = []; | |
var area = room.lookAtArea(pos.y - 1, pos.x - 1, pos.y + 1, pos.x + 1); | |
for (var x in area) { | |
for (var y in area[x]) { | |
var results: LookAtResult[] = y; | |
if (!results.some(lookAt => | |
lookAt.type === "constructionSite" || | |
lookAt.type === "exit" || | |
lookAt.type === "source" || | |
lookAt.type === "structure" || | |
(ignoreCreeps ? true : lookAt.type === "creep") || | |
lookAt.type === "terrain" && | |
lookAt.terrain !== "normal" && | |
lookAt.terrain !== "swamp")) { | |
pathableTiles.push(room.getPositionAt(x, y)); | |
} | |
} | |
} | |
return pathableTiles; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment