public MapRegisteredEventArgs(string mapName, Map map, byte[] minimap, byte[] metalMap, byte[] heightMap, byte[] serializedData)
 {
     MapName = mapName;
     Map = map;
     Minimap = minimap;
     MetalMap = metalMap;
     HeightMap = heightMap;
     SerializedData = serializedData;
 }
 private Map GetMapNoBitmaps(ResourceInfo ae)
 {
     NativeMethods.RemoveAllArchives();
     NativeMethods.GetMapCount();
     NativeMethods.AddAllArchives(ae.Name);
     var mapInfo = GetMapInfo(ae, DefaultMapInfoVersion);
     var map = new Map(ae)
     {
         TidalStrength = mapInfo.tidalStrength,
         Gravity = mapInfo.gravity,
         MaxMetal = mapInfo.maxMetal,
         ExtractorRadius = mapInfo.extractorRadius,
         MinWind = mapInfo.minWind,
         MaxWind = mapInfo.maxWind,
         Size = new Size(mapInfo.width, mapInfo.height),
         Positions = mapInfo.positions,
     };
     map.Options = GetMapOptions(map.Name, map.ArchiveName).ToArray();
     NativeMethods.RemoveAllArchives();
     TraceErrors();
     return map;
 }
        private static Bitmap FixAspectRatio(Map map, Image squareMinimap)
        {
            var newSize = map.Size.Width > map.Size.Height
                ? new Size(squareMinimap.Width, (int)(squareMinimap.Height / ((float)map.Size.Width / map.Size.Height)))
                : new Size((int)(squareMinimap.Width * ((float)map.Size.Width / map.Size.Height)), squareMinimap.Height);

            var correctMinimap = new Bitmap(newSize.Width, newSize.Height, PixelFormat.Format24bppRgb);
            using (var graphics = Graphics.FromImage(correctMinimap))
            {
                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                graphics.DrawImage(squareMinimap, new Rectangle(Point.Empty, newSize));
            }
            squareMinimap.Dispose();
            return correctMinimap;
        }
 public Bitmap GetMinimap(Map map)
 {
     return FixAspectRatio(map, GetSquareMinimap(map.Name, 0));
 }
 private void Set_MapImages(string mapName, int mapView)
 {
     //Program.ToolTip.SetMap(minimapBox, mapName);
     Program.ToolTip.SetMap(map_comboBox, mapName);
     string springVersion = (engine_comboBox.SelectedItem != null) ? (string)engine_comboBox.SelectedItem : null;
     // todo add check before calling invoke invokes!!!
     Program.SpringScanner.MetaData.GetMapAsync(mapName,
                                                (map, minimap, heightmap, metalmap) => Program.MainWindow.InvokeFunc(() =>
                                                {
                                                    if (map == null) return;
                                                    currentMap = map;
                                                    if (mapView == 1) minimap = heightmap;
                                                    else if (mapView == 2) minimap = metalmap;
                                                    if (minimap == null || minimap.Length == 0)
                                                    {
                                                         minimapBox.Image = null;
                                                        this.minimap = null;
                                                    }
                                                    else
                                                    {
                                                        this.minimap = Image.FromStream(new MemoryStream(minimap));
                                                        minimapSize = map.Size;
                                                        requestMinimapRefresh = true; //Refresh_MinimapImage();
                                                    }
                                                }),
                                                a => Program.MainWindow.InvokeFunc(() =>
                                                { //exceptions
                                                    minimapBox.Image = null;
                                                    minimap = null;
                                                }));
 }
		public Map GetMapNoBitmaps(string mapName, string archiveName)
		{
			if (mapName == null || archiveName == null) return null;
			NativeMethods.RemoveAllArchives();
			var checksum = maps.First(kvp => kvp.Value == mapName).Key;
			var mapInfo = GetMapInfo(checksum);
			var map = new Map(mapName)
			          {
			          	ArchiveName = Path.GetFileName(archiveName),
			          	Name = mapName,
			          	Description = mapInfo.description,
			          	TidalStrength = mapInfo.tidalStrength,
			          	Gravity = mapInfo.gravity,
			          	MaxMetal = mapInfo.maxMetal,
			          	ExtractorRadius = mapInfo.extractorRadius,
			          	MinWind = mapInfo.minWind,
			          	MaxWind = mapInfo.maxWind,
			          	Author = mapInfo.author,
			          	Size = new Size(mapInfo.width, mapInfo.height),
			          	Positions = mapInfo.positions,
			          };
			map.Options = GetMapOptions(map.Name, map.ArchiveName).ToArray();
			NativeMethods.RemoveAllArchives();
			TraceErrors();
			return map;
		}
        public Battle(string engineVersion, string password, int port, int maxplayers, int rank, Map map, string title, Mod mod, BattleDetails details): this()
        {
            if (!String.IsNullOrEmpty(password)) Password = password;
            if (port == 0) HostPort = 8452; else HostPort = port;
            try {
                var ports = IPGlobalProperties.GetIPGlobalProperties().GetActiveUdpListeners().OrderBy(x => x.Port).Select(x=>x.Port).ToList();
                if (ports.Contains(HostPort)) {
                    var blockedPort = HostPort;
                    while (ports.Contains(HostPort)) HostPort++;
                    Trace.TraceWarning("Host port {0} was used, using backup port {1}", blockedPort, HostPort);
                }
            } catch {}




            EngineVersion = engineVersion;
            MaxPlayers = maxplayers;
            Rank = rank;
            this.map = map;
            MapName = map.Name;
            MapHash = 0;
            Title = title;
            this.mod = mod;
            ModName = mod.Name;
            ModHash = 0;
            if (details != null) Details = details;
        }
 public void SetMapTooltipRenderer(string mapName)
 {
     this.mapName = mapName;
     Program.SpringScanner.MetaData.GetMapAsync(mapName, (map, minimap, heightmap, metalmap) => { this.map = map; }, (exc) => { });
 }