From b5f2948bcdb850a322b99b394d1ef0a319c4ccca Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Mon, 1 Apr 2024 01:52:09 +0300
Subject: [PATCH 48/48] Unhardcode wld.map from
 is_action_enabled_unit_on_tile()

See RM #390

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 ai/default/aiparatrooper.c         |  2 +-
 ai/default/daitools.c              | 60 +++++++++++++++---------------
 common/actions.c                   |  7 ++--
 common/actions.h                   |  3 +-
 common/unit.c                      | 18 ++++-----
 server/actiontools.c               |  7 ++--
 server/advisors/advgoto.c          | 28 +++++++-------
 server/scripting/api_server_edit.c |  4 +-
 server/unithand.c                  | 24 ++++++------
 server/unittools.c                 |  8 ++--
 10 files changed, 82 insertions(+), 79 deletions(-)

diff --git a/ai/default/aiparatrooper.c b/ai/default/aiparatrooper.c
index 803f53ad4b..379438285a 100644
--- a/ai/default/aiparatrooper.c
+++ b/ai/default/aiparatrooper.c
@@ -248,7 +248,7 @@ void dai_manage_paratrooper(struct ai_type *ait, struct player *pplayer,
                                                tile_city(ptile_dest), NULL,
                                                ptile_dest, NULL));
         } else {
-          possible = is_action_enabled_unit_on_tile(paction->id, punit,
+          possible = is_action_enabled_unit_on_tile(nmap, paction->id, punit,
                                                     ptile_dest, NULL);
         }
 
diff --git a/ai/default/daitools.c b/ai/default/daitools.c
index e3e3466898..48c0dade56 100644
--- a/ai/default/daitools.c
+++ b/ai/default/daitools.c
@@ -860,7 +860,7 @@ 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_NUKE_UNITS);
   } else if (action_id_get_target_kind(ACTION_NUKE) == ATK_TILE
-             && is_action_enabled_unit_on_tile(ACTION_NUKE,
+             && is_action_enabled_unit_on_tile(nmap, ACTION_NUKE,
                                                punit, ptile, NULL)) {
     /* Choose "Explode Nuclear". */
     unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
@@ -873,7 +873,7 @@ bool dai_unit_attack(struct ai_type *ait, struct unit *punit, struct tile *ptile
     unit_do_action(unit_owner(punit), punit->id, tcity->id,
                    0, "", ACTION_NUKE);
   } else if (action_id_get_target_kind(ACTION_NUKE_CITY) == ATK_TILE
-             && is_action_enabled_unit_on_tile(ACTION_NUKE_CITY,
+             && is_action_enabled_unit_on_tile(nmap, ACTION_NUKE_CITY,
                                                punit, ptile, NULL)) {
     /* Choose "Nuke City". */
     unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
@@ -947,22 +947,22 @@ bool dai_unit_attack(struct ai_type *ait, struct unit *punit, struct tile *ptile
     /* "Transport Embark 4". */
     unit_do_action(unit_owner(punit), punit->id, ptrans->id,
                    0, "", ACTION_TRANSPORT_EMBARK4);
-  } else if (is_action_enabled_unit_on_tile(ACTION_TRANSPORT_DISEMBARK1,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_TRANSPORT_DISEMBARK1,
                                             punit, ptile, NULL)) {
     /* "Transport Disembark". */
     unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
                    0, "", ACTION_TRANSPORT_DISEMBARK1);
-  } else if (is_action_enabled_unit_on_tile(ACTION_TRANSPORT_DISEMBARK2,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_TRANSPORT_DISEMBARK2,
                                             punit, ptile, NULL)) {
     /* "Transport Disembark 2". */
     unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
                    0, "", ACTION_TRANSPORT_DISEMBARK2);
-  } else if (is_action_enabled_unit_on_tile(ACTION_TRANSPORT_DISEMBARK3,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_TRANSPORT_DISEMBARK3,
                                             punit, ptile, NULL)) {
     /* "Transport Disembark 3". */
     unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
                    0, "", ACTION_TRANSPORT_DISEMBARK3);
-  } else if (is_action_enabled_unit_on_tile(ACTION_TRANSPORT_DISEMBARK4,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_TRANSPORT_DISEMBARK4,
                                             punit, ptile, NULL)) {
     /* "Transport Disembark 4". */
     unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
@@ -991,52 +991,52 @@ bool dai_unit_attack(struct ai_type *ait, struct unit *punit, struct tile *ptile
     /* Choose "Conquer Extras 4". */
     unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
                    0, "", ACTION_CONQUER_EXTRAS4);
-  } else if (is_action_enabled_unit_on_tile(ACTION_HUT_ENTER,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_ENTER,
                                             punit, ptile, NULL)) {
     /* Choose "Enter Hut". */
     unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
                    0, "", ACTION_HUT_ENTER);
-  } else if (is_action_enabled_unit_on_tile(ACTION_HUT_ENTER2,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_ENTER2,
                                             punit, ptile, NULL)) {
     /* Choose "Enter Hut 2". */
     unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
                    0, "", ACTION_HUT_ENTER2);
-  } else if (is_action_enabled_unit_on_tile(ACTION_HUT_ENTER3,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_ENTER3,
                                             punit, ptile, NULL)) {
     /* Choose "Enter Hut 3". */
     unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
                    0, "", ACTION_HUT_ENTER3);
-  } else if (is_action_enabled_unit_on_tile(ACTION_HUT_ENTER4,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_ENTER4,
                                             punit, ptile, NULL)) {
     /* Choose "Enter Hut 4". */
     unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
                    0, "", ACTION_HUT_ENTER4);
-  } else if (is_action_enabled_unit_on_tile(ACTION_HUT_FRIGHTEN,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_FRIGHTEN,
                                             punit, ptile, NULL)) {
     /* Choose "Frighten Hut". */
     unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
                    0, "", ACTION_HUT_FRIGHTEN);
-  } else if (is_action_enabled_unit_on_tile(ACTION_HUT_FRIGHTEN2,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_FRIGHTEN2,
                                             punit, ptile, NULL)) {
     /* Choose "Frighten Hut 2". */
     unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
                    0, "", ACTION_HUT_FRIGHTEN2);
-  } else if (is_action_enabled_unit_on_tile(ACTION_HUT_FRIGHTEN3,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_FRIGHTEN3,
                                             punit, ptile, NULL)) {
     /* Choose "Frighten Hut 3". */
     unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
                    0, "", ACTION_HUT_FRIGHTEN3);
-  } else if (is_action_enabled_unit_on_tile(ACTION_HUT_FRIGHTEN4,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_FRIGHTEN4,
                                             punit, ptile, NULL)) {
     /* Choose "Frighten Hut 4". */
     unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
                    0, "", ACTION_HUT_FRIGHTEN4);
-  } else if (is_action_enabled_unit_on_tile(ACTION_UNIT_MOVE,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_UNIT_MOVE,
                                             punit, ptile, NULL)) {
     /* Choose "Unit Move". */
     unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
                    0, "", ACTION_UNIT_MOVE);
-  } else if (is_action_enabled_unit_on_tile(ACTION_UNIT_MOVE2,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_UNIT_MOVE2,
                                             punit, ptile, NULL)) {
     /* Choose "Unit Move 2". */
     unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
@@ -1145,59 +1145,59 @@ bool dai_unit_move(struct ai_type *ait, struct unit *punit, struct tile *ptile)
                                                punit, ptrans)) {
     /* "Transport Embark 4". */
     paction = action_by_number(ACTION_TRANSPORT_EMBARK4);
-  } else if (is_action_enabled_unit_on_tile(ACTION_TRANSPORT_DISEMBARK1,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_TRANSPORT_DISEMBARK1,
                                             punit, ptile, NULL)) {
     /* "Transport Disembark". */
     paction = action_by_number(ACTION_TRANSPORT_DISEMBARK1);
-  } else if (is_action_enabled_unit_on_tile(ACTION_TRANSPORT_DISEMBARK2,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_TRANSPORT_DISEMBARK2,
                                             punit, ptile, NULL)) {
     /* "Transport Disembark 2". */
     paction = action_by_number(ACTION_TRANSPORT_DISEMBARK2);
-  } else if (is_action_enabled_unit_on_tile(ACTION_TRANSPORT_DISEMBARK3,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_TRANSPORT_DISEMBARK3,
                                             punit, ptile, NULL)) {
     /* "Transport Disembark 3". */
     paction = action_by_number(ACTION_TRANSPORT_DISEMBARK3);
-  } else if (is_action_enabled_unit_on_tile(ACTION_TRANSPORT_DISEMBARK4,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_TRANSPORT_DISEMBARK4,
                                             punit, ptile, NULL)) {
     /* "Transport Disembark 4". */
     paction = action_by_number(ACTION_TRANSPORT_DISEMBARK4);
-  } else if (is_action_enabled_unit_on_tile(ACTION_HUT_ENTER,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_ENTER,
                                             punit, ptile, NULL)) {
     /* "Enter Hut". */
     paction = action_by_number(ACTION_HUT_ENTER);
-  } else if (is_action_enabled_unit_on_tile(ACTION_HUT_ENTER2,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_ENTER2,
                                             punit, ptile, NULL)) {
     /* "Enter Hut 2". */
     paction = action_by_number(ACTION_HUT_ENTER2);
-  } else if (is_action_enabled_unit_on_tile(ACTION_HUT_ENTER3,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_ENTER3,
                                             punit, ptile, NULL)) {
     /* "Enter Hut 3". */
     paction = action_by_number(ACTION_HUT_ENTER3);
-  } else if (is_action_enabled_unit_on_tile(ACTION_HUT_ENTER4,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_ENTER4,
                                             punit, ptile, NULL)) {
     /* "Enter Hut 4". */
     paction = action_by_number(ACTION_HUT_ENTER4);
-  } else if (is_action_enabled_unit_on_tile(ACTION_HUT_FRIGHTEN,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_FRIGHTEN,
                                             punit, ptile, NULL)) {
     /* "Frighten Hut". */
     paction = action_by_number(ACTION_HUT_FRIGHTEN);
-  } else if (is_action_enabled_unit_on_tile(ACTION_HUT_FRIGHTEN2,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_FRIGHTEN2,
                                             punit, ptile, NULL)) {
     /* "Frighten Hut 2". */
     paction = action_by_number(ACTION_HUT_FRIGHTEN2);
-  } else if (is_action_enabled_unit_on_tile(ACTION_HUT_FRIGHTEN3,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_FRIGHTEN3,
                                             punit, ptile, NULL)) {
     /* "Frighten Hut 3". */
     paction = action_by_number(ACTION_HUT_FRIGHTEN3);
-  } else if (is_action_enabled_unit_on_tile(ACTION_HUT_FRIGHTEN4,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_FRIGHTEN4,
                                             punit, ptile, NULL)) {
     /* "Frighten Hut 4". */
     paction = action_by_number(ACTION_HUT_FRIGHTEN4);
-  } else if (is_action_enabled_unit_on_tile(ACTION_UNIT_MOVE,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_UNIT_MOVE,
                                             punit, ptile, NULL)) {
     /* "Unit Move". */
     paction = action_by_number(ACTION_UNIT_MOVE);
-  } else if (is_action_enabled_unit_on_tile(ACTION_UNIT_MOVE2,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_UNIT_MOVE2,
                                             punit, ptile, NULL)) {
     /* "Unit Move 2". */
     paction = action_by_number(ACTION_UNIT_MOVE2);
diff --git a/common/actions.c b/common/actions.c
index e8e5d634a3..c4712b02cc 100644
--- a/common/actions.c
+++ b/common/actions.c
@@ -2293,7 +2293,7 @@ struct action *action_is_blocked_by(const struct action *act,
         /* Can't be enabled. No target. */
         continue;
       }
-      if (is_action_enabled_unit_on_tile(blocker->id,
+      if (is_action_enabled_unit_on_tile(nmap, blocker->id,
                                          actor_unit, target_tile, NULL)) {
         return blocker;
       }
@@ -3278,13 +3278,12 @@ is_action_enabled_unit_on_tile_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_tile(const action_id wanted_action,
+bool is_action_enabled_unit_on_tile(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_tile_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 37397c0198..285aa49876 100644
--- a/common/actions.h
+++ b/common/actions.h
@@ -535,7 +535,8 @@ bool is_action_enabled_unit_on_units(const struct civ_map *nmap,
                                      const struct unit *actor_unit,
                                      const struct tile *target_tile);
 
-bool is_action_enabled_unit_on_tile(const action_id wanted_action,
+bool is_action_enabled_unit_on_tile(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);
diff --git a/common/unit.c b/common/unit.c
index 343e1d1d9f..6dc31a24e5 100644
--- a/common/unit.c
+++ b/common/unit.c
@@ -965,7 +965,7 @@ bool can_unit_do_activity_targeted_at(const struct civ_map *nmap,
 {                                                                         \
     switch (action_get_target_kind(paction)) {                            \
     case ATK_TILE:                                                        \
-      return is_action_enabled_unit_on_tile(paction->id,                  \
+      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,                \
@@ -992,35 +992,35 @@ bool can_unit_do_activity_targeted_at(const struct civ_map *nmap,
     /* The call below doesn't support actor tile speculation. */
     fc_assert_msg(unit_tile(punit) == ptile,
                   "Please use action_speculate_unit_on_tile()");
-    return is_action_enabled_unit_on_tile(ACTION_CLEAN,
+    return is_action_enabled_unit_on_tile(nmap, ACTION_CLEAN,
                                           punit, ptile, target);
 
   case ACTIVITY_MINE:
     /* The call below doesn't support actor tile speculation. */
     fc_assert_msg(unit_tile(punit) == ptile,
                   "Please use action_speculate_unit_on_tile()");
-    return is_action_enabled_unit_on_tile(ACTION_MINE, punit,
+    return is_action_enabled_unit_on_tile(nmap, ACTION_MINE, punit,
                                           ptile, target);
 
   case ACTIVITY_PLANT:
     /* The call below doesn't support actor tile speculation. */
     fc_assert_msg(unit_tile(punit) == ptile,
                   "Please use action_speculate_unit_on_tile()");
-    return is_action_enabled_unit_on_tile(ACTION_PLANT,
+    return is_action_enabled_unit_on_tile(nmap, ACTION_PLANT,
                                           punit, ptile, NULL);
 
   case ACTIVITY_IRRIGATE:
     /* The call below doesn't support actor tile speculation. */
     fc_assert_msg(unit_tile(punit) == ptile,
                   "Please use action_speculate_unit_on_tile()");
-    return is_action_enabled_unit_on_tile(ACTION_IRRIGATE, punit,
+    return is_action_enabled_unit_on_tile(nmap, ACTION_IRRIGATE, punit,
                                           ptile, target);
 
   case ACTIVITY_CULTIVATE:
     /* The call below doesn't support actor tile speculation. */
     fc_assert_msg(unit_tile(punit) == ptile,
                   "Please use action_speculate_unit_on_tile()");
-    return is_action_enabled_unit_on_tile(ACTION_CULTIVATE,
+    return is_action_enabled_unit_on_tile(nmap, ACTION_CULTIVATE,
                                           punit, ptile, NULL);
 
   case ACTIVITY_FORTIFYING:
@@ -1037,14 +1037,14 @@ bool can_unit_do_activity_targeted_at(const struct civ_map *nmap,
     /* The call below doesn't support actor tile speculation. */
     fc_assert_msg(unit_tile(punit) == ptile,
                   "Please use action_speculate_unit_on_tile()");
-    return is_action_enabled_unit_on_tile(ACTION_BASE,
+    return is_action_enabled_unit_on_tile(nmap, ACTION_BASE,
                                           punit, ptile, target);
 
   case ACTIVITY_GEN_ROAD:
     /* The call below doesn't support actor tile speculation. */
     fc_assert_msg(unit_tile(punit) == ptile,
                   "Please use action_speculate_unit_on_tile()");
-    return is_action_enabled_unit_on_tile(ACTION_ROAD,
+    return is_action_enabled_unit_on_tile(nmap, ACTION_ROAD,
                                           punit, ptile, target);
 
   case ACTIVITY_SENTRY:
@@ -1068,7 +1068,7 @@ bool can_unit_do_activity_targeted_at(const struct civ_map *nmap,
     /* The call below doesn't support actor tile speculation. */
     fc_assert_msg(unit_tile(punit) == ptile,
                   "Please use action_speculate_unit_on_tile()");
-    return is_action_enabled_unit_on_tile(ACTION_TRANSFORM_TERRAIN,
+    return is_action_enabled_unit_on_tile(nmap, ACTION_TRANSFORM_TERRAIN,
                                           punit, ptile, NULL);
 
   case ACTIVITY_CONVERT:
diff --git a/server/actiontools.c b/server/actiontools.c
index 1248576905..f5280d0a20 100644
--- a/server/actiontools.c
+++ b/server/actiontools.c
@@ -1039,8 +1039,8 @@ action_auto_perf_unit_do(const enum action_auto_perf_cause cause,
         break;
       case ATK_TILE:
         if (tgt_tile
-            && is_action_enabled_unit_on_tile(act, actor, tgt_tile,
-                                              target_extra)) {
+            && is_action_enabled_unit_on_tile(nmap, act, actor,
+                                              tgt_tile, target_extra)) {
           perform_action_to(act, actor, tgt_tile->index,
                             target_extra ? extra_number(target_extra) : -1);
         }
@@ -1136,7 +1136,8 @@ action_auto_perf_unit_prob(const enum action_auto_perf_cause cause,
         break;
       case ATK_TILE:
         if (tgt_tile
-            && is_action_enabled_unit_on_tile(act, actor, tgt_tile, target_extra)) {
+            && is_action_enabled_unit_on_tile(nmap, act, actor,
+                                              tgt_tile, target_extra)) {
           current = action_prob_vs_tile(actor, act, tgt_tile, target_extra);
         }
         break;
diff --git a/server/advisors/advgoto.c b/server/advisors/advgoto.c
index 4255a9f367..8e17874e59 100644
--- a/server/advisors/advgoto.c
+++ b/server/advisors/advgoto.c
@@ -193,59 +193,59 @@ static bool adv_unit_move(struct unit *punit, struct tile *ptile)
                                                punit, ptrans)) {
     /* "Transport Embark 4". */
     paction = action_by_number(ACTION_TRANSPORT_EMBARK4);
-  } else if (is_action_enabled_unit_on_tile(ACTION_TRANSPORT_DISEMBARK1,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_TRANSPORT_DISEMBARK1,
                                             punit, ptile, NULL)) {
     /* "Transport Disembark". */
     paction = action_by_number(ACTION_TRANSPORT_DISEMBARK1);
-  } else if (is_action_enabled_unit_on_tile(ACTION_TRANSPORT_DISEMBARK2,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_TRANSPORT_DISEMBARK2,
                                             punit, ptile, NULL)) {
     /* "Transport Disembark 2". */
     paction = action_by_number(ACTION_TRANSPORT_DISEMBARK2);
-  } else if (is_action_enabled_unit_on_tile(ACTION_TRANSPORT_DISEMBARK3,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_TRANSPORT_DISEMBARK3,
                                             punit, ptile, NULL)) {
     /* "Transport Disembark 3". */
     paction = action_by_number(ACTION_TRANSPORT_DISEMBARK3);
-  } else if (is_action_enabled_unit_on_tile(ACTION_TRANSPORT_DISEMBARK4,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_TRANSPORT_DISEMBARK4,
                                             punit, ptile, NULL)) {
     /* "Transport Disembark 4". */
     paction = action_by_number(ACTION_TRANSPORT_DISEMBARK4);
-  } else if (is_action_enabled_unit_on_tile(ACTION_HUT_ENTER,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_ENTER,
                                             punit, ptile, NULL)) {
     /* "Enter Hut". */
     paction = action_by_number(ACTION_HUT_ENTER);
-  } else if (is_action_enabled_unit_on_tile(ACTION_HUT_ENTER2,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_ENTER2,
                                             punit, ptile, NULL)) {
     /* "Enter Hut 2". */
     paction = action_by_number(ACTION_HUT_ENTER2);
-  } else if (is_action_enabled_unit_on_tile(ACTION_HUT_ENTER3,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_ENTER3,
                                             punit, ptile, NULL)) {
     /* "Enter Hut 3". */
     paction = action_by_number(ACTION_HUT_ENTER3);
-  } else if (is_action_enabled_unit_on_tile(ACTION_HUT_ENTER4,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_ENTER4,
                                             punit, ptile, NULL)) {
     /* "Enter Hut 4". */
     paction = action_by_number(ACTION_HUT_ENTER4);
-  } else if (is_action_enabled_unit_on_tile(ACTION_HUT_FRIGHTEN,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_FRIGHTEN,
                                             punit, ptile, NULL)) {
     /* "Frighten Hut". */
     paction = action_by_number(ACTION_HUT_FRIGHTEN);
-  } else if (is_action_enabled_unit_on_tile(ACTION_HUT_FRIGHTEN2,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_FRIGHTEN2,
                                             punit, ptile, NULL)) {
     /* "Frighten Hut 2". */
     paction = action_by_number(ACTION_HUT_FRIGHTEN2);
-  } else if (is_action_enabled_unit_on_tile(ACTION_HUT_FRIGHTEN3,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_FRIGHTEN3,
                                             punit, ptile, NULL)) {
     /* "Frighten Hut 3". */
     paction = action_by_number(ACTION_HUT_FRIGHTEN3);
-  } else if (is_action_enabled_unit_on_tile(ACTION_HUT_FRIGHTEN4,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_FRIGHTEN4,
                                             punit, ptile, NULL)) {
     /* "Frighten Hut 4". */
     paction = action_by_number(ACTION_HUT_FRIGHTEN4);
-  } else if (is_action_enabled_unit_on_tile(ACTION_UNIT_MOVE,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_UNIT_MOVE,
                                             punit, ptile, NULL)) {
     /* "Unit Move". */
     paction = action_by_number(ACTION_UNIT_MOVE);
-  } else if (is_action_enabled_unit_on_tile(ACTION_UNIT_MOVE2,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_UNIT_MOVE2,
                                             punit, ptile, NULL)) {
     /* "Unit Move 2". */
     paction = action_by_number(ACTION_UNIT_MOVE2);
diff --git a/server/scripting/api_server_edit.c b/server/scripting/api_server_edit.c
index fccc9289db..9e2195e2e5 100644
--- a/server/scripting/api_server_edit.c
+++ b/server/scripting/api_server_edit.c
@@ -379,7 +379,7 @@ bool api_edit_perform_action_unit_vs_tile(lua_State *L, Unit *punit,
     enabled = is_action_enabled_unit_on_units(nmap, paction->id, punit, tgt);
     break;
   case ATK_TILE:
-    enabled = is_action_enabled_unit_on_tile(paction->id, punit,
+    enabled = is_action_enabled_unit_on_tile(nmap, paction->id, punit,
                                              tgt, NULL);
     break;
   case ATK_EXTRAS:
@@ -441,7 +441,7 @@ bool api_edit_perform_action_unit_vs_tile_extra(lua_State *L, Unit *punit,
     enabled = is_action_enabled_unit_on_units(nmap, paction->id, punit, tgt);
     break;
   case ATK_TILE:
-    enabled = is_action_enabled_unit_on_tile(paction->id, punit,
+    enabled = is_action_enabled_unit_on_tile(nmap, paction->id, punit,
                                              tgt, sub_target);
     break;
   case ATK_EXTRAS:
diff --git a/server/unithand.c b/server/unithand.c
index 723a4671fd..d35cd62a06 100644
--- a/server/unithand.c
+++ b/server/unithand.c
@@ -3574,7 +3574,7 @@ bool unit_perform_action(struct player *pplayer,
 
 #define ACTION_PERFORM_UNIT_TILE(action, actor, target, action_performer) \
   if (target_tile                                                         \
-      && is_action_enabled_unit_on_tile(action_type,                      \
+      && is_action_enabled_unit_on_tile(nmap, action_type,                \
                                         actor_unit, target_tile,          \
                                         target_extra)) {                  \
     bool success;                                                         \
@@ -5745,17 +5745,17 @@ bool unit_move_handling(struct unit *punit, struct tile *pdesttile,
 
   /*** Phase 2: OK now move the unit ***/
   /* This is a regular move, subject to the rules. */
-  if (is_action_enabled_unit_on_tile(ACTION_UNIT_MOVE,
+  if (is_action_enabled_unit_on_tile(nmap, ACTION_UNIT_MOVE,
                                      punit, pdesttile, NULL)) {
     return unit_perform_action(pplayer, punit->id, tile_index(pdesttile),
                                NO_TARGET, "", ACTION_UNIT_MOVE,
                                ACT_REQ_PLAYER);
-  } else if (is_action_enabled_unit_on_tile(ACTION_UNIT_MOVE2,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_UNIT_MOVE2,
                                             punit, pdesttile, NULL)) {
     return unit_perform_action(pplayer, punit->id, tile_index(pdesttile),
                                NO_TARGET, "", ACTION_UNIT_MOVE2,
                                ACT_REQ_PLAYER);
-  } else if (is_action_enabled_unit_on_tile(ACTION_UNIT_MOVE3,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_UNIT_MOVE3,
                                             punit, pdesttile, NULL)) {
     return unit_perform_action(pplayer, punit->id, tile_index(pdesttile),
                                NO_TARGET, "", ACTION_UNIT_MOVE3,
@@ -5792,49 +5792,49 @@ bool unit_move_handling(struct unit *punit, struct tile *pdesttile,
     return unit_perform_action(pplayer, punit->id, ptrans->id,
                                NO_TARGET, "", ACTION_TRANSPORT_EMBARK4,
                                ACT_REQ_PLAYER);
-  } else if (is_action_enabled_unit_on_tile(ACTION_TRANSPORT_DISEMBARK1,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_TRANSPORT_DISEMBARK1,
                                             punit, pdesttile, NULL)) {
     /* "Transport Disembark". */
     return unit_perform_action(pplayer, punit->id, tile_index(pdesttile),
                                NO_TARGET, "", ACTION_TRANSPORT_DISEMBARK1,
                                ACT_REQ_PLAYER);
-  } else if (is_action_enabled_unit_on_tile(ACTION_TRANSPORT_DISEMBARK2,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_TRANSPORT_DISEMBARK2,
                                             punit, pdesttile, NULL)) {
     /* "Transport Disembark 2". */
     return unit_perform_action(pplayer, punit->id, tile_index(pdesttile),
                                NO_TARGET, "", ACTION_TRANSPORT_DISEMBARK2,
                                ACT_REQ_PLAYER);
-  } else if (is_action_enabled_unit_on_tile(ACTION_TRANSPORT_DISEMBARK3,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_TRANSPORT_DISEMBARK3,
                                             punit, pdesttile, NULL)) {
     /* "Transport Disembark 3". */
     return unit_perform_action(pplayer, punit->id, tile_index(pdesttile),
                                NO_TARGET, "", ACTION_TRANSPORT_DISEMBARK3,
                                ACT_REQ_PLAYER);
-  } else if (is_action_enabled_unit_on_tile(ACTION_TRANSPORT_DISEMBARK4,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_TRANSPORT_DISEMBARK4,
                                             punit, pdesttile, NULL)) {
     /* "Transport Disembark 4". */
     return unit_perform_action(pplayer, punit->id, tile_index(pdesttile),
                                NO_TARGET, "", ACTION_TRANSPORT_DISEMBARK4,
                                ACT_REQ_PLAYER);
-  } else if (is_action_enabled_unit_on_tile(ACTION_HUT_ENTER,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_ENTER,
                                             punit, pdesttile, NULL)) {
     /* "Enter Hut". */
     return unit_perform_action(pplayer, punit->id, tile_index(pdesttile),
                                NO_TARGET, "", ACTION_HUT_ENTER,
                                ACT_REQ_PLAYER);
-  } else if (is_action_enabled_unit_on_tile(ACTION_HUT_ENTER2,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_ENTER2,
                                             punit, pdesttile, NULL)) {
     /* "Enter Hut 2". */
     return unit_perform_action(pplayer, punit->id, tile_index(pdesttile),
                                NO_TARGET, "", ACTION_HUT_ENTER2,
                                ACT_REQ_PLAYER);
-  } else if (is_action_enabled_unit_on_tile(ACTION_HUT_FRIGHTEN,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_FRIGHTEN,
                                             punit, pdesttile, NULL)) {
     /* "Frighten Hut". */
     return unit_perform_action(pplayer, punit->id, tile_index(pdesttile),
                                NO_TARGET, "", ACTION_HUT_FRIGHTEN,
                                ACT_REQ_PLAYER);
-  } else if (is_action_enabled_unit_on_tile(ACTION_HUT_FRIGHTEN2,
+  } else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_FRIGHTEN2,
                                             punit, pdesttile, NULL)) {
     /* "Frighten Hut 2". */
     return unit_perform_action(pplayer, punit->id, tile_index(pdesttile),
diff --git a/server/unittools.c b/server/unittools.c
index a87039c49d..72fcae7a27 100644
--- a/server/unittools.c
+++ b/server/unittools.c
@@ -5086,6 +5086,8 @@ bool unit_can_be_retired(struct unit *punit)
 **************************************************************************/
 void random_movements(struct player *pplayer)
 {
+  const struct civ_map *nmap = &(wld.map);
+
   game.server.random_move_time = pplayer;
 
   unit_list_iterate_safe(pplayer->units, punit) {
@@ -5121,21 +5123,21 @@ void random_movements(struct player *pplayer)
             }
 
             if (!moved) {
-              if (is_action_enabled_unit_on_tile(ACTION_UNIT_MOVE, punit, dest,
+              if (is_action_enabled_unit_on_tile(nmap, ACTION_UNIT_MOVE, punit, dest,
                                                  NULL)) {
                 if (unit_perform_action(pplayer, id, tile_index(dest),
                                         NO_TARGET, "", ACTION_UNIT_MOVE,
                                         ACT_REQ_RULES)) {
                   moved = TRUE;
                 }
-              } else if (is_action_enabled_unit_on_tile(ACTION_UNIT_MOVE2,
+              } else if (is_action_enabled_unit_on_tile(nmap, ACTION_UNIT_MOVE2,
                                                         punit, dest, NULL)) {
                 if (unit_perform_action(pplayer, id, tile_index(dest),
                                         NO_TARGET, "", ACTION_UNIT_MOVE2,
                                         ACT_REQ_RULES)) {
                   moved = TRUE;
                 }
-              } else if (is_action_enabled_unit_on_tile(ACTION_UNIT_MOVE3,
+              } else if (is_action_enabled_unit_on_tile(nmap, ACTION_UNIT_MOVE3,
                                                         punit, dest, NULL)) {
                 if (unit_perform_action(pplayer, id, tile_index(dest),
                                         NO_TARGET, "", ACTION_UNIT_MOVE3,
-- 
2.43.0

