From c9791c5c1a126dde031378cfd5c568e4a2d86519 Mon Sep 17 00:00:00 2001 From: ae-g-i-s Date: Tue, 8 Mar 2016 21:30:28 +0100 Subject: [PATCH] Add addTemporaryDispositionChange parameter to MechanicsManager::getDerivedDisposition(), adjust callers that previously added temp disposition changes themselves (fixes #3233) --- apps/openmw/mwbase/mechanicsmanager.hpp | 2 +- apps/openmw/mwdialogue/filter.cpp | 3 +-- apps/openmw/mwgui/dialogue.cpp | 3 +-- apps/openmw/mwgui/tradewindow.cpp | 3 +-- apps/openmw/mwmechanics/mechanicsmanagerimp.cpp | 10 ++++++---- apps/openmw/mwmechanics/mechanicsmanagerimp.hpp | 2 +- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/apps/openmw/mwbase/mechanicsmanager.hpp b/apps/openmw/mwbase/mechanicsmanager.hpp index 42da1a052..b29859781 100644 --- a/apps/openmw/mwbase/mechanicsmanager.hpp +++ b/apps/openmw/mwbase/mechanicsmanager.hpp @@ -97,7 +97,7 @@ namespace MWBase virtual int getBarterOffer(const MWWorld::Ptr& ptr,int basePrice, bool buying) = 0; ///< This is used by every service to determine the price of objects given the trading skills of the player and NPC. - virtual int getDerivedDisposition(const MWWorld::Ptr& ptr) = 0; + virtual int getDerivedDisposition(const MWWorld::Ptr& ptr, bool addTemporaryDispositionChange = false) = 0; ///< Calculate the diposition of an NPC toward the player. virtual int countDeaths (const std::string& id) const = 0; diff --git a/apps/openmw/mwdialogue/filter.cpp b/apps/openmw/mwdialogue/filter.cpp index 69df38ccf..223690a71 100644 --- a/apps/openmw/mwdialogue/filter.cpp +++ b/apps/openmw/mwdialogue/filter.cpp @@ -145,8 +145,7 @@ bool MWDialogue::Filter::testDisposition (const ESM::DialInfo& info, bool invert if (isCreature) return true; - int actorDisposition = MWBase::Environment::get().getMechanicsManager()->getDerivedDisposition(mActor) - + MWBase::Environment::get().getDialogueManager()->getTemporaryDispositionChange(); + int actorDisposition = MWBase::Environment::get().getMechanicsManager()->getDerivedDisposition(mActor, true); // For service refusal, the disposition check is inverted. However, a value of 0 still means "always succeed". return invert ? (info.mData.mDisposition == 0 || actorDisposition < info.mData.mDisposition) : (actorDisposition >= info.mData.mDisposition); diff --git a/apps/openmw/mwgui/dialogue.cpp b/apps/openmw/mwgui/dialogue.cpp index 040cd6d65..76f39f5e7 100644 --- a/apps/openmw/mwgui/dialogue.cpp +++ b/apps/openmw/mwgui/dialogue.cpp @@ -640,8 +640,7 @@ namespace MWGui if(mMainWidget->getVisible() && mEnabled && mPtr.getTypeName() == typeid(ESM::NPC).name()) { int disp = std::max(0, std::min(100, - MWBase::Environment::get().getMechanicsManager()->getDerivedDisposition(mPtr) - + MWBase::Environment::get().getDialogueManager()->getTemporaryDispositionChange())); + MWBase::Environment::get().getMechanicsManager()->getDerivedDisposition(mPtr, true))); mDispositionBar->setProgressRange(100); mDispositionBar->setProgressPosition(disp); mDispositionText->setCaption(MyGUI::utility::toString(disp)+std::string("/100")); diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index 6f45ed005..d692c8b09 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -346,8 +346,7 @@ namespace MWGui else d = int(100 * (b - a) / a); - int clampedDisposition = std::max(0, std::min(MWBase::Environment::get().getMechanicsManager()->getDerivedDisposition(mPtr) - + MWBase::Environment::get().getDialogueManager()->getTemporaryDispositionChange(),100)); + int clampedDisposition = std::max(0, std::min(MWBase::Environment::get().getMechanicsManager()->getDerivedDisposition(mPtr, true),100)); const MWMechanics::CreatureStats &sellerStats = mPtr.getClass().getCreatureStats(mPtr); const MWMechanics::CreatureStats &playerStats = player.getClass().getCreatureStats(player); diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp index 7fbc3a853..e6a92b9ea 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp @@ -581,7 +581,7 @@ namespace MWMechanics mUpdatePlayer = true; } - int MechanicsManager::getDerivedDisposition(const MWWorld::Ptr& ptr) + int MechanicsManager::getDerivedDisposition(const MWWorld::Ptr& ptr, bool addTemporaryDispositionChange/* = false */) { const MWMechanics::NpcStats& npcSkill = ptr.getClass().getNpcStats(ptr); float x = static_cast(npcSkill.getBaseDisposition()); @@ -653,6 +653,9 @@ namespace MWMechanics x += ptr.getClass().getCreatureStats(ptr).getMagicEffects().get(ESM::MagicEffect::Charm).getMagnitude(); + if(addTemporaryDispositionChange) + x += MWBase::Environment::get().getDialogueManager()->getTemporaryDispositionChange(); + int effective_disposition = std::max(0,std::min(int(x),100));//, normally clamped to [0..100] when used return effective_disposition; } @@ -667,10 +670,9 @@ namespace MWMechanics MWWorld::Ptr playerPtr = getPlayer(); const MWMechanics::NpcStats &playerStats = playerPtr.getClass().getNpcStats(playerPtr); - // I suppose the temporary disposition change _has_ to be considered here, + // I suppose the temporary disposition change (second param to getDerivedDisposition()) _has_ to be considered here, // otherwise one would get different prices when exiting and re-entering the dialogue window... - int clampedDisposition = std::max(0, std::min(getDerivedDisposition(ptr) - + MWBase::Environment::get().getDialogueManager()->getTemporaryDispositionChange(),100)); + int clampedDisposition = std::max(0, std::min(getDerivedDisposition(ptr, true),100)); float a = static_cast(std::min(playerStats.getSkill(ESM::Skill::Mercantile).getModified(), 100)); float b = std::min(0.1f * playerStats.getAttribute(ESM::Attribute::Luck).getModified(), 10.f); float c = std::min(0.2f * playerStats.getAttribute(ESM::Attribute::Personality).getModified(), 10.f); diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp index fb29c07ea..c61dce521 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp @@ -92,7 +92,7 @@ namespace MWMechanics virtual int getBarterOffer(const MWWorld::Ptr& ptr,int basePrice, bool buying); ///< This is used by every service to determine the price of objects given the trading skills of the player and NPC. - virtual int getDerivedDisposition(const MWWorld::Ptr& ptr); + virtual int getDerivedDisposition(const MWWorld::Ptr& ptr, bool addTemporaryDispositionChange = false); ///< Calculate the diposition of an NPC toward the player. virtual int countDeaths (const std::string& id) const;