From b2fab5f5adf4e00f33915419cb0a8fda4c2e805c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Tue, 17 May 2022 17:40:58 +0300 Subject: [PATCH] Use World prng for weather system as it influences actors --- apps/openmw/mwworld/weather.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwworld/weather.cpp b/apps/openmw/mwworld/weather.cpp index eb0226d506..1e12d0b1dd 100644 --- a/apps/openmw/mwworld/weather.cpp +++ b/apps/openmw/mwworld/weather.cpp @@ -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(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;