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