forked from mirror/openmw-tes3mp
Remove NpcStats::mProfit and store it in the script instead
Also use the Profit label when the "minimumProfit" script variable exists, rather than hardcoding to NPCs.
This commit is contained in:
parent
bd0a0e64a9
commit
2346c3528d
9 changed files with 76 additions and 49 deletions
|
@ -3,6 +3,22 @@
|
|||
#include "../mwmechanics/npcstats.hpp"
|
||||
#include "../mwworld/class.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void modifyProfit(const MWWorld::Ptr& actor, int diff)
|
||||
{
|
||||
std::string script = actor.getClass().getScript(actor);
|
||||
if (!script.empty())
|
||||
{
|
||||
int profit = actor.getRefData().getLocals().getIntVar(script, "minimumprofit");
|
||||
profit += diff;
|
||||
actor.getRefData().getLocals().setVarByInt(script, "minimumprofit", profit);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
CompanionItemModel::CompanionItemModel(const MWWorld::Ptr &actor)
|
||||
|
@ -12,23 +28,25 @@ namespace MWGui
|
|||
|
||||
MWWorld::Ptr CompanionItemModel::copyItem (const ItemStack& item, size_t count, bool setNewOwner=false)
|
||||
{
|
||||
if (mActor.getClass().isNpc())
|
||||
{
|
||||
MWMechanics::NpcStats& stats = mActor.getClass().getNpcStats(mActor);
|
||||
stats.modifyProfit(item.mBase.getClass().getValue(item.mBase) * count);
|
||||
}
|
||||
if (hasProfit(mActor))
|
||||
modifyProfit(mActor, item.mBase.getClass().getValue(item.mBase) * count);
|
||||
|
||||
return InventoryItemModel::copyItem(item, count, setNewOwner);
|
||||
}
|
||||
|
||||
void CompanionItemModel::removeItem (const ItemStack& item, size_t count)
|
||||
{
|
||||
if (mActor.getClass().isNpc())
|
||||
{
|
||||
MWMechanics::NpcStats& stats = mActor.getClass().getNpcStats(mActor);
|
||||
stats.modifyProfit(-item.mBase.getClass().getValue(item.mBase) * count);
|
||||
}
|
||||
if (hasProfit(mActor))
|
||||
modifyProfit(mActor, -item.mBase.getClass().getValue(item.mBase) * count);
|
||||
|
||||
InventoryItemModel::removeItem(item, count);
|
||||
}
|
||||
|
||||
bool CompanionItemModel::hasProfit(const MWWorld::Ptr &actor)
|
||||
{
|
||||
std::string script = actor.getClass().getScript(actor);
|
||||
if (script.empty())
|
||||
return false;
|
||||
return actor.getRefData().getLocals().hasVar(script, "minimumprofit");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@ namespace MWGui
|
|||
|
||||
virtual MWWorld::Ptr copyItem (const ItemStack& item, size_t count, bool setNewOwner);
|
||||
virtual void removeItem (const ItemStack& item, size_t count);
|
||||
|
||||
bool hasProfit(const MWWorld::Ptr& actor);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -17,6 +17,21 @@
|
|||
#include "draganddrop.hpp"
|
||||
#include "countdialog.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
int getProfit(const MWWorld::Ptr& actor)
|
||||
{
|
||||
std::string script = actor.getClass().getScript(actor);
|
||||
if (!script.empty())
|
||||
{
|
||||
return actor.getRefData().getLocals().getIntVar(script, "minimumprofit");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
|
||||
|
@ -116,13 +131,12 @@ void CompanionWindow::updateEncumbranceBar()
|
|||
float encumbrance = mPtr.getClass().getEncumbrance(mPtr);
|
||||
mEncumbranceBar->setValue(encumbrance, capacity);
|
||||
|
||||
if (mPtr.getTypeName() != typeid(ESM::NPC).name())
|
||||
mProfitLabel->setCaption("");
|
||||
else
|
||||
if (mModel && mModel->hasProfit(mPtr))
|
||||
{
|
||||
MWMechanics::NpcStats& stats = mPtr.getClass().getNpcStats(mPtr);
|
||||
mProfitLabel->setCaptionWithReplacing("#{sProfitValue} " + MyGUI::utility::toString(stats.getProfit()));
|
||||
mProfitLabel->setCaptionWithReplacing("#{sProfitValue} " + MyGUI::utility::toString(getProfit(mPtr)));
|
||||
}
|
||||
else
|
||||
mProfitLabel->setCaption("");
|
||||
}
|
||||
|
||||
void CompanionWindow::onCloseButtonClicked(MyGUI::Widget* _sender)
|
||||
|
@ -132,7 +146,7 @@ void CompanionWindow::onCloseButtonClicked(MyGUI::Widget* _sender)
|
|||
|
||||
void CompanionWindow::exit()
|
||||
{
|
||||
if (mPtr.getTypeName() == typeid(ESM::NPC).name() && mPtr.getClass().getNpcStats(mPtr).getProfit() < 0)
|
||||
if (mModel && mModel->hasProfit(mPtr) && getProfit(mPtr) < 0)
|
||||
{
|
||||
std::vector<std::string> buttons;
|
||||
buttons.push_back("#{sCompanionWarningButtonOne}");
|
||||
|
@ -148,9 +162,6 @@ void CompanionWindow::onMessageBoxButtonClicked(int button)
|
|||
{
|
||||
if (button == 0)
|
||||
{
|
||||
mPtr.getRefData().getLocals().setVarByInt(mPtr.getClass().getScript(mPtr),
|
||||
"minimumprofit", mPtr.getClass().getNpcStats(mPtr).getProfit());
|
||||
|
||||
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Companion);
|
||||
// Important for Calvus' contract script to work properly
|
||||
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Dialogue);
|
||||
|
|
|
@ -31,7 +31,6 @@ MWMechanics::NpcStats::NpcStats()
|
|||
, mReputation(0)
|
||||
, mCrimeId(-1)
|
||||
, mWerewolfKills (0)
|
||||
, mProfit(0)
|
||||
, mTimeToStartDrowning(20.0)
|
||||
{
|
||||
mSkillIncreases.resize (ESM::Attribute::Length, 0);
|
||||
|
@ -448,16 +447,6 @@ void MWMechanics::NpcStats::addWerewolfKill()
|
|||
++mWerewolfKills;
|
||||
}
|
||||
|
||||
int MWMechanics::NpcStats::getProfit() const
|
||||
{
|
||||
return mProfit;
|
||||
}
|
||||
|
||||
void MWMechanics::NpcStats::modifyProfit(int diff)
|
||||
{
|
||||
mProfit += diff;
|
||||
}
|
||||
|
||||
float MWMechanics::NpcStats::getTimeToStartDrowning() const
|
||||
{
|
||||
return mTimeToStartDrowning;
|
||||
|
@ -501,7 +490,6 @@ void MWMechanics::NpcStats::writeState (ESM::NpcStats& state) const
|
|||
|
||||
state.mReputation = mReputation;
|
||||
state.mWerewolfKills = mWerewolfKills;
|
||||
state.mProfit = mProfit;
|
||||
state.mLevelProgress = mLevelProgress;
|
||||
|
||||
for (int i=0; i<ESM::Attribute::Length; ++i)
|
||||
|
@ -548,7 +536,6 @@ void MWMechanics::NpcStats::readState (const ESM::NpcStats& state)
|
|||
mBounty = state.mBounty;
|
||||
mReputation = state.mReputation;
|
||||
mWerewolfKills = state.mWerewolfKills;
|
||||
mProfit = state.mProfit;
|
||||
mLevelProgress = state.mLevelProgress;
|
||||
|
||||
for (int i=0; i<ESM::Attribute::Length; ++i)
|
||||
|
|
|
@ -28,8 +28,6 @@ namespace MWMechanics
|
|||
int mReputation;
|
||||
int mCrimeId;
|
||||
|
||||
int mProfit;
|
||||
|
||||
// ----- used by the player only, maybe should be moved at some point -------
|
||||
int mBounty;
|
||||
int mWerewolfKills;
|
||||
|
@ -49,10 +47,6 @@ namespace MWMechanics
|
|||
|
||||
NpcStats();
|
||||
|
||||
/// for mercenary companions. starts out as 0, and changes when items are added or removed through the UI.
|
||||
int getProfit() const;
|
||||
void modifyProfit(int diff);
|
||||
|
||||
int getBaseDisposition() const;
|
||||
void setBaseDisposition(int disposition);
|
||||
|
||||
|
|
|
@ -32,6 +32,21 @@ namespace MWScript
|
|||
return (mShorts.empty() && mLongs.empty() && mFloats.empty());
|
||||
}
|
||||
|
||||
bool Locals::hasVar(const std::string &script, const std::string &var)
|
||||
{
|
||||
try
|
||||
{
|
||||
const Compiler::Locals& locals =
|
||||
MWBase::Environment::get().getScriptManager()->getLocals(script);
|
||||
int index = locals.getIndex(var);
|
||||
return (index != -1);
|
||||
}
|
||||
catch (const Compiler::SourceException&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int Locals::getIntVar(const std::string &script, const std::string &var)
|
||||
{
|
||||
const Compiler::Locals& locals = MWBase::Environment::get().getScriptManager()->getLocals(script);
|
||||
|
|
|
@ -24,11 +24,15 @@ namespace MWScript
|
|||
bool isEmpty() const;
|
||||
|
||||
void configure (const ESM::Script& script);
|
||||
|
||||
/// @note var needs to be in lowercase
|
||||
bool setVarByInt(const std::string& script, const std::string& var, int val);
|
||||
int getIntVar (const std::string& script, const std::string& var);
|
||||
///< if var does not exist, returns 0
|
||||
|
||||
bool hasVar(const std::string& script, const std::string& var);
|
||||
|
||||
/// if var does not exist, returns 0
|
||||
/// @note var needs to be in lowercase
|
||||
int getIntVar (const std::string& script, const std::string& var);
|
||||
|
||||
void write (ESM::Locals& locals, const std::string& script) const;
|
||||
|
||||
|
|
|
@ -57,12 +57,13 @@ void ESM::NpcStats::load (ESMReader &esm)
|
|||
mWerewolfKills = 0;
|
||||
esm.getHNOT (mWerewolfKills, "WKIL");
|
||||
|
||||
mProfit = 0;
|
||||
esm.getHNOT (mProfit, "PROF");
|
||||
// No longer used
|
||||
if (esm.isNextSub("PROF"))
|
||||
esm.skipHSub(); // int profit
|
||||
|
||||
// No longer used. Now part of CreatureStats.
|
||||
float attackStrength = 0;
|
||||
esm.getHNOT (attackStrength, "ASTR");
|
||||
if (esm.isNextSub("ASTR"))
|
||||
esm.skipHSub(); // attackStrength
|
||||
|
||||
mLevelProgress = 0;
|
||||
esm.getHNOT (mLevelProgress, "LPRO");
|
||||
|
@ -132,9 +133,6 @@ void ESM::NpcStats::save (ESMWriter &esm) const
|
|||
if (mWerewolfKills)
|
||||
esm.writeHNT ("WKIL", mWerewolfKills);
|
||||
|
||||
if (mProfit)
|
||||
esm.writeHNT ("PROF", mProfit);
|
||||
|
||||
if (mLevelProgress)
|
||||
esm.writeHNT ("LPRO", mLevelProgress);
|
||||
|
||||
|
@ -158,7 +156,6 @@ void ESM::NpcStats::blank()
|
|||
mBounty = 0;
|
||||
mReputation = 0;
|
||||
mWerewolfKills = 0;
|
||||
mProfit = 0;
|
||||
mLevelProgress = 0;
|
||||
for (int i=0; i<8; ++i)
|
||||
mSkillIncrease[i] = 0;
|
||||
|
|
|
@ -40,7 +40,6 @@ namespace ESM
|
|||
int mBounty;
|
||||
int mReputation;
|
||||
int mWerewolfKills;
|
||||
int mProfit;
|
||||
int mLevelProgress;
|
||||
int mSkillIncrease[8];
|
||||
std::vector<std::string> mUsedIds; // lower case IDs
|
||||
|
|
Loading…
Reference in a new issue