2020-06-28 13:12:42 +02:00
|
|
|
#include "regionsoundselector.hpp"
|
|
|
|
|
2022-09-05 19:35:15 +02:00
|
|
|
#include <components/esm3/loadregn.hpp>
|
2020-10-24 18:54:46 +02:00
|
|
|
#include <components/fallback/fallback.hpp>
|
2020-06-28 13:12:42 +02:00
|
|
|
#include <components/misc/rng.hpp>
|
|
|
|
|
2023-04-20 13:37:01 +02:00
|
|
|
#include "../mwbase/environment.hpp"
|
2020-06-28 13:12:42 +02:00
|
|
|
#include "../mwworld/esmstore.hpp"
|
|
|
|
|
|
|
|
namespace MWSound
|
|
|
|
{
|
2020-10-24 18:54:46 +02:00
|
|
|
RegionSoundSelector::RegionSoundSelector()
|
2020-10-25 12:20:14 +01:00
|
|
|
: mMinTimeBetweenSounds(Fallback::Map::getFloat("Weather_Minimum_Time_Between_Environmental_Sounds"))
|
|
|
|
, mMaxTimeBetweenSounds(Fallback::Map::getFloat("Weather_Maximum_Time_Between_Environmental_Sounds"))
|
|
|
|
{
|
|
|
|
}
|
2020-10-24 18:54:46 +02:00
|
|
|
|
2024-03-09 17:14:43 +01:00
|
|
|
ESM::RefId RegionSoundSelector::getNextRandom(float duration, const ESM::RefId& regionName)
|
2020-06-28 13:12:42 +02:00
|
|
|
{
|
|
|
|
mTimePassed += duration;
|
|
|
|
|
|
|
|
if (mTimePassed < mTimeToNextEnvSound)
|
|
|
|
return {};
|
|
|
|
|
|
|
|
const float a = Misc::Rng::rollClosedProbability();
|
2020-10-24 18:54:46 +02:00
|
|
|
mTimeToNextEnvSound = mMinTimeBetweenSounds + (mMaxTimeBetweenSounds - mMinTimeBetweenSounds) * a;
|
2020-06-28 13:12:42 +02:00
|
|
|
mTimePassed = 0;
|
|
|
|
|
|
|
|
if (mLastRegionName != regionName)
|
|
|
|
{
|
|
|
|
mLastRegionName = regionName;
|
|
|
|
mSumChance = 0;
|
|
|
|
}
|
|
|
|
|
2023-04-20 13:37:01 +02:00
|
|
|
const ESM::Region* const region
|
2023-04-20 21:07:53 +02:00
|
|
|
= MWBase::Environment::get().getESMStore()->get<ESM::Region>().search(mLastRegionName);
|
2020-06-28 13:12:42 +02:00
|
|
|
|
|
|
|
if (region == nullptr)
|
|
|
|
return {};
|
|
|
|
|
2024-03-09 17:14:43 +01:00
|
|
|
for (const ESM::Region::SoundRef& sound : region->mSoundList)
|
2020-06-28 13:12:42 +02:00
|
|
|
{
|
2024-03-09 17:14:43 +01:00
|
|
|
if (Misc::Rng::roll0to99() < sound.mChance)
|
|
|
|
return sound.mSound;
|
2020-06-28 13:12:42 +02:00
|
|
|
}
|
2024-03-09 17:14:43 +01:00
|
|
|
return {};
|
2020-06-28 13:12:42 +02:00
|
|
|
}
|
|
|
|
}
|