diff --git a/DungeonMapGenerator/DungeonMapConsolePrinter/Program.cs b/DungeonMapGenerator/DungeonMapConsolePrinter/Program.cs index 17aae16..ea38424 100644 --- a/DungeonMapGenerator/DungeonMapConsolePrinter/Program.cs +++ b/DungeonMapGenerator/DungeonMapConsolePrinter/Program.cs @@ -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}" ); diff --git a/DungeonMapGenerator/DungeonMapConsolePrinter/bin/Debug/net9.0/DungeonMapConsolePrinter.dll b/DungeonMapGenerator/DungeonMapConsolePrinter/bin/Debug/net9.0/DungeonMapConsolePrinter.dll index 8cacfcc..c8b935d 100644 Binary files a/DungeonMapGenerator/DungeonMapConsolePrinter/bin/Debug/net9.0/DungeonMapConsolePrinter.dll and b/DungeonMapGenerator/DungeonMapConsolePrinter/bin/Debug/net9.0/DungeonMapConsolePrinter.dll differ diff --git a/DungeonMapGenerator/DungeonMapConsolePrinter/bin/Debug/net9.0/DungeonMapConsolePrinter.exe b/DungeonMapGenerator/DungeonMapConsolePrinter/bin/Debug/net9.0/DungeonMapConsolePrinter.exe index 504161b..a71fa11 100644 Binary files a/DungeonMapGenerator/DungeonMapConsolePrinter/bin/Debug/net9.0/DungeonMapConsolePrinter.exe and b/DungeonMapGenerator/DungeonMapConsolePrinter/bin/Debug/net9.0/DungeonMapConsolePrinter.exe differ diff --git a/DungeonMapGenerator/DungeonMapConsolePrinter/bin/Debug/net9.0/DungeonMapGenerator.dll b/DungeonMapGenerator/DungeonMapConsolePrinter/bin/Debug/net9.0/DungeonMapGenerator.dll index 7e2e81e..c229425 100644 Binary files a/DungeonMapGenerator/DungeonMapConsolePrinter/bin/Debug/net9.0/DungeonMapGenerator.dll and b/DungeonMapGenerator/DungeonMapConsolePrinter/bin/Debug/net9.0/DungeonMapGenerator.dll differ diff --git a/DungeonMapGenerator/DungeonMapGenerator/DungeonGenerator.cs b/DungeonMapGenerator/DungeonMapGenerator/DungeonGenerator.cs index 4ce00e2..6df7f11 100644 --- a/DungeonMapGenerator/DungeonMapGenerator/DungeonGenerator.cs +++ b/DungeonMapGenerator/DungeonMapGenerator/DungeonGenerator.cs @@ -42,57 +42,65 @@ namespace DungeonMapGenerator AddNormalRoomsAroundBossRoom(dungeonMap); AddConnectionRooms(dungeonMap); ConnectAllAdjacentRooms(dungeonMap); + AddAdjacentRoomsToEntranceRooms(dungeonMap); return dungeonMap; } - private void ConnectAllAdjacentRooms(DungeonMap dungeon) + private void AddAdjacentRoomsToEntranceRooms(DungeonMap dungeon) { - Dictionary pointRoomMapping = dungeon.GetPointRoomIdMapping(); - foreach (var room in dungeon.GetAllRooms()) + List entranceRooms = dungeon.GetEntranceRooms(); + List roomsToAddRoomsTowards = dungeon.GetNodeRooms(); + List obstructions = dungeon.GetRootRooms(); + + foreach (Room entranceRoom in entranceRooms) { - foreach ((Point p, RoomSide side) in room.GetAdjacentPoints()) + if (entranceRoom.GetAdjacentRooms().All(adjacent => adjacent.TypeOfRoom == RoomType.Entrance)) { - if (pointRoomMapping.ContainsKey(p)) + Room closestRoom = null; + foreach (RoomSide side in Enum.GetValues(typeof(RoomSide))) { - room.AddAdjacentRoom(pointRoomMapping[p]); + 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 List GetAdjacentPoints(Room room) -{ - var adjacentPoints = new List(); - - 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 ConnectAllAdjacentRooms(DungeonMap dungeon) + { + Dictionary pointRoomMapping = dungeon.GetPointRoomIdMapping(); + foreach (var room in dungeon.GetEntranceRooms()) + { + foreach ((Point p, RoomSide side) in room.GetAdjacentPoints()) + { + if (pointRoomMapping.TryGetValue(p, out var value)) + { + room.AddAdjacentRoom(value); + } + } + } + } 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 rootRooms = new List(dungeon.GetMonsterRooms()); - rootRooms.Add(dungeon.GetBossRoom()); + List rootRooms = dungeon.GetRootRooms(); // Create list of connection rooms Dictionary> nodeRoomAndSideItIsOn = dungeon.GetNodesWithSides(); diff --git a/DungeonMapGenerator/DungeonMapGenerator/DungeonMap.cs b/DungeonMapGenerator/DungeonMapGenerator/DungeonMap.cs index 79d856b..57d7355 100644 --- a/DungeonMapGenerator/DungeonMapGenerator/DungeonMap.cs +++ b/DungeonMapGenerator/DungeonMapGenerator/DungeonMap.cs @@ -221,6 +221,14 @@ namespace DungeonMapGenerator return nodeRooms; } + public List GetRootRooms() + { + List rootRooms = new List(); + rootRooms.AddRange(_monsterRooms); + rootRooms.Add(_bossRoom); + return rootRooms; + } + public Dictionary> GetNodesWithSides() { Dictionary> nodesWithSides = new Dictionary>(); diff --git a/DungeonMapGenerator/DungeonMapGenerator/bin/Debug/netstandard2.0/DungeonMapGenerator.dll b/DungeonMapGenerator/DungeonMapGenerator/bin/Debug/netstandard2.0/DungeonMapGenerator.dll index 7e2e81e..c229425 100644 Binary files a/DungeonMapGenerator/DungeonMapGenerator/bin/Debug/netstandard2.0/DungeonMapGenerator.dll and b/DungeonMapGenerator/DungeonMapGenerator/bin/Debug/netstandard2.0/DungeonMapGenerator.dll differ