mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-05 16:19:43 +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:
parent
c9b07b5f72
commit
4b0aeb4066
8 changed files with 8 additions and 14 deletions
apps/openmw
mwclass
mwgui
mwmechanics
components
libs/openengine/misc
|
@ -250,7 +250,7 @@ namespace MWClass
|
||||||
|
|
||||||
float hitchance = MWMechanics::getHitChance(ptr, victim, ref->mBase->mData.mCombat);
|
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);
|
victim.getClass().onHit(victim, 0.0f, false, MWWorld::Ptr(), ptr, false);
|
||||||
MWMechanics::reduceWeaponCondition(0.f, false, weapon, ptr);
|
MWMechanics::reduceWeaponCondition(0.f, false, weapon, ptr);
|
||||||
|
|
|
@ -382,7 +382,7 @@ namespace MWClass
|
||||||
|
|
||||||
float hitchance = MWMechanics::getHitChance(ptr, victim, ptr.getClass().getSkill(ptr, weapskill));
|
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);
|
othercls.onHit(victim, 0.0f, false, weapon, ptr, false);
|
||||||
MWMechanics::reduceWeaponCondition(0.f, false, weapon, ptr);
|
MWMechanics::reduceWeaponCondition(0.f, false, weapon, ptr);
|
||||||
|
|
|
@ -20,7 +20,7 @@ namespace MWGui
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i<mSourceModel->getItemCount(); ++i)
|
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));
|
mHiddenItems.push_back(mSourceModel->getItem(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,9 +155,8 @@ namespace MWGui
|
||||||
if (!region->mSleepList.empty())
|
if (!region->mSleepList.empty())
|
||||||
{
|
{
|
||||||
// figure out if player will be woken while sleeping
|
// 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();
|
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();
|
float fSleepRestMod = world->getStore().get<ESM::GameSetting>().find("fSleepRestMod")->getFloat();
|
||||||
mInterruptAt = hoursToWait - int(fSleepRestMod * hoursToWait);
|
mInterruptAt = hoursToWait - int(fSleepRestMod * hoursToWait);
|
||||||
|
|
|
@ -187,7 +187,7 @@ namespace MWMechanics
|
||||||
int skillValue = attacker.getClass().getSkill(attacker,
|
int skillValue = attacker.getClass().getSkill(attacker,
|
||||||
weapon.getClass().getEquipmentSkill(weapon));
|
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);
|
victim.getClass().onHit(victim, 0.0f, false, projectile, attacker, false);
|
||||||
MWMechanics::reduceWeaponCondition(0.f, false, weapon, attacker);
|
MWMechanics::reduceWeaponCondition(0.f, false, weapon, attacker);
|
||||||
|
|
|
@ -741,7 +741,7 @@ namespace MWMechanics
|
||||||
float x = 0;
|
float x = 0;
|
||||||
float y = 0;
|
float y = 0;
|
||||||
|
|
||||||
int roll = OEngine::Misc::Rng::roll0to99();
|
float roll = OEngine::Misc::Rng::rollClosedProbability() * 100;
|
||||||
|
|
||||||
if (type == PT_Admire)
|
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})
|
add_library(components STATIC ${COMPONENT_FILES} ${MOC_SRCS} ${ESM_UI_HDR})
|
||||||
|
|
||||||
target_link_libraries(components
|
target_link_libraries(components
|
||||||
${Boost_SYSTEM_LIBRARY}
|
${Boost_LIBRARIES}
|
||||||
${Boost_FILESYSTEM_LIBRARY}
|
|
||||||
${Boost_THREAD_LIBRARY}
|
|
||||||
${Boost_PROGRAM_OPTIONS_LIBRARY}
|
|
||||||
${Boost_WAVE_LIBRARY}
|
|
||||||
${OGRE_LIBRARIES}
|
${OGRE_LIBRARIES}
|
||||||
${OENGINE_LIBRARY}
|
${OENGINE_LIBRARY}
|
||||||
${BULLET_LIBRARIES}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
|
|
|
@ -26,4 +26,4 @@ namespace Misc {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue