diff --git a/client/lobby/CBonusSelection.cpp b/client/lobby/CBonusSelection.cpp index 4605ba3ed..ed572d72d 100644 --- a/client/lobby/CBonusSelection.cpp +++ b/client/lobby/CBonusSelection.cpp @@ -235,38 +235,30 @@ void CBonusSelection::createBonusesIcons() break; case CampaignBonusType::RESOURCE: { - int serialResID = 0; + desc.appendLocalString(EMetaText::GENERAL_TXT, 717); + switch(bonDescs[i].info1) { - case 0: - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: - serialResID = bonDescs[i].info1; - break; - case 0xFD: //wood + ore - serialResID = 7; - break; - case 0xFE: //rare resources - serialResID = 8; - break; + case 0xFD: //wood + ore + { + desc.replaceLocalString(EMetaText::GENERAL_TXT, 721); + picNumber = 7; + break; + } + case 0xFE: //wood + ore + { + desc.replaceLocalString(EMetaText::GENERAL_TXT, 722); + picNumber = 8; + break; + } + default: + { + desc.replaceName(GameResID(bonDescs[i].info1)); + picNumber = bonDescs[i].info1; + } } - picNumber = serialResID; - desc.appendLocalString(EMetaText::GENERAL_TXT, 717); desc.replaceNumber(bonDescs[i].info2); - - if(serialResID <= 6) - { - desc.replaceLocalString(EMetaText::RES_NAMES, serialResID); - } - else - { - desc.replaceLocalString(EMetaText::GENERAL_TXT, 714 + serialResID); - } break; } case CampaignBonusType::HEROES_FROM_PREVIOUS_SCENARIO: diff --git a/lib/CGameInfoCallback.cpp b/lib/CGameInfoCallback.cpp index a62a69c43..5d054efb6 100644 --- a/lib/CGameInfoCallback.cpp +++ b/lib/CGameInfoCallback.cpp @@ -122,17 +122,17 @@ TurnTimerInfo CGameInfoCallback::getPlayerTurnTime(PlayerColor color) const return TurnTimerInfo{}; } -const CGObjectInstance * CGameInfoCallback::getObjByQuestIdentifier(int identifier) const +const CGObjectInstance * CGameInfoCallback::getObjByQuestIdentifier(ObjectInstanceID identifier) const { if(gs->map->questIdentifierToId.empty()) { //assume that it is VCMI map and quest identifier equals instance identifier - return getObj(ObjectInstanceID(identifier), true); + return getObj(identifier, true); } else { - ERROR_RET_VAL_IF(!vstd::contains(gs->map->questIdentifierToId, identifier), "There is no object with such quest identifier!", nullptr); - return getObj(gs->map->questIdentifierToId[identifier]); + ERROR_RET_VAL_IF(!vstd::contains(gs->map->questIdentifierToId, identifier.getNum()), "There is no object with such quest identifier!", nullptr); + return getObj(gs->map->questIdentifierToId[identifier.getNum()]); } } diff --git a/lib/CGameInfoCallback.h b/lib/CGameInfoCallback.h index aeec312d3..65cc686ab 100644 --- a/lib/CGameInfoCallback.h +++ b/lib/CGameInfoCallback.h @@ -93,7 +93,7 @@ public: // std::vector getFlaggableObjects(int3 pos) const; // const CGObjectInstance * getTopObj (int3 pos) const; // PlayerColor getOwner(ObjectInstanceID heroID) const; -// const CGObjectInstance *getObjByQuestIdentifier(int identifier) const; //nullptr if object has been removed (eg. killed) +// const CGObjectInstance *getObjByQuestIdentifier(ObjectInstanceID identifier) const; //nullptr if object has been removed (eg. killed) //map // int3 guardingCreaturePosition (int3 pos) const; @@ -190,7 +190,7 @@ public: virtual std::vector getFlaggableObjects(int3 pos) const; virtual const CGObjectInstance * getTopObj (int3 pos) const; virtual PlayerColor getOwner(ObjectInstanceID heroID) const; - virtual const CGObjectInstance *getObjByQuestIdentifier(int identifier) const; //nullptr if object has been removed (eg. killed) + virtual const CGObjectInstance *getObjByQuestIdentifier(ObjectInstanceID identifier) const; //nullptr if object has been removed (eg. killed) //map virtual int3 guardingCreaturePosition (int3 pos) const; diff --git a/lib/MetaString.cpp b/lib/MetaString.cpp index 944c82190..3da43f519 100644 --- a/lib/MetaString.cpp +++ b/lib/MetaString.cpp @@ -114,8 +114,6 @@ std::string MetaString::getLocalString(const std::pair & txt) c { case EMetaText::GENERAL_TXT: return VLC->generaltexth->translate("core.genrltxt", ser); - case EMetaText::RES_NAMES: - return VLC->generaltexth->translate("core.restypes", ser); case EMetaText::ARRAY_TXT: return VLC->generaltexth->translate("core.arraytxt", ser); case EMetaText::ADVOB_TXT: @@ -374,6 +372,11 @@ void MetaString::replaceName(const SpellID & id) replaceTextID(id.toEntity(VLC)->getNameTextID()); } +void MetaString::replaceName(const GameResID& id) +{ + replaceTextID(TextIdentifier("core.restypes", id.getNum()).get()); +} + void MetaString::replaceNameSingular(const CreatureID & id) { replaceTextID(id.toEntity(VLC)->getNameSingularTextID()); diff --git a/lib/MetaString.h b/lib/MetaString.h index 92d3e3450..ff2ffca19 100644 --- a/lib/MetaString.h +++ b/lib/MetaString.h @@ -21,13 +21,13 @@ class MapObjectSubID; class PlayerColor; class SecondarySkill; class SpellID; +class GameResID; using TQuantity = si32; /// Strings classes that can be used as replacement in MetaString enum class EMetaText : uint8_t { GENERAL_TXT = 1, - RES_NAMES, ARRAY_TXT, ADVOB_TXT, JK_TXT @@ -97,6 +97,7 @@ public: void replaceName(const PlayerColor& id); void replaceName(const SecondarySkill& id); void replaceName(const SpellID& id); + void replaceName(const GameResID& id); /// Replaces first '%s' placeholder with singular or plural name depending on creatures count void replaceName(const CreatureID & id, TQuantity count); diff --git a/lib/gameState/CGameStateCampaign.cpp b/lib/gameState/CGameStateCampaign.cpp index 6ba1a44d6..b78828b57 100644 --- a/lib/gameState/CGameStateCampaign.cpp +++ b/lib/gameState/CGameStateCampaign.cpp @@ -189,8 +189,8 @@ void CGameStateCampaign::placeCampaignHeroes() auto it = gameState->scenarioOps->playerInfos.find(playerColor); if(it != gameState->scenarioOps->playerInfos.end()) { - auto heroTypeId = campaignBonus->info2; - if(heroTypeId == 0xffff) // random bonus hero + HeroTypeID heroTypeId = HeroTypeID(campaignBonus->info2); + if(heroTypeId.getNum() == 0xffff) // random bonus hero { heroTypeId = gameState->pickUnusedHeroTypeRandomly(playerColor); } diff --git a/lib/gameState/SThievesGuildInfo.h b/lib/gameState/SThievesGuildInfo.h index b712d543e..45ed3bdef 100644 --- a/lib/gameState/SThievesGuildInfo.h +++ b/lib/gameState/SThievesGuildInfo.h @@ -23,7 +23,7 @@ struct DLL_LINKAGE SThievesGuildInfo std::map colorToBestHero; //maps player's color to his best heros' std::map personality; // color to personality // ai tactic - std::map bestCreature; // color to ID // id or -1 if not known + std::map bestCreature; // color to ID // id or -1 if not known // template void serialize(Handler &h, const int version) // { diff --git a/lib/mapObjects/CBank.cpp b/lib/mapObjects/CBank.cpp index 14ca4b93e..46661af86 100644 --- a/lib/mapObjects/CBank.cpp +++ b/lib/mapObjects/CBank.cpp @@ -273,7 +273,7 @@ void CBank::doVisit(const CGHeroInstance * hero) const iw.components.emplace_back(ComponentType::RESOURCE, it, bc->resources[it]); loot.appendRawString("%d %s"); loot.replaceNumber(bc->resources[it]); - loot.replaceLocalString(EMetaText::RES_NAMES, it); + loot.replaceName(it); cb->giveResource(hero->getOwner(), it, bc->resources[it]); } } diff --git a/lib/mapObjects/CQuest.cpp b/lib/mapObjects/CQuest.cpp index ed1871ef1..f2f9c23b0 100644 --- a/lib/mapObjects/CQuest.cpp +++ b/lib/mapObjects/CQuest.cpp @@ -242,13 +242,13 @@ void CQuest::addTextReplacements(MetaString & text, std::vector & com if(mission.resources.nonZero()) { MetaString loot; - for(int i = 0; i < 7; ++i) + for(auto i : GameResID::ALL_RESOURCES()) { if(mission.resources[i]) { loot.appendRawString("%d %s"); loot.replaceNumber(mission.resources[i]); - loot.replaceLocalString(EMetaText::RES_NAMES, i); + loot.replaceName(i); } } text.replaceRawString(loot.buildList()); diff --git a/lib/mapObjects/MiscObjects.cpp b/lib/mapObjects/MiscObjects.cpp index 00968d887..ca35c3fdd 100644 --- a/lib/mapObjects/MiscObjects.cpp +++ b/lib/mapObjects/MiscObjects.cpp @@ -320,7 +320,7 @@ void CGResource::collectRes(const PlayerColor & player) const { sii.type = EInfoWindowMode::INFO; sii.text.appendLocalString(EMetaText::ADVOB_TXT,113); - sii.text.replaceLocalString(EMetaText::RES_NAMES, resourceID()); + sii.text.replaceName(resourceID()); } sii.components.emplace_back(ComponentType::RESOURCE, resourceID(), amount); sii.soundID = soundBase::pickup01 + CRandomGenerator::getDefault().nextInt(6); diff --git a/lib/modding/IdentifierStorage.cpp b/lib/modding/IdentifierStorage.cpp index cce9700c5..2a360db36 100644 --- a/lib/modding/IdentifierStorage.cpp +++ b/lib/modding/IdentifierStorage.cpp @@ -26,9 +26,9 @@ CIdentifierStorage::CIdentifierStorage() { //TODO: moddable spell schools for (auto i = 0; i < GameConstants::DEFAULT_SCHOOLS; ++i) - registerObject(ModScope::scopeBuiltin(), "spellSchool", SpellConfig::SCHOOL[i].jsonName, SpellConfig::SCHOOL[i].id); + registerObject(ModScope::scopeBuiltin(), "spellSchool", SpellConfig::SCHOOL[i].jsonName, SpellConfig::SCHOOL[i].id.getNum()); - registerObject(ModScope::scopeBuiltin(), "spellSchool", "any", SpellSchool(SpellSchool::ANY)); + registerObject(ModScope::scopeBuiltin(), "spellSchool", "any", SpellSchool::ANY.getNum()); for (int i = 0; i < GameConstants::RESOURCE_QUANTITY; ++i) registerObject(ModScope::scopeBuiltin(), "resource", GameConstants::RESOURCE_NAMES[i], i); diff --git a/lib/networkPacks/NetPacksLib.cpp b/lib/networkPacks/NetPacksLib.cpp index ac5488e35..2fd3b9cbb 100644 --- a/lib/networkPacks/NetPacksLib.cpp +++ b/lib/networkPacks/NetPacksLib.cpp @@ -1971,9 +1971,9 @@ void HeroVisit::applyGs(CGameState *gs) void SetAvailableArtifacts::applyGs(CGameState * gs) const { - if(id >= 0) + if(id != ObjectInstanceID::NONE) { - if(auto * bm = dynamic_cast(gs->map->objects[id].get())) + if(auto * bm = dynamic_cast(gs->getObjInstance(id))) { bm->artifacts = arts; } diff --git a/lib/rmg/CMapGenOptions.cpp b/lib/rmg/CMapGenOptions.cpp index d1bae95eb..035c3bc9b 100644 --- a/lib/rmg/CMapGenOptions.cpp +++ b/lib/rmg/CMapGenOptions.cpp @@ -325,7 +325,7 @@ void CMapGenOptions::resetPlayersMap() } else { - logGlobal->warn("Adding settings for player %s", color.encode(color)); + logGlobal->warn("Adding settings for player %s", color); // Usually, all players should be initialized in initPlayersMap() CPlayerSettings settings; players[color] = settings; diff --git a/lib/rmg/CMapGenerator.cpp b/lib/rmg/CMapGenerator.cpp index 78c03890e..188ebb5df 100644 --- a/lib/rmg/CMapGenerator.cpp +++ b/lib/rmg/CMapGenerator.cpp @@ -182,7 +182,7 @@ void CMapGenerator::addPlayerInfo() { // Teams are already configured in CMapGenOptions. However, it's not the case when it comes to map editor - std::set teamsTotal; + std::set teamsTotal; if (mapGenOptions.arePlayersCustomized()) { @@ -284,7 +284,7 @@ void CMapGenerator::addPlayerInfo() player.team = TeamID(*itTeam); teamNumbers[j].erase(itTeam); } - teamsTotal.insert(player.team.getNum()); + teamsTotal.insert(player.team); map->getMap(this).players[pSettings.getColor().getNum()] = player; } diff --git a/lib/rmg/modificators/TownPlacer.cpp b/lib/rmg/modificators/TownPlacer.cpp index f4a153cad..baa6b2d6e 100644 --- a/lib/rmg/modificators/TownPlacer.cpp +++ b/lib/rmg/modificators/TownPlacer.cpp @@ -223,7 +223,7 @@ void TownPlacer::addNewTowns(int count, bool hasFort, const PlayerColor & player } } -si32 TownPlacer::getRandomTownType(bool matchUndergroundType) +FactionID TownPlacer::getRandomTownType(bool matchUndergroundType) { auto townTypesAllowed = (!zone.getTownTypes().empty() ? zone.getTownTypes() : zone.getDefaultTownTypes()); if(matchUndergroundType) diff --git a/lib/rmg/modificators/TownPlacer.h b/lib/rmg/modificators/TownPlacer.h index a144da17d..75028093b 100644 --- a/lib/rmg/modificators/TownPlacer.h +++ b/lib/rmg/modificators/TownPlacer.h @@ -28,7 +28,7 @@ public: protected: void cleanupBoundaries(const rmg::Object & rmgObject); void addNewTowns(int count, bool hasFort, const PlayerColor & player, ObjectManager & manager); - si32 getRandomTownType(bool matchUndergroundType = false); + FactionID getRandomTownType(bool matchUndergroundType = false); void placeTowns(ObjectManager & manager); bool placeMines(ObjectManager & manager); int3 placeMainTown(ObjectManager & manager, CGTownInstance & town); diff --git a/test/spells/targetConditions/ElementalConditionTest.cpp b/test/spells/targetConditions/ElementalConditionTest.cpp index 61df6eb5a..b0085dee7 100644 --- a/test/spells/targetConditions/ElementalConditionTest.cpp +++ b/test/spells/targetConditions/ElementalConditionTest.cpp @@ -30,8 +30,8 @@ public: EXPECT_CALL(spellMock, forEachSchool(NotNull())).Times(AtLeast(1)).WillRepeatedly([](const spells::Spell::SchoolCallback & cb) { bool stop = false; - cb(SpellSchool(SpellSchool::AIR), stop); - cb(SpellSchool(SpellSchool::FIRE), stop); + cb(SpellSchool::AIR, stop); + cb(SpellSchool::FIRE, stop); }); EXPECT_CALL(mechanicsMock, isPositiveSpell()).WillRepeatedly(Return(isPositive));