Fix target-lock V2 crash

This commit is contained in:
2025-05-10 09:01:20 -05:00
parent 070fd2b219
commit 2870d8d561
2 changed files with 6 additions and 1 deletions

View File

@@ -1095,7 +1095,10 @@ void handle_target_mode(eGameMode target_mode, int range, eSpell spell) {
}
if(!enemy_locs_in_range.empty()){
std::vector<location> dest_candidates = points_containing_most(enemy_locs_in_range, enemy_locs_already_seen);
center = closest_point(dest_candidates, loc);
// Center can stay the same if all points with the most monsters exclude any required (already seen) monsters
if(!dest_candidates.empty()){
center = closest_point(dest_candidates, loc);
}
draw_terrain();
}
}

View File

@@ -401,6 +401,8 @@ std::vector<location> points_containing_most(std::vector<location> points, std:
}
}
if(points_seen_from.empty()) return {};
// Sort candidates by how many of the points they see
std::sort(points_seen_from.begin(), points_seen_from.end(), [](std::pair<location,int> pair1, std::pair<location,int> pair2) -> bool {
return pair1.second > pair2.second;