示例#1
0
        private unsafe int PatchLand(TileMatrix tileMatrix, string dataPath, string indexPath)
        {
            using (FileStream fsData = FileManager.GetFile(dataPath))
            {
                using (FileStream fsIndex = FileManager.GetFile(indexPath))
                {
                    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 / tileMatrix.BlockHeight;
                        int y = blockID % tileMatrix.BlockHeight;

                        fsData.Seek(4, SeekOrigin.Current);

                        Tile[] tiles = new Tile[64];

                        fixed (Tile* pTiles = tiles)
                        {
                            SharedMethods.Read(fsData.SafeFileHandle, pTiles, 192);
                        }

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

                    indexReader.Close();

                    return count;
                }
            }
        }
示例#2
0
 public TileMatrixPatch(TileMatrix matrix, int index)
 {
     string path = Path.Combine(Engine.FileManager.FilePath, string.Format("mapdif{0}.mul", index));
     string str2 = Path.Combine(Engine.FileManager.FilePath, string.Format("mapdifl{0}.mul", index));
     if (File.Exists(path) && File.Exists(str2))
     {
         this.m_LandData = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
         using (FileStream stream = new FileStream(str2, FileMode.Open, FileAccess.Read, FileShare.Read))
         {
             this.m_LandBlockRefs = this.SlurpRefs(matrix.BlockWidth, matrix.BlockHeight, stream);
         }
     }
     string str3 = Path.Combine(Engine.FileManager.FilePath, string.Format("stadif{0}.mul", index));
     string str4 = Path.Combine(Engine.FileManager.FilePath, string.Format("stadifl{0}.mul", index));
     string str5 = Path.Combine(Engine.FileManager.FilePath, string.Format("stadifi{0}.mul", index));
     if ((File.Exists(str3) && File.Exists(str4)) && File.Exists(str5))
     {
         this.m_StaticData = new FileStream(str3, FileMode.Open, FileAccess.Read, FileShare.Read);
         this.m_StaticLookup = new FileStream(str5, FileMode.Open, FileAccess.Read, FileShare.Read);
         this.m_StaticLookupReader = new BinaryReader(this.m_StaticLookup);
         using (FileStream stream2 = new FileStream(str4, FileMode.Open, FileAccess.Read, FileShare.Read))
         {
             this.m_StaticBlockRefs = this.SlurpRefs(matrix.BlockWidth, matrix.BlockHeight, stream2);
         }
     }
 }
示例#3
0
 public Map(InstallLocation install, int fileIndex, int mapID, int width, int height)
 {
     m_FileIndex = fileIndex;
     m_MapID = mapID;
     m_Width = width;
     m_Height = height;
     m_Tiles = new TileMatrix(install, m_FileIndex, m_MapID, m_Width, m_Height);
 }
示例#4
0
        public TileMatrixPatch(TileMatrix matrix, int index)
        {
            if (!m_Enabled)
            {
                return;
            }

            m_LandBlocks = PatchLand(matrix, String.Format("mapdif{0}.mul", index), String.Format("mapdifl{0}.mul", index));
            m_StaticBlocks = PatchStatics(matrix, String.Format("stadif{0}.mul", index), String.Format("stadifl{0}.mul", index), String.Format("stadifi{0}.mul", index));
        }
        public static TileMatrixProperties GetProperties(TileMatrix matrix)
        {
            switch (matrix)
            {
                case TileMatrix.Items1X1:
                    {
                        var prop = new TileMatrixProperties();
                        prop.Width = 128;
                        prop.Height = 128;

                        prop.TilesPerRow = 1;
                        prop.TilesPerColumn = 1;

                        prop.TileWidth = prop.Width / prop.TilesPerRow;
                        prop.TileHeight = prop.Height / prop.TilesPerColumn;
                        return prop;
                    }
                case TileMatrix.Items8X8:
                    {
                        var prop = new TileMatrixProperties();
                        prop.Width = 1024;
                        prop.Height = 1024;

                        prop.TilesPerRow = 8;
                        prop.TilesPerColumn = 8;

                        prop.TileWidth = prop.Width / prop.TilesPerRow;
                        prop.TileHeight = prop.Height / prop.TilesPerColumn;
                        return prop;
                    }
                case TileMatrix.Items8X16:
                    {
                        var prop = new TileMatrixProperties();
                        prop.Width = 1024;
                        prop.Height = 2048;

                        prop.TilesPerRow = 8;
                        prop.TilesPerColumn = 16;

                        prop.TileWidth = prop.Width / prop.TilesPerRow;
                        prop.TileHeight = prop.Height / prop.TilesPerColumn;
                        return prop;
                    }
            }

            return null;
        }
        public void Create(string name, TileMatrix matrix)
        {
            if (!_targets.ContainsKey(name))
            {
                TileMatrixProperties prop = GetProperties(matrix);

                _targets.Add(name, new RenderTarget2D(_device, prop.Width, prop.Height, false, SurfaceFormat.Color, DepthFormat.Depth24));

                RenderTarget2D target = _targets[name];

                _device.SetRenderTarget(target);
                _device.Clear(Color.Transparent);
                _device.SetRenderTarget(null);

                _targets[name] = target;
            }
            else
                throw new Exception("Target '" + name + "' already exist");
        }
        private Vector2 GetIndex(TileMatrix matrix, int index)
        {
            TileMatrixProperties prop = GetProperties(matrix);

            return new Vector2(index % prop.TilesPerRow, index / prop.TilesPerRow);
        }
示例#8
0
        private unsafe int PatchStatics(TileMatrix tileMatrix, string dataPath, string indexPath, string lookupPath)
        {
            using (FileStream fsData = FileManager.GetFile(dataPath))
            {
                using (FileStream fsIndex = FileManager.GetFile(indexPath))
                {
                    using (FileStream fsLookup = FileManager.GetFile(lookupPath))
                    {
                        BinaryReader indexReader = new BinaryReader(fsIndex);
                        BinaryReader lookupReader = new BinaryReader(fsLookup);

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

                        StaticTileList[][] lists = new StaticTileList[8][];

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

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

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

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

                            if (offset < 0 || length <= 0)
                            {
                                tileMatrix.SetStaticBlock(blockX, blockY, tileMatrix.EmptyStaticsBlock);

                                continue;
                            }

                            fsData.Seek(offset, SeekOrigin.Begin);

                            int tileCount = length / 7;

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

                            StaticTile[] staticTiles = m_TileBuffer;

                            fixed (StaticTile* pStaticTiles = staticTiles)
                            {
                                SharedMethods.Read(fsData.SafeFileHandle, pStaticTiles, length);

                                StaticTile* pCur = pStaticTiles, pEnd = pStaticTiles + tileCount;

                                while (pCur < pEnd)
                                {
                                    lists[pCur->X & 0x07][pCur->Y & 0x07].Add((short)((pCur->ID & 0x3FFF) + 0x4000), pCur->Z);

                                    pCur = pCur + 1;
                                }

                                StaticTile[][][] tiles = new StaticTile[8][][];

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

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

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

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

                        return count;
                    }
                }
            }
        }
示例#9
0
 public static void QueueMapLoad(int xBlock, int yBlock, TileMatrix matrix)
 {
     if (((xBlock >= 0) && (yBlock >= 0)) && ((xBlock < matrix.BlockWidth) && (yBlock < matrix.BlockHeight)))
     {
         int num = (xBlock * 0x200) + yBlock;
         bool ghost = false;
         Mobile player = World.Player;
         if (player != null)
         {
             ghost = player.Ghost;
         }
         if (!matrix.CheckLoaded(xBlock, yBlock))
         {
             m_MapLoadQueue.Enqueue(new Worker(xBlock, yBlock, matrix));
         }
     }
 }
示例#10
0
 public Worker(int X, int Y, TileMatrix Matrix)
 {
     this.X = X;
     this.Y = Y;
     this.Matrix = Matrix;
 }
示例#11
0
        public static void OnSave(WorldSaveEventArgs e)
        {
            if (!Directory.Exists(UltimaLiveSettings.UltimaLiveMapChangesSavePath))
            {
                Directory.CreateDirectory(UltimaLiveSettings.UltimaLiveMapChangesSavePath);
            }

            DateTime now   = DateTime.Now;
            string   Stamp = string.Format("{0}-{1}-{2}-{3}-{4}-{5}", now.Year, now.Month.ToString("00"), now.Day.ToString("00"), now.Hour.ToString("00"), now.Minute.ToString("00"), now.Second.ToString("00"));

            foreach (KeyValuePair <int, MapRegistry.MapDefinition> kvp in MapRegistry.Definitions)
            //for (int mapIndex = 0; mapIndex < Live.NumberOfMapFiles; mapIndex++)
            {
                try
                {
                    Map        CurrentMap    = Server.Map.Maps[kvp.Key];
                    TileMatrix CurrentMatrix = CurrentMap.Tiles;

                    ICollection keyColl = m_LandChanges[kvp.Key].Keys;
                    if (keyColl.Count > 0)
                    {
                        string filename = string.Format("map{0}-{1}.live", kvp.Key, Stamp);
                        Console.WriteLine(Path.Combine(UltimaLiveSettings.UltimaLiveMapChangesSavePath, filename));
                        GenericWriter writer = new BinaryFileWriter(Path.Combine(UltimaLiveSettings.UltimaLiveMapChangesSavePath, filename), true);
                        writer.Write((UInt16)kvp.Key);

                        foreach (Point2D p in keyColl)
                        {
                            writer.Write((UInt16)p.X);
                            writer.Write((UInt16)p.Y);
                            LandTile[] blocktiles = CurrentMatrix.GetLandBlock(p.X, p.Y);
                            for (int j = 0; j < 64; j++)
                            {
                                writer.Write((UInt16)blocktiles[j].ID);
                                writer.Write((sbyte)blocktiles[j].Z);
                            }
                        }
                        writer.Close();
                    }
                    m_LandChanges[kvp.Key].Clear();

                    keyColl = m_StaticsChanges[kvp.Key].Keys;
                    if (keyColl.Count > 0)
                    {
                        string        filename = string.Format("statics{0}-{1}.live", kvp.Key, Stamp);
                        GenericWriter writer   = new BinaryFileWriter(Path.Combine(UltimaLiveSettings.UltimaLiveMapChangesSavePath, filename), true);
                        writer.Write((UInt16)kvp.Key);

                        foreach (Point2D p in keyColl)
                        {
                            StaticTile[][][] staticTiles = CurrentMatrix.GetStaticBlock(p.X, p.Y);

                            int staticCount = 0;
                            for (int i = 0; i < staticTiles.Length; i++)
                            {
                                for (int j = 0; j < staticTiles[i].Length; j++)
                                {
                                    staticCount += staticTiles[i][j].Length;
                                }
                            }

                            writer.Write((UInt16)p.X);
                            writer.Write((UInt16)p.Y);
                            writer.Write((int)staticCount);

                            for (int i = 0; i < staticTiles.Length; i++)
                            {
                                for (int j = 0; j < staticTiles[i].Length; j++)
                                {
                                    for (int k = 0; k < staticTiles[i][j].Length; k++)
                                    {
                                        writer.Write((ushort)staticTiles[i][j][k].ID);
                                        writer.Write((byte)i);
                                        writer.Write((byte)j);
                                        writer.Write((sbyte)staticTiles[i][j][k].Z);
                                        writer.Write((short)staticTiles[i][j][k].Hue);
                                    }
                                }
                            }
                        }
                        writer.Close();
                    }
                    m_StaticsChanges[kvp.Key].Clear();
                }
                catch
                {
                    Console.WriteLine("Key: " + kvp.Key);
                }
            }
        }
示例#12
0
        private void GenerateMesh(QuadTreeNode tile)
        {
            var data = DataByTile[tile];

            TileMatrix tileMatrix    = ElevationTileMatrixSet[tile.Depth];
            int        MeshDimension = (int)tileMatrix.TileWidth;

            CartesianBounds cartesianBounds = tile.GeographicBounds.TransformedWith(Projection);
            double          spacingX        = (cartesianBounds.MaximumCoordinates.X - cartesianBounds.MinimumCoordinates.X) / tileMatrix.TileWidth;
            double          spacingY        = (cartesianBounds.MaximumCoordinates.Y - cartesianBounds.MinimumCoordinates.Y) / tileMatrix.TileHeight;
            double          originX         = cartesianBounds.MinimumCoordinates.X;
            double          originY         = cartesianBounds.MinimumCoordinates.Y;

            // vertices
            {
                data.vertices = new Vector3[MeshDimension * MeshDimension];
                int vertexIndex = 0;
                for (int row = 0; row < MeshDimension; ++row)
                {
                    for (int column = 0; column < MeshDimension; ++column, ++vertexIndex)
                    {
                        data.vertices[vertexIndex] = new Vector3((float)(originX + (column * spacingX)), 0.0f, (float)(originY + (row * spacingY)));
                    }
                }
            }

            // triangles
            {
                data.triangles = new int[(MeshDimension - 1) * (MeshDimension - 1) * 6];
                int triangleIndex = 0;
                for (int row = 0; row < (MeshDimension - 1); ++row)
                {
                    for (int column = 0; column < (MeshDimension - 1); ++column, triangleIndex += 6)
                    {
                        int vertexIndex = (row * MeshDimension) + column;

                        int lowerLeftIndex  = vertexIndex;
                        int lowerRightIndex = lowerLeftIndex + 1;
                        int upperLeftIndex  = lowerLeftIndex + MeshDimension;
                        int upperRightIndex = upperLeftIndex + 1;

                        data.triangles[triangleIndex + 0] = lowerLeftIndex;
                        data.triangles[triangleIndex + 1] = upperLeftIndex;
                        data.triangles[triangleIndex + 2] = upperRightIndex;

                        data.triangles[triangleIndex + 3] = lowerLeftIndex;
                        data.triangles[triangleIndex + 4] = upperRightIndex;
                        data.triangles[triangleIndex + 5] = lowerRightIndex;
                    }
                }
            }

            // uvs
            {
                data.uv = new Vector2[data.vertices.Length];
                int vertexIndex = 0;
                for (int row = 0; row < MeshDimension; ++row)
                {
                    for (int column = 0; column < MeshDimension; ++column, ++vertexIndex)
                    {
                        data.uv[vertexIndex] = new Vector2((float)column / (MeshDimension - 1), (float)row / (MeshDimension - 1));
                    }
                }
            }
        }
示例#13
0
        public static void OnLoad()
        {
            Console.WriteLine("Loading Ultima Live map changes");

            if (!Directory.Exists(UltimaLiveSettings.UltimaLiveMapChangesSavePath))
            {
                Directory.CreateDirectory(UltimaLiveSettings.UltimaLiveMapChangesSavePath);
            }

            string[]      filePaths    = Directory.GetFiles(UltimaLiveSettings.UltimaLiveMapChangesSavePath, "*.live");
            List <string> staticsPaths = new List <string>();
            List <string> landPaths    = new List <string>();

            foreach (string s in filePaths)
            {
                if (s.Contains("map"))
                {
                    landPaths.Add(s);
                }
                else if (s.Contains("statics"))
                {
                    staticsPaths.Add(s);
                }
            }

            landPaths.Sort();

            //read map blocks and apply them in order
            foreach (string s in landPaths)
            {
                BinaryReader reader = new BinaryReader(File.Open(Path.Combine(Core.BaseDirectory, s), FileMode.Open));
                try
                {
                    reader.BaseStream.Seek(0, SeekOrigin.Begin);
                    int MapNumber = reader.ReadUInt16();

                    while (reader.BaseStream.Position < reader.BaseStream.Length)
                    {
                        int        x          = (int)reader.ReadInt16();
                        int        y          = (int)reader.ReadInt16();
                        LandTile[] blocktiles = new LandTile[64];

                        for (int j = 0; j < 64; j++)
                        {
                            short    id = reader.ReadInt16();
                            sbyte    z  = reader.ReadSByte();
                            LandTile lt = new LandTile(id, z);
                            blocktiles[j] = lt;
                        }

                        List <int> associated;
                        MapRegistry.MapAssociations.TryGetValue(MapNumber, out associated);
                        foreach (int integer in associated)
                        {
                            Map        map = Map.Maps[integer];
                            TileMatrix tm  = map.Tiles;
                            tm.SetLandBlock(x, y, blocktiles);
                        }
                    }
                }
                catch
                {
                    Console.WriteLine("An error occured reading land changes at " + reader.BaseStream.Position);
                }
                finally
                {
                    reader.Close();
                }
            }


            staticsPaths.Sort();
            //read statics blocks and apply them in order
            foreach (string s in staticsPaths)
            {
                FileInfo     mapFile = new FileInfo(Path.Combine(Core.BaseDirectory, s));
                BinaryReader reader  = new BinaryReader(File.Open(Path.Combine(Core.BaseDirectory, s), FileMode.Open));
                try
                {
                    reader.BaseStream.Seek(0, SeekOrigin.Begin);
                    int MapNumber = reader.ReadUInt16();

                    while (reader.BaseStream.Position < reader.BaseStream.Length)
                    {
                        int blockX      = (int)reader.ReadInt16();
                        int blockY      = (int)reader.ReadInt16();
                        int staticCount = reader.ReadInt32();

                        Dictionary <Point2D, List <StaticTile> > blockStatics = new Dictionary <Point2D, List <StaticTile> >();

                        for (int staticIndex = 0; staticIndex < staticCount; staticIndex++)
                        {
                            UInt16     id  = reader.ReadUInt16();
                            byte       x   = reader.ReadByte();
                            byte       y   = reader.ReadByte();
                            sbyte      z   = reader.ReadSByte();
                            Int16      hue = reader.ReadInt16();
                            StaticTile st  = new StaticTile(id, x, y, z, hue);

                            Point2D p = new Point2D(x, y);
                            if (!(blockStatics.ContainsKey(p)))
                            {
                                blockStatics.Add(p, new List <StaticTile>());
                            }
                            blockStatics[p].Add(st);
                        }

                        StaticTile[][][] newblockOfTiles = new StaticTile[8][][];

                        for (int i = 0; i < 8; i++)
                        {
                            newblockOfTiles[i] = new StaticTile[8][];
                            for (int j = 0; j < 8; j++)
                            {
                                Point2D p      = new Point2D(i, j);
                                int     length = 0;
                                if (blockStatics.ContainsKey(p))
                                {
                                    length = blockStatics[p].Count;
                                }
                                newblockOfTiles[i][j] = new StaticTile[length];
                                for (int k = 0; k < length; k++)
                                {
                                    if (blockStatics.ContainsKey(p))
                                    {
                                        newblockOfTiles[i][j][k] = blockStatics[p][k];
                                    }
                                }
                            }
                        }

                        List <int> associated;
                        MapRegistry.MapAssociations.TryGetValue(MapNumber, out associated);
                        foreach (int integer in associated)
                        {
                            Map        map = Map.Maps[integer];
                            TileMatrix tm  = map.Tiles;
                            tm.SetStaticBlock(blockX, blockY, newblockOfTiles);
                        }
                    }
                }
                catch
                {
                    Console.WriteLine("An error occured reading land changes.");
                }
                finally
                {
                    reader.Close();
                }
            }
        }
示例#14
0
        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);

            TileMatrix matrix = Parameters.CurrentMap.Tiles;

            bool tilesHighlite   = false;
            bool R_tilesHighlite = false;

            pe.Graphics.Clear(Color.Black);
            MapCoordinates = new Dictionary <Rectangle, Point>();

            for (int x = 0; x < TileWidth; x++)
            {
                for (int y = 0; y < TileWidth; y++)
                {
                    int upperX = x * ScaledSize;
                    int upperY = y * ScaledSize;

                    Bitmap bmp = Cache.GetTile(matrix.GetLandTile(_Upper_Coordinate.X + x, _Upper_Coordinate.Y + y).ID, (int)MapScale);

                    if (bmp == null)
                    {
                        bmp = new Bitmap(ScaledSize, ScaledSize);
                        Graphics g = Graphics.FromImage(bmp);
                        g.Clear(Color.Black);
                        g.Dispose();
                    }

                    Rectangle area = new Rectangle(upperX, upperY, ScaledSize, ScaledSize);

                    if (_HighlightedArea.Contains(_Upper_Coordinate.X + x, _Upper_Coordinate.Y + y))
                    {
                        tilesHighlite = true;
                    }
                    else
                    {
                        tilesHighlite = false;
                    }

                    foreach (Rectangle rect in _HighlightedRegion)
                    {
                        if (rect.Contains(_Upper_Coordinate.X + x, _Upper_Coordinate.Y + y))
                        {
                            R_tilesHighlite = true;

                            break;
                        }
                        else
                        {
                            R_tilesHighlite = false;
                        }
                    }

                    pe.Graphics.DrawImage(bmp, upperX, upperY);

                    if (MapScale >= Scaling.Scale10)
                    {
                        pe.Graphics.DrawRectangle(new Pen(Color.FromArgb(150, Color.Black)), area);
                    }
                    else
                    {
                        pe.Graphics.DrawRectangle(new Pen(Color.FromArgb(100, Color.Black)), area);
                    }

                    if (tilesHighlite)
                    {
                        pe.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(100, Color.Yellow)), area);
                    }

                    if (R_tilesHighlite)
                    {
                        pe.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(100, Color.Red)), area);
                    }

                    MapCoordinates[area] = new Point(_Upper_Coordinate.X + x, _Upper_Coordinate.Y + y);
                }
            }
        }
示例#15
0
        private void button3_Click(object sender, EventArgs e)
        {
            string newPath = Application.ExecutablePath.Substring(0, Application.ExecutablePath.LastIndexOf('\\'));

            newPath += @"\Created\";

            if (!Directory.Exists(newPath))
            {
                Directory.CreateDirectory(newPath);
            }
            TileMatrix tm = new TileMatrix(0, 0, 6144, 4096);
            TransTable tt = new TransTable();

            for (int BlockX = 0; BlockX < 96; BlockX++)
            {
                for (int BlockY = 0; BlockY < 64; BlockY++)
                {
                    int BlockID  = BlockX * 64 + BlockY + 1;
                    int firstID  = BlockID / 100;
                    int secondID = BlockID - firstID * 100;
                    BlockID--;
                    String       filename = newPath + "facet0_" + firstID + "_" + secondID + ".dat";
                    BinaryWriter bw       = new BinaryWriter(File.Create(filename));
                    Tile         t;
                    HuedTile[]   ht;
                    bool         overlap = false;
                    for (int X = BlockX * 64; X < (BlockX + 1) * 64; X++)
                    {
                        for (int Y = BlockY * 64; Y < (BlockY + 1) * 64; Y++)
                        {
                            t = tm.GetLandTile(X, Y);
                            if (!overlap)
                            {
                                bw.Write((byte)0);
                            }
                            else
                            {
                                overlap = false;
                            }
                            if (bw.BaseStream.Position == 1)
                            {
                                bw.Write((UInt16)BlockID);
                            }
                            else
                            {
                                bw.Write((UInt16)0);
                            }
                            bw.Write((SByte)t.Z);
                            bw.Write((UInt16)tt[t.ID]);
                            bw.Write(UopParser.Flip((UInt16)t.ID));
                            AddDelimiters(bw, BlockX, BlockY, X, Y);
                            ht = tm.GetStaticTiles(X, Y);
                            if (ht != null)
                            {
                                for (int i = 0; i < ht.Length; i++)
                                {
                                    if (!overlap)
                                    {
                                        bw.Write((byte)0);
                                    }
                                    else
                                    {
                                        overlap = false;
                                    }
                                    bw.Write((byte)0);
                                    if (i == 0)
                                    {
                                        bw.Write((byte)ht.Length);
                                    }
                                    else
                                    {
                                        bw.Write((byte)0);
                                    }
                                    bw.Write((UInt16)ht[i].ID);
                                    bw.Write((UInt16)0);
                                    bw.Write((sbyte)ht[i].Z);
                                    bw.Write((UInt16)ht[i].Hue);
                                    overlap = true;
                                }
                            }
                        }
                    }
                    bw.Write(new byte[] { 0, 0, 0 });
                    bw.Close();
                }
            }
        }
示例#16
0
    public static void LiveFreeze(Mobile from, Map targetMap, Point3D start3d, Point3D end3d)
    {
      Dictionary<Point2D, List<Item>> ItemsByBlockLocation = new Dictionary<Point2D, List<Item>>();
      if (targetMap != null && start3d != NullP3D && end3d != NullP3D)
      {
        Point2D start = targetMap.Bound(new Point2D(start3d));
        Point2D end = targetMap.Bound(new Point2D(end3d));
        IPooledEnumerable eable = targetMap.GetItemsInBounds(new Rectangle2D(start.X, start.Y, end.X - start.X + 1, end.Y - start.Y + 1));

        Console.WriteLine(string.Format("Invoking live freeze from {0},{1} to {2},{3}", start.X, start.Y, end.X, end.Y));

        foreach (Item item in eable)
        {
          if (item is Static || item is BaseFloor || item is BaseWall)
          {
            Map itemMap = item.Map;
            if (itemMap == null || itemMap == Map.Internal)
              continue;

            Point2D p = new Point2D(item.X >> 3, item.Y >> 3);
            if (!(ItemsByBlockLocation.ContainsKey(p)))
            {
              ItemsByBlockLocation.Add(p, new List<Item>());
            }
            ItemsByBlockLocation[p].Add(item);
          }
        }

        eable.Free();
      }
      else
      {
        from.SendMessage("That was not a proper area. Please retarget and reissue the command.");
        return;
      }

      TileMatrix matrix = targetMap.Tiles;
      foreach (KeyValuePair<Point2D, List<Item>> kvp in ItemsByBlockLocation)
      {
        StaticTile[][][] blockOfTiles = matrix.GetStaticBlock(kvp.Key.X, kvp.Key.Y);
        Dictionary<Point2D, List<StaticTile>> newBlockStatics = new Dictionary<Point2D, List<StaticTile>>();

        foreach (Item item in kvp.Value)
        {
          int xOffset = item.X - (kvp.Key.X * 8);
          int yOffset = item.Y - (kvp.Key.Y * 8);
          if (xOffset < 0 || xOffset >= 8 || yOffset < 0 || yOffset >= 8)
            continue;

          StaticTile newTile = new StaticTile((ushort)item.ItemID, (byte)xOffset, (byte)yOffset, (sbyte)item.Z, (short)item.Hue);
          Point2D refPoint = new Point2D(xOffset, yOffset);

          if (!(newBlockStatics.ContainsKey(refPoint)))
          {
            newBlockStatics.Add(refPoint, new List<StaticTile>());
          }

          newBlockStatics[refPoint].Add(newTile);
          item.Delete();
        }

        for (int i = 0; i < blockOfTiles.Length; i++)
          for (int j = 0; j < blockOfTiles[i].Length; j++)
            for (int k = 0; k < blockOfTiles[i][j].Length; k++)
            {
              Point2D refPoint = new Point2D(i, j);
              if (!(newBlockStatics.ContainsKey(refPoint)))
              {
                newBlockStatics.Add(refPoint, new List<StaticTile>());
              }

              newBlockStatics[refPoint].Add(blockOfTiles[i][j][k]);
            }

        StaticTile[][][] newblockOfTiles = new StaticTile[8][][];

        for (int i = 0; i < 8; i++)
        {
          newblockOfTiles[i] = new StaticTile[8][];
          for (int j = 0; j < 8; j++)
          {
            Point2D p = new Point2D(i, j);
            int length = 0;
            if (newBlockStatics.ContainsKey(p))
            {
              length = newBlockStatics[p].Count;
            }
            newblockOfTiles[i][j] = new StaticTile[length];
            for (int k = 0; k < length; k++)
            {
              if (newBlockStatics.ContainsKey(p))
              {
                newblockOfTiles[i][j][k] = newBlockStatics[p][k];
              }
            }
          }
        }

        matrix.SetStaticBlock(kvp.Key.X, kvp.Key.Y, newblockOfTiles);
        int blockNum = ((kvp.Key.X * matrix.BlockHeight) + kvp.Key.Y);

        List<Mobile> candidates = new List<Mobile>();
        int bX = kvp.Key.X * 8;
        int bY = kvp.Key.Y * 8;

        IPooledEnumerable eable = targetMap.GetMobilesInRange(new Point3D(bX, bY, 0));

        foreach (Mobile m in eable)
        {
          if (m.Player)
          {
            candidates.Add(m);
          }
        }
        eable.Free();

        CRC.InvalidateBlockCRC(targetMap.MapID, blockNum);
        foreach (Mobile m in candidates)
        {
          m.Send(new UpdateStaticsPacket(new Point2D(kvp.Key.X, kvp.Key.Y), m));
        }
        MapChangeTracker.MarkStaticsBlockForSave(targetMap.MapID, kvp.Key);
      }
    }
        public static void OnSave(WorldSaveEventArgs e)
        {
            if (!ExportOnNextSave)
            {
                return;
            }

            ExportOnNextSave = false;

            if (!Directory.Exists(UltimaLiveSettings.UltimaLiveClientExportPath))
            {
                Directory.CreateDirectory(UltimaLiveSettings.UltimaLiveClientExportPath);
            }

            Console.Write("Exporting Client Files...");

            /* maps */
            // public static Dictionary<int, MapDefinition> Definitions
            foreach (KeyValuePair <int, MapRegistry.MapDefinition> kvp in MapRegistry.Definitions)
            {
                if (!MapRegistry.MapAssociations.ContainsKey(kvp.Key))
                {
                    continue;
                }

                string        filename = string.Format("map{0}.mul", kvp.Key);
                GenericWriter writer   = new BinaryFileWriter(Path.Combine(UltimaLiveSettings.UltimaLiveClientExportPath, filename), true);
                m_WorkMap = Server.Map.Maps[kvp.Key];
                TileMatrix CurrentMatrix = m_WorkMap.Tiles;
                int        blocks        = CurrentMatrix.BlockWidth * CurrentMatrix.BlockHeight;
                for (int xblock = 0; xblock < CurrentMatrix.BlockWidth; xblock++)
                {
                    for (int yblock = 0; yblock < CurrentMatrix.BlockHeight; yblock++)
                    {
                        writer.Write((uint)0);
                        LandTile[] blocktiles = CurrentMatrix.GetLandBlock(xblock, yblock);
                        if (blocktiles.Length == 196)
                        {
                            Console.WriteLine("Invalid landblock! Save failed!");
                            return;
                        }
                        else
                        {
                            for (int j = 0; j < 64; j++)
                            {
                                writer.Write((short)blocktiles[j].ID);
                                writer.Write((sbyte)blocktiles[j].Z);
                            }
                        }
                    }
                }
                writer.Close();
            }

            /* Statics */
            foreach (KeyValuePair <int, MapRegistry.MapDefinition> kvp in MapRegistry.Definitions)
            {
                if (!MapRegistry.MapAssociations.ContainsKey(kvp.Key))
                {
                    continue;
                }

                string        filename     = string.Format("statics{0}.mul", kvp.Key);
                GenericWriter staticWriter = new BinaryFileWriter(Path.Combine(UltimaLiveSettings.UltimaLiveClientExportPath, filename), true);
                filename = string.Format("staidx{0}.mul", kvp.Key);
                GenericWriter staticIndexWriter = new BinaryFileWriter(Path.Combine(UltimaLiveSettings.UltimaLiveClientExportPath, filename), true);

                m_WorkMap = Server.Map.Maps[kvp.Key];
                TileMatrix CurrentMatrix = m_WorkMap.Tiles;

                int blocks = CurrentMatrix.BlockWidth * CurrentMatrix.BlockHeight;

                int startBlock  = 0;
                int finishBlock = 0;

                for (int xblock = 0; xblock < CurrentMatrix.BlockWidth; xblock++)
                {
                    for (int yblock = 0; yblock < CurrentMatrix.BlockHeight; yblock++)
                    {
                        StaticTile[][][] staticTiles = CurrentMatrix.GetStaticBlock(xblock, yblock);

                        //Static File
                        for (int i = 0; i < staticTiles.Length; i++)
                        {
                            for (int j = 0; j < staticTiles[i].Length; j++)
                            {
                                StaticTile[] sortedTiles = staticTiles[i][j];
                                Array.Sort(sortedTiles, BlockUtility.CompareStaticTiles);

                                for (int k = 0; k < sortedTiles.Length; k++)
                                {
                                    staticWriter.Write((ushort)sortedTiles[k].ID);
                                    staticWriter.Write((byte)i);
                                    staticWriter.Write((byte)j);
                                    staticWriter.Write((sbyte)sortedTiles[k].Z);
                                    staticWriter.Write((short)sortedTiles[k].Hue);
                                    finishBlock += 7;
                                }
                            }
                        }

                        //Index File
                        if (finishBlock != startBlock)
                        {
                            staticIndexWriter.Write((int)startBlock);                 //lookup
                            staticIndexWriter.Write((int)(finishBlock - startBlock)); //length
                            staticIndexWriter.Write((int)0);                          //extra
                            startBlock = finishBlock;
                        }
                        else
                        {
                            staticIndexWriter.Write((uint)uint.MaxValue); //lookup
                            staticIndexWriter.Write((uint)uint.MaxValue); //length
                            staticIndexWriter.Write((uint)uint.MaxValue); //extra
                        }
                    }
                }
                staticWriter.Close();
                staticIndexWriter.Close();
            }
        }
示例#18
0
        public void Add(string name, TileMatrix matrix, int index, Texture2D texture)
        {
            if (!_targets.ContainsKey(name))
                throw new Exception("Target '" + name + "' does not exist");

            if( memoryErrorOccured )
                return;

            try
            {
                RenderTarget2D target = _targets[name];
                TileMatrixProperties prop = GetProperties(matrix);

                var tmpTarget = new RenderTarget2D(_device, prop.Width, prop.Height, false, SurfaceFormat.Color, DepthFormat.Depth24);
                Vector2 pos = GetIndex(matrix, index);

                _device.SetRenderTarget(tmpTarget);

                _device.Clear(Color.Transparent);

                try
                {
                    using (var spriteBatch = new SpriteBatch(_device))
                    {
                        spriteBatch.Begin();
                        spriteBatch.Draw(target, Vector2.Zero, Color.White);
                        spriteBatch.Draw(texture, new Rectangle((int)pos.X * prop.TileWidth, (int)pos.Y * prop.TileHeight, prop.TileWidth, prop.TileHeight), null, Color.White);
                        spriteBatch.End();
                    }
                }
                catch { }

                target.Dispose();
                target = null;

                _device.SetRenderTarget(null);

                _targets[name] = null;
                _targets[name] = tmpTarget;
                //tmpTarget.Dispose();
                //tmpTarget = null;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error during Texture generation: " + GC.GetTotalMemory(true) + ", " + GC.CollectionCount(0), "Error");
                memoryErrorOccured = true;
            }
        }
        private void ShowMapButton_Click(object sender, EventArgs e)
        {
            try { Application.OpenForms["MapViewer"].Close(); }
            catch { }

            MapViewer DWM = new MapViewer();

            if (RenderedMaps[facetList.SelectedIndex] == null)
            {
                TileMatrix matrix = Parameters.CurrentMap.Tiles;

                Bitmap bmp = new Bitmap(Parameters.CurrentMap.Width, Parameters.CurrentMap.Height);

                renderProgress.Visible = true;
                renderProgress.Value   = 0;
                renderProgress.Maximum = bmp.Width;

                for (int x = 0; x < Parameters.CurrentMap.Width; x++)
                {
                    for (int y = 0; y < Parameters.CurrentMap.Height; y++)
                    {
                        bmp.SetPixel(x, y, Cache.GetColor(matrix.GetLandTile(x, y).ID));
                    }

                    renderProgress.Increment(1);
                }

                renderProgress.Visible = false;

                bmp.Save(String.Format("Map{0}.bmp", facetList.SelectedIndex));
                RenderedMaps[facetList.SelectedIndex] = bmp;
            }

            if (RenderedMaps[facetList.SelectedIndex] != null)
            {
                DWM.Editor = this;

                System.Drawing.Size size = new System.Drawing.Size(RenderedMaps[facetList.SelectedIndex].Width, RenderedMaps[facetList.SelectedIndex].Height);

                int reductionPercentage = 100;

                while ((size.Width > Screen.GetWorkingArea(DWM).Width - 100 || size.Height > Screen.GetWorkingArea(DWM).Height - 100) && reductionPercentage > 0)
                {
                    double reduction = (double)reductionPercentage * 0.01;

                    size.Width  = (int)((double)RenderedMaps[facetList.SelectedIndex].Width * reduction);
                    size.Height = (int)((double)RenderedMaps[facetList.SelectedIndex].Height * reduction);

                    reductionPercentage -= 1;
                }

                size.Width  += 6;
                size.Height += 51;

                DWM.Location = new Point((Screen.PrimaryScreen.WorkingArea.Width - size.Width) / 2, (Screen.PrimaryScreen.WorkingArea.Height - size.Height) / 2);
                DWM.Size     = size;

                Bitmap   newBMP = new Bitmap(DWM.mapImage.Width, DWM.mapImage.Height);
                Graphics g      = Graphics.FromImage(newBMP);
                g.DrawImage(RenderedMaps[facetList.SelectedIndex], 0, 0, DWM.mapImage.Width, DWM.mapImage.Height);
                g.Dispose();

                DWM.mapImage.Image = newBMP;
                DWM.Show();
                DWM.Focus();
                DWM.Select();
            }
        }