1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00

Merge pull request #3996 from IvanSavenko/retaliation_tweaks

[1.5.2] Retaliation preview tweaks
This commit is contained in:
Ivan Savenko 2024-05-19 15:44:16 +03:00 committed by GitHub
commit d5f32c27b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 39 additions and 26 deletions

View File

@ -83,6 +83,13 @@ std::vector<std::string> BattleConsole::getVisibleText()
auto result = CMessage::breakText(text, pos.w, FONT_SMALL); 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) if(result.size() > 2)
result.resize(2); result.resize(2);
return result; return result;

View File

@ -760,37 +760,43 @@ DamageEstimation CBattleInfoCallback::battleEstimateDamage(const BattleAttackInf
DamageEstimation ret = calculateDmgRange(bai); 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) auto retaliationAttack = bai.reverse();
{ auto state = retaliationAttack.attacker->acquireState();
//FIXME: handle RANGED_RETALIATION state->damage(damage);
*retaliationDmg = DamageEstimation(); retaliationAttack.attacker = state.get();
} if (state->alive())
return calculateDmgRange(retaliationAttack);
else else
{ return DamageEstimation();
//TODO: rewrite using boost::numeric::interval };
//TODO: rewire once more using interval-based fuzzy arithmetic
const auto & estimateRetaliation = [&](int64_t damage) DamageEstimation retaliationMin = estimateRetaliation(ret.damage.min);
{ DamageEstimation retaliationMax = estimateRetaliation(ret.damage.max);
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); retaliationDmg->damage.min = std::min(retaliationMin.damage.min, retaliationMax.damage.min);
DamageEstimation retaliationMax = estimateRetaliation(ret.damage.max); retaliationDmg->damage.max = std::max(retaliationMin.damage.max, retaliationMax.damage.max);
retaliationDmg->damage.min = std::min(retaliationMin.damage.min, retaliationMax.damage.min); retaliationDmg->kills.min = std::min(retaliationMin.kills.min, retaliationMax.kills.min);
retaliationDmg->damage.max = std::max(retaliationMin.damage.max, retaliationMax.damage.max); 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; return ret;
} }