requirements for exit door

This commit is contained in:
2022-11-07 19:05:00 +01:00
parent 9e748a0f38
commit c2386d8d65
10 changed files with 95 additions and 71 deletions

View File

@@ -73,64 +73,19 @@ namespace Escape_Room_Engine.Engine.Scripts
// add exit
var exitDoor = new DoorModule(space, exitDoorTypes.RandomElement());
exitDoor.Place(new Vector2Int(
Random.Range(0, rrDimensions.width),
Random.Range(0, rrDimensions.length)
));
exitDoor.orientation = Module.EveryOrientation.RandomElement();
if (!space.AddModuleWithRequirements(exitDoor))
throw new Exception("Could not satisfy requirements for exit door.");
var exit = new Passage(exitDoor);
space.AddModule(exitDoor);
// add puzzles
for (var i = 0; i < Utilities.Utilities.RandomInclusive(minPuzzleCount, maxPuzzleCount); i++)
{
GeneratePuzzle(space);
space.AddModuleWithRequirements(new PuzzleModule(space, puzzleTypes.RandomElement()));
}
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.RequirementsOfType<PlacementRequirement>().ForEach(requirement =>
placementCandidates.IntersectWith(requirement.PlacementCandidates(puzzle, space)));
Logger.Log($"placement candidates: {string.Join(", ", placementCandidates.ToList().ConvertAll(c => c.ToString()))}", LogType.RequirementResolution);
if (placementCandidates.Count > 0)
{
puzzle.Place(placementCandidates.RandomElement());
}
else
{
Logger.Log("Could not find suitable placement for puzzle", LogType.PuzzleGeneration);
return;
}
// orient puzzle
var orientationCandidates = Module.EveryOrientation;
puzzle.description.RequirementsOfType<OrientationRequirement>().ForEach(requirement =>
orientationCandidates.IntersectWith(requirement.OrientationCandidates(puzzle, space)));
Logger.Log($"orientation candidates: {string.Join(",", orientationCandidates.ToList().ConvertAll(c => c.ToString()))}", LogType.RequirementResolution);
if (orientationCandidates.Count > 0)
{
puzzle.orientation = orientationCandidates.RandomElement();
}
else
{
Logger.Log("Could not find suitable orientation for puzzle", LogType.PuzzleGeneration);
return;
}
space.AddModule(puzzle);
}
/// <summary>
/// Generate space dimensions that fit the required size constraints and cover the position of the entrance.
/// </summary>