61public final class TraversalMap {
63 private TraversalMap() {}
81 Position position =
object.getPosition();
95 if (
object.getObjectType() == GROUND_PROP) {
96 if (def.hasActions() || def.isDecoration()) {
97 if (def.hasActions()) {
98 markOccupant(region, position.getHeight(), position.getX(), position.getY(), sizeX, sizeY,
false, add);
101 }
else if (
object.getObjectType() == GENERAL_PROP ||
object.getObjectType() == WALKABLE_PROP) {
103 }
else if (
object.getObjectType().getId() >= 12) {
105 }
else if (
object.getObjectType() == DIAGONAL_WALL) {
107 }
else if (
object.getObjectType().getId() >= 0 &&
object.getObjectType().getId() <= 3) {
109 markWall(region,
object.getDirection(), position.getHeight(), position.getX(), position.getY(),
object.getObjectType(), def.
isImpenetrable());
111 unmarkWall(region,
object.getDirection(), position.getHeight(), position.getX(), position.getY(),
object.getObjectType(), def.
isImpenetrable());
115 if (list && (
object.getId() == 11700 ||
object.getDefinition().hasActions())) {
116 if (add) region.addObject(
object);
117 else region.removeObject(
object);
142 if (orientation == ObjectDirection.NORTH) {
143 set(reg, height, x, y, TraversalConstants.WALL_NORTH);
144 set(reg, height, x, y + 1, TraversalConstants.WALL_SOUTH);
146 set(reg, height, x, y, TraversalConstants.IMPENETRABLE_WALL_NORTH);
147 set(reg, height, x, y + 1, TraversalConstants.IMPENETRABLE_WALL_SOUTH);
150 if (orientation == ObjectDirection.EAST) {
151 set(reg, height, x, y, TraversalConstants.WALL_EAST);
152 set(reg, height, x + 1, y, TraversalConstants.WALL_WEST);
154 set(reg, height, x, y, TraversalConstants.IMPENETRABLE_WALL_EAST);
155 set(reg, height, x + 1, y, TraversalConstants.IMPENETRABLE_WALL_WEST);
158 if (orientation == ObjectDirection.SOUTH) {
159 set(reg, height, x, y, TraversalConstants.WALL_SOUTH);
160 set(reg, height, x, y - 1, TraversalConstants.WALL_NORTH);
162 set(reg, height, x, y, TraversalConstants.IMPENETRABLE_WALL_SOUTH);
163 set(reg, height, x, y - 1, TraversalConstants.IMPENETRABLE_WALL_NORTH);
169 if (orientation == ObjectDirection.WEST) {
170 set(reg, height, x, y, TraversalConstants.WALL_WEST | TraversalConstants.WALL_NORTH);
171 set(reg, height, x - 1, y, TraversalConstants.WALL_EAST);
172 set(reg, height, x, y + 1, TraversalConstants.WALL_SOUTH);
174 set(reg, height, x, y, TraversalConstants.IMPENETRABLE_WALL_WEST | TraversalConstants.IMPENETRABLE_WALL_NORTH);
175 set(reg, height, x - 1, y, TraversalConstants.IMPENETRABLE_WALL_EAST);
176 set(reg, height, x, y + 1, TraversalConstants.IMPENETRABLE_WALL_SOUTH);
179 if (orientation == ObjectDirection.NORTH) {
180 set(reg, height, x, y, TraversalConstants.WALL_EAST | TraversalConstants.WALL_NORTH);
181 set(reg, height, x, y + 1, TraversalConstants.WALL_SOUTH);
182 set(reg, height, x + 1, y, TraversalConstants.WALL_WEST);
184 set(reg, height, x, y, TraversalConstants.IMPENETRABLE_WALL_EAST | TraversalConstants.IMPENETRABLE_WALL_NORTH);
185 set(reg, height, x, y + 1, TraversalConstants.IMPENETRABLE_WALL_SOUTH);
186 set(reg, height, x + 1, y, TraversalConstants.IMPENETRABLE_WALL_WEST);
189 if (orientation == ObjectDirection.EAST) {
190 set(reg, height, x, y, TraversalConstants.WALL_EAST | TraversalConstants.WALL_SOUTH);
191 set(reg, height, x + 1, y, TraversalConstants.WALL_WEST);
192 set(reg, height, x, y - 1, TraversalConstants.WALL_NORTH);
194 set(reg, height, x, y, TraversalConstants.IMPENETRABLE_WALL_EAST | TraversalConstants.IMPENETRABLE_WALL_SOUTH);
195 set(reg, height, x + 1, y, TraversalConstants.IMPENETRABLE_WALL_WEST);
196 set(reg, height, x, y - 1, TraversalConstants.IMPENETRABLE_WALL_NORTH);
199 if (orientation == ObjectDirection.SOUTH) {
200 set(reg, height, x, y, TraversalConstants.WALL_WEST | TraversalConstants.WALL_SOUTH);
201 set(reg, height, x - 1, y, TraversalConstants.WALL_EAST);
202 set(reg, height, x, y - 1, TraversalConstants.WALL_NORTH);
204 set(reg, height, x, y, TraversalConstants.IMPENETRABLE_WALL_WEST | TraversalConstants.IMPENETRABLE_WALL_SOUTH);
205 set(reg, height, x - 1, y, TraversalConstants.IMPENETRABLE_WALL_EAST);
206 set(reg, height, x, y - 1, TraversalConstants.IMPENETRABLE_WALL_NORTH);
211 case DIAGONAL_CORNER_WALL:
213 if (orientation == ObjectDirection.WEST) {
214 set(reg, height, x, y, TraversalConstants.WALL_NORTH_WEST);
215 set(reg, height, x - 1, y + 1, TraversalConstants.WALL_SOUTH_EAST);
217 set(reg, height, x, y, TraversalConstants.IMPENETRABLE_WALL_NORTH_WEST);
218 set(reg, height, x - 1, y + 1, TraversalConstants.IMPENETRABLE_WALL_SOUTH_EAST);
221 if (orientation == ObjectDirection.NORTH) {
222 set(reg, height, x, y, TraversalConstants.WALL_NORTH_EAST);
223 set(reg, height, x + 1, y + 1, TraversalConstants.WALL_SOUTH_WEST);
225 set(reg, height, x, y, TraversalConstants.IMPENETRABLE_WALL_NORTH_EAST);
226 set(reg, height, x + 1, y + 1, TraversalConstants.IMPENETRABLE_WALL_SOUTH_WEST);
229 if (orientation == ObjectDirection.EAST) {
230 set(reg, height, x, y, TraversalConstants.WALL_SOUTH_EAST);
231 set(reg, height, x + 1, y - 1, TraversalConstants.WALL_NORTH_WEST);
233 set(reg, height, x, y, TraversalConstants.IMPENETRABLE_WALL_SOUTH_EAST);
234 set(reg, height, x + 1, y - 1, TraversalConstants.IMPENETRABLE_WALL_NORTH_WEST);
237 if (orientation == ObjectDirection.SOUTH) {
238 set(reg, height, x, y, TraversalConstants.WALL_SOUTH_WEST);
239 set(reg, height, x - 1, y - 1, TraversalConstants.WALL_NORTH_EAST);
241 set(reg, height, x, y, TraversalConstants.IMPENETRABLE_WALL_SOUTH_WEST);
242 set(reg, height, x - 1, y - 1, TraversalConstants.IMPENETRABLE_WALL_NORTH_EAST);
261 private static void unmarkWall(Region reg, ObjectDirection orientation,
int height,
int x,
int y, ObjectType type,
boolean impenetrable) {
264 if (orientation == ObjectDirection.WEST) {
265 unset(reg, height, x, y, TraversalConstants.WALL_WEST);
266 unset(reg, height, x - 1, y, TraversalConstants.WALL_EAST);
268 unset(reg, height, x, y, TraversalConstants.IMPENETRABLE_WALL_WEST);
269 unset(reg, height, x - 1, y, TraversalConstants.IMPENETRABLE_WALL_EAST);
272 if (orientation == ObjectDirection.NORTH) {
273 unset(reg, height, x, y, TraversalConstants.WALL_NORTH);
274 unset(reg, height, x, y + 1, TraversalConstants.WALL_SOUTH);
276 unset(reg, height, x, y, TraversalConstants.IMPENETRABLE_WALL_NORTH);
277 unset(reg, height, x, y + 1, TraversalConstants.IMPENETRABLE_WALL_SOUTH);
280 if (orientation == ObjectDirection.EAST) {
281 unset(reg, height, x, y, TraversalConstants.WALL_EAST);
282 unset(reg, height, x + 1, y, TraversalConstants.WALL_WEST);
284 unset(reg, height, x, y, TraversalConstants.IMPENETRABLE_WALL_EAST);
285 unset(reg, height, x + 1, y, TraversalConstants.IMPENETRABLE_WALL_WEST);
288 if (orientation == ObjectDirection.SOUTH) {
289 unset(reg, height, x, y, TraversalConstants.WALL_SOUTH);
290 unset(reg, height, x, y - 1, TraversalConstants.WALL_NORTH);
292 unset(reg, height, x, y, TraversalConstants.IMPENETRABLE_WALL_SOUTH);
293 unset(reg, height, x, y - 1, TraversalConstants.IMPENETRABLE_WALL_NORTH);
299 if (orientation == ObjectDirection.WEST) {
300 unset(reg, height, x, y, TraversalConstants.WALL_WEST | TraversalConstants.WALL_NORTH);
301 unset(reg, height, x - 1, y, TraversalConstants.WALL_EAST);
302 unset(reg, height, x, y + 1, TraversalConstants.WALL_SOUTH);
304 unset(reg, height, x, y, TraversalConstants.IMPENETRABLE_WALL_WEST | TraversalConstants.IMPENETRABLE_WALL_NORTH);
305 unset(reg, height, x - 1, y, TraversalConstants.IMPENETRABLE_WALL_EAST);
306 unset(reg, height, x, y + 1, TraversalConstants.IMPENETRABLE_WALL_SOUTH);
309 if (orientation == ObjectDirection.NORTH) {
310 unset(reg, height, x, y, TraversalConstants.WALL_EAST | TraversalConstants.WALL_NORTH);
311 unset(reg, height, x, y + 1, TraversalConstants.WALL_SOUTH);
312 unset(reg, height, x + 1, y, TraversalConstants.WALL_WEST);
314 unset(reg, height, x, y, TraversalConstants.IMPENETRABLE_WALL_EAST | TraversalConstants.IMPENETRABLE_WALL_NORTH);
315 unset(reg, height, x, y + 1, TraversalConstants.IMPENETRABLE_WALL_SOUTH);
316 unset(reg, height, x + 1, y, TraversalConstants.IMPENETRABLE_WALL_WEST);
319 if (orientation == ObjectDirection.EAST) {
320 unset(reg, height, x, y, TraversalConstants.WALL_EAST | TraversalConstants.WALL_SOUTH);
321 unset(reg, height, x + 1, y, TraversalConstants.WALL_WEST);
322 unset(reg, height, x, y - 1, TraversalConstants.WALL_NORTH);
324 unset(reg, height, x, y, TraversalConstants.IMPENETRABLE_WALL_EAST | TraversalConstants.IMPENETRABLE_WALL_SOUTH);
325 unset(reg, height, x + 1, y, TraversalConstants.IMPENETRABLE_WALL_WEST);
326 unset(reg, height, x, y - 1, TraversalConstants.IMPENETRABLE_WALL_NORTH);
329 if (orientation == ObjectDirection.SOUTH) {
330 unset(reg, height, x, y, TraversalConstants.WALL_EAST | TraversalConstants.WALL_SOUTH);
331 unset(reg, height, x, y - 1, TraversalConstants.WALL_WEST);
332 unset(reg, height, x - 1, y, TraversalConstants.WALL_NORTH);
334 unset(reg, height, x, y, TraversalConstants.IMPENETRABLE_WALL_EAST | TraversalConstants.IMPENETRABLE_WALL_SOUTH);
335 unset(reg, height, x, y - 1, TraversalConstants.IMPENETRABLE_WALL_WEST);
336 unset(reg, height, x - 1, y, TraversalConstants.IMPENETRABLE_WALL_NORTH);
341 case DIAGONAL_CORNER_WALL:
343 if (orientation == ObjectDirection.WEST) {
344 unset(reg, height, x, y, TraversalConstants.WALL_NORTH_WEST);
345 unset(reg, height, x - 1, y + 1, TraversalConstants.WALL_SOUTH_EAST);
347 unset(reg, height, x, y, TraversalConstants.IMPENETRABLE_WALL_NORTH_WEST);
348 unset(reg, height, x - 1, y + 1, TraversalConstants.IMPENETRABLE_WALL_SOUTH_EAST);
351 if (orientation == ObjectDirection.NORTH) {
352 unset(reg, height, x, y, TraversalConstants.WALL_NORTH_EAST);
353 unset(reg, height, x + 1, y + 1, TraversalConstants.WALL_SOUTH_WEST);
355 unset(reg, height, x, y, TraversalConstants.IMPENETRABLE_WALL_NORTH_EAST);
356 unset(reg, height, x + 1, y + 1, TraversalConstants.IMPENETRABLE_WALL_SOUTH_WEST);
359 if (orientation == ObjectDirection.EAST) {
360 unset(reg, height, x, y, TraversalConstants.WALL_SOUTH_EAST);
361 unset(reg, height, x + 1, y - 1, TraversalConstants.WALL_NORTH_WEST);
363 unset(reg, height, x, y, TraversalConstants.IMPENETRABLE_WALL_SOUTH_EAST);
364 unset(reg, height, x + 1, y - 1, TraversalConstants.IMPENETRABLE_WALL_NORTH_WEST);
367 if (orientation == ObjectDirection.SOUTH) {
368 unset(reg, height, x, y, TraversalConstants.WALL_SOUTH_WEST);
369 unset(reg, height, x - 1, y - 1, TraversalConstants.WALL_NORTH_EAST);
371 unset(reg, height, x, y, TraversalConstants.IMPENETRABLE_WALL_SOUTH_WEST);
372 unset(reg, height, x - 1, y - 1, TraversalConstants.IMPENETRABLE_WALL_NORTH_EAST);
389 public static void block(
Region region,
int height,
int localX,
int localY) {
405 public static void markOccupant(
Region region,
int height,
int x,
int y,
int width,
int length,
boolean impenetrable,
boolean add) {
410 for (
int xPos = x; xPos < x + width; xPos++) {
411 for (
int yPos = y; yPos < y + length; yPos++) {
412 if (add)
set(region, height, xPos, yPos, flag);
413 else unset(region, height, xPos, yPos, flag);
439 private static boolean isTraversableNorth(
int height,
int x,
int y,
int size) {
440 for (
int offsetX = 0; offsetX < size; offsetX++) {
441 for (
int offsetY = 0; offsetY < size; offsetY++) {
442 if (!isTraversableNorth(height, x + offsetX, y + offsetY)) {
459 private static boolean isTraversableNorth(
int height,
int x,
int y) {
460 return isTraversableNorth(height, x, y,
false);
473 private static boolean isTraversableNorth(
int height,
int x,
int y,
boolean impenetrable) {
475 return isInactive(height, x, y + 1, TraversalConstants.IMPENETRABLE_BLOCKED | TraversalConstants.IMPENETRABLE_WALL_SOUTH);
477 return isInactive(height, x, y + 1, TraversalConstants.WALL_SOUTH | TraversalConstants.BLOCKED);
490 private static boolean isTraversableSouth(
int height,
int x,
int y,
int size) {
491 for (
int offsetX = 0; offsetX < size; offsetX++) {
492 for (
int offsetY = 0; offsetY < size; offsetY++) {
493 if (!isTraversableSouth(height, x + offsetX, y + offsetY)) {
510 private static boolean isTraversableSouth(
int height,
int x,
int y) {
511 return isTraversableSouth(height, x, y,
false);
524 private static boolean isTraversableSouth(
int height,
int x,
int y,
boolean impenetrable) {
526 return isInactive(height, x, y - 1, TraversalConstants.IMPENETRABLE_BLOCKED | TraversalConstants.IMPENETRABLE_WALL_NORTH);
528 return isInactive(height, x, y - 1, TraversalConstants.WALL_NORTH | TraversalConstants.BLOCKED);
541 private static boolean isTraversableEast(
int height,
int x,
int y,
int size) {
542 for (
int offsetX = 0; offsetX < size; offsetX++) {
543 for (
int offsetY = 0; offsetY < size; offsetY++) {
544 if (!isTraversableEast(height, x + offsetX, y + offsetY)) {
561 private static boolean isTraversableEast(
int height,
int x,
int y) {
562 return isTraversableEast(height, x, y,
false);
575 private static boolean isTraversableEast(
int height,
int x,
int y,
boolean impenetrable) {
577 return isInactive(height, x + 1, y, TraversalConstants.IMPENETRABLE_BLOCKED | TraversalConstants.IMPENETRABLE_WALL_WEST);
579 return isInactive(height, x + 1, y, TraversalConstants.WALL_WEST | TraversalConstants.BLOCKED);
592 private static boolean isTraversableWest(
int height,
int x,
int y,
int size) {
593 for (
int width = 0; width < size; width++) {
594 for (
int length = 0; length < size; length++) {
595 if (!isTraversableWest(height, x + width, y + length)) {
612 private static boolean isTraversableWest(
int height,
int x,
int y) {
613 return isTraversableWest(height, x, y,
false);
626 private static boolean isTraversableWest(
int height,
int x,
int y,
boolean impenetrable) {
628 return isInactive(height, x - 1, y, TraversalConstants.IMPENETRABLE_BLOCKED | TraversalConstants.IMPENETRABLE_WALL_EAST);
630 return isInactive(height, x - 1, y, TraversalConstants.WALL_EAST | TraversalConstants.BLOCKED);
643 private static boolean isTraversableNorthEast(
int height,
int x,
int y,
int size) {
644 for (
int offsetX = 0; offsetX < size; offsetX++) {
645 for (
int offsetY = 0; offsetY < size; offsetY++) {
646 if (!isTraversableNorthEast(height, x + offsetX, y + offsetY)) {
663 private static boolean isTraversableNorthEast(
int height,
int x,
int y) {
664 return isTraversableNorthEast(height, x, y,
false);
677 private static boolean isTraversableNorthEast(
int height,
int x,
int y,
boolean impenetrable) {
679 return isInactive(height, x + 1, y + 1, TraversalConstants.IMPENETRABLE_WALL_WEST | TraversalConstants.IMPENETRABLE_WALL_SOUTH | TraversalConstants.IMPENETRABLE_WALL_SOUTH_WEST) && isInactive(height, x + 1, y, TraversalConstants.IMPENETRABLE_WALL_WEST | TraversalConstants.IMPENETRABLE_BLOCKED) && isInactive(height, x, y + 1, TraversalConstants.IMPENETRABLE_WALL_SOUTH | TraversalConstants.IMPENETRABLE_BLOCKED);
681 return isInactive(height, x + 1, y + 1, TraversalConstants.WALL_WEST | TraversalConstants.WALL_SOUTH | TraversalConstants.WALL_SOUTH_WEST | TraversalConstants.BLOCKED) && isInactive(height, x + 1, y, TraversalConstants.WALL_WEST | TraversalConstants.BLOCKED) && isInactive(height, x, y + 1, TraversalConstants.WALL_SOUTH | TraversalConstants.BLOCKED);
694 private static boolean isTraversableNorthWest(
int height,
int x,
int y,
int size) {
695 for (
int offsetX = 0; offsetX < size; offsetX++) {
696 for (
int offsetY = 0; offsetY < size; offsetY++) {
697 if (!isTraversableNorthWest(height, x + offsetX, y + offsetY)) {
714 private static boolean isTraversableNorthWest(
int height,
int x,
int y) {
715 return isTraversableNorthWest(height, x, y,
false);
728 private static boolean isTraversableNorthWest(
int height,
int x,
int y,
boolean impenetrable) {
730 return isInactive(height, x - 1, y + 1, TraversalConstants.IMPENETRABLE_WALL_EAST | TraversalConstants.IMPENETRABLE_WALL_SOUTH | TraversalConstants.IMPENETRABLE_WALL_SOUTH_EAST) && isInactive(height, x - 1, y, TraversalConstants.IMPENETRABLE_WALL_EAST | TraversalConstants.IMPENETRABLE_BLOCKED) && isInactive(height, x, y + 1, TraversalConstants.IMPENETRABLE_WALL_SOUTH | TraversalConstants.IMPENETRABLE_BLOCKED);
732 return isInactive(height, x - 1, y + 1, TraversalConstants.WALL_EAST | TraversalConstants.WALL_SOUTH | TraversalConstants.WALL_SOUTH_EAST | TraversalConstants.BLOCKED) && isInactive(height, x - 1, y, TraversalConstants.WALL_EAST | TraversalConstants.BLOCKED) && isInactive(height, x, y + 1, TraversalConstants.WALL_SOUTH | TraversalConstants.BLOCKED);
745 private static boolean isTraversableSouthEast(
int height,
int x,
int y,
int size) {
746 for (
int offsetX = 0; offsetX < size; offsetX++) {
747 for (
int offsetY = 0; offsetY < size; offsetY++) {
748 if (!isTraversableSouthEast(height, x + offsetX, y + offsetY)) {
765 private static boolean isTraversableSouthEast(
int height,
int x,
int y) {
766 return isTraversableSouthEast(height, x, y,
false);
779 private static boolean isTraversableSouthEast(
int height,
int x,
int y,
boolean impenetrable) {
781 return isInactive(height, x + 1, y - 1, TraversalConstants.IMPENETRABLE_WALL_WEST | TraversalConstants.IMPENETRABLE_WALL_NORTH | TraversalConstants.IMPENETRABLE_WALL_NORTH_WEST) && isInactive(height, x + 1, y, TraversalConstants.IMPENETRABLE_WALL_WEST | TraversalConstants.IMPENETRABLE_BLOCKED) && isInactive(height, x, y - 1, TraversalConstants.IMPENETRABLE_WALL_NORTH | TraversalConstants.IMPENETRABLE_BLOCKED);
783 return isInactive(height, x + 1, y - 1, TraversalConstants.WALL_WEST | TraversalConstants.WALL_NORTH | TraversalConstants.WALL_NORTH_WEST | TraversalConstants.BLOCKED) && isInactive(height, x + 1, y, TraversalConstants.WALL_WEST | TraversalConstants.BLOCKED) && isInactive(height, x, y - 1, TraversalConstants.WALL_NORTH | TraversalConstants.BLOCKED);
796 private static boolean isTraversableSouthWest(
int height,
int x,
int y,
int size) {
797 for (
int offsetX = 0; offsetX < size; offsetX++) {
798 for (
int offsetY = 0; offsetY < size; offsetY++) {
799 if (!isTraversableSouthWest(height, x + offsetX, y + offsetY)) {
816 private static boolean isTraversableSouthWest(
int height,
int x,
int y) {
817 return isTraversableSouthWest(height, x, y,
false);
830 private static boolean isTraversableSouthWest(
int height,
int x,
int y,
boolean impenetrable) {
832 return isInactive(height, x - 1, y - 1, TraversalConstants.IMPENETRABLE_WALL_EAST | TraversalConstants.IMPENETRABLE_WALL_NORTH | TraversalConstants.IMPENETRABLE_WALL_NORTH_EAST) && isInactive(height, x - 1, y, TraversalConstants.IMPENETRABLE_WALL_EAST | TraversalConstants.IMPENETRABLE_BLOCKED) && isInactive(height, x, y - 1, TraversalConstants.IMPENETRABLE_WALL_NORTH | TraversalConstants.IMPENETRABLE_BLOCKED);
834 return isInactive(height, x - 1, y - 1, TraversalConstants.WALL_EAST | TraversalConstants.WALL_NORTH | TraversalConstants.WALL_NORTH_EAST | TraversalConstants.BLOCKED) && isInactive(height, x - 1, y, TraversalConstants.WALL_EAST | TraversalConstants.BLOCKED) && isInactive(height, x, y - 1, TraversalConstants.WALL_NORTH | TraversalConstants.BLOCKED);
845 public static void set(
Region region,
int height,
int x,
int y,
int flag) {
846 region.setFlags(height, x & 0x3F, y & 0x3F, flag);
860 private static boolean isInactive(
int height,
int x,
int y,
int flag) {
861 int localX = x & 0x3F;
862 int localY = y & 0x3F;
864 return (region.getFlags(height, localX, localY) & flag) == 0;
875 private static void unset(
Region region,
int height,
int x,
int y,
int flag) {
876 region.
unsetFlags(height, x & 0x3F, y & 0x3F, flag);
910 throw new IllegalArgumentException(
"direction: " + direction +
" is not valid");
927 return isTraversableNorth(from.
getHeight(), from.
getX(), from.
getY(), impenetrable);
929 return isTraversableSouth(from.
getHeight(), from.
getX(), from.
getY(), impenetrable);
931 return isTraversableEast(from.
getHeight(), from.
getX(), from.
getY(), impenetrable);
933 return isTraversableWest(from.
getHeight(), from.
getX(), from.
getY(), impenetrable);
935 return isTraversableNorthEast(from.
getHeight(), from.
getX(), from.
getY(), impenetrable);
937 return isTraversableNorthWest(from.
getHeight(), from.
getX(), from.
getY(), impenetrable);
939 return isTraversableSouthEast(from.
getHeight(), from.
getX(), from.
getY(), impenetrable);
941 return isTraversableSouthWest(from.
getHeight(), from.
getX(), from.
getY(), impenetrable);
945 throw new IllegalArgumentException(
"direction: " + direction +
" is not valid");
959 List<Position> positions =
new LinkedList<>();
960 for (
int y = 0; y < length; y++) {
961 for (
int x = 0; x < width; x++) {
965 positions.add(from.north());
968 positions.add(from.south());
971 positions.add(from.east());
974 positions.add(from.west());
977 positions.add(from.northEast());
980 positions.add(from.northWest());
983 positions.add(from.southEast());
986 positions.add(from.southWest());
992 public static Position getRandomTraversableTile(
Position southWest,
int width,
int length) {
993 List<Position> positions =
new LinkedList<>();
994 for (
int y = 0; y < length; y++) {
995 for (
int x = 0; x < width; x++) {
999 positions.add(from.north());
1002 positions.add(from.south());
1005 positions.add(from.east());
1008 positions.add(from.west());
1011 positions.add(from.northEast());
1014 positions.add(from.northWest());
1017 positions.add(from.southEast());
1020 positions.add(from.southWest());
1023 if (positions.isEmpty())
1025 return RandomUtils.random(positions);
1029 List<Position> positions =
new LinkedList<>();
1032 positions.add(from.north());
1035 positions.add(from.south());
1038 positions.add(from.east());
1041 positions.add(from.west());
1043 if (positions.isEmpty())
1046 return RandomUtils.random(positions);
1049 public static int getFlags(
int x,
int y,
int height) {
1050 int localX = x & 0x3F;
1051 int localY = y & 0x3F;
1052 Region region = World.getRegions().getRegion(x, y);
1053 return region.
getFlags(height, localX, localY);
1056 public static int getFlags(Position position) {
1057 return getFlags(position.getX(), position.getY(), position.getHeight());
1060 public static boolean blockedNorth(Position position) {
1061 return !isTraversableNorth(position.getHeight(), position.getX(), position.getY(),
false);
1064 public static boolean blockedEast(Position position) {
1065 return !isTraversableEast(position.getHeight(), position.getX(), position.getY(),
false);
1068 public static boolean blockedSouth(Position position) {
1069 return !isTraversableSouth(position.getHeight(), position.getX(), position.getY(),
false);
1072 public static boolean blockedWest(Position position) {
1073 return !isTraversableWest(position.getHeight(), position.getX(), position.getY(),
false);