diff --git a/apps/openmw/mwbase/mechanicsmanager.hpp b/apps/openmw/mwbase/mechanicsmanager.hpp index c5f1847af..39d7e6e1a 100644 --- a/apps/openmw/mwbase/mechanicsmanager.hpp +++ b/apps/openmw/mwbase/mechanicsmanager.hpp @@ -71,6 +71,9 @@ namespace MWBase virtual void setPlayerClass (const ESM::Class& class_) = 0; ///< Set player class to custom class. + + virtual void restoreDynamicStats() = 0; + ///< If the player is sleeping, this should be called every hour. }; } diff --git a/apps/openmw/mwgui/waitdialog.cpp b/apps/openmw/mwgui/waitdialog.cpp index cc9019f2b..3210f1db9 100644 --- a/apps/openmw/mwgui/waitdialog.cpp +++ b/apps/openmw/mwgui/waitdialog.cpp @@ -7,6 +7,7 @@ #include "../mwbase/windowmanager.hpp" #include "../mwbase/world.hpp" #include "../mwbase/environment.hpp" +#include "../mwbase/mechanicsmanager.hpp" #include "../mwworld/timestamp.hpp" #include "../mwworld/player.hpp" @@ -186,7 +187,11 @@ namespace MWGui mProgressBar.setProgress (mCurHour, mHours); if (mCurHour <= mHours) + { MWBase::Environment::get().getWorld ()->advanceTime (1); + if (mSleeping) + MWBase::Environment::get().getMechanicsManager ()->restoreDynamicStats (); + } } if (mCurHour > mHours) diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index b4cc40fec..ab52693f2 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -7,9 +7,15 @@ #include +#include + #include "../mwworld/class.hpp" #include "../mwworld/inventorystore.hpp" +#include "../mwbase/world.hpp" +#include "../mwbase/environment.hpp" +#include "../mwbase/windowmanager.hpp" + #include "creaturestats.hpp" namespace MWMechanics @@ -20,7 +26,7 @@ namespace MWMechanics adjustMagicEffects (ptr); calculateCreatureStatModifiers (ptr); calculateDynamicStats (ptr); - + // AI CreatureStats& creatureStats = MWWorld::Class::get (ptr).getCreatureStats (ptr); creatureStats.getAiSequence().execute (ptr); @@ -76,6 +82,46 @@ namespace MWMechanics creatureStats.getFatigue().setBase(strength+willpower+agility+endurance); } + void Actors::calculateRestoration (const MWWorld::Ptr& ptr, float duration) + { + CreatureStats& stats = MWWorld::Class::get (ptr).getCreatureStats (ptr); + + if (duration == 3600) + { + // stunted magicka + bool stunted = stats.getMagicEffects ().get(MWMechanics::EffectKey(136)).mMagnitude > 0; + + int endurance = stats.getAttribute (ESM::Attribute::Endurance).getModified (); + stats.getHealth().setCurrent(stats.getHealth ().getCurrent () + + 0.1 * endurance); + + const ESMS::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); + + float fFatigueReturnBase = store.gameSettings.find("fFatigueReturnBase")->getFloat (); + float fFatigueReturnMult = store.gameSettings.find("fFatigueReturnMult")->getFloat (); + float fEndFatigueMult = store.gameSettings.find("fEndFatigueMult")->getFloat (); + + float capacity = MWWorld::Class::get(ptr).getCapacity(ptr); + float encumbrance = MWWorld::Class::get(ptr).getEncumbrance(ptr); + float normalizedEncumbrance = (capacity == 0 ? 1 : encumbrance/capacity); + + float x = fFatigueReturnBase + fFatigueReturnMult * (1 - normalizedEncumbrance); + x *= fEndFatigueMult * endurance; + stats.getFatigue ().setCurrent (stats.getFatigue ().getCurrent () + 3600 * x); + + if (!stunted) + { + float fRestMagicMult = store.gameSettings.find("fRestMagicMult")->getFloat (); + stats.getMagicka().setCurrent (stats.getMagicka ().getCurrent () + + fRestMagicMult * stats.getAttribute(ESM::Attribute::Intelligence).getModified ()); + } + } + + + + } + + void Actors::calculateCreatureStatModifiers (const MWWorld::Ptr& ptr) { CreatureStats& creatureStats = MWWorld::Class::get (ptr).getCreatureStats (ptr); @@ -159,4 +205,12 @@ namespace MWMechanics movement.push_back (std::make_pair (iter->getRefData().getHandle(), vector)); } } + + void Actors::restoreDynamicStats() + { + for (std::set::iterator iter (mActors.begin()); iter!=mActors.end(); ++iter) + { + calculateRestoration (*iter, 3600); + } + } } diff --git a/apps/openmw/mwmechanics/actors.hpp b/apps/openmw/mwmechanics/actors.hpp index d5dcef487..7e5a0ac86 100644 --- a/apps/openmw/mwmechanics/actors.hpp +++ b/apps/openmw/mwmechanics/actors.hpp @@ -31,6 +31,9 @@ namespace MWMechanics void calculateCreatureStatModifiers (const MWWorld::Ptr& ptr); + void calculateRestoration (const MWWorld::Ptr& ptr, float duration); + + public: Actors(); @@ -54,6 +57,8 @@ namespace MWMechanics ///< This function is normally called automatically during the update process, but it can /// also be called explicitly at any time to force an update. + void restoreDynamicStats(); + ///< If the player is sleeping, this should be called every hour. }; } diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp index 2ac146c2f..de016811b 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp @@ -282,6 +282,11 @@ namespace MWMechanics mActors.update (movement, duration, paused); } + void MechanicsManager::restoreDynamicStats() + { + mActors.restoreDynamicStats (); + } + void MechanicsManager::setPlayerName (const std::string& name) { MWBase::Environment::get().getWorld()->getPlayer().setName (name); diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp index d5fd3b6f2..3a41e8fa6 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp @@ -73,6 +73,9 @@ namespace MWMechanics virtual void setPlayerClass (const ESM::Class& class_); ///< Set player class to custom class. + + virtual void restoreDynamicStats(); + ///< If the player is sleeping, this should be called every hour. }; } diff --git a/components/esm/loadgmst.cpp b/components/esm/loadgmst.cpp index 4bd464da6..491592bb9 100644 --- a/components/esm/loadgmst.cpp +++ b/components/esm/loadgmst.cpp @@ -186,7 +186,7 @@ int GameSetting::getInt() const } } -int GameSetting::getFloat() const +float GameSetting::getFloat() const { switch (type) { diff --git a/components/esm/loadgmst.hpp b/components/esm/loadgmst.hpp index f63028731..df6003462 100644 --- a/components/esm/loadgmst.hpp +++ b/components/esm/loadgmst.hpp @@ -87,7 +87,7 @@ struct GameSetting int getInt() const; ///< Throws an exception if GMST is not of type int or float. - int getFloat() const; + float getFloat() const; ///< Throws an exception if GMST is not of type int or float. std::string getString() const;