コード例 #1
0
ファイル: IMapGenerator.cs プロジェクト: xorle/MineEdit
        internal virtual void Precipitate(ref byte[, ,] b, BiomeType[,] bt, MapGenMaterials mats, long X, long Z)
        {
            int xs = b.GetLength(0);
            int zs = b.GetLength(2);

            for (int x = 0; x < xs; x++)
            {
                for (int z = 0; z < zs; z++)
                {
                    if (Biome.NeedsSnowAndIce(bt[x, z]))
                    {
                        continue;
                    }
                    // Fall down
                    for (int y = b.GetLength(1) - 1; y > 0; y--)
                    {
                        byte block = b[x, y, z];
                        if (block == 0)
                        {
                            continue;
                        }
                        if (block == mats.Water)
                        {
                            b[x, y, z] = mats.Ice;
                        }
                        else
                        {
                            b[x, y + 1, z] = mats.Snow;
                        }
                        break;
                    }
                }
            }
        }
コード例 #2
0
        public static IMapGenerator Get(string gen, long Seed, MapGenMaterials Materials)
        {
            if (gen == null)
            {
                gen = "QuickHillGenerator";
            }
            if (Generators.Count == 0)
            {
                Generators.Add("QuickHillGenerator", typeof(QuickHillGenerator));
            }
            string id = "QuickHillGenerator";

            if (Generators.ContainsKey(gen))
            {
                id = gen;
            }
            Console.WriteLine("Initializing {0}.", id);
            IMapGenerator g = (IMapGenerator)Generators[id].GetConstructor(new Type[] { typeof(long) }).Invoke(new object[] { Seed });

            g.Materials        = Materials;
            g.GenerateCaves    = true;
            g.GenerateDungeons = true;
            g.GenerateOres     = true;
            g.GenerateWater    = true;
            g.HellMode         = false;
            g.GenerateTrees    = true;
            g.NoPreservation   = false;
            return(g);
        }
コード例 #3
0
ファイル: MapGenMaterials.cs プロジェクト: xorle/MineEdit
 public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
 {
     if (destinationType == typeof(string) && value is MapGenMaterials)
     {
         MapGenMaterials mgm = (MapGenMaterials)value;
         return(mgm.ToString());
     }
     return(base.ConvertTo(context, culture, value, destinationType));
 }
コード例 #4
0
ファイル: IMapGenerator.cs プロジェクト: xorle/MineEdit
        public virtual void AddSoil(long X, long Z, RidgedMultifractal CavernNoise, Perlin CaveNoise, double[,] hm, ref byte[,,] b, BiomeType[,] biomes, int WaterHeight, int depth, MapGenMaterials mats)
        {
            int    YH = b.GetLength(1) - 2;
            double xo = (double)(X * b.GetLength(0));
            double zo = (double)(Z * b.GetLength(2));

            for (int x = 0; x < b.GetLength(0); x++)
            {
                //Console.WriteLine();
                for (int z = 0; z < b.GetLength(2); z++)
                {
                    double hmY = (double)(System.Math.Min(hm[x, z], 1d) * (b.GetLength(1) - 3));
                    bool   HavePloppedGrass = false;
                    bool   HaveTouchedSoil  = false;
                    // Caves first
                    if (GenerateCaves)
                    {
                        for (int y = 0; y < b.GetLength(1); y++)
                        {
                            // If we're in rock, and CavernNoise value is under a threshold value calculated by height
                            //  or CaveNoise value is over threshold value, and the block we're removing won't fall on us...
                            if (
                                b[x, y, z] == 1 &&
                                (
                                    ((CavernNoise.GetValue(x + xo, y, z + zo) / 2) + 1) < Utils.Lerp(CavernThresholdMax, CavernThresholdMin, (((double)y / (hmY + 1)))) ||
                                    (Utils.FixLibnoiseOutput(CaveNoise.GetValue(x + xo, y, z + zo)) > CaveThreshold)
                                ) &&
                                !(b[x, y, z] == 9 || b[x, y, z] == 8 || b[x, y, z] == 12 || b[x, y, z] == 13))
                            {
                                // Remove it
                                b[x, y, z] = 0;
                            }
                        }
                    }
                    for (int y = (int)b.GetLength(1) - 1; y > 0; y--)
                    {
                        byte supportBlock = b[x, y - 1, z];
                        // Ensure there's going to be stuff holding us up.
                        if (b[x, y, z] == mats.Rock && supportBlock == mats.Rock)
                        {
                            HaveTouchedSoil = true;
                            if (y + depth >= YH)
                            {
                                continue;
                            }
                            byte ddt = b[x, y + depth, z];
                            switch (ddt)
                            {
                            case 0:     // Air
                            case 8:     // Water
                            case 9:     // Water
                                BiomeType bt = biomes[x, z];
                                if (bt == BiomeType.Tundra)
                                {
                                    b[x, y, z] = mats.Sand;
                                }
                                else
                                {
                                    if (y - depth <= WaterHeight && GenerateWater)
                                    {
                                        if ((bt == BiomeType.Taiga || bt == BiomeType.TemperateForest || bt == BiomeType.Tundra) && y > WaterHeight)
                                        {
                                            b[x, y, z] = (HavePloppedGrass) ? mats.Soil : mats.Grass;
                                        }
                                        else
                                        {
                                            b[x, y, z] = mats.Sand;
                                        }
                                    }
                                    else
                                    {
                                        b[x, y, z] = (HavePloppedGrass) ? mats.Soil : mats.Grass;
                                    }
                                }
                                if (!HavePloppedGrass)
                                {
                                    HavePloppedGrass = true;
                                }
                                break;

                            default:
                                y = 0;
                                break;
                            }
                        }
                        else if (b[x, y, z] == 0 && y <= WaterHeight && !HaveTouchedSoil && GenerateWater)
                        {
                            b[x, y, z] = mats.Water;
                        }
                    }
                }
            }
        }