Implemented adding very hard locks to dead ends and adding a couple hard locks
This commit is contained in:
parent
d7af8dc4c2
commit
40967e9510
22 changed files with 22069 additions and 4 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -8,6 +8,7 @@ namespace DungeonMapGenerator
|
||||||
public static class DungeonLockPopulator
|
public static class DungeonLockPopulator
|
||||||
{
|
{
|
||||||
private const float ACCEPTABLE_ERROR = .02f;
|
private const float ACCEPTABLE_ERROR = .02f;
|
||||||
|
private const int MAX_HARD_LOCKS = 3;
|
||||||
public static void PopulateLocksOfDungeon(DungeonMap dungeon)
|
public static void PopulateLocksOfDungeon(DungeonMap dungeon)
|
||||||
{
|
{
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
|
|
@ -25,13 +26,21 @@ namespace DungeonMapGenerator
|
||||||
entranceRoom.Lock = new Lock((entranceRoomLock.ToString()));
|
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)
|
while (currentRooms.Count > 0)
|
||||||
{
|
{
|
||||||
List<Room> locklessRooms = new List<Room>();
|
List<Room> locklessRooms = new List<Room>();
|
||||||
List<Room> alreadyLockedRooms = new List<Room>();
|
List<Room> alreadyLockedRooms = new List<Room>();
|
||||||
List<Room> adjacentRooms = 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 room in currentRooms.ToList())
|
||||||
{
|
{
|
||||||
foreach (Room adjacentRoom in room.GetAdjacentRooms())
|
foreach (Room adjacentRoom in room.GetAdjacentRooms())
|
||||||
|
|
@ -84,14 +93,25 @@ namespace DungeonMapGenerator
|
||||||
currentRooms = adjacentRooms;
|
currentRooms = adjacentRooms;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if all locks were set
|
int hardLocksAdded = 0;
|
||||||
foreach (var room in dungeon.GetAllRooms())
|
foreach (var room in dungeon.GetAllRooms())
|
||||||
{
|
{
|
||||||
|
// Check if all locks were set
|
||||||
if (room.Lock == null)
|
if (room.Lock == null)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Room at {room.GetCenterOfRoom()} wasn't seen whilst populating locks");
|
Console.WriteLine($"Room at {room.GetCenterOfRoom()} wasn't seen whilst populating locks");
|
||||||
room.Lock = Lock.NormalLocks[random.Next(0, Lock.NormalLocks.Count)];
|
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++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using DiceProbabilities;
|
using DiceProbabilities;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
|
@ -33,6 +35,27 @@ namespace DungeonMapGenerator
|
||||||
[JsonProperty("LockType")]
|
[JsonProperty("LockType")]
|
||||||
private string _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()
|
public Lock()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ namespace DungeonMapGenerator
|
||||||
|
|
||||||
[JsonProperty("AdjacentRoomIds")]
|
[JsonProperty("AdjacentRoomIds")]
|
||||||
private HashSet<int> _adjacentRoomIds = new HashSet<int>();
|
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>>();
|
private readonly Dictionary<RoomSide, List<Room>> _adjacentRoomsBySide = new Dictionary<RoomSide, List<Room>>();
|
||||||
|
|
||||||
public Room()
|
public Room()
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
1367
Dungeons/dungeon 30x20(02).json
Normal file
1367
Dungeons/dungeon 30x20(02).json
Normal file
File diff suppressed because it is too large
Load diff
1166
Dungeons/dungeon 30x20(03).json
Normal file
1166
Dungeons/dungeon 30x20(03).json
Normal file
File diff suppressed because it is too large
Load diff
1135
Dungeons/dungeon 30x20(04).json
Normal file
1135
Dungeons/dungeon 30x20(04).json
Normal file
File diff suppressed because it is too large
Load diff
1143
Dungeons/dungeon 30x20(05).json
Normal file
1143
Dungeons/dungeon 30x20(05).json
Normal file
File diff suppressed because it is too large
Load diff
1233
Dungeons/dungeon 30x20(06).json
Normal file
1233
Dungeons/dungeon 30x20(06).json
Normal file
File diff suppressed because it is too large
Load diff
1134
Dungeons/dungeon 30x20(07).json
Normal file
1134
Dungeons/dungeon 30x20(07).json
Normal file
File diff suppressed because it is too large
Load diff
1184
Dungeons/dungeon 30x20(08).json
Normal file
1184
Dungeons/dungeon 30x20(08).json
Normal file
File diff suppressed because it is too large
Load diff
1220
Dungeons/dungeon 30x20(09).json
Normal file
1220
Dungeons/dungeon 30x20(09).json
Normal file
File diff suppressed because it is too large
Load diff
1193
Dungeons/dungeon 30x20(10).json
Normal file
1193
Dungeons/dungeon 30x20(10).json
Normal file
File diff suppressed because it is too large
Load diff
1138
Dungeons/dungeon 30x20(11).json
Normal file
1138
Dungeons/dungeon 30x20(11).json
Normal file
File diff suppressed because it is too large
Load diff
10102
PuzzleGameProject/Assets/Scenes/LooksLikeItCouldBeGood.unity
Normal file
10102
PuzzleGameProject/Assets/Scenes/LooksLikeItCouldBeGood.unity
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,7 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 668d089d7832d1541bc7d61754599b94
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Loading…
Add table
Add a link
Reference in a new issue