コード例 #1
0
    // Checks the advancement and water in Voronoi. When built there is no local minimal.
    // This code will help later for the vectors used in the rives' algorithm.
    // By built, there are low elevation areas in the island meaning that the rivers' ends will
    // follow through the land. Lakes end up on river paths by built, because they do not rise
    // the elevation as much as the rest of the terrain.
    public static void AssignCorner(ref Map map, EnvironmentConstructionScript islandShape, bool needsMoreRandomness)
    {
        System.Random mapRandom = new System.Random(map.generations);
        Queue <Characteristics.Corner> queue = new Queue <Characteristics.Corner>();

        foreach (var q in map.corners)
        {
            q.water = !islandShape.IsInside(q.pos);
        }

        foreach (var q in map.corners)
        {
            // Corners of the map is 0 when built
            if (q.border)
            {
                q.built = 0.0f;
                queue.Enqueue(q);
            }
            else
            {
                q.built = Mathf.Infinity;
            }
        }

        //If 'we' move away from the map border, the elevations will increase. This will enable the rivers go down
        while (queue.Count > 0)
        {
            var q = queue.Dequeue();

            foreach (var s in q.adjacent)
            {
                // Every step up is epsilon over water or 1 over land. The
                // number doesn't matter because we'll rescale the
                // elevations later.
                var newBuilt = 0.01f + q.built;
                if (!q.water && !s.water)
                {
                    newBuilt += 1;
                    if (needsMoreRandomness)
                    {
                        // The map will look nice and smooth because of the random points, rivers and edges.
                        // This random point slections are used in the square and hexagon grids only

                        newBuilt += (float)mapRandom.NextDouble();
                    }
                }
                // If this point changed, we'll add it to the queue so
                // that we can process its neighbors too.
                if (newBuilt < s.built)
                {
                    s.built = newBuilt;
                    queue.Enqueue(s);
                }
            }
        }
    }
コード例 #2
0
    public Map Generate(Vector2 dimensions,
                        int generations,
                        PolygonList.FaceType faceType,
                        EnvironmentConstructionScript.FunctionType functionType,
                        float height,
                        AnimationCurve heightMap,
                        int regionCount,
                        int relaxationCount,
                        float radius)
    {
        data             = new Map();
        data.generations = generations;
        this.height      = height;
        this.heigtMap    = heightMap;
        islandShape      = new EnvironmentConstructionScript(generations, dimensions.x, dimensions.y, functionType);
        rectangle        = new Rectangle(0, 0, dimensions.x, dimensions.y);
        if (faceType == PolygonList.FaceType.Hexagon || faceType == PolygonList.FaceType.Square)
        {
            relaxationCount = 0;        // relaxation is used to create accurate polygon size
        }
        // no specific value for rectangle - able to resize in the editor

        Polygon     polygon = PolygonList.Create(dimensions, generations, faceType, regionCount, radius);
        VoronoiBase voronoi = GenerateVoronoi(ref polygon, relaxationCount);

        Build(polygon, voronoi);
        ImproveBorders();
        // Determine the elevations and water at Voronoi corners.
        Elevation.AssignCorner(ref data, islandShape, faceType == PolygonList.FaceType.Hexagon || faceType == PolygonList.FaceType.Square);


        // Determine polygon and corner type: ocean, coast, land.

        CheckingScript.AssignSeaSealandAndLand(ref data);

        // Rescale elevations so that the highest is 1.0, and they're
        // distributed well. Lower elevations will be more common
        // than higher elevations.

        List <Characteristics.Corner> corners = LandCorners(data.corners);

        Elevation.Readjust(ref corners);

        //  elevations assigned to water corners
        foreach (var q in data.corners)
        {
            if (q.sea || q.sealine)
            {
                q.built = 0.0f;
            }
        }

        // Polygon elevations are the average of their corners
        Elevation.AllocatePolygon(ref data);

        // Determine humidity at corners, starting at rivers
        // and lakes, but not oceans. Then redistribute
        // humidity to cover the entire range evenly from 0.0
        // to 1.0. Then assign polygon humidity as the average
        // of the corner humidity.
        Humidity.AccountEdge(ref data);
        Humidity.Redistribute(ref corners);
        Humidity.AssignPolygon(ref data);

        CheckingScript.AssignHabitat(ref data);

        return(data);
    }