Feature #1972 ยป 0022-government.c-Replace-NULL-with-nullptr.patch
| common/government.c | ||
|---|---|---|
|
#include "government.h"
|
||
|
struct government *governments = NULL;
|
||
|
struct government *governments = nullptr;
|
||
|
static struct user_flag user_gov_flags[MAX_NUM_USER_GOVERNMENT_FLAGS];
|
||
|
/**********************************************************************//**
|
||
|
Returns the government that has the given (translated) name.
|
||
|
Returns NULL if none match.
|
||
|
Returns nullptr if none match.
|
||
|
**************************************************************************/
|
||
|
struct government *government_by_translated_name(const char *name)
|
||
|
{
|
||
| ... | ... | |
|
}
|
||
|
} governments_iterate_end;
|
||
|
return NULL;
|
||
|
return nullptr;
|
||
|
}
|
||
|
/**********************************************************************//**
|
||
|
Returns the government that has the given (untranslated) rule name.
|
||
|
Returns NULL if none match.
|
||
|
Returns nullptr if none match.
|
||
|
**************************************************************************/
|
||
|
struct government *government_by_rule_name(const char *name)
|
||
|
{
|
||
| ... | ... | |
|
}
|
||
|
} governments_iterate_end;
|
||
|
return NULL;
|
||
|
return nullptr;
|
||
|
}
|
||
|
/**********************************************************************//**
|
||
| ... | ... | |
|
**************************************************************************/
|
||
|
Government_type_id government_index(const struct government *pgovern)
|
||
|
{
|
||
|
fc_assert_ret_val(NULL != pgovern, -1);
|
||
|
fc_assert_ret_val(pgovern != nullptr, -1);
|
||
|
return pgovern - governments;
|
||
|
}
|
||
| ... | ... | |
|
**************************************************************************/
|
||
|
Government_type_id government_number(const struct government *pgovern)
|
||
|
{
|
||
|
fc_assert_ret_val(NULL != pgovern, -1);
|
||
|
fc_assert_ret_val(pgovern != nullptr, -1);
|
||
|
return pgovern->item_number;
|
||
|
}
|
||
|
/**********************************************************************//**
|
||
|
Return the government with the given index.
|
||
|
This function returns NULL for an out-of-range index (some callers
|
||
|
This function returns nullptr for an out-of-range index (some callers
|
||
|
rely on this).
|
||
|
**************************************************************************/
|
||
|
struct government *government_by_number(const Government_type_id gov)
|
||
|
{
|
||
|
if (gov < 0 || gov >= game.control.government_count) {
|
||
|
return NULL;
|
||
|
return nullptr;
|
||
|
}
|
||
|
return &governments[gov];
|
||
|
}
|
||
| ... | ... | |
|
**************************************************************************/
|
||
|
struct government *government_of_player(const struct player *pplayer)
|
||
|
{
|
||
|
fc_assert_ret_val(NULL != pplayer, NULL);
|
||
|
fc_assert_ret_val(pplayer != nullptr, nullptr);
|
||
|
return pplayer->government;
|
||
|
}
|
||
| ... | ... | |
|
**************************************************************************/
|
||
|
struct government *government_of_city(const struct city *pcity)
|
||
|
{
|
||
|
fc_assert_ret_val(NULL != pcity, NULL);
|
||
|
fc_assert_ret_val(pcity != nullptr, nullptr);
|
||
|
return government_of_player(city_owner(pcity));
|
||
|
}
|
||
| ... | ... | |
|
**************************************************************************/
|
||
|
const char *government_rule_name(const struct government *pgovern)
|
||
|
{
|
||
|
fc_assert_ret_val(NULL != pgovern, NULL);
|
||
|
fc_assert_ret_val(pgovern != nullptr, nullptr);
|
||
|
return rule_name_get(&pgovern->name);
|
||
|
}
|
||
| ... | ... | |
|
**************************************************************************/
|
||
|
const char *government_name_translation(const struct government *pgovern)
|
||
|
{
|
||
|
fc_assert_ret_val(NULL != pgovern, NULL);
|
||
|
fc_assert_ret_val(pgovern != nullptr, nullptr);
|
||
|
return name_translation_get(&pgovern->name);
|
||
|
}
|
||
| ... | ... | |
|
- no required tech (required is A_NONE)
|
||
|
- player has required tech
|
||
|
- we have an appropriate wonder
|
||
|
Returns FALSE if pplayer is NULL (used for observers).
|
||
|
Returns FALSE if pplayer is nullptr (used for observers).
|
||
|
**************************************************************************/
|
||
|
bool can_change_to_government(struct player *pplayer,
|
||
|
const struct government *gov)
|
||
|
{
|
||
|
fc_assert_ret_val(NULL != gov, FALSE);
|
||
|
fc_assert_ret_val(gov != nullptr, FALSE);
|
||
|
if (!pplayer) {
|
||
|
return FALSE;
|
||
| ... | ... | |
|
}
|
||
|
return are_reqs_active(&(const struct req_context) { .player = pplayer },
|
||
|
NULL, &gov->reqs, RPT_CERTAIN);
|
||
|
nullptr, &gov->reqs, RPT_CERTAIN);
|
||
|
}
|
||
| ... | ... | |
|
**************************************************************************/
|
||
|
static genhash_val_t nation_hash_val(const struct nation_type *pnation)
|
||
|
{
|
||
|
return NULL != pnation ? nation_number(pnation) : nation_count();
|
||
|
return pnation != nullptr ? nation_number(pnation) : nation_count();
|
||
|
}
|
||
|
/**********************************************************************//**
|
||
| ... | ... | |
|
bool ret = TRUE;
|
||
|
if (!formats_match(rule_name_get(&pruler_title->male), "%s")) {
|
||
|
if (NULL != pruler_title->pnation) {
|
||
|
if (pruler_title->pnation != nullptr) {
|
||
|
log_error("\"%s\" male ruler title for nation \"%s\" (nb %d) "
|
||
|
"is not a format. It should match \"%%s\"",
|
||
|
rule_name_get(&pruler_title->male),
|
||
| ... | ... | |
|
}
|
||
|
if (!formats_match(rule_name_get(&pruler_title->female), "%s")) {
|
||
|
if (NULL != pruler_title->pnation) {
|
||
|
if (pruler_title->pnation != nullptr) {
|
||
|
log_error("\"%s\" female ruler title for nation \"%s\" (nb %d) "
|
||
|
"is not a format. It should match \"%%s\"",
|
||
|
rule_name_get(&pruler_title->female),
|
||
| ... | ... | |
|
}
|
||
|
if (!formats_match(name_translation_get(&pruler_title->male), "%s")) {
|
||
|
if (NULL != pruler_title->pnation) {
|
||
|
if (pruler_title->pnation != nullptr) {
|
||
|
log_error("Translation of \"%s\" male ruler title for nation \"%s\" "
|
||
|
"(nb %d) is not a format (\"%s\"). It should match \"%%s\"",
|
||
|
rule_name_get(&pruler_title->male),
|
||
| ... | ... | |
|
}
|
||
|
if (!formats_match(name_translation_get(&pruler_title->female), "%s")) {
|
||
|
if (NULL != pruler_title->pnation) {
|
||
|
if (pruler_title->pnation != nullptr) {
|
||
|
log_error("Translation of \"%s\" female ruler title for nation \"%s\" "
|
||
|
"(nb %d) is not a format (\"%s\"). It should match \"%%s\"",
|
||
|
rule_name_get(&pruler_title->female),
|
||
| ... | ... | |
|
const struct ruler_title_hash *
|
||
|
government_ruler_titles(const struct government *pgovern)
|
||
|
{
|
||
|
fc_assert_ret_val(NULL != pgovern, NULL);
|
||
|
fc_assert_ret_val(pgovern != nullptr, nullptr);
|
||
|
return pgovern->ruler_titles;
|
||
|
}
|
||
|
/**********************************************************************//**
|
||
|
Add a new ruler title for the nation. Pass NULL for pnation for defining
|
||
|
the default title.
|
||
|
Add a new ruler title for the nation. Pass nullptr for pnation
|
||
|
for defining the default title.
|
||
|
**************************************************************************/
|
||
|
struct ruler_title *
|
||
|
government_ruler_title_new(struct government *pgovern,
|
||
| ... | ... | |
|
const char *ruler_male_title,
|
||
|
const char *ruler_female_title)
|
||
|
{
|
||
|
const char *domain = NULL;
|
||
|
const char *domain = nullptr;
|
||
|
struct ruler_title *pruler_title;
|
||
|
if (pnation != NULL) {
|
||
|
if (pnation != nullptr) {
|
||
|
domain = pnation->translation_domain;
|
||
|
}
|
||
|
pruler_title =
|
||
| ... | ... | |
|
if (!ruler_title_check(pruler_title)) {
|
||
|
ruler_title_destroy(pruler_title);
|
||
|
return NULL;
|
||
|
return nullptr;
|
||
|
}
|
||
|
if (ruler_title_hash_replace(pgovern->ruler_titles,
|
||
|
pnation, pruler_title)) {
|
||
|
if (NULL != pnation) {
|
||
|
if (pnation != nullptr) {
|
||
|
log_error("Ruler title for government \"%s\" (nb %d) and "
|
||
|
"nation \"%s\" (nb %d) was set twice.",
|
||
|
government_rule_name(pgovern), government_number(pgovern),
|
||
| ... | ... | |
|
}
|
||
|
/**********************************************************************//**
|
||
|
Return the nation of the ruler title. Returns NULL if this is default.
|
||
|
Return the nation of the ruler title. Returns nullptr if this is default.
|
||
|
**************************************************************************/
|
||
|
const struct nation_type *
|
||
|
ruler_title_nation(const struct ruler_title *pruler_title)
|
||
| ... | ... | |
|
const struct nation_type *pnation = nation_of_player(pplayer);
|
||
|
struct ruler_title *pruler_title;
|
||
|
fc_assert_ret_val(NULL != buf, NULL);
|
||
|
fc_assert_ret_val(0 < buf_len, NULL);
|
||
|
fc_assert_ret_val(buf != nullptr, nullptr);
|
||
|
fc_assert_ret_val(0 < buf_len, nullptr);
|
||
|
/* Try specific nation ruler title. */
|
||
|
if (!ruler_title_hash_lookup(pgovern->ruler_titles,
|
||
|
pnation, &pruler_title)
|
||
|
/* Try default ruler title. */
|
||
|
&& !ruler_title_hash_lookup(pgovern->ruler_titles,
|
||
|
NULL, &pruler_title)) {
|
||
|
nullptr, &pruler_title)) {
|
||
|
log_error("Missing title for government \"%s\" (nb %d) "
|
||
|
"nation \"%s\" (nb %d).",
|
||
|
government_rule_name(pgovern), government_number(pgovern),
|
||
| ... | ... | |
|
memset(pgovern, 0, sizeof(*pgovern));
|
||
|
pgovern->item_number = pgovern - governments;
|
||
|
pgovern->ruler_titles =
|
||
|
ruler_title_hash_new_full(nation_hash_val, nation_hash_comp,
|
||
|
NULL, NULL, NULL, ruler_title_destroy);
|
||
|
pgovern->ruler_titles
|
||
|
= ruler_title_hash_new_full(nation_hash_val, nation_hash_comp,
|
||
|
nullptr, nullptr, nullptr, ruler_title_destroy);
|
||
|
requirement_vector_init(&pgovern->reqs);
|
||
|
pgovern->changed_to_times = 0;
|
||
|
pgovern->ruledit_disabled = FALSE;
|
||
|
pgovern->ruledit_dlg = NULL;
|
||
|
pgovern->ruledit_dlg = nullptr;
|
||
|
}
|
||
|
/**********************************************************************//**
|
||
| ... | ... | |
|
static inline void government_free(struct government *pgovern)
|
||
|
{
|
||
|
ruler_title_hash_destroy(pgovern->ruler_titles);
|
||
|
pgovern->ruler_titles = NULL;
|
||
|
pgovern->ruler_titles = nullptr;
|
||
|
if (NULL != pgovern->helptext) {
|
||
|
if (pgovern->helptext != nullptr) {
|
||
|
strvec_destroy(pgovern->helptext);
|
||
|
pgovern->helptext = NULL;
|
||
|
pgovern->helptext = nullptr;
|
||
|
}
|
||
|
requirement_vector_free(&pgovern->reqs);
|
||
| ... | ... | |
|
{
|
||
|
int i;
|
||
|
fc_assert(NULL == governments);
|
||
|
fc_assert(governments == nullptr);
|
||
|
governments = fc_malloc(sizeof(*governments) * num);
|
||
|
game.control.government_count = num;
|
||
| ... | ... | |
|
{
|
||
|
int i;
|
||
|
if (NULL == governments) {
|
||
|
if (governments == nullptr) {
|
||
|
return;
|
||
|
}
|
||
| ... | ... | |
|
}
|
||
|
free(governments);
|
||
|
governments = NULL;
|
||
|
governments = nullptr;
|
||
|
game.control.government_count = 0;
|
||
|
}
|
||