diff --git a/Mods/vcmi/config/vcmi/english.json b/Mods/vcmi/config/vcmi/english.json index 2cb7b5772..600c382c8 100644 --- a/Mods/vcmi/config/vcmi/english.json +++ b/Mods/vcmi/config/vcmi/english.json @@ -60,6 +60,16 @@ "vcmi.radialWheel.moveUp" : "Move up", "vcmi.radialWheel.moveDown" : "Move down", "vcmi.radialWheel.moveBottom" : "Move to bottom", + + "vcmi.randomMap.description" : "Map created by the Random Map Generator.\nTemplate was %s, size %dx%d, levels %d, players %d, computers %d, water %s, monster %s, VCMI map", + "vcmi.randomMap.description.isHuman" : ", %s is human", + "vcmi.randomMap.description.townChoice" : ", %s town choice is %s", + "vcmi.randomMap.description.water.none" : "none", + "vcmi.randomMap.description.water.normal" : "normal", + "vcmi.randomMap.description.water.islands" : "islands", + "vcmi.randomMap.description.monster.weak" : "weak", + "vcmi.randomMap.description.monster.normal" : "normal", + "vcmi.randomMap.description.monster.strong" : "strong", "vcmi.spellBook.search" : "search...", diff --git a/lib/rmg/CMapGenerator.cpp b/lib/rmg/CMapGenerator.cpp index c33a10dd4..f789b78c6 100644 --- a/lib/rmg/CMapGenerator.cpp +++ b/lib/rmg/CMapGenerator.cpp @@ -152,41 +152,55 @@ std::unique_ptr CMapGenerator::generate() return std::move(map->mapInstance); } -std::string CMapGenerator::getMapDescription() const +MetaString CMapGenerator::getMapDescription() const { - assert(map); + const TextIdentifier mainPattern("vcmi", "randomMap", "description"); + const TextIdentifier isHuman("vcmi", "randomMap", "description", "isHuman"); + const TextIdentifier townChoiceIs("vcmi", "randomMap", "description", "townChoice"); + const std::array waterContent = { + TextIdentifier("vcmi", "randomMap", "description", "water", "none"), + TextIdentifier("vcmi", "randomMap", "description", "water", "normal"), + TextIdentifier("vcmi", "randomMap", "description", "water", "islands") + }; + const std::array monsterStrength = { + TextIdentifier("vcmi", "randomMap", "description", "monster", "weak"), + TextIdentifier("vcmi", "randomMap", "description", "monster", "normal"), + TextIdentifier("vcmi", "randomMap", "description", "monster", "strong") + }; - const std::string waterContentStr[3] = { "none", "normal", "islands" }; - const std::string monsterStrengthStr[3] = { "weak", "normal", "strong" }; - - int monsterStrengthIndex = mapGenOptions.getMonsterStrength() - EMonsterStrength::GLOBAL_WEAK; //does not start from 0 const auto * mapTemplate = mapGenOptions.getMapTemplate(); + int monsterStrengthIndex = mapGenOptions.getMonsterStrength() - EMonsterStrength::GLOBAL_WEAK; //does not start from 0 - if(!mapTemplate) - throw rmgException("Map template for Random Map Generator is not found. Could not start the game."); + MetaString result = MetaString::createFromTextID(mainPattern.get()); - std::stringstream ss; - ss << boost::str(boost::format(std::string("Map created by the Random Map Generator.\nTemplate was %s, size %dx%d") + - ", levels %d, players %d, computers %d, water %s, monster %s, VCMI map") % mapTemplate->getName() % - map->width() % map->height() % static_cast(map->levels()) % static_cast(mapGenOptions.getHumanOrCpuPlayerCount()) % - static_cast(mapGenOptions.getCompOnlyPlayerCount()) % waterContentStr[mapGenOptions.getWaterContent()] % - monsterStrengthStr[monsterStrengthIndex]); + result.replaceRawString(mapTemplate->getName()); + result.replaceNumber(map->width()); + result.replaceNumber(map->height()); + result.replaceNumber(map->levels()); + result.replaceNumber(mapGenOptions.getHumanOrCpuPlayerCount()); + result.replaceNumber(mapGenOptions.getCompOnlyPlayerCount()); + result.replaceTextID(waterContent.at(mapGenOptions.getWaterContent()).get()); + result.replaceTextID(monsterStrength.at(monsterStrengthIndex).get()); for(const auto & pair : mapGenOptions.getPlayersSettings()) { const auto & pSettings = pair.second; + if(pSettings.getPlayerType() == EPlayerType::HUMAN) { - ss << ", " << GameConstants::PLAYER_COLOR_NAMES[pSettings.getColor().getNum()] << " is human"; + result.appendTextID(isHuman.get()); + result.replaceName(pSettings.getColor()); } + if(pSettings.getStartingTown() != FactionID::RANDOM) { - ss << ", " << GameConstants::PLAYER_COLOR_NAMES[pSettings.getColor().getNum()] - << " town choice is " << (*VLC->townh)[pSettings.getStartingTown()]->getNameTranslated(); + result.appendTextID(townChoiceIs.get()); + result.replaceName(pSettings.getColor()); + result.replaceName(pSettings.getStartingTown()); } } - return ss.str(); + return result; } void CMapGenerator::addPlayerInfo() @@ -451,7 +465,7 @@ void CMapGenerator::addHeaderInfo() m.height = mapGenOptions.getHeight(); m.twoLevel = mapGenOptions.getHasTwoLevels(); m.name.appendLocalString(EMetaText::GENERAL_TXT, 740); - m.description.appendRawString(getMapDescription()); + m.description = getMapDescription(); m.difficulty = EMapDifficulty::NORMAL; addPlayerInfo(); m.waterMap = (mapGenOptions.getWaterContent() != EWaterContent::EWaterContent::NONE); diff --git a/lib/rmg/CMapGenerator.h b/lib/rmg/CMapGenerator.h index c1971bdba..a635534b6 100644 --- a/lib/rmg/CMapGenerator.h +++ b/lib/rmg/CMapGenerator.h @@ -10,14 +10,12 @@ #pragma once -#include "../GameConstants.h" #include "CMapGenOptions.h" -#include "../int3.h" -#include "CRmgTemplate.h" #include "../LoadProgress.h" VCMI_LIB_NAMESPACE_BEGIN +class MetaString; class CRmgTemplate; class CMapGenOptions; class JsonNode; @@ -93,7 +91,7 @@ private: /// Generation methods void loadConfig(); - std::string getMapDescription() const; + MetaString getMapDescription() const; void initPrisonsRemaining(); void initQuestArtsRemaining(); diff --git a/lib/texts/MetaString.cpp b/lib/texts/MetaString.cpp index 4ed57ce22..dfbf5f57a 100644 --- a/lib/texts/MetaString.cpp +++ b/lib/texts/MetaString.cpp @@ -13,6 +13,7 @@ #include "CArtHandler.h" #include "CCreatureHandler.h" #include "CCreatureSet.h" +#include "entities/faction/CFaction.h" #include "texts/CGeneralTextHandler.h" #include "CSkillHandler.h" #include "GameConstants.h" @@ -387,6 +388,11 @@ void MetaString::replaceName(const ArtifactID & id) replaceTextID(id.toEntity(VLC)->getNameTextID()); } +void MetaString::replaceName(const FactionID & id) +{ + replaceTextID(id.toEntity(VLC)->getNameTextID()); +} + void MetaString::replaceName(const MapObjectID& id) { replaceTextID(VLC->objtypeh->getObjectName(id, 0)); diff --git a/lib/texts/MetaString.h b/lib/texts/MetaString.h index e6ae5fd3f..d55cc279e 100644 --- a/lib/texts/MetaString.h +++ b/lib/texts/MetaString.h @@ -21,6 +21,7 @@ class MapObjectSubID; class PlayerColor; class SecondarySkill; class SpellID; +class FactionID; class GameResID; using TQuantity = si32; @@ -97,6 +98,7 @@ public: void replacePositiveNumber(int64_t txt); void replaceName(const ArtifactID & id); + void replaceName(const FactionID& id); void replaceName(const MapObjectID& id); void replaceName(const PlayerColor& id); void replaceName(const SecondarySkill& id);