Ejemplo n.º 1
0
    public static Texture2D GetSkinTex(Color col1, Color col2, int width, int length, int oct, float frec)
    {
        ImplicitFractal fractal = new ImplicitFractal(FractalType.BILLOW,
                                                      BasisType.GRADIENTVALUE,
                                                      InterpolationType.CUBIC,
                                                      oct,
                                                      frec,
                                                      Random.Range(0, int.MaxValue));
        MapData data = new MapData(width, length);

        data.GetData(fractal);
        Texture2D treeNoiseTex = new Texture2D(width, length);

        Color[] pixels = new Color[width * length];
        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < length; y++)
            {
                float n = (data.val[x, y] - data.Min) / (data.Max - data.Min);
                pixels[x + y * width] = Color.Lerp(col1, col2, n);
            }
        }
        treeNoiseTex.SetPixels(pixels);
        treeNoiseTex.wrapMode = TextureWrapMode.Clamp;
        treeNoiseTex.Apply();
        return(treeNoiseTex);
    }
Ejemplo n.º 2
0
 void Awake()
 {
     heightMap           = new ImplicitFractal(fractalType, basisType, interpolationType);
     heightMap.Octaves   = terrainOctaves;
     heightMap.Frequency = terrainFrequency;
     heightMap.Seed      = StringToInt(seed);
 }
Ejemplo n.º 3
0
        public MapData GetFractalData(ImplicitFractal fractal)
        {
            var mapData = new MapData(_width, _height);

            for (var x = 0; x < _width; x++)
            {
                for (var y = 0; y < _height; y++)
                {
                    var s = 0 + x / (float)_width;
                    var t = 0 + y / (float)_height;

                    var heightValue = (float)fractal.Get(s, t);
                    if (heightValue > mapData.Max)
                    {
                        mapData.Max = heightValue;
                    }

                    if (heightValue < mapData.Min)
                    {
                        mapData.Min = heightValue;
                    }

                    mapData.Data[y * _width + x] = heightValue;
                }
            }

            return(mapData);
        }
Ejemplo n.º 4
0
    void LoadTiles()
    {
        //Seeds
        SeedTree = Random.Range(0, int.MaxValue);
        //Noises
        ImplicitFractal treeNoise = new ImplicitFractal(FractalType.MULTI,
                                                        BasisType.WHITE,
                                                        InterpolationType.NONE,
                                                        treeOctaves,
                                                        treeFrequency,
                                                        SeedTree);
        MapData treeData = new MapData(width, length);

        treeData.GetData(treeNoise);
        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < length; y++)
            {
                float val  = (treeData.val[x, y] - treeData.Min) / (treeData.Max - treeData.Min);
                Tile  tile = gen[x, y];
                if (tile.Type == TileType.WOODFOREST)
                {
                    if (val < oak)
                    {
                        tile.TreeT = TreeType.Oak;
                    }
                }
                if (tile.Type == TileType.BORRELFOREST)
                {
                    if (val < pine)
                    {
                        tile.TreeT = TreeType.Pine;
                    }
                }
                if (tile.Type == TileType.DESERT)
                {
                    if (val < cactus)
                    {
                        tile.TreeT = TreeType.Cactus;
                    }
                }
                if (tile.Type == TileType.SAVANA)
                {
                    if (val < acacia)
                    {
                        tile.TreeT = TreeType.Acacia;
                    }
                }
                if (tile.Type == TileType.TROPIC)
                {
                    if (val < rainforest)
                    {
                        tile.TreeT = TreeType.Rainforest;
                    }
                }
            }
        }
    }
 private void Initialize()
 {
     // Initialize the HeightMap Generator
     HeightMap = new ImplicitFractal(FractalType.MULTI,
                                     BasisType.SIMPLEX,
                                     InterpolationType.QUINTIC,
                                     TerrainOctaves,
                                     TerrainFrequency,
                                     UnityEngine.Random.Range(0, int.MaxValue));
 }
Ejemplo n.º 6
0
 private void Initialize()
 {
     // Initialize the HeightMap Generator
     HeightMap = new ImplicitFractal(FractalType.Multi,
                                     BasisType.Simplex,
                                     InterpolationType.Quintic,
                                     TerrainOctaves,
                                     TerrainFrequency,
                                     UnityEngine.Random.Range(0, int.MaxValue));
 }
Ejemplo n.º 7
0
        public Grid <float> GenerateAnomalyMap(int mapLength, int mapWidth, int seed = -1)
        {
            if (seed == -1)
            {
                seed = Random.Range(0, int.MaxValue);
            }

            var lengthSample = mapLength * SampleModifier;
            var widthSample  = mapWidth * SampleModifier;

            var anomalyMap = new Grid <float>(mapLength, mapWidth);

            var anomalyGenerator = new ImplicitFractal(
                anomalyFractalType,
                BasisType.Simplex,
                InterpolationType.Quintic,
                anomalyOctaves, anomalyFrequency, anomalyLacunarity)
            {
                Seed = seed
            };

            var secondaryGenerator = new ImplicitFractal(
                FractalType.FractionalBrownianMotion,
                BasisType.Simplex,
                InterpolationType.Quintic,
                2, anomalyFrequency * 0.7D, .9f)
            {
                Seed = seed
            };

            anomalyMap.ForEachSet((x, y) =>
            {
                // Сэмплируем шум с небольшими интервалами
                // Координаты шума будут не рядом, а на расстоянии (1/worldXXX)
                var s = x * lengthSample / (float)mapLength;
                var t = y * widthSample / (float)mapWidth;

                float nx, ny, nz, nw;
                SphereCoordinates(out nx, out ny, out nz, out nw, s, t);

                var value = (float)anomalyGenerator.Get(nx, ny, nz, nw);
                value     = value * 0.5f + 0.5f;

                var secondaryValue = (float)secondaryGenerator.Get(s, t);
                secondaryValue     = secondaryValue * 0.5f + 0.5f;

                return(value * secondaryValue);
            });

            return(anomalyMap);
        }
Ejemplo n.º 8
0
    public static Texture2D GetNoiseTex(int width, int length, float val, int oct, float frec)
    {
        ImplicitFractal treeFract = new ImplicitFractal(FractalType.MULTI,
                                                        BasisType.SIMPLEX,
                                                        InterpolationType.QUINTIC,
                                                        oct,
                                                        frec,
                                                        Random.Range(0, int.MaxValue));
        double min = double.MaxValue;
        double max = double.MinValue;

        double[,] arr = new double[width, length];
        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < length; y++)
            {
                double n = treeFract.Get(x, y);
                arr[x, y] = n;
                if (n < min)
                {
                    min = n;
                }
                if (n > max)
                {
                    max = n;
                }
            }
        }
        Texture2D treeNoiseTex = new Texture2D(width, length);

        Color[] pixels = new Color[width * length];
        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < length; y++)
            {
                double n = (arr[x, y] - min) / (max - min);
                if (n < val)
                {
                    pixels[x + y * width] = Color.green;
                }
                else
                {
                    pixels[x + y * width] = Color.black;
                }
            }
        }
        treeNoiseTex.SetPixels(pixels);
        treeNoiseTex.wrapMode = TextureWrapMode.Clamp;
        treeNoiseTex.Apply();
        return(treeNoiseTex);
    }
Ejemplo n.º 9
0
        public Grid <float> GenerateHeatMap(int mapLength, int mapWidth, int seed = -1)
        {
            if (seed == -1)
            {
                seed = Random.Range(0, int.MaxValue);
            }

            var lengthSample = mapLength * SampleModifier;
            var widthSample  = mapWidth * SampleModifier;

            var heatMap = new Grid <float>(mapLength, mapWidth);

            var gradientGenerator = new ImplicitGradient(1, 1, 0, 1,
                                                         1, 1, 1, 1,
                                                         1, 1, 1, 1)
            {
                Seed = seed
            };

            var fractalGenerator = new ImplicitFractal(heatFractalType, BasisType.Simplex,
                                                       InterpolationType.Quintic, heatOctaves, heatFrequency, heatLacunarity)
            {
                Seed = seed
            };

            var combiner = new ImplicitCombiner(CombinerType.Multiply);

            combiner.AddSource(gradientGenerator);
            combiner.AddSource(fractalGenerator);

            heatMap.ForEachSet((x, y) =>
            {
                // Сэмплируем шум с небольшими интервалами
                // Координаты шума будут не рядом, а на расстоянии (1/worldXXX)
                var s = x * lengthSample / (float)mapLength;
                var t = y * widthSample / (float)mapWidth;

                float nx, ny, nz, nw;
                SphereCoordinates(out nx, out ny, out nz, out nw, s, t);

                var heat = (float)combiner.Get(nx, ny, nz, nw);

                heat = heat * 0.5f + 0.5f;

                var newHeat = (float)Contrast(heat, contrast);

                return(newHeat);
            });

            return(heatMap);
        }
Ejemplo n.º 10
0
    public void Initialize(int width, int length)
    {
        Width  = width;
        Length = length;

        Display = (Display)FindObjectOfType(typeof(Display));

        Tiles    = new Tile[Width, Length];
        Colors   = new Color[Width * Length];
        MapData  = new MapData(Width, Length);
        MeshData = new MeshData(Width, Length);
        Noise    = new ImplicitFractal(FractalType.MULTI, BasisType.SIMPLEX, InterpolationType.QUINTIC,
                                       Octaves, Frequency, Random.Range(0, int.MaxValue));
        MaxPosition = new Vector3(0, 0, 0);
    }
Ejemplo n.º 11
0
    protected override void Initialise()
    {
        if (useRandomSeed)
        {
            seed = (int)System.DateTime.Now.Ticks;
        }

        System.Random pseudoRandom = new System.Random(seed.GetHashCode());

        // HeightMap
        heightMap = new ImplicitFractal(
            FractalType.MULTI,
            BasisType.SIMPLEX,
            InterpolationType.QUINTIC,
            terrainOcatves,
            terrainFrequency,
            pseudoRandom.Next(0, int.MaxValue)
            );

        // Heat Map
        ImplicitGradient gradient    = new ImplicitGradient(1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1);
        ImplicitFractal  heatFractal = new ImplicitFractal(
            FractalType.MULTI,
            BasisType.SIMPLEX,
            InterpolationType.QUINTIC,
            heatOctaves,
            heatFrequency,
            pseudoRandom.Next(0, int.MaxValue)
            );

        heatMap = new ImplicitCombiner(CombinerType.MULTIPLY);
        heatMap.AddSource(gradient);
        heatMap.AddSource(heatFractal);

        // Moisture Map
        moistureMap = new ImplicitFractal(
            FractalType.MULTI,
            BasisType.SIMPLEX,
            InterpolationType.QUINTIC,
            moistureOctaves,
            moistureFrequency,
            pseudoRandom.Next(0, int.MaxValue)
            );
    }
Ejemplo n.º 12
0
    protected override void Initialize()
    {
        HeightMap = new ImplicitFractal(FractalType.MULTI,
                                        BasisType.SIMPLEX,
                                        InterpolationType.QUINTIC,
                                        TerrainOctaves,
                                        TerrainFrequency,
                                        Seed);

        HeatMap = new ImplicitFractal(FractalType.MULTI,
                                      BasisType.SIMPLEX,
                                      InterpolationType.QUINTIC,
                                      HeatOctaves,
                                      HeatFrequency,
                                      Seed);

        MoistureMap = new ImplicitFractal(FractalType.MULTI,
                                          BasisType.SIMPLEX,
                                          InterpolationType.QUINTIC,
                                          MoistureOctaves,
                                          MoistureFrequency,
                                          Seed);

        Cloud1Map = new ImplicitFractal(FractalType.BILLOW,
                                        BasisType.SIMPLEX,
                                        InterpolationType.QUINTIC,
                                        4,
                                        1.55f,
                                        Seed);

        Cloud2Map = new ImplicitFractal(FractalType.BILLOW,
                                        BasisType.SIMPLEX,
                                        InterpolationType.QUINTIC,
                                        5,
                                        1.75f,
                                        Seed);
    }
Ejemplo n.º 13
0
        public Grid <float> GenerateLandscapeMap(int mapLength, int mapWidth, int seed = -1)
        {
            if (seed == -1)
            {
                seed = Random.Range(0, int.MaxValue);
            }

            var lengthSample = mapLength * SampleModifier;
            var widthSample  = mapWidth * SampleModifier;

            var landscapeMap = new Grid <float>(mapLength, mapWidth);

            var landscapeGenerator = new ImplicitFractal(
                heightFractalType,
                BasisType.Simplex,
                InterpolationType.Quintic,
                2, 2, 0.45D)
            {
                Seed = seed
            };

            landscapeMap.ForEachSet((x, y) =>
            {
                // Координаты шума будут не рядом, а на расстоянии (1/worldXXX)
                var xSample = x * lengthSample / (float)mapLength;
                var ySample = y * lengthSample / (float)mapWidth;

                var height = (float)landscapeGenerator.Get(xSample, ySample);

                // Перевод из -1 -- 1 в 0 -- 1
                height = height * 0.5f + 0.5f;

                return(height);
            });

            return(landscapeMap);
        }
Ejemplo n.º 14
0
    private void Initialize()
    {
        // Initialize the HeightMap Generator
        _heightMap = new ImplicitFractal(FractalType.Multi,
                                         BasisType.Simplex,
                                         InterpolationType.Quintic,
                                         SeedHashCode);

        var gradient    = new ImplicitGradient(1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1);
        var heatFractal = new ImplicitFractal(FractalType.Multi,
                                              BasisType.Simplex,
                                              InterpolationType.Quintic,
                                              SeedHashCode * 3);

        // Combine the gradient with our heat fractal
        _heatMap = new ImplicitCombiner(CombinerType.Multiply);
        _heatMap.AddSource(gradient);
        _heatMap.AddSource(heatFractal);

        _moistureMap = new ImplicitFractal(FractalType.Multi,
                                           BasisType.Simplex,
                                           InterpolationType.Quintic,
                                           SeedHashCode * 6);
    }
Ejemplo n.º 15
0
    void LoadTiles()
    {
        //Seeds
        SeedHeight    = Random.Range(0, int.MaxValue);
        SeedHeat      = Random.Range(0, int.MaxValue);
        SeedMoinsture = Random.Range(0, int.MaxValue);
        //Noises
        ImplicitFractal heightMap = new ImplicitFractal(FractalType.MULTI,
                                                        BasisType.SIMPLEX,
                                                        InterpolationType.QUINTIC,
                                                        heightOctaves,
                                                        heightFrequency,
                                                        SeedHeight);
        ImplicitGradient grad = new ImplicitGradient(1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1);
        ImplicitFractal  frac = new ImplicitFractal(FractalType.MULTI,
                                                    BasisType.SIMPLEX,
                                                    InterpolationType.QUINTIC,
                                                    heatOctaves,
                                                    heatFrequency,
                                                    SeedHeat);
        ImplicitCombiner heatMap = new ImplicitCombiner(CombinerType.MULTIPLY);

        heatMap.AddSource(grad);
        heatMap.AddSource(frac);
        ImplicitFractal moinstureMap = new ImplicitFractal(FractalType.MULTI,
                                                           BasisType.SIMPLEX,
                                                           InterpolationType.QUINTIC,
                                                           moinstureOctaves,
                                                           moinstureFrequency,
                                                           SeedMoinsture);
        MapData heightData = new MapData(width, length);

        heightData.GetData(heightMap);
        MapData heatData = new MapData(width, length);

        heatData.GetData(heatMap);
        MapData moinstureData = new MapData(width, length);

        moinstureData.GetData(moinstureMap);
        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < length; y++)
            {
                float height    = (heightData.val[x, y] - heightData.Min) / (heightData.Max - heightData.Min) - heightWater;
                float heat      = (heatData.val[x, y] - heatData.Min) / (heatData.Max - heatData.Min);
                float moinsture = (moinstureData.val[x, y] - moinstureData.Min) / (moinstureData.Max - moinstureData.Min);
                Tile  tile      = gen[x, y];
                tile.X      = x;
                tile.Z      = y;
                tile.IsNull = false;
                if (height > -0.01f && height < 0)
                {
                    height = -0.01f;
                }
                else if (height > 0 && height < 0.01f)
                {
                    height = 0.01f;
                }

                if (height < 0)
                {
                    tile.HeightValue = -1 * height * height * deepValue;
                }
                else
                {
                    tile.HeightValue = height * height * mountValue;
                }
                //HeightType
                if (height < heightDeep)
                {
                    tile.HeightT = HeightType.DEEP;
                    moinsture    = 1;
                }
                else if (height < 0)
                {
                    tile.HeightT = HeightType.WATER;
                    moinsture    = 1;
                }
                else if (height < heightBeach)
                {
                    tile.HeightT = HeightType.BEACH;
                    moinsture   *= 2;
                }
                else if (height < heightGrass)
                {
                    tile.HeightT = HeightType.GRASS;
                    heat        -= 0.15f * height;
                }
                else if (height < heightForest)
                {
                    tile.HeightT = HeightType.FOREST;
                    heat        -= 0.25f * height;
                    moinsture   += 0.1f * height;
                }
                else if (height < heightRock)
                {
                    tile.HeightT = HeightType.ROCK;
                    heat        -= 0.3f * height;
                    moinsture   -= 0.3f * height;
                }
                else
                {
                    tile.HeightT = HeightType.SNOW;
                    heat        -= 0.55f * height;
                }
                //HeatType
                tile.HeatValue = heat;
                if (heat < coldest)
                {
                    tile.HeatT = HeatType.COLDEST;
                }
                else if (heat < cold)
                {
                    tile.HeatT = HeatType.COLD;
                }
                else if (heat < warm)
                {
                    tile.HeatT = HeatType.WARM;
                }
                else if (heat < warmest)
                {
                    tile.HeatT = HeatType.WARMEST;
                }
                else
                {
                    tile.HeatT = HeatType.HOT;
                }
                //MoinstureType
                tile.MoinstureValue = moinsture;
                if (moinsture < dryest)
                {
                    tile.MoinstureT = MoinstureType.DRYEST;
                }
                else if (moinsture < dry)
                {
                    tile.MoinstureT = MoinstureType.DRY;
                }
                else if (moinsture < wet)
                {
                    tile.MoinstureT = MoinstureType.WET;
                }
                else if (moinsture < wetter)
                {
                    tile.MoinstureT = MoinstureType.WETTER;
                }
                else
                {
                    tile.MoinstureT = MoinstureType.WETTEREST;
                }
                //TileType
                tile.Type = TileType.GRASS;
                if (tile.HeightT == HeightType.DEEP)
                {
                    tile.Type = TileType.COLDDESERT;
                }
                else if (tile.HeightT == HeightType.WATER)
                {
                    tile.Type = TileType.SILT;
                }
                else if (tile.HeatT == HeatType.COLDEST)
                {
                    tile.Type = TileType.SNOW;
                }
                else if (tile.HeatT == HeatType.COLD)
                {
                    if (tile.MoinstureT == MoinstureType.WETTER)
                    {
                        tile.Type = TileType.BORRELFOREST;
                    }
                    else if (tile.MoinstureT == MoinstureType.WETTEREST)
                    {
                        tile.Type = TileType.BORRELFOREST;
                    }
                    else
                    {
                        if (tile.HeightT == HeightType.ROCK)
                        {
                            tile.Type = TileType.STONE;
                        }
                        else
                        {
                            tile.Type = TileType.COLDDESERT;
                        }
                    }
                }
                else if (tile.HeatT == HeatType.WARM)
                {
                    if (tile.MoinstureT == MoinstureType.DRYEST)
                    {
                        if (tile.HeightT == HeightType.ROCK)
                        {
                            tile.Type = TileType.STONE;
                        }
                        else
                        {
                            tile.Type = TileType.GRASS;
                        }
                    }
                    else if (tile.MoinstureT == MoinstureType.DRY)
                    {
                        if (tile.HeightT == HeightType.ROCK)
                        {
                            tile.Type = TileType.STONE;
                        }
                        else
                        {
                            tile.Type = TileType.GRASS;
                        }
                    }
                    else if (tile.MoinstureT == MoinstureType.WET)
                    {
                        if (tile.HeightT == HeightType.ROCK)
                        {
                            tile.Type = TileType.STONE;
                        }
                        else
                        {
                            tile.Type = TileType.GRASS;
                        }
                    }
                    else if (tile.MoinstureT == MoinstureType.WETTER)
                    {
                        tile.Type = TileType.WOODFOREST;
                    }
                    else
                    {
                        if (tile.HeightT == HeightType.BEACH)
                        {
                            tile.Type = TileType.DESERT;
                        }
                        else
                        {
                            tile.Type = TileType.WOODFOREST;
                        }
                    }
                }
                else if (tile.HeatT == HeatType.WARMEST)
                {
                    if (tile.MoinstureT == MoinstureType.DRYEST)
                    {
                        tile.Type = TileType.DESERT;
                    }
                    else if (tile.MoinstureT == MoinstureType.DRY)
                    {
                        if (tile.HeightT == HeightType.ROCK)
                        {
                            tile.Type = TileType.STONE;
                        }
                        else
                        {
                            tile.Type = TileType.GRASS;
                        }
                    }
                    else if (tile.MoinstureT == MoinstureType.WET)
                    {
                        if (tile.HeightT == HeightType.ROCK)
                        {
                            tile.Type = TileType.STONE;
                        }
                        else
                        {
                            tile.Type = TileType.WOODFOREST;
                        }
                    }
                    else if (tile.MoinstureT == MoinstureType.WETTER)
                    {
                        if (tile.HeightT == HeightType.ROCK)
                        {
                            tile.Type = TileType.STONE;
                        }
                        else
                        {
                            tile.Type = TileType.WOODFOREST;
                        }
                    }
                    else
                    {
                        if (tile.HeightT == HeightType.BEACH)
                        {
                            tile.Type = TileType.SWAMP;
                        }
                        else
                        {
                            tile.Type = TileType.TROPIC;
                        }
                    }
                }
                else if (tile.HeatT == HeatType.HOT)
                {
                    if (tile.MoinstureT == MoinstureType.DRYEST)
                    {
                        tile.Type = TileType.DESERT;
                    }
                    else if (tile.MoinstureT == MoinstureType.DRY)
                    {
                        tile.Type = TileType.DESERT;
                    }
                    else if (tile.MoinstureT == MoinstureType.WET)
                    {
                        tile.Type = TileType.SAVANA;
                    }
                    else if (tile.MoinstureT == MoinstureType.WETTER)
                    {
                        tile.Type = TileType.SAVANA;
                    }
                    else
                    {
                        tile.Type = TileType.TROPIC;
                    }
                }
                if (tile.Z + 1 >= length)
                {
                    tile.forward = null;
                }
                else
                {
                    tile.forward = gen[tile.X, tile.Z + 1];
                }
                if (tile.Z - 1 < 0)
                {
                    tile.back = null;
                }
                else
                {
                    tile.back = gen[tile.X, tile.Z - 1];
                }

                if (tile.X + 1 >= width)
                {
                    tile.right = null;
                }
                else
                {
                    tile.right = gen[tile.X + 1, tile.Z];
                }
                if (tile.X - 1 < 0)
                {
                    tile.left = null;
                }
                else
                {
                    tile.left = gen[tile.X - 1, tile.Z];
                }
                gen[x, y] = tile;
            }
        }
    }
Ejemplo n.º 16
0
    void LoadTiles()
    {
        //Seeds
        SeedPlant = Random.Range(0, int.MaxValue);
        //Noises
        ImplicitFractal plantNoise = new ImplicitFractal(FractalType.MULTI,
                                                         BasisType.SIMPLEX,
                                                         InterpolationType.QUINTIC,
                                                         plantOctaves,
                                                         plantFrequency,
                                                         SeedPlant);
        MapData plantData = new MapData(width, length);

        plantData.GetData(plantNoise);
        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < length; y++)
            {
                float val  = (plantData.val[x, y] - plantData.Min) / (plantData.Max - plantData.Min);
                Tile  tile = gen[x, y];
                if (tile.TreeT != TreeType.NULL)
                {
                    tile.AgePlant = 0;
                    continue;
                }
                if (tile.Type == TileType.GRASS)
                {
                    if (val < grass)
                    {
                        tile.PlantT = PlantType.GRASS;
                    }
                }
                else if (tile.Type == TileType.SAVANA)
                {
                    if (val < savanna)
                    {
                        tile.PlantT = PlantType.SAVANNA;
                    }
                }
                else if (tile.Type == TileType.SWAMP)
                {
                    if (val < swamp)
                    {
                        tile.PlantT = PlantType.SWAMP;
                    }
                }
                else if (tile.Type == TileType.DESERT)
                {
                    if (val < desert)
                    {
                        tile.PlantT = PlantType.DESERT;
                    }
                }
                else if (tile.Type == TileType.COLDDESERT)
                {
                    if (val < cold)
                    {
                        tile.PlantT = PlantType.COLD;
                    }
                }
                tile.AgePlant = Random.Range(0.5f, 1);
                plants.Add(tile);
            }
        }
    }
Ejemplo n.º 17
0
    private void GenerateMap(HexMap m)
    {
        // Generate AltitudeMap
        ImplicitFractal AltitudeMap = GetFractal(m.AltitudeFractal);

        // Generate TemperatureMap
        ImplicitGradient gradient       = new ImplicitGradient(1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1);
        ImplicitCombiner TemperatureMap = new ImplicitCombiner(CombinerType.MULTIPLY);

        TemperatureMap.AddSource(gradient);
        TemperatureMap.AddSource(AltitudeMap);

        // Generate PressureMap
        ImplicitCombiner PressureMap = new ImplicitCombiner(CombinerType.AVERAGE);

        //PressureMap.AddSource( AltitudeMap );
        PressureMap.AddSource(GetFractal(m.PressureFractal));

        // Generate HumidityMap
        ImplicitFractal HumidityMap = GetFractal(m.HumidityFractal);

        // Generate RadiationMap
        ImplicitFractal RadiationMap = GetFractal(m.RadiationFractal);

        HexModel hex;

        for (int x = 0; x < _map.Width; x++)
        {
            for (int y = 0; y < _map.Height; y++)
            {
                hex = new HexModel
                {
                    X    = x,
                    Y    = y,
                    Lens = m.Lens
                };
                _map.Table[x][y] = hex;

                // WRAP ON BOTH AXIS
                // Noise range
                float x1 = 0, x2 = 2;
                float y1 = 0, y2 = 2;
                float dx = x2 - x1;
                float dy = y2 - y1;

                // Sample noise at smaller intervals
                float s = (float)x / _map.Width;
                float t = (float)y / _map.Height;

                // Calculate our 4D coordinates
                float nx = x1 + Mathf.Cos(s * 2 * Mathf.PI) * dx / (2 * Mathf.PI);
                float ny = y1 + Mathf.Cos(t * 2 * Mathf.PI) * dy / (2 * Mathf.PI);
                float nz = x1 + Mathf.Sin(s * 2 * Mathf.PI) * dx / (2 * Mathf.PI);
                float nw = y1 + Mathf.Sin(t * 2 * Mathf.PI) * dy / (2 * Mathf.PI);

                float altitude    = (float)AltitudeMap.Get(nx, ny, nz, nw);
                float temperature = (float)(1 - TemperatureMap.Get(nx, ny, nz, nw));
                float equador     = (float)(gradient.Get(nx, ny, nz, nw));
                //float pressure = PressureMap.Get( nx, ny, nz, nw );
                float humidity  = (float)HumidityMap.Get(nx, ny, nz, nw);
                float radiation = (float)RadiationMap.Get(nx, ny, nz, nw);

                // keep track of the max and min values found
                SetInitialHexValue(hex, R.Altitude, altitude);
                SetInitialHexValue(hex, R.Temperature, temperature);
                SetInitialHexValue(hex, R.Humidity, humidity);
                SetInitialHexValue(hex, R.Pressure, 1f - altitude);

                SetInitialHexValue(hex, R.Radiation, .5f);
            }
        }

        //Normalize Ranges to 0-1
        for (int x = 0; x < _map.Width; x++)
        {
            for (int y = 0; y < _map.Height; y++)
            {
                hex = _map.Table[x][y];

                SetHex(hex, R.Altitude, 0.005f);

                /*
                 * if( hex.Props[ R.Altitude ].Value < _planetModel.LiquidLevel )
                 * {
                 *  SetInitialHexValue( hex, R.Humidity, hex.Props[ R.Humidity ].Value + 0.5f );
                 *  SetInitialHexValue( hex, R.Pressure, hex.Props[ R.Pressure ].Value + 0.5f );
                 *  SetInitialHexValue( hex, R.Radiation, hex.Props[ R.Radiation ].Value - 0.5f );
                 *  if( hex.Props[ R.Temperature ].Value > 0.33 )
                 *  {
                 *      SetInitialHexValue( hex, R.Temperature, ( hex.Props[ R.Temperature ].Value - ( hex.Props[ R.Temperature ].Value * 0.5f ) ) );
                 *  }
                 *  else
                 *  {
                 *      SetInitialHexValue( hex, R.Temperature, ( hex.Props[ R.Temperature ].Value + ( hex.Props[ R.Temperature ].Value * 0.5f ) ) );
                 *  }
                 * }
                 */

                SetHex(hex, R.Temperature);
                SetHex(hex, R.Pressure);
                SetHex(hex, R.Humidity);
                SetHex(hex, R.Radiation);

                //element index
                hex.Props[R.Element].Index = (int)RandomUtil.GetWeightedValue(_elementsProbabilities);
                hex.Props[R.Element].Value = _elementsDict[hex.Props[R.Element].Index].Amount;
                hex.Props[R.Element].Delta = _elementsDict[hex.Props[R.Element].Index].Weight * 1;
                Color mColor;
                ColorUtility.TryParseHtmlString(_elementsDict[(int)hex.Props[R.Element].Index].Color, out mColor);
                hex.Props[R.Element].Color = mColor;
                //hex.Props[ R.Element ].Value = _planetModel._Elements[ RandomUtil.FromRangeInt( 0, _planetModel._Elements.Count ) ].Index;
                //hex.Props[ R.Minerals ].Value = (int)_elements[ (int)hex.Props[ R.Element ].Value ].Weight;

                hex.Props[R.Altitude].Value *= 2;

                _hexUpdateCommand.Execute(hex);
                _hexScoreUpdateCommand.ExecuteHex(hex);
            }
        }
    }