v2.2.0: added a failure condition check for branch creation
This commit is contained in:
+3
-1
@@ -88,7 +88,9 @@ public class BranchesBuilder extends RegularBuilder {
|
|||||||
roomsToBranch.addAll(multiConnections);
|
roomsToBranch.addAll(multiConnections);
|
||||||
if (exit != null) roomsToBranch.add(exit);
|
if (exit != null) roomsToBranch.add(exit);
|
||||||
roomsToBranch.addAll(singleConnections);
|
roomsToBranch.addAll(singleConnections);
|
||||||
createBranches(rooms, branchable, roomsToBranch, branchTunnelChances);
|
if (!createBranches(rooms, branchable, roomsToBranch, branchTunnelChances)){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
findNeighbours(rooms);
|
findNeighbours(rooms);
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -241,7 +241,9 @@ public class FigureEightBuilder extends RegularBuilder {
|
|||||||
roomsToBranch.addAll(multiConnections);
|
roomsToBranch.addAll(multiConnections);
|
||||||
roomsToBranch.addAll(singleConnections);
|
roomsToBranch.addAll(singleConnections);
|
||||||
weightRooms(branchable);
|
weightRooms(branchable);
|
||||||
createBranches(rooms, branchable, roomsToBranch, branchTunnelChances);
|
if (!createBranches(rooms, branchable, roomsToBranch, branchTunnelChances)){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
findNeighbours(rooms);
|
findNeighbours(rooms);
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -82,7 +82,9 @@ public class LineBuilder extends RegularBuilder {
|
|||||||
roomsToBranch.addAll(multiConnections);
|
roomsToBranch.addAll(multiConnections);
|
||||||
roomsToBranch.addAll(singleConnections);
|
roomsToBranch.addAll(singleConnections);
|
||||||
weightRooms(branchable);
|
weightRooms(branchable);
|
||||||
createBranches(rooms, branchable, roomsToBranch, branchTunnelChances);
|
if (!createBranches(rooms, branchable, roomsToBranch, branchTunnelChances)){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
findNeighbours(rooms);
|
findNeighbours(rooms);
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -155,7 +155,9 @@ public class LoopBuilder extends RegularBuilder {
|
|||||||
roomsToBranch.addAll(multiConnections);
|
roomsToBranch.addAll(multiConnections);
|
||||||
roomsToBranch.addAll(singleConnections);
|
roomsToBranch.addAll(singleConnections);
|
||||||
weightRooms(branchable);
|
weightRooms(branchable);
|
||||||
createBranches(rooms, branchable, roomsToBranch, branchTunnelChances);
|
if (!createBranches(rooms, branchable, roomsToBranch, branchTunnelChances)){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
findNeighbours(rooms);
|
findNeighbours(rooms);
|
||||||
|
|
||||||
|
|||||||
+10
-2
@@ -144,7 +144,7 @@ public abstract class RegularBuilder extends 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 void createBranches(ArrayList<Room> rooms, ArrayList<Room> branchable,
|
protected boolean createBranches(ArrayList<Room> rooms, ArrayList<Room> branchable,
|
||||||
ArrayList<Room> roomsToBranch, float[] connChances){
|
ArrayList<Room> roomsToBranch, float[] connChances){
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@@ -152,9 +152,13 @@ public abstract class RegularBuilder extends Builder {
|
|||||||
int tries;
|
int tries;
|
||||||
Room curr;
|
Room curr;
|
||||||
ArrayList<Room> connectingRoomsThisBranch = new ArrayList<>();
|
ArrayList<Room> connectingRoomsThisBranch = new ArrayList<>();
|
||||||
|
int failedBranchAttempts = 0;
|
||||||
float[] connectionChances = connChances.clone();
|
float[] connectionChances = connChances.clone();
|
||||||
while (i < roomsToBranch.size()){
|
while (i < roomsToBranch.size()){
|
||||||
|
|
||||||
|
if (failedBranchAttempts > 100){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
Room r = roomsToBranch.get(i);
|
Room r = roomsToBranch.get(i);
|
||||||
|
|
||||||
@@ -197,6 +201,7 @@ public abstract class RegularBuilder extends Builder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (connectingRoomsThisBranch.size() != connectingRooms){
|
if (connectingRoomsThisBranch.size() != connectingRooms){
|
||||||
|
failedBranchAttempts++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,6 +219,7 @@ public abstract class RegularBuilder extends Builder {
|
|||||||
rooms.remove(t);
|
rooms.remove(t);
|
||||||
}
|
}
|
||||||
connectingRoomsThisBranch.clear();
|
connectingRoomsThisBranch.clear();
|
||||||
|
failedBranchAttempts++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,6 +238,8 @@ public abstract class RegularBuilder extends Builder {
|
|||||||
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected float randomBranchAngle( Room r ){
|
protected float randomBranchAngle( Room r ){
|
||||||
|
|||||||
Reference in New Issue
Block a user