Browse Source

vcmi: add PERCENT_TO_SOURCE value type

This will adds percent only to bonuses with same source.
In theory it should allow us to create specials which affects only
secondary skills, or only artifacts (let's say, swordmaster special
- any attack bonus from artifact is doubled).
Konstantin 2 years ago
parent
commit
98218adea5
2 changed files with 14 additions and 2 deletions
  1. 12 2
      lib/HeroBonus.cpp
  2. 2 0
      lib/HeroBonus.h

+ 12 - 2
lib/HeroBonus.cpp

@@ -452,6 +452,7 @@ void BonusList::stackBonuses()
 
 int BonusList::totalValue() const
 {
+	std::array <std::pair<int, int>, Bonus::BonusSource::NUM_BONUS_SOURCE> sources = {};
 	int base = 0;
 	int percentToBase = 0;
 	int percentToAll = 0;
@@ -460,13 +461,14 @@ int BonusList::totalValue() const
 	bool hasIndepMax = false;
 	int indepMin = 0;
 	bool hasIndepMin = false;
+	int modifiedBase = 0;
 
 	for(std::shared_ptr<Bonus> b : bonuses)
 	{
 		switch(b->valType)
 		{
 		case Bonus::BASE_NUMBER:
-			base += b->val;
+			sources[b->source].first += b->val;
 			break;
 		case Bonus::PERCENT_TO_ALL:
 			percentToAll += b->val;
@@ -474,6 +476,9 @@ int BonusList::totalValue() const
 		case Bonus::PERCENT_TO_BASE:
 			percentToBase += b->val;
 			break;
+		case Bonus::PERCENT_TO_SOURCE:
+			sources[b->source].second += b->val;
+			break;
 		case Bonus::ADDITIVE_VALUE:
 			additive += b->val;
 			break;
@@ -501,7 +506,12 @@ int BonusList::totalValue() const
 			break;
 		}
 	}
-	int modifiedBase = base + (base * percentToBase) / 100;
+	for(auto src : sources)
+	{
+		base += src.first;
+		modifiedBase += src.first + (src.first * src.second) / 100;
+	}
+	modifiedBase += (base * percentToBase) / 100;
 	modifiedBase += additive;
 	int valFirst = (modifiedBase * (100 + percentToAll)) / 100;
 

+ 2 - 0
lib/HeroBonus.h

@@ -364,6 +364,7 @@ public:
 	BONUS_VALUE(BASE_NUMBER)\
 	BONUS_VALUE(PERCENT_TO_ALL)\
 	BONUS_VALUE(PERCENT_TO_BASE)\
+	BONUS_VALUE(PERCENT_TO_SOURCE) /*Adds value only to bonuses with same source*/\
 	BONUS_VALUE(INDEPENDENT_MAX) /*used for SPELL bonus */\
 	BONUS_VALUE(INDEPENDENT_MIN) //used for SECONDARY_SKILL_PREMY bonus
 
@@ -396,6 +397,7 @@ struct DLL_LINKAGE Bonus : public std::enable_shared_from_this<Bonus>
 #define BONUS_SOURCE(x) x,
 		BONUS_SOURCE_LIST
 #undef BONUS_SOURCE
+		NUM_BONUS_SOURCE /*This is a dummy value, which will be always last*/
 	};
 
 	enum LimitEffect