Freeciv-3.4
Loading...
Searching...
No Matches
accessarea.c
Go to the documentation of this file.
1/****************************************************************************
2 Freeciv - Copyright (C) 2004 - The Freeciv Team
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12****************************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18/* common/aicore */
19#include "pf_tools.h"
20
21/* common */
22#include "player.h"
23
24#include "accessarea.h"
25
27 const struct unit_type *access_unit;
28};
29
30static struct access_info ainfo = { nullptr };
31
33
34static void area_list_clear(struct aarea_list *alist);
35
36/*********************************************************************/
40void access_info_init(const struct unit_type *aunit)
41{
42 if (aunit != nullptr) {
43 int i;
44
46
47 for (i = 0; i < MAX_NUM_PLAYERS; i++) {
49 }
50 }
51}
52
53/*********************************************************************/
57{
58 int i;
59
60 if (ainfo.access_unit != nullptr) {
61 ainfo.access_unit = nullptr;
62
63 for (i = 0; i < MAX_NUM_PLAYERS; i++) {
65 }
66 }
67}
68
69/*********************************************************************/
73{
74 return ainfo.access_unit;
75}
76
77/*********************************************************************/
90
91/*********************************************************************/
96void access_areas_refresh(struct civ_map *nmap, struct player *plr)
97{
98 if (ainfo.access_unit != nullptr) {
99 int plridx = player_number(plr);
100 struct unit *access_unit;
101
104
106 pcity->server.aarea = nullptr;
108
109 access_unit = unit_virtual_create(plr, nullptr,
110 ainfo.access_unit, 0);
111
113 if (pcity->server.aarea == nullptr) {
114 struct access_area *aarea = fc_malloc(sizeof(struct access_area));
115 struct pf_parameter parameter;
116 struct pf_map *pfm;
117
118 aarea->cities = city_list_new();
119 aarea->capital = is_capital(pcity);
120
121 pcity->server.aarea = aarea;
124
125 unit_tile_set(access_unit, city_tile(pcity));
126 pft_fill_unit_parameter(&parameter, nmap, access_unit);
127 pfm = pf_map_new(&parameter);
128
130 if (pcity2->server.aarea == nullptr) {
131 struct pf_path *path;
132
134 if (path != nullptr) {
135 pcity2->server.aarea = aarea;
137
138 if (!aarea->capital && is_capital(pcity2)) {
139 aarea->capital = TRUE;
140 }
141 }
142
143 pf_path_destroy(path);
144 }
146
148 }
150
151 unit_virtual_destroy(access_unit);
152 }
153}
static struct aarea_list * aalist[MAX_NUM_PLAYERS]
Definition accessarea.c:32
static void area_list_clear(struct aarea_list *alist)
Definition accessarea.c:81
void access_info_init(const struct unit_type *aunit)
Definition accessarea.c:40
void access_info_close(void)
Definition accessarea.c:56
void access_areas_refresh(struct civ_map *nmap, struct player *plr)
Definition accessarea.c:96
const struct unit_type * access_info_access_unit(void)
Definition accessarea.c:72
static struct access_info ainfo
Definition accessarea.c:30
#define aarea_list_iterate_end
Definition accessarea.h:31
#define aarea_list_iterate(aarealist, parea)
Definition accessarea.h:29
bool is_capital(const struct city *pcity)
Definition city.c:1579
#define city_list_iterate(citylist, pcity)
Definition city.h:508
#define city_tile(_pcity_)
Definition city.h:564
#define city_list_iterate_end
Definition city.h:510
char * incite_cost
Definition comments.c:76
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
#define MAX_NUM_PLAYERS
Definition fc_types.h:36
#define fc_malloc(sz)
Definition mem.h:34
void pf_path_destroy(struct pf_path *path)
struct pf_map * pf_map_new(const struct pf_parameter *parameter)
struct pf_path * pf_map_path(struct pf_map *pfm, struct tile *ptile)
void pf_map_destroy(struct pf_map *pfm)
void pft_fill_unit_parameter(struct pf_parameter *parameter, const struct civ_map *nmap, const struct unit *punit)
Definition pf_tools.c:843
int player_number(const struct player *pplayer)
Definition player.c:839
struct city_list * cities
Definition fc_types.h:1101
const struct unit_type * access_unit
Definition accessarea.c:27
struct city_list * cities
Definition player.h:281
Definition unit.h:140
struct unit::@84::@87 server
#define TRUE
Definition support.h:46
struct unit * unit_virtual_create(struct player *pplayer, struct city *pcity, const struct unit_type *punittype, int veteran_level)
Definition unit.c:1688
void unit_virtual_destroy(struct unit *punit)
Definition unit.c:1793
void unit_tile_set(struct unit *punit, struct tile *ptile)
Definition unit.c:1311