mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 22:23:51 +00:00
Implement "Rest Until Healed"
Fixes: https://bugs.openmw.org/issues/563
This commit is contained in:
parent
04001717e7
commit
f0220fb06b
2 changed files with 58 additions and 7 deletions
|
@ -1,5 +1,8 @@
|
|||
#include "waitdialog.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
#include <libs/openengine/ogre/fader.hpp>
|
||||
|
@ -14,6 +17,7 @@
|
|||
#include "../mwworld/ptr.hpp"
|
||||
#include "../mwworld/class.hpp"
|
||||
|
||||
#include "../mwmechanics/creaturestats.hpp"
|
||||
#include "../mwmechanics/npcstats.hpp"
|
||||
|
||||
#include "widgets.hpp"
|
||||
|
@ -132,21 +136,66 @@ namespace MWGui
|
|||
|
||||
void WaitDialog::onUntilHealedButtonClicked(MyGUI::Widget* sender)
|
||||
{
|
||||
startWaiting();
|
||||
// we need to sleep for a specific time, and since that isn't calculated yet, we'll do it here
|
||||
// I'm making the assumption here that the # of hours rested is calculated when rest is started
|
||||
// TODO: the rougher logic here (calculating the hourly deltas) should really go into helper funcs elsewhere
|
||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
||||
MWMechanics::CreatureStats stats = MWWorld::Class::get(player).getCreatureStats(player);
|
||||
const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore();
|
||||
|
||||
float hourlyHealthDelta = stats.getAttribute(ESM::Attribute::Endurance).getModified() * 0.1;
|
||||
|
||||
bool stunted = (stats.getMagicEffects().get(MWMechanics::EffectKey(136)).mMagnitude > 0);
|
||||
float fRestMagicMult = store.get<ESM::GameSetting>().find("fRestMagicMult")->getFloat();
|
||||
float hourlyMagickaDelta = fRestMagicMult * stats.getAttribute(ESM::Attribute::Intelligence).getModified();
|
||||
|
||||
// this massive duplication is why it has to be put into helper functions instead
|
||||
float fFatigueReturnBase = store.get<ESM::GameSetting>().find("fFatigueReturnBase")->getFloat();
|
||||
float fFatigueReturnMult = store.get<ESM::GameSetting>().find("fFatigueReturnMult")->getFloat();
|
||||
float fEndFatigueMult = store.get<ESM::GameSetting>().find("fEndFatigueMult")->getFloat();
|
||||
float capacity = MWWorld::Class::get(player).getCapacity(player);
|
||||
float encumbrance = MWWorld::Class::get(player).getEncumbrance(player);
|
||||
float normalizedEncumbrance = (capacity == 0 ? 1 : encumbrance/capacity);
|
||||
if (normalizedEncumbrance > 1)
|
||||
normalizedEncumbrance = 1;
|
||||
float hourlyFatigueDelta = fFatigueReturnBase + fFatigueReturnMult * (1 - normalizedEncumbrance);
|
||||
hourlyFatigueDelta *= 3600 * fEndFatigueMult * stats.getAttribute(ESM::Attribute::Endurance).getModified();
|
||||
|
||||
std::cout << "Calced health per hour: " << hourlyHealthDelta << std::endl;
|
||||
|
||||
float healthHours = hourlyHealthDelta >= 0.0
|
||||
? (stats.getHealth().getBase() - stats.getHealth().getCurrent()) / hourlyHealthDelta
|
||||
: 1.0f;
|
||||
std::cout << "Calced health hours: " << healthHours << std::endl;
|
||||
std::cout << "getBase returns " << stats.getHealth().getBase() << ", getModified() returns " << stats.getHealth().getModified() << std::endl;
|
||||
float magickaHours = stunted ? 0.0 :
|
||||
hourlyMagickaDelta >= 0.0
|
||||
? (stats.getMagicka().getBase() - stats.getMagicka().getCurrent()) / hourlyMagickaDelta
|
||||
: 1.0f;
|
||||
float fatigueHours = hourlyFatigueDelta >= 0.0
|
||||
? (stats.getFatigue().getBase() - stats.getFatigue().getCurrent()) / hourlyFatigueDelta
|
||||
: 1.0f;
|
||||
|
||||
int autoHours = int(std::ceil( std::max(std::max(healthHours, magickaHours), std::max(fatigueHours, 1.0f)) )); // this should use a variadic max if possible
|
||||
|
||||
startWaiting(autoHours);
|
||||
}
|
||||
|
||||
void WaitDialog::onWaitButtonClicked(MyGUI::Widget* sender)
|
||||
{
|
||||
startWaiting();
|
||||
startWaiting(mManualHours);
|
||||
}
|
||||
|
||||
void WaitDialog::startWaiting ()
|
||||
void WaitDialog::startWaiting(int hoursToWait)
|
||||
{
|
||||
MWBase::Environment::get().getWorld ()->getFader ()->fadeOut(0.2);
|
||||
setVisible(false);
|
||||
mProgressBar.setVisible (true);
|
||||
|
||||
mWaiting = true;
|
||||
mCurHour = 0;
|
||||
mHours = hoursToWait;
|
||||
|
||||
mRemainingTime = 0.05;
|
||||
mProgressBar.setProgress (0, mHours);
|
||||
}
|
||||
|
@ -159,7 +208,7 @@ namespace MWGui
|
|||
void WaitDialog::onHourSliderChangedPosition(MyGUI::ScrollBar* sender, size_t position)
|
||||
{
|
||||
mHourText->setCaptionWithReplacing (boost::lexical_cast<std::string>(position+1) + " #{sRestMenu2}");
|
||||
mHours = position+1;
|
||||
mManualHours = position+1;
|
||||
}
|
||||
|
||||
void WaitDialog::setCanRest (bool canRest)
|
||||
|
@ -181,9 +230,9 @@ namespace MWGui
|
|||
|
||||
mRemainingTime -= dt;
|
||||
|
||||
if (mRemainingTime < 0)
|
||||
while (mRemainingTime < 0)
|
||||
{
|
||||
mRemainingTime = 0.05;
|
||||
mRemainingTime += 0.05;
|
||||
++mCurHour;
|
||||
mProgressBar.setProgress (mCurHour, mHours);
|
||||
|
||||
|
@ -197,6 +246,7 @@ namespace MWGui
|
|||
|
||||
if (mCurHour > mHours)
|
||||
stopWaiting();
|
||||
|
||||
}
|
||||
|
||||
void WaitDialog::stopWaiting ()
|
||||
|
|
|
@ -47,6 +47,7 @@ namespace MWGui
|
|||
bool mSleeping;
|
||||
int mCurHour;
|
||||
int mHours;
|
||||
int mManualHours; // stores the hours to rest selected via slider
|
||||
float mRemainingTime;
|
||||
|
||||
WaitDialogProgressBar mProgressBar;
|
||||
|
@ -58,7 +59,7 @@ namespace MWGui
|
|||
|
||||
void setCanRest(bool canRest);
|
||||
|
||||
void startWaiting();
|
||||
void startWaiting(int hoursToWait);
|
||||
void stopWaiting();
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue