1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-03-27 12:40:25 +00:00

Merge branch 'stringrefidskills' into 'master'

Assign StringRefIds to skills

See merge request OpenMW/openmw!3146
This commit is contained in:
psi29a 2023-07-20 07:15:49 +00:00
commit 03dbe1c9f3
21 changed files with 444 additions and 325 deletions

View file

@ -1264,7 +1264,8 @@ namespace EsmTool
template <> template <>
void Record<ESM::Skill>::print() void Record<ESM::Skill>::print()
{ {
std::cout << " ID: " << skillLabel(mData.mIndex) << " (" << mData.mIndex << ")" << std::endl; int index = ESM::Skill::refIdToIndex(mData.mId);
std::cout << " ID: " << skillLabel(index) << " (" << index << ")" << std::endl;
std::cout << " Description: " << mData.mDescription << std::endl; std::cout << " Description: " << mData.mDescription << std::endl;
std::cout << " Governing Attribute: " << attributeLabel(mData.mData.mAttribute) << " (" std::cout << " Governing Attribute: " << attributeLabel(mData.mData.mAttribute) << " ("
<< mData.mData.mAttribute << ")" << std::endl; << mData.mData.mAttribute << ")" << std::endl;

View file

@ -201,11 +201,10 @@ void CSMDoc::Document::createBase()
addGmsts(); addGmsts();
for (int i = 0; i < 27; ++i) for (int i = 0; i < ESM::Skill::Length; ++i)
{ {
ESM::Skill record; ESM::Skill record;
record.mIndex = i; record.mId = *ESM::Skill::indexToRefId(i).getIf<ESM::SkillId>();
record.mId = ESM::Skill::indexToRefId(record.mIndex);
record.blank(); record.blank();
getData().getSkills().add(record); getData().getSkills().add(record);

View file

@ -15,6 +15,7 @@
#include <QVariant> #include <QVariant>
#include <components/esm3/loaddial.hpp> #include <components/esm3/loaddial.hpp>
#include <components/esm3/loadskil.hpp>
#include <components/misc/strings/lower.hpp> #include <components/misc/strings/lower.hpp>
#include "collectionbase.hpp" #include "collectionbase.hpp"
@ -86,6 +87,13 @@ namespace CSMWorld
return ESM::RefId::stringRefId(LandTexture::createUniqueRecordId(record.mPluginIndex, record.mIndex)); return ESM::RefId::stringRefId(LandTexture::createUniqueRecordId(record.mPluginIndex, record.mIndex));
} }
inline void setRecordId(const ESM::RefId& id, ESM::Skill& record)
{
if (const auto* skillId = id.getIf<ESM::SkillId>())
record.mId = *skillId;
throw std::runtime_error("Invalid skill id: " + id.toDebugString());
}
/// \brief Single-type record collection /// \brief Single-type record collection
template <typename ESXRecordT> template <typename ESXRecordT>
class Collection : public CollectionBase class Collection : public CollectionBase

View file

@ -26,8 +26,6 @@ namespace CSMWorld
{ {
switch (value.getRecordType()) switch (value.getRecordType())
{ {
case ESM::REC_SKIL:
return ESM::Skill::sSkillNames[value.getValue()];
case ESM::REC_MGEF: case ESM::REC_MGEF:
return std::string(ESM::MagicEffect::sIndexNames[value.getValue()]); return std::string(ESM::MagicEffect::sIndexNames[value.getValue()]);
default: default:
@ -335,10 +333,10 @@ namespace CSMWorld
std::optional<std::uint32_t> getSkillIndex(std::string_view value) std::optional<std::uint32_t> getSkillIndex(std::string_view value)
{ {
const auto it = std::find(std::begin(ESM::Skill::sSkillNames), std::end(ESM::Skill::sSkillNames), value); int index = ESM::Skill::refIdToIndex(ESM::RefId::stringRefId(value));
if (it == std::end(ESM::Skill::sSkillNames)) if (index < 0)
return std::nullopt; return std::nullopt;
return static_cast<std::uint32_t>(it - std::begin(ESM::Skill::sSkillNames)); return static_cast<std::uint32_t>(index);
} }
std::string getStringId(ESM::RefId value) std::string getStringId(ESM::RefId value)

View file

@ -409,7 +409,8 @@ namespace CSMWorld
QVariant get(const Record<ESXRecordT>& record) const override QVariant get(const Record<ESXRecordT>& record) const override
{ {
return QString::fromStdString(ESM::Skill::sSkillNames[record.get().mData.getSkill(mIndex, mMajor)]); return QString::fromStdString(
ESM::Skill::indexToRefId(record.get().mData.getSkill(mIndex, mMajor)).getRefIdString());
} }
void set(Record<ESXRecordT>& record, const QVariant& data) override void set(Record<ESXRecordT>& record, const QVariant& data) override

View file

@ -121,11 +121,12 @@ namespace
// is this a minor or major skill? // is this a minor or major skill?
float add = 0.2f; float add = 0.2f;
int index = ESM::Skill::refIdToIndex(skill.mId);
for (const auto& skills : class_->mData.mSkills) for (const auto& skills : class_->mData.mSkills)
{ {
if (skills[0] == skill.mIndex) if (skills[0] == index)
add = 0.5; add = 0.5;
if (skills[1] == skill.mIndex) if (skills[1] == index)
add = 1.0; add = 1.0;
} }
modifierSum += add; modifierSum += add;
@ -199,15 +200,16 @@ namespace
int raceBonus = 0; int raceBonus = 0;
int specBonus = 0; int specBonus = 0;
int index = ESM::Skill::refIdToIndex(skill.mId);
auto bonusIt = std::find_if(race->mData.mBonus.begin(), race->mData.mBonus.end(), auto bonusIt = std::find_if(race->mData.mBonus.begin(), race->mData.mBonus.end(),
[&](const auto& bonus) { return bonus.mSkill == skill.mIndex; }); [&](const auto& bonus) { return bonus.mSkill == index; });
if (bonusIt != race->mData.mBonus.end()) if (bonusIt != race->mData.mBonus.end())
raceBonus = bonusIt->mBonus; raceBonus = bonusIt->mBonus;
for (const auto& skills : class_->mData.mSkills) for (const auto& skills : class_->mData.mSkills)
{ {
// is this a minor or major skill? // is this a minor or major skill?
if (std::find(skills.begin(), skills.end(), skill.mIndex) != skills.end()) if (std::find(skills.begin(), skills.end(), index) != skills.end())
{ {
majorMultiplier = 1.0f; majorMultiplier = 1.0f;
break; break;

View file

@ -471,8 +471,8 @@ namespace MWGui
assert(minorSkills.size() >= klass.mData.mSkills.size()); assert(minorSkills.size() >= klass.mData.mSkills.size());
for (size_t i = 0; i < klass.mData.mSkills.size(); ++i) for (size_t i = 0; i < klass.mData.mSkills.size(); ++i)
{ {
klass.mData.mSkills[i][1] = majorSkills[i].getIf<ESM::IndexRefId>()->getValue(); klass.mData.mSkills[i][1] = ESM::Skill::refIdToIndex(majorSkills[i]);
klass.mData.mSkills[i][0] = minorSkills[i].getIf<ESM::IndexRefId>()->getValue(); klass.mData.mSkills[i][0] = ESM::Skill::refIdToIndex(minorSkills[i]);
} }
MWBase::Environment::get().getMechanicsManager()->setPlayerClass(klass); MWBase::Environment::get().getMechanicsManager()->setPlayerClass(klass);

View file

@ -287,7 +287,7 @@ namespace MWGui
void EditEffectDialog::setSkill(ESM::RefId skill) void EditEffectDialog::setSkill(ESM::RefId skill)
{ {
mEffect.mSkill = skill.getIf<ESM::IndexRefId>()->getValue(); mEffect.mSkill = ESM::Skill::refIdToIndex(skill);
eventEffectModified(mEffect); eventEffectModified(mEffect);
} }

View file

@ -14,6 +14,7 @@
#include <components/lua/l10n.hpp> #include <components/lua/l10n.hpp>
#include <components/lua/luastate.hpp> #include <components/lua/luastate.hpp>
#include <components/lua/utilpackage.hpp> #include <components/lua/utilpackage.hpp>
#include <components/misc/strings/lower.hpp>
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/statemanager.hpp" #include "../mwbase/statemanager.hpp"
@ -156,10 +157,18 @@ namespace MWLua
return sol::nil; return sol::nil;
}; };
sol::table skill(context.mLua->sol(), sol::create); // TODO: deprecate this and provide access to the store instead
api["SKILL"] = LuaUtil::makeStrictReadOnly(skill); sol::table skills(context.mLua->sol(), sol::create);
for (int id = 0; id < ESM::Skill::Length; ++id) api["SKILL"] = LuaUtil::makeStrictReadOnly(skills);
skill[ESM::Skill::sSkillNames[id]] = Misc::StringUtils::lowerCase(ESM::Skill::sSkillNames[id]); for (int i = 0; i < ESM::Skill::Length; ++i)
{
ESM::RefId skill = ESM::Skill::indexToRefId(i);
std::string id = skill.serializeText();
std::string key = Misc::StringUtils::lowerCase(skill.getRefIdString());
// force first character to uppercase for backwards compatability
key[0] += 'A' - 'a';
skills[key] = id;
}
sol::table attribute(context.mLua->sol(), sol::create); sol::table attribute(context.mLua->sol(), sol::create);
api["ATTRIBUTE"] = LuaUtil::makeStrictReadOnly(attribute); api["ATTRIBUTE"] = LuaUtil::makeStrictReadOnly(attribute);

View file

@ -309,10 +309,10 @@ namespace MWLua
}); });
effectParamsT["affectedSkill"] effectParamsT["affectedSkill"]
= sol::readonly_property([](const ESM::ENAMstruct& params) -> sol::optional<std::string> { = sol::readonly_property([](const ESM::ENAMstruct& params) -> sol::optional<std::string> {
if (params.mSkill >= 0 && params.mSkill < ESM::Skill::Length) ESM::RefId id = ESM::Skill::indexToRefId(params.mSkill);
return Misc::StringUtils::lowerCase(ESM::Skill::sSkillNames[params.mSkill]); if (!id.empty())
else return id.serializeText();
return sol::nullopt; return sol::nullopt;
}); });
effectParamsT["affectedAttribute"] effectParamsT["affectedAttribute"]
= sol::readonly_property([](const ESM::ENAMstruct& params) -> sol::optional<std::string> { = sol::readonly_property([](const ESM::ENAMstruct& params) -> sol::optional<std::string> {
@ -383,11 +383,12 @@ namespace MWLua
activeEffectT["affectedSkill"] activeEffectT["affectedSkill"]
= sol::readonly_property([magicEffectStore](const ActiveEffect& effect) -> sol::optional<std::string> { = sol::readonly_property([magicEffectStore](const ActiveEffect& effect) -> sol::optional<std::string> {
auto* rec = magicEffectStore->find(effect.key.mId); auto* rec = magicEffectStore->find(effect.key.mId);
if ((rec->mData.mFlags & ESM::MagicEffect::TargetSkill) && effect.key.mArg >= 0 if (rec->mData.mFlags & ESM::MagicEffect::TargetSkill)
&& effect.key.mArg < ESM::Skill::Length) {
return Misc::StringUtils::lowerCase(ESM::Skill::sSkillNames[effect.key.mArg]); ESM::RefId id = ESM::Skill::indexToRefId(effect.key.mArg);
else return id.serializeText();
return sol::nullopt; }
return sol::nullopt;
}); });
activeEffectT["affectedAttribute"] activeEffectT["affectedAttribute"]
= sol::readonly_property([magicEffectStore](const ActiveEffect& effect) -> sol::optional<std::string> { = sol::readonly_property([magicEffectStore](const ActiveEffect& effect) -> sol::optional<std::string> {
@ -620,7 +621,10 @@ namespace MWLua
key = MWMechanics::EffectKey(id, ESM::Attribute::stringToAttributeId(argStr.value())); key = MWMechanics::EffectKey(id, ESM::Attribute::stringToAttributeId(argStr.value()));
if (rec->mData.mFlags & ESM::MagicEffect::TargetSkill) if (rec->mData.mFlags & ESM::MagicEffect::TargetSkill)
key = MWMechanics::EffectKey(id, ESM::Skill::stringToSkillId(argStr.value())); {
ESM::RefId skill = ESM::RefId::deserializeText(argStr.value());
key = MWMechanics::EffectKey(id, ESM::Skill::refIdToIndex(skill));
}
} }
return key; return key;

View file

@ -392,7 +392,6 @@ namespace MWLua
sol::table skills(context.mLua->sol(), sol::create); sol::table skills(context.mLua->sol(), sol::create);
npcStats["skills"] = LuaUtil::makeReadOnly(skills); npcStats["skills"] = LuaUtil::makeReadOnly(skills);
for (const ESM::Skill& skill : MWBase::Environment::get().getESMStore()->get<ESM::Skill>()) for (const ESM::Skill& skill : MWBase::Environment::get().getESMStore()->get<ESM::Skill>())
skills[Misc::StringUtils::lowerCase(ESM::Skill::sSkillNames[skill.mIndex])] skills[ESM::RefId(skill.mId).serializeText()] = addIndexedAccessor<SkillStat>(skill.mId);
= addIndexedAccessor<SkillStat>(skill.mId);
} }
} }

View file

@ -41,18 +41,14 @@ namespace
book.mData.mValue = rec["value"]; book.mData.mValue = rec["value"];
book.mData.mIsScroll = rec["isScroll"]; book.mData.mIsScroll = rec["isScroll"];
std::string_view skill = rec["skill"].get<std::string_view>(); ESM::RefId skill = ESM::RefId::deserializeText(rec["skill"].get<std::string_view>());
book.mData.mSkillId = -1; book.mData.mSkillId = -1;
if (skill.length() > 0) if (!skill.empty())
{ {
for (std::size_t i = 0; i < std::size(ESM::Skill::sSkillNames); ++i) book.mData.mSkillId = ESM::Skill::refIdToIndex(skill);
{
if (Misc::StringUtils::ciEqual(ESM::Skill::sSkillNames[i], skill))
book.mData.mSkillId = i;
}
if (book.mData.mSkillId == -1) if (book.mData.mSkillId == -1)
throw std::runtime_error("Incorrect skill: " + std::string(skill)); throw std::runtime_error("Incorrect skill: " + skill.toDebugString());
} }
return book; return book;
} }
@ -69,7 +65,7 @@ namespace MWLua
book["createRecordDraft"] = tableToBook; book["createRecordDraft"] = tableToBook;
for (int id = 0; id < ESM::Skill::Length; ++id) for (int id = 0; id < ESM::Skill::Length; ++id)
{ {
std::string skillName = Misc::StringUtils::lowerCase(ESM::Skill::sSkillNames[id]); std::string skillName = ESM::Skill::indexToRefId(id).serializeText();
skill[skillName] = skillName; skill[skillName] = skillName;
} }
@ -100,10 +96,10 @@ namespace MWLua
record["enchantCapacity"] record["enchantCapacity"]
= sol::readonly_property([](const ESM::Book& rec) -> float { return rec.mData.mEnchant * 0.1f; }); = sol::readonly_property([](const ESM::Book& rec) -> float { return rec.mData.mEnchant * 0.1f; });
record["skill"] = sol::readonly_property([](const ESM::Book& rec) -> sol::optional<std::string> { record["skill"] = sol::readonly_property([](const ESM::Book& rec) -> sol::optional<std::string> {
if (rec.mData.mSkillId >= 0) ESM::RefId skill = ESM::Skill::indexToRefId(rec.mData.mSkillId);
return Misc::StringUtils::lowerCase(ESM::Skill::sSkillNames[rec.mData.mSkillId]); if (!skill.empty())
else return skill.serializeText();
return sol::nullopt; return sol::nullopt;
}); });
} }
} }

View file

@ -158,9 +158,9 @@ namespace MWMechanics
for (const ESM::Skill& skill : esmStore.get<ESM::Skill>()) for (const ESM::Skill& skill : esmStore.get<ESM::Skill>())
{ {
int bonus = 0; int bonus = 0;
int index = ESM::Skill::refIdToIndex(skill.mId);
auto bonusIt = std::find_if(race->mData.mBonus.begin(), race->mData.mBonus.end(), auto bonusIt = std::find_if(race->mData.mBonus.begin(), race->mData.mBonus.end(),
[&](const auto& bonus) { return bonus.mSkill == skill.mIndex; }); [&](const auto& bonus) { return bonus.mSkill == index; });
if (bonusIt != race->mData.mBonus.end()) if (bonusIt != race->mData.mBonus.end())
bonus = bonusIt->mBonus; bonus = bonusIt->mBonus;

View file

@ -155,15 +155,15 @@ float MWMechanics::NpcStats::getSkillProgressRequirement(ESM::RefId id, const ES
const ESM::Skill* skill = MWBase::Environment::get().getESMStore()->get<ESM::Skill>().find(id); const ESM::Skill* skill = MWBase::Environment::get().getESMStore()->get<ESM::Skill>().find(id);
float typeFactor = gmst.find("fMiscSkillBonus")->mValue.getFloat(); float typeFactor = gmst.find("fMiscSkillBonus")->mValue.getFloat();
int index = ESM::Skill::refIdToIndex(skill->mId);
for (const auto& skills : class_.mData.mSkills) for (const auto& skills : class_.mData.mSkills)
{ {
if (skills[0] == skill->mIndex) if (skills[0] == index)
{ {
typeFactor = gmst.find("fMinorSkillBonus")->mValue.getFloat(); typeFactor = gmst.find("fMinorSkillBonus")->mValue.getFloat();
break; break;
} }
else if (skills[1] == skill->mIndex) else if (skills[1] == index)
{ {
typeFactor = gmst.find("fMajorSkillBonus")->mValue.getFloat(); typeFactor = gmst.find("fMajorSkillBonus")->mValue.getFloat();
break; break;
@ -228,15 +228,16 @@ void MWMechanics::NpcStats::increaseSkill(ESM::RefId id, const ESM::Class& class
// is this a minor or major skill? // is this a minor or major skill?
int increase = gmst.find("iLevelupMiscMultAttriubte")->mValue.getInteger(); // Note: GMST has a typo int increase = gmst.find("iLevelupMiscMultAttriubte")->mValue.getInteger(); // Note: GMST has a typo
int index = ESM::Skill::refIdToIndex(skill->mId);
for (const auto& skills : class_.mData.mSkills) for (const auto& skills : class_.mData.mSkills)
{ {
if (skills[0] == skill->mIndex) if (skills[0] == index)
{ {
mLevelProgress += gmst.find("iLevelUpMinorMult")->mValue.getInteger(); mLevelProgress += gmst.find("iLevelUpMinorMult")->mValue.getInteger();
increase = gmst.find("iLevelUpMinorMultAttribute")->mValue.getInteger(); increase = gmst.find("iLevelUpMinorMultAttribute")->mValue.getInteger();
break; break;
} }
else if (skills[1] == skill->mIndex) else if (skills[1] == index)
{ {
mLevelProgress += gmst.find("iLevelUpMajorMult")->mValue.getInteger(); mLevelProgress += gmst.find("iLevelUpMajorMult")->mValue.getInteger();
increase = gmst.find("iLevelUpMajorMultAttribute")->mValue.getInteger(); increase = gmst.find("iLevelUpMajorMultAttribute")->mValue.getInteger();
@ -463,7 +464,7 @@ void MWMechanics::NpcStats::writeState(ESM::NpcStats& state) const
for (const auto& [id, value] : mSkills) for (const auto& [id, value] : mSkills)
{ {
// TODO extend format // TODO extend format
auto index = id.getIf<ESM::IndexRefId>()->getValue(); auto index = ESM::Skill::refIdToIndex(id);
value.writeState(state.mSkills[index]); value.writeState(state.mSkills[index]);
} }

View file

@ -18,253 +18,325 @@ namespace MWMechanics
template <> template <>
struct Weapon<ESM::Weapon::None> struct Weapon<ESM::Weapon::None>
{ {
inline static const ESM::WeaponType sValue{ /* short group */ "", inline static const ESM::WeaponType& getValue()
/* long group */ "", {
/* sound ID */ "", static const ESM::WeaponType value{ /* short group */ "",
/* attach bone */ "", /* long group */ "",
/* sheath bone */ "", /* sound ID */ "",
/* usage skill */ ESM::Skill::HandToHand, /* attach bone */ "",
/* weapon class*/ ESM::WeaponType::Melee, /* sheath bone */ "",
/* ammo type */ ESM::Weapon::None, /* usage skill */ ESM::Skill::HandToHand,
/* flags */ 0 }; /* weapon class*/ ESM::WeaponType::Melee,
/* ammo type */ ESM::Weapon::None,
/* flags */ 0 };
return value;
}
}; };
template <> template <>
struct Weapon<ESM::Weapon::PickProbe> struct Weapon<ESM::Weapon::PickProbe>
{ {
inline static const ESM::WeaponType sValue{ /* short group */ "1h", inline static const ESM::WeaponType& getValue()
/* long group */ "pickprobe", {
/* sound ID */ "", static const ESM::WeaponType value{ /* short group */ "1h",
/* attach bone */ "", /* long group */ "pickprobe",
/* sheath bone */ "", /* sound ID */ "",
/* usage skill */ ESM::Skill::Security, /* attach bone */ "",
/* weapon class*/ ESM::WeaponType::Melee, /* sheath bone */ "",
/* ammo type */ ESM::Weapon::None, /* usage skill */ ESM::Skill::Security,
/* flags */ 0 }; /* weapon class*/ ESM::WeaponType::Melee,
/* ammo type */ ESM::Weapon::None,
/* flags */ 0 };
return value;
}
}; };
template <> template <>
struct Weapon<ESM::Weapon::Spell> struct Weapon<ESM::Weapon::Spell>
{ {
inline static const ESM::WeaponType sValue{ /* short group */ "spell", inline static const ESM::WeaponType& getValue()
/* long group */ "spellcast", {
/* sound ID */ "", static const ESM::WeaponType value{ /* short group */ "spell",
/* attach bone */ "", /* long group */ "spellcast",
/* sheath bone */ "", /* sound ID */ "",
/* usage skill */ ESM::Skill::HandToHand, /* attach bone */ "",
/* weapon class*/ ESM::WeaponType::Melee, /* sheath bone */ "",
/* ammo type */ ESM::Weapon::None, /* usage skill */ ESM::Skill::HandToHand,
/* flags */ ESM::WeaponType::TwoHanded }; /* weapon class*/ ESM::WeaponType::Melee,
/* ammo type */ ESM::Weapon::None,
/* flags */ ESM::WeaponType::TwoHanded };
return value;
}
}; };
template <> template <>
struct Weapon<ESM::Weapon::HandToHand> struct Weapon<ESM::Weapon::HandToHand>
{ {
inline static const ESM::WeaponType sValue{ /* short group */ "hh", inline static const ESM::WeaponType& getValue()
/* long group */ "handtohand", {
/* sound ID */ "", static const ESM::WeaponType value{ /* short group */ "hh",
/* attach bone */ "", /* long group */ "handtohand",
/* sheath bone */ "", /* sound ID */ "",
/* usage skill */ ESM::Skill::HandToHand, /* attach bone */ "",
/* weapon class*/ ESM::WeaponType::Melee, /* sheath bone */ "",
/* ammo type */ ESM::Weapon::None, /* usage skill */ ESM::Skill::HandToHand,
/* flags */ ESM::WeaponType::TwoHanded }; /* weapon class*/ ESM::WeaponType::Melee,
/* ammo type */ ESM::Weapon::None,
/* flags */ ESM::WeaponType::TwoHanded };
return value;
}
}; };
template <> template <>
struct Weapon<ESM::Weapon::ShortBladeOneHand> struct Weapon<ESM::Weapon::ShortBladeOneHand>
{ {
inline static const ESM::WeaponType sValue{ /* short group */ "1s", inline static const ESM::WeaponType& getValue()
/* long group */ "shortbladeonehand", {
/* sound ID */ "Item Weapon Shortblade", static const ESM::WeaponType value{ /* short group */ "1s",
/* attach bone */ "Weapon Bone", /* long group */ "shortbladeonehand",
/* sheath bone */ "Bip01 ShortBladeOneHand", /* sound ID */ "Item Weapon Shortblade",
/* usage skill */ ESM::Skill::ShortBlade, /* attach bone */ "Weapon Bone",
/* weapon class*/ ESM::WeaponType::Melee, /* sheath bone */ "Bip01 ShortBladeOneHand",
/* ammo type */ ESM::Weapon::None, /* usage skill */ ESM::Skill::ShortBlade,
/* flags */ ESM::WeaponType::HasHealth }; /* weapon class*/ ESM::WeaponType::Melee,
/* ammo type */ ESM::Weapon::None,
/* flags */ ESM::WeaponType::HasHealth };
return value;
}
}; };
template <> template <>
struct Weapon<ESM::Weapon::LongBladeOneHand> struct Weapon<ESM::Weapon::LongBladeOneHand>
{ {
inline static const ESM::WeaponType sValue{ /* short group */ "1h", inline static const ESM::WeaponType& getValue()
/* long group */ "weapononehand", {
/* sound ID */ "Item Weapon Longblade", static const ESM::WeaponType value{ /* short group */ "1h",
/* attach bone */ "Weapon Bone", /* long group */ "weapononehand",
/* sheath bone */ "Bip01 LongBladeOneHand", /* sound ID */ "Item Weapon Longblade",
/* usage skill */ ESM::Skill::LongBlade, /* attach bone */ "Weapon Bone",
/* weapon class*/ ESM::WeaponType::Melee, /* sheath bone */ "Bip01 LongBladeOneHand",
/* ammo type */ ESM::Weapon::None, /* usage skill */ ESM::Skill::LongBlade,
/* flags */ ESM::WeaponType::HasHealth }; /* weapon class*/ ESM::WeaponType::Melee,
/* ammo type */ ESM::Weapon::None,
/* flags */ ESM::WeaponType::HasHealth };
return value;
}
}; };
template <> template <>
struct Weapon<ESM::Weapon::BluntOneHand> struct Weapon<ESM::Weapon::BluntOneHand>
{ {
inline static const ESM::WeaponType sValue{ /* short group */ "1b", inline static const ESM::WeaponType& getValue()
/* long group */ "bluntonehand", {
/* sound ID */ "Item Weapon Blunt", static const ESM::WeaponType value{ /* short group */ "1b",
/* attach bone */ "Weapon Bone", /* long group */ "bluntonehand",
/* sheath bone */ "Bip01 BluntOneHand", /* sound ID */ "Item Weapon Blunt",
/* usage skill */ ESM::Skill::BluntWeapon, /* attach bone */ "Weapon Bone",
/* weapon class*/ ESM::WeaponType::Melee, /* sheath bone */ "Bip01 BluntOneHand",
/* ammo type */ ESM::Weapon::None, /* usage skill */ ESM::Skill::BluntWeapon,
/* flags */ ESM::WeaponType::HasHealth }; /* weapon class*/ ESM::WeaponType::Melee,
/* ammo type */ ESM::Weapon::None,
/* flags */ ESM::WeaponType::HasHealth };
return value;
}
}; };
template <> template <>
struct Weapon<ESM::Weapon::AxeOneHand> struct Weapon<ESM::Weapon::AxeOneHand>
{ {
inline static const ESM::WeaponType sValue{ /* short group */ "1b", inline static const ESM::WeaponType& getValue()
/* long group */ "bluntonehand", {
/* sound ID */ "Item Weapon Blunt", static const ESM::WeaponType value{ /* short group */ "1b",
/* attach bone */ "Weapon Bone", /* long group */ "bluntonehand",
/* sheath bone */ "Bip01 LongBladeOneHand", /* sound ID */ "Item Weapon Blunt",
/* usage skill */ ESM::Skill::Axe, /* attach bone */ "Weapon Bone",
/* weapon class*/ ESM::WeaponType::Melee, /* sheath bone */ "Bip01 LongBladeOneHand",
/* ammo type */ ESM::Weapon::None, /* usage skill */ ESM::Skill::Axe,
/* flags */ ESM::WeaponType::HasHealth }; /* weapon class*/ ESM::WeaponType::Melee,
/* ammo type */ ESM::Weapon::None,
/* flags */ ESM::WeaponType::HasHealth };
return value;
}
}; };
template <> template <>
struct Weapon<ESM::Weapon::LongBladeTwoHand> struct Weapon<ESM::Weapon::LongBladeTwoHand>
{ {
inline static const ESM::WeaponType sValue{ /* short group */ "2c", inline static const ESM::WeaponType& getValue()
/* long group */ "weapontwohand", {
/* sound ID */ "Item Weapon Longblade", static const ESM::WeaponType value{ /* short group */ "2c",
/* attach bone */ "Weapon Bone", /* long group */ "weapontwohand",
/* sheath bone */ "Bip01 LongBladeTwoClose", /* sound ID */ "Item Weapon Longblade",
/* usage skill */ ESM::Skill::LongBlade, /* attach bone */ "Weapon Bone",
/* weapon class*/ ESM::WeaponType::Melee, /* sheath bone */ "Bip01 LongBladeTwoClose",
/* ammo type */ ESM::Weapon::None, /* usage skill */ ESM::Skill::LongBlade,
/* flags */ ESM::WeaponType::HasHealth | ESM::WeaponType::TwoHanded }; /* weapon class*/ ESM::WeaponType::Melee,
/* ammo type */ ESM::Weapon::None,
/* flags */ ESM::WeaponType::HasHealth | ESM::WeaponType::TwoHanded };
return value;
}
}; };
template <> template <>
struct Weapon<ESM::Weapon::AxeTwoHand> struct Weapon<ESM::Weapon::AxeTwoHand>
{ {
inline static const ESM::WeaponType sValue{ /* short group */ "2b", inline static const ESM::WeaponType& getValue()
/* long group */ "blunttwohand", {
/* sound ID */ "Item Weapon Blunt", static const ESM::WeaponType value{ /* short group */ "2b",
/* attach bone */ "Weapon Bone", /* long group */ "blunttwohand",
/* sheath bone */ "Bip01 AxeTwoClose", /* sound ID */ "Item Weapon Blunt",
/* usage skill */ ESM::Skill::Axe, /* attach bone */ "Weapon Bone",
/* weapon class*/ ESM::WeaponType::Melee, /* sheath bone */ "Bip01 AxeTwoClose",
/* ammo type */ ESM::Weapon::None, /* usage skill */ ESM::Skill::Axe,
/* flags */ ESM::WeaponType::HasHealth | ESM::WeaponType::TwoHanded }; /* weapon class*/ ESM::WeaponType::Melee,
/* ammo type */ ESM::Weapon::None,
/* flags */ ESM::WeaponType::HasHealth | ESM::WeaponType::TwoHanded };
return value;
}
}; };
template <> template <>
struct Weapon<ESM::Weapon::BluntTwoClose> struct Weapon<ESM::Weapon::BluntTwoClose>
{ {
inline static const ESM::WeaponType sValue{ /* short group */ "2b", inline static const ESM::WeaponType& getValue()
/* long group */ "blunttwohand", {
/* sound ID */ "Item Weapon Blunt", static const ESM::WeaponType value{ /* short group */ "2b",
/* attach bone */ "Weapon Bone", /* long group */ "blunttwohand",
/* sheath bone */ "Bip01 BluntTwoClose", /* sound ID */ "Item Weapon Blunt",
/* usage skill */ ESM::Skill::BluntWeapon, /* attach bone */ "Weapon Bone",
/* weapon class*/ ESM::WeaponType::Melee, /* sheath bone */ "Bip01 BluntTwoClose",
/* ammo type */ ESM::Weapon::None, /* usage skill */ ESM::Skill::BluntWeapon,
/* flags */ ESM::WeaponType::HasHealth | ESM::WeaponType::TwoHanded }; /* weapon class*/ ESM::WeaponType::Melee,
/* ammo type */ ESM::Weapon::None,
/* flags */ ESM::WeaponType::HasHealth | ESM::WeaponType::TwoHanded };
return value;
}
}; };
template <> template <>
struct Weapon<ESM::Weapon::BluntTwoWide> struct Weapon<ESM::Weapon::BluntTwoWide>
{ {
inline static const ESM::WeaponType sValue{ /* short group */ "2w", inline static const ESM::WeaponType& getValue()
/* long group */ "weapontwowide", {
/* sound ID */ "Item Weapon Blunt", static const ESM::WeaponType value{ /* short group */ "2w",
/* attach bone */ "Weapon Bone", /* long group */ "weapontwowide",
/* sheath bone */ "Bip01 BluntTwoWide", /* sound ID */ "Item Weapon Blunt",
/* usage skill */ ESM::Skill::BluntWeapon, /* attach bone */ "Weapon Bone",
/* weapon class*/ ESM::WeaponType::Melee, /* sheath bone */ "Bip01 BluntTwoWide",
/* ammo type */ ESM::Weapon::None, /* usage skill */ ESM::Skill::BluntWeapon,
/* flags */ ESM::WeaponType::HasHealth | ESM::WeaponType::TwoHanded }; /* weapon class*/ ESM::WeaponType::Melee,
/* ammo type */ ESM::Weapon::None,
/* flags */ ESM::WeaponType::HasHealth | ESM::WeaponType::TwoHanded };
return value;
}
}; };
template <> template <>
struct Weapon<ESM::Weapon::SpearTwoWide> struct Weapon<ESM::Weapon::SpearTwoWide>
{ {
inline static const ESM::WeaponType sValue{ /* short group */ "2w", inline static const ESM::WeaponType& getValue()
/* long group */ "weapontwowide", {
/* sound ID */ "Item Weapon Spear", static const ESM::WeaponType value{ /* short group */ "2w",
/* attach bone */ "Weapon Bone", /* long group */ "weapontwowide",
/* sheath bone */ "Bip01 SpearTwoWide", /* sound ID */ "Item Weapon Spear",
/* usage skill */ ESM::Skill::Spear, /* attach bone */ "Weapon Bone",
/* weapon class*/ ESM::WeaponType::Melee, /* sheath bone */ "Bip01 SpearTwoWide",
/* ammo type */ ESM::Weapon::None, /* usage skill */ ESM::Skill::Spear,
/* flags */ ESM::WeaponType::HasHealth | ESM::WeaponType::TwoHanded }; /* weapon class*/ ESM::WeaponType::Melee,
/* ammo type */ ESM::Weapon::None,
/* flags */ ESM::WeaponType::HasHealth | ESM::WeaponType::TwoHanded };
return value;
}
}; };
template <> template <>
struct Weapon<ESM::Weapon::MarksmanBow> struct Weapon<ESM::Weapon::MarksmanBow>
{ {
inline static const ESM::WeaponType sValue{ /* short group */ "bow", inline static const ESM::WeaponType& getValue()
/* long group */ "bowandarrow", {
/* sound ID */ "Item Weapon Bow", static const ESM::WeaponType value{ /* short group */ "bow",
/* attach bone */ "Weapon Bone Left", /* long group */ "bowandarrow",
/* sheath bone */ "Bip01 MarksmanBow", /* sound ID */ "Item Weapon Bow",
/* usage skill */ ESM::Skill::Marksman, /* attach bone */ "Weapon Bone Left",
/* weapon class*/ ESM::WeaponType::Ranged, /* sheath bone */ "Bip01 MarksmanBow",
/* ammo type */ ESM::Weapon::Arrow, /* usage skill */ ESM::Skill::Marksman,
/* flags */ ESM::WeaponType::HasHealth | ESM::WeaponType::TwoHanded }; /* weapon class*/ ESM::WeaponType::Ranged,
/* ammo type */ ESM::Weapon::Arrow,
/* flags */ ESM::WeaponType::HasHealth | ESM::WeaponType::TwoHanded };
return value;
}
}; };
template <> template <>
struct Weapon<ESM::Weapon::MarksmanCrossbow> struct Weapon<ESM::Weapon::MarksmanCrossbow>
{ {
inline static const ESM::WeaponType sValue{ /* short group */ "crossbow", inline static const ESM::WeaponType& getValue()
/* long group */ "crossbow", {
/* sound ID */ "Item Weapon Crossbow", static const ESM::WeaponType value{ /* short group */ "crossbow",
/* attach bone */ "Weapon Bone", /* long group */ "crossbow",
/* sheath bone */ "Bip01 MarksmanCrossbow", /* sound ID */ "Item Weapon Crossbow",
/* usage skill */ ESM::Skill::Marksman, /* attach bone */ "Weapon Bone",
/* weapon class*/ ESM::WeaponType::Ranged, /* sheath bone */ "Bip01 MarksmanCrossbow",
/* ammo type */ ESM::Weapon::Bolt, /* usage skill */ ESM::Skill::Marksman,
/* flags */ ESM::WeaponType::HasHealth | ESM::WeaponType::TwoHanded }; /* weapon class*/ ESM::WeaponType::Ranged,
/* ammo type */ ESM::Weapon::Bolt,
/* flags */ ESM::WeaponType::HasHealth | ESM::WeaponType::TwoHanded };
return value;
}
}; };
template <> template <>
struct Weapon<ESM::Weapon::MarksmanThrown> struct Weapon<ESM::Weapon::MarksmanThrown>
{ {
inline static const ESM::WeaponType sValue{ /* short group */ "1t", inline static const ESM::WeaponType& getValue()
/* long group */ "throwweapon", {
/* sound ID */ "Item Weapon Blunt", static const ESM::WeaponType value{ /* short group */ "1t",
/* attach bone */ "Weapon Bone", /* long group */ "throwweapon",
/* sheath bone */ "Bip01 MarksmanThrown", /* sound ID */ "Item Weapon Blunt",
/* usage skill */ ESM::Skill::Marksman, /* attach bone */ "Weapon Bone",
/* weapon class*/ ESM::WeaponType::Thrown, /* sheath bone */ "Bip01 MarksmanThrown",
/* ammo type */ ESM::Weapon::None, /* usage skill */ ESM::Skill::Marksman,
/* flags */ 0 }; /* weapon class*/ ESM::WeaponType::Thrown,
/* ammo type */ ESM::Weapon::None,
/* flags */ 0 };
return value;
}
}; };
template <> template <>
struct Weapon<ESM::Weapon::Arrow> struct Weapon<ESM::Weapon::Arrow>
{ {
inline static const ESM::WeaponType sValue{ /* short group */ "", inline static const ESM::WeaponType& getValue()
/* long group */ "", {
/* sound ID */ "Item Ammo", static const ESM::WeaponType value{ /* short group */ "",
/* attach bone */ "Bip01 Arrow", /* long group */ "",
/* sheath bone */ "", /* sound ID */ "Item Ammo",
/* usage skill */ ESM::Skill::Marksman, /* attach bone */ "Bip01 Arrow",
/* weapon class*/ ESM::WeaponType::Ammo, /* sheath bone */ "",
/* ammo type */ ESM::Weapon::None, /* usage skill */ ESM::Skill::Marksman,
/* flags */ 0 }; /* weapon class*/ ESM::WeaponType::Ammo,
/* ammo type */ ESM::Weapon::None,
/* flags */ 0 };
return value;
}
}; };
template <> template <>
struct Weapon<ESM::Weapon::Bolt> struct Weapon<ESM::Weapon::Bolt>
{ {
inline static const ESM::WeaponType sValue{ /* short group */ "", inline static const ESM::WeaponType& getValue()
/* long group */ "", {
/* sound ID */ "Item Ammo", static const ESM::WeaponType value{ /* short group */ "",
/* attach bone */ "ArrowBone", /* long group */ "",
/* sheath bone */ "", /* sound ID */ "Item Ammo",
/* usage skill */ ESM::Skill::Marksman, /* attach bone */ "ArrowBone",
/* weapon class*/ ESM::WeaponType::Ammo, /* sheath bone */ "",
/* ammo type */ ESM::Weapon::None, /* usage skill */ ESM::Skill::Marksman,
/* flags */ 0 }; /* weapon class*/ ESM::WeaponType::Ammo,
/* ammo type */ ESM::Weapon::None,
/* flags */ 0 };
return value;
}
}; };
MWWorld::ContainerStoreIterator getActiveWeapon(const MWWorld::Ptr& actor, int* weaptype) MWWorld::ContainerStoreIterator getActiveWeapon(const MWWorld::Ptr& actor, int* weaptype)
@ -305,43 +377,43 @@ namespace MWMechanics
switch (static_cast<ESM::Weapon::Type>(weaponType)) switch (static_cast<ESM::Weapon::Type>(weaponType))
{ {
case ESM::Weapon::PickProbe: case ESM::Weapon::PickProbe:
return &Weapon<ESM::Weapon::PickProbe>::sValue; return &Weapon<ESM::Weapon::PickProbe>::getValue();
case ESM::Weapon::HandToHand: case ESM::Weapon::HandToHand:
return &Weapon<ESM::Weapon::HandToHand>::sValue; return &Weapon<ESM::Weapon::HandToHand>::getValue();
case ESM::Weapon::Spell: case ESM::Weapon::Spell:
return &Weapon<ESM::Weapon::Spell>::sValue; return &Weapon<ESM::Weapon::Spell>::getValue();
case ESM::Weapon::None: case ESM::Weapon::None:
return &Weapon<ESM::Weapon::None>::sValue; return &Weapon<ESM::Weapon::None>::getValue();
case ESM::Weapon::ShortBladeOneHand: case ESM::Weapon::ShortBladeOneHand:
return &Weapon<ESM::Weapon::ShortBladeOneHand>::sValue; return &Weapon<ESM::Weapon::ShortBladeOneHand>::getValue();
case ESM::Weapon::LongBladeOneHand: case ESM::Weapon::LongBladeOneHand:
return &Weapon<ESM::Weapon::LongBladeOneHand>::sValue; return &Weapon<ESM::Weapon::LongBladeOneHand>::getValue();
case ESM::Weapon::LongBladeTwoHand: case ESM::Weapon::LongBladeTwoHand:
return &Weapon<ESM::Weapon::LongBladeTwoHand>::sValue; return &Weapon<ESM::Weapon::LongBladeTwoHand>::getValue();
case ESM::Weapon::BluntOneHand: case ESM::Weapon::BluntOneHand:
return &Weapon<ESM::Weapon::BluntOneHand>::sValue; return &Weapon<ESM::Weapon::BluntOneHand>::getValue();
case ESM::Weapon::BluntTwoClose: case ESM::Weapon::BluntTwoClose:
return &Weapon<ESM::Weapon::BluntTwoClose>::sValue; return &Weapon<ESM::Weapon::BluntTwoClose>::getValue();
case ESM::Weapon::BluntTwoWide: case ESM::Weapon::BluntTwoWide:
return &Weapon<ESM::Weapon::BluntTwoWide>::sValue; return &Weapon<ESM::Weapon::BluntTwoWide>::getValue();
case ESM::Weapon::SpearTwoWide: case ESM::Weapon::SpearTwoWide:
return &Weapon<ESM::Weapon::SpearTwoWide>::sValue; return &Weapon<ESM::Weapon::SpearTwoWide>::getValue();
case ESM::Weapon::AxeOneHand: case ESM::Weapon::AxeOneHand:
return &Weapon<ESM::Weapon::AxeOneHand>::sValue; return &Weapon<ESM::Weapon::AxeOneHand>::getValue();
case ESM::Weapon::AxeTwoHand: case ESM::Weapon::AxeTwoHand:
return &Weapon<ESM::Weapon::AxeTwoHand>::sValue; return &Weapon<ESM::Weapon::AxeTwoHand>::getValue();
case ESM::Weapon::MarksmanBow: case ESM::Weapon::MarksmanBow:
return &Weapon<ESM::Weapon::MarksmanBow>::sValue; return &Weapon<ESM::Weapon::MarksmanBow>::getValue();
case ESM::Weapon::MarksmanCrossbow: case ESM::Weapon::MarksmanCrossbow:
return &Weapon<ESM::Weapon::MarksmanCrossbow>::sValue; return &Weapon<ESM::Weapon::MarksmanCrossbow>::getValue();
case ESM::Weapon::MarksmanThrown: case ESM::Weapon::MarksmanThrown:
return &Weapon<ESM::Weapon::MarksmanThrown>::sValue; return &Weapon<ESM::Weapon::MarksmanThrown>::getValue();
case ESM::Weapon::Arrow: case ESM::Weapon::Arrow:
return &Weapon<ESM::Weapon::Arrow>::sValue; return &Weapon<ESM::Weapon::Arrow>::getValue();
case ESM::Weapon::Bolt: case ESM::Weapon::Bolt:
return &Weapon<ESM::Weapon::Bolt>::sValue; return &Weapon<ESM::Weapon::Bolt>::getValue();
} }
return &Weapon<ESM::Weapon::ShortBladeOneHand>::sValue; return &Weapon<ESM::Weapon::ShortBladeOneHand>::getValue();
} }
} }

View file

@ -962,12 +962,14 @@ namespace MWWorld
}; };
for (ESM::Skill* skill : mShared) for (ESM::Skill* skill : mShared)
{ {
if (skill->mIndex >= 0) int index = ESM::Skill::refIdToIndex(skill->mId);
if (index >= 0)
{ {
skill->mName = getGMSTString(settings, skillValues[skill->mIndex][0]); const auto& values = skillValues[index];
skill->mIcon = skillValues[skill->mIndex][1]; skill->mName = getGMSTString(settings, values[0]);
skill->mWerewolfValue = getGMSTFloat(settings, skillValues[skill->mIndex][2]); skill->mIcon = values[1];
const auto& school = skillValues[skill->mIndex][3]; skill->mWerewolfValue = getGMSTFloat(settings, values[2]);
const auto& school = values[3];
if (!school.empty()) if (!school.empty())
{ {
if (!skill->mSchool) if (!skill->mSchool)

View file

@ -462,6 +462,8 @@ namespace
{ {
refId = ESM::RefId::esm3ExteriorCell(0, 0); refId = ESM::RefId::esm3ExteriorCell(0, 0);
} }
else if constexpr (std::is_same_v<RecordType, ESM::Skill>)
refId = ESM::Skill::Block;
else else
refId = ESM::StringRefId(stringId); refId = ESM::StringRefId(stringId);
@ -496,7 +498,7 @@ namespace
const RecordType* result = nullptr; const RecordType* result = nullptr;
if constexpr (std::is_same_v<RecordType, ESM::LandTexture>) if constexpr (std::is_same_v<RecordType, ESM::LandTexture>)
result = esmStore.get<RecordType>().search(index, 0); result = esmStore.get<RecordType>().search(index, 0);
else if constexpr (ESM::hasIndex<RecordType> && !std::is_same_v<RecordType, ESM::Skill>) else if constexpr (ESM::hasIndex<RecordType>)
result = esmStore.get<RecordType>().search(index); result = esmStore.get<RecordType>().search(index);
else else
result = esmStore.get<RecordType>().search(refId); result = esmStore.get<RecordType>().search(refId);

View file

@ -5,46 +5,37 @@
#include <components/misc/strings/algorithm.hpp> #include <components/misc/strings/algorithm.hpp>
#include <cstdint>
namespace ESM namespace ESM
{ {
const std::string Skill::sSkillNames[Length] = { const SkillId Skill::Block("Block");
"Block", const SkillId Skill::Armorer("Armorer");
"Armorer", const SkillId Skill::MediumArmor("MediumArmor");
"Mediumarmor", const SkillId Skill::HeavyArmor("HeavyArmor");
"Heavyarmor", const SkillId Skill::BluntWeapon("BluntWeapon");
"Bluntweapon", const SkillId Skill::LongBlade("LongBlade");
"Longblade", const SkillId Skill::Axe("Axe");
"Axe", const SkillId Skill::Spear("Spear");
"Spear", const SkillId Skill::Athletics("Athletics");
"Athletics", const SkillId Skill::Enchant("Enchant");
"Enchant", const SkillId Skill::Destruction("Destruction");
"Destruction", const SkillId Skill::Alteration("Alteration");
"Alteration", const SkillId Skill::Illusion("Illusion");
"Illusion", const SkillId Skill::Conjuration("Conjuration");
"Conjuration", const SkillId Skill::Mysticism("Mysticism");
"Mysticism", const SkillId Skill::Restoration("Restoration");
"Restoration", const SkillId Skill::Alchemy("Alchemy");
"Alchemy", const SkillId Skill::Unarmored("Unarmored");
"Unarmored", const SkillId Skill::Security("Security");
"Security", const SkillId Skill::Sneak("Sneak");
"Sneak", const SkillId Skill::Acrobatics("Acrobatics");
"Acrobatics", const SkillId Skill::LightArmor("LightArmor");
"Lightarmor", const SkillId Skill::ShortBlade("ShortBlade");
"Shortblade", const SkillId Skill::Marksman("Marksman");
"Marksman", const SkillId Skill::Mercantile("Mercantile");
"Mercantile", const SkillId Skill::Speechcraft("Speechcraft");
"Speechcraft", const SkillId Skill::HandToHand("HandToHand");
"Handtohand",
};
int Skill::stringToSkillId(std::string_view skill)
{
for (int id = 0; id < Skill::Length; ++id)
if (Misc::StringUtils::ciEqual(sSkillNames[id], skill))
return id;
throw std::logic_error("No such skill: " + std::string(skill));
}
void Skill::load(ESMReader& esm, bool& isDeleted) void Skill::load(ESMReader& esm, bool& isDeleted)
{ {
@ -53,13 +44,14 @@ namespace ESM
bool hasIndex = false; bool hasIndex = false;
bool hasData = false; bool hasData = false;
int32_t index = -1;
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().toInt()) switch (esm.retSubName().toInt())
{ {
case fourCC("INDX"): case fourCC("INDX"):
esm.getHT(mIndex); esm.getHT(index);
hasIndex = true; hasIndex = true;
break; break;
case fourCC("SKDT"): case fourCC("SKDT"):
@ -75,19 +67,17 @@ namespace ESM
} }
if (!hasIndex) if (!hasIndex)
esm.fail("Missing INDX"); esm.fail("Missing INDX");
else if (mIndex < 0 || mIndex >= Length) else if (index < 0 || index >= Length)
esm.fail("Invalid INDX"); esm.fail("Invalid INDX");
if (!hasData) if (!hasData)
esm.fail("Missing SKDT"); esm.fail("Missing SKDT");
// create an ID from the index and the name (only used in the editor and likely to change in the mId = *indexToRefId(index).getIf<SkillId>();
// future)
mId = indexToRefId(mIndex);
} }
void Skill::save(ESMWriter& esm, bool /*isDeleted*/) const void Skill::save(ESMWriter& esm, bool /*isDeleted*/) const
{ {
esm.writeHNT("INDX", mIndex); esm.writeHNT("INDX", refIdToIndex(mId));
esm.writeHNT("SKDT", mData, 24); esm.writeHNT("SKDT", mData, 24);
esm.writeHNOString("DESC", mDescription); esm.writeHNOString("DESC", mDescription);
} }
@ -101,11 +91,51 @@ namespace ESM
mDescription.clear(); mDescription.clear();
} }
static const RefId sSkills[Skill::Length] = {
Skill::Block,
Skill::Armorer,
Skill::MediumArmor,
Skill::HeavyArmor,
Skill::BluntWeapon,
Skill::LongBlade,
Skill::Axe,
Skill::Spear,
Skill::Athletics,
Skill::Enchant,
Skill::Destruction,
Skill::Alteration,
Skill::Illusion,
Skill::Conjuration,
Skill::Mysticism,
Skill::Restoration,
Skill::Alchemy,
Skill::Unarmored,
Skill::Security,
Skill::Sneak,
Skill::Acrobatics,
Skill::LightArmor,
Skill::ShortBlade,
Skill::Marksman,
Skill::Mercantile,
Skill::Speechcraft,
Skill::HandToHand,
};
RefId Skill::indexToRefId(int index) RefId Skill::indexToRefId(int index)
{ {
if (index < 0 || index >= Length) if (index < 0 || index >= Length)
return RefId(); return RefId();
return RefId::index(sRecordId, static_cast<std::uint32_t>(index)); return sSkills[index];
}
int Skill::refIdToIndex(RefId id)
{
for (int i = 0; i < Length; ++i)
{
if (sSkills[i] == id)
return i;
}
return -1;
} }
const std::array<RefId, MagicSchool::Length> sMagicSchools = { const std::array<RefId, MagicSchool::Length> sMagicSchools = {

View file

@ -14,6 +14,8 @@ namespace ESM
class ESMReader; class ESMReader;
class ESMWriter; class ESMWriter;
using SkillId = StringRefId;
struct MagicSchool struct MagicSchool
{ {
ESM::RefId mAreaSound; ESM::RefId mAreaSound;
@ -43,7 +45,7 @@ namespace ESM
static std::string_view getRecordType() { return "Skill"; } static std::string_view getRecordType() { return "Skill"; }
unsigned int mRecordFlags; unsigned int mRecordFlags;
RefId mId; SkillId mId;
struct SKDTstruct struct SKDTstruct
{ {
@ -55,48 +57,40 @@ namespace ESM
}; // Total size: 24 bytes }; // Total size: 24 bytes
SKDTstruct mData; SKDTstruct mData;
// Skill index. Skils don't have an id ("NAME") like most records,
// they only have a numerical index that matches one of the
// hard-coded skills in the game.
int mIndex{ -1 };
std::string mDescription; std::string mDescription;
std::string mName; std::string mName;
std::string mIcon; std::string mIcon;
float mWerewolfValue{}; float mWerewolfValue{};
std::optional<MagicSchool> mSchool; std::optional<MagicSchool> mSchool;
static constexpr IndexRefId Block{ sRecordId, 0 }; static const SkillId Block;
static constexpr IndexRefId Armorer{ sRecordId, 1 }; static const SkillId Armorer;
static constexpr IndexRefId MediumArmor{ sRecordId, 2 }; static const SkillId MediumArmor;
static constexpr IndexRefId HeavyArmor{ sRecordId, 3 }; static const SkillId HeavyArmor;
static constexpr IndexRefId BluntWeapon{ sRecordId, 4 }; static const SkillId BluntWeapon;
static constexpr IndexRefId LongBlade{ sRecordId, 5 }; static const SkillId LongBlade;
static constexpr IndexRefId Axe{ sRecordId, 6 }; static const SkillId Axe;
static constexpr IndexRefId Spear{ sRecordId, 7 }; static const SkillId Spear;
static constexpr IndexRefId Athletics{ sRecordId, 8 }; static const SkillId Athletics;
static constexpr IndexRefId Enchant{ sRecordId, 9 }; static const SkillId Enchant;
static constexpr IndexRefId Destruction{ sRecordId, 10 }; static const SkillId Destruction;
static constexpr IndexRefId Alteration{ sRecordId, 11 }; static const SkillId Alteration;
static constexpr IndexRefId Illusion{ sRecordId, 12 }; static const SkillId Illusion;
static constexpr IndexRefId Conjuration{ sRecordId, 13 }; static const SkillId Conjuration;
static constexpr IndexRefId Mysticism{ sRecordId, 14 }; static const SkillId Mysticism;
static constexpr IndexRefId Restoration{ sRecordId, 15 }; static const SkillId Restoration;
static constexpr IndexRefId Alchemy{ sRecordId, 16 }; static const SkillId Alchemy;
static constexpr IndexRefId Unarmored{ sRecordId, 17 }; static const SkillId Unarmored;
static constexpr IndexRefId Security{ sRecordId, 18 }; static const SkillId Security;
static constexpr IndexRefId Sneak{ sRecordId, 19 }; static const SkillId Sneak;
static constexpr IndexRefId Acrobatics{ sRecordId, 20 }; static const SkillId Acrobatics;
static constexpr IndexRefId LightArmor{ sRecordId, 21 }; static const SkillId LightArmor;
static constexpr IndexRefId ShortBlade{ sRecordId, 22 }; static const SkillId ShortBlade;
static constexpr IndexRefId Marksman{ sRecordId, 23 }; static const SkillId Marksman;
static constexpr IndexRefId Mercantile{ sRecordId, 24 }; static const SkillId Mercantile;
static constexpr IndexRefId Speechcraft{ sRecordId, 25 }; static const SkillId Speechcraft;
static constexpr IndexRefId HandToHand{ sRecordId, 26 }; static const SkillId HandToHand;
static constexpr int Length = 27; static constexpr int Length = 27;
static const std::string sSkillNames[Length];
static int stringToSkillId(std::string_view skill);
void load(ESMReader& esm, bool& isDeleted); void load(ESMReader& esm, bool& isDeleted);
void save(ESMWriter& esm, bool isDeleted = false) const; void save(ESMWriter& esm, bool isDeleted = false) const;
@ -105,6 +99,7 @@ namespace ESM
///< Set record to default state (does not touch the ID/index). ///< Set record to default state (does not touch the ID/index).
static RefId indexToRefId(int index); static RefId indexToRefId(int index);
static int refIdToIndex(RefId id);
}; };
} }
#endif #endif

View file

@ -49,7 +49,7 @@ namespace ESM
mWerewolfDeprecatedData = true; mWerewolfDeprecatedData = true;
std::vector<StatState<float>> skills(mSkills.begin(), mSkills.end()); std::vector<StatState<float>> skills(mSkills.begin(), mSkills.end());
for (int i = 0; i < ESM::Skill::Length; ++i) for (size_t i = 0; i < std::size(mSkills); ++i)
{ {
StatState<float> skill; StatState<float> skill;
skill.load(esm, intFallback); skill.load(esm, intFallback);

View file

@ -54,7 +54,7 @@ namespace ESM
= esm.getFormatVersion() <= MaxClearModifiersFormatVersion && !mObject.mNpcStats.mIsWerewolf; = esm.getFormatVersion() <= MaxClearModifiersFormatVersion && !mObject.mNpcStats.mIsWerewolf;
if (esm.hasMoreSubs()) if (esm.hasMoreSubs())
{ {
for (int i = 0; i < Attribute::Length; ++i) for (size_t i = 0; i < std::size(mSaveAttributes); ++i)
{ {
StatState<float> attribute; StatState<float> attribute;
attribute.load(esm, intFallback); attribute.load(esm, intFallback);
@ -64,7 +64,7 @@ namespace ESM
if (mObject.mNpcStats.mIsWerewolf) if (mObject.mNpcStats.mIsWerewolf)
mObject.mCreatureStats.mAttributes[i] = attribute; mObject.mCreatureStats.mAttributes[i] = attribute;
} }
for (int i = 0; i < Skill::Length; ++i) for (size_t i = 0; i < std::size(mSaveSkills); ++i)
{ {
StatState<float> skill; StatState<float> skill;
skill.load(esm, intFallback); skill.load(esm, intFallback);