diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java index dac5a52f2..83f1eb507 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java @@ -268,8 +268,7 @@ public class Dungeon { level = new DeadEndLevel(); Statistics.deepestFloor--; } - - visible = new boolean[level.length()]; + level.create(); Statistics.qualifiedForNoKilling = !bossLevel(); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CavesBossLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CavesBossLevel.java index d422f68b2..e6b73581d 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CavesBossLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CavesBossLevel.java @@ -100,6 +100,8 @@ public class CavesBossLevel extends Level { @Override protected boolean build() { + setSize(32, 32); + int topMost = Integer.MAX_VALUE; for (int i=0; i < 8; i++) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CityBossLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CityBossLevel.java index 11034ddd3..fdf618a06 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CityBossLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CityBossLevel.java @@ -95,6 +95,8 @@ public class CityBossLevel extends Level { @Override protected boolean build() { + setSize(32, 32); + Painter.fill( this, LEFT, TOP, HALL_WIDTH, HALL_HEIGHT, Terrain.EMPTY ); Painter.fill( this, CENTER, TOP, 1, HALL_HEIGHT, Terrain.EMPTY_SP ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/DeadEndLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/DeadEndLevel.java index 369ef4d43..93be0a81c 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/DeadEndLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/DeadEndLevel.java @@ -25,8 +25,6 @@ import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; import com.watabou.utils.Random; -import java.util.Arrays; - public class DeadEndLevel extends Level { private static final int SIZE = 5; @@ -48,8 +46,8 @@ public class DeadEndLevel extends Level { @Override protected boolean build() { - - Arrays.fill( map, Terrain.WALL ); + + setSize(7, 7); for (int i=2; i < SIZE; i++) { for (int j=2; j < SIZE; j++) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/HallsBossLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/HallsBossLevel.java index fd9818532..4d2cda778 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/HallsBossLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/HallsBossLevel.java @@ -94,6 +94,8 @@ public class HallsBossLevel extends Level { @Override protected boolean build() { + setSize(32, 32); + for (int i=0; i < 5; i++) { int top = Random.IntRange( 2, ROOM_TOP - 1 ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/LastLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/LastLevel.java index 09d78b064..f90123ae7 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/LastLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/LastLevel.java @@ -44,15 +44,6 @@ public class LastLevel extends Level { private int pedestal; - @Override - protected void setupSize() { - if (width == 0 || height == 0) { - width = 16; - height = 64; - } - length = width * height; - } - @Override public String tilesTex() { return Assets.TILES_HALLS; @@ -77,7 +68,8 @@ public class LastLevel extends Level { @Override protected boolean build() { - + + setSize(16, 64); Arrays.fill( map, Terrain.CHASM ); int mid = width/2; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java index df6b1d443..79bb70f9d 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java @@ -179,23 +179,6 @@ public abstract class Level implements Bundlable { public void create() { Random.seed( Dungeon.seedCurDepth() ); - - setupSize(); - PathFinder.setMapSize(width(), height()); - passable = new boolean[length()]; - losBlocking = new boolean[length()]; - flamable = new boolean[length()]; - secret = new boolean[length()]; - solid = new boolean[length()]; - avoid = new boolean[length()]; - water = new boolean[length()]; - pit = new boolean[length()]; - - map = new int[length()]; - visited = new boolean[length()]; - Arrays.fill( visited, false ); - mapped = new boolean[length()]; - Arrays.fill( mapped, false ); if (!(Dungeon.bossLevel() || Dungeon.depth == 21) /*final shop floor*/) { addItemToSpawn( Generator.random( Generator.Category.FOOD ) ); @@ -262,10 +245,9 @@ public abstract class Level implements Bundlable { boolean pitNeeded = Dungeon.depth > 1 && weakFloorCreated; do { - Arrays.fill( map, feeling == Feeling.CHASM ? Terrain.CHASM : Terrain.WALL ); - pitRoomNeeded = pitNeeded; weakFloorCreated = false; + width = height = length = 0; mobs = new HashSet<>(); heaps = new SparseArray<>(); @@ -278,6 +260,16 @@ public abstract class Level implements Bundlable { } while (!build()); decorate(); + PathFinder.setMapSize(width(), height()); + passable = new boolean[length()]; + losBlocking = new boolean[length()]; + flamable = new boolean[length()]; + secret = new boolean[length()]; + solid = new boolean[length()]; + avoid = new boolean[length()]; + water = new boolean[length()]; + pit = new boolean[length()]; + buildFlagMaps(); cleanWalls(); @@ -286,11 +278,20 @@ public abstract class Level implements Bundlable { Random.seed(); } - - protected void setupSize(){ - if (width == 0 || height == 0) - width = height = 32; - length = width * height; + + public void setSize(int w, int h){ + + width = w; + height = h; + length = w * h; + + map = new int[length]; + Arrays.fill( map, Terrain.WALL ); + Arrays.fill( map, feeling == Level.Feeling.CHASM ? Terrain.CHASM : Terrain.WALL ); + + visited = new boolean[length]; + mapped = new boolean[length]; + Dungeon.visible = new boolean[length]; } public void reset() { @@ -450,20 +451,14 @@ public abstract class Level implements Bundlable { } public int width() { - if (width == 0) - setupSize(); return width; } public int height() { - if (height == 0) - setupSize(); return height; } public int length() { - if (length == 0) - setupSize(); return length; } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/PrisonBossLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/PrisonBossLevel.java index dbba39f9f..6609ff42b 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/PrisonBossLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/PrisonBossLevel.java @@ -119,6 +119,8 @@ public class PrisonBossLevel extends Level { @Override protected boolean build() { + setSize(32, 32); + map = MAP_START.clone(); decorate(); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/RegularPainter.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/RegularPainter.java index 97147966d..76f20cb67 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/RegularPainter.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/RegularPainter.java @@ -64,6 +64,25 @@ public class RegularPainter extends Painter { @Override public boolean paint(Level level, ArrayList rooms) { + int leftMost = Integer.MAX_VALUE, topMost = Integer.MAX_VALUE; + + for (Room r : rooms){ + if (r.left < leftMost) leftMost = r.left; + if (r.top < topMost) topMost = r.top; + } + + int width = 0, height = 0; + + for (Room r : rooms){ + r.shift( -leftMost, -topMost); + if (r.right > width) width = r.right; + if (r.bottom > height) height = r.bottom; + } + + level.setSize(width+1, height+1); + + PathFinder.setMapSize(level.width(), level.height()); + for (Room r : rooms) { placeDoors( r ); r.paint( level );