Freeciv21
Develop your civilization from humble roots to a global empire
nation.cpp
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2020 Freeciv21 and Freeciv
3 \_ \ / __/ contributors. This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 
18 // utility
19 #include "fcintl.h"
20 #include "name_translation.h"
21 #include "support.h"
22 
23 // common
24 #include "connection.h"
25 #include "game.h"
26 #include "government.h"
27 #include "player.h"
28 #include "traits.h"
29 
30 #include "nation.h"
31 
32 // Nation set structure.
33 struct nation_set {
34  struct name_translation name;
36 };
37 
38 std::vector<nation_type> nations;
39 static int num_nation_sets;
41 static int num_nation_groups;
43 
47 #ifdef FREECIV_DEBUG
48 #define NATION_CHECK(pnation, action) \
49  fc_assert_action(nation_check(pnation), action)
50 
55 static bool nation_check(const nation_type *pnation)
56 {
57  if (0 == game.control.nation_count) {
58  qCritical("Function called before nations setup.");
59  return false;
60  }
61  if (nullptr == pnation) {
62  qCritical("This function has nullptr nation argument.");
63  return false;
64  }
65  if (pnation->item_number < 0
66  || pnation->item_number >= game.control.nation_count
67  || &nations[nation_index(pnation)] != pnation) {
68  qCritical("This function has bad nation number %d (count %d).",
69  pnation->item_number, game.control.nation_count);
70  return false;
71  }
72  return true;
73 }
74 
75 #else // FREECIV_DEBUG
76 #define NATION_CHECK(pnation, action) // Do Nothing.
77 #endif // FREECIV_DEBUG
78 
84 {
85  for (auto &pnation : nations) {
86  if (0 == strcmp(nation_plural_translation(&pnation), name)) {
87  return &pnation;
88  }
89  } // iterate over nations - pnation
90 
91  return NO_NATION_SELECTED;
92 }
93 
98 struct nation_type *nation_by_rule_name(const char *name)
99 {
100  const char *qname = Qn_(name);
101 
102  for (auto &pnation : nations) {
103  if (0 == fc_strcasecmp(nation_rule_name(&pnation), qname)) {
104  return &pnation;
105  }
106  } // iterate over nations - pnation
107 
108  return NO_NATION_SELECTED;
109 }
110 
115 const char *nation_rule_name(const struct nation_type *pnation)
116 {
117  NATION_CHECK(pnation, return "");
118 
119  return rule_name_get(&pnation->adjective);
120 }
121 
126 const char *nation_adjective_translation(const struct nation_type *pnation)
127 {
128  NATION_CHECK(pnation, return "");
129  return name_translation_get(&pnation->adjective);
130 }
131 
136 const char *nation_plural_translation(const struct nation_type *pnation)
137 {
138  NATION_CHECK(pnation, return "");
139  return name_translation_get(&pnation->noun_plural);
140 }
141 
146 const char *nation_adjective_for_player(const struct player *pplayer)
147 {
149 }
150 
155 const char *nation_plural_for_player(const struct player *pplayer)
156 {
158 }
159 
165 bool is_nation_pickable(const struct nation_type *nation)
166 {
167  fc_assert_ret_val(!is_server(), false);
168  return nation->client.is_pickable;
169 }
170 
177 bool is_nation_playable(const struct nation_type *nation)
178 {
179  NATION_CHECK(nation, return false);
180  return nation->is_playable;
181 }
182 
188 enum barbarian_type nation_barbarian_type(const struct nation_type *nation)
189 {
190  NATION_CHECK(nation, return NOT_A_BARBARIAN);
191  return nation->barb_type;
192 }
193 
198  char *name;
199  bool is_male;
200 };
201 
205 const struct nation_leader_list *
206 nation_leaders(const struct nation_type *pnation)
207 {
208  NATION_CHECK(pnation, return nullptr);
209  return pnation->leaders;
210 }
211 
216  const char *name, bool is_male)
217 {
218  NATION_CHECK(pnation, return nullptr);
219  auto *pleader = new nation_leader;
220  pleader->name = fc_strdup(name);
221  pleader->is_male = is_male;
222 
223  nation_leader_list_append(pnation->leaders, pleader);
224  return pleader;
225 }
226 
230 static void nation_leader_destroy(struct nation_leader *pleader)
231 {
232  delete[] pleader->name;
233  delete pleader;
234 }
235 
240 struct nation_leader *
241 nation_leader_by_name(const struct nation_type *pnation, const char *name)
242 {
243  NATION_CHECK(pnation, return nullptr);
244  nation_leader_list_iterate(pnation->leaders, pleader)
245  {
246  if (0 == fc_strcasecmp(name, pleader->name)) {
247  return pleader;
248  }
249  }
251  return nullptr;
252 }
253 
257 const char *nation_leader_name(const struct nation_leader *pleader)
258 {
259  fc_assert_ret_val(nullptr != pleader, nullptr);
260  return pleader->name;
261 }
262 
266 bool nation_leader_is_male(const struct nation_leader *pleader)
267 {
268  fc_assert_ret_val(nullptr != pleader, true);
269  return pleader->is_male;
270 }
271 
275 const char *nation_legend_translation(const struct nation_type *pnation,
276  const char *legend)
277 {
278  if (pnation->translation_domain == nullptr) {
279  return _(legend);
280  }
281 
282  return DG_(pnation->translation_domain, legend);
283 }
284 
297 struct nation_city {
298  char *name;
301 };
302 
306 const struct nation_city_list *
307 nation_cities(const struct nation_type *pnation)
308 {
309  NATION_CHECK(pnation, return nullptr);
310  fc_assert_ret_val(is_server(), nullptr);
311 
312  return pnation->server.default_cities;
313 }
314 
318 struct nation_city *nation_city_new(struct nation_type *pnation,
319  const char *name)
320 {
321  struct nation_city *pncity;
322 
323  NATION_CHECK(pnation, return nullptr);
324  fc_assert_ret_val(is_server(), nullptr);
325 
326  fc_assert(0 == NCP_NONE);
327  pncity = new nation_city{}; // Set NCP_NONE.
328  pncity->name = fc_strdup(name);
329 
330  nation_city_list_append(pnation->server.default_cities, pncity);
331  return pncity;
332 }
333 
337 static void nation_city_destroy(struct nation_city *pncity)
338 {
339  delete[] pncity->name;
340  delete pncity;
341 }
342 
348 {
349  switch (prefer) {
350  case NCP_DISLIKE:
351  return NCP_LIKE;
352  case NCP_NONE:
353  return NCP_NONE;
354  case NCP_LIKE:
355  return NCP_DISLIKE;
356  }
357 
358  qCritical("%s(): Wrong nation_city_preference variant (%d).", __FUNCTION__,
359  prefer);
360  return NCP_NONE;
361 }
362 
367  const struct terrain *pterrain,
368  enum nation_city_preference prefer)
369 {
370  fc_assert_ret(nullptr != pncity);
371  fc_assert_ret(nullptr != pterrain);
372  pncity->terrain[terrain_index(pterrain)] = prefer;
373 }
374 
379  enum nation_city_preference prefer)
380 {
381  fc_assert_ret(nullptr != pncity);
382  pncity->river = prefer;
383 }
384 
388 const char *nation_city_name(const struct nation_city *pncity)
389 {
390  fc_assert_ret_val(nullptr != pncity, nullptr);
391  return pncity->name;
392 }
393 
398 nation_city_terrain_preference(const struct nation_city *pncity,
399  const struct terrain *pterrain)
400 {
401  fc_assert_ret_val(nullptr != pncity, NCP_DISLIKE);
402  fc_assert_ret_val(nullptr != pterrain, NCP_DISLIKE);
403  return pncity->terrain[terrain_index(pterrain)];
404 }
405 
410 nation_city_river_preference(const struct nation_city *pncity)
411 {
412  fc_assert_ret_val(nullptr != pncity, NCP_DISLIKE);
413  return pncity->river;
414 }
415 
419 struct nation_type *nation_of_player(const struct player *pplayer)
420 {
421  fc_assert_ret_val(nullptr != pplayer, nullptr);
422  NATION_CHECK(pplayer->nation, return nullptr);
423  return pplayer->nation;
424 }
425 
429 struct nation_type *nation_of_city(const struct city *pcity)
430 {
431  fc_assert_ret_val(pcity != nullptr, nullptr);
432  return nation_of_player(city_owner(pcity));
433 }
434 
438 struct nation_type *nation_of_unit(const struct unit *punit)
439 {
440  fc_assert_ret_val(punit != nullptr, nullptr);
441  return nation_of_player(unit_owner(punit));
442 }
443 
451 {
452  if (nation < 0 || nation >= game.control.nation_count) {
453  return nullptr;
454  }
455  return &nations[nation];
456 }
457 
465 {
466  fc_assert_ret_val(nullptr != pnation, 0);
467  return pnation - &nations[0];
468 }
469 
475 {
478 
479  leaders = nation_leader_list_new_full(nation_leader_destroy);
480  sets = nation_set_list_new();
481  groups = nation_group_list_new();
482 
483  if (is_server()) {
484  server.default_cities = nation_city_list_new_full(nation_city_destroy);
485  server.civilwar_nations = nation_list_new();
486  server.parent_nations = nation_list_new();
487  server.conflicts_with = nation_list_new();
488  server.rgb = nullptr;
489  server.traits = new trait_limits[TRAIT_COUNT];
490  } else {
491  client.is_pickable = true;
492  }
493 }
494 
500 {
501  delete[] legend;
502  delete[] translation_domain;
503  nation_leader_list_destroy(leaders);
504  nation_set_list_destroy(sets);
505  nation_group_list_destroy(groups);
506 
507  if (is_server()) {
508  nation_city_list_destroy(server.default_cities);
509  nation_list_destroy(server.civilwar_nations);
510  nation_list_destroy(server.parent_nations);
511  nation_list_destroy(server.conflicts_with);
513  delete[] server.traits;
514  }
515 }
516 
520 void nations_alloc(int num)
521 {
522  game.control.nation_count = num;
523  nations.resize(game.control.nation_count);
524  int i = 0;
525  for (auto &pnation : nations) {
526  pnation.item_number = i++;
527  } // iterate over nations - pnation
528 }
529 
534 {
535  nations.clear();
536  game.control.nation_count = 0;
537 }
538 
544 struct government *
546 {
547  NATION_CHECK(pnation, return game.default_government);
548  if (pnation->init_government) {
549  return pnation->init_government;
550  } else {
551  return game.default_government;
552  }
553 }
554 
558 struct nation_style *style_of_nation(const struct nation_type *pnation)
559 {
560  NATION_CHECK(pnation, return 0);
561  return pnation->style;
562 }
563 
568 const struct rgbcolor *nation_color(const struct nation_type *pnation)
569 {
570  NATION_CHECK(pnation, return nullptr);
571  return pnation->server.rgb;
572 }
573 
578 
582 int nation_set_index(const struct nation_set *pset)
583 {
584  fc_assert_ret_val(nullptr != pset, 0);
585  return pset - nation_sets;
586 }
587 
591 int nation_set_number(const struct nation_set *pset)
592 {
593  return nation_set_index(pset);
594 }
595 
599 struct nation_set *nation_set_new(const char *set_name,
600  const char *set_rule_name,
601  const char *set_description)
602 {
603  struct nation_set *pset;
604 
606  qCritical("Too many nation sets (%d is the maximum).",
608  return nullptr;
609  }
610 
611  // Print the name and truncate if needed.
612  pset = nation_sets + num_nation_sets;
613  names_set(&pset->name, nullptr, set_name, set_rule_name);
614  (void) sz_loud_strlcpy(
615  pset->description, set_description,
616  "Nation set description \"%s\" too long; truncating.");
617 
618  if (nullptr != nation_set_by_rule_name(rule_name_get(&pset->name))) {
619  qCritical("Duplicate nation set name %s.", rule_name_get(&pset->name));
620  return nullptr;
621  }
622 
623  if (nullptr != nation_group_by_rule_name(rule_name_get(&pset->name))) {
624  qCritical("Nation set name %s is already used for a group.",
625  rule_name_get(&pset->name));
626  return nullptr;
627  }
628 
629  num_nation_sets++;
630 
631  return pset;
632 }
633 
641 {
642  if (id < 0 || id >= num_nation_sets) {
643  return nullptr;
644  }
645  return nation_sets + id;
646 }
647 
653 {
654  const char *qname = Qn_(name);
655 
656  nation_sets_iterate(pset)
657  {
658  if (0 == fc_strcasecmp(rule_name_get(&pset->name), qname)) {
659  return pset;
660  }
661  }
663 
664  return nullptr;
665 }
666 
672 const char *nation_set_untranslated_name(const struct nation_set *pset)
673 {
674  fc_assert_ret_val(nullptr != pset, nullptr);
675  return untranslated_name(&pset->name);
676 }
677 
682 const char *nation_set_rule_name(const struct nation_set *pset)
683 {
684  fc_assert_ret_val(nullptr != pset, nullptr);
685 
686  return rule_name_get(&pset->name);
687 }
688 
693 const char *nation_set_name_translation(const struct nation_set *pset)
694 {
695  fc_assert_ret_val(nullptr != pset, nullptr);
696  return name_translation_get(&pset->name);
697 }
698 
703 const char *nation_set_description(const struct nation_set *pset)
704 {
705  fc_assert_ret_val(nullptr != pset, nullptr);
706  return pset->description;
707 }
708 
712 bool nation_is_in_set(const struct nation_type *pnation,
713  const struct nation_set *pset)
714 {
715  fc_assert_ret_val(nullptr != pnation, false);
716 
717  nation_set_list_iterate(pnation->sets, aset)
718  {
719  if (aset == pset) {
720  return true;
721  }
722  }
724  return false;
725 }
726 
737 {
738  struct nation_set *pset = nullptr;
739 
740  if (strlen(setting) > 0) {
742  }
743  if (pset == nullptr) {
744  /* Either no nation set specified, or the specified one isn't in the
745  * current ruleset. Default to the first nation set specified by
746  * the ruleset. */
747  pset = nation_set_by_number(0);
748  }
749  fc_assert(pset != nullptr);
750 
751  return pset;
752 }
753 
758  struct iterator vtable;
759  struct nation_set *p, *end;
760 };
761 #define NATION_SET_ITER(p) ((struct nation_set_iter *) (p))
762 
766 size_t nation_set_iter_sizeof() { return sizeof(struct nation_set_iter); }
767 
771 static void nation_set_iter_next(struct iterator *iter)
772 {
773  NATION_SET_ITER(iter)->p++;
774 }
775 
779 static void *nation_set_iter_get(const struct iterator *iter)
780 {
781  return NATION_SET_ITER(iter)->p;
782 }
783 
787 static bool nation_set_iter_valid(const struct iterator *iter)
788 {
789  struct nation_set_iter *it = NATION_SET_ITER(iter);
790  return it->p < it->end;
791 }
792 
797 {
801  it->p = nation_sets;
802  it->end = nation_sets + nation_set_count();
803  return ITERATOR(it);
804 }
805 
810 
814 int nation_group_index(const struct nation_group *pgroup)
815 {
816  fc_assert_ret_val(nullptr != pgroup, 0);
817  return pgroup - nation_groups;
818 }
819 
823 int nation_group_number(const struct nation_group *pgroup)
824 {
825  return nation_group_index(pgroup);
826 }
827 
831 struct nation_group *nation_group_new(const char *name)
832 {
833  struct nation_group *pgroup;
834 
836  qCritical("Too many nation groups (%d is the maximum).",
838  return nullptr;
839  }
840 
841  // Print the name and truncate if needed.
842  pgroup = nation_groups + num_nation_groups;
843  name_set(&pgroup->name, nullptr, name);
844  if (nullptr != nation_group_by_rule_name(rule_name_get(&pgroup->name))) {
845  qCritical("Duplicate nation group name %s.",
846  rule_name_get(&pgroup->name));
847  return nullptr;
848  }
849 
850  if (nullptr != nation_set_by_rule_name(rule_name_get(&pgroup->name))) {
851  qCritical("Nation group name %s is already used for a set.",
852  rule_name_get(&pgroup->name));
853  return nullptr;
854  }
855 
856  if (is_server()) {
857  pgroup->server.match = 0;
858  }
860 
861  return pgroup;
862 }
863 
871 {
872  if (id < 0 || id >= num_nation_groups) {
873  return nullptr;
874  }
875  return nation_groups + id;
876 }
877 
883 {
884  const char *qname = Qn_(name);
885 
886  nation_groups_iterate(pgroup)
887  {
888  if (0 == fc_strcasecmp(rule_name_get(&pgroup->name), qname)) {
889  return pgroup;
890  }
891  }
893 
894  return nullptr;
895 }
896 
900 void nation_group_set_hidden(struct nation_group *pgroup, bool hidden)
901 {
902  fc_assert_ret(nullptr != pgroup);
903  pgroup->hidden = hidden;
904 }
905 
910 void nation_group_set_match(struct nation_group *pgroup, int match)
911 {
913  fc_assert_ret(nullptr != pgroup);
914  pgroup->server.match = match;
915 }
916 
921 {
922  fc_assert_ret_val(nullptr != pgroup, true);
923  return pgroup->hidden;
924 }
925 
932 const char *nation_group_untranslated_name(const struct nation_group *pgroup)
933 {
934  fc_assert_ret_val(nullptr != pgroup, nullptr);
935  return untranslated_name(&pgroup->name);
936 }
937 
942 const char *nation_group_rule_name(const struct nation_group *pgroup)
943 {
944  fc_assert_ret_val(nullptr != pgroup, nullptr);
945 
946  return rule_name_get(&pgroup->name);
947 }
948 
953 const char *nation_group_name_translation(const struct nation_group *pgroup)
954 {
955  fc_assert_ret_val(nullptr != pgroup, nullptr);
956  return name_translation_get(&pgroup->name);
957 }
958 
962 bool nation_is_in_group(const struct nation_type *pnation,
963  const struct nation_group *pgroup)
964 {
965  fc_assert_ret_val(nullptr != pnation, false);
966 
967  nation_group_list_iterate(pnation->groups, agroup)
968  {
969  if (agroup == pgroup) {
970  return true;
971  }
972  }
974  return false;
975 }
976 
981  struct iterator vtable;
982  struct nation_group *p, *end;
983 };
984 #define NATION_GROUP_ITER(p) ((struct nation_group_iter *) (p))
985 
990 {
991  return sizeof(struct nation_group_iter);
992 }
993 
997 static void nation_group_iter_next(struct iterator *iter)
998 {
999  NATION_GROUP_ITER(iter)->p++;
1000 }
1001 
1005 static void *nation_group_iter_get(const struct iterator *iter)
1006 {
1007  return NATION_GROUP_ITER(iter)->p;
1008 }
1009 
1013 static bool nation_group_iter_valid(const struct iterator *iter)
1014 {
1015  struct nation_group_iter *it = NATION_GROUP_ITER(iter);
1016  return it->p < it->end;
1017 }
1018 
1023 {
1027  it->p = nation_groups;
1029  return ITERATOR(it);
1030 }
1031 
1032 /*
1033  Initializes all nation set/group data.
1034  */
1036 
1041 
1046 bool can_conn_edit_players_nation(const struct connection *pconn,
1047  const struct player *pplayer)
1048 {
1049  return (can_conn_edit(pconn)
1050  || (game.info.is_new_game
1051  && ((!pconn->observer && pconn->playing == pplayer)
1052  || pconn->access_level >= ALLOW_CTRL)));
1053 }
1054 
1065 int nations_match(const struct nation_type *pnation1,
1066  const struct nation_type *pnation2, bool ignore_conflicts)
1067 {
1068  bool in_conflict = false;
1069  int sum = 0;
1070 
1072  NATION_CHECK(pnation1, return -1);
1073  NATION_CHECK(pnation2, return -1);
1074 
1075  if (!ignore_conflicts) {
1076  nation_list_iterate(pnation1->server.conflicts_with, pnation0)
1077  {
1078  if (pnation0 == pnation2) {
1079  in_conflict = true;
1080  sum = 1; // Be sure to returns something negative.
1081  break;
1082  }
1083  }
1085 
1086  if (!in_conflict) {
1087  nation_list_iterate(pnation2->server.conflicts_with, pnation0)
1088  {
1089  if (pnation0 == pnation1) {
1090  in_conflict = true;
1091  sum = 1; // Be sure to returns something negative.
1092  break;
1093  }
1094  }
1096  }
1097  }
1098 
1099  nation_group_list_iterate(pnation1->groups, pgroup)
1100  {
1101  if (nation_is_in_group(pnation2, pgroup)) {
1102  sum += pgroup->server.match;
1103  }
1104  }
1106 
1107  return (in_conflict ? -sum : sum);
1108 }
struct player * city_owner(const struct city *pcity)
Return the owner of the city.
Definition: city.cpp:1083
bool can_conn_edit(const struct connection *pconn)
Return TRUE iff the connection is currently allowed to edit.
Definition: connection.cpp:472
#define MAX_NUM_NATION_SETS
Definition: fc_types.h:51
int Nation_type_id
Definition: fc_types.h:297
#define MAX_NUM_NATION_GROUPS
Definition: fc_types.h:53
#define DG_(domain, String)
Definition: fcintl.h:51
#define _(String)
Definition: fcintl.h:50
#define Qn_(String)
Definition: fcintl.h:66
struct civ_game game
Definition: game.cpp:47
bool is_server()
Is program type server?
Definition: game.cpp:57
const char * name
Definition: inputfile.cpp:118
#define ITERATOR(p)
Definition: iterator.h:26
#define fc_assert_ret(condition)
Definition: log.h:112
#define fc_assert(condition)
Definition: log.h:89
#define fc_assert_ret_val(condition, val)
Definition: log.h:114
static void name_set(struct name_translation *ptrans, const char *domain, const char *vernacular_name)
static const char * untranslated_name(const struct name_translation *ptrans)
static const char * rule_name_get(const struct name_translation *ptrans)
static const char * name_translation_get(const struct name_translation *ptrans)
static void names_set(struct name_translation *ptrans, const char *domain, const char *vernacular_name, const char *rule_name)
static void name_init(struct name_translation *ptrans)
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
static void nation_city_destroy(struct nation_city *pncity)
Destroy a default nation city created with nation_city_new().
Definition: nation.cpp:337
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
static struct nation_set nation_sets[MAX_NUM_NATION_SETS]
Definition: nation.cpp:40
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
static void nation_group_iter_next(struct iterator *iter)
Implementation of iterator 'next' function.
Definition: nation.cpp:997
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
static struct nation_group nation_groups[MAX_NUM_NATION_GROUPS]
Definition: nation.cpp:42
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
#define NATION_SET_ITER(p)
Definition: nation.cpp:761
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
static int num_nation_sets
Definition: nation.cpp:39
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
static int num_nation_groups
Definition: nation.cpp:41
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
static void nation_leader_destroy(struct nation_leader *pleader)
Destroy a nation leader created with nation_leader_new().
Definition: nation.cpp:230
#define NATION_GROUP_ITER(p)
Definition: nation.cpp:984
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
static void nation_set_iter_next(struct iterator *iter)
Implementation of iterator 'next' function.
Definition: nation.cpp:771
static bool nation_set_iter_valid(const struct iterator *iter)
Implementation of iterator 'valid' function.
Definition: nation.cpp:787
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
static bool nation_group_iter_valid(const struct iterator *iter)
Implementation of iterator 'valid' function.
Definition: nation.cpp:1013
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
#define NATION_CHECK(pnation, action)
Runs action if the nation is not valid.
Definition: nation.cpp:76
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
static void * nation_group_iter_get(const struct iterator *iter)
Implementation of iterator 'get' function.
Definition: nation.cpp:1005
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
static void * nation_set_iter_get(const struct iterator *iter)
Implementation of iterator 'get' function.
Definition: nation.cpp:779
int nation_group_number(const struct nation_group *pgroup)
Return the nation group index.
Definition: nation.cpp:823
#define nation_leader_list_iterate(leaderlist, pleader)
Definition: nation.h:45
#define nation_list_iterate(nationlist, pnation)
Definition: nation.h:72
#define nation_sets_iterate_end
Definition: nation.h:286
#define nation_set_list_iterate_end
Definition: nation.h:56
#define nation_group_list_iterate(grouplist, pgroup)
Definition: nation.h:63
#define nation_sets_iterate(NAME_pset)
Definition: nation.h:283
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
#define nation_list_iterate_end
Definition: nation.h:74
#define nation_leader_list_iterate_end
Definition: nation.h:47
#define nation_group_list_iterate_end
Definition: nation.h:65
#define nation_set_list_iterate(setlist, pset)
Definition: nation.h:54
#define nation_groups_iterate(NAME_pgroup)
Definition: nation.h:292
#define nation_groups_iterate_end
Definition: nation.h:296
#define NO_NATION_SELECTED
Definition: nation.h:21
#define MAX_LEN_MSG
Definition: packets.h:37
void rgbcolor_destroy(struct rgbcolor *prgbcolor)
Free rgbcolor structure.
Definition: rgbcolor.cpp:65
#define sz_loud_strlcpy(buffer, str, errmsg)
Definition: shared.h:127
Definition: city.h:291
struct packet_ruleset_control control
Definition: game.h:74
struct packet_game_info info
Definition: game.h:80
struct government * default_government
Definition: game.h:84
struct player * playing
Definition: connection.h:142
enum cmdlevel access_level
Definition: connection.h:164
bool observer
Definition: connection.h:138
bool(* valid)(const struct iterator *it)
Definition: iterator.h:23
void *(* get)(const struct iterator *it)
Definition: iterator.h:22
void(* next)(struct iterator *it)
Definition: iterator.h:21
Nation default cities.
Definition: nation.cpp:297
enum nation_city_preference river
Definition: nation.cpp:299
enum nation_city_preference terrain[MAX_NUM_TERRAINS]
Definition: nation.cpp:300
char * name
Definition: nation.cpp:298
Nation group iterator.
Definition: nation.cpp:980
struct iterator vtable
Definition: nation.cpp:981
struct nation_group * p
Definition: nation.cpp:982
struct nation_group * end
Definition: nation.cpp:982
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
char * name
Definition: nation.cpp:198
bool is_male
Definition: nation.cpp:199
Nation set iterator.
Definition: nation.cpp:757
struct iterator vtable
Definition: nation.cpp:758
struct nation_set * end
Definition: nation.cpp:759
struct nation_set * p
Definition: nation.cpp:759
Functions for handling the nations.
Definition: nation.cpp:33
struct name_translation name
Definition: nation.cpp:34
char description[MAX_LEN_MSG]
Definition: nation.cpp:35
struct nation_group_list * groups
Definition: nation.h:95
struct name_translation noun_plural
Definition: nation.h:81
struct nation_set_list * sets
Definition: nation.h:92
struct name_translation adjective
Definition: nation.h:80
struct nation_leader_list * leaders
Definition: nation.h:84
struct nation_type::@48::@50 server
char * legend
Definition: nation.h:86
Nation_type_id item_number
Definition: nation.h:78
enum barbarian_type barb_type
Definition: nation.h:89
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
government * init_government
Definition: nation.h:103
bool is_playable
Definition: nation.h:88
Definition: player.h:231
struct nation_type * nation
Definition: player.h:242
Definition: servers.h:55
Definition: unit.h:134
int fc_strcasecmp(const char *str0, const char *str1)
Compare strings like strcmp(), but ignoring case.
Definition: support.cpp:89
#define fc_strdup(str)
Definition: support.h:111
Terrain_type_id terrain_index(const struct terrain *pterrain)
Return the terrain index.
Definition: terrain.cpp:110
#define MAX_NUM_TERRAINS
Definition: terrain.h:58
#define unit_owner(_pu)
Definition: unit.h:370