From 4a8663b50cf0050c457205b09150712da30ccb0d Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sat, 24 Feb 2024 07:31:52 +0200
Subject: [PATCH 36/36] Unhardcode wld.map from is_action_possible()

See RM #273

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 common/actions.c | 53 +++++++++++++++++++++++++++++-------------------
 1 file changed, 32 insertions(+), 21 deletions(-)

diff --git a/common/actions.c b/common/actions.c
index 4cd0c3f2b5..38e66d526c 100644
--- a/common/actions.c
+++ b/common/actions.c
@@ -2754,7 +2754,8 @@ action_hard_reqs_actor(const struct civ_map *nmap,
   context. This may or may not be legal depending on the action.
 **************************************************************************/
 static enum fc_tristate
-is_action_possible(const action_id wanted_action,
+is_action_possible(const struct civ_map *nmap,
+                   const action_id wanted_action,
                    const struct req_context *actor,
                    const struct req_context *target,
                    const struct extra_type *target_extra,
@@ -2764,7 +2765,6 @@ is_action_possible(const action_id wanted_action,
   enum fc_tristate out;
   struct action *paction = action_by_number(wanted_action);
   enum action_target_kind tkind = action_get_target_kind(paction);
-  struct civ_map *nmap = &(wld.map);
 
   if (actor == NULL) {
     actor = req_context_empty();
@@ -2929,7 +2929,8 @@ static bool is_enabler_active(const struct action_enabler *enabler,
   Passing NULL for actor or target is equivalent to passing an empty
   context. This may or may not be legal depending on the action.
 **************************************************************************/
-static bool is_action_enabled(const action_id wanted_action,
+static bool is_action_enabled(const struct civ_map *nmap,
+                              const action_id wanted_action,
                               const struct req_context *actor,
                               const struct req_context *target,
                               const struct extra_type *target_extra,
@@ -2937,7 +2938,7 @@ static bool is_action_enabled(const action_id wanted_action,
 {
   enum fc_tristate possible;
 
-  possible = is_action_possible(wanted_action, actor, target, target_extra,
+  possible = is_action_possible(nmap, wanted_action, actor, target, target_extra,
                                 TRUE, actor_home);
 
   if (possible != TRI_YES) {
@@ -2964,7 +2965,7 @@ static bool is_action_enabled(const action_id wanted_action,
   Returns TRUE if actor_unit can do wanted_action to target_city as far as
   action enablers are concerned.
 
-  See note in is_action_enabled for why the action may still be disabled.
+  See note in is_action_enabled() for why the action may still be disabled.
 **************************************************************************/
 static bool
 is_action_enabled_unit_on_city_full(const action_id wanted_action,
@@ -2975,6 +2976,7 @@ is_action_enabled_unit_on_city_full(const action_id wanted_action,
 {
   const struct impr_type *target_building;
   const struct unit_type *target_utype;
+  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. */
@@ -3006,7 +3008,7 @@ is_action_enabled_unit_on_city_full(const action_id wanted_action,
   target_building = tgt_city_local_building(target_city);
   target_utype = tgt_city_local_utype(target_city);
 
-  return is_action_enabled(wanted_action,
+  return is_action_enabled(nmap, wanted_action,
                            &(const struct req_context) {
                              .player = unit_owner(actor_unit),
                              .city = tile_city(actor_tile),
@@ -3029,7 +3031,7 @@ is_action_enabled_unit_on_city_full(const action_id wanted_action,
   Returns TRUE if actor_unit can do wanted_action to target_city as far as
   action enablers are concerned.
 
-  See note in is_action_enabled for why the action may still be disabled.
+  See note in is_action_enabled() for why the action may still be disabled.
 **************************************************************************/
 bool is_action_enabled_unit_on_city(const action_id wanted_action,
                                     const struct unit *actor_unit,
@@ -3045,7 +3047,7 @@ bool is_action_enabled_unit_on_city(const action_id wanted_action,
   Returns TRUE if actor_unit can do wanted_action to target_unit as far as
   action enablers are concerned.
 
-  See note in is_action_enabled for why the action may still be disabled.
+  See note in is_action_enabled() for why the action may still be disabled.
 **************************************************************************/
 static bool
 is_action_enabled_unit_on_unit_full(const action_id wanted_action,
@@ -3054,6 +3056,8 @@ is_action_enabled_unit_on_unit_full(const action_id wanted_action,
                                     const struct tile *actor_tile,
                                     const struct unit *target_unit)
 {
+  const struct civ_map *nmap = &(wld.map);
+
   if (actor_unit == NULL || target_unit == NULL) {
     /* Can't do an action when actor or target are missing. */
     return FALSE;
@@ -3081,7 +3085,7 @@ is_action_enabled_unit_on_unit_full(const action_id wanted_action,
     return FALSE;
   }
 
-  return is_action_enabled(wanted_action,
+  return is_action_enabled(nmap, wanted_action,
                            &(const struct req_context) {
                              .player = unit_owner(actor_unit),
                              .city = tile_city(actor_tile),
@@ -3104,7 +3108,7 @@ is_action_enabled_unit_on_unit_full(const action_id wanted_action,
   Returns TRUE if actor_unit can do wanted_action to target_unit as far as
   action enablers are concerned.
 
-  See note in is_action_enabled for why the action may still be disabled.
+  See note in is_action_enabled() for why the action may still be disabled.
 **************************************************************************/
 bool is_action_enabled_unit_on_unit(const action_id wanted_action,
                                     const struct unit *actor_unit,
@@ -3120,7 +3124,7 @@ bool is_action_enabled_unit_on_unit(const action_id wanted_action,
   Returns TRUE if actor_unit can do wanted_action to all units on the
   target_tile as far as action enablers are concerned.
 
-  See note in is_action_enabled for why the action may still be disabled.
+  See note in is_action_enabled() for why the action may still be disabled.
 **************************************************************************/
 static bool
 is_action_enabled_unit_on_units_full(const action_id wanted_action,
@@ -3130,6 +3134,7 @@ is_action_enabled_unit_on_units_full(const action_id wanted_action,
                                      const struct tile *target_tile)
 {
   const struct req_context *actor_ctxt;
+  const struct civ_map *nmap = &(wld.map);
 
   if (actor_unit == NULL || target_tile == NULL
       || unit_list_size(target_tile->units) == 0) {
@@ -3168,7 +3173,7 @@ is_action_enabled_unit_on_units_full(const action_id wanted_action,
   };
 
   unit_list_iterate(target_tile->units, target_unit) {
-    if (!is_action_enabled(wanted_action, actor_ctxt,
+    if (!is_action_enabled(nmap, wanted_action, actor_ctxt,
                            &(const struct req_context) {
                              .player = unit_owner(target_unit),
                              .city = tile_city(unit_tile(target_unit)),
@@ -3190,7 +3195,7 @@ is_action_enabled_unit_on_units_full(const action_id wanted_action,
   Returns TRUE if actor_unit can do wanted_action to all units on the
   target_tile as far as action enablers are concerned.
 
-  See note in is_action_enabled for why the action may still be disabled.
+  See note in is_action_enabled() for why the action may still be disabled.
 **************************************************************************/
 bool is_action_enabled_unit_on_units(const action_id wanted_action,
                                      const struct unit *actor_unit,
@@ -3206,7 +3211,7 @@ bool is_action_enabled_unit_on_units(const action_id wanted_action,
   Returns TRUE if actor_unit can do wanted_action to the target_tile as far
   as action enablers are concerned.
 
-  See note in is_action_enabled for why the action may still be disabled.
+  See note in is_action_enabled() for why the action may still be disabled.
 **************************************************************************/
 static bool
 is_action_enabled_unit_on_tile_full(const action_id wanted_action,
@@ -3216,6 +3221,8 @@ is_action_enabled_unit_on_tile_full(const action_id wanted_action,
                                     const struct tile *target_tile,
                                     const struct extra_type *target_extra)
 {
+  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. */
     return FALSE;
@@ -3243,7 +3250,7 @@ is_action_enabled_unit_on_tile_full(const action_id wanted_action,
     return FALSE;
   }
 
-  return is_action_enabled(wanted_action,
+  return is_action_enabled(nmap, wanted_action,
                            &(const struct req_context) {
                              .player = unit_owner(actor_unit),
                              .city = tile_city(actor_tile),
@@ -3264,7 +3271,7 @@ is_action_enabled_unit_on_tile_full(const action_id wanted_action,
   Returns TRUE if actor_unit can do wanted_action to the target_tile as far
   as action enablers are concerned.
 
-  See note in is_action_enabled for why the action may still be disabled.
+  See note in is_action_enabled() for why the action may still be disabled.
 **************************************************************************/
 bool is_action_enabled_unit_on_tile(const action_id wanted_action,
                                     const struct unit *actor_unit,
@@ -3281,7 +3288,7 @@ bool is_action_enabled_unit_on_tile(const action_id wanted_action,
   Returns TRUE if actor_unit can do wanted_action to the extras at
   target_tile as far as action enablers are concerned.
 
-  See note in is_action_enabled for why the action may still be disabled.
+  See note in is_action_enabled() for why the action may still be disabled.
 **************************************************************************/
 static bool
 is_action_enabled_unit_on_extras_full(const action_id wanted_action,
@@ -3291,6 +3298,8 @@ is_action_enabled_unit_on_extras_full(const action_id wanted_action,
                                       const struct tile *target_tile,
                                       const struct extra_type *target_extra)
 {
+  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. */
     return FALSE;
@@ -3318,7 +3327,7 @@ is_action_enabled_unit_on_extras_full(const action_id wanted_action,
     return FALSE;
   }
 
-  return is_action_enabled(wanted_action,
+  return is_action_enabled(nmap, wanted_action,
                            &(const struct req_context) {
                              .player = unit_owner(actor_unit),
                              .city = tile_city(actor_tile),
@@ -3339,7 +3348,7 @@ is_action_enabled_unit_on_extras_full(const action_id wanted_action,
   Returns TRUE if actor_unit can do wanted_action to the extras at
   target_tile as far as action enablers are concerned.
 
-  See note in is_action_enabled for why the action may still be disabled.
+  See note in is_action_enabled() for why the action may still be disabled.
 **************************************************************************/
 bool is_action_enabled_unit_on_extras(const action_id wanted_action,
                                       const struct unit *actor_unit,
@@ -3365,6 +3374,8 @@ is_action_enabled_unit_on_self_full(const action_id wanted_action,
                                     const struct city *actor_home,
                                     const struct tile *actor_tile)
 {
+  const struct civ_map *nmap = &(wld.map);
+
   if (actor_unit == NULL) {
     /* Can't do an action when the actor is missing. */
     return FALSE;
@@ -3392,7 +3403,7 @@ is_action_enabled_unit_on_self_full(const action_id wanted_action,
     return FALSE;
   }
 
-  return is_action_enabled(wanted_action,
+  return is_action_enabled(nmap, wanted_action,
                            &(const struct req_context) {
                              .player = unit_owner(actor_unit),
                              .city = tile_city(actor_tile),
@@ -3773,7 +3784,7 @@ action_prob(const action_id wanted_action,
     target = req_context_empty();
   }
 
-  known = is_action_possible(wanted_action, actor, target,
+  known = is_action_possible(nmap, wanted_action, actor, target,
                              target_extra,
                              FALSE, actor_home);
 
-- 
2.43.0

