mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-13 21:40:11 +00:00
Roll for each region sound
This commit is contained in:
parent
dce0a9e11e
commit
f9da2b6b26
@ -157,6 +157,7 @@
|
||||
Bug #7840: First run of the launcher doesn't save viewing distance as the default value
|
||||
Bug #7841: Editor: "Dirty" water heights are saved in modified CELLs
|
||||
Bug #7859: AutoCalc flag is not used to calculate potion value
|
||||
Bug #7872: Region sounds use wrong odds
|
||||
Feature #2566: Handle NAM9 records for manual cell references
|
||||
Feature #3537: Shader-based water ripples
|
||||
Feature #5173: Support for NiFogProperty
|
||||
|
@ -4,29 +4,18 @@
|
||||
#include <components/fallback/fallback.hpp>
|
||||
#include <components/misc/rng.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <numeric>
|
||||
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwworld/esmstore.hpp"
|
||||
|
||||
namespace MWSound
|
||||
{
|
||||
namespace
|
||||
{
|
||||
int addChance(int result, const ESM::Region::SoundRef& v)
|
||||
{
|
||||
return result + v.mChance;
|
||||
}
|
||||
}
|
||||
|
||||
RegionSoundSelector::RegionSoundSelector()
|
||||
: mMinTimeBetweenSounds(Fallback::Map::getFloat("Weather_Minimum_Time_Between_Environmental_Sounds"))
|
||||
, mMaxTimeBetweenSounds(Fallback::Map::getFloat("Weather_Maximum_Time_Between_Environmental_Sounds"))
|
||||
{
|
||||
}
|
||||
|
||||
std::optional<ESM::RefId> RegionSoundSelector::getNextRandom(float duration, const ESM::RefId& regionName)
|
||||
ESM::RefId RegionSoundSelector::getNextRandom(float duration, const ESM::RefId& regionName)
|
||||
{
|
||||
mTimePassed += duration;
|
||||
|
||||
@ -49,28 +38,11 @@ namespace MWSound
|
||||
if (region == nullptr)
|
||||
return {};
|
||||
|
||||
if (mSumChance == 0)
|
||||
for (const ESM::Region::SoundRef& sound : region->mSoundList)
|
||||
{
|
||||
mSumChance = std::accumulate(region->mSoundList.begin(), region->mSoundList.end(), 0, addChance);
|
||||
if (mSumChance == 0)
|
||||
if (Misc::Rng::roll0to99() < sound.mChance)
|
||||
return sound.mSound;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
const int r = Misc::Rng::rollDice(std::max(mSumChance, 100));
|
||||
int pos = 0;
|
||||
|
||||
const auto isSelected = [&](const ESM::Region::SoundRef& sound) {
|
||||
if (r - pos < sound.mChance)
|
||||
return true;
|
||||
pos += sound.mChance;
|
||||
return false;
|
||||
};
|
||||
|
||||
const auto it = std::find_if(region->mSoundList.begin(), region->mSoundList.end(), isSelected);
|
||||
|
||||
if (it == region->mSoundList.end())
|
||||
return {};
|
||||
|
||||
return it->mSound;
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
#define GAME_SOUND_REGIONSOUNDSELECTOR_H
|
||||
|
||||
#include <components/esm/refid.hpp>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace MWBase
|
||||
@ -15,7 +14,7 @@ namespace MWSound
|
||||
class RegionSoundSelector
|
||||
{
|
||||
public:
|
||||
std::optional<ESM::RefId> getNextRandom(float duration, const ESM::RefId& regionName);
|
||||
ESM::RefId getNextRandom(float duration, const ESM::RefId& regionName);
|
||||
|
||||
RegionSoundSelector();
|
||||
|
||||
|
@ -900,8 +900,9 @@ namespace MWSound
|
||||
if (mCurrentRegionSound && mOutput->isSoundPlaying(mCurrentRegionSound))
|
||||
return;
|
||||
|
||||
if (const auto next = mRegionSoundSelector.getNextRandom(duration, cell->getRegion()))
|
||||
mCurrentRegionSound = playSound(*next, 1.0f, 1.0f);
|
||||
ESM::RefId next = mRegionSoundSelector.getNextRandom(duration, cell->getRegion());
|
||||
if (!next.empty())
|
||||
mCurrentRegionSound = playSound(next, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
void SoundManager::updateWaterSound()
|
||||
|
Loading…
x
Reference in New Issue
Block a user