Inheritance: NumberedMapObject
Beispiel #1
0
        /// <summary>Reads the tiles. </summary>
        private void ReadTiles()
        {
            var mapSection = GetSection("IsoMapPack5");

            byte[] lzoData     = Convert.FromBase64String(mapSection.ConcatenatedValues());
            int    cells       = (FullSize.Width * 2 - 1) * FullSize.Height;
            int    lzoPackSize = cells * 11 + 4;          // last 4 bytes contains a lzo pack header saying no more data is left

            var  isoMapPack          = new byte[lzoPackSize];
            uint totalDecompressSize = Format5.DecodeInto(lzoData, isoMapPack);

            var mf       = new MemoryFile(isoMapPack);
            int numtiles = 0;

            for (int i = 0; i < cells; i++)
            {
                ushort rx      = mf.ReadUInt16();
                ushort ry      = mf.ReadUInt16();
                short  tilenum = mf.ReadInt16();
                short  zero1   = mf.ReadInt16();
                ushort subtile = mf.ReadByte();
                short  z       = mf.ReadByte();
                byte   zero2   = mf.ReadByte();

                int dx = rx - ry + FullSize.Width - 1;
                int dy = rx + ry - FullSize.Width - 1;
                numtiles++;
                if (dx >= 0 && dx < 2 * Tiles.Width &&
                    dy >= 0 && dy < 2 * Tiles.Height)
                {
                    var tile = new IsoTile((ushort)dx, (ushort)dy, rx, ry, z, tilenum, subtile);
                    Tiles[(ushort)dx, (ushort)dy / 2] = tile;
                }
            }

            // fix missing tiles

            // import tiles
            for (ushort y = 0; y < FullSize.Height; y++)
            {
                for (ushort x = 0; x <= FullSize.Width * 2 - 2; x++)
                {
                    var isoTile = Tiles[x, y];
                    if (isoTile == null)
                    {
                        // fix null tiles to blank
                        ushort dx = (ushort)(x);
                        ushort dy = (ushort)(y * 2 + x % 2);
                        ushort rx = (ushort)((dx + dy) / 2 + 1);
                        ushort ry = (ushort)(dy - rx + FullSize.Width + 1);
                        Tiles[x, y] = new IsoTile(dx, dy, rx, ry, 0, 0, 0);
                    }
                }
            }


            Logger.Debug("Read {0} tiles", numtiles);
        }
Beispiel #2
0
        /// <summary>Reads the tiles. </summary>
        private void ReadTiles()
        {
            var mapSection = GetSection("IsoMapPack5");
            byte[] lzoData = Convert.FromBase64String(mapSection.ConcatenatedValues());
            int cells = (FullSize.Width * 2 - 1) * FullSize.Height;
            int lzoPackSize = cells * 11 + 4; // last 4 bytes contains a lzo pack header saying no more data is left

            var isoMapPack = new byte[lzoPackSize];
            uint totalDecompressSize = Format5.DecodeInto(lzoData, isoMapPack);

            var mf = new MemoryFile(isoMapPack);
            int numtiles = 0;
            for (int i = 0; i < cells; i++) {
                ushort rx = mf.ReadUInt16();
                ushort ry = mf.ReadUInt16();
                short tilenum = mf.ReadInt16();
                short zero1 = mf.ReadInt16();
                byte subtile = mf.ReadByte();
                byte z = mf.ReadByte();
                byte zero2 = mf.ReadByte();

                int dx = rx - ry + FullSize.Width - 1;
                int dy = rx + ry - FullSize.Width - 1;
                numtiles++;
                if (dx >= 0 && dx < 2 * Tiles.Width &&
                    dy >= 0 && dy < 2 * Tiles.Height) {
                    var tile = new IsoTile((ushort)dx, (ushort)dy, rx, ry, z, tilenum, subtile);
                    Tiles[(ushort)dx, (ushort)dy / 2] = tile;
                }
            }

            // fix missing tiles

            // import tiles
            for (ushort y = 0; y < FullSize.Height; y++) {
                for (ushort x = 0; x <= FullSize.Width * 2 - 2; x++) {
                    var isoTile = Tiles[x, y];
                    if (isoTile == null) {
                        // fix null tiles to blank
                        ushort dx = (ushort)(x);
                        ushort dy = (ushort)(y * 2 + x % 2);
                        ushort rx = (ushort)((dx + dy) / 2 + 1);
                        ushort ry = (ushort)(dy - rx + FullSize.Width + 1);
                        Tiles[x, y] = new IsoTile(dx, dy, rx, ry, 0, 0, 0);
                    }
                }
            }

            Logger.Debug("Read {0} tiles", numtiles);
        }
Beispiel #3
0
        /// <summary>Reads the tiles. </summary>
        private void ReadTiles()
        {
            var mapSection = GetSection("IsoMapPack5");

            byte[] lzoData     = Convert.FromBase64String(mapSection.ConcatenatedValues());
            int    cells       = (FullSize.Width * 2 - 1) * FullSize.Height;
            int    lzoPackSize = cells * 11 + 4;          // last 4 bytes contains a lzo pack header saying no more data is left

            var isoMapPack = new byte[lzoPackSize];

            // In case, IsoMapPack5 contains less entries than the number of cells, fill up any number greater
            // than 511 and filter later.
            int j = 0;

            for (int i = 0; i < cells; i++)
            {
                isoMapPack[j]     = 0x88;
                isoMapPack[j + 1] = 0x40;
                isoMapPack[j + 2] = 0x88;
                isoMapPack[j + 3] = 0x40;
                j += 11;
            }

            Format5.DecodeInto(lzoData, isoMapPack);

            // Fill level 0 clear tiles for all array values
            for (ushort y = 0; y < FullSize.Height; y++)
            {
                for (ushort x = 0; x <= FullSize.Width * 2 - 2; x++)
                {
                    ushort dx = (ushort)(x);
                    ushort dy = (ushort)(y * 2 + x % 2);
                    ushort rx = (ushort)((dx + dy) / 2 + 1);
                    ushort ry = (ushort)(dy - rx + FullSize.Width + 1);
                    Tiles[x, y] = new IsoTile(dx, dy, rx, ry, 0, 0, 0, 0);
                }
            }

            // Overwrite with actual entries found in IsoMapPack5
            var mf       = new MemoryFile(isoMapPack);
            int numtiles = 0;

            for (int i = 0; i < cells; i++)
            {
                ushort rx        = mf.ReadUInt16();
                ushort ry        = mf.ReadUInt16();
                int    tilenum   = mf.ReadInt32();
                byte   subtile   = mf.ReadByte();
                byte   z         = mf.ReadByte();
                byte   icegrowth = mf.ReadByte();

                if (tilenum >= 65535)
                {
                    tilenum = 0;                                   // Tile 0xFFFF used as empty/clear
                }
                if (rx <= 511 && ry <= 511)
                {
                    int dx = rx - ry + FullSize.Width - 1;
                    int dy = rx + ry - FullSize.Width - 1;
                    numtiles++;
                    if (dx >= 0 && dx < 2 * Tiles.Width && dy >= 0 && dy < 2 * Tiles.Height)
                    {
                        var tile = new IsoTile((ushort)dx, (ushort)dy, rx, ry, z, tilenum, subtile, icegrowth);
                        Tiles[(ushort)dx, (ushort)dy / 2] = tile;
                    }
                }
            }

            Logger.Debug("Read {0} tiles", numtiles);
        }