diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 997eea667b..90cb59ec3a 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -99,7 +99,7 @@ add_openmw_dir (mwmechanics aicast aiescort aiface aiactivate aicombat recharge repair enchanting pathfinding pathgrid security spellcasting spellresistance disease pickpocket levelledlist combat steering obstacle autocalcspell difficultyscaling aicombataction summoning character actors objects aistate trading weaponpriority spellpriority weapontype spellutil - spelleffects + spelleffects magicschool ) add_openmw_dir (mwstate diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index 7fa58589df..4c32ef83cf 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -20,6 +20,7 @@ #include "../mwbase/world.hpp" #include "../mwmechanics/actorutil.hpp" +#include "../mwmechanics/magicschool.hpp" #include "../mwmechanics/spellutil.hpp" #include "../mwworld/class.hpp" #include "../mwworld/esmstore.hpp" @@ -31,9 +32,6 @@ namespace MWGui { - std::string ToolTips::sSchoolNames[] = { "#{sSchoolAlteration}", "#{sSchoolConjuration}", "#{sSchoolDestruction}", - "#{sSchoolIllusion}", "#{sSchoolMysticism}", "#{sSchoolRestoration}" }; - ToolTips::ToolTips() : Layout("openmw_tooltips.layout") , mFocusToolTipX(0.0) @@ -250,8 +248,8 @@ namespace MWGui spell)) // display school of spells that contribute to skill progress { MWWorld::Ptr player = MWMechanics::getPlayer(); - int school = MWMechanics::getSpellSchool(spell, player); - info.text = "#{sSchool}: " + sSchoolNames[school]; + const auto& school = MWMechanics::getMagicSchool(MWMechanics::getSpellSchool(spell, player)); + info.text = "#{sSchool}: " + MyGUI::TextIterator::toTagsString(school.mName).asUTF8(); } const std::string& cost = focus->getUserString("SpellCost"); if (!cost.empty() && cost != "0") @@ -956,7 +954,9 @@ namespace MWGui widget->setUserString("ToolTipLayout", "MagicEffectToolTip"); widget->setUserString("Caption_MagicEffectName", "#{" + name + "}"); 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); } diff --git a/apps/openmw/mwgui/tooltips.hpp b/apps/openmw/mwgui/tooltips.hpp index 4fa0803eaa..500c3bea44 100644 --- a/apps/openmw/mwgui/tooltips.hpp +++ b/apps/openmw/mwgui/tooltips.hpp @@ -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 void position(MyGUI::IntPoint& position, MyGUI::IntSize size, MyGUI::IntSize viewportSize); - static std::string sSchoolNames[6]; - int mHorizontalScrollIndex; float mDelay; diff --git a/apps/openmw/mwmechanics/autocalcspell.cpp b/apps/openmw/mwmechanics/autocalcspell.cpp index 64cc4e8597..0117e3f563 100644 --- a/apps/openmw/mwmechanics/autocalcspell.cpp +++ b/apps/openmw/mwmechanics/autocalcspell.cpp @@ -13,6 +13,7 @@ #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" +#include "magicschool.hpp" #include "spellutil.hpp" namespace MWMechanics @@ -35,27 +36,14 @@ namespace MWMechanics static const float fNPCbaseMagickaMult = gmst.find("fNPCbaseMagickaMult")->mValue.getFloat(); 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 schoolCaps; - for (int i = 0; i < 6; ++i) + for (int i = 0; i < MagicSchool::Length; ++i) { + const MagicSchool& school = getMagicSchool(i); SchoolCaps caps; caps.mCount = 0; - caps.mLimit = iAutoSpellSchoolMax[i]; - caps.mReachedLimit = iAutoSpellSchoolMax[i] <= 0; + caps.mLimit = school.mAutoCalcMax; + caps.mReachedLimit = school.mAutoCalcMax <= 0; caps.mMinCost = std::numeric_limits::max(); caps.mWeakestSpell = ESM::RefId(); schoolCaps[i] = caps; diff --git a/apps/openmw/mwmechanics/magicschool.cpp b/apps/openmw/mwmechanics/magicschool.cpp new file mode 100644 index 0000000000..b98355faeb --- /dev/null +++ b/apps/openmw/mwmechanics/magicschool.cpp @@ -0,0 +1,39 @@ +#include "magicschool.hpp" + +#include + +#include "../mwworld/esmstore.hpp" + +#include "../mwbase/environment.hpp" + +namespace +{ + std::array initSchools() + { + const MWWorld::Store& gmst + = MWBase::Environment::get().getESMStore()->get(); + std::array 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 sSchools = initSchools(); + return sSchools[index]; + } +} diff --git a/apps/openmw/mwmechanics/magicschool.hpp b/apps/openmw/mwmechanics/magicschool.hpp new file mode 100644 index 0000000000..fbfbca0efd --- /dev/null +++ b/apps/openmw/mwmechanics/magicschool.hpp @@ -0,0 +1,26 @@ +#ifndef GAME_MWMECHANICS_MAGICSCHOOL_H +#define GAME_MWMECHANICS_MAGICSCHOOL_H + +#include + +#include + +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 diff --git a/apps/openmw/mwmechanics/spellcasting.cpp b/apps/openmw/mwmechanics/spellcasting.cpp index 59c2a1686d..909784e15b 100644 --- a/apps/openmw/mwmechanics/spellcasting.cpp +++ b/apps/openmw/mwmechanics/spellcasting.cpp @@ -22,6 +22,7 @@ #include "actorutil.hpp" #include "creaturestats.hpp" +#include "magicschool.hpp" #include "spelleffects.hpp" #include "spellutil.hpp" #include "weapontype.hpp" @@ -83,15 +84,12 @@ namespace MWMechanics mHitPosition, static_cast(effectInfo.mArea * 2)); // 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(); if (!effect->mAreaSound.empty()) sndMgr->playSound3D(mHitPosition, effect->mAreaSound, 1.0f, 1.0f); else - sndMgr->playSound3D( - mHitPosition, ESM::RefId::stringRefId(schools[effect->mData.mSchool] + " area"), 1.0f, 1.0f); + sndMgr->playSound3D(mHitPosition, getMagicSchool(effect->mData.mSchool).mAreaSound, 1.0f, 1.0f); } // Get the actors in range of the effect std::vector objects; @@ -341,11 +339,8 @@ namespace MWMechanics school = magicEffect->mData.mSchool; } - static const std::string schools[] - = { "alteration", "conjuration", "destruction", "illusion", "mysticism", "restoration" }; MWBase::SoundManager* sndMgr = MWBase::Environment::get().getSoundManager(); - sndMgr->playSound3D( - mCaster, ESM::RefId::stringRefId("Spell Failure " + schools[school]), 1.0f, 1.0f); + sndMgr->playSound3D(mCaster, getMagicSchool(school).mFailureSound, 1.0f, 1.0f); } return false; } @@ -428,12 +423,8 @@ namespace MWMechanics if (fail) { // Failure sound - static const std::string schools[] - = { "alteration", "conjuration", "destruction", "illusion", "mysticism", "restoration" }; - MWBase::SoundManager* sndMgr = MWBase::Environment::get().getSoundManager(); - sndMgr->playSound3D( - mCaster, ESM::RefId::stringRefId("Spell Failure " + schools[school]), 1.0f, 1.0f); + sndMgr->playSound3D(mCaster, getMagicSchool(school).mFailureSound, 1.0f, 1.0f); return false; } } @@ -595,17 +586,13 @@ namespace MWMechanics if (animation && !mCaster.getClass().isActor()) animation->addSpellCastGlow(effect); - static const std::string schools[] - = { "alteration", "conjuration", "destruction", "illusion", "mysticism", "restoration" }; - addedEffects.push_back(Misc::ResourceHelpers::correctMeshPath(castStatic->mModel, vfs)); MWBase::SoundManager* sndMgr = MWBase::Environment::get().getSoundManager(); if (!effect->mCastSound.empty()) sndMgr->playSound3D(mCaster, effect->mCastSound, 1.0f, 1.0f); else - sndMgr->playSound3D( - mCaster, ESM::RefId::stringRefId(schools[effect->mData.mSchool] + " cast"), 1.0f, 1.0f); + sndMgr->playSound3D(mCaster, getMagicSchool(effect->mData.mSchool).mCastSound, 1.0f, 1.0f); } } @@ -613,15 +600,11 @@ namespace MWMechanics { if (playNonLooping) { - static const std::string schools[] - = { "alteration", "conjuration", "destruction", "illusion", "mysticism", "restoration" }; - MWBase::SoundManager* sndMgr = MWBase::Environment::get().getSoundManager(); if (!magicEffect.mHitSound.empty()) sndMgr->playSound3D(target, magicEffect.mHitSound, 1.0f, 1.0f); else - sndMgr->playSound3D( - target, ESM::RefId::stringRefId(schools[magicEffect.mData.mSchool] + " hit"), 1.0f, 1.0f); + sndMgr->playSound3D(target, getMagicSchool(magicEffect.mData.mSchool).mHitSound, 1.0f, 1.0f); } // Add VFX diff --git a/apps/openmw/mwworld/projectilemanager.cpp b/apps/openmw/mwworld/projectilemanager.cpp index 0785241927..3aa19d1473 100644 --- a/apps/openmw/mwworld/projectilemanager.cpp +++ b/apps/openmw/mwworld/projectilemanager.cpp @@ -42,6 +42,7 @@ #include "../mwmechanics/actorutil.hpp" #include "../mwmechanics/combat.hpp" #include "../mwmechanics/creaturestats.hpp" +#include "../mwmechanics/magicschool.hpp" #include "../mwmechanics/spellcasting.hpp" #include "../mwmechanics/weapontype.hpp" @@ -98,12 +99,10 @@ namespace else projectileIDs.push_back(magicEffect->mBolt); - static const std::string schools[] - = { "alteration", "conjuration", "destruction", "illusion", "mysticism", "restoration" }; if (!magicEffect->mBoltSound.empty()) sounds.emplace(magicEffect->mBoltSound); else - sounds.emplace(ESM::RefId::stringRefId(schools[magicEffect->mData.mSchool] + " bolt")); + sounds.emplace(MWMechanics::getMagicSchool(magicEffect->mData.mSchool).mBoltSound); projectileEffects.mList.push_back(*iter); }