Merge branch 'clickbait' into 'master'

Move more arrays to the ESM::Attribute struct

See merge request OpenMW/openmw!3074
macos_ci
psi29a 2 years ago
commit 4399748889

@ -48,22 +48,18 @@ namespace MWGui
} }
int w = 2; int w = 2;
const auto& store = MWBase::Environment::get().getESMStore();
for (const auto& [effectId, effectInfos] : effects) for (const auto& [effectId, effectInfos] : effects)
{ {
const ESM::MagicEffect* effect const ESM::MagicEffect* effect = store->get<ESM::MagicEffect>().find(effectId);
= MWBase::Environment::get().getESMStore()->get<ESM::MagicEffect>().find(effectId);
float remainingDuration = 0; float remainingDuration = 0;
float totalDuration = 0; float totalDuration = 0;
std::string sourcesDescription; std::string sourcesDescription;
static const float fadeTime = MWBase::Environment::get() static const float fadeTime
.getESMStore() = store->get<ESM::GameSetting>().find("fMagicStartIconBlink")->mValue.getFloat();
->get<ESM::GameSetting>()
.find("fMagicStartIconBlink")
->mValue.getFloat();
bool addNewLine = false; bool addNewLine = false;
for (const MagicEffectInfo& effectInfo : effectInfos) for (const MagicEffectInfo& effectInfo : effectInfos)
@ -94,9 +90,10 @@ namespace MWGui
} }
if (effect->mData.mFlags & ESM::MagicEffect::TargetAttribute) if (effect->mData.mFlags & ESM::MagicEffect::TargetAttribute)
{ {
const ESM::Attribute* attribute = store->get<ESM::Attribute>().find(effectInfo.mKey.mArg);
sourcesDescription += " ("; sourcesDescription += " (";
sourcesDescription += MWBase::Environment::get().getWindowManager()->getGameSettingString( sourcesDescription
ESM::Attribute::sGmstAttributeIds[effectInfo.mKey.mArg], {}); += MWBase::Environment::get().getWindowManager()->getGameSettingString(attribute->mName, {});
sourcesDescription += ')'; sourcesDescription += ')';
} }
ESM::MagicEffect::MagnitudeDisplayType displayType = effect->getMagnitudeDisplayType(); ESM::MagicEffect::MagnitudeDisplayType displayType = effect->getMagnitudeDisplayType();

@ -54,9 +54,9 @@ namespace MWGui
if (effectId != -1) if (effectId != -1)
{ {
const ESM::MagicEffect* magicEffect = store.get<ESM::MagicEffect>().find(effectId); const ESM::MagicEffect* magicEffect = store.get<ESM::MagicEffect>().find(effectId);
const ESM::Attribute* attribute = store.get<ESM::Attribute>().search(effect.mAttribute);
std::string fullEffectName std::string fullEffectName = MWMechanics::getMagicEffectString(*magicEffect, attribute, effect.mSkill);
= MWMechanics::getMagicEffectString(*magicEffect, effect.mAttribute, effect.mSkill);
std::string convert = Utf8Stream::lowerCaseUtf8(fullEffectName); std::string convert = Utf8Stream::lowerCaseUtf8(fullEffectName);
if (convert.find(filter) != std::string::npos) if (convert.find(filter) != std::string::npos)
{ {

@ -340,20 +340,21 @@ namespace MWGui
MWWorld::Ptr player = MWMechanics::getPlayer(); MWWorld::Ptr player = MWMechanics::getPlayer();
const MWMechanics::NpcStats& PCstats = player.getClass().getNpcStats(player); const MWMechanics::NpcStats& PCstats = player.getClass().getNpcStats(player);
const auto& store = MWBase::Environment::get().getESMStore();
std::string detailText; std::string detailText;
std::stringstream detail; std::stringstream detail;
bool first = true; bool first = true;
for (int attribute = 0; attribute < ESM::Attribute::Length; ++attribute) for (const auto& attribute : store->get<ESM::Attribute>())
{ {
float mult = PCstats.getLevelupAttributeMultiplier(attribute); float mult = PCstats.getLevelupAttributeMultiplier(attribute.mId);
mult = std::min(mult, 100 - PCstats.getAttribute(attribute).getBase()); mult = std::min(mult, 100 - PCstats.getAttribute(attribute.mId).getBase());
if (mult > 1) if (mult > 1)
{ {
if (!first) if (!first)
detail << '\n'; detail << '\n';
detail << "#{" << MyGUI::TextIterator::toTagsString(ESM::Attribute::sGmstAttributeIds[attribute]) detail << "#{" << MyGUI::TextIterator::toTagsString(attribute.mName) << "} x"
<< "} x" << MyGUI::utility::toString(mult); << MyGUI::utility::toString(mult);
first = false; first = false;
} }
} }
@ -363,11 +364,7 @@ namespace MWGui
MyGUI::Widget* levelWidget; MyGUI::Widget* levelWidget;
for (int i = 0; i < 2; ++i) for (int i = 0; i < 2; ++i)
{ {
int max = MWBase::Environment::get() int max = store->get<ESM::GameSetting>().find("iLevelUpTotal")->mValue.getInteger();
.getESMStore()
->get<ESM::GameSetting>()
.find("iLevelUpTotal")
->mValue.getInteger();
getWidget(levelWidget, i == 0 ? "Level_str" : "LevelText"); getWidget(levelWidget, i == 0 ? "Level_str" : "LevelText");
levelWidget->setUserString( levelWidget->setUserString(

@ -829,12 +829,14 @@ namespace MWGui
void ToolTips::createAttributeToolTip(MyGUI::Widget* widget, int attributeId) void ToolTips::createAttributeToolTip(MyGUI::Widget* widget, int attributeId)
{ {
if (attributeId == -1) const ESM::Attribute* attribute
= MWBase::Environment::get().getESMStore()->get<ESM::Attribute>().search(attributeId);
if (!attribute)
return; return;
const std::string& icon = ESM::Attribute::sAttributeIcons[attributeId]; const std::string& icon = attribute->mIcon;
const std::string& name = ESM::Attribute::sGmstAttributeIds[attributeId]; const std::string& name = attribute->mName;
const std::string& desc = ESM::Attribute::sGmstAttributeDescIds[attributeId]; const std::string& desc = attribute->mDescription;
widget->setUserString("ToolTipType", "Layout"); widget->setUserString("ToolTipType", "Layout");
widget->setUserString("ToolTipLayout", "AttributeToolTip"); widget->setUserString("ToolTipLayout", "AttributeToolTip");

@ -378,6 +378,7 @@ namespace MWGui::Widgets
const MWWorld::ESMStore& store = *MWBase::Environment::get().getESMStore(); const MWWorld::ESMStore& store = *MWBase::Environment::get().getESMStore();
const ESM::MagicEffect* magicEffect = store.get<ESM::MagicEffect>().search(mEffectParams.mEffectID); const ESM::MagicEffect* magicEffect = store.get<ESM::MagicEffect>().search(mEffectParams.mEffectID);
const ESM::Attribute* attribute = store.get<ESM::Attribute>().search(mEffectParams.mAttribute);
assert(magicEffect); assert(magicEffect);
@ -393,8 +394,7 @@ namespace MWGui::Widgets
std::string sec = " " + std::string{ windowManager->getGameSettingString("ssecond", {}) }; std::string sec = " " + std::string{ windowManager->getGameSettingString("ssecond", {}) };
std::string secs = " " + std::string{ windowManager->getGameSettingString("sseconds", {}) }; std::string secs = " " + std::string{ windowManager->getGameSettingString("sseconds", {}) };
std::string spellLine std::string spellLine = MWMechanics::getMagicEffectString(*magicEffect, attribute, mEffectParams.mSkill);
= MWMechanics::getMagicEffectString(*magicEffect, mEffectParams.mAttribute, mEffectParams.mSkill);
if (mEffectParams.mMagnMin || mEffectParams.mMagnMax) if (mEffectParams.mMagnMin || mEffectParams.mMagnMax)
{ {

@ -561,23 +561,23 @@ std::vector<std::string> MWMechanics::Alchemy::effectsDescription(const MWWorld:
std::vector<std::string> effects; std::vector<std::string> effects;
const auto& item = ptr.get<ESM::Ingredient>()->mBase; const auto& item = ptr.get<ESM::Ingredient>()->mBase;
const auto& gmst = MWBase::Environment::get().getESMStore()->get<ESM::GameSetting>(); const auto& store = MWBase::Environment::get().getESMStore();
const auto& mgef = MWBase::Environment::get().getESMStore()->get<ESM::MagicEffect>(); const auto& mgef = store->get<ESM::MagicEffect>();
const static auto fWortChanceValue = gmst.find("fWortChanceValue")->mValue.getFloat(); const static auto fWortChanceValue = store->get<ESM::GameSetting>().find("fWortChanceValue")->mValue.getFloat();
const auto& data = item->mData; const auto& data = item->mData;
for (auto i = 0; i < 4; ++i) for (auto i = 0; i < 4; ++i)
{ {
const auto effectID = data.mEffectID[i]; const auto effectID = data.mEffectID[i];
const auto skillID = data.mSkills[i]; const auto skillID = data.mSkills[i];
const auto attributeID = data.mAttributes[i];
if (alchemySkill < fWortChanceValue * (i + 1)) if (alchemySkill < fWortChanceValue * (i + 1))
break; break;
if (effectID != -1) if (effectID != -1)
{ {
std::string effect = getMagicEffectString(*mgef.find(effectID), attributeID, skillID); const ESM::Attribute* attribute = store->get<ESM::Attribute>().search(data.mAttributes[i]);
std::string effect = getMagicEffectString(*mgef.find(effectID), attribute, skillID);
effects.push_back(effect); effects.push_back(effect);
} }

@ -51,9 +51,9 @@ namespace MWMechanics
std::string EffectKey::toString() const std::string EffectKey::toString() const
{ {
const ESM::MagicEffect* magicEffect const auto& store = MWBase::Environment::get().getESMStore();
= MWBase::Environment::get().getESMStore()->get<ESM::MagicEffect>().search(mId); const ESM::MagicEffect* magicEffect = store->get<ESM::MagicEffect>().search(mId);
return getMagicEffectString(*magicEffect, mArg, mArg); return getMagicEffectString(*magicEffect, store->get<ESM::Attribute>().find(mArg), mArg);
} }
bool operator<(const EffectKey& left, const EffectKey& right) bool operator<(const EffectKey& left, const EffectKey& right)
@ -227,10 +227,10 @@ namespace MWMechanics
} }
} }
std::string getMagicEffectString(const ESM::MagicEffect& effect, int attributeArg, int skillArg) std::string getMagicEffectString(const ESM::MagicEffect& effect, const ESM::Attribute* attribute, int skillArg)
{ {
const bool targetsSkill = effect.mData.mFlags & ESM::MagicEffect::TargetSkill && skillArg != -1; const bool targetsSkill = effect.mData.mFlags & ESM::MagicEffect::TargetSkill && skillArg != -1;
const bool targetsAttribute = effect.mData.mFlags & ESM::MagicEffect::TargetAttribute && attributeArg != -1; const bool targetsAttribute = effect.mData.mFlags & ESM::MagicEffect::TargetAttribute && attribute;
std::string spellLine; std::string spellLine;
@ -277,7 +277,7 @@ namespace MWMechanics
else if (targetsAttribute) else if (targetsAttribute)
{ {
spellLine += ' '; spellLine += ' ';
spellLine += windowManager->getGameSettingString(ESM::Attribute::sGmstAttributeIds[attributeArg], {}); spellLine += windowManager->getGameSettingString(attribute->mName, {});
} }
return spellLine; return spellLine;
} }

@ -7,6 +7,7 @@
namespace ESM namespace ESM
{ {
struct Attribute;
struct ENAMstruct; struct ENAMstruct;
struct EffectList; struct EffectList;
struct MagicEffect; struct MagicEffect;
@ -113,7 +114,7 @@ namespace MWMechanics
///< Return changes from \a prev to \a now. ///< Return changes from \a prev to \a now.
}; };
std::string getMagicEffectString(const ESM::MagicEffect& effect, int attributeArg, int skillArg); std::string getMagicEffectString(const ESM::MagicEffect& effect, const ESM::Attribute* attribute, int skillArg);
} }
#endif #endif

@ -90,22 +90,17 @@ namespace MWWorld
void Player::setWerewolfStats() void Player::setWerewolfStats()
{ {
const MWWorld::Store<ESM::GameSetting>& gmst const auto& store = MWBase::Environment::get().getESMStore();
= MWBase::Environment::get().getESMStore()->get<ESM::GameSetting>(); const MWWorld::Store<ESM::GameSetting>& gmst = store->get<ESM::GameSetting>();
MWMechanics::CreatureStats& creatureStats = getPlayer().getClass().getCreatureStats(getPlayer()); MWMechanics::CreatureStats& creatureStats = getPlayer().getClass().getCreatureStats(getPlayer());
MWMechanics::NpcStats& npcStats = getPlayer().getClass().getNpcStats(getPlayer()); MWMechanics::NpcStats& npcStats = getPlayer().getClass().getNpcStats(getPlayer());
MWMechanics::DynamicStat<float> health = creatureStats.getDynamic(0); MWMechanics::DynamicStat<float> health = creatureStats.getDynamic(0);
creatureStats.setHealth(health.getBase() * gmst.find("fWereWolfHealth")->mValue.getFloat()); creatureStats.setHealth(health.getBase() * gmst.find("fWereWolfHealth")->mValue.getFloat());
for (size_t i = 0; i < ESM::Attribute::Length; ++i) for (const auto& attribute : store->get<ESM::Attribute>())
{ {
// Oh, Bethesda. It's "Intelligence". MWMechanics::AttributeValue value = npcStats.getAttribute(attribute.mId);
std::string name = "fWerewolf" value.setModifier(gmst.find(attribute.mWerewolfGMST)->mValue.getFloat() - value.getModified());
+ ((i == ESM::Attribute::Intelligence) ? std::string("Intellegence") npcStats.setAttribute(attribute.mId, value);
: ESM::Attribute::sAttributeNames[i]);
MWMechanics::AttributeValue value = npcStats.getAttribute(i);
value.setModifier(gmst.find(name)->mValue.getFloat() - value.getModified());
npcStats.setAttribute(i, value);
} }
for (size_t i = 0; i < ESM::Skill::Length; i++) for (size_t i = 0; i < ESM::Skill::Length; i++)

@ -948,14 +948,47 @@ namespace MWWorld
} }
void Store<ESM::Attribute>::setUp() void Store<ESM::Attribute>::setUp()
{ {
for (int i = 0; i < ESM::Attribute::Length; ++i) mStatic.push_back({ .mId = ESM::Attribute::Strength,
{ .mName = "sAttributeStrength",
ESM::Attribute newAttribute; .mDescription = "sStrDesc",
newAttribute.mId = ESM::Attribute::AttributeID(i); .mIcon = "icons\\k\\attribute_strength.dds",
newAttribute.mName = ESM::Attribute::sGmstAttributeIds[i]; .mWerewolfGMST = "fWerewolfStrength" });
newAttribute.mDescription = ESM::Attribute::sGmstAttributeDescIds[i]; mStatic.push_back({ .mId = ESM::Attribute::Intelligence,
mStatic.push_back(newAttribute); .mName = "sAttributeIntelligence",
} .mDescription = "sIntDesc",
.mIcon = "icons\\k\\attribute_int.dds",
// Oh, Bethesda. It's "Intelligence".
.mWerewolfGMST = "fWerewolfIntellegence" });
mStatic.push_back({ .mId = ESM::Attribute::Willpower,
.mName = "sAttributeWillpower",
.mDescription = "sWilDesc",
.mIcon = "icons\\k\\attribute_wilpower.dds",
.mWerewolfGMST = "fWerewolfWillpower" });
mStatic.push_back({ .mId = ESM::Attribute::Agility,
.mName = "sAttributeAgility",
.mDescription = "sAgiDesc",
.mIcon = "icons\\k\\attribute_agility.dds",
.mWerewolfGMST = "fWerewolfAgility" });
mStatic.push_back({ .mId = ESM::Attribute::Speed,
.mName = "sAttributeSpeed",
.mDescription = "sSpdDesc",
.mIcon = "icons\\k\\attribute_speed.dds",
.mWerewolfGMST = "fWerewolfSpeed" });
mStatic.push_back({ .mId = ESM::Attribute::Endurance,
.mName = "sAttributeEndurance",
.mDescription = "sEndDesc",
.mIcon = "icons\\k\\attribute_endurance.dds",
.mWerewolfGMST = "fWerewolfEndurance" });
mStatic.push_back({ .mId = ESM::Attribute::Personality,
.mName = "sAttributePersonality",
.mDescription = "sPerDesc",
.mIcon = "icons\\k\\attribute_personality.dds",
.mWerewolfGMST = "fWerewolfPersonality" });
mStatic.push_back({ .mId = ESM::Attribute::Luck,
.mName = "sAttributeLuck",
.mDescription = "sLucDesc",
.mIcon = "icons\\k\\attribute_luck.dds",
.mWerewolfGMST = "fWerewolfLuck" });
} }
size_t Store<ESM::Attribute>::getSize() const size_t Store<ESM::Attribute>::getSize() const
{ {

@ -15,39 +15,6 @@ const std::string Attribute::sAttributeNames[Attribute::Length] = {
"Luck", "Luck",
}; };
const std::string Attribute::sGmstAttributeIds[Attribute::Length] = {
"sAttributeStrength",
"sAttributeIntelligence",
"sAttributeWillpower",
"sAttributeAgility",
"sAttributeSpeed",
"sAttributeEndurance",
"sAttributePersonality",
"sAttributeLuck",
};
const std::string Attribute::sGmstAttributeDescIds[Attribute::Length] = {
"sStrDesc",
"sIntDesc",
"sWilDesc",
"sAgiDesc",
"sSpdDesc",
"sEndDesc",
"sPerDesc",
"sLucDesc",
};
const std::string Attribute::sAttributeIcons[Attribute::Length] = {
"icons\\k\\attribute_strength.dds",
"icons\\k\\attribute_int.dds",
"icons\\k\\attribute_wilpower.dds",
"icons\\k\\attribute_agility.dds",
"icons\\k\\attribute_speed.dds",
"icons\\k\\attribute_endurance.dds",
"icons\\k\\attribute_personality.dds",
"icons\\k\\attribute_luck.dds",
};
Attribute::AttributeID Attribute::stringToAttributeId(std::string_view attribute) Attribute::AttributeID Attribute::stringToAttributeId(std::string_view attribute)
{ {
for (int id = 0; id < Attribute::Length; ++id) for (int id = 0; id < Attribute::Length; ++id)

@ -26,12 +26,9 @@ namespace ESM
}; };
AttributeID mId; AttributeID mId;
std::string mName, mDescription; std::string mName, mDescription, mIcon, mWerewolfGMST;
static const std::string sAttributeNames[Length]; static const std::string sAttributeNames[Length];
static const std::string sGmstAttributeIds[Length];
static const std::string sGmstAttributeDescIds[Length];
static const std::string sAttributeIcons[Length];
static AttributeID stringToAttributeId(std::string_view attribute); static AttributeID stringToAttributeId(std::string_view attribute);
}; };

Loading…
Cancel
Save