From b86969909ae4ff071ea98c0574d0513e22daec50 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Sat, 14 Jan 2023 19:03:18 +0200 Subject: [PATCH] Fixes compilation due to changes in callback interface --- AI/BattleAI/AttackPossibility.cpp | 8 ++++--- AI/BattleAI/BattleAI.cpp | 2 +- AI/BattleAI/BattleExchangeVariant.cpp | 6 ++++-- AI/BattleAI/PotentialTargets.cpp | 6 ++---- AI/StupidAI/StupidAI.cpp | 3 ++- cmake_modules/VCMI_lib.cmake | 2 ++ lib/GameConstants.h | 1 + lib/battle/BattleAttackInfo.cpp | 30 +++++++++------------------ lib/battle/BattleAttackInfo.h | 13 ++++++------ server/CGameHandler.cpp | 19 +++++------------ 10 files changed, 39 insertions(+), 51 deletions(-) diff --git a/AI/BattleAI/AttackPossibility.cpp b/AI/BattleAI/AttackPossibility.cpp index 93405b392..d998706ab 100644 --- a/AI/BattleAI/AttackPossibility.cpp +++ b/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); diff --git a/AI/BattleAI/BattleAI.cpp b/AI/BattleAI/BattleAI.cpp index a0ccfb6f9..346452b25 100644 --- a/AI/BattleAI/BattleAI.cpp +++ b/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() ); } diff --git a/AI/BattleAI/BattleExchangeVariant.cpp b/AI/BattleAI/BattleExchangeVariant.cpp index 7d21569c9..c426e2186 100644 --- a/AI/BattleAI/BattleExchangeVariant.cpp +++ b/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 diff --git a/AI/BattleAI/PotentialTargets.cpp b/AI/BattleAI/PotentialTargets.cpp index 8ce7b23c6..8fc3911cf 100644 --- a/AI/BattleAI/PotentialTargets.cpp +++ b/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); }; diff --git a/AI/StupidAI/StupidAI.cpp b/AI/StupidAI/StupidAI.cpp index 4baaa0742..446fbb29c 100644 --- a/AI/StupidAI/StupidAI.cpp +++ b/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((dmg.first + dmg.second) / 2); adr = static_cast((retal.first + retal.second) / 2); } diff --git a/cmake_modules/VCMI_lib.cmake b/cmake_modules/VCMI_lib.cmake index 4399502d0..869080564 100644 --- a/cmake_modules/VCMI_lib.cmake +++ b/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 diff --git a/lib/GameConstants.h b/lib/GameConstants.h index 24e0a09d4..c6c8aa27e 100644 --- a/lib/GameConstants.h +++ b/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, diff --git a/lib/battle/BattleAttackInfo.cpp b/lib/battle/BattleAttackInfo.cpp index 1d38d699b..2746dc7cd 100644 --- a/lib/battle/BattleAttackInfo.cpp +++ b/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; } diff --git a/lib/battle/BattleAttackInfo.h b/lib/battle/BattleAttackInfo.h index b24376a30..d221581fb 100644 --- a/lib/battle/BattleAttackInfo.h +++ b/lib/battle/BattleAttackInfo.h @@ -27,13 +27,14 @@ struct DLL_LINKAGE BattleAttackInfo BattleHex attackerPos; BattleHex defenderPos; - bool shooting; - int chargedFields; + int chargeDistance = 0; + bool shooting = false; + bool luckyStrike = false; + bool unluckyStrike = false; + bool deathBlow = false; + bool doubleDamage = false; - double additiveBonus; - double multBonus; - - BattleAttackInfo(const battle::Unit * Attacker, const battle::Unit * Defender, bool Shooting = false); + BattleAttackInfo(const battle::Unit * Attacker, const battle::Unit * Defender, int chargeDistance, bool Shooting); BattleAttackInfo reverse() const; }; diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index b2b82d002..589154c41 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -1224,21 +1224,12 @@ int64_t CGameHandler::applyBattleEffects(BattleAttack & bat, std::shared_ptrunitId(); 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());