Пример #1
0
        internal static bool TryLoad(MapId mapId, out Map map)
        {
            map = null;
            var basePath = TerrainDisplayConfig.MapDir;
            var mapPath = Path.Combine(basePath, mapId.ToString());
            var fileName = string.Format("{0}{1}", mapId, Extension);
            var filePath = Path.Combine(mapPath, fileName);

            if (!Directory.Exists(mapPath))
            {
                log.Warn("Unable to find requested .map dir: {0}", mapPath);
                return false;
            }
            if (!File.Exists(filePath))
            {
                log.Warn("Unable to find requested .map file: {0}", filePath);
                return false;
            }

            using(var file = File.OpenRead(filePath))
            {
                map = ReadWDTInfo(file);
                file.Close();

                if (map == null)
                {
                    log.Warn("Unable to load the requested .map file: {0}", filePath);
                    return false;
                }
            }

            map.MapId = mapId;
            return true;
        }
Пример #2
0
        private static Map ReadWDTInfo(Stream file)
        {
            var br = new BinaryReader(file);
            var fileTypeId = br.ReadString();
            if (!fileTypeId.Equals(fileTypeId)) return null;

            var isWMOOnly = br.ReadBoolean();
            var tileProfile = ReadTileProfile(br, isWMOOnly);

            var map = new Map
            {
                IsWMOOnly = isWMOOnly,
                TileProfile = tileProfile
            };
            return map;
        }
Пример #3
0
        /// <summary>
        /// Tries to retrieve/load the map from/into the maps Dictionary.
        /// </summary>
        /// <param name="mapId">The <see cref="WCell.Constants.World.MapId"/> that corresponds to the desired map.</param>
        /// <param name="map">Holder for the Map object to return.</param>
        /// <returns>True if the map was encountered.</returns>
        private bool TryGetMap(MapId mapId, out Map map)
        {
            if (!_maps.TryGetValue(mapId, out map))
            {
                if (!Map.TryLoad(mapId, out map))
                {
                    log.Warn("Unable to load the requested map: {0}", mapId);
                    return false;
                }

                _maps.Add(mapId, map);
            }

            if (map == null)
            {
                log.Warn("Unable to load the requested map. Assuming LOS for now. Map: {0}", mapId);
                return false;
            }

            return true;
        }