1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-21 17:39:40 +00:00

Use fallback values for region sounds and fix probability

This commit is contained in:
unknown 2020-10-24 18:54:46 +02:00
parent fb63f8058f
commit 1ce296aa7f
2 changed files with 16 additions and 4 deletions

View file

@ -1,5 +1,6 @@
#include "regionsoundselector.hpp"
#include <components/fallback/fallback.hpp>
#include <components/misc/rng.hpp>
#include <algorithm>
@ -18,6 +19,12 @@ namespace MWSound
}
}
RegionSoundSelector::RegionSoundSelector()
{
mMinTimeBetweenSounds = Fallback::Map::getFloat("Weather_Minimum_Time_Between_Environmental_Sounds");
mMaxTimeBetweenSounds = Fallback::Map::getFloat("Weather_Maximum_Time_Between_Environmental_Sounds");
}
boost::optional<std::string> RegionSoundSelector::getNextRandom(float duration, const std::string& regionName,
const MWBase::World& world)
{
@ -27,9 +34,7 @@ namespace MWSound
return {};
const float a = Misc::Rng::rollClosedProbability();
// NOTE: We should use the "Minimum Time Between Environmental Sounds" and
// "Maximum Time Between Environmental Sounds" fallback settings here.
mTimeToNextEnvSound = 5.0f * a + 15.0f * (1.0f - a);
mTimeToNextEnvSound = mMinTimeBetweenSounds + (mMaxTimeBetweenSounds - mMinTimeBetweenSounds) * a;
mTimePassed = 0;
if (mLastRegionName != regionName)
@ -50,7 +55,7 @@ namespace MWSound
return {};
}
const int r = Misc::Rng::rollDice(mSumChance);
const int r = Misc::Rng::rollDice(std::max(mSumChance, 100));
int pos = 0;
const auto isSelected = [&] (const ESM::Region::SoundRef& sound)
@ -66,6 +71,9 @@ namespace MWSound
if (it == region->mSoundList.end())
return {};
// TODO
// mTimeToNextEnvSound += soundDuration
return it->mSound;
}
}

View file

@ -18,11 +18,15 @@ namespace MWSound
boost::optional<std::string> getNextRandom(float duration, const std::string& regionName,
const MWBase::World& world);
RegionSoundSelector();
private:
float mTimeToNextEnvSound = 0.0f;
int mSumChance = 0;
std::string mLastRegionName;
float mTimePassed = 0.0;
float mMinTimeBetweenSounds;
float mMaxTimeBetweenSounds;
};
}