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#include "tiledef.h"
24
25#include "accessarea.h"
26
28 const struct unit_type *access_unit;
29};
30
31static struct access_info ainfo = { nullptr };
32
34
35static void area_list_clear(struct aarea_list *alist);
36
37/*********************************************************************/
41void access_info_init(const struct unit_type *aunit)
42{
43 if (aunit != nullptr) {
44 int i;
45
47
48 for (i = 0; i < MAX_NUM_PLAYERS; i++) {
50 }
51 }
52}
53
54/*********************************************************************/
58{
59 int i;
60
61 if (ainfo.access_unit != nullptr) {
62 ainfo.access_unit = nullptr;
63
64 for (i = 0; i < MAX_NUM_PLAYERS; i++) {
66 }
67 }
68}
69
70/*********************************************************************/
74{
75 return ainfo.access_unit;
76}
77
78/*********************************************************************/
91
92/*********************************************************************/
97void access_areas_refresh(struct civ_map *nmap, struct player *plr)
98{
99 if (ainfo.access_unit != nullptr) {
100 int plridx = player_number(plr);
101 struct unit *access_unit;
102
105
107 pcity->server.aarea = nullptr;
109
110 access_unit = unit_virtual_create(plr, nullptr,
111 ainfo.access_unit, 0);
112
114 if (pcity->server.aarea == nullptr) {
115 struct access_area *aarea = fc_malloc(sizeof(struct access_area));
116 struct pf_parameter parameter;
117 struct pf_map *pfm;
118 int i;
119
120 aarea->cities = city_list_new();
121 aarea->capital = is_capital(pcity);
122
123 pcity->server.aarea = aarea;
126
127 unit_tile_set(access_unit, city_tile(pcity));
128 pft_fill_unit_parameter(&parameter, nmap, access_unit);
129 pfm = pf_map_new(&parameter);
130
132 if (pcity2->server.aarea == nullptr) {
133 struct pf_path *path;
134
136 if (path != nullptr) {
137 pcity2->server.aarea = aarea;
139
140 if (!aarea->capital && is_capital(pcity2)) {
141 aarea->capital = TRUE;
142 }
143 }
144
145 pf_path_destroy(path);
146 }
148
149 BV_CLR_ALL(aarea->tiledefs);
150 for (i = 0; i < MAX_TILEDEFS; i++) {
151 pf_map_tiles_iterate(pfm, ptile, TRUE) {
153 BV_SET(aarea->tiledefs, i);
154 break;
155 }
157 }
158
160 }
162
163 unit_virtual_destroy(access_unit);
164 }
165}
static struct aarea_list * aalist[MAX_NUM_PLAYERS]
Definition accessarea.c:33
static void area_list_clear(struct aarea_list *alist)
Definition accessarea.c:82
void access_info_init(const struct unit_type *aunit)
Definition accessarea.c:41
void access_info_close(void)
Definition accessarea.c:57
void access_areas_refresh(struct civ_map *nmap, struct player *plr)
Definition accessarea.c:97
const struct unit_type * access_info_access_unit(void)
Definition accessarea.c:73
static struct access_info ainfo
Definition accessarea.c:31
#define aarea_list_iterate_end
Definition accessarea.h:31
#define aarea_list_iterate(aarealist, parea)
Definition accessarea.h:29
#define BV_CLR_ALL(bv)
Definition bitvector.h:103
#define BV_SET(bv, bit)
Definition bitvector.h:89
bool is_capital(const struct city *pcity)
Definition city.c:1615
#define city_list_iterate(citylist, pcity)
Definition city.h:508
#define city_tile(_pcity_)
Definition city.h:565
#define city_list_iterate_end
Definition city.h:510
char * incite_cost
Definition comments.c:77
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 MAX_TILEDEFS
Definition fc_types.h:56
#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)
#define pf_map_tiles_iterate(ARG_pfm, NAME_tile, COND_from_start)
#define pf_map_tiles_iterate_end
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:826
bv_tiledefs tiledefs
Definition fc_types.h:1107
struct city_list * cities
Definition fc_types.h:1105
const struct unit_type * access_unit
Definition accessarea.c:28
struct city_list * cities
Definition player.h:281
Definition unit.h:140
struct unit::@84::@87 server
#define TRUE
Definition support.h:46
struct tiledef * tiledef_by_number(int id)
Definition tiledef.c:84
bool tile_matches_tiledef(const struct tiledef *td, const struct tile *ptile)
Definition tiledef.c:150
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