protected virtual bool PlaceExit(Room prev, float direction, float pathVariance) { var res = AttemptToPlaceRoom(prev, exit, direction + SeededRandom.Range(-pathVariance, pathVariance)); if (res != -1) { PlacedRooms.Add(exit); return(true); } else { return(false); } }
protected override bool PlaceExit(Room prev, float direction, float pathVariance) { var res = AttemptToPlaceRoom(prev, BossRoom, direction + SeededRandom.Range(-pathVariance, pathVariance)); if (res != -1) { PlacedRooms.Add(BossRoom); return(base.PlaceExit(BossRoom, direction, pathVariance)); } else { return(false); } }
public override bool Build(List <Room> rooms) { this.Rooms = rooms; InitBuilder(); if (entrance == null || exit == null) { return(false); } float direction = SeededRandom.RandomDirection(); entrance.SetSize(); entrance.Bounds.SetPosition(0, 0); PlacedRooms.Add(entrance); branchable.Add(entrance); int roomsOnPath = (int)(multiConnections.Count * pathLengthPercentage) + SeededRandom.PickRandom(pathLengthJitters); roomsOnPath = Math.Min(roomsOnPath, multiConnections.Count); float pathVariance = 15; var curr = entrance; float res; int rejected = 0; for (int i = 0; i < roomsOnPath; i++) { for (int j = 0; j < SeededRandom.PickRandom(pathConnectionLength); j++) { var connectionRoom = new ConnectionRoom(); res = AttemptToPlaceRoom(curr, connectionRoom, direction + SeededRandom.Range(-pathVariance, pathVariance)); if (res != -1) { PlacedRooms.Add(connectionRoom); branchable.Add(connectionRoom); curr = connectionRoom; } else { rejected++; } } var next = multiConnections[i]; res = AttemptToPlaceRoom(curr, next, direction + SeededRandom.Range(-pathVariance, pathVariance)); if (res != -1) { PlacedRooms.Add(next); branchable.Add(next); curr = next; } else { rejected++; } } for (int j = 0; j < SeededRandom.PickRandom(pathConnectionLength); j++) { var connectionRoom = new ConnectionRoom(); res = AttemptToPlaceRoom(curr, connectionRoom, direction + SeededRandom.Range(-pathVariance, pathVariance)); if (res != -1) { PlacedRooms.Add(connectionRoom); branchable.Add(connectionRoom); curr = connectionRoom; } else { rejected++; } } if (!PlaceExit(curr, direction, pathVariance)) { return(false); } var roomsToBranch = GetRoomsToBranch(roomsOnPath); CreateBranches(roomsToBranch); FindNeighbours(); return(true); }
public override bool Build(List <Room> rooms) { this.Rooms = rooms; InitBuilder(); if (entrance == null || exit == null) { return(false); } float startAngle = SeededRandom.RandomDirection(); entrance.SetSize(); entrance.Bounds.SetPosition(0, 0); PlacedRooms.Add(entrance); branchable.Add(entrance); var loop = new List <Room>(); int roomsOnPath = (int)(multiConnections.Count * pathLengthPercentage) + SeededRandom.PickRandom(pathLengthJitters); roomsOnPath = Math.Min(roomsOnPath, multiConnections.Count); for (int i = 0; i <= roomsOnPath; i++) { if (i == 0) { loop.Add(entrance); } else { loop.Add(multiConnections[0]); multiConnections.RemoveAt(0); } for (int j = 0; j < SeededRandom.PickRandom(pathConnectionLength); j++) { var newRoom = new ConnectionRoom(); loop.Add(newRoom); } } loop.Insert((loop.Count + 1) / 2, exit); var prev = entrance; float targetAngle; for (int i = 1; i < loop.Count; i++) { var curr = loop[i]; targetAngle = startAngle + TargetAngle(i / (float)loop.Count); var res = AttemptToPlaceRoom(prev, curr, targetAngle); if (res != -1) { PlacedRooms.Add(curr); prev = curr; branchable.Add(curr); } else if (!(curr is ConnectionRoom)) { //Little chance dependant, could be better return(false); } } //While not connected with the entrance, place connection rooms to connect //Also chance dependent. Should find better way to handle while (!prev.Connect(entrance)) { var c = new ConnectionRoom(); var angleToEntrance = GetAngleBetweenRooms(prev, entrance); if (AttemptToPlaceRoom(prev, c, angleToEntrance) == -1) { return(false); } loop.Add(c); PlacedRooms.Add(c); branchable.Add(c); prev = c; } UnityEngine.Debug.Log($"There are {loop.Count} rooms in the loop"); //Pass in 0 because we remove the rooms from multiconnection var roomsToBranch = GetRoomsToBranch(0); CreateBranches(roomsToBranch); FindNeighbours(); return(true); }