浏览代码

Fixes issue of bonuses not correctly removed

Tomasz Zieliński 1 年之前
父节点
当前提交
04691c851f
共有 3 个文件被更改,包括 21 次插入3 次删除
  1. 3 0
      lib/bonuses/Bonus.cpp
  2. 14 2
      lib/bonuses/CBonusSystemNode.cpp
  3. 4 1
      lib/mapObjects/CGTownInstance.cpp

+ 3 - 0
lib/bonuses/Bonus.cpp

@@ -147,6 +147,9 @@ std::string Bonus::Description(std::optional<si32> 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();

+ 14 - 2
lib/bonuses/CBonusSystemNode.cpp

@@ -414,8 +414,20 @@ void CBonusSystemNode::unpropagateBonus(const std::shared_ptr<Bonus> & 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;

+ 4 - 1
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)