public static List <RoomOutline> GenerateRoomOutlines(CellRect initialRect, Map map, int divisionsCount, int finalRoomsCount, int maxRoomCells) { List <RoomOutline> list = new List <RoomOutline>(); list.Add(new RoomOutline(initialRect)); for (int i = 0; i < divisionsCount; i++) { RoomOutline roomOutline; if (!(from x in list where x.CellsCountIgnoringWalls >= 32 select x).TryRandomElementByWeight((RoomOutline x) => (float)Mathf.Max(x.rect.Width, x.rect.Height), out roomOutline)) { break; } bool flag = roomOutline.rect.Height > roomOutline.rect.Width; if (!flag || roomOutline.rect.Height > 6) { if (flag || roomOutline.rect.Width > 6) { RoomOutlinesGenerator.Split(roomOutline, list, flag); } } } while (list.Any((RoomOutline x) => x.CellsCountIgnoringWalls > maxRoomCells)) { RoomOutline roomOutline2 = (from x in list where x.CellsCountIgnoringWalls > maxRoomCells select x).RandomElement <RoomOutline>(); bool horizontalWall = roomOutline2.rect.Height > roomOutline2.rect.Width; RoomOutlinesGenerator.Split(roomOutline2, list, horizontalWall); } while (list.Count > finalRoomsCount) { list.Remove(list.RandomElement <RoomOutline>()); } return(list); }