From 53a6f0525141f94e176727ef8ac82caa1d1fcd7c Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sat, 29 Jun 2024 07:58:57 +0300
Subject: [PATCH 30/30] Unhardcode wld.map from action_prob_self()

See RM #739

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

diff --git a/client/control.c b/client/control.c
index be763f0528..3439d565fd 100644
--- a/client/control.c
+++ b/client/control.c
@@ -2033,7 +2033,7 @@ static void do_disband_alternative(void *p)
     }
     break;
   case ATK_SELF:
-    if (action_prob_possible(action_prob_self(punit, act))) {
+    if (action_prob_possible(action_prob_self(nmap, punit, act))) {
       request_do_action(act, punit->id, punit->id, 0, "");
     }
     break;
diff --git a/common/actions.c b/common/actions.c
index e3351d2ac8..77d4ce9aea 100644
--- a/common/actions.c
+++ b/common/actions.c
@@ -4711,11 +4711,10 @@ action_prob_self_full(const struct civ_map *nmap,
   Get the actor unit's probability of successfully performing the chosen
   action on itself.
 **************************************************************************/
-struct act_prob action_prob_self(const struct unit *actor_unit,
+struct act_prob action_prob_self(const struct civ_map *nmap,
+                                 const struct unit *actor_unit,
                                  const action_id act_id)
 {
-  const struct civ_map *nmap = &(wld.map);
-
   return action_prob_self_full(nmap, actor_unit,
                                unit_home(actor_unit),
                                unit_tile(actor_unit),
@@ -4775,7 +4774,7 @@ struct act_prob action_prob_unit_vs_tgt(const struct action *paction,
     }
     break;
   case ATK_SELF:
-    prob = action_prob_self(act_unit, paction->id);
+    prob = action_prob_self(nmap, act_unit, paction->id);
     break;
   case ATK_COUNT:
     log_error("Invalid action target kind");
diff --git a/common/actions.h b/common/actions.h
index 3f16ce9d60..d47f57e1bc 100644
--- a/common/actions.h
+++ b/common/actions.h
@@ -578,7 +578,8 @@ struct act_prob action_prob_vs_extras(const struct civ_map *nmap,
                                       const struct tile *target,
                                       const struct extra_type *tgt_extra);
 
-struct act_prob action_prob_self(const struct unit *actor,
+struct act_prob action_prob_self(const struct civ_map *nmap,
+                                 const struct unit *actor,
                                  const action_id act_id);
 
 struct act_prob action_prob_unit_vs_tgt(const struct action *paction,
diff --git a/server/actiontools.c b/server/actiontools.c
index 2883318772..1812fa45f5 100644
--- a/server/actiontools.c
+++ b/server/actiontools.c
@@ -1176,7 +1176,7 @@ action_auto_perf_unit_prob(const enum action_auto_perf_cause cause,
       case ATK_SELF:
         if (actor
             && is_action_enabled_unit_on_self(nmap, act, actor)) {
-          current = action_prob_self(actor, act);
+          current = action_prob_self(nmap, actor, act);
         }
         break;
       case ATK_COUNT:
diff --git a/server/unithand.c b/server/unithand.c
index 6f05366a0c..b5501c7a04 100644
--- a/server/unithand.c
+++ b/server/unithand.c
@@ -2418,7 +2418,7 @@ void handle_unit_get_actions(struct connection *pc,
     case ATK_SELF:
       if (actor_target_distance == 0) {
         /* Calculate the probabilities. */
-        probabilities[act] = action_prob_self(actor_unit, act);
+        probabilities[act] = action_prob_self(nmap, actor_unit, act);
       } else {
         /* Don't bother with self targeted actions unless the actor is
          * asking about what can be done to its own tile. */
diff --git a/server/unittools.c b/server/unittools.c
index 08501b13d3..c833971129 100644
--- a/server/unittools.c
+++ b/server/unittools.c
@@ -4831,7 +4831,7 @@ bool execute_orders(struct unit *punit, const bool fresh)
         tgt_id = tgt_unit->id;
         break;
       case ATK_SELF:
-        prob = action_prob_self(punit, order.action);
+        prob = action_prob_self(nmap, punit, order.action);
 
         tgt_id = unitid;
         break;
-- 
2.43.0

