Index: source/soundmanager/scripting/SoundGroup.cpp =================================================================== --- source/soundmanager/scripting/SoundGroup.cpp +++ source/soundmanager/scripting/SoundGroup.cpp @@ -21,23 +21,27 @@ #include "graphics/Camera.h" #include "graphics/GameView.h" #include "lib/rand.h" -#include "ps/Game.h" #include "ps/CLogger.h" #include "ps/CStr.h" #include "ps/Filesystem.h" +#include "ps/Game.h" #include "ps/Util.h" #include "ps/XML/Xeromyces.h" +#include "simulation2/components/ICmpVisual.h" +#include "simulation2/system/Component.h" #include "soundmanager/items/ISoundItem.h" #include "soundmanager/SoundManager.h" #include +#include extern CGame *g_Game; #if CONFIG2_AUDIO -static float RandFloat(float min, float max) +static float RandFloat(std::mt19937& rng, float min, float max) { - return rand(min * 100.f, max * 100.f) / 100.f; + std::uniform_real_distribution uni_dist(min, max); + return uni_dist(rng); } #endif @@ -179,13 +183,17 @@ hSound->SetRollOff(itemRollOff); } + std::mt19937 rng; + CmpPtr cmpVisual(*g_Game->GetSimulation2(), source); + rng.seed(cmpVisual ? cmpVisual->GetActorSeed() : 0); + if (TestFlag(eRandPitch)) - hSound->SetPitch(RandFloat(m_PitchLower, m_PitchUpper)); + hSound->SetPitch(RandFloat(rng, m_PitchLower, m_PitchUpper)); else hSound->SetPitch(m_Pitch); if (TestFlag(eRandGain)) - m_Gain = RandFloat(m_GainLower, m_GainUpper); + m_Gain = RandFloat(rng, m_GainLower, m_GainUpper); hSound->SetCone(m_ConeInnerAngle, m_ConeOuterAngle, m_ConeOuterGain); static_cast(g_SoundManager)->PlayGroupItem(hSound, m_Gain);