mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-09-23 03:47:34 -04:00
Cache awareness rolls for 5 seconds to make sneaking easier
This commit is contained in:
parent
730a62effc
commit
b3fe84a560
@ -409,6 +409,7 @@ namespace MWMechanics
|
||||
|
||||
void Actors::updateActor(const MWWorld::Ptr& ptr, float duration) const
|
||||
{
|
||||
ptr.getClass().getCreatureStats(ptr).updateAwareness(duration);
|
||||
// magic effects
|
||||
adjustMagicEffects(ptr, duration);
|
||||
|
||||
|
@ -686,4 +686,24 @@ namespace MWMechanics
|
||||
{
|
||||
return mSummonGraveyard;
|
||||
}
|
||||
|
||||
void CreatureStats::updateAwareness(float duration)
|
||||
{
|
||||
mAwarenessTimer += duration;
|
||||
// Only reroll for awareness every 5 seconds
|
||||
if (mAwarenessTimer >= 5.f)
|
||||
{
|
||||
mAwarenessTimer = 0.f;
|
||||
mAwarenessRoll = -1;
|
||||
}
|
||||
}
|
||||
|
||||
int CreatureStats::getAwarenessRoll()
|
||||
{
|
||||
if (mAwarenessRoll >= 0)
|
||||
return mAwarenessRoll;
|
||||
auto& prng = MWBase::Environment::get().getWorld()->getPrng();
|
||||
mAwarenessRoll = Misc::Rng::roll0to99(prng);
|
||||
return mAwarenessRoll;
|
||||
}
|
||||
}
|
||||
|
@ -90,6 +90,9 @@ namespace MWMechanics
|
||||
// This may be necessary when the creature is in an inactive cell.
|
||||
std::vector<int> mSummonGraveyard;
|
||||
|
||||
float mAwarenessTimer = 0.f;
|
||||
int mAwarenessRoll = -1;
|
||||
|
||||
protected:
|
||||
std::string mAttackType;
|
||||
int mLevel = 0;
|
||||
@ -300,6 +303,9 @@ namespace MWMechanics
|
||||
void setTeleported(bool v) { mTeleported = v; }
|
||||
|
||||
const std::map<ESM::RefId, AttributeValue>& getAttributes() const { return mAttributes; }
|
||||
|
||||
void updateAwareness(float duration);
|
||||
int getAwarenessRoll();
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -1675,8 +1675,7 @@ namespace MWMechanics
|
||||
}
|
||||
|
||||
float target = x - y;
|
||||
auto& prng = MWBase::Environment::get().getWorld()->getPrng();
|
||||
return (Misc::Rng::roll0to99(prng) >= target);
|
||||
return observerStats.getAwarenessRoll() >= target;
|
||||
}
|
||||
|
||||
void MechanicsManager::startCombat(
|
||||
|
Loading…
x
Reference in New Issue
Block a user