From 1c6a936cb3c25da2da9287e6259b22112ec1c442 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sun, 7 Apr 2024 02:37:12 +0300
Subject: [PATCH 57/57] Unhardcode wld.map from
 is_action_enabled_unit_on_extras()

See RM #410

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 ai/default/daitools.c              | 8 ++++----
 common/actions.c                   | 7 +++----
 common/actions.h                   | 3 ++-
 common/unit.c                      | 2 +-
 server/actiontools.c               | 4 ++--
 server/scripting/api_server_edit.c | 4 ++--
 server/unithand.c                  | 2 +-
 7 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/ai/default/daitools.c b/ai/default/daitools.c
index c9cf65604b..77664f022e 100644
--- a/ai/default/daitools.c
+++ b/ai/default/daitools.c
@@ -968,25 +968,25 @@ bool dai_unit_attack(struct ai_type *ait, struct unit *punit, struct tile *ptile
     unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
                    0, "", ACTION_TRANSPORT_DISEMBARK4);
   } else if (tile_has_claimable_base(ptile, unit_type_get(punit))
-             && is_action_enabled_unit_on_extras(ACTION_CONQUER_EXTRAS,
+             && is_action_enabled_unit_on_extras(nmap, ACTION_CONQUER_EXTRAS,
                                                  punit, ptile, NULL)) {
     /* Choose "Conquer Extras". */
     unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
                    0, "", ACTION_CONQUER_EXTRAS);
   } else if (tile_has_claimable_base(ptile, unit_type_get(punit))
-             && is_action_enabled_unit_on_extras(ACTION_CONQUER_EXTRAS2,
+             && is_action_enabled_unit_on_extras(nmap, ACTION_CONQUER_EXTRAS2,
                                                  punit, ptile, NULL)) {
     /* Choose "Conquer Extras 2". */
     unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
                    0, "", ACTION_CONQUER_EXTRAS2);
   } else if (tile_has_claimable_base(ptile, unit_type_get(punit))
-             && is_action_enabled_unit_on_extras(ACTION_CONQUER_EXTRAS3,
+             && is_action_enabled_unit_on_extras(nmap, ACTION_CONQUER_EXTRAS3,
                                                  punit, ptile, NULL)) {
     /* Choose "Conquer Extras 3". */
     unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
                    0, "", ACTION_CONQUER_EXTRAS3);
   } else if (tile_has_claimable_base(ptile, unit_type_get(punit))
-             && is_action_enabled_unit_on_extras(ACTION_CONQUER_EXTRAS4,
+             && is_action_enabled_unit_on_extras(nmap, ACTION_CONQUER_EXTRAS4,
                                                  punit, ptile, NULL)) {
     /* Choose "Conquer Extras 4". */
     unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
diff --git a/common/actions.c b/common/actions.c
index e3e74c73ec..f1231f2642 100644
--- a/common/actions.c
+++ b/common/actions.c
@@ -2307,7 +2307,7 @@ struct action *action_is_blocked_by(const struct action *act,
         /* Can't be enabled. No target. */
         continue;
       }
-      if (is_action_enabled_unit_on_extras(blocker->id,
+      if (is_action_enabled_unit_on_extras(nmap, blocker->id,
                                            actor_unit, target_tile, NULL)) {
         return blocker;
       }
@@ -3359,13 +3359,12 @@ is_action_enabled_unit_on_extras_full(const struct civ_map *nmap,
 
   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,
+bool is_action_enabled_unit_on_extras(const struct civ_map *nmap,
+                                      const action_id wanted_action,
                                       const struct unit *actor_unit,
                                       const struct tile *target_tile,
                                       const struct extra_type *target_extra)
 {
-  const struct civ_map *nmap = &(wld.map);
-
   return is_action_enabled_unit_on_extras_full(nmap, wanted_action, actor_unit,
                                                unit_home(actor_unit),
                                                unit_tile(actor_unit),
diff --git a/common/actions.h b/common/actions.h
index e88c6f3559..0e5df224bc 100644
--- a/common/actions.h
+++ b/common/actions.h
@@ -541,7 +541,8 @@ bool is_action_enabled_unit_on_tile(const struct civ_map *nmap,
                                     const struct tile *target_tile,
                                     const struct extra_type *target_extra);
 
-bool is_action_enabled_unit_on_extras(const action_id wanted_action,
+bool is_action_enabled_unit_on_extras(const struct civ_map *nmap,
+                                      const action_id wanted_action,
                                       const struct unit *actor_unit,
                                       const struct tile *target,
                                       const struct extra_type *tgt_extra);
diff --git a/common/unit.c b/common/unit.c
index 6dc31a24e5..dcb338dd15 100644
--- a/common/unit.c
+++ b/common/unit.c
@@ -968,7 +968,7 @@ bool can_unit_do_activity_targeted_at(const struct civ_map *nmap,
       return is_action_enabled_unit_on_tile(nmap, paction->id,            \
                                             punit, ptile, target);        \
     case ATK_EXTRAS:                                                      \
-      return is_action_enabled_unit_on_extras(paction->id,                \
+      return is_action_enabled_unit_on_extras(nmap, paction->id,          \
                                               punit, ptile, target);      \
     case ATK_CITY:                                                        \
     case ATK_UNIT:                                                        \
diff --git a/server/actiontools.c b/server/actiontools.c
index 06ef954380..590a46a215 100644
--- a/server/actiontools.c
+++ b/server/actiontools.c
@@ -1047,7 +1047,7 @@ action_auto_perf_unit_do(const enum action_auto_perf_cause cause,
         break;
       case ATK_EXTRAS:
         if (tgt_tile
-            && is_action_enabled_unit_on_extras(act, actor,
+            && is_action_enabled_unit_on_extras(nmap, act, actor,
                                                 tgt_tile, target_extra)) {
           perform_action_to(act, actor, tgt_tile->index,
                             target_extra ? extra_number(target_extra) : -1);
@@ -1143,7 +1143,7 @@ action_auto_perf_unit_prob(const enum action_auto_perf_cause cause,
         break;
       case ATK_EXTRAS:
         if (tgt_tile
-            && is_action_enabled_unit_on_extras(act, actor,
+            && is_action_enabled_unit_on_extras(nmap, act, actor,
                                                 tgt_tile, target_extra)) {
           current = action_prob_vs_extras(actor, act,
                                           tgt_tile, target_extra);
diff --git a/server/scripting/api_server_edit.c b/server/scripting/api_server_edit.c
index 00efe26516..0c11677632 100644
--- a/server/scripting/api_server_edit.c
+++ b/server/scripting/api_server_edit.c
@@ -383,7 +383,7 @@ bool api_edit_perform_action_unit_vs_tile(lua_State *L, Unit *punit,
                                              tgt, NULL);
     break;
   case ATK_EXTRAS:
-    enabled = is_action_enabled_unit_on_extras(paction->id, punit,
+    enabled = is_action_enabled_unit_on_extras(nmap, paction->id, punit,
                                                tgt, NULL);
     break;
   case ATK_CITY:
@@ -445,7 +445,7 @@ bool api_edit_perform_action_unit_vs_tile_extra(lua_State *L, Unit *punit,
                                              tgt, sub_target);
     break;
   case ATK_EXTRAS:
-    enabled = is_action_enabled_unit_on_extras(paction->id, punit,
+    enabled = is_action_enabled_unit_on_extras(nmap, paction->id, punit,
                                                tgt, sub_target);
     break;
   case ATK_CITY:
diff --git a/server/unithand.c b/server/unithand.c
index e53bfb20a2..63f644aebf 100644
--- a/server/unithand.c
+++ b/server/unithand.c
@@ -3602,7 +3602,7 @@ bool unit_perform_action(struct player *pplayer,
 
 #define ACTION_PERFORM_UNIT_EXTRAS(action, actor, target, action_performer)\
   if (target_tile                                                         \
-      && is_action_enabled_unit_on_extras(action_type,                    \
+      && is_action_enabled_unit_on_extras(nmap, action_type,              \
                                           actor_unit, target_tile,        \
                                           target_extra)) {                \
     bool success;                                                         \
-- 
2.43.0

