Exemplo n.º 1
0
        private void button3_Click(object sender, EventArgs e)
        {
            Ultima.Tile mytile = new Ultima.Tile();

            //mytile = tm.GetLandTile(2563, 489);
            int mytileid = (mytile.ID & 0x3FFF);

            // uonet.display(""+mytileid);


            Ultima.Tile       mytile2 = new Ultima.Tile();
            Ultima.TileMatrix tm      = new TileMatrix(0, 0, 6144, 4096);
            HuedTile[]        htile   = tm.GetStaticTiles(2563, 489);
            int mytileid2             = (htile[0].ID & 0x3FFF); // need a check, exception if ID is 0

            //uonet.display("" + htile[0].ID + "___" + htile[1].ID);

            //mytile2 =



            mytile = tm.GetLandTile(273, 1216);
            //txtOutput.Text = txtOutput.Text + StringList.Table[1076267];
            //txtOutput.Text = txtOutput.Text +
        }
Exemplo n.º 2
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 )
                        {
                            _lread(fsData.SafeFileHandle, pTiles, 192);
                        }

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

                    return count;
                }
            }
        }
 public Tile[] ToArray()
 {
     Tile[] mTiles = new Tile[this.m_Count];
     for (int i = 0; i < this.m_Count; i++)
     {
         mTiles[i] = this.m_Tiles[i];
     }
     this.m_Count = 0;
     return mTiles;
 }
Exemplo n.º 4
0
        public TileMatrixPatch(TileMatrix matrix, int index, string path)
        {
            BlockWidth = matrix.BlockWidth;
            BlockHeight = matrix.BlockWidth;

            LandBlocksCount = StaticBlocksCount = 0;
            string mapDataPath, mapIndexPath;
            if (path == null)
            {
                mapDataPath = Files.GetFilePath("mapdif{0}.mul", index);
                mapIndexPath = Files.GetFilePath("mapdifl{0}.mul", index);
            }
            else
            {
                mapDataPath = Path.Combine(path, String.Format("mapdif{0}.mul", index));
                if (!File.Exists(mapDataPath))
                    mapDataPath = null;
                mapIndexPath = Path.Combine(path, String.Format("mapdifl{0}.mul", index));
                if (!File.Exists(mapIndexPath))
                    mapIndexPath = null;
            }

            if (mapDataPath != null && mapIndexPath != null)
            {
                LandBlocks = new Tile[matrix.BlockWidth][][];
                LandBlocksCount = PatchLand(matrix, mapDataPath, mapIndexPath);
            }

            string staDataPath, staIndexPath, staLookupPath;
            if (path == null)
            {
                staDataPath = Files.GetFilePath("stadif{0}.mul", index);
                staIndexPath = Files.GetFilePath("stadifl{0}.mul", index);
                staLookupPath = Files.GetFilePath("stadifi{0}.mul", index);
            }
            else
            {
                staDataPath = Path.Combine(path, String.Format("stadif{0}.mul", index));
                if (!File.Exists(staDataPath))
                    staDataPath = null;
                staIndexPath = Path.Combine(path, String.Format("stadifl{0}.mul", index));
                if (!File.Exists(staIndexPath))
                    staIndexPath = null;
                staLookupPath = Path.Combine(path, String.Format("stadifi{0}.mul", index));
                if (!File.Exists(staLookupPath))
                    staLookupPath = null;
            }

            if (staDataPath != null && staIndexPath != null && staLookupPath != null)
            {
                StaticBlocks = new HuedTile[matrix.BlockWidth][][][][];
                StaticBlocksCount = PatchStatics(matrix, staDataPath, staIndexPath, staLookupPath);
            }
        }
Exemplo n.º 5
0
		public Tile[] ToArray()
		{
			var tiles = new Tile[Count];
			if (m_Tiles.Count > 0)
			{
				m_Tiles.CopyTo(tiles);
			}
			m_Tiles.Clear();

			return tiles;
		}
Exemplo n.º 6
0
		public Tile[] ToArray()
		{
			Tile[] tiles = new Tile[m_Count];

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

			m_Count = 0;

			return tiles;
		}
 private unsafe int PatchLand(TileMatrix matrix, string dataPath, string indexPath)
 {
     using (FileStream fileStream1 = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read))
       {
     using (FileStream fileStream2 = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.Read))
     {
       BinaryReader binaryReader = new BinaryReader((Stream) fileStream2);
       int num1 = (int) (binaryReader.BaseStream.Length / 4L);
       for (int index = 0; index < num1; ++index)
       {
     int num2 = binaryReader.ReadInt32();
     int x = num2 / matrix.BlockHeight;
     int y = num2 % matrix.BlockHeight;
     fileStream1.Seek(4L, SeekOrigin.Current);
     Tile[] tileArray = new Tile[64];
     fixed (Tile* tilePtr = &tileArray[0])
       TileMatrixPatch._lread(fileStream1.Handle, (void*) tilePtr, 192);
     matrix.SetLandBlock(x, y, tileArray);
       }
       return num1;
     }
       }
 }
Exemplo n.º 8
0
 public Tile(Ultima.Tile land)
 {
     this.Type = land.ID;
     this.Z    = land.Z;
 }
Exemplo n.º 9
0
        public void SetLandBlock( int x, int y, Tile[] value )
        {
            if ( x < 0 || y < 0 || x >= m_BlockWidth || y >= m_BlockHeight )
                return;

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

            m_LandTiles[x][y] = value;
        }
Exemplo n.º 10
0
 public static bool Ignored(this Ultima.Tile tile)
 {
     return(tile.ID == 2 || tile.ID == 0x1DB || (tile.ID >= 0x1AE && tile.ID <= 0x1B5));
 }
Exemplo n.º 11
0
        public Tile[] ToArray()
        {
            Tile[] tiles = new Tile[Count];
            if (m_Tiles.Count > 0)
                m_Tiles.CopyTo(tiles);
            m_Tiles.Clear();

            return tiles;
        }
Exemplo n.º 12
0
		public TileMatrix(int fileIndex, int mapID, int width, int height, string path)
		{
			Width = width;
			Height = height;
			BlockWidth = width >> 3;
			BlockHeight = height >> 3;

			if (path == null)
			{
				mapPath = Files.GetFilePath("map{0}.mul", fileIndex);

				if (String.IsNullOrEmpty(mapPath) || !File.Exists(mapPath))
				{
					mapPath = Files.GetFilePath("map{0}LegacyMUL.uop", fileIndex);
				}

				if (mapPath != null && mapPath.EndsWith(".uop"))
				{
					IsUOPFormat = true;
				}
			}
			else
			{
				mapPath = Path.Combine(path, String.Format("map{0}.mul", fileIndex));

				if (!File.Exists(mapPath))
				{
					mapPath = Path.Combine(path, String.Format("map{0}LegacyMUL.uop", fileIndex));
				}

				if (!File.Exists(mapPath))
				{
					mapPath = null;
				}
				else if (mapPath != null && mapPath.EndsWith(".uop"))
				{
					IsUOPFormat = true;
				}
			}

			if (path == null)
			{
				indexPath = Files.GetFilePath("staidx{0}.mul", fileIndex);
			}
			else
			{
				indexPath = Path.Combine(path, String.Format("staidx{0}.mul", fileIndex));
				if (!File.Exists(indexPath))
				{
					indexPath = null;
				}
			}

			if (path == null)
			{
				staticsPath = Files.GetFilePath("statics{0}.mul", fileIndex);
			}
			else
			{
				staticsPath = Path.Combine(path, String.Format("statics{0}.mul", fileIndex));
				if (!File.Exists(staticsPath))
				{
					staticsPath = null;
				}
			}

			EmptyStaticBlock = new HuedTile[8][][];

			for (int i = 0; i < 8; ++i)
			{
				EmptyStaticBlock[i] = new HuedTile[8][];

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

			InvalidLandBlock = new Tile[196];

			m_LandTiles = new Tile[BlockWidth][][];
			m_StaticTiles = new HuedTile[BlockWidth][][][][];

			Patch = new TileMatrixPatch(this, mapID, path);
		}
Exemplo 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),
                              fsIndex = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                using (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 gc = GCHandle.Alloc(tiles, GCHandleType.Pinned);
                        try
                        {
                            if (m_Buffer == null || m_Buffer.Length < 192)
                                m_Buffer = new byte[192];

                            fsData.Read(m_Buffer, 0, 192);

                            Marshal.Copy(m_Buffer, 0, gc.AddrOfPinnedObject(), 192);
                        }
                        finally
                        {
                            gc.Free();
                        }
                        if (LandBlocks[x] == null)
                            LandBlocks[x] = new Tile[matrix.BlockHeight][];
                        LandBlocks[x][y] = tiles;
                    }
                    return count;
                }
            }
        }
Exemplo n.º 14
0
        public Tile[] GetLandBlock( int x, int y )
        {
            if ( x < 0 || y < 0 || x >= m_BlockWidth || y >= m_BlockHeight || m_Map == null ) return m_InvalidLandBlock;

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

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

            if ( tiles == null )
                tiles = m_LandTiles[x][y] = ReadLandBlock( x, y );

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

            Tile[] tiles = new Tile[64];

            fixed ( Tile *pTiles = tiles )
            {
                _lread(m_Map.Handle, pTiles, 192);
            }

            return tiles;
        }
Exemplo n.º 16
0
        private unsafe Tile[] ReadLandBlock(int x, int y)
        {
            if (m_Map == null || !m_Map.CanRead || !m_Map.CanSeek)
            {
                if (mapPath == null)
                    m_Map = null;
                else
                    m_Map = new FileStream(mapPath, FileMode.Open, FileAccess.Read, FileShare.Read);
            }
            Tile[] tiles = new Tile[64];
            if (m_Map != null)
            {
                m_Map.Seek(((x * BlockHeight) + y) * 196 + 4, SeekOrigin.Begin);

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

                    m_Map.Read(m_Buffer, 0, 192);

                    Marshal.Copy(m_Buffer, 0, gc.AddrOfPinnedObject(), 192);
                }
                finally
                {
                    gc.Free();
                }
                //m_Map.Close();
            }

            return tiles;
        }
Exemplo n.º 17
0
        public TileMatrix(int fileIndex, int mapID, int width, int height, string path)
        {
            Width = width;
            Height = height;
            BlockWidth = width >> 3;
            BlockHeight = height >> 3;

            if (path == null)
                mapPath = Files.GetFilePath("map{0}.mul", fileIndex);
            else
            {
                mapPath = Path.Combine(path, String.Format("map{0}.mul", fileIndex));
                if (!File.Exists(mapPath))
                    mapPath = null;
            }

            if (path == null)
                indexPath = Files.GetFilePath("staidx{0}.mul", fileIndex);
            else
            {
                indexPath = Path.Combine(path, String.Format("staidx{0}.mul", fileIndex));
                if (!File.Exists(indexPath))
                    indexPath = null;
            }

            if (path == null)
                staticsPath = Files.GetFilePath("statics{0}.mul", fileIndex);
            else
            {
                staticsPath = Path.Combine(path, String.Format("statics{0}.mul", fileIndex));
                if (!File.Exists(staticsPath))
                    staticsPath = null;
            }

            EmptyStaticBlock = new HuedTile[8][][];

            for (int i = 0; i < 8; ++i)
            {
                EmptyStaticBlock[i] = new HuedTile[8][];

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

            InvalidLandBlock = new Tile[196];

            m_LandTiles = new Tile[BlockWidth][][];
            m_StaticTiles = new HuedTile[BlockWidth][][][][];

            Patch = new TileMatrixPatch(this, mapID, path);
        }
Exemplo n.º 18
0
        private void button3_Click(object sender, EventArgs e)
        {
            Ultima.Tile mytile = new Ultima.Tile();

            //mytile = tm.GetLandTile(2563, 489);
            int mytileid = (mytile.ID & 0x3FFF);
               // uonet.display(""+mytileid);

            Ultima.Tile mytile2 = new Ultima.Tile();
            Ultima.TileMatrix tm = new TileMatrix(0, 0, 6144, 4096);
            HuedTile[] htile = tm.GetStaticTiles(2563, 489);
            int mytileid2 = (htile[0].ID & 0x3FFF); // need a check, exception if ID is 0
            //uonet.display("" + htile[0].ID + "___" + htile[1].ID);

            //mytile2 =

            mytile = tm.GetLandTile(273, 1216);
            //txtOutput.Text = txtOutput.Text + StringList.Table[1076267];
            //txtOutput.Text = txtOutput.Text +
        }
Exemplo n.º 19
0
        /// <summary>
        /// Generate in memmory new Facet from map & statics mul files		
        /// </summary>
        /// <param name="map">source map for generating facet</param>
        /// <param name="algorithm">type of algorithm which will be used for converting map to facet</param>
        public unsafe Facet(Map map, FacetGenAlgorithm algorithm)
        {
            if (map == null)
                throw new ArgumentNullException();

            m_Width = map.Width;
            m_Height = map.Height;
            m_FileIndex = map.FileIndex;
            m_FileName = Files.GetFilePath(String.Format("facet{0:D2}.mul", FileIndex));

            #region FacetGenAlgorithm.UltimaMap
            if (algorithm == FacetGenAlgorithm.UltimaMap)
            {
                Bitmap bmp = map.GetImage(0, 0, Width, Height, true);
                m_Bitmap = bmp.Clone(new Rectangle(0, 0, Width, Height), PixelFormat.Format16bppRgb555);
                bmp.Dispose();
                return;
            }
            #endregion FacetGenAlgorithm.UltimaMap

            m_Bitmap = new Bitmap(Width, Height, PixelFormat.Format16bppRgb555);
            BitmapData data = m_Bitmap.LockBits(new Rectangle(0, 0, Width, Height), ImageLockMode.WriteOnly, PixelFormat.Format16bppRgb555);
            ushort* cur = (ushort*)data.Scan0;
            int stride = data.Stride >> 1;

            switch (algorithm)
            {
                #region FacetGenAlgorithm.Simple
                case FacetGenAlgorithm.Simple:
                    {
                        TileMatrix matrix = new TileMatrix(FileIndex, FileIndex, Width, Height, null);
                        int blocklength = Width >> 3;
                        Tile[][] land = new Tile[blocklength][];
                        HuedTile[][][][] item = new HuedTile[blocklength][][][];
                        HuedTileComparer comparator = new HuedTileComparer();

                        for (int h = 0; h < (Height >> 3); ++h)
                        {
                            for (int b = 0; b < blocklength; ++b)
                            {
                                land[b] = matrix.GetLandBlock(b, h);
                                item[b] = matrix.GetStaticBlock(b, h);
                            }

                            for (int y = 0; y < 8; ++y)
                            {
                                int i = -1;
                                for (int b = 0; b < blocklength; ++b)
                                {
                                    for (int x = 0; x < 8; ++x)
                                    {
                                        Tile landtile = land[b][(y << 3) + x];
                                        HuedTile[] itemtile = item[b][x][y];
                                        if (itemtile == null || itemtile.Length == 0)
                                        {
                                            if (Array.BinarySearch(nodrawland, landtile.ID) < 0)
                                                cur[++i] = (ushort)RadarCol.Colors[landtile.ID];
                                            else
                                                cur[++i] = 0x0000;
                                            continue;
                                        }

                                        Array.Sort(itemtile, comparator);

                                        cur[++i] = itemtile[0].Z < landtile.Z
                                                 ? (ushort)RadarCol.Colors[landtile.ID]
                                                 : (ushort)RadarCol.Colors[0x4000 + itemtile[0].ID];

                                        if (cur[i] == 0x0421 || cur[i] == 0x0000)
                                            if (Array.BinarySearch(nodrawland, landtile.ID) < 0)
                                                cur[++i] = (ushort)RadarCol.Colors[landtile.ID];
                                            else
                                                cur[++i] = 0x0000;
                                    }
                                }
                                cur += stride;
                            }
                        }
                        break;
                    }
                #endregion FacetGenAlgorithm.Simple

                #region FacetGenAlgorithm.AltMask
                case FacetGenAlgorithm.AltMask:
                    {
                        TileMatrix matrix = new TileMatrix(FileIndex, FileIndex, Width, Height, null);
                        int blocklength = Width >> 3;
                        Tile[][] land = new Tile[blocklength][];
                        HuedTile[][][][] item = new HuedTile[blocklength][][][];
                        HuedTileComparer comparator = new HuedTileComparer();

                        for (int h = 0; h < (Height >> 3); ++h)
                        {
                            for (int b = 0; b < blocklength; ++b)
                            {
                                land[b] = matrix.GetLandBlock(b, h);
                                item[b] = matrix.GetStaticBlock(b, h);
                            }

                            matrix.Dispose();

                            for (int y = 0; y < 8; ++y)
                            {
                                int i = -1;
                                for (int b = 0; b < blocklength; ++b)
                                {
                                    for (int x = 0; x < 8; ++x)
                                    {
                                        Tile landtile = land[b][(y << 3) + x];
                                        HuedTile[] itemtile = item[b][x][y];
                                        bool drawland = false;

                                        if (itemtile == null || itemtile.Length == 0)
                                        {
                                            if (Array.BinarySearch(nodrawland, landtile.ID) >= 0)
                                                cur[++i] = 0x0000;
                                            else
                                            {
                                                cur[++i] = (ushort)RadarCol.Colors[landtile.ID];
                                                drawland = true;
                                            }
                                        }
                                        else
                                        {
                                            Array.Sort(itemtile, comparator);

                                            ushort landcolor = (ushort)RadarCol.Colors[landtile.ID];
                                            ushort itemcolor = 0x0000;
                                            int iu = 0;
                                            for (int u = 0; u < itemtile.Length; ++u)
                                            {
                                                iu = u;
                                                if (Array.BinarySearch(nodrawitem, itemtile[u].ID) >= 0)
                                                    continue;
                                                itemcolor = (ushort)RadarCol.Colors[0x4000 + itemtile[u].ID];
                                                if (itemcolor == 0x0000 || itemcolor == 0x0421)
                                                    if ((u + 1 < itemtile.Length) && (itemtile[u].Z >= landtile.Z))
                                                        continue;
                                                    else
                                                    {
                                                        itemcolor = 0x0000;
                                                        break;
                                                    }
                                                break;
                                            }

                                            if (itemcolor == 0x0000 || itemtile[iu].Z < landtile.Z)
                                            {
                                                if (Array.BinarySearch(nodrawland, landtile.ID) >= 0)
                                                    cur[++i] = 0x0000;
                                                else
                                                {
                                                    cur[++i] = landcolor;
                                                    drawland = true;
                                                }
                                            }
                                            else
                                                cur[++i] = itemcolor;
                                        }

                                        if (drawland && ((TileData.LandTable[landtile.ID].Flags & TileFlag.Wet) == 0))
                                        {
                                            short inc = (short)(0 - (landtile.Z / 20));

                                            short maskR = (short)(((cur[i] & 0x7C00) >> 10) + inc);
                                            maskR = Math.Min(Math.Max((short)0x00, maskR), (short)0x1F);
                                            short maskG = (short)(((cur[i] & 0x03E0) >> 5) + inc);
                                            maskG = Math.Min(Math.Max((short)0x00, maskG), (short)0x1F);
                                            short maskB = (short)(((cur[i] & 0x001F) >> 0) + inc);
                                            maskB = Math.Min(Math.Max((short)0x00, maskB), (short)0x1F);

                                            cur[i] = (ushort)((maskR << 10) | (maskG << 5) | (maskB << 0));
                                        }
                                        else
                                        {
                                            ushort maskR = (ushort)((cur[i] & 0x7C00) >> 10);
                                            if (maskR > 0)
                                                --maskR;
                                            ushort maskG = (ushort)((cur[i] & 0x03E0) >> 5);
                                            if (maskG > 0)
                                                --maskG;
                                            ushort maskB = (ushort)((cur[i] & 0x001F) >> 0);
                                            if (maskB > 0)
                                                --maskB;
                                            cur[i] = (ushort)((maskR << 10) | (maskG << 5) | (maskB << 0));
                                        }
                                    }
                                }
                                cur += stride;
                            }
                        }
                        break;
                    }
                #endregion FacetGenAlgorithm.AltMask

                #region FacetGenAlgorithm.AltMaskNoise
                case FacetGenAlgorithm.AltMaskNoise:
                    {
                        Random random = new Random();
                        TileMatrix matrix = new TileMatrix(FileIndex, FileIndex, Width, Height, null);
                        int blocklength = Width >> 3;
                        Tile[][] land = new Tile[blocklength][];
                        HuedTile[][][][] item = new HuedTile[blocklength][][][];
                        HuedTileComparer comparator = new HuedTileComparer();

                        for (int h = 0; h < (Height >> 3); ++h)
                        {
                            for (int b = 0; b < blocklength; ++b)
                            {
                                land[b] = matrix.ReadLandBlock(b, h);
                                item[b] = matrix.ReadStaticBlock(b, h);
                            }

                            for (int y = 0; y < 8; ++y)
                            {
                                int i = -1;
                                for (int b = 0; b < blocklength; ++b)
                                {
                                    for (int x = 0; x < 8; ++x)
                                    {
                                        Tile landtile = land[b][(y << 3) + x];
                                        HuedTile[] itemtile = item[b][x][y];
                                        bool drawland = false;

                                        if (itemtile == null || itemtile.Length == 0)
                                        {
                                            if (Array.BinarySearch(nodrawland, landtile.ID) >= 0)
                                                cur[++i] = 0x0000;
                                            else
                                            {
                                                cur[++i] = (ushort)RadarCol.Colors[landtile.ID];
                                                drawland = true;
                                            }
                                        }
                                        else
                                        {
                                            Array.Sort(itemtile, comparator);

                                            ushort landcolor = (ushort)RadarCol.Colors[landtile.ID];
                                            ushort itemcolor = 0x0000;
                                            int iu = 0;
                                            for (int u = 0; u < itemtile.Length; ++u)
                                            {
                                                iu = u;
                                                if (Array.BinarySearch(nodrawitem, itemtile[u].ID) >= 0)
                                                    continue;
                                                itemcolor = (ushort)RadarCol.Colors[0x4000 + itemtile[u].ID];
                                                if (itemcolor == 0x0000 || itemcolor == 0x0421 )
                                                    if ((u + 1 < itemtile.Length) && (itemtile[u].Z >= landtile.Z))
                                                        continue;
                                                    else
                                                    {
                                                        itemcolor = 0x0000;
                                                        break;
                                                    }
                                                break;
                                            }

                                            if (itemcolor == 0x0000 || itemtile[iu].Z < landtile.Z)
                                            {
                                                if (Array.BinarySearch(nodrawland, landtile.ID) >= 0)
                                                    cur[++i] = 0x0000;
                                                else
                                                {
                                                    cur[++i] = landcolor;
                                                    drawland = true;
                                                }
                                            }
                                            else
                                                cur[++i] = itemcolor;
                                        }

                                        if (drawland && ((TileData.LandTable[landtile.ID].Flags & TileFlag.Wet) == 0))
                                        {
                                            short inc = (short)(0 - (landtile.Z / 25));

                                            short maskR = (short)(((cur[i] & 0x7C00) >> 10) + inc);
                                            short maskG = (short)(((cur[i] & 0x03E0) >> 5) + inc);
                                            short maskB = (short)(((cur[i] & 0x001F) >> 0) + inc);

                                            inc = (short)(random.Next(-1, 2));
                                            maskR += inc;
                                            inc = (short)(random.Next(-1, 2));
                                            maskG += inc;
                                            inc = (short)(random.Next(-1, 2));
                                            maskB += inc;

                                            maskR = Math.Min(Math.Max((short)0x00, maskR), (short)0x1F);
                                            maskG = Math.Min(Math.Max((short)0x00, maskG), (short)0x1F);
                                            maskB = Math.Min(Math.Max((short)0x00, maskB), (short)0x1F);

                                            cur[i] = (ushort)((maskR << 10) | (maskG << 5) | (maskB << 0));
                                        }
                                        else
                                        {
                                            ushort maskR = (ushort)((cur[i] & 0x7C00) >> 10);
                                            if (maskR > 0)
                                                --maskR;
                                            ushort maskG = (ushort)((cur[i] & 0x03E0) >> 5);
                                            if (maskG > 0)
                                                --maskG;
                                            ushort maskB = (ushort)((cur[i] & 0x001F) >> 0);
                                            if (maskB > 0)
                                                --maskB;
                                            cur[i] = (ushort)((maskR << 10) | (maskG << 5) | (maskB << 0));
                                        }
                                    }
                                }
                                cur += stride;
                            }

                        }
                        break;
                    }
                #endregion FacetGenAlgorithm.AltMaskNoise

                #region FacetGenAlgorithm.Improved
                case FacetGenAlgorithm.Improved:
                    {
                        Random random = new Random();
                        TileMatrix matrix = new TileMatrix(FileIndex, FileIndex, Width, Height, null);
                        int blocklength = Width >> 3;
                        Tile[][] land = new Tile[blocklength][];
                        HuedTile[][][][] item = new HuedTile[blocklength][][][];
                        HuedTileComparer comparator = new HuedTileComparer();

                        for (int h = 0; h < (Height >> 3); ++h)
                        {
                            for (int b = 0; b < blocklength; ++b)
                            {
                                land[b] = matrix.GetLandBlock(b, h);
                                item[b] = matrix.GetStaticBlock(b, h);
                            }

                            for (int y = 0; y < 8; ++y)
                            {
                                int i = -1;
                                for (int b = 0; b < blocklength; ++b)
                                {
                                    for (int x = 0; x < 8; ++x)
                                    {
                                        Tile landtile = land[b][(y << 3) + x];
                                        HuedTile[] itemtile = item[b][x][y];
                                        bool drawland = false;

                                        if (itemtile == null || itemtile.Length == 0)
                                        {
                                            cur[++i] = (ushort)RadarCol.Colors[landtile.ID];
                                            drawland = true;
                                        }
                                        else
                                        {
                                            Array.Sort(itemtile, comparator);

                                            ushort landcolor = (ushort)RadarCol.Colors[landtile.ID];
                                            ushort itemcolor = 0x0000;
                                            int iu = 0;
                                            for (int u = 0; u < itemtile.Length; ++u)
                                            {
                                                iu = u;
                                                itemcolor = (ushort)RadarCol.Colors[0x4000 + itemtile[u].ID];
                                                if (itemcolor == 0x0000 || itemcolor == 0x0421)
                                                    if ((u + 1 < itemtile.Length) && (itemtile[u].Z >= landtile.Z))
                                                        continue;
                                                    else
                                                    {
                                                        itemcolor = 0x0000;
                                                        break;
                                                    }
                                                break;
                                            }

                                            if (itemcolor == 0x0000 || itemtile[iu].Z < landtile.Z)
                                            {
                                                cur[++i] = landcolor;
                                                drawland = true;
                                            }
                                            else
                                                cur[++i] = itemcolor;
                                        }

                                        if (drawland)
                                        {
                                            short inc = (short)(0 - (landtile.Z / 20));
                                            //
                                            inc *= 3;
                                            if (inc == 0)
                                                switch (random.Next(0, 2))
                                                {
                                                    case 0: inc = -1; break;
                                                    case 1: inc = 1; break;
                                                }
                                            short dir = (short)((inc >= 0) ? 1 : -1);

                                            short maskR = (short)((cur[i] & 0x7C00) >> 10);
                                            short maskG = (short)((cur[i] & 0x03E0) >> 5);
                                            short maskB = (short)((cur[i] & 0x001F) >> 0);

                                            for (short rand = 0; rand < dir * inc; ++rand)
                                                switch (random.Next(0, 3))
                                                {
                                                    case 0: maskR += dir; break;
                                                    case 1: maskG += dir; break;
                                                    case 2: maskB += dir; break;
                                                }

                                            maskR = Math.Min(Math.Max((short)0x00, maskR), (short)0x1F);
                                            maskG = Math.Min(Math.Max((short)0x00, maskG), (short)0x1F);
                                            maskB = Math.Min(Math.Max((short)0x00, maskB), (short)0x1F);
                                            /*
                                            short maskR = (short)(((cur[i] & 0x7C00) >> 10) + inc);
                                            maskR = Math.Min(Math.Max((short)0x00, maskR), (short)0x1F);
                                            short maskG = (short)(((cur[i] & 0x03E0) >> 5) + inc);
                                            maskG = Math.Min(Math.Max((short)0x00, maskG), (short)0x1F);
                                            short maskB = (short)(((cur[i] & 0x001F) >> 0) + inc);
                                            maskB = Math.Min(Math.Max((short)0x00, maskB), (short)0x1F);
                                            */
                                            cur[i] = (ushort)((maskR << 10) | (maskG << 5) | (maskB << 0));
                                        }
                                        else
                                        {
                                            ushort maskR = (ushort)((cur[i] & 0x7C00) >> 10);
                                            if (maskR > 0)
                                                --maskR;
                                            ushort maskG = (ushort)((cur[i] & 0x03E0) >> 5);
                                            if (maskG > 0)
                                                --maskG;
                                            ushort maskB = (ushort)((cur[i] & 0x001F) >> 0);
                                            if (maskB > 0)
                                                --maskB;
                                            cur[i] = (ushort)((maskR << 10) | (maskG << 5) | (maskB << 0));
                                        }
                                    }
                                }
                                cur += stride;
                            }
                        }
                        break;
                    }
                #endregion FacetGenAlgorithm.Improved
            }

            m_Bitmap.UnlockBits(data);
        }
Exemplo n.º 20
0
		public Tile[] GetLandBlock(int x, int y, bool patch)
		{
			if (x < 0 || y < 0 || x >= BlockWidth || y >= BlockHeight)
			{
				return InvalidLandBlock;
			}

			if (m_LandTiles[x] == null)
			{
				m_LandTiles[x] = new Tile[BlockHeight][];
			}

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

			if (tiles == null)
			{
				tiles = m_LandTiles[x][y] = ReadLandBlock(x, y);
			}

			if ((Map.UseDiff) && (patch))
			{
				if (Patch.LandBlocksCount > 0)
				{
					if (Patch.LandBlocks[x] != null)
					{
						if (Patch.LandBlocks[x][y] != null)
						{
							tiles = Patch.LandBlocks[x][y];
						}
					}
				}
			}
			return tiles;
		}
Exemplo n.º 21
0
        public MultiComponentList( BinaryReader reader, int count )
        {
            m_Min = m_Max = Point.Empty;

            MultiTileEntry[] allTiles = 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 ( 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 Point( -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 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 )
            {
                int xOffset = allTiles[i].m_OffsetX + m_Center.X;
                int yOffset = allTiles[i].m_OffsetY + m_Center.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();

                    if ( m_Tiles[x][y].Length > 1 )
                        Array.Sort( m_Tiles[x][y] );
                }
            }
        }
Exemplo n.º 22
0
		private Tile[] ReadLandBlock(int x, int y)
		{
			if (m_Map == null || !m_Map.CanRead || !m_Map.CanSeek)
			{
				if (mapPath == null)
				{
					m_Map = null;
				}
				else
				{
					m_Map = new FileStream(mapPath, FileMode.Open, FileAccess.Read, FileShare.Read);
				}

				if (IsUOPFormat && mapPath != null && !IsUOPAlreadyRead)
				{
					var fi = new FileInfo(mapPath);
					string uopPattern = fi.Name.Replace(fi.Extension, "").ToLowerInvariant();

					ReadUOPFiles(uopPattern);
					IsUOPAlreadyRead = true;
				}
			}
			var tiles = new Tile[64];
			if (m_Map != null)
			{
				long offset = ((x * BlockHeight) + y) * 196 + 4;

				if (IsUOPFormat)
				{
					offset = CalculateOffsetFromUOP(offset);
				}

				m_Map.Seek(offset, SeekOrigin.Begin);

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

					m_Map.Read(m_Buffer, 0, 192);

					Marshal.Copy(m_Buffer, 0, gc.AddrOfPinnedObject(), 192);
				}
				finally
				{
					gc.Free();
				}
				//m_Map.Close();
			}

			return tiles;
		}
Exemplo n.º 23
0
		public void SetLandBlock(int x, int y, Tile[] value)
		{
			if (x < 0 || y < 0 || x >= BlockWidth || y >= BlockHeight)
			{
				return;
			}

			if (m_LandTiles[x] == null)
			{
				m_LandTiles[x] = new Tile[BlockHeight][];
			}

			m_LandTiles[x][y] = value;
		}
 private Tile[] ReadLandBlock(int x, int y)
 {
     unsafe
     {
         this.m_Map.Seek((long)((x * this.m_BlockHeight + y) * 196 + 4), SeekOrigin.Begin);
         Tile[] tileArray = new Tile[64];
         fixed (Tile* tilePointer = &tileArray[0])
         {
             TileMatrix._lread(this.m_Map.Handle, tilePointer, 192);
         }
         return tileArray;
     }
 }