13
13
#ifndef FC__NATION_H
14
14
#define FC__NATION_H
16
#include "shared.h" /* MAX_LEN_NAME */
18
20
#include "fc_types.h"
21
#include "name_translation.h"
19
22
#include "terrain.h" /* MAX_NUM_TERRAINS */
21
#define MAX_NUM_TECH_GOALS 10
24
#define NO_NATION_SELECTED (NULL)
23
26
/* Changing this value will break network compatibility. */
24
#define NO_NATION_SELECTED (NULL)
26
27
#define NATION_NONE -1
27
28
#define NATION_ANY -2
30
* Purpose of this constant is to catch invalid ruleset and network
31
* data and to allow static allocation of the nation_info packet.
33
#define MAX_NUM_LEADERS MAX_NUM_ITEMS
35
#define MAX_NUM_NATION_GROUPS 128
38
* The nation_city structure holds information about a default choice for
39
* the city name. The "name" field is, of course, just the name for
40
* the city. The "river" and "terrain" fields are entries recording
41
* whether the terrain is present near the city - we give higher priority
42
* to cities which have matching terrain. In the case of a river we only
43
* care if the city is _on_ the river, for other terrain features we give
44
* the bonus if the city is close to the terrain. Both of these entries
45
* may hold a value of 0 (no preference), 1 (city likes the terrain), or -1
46
* (city doesn't like the terrain).
48
* This is controlled through the nation's ruleset like this:
49
* cities = "Washington (ocean, river, swamp)", "New York (!mountains)"
56
ternary terrain[MAX_NUM_TERRAINS];
59
struct nation_leader {
67
char name[MAX_LEN_NAME];
69
/* How much the AI will try to select a nation in the same group */
30
/* Nation city (server only). */
33
enum nation_city_preference {
39
#define SPECLIST_TAG nation_city
40
#define SPECLIST_TYPE struct nation_city
42
#define nation_city_list_iterate(citylist, pncity) \
43
TYPED_LIST_ITERATE(struct nation_city, citylist, pncity)
44
#define nation_city_list_iterate_end LIST_ITERATE_END
48
#define SPECLIST_TAG nation_leader
49
#define SPECLIST_TYPE struct nation_leader
51
#define nation_leader_list_iterate(leaderlist, pleader) \
52
TYPED_LIST_ITERATE(struct nation_leader, leaderlist, pleader)
53
#define nation_leader_list_iterate_end LIST_ITERATE_END
57
#define SPECLIST_TAG nation_group
58
#define SPECLIST_TYPE struct nation_group
60
#define nation_group_list_iterate(grouplist, pgroup) \
61
TYPED_LIST_ITERATE(struct nation_group, grouplist, pgroup)
62
#define nation_group_list_iterate_end LIST_ITERATE_END
66
#define SPECLIST_TAG nation
67
#define SPECLIST_TYPE struct nation_type
69
#define nation_list_iterate(nationlist, pnation) \
70
TYPED_LIST_ITERATE(struct nation_type, nationlist, pnation)
71
#define nation_list_iterate_end LIST_ITERATE_END
74
#define SPECHASH_TAG nation
75
#define SPECHASH_KEY_TYPE struct nation_type *
76
#define SPECHASH_DATA_TYPE void *
78
#define nation_hash_iterate(nationhash, pnation) \
79
TYPED_HASH_KEYS_ITERATE(struct nation_type *, nationhash, pnation)
80
#define nation_hash_iterate_end HASH_KEYS_ITERATE_END
73
82
/* Pointer values are allocated on load then freed in free_nations(). */
74
83
struct nation_type {
77
86
struct name_translation noun_plural;
78
87
char flag_graphic_str[MAX_LEN_NAME];
79
88
char flag_graphic_alt[MAX_LEN_NAME];
81
struct nation_leader *leaders;
89
struct nation_leader_list *leaders;
83
struct nation_city *city_names; /* The default city names. */
84
91
char *legend; /* may be empty */
87
94
enum barbarian_type barb_type;
89
/* civilwar_nations is a NO_NATION_SELECTED-terminated list of index of
90
* the nations that can fork from this one. parent_nations is the inverse
91
* of this array. Server only. */
92
struct nation_type **civilwar_nations;
93
struct nation_type **parent_nations;
95
/* Items given to this nation at game start. Server only. */
96
int init_techs[MAX_NUM_TECH_LIST];
97
int init_buildings[MAX_NUM_BUILDING_LIST];
98
struct government *init_government;
99
struct unit_type *init_units[MAX_NUM_UNIT_LIST];
101
/* Groups which this nation is assigned to */
103
struct nation_group **groups;
105
/* Nations which we don't want in the same game.
106
* For example, British and English.
107
* Terminated with NO_NATION_SELECTED. */
108
struct nation_type **conflicts_with;
110
96
/* Unavailable nations aren't allowed to be chosen in the scenario. */
111
97
bool is_available;
99
/* Groups which this nation is assigned to */
100
struct nation_group_list *groups;
113
102
struct player *player; /* Who's using the nation, or NULL. */
106
/* Only used in the server (./ai/ and ./server/). */
108
struct nation_city_list *default_cities;
110
/* 'civilwar_nations' is a list of the nations that can fork from
111
* this one. 'parent_nations' is the inverse of this list. */
112
struct nation_list *civilwar_nations;
113
struct nation_list *parent_nations;
115
/* Nations which we don't want in the same game. For example,
116
* British and English. */
117
struct nation_list *conflicts_with;
119
/* Items given to this nation at game start. */
120
int init_techs[MAX_NUM_TECH_LIST];
121
int init_buildings[MAX_NUM_BUILDING_LIST];
122
struct government *init_government;
123
struct unit_type *init_units[MAX_NUM_UNIT_LIST];
127
/* Only used at the client. */
116
133
/* General nation accessor functions. */
123
140
struct nation_type *nation_of_city(const struct city *pcity);
124
141
struct nation_type *nation_of_unit(const struct unit *punit);
126
struct nation_type *find_nation_by_rule_name(const char *name);
127
struct nation_type *find_nation_by_translated_name(const char *name);
143
struct nation_type *nation_by_rule_name(const char *name);
144
struct nation_type *nation_by_translated_name(const char *name);
129
146
const char *nation_rule_name(const struct nation_type *pnation);
131
const char *nation_adjective_translation(struct nation_type *pnation);
148
const char *nation_adjective_translation(const struct nation_type *pnation);
132
149
const char *nation_adjective_for_player(const struct player *pplayer);
133
const char *nation_plural_translation(struct nation_type *pnation);
150
const char *nation_plural_translation(const struct nation_type *pnation);
134
151
const char *nation_plural_for_player(const struct player *pplayer);
136
153
int city_style_of_nation(const struct nation_type *nation);
142
159
const struct player *pplayer);
144
161
/* General nation leader accessor functions. */
145
struct nation_leader *get_nation_leaders(const struct nation_type *nation, int *dim);
146
struct nation_type **get_nation_civilwar(const struct nation_type *nation);
147
bool get_nation_leader_sex(const struct nation_type *nation,
149
bool check_nation_leader_name(const struct nation_type *nation,
162
const struct nation_leader_list *
163
nation_leaders(const struct nation_type *pnation);
164
struct nation_leader *nation_leader_new(struct nation_type *pnation,
165
const char *name, bool is_male);
166
struct nation_leader *
167
nation_leader_by_name(const struct nation_type *pnation, const char *name);
168
const char *nation_leader_name(const struct nation_leader *pleader);
169
bool nation_leader_is_male(const struct nation_leader *pleader);
171
/* General nation city accessor functions. */
174
const struct nation_city_list *
175
nation_cities(const struct nation_type *pnation);
176
struct nation_city *nation_city_new(struct nation_type *pnation,
179
const char *nation_city_name(const struct nation_city *pncity);
181
enum nation_city_preference
182
nation_city_preference_revert(enum nation_city_preference prefer);
183
void nation_city_set_terrain_preference(struct nation_city *pncity,
184
const struct terrain *pterrain,
185
enum nation_city_preference prefer);
186
void nation_city_set_river_preference(struct nation_city *pncity,
187
enum nation_city_preference prefer);
188
enum nation_city_preference
189
nation_city_terrain_preference(const struct nation_city *pncity,
190
const struct terrain *pterrain);
191
enum nation_city_preference
192
nation_city_river_preference(const struct nation_city *pncity);
152
194
/* General nation group accessor routines */
153
195
int nation_group_count(void);
154
196
int nation_group_index(const struct nation_group *pgroup);
155
197
int nation_group_number(const struct nation_group *pgroup);
199
struct nation_group *nation_group_new(const char *name);
157
200
struct nation_group *nation_group_by_number(int id);
158
struct nation_group *find_nation_group_by_rule_name(const char *name);
160
bool is_nation_in_group(struct nation_type *nation,
161
struct nation_group *group);
201
struct nation_group *nation_group_by_rule_name(const char *name);
203
void nation_group_set_match(struct nation_group *pgroup, int match);
205
const char *nation_group_untranslated_name(const struct nation_group *pgroup);
206
const char *nation_group_rule_name(const struct nation_group *pgroup);
207
const char *nation_group_name_translation(const struct nation_group *pgroup);
209
bool nation_is_in_group(const struct nation_type *pnation,
210
const struct nation_group *pgroup);
163
212
/* Initialization and iteration */
213
void nation_groups_init(void);
164
214
void nation_groups_free(void);
165
struct nation_group *add_new_nation_group(const char *name);
167
struct nation_group *nation_group_array_first(void);
168
const struct nation_group *nation_group_array_last(void);
170
#define nation_groups_iterate(_p) \
172
struct nation_group *_p = nation_group_array_first(); \
174
for (; _p <= nation_group_array_last(); _p++) {
176
#define nation_groups_iterate_end \
216
struct nation_group_iter;
217
size_t nation_group_iter_sizeof(void);
218
struct iterator *nation_group_iter_init(struct nation_group_iter *it);
220
#define nation_groups_iterate(NAME_pgroup) \
221
generic_iterate(struct nation_group_iter, struct nation_group *, \
222
NAME_pgroup, nation_group_iter_sizeof, \
223
nation_group_iter_init)
224
#define nation_groups_iterate_end generic_iterate_end
181
226
/* Initialization and iteration */
182
227
void nations_alloc(int num);
183
228
void nations_free(void);
184
void nation_city_names_free(struct nation_city *city_names);
186
#include "iterator.h"
230
int nations_match(const struct nation_type *pnation1,
231
const struct nation_type *pnation2,
232
bool ignore_conflicts);
187
234
struct nation_iter;
188
235
size_t nation_iter_sizeof(void);
189
236
struct iterator *nation_iter_init(struct nation_iter *it);