1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-31 22:05:10 +02:00

- Fixed several legacy issues with map templates

- Added Clash of Dragons 1.2 template
- Temporarily disabled exception when RMG runs out of two-way monoliths (exception was not handled anyway)
This commit is contained in:
DjWarmonger 2014-10-30 21:23:25 +01:00
parent ce83db0f43
commit 697e42dd24
2 changed files with 17 additions and 19 deletions

View File

@ -211,27 +211,15 @@ void CMapGenerator::genZones()
auto w = mapGenOptions->getWidth(); auto w = mapGenOptions->getWidth();
auto h = mapGenOptions->getHeight(); auto h = mapGenOptions->getHeight();
auto tmpl = mapGenOptions->getMapTemplate(); auto tmpl = mapGenOptions->getMapTemplate();
zones = tmpl->getZones(); //copy from template (refactor?) 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); CZonePlacer placer(this);
placer.placeZones(mapGenOptions, &rand); placer.placeZones(mapGenOptions, &rand);
placer.assignZones(mapGenOptions); placer.assignZones(mapGenOptions);
int i = 0; 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"; logGlobal->infoStream() << "Zones generated successfully";
} }
@ -484,7 +472,13 @@ float CMapGenerator::getNearestObjectDistance(const int3 &tile) const
int CMapGenerator::getNextMonlithIndex() int CMapGenerator::getNextMonlithIndex()
{ {
if (monolithIndex >= VLC->objtypeh->knownSubObjects(Obj::MONOLITH_TWO_WAY).size()) 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 else
return monolithIndex++; return monolithIndex++;
} }

View File

@ -63,7 +63,9 @@ void CJsonRmgTemplateLoader::loadTemplates()
if (!zoneNode["matchTerrainToTown"].isNull()) //default : true if (!zoneNode["matchTerrainToTown"].isNull()) //default : true
zone->setMatchTerrainToTown(zoneNode["matchTerrainToTown"].Bool()); zone->setMatchTerrainToTown(zoneNode["matchTerrainToTown"].Bool());
zone->setTerrainTypes(parseTerrainTypes(zoneNode["terrainTypes"].Vector(), zone->getDefaultTerrainTypes())); 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) for (int i = 0; i < 2; ++i)
{ {
@ -80,8 +82,7 @@ void CJsonRmgTemplateLoader::loadTemplates()
for (const JsonNode & allowedTown : zoneNode[i ? "allowedTowns" : "allowedMonsters"].Vector()) for (const JsonNode & allowedTown : zoneNode[i ? "allowedTowns" : "allowedMonsters"].Vector())
{ {
//complain if the town type is not present in our game //complain if the town type is not present in our game
boost::optional<si32> id = VLC->modh->identifiers.getIdentifier("faction", allowedTown, false); if (auto id = VLC->modh->identifiers.getIdentifier("faction", allowedTown, false))
if (id.is_initialized())
allowedTownTypes.insert(id.get()); allowedTownTypes.insert(id.get());
} }
} }
@ -91,8 +92,7 @@ void CJsonRmgTemplateLoader::loadTemplates()
for (const JsonNode & bannedTown : zoneNode[i ? "bannedTowns" : "bannedMonsters"].Vector()) for (const JsonNode & bannedTown : zoneNode[i ? "bannedTowns" : "bannedMonsters"].Vector())
{ {
//erase unindentified towns silently //erase unindentified towns silently
boost::optional<si32> id = VLC->modh->identifiers.getIdentifier("faction", bannedTown, true); if (auto id = VLC->modh->identifiers.getIdentifier("faction", bannedTown, true))
if (id.is_initialized())
vstd::erase_if_present(allowedTownTypes, id.get()); vstd::erase_if_present(allowedTownTypes, id.get());
} }
} }
@ -172,7 +172,11 @@ void CJsonRmgTemplateLoader::loadTemplates()
const auto & zoneNode = zonePair.second; const auto & zoneNode = zonePair.second;
if (!zoneNode["terrainTypeLikeZone"].isNull()) 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()) if (!zoneNode["townTypeLikeZone"].isNull())
zone->setTownTypes (zones[zoneNode["townTypeLikeZone"].Float()]->getTownTypes()); zone->setTownTypes (zones[zoneNode["townTypeLikeZone"].Float()]->getTownTypes());