From 074e241c329df2321ff8019892a2de9fbf1ec7d8 Mon Sep 17 00:00:00 2001 From: Emanuel Guevel Date: Sat, 20 Jul 2013 14:52:17 +0200 Subject: [PATCH 1/6] MWMechanics::DynamicStat: fix members initialization --- apps/openmw/mwmechanics/stat.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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) {} From 7837dcdc199e402c20b16efe6cf6aafabb5fbb06 Mon Sep 17 00:00:00 2001 From: Emanuel Guevel Date: Sat, 20 Jul 2013 14:52:17 +0200 Subject: [PATCH 2/6] Calculate NPC health on loading instead of updating it continually Only NPC with auto-calculated stats are concerned. --- apps/openmw/mwclass/npc.cpp | 4 ++++ apps/openmw/mwmechanics/actors.cpp | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 778120466f..5fb4730b57 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -109,6 +109,10 @@ namespace creatureStats.getAttribute(attribute).setBase ( std::min(creatureStats.getAttribute(attribute).getBase() + static_cast((level-1) * modifierSum+0.5), 100) ); } + + int strength = creatureStats.getAttribute(ESM::Attribute::Strength).getBase(); + int endurance = creatureStats.getAttribute(ESM::Attribute::Endurance).getBase(); + creatureStats.setHealth(static_cast (0.5 * (strength + endurance)) + creatureStats.getLevelHealthBonus()); } } 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); From 2a0644a7c34a99daed4b90a8e33282637744abf1 Mon Sep 17 00:00:00 2001 From: Emanuel Guevel Date: Sat, 20 Jul 2013 21:56:57 +0200 Subject: [PATCH 3/6] Move some levelup logic from mwgui to mwmechanics --- apps/openmw/mwgui/levelupdialog.cpp | 7 +------ apps/openmw/mwmechanics/creaturestats.cpp | 20 +++++++++++++++----- apps/openmw/mwmechanics/creaturestats.hpp | 4 ++-- 3 files changed, 18 insertions(+), 13 deletions(-) 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/creaturestats.cpp b/apps/openmw/mwmechanics/creaturestats.cpp index 19d2080211..e6e058ad9d 100644 --- a/apps/openmw/mwmechanics/creaturestats.cpp +++ b/apps/openmw/mwmechanics/creaturestats.cpp @@ -18,16 +18,26 @@ 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(); + + mLevel++; + } + const AiSequence& CreatureStats::getAiSequence() const { return mAiSequence; diff --git a/apps/openmw/mwmechanics/creaturestats.hpp b/apps/openmw/mwmechanics/creaturestats.hpp index 63de13d0d4..175f56e65b 100644 --- a/apps/openmw/mwmechanics/creaturestats.hpp +++ b/apps/openmw/mwmechanics/creaturestats.hpp @@ -95,10 +95,10 @@ 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(); + bool isDead() const; bool hasDied() const; From 2356e6218e7cb6b47d6bd9da4b4bb462dca85fdb Mon Sep 17 00:00:00 2001 From: Emanuel Guevel Date: Sat, 20 Jul 2013 21:57:45 +0200 Subject: [PATCH 4/6] Complete health increase on level up --- apps/openmw/mwmechanics/creaturestats.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/openmw/mwmechanics/creaturestats.cpp b/apps/openmw/mwmechanics/creaturestats.cpp index e6e058ad9d..743dcfc7b4 100644 --- a/apps/openmw/mwmechanics/creaturestats.cpp +++ b/apps/openmw/mwmechanics/creaturestats.cpp @@ -29,11 +29,13 @@ 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); mLevel++; } From 1c330fc8991faff93b70767df0a6097c765f1543 Mon Sep 17 00:00:00 2001 From: Emanuel Guevel Date: Sun, 21 Jul 2013 10:09:08 +0200 Subject: [PATCH 5/6] Use the correct formula for NPC health initialization --- apps/openmw/mwclass/npc.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 5fb4730b57..b6af9f0e57 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -110,9 +110,10 @@ namespace + 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)) + creatureStats.getLevelHealthBonus()); + creatureStats.setHealth(static_cast (0.5 * (strength + endurance)) + 4 * (creatureStats.getLevel() - 1)); } } From 48f0e64ec386b3cfa8a0d6275b8ead99c9ff78ea Mon Sep 17 00:00:00 2001 From: Emanuel Guevel Date: Sun, 21 Jul 2013 11:00:36 +0200 Subject: [PATCH 6/6] 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;