diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 778120466f..b6af9f0e57 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -109,6 +109,11 @@ namespace creatureStats.getAttribute(attribute).setBase ( std::min(creatureStats.getAttribute(attribute).getBase() + static_cast((level-1) * modifierSum+0.5), 100) ); } + + // initial health + int strength = creatureStats.getAttribute(ESM::Attribute::Strength).getBase(); + int endurance = creatureStats.getAttribute(ESM::Attribute::Endurance).getBase(); + creatureStats.setHealth(static_cast (0.5 * (strength + endurance)) + 4 * (creatureStats.getLevel() - 1)); } } diff --git a/apps/openmw/mwgui/charactercreation.cpp b/apps/openmw/mwgui/charactercreation.cpp index 6a6c596be6..d1e103dd35 100644 --- a/apps/openmw/mwgui/charactercreation.cpp +++ b/apps/openmw/mwgui/charactercreation.cpp @@ -10,7 +10,10 @@ #include "../mwbase/environment.hpp" #include "../mwbase/soundmanager.hpp" #include "../mwbase/mechanicsmanager.hpp" +#include "../mwmechanics/creaturestats.hpp" +#include "../mwworld/class.hpp" #include "../mwworld/fallback.hpp" +#include "../mwworld/player.hpp" namespace { @@ -41,6 +44,14 @@ namespace // Note: Order is taken from http://www.uesp.net/wiki/Morrowind:Class_Quiz unsigned int points[3]; }; + + void updatePlayerHealth() + { + MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); + MWMechanics::CreatureStats& creatureStats = MWWorld::Class::get(player).getCreatureStats(player); + + creatureStats.updateHealth(); + } } namespace MWGui @@ -334,6 +345,8 @@ namespace MWGui mCreationStage = CSE_ClassChosen; MWBase::Environment::get().getWindowManager()->popGuiMode(); } + + updatePlayerHealth(); } void CharacterCreation::onPickClassDialogBack() @@ -461,6 +474,8 @@ namespace MWGui mCreationStage = CSE_RaceChosen; MWBase::Environment::get().getWindowManager()->popGuiMode(); } + + updatePlayerHealth(); } void CharacterCreation::onBirthSignDialogDone(WindowBase* parWindow) @@ -484,6 +499,8 @@ namespace MWGui mCreationStage = CSE_BirthSignChosen; MWBase::Environment::get().getWindowManager()->popGuiMode(); } + + updatePlayerHealth(); } void CharacterCreation::onBirthSignDialogBack() @@ -547,6 +564,8 @@ namespace MWGui mCreationStage = CSE_ClassChosen; MWBase::Environment::get().getWindowManager()->popGuiMode(); } + + updatePlayerHealth(); } void CharacterCreation::onCreateClassDialogBack() @@ -715,6 +734,8 @@ namespace MWGui mCreationStage = CSE_ClassChosen; MWBase::Environment::get().getWindowManager()->popGuiMode(); } + + updatePlayerHealth(); } CharacterCreation::~CharacterCreation() diff --git a/apps/openmw/mwgui/levelupdialog.cpp b/apps/openmw/mwgui/levelupdialog.cpp index 5857db4d2e..7c0191d495 100644 --- a/apps/openmw/mwgui/levelupdialog.cpp +++ b/apps/openmw/mwgui/levelupdialog.cpp @@ -173,12 +173,7 @@ namespace MWGui attribute.setBase(100); } - // "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" - creatureStats.increaseLevelHealthBonus (creatureStats.getAttribute(ESM::Attribute::Endurance).getBase() * 0.1f); - - creatureStats.setLevel (creatureStats.getLevel()+1); + creatureStats.levelUp(); pcStats.levelUp (); MWBase::Environment::get().getWindowManager()->removeGuiMode (GM_Levelup); diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index f55b00094d..baa264aa4e 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -76,10 +76,6 @@ namespace MWMechanics double magickaFactor = creatureStats.getMagicEffects().get (EffectKey (ESM::MagicEffect::FortifyMaximumMagicka)).mMagnitude * 0.1 + 0.5; - DynamicStat health = creatureStats.getHealth(); - health.setBase (static_cast (0.5 * (strength + endurance)) + creatureStats.getLevelHealthBonus ()); - creatureStats.setHealth (health); - DynamicStat magicka = creatureStats.getMagicka(); magicka.setBase (static_cast (intelligence + magickaFactor * intelligence)); creatureStats.setMagicka (magicka); diff --git a/apps/openmw/mwmechanics/creaturestats.cpp b/apps/openmw/mwmechanics/creaturestats.cpp index 19d2080211..569ccd5927 100644 --- a/apps/openmw/mwmechanics/creaturestats.cpp +++ b/apps/openmw/mwmechanics/creaturestats.cpp @@ -18,16 +18,35 @@ namespace MWMechanics mAiSettings[i] = 0; } - void CreatureStats::increaseLevelHealthBonus (float value) - { - mLevelHealthBonus += value; - } - float CreatureStats::getLevelHealthBonus () const { return mLevelHealthBonus; } + void CreatureStats::levelUp() + { + const MWWorld::Store &gmst = + MWBase::Environment::get().getWorld()->getStore().get(); + + 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 (0.5 * (strength + endurance)) + mLevelHealthBonus); + } + const AiSequence& CreatureStats::getAiSequence() const { return mAiSequence; diff --git a/apps/openmw/mwmechanics/creaturestats.hpp b/apps/openmw/mwmechanics/creaturestats.hpp index 63de13d0d4..da8b5842a6 100644 --- a/apps/openmw/mwmechanics/creaturestats.hpp +++ b/apps/openmw/mwmechanics/creaturestats.hpp @@ -95,10 +95,14 @@ namespace MWMechanics float getFatigueTerm() const; ///< Return effective fatigue - // small hack to allow the fact that Health permanently increases by 10% of endurance on each level up - void increaseLevelHealthBonus(float value); 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; diff --git a/apps/openmw/mwmechanics/stat.hpp b/apps/openmw/mwmechanics/stat.hpp index e9b7f43850..606671389a 100644 --- a/apps/openmw/mwmechanics/stat.hpp +++ b/apps/openmw/mwmechanics/stat.hpp @@ -98,8 +98,8 @@ namespace MWMechanics public: typedef T Type; - DynamicStat() : mCurrent (0) {} - DynamicStat(T current) : mCurrent (current) {} + DynamicStat() : mStatic (0), mCurrent (0) {} + DynamicStat(T base) : mStatic (base), mCurrent (base) {} DynamicStat(T base, T modified, T current) : mStatic(base, modified), mCurrent (current) {} DynamicStat(const Stat &stat, T current) : mStatic(stat), mCurrent (current) {}