Feature #1810 ยป 0046-effects.-ch-Replace-NULL-with-nullptr.patch
| common/effects.c | ||
|---|---|---|
|
if (value >= 0 && value < government_count()) {
|
||
|
return ruleset_cache.reqs.govs[value];
|
||
|
} else {
|
||
|
return NULL;
|
||
|
return nullptr;
|
||
|
}
|
||
|
case VUT_IMPROVEMENT:
|
||
|
if (value >= 0 && value < improvement_count()) {
|
||
|
return ruleset_cache.reqs.buildings[value];
|
||
|
} else {
|
||
|
return NULL;
|
||
|
return nullptr;
|
||
|
}
|
||
|
case VUT_ADVANCE:
|
||
|
if (value >= 0 && value < advance_count()) {
|
||
|
return ruleset_cache.reqs.advances[value];
|
||
|
} else {
|
||
|
return NULL;
|
||
|
return nullptr;
|
||
|
}
|
||
|
default:
|
||
|
return NULL;
|
||
|
return nullptr;
|
||
|
}
|
||
|
}
|
||
| ... | ... | |
|
/* Only relevant for ruledit and other rulesave users. */
|
||
|
peffect->rulesave.do_not_save = FALSE;
|
||
|
peffect->rulesave.comment = NULL;
|
||
|
peffect->rulesave.comment = nullptr;
|
||
|
return peffect;
|
||
|
}
|
||
| ... | ... | |
|
void effect_free(struct effect *peffect)
|
||
|
{
|
||
|
requirement_vector_free(&peffect->reqs);
|
||
|
if (peffect->rulesave.comment != NULL) {
|
||
|
if (peffect->rulesave.comment != nullptr) {
|
||
|
free(peffect->rulesave.comment);
|
||
|
}
|
||
|
free(peffect);
|
||
| ... | ... | |
|
requirement_vector_append(&peffect->reqs, req);
|
||
|
if (eff_list != NULL) {
|
||
|
if (eff_list != nullptr) {
|
||
|
effect_list_append(eff_list, peffect);
|
||
|
}
|
||
| ... | ... | |
|
.value.building = impr
|
||
|
});
|
||
|
if (eff_list != NULL) {
|
||
|
if (eff_list != nullptr) {
|
||
|
effect_list_append(eff_list, peffect);
|
||
|
}
|
||
|
}
|
||
| ... | ... | |
|
effect_free(peffect);
|
||
|
} effect_list_iterate_end;
|
||
|
effect_list_destroy(tracker_list);
|
||
|
ruleset_cache.tracker = NULL;
|
||
|
ruleset_cache.tracker = nullptr;
|
||
|
}
|
||
|
for (i = 0; i < ARRAY_SIZE(ruleset_cache.effects); i++) {
|
||
| ... | ... | |
|
if (plist) {
|
||
|
effect_list_destroy(plist);
|
||
|
ruleset_cache.effects[i] = NULL;
|
||
|
ruleset_cache.effects[i] = nullptr;
|
||
|
}
|
||
|
}
|
||
| ... | ... | |
|
if (plist) {
|
||
|
effect_list_destroy(plist);
|
||
|
ruleset_cache.reqs.buildings[i] = NULL;
|
||
|
ruleset_cache.reqs.buildings[i] = nullptr;
|
||
|
}
|
||
|
}
|
||
| ... | ... | |
|
if (plist) {
|
||
|
effect_list_destroy(plist);
|
||
|
ruleset_cache.reqs.govs[i] = NULL;
|
||
|
ruleset_cache.reqs.govs[i] = nullptr;
|
||
|
}
|
||
|
}
|
||
| ... | ... | |
|
if (plist) {
|
||
|
effect_list_destroy(plist);
|
||
|
ruleset_cache.reqs.advances[i] = NULL;
|
||
|
ruleset_cache.reqs.advances[i] = nullptr;
|
||
|
}
|
||
|
}
|
||
| ... | ... | |
|
(that is, the sum of all positive effects clauses that apply specifically
|
||
|
to this universal -- this can be an overestimate in the case of
|
||
|
mutually exclusive effects).
|
||
|
for_uni can be NULL to get max effect value ignoring requirements.
|
||
|
for_uni can be nullptr to get max effect value ignoring requirements.
|
||
|
**************************************************************************/
|
||
|
int effect_cumulative_max(enum effect_type type, struct universal *unis,
|
||
|
size_t n_unis)
|
||
| ... | ... | |
|
struct effect_list *plist = ruleset_cache.tracker;
|
||
|
int value = 0;
|
||
|
fc_assert_ret_val(((unis == NULL && n_unis == 0)
|
||
|
|| (unis != NULL && n_unis > 0)),
|
||
|
fc_assert_ret_val(((unis == nullptr && n_unis == 0)
|
||
|
|| (unis != nullptr && n_unis > 0)),
|
||
|
0);
|
||
|
if (plist) {
|
||
|
effect_list_iterate(plist, peffect) {
|
||
|
if (peffect->type == type) {
|
||
|
if (peffect->value > 0) {
|
||
|
if (unis == NULL
|
||
|
if (unis == nullptr
|
||
|
|| !universals_mean_unfulfilled(&(peffect->reqs), unis, n_unis)) {
|
||
|
value += peffect->value;
|
||
|
}
|
||
| ... | ... | |
|
(that is, the sum of all negative effects clauses that apply specifically
|
||
|
to this universal -- this can be an overestimate in the case of
|
||
|
mutually exclusive effects).
|
||
|
for_uni can be NULL to get min effect value ignoring requirements.
|
||
|
for_uni can be nullptr to get min effect value ignoring requirements.
|
||
|
**************************************************************************/
|
||
|
int effect_cumulative_min(enum effect_type type, struct universal *for_uni)
|
||
|
{
|
||
| ... | ... | |
|
effect_list_iterate(plist, peffect) {
|
||
|
if (peffect->type == type) {
|
||
|
if (peffect->value < 0) {
|
||
|
if (for_uni == NULL
|
||
|
if (for_uni == nullptr
|
||
|
|| universal_fulfills_requirements(FALSE, &(peffect->reqs),
|
||
|
for_uni)) {
|
||
|
value += peffect->value;
|
||
| ... | ... | |
|
**************************************************************************/
|
||
|
int effect_value_will_make_positive(enum effect_type type)
|
||
|
{
|
||
|
return 1 + (effect_cumulative_min(type, NULL) * -1);
|
||
|
return 1 + (effect_cumulative_min(type, nullptr) * -1);
|
||
|
}
|
||
|
/**********************************************************************//**
|
||
| ... | ... | |
|
struct multiplier *pmul;
|
||
|
pmul = packet->has_multiplier ? multiplier_by_number(packet->multiplier)
|
||
|
: NULL;
|
||
|
: nullptr;
|
||
|
peffect = effect_new(packet->effect_type, packet->effect_value, pmul);
|
||
|
requirement_vector_iterate(&(packet->reqs), preq) {
|
||
| ... | ... | |
|
(Assumes that any requirement specified in the ruleset with a negative
|
||
|
sense is an impediment.)
|
||
|
context may be NULL. This is equivalent to passing an empty context.
|
||
|
context may be nullptr. This is equivalent to passing an empty context.
|
||
|
**************************************************************************/
|
||
|
static bool is_effect_prevented(const struct req_context *context,
|
||
|
const struct req_context *other_context,
|
||
| ... | ... | |
|
.city = pcity,
|
||
|
.building = pimprove,
|
||
|
},
|
||
|
NULL,
|
||
|
nullptr,
|
||
|
peffect, prob_type)) {
|
||
|
return FALSE;
|
||
|
}
|
||
| ... | ... | |
|
context gives the target (or targets) to evaluate requirements against
|
||
|
effect_type gives the effect type to be considered
|
||
|
context and other_context may be NULL. This is equivalent to passing
|
||
|
context and other_context may be nullptr. This is equivalent to passing
|
||
|
empty contexts.
|
||
|
Returns the effect sources of this type _currently active_.
|
||
| ... | ... | |
|
{
|
||
|
int bonus = 0;
|
||
|
if (context == NULL) {
|
||
|
if (context == nullptr) {
|
||
|
context = req_context_empty();
|
||
|
}
|
||
| ... | ... | |
|
{
|
||
|
double sum = 0.;
|
||
|
if (context == NULL) {
|
||
|
if (context == nullptr) {
|
||
|
context = req_context_empty();
|
||
|
}
|
||
| ... | ... | |
|
return 0;
|
||
|
}
|
||
|
return get_target_bonus_effects(NULL, NULL, NULL, effect_type);
|
||
|
return get_target_bonus_effects(nullptr, nullptr, nullptr, effect_type);
|
||
|
}
|
||
|
/**********************************************************************//**
|
||
| ... | ... | |
|
return 0;
|
||
|
}
|
||
|
return get_target_bonus_effects(NULL,
|
||
|
return get_target_bonus_effects(nullptr,
|
||
|
&(const struct req_context) {
|
||
|
.player = pplayer,
|
||
|
},
|
||
|
NULL,
|
||
|
nullptr,
|
||
|
effect_type);
|
||
|
}
|
||
| ... | ... | |
|
return 0;
|
||
|
}
|
||
|
return get_target_bonus_effects(NULL,
|
||
|
return get_target_bonus_effects(nullptr,
|
||
|
&(const struct req_context) {
|
||
|
.player = city_owner(pcity),
|
||
|
.city = pcity,
|
||
|
.tile = city_tile(pcity),
|
||
|
},
|
||
|
NULL, effect_type);
|
||
|
nullptr, effect_type);
|
||
|
}
|
||
|
/**********************************************************************//**
|
||
| ... | ... | |
|
return 0;
|
||
|
}
|
||
|
return get_target_bonus_effects(NULL,
|
||
|
return get_target_bonus_effects(nullptr,
|
||
|
&(const struct req_context) {
|
||
|
.player = tile_owner(ptile),
|
||
|
.city = tile_city(ptile),
|
||
|
.tile = ptile,
|
||
|
},
|
||
|
NULL,
|
||
|
nullptr,
|
||
|
effect_type);
|
||
|
}
|
||
| ... | ... | |
|
const struct output_type *poutput,
|
||
|
enum effect_type effect_type)
|
||
|
{
|
||
|
fc_assert_ret_val(pcity != NULL, 0);
|
||
|
fc_assert_ret_val(pspecialist != NULL, 0);
|
||
|
fc_assert_ret_val(poutput != NULL, 0);
|
||
|
return get_target_bonus_effects(NULL,
|
||
|
fc_assert_ret_val(pcity != nullptr, 0);
|
||
|
fc_assert_ret_val(pspecialist != nullptr, 0);
|
||
|
fc_assert_ret_val(poutput != nullptr, 0);
|
||
|
return get_target_bonus_effects(nullptr,
|
||
|
&(const struct req_context) {
|
||
|
.player = city_owner(pcity),
|
||
|
.city = pcity,
|
||
|
.output = poutput,
|
||
|
.specialist = pspecialist,
|
||
|
},
|
||
|
NULL,
|
||
|
nullptr,
|
||
|
effect_type);
|
||
|
}
|
||
| ... | ... | |
|
pcity must be supplied.
|
||
|
FIXME: this is now used both for tile bonuses, tile-output bonuses,
|
||
|
and city-output bonuses. Thus ptile or poutput may be NULL for
|
||
|
and city-output bonuses. Thus ptile or poutput may be nullptr for
|
||
|
certain callers. This could be changed by adding 2 new functions to
|
||
|
the interface but they'd be almost identical and their likely names
|
||
|
would conflict with functions already in city.c.
|
||
| ... | ... | |
|
const struct output_type *poutput,
|
||
|
enum effect_type effect_type)
|
||
|
{
|
||
|
fc_assert_ret_val(pcity != NULL, 0);
|
||
|
return get_target_bonus_effects(NULL,
|
||
|
fc_assert_ret_val(pcity != nullptr, 0);
|
||
|
return get_target_bonus_effects(nullptr,
|
||
|
&(const struct req_context) {
|
||
|
.player = city_owner(pcity),
|
||
|
.city = pcity,
|
||
|
.tile = ptile,
|
||
|
.output = poutput,
|
||
|
},
|
||
|
NULL,
|
||
|
nullptr,
|
||
|
effect_type);
|
||
|
}
|
||
|
/**********************************************************************//**
|
||
|
Returns the effect bonus at a tile for given output type (or NULL for
|
||
|
Returns the effect bonus at a tile for given output type (or nullptr for
|
||
|
output-type-independent bonus).
|
||
|
If pcity is supplied, it's the bonus for that particular city, otherwise
|
||
|
it's the player/city-independent bonus (and any city on the tile is
|
||
| ... | ... | |
|
const struct output_type *poutput,
|
||
|
enum effect_type effect_type)
|
||
|
{
|
||
|
const struct player *pplayer = pcity ? city_owner(pcity) : NULL;
|
||
|
const struct player *pplayer = pcity ? city_owner(pcity) : nullptr;
|
||
|
return get_target_bonus_effects(NULL,
|
||
|
return get_target_bonus_effects(nullptr,
|
||
|
&(const struct req_context) {
|
||
|
.player = pplayer,
|
||
|
.city = pcity,
|
||
|
.tile = ptile,
|
||
|
.output = poutput,
|
||
|
},
|
||
|
NULL,
|
||
|
nullptr,
|
||
|
effect_type);
|
||
|
}
|
||
| ... | ... | |
|
return 0;
|
||
|
}
|
||
|
fc_assert_ret_val(pplayer != NULL, 0);
|
||
|
fc_assert_ret_val(poutput != NULL, 0);
|
||
|
fc_assert_ret_val(pplayer != nullptr, 0);
|
||
|
fc_assert_ret_val(poutput != nullptr, 0);
|
||
|
fc_assert_ret_val(effect_type != EFT_COUNT, 0);
|
||
|
return get_target_bonus_effects(NULL,
|
||
|
return get_target_bonus_effects(nullptr,
|
||
|
&(const struct req_context) {
|
||
|
.player = pplayer,
|
||
|
.output= poutput,
|
||
|
},
|
||
|
NULL,
|
||
|
nullptr,
|
||
|
effect_type);
|
||
|
}
|
||
| ... | ... | |
|
return 0;
|
||
|
}
|
||
|
fc_assert_ret_val(pcity != NULL, 0);
|
||
|
fc_assert_ret_val(poutput != NULL, 0);
|
||
|
fc_assert_ret_val(pcity != nullptr, 0);
|
||
|
fc_assert_ret_val(poutput != nullptr, 0);
|
||
|
fc_assert_ret_val(effect_type != EFT_COUNT, 0);
|
||
|
return get_target_bonus_effects(NULL,
|
||
|
return get_target_bonus_effects(nullptr,
|
||
|
&(const struct req_context) {
|
||
|
.player = city_owner(pcity),
|
||
|
.city = pcity,
|
||
|
.output = poutput,
|
||
|
},
|
||
|
NULL,
|
||
|
nullptr,
|
||
|
effect_type);
|
||
|
}
|
||
| ... | ... | |
|
return 0;
|
||
|
}
|
||
|
fc_assert_ret_val(NULL != pcity && NULL != building, 0);
|
||
|
return get_target_bonus_effects(NULL,
|
||
|
fc_assert_ret_val(pcity != nullptr && building != nullptr, 0);
|
||
|
return get_target_bonus_effects(nullptr,
|
||
|
&(const struct req_context) {
|
||
|
.player = city_owner(pcity),
|
||
|
.city = pcity,
|
||
|
.building = building,
|
||
|
},
|
||
|
NULL,
|
||
|
nullptr,
|
||
|
effect_type);
|
||
|
}
|
||
| ... | ... | |
|
return 0;
|
||
|
}
|
||
|
fc_assert_ret_val(punit != NULL, 0);
|
||
|
return get_target_bonus_effects(NULL,
|
||
|
fc_assert_ret_val(punit != nullptr, 0);
|
||
|
return get_target_bonus_effects(nullptr,
|
||
|
&(const struct req_context) {
|
||
|
.player = unit_owner(punit),
|
||
|
.city = unit_tile(punit)
|
||
|
? tile_city(unit_tile(punit))
|
||
|
: NULL,
|
||
|
: nullptr,
|
||
|
.tile = unit_tile(punit),
|
||
|
.unit = punit,
|
||
|
.unittype = unit_type_get(punit),
|
||
|
},
|
||
|
NULL,
|
||
|
nullptr,
|
||
|
effect_type);
|
||
|
}
|
||
| ... | ... | |
|
const struct unit *punit,
|
||
|
enum effect_type etype)
|
||
|
{
|
||
|
struct player *pplayer = NULL;
|
||
|
const struct unit_type *utype = NULL;
|
||
|
struct player *pplayer = nullptr;
|
||
|
const struct unit_type *utype = nullptr;
|
||
|
if (!initialized) {
|
||
|
return 0;
|
||
|
}
|
||
|
fc_assert_ret_val(ptile != NULL, 0);
|
||
|
fc_assert_ret_val(ptile != nullptr, 0);
|
||
|
if (punit != NULL) {
|
||
|
if (punit != nullptr) {
|
||
|
pplayer = unit_owner(punit);
|
||
|
utype = unit_type_get(punit);
|
||
|
}
|
||
|
return get_target_bonus_effects(NULL,
|
||
|
return get_target_bonus_effects(nullptr,
|
||
|
&(const struct req_context) {
|
||
|
.player = pplayer,
|
||
|
.city = tile_city(ptile),
|
||
| ... | ... | |
|
return 0;
|
||
|
}
|
||
|
fc_assert_ret_val(pplayer != NULL, 0);
|
||
|
fc_assert_ret_val(pplayer != nullptr, 0);
|
||
|
return get_target_bonus_effects(plist,
|
||
|
&(const struct req_context) {
|
||
|
.player = pplayer,
|
||
|
},
|
||
|
NULL,
|
||
|
nullptr,
|
||
|
effect_type);
|
||
|
}
|
||
| ... | ... | |
|
return 0;
|
||
|
}
|
||
|
fc_assert_ret_val(pcity != NULL, 0);
|
||
|
fc_assert_ret_val(pcity != nullptr, 0);
|
||
|
return get_target_bonus_effects(plist,
|
||
|
&(const struct req_context) {
|
||
|
.player = city_owner(pcity),
|
||
|
.city = pcity,
|
||
|
.output = poutput,
|
||
|
},
|
||
|
NULL,
|
||
|
nullptr,
|
||
|
effect_type);
|
||
|
}
|
||
| ... | ... | |
|
struct universal source = { .kind = VUT_IMPROVEMENT,
|
||
|
.value = {.building = pimprove}};
|
||
|
struct effect_list *plist = get_req_source_effects(&source);
|
||
|
struct player *owner = NULL;
|
||
|
struct player *owner = nullptr;
|
||
|
if (pcity != NULL) {
|
||
|
if (pcity != nullptr) {
|
||
|
owner = city_owner(pcity);
|
||
|
}
|
||
| ... | ... | |
|
continue;
|
||
|
}
|
||
|
if (!is_req_active(&context, NULL, preq, prob_type)) {
|
||
|
if (!is_req_active(&context, nullptr, preq, prob_type)) {
|
||
|
useful = FALSE;
|
||
|
break;
|
||
|
}
|
||
| ... | ... | |
|
**************************************************************************/
|
||
|
bool iterate_effect_cache(iec_cb cb, void *data)
|
||
|
{
|
||
|
fc_assert_ret_val(cb != NULL, FALSE);
|
||
|
fc_assert_ret_val(cb != nullptr, FALSE);
|
||
|
effect_list_iterate(ruleset_cache.tracker, peffect) {
|
||
|
if (!cb(peffect, data)) {
|
||
| common/effects.h | ||
|---|---|---|
|
#define USER_EFFECT_NUMBER(eff) (eff - EFT_USER_EFFECT_1)
|
||
|
/* An effect is provided by a source. If the source is present, and the
|
||
|
/* An effect is provided by a source. If the source is present, and the
|
||
|
* other conditions (described below) are met, the effect will be active.
|
||
|
* Note the difference between effect and effect_type. */
|
||
|
struct effect {
|
||
|
enum effect_type type;
|
||
|
/* Pointer to multipliers (NULL means that this effect has no multiplier */
|
||
|
/* Pointer to multipliers (nullptr means that this effect has no multiplier) */
|
||
|
struct multiplier *multiplier;
|
||
|
/* The "value" of the effect. The meaning of this varies between
|
||
|
* effects. When get_xxx_bonus() is called the value of all applicable
|
||
|
/* The "value" of the effect. The meaning of this varies between
|
||
|
* effects. When get_xxx_bonus() is called the value of all applicable
|
||
|
* effects will be summed up. */
|
||
|
int value;
|
||
|
/* An effect can have multiple requirements. The effect will only be
|
||
|
/* An effect can have multiple requirements. The effect will only be
|
||
|
* active if all of these requirement are met. */
|
||
|
struct requirement_vector reqs;
|
||
| ... | ... | |
|
}
|
||
|
#endif /* __cplusplus */
|
||
|
#endif /* FC__EFFECTS_H */
|
||
|
#endif /* FC__EFFECTS_H */
|
||