MapFormatSettings.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * MapFormatSettings.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "MapFormatSettings.h"
  12. #include "MapFeaturesH3M.h"
  13. #include "../GameLibrary.h"
  14. #include "../IGameSettings.h"
  15. MapIdentifiersH3M MapFormatSettings::generateMapping(EMapFormat format)
  16. {
  17. auto features = MapFormatFeaturesH3M::find(format, 0);
  18. MapIdentifiersH3M identifierMapper;
  19. if(features.levelROE)
  20. identifierMapper.loadMapping(LIBRARY->engineSettings()->getValue(EGameSettings::MAP_FORMAT_RESTORATION_OF_ERATHIA));
  21. if(features.levelAB)
  22. identifierMapper.loadMapping(LIBRARY->engineSettings()->getValue(EGameSettings::MAP_FORMAT_ARMAGEDDONS_BLADE));
  23. if(features.levelSOD)
  24. identifierMapper.loadMapping(LIBRARY->engineSettings()->getValue(EGameSettings::MAP_FORMAT_SHADOW_OF_DEATH));
  25. if(features.levelCHR)
  26. identifierMapper.loadMapping(LIBRARY->engineSettings()->getValue(EGameSettings::MAP_FORMAT_CHRONICLES));
  27. if(features.levelWOG)
  28. identifierMapper.loadMapping(LIBRARY->engineSettings()->getValue(EGameSettings::MAP_FORMAT_IN_THE_WAKE_OF_GODS));
  29. if(features.levelHOTA0)
  30. identifierMapper.loadMapping(LIBRARY->engineSettings()->getValue(EGameSettings::MAP_FORMAT_HORN_OF_THE_ABYSS));
  31. return identifierMapper;
  32. }
  33. std::map<CampaignVersion, EMapFormat> MapFormatSettings::generateCampaignMapping()
  34. {
  35. return {
  36. {CampaignVersion::RoE, EMapFormat::ROE },
  37. {CampaignVersion::AB, EMapFormat::AB },
  38. {CampaignVersion::SoD, EMapFormat::SOD },
  39. {CampaignVersion::WoG, EMapFormat::WOG },
  40. {CampaignVersion::Chr, EMapFormat::CHR },
  41. {CampaignVersion::HotA, EMapFormat::HOTA}
  42. };
  43. }
  44. std::map<EMapFormat, MapIdentifiersH3M> MapFormatSettings::generateMappings()
  45. {
  46. std::map<EMapFormat, MapIdentifiersH3M> result;
  47. auto addMapping = [&result](EMapFormat format)
  48. {
  49. try
  50. {
  51. result[format] = generateMapping(format);
  52. logMod->trace("Loaded map format support for %d", static_cast<int>(format));
  53. }
  54. catch(const std::runtime_error &)
  55. {
  56. // unsupported map format - skip
  57. logMod->debug("Failed to load map format support for %d", static_cast<int>(format));
  58. }
  59. };
  60. addMapping(EMapFormat::ROE);
  61. addMapping(EMapFormat::AB);
  62. addMapping(EMapFormat::SOD);
  63. addMapping(EMapFormat::CHR);
  64. addMapping(EMapFormat::HOTA);
  65. addMapping(EMapFormat::WOG);
  66. return result;
  67. }
  68. MapFormatSettings::MapFormatSettings()
  69. : mapping(generateMappings())
  70. , campaignToMap(generateCampaignMapping())
  71. {
  72. }
  73. VCMI_LIB_NAMESPACE_END