MiningBaseGenerator
A class in Root.Township, the global namespace.
Server-side generator that builds a random mine base from StructurePart tiles on a grid and spawns them as child entities. It checks the space with physics first so parts avoid existing terrain.
- Listed in Global namespace: M to O
- Inherits or implements
GeneratedNetworkEntityBehaviour - Nested types
PartOption,Point,Possibility
Constructors
| Member | What it is |
|---|---|
MiningBaseGenerator() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
28 private and internal fields
| Member | What it is |
|---|---|
private const StructureSide AllSides | Constant flag set holding all six StructureSide directions. |
private MiningBaseGenerator.PartOption[] centerPieces | Weighted parts the generation can start from. |
private LayerMask collideWith | Layers that count as blocked when scanning the space. |
private int depth | Grid size along Z, in tiles. |
private float floorEdgeChance | Chance that each bottom-layer cell starts with open gates on all four horizontal sides. |
private int halfContinuationCount | Once more parts than this are placed, the chance of spreading further is halved. |
private int height | Grid size along Y, in tiles. |
private int[,] heights | Per column height array; reset each attempt. |
private const int HorizontalMask | Bit mask (15) for the four horizontal StructureSide flags. |
private StructureSide[,,] incomingAir | Per cell sides that neighbours say are open air. |
private StructureSide[,,] incomingGates | Per cell sides where a neighbour has an open gate. |
private StructureSide[,,] incomingRequireAir | Per cell sides where a neighbour needs air next to it. |
private StructureSide[,,] incomingRequireSolid | Per cell sides where a neighbour needs solid next to it. |
private StructureSide[,,] incomingSolid | Per cell sides that neighbours say are solid. |
private bool isRegenerating | Inspector button flag labelled Regenerate. |
private int maximumAttempts | How many generation attempts to make before giving up. |
private int maximumSpawned | An attempt fails if it places this many parts or more. |
private int minimumSpawned | An attempt fails if it places fewer parts than this. |
private MiningBaseGenerator.PartOption[] parts | Weighted parts used to fill out the base after the center piece. |
private List<MiningBaseGenerator.Point> priority | Cells to process before the normal queue. |
private List<MiningBaseGenerator.Point> queue | Cells waiting to have a part placed at them. |
private List<MiningBaseGenerator.Possibility> results | Placements chosen in the current attempt. |
private bool[,,] spacialAwareness | Per cell flags for cells already blocked by world geometry. |
private bool[,] spacialAwarenessFloor | Per column flags for whether ground was found below the bottom layer. |
private StructureType structureType | Structure type that supplies the tile size. |
private bool[,,] taken | Per cell flags for cells already filled. |
private float verticalCheckOffset | Height added to each cell's centre before the space checks. |
private int width | Grid size along X, in tiles. |
Methods
| Member | What it is |
|---|---|
bool CheckPossible(MiningBaseGenerator.Possibility possibility, out int pathCount, bool isForced = false) | Checks whether a part at a given offset and rotation fits the grid and matches the gate, solid and air rules of its neighbours; outputs how many gates connect. |
MiningBaseGenerator.PartOption GetRandom(MiningBaseGenerator.PartOption[] parts, SpawnData spawnData) | Weighted random pick: either a PartOption (chance plus biome attribute bonus) or an index into a possibility list. |
int GetRandom(List<MiningBaseGenerator.Possibility> possibilities) | Weighted random pick: either a PartOption (chance plus biome attribute bonus) or an index into a possibility list. |
StructureSide Rotate(StructureSide side, int rotations) | Rotates the horizontal bits of a StructureSide mask by a number of 90 degree steps, leaving up and down alone. |
protected override void Generate(SpawnData spawnData) | Server: scans the space, retries Attempt up to maximumAttempts times, then spawns the result if one succeeded. |
15 private and internal methods
| Member | What it is |
|---|---|
private void ApplySpacialAwareness() | Marks grid cells blocked by world geometry as taken and clears the floor flag where no ground was found below. Called at the start of each attempt. |
private bool Attempt(SpawnData spawnData) | Runs one full generation pass from a random center piece. Returns true if the part count lands between minimumSpawned and maximumSpawned. |
private void ChoosePossibility(MiningBaseGenerator.Point point, List<MiningBaseGenerator.Possibility> possibilities) | Picks a weighted random placement for a queued cell, discarding ones that don't fit, and marks the first one that does. |
private void CullResults() | Removes placed parts whose cubes connect to fewer gates than their MinimumGatesForCulling value. |
private List<MiningBaseGenerator.Possibility> GeneratePossibilities(MiningBaseGenerator.Point point, SpawnData spawnData) | Lists every part, rotation, drop and offset that could cover a grid cell, weighted by the part's chance and biome attribute. |
private void GenerateSpacialAwareness() | Box-casts each grid cell and raycasts down from the bottom layer to record which cells are blocked and which have ground under them. |
private void Mark(MiningBaseGenerator.Possibility possibility, float continuationChance = 1) | Records a placed part: marks its cells as taken and pushes its gate, solid and air sides onto neighbouring cells, maybe queueing them. |
private void MarkCenterPiece(SpawnData spawnData) | Places a random center piece at a random spot on the bottom layer, ignoring neighbour rules. |
private void MarkIncoming(int x, int y, int z, StructureSide outgoingSides, StructureSide[,,] map, float queueChance = -1) | Sets or clears the matching side flag on each neighbour of a cell in one of the incoming maps, and may queue that neighbour. |
private bool MatchAll(int x, int y, int z, StructureSide sides, StructureSide[,,] map) | True if every bit in one side mask is also set in the other (either the given sides or the map cell is the required set). |
private bool MatchAll(int x, int y, int z, StructureSide[,,] map, StructureSide sides) | True if every bit in one side mask is also set in the other (either the given sides or the map cell is the required set). |
private bool MatchAny(int x, int y, int z, StructureSide sides, StructureSide[,,] map) | True if any of the given sides is set in the map cell. |
private int NumberOfSetBits(int i) | Counts the set bits in an integer. Used to count connected gates when culling. |
private void Reset() | Clears results and queues and rebuilds the grid maps, with solid floor below, air inside and random floor-edge gates. |
private void SpawnResults(SpawnData spawnData) | Spawns each chosen part as a child entity and places it on the grid using the structure type's tile size. |