mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-16 08:42:23 +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 #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 #7841: Editor: "Dirty" water heights are saved in modified CELLs
|
||||||
Bug #7859: AutoCalc flag is not used to calculate potion value
|
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 #2566: Handle NAM9 records for manual cell references
|
||||||
Feature #3537: Shader-based water ripples
|
Feature #3537: Shader-based water ripples
|
||||||
Feature #5173: Support for NiFogProperty
|
Feature #5173: Support for NiFogProperty
|
||||||
|
@ -4,29 +4,18 @@
|
|||||||
#include <components/fallback/fallback.hpp>
|
#include <components/fallback/fallback.hpp>
|
||||||
#include <components/misc/rng.hpp>
|
#include <components/misc/rng.hpp>
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <numeric>
|
|
||||||
|
|
||||||
#include "../mwbase/environment.hpp"
|
#include "../mwbase/environment.hpp"
|
||||||
#include "../mwworld/esmstore.hpp"
|
#include "../mwworld/esmstore.hpp"
|
||||||
|
|
||||||
namespace MWSound
|
namespace MWSound
|
||||||
{
|
{
|
||||||
namespace
|
|
||||||
{
|
|
||||||
int addChance(int result, const ESM::Region::SoundRef& v)
|
|
||||||
{
|
|
||||||
return result + v.mChance;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RegionSoundSelector::RegionSoundSelector()
|
RegionSoundSelector::RegionSoundSelector()
|
||||||
: mMinTimeBetweenSounds(Fallback::Map::getFloat("Weather_Minimum_Time_Between_Environmental_Sounds"))
|
: mMinTimeBetweenSounds(Fallback::Map::getFloat("Weather_Minimum_Time_Between_Environmental_Sounds"))
|
||||||
, mMaxTimeBetweenSounds(Fallback::Map::getFloat("Weather_Maximum_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;
|
mTimePassed += duration;
|
||||||
|
|
||||||
@ -49,28 +38,11 @@ namespace MWSound
|
|||||||
if (region == nullptr)
|
if (region == nullptr)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
if (mSumChance == 0)
|
for (const ESM::Region::SoundRef& sound : region->mSoundList)
|
||||||
{
|
{
|
||||||
mSumChance = std::accumulate(region->mSoundList.begin(), region->mSoundList.end(), 0, addChance);
|
if (Misc::Rng::roll0to99() < sound.mChance)
|
||||||
if (mSumChance == 0)
|
return sound.mSound;
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
|
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
|
#define GAME_SOUND_REGIONSOUNDSELECTOR_H
|
||||||
|
|
||||||
#include <components/esm/refid.hpp>
|
#include <components/esm/refid.hpp>
|
||||||
#include <optional>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace MWBase
|
namespace MWBase
|
||||||
@ -15,7 +14,7 @@ namespace MWSound
|
|||||||
class RegionSoundSelector
|
class RegionSoundSelector
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::optional<ESM::RefId> getNextRandom(float duration, const ESM::RefId& regionName);
|
ESM::RefId getNextRandom(float duration, const ESM::RefId& regionName);
|
||||||
|
|
||||||
RegionSoundSelector();
|
RegionSoundSelector();
|
||||||
|
|
||||||
|
@ -900,8 +900,9 @@ namespace MWSound
|
|||||||
if (mCurrentRegionSound && mOutput->isSoundPlaying(mCurrentRegionSound))
|
if (mCurrentRegionSound && mOutput->isSoundPlaying(mCurrentRegionSound))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (const auto next = mRegionSoundSelector.getNextRandom(duration, cell->getRegion()))
|
ESM::RefId next = mRegionSoundSelector.getNextRandom(duration, cell->getRegion());
|
||||||
mCurrentRegionSound = playSound(*next, 1.0f, 1.0f);
|
if (!next.empty())
|
||||||
|
mCurrentRegionSound = playSound(next, 1.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundManager::updateWaterSound()
|
void SoundManager::updateWaterSound()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user