From 6e9f708357c0117ee273ea5a243903b75b0d3ea6 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Fri, 12 Jan 2024 07:25:32 +0200
Subject: [PATCH 18/18] Unhardcode wld.map from action_hard_reqs_actor()

See RM #173

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 common/actions.c  | 22 +++++++++++++---------
 common/actions.h  |  4 +++-
 common/unit.c     |  6 ++++--
 server/unithand.c |  5 +++--
 4 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/common/actions.c b/common/actions.c
index 330ab94c00..8214d5c8d5 100644
--- a/common/actions.c
+++ b/common/actions.c
@@ -3533,13 +3533,13 @@ action_actor_utype_hard_reqs_ok(const struct action *paction,
   may or may not be legal depending on the action.
 **************************************************************************/
 static enum fc_tristate
-action_hard_reqs_actor(const struct action *paction,
+action_hard_reqs_actor(const struct civ_map *nmap,
+                       const struct action *paction,
                        const struct req_context *actor,
                        const bool omniscient,
                        const struct city *homecity)
 {
   enum action_result result = paction->result;
-  const struct civ_map *nmap = &(wld.map);
 
   if (actor == NULL) {
     actor = req_context_empty();
@@ -3808,7 +3808,7 @@ is_action_possible(const action_id wanted_action,
   }
 
   /* Actor specific hard requirements. */
-  out = action_hard_reqs_actor(paction, actor, omniscient, homecity);
+  out = action_hard_reqs_actor(nmap, paction, actor, omniscient, homecity);
 
   if (out == TRI_NO) {
     /* Illegal because of a hard actor requirement. */
@@ -5358,10 +5358,11 @@ static struct act_prob ap_diplomat_battle(const struct unit *pattacker,
 /**********************************************************************//**
   Returns the action probability for when a target is unseen.
 **************************************************************************/
-static struct act_prob act_prob_unseen_target(action_id act_id,
+static struct act_prob act_prob_unseen_target(const struct civ_map *nmap,
+                                              action_id act_id,
                                               const struct unit *actor_unit)
 {
-  if (action_maybe_possible_actor_unit(act_id, actor_unit)) {
+  if (action_maybe_possible_actor_unit(nmap, act_id, actor_unit)) {
     /* Unknown because the target is unseen. */
     return ACTPROB_NOT_KNOWN;
   } else {
@@ -5771,6 +5772,7 @@ action_prob_vs_city_full(const struct unit* actor_unit,
   const struct impr_type *target_building;
   const struct unit_type *target_utype;
   const struct action *act = action_by_number(act_id);
+  const struct civ_map *nmap = &(wld.map);
 
   if (actor_unit == NULL || target_city == NULL) {
     /* Can't do an action when actor or target are missing. */
@@ -5820,7 +5822,7 @@ action_prob_vs_city_full(const struct unit* actor_unit,
   if (!player_can_see_city_externals(unit_owner(actor_unit), target_city)) {
     /* The invisible city at this tile may, as far as the player knows, not
      * exist anymore. */
-    return act_prob_unseen_target(act_id, actor_unit);
+    return act_prob_unseen_target(nmap, act_id, actor_unit);
   }
 
   target_building = tgt_city_local_building(target_city);
@@ -5954,6 +5956,7 @@ action_prob_vs_units_full(const struct unit* actor_unit,
   struct act_prob prob_all;
   const struct req_context *actor_ctxt;
   const struct action *act = action_by_number(act_id);
+  const struct civ_map *nmap = &(wld.map);
 
   if (actor_unit == NULL || target_tile == NULL) {
     /* Can't do an action when actor or target are missing. */
@@ -6026,7 +6029,7 @@ action_prob_vs_units_full(const struct unit* actor_unit,
       return ACTPROB_IMPOSSIBLE;
     } else {
       /* The player doesn't know that the tile is empty. */
-      return act_prob_unseen_target(act_id, actor_unit);
+      return act_prob_unseen_target(nmap, act_id, actor_unit);
     }
   }
 
@@ -7125,7 +7128,8 @@ bool is_action_possible_on_city(action_id act_id,
   performed right now by the specified actor unit if an approriate target
   is provided.
 **************************************************************************/
-bool action_maybe_possible_actor_unit(const action_id act_id,
+bool action_maybe_possible_actor_unit(const struct civ_map *nmap,
+                                      const action_id act_id,
                                       const struct unit *actor_unit)
 {
   const struct player *actor_player = unit_owner(actor_unit);
@@ -7147,7 +7151,7 @@ bool action_maybe_possible_actor_unit(const action_id act_id,
     return FALSE;
   }
 
-  result = action_hard_reqs_actor(paction, &actor_ctxt, FALSE,
+  result = action_hard_reqs_actor(nmap, paction, &actor_ctxt, FALSE,
                                   unit_home(actor_unit));
 
   if (result == TRI_NO) {
diff --git a/common/actions.h b/common/actions.h
index af606d7775..d7e8ba1c8c 100644
--- a/common/actions.h
+++ b/common/actions.h
@@ -16,6 +16,7 @@
 
 /* common */
 #include "fc_types.h"
+#include "map_types.h"
 #include "metaknowledge.h"
 #include "requirements.h"
 
@@ -947,7 +948,8 @@ bool is_action_possible_on_city(action_id act_id,
                                 const struct player *actor_player,
                                 const struct city* target_city);
 
-bool action_maybe_possible_actor_unit(const action_id wanted_action,
+bool action_maybe_possible_actor_unit(const struct civ_map *nmap,
+                                      const action_id wanted_action,
                                       const struct unit* actor_unit);
 
 bool action_mp_full_makes_legal(const struct unit *actor,
diff --git a/common/unit.c b/common/unit.c
index e2d7461837..d5d3cb8055 100644
--- a/common/unit.c
+++ b/common/unit.c
@@ -818,13 +818,15 @@ bool can_unit_alight_or_be_unloaded(const struct unit *pcargo,
 **************************************************************************/
 bool can_unit_paradrop(const struct unit *punit)
 {
+  const struct civ_map *nmap = &(wld.map);
+
   action_by_result_iterate(paction, ACTRES_PARADROP) {
-    if (action_maybe_possible_actor_unit(paction->id, punit)) {
+    if (action_maybe_possible_actor_unit(nmap, paction->id, punit)) {
       return TRUE;
     }
   } action_by_result_iterate_end;
   action_by_result_iterate(paction, ACTRES_PARADROP_CONQUER) {
-    if (action_maybe_possible_actor_unit(paction->id, punit)) {
+    if (action_maybe_possible_actor_unit(nmap, paction->id, punit)) {
       return TRUE;
     }
   } action_by_result_iterate_end;
diff --git a/server/unithand.c b/server/unithand.c
index 841c4acfc4..7b5af29c11 100644
--- a/server/unithand.c
+++ b/server/unithand.c
@@ -2090,6 +2090,7 @@ void handle_unit_get_actions(struct connection *pc,
   int actor_target_distance;
   const struct player_tile *plrtile;
   int target_extra_id = target_extra_id_client;
+  const struct civ_map *nmap = &(wld.map);
 
   /* No potentially legal action is known yet. If none is found the player
    * should get an explanation. */
@@ -2101,7 +2102,7 @@ void handle_unit_get_actions(struct connection *pc,
 
   actor_player = pc->playing;
   actor_unit = game_unit_by_number(actor_unit_id);
-  target_tile = index_to_tile(&(wld.map), target_tile_id);
+  target_tile = index_to_tile(nmap, target_tile_id);
 
   /* Initialize the action probabilities. */
   action_iterate(act) {
@@ -2180,7 +2181,7 @@ void handle_unit_get_actions(struct connection *pc,
           probabilities[act] = action_prob_vs_city(actor_unit, act,
                                                    target_city);
         } else if (!tile_is_seen(target_tile, actor_player)
-                   && action_maybe_possible_actor_unit(act, actor_unit)
+                   && action_maybe_possible_actor_unit(nmap, act, actor_unit)
                    && action_id_distance_accepted(act,
                                                   actor_target_distance)) {
           /* The target city is non existing. The player isn't aware of this
-- 
2.43.0

