Feature #1735 ยป 0034-improvement.-ch-Replace-NULL-with-nullptr.patch
| common/improvement.c | ||
|---|---|---|
|
requirement_vector_init(&p->reqs);
|
||
|
requirement_vector_init(&p->obsolete_by);
|
||
|
p->ruledit_disabled = FALSE;
|
||
|
p->ruledit_dlg = NULL;
|
||
|
p->ruledit_dlg = nullptr;
|
||
|
}
|
||
|
}
|
||
| ... | ... | |
|
**************************************************************************/
|
||
|
static void improvement_free(struct impr_type *p)
|
||
|
{
|
||
|
if (NULL != p->helptext) {
|
||
|
if (p->helptext != nullptr) {
|
||
|
strvec_destroy(p->helptext);
|
||
|
p->helptext = NULL;
|
||
|
p->helptext = nullptr;
|
||
|
}
|
||
|
requirement_vector_free(&p->reqs);
|
||
| ... | ... | |
|
if (game.control.num_impr_types > 0) {
|
||
|
return improvement_types;
|
||
|
}
|
||
|
return NULL;
|
||
|
return nullptr;
|
||
|
}
|
||
|
/**********************************************************************//**
|
||
| ... | ... | |
|
if (game.control.num_impr_types > 0) {
|
||
|
return &improvement_types[game.control.num_impr_types - 1];
|
||
|
}
|
||
|
return NULL;
|
||
|
return nullptr;
|
||
|
}
|
||
|
/**********************************************************************//**
|
||
| ... | ... | |
|
**************************************************************************/
|
||
|
Impr_type_id improvement_index(const struct impr_type *pimprove)
|
||
|
{
|
||
|
fc_assert_ret_val(NULL != pimprove, -1);
|
||
|
fc_assert_ret_val(pimprove != nullptr, -1);
|
||
|
return pimprove - improvement_types;
|
||
|
}
|
||
| ... | ... | |
|
**************************************************************************/
|
||
|
Impr_type_id improvement_number(const struct impr_type *pimprove)
|
||
|
{
|
||
|
fc_assert_ret_val(NULL != pimprove, -1);
|
||
|
fc_assert_ret_val(pimprove != nullptr, -1);
|
||
|
return pimprove->item_number;
|
||
|
}
|
||
|
/**********************************************************************//**
|
||
|
Returns the improvement type for the given index/ID. Returns NULL for
|
||
|
Returns the improvement type for the given index/ID. Returns nullptr for
|
||
|
an out-of-range index.
|
||
|
**************************************************************************/
|
||
|
struct impr_type *improvement_by_number(const Impr_type_id id)
|
||
|
{
|
||
|
if (id < 0 || id >= improvement_count()) {
|
||
|
return NULL;
|
||
|
return nullptr;
|
||
|
}
|
||
|
return &improvement_types[id];
|
||
|
}
|
||
|
/**********************************************************************//**
|
||
|
Returns pointer when the improvement_type "exists" in this game,
|
||
|
returns NULL otherwise.
|
||
|
returns nullptr otherwise.
|
||
|
An improvement_type doesn't exist for any of:
|
||
|
- the improvement_type has been flagged as removed by setting its
|
||
| ... | ... | |
|
**************************************************************************/
|
||
|
const struct impr_type *valid_improvement(const struct impr_type *pimprove)
|
||
|
{
|
||
|
if (NULL == pimprove) {
|
||
|
return NULL;
|
||
|
if (pimprove == nullptr) {
|
||
|
return nullptr;
|
||
|
}
|
||
|
if (!victory_enabled(VC_SPACERACE)
|
||
| ... | ... | |
|
|| building_has_effect(pimprove, EFT_SS_COMPONENT)
|
||
|
|| building_has_effect(pimprove, EFT_SS_MODULE))) {
|
||
|
/* This assumes that space parts don't have any other effects. */
|
||
|
return NULL;
|
||
|
return nullptr;
|
||
|
}
|
||
|
return pimprove;
|
||
| ... | ... | |
|
/**********************************************************************//**
|
||
|
Returns pointer when the improvement_type "exists" in this game,
|
||
|
returns NULL otherwise.
|
||
|
returns nullptr otherwise.
|
||
|
In addition to valid_improvement(), tests for id is out of range.
|
||
|
**************************************************************************/
|
||
| ... | ... | |
|
/**********************************************************************//**
|
||
|
Returns estimate of the number of shields it takes to build this improvement.
|
||
|
pplayer and ptile can be NULL, but that might reduce quality of the
|
||
|
pplayer and ptile can be nullptr, but that might reduce quality of the
|
||
|
estimate.
|
||
|
**************************************************************************/
|
||
|
int impr_estimate_build_shield_cost(const struct player *pplayer,
|
||
| ... | ... | |
|
{
|
||
|
int base = pimprove->build_cost
|
||
|
* (100 +
|
||
|
get_target_bonus_effects(NULL,
|
||
|
get_target_bonus_effects(nullptr,
|
||
|
&(const struct req_context) {
|
||
|
.player = pplayer,
|
||
|
.building = pimprove,
|
||
|
.tile = ptile,
|
||
|
},
|
||
|
NULL,
|
||
|
nullptr,
|
||
|
EFT_IMPR_BUILD_COST_PCT)) / 100;
|
||
|
return MAX(base * game.info.shieldbox / 100, 1);
|
||
| ... | ... | |
|
/**********************************************************************//**
|
||
|
Does a linear search of improvement_types[].name.translated
|
||
|
Returns NULL when none match.
|
||
|
Returns nullptr when none match.
|
||
|
**************************************************************************/
|
||
|
struct impr_type *improvement_by_translated_name(const char *name)
|
||
|
{
|
||
| ... | ... | |
|
}
|
||
|
} improvement_iterate_end;
|
||
|
return NULL;
|
||
|
return nullptr;
|
||
|
}
|
||
|
/**********************************************************************//**
|
||
|
Does a linear search of improvement_types[].name.vernacular
|
||
|
Returns NULL when none match.
|
||
|
Returns nullptr when none match.
|
||
|
**************************************************************************/
|
||
|
struct impr_type *improvement_by_rule_name(const char *name)
|
||
|
{
|
||
| ... | ... | |
|
}
|
||
|
} improvement_iterate_end;
|
||
|
return NULL;
|
||
|
return nullptr;
|
||
|
}
|
||
|
/**********************************************************************//**
|
||
| ... | ... | |
|
const struct req_context context = {
|
||
|
.player = pplayer,
|
||
|
.city = pcity,
|
||
|
.tile = pcity ? city_tile(pcity) : NULL,
|
||
|
.tile = pcity ? city_tile(pcity) : nullptr,
|
||
|
.building = pimprove,
|
||
|
};
|
||
|
requirement_vector_iterate(&pimprove->obsolete_by, preq) {
|
||
|
if (is_req_active(&context, NULL, preq, RPT_CERTAIN)) {
|
||
|
if (is_req_active(&context, nullptr, preq, RPT_CERTAIN)) {
|
||
|
return TRUE;
|
||
|
}
|
||
|
} requirement_vector_iterate_end;
|
||
| ... | ... | |
|
action_enablers_iterate(enabler) {
|
||
|
if (!requirement_fulfilled_by_improvement(pimprove, &enabler->target_reqs)
|
||
|
&& !is_action_possible_on_city(enabler_get_action_id(enabler),
|
||
|
NULL, pcity)) {
|
||
|
nullptr, pcity)) {
|
||
|
return TRUE;
|
||
|
}
|
||
|
} action_enablers_iterate_end;
|
||
| ... | ... | |
|
requirement_vector_iterate(&pimprove->reqs, preq) {
|
||
|
if (preq->range >= REQ_RANGE_PLAYER
|
||
|
&& !is_req_active(&context, NULL, preq, RPT_CERTAIN)) {
|
||
|
&& !is_req_active(&context, nullptr, preq, RPT_CERTAIN)) {
|
||
|
return FALSE;
|
||
|
}
|
||
|
} requirement_vector_iterate_end;
|
||
| ... | ... | |
|
if (!can_player_build_improvement_direct(p, pimprove)) {
|
||
|
return FALSE;
|
||
|
}
|
||
|
if (improvement_obsolete(p, pimprove, NULL)) {
|
||
|
if (improvement_obsolete(p, pimprove, nullptr)) {
|
||
|
return FALSE;
|
||
|
}
|
||
|
return TRUE;
|
||
|
}
|
||
| ... | ... | |
|
if (!valid_improvement(pimprove)) {
|
||
|
return FALSE;
|
||
|
}
|
||
|
if (improvement_obsolete(p, pimprove, NULL)) {
|
||
|
if (improvement_obsolete(p, pimprove, nullptr)) {
|
||
|
return FALSE;
|
||
|
}
|
||
|
if (is_great_wonder(pimprove) && !great_wonder_is_available(pimprove)) {
|
||
| ... | ... | |
|
* they can never be met). */
|
||
|
requirement_vector_iterate(&pimprove->reqs, preq) {
|
||
|
if (preq->range >= REQ_RANGE_PLAYER
|
||
|
&& is_req_preventing(&context, NULL, preq, RPT_POSSIBLE)) {
|
||
|
&& is_req_preventing(&context, nullptr, preq, RPT_POSSIBLE)) {
|
||
|
return FALSE;
|
||
|
}
|
||
|
} requirement_vector_iterate_end;
|
||
| ... | ... | |
|
struct player *pplayer;
|
||
|
int windex = improvement_number(pimprove);
|
||
|
fc_assert_ret(NULL != pcity);
|
||
|
fc_assert_ret(pcity != nullptr);
|
||
|
fc_assert_ret(is_wonder(pimprove));
|
||
|
pplayer = city_owner(pcity);
|
||
| ... | ... | |
|
struct player *pplayer;
|
||
|
int windex = improvement_number(pimprove);
|
||
|
fc_assert_ret(NULL != pcity);
|
||
|
fc_assert_ret(pcity != nullptr);
|
||
|
fc_assert_ret(is_wonder(pimprove));
|
||
|
pplayer = city_owner(pcity);
|
||
| ... | ... | |
|
bool wonder_is_lost(const struct player *pplayer,
|
||
|
const struct impr_type *pimprove)
|
||
|
{
|
||
|
fc_assert_ret_val(NULL != pplayer, FALSE);
|
||
|
fc_assert_ret_val(pplayer != nullptr, FALSE);
|
||
|
fc_assert_ret_val(is_wonder(pimprove), FALSE);
|
||
|
return pplayer->wonders[improvement_index(pimprove)] == WONDER_LOST;
|
||
| ... | ... | |
|
bool wonder_is_built(const struct player *pplayer,
|
||
|
const struct impr_type *pimprove)
|
||
|
{
|
||
|
fc_assert_ret_val(NULL != pplayer, FALSE);
|
||
|
fc_assert_ret_val(pplayer != nullptr, FALSE);
|
||
|
fc_assert_ret_val(is_wonder(pimprove), FALSE);
|
||
|
return WONDER_BUILT(pplayer->wonders[improvement_index(pimprove)]);
|
||
| ... | ... | |
|
/**********************************************************************//**
|
||
|
Get the world city with this wonder (small or great). This doesn't
|
||
|
always succeed on the client side, and even when it does, it may
|
||
|
return an "invisible" city whose members are unexpectedly NULL;
|
||
|
return an "invisible" city whose members are unexpectedly nullptr;
|
||
|
take care.
|
||
|
**************************************************************************/
|
||
|
struct city *city_from_wonder(const struct player *pplayer,
|
||
| ... | ... | |
|
int city_id;
|
||
|
if (idx < 0) {
|
||
|
return NULL;
|
||
|
return nullptr;
|
||
|
}
|
||
|
city_id = pplayer->wonders[idx];
|
||
|
fc_assert_ret_val(NULL != pplayer, NULL);
|
||
|
fc_assert_ret_val(is_wonder(pimprove), NULL);
|
||
|
fc_assert_ret_val(pplayer != nullptr, nullptr);
|
||
|
fc_assert_ret_val(is_wonder(pimprove), nullptr);
|
||
|
if (!WONDER_BUILT(city_id)) {
|
||
|
return NULL;
|
||
|
return nullptr;
|
||
|
}
|
||
|
#ifdef FREECIV_DEBUG
|
||
| ... | ... | |
|
/* On client side, this info is not always known. */
|
||
|
struct city *pcity = player_city_by_number(pplayer, city_id);
|
||
|
if (NULL == pcity) {
|
||
|
if (pcity == nullptr) {
|
||
|
log_error("Player %s (nb %d) has outdated wonder info for "
|
||
|
"%s (nb %d), it points to city nb %d.",
|
||
|
player_name(pplayer), player_number(pplayer),
|
||
| ... | ... | |
|
player_name(pplayer), player_number(pplayer),
|
||
|
improvement_rule_name(pimprove),
|
||
|
improvement_number(pimprove), city_name_get(pcity), pcity->id);
|
||
|
return NULL;
|
||
|
return nullptr;
|
||
|
}
|
||
|
return pcity;
|
||
| ... | ... | |
|
{
|
||
|
int player_id = game.info.great_wonder_owners[improvement_index(pimprove)];
|
||
|
fc_assert_ret_val(is_great_wonder(pimprove), NULL);
|
||
|
fc_assert_ret_val(is_great_wonder(pimprove), nullptr);
|
||
|
if (WONDER_OWNED(player_id)) {
|
||
|
#ifdef FREECIV_DEBUG
|
||
|
const struct player *pplayer = player_by_number(player_id);
|
||
|
struct city *pcity = city_from_wonder(pplayer, pimprove);
|
||
|
if (is_server() && NULL == pcity) {
|
||
|
if (is_server() && pcity == nullptr) {
|
||
|
log_error("Game has outdated wonder info for %s (nb %d), "
|
||
|
"the player %s (nb %d) doesn't have this wonder.",
|
||
|
improvement_rule_name(pimprove),
|
||
| ... | ... | |
|
return city_from_wonder(player_by_number(player_id), pimprove);
|
||
|
#endif /* FREECIV_DEBUG */
|
||
|
} else {
|
||
|
return NULL;
|
||
|
return nullptr;
|
||
|
}
|
||
|
}
|
||
| ... | ... | |
|
{
|
||
|
int player_id = game.info.great_wonder_owners[improvement_index(pimprove)];
|
||
|
fc_assert_ret_val(is_great_wonder(pimprove), NULL);
|
||
|
fc_assert_ret_val(is_great_wonder(pimprove), nullptr);
|
||
|
if (WONDER_OWNED(player_id)) {
|
||
|
return player_by_number(player_id);
|
||
|
} else {
|
||
|
return NULL;
|
||
|
return nullptr;
|
||
|
}
|
||
|
}
|
||
| ... | ... | |
|
{
|
||
|
fc_assert_ret_val(is_small_wonder(pimprove), FALSE);
|
||
|
return (NULL != pplayer
|
||
|
return (pplayer != nullptr
|
||
|
&& wonder_is_built(pplayer, pimprove));
|
||
|
}
|
||
| ... | ... | |
|
struct city *city_from_small_wonder(const struct player *pplayer,
|
||
|
const struct impr_type *pimprove)
|
||
|
{
|
||
|
fc_assert_ret_val(is_small_wonder(pimprove), NULL);
|
||
|
fc_assert_ret_val(is_small_wonder(pimprove), nullptr);
|
||
|
if (NULL == pplayer) {
|
||
|
return NULL; /* Used in some places in the client. */
|
||
|
if (pplayer == nullptr) {
|
||
|
return nullptr; /* Used in some places in the client. */
|
||
|
} else {
|
||
|
return city_from_wonder(pplayer, pimprove);
|
||
|
}
|
||
| ... | ... | |
|
/**********************************************************************//**
|
||
|
Return TRUE iff the player can sell the given improvement from city.
|
||
|
If pimprove is NULL, returns iff city could sell some building type (this
|
||
|
does not check if such building is in this city)
|
||
|
If pimprove is nullptr, returns iff city could sell some building type
|
||
|
(this does not check if such building is in this city)
|
||
|
**************************************************************************/
|
||
|
enum test_result test_player_sell_building_now(struct player *pplayer,
|
||
|
struct city *pcity,
|
||
| ... | ... | |
|
}
|
||
|
/* Check if particular building can be solt */
|
||
|
if (pimprove != NULL
|
||
|
if (pimprove != nullptr
|
||
|
&& !can_city_sell_building(pcity, pimprove)) {
|
||
|
return TR_OTHER_FAILURE;
|
||
|
}
|
||
| ... | ... | |
|
}
|
||
|
} requirement_vector_iterate_end;
|
||
|
return NULL;
|
||
|
return nullptr;
|
||
|
}
|
||
|
/************************************************************************//**
|
||
| ... | ... | |
|
fc_assert_ret(id >= IF_USER_FLAG_1 && id <= IF_LAST_USER_FLAG);
|
||
|
if (user_impr_flags[bfid].name != NULL) {
|
||
|
if (user_impr_flags[bfid].name != nullptr) {
|
||
|
FC_FREE(user_impr_flags[bfid].name);
|
||
|
user_impr_flags[bfid].name = NULL;
|
||
|
user_impr_flags[bfid].name = nullptr;
|
||
|
}
|
||
|
if (name && name[0] != '\0') {
|
||
|
user_impr_flags[bfid].name = fc_strdup(name);
|
||
|
}
|
||
|
if (user_impr_flags[bfid].helptxt != NULL) {
|
||
|
if (user_impr_flags[bfid].helptxt != nullptr) {
|
||
|
free(user_impr_flags[bfid].helptxt);
|
||
|
user_impr_flags[bfid].helptxt = NULL;
|
||
|
user_impr_flags[bfid].helptxt = nullptr;
|
||
|
}
|
||
|
if (helptxt && helptxt[0] != '\0') {
|
||
| ... | ... | |
|
const char *impr_flag_id_name_cb(enum impr_flag_id flag)
|
||
|
{
|
||
|
if (flag < IF_USER_FLAG_1 || flag > IF_LAST_USER_FLAG) {
|
||
|
return NULL;
|
||
|
return nullptr;
|
||
|
}
|
||
|
return user_impr_flags[flag - IF_USER_FLAG_1].name;
|
||
| common/improvement.h | ||
|---|---|---|
|
*/
|
||
|
#define B_LAST MAX_NUM_BUILDINGS
|
||
|
#define B_NEVER (NULL)
|
||
|
#define B_NEVER (nullptr)
|
||
|
/* Used in the network protocol. */
|
||
|
BV_DEFINE(bv_imprs, B_LAST);
|
||
| ... | ... | |
|
struct city *city_from_small_wonder(const struct player *pplayer,
|
||
|
const struct impr_type *pimprove);
|
||
|
/* player related improvement functions */
|
||
|
/* Player related improvement functions */
|
||
|
bool improvement_obsolete(const struct player *pplayer,
|
||
|
const struct impr_type *pimprove,
|
||
|
const struct impr_type *pimprove,
|
||
|
const struct city *pcity);
|
||
|
bool is_improvement_productive(const struct city *pcity,
|
||
|
const struct impr_type *pimprove);
|
||
| ... | ... | |
|
struct impr_type *improvement_array_first(void);
|
||
|
const struct impr_type *improvement_array_last(void);
|
||
|
#define improvement_iterate(_p) \
|
||
|
{ \
|
||
|
struct impr_type *_p = improvement_array_first(); \
|
||
|
if (NULL != _p) { \
|
||
|
#define improvement_iterate(_p) \
|
||
|
{ \
|
||
|
struct impr_type *_p = improvement_array_first(); \
|
||
|
if (_p != nullptr) { \
|
||
|
for (; _p <= improvement_array_last(); _p++) {
|
||
|
#define improvement_iterate_end \
|
||
|
} \
|
||
|
} \
|
||
|
#define improvement_iterate_end \
|
||
|
} \
|
||
|
} \
|
||
|
}
|
||
|
#define improvement_re_active_iterate(_p) \
|
||