1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-10 06:39:49 +00:00

Use World prng for weather system as it influences actors

This commit is contained in:
ζeh Matt 2022-05-17 17:40:58 +03:00
parent 3a90bc7187
commit b2fab5f5ad
No known key found for this signature in database
GPG Key ID: 18CE582C71A225B0

View File

@ -226,8 +226,8 @@ namespace MWWorld
if(transitionRatio >= mThunderThreshold && mThunderFrequency > 0.0f)
{
flashDecrement(elapsedSeconds);
if(Misc::Rng::rollProbability() <= thunderChance(transitionRatio, elapsedSeconds))
auto& prng = MWBase::Environment::get().getWorld()->getPrng();
if(Misc::Rng::rollProbability(prng) <= thunderChance(transitionRatio, elapsedSeconds))
{
lightningAndThunder();
}
@ -265,7 +265,8 @@ namespace MWWorld
// They appear to go from 0 (brightest, closest) to 3 (faintest, farthest). The value of 0.25 per distance
// was derived by setting the Flash Decrement to 0.1 and measuring how long each value took to decay to 0.
// TODO: Determine the distribution of each distance to see if it's evenly weighted.
unsigned int distance = Misc::Rng::rollDice(4);
auto& prng = MWBase::Environment::get().getWorld()->getPrng();
unsigned int distance = Misc::Rng::rollDice(4, prng);
// Flash brightness appears additive, since if multiple strikes occur, it takes longer for it to decay to 0.
mFlashBrightness += 1 - (distance * 0.25f);
MWBase::Environment::get().getSoundManager()->playSound(mThunderSoundID[distance], 1.0, 1.0);
@ -348,7 +349,8 @@ namespace MWWorld
// All probabilities must add to 100 (responsibility of the user).
// If chances A and B has values 30 and 70 then by generating 100 numbers 1..100, 30% will be lesser or equal 30
// and 70% will be greater than 30 (in theory).
int chance = Misc::Rng::rollDice(100) + 1; // 1..100
auto& prng = MWBase::Environment::get().getWorld()->getPrng();
int chance = Misc::Rng::rollDice(100, prng) + 1; // 1..100
int sum = 0;
int i = 0;
for(; static_cast<size_t>(i) < mChances.size(); ++i)
@ -685,7 +687,8 @@ namespace MWWorld
currentSpeed = targetSpeed;
float multiplier = mWeatherSettings[weatherId].mRainEffect.empty() ? 1.f : 0.5f;
float updatedSpeed = (Misc::Rng::rollClosedProbability() - 0.5f) * multiplier * targetSpeed + currentSpeed;
auto& prng = MWBase::Environment::get().getWorld()->getPrng();
float updatedSpeed = (Misc::Rng::rollClosedProbability(prng) - 0.5f) * multiplier * targetSpeed + currentSpeed;
if (updatedSpeed > 0.5f * targetSpeed && updatedSpeed < 2.f * targetSpeed)
currentSpeed = updatedSpeed;