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

Compute creature speed only once during evaluation

This commit is contained in:
Ivan Savenko 2023-11-18 19:41:29 +02:00
parent a3f9450d83
commit 9b8145f522

View File

@ -890,11 +890,12 @@ bool BattleExchangeEvaluator::checkPositionBlocksOurStacks(HypotheticBattle & hb
auto ratio = blockedUnitDamage / (blockedUnitDamage + activeUnitDamage); auto ratio = blockedUnitDamage / (blockedUnitDamage + activeUnitDamage);
auto unitReachability = turnBattle.getReachability(unit); auto unitReachability = turnBattle.getReachability(unit);
auto unitSpeed = unit->speed(turn); // Cached value, to avoid performance hit
for(BattleHex hex = BattleHex::TOP_LEFT; hex.isValid(); hex = hex + 1) for(BattleHex hex = BattleHex::TOP_LEFT; hex.isValid(); hex = hex + 1)
{ {
bool enemyUnit = false; bool enemyUnit = false;
bool reachable = unitReachability.distances[hex] <= unit->speed(turn); bool reachable = unitReachability.distances[hex] <= unitSpeed;
if(!reachable && unitReachability.accessibility[hex] == EAccessibility::ALIVE_STACK) if(!reachable && unitReachability.accessibility[hex] == EAccessibility::ALIVE_STACK)
{ {
@ -906,7 +907,7 @@ bool BattleExchangeEvaluator::checkPositionBlocksOurStacks(HypotheticBattle & hb
for(BattleHex neighbor : hex.neighbouringTiles()) for(BattleHex neighbor : hex.neighbouringTiles())
{ {
reachable = unitReachability.distances[neighbor] <= unit->speed(turn); reachable = unitReachability.distances[neighbor] <= unitSpeed;
if(reachable) break; if(reachable) break;
} }