MapServer.GameMap.Create C# (CSharp) Method

Create() public method

public Create ( ) : bool
return bool
        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;
        }

Usage Example

示例#1
0
        private bool LoadGameMapInfo()
        {
            String text = mPacket.LoadFileToText(TextDefine.CONFIG_FILE_MAP);
            CsvFile csv = new CsvFile(text);

            String v;
            if (text == "") return false;
            for (int i = 0; i < csv.GetLine(); i++)
            {
                GameStruct.MapInfo info = new GameStruct.MapInfo();
                v = csv.GetFieldInfoToValue(i, "id");
                info.id = Convert.ToUInt32(v);
                info.name = csv.GetFieldInfoToValue(i, "name");
                info.dmappath = csv.GetFieldInfoToValue(i, "dmap");
                v = csv.GetFieldInfoToValue(i, "recallid");
                info.recallid = Convert.ToUInt32(v);
                v = csv.GetFieldInfoToValue(i, "recallx");
                info.recallx = Convert.ToUInt16(v);
                v = csv.GetFieldInfoToValue(i, "recally");
                info.recally = Convert.ToUInt16(v);
                v = csv.GetFieldInfoToValue(i, "snows");
                info.issnows = Convert.ToBoolean(v);
                //加入到地图
                GameMap map = new GameMap(info);
                if (!map.Create())
                {
                    Log.Instance().WriteLog("加载地图失败.." + info.name);
                }
                MapManager.Instance().AddMap(map);

            }
            return true;
        }