From dd5a5a6f9f6168ee97ebcd6c01cca96d6eee256f Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sun, 25 May 2025 20:24:47 +0300
Subject: [PATCH 73/73] AI: Pass civ_map to find_something_to_kill()

See RM #1240

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 ai/default/daimilitary.c |  2 +-
 ai/default/daiunit.c     | 23 ++++++++++++-----------
 ai/default/daiunit.h     |  3 ++-
 3 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/ai/default/daimilitary.c b/ai/default/daimilitary.c
index ea3dd08341..b8aa631a83 100644
--- a/ai/default/daimilitary.c
+++ b/ai/default/daimilitary.c
@@ -1559,7 +1559,7 @@ static struct adv_choice *kill_something_with(struct ai_type *ait,
     goto cleanup;
   }
 
-  best_choice->want = find_something_to_kill(ait, pplayer, myunit, &ptile, NULL,
+  best_choice->want = find_something_to_kill(ait, nmap, pplayer, myunit, &ptile, NULL,
                                              &ferry_map, &ferryboat,
                                              &boattype, &move_time);
   if (NULL == ptile
diff --git a/ai/default/daiunit.c b/ai/default/daiunit.c
index b389a7dce2..6e8392ac6a 100644
--- a/ai/default/daiunit.c
+++ b/ai/default/daiunit.c
@@ -101,8 +101,8 @@ static void dai_military_findjob(struct ai_type *ait, const struct civ_map *nmap
                                  struct player *pplayer, struct unit *punit);
 static void dai_military_defend(struct ai_type *ait, struct player *pplayer,
                                 struct unit *punit);
-static void dai_military_attack(struct ai_type *ait, struct player *pplayer,
-                                struct unit *punit);
+static void dai_military_attack(struct ai_type *ait, const struct civ_map *nmap,
+                                struct player *pplayer, struct unit *punit);
 
 static bool unit_role_defender(const struct unit_type *punittype);
 static int unit_def_rating_squared(const struct unit *punit,
@@ -243,7 +243,7 @@ static bool has_defense(struct city *pcity)
   the denom, so that def=1 units are penalized correctly."
 
   Translation (GB): build_cost_balanced is used in the denominator of
-  the want equation (see, e.g.  find_something_to_kill) instead of
+  the want equation (see, e.g. find_something_to_kill() ) instead of
   just build_cost to make AI build more balanced units (with def > 1).
 **************************************************************************/
 int build_cost_balanced(const struct unit_type *punittype)
@@ -1141,7 +1141,8 @@ bool find_beachhead(const struct player *pplayer, struct pf_map *ferry_map,
 
   punit->id == 0 means that the unit is virtual (considered to be built).
 **************************************************************************/
-adv_want find_something_to_kill(struct ai_type *ait, struct player *pplayer,
+adv_want find_something_to_kill(struct ai_type *ait, const struct civ_map *nmap,
+                                struct player *pplayer,
                                 struct unit *punit,
                                 struct tile **pdest_tile, struct pf_path **ppath,
                                 struct pf_map **pferrymap,
@@ -1182,7 +1183,6 @@ adv_want find_something_to_kill(struct ai_type *ait, struct player *pplayer,
   adv_want best = 0;    /* Best of all wants. */
   struct tile *goto_dest_tile = nullptr;
   bool can_occupy;
-  struct civ_map *nmap = &(wld.map);
 
   /* Very preliminary checks. */
   *pdest_tile = punit_tile;
@@ -1755,8 +1755,8 @@ static void dai_military_attack_barbarian(struct ai_type *ait,
   looking for trouble elsewhere. If there is nothing to kill, sailing units
   go home, others explore while barbs go berserk.
 **************************************************************************/
-static void dai_military_attack(struct ai_type *ait, struct player *pplayer,
-                                struct unit *punit)
+static void dai_military_attack(struct ai_type *ait, const struct civ_map *nmap,
+                                struct player *pplayer, struct unit *punit)
 {
   struct tile *dest_tile;
   int id = punit->id;
@@ -1794,7 +1794,7 @@ static void dai_military_attack(struct ai_type *ait, struct player *pplayer,
     struct unit *ferryboat;
 
     /* Then find enemies the hard way */
-    find_something_to_kill(ait, pplayer, punit, &dest_tile, &path,
+    find_something_to_kill(ait, nmap, pplayer, punit, &dest_tile, &path,
                            nullptr, &ferryboat, nullptr, nullptr);
     if (!same_pos(unit_tile(punit), dest_tile)) {
       if (!is_tiles_adjacent(unit_tile(punit), dest_tile)
@@ -2440,6 +2440,7 @@ static void dai_manage_caravan(struct ai_type *ait, struct player *pplayer,
   If something is attacking our city, kill it yeahhh!!!.
 **************************************************************************/
 static void dai_manage_hitpoint_recovery(struct ai_type *ait,
+                                         const struct civ_map *nmap,
                                          struct unit *punit)
 {
   struct player *pplayer = unit_owner(punit);
@@ -2480,7 +2481,7 @@ static void dai_manage_hitpoint_recovery(struct ai_type *ait,
       /* Oops */
       UNIT_LOG(LOGLEVEL_RECOVERY, punit, "didn't find a city to recover in!");
       dai_unit_new_task(ait, punit, AIUNIT_NONE, nullptr);
-      dai_military_attack(ait, pplayer, punit);
+      dai_military_attack(ait, nmap, pplayer, punit);
       return;
     }
   }
@@ -2587,7 +2588,7 @@ void dai_manage_military(struct ai_type *ait, const struct civ_map *nmap,
   case AIUNIT_ATTACK:
   case AIUNIT_NONE:
     TIMING_LOG(AIT_ATTACK, TIMER_START);
-    dai_military_attack(ait, pplayer, punit);
+    dai_military_attack(ait, nmap, pplayer, punit);
     TIMING_LOG(AIT_ATTACK, TIMER_STOP);
     break;
   case AIUNIT_ESCORT:
@@ -2611,7 +2612,7 @@ void dai_manage_military(struct ai_type *ait, const struct civ_map *nmap,
     break;
   case AIUNIT_RECOVER:
     TIMING_LOG(AIT_RECOVER, TIMER_START);
-    dai_manage_hitpoint_recovery(ait, punit);
+    dai_manage_hitpoint_recovery(ait, nmap, punit);
     TIMING_LOG(AIT_RECOVER, TIMER_STOP);
     break;
   case AIUNIT_HUNTER:
diff --git a/ai/default/daiunit.h b/ai/default/daiunit.h
index 27a74adc23..4afe4dfeed 100644
--- a/ai/default/daiunit.h
+++ b/ai/default/daiunit.h
@@ -109,7 +109,8 @@ bool find_beachhead(const struct player *pplayer, struct pf_map *ferry_map,
                     const struct unit_type *cargo_type,
                     const struct unit_type *ferry_type,
                     struct tile **ferry_dest, struct tile **beachhead_tile);
-adv_want find_something_to_kill(struct ai_type *ait, struct player *pplayer,
+adv_want find_something_to_kill(struct ai_type *ait, const struct civ_map *nmap,
+                                struct player *pplayer,
                                 struct unit *punit,
                                 struct tile **pdest_tile,
                                 struct pf_path **ppath,
-- 
2.47.2

