v0.6.0: improved logic for the placement of large standard rooms

This commit is contained in:
Evan Debenham 2017-05-03 23:19:10 -04:00
parent 01ed933be2
commit 33dd5089f4
5 changed files with 45 additions and 11 deletions

View File

@ -95,8 +95,14 @@ public abstract class RegularLevel extends Level {
initRooms.add( roomExit = new ExitRoom()); initRooms.add( roomExit = new ExitRoom());
int standards = standardRooms(); int standards = standardRooms();
for (int i = 0; i < standards; i++) for (int i = 0; i < standards; i++) {
initRooms.add(StandardRoom.createRoom()); StandardRoom s;
do {
s = StandardRoom.createRoom();
} while ((i + s.sizeCat.roomValue) > standards);
i += s.sizeCat.roomValue-1;
initRooms.add(s);
}
if (Dungeon.shopOnLevel()) if (Dungeon.shopOnLevel())
initRooms.add(new ShopRoom()); initRooms.add(new ShopRoom());
@ -189,8 +195,13 @@ public abstract class RegularLevel extends Level {
ArrayList<Room> stdRooms = new ArrayList<>(); ArrayList<Room> stdRooms = new ArrayList<>();
for (Room room : rooms) { for (Room room : rooms) {
if (room instanceof StandardRoom && room != roomEntrance) stdRooms.add(room); if (room instanceof StandardRoom && room != roomEntrance) {
for (int i = 0; i < ((StandardRoom) room).sizeCat.roomValue; i++) {
stdRooms.add(room);
}
}
} }
Random.shuffle(rooms);
Iterator<Room> stdRoomIter = stdRooms.iterator(); Iterator<Room> stdRoomIter = stdRooms.iterator();
while (mobsToSpawn > 0) { while (mobsToSpawn > 0) {

View File

@ -79,6 +79,7 @@ public class LineBuilder extends RegularBuilder {
roomsToBranch.add(multiConnections.get(i)); roomsToBranch.add(multiConnections.get(i));
} }
roomsToBranch.addAll(singleConnections); roomsToBranch.addAll(singleConnections);
weightRooms(branchable);
createBranches(rooms, branchable, roomsToBranch, branchTunnelChances); createBranches(rooms, branchable, roomsToBranch, branchTunnelChances);
findNeighbours(rooms); findNeighbours(rooms);

View File

@ -92,6 +92,7 @@ public class LoopBuilder extends RegularBuilder {
ArrayList<Room> roomsToBranch = new ArrayList<>(); ArrayList<Room> roomsToBranch = new ArrayList<>();
roomsToBranch.addAll(multiConnections); roomsToBranch.addAll(multiConnections);
roomsToBranch.addAll(singleConnections); roomsToBranch.addAll(singleConnections);
weightRooms(branchable);
createBranches(rooms, branchable, roomsToBranch, branchTunnelChances); createBranches(rooms, branchable, roomsToBranch, branchTunnelChances);
findNeighbours(rooms); findNeighbours(rooms);

View File

@ -25,6 +25,7 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.ConnectionRoom; import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.ConnectionRoom;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.EntranceRoom; import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.EntranceRoom;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.ExitRoom; import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.ExitRoom;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.StandardRoom;
import com.watabou.utils.Random; import com.watabou.utils.Random;
import java.util.ArrayList; import java.util.ArrayList;
@ -98,6 +99,15 @@ public abstract class RegularBuilder extends Builder {
// *** Branch Placement *** // *** Branch Placement ***
protected static void weightRooms(ArrayList<Room> rooms){
for (Room r : rooms.toArray(new Room[0])){
if (r instanceof StandardRoom){
for (int i = 0; i < ((StandardRoom) r).sizeCat.connectionWeight(); i++)
rooms.add(r);
}
}
}
//places the rooms in roomsToBranch into branches from rooms in branchable. //places the rooms in roomsToBranch into branches from rooms in branchable.
//note that the three arrays should be separate, they may contain the same rooms however //note that the three arrays should be separate, they may contain the same rooms however
protected static void createBranches(ArrayList<Room> rooms, ArrayList<Room> branchable, protected static void createBranches(ArrayList<Room> rooms, ArrayList<Room> branchable,
@ -160,11 +170,16 @@ public abstract class RegularBuilder extends Builder {
continue; continue;
} }
for (Room t : connectingRoomsThisBranch){ branchable.addAll(connectingRoomsThisBranch);
branchable.add(t); if (r.maxConnections(Room.ALL) > 1) {
if (r instanceof StandardRoom){
for (int j = 0; j < ((StandardRoom) r).sizeCat.connectionWeight(); j++){
branchable.add(r);
}
} else {
branchable.add(r);
}
} }
if (r.maxConnections(Room.ALL) > 1 && Random.Int(2) == 0)
branchable.add(r);
i++; i++;
} }

View File

@ -31,15 +31,21 @@ public abstract class StandardRoom extends Room {
public enum SizeCategories{ public enum SizeCategories{
NORMAL(4, 10), NORMAL(4, 10, 1),
LARGE(10, 14), LARGE(10, 14, 2),
GIANT(14, 18); GIANT(14, 18, 3);
public final int minDim, maxDim; public final int minDim, maxDim;
public final int roomValue;
SizeCategories(int min, int max){ SizeCategories(int min, int max, int val){
minDim = min; minDim = min;
maxDim = max; maxDim = max;
roomValue = val;
}
public int connectionWeight(){
return roomValue*roomValue;
} }
} }