コード例 #1
0
    public Map Generate(Vector2 dimensions,
                        int seed,
                        PointSelector.FaceType faceType,
                        IslandShape.FunctionType functionType,
                        float height,
                        AnimationCurve heightMap,
                        int regionCount,
                        int relaxationCount,
                        float radius)
    {
        data          = new Map();
        data.seed     = seed;
        this.height   = height;
        this.heigtMap = heightMap;
        islandShape   = new IslandShape(seed, dimensions.x, dimensions.y, functionType);
        rectangle     = new Rectangle(0, 0, dimensions.x, dimensions.y);
        if (faceType == PointSelector.FaceType.Hexagon || faceType == PointSelector.FaceType.Square)
        {
            relaxationCount = 0;
        }

        Polygon     polygon = PointSelector.Generate(dimensions, seed, faceType, regionCount, radius);
        VoronoiBase voronoi = GenerateVoronoi(ref polygon, relaxationCount);

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


        // Determine polygon and corner type: ocean, coast, land.
        Biomes.AssignOceanCoastAndLand(ref data);

        // Rescale elevations so that the highest is 1.0, and they're
        // distributed well. We want lower elevations to be more common
        // than higher elevations, in proportions approximately matching
        // concentric rings. That is, the lowest elevation is the
        // largest ring around the island, and therefore should more
        // land area than the highest elevation, which is the very
        // center of a perfectly circular island.

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

        Elevation.Redistribute(ref corners);

        // Assign elevations to non-land corners
        foreach (var q in data.corners)
        {
            if (q.ocean || q.coast)
            {
                q.elevation = 0.0f;
            }
        }

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

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

        Biomes.AssignBiomes(ref data);

        return(data);
    }