Dwarrowdelf.TerrainGen.RiverGen.CreateRiverPath C# (CSharp) Method

CreateRiverPath() public method

public CreateRiverPath ( ) : bool
return bool
        public bool CreateRiverPath()
        {
            int offset = m_random.Next();

            m_riverPath = null;

            for (int i = 0; i < 8; ++i)
            {
                SideEdge edge = (SideEdge)((i + offset) % 4);

                var startLoc = FindStartLoc(m_random, edge);

                var target = new MyTarget(m_terrain, startLoc, edge);
                int maxNodeCount = 500000; // XXX this should reflect the map size
                var res = AStar.Find(new IntVector3[] { startLoc }, target, maxNodeCount);

                if (res.Status != AStarStatus.Found)
                    continue;

                var riverPath = res.GetPathLocationsReverse().Select(p => p.ToIntVector2()).ToArray();

                if (riverPath.Length < 100)
                {
                    Trace.TraceInformation("retry, too short");
                    continue;
                }

                int tot = riverPath.Aggregate(0, (a, p) =>
                    a + MyMath.Min(p.X, p.Y, m_terrain.Width - p.X - 1, m_terrain.Height - p.Y - 1));

                int avg = tot / riverPath.Length;

                if (avg < 20)
                {
                    Trace.TraceInformation("too close to edge, avg {0}", avg);
                    continue;
                }

                m_riverPath = riverPath;

                return true;
            }

            return false;
        }

Usage Example

Beispiel #1
0
        public void Generate(DiamondSquare.CornerData corners, double range, double h, double amplify)
        {
            GenerateHeightMap(corners, range, h, amplify);

            FillMap();

            var random  = m_random;
            var terrain = m_data;

            double xk = (random.NextDouble() * 2 - 1) * 0.01;
            double yk = (random.NextDouble() * 2 - 1) * 0.01;

            TerrainHelpers.CreateBaseMinerals(terrain, random, xk, yk);

            TerrainHelpers.CreateOreVeins(terrain, random, xk, yk);

            TerrainHelpers.CreateOreClusters(terrain, random);

            if (m_data.Width > 128)
            {
                var riverGen = new RiverGen(m_data, m_random);
                if (riverGen.CreateRiverPath())
                {
                    riverGen.AdjustRiver();
                }
                else
                {
                    Trace.TraceError("Failed to create river");
                }
            }

            int soilLimit = m_size.Depth * 4 / 5;

            TerrainHelpers.CreateSoil(m_data, soilLimit);
        }
All Usage Examples Of Dwarrowdelf.TerrainGen.RiverGen::CreateRiverPath