1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-31 22:45:33 +00:00

consolidate random number logic

Note, I suspect Rng::rollClosedProbability() is not needed.  The only difference between it and rollProbability() is that one time in 37k (on Windows), it will give an output of 1.0.
On some versions of Linux, the value of 1.0 will occur about 1 time in 4 billion.

(cherry picked from commit 3f28634d1f)

# Conflicts:
#	apps/openmw/mwclass/creature.cpp
#	apps/openmw/mwclass/npc.cpp
#	apps/openmw/mwgui/pickpocketitemmodel.cpp
#	apps/openmw/mwgui/waitdialog.cpp
#	apps/openmw/mwmechanics/combat.cpp
#	apps/openmw/mwmechanics/mechanicsmanagerimp.cpp
#	components/CMakeLists.txt
#	libs/openengine/misc/rng.cpp
This commit is contained in:
dteviot 2015-03-15 14:07:47 +13:00 committed by cc9cii
parent c9b07b5f72
commit 4b0aeb4066
8 changed files with 8 additions and 14 deletions

View file

@ -250,7 +250,7 @@ namespace MWClass
float hitchance = MWMechanics::getHitChance(ptr, victim, ref->mBase->mData.mCombat);
if(OEngine::Misc::Rng::roll0to99() >= hitchance)
if(OEngine::Misc::Rng::rollProbability() >= hitchance/100.0f)
{
victim.getClass().onHit(victim, 0.0f, false, MWWorld::Ptr(), ptr, false);
MWMechanics::reduceWeaponCondition(0.f, false, weapon, ptr);

View file

@ -382,7 +382,7 @@ namespace MWClass
float hitchance = MWMechanics::getHitChance(ptr, victim, ptr.getClass().getSkill(ptr, weapskill));
if (OEngine::Misc::Rng::roll0to99() >= hitchance)
if (OEngine::Misc::Rng::rollProbability() >= hitchance / 100.0f)
{
othercls.onHit(victim, 0.0f, false, weapon, ptr, false);
MWMechanics::reduceWeaponCondition(0.f, false, weapon, ptr);

View file

@ -20,7 +20,7 @@ namespace MWGui
{
for (size_t i = 0; i<mSourceModel->getItemCount(); ++i)
{
if (OEngine::Misc::Rng::roll0to99() > chance)
if (chance <= OEngine::Misc::Rng::roll0to99())
mHiddenItems.push_back(mSourceModel->getItem(i));
}
}

View file

@ -155,9 +155,8 @@ namespace MWGui
if (!region->mSleepList.empty())
{
// figure out if player will be woken while sleeping
int x = OEngine::Misc::Rng::rollDice(hoursToWait);
float fSleepRandMod = world->getStore().get<ESM::GameSetting>().find("fSleepRandMod")->getFloat();
if (x < fSleepRandMod * hoursToWait)
if (OEngine::Misc::Rng::rollProbability() > fSleepRandMod)
{
float fSleepRestMod = world->getStore().get<ESM::GameSetting>().find("fSleepRestMod")->getFloat();
mInterruptAt = hoursToWait - int(fSleepRestMod * hoursToWait);

View file

@ -187,7 +187,7 @@ namespace MWMechanics
int skillValue = attacker.getClass().getSkill(attacker,
weapon.getClass().getEquipmentSkill(weapon));
if (OEngine::Misc::Rng::roll0to99() >= getHitChance(attacker, victim, skillValue))
if (OEngine::Misc::Rng::rollProbability() >= getHitChance(attacker, victim, skillValue) / 100.0f)
{
victim.getClass().onHit(victim, 0.0f, false, projectile, attacker, false);
MWMechanics::reduceWeaponCondition(0.f, false, weapon, attacker);

View file

@ -741,7 +741,7 @@ namespace MWMechanics
float x = 0;
float y = 0;
int roll = OEngine::Misc::Rng::roll0to99();
float roll = OEngine::Misc::Rng::rollClosedProbability() * 100;
if (type == PT_Admire)
{

View file

@ -166,14 +166,9 @@ include_directories(${BULLET_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR})
add_library(components STATIC ${COMPONENT_FILES} ${MOC_SRCS} ${ESM_UI_HDR})
target_link_libraries(components
${Boost_SYSTEM_LIBRARY}
${Boost_FILESYSTEM_LIBRARY}
${Boost_THREAD_LIBRARY}
${Boost_PROGRAM_OPTIONS_LIBRARY}
${Boost_WAVE_LIBRARY}
${Boost_LIBRARIES}
${OGRE_LIBRARIES}
${OENGINE_LIBRARY}
${BULLET_LIBRARIES}
)
if (WIN32)

View file

@ -26,4 +26,4 @@ namespace Misc {
}
}
}
}