From 04691c851f8f5f2809aef0a09ba040025ff66ca7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Zieli=C5=84ski?= Date: Fri, 26 Apr 2024 19:22:20 +0200 Subject: [PATCH 1/2] Fixes issue of bonuses not correctly removed --- lib/bonuses/Bonus.cpp | 3 +++ lib/bonuses/CBonusSystemNode.cpp | 16 ++++++++++++++-- lib/mapObjects/CGTownInstance.cpp | 5 ++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/bonuses/Bonus.cpp b/lib/bonuses/Bonus.cpp index 16ae74ee3..e82b6eb13 100644 --- a/lib/bonuses/Bonus.cpp +++ b/lib/bonuses/Bonus.cpp @@ -147,6 +147,9 @@ std::string Bonus::Description(std::optional customValue) const descriptionHelper.replaceRawString(std::to_string(valueToShow)); else descriptionHelper.replaceRawString("-" + std::to_string(valueToShow)); + + if(type == BonusType::CREATURE_GROWTH_PERCENT) + descriptionHelper.appendRawString(" +" + std::to_string(valueToShow)); } return descriptionHelper.toString(); diff --git a/lib/bonuses/CBonusSystemNode.cpp b/lib/bonuses/CBonusSystemNode.cpp index 3cedf4408..39e09963a 100644 --- a/lib/bonuses/CBonusSystemNode.cpp +++ b/lib/bonuses/CBonusSystemNode.cpp @@ -414,8 +414,20 @@ void CBonusSystemNode::unpropagateBonus(const std::shared_ptr & b) { if(b->propagator->shouldBeAttached(this)) { - bonuses -= b; - logBonus->trace("#$# %s #is no longer propagated to# %s", b->Description(), nodeName()); + if (bonuses -= b) + 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; diff --git a/lib/mapObjects/CGTownInstance.cpp b/lib/mapObjects/CGTownInstance.cpp index 0918cfd69..0c18b5f6f 100644 --- a/lib/mapObjects/CGTownInstance.cpp +++ b/lib/mapObjects/CGTownInstance.cpp @@ -156,7 +156,10 @@ GrowthInfo CGTownInstance::getGrowthInfo(int level) const for(const auto & b : *bonuses2) { const auto growth = b->val * (base + castleBonus) / 100; - ret.entries.emplace_back(growth, b->Description(growth)); + if (growth) + { + ret.entries.emplace_back(growth, b->Description(growth)); + } } //other *-of-legion-like bonuses (%d to growth cumulative with grail) From 914cea5877d55f90d8622d5f8980642fde748295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Zieli=C5=84ski?= Date: Fri, 26 Apr 2024 19:33:26 +0200 Subject: [PATCH 2/2] Tweaks --- lib/bonuses/CBonusSystemNode.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/bonuses/CBonusSystemNode.cpp b/lib/bonuses/CBonusSystemNode.cpp index 39e09963a..2f6d4db0b 100644 --- a/lib/bonuses/CBonusSystemNode.cpp +++ b/lib/bonuses/CBonusSystemNode.cpp @@ -417,9 +417,9 @@ void CBonusSystemNode::unpropagateBonus(const std::shared_ptr & b) if (bonuses -= b) 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()); + logBonus->warn("Attempt to remove #$# %s, which is not propagated to %s", b->Description(), nodeName()); - bonuses.remove_if([this, b](const auto & bonus) + bonuses.remove_if([b](const auto & bonus) { if (bonus->propagationUpdater && bonus->propagationUpdater == b->propagationUpdater) {