Esempio n. 1
0
        private void TraceBorder(TilePair tilePair, List <TilePair> borderRoute, IHexMap map)
        {
            // Abort if current combination is already stored
            if (borderRoute.Any(p => p.Neighbour == tilePair.Neighbour && p.HexTile == tilePair.HexTile))
            {
                return;
            }

            borderRoute.Add(tilePair);

            var nextPair = map.GetNextNeighbourWithDirection(tilePair.HexTile, tilePair.Neighbour);

            if (nextPair.Neighbour.Province == null || nextPair.Neighbour.Province.Owner != tilePair.HexTile.Province.Owner)
            {
                // Move on with current tile and next neighbour province tile
                TraceBorder(nextPair, borderRoute, map);
                return;
            }

            // Take next own province tile and current neighbour province tile
            var newCurrentProvinceTile    = nextPair.Neighbour;
            var lastNeighbourProvinceTile = borderRoute.Where(t => t.HexTile == tilePair.HexTile).Select(t => t.Neighbour).Last();
            var newPair = map.GetPairWithDirection(newCurrentProvinceTile, lastNeighbourProvinceTile);

            if (newPair == null)
            {
                return;
            }
            TraceBorder(newPair, borderRoute, map);
        }
Esempio n. 2
0
    private List <TilePair> GetOverlap(List <Vector2Int> tilesA, List <Vector2Int> tilesB, bool isVertical, out bool isConnected)
    {
        var overlap = new List <TilePair>();

        isConnected = false;
        foreach (var tileA in tilesA)
        {
            foreach (var tileB in tilesB)
            {
                if (tileA.x == tileB.x && isVertical)
                {
                    var pair = new TilePair(tileA, tileB);
                    overlap.Add(pair);
                    if (tileA.y == tileB.y - 1 || tileA.y == tileB.y + 1)
                    {
                        isConnected = true;
                    }
                }
                else if (tileA.y == tileB.y && !isVertical)
                {
                    var pair = new TilePair(tileA, tileB);
                    overlap.Add(pair);
                    if (tileA.x == tileB.x - 1 || tileA.x == tileB.x + 1)
                    {
                        isConnected = true;
                    }
                }
            }
        }

        return(overlap);
    }
Esempio n. 3
0
 private void AddPaths(List <Area> areas, int minArea)                       //connect all unconnected areas in the map.
 {
     for (int a1 = 1; a1 < areas.Count; a1++)                                //foreach area
     {
         TilePair t = ClosestTiles(areas[a1].EdgeTiles, areas[0].EdgeTiles); //the two edge tiles that are the least distance apart
         if (t.tilepair != null && areas[a1].Tiles.Count > minArea)
         {
             ConnectAreas(t.tilepair);
         }
         else
         {
             var a = areas[a1];
             for (int i = 0; i < areas[a1].Tiles.Count; i++) //fill this area it cannot be connected
             {
                 grid[Convert.ToInt32(a.Tiles[i].x), Convert.ToInt32(a.Tiles[i].y)] = true;
             }
         }
     }
 }
Esempio n. 4
0
        private static void ScaleTile(TilePair nw, TilePair se, int lod, int targetlod, out PixelPair pixnw, out PixelPair pixse)
        {
            se.X++;
            se.Y++;

            var diff = targetlod - lod;
            var factor = Math.Pow(2.0, diff);

            var targetnw = new TilePair((int)(nw.X * factor), (int)(nw.Y * factor));
            var targetse = new TilePair((int)(se.X * factor), (int)(se.Y * factor));

            if (targetnw.X == targetse.X) targetse.X++;
            if (targetnw.Y == targetse.Y) targetse.Y++;

            if (diff < 0) {
                if (targetse.X * (1.0 / factor) < se.X) targetse.X++;
                if (targetse.Y * (1.0 / factor) < se.Y) targetse.Y++;
            }

            pixnw = Pixel(targetnw);
            pixse = Pixel(targetse);
        }
Esempio n. 5
0
 private static PixelPair Pixel(TilePair tile)
 {
     int pixx, pixy;
     TileSystem.TileXYToPixelXY(tile.X, tile.Y, out pixx, out pixy);
     return new PixelPair(pixx, pixy);
 }
Esempio n. 6
0
        public Point? GetScreenPosition(TilePair tile)
        {
            if (!this.IsScreenPositionInferred()) return null;

            int pixelx, pixely;
            TileSystem.TileXYToPixelXY(tile.X, tile.Y, out pixelx, out pixely);
            return this.GetScreenPosition(new PixelPair(pixelx, pixely));
        }
Esempio n. 7
0
 public string GetQuadKey(TilePair tile)
 {
     return QuadKey(tile, this.ZoomLevel);
 }
Esempio n. 8
0
        public PixelPair GetPixel(TilePair tile, int tilelod, bool secorner)
        {
            var srcpix = this.GetPixel(tile);
            if (secorner) {
                srcpix.X += this.TileSize;
                srcpix.Y += this.TileSize;
            }

            var diff = this.ZoomLevel - tilelod;
            var factor = Math.Pow(2.0, diff);

            var x = (int)(srcpix.X * factor);
            var y = (int)(srcpix.Y * factor);
            return new PixelPair(x, y);
        }
Esempio n. 9
0
 public PixelPair GetPixel(TilePair tile)
 {
     return Pixel(tile);
 }
Esempio n. 10
0
 public Location GetLocation(TilePair tile, int tilelod, bool secorner)
 {
     var pixel = this.GetPixel(tile, tilelod, secorner);
     double lat, lon;
     TileSystem.PixelXYToLatLong(pixel.X, pixel.Y, this.ZoomLevel, out lat, out lon);
     return new Location(lat, lon);
 }
Esempio n. 11
0
 public static string QuadKey(TilePair tile, int lod)
 {
     return TileSystem.TileXYToQuadKey(tile.X, tile.Y, lod);
 }
Esempio n. 12
0
 public static IEnumerable<TilePair> IterateTiles(TilePair nw, TilePair se, int lod, int targetlod)
 {
     PixelPair pixnw, pixse;
     ScaleTile(nw, se, lod, targetlod, out pixnw, out pixse);
     return IterateTiles(pixnw, pixse, targetlod);
 }
Esempio n. 13
0
 public static IEnumerable<TilePair> IterateTiles(TilePair nw, TilePair se, int lod)
 {
     se.X++;
     se.Y++;
     var pixnw = Pixel(nw);
     var pixse = Pixel(se);
     return IterateTiles(pixnw, pixse, lod);
 }
Esempio n. 14
0
 public static int CountTiles(TilePair nw, TilePair se, int lod, int targetlod)
 {
     PixelPair pixnw, pixse;
     ScaleTile(nw, se, lod, targetlod, out pixnw, out pixse);
     return CountTiles(pixnw, pixse, targetlod);
 }