Implemented adding rooms to entrance rooms that didn't have an adjacent non entrance room.
This commit is contained in:
parent
0d8fe18849
commit
807656b112
7 changed files with 51 additions and 35 deletions
|
|
@ -13,8 +13,8 @@ class Program
|
|||
var generator = new DungeonGenerator();
|
||||
|
||||
// Call the method you want to run
|
||||
int width = 30;
|
||||
int height = 20;
|
||||
int width = 100;
|
||||
int height = 50;
|
||||
DungeonMap map = generator.GenerateDungeon(width, height, 5);
|
||||
DungeonLockPopulator.PopulateLocksOfDungeon(map);
|
||||
DungeonMapSerializer.SerializeToFile(map, SAVED_DUNGEONS_PATH, $"{DUNGEON_NAME} {width}x{height}" );
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -42,57 +42,65 @@ namespace DungeonMapGenerator
|
|||
AddNormalRoomsAroundBossRoom(dungeonMap);
|
||||
AddConnectionRooms(dungeonMap);
|
||||
ConnectAllAdjacentRooms(dungeonMap);
|
||||
AddAdjacentRoomsToEntranceRooms(dungeonMap);
|
||||
|
||||
return dungeonMap;
|
||||
}
|
||||
|
||||
private void AddAdjacentRoomsToEntranceRooms(DungeonMap dungeon)
|
||||
{
|
||||
List<Room> entranceRooms = dungeon.GetEntranceRooms();
|
||||
List<Room> roomsToAddRoomsTowards = dungeon.GetNodeRooms();
|
||||
List<Room> obstructions = dungeon.GetRootRooms();
|
||||
|
||||
foreach (Room entranceRoom in entranceRooms)
|
||||
{
|
||||
if (entranceRoom.GetAdjacentRooms().All(adjacent => adjacent.TypeOfRoom == RoomType.Entrance))
|
||||
{
|
||||
Room closestRoom = null;
|
||||
foreach (RoomSide side in Enum.GetValues(typeof(RoomSide)))
|
||||
{
|
||||
Room closestRoomOnSide = FindClosestSeenConnection(entranceRoom, side, roomsToAddRoomsTowards, obstructions);
|
||||
if (closestRoomOnSide != null)
|
||||
{
|
||||
closestRoom = closestRoomOnSide;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (closestRoom != null)
|
||||
{
|
||||
dungeon.AddRooms(PlaceRoomsOrganicallyTowardRoom(
|
||||
entranceRoom,
|
||||
closestRoom,
|
||||
RoomType.Normal,
|
||||
dungeon.GetOccupiedPoints(),
|
||||
dungeon.GetUnoccupiedPoints()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ConnectAllAdjacentRooms(DungeonMap dungeon)
|
||||
{
|
||||
Dictionary<Point, Room> pointRoomMapping = dungeon.GetPointRoomIdMapping();
|
||||
foreach (var room in dungeon.GetAllRooms())
|
||||
foreach (var room in dungeon.GetEntranceRooms())
|
||||
{
|
||||
foreach ((Point p, RoomSide side) in room.GetAdjacentPoints())
|
||||
{
|
||||
if (pointRoomMapping.ContainsKey(p))
|
||||
if (pointRoomMapping.TryGetValue(p, out var value))
|
||||
{
|
||||
room.AddAdjacentRoom(pointRoomMapping[p]);
|
||||
room.AddAdjacentRoom(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<Point> GetAdjacentPoints(Room room)
|
||||
{
|
||||
var adjacentPoints = new List<Point>();
|
||||
|
||||
int x = room.PositionOfTopLeft.X;
|
||||
int y = room.PositionOfTopLeft.Y;
|
||||
int width = room.Width;
|
||||
int height = room.Height;
|
||||
|
||||
// Add points to the left and right of the room
|
||||
for (int i = 0; i < height; i++)
|
||||
{
|
||||
adjacentPoints.Add(new Point(x - 1, y + i)); // Left side
|
||||
adjacentPoints.Add(new Point(x + width, y + i)); // Right side
|
||||
}
|
||||
|
||||
// Add points above and below the room
|
||||
for (int i = 0; i < width; i++)
|
||||
{
|
||||
adjacentPoints.Add(new Point(x + i, y - 1)); // Top side
|
||||
adjacentPoints.Add(new Point(x + i, y + height)); // Bottom side
|
||||
}
|
||||
|
||||
return adjacentPoints;
|
||||
}
|
||||
|
||||
private void AddConnectionRooms(DungeonMap dungeon)
|
||||
{
|
||||
// For each room adjacent to a monster and boos room connect it with the closest thing (entrance room, or monster adjacent room)
|
||||
// unless there is something already going there.
|
||||
List<Room> rootRooms = new List<Room>(dungeon.GetMonsterRooms());
|
||||
rootRooms.Add(dungeon.GetBossRoom());
|
||||
List<Room> rootRooms = dungeon.GetRootRooms();
|
||||
|
||||
// Create list of connection rooms
|
||||
Dictionary<RoomSide, List<Room>> nodeRoomAndSideItIsOn = dungeon.GetNodesWithSides();
|
||||
|
|
|
|||
|
|
@ -221,6 +221,14 @@ namespace DungeonMapGenerator
|
|||
return nodeRooms;
|
||||
}
|
||||
|
||||
public List<Room> GetRootRooms()
|
||||
{
|
||||
List<Room> rootRooms = new List<Room>();
|
||||
rootRooms.AddRange(_monsterRooms);
|
||||
rootRooms.Add(_bossRoom);
|
||||
return rootRooms;
|
||||
}
|
||||
|
||||
public Dictionary<RoomSide, List<Room>> GetNodesWithSides()
|
||||
{
|
||||
Dictionary<RoomSide, List<Room>> nodesWithSides = new Dictionary<RoomSide, List<Room>>();
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue