v0.4.3: adjusted several parts of levelgen to be more predictable (no functional difference however)
This commit is contained in:
parent
fc8f362ed4
commit
84f61ff37e
|
@ -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<Room> rooms;
|
||||
protected ArrayList<Room> 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<Room> connected = new HashSet<Room>();
|
||||
ArrayList<Room> 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<Room> neigbours = new HashSet<Room>();
|
||||
ArrayList<Room> 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<Integer> validCells = new LinkedList<Integer>();
|
||||
ArrayList<Integer> 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<Room> stdRooms = new HashSet<>();
|
||||
ArrayList<Room> 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<Room>) ((Collection<?>) bundle.getCollection( "rooms" )) );
|
||||
rooms = new ArrayList<>( (Collection<Room>) ((Collection<?>) bundle.getCollection( "rooms" )) );
|
||||
for (Room r : rooms) {
|
||||
if (r.type == Type.WEAK_FLOOR) {
|
||||
weakFloorCreated = true;
|
||||
|
|
|
@ -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<Room> neigbours = new HashSet<Room>();
|
||||
public HashMap<Room, Door> connected = new HashMap<Room, Door>();
|
||||
public ArrayList<Room> neigbours = new ArrayList<Room>();
|
||||
public LinkedHashMap<Room, Door> connected = new LinkedHashMap<Room, Door>();
|
||||
|
||||
public int distance;
|
||||
public int price = 1;
|
||||
|
@ -127,7 +126,12 @@ public class Room extends Rect implements Graph.Node, Bundlable {
|
|||
}
|
||||
};
|
||||
|
||||
public static final ArrayList<Type> SPECIALS = new ArrayList<Type>( Arrays.asList(
|
||||
private static final ArrayList<Type> ALL_SPEC = new ArrayList<Type>( 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 ArrayList<Type> SPECIALS = new ArrayList<Type>( 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<Type>)ALL_SPEC.clone();
|
||||
int size = SPECIALS.size();
|
||||
for (int i=0; i < size - 1; i++) {
|
||||
int j = Random.Int( i, size );
|
||||
|
|
Loading…
Reference in New Issue
Block a user