Skip to main content

BuildingRooms

A class in Root.Township, Alta.PAGaC.

PAGaC generation step that lays out random rooms in the tag grid, then carves doors, stairs and windows between them. Probably an editor or prototype tool; nothing outside PAGaC uses it.

Constructors​

MemberWhat it is
BuildingRooms()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

26 private and internal fields
MemberWhat it is
private Tag airThe empty tag, taken from the GenerationBase.
private Tag doorTag used for door cells.
private Tag floorTag used for floor cells.
private int floorHeightCells per storey.
private GenerationBase generationBaseThe base passed to the current Run.
private Generator generatorThe tag grid being written to.
private float loopChanceChance of also connecting to an already used neighbour on the same floor, making loops.
private int maximumAreaXZLargest allowed floor area for a room, in coarse cells; rooms outside the range are rerolled.
private int maximumRoomsUpper bound for the random room count (exclusive).
private int maximumSizeHorizontalUpper bound for a room's horizontal size in coarse cells.
private int maximumSizeVerticalUpper bound for a room's vertical size.
private int minimumAreaXZSmallest allowed floor area for a room, in coarse cells.
private int minimumRoomsLower bound for the random room count.
private int minimumSizeHorizontalLower bound for a room's horizontal size in coarse cells.
private int minimumSizeVerticalLower bound for a room's vertical size.
private List<BuildingRooms.RoomNode> nodesAll room nodes in the graph.
private float pathRandomElementSerialized but not read anywhere in this build.
private float pathRandomWeightingChance GetNext picks a random node. Never assigned, so always 0.
private int resolutionMultiplierGrid cells per coarse room cell horizontally.
private List<BuildingRooms.Room> roomsRooms generated in the current run.
private Tag stairTag used for stair cells.
private int stairBufferClear cells kept before and after a staircase.
private List<BuildingRooms.RoomNode> usedNodesNodes reached so far that may still branch.
private Tag wallTag used for wall cells.
private Tag windowTag used for window cells.
private float windowChanceChance of placing a window at each possible spot.

Properties​

MemberWhat it is
int SizeX { get; }Width of the generation grid.
int SizeY { get; }Height of the generation grid.
int SizeZ { get; }Depth of the generation grid.

Methods​

MemberWhat it is
override void Run(GenerationBase generationBase)Generates the rooms, tags walls, air and floors into the grid, then traverses the graph to add connections and windows.
12 private and internal methods
MemberWhat it is
private BuildingRooms.RoomNode Carve(BuildingRooms.RoomNode current)From one room node, picks a random unused (or, by loopChance, looping) neighbour and connects it; returns the next node or null.
private bool CreateConnection(BuildingRooms.RoomPath path)Connects two room nodes with a door if they are on the same floor, otherwise with stairs.
private bool CreateDoor(BuildingRooms.RoomPath path)Tries to tag a door cell in a random stretch of shared wall; fails if the cells around it aren't clear.
private BuildingRooms.RoomNode CreateRoom(bool isFloored, bool isExternal, int floor)Makes a room node for a floor and adds it to nodes.
private void CreateRoomNodes(int workingSizeX, int workingSizeY, int workingSizeZ)Builds the node graph: one external node per floor, plus one per floor of each room, with their grid extents.
private bool CreateStairs(BuildingRooms.RoomPath path)Tries to fit a staircase along a shared wall between two floors, avoiding existing stairs and doors.
private bool CreateWindow(BuildingRooms.RoomPath path)Tags window cells at random (by windowChance) along wall between an external node and a room on the same floor.
private BuildingRooms.RoomNode GetNext()Picks the next node to carve from: the most recently used, or rarely a random one.
private List<BuildingRooms.NodeRange> GetWalls(IEnumerable<Node> overlap, int minimumWall, Predicate<Node> predicate, int startResolution = 1, int startResolutionOffset = 0)Finds straight runs of overlap cells at least a given length, optionally filtered and aligned to a step.
private void OnDrawGizmos()Draws each room node's bounds as a wire box.
private void StartTraverse()Seeds traversal with the ground floor's external node and runs Traverse.
private void Traverse()Repeatedly carves paths out from used nodes until every reachable node has been visited.