1 /**********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
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)
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 ***********************************************************************/
18 #endif /* __cplusplus */
25 #include "name_translation.h"
27 #include "terrain.h" /* MAX_NUM_TERRAINS */
29 #define NO_NATION_SELECTED (NULL)
31 /* Changing this value will break network compatibility. */
32 #define NATION_NONE -1
35 /* Nation city (server only). */
38 enum nation_city_preference
{
44 #define SPECLIST_TAG nation_city
45 #define SPECLIST_TYPE struct nation_city
47 #define nation_city_list_iterate(citylist, pncity) \
48 TYPED_LIST_ITERATE(struct nation_city, citylist, pncity)
49 #define nation_city_list_iterate_end LIST_ITERATE_END
53 #define SPECLIST_TAG nation_leader
54 #define SPECLIST_TYPE struct nation_leader
56 #define nation_leader_list_iterate(leaderlist, pleader) \
57 TYPED_LIST_ITERATE(struct nation_leader, leaderlist, pleader)
58 #define nation_leader_list_iterate_end LIST_ITERATE_END
62 #define SPECLIST_TAG nation_set
63 #define SPECLIST_TYPE struct nation_set
65 #define nation_set_list_iterate(setlist, pset) \
66 TYPED_LIST_ITERATE(struct nation_set, setlist, pset)
67 #define nation_set_list_iterate_end LIST_ITERATE_END
71 #define SPECLIST_TAG nation_group
72 #define SPECLIST_TYPE struct nation_group
74 #define nation_group_list_iterate(grouplist, pgroup) \
75 TYPED_LIST_ITERATE(struct nation_group, grouplist, pgroup)
76 #define nation_group_list_iterate_end LIST_ITERATE_END
80 #define SPECLIST_TAG nation
81 #define SPECLIST_TYPE struct nation_type
83 #define nation_list_iterate(nationlist, pnation) \
84 TYPED_LIST_ITERATE(struct nation_type, nationlist, pnation)
85 #define nation_list_iterate_end LIST_ITERATE_END
88 #define SPECHASH_TAG nation
89 #define SPECHASH_IKEY_TYPE struct nation_type *
90 #define SPECHASH_IDATA_TYPE void *
92 #define nation_hash_iterate(nationhash, pnation) \
93 TYPED_HASH_KEYS_ITERATE(struct nation_type *, nationhash, pnation)
94 #define nation_hash_iterate_end HASH_KEYS_ITERATE_END
96 /* Pointer values are allocated on load then freed in free_nations(). */
98 Nation_type_id item_number
;
99 char *translation_domain
;
100 struct name_translation adjective
;
101 struct name_translation noun_plural
;
102 char flag_graphic_str
[MAX_LEN_NAME
];
103 char flag_graphic_alt
[MAX_LEN_NAME
];
104 struct nation_leader_list
*leaders
;
105 struct nation_style
*style
;
106 char *legend
; /* may be empty */
109 enum barbarian_type barb_type
;
111 /* Sets which this nation is assigned to */
112 struct nation_set_list
*sets
;
114 /* Groups which this nation is assigned to */
115 struct nation_group_list
*groups
;
117 struct player
*player
; /* Who's using the nation, or NULL. */
119 /* Items given to this nation at game start. */
120 /* (Only used in the client for documentation purposes.) */
121 int init_techs
[MAX_NUM_TECH_LIST
];
122 int init_buildings
[MAX_NUM_BUILDING_LIST
];
123 struct government
*init_government
; /* use game default_government if NULL */
124 struct unit_type
*init_units
[MAX_NUM_UNIT_LIST
];
128 /* Only used in the server (./ai/ and ./server/). */
130 struct nation_city_list
*default_cities
;
132 /* 'civilwar_nations' is a list of the nations that can fork from
133 * this one. 'parent_nations' is the inverse of this list. */
134 struct nation_list
*civilwar_nations
;
135 struct nation_list
*parent_nations
;
137 /* Nations which we don't want in the same game. For example,
138 * British and English. */
139 struct nation_list
*conflicts_with
;
141 /* Nation's associated player color (NULL if none). */
142 struct rgbcolor
*rgb
;
144 struct trait_limits
*traits
;
146 /* This nation has no start position in the current scenario. */
151 /* Only used at the client. */
153 /* Whether the client is allowed to try to pick the nation at game
154 * start. Reasons for restricting this include lack of start positions
155 * in a scenario, or a nation outside the current nationset. However,
156 * in some circumstances the server may decide to put a nation with this
157 * flag in the game anyway, so the client can't rely on its absence.
158 * (On the server this is calculated on the fly from other values.
159 * Use is_nation_pickable() to get the answer on client or server.) */
165 /* Nation group structure. */
166 struct nation_group
{
167 struct name_translation name
;
172 /* Only used in the server (./server/). */
174 /* How much the AI will try to select a nation in the same group */
178 /* Add client side when needed */
182 /* General nation accessor functions. */
183 Nation_type_id
nation_count(void);
184 Nation_type_id
nation_index(const struct nation_type
*pnation
);
185 Nation_type_id
nation_number(const struct nation_type
*pnation
);
187 struct nation_type
*nation_by_number(const Nation_type_id nation
);
188 struct nation_type
*nation_of_player(const struct player
*pplayer
);
189 struct nation_type
*nation_of_city(const struct city
*pcity
);
190 struct nation_type
*nation_of_unit(const struct unit
*punit
);
192 struct nation_type
*nation_by_rule_name(const char *name
);
193 struct nation_type
*nation_by_translated_plural(const char *name
);
195 const char *nation_rule_name(const struct nation_type
*pnation
);
197 const char *nation_adjective_translation(const struct nation_type
*pnation
);
198 const char *nation_adjective_for_player(const struct player
*pplayer
);
199 const char *nation_plural_translation(const struct nation_type
*pnation
);
200 const char *nation_plural_for_player(const struct player
*pplayer
);
202 struct government
*init_government_of_nation(const struct nation_type
*pnation
);
204 struct nation_style
*style_of_nation(const struct nation_type
*pnation
);
206 const struct rgbcolor
*nation_color(const struct nation_type
*pnation
);
208 /* Ancillary nation routines */
209 bool is_nation_pickable(const struct nation_type
*nation
);
210 bool is_nation_playable(const struct nation_type
*nation
);
211 enum barbarian_type
nation_barbarian_type(const struct nation_type
*nation
);
212 bool can_conn_edit_players_nation(const struct connection
*pconn
,
213 const struct player
*pplayer
);
215 /* General nation leader accessor functions. */
216 const struct nation_leader_list
*
217 nation_leaders(const struct nation_type
*pnation
);
218 struct nation_leader
*nation_leader_new(struct nation_type
*pnation
,
219 const char *name
, bool is_male
);
220 struct nation_leader
*
221 nation_leader_by_name(const struct nation_type
*pnation
, const char *name
);
222 const char *nation_leader_name(const struct nation_leader
*pleader
);
223 bool nation_leader_is_male(const struct nation_leader
*pleader
);
225 const char *nation_legend_translation(const struct nation_type
*pnation
,
228 /* General nation city accessor functions. */
231 const struct nation_city_list
*
232 nation_cities(const struct nation_type
*pnation
);
233 struct nation_city
*nation_city_new(struct nation_type
*pnation
,
236 const char *nation_city_name(const struct nation_city
*pncity
);
238 enum nation_city_preference
239 nation_city_preference_revert(enum nation_city_preference prefer
);
240 void nation_city_set_terrain_preference(struct nation_city
*pncity
,
241 const struct terrain
*pterrain
,
242 enum nation_city_preference prefer
);
243 void nation_city_set_river_preference(struct nation_city
*pncity
,
244 enum nation_city_preference prefer
);
245 enum nation_city_preference
246 nation_city_terrain_preference(const struct nation_city
*pncity
,
247 const struct terrain
*pterrain
);
248 enum nation_city_preference
249 nation_city_river_preference(const struct nation_city
*pncity
);
251 /* General nation set accessor routines */
252 int nation_set_count(void);
253 int nation_set_index(const struct nation_set
*pset
);
254 int nation_set_number(const struct nation_set
*pset
);
256 struct nation_set
*nation_set_new(const char *set_name
,
257 const char *set_rule_name
,
258 const char *set_description
);
259 struct nation_set
*nation_set_by_number(int id
);
260 struct nation_set
*nation_set_by_rule_name(const char *name
);
262 const char *nation_set_untranslated_name(const struct nation_set
*pset
);
263 const char *nation_set_rule_name(const struct nation_set
*pset
);
264 const char *nation_set_name_translation(const struct nation_set
*pset
);
265 const char *nation_set_description(const struct nation_set
*pset
);
267 bool nation_is_in_set(const struct nation_type
*pnation
,
268 const struct nation_set
*pset
);
270 struct nation_set
*nation_set_by_setting_value(const char *setting
);
272 /* General nation group accessor routines */
273 int nation_group_count(void);
274 int nation_group_index(const struct nation_group
*pgroup
);
275 int nation_group_number(const struct nation_group
*pgroup
);
277 struct nation_group
*nation_group_new(const char *name
);
278 struct nation_group
*nation_group_by_number(int id
);
279 struct nation_group
*nation_group_by_rule_name(const char *name
);
281 void nation_group_set_hidden(struct nation_group
*pgroup
, bool hidden
);
282 void nation_group_set_match(struct nation_group
*pgroup
, int match
);
283 bool is_nation_group_hidden(struct nation_group
*pgroup
);
285 const char *nation_group_untranslated_name(const struct nation_group
*pgroup
);
286 const char *nation_group_rule_name(const struct nation_group
*pgroup
);
287 const char *nation_group_name_translation(const struct nation_group
*pgroup
);
289 bool nation_is_in_group(const struct nation_type
*pnation
,
290 const struct nation_group
*pgroup
);
292 /* Initialization and iteration */
293 void nation_sets_groups_init(void);
294 void nation_sets_groups_free(void);
296 struct nation_set_iter
;
297 size_t nation_set_iter_sizeof(void);
298 struct iterator
*nation_set_iter_init(struct nation_set_iter
*it
);
300 #define nation_sets_iterate(NAME_pset) \
301 generic_iterate(struct nation_set_iter, struct nation_set *, \
302 NAME_pset, nation_set_iter_sizeof, \
303 nation_set_iter_init)
304 #define nation_sets_iterate_end generic_iterate_end
306 struct nation_group_iter
;
307 size_t nation_group_iter_sizeof(void);
308 struct iterator
*nation_group_iter_init(struct nation_group_iter
*it
);
310 #define nation_groups_iterate(NAME_pgroup) \
311 generic_iterate(struct nation_group_iter, struct nation_group *, \
312 NAME_pgroup, nation_group_iter_sizeof, \
313 nation_group_iter_init)
314 #define nation_groups_iterate_end generic_iterate_end
316 /* Initialization and iteration */
317 void nations_alloc(int num
);
318 void nations_free(void);
320 int nations_match(const struct nation_type
*pnation1
,
321 const struct nation_type
*pnation2
,
322 bool ignore_conflicts
);
325 size_t nation_iter_sizeof(void);
326 struct iterator
*nation_iter_init(struct nation_iter
*it
);
328 /* Iterate over nations. This iterates over _all_ nations, including
329 * unplayable ones (use is_nation_playable to filter if necessary).
330 * This does not take account of the current nationset! -- on the
331 * server, use allowed_nations_iterate() for that. */
332 #define nations_iterate(NAME_pnation)\
333 generic_iterate(struct nation_iter, struct nation_type *,\
334 NAME_pnation, nation_iter_sizeof, nation_iter_init)
335 #define nations_iterate_end generic_iterate_end
339 #endif /* __cplusplus */
341 #endif /* FC__NATION_H */