1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-23 22:37:55 +02:00

Use bonus system cache whenever possible

This commit is contained in:
Ivan Savenko
2024-12-21 18:47:11 +00:00
parent e2e5fce3b5
commit 95a07ee5cb
21 changed files with 123 additions and 89 deletions

View File

@@ -43,7 +43,7 @@ TerrainId AFactionMember::getNativeTerrain() const
int32_t AFactionMember::magicResistance() const
{
si32 val = getBonusBearer()->valOfBonuses(Selector::type()(BonusType::MAGIC_RESISTANCE));
si32 val = getBonusBearer()->valOfBonuses(BonusType::MAGIC_RESISTANCE);
vstd::amin (val, 100);
return val;
}
@@ -114,9 +114,7 @@ int AFactionMember::moraleValAndBonusList(TConstBonusListPtr & bonusList) const
return 0;
}
static const auto moraleSelector = Selector::type()(BonusType::MORALE);
static const std::string cachingStrMor = "type_MORALE";
bonusList = getBonusBearer()->getBonuses(moraleSelector, cachingStrMor);
bonusList = getBonusBearer()->getBonusesOfType(BonusType::MORALE);
return std::clamp(bonusList->totalValue(), maxBadMorale, maxGoodMorale);
}
@@ -140,9 +138,7 @@ int AFactionMember::luckValAndBonusList(TConstBonusListPtr & bonusList) const
return 0;
}
static const auto luckSelector = Selector::type()(BonusType::LUCK);
static const std::string cachingStrLuck = "type_LUCK";
bonusList = getBonusBearer()->getBonuses(luckSelector, cachingStrLuck);
bonusList = getBonusBearer()->getBonusesOfType(BonusType::LUCK);
return std::clamp(bonusList->totalValue(), maxBadLuck, maxGoodLuck);
}