Ejemplo n.º 1
0
 public Game(int width, int height, int mines)
 {
     this.height = height;
     this.width = width;
     this.mines = mines;
     tiles = new Tile[width, height];
     for (int i = 0; i < this.width; i++)
         for (int j = 0; j < this.height; j++)
             tiles[i, j] = new Tile();
     Random rand = new Random();
     for (int i = 0; i < mines; )
     {
         int r1 = rand.Next(width);
         int r2 = rand.Next(height);
         if (tiles[r1, r2].status == Tile.TileStatus.CLEAN)
         {
             tiles[r1, r2].status = Tile.TileStatus.MINED;
             i++;
         }
     }
     timer = new System.Timers.Timer();
     timer.Interval = 1000;
     timer.Elapsed += new System.Timers.ElapsedEventHandler(onTick);
     timer.Start();
 }
Ejemplo n.º 2
0
        public MultiComponentList( MultiComponentList toCopy )
        {
            m_Min = toCopy.m_Min;
            m_Max = toCopy.m_Max;

            m_Center = toCopy.m_Center;

            m_Width = toCopy.m_Width;
            m_Height = toCopy.m_Height;

            m_Tiles = new Tile[m_Width][][];

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

                for ( int y = 0; y < m_Height; ++y )
                {
                    m_Tiles[x][y] = new Tile[toCopy.m_Tiles[x][y].Length];

                    for ( int i = 0; i < m_Tiles[x][y].Length; ++i )
                        m_Tiles[x][y][i] = toCopy.m_Tiles[x][y][i];
                }
            }

            m_List = new MultiTileEntry[toCopy.m_List.Length];

            for ( int i = 0; i < m_List.Length; ++i )
                m_List[i] = toCopy.m_List[i];
        }
Ejemplo n.º 3
0
		private bool IsOk(Mobile m, bool ignoreDoors, int ourZ, int ourTop, Tile[] tiles, ArrayList items, bool canFly )
		{
			for ( int i = 0; i < tiles.Length; ++i )
			{
				Tile check = tiles[i];
				ItemData itemData = TileData.ItemTable[check.ID & 0x3FFF];
				
				if ( (itemData.Flags & ImpassableSurface) != 0 ) // Impassable || Surface
				{
					//we can fly test what we can fly over defined in mobile array
					if(canFly && m.FlyArray != null)
					{
						//look through are array of fly tiles
						for( int x = 0; x < m.FlyArray.Length; x++ )
						{
							if(check.ID == m.FlyArray[x] )
							{
								FlyZvalue = check.Z + itemData.CalcHeight;
								continue;
							}
						}
						if(FlyZvalue !=0)
							continue;
						
					}

					int checkZ = check.Z;
					int checkTop = checkZ + itemData.CalcHeight;

					if ( checkTop > ourZ && ourTop > checkZ )
						return false;
				}
			}

			for ( int i = 0; i < items.Count; ++i )
			{
				Item item = (Item)items[i];
				int itemID = item.ItemID & 0x3FFF;
				ItemData itemData = TileData.ItemTable[itemID];
				TileFlag flags = itemData.Flags;

				if ( (flags & ImpassableSurface) != 0 ) // Impassable || Surface
				{
					if ( ignoreDoors && ((flags & TileFlag.Door) != 0 || itemID == 0x692 || itemID == 0x846 || itemID == 0x873 || (itemID >= 0x6F5 && itemID <= 0x6F6)) )
						continue;
										
					int checkZ = item.Z;
					int checkTop = checkZ + itemData.CalcHeight;

					if ( checkTop > ourZ && ourTop > checkZ )
						return false;
				}
			}

			return true;
		}
Ejemplo n.º 4
0
        public void AddRange( Tile[] tiles )
        {
            if ( (m_Count + tiles.Length) > m_Tiles.Length )
            {
                Tile[] old = m_Tiles;
                m_Tiles = new Tile[(m_Count + tiles.Length) * 2];

                for ( int i = 0; i < old.Length; ++i )
                    m_Tiles[i] = old[i];
            }

            for ( int i = 0; i < tiles.Length; ++i )
                m_Tiles[m_Count++] = tiles[i];
        }
Ejemplo n.º 5
0
		public Tile[] ToArray()
		{
			if ( m_Count == 0 )
				return m_EmptyTiles;

			Tile[] tiles = new Tile[m_Count];

			for ( int i = 0; i < m_Count; ++i )
				tiles[i] = m_Tiles[i];

			m_Count = 0;

			return tiles;
		}
Ejemplo n.º 6
0
		private bool IsOk( bool ignoreDoors, bool ignoreSpellFields, int ourZ, int ourTop, Tile[] tiles, List<Item> items )
		{
			for ( int i = 0; i < tiles.Length; ++i )
			{
				Tile check = tiles[i];

				#region SA
				ItemData itemData = TileData.ItemTable[(check.ID-0x4000) & 0x7FFF];
				#endregion

				if ( (itemData.Flags & ImpassableSurface) != 0 ) // Impassable || Surface
				{
					int checkZ = check.Z;
					int checkTop = checkZ + itemData.CalcHeight;

					if ( checkTop > ourZ && ourTop > checkZ )
						return false;
				}
			}

			for ( int i = 0; i < items.Count; ++i )
			{
				Item item = items[i];

				#region SA
				int itemID = (item.ItemID-0x4000) & 0x7FFF;
				#endregion

				ItemData itemData = TileData.ItemTable[itemID];
				TileFlag flags = itemData.Flags;

				if ( (flags & ImpassableSurface) != 0 ) // Impassable || Surface
				{
					if ( ignoreDoors && ((flags & TileFlag.Door) != 0 || itemID == 0x692 || itemID == 0x846 || itemID == 0x873 || (itemID >= 0x6F5 && itemID <= 0x6F6)) )
						continue;

					if ( ignoreSpellFields && ( itemID == 0x82 || itemID == 0x3946 || itemID == 0x3956 ) )
						continue;

					int checkZ = item.Z;
					int checkTop = checkZ + itemData.CalcHeight;

					if ( checkTop > ourZ && ourTop > checkZ )
						return false;
				}
			}

			return true;
		}
Ejemplo n.º 7
0
        public static Tile[] PatchTiles( Tile[] tiles, int season )
        {
            if ( season <= 0 || season >= SeasonCount )
                return tiles;

            var tileChanges = m_TileChanges[season];
            if ( tileChanges != null )
            {
                for ( int i = 0; i < tiles.Length; i++ )
                {
                    if ( tileChanges.ContainsKey( tiles[i].ID ) )
                        tiles[i].ID = tileChanges[tiles[i].ID];
                }
            }

            return tiles;
        }
Ejemplo n.º 8
0
		private bool IsOk( bool ignoreDoors, int ourZ, int ourTop, Tile[] tiles, ArrayList items )
		{
			for ( int i = 0; i < tiles.Length; ++i )
			{
				Tile check = tiles[i];
				ItemData itemData = TileData.ItemTable[check.ID & 0x3FFF];

				if ( (itemData.Flags & ImpassableSurface) != 0 ) // Impassable || Surface
				{
					int checkZ = check.Z;
					int checkTop = checkZ + itemData.CalcHeight;

					if ( checkTop > ourZ && ourTop > checkZ )
						return false;
				}
			}

			for ( int i = 0; i < items.Count; ++i )
			{
				Item item = (Item)items[i];
				int itemID = item.ItemID & 0x3FFF;
				ItemData itemData = TileData.ItemTable[itemID];
				TileFlag flags = itemData.Flags;

				if ( (flags & ImpassableSurface) != 0 ) // Impassable || Surface
				{
					if ( ignoreDoors && ((flags & TileFlag.Door) != 0 || itemID == 0x692 || itemID == 0x846 || itemID == 0x873 || (itemID >= 0x6F5 && itemID <= 0x6F6)) )
						continue;

					int checkZ = item.Z;
					int checkTop = checkZ + itemData.CalcHeight;

					if ( checkTop > ourZ && ourTop > checkZ )
						return false;
				}
			}

			return true;
		}
Ejemplo n.º 9
0
		private static void ProcessDisplayCase( Map map, Tile[] tiles, int x, int y )
		{
			ShopFlags flags = ShopFlags.None;

			for ( int i = 0; i < tiles.Length; ++i )
				flags |= ProcessDisplayedItem( tiles[i].ID );

			if ( flags != ShopFlags.None )
			{
				Point2D p = new Point2D( x, y );
				ShopInfo si = (ShopInfo)m_ShopTable[p];

				if ( si == null )
				{
					ArrayList floor = new ArrayList();

					RecurseFindFloor( map, x, y, floor );

					if ( floor.Count == 0 )
						return;

					si = new ShopInfo();
					si.m_Flags = flags;
					si.m_Floor = floor;
					m_ShopList.Add( si );

					for ( int i = 0; i < floor.Count; ++i )
						m_ShopTable[(Point2D)floor[i]] = si;
				}
				else
				{
					si.m_Flags |= flags;
				}
			}
		}
Ejemplo n.º 10
0
        public void Resize(int newWidth, int newHeight)
        {
            int oldWidth = m_Width, oldHeight = m_Height;

            Tile[][][] oldTiles = m_Tiles;

            int totalLength = 0;

            Tile[][][] newTiles = new Tile[newWidth][][];

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

                for (int y = 0; y < newHeight; ++y)
                {
                    if (x < oldWidth && y < oldHeight)
                    {
                        newTiles[x][y] = oldTiles[x][y];
                    }
                    else
                    {
                        newTiles[x][y] = new Tile[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)
                {
                    Tile[] tiles = newTiles[x][y];

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

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

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

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

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

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

                        m_List[index++] = new MultiTileEntry((short)tile.ID, (short)vx, (short)vy, (short)tile.Z, 1);
                    }
                }
            }
        }
Ejemplo n.º 11
0
        private unsafe Tile[] ReadLandBlock( int x, int y )
        {
            try
            {
                m_Map.Seek( ((x * m_BlockHeight) + y) * 196 + 4, SeekOrigin.Begin );

                Tile[] tiles = new Tile[64];

                fixed ( Tile *pTiles = tiles )
                {
            #if !MONO
                    _lread( m_Map.Handle, pTiles, 192 );
            #else
                    if ( m_Buffer == null || 192 > m_Buffer.Length )
                        m_Buffer = new byte[192];

                    m_Map.Read( m_Buffer, 0, 192 );

                    fixed ( byte *pbBuffer = m_Buffer )
                    {
                        Tile *pBuffer = (Tile *)pbBuffer;
                        Tile *pEnd = pBuffer + 64;
                        Tile *pCur = pTiles;

                        while ( pBuffer < pEnd )
                            *pCur++ = *pBuffer++;
                    }
            #endif
                }

                return tiles;
            }
            catch
            {
                if ( DateTime.Now >= m_NextLandWarning )
                {
                    Console.WriteLine( "Warning: Land EOS for {0} ({1}, {2})", m_Owner, x, y );
                    m_NextLandWarning = DateTime.Now + TimeSpan.FromMinutes( 1.0 );
                }

                return m_InvalidLandBlock;
            }
        }
Ejemplo n.º 12
0
        public static bool IsInContact( Tile check, Tile[] tiles )
        {
            int checkHeight = check.Height;
            int checkZ = check.Z;

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

                if ( ((checkZ + checkHeight) > tile.Z && checkZ < (tile.Z + tile.Height))/* || (tile.Z < (checkZ + checkHeight) && (tile.Z + tile.Height) > checkZ)*/ )
                {
                    return true;
                }
                else if ( checkHeight == 0 && tile.Height == 0 && checkZ == tile.Z )
                {
                    return true;
                }
            }

            return false;
        }
Ejemplo n.º 13
0
		private unsafe int PatchLand( TileMatrix matrix, string dataPath, string indexPath )
		{
			using ( FileStream fsData = new FileStream( dataPath, FileMode.Open, FileAccess.Read, FileShare.Read ) )
			{
				using ( FileStream fsIndex = new FileStream( indexPath, FileMode.Open, FileAccess.Read, FileShare.Read ) )
				{
					BinaryReader indexReader = new BinaryReader( fsIndex );

					int count = (int)(indexReader.BaseStream.Length / 4);

					for ( int i = 0; i < count; ++i )
					{
						int blockID = indexReader.ReadInt32();
						int x = blockID / matrix.BlockHeight;
						int y = blockID % matrix.BlockHeight;

						fsData.Seek( 4, SeekOrigin.Current );

						Tile[] tiles = new Tile[64];

						fixed ( Tile *pTiles = tiles )
						{
#if !MONO
							NativeReader.Read( fsData.SafeFileHandle.DangerousGetHandle(), pTiles, 192 );
#else
							NativeReader.Read( fsData.Handle, pTiles, 192 );
#endif
						}

						matrix.SetLandBlock( x, y, tiles );
					}
					
					indexReader.Close();

					return count;
				}
			}
		}
Ejemplo n.º 14
0
        public TileMatrix( Map owner, int fileIndex, int mapID, int width, int height )
        {
            m_FileShare = new ArrayList();

            for ( int i = 0; i < m_Instances.Count; ++i )
            {
                TileMatrix tm = (TileMatrix)m_Instances[i];

                if ( tm.m_FileIndex == fileIndex )
                {
                    tm.m_FileShare.Add( this );
                    m_FileShare.Add( tm );
                }
            }

            m_Instances.Add( this );
            m_FileIndex = fileIndex;
            m_Width = width;
            m_Height = height;
            m_BlockWidth = width >> 3;
            m_BlockHeight = height >> 3;

            m_Owner = owner;

            if ( fileIndex != 0x7F )
            {
                string mapPath = Core.FindDataFile( "map{0}.mul", fileIndex );

                if ( File.Exists( mapPath ) )
                    m_Map = new FileStream( mapPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite );

                string indexPath = Core.FindDataFile( "staidx{0}.mul", fileIndex );

                if ( File.Exists( indexPath ) )
                {
                    m_Index = new FileStream( indexPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite );
                    m_IndexReader = new BinaryReader( m_Index );
                }

                string staticsPath = Core.FindDataFile( "statics{0}.mul", fileIndex );

                if ( File.Exists( staticsPath ) )
                    m_Statics = new FileStream( staticsPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite );
            }

            m_EmptyStaticBlock = new Tile[8][][];

            for ( int i = 0; i < 8; ++i )
            {
                m_EmptyStaticBlock[i] = new Tile[8][];

                for ( int j = 0; j < 8; ++j )
                    m_EmptyStaticBlock[i][j] = new Tile[0];
            }

            m_InvalidLandBlock = new Tile[196];

            m_LandTiles = new Tile[m_BlockWidth][][];
            m_StaticTiles = new Tile[m_BlockWidth][][][][];
            m_StaticPatches = new int[m_BlockWidth][];
            m_LandPatches = new int[m_BlockWidth][];

            m_Patch = new TileMatrixPatch( this, mapID );
        }
Ejemplo n.º 15
0
        public void SetStaticBlock( int x, int y, Tile[][][] value )
        {
            if ( x < 0 || y < 0 || x >= m_BlockWidth || y >= m_BlockHeight )
                return;

            if ( m_StaticTiles[x] == null )
                m_StaticTiles[x] = new Tile[m_BlockHeight][][][];

            m_StaticTiles[x][y] = value;

            if ( m_StaticPatches[x] == null )
                m_StaticPatches[x] = new int[(m_BlockHeight + 31) >> 5];

            m_StaticPatches[x][y >> 5] |= 1 << (y & 0x1F);
        }
		private int PatchLand( TileMatrix matrix, string dataPath, string indexPath )
		{
			using ( FileStream fsData = new FileStream( dataPath, FileMode.Open, FileAccess.Read, FileShare.Read ) )
			{
				using ( FileStream fsIndex = new FileStream( indexPath, FileMode.Open, FileAccess.Read, FileShare.Read ) )
				{
					BinaryReader indexReader = new BinaryReader( fsIndex );

					int count = (int)(indexReader.BaseStream.Length / 4);

					for ( int i = 0; i < count; ++i )
					{
						int blockID = indexReader.ReadInt32();
						int x = blockID / matrix.BlockHeight;
						int y = blockID % matrix.BlockHeight;

						fsData.Seek( 4, SeekOrigin.Current );

						Tile[] tiles = new Tile[64];

						GCHandle handle = GCHandle.Alloc(tiles, GCHandleType.Pinned);
						try {
							if ( m_Buffer == null || 192 > m_Buffer.Length )
								m_Buffer = new byte[192];

							fsData.Read( m_Buffer, 0, 192 );

							Marshal.Copy(m_Buffer, 0, handle.AddrOfPinnedObject(), 192);
						} finally {
							handle.Free();
						}

						matrix.SetLandBlock( x, y, tiles );
					}

					indexReader.Close();

					return count;
				}
			}
		}
Ejemplo n.º 17
0
        public void RemoveXYZH( int x, int y, int z, int minHeight )
        {
            int vx = x + m_Center.m_X;
            int vy = y + m_Center.m_Y;

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

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

                    if ( tile.Z == z && tile.Height >= minHeight )
                    {
                        Tile[] newTiles = new Tile[oldTiles.Length - 1];

                        for ( int j = 0; j < i; ++j )
                            newTiles[j] = oldTiles[j];

                        for ( int j = i + 1; j < oldTiles.Length; ++j )
                            newTiles[j - 1] = oldTiles[j];

                        m_Tiles[vx][vy] = newTiles;

                        break;
                    }
                }

                MultiTileEntry[] oldList = m_List;

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

                    if ( tile.m_OffsetX == (short)x && tile.m_OffsetY == (short)y && tile.m_OffsetZ == (short)z && TileData.ItemTable[tile.m_ItemID & 0x3FFF].Height >= minHeight )
                    {
                        MultiTileEntry[] newList = new MultiTileEntry[oldList.Length - 1];

                        for ( int j = 0; j < i; ++j )
                            newList[j] = oldList[j];

                        for ( int j = i + 1; j < oldList.Length; ++j )
                            newList[j - 1] = oldList[j];

                        m_List = newList;

                        break;
                    }
                }
            }
        }
Ejemplo n.º 18
0
        public void Resize( int newWidth, int newHeight )
        {
            int oldWidth = m_Width, oldHeight = m_Height;
            Tile[][][] oldTiles = m_Tiles;

            int totalLength = 0;

            Tile[][][] newTiles = new Tile[newWidth][][];

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

                for ( int y = 0; y < newHeight; ++y )
                {
                    if ( x < oldWidth && y < oldHeight )
                        newTiles[x][y] = oldTiles[x][y];
                    else
                        newTiles[x][y] = new Tile[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 )
                {
                    Tile[] tiles = newTiles[x][y];

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

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

                        if ( vx < m_Min.m_X )
                            m_Min.m_X = vx;

                        if ( vy < m_Min.m_Y )
                            m_Min.m_Y = vy;

                        if ( vx > m_Max.m_X )
                            m_Max.m_X = vx;

                        if ( vy > m_Max.m_Y )
                            m_Max.m_Y = vy;

                        m_List[index++] = new MultiTileEntry( (short)tile.ID, (short)vx, (short)vy, (short)tile.Z, 1 );
                    }
                }
            }
        }
Ejemplo n.º 19
0
        public void Add( int itemID, int x, int y, int z )
        {
            itemID &= 0x3FFF;
            itemID |= 0x4000;

            int vx = x + m_Center.m_X;
            int vy = y + m_Center.m_Y;

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

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

                    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 & 0x3FFF].Flags & TileFlag.Roof ) != 0;

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

                oldTiles = m_Tiles[vx][vy];

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

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

                newTiles[oldTiles.Length] = new Tile( (short)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( (short)itemID, (short)x, (short)y, (short)z, 1 );

                m_List = newList;

                if ( x < m_Min.m_X )
                    m_Min.m_X = x;

                if ( y < m_Min.m_Y )
                    m_Min.m_Y = y;

                if ( x > m_Max.m_X )
                    m_Max.m_X = x;

                if ( y > m_Max.m_Y )
                    m_Max.m_Y = y;
            }
        }
Ejemplo n.º 20
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.ReadInt16();
                allTiles[i].m_OffsetX = reader.ReadInt16();
                allTiles[i].m_OffsetY = reader.ReadInt16();
                allTiles[i].m_OffsetZ = reader.ReadInt16();
                allTiles[i].m_Flags = reader.ReadInt32();

                MultiTileEntry e = allTiles[i];

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

                    if ( e.m_OffsetY < m_Min.m_Y )
                        m_Min.m_Y = e.m_OffsetY;

                    if ( e.m_OffsetX > m_Max.m_X )
                        m_Max.m_X = e.m_OffsetX;

                    if ( e.m_OffsetY > m_Max.m_Y )
                        m_Max.m_Y = e.m_OffsetY;
                }
            }

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

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

            for ( int x = 0; x < m_Width; ++x )
            {
                tiles[x] = new TileList[m_Height];
                m_Tiles[x] = new Tile[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.m_X;
                    int yOffset = allTiles[i].m_OffsetY + m_Center.m_Y;

                    tiles[xOffset][yOffset].Add( (short)((allTiles[i].m_ItemID & 0x3FFF) | 0x4000), (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();
        }
Ejemplo n.º 21
0
        public MultiComponentList(GenericReader reader)
        {
            int version = reader.ReadInt();

            switch (version)
            {
            case 0:
            {
                m_Min    = reader.ReadPoint2D();
                m_Max    = reader.ReadPoint2D();
                m_Center = reader.ReadPoint2D();
                m_Width  = reader.ReadInt();
                m_Height = reader.ReadInt();

                int length = reader.ReadInt();

                MultiTileEntry[] allTiles = m_List = new MultiTileEntry[length];

                for (int i = 0; i < length; ++i)
                {
                    allTiles[i].m_ItemID  = reader.ReadShort();
                    allTiles[i].m_OffsetX = reader.ReadShort();
                    allTiles[i].m_OffsetY = reader.ReadShort();
                    allTiles[i].m_OffsetZ = reader.ReadShort();
                    allTiles[i].m_Flags   = reader.ReadInt();
                }

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

                for (int x = 0; x < m_Width; ++x)
                {
                    tiles[x]   = new TileList[m_Height];
                    m_Tiles[x] = new Tile[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.m_X;
                        int yOffset = allTiles[i].m_OffsetY + m_Center.m_Y;

                        tiles[xOffset][yOffset].Add((short)((allTiles[i].m_ItemID & 0x3FFF) | 0x4000), (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();
                    }
                }

                break;
            }
            }
        }
Ejemplo n.º 22
0
		private void AddSingleCallback( StaticTarget st )
		{
			Tile tile = new Tile( (short) ( st.ItemID + 16384 ), (sbyte) st.Z );
			Point2D p = new Point2D( st.X, st.Y );

			ArrayList current = m_Tiles[ p ] as ArrayList;

			if ( current != null )
			{
				if ( ! current.Contains( tile ) )
				{
					current.Add( tile );
				}
			}
			else
			{
				current = new ArrayList();
				current.Add( tile );
				m_Tiles[ p ] = current;
			}

			ResendGump();
		}
Ejemplo n.º 23
0
        private unsafe Tile[][][] ReadStaticBlock( int x, int y )
        {
            try
            {
                m_IndexReader.BaseStream.Seek( ((x * m_BlockHeight) + y) * 12, SeekOrigin.Begin );

                int lookup = m_IndexReader.ReadInt32();
                int length = m_IndexReader.ReadInt32();

                if ( lookup < 0 || length <= 0 )
                {
                    return m_EmptyStaticBlock;
                }
                else
                {
                    int count = length / 7;

                    m_Statics.Seek( lookup, SeekOrigin.Begin );

                    if ( m_TileBuffer.Length < count )
                        m_TileBuffer = new StaticTile[count];

                    StaticTile[] staTiles = m_TileBuffer;//new StaticTile[tileCount];

                    fixed ( StaticTile *pTiles = staTiles )
                    {
                        if ( m_Buffer == null || length > m_Buffer.Length )
                            m_Buffer = new byte[length];

                        m_Statics.Read( m_Buffer, 0, length );

                        Marshal.Copy(m_Buffer, 0, new IntPtr(pTiles), length);

                        if ( m_Lists == null )
                        {
                            m_Lists = new TileList[8][];

                            for ( int i = 0; i < 8; ++i )
                            {
                                m_Lists[i] = new TileList[8];

                                for ( int j = 0; j < 8; ++j )
                                    m_Lists[i][j] = new TileList();
                            }
                        }

                        TileList[][] lists = m_Lists;

                        for (int i = 0; i < count; i++) {
                            StaticTile *pCur = pTiles + i;
                            lists[pCur->m_X & 0x7][pCur->m_Y & 0x7].Add( (short)((pCur->m_ID & 0x3FFF) + 0x4000), pCur->m_Z );
                        }

                        Tile[][][] tiles = new Tile[8][][];

                        for ( int i = 0; i < 8; ++i )
                        {
                            tiles[i] = new Tile[8][];

                            for ( int j = 0; j < 8; ++j )
                                tiles[i][j] = lists[i][j].ToArray();
                        }

                        return tiles;
                    }
                }
            }
            catch ( EndOfStreamException )
            {
                if ( DateTime.Now >= m_NextStaticWarning )
                {
                    Console.WriteLine( "Warning: Static EOS for {0} ({1}, {2})", m_Owner, x, y );
                    m_NextStaticWarning = DateTime.Now + TimeSpan.FromMinutes( 1.0 );
                }

                return m_EmptyStaticBlock;
            }
        }
		private int PatchStatics( TileMatrix matrix, string dataPath, string indexPath, string lookupPath )
		{
			using ( FileStream fsData = new FileStream( dataPath, FileMode.Open, FileAccess.Read, FileShare.Read ) )
			{
				using ( FileStream fsIndex = new FileStream( indexPath, FileMode.Open, FileAccess.Read, FileShare.Read ) )
				{
					using ( FileStream fsLookup = new FileStream( lookupPath, FileMode.Open, FileAccess.Read, FileShare.Read ) )
					{
						BinaryReader indexReader = new BinaryReader( fsIndex );
						BinaryReader lookupReader = new BinaryReader( fsLookup );

						int count = (int)(indexReader.BaseStream.Length / 4);

						TileList[][] lists = new TileList[8][];

						for ( int x = 0; x < 8; ++x )
						{
							lists[x] = new TileList[8];

							for ( int y = 0; y < 8; ++y )
								lists[x][y] = new TileList();
						}

						for ( int i = 0; i < count; ++i )
						{
							int blockID = indexReader.ReadInt32();
							int blockX = blockID / matrix.BlockHeight;
							int blockY = blockID % matrix.BlockHeight;

							int offset = lookupReader.ReadInt32();
							int length = lookupReader.ReadInt32();
							lookupReader.ReadInt32(); // Extra

							if ( offset < 0 || length <= 0 )
							{
								matrix.SetStaticBlock( blockX, blockY, matrix.EmptyStaticBlock );
								continue;
							}

							fsData.Seek( offset, SeekOrigin.Begin );

							int tileCount = length / 7;

							if ( m_TileBuffer.Length < tileCount )
								m_TileBuffer = new StaticTile[tileCount];

							StaticTile[] staTiles = m_TileBuffer;//new StaticTile[tileCount];

							GCHandle handle = GCHandle.Alloc(staTiles, GCHandleType.Pinned);
							try {
								if ( m_Buffer == null || length > m_Buffer.Length )
									m_Buffer = new byte[length];

								fsData.Read( m_Buffer, 0, length );

								Marshal.Copy(m_Buffer, 0, handle.AddrOfPinnedObject(), length);

								for (int j = 0; j < tileCount; j++)
								{
									StaticTile cur = staTiles[j];
									lists[cur.m_X & 0x7][cur.m_Y & 0x7].Add( (short)((cur.m_ID & 0x3FFF) + 0x4000), cur.m_Z );
								}

								Tile[][][] tiles = new Tile[8][][];

								for ( int x = 0; x < 8; ++x )
								{
									tiles[x] = new Tile[8][];

									for ( int y = 0; y < 8; ++y )
										tiles[x][y] = lists[x][y].ToArray();
								}

								matrix.SetStaticBlock( blockX, blockY, tiles );
							} finally {
								handle.Free();
							}
						}

						indexReader.Close();
						lookupReader.Close();

						return count;
					}
				}
			}
		}
Ejemplo n.º 25
0
        private unsafe Tile[][][] ReadStaticBlock(int x, int y)
        {
            try
            {
                m_IndexReader.BaseStream.Seek(((x * m_BlockHeight) + y) * 12, SeekOrigin.Begin);

                int lookup = m_IndexReader.ReadInt32();
                int length = m_IndexReader.ReadInt32();

                if (lookup < 0 || length <= 0)
                {
                    return(m_EmptyStaticBlock);
                }
                else
                {
                    int count = length / 7;

                    m_Statics.Seek(lookup, SeekOrigin.Begin);

                    if (m_TileBuffer.Length < count)
                    {
                        m_TileBuffer = new StaticTile[count];
                    }

                    StaticTile[] staTiles = m_TileBuffer;                    //new StaticTile[tileCount];

                    fixed(StaticTile *pTiles = staTiles)
                    {
#if !MONO
                        _lread(m_Statics.Handle, pTiles, length);
#else
                        if (m_Buffer == null || length > m_Buffer.Length)
                        {
                            m_Buffer = new byte[length];
                        }

                        m_Statics.Read(m_Buffer, 0, length);

                        fixed(byte *pbBuffer = m_Buffer)
                        {
                            StaticTile *pCopyBuffer = (StaticTile *)pbBuffer;
                            StaticTile *pCopyEnd    = pCopyBuffer + count;
                            StaticTile *pCopyCur    = pTiles;

                            while (pCopyBuffer < pCopyEnd)
                            {
                                *pCopyCur++ = *pCopyBuffer++;
                            }
                        }
#endif

                        if (m_Lists == null)
                        {
                            m_Lists = new TileList[8][];

                            for (int i = 0; i < 8; ++i)
                            {
                                m_Lists[i] = new TileList[8];

                                for (int j = 0; j < 8; ++j)
                                {
                                    m_Lists[i][j] = new TileList();
                                }
                            }
                        }

                        TileList[][] lists = m_Lists;

                        StaticTile *pCur = pTiles, pEnd = pTiles + count;

                        while (pCur < pEnd)
                        {
                            lists[pCur->m_X & 0x7][pCur->m_Y & 0x7].Add((short)((pCur->m_ID & 0x3FFF) + 0x4000), pCur->m_Z);
                            ++pCur;
                        }

                        Tile[][][] tiles = new Tile[8][][];

                        for (int i = 0; i < 8; ++i)
                        {
                            tiles[i] = new Tile[8][];

                            for (int j = 0; j < 8; ++j)
                            {
                                tiles[i][j] = lists[i][j].ToArray();
                            }
                        }

                        return(tiles);
                    }
                }
            }
            catch (EndOfStreamException)
            {
                if (DateTime.Now >= m_NextStaticWarning)
                {
                    Console.WriteLine("Warning: Static EOS for {0} ({1}, {2})", m_Owner, x, y);
                    m_NextStaticWarning = DateTime.Now + TimeSpan.FromMinutes(1.0);
                }

                return(m_EmptyStaticBlock);
            }
        }
Ejemplo n.º 26
0
		private unsafe int PatchStatics( TileMatrix matrix, string dataPath, string indexPath, string lookupPath )
		{
			using ( FileStream fsData = new FileStream( dataPath, FileMode.Open, FileAccess.Read, FileShare.Read ) )
			{
				using ( FileStream fsIndex = new FileStream( indexPath, FileMode.Open, FileAccess.Read, FileShare.Read ) )
				{
					using ( FileStream fsLookup = new FileStream( lookupPath, FileMode.Open, FileAccess.Read, FileShare.Read ) )
					{
						BinaryReader indexReader = new BinaryReader( fsIndex );
						BinaryReader lookupReader = new BinaryReader( fsLookup );

						int count = (int)(indexReader.BaseStream.Length / 4);

						TileList[][] lists = new TileList[8][];

						for ( int x = 0; x < 8; ++x )
						{
							lists[x] = new TileList[8];

							for ( int y = 0; y < 8; ++y )
								lists[x][y] = new TileList();
						}

						for ( int i = 0; i < count; ++i )
						{
							int blockID = indexReader.ReadInt32();
							int blockX = blockID / matrix.BlockHeight;
							int blockY = blockID % matrix.BlockHeight;

							int offset = lookupReader.ReadInt32();
							int length = lookupReader.ReadInt32();
							lookupReader.ReadInt32(); // Extra

							if ( offset < 0 || length <= 0 )
							{
								matrix.SetStaticBlock( blockX, blockY, matrix.EmptyStaticBlock );
								continue;
							}

							fsData.Seek( offset, SeekOrigin.Begin );

							int tileCount = length / 7;

							if ( m_TileBuffer.Length < tileCount )
								m_TileBuffer = new StaticTile[tileCount];

							StaticTile[] staTiles = m_TileBuffer;

							fixed ( StaticTile *pTiles = staTiles )
							{
#if !MONO
								NativeReader.Read( fsData.SafeFileHandle.DangerousGetHandle(), pTiles, length );
#else
								NativeReader.Read( fsData.Handle, pTiles, length );
#endif
								StaticTile *pCur = pTiles, pEnd = pTiles + tileCount;

								while ( pCur < pEnd )
								{
									lists[pCur->m_X & 0x7][pCur->m_Y & 0x7].Add( (short)((pCur->m_ID & 0x3FFF) + 0x4000), pCur->m_Z );
									pCur = pCur + 1;
								}

								Tile[][][] tiles = new Tile[8][][];

								for ( int x = 0; x < 8; ++x )
								{
									tiles[x] = new Tile[8][];

									for ( int y = 0; y < 8; ++y )
										tiles[x][y] = lists[x][y].ToArray();
								}

								matrix.SetStaticBlock( blockX, blockY, tiles );
							}
						}

						indexReader.Close();
						lookupReader.Close();

						return count;
					}
				}
			}
		}
Ejemplo n.º 27
0
        private unsafe int PatchLand( TileMatrix matrix, string dataPath, string indexPath )
        {
            using ( FileStream fsData = new FileStream( dataPath, FileMode.Open, FileAccess.Read, FileShare.Read ) )
            {
                using ( FileStream fsIndex = new FileStream( indexPath, FileMode.Open, FileAccess.Read, FileShare.Read ) )
                {
                    BinaryReader indexReader = new BinaryReader( fsIndex );

                    int count = (int)(indexReader.BaseStream.Length / 4);

                    for ( int i = 0; i < count; ++i )
                    {
                        int blockID = indexReader.ReadInt32();
                        int x = blockID / matrix.BlockHeight;
                        int y = blockID % matrix.BlockHeight;

                        fsData.Seek( 4, SeekOrigin.Current );

                        Tile[] tiles = new Tile[64];

                        fixed ( Tile *pTiles = tiles )
                        {
                            if ( m_Buffer == null || 192 > m_Buffer.Length )
                                m_Buffer = new byte[192];

                            fsData.Read( m_Buffer, 0, 192 );

                            Marshal.Copy(m_Buffer, 0, new IntPtr(pTiles), 192);
                        }

                        matrix.SetLandBlock( x, y, tiles );
                    }

                    indexReader.Close();

                    return count;
                }
            }
        }
Ejemplo n.º 28
0
        public void Add(int itemID, int x, int y, int z)
        {
            itemID &= 0x3FFF;
            itemID |= 0x4000;

            int vx = x + m_Center.m_X;
            int vy = y + m_Center.m_Y;

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

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

                    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 & 0x3FFF].Flags & TileFlag.Roof) != 0;

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

                oldTiles = m_Tiles[vx][vy];

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

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

                newTiles[oldTiles.Length] = new Tile((short)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((short)itemID, (short)x, (short)y, (short)z, 1);

                m_List = newList;

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

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

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

                if (y > m_Max.mY)
                {
                    m_Max.mY = y;
                }
            }
        }
Ejemplo n.º 29
0
        public static bool CanMobileFit( int z, Tile[] tiles )
        {
            int checkHeight = 15;
            int checkZ = z;

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

                if ( ((checkZ + checkHeight) > tile.Z && checkZ < (tile.Z + tile.Height))/* || (tile.Z < (checkZ + checkHeight) && (tile.Z + tile.Height) > checkZ)*/ )
                {
                    return false;
                }
                else if ( checkHeight == 0 && tile.Height == 0 && checkZ == tile.Z )
                {
                    return false;
                }
            }

            return true;
        }
Ejemplo n.º 30
0
        public Tile[][][] GetStaticBlock( int x, int y )
        {
            if ( x < 0 || y < 0 || x >= m_BlockWidth || y >= m_BlockHeight || m_Statics == null || m_Index == null )
                return m_EmptyStaticBlock;

            if ( m_StaticTiles[x] == null )
                m_StaticTiles[x] = new Tile[m_BlockHeight][][][];

            Tile[][][] tiles = m_StaticTiles[x][y];

            if ( tiles == null )
            {
                for ( int i = 0; tiles == null && i < m_FileShare.Count; ++i )
                {
                    TileMatrix shared = (TileMatrix)m_FileShare[i];

                    if ( x >= 0 && x < shared.m_BlockWidth && y >= 0 && y < shared.m_BlockHeight )
                    {
                        Tile[][][][] theirTiles = shared.m_StaticTiles[x];

                        if ( theirTiles != null )
                            tiles = theirTiles[y];

                        if ( tiles != null )
                        {
                            int[] theirBits = shared.m_StaticPatches[x];

                            if ( theirBits != null && (theirBits[y >> 5] & (1 << (y & 0x1F))) != 0 )
                                tiles = null;
                        }
                    }
                }

                if ( tiles == null )
                    tiles = ReadStaticBlock( x, y );

                m_StaticTiles[x][y] = tiles;
            }

            return tiles;
        }
        private unsafe Tile[][][] ReadStaticBlock( int x, int y )
        {
            try
            {
                m_IndexReader.BaseStream.Seek( ((x * m_BlockHeight) + y) * 12, SeekOrigin.Begin );

                int lookup = m_IndexReader.ReadInt32();
                int length = m_IndexReader.ReadInt32();

                if ( lookup < 0 || length <= 0 )
                {
                    return m_EmptyStaticBlock;
                }
                else
                {
                    int count = length / 7;

                    m_Statics.Seek( lookup, SeekOrigin.Begin );

                    if ( m_TileBuffer.Length < count )
                        m_TileBuffer = new StaticTile[count];

                    StaticTile[] staTiles = m_TileBuffer;//new StaticTile[tileCount];

                    fixed ( StaticTile *pTiles = staTiles )
                    {
            #if !MONO
                        NativeReader.Read( m_Statics.SafeFileHandle.DangerousGetHandle(), pTiles, length );
            #else
                        NativeReader.Read( m_Statics.Handle, pTiles, length );
            #endif
                        if ( m_Lists == null )
                        {
                            m_Lists = new TileList[8][];

                            for ( int i = 0; i < 8; ++i )
                            {
                                m_Lists[i] = new TileList[8];

                                for ( int j = 0; j < 8; ++j )
                                    m_Lists[i][j] = new TileList();
                            }
                        }

                        TileList[][] lists = m_Lists;

                        StaticTile *pCur = pTiles, pEnd = pTiles + count;

                        while ( pCur < pEnd )
                        {
                            lists[pCur->m_X & 0x7][pCur->m_Y & 0x7].Add( (short)((pCur->m_ID & 0x3FFF) + 0x4000), pCur->m_Z );
                            pCur = pCur + 1;
                        }

                        Tile[][][] tiles = new Tile[8][][];

                        for ( int i = 0; i < 8; ++i )
                        {
                            tiles[i] = new Tile[8][];

                            for ( int j = 0; j < 8; ++j )
                                tiles[i][j] = lists[i][j].ToArray();
                        }

                        return tiles;
                    }
                }
            }
            catch ( EndOfStreamException )
            {
                if ( DateTime.Now >= m_NextStaticWarning )
                {
                    Console.WriteLine( "Warning: Static EOS for {0} ({1}, {2})", m_Owner, x, y );
                    m_NextStaticWarning = DateTime.Now + TimeSpan.FromMinutes( 1.0 );
                }

                return m_EmptyStaticBlock;
            }
        }
Ejemplo n.º 32
0
        private unsafe Tile[] ReadLandBlock( int x, int y )
        {
            try
            {
                m_Map.Seek( ((x * m_BlockHeight) + y) * 196 + 4, SeekOrigin.Begin );

                Tile[] tiles = new Tile[64];

                fixed ( Tile *pTiles = tiles )
                {
                    if ( m_Buffer == null || 192 > m_Buffer.Length )
                        m_Buffer = new byte[192];

                    m_Map.Read( m_Buffer, 0, 192 );

                    Marshal.Copy(m_Buffer, 0, new IntPtr(pTiles), 192);
                }

                return tiles;
            }
            catch
            {
                if ( DateTime.Now >= m_NextLandWarning )
                {
                    Console.WriteLine( "Warning: Land EOS for {0} ({1}, {2})", m_Owner, x, y );
                    m_NextLandWarning = DateTime.Now + TimeSpan.FromMinutes( 1.0 );
                }

                return m_InvalidLandBlock;
            }
        }
Ejemplo n.º 33
0
        public MultiComponentList( GenericReader reader )
        {
            int version = reader.ReadInt();

            switch ( version )
            {
                case 0:
                {
                    m_Min = reader.ReadPoint2D();
                    m_Max = reader.ReadPoint2D();
                    m_Center = reader.ReadPoint2D();
                    m_Width = reader.ReadInt();
                    m_Height = reader.ReadInt();

                    int length = reader.ReadInt();

                    MultiTileEntry[] allTiles = m_List = new MultiTileEntry[length];

                    for ( int i = 0; i < length; ++i )
                    {
                        allTiles[i].m_ItemID = reader.ReadShort();
                        allTiles[i].m_OffsetX = reader.ReadShort();
                        allTiles[i].m_OffsetY = reader.ReadShort();
                        allTiles[i].m_OffsetZ = reader.ReadShort();
                        allTiles[i].m_Flags = reader.ReadInt();
                    }

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

                    for ( int x = 0; x < m_Width; ++x )
                    {
                        tiles[x] = new TileList[m_Height];
                        m_Tiles[x] = new Tile[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.m_X;
                            int yOffset = allTiles[i].m_OffsetY + m_Center.m_Y;

                            tiles[xOffset][yOffset].Add( (short)((allTiles[i].m_ItemID & 0x3FFF) | 0x4000), (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();

                    break;
                }
            }
        }
Ejemplo n.º 34
0
        static bool TileAtZ(Tile[] tiles, int z)
        {
            for (int j = 0; j < tiles.Length; ++j)
            {
                Tile tile = tiles[j];
                if (tile.Z == z)
                    return true;
            }

            return false;
        }
Ejemplo n.º 35
0
        public TileMatrix(Map owner, int fileIndex, int mapID, int width, int height)
        {
            m_FileShare = new ArrayList();

            for (int i = 0; i < m_Instances.Count; ++i)
            {
                TileMatrix tm = (TileMatrix)m_Instances[i];

                if (tm.m_FileIndex == fileIndex)
                {
                    tm.m_FileShare.Add(this);
                    m_FileShare.Add(tm);
                }
            }

            m_Instances.Add(this);
            m_FileIndex   = fileIndex;
            m_Width       = width;
            m_Height      = height;
            m_BlockWidth  = width >> 3;
            m_BlockHeight = height >> 3;

            m_Owner = owner;

            if (fileIndex != 0x7F)
            {
                string mapPath = Core.FindDataFile("map{0}.mul", fileIndex);

                if (File.Exists(mapPath))
                {
                    m_Map = new FileStream(mapPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                }

                string indexPath = Core.FindDataFile("staidx{0}.mul", fileIndex);

                if (File.Exists(indexPath))
                {
                    m_Index       = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                    m_IndexReader = new BinaryReader(m_Index);
                }

                string staticsPath = Core.FindDataFile("statics{0}.mul", fileIndex);

                if (File.Exists(staticsPath))
                {
                    m_Statics = new FileStream(staticsPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                }
            }

            m_EmptyStaticBlock = new Tile[8][][];

            for (int i = 0; i < 8; ++i)
            {
                m_EmptyStaticBlock[i] = new Tile[8][];

                for (int j = 0; j < 8; ++j)
                {
                    m_EmptyStaticBlock[i][j] = new Tile[0];
                }
            }

            m_InvalidLandBlock = new Tile[196];

            m_LandTiles     = new Tile[m_BlockWidth][][];
            m_StaticTiles   = new Tile[m_BlockWidth][][][][];
            m_StaticPatches = new int[m_BlockWidth][];
            m_LandPatches   = new int[m_BlockWidth][];

            m_Patch = new TileMatrixPatch(this, mapID);
        }