From 3d4fbd9515a261ccdba287c8d77d33ba72824dc7 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 18 Jun 2022 11:12:16 +0300 Subject: [PATCH 52/52] player_distance_to_player(): Fix clang analyze div by zero warning See osdn #44856 Signed-off-by: Marko Lindqvist --- common/aicore/aisupport.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/common/aicore/aisupport.c b/common/aicore/aisupport.c index 906795839b..8186d081a9 100644 --- a/common/aicore/aisupport.c +++ b/common/aicore/aisupport.c @@ -69,18 +69,18 @@ struct player *player_leading_spacerace(void) } /*******************************************************************//** - Calculate average distances to other players. We calculate the + Calculate average distances to other players. We calculate the average distance from all of our cities to the closest enemy city. ***********************************************************************/ int player_distance_to_player(struct player *pplayer, struct player *target) { - int cities = 0; + int cities = city_list_size(pplayer->cities); int dists = 0; if (pplayer == target || !target->is_alive || !pplayer->is_alive - || city_list_size(pplayer->cities) == 0 + || cities == 0 || city_list_size(target->cities) == 0) { return 1; } @@ -97,7 +97,6 @@ int player_distance_to_player(struct player *pplayer, struct player *target) } } city_list_iterate_end; dists += min_dist; - cities++; } city_list_iterate_end; return MAX(dists / cities, 1); -- 2.35.1