orientation requirements

This commit is contained in:
2022-11-07 15:41:00 +01:00
parent 8719543f96
commit d9513f70b3
17 changed files with 133 additions and 19 deletions

View File

@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Escape_Room_Engine.Engine.Scripts.Modules;
using Escape_Room_Engine.Engine.Scripts.Requirements;
using Escape_Room_Engine.Engine.Scripts.Utilities;
using UnityEngine;
using Logger = Escape_Room_Engine.Engine.Scripts.Utilities.Logger;
@@ -94,17 +95,40 @@ namespace Escape_Room_Engine.Engine.Scripts
// place puzzle
var placementCandidates = space.rrDimensions.EveryPosition;
puzzle._description.PlacementRequirements.ForEach(requirement =>
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());
space.AddModule(puzzle);
}
else
{
Logger.Log("Could not find suitable placement for puzzle", LogType.PuzzleGeneration);
return;
}
// orient puzzle
HashSet<Orientation> orientationCandidates = Module.EveryOrientation;
Logger.Log($"orientation candidatesA: {string.Join(",", orientationCandidates.ToList().ConvertAll(c => c.ToString()))}", LogType.RequirementResolution);
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.Orient(orientationCandidates.RandomElement());
}
else
{
Logger.Log("Could not find suitable orientation for puzzle", LogType.PuzzleGeneration);
return;
}
space.AddModule(puzzle);
}
/// <summary>