Use a regular TypedDynamicStore for ESM:Skill

revert-6246b479
Evil Eye 2 years ago
parent 75c371de66
commit 16c0f0d5cc

@ -99,7 +99,7 @@ namespace MWGui
mPlayerAttributes.emplace(attribute.mId, MWMechanics::AttributeValue()); mPlayerAttributes.emplace(attribute.mId, MWMechanics::AttributeValue());
for (const auto& skill : store.get<ESM::Skill>()) for (const auto& skill : store.get<ESM::Skill>())
mPlayerSkillValues.emplace(skill.second.mIndex, MWMechanics::SkillValue()); mPlayerSkillValues.emplace(skill.mIndex, MWMechanics::SkillValue());
} }
void CharacterCreation::setValue(std::string_view id, const MWMechanics::AttributeValue& value) void CharacterCreation::setValue(std::string_view id, const MWMechanics::AttributeValue& value)

@ -236,10 +236,10 @@ namespace MWGui
std::copy(minor.begin(), minor.end(), std::inserter(skillSet, skillSet.begin())); std::copy(minor.begin(), minor.end(), std::inserter(skillSet, skillSet.begin()));
mMiscSkills.clear(); mMiscSkills.clear();
const auto& store = MWBase::Environment::get().getWorld()->getStore().get<ESM::Skill>(); const auto& store = MWBase::Environment::get().getWorld()->getStore().get<ESM::Skill>();
for (const auto& skill : store) for (const ESM::Skill& skill : store)
{ {
if (!skillSet.contains(skill.second.mIndex)) if (!skillSet.contains(skill.mIndex))
mMiscSkills.push_back(skill.second.mIndex); mMiscSkills.push_back(skill.mIndex);
} }
mUpdateSkillArea = true; mUpdateSkillArea = true;
@ -339,12 +339,13 @@ namespace MWGui
addGroup( addGroup(
MWBase::Environment::get().getWindowManager()->getGameSettingString(titleId, titleDefault), coord1, coord2); MWBase::Environment::get().getWindowManager()->getGameSettingString(titleId, titleDefault), coord1, coord2);
for (const int& skillId : skills) for (const int& skillIndex : skills)
{ {
const ESM::Skill* skill = MWBase::Environment::get().getESMStore()->get<ESM::Skill>().search(skillId); const ESM::Skill* skill = MWBase::Environment::get().getESMStore()->get<ESM::Skill>().search(
if (!skill) // Skip unknown skill indexes ESM::Skill::indexToRefId(skillIndex));
if (!skill) // Skip unknown skills
continue; continue;
const MWMechanics::SkillValue& stat = mSkillValues.find(skillId)->second; const MWMechanics::SkillValue& stat = mSkillValues.find(skill->mIndex)->second;
int base = stat.getBase(); int base = stat.getBase();
int modified = stat.getModified(); int modified = stat.getModified();
@ -358,10 +359,10 @@ namespace MWGui
for (int i = 0; i < 2; ++i) for (int i = 0; i < 2; ++i)
{ {
ToolTips::createSkillToolTip(mSkillWidgets[mSkillWidgets.size() - 1 - i], skillId); ToolTips::createSkillToolTip(mSkillWidgets[mSkillWidgets.size() - 1 - i], skill->mIndex);
} }
mSkillWidgetMap[skillId] = widget; mSkillWidgetMap[skill->mIndex] = widget;
} }
} }

@ -55,7 +55,7 @@ namespace MWGui
{ {
const ESM::MagicEffect* magicEffect = store.get<ESM::MagicEffect>().find(effectId); const ESM::MagicEffect* magicEffect = store.get<ESM::MagicEffect>().find(effectId);
const ESM::Attribute* attribute = store.get<ESM::Attribute>().search(effect.mAttribute); const ESM::Attribute* attribute = store.get<ESM::Attribute>().search(effect.mAttribute);
const ESM::Skill* skill = store.get<ESM::Skill>().search(effect.mSkill); const ESM::Skill* skill = store.get<ESM::Skill>().search(ESM::Skill::indexToRefId(effect.mSkill));
std::string fullEffectName = MWMechanics::getMagicEffectString(*magicEffect, attribute, skill); std::string fullEffectName = MWMechanics::getMagicEffectString(*magicEffect, attribute, skill);
std::string convert = Utf8Stream::lowerCaseUtf8(fullEffectName); std::string convert = Utf8Stream::lowerCaseUtf8(fullEffectName);

@ -327,8 +327,8 @@ namespace MWGui
const auto& store = MWBase::Environment::get().getWorld()->getStore().get<ESM::Skill>(); const auto& store = MWBase::Environment::get().getWorld()->getStore().get<ESM::Skill>();
for (const auto& skill : store) for (const auto& skill : store)
{ {
if (!skillSet.contains(skill.second.mIndex)) if (!skillSet.contains(skill.mIndex))
mMiscSkills.push_back(skill.second.mIndex); mMiscSkills.push_back(skill.mIndex);
} }
updateSkillArea(); updateSkillArea();
@ -504,13 +504,12 @@ namespace MWGui
addGroup( addGroup(
MWBase::Environment::get().getWindowManager()->getGameSettingString(titleId, titleDefault), coord1, coord2); MWBase::Environment::get().getWindowManager()->getGameSettingString(titleId, titleDefault), coord1, coord2);
const MWWorld::ESMStore& esmStore = *MWBase::Environment::get().getESMStore();
for (const int skillId : skills) for (const int skillId : skills)
{ {
if (skillId < 0 || skillId >= ESM::Skill::Length) // Skip unknown skill indexes const ESM::Skill* skill = esmStore.get<ESM::Skill>().search(ESM::Skill::indexToRefId(skillId));
if (!skill) // Skip unknown skills
continue; continue;
const MWWorld::ESMStore& esmStore = *MWBase::Environment::get().getESMStore();
const ESM::Skill* skill = esmStore.get<ESM::Skill>().find(skillId);
const ESM::Attribute* attr = esmStore.get<ESM::Attribute>().find(skill->mData.mAttribute); const ESM::Attribute* attr = esmStore.get<ESM::Attribute>().find(skill->mData.mAttribute);
@ -640,13 +639,13 @@ namespace MWGui
bool firstSkill = true; bool firstSkill = true;
for (int id : faction->mData.mSkills) for (int id : faction->mData.mSkills)
{ {
if (id != -1) const ESM::Skill* skill = store.get<ESM::Skill>().search(ESM::Skill::indexToRefId(id));
if (skill)
{ {
if (!firstSkill) if (!firstSkill)
text += ", "; text += ", ";
firstSkill = false; firstSkill = false;
const ESM::Skill* skill = store.get<ESM::Skill>().find(id);
text += MyGUI::TextIterator::toTagsString(skill->mName); text += MyGUI::TextIterator::toTagsString(skill->mName);
} }
} }

@ -846,7 +846,7 @@ namespace MWGui
const MWWorld::Store<ESM::Skill>& skills = MWBase::Environment::get().getESMStore()->get<ESM::Skill>(); const MWWorld::Store<ESM::Skill>& skills = MWBase::Environment::get().getESMStore()->get<ESM::Skill>();
bool isFirst = true; bool isFirst = true;
for (const auto& [_, skill] : skills) for (const auto& skill : skills)
{ {
if (skill.mData.mSpecialization == specId) if (skill.mData.mSpecialization == specId)
{ {

@ -60,7 +60,8 @@ namespace MWGui::Widgets
{ {
if (mSkillNameWidget) if (mSkillNameWidget)
{ {
const ESM::Skill* skill = MWBase::Environment::get().getESMStore()->get<ESM::Skill>().search(mSkillId); const ESM::Skill* skill = MWBase::Environment::get().getESMStore()->get<ESM::Skill>().search(
ESM::Skill::indexToRefId(mSkillId));
if (skill == nullptr) if (skill == nullptr)
mSkillNameWidget->setCaption({}); mSkillNameWidget->setCaption({});
else else
@ -374,7 +375,7 @@ namespace MWGui::Widgets
const ESM::MagicEffect* magicEffect = store.get<ESM::MagicEffect>().search(mEffectParams.mEffectID); const ESM::MagicEffect* magicEffect = store.get<ESM::MagicEffect>().search(mEffectParams.mEffectID);
const ESM::Attribute* attribute = store.get<ESM::Attribute>().search(mEffectParams.mAttribute); const ESM::Attribute* attribute = store.get<ESM::Attribute>().search(mEffectParams.mAttribute);
const ESM::Skill* skill = store.get<ESM::Skill>().search(mEffectParams.mSkill); const ESM::Skill* skill = store.get<ESM::Skill>().search(ESM::Skill::indexToRefId(mEffectParams.mSkill));
assert(magicEffect); assert(magicEffect);

@ -576,7 +576,7 @@ std::vector<std::string> MWMechanics::Alchemy::effectsDescription(const MWWorld:
if (effectID != -1) if (effectID != -1)
{ {
const ESM::Attribute* attribute = store->get<ESM::Attribute>().search(data.mAttributes[i]); const ESM::Attribute* attribute = store->get<ESM::Attribute>().search(data.mAttributes[i]);
const ESM::Skill* skill = store->get<ESM::Skill>().search(data.mAttributes[i]); const ESM::Skill* skill = store->get<ESM::Skill>().search(ESM::Skill::indexToRefId(data.mSkills[i]));
std::string effect = getMagicEffectString(*mgef.find(effectID), attribute, skill); std::string effect = getMagicEffectString(*mgef.find(effectID), attribute, skill);
effects.push_back(effect); effects.push_back(effect);

@ -53,8 +53,8 @@ namespace MWMechanics
{ {
const auto& store = MWBase::Environment::get().getESMStore(); const auto& store = MWBase::Environment::get().getESMStore();
const ESM::MagicEffect* magicEffect = store->get<ESM::MagicEffect>().search(mId); const ESM::MagicEffect* magicEffect = store->get<ESM::MagicEffect>().search(mId);
return getMagicEffectString( return getMagicEffectString(*magicEffect, store->get<ESM::Attribute>().search(mArg),
*magicEffect, store->get<ESM::Attribute>().search(mArg), store->get<ESM::Skill>().search(mArg)); store->get<ESM::Skill>().search(ESM::Skill::indexToRefId(mArg)));
} }
bool operator<(const EffectKey& left, const EffectKey& right) bool operator<(const EffectKey& left, const EffectKey& right)

@ -214,14 +214,11 @@ namespace MWMechanics
} }
} }
const MWWorld::Store<ESM::Skill>& skills = esmStore.get<ESM::Skill>(); for (const ESM::Skill& skill : esmStore.get<ESM::Skill>())
MWWorld::Store<ESM::Skill>::iterator iter = skills.begin();
for (; iter != skills.end(); ++iter)
{ {
if (iter->second.mData.mSpecialization == class_->mData.mSpecialization) if (skill.mData.mSpecialization == class_->mData.mSpecialization)
{ {
int index = iter->first; int index = skill.mIndex;
if (index >= 0 && index < 27) if (index >= 0 && index < 27)
{ {

@ -103,7 +103,7 @@ namespace MWWorld
npcStats.setAttribute(attribute.mId, value); npcStats.setAttribute(attribute.mId, value);
} }
for (const auto& [_, skill] : store->get<ESM::Skill>()) for (const auto& skill : store->get<ESM::Skill>())
{ {
// Acrobatics is set separately for some reason. // Acrobatics is set separately for some reason.
if (skill.mIndex == ESM::Skill::Acrobatics) if (skill.mIndex == ESM::Skill::Acrobatics)

@ -113,7 +113,6 @@ namespace MWWorld
// Need to instantiate these before they're used // Need to instantiate these before they're used
template class IndexedStore<ESM::MagicEffect>; template class IndexedStore<ESM::MagicEffect>;
template class IndexedStore<ESM::Skill>;
template <class T, class Id> template <class T, class Id>
TypedDynamicStore<T, Id>::TypedDynamicStore() TypedDynamicStore<T, Id>::TypedDynamicStore()
@ -915,8 +914,6 @@ namespace MWWorld
// Skill // Skill
//========================================================================= //=========================================================================
Store<ESM::Skill>::Store() {}
void Store<ESM::Skill>::setUp(const MWWorld::Store<ESM::GameSetting>& settings) void Store<ESM::Skill>::setUp(const MWWorld::Store<ESM::GameSetting>& settings)
{ {
constexpr std::string_view skillValues[ESM::Skill::Length][3] = { constexpr std::string_view skillValues[ESM::Skill::Length][3] = {
@ -949,15 +946,13 @@ namespace MWWorld
{ "sSkillSpeechcraft", "icons\\k\\stealth_speechcraft.dds", "fWerewolfSpeechcraft" }, { "sSkillSpeechcraft", "icons\\k\\stealth_speechcraft.dds", "fWerewolfSpeechcraft" },
{ "sSkillHandtohand", "icons\\k\\stealth_handtohand.dds", "fWerewolfHandtohand" }, { "sSkillHandtohand", "icons\\k\\stealth_handtohand.dds", "fWerewolfHandtohand" },
}; };
for (int i = 0; i < ESM::Skill::Length; ++i) for (ESM::Skill* skill : mShared)
{ {
auto found = mStatic.find(i); if (skill->mIndex >= 0)
if (found != mStatic.end())
{ {
ESM::Skill& skill = found->second; skill->mName = getGMSTString(settings, skillValues[skill->mIndex][0]);
skill.mName = getGMSTString(settings, skillValues[i][0]); skill->mIcon = skillValues[skill->mIndex][1];
skill.mIcon = skillValues[i][1]; skill->mWerewolfValue = getGMSTFloat(settings, skillValues[skill->mIndex][2]);
skill.mWerewolfValue = getGMSTFloat(settings, skillValues[i][2]);
} }
} }
} }
@ -1344,7 +1339,7 @@ template class MWWorld::TypedDynamicStore<ESM::Race>;
template class MWWorld::TypedDynamicStore<ESM::Region>; template class MWWorld::TypedDynamicStore<ESM::Region>;
template class MWWorld::TypedDynamicStore<ESM::Repair>; template class MWWorld::TypedDynamicStore<ESM::Repair>;
template class MWWorld::TypedDynamicStore<ESM::Script>; template class MWWorld::TypedDynamicStore<ESM::Script>;
// template class MWWorld::Store<ESM::Skill>; template class MWWorld::TypedDynamicStore<ESM::Skill>;
template class MWWorld::TypedDynamicStore<ESM::Sound>; template class MWWorld::TypedDynamicStore<ESM::Sound>;
template class MWWorld::TypedDynamicStore<ESM::SoundGenerator>; template class MWWorld::TypedDynamicStore<ESM::SoundGenerator>;
template class MWWorld::TypedDynamicStore<ESM::Spell>; template class MWWorld::TypedDynamicStore<ESM::Spell>;

@ -17,6 +17,7 @@
#include <components/esm3/loadgmst.hpp> #include <components/esm3/loadgmst.hpp>
#include <components/esm3/loadland.hpp> #include <components/esm3/loadland.hpp>
#include <components/esm3/loadpgrd.hpp> #include <components/esm3/loadpgrd.hpp>
#include <components/esm3/loadskil.hpp>
#include <components/esm4/loadcell.hpp> #include <components/esm4/loadcell.hpp>
#include <components/esm4/loadland.hpp> #include <components/esm4/loadland.hpp>
#include <components/esm4/loadrefr.hpp> #include <components/esm4/loadrefr.hpp>
@ -30,7 +31,6 @@ namespace ESM
struct Attribute; struct Attribute;
struct LandTexture; struct LandTexture;
struct MagicEffect; struct MagicEffect;
struct Skill;
struct WeaponType; struct WeaponType;
class ESMReader; class ESMReader;
class ESMWriter; class ESMWriter;
@ -476,10 +476,14 @@ namespace MWWorld
}; };
template <> template <>
class Store<ESM::Skill> : public IndexedStore<ESM::Skill> class Store<ESM::Skill> : public TypedDynamicStore<ESM::Skill>
{ {
public: public:
Store(); Store() = default;
using TypedDynamicStore<ESM::Skill>::find;
// TODO delete
const ESM::Skill* find(int index) const { return find(ESM::Skill::indexToRefId(index)); }
void setUp(const MWWorld::Store<ESM::GameSetting>& settings); void setUp(const MWWorld::Store<ESM::GameSetting>& settings);
}; };

@ -75,6 +75,8 @@ namespace ESM
} }
if (!hasIndex) if (!hasIndex)
esm.fail("Missing INDX"); esm.fail("Missing INDX");
else if (mIndex < 0 || mIndex >= Length)
esm.fail("Invalid INDX");
if (!hasData) if (!hasData)
esm.fail("Missing SKDT"); esm.fail("Missing SKDT");
@ -101,7 +103,7 @@ namespace ESM
RefId Skill::indexToRefId(int index) RefId Skill::indexToRefId(int index)
{ {
if (index == -1) if (index < 0 || index >= Length)
return RefId(); return RefId();
return RefId::index(sRecordId, static_cast<std::uint32_t>(index)); return RefId::index(sRecordId, static_cast<std::uint32_t>(index));
} }

@ -41,7 +41,7 @@ namespace ESM
// Skill index. Skils don't have an id ("NAME") like most records, // Skill index. Skils don't have an id ("NAME") like most records,
// they only have a numerical index that matches one of the // they only have a numerical index that matches one of the
// hard-coded skills in the game. // hard-coded skills in the game.
int mIndex; int mIndex{ -1 };
std::string mDescription; std::string mDescription;
std::string mName; std::string mName;

Loading…
Cancel
Save