mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-18 14:42:27 +00:00
Add getRatio method
This commit is contained in:
parent
6b203892fc
commit
054d8babc4
@ -257,11 +257,7 @@ 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();
|
return select.selectCompare(static_cast<int>(player.getClass().getCreatureStats(player).getHealth().getRatio() * 100));
|
||||||
if(ratio > 0)
|
|
||||||
ratio = player.getClass().getCreatureStats(player).getHealth().getCurrent() / ratio;
|
|
||||||
|
|
||||||
return select.selectCompare (static_cast<int>(ratio*100));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case SelectWrapper::Function_PcDynamicStat:
|
case SelectWrapper::Function_PcDynamicStat:
|
||||||
@ -276,11 +272,7 @@ bool MWDialogue::Filter::testSelectStructNumeric (const SelectWrapper& select) c
|
|||||||
|
|
||||||
case SelectWrapper::Function_HealthPercent:
|
case SelectWrapper::Function_HealthPercent:
|
||||||
{
|
{
|
||||||
float ratio = mActor.getClass().getCreatureStats(mActor).getHealth().getModified();
|
return select.selectCompare(static_cast<int>(mActor.getClass().getCreatureStats(mActor).getHealth().getRatio() * 100));
|
||||||
if(ratio > 0)
|
|
||||||
ratio = mActor.getClass().getCreatureStats(mActor).getHealth().getCurrent() / ratio;
|
|
||||||
|
|
||||||
return select.selectCompare (static_cast<int>(ratio*100));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -608,8 +608,7 @@ 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 :)
|
||||||
float health = stats.getHealth().getModified();
|
mEnemyHealth->setProgressPosition(static_cast<size_t>(stats.getHealth().getRatio() * 100));
|
||||||
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)
|
||||||
|
@ -476,8 +476,7 @@ namespace MWMechanics
|
|||||||
static const float fAIFleeHealthMult = gmst.find("fAIFleeHealthMult")->mValue.getFloat();
|
static const float fAIFleeHealthMult = gmst.find("fAIFleeHealthMult")->mValue.getFloat();
|
||||||
static const float fAIFleeFleeMult = gmst.find("fAIFleeFleeMult")->mValue.getFloat();
|
static const float fAIFleeFleeMult = gmst.find("fAIFleeFleeMult")->mValue.getFloat();
|
||||||
|
|
||||||
float healthPercentage = (stats.getHealth().getModified() == 0.0f)
|
float healthPercentage = stats.getHealth().getRatio(false);
|
||||||
? 1.0f : stats.getHealth().getCurrent() / stats.getHealth().getModified();
|
|
||||||
float rating = (1.0f - healthPercentage) * fAIFleeHealthMult + flee * fAIFleeFleeMult;
|
float rating = (1.0f - healthPercentage) * fAIFleeHealthMult + flee * fAIFleeFleeMult;
|
||||||
|
|
||||||
static const int iWereWolfLevelToAttack = gmst.find("iWereWolfLevelToAttack")->mValue.getInteger();
|
static const int iWereWolfLevelToAttack = gmst.find("iWereWolfLevelToAttack")->mValue.getInteger();
|
||||||
|
@ -65,6 +65,19 @@ namespace MWMechanics
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
T DynamicStat<T>::getRatio(bool nanIsZero) const
|
||||||
|
{
|
||||||
|
T modified = getModified();
|
||||||
|
if(modified == T{})
|
||||||
|
{
|
||||||
|
if(nanIsZero)
|
||||||
|
return modified;
|
||||||
|
return {1};
|
||||||
|
}
|
||||||
|
return getCurrent() / modified;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void DynamicStat<T>::writeState (ESM::StatState<T>& state) const
|
void DynamicStat<T>::writeState (ESM::StatState<T>& state) const
|
||||||
{
|
{
|
||||||
|
@ -67,6 +67,7 @@ namespace MWMechanics
|
|||||||
const T& getBase() const { return mStatic.getBase(); };
|
const T& getBase() const { return mStatic.getBase(); };
|
||||||
T getModified(bool capped = true) const { return mStatic.getModified(capped); };
|
T getModified(bool capped = true) const { return mStatic.getModified(capped); };
|
||||||
const T& getCurrent() const { return mCurrent; };
|
const T& getCurrent() const { return mCurrent; };
|
||||||
|
T getRatio(bool nanIsZero = true) const;
|
||||||
|
|
||||||
/// Set base and adjust current accordingly.
|
/// Set base and adjust current accordingly.
|
||||||
void setBase(const T& value) { mStatic.setBase(value); };
|
void setBase(const T& value) { mStatic.setBase(value); };
|
||||||
|
@ -324,17 +324,9 @@ namespace MWScript
|
|||||||
void execute (Interpreter::Runtime& runtime) override
|
void execute (Interpreter::Runtime& runtime) override
|
||||||
{
|
{
|
||||||
MWWorld::Ptr ptr = R()(runtime);
|
MWWorld::Ptr ptr = R()(runtime);
|
||||||
|
const MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats(ptr);
|
||||||
|
|
||||||
MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats (ptr);
|
runtime.push(stats.getDynamic(mIndex).getRatio());
|
||||||
|
|
||||||
Interpreter::Type_Float value = 0;
|
|
||||||
|
|
||||||
Interpreter::Type_Float max = stats.getDynamic(mIndex).getModified();
|
|
||||||
|
|
||||||
if (max>0)
|
|
||||||
value = stats.getDynamic(mIndex).getCurrent() / max;
|
|
||||||
|
|
||||||
runtime.push (value);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user