requirements foundation

This commit is contained in:
2022-11-07 14:21:00 +01:00
parent 7e9331f612
commit 8719543f96
34 changed files with 332 additions and 160 deletions

View File

@@ -82,17 +82,31 @@ namespace Escape_Room_Engine.Engine.Scripts
// add puzzles
for (var i = 0; i < Utilities.Utilities.RandomInclusive(minPuzzleCount, maxPuzzleCount); i++)
{
var puzzle = new PuzzleModule(space, puzzleTypes.RandomElement());
puzzle.Place(new Vector2Int(
Random.Range(0, rrDimensions.width),
Random.Range(0, rrDimensions.length)
));
space.AddModule(puzzle);
GeneratePuzzle(space);
}
room.AddSpace(space, exit);
}
private void GeneratePuzzle(Space space)
{
var puzzle = new PuzzleModule(space, puzzleTypes.RandomElement());
// place puzzle
var placementCandidates = space.rrDimensions.EveryPosition;
puzzle._description.PlacementRequirements.ForEach(requirement =>
placementCandidates.IntersectWith(requirement.PlacementCandidates(puzzle, space)));
if (placementCandidates.Count > 0)
{
puzzle.Place(placementCandidates.RandomElement());
space.AddModule(puzzle);
}
else
{
Logger.Log("Could not find suitable placement for puzzle", LogType.PuzzleGeneration);
}
}
/// <summary>
/// Generate space dimensions that fit the required size constraints and cover the position of the entrance.
/// </summary>