1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 20:53:50 +00:00

Issue #61: Implemented basic ingredient handling in Alchemy class

This commit is contained in:
Marc Zinnschlag 2012-10-02 10:20:26 +02:00
parent 6469933ce8
commit 1cc2c2055f
2 changed files with 73 additions and 1 deletions

View file

@ -11,6 +11,10 @@ void MWMechanics::Alchemy::setAlchemist (const MWWorld::Ptr& npc)
{
mNpc = npc;
mIngredients.resize (4);
std::fill (mIngredients.begin(), mIngredients.end(), MWWorld::Ptr());
mTools.resize (4);
std::fill (mTools.begin(), mTools.end(), MWWorld::Ptr());
@ -44,3 +48,51 @@ MWMechanics::Alchemy::TToolsIterator MWMechanics::Alchemy::endTools() const
{
return mTools.end();
}
MWMechanics::Alchemy::TIngredientsIterator MWMechanics::Alchemy::beginIngredients() const
{
return mIngredients.begin();
}
MWMechanics::Alchemy::TIngredientsIterator MWMechanics::Alchemy::endIngredients() const
{
return mIngredients.end();
}
void MWMechanics::Alchemy::clear()
{
mNpc = MWWorld::Ptr();
mTools.clear();
mIngredients.clear();
}
int MWMechanics::Alchemy::addIngredient (const MWWorld::Ptr& ingredient)
{
// find a free slot
int slot = -1;
for (int i=0; i<static_cast<int> (mIngredients.size()); ++i)
if (mIngredients[i].isEmpty())
{
slot = i;
break;
}
if (slot==-1)
return -1;
for (TIngredientsIterator iter (mIngredients.begin()); iter!=mIngredients.end(); ++iter)
if (!iter->isEmpty() && ingredient.get<ESM::Ingredient>()==iter->get<ESM::Ingredient>())
return -1;
mIngredients[slot] = ingredient;
return slot;
}
void MWMechanics::Alchemy::removeIngredient (int index)
{
if (index>=0 && index<static_cast<int> (mIngredients.size()))
mIngredients[index] = MWWorld::Ptr();
}

View file

@ -7,7 +7,7 @@
namespace MWMechanics
{
/// \brief Potion creatin via alchemy skill
/// \brief Potion creation via alchemy skill
class Alchemy
{
public:
@ -15,10 +15,14 @@ namespace MWMechanics
typedef std::vector<MWWorld::Ptr> TToolsContainer;
typedef TToolsContainer::const_iterator TToolsIterator;
typedef std::vector<MWWorld::Ptr> TIngredientsContainer;
typedef TIngredientsContainer::const_iterator TIngredientsIterator;
private:
MWWorld::Ptr mNpc;
TToolsContainer mTools;
TIngredientsContainer mIngredients;
public:
@ -29,6 +33,22 @@ namespace MWMechanics
TToolsIterator beginTools() const;
TToolsIterator endTools() const;
TIngredientsIterator beginIngredients() const;
TIngredientsIterator endIngredients() const;
void clear();
///< Remove alchemist, tools and ingredients.
int addIngredient (const MWWorld::Ptr& ingredient);
///< Add ingredient into the next free slot.
///
/// \return Slot index or -1, if adding failed because of no free slot or the ingredient type being
/// listed already.
void removeIngredient (int index);
///< Remove ingredient from slot (calling this function on an empty slot is a no-op).
};
}