Exemple #1
0
        public static void RegisterGenerators()
        {
            const GenType type = GenType.Simple;

            MapGen.Register("Island", type, GenIsland, defHelp);
            MapGen.Register("Mountains", type, GenMountains, defHelp);
            MapGen.Register("Forest", type, GenForest, defHelp);
            MapGen.Register("Ocean", type, GenOcean, defHelp);
            MapGen.Register("Flat", type, GenFlat, "&HSeed specifies grass height (default half of level height)");
            MapGen.Register("Pixel", type, GenPixel, "&HSeed does nothing");
            MapGen.Register("Empty", type, GenEmpty, "&HSeed does nothing");
            MapGen.Register("Desert", type, GenDesert, defHelp);
            MapGen.Register("Space", type, GenSpace, defHelp);
            MapGen.Register("Rainbow", type, GenRainbow, defHelp);
            MapGen.Register("Hell", type, GenHell, defHelp);
        }
        static bool GenHell(Player p, Level lvl, string seed)
        {
            Random rng = MapGen.MakeRng(seed);
            int    width = lvl.Width, height = lvl.Height, length = lvl.Length;
            int    index = 0;

            byte[] blocks = lvl.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.Bedrock;
                        }
                        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 (rng.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++;
                    }
                }
            }

            lvl.Config.CloudColor   = "#000000";
            lvl.Config.SkyColor     = "#FFCC00";
            lvl.Config.FogColor     = "#FF6600";
            lvl.Config.HorizonBlock = Block.StillLava;
            return(new RealisticMapGen().Gen(p, lvl, seed, RealisticMapGenArgs.hell));
        }
Exemple #3
0
        static bool GenRainbow(Player p, Level lvl, string seed)
        {
            int       maxX = lvl.Width - 1, maxY = lvl.Height - 1, maxZ = lvl.Length - 1;
            Random    rng       = MapGen.MakeRng(seed);
            NextBlock nextBlock = () => (byte)rng.Next(Block.Red, Block.White);

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

            // Cuboid base and top
            Cuboid(lvl, 0, 0, 0, maxX, 0, maxZ, nextBlock);
            Cuboid(lvl, 0, maxY, 0, maxX, maxY, maxZ, nextBlock);
            return(true);
        }
Exemple #4
0
        static bool GenSpace(Player p, Level lvl, string seed)
        {
            int       maxX = lvl.Width - 1, maxY = lvl.Height - 1, maxZ = lvl.Length - 1;
            Random    rng       = MapGen.MakeRng(seed);
            NextBlock nextBlock = () => rng.Next(100) == 0 ? Block.Iron : Block.Obsidian;

            // Cuboid the four walls
            Cuboid(lvl, 0, 2, 0, maxX, maxY, 0, nextBlock);
            Cuboid(lvl, 0, 2, maxZ, maxX, maxY, maxZ, nextBlock);
            Cuboid(lvl, 0, 2, 0, 0, maxY, maxZ, nextBlock);
            Cuboid(lvl, maxX, 2, 0, maxX, maxY, maxZ, nextBlock);

            // Cuboid base and top
            Cuboid(lvl, 0, 0, 0, maxX, 0, maxZ, () => Block.Bedrock);
            Cuboid(lvl, 0, 1, 0, maxX, 1, maxZ, nextBlock);
            Cuboid(lvl, 0, maxY, 0, maxX, maxY, maxZ, nextBlock);
            return(true);
        }
Exemple #5
0
        public static Level Generate(Player p, MapGen gen, string name,
                                     ushort x, ushort y, ushort z, string seed)
        {
            name = name.ToLower();
            if (gen == null)
            {
                PrintThemes(p); return(null);
            }
            if (!Formatter.ValidMapName(p, name))
            {
                return(null);
            }

            if (LevelInfo.MapExists(name))
            {
                p.Message("%WLevel \"{0}\" already exists", name); return(null);
            }

            if (Interlocked.CompareExchange(ref p.GeneratingMap, 1, 0) == 1)
            {
                p.Message("You are already generating a map, please wait until that map has finished generating first.");
                return(null);
            }

            Level lvl;

            try {
                p.Message("Generating map \"{0}\"..", name);
                lvl = new Level(name, x, y, z);
                if (!gen.Generate(p, lvl, seed))
                {
                    lvl.Dispose(); return(null);
                }

                string format = seed.Length > 0 ? "{0}%S created level {1}%S with seed \"{2}\"" : "{0}%S created level {1}";
                string msg    = string.Format(format, p.ColoredName, lvl.ColoredName, seed);
                Chat.MessageGlobal(msg);
            } finally {
                Interlocked.Exchange(ref p.GeneratingMap, 0);
                Server.DoGC();
            }
            return(lvl);
        }
Exemple #6
0
        public static void RegisterGenerators()
        {
            string[] names = Enum.GetNames(typeof(MapGenBiome));
            string   desc  = "%HSeed specifies biome of the map. " +
                             "It must be one of the following: &f" + names.Join();

            for (MapGenTheme theme = 0; theme < MapGenTheme.Count; theme++)
            {
                // Because of the way C# implements for loop closures, '=> Gen(p, lvl, seed, theme_)'
                //  captures the variable from the LAST iteration, not the current one
                // Hence this causes an error to get thrown later, because 'Gen' is always executed
                //  with 'MapGenTheme.Count' theme instead of the expected theme
                // Using a local variable copy fixes this
                MapGenTheme theme_ = theme;

                MapGen.Register(theme_.ToString(), GenType.fCraft,
                                (p, lvl, seed) => Gen(p, lvl, seed, theme_), desc);
            }
        }
Exemple #7
0
        public bool Gen(Player p, Level lvl, string seed, RealisticMapGenArgs args)
        {
            DateTime start = DateTime.UtcNow;

            Logger.Log(LogType.SystemActivity, "Attempting map gen");
            rng       = MapGen.MakeRng(seed);
            this.args = args;

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

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

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

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

                //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 (args.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 (!args.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);
                p.Message("&WGeneration failed. See error logs.");
                return(false);
            }
            return(true);
        }