diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index ade9d635b..83d6cc1f3 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -20,7 +20,6 @@ #include "character.hpp" #include -#include #include @@ -243,6 +242,11 @@ std::string CharacterController::chooseRandomGroup (const std::string& prefix, i return prefix + toString(roll); } +void CharacterController::updateKnockoutTimer(float duration) +{ + mTimeUntilWake -= duration; +} + void CharacterController::refreshHitRecoilAnims() { bool recovery = mPtr.getClass().getCreatureStats(mPtr).getHitRecovery(); @@ -255,11 +259,7 @@ void CharacterController::refreshHitRecoilAnims() || mPtr.getClass().getCreatureStats(mPtr).getFatigue().getBase() == 0) && mAnimation->hasAnimation("knockout")) { - std::random_device r; - std::mt19937 gen(r()); - std::uniform_int_distribution dist(1, 3); - mTimeToWake = time(NULL); - mTimeToWake += dist(gen); // Wake up after 1 to 3 seconds + mTimeUntilWake = Misc::Rng::rollClosedProbability() * 2 + 1; // Wake up after 1 to 3 seconds if (isSwimming && mAnimation->hasAnimation("swimknockout")) { mHitState = CharState_SwimKnockOut; @@ -345,7 +345,7 @@ void CharacterController::refreshHitRecoilAnims() mHitState = CharState_None; } else if (isKnockedOut() && mPtr.getClass().getCreatureStats(mPtr).getFatigue().getCurrent() > 0 - && time(NULL) > mTimeToWake) + && mTimeUntilWake <= 0) { mHitState = isSwimming ? CharState_SwimKnockDown : CharState_KnockDown; mAnimation->disable(mCurrentHit); @@ -1635,6 +1635,9 @@ void CharacterController::update(float duration) float speed = 0.f; updateMagicEffects(); + + if (isKnockedOut()) + updateKnockoutTimer(duration); bool godmode = mPtr == MWMechanics::getPlayer() && MWBase::Environment::get().getWorld()->getGodModeState(); diff --git a/apps/openmw/mwmechanics/character.hpp b/apps/openmw/mwmechanics/character.hpp index 12b4d6adc..0b9e60c11 100644 --- a/apps/openmw/mwmechanics/character.hpp +++ b/apps/openmw/mwmechanics/character.hpp @@ -196,7 +196,7 @@ class CharacterController : public MWRender::Animation::TextKeyListener float mSecondsOfSwimming; float mSecondsOfRunning; - time_t mTimeToWake; + float mTimeUntilWake; MWWorld::ConstPtr mHeadTrackTarget; @@ -226,6 +226,8 @@ class CharacterController : public MWRender::Animation::TextKeyListener void updateMagicEffects(); + void updateKnockoutTimer(float duration); + void playDeath(float startpoint, CharacterState death); CharacterState chooseRandomDeathState() const; void playRandomDeath(float startpoint = 0.0f);