Example #1
0
        static void FixLight(Player p, Level lvl, ref int totalFixed)
        {
            int index = 0, oneY = lvl.Width * lvl.Length;
            BufferedBlockSender buffer = new BufferedBlockSender(lvl);
            BlockID             above, block;

            for (ushort y = 0; y < lvl.Height - 1; y++)
            {
                for (ushort z = 0; z < lvl.Length; z++)
                {
                    for (ushort x = 0; x < lvl.Width; x++)
                    {
                        block = lvl.FastGetBlock(index);
                        bool inShadow = false;

                        if (lvl.Props[block].GrassBlock != Block.Invalid)
                        {
                            for (int i = 1; i < (lvl.Height - y); i++)
                            {
                                above = lvl.FastGetBlock(index + oneY * i);
                                if (!lvl.LightPasses(above))
                                {
                                    inShadow = true; break;
                                }
                            }

                            BlockID grass = lvl.Props[block].GrassBlock;
                            if (!inShadow && p.level.TryChangeBlock(p, x, y, z, grass) == ChangeResult.Modified)
                            {
                                buffer.Add(lvl.PosToInt(x, y, z), grass);
                                totalFixed++;
                            }
                        }
                        else if (lvl.Props[block].DirtBlock != Block.Invalid)
                        {
                            for (int i = 1; i < (lvl.Height - y); i++)
                            {
                                above = lvl.FastGetBlock(index + oneY * i);
                                if (!lvl.LightPasses(above))
                                {
                                    inShadow = true; break;
                                }
                            }

                            BlockID dirt = lvl.Props[block].DirtBlock;
                            if (inShadow && p.level.TryChangeBlock(p, x, y, z, dirt) == ChangeResult.Modified)
                            {
                                buffer.Add(lvl.PosToInt(x, y, z), dirt);
                                totalFixed++;
                            }
                        }
                        index++;
                    }
                }
            }
            buffer.Flush();
        }
Example #2
0
        static void Fix(Player p, Level lvl, ref int totalFixed, bool fixGrass, bool fixDirt)
        {
            int index = 0, maxY = lvl.Height - 1, oneY = lvl.Width * lvl.Length;
            BufferedBlockSender buffer = new BufferedBlockSender(lvl);
            ExtBlock            above = default(ExtBlock), block = default(ExtBlock);

            for (ushort y = 0; y < lvl.Height; y++)
            {
                for (ushort z = 0; z < lvl.Length; z++)
                {
                    for (ushort x = 0; x < lvl.Width; x++)
                    {
                        block.BlockID = lvl.blocks[index];
                        block.ExtID   = 0;
                        if (block.BlockID == Block.custom_block)
                        {
                            block.ExtID = lvl.GetExtTile(x, y, z);
                        }

                        if (fixGrass && lvl.Props[block.Index].GrassIndex != Block.Invalid)
                        {
                            above.BlockID = y == maxY ? Block.Air : lvl.blocks[index + oneY];
                            above.ExtID   = 0;
                            if (above.BlockID == Block.custom_block)
                            {
                                above.ExtID = lvl.GetExtTile(x, (ushort)(y + 1), z);
                            }

                            ExtBlock grass = ExtBlock.FromIndex(lvl.Props[block.Index].GrassIndex);
                            if (lvl.LightPasses(above) && p.level.DoBlockchange(p, x, y, z, grass) == 2)
                            {
                                buffer.Add(index, grass.BlockID, grass.ExtID);
                                totalFixed++;
                            }
                        }
                        else if (fixDirt && lvl.Props[block.Index].DirtIndex != Block.Invalid)
                        {
                            above.BlockID = y == maxY ? Block.Air : lvl.blocks[index + oneY];
                            above.ExtID   = 0;
                            if (above.BlockID == Block.custom_block)
                            {
                                above.ExtID = lvl.GetExtTile(x, (ushort)(y + 1), z);
                            }

                            ExtBlock dirt = ExtBlock.FromIndex(lvl.Props[block.Index].DirtIndex);
                            if (!lvl.LightPasses(above) && p.level.DoBlockchange(p, x, y, z, dirt) == 2)
                            {
                                buffer.Add(index, dirt.BlockID, dirt.ExtID);
                                totalFixed++;
                            }
                        }
                        index++;
                    }
                }
            }
            buffer.Send(true);
        }
Example #3
0
        static void FixDirtAndGrass(Player p, Level lvl, ref int totalFixed)
        {
            int index = 0, maxY = lvl.Height - 1, oneY = lvl.Width * lvl.Length;
            BufferedBlockSender buffer = new BufferedBlockSender(lvl);

            for (int y = 0; y < lvl.Height; y++)
            {
                for (int z = 0; z < lvl.Length; z++)
                {
                    for (int x = 0; x < lvl.Width; x++)
                    {
                        byte block = lvl.blocks[index];
                        if (block == Block.dirt)
                        {
                            byte above = y == maxY ? Block.air : lvl.blocks[index + oneY], extAbove = 0;
                            if (above == Block.custom_block)
                            {
                                extAbove = lvl.GetExtTile((ushort)x, (ushort)(y + 1), (ushort)z);
                            }

                            if (Block.LightPass(above, extAbove, lvl.CustomBlockDefs))
                            {
                                if (p.level.DoBlockchange(p, (ushort)x, (ushort)y, (ushort)z, Block.grass))
                                {
                                    buffer.Add(index, Block.grass, 0);
                                    totalFixed++;
                                }
                            }
                        }
                        else if (block == Block.grass)
                        {
                            byte above = y == maxY ? Block.air : lvl.blocks[index + oneY], extAbove = 0;
                            if (above == Block.custom_block)
                            {
                                extAbove = lvl.GetExtTile((ushort)x, (ushort)(y + 1), (ushort)z);
                            }

                            if (!Block.LightPass(above, extAbove, lvl.CustomBlockDefs))
                            {
                                if (p.level.DoBlockchange(p, (ushort)x, (ushort)y, (ushort)z, Block.dirt))
                                {
                                    buffer.Add(index, Block.dirt, 0);
                                    totalFixed++;
                                }
                            }
                        }
                        index++;
                    }
                }
            }
            buffer.Send(true);
        }
Example #4
0
        static void HighlightPlayer(Player p, TimeSpan delta, string who, int[] ids, Vec3S32[] marks)
        {
            HighlightDrawOp op = new HighlightDrawOp();

            op.Start = DateTime.UtcNow.Subtract(delta);
            op.who   = who; op.ids = ids;
            op.Setup(p, p.level, marks);

            BufferedBlockSender buffer = new BufferedBlockSender(p);

            op.Perform(marks, null,
                       P => {
                int index = p.level.PosToInt(P.X, P.Y, P.Z);
                buffer.Add(index, P.Block);
            });
            buffer.Flush();

            if (op.found)
            {
                p.Message("Now highlighting past &b{0} &Sfor {1}",
                          delta.Shorten(true), p.FormatNick(who));
                p.Message("&WUse /reload to un-highlight");
            }
            else
            {
                p.Message("No changes found by {1} &Sin the past &b{0}",
                          delta.Shorten(true), p.FormatNick(who));
            }
        }
Example #5
0
        static void HighlightPlayer(Player p, TimeSpan delta, string who, int[] ids, Vec3S32[] marks)
        {
            HighlightDrawOp op = new HighlightDrawOp();

            op.Start = DateTime.UtcNow.Subtract(delta);
            op.who   = who; op.ids = ids;
            DrawOpPerformer.Setup(op, p, marks);

            BufferedBlockSender buffer = new BufferedBlockSender(p);

            op.Perform(marks, null,
                       P => {
                int index = p.level.PosToInt(P.X, P.Y, P.Z);
                buffer.Add(index, P.Block.BlockID, P.Block.ExtID);
            });
            buffer.Send(true);

            if (op.found)
            {
                Player.Message(p, "Now highlighting past &b{0} %Sfor {1}",
                               delta.Shorten(true), PlayerInfo.GetColoredName(p, who));
                Player.Message(p, "&cUse /reload to un-highlight");
            }
            else
            {
                Player.Message(p, "No changes found by {1} %Sin the past &b{0}",
                               delta.Shorten(true), PlayerInfo.GetColoredName(p, who));
            }
        }
Example #6
0
        static void ConsoleOutputBlock(DrawOpBlock b, Level lvl, BufferedBlockSender buffer)
        {
            int index = lvl.PosToInt(b.X, b.Y, b.Z);

            if (!lvl.DoPhysicsBlockchange(index, b.Block, false,
                                          default(PhysicsArgs), b.ExtBlock))
            {
                return;
            }
            buffer.Add(index, b.Block, b.ExtBlock);
        }
Example #7
0
        void TryChangeBlock(int x, int y, int z, BlockID block)
        {
            int index = Map.PosToInt((ushort)x, (ushort)y, (ushort)z);

            if (!Map.DoPhysicsBlockchange(index, block))
            {
                return;
            }

            bulk.Add(index, block);
        }
Example #8
0
        static void Fix(Player p, Level lvl, ref int totalFixed, bool fixGrass, bool fixDirt)
        {
            int index = 0, maxY = lvl.Height - 1, oneY = lvl.Width * lvl.Length;
            BufferedBlockSender buffer = new BufferedBlockSender(lvl);
            BlockID             above, block;

            for (ushort y = 0; y < lvl.Height; y++)
            {
                for (ushort z = 0; z < lvl.Length; z++)
                {
                    for (ushort x = 0; x < lvl.Width; x++)
                    {
                        block = lvl.FastGetBlock(index);
                        if (fixGrass && lvl.Props[block].GrassBlock != Block.Invalid)
                        {
                            above = y == maxY ? Block.Air : lvl.FastGetBlock(index + oneY);
                            BlockID grass = lvl.Props[block].GrassBlock;

                            if (lvl.LightPasses(above) && p.level.TryChangeBlock(p, x, y, z, grass) == ChangeResult.Modified)
                            {
                                buffer.Add(index, grass);
                                totalFixed++;
                            }
                        }
                        else if (fixDirt && lvl.Props[block].DirtBlock != Block.Invalid)
                        {
                            above = y == maxY ? Block.Air : lvl.FastGetBlock(index + oneY);
                            BlockID dirt = lvl.Props[block].DirtBlock;

                            if (!lvl.LightPasses(above) && p.level.TryChangeBlock(p, x, y, z, dirt) == ChangeResult.Modified)
                            {
                                buffer.Add(index, dirt);
                                totalFixed++;
                            }
                        }
                        index++;
                    }
                }
            }
            buffer.Flush();
        }
Example #9
0
        public override void Perform(Vec3U16[] marks, Player p, Level lvl, Brush brush)
        {
            UndoCache     cache = p.UndoBuffer;
            UndoCacheNode node  = cache.Tail;

            if (node == null)
            {
                return;
            }
            int timeDelta = (int)DateTime.UtcNow.Subtract(Server.StartTime).TotalSeconds;

            while (node != null)
            {
                lvl = LevelInfo.FindExact(node.MapName);
                if (lvl == null || (p.level != null && !p.level.name.CaselessEq(lvl.name)))
                {
                    node = node.Prev; continue;
                }
                List <UndoCacheItem> items  = node.Items;
                BufferedBlockSender  buffer = new BufferedBlockSender(lvl);

                for (int i = items.Count - 1; i >= 0; i--)
                {
                    UndoCacheItem item = items[i];
                    ushort        x, y, z;
                    node.Unpack(item.Index, out x, out y, out z);

                    DateTime time = node.BaseTime.AddTicks(item.TimeDelta * TimeSpan.TicksPerSecond);
                    if (time > End)
                    {
                        continue;
                    }
                    if (time < Start)
                    {
                        buffer.CheckIfSend(true); return;
                    }

                    byte tile, extTile;
                    item.GetBlock(out tile, out extTile);
                    if (lvl.DoBlockchange(p, x, y, z, tile, extTile))
                    {
                        buffer.Add(lvl.PosToInt(x, y, z), tile, extTile);
                        buffer.CheckIfSend(false);
                    }
                }
                buffer.CheckIfSend(true);
                node = node.Prev;
            }
        }
Example #10
0
        public static void DoHighlight(Stream s, UndoFormat format, UndoFormatArgs args)
        {
            BufferedBlockSender buffer = new BufferedBlockSender(args.Player);
            Level lvl = args.Player.level;

            foreach (UndoFormatEntry P in format.GetEntries(s, args))
            {
                byte block = P.Block, newBlock = P.NewBlock;
                byte highlight = (newBlock == Block.air ||
                                  Block.Convert(block) == Block.water || block == Block.waterstill ||
                                  Block.Convert(block) == Block.lava || block == Block.lavastill)
                    ? Block.red : Block.green;

                buffer.Add(lvl.PosToInt(P.X, P.Y, P.Z), highlight, 0);
            }
            buffer.Send(true);
        }
Example #11
0
        protected internal static void UndoBlock(Player p, Level lvl, Player.UndoPos Pos,
                                                 int timeDelta, BufferedBlockSender buffer)
        {
            byte lvlTile = lvl.GetTile(Pos.x, Pos.y, Pos.z);

            if (lvlTile == Pos.newtype || Block.Convert(lvlTile) == Block.water ||
                Block.Convert(lvlTile) == Block.lava || lvlTile == Block.grass)
            {
                byte newExtType = Pos.newExtType;
                Pos.newtype   = Pos.type; Pos.newExtType = Pos.extType;
                Pos.extType   = newExtType; Pos.type = lvlTile;
                Pos.timeDelta = timeDelta;
                if (lvl.DoBlockchange(p, Pos.x, Pos.y, Pos.z, Pos.newtype, Pos.newExtType))
                {
                    buffer.Add(lvl.PosToInt(Pos.x, Pos.y, Pos.z), Pos.newtype, Pos.newExtType);
                    buffer.CheckIfSend(false);
                }
            }
        }
Example #12
0
        static void FixLight(Player p, Level lvl, ref int totalFixed)
        {
            int index = 0;
            BufferedBlockSender buffer = new BufferedBlockSender(lvl);

            for (int y = 0; y < lvl.Height - 1; y++)
            {
                for (int z = 0; z < lvl.Length; z++)
                {
                    for (int x = 0; x < lvl.Width; x++)
                    {
                        byte block    = lvl.blocks[index];
                        bool inShadow = false;
                        if (block == Block.dirt)
                        {
                            for (int i = 1; i < (lvl.Height - y); i++)
                            {
                                byte above = lvl.blocks[index + (lvl.Width * lvl.Length) * i], extAbove = 0;
                                if (above == Block.custom_block)
                                {
                                    extAbove = lvl.GetExtTile((ushort)x, (ushort)(y + i), (ushort)z);
                                }

                                if (!Block.LightPass(above, extAbove, lvl.CustomBlockDefs))
                                {
                                    inShadow = true; break;
                                }
                            }

                            if (!inShadow && p.level.DoBlockchange(p, (ushort)x, (ushort)y, (ushort)z, Block.grass))
                            {
                                buffer.Add(index, Block.grass, 0);
                                totalFixed++;
                            }
                        }
                        else if (block == Block.grass)
                        {
                            for (int i = 1; i < (lvl.Height - y); i++)
                            {
                                byte above = lvl.blocks[index + (lvl.Width * lvl.Length) * i], extAbove = 0;
                                if (above == Block.custom_block)
                                {
                                    extAbove = lvl.GetExtTile((ushort)x, (ushort)(y + i), (ushort)z);
                                }

                                if (!Block.LightPass(above, extAbove, lvl.CustomBlockDefs))
                                {
                                    inShadow = true; break;
                                }
                            }

                            if (inShadow && p.level.DoBlockchange(p, (ushort)x, (ushort)y, (ushort)z, Block.dirt))
                            {
                                buffer.Add(index, Block.dirt, 0);
                                totalFixed++;
                            }
                        }
                        index++;
                    }
                }
            }
            buffer.Send(true);
        }
Example #13
0
        static void FixLight(Player p, Level lvl, ref int totalFixed)
        {
            int index = 0;
            BufferedBlockSender buffer = new BufferedBlockSender(lvl);
            ExtBlock            above = default(ExtBlock), block = default(ExtBlock);

            for (ushort y = 0; y < lvl.Height - 1; y++)
            {
                for (ushort z = 0; z < lvl.Length; z++)
                {
                    for (ushort x = 0; x < lvl.Width; x++)
                    {
                        block.BlockID = lvl.blocks[index];
                        block.ExtID   = 0;
                        bool inShadow = false;
                        if (block.BlockID == Block.custom_block)
                        {
                            block.ExtID = lvl.GetExtTile(x, y, z);
                        }

                        if (lvl.Props[block.Index].GrassIndex != Block.Invalid)
                        {
                            for (int i = 1; i < (lvl.Height - y); i++)
                            {
                                above.BlockID = lvl.blocks[index + (lvl.Width * lvl.Length) * i];
                                above.ExtID   = 0;
                                if (above.BlockID == Block.custom_block)
                                {
                                    above.ExtID = lvl.GetExtTile(x, (ushort)(y + i), z);
                                }

                                if (!lvl.LightPasses(above))
                                {
                                    inShadow = true; break;
                                }
                            }

                            ExtBlock grass = ExtBlock.FromIndex(lvl.Props[block.Index].GrassIndex);
                            if (!inShadow && p.level.DoBlockchange(p, x, (ushort)y, z, grass) == 2)
                            {
                                buffer.Add(index, grass.BlockID, grass.ExtID);
                                totalFixed++;
                            }
                        }
                        else if (lvl.Props[block.Index].DirtIndex != Block.Invalid)
                        {
                            for (int i = 1; i < (lvl.Height - y); i++)
                            {
                                above.BlockID = lvl.blocks[index + (lvl.Width * lvl.Length) * i];
                                above.ExtID   = 0;
                                if (above.BlockID == Block.custom_block)
                                {
                                    above.ExtID = lvl.GetExtTile(x, (ushort)(y + i), z);
                                }

                                if (!lvl.LightPasses(above))
                                {
                                    inShadow = true; break;
                                }
                            }

                            ExtBlock dirt = ExtBlock.FromIndex(lvl.Props[block.Index].DirtIndex);
                            if (inShadow && p.level.DoBlockchange(p, x, (ushort)y, z, dirt) == 2)
                            {
                                buffer.Add(index, dirt.BlockID, dirt.ExtID);
                                totalFixed++;
                            }
                        }
                        index++;
                    }
                }
            }
            buffer.Send(true);
        }