mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-11-04 04:56:39 +00:00 
			
		
		
		
	Prevent division by 0
This commit is contained in:
		
							parent
							
								
									8cfb3e1053
								
							
						
					
					
						commit
						5aef14eccd
					
				
					 2 changed files with 8 additions and 6 deletions
				
			
		| 
						 | 
					@ -257,9 +257,9 @@ bool MWDialogue::Filter::testSelectStructNumeric (const SelectWrapper& select) c
 | 
				
			||||||
        case SelectWrapper::Function_PcHealthPercent:
 | 
					        case SelectWrapper::Function_PcHealthPercent:
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            MWWorld::Ptr player = MWMechanics::getPlayer();
 | 
					            MWWorld::Ptr player = MWMechanics::getPlayer();
 | 
				
			||||||
 | 
					            float ratio = player.getClass().getCreatureStats(player).getHealth().getModified();
 | 
				
			||||||
            float ratio = player.getClass().getCreatureStats (player).getHealth().getCurrent() /
 | 
					            if(ratio > 0)
 | 
				
			||||||
                player.getClass().getCreatureStats (player).getHealth().getModified();
 | 
					                ratio = player.getClass().getCreatureStats(player).getHealth().getCurrent() / ratio;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return select.selectCompare (static_cast<int>(ratio*100));
 | 
					            return select.selectCompare (static_cast<int>(ratio*100));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -276,8 +276,9 @@ bool MWDialogue::Filter::testSelectStructNumeric (const SelectWrapper& select) c
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        case SelectWrapper::Function_HealthPercent:
 | 
					        case SelectWrapper::Function_HealthPercent:
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            float ratio = mActor.getClass().getCreatureStats (mActor).getHealth().getCurrent() /
 | 
					            float ratio = mActor.getClass().getCreatureStats(mActor).getHealth().getModified();
 | 
				
			||||||
                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));
 | 
					            return select.selectCompare (static_cast<int>(ratio*100));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -608,7 +608,8 @@ namespace MWGui
 | 
				
			||||||
        mEnemyHealth->setProgressRange(100);
 | 
					        mEnemyHealth->setProgressRange(100);
 | 
				
			||||||
        // Health is usually cast to int before displaying. Actors die whenever they are < 1 health.
 | 
					        // 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 :)
 | 
					        // 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();
 | 
					        static const float fNPCHealthBarFade = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fNPCHealthBarFade")->mValue.getFloat();
 | 
				
			||||||
        if (fNPCHealthBarFade > 0.f)
 | 
					        if (fNPCHealthBarFade > 0.f)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue