From d8e29fb518950aef6563dc935ea94dd3a5bd372f Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Fri, 22 Mar 2024 23:27:06 +0200
Subject: [PATCH 41/41] Unhardcode wld.map from
 is_action_enabled_unit_on_unit()

See RM #340

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 ai/default/aidiplomat.c            |  5 +++--
 ai/default/daihunter.c             |  4 ++--
 ai/default/daitools.c              | 16 ++++++++--------
 common/actions.c                   |  7 +++----
 common/actions.h                   |  3 ++-
 common/unit.c                      |  6 ++++--
 server/actiontools.c               |  4 ++--
 server/advisors/advgoto.c          | 21 +++++++++++----------
 server/barbarian.c                 | 20 +++++++++++---------
 server/scripting/api_server_edit.c |  4 +++-
 server/unithand.c                  | 19 ++++++++++---------
 11 files changed, 59 insertions(+), 50 deletions(-)

diff --git a/ai/default/aidiplomat.c b/ai/default/aidiplomat.c
index 4f74efd5fc..9604952bbd 100644
--- a/ai/default/aidiplomat.c
+++ b/ai/default/aidiplomat.c
@@ -589,6 +589,7 @@ static bool dai_diplomat_bribe_nearby(struct ai_type *ait,
                                       struct unit *punit, struct pf_map *pfm)
 {
   int gold_avail, expenses;
+  const struct civ_map *nmap = &(wld.map);
 
   dai_calc_data(pplayer, NULL, &expenses, NULL);
   gold_avail = pplayer->economic.gold - expenses;
@@ -610,7 +611,7 @@ static bool dai_diplomat_bribe_nearby(struct ai_type *ait,
         || !POTENTIALLY_HOSTILE_PLAYER(ait, pplayer, unit_owner(pvictim))
         || unit_list_size(ptile->units) > 1
         || tile_city(ptile)
-        || !is_action_enabled_unit_on_unit(ACTION_SPY_BRIBE_UNIT,
+        || !is_action_enabled_unit_on_unit(nmap, ACTION_SPY_BRIBE_UNIT,
                                            punit, pvictim)) {
       continue;
     }
@@ -661,7 +662,7 @@ static bool dai_diplomat_bribe_nearby(struct ai_type *ait,
       struct tile *bribee_tile;
       struct pf_path *path;
 
-      bribee_tile = mapstep(&(wld.map), pos.tile, DIR_REVERSE(pos.dir_to_here));
+      bribee_tile = mapstep(nmap, pos.tile, DIR_REVERSE(pos.dir_to_here));
       path = pf_map_path(pfm, bribee_tile);
       if (!path || !adv_unit_execute_path(punit, path) 
           || punit->moves_left <= 0) {
diff --git a/ai/default/daihunter.c b/ai/default/daihunter.c
index e4c06f7641..f6d34b4b55 100644
--- a/ai/default/daihunter.c
+++ b/ai/default/daihunter.c
@@ -357,7 +357,7 @@ static void dai_hunter_try_launch(struct ai_type *ait,
           }
         } unit_list_iterate_end;
         if (sucker) {
-          break; /* found something - kill it! */
+          break; /* Found something - kill it! */
         }
       } pf_map_move_costs_iterate_end;
       pf_map_destroy(pfm);
@@ -366,7 +366,7 @@ static void dai_hunter_try_launch(struct ai_type *ait,
         if (unit_transported(missile)) {
           struct unit *ptrans = unit_transport_get(missile);
 
-          if (is_action_enabled_unit_on_unit(ACTION_TRANSPORT_DEBOARD,
+          if (is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_DEBOARD,
                                              missile, ptrans)) {
             unit_do_action(unit_owner(punit), punit->id, ptrans->id,
                            0, "", ACTION_TRANSPORT_DEBOARD);
diff --git a/ai/default/daitools.c b/ai/default/daitools.c
index 2b75b63eee..84532fe38a 100644
--- a/ai/default/daitools.c
+++ b/ai/default/daitools.c
@@ -921,28 +921,28 @@ bool dai_unit_attack(struct ai_type *ait, struct unit *punit, struct tile *ptile
                    0, "", ACTION_CONQUER_CITY4);
   } else if (!can_unit_survive_at_tile(nmap, punit, ptile)
              && ((ptrans = transporter_for_unit_at(punit, ptile)))
-             && is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK,
+             && is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK,
                                                punit, ptrans)) {
     /* "Transport Embark". */
     unit_do_action(unit_owner(punit), punit->id, ptrans->id,
                    0, "", ACTION_TRANSPORT_EMBARK);
   } else if (!can_unit_survive_at_tile(nmap, punit, ptile)
              && ((ptrans = transporter_for_unit_at(punit, ptile)))
-             && is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK2,
+             && is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK2,
                                                punit, ptrans)) {
     /* "Transport Embark 2". */
     unit_do_action(unit_owner(punit), punit->id, ptrans->id,
                    0, "", ACTION_TRANSPORT_EMBARK2);
   } else if (!can_unit_survive_at_tile(nmap, punit, ptile)
              && ((ptrans = transporter_for_unit_at(punit, ptile)))
-             && is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK3,
+             && is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK3,
                                                punit, ptrans)) {
     /* "Transport Embark 3". */
     unit_do_action(unit_owner(punit), punit->id, ptrans->id,
                    0, "", ACTION_TRANSPORT_EMBARK3);
   } else if (!can_unit_survive_at_tile(nmap, punit, ptile)
              && ((ptrans = transporter_for_unit_at(punit, ptile)))
-             && is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK4,
+             && is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK4,
                                                punit, ptrans)) {
     /* "Transport Embark 4". */
     unit_do_action(unit_owner(punit), punit->id, ptrans->id,
@@ -1123,25 +1123,25 @@ bool dai_unit_move(struct ai_type *ait, struct unit *punit, struct tile *ptile)
   /* Select move kind. */
   if (!can_unit_survive_at_tile(nmap, punit, ptile)
       && ((ptrans = transporter_for_unit_at(punit, ptile)))
-      && is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK,
+      && is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK,
                                         punit, ptrans)) {
     /* "Transport Embark". */
     paction = action_by_number(ACTION_TRANSPORT_EMBARK);
   } else if (!can_unit_survive_at_tile(nmap, punit, ptile)
              && ptrans != NULL
-             && is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK2,
+             && is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK2,
                                                punit, ptrans)) {
     /* "Transport Embark 2". */
     paction = action_by_number(ACTION_TRANSPORT_EMBARK2);
   } else if (!can_unit_survive_at_tile(nmap, punit, ptile)
              && ptrans != NULL
-             && is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK3,
+             && is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK3,
                                                punit, ptrans)) {
     /* "Transport Embark 3". */
     paction = action_by_number(ACTION_TRANSPORT_EMBARK3);
   } else if (!can_unit_survive_at_tile(nmap, punit, ptile)
              && ptrans != NULL
-             && is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK4,
+             && is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK4,
                                                punit, ptrans)) {
     /* "Transport Embark 4". */
     paction = action_by_number(ACTION_TRANSPORT_EMBARK4);
diff --git a/common/actions.c b/common/actions.c
index fd1e74f216..66bcaf781b 100644
--- a/common/actions.c
+++ b/common/actions.c
@@ -2273,7 +2273,7 @@ struct action *action_is_blocked_by(const struct action *act,
         /* Can't be enabled. No target. */
         continue;
       }
-      if (is_action_enabled_unit_on_unit(blocker->id,
+      if (is_action_enabled_unit_on_unit(nmap, blocker->id,
                                          actor_unit, target_unit)) {
         return blocker;
       }
@@ -3114,12 +3114,11 @@ is_action_enabled_unit_on_unit_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_unit(const action_id wanted_action,
+bool is_action_enabled_unit_on_unit(const struct civ_map *nmap,
+                                    const action_id wanted_action,
                                     const struct unit *actor_unit,
                                     const struct unit *target_unit)
 {
-  const struct civ_map *nmap = &(wld.map);
-
   return is_action_enabled_unit_on_unit_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 ae546da8d5..6ac4b81856 100644
--- a/common/actions.h
+++ b/common/actions.h
@@ -525,7 +525,8 @@ bool is_action_enabled_unit_on_city(const struct civ_map *nmap,
                                     const struct unit *actor_unit,
                                     const struct city *target_city);
 
-bool is_action_enabled_unit_on_unit(const action_id wanted_action,
+bool is_action_enabled_unit_on_unit(const struct civ_map *nmap,
+                                    const action_id wanted_action,
                                     const struct unit *actor_unit,
                                     const struct unit *target_unit);
 
diff --git a/common/unit.c b/common/unit.c
index 8f3baf0c3d..84429e9852 100644
--- a/common/unit.c
+++ b/common/unit.c
@@ -797,6 +797,8 @@ bool can_unit_unload(const struct unit *pcargo, const struct unit *ptrans)
 bool can_unit_deboard_or_be_unloaded(const struct unit *pcargo,
                                      const struct unit *ptrans)
 {
+  const struct civ_map *nmap = &(wld.map);
+
   if (!pcargo || !ptrans) {
     return FALSE;
   }
@@ -804,9 +806,9 @@ bool can_unit_deboard_or_be_unloaded(const struct unit *pcargo,
   fc_assert_ret_val(unit_transport_get(pcargo) == ptrans, FALSE);
 
   if (is_server()) {
-    return (is_action_enabled_unit_on_unit(ACTION_TRANSPORT_DEBOARD,
+    return (is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_DEBOARD,
                                            pcargo, ptrans)
-            || is_action_enabled_unit_on_unit(ACTION_TRANSPORT_UNLOAD,
+            || is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_UNLOAD,
                                               ptrans, pcargo));
   } else {
     return (action_prob_possible(
diff --git a/server/actiontools.c b/server/actiontools.c
index b76b2d68ff..3b00dd25ef 100644
--- a/server/actiontools.c
+++ b/server/actiontools.c
@@ -1061,7 +1061,7 @@ action_auto_perf_unit_do(const enum action_auto_perf_cause cause,
         break;
       case ATK_UNIT:
         if (tgt_unit
-            && is_action_enabled_unit_on_unit(act, actor, tgt_unit)) {
+            && is_action_enabled_unit_on_unit(nmap, act, actor, tgt_unit)) {
           perform_action_to(act, actor, tgt_unit->id, EXTRA_NONE);
         }
         break;
@@ -1156,7 +1156,7 @@ action_auto_perf_unit_prob(const enum action_auto_perf_cause cause,
         break;
       case ATK_UNIT:
         if (tgt_unit
-            && is_action_enabled_unit_on_unit(act, actor, tgt_unit)) {
+            && is_action_enabled_unit_on_unit(nmap, act, actor, tgt_unit)) {
           current = action_prob_vs_unit(actor, act, tgt_unit);
         }
         break;
diff --git a/server/advisors/advgoto.c b/server/advisors/advgoto.c
index c8400bf2ae..4255a9f367 100644
--- a/server/advisors/advgoto.c
+++ b/server/advisors/advgoto.c
@@ -158,8 +158,9 @@ static bool adv_unit_move(struct unit *punit, struct tile *ptile)
   struct action *paction;
   struct player *pplayer = unit_owner(punit);
   struct unit *ptrans = NULL;
+  const struct civ_map *nmap = &(wld.map);
 
-  /* if enemy, stop and give a chance for the human player to
+  /* If enemy, stop and give a chance for the human player to
      handle this case */
   if (is_enemy_unit_tile(ptile, pplayer)
       || is_enemy_city_tile(ptile, pplayer)) {
@@ -168,27 +169,27 @@ static bool adv_unit_move(struct unit *punit, struct tile *ptile)
   }
 
   /* Select move kind. */
-  if (!can_unit_survive_at_tile(&(wld.map), punit, ptile)
+  if (!can_unit_survive_at_tile(nmap, punit, ptile)
       && ((ptrans = transporter_for_unit_at(punit, ptile)))
-      && is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK,
+      && is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK,
                                         punit, ptrans)) {
     /* "Transport Embark". */
     paction = action_by_number(ACTION_TRANSPORT_EMBARK);
-  } else if (!can_unit_survive_at_tile(&(wld.map), punit, ptile)
+  } else if (!can_unit_survive_at_tile(nmap, punit, ptile)
              && ptrans != NULL
-             && is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK2,
+             && is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK2,
                                                punit, ptrans)) {
     /* "Transport Embark 2". */
     paction = action_by_number(ACTION_TRANSPORT_EMBARK2);
-  } else if (!can_unit_survive_at_tile(&(wld.map), punit, ptile)
+  } else if (!can_unit_survive_at_tile(nmap, punit, ptile)
              && ptrans != NULL
-             && is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK3,
+             && is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK3,
                                                punit, ptrans)) {
     /* "Transport Embark 3". */
     paction = action_by_number(ACTION_TRANSPORT_EMBARK3);
-  } else if (!can_unit_survive_at_tile(&(wld.map), punit, ptile)
+  } else if (!can_unit_survive_at_tile(nmap, punit, ptile)
              && ptrans != NULL
-             && is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK4,
+             && is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK4,
                                                punit, ptrans)) {
     /* "Transport Embark 4". */
     paction = action_by_number(ACTION_TRANSPORT_EMBARK4);
@@ -257,7 +258,7 @@ static bool adv_unit_move(struct unit *punit, struct tile *ptile)
   if (action_has_result(paction, ACTRES_UNIT_MOVE)
       || action_has_result(paction, ACTRES_TRANSPORT_DISEMBARK)) {
     /* The unit will have to move it self rather than being moved. */
-    int mcost = map_move_cost_unit(&(wld.map), punit, ptile);
+    int mcost = map_move_cost_unit(nmap, punit, ptile);
 
     if (paction) {
       struct tile *from_tile;
diff --git a/server/barbarian.c b/server/barbarian.c
index 5284759551..b6181e2eb7 100644
--- a/server/barbarian.c
+++ b/server/barbarian.c
@@ -283,6 +283,7 @@ bool unleash_barbarians(struct tile *ptile)
   int checked_count;
   int dir;
   bool barbarian_stays = FALSE;
+  const struct civ_map *nmap = &(wld.map);
 
   /* FIXME: When there is no L_BARBARIAN unit,
    *        but L_BARBARIAN_TECH is already available,
@@ -326,7 +327,7 @@ bool unleash_barbarians(struct tile *ptile)
   /* Get information about surrounding terrains in terrain class level.
    * Only needed if we consider moving units away to random directions. */
   for (dir = 0; dir < 8; dir++) {
-    dir_tiles[dir] = mapstep(&(wld.map), ptile, dir);
+    dir_tiles[dir] = mapstep(nmap, ptile, dir);
     if (dir_tiles[dir] == NULL) {
       terrainc[dir] = terrain_class_invalid();
     } else if (!is_non_allied_unit_tile(dir_tiles[dir], barbarians, TRUE)) {
@@ -356,7 +357,7 @@ bool unleash_barbarians(struct tile *ptile)
              checked_count++) {
           int rdir = random_unchecked_direction(land_tiles - checked_count, checked);
 
-          if (unit_can_move_to_tile(&(wld.map), punit2, dir_tiles[rdir],
+          if (unit_can_move_to_tile(nmap, punit2, dir_tiles[rdir],
                                     TRUE, FALSE, FALSE)) {
             /* Move */
             (void) unit_move_pay(punit2, dir_tiles[rdir]);
@@ -402,22 +403,22 @@ bool unleash_barbarians(struct tile *ptile)
         /* We do have a boat. Try to get everybody in */
         unit_list_iterate_safe((ptile)->units, punit2) {
           if (unit_owner(punit2) == barbarians) {
-            if (is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK,
+            if (is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK,
                                                punit2, boat)) {
               /* Load */
               unit_do_action(unit_owner(punit2), punit2->id, boat->id,
                              0, "", ACTION_TRANSPORT_EMBARK);
-            } else if (is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK2,
+            } else if (is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK2,
                                                       punit2, boat)) {
               /* Load */
               unit_do_action(unit_owner(punit2), punit2->id, boat->id,
                              0, "", ACTION_TRANSPORT_EMBARK2);
-            } else if (is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK3,
+            } else if (is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK3,
                                                       punit2, boat)) {
               /* Load */
               unit_do_action(unit_owner(punit2), punit2->id, boat->id,
                              0, "", ACTION_TRANSPORT_EMBARK3);
-            } else if (is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK4,
+            } else if (is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK4,
                                                       punit2, boat)) {
               /* Load */
               unit_do_action(unit_owner(punit2), punit2->id, boat->id,
@@ -442,7 +443,7 @@ bool unleash_barbarians(struct tile *ptile)
 
             rdir = random_unchecked_direction(land_tiles - checked_count, checked);
 
-            if (unit_can_move_to_tile(&(wld.map), punit2, dir_tiles[rdir],
+            if (unit_can_move_to_tile(nmap, punit2, dir_tiles[rdir],
                                       TRUE, FALSE, FALSE)) {
               /* Move */
               (void) unit_move_pay(punit2, dir_tiles[rdir]);
@@ -541,13 +542,14 @@ static void try_summon_barbarians(void)
   bool hut_present = FALSE;
   int city_count;
   int city_max;
+  const struct civ_map *nmap = &(wld.map);
 
   /* We attempt the summons on a particular, random position.  If this is
    * an invalid position then the summons simply fails this time.  This means
    * that a particular tile's chance of being summoned on is independent of
    * all the other tiles on the map - which is essential for balanced
    * gameplay. */
-  ptile = rand_map_pos(&(wld.map));
+  ptile = rand_map_pos(nmap);
 
   if (terrain_has_flag(tile_terrain(ptile), TER_NO_BARBS)) {
     return;
@@ -665,7 +667,7 @@ static void try_summon_barbarians(void)
 
     if (is_native_tile(boat, utile)
         && !utype_player_already_has_this_unique(barbarians, boat)
-        && (is_safe_ocean(&(wld.map), utile)
+        && (is_safe_ocean(nmap, utile)
             || (!utype_has_flag(boat, UTYF_COAST_STRICT)
                 && !utype_has_flag(boat, UTYF_COAST)))) {
       int cap;
diff --git a/server/scripting/api_server_edit.c b/server/scripting/api_server_edit.c
index 103358602d..4f2b634e5c 100644
--- a/server/scripting/api_server_edit.c
+++ b/server/scripting/api_server_edit.c
@@ -339,6 +339,8 @@ bool api_edit_perform_action_unit_vs_city_tech(lua_State *L, Unit *punit,
 bool api_edit_perform_action_unit_vs_unit(lua_State *L, Unit *punit,
                                           Action *paction, Unit *tgt)
 {
+  const struct civ_map *nmap = &(wld.map);
+
   LUASCRIPT_CHECK_STATE(L, FALSE);
   LUASCRIPT_CHECK_ARG_NIL(L, punit, 2, Unit, FALSE);
   LUASCRIPT_CHECK_ARG_NIL(L, paction, 3, Action, FALSE);
@@ -347,7 +349,7 @@ bool api_edit_perform_action_unit_vs_unit(lua_State *L, Unit *punit,
   fc_assert_ret_val(action_get_actor_kind(paction) == AAK_UNIT, FALSE);
   fc_assert_ret_val(action_get_target_kind(paction) == ATK_UNIT, FALSE);
   fc_assert_ret_val(!action_has_result(paction, ACTRES_FOUND_CITY), FALSE);
-  if (is_action_enabled_unit_on_unit(paction->id, punit, tgt)) {
+  if (is_action_enabled_unit_on_unit(nmap, paction->id, punit, tgt)) {
     return unit_perform_action(unit_owner(punit), punit->id,
                                tgt->id, IDENTITY_NUMBER_ZERO, "",
                                paction->id, ACT_REQ_RULES);
diff --git a/server/unithand.c b/server/unithand.c
index 553bf87621..401fb4c4a5 100644
--- a/server/unithand.c
+++ b/server/unithand.c
@@ -3206,7 +3206,7 @@ void handle_unit_action_query(struct connection *pc,
   switch (paction->result) {
   case ACTRES_SPY_BRIBE_UNIT:
     if (punit
-        && is_action_enabled_unit_on_unit(action_type,
+        && is_action_enabled_unit_on_unit(nmap, action_type,
                                           pactor, punit)) {
       dsend_packet_unit_action_answer(pc,
                                       actor_id, target_id,
@@ -3517,7 +3517,7 @@ bool unit_perform_action(struct player *pplayer,
 
 #define ACTION_PERFORM_UNIT_UNIT(action, actor, target, action_performer) \
   if (punit                                                               \
-      && is_action_enabled_unit_on_unit(action_type, actor_unit, punit)) {\
+      && is_action_enabled_unit_on_unit(nmap, action_type, actor_unit, punit)) { \
     bool success;                                                         \
     script_server_signal_emit("action_started_unit_unit",                 \
                               action_by_number(action), actor, target);   \
@@ -5668,6 +5668,7 @@ bool unit_move_handling(struct unit *punit, struct tile *pdesttile,
 {
   struct player *pplayer = unit_owner(punit);
   struct unit *ptrans;
+  const struct civ_map *nmap = &(wld.map);
 
   /*** Phase 1: Attempted action interpretation checks ***/
 
@@ -5758,31 +5759,31 @@ bool unit_move_handling(struct unit *punit, struct tile *pdesttile,
                                ACT_REQ_PLAYER);
   } else if (!can_unit_survive_at_tile(&(wld.map), punit, pdesttile)
              && ((ptrans = transporter_for_unit_at(punit, pdesttile)))
-             && is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK,
+             && is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK,
                                                punit, ptrans)) {
     /* "Transport Embark". */
     return unit_perform_action(pplayer, punit->id, ptrans->id,
                                NO_TARGET, "", ACTION_TRANSPORT_EMBARK,
                                ACT_REQ_PLAYER);
-  } else if (!can_unit_survive_at_tile(&(wld.map), punit, pdesttile)
+  } else if (!can_unit_survive_at_tile(nmap, punit, pdesttile)
              && ((ptrans = transporter_for_unit_at(punit, pdesttile)))
-             && is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK2,
+             && is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK2,
                                                punit, ptrans)) {
     /* "Transport Embark 2". */
     return unit_perform_action(pplayer, punit->id, ptrans->id,
                                NO_TARGET, "", ACTION_TRANSPORT_EMBARK2,
                                ACT_REQ_PLAYER);
-  } else if (!can_unit_survive_at_tile(&(wld.map), punit, pdesttile)
+  } else if (!can_unit_survive_at_tile(nmap, punit, pdesttile)
              && ((ptrans = transporter_for_unit_at(punit, pdesttile)))
-             && is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK3,
+             && is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK3,
                                                punit, ptrans)) {
     /* "Transport Embark 3". */
     return unit_perform_action(pplayer, punit->id, ptrans->id,
                                NO_TARGET, "", ACTION_TRANSPORT_EMBARK3,
                                ACT_REQ_PLAYER);
-  } else if (!can_unit_survive_at_tile(&(wld.map), punit, pdesttile)
+  } else if (!can_unit_survive_at_tile(nmap, punit, pdesttile)
              && ((ptrans = transporter_for_unit_at(punit, pdesttile)))
-             && is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK4,
+             && is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK4,
                                                punit, ptrans)) {
     /* "Transport Embark 4". */
     return unit_perform_action(pplayer, punit->id, ptrans->id,
-- 
2.43.0

