mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-17 01:32:21 +02:00
Initial version of new bonus caching system
This commit is contained in:
@ -293,6 +293,7 @@ CGHeroInstance::CGHeroInstance(IGameCallback * cb)
|
||||
level(1),
|
||||
exp(UNINITIALIZED_EXPERIENCE),
|
||||
gender(EHeroGender::DEFAULT),
|
||||
primarySkills(this),
|
||||
lowestCreatureSpeed(0)
|
||||
{
|
||||
setNodeType(HERO);
|
||||
@ -704,40 +705,20 @@ void CGHeroInstance::setPropertyDer(ObjProperty what, ObjPropertyID identifier)
|
||||
setStackCount(SlotID(0), identifier.getNum());
|
||||
}
|
||||
|
||||
std::array<int, 4> CGHeroInstance::getPrimarySkills() const
|
||||
int CGHeroInstance::getPrimSkillLevel(PrimarySkill id) const
|
||||
{
|
||||
std::array<int, 4> result;
|
||||
|
||||
auto allSkills = getBonusBearer()->getBonusesOfType(BonusType::PRIMARY_SKILL);
|
||||
for (auto skill : PrimarySkill::ALL_SKILLS())
|
||||
{
|
||||
int ret = allSkills->valOfBonuses(Selector::subtype()(BonusSubtypeID(skill)));
|
||||
int minSkillValue = VLC->engineSettings()->getVectorValue(EGameSettings::HEROES_MINIMAL_PRIMARY_SKILLS, skill.getNum());
|
||||
result[skill] = std::max(ret, minSkillValue); //otherwise, some artifacts may cause negative skill value effect
|
||||
}
|
||||
|
||||
return result;
|
||||
return primarySkills.getSkills()[id];
|
||||
}
|
||||
|
||||
double CGHeroInstance::getFightingStrength() const
|
||||
{
|
||||
const auto & primarySkills = getPrimarySkills();
|
||||
return getFightingStrengthImpl(primarySkills);
|
||||
}
|
||||
|
||||
double CGHeroInstance::getFightingStrengthImpl(const std::array<int, 4> & primarySkills) const
|
||||
{
|
||||
return sqrt((1.0 + 0.05*primarySkills[PrimarySkill::ATTACK]) * (1.0 + 0.05*primarySkills[PrimarySkill::DEFENSE]));
|
||||
const auto & skillValues = primarySkills.getSkills();
|
||||
return sqrt((1.0 + 0.05*skillValues[PrimarySkill::ATTACK]) * (1.0 + 0.05*skillValues[PrimarySkill::DEFENSE]));
|
||||
}
|
||||
|
||||
double CGHeroInstance::getMagicStrength() const
|
||||
{
|
||||
const auto & primarySkills = getPrimarySkills();
|
||||
return getMagicStrengthImpl(primarySkills);
|
||||
}
|
||||
|
||||
double CGHeroInstance::getMagicStrengthImpl(const std::array<int, 4> & primarySkills) const
|
||||
{
|
||||
const auto & skillValues = primarySkills.getSkills();
|
||||
if (!hasSpellbook())
|
||||
return 1;
|
||||
bool atLeastOneCombatSpell = false;
|
||||
@ -751,13 +732,12 @@ double CGHeroInstance::getMagicStrengthImpl(const std::array<int, 4> & primarySk
|
||||
}
|
||||
if (!atLeastOneCombatSpell)
|
||||
return 1;
|
||||
return sqrt((1.0 + 0.05*primarySkills[PrimarySkill::KNOWLEDGE] * mana / manaLimit()) * (1.0 + 0.05*primarySkills[PrimarySkill::SPELL_POWER] * mana / manaLimit()));
|
||||
return sqrt((1.0 + 0.05*skillValues[PrimarySkill::KNOWLEDGE] * mana / manaLimit()) * (1.0 + 0.05*skillValues[PrimarySkill::SPELL_POWER] * mana / manaLimit()));
|
||||
}
|
||||
|
||||
double CGHeroInstance::getHeroStrength() const
|
||||
{
|
||||
const auto & primarySkills = getPrimarySkills();
|
||||
return getFightingStrengthImpl(primarySkills) * getMagicStrengthImpl(primarySkills);
|
||||
return getFightingStrength() * getMagicStrength();
|
||||
}
|
||||
|
||||
uint64_t CGHeroInstance::getValueForDiplomacy() const
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "CArmedInstance.h"
|
||||
#include "IOwnableObject.h"
|
||||
|
||||
#include "../bonuses/BonusCache.h"
|
||||
#include "../entities/hero/EHeroGender.h"
|
||||
#include "../CArtHandler.h" // For CArtifactSet
|
||||
|
||||
@ -58,13 +59,12 @@ class DLL_LINKAGE CGHeroInstance : public CArmedInstance, public IBoatGenerator,
|
||||
friend class CMapFormatJson;
|
||||
|
||||
private:
|
||||
PrimarySkillsCache primarySkills;
|
||||
|
||||
std::set<SpellID> spells; //known spells (spell IDs)
|
||||
mutable int lowestCreatureSpeed;
|
||||
ui32 movement; //remaining movement points
|
||||
|
||||
double getFightingStrengthImpl(const std::array<int, 4> & primarySkills) const;
|
||||
double getMagicStrengthImpl(const std::array<int, 4> & primarySkills) const;
|
||||
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@ -204,7 +204,7 @@ public:
|
||||
std::vector<SecondarySkill> getLevelUpProposedSecondarySkills(vstd::RNG & rand) const;
|
||||
|
||||
ui8 getSecSkillLevel(const SecondarySkill & skill) const; //0 - no skill
|
||||
std::array<int, 4> getPrimarySkills() const;
|
||||
int getPrimSkillLevel(PrimarySkill id) const;
|
||||
|
||||
/// Returns true if hero has free secondary skill slot.
|
||||
bool canLearnSkill() const;
|
||||
|
Reference in New Issue
Block a user