示例#1
0
        private static NavGrid ReadData(NavBinaryReader b)
        {
            var grid = new NavGrid
            {
                MajorVersion = b.GetBinaryReader().ReadByte()
            };

            if (grid.MajorVersion != 2)
            {
                grid.MinorVersion = b.GetBinaryReader().ReadInt16();
            }

            grid           = ReadStandardNavGridHeader(b, grid);
            grid.Cells     = new NavGridCell[grid.XCellCount * grid.YCellCount];
            grid.CellFlags = new ushort[grid.XCellCount * grid.YCellCount];

            if (grid.MajorVersion == 0x02 || grid.MajorVersion == 0x03 || grid.MajorVersion == 0x05)
            {
                // Read cells, total size: 0x38 * XCellCount * YCellCount bytes

                for (var i = 0; i < grid.Cells.Length; i++)
                {
                    grid.Cells[i]    = b.ReadGridCell_Version5(out grid.CellFlags[i]);
                    grid.Cells[i].Id = i;
                }

                grid.XSampledHeightCount = b.GetBinaryReader().ReadInt32();
                grid.YSampledHeightCount = b.GetBinaryReader().ReadInt32();

                //should be mXSampledHeightDist
                grid.DirectionX = b.GetBinaryReader().ReadSingle();
                //should be mYSampledHeightDist
                grid.DirectionY = b.GetBinaryReader().ReadSingle();
            }
            else if (grid.MajorVersion == 0x07)
            {
                // Read cells, total size: 0x30 * XCellCount * YCellCount bytes

                for (var i = 0; i < grid.Cells.Length; i++)
                {
                    grid.Cells[i]    = b.ReadGridCell_Version7();
                    grid.Cells[i].Id = i;
                }

                for (var i = 0; i < grid.Cells.Length; i++)
                {
                    grid.CellFlags[i] = b.GetBinaryReader().ReadUInt16();
                }
            }
            else
            {
                throw new Exception($"Magic number at the start is unsupported! Value: {grid.MajorVersion:X}");
            }

            grid.MapWidth    = grid.MaxGridPos.X + grid.MinGridPos.X;
            grid.MapHeight   = grid.MaxGridPos.Z + grid.MinGridPos.Z;
            grid.MiddleOfMap = new Vector2(grid.MapWidth / 2, grid.MapHeight / 2);
            grid.InitializePathfinding();
            return(grid);
        }
示例#2
0
        private static NavGrid ReadStandardNavGridHeader(NavBinaryReader b, NavGrid grid)
        {
            grid.MinGridPos = b.ReadVector3();
            grid.MaxGridPos = b.ReadVector3();

            grid.CellSize   = b.GetBinaryReader().ReadSingle();
            grid.XCellCount = b.GetBinaryReader().ReadUInt32();
            grid.YCellCount = b.GetBinaryReader().ReadUInt32();

            return(grid);
        }
示例#3
0
 public bool HasFlag(NavGrid grid, NavigationGridCellFlags flag)
 {
     return(grid.HasFlag(Id, flag));
 }