1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 18:35:20 +00:00
OpenMW/apps/openmw/mwmechanics/difficultyscaling.cpp
2023-07-03 16:01:48 +00:00

39 lines
1.0 KiB
C++

#include "difficultyscaling.hpp"
#include <components/settings/values.hpp>
#include "../mwbase/environment.hpp"
#include "../mwworld/esmstore.hpp"
#include "../mwworld/ptr.hpp"
#include "actorutil.hpp"
float scaleDamage(float damage, const MWWorld::Ptr& attacker, const MWWorld::Ptr& victim)
{
const MWWorld::Ptr& player = MWMechanics::getPlayer();
static const float fDifficultyMult
= MWBase::Environment::get().getESMStore()->get<ESM::GameSetting>().find("fDifficultyMult")->mValue.getFloat();
const float difficultyTerm = 0.01f * Settings::game().mDifficulty;
float x = 0;
if (victim == player)
{
if (difficultyTerm > 0)
x = fDifficultyMult * difficultyTerm;
else
x = difficultyTerm / fDifficultyMult;
}
else if (attacker == player)
{
if (difficultyTerm > 0)
x = -difficultyTerm / fDifficultyMult;
else
x = fDifficultyMult * (-difficultyTerm);
}
damage *= 1 + x;
return damage;
}