public bool Create() { if (info == null) { return(false); } if (!File.Exists(info.dmappath)) { Log.Instance().WriteLog("地图文件不存在:" + info.dmappath); return(false); } FileStream stream = new FileStream(info.dmappath, FileMode.Open); BinaryReader read = new BinaryReader(stream); mnVersion = read.ReadUInt32(); //版本号 uint dwData = read.ReadUInt32(); //附加数据 byte[] b = read.ReadBytes(260); String sPuzPath = System.Text.Encoding.Default.GetString(b); //spul路径 uint nWidth = read.ReadUInt32(); //地图宽度 uint nHeight = read.ReadUInt32(); //地图高度 mnWidth = nWidth; mnHeight = nHeight; mPath = new MapPath(nWidth, nHeight); mMapGridInfo = new GameStruct.MapGridInfo[nWidth, nHeight]; for (uint i = 0; i < nHeight; i++) { uint dwCheckData = 0; for (uint j = 0; j < nWidth; j++) { GameStruct.MapGridInfo grid; ushort usMask = read.ReadUInt16(); //掩码 ushort usTerrain = read.ReadUInt16(); //地形 short sAltitude = read.ReadInt16(); //高度 //校验数据 dwCheckData += usMask * (usTerrain + i + 1) + ((uint)sAltitude + 2) * (j + 1 + usTerrain); grid.Mask = (byte)usMask; //grid.Terrain = usTerrain; //grid.Altitude = sAltitude; mMapGridInfo[j, i] = grid; if (usMask > 0) { mPath.SetPointMask((short)j, (short)i, MapPath.MASK_CLOSE); } } uint dwMapCheckData; dwMapCheckData = read.ReadUInt32(); if (dwMapCheckData != dwCheckData) { Log.Instance().WriteLog("载入地图文件失败..路径:" + info.dmappath); return(false); } } stream.Dispose(); return(true); }
public bool Create() { if (info == null) return false; if (!File.Exists(info.dmappath)) { Log.Instance().WriteLog("地图文件不存在:" + info.dmappath); return false; } FileStream stream = new FileStream(info.dmappath, FileMode.Open); BinaryReader read = new BinaryReader(stream); mnVersion = read.ReadUInt32(); //版本号 uint dwData = read.ReadUInt32(); //附加数据 byte[] b = read.ReadBytes(260); String sPuzPath = System.Text.Encoding.Default.GetString(b); //spul路径 uint nWidth = read.ReadUInt32(); //地图宽度 uint nHeight = read.ReadUInt32(); //地图高度 mnWidth = nWidth; mnHeight = nHeight; mPath = new MapPath(nWidth,nHeight); mMapGridInfo = new GameStruct.MapGridInfo[nWidth, nHeight]; for (uint i = 0; i < nHeight; i++) { uint dwCheckData = 0; for (uint j = 0; j < nWidth; j++) { GameStruct.MapGridInfo grid; ushort usMask = read.ReadUInt16(); //掩码 ushort usTerrain = read.ReadUInt16(); //地形 short sAltitude = read.ReadInt16(); //高度 //校验数据 dwCheckData += usMask * (usTerrain + i + 1) + ((uint)sAltitude + 2) * (j + 1 + usTerrain); grid.Mask = (byte)usMask; //grid.Terrain = usTerrain; //grid.Altitude = sAltitude; mMapGridInfo[j, i] = grid; if(usMask > 0) { mPath.SetPointMask((short)j, (short)i, MapPath.MASK_CLOSE); } } uint dwMapCheckData; dwMapCheckData = read.ReadUInt32(); if (dwMapCheckData != dwCheckData) { Log.Instance().WriteLog("载入地图文件失败..路径:" + info.dmappath); return false; } } stream.Dispose(); return true; }