Move levelup to NpcStats

The code came from back in the days where NpcStats did not derive from CreatureStats.
actorid
scrawl 11 years ago
parent ba67bf45f8
commit cc40cec395

@ -10,7 +10,7 @@
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/soundmanager.hpp" #include "../mwbase/soundmanager.hpp"
#include "../mwbase/mechanicsmanager.hpp" #include "../mwbase/mechanicsmanager.hpp"
#include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/npcstats.hpp"
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "../mwworld/fallback.hpp" #include "../mwworld/fallback.hpp"
@ -47,9 +47,8 @@ namespace
void updatePlayerHealth() void updatePlayerHealth()
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
MWMechanics::CreatureStats& creatureStats = MWWorld::Class::get(player).getCreatureStats(player); MWMechanics::NpcStats& npcStats = MWWorld::Class::get(player).getNpcStats(player);
npcStats.updateHealth();
creatureStats.updateHealth();
} }
} }

@ -155,7 +155,6 @@ namespace MWGui
void LevelupDialog::onOkButtonClicked (MyGUI::Widget* sender) void LevelupDialog::onOkButtonClicked (MyGUI::Widget* sender)
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayerPtr(); MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayerPtr();
MWMechanics::CreatureStats& creatureStats = MWWorld::Class::get(player).getCreatureStats (player);
MWMechanics::NpcStats& pcStats = MWWorld::Class::get(player).getNpcStats (player); MWMechanics::NpcStats& pcStats = MWWorld::Class::get(player).getNpcStats (player);
if (mSpentAttributes.size() < 3) if (mSpentAttributes.size() < 3)
@ -165,15 +164,14 @@ namespace MWGui
// increase attributes // increase attributes
for (int i=0; i<3; ++i) for (int i=0; i<3; ++i)
{ {
MWMechanics::AttributeValue attribute = creatureStats.getAttribute(mSpentAttributes[i]); MWMechanics::AttributeValue attribute = pcStats.getAttribute(mSpentAttributes[i]);
attribute.setBase (attribute.getBase () + pcStats.getLevelupAttributeMultiplier (mSpentAttributes[i])); attribute.setBase (attribute.getBase () + pcStats.getLevelupAttributeMultiplier (mSpentAttributes[i]));
if (attribute.getBase() >= 100) if (attribute.getBase() >= 100)
attribute.setBase(100); attribute.setBase(100);
creatureStats.setAttribute(mSpentAttributes[i], attribute); pcStats.setAttribute(mSpentAttributes[i], attribute);
} }
creatureStats.levelUp();
pcStats.levelUp (); pcStats.levelUp ();
MWBase::Environment::get().getWindowManager()->removeGuiMode (GM_Levelup); MWBase::Environment::get().getWindowManager()->removeGuiMode (GM_Levelup);

@ -10,7 +10,7 @@
namespace MWMechanics namespace MWMechanics
{ {
CreatureStats::CreatureStats() CreatureStats::CreatureStats()
: mLevel (0), mLevelHealthBonus(0.f), mDead (false), mDied (false), mFriendlyHits (0), : mLevel (0), mDead (false), mDied (false), mFriendlyHits (0),
mTalkedTo (false), mAlarmed (false), mTalkedTo (false), mAlarmed (false),
mAttacked (false), mHostile (false), mAttacked (false), mHostile (false),
mAttackingOrSpell(false), mAttackingOrSpell(false),
@ -22,35 +22,6 @@ namespace MWMechanics
mAiSettings[i] = 0; mAiSettings[i] = 0;
} }
float CreatureStats::getLevelHealthBonus () const
{
return mLevelHealthBonus;
}
void CreatureStats::levelUp()
{
const MWWorld::Store<ESM::GameSetting> &gmst =
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>();
const int endurance = getAttribute(ESM::Attribute::Endurance).getBase();
// "When you gain a level, in addition to increasing three primary attributes, your Health
// will automatically increase by 10% of your Endurance attribute. If you increased Endurance this level,
// the Health increase is calculated from the increased Endurance"
mLevelHealthBonus += endurance * gmst.find("fLevelUpHealthEndMult")->getFloat();
updateHealth();
mLevel++;
}
void CreatureStats::updateHealth()
{
const int endurance = getAttribute(ESM::Attribute::Endurance).getBase();
const int strength = getAttribute(ESM::Attribute::Strength).getBase();
setHealth(static_cast<int> (0.5 * (strength + endurance)) + mLevelHealthBonus);
}
const AiSequence& CreatureStats::getAiSequence() const const AiSequence& CreatureStats::getAiSequence() const
{ {
return mAiSequence; return mAiSequence;

@ -22,13 +22,11 @@ namespace MWMechanics
DrawState_ mDrawState; DrawState_ mDrawState;
AttributeValue mAttributes[8]; AttributeValue mAttributes[8];
DynamicStat<float> mDynamic[3]; // health, magicka, fatigue DynamicStat<float> mDynamic[3]; // health, magicka, fatigue
int mLevel;
Spells mSpells; Spells mSpells;
ActiveSpells mActiveSpells; ActiveSpells mActiveSpells;
MagicEffects mMagicEffects; MagicEffects mMagicEffects;
Stat<int> mAiSettings[4]; Stat<int> mAiSettings[4];
AiSequence mAiSequence; AiSequence mAiSequence;
float mLevelHealthBonus;
bool mDead; bool mDead;
bool mDied; bool mDied;
int mFriendlyHits; int mFriendlyHits;
@ -54,6 +52,7 @@ namespace MWMechanics
protected: protected:
bool mIsWerewolf; bool mIsWerewolf;
AttributeValue mWerewolfAttributes[8]; AttributeValue mWerewolfAttributes[8];
int mLevel;
public: public:
CreatureStats(); CreatureStats();
@ -142,14 +141,6 @@ namespace MWMechanics
float getFatigueTerm() const; float getFatigueTerm() const;
///< Return effective fatigue ///< Return effective fatigue
float getLevelHealthBonus() const;
void levelUp();
void updateHealth();
///< Calculate health based on endurance and strength.
/// Called at character creation and at level up.
bool isDead() const; bool isDead() const;
bool hasDied() const; bool hasDied() const;

@ -30,6 +30,7 @@ MWMechanics::NpcStats::NpcStats()
, mProfit(0) , mProfit(0)
, mTimeToStartDrowning(20.0) , mTimeToStartDrowning(20.0)
, mLastDrowningHit(0) , mLastDrowningHit(0)
, mLevelHealthBonus(0)
{ {
mSkillIncreases.resize (ESM::Attribute::Length, 0); mSkillIncreases.resize (ESM::Attribute::Length, 0);
} }
@ -237,6 +238,27 @@ void MWMechanics::NpcStats::levelUp()
mLevelProgress -= 10; mLevelProgress -= 10;
for (int i=0; i<ESM::Attribute::Length; ++i) for (int i=0; i<ESM::Attribute::Length; ++i)
mSkillIncreases[i] = 0; mSkillIncreases[i] = 0;
const MWWorld::Store<ESM::GameSetting> &gmst =
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>();
const int endurance = getAttribute(ESM::Attribute::Endurance).getBase();
// "When you gain a level, in addition to increasing three primary attributes, your Health
// will automatically increase by 10% of your Endurance attribute. If you increased Endurance this level,
// the Health increase is calculated from the increased Endurance"
mLevelHealthBonus += endurance * gmst.find("fLevelUpHealthEndMult")->getFloat();
updateHealth();
setLevel(getLevel()+1);
}
void MWMechanics::NpcStats::updateHealth()
{
const int endurance = getAttribute(ESM::Attribute::Endurance).getBase();
const int strength = getAttribute(ESM::Attribute::Strength).getBase();
setHealth(static_cast<int> (0.5 * (strength + endurance)) + mLevelHealthBonus);
} }
int MWMechanics::NpcStats::getLevelupAttributeMultiplier(int attribute) const int MWMechanics::NpcStats::getLevelupAttributeMultiplier(int attribute) const

@ -51,6 +51,8 @@ namespace MWMechanics
/// time since last hit from drowning /// time since last hit from drowning
float mLastDrowningHit; float mLastDrowningHit;
float mLevelHealthBonus;
public: public:
NpcStats(); NpcStats();
@ -98,6 +100,10 @@ namespace MWMechanics
void levelUp(); void levelUp();
void updateHealth();
///< Calculate health based on endurance and strength.
/// Called at character creation and at level up.
void flagAsUsed (const std::string& id); void flagAsUsed (const std::string& id);
bool hasBeenUsed (const std::string& id) const; bool hasBeenUsed (const std::string& id) const;

Loading…
Cancel
Save