diff --git a/apps/openmw/mwmechanics/npcstats.cpp b/apps/openmw/mwmechanics/npcstats.cpp index cdb9770290..6c95c53721 100644 --- a/apps/openmw/mwmechanics/npcstats.cpp +++ b/apps/openmw/mwmechanics/npcstats.cpp @@ -3,6 +3,15 @@ #include +#include +#include +#include + +#include + +#include "../mwbase/environment.hpp" +#include "../mwbase/world.hpp" + MWMechanics::NpcStats::NpcStats() : mMovementFlags (0), mDrawState (DrawState_Nothing) {} @@ -55,3 +64,62 @@ const std::map& MWMechanics::NpcStats::getFactionRanks() const { return mFactionRank; } + +float MWMechanics::NpcStats::getSkillGain (int skillIndex, const ESM::Class& class_, int usageType, + int level) const +{ + if (level<0) + level = static_cast (getSkill (skillIndex).getBase()); + + const ESM::Skill *skill = MWBase::Environment::get().getWorld()->getStore().skills.find (skillIndex); + + float skillFactor = 1; + + if (usageType>=4) + throw std::runtime_error ("skill usage type out of range"); + + if (usageType>0) + { + skillFactor = skill->data.useValue[usageType]; + + if (skillFactor<=0) + throw std::runtime_error ("invalid skill gain factor"); + } + + float typeFactor = + MWBase::Environment::get().getWorld()->getStore().gameSettings.find ("fMiscSkillBonus")->f; + + for (int i=0; i<5; ++i) + if (class_.data.skills[i][0]==skillIndex) + { + typeFactor = + MWBase::Environment::get().getWorld()->getStore().gameSettings.find ("fMinorSkillBonus")->f; + + break; + } + + for (int i=0; i<5; ++i) + if (class_.data.skills[i][1]==skillIndex) + { + typeFactor = + MWBase::Environment::get().getWorld()->getStore().gameSettings.find ("fMajorSkillBonus")->f; + + break; + } + + if (typeFactor<=0) + throw std::runtime_error ("invalid skill type factor"); + + float specialisationFactor = 1; + + if (skill->data.specialization==class_.data.specialization) + { + specialisationFactor = + MWBase::Environment::get().getWorld()->getStore().gameSettings.find ("fSpecialSkillBonus")->f; + + if (specialisationFactor<=0) + throw std::runtime_error ("invalid skill specialisation factor"); + } + + return 1.0 / (level +1) * (1.0 / skillFactor) * typeFactor * specialisationFactor; +} diff --git a/apps/openmw/mwmechanics/npcstats.hpp b/apps/openmw/mwmechanics/npcstats.hpp index 16a777b71a..0264042723 100644 --- a/apps/openmw/mwmechanics/npcstats.hpp +++ b/apps/openmw/mwmechanics/npcstats.hpp @@ -8,6 +8,11 @@ #include "stat.hpp" #include "drawstate.hpp" +namespace ESM +{ + struct Class; +} + namespace MWMechanics { /// \brief Additional stats for NPCs @@ -59,6 +64,12 @@ namespace MWMechanics std::map& getFactionRanks(); const std::map& getFactionRanks() const; + + float getSkillGain (int skillIndex, const ESM::Class& class_, int usageType = -1, + int level = -1) const; + ///< \param usageType: Usage specific factor, specified in the respective skill record; + /// -1: use a factor of 1.0 instead. + /// \param level Level to base calculation on; -1: use current level. }; }