1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00

Use throwing ::at to prevent undefined behavior

This commit is contained in:
Ivan Savenko 2024-08-15 13:14:51 +00:00
parent fe115c6917
commit d09fb07362
3 changed files with 8 additions and 8 deletions

View File

@ -265,7 +265,7 @@ BattleAction BattleEvaluator::goTowardsNearest(const CStack * stack, std::vector
{
std::sort(targetHexes.begin(), targetHexes.end(), [&](BattleHex h1, BattleHex h2) -> bool
{
return reachability.distances[h1] < reachability.distances[h2];
return reachability.distances.at(h1) < reachability.distances.at(h2);
});
for(auto hex : targetHexes)
@ -283,7 +283,7 @@ BattleAction BattleEvaluator::goTowardsNearest(const CStack * stack, std::vector
}
}
if(reachability.distances[targetHexes.front()] <= GameConstants::BFIELD_SIZE)
if(reachability.distances.at(targetHexes.front()) <= GameConstants::BFIELD_SIZE)
{
break;
}
@ -299,7 +299,7 @@ BattleAction BattleEvaluator::goTowardsNearest(const CStack * stack, std::vector
BattleHex bestNeighbor = targetHexes.front();
if(reachability.distances[bestNeighbor] > GameConstants::BFIELD_SIZE)
if(reachability.distances.at(bestNeighbor) > GameConstants::BFIELD_SIZE)
{
return BattleAction::makeDefend(stack);
}

View File

@ -764,7 +764,7 @@ std::vector<const battle::Unit *> BattleExchangeEvaluator::getOneTurnReachableUn
ReachabilityInfo unitReachability = reachabilityIter != reachabilityCache.end() ? reachabilityIter->second : turnBattle.getReachability(unit);
bool reachable = unitReachability.distances[hex] <= radius;
bool reachable = unitReachability.distances.at(hex) <= radius;
if(!reachable && unitReachability.accessibility[hex] == EAccessibility::ALIVE_STACK)
{
@ -774,7 +774,7 @@ std::vector<const battle::Unit *> BattleExchangeEvaluator::getOneTurnReachableUn
{
for(BattleHex neighbor : hex.neighbouringTiles())
{
reachable = unitReachability.distances[neighbor] <= radius;
reachable = unitReachability.distances.at(neighbor) <= radius;
if(reachable) break;
}
@ -824,7 +824,7 @@ bool BattleExchangeEvaluator::checkPositionBlocksOurStacks(HypotheticBattle & hb
for(BattleHex hex = BattleHex::TOP_LEFT; hex.isValid(); hex = hex + 1)
{
bool enemyUnit = false;
bool reachable = unitReachability.distances[hex] <= unitSpeed;
bool reachable = unitReachability.distances.at(hex) <= unitSpeed;
if(!reachable && unitReachability.accessibility[hex] == EAccessibility::ALIVE_STACK)
{
@ -836,7 +836,7 @@ bool BattleExchangeEvaluator::checkPositionBlocksOurStacks(HypotheticBattle & hb
for(BattleHex neighbor : hex.neighbouringTiles())
{
reachable = unitReachability.distances[neighbor] <= unitSpeed;
reachable = unitReachability.distances.at(neighbor) <= unitSpeed;
if(reachable) break;
}

View File

@ -1035,7 +1035,7 @@ ReachabilityInfo CBattleInfoCallback::makeBFS(const AccessibilityInfo &accessibi
if(isInObstacle(curHex, obstacles, checkParams))
continue;
const int costToNeighbour = ret.distances[curHex.hex] + 1;
const int costToNeighbour = ret.distances.at(curHex.hex) + 1;
for(BattleHex neighbour : BattleHex::neighbouringTilesCache[curHex.hex])
{
if(neighbour.isValid())