/// <summary> /// Performs the actual map download operation. /// </summary> /// <param name="localPath">Local path in the operating system.</param> /// <param name="mapFileName"></param> /// <returns></returns> private static Map DownloadMap(string mapFileName, MasterCommunicator main) { Debugger.Write("Downloading map {0}...", mapFileName); VTankObject.Map map = main.GetProxy().DownloadMap(mapFileName); string title = map.title; int width = map.width; int height = map.height; VTankObject.Tile[] tiles = map.tileData; Tile[] realTiles = new Tile[tiles.Length]; Map newMap = new Map(title, mapFileName, (uint)width, (uint)height); int size = width * height; for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { VTankObject.Tile relevantTile = tiles[y * width + x]; newMap.SetTile((uint)x, (uint)y, new Tile( (uint)relevantTile.id, (ushort)relevantTile.objectId, (ushort)relevantTile.eventId, relevantTile.passable, (ushort)relevantTile.height, (ushort)relevantTile.type, (ushort)relevantTile.effect)); } } List <int> buf = new List <int>(); for (int i = 0; i < map.supportedGameModes.Length; i++) { buf.Add(map.supportedGameModes[i]); } newMap.SetGameModes(buf); return(newMap); }
/// <summary> /// Download the map from Echelon. /// </summary> /// <param name="mapName">Filename of the map to be downloaded.</param> private void DownloadMap(string mapName) { Options options = ServiceManager.Game.Options; Message = String.Format("Downloading map {0}...", mapName); Value = 25; VTankObject.Map map = ServiceManager.Echelon.GetProxy().DownloadMap(mapName); Message = "Reading map..."; Console.WriteLine("Finished downloading map {0}.", map.filename); try { DirectoryInfo directory = new DirectoryInfo(options.MapsFolder); if (!directory.Exists) { directory.Create(); } } catch (Exception) { options.MapsFolder = String.Format(@"{0}\{1}\maps\", Environment.GetEnvironmentVariable("APPDATA"), "VTank"); try { Directory.CreateDirectory(options.MapsFolder); } catch (Exception) { } } Map realMap = new Map( map.title, map.filename, (uint)map.width, (uint)map.height); List <int> buf = new List <int>(); for (int i = 0; i < map.supportedGameModes.Length; i++) { buf.Add(map.supportedGameModes[i]); } realMap.SetGameModes(buf); VTankObject.Tile[] tiles = map.tileData; // Set the tile data. for (uint y = 0; y < (uint)map.height; y++) { for (uint x = 0; x < (uint)map.width; x++) { int position = (int)(y) * map.width + (int)(x); VTankObject.Tile tempTile = tiles[position]; Tile tile = new Tile( (uint)tempTile.id, (ushort)tempTile.objectId, (ushort)tempTile.eventId, tempTile.passable, (ushort)tempTile.height, (ushort)tempTile.type, (ushort)tempTile.effect); realMap.SetTile(x, y, tile); } } try { realMap.SaveMap(options.MapsFolder); } catch (Exception) { options.MapsFolder = String.Format(@"{0}\{1}\maps\", Environment.GetEnvironmentVariable("APPDATA"), "VTank"); try { Directory.CreateDirectory(options.MapsFolder); realMap.SaveMap(options.MapsFolder); } catch (Exception ex) { ServiceManager.Game.Console.DebugPrint("[WARNING] Cannot save map: {0}", ex.Message); } } currentMapInstance = realMap; }