//Stitching together all the cellular automata rooms void CollateTiles() { //Figure out the dimensions of the dungeon int MostLeft = 0; int MostRight = 0; int MostUp = 0; int MostDown = 0; foreach (GrammarNode node in Nodes) { Vector3 pos = node.transform.position; if (pos.x < MostLeft) { MostLeft = (int)pos.x; } else if (pos.x > MostRight) { MostRight = (int)pos.x; } if (pos.z < MostDown) { MostDown = (int)pos.z; } else if (pos.z > MostUp) { MostUp = (int)pos.z; } } //Each node position is centered, so offset by half width(17) to get true dungeon size int SizeLeft = MostLeft; int SizeRight = MostRight; int SizeUp = MostUp; int SizeDown = MostDown; if (MostLeft < 8) { SizeLeft -= 8 + 1; // If size is below 0 add 1 to offset (-2 > 2 is a difference of 4 but -2x -> 2x is 5 spaces) } else { SizeLeft -= 8; } SizeRight += 8; if (MostDown < 8) { SizeDown -= 8 + 1; } else { SizeDown -= 8; } SizeUp += 8; DungeonWidth = SizeRight - SizeLeft; DungeonLength = SizeUp - SizeDown; DungeonOffset = new Vector3(SizeLeft + 1, 0, SizeDown + 1); Tiles = new CellularAutomata.Tile[DungeonWidth, DungeonLength]; //print("MostLeft: " + MostLeft + " MostRight: " + MostRight + " MostDown: " + MostDown + " MostUp: " + MostUp); //print("SizeLeft: " + SizeLeft + " SizeRight: " + SizeRight + " SizeDown: " + SizeDown + " SizeUp: " + SizeUp); //print("Dungeon Size: " + DungeonWidth + " " + DungeonLength); foreach (GrammarNode node in Nodes) { CellularAutomata cell = node.gameObject.GetComponent <CellularAutomata>(); Vector3 pos = cell.transform.position; for (int i = 0; i < 17; ++i) { for (int j = 0; j < 17; ++j) { Tiles[(int)pos.x + Mathf.Abs(MostLeft) + i, (int)pos.z + Mathf.Abs(MostDown) + j] = cell.GetTile(i, j); } } } }