Ejemplo n.º 1
0
        static bool GenBillow2D(MapGenArgs args)
        {
            Billow billow2D = new Billow();

            billow2D.Seed = args.UseSeed ? args.Seed : new Random().Next();
            return(Gen2D(args, billow2D));
        }
Ejemplo n.º 2
0
        static bool Gen2D(MapGenArgs args, IModule module)
        {
            Level lvl = args.Level;
            int   width = lvl.Width, length = lvl.Length, half = lvl.Height / 2;
            int   waterHeight = half - 1;

            for (int z = 0; z < length; ++z)
            {
                for (int x = 0; x < width; ++x)
                {
                    double noise         = module.GetValue(x / 100.0, 0.1, z / 100.0);
                    int    height2D      = (int)System.Math.Floor((noise + 2) * 10) + (half - 20);
                    int    height2Dtex01 = (int)System.Math.Floor((noise + 2) * 15) + (half - 30);
                    byte   topBlock      = height2D < height2Dtex01 ? Block.grass : Block.sand;
                    lvl.SetTile((ushort)x, (ushort)height2D, (ushort)z, topBlock);

                    if (height2D < waterHeight)
                    {
                        for (int y = waterHeight; y >= height2D; y--)
                        {
                            lvl.SetTile((ushort)x, (ushort)y, (ushort)z, Block.water);
                        }
                    }
                    for (int y = height2D - 1; y >= 0; y--)
                    {
                        byte block = (y > height2D * 3 / 4) ? Block.dirt : Block.rock;
                        lvl.SetTile((ushort)x, (ushort)y, (ushort)z, block);
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 3
0
        static bool GenEmpty(MapGenArgs args)
        {
            int maxX = args.Level.Width - 1, maxZ = args.Level.Length - 1;

            Cuboid(args, 0, 0, 0, maxX, 0, maxZ, () => Block.blackrock);
            return(true);
        }
Ejemplo n.º 4
0
        static bool GenRidged2D(MapGenArgs args)
        {
            RidgedMultifractal ridged2D = new RidgedMultifractal();

            ridged2D.Seed = args.UseSeed ? args.Seed : new Random().Next();
            return(Gen2D(args, ridged2D));
        }
Ejemplo n.º 5
0
        static bool GenVoronoi(MapGenArgs args)
        {
            Voronoi voronoi2D = new Voronoi();

            voronoi2D.Seed = args.UseSeed ? args.Seed : new Random().Next();
            return(Gen2D(args, voronoi2D));
        }
Ejemplo n.º 6
0
        unsafe static bool GenFlat(MapGenArgs args)
        {
            Level lvl         = args.Level;
            int   grassHeight = lvl.Height / 2;

            if (args.UseSeed && args.Seed >= 0 && args.Seed < lvl.Height)
            {
                grassHeight = args.Seed;
            }
            lvl.EdgeLevel = grassHeight + 1;

            fixed(byte *ptr = lvl.blocks)
            {
                if (grassHeight > 0)
                {
                    MapSet(lvl.Width, lvl.Length, ptr, 0, grassHeight - 1, Block.dirt);
                }
                if (grassHeight < lvl.Height)
                {
                    MapSet(lvl.Width, lvl.Length, ptr, grassHeight, grassHeight, Block.grass);
                }
            }

            return(true);
        }
Ejemplo n.º 7
0
        static bool GenPerlin3DYAdjust(MapGenArgs args)
        {
            Perlin adjNoise = new Perlin();

            adjNoise.Seed = args.UseSeed ? args.Seed : new Random().Next();
            return(Gen3DYAdjust(args, adjNoise));
        }
Ejemplo n.º 8
0
        static bool GenPerlin3D(MapGenArgs args)
        {
            Perlin perlin3D = new Perlin();

            perlin3D.Seed = args.UseSeed ? args.Seed : new Random().Next();
            return(Gen3D(args, perlin3D));
        }
Ejemplo n.º 9
0
        static bool GenerateMap(MapGenArgs genArgs)
        {
            MapGenTheme theme = MapGenTheme.Forest;

            if (genArgs.Args.Length > 0 &&
                !CommandParser.GetEnum(genArgs.Player, genArgs.Args, "Seed", ref theme))
            {
                return(false);
            }

            MapGenTemplate         templ = (MapGenTemplate)Enum.Parse(typeof(MapGenTemplate), genArgs.Theme.Substring(3), true);
            fCraftMapGeneratorArgs args  = fCraftMapGeneratorArgs.MakeTemplate(templ);
            Level map = genArgs.Level;

            float ratio = map.Height / 96.0f;

            args.MaxHeight    = (int)Math.Round(args.MaxHeight * ratio);
            args.MaxDepth     = (int)Math.Round(args.MaxDepth * ratio);
            args.SnowAltitude = (int)Math.Round(args.SnowAltitude * ratio);

            args.Theme      = theme;
            args.AddTrees   = theme == MapGenTheme.Forest;
            args.AddWater   = theme != MapGenTheme.Desert;
            args.WaterLevel = (map.Height - 1) / 2;

            fCraftMapGenerator generator = new fCraftMapGenerator(args);

            generator.Generate(map);
            return(true);
        }
Ejemplo n.º 10
0
        static bool Gen2D(MapGenArgs args, IModule module)
        {
            Level lvl = args.Level;
            int   width = lvl.Width, length = lvl.Length, half = lvl.Height / 2;
            int   waterHeight = half - 1;

            for (int z = 0; z < length; ++z)
            {
                for (int x = 0; x < width; ++x)
                {
                    double noise      = module.GetValue(x / 100.0, 0.1, z / 100.0);
                    int    dirtHeight = (int)System.Math.Floor((noise + 2) * 10) + (half - 20);
                    int    sandHeight = (int)System.Math.Floor((noise + 2) * 15) + (half - 30);
                    byte   topBlock   = dirtHeight < sandHeight ? Block.Grass : Block.Sand;
                    lvl.SetTile((ushort)x, (ushort)dirtHeight, (ushort)z, topBlock);

                    if (dirtHeight < waterHeight)
                    {
                        for (int y = waterHeight; y >= dirtHeight; y--)
                        {
                            lvl.SetTile((ushort)x, (ushort)y, (ushort)z, Block.StillWater);
                        }
                    }
                    for (int y = dirtHeight - 1; y >= 0; y--)
                    {
                        byte block = (y > dirtHeight * 3 / 4) ? Block.Dirt : Block.Stone;
                        lvl.SetTile((ushort)x, (ushort)y, (ushort)z, block);
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 11
0
        static bool GenerateMap(MapGenArgs genArgs)
        {
            MapGenTheme theme = MapGenTheme.Forest;

            if (genArgs.Args != "" && !Utils.TryParseEnum(genArgs.Args, out theme))
            {
                string[] themes = Enum.GetNames(typeof(MapGenTheme));
                Player.Message(genArgs.Player, "Seed must be one of the following themes: " + themes.Join());
                return(false);
            }

            MapGenTemplate         templ = (MapGenTemplate)Enum.Parse(typeof(MapGenTemplate), genArgs.Theme.Substring(3), true);
            fCraftMapGeneratorArgs args  = fCraftMapGeneratorArgs.MakeTemplate(templ);
            Level map = genArgs.Level;

            float ratio = map.Height / 96.0f;

            args.MaxHeight    = (int)Math.Round(args.MaxHeight * ratio);
            args.MaxDepth     = (int)Math.Round(args.MaxDepth * ratio);
            args.SnowAltitude = (int)Math.Round(args.SnowAltitude * ratio);

            args.Theme      = theme;
            args.AddTrees   = theme == MapGenTheme.Forest;
            args.AddWater   = theme != MapGenTheme.Desert;
            args.WaterLevel = (map.Height - 1) / 2;

            fCraftMapGenerator generator = new fCraftMapGenerator(args);

            generator.Generate(map);
            return(true);
        }
Ejemplo n.º 12
0
        public static bool Generate(Level lvl, string theme, string seed, Player p)
        {
            MapGenArgs genArgs = new MapGenArgs();

            genArgs.Level = lvl; genArgs.Player = p;
            genArgs.Theme = theme; lvl.Config.Theme = theme;
            genArgs.Args  = seed;   lvl.Config.Seed = seed;

            genArgs.UseSeed = seed.Length > 0;
            if (genArgs.UseSeed && !int.TryParse(seed, out genArgs.Seed))
            {
                genArgs.Seed = seed.GetHashCode();
            }
            MapGenerator generator = null;

            simpleGens.TryGetValue(theme, out generator);
            if (generator != null)
            {
                return(generator(genArgs));
            }
            advGens.TryGetValue(theme, out generator);
            if (generator != null)
            {
                return(generator(genArgs));
            }
            return(false);
        }
Ejemplo n.º 13
0
        public static bool Generate(Level lvl, string theme, string args, Player p)
        {
            MapGenArgs genArgs = new MapGenArgs();

            genArgs.Level = lvl; genArgs.Player = p;
            genArgs.Theme = theme; genArgs.Args = args;

            genArgs.UseSeed = args != "";
            if (genArgs.UseSeed && !int.TryParse(args, out genArgs.Seed))
            {
                genArgs.Seed = args.GetHashCode();
            }
            Func <MapGenArgs, bool> generator = null;

            simpleGens.TryGetValue(theme, out generator);
            if (generator != null)
            {
                return(generator(genArgs));
            }
            advGens.TryGetValue(theme, out generator);
            if (generator != null)
            {
                return(generator(genArgs));
            }
            return(false);
        }
Ejemplo n.º 14
0
        public static bool Generate(MapGenArgs args)
        {
            Player p   = args.Player;
            Level  lvl = args.Level;

            if (args.Args == "")
            {
                Player.Message(p, "You need to provide a url for the image."); return(false);
            }

            if (!DownloadImage(args.Args, "extra/heightmap/", p))
            {
                return(false);
            }
            Bitmap bmp = ReadBitmap("tempImage_" + p.name, "extra/heightmap/", p);

            if (bmp == null)
            {
                return(false);
            }
            int index = 0, oneY = lvl.Width * lvl.Length;

            using (bmp) {
                if (lvl.Width != bmp.Width || lvl.Length != bmp.Height)
                {
                    Player.Message(p, "The size of the heightmap is {0} by {1}.", bmp.Width, bmp.Height);
                    Player.Message(p, "The width and length of the new level must match that size.");
                    return(false);
                }

                for (int z = 0; z < bmp.Height; z++)
                {
                    for (int x = 0; x < bmp.Width; x++)
                    {
                        int height = bmp.GetPixel(x, z).R *lvl.Height / 255;
                        for (int y = 0; y < height - 1; y++)
                        {
                            lvl.blocks[index + oneY * y] = Block.dirt;
                        }
                        if (height > 0)
                        {
                            lvl.blocks[index + oneY * (height - 1)] = Block.grass;
                        }
                        index++;
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 15
0
        static bool GenPixel(MapGenArgs args)
        {
            int         maxX = args.Level.Width - 1, maxY = args.Level.Height - 1, maxZ = args.Level.Length - 1;
            Func <byte> block = () => Block.white;

            // Cuboid the four walls
            Cuboid(args, 0, 1, 0, maxX, maxY, 0, block);
            Cuboid(args, 0, 1, maxZ, maxX, maxY, maxZ, block);
            Cuboid(args, 0, 1, 0, 0, maxY, maxZ, block);
            Cuboid(args, maxX, 1, 0, maxX, maxY, maxZ, block);

            // Cuboid base
            Cuboid(args, 0, 0, 0, maxX, 0, maxZ, () => Block.blackrock);
            return(true);
        }
Ejemplo n.º 16
0
        static bool GenPixel(MapGenArgs args)
        {
            int       maxX = args.Level.Width - 1, maxY = args.Level.Height - 1, maxZ = args.Level.Length - 1;
            NextBlock nextBlock = () => Block.White;

            // Cuboid the four walls
            Cuboid(args, 0, 1, 0, maxX, maxY, 0, nextBlock);
            Cuboid(args, 0, 1, maxZ, maxX, maxY, maxZ, nextBlock);
            Cuboid(args, 0, 1, 0, 0, maxY, maxZ, nextBlock);
            Cuboid(args, maxX, 1, 0, maxX, maxY, maxZ, nextBlock);

            // Cuboid base
            Cuboid(args, 0, 0, 0, maxX, 0, maxZ, () => Block.Bedrock);
            return(true);
        }
Ejemplo n.º 17
0
        static bool GenRainbow(MapGenArgs args)
        {
            int         maxX = args.Level.Width - 1, maxY = args.Level.Height - 1, maxZ = args.Level.Length - 1;
            Random      rand  = args.UseSeed ? new Random(args.Seed) : new Random();
            Func <byte> block = () => (byte)rand.Next(Block.red, Block.white);

            // Cuboid the four walls
            Cuboid(args, 0, 1, 0, maxX, maxY, 0, block);
            Cuboid(args, 0, 1, maxZ, maxX, maxY, maxZ, block);
            Cuboid(args, 0, 1, 0, 0, maxY, maxZ, block);
            Cuboid(args, maxX, 1, 0, maxX, maxY, maxZ, block);

            // Cuboid base and top
            Cuboid(args, 0, 0, 0, maxX, 0, maxZ, block);
            Cuboid(args, 0, maxY, 0, maxX, maxY, maxZ, block);
            return(true);
        }
Ejemplo n.º 18
0
        static void Cuboid(MapGenArgs args, int minX, int minY, int minZ,
                           int maxX, int maxY, int maxZ, Func <byte> block)
        {
            int width = args.Level.Width, height = args.Level.Height, length = args.Level.Length;

            byte[] blocks = args.Level.blocks;

            for (int y = minY; y <= maxY; y++)
            {
                for (int z = minZ; z <= maxZ; z++)
                {
                    for (int x = minX; x <= maxX; x++)
                    {
                        blocks[x + width * (z + y * length)] = block();
                    }
                }
            }
        }
Ejemplo n.º 19
0
        static bool GenSpace(MapGenArgs args)
        {
            int         maxX = args.Level.Width - 1, maxY = args.Level.Height - 1, maxZ = args.Level.Length - 1;
            Random      rand  = args.UseSeed ? new Random(args.Seed) : new Random();
            Func <byte> block = () => rand.Next(100) == 0 ? Block.iron : Block.obsidian;

            // Cuboid the four walls
            Cuboid(args, 0, 2, 0, maxX, maxY, 0, block);
            Cuboid(args, 0, 2, maxZ, maxX, maxY, maxZ, block);
            Cuboid(args, 0, 2, 0, 0, maxY, maxZ, block);
            Cuboid(args, maxX, 2, 0, maxX, maxY, maxZ, block);

            // Cuboid base and top
            Cuboid(args, 0, 0, 0, maxX, 0, maxZ, () => Block.blackrock);
            Cuboid(args, 0, 1, 0, maxX, 1, maxZ, block);
            Cuboid(args, 0, maxY, 0, maxX, maxY, maxZ, block);
            return(true);
        }
Ejemplo n.º 20
0
        static bool GenHell(MapGenArgs args)
        {
            Random rand = args.UseSeed ? new Random(args.Seed) : new Random();
            int    width = args.Level.Width, height = args.Level.Height, length = args.Level.Length;
            int    index = 0;

            byte[] blocks = args.Level.blocks;

            for (int y = 0; y < height; ++y)
            {
                for (int z = 0; z < length; ++z)
                {
                    for (int x = 0; x < width; ++x)
                    {
                        if (y == 0)
                        {
                            blocks[index] = Block.blackrock;
                        }
                        else if (x == 0 || x == width - 1 || z == 0 || z == length - 1 || y == 0 || y == height - 1)
                        {
                            blocks[index] = Block.obsidian;
                        }
                        else if (x == 1 || x == width - 2 || z == 1 || z == length - 2)
                        {
                            if (rand.Next(1000) != 7)
                            {
                                index++; continue;
                            }

                            int colIndex = z * width + x;
                            for (int i = 1; i < (height - y); ++i)
                            {
                                int yy = height - i;
                                blocks[colIndex + yy * width * length] = Block.lava;
                            }
                        }
                        index++;
                    }
                }
            }
            return(GenSimple(args));
        }
Ejemplo n.º 21
0
        static bool Gen3DYAdjust(MapGenArgs args, IModule module)
        {
            Level lvl = args.Level;
            int   width = lvl.Width, height = lvl.Height, length = lvl.Length;

            for (int y = 0; y < height; y++)
            {
                for (int z = 0; z < length; ++z)
                {
                    for (int x = 0; x < width; ++x)
                    {
                        double value = System.Math.Floor((module.GetValue(x / 100.0, y / 100.0, z / 100.0) + 2) * 10);
                        if (value > 30 * y / height)
                        {
                            lvl.SetTile((ushort)x, (ushort)y, (ushort)z, Block.grass);
                        }
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 22
0
        public bool GenerateMap(MapGenArgs args)
        {
            DateTime start = DateTime.UtcNow;

            Logger.Log(LogType.SystemActivity, "Attempting map gen");
            rand = args.UseSeed ? new Random(args.Seed) : new Random();
            Level lvl = args.Level;

            if (!RealisticGenParams.Themes.TryGetValue(args.Theme, out genParams))
            {
                genParams = new RealisticGenParams();
            }

            try {
                terrain = new float[lvl.Width * lvl.Length];
                overlay = new float[lvl.Width * lvl.Length];
                if (genParams.GenTrees)
                {
                    overlay2 = new float[lvl.Width * lvl.Length];
                }
                LiquidLevel = genParams.GetLiquidLevel(lvl.Height);

                GenerateFault(terrain, lvl, rand);
                FilterAverage(lvl);
                Logger.Log(LogType.SystemActivity, "Creating overlay");
                GeneratePerlinNoise(overlay, lvl, rand);

                if (genParams.GenerateOverlay2)
                {
                    Logger.Log(LogType.SystemActivity, "Planning trees");
                    GeneratePerlinNoise(overlay2, lvl, rand);
                }

                Logger.Log(LogType.SystemActivity, "Converting height map, and applying overlays");
                float rangeLo = genParams.RangeLow;
                float rangeHi = genParams.RangeHigh;
                treeDens = genParams.TreeDens;
                treeDist = genParams.TreeDist;

                //loops though evey X/Z coordinate
                for (int index = 0; index < terrain.Length; index++)
                {
                    ushort x = (ushort)(index % lvl.Width);
                    ushort z = (ushort)(index / lvl.Width);
                    ushort y;
                    if (genParams.FalloffEdges)
                    {
                        float offset = NegateEdge(x, z, lvl);
                        y = Evaluate(lvl, Range(terrain[index], rangeLo - offset, rangeHi - offset));
                    }
                    else
                    {
                        y = Evaluate(lvl, Range(terrain[index], rangeLo, rangeHi));
                    }

                    if (!genParams.UseLavaLiquid)
                    {
                        GenNonLavaColumn(x, y, z, lvl, index);
                    }
                    else
                    {
                        GenLavaColumn(x, y, z, lvl, index);
                    }
                }
                Logger.Log(LogType.SystemActivity, "Total time was {0} seconds.", (DateTime.UtcNow - start).TotalSeconds);
            } catch (Exception e) {
                Logger.LogError(e);
                Player.Message(args.Player, "Generation failed.");
                return(false);
            }
            return(true);
        }
Ejemplo n.º 23
0
 static bool GenSimple(MapGenArgs args)
 {
     return(new RealisticMapGen().GenerateMap(args));
 }
Ejemplo n.º 24
0
 static bool GenCylinders(MapGenArgs args)
 {
     return(Gen2D(args, new Cylinders()));
 }
Ejemplo n.º 25
0
 static bool GenSpheres(MapGenArgs args)
 {
     return(Gen2D(args, new Spheres()));
 }
Ejemplo n.º 26
0
 static bool GenCheckerboard(MapGenArgs args)
 {
     return(Gen2D(args, new Checkerboard()));
 }
Ejemplo n.º 27
0
        public static bool Generate(MapGenArgs args)
        {
            Player p   = args.Player;
            Level  lvl = args.Level;

            if (args.Args.Length == 0)
            {
                Player.Message(p, "You need to provide a url for the image."); return(false);
            }

            if (!DownloadImage(args.Args, "extra/heightmap/", p))
            {
                return(false);
            }
            string user = p == null ? "(console)" : p.name;
            Bitmap bmp  = ReadBitmap("tempImage_" + user, "extra/heightmap/", p);

            if (bmp == null)
            {
                return(false);
            }

            int index = 0, oneY = lvl.Width * lvl.Length;

            using (bmp) {
                if (lvl.Width != bmp.Width || lvl.Length != bmp.Height)
                {
                    Player.Message(p, "The size of the heightmap is {0} by {1}.", bmp.Width, bmp.Height);
                    Player.Message(p, "The width and length of the new level must match that size.");
                    return(false);
                }

                using (PixelGetter pixels = new PixelGetter(bmp)) {
                    pixels.Init();
                    for (int z = 0; z < pixels.Height; z++)
                    {
                        for (int x = 0; x < pixels.Width; x++)
                        {
                            int  height = pixels.Get(x, z).R;
                            byte layer = Block.Dirt, top = Block.Grass;

                            if (
                                IsShorterBy(height, pixels, x - 1, z) ||
                                IsShorterBy(height, pixels, x + 1, z) ||
                                IsShorterBy(height, pixels, x, z - 1) ||
                                IsShorterBy(height, pixels, x, z + 1))
                            {
                                layer = Block.Stone; top = Block.Stone;
                            }

                            height = height * lvl.Height / 255;
                            for (int y = 0; y < height - 1; y++)
                            {
                                lvl.blocks[index + oneY * y] = layer;
                            }
                            if (height > 0)
                            {
                                lvl.blocks[index + oneY * (height - 1)] = top;
                            }
                            index++;
                        }
                    }
                }
            }
            return(true);
        }