Project

General

Profile

Feature #1384 ยป 0050-terrain.-ch-Replace-NULL-with-nullptr.patch

Marko Lindqvist, 05/10/2025 04:56 AM

View differences:

common/terrain.c
/* Can't use terrain_by_number here because it does a bounds check. */
civ_terrains[i].item_number = i;
civ_terrains[i].ruledit_disabled = FALSE;
civ_terrains[i].ruledit_dlg = NULL;
civ_terrains[i].rgb = NULL;
civ_terrains[i].animal = NULL;
civ_terrains[i].ruledit_dlg = nullptr;
civ_terrains[i].rgb = nullptr;
civ_terrains[i].animal = nullptr;
for (j = 0; j < MAX_EXTRA_TYPES; j++) {
civ_terrains[i].extra_removal_times[j] = 0;
......
void terrains_free(void)
{
terrain_type_iterate(pterrain) {
if (NULL != pterrain->helptext) {
if (pterrain->helptext != nullptr) {
strvec_destroy(pterrain->helptext);
pterrain->helptext = NULL;
pterrain->helptext = nullptr;
}
if (pterrain->resources != NULL) {
if (pterrain->resources != nullptr) {
/* Server allocates this on ruleset loading, client when
* ruleset packet is received. */
free(pterrain->resources);
pterrain->resources = NULL;
pterrain->resources = nullptr;
}
if (pterrain->resource_freq != NULL) {
if (pterrain->resource_freq != nullptr) {
/* Server allocates this on ruleset loading, client when
* ruleset packet is received. */
free(pterrain->resource_freq);
pterrain->resource_freq = NULL;
pterrain->resource_freq = nullptr;
}
if (pterrain->rgb != NULL) {
if (pterrain->rgb != nullptr) {
/* Server allocates this on ruleset loading, client when
* ruleset packet is received. */
rgbcolor_destroy(pterrain->rgb);
pterrain->rgb = NULL;
pterrain->rgb = nullptr;
}
} terrain_type_iterate_end;
}
......
if (game.control.terrain_count > 0) {
return civ_terrains;
}
return NULL;
return nullptr;
}
/**********************************************************************//**
......
if (game.control.terrain_count > 0) {
return &civ_terrains[game.control.terrain_count - 1];
}
return NULL;
return nullptr;
}
/**********************************************************************//**
......
{
if (type < 0 || type >= game.control.terrain_count) {
/* This isn't an error; some T_UNKNOWN callers depend on it. */
return NULL;
return nullptr;
}
return &civ_terrains[type];
}
......
struct terrain *rand_terrain_by_flag(enum terrain_flag_id flag)
{
int num = 0;
struct terrain *terr = NULL;
struct terrain *terr = nullptr;
terrain_type_iterate(pterr) {
if (terrain_has_flag(pterr, flag)) {
......
{
struct extra_type **r = pterrain->resources;
while (NULL != *r) {
while (*r != nullptr) {
if (*r == presource) {
return TRUE;
}
r++;
}
return FALSE;
}
......
const struct terrain *pterrain,
bool check_self)
{
if (pterrain == NULL) {
if (pterrain == nullptr) {
return FALSE;
}
......
const struct terrain *pterrain,
bool check_self)
{
if (pterrain == NULL) {
if (pterrain == nullptr) {
return FALSE;
}
......
const struct extra_type *pres,
bool check_self)
{
if (pres == NULL) {
if (pres == nullptr) {
return FALSE;
}
......
const struct extra_type *pres,
bool check_self)
{
if (pres == NULL) {
if (pres == nullptr) {
return FALSE;
}
......
/**********************************************************************//**
Returns the highest-priority (best) extra to be pillaged from the
terrain set. May return NULL if nothing is available.
terrain set. May return nullptr if nothing is available.
**************************************************************************/
struct extra_type *get_preferred_pillage(bv_extras extras)
{
......
} extra_type_by_cause_iterate_rev_end;
}
return NULL;
return nullptr;
}
/**********************************************************************//**
......
const char *terrain_class_name_translation(enum terrain_class tclass)
{
if (!terrain_class_is_valid(tclass)) {
return NULL;
return nullptr;
}
return _(terrain_class_name(tclass));
......
{
int factor;
if (tgt != NULL && tgt->build_time != 0) {
if (tgt != nullptr && tgt->build_time != 0) {
/* Extra specific build time */
return tgt->build_time;
}
if (tgt == NULL) {
if (tgt == nullptr) {
factor = 1;
} else {
factor = tgt->build_time_factor;
......
fc_assert_ret(id >= TER_USER_1 && id <= TER_USER_LAST);
if (user_terrain_flags[tfid].name != NULL) {
if (user_terrain_flags[tfid].name != nullptr) {
FC_FREE(user_terrain_flags[tfid].name);
user_terrain_flags[tfid].name = NULL;
user_terrain_flags[tfid].name = nullptr;
}
if (name && name[0] != '\0') {
user_terrain_flags[tfid].name = fc_strdup(name);
}
if (user_terrain_flags[tfid].helptxt != NULL) {
if (user_terrain_flags[tfid].helptxt != nullptr) {
FC_FREE(user_terrain_flags[tfid].helptxt);
user_terrain_flags[tfid].helptxt = NULL;
user_terrain_flags[tfid].helptxt = nullptr;
}
if (helptxt && helptxt[0] != '\0') {
......
const char *terrain_flag_id_name_cb(enum terrain_flag_id flag)
{
if (flag < TER_USER_1 || flag > TER_USER_LAST) {
return NULL;
return nullptr;
}
return user_terrain_flags[flag-TER_USER_1].name;
common/terrain.h
/* === */
#define T_NONE (NULL) /* A special flag meaning no terrain type. */
#define T_UNKNOWN (NULL) /* An unknown terrain. */
#define T_NONE (nullptr) /* A special flag meaning no terrain type. */
#define T_UNKNOWN (nullptr) /* An unknown terrain. */
/* The first terrain value. */
#define T_FIRST 0
......
enum terrain_class tclass;
int movement_cost; /* whole MP, not scaled by SINGLE_MOVE */
int movement_cost; /* Whole MP, not scaled by SINGLE_MOVE */
int defense_bonus; /* % defense bonus - defaults to zero */
int output[O_LAST];
struct extra_type **resources; /* NULL-terminated */
int *resource_freq; /* same length as resources */
struct extra_type **resources; /* nullptr-terminated */
int *resource_freq; /* Same length as resources */
#define RESOURCE_FREQUENCY_MINIMUM (0)
#define RESOURCE_FREQUENCY_DEFAULT (1)
......
const struct unit_type *animal;
/* May be NULL if the transformation is impossible. */
/* May be nullptr if the transformation is impossible. */
struct terrain *warmer_wetter_result, *warmer_drier_result;
struct terrain *cooler_wetter_result, *cooler_drier_result;
......
struct terrain *terrain_array_first(void);
const struct terrain *terrain_array_last(void);
#define terrain_type_iterate(_p) \
{ \
struct terrain *_p = terrain_array_first(); \
if (NULL != _p) { \
#define terrain_type_iterate(_p) \
{ \
struct terrain *_p = terrain_array_first(); \
if (_p != nullptr) { \
for (; _p <= terrain_array_last(); _p++) {
#define terrain_type_iterate_end \
} \
} \
#define terrain_type_iterate_end \
} \
} \
}
#define terrain_re_active_iterate(_p) \
......
} terrain_type_iterate_end;
#define terrain_resources_iterate(pterrain, _res, _freq) \
if (NULL != pterrain && NULL != pterrain->resources) { \
if (pterrain != nullptr && pterrain->resources != nullptr) { \
int _res##_index; \
for (_res##_index = 0; \
pterrain->resources[_res##_index] != NULL; \
pterrain->resources[_res##_index] != nullptr; \
_res##_index++) { \
struct extra_type *_res = pterrain->resources[_res##_index]; \
int _freq = pterrain->resource_freq[_res##_index];
    (1-1/1)