mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-27 22:45:34 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
5fdd264d07
4 changed files with 65 additions and 46 deletions
apps/openmw
|
@ -134,11 +134,12 @@ namespace MWGui
|
||||||
for (MWMechanics::Alchemy::TToolsIterator iter (mAlchemy.beginTools());
|
for (MWMechanics::Alchemy::TToolsIterator iter (mAlchemy.beginTools());
|
||||||
iter!=mAlchemy.endTools() && index<static_cast<int> (mApparatus.size()); ++iter, ++index)
|
iter!=mAlchemy.endTools() && index<static_cast<int> (mApparatus.size()); ++iter, ++index)
|
||||||
{
|
{
|
||||||
|
mApparatus.at (index)->setItem(*iter);
|
||||||
|
mApparatus.at (index)->clearUserStrings();
|
||||||
if (!iter->isEmpty())
|
if (!iter->isEmpty())
|
||||||
{
|
{
|
||||||
mApparatus.at (index)->setUserString ("ToolTipType", "ItemPtr");
|
mApparatus.at (index)->setUserString ("ToolTipType", "ItemPtr");
|
||||||
mApparatus.at (index)->setUserData (*iter);
|
mApparatus.at (index)->setUserData (*iter);
|
||||||
mApparatus.at (index)->setItem(*iter);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,6 +174,11 @@ namespace MWGui
|
||||||
|
|
||||||
void AlchemyWindow::update()
|
void AlchemyWindow::update()
|
||||||
{
|
{
|
||||||
|
std::string suggestedName = mAlchemy.suggestPotionName();
|
||||||
|
if (suggestedName != mSuggestedPotionName)
|
||||||
|
mNameEdit->setCaptionWithReplacing(suggestedName);
|
||||||
|
mSuggestedPotionName = suggestedName;
|
||||||
|
|
||||||
mSortModel->clearDragItems();
|
mSortModel->clearDragItems();
|
||||||
|
|
||||||
MWMechanics::Alchemy::TIngredientsIterator it = mAlchemy.beginIngredients ();
|
MWMechanics::Alchemy::TIngredientsIterator it = mAlchemy.beginIngredients ();
|
||||||
|
|
|
@ -23,6 +23,8 @@ namespace MWGui
|
||||||
virtual void exit();
|
virtual void exit();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::string mSuggestedPotionName;
|
||||||
|
|
||||||
ItemView* mItemView;
|
ItemView* mItemView;
|
||||||
SortFilterItemModel* mSortModel;
|
SortFilterItemModel* mSortModel;
|
||||||
|
|
||||||
|
|
|
@ -205,7 +205,7 @@ void MWMechanics::Alchemy::updateEffects()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const ESM::Potion *MWMechanics::Alchemy::getRecord() const
|
const ESM::Potion *MWMechanics::Alchemy::getRecord(const ESM::Potion& toFind) const
|
||||||
{
|
{
|
||||||
const MWWorld::Store<ESM::Potion> &potions =
|
const MWWorld::Store<ESM::Potion> &potions =
|
||||||
MWBase::Environment::get().getWorld()->getStore().get<ESM::Potion>();
|
MWBase::Environment::get().getWorld()->getStore().get<ESM::Potion>();
|
||||||
|
@ -216,6 +216,18 @@ const ESM::Potion *MWMechanics::Alchemy::getRecord() const
|
||||||
if (iter->mEffects.mList.size() != mEffects.size())
|
if (iter->mEffects.mList.size() != mEffects.size())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (iter->mName != toFind.mName
|
||||||
|
|| iter->mScript != toFind.mScript
|
||||||
|
|| iter->mData.mWeight != toFind.mData.mWeight
|
||||||
|
|| iter->mData.mValue != toFind.mData.mValue
|
||||||
|
|| iter->mData.mAutoCalc != toFind.mData.mAutoCalc)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Don't choose an ID that came from the content files, would have unintended side effects
|
||||||
|
// where alchemy can be used to produce quest-relevant items
|
||||||
|
if (!potions.isDynamic(iter->mId))
|
||||||
|
continue;
|
||||||
|
|
||||||
bool mismatch = false;
|
bool mismatch = false;
|
||||||
|
|
||||||
for (int i=0; i<static_cast<int> (iter->mEffects.mList.size()); ++i)
|
for (int i=0; i<static_cast<int> (iter->mEffects.mList.size()); ++i)
|
||||||
|
@ -266,37 +278,34 @@ void MWMechanics::Alchemy::removeIngredients()
|
||||||
|
|
||||||
void MWMechanics::Alchemy::addPotion (const std::string& name)
|
void MWMechanics::Alchemy::addPotion (const std::string& name)
|
||||||
{
|
{
|
||||||
const ESM::Potion *record = getRecord();
|
ESM::Potion newRecord;
|
||||||
|
|
||||||
|
newRecord.mData.mWeight = 0;
|
||||||
|
|
||||||
|
for (TIngredientsIterator iter (beginIngredients()); iter!=endIngredients(); ++iter)
|
||||||
|
if (!iter->isEmpty())
|
||||||
|
newRecord.mData.mWeight += iter->get<ESM::Ingredient>()->mBase->mData.mWeight;
|
||||||
|
|
||||||
|
newRecord.mData.mWeight /= countIngredients();
|
||||||
|
|
||||||
|
newRecord.mData.mValue = mValue;
|
||||||
|
newRecord.mData.mAutoCalc = 0;
|
||||||
|
|
||||||
|
newRecord.mName = name;
|
||||||
|
|
||||||
|
int index = static_cast<int> (std::rand()/(static_cast<double> (RAND_MAX)+1)*6);
|
||||||
|
assert (index>=0 && index<6);
|
||||||
|
|
||||||
|
static const char *meshes[] = { "standard", "bargain", "cheap", "fresh", "exclusive", "quality" };
|
||||||
|
|
||||||
|
newRecord.mModel = "m\\misc_potion_" + std::string (meshes[index]) + "_01.nif";
|
||||||
|
newRecord.mIcon = "m\\tx_potion_" + std::string (meshes[index]) + "_01.dds";
|
||||||
|
|
||||||
|
newRecord.mEffects.mList = mEffects;
|
||||||
|
|
||||||
|
const ESM::Potion* record = getRecord(newRecord);
|
||||||
if (!record)
|
if (!record)
|
||||||
{
|
|
||||||
ESM::Potion newRecord;
|
|
||||||
|
|
||||||
newRecord.mData.mWeight = 0;
|
|
||||||
|
|
||||||
for (TIngredientsIterator iter (beginIngredients()); iter!=endIngredients(); ++iter)
|
|
||||||
if (!iter->isEmpty())
|
|
||||||
newRecord.mData.mWeight += iter->get<ESM::Ingredient>()->mBase->mData.mWeight;
|
|
||||||
|
|
||||||
newRecord.mData.mWeight /= countIngredients();
|
|
||||||
|
|
||||||
newRecord.mData.mValue = mValue;
|
|
||||||
newRecord.mData.mAutoCalc = 0;
|
|
||||||
|
|
||||||
newRecord.mName = name;
|
|
||||||
|
|
||||||
int index = static_cast<int> (std::rand()/(static_cast<double> (RAND_MAX)+1)*6);
|
|
||||||
assert (index>=0 && index<6);
|
|
||||||
|
|
||||||
static const char *name[] = { "standard", "bargain", "cheap", "fresh", "exclusive", "quality" };
|
|
||||||
|
|
||||||
newRecord.mModel = "m\\misc_potion_" + std::string (name[index]) + "_01.nif";
|
|
||||||
newRecord.mIcon = "m\\tx_potion_" + std::string (name[index]) + "_01.dds";
|
|
||||||
|
|
||||||
newRecord.mEffects.mList = mEffects;
|
|
||||||
|
|
||||||
record = MWBase::Environment::get().getWorld()->createRecord (newRecord);
|
record = MWBase::Environment::get().getWorld()->createRecord (newRecord);
|
||||||
}
|
|
||||||
|
|
||||||
mAlchemist.getClass().getContainerStore (mAlchemist).add (record->mId, 1, mAlchemist);
|
mAlchemist.getClass().getContainerStore (mAlchemist).add (record->mId, 1, mAlchemist);
|
||||||
}
|
}
|
||||||
|
@ -436,14 +445,6 @@ MWMechanics::Alchemy::TEffectsIterator MWMechanics::Alchemy::endEffects() const
|
||||||
return mEffects.end();
|
return mEffects.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MWMechanics::Alchemy::getPotionName() const
|
|
||||||
{
|
|
||||||
if (const ESM::Potion *potion = getRecord())
|
|
||||||
return potion->mName;
|
|
||||||
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
MWMechanics::Alchemy::Result MWMechanics::Alchemy::create (const std::string& name)
|
MWMechanics::Alchemy::Result MWMechanics::Alchemy::create (const std::string& name)
|
||||||
{
|
{
|
||||||
if (mTools[ESM::Apparatus::MortarPestle].isEmpty())
|
if (mTools[ESM::Apparatus::MortarPestle].isEmpty())
|
||||||
|
@ -452,7 +453,7 @@ MWMechanics::Alchemy::Result MWMechanics::Alchemy::create (const std::string& na
|
||||||
if (countIngredients()<2)
|
if (countIngredients()<2)
|
||||||
return Result_LessThanTwoIngredients;
|
return Result_LessThanTwoIngredients;
|
||||||
|
|
||||||
if (name.empty() && getPotionName().empty())
|
if (name.empty())
|
||||||
return Result_NoName;
|
return Result_NoName;
|
||||||
|
|
||||||
if (listEffects().empty())
|
if (listEffects().empty())
|
||||||
|
@ -479,3 +480,14 @@ MWMechanics::Alchemy::Result MWMechanics::Alchemy::create (const std::string& na
|
||||||
|
|
||||||
return Result_Success;
|
return Result_Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string MWMechanics::Alchemy::suggestPotionName()
|
||||||
|
{
|
||||||
|
std::set<MWMechanics::EffectKey> effects = listEffects();
|
||||||
|
if (effects.empty())
|
||||||
|
return "";
|
||||||
|
|
||||||
|
int effectId = effects.begin()->mId;
|
||||||
|
return MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find(
|
||||||
|
ESM::MagicEffect::effectIdToString(effectId))->getString();
|
||||||
|
}
|
||||||
|
|
|
@ -56,8 +56,9 @@ namespace MWMechanics
|
||||||
|
|
||||||
void updateEffects();
|
void updateEffects();
|
||||||
|
|
||||||
const ESM::Potion *getRecord() const;
|
const ESM::Potion *getRecord(const ESM::Potion& toFind) const;
|
||||||
///< Return existing record for created potion (may return 0)
|
///< Try to find a potion record similar to \a toFind in the record store, or return 0 if not found
|
||||||
|
/// \note Does not account for record ID, model or icon
|
||||||
|
|
||||||
void removeIngredients();
|
void removeIngredients();
|
||||||
///< Remove selected ingredients from alchemist's inventory, cleanup selected ingredients and
|
///< Remove selected ingredients from alchemist's inventory, cleanup selected ingredients and
|
||||||
|
@ -108,15 +109,13 @@ namespace MWMechanics
|
||||||
void removeIngredient (int index);
|
void removeIngredient (int index);
|
||||||
///< Remove ingredient from slot (calling this function on an empty slot is a no-op).
|
///< Remove ingredient from slot (calling this function on an empty slot is a no-op).
|
||||||
|
|
||||||
std::string getPotionName() const;
|
std::string suggestPotionName ();
|
||||||
///< Return the name of the potion that would be created when calling create (if a record for such
|
///< Suggest a name for the potion, based on the current effects
|
||||||
/// a potion already exists) or return an empty string.
|
|
||||||
|
|
||||||
Result create (const std::string& name);
|
Result create (const std::string& name);
|
||||||
///< Try to create a potion from the ingredients, place it in the inventory of the alchemist and
|
///< Try to create a potion from the ingredients, place it in the inventory of the alchemist and
|
||||||
/// adjust the skills of the alchemist accordingly.
|
/// adjust the skills of the alchemist accordingly.
|
||||||
/// \param name must not be an empty string, unless there is already a potion record (
|
/// \param name must not be an empty string, or Result_NoName is returned
|
||||||
/// getPotionName() does not return an empty string).
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue