Exemple #1
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();
        }
Exemple #2
0
        private static void build_freeform_area(EventHandler callback)
        {
            List <Tile> tiles = 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 (tiles.Count == 0)
            {
                return;
            }
            int height = MapBuilder.fData.Height * MapBuilder.fData.Width;

            while (height > 0)
            {
                callback(null, null);
                int   num   = Session.Random.Next() % tiles.Count;
                Tile  item  = tiles[num];
                Point point = new Point(0, 0);
                if (MapBuilder.fMap.Tiles.Count != 0)
                {
                    int              num1       = Session.Random.Next() % MapBuilder.fMap.Tiles.Count;
                    TileData         tileDatum  = MapBuilder.fMap.Tiles[num1];
                    Tile             tile1      = Session.FindTile(tileDatum.TileID, SearchType.Global);
                    List <Rectangle> rectangles = new List <Rectangle>();
                    int              x          = tileDatum.Location.X;
                    Size             size       = item.Size;
                    int              width      = x - (size.Width - 1);
                    int              x1         = tileDatum.Location.X + (tile1.Size.Width - 1);
                    int              y          = tileDatum.Location.Y - (item.Size.Height - 1);
                    int              y1         = tileDatum.Location.Y + (tile1.Size.Height - 1);
                    for (int i = width; i <= x1; i++)
                    {
                        int       y2        = tileDatum.Location.Y - item.Size.Height;
                        int       width1    = item.Size.Width;
                        Size      size1     = item.Size;
                        Rectangle rectangle = new Rectangle(i, y2, width1, size1.Height);
                        rectangles.Add(rectangle);
                    }
                    for (int j = width; j <= x1; j++)
                    {
                        int num2   = tileDatum.Location.Y + tile1.Size.Height;
                        int width2 = item.Size.Width;
                        size = item.Size;
                        Rectangle rectangle1 = new Rectangle(j, num2, width2, size.Height);
                        rectangles.Add(rectangle1);
                    }
                    for (int k = y; k <= y1; k++)
                    {
                        int x2 = tileDatum.Location.X;
                        size = tile1.Size;
                        int width3 = x2 - size.Width;
                        int num3   = item.Size.Width;
                        size = item.Size;
                        Rectangle rectangle2 = new Rectangle(width3, k, num3, size.Height);
                        rectangles.Add(rectangle2);
                    }
                    for (int l = y; l <= y1; l++)
                    {
                        int x3 = tileDatum.Location.X;
                        size = tile1.Size;
                        int width4 = x3 + size.Width;
                        int num4   = item.Size.Width;
                        size = item.Size;
                        Rectangle rectangle3 = new Rectangle(width4, l, num4, size.Height);
                        rectangles.Add(rectangle3);
                    }
                    List <Rectangle> rectangles1 = new List <Rectangle>();
                    foreach (Rectangle rectangle4 in rectangles)
                    {
                        if (!MapBuilder.check_rect_is_empty(rectangle4))
                        {
                            continue;
                        }
                        rectangles1.Add(rectangle4);
                    }
                    if (rectangles1.Count == 0)
                    {
                        continue;
                    }
                    int num5 = Session.Random.Next() % rectangles1.Count;
                    point = rectangles1[num5].Location;
                }
                TileData tileDatum1 = new TileData()
                {
                    TileID   = item.ID,
                    Location = point
                };
                MapBuilder.fMap.Tiles.Add(tileDatum1);
                height -= item.Area;
            }
            int num6 = 0;
            int num7 = 0;
            int num8 = 0;
            int num9 = 0;

            foreach (TileData tile3 in MapBuilder.fMap.Tiles)
            {
                Tile      tile4      = Session.FindTile(tile3.TileID, SearchType.Global);
                Rectangle rectangle5 = new Rectangle(tile3.Location, tile4.Size);
                num6 = Math.Min(num6, rectangle5.Left);
                num7 = Math.Max(num7, rectangle5.Right);
                num8 = Math.Min(num8, rectangle5.Top);
                num9 = Math.Max(num9, rectangle5.Bottom);
            }
            MapArea mapArea = new MapArea()
            {
                Name   = "Area",
                Region = new Rectangle(num6, num8, num7 - num6, num9 - num8)
            };

            MapBuilder.fMap.Areas.Add(mapArea);
        }
Exemple #3
0
        private static Pair <TileData, Direction> add_tile(Tile t, Endpoint ep, bool follow_direction, bool not_alongside)
        {
            TileData tileDatum = new TileData()
            {
                TileID = t.ID
            };
            Direction direction = ep.Direction;

            if (!follow_direction)
            {
                List <Direction> directions = new List <Direction>();
                if (ep.Direction != Direction.North)
                {
                    directions.Add(Direction.South);
                }
                if (ep.Direction != Direction.East)
                {
                    directions.Add(Direction.West);
                }
                if (ep.Direction != Direction.South)
                {
                    directions.Add(Direction.North);
                }
                if (ep.Direction != Direction.West)
                {
                    directions.Add(Direction.East);
                }
                int num = Session.Random.Next() % directions.Count;
                direction = directions[num];
            }
            if (!follow_direction)
            {
                tileDatum.Rotations = Session.Random.Next() % 4;
            }
            else
            {
                int num1 = Math.Min(t.Size.Width, t.Size.Height);
                if (direction == Direction.North || direction == Direction.South)
                {
                    if (num1 > 1)
                    {
                        if (t.Size.Width > t.Size.Height)
                        {
                            tileDatum.Rotations = 1;
                        }
                    }
                    else if (t.Size.Width < t.Size.Height)
                    {
                        tileDatum.Rotations = 1;
                    }
                }
                if (direction == Direction.East || direction == Direction.West)
                {
                    if (num1 > 1)
                    {
                        if (t.Size.Height > t.Size.Width)
                        {
                            tileDatum.Rotations = 1;
                        }
                    }
                    else if (t.Size.Height < t.Size.Width)
                    {
                        tileDatum.Rotations = 1;
                    }
                }
            }
            int num2 = (tileDatum.Rotations % 2 == 0 ? t.Size.Width : t.Size.Height);
            int num3 = (tileDatum.Rotations % 2 == 0 ? t.Size.Height : t.Size.Width);

            switch (ep.Direction)
            {
            case Direction.North:
            {
                tileDatum.Location = new Point(ep.TopLeft.X, ep.TopLeft.Y - (num3 - 1));
                break;
            }

            case Direction.East:
            {
                tileDatum.Location = ep.TopLeft;
                break;
            }

            case Direction.South:
            {
                tileDatum.Location = ep.TopLeft;
                break;
            }

            case Direction.West:
            {
                tileDatum.Location = new Point(ep.TopLeft.X - (num2 - 1), ep.TopLeft.Y);
                break;
            }
            }
            Rectangle _rect = MapBuilder.get_rect(t, tileDatum);

            if (not_alongside)
            {
                switch (direction)
                {
                case Direction.North:
                case Direction.South:
                {
                    _rect = new Rectangle(_rect.X - 1, _rect.Y, _rect.Width + 2, _rect.Height);
                    break;
                }

                case Direction.East:
                case Direction.West:
                {
                    _rect = new Rectangle(_rect.X, _rect.Y - 1, _rect.Width, _rect.Height + 2);
                    break;
                }
                }
            }
            if (!MapBuilder.check_rect_is_empty(_rect))
            {
                return(null);
            }
            MapBuilder.fMap.Tiles.Add(tileDatum);
            return(new Pair <TileData, Direction>(tileDatum, direction));
        }