Ejemplo n.º 1
0
        public override IEnumerator Recalculating()
        {
            byte  sandTileId = _tileset.Sand.Id;
            byte  soilId     = _tileset.Soil.Id;
            float seaLevel   = GameContext.SeaLevel;

            int layer = (int)TilemapLayer.Soil;

            foreach (Position position in Values.AllCellMiddles())
            {
                if (_waterMapValues.Get(position) != WaterIngredientGenerator.Ground)
                {
                    Values.Set(position, None);
                    continue;
                }

                float height = _heightMapValues.Get(position);

                float aboveSeaLevel = height - seaLevel;
                if (aboveSeaLevel < _config.HeightAboveSeaForNormalSoil)
                {
                    Values.Set(position, Sand);
                    _tileMatricesByte[layer].Set(position, sandTileId);
                }
                else
                {
                    Values.Set(position, Soil);
                    _tileMatricesByte[layer].Set(position, soilId);
                }
            }

            yield return(new WaitForSeconds(0.1f));
        }
Ejemplo n.º 2
0
        public override IEnumerator Recalculating()
        {
            _seaLevel = GameContext.SeaLevel;
            var matrixByteForWaterLayer = GameContext.TileMatricesByLayer[(int)TilemapLayer.Water];
            var matrixByteForDirtLayer  = GameContext.TileMatricesByLayer[(int)TilemapLayer.Dirt];

            byte saltyWaterId = _tileset.SaltyWater.Id;
            byte dirtId       = _tileset.DryDirt.Id;

            foreach (Position cellMiddle in Values.AllCellMiddles())
            {
                matrixByteForWaterLayer.Set(cellMiddle, saltyWaterId);

                if (_heightMapValues.Get(cellMiddle) < _seaLevel)
                {
                    Values.Set(cellMiddle, Sea);
                }
                else
                {
                    matrixByteForDirtLayer.Set(cellMiddle, dirtId);
                    Values.Set(cellMiddle, Ground);
                }
            }

            float mapHectars = Values.XSize * Values.YSize / 10000f;
            int   lakeCount  = (int)(mapHectars * _config.SoleLakesCountPerHectar);

            for (int i = 0; i < lakeCount; i++)
            {
                int lakePositions = (int)_config.RandomToSoleLakeArea.Evaluate(_rng.NextFloat());
                yield return(new WaitForSeconds(0.1f));
            }

            yield return(new WaitForSeconds(0.1f));
        }
Ejemplo n.º 3
0
 public override IEnumerator Recalculating()
 {
     foreach (Position position in Values.AllCellMiddles())
     {
         Values.Set(position, 0f);
     }
     yield break;
 }
 private void BuryDepressions(float cutOffValue, int[,] closedSeaPositions)
 {
     foreach (Position position in Values.AllCellMiddles())
     {
         float value = Values.Get(position);
         Func <int, int, bool> isSea = (x, y) => closedSeaPositions[x, y] < int.MaxValue;
         if (value < cutOffValue && !isSea(position.x, position.y))
         {
             float heightReflectedFromCutoff = 2 * cutOffValue - value;                   // to prevent depressions
             Values.Set(position, heightReflectedFromCutoff);
         }
     }
 }
        public override IEnumerator Recalculating()
        {
            Position                middle = new Position(Values.XSize / 2, Values.YSize / 2);
            float                   furthestDistanceToMiddle = Position.Distance(Position.MinValue, middle);
            float                   noiseScale            = _config.Scale;
            AnimationCurve          toCenterFalloffCurve  = _config.MaxFactorDistanceFromCenterToFalloff;
            Dictionary <int, float> afterNoiseAdjustments = InitializeAfterNoiseAdjustments(_config.Octaves);

            foreach (Position position in Values.AllCellMiddles())
            {
                Position probedPositionForNoise = position + _noiseOffset;

                float persistence01 = 0.5f;

                float heightValue = Perlin.Noise(probedPositionForNoise.x * noiseScale, probedPositionForNoise.y * noiseScale,
                                                 _config.Octaves, persistence01);
                int adjustmentKey = (int)Math.Round(persistence01 * 10);
                heightValue *= afterNoiseAdjustments[adjustmentKey];

                float distanceToMiddle         = Position.Distance(position, middle);
                float relativeDistanceToMiddle = distanceToMiddle / furthestDistanceToMiddle;
                heightValue *= toCenterFalloffCurve.Evaluate(relativeDistanceToMiddle);
                Values.Set(position, heightValue);
            }

            float cutOffValue = CalculateSeaLevelToMatchGroundPercentage();

            GameContext.SeaLevel = cutOffValue;

            bool Qualifier(int x, int y) => Values.Get(x, y) < cutOffValue;

            var bounds     = new FloodBounds(Values.XSize, Values.YSize);
            var parameters = new FloodParameters(0, 0)
            {
                Qualifier         = Qualifier,
                BoundsRestriction = bounds,
                NeighbourhoodType = NeighbourhoodType.Four
            };

            int[,] closedSeaPositions = new int[bounds.SizeX, bounds.SizeY];
            new FloodSpiller().SpillFlood(parameters, closedSeaPositions);

            BuryDepressions(cutOffValue, closedSeaPositions);

            yield return(new WaitForSeconds(0.1f));
        }
Ejemplo n.º 6
0
        public override IEnumerator Recalculating()
        {
            OsnowaBaseTile dirtBaseTile   = _worldGeneratorConfig.Tileset.DryDirt;
            MatrixByte     dirtMatrixByte = GameContext.TileMatricesByLayer[(int)dirtBaseTile.Layer];
            float          seaLevel       = GameContext.SeaLevel;

            foreach (Position position in Values.AllCellMiddles())
            {
                float value  = _initialShapeValues.Get(position);
                bool  isLand = value > seaLevel;
                value = isLand ? float.MaxValue : float.MinValue;
                Values.Set(position, value);
                if (isLand)
                {
                    dirtMatrixByte.Set(position, dirtBaseTile.Id);
                }
            }

            yield return(new WaitForSeconds(0.1f));
        }