Merge branch 'unawarenesstraining' into 'master'
Some checks are pending
Build and test / MacOS (push) Waiting to run
Build and test / Read .env file and expose it as output (push) Waiting to run
Build and test / Windows (2019) (push) Blocked by required conditions
Build and test / Windows (2022) (push) Blocked by required conditions
Build and test / Ubuntu (push) Waiting to run

Cache awareness rolls for 5 seconds to make sneaking easier

See merge request OpenMW/openmw!4434
This commit is contained in:
Evil Eye 2025-04-24 00:35:10 +00:00
commit 0ecf885b83
4 changed files with 28 additions and 2 deletions

View file

@ -407,6 +407,7 @@ namespace MWMechanics
void Actors::updateActor(const MWWorld::Ptr& ptr, float duration) const void Actors::updateActor(const MWWorld::Ptr& ptr, float duration) const
{ {
ptr.getClass().getCreatureStats(ptr).updateAwareness(duration);
// magic effects // magic effects
adjustMagicEffects(ptr, duration); adjustMagicEffects(ptr, duration);

View file

@ -695,4 +695,24 @@ namespace MWMechanics
{ {
return mSummonGraveyard; 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;
}
} }

View file

@ -90,6 +90,9 @@ namespace MWMechanics
// This may be necessary when the creature is in an inactive cell. // This may be necessary when the creature is in an inactive cell.
std::vector<int> mSummonGraveyard; std::vector<int> mSummonGraveyard;
float mAwarenessTimer = 0.f;
int mAwarenessRoll = -1;
protected: protected:
std::string mAttackType; std::string mAttackType;
int mLevel = 0; int mLevel = 0;
@ -303,6 +306,9 @@ namespace MWMechanics
void setTeleported(bool v) { mTeleported = v; } void setTeleported(bool v) { mTeleported = v; }
const std::map<ESM::RefId, AttributeValue>& getAttributes() const { return mAttributes; } const std::map<ESM::RefId, AttributeValue>& getAttributes() const { return mAttributes; }
void updateAwareness(float duration);
int getAwarenessRoll();
}; };
} }

View file

@ -1657,8 +1657,7 @@ namespace MWMechanics
} }
float target = x - y; float target = x - y;
auto& prng = MWBase::Environment::get().getWorld()->getPrng(); return observerStats.getAwarenessRoll() >= target;
return (Misc::Rng::roll0to99(prng) >= target);
} }
void MechanicsManager::startCombat( void MechanicsManager::startCombat(