コード例 #1
0
        public void Serialize(GenericWriter writer)
        {
            writer.Write((int)1); // version;

            writer.Write(m_Min);
            writer.Write(m_Max);
            writer.Write(m_Center);

            writer.Write((int)m_Width);
            writer.Write((int)m_Height);

            writer.Write((int)m_List.Length);

            for (int i = 0; i < m_List.Length; ++i)
            {
                MultiTileEntry ent = m_List[i];

                writer.Write((ushort)ent.m_ItemID);
                writer.Write((short)ent.m_OffsetX);
                writer.Write((short)ent.m_OffsetY);
                writer.Write((short)ent.m_OffsetZ);
                writer.Write((int)ent.m_Flags);
            }
        }
コード例 #2
0
        public MultiComponentList(BinaryReader reader, int count)
        {
            MultiTileEntry[] allTiles = m_List = new MultiTileEntry[count];

            for (int i = 0; i < count; ++i)
            {
                allTiles[i].m_ItemID  = reader.ReadUInt16();
                allTiles[i].m_OffsetX = reader.ReadInt16();
                allTiles[i].m_OffsetY = reader.ReadInt16();
                allTiles[i].m_OffsetZ = reader.ReadInt16();
                allTiles[i].m_Flags   = reader.ReadInt32();

                if (_PostHSFormat)
                {
                    reader.ReadInt32(); // ??
                }
                MultiTileEntry e = allTiles[i];

                if (i == 0 || e.m_Flags != 0)
                {
                    if (e.m_OffsetX < m_Min.X)
                    {
                        m_Min.X = e.m_OffsetX;
                    }

                    if (e.m_OffsetY < m_Min.Y)
                    {
                        m_Min.Y = e.m_OffsetY;
                    }

                    if (e.m_OffsetX > m_Max.X)
                    {
                        m_Max.X = e.m_OffsetX;
                    }

                    if (e.m_OffsetY > m_Max.Y)
                    {
                        m_Max.Y = e.m_OffsetY;
                    }
                }
            }

            m_Center = new Point2D(-m_Min.X, -m_Min.Y);
            m_Width  = (m_Max.X - m_Min.X) + 1;
            m_Height = (m_Max.Y - m_Min.Y) + 1;

            TileList[][] tiles = new TileList[m_Width][];
            m_Tiles = new StaticTile[m_Width][][];

            for (int x = 0; x < m_Width; ++x)
            {
                tiles[x]   = new TileList[m_Height];
                m_Tiles[x] = new StaticTile[m_Height][];

                for (int y = 0; y < m_Height; ++y)
                {
                    tiles[x][y] = new TileList();
                }
            }

            for (int i = 0; i < allTiles.Length; ++i)
            {
                if (i == 0 || allTiles[i].m_Flags != 0)
                {
                    int xOffset = allTiles[i].m_OffsetX + m_Center.X;
                    int yOffset = allTiles[i].m_OffsetY + m_Center.Y;

                    tiles[xOffset][yOffset].Add((ushort)allTiles[i].m_ItemID, (sbyte)allTiles[i].m_OffsetZ);
                }
            }

            for (int x = 0; x < m_Width; ++x)
            {
                for (int y = 0; y < m_Height; ++y)
                {
                    m_Tiles[x][y] = tiles[x][y].ToArray();
                }
            }
        }
コード例 #3
0
        public void Resize(int newWidth, int newHeight)
        {
            int oldWidth = m_Width, oldHeight = m_Height;

            StaticTile[][][] oldTiles = m_Tiles;

            int totalLength           = 0;

            StaticTile[][][] newTiles = new StaticTile[newWidth][][];

            for (int x = 0; x < newWidth; ++x)
            {
                newTiles[x] = new StaticTile[newHeight][];

                for (int y = 0; y < newHeight; ++y)
                {
                    if (x < oldWidth && y < oldHeight)
                    {
                        newTiles[x][y] = oldTiles[x][y];
                    }
                    else
                    {
                        newTiles[x][y] = new StaticTile[0];
                    }

                    totalLength += newTiles[x][y].Length;
                }
            }

            m_Tiles  = newTiles;
            m_List   = new MultiTileEntry[totalLength];
            m_Width  = newWidth;
            m_Height = newHeight;

            m_Min = Point2D.Zero;
            m_Max = Point2D.Zero;

            int index = 0;

            for (int x = 0; x < newWidth; ++x)
            {
                for (int y = 0; y < newHeight; ++y)
                {
                    StaticTile[] tiles = newTiles[x][y];

                    for (int i = 0; i < tiles.Length; ++i)
                    {
                        StaticTile tile = tiles[i];

                        int vx = x - m_Center.X;
                        int vy = y - m_Center.Y;

                        if (vx < m_Min.X)
                        {
                            m_Min.X = vx;
                        }

                        if (vy < m_Min.Y)
                        {
                            m_Min.Y = vy;
                        }

                        if (vx > m_Max.X)
                        {
                            m_Max.X = vx;
                        }

                        if (vy > m_Max.Y)
                        {
                            m_Max.Y = vy;
                        }

                        m_List[index++] = new MultiTileEntry((ushort)tile.ID, (short)vx, (short)vy, (short)tile.Z, 1);
                    }
                }
            }
        }
コード例 #4
0
        public void Add(int itemID, int x, int y, int z)
        {
            int vx = x + m_Center.X;
            int vy = y + m_Center.Y;

            if (vx >= 0 && vx < m_Width && vy >= 0 && vy < m_Height)
            {
                StaticTile[] oldTiles = m_Tiles[vx][vy];

                for (int i = oldTiles.Length - 1; i >= 0; --i)
                {
                    ItemData data = TileData.ItemTable[itemID & TileData.MaxItemValue];

                    if (oldTiles[i].Z == z && (oldTiles[i].Height > 0 == data.Height > 0))
                    {
                        bool newIsRoof = (data.Flags & TileFlag.Roof) != 0;
                        bool oldIsRoof = (TileData.ItemTable[oldTiles[i].ID & TileData.MaxItemValue].Flags & TileFlag.Roof) != 0;

                        if (newIsRoof == oldIsRoof)
                        {
                            Remove(oldTiles[i].ID, x, y, z);
                        }
                    }
                }

                oldTiles = m_Tiles[vx][vy];

                StaticTile[] newTiles = new StaticTile[oldTiles.Length + 1];

                for (int i = 0; i < oldTiles.Length; ++i)
                {
                    newTiles[i] = oldTiles[i];
                }

                newTiles[oldTiles.Length] = new StaticTile((ushort)itemID, (sbyte)z);

                m_Tiles[vx][vy] = newTiles;

                MultiTileEntry[] oldList = m_List;
                MultiTileEntry[] newList = new MultiTileEntry[oldList.Length + 1];

                for (int i = 0; i < oldList.Length; ++i)
                {
                    newList[i] = oldList[i];
                }

                newList[oldList.Length] = new MultiTileEntry((ushort)itemID, (short)x, (short)y, (short)z, 1);

                m_List = newList;

                if (x < m_Min.X)
                {
                    m_Min.X = x;
                }

                if (y < m_Min.Y)
                {
                    m_Min.Y = y;
                }

                if (x > m_Max.X)
                {
                    m_Max.X = x;
                }

                if (y > m_Max.Y)
                {
                    m_Max.Y = y;
                }
            }
        }