diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/RegularLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/RegularLevel.java index 29180eaf8..1cab100a6 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/RegularLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/RegularLevel.java @@ -46,15 +46,12 @@ import com.watabou.utils.Rect; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; public abstract class RegularLevel extends Level { - protected HashSet rooms; + protected ArrayList rooms; protected Room roomEntrance; protected Room roomExit; @@ -94,7 +91,7 @@ public abstract class RegularLevel extends Level { roomEntrance.type = Type.ENTRANCE; roomExit.type = Type.EXIT; - HashSet connected = new HashSet(); + ArrayList connected = new ArrayList<>(); connected.add( roomEntrance ); Graph.buildDistanceMap( rooms, roomExit ); @@ -183,7 +180,7 @@ public abstract class RegularLevel extends Level { protected boolean initRooms() { - rooms = new HashSet<>(); + rooms = new ArrayList<>(); split( new Rect( 0, 0, width() - 1, height() - 1 ) ); if (rooms.size() < 8) { @@ -251,7 +248,7 @@ public abstract class RegularLevel extends Level { } else if (Random.Int( 2 ) == 0){ - HashSet neigbours = new HashSet(); + ArrayList neigbours = new ArrayList<>(); for (Room n : r.neigbours) { if (!r.connected.containsKey( n ) && !Room.SPECIALS.contains( n.type ) && @@ -341,7 +338,7 @@ public abstract class RegularLevel extends Level { float[] trapChances = trapChances(); Class[] trapClasses = trapClasses(); - LinkedList validCells = new LinkedList(); + ArrayList validCells = new ArrayList<>(); for (int i = 0; i < length(); i ++) { if (map[i] == Terrain.EMPTY){ @@ -360,11 +357,10 @@ public abstract class RegularLevel extends Level { //no more than one trap every 5 valid tiles. nTraps = Math.min(nTraps, validCells.size()/5); - Collections.shuffle(validCells); - for (int i = 0; i < nTraps; i++) { - int trapPos = validCells.removeFirst(); + Integer trapPos = Random.element(validCells); + validCells.remove(trapPos); //removes the integer object, not at the index try { Trap trap = ((Trap)trapClasses[Random.chances( trapChances )].newInstance()).hide(); @@ -584,7 +580,7 @@ public abstract class RegularLevel extends Level { //on floor 1, 10 rats are created so the player can get level 2. int mobsToSpawn = Dungeon.depth == 1 ? 10 : nMobs(); - HashSet stdRooms = new HashSet<>(); + ArrayList stdRooms = new ArrayList<>(); for (Room room : rooms) { if (room.type == Type.STANDARD) stdRooms.add(room); } @@ -764,7 +760,7 @@ public abstract class RegularLevel extends Level { public void restoreFromBundle( Bundle bundle ) { super.restoreFromBundle( bundle ); - rooms = new HashSet<>( (Collection) ((Collection) bundle.getCollection( "rooms" )) ); + rooms = new ArrayList<>( (Collection) ((Collection) bundle.getCollection( "rooms" )) ); for (Room r : rooms) { if (r.type == Type.WEAK_FLOOR) { weakFloorCreated = true; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/Room.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/Room.java index 42a21d85c..6867ed0ed 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/Room.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/Room.java @@ -61,13 +61,12 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; +import java.util.LinkedHashMap; public class Room extends Rect implements Graph.Node, Bundlable { - public HashSet neigbours = new HashSet(); - public HashMap connected = new HashMap(); + public ArrayList neigbours = new ArrayList(); + public LinkedHashMap connected = new LinkedHashMap(); public int distance; public int price = 1; @@ -126,8 +125,13 @@ public class Room extends Rect implements Graph.Node, Bundlable { } } }; + + private static final ArrayList ALL_SPEC = new ArrayList( Arrays.asList( + Type.WEAK_FLOOR, Type.MAGIC_WELL, Type.CRYPT, Type.POOL, Type.GARDEN, Type.LIBRARY, Type.ARMORY, + Type.TREASURY, Type.TRAPS, Type.STORAGE, Type.STATUE, Type.LABORATORY, Type.VAULT + ) ); - public static final ArrayList SPECIALS = new ArrayList( Arrays.asList( + public static ArrayList SPECIALS = new ArrayList( Arrays.asList( Type.WEAK_FLOOR, Type.MAGIC_WELL, Type.CRYPT, Type.POOL, Type.GARDEN, Type.LIBRARY, Type.ARMORY, Type.TREASURY, Type.TRAPS, Type.STORAGE, Type.STATUE, Type.LABORATORY, Type.VAULT ) ); @@ -221,6 +225,7 @@ public class Room extends Rect implements Graph.Node, Bundlable { } public static void shuffleTypes() { + SPECIALS = (ArrayList)ALL_SPEC.clone(); int size = SPECIALS.size(); for (int i=0; i < size - 1; i++) { int j = Random.Int( i, size );