Freeciv21
Develop your civilization from humble roots to a global empire
nation.h
Go to the documentation of this file.
1 /**************************************************************************
2  Copyright (c) 1996-2020 Freeciv21 and Freeciv contributors. This file is
3  __ __ part of Freeciv21. Freeciv21 is free software: you can
4 / \\..// \ redistribute it and/or modify it under the terms of the GNU
5  ( oo ) General Public License as published by the Free Software
6  \__/ Foundation, either version 3 of the License, or (at your
7  option) any later version. You should have received
8  a copy of the GNU General Public License along with Freeciv21. If not,
9  see https://www.gnu.org/licenses/.
10 **************************************************************************/
11 #pragma once
12 
13 #include <array>
14 
15 #include "name_translation.h"
16 // utility
17 #include "iterator.h"
18 
19 #include "rgbcolor.h"
20 
21 #define NO_NATION_SELECTED (nullptr)
22 
23 // Changing this value will break network compatibility.
24 #define NATION_NONE -1
25 #define NATION_ANY -2
26 
27 extern std::vector<nation_type> nations;
28 // Nation city (server only).
29 struct nation_city;
30 
32 
33 #define SPECLIST_TAG nation_city
34 #define SPECLIST_TYPE struct nation_city
35 #include "speclist.h"
36 #define nation_city_list_iterate(citylist, pncity) \
37  TYPED_LIST_ITERATE(struct nation_city, citylist, pncity)
38 #define nation_city_list_iterate_end LIST_ITERATE_END
39 
40 // Nation leader.
41 struct nation_leader;
42 #define SPECLIST_TAG nation_leader
43 #define SPECLIST_TYPE struct nation_leader
44 #include "speclist.h"
45 #define nation_leader_list_iterate(leaderlist, pleader) \
46  TYPED_LIST_ITERATE(struct nation_leader, leaderlist, pleader)
47 #define nation_leader_list_iterate_end LIST_ITERATE_END
48 
49 // Nation set.
50 struct nation_set;
51 #define SPECLIST_TAG nation_set
52 #define SPECLIST_TYPE struct nation_set
53 #include "speclist.h"
54 #define nation_set_list_iterate(setlist, pset) \
55  TYPED_LIST_ITERATE(struct nation_set, setlist, pset)
56 #define nation_set_list_iterate_end LIST_ITERATE_END
57 
58 // Nation group.
59 struct nation_group;
60 #define SPECLIST_TAG nation_group
61 #define SPECLIST_TYPE struct nation_group
62 #include "speclist.h"
63 #define nation_group_list_iterate(grouplist, pgroup) \
64  TYPED_LIST_ITERATE(struct nation_group, grouplist, pgroup)
65 #define nation_group_list_iterate_end LIST_ITERATE_END
66 
67 // Nation list.
68 struct nation_type;
69 #define SPECLIST_TAG nation
70 #define SPECLIST_TYPE struct nation_type
71 #include "speclist.h"
72 #define nation_list_iterate(nationlist, pnation) \
73  TYPED_LIST_ITERATE(struct nation_type, nationlist, pnation)
74 #define nation_list_iterate_end LIST_ITERATE_END
75 
76 // Pointer values are allocated on load then freed in free_nations().
77 struct nation_type {
79  char *translation_domain = nullptr;
84  struct nation_leader_list *leaders = nullptr;
85  struct nation_style *style = nullptr;
86  char *legend = nullptr; // may be empty
87 
88  bool is_playable = true;
89  enum barbarian_type barb_type = NOT_A_BARBARIAN;
90 
91  // Sets which this nation is assigned to
92  struct nation_set_list *sets;
93 
94  // Groups which this nation is assigned to
95  struct nation_group_list *groups;
96 
97  struct player *player = nullptr; // Who's using the nation, or nullptr.
98 
99  // Items given to this nation at game start.
100  // (Only used in the client for documentation purposes.)
104  nullptr; // use game default_government if nullptr
105  std::array<unit_type *, MAX_NUM_UNIT_LIST> init_units = {nullptr};
106 
107  union {
108  struct {
109  /* Only used in the server (./ai/ and ./server/). */
110 
111  struct nation_city_list *default_cities;
112 
113  /* 'civilwar_nations' is a list of the nations that can fork from
114  * this one. 'parent_nations' is the inverse of this list. */
115  struct nation_list *civilwar_nations;
116  struct nation_list *parent_nations;
117 
118  /* Nations which we don't want in the same game. For example,
119  * British and English. */
120  struct nation_list *conflicts_with;
121 
122  // Nation's associated player color (nullptr if none).
123  struct rgbcolor *rgb;
124 
126 
127  // This nation has no start position in the current scenario.
130 
131  struct {
132  // Only used at the client.
133 
134  /* Whether the client is allowed to try to pick the nation at game
135  * start. Reasons for restricting this include lack of start positions
136  * in a scenario, or a nation outside the current nationset. However,
137  * in some circumstances the server may decide to put a nation with
138  * this flag in the game anyway, so the client can't rely on its
139  * absence. (On the server this is calculated on the fly from other
140  * values. Use is_nation_pickable() to get the answer on client or
141  * server.) */
144  };
145  nation_type();
146  ~nation_type();
147 };
148 
149 // Nation group structure.
150 struct nation_group {
151  struct name_translation name;
152  bool hidden;
153 
154  union {
155  struct {
156  /* Only used in the server (./server/). */
157 
158  // How much the AI will try to select a nation in the same group
159  int match;
161 
162  // Add client side when needed
163  };
164 };
165 
166 Nation_type_id nation_index(const struct nation_type *pnation);
167 
168 struct nation_type *nation_by_number(const Nation_type_id nation);
169 struct nation_type *nation_of_player(const struct player *pplayer);
170 struct nation_type *nation_of_city(const struct city *pcity);
171 struct nation_type *nation_of_unit(const struct unit *punit);
172 
173 struct nation_type *nation_by_rule_name(const char *name);
174 struct nation_type *nation_by_translated_plural(const char *name);
175 
176 const char *nation_rule_name(const struct nation_type *pnation);
177 
178 const char *nation_adjective_translation(const struct nation_type *pnation);
179 const char *nation_adjective_for_player(const struct player *pplayer);
180 const char *nation_plural_translation(const struct nation_type *pnation);
181 const char *nation_plural_for_player(const struct player *pplayer);
182 
183 struct government *
184 init_government_of_nation(const struct nation_type *pnation);
185 
186 struct nation_style *style_of_nation(const struct nation_type *pnation);
187 
188 const struct rgbcolor *nation_color(const struct nation_type *pnation);
189 
190 // Ancillary nation routines
191 bool is_nation_pickable(const struct nation_type *nation);
192 bool is_nation_playable(const struct nation_type *nation);
193 enum barbarian_type nation_barbarian_type(const struct nation_type *nation);
194 bool can_conn_edit_players_nation(const struct connection *pconn,
195  const struct player *pplayer);
196 
197 // General nation leader accessor functions.
198 const struct nation_leader_list *
199 nation_leaders(const struct nation_type *pnation);
200 struct nation_leader *nation_leader_new(struct nation_type *pnation,
201  const char *name, bool is_male);
202 struct nation_leader *
203 nation_leader_by_name(const struct nation_type *pnation, const char *name);
204 const char *nation_leader_name(const struct nation_leader *pleader);
205 bool nation_leader_is_male(const struct nation_leader *pleader);
206 
207 const char *nation_legend_translation(const struct nation_type *pnation,
208  const char *legend);
209 
210 // General nation city accessor functions.
211 struct terrain;
212 
213 const struct nation_city_list *
214 nation_cities(const struct nation_type *pnation);
215 struct nation_city *nation_city_new(struct nation_type *pnation,
216  const char *name);
217 
218 const char *nation_city_name(const struct nation_city *pncity);
219 
223  const struct terrain *pterrain,
224  enum nation_city_preference prefer);
226  enum nation_city_preference prefer);
228 nation_city_terrain_preference(const struct nation_city *pncity,
229  const struct terrain *pterrain);
231 nation_city_river_preference(const struct nation_city *pncity);
232 
233 // General nation set accessor routines
234 int nation_set_count();
235 int nation_set_index(const struct nation_set *pset);
236 int nation_set_number(const struct nation_set *pset);
237 
238 struct nation_set *nation_set_new(const char *set_name,
239  const char *set_rule_name,
240  const char *set_description);
241 struct nation_set *nation_set_by_number(int id);
242 struct nation_set *nation_set_by_rule_name(const char *name);
243 
244 const char *nation_set_untranslated_name(const struct nation_set *pset);
245 const char *nation_set_rule_name(const struct nation_set *pset);
246 const char *nation_set_name_translation(const struct nation_set *pset);
247 const char *nation_set_description(const struct nation_set *pset);
248 
249 bool nation_is_in_set(const struct nation_type *pnation,
250  const struct nation_set *pset);
251 
252 struct nation_set *nation_set_by_setting_value(const char *setting);
253 
254 // General nation group accessor routines
255 int nation_group_count();
256 int nation_group_index(const struct nation_group *pgroup);
257 int nation_group_number(const struct nation_group *pgroup);
258 
259 struct nation_group *nation_group_new(const char *name);
260 struct nation_group *nation_group_by_number(int id);
261 struct nation_group *nation_group_by_rule_name(const char *name);
262 
263 void nation_group_set_hidden(struct nation_group *pgroup, bool hidden);
264 void nation_group_set_match(struct nation_group *pgroup, int match);
265 bool is_nation_group_hidden(struct nation_group *pgroup);
266 
267 const char *
268 nation_group_untranslated_name(const struct nation_group *pgroup);
269 const char *nation_group_rule_name(const struct nation_group *pgroup);
270 const char *nation_group_name_translation(const struct nation_group *pgroup);
271 
272 bool nation_is_in_group(const struct nation_type *pnation,
273  const struct nation_group *pgroup);
274 
275 // Initialization and iteration
278 
279 struct nation_set_iter;
280 size_t nation_set_iter_sizeof();
281 struct iterator *nation_set_iter_init(struct nation_set_iter *it);
282 
283 #define nation_sets_iterate(NAME_pset) \
284  generic_iterate(struct nation_set_iter, struct nation_set *, NAME_pset, \
285  nation_set_iter_sizeof, nation_set_iter_init)
286 #define nation_sets_iterate_end generic_iterate_end
287 
288 struct nation_group_iter;
289 size_t nation_group_iter_sizeof();
291 
292 #define nation_groups_iterate(NAME_pgroup) \
293  generic_iterate(struct nation_group_iter, struct nation_group *, \
294  NAME_pgroup, nation_group_iter_sizeof, \
295  nation_group_iter_init)
296 #define nation_groups_iterate_end generic_iterate_end
297 
298 // Initialization and iteration
299 void nations_alloc(int num);
300 void nations_free();
301 
302 int nations_match(const struct nation_type *pnation1,
303  const struct nation_type *pnation2, bool ignore_conflicts);
#define MAX_NUM_BUILDING_LIST
Definition: fc_types.h:38
int Nation_type_id
Definition: fc_types.h:297
#define MAX_LEN_NAME
Definition: fc_types.h:61
#define MAX_NUM_TECH_LIST
Definition: fc_types.h:36
const char * name
Definition: inputfile.cpp:118
struct nation_set * nation_set_by_number(int id)
Return the nation set with the given index.
Definition: nation.cpp:640
void nation_group_set_match(struct nation_group *pgroup, int match)
Set how much the AI will try to select a nation in the same group.
Definition: nation.cpp:910
struct nation_type * nation_by_number(const Nation_type_id nation)
Return the nation with the given index.
Definition: nation.cpp:450
void nation_sets_groups_init()
Definition: nation.cpp:1035
size_t nation_set_iter_sizeof()
Implementation of iterator 'sizeof' function.
Definition: nation.cpp:766
void nation_sets_groups_free()
Frees and resets all nation set/group data.
Definition: nation.cpp:1040
struct nation_style * style_of_nation(const struct nation_type *pnation)
Returns nation's style.
Definition: nation.cpp:558
const char * nation_set_name_translation(const struct nation_set *pset)
Return the translated name of a nation set.
Definition: nation.cpp:693
struct nation_type * nation_of_city(const struct city *pcity)
Return the nation of the player who owns the city.
Definition: nation.cpp:429
const char * nation_group_name_translation(const struct nation_group *pgroup)
Return the translated name of a nation group.
Definition: nation.cpp:953
enum nation_city_preference nation_city_preference_revert(enum nation_city_preference prefer)
Reverts the nation city preference.
Definition: nation.cpp:347
struct nation_leader * nation_leader_by_name(const struct nation_type *pnation, const char *name)
Returns the nation leader structure which match 'name' or nullptr if not found.
Definition: nation.cpp:241
int nation_group_index(const struct nation_group *pgroup)
Return the nation group index.
Definition: nation.cpp:814
struct nation_leader * nation_leader_new(struct nation_type *pnation, const char *name, bool is_male)
Create a new leader for the nation.
Definition: nation.cpp:215
size_t nation_group_iter_sizeof()
Implementation of iterator 'sizeof' function.
Definition: nation.cpp:989
struct iterator * nation_group_iter_init(struct nation_group_iter *it)
Implementation of iterator 'init' function.
Definition: nation.cpp:1022
const char * nation_set_untranslated_name(const struct nation_set *pset)
Return the untranslated name of a nation set (including qualifier, if any).
Definition: nation.cpp:672
int nations_match(const struct nation_type *pnation1, const struct nation_type *pnation2, bool ignore_conflicts)
Returns how much two nations look good in the same game.
Definition: nation.cpp:1065
bool nation_leader_is_male(const struct nation_leader *pleader)
Return the sex of the nation leader.
Definition: nation.cpp:266
struct government * init_government_of_nation(const struct nation_type *pnation)
Returns initial government type for this nation.
Definition: nation.cpp:545
int nation_set_count()
Return the number of nation sets.
Definition: nation.cpp:577
int nation_set_index(const struct nation_set *pset)
Return the nation set index.
Definition: nation.cpp:582
enum nation_city_preference nation_city_terrain_preference(const struct nation_city *pncity, const struct terrain *pterrain)
Return the default nation city preference for the terrain.
Definition: nation.cpp:398
bool is_nation_pickable(const struct nation_type *nation)
Return whether a nation is "pickable" – whether players can select it at game start.
Definition: nation.cpp:165
const char * nation_rule_name(const struct nation_type *pnation)
Return the (untranslated) rule name of the nation (adjective form).
Definition: nation.cpp:115
std::vector< nation_type > nations
Definition: nation.cpp:38
bool is_nation_playable(const struct nation_type *nation)
Return whether a nation is "playable"; i.e., whether a human player can choose this nation.
Definition: nation.cpp:177
struct nation_city * nation_city_new(struct nation_type *pnation, const char *name)
Create a new default city for the nation (server only function).
Definition: nation.cpp:318
int nation_group_count()
Return the number of nation groups.
Definition: nation.cpp:809
struct nation_group * nation_group_new(const char *name)
Add new group into the array of groups.
Definition: nation.cpp:831
int nation_set_number(const struct nation_set *pset)
Return the nation set index.
Definition: nation.cpp:591
struct nation_set * nation_set_by_setting_value(const char *setting)
Returns the nation set that would be selected by the given value of the 'nationset' server setting.
Definition: nation.cpp:736
void nation_city_set_terrain_preference(struct nation_city *pncity, const struct terrain *pterrain, enum nation_city_preference prefer)
Set the default nation city preference for the terrain.
Definition: nation.cpp:366
const char * nation_adjective_translation(const struct nation_type *pnation)
Return the (translated) adjective for the given nation.
Definition: nation.cpp:126
struct nation_group * nation_group_by_rule_name(const char *name)
Return the nation group that has the given (untranslated) rule name.
Definition: nation.cpp:882
const char * nation_plural_for_player(const struct player *pplayer)
Return the (translated) plural noun of the given nation of a player.
Definition: nation.cpp:155
nation_city_preference
Definition: nation.h:31
@ NCP_NONE
Definition: nation.h:31
@ NCP_DISLIKE
Definition: nation.h:31
@ NCP_LIKE
Definition: nation.h:31
void nation_city_set_river_preference(struct nation_city *pncity, enum nation_city_preference prefer)
Set the default nation city preference about rivers.
Definition: nation.cpp:378
bool nation_is_in_group(const struct nation_type *pnation, const struct nation_group *pgroup)
Check if the given nation is in a given group.
Definition: nation.cpp:962
bool nation_is_in_set(const struct nation_type *pnation, const struct nation_set *pset)
Check if the given nation is in a given set.
Definition: nation.cpp:712
const struct rgbcolor * nation_color(const struct nation_type *pnation)
Returns nation's player color preference, or nullptr if none.
Definition: nation.cpp:568
struct nation_type * nation_of_unit(const struct unit *punit)
Return the nation of the player who owns the unit.
Definition: nation.cpp:438
enum nation_city_preference nation_city_river_preference(const struct nation_city *pncity)
Return the default nation city preference for rivers.
Definition: nation.cpp:410
const char * nation_set_rule_name(const struct nation_set *pset)
Return the (untranslated) rule name of a nation set.
Definition: nation.cpp:682
struct iterator * nation_set_iter_init(struct nation_set_iter *it)
Implementation of iterator 'init' function.
Definition: nation.cpp:796
const char * nation_adjective_for_player(const struct player *pplayer)
Return the (translated) adjective for the given nation of a player.
Definition: nation.cpp:146
const char * nation_legend_translation(const struct nation_type *pnation, const char *legend)
Return translated version of nation legend.
Definition: nation.cpp:275
struct nation_group * nation_group_by_number(int id)
Return the nation group with the given index.
Definition: nation.cpp:870
const char * nation_set_description(const struct nation_set *pset)
Return the (untranslated) user description of a nation set.
Definition: nation.cpp:703
bool is_nation_group_hidden(struct nation_group *pgroup)
Return whether this group should appear in the nation selection UI.
Definition: nation.cpp:920
bool can_conn_edit_players_nation(const struct connection *pconn, const struct player *pplayer)
Return TRUE iff the editor is allowed to edit the player's nation in pregame.
Definition: nation.cpp:1046
struct nation_set * nation_set_new(const char *set_name, const char *set_rule_name, const char *set_description)
Add new set into the array of nation sets.
Definition: nation.cpp:599
struct nation_type * nation_by_rule_name(const char *name)
Returns the nation that has the given (untranslated) rule name (adjective).
Definition: nation.cpp:98
Nation_type_id nation_index(const struct nation_type *pnation)
Return the nation index.
Definition: nation.cpp:464
const char * nation_leader_name(const struct nation_leader *pleader)
Return the name of the nation leader.
Definition: nation.cpp:257
const char * nation_plural_translation(const struct nation_type *pnation)
Return the (translated) plural noun of the given nation.
Definition: nation.cpp:136
struct nation_type * nation_of_player(const struct player *pplayer)
Return the nation of a player.
Definition: nation.cpp:419
const char * nation_city_name(const struct nation_city *pncity)
Return the name of the default nation city.
Definition: nation.cpp:388
void nations_free()
De-allocate the currently allocated nations.
Definition: nation.cpp:533
const struct nation_city_list * nation_cities(const struct nation_type *pnation)
Return the default cities of the nation (server only function).
Definition: nation.cpp:307
const char * nation_group_untranslated_name(const struct nation_group *pgroup)
Return the untranslated name of a nation group (including qualifier, if any).
Definition: nation.cpp:932
const struct nation_leader_list * nation_leaders(const struct nation_type *pnation)
Returns the list the nation leader names.
Definition: nation.cpp:206
struct nation_type * nation_by_translated_plural(const char *name)
Returns the nation that has the given (translated) plural noun.
Definition: nation.cpp:83
void nation_group_set_hidden(struct nation_group *pgroup, bool hidden)
Set whether this group should appear in the nation selection UI.
Definition: nation.cpp:900
struct nation_set * nation_set_by_rule_name(const char *name)
Return the nation set that has the given (untranslated) rule name.
Definition: nation.cpp:652
void nations_alloc(int num)
Allocate space for the given number of nations.
Definition: nation.cpp:520
enum barbarian_type nation_barbarian_type(const struct nation_type *nation)
Returns which kind of barbarians can use this nation.
Definition: nation.cpp:188
const char * nation_group_rule_name(const struct nation_group *pgroup)
Return the (untranslated) rule name of a nation group.
Definition: nation.cpp:942
int nation_group_number(const struct nation_group *pgroup)
Return the nation group index.
Definition: nation.cpp:823
Definition: city.h:291
Nation default cities.
Definition: nation.cpp:297
Nation group iterator.
Definition: nation.cpp:980
int match
Definition: nation.h:159
struct name_translation name
Definition: nation.h:151
struct nation_group::@52::@54 server
bool hidden
Definition: nation.h:152
Nation leader.
Definition: nation.cpp:197
bool is_male
Definition: nation.cpp:199
Nation set iterator.
Definition: nation.cpp:757
Functions for handling the nations.
Definition: nation.cpp:33
int init_buildings[MAX_NUM_BUILDING_LIST]
Definition: nation.h:102
struct nation_list * conflicts_with
Definition: nation.h:120
struct nation_group_list * groups
Definition: nation.h:95
struct name_translation noun_plural
Definition: nation.h:81
struct nation_list * parent_nations
Definition: nation.h:116
struct nation_set_list * sets
Definition: nation.h:92
char flag_graphic_str[MAX_LEN_NAME]
Definition: nation.h:82
struct name_translation adjective
Definition: nation.h:80
struct rgbcolor * rgb
Definition: nation.h:123
struct trait_limits * traits
Definition: nation.h:125
char flag_graphic_alt[MAX_LEN_NAME]
Definition: nation.h:83
bool is_pickable
Definition: nation.h:142
struct nation_leader_list * leaders
Definition: nation.h:84
struct nation_type::@48::@50 server
std::array< unit_type *, MAX_NUM_UNIT_LIST > init_units
Definition: nation.h:105
char * legend
Definition: nation.h:86
Nation_type_id item_number
Definition: nation.h:78
enum barbarian_type barb_type
Definition: nation.h:89
bool no_startpos
Definition: nation.h:128
char * translation_domain
Definition: nation.h:79
nation_type()
Allocate resources associated with the given nation.
Definition: nation.cpp:474
struct nation_type::@48::@51 client
struct nation_style * style
Definition: nation.h:85
~nation_type()
De-allocate resources associated with the given nation.
Definition: nation.cpp:499
struct nation_city_list * default_cities
Definition: nation.h:111
int init_techs[MAX_NUM_TECH_LIST]
Definition: nation.h:101
government * init_government
Definition: nation.h:103
struct nation_list * civilwar_nations
Definition: nation.h:115
bool is_playable
Definition: nation.h:88
Definition: player.h:231
Definition: unit.h:134