mirror of
				https://github.com/TES3MP/openmw-tes3mp.git
				synced 2025-10-31 17:26:42 +00:00 
			
		
		
		
	Issue #324: Added skill gain calculation function
This commit is contained in:
		
							parent
							
								
									10723a149b
								
							
						
					
					
						commit
						0f41cc499d
					
				
					 2 changed files with 79 additions and 0 deletions
				
			
		|  | @ -3,6 +3,15 @@ | |||
| 
 | ||||
| #include <stdexcept> | ||||
| 
 | ||||
| #include <components/esm/loadskil.hpp> | ||||
| #include <components/esm/loadclas.hpp> | ||||
| #include <components/esm/loadgmst.hpp> | ||||
| 
 | ||||
| #include <components/esm_store/store.hpp> | ||||
| 
 | ||||
| #include "../mwbase/environment.hpp" | ||||
| #include "../mwbase/world.hpp" | ||||
| 
 | ||||
| MWMechanics::NpcStats::NpcStats() | ||||
| : mMovementFlags (0), mDrawState (DrawState_Nothing) | ||||
| {} | ||||
|  | @ -55,3 +64,62 @@ const std::map<std::string, int>& 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<int> (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; | ||||
| } | ||||
|  |  | |||
|  | @ -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<std::string, int>& getFactionRanks(); | ||||
| 
 | ||||
|             const std::map<std::string, int>& 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.
 | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue