Bläddra i källkod

Compute creature speed only once during evaluation

Ivan Savenko 1 år sedan
förälder
incheckning
9b8145f522
1 ändrade filer med 3 tillägg och 2 borttagningar
  1. 3 2
      AI/BattleAI/BattleExchangeVariant.cpp

+ 3 - 2
AI/BattleAI/BattleExchangeVariant.cpp

@@ -890,11 +890,12 @@ bool BattleExchangeEvaluator::checkPositionBlocksOurStacks(HypotheticBattle & hb
 			auto ratio = blockedUnitDamage / (blockedUnitDamage + activeUnitDamage);
 
 			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)
 			{
 				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)
 				{
@@ -906,7 +907,7 @@ bool BattleExchangeEvaluator::checkPositionBlocksOurStacks(HypotheticBattle & hb
 
 						for(BattleHex neighbor : hex.neighbouringTiles())
 						{
-							reachable = unitReachability.distances[neighbor] <= unit->speed(turn);
+							reachable = unitReachability.distances[neighbor] <= unitSpeed;
 
 							if(reachable) break;
 						}