Use std::array in RADTstruct

macos_ci
Evil Eye 2 years ago
parent 25bbaa2343
commit 8a474b9807

@ -1188,7 +1188,7 @@ namespace EsmTool
std::cout << (male ? " Male:" : " Female:") << std::endl;
for (int j = 0; j < 8; ++j)
for (int j = 0; j < ESM::Attribute::Length; ++j)
std::cout << " " << sAttributeNames[j] << ": " << mData.mData.mAttributeValues[j].getValue(male)
<< std::endl;
@ -1196,11 +1196,11 @@ namespace EsmTool
std::cout << " Weight: " << mData.mData.mWeight.getValue(male) << std::endl;
}
for (int i = 0; i != 7; i++)
for (const auto& bonus : mData.mData.mBonus)
// Not all races have 7 skills.
if (mData.mData.mBonus[i].mSkill != -1)
std::cout << " Skill: " << skillLabel(mData.mData.mBonus[i].mSkill) << " ("
<< mData.mData.mBonus[i].mSkill << ") = " << mData.mData.mBonus[i].mBonus << std::endl;
if (bonus.mSkill != -1)
std::cout << " Skill: " << skillLabel(bonus.mSkill) << " (" << bonus.mSkill << ") = " << bonus.mBonus
<< std::endl;
for (const auto& power : mData.mPowers.mList)
std::cout << " Power: " << power << std::endl;

@ -825,8 +825,7 @@ namespace CSMWorld
{
ESM::Race race = record.get();
if (subRowIndex < 0
|| subRowIndex >= static_cast<int>(sizeof(race.mData.mBonus) / sizeof(race.mData.mBonus[0])))
if (subRowIndex < 0 || static_cast<size_t>(subRowIndex) >= race.mData.mBonus.size())
throw std::runtime_error("index out of range");
switch (subColIndex)
@ -845,8 +844,7 @@ namespace CSMWorld
{
ESM::Race race = record.get();
if (subRowIndex < 0
|| subRowIndex >= static_cast<int>(sizeof(race.mData.mBonus) / sizeof(race.mData.mBonus[0])))
if (subRowIndex < 0 || static_cast<size_t>(subRowIndex) >= race.mData.mBonus.size())
throw std::runtime_error("index out of range");
switch (subColIndex)
@ -871,8 +869,7 @@ namespace CSMWorld
int RaceSkillsBonusAdapter::getRowsCount(const Record<ESM::Race>& record) const
{
// there are 7 skill bonuses
return static_cast<int>(sizeof(record.get().mData.mBonus) / sizeof(record.get().mData.mBonus[0]));
return record.get().mData.mBonus.size();
}
void CellListAdapter::addRow(Record<CSMWorld::Cell>& record, int position) const

@ -201,14 +201,10 @@ namespace
int raceBonus = 0;
int specBonus = 0;
for (int raceSkillIndex = 0; raceSkillIndex < 7; ++raceSkillIndex)
{
if (race->mData.mBonus[raceSkillIndex].mSkill == skillIndex)
{
raceBonus = race->mData.mBonus[raceSkillIndex].mBonus;
break;
}
}
auto bonusIt = std::find_if(race->mData.mBonus.begin(), race->mData.mBonus.end(),
[skillIndex](const auto& bonus) { return bonus.mSkill == skillIndex; });
if (bonusIt != race->mData.mBonus.end())
raceBonus = bonusIt->mBonus;
for (int k = 0; k < 5; ++k)
{

@ -412,20 +412,15 @@ namespace MWGui
const MWWorld::ESMStore& store = *MWBase::Environment::get().getESMStore();
const ESM::Race* race = store.get<ESM::Race>().find(mCurrentRaceId);
int count = sizeof(race->mData.mBonus)
/ sizeof(race->mData.mBonus[0]); // TODO: Find a portable macro for this ARRAYSIZE?
for (int i = 0; i < count; ++i)
for (const auto& bonus : race->mData.mBonus)
{
int skillId = race->mData.mBonus[i].mSkill;
if (skillId < 0 || skillId > ESM::Skill::Length) // Skip unknown skill indexes
if (bonus.mSkill < 0 || bonus.mSkill >= ESM::Skill::Length) // Skip unknown skill indexes
continue;
skillWidget = mSkillList->createWidget<Widgets::MWSkill>(
"MW_StatNameValue", coord1, MyGUI::Align::Default, std::string("Skill") + MyGUI::utility::toString(i));
skillWidget->setSkillNumber(skillId);
skillWidget->setSkillValue(
Widgets::MWSkill::SkillValue(static_cast<float>(race->mData.mBonus[i].mBonus), 0.f));
ToolTips::createSkillToolTip(skillWidget, skillId);
skillWidget = mSkillList->createWidget<Widgets::MWSkill>("MW_StatNameValue", coord1, MyGUI::Align::Default);
skillWidget->setSkillId(ESM::Skill::SkillEnum(bonus.mSkill));
skillWidget->setSkillValue(Widgets::MWSkill::SkillValue(static_cast<float>(bonus.mBonus), 0.f));
ToolTips::createSkillToolTip(skillWidget, bonus.mSkill);
mSkillItems.push_back(skillWidget);

@ -148,7 +148,7 @@ namespace MWMechanics
bool male = (player->mFlags & ESM::NPC::Female) == 0;
for (int i = 0; i < 8; ++i)
for (int i = 0; i < ESM::Attribute::Length; ++i)
{
const ESM::Race::MaleFemale& attribute = race->mData.mAttributeValues[i];
@ -159,12 +159,10 @@ namespace MWMechanics
{
int bonus = 0;
for (int i2 = 0; i2 < 7; ++i2)
if (race->mData.mBonus[i2].mSkill == i)
{
bonus = race->mData.mBonus[i2].mBonus;
break;
}
auto bonusIt = std::find_if(race->mData.mBonus.begin(), race->mData.mBonus.end(),
[i](const auto& bonus) { return bonus.mSkill == i; });
if (bonusIt != race->mData.mBonus.end())
bonus = bonusIt->mBonus;
npcStats.getSkill(i).setBase(5 + bonus);
}

@ -84,14 +84,14 @@ namespace ESM
mPowers.mList.clear();
for (int i = 0; i < 7; ++i)
for (auto& bonus : mData.mBonus)
{
mData.mBonus[i].mSkill = -1;
mData.mBonus[i].mBonus = 0;
bonus.mSkill = -1;
bonus.mBonus = 0;
}
for (int i = 0; i < 8; ++i)
mData.mAttributeValues[i].mMale = mData.mAttributeValues[i].mFemale = 1;
for (auto& attribute : mData.mAttributeValues)
attribute.mMale = attribute.mFemale = 1;
mData.mHeight.mMale = mData.mHeight.mFemale = 1;
mData.mWeight.mMale = mData.mWeight.mFemale = 1;

@ -1,6 +1,7 @@
#ifndef OPENMW_ESM_RACE_H
#define OPENMW_ESM_RACE_H
#include <array>
#include <string>
#include "components/esm/defs.hpp"
@ -53,10 +54,10 @@ namespace ESM
struct RADTstruct
{
// List of skills that get a bonus
SkillBonus mBonus[7];
std::array<SkillBonus, 7> mBonus;
// Attribute values for male/female
MaleFemale mAttributeValues[8];
std::array<MaleFemale, 8> mAttributeValues;
// The actual eye level height (in game units) is (probably) given
// as 'height' times 128. This has not been tested yet.

Loading…
Cancel
Save