Struct RoomCorridorSettings
Immutable settings for the Room-and-Corridor map generation algorithm.
Inherited Members
Namespace: Scylla.Core.Util.ProceduralMapGen
Assembly: ScyllaCore.dll
Syntax
public readonly struct RoomCorridorSettings
Remarks
The Room-and-Corridor algorithm places rectangular rooms randomly within the grid, then connects them using a Minimum Spanning Tree (MST) so that every room is reachable. Additional loop corridors can be added via ExtraCorridorRatio to create a less tree-like, more interesting layout.
Each dimension of a generated room is sampled uniformly from [MinRoomWidth, MaxRoomWidth] and [MinRoomHeight, MaxRoomHeight]. Rooms are rejected if they would overlap an existing room (accounting for MinRoomSpacing); after MaxPlacementAttempts consecutive failures the room is skipped and the algorithm moves on to the next one.
Use CorridorStyle to choose between clean L-shaped corridors (LShaped) and more organic winding corridors (Winding). When winding style is selected, supply a WindingCorridorSettings via WindingSettings to control the jog count and perpendicular offset range.
Pass the completed settings struct as the first argument to RoomAndCorridor(ScyllaSquareGrid<int>, RoomCorridorSettings, MapGenSettings, IRandomSource). Use one of the built-in static presets (Default, Dense, Sparse) as a starting point and create custom instances via the constructor.
Constructors
RoomCorridorSettings(int, int, int, int, int, int, float, int, int, CorridorStyle, WindingCorridorSettings)
Initializes a new RoomCorridorSettings with the specified parameters.
Declaration
public RoomCorridorSettings(int roomCount = 10, int minRoomWidth = 4, int minRoomHeight = 4, int maxRoomWidth = 12, int maxRoomHeight = 12, int minRoomSpacing = 1, float extraCorridorRatio = 0.15, int corridorWidth = 1, int maxPlacementAttempts = 100, CorridorStyle corridorStyle = CorridorStyle.LShaped, WindingCorridorSettings windingSettings = default)
Parameters
| Type | Name | Description |
|---|---|---|
| int | roomCount | Number of rooms to attempt placing. The actual placed count may be lower if the
grid is too small or |
| int | minRoomWidth | Minimum room width in cells (inclusive). Must be at least |
| int | minRoomHeight | Minimum room height in cells (inclusive). Must be at least |
| int | maxRoomWidth | Maximum room width in cells (inclusive). Must be >= |
| int | maxRoomHeight | Maximum room height in cells (inclusive). Must be >= |
| int | minRoomSpacing | Minimum number of empty cells between room edges. Use |
| float | extraCorridorRatio | Fraction of additional loop corridors beyond the MST. |
| int | corridorWidth | Width of each carved corridor in cells. Defaults to |
| int | maxPlacementAttempts | Maximum random placement attempts per room before skipping it. Higher values
increase placement success on crowded grids at a computation cost. Defaults to |
| CorridorStyle | corridorStyle | The corridor carving style. Defaults to LShaped. |
| WindingCorridorSettings | windingSettings | Winding corridor settings, only applied when |
Fields
CorridorStyle
The corridor carving style applied when connecting rooms.
Declaration
public readonly CorridorStyle CorridorStyle
Field Value
| Type | Description |
|---|---|
| CorridorStyle |
Remarks
- LShaped - corridors make a single right-angle bend: first horizontal then vertical (or vice versa, chosen randomly). This is the default and produces predictable, clean layouts.
- Winding - corridors include multiple random waypoints with perpendicular jogs, producing a more organic, cave-like appearance. Configure the jog parameters via WindingSettings.
See Also
CorridorWidth
Width of each carved corridor in cells.
Declaration
public readonly int CorridorWidth
Field Value
| Type | Description |
|---|---|
| int |
Remarks
A value of 1 produces single-cell-wide corridors. A value of 2 doubles
the corridor width, which can improve navigability but increases floor coverage
significantly on dense maps.
Default
Default preset: 10 rooms of moderate size (4-12 cells) with 1-cell spacing, 1-cell-wide L-shaped corridors, and 15 % extra loop corridors beyond the MST.
Declaration
public static readonly RoomCorridorSettings Default
Field Value
| Type | Description |
|---|---|
| RoomCorridorSettings |
Remarks
Suitable as a balanced starting point for dungeon layouts. Adjust ExtraCorridorRatio upward to increase inter-room loop density, or increase RoomCount for more rooms.
Dense
Dense preset: 18 small rooms (3-8 cells) with tight 1-cell spacing and 30 % extra corridors, producing a busy, highly connected dungeon.
Declaration
public static readonly RoomCorridorSettings Dense
Field Value
| Type | Description |
|---|---|
| RoomCorridorSettings |
Remarks
Use this preset on larger grids; on small grids the high room count will cause many placement failures, resulting in fewer actual rooms than requested.
ExtraCorridorRatio
Fraction of extra loop corridors added beyond the MST skeleton.
Declaration
public readonly float ExtraCorridorRatio
Field Value
| Type | Description |
|---|---|
| float |
Remarks
After connecting all rooms via a Minimum Spanning Tree (guaranteeing full
reachability with the minimum edge count), additional edges from the complete
graph are randomly selected and carved as corridors to create loops.
The number of extra corridors is approximately
(roomCount - 1) * ExtraCorridorRatio.
A value of 0.0 produces a pure tree (no loops, dead ends at every
non-junction corridor). A value of 0.15 adds roughly 15 % more corridors.
A value of 1.0 would attempt to add as many extra corridors as there are
MST edges. Typical useful range is 0.0-0.5.
MaxPlacementAttempts
Maximum number of random placement attempts the algorithm makes for each room before giving up on that room and moving to the next.
Declaration
public readonly int MaxPlacementAttempts
Field Value
| Type | Description |
|---|---|
| int |
Remarks
Higher values increase the likelihood that all RoomCount rooms are placed, at the cost of additional computation for packed layouts. Values in the range 50-200 are typical. If RoomCount is high relative to the grid area, some rooms will inevitably be skipped regardless of this value.
MaxRoomHeight
Maximum room height in cells (inclusive).
Declaration
public readonly int MaxRoomHeight
Field Value
| Type | Description |
|---|---|
| int |
Remarks
Each generated room's height is sampled uniformly from [MinRoomHeight, MaxRoomHeight]. Must be at least as large as MinRoomHeight.
MaxRoomWidth
Maximum room width in cells (inclusive).
Declaration
public readonly int MaxRoomWidth
Field Value
| Type | Description |
|---|---|
| int |
Remarks
Each generated room's width is sampled uniformly from [MinRoomWidth, MaxRoomWidth]. Must be at least as large as MinRoomWidth.
MinRoomHeight
Minimum room height in cells (inclusive).
Declaration
public readonly int MinRoomHeight
Field Value
| Type | Description |
|---|---|
| int |
Remarks
Each generated room's height is sampled uniformly from [MinRoomHeight, MaxRoomHeight]. Must be at least 1 and no greater than MaxRoomHeight.
MinRoomSpacing
Minimum number of empty cells required between the edges of any two rooms.
Declaration
public readonly int MinRoomSpacing
Field Value
| Type | Description |
|---|---|
| int |
Remarks
A value of 0 allows rooms to touch wall-to-wall. A value of 1
(the default) ensures at least one empty wall cell separates every pair of rooms.
Higher values produce sparser, more corridor-heavy layouts.
MinRoomWidth
Minimum room width in cells (inclusive).
Declaration
public readonly int MinRoomWidth
Field Value
| Type | Description |
|---|---|
| int |
Remarks
Each generated room's width is sampled uniformly from [MinRoomWidth, MaxRoomWidth]. Must be at least 1 and no greater than MaxRoomWidth.
RoomCount
The number of rooms the algorithm attempts to place.
Declaration
public readonly int RoomCount
Field Value
| Type | Description |
|---|---|
| int |
Remarks
Each room generates up to MaxPlacementAttempts random candidate positions. If no valid position is found within that budget the room is skipped, so the actual placed count may be lower than this value on dense or small grids.
Sparse
Sparse preset: 5 large rooms (6-16 cells) with 3-cell spacing, 2-cell-wide corridors, and no extra corridors (pure MST tree connectivity).
Declaration
public static readonly RoomCorridorSettings Sparse
Field Value
| Type | Description |
|---|---|
| RoomCorridorSettings |
Remarks
Produces an open, palace-like layout where every room is connected by exactly one corridor path. Combine with Sparse for a sparse-door dungeon feel.
WindingSettings
Settings controlling the number and amplitude of jogs in winding corridors.
Declaration
public readonly WindingCorridorSettings WindingSettings
Field Value
| Type | Description |
|---|---|
| WindingCorridorSettings |
Remarks
This field is only used when CorridorStyle is set to Winding. When LShaped is selected, this field is ignored entirely.
When enabling winding corridors, pass
Default or a custom
WindingCorridorSettings instance. Passing the C# default
keyword zero-initializes the struct, which will fall back to safe internal
defaults but may produce corridors with no jogs.
See Also
Methods
Lerp(RoomCorridorSettings, RoomCorridorSettings, float)
Linearly interpolates between two RoomCorridorSettings instances and returns a new blended settings struct.
Declaration
public static RoomCorridorSettings Lerp(RoomCorridorSettings a, RoomCorridorSettings b, float t)
Parameters
| Type | Name | Description |
|---|---|---|
| RoomCorridorSettings | a | Start settings returned when |
| RoomCorridorSettings | b | End settings returned when |
| float | t | Interpolation factor. Values outside [0, 1] are clamped before use. |
Returns
| Type | Description |
|---|---|
| RoomCorridorSettings | A new RoomCorridorSettings whose numeric fields are linearly
blended between |
Remarks
Integer fields (RoomCount, MinRoomWidth, MinRoomHeight, MaxRoomWidth, MaxRoomHeight, MinRoomSpacing, CorridorWidth, MaxPlacementAttempts) are interpolated as floats and rounded to the nearest integer.
The CorridorStyle enum cannot be meaningfully interpolated; it
takes the value from a when t < 0.5 and from
b when t >= 0.5.
WindingSettings is interpolated recursively via Lerp(WindingCorridorSettings, WindingCorridorSettings, float).