mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-06 09:09:40 +02:00
Refactor BattleHex, remake the use of precomputed neighbouring tiles containers.
- Moved short, frequently used functions to the BattleHex header for inlining - Made BattleHex a class with a private hex value - Moved getClosestTile implementation back to BattleHex - Enabled access to static precomputed data in BattleHexArray via BattleHex (note: circular dependency prevented static precomputed containers being directly placed in BattleHex)
This commit is contained in:
@@ -384,7 +384,7 @@ AttackPossibility AttackPossibility::evaluate(
|
||||
affectedUnits = defenderUnits;
|
||||
vstd::concatenate(affectedUnits, retaliatedUnits);
|
||||
|
||||
logAi->trace("Attacked battle units count %d, %d->%d", affectedUnits.size(), hex.hex, defHex.hex);
|
||||
logAi->trace("Attacked battle units count %d, %d->%d", affectedUnits.size(), hex, defHex);
|
||||
|
||||
std::map<uint32_t, std::shared_ptr<battle::CUnitState>> defenderStates;
|
||||
|
||||
|
||||
@@ -215,7 +215,7 @@ BattleAction BattleEvaluator::selectStackAction(const CStack * stack)
|
||||
bestAttack.affectedUnits[0]->unitType()->getJsonKey(),
|
||||
bestAttack.affectedUnits[0]->getCount(),
|
||||
(int)bestAttack.from,
|
||||
(int)bestAttack.attack.attacker->getPosition().hex,
|
||||
(int)bestAttack.attack.attacker->getPosition(),
|
||||
bestAttack.attack.chargeDistance,
|
||||
bestAttack.attack.attacker->getMovementRange(0),
|
||||
bestAttack.defenderDamageReduce,
|
||||
@@ -252,7 +252,7 @@ BattleAction BattleEvaluator::selectStackAction(const CStack * stack)
|
||||
|
||||
if(siegeDefense)
|
||||
{
|
||||
logAi->trace("Evaluating exchange at %d self-defense", stack->getPosition().hex);
|
||||
logAi->trace("Evaluating exchange at %d self-defense", stack->getPosition());
|
||||
|
||||
BattleAttackInfo bai(stack, stack, 0, false);
|
||||
AttackPossibility apDefend(stack->getPosition(), stack->getPosition(), bai);
|
||||
@@ -286,7 +286,7 @@ BattleAction BattleEvaluator::selectStackAction(const CStack * stack)
|
||||
"Moving %s towards hex %s[%d], score: %2f",
|
||||
stack->getDescription(),
|
||||
moveTarget.cachedAttack->attack.defender->getDescription(),
|
||||
moveTarget.cachedAttack->attack.defender->getPosition().hex,
|
||||
moveTarget.cachedAttack->attack.defender->getPosition(),
|
||||
moveTarget.score);
|
||||
|
||||
return goTowardsNearest(stack, moveTarget.positions, *targets);
|
||||
|
||||
@@ -960,7 +960,7 @@ std::vector<const battle::Unit *> BattleExchangeEvaluator::getOneTurnReachableUn
|
||||
|
||||
if(hexStack && cb->battleMatchOwner(unit, hexStack, false))
|
||||
{
|
||||
for(BattleHex neighbour : BattleHexArray::neighbouringTilesCache[hex.hex])
|
||||
for(BattleHex neighbour : hex.getNeighbouringTiles())
|
||||
{
|
||||
reachable = unitReachability.distances.at(neighbour) <= radius;
|
||||
|
||||
@@ -1021,7 +1021,7 @@ bool BattleExchangeEvaluator::checkPositionBlocksOurStacks(HypotheticBattle & hb
|
||||
if(hexStack && cb->battleMatchOwner(unit, hexStack, false))
|
||||
{
|
||||
enemyUnit = true;
|
||||
for(BattleHex neighbour : BattleHexArray::neighbouringTilesCache[hex.hex])
|
||||
for(BattleHex neighbour : hex.getNeighbouringTiles())
|
||||
{
|
||||
reachable = unitReachability.distances.at(neighbour) <= unitSpeed;
|
||||
|
||||
|
||||
@@ -107,7 +107,8 @@ static bool willSecondHexBlockMoreEnemyShooters(std::shared_ptr<CBattleCallback>
|
||||
|
||||
for(int i = 0; i < 2; i++)
|
||||
{
|
||||
for (auto neighbour : BattleHexArray::neighbouringTilesCache[i ? h2.hex : h1.hex])
|
||||
BattleHex hex = i ? h2 : h1;
|
||||
for (auto neighbour : hex.getNeighbouringTiles())
|
||||
if(const auto * s = cb->getBattle(battleID)->battleGetUnitByPos(neighbour))
|
||||
if(s->isShooter())
|
||||
shooters[i]++;
|
||||
|
||||
Reference in New Issue
Block a user