From 1c6b67cf53043556d221473c7ce5c4d6150157b2 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Thu, 9 May 2024 22:46:15 +0300
Subject: [PATCH 75/75] Unhardcode wld.map from action_prob_vs_stack()

See RM #579

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

diff --git a/client/control.c b/client/control.c
index 3a496a3495..c88d0f71bd 100644
--- a/client/control.c
+++ b/client/control.c
@@ -1996,7 +1996,7 @@ static void do_disband_alternative(void *p)
     break;
   case ATK_UNITS:
     if ((ptile = unit_tile(punit))
-        && action_prob_possible(action_prob_vs_stack(punit, act, ptile))) {
+        && action_prob_possible(action_prob_vs_stack(nmap, punit, act, ptile))) {
       request_do_action(act, punit->id, ptile->index, 0, "");
     }
     break;
diff --git a/common/actions.c b/common/actions.c
index 70cfe3664b..4a3a30a9f8 100644
--- a/common/actions.c
+++ b/common/actions.c
@@ -4473,12 +4473,11 @@ action_prob_vs_stack_full(const struct civ_map *nmap,
   Get the actor unit's probability of successfully performing the chosen
   action on all units at the target tile.
 **************************************************************************/
-struct act_prob action_prob_vs_stack(const struct unit *actor_unit,
+struct act_prob action_prob_vs_stack(const struct civ_map *nmap,
+                                     const struct unit *actor_unit,
                                      const action_id act_id,
                                      const struct tile *target_tile)
 {
-  const struct civ_map *nmap = &(wld.map);
-
   return action_prob_vs_stack_full(nmap, actor_unit,
                                    unit_home(actor_unit),
                                    unit_tile(actor_unit),
@@ -4751,7 +4750,7 @@ struct act_prob action_prob_unit_vs_tgt(const struct action *paction,
   switch (action_get_target_kind(paction)) {
   case ATK_UNITS:
     if (tgt_tile) {
-      prob = action_prob_vs_stack(act_unit, paction->id, tgt_tile);
+      prob = action_prob_vs_stack(nmap, act_unit, paction->id, tgt_tile);
     }
     break;
   case ATK_TILE:
diff --git a/common/actions.h b/common/actions.h
index df13a42dc9..acef71a7e4 100644
--- a/common/actions.h
+++ b/common/actions.h
@@ -561,7 +561,8 @@ struct act_prob action_prob_vs_unit(const struct civ_map *nmap,
                                     const action_id act_id,
                                     const struct unit *victim);
 
-struct act_prob action_prob_vs_stack(const struct unit* actor,
+struct act_prob action_prob_vs_stack(const struct civ_map *nmap,
+                                     const struct unit* actor,
                                      const action_id act_id,
                                      const struct tile* victims);
 
diff --git a/server/actiontools.c b/server/actiontools.c
index 4fdd81a50e..38e71fb79d 100644
--- a/server/actiontools.c
+++ b/server/actiontools.c
@@ -735,6 +735,8 @@ struct tile *action_tgt_tile(struct unit *actor,
                              const struct extra_type *target_extra,
                              bool accept_all_actions)
 {
+  const struct civ_map *nmap = &(wld.map);
+
   if (actor == NULL || target == NULL) {
     /* Can't do any actions if actor or target are missing. */
     return NULL;
@@ -761,7 +763,7 @@ struct tile *action_tgt_tile(struct unit *actor,
       prob = action_prob_vs_extras(actor, act, target, target_extra);
       break;
     case ATK_UNITS:
-      prob = action_prob_vs_stack(actor, act, target);
+      prob = action_prob_vs_stack(nmap, actor, act, target);
       break;
     case ATK_CITY:
     case ATK_UNIT:
@@ -1135,7 +1137,7 @@ action_auto_perf_unit_prob(const enum action_auto_perf_cause cause,
       case ATK_UNITS:
         if (tgt_tile
             && is_action_enabled_unit_on_stack(nmap, act, actor, tgt_tile)) {
-          current = action_prob_vs_stack(actor, act, tgt_tile);
+          current = action_prob_vs_stack(nmap, actor, act, tgt_tile);
         }
         break;
       case ATK_TILE:
diff --git a/server/unithand.c b/server/unithand.c
index 20518cb4c7..34cc4f543e 100644
--- a/server/unithand.c
+++ b/server/unithand.c
@@ -2381,7 +2381,7 @@ void handle_unit_get_actions(struct connection *pc,
     case ATK_UNITS:
       if (target_tile) {
         /* Calculate the probabilities. */
-        probabilities[act] = action_prob_vs_stack(actor_unit, act,
+        probabilities[act] = action_prob_vs_stack(nmap, actor_unit, act,
                                                   target_tile);
       } else {
         /* No target to act against. */
diff --git a/server/unittools.c b/server/unittools.c
index 830682c0e8..5c87f62868 100644
--- a/server/unittools.c
+++ b/server/unittools.c
@@ -4801,7 +4801,7 @@ bool execute_orders(struct unit *punit, const bool fresh)
 
       switch (action_id_get_target_kind(order.action)) {
       case ATK_UNITS:
-        prob = action_prob_vs_stack(punit, order.action,
+        prob = action_prob_vs_stack(nmap, punit, order.action,
                                     dst_tile);
         tgt_id = dst_tile->index;
         break;
@@ -5116,7 +5116,7 @@ void random_movements(struct player *pplayer)
           struct tile *dest = mapstep(&(wld.map), curtile, dirs[choice]);
 
           if (dest != NULL) {
-            if (action_prob_possible(action_prob_vs_stack(punit, ACTION_ATTACK,
+            if (action_prob_possible(action_prob_vs_stack(nmap, punit, ACTION_ATTACK,
                                                           dest))) {
               if (unit_perform_action(pplayer, id, tile_index(dest), NO_TARGET,
                                       "", ACTION_ATTACK, ACT_REQ_RULES)) {
-- 
2.43.0

