From 5bb4f6e9767e62b4f4c4030409dda46a8e323911 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sun, 11 Aug 2024 05:25:41 +0300
Subject: [PATCH 20/20] 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-gtk-5.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 ++-
 8 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/client/gui-gtk-3.22/menu.c b/client/gui-gtk-3.22/menu.c
index 2c053d68eb..26fe7a8f61 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 230ebe1f60..f2c4ce4c8c 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-gtk-5.0/menu.c b/client/gui-gtk-5.0/menu.c
index c17b101dd2..020c437d04 100644
--- a/client/gui-gtk-5.0/menu.c
+++ b/client/gui-gtk-5.0/menu.c
@@ -3784,7 +3784,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 3dc7cb5faa..028537f81d 100644
--- a/client/gui-qt/menu.cpp
+++ b/client/gui-qt/menu.cpp
@@ -2529,7 +2529,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 26dea81cdb..76d882bc9f 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 ecfdb93476..323140b02c 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 ec9b4d4f63..93fe81a081 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 b6b3263000..1f280f6ff3 100644
--- a/common/unit.h
+++ b/common/unit.h
@@ -309,7 +309,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

