Implemented adding very hard locks to dead ends and adding a couple hard locks

This commit is contained in:
Max 2025-02-20 08:35:03 +01:00
parent d7af8dc4c2
commit 40967e9510
22 changed files with 22069 additions and 4 deletions

View file

@ -8,6 +8,7 @@ namespace DungeonMapGenerator
public static class DungeonLockPopulator
{
private const float ACCEPTABLE_ERROR = .02f;
private const int MAX_HARD_LOCKS = 3;
public static void PopulateLocksOfDungeon(DungeonMap dungeon)
{
Random random = new Random();
@ -25,13 +26,21 @@ namespace DungeonMapGenerator
entranceRoom.Lock = new Lock((entranceRoomLock.ToString()));
}
// Give the dead ends very hard locks
foreach (Room room in dungeon.GetAllRooms().Except(currentRooms))
{
if (room.GetAdjacentRooms().Count() == 1)
{
room.Lock = Lock.GetRandomVeryHardLock();
}
}
while (currentRooms.Count > 0)
{
List<Room> locklessRooms = new List<Room>();
List<Room> alreadyLockedRooms = new List<Room>();
List<Room> adjacentRooms = new List<Room>();
// Get all adjacent rooms that haven't been locked at
foreach (Room room in currentRooms.ToList())
{
foreach (Room adjacentRoom in room.GetAdjacentRooms())
@ -84,14 +93,25 @@ namespace DungeonMapGenerator
currentRooms = adjacentRooms;
}
// Check if all locks were set
int hardLocksAdded = 0;
foreach (var room in dungeon.GetAllRooms())
{
// Check if all locks were set
if (room.Lock == null)
{
Console.WriteLine($"Room at {room.GetCenterOfRoom()} wasn't seen whilst populating locks");
room.Lock = Lock.NormalLocks[random.Next(0, Lock.NormalLocks.Count)];
}
// Add two hard locks
if (hardLocksAdded < MAX_HARD_LOCKS
&& room.TypeOfRoom == RoomType.Normal
&& room.GetAdjacentRooms().All(adjacent => adjacent.TypeOfRoom == RoomType.Normal)
&& (room.Lock.GetLock() == "4" || room.Lock.GetLock() == "10"))
{
room.Lock = Lock.GetRandomHardLock();
hardLocksAdded++;
}
}
}

View file

@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using DiceProbabilities;
using Newtonsoft.Json;
@ -33,6 +35,27 @@ namespace DungeonMapGenerator
[JsonProperty("LockType")]
private string _lockType;
public static Lock GetRandomVeryHardLock()
{
return GetRandomLockFromList(VeryHardLocks);
}
public static Lock GetRandomHardLock()
{
return GetRandomLockFromList(HardLocks);
}
public static Lock GetRandomNormalLock()
{
return GetRandomLockFromList(NormalLocks);
}
private static Lock GetRandomLockFromList(List<Lock> list)
{
Random random = new Random();
return new Lock(list[random.Next(0, list.Count())].GetLock());
}
public Lock()
{

View file

@ -35,7 +35,7 @@ namespace DungeonMapGenerator
[JsonProperty("AdjacentRoomIds")]
private HashSet<int> _adjacentRoomIds = new HashSet<int>();
private List<Room> _adjacentRooms = new List<Room>();
private HashSet<Room> _adjacentRooms = new HashSet<Room>();
private readonly Dictionary<RoomSide, List<Room>> _adjacentRoomsBySide = new Dictionary<RoomSide, List<Room>>();
public Room()

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

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 668d089d7832d1541bc7d61754599b94
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: