Переглянути джерело

Support for creature damage bonus.

TODO: display it in a creature window
DjWarmonger 15 роки тому
батько
коміт
695c862638
5 змінених файлів з 28 додано та 10 видалено
  1. 5 5
      AI/GeniusAI/BattleLogic.cpp
  2. 10 3
      hch/CObjectHandler.cpp
  3. 9 0
      lib/CCreatureSet.cpp
  4. 2 0
      lib/CCreatureSet.h
  5. 2 2
      lib/CGameState.cpp

+ 5 - 5
AI/GeniusAI/BattleLogic.cpp

@@ -133,8 +133,8 @@ void CBattleLogic::MakeStatistics(int currentCreatureId)
 			// make stats
 			int hitPoints = st->count * stackHP - (stackHP - st->firstHPleft);
 
-			m_statMaxDamage.push_back(std::pair<int, int>(id, st->type->damageMax * st->count));
-			m_statMinDamage.push_back(std::pair<int, int>(id, st->type->damageMin * st->count));
+			m_statMaxDamage.push_back(std::pair<int, int>(id, st->getMaxDamage() * st->count));
+			m_statMinDamage.push_back(std::pair<int, int>(id, st->getMinDamage() * st->count));
 			m_statHitPoints.push_back(std::pair<int, int>(id, hitPoints));
 			m_statMaxSpeed.push_back(std::pair<int, int>(id, stackHP));
 
@@ -175,13 +175,13 @@ void CBattleLogic::MakeStatistics(int currentCreatureId)
 				}
 			}
 
-			cs.damage_max = (int)(currentStack->type->damageMax * currentStack->count * damageFactor);
+			cs.damage_max = (int)(currentStack->getMaxDamage() * currentStack->count * damageFactor);
 			if (cs.damage_max > hitPoints)
 			{
 				cs.damage_max = hitPoints;
 			}
 
-			cs.damage_min = (int)(currentStack->type->damageMin * currentStack->count * damageFactor);
+			cs.damage_min = (int)(currentStack->getMinDamage() * currentStack->count * damageFactor);
 			if (cs.damage_min > hitPoints)
 			{
 				cs.damage_min = hitPoints;
@@ -217,7 +217,7 @@ void CBattleLogic::MakeStatistics(int currentCreatureId)
 			}
 			int hitPoints = st->count * stackHP - (stackHP - st->firstHPleft);
 
-			totalDamage += (st->type->damageMax + st->type->damageMin) * st->count / 2;
+			totalDamage += (st->getMaxDamage() + st->getMinDamage()) * st->count / 2;
 			totalHitPoints += hitPoints;
 		}
 	}

+ 10 - 3
hch/CObjectHandler.cpp

@@ -1109,13 +1109,20 @@ void CGHeroInstance::initObj()
 			case 13://Dragon bonuses (Mutare)
 				bonus.type = Bonus::PRIMARY_SKILL;
 				bonus.valType = Bonus::ADDITIVE_VALUE;
-				bonus.additionalInfo = it->additionalinfo; //id
-				bonus.subtype = it->subtype; //which stat it is
+				switch (it->subtype)
+				{
+					case 1:
+						bonus.subtype = PrimarySkill::ATTACK;
+						break;
+					case 2:
+						bonus.subtype = PrimarySkill::DEFENSE;
+						break;
+				}
 				for (std::vector<CCreature*>::iterator i = VLC->creh->creatures.begin(); i != VLC->creh->creatures.end(); i++)
 				{ //TODO: what if creature changes type during the game (Dragon Eye Ring?)
 					if ((*i)->hasBonusOfType(Bonus::DRAGON_NATURE)) //TODO: implement it!
 					{
-						bonus.additionalInfo = (*i)->idNumber; //for each Dragon separately
+						bonus.limiter = new CCreatureTypeLimiter (**i, false);
 						speciality.bonuses.push_back (bonus);
 					}
 				}

+ 9 - 0
lib/CCreatureSet.cpp

@@ -276,4 +276,13 @@ void CStackInstance::getParents(TCNodes &out, const CBonusSystemNode *source /*=
 		out.insert(armyObj);
 	else
 		out.insert(&IObjectInterface::cb->gameState()->globalEffects);
+}
+
+ui32 CStackInstance::getMinDamage() const
+{
+	return type->damageMin + valOfBonuses(Bonus::CREATURE_DAMAGE, 0) + valOfBonuses(Bonus::CREATURE_DAMAGE, 1);
+}
+ui32 CStackInstance::getMaxDamage() const
+{
+	return type->damageMax + valOfBonuses(Bonus::CREATURE_DAMAGE, 0) + valOfBonuses(Bonus::CREATURE_DAMAGE, 2);
 }

+ 2 - 0
lib/CCreatureSet.h

@@ -25,6 +25,8 @@ public:
 	const CArmedInstance *armyObj; //stack must be part of some army, army must be part of some object
 	const CCreature *type;
 	TQuantity count;
+	ui32 getMinDamage() const;
+	ui32 getMaxDamage() const;
 	ui32 experience; //TODO: handle
 	//TODO: stack artifacts
 

+ 2 - 2
lib/CGameState.cpp

@@ -2495,8 +2495,8 @@ bool CGameState::checkForVisitableDir( const int3 & src, const TerrainTile *pom,
 std::pair<ui32, ui32> BattleInfo::calculateDmgRange( const CStack* attacker, const CStack* defender, const CGHeroInstance * attackerHero, const CGHeroInstance * defendingHero, bool shooting, ui8 charge, bool lucky )
 {
 	float additiveBonus=1.0f, multBonus=1.0f,
-		minDmg = attacker->type->damageMin * attacker->count, 
-		maxDmg = attacker->type->damageMax * attacker->count;
+		minDmg = attacker->getMinDamage() * attacker->count, 
+		maxDmg = attacker->getMaxDamage() * attacker->count;
 
 	if(attacker->type->idNumber == 149) //arrow turret
 	{