From 2636a0dcc310f76046fc7e960da4d4c8e5ca8801 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Sat, 17 Jun 2023 23:52:42 +0300 Subject: [PATCH] Moved MetaString to a new file --- client/windows/CQuestLog.cpp | 2 +- cmake_modules/VCMI_lib.cmake | 2 + include/vcmi/spells/Caster.h | 2 +- include/vcmi/spells/Magic.h | 2 +- lib/CGameState.cpp | 228 --------------------------- lib/CGameState.h | 2 +- lib/IGameCallback.h | 2 +- lib/IGameEventsReceiver.h | 2 +- lib/MetaString.cpp | 253 ++++++++++++++++++++++++++++++ lib/MetaString.h | 90 +++++++++++ lib/NetPacks.h | 1 + lib/NetPacksBase.h | 85 ---------- lib/battle/Unit.cpp | 1 + lib/battle/Unit.h | 2 +- lib/mapObjects/CGCreature.cpp | 4 +- lib/mapObjects/CQuest.cpp | 2 +- lib/mapObjects/IObjectInterface.h | 1 + lib/mapObjects/MiscObjects.h | 1 + lib/rewardable/Configuration.h | 3 +- lib/spells/BonusCaster.cpp | 2 +- lib/spells/Problem.cpp | 1 - lib/spells/Problem.h | 2 +- lib/spells/effects/Timed.h | 2 +- 23 files changed, 364 insertions(+), 328 deletions(-) create mode 100644 lib/MetaString.cpp create mode 100644 lib/MetaString.h diff --git a/client/windows/CQuestLog.cpp b/client/windows/CQuestLog.cpp index 86f6a03a7..5a5a4f79a 100644 --- a/client/windows/CQuestLog.cpp +++ b/client/windows/CQuestLog.cpp @@ -28,7 +28,7 @@ #include "../../lib/CConfigHandler.h" #include "../../lib/CGameState.h" #include "../../lib/CGeneralTextHandler.h" -#include "../../lib/NetPacksBase.h" +#include "../../lib/MetaString.h" #include "../../lib/mapObjects/CQuest.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/cmake_modules/VCMI_lib.cmake b/cmake_modules/VCMI_lib.cmake index e1a6d151c..bbdc44fb8 100644 --- a/cmake_modules/VCMI_lib.cmake +++ b/cmake_modules/VCMI_lib.cmake @@ -238,6 +238,7 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE) ${MAIN_LIB_DIR}/LoadProgress.cpp ${MAIN_LIB_DIR}/LogicalExpression.cpp ${MAIN_LIB_DIR}/NetPacksLib.cpp + ${MAIN_LIB_DIR}/MetaString.cpp ${MAIN_LIB_DIR}/ObstacleHandler.cpp ${MAIN_LIB_DIR}/StartInfo.cpp ${MAIN_LIB_DIR}/ResourceSet.cpp @@ -560,6 +561,7 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE) ${MAIN_LIB_DIR}/Languages.h ${MAIN_LIB_DIR}/LoadProgress.h ${MAIN_LIB_DIR}/LogicalExpression.h + ${MAIN_LIB_DIR}/MetaString.h ${MAIN_LIB_DIR}/NetPacksBase.h ${MAIN_LIB_DIR}/NetPacks.h ${MAIN_LIB_DIR}/NetPacksLobby.h diff --git a/include/vcmi/spells/Caster.h b/include/vcmi/spells/Caster.h index 09e28aa18..8c170ce63 100644 --- a/include/vcmi/spells/Caster.h +++ b/include/vcmi/spells/Caster.h @@ -13,7 +13,7 @@ VCMI_LIB_NAMESPACE_BEGIN class PlayerColor; -struct MetaString; +class MetaString; class ServerCallback; class CGHeroInstance; diff --git a/include/vcmi/spells/Magic.h b/include/vcmi/spells/Magic.h index 20a21541e..f5bb312c7 100644 --- a/include/vcmi/spells/Magic.h +++ b/include/vcmi/spells/Magic.h @@ -12,7 +12,7 @@ VCMI_LIB_NAMESPACE_BEGIN -struct MetaString; +class MetaString; namespace battle { diff --git a/lib/CGameState.cpp b/lib/CGameState.cpp index e710190a7..f93af8b5a 100644 --- a/lib/CGameState.cpp +++ b/lib/CGameState.cpp @@ -68,234 +68,6 @@ public: } }; -void MetaString::getLocalString(const std::pair & txt, std::string & dst) const -{ - int type = txt.first; - int ser = txt.second; - - if(type == ART_NAMES) - { - const auto * art = ArtifactID(ser).toArtifact(VLC->artifacts()); - if(art) - dst = art->getNameTranslated(); - else - dst = "#!#"; - } - else if(type == ART_DESCR) - { - const auto * art = ArtifactID(ser).toArtifact(VLC->artifacts()); - if(art) - dst = art->getDescriptionTranslated(); - else - dst = "#!#"; - } - else if (type == ART_EVNTS) - { - const auto * art = ArtifactID(ser).toArtifact(VLC->artifacts()); - if(art) - dst = art->getEventTranslated(); - else - dst = "#!#"; - } - else if(type == CRE_PL_NAMES) - { - const auto * cre = CreatureID(ser).toCreature(VLC->creatures()); - if(cre) - dst = cre->getNamePluralTranslated(); - else - dst = "#!#"; - } - else if(type == CRE_SING_NAMES) - { - const auto * cre = CreatureID(ser).toCreature(VLC->creatures()); - if(cre) - dst = cre->getNameSingularTranslated(); - else - dst = "#!#"; - } - else if(type == MINE_NAMES) - { - dst = VLC->generaltexth->translate("core.minename", ser); - } - else if(type == MINE_EVNTS) - { - dst = VLC->generaltexth->translate("core.mineevnt", ser); - } - else if(type == SPELL_NAME) - { - const auto * spell = SpellID(ser).toSpell(VLC->spells()); - if(spell) - dst = spell->getNameTranslated(); - else - dst = "#!#"; - } - else if(type == OBJ_NAMES) - { - dst = VLC->objtypeh->getObjectName(ser, 0); - } - else if(type == SEC_SKILL_NAME) - { - dst = VLC->skillh->getByIndex(ser)->getNameTranslated(); - } - else - { - switch(type) - { - case GENERAL_TXT: - dst = VLC->generaltexth->translate("core.genrltxt", ser); - break; - case RES_NAMES: - dst = VLC->generaltexth->translate("core.restypes", ser); - break; - case ARRAY_TXT: - dst = VLC->generaltexth->translate("core.arraytxt", ser); - break; - case CREGENS: - dst = VLC->objtypeh->getObjectName(Obj::CREATURE_GENERATOR1, ser); - break; - case CREGENS4: - dst = VLC->objtypeh->getObjectName(Obj::CREATURE_GENERATOR4, ser); - break; - case ADVOB_TXT: - dst = VLC->generaltexth->translate("core.advevent", ser); - break; - case COLOR: - dst = VLC->generaltexth->translate("vcmi.capitalColors", ser); - break; - case JK_TXT: - dst = VLC->generaltexth->translate("core.jktext", ser); - break; - default: - logGlobal->error("Failed string substitution because type is %d", type); - dst = "#@#"; - return; - } - } -} - -DLL_LINKAGE void MetaString::toString(std::string &dst) const -{ - size_t exSt = 0; - size_t loSt = 0; - size_t nums = 0; - dst.clear(); - - for(const auto & elem : message) - {//TEXACT_STRING, TLOCAL_STRING, TNUMBER, TREPLACE_ESTRING, TREPLACE_LSTRING, TREPLACE_NUMBER - switch(elem) - { - case TEXACT_STRING: - dst += exactStrings[exSt++]; - break; - case TLOCAL_STRING: - { - std::string hlp; - getLocalString(localStrings[loSt++], hlp); - dst += hlp; - } - break; - case TNUMBER: - dst += std::to_string(numbers[nums++]); - break; - case TREPLACE_ESTRING: - boost::replace_first(dst, "%s", exactStrings[exSt++]); - break; - case TREPLACE_LSTRING: - { - std::string hlp; - getLocalString(localStrings[loSt++], hlp); - boost::replace_first(dst, "%s", hlp); - } - break; - case TREPLACE_NUMBER: - boost::replace_first(dst, "%d", std::to_string(numbers[nums++])); - break; - case TREPLACE_PLUSNUMBER: - boost::replace_first(dst, "%+d", '+' + std::to_string(numbers[nums++])); - break; - default: - logGlobal->error("MetaString processing error! Received message of type %d", int(elem)); - break; - } - } -} - -DLL_LINKAGE std::string MetaString::toString() const -{ - std::string ret; - toString(ret); - return ret; -} - -DLL_LINKAGE std::string MetaString::buildList () const -///used to handle loot from creature bank -{ - - size_t exSt = 0; - size_t loSt = 0; - size_t nums = 0; - std::string lista; - for (int i = 0; i < message.size(); ++i) - { - if (i > 0 && (message[i] == TEXACT_STRING || message[i] == TLOCAL_STRING)) - { - if (exSt == exactStrings.size() - 1) - lista += VLC->generaltexth->allTexts[141]; //" and " - else - lista += ", "; - } - switch (message[i]) - { - case TEXACT_STRING: - lista += exactStrings[exSt++]; - break; - case TLOCAL_STRING: - { - std::string hlp; - getLocalString (localStrings[loSt++], hlp); - lista += hlp; - } - break; - case TNUMBER: - lista += std::to_string(numbers[nums++]); - break; - case TREPLACE_ESTRING: - lista.replace (lista.find("%s"), 2, exactStrings[exSt++]); - break; - case TREPLACE_LSTRING: - { - std::string hlp; - getLocalString (localStrings[loSt++], hlp); - lista.replace (lista.find("%s"), 2, hlp); - } - break; - case TREPLACE_NUMBER: - lista.replace (lista.find("%d"), 2, std::to_string(numbers[nums++])); - break; - default: - logGlobal->error("MetaString processing error! Received message of type %d",int(message[i])); - } - - } - return lista; -} - -void MetaString::addCreReplacement(const CreatureID & id, TQuantity count) //adds sing or plural name; -{ - if (!count) - addReplacement (CRE_PL_NAMES, id); //no creatures - just empty name (eg. defeat Angels) - else if (count == 1) - addReplacement (CRE_SING_NAMES, id); - else - addReplacement (CRE_PL_NAMES, id); -} - -void MetaString::addReplacement(const CStackBasicDescriptor & stack) -{ - assert(stack.type); //valid type - addCreReplacement(stack.type->getId(), stack.count); -} - static CGObjectInstance * createObject(const Obj & id, int subid, const int3 & pos, const PlayerColor & owner) { CGObjectInstance * nobj; diff --git a/lib/CGameState.h b/lib/CGameState.h index 2e2adc317..a55eb5c73 100644 --- a/lib/CGameState.h +++ b/lib/CGameState.h @@ -43,7 +43,7 @@ class CCreature; class CMap; struct StartInfo; struct SetObjectProperty; -struct MetaString; +class MetaString; struct CPack; class CSpell; struct TerrainTile; diff --git a/lib/IGameCallback.h b/lib/IGameCallback.h index e349b6daa..3eb4c6c9a 100644 --- a/lib/IGameCallback.h +++ b/lib/IGameCallback.h @@ -20,7 +20,7 @@ struct SetMovePoints; struct GiveBonus; struct BlockingDialog; struct TeleportDialog; -struct MetaString; +class MetaString; struct StackLocation; struct ArtifactLocation; class CCreatureSet; diff --git a/lib/IGameEventsReceiver.h b/lib/IGameEventsReceiver.h index e962e9091..226b92198 100644 --- a/lib/IGameEventsReceiver.h +++ b/lib/IGameEventsReceiver.h @@ -49,7 +49,7 @@ struct BattleTriggerEffect; struct CObstacleInstance; struct CPackForServer; class EVictoryLossCheckResult; -struct MetaString; +class MetaString; class ObstacleChanges; class UnitChanges; diff --git a/lib/MetaString.cpp b/lib/MetaString.cpp new file mode 100644 index 000000000..7865634df --- /dev/null +++ b/lib/MetaString.cpp @@ -0,0 +1,253 @@ +/* + * CGameState.cpp, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ +#include "StdInc.h" +#include "MetaString.h" + +#include "CArtHandler.h" +#include "CCreatureHandler.h" +#include "CCreatureSet.h" +#include "CGeneralTextHandler.h" +#include "CSkillHandler.h" +#include "GameConstants.h" +#include "VCMI_Lib.h" +#include "mapObjectConstructors/CObjectClassesHandler.h" +#include "spells/CSpellHandler.h" + +VCMI_LIB_NAMESPACE_BEGIN + +void MetaString::getLocalString(const std::pair & txt, std::string & dst) const +{ + int type = txt.first; + int ser = txt.second; + + if(type == ART_NAMES) + { + const auto * art = ArtifactID(ser).toArtifact(VLC->artifacts()); + if(art) + dst = art->getNameTranslated(); + else + dst = "#!#"; + } + else if(type == ART_DESCR) + { + const auto * art = ArtifactID(ser).toArtifact(VLC->artifacts()); + if(art) + dst = art->getDescriptionTranslated(); + else + dst = "#!#"; + } + else if (type == ART_EVNTS) + { + const auto * art = ArtifactID(ser).toArtifact(VLC->artifacts()); + if(art) + dst = art->getEventTranslated(); + else + dst = "#!#"; + } + else if(type == CRE_PL_NAMES) + { + const auto * cre = CreatureID(ser).toCreature(VLC->creatures()); + if(cre) + dst = cre->getNamePluralTranslated(); + else + dst = "#!#"; + } + else if(type == CRE_SING_NAMES) + { + const auto * cre = CreatureID(ser).toCreature(VLC->creatures()); + if(cre) + dst = cre->getNameSingularTranslated(); + else + dst = "#!#"; + } + else if(type == MINE_NAMES) + { + dst = VLC->generaltexth->translate("core.minename", ser); + } + else if(type == MINE_EVNTS) + { + dst = VLC->generaltexth->translate("core.mineevnt", ser); + } + else if(type == SPELL_NAME) + { + const auto * spell = SpellID(ser).toSpell(VLC->spells()); + if(spell) + dst = spell->getNameTranslated(); + else + dst = "#!#"; + } + else if(type == OBJ_NAMES) + { + dst = VLC->objtypeh->getObjectName(ser, 0); + } + else if(type == SEC_SKILL_NAME) + { + dst = VLC->skillh->getByIndex(ser)->getNameTranslated(); + } + else + { + switch(type) + { + case GENERAL_TXT: + dst = VLC->generaltexth->translate("core.genrltxt", ser); + break; + case RES_NAMES: + dst = VLC->generaltexth->translate("core.restypes", ser); + break; + case ARRAY_TXT: + dst = VLC->generaltexth->translate("core.arraytxt", ser); + break; + case CREGENS: + dst = VLC->objtypeh->getObjectName(Obj::CREATURE_GENERATOR1, ser); + break; + case CREGENS4: + dst = VLC->objtypeh->getObjectName(Obj::CREATURE_GENERATOR4, ser); + break; + case ADVOB_TXT: + dst = VLC->generaltexth->translate("core.advevent", ser); + break; + case COLOR: + dst = VLC->generaltexth->translate("vcmi.capitalColors", ser); + break; + case JK_TXT: + dst = VLC->generaltexth->translate("core.jktext", ser); + break; + default: + logGlobal->error("Failed string substitution because type is %d", type); + dst = "#@#"; + return; + } + } +} + +DLL_LINKAGE void MetaString::toString(std::string &dst) const +{ + size_t exSt = 0; + size_t loSt = 0; + size_t nums = 0; + dst.clear(); + + for(const auto & elem : message) + {//TEXACT_STRING, TLOCAL_STRING, TNUMBER, TREPLACE_ESTRING, TREPLACE_LSTRING, TREPLACE_NUMBER + switch(elem) + { + case TEXACT_STRING: + dst += exactStrings[exSt++]; + break; + case TLOCAL_STRING: + { + std::string hlp; + getLocalString(localStrings[loSt++], hlp); + dst += hlp; + } + break; + case TNUMBER: + dst += std::to_string(numbers[nums++]); + break; + case TREPLACE_ESTRING: + boost::replace_first(dst, "%s", exactStrings[exSt++]); + break; + case TREPLACE_LSTRING: + { + std::string hlp; + getLocalString(localStrings[loSt++], hlp); + boost::replace_first(dst, "%s", hlp); + } + break; + case TREPLACE_NUMBER: + boost::replace_first(dst, "%d", std::to_string(numbers[nums++])); + break; + case TREPLACE_PLUSNUMBER: + boost::replace_first(dst, "%+d", '+' + std::to_string(numbers[nums++])); + break; + default: + logGlobal->error("MetaString processing error! Received message of type %d", int(elem)); + break; + } + } +} + +DLL_LINKAGE std::string MetaString::toString() const +{ + std::string ret; + toString(ret); + return ret; +} + +DLL_LINKAGE std::string MetaString::buildList () const +///used to handle loot from creature bank +{ + + size_t exSt = 0; + size_t loSt = 0; + size_t nums = 0; + std::string lista; + for (int i = 0; i < message.size(); ++i) + { + if (i > 0 && (message[i] == TEXACT_STRING || message[i] == TLOCAL_STRING)) + { + if (exSt == exactStrings.size() - 1) + lista += VLC->generaltexth->allTexts[141]; //" and " + else + lista += ", "; + } + switch (message[i]) + { + case TEXACT_STRING: + lista += exactStrings[exSt++]; + break; + case TLOCAL_STRING: + { + std::string hlp; + getLocalString (localStrings[loSt++], hlp); + lista += hlp; + } + break; + case TNUMBER: + lista += std::to_string(numbers[nums++]); + break; + case TREPLACE_ESTRING: + lista.replace (lista.find("%s"), 2, exactStrings[exSt++]); + break; + case TREPLACE_LSTRING: + { + std::string hlp; + getLocalString (localStrings[loSt++], hlp); + lista.replace (lista.find("%s"), 2, hlp); + } + break; + case TREPLACE_NUMBER: + lista.replace (lista.find("%d"), 2, std::to_string(numbers[nums++])); + break; + default: + logGlobal->error("MetaString processing error! Received message of type %d",int(message[i])); + } + + } + return lista; +} + +void MetaString::addCreReplacement(const CreatureID & id, TQuantity count) //adds sing or plural name; +{ + if (!count) + addReplacement (CRE_PL_NAMES, id); //no creatures - just empty name (eg. defeat Angels) + else if (count == 1) + addReplacement (CRE_SING_NAMES, id); + else + addReplacement (CRE_PL_NAMES, id); +} + +void MetaString::addReplacement(const CStackBasicDescriptor & stack) +{ + assert(stack.type); //valid type + addCreReplacement(stack.type->getId(), stack.count); +} + +VCMI_LIB_NAMESPACE_END diff --git a/lib/MetaString.h b/lib/MetaString.h new file mode 100644 index 000000000..0189f7679 --- /dev/null +++ b/lib/MetaString.h @@ -0,0 +1,90 @@ +/* + * MetaString.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ +#pragma once + +VCMI_LIB_NAMESPACE_BEGIN + +class CreatureID; +class CStackBasicDescriptor; +using TQuantity = si32; + +class DLL_LINKAGE MetaString +{ +private: + enum EMessage {TEXACT_STRING, TLOCAL_STRING, TNUMBER, TREPLACE_ESTRING, TREPLACE_LSTRING, TREPLACE_NUMBER, TREPLACE_PLUSNUMBER}; +public: + enum {GENERAL_TXT=1, OBJ_NAMES, RES_NAMES, ART_NAMES, ARRAY_TXT, CRE_PL_NAMES, CREGENS, MINE_NAMES, + MINE_EVNTS, ADVOB_TXT, ART_EVNTS, SPELL_NAME, SEC_SKILL_NAME, CRE_SING_NAMES, CREGENS4, COLOR, ART_DESCR, JK_TXT}; + + std::vector message; //vector of EMessage + + std::vector > localStrings; + std::vector exactStrings; + std::vector numbers; + + template void serialize(Handler & h, const int version) + { + h & exactStrings; + h & localStrings; + h & message; + h & numbers; + } + void addTxt(ui8 type, ui32 serial) + { + message.push_back(TLOCAL_STRING); + localStrings.emplace_back(type, serial); + } + void addRawString(std::string value) + { + message.push_back(TEXACT_STRING); + exactStrings.push_back(value); + } + void appendNumber(int64_t value) + { + message.push_back(TNUMBER); + numbers.push_back(value); + } + void addReplacement(ui8 type, ui32 serial) + { + message.push_back(TREPLACE_LSTRING); + localStrings.emplace_back(type, serial); + } + void addReplacement(const std::string &txt) + { + message.push_back(TREPLACE_ESTRING); + exactStrings.push_back(txt); + } + void addReplacement(int64_t txt) + { + message.push_back(TREPLACE_NUMBER); + numbers.push_back(txt); + } + void addReplacement2(int64_t txt) + { + message.push_back(TREPLACE_PLUSNUMBER); + numbers.push_back(txt); + } + void addCreReplacement(const CreatureID & id, TQuantity count); //adds sing or plural name; + void addReplacement(const CStackBasicDescriptor &stack); //adds sing or plural name; + std::string buildList () const; + void clear() + { + exactStrings.clear(); + localStrings.clear(); + message.clear(); + numbers.clear(); + } + void toString(std::string &dst) const; + std::string toString() const; + void getLocalString(const std::pair & txt, std::string & dst) const; + +}; + +VCMI_LIB_NAMESPACE_END diff --git a/lib/NetPacks.h b/lib/NetPacks.h index 254bac795..38e71e425 100644 --- a/lib/NetPacks.h +++ b/lib/NetPacks.h @@ -19,6 +19,7 @@ #include "CGameStateFwd.h" #include "mapping/CMapDefines.h" #include "battle/CObstacleInstance.h" +#include "MetaString.h" #include "spells/ViewSpellInt.h" diff --git a/lib/NetPacksBase.h b/lib/NetPacksBase.h index 76d4fc88d..cbc793f5b 100644 --- a/lib/NetPacksBase.h +++ b/lib/NetPacksBase.h @@ -115,91 +115,6 @@ protected: virtual void visitBasic(ICPackVisitor & cpackVisitor) override; }; -struct DLL_LINKAGE MetaString -{ -private: - enum EMessage {TEXACT_STRING, TLOCAL_STRING, TNUMBER, TREPLACE_ESTRING, TREPLACE_LSTRING, TREPLACE_NUMBER, TREPLACE_PLUSNUMBER}; -public: - enum {GENERAL_TXT=1, OBJ_NAMES, RES_NAMES, ART_NAMES, ARRAY_TXT, CRE_PL_NAMES, CREGENS, MINE_NAMES, - MINE_EVNTS, ADVOB_TXT, ART_EVNTS, SPELL_NAME, SEC_SKILL_NAME, CRE_SING_NAMES, CREGENS4, COLOR, ART_DESCR, JK_TXT}; - - std::vector message; //vector of EMessage - - std::vector > localStrings; - std::vector exactStrings; - std::vector numbers; - - template void serialize(Handler & h, const int version) - { - h & exactStrings; - h & localStrings; - h & message; - h & numbers; - } - void addTxt(ui8 type, ui32 serial) - { - message.push_back(TLOCAL_STRING); - localStrings.emplace_back(type, serial); - } - MetaString& operator<<(const std::pair &txt) - { - message.push_back(TLOCAL_STRING); - localStrings.push_back(txt); - return *this; - } - MetaString& operator<<(int64_t txt) - { - message.push_back(TNUMBER); - numbers.push_back(txt); - return *this; - } - - void addRawString(std::string value) - { - message.push_back(TEXACT_STRING); - exactStrings.push_back(value); - } - void addNumber(int64_t value) - { - message.push_back(TNUMBER); - numbers.push_back(value); - } - void addReplacement(ui8 type, ui32 serial) - { - message.push_back(TREPLACE_LSTRING); - localStrings.emplace_back(type, serial); - } - void addReplacement(const std::string &txt) - { - message.push_back(TREPLACE_ESTRING); - exactStrings.push_back(txt); - } - void addReplacement(int64_t txt) - { - message.push_back(TREPLACE_NUMBER); - numbers.push_back(txt); - } - void addReplacement2(int64_t txt) - { - message.push_back(TREPLACE_PLUSNUMBER); - numbers.push_back(txt); - } - void addCreReplacement(const CreatureID & id, TQuantity count); //adds sing or plural name; - void addReplacement(const CStackBasicDescriptor &stack); //adds sing or plural name; - std::string buildList () const; - void clear() - { - exactStrings.clear(); - localStrings.clear(); - message.clear(); - numbers.clear(); - } - void toString(std::string &dst) const; - std::string toString() const; - void getLocalString(const std::pair & txt, std::string & dst) const; - -}; - struct Component { enum class EComponentType : uint8_t diff --git a/lib/battle/Unit.cpp b/lib/battle/Unit.cpp index 9c115485e..abb20c005 100644 --- a/lib/battle/Unit.cpp +++ b/lib/battle/Unit.cpp @@ -13,6 +13,7 @@ #include "../VCMI_Lib.h" #include "../CGeneralTextHandler.h" +#include "../MetaString.h" #include "../NetPacksBase.h" #include "../serializer/JsonDeserializer.h" diff --git a/lib/battle/Unit.h b/lib/battle/Unit.h index 2318f1214..5f6350a56 100644 --- a/lib/battle/Unit.h +++ b/lib/battle/Unit.h @@ -21,7 +21,7 @@ VCMI_LIB_NAMESPACE_BEGIN -struct MetaString; +class MetaString; class JsonNode; class JsonSerializeFormat; diff --git a/lib/mapObjects/CGCreature.cpp b/lib/mapObjects/CGCreature.cpp index a1c9edf38..7495040a3 100644 --- a/lib/mapObjects/CGCreature.cpp +++ b/lib/mapObjects/CGCreature.cpp @@ -49,7 +49,7 @@ std::string CGCreature::getHoverText(const CGHeroInstance * hero) const if(hero->hasVisions(this, 0)) { MetaString ms; - ms << stacks.begin()->second->count; + ms.appendNumber(stacks.begin()->second->count); ms.addRawString(" "); ms.addTxt(MetaString::CRE_PL_NAMES,subID); @@ -324,7 +324,7 @@ void CGCreature::joinDecision(const CGHeroInstance *h, int cost, ui32 accept) co { InfoWindow iw; iw.player = h->tempOwner; - iw.text << std::pair(1,29); //You don't have enough gold + iw.text.addTxt(1,29); //You don't have enough gold cb->showInfoDialog(&iw); //act as if player refused diff --git a/lib/mapObjects/CQuest.cpp b/lib/mapObjects/CQuest.cpp index cc9871210..c3d9ef878 100644 --- a/lib/mapObjects/CQuest.cpp +++ b/lib/mapObjects/CQuest.cpp @@ -1157,7 +1157,7 @@ void CGBorderGuard::initObj(CRandomGenerator & rand) void CGBorderGuard::getVisitText (MetaString &text, std::vector &components, bool isCustom, bool FirstVisit, const CGHeroInstance * h) const { - text << std::pair(11,18); + text.addTxt(11,18); } void CGBorderGuard::getRolloverText (MetaString &text, bool onHover) const diff --git a/lib/mapObjects/IObjectInterface.h b/lib/mapObjects/IObjectInterface.h index d724bb7fc..b27a66f00 100644 --- a/lib/mapObjects/IObjectInterface.h +++ b/lib/mapObjects/IObjectInterface.h @@ -20,6 +20,7 @@ class CRandomGenerator; class IGameCallback; class ResourceSet; class int3; +class MetaString; class DLL_LINKAGE IObjectInterface { diff --git a/lib/mapObjects/MiscObjects.h b/lib/mapObjects/MiscObjects.h index be57546a1..5da7e464b 100644 --- a/lib/mapObjects/MiscObjects.h +++ b/lib/mapObjects/MiscObjects.h @@ -10,6 +10,7 @@ #pragma once #include "CArmedInstance.h" +#include "../MetaString.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/rewardable/Configuration.h b/lib/rewardable/Configuration.h index cc65dda42..a2069fc71 100644 --- a/lib/rewardable/Configuration.h +++ b/lib/rewardable/Configuration.h @@ -11,8 +11,9 @@ #pragma once #include "Limiter.h" -#include "Reward.h" +#include "MetaString.h" #include "NetPacksBase.h" +#include "Reward.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/spells/BonusCaster.cpp b/lib/spells/BonusCaster.cpp index 76a84f0b7..e46f6e640 100644 --- a/lib/spells/BonusCaster.cpp +++ b/lib/spells/BonusCaster.cpp @@ -13,7 +13,7 @@ #include -#include "../NetPacksBase.h" +#include "../MetaString.h" #include "../battle/Unit.h" #include "../bonuses/Bonus.h" diff --git a/lib/spells/Problem.cpp b/lib/spells/Problem.cpp index f9448bf55..ed93028cd 100644 --- a/lib/spells/Problem.cpp +++ b/lib/spells/Problem.cpp @@ -8,7 +8,6 @@ * */ #include "StdInc.h" - #include "Problem.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/spells/Problem.h b/lib/spells/Problem.h index 7d3434ee3..aca7062f6 100644 --- a/lib/spells/Problem.h +++ b/lib/spells/Problem.h @@ -12,7 +12,7 @@ #include -#include "../NetPacksBase.h" +#include "../MetaString.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/spells/effects/Timed.h b/lib/spells/effects/Timed.h index 04051a788..57f81ecd6 100644 --- a/lib/spells/effects/Timed.h +++ b/lib/spells/effects/Timed.h @@ -16,7 +16,7 @@ VCMI_LIB_NAMESPACE_BEGIN struct Bonus; struct SetStackEffect; -struct MetaString; +class MetaString; namespace spells {