Exemplo n.º 1
0
 public virtual void SetMarks(Vec3S32[] marks)
 {
     Origin = marks[0]; Min = marks[0]; Max = marks[0];
     for (int i = 1; i < marks.Length; i++)
     {
         Min = Vec3S32.Min(Min, marks[i]);
         Max = Vec3S32.Max(Max, marks[i]);
     }
 }
Exemplo n.º 2
0
        bool SetSafeZone(Player p, Vec3S32[] m, object state, BlockID block)
        {
            LSMapConfig cfg = (LSMapConfig)state;

            cfg.SafeZoneMin = (Vec3U16)Vec3S32.Min(m[0], m[1]);
            cfg.SafeZoneMax = (Vec3U16)Vec3S32.Max(m[0], m[1]);
            SaveMapConfig(p, cfg);

            p.Message("Safe zone set! &b({0}) ({1})", cfg.SafeZoneMin, cfg.SafeZoneMax);
            return(false);
        }
Exemplo n.º 3
0
        bool SetSafeZone(Player p, Vec3S32[] m, object state, ExtBlock block)
        {
            Vec3S32 min = Vec3S32.Min(m[0], m[1]);
            Vec3S32 max = Vec3S32.Max(m[0], m[1]);

            LavaSurvival.MapSettings settings = Server.lava.LoadMapSettings(p.level.name);
            settings.safeZone = new Vec3U16[] { (Vec3U16)min, (Vec3U16)max };
            Server.lava.SaveMapSettings(settings);

            Player.Message(p, "Safe zone set! &b({0}, {1}, {2}) ({3}, {4}, {5})",
                           min.X, min.Y, min.Z, max.X, max.Y, max.Z);
            return(false);
        }
Exemplo n.º 4
0
        bool DoMeasure(Player p, Vec3S32[] m, object state, ExtBlock block)
        {
            ExtBlock[] toCount = (ExtBlock[])state;
            Vec3S32    min = Vec3S32.Min(m[0], m[1]), max = Vec3S32.Max(m[0], m[1]);

            int[] counts = new int[512];

            for (ushort y = (ushort)min.Y; y <= (ushort)max.Y; y++)
            {
                for (ushort z = (ushort)min.Z; z <= (ushort)max.Z; z++)
                {
                    for (ushort x = (ushort)min.X; x <= (ushort)max.X; x++)
                    {
                        counts[p.level.GetBlock(x, y, z).Index]++;
                    }
                }
            }

            int width = max.X - min.X + 1, height = max.Y - min.Y + 1, length = max.Z - min.Z + 1;
            int volume = width * height * length;

            Player.Message(p, "Measuring from &a({0}, {1}, {2}) %Sto &a({3}, {4}, {5})",
                           min.X, min.Y, min.Z, max.X, max.Y, max.Z);
            Player.Message(p, "  &b{0} %Swide, &b{1} %Shigh, &b{2} %Slong, {3} blocks",
                           width, height, length, volume);

            string title = "Block types: ";

            if (toCount == null)
            {
                toCount = MostFrequentBlocks(counts);
                title   = "Top " + toCount.Length + " block types: ";
            }

            string blocks = toCount.Join(bl => p.level.BlockName(bl) + FormatCount(counts[bl.Index], volume));

            Player.Message(p, title + blocks);
            return(true);
        }
Exemplo n.º 5
0
        bool DoMeasure(Player p, Vec3S32[] m, object state, BlockID block)
        {
            BlockID[] toCount = (BlockID[])state;
            Vec3S32   min = Vec3S32.Min(m[0], m[1]), max = Vec3S32.Max(m[0], m[1]);

            int[] counts = new int[Block.ExtendedCount];

            for (ushort y = (ushort)min.Y; y <= (ushort)max.Y; y++)
            {
                for (ushort z = (ushort)min.Z; z <= (ushort)max.Z; z++)
                {
                    for (ushort x = (ushort)min.X; x <= (ushort)max.X; x++)
                    {
                        counts[p.level.GetBlock(x, y, z)]++;
                    }
                }
            }

            int width = max.X - min.X + 1, height = max.Y - min.Y + 1, length = max.Z - min.Z + 1;
            int volume = width * height * length;

            p.Message("Measuring from &a({0}) &Sto &a({1})", min, max);
            p.Message("  &b{0} &Swide, &b{1} &Shigh, &b{2} &Slong, {3} blocks",
                      width, height, length, volume);

            string title = "Block types: ";

            if (toCount == null)
            {
                toCount = MostFrequentBlocks(counts);
                title   = "Top " + toCount.Length + " block types: ";
            }

            string blocks = toCount.Join(bl => Block.GetName(p, bl) + FormatCount(counts[bl], volume));

            p.Message(title + blocks);
            return(true);
        }
Exemplo n.º 6
0
        void DoCopyMark(Player p, Vec3S32[] m, int i, object state, BlockID block)
        {
            CopyArgs cArgs = (CopyArgs)state;

            if (i == 2)
            {
                CopyState copy = p.CurrentCopy;
                copy.Offset.X = copy.OriginX - m[i].X;
                copy.Offset.Y = copy.OriginY - m[i].Y;
                copy.Offset.Z = copy.OriginZ - m[i].Z;

                p.Message("Set offset of where to paste from.");
                CompleteCopy(p, m, cArgs);
                return;
            }
            if (i != 1)
            {
                return;
            }

            Vec3S32 min = Vec3S32.Min(m[0], m[1]), max = Vec3S32.Max(m[0], m[1]);
            ushort  minX = (ushort)min.X, minY = (ushort)min.Y, minZ = (ushort)min.Z;
            ushort  maxX = (ushort)max.X, maxY = (ushort)max.Y, maxZ = (ushort)max.Z;

            CopyState cState = new CopyState(minX, minY, minZ, maxX - minX + 1,
                                             maxY - minY + 1, maxZ - minZ + 1);

            cState.OriginX = m[0].X; cState.OriginY = m[0].Y; cState.OriginZ = m[0].Z;

            int index = 0; cState.UsedBlocks = 0;

            cState.PasteAir = cArgs.air;

            for (ushort y = minY; y <= maxY; ++y)
            {
                for (ushort z = minZ; z <= maxZ; ++z)
                {
                    for (ushort x = minX; x <= maxX; ++x)
                    {
                        block = p.level.GetBlock(x, y, z);
                        if (!p.group.Blocks[block])
                        {
                            index++; continue;
                        }

                        if (block != Block.Air || cState.PasteAir)
                        {
                            cState.UsedBlocks++;
                        }
                        cState.Set(block, index);
                        index++;
                    }
                }
            }

            if (cState.UsedBlocks > p.group.DrawLimit)
            {
                p.Message("You tried to copy {0} blocks. You cannot copy more than {1} blocks.",
                          cState.UsedBlocks, p.group.DrawLimit);
                cState.Clear(); cState = null;
                p.ClearSelection();
                return;
            }

            cState.CopySource = "level " + p.level.name;
            p.CurrentCopy     = cState;

            p.Message("Copied &a{0} &Sblocks, origin at ({1}, {2}, {3}) corner", cState.UsedBlocks,
                      cState.OriginX == cState.X ? "Min" : "Max",
                      cState.OriginY == cState.Y ? "Min" : "Max",
                      cState.OriginZ == cState.Z ? "Min" : "Max");
            if (!cState.PasteAir)
            {
                p.Message("To also copy air blocks, use &T/Copy Air");
            }

            if (cArgs.offsetIndex != -1)
            {
                p.Message("Place a block to determine where to paste from");
            }
            else
            {
                CompleteCopy(p, m, cArgs);
            }
        }
Exemplo n.º 7
0
        // actual decoding stuff
        public override Level Read(Stream src, string name, bool metadata)
        {
            BinaryReader reader = new BinaryReader(src);

            if (ReadFourCC(reader) != "VOX ")
            {
                throw new NotSupportedException("Invalid header");
            }
            if (reader.ReadInt32() != 150)
            {
                throw new NotSupportedException("Unsupported version number");
            }

            Chunk main = ReadChunk(reader);

            if (main.FourCC != "MAIN")
            {
                throw new NotSupportedException("MAIN chunk expected");
            }

            uint[] palette = new uint[256] {
                0x00000000, 0xffffffff, 0xffccffff, 0xff99ffff, 0xff66ffff, 0xff33ffff, 0xff00ffff, 0xffffccff, 0xffccccff, 0xff99ccff, 0xff66ccff, 0xff33ccff, 0xff00ccff, 0xffff99ff, 0xffcc99ff, 0xff9999ff,
                0xff6699ff, 0xff3399ff, 0xff0099ff, 0xffff66ff, 0xffcc66ff, 0xff9966ff, 0xff6666ff, 0xff3366ff, 0xff0066ff, 0xffff33ff, 0xffcc33ff, 0xff9933ff, 0xff6633ff, 0xff3333ff, 0xff0033ff, 0xffff00ff,
                0xffcc00ff, 0xff9900ff, 0xff6600ff, 0xff3300ff, 0xff0000ff, 0xffffffcc, 0xffccffcc, 0xff99ffcc, 0xff66ffcc, 0xff33ffcc, 0xff00ffcc, 0xffffcccc, 0xffcccccc, 0xff99cccc, 0xff66cccc, 0xff33cccc,
                0xff00cccc, 0xffff99cc, 0xffcc99cc, 0xff9999cc, 0xff6699cc, 0xff3399cc, 0xff0099cc, 0xffff66cc, 0xffcc66cc, 0xff9966cc, 0xff6666cc, 0xff3366cc, 0xff0066cc, 0xffff33cc, 0xffcc33cc, 0xff9933cc,
                0xff6633cc, 0xff3333cc, 0xff0033cc, 0xffff00cc, 0xffcc00cc, 0xff9900cc, 0xff6600cc, 0xff3300cc, 0xff0000cc, 0xffffff99, 0xffccff99, 0xff99ff99, 0xff66ff99, 0xff33ff99, 0xff00ff99, 0xffffcc99,
                0xffcccc99, 0xff99cc99, 0xff66cc99, 0xff33cc99, 0xff00cc99, 0xffff9999, 0xffcc9999, 0xff999999, 0xff669999, 0xff339999, 0xff009999, 0xffff6699, 0xffcc6699, 0xff996699, 0xff666699, 0xff336699,
                0xff006699, 0xffff3399, 0xffcc3399, 0xff993399, 0xff663399, 0xff333399, 0xff003399, 0xffff0099, 0xffcc0099, 0xff990099, 0xff660099, 0xff330099, 0xff000099, 0xffffff66, 0xffccff66, 0xff99ff66,
                0xff66ff66, 0xff33ff66, 0xff00ff66, 0xffffcc66, 0xffcccc66, 0xff99cc66, 0xff66cc66, 0xff33cc66, 0xff00cc66, 0xffff9966, 0xffcc9966, 0xff999966, 0xff669966, 0xff339966, 0xff009966, 0xffff6666,
                0xffcc6666, 0xff996666, 0xff666666, 0xff336666, 0xff006666, 0xffff3366, 0xffcc3366, 0xff993366, 0xff663366, 0xff333366, 0xff003366, 0xffff0066, 0xffcc0066, 0xff990066, 0xff660066, 0xff330066,
                0xff000066, 0xffffff33, 0xffccff33, 0xff99ff33, 0xff66ff33, 0xff33ff33, 0xff00ff33, 0xffffcc33, 0xffcccc33, 0xff99cc33, 0xff66cc33, 0xff33cc33, 0xff00cc33, 0xffff9933, 0xffcc9933, 0xff999933,
                0xff669933, 0xff339933, 0xff009933, 0xffff6633, 0xffcc6633, 0xff996633, 0xff666633, 0xff336633, 0xff006633, 0xffff3333, 0xffcc3333, 0xff993333, 0xff663333, 0xff333333, 0xff003333, 0xffff0033,
                0xffcc0033, 0xff990033, 0xff660033, 0xff330033, 0xff000033, 0xffffff00, 0xffccff00, 0xff99ff00, 0xff66ff00, 0xff33ff00, 0xff00ff00, 0xffffcc00, 0xffcccc00, 0xff99cc00, 0xff66cc00, 0xff33cc00,
                0xff00cc00, 0xffff9900, 0xffcc9900, 0xff999900, 0xff669900, 0xff339900, 0xff009900, 0xffff6600, 0xffcc6600, 0xff996600, 0xff666600, 0xff336600, 0xff006600, 0xffff3300, 0xffcc3300, 0xff993300,
                0xff663300, 0xff333300, 0xff003300, 0xffff0000, 0xffcc0000, 0xff990000, 0xff660000, 0xff330000, 0xff0000ee, 0xff0000dd, 0xff0000bb, 0xff0000aa, 0xff000088, 0xff000077, 0xff000055, 0xff000044,
                0xff000022, 0xff000011, 0xff00ee00, 0xff00dd00, 0xff00bb00, 0xff00aa00, 0xff008800, 0xff007700, 0xff005500, 0xff004400, 0xff002200, 0xff001100, 0xffee0000, 0xffdd0000, 0xffbb0000, 0xffaa0000,
                0xff880000, 0xff770000, 0xff550000, 0xff440000, 0xff220000, 0xff110000, 0xffeeeeee, 0xffdddddd, 0xffbbbbbb, 0xffaaaaaa, 0xff888888, 0xff777777, 0xff555555, 0xff444444, 0xff222222, 0xff111111,
            };

            src.Seek(main.ChunkContentSize, SeekOrigin.Current);
            long                   end    = src.Position + main.ChildChunkContentSize;
            Level                  lvl    = null;
            List <Model>           models = new List <Model>();
            Dictionary <int, Node> nodes  = new Dictionary <int, Node>();

            while (src.Position < end)
            {
                Chunk chunk = ReadChunk(reader);

                if (chunk.FourCC == "RGBA")
                {
                    if (chunk.ChunkContentSize != 4 * 256)
                    {
                        throw new NotSupportedException("RGBA chunk must be 1024 bytes");
                    }
                    for (int i = 0; i <= 254; i++)
                    {
                        palette[i + 1] = reader.ReadUInt32();
                    }
                    reader.ReadUInt32();
                }
                else if (chunk.FourCC == "SIZE")
                {
                    if (chunk.ChunkContentSize != 12)
                    {
                        throw new NotSupportedException("Size chunk must be 12 bytes");
                    }
                    Model part = new Model();

                    part.SizeX = reader.ReadInt32();
                    part.SizeY = reader.ReadInt32();
                    part.SizeZ = reader.ReadInt32();
                    models.Add(part);
                }
                else if (chunk.FourCC == "XYZI")
                {
                    int   numVoxels = reader.ReadInt32();
                    Model part      = models[models.Count - 1];
                    part.Voxels = new Voxel[numVoxels];

                    for (int i = 0; i < numVoxels; i++)
                    {
                        part.Voxels[i].X = reader.ReadByte();
                        part.Voxels[i].Y = reader.ReadByte();
                        part.Voxels[i].Z = reader.ReadByte();
                        part.Voxels[i].B = reader.ReadByte();                         // index into palette
                    }
                }
                else if (chunk.FourCC == "nTRN")
                {
                    TransformNode node = new TransformNode();
                    node.Type = NodeType.Transform;
                    ReadNode(reader, node);
                    node.Children = new int[1];

                    node.Children[0] = reader.ReadInt32();
                    int reservedID = reader.ReadInt32();
                    int layerID    = reader.ReadInt32();
                    int numFrames  = reader.ReadInt32();

                    if (numFrames != 1)
                    {
                        throw new NotSupportedException("Transform node must only have one frame");
                    }
                    node.FrameAttribs = ReadDict(reader);
                    nodes[node.Id]    = node;
                }
                else if (chunk.FourCC == "nGRP")
                {
                    GroupNode node = new GroupNode();
                    node.Type = NodeType.Group;
                    ReadNode(reader, node);
                    node.Children = new int[reader.ReadInt32()];

                    for (int i = 0; i < node.Children.Length; i++)
                    {
                        node.Children[i] = reader.ReadInt32();
                    }
                    nodes[node.Id] = node;
                }
                else if (chunk.FourCC == "nSHP")
                {
                    ShapeNode node = new ShapeNode();
                    node.Type = NodeType.Shape;
                    ReadNode(reader, node);
                    node.Children = new int[0];

                    int numModels = reader.ReadInt32();
                    if (numModels != 1)
                    {
                        throw new NotSupportedException("Shape node must only have one model");
                    }

                    int modelID = reader.ReadInt32();
                    node.Model        = models[modelID];
                    node.ModelAttribs = ReadDict(reader);
                    nodes[node.Id]    = node;
                }
                else
                {
                    src.Seek(chunk.ChunkContentSize, SeekOrigin.Current);
                }
                src.Seek(chunk.ChildChunkContentSize, SeekOrigin.Current);
            }

            // assume root node is 0
            if (nodes.Count > 0)
            {
                Transform(0, Vec3S32.Zero, null, nodes);
            }

            Vec3S32 min = Vec3S32.Zero, max = Vec3S32.Zero;

            foreach (Model m in models)
            {
                min = Vec3S32.Min(min, m.Transform(0, 0, 0));
                max = Vec3S32.Max(max, m.Transform(m.SizeX - 1, m.SizeY - 1, m.SizeZ - 1));
            }

            // magicavox uses Z for vertical
            int width = (max.X - min.X) + 1, height = (max.Z - min.Z) + 1, length = (max.Y - min.Y) + 1;

            lvl = new Level(name, (ushort)width, (ushort)height, (ushort)length);

            ComposeParts(lvl, models, min.X, min.Y, min.Z);
            ComposePalette(lvl, palette);
            return(lvl);
        }
Exemplo n.º 8
0
        void DoCopyMark(Player p, Vec3S32[] m, int i, object state, ExtBlock block)
        {
            if (i == 2)
            {
                CopyState copy = p.CopySlots[p.CurrentCopySlot];
                copy.Offset.X = copy.OriginX - m[i].X;
                copy.Offset.Y = copy.OriginY - m[i].Y;
                copy.Offset.Z = copy.OriginZ - m[i].Z;
                Player.Message(p, "Set offset of where to paste from.");
                return;
            }
            if (i != 1)
            {
                return;
            }

            CopyArgs cArgs = (CopyArgs)state;
            Vec3S32  min = Vec3S32.Min(m[0], m[1]), max = Vec3S32.Max(m[0], m[1]);
            ushort   minX = (ushort)min.X, minY = (ushort)min.Y, minZ = (ushort)min.Z;
            ushort   maxX = (ushort)max.X, maxY = (ushort)max.Y, maxZ = (ushort)max.Z;

            CopyState cState = new CopyState(minX, minY, minZ, maxX - minX + 1,
                                             maxY - minY + 1, maxZ - minZ + 1);

            cState.OriginX = m[0].X; cState.OriginY = m[0].Y; cState.OriginZ = m[0].Z;

            int index = 0; cState.UsedBlocks = 0;

            cState.PasteAir = cArgs.air;

            for (ushort y = minY; y <= maxY; ++y)
            {
                for (ushort z = minZ; z <= maxZ; ++z)
                {
                    for (ushort x = minX; x <= maxX; ++x)
                    {
                        block = p.level.GetBlock(x, y, z);
                        if (!p.group.Blocks[block.BlockID])
                        {
                            index++; continue;
                        }                                                  // TODO: will need to fix this when extblock permissions

                        if (block.BlockID != Block.Air || cState.PasteAir)
                        {
                            cState.UsedBlocks++;
                        }
                        cState.Set(block, index);
                        index++;
                    }
                }
            }

            if (cState.UsedBlocks > p.group.DrawLimit)
            {
                Player.Message(p, "You tried to copy {0} blocks. You cannot copy more than {1} blocks.",
                               cState.UsedBlocks, p.group.DrawLimit);
                cState.Clear(); cState = null;
                p.ClearSelection();
                return;
            }

            cState.CopySource = "level " + p.level.name;
            p.SetCurrentCopy(cState);
            if (cArgs.cut)
            {
                DrawOp op = new CuboidDrawOp();
                op.Flags = BlockDBFlags.Cut;
                Brush brush = new SolidBrush(ExtBlock.Air);
                DrawOpPerformer.Do(op, brush, p, new Vec3S32[] { min, max }, false);
            }

            Player.Message(p, "Copied &a{0} %Sblocks, origin at ({1}, {2}, {3}) corner", cState.UsedBlocks,
                           cState.OriginX == cState.X ? "Min" : "Max",
                           cState.OriginY == cState.Y ? "Min" : "Max",
                           cState.OriginZ == cState.Z ? "Min" : "Max");
            if (!cState.PasteAir)
            {
                Player.Message(p, "To also copy air blocks, use %T/Copy Air");
            }
            if (cArgs.offsetIndex != -1)
            {
                Player.Message(p, "Place a block to determine where to paste from");
            }
        }