public override void ApplyToPath(IRandom rand, FloorPlan floorPlan) { List <RoomHallIndex> candBranchPoints = new List <RoomHallIndex>(); for (int ii = 0; ii < floorPlan.RoomCount; ii++) { candBranchPoints.Add(new RoomHallIndex(ii, false)); } // compute a goal amount of terminals to connect // this computation ignores the fact that some terminals may be impossible int connectionsLeft = this.ConnectFactor.Pick(rand) * candBranchPoints.Count / 2 / 100; while (candBranchPoints.Count > 0 && connectionsLeft > 0) { // choose random point to connect from int randIndex = rand.Next(candBranchPoints.Count); var chosenDestResult = ChooseConnection(rand, floorPlan, candBranchPoints); if (chosenDestResult is ListPathTraversalNode chosenDest) { // connect PermissiveRoomGen <T> hall = (PermissiveRoomGen <T>) this.GenericHalls.Pick(rand).Copy(); hall.PrepareSize(rand, chosenDest.Connector.Size); hall.SetLoc(chosenDest.Connector.Start); floorPlan.AddHall(hall, chosenDest.From, chosenDest.To); candBranchPoints.RemoveAt(randIndex); connectionsLeft--; GenContextDebug.DebugProgress("Added Connection"); // check to see if connection destination was also a candidate, // counting this as a double if so for (int jj = 0; jj < candBranchPoints.Count; jj++) { if (candBranchPoints[jj] == chosenDest.To) { candBranchPoints.RemoveAt(jj); connectionsLeft--; break; } } } else { // remove the list anyway, but don't call it a success candBranchPoints.RemoveAt(randIndex); } } }
public override void ApplyToPath(IRandom rand, FloorPlan floorPlan) { List <List <RoomHallIndex> > candBranchPoints = GetBranchArms(floorPlan); // remove the rooms that do not pass filter for (int xx = 0; xx < candBranchPoints.Count; xx++) { for (int yy = candBranchPoints[xx].Count - 1; yy >= 0; yy--) { IFloorRoomPlan plan = floorPlan.GetRoomHall(candBranchPoints[xx][yy]); if (!BaseRoomFilter.PassesAllFilters(plan, this.Filters)) { candBranchPoints[xx].RemoveAt(yy); } } } // compute a goal amount of branches to connect // this computation ignores the fact that some terminals may be impossible var randBin = new RandBinomial(candBranchPoints.Count, this.ConnectPercent); int connectionsLeft = randBin.Pick(rand); while (candBranchPoints.Count > 0 && connectionsLeft > 0) { // choose random point to connect from int randIndex = rand.Next(candBranchPoints.Count); var chosenDestResult = ChooseConnection(rand, floorPlan, candBranchPoints[randIndex]); if (chosenDestResult is ListPathTraversalNode chosenDest) { // connect PermissiveRoomGen <T> hall = (PermissiveRoomGen <T>) this.GenericHalls.Pick(rand).Copy(); hall.PrepareSize(rand, chosenDest.Connector.Size); hall.SetLoc(chosenDest.Connector.Start); floorPlan.AddHall(hall, this.Components.Clone(), chosenDest.From, chosenDest.To); candBranchPoints.RemoveAt(randIndex); connectionsLeft--; GenContextDebug.DebugProgress("Added Connection"); // check to see if connection destination was also a candidate, // counting this as a double if so for (int ii = candBranchPoints.Count - 1; ii >= 0; ii--) { for (int jj = 0; jj < candBranchPoints[ii].Count; jj++) { if (candBranchPoints[ii][jj] == chosenDest.To) { candBranchPoints.RemoveAt(ii); connectionsLeft--; break; } } } } else { // remove the list anyway, but don't call it a success candBranchPoints.RemoveAt(randIndex); } } }