Browse Source

Fixes compilation due to changes in callback interface

Ivan Savenko 2 years ago
parent
commit
b86969909a

+ 5 - 3
AI/BattleAI/AttackPossibility.cpp

@@ -49,7 +49,8 @@ int64_t AttackPossibility::calculateDamageReduce(
 
 	vstd::amin(damageDealt, defender->getAvailableHealth());
 
-	auto enemyDamageBeforeAttack = cb.battleEstimateDamage(BattleAttackInfo(defender, attacker, defender->canShoot()));
+	// FIXME: provide distance info for Jousting bonus
+	auto enemyDamageBeforeAttack = cb.battleEstimateDamage(defender, attacker, 0);
 	auto enemiesKilled = damageDealt / defender->MaxHealth() + (damageDealt % defender->MaxHealth() >= defender->getFirstHPleft() ? 1 : 0);
 	auto enemyDamage = averageDmg(enemyDamageBeforeAttack);
 	auto damagePerEnemy = enemyDamage / (double)defender->getCount();
@@ -74,10 +75,11 @@ int64_t AttackPossibility::evaluateBlockedShootersDmg(const BattleAttackInfo & a
 		if(!state.battleCanShoot(st))
 			continue;
 
-		BattleAttackInfo rangeAttackInfo(st, attacker, true);
+		// FIXME: provide distance info for Jousting bonus
+		BattleAttackInfo rangeAttackInfo(st, attacker, 0, true);
 		rangeAttackInfo.defenderPos = hex;
 
-		BattleAttackInfo meleeAttackInfo(st, attacker, false);
+		BattleAttackInfo meleeAttackInfo(st, attacker, 0, false);
 		meleeAttackInfo.defenderPos = hex;
 
 		auto rangeDmg = state.battleEstimateDamage(rangeAttackInfo);

+ 1 - 1
AI/BattleAI/BattleAI.cpp

@@ -210,7 +210,7 @@ BattleAction CBattleAI::activeStack( const CStack * stack )
 					bestAttack.attackerState->unitType()->identifier,
 					bestAttack.affectedUnits[0]->unitType()->identifier,
 					(int)bestAttack.affectedUnits[0]->getCount(), action, (int)bestAttack.from, (int)bestAttack.attack.attacker->getPosition().hex,
-					bestAttack.attack.chargedFields, bestAttack.attack.attacker->Speed(0, true),
+					bestAttack.attack.chargeDistance, bestAttack.attack.attacker->Speed(0, true),
 					bestAttack.defenderDamageReduce, bestAttack.attackerDamageReduce, bestAttack.attackValue()
 				);
 			}

+ 4 - 2
AI/BattleAI/BattleExchangeVariant.cpp

@@ -69,7 +69,8 @@ int64_t BattleExchangeVariant::trackAttack(
 	const bool counterAttacksBlocked = attacker->hasBonus(selectorBlocksRetaliation, cachingStringBlocksRetaliation);
 
 	TDmgRange retaliation;
-	BattleAttackInfo bai(attacker.get(), defender.get(), shooting);
+	// FIXME: provide distance info for Jousting bonus
+	BattleAttackInfo bai(attacker.get(), defender.get(), 0, shooting);
 
 	if(shooting)
 	{
@@ -234,7 +235,8 @@ MoveTarget BattleExchangeEvaluator::findMoveTowardsUnreachable(const battle::Uni
 
 		for(auto hex : hexes)
 		{
-			auto bai = BattleAttackInfo(activeStack, closestStack, cb->battleCanShoot(activeStack));
+			// FIXME: provide distance info for Jousting bonus
+			auto bai = BattleAttackInfo(activeStack, closestStack, 0, cb->battleCanShoot(activeStack));
 			auto attack = AttackPossibility::evaluate(bai, hex, hb);
 
 			attack.shootersBlockedDmg = 0; // we do not want to count on it, it is not for sure

+ 2 - 4
AI/BattleAI/PotentialTargets.cpp

@@ -46,10 +46,8 @@ PotentialTargets::PotentialTargets(const battle::Unit * attacker, const Hypothet
 
 		auto GenerateAttackInfo = [&](bool shooting, BattleHex hex) -> AttackPossibility
 		{
-			auto bai = BattleAttackInfo(attackerInfo, defender, shooting);
-
-			if(hex.isValid() && !shooting)
-				bai.chargedFields = reachability.distances[hex];
+			int distance = hex.isValid() ? reachability.distances[hex] : 0;
+			auto bai = BattleAttackInfo(attackerInfo, defender, distance, shooting);
 
 			return AttackPossibility::evaluate(bai, hex, state);
 		};

+ 2 - 1
AI/StupidAI/StupidAI.cpp

@@ -55,7 +55,8 @@ public:
 	{}
 	void calcDmg(const CStack * ourStack)
 	{
-		TDmgRange retal, dmg = cbc->battleEstimateDamage(ourStack, s, &retal);
+		// FIXME: provide distance info for Jousting bonus
+		TDmgRange retal, dmg = cbc->battleEstimateDamage(ourStack, s, 0, &retal);
 		adi = static_cast<int>((dmg.first + dmg.second) / 2);
 		adr = static_cast<int>((retal.first + retal.second) / 2);
 	}

+ 2 - 0
cmake_modules/VCMI_lib.cmake

@@ -19,6 +19,7 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE)
 		${MAIN_LIB_DIR}/battle/CObstacleInstance.cpp
 		${MAIN_LIB_DIR}/battle/CPlayerBattleCallback.cpp
 		${MAIN_LIB_DIR}/battle/CUnitState.cpp
+		${MAIN_LIB_DIR}/battle/DamageCalculator.cpp
 		${MAIN_LIB_DIR}/battle/Destination.cpp
 		${MAIN_LIB_DIR}/battle/IBattleState.cpp
 		${MAIN_LIB_DIR}/battle/ReachabilityInfo.cpp
@@ -253,6 +254,7 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE)
 		${MAIN_LIB_DIR}/battle/CObstacleInstance.h
 		${MAIN_LIB_DIR}/battle/CPlayerBattleCallback.h
 		${MAIN_LIB_DIR}/battle/CUnitState.h
+		${MAIN_LIB_DIR}/battle/DamageCalculator.h
 		${MAIN_LIB_DIR}/battle/Destination.h
 		${MAIN_LIB_DIR}/battle/IBattleInfoCallback.h
 		${MAIN_LIB_DIR}/battle/IBattleState.h

+ 1 - 0
lib/GameConstants.h

@@ -1126,6 +1126,7 @@ public:
 		GOLD_GOLEM = 116,
 		DIAMOND_GOLEM = 117,
 		PSYCHIC_ELEMENTAL = 120,
+		MAGIC_ELEMENTAL = 121,
 		CATAPULT = 145,
 		BALLISTA = 146,
 		FIRST_AID_TENT = 147,

+ 10 - 20
lib/battle/BattleAttackInfo.cpp

@@ -13,31 +13,21 @@
 
 VCMI_LIB_NAMESPACE_BEGIN
 
-BattleAttackInfo::BattleAttackInfo(const battle::Unit * Attacker, const battle::Unit * Defender, bool Shooting)
+BattleAttackInfo::BattleAttackInfo(const battle::Unit * Attacker, const battle::Unit * Defender, int chargeDistance, bool Shooting)
 	: attacker(Attacker),
-	defender(Defender)
-{
-	shooting = Shooting;
-	chargedFields = 0;
-	additiveBonus = 0.0;
-	multBonus = 1.0;
-	attackerPos = BattleHex::INVALID;
-	defenderPos = BattleHex::INVALID;
-}
+	defender(Defender),
+	shooting(Shooting),
+	attackerPos(BattleHex::INVALID),
+	defenderPos(BattleHex::INVALID),
+	chargeDistance(chargeDistance)
+{}
 
 BattleAttackInfo BattleAttackInfo::reverse() const
 {
-	BattleAttackInfo ret = *this;
-
-	std::swap(ret.attacker, ret.defender);
-	std::swap(ret.defenderPos, ret.attackerPos);
-
-	ret.shooting = false;
-	ret.chargedFields = 0;
-
-	ret.additiveBonus = 0.0;
-	ret.multBonus = 1.0;
+	BattleAttackInfo ret(defender, attacker, 0, false);
 
+	ret.defenderPos = attackerPos;
+	ret.attackerPos = defenderPos;
 	return ret;
 }
 

+ 8 - 7
lib/battle/BattleAttackInfo.h

@@ -27,13 +27,14 @@ struct DLL_LINKAGE BattleAttackInfo
 	BattleHex attackerPos;
 	BattleHex defenderPos;
 
-	bool shooting;
-	int chargedFields;
-
-	double additiveBonus;
-	double multBonus;
-
-	BattleAttackInfo(const battle::Unit * Attacker, const battle::Unit * Defender, bool Shooting = false);
+	int chargeDistance = 0;
+	bool shooting      = false;
+	bool luckyStrike   = false;
+	bool unluckyStrike = false;
+	bool deathBlow     = false;
+	bool doubleDamage  = false;
+
+	BattleAttackInfo(const battle::Unit * Attacker, const battle::Unit * Defender, int chargeDistance, bool Shooting);
 	BattleAttackInfo reverse() const;
 };
 

+ 5 - 14
server/CGameHandler.cpp

@@ -1224,21 +1224,12 @@ int64_t CGameHandler::applyBattleEffects(BattleAttack & bat, std::shared_ptr<bat
 	bsa.attackerID = attackerState->unitId();
 	bsa.stackAttacked = def->unitId();
 	{
-		BattleAttackInfo bai(attackerState.get(), def, bat.shot());
-		bai.chargedFields = distance;
+		BattleAttackInfo bai(attackerState.get(), def, distance, bat.shot());
 
-		if(bat.deathBlow())
-			bai.additiveBonus += 1.0;
-
-		if(bat.ballistaDoubleDmg())
-			bai.additiveBonus += 1.0;
-
-		if(bat.lucky())
-			bai.additiveBonus += 1.0;
-
-		//unlucky hit, used only if negative luck is enabled
-		if(bat.unlucky())
-			bai.additiveBonus -= 0.5; // FIXME: how bad (and luck in general) should work with following bonuses?
+		bai.deathBlow = bat.deathBlow();
+		bai.doubleDamage = bat.ballistaDoubleDmg();
+		bai.luckyStrike  = bat.lucky();
+		bai.unluckyStrike  = bat.unlucky();
 
 		auto range = gs->curB->calculateDmgRange(bai);
 		bsa.damageAmount = gs->curB->getActualDamage(range, attackerState->getCount(), getRandomGenerator());