mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-03-26 20:37:25 +00:00
Replace Skill::mIndex with Skill::refIdToIndex
This commit is contained in:
parent
3a1ae9df58
commit
ac9378fa08
@ -1264,7 +1264,8 @@ namespace EsmTool
|
||||
template <>
|
||||
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 << " Governing Attribute: " << attributeLabel(mData.mData.mAttribute) << " ("
|
||||
<< mData.mData.mAttribute << ")" << std::endl;
|
||||
|
@ -201,11 +201,10 @@ void CSMDoc::Document::createBase()
|
||||
|
||||
addGmsts();
|
||||
|
||||
for (int i = 0; i < 27; ++i)
|
||||
for (int i = 0; i < ESM::Skill::Length; ++i)
|
||||
{
|
||||
ESM::Skill record;
|
||||
record.mIndex = i;
|
||||
record.mId = ESM::Skill::indexToRefId(record.mIndex);
|
||||
record.mId = ESM::Skill::indexToRefId(i);
|
||||
record.blank();
|
||||
|
||||
getData().getSkills().add(record);
|
||||
|
@ -121,11 +121,12 @@ namespace
|
||||
|
||||
// is this a minor or major skill?
|
||||
float add = 0.2f;
|
||||
int index = ESM::Skill::refIdToIndex(skill.mId);
|
||||
for (const auto& skills : class_->mData.mSkills)
|
||||
{
|
||||
if (skills[0] == skill.mIndex)
|
||||
if (skills[0] == index)
|
||||
add = 0.5;
|
||||
if (skills[1] == skill.mIndex)
|
||||
if (skills[1] == index)
|
||||
add = 1.0;
|
||||
}
|
||||
modifierSum += add;
|
||||
@ -199,15 +200,16 @@ namespace
|
||||
int raceBonus = 0;
|
||||
int specBonus = 0;
|
||||
|
||||
int index = ESM::Skill::refIdToIndex(skill.mId);
|
||||
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())
|
||||
raceBonus = bonusIt->mBonus;
|
||||
|
||||
for (const auto& skills : class_->mData.mSkills)
|
||||
{
|
||||
// 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;
|
||||
break;
|
||||
|
@ -471,8 +471,8 @@ namespace MWGui
|
||||
assert(minorSkills.size() >= klass.mData.mSkills.size());
|
||||
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][0] = minorSkills[i].getIf<ESM::IndexRefId>()->getValue();
|
||||
klass.mData.mSkills[i][1] = ESM::Skill::refIdToIndex(majorSkills[i]);
|
||||
klass.mData.mSkills[i][0] = ESM::Skill::refIdToIndex(minorSkills[i]);
|
||||
}
|
||||
|
||||
MWBase::Environment::get().getMechanicsManager()->setPlayerClass(klass);
|
||||
|
@ -287,7 +287,7 @@ namespace MWGui
|
||||
|
||||
void EditEffectDialog::setSkill(ESM::RefId skill)
|
||||
{
|
||||
mEffect.mSkill = skill.getIf<ESM::IndexRefId>()->getValue();
|
||||
mEffect.mSkill = ESM::Skill::refIdToIndex(skill);
|
||||
eventEffectModified(mEffect);
|
||||
}
|
||||
|
||||
|
@ -392,7 +392,7 @@ namespace MWLua
|
||||
sol::table skills(context.mLua->sol(), sol::create);
|
||||
npcStats["skills"] = LuaUtil::makeReadOnly(skills);
|
||||
for (const ESM::Skill& skill : MWBase::Environment::get().getESMStore()->get<ESM::Skill>())
|
||||
skills[Misc::StringUtils::lowerCase(ESM::Skill::sSkillNames[skill.mIndex])]
|
||||
skills[Misc::StringUtils::lowerCase(ESM::Skill::sSkillNames[ESM::Skill::refIdToIndex(skill.mId)])]
|
||||
= addIndexedAccessor<SkillStat>(skill.mId);
|
||||
}
|
||||
}
|
||||
|
@ -158,9 +158,9 @@ namespace MWMechanics
|
||||
for (const ESM::Skill& skill : esmStore.get<ESM::Skill>())
|
||||
{
|
||||
int bonus = 0;
|
||||
|
||||
int index = ESM::Skill::refIdToIndex(skill.mId);
|
||||
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())
|
||||
bonus = bonusIt->mBonus;
|
||||
|
||||
|
@ -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);
|
||||
|
||||
float typeFactor = gmst.find("fMiscSkillBonus")->mValue.getFloat();
|
||||
|
||||
int index = ESM::Skill::refIdToIndex(skill->mId);
|
||||
for (const auto& skills : class_.mData.mSkills)
|
||||
{
|
||||
if (skills[0] == skill->mIndex)
|
||||
if (skills[0] == index)
|
||||
{
|
||||
typeFactor = gmst.find("fMinorSkillBonus")->mValue.getFloat();
|
||||
break;
|
||||
}
|
||||
else if (skills[1] == skill->mIndex)
|
||||
else if (skills[1] == index)
|
||||
{
|
||||
typeFactor = gmst.find("fMajorSkillBonus")->mValue.getFloat();
|
||||
break;
|
||||
@ -228,15 +228,16 @@ void MWMechanics::NpcStats::increaseSkill(ESM::RefId id, const ESM::Class& class
|
||||
|
||||
// is this a minor or major skill?
|
||||
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)
|
||||
{
|
||||
if (skills[0] == skill->mIndex)
|
||||
if (skills[0] == index)
|
||||
{
|
||||
mLevelProgress += gmst.find("iLevelUpMinorMult")->mValue.getInteger();
|
||||
increase = gmst.find("iLevelUpMinorMultAttribute")->mValue.getInteger();
|
||||
break;
|
||||
}
|
||||
else if (skills[1] == skill->mIndex)
|
||||
else if (skills[1] == index)
|
||||
{
|
||||
mLevelProgress += gmst.find("iLevelUpMajorMult")->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)
|
||||
{
|
||||
// TODO extend format
|
||||
auto index = id.getIf<ESM::IndexRefId>()->getValue();
|
||||
auto index = ESM::Skill::refIdToIndex(id);
|
||||
value.writeState(state.mSkills[index]);
|
||||
}
|
||||
|
||||
|
@ -962,12 +962,14 @@ namespace MWWorld
|
||||
};
|
||||
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]);
|
||||
skill->mIcon = skillValues[skill->mIndex][1];
|
||||
skill->mWerewolfValue = getGMSTFloat(settings, skillValues[skill->mIndex][2]);
|
||||
const auto& school = skillValues[skill->mIndex][3];
|
||||
const auto& values = skillValues[index];
|
||||
skill->mName = getGMSTString(settings, values[0]);
|
||||
skill->mIcon = values[1];
|
||||
skill->mWerewolfValue = getGMSTFloat(settings, values[2]);
|
||||
const auto& school = values[3];
|
||||
if (!school.empty())
|
||||
{
|
||||
if (!skill->mSchool)
|
||||
|
@ -462,6 +462,8 @@ namespace
|
||||
{
|
||||
refId = ESM::RefId::esm3ExteriorCell(0, 0);
|
||||
}
|
||||
else if constexpr (std::is_same_v<RecordType, ESM::Skill>)
|
||||
refId = ESM::Skill::Block;
|
||||
else
|
||||
refId = ESM::StringRefId(stringId);
|
||||
|
||||
@ -496,7 +498,7 @@ namespace
|
||||
const RecordType* result = nullptr;
|
||||
if constexpr (std::is_same_v<RecordType, ESM::LandTexture>)
|
||||
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);
|
||||
else
|
||||
result = esmStore.get<RecordType>().search(refId);
|
||||
|
@ -53,13 +53,14 @@ namespace ESM
|
||||
|
||||
bool hasIndex = false;
|
||||
bool hasData = false;
|
||||
int index = -1;
|
||||
while (esm.hasMoreSubs())
|
||||
{
|
||||
esm.getSubName();
|
||||
switch (esm.retSubName().toInt())
|
||||
{
|
||||
case fourCC("INDX"):
|
||||
esm.getHT(mIndex);
|
||||
esm.getHT(index);
|
||||
hasIndex = true;
|
||||
break;
|
||||
case fourCC("SKDT"):
|
||||
@ -75,19 +76,19 @@ namespace ESM
|
||||
}
|
||||
if (!hasIndex)
|
||||
esm.fail("Missing INDX");
|
||||
else if (mIndex < 0 || mIndex >= Length)
|
||||
else if (index < 0 || index >= Length)
|
||||
esm.fail("Invalid INDX");
|
||||
if (!hasData)
|
||||
esm.fail("Missing SKDT");
|
||||
|
||||
// create an ID from the index and the name (only used in the editor and likely to change in the
|
||||
// future)
|
||||
mId = indexToRefId(mIndex);
|
||||
mId = indexToRefId(index);
|
||||
}
|
||||
|
||||
void Skill::save(ESMWriter& esm, bool /*isDeleted*/) const
|
||||
{
|
||||
esm.writeHNT("INDX", mIndex);
|
||||
esm.writeHNT("INDX", refIdToIndex(mId));
|
||||
esm.writeHNT("SKDT", mData, 24);
|
||||
esm.writeHNOString("DESC", mDescription);
|
||||
}
|
||||
@ -108,6 +109,16 @@ namespace ESM
|
||||
return RefId::index(sRecordId, static_cast<std::uint32_t>(index));
|
||||
}
|
||||
|
||||
int Skill::refIdToIndex(RefId id)
|
||||
{
|
||||
if (const IndexRefId* index = id.getIf<IndexRefId>())
|
||||
{
|
||||
if (index->getRecordType() == sRecordId)
|
||||
return index->getValue();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
const std::array<RefId, MagicSchool::Length> sMagicSchools = {
|
||||
Skill::Alteration,
|
||||
Skill::Conjuration,
|
||||
|
@ -55,11 +55,6 @@ namespace ESM
|
||||
}; // Total size: 24 bytes
|
||||
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 mName;
|
||||
std::string mIcon;
|
||||
@ -105,6 +100,7 @@ namespace ESM
|
||||
///< Set record to default state (does not touch the ID/index).
|
||||
|
||||
static RefId indexToRefId(int index);
|
||||
static int refIdToIndex(RefId id);
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user