diff --git a/Database Updates/UpdateDatabase_Allow_diagonale.sql b/Database Updates/UpdateDatabase_Allow_diagonale.sql new file mode 100644 index 0000000..089f205 --- /dev/null +++ b/Database Updates/UpdateDatabase_Allow_diagonale.sql @@ -0,0 +1 @@ +INSERT INTO emulator_settings (`key`, `value`) VALUES ('pathfinder.diagonale.enabled', '1'); diff --git a/Emulator/pom.xml b/Emulator/pom.xml index cf63987..921ffdc 100644 --- a/Emulator/pom.xml +++ b/Emulator/pom.xml @@ -34,8 +34,8 @@ maven-compiler-plugin 3.8.1 - 1.8 - 1.8 + 11 + 11 diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomLayout.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomLayout.java index 8d8d8e6..4c27258 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomLayout.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomLayout.java @@ -32,6 +32,7 @@ public class RoomLayout { private RoomTile[][] roomTiles; private RoomTile doorTile; private Room room; + boolean canMoveDiagonally = PathfinderConfig.canMoveDiagonally(); public RoomLayout(ResultSet set, Room room) throws SQLException { this.room = room; @@ -49,6 +50,13 @@ public class RoomLayout { } } + public class PathfinderConfig { + private static boolean canMoveDiagonally = Emulator.getConfig().getBoolean("pathfinder.diagonal.enabled", false); + public static boolean canMoveDiagonally() { + return canMoveDiagonally; + } + } + public static boolean squareInSquare(Rectangle outerSquare, Rectangle innerSquare) { if (outerSquare.x > innerSquare.x) return false; @@ -255,7 +263,7 @@ public class RoomLayout { public String getRelativeMap() { return this.heightmap.replace("\r\n", "\r"); - }//re + } public final Deque findPath(RoomTile oldTile, RoomTile newTile, RoomTile goalLocation, RoomUnit roomUnit) { return this.findPath(oldTile, newTile, goalLocation, roomUnit, false); @@ -426,11 +434,13 @@ public class RoomLayout { } } } + if (this.CANMOVEDIAGONALY) { + // Diagonal: bottom-right if ((x < this.mapSizeX) && (y < this.mapSizeY)) { RoomTile offX = this.findTile(openList, (short) (x + 1), y); RoomTile offY = this.findTile(openList, x, (short) (y + 1)); - if (offX != null && offY != null && (offX.isWalkable() || offY.isWalkable())) { + if (offX != null && offY != null && (canMoveDiagonally || offX.isWalkable() || offY.isWalkable())) { RoomTile temp = this.findTile(openList, (short) (x + 1), (short) (y + 1)); if (this.canWalkOn(temp, unit)) { if (temp.state != RoomTileState.SIT || nextTile.getStackHeight() - node.getStackHeight() <= 2.0) { @@ -441,10 +451,12 @@ public class RoomLayout { } } } + + // Diagonal: top-left if ((x > 0) && (y > 0)) { RoomTile offX = this.findTile(openList, (short) (x - 1), y); RoomTile offY = this.findTile(openList, x, (short) (y - 1)); - if (offX != null && offY != null && (offX.isWalkable() || offY.isWalkable())) { + if (offX != null && offY != null && (canMoveDiagonally || offX.isWalkable() || offY.isWalkable())) { RoomTile temp = this.findTile(openList, (short) (x - 1), (short) (y - 1)); if (this.canWalkOn(temp, unit)) { if (temp.state != RoomTileState.SIT || nextTile.getStackHeight() - node.getStackHeight() <= 2.0) { @@ -455,10 +467,12 @@ public class RoomLayout { } } } + + // Diagonal: bottom-left if ((x > 0) && (y < this.mapSizeY)) { RoomTile offX = this.findTile(openList, (short) (x - 1), y); RoomTile offY = this.findTile(openList, x, (short) (y + 1)); - if (offX != null && offY != null && (offX.isWalkable() || offY.isWalkable())) { + if (offX != null && offY != null && (canMoveDiagonally || offX.isWalkable() || offY.isWalkable())) { RoomTile temp = this.findTile(openList, (short) (x - 1), (short) (y + 1)); if (this.canWalkOn(temp, unit)) { if (temp.state != RoomTileState.SIT || nextTile.getStackHeight() - node.getStackHeight() <= 2.0) { @@ -469,10 +483,12 @@ public class RoomLayout { } } } + + // Diagonal: top-right if ((x < this.mapSizeX) && (y > 0)) { RoomTile offX = this.findTile(openList, (short) (x + 1), y); RoomTile offY = this.findTile(openList, x, (short) (y - 1)); - if (offX != null && offY != null && (offX.isWalkable() || offY.isWalkable())) { + if (offX != null && offY != null && (canMoveDiagonally || offX.isWalkable() || offY.isWalkable())) { RoomTile temp = this.findTile(openList, (short) (x + 1), (short) (y - 1)); if (this.canWalkOn(temp, unit)) { if (temp.state != RoomTileState.SIT || nextTile.getStackHeight() - node.getStackHeight() <= 2.0) { @@ -487,7 +503,7 @@ public class RoomLayout { return adj; } - private boolean canWalkOn(RoomTile tile, RoomUnit unit) { + private boolean canWalkOn(RoomTile tile, RoomUnit unit) { return tile != null && (unit.canOverrideTile(tile) || (tile.state != RoomTileState.BLOCKED && tile.state != RoomTileState.INVALID)); }