diff --git a/apps/openmw/mwclass/weapon.cpp b/apps/openmw/mwclass/weapon.cpp index d271eba9c2..4eddc37f73 100644 --- a/apps/openmw/mwclass/weapon.cpp +++ b/apps/openmw/mwclass/weapon.cpp @@ -165,8 +165,8 @@ namespace MWClass { text += "\n#{sType} "; - int skill = MWMechanics::getWeaponType(ref->mBase->mData.mType)->mSkill; - const std::string& type = ESM::Skill::sSkillNameIds[skill]; + const ESM::Skill* skill + = store.get().find(MWMechanics::getWeaponType(ref->mBase->mData.mType)->mSkill); std::string_view oneOrTwoHanded; if (weaponType->mWeaponClass == ESM::WeaponType::Melee) { @@ -176,7 +176,7 @@ namespace MWClass oneOrTwoHanded = "sOneHanded"; } - text += store.get().find(type)->mValue.getString(); + text += skill->mName; if (!oneOrTwoHanded.empty()) text += ", " + store.get().find(oneOrTwoHanded)->mValue.getString(); diff --git a/apps/openmw/mwgui/jailscreen.cpp b/apps/openmw/mwgui/jailscreen.cpp index 9dc45d0d05..ec0614a664 100644 --- a/apps/openmw/mwgui/jailscreen.cpp +++ b/apps/openmw/mwgui/jailscreen.cpp @@ -88,15 +88,16 @@ namespace MWGui // We should not worsen corprus when in prison player.getClass().getCreatureStats(player).getActiveSpells().skipWorsenings(mDays * 24); - std::set skills; + const auto& skillStore = MWBase::Environment::get().getESMStore()->get(); + std::set skills; for (int day = 0; day < mDays; ++day) { auto& prng = MWBase::Environment::get().getWorld()->getPrng(); - int skill = Misc::Rng::rollDice(ESM::Skill::Length, prng); + const ESM::Skill* skill = skillStore.find(Misc::Rng::rollDice(ESM::Skill::Length, prng)); skills.insert(skill); - MWMechanics::SkillValue& value = player.getClass().getNpcStats(player).getSkill(skill); - if (skill == ESM::Skill::Security || skill == ESM::Skill::Sneak) + MWMechanics::SkillValue& value = player.getClass().getNpcStats(player).getSkill(skill->mIndex); + if (skill->mIndex == ESM::Skill::Security || skill->mIndex == ESM::Skill::Sneak) value.setBase(std::min(100.f, value.getBase() + 1)); else value.setBase(std::max(0.f, value.getBase() - 1)); @@ -113,15 +114,14 @@ namespace MWGui message = Misc::StringUtils::format(message, mDays); - for (const int& skill : skills) + for (const ESM::Skill* skill : skills) { - const std::string& skillName = gmst.find(ESM::Skill::sSkillNameIds[skill])->mValue.getString(); - int skillValue = player.getClass().getNpcStats(player).getSkill(skill).getBase(); + int skillValue = player.getClass().getNpcStats(player).getSkill(skill->mIndex).getBase(); std::string skillMsg = gmst.find("sNotifyMessage44")->mValue.getString(); - if (skill == ESM::Skill::Sneak || skill == ESM::Skill::Security) + if (skill->mIndex == ESM::Skill::Sneak || skill->mIndex == ESM::Skill::Security) skillMsg = gmst.find("sNotifyMessage39")->mValue.getString(); - skillMsg = Misc::StringUtils::format(skillMsg, skillName, skillValue); + skillMsg = Misc::StringUtils::format(skillMsg, skill->mName, skillValue); message += "\n" + skillMsg; } diff --git a/apps/openmw/mwgui/review.cpp b/apps/openmw/mwgui/review.cpp index b4251df3bc..acea128f07 100644 --- a/apps/openmw/mwgui/review.cpp +++ b/apps/openmw/mwgui/review.cpp @@ -341,10 +341,9 @@ namespace MWGui for (const int& skillId : skills) { - if (skillId < 0 || skillId >= ESM::Skill::Length) // Skip unknown skill indexes + const ESM::Skill* skill = MWBase::Environment::get().getESMStore()->get().search(skillId); + if (!skill) // Skip unknown skill indexes continue; - assert(skillId >= 0 && skillId < ESM::Skill::Length); - const std::string& skillNameId = ESM::Skill::sSkillNameIds[skillId]; const MWMechanics::SkillValue& stat = mSkillValues.find(skillId)->second; int base = stat.getBase(); int modified = stat.getModified(); @@ -355,8 +354,7 @@ namespace MWGui else if (modified < base) state = "decreased"; MyGUI::TextBox* widget = addValueItem( - MWBase::Environment::get().getWindowManager()->getGameSettingString(skillNameId, skillNameId), - MyGUI::utility::toString(static_cast(modified)), state, coord1, coord2); + skill->mName, MyGUI::utility::toString(static_cast(modified)), state, coord1, coord2); for (int i = 0; i < 2; ++i) { diff --git a/apps/openmw/mwgui/spellicons.cpp b/apps/openmw/mwgui/spellicons.cpp index a62c70597f..5f69f7f168 100644 --- a/apps/openmw/mwgui/spellicons.cpp +++ b/apps/openmw/mwgui/spellicons.cpp @@ -83,10 +83,8 @@ namespace MWGui if (effect->mData.mFlags & ESM::MagicEffect::TargetSkill) { - sourcesDescription += " ("; - sourcesDescription += MWBase::Environment::get().getWindowManager()->getGameSettingString( - ESM::Skill::sSkillNameIds[effectInfo.mKey.mArg], {}); - sourcesDescription += ')'; + const ESM::Skill* skill = store->get().find(effectInfo.mKey.mArg); + sourcesDescription += " (" + skill->mName + ')'; } if (effect->mData.mFlags & ESM::MagicEffect::TargetAttribute) { diff --git a/apps/openmw/mwgui/spellmodel.cpp b/apps/openmw/mwgui/spellmodel.cpp index 9fc86dd0e6..473324e685 100644 --- a/apps/openmw/mwgui/spellmodel.cpp +++ b/apps/openmw/mwgui/spellmodel.cpp @@ -55,8 +55,9 @@ namespace MWGui { const ESM::MagicEffect* magicEffect = store.get().find(effectId); const ESM::Attribute* attribute = store.get().search(effect.mAttribute); + const ESM::Skill* skill = store.get().search(effect.mSkill); - std::string fullEffectName = MWMechanics::getMagicEffectString(*magicEffect, attribute, effect.mSkill); + std::string fullEffectName = MWMechanics::getMagicEffectString(*magicEffect, attribute, skill); std::string convert = Utf8Stream::lowerCaseUtf8(fullEffectName); if (convert.find(filter) != std::string::npos) { diff --git a/apps/openmw/mwgui/statswindow.cpp b/apps/openmw/mwgui/statswindow.cpp index 594b2e4c02..90e734d640 100644 --- a/apps/openmw/mwgui/statswindow.cpp +++ b/apps/openmw/mwgui/statswindow.cpp @@ -510,8 +510,6 @@ namespace MWGui { if (skillId < 0 || skillId >= ESM::Skill::Length) // Skip unknown skill indexes continue; - const std::string& skillNameId = ESM::Skill::sSkillNameIds[skillId]; - const MWWorld::ESMStore& esmStore = *MWBase::Environment::get().getESMStore(); const ESM::Skill* skill = esmStore.get().find(skillId); @@ -520,9 +518,8 @@ namespace MWGui const ESM::Attribute* attr = esmStore.get().find(skill->mData.mAttribute); - std::pair widgets = addValueItem( - MWBase::Environment::get().getWindowManager()->getGameSettingString(skillNameId, skillNameId), {}, - "normal", coord1, coord2); + std::pair widgets + = addValueItem(skill->mName, {}, "normal", coord1, coord2); mSkillWidgetMap[skillId] = widgets; for (int i = 0; i < 2; ++i) @@ -530,7 +527,7 @@ namespace MWGui mSkillWidgets[mSkillWidgets.size() - 1 - i]->setUserString("ToolTipType", "Layout"); mSkillWidgets[mSkillWidgets.size() - 1 - i]->setUserString("ToolTipLayout", "SkillToolTip"); mSkillWidgets[mSkillWidgets.size() - 1 - i]->setUserString( - "Caption_SkillName", "#{" + skillNameId + "}"); + "Caption_SkillName", MyGUI::TextIterator::toTagsString(skill->mName)); mSkillWidgets[mSkillWidgets.size() - 1 - i]->setUserString( "Caption_SkillDescription", skill->mDescription); mSkillWidgets[mSkillWidgets.size() - 1 - i]->setUserString( @@ -652,8 +649,8 @@ namespace MWGui text += ", "; firstSkill = false; - - text += "#{" + ESM::Skill::sSkillNameIds[faction->mData.mSkills[i]] + "}"; + const ESM::Skill* skill = store.get().find(faction->mData.mSkills[i]); + text += MyGUI::TextIterator::toTagsString(skill->mName); } } diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index 5c5d9176ff..b97e29af7d 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -810,18 +811,14 @@ namespace MWGui return; const MWWorld::ESMStore& store = *MWBase::Environment::get().getESMStore(); - - const std::string& skillNameId = ESM::Skill::sSkillNameIds[skillId]; const ESM::Skill* skill = store.get().find(skillId); - assert(skill); - const ESM::Attribute* attr = store.get().find(skill->mData.mAttribute); - assert(attr); + std::string icon = "icons\\k\\" + ESM::Skill::sIconNames[skillId]; widget->setUserString("ToolTipType", "Layout"); widget->setUserString("ToolTipLayout", "SkillNoProgressToolTip"); - widget->setUserString("Caption_SkillNoProgressName", "#{" + skillNameId + "}"); + widget->setUserString("Caption_SkillNoProgressName", MyGUI::TextIterator::toTagsString(skill->mName)); widget->setUserString("Caption_SkillNoProgressDescription", skill->mDescription); widget->setUserString("Caption_SkillNoProgressAttribute", "#{sGoverningAttribute}: #{" + attr->mName + "}"); widget->setUserString("ImageTexture_SkillNoProgressImage", icon); @@ -853,16 +850,16 @@ namespace MWGui const MWWorld::Store& skills = MWBase::Environment::get().getESMStore()->get(); bool isFirst = true; - for (auto& skillPair : skills) + for (const auto& [_, skill] : skills) { - if (skillPair.second.mData.mSpecialization == specId) + if (skill.mData.mSpecialization == specId) { if (isFirst) isFirst = false; else specText += "\n"; - specText += std::string("#{") + ESM::Skill::sSkillNameIds[skillPair.first] + "}"; + specText += MyGUI::TextIterator::toTagsString(skill.mName); } } widget->setUserString("Caption_ColumnText", specText); diff --git a/apps/openmw/mwgui/trainingwindow.cpp b/apps/openmw/mwgui/trainingwindow.cpp index 94647c839b..7b0e93edd0 100644 --- a/apps/openmw/mwgui/trainingwindow.cpp +++ b/apps/openmw/mwgui/trainingwindow.cpp @@ -2,6 +2,7 @@ #include #include +#include #include "../mwbase/environment.hpp" #include "../mwbase/mechanicsmanager.hpp" @@ -97,8 +98,9 @@ namespace MWGui MWMechanics::NpcStats& pcStats = player.getClass().getNpcStats(player); - const MWWorld::Store& gmst - = MWBase::Environment::get().getESMStore()->get(); + const auto& store = MWBase::Environment::get().getESMStore(); + const MWWorld::Store& gmst = store->get(); + const MWWorld::Store& skillStore = store->get(); const int lineHeight = MWBase::Environment::get().getWindowManager()->getFontHeight() + 2; @@ -118,8 +120,9 @@ namespace MWGui button->setUserData(skills[i].first); button->eventMouseButtonClick += MyGUI::newDelegate(this, &TrainingWindow::onTrainingSelected); + const ESM::Skill* skill = skillStore.find(skills[i].first); button->setCaptionWithReplacing( - "#{" + ESM::Skill::sSkillNameIds[skills[i].first] + "} - " + MyGUI::utility::toString(price)); + MyGUI::TextIterator::toTagsString(skill->mName) + " - " + MyGUI::utility::toString(price)); button->setSize(button->getTextSize().width + 12, button->getSize().height); diff --git a/apps/openmw/mwgui/widgets.cpp b/apps/openmw/mwgui/widgets.cpp index 10f7345fce..8523a85550 100644 --- a/apps/openmw/mwgui/widgets.cpp +++ b/apps/openmw/mwgui/widgets.cpp @@ -60,16 +60,11 @@ namespace MWGui::Widgets { if (mSkillNameWidget) { - if (mSkillId == ESM::Skill::Length) - { + const ESM::Skill* skill = MWBase::Environment::get().getESMStore()->get().search(mSkillId); + if (skill == nullptr) mSkillNameWidget->setCaption({}); - } else - { - MyGUI::UString name = toUString(MWBase::Environment::get().getWindowManager()->getGameSettingString( - ESM::Skill::sSkillNameIds[mSkillId], {})); - mSkillNameWidget->setCaption(name); - } + mSkillNameWidget->setCaption(skill->mName); } if (mSkillValueWidget) { @@ -379,6 +374,7 @@ namespace MWGui::Widgets const ESM::MagicEffect* magicEffect = store.get().search(mEffectParams.mEffectID); const ESM::Attribute* attribute = store.get().search(mEffectParams.mAttribute); + const ESM::Skill* skill = store.get().search(mEffectParams.mSkill); assert(magicEffect); @@ -394,7 +390,7 @@ namespace MWGui::Widgets std::string sec = " " + std::string{ windowManager->getGameSettingString("ssecond", {}) }; std::string secs = " " + std::string{ windowManager->getGameSettingString("sseconds", {}) }; - std::string spellLine = MWMechanics::getMagicEffectString(*magicEffect, attribute, mEffectParams.mSkill); + std::string spellLine = MWMechanics::getMagicEffectString(*magicEffect, attribute, skill); if (mEffectParams.mMagnMin || mEffectParams.mMagnMax) { diff --git a/apps/openmw/mwmechanics/alchemy.cpp b/apps/openmw/mwmechanics/alchemy.cpp index 3735962a95..acab0edefa 100644 --- a/apps/openmw/mwmechanics/alchemy.cpp +++ b/apps/openmw/mwmechanics/alchemy.cpp @@ -569,7 +569,6 @@ std::vector MWMechanics::Alchemy::effectsDescription(const MWWorld: for (auto i = 0; i < 4; ++i) { const auto effectID = data.mEffectID[i]; - const auto skillID = data.mSkills[i]; if (alchemySkill < fWortChanceValue * (i + 1)) break; @@ -577,7 +576,8 @@ std::vector MWMechanics::Alchemy::effectsDescription(const MWWorld: if (effectID != -1) { const ESM::Attribute* attribute = store->get().search(data.mAttributes[i]); - std::string effect = getMagicEffectString(*mgef.find(effectID), attribute, skillID); + const ESM::Skill* skill = store->get().search(data.mAttributes[i]); + std::string effect = getMagicEffectString(*mgef.find(effectID), attribute, skill); effects.push_back(effect); } diff --git a/apps/openmw/mwmechanics/magiceffects.cpp b/apps/openmw/mwmechanics/magiceffects.cpp index 9f5e781731..b3f7a89d00 100644 --- a/apps/openmw/mwmechanics/magiceffects.cpp +++ b/apps/openmw/mwmechanics/magiceffects.cpp @@ -53,7 +53,8 @@ namespace MWMechanics { const auto& store = MWBase::Environment::get().getESMStore(); const ESM::MagicEffect* magicEffect = store->get().search(mId); - return getMagicEffectString(*magicEffect, store->get().find(mArg), mArg); + return getMagicEffectString( + *magicEffect, store->get().search(mArg), store->get().search(mArg)); } bool operator<(const EffectKey& left, const EffectKey& right) @@ -227,9 +228,10 @@ namespace MWMechanics } } - std::string getMagicEffectString(const ESM::MagicEffect& effect, const ESM::Attribute* attribute, int skillArg) + std::string getMagicEffectString( + const ESM::MagicEffect& effect, const ESM::Attribute* attribute, const ESM::Skill* skill) { - const bool targetsSkill = effect.mData.mFlags & ESM::MagicEffect::TargetSkill && skillArg != -1; + const bool targetsSkill = effect.mData.mFlags & ESM::MagicEffect::TargetSkill && skill; const bool targetsAttribute = effect.mData.mFlags & ESM::MagicEffect::TargetAttribute && attribute; std::string spellLine; @@ -272,7 +274,7 @@ namespace MWMechanics if (targetsSkill) { spellLine += ' '; - spellLine += windowManager->getGameSettingString(ESM::Skill::sSkillNameIds[skillArg], {}); + spellLine += skill->mName; } else if (targetsAttribute) { diff --git a/apps/openmw/mwmechanics/magiceffects.hpp b/apps/openmw/mwmechanics/magiceffects.hpp index d53dd9e21e..e03f3db21f 100644 --- a/apps/openmw/mwmechanics/magiceffects.hpp +++ b/apps/openmw/mwmechanics/magiceffects.hpp @@ -12,6 +12,7 @@ namespace ESM struct EffectList; struct MagicEffect; struct MagicEffects; + struct Skill; } namespace MWMechanics @@ -114,7 +115,8 @@ namespace MWMechanics ///< Return changes from \a prev to \a now. }; - std::string getMagicEffectString(const ESM::MagicEffect& effect, const ESM::Attribute* attribute, int skillArg); + std::string getMagicEffectString( + const ESM::MagicEffect& effect, const ESM::Attribute* attribute, const ESM::Skill* skill); } #endif diff --git a/apps/openmw/mwmechanics/npcstats.cpp b/apps/openmw/mwmechanics/npcstats.cpp index 6f56af46ad..f92d4dad78 100644 --- a/apps/openmw/mwmechanics/npcstats.cpp +++ b/apps/openmw/mwmechanics/npcstats.cpp @@ -10,6 +10,8 @@ #include +#include + #include "../mwworld/esmstore.hpp" #include "../mwbase/environment.hpp" @@ -259,8 +261,8 @@ void MWMechanics::NpcStats::increaseSkill( MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("skillraise")); std::string message{ MWBase::Environment::get().getWindowManager()->getGameSettingString("sNotifyMessage39", {}) }; - message = Misc::StringUtils::format( - message, ("#{" + ESM::Skill::sSkillNameIds[skillIndex] + "}"), static_cast(base)); + message + = Misc::StringUtils::format(message, MyGUI::TextIterator::toTagsString(skill->mName), static_cast(base)); if (readBook) message = "#{sBookSkillMessage}\n" + message; diff --git a/apps/openmw/mwworld/esmstore.cpp b/apps/openmw/mwworld/esmstore.cpp index 598ec70a5c..29576709cc 100644 --- a/apps/openmw/mwworld/esmstore.cpp +++ b/apps/openmw/mwworld/esmstore.cpp @@ -445,7 +445,7 @@ namespace MWWorld for (const auto& [k, v] : mStoreImp->mIds) mStoreImp->mStaticIds.emplace(k, v); - getWritable().setUp(); + getWritable().setUp(get()); getWritable().setUp(); getWritable().setUp(); getWritable().updateLandPositions(get()); diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index d9520dc3b3..dd42476f64 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -901,6 +901,53 @@ namespace MWWorld Store::Store() {} + void Store::setUp(const MWWorld::Store settings) + { + constexpr std::string_view skillNameIds[ESM::Skill::Length] = { + "sSkillBlock", + "sSkillArmorer", + "sSkillMediumarmor", + "sSkillHeavyarmor", + "sSkillBluntweapon", + "sSkillLongblade", + "sSkillAxe", + "sSkillSpear", + "sSkillAthletics", + "sSkillEnchant", + "sSkillDestruction", + "sSkillAlteration", + "sSkillIllusion", + "sSkillConjuration", + "sSkillMysticism", + "sSkillRestoration", + "sSkillAlchemy", + "sSkillUnarmored", + "sSkillSecurity", + "sSkillSneak", + "sSkillAcrobatics", + "sSkillLightarmor", + "sSkillShortblade", + "sSkillMarksman", + "sSkillMercantile", + "sSkillSpeechcraft", + "sSkillHandtohand", + }; + for (int i = 0; i < ESM::Skill::Length; ++i) + { + auto found = mStatic.find(i); + if (found != mStatic.end()) + { + ESM::Skill& skill = found->second; + std::string_view id = skillNameIds[i]; + const ESM::GameSetting* setting = settings.search(id); + if (setting && setting->mValue.getType() == ESM::VT_String) + skill.mName = setting->mValue.getString(); + else + skill.mName = id; + } + } + } + // Game Settings //========================================================================= diff --git a/apps/openmw/mwworld/store.hpp b/apps/openmw/mwworld/store.hpp index c496d1ee0f..453f36db11 100644 --- a/apps/openmw/mwworld/store.hpp +++ b/apps/openmw/mwworld/store.hpp @@ -474,6 +474,8 @@ namespace MWWorld { public: Store(); + + void setUp(const MWWorld::Store settings); }; template <> diff --git a/components/esm3/loadskil.cpp b/components/esm3/loadskil.cpp index ec110702b6..0115e84e34 100644 --- a/components/esm3/loadskil.cpp +++ b/components/esm3/loadskil.cpp @@ -36,35 +36,6 @@ namespace ESM "Speechcraft", "Handtohand", }; - const std::string Skill::sSkillNameIds[Length] = { - "sSkillBlock", - "sSkillArmorer", - "sSkillMediumarmor", - "sSkillHeavyarmor", - "sSkillBluntweapon", - "sSkillLongblade", - "sSkillAxe", - "sSkillSpear", - "sSkillAthletics", - "sSkillEnchant", - "sSkillDestruction", - "sSkillAlteration", - "sSkillIllusion", - "sSkillConjuration", - "sSkillMysticism", - "sSkillRestoration", - "sSkillAlchemy", - "sSkillUnarmored", - "sSkillSecurity", - "sSkillSneak", - "sSkillAcrobatics", - "sSkillLightarmor", - "sSkillShortblade", - "sSkillMarksman", - "sSkillMercantile", - "sSkillSpeechcraft", - "sSkillHandtohand", - }; const std::string Skill::sIconNames[Length] = { "combat_block.dds", "combat_armor.dds", diff --git a/components/esm3/loadskil.hpp b/components/esm3/loadskil.hpp index ce2d3bf531..5ceec6ffa7 100644 --- a/components/esm3/loadskil.hpp +++ b/components/esm3/loadskil.hpp @@ -44,6 +44,7 @@ namespace ESM int mIndex; std::string mDescription; + std::string mName; enum SkillEnum { @@ -77,7 +78,6 @@ namespace ESM Length }; static const std::string sSkillNames[Length]; - static const std::string sSkillNameIds[Length]; static const std::string sIconNames[Length]; static SkillEnum stringToSkillId(std::string_view skill);