示例#1
0
    // Generates and adds heightmap to dictionary
    // based on initial cartesian coordinates
    public float[,] GenerateHeightmap(int x, int y, uint[,] subBiome, float[,] gradient)
    {
        // Create 2D array of noise values
        float[,] heightmap = new float[HeightmapDimensions, HeightmapDimensions];

        // Assign this biome map
        BiomeMap = subBiome;

        // Check for adjacent heightmaps
        adjacentTruthTable = new Tuple <bool, bool, bool, bool>(
            MapDatabaseScript.IsFilled(x, y + 1),
            MapDatabaseScript.IsFilled(x + 1, y),
            MapDatabaseScript.IsFilled(x, y - 1),
            MapDatabaseScript.IsFilled(x - 1, y)
            );

        // Copy over top values
        if (adjacentTruthTable.Item1)
        {
            float[,] hm = MapDatabaseScript.GetHeightmap(x, y + 1);
            for (int i = 0; i < HeightmapDimensions; i++)
            {
                heightmap[0, i] = hm[HeightmapDimensions - 1, i];
            }
        }

        // Copy over right values
        if (adjacentTruthTable.Item2)
        {
            float[,] hm = MapDatabaseScript.GetHeightmap(x + 1, y);
            for (int i = 0; i < HeightmapDimensions; i++)
            {
                heightmap[i, HeightmapDimensions - 1] = hm[i, 0];
            }
        }

        // Copy over bottom values
        if (adjacentTruthTable.Item3)
        {
            float[,] hm = MapDatabaseScript.GetHeightmap(x, y - 1);
            for (int i = 0; i < HeightmapDimensions; i++)
            {
                heightmap[HeightmapDimensions - 1, i] = hm[0, i];
            }
        }

        // Copy over left values
        if (adjacentTruthTable.Item4)
        {
            float[,] hm = MapDatabaseScript.GetHeightmap(x - 1, y);
            for (int i = 0; i < HeightmapDimensions; i++)
            {
                heightmap[i, 0] = hm[i, HeightmapDimensions - 1];
            }
        }

        /*
         * // Set values to uninitialized verticies
         * if (!adjacentTruthTable.Item1 && !adjacentTruthTable.Item4)
         *  heightmap[0, 0] = GetBiomeVertex(0, 0);
         *
         * if (!adjacentTruthTable.Item3 && !adjacentTruthTable.Item4)
         *  heightmap[HeightmapDimensions - 1, 0] = GetBiomeVertex(HeightmapDimensions - 1, 0);
         *
         * if (!adjacentTruthTable.Item1 && !adjacentTruthTable.Item2)
         *  heightmap[0, HeightmapDimensions - 1] = GetBiomeVertex(0, HeightmapDimensions - 1);
         *
         * if (!adjacentTruthTable.Item2 && !adjacentTruthTable.Item3)
         *  heightmap[HeightmapDimensions - 1, HeightmapDimensions - 1] = GetBiomeVertex(HeightmapDimensions - 1, HeightmapDimensions - 1);
         */

        //DiamondSquareGen(heightmap, 0, HeightmapDimensions - 1, 0, HeightmapDimensions - 1);

        //ZeroGen(HeightmapDimensions, heightmap);

        //BasicBiomeGen(HeightmapDimensions, heightmap);

        AdvancedBiomeGen(HeightmapDimensions, heightmap, gradient);

        MapDatabaseScript.AddHeightmap(x, y, heightmap);
        return(heightmap);
    }