From 9e94257226478eaeab9a5f13fb7f247d7c9346a7 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Fri, 1 May 2026 18:02:24 +0300
Subject: [PATCH 33/33] Move access_areas_refresh() from common/ to server/

See RM #2010

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 common/accessarea.c |  87 ++++++------------------------------
 common/accessarea.h |   4 +-
 meson.build         |   1 +
 server/Makefile.am  |   2 +
 server/aahand.c     | 105 ++++++++++++++++++++++++++++++++++++++++++++
 server/aahand.h     |  18 ++++++++
 server/srv_main.c   |   2 +-
 7 files changed, 144 insertions(+), 75 deletions(-)
 create mode 100644 server/aahand.c
 create mode 100644 server/aahand.h

diff --git a/common/accessarea.c b/common/accessarea.c
index e21a294f8f..b478121fb6 100644
--- a/common/accessarea.c
+++ b/common/accessarea.c
@@ -32,8 +32,6 @@ static struct access_info ainfo = { nullptr };
 
 static struct aarea_list *aalist[MAX_NUM_PLAYERS];
 
-static void area_list_clear(struct aarea_list *alist);
-
 /*********************************************************************//**
   Initialize access info.
   @param aunit Access unit for the access info
@@ -79,7 +77,7 @@ const struct unit_type *access_info_access_unit(void)
   Free access area list.
   @param alist List to clear
 *************************************************************************/
-static void area_list_clear(struct aarea_list *alist)
+void area_list_clear(struct aarea_list *alist)
 {
   aarea_list_iterate(alist, parea) {
     city_list_destroy(parea->cities);
@@ -90,76 +88,19 @@ static void area_list_clear(struct aarea_list *alist)
 }
 
 /*********************************************************************//**
-  Construct access areas
-  @param nmap Map to use when determining access
-  @param plr  Player to construct areas for
+  Free access area list of player.
+  @param pplayer Whose list to clear
 *************************************************************************/
-void access_areas_refresh(struct civ_map *nmap, struct player *plr)
+void area_list_clear_plr(struct player *pplayer)
 {
-  if (ainfo.access_unit != nullptr) {
-    int plridx = player_number(plr);
-    struct unit *access_unit;
-
-    area_list_clear(aalist[plridx]);
-    aalist[plridx] = aarea_list_new();
-
-    city_list_iterate(plr->cities, pcity) {
-      pcity->server.aarea = nullptr;
-    } city_list_iterate_end;
-
-    access_unit = unit_virtual_create(plr, nullptr,
-                                      ainfo.access_unit, 0);
-
-    city_list_iterate(plr->cities, pcity) {
-      if (pcity->server.aarea == nullptr) {
-        struct access_area *aarea = fc_malloc(sizeof(struct access_area));
-        struct pf_parameter parameter;
-        struct pf_map *pfm;
-
-        aarea->cities = city_list_new();
-        aarea->capital = is_capital(pcity);
-
-        pcity->server.aarea = aarea;
-        city_list_append(aarea->cities, pcity);
-        aarea_list_append(aalist[plridx], aarea);
-
-        unit_tile_set(access_unit, city_tile(pcity));
-        pft_fill_unit_parameter(&parameter, nmap, access_unit);
-        pfm = pf_map_new(&parameter);
-
-        city_list_iterate(plr->cities, pcity2) {
-          if (pcity2->server.aarea == nullptr) {
-            struct pf_path *path;
-
-            path = pf_map_path(pfm, city_tile(pcity2));
-            if (path != nullptr) {
-              pcity2->server.aarea = aarea;
-              city_list_append(aarea->cities, pcity2);
-
-              if (!aarea->capital && is_capital(pcity2)) {
-                aarea->capital = TRUE;
-              }
-            }
-
-            pf_path_destroy(path);
-          }
-        } city_list_iterate_end;
-
-        BV_CLR_ALL(aarea->tiledefs);
-        pf_map_tiles_iterate(pfm, ptile, TRUE) {
-          if (ptile != nullptr) {
-            tiledef_iterate(td) {
-              if (tile_matches_tiledef(td, ptile)) {
-                BV_SET(aarea->tiledefs, tiledef_number(td));
-              }
-            } tiledef_iterate_end;
-          }
-        } pf_map_tiles_iterate_end;
-
-        pf_map_destroy(pfm);
-      }
-    } city_list_iterate_end;
-
-    unit_virtual_destroy(access_unit);
-  }
+  area_list_clear(aalist[player_index(pplayer)]);
+}
+
+/*********************************************************************//**
+  Set access area list for player
+  @param pplayer Whose list to set
+*************************************************************************/
+void area_list_for_player_set(struct player *pplayer, struct aarea_list *alist)
+{
+  aalist[player_index(pplayer)] = alist;
 }
diff --git a/common/accessarea.h b/common/accessarea.h
index 263a5fd6c9..3541bbc786 100644
--- a/common/accessarea.h
+++ b/common/accessarea.h
@@ -34,7 +34,9 @@ void access_info_init(const struct unit_type *aunit);
 void access_info_close(void);
 const struct unit_type *access_info_access_unit(void);
 
-void access_areas_refresh(struct civ_map *nmap, struct player *plr);
+void area_list_clear(struct aarea_list *alist);
+void area_list_clear_plr(struct player *pplayer);
+void area_list_for_player_set(struct player *pplayer, struct aarea_list *alist);
 
 #ifdef __cplusplus
 }
diff --git a/meson.build b/meson.build
index c0a7065ce2..d93f99c2de 100644
--- a/meson.build
+++ b/meson.build
@@ -1654,6 +1654,7 @@ server_lib = static_library('fc_server',
   'server/scripting/api_server_notify.c',
   'server/scripting/script_fcdb.c',
   'server/scripting/script_server.c',
+  'server/aahand.c',
   'server/actiontools.c',
   'server/aiiface.c',
   'server/animals.c',
diff --git a/server/Makefile.am b/server/Makefile.am
index 6b958c92b7..17e834a6f2 100644
--- a/server/Makefile.am
+++ b/server/Makefile.am
@@ -31,6 +31,8 @@ exe_sources = \
 		srv_entrypoint.c
 
 libfreeciv_srv_la_SOURCES = \
+		aahand.c	\
+		aahand.h	\
 		actiontools.c	\
 		actiontools.h	\
 		aiiface.c	\
diff --git a/server/aahand.c b/server/aahand.c
new file mode 100644
index 0000000000..dabc000449
--- /dev/null
+++ b/server/aahand.c
@@ -0,0 +1,105 @@
+/****************************************************************************
+ Freeciv - Copyright (C) 2004 - The Freeciv Team
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <fc_config.h>
+#endif
+
+/* common/aicore */
+#include "pf_tools.h"
+
+/* common */
+#include "accessarea.h"
+#include "player.h"
+#include "tiledef.h"
+
+#include "aahand.h"
+
+/*********************************************************************//**
+  Construct access areas
+  @param nmap Map to use when determining access
+  @param plr  Player to construct areas for
+*************************************************************************/
+void access_areas_refresh(struct civ_map *nmap, struct player *plr)
+{
+  const struct unit_type *access_utype = access_info_access_unit();
+
+  if (access_utype != nullptr) {
+    struct unit *access_unit;
+    struct aarea_list *alist;
+
+    area_list_clear_plr(plr);
+    alist = aarea_list_new();
+
+    area_list_for_player_set(plr, alist);
+
+    city_list_iterate(plr->cities, pcity) {
+      pcity->server.aarea = nullptr;
+    } city_list_iterate_end;
+
+    access_unit = unit_virtual_create(plr, nullptr,
+                                      access_utype, 0);
+
+    city_list_iterate(plr->cities, pcity) {
+      if (pcity->server.aarea == nullptr) {
+        struct access_area *aarea = fc_malloc(sizeof(struct access_area));
+        struct pf_parameter parameter;
+        struct pf_map *pfm;
+
+        aarea->cities = city_list_new();
+        aarea->capital = is_capital(pcity);
+
+        pcity->server.aarea = aarea;
+        city_list_append(aarea->cities, pcity);
+        aarea_list_append(alist, aarea);
+
+        unit_tile_set(access_unit, city_tile(pcity));
+        pft_fill_unit_parameter(&parameter, nmap, access_unit);
+        pfm = pf_map_new(&parameter);
+
+        city_list_iterate(plr->cities, pcity2) {
+          if (pcity2->server.aarea == nullptr) {
+            struct pf_path *path;
+
+            path = pf_map_path(pfm, city_tile(pcity2));
+            if (path != nullptr) {
+              pcity2->server.aarea = aarea;
+              city_list_append(aarea->cities, pcity2);
+
+              if (!aarea->capital && is_capital(pcity2)) {
+                aarea->capital = TRUE;
+              }
+            }
+
+            pf_path_destroy(path);
+          }
+        } city_list_iterate_end;
+
+        BV_CLR_ALL(aarea->tiledefs);
+        pf_map_tiles_iterate(pfm, ptile, TRUE) {
+          if (ptile != nullptr) {
+            tiledef_iterate(td) {
+              if (tile_matches_tiledef(td, ptile)) {
+                BV_SET(aarea->tiledefs, tiledef_number(td));
+              }
+            } tiledef_iterate_end;
+          }
+        } pf_map_tiles_iterate_end;
+
+        pf_map_destroy(pfm);
+      }
+    } city_list_iterate_end;
+
+    unit_virtual_destroy(access_unit);
+  }
+}
diff --git a/server/aahand.h b/server/aahand.h
new file mode 100644
index 0000000000..ebf0abe729
--- /dev/null
+++ b/server/aahand.h
@@ -0,0 +1,18 @@
+/***********************************************************************
+ Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+***********************************************************************/
+#ifndef FC__AAHAND_H
+#define FC__AAHAND_H
+
+void access_areas_refresh(struct civ_map *nmap, struct player *plr);
+
+#endif /* FC__AAHAND_H */
diff --git a/server/srv_main.c b/server/srv_main.c
index db365b12d5..6eae94b86a 100644
--- a/server/srv_main.c
+++ b/server/srv_main.c
@@ -66,7 +66,6 @@
 #include "citymap.h"
 
 /* common */
-#include "accessarea.h"
 #include "achievements.h"
 #include "calendar.h"
 #include "capstr.h"
@@ -91,6 +90,7 @@
 #include "victory.h"
 
 /* server */
+#include "aahand.h"
 #include "aiiface.h"
 #include "animals.h"
 #include "auth.h"
-- 
2.53.0

