From ed297f8b8445af51755064696de66b8e2554cf07 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Mon, 25 Mar 2024 06:09:57 +0200
Subject: [PATCH 57/57] Unhardcode wld.map from caravan_find_best_destination()

See RM #361

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 ai/default/daiunit.c    | 5 +++--
 common/aicore/caravan.c | 5 ++---
 common/aicore/caravan.h | 3 ++-
 3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/ai/default/daiunit.c b/ai/default/daiunit.c
index 0879e44ae1..bf2f8e9ab1 100644
--- a/ai/default/daiunit.c
+++ b/ai/default/daiunit.c
@@ -2387,9 +2387,10 @@ static void dai_manage_caravan(struct ai_type *ait, struct player *pplayer,
       parameter.allow_foreign_trade = FTL_NATIONAL_ONLY;
       parameter.ignore_transit_time = FALSE;
     }
-    caravan_find_best_destination(punit, &parameter, &result, !has_handicap(pplayer, H_MAP));
+    caravan_find_best_destination(nmap, punit, &parameter, &result,
+                                  !has_handicap(pplayer, H_MAP));
     if (result.dest != NULL) {
-      /* we did find a new destination for the unit */
+      /* We did find a new destination for the unit */
       dest = result.dest;
       help_wonder = result.help_wonder;
       required_boat = uclass_need_trans_between(pclass, unit_tile(punit), dest->tile);
diff --git a/common/aicore/caravan.c b/common/aicore/caravan.c
index a14932f324..f118ff7877 100644
--- a/common/aicore/caravan.c
+++ b/common/aicore/caravan.c
@@ -674,12 +674,11 @@ static void caravan_find_best_destination_withtransit(
   Store it in *destout (if destout is non-null); return the value of the
   trade route.
 ****************************************************************************/
-void caravan_find_best_destination(const struct unit *caravan,
+void caravan_find_best_destination(const struct civ_map *nmap,
+                                   const struct unit *caravan,
                                    const struct caravan_parameter *parameter,
                                    struct caravan_result *result, bool omniscient)
 {
-  const struct civ_map *nmap = &(wld.map);
-
   if (parameter->ignore_transit_time) {
     caravan_find_best_destination_notransit(caravan, parameter, result);
   } else {
diff --git a/common/aicore/caravan.h b/common/aicore/caravan.h
index dac3611e5c..1f98a4bd00 100644
--- a/common/aicore/caravan.h
+++ b/common/aicore/caravan.h
@@ -143,7 +143,8 @@ void caravan_result_init_zero(struct caravan_result *result);
 int caravan_result_compare(const struct caravan_result *a,
                            const struct caravan_result *b);
 
-void caravan_find_best_destination(const struct unit *caravan,
+void caravan_find_best_destination(const struct civ_map *nmap,
+                                   const struct unit *caravan,
                                    const struct caravan_parameter *parameter,
                                    struct caravan_result *result, bool omniscient);
 
-- 
2.43.0

