mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-22 20:09:43 +00:00
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 "../mwmechanics/npcstats.hpp"
|
||||||
#include "../mwworld/class.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
|
namespace MWGui
|
||||||
{
|
{
|
||||||
CompanionItemModel::CompanionItemModel(const MWWorld::Ptr &actor)
|
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)
|
MWWorld::Ptr CompanionItemModel::copyItem (const ItemStack& item, size_t count, bool setNewOwner=false)
|
||||||
{
|
{
|
||||||
if (mActor.getClass().isNpc())
|
if (hasProfit(mActor))
|
||||||
{
|
modifyProfit(mActor, item.mBase.getClass().getValue(item.mBase) * count);
|
||||||
MWMechanics::NpcStats& stats = mActor.getClass().getNpcStats(mActor);
|
|
||||||
stats.modifyProfit(item.mBase.getClass().getValue(item.mBase) * count);
|
|
||||||
}
|
|
||||||
|
|
||||||
return InventoryItemModel::copyItem(item, count, setNewOwner);
|
return InventoryItemModel::copyItem(item, count, setNewOwner);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompanionItemModel::removeItem (const ItemStack& item, size_t count)
|
void CompanionItemModel::removeItem (const ItemStack& item, size_t count)
|
||||||
{
|
{
|
||||||
if (mActor.getClass().isNpc())
|
if (hasProfit(mActor))
|
||||||
{
|
modifyProfit(mActor, -item.mBase.getClass().getValue(item.mBase) * count);
|
||||||
MWMechanics::NpcStats& stats = mActor.getClass().getNpcStats(mActor);
|
|
||||||
stats.modifyProfit(-item.mBase.getClass().getValue(item.mBase) * count);
|
|
||||||
}
|
|
||||||
|
|
||||||
InventoryItemModel::removeItem(item, 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 MWWorld::Ptr copyItem (const ItemStack& item, size_t count, bool setNewOwner);
|
||||||
virtual void removeItem (const ItemStack& item, size_t count);
|
virtual void removeItem (const ItemStack& item, size_t count);
|
||||||
|
|
||||||
|
bool hasProfit(const MWWorld::Ptr& actor);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,21 @@
|
||||||
#include "draganddrop.hpp"
|
#include "draganddrop.hpp"
|
||||||
#include "countdialog.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
|
namespace MWGui
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -116,13 +131,12 @@ void CompanionWindow::updateEncumbranceBar()
|
||||||
float encumbrance = mPtr.getClass().getEncumbrance(mPtr);
|
float encumbrance = mPtr.getClass().getEncumbrance(mPtr);
|
||||||
mEncumbranceBar->setValue(encumbrance, capacity);
|
mEncumbranceBar->setValue(encumbrance, capacity);
|
||||||
|
|
||||||
if (mPtr.getTypeName() != typeid(ESM::NPC).name())
|
if (mModel && mModel->hasProfit(mPtr))
|
||||||
mProfitLabel->setCaption("");
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
MWMechanics::NpcStats& stats = mPtr.getClass().getNpcStats(mPtr);
|
mProfitLabel->setCaptionWithReplacing("#{sProfitValue} " + MyGUI::utility::toString(getProfit(mPtr)));
|
||||||
mProfitLabel->setCaptionWithReplacing("#{sProfitValue} " + MyGUI::utility::toString(stats.getProfit()));
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
mProfitLabel->setCaption("");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompanionWindow::onCloseButtonClicked(MyGUI::Widget* _sender)
|
void CompanionWindow::onCloseButtonClicked(MyGUI::Widget* _sender)
|
||||||
|
@ -132,7 +146,7 @@ void CompanionWindow::onCloseButtonClicked(MyGUI::Widget* _sender)
|
||||||
|
|
||||||
void CompanionWindow::exit()
|
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;
|
std::vector<std::string> buttons;
|
||||||
buttons.push_back("#{sCompanionWarningButtonOne}");
|
buttons.push_back("#{sCompanionWarningButtonOne}");
|
||||||
|
@ -148,9 +162,6 @@ void CompanionWindow::onMessageBoxButtonClicked(int button)
|
||||||
{
|
{
|
||||||
if (button == 0)
|
if (button == 0)
|
||||||
{
|
{
|
||||||
mPtr.getRefData().getLocals().setVarByInt(mPtr.getClass().getScript(mPtr),
|
|
||||||
"minimumprofit", mPtr.getClass().getNpcStats(mPtr).getProfit());
|
|
||||||
|
|
||||||
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Companion);
|
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Companion);
|
||||||
// Important for Calvus' contract script to work properly
|
// Important for Calvus' contract script to work properly
|
||||||
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Dialogue);
|
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Dialogue);
|
||||||
|
|
|
@ -31,7 +31,6 @@ MWMechanics::NpcStats::NpcStats()
|
||||||
, mReputation(0)
|
, mReputation(0)
|
||||||
, mCrimeId(-1)
|
, mCrimeId(-1)
|
||||||
, mWerewolfKills (0)
|
, mWerewolfKills (0)
|
||||||
, mProfit(0)
|
|
||||||
, mTimeToStartDrowning(20.0)
|
, mTimeToStartDrowning(20.0)
|
||||||
{
|
{
|
||||||
mSkillIncreases.resize (ESM::Attribute::Length, 0);
|
mSkillIncreases.resize (ESM::Attribute::Length, 0);
|
||||||
|
@ -448,16 +447,6 @@ void MWMechanics::NpcStats::addWerewolfKill()
|
||||||
++mWerewolfKills;
|
++mWerewolfKills;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MWMechanics::NpcStats::getProfit() const
|
|
||||||
{
|
|
||||||
return mProfit;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MWMechanics::NpcStats::modifyProfit(int diff)
|
|
||||||
{
|
|
||||||
mProfit += diff;
|
|
||||||
}
|
|
||||||
|
|
||||||
float MWMechanics::NpcStats::getTimeToStartDrowning() const
|
float MWMechanics::NpcStats::getTimeToStartDrowning() const
|
||||||
{
|
{
|
||||||
return mTimeToStartDrowning;
|
return mTimeToStartDrowning;
|
||||||
|
@ -501,7 +490,6 @@ void MWMechanics::NpcStats::writeState (ESM::NpcStats& state) const
|
||||||
|
|
||||||
state.mReputation = mReputation;
|
state.mReputation = mReputation;
|
||||||
state.mWerewolfKills = mWerewolfKills;
|
state.mWerewolfKills = mWerewolfKills;
|
||||||
state.mProfit = mProfit;
|
|
||||||
state.mLevelProgress = mLevelProgress;
|
state.mLevelProgress = mLevelProgress;
|
||||||
|
|
||||||
for (int i=0; i<ESM::Attribute::Length; ++i)
|
for (int i=0; i<ESM::Attribute::Length; ++i)
|
||||||
|
@ -548,7 +536,6 @@ void MWMechanics::NpcStats::readState (const ESM::NpcStats& state)
|
||||||
mBounty = state.mBounty;
|
mBounty = state.mBounty;
|
||||||
mReputation = state.mReputation;
|
mReputation = state.mReputation;
|
||||||
mWerewolfKills = state.mWerewolfKills;
|
mWerewolfKills = state.mWerewolfKills;
|
||||||
mProfit = state.mProfit;
|
|
||||||
mLevelProgress = state.mLevelProgress;
|
mLevelProgress = state.mLevelProgress;
|
||||||
|
|
||||||
for (int i=0; i<ESM::Attribute::Length; ++i)
|
for (int i=0; i<ESM::Attribute::Length; ++i)
|
||||||
|
|
|
@ -28,8 +28,6 @@ namespace MWMechanics
|
||||||
int mReputation;
|
int mReputation;
|
||||||
int mCrimeId;
|
int mCrimeId;
|
||||||
|
|
||||||
int mProfit;
|
|
||||||
|
|
||||||
// ----- used by the player only, maybe should be moved at some point -------
|
// ----- used by the player only, maybe should be moved at some point -------
|
||||||
int mBounty;
|
int mBounty;
|
||||||
int mWerewolfKills;
|
int mWerewolfKills;
|
||||||
|
@ -49,10 +47,6 @@ namespace MWMechanics
|
||||||
|
|
||||||
NpcStats();
|
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;
|
int getBaseDisposition() const;
|
||||||
void setBaseDisposition(int disposition);
|
void setBaseDisposition(int disposition);
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,21 @@ namespace MWScript
|
||||||
return (mShorts.empty() && mLongs.empty() && mFloats.empty());
|
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)
|
int Locals::getIntVar(const std::string &script, const std::string &var)
|
||||||
{
|
{
|
||||||
const Compiler::Locals& locals = MWBase::Environment::get().getScriptManager()->getLocals(script);
|
const Compiler::Locals& locals = MWBase::Environment::get().getScriptManager()->getLocals(script);
|
||||||
|
|
|
@ -24,11 +24,15 @@ namespace MWScript
|
||||||
bool isEmpty() const;
|
bool isEmpty() const;
|
||||||
|
|
||||||
void configure (const ESM::Script& script);
|
void configure (const ESM::Script& script);
|
||||||
|
|
||||||
/// @note var needs to be in lowercase
|
/// @note var needs to be in lowercase
|
||||||
bool setVarByInt(const std::string& script, const std::string& var, int val);
|
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
|
/// @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;
|
void write (ESM::Locals& locals, const std::string& script) const;
|
||||||
|
|
||||||
|
|
|
@ -57,12 +57,13 @@ void ESM::NpcStats::load (ESMReader &esm)
|
||||||
mWerewolfKills = 0;
|
mWerewolfKills = 0;
|
||||||
esm.getHNOT (mWerewolfKills, "WKIL");
|
esm.getHNOT (mWerewolfKills, "WKIL");
|
||||||
|
|
||||||
mProfit = 0;
|
// No longer used
|
||||||
esm.getHNOT (mProfit, "PROF");
|
if (esm.isNextSub("PROF"))
|
||||||
|
esm.skipHSub(); // int profit
|
||||||
|
|
||||||
// No longer used. Now part of CreatureStats.
|
// No longer used. Now part of CreatureStats.
|
||||||
float attackStrength = 0;
|
if (esm.isNextSub("ASTR"))
|
||||||
esm.getHNOT (attackStrength, "ASTR");
|
esm.skipHSub(); // attackStrength
|
||||||
|
|
||||||
mLevelProgress = 0;
|
mLevelProgress = 0;
|
||||||
esm.getHNOT (mLevelProgress, "LPRO");
|
esm.getHNOT (mLevelProgress, "LPRO");
|
||||||
|
@ -132,9 +133,6 @@ void ESM::NpcStats::save (ESMWriter &esm) const
|
||||||
if (mWerewolfKills)
|
if (mWerewolfKills)
|
||||||
esm.writeHNT ("WKIL", mWerewolfKills);
|
esm.writeHNT ("WKIL", mWerewolfKills);
|
||||||
|
|
||||||
if (mProfit)
|
|
||||||
esm.writeHNT ("PROF", mProfit);
|
|
||||||
|
|
||||||
if (mLevelProgress)
|
if (mLevelProgress)
|
||||||
esm.writeHNT ("LPRO", mLevelProgress);
|
esm.writeHNT ("LPRO", mLevelProgress);
|
||||||
|
|
||||||
|
@ -158,7 +156,6 @@ void ESM::NpcStats::blank()
|
||||||
mBounty = 0;
|
mBounty = 0;
|
||||||
mReputation = 0;
|
mReputation = 0;
|
||||||
mWerewolfKills = 0;
|
mWerewolfKills = 0;
|
||||||
mProfit = 0;
|
|
||||||
mLevelProgress = 0;
|
mLevelProgress = 0;
|
||||||
for (int i=0; i<8; ++i)
|
for (int i=0; i<8; ++i)
|
||||||
mSkillIncrease[i] = 0;
|
mSkillIncrease[i] = 0;
|
||||||
|
|
|
@ -40,7 +40,6 @@ namespace ESM
|
||||||
int mBounty;
|
int mBounty;
|
||||||
int mReputation;
|
int mReputation;
|
||||||
int mWerewolfKills;
|
int mWerewolfKills;
|
||||||
int mProfit;
|
|
||||||
int mLevelProgress;
|
int mLevelProgress;
|
||||||
int mSkillIncrease[8];
|
int mSkillIncrease[8];
|
||||||
std::vector<std::string> mUsedIds; // lower case IDs
|
std::vector<std::string> mUsedIds; // lower case IDs
|
||||||
|
|
Loading…
Reference in a new issue