1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-15 01:24:45 +02:00

Few more fixes to bonus caching

This commit is contained in:
Ivan Savenko
2024-12-22 13:27:40 +00:00
parent 2ebf37beb0
commit 5caf12f22f
3 changed files with 9 additions and 24 deletions

View File

@ -32,12 +32,9 @@ bool INativeTerrainProvider::isNativeTerrain(TerrainId terrain) const
TerrainId AFactionMember::getNativeTerrain() const
{
const std::string cachingStringNoTerrainPenalty = "type_TERRAIN_NATIVE_NONE";
static const auto selectorNoTerrainPenalty = Selector::typeSubtype(BonusType::TERRAIN_NATIVE, BonusSubtypeID());
//this code is used in the CreatureTerrainLimiter::limit to setup battle bonuses
//and in the CGHeroInstance::getNativeTerrain() to setup movement bonuses or/and penalties.
return getBonusBearer()->hasBonus(selectorNoTerrainPenalty, cachingStringNoTerrainPenalty)
return getBonusBearer()->hasBonusOfType(BonusType::TERRAIN_NATIVE)
? TerrainId::ANY_TERRAIN : getFactionID().toEntity(VLC)->getNativeTerrain();
}
@ -50,20 +47,12 @@ int32_t AFactionMember::magicResistance() const
int AFactionMember::getAttack(bool ranged) const
{
const std::string cachingStr = "type_PRIMARY_SKILLs_ATTACK";
static const auto selector = Selector::typeSubtype(BonusType::PRIMARY_SKILL, BonusSubtypeID(PrimarySkill::ATTACK));
return getBonusBearer()->valOfBonuses(selector, cachingStr);
return getBonusBearer()->valOfBonuses(BonusType::PRIMARY_SKILL, BonusSubtypeID(PrimarySkill::ATTACK));
}
int AFactionMember::getDefense(bool ranged) const
{
const std::string cachingStr = "type_PRIMARY_SKILLs_DEFENSE";
static const auto selector = Selector::typeSubtype(BonusType::PRIMARY_SKILL, BonusSubtypeID(PrimarySkill::DEFENSE));
return getBonusBearer()->valOfBonuses(selector, cachingStr);
return getBonusBearer()->valOfBonuses(BonusType::PRIMARY_SKILL, BonusSubtypeID(PrimarySkill::DEFENSE));
}
int AFactionMember::getMinDamage(bool ranged) const
@ -82,9 +71,7 @@ int AFactionMember::getMaxDamage(bool ranged) const
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 allSkills = getBonusBearer()->getBonusesOfType(BonusType::PRIMARY_SKILL);
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
@ -157,9 +144,7 @@ int AFactionMember::luckVal() const
ui32 ACreature::getMaxHealth() const
{
const std::string cachingStr = "type_STACK_HEALTH";
static const auto selector = Selector::type()(BonusType::STACK_HEALTH);
auto value = getBonusBearer()->valOfBonuses(selector, cachingStr);
auto value = getBonusBearer()->valOfBonuses(BonusType::STACK_HEALTH);
return std::max(1, value); //never 0
}

View File

@ -640,10 +640,10 @@ bool CUnitState::canMove(int turn) const
return false;
if (turn == 0)
return valOfBonuses(BonusType::NOT_ACTIVE);
return !hasBonusOfType(BonusType::NOT_ACTIVE);
std::string cachingStr = "type_NOT_ACTIVE_turns_" + std::to_string(turn);
return valOfBonuses(Selector::type()(BonusType::NOT_ACTIVE).And(Selector::turns(turn)), cachingStr); //eg. Ammo Cart or blinded creature
return !hasBonus(Selector::type()(BonusType::NOT_ACTIVE).And(Selector::turns(turn)), cachingStr); //eg. Ammo Cart or blinded creature
}
bool CUnitState::defended(int turn) const

View File

@ -158,7 +158,7 @@ int CTotalsProxy::getMeleeValue() const
if(treeVersion != meleeCachedLast)
{
auto bonuses = target->getBonuses(selector, limit, "CTotalsProxy::getMeleeValue");
auto bonuses = target->getBonuses(selector, limit);
meleeValue = initialValue + bonuses->totalValue();
meleeCachedLast = treeVersion;
}
@ -174,7 +174,7 @@ int CTotalsProxy::getRangedValue() const
if(treeVersion != rangedCachedLast)
{
auto bonuses = target->getBonuses(selector, limit, "CTotalsProxy::getRangedValue");
auto bonuses = target->getBonuses(selector, limit);
rangedValue = initialValue + bonuses->totalValue();
rangedCachedLast = treeVersion;
}