Project

General

Profile

Feature #2010 ยป 0033-Move-access_areas_refresh-from-common-to-server.patch

Marko Lindqvist, 05/01/2026 06:05 PM

View differences:

common/accessarea.c
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
......
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);
......
}
/*********************************************************************//**
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;
}
common/accessarea.h
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
}
meson.build
'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',
server/Makefile.am
srv_entrypoint.c
libfreeciv_srv_la_SOURCES = \
aahand.c \
aahand.h \
actiontools.c \
actiontools.h \
aiiface.c \
server/aahand.c
/****************************************************************************
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);
}
}
server/aahand.h
/***********************************************************************
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 */
server/srv_main.c
#include "citymap.h"
/* common */
#include "accessarea.h"
#include "achievements.h"
#include "calendar.h"
#include "capstr.h"
......
#include "victory.h"
/* server */
#include "aahand.h"
#include "aiiface.h"
#include "animals.h"
#include "auth.h"
    (1-1/1)