1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-05 00:49:09 +02:00

Added simple damage preview for retaliations

This commit is contained in:
Ivan Savenko
2024-05-10 19:40:33 +00:00
parent ac4204f660
commit d094a17298

View File

@ -114,6 +114,22 @@ static std::string formatRangedAttack(const DamageEstimation & estimation, const
return formatAttack(estimation, creatureName, baseTextID, shotsLeft);
}
static std::string formatRetaliation(const DamageEstimation & estimation, bool mayBeKilled)
{
if (estimation.damage.max == 0)
return CGI->generaltexth->translate("vcmi.battleWindow.damageRetaliation.never");
std::string baseTextID = estimation.kills.max == 0 ?
"vcmi.battleWindow.damageRetaliation.damage" :
"vcmi.battleWindow.damageRetaliation.damageKills";
std::string prefixTextID = mayBeKilled ?
"vcmi.battleWindow.damageRetaliation.will" :
"vcmi.battleWindow.damageRetaliation.may";
return CGI->generaltexth->translate(prefixTextID) + formatAttack(estimation, "", baseTextID, 0);
}
BattleActionsController::BattleActionsController(BattleInterface & owner):
owner(owner),
selectedStack(nullptr),
@ -484,21 +500,30 @@ std::string BattleActionsController::actionGetStatusMessage(PossiblePlayerBattle
case PossiblePlayerBattleAction::ATTACK_AND_RETURN: //TODO: allow to disable return
{
BattleHex attackFromHex = owner.fieldController->fromWhichHexAttack(targetHex);
DamageEstimation estimation = owner.getBattle()->battleEstimateDamage(owner.stacksController->getActiveStack(), targetStack, attackFromHex);
DamageEstimation retaliation;
DamageEstimation estimation = owner.getBattle()->battleEstimateDamage(owner.stacksController->getActiveStack(), targetStack, attackFromHex, &retaliation);
estimation.kills.max = std::min<int64_t>(estimation.kills.max, targetStack->getCount());
estimation.kills.min = std::min<int64_t>(estimation.kills.min, targetStack->getCount());
bool enemyMayBeKilled = estimation.kills.max == targetStack->getCount();
return formatMeleeAttack(estimation, targetStack->getName());
return formatMeleeAttack(estimation, targetStack->getName()) + "\n" + formatRetaliation(retaliation, enemyMayBeKilled);
}
case PossiblePlayerBattleAction::SHOOT:
{
const auto * shooter = owner.stacksController->getActiveStack();
DamageEstimation estimation = owner.getBattle()->battleEstimateDamage(shooter, targetStack, shooter->getPosition());
DamageEstimation retaliation;
DamageEstimation estimation = owner.getBattle()->battleEstimateDamage(shooter, targetStack, shooter->getPosition(), &retaliation);
estimation.kills.max = std::min<int64_t>(estimation.kills.max, targetStack->getCount());
estimation.kills.min = std::min<int64_t>(estimation.kills.min, targetStack->getCount());
bool enemyMayBeKilled = estimation.kills.max == targetStack->getCount();
bool mayRetaliate = retaliation.damage.max > 0;
// for ranged attacks only show retaliation info if retaliation actually happens - since most shooters don't retaliate
if (mayRetaliate)
return formatRangedAttack(estimation, targetStack->getName(), shooter->shots.available()) + "\n" + formatRetaliation(retaliation, enemyMayBeKilled);
else
return formatRangedAttack(estimation, targetStack->getName(), shooter->shots.available());
}