Freeciv-3.1
Loading...
Searching...
No Matches
nation.c
Go to the documentation of this file.
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)
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/***********************************************************************
15 Functions for handling the nations.
16***********************************************************************/
17
18#ifdef HAVE_CONFIG_H
19#include <fc_config.h>
20#endif
21
22/* utility */
23#include "fcintl.h"
24#include "log.h"
25#include "mem.h"
26#include "support.h"
27
28/* common */
29#include "connection.h"
30#include "game.h"
31#include "government.h"
32#include "player.h"
33#include "tech.h"
34#include "traits.h"
35
36#include "nation.h"
37
38
39/* Nation set structure. */
44
45static struct nation_type *nations = NULL;
46
47static int num_nation_sets;
51
52/****************************************************************************
53 Runs action if the nation is not valid.
54****************************************************************************/
55#ifdef FREECIV_DEBUG
56#define NATION_CHECK(pnation, action) \
57 fc_assert_action(nation_check(pnation, \
58 log_do_output_for_level(LOG_ERROR), \
59 __FILE__, __FUNCTION__, __FC_LINE__), \
60 action)
61
62/************************************************************************/
66static inline bool nation_check(const struct nation_type *pnation,
67 bool do_output, const char *file,
68 const char *function, int line)
69{
70 if (0 == nation_count()) {
71 if (do_output) {
72 do_log(file, function, line, TRUE, LOG_ERROR,
73 "Function called before nations setup.");
74 }
75 return FALSE;
76 }
77 if (NULL == pnation) {
78 if (do_output) {
79 do_log(file, function, line, TRUE, LOG_ERROR,
80 "This function has NULL nation argument.");
81 }
82 return FALSE;
83 }
84 if (pnation->item_number < 0
85 || pnation->item_number >= nation_count()
86 || &nations[nation_index(pnation)] != pnation) {
87 if (do_output) {
88 do_log(file, function, line, TRUE, LOG_ERROR,
89 "This function has bad nation number %d (count %d).",
90 pnation->item_number, nation_count());
91 }
92 return FALSE;
93 }
94 return TRUE;
95}
96
97#else /* FREECIV_DEBUG */
98#define NATION_CHECK(pnation, action) /* Do Nothing. */
99#endif /* FREECIV_DEBUG */
100
101/************************************************************************/
106{
107 nations_iterate(pnation) {
108 if (0 == strcmp(nation_plural_translation(pnation), name)) {
109 return pnation;
110 }
112
113 return NO_NATION_SELECTED;
114}
115
116/************************************************************************/
121{
122 const char *qname = Qn_(name);
123
124 nations_iterate(pnation) {
125 if (0 == fc_strcasecmp(nation_rule_name(pnation), qname)) {
126 return pnation;
127 }
129
130 return NO_NATION_SELECTED;
131}
132
133/************************************************************************/
137const char *nation_rule_name(const struct nation_type *pnation)
138{
139 NATION_CHECK(pnation, return "");
140
141 return rule_name_get(&pnation->adjective);
142}
143
144/************************************************************************/
148const char *nation_adjective_translation(const struct nation_type *pnation)
149{
150 NATION_CHECK(pnation, return "");
151 return name_translation_get(&pnation->adjective);
152}
153
154/************************************************************************/
158const char *nation_plural_translation(const struct nation_type *pnation)
159{
160 NATION_CHECK(pnation, return "");
161 return name_translation_get(&pnation->noun_plural);
162}
163
164/************************************************************************/
168const char *nation_adjective_for_player(const struct player *pplayer)
169{
171}
172
173/************************************************************************/
177const char *nation_plural_for_player(const struct player *pplayer)
178{
180}
181
182/************************************************************************/
187bool is_nation_pickable(const struct nation_type *nation)
188{
190 return nation->client.is_pickable;
191}
192
193/************************************************************************/
199bool is_nation_playable(const struct nation_type *nation)
200{
201 NATION_CHECK(nation, return FALSE);
202 return nation->is_playable;
203}
204
205/************************************************************************/
210enum barbarian_type nation_barbarian_type(const struct nation_type *nation)
211{
212 NATION_CHECK(nation, return NOT_A_BARBARIAN);
213 return nation->barb_type;
214}
215
216
217/****************************************************************************
218 Nation leader.
219****************************************************************************/
221 char *name;
223};
224
225/************************************************************************/
228const struct nation_leader_list *
229nation_leaders(const struct nation_type *pnation)
230{
231 NATION_CHECK(pnation, return NULL);
232 return pnation->leaders;
233}
234
235/************************************************************************/
239 const char *name, bool is_male)
240{
241 struct nation_leader *pleader;
242
243 NATION_CHECK(pnation, return NULL);
244 pleader = fc_malloc(sizeof(*pleader));
245 pleader->name = fc_strdup(name);
246 pleader->is_male = is_male;
247
248 nation_leader_list_append(pnation->leaders, pleader);
249 return pleader;
250}
251
252/************************************************************************/
255static void nation_leader_destroy(struct nation_leader *pleader)
256{
257 free(pleader->name);
258 free(pleader);
259}
260
261/************************************************************************/
265struct nation_leader *
266nation_leader_by_name(const struct nation_type *pnation, const char *name)
267{
268 NATION_CHECK(pnation, return NULL);
269 nation_leader_list_iterate(pnation->leaders, pleader) {
270 if (0 == fc_strcasecmp(name, pleader->name)) {
271 return pleader;
272 }
274 return NULL;
275}
276
277/************************************************************************/
280const char *nation_leader_name(const struct nation_leader *pleader)
281{
282 fc_assert_ret_val(NULL != pleader, NULL);
283 return pleader->name;
284}
285
286/************************************************************************/
289bool nation_leader_is_male(const struct nation_leader *pleader)
290{
291 fc_assert_ret_val(NULL != pleader, TRUE);
292 return pleader->is_male;
293}
294
295/************************************************************************/
298const char *nation_legend_translation(const struct nation_type *pnation,
299 const char *legend)
300{
301 if (pnation->translation_domain == NULL) {
302 return _(legend);
303 }
304
305 return DG_(pnation->translation_domain, legend);
306}
307
308/****************************************************************************
309 Nation default cities. The nation_city structure holds information about
310 a default choice for the city name. The 'name' field is, of course, just
311 the name for the city. The 'river' and 'terrain' fields are entries
312 recording whether the terrain is present near the city - we give higher
313 priority to cities which have matching terrain. In the case of a river we
314 only care if the city is _on_ the river, for other terrain features we
315 give the bonus if the city is close to the terrain.
316
317 This is controlled through the nation's ruleset like this:
318 cities = "Washington (ocean, river, swamp)", "New York (!mountains)"
319****************************************************************************/
325
326/************************************************************************/
329const struct nation_city_list *
330nation_cities(const struct nation_type *pnation)
331{
332 NATION_CHECK(pnation, return NULL);
334
335 return pnation->server.default_cities;
336}
337
338/************************************************************************/
342 const char *name)
343{
344 struct nation_city *pncity;
345
346 NATION_CHECK(pnation, return NULL);
348
349 fc_assert(0 == NCP_NONE);
350 pncity = fc_calloc(1, sizeof(*pncity)); /* Set NCP_NONE. */
351 pncity->name = fc_strdup(name);
352
353 nation_city_list_append(pnation->server.default_cities, pncity);
354 return pncity;
355}
356
357/************************************************************************/
360static void nation_city_destroy(struct nation_city *pncity)
361{
362 free(pncity->name);
363 free(pncity);
364}
365
366/************************************************************************/
371{
372 switch (prefer) {
373 case NCP_DISLIKE:
374 return NCP_LIKE;
375 case NCP_NONE:
376 return NCP_NONE;
377 case NCP_LIKE:
378 return NCP_DISLIKE;
379 }
380
381 log_error("%s(): Wrong nation_city_preference variant (%d).",
382 __FUNCTION__, prefer);
383 return NCP_NONE;
384}
385
386/************************************************************************/
390 const struct terrain *pterrain,
391 enum nation_city_preference prefer)
392{
393 fc_assert_ret(NULL != pncity);
394 fc_assert_ret(NULL != pterrain);
395 pncity->terrain[terrain_index(pterrain)] = prefer;
396}
397
398/************************************************************************/
402 enum nation_city_preference prefer)
403{
404 fc_assert_ret(NULL != pncity);
405 pncity->river = prefer;
406}
407
408/************************************************************************/
411const char *nation_city_name(const struct nation_city *pncity)
412{
413 fc_assert_ret_val(NULL != pncity, NULL);
414 return pncity->name;
415}
416
417/************************************************************************/
422 const struct terrain *pterrain)
423{
424 fc_assert_ret_val(NULL != pncity, NCP_DISLIKE);
425 fc_assert_ret_val(NULL != pterrain, NCP_DISLIKE);
426 return pncity->terrain[terrain_index(pterrain)];
427}
428
429/************************************************************************/
434{
435 fc_assert_ret_val(NULL != pncity, NCP_DISLIKE);
436 return pncity->river;
437}
438
439
440/************************************************************************/
443struct nation_type *nation_of_player(const struct player *pplayer)
444{
445 fc_assert_ret_val(NULL != pplayer, NULL);
446 NATION_CHECK(pplayer->nation, return NULL);
447 return pplayer->nation;
448}
449
450/************************************************************************/
453struct nation_type *nation_of_city(const struct city *pcity)
454{
455 fc_assert_ret_val(pcity != NULL, NULL);
456 return nation_of_player(city_owner(pcity));
457}
458
459/************************************************************************/
462struct nation_type *nation_of_unit(const struct unit *punit)
463{
464 fc_assert_ret_val(punit != NULL, NULL);
466}
467
468/************************************************************************/
475{
476 if (nation < 0 || nation >= game.control.nation_count) {
477 return NULL;
478 }
479 return nations + nation;
480}
481
482/************************************************************************/
486{
487 fc_assert_ret_val(NULL != pnation, -1);
488 return pnation->item_number;
489}
490
491/************************************************************************/
498{
499 fc_assert_ret_val(NULL != pnation, -1);
500 return pnation - nations;
501}
502
503/************************************************************************/
510
511/****************************************************************************
512 Nation iterator.
513****************************************************************************/
516 struct nation_type *p, *end;
517};
518#define NATION_ITER(p) ((struct nation_iter *)(p))
519
520/************************************************************************/
524{
525 return sizeof(struct nation_iter);
526}
527
528/************************************************************************/
531static void nation_iter_next(struct iterator *iter)
532{
533 NATION_ITER(iter)->p++;
534}
535
536/************************************************************************/
539static void *nation_iter_get(const struct iterator *iter)
540{
541 return NATION_ITER(iter)->p;
542}
543
544/************************************************************************/
547static bool nation_iter_valid(const struct iterator *iter)
548{
549 struct nation_iter *it = NATION_ITER(iter);
550 return it->p < it->end;
551}
552
553/************************************************************************/
557{
561 it->p = nations;
562 if (nations == NULL) {
563 it->end = NULL;
564 } else {
565 it->end = nations + nation_count();
566 }
567 return ITERATOR(it);
568}
569
570/************************************************************************/
573static void nation_init(struct nation_type *pnation)
574{
575 memset(pnation, 0, sizeof(*pnation));
576
577 pnation->item_number = pnation - nations;
578 pnation->translation_domain = NULL;
579 pnation->leaders = nation_leader_list_new_full(nation_leader_destroy);
580 pnation->sets = nation_set_list_new();
581 pnation->groups = nation_group_list_new();
582
583 if (is_server()) {
584 pnation->server.default_cities =
585 nation_city_list_new_full(nation_city_destroy);
586 pnation->server.civilwar_nations = nation_list_new();
587 pnation->server.parent_nations = nation_list_new();
588 pnation->server.conflicts_with = nation_list_new();
589 /* server.rgb starts out NULL */
590 pnation->server.traits = fc_calloc(TRAIT_COUNT,
591 sizeof(*pnation->server.traits));
592 }
593}
594
595/************************************************************************/
598static void nation_free(struct nation_type *pnation)
599{
600 free(pnation->legend);
601 FC_FREE(pnation->translation_domain);
602 nation_leader_list_destroy(pnation->leaders);
603 nation_set_list_destroy(pnation->sets);
604 nation_group_list_destroy(pnation->groups);
605
606 if (is_server()) {
607 nation_city_list_destroy(pnation->server.default_cities);
608 nation_list_destroy(pnation->server.civilwar_nations);
609 nation_list_destroy(pnation->server.parent_nations);
610 nation_list_destroy(pnation->server.conflicts_with);
611 rgbcolor_destroy(pnation->server.rgb);
612 FC_FREE(pnation->server.traits);
613 }
614
615 memset(pnation, 0, sizeof(*pnation));
616}
617
618/************************************************************************/
621void nations_alloc(int num)
622{
623 int i;
624
625 nations = fc_malloc(sizeof(*nations) * num);
627
628 for (i = 0; i < num; i++) {
629 nation_init(nations + i);
630 }
631}
632
633/************************************************************************/
636void nations_free(void)
637{
638 int i;
639
640 if (NULL == nations) {
641 return;
642 }
643
644 for (i = 0; i < game.control.nation_count; i++) {
645 nation_free(nations + i);
646 }
647
648 free(nations);
649 nations = NULL;
651}
652
653/************************************************************************/
659{
660 NATION_CHECK(pnation, return game.default_government);
661 if (pnation->init_government) {
662 return pnation->init_government;
663 } else {
665 }
666}
667
668/************************************************************************/
671struct nation_style *style_of_nation(const struct nation_type *pnation)
672{
673 NATION_CHECK(pnation, return 0);
674 return pnation->style;
675}
676
677/************************************************************************/
681const struct rgbcolor *nation_color(const struct nation_type *pnation)
682{
683 NATION_CHECK(pnation, return NULL);
684 return pnation->server.rgb;
685}
686
687/************************************************************************/
691{
692 return num_nation_sets;
693}
694
695/************************************************************************/
698int nation_set_index(const struct nation_set *pset)
699{
700 fc_assert_ret_val(NULL != pset, -1);
701 return pset - nation_sets;
702}
703
704/************************************************************************/
707int nation_set_number(const struct nation_set *pset)
708{
709 return nation_set_index(pset);
710}
711
712/************************************************************************/
715struct nation_set *nation_set_new(const char *set_name,
716 const char *set_rule_name,
717 const char *set_description)
718{
719 struct nation_set *pset;
720
722 log_error("More nation sets than reported (%d).",
724 return NULL;
725 }
726
728 log_error("Too many nation sets (%d is the maximum).",
730 return NULL;
731 }
732
733 /* Print the name and truncate if needed. */
735 names_set(&pset->name, NULL, set_name, set_rule_name);
736 (void) sz_loud_strlcpy(pset->description, set_description,
737 "Nation set description \"%s\" too long; truncating.");
738
739 if (NULL != nation_set_by_rule_name(rule_name_get(&pset->name))) {
740 log_error("Duplicate nation set name %s.", rule_name_get(&pset->name));
741 return NULL;
742 }
743
744 if (NULL != nation_group_by_rule_name(rule_name_get(&pset->name))) {
745 log_error("Nation set name %s is already used for a group.",
746 rule_name_get(&pset->name));
747 return NULL;
748 }
749
751
752 return pset;
753}
754
755/************************************************************************/
762{
763 /* Return valid pointer on client side even when the data of the
764 * group is not yet received. So compare against expected number
765 * of sets (game.control.num_nation_sets) and not
766 * what we have already set up (num_nation_sets) */
767 if (id < 0 || id >= game.control.num_nation_sets) {
768 return NULL;
769 }
770
771 return nation_sets + id;
772}
773
774/************************************************************************/
779{
780 const char *qname = Qn_(name);
781
782 nation_sets_iterate(pset) {
783 if (0 == fc_strcasecmp(rule_name_get(&pset->name), qname)) {
784 return pset;
785 }
787
788 return NULL;
789}
790
791/************************************************************************/
796const char *nation_set_untranslated_name(const struct nation_set *pset)
797{
798 fc_assert_ret_val(NULL != pset, NULL);
799 return untranslated_name(&pset->name);
800}
801
802/************************************************************************/
806const char *nation_set_rule_name(const struct nation_set *pset)
807{
808 fc_assert_ret_val(NULL != pset, NULL);
809
810 return rule_name_get(&pset->name);
811}
812
813/************************************************************************/
817const char *nation_set_name_translation(const struct nation_set *pset)
818{
819 fc_assert_ret_val(NULL != pset, NULL);
820 return name_translation_get(&pset->name);
821}
822
823/************************************************************************/
827const char *nation_set_description(const struct nation_set *pset)
828{
829 fc_assert_ret_val(NULL != pset, NULL);
830 return pset->description;
831}
832
833/************************************************************************/
836bool nation_is_in_set(const struct nation_type *pnation,
837 const struct nation_set *pset)
838{
839 fc_assert_ret_val(NULL != pnation, FALSE);
840
841 nation_set_list_iterate(pnation->sets, aset) {
842 if (aset == pset) {
843 return TRUE;
844 }
846 return FALSE;
847}
848
849/************************************************************************/
859{
860 struct nation_set *pset = NULL;
861
862 if (strlen(setting) > 0) {
864 }
865 if (pset == NULL) {
866 /* Either no nation set specified, or the specified one isn't in the
867 * current ruleset. Default to the first nation set specified by
868 * the ruleset. */
869 pset = nation_set_by_number(0);
870 }
871 fc_assert(pset != NULL);
872
873 return pset;
874}
875
876/****************************************************************************
877 Nation set iterator.
878****************************************************************************/
881 struct nation_set *p, *end;
882};
883#define NATION_SET_ITER(p) ((struct nation_set_iter *)(p))
884
885/************************************************************************/
889{
890 return sizeof(struct nation_set_iter);
891}
892
893/************************************************************************/
896static void nation_set_iter_next(struct iterator *iter)
897{
898 NATION_SET_ITER(iter)->p++;
899}
900
901/************************************************************************/
904static void *nation_set_iter_get(const struct iterator *iter)
905{
906 return NATION_SET_ITER(iter)->p;
907}
908
909/************************************************************************/
912static bool nation_set_iter_valid(const struct iterator *iter)
913{
914 struct nation_set_iter *it = NATION_SET_ITER(iter);
915 return it->p < it->end;
916}
917
918/************************************************************************/
930
931/************************************************************************/
935{
936 return num_nation_groups;
937}
938
939/************************************************************************/
942int nation_group_index(const struct nation_group *pgroup)
943{
944 fc_assert_ret_val(NULL != pgroup, -1);
945 return pgroup - nation_groups;
946}
947
948/************************************************************************/
951int nation_group_number(const struct nation_group *pgroup)
952{
953 return nation_group_index(pgroup);
954}
955
956/************************************************************************/
960{
961 struct nation_group *pgroup;
962
964 log_error("More nation groups than reported (%d).",
966 return NULL;
967 }
968
970 log_error("Too many nation groups (%d is the maximum).",
972 return NULL;
973 }
974
975 /* Print the name and truncate if needed. */
977 name_set(&pgroup->name, NULL, name);
978 if (NULL != nation_group_by_rule_name(rule_name_get(&pgroup->name))) {
979 log_error("Duplicate nation group name %s.", rule_name_get(&pgroup->name));
980 return NULL;
981 }
982
983 if (NULL != nation_set_by_rule_name(rule_name_get(&pgroup->name))) {
984 log_error("Nation group name %s is already used for a set.",
985 rule_name_get(&pgroup->name));
986 return NULL;
987 }
988
989 if (is_server()) {
990 pgroup->server.match = 0;
991 }
993
994 return pgroup;
995}
996
997/************************************************************************/
1004{
1005 /* Return valid pointer on client side even when the data of the
1006 * group is not yet received. So compare against expected number
1007 * of groups (game.control.num_nation_groups) and not
1008 * what we have already set up (num_nation_groups) */
1009 if (id < 0 || id >= game.control.num_nation_groups) {
1010 return NULL;
1011 }
1012
1013 return nation_groups + id;
1014}
1015
1016/************************************************************************/
1021{
1022 const char *qname = Qn_(name);
1023
1024 nation_groups_iterate(pgroup) {
1025 if (0 == fc_strcasecmp(rule_name_get(&pgroup->name), qname)) {
1026 return pgroup;
1027 }
1029
1030 return NULL;
1031}
1032
1033/************************************************************************/
1037{
1038 fc_assert_ret(NULL != pgroup);
1039 pgroup->hidden = hidden;
1040}
1041
1042/************************************************************************/
1047{
1049 fc_assert_ret(NULL != pgroup);
1050 pgroup->server.match = match;
1051}
1052
1053/************************************************************************/
1057{
1058 fc_assert_ret_val(NULL != pgroup, TRUE);
1059 return pgroup->hidden;
1060}
1061
1062/************************************************************************/
1068const char *nation_group_untranslated_name(const struct nation_group *pgroup)
1069{
1070 fc_assert_ret_val(NULL != pgroup, NULL);
1071 return untranslated_name(&pgroup->name);
1072}
1073
1074/************************************************************************/
1078const char *nation_group_rule_name(const struct nation_group *pgroup)
1079{
1080 fc_assert_ret_val(NULL != pgroup, NULL);
1081
1082 return rule_name_get(&pgroup->name);
1083}
1084
1085/************************************************************************/
1089const char *nation_group_name_translation(const struct nation_group *pgroup)
1090{
1091 fc_assert_ret_val(NULL != pgroup, NULL);
1092 return name_translation_get(&pgroup->name);
1093}
1094
1095/************************************************************************/
1098bool nation_is_in_group(const struct nation_type *pnation,
1099 const struct nation_group *pgroup)
1100{
1101 fc_assert_ret_val(NULL != pnation, FALSE);
1102
1103 nation_group_list_iterate(pnation->groups, agroup) {
1104 if (agroup == pgroup) {
1105 return TRUE;
1106 }
1108 return FALSE;
1109}
1110
1111/****************************************************************************
1112 Nation group iterator.
1113****************************************************************************/
1118#define NATION_GROUP_ITER(p) ((struct nation_group_iter *)(p))
1119
1120/************************************************************************/
1124{
1125 return sizeof(struct nation_group_iter);
1126}
1127
1128/************************************************************************/
1131static void nation_group_iter_next(struct iterator *iter)
1132{
1133 NATION_GROUP_ITER(iter)->p++;
1134}
1135
1136/************************************************************************/
1139static void *nation_group_iter_get(const struct iterator *iter)
1140{
1141 return NATION_GROUP_ITER(iter)->p;
1142}
1143
1144/************************************************************************/
1147static bool nation_group_iter_valid(const struct iterator *iter)
1148{
1149 struct nation_group_iter *it = NATION_GROUP_ITER(iter);
1150 return it->p < it->end;
1151}
1152
1153/************************************************************************/
1165
1166/************************************************************************/
1173
1174/************************************************************************/
1181
1182/************************************************************************/
1187 const struct player *pplayer)
1188{
1189 return (can_conn_edit(pconn)
1191 && ((!pconn->observer && pconn->playing == pplayer)
1192 || pconn->access_level >= ALLOW_CTRL)));
1193}
1194
1195/************************************************************************/
1205int nations_match(const struct nation_type *pnation1,
1206 const struct nation_type *pnation2,
1207 bool ignore_conflicts)
1208{
1209 bool in_conflict = FALSE;
1210 int sum = 0;
1211
1213 NATION_CHECK(pnation1, return -1);
1214 NATION_CHECK(pnation2, return -1);
1215
1216 if (!ignore_conflicts) {
1217 nation_list_iterate(pnation1->server.conflicts_with, pnation0) {
1218 if (pnation0 == pnation2) {
1219 in_conflict = TRUE;
1220 sum = 1; /* Be sure to return something negative. */
1221 break;
1222 }
1224
1225 if (!in_conflict) {
1226 nation_list_iterate(pnation2->server.conflicts_with, pnation0) {
1227 if (pnation0 == pnation1) {
1228 in_conflict = TRUE;
1229 sum = 1; /* Be sure to return something negative. */
1230 break;
1231 }
1233 }
1234 }
1235
1236 nation_group_list_iterate(pnation1->groups, pgroup) {
1237 if (nation_is_in_group(pnation2, pgroup)) {
1238 sum += pgroup->server.match;
1239 }
1241
1242 return (in_conflict ? -sum : sum);
1243}
#define city_owner(_pcity_)
Definition city.h:543
bool can_conn_edit(const struct connection *pconn)
Definition connection.c:510
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 * punit
Definition dialogs_g.h:73
int int id
Definition editgui_g.h:28
static bool is_server(void)
#define MAX_NUM_NATION_SETS
Definition fc_types.h:57
int Nation_type_id
Definition fc_types.h:350
#define MAX_NUM_NATION_GROUPS
Definition fc_types.h:58
#define DG_(domain, String)
Definition fcintl.h:68
#define _(String)
Definition fcintl.h:67
#define Qn_(String)
Definition fcintl.h:89
struct civ_game game
Definition game.c:57
const char * name
Definition inputfile.c:127
#define ITERATOR(p)
Definition iterator.h:37
void do_log(const char *file, const char *function, int line, bool print_from_where, enum log_level level, const char *message,...)
Definition log.c:514
#define fc_assert_ret(condition)
Definition log.h:191
#define fc_assert(condition)
Definition log.h:176
#define fc_assert_ret_val(condition, val)
Definition log.h:194
@ LOG_ERROR
Definition log.h:30
#define log_error(message,...)
Definition log.h:103
#define fc_calloc(n, esz)
Definition mem.h:38
#define FC_FREE(ptr)
Definition mem.h:41
#define fc_strdup(str)
Definition mem.h:43
#define fc_malloc(sz)
Definition mem.h:34
static void name_set(struct name_translation *ptrans, const char *domain, const char *vernacular_name)
static const char * rule_name_get(const struct name_translation *ptrans)
static const char * name_translation_get(const struct name_translation *ptrans)
static const char * untranslated_name(const struct name_translation *ptrans)
static void names_set(struct name_translation *ptrans, const char *domain, const char *vernacular_name, const char *rule_name)
void nation_group_set_match(struct nation_group *pgroup, int match)
Definition nation.c:1046
void nations_free(void)
Definition nation.c:636
const char * nation_city_name(const struct nation_city *pncity)
Definition nation.c:411
static void nation_city_destroy(struct nation_city *pncity)
Definition nation.c:360
const char * nation_group_untranslated_name(const struct nation_group *pgroup)
Definition nation.c:1068
const struct nation_city_list * nation_cities(const struct nation_type *pnation)
Definition nation.c:330
struct nation_group * nation_group_by_rule_name(const char *name)
Definition nation.c:1020
struct nation_type * nation_by_translated_plural(const char *name)
Definition nation.c:105
const char * nation_rule_name(const struct nation_type *pnation)
Definition nation.c:137
enum nation_city_preference nation_city_preference_revert(enum nation_city_preference prefer)
Definition nation.c:370
int nation_group_index(const struct nation_group *pgroup)
Definition nation.c:942
static void nation_free(struct nation_type *pnation)
Definition nation.c:598
Nation_type_id nation_count(void)
Definition nation.c:506
static void * nation_iter_get(const struct iterator *iter)
Definition nation.c:539
Nation_type_id nation_number(const struct nation_type *pnation)
Definition nation.c:485
struct nation_group * nation_group_new(const char *name)
Definition nation.c:959
struct nation_leader * nation_leader_by_name(const struct nation_type *pnation, const char *name)
Definition nation.c:266
struct iterator * nation_set_iter_init(struct nation_set_iter *it)
Definition nation.c:921
int nations_match(const struct nation_type *pnation1, const struct nation_type *pnation2, bool ignore_conflicts)
Definition nation.c:1205
static bool nation_iter_valid(const struct iterator *iter)
Definition nation.c:547
struct nation_type * nation_of_unit(const struct unit *punit)
Definition nation.c:462
bool nation_leader_is_male(const struct nation_leader *pleader)
Definition nation.c:289
const char * nation_adjective_for_player(const struct player *pplayer)
Definition nation.c:168
size_t nation_set_iter_sizeof(void)
Definition nation.c:888
static void nation_iter_next(struct iterator *iter)
Definition nation.c:531
struct nation_set * nation_set_new(const char *set_name, const char *set_rule_name, const char *set_description)
Definition nation.c:715
const char * nation_adjective_translation(const struct nation_type *pnation)
Definition nation.c:148
static struct nation_set nation_sets[MAX_NUM_NATION_SETS]
Definition nation.c:48
struct nation_type * nation_by_number(const Nation_type_id nation)
Definition nation.c:474
int nation_set_index(const struct nation_set *pset)
Definition nation.c:698
struct nation_city * nation_city_new(struct nation_type *pnation, const char *name)
Definition nation.c:341
enum nation_city_preference nation_city_terrain_preference(const struct nation_city *pncity, const struct terrain *pterrain)
Definition nation.c:421
bool is_nation_pickable(const struct nation_type *nation)
Definition nation.c:187
const struct nation_leader_list * nation_leaders(const struct nation_type *pnation)
Definition nation.c:229
const char * nation_set_name_translation(const struct nation_set *pset)
Definition nation.c:817
const char * nation_group_rule_name(const struct nation_group *pgroup)
Definition nation.c:1078
struct nation_type * nation_of_player(const struct player *pplayer)
Definition nation.c:443
const char * nation_set_untranslated_name(const struct nation_set *pset)
Definition nation.c:796
struct nation_type * nation_of_city(const struct city *pcity)
Definition nation.c:453
static void nation_group_iter_next(struct iterator *iter)
Definition nation.c:1131
bool is_nation_playable(const struct nation_type *nation)
Definition nation.c:199
static struct nation_group nation_groups[MAX_NUM_NATION_GROUPS]
Definition nation.c:50
struct iterator * nation_iter_init(struct nation_iter *it)
Definition nation.c:556
void nation_sets_groups_free(void)
Definition nation.c:1177
int nation_set_number(const struct nation_set *pset)
Definition nation.c:707
const struct rgbcolor * nation_color(const struct nation_type *pnation)
Definition nation.c:681
void nation_city_set_terrain_preference(struct nation_city *pncity, const struct terrain *pterrain, enum nation_city_preference prefer)
Definition nation.c:389
#define NATION_SET_ITER(p)
Definition nation.c:883
static int num_nation_sets
Definition nation.c:47
struct iterator * nation_group_iter_init(struct nation_group_iter *it)
Definition nation.c:1156
void nation_city_set_river_preference(struct nation_city *pncity, enum nation_city_preference prefer)
Definition nation.c:401
bool nation_is_in_group(const struct nation_type *pnation, const struct nation_group *pgroup)
Definition nation.c:1098
static void * nation_set_iter_get(const struct iterator *iter)
Definition nation.c:904
bool nation_is_in_set(const struct nation_type *pnation, const struct nation_set *pset)
Definition nation.c:836
const char * nation_set_description(const struct nation_set *pset)
Definition nation.c:827
const char * nation_group_name_translation(const struct nation_group *pgroup)
Definition nation.c:1089
enum nation_city_preference nation_city_river_preference(const struct nation_city *pncity)
Definition nation.c:433
int nation_set_count(void)
Definition nation.c:690
static int num_nation_groups
Definition nation.c:49
void nation_sets_groups_init(void)
Definition nation.c:1169
struct nation_set * nation_set_by_number(int id)
Definition nation.c:761
struct nation_type * nation_by_rule_name(const char *name)
Definition nation.c:120
struct nation_group * nation_group_by_number(int id)
Definition nation.c:1003
static void nation_leader_destroy(struct nation_leader *pleader)
Definition nation.c:255
#define NATION_GROUP_ITER(p)
Definition nation.c:1118
static void nation_set_iter_next(struct iterator *iter)
Definition nation.c:896
static bool nation_set_iter_valid(const struct iterator *iter)
Definition nation.c:912
const char * nation_plural_translation(const struct nation_type *pnation)
Definition nation.c:158
struct nation_set * nation_set_by_rule_name(const char *name)
Definition nation.c:778
bool is_nation_group_hidden(struct nation_group *pgroup)
Definition nation.c:1056
static struct nation_type * nations
Definition nation.c:45
bool can_conn_edit_players_nation(const struct connection *pconn, const struct player *pplayer)
Definition nation.c:1186
struct nation_set * nation_set_by_setting_value(const char *setting)
Definition nation.c:858
Nation_type_id nation_index(const struct nation_type *pnation)
Definition nation.c:497
const char * nation_leader_name(const struct nation_leader *pleader)
Definition nation.c:280
#define NATION_ITER(p)
Definition nation.c:518
static bool nation_group_iter_valid(const struct iterator *iter)
Definition nation.c:1147
static void * nation_group_iter_get(const struct iterator *iter)
Definition nation.c:1139
int nation_group_count(void)
Definition nation.c:934
const char * nation_set_rule_name(const struct nation_set *pset)
Definition nation.c:806
struct nation_leader * nation_leader_new(struct nation_type *pnation, const char *name, bool is_male)
Definition nation.c:238
#define NATION_CHECK(pnation, action)
Definition nation.c:98
void nation_group_set_hidden(struct nation_group *pgroup, bool hidden)
Definition nation.c:1036
static void nation_init(struct nation_type *pnation)
Definition nation.c:573
void nations_alloc(int num)
Definition nation.c:621
enum barbarian_type nation_barbarian_type(const struct nation_type *nation)
Definition nation.c:210
const char * nation_plural_for_player(const struct player *pplayer)
Definition nation.c:177
size_t nation_iter_sizeof(void)
Definition nation.c:523
int nation_group_number(const struct nation_group *pgroup)
Definition nation.c:951
size_t nation_group_iter_sizeof(void)
Definition nation.c:1123
struct government * init_government_of_nation(const struct nation_type *pnation)
Definition nation.c:658
struct nation_style * style_of_nation(const struct nation_type *pnation)
Definition nation.c:671
const char * nation_legend_translation(const struct nation_type *pnation, const char *legend)
Definition nation.c:298
#define nation_leader_list_iterate(leaderlist, pleader)
Definition nation.h:56
#define nation_list_iterate(nationlist, pnation)
Definition nation.h:83
#define nation_sets_iterate_end
Definition nation.h:304
#define nation_set_list_iterate_end
Definition nation.h:67
#define nation_group_list_iterate(grouplist, pgroup)
Definition nation.h:74
#define nation_sets_iterate(NAME_pset)
Definition nation.h:300
#define nations_iterate_end
Definition nation.h:335
nation_city_preference
Definition nation.h:38
@ NCP_NONE
Definition nation.h:40
@ NCP_DISLIKE
Definition nation.h:39
@ NCP_LIKE
Definition nation.h:41
#define nation_list_iterate_end
Definition nation.h:85
#define nations_iterate(NAME_pnation)
Definition nation.h:332
#define nation_leader_list_iterate_end
Definition nation.h:58
#define nation_group_list_iterate_end
Definition nation.h:76
#define nation_set_list_iterate(setlist, pset)
Definition nation.h:65
#define nation_groups_iterate(NAME_pgroup)
Definition nation.h:310
#define nation_groups_iterate_end
Definition nation.h:314
#define NO_NATION_SELECTED
Definition nation.h:29
#define MAX_LEN_MSG
Definition packets.h:43
void rgbcolor_destroy(struct rgbcolor *prgbcolor)
Definition rgbcolor.c:74
#define sz_loud_strlcpy(buffer, str, errmsg)
Definition shared.h:155
Definition city.h:309
struct packet_ruleset_control control
Definition game.h:83
struct packet_game_info info
Definition game.h:89
struct government * default_government
Definition game.h:93
struct player * playing
Definition connection.h:156
enum cmdlevel access_level
Definition connection.h:182
bool observer
Definition connection.h:152
bool(* valid)(const struct iterator *it)
Definition iterator.h:34
void *(* get)(const struct iterator *it)
Definition iterator.h:33
void(* next)(struct iterator *it)
Definition iterator.h:32
enum nation_city_preference river
Definition nation.c:322
enum nation_city_preference terrain[MAX_NUM_TERRAINS]
Definition nation.c:323
char * name
Definition nation.c:321
struct iterator vtable
Definition nation.c:1115
struct nation_group * p
Definition nation.c:1116
struct nation_group * end
Definition nation.c:1116
struct name_translation name
Definition nation.h:167
struct nation_group::@54::@56 server
bool hidden
Definition nation.h:168
struct iterator vtable
Definition nation.c:515
struct nation_type * end
Definition nation.c:516
struct nation_type * p
Definition nation.c:516
char * name
Definition nation.c:221
bool is_male
Definition nation.c:222
struct iterator vtable
Definition nation.c:880
struct nation_set * end
Definition nation.c:881
struct nation_set * p
Definition nation.c:881
struct name_translation name
Definition nation.c:41
char description[MAX_LEN_MSG]
Definition nation.c:42
struct nation_list * conflicts_with
Definition nation.h:139
struct nation_group_list * groups
Definition nation.h:115
struct name_translation noun_plural
Definition nation.h:101
struct nation_list * parent_nations
Definition nation.h:135
struct nation_set_list * sets
Definition nation.h:112
struct name_translation adjective
Definition nation.h:100
struct rgbcolor * rgb
Definition nation.h:142
struct nation_type::@50::@53 client
struct trait_limits * traits
Definition nation.h:144
struct government * init_government
Definition nation.h:123
bool is_pickable
Definition nation.h:160
struct nation_leader_list * leaders
Definition nation.h:104
char * legend
Definition nation.h:106
Nation_type_id item_number
Definition nation.h:98
enum barbarian_type barb_type
Definition nation.h:109
char * translation_domain
Definition nation.h:99
struct nation_type::@50::@52 server
struct nation_style * style
Definition nation.h:105
struct nation_city_list * default_cities
Definition nation.h:130
struct nation_list * civilwar_nations
Definition nation.h:134
bool is_playable
Definition nation.h:108
struct nation_type * nation
Definition player.h:260
Definition unit.h:138
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
Terrain_type_id terrain_index(const struct terrain *pterrain)
Definition terrain.c:126
#define MAX_NUM_TERRAINS
Definition terrain.h:64
#define unit_owner(_pu)
Definition unit.h:394