From 48f0e64ec386b3cfa8a0d6275b8ead99c9ff78ea Mon Sep 17 00:00:00 2001 From: Emanuel Guevel Date: Sun, 21 Jul 2013 11:00:36 +0200 Subject: [PATCH] Fix health calculation at character creation --- apps/openmw/mwgui/charactercreation.cpp | 21 +++++++++++++++++++++ apps/openmw/mwmechanics/creaturestats.cpp | 11 +++++++++-- apps/openmw/mwmechanics/creaturestats.hpp | 4 ++++ 3 files changed, 34 insertions(+), 2 deletions(-) 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/mwmechanics/creaturestats.cpp b/apps/openmw/mwmechanics/creaturestats.cpp index 743dcfc7b4..569ccd5927 100644 --- a/apps/openmw/mwmechanics/creaturestats.cpp +++ b/apps/openmw/mwmechanics/creaturestats.cpp @@ -29,17 +29,24 @@ namespace MWMechanics MWBase::Environment::get().getWorld()->getStore().get(); const int endurance = getAttribute(ESM::Attribute::Endurance).getBase(); - const int strength = getAttribute(ESM::Attribute::Strength).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(); - setHealth(static_cast (0.5 * (strength + endurance)) + mLevelHealthBonus); + 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 175f56e65b..da8b5842a6 100644 --- a/apps/openmw/mwmechanics/creaturestats.hpp +++ b/apps/openmw/mwmechanics/creaturestats.hpp @@ -99,6 +99,10 @@ namespace MWMechanics 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;