diff --git a/apps/esmtool/record.cpp b/apps/esmtool/record.cpp index de4c39fd9d..a142bac3c5 100644 --- a/apps/esmtool/record.cpp +++ b/apps/esmtool/record.cpp @@ -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; diff --git a/apps/opencs/model/world/nestedcoladapterimp.cpp b/apps/opencs/model/world/nestedcoladapterimp.cpp index c4f912301c..bdfb68c64a 100644 --- a/apps/opencs/model/world/nestedcoladapterimp.cpp +++ b/apps/opencs/model/world/nestedcoladapterimp.cpp @@ -825,8 +825,7 @@ namespace CSMWorld { ESM::Race race = record.get(); - if (subRowIndex < 0 - || subRowIndex >= static_cast(sizeof(race.mData.mBonus) / sizeof(race.mData.mBonus[0]))) + if (subRowIndex < 0 || static_cast(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(sizeof(race.mData.mBonus) / sizeof(race.mData.mBonus[0]))) + if (subRowIndex < 0 || static_cast(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& record) const { - // there are 7 skill bonuses - return static_cast(sizeof(record.get().mData.mBonus) / sizeof(record.get().mData.mBonus[0])); + return record.get().mData.mBonus.size(); } void CellListAdapter::addRow(Record& record, int position) const diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 7aba7b2b50..988de3c57f 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -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) { diff --git a/apps/openmw/mwgui/race.cpp b/apps/openmw/mwgui/race.cpp index 795c58723f..ab2d9bce2d 100644 --- a/apps/openmw/mwgui/race.cpp +++ b/apps/openmw/mwgui/race.cpp @@ -412,20 +412,15 @@ namespace MWGui const MWWorld::ESMStore& store = *MWBase::Environment::get().getESMStore(); const ESM::Race* race = store.get().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( - "MW_StatNameValue", coord1, MyGUI::Align::Default, std::string("Skill") + MyGUI::utility::toString(i)); - skillWidget->setSkillNumber(skillId); - skillWidget->setSkillValue( - Widgets::MWSkill::SkillValue(static_cast(race->mData.mBonus[i].mBonus), 0.f)); - ToolTips::createSkillToolTip(skillWidget, skillId); + skillWidget = mSkillList->createWidget("MW_StatNameValue", coord1, MyGUI::Align::Default); + skillWidget->setSkillId(ESM::Skill::SkillEnum(bonus.mSkill)); + skillWidget->setSkillValue(Widgets::MWSkill::SkillValue(static_cast(bonus.mBonus), 0.f)); + ToolTips::createSkillToolTip(skillWidget, bonus.mSkill); mSkillItems.push_back(skillWidget); diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp index 1a9262b8da..7f83f0ad8c 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp @@ -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); } diff --git a/components/esm3/loadrace.cpp b/components/esm3/loadrace.cpp index 00eb5eda3a..eb8faf40e9 100644 --- a/components/esm3/loadrace.cpp +++ b/components/esm3/loadrace.cpp @@ -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; diff --git a/components/esm3/loadrace.hpp b/components/esm3/loadrace.hpp index 36dce54cce..8dd60bdef1 100644 --- a/components/esm3/loadrace.hpp +++ b/components/esm3/loadrace.hpp @@ -1,6 +1,7 @@ #ifndef OPENMW_ESM_RACE_H #define OPENMW_ESM_RACE_H +#include #include #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 mBonus; // Attribute values for male/female - MaleFemale mAttributeValues[8]; + std::array mAttributeValues; // The actual eye level height (in game units) is (probably) given // as 'height' times 128. This has not been tested yet.