1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

Address various issues pointed out by reviewers

This commit is contained in:
Victor Luchits 2020-05-09 14:09:32 +03:00
parent 59c39527c5
commit d4cc005882
3 changed files with 30 additions and 26 deletions

View File

@ -9,7 +9,9 @@
*/
#include "StdInc.h"
#include "AttackPossibility.h"
#include "../../lib/CStack.h"//todo: remove
#include "../../lib/CStack.h" // TODO: remove
// Eventually only IBattleInfoCallback and battle::Unit should be used,
// CUnitState should be private and CStack should be removed completely
AttackPossibility::AttackPossibility(BattleHex from, BattleHex dest, const BattleAttackInfo & attack)
: from(from), dest(dest), attack(attack)
@ -179,11 +181,11 @@ AttackPossibility AttackPossibility::evaluate(const BattleAttackInfo & attackInf
// check how much damage we gain from blocking enemy shooters on this hex
bestAp.shootersBlockedDmg = evaluateBlockedShootersDmg(attackInfo, hex, state);
logAi->debug("BattleAI best AP: %s -> %s at %d from %d, affects %d units: %d %d %d %s",
VLC->creh->creatures.at(attackInfo.attacker->acquireState()->creatureId())->identifier.c_str(),
VLC->creh->creatures.at(attackInfo.defender->acquireState()->creatureId())->identifier.c_str(),
logAi->debug("BattleAI best AP: %s -> %s at %d from %d, affects %d units: %lld %lld %lld %lld",
attackInfo.attacker->unitType()->identifier,
attackInfo.defender->unitType()->identifier,
(int)bestAp.dest, (int)bestAp.from, (int)bestAp.affectedUnits.size(),
(int)bestAp.damageDealt, (int)bestAp.damageReceived, (int)bestAp.collateralDamage, (int)bestAp.shootersBlockedDmg);
bestAp.damageDealt, bestAp.damageReceived, bestAp.collateralDamage, bestAp.shootersBlockedDmg);
//TODO other damage related to attack (eg. fire shield and other abilities)
return bestAp;

View File

@ -18,7 +18,9 @@
#include "../../lib/CThreadHelper.h"
#include "../../lib/spells/CSpellHandler.h"
#include "../../lib/spells/ISpellMechanics.h"
#include "../../lib/CStack.h"//todo: remove
#include "../../lib/CStack.h" // TODO: remove
// Eventually only IBattleInfoCallback and battle::Unit should be used,
// CUnitState should be private and CStack should be removed completely
#define LOGL(text) print(text)
#define LOGFL(text, formattingEl) print(boost::str(boost::format(text) % formattingEl))
@ -167,12 +169,12 @@ BattleAction CBattleAI::activeStack( const CStack * stack )
else
{
auto &target = bestAttack;
logAi->debug("BattleAI: %s -> %s %d from, %d curpos %d dist %d speed %d: %d %d %d",
VLC->creh->creatures.at(target.attackerState->creatureId())->identifier,
VLC->creh->creatures.at(target.affectedUnits[0]->creatureId())->identifier,
logAi->debug("BattleAI: %s -> %s %d from, %d curpos %d dist %d speed %d: %lld %lld %lld",
target.attackerState->unitType()->identifier,
target.affectedUnits[0]->unitType()->identifier,
(int)target.affectedUnits.size(), (int)target.from, (int)bestAttack.attack.attacker->getPosition().hex,
(int)bestAttack.attack.chargedFields, (int)bestAttack.attack.attacker->Speed(0, true),
(int)target.damageDealt, (int)target.damageReceived, (int)target.attackValue()
bestAttack.attack.chargedFields, bestAttack.attack.attacker->Speed(0, true),
target.damageDealt, target.damageReceived, target.attackValue()
);
return BattleAction::makeMeleeAttack(stack, bestAttack.attack.defender->getPosition(), bestAttack.from);

View File

@ -84,24 +84,24 @@ PotentialTargets::PotentialTargets(const battle::Unit * attacker, const Hypothet
}
}
boost::sort(possibleAttacks, [](const AttackPossibility & lhs, const AttackPossibility & rhs) -> bool
{
if(lhs.collateralDamage < rhs.collateralDamage)
return false;
if(lhs.collateralDamage > rhs.collateralDamage)
return true;
return (lhs.damageDealt + lhs.shootersBlockedDmg + lhs.damageReceived > rhs.damageDealt + rhs.shootersBlockedDmg + rhs.damageReceived);
boost::sort(possibleAttacks, [](const AttackPossibility & lhs, const AttackPossibility & rhs) -> bool
{
if(lhs.collateralDamage > rhs.collateralDamage)
return false;
if(lhs.collateralDamage < rhs.collateralDamage)
return true;
return (lhs.damageDealt + lhs.shootersBlockedDmg - lhs.damageReceived > rhs.damageDealt + rhs.shootersBlockedDmg - rhs.damageReceived);
});
if (!possibleAttacks.empty())
{
auto &bestAp = possibleAttacks[0];
logGlobal->info("Battle AI best: %s -> %s at %d from %d, affects %d units: %d %d %d %s",
VLC->creh->creatures.at(bestAp.attackerState->creatureId())->identifier.c_str(),
VLC->creh->creatures.at(state->battleGetUnitByPos(bestAp.dest)->creatureId())->identifier.c_str(),
(int)bestAp.dest, (int)bestAp.from, (int)bestAp.affectedUnits.size(),
(int)bestAp.damageDealt, (int)bestAp.damageReceived, (int)bestAp.collateralDamage, (int)bestAp.shootersBlockedDmg);
{
auto &bestAp = possibleAttacks[0];
logGlobal->info("Battle AI best: %s -> %s at %d from %d, affects %d units: %lld %lld %lld %lld",
bestAp.attack.attacker->unitType()->identifier,
state->battleGetUnitByPos(bestAp.dest)->unitType()->identifier,
(int)bestAp.dest, (int)bestAp.from, (int)bestAp.affectedUnits.size(),
bestAp.damageDealt, bestAp.damageReceived, bestAp.collateralDamage, bestAp.shootersBlockedDmg);
}
}