diff --git a/lib/rmg/CMapGenerator.cpp b/lib/rmg/CMapGenerator.cpp index b0dbcbec5..cb03ecd1a 100644 --- a/lib/rmg/CMapGenerator.cpp +++ b/lib/rmg/CMapGenerator.cpp @@ -211,27 +211,15 @@ void CMapGenerator::genZones() auto w = mapGenOptions->getWidth(); auto h = mapGenOptions->getHeight(); - auto tmpl = mapGenOptions->getMapTemplate(); zones = tmpl->getZones(); //copy from template (refactor?) - int player_per_side = zones.size() > 4 ? 3 : 2; - - logGlobal->infoStream() << boost::format("Map size %d %d, players per side %d") % w % h % player_per_side; - CZonePlacer placer(this); placer.placeZones(mapGenOptions, &rand); placer.assignZones(mapGenOptions); int i = 0; - for(auto const it : zones) - { - CRmgTemplateZone * zone = it.second; - zone->setType(i < pcnt ? ETemplateZoneType::PLAYER_START : ETemplateZoneType::TREASURE); - this->zones[it.first] = zone; - ++i; - } logGlobal->infoStream() << "Zones generated successfully"; } @@ -484,7 +472,13 @@ float CMapGenerator::getNearestObjectDistance(const int3 &tile) const int CMapGenerator::getNextMonlithIndex() { if (monolithIndex >= VLC->objtypeh->knownSubObjects(Obj::MONOLITH_TWO_WAY).size()) - throw rmgException(boost::to_string(boost::format("There is no Monolith Two Way with index %d available!") % monolithIndex)); + { + logGlobal->errorStream() << boost::to_string(boost::format("RMG Error! There is no Monolith Two Way with index %d available!") % monolithIndex); + monolithIndex++; + return VLC->objtypeh->knownSubObjects(Obj::MONOLITH_TWO_WAY).size() - 1; + //TODO: interrupt map generation and report error + //throw rmgException(boost::to_string(boost::format("There is no Monolith Two Way with index %d available!") % monolithIndex)); + } else return monolithIndex++; } diff --git a/lib/rmg/CRmgTemplateStorage.cpp b/lib/rmg/CRmgTemplateStorage.cpp index b45c67a27..e896ed32b 100644 --- a/lib/rmg/CRmgTemplateStorage.cpp +++ b/lib/rmg/CRmgTemplateStorage.cpp @@ -63,7 +63,9 @@ void CJsonRmgTemplateLoader::loadTemplates() if (!zoneNode["matchTerrainToTown"].isNull()) //default : true zone->setMatchTerrainToTown(zoneNode["matchTerrainToTown"].Bool()); zone->setTerrainTypes(parseTerrainTypes(zoneNode["terrainTypes"].Vector(), zone->getDefaultTerrainTypes())); - zone->setTownsAreSameType((zoneNode["townsAreSameType"].Bool())); + + if (!zoneNode["townsAreSameType"].isNull()) //default : false + zone->setTownsAreSameType((zoneNode["townsAreSameType"].Bool())); for (int i = 0; i < 2; ++i) { @@ -80,8 +82,7 @@ void CJsonRmgTemplateLoader::loadTemplates() for (const JsonNode & allowedTown : zoneNode[i ? "allowedTowns" : "allowedMonsters"].Vector()) { //complain if the town type is not present in our game - boost::optional id = VLC->modh->identifiers.getIdentifier("faction", allowedTown, false); - if (id.is_initialized()) + if (auto id = VLC->modh->identifiers.getIdentifier("faction", allowedTown, false)) allowedTownTypes.insert(id.get()); } } @@ -91,8 +92,7 @@ void CJsonRmgTemplateLoader::loadTemplates() for (const JsonNode & bannedTown : zoneNode[i ? "bannedTowns" : "bannedMonsters"].Vector()) { //erase unindentified towns silently - boost::optional id = VLC->modh->identifiers.getIdentifier("faction", bannedTown, true); - if (id.is_initialized()) + if (auto id = VLC->modh->identifiers.getIdentifier("faction", bannedTown, true)) vstd::erase_if_present(allowedTownTypes, id.get()); } } @@ -172,7 +172,11 @@ void CJsonRmgTemplateLoader::loadTemplates() const auto & zoneNode = zonePair.second; if (!zoneNode["terrainTypeLikeZone"].isNull()) - zone->setTerrainTypes (zones[zoneNode["terrainTypeLikeZone"].Float()]->getTerrainTypes()); + { + int id = zoneNode["terrainTypeLikeZone"].Float(); + zone->setTerrainTypes(zones[id]->getTerrainTypes()); + zone->setMatchTerrainToTown(zones[id]->getMatchTerrainToTown()); + } if (!zoneNode["townTypeLikeZone"].isNull()) zone->setTownTypes (zones[zoneNode["townTypeLikeZone"].Float()]->getTownTypes());