Freeciv21
Develop your civilization from humble roots to a global empire
government.h
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 #pragma once
14 
15 #include <QHash>
16 // utility
17 #include "iterator.h"
18 #include "shared.h"
19 // common
20 #include "fc_types.h"
21 #include "name_translation.h"
22 #include "requirements.h"
23 
24 struct ruler_title; // Opaque type.
25 
26 /* G_LAST is a value guaranteed to be larger than any valid
27  * Government_type_id. It defines the maximum number of governments
28  * (so can also be used to size static arrays indexed by governments);
29  * it is sometimes used as a sentinel value (but not in the network
30  * protocol, which generally uses government_count()). */
31 #define G_LAST (127)
32 
33 /* This is struct government itself. All information about a form of
34  * government is contained inhere. -- SKi */
35 struct government {
37  struct name_translation name;
41  struct requirement_vector reqs;
42  QHash<const struct nation_type *, struct ruler_title *> *ruler_titles;
45 
46  // AI cached data for this government.
47  struct {
48  struct government *better; // hint: a better government (or nullptr)
49  } ai;
50  government();
51  ~government();
52 };
53 
54 extern std::vector<government> governments;
55 // General government accessor functions.
57 Government_type_id government_index(const struct government *pgovern);
58 Government_type_id government_number(const struct government *pgovern);
59 
61 struct government *government_of_player(const struct player *pplayer);
62 struct government *government_of_city(const struct city *pcity);
63 
64 struct government *government_by_rule_name(const char *name);
65 struct government *government_by_translated_name(const char *name);
66 
67 const char *government_rule_name(const struct government *pgovern);
68 const char *government_name_translation(const struct government *pgovern);
69 const char *government_name_for_player(const struct player *pplayer);
70 
71 // Ruler titles.
72 QHash<const struct nation_type *, struct ruler_title *> *
73 government_ruler_titles(const struct government *pgovern);
75  struct government *pgovern, const struct nation_type *pnation,
76  const char *ruler_male_title, const char *ruler_female_title);
77 
78 const struct nation_type *
79 ruler_title_nation(const struct ruler_title *pruler_title);
80 const char *
81 ruler_title_male_untranslated_name(const struct ruler_title *pruler_title);
82 const char *
83 ruler_title_female_untranslated_name(const struct ruler_title *pruler_title);
84 
85 const char *ruler_title_for_player(const struct player *pplayer, char *buf,
86  size_t buf_len);
87 
88 // Ancillary routines
89 bool can_change_to_government(struct player *pplayer,
90  const struct government *pgovern);
91 
92 // Initialization and iteration
93 void governments_alloc(int num);
94 void governments_free();
95 
int Government_type_id
Definition: fc_types.h:298
#define MAX_LEN_NAME
Definition: fc_types.h:61
struct government * government_of_player(const struct player *pplayer)
Return the government of a player.
Definition: government.cpp:107
struct government * government_by_number(const Government_type_id gov)
Return the government with the given index.
Definition: government.cpp:96
const char * government_name_for_player(const struct player *pplayer)
Return the (translated) name of the given government of a player.
Definition: government.cpp:147
void governments_free()
De-allocate the currently allocated governments.
Definition: government.cpp:452
const struct nation_type * ruler_title_nation(const struct ruler_title *pruler_title)
Return the nation of the rule title.
Definition: government.cpp:340
bool untargeted_revolution_allowed()
Is it possible to start a revolution without specifying the target government in the current game?
Definition: government.cpp:462
Government_type_id government_count()
Return the number of governments.
Definition: government.cpp:64
const char * government_rule_name(const struct government *pgovern)
Return the (untranslated) rule name of the government.
Definition: government.cpp:126
struct government * government_of_city(const struct city *pcity)
Return the government of the player who owns the city.
Definition: government.cpp:116
const char * ruler_title_for_player(const struct player *pplayer, char *buf, size_t buf_len)
Return the ruler title of the player (translated).
Definition: government.cpp:366
QHash< const struct nation_type *, struct ruler_title * > * government_ruler_titles(const struct government *pgovern)
Returns all ruler titles for a government type.
Definition: government.cpp:290
const char * ruler_title_female_untranslated_name(const struct ruler_title *pruler_title)
Return the female rule title name.
Definition: government.cpp:358
const char * ruler_title_male_untranslated_name(const struct ruler_title *pruler_title)
Return the male rule title name.
Definition: government.cpp:349
struct government * government_by_rule_name(const char *name)
Returns the government that has the given (untranslated) rule name.
Definition: government.cpp:48
void governments_alloc(int num)
Allocate the governments.
Definition: government.cpp:437
struct ruler_title * government_ruler_title_new(struct government *pgovern, const struct nation_type *pnation, const char *ruler_male_title, const char *ruler_female_title)
Add a new ruler title for the nation.
Definition: government.cpp:300
std::vector< government > governments
Definition: government.cpp:28
Government_type_id government_number(const struct government *pgovern)
Return the government index.
Definition: government.cpp:84
Government_type_id government_index(const struct government *pgovern)
Return the government index.
Definition: government.cpp:75
bool can_change_to_government(struct player *pplayer, const struct government *pgovern)
Can change to government if appropriate tech exists, and one of:
Definition: government.cpp:159
const char * government_name_translation(const struct government *pgovern)
Return the (translated) name of the given government.
Definition: government.cpp:136
struct government * government_by_translated_name(const char *name)
Returns the government that has the given (translated) name.
Definition: government.cpp:33
const char * name
Definition: inputfile.cpp:118
Definition: city.h:291
struct requirement_vector reqs
Definition: government.h:41
char graphic_alt[MAX_LEN_NAME]
Definition: government.h:40
bool ruledit_disabled
Definition: government.h:38
struct government * better
Definition: government.h:48
Government_type_id item_number
Definition: government.h:36
QHash< const struct nation_type *, struct ruler_title * > * ruler_titles
Definition: government.h:42
int changed_to_times
Definition: government.h:43
struct government::@38 ai
QVector< QString > * helptext
Definition: government.h:44
struct name_translation name
Definition: government.h:37
~government()
De-allocate resources associated with the given government.
Definition: government.cpp:421
government()
Allocate resources associated with the given government.
Definition: government.cpp:407
char graphic_str[MAX_LEN_NAME]
Definition: government.h:39
Definition: player.h:231
Ruler titles.
Definition: government.cpp:181
const struct nation_type * pnation
Definition: government.cpp:182