mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-03 21:45:33 +00:00
Merge remote-tracking branch 'wareya/master' into next
This commit is contained in:
commit
b8c0c94d5f
2 changed files with 53 additions and 7 deletions
|
@ -1,5 +1,7 @@
|
||||||
#include "waitdialog.hpp"
|
#include "waitdialog.hpp"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
|
|
||||||
#include <libs/openengine/ogre/fader.hpp>
|
#include <libs/openengine/ogre/fader.hpp>
|
||||||
|
@ -14,6 +16,7 @@
|
||||||
#include "../mwworld/ptr.hpp"
|
#include "../mwworld/ptr.hpp"
|
||||||
#include "../mwworld/class.hpp"
|
#include "../mwworld/class.hpp"
|
||||||
|
|
||||||
|
#include "../mwmechanics/creaturestats.hpp"
|
||||||
#include "../mwmechanics/npcstats.hpp"
|
#include "../mwmechanics/npcstats.hpp"
|
||||||
|
|
||||||
#include "widgets.hpp"
|
#include "widgets.hpp"
|
||||||
|
@ -132,21 +135,62 @@ namespace MWGui
|
||||||
|
|
||||||
void WaitDialog::onUntilHealedButtonClicked(MyGUI::Widget* sender)
|
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();
|
||||||
|
|
||||||
|
float healthHours = hourlyHealthDelta >= 0.0
|
||||||
|
? (stats.getHealth().getBase() - stats.getHealth().getCurrent()) / hourlyHealthDelta
|
||||||
|
: 1.0f;
|
||||||
|
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)
|
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);
|
MWBase::Environment::get().getWorld ()->getFader ()->fadeOut(0.2);
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
mProgressBar.setVisible (true);
|
mProgressBar.setVisible (true);
|
||||||
|
|
||||||
mWaiting = true;
|
mWaiting = true;
|
||||||
mCurHour = 0;
|
mCurHour = 0;
|
||||||
|
mHours = hoursToWait;
|
||||||
|
|
||||||
mRemainingTime = 0.05;
|
mRemainingTime = 0.05;
|
||||||
mProgressBar.setProgress (0, mHours);
|
mProgressBar.setProgress (0, mHours);
|
||||||
}
|
}
|
||||||
|
@ -159,7 +203,7 @@ namespace MWGui
|
||||||
void WaitDialog::onHourSliderChangedPosition(MyGUI::ScrollBar* sender, size_t position)
|
void WaitDialog::onHourSliderChangedPosition(MyGUI::ScrollBar* sender, size_t position)
|
||||||
{
|
{
|
||||||
mHourText->setCaptionWithReplacing (boost::lexical_cast<std::string>(position+1) + " #{sRestMenu2}");
|
mHourText->setCaptionWithReplacing (boost::lexical_cast<std::string>(position+1) + " #{sRestMenu2}");
|
||||||
mHours = position+1;
|
mManualHours = position+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaitDialog::setCanRest (bool canRest)
|
void WaitDialog::setCanRest (bool canRest)
|
||||||
|
@ -181,9 +225,9 @@ namespace MWGui
|
||||||
|
|
||||||
mRemainingTime -= dt;
|
mRemainingTime -= dt;
|
||||||
|
|
||||||
if (mRemainingTime < 0)
|
while (mRemainingTime < 0)
|
||||||
{
|
{
|
||||||
mRemainingTime = 0.05;
|
mRemainingTime += 0.05;
|
||||||
++mCurHour;
|
++mCurHour;
|
||||||
mProgressBar.setProgress (mCurHour, mHours);
|
mProgressBar.setProgress (mCurHour, mHours);
|
||||||
|
|
||||||
|
@ -197,6 +241,7 @@ namespace MWGui
|
||||||
|
|
||||||
if (mCurHour > mHours)
|
if (mCurHour > mHours)
|
||||||
stopWaiting();
|
stopWaiting();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaitDialog::stopWaiting ()
|
void WaitDialog::stopWaiting ()
|
||||||
|
|
|
@ -47,6 +47,7 @@ namespace MWGui
|
||||||
bool mSleeping;
|
bool mSleeping;
|
||||||
int mCurHour;
|
int mCurHour;
|
||||||
int mHours;
|
int mHours;
|
||||||
|
int mManualHours; // stores the hours to rest selected via slider
|
||||||
float mRemainingTime;
|
float mRemainingTime;
|
||||||
|
|
||||||
WaitDialogProgressBar mProgressBar;
|
WaitDialogProgressBar mProgressBar;
|
||||||
|
@ -58,7 +59,7 @@ namespace MWGui
|
||||||
|
|
||||||
void setCanRest(bool canRest);
|
void setCanRest(bool canRest);
|
||||||
|
|
||||||
void startWaiting();
|
void startWaiting(int hoursToWait);
|
||||||
void stopWaiting();
|
void stopWaiting();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue