From cc87c70719b338fdd0942853a28bdb49ac90fd1d Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Wed, 11 Dec 2024 07:27:02 +0200
Subject: [PATCH 53/53] AI: Pass civ_map to dai_manage_military()

See RM #1181

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 ai/default/aiferry.c     |  3 ++-
 ai/default/daiparadrop.c |  2 +-
 ai/default/daiunit.c     | 14 +++++++-------
 ai/default/daiunit.h     |  4 ++--
 4 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/ai/default/aiferry.c b/ai/default/aiferry.c
index 841487b42c..020a559e1c 100644
--- a/ai/default/aiferry.c
+++ b/ai/default/aiferry.c
@@ -1120,6 +1120,7 @@ void dai_manage_ferryboat(struct ai_type *ait, struct player *pplayer,
   struct unit_ai *unit_data;
   int bossid;
   const struct unit_type *ptype;
+  const struct civ_map *nmap = &(wld.map);
 
   CHECK_UNIT(punit);
 
@@ -1249,7 +1250,7 @@ void dai_manage_ferryboat(struct ai_type *ait, struct player *pplayer,
       * -- Syela */
     dai_unit_new_task(ait, punit, AIUNIT_NONE, NULL);
     UNIT_LOG(LOGLEVEL_FERRY, punit, "passing ferry over to attack code");
-    dai_manage_military(ait, pplayer, punit);
+    dai_manage_military(ait, nmap, pplayer, punit);
     return;
   }
 
diff --git a/ai/default/daiparadrop.c b/ai/default/daiparadrop.c
index ba382d9266..5854b0e450 100644
--- a/ai/default/daiparadrop.c
+++ b/ai/default/daiparadrop.c
@@ -297,7 +297,7 @@ void dai_manage_paratrooper(struct ai_type *ait, struct player *pplayer,
     } else {
       UNIT_LOG(LOGLEVEL_PARATROOPER, punit,
 	       "didn't find city to go and recover.");
-      dai_manage_military(ait, pplayer, punit);
+      dai_manage_military(ait, nmap, pplayer, punit);
     }
   }
 }
diff --git a/ai/default/daiunit.c b/ai/default/daiunit.c
index f15c2cac55..baa4749ef3 100644
--- a/ai/default/daiunit.c
+++ b/ai/default/daiunit.c
@@ -98,7 +98,7 @@ static void dai_manage_barbarian_leader(struct ai_type *ait,
                                         struct player *pplayer,
                                         struct unit *leader);
 
-static void dai_military_findjob(struct ai_type *ait,
+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);
@@ -849,12 +849,11 @@ bool dai_can_unit_type_follow_unit_type(const struct unit_type *follower,
 /**********************************************************************//**
   See if we have a specific job for the unit.
 **************************************************************************/
-static void dai_military_findjob(struct ai_type *ait,
+static void dai_military_findjob(struct ai_type *ait, const struct civ_map *nmap,
                                  struct player *pplayer, struct unit *punit)
 {
   const struct unit_type *punittype = unit_type_get(punit);
   struct unit_ai *unit_data;
-  const struct civ_map *nmap = &(wld.map);
 
   CHECK_UNIT(punit);
 
@@ -2501,8 +2500,8 @@ static void dai_manage_hitpoint_recovery(struct ai_type *ait,
   Decide what to do with a military unit. It will be managed once only.
   It is up to the caller to try again if it has moves left.
 **************************************************************************/
-void dai_manage_military(struct ai_type *ait, struct player *pplayer,
-                         struct unit *punit)
+void dai_manage_military(struct ai_type *ait, const struct civ_map *nmap,
+                         struct player *pplayer, struct unit *punit)
 {
   struct unit_ai *unit_data = def_ai_unit_data(punit, ait);
   int id = punit->id;
@@ -2559,7 +2558,7 @@ void dai_manage_military(struct ai_type *ait, struct player *pplayer,
 
   /* Do we have a specific job for this unit? If not, we default
    * to attack. */
-  dai_military_findjob(ait, pplayer, punit);
+  dai_military_findjob(ait, nmap, pplayer, punit);
 
   switch (unit_data->task) {
   case AIUNIT_AUTO_WORKER:
@@ -2663,6 +2662,7 @@ void dai_manage_unit(struct ai_type *ait, struct player *pplayer,
   struct unit *bodyguard = aiguard_guard_of(ait, punit);
   bool is_ferry = FALSE;
   const struct unit_type *ptype;
+  const struct civ_map *nmap = &(wld.map);
 
   CHECK_UNIT(punit);
 
@@ -2740,7 +2740,7 @@ void dai_manage_unit(struct ai_type *ait, struct player *pplayer,
   } else if (!is_special_unit(punit)) {
     TIMING_LOG(AIT_MILITARY, TIMER_START);
     UNIT_LOG(LOG_DEBUG, punit, "recruit unit for the military");
-    dai_manage_military(ait, pplayer, punit); 
+    dai_manage_military(ait, nmap, pplayer, punit);
     TIMING_LOG(AIT_MILITARY, TIMER_STOP);
     return;
   } else {
diff --git a/ai/default/daiunit.h b/ai/default/daiunit.h
index 0f03750354..8150b6d79c 100644
--- a/ai/default/daiunit.h
+++ b/ai/default/daiunit.h
@@ -91,8 +91,8 @@ bool dai_military_rampage(struct unit *punit, int thresh_adj,
 void dai_manage_units(struct ai_type *ait, struct player *pplayer); 
 void dai_manage_unit(struct ai_type *ait, struct player *pplayer,
                      struct unit *punit);
-void dai_manage_military(struct ai_type *ait, struct player *pplayer,
-                         struct unit *punit);
+void dai_manage_military(struct ai_type *ait, const struct civ_map *nmap,
+                         struct player *pplayer, struct unit *punit);
 struct city *find_nearest_safe_city(struct unit *punit);
 bool uclass_need_trans_between(struct unit_class *pclass,
                                struct tile *ctile, struct tile *ptile);
-- 
2.45.2

