From 36e0e2d495e0ef0ecc96ff009c04a2d90c8ee38a Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Thu, 16 May 2024 02:35:20 +0300
Subject: [PATCH 38/38] Unhardcode wld.map from action_prob_vs_tile()

See RM #622

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 client/control.c     |  3 ++-
 common/actions.c     |  7 +++----
 common/actions.h     |  3 ++-
 common/unit.c        |  2 +-
 server/actiontools.c | 11 +++++++----
 server/cityhand.c    |  3 ++-
 server/unithand.c    |  2 +-
 server/unittools.c   |  2 +-
 8 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/client/control.c b/client/control.c
index 2703556251..f2b67f4270 100644
--- a/client/control.c
+++ b/client/control.c
@@ -1947,7 +1947,8 @@ static void do_disband_alternative(void *p)
     break;
   case ATK_TILE:
     if ((ptile = unit_tile(punit))
-        && action_prob_possible(action_prob_vs_tile(punit, act, ptile, NULL))) {
+        && action_prob_possible(action_prob_vs_tile(nmap, punit, act,
+                                                    ptile, NULL))) {
       request_do_action(act, punit->id, ptile->index, 0, "");
     }
     break;
diff --git a/common/actions.c b/common/actions.c
index b19b56492c..80b6702bda 100644
--- a/common/actions.c
+++ b/common/actions.c
@@ -6221,13 +6221,12 @@ action_prob_vs_tile_full(const struct civ_map *nmap,
   Get the actor unit's probability of successfully performing the chosen
   action on the target tile.
 **************************************************************************/
-struct act_prob action_prob_vs_tile(const struct unit *actor_unit,
+struct act_prob action_prob_vs_tile(const struct civ_map *nmap,
+                                    const struct unit *actor_unit,
                                     const action_id act_id,
                                     const struct tile *target_tile,
                                     const struct extra_type *target_extra)
 {
-  const struct civ_map *nmap = &(wld.map);
-
   return action_prob_vs_tile_full(nmap, actor_unit,
                                   unit_home(actor_unit),
                                   unit_tile(actor_unit),
@@ -6420,7 +6419,7 @@ struct act_prob action_prob_unit_vs_tgt(const struct action *paction,
     break;
   case ATK_TILE:
     if (tgt_tile) {
-      prob = action_prob_vs_tile(act_unit, paction->id, tgt_tile, extra_tgt);
+      prob = action_prob_vs_tile(nmap, act_unit, paction->id, tgt_tile, extra_tgt);
     }
     break;
   case ATK_EXTRAS:
diff --git a/common/actions.h b/common/actions.h
index 432ddd224b..613f5f0a96 100644
--- a/common/actions.h
+++ b/common/actions.h
@@ -828,7 +828,8 @@ struct act_prob action_prob_vs_units(const struct civ_map *nmap,
                                      const action_id act_id,
                                      const struct tile* victims);
 
-struct act_prob action_prob_vs_tile(const struct unit *actor,
+struct act_prob action_prob_vs_tile(const struct civ_map *nmap,
+                                    const struct unit *actor,
                                     const action_id act_id,
                                     const struct tile *victims,
                                     const struct extra_type *target_extra);
diff --git a/common/unit.c b/common/unit.c
index dd18f250c6..f7740d07e0 100644
--- a/common/unit.c
+++ b/common/unit.c
@@ -433,7 +433,7 @@ bool unit_can_add_or_build_city(const struct unit *punit)
     return action_prob_possible(action_prob_vs_city(nmap, punit,
         ACTION_JOIN_CITY, tgt_city));
   } else {
-    return action_prob_possible(action_prob_vs_tile(punit,
+    return action_prob_possible(action_prob_vs_tile(nmap, punit,
         ACTION_FOUND_CITY, unit_tile(punit), NULL));
   }
 }
diff --git a/server/actiontools.c b/server/actiontools.c
index 79cceff765..95c1d21123 100644
--- a/server/actiontools.c
+++ b/server/actiontools.c
@@ -755,7 +755,7 @@ struct tile *action_tgt_tile(struct unit *actor,
 
     switch (action_id_get_target_kind(act)) {
     case ATK_TILE:
-      prob = action_prob_vs_tile(actor, act, target, target_extra);
+      prob = action_prob_vs_tile(nmap, actor, act, target, target_extra);
       break;
     case ATK_EXTRAS:
       prob = action_prob_vs_extras(actor, act, target, target_extra);
@@ -801,6 +801,8 @@ static bool may_unit_act_vs_tile_extra(const struct unit *actor,
                                        const struct extra_type *tgt_extra,
                                        bool accept_all_actions)
 {
+  const struct civ_map *nmap = &(wld.map);
+
   if (actor == NULL || tgt_tile == NULL || tgt_extra == NULL) {
     /* Can't do any actions if actor or target are missing. */
     return FALSE;
@@ -822,7 +824,7 @@ static bool may_unit_act_vs_tile_extra(const struct unit *actor,
 
     switch (action_id_get_target_kind(act)) {
     case ATK_TILE:
-      if (action_prob_possible(action_prob_vs_tile(actor, act,
+      if (action_prob_possible(action_prob_vs_tile(nmap, actor, act,
                                                    tgt_tile, tgt_extra))) {
         /* The actor unit may be able to do this action to the target
          * extra. */
@@ -886,6 +888,7 @@ int action_sub_target_id_for_action(const struct action *paction,
                                     struct unit *actor_unit)
 {
   const struct tile *tgt_tile = unit_tile(actor_unit);
+  const struct civ_map *nmap = &(wld.map);
 
   fc_assert_ret_val(paction->target_complexity == ACT_TGT_COMPL_FLEXIBLE,
                     NO_TARGET);
@@ -920,7 +923,7 @@ int action_sub_target_id_for_action(const struct action *paction,
       }
     }
     extra_type_re_active_iterate(tgt_extra) {
-      if (action_prob_possible(action_prob_vs_tile(actor_unit, paction->id,
+      if (action_prob_possible(action_prob_vs_tile(nmap, actor_unit, paction->id,
                                                    tgt_tile, tgt_extra))) {
         /* The actor unit may be able to do this action to the target
          * extra. */
@@ -1142,7 +1145,7 @@ action_auto_perf_unit_prob(const enum action_auto_perf_cause cause,
         if (tgt_tile
             && is_action_enabled_unit_on_tile(nmap, act, actor,
                                               tgt_tile, target_extra)) {
-          current = action_prob_vs_tile(actor, act, tgt_tile, target_extra);
+          current = action_prob_vs_tile(nmap, actor, act, tgt_tile, target_extra);
         }
         break;
       case ATK_EXTRAS:
diff --git a/server/cityhand.c b/server/cityhand.c
index 89142e9958..9ff6b3c8dd 100644
--- a/server/cityhand.c
+++ b/server/cityhand.c
@@ -61,6 +61,7 @@ void handle_city_name_suggestion_req(struct player *pplayer, int unit_id16,
                                      int unit_id32)
 {
   struct unit *punit;
+  const struct civ_map *nmap = &(wld.map);
 
   if (!has_capability("ids32", pplayer->current_conn->capability)) {
     unit_id32 = unit_id16;
@@ -75,7 +76,7 @@ void handle_city_name_suggestion_req(struct player *pplayer, int unit_id16,
     return;
   }
 
-  if (action_prob_possible(action_prob_vs_tile(punit, ACTION_FOUND_CITY,
+  if (action_prob_possible(action_prob_vs_tile(nmap, punit, ACTION_FOUND_CITY,
                                                unit_tile(punit), NULL))) {
     log_verbose("handle_city_name_suggest_req(unit_pos (%d, %d))",
                 TILE_XY(unit_tile(punit)));
diff --git a/server/unithand.c b/server/unithand.c
index 5bc30a694a..243a6b49d5 100644
--- a/server/unithand.c
+++ b/server/unithand.c
@@ -2233,7 +2233,7 @@ void handle_unit_get_actions(struct connection *pc,
     case ATK_TILE:
       if (target_tile) {
         /* Calculate the probabilities. */
-        probabilities[act] = action_prob_vs_tile(actor_unit, act,
+        probabilities[act] = action_prob_vs_tile(nmap, actor_unit, act,
                                                  target_tile, target_extra);
       } else {
         /* No target to act against. */
diff --git a/server/unittools.c b/server/unittools.c
index 8a9b889310..7fd2841de5 100644
--- a/server/unittools.c
+++ b/server/unittools.c
@@ -4667,7 +4667,7 @@ bool execute_orders(struct unit *punit, const bool fresh)
         tgt_id = dst_tile->index;
         break;
       case ATK_TILE:
-        prob = action_prob_vs_tile(punit, order.action,
+        prob = action_prob_vs_tile(nmap, punit, order.action,
                                    dst_tile, pextra);
         tgt_id = dst_tile->index;
         break;
-- 
2.43.0

