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));
            int         num         = 0;
            RoomOutline roomOutline = default(RoomOutline);

            while (num < divisionsCount && (from x in list
                                            where x.CellsCountIgnoringWalls >= 32
                                            select x).TryRandomElementByWeight <RoomOutline>((Func <RoomOutline, float>)((RoomOutline x) => (float)Mathf.Max(x.rect.Width, x.rect.Height)), out roomOutline))
            {
                bool flag = roomOutline.rect.Height > roomOutline.rect.Width;
                if ((!flag || roomOutline.rect.Height > 6) && (flag || roomOutline.rect.Width > 6))
                {
                    RoomOutlinesGenerator.Split(roomOutline, list, flag);
                }
                num++;
            }
            while (list.Any((RoomOutline x) => x.CellsCountIgnoringWalls > maxRoomCells))
            {
                RoomOutline roomOutline2 = (from x in list
                                            where x.CellsCountIgnoringWalls > maxRoomCells
                                            select x).RandomElement();
                bool horizontalWall = roomOutline2.rect.Height > roomOutline2.rect.Width;
                RoomOutlinesGenerator.Split(roomOutline2, list, horizontalWall);
            }
            while (list.Count > finalRoomsCount)
            {
                list.Remove(list.RandomElement());
            }
            return(list);
        }
Exemplo n.º 2
0
        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++)
            {
                if (!list.Where((RoomOutline x) => x.CellsCountIgnoringWalls >= 32).TryRandomElementByWeight((RoomOutline x) => Mathf.Max(x.rect.Width, x.rect.Height), out RoomOutline result))
                {
                    break;
                }
                bool flag = result.rect.Height > result.rect.Width;
                if ((!flag || result.rect.Height > 6) && (flag || result.rect.Width > 6))
                {
                    Split(result, list, flag);
                }
            }
            while (list.Any((RoomOutline x) => x.CellsCountIgnoringWalls > maxRoomCells))
            {
                RoomOutline roomOutline    = list.Where((RoomOutline x) => x.CellsCountIgnoringWalls > maxRoomCells).RandomElement();
                bool        horizontalWall = roomOutline.rect.Height > roomOutline.rect.Width;
                Split(roomOutline, list, horizontalWall);
            }
            while (list.Count > finalRoomsCount)
            {
                list.Remove(list.RandomElement());
            }
            return(list);
        }
 private static void Split(RoomOutline room, List <RoomOutline> allRooms, bool horizontalWall)
 {
     allRooms.Remove(room);
     if (horizontalWall)
     {
         int z = room.rect.CenterCell.z;
         allRooms.Add(new RoomOutline(new CellRect(room.rect.minX, room.rect.minZ, room.rect.Width, z - room.rect.minZ + 1)));
         allRooms.Add(new RoomOutline(new CellRect(room.rect.minX, z, room.rect.Width, room.rect.maxZ - z + 1)));
     }
     else
     {
         int x = room.rect.CenterCell.x;
         allRooms.Add(new RoomOutline(new CellRect(room.rect.minX, room.rect.minZ, x - room.rect.minX + 1, room.rect.Height)));
         allRooms.Add(new RoomOutline(new CellRect(x, room.rect.minZ, room.rect.maxX - x + 1, room.rect.Height)));
     }
 }
        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);
        }
 internal bool <> m__1(RoomOutline x)
 {
     return(x.CellsCountIgnoringWalls > this.maxRoomCells);
 }
 private static float <GenerateRoomOutlines> m__1(RoomOutline x)
 {
     return((float)Mathf.Max(x.rect.Width, x.rect.Height));
 }
 private static bool <GenerateRoomOutlines> m__0(RoomOutline x)
 {
     return(x.CellsCountIgnoringWalls >= 32);
 }