From edca5ac0b879b200f670ae94b2f56db2b46226aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Fri, 25 Mar 2022 20:47:43 +0200 Subject: [PATCH] Rename hasDisease to hasSpellType and refactor function --- apps/openmw/mwmechanics/spells.cpp | 18 ++++++++---------- apps/openmw/mwmechanics/spells.hpp | 2 +- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/apps/openmw/mwmechanics/spells.cpp b/apps/openmw/mwmechanics/spells.cpp index 09390425f6..e3e8e849e4 100644 --- a/apps/openmw/mwmechanics/spells.cpp +++ b/apps/openmw/mwmechanics/spells.cpp @@ -112,25 +112,23 @@ namespace MWMechanics return mSelectedSpell; } - bool Spells::hasDisease(const ESM::Spell::SpellType type) const + bool Spells::hasSpellType(const ESM::Spell::SpellType type) const { - for (const auto spell : mSpells) - { - if (spell->mData.mType == type) - return true; - } - - return false; + auto it = std::find_if(std::begin(mSpells), std::end(mSpells), [=](const ESM::Spell* spell) + { + return spell->mData.mType == type; + }); + return it != std::end(mSpells); } bool Spells::hasCommonDisease() const { - return hasDisease(ESM::Spell::ST_Disease); + return hasSpellType(ESM::Spell::ST_Disease); } bool Spells::hasBlightDisease() const { - return hasDisease(ESM::Spell::ST_Blight); + return hasSpellType(ESM::Spell::ST_Blight); } void Spells::purge(const SpellFilter& filter) diff --git a/apps/openmw/mwmechanics/spells.hpp b/apps/openmw/mwmechanics/spells.hpp index 89e24c4eb5..25dab0c9d4 100644 --- a/apps/openmw/mwmechanics/spells.hpp +++ b/apps/openmw/mwmechanics/spells.hpp @@ -36,7 +36,7 @@ namespace MWMechanics std::vector> mUsedPowers; - bool hasDisease(const ESM::Spell::SpellType type) const; + bool hasSpellType(const ESM::Spell::SpellType type) const; using SpellFilter = bool (*)(const ESM::Spell*); void purge(const SpellFilter& filter);