Пример #1
0
        public void SerializeIsoMapPack5(IniFile.IniSection isoMapPack5)
        {
            int cells       = (Width * 2 - 1) * 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];
            var  isoMapPack2 = new byte[lzoPackSize];
            long di          = 0;

            foreach (var tile in this.isoTiles)
            {
                var bs = tile.ToMapPack5Entry().ToArray();
                Array.Copy(bs, 0, isoMapPack, di, 11);
                di += 11;
            }

            var    compressed   = Format5.Encode(isoMapPack, 5);
            string compressed64 = Convert.ToBase64String(compressed);

            int i   = 1;
            int idx = 0;

            isoMapPack5.Clear();
            while (idx < compressed64.Length)
            {
                int adv = Math.Min(74, compressed64.Length - idx);
                isoMapPack5.SetValue(i++.ToString(), compressed64.Substring(idx, adv));
                idx += adv;
            }
        }
Пример #2
0
        public void SerializeIsoMapPack5(IniFile.IniSection isoMapPack5, bool compress = false)
        {
            List <IsoTile> tileSet = new List <IsoTile>();

            byte[] encoded;

            foreach (var isoTile in this.isoTiles)
            {
                tileSet.Add(isoTile);
            }

            // Compressing involves removing level 0 clear tiles and then sort the tiles before encoding
            if (compress)
            {
                List <IsoTile> tileSetStage = new List <IsoTile>();
                List <byte[]>  sortedTiles  = new List <byte[]>();

                foreach (var t in tileSet)
                {
                    if (t.TileNum > 0 || t.Z > 0 || t.SubTile > 0 || t.IceGrowth > 0)
                    {
                        tileSetStage.Add(t);
                    }
                }
                if (tileSetStage.Count == 0)
                {
                    tileSetStage.Add(tileSet.First());
                    encoded = GetEncoded(tileSetStage);
                }
                else
                {
                    sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.Rx).ThenBy(x => x.SubTile).ThenBy(x => x.TileNum).ThenBy(x => x.Z).ToList()));
                    sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.Rx).ThenBy(x => x.TileNum).ThenBy(x => x.SubTile).ThenBy(x => x.Z).ToList()));
                    sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.SubTile).ThenBy(x => x.TileNum).ThenBy(x => x.Rx).ThenBy(x => x.Z).ToList()));
                    sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.SubTile).ThenBy(x => x.TileNum).ThenBy(x => x.Z).ThenBy(x => x.Rx).ToList()));
                    sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.SubTile).ThenBy(x => x.TileNum).ThenBy(x => x.Z).ThenBy(x => x.Ry).ToList()));
                    sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.SubTile).ThenBy(x => x.Z).ThenBy(x => x.TileNum).ThenBy(x => x.Rx).ToList()));
                    sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.SubTile).ThenBy(x => x.Z).ThenBy(x => x.TileNum).ThenBy(x => x.Ry).ToList()));
                    sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.TileNum).ThenBy(x => x.Rx).ThenBy(x => x.SubTile).ThenBy(x => x.Z).ToList()));
                    sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.TileNum).ThenBy(x => x.SubTile).ThenBy(x => x.Ry).ThenBy(x => x.Z).ToList()));
                    sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.TileNum).ThenBy(x => x.SubTile).ThenBy(x => x.Z).ThenBy(x => x.Rx).ToList()));
                    sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.TileNum).ThenBy(x => x.SubTile).ThenBy(x => x.Z).ThenBy(x => x.Ry).ToList()));
                    sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.TileNum).ThenBy(x => x.Z).ThenBy(x => x.SubTile).ThenBy(x => x.Rx).ToList()));
                    sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.TileNum).ThenBy(x => x.Z).ThenBy(x => x.SubTile).ThenBy(x => x.Ry).ToList()));
                    sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.Z).ThenBy(x => x.SubTile).ThenBy(x => x.TileNum).ThenBy(x => x.Rx).ToList()));
                    sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.Z).ThenBy(x => x.SubTile).ThenBy(x => x.TileNum).ThenBy(x => x.Ry).ToList()));
                    sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.Z).ThenBy(x => x.TileNum).ThenBy(x => x.Rx).ThenBy(x => x.SubTile).ToList()));
                    sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.Z).ThenBy(x => x.TileNum).ThenBy(x => x.Ry).ThenBy(x => x.SubTile).ToList()));
                    sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.Z).ThenBy(x => x.TileNum).ThenBy(x => x.SubTile).ThenBy(x => x.Rx).ToList()));
                    sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.Z).ThenBy(x => x.TileNum).ThenBy(x => x.SubTile).ThenBy(x => x.Ry).ToList()));
                    int smallest      = sortedTiles[0].Length;
                    int smallestIndex = 0;
                    for (int index = 0; index < sortedTiles.Count; index++)
                    {
                        if (sortedTiles[index].Length < smallest)
                        {
                            smallest      = sortedTiles[index].Length;
                            smallestIndex = index;
                        }
                    }
                    encoded = sortedTiles[smallestIndex];
                }
            }
            else
            {
                encoded = GetEncoded(tileSet);
            }

            string compressed64 = Convert.ToBase64String(encoded, Base64FormattingOptions.None);

            int i   = 1;
            int idx = 0;

            isoMapPack5.Clear();
            while (idx < compressed64.Length)
            {
                int adv = Math.Min(74, compressed64.Length - idx);
                isoMapPack5.SetValue(i++.ToString(), compressed64.Substring(idx, adv));
                idx += adv;
            }
        }