From 564eb96362af9fb4058d7e10aa4b5e5a3b23b263 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sun, 11 Aug 2024 05:27:38 +0300
Subject: [PATCH 13/13] Unhardcode wld.map from
 unit_can_help_build_wonder_here()

See RM #785

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 client/gui-gtk-3.22/menu.c | 2 +-
 client/gui-gtk-4.0/menu.c  | 3 ++-
 client/gui-qt/menu.cpp     | 2 +-
 client/gui-sdl2/menu.c     | 2 +-
 client/gui-sdl3/menu.c     | 2 +-
 common/unit.c              | 4 ++--
 common/unit.h              | 3 ++-
 7 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/client/gui-gtk-3.22/menu.c b/client/gui-gtk-3.22/menu.c
index 6d7e3ef396..648060935b 100644
--- a/client/gui-gtk-3.22/menu.c
+++ b/client/gui-gtk-3.22/menu.c
@@ -2564,7 +2564,7 @@ void real_menus_update(void)
    * get an eventual error message from the server if we try. */
   menu_entry_set_sensitive("BUILD_CITY",
             (can_units_do(punits, unit_can_add_or_build_city)
-             || can_units_do(punits, unit_can_help_build_wonder_here)));
+             || can_units_do_on_map(&(wld.map), punits, unit_can_help_build_wonder_here)));
   menu_entry_set_sensitive("BUILD_ROAD",
                            (can_units_do_any_road(&(wld.map), punits)
                             || can_units_do(punits,
diff --git a/client/gui-gtk-4.0/menu.c b/client/gui-gtk-4.0/menu.c
index 38eadc11f3..0b928d707b 100644
--- a/client/gui-gtk-4.0/menu.c
+++ b/client/gui-gtk-4.0/menu.c
@@ -3780,7 +3780,8 @@ void real_menus_update(void)
    * get an eventual error message from the server if we try. */
   menu_entry_set_sensitive(map, "BUILD_CITY",
                            (can_units_do(punits, unit_can_add_or_build_city)
-                            || can_units_do(punits, unit_can_help_build_wonder_here)));
+                            || can_units_do_on_map(&(wld.map), punits,
+                                                   unit_can_help_build_wonder_here)));
 
   menu_entry_set_sensitive(map, "DO_ACTION",
                            units_can_do_action(punits, ACTION_ANY, TRUE));
diff --git a/client/gui-qt/menu.cpp b/client/gui-qt/menu.cpp
index 10495d3512..078191bcc6 100644
--- a/client/gui-qt/menu.cpp
+++ b/client/gui-qt/menu.cpp
@@ -2524,7 +2524,7 @@ void mr_menu::menus_sensitive()
         i.value()->setText(
           QString(action_id_name_translation(ACTION_HELP_WONDER))
           .replace("&", "&&"));
-        if (can_units_do(punits, unit_can_help_build_wonder_here)) {
+        if (can_units_do_on_map(&(wld.map), punits, unit_can_help_build_wonder_here)) {
           i.value()->setEnabled(true);
         }
         break;
diff --git a/client/gui-sdl2/menu.c b/client/gui-sdl2/menu.c
index 519e7a12e0..6af76923a3 100644
--- a/client/gui-sdl2/menu.c
+++ b/client/gui-sdl2/menu.c
@@ -1098,7 +1098,7 @@ void real_menus_update(void)
         set_wflag(order_build_add_to_city_button, WF_HIDDEN);
       }
 
-      if (unit_can_help_build_wonder_here(punit)) {
+      if (unit_can_help_build_wonder_here(&(wld.map), punit)) {
         local_show(ID_UNIT_ORDER_BUILD_WONDER);
       } else {
         local_hide(ID_UNIT_ORDER_BUILD_WONDER);
diff --git a/client/gui-sdl3/menu.c b/client/gui-sdl3/menu.c
index ff95c145e6..4fe8f2d3d5 100644
--- a/client/gui-sdl3/menu.c
+++ b/client/gui-sdl3/menu.c
@@ -1094,7 +1094,7 @@ void real_menus_update(void)
         set_wflag(order_build_add_to_city_button, WF_HIDDEN);
       }
 
-      if (unit_can_help_build_wonder_here(punit)) {
+      if (unit_can_help_build_wonder_here(&(wld.map), punit)) {
         local_show(ID_UNIT_ORDER_BUILD_WONDER);
       } else {
         local_hide(ID_UNIT_ORDER_BUILD_WONDER);
diff --git a/common/unit.c b/common/unit.c
index 0429a55711..22c5590865 100644
--- a/common/unit.c
+++ b/common/unit.c
@@ -255,10 +255,10 @@ int unit_shield_value(const struct unit *punit,
   Return TRUE unless it is known to be impossible to disband this unit at
   its current position to get full shields for building a wonder.
 **************************************************************************/
-bool unit_can_help_build_wonder_here(const struct unit *punit)
+bool unit_can_help_build_wonder_here(const struct civ_map *nmap,
+                                     const struct unit *punit)
 {
   struct city *pcity = tile_city(unit_tile(punit));
-  const struct civ_map *nmap = &(wld.map);
 
   if (pcity == NULL) {
     /* No city to help at this tile. */
diff --git a/common/unit.h b/common/unit.h
index dff2360e91..9a57e97f49 100644
--- a/common/unit.h
+++ b/common/unit.h
@@ -306,7 +306,8 @@ bool are_unit_orders_equal(const struct unit_order *order1,
 int unit_shield_value(const struct unit *punit,
                       const struct unit_type *punittype,
                       const struct action *paction);
-bool unit_can_help_build_wonder_here(const struct unit *punit);
+bool unit_can_help_build_wonder_here(const struct civ_map *nmap,
+                                     const struct unit *punit);
 bool unit_can_est_trade_route_here(const struct unit *punit);
 enum unit_airlift_result
     test_unit_can_airlift_to(const struct civ_map *nmap,
-- 
2.43.0

