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:
@ -32,12 +32,9 @@ bool INativeTerrainProvider::isNativeTerrain(TerrainId terrain) const
|
|||||||
|
|
||||||
TerrainId AFactionMember::getNativeTerrain() 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
|
//this code is used in the CreatureTerrainLimiter::limit to setup battle bonuses
|
||||||
//and in the CGHeroInstance::getNativeTerrain() to setup movement bonuses or/and penalties.
|
//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();
|
? TerrainId::ANY_TERRAIN : getFactionID().toEntity(VLC)->getNativeTerrain();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,20 +47,12 @@ int32_t AFactionMember::magicResistance() const
|
|||||||
|
|
||||||
int AFactionMember::getAttack(bool ranged) const
|
int AFactionMember::getAttack(bool ranged) const
|
||||||
{
|
{
|
||||||
const std::string cachingStr = "type_PRIMARY_SKILLs_ATTACK";
|
return getBonusBearer()->valOfBonuses(BonusType::PRIMARY_SKILL, BonusSubtypeID(PrimarySkill::ATTACK));
|
||||||
|
|
||||||
static const auto selector = Selector::typeSubtype(BonusType::PRIMARY_SKILL, BonusSubtypeID(PrimarySkill::ATTACK));
|
|
||||||
|
|
||||||
return getBonusBearer()->valOfBonuses(selector, cachingStr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int AFactionMember::getDefense(bool ranged) const
|
int AFactionMember::getDefense(bool ranged) const
|
||||||
{
|
{
|
||||||
const std::string cachingStr = "type_PRIMARY_SKILLs_DEFENSE";
|
return getBonusBearer()->valOfBonuses(BonusType::PRIMARY_SKILL, BonusSubtypeID(PrimarySkill::DEFENSE));
|
||||||
|
|
||||||
static const auto selector = Selector::typeSubtype(BonusType::PRIMARY_SKILL, BonusSubtypeID(PrimarySkill::DEFENSE));
|
|
||||||
|
|
||||||
return getBonusBearer()->valOfBonuses(selector, cachingStr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int AFactionMember::getMinDamage(bool ranged) const
|
int AFactionMember::getMinDamage(bool ranged) const
|
||||||
@ -82,9 +71,7 @@ int AFactionMember::getMaxDamage(bool ranged) const
|
|||||||
|
|
||||||
int AFactionMember::getPrimSkillLevel(PrimarySkill id) const
|
int AFactionMember::getPrimSkillLevel(PrimarySkill id) const
|
||||||
{
|
{
|
||||||
static const CSelector selectorAllSkills = Selector::type()(BonusType::PRIMARY_SKILL);
|
auto allSkills = getBonusBearer()->getBonusesOfType(BonusType::PRIMARY_SKILL);
|
||||||
static const std::string keyAllSkills = "type_PRIMARY_SKILL";
|
|
||||||
auto allSkills = getBonusBearer()->getBonuses(selectorAllSkills, keyAllSkills);
|
|
||||||
int ret = allSkills->valOfBonuses(Selector::subtype()(BonusSubtypeID(id)));
|
int ret = allSkills->valOfBonuses(Selector::subtype()(BonusSubtypeID(id)));
|
||||||
int minSkillValue = VLC->engineSettings()->getVectorValue(EGameSettings::HEROES_MINIMAL_PRIMARY_SKILLS, id.getNum());
|
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
|
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
|
ui32 ACreature::getMaxHealth() const
|
||||||
{
|
{
|
||||||
const std::string cachingStr = "type_STACK_HEALTH";
|
auto value = getBonusBearer()->valOfBonuses(BonusType::STACK_HEALTH);
|
||||||
static const auto selector = Selector::type()(BonusType::STACK_HEALTH);
|
|
||||||
auto value = getBonusBearer()->valOfBonuses(selector, cachingStr);
|
|
||||||
return std::max(1, value); //never 0
|
return std::max(1, value); //never 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -640,10 +640,10 @@ bool CUnitState::canMove(int turn) const
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (turn == 0)
|
if (turn == 0)
|
||||||
return valOfBonuses(BonusType::NOT_ACTIVE);
|
return !hasBonusOfType(BonusType::NOT_ACTIVE);
|
||||||
|
|
||||||
std::string cachingStr = "type_NOT_ACTIVE_turns_" + std::to_string(turn);
|
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
|
bool CUnitState::defended(int turn) const
|
||||||
|
@ -158,7 +158,7 @@ int CTotalsProxy::getMeleeValue() const
|
|||||||
|
|
||||||
if(treeVersion != meleeCachedLast)
|
if(treeVersion != meleeCachedLast)
|
||||||
{
|
{
|
||||||
auto bonuses = target->getBonuses(selector, limit, "CTotalsProxy::getMeleeValue");
|
auto bonuses = target->getBonuses(selector, limit);
|
||||||
meleeValue = initialValue + bonuses->totalValue();
|
meleeValue = initialValue + bonuses->totalValue();
|
||||||
meleeCachedLast = treeVersion;
|
meleeCachedLast = treeVersion;
|
||||||
}
|
}
|
||||||
@ -174,7 +174,7 @@ int CTotalsProxy::getRangedValue() const
|
|||||||
|
|
||||||
if(treeVersion != rangedCachedLast)
|
if(treeVersion != rangedCachedLast)
|
||||||
{
|
{
|
||||||
auto bonuses = target->getBonuses(selector, limit, "CTotalsProxy::getRangedValue");
|
auto bonuses = target->getBonuses(selector, limit);
|
||||||
rangedValue = initialValue + bonuses->totalValue();
|
rangedValue = initialValue + bonuses->totalValue();
|
||||||
rangedCachedLast = treeVersion;
|
rangedCachedLast = treeVersion;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user