1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-06-20 17:41:33 +00:00

Deduplicate swim speed formula implementation

This commit is contained in:
elsid 2020-06-14 18:01:22 +02:00
parent a854a6e04a
commit 2a0e1697b6
No known key found for this signature in database
GPG key ID: B845CB9FEE18AB40
3 changed files with 13 additions and 18 deletions

View file

@ -3,6 +3,8 @@
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include <components/esm/loadmgef.hpp>
namespace ESM namespace ESM
{ {
struct GameSetting; struct GameSetting;
@ -17,6 +19,15 @@ namespace MWClass
Actor() = default; Actor() = default;
template <class GMST>
float getSwimSpeedImpl(const MWWorld::Ptr& ptr, const GMST& gmst, const MWMechanics::MagicEffects& mageffects, float baseSpeed) const
{
return baseSpeed
* (1.0f + 0.01f * mageffects.get(ESM::MagicEffect::SwiftSwim).getMagnitude())
* (gmst.fSwimRunBase->mValue.getFloat()
+ 0.01f * getSkill(ptr, ESM::Skill::Athletics) * gmst.fSwimRunAthleticsMult->mValue.getFloat());
}
public: public:
~Actor() override = default; ~Actor() override = default;

View file

@ -891,12 +891,8 @@ namespace MWClass
float Creature::getSwimSpeed(const MWWorld::Ptr& ptr) const float Creature::getSwimSpeed(const MWWorld::Ptr& ptr) const
{ {
const MWMechanics::CreatureStats& stats = getCreatureStats(ptr); const MWMechanics::CreatureStats& stats = getCreatureStats(ptr);
const GMST& gmst = getGmst();
const MWMechanics::MagicEffects& mageffects = stats.getMagicEffects(); const MWMechanics::MagicEffects& mageffects = stats.getMagicEffects();
return getWalkSpeed(ptr) return getSwimSpeedImpl(ptr, getGmst(), mageffects, getWalkSpeed(ptr));
* (1.0f + 0.01f * mageffects.get(ESM::MagicEffect::SwiftSwim).getMagnitude())
* (gmst.fSwimRunBase->mValue.getFloat()
+ 0.01f * getSkill(ptr, ESM::Skill::Athletics) * gmst.fSwimRunAthleticsMult->mValue.getFloat());
} }
} }

View file

@ -1476,7 +1476,6 @@ namespace MWClass
float Npc::getSwimSpeed(const MWWorld::Ptr& ptr) const float Npc::getSwimSpeed(const MWWorld::Ptr& ptr) const
{ {
const GMST& gmst = getGmst();
const MWBase::World* world = MWBase::Environment::get().getWorld(); const MWBase::World* world = MWBase::Environment::get().getWorld();
const MWMechanics::CreatureStats& stats = getCreatureStats(ptr); const MWMechanics::CreatureStats& stats = getCreatureStats(ptr);
const NpcCustomData* npcdata = static_cast<const NpcCustomData*>(ptr.getRefData().getCustomData()); const NpcCustomData* npcdata = static_cast<const NpcCustomData*>(ptr.getRefData().getCustomData());
@ -1486,17 +1485,6 @@ namespace MWClass
const bool running = stats.getStance(MWMechanics::CreatureStats::Stance_Run) const bool running = stats.getStance(MWMechanics::CreatureStats::Stance_Run)
&& (inair || MWBase::Environment::get().getMechanicsManager()->isRunning(ptr)); && (inair || MWBase::Environment::get().getMechanicsManager()->isRunning(ptr));
float swimSpeed; return getSwimSpeedImpl(ptr, getGmst(), mageffects, running ? getRunSpeed(ptr) : getWalkSpeed(ptr));
if (running)
swimSpeed = getRunSpeed(ptr);
else
swimSpeed = getWalkSpeed(ptr);
swimSpeed *= 1.0f + 0.01f * mageffects.get(ESM::MagicEffect::SwiftSwim).getMagnitude();
swimSpeed *= gmst.fSwimRunBase->mValue.getFloat()
+ 0.01f * getSkill(ptr, ESM::Skill::Athletics) * gmst.fSwimRunAthleticsMult->mValue.getFloat();
return swimSpeed;
} }
} }