room size generation takes into account door module size
This commit is contained in:
@@ -6,6 +6,7 @@ using UnityEngine;
|
|||||||
using Logger = EscapeRoomEngine.Engine.Runtime.Utilities.Logger;
|
using Logger = EscapeRoomEngine.Engine.Runtime.Utilities.Logger;
|
||||||
using LogType = EscapeRoomEngine.Engine.Runtime.Utilities.LogType;
|
using LogType = EscapeRoomEngine.Engine.Runtime.Utilities.LogType;
|
||||||
using Object = UnityEngine.Object;
|
using Object = UnityEngine.Object;
|
||||||
|
using Range = EscapeRoomEngine.Engine.Runtime.Utilities.Range;
|
||||||
|
|
||||||
namespace EscapeRoomEngine.Engine.Runtime
|
namespace EscapeRoomEngine.Engine.Runtime
|
||||||
{
|
{
|
||||||
@@ -145,50 +146,50 @@ namespace EscapeRoomEngine.Engine.Runtime
|
|||||||
/// <returns>A room relative (<i>RR</i>) placement with the generated dimensions. Always faces North.</returns>
|
/// <returns>A room relative (<i>RR</i>) placement with the generated dimensions. Always faces North.</returns>
|
||||||
private static Placement GenerateSpaceDimensions(Passage entrance, Vector3Int minSize, Vector3Int availableSpace)
|
private static Placement GenerateSpaceDimensions(Passage entrance, Vector3Int minSize, Vector3Int availableSpace)
|
||||||
{
|
{
|
||||||
var xMin = -1;
|
var x = new Range(-1, -1);
|
||||||
var xMax = -1;
|
var z = new Range(-1, -1);
|
||||||
var zMin = -1;
|
|
||||||
var zMax = -1;
|
|
||||||
var door = entrance.fromOut;
|
var door = entrance.fromOut;
|
||||||
var position = door.RrPosition;
|
var position = door.RrPosition;
|
||||||
|
var bottomLeft = door.srPlacement.BottomLeft;
|
||||||
|
var doorSize = door.Size;
|
||||||
|
|
||||||
// fix the side the door is facing away from
|
// fix the side the door is facing away from
|
||||||
switch (door.Orientation)
|
switch (door.Orientation)
|
||||||
{
|
{
|
||||||
case Orientation.North:
|
case Orientation.North:
|
||||||
zMin = position.z;
|
z.min = position.z;
|
||||||
zMax = Utilities.Utilities.RandomInclusive(zMin + minSize.z, availableSpace.z);
|
z.max = Utilities.Utilities.RandomInclusive(z.min + minSize.z, availableSpace.z);
|
||||||
break;
|
break;
|
||||||
case Orientation.East:
|
case Orientation.East:
|
||||||
xMin = position.x;
|
x.min = position.x;
|
||||||
xMax = Utilities.Utilities.RandomInclusive(xMin + minSize.x, availableSpace.x);
|
x.max = Utilities.Utilities.RandomInclusive(x.min + minSize.x, availableSpace.x);
|
||||||
break;
|
break;
|
||||||
case Orientation.South:
|
case Orientation.South:
|
||||||
zMax = position.z + 1;
|
z.max = position.z + 1;
|
||||||
zMin = Utilities.Utilities.RandomInclusive(0, zMax - minSize.z);
|
z.min = Utilities.Utilities.RandomInclusive(0, z.max - minSize.z);
|
||||||
break;
|
break;
|
||||||
case Orientation.West:
|
case Orientation.West:
|
||||||
xMax = position.x + 1;
|
x.max = position.x + 1;
|
||||||
xMin = Utilities.Utilities.RandomInclusive(0, xMax - minSize.x);
|
x.min = Utilities.Utilities.RandomInclusive(0, x.max - minSize.x);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException();
|
throw new ArgumentOutOfRangeException();
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculate remaining values if they haven't been covered by the switch statement yet
|
// calculate remaining values if they haven't been covered by the switch statement yet
|
||||||
if(xMin == -1)
|
if(x.min == -1)
|
||||||
xMin = Utilities.Utilities.RandomInclusive(0, Math.Min(position.x, availableSpace.x - minSize.x));
|
x.min = Utilities.Utilities.RandomInclusive(0, Math.Min(bottomLeft.x, availableSpace.x - minSize.x));
|
||||||
if(xMax == -1)
|
if(x.max == -1)
|
||||||
xMax = Utilities.Utilities.RandomInclusive(Math.Max(position.x + 1, xMin + minSize.x), availableSpace.x);
|
x.max = Utilities.Utilities.RandomInclusive(Math.Max(bottomLeft.x + doorSize.x, x.min + minSize.x), availableSpace.x);
|
||||||
if(zMin == -1)
|
if(z.min == -1)
|
||||||
zMin = Utilities.Utilities.RandomInclusive(0, Math.Min(position.z, availableSpace.z - minSize.z));
|
z.min = Utilities.Utilities.RandomInclusive(0, Math.Min(bottomLeft.z, availableSpace.z - minSize.z));
|
||||||
if(zMax == -1)
|
if(z.max == -1)
|
||||||
zMax = Utilities.Utilities.RandomInclusive(Math.Max(position.z + 1, zMin + minSize.z), availableSpace.z);
|
z.max = Utilities.Utilities.RandomInclusive(Math.Max(bottomLeft.z + doorSize.x, z.min + minSize.z), availableSpace.z);
|
||||||
|
|
||||||
var dimensions = new Placement
|
var dimensions = new Placement
|
||||||
{
|
{
|
||||||
position = new Vector3Int(xMin, 0, zMin),
|
position = new Vector3Int(x.min, 0, z.min),
|
||||||
size = new Vector2Int(xMax - xMin, zMax - zMin)
|
size = new Vector2Int(x.Length, z.Length)
|
||||||
};
|
};
|
||||||
|
|
||||||
Logger.Log($"Generated space dimensions {dimensions} from entrance position {position}", LogType.RoomGeneration);
|
Logger.Log($"Generated space dimensions {dimensions} from entrance position {position}", LogType.RoomGeneration);
|
||||||
|
|||||||
Reference in New Issue
Block a user