private void Initialize()
    {
        // Initialize the HeightMap Generator
        HeightMap = new ImplicitFractal(FractalType.MULTI,
                                        BasisType.SIMPLEX,
                                        InterpolationType.QUINTIC,
                                        TerrainOctaves,
                                        TerrainFrequency,
                                        Seed);


        // Initialize the 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,
                                                           Seed);

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

        //moisture map
        MoistureMap = new ImplicitFractal(FractalType.MULTI,
                                          BasisType.SIMPLEX,
                                          InterpolationType.QUINTIC,
                                          MoistureOctaves,
                                          MoistureFrequency,
                                          Seed);
    }
Example #2
0
        public override void Initialize()
        {
            // HeightMap
            HeightMap = new ImplicitFractal(FractalType.Multi,
                                            BasisType.Simplex,
                                            InterpolationType.Quintic,
                                            TerrainOctaves,
                                            TerrainFrequency,
                                            Seed);

            // 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,
                                                               Seed);

            HeatMap = new ImplicitCombiner(CombinerType.Multiply);
            HeatMap.AddSource(gradient);
            HeatMap.AddSource(heatFractal);

            // Moisture Map
            MoistureMap = new ImplicitFractal(FractalType.Multi,
                                              BasisType.Simplex,
                                              InterpolationType.Quintic,
                                              MoistureOctaves,
                                              MoistureFrequency,
                                              Seed);
        }
Example #3
0
        public MapData GetCombinerData(ImplicitCombiner combiner)
        {
            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)combiner.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);
        }
Example #4
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);
        }
Example #5
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)
            );
    }
Example #6
0
        private void Initialize(int seed, out ImplicitModuleBase HeightMap, out ImplicitModuleBase HeatMap, out ImplicitModuleBase MoistureMap)
        {
            FractalType randomFractalType = (FractalType)random.Next(0, 5);
            BasisType   randomBasisType   = (BasisType)random.Next(0, 4); // exclude white

            // HEIGHT
            // Multi, Billow, Fractional Brownian, Hybrid Multi, Ridged Multi
            // Simplex, Gradient, Gradient Value, Value
            //ImplicitFractal heightFractal = new ImplicitFractal(FractalType.Multi, BasisType.Simplex, InterpolationType.Quintic)
            ImplicitFractal heightFractal = new ImplicitFractal(randomFractalType, randomBasisType, InterpolationType.Quintic)
            {
                Octaves   = TerrainOctaves,
                Frequency = TerrainFrequency,
                Seed      = seed
            };

            HeightMap = heightFractal;

            // HEAT
            ImplicitGradient heatGradient = new ImplicitGradient(1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1);
            ImplicitFractal  heatFractal  = new ImplicitFractal(randomFractalType, randomBasisType, InterpolationType.Quintic)
            {
                Octaves   = HeatOctaves,
                Frequency = HeatFrequency,
                Seed      = seed
            };

            HeatMap = new ImplicitCombiner(CombinerType.Multiply);
            ((ImplicitCombiner)HeatMap).AddSource(heatGradient);
            ((ImplicitCombiner)HeatMap).AddSource(heatFractal);

            // MOISTURE
            MoistureMap = new ImplicitFractal(randomFractalType, randomBasisType, InterpolationType.Quintic)
            {
                Octaves   = MoistureOctaves,
                Frequency = MoistureFrequency,
                Seed      = seed
            };
        }
Example #7
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);
    }
Example #8
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);
            }
        }
    }
Example #9
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;
            }
        }
    }