mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-11-03 23:26:40 +00:00 
			
		
		
		
	Move levelup to NpcStats
The code came from back in the days where NpcStats did not derive from CreatureStats.
This commit is contained in:
		
							parent
							
								
									ba67bf45f8
								
							
						
					
					
						commit
						cc40cec395
					
				
					 6 changed files with 35 additions and 48 deletions
				
			
		| 
						 | 
				
			
			@ -10,7 +10,7 @@
 | 
			
		|||
#include "../mwbase/environment.hpp"
 | 
			
		||||
#include "../mwbase/soundmanager.hpp"
 | 
			
		||||
#include "../mwbase/mechanicsmanager.hpp"
 | 
			
		||||
#include "../mwmechanics/creaturestats.hpp"
 | 
			
		||||
#include "../mwmechanics/npcstats.hpp"
 | 
			
		||||
#include "../mwworld/class.hpp"
 | 
			
		||||
#include "../mwworld/fallback.hpp"
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -47,9 +47,8 @@ namespace
 | 
			
		|||
    void updatePlayerHealth()
 | 
			
		||||
    {
 | 
			
		||||
        MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
 | 
			
		||||
        MWMechanics::CreatureStats& creatureStats = MWWorld::Class::get(player).getCreatureStats(player);
 | 
			
		||||
 | 
			
		||||
        creatureStats.updateHealth();
 | 
			
		||||
        MWMechanics::NpcStats& npcStats = MWWorld::Class::get(player).getNpcStats(player);
 | 
			
		||||
        npcStats.updateHealth();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -155,7 +155,6 @@ namespace MWGui
 | 
			
		|||
    void LevelupDialog::onOkButtonClicked (MyGUI::Widget* sender)
 | 
			
		||||
    {
 | 
			
		||||
        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);
 | 
			
		||||
 | 
			
		||||
        if (mSpentAttributes.size() < 3)
 | 
			
		||||
| 
						 | 
				
			
			@ -165,15 +164,14 @@ namespace MWGui
 | 
			
		|||
            // increase attributes
 | 
			
		||||
            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]));
 | 
			
		||||
 | 
			
		||||
                if (attribute.getBase() >= 100)
 | 
			
		||||
                    attribute.setBase(100);
 | 
			
		||||
                creatureStats.setAttribute(mSpentAttributes[i], attribute);
 | 
			
		||||
                pcStats.setAttribute(mSpentAttributes[i], attribute);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            creatureStats.levelUp();
 | 
			
		||||
            pcStats.levelUp ();
 | 
			
		||||
 | 
			
		||||
            MWBase::Environment::get().getWindowManager()->removeGuiMode (GM_Levelup);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,7 +10,7 @@
 | 
			
		|||
namespace MWMechanics
 | 
			
		||||
{
 | 
			
		||||
    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),
 | 
			
		||||
          mAttacked (false), mHostile (false),
 | 
			
		||||
          mAttackingOrSpell(false),
 | 
			
		||||
| 
						 | 
				
			
			@ -22,35 +22,6 @@ namespace MWMechanics
 | 
			
		|||
            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
 | 
			
		||||
    {
 | 
			
		||||
        return mAiSequence;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -22,13 +22,11 @@ namespace MWMechanics
 | 
			
		|||
        DrawState_ mDrawState;
 | 
			
		||||
        AttributeValue mAttributes[8];
 | 
			
		||||
        DynamicStat<float> mDynamic[3]; // health, magicka, fatigue
 | 
			
		||||
        int mLevel;
 | 
			
		||||
        Spells mSpells;
 | 
			
		||||
        ActiveSpells mActiveSpells;
 | 
			
		||||
        MagicEffects mMagicEffects;
 | 
			
		||||
        Stat<int> mAiSettings[4];
 | 
			
		||||
        AiSequence mAiSequence;
 | 
			
		||||
        float mLevelHealthBonus;
 | 
			
		||||
        bool mDead;
 | 
			
		||||
        bool mDied;
 | 
			
		||||
        int mFriendlyHits;
 | 
			
		||||
| 
						 | 
				
			
			@ -54,6 +52,7 @@ namespace MWMechanics
 | 
			
		|||
    protected:
 | 
			
		||||
        bool mIsWerewolf;
 | 
			
		||||
        AttributeValue mWerewolfAttributes[8];
 | 
			
		||||
        int mLevel;
 | 
			
		||||
 | 
			
		||||
    public:
 | 
			
		||||
        CreatureStats();
 | 
			
		||||
| 
						 | 
				
			
			@ -142,14 +141,6 @@ namespace MWMechanics
 | 
			
		|||
        float getFatigueTerm() const;
 | 
			
		||||
        ///< 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 hasDied() const;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -30,6 +30,7 @@ MWMechanics::NpcStats::NpcStats()
 | 
			
		|||
, mProfit(0)
 | 
			
		||||
, mTimeToStartDrowning(20.0)
 | 
			
		||||
, mLastDrowningHit(0)
 | 
			
		||||
, mLevelHealthBonus(0)
 | 
			
		||||
{
 | 
			
		||||
    mSkillIncreases.resize (ESM::Attribute::Length, 0);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -237,6 +238,27 @@ void MWMechanics::NpcStats::levelUp()
 | 
			
		|||
    mLevelProgress -= 10;
 | 
			
		||||
    for (int i=0; i<ESM::Attribute::Length; ++i)
 | 
			
		||||
        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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -51,6 +51,8 @@ namespace MWMechanics
 | 
			
		|||
            /// time since last hit from drowning
 | 
			
		||||
            float mLastDrowningHit;
 | 
			
		||||
 | 
			
		||||
            float mLevelHealthBonus;
 | 
			
		||||
 | 
			
		||||
        public:
 | 
			
		||||
 | 
			
		||||
            NpcStats();
 | 
			
		||||
| 
						 | 
				
			
			@ -98,6 +100,10 @@ namespace MWMechanics
 | 
			
		|||
 | 
			
		||||
            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);
 | 
			
		||||
 | 
			
		||||
            bool hasBeenUsed (const std::string& id) const;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue