private void ApplyRuinToFloor(int floor, float ruinLevel) { int ruinedArea = 0; int areaToRuin = 0; foreach (var room in building.rooms) { if (room.floor == floor) { areaToRuin += room.xSize * room.ySize; } } areaToRuin = (int)(areaToRuin * ruinLevel); int maxRuinAreaSize = (int)Mathf.Sqrt(areaToRuin / 4); while (ruinedArea < areaToRuin) { int newRuinAreaSizeX = Random.Range(1, maxRuinAreaSize + 1); int newRuinAreaSizeY = Random.Range(1, maxRuinAreaSize + 1); int posX = Random.Range(0, building.maxDimensions - 1 - newRuinAreaSizeX); int posY = Random.Range(0, building.maxDimensions - 1 - newRuinAreaSizeY); for (int x = posX; x < posX + newRuinAreaSizeX; x++) { for (int y = posY; y < posY + newRuinAreaSizeY; y++) { if (LevelGenGridUtils.IsNonStairsFloor(x, y, floor, building.grid)) { building.grid[floor, x, y] = "R"; ruinedArea++; } } } } ConnectOrphanedStairs(floor); EnsureStairsConnect(floor); }