Ejemplo n.º 1
0
        public static Bitmap[,] FetchHeightMap(double lon, double lat, int tilesX, int tilesY)
        {
            Bitmap[,] images = new Bitmap[tilesX, tilesY];
            int x = Slippy.long2tilex(lon, ZOOM);
            int y = Slippy.lat2tiley(lat, ZOOM);

            for (int i = -(tilesX - 1) / 2; i < (tilesX + 1) / 2; i++)
            {
                for (int j = -(tilesY - 1) / 2; j < (tilesY + 1) / 2; j++)
                {
                    string          url      = "https://api.mapbox.com/v4/mapbox.terrain-rgb/" + ZOOM + "/" + (x + i) + "/" + (y - j) + ".png?access_token=pk.eyJ1IjoiaHVtYW5pemVyIiwiYSI6ImNraGdkc2t6YzBnYjYyeW1jOTJ0a3kxdGkifQ.SIpcsxeP7Xp2RTxDAEv3wA";
                    WebRequest      request  = WebRequest.Create(url);
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                    Image           image    = Image.FromStream(response.GetResponseStream());
                    images[i + (tilesX - 1) / 2, j + (tilesY - 1) / 2] = new Bitmap(image);
                }
            }
            return(images);
        }
Ejemplo n.º 2
0
        public static Bitmap[,] FetchWaterMap(double lon, double lat, int tilesX, int tilesY)
        {
            Bitmap[,] images = new Bitmap[tilesX, tilesY];
            int x = Slippy.long2tilex(lon, ZOOM);
            int y = Slippy.lat2tiley(lat, ZOOM);

            for (int i = -(tilesX - 1) / 2; i < (tilesX + 1) / 2; i++)
            {
                for (int j = -(tilesY - 1) / 2; j < (tilesY + 1) / 2; j++)
                {
                    string          url      = "https://api.mapbox.com/styles/v1" + "/huterguier/ckip28dz75c5s17p98d8lb0gb" + "/tiles/256/" + ZOOM + "/" + (x + i) + "/" + (y - j) + "?access_token=pk.eyJ1IjoiaHV0ZXJndWllciIsImEiOiJja2g2Nm56cTEwOTV0MnhuemR1bHRianJtIn0.ViSkV78j-GHgC18pMnZfrQ";
                    WebRequest      request  = WebRequest.Create(url);
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                    Image           image    = Image.FromStream(response.GetResponseStream());
                    images[i + (tilesX - 1) / 2, j + (tilesY - 1) / 2] = new Bitmap(image);
                }
            }
            return(images);
        }
Ejemplo n.º 3
0
        public MapGenerator(float lat, float lon, int size)
        {
            LONGITUDE = lon;
            LATITUDE  = lat;

            TILE_COUNT_X = size;
            TILE_COUNT_Z = size;

            IMAGE_WIDTH  = size * SINGLE_IMAGE_WIDTH;
            IMAGE_HEIGHT = size * SINGLE_IMAGE_HEIGHT;

            CHUNK_COUNT_X = TILE_COUNT_X * CHUNKS_PER_TILE_X;
            CHUNK_COUNT_Z = TILE_COUNT_Z * CHUNKS_PER_TILE_Z;

            CELL_COUNT_X = CHUNK_COUNT_X * HexMetrics.chunkSizeX;
            CELL_COUNT_Z = CHUNK_COUNT_Z * HexMetrics.chunkSizeZ;

            CELL_COUNT = CELL_COUNT_X * CELL_COUNT_Z;

            HEX_WIDTH  = HexMetrics.innerRadius + 2f * HexMetrics.innerRadius * (float)CELL_COUNT_X;
            HEX_HEIGHT = 0.5f * HexMetrics.outerRadius + 1.5f * HexMetrics.outerRadius * (float)CELL_COUNT_Z;


            float cornerLon = (float)Slippy.tilex2long((Slippy.long2tilex(LONGITUDE, MapboxHandler.ZOOM) - TILE_COUNT_X / 2), MapboxHandler.ZOOM);
            float deltaLon  = TILE_COUNT_X * Math.Abs((float)Slippy.tilex2long(Slippy.long2tilex(LONGITUDE, MapboxHandler.ZOOM), MapboxHandler.ZOOM) - (float)Slippy.tilex2long((Slippy.long2tilex(LONGITUDE, MapboxHandler.ZOOM) + 1), MapboxHandler.ZOOM));

            float deltaLat  = TILE_COUNT_Z * Math.Abs((float)Slippy.tiley2lat(Slippy.lat2tiley(LATITUDE, MapboxHandler.ZOOM), MapboxHandler.ZOOM) - (float)Slippy.tiley2lat((Slippy.lat2tiley(LATITUDE, MapboxHandler.ZOOM) + 1), MapboxHandler.ZOOM));
            float cornerLat = (float)Slippy.tiley2lat((Slippy.lat2tiley(LATITUDE, MapboxHandler.ZOOM) + TILE_COUNT_Z / 2 + 1), MapboxHandler.ZOOM) + 0.5f * ((HEX_WIDTH - HEX_HEIGHT) / HEX_WIDTH) * deltaLat;

            /*
             * Console.WriteLine(cornerLon);
             * Console.WriteLine(cornerLat);
             *
             * Console.WriteLine(cornerLon + deltaLon);
             * Console.WriteLine(cornerLat + deltaLat);
             *
             * Console.WriteLine(0.5f * ((HEX_WIDTH - HEX_HEIGHT) / HEX_WIDTH) * deltaLat);
             */
            hexGrid = new HexGrid.HexGrid(CHUNK_COUNT_X, CHUNK_COUNT_Z, cornerLon, cornerLat, deltaLon, (HEX_HEIGHT / HEX_WIDTH) * deltaLat);

            waterAreas = new List <List <HexCell> >();

            random = new Random();

            cellQueryThresholds = new Dictionary <HexCellBiome, int>();
            foreach (HexCellBiome biome in Enum.GetValues(typeof(HexCellBiome)))
            {
                cellQueryThresholds.Add(biome, 4);
            }

            biomeThresholds = new Dictionary <HexCellBiome, Tuple <int, int> >
            {
                { HexCellBiome.FOREST, new Tuple <int, int>((int)(0.05f * CELL_COUNT), (int)(0.4f * CELL_COUNT)) },
                { HexCellBiome.SCRUB, new Tuple <int, int>((int)(0.05f * CELL_COUNT), (int)(0.4f * CELL_COUNT)) },
                { HexCellBiome.GRASS, new Tuple <int, int>((int)(0.05f * CELL_COUNT), (int)(0.4f * CELL_COUNT)) },
                { HexCellBiome.CROP, new Tuple <int, int>((int)(0.05f * CELL_COUNT), (int)(0.4f * CELL_COUNT)) },
                { HexCellBiome.COAL, new Tuple <int, int>((int)(0.02f * CELL_COUNT), (int)(0.1f * CELL_COUNT)) },
                { HexCellBiome.ROCK, new Tuple <int, int>((int)(0.04f * CELL_COUNT), (int)(0.4f * CELL_COUNT)) },
                { HexCellBiome.CITY, new Tuple <int, int>((int)(0.1f * CELL_COUNT), (int)(0.2f * CELL_COUNT)) },
                { HexCellBiome.BUILDINGS, new Tuple <int, int>((int)(0.05f * CELL_COUNT), (int)(0.2f * CELL_COUNT)) },
                { HexCellBiome.WATER, new Tuple <int, int>((int)(0.005f * CELL_COUNT), (int)(0.1f * CELL_COUNT)) }
            };

            /*
             * parsedRessources = new int[Enum.GetValues(RessourceType).Length];
             * ressourceThresholds = new Dictionary<Type, int>{
             *  { RessourceType.COAL, new Tuple<int, int>((int)(0.005f * CELL_COUNT), (int)(0.01f * CELL_COUNT)) },
             *  { RessourceType.WOOD, new Tuple<int, int>((int)(0.005f * CELL_COUNT), (int)(0.01f * CELL_COUNT)) },
             *  { RessourceType.WHEAT, new Tuple<int, int>((int)(0.005f * CELL_COUNT), (int)(0.01f * CELL_COUNT)) },
             *  { RessourceType.FISH, new Tuple<int, int>((int)(0.005f * CELL_COUNT), (int)(0.01f * CELL_COUNT)) },
             *  { RessourceType.IRON_ORE, new Tuple<int, int>((int)(0.005f * CELL_COUNT), (int)(0.01f * CELL_COUNT)) },
             *  { RessourceType, new Tuple<int, int>((int)(0.005f * CELL_COUNT), (int)(0.01f * CELL_COUNT)) },
             *  { RessourceType.COAL, new Tuple<int, int>((int)(0.005f * CELL_COUNT), (int)(0.01f * CELL_COUNT)) },
             * }
             */
        }