mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-03-29 13:20:35 +00:00
Replace Skill::mIndex with Skill::refIdToIndex
This commit is contained in:
parent
3a1ae9df58
commit
ac9378fa08
@ -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;
|
||||||
|
@ -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);
|
||||||
record.mId = ESM::Skill::indexToRefId(record.mIndex);
|
|
||||||
record.blank();
|
record.blank();
|
||||||
|
|
||||||
getData().getSkills().add(record);
|
getData().getSkills().add(record);
|
||||||
|
@ -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;
|
||||||
|
@ -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);
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -392,7 +392,7 @@ 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[Misc::StringUtils::lowerCase(ESM::Skill::sSkillNames[ESM::Skill::refIdToIndex(skill.mId)])]
|
||||||
= addIndexedAccessor<SkillStat>(skill.mId);
|
= addIndexedAccessor<SkillStat>(skill.mId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
@ -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]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
@ -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);
|
||||||
|
@ -53,13 +53,14 @@ namespace ESM
|
|||||||
|
|
||||||
bool hasIndex = false;
|
bool hasIndex = false;
|
||||||
bool hasData = false;
|
bool hasData = false;
|
||||||
|
int 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 +76,19 @@ 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
|
// create an ID from the index and the name (only used in the editor and likely to change in the
|
||||||
// future)
|
// future)
|
||||||
mId = indexToRefId(mIndex);
|
mId = indexToRefId(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
@ -108,6 +109,16 @@ namespace ESM
|
|||||||
return RefId::index(sRecordId, static_cast<std::uint32_t>(index));
|
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 = {
|
const std::array<RefId, MagicSchool::Length> sMagicSchools = {
|
||||||
Skill::Alteration,
|
Skill::Alteration,
|
||||||
Skill::Conjuration,
|
Skill::Conjuration,
|
||||||
|
@ -55,11 +55,6 @@ 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;
|
||||||
@ -105,6 +100,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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user