Don't reveal unknown potion effects in alchemy window (Fixes #3146)

coverity_scan
scrawl 9 years ago
parent d3b76b7006
commit b9d1d6144a

@ -20,7 +20,7 @@
#include "../mwrender/objects.hpp"
#include "../mwrender/renderinginterface.hpp"
#include "../mwmechanics/npcstats.hpp"
#include "../mwmechanics/alchemy.hpp"
namespace MWClass
{
@ -124,17 +124,8 @@ namespace MWClass
// hide effects the player doesnt know about
MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayerPtr();
MWMechanics::NpcStats& npcStats = player.getClass().getNpcStats (player);
int alchemySkill = npcStats.getSkill (ESM::Skill::Alchemy).getBase();
int i=0;
static const float fWortChanceValue =
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fWortChanceValue")->getFloat();
for (MWGui::Widgets::SpellEffectList::iterator it = info.effects.begin(); it != info.effects.end(); ++it)
{
it->mKnown = (i <= 1 && alchemySkill >= fWortChanceValue)
|| (i <= 3 && alchemySkill >= fWortChanceValue*2);
++i;
}
for (unsigned int i=0; i<info.effects.size(); ++i)
info.effects[i].mKnown = MWMechanics::Alchemy::knownEffect(i, player);
info.isPotion = true;

@ -216,6 +216,7 @@ namespace MWGui
std::set<MWMechanics::EffectKey> effectIds = mAlchemy->listEffects();
Widgets::SpellEffectList list;
unsigned int effectIndex=0;
for (std::set<MWMechanics::EffectKey>::iterator it = effectIds.begin(); it != effectIds.end(); ++it)
{
Widgets::SpellEffectParams params;
@ -228,7 +229,10 @@ namespace MWGui
params.mIsConstant = true;
params.mNoTarget = true;
params.mKnown = mAlchemy->knownEffect(effectIndex, MWBase::Environment::get().getWorld()->getPlayerPtr());
list.push_back(params);
++effectIndex;
}
while (mEffectsBox->getChildCount())

@ -451,6 +451,16 @@ MWMechanics::Alchemy::TEffectsIterator MWMechanics::Alchemy::endEffects() const
return mEffects.end();
}
bool MWMechanics::Alchemy::knownEffect(unsigned int potionEffectIndex, const MWWorld::Ptr &npc)
{
MWMechanics::NpcStats& npcStats = npc.getClass().getNpcStats(npc);
int alchemySkill = npcStats.getSkill (ESM::Skill::Alchemy).getBase();
static const float fWortChanceValue =
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fWortChanceValue")->getFloat();
return (potionEffectIndex <= 1 && alchemySkill >= fWortChanceValue)
|| (potionEffectIndex <= 3 && alchemySkill >= fWortChanceValue*2);
}
MWMechanics::Alchemy::Result MWMechanics::Alchemy::create (const std::string& name)
{
if (mTools[ESM::Apparatus::MortarPestle].isEmpty())

@ -80,6 +80,9 @@ namespace MWMechanics
public:
static bool knownEffect (unsigned int potionEffectIndex, const MWWorld::Ptr& npc);
///< Does npc have sufficient alchemy skill to know about this potion effect?
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).

Loading…
Cancel
Save