Skip to content

Instantly share code, notes, and snippets.

@vanhouc
Last active August 29, 2015 14:28
Show Gist options
  • Save vanhouc/234969a97e5390eaf8d6 to your computer and use it in GitHub Desktop.
Save vanhouc/234969a97e5390eaf8d6 to your computer and use it in GitHub Desktop.
Find pathable tiles
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