1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-27 22:49:25 +02:00

Fixes issue of bonuses not correctly removed

This commit is contained in:
Tomasz Zieliński
2024-04-26 19:22:20 +02:00
parent 23fd47ae63
commit 04691c851f
3 changed files with 21 additions and 3 deletions

View File

@@ -147,6 +147,9 @@ std::string Bonus::Description(std::optional<si32> customValue) const
descriptionHelper.replaceRawString(std::to_string(valueToShow)); descriptionHelper.replaceRawString(std::to_string(valueToShow));
else else
descriptionHelper.replaceRawString("-" + std::to_string(valueToShow)); descriptionHelper.replaceRawString("-" + std::to_string(valueToShow));
if(type == BonusType::CREATURE_GROWTH_PERCENT)
descriptionHelper.appendRawString(" +" + std::to_string(valueToShow));
} }
return descriptionHelper.toString(); return descriptionHelper.toString();

View File

@@ -414,8 +414,20 @@ void CBonusSystemNode::unpropagateBonus(const std::shared_ptr<Bonus> & b)
{ {
if(b->propagator->shouldBeAttached(this)) if(b->propagator->shouldBeAttached(this))
{ {
bonuses -= b; if (bonuses -= b)
logBonus->trace("#$# %s #is no longer propagated to# %s", b->Description(), nodeName()); logBonus->trace("#$# %s #is no longer propagated to# %s", b->Description(), nodeName());
else
logBonus->error("Error on unpropagateBonus. #$# %s is not propagated to %s", b->Description(), nodeName());
bonuses.remove_if([this, b](const auto & bonus)
{
if (bonus->propagationUpdater && bonus->propagationUpdater == b->propagationUpdater)
{
treeHasChanged();
return true;
}
return false;
});
} }
TNodes lchildren; TNodes lchildren;

View File

@@ -156,8 +156,11 @@ GrowthInfo CGTownInstance::getGrowthInfo(int level) const
for(const auto & b : *bonuses2) for(const auto & b : *bonuses2)
{ {
const auto growth = b->val * (base + castleBonus) / 100; const auto growth = b->val * (base + castleBonus) / 100;
if (growth)
{
ret.entries.emplace_back(growth, b->Description(growth)); ret.entries.emplace_back(growth, b->Description(growth));
} }
}
//other *-of-legion-like bonuses (%d to growth cumulative with grail) //other *-of-legion-like bonuses (%d to growth cumulative with grail)
// Note: bonus uses 1-based levels (Pikeman is level 1), town list uses 0-based (Pikeman in 0-th creatures entry) // Note: bonus uses 1-based levels (Pikeman is level 1), town list uses 0-based (Pikeman in 0-th creatures entry)