void ILandMapEffector.Effect(LandMap landMap)
        {
            if (level <= 1)
            {
                return;
            }

            for (var y = 0; y < LandMap.Size; y++)
            {
                for (var x = 0; x < LandMap.Size; x++)
                {
                    var nextValue      = landMap.GetHeight(x, y);
                    var nextValueCount = 0;

                    for (var xRange = Math.Max(x - level, 0); xRange < Math.Min(x + level, LandMap.Size); xRange++)
                    {
                        for (var yRange = Math.Max(y - level, 0); yRange < Math.Min(y + level, LandMap.Size); yRange++, nextValueCount++)
                        {
                            var subX = x - xRange;
                            var subY = y - yRange;

                            if (!(Math.Sqrt(subX * subX + subY * subY) <= level))
                            {
                                continue;
                            }

                            nextValue += landMap.GetHeight(xRange, yRange);
                        }
                    }

                    var finalValue = nextValue / nextValueCount;
                    landMap.SetHeight(x, y, finalValue);
                }
            }
        }
 void ILandMapEffector.Effect(LandMap landMap)
 {
     for (var y = 0; y < LandMap.Size; y++)
     {
         for (var x = 0; x < LandMap.Size; x++)
         {
             var fbm   = fBM(x, y, octaves, lacunarity, gain);
             var value = landMap.GetHeight(x, y);
             landMap.SetHeight(x, y, fbm + value);
         }
     }
 }
 void ILandMapEffector.Effect(LandMap landMap)
 {
     for (var y = 0; y < LandMap.Size; y++)
     {
         for (var x = 0; x < LandMap.Size; x++)
         {
             var voronoi = Voronoi(x, y, u, v);
             var value   = landMap.GetHeight(x, y);
             landMap.SetHeight(x, y, voronoi + value);
         }
     }
 }
Beispiel #4
0
        void ILandMapEffector.Effect(LandMap landMap)
        {
            var random = Random.Range(-1000f, 1000f);

            for (var y = 0; y < LandMap.Size; y++)
            {
                for (var x = 0; x < LandMap.Size; x++)
                {
                    var xSample = random + (float)x / LandMap.Size * noiseScale;
                    var ySample = random + (float)y / LandMap.Size * noiseScale;

                    var noiseValue = OctavePerlin(xSample, ySample);
                    var value      = landMap.GetHeight(x, y);
                    landMap.SetHeight(x, y, noiseValue + value);
                }
            }
        }
        void ILandMapEffector.Effect(LandMap landMap)
        {
            var random = Random.Range(-1000f, 1000f);

            for (var y = 0; y < LandMap.Size; y++)
            {
                for (var x = 0; x < LandMap.Size; x++)
                {
                    var xSample = random + (float)x / LandMap.Size * noiseScale;
                    var ySample = random + (float)y / LandMap.Size * noiseScale;

                    var noise = Mathf.PerlinNoise(xSample, ySample);

                    if (noise <= rounding)
                    {
                        noise = 0;
                    }

                    var value = landMap.GetHeight(x, y);
                    landMap.SetHeight(x, y, noise + value);
                }
            }
        }
        private void Deposit(LandMap landMap, int x, int y)
        {
            var         c           = 0f;
            var         v           = 1.05f;
            const float minSlope    = 1.15f;
            const float maxVelocity = 10f;

            for (var iteration = 0; iteration < iterations; iteration++)
            {
                v = Mathf.Min(v, maxVelocity);
                var value = landMap.GetHeight(x, y);

                float[] nv =
                {
                    landMap.GetHeight(x,     y - 1),
                    landMap.GetHeight(x,     y + 1),
                    landMap.GetHeight(x + 1, y),
                    landMap.GetHeight(x - 1, y)
                };

                var minIndex = IndexOfMinimum(nv);

                if (!(nv[minIndex] < value))
                {
                    continue;
                }

                var slope = Mathf.Min(minSlope, value - nv[minIndex]);
                var vtc   = depositionSpeed * v * slope;

                if (c > carryingCapacity)
                {
                    c -= vtc;
                    landMap.SetHeight(x, y, landMap.GetHeight(x, y) + vtc);
                }
                else
                {
                    if (c + vtc > carryingCapacity)
                    {
                        var delta = c + vtc - carryingCapacity;
                        c += delta;
                        landMap.SetHeight(x, y, landMap.GetHeight(x, y) + delta);
                    }
                    else
                    {
                        c += vtc;
                        landMap.SetHeight(x, y, landMap.GetHeight(x, y) - vtc);
                    }
                }

                switch (minIndex)
                {
                case 0: y -= 1; break;

                case 1: y += 1; break;

                case 2: x += 1; break;

                case 3: x -= 1; break;
                }

                if (x > LandMap.MaxSize)
                {
                    x = LandMap.Size;
                }

                if (x < 0)
                {
                    x = 0;
                }

                if (y > LandMap.MaxSize)
                {
                    y = LandMap.Size;
                }

                if (y < 0)
                {
                    y = 0;
                }
            }

            int IndexOfMinimum(IReadOnlyList <float> array)
            {
                var index    = 0;
                var minValue = array[0];

                for (var i = 0; i < 3; i++)
                {
                    if (!(array[i] < minValue))
                    {
                        continue;
                    }

                    minValue = array[i];
                    index    = i;
                }

                return(index);
            }
        }