1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-28 14:53:58 +00:00

Prevent division by 0

This commit is contained in:
Evil Eye 2022-02-10 20:28:27 +01:00
parent 8cfb3e1053
commit 5aef14eccd
2 changed files with 8 additions and 6 deletions

View File

@ -257,9 +257,9 @@ bool MWDialogue::Filter::testSelectStructNumeric (const SelectWrapper& select) c
case SelectWrapper::Function_PcHealthPercent:
{
MWWorld::Ptr player = MWMechanics::getPlayer();
float ratio = player.getClass().getCreatureStats (player).getHealth().getCurrent() /
player.getClass().getCreatureStats (player).getHealth().getModified();
float ratio = player.getClass().getCreatureStats(player).getHealth().getModified();
if(ratio > 0)
ratio = player.getClass().getCreatureStats(player).getHealth().getCurrent() / ratio;
return select.selectCompare (static_cast<int>(ratio*100));
}
@ -276,8 +276,9 @@ bool MWDialogue::Filter::testSelectStructNumeric (const SelectWrapper& select) c
case SelectWrapper::Function_HealthPercent:
{
float ratio = mActor.getClass().getCreatureStats (mActor).getHealth().getCurrent() /
mActor.getClass().getCreatureStats (mActor).getHealth().getModified();
float ratio = mActor.getClass().getCreatureStats(mActor).getHealth().getModified();
if(ratio > 0)
ratio = mActor.getClass().getCreatureStats(mActor).getHealth().getCurrent() / ratio;
return select.selectCompare (static_cast<int>(ratio*100));
}

View File

@ -608,7 +608,8 @@ namespace MWGui
mEnemyHealth->setProgressRange(100);
// Health is usually cast to int before displaying. Actors die whenever they are < 1 health.
// Therefore any value < 1 should show as an empty health bar. We do the same in statswindow :)
mEnemyHealth->setProgressPosition(static_cast<size_t>(stats.getHealth().getCurrent() / stats.getHealth().getModified() * 100));
float health = stats.getHealth().getModified();
mEnemyHealth->setProgressPosition(health == 0.f ? 0 : static_cast<size_t>(stats.getHealth().getCurrent() / health * 100));
static const float fNPCHealthBarFade = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fNPCHealthBarFade")->mValue.getFloat();
if (fNPCHealthBarFade > 0.f)