Browse Source

Added possibility to add custom components to reward description.
Used to properly display morale/luck rewards since bonuses don't provide
components associated with them.

Ivan Savenko 11 years ago
parent
commit
2c8af871fc
2 changed files with 10 additions and 0 deletions
  1. 7 0
      lib/CObjectWithReward.cpp
  2. 3 0
      lib/CObjectWithReward.h

+ 7 - 0
lib/CObjectWithReward.cpp

@@ -322,6 +322,9 @@ bool CObjectWithReward::wasVisited (const CGHeroInstance * h) const
 
 void CRewardInfo::loadComponents(std::vector<Component> & comps) const
 {
+	for (auto comp : extraComponents)
+		comps.push_back(comp);
+
 	for (size_t i=0; i<resources.size(); i++)
 	{
 		if (resources[i] !=0)
@@ -589,6 +592,10 @@ void CGBonusingObject::initObj()
 	{
 		Bonus b(duration, type, Bonus::OBJECT, value, ID, descrID != 0 ? VLC->generaltexth->advobtxt[descrID] : "");
 		visit.reward.bonuses.push_back(b);
+		if (type == Bonus::MORALE)
+			visit.reward.extraComponents.push_back(Component(Component::MORALE, 0, value, 0));
+		if (type == Bonus::LUCK)
+			visit.reward.extraComponents.push_back(Component(Component::LUCK, 0, value, 0));
 	};
 
 	auto configureBonus = [&](CVisitInfo & visit, Bonus::BonusType type, si32 value, si32 descrID)

+ 3 - 0
lib/CObjectWithReward.h

@@ -93,6 +93,9 @@ public:
 	std::vector<SpellID> spells;
 	std::vector<CStackBasicDescriptor> creatures;
 
+	/// list of components that will be added to reward description. First entry in list will override displayed component
+	std::vector<Component> extraComponents;
+
 	/// Generates list of components that describes reward
 	virtual void loadComponents(std::vector<Component> & comps) const;
 	Component getDisplayedComponent() const;