Exemplo n.º 1
0
        private static void build_warren(EventHandler callback)
        {
            MapBuilder.begin_map();
            int num = 0;

            while (MapBuilder.fMap.Areas.Count < MapBuilder.fData.MaxAreaCount && MapBuilder.fEndpoints.Count != 0 && num != 100)
            {
                int      num1 = Session.Random.Next() % MapBuilder.fEndpoints.Count;
                Endpoint item = MapBuilder.fEndpoints[num1];
                bool     flag = true;
                switch (Session.Random.Next() % 10)
                {
                case 0:
                case 1:
                case 2:
                {
                    try
                    {
                        flag = MapBuilder.add_area(item);
                        break;
                    }
                    catch (Exception exception)
                    {
                        LogSystem.Trace(exception);
                        flag = false;
                        break;
                    }
                }

                case 3:
                case 4:
                case 5:
                case 6:
                case 7:
                {
                    try
                    {
                        flag = MapBuilder.add_corridor(item, false);
                        break;
                    }
                    catch (Exception exception1)
                    {
                        LogSystem.Trace(exception1);
                        flag = false;
                        break;
                    }
                }

                case 8:
                {
                    try
                    {
                        if (item.Category != TileCategory.Doorway)
                        {
                            flag = MapBuilder.add_doorway(item);
                        }
                        break;
                    }
                    catch (Exception exception2)
                    {
                        LogSystem.Trace(exception2);
                        flag = false;
                        break;
                    }
                }

                case 9:
                {
                    try
                    {
                        flag = MapBuilder.add_stairway(item);
                        break;
                    }
                    catch (Exception exception3)
                    {
                        LogSystem.Trace(exception3);
                        flag = false;
                        break;
                    }
                }
                }
                if (!flag)
                {
                    num++;
                }
                else
                {
                    MapBuilder.fEndpoints.Remove(item);
                    num = 0;
                    callback(null, null);
                }
            }
            List <TileData> tileDatas = new List <TileData>();

            foreach (TileData tile in MapBuilder.fMap.Tiles)
            {
                Tile tile1 = Session.FindTile(tile.TileID, SearchType.Global);
                if (tile1 != null)
                {
                    if (tile1.Category != TileCategory.Doorway)
                    {
                        continue;
                    }
                    Rectangle _rect = MapBuilder.get_rect(tile1, tile);
                    int       num2  = 0;
                    int       left  = _rect.Left;
                    while (left != _rect.Right)
                    {
                        int top = _rect.Top - 1;
                        if (MapBuilder.tile_at_point(new Point(left, top)) != null)
                        {
                            left++;
                        }
                        else
                        {
                            num2++;
                            break;
                        }
                    }
                    int left1 = _rect.Left;
                    while (left1 != _rect.Right)
                    {
                        int bottom = _rect.Bottom + 1;
                        if (MapBuilder.tile_at_point(new Point(left1, bottom)) != null)
                        {
                            left1++;
                        }
                        else
                        {
                            num2++;
                            break;
                        }
                    }
                    int top1 = _rect.Top;
                    while (top1 != _rect.Bottom)
                    {
                        int left2 = _rect.Left - 1;
                        if (MapBuilder.tile_at_point(new Point(left2, top1)) != null)
                        {
                            top1++;
                        }
                        else
                        {
                            num2++;
                            break;
                        }
                    }
                    int top2 = _rect.Top;
                    while (top2 != _rect.Bottom)
                    {
                        int right = _rect.Right + 1;
                        if (MapBuilder.tile_at_point(new Point(right, top2)) != null)
                        {
                            top2++;
                        }
                        else
                        {
                            num2++;
                            break;
                        }
                    }
                    if (num2 == 2)
                    {
                        continue;
                    }
                    tileDatas.Add(tile);
                }
                else
                {
                    tileDatas.Add(tile);
                }
            }
            foreach (TileData tileData in tileDatas)
            {
                MapBuilder.fMap.Tiles.Remove(tileData);
                callback(null, null);
            }
        }
Exemplo n.º 2
0
        private static void build_filled_area(EventHandler callback)
        {
            List <Tile> tiles  = new List <Tile>();
            List <Tile> tiles1 = new List <Tile>();

            foreach (Library library in MapBuilder.fData.Libraries)
            {
                foreach (Tile tile in library.Tiles)
                {
                    if (tile.Category != TileCategory.Plain && tile.Category != TileCategory.Feature)
                    {
                        continue;
                    }
                    tiles.Add(tile);
                    if (tile.Area != 1)
                    {
                        continue;
                    }
                    tiles1.Add(tile);
                }
            }
            if (tiles.Count == 0 || tiles1.Count == 0)
            {
                return;
            }
            MapArea mapArea = new MapArea()
            {
                Name   = "Area",
                Region = new Rectangle(0, 0, MapBuilder.fData.Width, MapBuilder.fData.Height)
            };

            MapBuilder.fMap.Areas.Add(mapArea);
            int area = 0;
            int num  = 0;

            do
            {
                bool        flag      = Session.Random.Next(20) == 0;
                List <Tile> tiles2    = (flag ? tiles1 : tiles);
                int         num1      = Session.Random.Next(tiles2.Count);
                Tile        item      = tiles2[num1];
                TileData    tileDatum = new TileData()
                {
                    TileID    = item.ID,
                    Rotations = Session.Random.Next(4)
                };
                int width  = item.Size.Width;
                int height = item.Size.Height;
                if (tileDatum.Rotations == 1 || tileDatum.Rotations == 3)
                {
                    width  = item.Size.Height;
                    height = item.Size.Width;
                }
                List <Point> points = new List <Point>();
                if (!flag)
                {
                    int num2 = (item.Area < 4 ? 1 : 2);
                    for (int i = 0; i <= MapBuilder.fData.Width; i += num2)
                    {
                        for (int j = 0; j <= MapBuilder.fData.Height; j += num2)
                        {
                            Rectangle rectangle = new Rectangle(i, j, width, height);
                            if (rectangle.Right <= MapBuilder.fData.Width && rectangle.Bottom <= MapBuilder.fData.Height && MapBuilder.check_rect_is_empty(rectangle))
                            {
                                points.Add(new Point(i, j));
                            }
                        }
                    }
                }
                else
                {
                    for (int k = 0; k <= MapBuilder.fData.Width; k++)
                    {
                        for (int l = 0; l <= MapBuilder.fData.Height; l++)
                        {
                            Point point = new Point(k, l);
                            if (MapBuilder.tile_at_point(point) == null)
                            {
                                int num3 = 0;
                                if (MapBuilder.tile_at_point(new Point(k + 1, l)) != null)
                                {
                                    num3++;
                                }
                                if (MapBuilder.tile_at_point(new Point(k - 1, l)) != null)
                                {
                                    num3++;
                                }
                                if (MapBuilder.tile_at_point(new Point(k, l + 1)) != null)
                                {
                                    num3++;
                                }
                                if (MapBuilder.tile_at_point(new Point(k, l - 1)) != null)
                                {
                                    num3++;
                                }
                                if (num3 >= 3)
                                {
                                    points.Add(point);
                                }
                            }
                        }
                    }
                }
                if (points.Count == 0)
                {
                    num++;
                    if (num >= 100)
                    {
                        num = 0;
                        if (MapBuilder.fMap.Tiles.Count != 0)
                        {
                            int      num4  = Session.Random.Next(MapBuilder.fMap.Tiles.Count);
                            TileData item1 = MapBuilder.fMap.Tiles[num4];
                            MapBuilder.fMap.Tiles.Remove(item1);
                            area -= Session.FindTile(item1.TileID, SearchType.Global).Area;
                        }
                    }
                }
                else
                {
                    int num5 = Session.Random.Next(points.Count);
                    tileDatum.Location = points[num5];
                    MapBuilder.fMap.Tiles.Add(tileDatum);
                    area += item.Area;
                }
                callback(null, null);
            }while (area != MapBuilder.fData.Width * MapBuilder.fData.Height);
            MapBuilder.fMap.Areas.Clear();
        }