Esempio n. 1
0
 public Map(string name, MapInfo mapInfo)
 {
     Name = name;
     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);
     StartPos[] positions = mapInfo.Positions;
     Positions = new Point[mapInfo.PosCount];
     for (int i = 0; i < mapInfo.PosCount; i++) {
         Positions[i] = new Point(positions[i].X, positions[i].Z);
     }
     HumanName = GetHumanName(name);
 }
 public MapInfo GetMapInfo(uint checksum, int mapInfoVersion)
 {
     if (disposed) {
         throw new ObjectDisposedException("Unitsync has already been released.");
     }
     string mapName = maps[checksum];
     if (!mapName.ToLower().EndsWith(".smf") && !(mapName.ToLower().EndsWith(".sm3"))) {
         throw new ArgumentException("Map name is invalid, must end with \".smf\" or \".sm3\".");
     }
     if (!new[] {0, 1}.Contains(mapInfoVersion)) {
         throw new ArgumentOutOfRangeException("mapInfoVersion", "must be 0 or 1.");
     }
     if (!GetMapNames().ContainsValue(mapName)) {
         throw new UnitSyncException(String.Format("Map not found ({0}).", mapName));
     }
     var mapInfo = new MapInfo
     {
         // make buffers
         Author = new String(' ', AuthorBufferSize),
         Description = new String(' ', DescriptionBufferSize)
     };
     if (!NativeMethods.GetMapInfoEx(mapName, ref mapInfo, mapInfoVersion)) {
         throw new UnitSyncException("Error getting map information.");
     }
     TestMapInfo(mapInfo);
     return mapInfo;
 }
Esempio n. 3
0
 public Map(string name, MapInfo mapInfo, uint? checksum) : this(name, mapInfo)
 {
     Checksum = checksum;
 }
 static void TestMapInfo(MapInfo mapInfo)
 {
     if (mapInfo.Description == null) {
         throw new UnitSyncException("Null description.");
     }
     if (mapInfo.Description.StartsWith("Parse error")) {
         throw new UnitSyncException("Parse error. This usually means the map is broken.");
     }
     if (mapInfo.Description.EndsWith("not found")) {
         throw new UnitSyncException("Map file not found. This usually means the map is broken.");
     }
     if (mapInfo.Width <= 0 || mapInfo.Height <= 0) {
         throw new UnitSyncException(
             String.Format("Invalid map size. ({0}, {1})", mapInfo.Width, mapInfo.Height));
     }
     StartPos[] positions = mapInfo.Positions;
     if (positions == null) {
         throw new UnitSyncException("Error in loading start positions.");
     }
     if (mapInfo.ExtractorRadius < 0) {
         throw new UnitSyncException(String.Format("Invalid extractor radius ({0}).", mapInfo.ExtractorRadius));
     }
     if (mapInfo.Gravity < 0) {
         throw new UnitSyncException(String.Format("Invalid gravity ({0}).", mapInfo.Gravity));
     }
     if (mapInfo.MaxMetal < 0) {
         throw new UnitSyncException(string.Format("Invalid maximum metal ({0}).", mapInfo.MaxMetal));
     }
     if (mapInfo.MaxWind < 0) {
         throw new UnitSyncException(string.Format("Invalid maximum wind ({0}).", mapInfo.MaxWind));
     }
     if (mapInfo.MinWind < 0) {
         throw new UnitSyncException(string.Format("Invalid minimum wind ({0}).", mapInfo.MinWind));
     }
     if (mapInfo.MinWind > mapInfo.MaxWind) {
         throw new UnitSyncException(
             string.Format(
                 "Minimum wind is higher than maximum wind ({0}, {1})", mapInfo.MinWind, mapInfo.MaxWind));
     }
     if (mapInfo.TidalStrength < 0) {
         throw new UnitSyncException(string.Format("Invalid tidal strength ({0}).", mapInfo.TidalStrength));
     }
 }