This commit is contained in:
2022-12-15 23:29:02 +01:00
parent 95220bec08
commit 4f57b57a00
24 changed files with 1695 additions and 81 deletions

View File

@@ -22,7 +22,7 @@ namespace EscapeRoomEngine.Engine.Runtime
[InfoBox("If a space was generated without any puzzles in it, the engine will try generating another new space. To prevent infinite loops, the amount of retries is bound.")]
public int maxSpaceGenerationTries = 1000;
[Tooltip("The engine will try to generate a room that takes approximately this many seconds to complete.")]
public float initialTargetTime = 5 * 60;
public float initialTargetTime = 10 * 60;
public Vector3 roomOffset = new(0, 1000, 0);
[Required] public EngineTheme theme;
@@ -83,7 +83,11 @@ namespace EscapeRoomEngine.Engine.Runtime
var tries = 0;
Space space;
Passage exit = null;
var puzzle = PlanPuzzles();
// choose the next puzzle
// PlanPuzzles();
var puzzle = ChoosePuzzle();
GameControl.Instance.CurrentPuzzle = puzzle;
do
{
@@ -119,21 +123,41 @@ namespace EscapeRoomEngine.Engine.Runtime
room.AddSpace(space, exit);
}
/// <summary>
/// Updates the list of puzzles planned for this run and returns the puzzle to put in the next room.
/// </summary>
private PuzzleModuleDescription PlanPuzzles()
private PuzzleModuleDescription ChoosePuzzle()
{
var nextPuzzle = _plannedPuzzles.PopRandomElement();
EstimatedTimeRemaining = Measure.AverageTime(_plannedPuzzles);
return nextPuzzle;
// choose a puzzle from the plan and remove it from both the plan and later available puzzles (so it is only chosen once)
var puzzle = _plannedPuzzles.PopRandomElement();
_availablePuzzles.Remove(puzzle);
return puzzle;
}
#endregion
/// <summary>
/// Updates the list of puzzles planned for this run.
/// </summary>
public void PlanPuzzles()
{
var n = _availablePuzzles.Count;
var estimates = new int[n];
var indices = new Range(0, n).ToArray();
var target = Mathf.RoundToInt(GameControl.Instance.TargetTime - GameControl.Instance.EstimatedTimeRoom);
_plannedPuzzles = new List<PuzzleModuleDescription>();
for (var i = 0; i < n; i++)
{
estimates[i] = Mathf.RoundToInt(Measure.EstimateTime(_availablePuzzles[i]));
}
var chosen = Backtrack.Closest(indices, estimates, target);
foreach (var i in chosen)
{
_plannedPuzzles.Add(_availablePuzzles[i]);
}
EstimatedTimeRemaining = Measure.EstimateTime(_plannedPuzzles);
GameControl.Instance.PlannedPuzzles = _plannedPuzzles;
}
public void HidePreviousRoom(bool destroy = true)
{
if (NumberOfRooms > 2)