Feature #1726 ยป 0027-extras.-ch-Replace-NULL-with-nullptr.patch
| common/extras.c | ||
|---|---|---|
|
requirement_vector_init(&(extras[i].appearance_reqs));
|
||
|
requirement_vector_init(&(extras[i].disappearance_reqs));
|
||
|
extras[i].id = i;
|
||
|
extras[i].hiders = NULL;
|
||
|
extras[i].bridged = NULL;
|
||
|
extras[i].hiders = nullptr;
|
||
|
extras[i].bridged = nullptr;
|
||
|
extras[i].data.special_idx = -1;
|
||
|
extras[i].data.base = NULL;
|
||
|
extras[i].data.road = NULL;
|
||
|
extras[i].data.resource = NULL;
|
||
|
extras[i].data.base = nullptr;
|
||
|
extras[i].data.road = nullptr;
|
||
|
extras[i].data.resource = nullptr;
|
||
|
extras[i].causes = 0;
|
||
|
extras[i].rmcauses = 0;
|
||
|
extras[i].helptext = NULL;
|
||
|
extras[i].helptext = nullptr;
|
||
|
extras[i].ruledit_disabled = FALSE;
|
||
|
extras[i].ruledit_dlg = NULL;
|
||
|
extras[i].ruledit_dlg = nullptr;
|
||
|
extras[i].visibility_req = A_NONE;
|
||
|
}
|
||
|
}
|
||
| ... | ... | |
|
resource_types_free();
|
||
|
for (i = 0; i < game.control.num_extra_types; i++) {
|
||
|
if (extras[i].data.base != NULL) {
|
||
|
if (extras[i].data.base != nullptr) {
|
||
|
FC_FREE(extras[i].data.base);
|
||
|
extras[i].data.base = NULL;
|
||
|
extras[i].data.base = nullptr;
|
||
|
}
|
||
|
if (extras[i].data.road != NULL) {
|
||
|
if (extras[i].data.road != nullptr) {
|
||
|
FC_FREE(extras[i].data.road);
|
||
|
extras[i].data.road = NULL;
|
||
|
extras[i].data.road = nullptr;
|
||
|
}
|
||
|
if (extras[i].data.resource != NULL) {
|
||
|
if (extras[i].data.resource != nullptr) {
|
||
|
FC_FREE(extras[i].data.resource);
|
||
|
extras[i].data.resource = NULL;
|
||
|
extras[i].data.resource = nullptr;
|
||
|
}
|
||
|
}
|
||
|
for (i = 0; i < EC_LAST; i++) {
|
||
|
extra_type_list_destroy(caused_by[i]);
|
||
|
caused_by[i] = NULL;
|
||
|
caused_by[i] = nullptr;
|
||
|
}
|
||
|
for (i = 0; i < ERM_COUNT; i++) {
|
||
|
extra_type_list_destroy(removed_by[i]);
|
||
|
removed_by[i] = NULL;
|
||
|
removed_by[i] = nullptr;
|
||
|
}
|
||
|
extra_type_list_destroy(cleanable);
|
||
|
cleanable = NULL;
|
||
|
cleanable = nullptr;
|
||
|
extra_type_list_destroy(unit_hidden);
|
||
|
unit_hidden = NULL;
|
||
|
unit_hidden = nullptr;
|
||
|
extra_type_list_destroy(zoccers);
|
||
|
zoccers = NULL;
|
||
|
zoccers = nullptr;
|
||
|
extra_type_list_destroy(terr_claimer);
|
||
|
terr_claimer = NULL;
|
||
|
terr_claimer = nullptr;
|
||
|
for (i = 0; i < MAX_EXTRA_TYPES; i++) {
|
||
|
requirement_vector_free(&(extras[i].reqs));
|
||
| ... | ... | |
|
requirement_vector_free(&(extras[i].appearance_reqs));
|
||
|
requirement_vector_free(&(extras[i].disappearance_reqs));
|
||
|
if (NULL != extras[i].helptext) {
|
||
|
if (extras[i].helptext != nullptr) {
|
||
|
strvec_destroy(extras[i].helptext);
|
||
|
extras[i].helptext = NULL;
|
||
|
extras[i].helptext = nullptr;
|
||
|
}
|
||
|
}
|
||
|
extra_type_iterate(pextra) {
|
||
|
if (pextra->hiders != NULL) {
|
||
|
if (pextra->hiders != nullptr) {
|
||
|
extra_type_list_destroy(pextra->hiders);
|
||
|
pextra->hiders = NULL;
|
||
|
pextra->hiders = nullptr;
|
||
|
}
|
||
|
if (pextra->bridged != NULL) {
|
||
|
if (pextra->bridged != nullptr) {
|
||
|
extra_type_list_destroy(pextra->bridged);
|
||
|
pextra->bridged = NULL;
|
||
|
pextra->bridged = nullptr;
|
||
|
}
|
||
|
} extra_type_iterate_end;
|
||
|
}
|
||
| ... | ... | |
|
****************************************************************************/
|
||
|
int extra_number(const struct extra_type *pextra)
|
||
|
{
|
||
|
fc_assert_ret_val(NULL != pextra, -1);
|
||
|
fc_assert_ret_val(pextra != nullptr, -1);
|
||
|
return pextra->id;
|
||
|
}
|
||
| ... | ... | |
|
****************************************************************************/
|
||
|
int extra_index(const struct extra_type *pextra)
|
||
|
{
|
||
|
fc_assert_ret_val(NULL != pextra, -1);
|
||
|
fc_assert_ret_val(pextra != nullptr, -1);
|
||
|
return pextra - extras;
|
||
|
}
|
||
| ... | ... | |
|
****************************************************************************/
|
||
|
struct extra_type *extra_by_number(int id)
|
||
|
{
|
||
|
fc_assert_ret_val(id >= 0 && id < MAX_EXTRA_TYPES, NULL);
|
||
|
fc_assert_ret_val(id >= 0 && id < MAX_EXTRA_TYPES, nullptr);
|
||
|
return &extras[id];
|
||
|
}
|
||
| ... | ... | |
|
}
|
||
|
/************************************************************************//**
|
||
|
Returns extra type matching rule name or NULL if there is no extra type
|
||
|
Returns extra type matching rule name or nullptr if there is no extra type
|
||
|
with such name.
|
||
|
****************************************************************************/
|
||
|
struct extra_type *extra_type_by_rule_name(const char *name)
|
||
|
{
|
||
|
const char *qs;
|
||
|
if (name == NULL) {
|
||
|
return NULL;
|
||
|
if (name == nullptr) {
|
||
|
return nullptr;
|
||
|
}
|
||
|
qs = Qn_(name);
|
||
| ... | ... | |
|
}
|
||
|
} extra_type_iterate_end;
|
||
|
return NULL;
|
||
|
return nullptr;
|
||
|
}
|
||
|
/************************************************************************//**
|
||
|
Returns extra type matching the translated name, or NULL if there is no
|
||
|
Returns extra type matching the translated name, or nullptr if there is no
|
||
|
extra type with that name.
|
||
|
****************************************************************************/
|
||
|
struct extra_type *extra_type_by_translated_name(const char *name)
|
||
| ... | ... | |
|
}
|
||
|
} extra_type_iterate_end;
|
||
|
return NULL;
|
||
|
return nullptr;
|
||
|
}
|
||
|
/************************************************************************//**
|
||
| ... | ... | |
|
struct extra_type_list *full_list = extra_type_list_by_cause(cause);
|
||
|
struct extra_type_list *potential = extra_type_list_new();
|
||
|
int options;
|
||
|
struct extra_type *selected = NULL;
|
||
|
struct extra_type *selected = nullptr;
|
||
|
extra_type_list_iterate(full_list, pextra) {
|
||
|
if ((!generated || pextra->generated)
|
||
| ... | ... | |
|
if (pterr->base_time == 0) {
|
||
|
return FALSE;
|
||
|
}
|
||
|
if (tile_city(ptile) != NULL && extra_base_get(pextra)->border_sq >= 0) {
|
||
|
if (tile_city(ptile) != nullptr && extra_base_get(pextra)->border_sq >= 0) {
|
||
|
return FALSE;
|
||
|
}
|
||
|
}
|
||
| ... | ... | |
|
return FALSE;
|
||
|
}
|
||
|
if (pplayer != NULL && !player_knows_techs_with_flag(pplayer, TF_BRIDGE)) {
|
||
|
if (pplayer != nullptr && !player_knows_techs_with_flag(pplayer, TF_BRIDGE)) {
|
||
|
/* Player does not know technology to bridge over extras that require it. */
|
||
|
extra_type_list_iterate(pextra->bridged, pbridged) {
|
||
|
if (tile_has_extra(ptile, pbridged)) {
|
||
| ... | ... | |
|
return FALSE;
|
||
|
}
|
||
|
if (ptile->placing != NULL) {
|
||
|
if (ptile->placing != nullptr) {
|
||
|
/* Already placing something */
|
||
|
return FALSE;
|
||
|
}
|
||
| ... | ... | |
|
} else {
|
||
|
struct city *pcity = tile_worked(ptile);
|
||
|
if (pcity == NULL || city_owner(pcity) != pplayer) {
|
||
|
if (pcity == nullptr || city_owner(pcity) != pplayer) {
|
||
|
return FALSE;
|
||
|
}
|
||
|
}
|
||
| ... | ... | |
|
struct city *pcity = tile_city(ptile);
|
||
|
/* Cannot remove EF_ALWAYS_ON_CITY_CENTER extras from city center. */
|
||
|
if (pcity != NULL) {
|
||
|
if (pcity != nullptr) {
|
||
|
if (extra_has_flag(pextra, EF_ALWAYS_ON_CITY_CENTER)) {
|
||
|
return FALSE;
|
||
|
}
|
||
| ... | ... | |
|
if (pterr->base_time == 0) {
|
||
|
return FALSE;
|
||
|
}
|
||
|
if (tile_city(ptile) != NULL && extra_base_get(pextra)->border_sq >= 0) {
|
||
|
if (tile_city(ptile) != nullptr && extra_base_get(pextra)->border_sq >= 0) {
|
||
|
return FALSE;
|
||
|
}
|
||
|
}
|
||
| ... | ... | |
|
}
|
||
|
return are_reqs_active(&(const struct req_context) { .tile = ptile },
|
||
|
NULL, &pextra->reqs, RPT_POSSIBLE);
|
||
|
nullptr, &pextra->reqs, RPT_POSSIBLE);
|
||
|
}
|
||
|
/************************************************************************//**
|
||
| ... | ... | |
|
{
|
||
|
extra_type_by_cause_iterate(cause, pextra) {
|
||
|
if (!tile_has_extra(ptile, pextra)) {
|
||
|
if (punit != NULL) {
|
||
|
if (punit != nullptr) {
|
||
|
if (can_build_extra(pextra, punit, ptile)) {
|
||
|
return pextra;
|
||
|
}
|
||
|
} else {
|
||
|
/* punit is certainly NULL, pplayer can be too */
|
||
|
/* punit is certainly nullptr, pplayer can be too */
|
||
|
if (player_can_build_extra(pextra, pplayer, ptile)) {
|
||
|
return pextra;
|
||
|
}
|
||
| ... | ... | |
|
}
|
||
|
} extra_type_by_cause_iterate_end;
|
||
|
return NULL;
|
||
|
return nullptr;
|
||
|
}
|
||
|
/************************************************************************//**
|
||
| ... | ... | |
|
const struct player *pplayer,
|
||
|
const struct unit *punit)
|
||
|
{
|
||
|
fc_assert(punit != NULL || pplayer != NULL);
|
||
|
fc_assert(punit != nullptr || pplayer != nullptr);
|
||
|
extra_type_by_rmcause_iterate(rmcause, pextra) {
|
||
|
if (tile_has_extra(ptile, pextra)) {
|
||
|
if (punit != NULL) {
|
||
|
if (punit != nullptr) {
|
||
|
if (can_remove_extra(pextra, punit, ptile)) {
|
||
|
return pextra;
|
||
|
}
|
||
| ... | ... | |
|
}
|
||
|
} extra_type_by_rmcause_iterate_end;
|
||
|
return NULL;
|
||
|
return nullptr;
|
||
|
}
|
||
|
/************************************************************************//**
|
||
| ... | ... | |
|
const struct player *pplayer,
|
||
|
const struct unit *punit)
|
||
|
{
|
||
|
fc_assert(punit != NULL || pplayer != NULL);
|
||
|
fc_assert(punit != nullptr || pplayer != nullptr);
|
||
|
extra_type_cleanable_iterate(pextra) {
|
||
|
if (tile_has_extra(ptile, pextra)) {
|
||
|
if (punit != NULL) {
|
||
|
if (punit != nullptr) {
|
||
|
if (can_remove_extra(pextra, punit, ptile)) {
|
||
|
return pextra;
|
||
|
}
|
||
| ... | ... | |
|
}
|
||
|
} extra_type_cleanable_iterate_end;
|
||
|
return NULL;
|
||
|
return nullptr;
|
||
|
}
|
||
|
/************************************************************************//**
|
||
| ... | ... | |
|
fc_assert_ret(id >= EF_USER_FLAG_1 && id <= EF_LAST_USER_FLAG);
|
||
|
if (user_extra_flags[efid].name != NULL) {
|
||
|
if (user_extra_flags[efid].name != nullptr) {
|
||
|
FC_FREE(user_extra_flags[efid].name);
|
||
|
user_extra_flags[efid].name = NULL;
|
||
|
user_extra_flags[efid].name = nullptr;
|
||
|
}
|
||
|
if (name && name[0] != '\0') {
|
||
|
user_extra_flags[efid].name = fc_strdup(name);
|
||
|
}
|
||
|
if (user_extra_flags[efid].helptxt != NULL) {
|
||
|
if (user_extra_flags[efid].helptxt != nullptr) {
|
||
|
free(user_extra_flags[efid].helptxt);
|
||
|
user_extra_flags[efid].helptxt = NULL;
|
||
|
user_extra_flags[efid].helptxt = nullptr;
|
||
|
}
|
||
|
if (helptxt && helptxt[0] != '\0') {
|
||
| ... | ... | |
|
const char *extra_flag_id_name_cb(enum extra_flag_id flag)
|
||
|
{
|
||
|
if (flag < EF_USER_FLAG_1 || flag > EF_LAST_USER_FLAG) {
|
||
|
return NULL;
|
||
|
return nullptr;
|
||
|
}
|
||
|
return user_extra_flags[flag - EF_USER_FLAG_1].name;
|
||
| common/extras.h | ||
|---|---|---|
|
struct player *extra_owner(const struct tile *ptile);
|
||
|
bool player_knows_extra_exist(const struct player *pplayer,
|
||
|
const struct extra_type *pextra,
|
||
|
const struct tile *ptile);
|
||
|
const struct extra_type *pextra,
|
||
|
const struct tile *ptile);
|
||
|
#define extra_type_iterate(_p) \
|
||
|
{ \
|
||
| ... | ... | |
|
#define extra_type_by_cause_iterate(_cause, _extra) \
|
||
|
{ \
|
||
|
struct extra_type_list *_etl_##_extra = extra_type_list_by_cause(_cause); \
|
||
|
if (_etl_##_extra != NULL) { \
|
||
|
if (_etl_##_extra != nullptr) { \
|
||
|
extra_type_list_iterate(_etl_##_extra, _extra) {
|
||
|
#define extra_type_by_cause_iterate_end \
|
||