From d626baf34541fd65a351e0f573465adf7553ead7 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Fri, 15 Nov 2024 20:23:00 +0200
Subject: [PATCH 76/76] AI: Pass civ_map to dai_process_defender_want()

See RM #1117

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

diff --git a/ai/default/daicity.c b/ai/default/daicity.c
index c8ede15e77..4523b51e93 100644
--- a/ai/default/daicity.c
+++ b/ai/default/daicity.c
@@ -254,6 +254,7 @@ static void dai_city_choose_build(struct ai_type *ait, struct player *pplayer,
   struct adv_choice *newchoice;
   struct adv_data *adv = adv_data_get(pplayer, NULL);
   struct ai_city *city_data = def_ai_city_data(pcity, ait);
+  const struct civ_map *nmap = &(wld.map);
 
   if (has_handicap(pplayer, H_AWAY)
       && !city_built_last_turn(pcity)
@@ -290,7 +291,7 @@ static void dai_city_choose_build(struct ai_type *ait, struct player *pplayer,
       unsigned int our_def = assess_defense_quadratic(ait, pcity);
 
       if (our_def == 0
-          && dai_process_defender_want(ait, pplayer, pcity, 1,
+          && dai_process_defender_want(ait, nmap, pplayer, pcity, 1,
                                        &(city_data->choice), 0)) {
         adv_choice_set_use(&(city_data->choice), "fallback defender");
         CITY_LOG(LOG_DEBUG, pcity, "Building fallback defender");
diff --git a/ai/default/daimilitary.c b/ai/default/daimilitary.c
index 6c92549777..3bf2d7fa7a 100644
--- a/ai/default/daimilitary.c
+++ b/ai/default/daimilitary.c
@@ -1057,7 +1057,8 @@ static adv_want dai_unit_attack_desirability(struct ai_type *ait,
   type in choice. Also sets the technology want for the units we can't
   build yet.
 **************************************************************************/
-bool dai_process_defender_want(struct ai_type *ait, struct player *pplayer,
+bool dai_process_defender_want(struct ai_type *ait, const struct civ_map *nmap,
+                               struct player *pplayer,
                                struct city *pcity, unsigned int danger,
                                struct adv_choice *choice, adv_want extra_want)
 {
@@ -1076,7 +1077,6 @@ bool dai_process_defender_want(struct ai_type *ait, struct player *pplayer,
   struct ai_city *city_data = def_ai_city_data(pcity, ait);
   struct ai_plr *plr_data = def_ai_player_data(pplayer, ait);
   adv_want total_want = danger + extra_want;
-  const struct civ_map *nmap = &(wld.map);
 
   memset(tech_desire, 0, sizeof(tech_desire));
 
@@ -1865,7 +1865,7 @@ struct adv_choice *military_advisor_choose_build(struct ai_type *ait,
     if (our_def == 0 && danger > 0) {
       /* Build defensive unit first! Walls will help nothing if there's
        * nobody behind them. */
-      if (dai_process_defender_want(ait, pplayer, pcity, danger, choice,
+      if (dai_process_defender_want(ait, nmap, pplayer, pcity, danger, choice,
                                     martial_value)) {
         choice->want = DAI_WANT_BELOW_MIL_EMERGENCY + danger;
         adv_choice_set_use(choice, "first defender");
@@ -1926,8 +1926,8 @@ struct adv_choice *military_advisor_choose_build(struct ai_type *ait,
         adv_init_choice(&uchoice);
 
         /* Consider building defensive units */
-        if (dai_process_defender_want(ait, pplayer, pcity, danger, &uchoice,
-                                      martial_value)) {
+        if (dai_process_defender_want(ait, nmap, pplayer, pcity, danger,
+                                      &uchoice, martial_value)) {
           /* Potential defender found */
           if (urgency == 0
               && uchoice.value.utype->defense_strength == 1) {
diff --git a/ai/default/daimilitary.h b/ai/default/daimilitary.h
index 16a63289eb..c53abb8fd3 100644
--- a/ai/default/daimilitary.h
+++ b/ai/default/daimilitary.h
@@ -46,7 +46,8 @@ int assess_defense_quadratic(struct ai_type *ait, struct city *pcity);
 int assess_defense_unit(struct ai_type *ait, struct city *pcity,
                         struct unit *punit, bool igwall);
 int assess_defense(struct ai_type *ait, struct city *pcity);
-bool dai_process_defender_want(struct ai_type *ait, struct player *pplayer,
+bool dai_process_defender_want(struct ai_type *ait, const struct civ_map *nmap,
+                               struct player *pplayer,
                                struct city *pcity, unsigned int danger,
                                struct adv_choice *choice, adv_want extra_want);
 
-- 
2.45.2

