From 6942699fb629519b4ffd0c28407867c10d45c3c8 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sat, 30 Nov 2024 06:35:44 +0200
Subject: [PATCH 72/72] AI: Pass civ_map to look_for_charge()

See RM #1171

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

diff --git a/ai/default/daimilitary.c b/ai/default/daimilitary.c
index 39d1f937f2..2d636f9fdd 100644
--- a/ai/default/daimilitary.c
+++ b/ai/default/daimilitary.c
@@ -1715,6 +1715,7 @@ cleanup:
   if want is 0 this advisor doesn't want anything
 **************************************************************************/
 static void dai_unit_consider_bodyguard(struct ai_type *ait,
+                                        const struct civ_map *nmap,
                                         struct city *pcity,
                                         struct unit_type *punittype,
                                         struct adv_choice *choice)
@@ -1727,7 +1728,7 @@ static void dai_unit_consider_bodyguard(struct ai_type *ait,
       = unit_virtual_create(pplayer, pcity, punittype,
                             city_production_unit_veteran_level(pcity,
                                                                punittype));
-    const adv_want want = look_for_charge(ait, pplayer, virtualunit,
+    const adv_want want = look_for_charge(ait, nmap, pplayer, virtualunit,
                                           &aunit, &acity);
 
     if (want > choice->want) {
@@ -1988,7 +1989,7 @@ struct adv_choice *military_advisor_choose_build(struct ai_type *ait,
   punittype = dai_choose_bodyguard(ait, nmap, pcity, TC_LAND, L_DEFEND_GOOD,
                                    allow_gold_upkeep);
   if (punittype) {
-    dai_unit_consider_bodyguard(ait, pcity, punittype, choice);
+    dai_unit_consider_bodyguard(ait, nmap, pcity, punittype, choice);
   }
 
   /* If we are in severe danger, don't consider attackers. This is probably
@@ -2009,7 +2010,7 @@ struct adv_choice *military_advisor_choose_build(struct ai_type *ait,
   punittype = dai_choose_bodyguard(ait, nmap, pcity, TC_OCEAN, L_DEFEND_GOOD,
                                    allow_gold_upkeep);
   if (punittype) {
-    dai_unit_consider_bodyguard(ait, pcity, punittype, choice);
+    dai_unit_consider_bodyguard(ait, nmap, pcity, punittype, choice);
   }
 
   /* Consider making an airplane */
diff --git a/ai/default/daiunit.c b/ai/default/daiunit.c
index be0a19e636..f15c2cac55 100644
--- a/ai/default/daiunit.c
+++ b/ai/default/daiunit.c
@@ -712,8 +712,8 @@ static bool unit_role_defender(const struct unit_type *punittype)
   do we attempt to bodyguard units with higher defense than us, or military
   units with lower attack than us that are not transports.
 **************************************************************************/
-adv_want look_for_charge(struct ai_type *ait, struct player *pplayer,
-                         struct unit *punit,
+adv_want look_for_charge(struct ai_type *ait, const struct civ_map *nmap,
+                         struct player *pplayer, struct unit *punit,
                          struct unit **aunit, struct city **acity)
 {
   struct pf_parameter parameter;
@@ -724,7 +724,6 @@ adv_want look_for_charge(struct ai_type *ait, struct player *pplayer,
   int def, best_def = -1;
   /* Arbitrary: 3 turns. */
   const int max_move_cost = 3 * unit_move_rate(punit);
-  const struct civ_map *nmap = &(wld.map);
 
   *aunit = NULL;
   *acity = NULL;
@@ -920,7 +919,7 @@ static void dai_military_findjob(struct ai_type *ait,
     struct city *acity;
     struct unit *aunit;
 
-    look_for_charge(ait, pplayer, punit, &aunit, &acity);
+    look_for_charge(ait, nmap, pplayer, punit, &aunit, &acity);
     if (acity) {
       dai_unit_new_task(ait, punit, AIUNIT_ESCORT, acity->tile);
       aiguard_assign_guard_city(ait, acity, punit);
diff --git a/ai/default/daiunit.h b/ai/default/daiunit.h
index 817e832aa3..0f03750354 100644
--- a/ai/default/daiunit.h
+++ b/ai/default/daiunit.h
@@ -96,8 +96,8 @@ void dai_manage_military(struct ai_type *ait, struct player *pplayer,
 struct city *find_nearest_safe_city(struct unit *punit);
 bool uclass_need_trans_between(struct unit_class *pclass,
                                struct tile *ctile, struct tile *ptile);
-adv_want look_for_charge(struct ai_type *ait, struct player *pplayer,
-                         struct unit *punit,
+adv_want look_for_charge(struct ai_type *ait, const struct civ_map *nmap,
+                         struct player *pplayer, struct unit *punit,
                          struct unit **aunit, struct city **acity);
 bool dai_can_unit_type_follow_unit_type(const struct unit_type *follower,
                                         const struct unit_type *followee,
-- 
2.45.2

