Esempio n. 1
0
 public Cell(LayerInfo info)
 {
     Accessible = info.Mask == 0;
     Altitude   = info.Altitude;
 }
Esempio n. 2
0
File: GameMap.cs Progetto: Pircs/Yi
        private void LoadDataMap(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException();
            }

            //Load the DMap file...
            using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                uint version; //Currently 1004?
                uint data;

                stream.Read(&version, sizeof(uint));
                stream.Read(&data, sizeof(uint));
                //Console.Add("Version: {0} Data: {1}", Version, Data);

                byte *pFileName = stackalloc byte[MaxPath];
                stream.Read(pFileName, MaxPath);

                //var fullFileName = _folder + new string((sbyte*)pFileName);
                //LoadPuzzle(FullFileName);
                //Console.Add("Puzzle: {0} [{1}]", FullFileName, MAX_PATH);

                fixed(MySize *pMapSize = &_mapSize)
                stream.Read(pMapSize, sizeof(MySize));

                //Console.Add("Width = {0}, Height = {1}", MapSize.Width, MapSize.Height);

                _cells = new Cell[_mapSize.Width, _mapSize.Height];
                for (var i = 0; i < _mapSize.Height; i++)
                {
                    uint checkData = 0;
                    for (var j = 0; j < _mapSize.Width; j++)
                    {
                        var layer = new LayerInfo();

                        stream.Read(&layer.Mask, sizeof(ushort));
                        stream.Read(&layer.Terrain, sizeof(ushort));
                        stream.Read(&layer.Altitude, sizeof(short));
                        checkData += (uint)(layer.Mask * (layer.Terrain + i + 1) + (layer.Altitude + 2) * (j + 1 + layer.Terrain));

                        //Console.Add("Cell({0}, {1}) MASK[{2}] TERRAIN[{3}] ALTITUDE[{4}]", j, i, Layer.Mask, Layer.Terrain, Layer.Altitude);
                        _cells[j, i] = new Cell(layer);
                    }
                    uint mapCheckData;
                    stream.Read(&mapCheckData, sizeof(uint));

                    if (mapCheckData != checkData)
                    {
                        throw new Exception("Map checksum failed!");
                    }
                }

                LoadDataPassage(stream);

                /*if (Version == 1003)
                 *  LoadDataRegion(Stream);*/
                LoadDataLayer(stream);

                //The rest are LAYER_SCENE, but useless for a server. I'll not implement the rest as it would only
                //slow down the loading.
            }
        }