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 <= 1 || mapInfo.height <= 1) throw new UnitSyncException(String.Format("Invalid map size. ({0}, {1})", mapInfo.width, mapInfo.height)); }
void ProcessMapInfoItem(int index, string key, ref MapInfo info) { switch (key) { case "description": info.description = NativeMethods.GetInfoValueString(index); break; case "author": info.author = NativeMethods.GetInfoValueString(index); break; case "tidalStrength": info.tidalStrength = NativeMethods.GetInfoValueInteger(index); break; case "gravity": info.gravity = NativeMethods.GetInfoValueInteger(index); break; case "maxMetal": info.maxMetal = NativeMethods.GetInfoValueFloat(index); break; case "extractorRadius": info.extractorRadius = NativeMethods.GetInfoValueInteger(index); break; case "minWind": info.minWind = NativeMethods.GetInfoValueInteger(index); break; case "maxWind": info.maxWind = NativeMethods.GetInfoValueInteger(index); break; case "width": info.width = NativeMethods.GetInfoValueInteger(index); break; case "height": info.height = NativeMethods.GetInfoValueInteger(index); break; } }
MapInfo GetMapInfo(uint checksum, int mapInfoVersion) { if (disposed) throw new ObjectDisposedException("Unitsync has already been released."); if (maps == null) GetMapHashes(); if (mapIndices == null) GetMapIndices(); var mapName = maps[checksum]; if (!new[] { 0, 1 }.Contains(mapInfoVersion)) throw new ArgumentOutOfRangeException("mapInfoVersion", "must be 0 or 1."); if (!GetMapHashes().ContainsValue(mapName)) throw new UnitSyncException(String.Format("Map not found ({0}).", mapName)); var mapInfo = new MapInfo { author = new String(' ', AuthorBufferSize), description = new String(' ', DescriptionBufferSize) }; try { int mapIndex = mapIndices[mapName]; int infoItemCount = NativeMethods.GetMapInfoCount(mapIndex); for (int i=0; i < infoItemCount; i++) { string key = NativeMethods.GetInfoKey(i); //string desc = NativeMethods.GetInfoDescription(i); //string type = NativeMethods.GetInfoType(i); //Trace.TraceInformation(String.Format("Unitsync map info: ({0}) key: {1}; type: {2}, desc: {3}", i, key, type, desc)); ProcessMapInfoItem(i, key, ref mapInfo); } } catch (Exception ex) { throw new UnitSyncException(String.Format("Error loading map info for ({0}): {1}", mapName, ex)); } TestMapInfo(mapInfo); return mapInfo; }
MapInfo GetMapInfo(uint checksum, int mapInfoVersion) { if (disposed) throw new ObjectDisposedException("Unitsync has already been released."); if (maps == null) GetMapHashes(); var mapName = maps[checksum]; if (!new[] { 0, 1 }.Contains(mapInfoVersion)) throw new ArgumentOutOfRangeException("mapInfoVersion", "must be 0 or 1."); if (!GetMapHashes().ContainsValue(mapName)) throw new UnitSyncException(String.Format("Map not found ({0}).", mapName)); var mapInfo = new MapInfo { 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; }