Commit 4b0aeb40 authored by dteviot's avatar dteviot Committed by cc9cii

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 3f28634d)

# 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
parent c9b07b5f
......@@ -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);
......
......@@ -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);
......
......@@ -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));
}
}
......
......@@ -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);
......
......@@ -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);
......
......@@ -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)
{
......
......@@ -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)
......
......@@ -26,4 +26,4 @@ namespace Misc {
}
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment