1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-03 00:46:55 +02:00

Avoid vector allocation when accessing game settings value

This commit is contained in:
Ivan Savenko
2024-12-18 13:38:38 +00:00
parent 9e2646898b
commit b8a04c6356
5 changed files with 10 additions and 4 deletions

View File

@ -85,8 +85,8 @@ int AFactionMember::getPrimSkillLevel(PrimarySkill id) const
static const CSelector selectorAllSkills = Selector::type()(BonusType::PRIMARY_SKILL);
static const std::string keyAllSkills = "type_PRIMARY_SKILL";
auto allSkills = getBonusBearer()->getBonuses(selectorAllSkills, keyAllSkills);
auto ret = allSkills->valOfBonuses(Selector::subtype()(BonusSubtypeID(id)));
auto minSkillValue = VLC->engineSettings()->getVector(EGameSettings::HEROES_MINIMAL_PRIMARY_SKILLS)[id.getNum()];
int ret = allSkills->valOfBonuses(Selector::subtype()(BonusSubtypeID(id)));
int minSkillValue = VLC->engineSettings()->getVectorValue(EGameSettings::HEROES_MINIMAL_PRIMARY_SKILLS, id.getNum());
return std::max(ret, minSkillValue); //otherwise, some artifacts may cause negative skill value effect, sp=0 works in old saves
}