From d588675f502605cfb2dc6b088de283263388229f Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sun, 8 Sep 2024 12:55:12 +0300
Subject: [PATCH 31/31] Unhardcode wld.map from action_speculate_unit_on_city()

See RM #839

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 common/actions.c              | 4 ++--
 common/actions.h              | 3 ++-
 common/aicore/caravan.c       | 7 ++++---
 server/advisors/autoworkers.c | 4 +++-
 4 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/common/actions.c b/common/actions.c
index d9a8939e19..c442eea7e1 100644
--- a/common/actions.c
+++ b/common/actions.c
@@ -4785,7 +4785,8 @@ struct act_prob action_prob_unit_vs_tgt(const struct civ_map *nmap,
   performing the chosen action on the target city given the specified
   game state changes.
 **************************************************************************/
-struct act_prob action_speculate_unit_on_city(const action_id act_id,
+struct act_prob action_speculate_unit_on_city(const struct civ_map *nmap,
+                                              const action_id act_id,
                                               const struct unit *actor,
                                               const struct city *actor_home,
                                               const struct tile *actor_tile,
@@ -4796,7 +4797,6 @@ struct act_prob action_speculate_unit_on_city(const action_id act_id,
    * current position rather than on actor_tile. Maybe this function should
    * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
    * other requirement makes the action ACTPROB_IMPOSSIBLE? */
-  const struct civ_map *nmap = &(wld.map);
 
   if (omniscient_cheat) {
     if (is_action_enabled_unit_on_city_full(nmap, act_id,
diff --git a/common/actions.h b/common/actions.h
index 1c99cfc6b2..25dd7eaad6 100644
--- a/common/actions.h
+++ b/common/actions.h
@@ -592,7 +592,8 @@ struct act_prob action_prob_unit_vs_tgt(const struct civ_map *nmap,
                                         const struct extra_type *sub_tgt);
 
 struct act_prob
-action_speculate_unit_on_city(action_id act_id,
+action_speculate_unit_on_city(const struct civ_map *nmap,
+                              action_id act_id,
                               const struct unit *actor,
                               const struct city *actor_home,
                               const struct tile *actor_tile,
diff --git a/common/aicore/caravan.c b/common/aicore/caravan.c
index 9553156f1e..7c9e6d4f18 100644
--- a/common/aicore/caravan.c
+++ b/common/aicore/caravan.c
@@ -495,6 +495,7 @@ static bool get_discounted_reward(const struct unit *caravan,
   bool consider_trade;
   bool consider_windfall;
   struct goods_type *pgood;
+  const struct civ_map *nmap = &(wld.map);
 
   /* if no foreign trade is allowed, just quit. */
   if (!does_foreign_trade_param_allow(parameter, pplayer_src, pplayer_dest)) {
@@ -504,17 +505,17 @@ static bool get_discounted_reward(const struct unit *caravan,
 
   consider_wonder = parameter->consider_wonders
     && action_prob_possible(
-        action_speculate_unit_on_city(ACTION_HELP_WONDER,
+        action_speculate_unit_on_city(nmap, ACTION_HELP_WONDER,
                                       caravan, src, city_tile(dest),
                                       TRUE, dest));
   consider_trade = parameter->consider_trade
     && action_prob_possible(
-        action_speculate_unit_on_city(ACTION_TRADE_ROUTE,
+        action_speculate_unit_on_city(nmap, ACTION_TRADE_ROUTE,
                                       caravan, src, city_tile(dest),
                                       TRUE, dest));
   consider_windfall = parameter->consider_windfall
     && action_prob_possible(
-        action_speculate_unit_on_city(ACTION_MARKETPLACE,
+        action_speculate_unit_on_city(nmap, ACTION_MARKETPLACE,
                                       caravan, src, city_tile(dest),
                                       TRUE, dest));
 
diff --git a/server/advisors/autoworkers.c b/server/advisors/autoworkers.c
index bed3824eb1..eaf55b635c 100644
--- a/server/advisors/autoworkers.c
+++ b/server/advisors/autoworkers.c
@@ -1296,6 +1296,8 @@ bool auto_workers_speculate_can_act_at(const struct unit *punit,
                                        struct extra_type *target,
                                        const struct tile *ptile)
 {
+  const struct civ_map *nmap = &(wld.map);
+
   action_by_activity_iterate(paction, activity) {
     if (action_get_actor_kind(paction) != AAK_UNIT) {
       /* Not relevant. */
@@ -1305,7 +1307,7 @@ bool auto_workers_speculate_can_act_at(const struct unit *punit,
     switch (action_get_target_kind(paction)) {
     case ATK_CITY:
       return action_prob_possible(action_speculate_unit_on_city(
-                                    paction->id,
+                                    nmap, paction->id,
                                     punit, unit_home(punit), ptile,
                                     omniscient_cheat,
                                     tile_city(ptile)));
-- 
2.45.2

