From 861cc26aa6f5fe8b393d271caf092ff74119a678 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 2 Oct 2014 14:45:57 +0200 Subject: [PATCH] Don't sell racial spells (Fixes #1961) --- apps/openmw/mwgui/spellbuyingwindow.cpp | 9 +++++++++ apps/openmw/mwmechanics/autocalcspell.cpp | 2 +- components/esm/spelllist.cpp | 8 ++++++++ components/esm/spelllist.hpp | 3 +++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwgui/spellbuyingwindow.cpp b/apps/openmw/mwgui/spellbuyingwindow.cpp index cd378aadf..dd6339b4c 100644 --- a/apps/openmw/mwgui/spellbuyingwindow.cpp +++ b/apps/openmw/mwgui/spellbuyingwindow.cpp @@ -100,6 +100,15 @@ namespace MWGui if (spell->mData.mType!=ESM::Spell::ST_Spell) continue; // don't try to sell diseases, curses or powers + if (actor.getClass().isNpc()) + { + const ESM::Race* race = + MWBase::Environment::get().getWorld()->getStore().get().find( + actor.get()->mBase->mRace); + if (race->mPowers.exists(spell->mId)) + continue; + } + if (playerHasSpell(iter->first)) continue; diff --git a/apps/openmw/mwmechanics/autocalcspell.cpp b/apps/openmw/mwmechanics/autocalcspell.cpp index 01447c6e4..7b8c43a06 100644 --- a/apps/openmw/mwmechanics/autocalcspell.cpp +++ b/apps/openmw/mwmechanics/autocalcspell.cpp @@ -72,7 +72,7 @@ namespace MWMechanics if (baseMagicka < iAutoSpellTimesCanCast * spell->mData.mCost) continue; - if (race && std::find(race->mPowers.mList.begin(), race->mPowers.mList.end(), spell->mId) != race->mPowers.mList.end()) + if (race && race->mPowers.exists(spell->mId)) continue; if (!attrSkillCheck(spell, actorSkills, actorAttributes)) diff --git a/components/esm/spelllist.cpp b/components/esm/spelllist.cpp index aeface617..8ec386db4 100644 --- a/components/esm/spelllist.cpp +++ b/components/esm/spelllist.cpp @@ -20,4 +20,12 @@ void SpellList::save(ESMWriter &esm) const } } +bool SpellList::exists(const std::string &spell) const +{ + for (std::vector::const_iterator it = mList.begin(); it != mList.end(); ++it) + if (Misc::StringUtils::ciEqual(*it, spell)) + return true; + return false; +} + } diff --git a/components/esm/spelllist.hpp b/components/esm/spelllist.hpp index 934bdda7a..bcd6ba798 100644 --- a/components/esm/spelllist.hpp +++ b/components/esm/spelllist.hpp @@ -16,6 +16,9 @@ namespace ESM { std::vector mList; + /// Is this spell ID in mList? + bool exists(const std::string& spell) const; + void load(ESMReader &esm); void save(ESMWriter &esm) const; };