From f8b8569f3b37bce2db513d388b2038df60bf79d6 Mon Sep 17 00:00:00 2001 From: elsid Date: Mon, 4 Jul 2022 21:38:26 +0200 Subject: [PATCH] Initialize variables on declaration --- apps/openmw/mwmechanics/actors.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index 83179113a5..ba098aad38 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -93,16 +93,18 @@ void adjustCommandedActor (const MWWorld::Ptr& actor) }); } -void getRestorationPerHourOfSleep (const MWWorld::Ptr& ptr, float& health, float& magicka) +std::pair getRestorationPerHourOfSleep(const MWWorld::Ptr& ptr) { MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats (ptr); const MWWorld::Store& settings = MWBase::Environment::get().getWorld()->getStore().get(); float endurance = stats.getAttribute (ESM::Attribute::Endurance).getModified (); - health = 0.1f * endurance; + const float health = 0.1f * endurance; float fRestMagicMult = settings.find("fRestMagicMult")->mValue.getFloat (); - magicka = fRestMagicMult * stats.getAttribute(ESM::Attribute::Intelligence).getModified(); + const float magicka = fRestMagicMult * stats.getAttribute(ESM::Attribute::Intelligence).getModified(); + + return {health, magicka}; } template @@ -764,8 +766,7 @@ namespace MWMechanics if (sleep) { - float health, magicka; - getRestorationPerHourOfSleep(ptr, health, magicka); + auto [health, magicka] = getRestorationPerHourOfSleep(ptr); DynamicStat stat = stats.getHealth(); stat.setCurrent(stat.getCurrent() + health * hours); @@ -1908,8 +1909,7 @@ namespace MWMechanics int Actors::getHoursToRest(const MWWorld::Ptr &ptr) const { - float healthPerHour, magickaPerHour; - getRestorationPerHourOfSleep(ptr, healthPerHour, magickaPerHour); + auto [healthPerHour, magickaPerHour] = getRestorationPerHourOfSleep(ptr); CreatureStats& stats = ptr.getClass().getCreatureStats(ptr); bool stunted = stats.getMagicEffects ().get(ESM::MagicEffect::StuntedMagicka).getMagnitude() > 0;