1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-03-02 20:39:42 +00:00

Combine magic school properties into structs

This commit is contained in:
Evil Eye 2023-06-17 16:31:19 +02:00
parent a555519290
commit 9947a41c37
8 changed files with 85 additions and 52 deletions

View file

@ -99,7 +99,7 @@ add_openmw_dir (mwmechanics
aicast aiescort aiface aiactivate aicombat recharge repair enchanting pathfinding pathgrid security spellcasting spellresistance aicast aiescort aiface aiactivate aicombat recharge repair enchanting pathfinding pathgrid security spellcasting spellresistance
disease pickpocket levelledlist combat steering obstacle autocalcspell difficultyscaling aicombataction summoning disease pickpocket levelledlist combat steering obstacle autocalcspell difficultyscaling aicombataction summoning
character actors objects aistate trading weaponpriority spellpriority weapontype spellutil character actors objects aistate trading weaponpriority spellpriority weapontype spellutil
spelleffects spelleffects magicschool
) )
add_openmw_dir (mwstate add_openmw_dir (mwstate

View file

@ -20,6 +20,7 @@
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
#include "../mwmechanics/actorutil.hpp" #include "../mwmechanics/actorutil.hpp"
#include "../mwmechanics/magicschool.hpp"
#include "../mwmechanics/spellutil.hpp" #include "../mwmechanics/spellutil.hpp"
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "../mwworld/esmstore.hpp" #include "../mwworld/esmstore.hpp"
@ -31,9 +32,6 @@
namespace MWGui namespace MWGui
{ {
std::string ToolTips::sSchoolNames[] = { "#{sSchoolAlteration}", "#{sSchoolConjuration}", "#{sSchoolDestruction}",
"#{sSchoolIllusion}", "#{sSchoolMysticism}", "#{sSchoolRestoration}" };
ToolTips::ToolTips() ToolTips::ToolTips()
: Layout("openmw_tooltips.layout") : Layout("openmw_tooltips.layout")
, mFocusToolTipX(0.0) , mFocusToolTipX(0.0)
@ -250,8 +248,8 @@ namespace MWGui
spell)) // display school of spells that contribute to skill progress spell)) // display school of spells that contribute to skill progress
{ {
MWWorld::Ptr player = MWMechanics::getPlayer(); MWWorld::Ptr player = MWMechanics::getPlayer();
int school = MWMechanics::getSpellSchool(spell, player); const auto& school = MWMechanics::getMagicSchool(MWMechanics::getSpellSchool(spell, player));
info.text = "#{sSchool}: " + sSchoolNames[school]; info.text = "#{sSchool}: " + MyGUI::TextIterator::toTagsString(school.mName).asUTF8();
} }
const std::string& cost = focus->getUserString("SpellCost"); const std::string& cost = focus->getUserString("SpellCost");
if (!cost.empty() && cost != "0") if (!cost.empty() && cost != "0")
@ -956,7 +954,9 @@ namespace MWGui
widget->setUserString("ToolTipLayout", "MagicEffectToolTip"); widget->setUserString("ToolTipLayout", "MagicEffectToolTip");
widget->setUserString("Caption_MagicEffectName", "#{" + name + "}"); widget->setUserString("Caption_MagicEffectName", "#{" + name + "}");
widget->setUserString("Caption_MagicEffectDescription", effect->mDescription); widget->setUserString("Caption_MagicEffectDescription", effect->mDescription);
widget->setUserString("Caption_MagicEffectSchool", "#{sSchool}: " + sSchoolNames[effect->mData.mSchool]); widget->setUserString("Caption_MagicEffectSchool",
"#{sSchool}: "
+ MyGUI::TextIterator::toTagsString(MWMechanics::getMagicSchool(effect->mData.mSchool).mName).asUTF8());
widget->setUserString("ImageTexture_MagicEffectImage", icon); widget->setUserString("ImageTexture_MagicEffectImage", icon);
} }

View file

@ -122,8 +122,6 @@ namespace MWGui
/// Adjust position for a tooltip so that it doesn't leave the screen and does not obscure the mouse cursor /// Adjust position for a tooltip so that it doesn't leave the screen and does not obscure the mouse cursor
void position(MyGUI::IntPoint& position, MyGUI::IntSize size, MyGUI::IntSize viewportSize); void position(MyGUI::IntPoint& position, MyGUI::IntSize size, MyGUI::IntSize viewportSize);
static std::string sSchoolNames[6];
int mHorizontalScrollIndex; int mHorizontalScrollIndex;
float mDelay; float mDelay;

View file

@ -13,6 +13,7 @@
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
#include "magicschool.hpp"
#include "spellutil.hpp" #include "spellutil.hpp"
namespace MWMechanics namespace MWMechanics
@ -35,27 +36,14 @@ namespace MWMechanics
static const float fNPCbaseMagickaMult = gmst.find("fNPCbaseMagickaMult")->mValue.getFloat(); static const float fNPCbaseMagickaMult = gmst.find("fNPCbaseMagickaMult")->mValue.getFloat();
float baseMagicka = fNPCbaseMagickaMult * actorAttributes.at(ESM::Attribute::Intelligence).getBase(); float baseMagicka = fNPCbaseMagickaMult * actorAttributes.at(ESM::Attribute::Intelligence).getBase();
static const std::string schools[]
= { "alteration", "conjuration", "destruction", "illusion", "mysticism", "restoration" };
static int iAutoSpellSchoolMax[6];
static bool init = false;
if (!init)
{
for (int i = 0; i < 6; ++i)
{
const std::string& gmstName = "iAutoSpell" + schools[i] + "Max";
iAutoSpellSchoolMax[i] = gmst.find(gmstName)->mValue.getInteger();
}
init = true;
}
std::map<int, SchoolCaps> schoolCaps; std::map<int, SchoolCaps> schoolCaps;
for (int i = 0; i < 6; ++i) for (int i = 0; i < MagicSchool::Length; ++i)
{ {
const MagicSchool& school = getMagicSchool(i);
SchoolCaps caps; SchoolCaps caps;
caps.mCount = 0; caps.mCount = 0;
caps.mLimit = iAutoSpellSchoolMax[i]; caps.mLimit = school.mAutoCalcMax;
caps.mReachedLimit = iAutoSpellSchoolMax[i] <= 0; caps.mReachedLimit = school.mAutoCalcMax <= 0;
caps.mMinCost = std::numeric_limits<int>::max(); caps.mMinCost = std::numeric_limits<int>::max();
caps.mWeakestSpell = ESM::RefId(); caps.mWeakestSpell = ESM::RefId();
schoolCaps[i] = caps; schoolCaps[i] = caps;

View file

@ -0,0 +1,39 @@
#include "magicschool.hpp"
#include <components/esm3/loadgmst.hpp>
#include "../mwworld/esmstore.hpp"
#include "../mwbase/environment.hpp"
namespace
{
std::array<MWMechanics::MagicSchool, MWMechanics::MagicSchool::Length> initSchools()
{
const MWWorld::Store<ESM::GameSetting>& gmst
= MWBase::Environment::get().getESMStore()->get<ESM::GameSetting>();
std::array<MWMechanics::MagicSchool, MWMechanics::MagicSchool::Length> out;
const std::string schools[]
= { "alteration", "conjuration", "destruction", "illusion", "mysticism", "restoration" };
for (size_t i = 0; i < out.size(); ++i)
{
out[i].mAreaSound = ESM::RefId::stringRefId(schools[i] + " area");
out[i].mBoltSound = ESM::RefId::stringRefId(schools[i] + " bolt");
out[i].mCastSound = ESM::RefId::stringRefId(schools[i] + " cast");
out[i].mFailureSound = ESM::RefId::stringRefId("Spell Failure " + schools[i]);
out[i].mHitSound = ESM::RefId::stringRefId(schools[i] + " hit");
out[i].mName = gmst.find("sSchool" + schools[i])->mValue.getString();
out[i].mAutoCalcMax = gmst.find("iAutoSpell" + schools[i] + "Max")->mValue.getInteger();
}
return out;
}
}
namespace MWMechanics
{
const MagicSchool& getMagicSchool(int index)
{
static const std::array<MagicSchool, MagicSchool::Length> sSchools = initSchools();
return sSchools[index];
}
}

View file

@ -0,0 +1,26 @@
#ifndef GAME_MWMECHANICS_MAGICSCHOOL_H
#define GAME_MWMECHANICS_MAGICSCHOOL_H
#include <components/esm/refid.hpp>
#include <array>
namespace MWMechanics
{
struct MagicSchool
{
ESM::RefId mAreaSound;
ESM::RefId mBoltSound;
ESM::RefId mCastSound;
ESM::RefId mFailureSound;
ESM::RefId mHitSound;
std::string mName;
int mAutoCalcMax;
static constexpr int Length = 6;
};
const MagicSchool& getMagicSchool(int index);
}
#endif

View file

@ -22,6 +22,7 @@
#include "actorutil.hpp" #include "actorutil.hpp"
#include "creaturestats.hpp" #include "creaturestats.hpp"
#include "magicschool.hpp"
#include "spelleffects.hpp" #include "spelleffects.hpp"
#include "spellutil.hpp" #include "spellutil.hpp"
#include "weapontype.hpp" #include "weapontype.hpp"
@ -83,15 +84,12 @@ namespace MWMechanics
mHitPosition, static_cast<float>(effectInfo.mArea * 2)); mHitPosition, static_cast<float>(effectInfo.mArea * 2));
// Play explosion sound (make sure to use NoTrack, since we will delete the projectile now) // Play explosion sound (make sure to use NoTrack, since we will delete the projectile now)
static const std::string schools[]
= { "alteration", "conjuration", "destruction", "illusion", "mysticism", "restoration" };
{ {
MWBase::SoundManager* sndMgr = MWBase::Environment::get().getSoundManager(); MWBase::SoundManager* sndMgr = MWBase::Environment::get().getSoundManager();
if (!effect->mAreaSound.empty()) if (!effect->mAreaSound.empty())
sndMgr->playSound3D(mHitPosition, effect->mAreaSound, 1.0f, 1.0f); sndMgr->playSound3D(mHitPosition, effect->mAreaSound, 1.0f, 1.0f);
else else
sndMgr->playSound3D( sndMgr->playSound3D(mHitPosition, getMagicSchool(effect->mData.mSchool).mAreaSound, 1.0f, 1.0f);
mHitPosition, ESM::RefId::stringRefId(schools[effect->mData.mSchool] + " area"), 1.0f, 1.0f);
} }
// Get the actors in range of the effect // Get the actors in range of the effect
std::vector<MWWorld::Ptr> objects; std::vector<MWWorld::Ptr> objects;
@ -341,11 +339,8 @@ namespace MWMechanics
school = magicEffect->mData.mSchool; school = magicEffect->mData.mSchool;
} }
static const std::string schools[]
= { "alteration", "conjuration", "destruction", "illusion", "mysticism", "restoration" };
MWBase::SoundManager* sndMgr = MWBase::Environment::get().getSoundManager(); MWBase::SoundManager* sndMgr = MWBase::Environment::get().getSoundManager();
sndMgr->playSound3D( sndMgr->playSound3D(mCaster, getMagicSchool(school).mFailureSound, 1.0f, 1.0f);
mCaster, ESM::RefId::stringRefId("Spell Failure " + schools[school]), 1.0f, 1.0f);
} }
return false; return false;
} }
@ -428,12 +423,8 @@ namespace MWMechanics
if (fail) if (fail)
{ {
// Failure sound // Failure sound
static const std::string schools[]
= { "alteration", "conjuration", "destruction", "illusion", "mysticism", "restoration" };
MWBase::SoundManager* sndMgr = MWBase::Environment::get().getSoundManager(); MWBase::SoundManager* sndMgr = MWBase::Environment::get().getSoundManager();
sndMgr->playSound3D( sndMgr->playSound3D(mCaster, getMagicSchool(school).mFailureSound, 1.0f, 1.0f);
mCaster, ESM::RefId::stringRefId("Spell Failure " + schools[school]), 1.0f, 1.0f);
return false; return false;
} }
} }
@ -595,17 +586,13 @@ namespace MWMechanics
if (animation && !mCaster.getClass().isActor()) if (animation && !mCaster.getClass().isActor())
animation->addSpellCastGlow(effect); animation->addSpellCastGlow(effect);
static const std::string schools[]
= { "alteration", "conjuration", "destruction", "illusion", "mysticism", "restoration" };
addedEffects.push_back(Misc::ResourceHelpers::correctMeshPath(castStatic->mModel, vfs)); addedEffects.push_back(Misc::ResourceHelpers::correctMeshPath(castStatic->mModel, vfs));
MWBase::SoundManager* sndMgr = MWBase::Environment::get().getSoundManager(); MWBase::SoundManager* sndMgr = MWBase::Environment::get().getSoundManager();
if (!effect->mCastSound.empty()) if (!effect->mCastSound.empty())
sndMgr->playSound3D(mCaster, effect->mCastSound, 1.0f, 1.0f); sndMgr->playSound3D(mCaster, effect->mCastSound, 1.0f, 1.0f);
else else
sndMgr->playSound3D( sndMgr->playSound3D(mCaster, getMagicSchool(effect->mData.mSchool).mCastSound, 1.0f, 1.0f);
mCaster, ESM::RefId::stringRefId(schools[effect->mData.mSchool] + " cast"), 1.0f, 1.0f);
} }
} }
@ -613,15 +600,11 @@ namespace MWMechanics
{ {
if (playNonLooping) if (playNonLooping)
{ {
static const std::string schools[]
= { "alteration", "conjuration", "destruction", "illusion", "mysticism", "restoration" };
MWBase::SoundManager* sndMgr = MWBase::Environment::get().getSoundManager(); MWBase::SoundManager* sndMgr = MWBase::Environment::get().getSoundManager();
if (!magicEffect.mHitSound.empty()) if (!magicEffect.mHitSound.empty())
sndMgr->playSound3D(target, magicEffect.mHitSound, 1.0f, 1.0f); sndMgr->playSound3D(target, magicEffect.mHitSound, 1.0f, 1.0f);
else else
sndMgr->playSound3D( sndMgr->playSound3D(target, getMagicSchool(magicEffect.mData.mSchool).mHitSound, 1.0f, 1.0f);
target, ESM::RefId::stringRefId(schools[magicEffect.mData.mSchool] + " hit"), 1.0f, 1.0f);
} }
// Add VFX // Add VFX

View file

@ -42,6 +42,7 @@
#include "../mwmechanics/actorutil.hpp" #include "../mwmechanics/actorutil.hpp"
#include "../mwmechanics/combat.hpp" #include "../mwmechanics/combat.hpp"
#include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/magicschool.hpp"
#include "../mwmechanics/spellcasting.hpp" #include "../mwmechanics/spellcasting.hpp"
#include "../mwmechanics/weapontype.hpp" #include "../mwmechanics/weapontype.hpp"
@ -98,12 +99,10 @@ namespace
else else
projectileIDs.push_back(magicEffect->mBolt); projectileIDs.push_back(magicEffect->mBolt);
static const std::string schools[]
= { "alteration", "conjuration", "destruction", "illusion", "mysticism", "restoration" };
if (!magicEffect->mBoltSound.empty()) if (!magicEffect->mBoltSound.empty())
sounds.emplace(magicEffect->mBoltSound); sounds.emplace(magicEffect->mBoltSound);
else else
sounds.emplace(ESM::RefId::stringRefId(schools[magicEffect->mData.mSchool] + " bolt")); sounds.emplace(MWMechanics::getMagicSchool(magicEffect->mData.mSchool).mBoltSound);
projectileEffects.mList.push_back(*iter); projectileEffects.mList.push_back(*iter);
} }