public bool IsSameAs(MapTile other)
 {
     return _type == other._type &&
            _light == other._light &&
            _misc == other._misc &&
            _misc2 == other._misc2;
 }
Exemple #2
0
        public static Map Load(string filename)
        {
            var m = new Map();

            using (var b = new BinaryReader(File.OpenRead(filename)))
            {
                m.Version = b.ReadInt32();

                if (m.Version <= World.CompatibleVersion)
                {
                    m.WorldName = b.ReadString();
                    m.WorldId   = b.ReadInt32();
                    m.MaxTilesY = b.ReadInt32();
                    m.MaxTilesX = b.ReadInt32();

                    m.Tiles = new MapTile[m.MaxTilesX, m.MaxTilesY];
                    for (int x = 0; x < m.MaxTilesX; x++)
                    {
                        // status
                        for (int y = 0; y < m.MaxTilesY; y++)
                        {
                            if (!b.ReadBoolean())
                            {
                                int rle = b.ReadInt16();

                                if (rle > 0)
                                {
                                    y = y + rle;
                                    if (m[x, y] != null)
                                    {
                                        m[x, y] = new MapTile();
                                    }
                                }
                            }
                            else
                            {
                                var curTile = new MapTile();
                                curTile.Type  = b.ReadByte();
                                curTile.Light = b.ReadByte();
                                curTile.Misc  = b.ReadByte();

                                if (m.Version < 50)
                                {
                                    curTile.Misc2 = 0;
                                }
                                else
                                {
                                    curTile.Misc2 = b.ReadByte();
                                }

                                m[x, y] = curTile;

                                int rle = b.ReadInt16();
                                if (curTile.Light == 255)
                                {
                                    if (rle > 0)
                                    {
                                        for (int k = y + 1; k < y + rle + 1; k++)
                                        {
                                            m[x, k] = curTile.Copy();
                                        }
                                        y = y + rle;
                                    }
                                }
                                else if (rle > 0)
                                {
                                    for (int k = y + 1; k < y + rle + 1; k++)
                                    {
                                        byte light = b.ReadByte();

                                        if (light > 18)
                                        {
                                            m[x, k]       = curTile.Copy();
                                            m[x, k].Light = light;
                                        }
                                    }
                                    y = y + rle;
                                }
                            }
                        }
                    }
                    b.Close();
                }
            }

            return(m);
        }
Exemple #3
0
        public static Map Load(string filename)
        {
            var m = new Map();

            using (var b = new BinaryReader(File.OpenRead(filename)))
            {
                m.Version = b.ReadInt32();

                if (m.Version <= World.CompatibleVersion)
                {
                    m.WorldName = b.ReadString();
                    m.WorldId = b.ReadInt32();
                    m.MaxTilesY = b.ReadInt32();
                    m.MaxTilesX = b.ReadInt32();

                    m.Tiles = new MapTile[m.MaxTilesX, m.MaxTilesY];
                    for (int x = 0; x < m.MaxTilesX; x++)
                    {
                        // status
                        for (int y = 0; y < m.MaxTilesY; y++)
                        {
                            if (!b.ReadBoolean())
                            {
                                int rle = b.ReadInt16();

                                if (rle > 0)
                                {
                                    y = y + rle;
                                    if (m[x, y] != null)
                                    {
                                        m[x, y] = new MapTile();
                                    }
                                }
                            }
                            else
                            {
                                var curTile = new MapTile();
                                curTile.Type = b.ReadByte();
                                curTile.Light = b.ReadByte();
                                curTile.Misc = b.ReadByte();

                                if (m.Version < 50)
                                    curTile.Misc2 = 0;
                                else
                                    curTile.Misc2 = b.ReadByte();

                                m[x, y] = curTile;

                                int rle = b.ReadInt16();
                                if (curTile.Light == 255)
                                {
                                    if (rle > 0)
                                    {
                                        for (int k = y + 1; k < y + rle + 1; k++)
                                        {
                                            m[x, k] = curTile.Copy();
                                        }
                                        y = y + rle;
                                    }
                                }
                                else if (rle > 0)
                                {
                                    for (int k = y + 1; k < y + rle + 1; k++)
                                    {
                                        byte light = b.ReadByte();

                                        if (light > 18)
                                        {
                                            m[x, k] = curTile.Copy();
                                            m[x, k].Light = light;
                                        }
                                    }
                                    y = y + rle;
                                }
                            }
                        }
                    }
                    b.Close();
                }
            }

            return m;
        }