From fc07c7cebfb10439d3b8a298f7e2809ca7ef9a35 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Thu, 1 Feb 2024 05:24:02 +0200
Subject: [PATCH 36/36] Unhardcode wld.map from pft_fill_reverse_parameter()

See RM #220

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 common/aicore/path_finding.c | 10 +++++-----
 common/aicore/path_finding.h |  4 ++--
 common/aicore/pf_tools.c     |  5 +++--
 common/aicore/pf_tools.h     |  3 ++-
 4 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/common/aicore/path_finding.c b/common/aicore/path_finding.c
index 04c63535eb..cdd2399d42 100644
--- a/common/aicore/path_finding.c
+++ b/common/aicore/path_finding.c
@@ -3688,7 +3688,7 @@ static void pf_reverse_map_destroy_param(struct pf_parameter *param)
 struct pf_reverse_map *pf_reverse_map_new(const struct player *pplayer,
                                           struct tile *target_tile,
                                           int max_turns, bool omniscient,
-                                          const struct civ_map *map)
+                                          const struct civ_map *nmap)
 {
   struct pf_reverse_map *pfrm = fc_malloc(sizeof(struct pf_reverse_map));
   struct pf_parameter *param = &pfrm->template;
@@ -3697,10 +3697,10 @@ struct pf_reverse_map *pf_reverse_map_new(const struct player *pplayer,
   pfrm->max_turns = max_turns;
 
   /* Initialize the parameter. */
-  pft_fill_reverse_parameter(param, target_tile);
+  pft_fill_reverse_parameter(nmap, param, target_tile);
   param->owner = pplayer;
   param->omniscience = omniscient;
-  param->map = map;
+  param->map = nmap;
 
   /* Initialize the map hash. */
   pfrm->hash = pf_pos_hash_new();
@@ -3715,10 +3715,10 @@ struct pf_reverse_map *pf_reverse_map_new(const struct player *pplayer,
 struct pf_reverse_map *pf_reverse_map_new_for_city(const struct city *pcity,
                                                    const struct player *attacker,
                                                    int max_turns, bool omniscient,
-                                                   const struct civ_map *map)
+                                                   const struct civ_map *nmap)
 {
   return pf_reverse_map_new(attacker, city_tile(pcity), max_turns, omniscient,
-                            map);
+                            nmap);
 }
 
 /************************************************************************//**
diff --git a/common/aicore/path_finding.h b/common/aicore/path_finding.h
index 42fb89718f..914cda1f1c 100644
--- a/common/aicore/path_finding.h
+++ b/common/aicore/path_finding.h
@@ -526,12 +526,12 @@ void pf_path_print_real(const struct pf_path *path, enum log_level level,
 struct pf_reverse_map *pf_reverse_map_new(const struct player *pplayer,
                                           struct tile *start_tile,
                                           int max_turns, bool omniscient,
-                                          const struct civ_map *map)
+                                          const struct civ_map *nmap)
                        fc__warn_unused_result;
 struct pf_reverse_map *pf_reverse_map_new_for_city(const struct city *pcity,
                                                    const struct player *attacker,
                                                    int max_turns, bool omniscient,
-                                                   const struct civ_map *map)
+                                                   const struct civ_map *nmap)
                        fc__warn_unused_result;
 void pf_reverse_map_destroy(struct pf_reverse_map *prfm);
 
diff --git a/common/aicore/pf_tools.c b/common/aicore/pf_tools.c
index 6ca898bf3c..b15f718852 100644
--- a/common/aicore/pf_tools.c
+++ b/common/aicore/pf_tools.c
@@ -961,12 +961,13 @@ void pft_fill_unit_attack_param(struct pf_parameter *parameter,
 /************************************************************************//**
   Fill default parameters for reverse map.
 ****************************************************************************/
-void pft_fill_reverse_parameter(struct pf_parameter *parameter,
+void pft_fill_reverse_parameter(const struct civ_map *nmap,
+                                struct pf_parameter *parameter,
                                 struct tile *target_tile)
 {
   memset(parameter, 0, sizeof(*parameter));
 
-  parameter->map = &(wld.map);
+  parameter->map = nmap;
 
   /* We ignore refuel bases in reverse mode. */
   parameter->fuel = 1;
diff --git a/common/aicore/pf_tools.h b/common/aicore/pf_tools.h
index 3d2508d3ac..06baa5a9eb 100644
--- a/common/aicore/pf_tools.h
+++ b/common/aicore/pf_tools.h
@@ -68,7 +68,8 @@ void pft_fill_utype_attack_param(struct pf_parameter *parameter,
                                  const struct unit_type *punittype,
                                  struct tile *pstart_tile,
                                  struct player *pplayer);
-void pft_fill_reverse_parameter(struct pf_parameter *parameter,
+void pft_fill_reverse_parameter(const struct civ_map *nmap,
+                                struct pf_parameter *parameter,
                                 struct tile *target_tile);
 
 void pft_fill_amphibious_parameter(struct pft_amphibious *parameter);
-- 
2.43.0

