Project

General

Profile

Feature #1859 ยป 0043-city.-ch-Replace-NULL-with-nullptr.patch

Marko Lindqvist, 01/03/2026 03:41 AM

View differences:

common/city.c
#endif /* FREECIV_DEBUG */
/* Get city tile information using the city tile index. */
static struct iter_index *city_map_index = NULL;
static struct iter_index *city_map_index = nullptr;
/* Get city tile information using the city tile coordinates. This is an
* [x][y] array of integer values corresponding to city_map_index. The
* coordinates x and y are in the range [0, CITY_MAP_MAX_SIZE] */
......
int *min_dist)
fc__attribute((nonnull (1, 2)));
struct citystyle *city_styles = NULL;
struct citystyle *city_styles = nullptr;
/* One day these values may be read in from the ruleset. In the meantime
* they're just an easy way to access information about each output type. */
......
**************************************************************************/
int city_map_radius_sq_get(const struct city *pcity)
{
/* a save return value is only the minimal squared radius */
fc_assert_ret_val(pcity != NULL, CITY_MAP_MIN_RADIUS_SQ);
/* A safe return value is only the minimal squared radius */
fc_assert_ret_val(pcity != nullptr, CITY_MAP_MIN_RADIUS_SQ);
return pcity->city_radius_sq;
}
......
int rs_max_city_radius_sq(void)
{
int max_rad = game.info.init_city_radius_sq
+ effect_cumulative_max(EFT_CITY_RADIUS_SQ, NULL, 0);
+ effect_cumulative_max(EFT_CITY_RADIUS_SQ, nullptr, 0);
return MIN(max_rad, CITY_MAP_MAX_RADIUS_SQ);
}
......
int tile_x, tile_y;
fc_assert_ret_val(is_valid_city_coords(city_radius_sq, city_map_x,
city_map_y), NULL);
city_map_y), nullptr);
index_to_map_pos(&tile_x, &tile_y, tile_index(city_center));
tile_x += CITY_ABS2REL(city_map_x);
......
int x, mindex;
static char citylog[128], tmp[8];
fc_assert_ret_val(city_map_data != NULL, NULL);
fc_assert_ret_val(city_map_data != nullptr, nullptr);
/* print y coordinates (absolute) */
fc_snprintf(citylog, sizeof(citylog), "%2d ", y);
......
**************************************************************************/
void citylog_map_workers(enum log_level level, struct city *pcity)
{
int *city_map_data = NULL;
int *city_map_data = nullptr;
const struct civ_map *nmap = &(wld.map);
fc_assert_ret(pcity != NULL);
fc_assert_ret(pcity != nullptr);
if (!log_do_output_for_level(level)) {
return;
......
**************************************************************************/
static void citylog_map_index(enum log_level level)
{
int *city_map_data = NULL;
int *city_map_data = nullptr;
if (!log_do_output_for_level(level)) {
return;
......
**************************************************************************/
static void citylog_map_radius_sq(enum log_level level)
{
int *city_map_data = NULL;
int *city_map_data = nullptr;
if (!log_do_output_for_level(level)) {
return;
......
}
}
fc_assert(NULL == city_map_index);
fc_assert(city_map_index == nullptr);
city_map_index = fc_malloc(city_count_tiles * sizeof(*city_map_index));
/* copy the index numbers from city_map_index_tmp into city_map_index */
/* Copy the index numbers from city_map_index_tmp into city_map_index */
for (i = 0; i < city_count_tiles; i++) {
city_map_index[i] = city_map_index_tmp[i];
}
......
qsort(city_map_index, city_count_tiles, sizeof(*city_map_index),
compare_iter_index);
/* set the static variable city_map_xy */
/* Set the static variable city_map_xy */
for (i = 0; i < city_count_tiles; i++) {
city_x = CITY_REL2ABS(city_map_index[i].dx);
city_y = CITY_REL2ABS(city_map_index[i].dy);
......
**************************************************************************/
const char *get_output_identifier(Output_type_id output)
{
fc_assert_ret_val(output >= 0 && output < O_LAST, NULL);
fc_assert_ret_val(output >= 0 && output < O_LAST, nullptr);
return output_types[output].id;
}
......
**************************************************************************/
const char *get_output_name(Output_type_id output)
{
fc_assert_ret_val(output >= 0 && output < O_LAST, NULL);
fc_assert_ret_val(output >= 0 && output < O_LAST, nullptr);
return _(output_types[output].name);
}
......
**************************************************************************/
struct output_type *get_output_type(Output_type_id output)
{
fc_assert_ret_val(output >= 0 && output < O_LAST, NULL);
fc_assert_ret_val(output >= 0 && output < O_LAST, nullptr);
return &output_types[output];
}
......
Return the extended name of the building.
**************************************************************************/
const char *city_improvement_name_translation(const struct city *pcity,
const struct impr_type *pimprove)
const struct impr_type *pimprove)
{
static char buffer[256];
const char *state = NULL;
const char *state = nullptr;
if (is_great_wonder(pimprove)) {
if (great_wonder_is_available(pimprove)) {
......
Return TRUE when the current production has this flag.
**************************************************************************/
bool city_production_has_flag(const struct city *pcity,
enum impr_flag_id flag)
enum impr_flag_id flag)
{
return VUT_IMPROVEMENT == pcity->production.kind
&& improvement_has_flag(pcity->production.value.building, flag);
......
int shields_left = pcity->shield_stock;
int unit_shield_cost, i;
fc_assert_ret_val(num_units != NULL, FALSE);
fc_assert_ret_val(num_units != nullptr, FALSE);
(*num_units) = 0;
if (pcity->production.kind != VUT_UTYPE) {
/* not a unit as the current production */
/* Not a unit as the current production */
return FALSE;
}
utype = pcity->production.value.utype;
if (utype_pop_value(utype, pcity) != 0 || utype_has_flag(utype, UTYF_UNIQUE)) {
/* unit with population cost or unique unit means that only one unit can
/* Unit with population cost or unique unit means that only one unit can
* be build */
(*num_units)++;
return FALSE;
......
shields_left += pcity->prod[O_SHIELD];
}
unit_shield_cost = utype_build_shield_cost(pcity, NULL, utype);
unit_shield_cost = utype_build_shield_cost(pcity, nullptr, utype);
for (i = 0; i < build_slots; i++) {
if (shields_left < unit_shield_cost) {
/* not enough shields */
/* Not enough shields */
break;
}
......
(void) worklist_peek_ith(&pcity->worklist, &target, i);
if (target.kind != VUT_UTYPE
|| utype_index(target.value.utype) != utype_index(utype)) {
/* stop if there is a build target in the worklist not equal to the
/* Stop if there is a build target in the worklist not equal to the
* unit we build */
break;
}
......
const struct unit_type *punittype)
{
int levels = get_unittype_bonus(city_owner(pcity), pcity->tile, punittype,
NULL, EFT_VETERAN_BUILD);
nullptr, EFT_VETERAN_BUILD);
int max_levels = utype_veteran_levels(punittype) - 1;
levels = CLIP(0, levels, max_levels);
......
.city = pcity,
.tile = pcity->tile,
},
NULL,
nullptr,
&(pimprove->reqs), RPT_CERTAIN);
}
......
/* Check for requirements that aren't met and that are unchanging (so
* they can never be met). */
requirement_vector_iterate(&pimprove->reqs, preq) {
if (is_req_preventing(&city_ctxt, NULL, preq, RPT_POSSIBLE)) {
if (is_req_preventing(&city_ctxt, nullptr, preq, RPT_POSSIBLE)) {
return FALSE;
}
} requirement_vector_iterate_end;
......
.tile = city_tile(pcity),
.unittype = punittype,
},
NULL,
nullptr,
&punittype->build_reqs, RPT_CERTAIN)) {
return FALSE;
}
......
**************************************************************************/
bool can_city_build_unit_later(const struct civ_map *nmap,
const struct city *pcity,
const struct unit_type *punittype)
const struct unit_type *punittype)
{
/* Can the _player_ ever build this unit? */
if (!can_player_build_unit_later(city_owner(pcity), punittype)) {
......
.player = city_owner(pcity),
.city = pcity,
},
NULL,
nullptr,
&specialist_by_number(type)->reqs, RPT_POSSIBLE);
}
......
**************************************************************************/
void city_choose_build_default(const struct civ_map *nmap, struct city *pcity)
{
if (NULL == city_tile(pcity)) {
if (city_tile(pcity) == nullptr) {
/* When a "dummy" city is created with no tile, then choosing a build
* target could fail. This currently might happen during map editing.
* FIXME: assumes the first unit is always "valid", so check for
......
**************************************************************************/
const char *city_name_get(const struct city *pcity)
{
return (pcity->name != NULL) ? pcity->name : "City missing a name";
return (pcity->name != nullptr) ? pcity->name : "City missing a name";
}
/**********************************************************************//**
......
**************************************************************************/
void city_name_set(struct city *pcity, const char *new_name)
{
if (pcity->name != NULL) {
if (pcity->name != nullptr) {
free(pcity->name);
}
......
{
citizens size = city_size_get(pcity);
fc_assert_ret(pcity != NULL);
fc_assert_ret(pcity != nullptr);
fc_assert_ret(MAX_CITY_SIZE - size >= add);
/* Client sets size to zero to start stacking citizens in */
......
**************************************************************************/
void city_size_set(struct city *pcity, citizens size)
{
fc_assert_ret(pcity != NULL);
fc_assert_ret(pcity != nullptr);
/* Set city size. */
pcity->size = size;
......
{
int gold_needed = 0;
if (pcity == NULL) {
if (pcity == nullptr) {
return 0;
}
......
{
int gold_needed = 0;
if (pcity == NULL || pcity->units_supported == NULL) {
if (pcity == nullptr || pcity->units_supported == nullptr) {
return 0;
}
......
bool city_has_building(const struct city *pcity,
const struct impr_type *pimprove)
{
if (NULL == pimprove) {
if (pimprove == nullptr) {
/* Callers should ensure that any external data is tested with
* valid_improvement_by_number() */
return FALSE;
}
return (pcity->built[improvement_index(pimprove)].turn > I_NEVER);
}
......
{
int upkeep;
if (NULL == b) {
if (b == nullptr) {
return 0;
}
if (!is_building_sellable(b)) {
......
/**********************************************************************//**
Calculate the output for the tile.
pcity may be NULL.
pcity may be nullptr.
is_celebrating may be speculative.
otype is the output type (generally O_FOOD, O_TRADE, or O_SHIELD).
......
{
int prod;
const struct req_context city_ctxt = {
.player = pcity ? city_owner(pcity) : NULL,
.player = pcity ? city_owner(pcity) : nullptr,
.city = pcity,
.tile = ptile,
};
......
fc_assert_ret_val(otype >= 0 && otype < O_LAST, 0);
if (T_UNKNOWN == pterrain) {
/* Special case for the client. The server doesn't allow unknown tiles
/* Special case for the client. The server doesn't allow unknown tiles
* to be worked but we don't necessarily know what player is involved. */
return 0;
}
......
case O_SHIELD:
if (pterrain->mining_shield_incr != 0) {
prod += pterrain->mining_shield_incr
* get_target_bonus_effects(NULL, &city_ctxt, NULL, EFT_MINING_PCT)
* get_target_bonus_effects(nullptr, &city_ctxt, nullptr, EFT_MINING_PCT)
/ 100;
}
break;
case O_FOOD:
if (pterrain->irrigation_food_incr != 0) {
prod += pterrain->irrigation_food_incr
* get_target_bonus_effects(NULL, &city_ctxt, NULL,
* get_target_bonus_effects(nullptr, &city_ctxt, nullptr,
EFT_IRRIGATION_PCT) / 100;
}
break;
......
EFT_OUTPUT_TILE_PUNISH_PCT))
/ 100;
if (NULL != pcity && is_city_center(pcity, ptile)) {
if (pcity != nullptr && is_city_center(pcity, ptile)) {
prod = MAX(prod, game.info.min_city_center_output[otype]);
}
......
int city_map_x, city_map_y;
struct player *towner;
if (NULL == ptile) {
if (ptile == nullptr) {
return FALSE;
}
......
return FALSE;
}
if (NULL != restriction
if (restriction != nullptr
&& TILE_UNKNOWN == tile_get_known(ptile, restriction)) {
return FALSE;
}
towner = tile_owner(ptile);
if (NULL != towner && towner != powner
if (towner != nullptr && towner != powner
&& !gives_shared_tiles(towner, powner)) {
return FALSE;
}
/* TODO: civ3-like option for borders */
if (NULL != tile_worked(ptile) && tile_worked(ptile) != pcity) {
if (tile_worked(ptile) != nullptr && tile_worked(ptile) != pcity) {
return FALSE;
}
......
}
if (!is_free_worked(pcity, ptile)
&& NULL != unit_occupies_tile(ptile, powner)) {
&& unit_occupies_tile(ptile, powner) != nullptr) {
return FALSE;
}
if (get_city_tile_output_bonus(pcity, ptile, NULL, EFT_TILE_WORKABLE) <= 0) {
if (get_city_tile_output_bonus(pcity, ptile, nullptr, EFT_TILE_WORKABLE) <= 0) {
return FALSE;
}
......
Returns TRUE if the given unit can build a city at the given map
coordinates.
punit is the founding unit. It may be NULL if a city is built out of the
blue (e.g., through editing).
punit is the founding unit. It may be nullptr if a city is built out of
the blue (e.g., through editing).
**************************************************************************/
bool city_can_be_built_here(const struct civ_map *nmap,
const struct tile *ptile,
......
return FALSE;
}
if (punit == NULL) {
if (punit == nullptr) {
/* The remaining checks tests if punit can found a city here */
return TRUE;
}
......
towner = tile_owner(ptile);
if (towner == NULL || towner == unit_owner(punit)) {
if (towner == nullptr || towner == unit_owner(punit)) {
return TRUE;
}
......
}
/**********************************************************************//**
This can be City Walls, Coastal defense... depending on attacker type.
If attacker type is not given, just any defense effect will do.
This can be City Walls, Coastal defense... depending on attacker type.
If attacker type is not given, just any defense effect will do.
**************************************************************************/
bool city_got_defense_effect(const struct city *pcity,
const struct unit_type *attacker)
......
}
return get_unittype_bonus(city_owner(pcity), pcity->tile, attacker,
NULL, EFT_DEFEND_BONUS) > 0;
nullptr, EFT_DEFEND_BONUS) > 0;
}
/**********************************************************************//**
Return TRUE iff the city is happy. A happy city will start celebrating
Return TRUE iff the city is happy. A happy city will start celebrating
soon.
A city can only be happy if half or more of the population is happy,
none of the population is unhappy or angry, and it has sufficient size.
......
bool city_happy(const struct city *pcity)
{
return (city_size_get(pcity) >= game.info.celebratesize
&& pcity->feel[CITIZEN_ANGRY][FEELING_FINAL] == 0
&& pcity->feel[CITIZEN_UNHAPPY][FEELING_FINAL] == 0
&& pcity->feel[CITIZEN_HAPPY][FEELING_FINAL] >= (city_size_get(pcity) + 1) / 2);
&& pcity->feel[CITIZEN_ANGRY][FEELING_FINAL] == 0
&& pcity->feel[CITIZEN_UNHAPPY][FEELING_FINAL] == 0
&& pcity->feel[CITIZEN_HAPPY][FEELING_FINAL] >= (city_size_get(pcity) + 1) / 2);
}
/**********************************************************************//**
......
bool city_unhappy(const struct city *pcity)
{
return (pcity->feel[CITIZEN_HAPPY][FEELING_FINAL]
< pcity->feel[CITIZEN_UNHAPPY][FEELING_FINAL]
+ 2 * pcity->feel[CITIZEN_ANGRY][FEELING_FINAL]);
< pcity->feel[CITIZEN_UNHAPPY][FEELING_FINAL]
+ 2 * pcity->feel[CITIZEN_ANGRY][FEELING_FINAL]);
}
/**********************************************************************//**
......
/* .rapture is checked instead of city_celebrating() because this
function is called after .was_happy was updated. */
return (pcity->rapture > 0 && pcity->surplus[O_FOOD] > 0
&& (pcity->rapture % game.info.rapturedelay) == 0
&& (pcity->rapture % game.info.rapturedelay) == 0
&& get_city_bonus(pcity, EFT_RAPTURE_GROW) > 0);
}
......
if (id != 0) {
city_list_iterate(This, pcity) {
if (pcity->id == id) {
return pcity;
return pcity;
}
} city_list_iterate_end;
}
return NULL;
return nullptr;
}
/**********************************************************************//**
......
}
} city_list_iterate_end;
return NULL;
return nullptr;
}
/**********************************************************************//**
......
{
if (pcity->surplus[O_FOOD] > 0) {
return (city_granary_size(city_size_get(pcity)) - pcity->food_stock +
pcity->surplus[O_FOOD] - 1) / pcity->surplus[O_FOOD];
pcity->surplus[O_FOOD] - 1) / pcity->surplus[O_FOOD];
} else if (pcity->surplus[O_FOOD] < 0) {
/* Turns before famine loss */
return -1 + (pcity->food_stock / pcity->surplus[O_FOOD]);
......
{
struct city *pcity = tile_city(ptile);
if (pcity != NULL && pplayers_at_war(pplayer, city_owner(pcity))) {
if (pcity != nullptr && pplayers_at_war(pplayer, city_owner(pcity))) {
return pcity;
}
return NULL;
return nullptr;
}
/**********************************************************************//**
......
{
struct city *pcity = tile_city(ptile);
if (pcity != NULL && pplayers_allied(pplayer, city_owner(pcity))) {
if (pcity != nullptr && pplayers_allied(pplayer, city_owner(pcity))) {
return pcity;
}
return NULL;
return nullptr;
}
/**********************************************************************//**
......
{
struct city *pcity = tile_city(ptile);
if (pcity != NULL && pplayers_non_attack(pplayer, city_owner(pcity))) {
if (pcity != nullptr && pplayers_non_attack(pplayer, city_owner(pcity))) {
return pcity;
}
return NULL;
return nullptr;
}
/**********************************************************************//**
......
{
struct city *pcity = tile_city(ptile);
if (pcity != NULL && !pplayers_allied(pplayer, city_owner(pcity))) {
if (pcity != nullptr && !pplayers_allied(pplayer, city_owner(pcity))) {
return pcity;
}
return NULL;
return nullptr;
}
/**********************************************************************//**
......
}
/**********************************************************************//**
Return the factor (in %) by which the city's output should be multiplied.
Return the factor (in %) by which the city's output should be multiplied.
**************************************************************************/
int get_final_city_output_bonus(const struct city *pcity, Output_type_id otype)
{
struct output_type *output = &output_types[otype];
int bonus1 = 100 + get_city_tile_output_bonus(pcity, NULL, output,
EFT_OUTPUT_BONUS);
int bonus2 = 100 + get_city_tile_output_bonus(pcity, NULL, output,
EFT_OUTPUT_BONUS_2);
int bonus1 = 100 + get_city_tile_output_bonus(pcity, nullptr, output,
EFT_OUTPUT_BONUS);
int bonus2 = 100 + get_city_tile_output_bonus(pcity, nullptr, output,
EFT_OUTPUT_BONUS_2);
return MAX(bonus1 * bonus2 / 100, 0);
}
......
static const struct city *nearest_gov_center(const struct city *pcity,
int *min_dist)
{
const struct city *gov_center = NULL;
const struct city *gov_center = nullptr;
*min_dist = FC_INFINITY;
......
city_tile_iterate_index(nmap, city_map_radius_sq_get(pcity), pcenter, ptile,
city_tile_index) {
if (workers_map == NULL) {
if (workers_map == nullptr) {
struct city *pwork = tile_worked(ptile);
is_worked = (NULL != pwork && pwork == pcity);
is_worked = (pwork != nullptr && pwork == pcity);
} else {
is_worked = workers_map[city_tile_index];
}
......
int radius_sq = city_map_radius_sq_get(pcity);
/* Initialize tile_cache if needed */
if (pcity->tile_cache == NULL || pcity->tile_cache_radius_sq == -1
if (pcity->tile_cache == nullptr || pcity->tile_cache_radius_sq == -1
|| pcity->tile_cache_radius_sq != radius_sq) {
pcity->tile_cache = fc_realloc(pcity->tile_cache,
city_map_tiles(radius_sq)
......
int min_dist;
const struct city *gov_center = nearest_gov_center(pcity, &min_dist);
if (gov_center == NULL) {
if (gov_center == nullptr) {
/* No gov center - no income */
waste_level = 100;
} else {
......
output_type_iterate(o) {
switch (output_types[o].unhappy_penalty) {
case UNHAPPY_PENALTY_NONE:
pcity->unhappy_penalty[o] = 0;
break;
pcity->unhappy_penalty[o] = 0;
break;
case UNHAPPY_PENALTY_SURPLUS:
pcity->unhappy_penalty[o] = MAX(pcity->prod[o] - pcity->usage[o], 0);
break;
pcity->unhappy_penalty[o] = MAX(pcity->prod[o] - pcity->usage[o], 0);
break;
case UNHAPPY_PENALTY_ALL_PRODUCTION:
pcity->unhappy_penalty[o] = pcity->prod[o];
break;
pcity->unhappy_penalty[o] = pcity->prod[o];
break;
}
pcity->prod[o] -= pcity->unhappy_penalty[o];
} output_type_iterate_end;
} else {
memset(pcity->unhappy_penalty, 0,
O_LAST * sizeof(*pcity->unhappy_penalty));
O_LAST * sizeof(*pcity->unhappy_penalty));
}
}
......
Calculate the pollution from production and population in the city.
**************************************************************************/
int city_pollution_types(const struct city *pcity, int shield_total,
int *pollu_prod, int *pollu_pop, int *pollu_mod)
int *pollu_prod, int *pollu_pop, int *pollu_mod)
{
int prod, pop, mod;
......
**************************************************************************/
int city_pollution(const struct city *pcity, int shield_total)
{
return city_pollution_types(pcity, shield_total, NULL, NULL, NULL);
return city_pollution_types(pcity, shield_total,
nullptr, nullptr, nullptr);
}
/**********************************************************************//**
......
of both cities. The health penalty is given as the product of the ruleset
option 'game.info.illness_trade_infection' (in percent) and the square
root of the product of the size of both cities.
*************************************************************************/
**************************************************************************/
static int get_trade_illness(const struct city *pcity)
{
float illness_trade = 0.0;
......
* there's just a placeholder city with a placeholder owner
* created for some tile->worked. */
if (!is_server()
&& (tcity == NULL
|| city_owner(tcity)->slot == NULL)) {
&& (tcity == nullptr
|| city_owner(tcity)->slot == nullptr)) {
continue;
}
fc_assert_action(tcity != NULL, continue);
fc_assert_action(tcity != nullptr, continue);
can_trade = can_cities_trade(pcity, tcity);
......
} trade_routes_iterate_end;
pcity->prod[O_GOLD] += get_city_tithes_bonus(pcity);
/* Account for waste. Note that waste is calculated before tax income is
/* Account for waste. Note that waste is calculated before tax income is
* calculated, so if you had "science waste" it would not include taxed
* science. However waste is calculated after the bonuses are multiplied
* science. However waste is calculated after the bonuses are multiplied
* on, so shield waste will include shield bonuses. */
output_type_iterate(o) {
int prod = pcity->prod[o] * pcity->bonus[o] / 100 + pcity->abs_bonus[o];
prod = MAX(prod, 0);
pcity->waste[o] = city_waste(pcity, o, prod, NULL);
pcity->waste[o] = city_waste(pcity, o, prod, nullptr);
} output_type_iterate_end;
/* Convert trade into science/luxury/gold, and add this on to whatever
......
struct player *plr;
int happy_cost;
if (punit == NULL || free_unhappy == NULL) {
if (punit == nullptr || free_unhappy == nullptr) {
return 0;
}
pcity = game_city_by_number(punit->homecity);
if (pcity == NULL) {
if (pcity == nullptr) {
return 0;
}
......
unit_list_iterate(pcity->tile->units, punit) {
if (is_martial_law_unit(punit)
&& unit_owner(punit) == city_owner(pcity)) {
int current = get_target_bonus_effects(NULL,
int current = get_target_bonus_effects(nullptr,
&(const struct req_context) {
.player = city_owner(pcity),
.city = pcity,
......
.unit = punit,
.unittype = unit_type_get(punit)
},
NULL, EFT_MARTIAL_LAW_BY_UNIT);
nullptr, EFT_MARTIAL_LAW_BY_UNIT);
if (current > 0) {
if (sel_count < max_mart_units) {
best_units[sel_count++] = current;
......
/**********************************************************************//**
Refreshes the internal cached data in the city structure.
!full_refresh will not update tile_cache[] or bonus[]. These two
!full_refresh will not update tile_cache[] or bonus[]. These two
values do not need to be recalculated for AI CMA testing.
'workers_map' is an boolean array which defines the placement of the
......
void city_refresh_from_main_map(const struct civ_map *nmap,
struct city *pcity, bool *workers_map)
{
if (workers_map == NULL) {
/* do a full refresh */
if (workers_map == nullptr) {
/* Do a full refresh */
/* Calculate the bonus[] array values. */
set_city_bonuses(pcity);
......
pcity->pollution = city_pollution(pcity, pcity->prod[O_SHIELD]);
happy_copy(pcity, FEELING_LUXURY);
citizen_happy_luxury(pcity); /* With our new found luxuries */
citizen_happy_luxury(pcity); /* With our new found luxuries */
happy_copy(pcity, FEELING_EFFECT);
citizen_content_buildings(pcity);
......
/**********************************************************************//**
Give corruption/waste generated by city. otype gives the output type
(O_SHIELD/O_TRADE). 'total' gives the total output of this type in the
city. If non-NULL, 'breakdown' should be an OLOSS_LAST-sized array
city. If non-nullptr, 'breakdown' should be an OLOSS_LAST-sized array
which will be filled in with a breakdown of the kinds of waste
(not cumulative).
**************************************************************************/
......
int min_dist;
const struct city *gov_center = nearest_gov_center(pcity, &min_dist);
if (gov_center == NULL) {
if (gov_center == nullptr) {
waste_all = TRUE; /* No gov center - no income */
} else {
waste_level += waste_by_dist * min_dist / 100;
if (waste_by_rel_dist > 0) {
/* Multiply by 50 as an "standard size" for which EFT_OUTPUT_WASTE_BY_DISTANCE
* and EFT_OUTPUT_WASTE_BY_REL_DISTANCE would give same result. */
/* Multiply by 50 as an "standard size" for which EFT_OUTPUT_WASTE_BY_DISTANCE
* and EFT_OUTPUT_WASTE_BY_REL_DISTANCE would give same result. */
waste_level += waste_by_rel_dist * 50 * min_dist / 100
/ MAX(MAP_NATIVE_WIDTH, MAP_NATIVE_HEIGHT);
/ MAX(MAP_NATIVE_WIDTH, MAP_NATIVE_HEIGHT);
}
}
}
......
int val2 = get_specialist_output(pcity, i, otype);
if (val2 > val) {
best = i;
val = val2;
best = i;
val = val2;
}
}
} normal_specialist_type_iterate_end;
......
Adds an improvement (and its effects) to a city.
**************************************************************************/
void city_add_improvement(struct city *pcity,
const struct impr_type *pimprove)
const struct impr_type *pimprove)
{
pcity->built[improvement_index(pimprove)].turn = game.info.turn; /*I_ACTIVE*/
......
Removes an improvement (and its effects) from a city.
**************************************************************************/
void city_remove_improvement(struct city *pcity,
const struct impr_type *pimprove)
const struct impr_type *pimprove)
{
log_debug("Improvement %s removed from city %s",
improvement_rule_name(pimprove), pcity->name);
......
}
free(city_styles);
city_styles = NULL;
city_styles = nullptr;
game.control.num_city_styles = 0;
}
......
* if you ever allocate it by some other mean than fc_calloc() */
struct city *pcity = fc_calloc(1, sizeof(*pcity));
fc_assert_ret_val(NULL != name, NULL); /* No unnamed cities! */
fc_assert_ret_val(name != nullptr, nullptr); /* No unnamed cities! */
/* Do this early, so any logging later will have the city name */
city_name_set(pcity, name);
pcity->tile = ptile;
fc_assert_ret_val(NULL != pplayer, NULL); /* No unowned cities! */
fc_assert_ret_val(pplayer != nullptr, nullptr); /* No unowned cities! */
pcity->owner = pplayer;
pcity->acquire_t = CACQ_FOUNDED;
......
unit_list_destroy(pcity->units_supported);
trade_route_list_destroy(pcity->routes);
if (pcity->tile_cache != NULL) {
if (pcity->tile_cache != nullptr) {
free(pcity->tile_cache);
}
......
unit_list_destroy(pcity->client.info_units_present);
/* Handle a rare case where the game is freed in the middle of a
* spy/diplomat investigate cycle. */
if (pcity->client.collecting_info_units_supported != NULL) {
if (pcity->client.collecting_info_units_supported != nullptr) {
unit_list_destroy(pcity->client.collecting_info_units_supported);
}
if (pcity->client.collecting_info_units_present != NULL) {
if (pcity->client.collecting_info_units_present != nullptr) {
unit_list_destroy(pcity->client.collecting_info_units_present);
}
}
free(pcity->name);
memset(pcity, 0, sizeof(*pcity)); /* ensure no pointers remain */
memset(pcity, 0, sizeof(*pcity)); /* Ensure no pointers remain */
free(pcity);
}
......
Return TRUE if the city is a virtual city. That is, it is a valid city
pointer but does not correspond to a city that exists in the game.
NB: A return value of FALSE implies that either the pointer is NULL or
NB: A return value of FALSE implies that either the pointer is nullptr or
that the city exists in the game.
**************************************************************************/
bool city_is_virtual(const struct city *pcity)
......
pcity->rally_point.persistent = FALSE;
pcity->rally_point.vigilant = FALSE;
free(pcity->rally_point.orders);
pcity->rally_point.orders = NULL;
pcity->rally_point.orders = nullptr;
}
}
......
struct unit_order *checked_orders;
const struct civ_map *nmap = &(wld.map);
if (NULL == pcity) {
if (pcity == nullptr) {
/* Probably lost. */
log_verbose("handle_city_rally_point() bad city number %d.",
packet->id);
......
pcity->rally_point.persistent = FALSE;
if (pcity->rally_point.orders) {
free(pcity->rally_point.orders);
pcity->rally_point.orders = NULL;
pcity->rally_point.orders = nullptr;
}
} else {
checked_orders = create_unit_orders(nmap, packet->length,
common/city.h
* (the city center is _radius_sq_min = 0) outward to the tiles of
* _radius_sq_max. (_x, _y) will be the valid elements of
* [0, CITY_MAP_MAX_SIZE] taking into account the city radius. */
#define city_map_iterate_outwards_radius_sq_index(_radius_sq_min, \
#define city_map_iterate_outwards_radius_sq_index(_radius_sq_min, \
_radius_sq_max, \
_index, _x, _y) \
{ \
fc_assert(_radius_sq_min <= _radius_sq_max); \
int _x = 0, _y = 0, _index; \
int _x##_y##_index = city_map_tiles(_radius_sq_min); \
while (city_tile_index_to_xy(&_x, &_y, _x##_y##_index, \
_radius_sq_max)) { \
_index = _x##_y##_index; \
_index, _x, _y) \
{ \
fc_assert(_radius_sq_min <= _radius_sq_max); \
int _x = 0, _y = 0, _index; \
int _x##_y##_index = city_map_tiles(_radius_sq_min); \
while (city_tile_index_to_xy(&_x, &_y, _x##_y##_index, \
_radius_sq_max)) { \
_index = _x##_y##_index; \
_x##_y##_index++;
#define city_map_iterate_outwards_radius_sq_index_end \
} \
#define city_map_iterate_outwards_radius_sq_index_end \
} \
}
/* Same as above, but don't set index */
......
_radius_sq_max)) { \
_x##_y##_index++;
#define city_map_iterate_outwards_radius_sq_end \
} \
#define city_map_iterate_outwards_radius_sq_end \
} \
}
/* Iterate a city map. This iterates over all city positions in the city
* map starting at the city center (i.e., positions that are workable by
* the city) using the index (_index) and the coordinates (_x, _y). It
* the city) using the index (_index) and the coordinates (_x, _y). It
* is an abbreviation for city_map_iterate_outwards_radius_sq(_end). */
#define city_map_iterate(_radius_sq, _index, _x, _y) \
city_map_iterate_outwards_radius_sq_index(CITY_MAP_CENTER_RADIUS_SQ, \
#define city_map_iterate(_radius_sq, _index, _x, _y) \
city_map_iterate_outwards_radius_sq_index(CITY_MAP_CENTER_RADIUS_SQ, \
_radius_sq, _index, _x, _y)
#define city_map_iterate_end \
#define city_map_iterate_end \
city_map_iterate_outwards_radius_sq_index_end
#define city_map_iterate_without_index(_radius_sq, _x, _y) \
......
city_map_iterate_outwards_radius_sq_end
/* Iterate the tiles between two radii of a city map. */
#define city_map_iterate_radius_sq(_radius_sq_min, _radius_sq_max, \
_x, _y) \
city_map_iterate_outwards_radius_sq(_radius_sq_min, _radius_sq_max, \
#define city_map_iterate_radius_sq(_radius_sq_min, _radius_sq_max, \
_x, _y) \
city_map_iterate_outwards_radius_sq(_radius_sq_min, _radius_sq_max, \
_x, _y)
#define city_map_iterate_radius_sq_end \
#define city_map_iterate_radius_sq_end \
city_map_iterate_outwards_radius_sq_end
/* Iterate a city map in checked real map coordinates.
......
* (_index) will be the city tile index in the interval
* [0, city_map_tiles(_radius_sq)] */
#define city_tile_iterate_index(_nmap, _radius_sq, _city_tile, _tile, \
_index) { \
city_map_iterate_outwards_radius_sq_index(CITY_MAP_CENTER_RADIUS_SQ, \
_radius_sq, _index, _x, _y) \
_index) { \
city_map_iterate_outwards_radius_sq_index(CITY_MAP_CENTER_RADIUS_SQ, \
_radius_sq, _index, _x, _y) \
struct tile *_tile = city_map_to_tile(_nmap, _city_tile, _radius_sq, \
_x, _y); \
if (NULL != _tile) {
_x, _y); \
if (_tile != nullptr) {
#define city_tile_iterate_index_end \
} \
#define city_tile_iterate_index_end \
} \
} city_map_iterate_outwards_radius_sq_index_end;
/* simple extension to skip is_free_worked() tiles. */
#define city_tile_iterate_skip_free_worked(_nmap, _radius_sq, _city_tile, \
_tile, _index, _x, _y) { \
city_map_iterate(_radius_sq, _index, _x, _y) { \
if (!is_free_worked_index(_index)) { \
_tile, _index, _x, _y) { \
city_map_iterate(_radius_sq, _index, _x, _y) { \
if (!is_free_worked_index(_index)) { \
struct tile *_tile = city_map_to_tile(_nmap, _city_tile, _radius_sq, \
_x, _y); \
if (NULL != _tile) {
_x, _y); \
if (_tile != nullptr) {
#define city_tile_iterate_skip_free_worked_end \
} \
} \
} city_map_iterate_end; \
#define city_tile_iterate_skip_free_worked_end \
} \
} \
} city_map_iterate_end; \
}
/* Does the same thing as city_tile_iterate_index(), but keeps the city
......
_radius_sq, _x, _y) \
struct tile *_tile = city_map_to_tile(_nmap, _center##_tile, _radius_sq, \
_x, _y); \
if (NULL != _tile) {
if (_tile != nullptr) {
#define city_tile_iterate_end \
} \
......
* (replaced Impr_Status) */
struct built_status {
int turn; /* turn built, negative for old state */
#define I_NEVER (-1) /* Improvement never built */
#define I_DESTROYED (-2) /* Improvement built and destroyed */
int turn; /* Turn built, negative for old state */
#define I_NEVER (-1) /* Improvement never built */
#define I_DESTROYED (-2) /* Improvement built and destroyed */
};
/* How much this output type is penalized for unhappy cities: not at all,
......
CITIZEN_SPECIALIST = CITIZEN_LAST,
};
/* changing this order will break network compatibility,
/* Changing this order will break network compatibility,
* and clients that don't use the symbols. */
enum citizen_feeling {
FEELING_BASE, /* before any of the modifiers below */
FEELING_LUXURY, /* after luxury */
FEELING_EFFECT, /* after building effects */
FEELING_NATIONALITY, /* after citizen nationality effects */
FEELING_MARTIAL, /* after units enforce martial order */
FEELING_FINAL, /* after wonders (final result) */
FEELING_BASE, /* Before any of the modifiers below */
FEELING_LUXURY, /* After luxury */
FEELING_EFFECT, /* After building effects */
FEELING_NATIONALITY, /* After citizen nationality effects */
FEELING_MARTIAL, /* After units enforce martial order */
FEELING_FINAL, /* After wonders (final result) */
FEELING_LAST
};
......
#endif
struct city {
char *name;
struct tile *tile; /* May be NULL, should check! */
struct player *owner; /* Cannot be NULL. */
struct player *original; /* Often NULL in client,
* can be NULL on server after player removal */
struct tile *tile; /* May be nullptr, should check! */
struct player *owner; /* Cannot be nullptr. */
struct player *original; /* Often nullptr in client,
* can be nullptr on server after player removal */
int id;
int style;
enum capital_type capital;
......
bool colored;
int color_index;
/* info for dipl/spy investigation */
/* Info for dipl/spy investigation */
struct unit_list *info_units_supported;
struct unit_list *info_units_present;
/* Before popup the city dialog, units go there. In normal process,
* these pointers are set to NULL. */
* these pointers are set to nullptr. */
struct unit_list *collecting_info_units_supported;
struct unit_list *collecting_info_units_present;
......
struct city *_city = \
game_city_by_number(_city##_numbers[_city##_index]); \
\
if (NULL != _city) {
if (_city != nullptr) {
#define city_list_iterate_safe_end \
} \
......
**************************************************************************/
static inline citizens city_size_get(const struct city *pcity)
{
fc_assert_ret_val(pcity != NULL, 0);
fc_assert_ret_val(pcity != nullptr, 0);
return pcity->size;
}
......
int city_unit_slots_available(const struct city *pcity);
bool city_can_use_specialist(const struct city *pcity,
Specialist_type_id type);
Specialist_type_id type);
bool city_has_building(const struct city *pcity,
const struct impr_type *pimprove);
bool is_capital(const struct city *pcity);
......
/* Textual representation of buildings */
const char *city_improvement_name_translation(const struct city *pcity,
const struct impr_type *pimprove);
const struct impr_type *pimprove);
const char *city_production_name_translation(const struct city *pcity);
/* City map functions */
......
static inline bool is_enemy_city_tile(const struct tile *ptile,
const struct player *pplayer)
{
return NULL != tile_enemy_city(ptile, pplayer);
return tile_enemy_city(ptile, pplayer) != nullptr;
}
struct city *tile_allied_city(const struct tile *ptile,
......
static inline bool is_allied_city_tile(const struct tile *ptile,
const struct player *pplayer)
{
return NULL != tile_allied_city(ptile, pplayer);
return tile_allied_city(ptile, pplayer) != nullptr;
}
struct city *tile_non_attack_city(const struct tile *ptile,
......
static inline bool is_non_attack_city_tile(const struct tile *ptile,
const struct player *pplayer)
{
return NULL != tile_non_attack_city(ptile, pplayer);
return tile_non_attack_city(ptile, pplayer) != nullptr;
}
struct city *tile_non_allied_city(const struct tile *ptile,
......
static inline bool is_non_allied_city_tile(const struct tile *ptile,
const struct player *pplayer)
{
return NULL != tile_non_allied_city(ptile, pplayer);
return tile_non_allied_city(ptile, pplayer) != nullptr;
}
bool is_unit_near_a_friendly_city(const struct civ_map *nmap,
......
int city_granary_size(int city_size);
void city_add_improvement(struct city *pcity,
const struct impr_type *pimprove);
const struct impr_type *pimprove);
void city_remove_improvement(struct city *pcity,
const struct impr_type *pimprove);
const struct impr_type *pimprove);
/* City update functions */
void city_refresh_from_main_map(const struct civ_map *nmap,
......
int city_waste(const struct city *pcity, Output_type_id otype, int total,
int *breakdown);
Specialist_type_id best_specialist(Output_type_id otype,
const struct city *pcity);
const struct city *pcity);
int get_final_city_output_bonus(const struct city *pcity, Output_type_id otype);
bool city_built_last_turn(const struct city *pcity);
/* City creation / destruction */
struct city *create_city_virtual(struct player *pplayer,
struct tile *ptile, const char *name);
struct tile *ptile, const char *name);
void destroy_city_virtual(struct city *pcity);
bool city_is_virtual(const struct city *pcity);
......
void add_tax_income(const struct player *pplayer, int trade, int *output);
int get_city_tithes_bonus(const struct city *pcity);
int city_pollution_types(const struct city *pcity, int shield_total,
int *pollu_prod, int *pollu_pop, int *pollu_mod);
int *pollu_prod, int *pollu_pop, int *pollu_mod);
int city_pollution(const struct city *pcity, int shield_total);
int city_illness_calc(const struct city *pcity, int *ill_base,
int *ill_size, int *ill_trade, int *ill_pollution);
......
* Iterates over all improvements, skipping those not yet built in the
* given city.
*/
#define city_built_iterate(_pcity, _p) \
improvement_iterate(_p) { \
if ((_pcity)->built[improvement_index(_p)].turn <= I_NEVER) { \
continue; \
#define city_built_iterate(_pcity, _p) \
improvement_iterate(_p) { \
if ((_pcity)->built[improvement_index(_p)].turn <= I_NEVER) { \
continue; \
}
#define city_built_iterate_end \
#define city_built_iterate_end \
} improvement_iterate_end;
/* Iterates over all output types in the game. */
#define output_type_iterate(output) \
{ \
Output_type_id output; \
\
#define output_type_iterate(output) \
{ \
Output_type_id output; \
\
for (output = 0; output < O_LAST; output++) {
#define output_type_iterate_end \
} \
#define output_type_iterate_end \
} \
}
    (1-1/1)