Implemented number population

This commit is contained in:
Max 2025-02-18 18:00:36 +01:00
parent fd1700d650
commit 2f1b2d49b3
21 changed files with 10030 additions and 18173 deletions

View file

@ -378,7 +378,7 @@ namespace DungeonMapGenerator
throw new Exception("Number of entrance lines cannot be greater than 4"); throw new Exception("Number of entrance lines cannot be greater than 4");
} }
const int numEntranceRooms = 12; const int numEntranceRooms = 11;
List<Room> entranceRooms = new List<Room>(); List<Room> entranceRooms = new List<Room>();
Random random = new Random(); Random random = new Random();
Dictionary<Side, int> sidesToEnterOn = new Dictionary<Side, int>() Dictionary<Side, int> sidesToEnterOn = new Dictionary<Side, int>()

View file

@ -43,7 +43,7 @@ namespace DungeonMapGenerator
} }
} }
} }
// Sort locked and not locked rooms // Sort locked and not locked rooms
foreach (Room adjacentRoom in adjacentRooms.ToList()) foreach (Room adjacentRoom in adjacentRooms.ToList())
{ {
@ -64,18 +64,35 @@ namespace DungeonMapGenerator
pregeneratedLocks.Add(room.Lock); pregeneratedLocks.Add(room.Lock);
} }
if (locklessRooms.Count > 0) if (locklessRooms.Count > 3)
{ {
// Add locks to the rooms with odds adding to within the difficulty range // Add locks to the rooms with odds adding to the desired success chance
List<Lock> locks = GenerateLocks(pregeneratedLocks, locklessRooms.Count, desiredSuccessChance); List<Lock> locks = GenerateLocks(pregeneratedLocks, locklessRooms.Count, desiredSuccessChance);
for (int i = 0; i < locklessRooms.Count; i++) for (int i = 0; i < locklessRooms.Count; i++)
{ {
locklessRooms[i].Lock = locks[i]; locklessRooms[i].Lock = locks[i];
} }
} }
else if (locklessRooms.Count > 0)
{
foreach (Room room in locklessRooms)
{
room.Lock = Lock.PossibleLocks[random.Next(0, Lock.PossibleLocks.Count)];
}
}
currentRooms = adjacentRooms; currentRooms = adjacentRooms;
} }
// Check if all locks were set
foreach (var room in dungeon.GetAllRooms())
{
if (room.Lock == null)
{
Console.WriteLine($"Room at {room.GetCenterOfRoom()} wasn't seen whilst populating locks");
room.Lock = Lock.PossibleLocks[random.Next(0, Lock.PossibleLocks.Count)];
}
}
} }
private static List<Lock> GenerateLocks(List<Lock> pregeneratedLocks, int numLocks, float successChance) private static List<Lock> GenerateLocks(List<Lock> pregeneratedLocks, int numLocks, float successChance)

View file

@ -132,19 +132,35 @@ namespace DungeonMapGenerator
{ {
return new HashSet<Point>(_occupiedPoints); return new HashSet<Point>(_occupiedPoints);
} }
public string GetMapAsString() public string GetMapAsString()
{
return GetMapAsString(null);
}
public string GetMapAsString(List<Room> roomsToHighlight)
{ {
List<Point> monsterRoomPoints = _monsterRooms.SelectMany(room => room.GetPointsInRoom()).ToList(); List<Point> monsterRoomPoints = _monsterRooms.SelectMany(room => room.GetPointsInRoom()).ToList();
List<Point> entranceRoomPoints = _entranceRooms.SelectMany(room => room.GetPointsInRoom()).ToList(); List<Point> entranceRoomPoints = _entranceRooms.SelectMany(room => room.GetPointsInRoom()).ToList();
List<Point> normalRoomPoints = _normalRooms.SelectMany(room => room.GetPointsInRoom()).ToList(); List<Point> normalRoomPoints = _normalRooms.SelectMany(room => room.GetPointsInRoom()).ToList();
List<Point> highlightRoomPoints = new List<Point>();
if (roomsToHighlight != null)
{
highlightRoomPoints = roomsToHighlight.SelectMany(room => room.GetPointsInRoom()).ToList();
}
char[,] mapMatrix = new Char[Width, Height]; char[,] mapMatrix = new Char[Width, Height];
for (int x = 0; x < Width; x++) for (int x = 0; x < Width; x++)
{ {
for (int y = 0; y < Height; y++) for (int y = 0; y < Height; y++)
{ {
Point point = new Point(x, y); Point point = new Point(x, y);
if (entranceRoomPoints.Contains(point)) if (highlightRoomPoints.Contains(point))
{
mapMatrix[x, y] = 'O';
}
else if (entranceRoomPoints.Contains(point))
{ {
mapMatrix[x, y] = '*'; mapMatrix[x, y] = '*';
} }

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff