From 2bae8851fa334629bc163bbf3f9f4b1bab1f679d Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sat, 4 May 2024 13:48:13 +0300
Subject: [PATCH 67/67] Unhardcode wld.map from action_prob_vs_unit()

See RM #549

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 ai/default/aidiplomat.c | 4 ++--
 ai/default/aiferry.c    | 4 ++--
 client/control.c        | 7 ++++---
 common/actions.c        | 7 +++----
 common/actions.h        | 5 +++--
 common/unit.c           | 4 ++--
 server/actiontools.c    | 6 ++++--
 server/unithand.c       | 2 +-
 server/unittools.c      | 2 +-
 9 files changed, 22 insertions(+), 19 deletions(-)

diff --git a/ai/default/aidiplomat.c b/ai/default/aidiplomat.c
index a9abb25d80..3b55073f58 100644
--- a/ai/default/aidiplomat.c
+++ b/ai/default/aidiplomat.c
@@ -673,7 +673,7 @@ static bool dai_diplomat_bribe_nearby(struct ai_type *ait,
       pf_path_destroy(path);
     }
 
-    if (action_prob_possible(action_prob_vs_unit(punit,
+    if (action_prob_possible(action_prob_vs_unit(nmap, punit,
                                  ACTION_SPY_BRIBE_UNIT,
                                  pvictim))) {
       unit_do_action(pplayer, punit->id,
@@ -685,7 +685,7 @@ static bool dai_diplomat_bribe_nearby(struct ai_type *ait,
       } else {
         return FALSE;
       }
-    } else if (action_prob_possible(action_prob_vs_unit(punit,
+    } else if (action_prob_possible(action_prob_vs_unit(nmap, punit,
                                         ACTION_SPY_SABOTAGE_UNIT_ESC,
                                         pvictim))
                && threat) {
diff --git a/ai/default/aiferry.c b/ai/default/aiferry.c
index 233e233245..841487b42c 100644
--- a/ai/default/aiferry.c
+++ b/ai/default/aiferry.c
@@ -840,7 +840,7 @@ bool aiferry_gobyboat(struct ai_type *ait, struct player *pplayer,
     action_by_result_iterate(paction, ACTRES_TRANSPORT_BOARD) {
       enum gen_action act_id = action_id(paction);
 
-      if (action_prob_possible(action_prob_vs_unit(punit, act_id,
+      if (action_prob_possible(action_prob_vs_unit(nmap, punit, act_id,
                                                    ferryboat))) {
         if (unit_perform_action(pplayer,
                                 punit->id, ferryboat->id, 0, "",
@@ -906,7 +906,7 @@ bool aiferry_gobyboat(struct ai_type *ait, struct player *pplayer,
         action_by_result_iterate(paction, ACTRES_TRANSPORT_BOARD) {
           enum gen_action act_id = action_id(paction);
 
-          if (action_prob_possible(action_prob_vs_unit(bodyguard,
+          if (action_prob_possible(action_prob_vs_unit(nmap, bodyguard,
                                                        act_id,
                                                        ferryboat))) {
             if (unit_perform_action(pplayer,
diff --git a/client/control.c b/client/control.c
index 2e2b61e75d..3a496a3495 100644
--- a/client/control.c
+++ b/client/control.c
@@ -1949,6 +1949,7 @@ static void do_disband_alternative(void *p)
   struct client_disband_unit_data *next;
   struct client_disband_unit_data *data = p;
   int act;
+  const struct civ_map *nmap = &(wld.map);
 
   fc_assert_ret(can_client_issue_orders());
 
@@ -1983,13 +1984,13 @@ static void do_disband_alternative(void *p)
   switch (action_id_get_target_kind(act)) {
   case ATK_CITY:
     if ((pcity = tile_city(unit_tile(punit)))
-        && action_prob_possible(action_prob_vs_city(&(wld.map), punit,
+        && action_prob_possible(action_prob_vs_city(nmap, punit,
                                                     act, pcity))) {
       request_do_action(act, punit->id, pcity->id, 0, "");
     }
     break;
   case ATK_UNIT:
-    if (action_prob_possible(action_prob_vs_unit(punit, act, punit))) {
+    if (action_prob_possible(action_prob_vs_unit(nmap, punit, act, punit))) {
       request_do_action(act, punit->id, punit->id, 0, "");
     }
     break;
@@ -2141,7 +2142,7 @@ void request_unit_load(struct unit *pcargo, struct unit *ptrans,
                              : ACTRES_TRANSPORT_EMBARK) {
       enum gen_action act_id = action_id(paction);
 
-      if (action_prob_possible(action_prob_vs_unit(pcargo, act_id,
+      if (action_prob_possible(action_prob_vs_unit(&(wld.map), pcargo, act_id,
                                                    ptrans))) {
         /* Try the first action that may be legal. */
         /* Implement something like do_disband_alternative() if a ruleset
diff --git a/common/actions.c b/common/actions.c
index 3839f53d83..70cfe3664b 100644
--- a/common/actions.c
+++ b/common/actions.c
@@ -4281,12 +4281,11 @@ action_prob_vs_unit_full(const struct civ_map *nmap,
   Get the actor unit's probability of successfully performing the chosen
   action on the target unit.
 **************************************************************************/
-struct act_prob action_prob_vs_unit(const struct unit *actor_unit,
+struct act_prob action_prob_vs_unit(const struct civ_map *nmap,
+                                    const struct unit *actor_unit,
                                     const action_id act_id,
                                     const struct unit *target_unit)
 {
-  const struct civ_map *nmap = &(wld.map);
-
   return action_prob_vs_unit_full(nmap, actor_unit,
                                   unit_home(actor_unit),
                                   unit_tile(actor_unit),
@@ -4773,7 +4772,7 @@ struct act_prob action_prob_unit_vs_tgt(const struct action *paction,
     break;
   case ATK_UNIT:
     if (tgt_unit) {
-      prob = action_prob_vs_unit(act_unit, paction->id, tgt_unit);
+      prob = action_prob_vs_unit(nmap, act_unit, paction->id, tgt_unit);
     }
     break;
   case ATK_SELF:
diff --git a/common/actions.h b/common/actions.h
index 8cae4ee395..df13a42dc9 100644
--- a/common/actions.h
+++ b/common/actions.h
@@ -556,9 +556,10 @@ struct act_prob action_prob_vs_city(const struct civ_map *nmap,
                                     const action_id act_id,
                                     const struct city *victim);
 
-struct act_prob action_prob_vs_unit(const struct unit* actor,
+struct act_prob action_prob_vs_unit(const struct civ_map *nmap,
+                                    const struct unit *actor,
                                     const action_id act_id,
-                                    const struct unit* victim);
+                                    const struct unit *victim);
 
 struct act_prob action_prob_vs_stack(const struct unit* actor,
                                      const action_id act_id,
diff --git a/common/unit.c b/common/unit.c
index 16e5a1b926..c5d57c999c 100644
--- a/common/unit.c
+++ b/common/unit.c
@@ -816,9 +816,9 @@ bool can_unit_deboard_or_be_unloaded(const struct unit *pcargo,
                                               ptrans, pcargo));
   } else {
     return (action_prob_possible(
-             action_prob_vs_unit(pcargo, ACTION_TRANSPORT_DEBOARD, ptrans))
+             action_prob_vs_unit(nmap, pcargo, ACTION_TRANSPORT_DEBOARD, ptrans))
             || action_prob_possible(
-              action_prob_vs_unit(ptrans, ACTION_TRANSPORT_UNLOAD,
+              action_prob_vs_unit(nmap, ptrans, ACTION_TRANSPORT_UNLOAD,
                                   pcargo)));
   }
 }
diff --git a/server/actiontools.c b/server/actiontools.c
index 2860b933b5..4fdd81a50e 100644
--- a/server/actiontools.c
+++ b/server/actiontools.c
@@ -665,6 +665,8 @@ struct city *action_tgt_city(struct unit *actor, struct tile *target_tile,
 static bool may_unit_act_vs_unit(struct unit *actor, struct unit *target,
                                  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 FALSE;
@@ -682,7 +684,7 @@ static bool may_unit_act_vs_unit(struct unit *actor, struct unit *target,
       continue;
     }
 
-    if (action_prob_possible(action_prob_vs_unit(actor, act, target))) {
+    if (action_prob_possible(action_prob_vs_unit(nmap, actor, act, target))) {
       /* The actor unit may be able to do this action to the target
        * unit. */
       return TRUE;
@@ -1160,7 +1162,7 @@ action_auto_perf_unit_prob(const enum action_auto_perf_cause cause,
       case ATK_UNIT:
         if (tgt_unit
             && is_action_enabled_unit_on_unit(nmap, act, actor, tgt_unit)) {
-          current = action_prob_vs_unit(actor, act, tgt_unit);
+          current = action_prob_vs_unit(nmap, actor, act, tgt_unit);
         }
         break;
       case ATK_SELF:
diff --git a/server/unithand.c b/server/unithand.c
index 785c2121c4..4e9f569242 100644
--- a/server/unithand.c
+++ b/server/unithand.c
@@ -2371,7 +2371,7 @@ void handle_unit_get_actions(struct connection *pc,
     case ATK_UNIT:
       if (target_unit) {
         /* Calculate the probabilities. */
-        probabilities[act] = action_prob_vs_unit(actor_unit, act,
+        probabilities[act] = action_prob_vs_unit(nmap, actor_unit, act,
                                                  target_unit);
       } else {
         /* No target to act against. */
diff --git a/server/unittools.c b/server/unittools.c
index 48aef44f9e..69d1e71113 100644
--- a/server/unittools.c
+++ b/server/unittools.c
@@ -4821,7 +4821,7 @@ bool execute_orders(struct unit *punit, const bool fresh)
         tgt_id = tgt_city->id;
         break;
       case ATK_UNIT:
-        prob = action_prob_vs_unit(punit, order.action,
+        prob = action_prob_vs_unit(nmap, punit, order.action,
                                    tgt_unit);
 
         tgt_id = tgt_unit->id;
-- 
2.43.0

