From e7198720841eccc03fafc280c232232cdddba6f5 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sun, 1 Sep 2024 00:59:46 +0300
Subject: [PATCH 15/15] Unhardcode wld.map from action_prob_unit_vs_tgt()

See RM #819

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

diff --git a/ai/default/daiparadrop.c b/ai/default/daiparadrop.c
index 82145b26d7..ba382d9266 100644
--- a/ai/default/daiparadrop.c
+++ b/ai/default/daiparadrop.c
@@ -242,7 +242,7 @@ void dai_manage_paratrooper(struct ai_type *ait, struct player *pplayer,
 
         if (has_handicap(pplayer, H_FOG)) {
           possible = action_prob_possible(
-                       action_prob_unit_vs_tgt(paction, punit,
+                       action_prob_unit_vs_tgt(nmap, paction, punit,
                                                tile_city(ptile_dest), NULL,
                                                ptile_dest, NULL));
         } else {
diff --git a/client/control.c b/client/control.c
index 4ffcbe2862..244e26326a 100644
--- a/client/control.c
+++ b/client/control.c
@@ -3148,7 +3148,7 @@ static void do_unit_teleport_to(struct unit *punit, struct tile *ptile)
     }
 
     if (action_prob_possible(
-          action_prob_unit_vs_tgt(paction, punit,
+          action_prob_unit_vs_tgt(&(wld.map), paction, punit,
                                   tile_city(ptile), NULL,
                                   ptile, NULL))) {
       if (teleport_action == NULL) {
@@ -3188,7 +3188,7 @@ void do_unit_paradrop_to(struct unit *punit, struct tile *ptile)
     }
 
     if (action_prob_possible(
-          action_prob_unit_vs_tgt(paction, punit,
+          action_prob_unit_vs_tgt(&(wld.map), paction, punit,
                                   tile_city(ptile), NULL,
                                   ptile, NULL))) {
       if (paradrop_action == NULL) {
diff --git a/common/actions.c b/common/actions.c
index f00151eed5..d9a8939e19 100644
--- a/common/actions.c
+++ b/common/actions.c
@@ -4728,7 +4728,8 @@ struct act_prob action_prob_self(const struct civ_map *nmap,
   @param extra_tgt the target for extra sub targeted actions
   @return the action probability of performing the action
 **************************************************************************/
-struct act_prob action_prob_unit_vs_tgt(const struct action *paction,
+struct act_prob action_prob_unit_vs_tgt(const struct civ_map *nmap,
+                                        const struct action *paction,
                                         const struct unit *act_unit,
                                         const struct city *tgt_city,
                                         const struct unit *tgt_unit,
@@ -4737,7 +4738,6 @@ struct act_prob action_prob_unit_vs_tgt(const struct action *paction,
 {
   /* Assume impossible until told otherwise. */
   struct act_prob prob = ACTPROB_IMPOSSIBLE;
-  const struct civ_map *nmap = &(wld.map);
 
   fc_assert_ret_val(paction, ACTPROB_IMPOSSIBLE);
   fc_assert_ret_val(act_unit, ACTPROB_IMPOSSIBLE);
diff --git a/common/actions.h b/common/actions.h
index 65b1ad000a..1c99cfc6b2 100644
--- a/common/actions.h
+++ b/common/actions.h
@@ -583,7 +583,8 @@ 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,
+struct act_prob action_prob_unit_vs_tgt(const struct civ_map *nmap,
+                                        const struct action *paction,
                                         const struct unit *act_unit,
                                         const struct city *tgt_city,
                                         const struct unit *tgt_unit,
diff --git a/server/unithand.c b/server/unithand.c
index dfeb816a51..9ff036cdbc 100644
--- a/server/unithand.c
+++ b/server/unithand.c
@@ -3119,6 +3119,7 @@ static void illegal_action(struct player *pplayer,
 {
   bool information_revealed;
   bool was_punished;
+  const struct civ_map *nmap = &(wld.map);
 
   struct action *stopped_action = action_by_number(stopped_action_id);
 
@@ -3129,6 +3130,7 @@ static void illegal_action(struct player *pplayer,
 
 
   information_revealed = action_prob_possible(action_prob_unit_vs_tgt(
+                                                 nmap,
                                                  stopped_action,
                                                  actor,
                                                  target_city, target_unit,
-- 
2.45.2

