Ver código fonte

Merge pull request #1483 from kambala-decapitator/statue-of-legion-bonus

fix displaying growth bonus from Statue of Legion
Andrey Filipenkov 2 anos atrás
pai
commit
785d565f31
3 arquivos alterados com 16 adições e 14 exclusões
  1. 3 3
      lib/HeroBonus.cpp
  2. 1 1
      lib/HeroBonus.h
  3. 12 10
      lib/mapObjects/CGTownInstance.cpp

+ 3 - 3
lib/HeroBonus.cpp

@@ -1576,7 +1576,7 @@ bool NBonus::hasOfType(const CBonusSystemNode *obj, Bonus::BonusType type, int s
 	return false;
 }
 
-std::string Bonus::Description() const
+std::string Bonus::Description(boost::optional<si32> customValue) const
 {
 	std::ostringstream str;
 
@@ -1615,8 +1615,8 @@ std::string Bonus::Description() const
 		str << description;
 	}
 
-	if(val != 0)
-		str << " " << std::showpos << val;
+	if(auto value = customValue.value_or(val))
+		str << " " << std::showpos << value;
 
 	return str.str();
 }

+ 1 - 1
lib/HeroBonus.h

@@ -510,7 +510,7 @@ struct DLL_LINKAGE Bonus : public std::enable_shared_from_this<Bonus>
 		return (high << 16) + low;
 	}
 
-	std::string Description() const;
+	std::string Description(boost::optional<si32> customValue = {}) const;
 	JsonNode toJsonNode() const;
 	std::string nameForBonus() const; // generate suitable name for bonus - e.g. for storing in json struct
 

+ 12 - 10
lib/mapObjects/CGTownInstance.cpp

@@ -553,24 +553,26 @@ GrowthInfo CGTownInstance::getGrowthInfo(int level) const
 		if(hasBuilt(BuildingID::HORDE_2))
 			ret.entries.push_back(GrowthInfo::Entry(subID, BuildingID::HORDE_2, creature->hordeGrowth));
 
-	int dwellingBonus = 0;
-	if(const PlayerState *p = cb->getPlayerState(tempOwner, false))
+	//statue-of-legion-like bonus: % to base+castle
+	TConstBonusListPtr bonuses2 = getBonuses(Selector::type()(Bonus::CREATURE_GROWTH_PERCENT));
+	for(const auto & b : *bonuses2)
 	{
-		dwellingBonus = getDwellingBonus(creatures[level].second, p->dwellings);
+		const auto growth = b->val * (base + castleBonus) / 100;
+		ret.entries.push_back(GrowthInfo::Entry(growth, b->Description(growth)));
 	}
 
-	if(dwellingBonus)
-		ret.entries.push_back(GrowthInfo::Entry(VLC->generaltexth->allTexts[591], dwellingBonus));// \nExternal dwellings %+d
-
 	//other *-of-legion-like bonuses (%d to growth cumulative with grail)
 	TConstBonusListPtr bonuses = getBonuses(Selector::type()(Bonus::CREATURE_GROWTH).And(Selector::subtype()(level)));
 	for(const auto & b : *bonuses)
 		ret.entries.push_back(GrowthInfo::Entry(b->val, b->Description()));
 
-	//statue-of-legion-like bonus: % to base+castle
-	TConstBonusListPtr bonuses2 = getBonuses(Selector::type()(Bonus::CREATURE_GROWTH_PERCENT));
-	for(const auto & b : *bonuses2)
-		ret.entries.push_back(GrowthInfo::Entry(b->val * (base + castleBonus) / 100, b->Description()));
+	int dwellingBonus = 0;
+	if(const PlayerState *p = cb->getPlayerState(tempOwner, false))
+	{
+		dwellingBonus = getDwellingBonus(creatures[level].second, p->dwellings);
+	}
+	if(dwellingBonus)
+		ret.entries.push_back(GrowthInfo::Entry(VLC->generaltexth->allTexts[591], dwellingBonus));// \nExternal dwellings %+d
 
 	if(hasBuilt(BuildingID::GRAIL)) //grail - +50% to ALL (so far added) growth
 		ret.entries.push_back(GrowthInfo::Entry(subID, BuildingID::GRAIL, ret.totalGrowth() / 2));