From 570e239785bea7eed689464137a5e0702bf6874d Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Thu, 9 May 2024 22:49:53 +0300
Subject: [PATCH 32/32] Unhardcode wld.map from action_prob_vs_units()

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   | 2 +-
 6 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/client/control.c b/client/control.c
index 1fc63e38d1..fe9f57d136 100644
--- a/client/control.c
+++ b/client/control.c
@@ -1923,7 +1923,7 @@ static void do_disband_alternative(void *p)
     break;
   case ATK_UNITS:
     if ((ptile = unit_tile(punit))
-        && action_prob_possible(action_prob_vs_units(punit, act, ptile))) {
+        && action_prob_possible(action_prob_vs_units(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 008dbfc383..b19b56492c 100644
--- a/common/actions.c
+++ b/common/actions.c
@@ -6138,12 +6138,11 @@ action_prob_vs_units_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_units(const struct unit *actor_unit,
+struct act_prob action_prob_vs_units(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_units_full(nmap, actor_unit,
                                    unit_home(actor_unit),
                                    unit_tile(actor_unit),
@@ -6416,7 +6415,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_units(act_unit, paction->id, tgt_tile);
+      prob = action_prob_vs_units(nmap, act_unit, paction->id, tgt_tile);
     }
     break;
   case ATK_TILE:
diff --git a/common/actions.h b/common/actions.h
index 0f0532cd48..432ddd224b 100644
--- a/common/actions.h
+++ b/common/actions.h
@@ -823,7 +823,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_units(const struct unit* actor,
+struct act_prob action_prob_vs_units(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 1f7a10134f..79cceff765 100644
--- a/server/actiontools.c
+++ b/server/actiontools.c
@@ -733,6 +733,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;
@@ -759,7 +761,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_units(actor, act, target);
+      prob = action_prob_vs_units(nmap, actor, act, target);
       break;
     case ATK_CITY:
     case ATK_UNIT:
@@ -1133,7 +1135,7 @@ action_auto_perf_unit_prob(const enum action_auto_perf_cause cause,
       case ATK_UNITS:
         if (tgt_tile
             && is_action_enabled_unit_on_units(nmap, act, actor, tgt_tile)) {
-          current = action_prob_vs_units(actor, act, tgt_tile);
+          current = action_prob_vs_units(nmap, actor, act, tgt_tile);
         }
         break;
       case ATK_TILE:
diff --git a/server/unithand.c b/server/unithand.c
index cce341074d..5bc30a694a 100644
--- a/server/unithand.c
+++ b/server/unithand.c
@@ -2223,7 +2223,7 @@ void handle_unit_get_actions(struct connection *pc,
     case ATK_UNITS:
       if (target_tile) {
         /* Calculate the probabilities. */
-        probabilities[act] = action_prob_vs_units(actor_unit, act,
+        probabilities[act] = action_prob_vs_units(nmap, actor_unit, act,
                                                   target_tile);
       } else {
         /* No target to act against. */
diff --git a/server/unittools.c b/server/unittools.c
index fa60834a47..8a9b889310 100644
--- a/server/unittools.c
+++ b/server/unittools.c
@@ -4662,7 +4662,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_units(punit, order.action,
+        prob = action_prob_vs_units(nmap, punit, order.action,
                                     dst_tile);
         tgt_id = dst_tile->index;
         break;
-- 
2.43.0

