mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-15 01:24:45 +02:00
Address various issues pointed out by reviewers
This commit is contained in:
@ -9,7 +9,9 @@
|
|||||||
*/
|
*/
|
||||||
#include "StdInc.h"
|
#include "StdInc.h"
|
||||||
#include "AttackPossibility.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)
|
AttackPossibility::AttackPossibility(BattleHex from, BattleHex dest, const BattleAttackInfo & attack)
|
||||||
: from(from), dest(dest), attack(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
|
// check how much damage we gain from blocking enemy shooters on this hex
|
||||||
bestAp.shootersBlockedDmg = evaluateBlockedShootersDmg(attackInfo, hex, state);
|
bestAp.shootersBlockedDmg = evaluateBlockedShootersDmg(attackInfo, hex, state);
|
||||||
|
|
||||||
logAi->debug("BattleAI best AP: %s -> %s at %d from %d, affects %d units: %d %d %d %s",
|
logAi->debug("BattleAI best AP: %s -> %s at %d from %d, affects %d units: %lld %lld %lld %lld",
|
||||||
VLC->creh->creatures.at(attackInfo.attacker->acquireState()->creatureId())->identifier.c_str(),
|
attackInfo.attacker->unitType()->identifier,
|
||||||
VLC->creh->creatures.at(attackInfo.defender->acquireState()->creatureId())->identifier.c_str(),
|
attackInfo.defender->unitType()->identifier,
|
||||||
(int)bestAp.dest, (int)bestAp.from, (int)bestAp.affectedUnits.size(),
|
(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)
|
//TODO other damage related to attack (eg. fire shield and other abilities)
|
||||||
return bestAp;
|
return bestAp;
|
||||||
|
@ -18,7 +18,9 @@
|
|||||||
#include "../../lib/CThreadHelper.h"
|
#include "../../lib/CThreadHelper.h"
|
||||||
#include "../../lib/spells/CSpellHandler.h"
|
#include "../../lib/spells/CSpellHandler.h"
|
||||||
#include "../../lib/spells/ISpellMechanics.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 LOGL(text) print(text)
|
||||||
#define LOGFL(text, formattingEl) print(boost::str(boost::format(text) % formattingEl))
|
#define LOGFL(text, formattingEl) print(boost::str(boost::format(text) % formattingEl))
|
||||||
@ -167,12 +169,12 @@ BattleAction CBattleAI::activeStack( const CStack * stack )
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto &target = bestAttack;
|
auto &target = bestAttack;
|
||||||
logAi->debug("BattleAI: %s -> %s %d from, %d curpos %d dist %d speed %d: %d %d %d",
|
logAi->debug("BattleAI: %s -> %s %d from, %d curpos %d dist %d speed %d: %lld %lld %lld",
|
||||||
VLC->creh->creatures.at(target.attackerState->creatureId())->identifier,
|
target.attackerState->unitType()->identifier,
|
||||||
VLC->creh->creatures.at(target.affectedUnits[0]->creatureId())->identifier,
|
target.affectedUnits[0]->unitType()->identifier,
|
||||||
(int)target.affectedUnits.size(), (int)target.from, (int)bestAttack.attack.attacker->getPosition().hex,
|
(int)target.affectedUnits.size(), (int)target.from, (int)bestAttack.attack.attacker->getPosition().hex,
|
||||||
(int)bestAttack.attack.chargedFields, (int)bestAttack.attack.attacker->Speed(0, true),
|
bestAttack.attack.chargedFields, bestAttack.attack.attacker->Speed(0, true),
|
||||||
(int)target.damageDealt, (int)target.damageReceived, (int)target.attackValue()
|
target.damageDealt, target.damageReceived, target.attackValue()
|
||||||
);
|
);
|
||||||
|
|
||||||
return BattleAction::makeMeleeAttack(stack, bestAttack.attack.defender->getPosition(), bestAttack.from);
|
return BattleAction::makeMeleeAttack(stack, bestAttack.attack.defender->getPosition(), bestAttack.from);
|
||||||
|
@ -84,24 +84,24 @@ PotentialTargets::PotentialTargets(const battle::Unit * attacker, const Hypothet
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::sort(possibleAttacks, [](const AttackPossibility & lhs, const AttackPossibility & rhs) -> bool
|
boost::sort(possibleAttacks, [](const AttackPossibility & lhs, const AttackPossibility & rhs) -> bool
|
||||||
{
|
{
|
||||||
if(lhs.collateralDamage < rhs.collateralDamage)
|
if(lhs.collateralDamage > rhs.collateralDamage)
|
||||||
return false;
|
return false;
|
||||||
if(lhs.collateralDamage > rhs.collateralDamage)
|
if(lhs.collateralDamage < rhs.collateralDamage)
|
||||||
return true;
|
return true;
|
||||||
return (lhs.damageDealt + lhs.shootersBlockedDmg + lhs.damageReceived > rhs.damageDealt + rhs.shootersBlockedDmg + rhs.damageReceived);
|
return (lhs.damageDealt + lhs.shootersBlockedDmg - lhs.damageReceived > rhs.damageDealt + rhs.shootersBlockedDmg - rhs.damageReceived);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!possibleAttacks.empty())
|
if (!possibleAttacks.empty())
|
||||||
{
|
{
|
||||||
auto &bestAp = possibleAttacks[0];
|
auto &bestAp = possibleAttacks[0];
|
||||||
|
|
||||||
logGlobal->info("Battle AI best: %s -> %s at %d from %d, affects %d units: %d %d %d %s",
|
logGlobal->info("Battle AI best: %s -> %s at %d from %d, affects %d units: %lld %lld %lld %lld",
|
||||||
VLC->creh->creatures.at(bestAp.attackerState->creatureId())->identifier.c_str(),
|
bestAp.attack.attacker->unitType()->identifier,
|
||||||
VLC->creh->creatures.at(state->battleGetUnitByPos(bestAp.dest)->creatureId())->identifier.c_str(),
|
state->battleGetUnitByPos(bestAp.dest)->unitType()->identifier,
|
||||||
(int)bestAp.dest, (int)bestAp.from, (int)bestAp.affectedUnits.size(),
|
(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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user