From 42f02f3ccd2b11e06868587871174661448865e3 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sun, 30 Sep 2012 18:54:20 +0200 Subject: [PATCH] Issue #61: Re-implemented tool selection in Alchemy class --- apps/openmw/mwmechanics/alchemy.cpp | 39 +++++++++++++++++++++++++++++ apps/openmw/mwmechanics/alchemy.hpp | 14 +++++++++++ 2 files changed, 53 insertions(+) diff --git a/apps/openmw/mwmechanics/alchemy.cpp b/apps/openmw/mwmechanics/alchemy.cpp index ea5cbe965..0a0189190 100644 --- a/apps/openmw/mwmechanics/alchemy.cpp +++ b/apps/openmw/mwmechanics/alchemy.cpp @@ -1,7 +1,46 @@ #include "alchemy.hpp" +#include +#include + +#include "../mwworld/containerstore.hpp" +#include "../mwworld/class.hpp" + void MWMechanics::Alchemy::setAlchemist (const MWWorld::Ptr& npc) { mNpc = npc; + + mTools.resize (4); + + std::fill (mTools.begin(), mTools.end(), MWWorld::Ptr()); + + MWWorld::ContainerStore& store = MWWorld::Class::get (npc).getContainerStore (npc); + + for (MWWorld::ContainerStoreIterator iter (store.begin (MWWorld::ContainerStore::Type_Apparatus)); + iter!=store.end(); ++iter) + { + MWWorld::LiveCellRef* ref = iter->get(); + + int type = ref->base->data.type; + + if (type<0 || type>=static_cast (mTools.size())) + throw std::runtime_error ("invalid apparatus type"); + + if (!mTools[type].isEmpty()) + if (ref->base->data.quality<=mTools[type].get()->base->data.quality) + continue; + + mTools[type] = *iter; + } +} + +MWMechanics::Alchemy::TToolsIterator MWMechanics::Alchemy::beginTools() const +{ + return mTools.begin(); +} + +MWMechanics::Alchemy::TToolsIterator MWMechanics::Alchemy::endTools() const +{ + return mTools.end(); } diff --git a/apps/openmw/mwmechanics/alchemy.hpp b/apps/openmw/mwmechanics/alchemy.hpp index 93c50f1ff..fcaba9012 100644 --- a/apps/openmw/mwmechanics/alchemy.hpp +++ b/apps/openmw/mwmechanics/alchemy.hpp @@ -1,6 +1,8 @@ #ifndef GAME_MWMECHANICS_ALCHEMY_H #define GAME_MWMECHANICS_ALCHEMY_H +#include + #include "../mwworld/ptr.hpp" namespace MWMechanics @@ -8,13 +10,25 @@ namespace MWMechanics /// \brief Potion creatin via alchemy skill class Alchemy { + public: + + typedef std::vector TToolsContainer; + typedef TToolsContainer::const_iterator TToolsIterator; + + private: + MWWorld::Ptr mNpc; + TToolsContainer mTools; public: void setAlchemist (const MWWorld::Ptr& npc); ///< Set alchemist and configure alchemy setup accordingly. \a npc may be empty to indicate that /// there is no alchemist (alchemy session has ended). + + TToolsIterator beginTools() const; + + TToolsIterator endTools() const; }; }