Project

General

Profile

Feature #1438 ยป 0072-nation.-ch-Replace-NULL-with-nullptr.patch

Marko Lindqvist, 05/24/2025 12:53 PM

View differences:

common/nation.c
char description[MAX_LEN_MSG];
};
static struct nation_type *nations = NULL;
static struct nation_type *nations = nullptr;
static int num_nation_sets;
static struct nation_set nation_sets[MAX_NUM_NATION_SETS];
......
}
return FALSE;
}
if (NULL == pnation) {
if (pnation == nullptr) {
if (do_output) {
do_log(file, function, line, TRUE, LOG_ERROR,
"This function has NULL nation argument.");
"This function has nullptr nation argument.");
}
return FALSE;
}
......
const struct nation_leader_list *
nation_leaders(const struct nation_type *pnation)
{
NATION_CHECK(pnation, return NULL);
NATION_CHECK(pnation, return nullptr);
return pnation->leaders;
}
......
{
struct nation_leader *pleader;
NATION_CHECK(pnation, return NULL);
NATION_CHECK(pnation, return nullptr);
pleader = fc_malloc(sizeof(*pleader));
pleader->name = fc_strdup(name);
pleader->is_male = is_male;
nation_leader_list_append(pnation->leaders, pleader);
return pleader;
}
......
}
/************************************************************************//**
Returns the nation leader structure which match 'name' or NULL if not
Returns the nation leader structure which match 'name' or nullptr if not
found.
****************************************************************************/
struct nation_leader *
nation_leader_by_name(const struct nation_type *pnation, const char *name)
{
NATION_CHECK(pnation, return NULL);
NATION_CHECK(pnation, return nullptr);
nation_leader_list_iterate(pnation->leaders, pleader) {
if (0 == fc_strcasecmp(name, pleader->name)) {
if (!fc_strcasecmp(name, pleader->name)) {
return pleader;
}
} nation_leader_list_iterate_end;
return NULL;
return nullptr;
}
/************************************************************************//**
......
****************************************************************************/
const char *nation_leader_name(const struct nation_leader *pleader)
{
fc_assert_ret_val(NULL != pleader, NULL);
fc_assert_ret_val(pleader != nullptr, nullptr);
return pleader->name;
}
......
****************************************************************************/
bool nation_leader_is_male(const struct nation_leader *pleader)
{
fc_assert_ret_val(NULL != pleader, TRUE);
fc_assert_ret_val(pleader != nullptr, TRUE);
return pleader->is_male;
}
......
const char *nation_legend_translation(const struct nation_type *pnation,
const char *legend)
{
if (pnation->translation_domain == NULL) {
if (pnation->translation_domain == nullptr) {
return _(legend);
}
......
const struct nation_city_list *
nation_cities(const struct nation_type *pnation)
{
NATION_CHECK(pnation, return NULL);
fc_assert_ret_val(is_server(), NULL);
NATION_CHECK(pnation, return nullptr);
fc_assert_ret_val(is_server(), nullptr);
return pnation->server.default_cities;
}
......
{
struct nation_city *pncity;
NATION_CHECK(pnation, return NULL);
fc_assert_ret_val(is_server(), NULL);
NATION_CHECK(pnation, return nullptr);
fc_assert_ret_val(is_server(), nullptr);
fc_assert(NCP_NONE == 0);
fc_assert(0 == NCP_NONE);
pncity = fc_calloc(1, sizeof(*pncity)); /* Set NCP_NONE. */
pncity->name = fc_strdup(name);
nation_city_list_append(pnation->server.default_cities, pncity);
return pncity;
}
......
const struct terrain *pterrain,
enum nation_city_preference prefer)
{
fc_assert_ret(NULL != pncity);
fc_assert_ret(NULL != pterrain);
fc_assert_ret(pncity != nullptr);
fc_assert_ret(pterrain != nullptr);
pncity->terrain[terrain_index(pterrain)] = prefer;
}
......
void nation_city_set_river_preference(struct nation_city *pncity,
enum nation_city_preference prefer)
{
fc_assert_ret(NULL != pncity);
fc_assert_ret(pncity != nullptr);
pncity->river = prefer;
}
......
****************************************************************************/
const char *nation_city_name(const struct nation_city *pncity)
{
fc_assert_ret_val(NULL != pncity, NULL);
fc_assert_ret_val(pncity != nullptr, nullptr);
return pncity->name;
}
......
nation_city_terrain_preference(const struct nation_city *pncity,
const struct terrain *pterrain)
{
fc_assert_ret_val(NULL != pncity, NCP_DISLIKE);
fc_assert_ret_val(NULL != pterrain, NCP_DISLIKE);
fc_assert_ret_val(pncity != nullptr, NCP_DISLIKE);
fc_assert_ret_val(pterrain != nullptr, NCP_DISLIKE);
return pncity->terrain[terrain_index(pterrain)];
}
......
enum nation_city_preference
nation_city_river_preference(const struct nation_city *pncity)
{
fc_assert_ret_val(NULL != pncity, NCP_DISLIKE);
fc_assert_ret_val(pncity != nullptr, NCP_DISLIKE);
return pncity->river;
}
/************************************************************************//**
Return the nation of a player.
****************************************************************************/
struct nation_type *nation_of_player(const struct player *pplayer)
{
fc_assert_ret_val(NULL != pplayer, NULL);
NATION_CHECK(pplayer->nation, return NULL);
fc_assert_ret_val(pplayer != nullptr, nullptr);
NATION_CHECK(pplayer->nation, return nullptr);
return pplayer->nation;
}
......
****************************************************************************/
struct nation_type *nation_of_city(const struct city *pcity)
{
fc_assert_ret_val(pcity != NULL, NULL);
fc_assert_ret_val(pcity != nullptr, nullptr);
return nation_of_player(city_owner(pcity));
}
......
****************************************************************************/
struct nation_type *nation_of_unit(const struct unit *punit)
{
fc_assert_ret_val(punit != NULL, NULL);
fc_assert_ret_val(punit != nullptr, nullptr);
return nation_of_player(unit_owner(punit));
}
/************************************************************************//**
Return the nation 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 nation_type *nation_by_number(const Nation_type_id nation)
{
if (nation < 0 || nation >= game.control.nation_count) {
return NULL;
return nullptr;
}
return nations + nation;
}
......
****************************************************************************/
Nation_type_id nation_number(const struct nation_type *pnation)
{
fc_assert_ret_val(NULL != pnation, -1);
fc_assert_ret_val(pnation != nullptr, -1);
return pnation->item_number;
}
......
****************************************************************************/
Nation_type_id nation_index(const struct nation_type *pnation)
{
fc_assert_ret_val(NULL != pnation, -1);
fc_assert_ret_val(pnation != nullptr, -1);
return pnation - nations;
}
......
it->vtable.get = nation_iter_get;
it->vtable.valid = nation_iter_valid;
it->p = nations;
if (nations == NULL) {
it->end = NULL;
if (nations == nullptr) {
it->end = nullptr;
} else {
it->end = nations + nation_count();
}
return ITERATOR(it);
}
......
memset(pnation, 0, sizeof(*pnation));
pnation->item_number = pnation - nations;
pnation->translation_domain = NULL;
pnation->translation_domain = nullptr;
pnation->leaders = nation_leader_list_new_full(nation_leader_destroy);
pnation->sets = nation_set_list_new();
pnation->groups = nation_group_list_new();
......
pnation->server.civilwar_nations = nation_list_new();
pnation->server.parent_nations = nation_list_new();
pnation->server.conflicts_with = nation_list_new();
/* server.rgb starts out NULL */
/* server.rgb starts out nullptr */
pnation->server.traits = fc_calloc(TRAIT_COUNT,
sizeof(*pnation->server.traits));
}
......
{
int i;
if (NULL == nations) {
if (nations == nullptr) {
return;
}
......
}
free(nations);
nations = NULL;
nations = nullptr;
game.control.nation_count = 0;
}
/************************************************************************//**
Returns initial government type for this nation.
Always returns non-NULL -- nation-specific government or failing that
Always returns non-nullptr -- nation-specific government or failing that
ruleset default government.
****************************************************************************/
struct government *init_government_of_nation(const struct nation_type *pnation)
......
}
/************************************************************************//**
Returns nation's player color preference, or NULL if none.
Returns nation's player color preference, or nullptr if none.
Server only function.
****************************************************************************/
const struct rgbcolor *nation_color(const struct nation_type *pnation)
{
NATION_CHECK(pnation, return NULL);
NATION_CHECK(pnation, return nullptr);
return pnation->server.rgb;
}
......
****************************************************************************/
int nation_set_index(const struct nation_set *pset)
{
fc_assert_ret_val(NULL != pset, -1);
fc_assert_ret_val(pset != nullptr, -1);
return pset - nation_sets;
}
......
if (game.control.num_nation_sets <= num_nation_sets) {
log_error("More nation sets than reported (%d).",
game.control.num_nation_sets);
return NULL;
return nullptr;
}
if (MAX_NUM_NATION_SETS <= num_nation_sets) {
log_error("Too many nation sets (%d is the maximum).",
MAX_NUM_NATION_SETS);
return NULL;
return nullptr;
}
/* Print the name and truncate if needed. */
pset = nation_sets + num_nation_sets;
names_set(&pset->name, NULL, set_name, set_rule_name);
names_set(&pset->name, nullptr, set_name, set_rule_name);
(void) sz_loud_strlcpy(pset->description, set_description,
"Nation set description \"%s\" too long; truncating.");
if (NULL != nation_set_by_rule_name(rule_name_get(&pset->name))) {
if (nation_set_by_rule_name(rule_name_get(&pset->name)) != nullptr) {
log_error("Duplicate nation set name %s.", rule_name_get(&pset->name));
return NULL;
return nullptr;
}
if (NULL != nation_group_by_rule_name(rule_name_get(&pset->name))) {
if (nation_group_by_rule_name(rule_name_get(&pset->name)) != nullptr) {
log_error("Nation set name %s is already used for a group.",
rule_name_get(&pset->name));
return NULL;
return nullptr;
}
num_nation_sets++;
......
/************************************************************************//**
Return the nation set 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 nation_set *nation_set_by_number(int id)
......
* of sets (game.control.num_nation_sets) and not
* what we have already set up (num_nation_sets) */
if (id < 0 || id >= game.control.num_nation_sets) {
return NULL;
return nullptr;
}
return nation_sets + id;
......
/************************************************************************//**
Return the nation set that has the given (untranslated) rule name.
Returns NULL if no set is found.
Returns nullptr if no set is found.
****************************************************************************/
struct nation_set *nation_set_by_rule_name(const char *name)
{
......
}
} nation_sets_iterate_end;
return NULL;
return nullptr;
}
/************************************************************************//**
......
****************************************************************************/
const char *nation_set_untranslated_name(const struct nation_set *pset)
{
fc_assert_ret_val(NULL != pset, NULL);
fc_assert_ret_val(pset != nullptr, nullptr);
return untranslated_name(&pset->name);
}
......
****************************************************************************/
const char *nation_set_rule_name(const struct nation_set *pset)
{
fc_assert_ret_val(NULL != pset, NULL);
fc_assert_ret_val(pset != nullptr, nullptr);
return rule_name_get(&pset->name);
}
......
****************************************************************************/
const char *nation_set_name_translation(const struct nation_set *pset)
{
fc_assert_ret_val(NULL != pset, NULL);
fc_assert_ret_val(pset != nullptr, nullptr);
return name_translation_get(&pset->name);
}
......
****************************************************************************/
const char *nation_set_description(const struct nation_set *pset)
{
fc_assert_ret_val(NULL != pset, NULL);
fc_assert_ret_val(pset != nullptr, nullptr);
return pset->description;
}
......
bool nation_is_in_set(const struct nation_type *pnation,
const struct nation_set *pset)
{
fc_assert_ret_val(NULL != pnation, FALSE);
fc_assert_ret_val(pnation != nullptr, FALSE);
nation_set_list_iterate(pnation->sets, aset) {
if (aset == pset) {
return TRUE;
}
} nation_set_list_iterate_end;
return FALSE;
}
......
****************************************************************************/
struct nation_set *nation_set_by_setting_value(const char *setting)
{
struct nation_set *pset = NULL;
struct nation_set *pset = nullptr;
if (strlen(setting) > 0) {
pset = nation_set_by_rule_name(setting);
}
if (pset == NULL) {
if (pset == nullptr) {
/* Either no nation set specified, or the specified one isn't in the
* current ruleset. Default to the first nation set specified by
* the ruleset. */
pset = nation_set_by_number(0);
}
fc_assert(pset != NULL);
fc_assert(pset != nullptr);
return pset;
}
......
****************************************************************************/
int nation_group_index(const struct nation_group *pgroup)
{
fc_assert_ret_val(NULL != pgroup, -1);
fc_assert_ret_val(pgroup != nullptr, -1);
return pgroup - nation_groups;
}
......
if (game.control.num_nation_groups <= num_nation_groups) {
log_error("More nation groups than reported (%d).",
game.control.num_nation_groups);
return NULL;
return nullptr;
}
if (MAX_NUM_NATION_GROUPS <= num_nation_groups) {
log_error("Too many nation groups (%d is the maximum).",
MAX_NUM_NATION_GROUPS);
return NULL;
return nullptr;
}
/* Print the name and truncate if needed. */
pgroup = nation_groups + num_nation_groups;
name_set(&pgroup->name, NULL, name);
if (NULL != nation_group_by_rule_name(rule_name_get(&pgroup->name))) {
name_set(&pgroup->name, nullptr, name);
if (nation_group_by_rule_name(rule_name_get(&pgroup->name)) != nullptr) {
log_error("Duplicate nation group name %s.", rule_name_get(&pgroup->name));
return NULL;
return nullptr;
}
if (NULL != nation_set_by_rule_name(rule_name_get(&pgroup->name))) {
if (nation_set_by_rule_name(rule_name_get(&pgroup->name)) != nullptr) {
log_error("Nation group name %s is already used for a set.",
rule_name_get(&pgroup->name));
return NULL;
return nullptr;
}
if (is_server()) {
......
/************************************************************************//**
Return the nation group 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 nation_group *nation_group_by_number(int id)
......
* of groups (game.control.num_nation_groups) and not
* what we have already set up (num_nation_groups) */
if (id < 0 || id >= game.control.num_nation_groups) {
return NULL;
return nullptr;
}
return nation_groups + id;
......
/************************************************************************//**
Return the nation group that has the given (untranslated) rule name.
Returns NULL if no group is found.
Returns nullptr if no group is found.
****************************************************************************/
struct nation_group *nation_group_by_rule_name(const char *name)
{
......
}
} nation_groups_iterate_end;
return NULL;
return nullptr;
}
/************************************************************************//**
......
****************************************************************************/
void nation_group_set_hidden(struct nation_group *pgroup, bool hidden)
{
fc_assert_ret(NULL != pgroup);
fc_assert_ret(pgroup != nullptr);
pgroup->hidden = hidden;
}
......
void nation_group_set_match(struct nation_group *pgroup, int match)
{
fc_assert_ret(is_server());
fc_assert_ret(NULL != pgroup);
fc_assert_ret(pgroup != nullptr);
pgroup->server.match = match;
}
......
****************************************************************************/
bool is_nation_group_hidden(struct nation_group *pgroup)
{
fc_assert_ret_val(NULL != pgroup, TRUE);
fc_assert_ret_val(pgroup != nullptr, TRUE);
return pgroup->hidden;
}
......
****************************************************************************/
const char *nation_group_untranslated_name(const struct nation_group *pgroup)
{
fc_assert_ret_val(NULL != pgroup, NULL);
fc_assert_ret_val(pgroup != nullptr, nullptr);
return untranslated_name(&pgroup->name);
}
......
****************************************************************************/
const char *nation_group_rule_name(const struct nation_group *pgroup)
{
fc_assert_ret_val(NULL != pgroup, NULL);
fc_assert_ret_val(pgroup != nullptr, nullptr);
return rule_name_get(&pgroup->name);
}
......
****************************************************************************/
const char *nation_group_name_translation(const struct nation_group *pgroup)
{
fc_assert_ret_val(NULL != pgroup, NULL);
fc_assert_ret_val(pgroup != nullptr, nullptr);
return name_translation_get(&pgroup->name);
}
......
bool nation_is_in_group(const struct nation_type *pnation,
const struct nation_group *pgroup)
{
fc_assert_ret_val(NULL != pnation, FALSE);
fc_assert_ret_val(pnation != nullptr, FALSE);
nation_group_list_iterate(pnation->groups, agroup) {
if (agroup == pgroup) {
......
pregame.
****************************************************************************/
bool can_conn_edit_players_nation(const struct connection *pconn,
const struct player *pplayer)
const struct player *pplayer)
{
return (can_conn_edit(pconn)
|| (game.info.is_new_game
&& ((!pconn->observer && pconn->playing == pplayer)
|| pconn->access_level >= ALLOW_CTRL)));
&& ((!pconn->observer && pconn->playing == pplayer)
|| pconn->access_level >= ALLOW_CTRL)));
}
/************************************************************************//**
common/nation.h
struct rgbcolor;
#define NO_NATION_SELECTED (NULL)
#define NO_NATION_SELECTED (nullptr)
/* Changing this value will break network compatibility. */
#define NATION_NONE -1
......
/* Groups which this nation is assigned to */
struct nation_group_list *groups;
struct player *player; /* Who's using the nation, or NULL. */
struct player *player; /* Who's using the nation, or nullptr. */
/* Items given to this nation at game start. */
/* (Only used in the client for documentation purposes.) */
int init_techs[MAX_NUM_TECH_LIST];
int init_buildings[MAX_NUM_BUILDING_LIST];
struct government *init_government; /* use game default_government if NULL */
/* Use game default_government if nullptr */
struct government *init_government;
struct unit_type *init_units[MAX_NUM_UNIT_LIST];
union {
......
* British and English. */
struct nation_list *conflicts_with;
/* Nation's associated player color (NULL if none). */
/* Nation's associated player color (nullptr if none). */
struct rgbcolor *rgb;
struct trait_limits *traits;
......
bool is_nation_playable(const struct nation_type *nation);
enum barbarian_type nation_barbarian_type(const struct nation_type *nation);
bool can_conn_edit_players_nation(const struct connection *pconn,
const struct player *pplayer);
const struct player *pplayer);
/* General nation leader accessor functions. */
const struct nation_leader_list *
......
size_t nation_iter_sizeof(void);
struct iterator *nation_iter_init(struct nation_iter *it);
/* Iterate over nations. This iterates over _all_ nations, including
/* Iterate over nations. This iterates over _all_ nations, including
* unplayable ones (use is_nation_playable to filter if necessary).
* This does not take account of the current nationset! -- on the
* server, use allowed_nations_iterate() for that. */
    (1-1/1)