mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-03-26 02:38:04 +00:00
Reduce the number of magic numbers
This commit is contained in:
parent
6adcd122a8
commit
bac6777fae
apps
esmtool
opencs/model/world
openmw
mwclass
mwgui
mwmechanics
mwworld
components/esm3
@ -1171,7 +1171,7 @@ namespace EsmTool
|
||||
template <>
|
||||
void Record<ESM::Race>::print()
|
||||
{
|
||||
static const char* sAttributeNames[8]
|
||||
static const char* sAttributeNames[ESM::Attribute::Length]
|
||||
= { "Strength", "Intelligence", "Willpower", "Agility", "Speed", "Endurance", "Personality", "Luck" };
|
||||
|
||||
std::cout << " Name: " << mData.mName << std::endl;
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <apps/opencs/model/world/refiddata.hpp>
|
||||
#include <apps/opencs/model/world/universalid.hpp>
|
||||
|
||||
#include <components/esm/attr.hpp>
|
||||
#include <components/esm3/loadcont.hpp>
|
||||
#include <components/esm3/loadmgef.hpp>
|
||||
#include <components/esm3/loadskil.hpp>
|
||||
@ -1007,8 +1008,7 @@ int CSMWorld::NpcAttributesRefIdAdapter::getNestedColumnsCount(const RefIdColumn
|
||||
int CSMWorld::NpcAttributesRefIdAdapter::getNestedRowsCount(
|
||||
const RefIdColumn* column, const RefIdData& data, int index) const
|
||||
{
|
||||
// There are 8 attributes
|
||||
return 8;
|
||||
return ESM::Attribute::Length;
|
||||
}
|
||||
|
||||
void CSMWorld::NpcSkillsRefIdAdapter::addNestedRow(
|
||||
@ -1385,8 +1385,7 @@ int CSMWorld::CreatureAttributesRefIdAdapter::getNestedColumnsCount(
|
||||
int CSMWorld::CreatureAttributesRefIdAdapter::getNestedRowsCount(
|
||||
const RefIdColumn* column, const RefIdData& data, int index) const
|
||||
{
|
||||
// There are 8 attributes
|
||||
return 8;
|
||||
return ESM::Attribute::Length;
|
||||
}
|
||||
|
||||
void CSMWorld::CreatureAttackRefIdAdapter::addNestedRow(
|
||||
|
@ -123,7 +123,7 @@ namespace MWClass
|
||||
const MWWorld::LiveCellRef<ESM::Clothing>* ref = ptr.get<ESM::Clothing>();
|
||||
static const ESM::RefId ringUp = ESM::RefId::stringRefId("Item Ring Up");
|
||||
static const ESM::RefId clothsUp = ESM::RefId::stringRefId("Item Clothes Up");
|
||||
if (ref->mBase->mData.mType == 8)
|
||||
if (ref->mBase->mData.mType == ESM::Clothing::Ring)
|
||||
{
|
||||
return ringUp;
|
||||
}
|
||||
@ -135,7 +135,7 @@ namespace MWClass
|
||||
const MWWorld::LiveCellRef<ESM::Clothing>* ref = ptr.get<ESM::Clothing>();
|
||||
static const ESM::RefId ringDown = ESM::RefId::stringRefId("Item Ring Down");
|
||||
static const ESM::RefId clothsDown = ESM::RefId::stringRefId("Item Clothes Down");
|
||||
if (ref->mBase->mData.mType == 8)
|
||||
if (ref->mBase->mData.mType == ESM::Clothing::Ring)
|
||||
{
|
||||
return ringDown;
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ namespace MWGui
|
||||
MWMechanics::CreatureStats& creatureStats = player.getClass().getCreatureStats(player);
|
||||
MWMechanics::NpcStats& pcStats = player.getClass().getNpcStats(player);
|
||||
|
||||
for (int i = 0; i < 8; ++i)
|
||||
for (int i = 0; i < ESM::Attribute::Length; ++i)
|
||||
{
|
||||
int val = creatureStats.getAttribute(i).getBase();
|
||||
if (std::find(mSpentAttributes.begin(), mSpentAttributes.end(), i) != mSpentAttributes.end())
|
||||
@ -149,7 +149,7 @@ namespace MWGui
|
||||
mLevelDescription->setCaption(toUString(levelupdescription));
|
||||
|
||||
unsigned int availableAttributes = 0;
|
||||
for (int i = 0; i < 8; ++i)
|
||||
for (int i = 0; i < ESM::Attribute::Length; ++i)
|
||||
{
|
||||
MyGUI::TextBox* text = mAttributeMultipliers[i];
|
||||
if (pcStats.getAttribute(i).getBase() < 100)
|
||||
|
@ -129,17 +129,15 @@ namespace MWGui::Widgets
|
||||
{
|
||||
if (mAttributeNameWidget)
|
||||
{
|
||||
if (mId < 0 || mId >= 8)
|
||||
const ESM::Attribute* attribute
|
||||
= MWBase::Environment::get().getESMStore()->get<ESM::Attribute>().search(mId);
|
||||
if (!attribute)
|
||||
{
|
||||
mAttributeNameWidget->setCaption({});
|
||||
}
|
||||
else
|
||||
{
|
||||
static const std::string_view attributes[8]
|
||||
= { "sAttributeStrength", "sAttributeIntelligence", "sAttributeWillpower", "sAttributeAgility",
|
||||
"sAttributeSpeed", "sAttributeEndurance", "sAttributePersonality", "sAttributeLuck" };
|
||||
MyGUI::UString name = toUString(
|
||||
MWBase::Environment::get().getWindowManager()->getGameSettingString(attributes[mId], {}));
|
||||
MyGUI::UString name = toUString(attribute->mName);
|
||||
mAttributeNameWidget->setCaption(name);
|
||||
}
|
||||
}
|
||||
|
@ -535,10 +535,10 @@ namespace MWMechanics
|
||||
|
||||
void CreatureStats::writeState(ESM::CreatureStats& state) const
|
||||
{
|
||||
for (int i = 0; i < ESM::Attribute::Length; ++i)
|
||||
for (size_t i = 0; i < state.mAttributes.size(); ++i)
|
||||
mAttributes[i].writeState(state.mAttributes[i]);
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
for (size_t i = 0; i < state.mDynamic.size(); ++i)
|
||||
mDynamic[i].writeState(state.mDynamic[i]);
|
||||
|
||||
state.mTradeTime = mLastRestock.toEsm();
|
||||
@ -582,7 +582,7 @@ namespace MWMechanics
|
||||
state.mSummonGraveyard = mSummonGraveyard;
|
||||
|
||||
state.mHasAiSettings = true;
|
||||
for (int i = 0; i < 4; ++i)
|
||||
for (size_t i = 0; i < state.mAiSettings.size(); ++i)
|
||||
mAiSettings[i].writeState(state.mAiSettings[i]);
|
||||
|
||||
state.mMissingACDT = false;
|
||||
@ -592,10 +592,10 @@ namespace MWMechanics
|
||||
{
|
||||
if (!state.mMissingACDT)
|
||||
{
|
||||
for (int i = 0; i < ESM::Attribute::Length; ++i)
|
||||
for (size_t i = 0; i < state.mAttributes.size(); ++i)
|
||||
mAttributes[i].readState(state.mAttributes[i]);
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
for (size_t i = 0; i < state.mDynamic.size(); ++i)
|
||||
mDynamic[i].readState(state.mDynamic[i]);
|
||||
|
||||
mGoldPool = state.mGoldPool;
|
||||
@ -636,7 +636,7 @@ namespace MWMechanics
|
||||
mSummonGraveyard = state.mSummonGraveyard;
|
||||
|
||||
if (state.mHasAiSettings)
|
||||
for (int i = 0; i < 4; ++i)
|
||||
for (size_t i = 0; i < state.mAiSettings.size(); ++i)
|
||||
mAiSettings[i].readState(state.mAiSettings[i]);
|
||||
if (state.mRecalcDynamicStats)
|
||||
recalculateMagicka();
|
||||
|
@ -43,8 +43,7 @@ namespace MWWorld
|
||||
|
||||
ESM::CreatureStats::CorprusStats stats;
|
||||
stats.mNextWorsening = oldStats.mNextWorsening;
|
||||
for (int i = 0; i < ESM::Attribute::Length; ++i)
|
||||
stats.mWorsenings[i] = 0;
|
||||
stats.mWorsenings.fill(0);
|
||||
|
||||
for (auto& effect : spell->mEffects.mList)
|
||||
{
|
||||
@ -179,8 +178,8 @@ namespace MWWorld
|
||||
{
|
||||
it->mNextWorsening = spell.second.mNextWorsening;
|
||||
int worsenings = 0;
|
||||
for (int i = 0; i < ESM::Attribute::Length; ++i)
|
||||
worsenings = std::max(spell.second.mWorsenings[i], worsenings);
|
||||
for (const auto& worsening : spell.second.mWorsenings)
|
||||
worsenings = std::max(worsening, worsenings);
|
||||
it->mWorsenings = worsenings;
|
||||
}
|
||||
}
|
||||
@ -209,20 +208,19 @@ namespace MWWorld
|
||||
}
|
||||
}
|
||||
// Reset modifiers that were previously recalculated each frame
|
||||
for (std::size_t i = 0; i < ESM::Attribute::Length; ++i)
|
||||
creatureStats.mAttributes[i].mMod = 0.f;
|
||||
for (std::size_t i = 0; i < 3; ++i)
|
||||
for (auto& attribute : creatureStats.mAttributes)
|
||||
attribute.mMod = 0.f;
|
||||
for (auto& dynamic : creatureStats.mDynamic)
|
||||
{
|
||||
auto& dynamic = creatureStats.mDynamic[i];
|
||||
dynamic.mCurrent -= dynamic.mMod - dynamic.mBase;
|
||||
dynamic.mMod = 0.f;
|
||||
}
|
||||
for (std::size_t i = 0; i < 4; ++i)
|
||||
creatureStats.mAiSettings[i].mMod = 0.f;
|
||||
for (auto& setting : creatureStats.mAiSettings)
|
||||
setting.mMod = 0.f;
|
||||
if (npcStats)
|
||||
{
|
||||
for (std::size_t i = 0; i < npcStats->mSkills.size(); ++i)
|
||||
npcStats->mSkills[i].mMod = 0.f;
|
||||
for (auto& skill : npcStats->mSkills)
|
||||
skill.mMod = 0.f;
|
||||
}
|
||||
}
|
||||
|
||||
@ -230,9 +228,9 @@ namespace MWWorld
|
||||
// version or not
|
||||
void convertStats(ESM::CreatureStats& creatureStats)
|
||||
{
|
||||
for (std::size_t i = 0; i < 3; ++i)
|
||||
creatureStats.mDynamic[i].mMod = 0.f;
|
||||
for (std::size_t i = 0; i < 4; ++i)
|
||||
creatureStats.mAiSettings[i].mMod = 0.f;
|
||||
for (auto& dynamic : creatureStats.mDynamic)
|
||||
dynamic.mMod = 0.f;
|
||||
for (auto& setting : creatureStats.mAiSettings)
|
||||
setting.mMod = 0.f;
|
||||
}
|
||||
}
|
||||
|
@ -10,11 +10,11 @@ namespace ESM
|
||||
void CreatureStats::load(ESMReader& esm)
|
||||
{
|
||||
const bool intFallback = esm.getFormatVersion() <= MaxIntFallbackFormatVersion;
|
||||
for (int i = 0; i < 8; ++i)
|
||||
mAttributes[i].load(esm, intFallback);
|
||||
for (auto& attribute : mAttributes)
|
||||
attribute.load(esm, intFallback);
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
mDynamic[i].load(esm);
|
||||
for (auto& dynamic : mDynamic)
|
||||
dynamic.load(esm);
|
||||
|
||||
mGoldPool = 0;
|
||||
esm.getHNOT(mGoldPool, "GOLD");
|
||||
@ -154,8 +154,8 @@ namespace ESM
|
||||
|
||||
if (mHasAiSettings)
|
||||
{
|
||||
for (int i = 0; i < 4; ++i)
|
||||
mAiSettings[i].load(esm);
|
||||
for (auto& setting : mAiSettings)
|
||||
setting.load(esm);
|
||||
}
|
||||
|
||||
while (esm.isNextSub("CORP"))
|
||||
@ -179,11 +179,11 @@ namespace ESM
|
||||
|
||||
void CreatureStats::save(ESMWriter& esm) const
|
||||
{
|
||||
for (int i = 0; i < 8; ++i)
|
||||
mAttributes[i].save(esm);
|
||||
for (const auto& attribute : mAttributes)
|
||||
attribute.save(esm);
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
mDynamic[i].save(esm);
|
||||
for (const auto& dynamic : mDynamic)
|
||||
dynamic.save(esm);
|
||||
|
||||
if (mGoldPool)
|
||||
esm.writeHNT("GOLD", mGoldPool);
|
||||
@ -268,8 +268,8 @@ namespace ESM
|
||||
esm.writeHNT("AISE", mHasAiSettings);
|
||||
if (mHasAiSettings)
|
||||
{
|
||||
for (int i = 0; i < 4; ++i)
|
||||
mAiSettings[i].save(esm);
|
||||
for (const auto& setting : mAiSettings)
|
||||
setting.save(esm);
|
||||
}
|
||||
if (mMissingACDT)
|
||||
esm.writeHNT("NOAC", mMissingACDT);
|
||||
|
@ -1,6 +1,7 @@
|
||||
#ifndef OPENMW_ESM_CREATURESTATS_H
|
||||
#define OPENMW_ESM_CREATURESTATS_H
|
||||
|
||||
#include <array>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@ -26,19 +27,19 @@ namespace ESM
|
||||
{
|
||||
struct CorprusStats
|
||||
{
|
||||
int mWorsenings[Attribute::Length];
|
||||
std::array<int, Attribute::Length> mWorsenings;
|
||||
TimeStamp mNextWorsening;
|
||||
};
|
||||
|
||||
StatState<float> mAttributes[Attribute::Length];
|
||||
StatState<float> mDynamic[3];
|
||||
std::array<StatState<float>, Attribute::Length> mAttributes;
|
||||
std::array<StatState<float>, 3> mDynamic;
|
||||
|
||||
MagicEffects mMagicEffects;
|
||||
|
||||
AiSequence::AiSequence mAiSequence;
|
||||
|
||||
bool mHasAiSettings;
|
||||
StatState<int> mAiSettings[4];
|
||||
std::array<StatState<int>, 4> mAiSettings;
|
||||
|
||||
std::map<SummonKey, int> mSummonedCreatureMap;
|
||||
std::multimap<int, int> mSummonedCreatures;
|
||||
|
Loading…
x
Reference in New Issue
Block a user