From 3c71378fade9b52cd011034425aa7c585f818444 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 18 Oct 2012 14:41:57 +0200 Subject: [PATCH] Issue 61: improved ingredients handling in alchemy and documenation --- apps/openmw/mwmechanics/alchemy.cpp | 29 ++++++++++++++--------------- apps/openmw/mwmechanics/alchemy.hpp | 4 ++++ 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/apps/openmw/mwmechanics/alchemy.cpp b/apps/openmw/mwmechanics/alchemy.cpp index 3a5efbaaf6..d59d713064 100644 --- a/apps/openmw/mwmechanics/alchemy.cpp +++ b/apps/openmw/mwmechanics/alchemy.cpp @@ -148,13 +148,7 @@ void MWMechanics::Alchemy::updateEffects() { mEffects.clear(); - int ingredients = 0; - - for (TIngredientsIterator iter (beginIngredients()); iter!=endIngredients(); ++iter) - if (!iter->isEmpty()) - ++ingredients; - - if (ingredients<2 || mAlchemist.isEmpty() || mTools[ESM::Apparatus::MortarPestle].isEmpty()) + if (countIngredients()<2 || mAlchemist.isEmpty() || mTools[ESM::Apparatus::MortarPestle].isEmpty()) return; // find effects @@ -251,6 +245,17 @@ float MWMechanics::Alchemy::getChance() const + 0.1 * creatureStats.getAttribute (7).getModified()); } +int MWMechanics::Alchemy::countIngredients() const +{ + int ingredients = 0; + + for (TIngredientsIterator iter (beginIngredients()); iter!=endIngredients(); ++iter) + if (!iter->isEmpty()) + ++ingredients; + + return ingredients; +} + void MWMechanics::Alchemy::setAlchemist (const MWWorld::Ptr& npc) { mAlchemist = npc; @@ -370,14 +375,8 @@ MWMechanics::Alchemy::Result MWMechanics::Alchemy::create (const std::string& na { if (mTools[ESM::Apparatus::MortarPestle].isEmpty()) return Result_NoMortarAndPestle; - - int ingredients = 0; - - for (TIngredientsIterator iter (beginIngredients()); iter!=endIngredients(); ++iter) - if (!iter->isEmpty()) - ++ingredients; - - if (ingredients<2) + + if (countIngredients()<2) return Result_LessThanTwoIngredients; if (name.empty() && getPotionName().empty()) diff --git a/apps/openmw/mwmechanics/alchemy.hpp b/apps/openmw/mwmechanics/alchemy.hpp index 73fa7eb188..52af29912e 100644 --- a/apps/openmw/mwmechanics/alchemy.hpp +++ b/apps/openmw/mwmechanics/alchemy.hpp @@ -70,6 +70,8 @@ namespace MWMechanics float getChance() const; ///< Return chance of success. + int countIngredients() const; + public: void setAlchemist (const MWWorld::Ptr& npc); @@ -77,10 +79,12 @@ namespace MWMechanics /// there is no alchemist (alchemy session has ended). TToolsIterator beginTools() const; + ///< \attention Iterates over tool slots, not over tools. Some of the slots may be empty. TToolsIterator endTools() const; TIngredientsIterator beginIngredients() const; + ///< \attention Iterates over ingredient slots, not over ingredients. Some of the slots may be empty. TIngredientsIterator endIngredients() const;