mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-25 15:35:23 +00:00
Merge pull request #2145 from akortunov/rest
Update jail state once instead of for every single hour
This commit is contained in:
commit
886c77bced
@ -35,6 +35,7 @@
|
||||
Bug #4813: Creatures with known file but no "Sound Gen Creature" assigned use default sounds
|
||||
Bug #4815: "Finished" journal entry with lower index doesn't close journal, SetJournalIndex closes journal
|
||||
Bug #4820: Spell absorption is broken
|
||||
Bug #4823: Jail progress bar works incorrectly
|
||||
Bug #4827: NiUVController is handled incorrectly
|
||||
Bug #4828: Potion looping effects VFX are not shown for NPCs
|
||||
Bug #4837: CTD when a mesh with NiLODNode root node with particles is loaded
|
||||
|
@ -90,9 +90,9 @@ namespace MWBase
|
||||
virtual void setPlayerClass (const ESM::Class& class_) = 0;
|
||||
///< Set player class to custom class.
|
||||
|
||||
virtual void restoreDynamicStats(MWWorld::Ptr actor, bool sleep) = 0;
|
||||
virtual void restoreDynamicStats(MWWorld::Ptr actor, double hours, bool sleep) = 0;
|
||||
|
||||
virtual void rest(bool sleep) = 0;
|
||||
virtual void rest(double hours, bool sleep) = 0;
|
||||
///< If the player is sleeping or waiting, this should be called every hour.
|
||||
/// @param sleep is the player sleeping or waiting?
|
||||
|
||||
|
@ -588,7 +588,7 @@ namespace MWBase
|
||||
|
||||
virtual bool isPlayerInJail() const = 0;
|
||||
|
||||
virtual void rest() = 0;
|
||||
virtual void rest(double hours) = 0;
|
||||
|
||||
virtual void setPlayerTraveling(bool traveling) = 0;
|
||||
virtual bool isPlayerTraveling() const = 0;
|
||||
|
@ -78,8 +78,7 @@ namespace MWGui
|
||||
|
||||
MWWorld::Ptr player = MWMechanics::getPlayer();
|
||||
|
||||
for (int i=0; i<mDays*24; ++i)
|
||||
MWBase::Environment::get().getMechanicsManager()->rest(true);
|
||||
MWBase::Environment::get().getMechanicsManager()->rest(mDays * 24, true);
|
||||
MWBase::Environment::get().getWorld()->advanceTime(mDays * 24);
|
||||
|
||||
std::set<int> skills;
|
||||
|
@ -169,8 +169,7 @@ namespace MWGui
|
||||
npcStats.setGoldPool(npcStats.getGoldPool() + price);
|
||||
|
||||
// advance time
|
||||
MWBase::Environment::get().getMechanicsManager()->rest(false);
|
||||
MWBase::Environment::get().getMechanicsManager()->rest(false);
|
||||
MWBase::Environment::get().getMechanicsManager()->rest(2, false);
|
||||
MWBase::Environment::get().getWorld ()->advanceTime (2);
|
||||
|
||||
setVisible(false);
|
||||
|
@ -174,10 +174,7 @@ namespace MWGui
|
||||
ESM::Position playerPos = player.getRefData().getPosition();
|
||||
float d = (osg::Vec3f(pos.pos[0], pos.pos[1], 0) - osg::Vec3f(playerPos.pos[0], playerPos.pos[1], 0)).length();
|
||||
int hours = static_cast<int>(d /MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fTravelTimeMult")->mValue.getFloat());
|
||||
for(int i = 0;i < hours;i++)
|
||||
{
|
||||
MWBase::Environment::get().getMechanicsManager ()->rest (true);
|
||||
}
|
||||
MWBase::Environment::get().getMechanicsManager ()->rest (hours, true);
|
||||
MWBase::Environment::get().getWorld()->advanceTime(hours);
|
||||
}
|
||||
|
||||
|
@ -232,7 +232,7 @@ namespace MWGui
|
||||
void WaitDialog::onWaitingProgressChanged(int cur, int total)
|
||||
{
|
||||
mProgressBar.setProgress(cur, total);
|
||||
MWBase::Environment::get().getMechanicsManager()->rest(mSleeping);
|
||||
MWBase::Environment::get().getMechanicsManager()->rest(1, mSleeping);
|
||||
MWBase::Environment::get().getWorld()->advanceTime(1);
|
||||
|
||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
|
||||
|
@ -130,23 +130,45 @@ void getRestorationPerHourOfSleep (const MWWorld::Ptr& ptr, float& health, float
|
||||
MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats (ptr);
|
||||
const MWWorld::Store<ESM::GameSetting>& settings = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>();
|
||||
|
||||
bool stunted = stats.getMagicEffects ().get(ESM::MagicEffect::StuntedMagicka).getMagnitude() > 0;
|
||||
int endurance = stats.getAttribute (ESM::Attribute::Endurance).getModified ();
|
||||
|
||||
health = 0.1f * endurance;
|
||||
|
||||
magicka = 0;
|
||||
if (!stunted)
|
||||
{
|
||||
float fRestMagicMult = settings.find("fRestMagicMult")->mValue.getFloat ();
|
||||
magicka = fRestMagicMult * stats.getAttribute(ESM::Attribute::Intelligence).getModified();
|
||||
}
|
||||
float fRestMagicMult = settings.find("fRestMagicMult")->mValue.getFloat ();
|
||||
magicka = fRestMagicMult * stats.getAttribute(ESM::Attribute::Intelligence).getModified();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace MWMechanics
|
||||
{
|
||||
class GetStuntedMagickaDuration : public MWMechanics::EffectSourceVisitor
|
||||
{
|
||||
public:
|
||||
float mRemainingTime;
|
||||
|
||||
GetStuntedMagickaDuration(const MWWorld::Ptr& actor)
|
||||
: mRemainingTime(0.f){}
|
||||
|
||||
virtual void visit (MWMechanics::EffectKey key,
|
||||
const std::string& sourceName, const std::string& sourceId, int casterActorId,
|
||||
float magnitude, float remainingTime = -1, float totalTime = -1)
|
||||
{
|
||||
if (mRemainingTime == -1) return;
|
||||
|
||||
if (key.mId == ESM::MagicEffect::StuntedMagicka)
|
||||
{
|
||||
if (totalTime == -1)
|
||||
{
|
||||
mRemainingTime = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (remainingTime > mRemainingTime)
|
||||
mRemainingTime = remainingTime;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class SoulTrap : public MWMechanics::EffectSourceVisitor
|
||||
{
|
||||
MWWorld::Ptr mCreature;
|
||||
@ -568,7 +590,7 @@ namespace MWMechanics
|
||||
creatureStats.setMagicka(magicka);
|
||||
}
|
||||
|
||||
void Actors::restoreDynamicStats (const MWWorld::Ptr& ptr, bool sleep)
|
||||
void Actors::restoreDynamicStats (const MWWorld::Ptr& ptr, double hours, bool sleep)
|
||||
{
|
||||
MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats (ptr);
|
||||
if (stats.isDead())
|
||||
@ -582,12 +604,36 @@ namespace MWMechanics
|
||||
getRestorationPerHourOfSleep(ptr, health, magicka);
|
||||
|
||||
DynamicStat<float> stat = stats.getHealth();
|
||||
stat.setCurrent(stat.getCurrent() + health);
|
||||
stat.setCurrent(stat.getCurrent() + health * hours);
|
||||
stats.setHealth(stat);
|
||||
|
||||
stat = stats.getMagicka();
|
||||
stat.setCurrent(stat.getCurrent() + magicka);
|
||||
stats.setMagicka(stat);
|
||||
double restoreHours = hours;
|
||||
bool stunted = stats.getMagicEffects ().get(ESM::MagicEffect::StuntedMagicka).getMagnitude() > 0;
|
||||
if (stunted)
|
||||
{
|
||||
// Stunted Magicka effect should be taken into account.
|
||||
GetStuntedMagickaDuration visitor(ptr);
|
||||
stats.getActiveSpells().visitEffectSources(visitor);
|
||||
stats.getSpells().visitEffectSources(visitor);
|
||||
if (ptr.getClass().hasInventoryStore(ptr))
|
||||
ptr.getClass().getInventoryStore(ptr).visitEffectSources(visitor);
|
||||
|
||||
// Take a maximum remaining duration of Stunted Magicka effects (-1 is a constant one) in game hours.
|
||||
if (visitor.mRemainingTime > 0)
|
||||
{
|
||||
double timeScale = MWBase::Environment::get().getWorld()->getTimeScaleFactor();
|
||||
restoreHours = std::max(0.0, hours - visitor.mRemainingTime * timeScale / 3600.f);
|
||||
}
|
||||
else if (visitor.mRemainingTime == -1)
|
||||
restoreHours = 0;
|
||||
}
|
||||
|
||||
if (restoreHours > 0)
|
||||
{
|
||||
stat = stats.getMagicka();
|
||||
stat.setCurrent(stat.getCurrent() + magicka * restoreHours);
|
||||
stats.setMagicka(stat);
|
||||
}
|
||||
}
|
||||
|
||||
// Current fatigue can be above base value due to a fortify effect.
|
||||
@ -610,7 +656,7 @@ namespace MWMechanics
|
||||
float x = fFatigueReturnBase + fFatigueReturnMult * (1 - normalizedEncumbrance);
|
||||
x *= fEndFatigueMult * endurance;
|
||||
|
||||
fatigue.setCurrent (fatigue.getCurrent() + 3600 * x);
|
||||
fatigue.setCurrent (fatigue.getCurrent() + 3600 * x * hours);
|
||||
stats.setFatigue (fatigue);
|
||||
}
|
||||
|
||||
@ -1685,9 +1731,9 @@ namespace MWMechanics
|
||||
}
|
||||
}
|
||||
|
||||
void Actors::rest(bool sleep)
|
||||
void Actors::rest(double hours, bool sleep)
|
||||
{
|
||||
float duration = 3600.f / MWBase::Environment::get().getWorld()->getTimeScaleFactor();
|
||||
float duration = hours * 3600.f / MWBase::Environment::get().getWorld()->getTimeScaleFactor();
|
||||
const MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
|
||||
const osg::Vec3f playerPos = player.getRefData().getPosition().asVec3();
|
||||
|
||||
@ -1697,7 +1743,7 @@ namespace MWMechanics
|
||||
continue;
|
||||
|
||||
if (!sleep || iter->first == player)
|
||||
restoreDynamicStats(iter->first, sleep);
|
||||
restoreDynamicStats(iter->first, hours, sleep);
|
||||
|
||||
if ((!iter->first.getRefData().getBaseNode()) ||
|
||||
(playerPos - iter->first.getRefData().getPosition().asVec3()).length2() > mActorsProcessingRange*mActorsProcessingRange)
|
||||
@ -1809,11 +1855,12 @@ namespace MWMechanics
|
||||
getRestorationPerHourOfSleep(ptr, healthPerHour, magickaPerHour);
|
||||
|
||||
CreatureStats& stats = ptr.getClass().getCreatureStats(ptr);
|
||||
bool stunted = stats.getMagicEffects ().get(ESM::MagicEffect::StuntedMagicka).getMagnitude() > 0;
|
||||
|
||||
float healthHours = healthPerHour > 0
|
||||
? (stats.getHealth().getModified() - stats.getHealth().getCurrent()) / healthPerHour
|
||||
: 1.0f;
|
||||
float magickaHours = magickaPerHour > 0
|
||||
float magickaHours = magickaPerHour > 0 && !stunted
|
||||
? (stats.getMagicka().getModified() - stats.getMagicka().getCurrent()) / magickaPerHour
|
||||
: 1.0f;
|
||||
|
||||
|
@ -121,13 +121,13 @@ namespace MWMechanics
|
||||
void updateHeadTracking(const MWWorld::Ptr& actor, const MWWorld::Ptr& targetActor,
|
||||
MWWorld::Ptr& headTrackTarget, float& sqrHeadTrackDistance);
|
||||
|
||||
void rest(bool sleep);
|
||||
///< Update actors while the player is waiting or sleeping. This should be called every hour.
|
||||
void rest(double hours, bool sleep);
|
||||
///< Update actors while the player is waiting or sleeping.
|
||||
|
||||
void updateSneaking(CharacterController* ctrl, float duration);
|
||||
///< Update the sneaking indicator state according to the given player character controller.
|
||||
|
||||
void restoreDynamicStats(const MWWorld::Ptr& actor, bool sleep);
|
||||
void restoreDynamicStats(const MWWorld::Ptr& actor, double hours, bool sleep);
|
||||
|
||||
int getHoursToRest(const MWWorld::Ptr& ptr) const;
|
||||
///< Calculate how many hours the given actor needs to rest in order to be fully healed
|
||||
|
@ -480,17 +480,17 @@ namespace MWMechanics
|
||||
return mActors.isSneaking(ptr);
|
||||
}
|
||||
|
||||
void MechanicsManager::rest(bool sleep)
|
||||
void MechanicsManager::rest(double hours, bool sleep)
|
||||
{
|
||||
if (sleep)
|
||||
MWBase::Environment::get().getWorld()->rest();
|
||||
MWBase::Environment::get().getWorld()->rest(hours);
|
||||
|
||||
mActors.rest(sleep);
|
||||
mActors.rest(hours, sleep);
|
||||
}
|
||||
|
||||
void MechanicsManager::restoreDynamicStats(MWWorld::Ptr actor, bool sleep)
|
||||
void MechanicsManager::restoreDynamicStats(MWWorld::Ptr actor, double hours, bool sleep)
|
||||
{
|
||||
mActors.restoreDynamicStats(actor, sleep);
|
||||
mActors.restoreDynamicStats(actor, hours, sleep);
|
||||
}
|
||||
|
||||
int MechanicsManager::getHoursToRest() const
|
||||
|
@ -95,9 +95,9 @@ namespace MWMechanics
|
||||
virtual void setPlayerClass (const ESM::Class& class_) override;
|
||||
///< Set player class to custom class.
|
||||
|
||||
virtual void restoreDynamicStats(MWWorld::Ptr actor, bool sleep) override;
|
||||
virtual void restoreDynamicStats(MWWorld::Ptr actor, double hours, bool sleep) override;
|
||||
|
||||
virtual void rest(bool sleep) override;
|
||||
virtual void rest(double hours, bool sleep) override;
|
||||
///< If the player is sleeping or waiting, this should be called every hour.
|
||||
/// @param sleep is the player sleeping or waiting?
|
||||
|
||||
|
@ -150,16 +150,16 @@ MWWorld::CellStore *MWWorld::Cells::getInterior (const std::string& name)
|
||||
return &result->second;
|
||||
}
|
||||
|
||||
void MWWorld::Cells::rest ()
|
||||
void MWWorld::Cells::rest (double hours)
|
||||
{
|
||||
for (auto &interior : mInteriors)
|
||||
{
|
||||
interior.second.rest();
|
||||
interior.second.rest(hours);
|
||||
}
|
||||
|
||||
for (auto &exterior : mExteriors)
|
||||
{
|
||||
exterior.second.rest();
|
||||
exterior.second.rest(hours);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ namespace MWWorld
|
||||
|
||||
/// @note name must be lower case
|
||||
Ptr getPtr (const std::string& name);
|
||||
void rest ();
|
||||
void rest (double hours);
|
||||
|
||||
/// Get all Ptrs referencing \a name in exterior cells
|
||||
/// @note Due to the current implementation of getPtr this only supports one Ptr per cell.
|
||||
|
@ -966,7 +966,7 @@ namespace MWWorld
|
||||
}
|
||||
}
|
||||
|
||||
void CellStore::rest()
|
||||
void CellStore::rest(double hours)
|
||||
{
|
||||
if (mState == State_Loaded)
|
||||
{
|
||||
@ -975,7 +975,7 @@ namespace MWWorld
|
||||
Ptr ptr = getCurrentPtr(&*it);
|
||||
if (!ptr.isEmpty() && ptr.getRefData().getCount() > 0)
|
||||
{
|
||||
MWBase::Environment::get().getMechanicsManager()->restoreDynamicStats(ptr, true);
|
||||
MWBase::Environment::get().getMechanicsManager()->restoreDynamicStats(ptr, hours, true);
|
||||
}
|
||||
}
|
||||
for (CellRefList<ESM::NPC>::List::iterator it (mNpcs.mList.begin()); it!=mNpcs.mList.end(); ++it)
|
||||
@ -983,7 +983,7 @@ namespace MWWorld
|
||||
Ptr ptr = getCurrentPtr(&*it);
|
||||
if (!ptr.isEmpty() && ptr.getRefData().getCount() > 0)
|
||||
{
|
||||
MWBase::Environment::get().getMechanicsManager()->restoreDynamicStats(ptr, true);
|
||||
MWBase::Environment::get().getMechanicsManager()->restoreDynamicStats(ptr, hours, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -183,7 +183,7 @@ namespace MWWorld
|
||||
/// @return updated MWWorld::Ptr with the new CellStore pointer set.
|
||||
MWWorld::Ptr moveTo(const MWWorld::Ptr& object, MWWorld::CellStore* cellToMoveTo);
|
||||
|
||||
void rest();
|
||||
void rest(double hours);
|
||||
|
||||
/// Make a copy of the given object and insert it into this cell.
|
||||
/// @note If you get a linker error here, this means the given type can not be inserted into a cell.
|
||||
|
@ -3280,9 +3280,9 @@ namespace MWWorld
|
||||
return closestMarker;
|
||||
}
|
||||
|
||||
void World::rest()
|
||||
void World::rest(double hours)
|
||||
{
|
||||
mCells.rest();
|
||||
mCells.rest(hours);
|
||||
}
|
||||
|
||||
void World::teleportToClosestMarker (const MWWorld::Ptr& ptr,
|
||||
|
@ -576,7 +576,7 @@ namespace MWWorld
|
||||
RestPermitted canRest() const override;
|
||||
///< check if the player is allowed to rest
|
||||
|
||||
void rest() override;
|
||||
void rest(double hours) override;
|
||||
|
||||
/// \todo Probably shouldn't be here
|
||||
MWRender::Animation* getAnimation(const MWWorld::Ptr &ptr) override;
|
||||
|
Loading…
x
Reference in New Issue
Block a user