Ejemplo n.º 1
0
        public static void DoShrub(Level lvl, ref Check C)
        {
            Random rand = lvl.physRandom;
            ushort x, y, z;

            lvl.IntToPos(C.b, out x, out y, out z);
            if (lvl.physics > 1)   //Adv physics kills flowers and mushroos in water/lava
            {
                AirPhysics.PhysAir(lvl, lvl.PosToInt((ushort)(x + 1), y, z));
                AirPhysics.PhysAir(lvl, lvl.PosToInt((ushort)(x - 1), y, z));
                AirPhysics.PhysAir(lvl, lvl.PosToInt(x, y, (ushort)(z + 1)));
                AirPhysics.PhysAir(lvl, lvl.PosToInt(x, y, (ushort)(z - 1)));
                AirPhysics.PhysAir(lvl, lvl.PosToInt(x, (ushort)(y + 1), z));
            }

            if (!lvl.growTrees)
            {
                C.data.Data = 255; return;
            }
            if (C.data.Data < 20)
            {
                if (rand.Next(20) == 0)
                {
                    C.data.Data++;
                }
                return;
            }

            TreeDrawOp op = new TreeDrawOp();

            op.random = rand;
            op.method = DrawOp.M_BlockChange;
            op.Perform(new [] { new Vec3U16(x, y, z) }, null, lvl, null);
            C.data.Data = 255;
        }
Ejemplo n.º 2
0
        protected override DrawOp GetDrawOp(DrawArgs dArgs)
        {
            string[] args = dArgs.Message.SplitSpaces(3);
            Tree     tree = Tree.Find(args[0]);

            if (tree == null)
            {
                tree = new NormalTree();
            }

            int size;

            if (args.Length > 1 && int.TryParse(args[1], out size))
            {
                Player p   = dArgs.Player;
                string opt = args[0] + " tree size";
                if (!CommandParser.GetInt(p, args[1], opt, ref size, tree.MinSize, tree.MaxSize))
                {
                    return(null);
                }
            }
            else
            {
                size = -1;
            }

            TreeDrawOp op = new TreeDrawOp();

            op.Tree = tree; op.Size = size;
            return(op);
        }
Ejemplo n.º 3
0
        bool DoTree(Player p, Vec3S32[] marks, object state, ExtBlock block)
        {
            DrawArgs   dArgs = (DrawArgs)state;
            TreeDrawOp op    = new TreeDrawOp();

            op.Tree = dArgs.tree;
            op.Size = dArgs.size;

            Brush brush = null;

            if (dArgs.brushMsg.Length > 0)
            {
                brush = ParseBrush(dArgs.brushMsg, p, block);
            }
            DrawOpPerformer.Do(op, brush, p, marks);
            return(true);
        }
Ejemplo n.º 4
0
        protected override void GetBrush(DrawArgs dArgs)
        {
            TreeDrawOp op = (TreeDrawOp)dArgs.Op;

            if (op.Size != -1)
            {
                dArgs.BrushArgs = dArgs.Message.Splice(2, 0); // type, value/height, brush args
            }
            else
            {
                dArgs.BrushArgs = dArgs.Message.Splice(1, 0); // type, brush args
            }

            // use leaf blocks by default
            if (dArgs.BrushName.CaselessEq("Normal") && dArgs.BrushArgs.Length == 0)
            {
                dArgs.BrushArgs = Block.Leaves.ToString();
            }
        }
Ejemplo n.º 5
0
        bool DoTree(Player p, Vec3S32[] marks, object state, byte type, byte extType)
        {
            DrawArgs   dArgs = (DrawArgs)state;
            TreeDrawOp op    = new TreeDrawOp();

            op.Tree   = dArgs.tree;
            op.random = new System.Random();
            Brush brush = null;

            if (dArgs.brushMsg != "")
            {
                if (!p.group.CanExecute("brush"))
                {
                    Player.Message(p, "You cannot use /brush, so therefore cannot use /tree with a brush."); return(false);
                }
                brush = ParseBrush(dArgs.brushMsg, p, type, extType);
                if (brush == null)
                {
                    return(false);
                }
            }
            return(DrawOp.DoDrawOp(op, brush, p, marks));
        }
Ejemplo n.º 6
0
        void PlaceBlock1(Player p, ushort x, ushort y, ushort z, byte type, byte extType)
        {
            RevertAndClearState(p, x, y, z);
            CatchPos cpos = (CatchPos)p.blockchangeObject;

            type = type < 128 ? p.bindings[type] : type;

            TreeDrawOp op = new TreeDrawOp();

            op.Type   = cpos.mode;
            op.random = p.random;
            Brush brush = null;

            if (cpos.brushMsg != "")
            {
                if (!p.group.CanExecute("brush"))
                {
                    Player.SendMessage(p, "You cannot use /brush, so therefore cannot use /tree with a brush."); return;
                }
                brush = ParseBrush(cpos.brushMsg, p, type, extType);
                if (brush == null)
                {
                    return;
                }
            }

            Vec3U16[] marks = { new Vec3U16(x, y, z) };
            if (!DrawOp.DoDrawOp(op, brush, p, marks))
            {
                return;
            }
            if (p.staticCommands)
            {
                p.Blockchange += new Player.BlockchangeEventHandler(PlaceBlock1);
            }
        }
Ejemplo n.º 7
0
        public bool GenerateMap(Level Lvl, string type, int seed = 0, bool useSeed = false)
        {
            DateTime startTime = DateTime.UtcNow;

            Server.s.Log("Attempting map gen");
            rand = useSeed ? new System.Random(seed) : new System.Random();
            if (!MapGenParams.Themes.TryGetValue(type, out genParams))
            {
                genParams = new MapGenParams();
            }
            if (genParams.GenTrees)
            {
                treeDrawer        = new TreeDrawOp();
                treeDrawer.random = rand;
                treeDrawer.method = DrawOp.M_SetTile;
                treeCoords        = new Vec3U16[1];
            }

            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);
                Server.s.Log("Creating overlay");
                GeneratePerlinNoise(overlay, Lvl, rand);

                if (genParams.GenerateOverlay2)
                {
                    Server.s.Log("Planning trees");
                    GeneratePerlinNoise(overlay2, Lvl, rand);
                }

                Server.s.Log("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);
                    }
                }
                Server.s.Log("Total time was " + (DateTime.UtcNow - startTime).TotalSeconds.ToString() + " seconds.");
            } catch (Exception e) {
                Server.ErrorLog(e);
                Server.s.Log("Gen Fail");
                return(false);
            }
            return(true);
        }
Ejemplo n.º 8
0
        void GenNonLavaColumn(ushort x, ushort y, ushort z, Level Lvl, int index)
        {
            if (y > LiquidLevel)
            {
                int pos = x + Lvl.Width * (z + y * Lvl.Length);
                for (ushort yy = 0; y - yy >= 0; yy++)
                {
                    if (genParams.SimpleColumns)
                    {
                        Lvl.blocks[pos] = Block.sand;
                    }
                    else if (overlay[index] < 0.72f)
                    {
                        if (genParams.IslandColumns)   //increase sand height for island
                        {
                            if (y > LiquidLevel + 2)
                            {
                                if (yy == 0)
                                {
                                    Lvl.blocks[pos] = Block.grass;              //top layer
                                }
                                else if (yy < 3)
                                {
                                    Lvl.blocks[pos] = Block.dirt;               //next few
                                }
                                else
                                {
                                    Lvl.blocks[pos] = Block.rock;               //ten rock it
                                }
                            }
                            else
                            {
                                Lvl.blocks[pos] = Block.sand;                   //SAAAND extra for islands
                            }
                        }
                        else
                        {
                            if (yy == 0)
                            {
                                Lvl.blocks[pos] = Block.grass;
                            }
                            else if (yy < 3)
                            {
                                Lvl.blocks[pos] = Block.dirt;
                            }
                            else
                            {
                                Lvl.blocks[pos] = Block.rock;
                            }
                        }
                    }
                    else
                    {
                        Lvl.blocks[pos] = Block.rock;
                    }
                    pos -= Lvl.Width * Lvl.Length;
                }

                if (genParams.GenFlowers && overlay[index] < 0.25f)
                {
                    switch (rand.Next(12))
                    {
                    case 10:
                        Lvl.SetTile(x, (ushort)(y + 1), z, Block.redflower); break;

                    case 11:
                        Lvl.SetTile(x, (ushort)(y + 1), z, Block.yellowflower); break;

                    default:
                        break;
                    }
                }

                if (genParams.GenTrees && overlay[index] < 0.65f && overlay2[index] < treeDens)
                {
                    if (Lvl.GetTile(x, (ushort)(y + 1), z) == Block.air)
                    {
                        if (Lvl.GetTile(x, y, z) == Block.grass || genParams.UseCactus)
                        {
                            if (rand.Next(13) == 0 && !TreeDrawOp.TreeCheck(Lvl, x, y, z, treeDist))
                            {
                                treeDrawer.Type = genParams.UseCactus ? TreeDrawOp.T_Cactus : TreeDrawOp.T_Tree;
                                treeCoords[0].X = x; treeCoords[0].Y = (ushort)(y + 1); treeCoords[0].Z = z;
                                treeDrawer.Perform(treeCoords, null, Lvl, null);
                            }
                        }
                    }
                }
            }
            else     //Must be on/under the water line then
            {
                int pos = x + Lvl.Width * (z + LiquidLevel * Lvl.Length);
                for (ushort yy = 0; LiquidLevel - yy >= 0; yy++)
                {
                    if (LiquidLevel - yy > y)
                    {
                        Lvl.blocks[pos] = Block.water;    //better fill the water above me
                    }
                    else if (LiquidLevel - yy > y - 3)
                    {
                        byte block = overlay[index] < 0.75f ? Block.sand : Block.gravel; // sand on top
                        Lvl.blocks[pos] = block;
                    }
                    else
                    {
                        Lvl.blocks[pos] = Block.rock;
                    }
                    pos -= Lvl.Width * Lvl.Length;
                }
            }
        }