v0.6.0: implemented logic for variable tunnel rooms

This commit is contained in:
Evan Debenham 2017-05-01 16:21:32 -04:00
parent 5b9d276ac1
commit d559a495cc
4 changed files with 39 additions and 18 deletions

View File

@ -22,7 +22,7 @@
package com.shatteredpixel.shatteredpixeldungeon.levels.builders; package com.shatteredpixel.shatteredpixeldungeon.levels.builders;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room; import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.TunnelRoom; import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.ConnectionRoom;
import com.watabou.utils.GameMath; import com.watabou.utils.GameMath;
import com.watabou.utils.Point; import com.watabou.utils.Point;
import com.watabou.utils.PointF; import com.watabou.utils.PointF;
@ -246,21 +246,21 @@ public abstract class Builder {
//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,
ArrayList<Room> roomsToBranch, float[] tunnelChances){ ArrayList<Room> roomsToBranch, float[] connChances){
int i = 0; int i = 0;
float angle; float angle;
int tries; int tries;
Room curr; Room curr;
ArrayList<Room> tunnelsThisBranch = new ArrayList<>(); ArrayList<Room> connectingRoomsThisBranch = new ArrayList<>();
while (i < roomsToBranch.size()){ while (i < roomsToBranch.size()){
tunnelsThisBranch.clear(); connectingRoomsThisBranch.clear();
curr = Random.element(branchable); curr = Random.element(branchable);
int tunnels = Random.chances(tunnelChances); int connectingRooms = Random.chances(connChances);
for (int j = 0; j < tunnels; j++){ for (int j = 0; j < connectingRooms; j++){
TunnelRoom t = new TunnelRoom(); ConnectionRoom t = ConnectionRoom.createRoom();
tries = 10; tries = 10;
do { do {
@ -269,21 +269,21 @@ public abstract class Builder {
} while (angle == -1 && tries >= 0); } while (angle == -1 && tries >= 0);
if (angle == -1) { if (angle == -1) {
for (Room r : tunnelsThisBranch){ for (Room r : connectingRoomsThisBranch){
r.clearConnections(); r.clearConnections();
rooms.remove(r); rooms.remove(r);
} }
tunnelsThisBranch.clear(); connectingRoomsThisBranch.clear();
break; break;
} else { } else {
tunnelsThisBranch.add(t); connectingRoomsThisBranch.add(t);
rooms.add(t); rooms.add(t);
} }
curr = t; curr = t;
} }
if (tunnelsThisBranch.size() != tunnels){ if (connectingRoomsThisBranch.size() != connectingRooms){
continue; continue;
} }
@ -297,15 +297,15 @@ public abstract class Builder {
} while (angle == -1 && tries >= 0); } while (angle == -1 && tries >= 0);
if (angle == -1){ if (angle == -1){
for (Room t : tunnelsThisBranch){ for (Room t : connectingRoomsThisBranch){
t.clearConnections(); t.clearConnections();
rooms.remove(t); rooms.remove(t);
} }
tunnelsThisBranch.clear(); connectingRoomsThisBranch.clear();
continue; continue;
} }
for (Room t : tunnelsThisBranch){ for (Room t : connectingRoomsThisBranch){
branchable.add(t); branchable.add(t);
} }
if (r.maxConnections(Room.ALL) > 1 && Random.Int(2) == 0) if (r.maxConnections(Room.ALL) > 1 && Random.Int(2) == 0)

View File

@ -22,7 +22,7 @@
package com.shatteredpixel.shatteredpixeldungeon.levels.builders; package com.shatteredpixel.shatteredpixeldungeon.levels.builders;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room; import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.TunnelRoom; import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.ConnectionRoom;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.ShopRoom; import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.ShopRoom;
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;
@ -117,7 +117,7 @@ public class LineBuilder extends Builder {
int tunnels = Random.chances(pathTunnelChances); int tunnels = Random.chances(pathTunnelChances);
for (int j = 0; j < tunnels; j++){ for (int j = 0; j < tunnels; j++){
TunnelRoom t = new TunnelRoom(); ConnectionRoom t = ConnectionRoom.createRoom();
placeRoom(rooms, curr, t, direction + Random.Float(-pathVariance, pathVariance)); placeRoom(rooms, curr, t, direction + Random.Float(-pathVariance, pathVariance));
branchable.add(t); branchable.add(t);
rooms.add(t); rooms.add(t);

View File

@ -22,7 +22,7 @@
package com.shatteredpixel.shatteredpixeldungeon.levels.builders; package com.shatteredpixel.shatteredpixeldungeon.levels.builders;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room; import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.TunnelRoom; import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.ConnectionRoom;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.EmptyRoom; import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.EmptyRoom;
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;
@ -109,7 +109,7 @@ public class LoopBuilder extends Builder {
int tunnels = Random.chances(pathTunnelChances); int tunnels = Random.chances(pathTunnelChances);
for (int j = 0; j < tunnels; j++){ for (int j = 0; j < tunnels; j++){
loop.add(new TunnelRoom()); loop.add(ConnectionRoom.createRoom());
} }
} }

View File

@ -21,7 +21,11 @@
package com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection; package com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room; import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room;
import com.watabou.utils.Random;
import java.util.HashMap;
public abstract class ConnectionRoom extends Room { public abstract class ConnectionRoom extends Room {
@ -45,5 +49,22 @@ public abstract class ConnectionRoom extends Room {
else return 4; else return 4;
} }
private static HashMap<Class<?extends ConnectionRoom>, Float> chances = new HashMap<>();
static {
chances.put(TunnelRoom.class, 10f);
chances.put(PerimeterRoom.class, 10f);
chances.put(BridgeRoom.class, 3f);
chances.put(WalkwayRoom.class, 3f);
chances.put(MazeConnectionRoom.class, 1f);
}
public static ConnectionRoom createRoom(){
try {
return Random.chances(chances).newInstance();
} catch (Exception e) {
ShatteredPixelDungeon.reportException(e);
return null;
}
}
} }