From 85d8e093df56d4986a8c856db279c7b29307aa52 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Fri, 17 May 2024 12:22:21 +0000 Subject: [PATCH 1/2] Battle console: attempt to re-split string if it is too long to fit into two lines due to line break --- client/battle/BattleInterfaceClasses.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/client/battle/BattleInterfaceClasses.cpp b/client/battle/BattleInterfaceClasses.cpp index 1891f3f08..27de34ff3 100644 --- a/client/battle/BattleInterfaceClasses.cpp +++ b/client/battle/BattleInterfaceClasses.cpp @@ -83,6 +83,13 @@ std::vector BattleConsole::getVisibleText() auto result = CMessage::breakText(text, pos.w, FONT_SMALL); + if(result.size() > 2 && text.find('\n') != std::string::npos) + { + // Text has too many lines to fit into console, but has line breaks. Try ignore them and fit text that way + std::string cleanText = boost::algorithm::replace_all_copy(text, "\n", " "); + result = CMessage::breakText(cleanText, pos.w, FONT_SMALL); + } + if(result.size() > 2) result.resize(2); return result; From 7f9df2ef6f59c408d4bc089972735e887db201f6 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Fri, 17 May 2024 12:23:51 +0000 Subject: [PATCH 2/2] Tweaks to retaliation damage calculation: - method now uses early returns to avoid deeply nested if's - assume that retaliation damage is zero if target will die from attack - account for BLOCKS_RETALIATION bonus when computing whether target will retaliate --- lib/battle/CBattleInfoCallback.cpp | 58 ++++++++++++++++-------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/lib/battle/CBattleInfoCallback.cpp b/lib/battle/CBattleInfoCallback.cpp index 15cd933c9..c5f578412 100644 --- a/lib/battle/CBattleInfoCallback.cpp +++ b/lib/battle/CBattleInfoCallback.cpp @@ -760,37 +760,43 @@ DamageEstimation CBattleInfoCallback::battleEstimateDamage(const BattleAttackInf DamageEstimation ret = calculateDmgRange(bai); - if(retaliationDmg && bai.defender->ableToRetaliate()) + if(retaliationDmg == nullptr) + return ret; + + *retaliationDmg = DamageEstimation(); + + if(bai.shooting) //FIXME: handle RANGED_RETALIATION + return ret; + + if (!bai.defender->ableToRetaliate()) + return ret; + + if (bai.attacker->hasBonusOfType(BonusType::BLOCKS_RETALIATION)) + return ret; + + //TODO: rewrite using boost::numeric::interval + //TODO: rewire once more using interval-based fuzzy arithmetic + + const auto & estimateRetaliation = [&](int64_t damage) { - if(bai.shooting) - { - //FIXME: handle RANGED_RETALIATION - *retaliationDmg = DamageEstimation(); - } + auto retaliationAttack = bai.reverse(); + auto state = retaliationAttack.attacker->acquireState(); + state->damage(damage); + retaliationAttack.attacker = state.get(); + if (state->alive()) + return calculateDmgRange(retaliationAttack); else - { - //TODO: rewrite using boost::numeric::interval - //TODO: rewire once more using interval-based fuzzy arithmetic + return DamageEstimation(); + }; - const auto & estimateRetaliation = [&](int64_t damage) - { - auto retaliationAttack = bai.reverse(); - auto state = retaliationAttack.attacker->acquireState(); - state->damage(damage); - retaliationAttack.attacker = state.get(); - return calculateDmgRange(retaliationAttack); - }; + DamageEstimation retaliationMin = estimateRetaliation(ret.damage.min); + DamageEstimation retaliationMax = estimateRetaliation(ret.damage.max); - DamageEstimation retaliationMin = estimateRetaliation(ret.damage.min); - DamageEstimation retaliationMax = estimateRetaliation(ret.damage.max); + retaliationDmg->damage.min = std::min(retaliationMin.damage.min, retaliationMax.damage.min); + retaliationDmg->damage.max = std::max(retaliationMin.damage.max, retaliationMax.damage.max); - retaliationDmg->damage.min = std::min(retaliationMin.damage.min, retaliationMax.damage.min); - retaliationDmg->damage.max = std::max(retaliationMin.damage.max, retaliationMax.damage.max); - - retaliationDmg->kills.min = std::min(retaliationMin.kills.min, retaliationMax.kills.min); - retaliationDmg->kills.max = std::max(retaliationMin.kills.max, retaliationMax.kills.max); - } - } + retaliationDmg->kills.min = std::min(retaliationMin.kills.min, retaliationMax.kills.min); + retaliationDmg->kills.max = std::max(retaliationMin.kills.max, retaliationMax.kills.max); return ret; }