From 79beecf7a30b910b66688a6aeae43938d1535825 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sat, 26 Oct 2024 05:22:37 +0300
Subject: [PATCH 59/59] Unhardcode wld.map from can_city_build_later()

See RM #1022

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 client/citydlg_common.c | 8 +++++---
 client/gui-sdl2/wldlg.c | 4 ++--
 client/gui-sdl3/wldlg.c | 4 ++--
 common/city.c           | 5 ++---
 common/city.h           | 3 ++-
 5 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/client/citydlg_common.c b/client/citydlg_common.c
index de1b3abb23..a3c95b9ff3 100644
--- a/client/citydlg_common.c
+++ b/client/citydlg_common.c
@@ -1375,11 +1375,13 @@ void city_worklist_commit(struct city *pcity, struct worklist *pwl)
 static bool base_city_queue_insert(struct city *pcity, int position,
                                    struct universal *item)
 {
+  const struct civ_map *nmap = &(wld.map);
+
   if (position == 0) {
     struct universal old = pcity->production;
 
     /* Insert as current production. */
-    if (!can_city_build_direct(&(wld.map), pcity, item)) {
+    if (!can_city_build_direct(nmap, pcity, item)) {
       return FALSE;
     }
 
@@ -1391,7 +1393,7 @@ static bool base_city_queue_insert(struct city *pcity, int position,
   } else if (position >= 1
              && position <= worklist_length(&pcity->worklist)) {
     /* Insert into middle. */
-    if (!can_city_build_later(pcity, item)) {
+    if (!can_city_build_later(nmap, pcity, item)) {
       return FALSE;
     }
     if (!worklist_insert(&pcity->worklist, item, position - 1)) {
@@ -1399,7 +1401,7 @@ static bool base_city_queue_insert(struct city *pcity, int position,
     }
   } else {
     /* Insert at end. */
-    if (!can_city_build_later(pcity, item)) {
+    if (!can_city_build_later(nmap, pcity, item)) {
       return FALSE;
     }
     if (!worklist_append(&pcity->worklist, item)) {
diff --git a/client/gui-sdl2/wldlg.c b/client/gui-sdl2/wldlg.c
index eb6993ddd7..1c15e21ebe 100644
--- a/client/gui-sdl2/wldlg.c
+++ b/client/gui-sdl2/wldlg.c
@@ -691,7 +691,7 @@ static void add_global_worklist(struct widget *pwidget)
 
     /* Global worklist can have targets unavilable in current state of game
        then we must remove those targets from new city worklist */
-    if (!can_city_build_later(editor->pcity, &pworklist->entries[count])) {
+    if (!can_city_build_later(&(wld.map), editor->pcity, &pworklist->entries[count])) {
       continue;
     }
 
@@ -769,7 +769,7 @@ static void set_global_worklist(struct widget *pwidget)
   for (count = 0; count < worklist_length(pworklist); count++) {
     /* global worklist can have targets unavilable in current state of game
        then we must remove those targets from new city worklist */
-    if (!can_city_build_later(editor->pcity, &pworklist->entries[count])) {
+    if (!can_city_build_later(&(wld.map), editor->pcity, &pworklist->entries[count])) {
       continue;
     }
 
diff --git a/client/gui-sdl3/wldlg.c b/client/gui-sdl3/wldlg.c
index a09e50cb8c..e86ce8dc9f 100644
--- a/client/gui-sdl3/wldlg.c
+++ b/client/gui-sdl3/wldlg.c
@@ -687,7 +687,7 @@ static void add_global_worklist(struct widget *pwidget)
 
     /* Global worklist can have targets unavilable in current state of game
        then we must remove those targets from new city worklist */
-    if (!can_city_build_later(editor->pcity, &pworklist->entries[count])) {
+    if (!can_city_build_later(&(wld.map), editor->pcity, &pworklist->entries[count])) {
       continue;
     }
 
@@ -765,7 +765,7 @@ static void set_global_worklist(struct widget *pwidget)
   for (count = 0; count < worklist_length(pworklist); count++) {
     /* global worklist can have targets unavilable in current state of game
        then we must remove those targets from new city worklist */
-    if (!can_city_build_later(editor->pcity, &pworklist->entries[count])) {
+    if (!can_city_build_later(&(wld.map), editor->pcity, &pworklist->entries[count])) {
       continue;
     }
 
diff --git a/common/city.c b/common/city.c
index 88fd7b8f43..8d71c05dea 100644
--- a/common/city.c
+++ b/common/city.c
@@ -1028,11 +1028,10 @@ bool can_city_build_now(const struct civ_map *nmap,
 /**********************************************************************//**
   Returns whether city can ever build given target, unit or improvement. 
 **************************************************************************/
-bool can_city_build_later(const struct city *pcity,
+bool can_city_build_later(const struct civ_map *nmap,
+                          const struct city *pcity,
                           const struct universal *target)
 {
-  const struct civ_map *nmap = &(wld.map);
-
   switch (target->kind) {
   case VUT_UTYPE:
     return can_city_build_unit_later(nmap, pcity, target->value.utype);
diff --git a/common/city.h b/common/city.h
index 35c79e37d9..f34f9ef5f9 100644
--- a/common/city.h
+++ b/common/city.h
@@ -617,7 +617,8 @@ bool can_city_build_unit_now(const struct civ_map *nmap,
 bool can_city_build_direct(const struct civ_map *nmap,
                            const struct city *pcity,
                            const struct universal *target);
-bool can_city_build_later(const struct city *pcity,
+bool can_city_build_later(const struct civ_map *nmap,
+                          const struct city *pcity,
                           const struct universal *target);
 bool can_city_build_now(const struct civ_map *nmap,
                         const struct city *pcity,
-- 
2.45.2

