From c16c596dc6d47b04ad0b719ced951a6e9d3dd00c Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 12 Jul 2023 01:08:13 +0300 Subject: [PATCH 32/32] Improve citytools.[ch] coding style See osdn #48387 Signed-off-by: Marko Lindqvist --- server/citytools.c | 681 +++++++++++++++++++++++---------------------- server/citytools.h | 13 +- 2 files changed, 351 insertions(+), 343 deletions(-) diff --git a/server/citytools.c b/server/citytools.c index bcb68ace52..f1ce795f42 100644 --- a/server/citytools.c +++ b/server/citytools.c @@ -95,7 +95,7 @@ /* Queue for pending auto_arrange_workers() */ -static struct city_list *arrange_workers_queue = NULL; +static struct city_list *arrange_workers_queue = nullptr; /* Suppress sending cities during game_load() and end_phase() */ static bool send_city_suppressed = FALSE; @@ -124,8 +124,8 @@ static void announce_trade_route_removal(struct city *pc1, struct city *pc2, Call freeze_workers() to freeze the auto-arranging of citizens. So long as the freeze is in place no arrangement will be done for this city. Any call to auto_arrange_workers() will just queue up an arrangement for later. - Later when thaw_workers is called, the freeze is removed and the - auto-arrange will be done if there is any arrangement pending. + Later when thaw_workers is called, the freeze is removed and + the auto-arrange will be done if there is any arrangement pending. Freezing may safely be done more than once. @@ -138,8 +138,8 @@ void city_freeze_workers(struct city *pcity) } /************************************************************************//** - Thaw (unfreeze) the workers (citizens on tiles) for the city. The workers - will be auto-arranged if there is an arrangement pending. See explanation + Thaw (unfreeze) the workers (citizens on tiles) for the city. The workers + will be auto-arranged if there is an arrangement pending. See explanation in freeze_workers(). ****************************************************************************/ void city_thaw_workers(struct city *pcity) @@ -158,7 +158,7 @@ void city_thaw_workers(struct city *pcity) ****************************************************************************/ void city_freeze_workers_queue(struct city *pcity) { - if (NULL == arrange_workers_queue) { + if (arrange_workers_queue == nullptr) { arrange_workers_queue = city_list_new(); } else if (city_list_find_number(arrange_workers_queue, pcity->id)) { return; @@ -177,7 +177,7 @@ void city_freeze_workers_queue(struct city *pcity) ****************************************************************************/ static bool city_workers_queue_remove(struct city *pcity) { - if (arrange_workers_queue == NULL) { + if (arrange_workers_queue == nullptr) { return FALSE; } @@ -190,7 +190,7 @@ static bool city_workers_queue_remove(struct city *pcity) ****************************************************************************/ void city_thaw_workers_queue(void) { - if (NULL == arrange_workers_queue) { + if (arrange_workers_queue == nullptr) { return; } @@ -199,12 +199,12 @@ void city_thaw_workers_queue(void) } city_list_iterate_end; city_list_destroy(arrange_workers_queue); - arrange_workers_queue = NULL; + arrange_workers_queue = nullptr; } /************************************************************************//** Returns the priority of the city name at the given position, using its - own internal algorithm. Lower priority values are more desired, and all + own internal algorithm. Lower priority values are more desired, and all priorities are non-negative. This function takes into account game.natural_city_names, and should be @@ -219,16 +219,16 @@ static int evaluate_city_name_priority(struct tile *ptile, enum nation_city_preference goodness; /* Increasing this value will increase the difference caused by - (non-)matching terrain. A matching terrain is mult_factor + (non-)matching terrain. A matching terrain is mult_factor "better" than an unlisted terrain, which is mult_factor "better" than a non-matching terrain. */ const float mult_factor = 1.4; bool river = FALSE; /* - * If natural city names aren't being used, we just return the - * base value. This will have the effect of the first-listed - * city being used. We do this here rather than special-casing + * If natural city names aren't being used, we just return + * the base value. This will have the effect of the first-listed + * city being used. We do this here rather than special-casing * it elsewhere because this localizes everything to this * function, even though it's a bit inefficient. */ @@ -240,14 +240,14 @@ static int evaluate_city_name_priority(struct tile *ptile, * Assuming we're using the natural city naming system, we use * an internal alorithm to calculate the priority of each name. * It's a pretty fuzzy algorithm; we basically do the following: - * - Change the priority scale from 0..n to 10..n+10. This means + * - Change the priority scale from 0..n to 10..n+10. This means * each successive city is 10% lower priority than the first. - * - Multiply by a semi-random number. This has the effect of + * - Multiply by a semi-random number. This has the effect of * decreasing rounding errors in the successive calculations, * as well as introducing a smallish random effect. * - Check over all the applicable terrains, and * multiply or divide the priority based on whether or not - * the terrain matches. See comment below. + * the terrain matches. See comment below. */ priority += 10.0; @@ -255,13 +255,13 @@ static int evaluate_city_name_priority(struct tile *ptile, /* * The terrain priority in the struct nation_city will be either - * -1, 0, or 1. We therefore take this as-is if the terrain is + * -1, 0, or 1. We therefore take this as-is if the terrain is * present, or negate it if not. * * The reason we multiply as well as divide the value is so * that cities that don't care what terrain they are on (which - * is the default) will be left in the middle of the pack. If - * we _only_ multiplied (or divided), then cities that had more + * is the default) will be left in the middle of the pack. + * If we _only_ multiplied (or divided), then cities that had more * terrain labels would have their priorities hurt (or helped). */ goodness = nation_city_river_preference(pncity); @@ -327,7 +327,7 @@ static bool is_default_city_name(const char *name, struct player *pplayer) the best available city name, and returns a pointer to it. The function checks if the city name is available and calls evaluate_city_name_priority() to determine the priority of the city name. - If the list has no valid entries in it, NULL will be returned. + If the list has no valid entries in it, nullptr will be returned. ****************************************************************************/ static const char *search_for_city_name(struct tile *ptile, const struct nation_city_list * @@ -335,12 +335,13 @@ static const char *search_for_city_name(struct tile *ptile, struct player *pplayer) { int choice = 0, priority, best_priority = -1; - const char *name, *best_name = NULL; + const char *name; + const char *best_name = nullptr; nation_city_list_iterate(default_cities, pncity) { name = nation_city_name(pncity); - if (NULL == game_city_by_name(name) - && is_allowed_city_name(pplayer, name, NULL, 0)) { + if (game_city_by_name(name) == nullptr + && is_allowed_city_name(pplayer, name, nullptr, 0)) { priority = evaluate_city_name_priority(ptile, pncity, choice++); if (-1 == best_priority || priority < best_priority) { best_priority = priority; @@ -361,11 +362,11 @@ static const char *search_for_city_name(struct tile *ptile, 3: a city name has to be globally unique, and players can't use names that are in another player's default city names. (E.g., Swedish may not call new cities or rename old cities as Helsinki, because it's in - Finns' default city names. Duplicated names may be used by + Finns' default city names. Duplicated names may be used by either nation.) ****************************************************************************/ bool is_allowed_city_name(struct player *pplayer, const char *cityname, - char *error_buf, size_t bufsz) + char *error_buf, size_t bufsz) { struct connection *pconn = conn_by_user(pplayer->username); @@ -395,22 +396,22 @@ bool is_allowed_city_name(struct player *pplayer, const char *cityname, return TRUE; } - /* + /* * Mode 3: Check that the proposed city name is not in another - * player's default city names. Note the name will already have been + * player's default city names. Note the name will already have been * allowed if it is in this player's default city names list. */ if (CNM_NO_STEALING == game.server.allowed_city_names) { - struct player *pother = NULL; + struct player *pother = nullptr; players_iterate(player2) { if (player2 != pplayer && is_default_city_name(cityname, player2)) { - pother = player2; - break; + pother = player2; + break; } } players_iterate_end; - if (pother != NULL) { + if (pother != nullptr) { if (error_buf) { fc_snprintf(error_buf, bufsz, _("Can't use %s as a city name. It is reserved for %s."), @@ -421,12 +422,12 @@ bool is_allowed_city_name(struct player *pplayer, const char *cityname, } /* To prevent abuse, only players with HACK access (usually local - * connections) can use non-ascii names. Otherwise players could use + * connections) can use non-ascii names. Otherwise players could use * confusing garbage names in multi-player games. * - * We can even reach here for an AI player, if all the cities of the - * original nation are exhausted and the backup nations have non-ascii - * names in them. */ + * We can even reach here for an AI player, if all the cities of + * the original nation are exhausted and the backup nations have + * non-ascii names in them. */ if (!is_ascii_name(cityname) && (!pconn || pconn->access_level != ALLOW_HACK)) { if (error_buf) { @@ -458,7 +459,7 @@ const char *city_name_suggestion(struct player *pplayer, struct tile *ptile) /* First try default city names. */ name = search_for_city_name(ptile, nation_cities(pnation), pplayer); - if (NULL != name) { + if (name != nullptr) { log_debug("Default city name found: %s.", name); return name; } @@ -503,7 +504,7 @@ const char *city_name_suggestion(struct player *pplayer, struct tile *ptile) log_debug("Looking through %s.", nation_rule_name(pnation)); name = search_for_city_name(ptile, nation_cities(pnation), pplayer); - if (NULL != name) { + if (name != nullptr) { return name; } } @@ -552,7 +553,7 @@ const char *city_name_suggestion(struct player *pplayer, struct tile *ptile) log_debug("City name not found in rulesets."); for (i = 1; i <= map_num_tiles(); i++ ) { fc_snprintf(tempname, MAX_LEN_CITYNAME, _("City no. %d"), i); - if (NULL == game_city_by_name(tempname)) { + if (game_city_by_name(tempname) == nullptr) { return tempname; } } @@ -601,9 +602,9 @@ static void transfer_unit(struct unit *punit, struct city *tocity, if (verbose) { notify_player(from_player, unit_tile(punit), E_UNIT_RELOCATED, ftc_server, - _("Changed homecity of %s to %s."), - unit_link(punit), - city_link(tocity)); + _("Changed homecity of %s to %s."), + unit_link(punit), + city_link(tocity)); } } else { struct tile *utile = unit_tile(punit); @@ -635,7 +636,7 @@ static void transfer_unit(struct unit *punit, struct city *tocity, unit_tile_link(punit)); } - wipe_unit(punit, ULR_CITY_LOST, NULL); + wipe_unit(punit, ULR_CITY_LOST, nullptr); } return; @@ -649,11 +650,11 @@ static void transfer_unit(struct unit *punit, struct city *tocity, if (verbose) { notify_player(from_player, unit_tile(punit), E_UNIT_RELOCATED, ftc_server, - _("Transferred %s in %s from %s to %s."), - unit_link(punit), - city_link(in_city), - nation_plural_for_player(from_player), - nation_plural_for_player(to_player)); + _("Transferred %s in %s from %s to %s."), + unit_link(punit), + city_link(in_city), + nation_plural_for_player(from_player), + nation_plural_for_player(to_player)); } } else if (can_unit_exist_at_tile(&(wld.map), punit, tocity->tile)) { log_verbose("Transferred %s from %s to %s", @@ -664,9 +665,9 @@ static void transfer_unit(struct unit *punit, struct city *tocity, notify_player(from_player, unit_tile(punit), E_UNIT_RELOCATED, ftc_server, _("Transferred %s from %s to %s."), - unit_link(punit), - nation_plural_for_player(from_player), - nation_plural_for_player(to_player)); + unit_link(punit), + nation_plural_for_player(from_player), + nation_plural_for_player(to_player)); } } else { log_verbose("Could not transfer %s from %s to %s", @@ -683,7 +684,7 @@ static void transfer_unit(struct unit *punit, struct city *tocity, nation_adjective_for_player(to_player), city_link(tocity)); } - wipe_unit(punit, ULR_CITY_LOST, NULL); + wipe_unit(punit, ULR_CITY_LOST, nullptr); return; } @@ -696,7 +697,7 @@ static void transfer_unit(struct unit *punit, struct city *tocity, When a city is transferred (bought, incited, disbanded, civil war): Units in a transferred city are transferred to the new owner; units supported by the city, but held in other cities are updated to - reflect those cities as their new homecity. Units supported + reflect those cities as their new homecity. Units supported by the transferred city that are not in a city tile may be deleted. - Kris Bubendorfer @@ -756,10 +757,10 @@ void transfer_city_units(struct player *pplayer, struct player *pvictim, * Not sure if it would be safe to unlink first and transfer only * after that. Not sure if it is correct to unlink at all in * some cases, depending which list 'units' points to. */ - transfer_unit(vunit, pcity, !homeless, verbose); - unit_list_remove(units, vunit); + transfer_unit(vunit, pcity, !homeless, verbose); + unit_list_remove(units, vunit); } else if (!pplayers_allied(pplayer, unit_owner(vunit))) { - /* the owner of vunit is allied to pvictim but not to pplayer */ + /* The owner of vunit is allied to pvictim but not to pplayer */ bounce_unit(vunit, verbose); } } unit_list_iterate_safe_end; @@ -770,7 +771,7 @@ void transfer_city_units(struct player *pplayer, struct player *pvictim, } /* Any remaining units supported by the city are either given new home - cities or maybe destroyed */ + * cities or maybe destroyed */ unit_list_iterate_safe(units, vunit) { struct city *new_home_city = tile_city(unit_tile(vunit)); @@ -784,18 +785,18 @@ void transfer_city_units(struct player *pplayer, struct player *pvictim, } if (new_home_city && new_home_city != exclude_city - && city_owner(new_home_city) == unit_owner(vunit)) { - /* unit is in another city: make that the new homecity, + && city_owner(new_home_city) == unit_owner(vunit)) { + /* Unit is in another city: make that the new homecity, * unless that city is actually the same city (happens if disbanding) * Unit had a homecity since it was supported, so rehome. */ transfer_unit(vunit, new_home_city, TRUE, verbose); } else if ((kill_outside == -1 || real_map_distance(unit_tile(vunit), ptile) <= kill_outside) && saved_id) { - /* else transfer to specified city. */ + /* Else transfer to specified city. */ transfer_unit(vunit, pcity, TRUE, verbose); if (unit_tile(vunit) == ptile && !pplayers_allied(pplayer, pvictim)) { - /* Unit is inside city being transferred, bounce it */ + /* Unit is inside city being transferred, bounce it. */ bounce_unit(vunit, TRUE); } } else { @@ -810,7 +811,7 @@ void transfer_city_units(struct player *pplayer, struct player *pvictim, _("%s lost along with control of %s."), unit_tile_link(vunit), name); } - wipe_unit(vunit, ULR_CITY_LOST, NULL); + wipe_unit(vunit, ULR_CITY_LOST, nullptr); } } unit_list_iterate_safe_end; @@ -837,14 +838,14 @@ void transfer_city_units(struct player *pplayer, struct player *pvictim, 'only_continent' if set only cities on the same continent as 'ptile' are valid. 'only_known' if set only cities known to 'pplayer' are considered. - 'only_player' if set and 'pplayer' is not NULL only cities of this + 'only_player' if set and 'pplayer' is not nullptr only cities of this player are returned. - 'only_enemy' if set and 'pplayer' is not NULL only cities of players + 'only_enemy' if set and 'pplayer' is not nullptr only cities of players which are at war with 'pplayer' are returned. - 'pclass' if set, and 'pclass' is not NULL only cities that have + 'pclass' if set, and 'pclass' is not nullptr only cities that have adjacent native terrain for that unit class are returned. - If no city is found NULL is returned. + If no city is found nullptr is returned. ****************************************************************************/ struct city *find_closest_city(const struct tile *ptile, const struct city *pexclcity, @@ -854,27 +855,27 @@ struct city *find_closest_city(const struct tile *ptile, bool only_enemy, const struct unit_class *pclass) { Continent_id con; - struct city *best_city = NULL; + struct city *best_city = nullptr; int best_dist = -1; - fc_assert_ret_val(ptile != NULL, NULL); + fc_assert_ret_val(ptile != nullptr, nullptr); - if (pplayer != NULL && only_player && only_enemy) { + if (pplayer != nullptr && only_player && only_enemy) { log_error("Non of my own cities will be at war with me!"); - return NULL; + return nullptr; } con = tile_continent(ptile); players_iterate(aplayer) { - if (pplayer != NULL && only_player && pplayer != aplayer) { - /* only cities of player 'pplayer' */ + if (pplayer != nullptr && only_player && pplayer != aplayer) { + /* Only cities of player 'pplayer' */ continue; } - if (pplayer != NULL && only_enemy + if (pplayer != nullptr && only_enemy && !pplayers_at_war(pplayer, aplayer)) { - /* only cities of players at war with player 'pplayer' */ + /* Only cities of players at war with player 'pplayer' */ continue; } @@ -901,7 +902,7 @@ struct city *find_closest_city(const struct tile *ptile, || (map_is_known(city_tile(pcity), pplayer) && map_get_player_site(city_tile(pcity), pplayer)->identity > IDENTITY_NUMBER_ZERO)) - && (pclass == NULL + && (pclass == nullptr || is_native_near_tile(&(wld.map), pclass, city_tile(pcity)))) { best_dist = city_dist; best_city = pcity; @@ -922,7 +923,7 @@ static void raze_city(struct city *pcity) int razechance = game.server.razechance; bool city_remains = TRUE; - /* land barbarians are more likely to destroy city improvements */ + /* Land barbarians are more likely to destroy city improvements */ if (is_land_barbarian(city_owner(pcity))) { razechance += 30; } @@ -932,8 +933,9 @@ static void raze_city(struct city *pcity) * transfer_city() (with 100% probability). */ fc_assert(!is_small_wonder(pimprove)); if (is_improvement(pimprove) && (fc_rand(100) < razechance)) { - /* FIXME: Should maybe have conquering unit instead of NULL as destroyer */ - city_remains = building_removed(pcity, pimprove, "razed", NULL); + /* FIXME: Should maybe have conquering unit instead + * of nullptr as destroyer */ + city_remains = building_removed(pcity, pimprove, "razed", nullptr); if (!city_remains) { break; } @@ -1003,9 +1005,9 @@ static void reestablish_city_trade_routes(struct city *pcity) } /************************************************************************//** - Create saved small wonders in random cities. Usually used to save the - palace when the primary capital was conquered. Respects the 'savepalace' - server setting. + Create saved small wonders in random cities. Usually used to save + the palace when the primary capital was conquered. + Respects the 'savepalace' server setting. ****************************************************************************/ static void build_free_small_wonders(struct player *pplayer, bv_imprs *had_small_wonders) @@ -1030,28 +1032,28 @@ static void build_free_small_wonders(struct player *pplayer, /* FIXME: instead, find central city */ struct city *pnew_city = city_list_get(pplayer->cities, fc_rand(size)); - fc_assert_action(NULL == city_from_small_wonder(pplayer, pimprove), + fc_assert_action(city_from_small_wonder(pplayer, pimprove) == nullptr, continue); city_add_improvement(pnew_city, pimprove); /* - * send_player_cities will recalculate all cities and send them to + * send_player_cities() will recalculate all cities and send them to * the client. */ send_player_cities(pplayer); notify_player(pplayer, city_tile(pnew_city), E_IMP_BUILD, ftc_server, - /* FIXME: should already be notified about city loss? */ - /* TRANS: ... */ - _("A replacement %s was built in %s."), - improvement_name_translation(pimprove), - city_link(pnew_city)); - /* + /* FIXME: should already be notified about city loss? */ + /* TRANS: ... */ + _("A replacement %s was built in %s."), + improvement_name_translation(pimprove), + city_link(pnew_city)); + /* * The enemies want to see the new capital in their intelligence - * report. + * report. */ - send_city_info(NULL, pnew_city); + send_city_info(nullptr, pnew_city); } } improvement_iterate_end; } @@ -1086,7 +1088,7 @@ bool transfer_city(struct player *ptaker, struct city *pcity, int units_num = 0; const int ul_size = unit_list_size(pcenter->units); int central_units[ul_size + 1]; - bv_player *could_see_unit = NULL; + bv_player *could_see_unit = nullptr; int i; fc_assert_ret_val(pgiver != ptaker, TRUE); @@ -1135,18 +1137,18 @@ bool transfer_city(struct player *ptaker, struct city *pcity, * 2. Otherwise we might delete the homecity from under the unit * in the client */ punit->homecity = 0; - send_unit_info(NULL, punit); + send_unit_info(nullptr, punit); } unit_list_iterate_end; unit_list_clear(pcity->units_supported); /* Remove all global improvement effects that this city confers (but - then restore the local improvement list - we need this to restore the - global effects for the new city owner) */ + then restore the local improvement list - we need this to restore + the global effects for the new city owner) */ BV_CLR_ALL(had_small_wonders); city_built_iterate(pcity, pimprove) { if (is_small_wonder(pimprove)) { /* Small wonders are really removed (not restored later). */ - building_removed(pcity, pimprove, "conquered", NULL); + building_removed(pcity, pimprove, "conquered", nullptr); BV_SET(had_small_wonders, improvement_index(pimprove)); } else { city_remove_improvement(pcity, pimprove); @@ -1192,7 +1194,7 @@ bool transfer_city(struct player *ptaker, struct city *pcity, map_claim_ownership(pcenter, ptaker, pcenter, TRUE); city_list_prepend(ptaker->cities, pcity); - if (could_see_unit != NULL) { + if (could_see_unit != nullptr) { /* Hide/reveal units. Do it after vision have been given to taker, city * owner has been changed, and before any script could be spawned. */ for (i = 0; i < units_num; i++) { @@ -1217,11 +1219,11 @@ bool transfer_city(struct player *ptaker, struct city *pcity, fc_assert(i == units_num); free(could_see_unit); - could_see_unit = NULL; + could_see_unit = nullptr; } transfer_city_units(ptaker, pgiver, old_city_units, - pcity, NULL, + pcity, nullptr, kill_outside, transfer_unit_verbose); /* The units themselves are already freed by transfer_city_units(). */ unit_list_destroy(old_city_units); @@ -1250,13 +1252,13 @@ bool transfer_city(struct player *ptaker, struct city *pcity, /* Clear CMA. */ if (pcity->cm_parameter) { free(pcity->cm_parameter); - pcity->cm_parameter = NULL; + pcity->cm_parameter = nullptr; } city_refresh(pcity); } - /* + /* * maybe_make_contact() MUST be called before city_map_update_all(), * since the diplomacy status can influence whether a tile is available. */ @@ -1274,7 +1276,7 @@ bool transfer_city(struct player *ptaker, struct city *pcity, * them a palace etc */ if (build_free) { city_build_free_buildings(pcity); - } /* else caller should probably ensure palace is built */ + } /* Else caller should probably ensure palace is built */ ptaker->server.got_first_city = TRUE; } @@ -1305,7 +1307,7 @@ bool transfer_city(struct player *ptaker, struct city *pcity, "technological insight!"), clink); - if (upgradet != NULL) { + if (upgradet != nullptr) { notify_player(ptaker, pcenter, E_CITY_TRANSFER, ftc_server, _("Workers spontaneously gather and upgrade " "%s with %s."), @@ -1323,7 +1325,7 @@ bool transfer_city(struct player *ptaker, struct city *pcity, savepalace is on. */ build_free_small_wonders(pgiver, &had_small_wonders); - /* Refresh the city's vision range, since it might be different + /* Refresh the city's vision range, since it might be different * under the new owner. */ city_refresh_vision(pcity); @@ -1334,11 +1336,11 @@ bool transfer_city(struct player *ptaker, struct city *pcity, map_claim_border(pcenter, ptaker, -1); /* city_thaw_workers_queue() later */ - auto_arrange_workers(pcity); /* does city_map_update_all() */ + auto_arrange_workers(pcity); /* Does city_map_update_all() */ city_thaw_workers(pcity); - city_thaw_workers_queue(); /* after old city has a chance to work! */ + city_thaw_workers_queue(); /* After old city has a chance to work! */ city_refresh_queue_add(pcity); - /* no sanity check here as the city is not refreshed! */ + /* No sanity check here as the city is not refreshed! */ } if (city_remains) { @@ -1346,7 +1348,7 @@ bool transfer_city(struct player *ptaker, struct city *pcity, * having shared vision pact with them before they may * lose vision to it. When we later send info to everybody seeing the city, * they may not be included. */ - send_city_info(NULL, pcity); + send_city_info(nullptr, pcity); } /* Remove the sight points from the giver. */ @@ -1355,9 +1357,9 @@ bool transfer_city(struct player *ptaker, struct city *pcity, /* Send wonder infos. */ if (had_great_wonders) { - send_game_info(NULL); + send_game_info(nullptr); if (city_remains) { - send_player_info_c(ptaker, NULL); + send_player_info_c(ptaker, nullptr); /* Refresh all cities of the taker to account for possible changes due * to player wide effects. */ @@ -1373,7 +1375,7 @@ bool transfer_city(struct player *ptaker, struct city *pcity, } if (BV_ISSET_ANY(had_small_wonders) || had_great_wonders) { /* No need to send to detached connections. */ - send_player_info_c(pgiver, NULL); + send_player_info_c(pgiver, nullptr); /* Refresh all cities of the giver to account for possible changes due * to player wide effects. */ @@ -1389,7 +1391,7 @@ bool transfer_city(struct player *ptaker, struct city *pcity, if (city_remains) { /* Send information about conquered city to all players. */ - send_city_info(NULL, pcity); + send_city_info(nullptr, pcity); } /* We may cross the EFT_EMPIRE_SIZE_* effects, then we will have to @@ -1429,11 +1431,11 @@ void city_build_free_buildings(struct city *pcity) bool has_small_wonders, has_great_wonders; bool first_city; - fc_assert_ret(NULL != pcity); + fc_assert_ret(pcity != nullptr); pplayer = city_owner(pcity); - fc_assert_ret(NULL != pplayer); + fc_assert_ret(pplayer != nullptr); nation = nation_of_player(pplayer); - fc_assert_ret(NULL != nation); + fc_assert_ret(nation != nullptr); /* If this isn't the first city a player has ever had, they only get * any initial buildings with the SaveSmallWonder flag, and then only @@ -1494,12 +1496,12 @@ void city_build_free_buildings(struct city *pcity) /* Update wonder infos. */ if (has_great_wonders) { - send_game_info(NULL); + send_game_info(nullptr); /* No need to send to detached connections. */ - send_player_info_c(pplayer, NULL); + send_player_info_c(pplayer, nullptr); } else if (has_small_wonders) { /* No need to send to detached connections. */ - send_player_info_c(pplayer, NULL); + send_player_info_c(pplayer, nullptr); } } @@ -1520,8 +1522,8 @@ void create_city(struct player *pplayer, struct tile *ptile, pcity = create_city_virtual(pplayer, ptile, name); - /* Remove units no more seen. Do it before city is really put into the - * game. */ + /* Remove units no more seen. Do it before city is really put into + * the game. */ players_iterate(other_player) { if (can_player_see_units_in_city(other_player, pcity) || !map_is_known_and_seen(ptile, other_player, V_MAIN)) { @@ -1557,10 +1559,10 @@ void create_city(struct player *pplayer, struct tile *ptile, /* Place a worker at the is_city_center() is_free_worked(). * It is possible to build a city on a tile that is already worked; * this will displace the worker on the newly-built city's tile -- Syela */ - tile_set_worked(ptile, pcity); /* instead of city_map_update_worker() */ + tile_set_worked(ptile, pcity); /* Instead of city_map_update_worker() */ - if (NULL != pwork) { - /* was previously worked by another city */ + if (pwork != nullptr) { + /* Was previously worked by another city */ /* Turn citizen into specialist. */ pwork->specialists[DEFAULT_SPECIALIST]++; /* One less citizen. Citizen sanity will be handled later in @@ -1585,7 +1587,7 @@ void create_city(struct player *pplayer, struct tile *ptile, } extra_type_iterate_end; /* Build any extras that the city should have. */ - upgrade_city_extras(pcity, NULL); + upgrade_city_extras(pcity, nullptr); /* Claim the ground we stand on */ map_claim_ownership(ptile, pplayer, ptile, TRUE); @@ -1601,14 +1603,14 @@ void create_city(struct player *pplayer, struct tile *ptile, map_claim_border(ptile, pplayer, -1); /* city_thaw_workers_queue() later */ - /* Refresh the city. First a city refresh is done (this shouldn't + /* Refresh the city. First a city refresh is done (this shouldn't * send any packets to the client because the city has no supported units) - * then rearrange the workers. Note that auto_arrange_workers does its - * own refresh call; it is safest to do our own controlled city_refresh + * then rearrange the workers. Note that auto_arrange_workers() does its + * own refresh call; it is safest to do our own controlled city_refresh() * first. */ city_refresh(pcity); auto_arrange_workers(pcity); - city_thaw_workers_queue(); /* after new city has a chance to work! */ + city_thaw_workers_queue(); /* After new city has a chance to work! */ city_refresh_queue_processing(); /* Bases destroyed earlier may have had watchtower effect. Refresh @@ -1625,12 +1627,12 @@ void create_city(struct player *pplayer, struct tile *ptile, } pcity->server.synced = FALSE; - send_city_info(NULL, pcity); + send_city_info(nullptr, pcity); sync_cities(); /* Will also send pwork. */ notify_player(pplayer, ptile, E_CITY_BUILD, ftc_server, - _("You have founded %s."), - city_link(pcity)); + _("You have founded %s."), + city_link(pcity)); maybe_make_contact(ptile, city_owner(pcity)); unit_list_iterate((ptile)->units, punit) { @@ -1670,16 +1672,16 @@ bool create_city_for_player(struct player *pplayer, struct tile *ptile, const char *name) { if (is_enemy_unit_tile(ptile, pplayer) - || !city_can_be_built_here(ptile, NULL)) { + || !city_can_be_built_here(ptile, nullptr)) { return FALSE; } if (!pplayer->is_alive) { pplayer->is_alive = TRUE; - send_player_info_c(pplayer, NULL); + send_player_info_c(pplayer, nullptr); } - if (name == NULL || name[0] == '\0') { + if (name == nullptr || name[0] == '\0') { name = city_name_suggestion(pplayer, ptile); } @@ -1711,7 +1713,7 @@ void remove_city(struct city *pcity) BV_CLR_ALL(had_small_wonders); city_built_iterate(pcity, pimprove) { - building_removed(pcity, pimprove, "city_destroyed", NULL); + building_removed(pcity, pimprove, "city_destroyed", nullptr); if (is_small_wonder(pimprove)) { BV_SET(had_small_wonders, improvement_index(pimprove)); @@ -1725,7 +1727,7 @@ void remove_city(struct city *pcity) struct city *new_home_city = tile_city(unit_tile(punit)); if (new_home_city - && new_home_city != pcity + && new_home_city != pcity && city_owner(new_home_city) == powner && !punit->server.dying) { transfer_unit(punit, new_home_city, TRUE, TRUE); @@ -1753,12 +1755,13 @@ void remove_city(struct city *pcity) * native. See UTYF_COAST_STRICT */ ptrans = transporter_for_unit_at(punit, tile1); } else { - ptrans = NULL; + ptrans = nullptr; } if (action_auto_perf_unit_do(AAPC_CITY_GONE, punit, - tile_owner(tile1), NULL, NULL, + tile_owner(tile1), + nullptr, nullptr, tile1, tile_city(tile1), ptrans, - NULL) != NULL) { + nullptr) != nullptr) { moved = TRUE; } if (moved) { @@ -1780,7 +1783,7 @@ void remove_city(struct city *pcity) "get out, and it was therefore lost."), ctl, unit_tile_link(punit)); - wipe_unit(punit, ULR_CITY_LOST, NULL); + wipe_unit(punit, ULR_CITY_LOST, nullptr); } } unit_list_iterate_safe_end; @@ -1797,7 +1800,7 @@ void remove_city(struct city *pcity) continue; } other_city = tile_city(piter); - if (other_city != NULL) { + if (other_city != nullptr) { /* Adjacent tile has a city that may have been part of same channel */ dbv_set(&tile_processed, tile_index(piter)); tile_list_append(process_queue, piter); @@ -1814,7 +1817,7 @@ void remove_city(struct city *pcity) ctl, unit_tile_link(punit), city_link(other_city)); - wipe_unit(punit, ULR_CITY_LOST, NULL); + wipe_unit(punit, ULR_CITY_LOST, nullptr); } } unit_list_iterate_safe_end; } else { @@ -1833,7 +1836,7 @@ void remove_city(struct city *pcity) /* Any remaining supported units are destroyed */ unit_list_iterate_safe(pcity->units_supported, punit) { - wipe_unit(punit, ULR_CITY_LOST, NULL); + wipe_unit(punit, ULR_CITY_LOST, nullptr); } unit_list_iterate_safe_end; if (!city_exist(id)) { @@ -1856,18 +1859,17 @@ void remove_city(struct city *pcity) /* idex_unregister_city() is called in game_remove_city() below */ - /* identity_number_release(pcity->id) is *NOT* done! The cities may - still be alive in the client, or in the player map. The number of - removed cities is small, so the loss is acceptable. - */ + /* identity_number_release(pcity->id) is *NOT* done! The cities may + * still be alive in the client, or in the player map. The number of + * removed cities is small, so the loss is acceptable. */ old_vision = pcity->server.vision; - pcity->server.vision = NULL; + pcity->server.vision = nullptr; script_server_remove_exported_object(pcity); adv_city_free(pcity); /* Remove city from the map. */ - tile_set_worked(pcenter, NULL); + tile_set_worked(pcenter, nullptr); /* Reveal units. */ players_iterate(other_player) { @@ -1903,8 +1905,8 @@ void remove_city(struct city *pcity) } players_iterate_end; conn_list_iterate(game.est_connections, pconn) { - if (NULL == pconn->playing && pconn->observer) { - /* For detached observers we have to send a specific packet. This is + if (pconn->playing == nullptr && pconn->observer) { + /* For detached observers we have to send a specific packet. This is * a hack necessitated by the private map that exists for players but * not observers. */ dsend_packet_city_remove(pconn, id); @@ -1915,20 +1917,20 @@ void remove_city(struct city *pcity) vision_free(old_vision); /* Infrastructures may have changed. */ - send_tile_info(NULL, pcenter, FALSE); + send_tile_info(nullptr, pcenter, FALSE); /* Build a new palace for free if the player lost their capital and - savepalace is on. */ + * savepalace is on. */ build_free_small_wonders(powner, &had_small_wonders); /* Update wonder infos. */ if (had_great_wonders) { - send_game_info(NULL); + send_game_info(nullptr); /* No need to send to detached connections. */ - send_player_info_c(powner, NULL); + send_player_info_c(powner, nullptr); } else if (BV_ISSET_ANY(had_small_wonders)) { /* No need to send to detached connections. */ - send_player_info_c(powner, NULL); + send_player_info_c(powner, nullptr); } if (old_content_citizens != player_content_citizens(powner) @@ -1952,8 +1954,8 @@ void remove_city(struct city *pcity) during peace. At the moment this can happen to domestic, allied and team mate cities) - A unit can't conquer a city if it is owned by the animal barbarian. - - A unit can't conquer a city if its unit class is missing the - "CanOccupyCity" unit class flag. + - A unit can't conquer a city if its unit class is missing + the "CanOccupyCity" unit class flag. - A unit can't conquer a city if its unit type has the "NonMil" unit type flag. - Transported units trying to conquer a city should be unloaded before @@ -1974,7 +1976,7 @@ bool unit_conquer_city(struct unit *punit, struct city *pcity) fc_assert_ret_val_msg(pplayers_at_war(pplayer, cplayer), FALSE, "Can't conquer city during peace."); - /* If we cannot occupy the city, this unit entering will not trigger the + /* If we cannot occupy the city, this unit entering will not trigger * effects below. */ fc_assert_ret_val_msg(unit_can_take_over(punit) || utype_can_do_action(unit_type_get(punit), @@ -1987,22 +1989,21 @@ bool unit_conquer_city(struct unit *punit, struct city *pcity) /* A transported unit trying to conquer a city should already have been * unloaded. */ - fc_assert_ret_val_msg(punit->transporter == NULL, FALSE, + fc_assert_ret_val_msg(punit->transporter == nullptr, FALSE, "Can't conquer city while transported."); /* Okay, we're at war - invader captures/destroys city... */ - - /* If a capital is captured, then spark off a civil war - - Kris Bubendorfer - Also check spaceships --dwp - */ + + /* If a capital is captured, then spark off a civil war + * - Kris Bubendorfer + * Also check spaceships --dwp */ if (is_capital(pcity) && (cplayer->spaceship.state == SSHIP_STARTED || cplayer->spaceship.state == SSHIP_LAUNCHED)) { spaceship_lost(cplayer); } - + if (is_capital(pcity) && civil_war_possible(cplayer, TRUE, TRUE) && normal_player_count() < MAX_NUM_PLAYERS @@ -2010,7 +2011,7 @@ bool unit_conquer_city(struct unit *punit, struct city *pcity) try_civil_war = TRUE; } - /* + /* * We later remove a citizen. Lets check if we can save this since * the city will be destroyed. */ @@ -2021,7 +2022,7 @@ bool unit_conquer_city(struct unit *punit, struct city *pcity) _("You destroy %s completely."), city_tile_link(pcity)); notify_player(cplayer, city_tile(pcity), E_CITY_LOST, ftc_server, - _("%s has been destroyed by %s."), + _("%s has been destroyed by %s."), city_tile_link(pcity), player_name(pplayer)); script_server_signal_emit("city_destroyed", pcity, cplayer, pplayer); @@ -2047,54 +2048,54 @@ bool unit_conquer_city(struct unit *punit, struct city *pcity) if (pcity->original != pplayer) { if (coins > 0) { notify_player(pplayer, city_tile(pcity), E_UNIT_WIN_ATT, ftc_server, - PL_("You conquer %s; your lootings accumulate" - " to %d gold!", - "You conquer %s; your lootings accumulate" - " to %d gold!", coins), - city_link(pcity), - coins); + PL_("You conquer %s; your lootings accumulate" + " to %d gold!", + "You conquer %s; your lootings accumulate" + " to %d gold!", coins), + city_link(pcity), + coins); notify_player(cplayer, city_tile(pcity), E_CITY_LOST, ftc_server, - PL_("%s conquered %s and looted %d gold" - " from the city.", - "%s conquered %s and looted %d gold" - " from the city.", coins), - player_name(pplayer), - city_link(pcity), - coins); + PL_("%s conquered %s and looted %d gold" + " from the city.", + "%s conquered %s and looted %d gold" + " from the city.", coins), + player_name(pplayer), + city_link(pcity), + coins); } else { notify_player(pplayer, city_tile(pcity), E_UNIT_WIN_ATT, ftc_server, - _("You conquer %s."), - city_link(pcity)); + _("You conquer %s."), + city_link(pcity)); notify_player(cplayer, city_tile(pcity), E_CITY_LOST, ftc_server, - _("%s conquered %s."), - player_name(pplayer), - city_link(pcity)); + _("%s conquered %s."), + player_name(pplayer), + city_link(pcity)); } } else { if (coins > 0) { notify_player(pplayer, city_tile(pcity), E_UNIT_WIN_ATT, ftc_server, - PL_("You have liberated %s!" - " Lootings accumulate to %d gold.", - "You have liberated %s!" - " Lootings accumulate to %d gold.", coins), - city_link(pcity), - coins); + PL_("You have liberated %s!" + " Lootings accumulate to %d gold.", + "You have liberated %s!" + " Lootings accumulate to %d gold.", coins), + city_link(pcity), + coins); notify_player(cplayer, city_tile(pcity), E_CITY_LOST, ftc_server, - PL_("%s liberated %s and looted %d gold" - " from the city.", - "%s liberated %s and looted %d gold" - " from the city.", coins), - player_name(pplayer), - city_link(pcity), - coins); + PL_("%s liberated %s and looted %d gold" + " from the city.", + "%s liberated %s and looted %d gold" + " from the city.", coins), + player_name(pplayer), + city_link(pcity), + coins); } else { notify_player(pplayer, city_tile(pcity), E_UNIT_WIN_ATT, ftc_server, - _("You have liberated %s!"), - city_link(pcity)); + _("You have liberated %s!"), + city_link(pcity)); notify_player(cplayer, city_tile(pcity), E_CITY_LOST, ftc_server, - _("%s liberated %s."), - player_name(pplayer), - city_link(pcity)); + _("%s liberated %s."), + player_name(pplayer), + city_link(pcity)); } } @@ -2111,7 +2112,7 @@ bool unit_conquer_city(struct unit *punit, struct city *pcity) !is_barbarian(pplayer)); if (city_remains) { - /* reduce size should not destroy this city */ + /* Reduce size should not destroy this city */ fc_assert(city_size_get(pcity) > 1); city_reduce_size(pcity, 1, pplayer, "conquest"); } @@ -2162,7 +2163,7 @@ static void package_dumb_city(struct player *pplayer, struct tile *ptile, packet->owner = player_number(vision_site_owner(pdcity)); packet->tile = tile_index(ptile); - if (pdcity->name == NULL) { + if (pdcity->name == nullptr) { packet->name[0] = '\0'; } else { sz_strlcpy(packet->name, pdcity->name); @@ -2191,14 +2192,14 @@ void refresh_dumb_city(struct city *pcity) players_iterate(pplayer) { if (player_can_see_city_externals(pplayer, pcity)) { if (update_dumb_city(pplayer, pcity)) { - struct packet_city_short_info packet; - - if (city_owner(pcity) != pplayer) { - /* Don't send the short_city information to someone who can see the - * city's internals. Doing so would really confuse the client. */ - package_dumb_city(pplayer, pcity->tile, &packet); - lsend_packet_city_short_info(pplayer->connections, &packet); - } + struct packet_city_short_info packet; + + if (city_owner(pcity) != pplayer) { + /* Don't send the short_city information to someone who can see + * city's internals. Doing so would really confuse the client. */ + package_dumb_city(pplayer, pcity->tile, &packet); + lsend_packet_city_short_info(pplayer->connections, &packet); + } } } } players_iterate_end; @@ -2208,7 +2209,7 @@ void refresh_dumb_city(struct city *pcity) } /************************************************************************//** - Broadcast info about a city to all players who observe the tile. + Broadcast info about a city to all players who observe the tile. If the player can see the city we update the city info first. If not we just use the info from the players private map. See also comments to send_city_info_at_tile(). @@ -2240,7 +2241,7 @@ void broadcast_city_info(struct city *pcity) if (any_web_conns()) { webp_ptr = &web_packet; } else { - webp_ptr = NULL; + webp_ptr = nullptr; } routes = trade_route_packet_list_new(); @@ -2270,7 +2271,7 @@ void broadcast_city_info(struct city *pcity) } players_iterate_end; /* Send to global observers. */ - packet.original = city_original_owner(pcity, NULL); + packet.original = city_original_owner(pcity, nullptr); conn_list_iterate(game.est_connections, pconn) { if (conn_is_global_observer(pconn)) { send_packet_city_info(pconn, &packet, FALSE); @@ -2288,7 +2289,7 @@ void broadcast_city_info(struct city *pcity) /************************************************************************//** Send to each client information about the cities it knows about. - dest may not be NULL + dest may not be nullptr ****************************************************************************/ void send_all_known_cities(struct conn_list *dest) { @@ -2300,8 +2301,9 @@ void send_all_known_cities(struct conn_list *dest) continue; } whole_map_iterate(&(wld.map), ptile) { - if (!pplayer || NULL != map_get_player_site(ptile, pplayer)) { - send_city_info_at_tile(pplayer, pconn->self, NULL, ptile); + if (pplayer == nullptr + || map_get_player_site(ptile, pplayer) != nullptr) { + send_city_info_at_tile(pplayer, pconn->self, nullptr, ptile); } } whole_map_iterate_end; } @@ -2329,9 +2331,9 @@ void send_player_cities(struct player *pplayer) } /************************************************************************//** - A wrapper, accessing either broadcast_city_info() (dest == NULL), + A wrapper, accessing either broadcast_city_info() (dest == nullptr), or a convenience case of send_city_info_at_tile(). - Must specify non-NULL pcity. + Must specify non-nullptr pcity. ****************************************************************************/ void send_city_info(struct player *dest, struct city *pcity) { @@ -2361,7 +2363,7 @@ void send_city_info(struct player *dest, struct city *pcity) if (game.info.team_pooled_research && player_list_size(team_members(powner->team)) > 1) { /* We want to send the new total bulbs production of the team. */ - send_research_info(research_get(powner), NULL); + send_research_info(research_get(powner), nullptr); } } @@ -2370,20 +2372,20 @@ void send_city_info(struct player *dest, struct city *pcity) be pviewer->connections). If pplayer can see the city we update the city info first. If not we just use the info from the players private map. - If (pviewer == NULL) this is for observers, who see everything (?) - For this function dest may not be NULL. See send_city_info() and + If (pviewer == nullptr) this is for observers, who see everything (?) + For this function dest may not be nullptr. See send_city_info() and broadcast_city_info(). - If pcity is non-NULL it should be same as tile_city(x,y); if pcity - is NULL, this function calls tile_city(x,y) (it is ok if this - returns NULL). + If pcity is non-nullptr it should be same as tile_city(x, y); if pcity + is nullptr, this function calls tile_city(x, y) (it is ok if this + returns nullptr). - Sometimes a player's map contain a city that doesn't actually exist. Use - reality_check_city(pplayer, ptile) to update that. Remember to NOT send info - about a city to a player who thinks the tile contains another city. If you - want to update the clients info of the tile you must use - reality_check_city(pplayer, ptile) first. This is generally taken care of - automatically when a tile becomes visible. + Sometimes a player's map contain a city that doesn't actually exist. + Use reality_check_city(pplayer, ptile) to update that. Remember to + NOT send info about a city to a player who thinks the tile contains + another city. If you want to update the clients info of the tile you + must use reality_check_city(pplayer, ptile) first. This is generally + taken care of automatically when a tile becomes visible. ****************************************************************************/ void send_city_info_at_tile(struct player *pviewer, struct conn_list *dest, struct city *pcity, struct tile *ptile) @@ -2393,14 +2395,14 @@ void send_city_info_at_tile(struct player *pviewer, struct conn_list *dest, struct packet_city_rally_point rally_packet; struct packet_web_city_info_addition web_packet; struct packet_city_short_info sc_pack; - struct player *powner = NULL; - struct trade_route_packet_list *routes = NULL; + struct player *powner = nullptr; + struct trade_route_packet_list *routes = nullptr; struct packet_web_city_info_addition *webp_ptr; if (!pcity) { pcity = tile_city(ptile); } - if (pcity != NULL && pcity->server.needs_arrange != CNA_NOT) { + if (pcity != nullptr && pcity->server.needs_arrange != CNA_NOT) { pcity->server.needs_arrange = CNA_BROADCAST_PENDING; return; @@ -2412,15 +2414,15 @@ void send_city_info_at_tile(struct player *pviewer, struct conn_list *dest, if (any_web_conns()) { webp_ptr = &web_packet; } else { - webp_ptr = NULL; + webp_ptr = nullptr; } - if (powner != NULL && powner == pviewer) { + if (powner != nullptr && powner == pviewer) { /* Send info to owner */ - /* This case implies powner non-NULL which means pcity non-NULL */ + /* This case implies powner non-nullptr which means pcity non-nullptr */ if (!send_city_suppressed) { /* Wait that city has been rearranged, if it's currently - * not in sane state. */ + * not in a sane state. */ routes = trade_route_packet_list_new(); @@ -2438,7 +2440,7 @@ void send_city_info_at_tile(struct player *pviewer, struct conn_list *dest, } trade_route_packet_list_iterate_end; if (dest == powner->connections) { /* HACK: send also a copy to global observers. */ - packet.original = city_original_owner(pcity, NULL); + packet.original = city_original_owner(pcity, nullptr); conn_list_iterate(game.est_connections, pconn) { if (conn_is_global_observer(pconn)) { send_packet_city_info(pconn, &packet, FALSE); @@ -2450,8 +2452,8 @@ void send_city_info_at_tile(struct player *pviewer, struct conn_list *dest, } } } else { - /* send info to non-owner */ - if (!pviewer) { /* observer */ + /* Send info to non-owner */ + if (!pviewer) { /* Observer */ if (pcity) { routes = trade_route_packet_list_new(); @@ -2468,14 +2470,14 @@ void send_city_info_at_tile(struct player *pviewer, struct conn_list *dest, } } else { if (map_is_known_and_seen(ptile, pviewer, V_MAIN)) { - if (pcity) { /* it's there and we see it; update and send */ + if (pcity) { /* It's there and we see it; update and send */ update_dumb_city(pviewer, pcity); package_dumb_city(pviewer, ptile, &sc_pack); lsend_packet_city_short_info(dest, &sc_pack); } - } else { /* not seen; send old info */ + } else { /* Not seen; send old info */ if (map_is_known(ptile, pviewer) - && map_get_player_site(ptile, pviewer) != NULL) { + && map_get_player_site(ptile, pviewer) != nullptr) { package_dumb_city(pviewer, ptile, &sc_pack); lsend_packet_city_short_info(dest, &sc_pack); } @@ -2483,7 +2485,7 @@ void send_city_info_at_tile(struct player *pviewer, struct conn_list *dest, } } - if (routes != NULL) { + if (routes != nullptr) { trade_route_packet_list_iterate(routes, route_packet) { FC_FREE(route_packet); } trade_route_packet_list_iterate_end; @@ -2542,9 +2544,10 @@ void package_city(struct city *pcity, struct packet_city_info *packet, player_slots_iterate(pslot) { citizens nationality = citizens_nation_get(pcity, pslot); + if (nationality != 0) { /* This player should exist! */ - fc_assert(player_slot_get_player(pslot) != NULL); + fc_assert(player_slot_get_player(pslot) != nullptr); nat_packet->nation_id[nat_packet->nationalities_count] = player_slot_index(pslot); @@ -2574,8 +2577,8 @@ void package_city(struct city *pcity, struct packet_city_info *packet, } else { /* Note: If you get this error and try to debug the cause, you may find * using check_city_feelings() in some key points useful. */ - /* Have this as an fc_assert() first, so one can use '-F' to caught these in - * debugger. */ + /* Have this as an fc_assert() first, so one can use '-F' to caught + * these in debugger. */ fc_assert(packet->size == ppl); /* In all builds have an error message shown. */ @@ -2600,7 +2603,8 @@ void package_city(struct city *pcity, struct packet_city_info *packet, i = 0; trade_routes_iterate(pcity, proute) { - struct packet_trade_route_info *tri_packet = fc_malloc(sizeof(struct packet_trade_route_info)); + struct packet_trade_route_info *tri_packet + = fc_malloc(sizeof(struct packet_trade_route_info)); tri_packet->city = pcity->id; tri_packet->index = i; @@ -2677,7 +2681,7 @@ void package_city(struct city *pcity, struct packet_city_info *packet, } improvement_iterate_end; #ifdef FREECIV_WEB - if (web_packet != NULL) { + if (web_packet != nullptr) { struct tile *pcenter = city_tile(pcity); BV_CLR_ALL(web_packet->can_build_unit); @@ -2685,7 +2689,7 @@ void package_city(struct city *pcity, struct packet_city_info *packet, web_packet->id = pcity->id; - if (pcity->cm_parameter != NULL) { + if (pcity->cm_parameter != nullptr) { web_packet->cma_enabled = TRUE; cm_copy_parameter(&web_packet->cm_parameter, pcity->cm_parameter); } else { @@ -2725,18 +2729,18 @@ void package_city(struct city *pcity, struct packet_city_info *packet, contains a city, it must be the same city (avoid problems by always calling reality_check_city() first) - Returns TRUE iff anything has changed for the player city (i.e., if the - client needs to be updated with a *short* city packet). This information - is only used in refresh_dumb_city(); elsewhere the data is (of necessity) - broadcast regardless. + Returns TRUE iff anything has changed for the player city + (i.e., if the client needs to be updated with a *short* city packet). + This information is only used in refresh_dumb_city(); + elsewhere the data is (of necessity) broadcast regardless. ****************************************************************************/ bool update_dumb_city(struct player *pplayer, struct city *pcity) { bv_imprs improvements; struct tile *pcenter = city_tile(pcity); struct vision_site *pdcity = map_get_player_city(pcenter, pplayer); - /* pcity->client.occupied isn't used at the server, so we go straight to the - * unit list to check the occupied status. */ + /* pcity->client.occupied isn't used at the server, so we go straight to + * the unit list to check the occupied status. */ bool occupied = (unit_list_size(pcenter->units) > 0); int walls = city_citywalls_gfx(pcity); bool happy = city_happy(pcity); @@ -2756,7 +2760,7 @@ bool update_dumb_city(struct player *pplayer, struct city *pcity) } } improvement_iterate_end; - if (NULL == pdcity) { + if (pdcity == nullptr) { pdcity = vision_site_new_from_city(pcity); change_playertile_site(map_get_player_tile(pcenter, pplayer), pdcity); } else if (pdcity->location != pcenter) { @@ -2813,14 +2817,14 @@ void reality_check_city(struct player *pplayer, struct tile *ptile) dlsend_packet_city_remove(pplayer->connections, pdcity->identity); fc_assert_ret(playtile->site == pdcity); - playtile->site = NULL; + playtile->site = nullptr; vision_site_destroy(pdcity); } } } /************************************************************************//** - Removes a dumb city. Called when the vision changed to unknown. + Removes a dumb city. Called when the vision changed to unknown. ****************************************************************************/ void remove_dumb_city(struct player *pplayer, struct tile *ptile) { @@ -2831,7 +2835,7 @@ void remove_dumb_city(struct player *pplayer, struct tile *ptile) dlsend_packet_city_remove(pplayer->connections, pdcity->identity); fc_assert_ret(playtile->site == pdcity); - playtile->site = NULL; + playtile->site = nullptr; vision_site_destroy(pdcity); } } @@ -2894,27 +2898,28 @@ static void announce_trade_route_removal(struct city *pc1, struct city *pc2, source_gone should be TRUE if the reason for removal is the imminent removal of the source city (pc1) from the game. - Does not free the trade route structures, only removes them from the - cities. + Does not free the trade route structures, only removes them + from cities. ****************************************************************************/ -struct trade_route *remove_trade_route(struct city *pc1, struct trade_route *proute, +struct trade_route *remove_trade_route(struct city *pc1, + struct trade_route *proute, bool announce, bool source_gone) { struct city *pc2 = game_city_by_number(proute->partner); - struct trade_route *back_route = NULL; + struct trade_route *back_route = nullptr; - fc_assert_ret_val(pc1 && proute, NULL); + fc_assert_ret_val(pc1 && proute, nullptr); trade_route_list_remove(pc1->routes, proute); - if (pc2 != NULL) { + if (pc2 != nullptr) { trade_routes_iterate(pc2, pback) { if (pc1->id == pback->partner) { back_route = pback; } } trade_routes_iterate_end; - if (back_route != NULL) { + if (back_route != nullptr) { trade_route_list_remove(pc2->routes, back_route); } } @@ -2938,13 +2943,13 @@ bool city_illness_strike(struct city *pcity) ftc_server, _("%s has been struck by a plague! Population lost!"), city_link(pcity)); - if (city_reduce_size(pcity, 1, NULL, "plague")) { + if (city_reduce_size(pcity, 1, nullptr, "plague")) { pcity->turn_plague = game.info.turn; - /* recalculate illness */ - pcity->server.illness - = city_illness_calc(pcity, NULL, NULL, &(pcity->illness_trade), - NULL); + /* Recalculate illness */ + pcity->server.illness = city_illness_calc(pcity, nullptr, nullptr, + &(pcity->illness_trade), + nullptr); return TRUE; } @@ -2953,8 +2958,8 @@ bool city_illness_strike(struct city *pcity) } /************************************************************************//** - Sell the improvement from the city, and give the player the owner. Not - all buildings can be sold. + Sell the improvement from the city, and give the player the owner. + Not all buildings can be sold. I guess the player should always be the city owner? ****************************************************************************/ @@ -2963,7 +2968,7 @@ void do_sell_building(struct player *pplayer, struct city *pcity, { if (can_city_sell_building(pcity, pimprove)) { pplayer->economic.gold += impr_sell_gold(pimprove); - building_lost(pcity, pimprove, reason, NULL); + building_lost(pcity, pimprove, reason, nullptr); } } @@ -2972,7 +2977,7 @@ void do_sell_building(struct player *pplayer, struct city *pcity, moves it from a city it is in now, returns that city. If it is a wonder not present (never built or destroyed), returns pcity. If the wonder is great, also tells its owner. - If it is not a wonder (must be a regular improvement), returns NULL. + If it is not a wonder (must be a regular improvement), returns nullptr. It's up to the caller to update the necessary cities and emit signals. FIXME: If governmental center status of a city is changed, check if other cities of its owner need update. And what's there with trade partners? @@ -2983,9 +2988,10 @@ struct city *build_or_move_building(struct city *pcity, struct impr_type *pimprove, struct player **oldcity_owner) { - struct city *oldcity = NULL; + struct city *oldcity = nullptr; + + fc_assert_ret_val(!city_has_building(pcity, pimprove), nullptr); - fc_assert_ret_val(!city_has_building(pcity, pimprove), NULL); if (is_great_wonder(pimprove)) { if (!(oldcity = city_from_great_wonder(pimprove))) { oldcity = pcity; @@ -3026,7 +3032,7 @@ bool building_removed(struct city *pcity, const struct impr_type *pimprove, } /************************************************************************//** - Destroy the improvement in the city straight-out. Note that this is + Destroy the improvement in the city straight-out. Note that this is different from selling a building. ****************************************************************************/ void building_lost(struct city *pcity, const struct impr_type *pimprove, @@ -3035,24 +3041,24 @@ void building_lost(struct city *pcity, const struct impr_type *pimprove, struct player *owner = city_owner(pcity); bool was_capital = is_capital(pcity); bool city_remains; - + city_remains = building_removed(pcity, pimprove, reason, destroyer); if ((was_capital && (!city_remains || !is_capital(pcity))) && (owner->spaceship.state == SSHIP_STARTED - || owner->spaceship.state == SSHIP_LAUNCHED)) { + || owner->spaceship.state == SSHIP_LAUNCHED)) { /* If the capital was lost (by destruction of the palace) production on * the spaceship is lost. */ spaceship_lost(owner); } if (city_remains) { - /* update city; influence of effects (buildings, ...) on unit upkeep */ + /* Update city; influence of effects (buildings, ...) on unit upkeep */ if (city_refresh(pcity)) { auto_arrange_workers(pcity); } - /* Re-update the city's visible area. This updates fog if the vision + /* Re-update the city's visible area. This updates fog if the vision * range increases or decreases. */ city_refresh_vision(pcity); } @@ -3093,7 +3099,7 @@ void update_unit_upkeep(struct unit *punit, int free_uk[O_LAST]) if (update) { /* Update unit information to the player and global observers. */ - send_unit_info(NULL, punit); + send_unit_info(nullptr, punit); } } @@ -3158,10 +3164,10 @@ void change_build_target(struct player *pplayer, struct city *pcity, && event != E_IMP_AUTO && event != E_WORKLIST) { /* If the build target is changed because of an advisor's suggestion or - because the worklist advances, then the wonder was completed -- - don't announce that the player has *stopped* building that wonder. - */ - notify_player(NULL, city_tile(pcity), E_WONDER_STOPPED, ftc_server, + * because the worklist advances, then the wonder was completed -- + * don't announce that the player has *stopped* building that wonder. + */ + notify_player(nullptr, city_tile(pcity), E_WONDER_STOPPED, ftc_server, _("The %s have stopped building The %s in %s."), nation_plural_for_player(pplayer), city_production_name_translation(pcity), @@ -3214,7 +3220,7 @@ void change_build_target(struct player *pplayer, struct city *pcity, about it. */ if (VUT_IMPROVEMENT == pcity->production.kind && is_great_wonder(pcity->production.value.building)) { - notify_player(NULL, city_tile(pcity), E_WONDER_STARTED, ftc_server, + notify_player(nullptr, city_tile(pcity), E_WONDER_STARTED, ftc_server, _("The %s have started building The %s in %s."), nation_plural_for_player(pplayer), name, @@ -3229,8 +3235,8 @@ void change_build_target(struct player *pplayer, struct city *pcity, ****************************************************************************/ void city_map_update_empty(struct city *pcity, struct tile *ptile) { - tile_set_worked(ptile, NULL); - send_tile_info(NULL, ptile, FALSE); + tile_set_worked(ptile, nullptr); + send_tile_info(nullptr, ptile, FALSE); pcity->server.synced = FALSE; } @@ -3242,7 +3248,7 @@ void city_map_update_empty(struct city *pcity, struct tile *ptile) void city_map_update_worker(struct city *pcity, struct tile *ptile) { tile_set_worked(ptile, pcity); - send_tile_info(NULL, ptile, FALSE); + send_tile_info(nullptr, ptile, FALSE); pcity->server.synced = FALSE; } @@ -3255,21 +3261,21 @@ static bool city_map_update_tile_direct(struct tile *ptile, bool queued) { struct city *pwork = tile_worked(ptile); - if (NULL != pwork - && !is_free_worked(pwork, ptile) - && !city_can_work_tile(pwork, ptile)) { - tile_set_worked(ptile, NULL); - send_tile_info(NULL, ptile, FALSE); + if (pwork != nullptr + && !is_free_worked(pwork, ptile) + && !city_can_work_tile(pwork, ptile)) { + tile_set_worked(ptile, nullptr); + send_tile_info(nullptr, ptile, FALSE); - pwork->specialists[DEFAULT_SPECIALIST]++; /* keep city sanity */ + pwork->specialists[DEFAULT_SPECIALIST]++; /* Keep city sanity */ pwork->server.synced = FALSE; if (queued) { - city_freeze_workers_queue(pwork); /* place the displaced later */ + city_freeze_workers_queue(pwork); /* Place the displaced later */ } else { city_refresh(pwork); /* Specialist added, keep citizen count sanity */ auto_arrange_workers(pwork); - send_city_info(NULL, pwork); + send_city_info(nullptr, pwork); } return TRUE; } @@ -3279,8 +3285,8 @@ static bool city_map_update_tile_direct(struct tile *ptile, bool queued) /************************************************************************//** Updates the worked status of a tile. - Call city_thaw_workers_queue() followed by sync_cities() to send the - affected cities to the clients. + Call city_thaw_workers_queue() followed by sync_cities() + to send the affected cities to the clients. ****************************************************************************/ bool city_map_update_tile_frozen(struct tile *ptile) { @@ -3308,8 +3314,8 @@ void sync_cities(void) players_iterate(pplayer) { city_list_iterate(pplayer->cities, pcity) { if (!pcity->server.synced) { - /* sending will set to TRUE. */ - send_city_info(pplayer, pcity); + /* Sending will set to TRUE. */ + send_city_info(pplayer, pcity); } } city_list_iterate_end; } players_iterate_end; @@ -3324,7 +3330,7 @@ void city_map_update_all(struct city *pcity) city_tile_iterate_skip_free_worked(city_map_radius_sq_get(pcity), pcenter, ptile, _index, _x, _y) { - /* bypass city_map_update_tile_now() for efficiency */ + /* Bypass city_map_update_tile_now() for efficiency */ city_map_update_tile_direct(ptile, FALSE); } city_tile_iterate_skip_free_worked_end; } @@ -3343,12 +3349,12 @@ void city_map_update_all_cities_for_player(struct player *pplayer) /************************************************************************//** For each city adjacent to ptile, check all the buildings in the city. - Any which have unmet terrain requirements will be sold. This is called + Any which have unmet terrain requirements will be sold. This is called after any terrain changes (but this may be tied to the default ruleset). - FIXME: This function isn't very general. It would be better to check + FIXME: This function isn't very general. It would be better to check each turn to make sure all requirements of all buildings of all cities - are met, and sell any buildings that can't be supported. Terrains aren't + are met, and sell any buildings that can't be supported. Terrains aren't the only requirement that may disappear. ****************************************************************************/ void city_landlocked_sell_coastal_improvements(struct tile *ptile) @@ -3370,11 +3376,11 @@ void city_landlocked_sell_coastal_improvements(struct tile *ptile) continue; } - requirement_vector_iterate(&pimprove->reqs, preq) { - if ((VUT_TERRAIN == preq->source.kind + requirement_vector_iterate(&pimprove->reqs, preq) { + if ((VUT_TERRAIN == preq->source.kind || VUT_TERRAINCLASS == preq->source.kind || VUT_TERRFLAG == preq->source.kind) - && !is_req_active(&city_ctxt, NULL, preq, RPT_CERTAIN)) { + && !is_req_active(&city_ctxt, nullptr, preq, RPT_CERTAIN)) { int price = impr_sell_gold(pimprove); do_sell_building(pplayer, pcity, pimprove, "landlocked"); @@ -3385,8 +3391,8 @@ void city_landlocked_sell_coastal_improvements(struct tile *ptile) " for %d gold.", price), improvement_name_translation(pimprove), city_link(pcity), price); - } - } requirement_vector_iterate_end; + } + } requirement_vector_iterate_end; } city_built_iterate_end; } } adjc_iterate_end; @@ -3400,8 +3406,8 @@ void city_landlocked_sell_coastal_improvements(struct tile *ptile) ****************************************************************************/ void city_refresh_vision(struct city *pcity) { - v_radius_t vision_radius_sq = - V_RADIUS(get_city_bonus(pcity, EFT_CITY_VISION_RADIUS_SQ), 2, 2); + v_radius_t vision_radius_sq + = V_RADIUS(get_city_bonus(pcity, EFT_CITY_VISION_RADIUS_SQ), 2, 2); vision_change_sight(pcity->server.vision, vision_radius_sq); ASSERT_VISION(pcity->server.vision); @@ -3424,23 +3430,23 @@ void refresh_player_cities_vision(struct player *pplayer) bool city_map_update_radius_sq(struct city *pcity) { - fc_assert_ret_val(pcity != NULL, FALSE); + fc_assert_ret_val(pcity != nullptr, FALSE); int city_tiles_old, city_tiles_new; int city_radius_sq_old = city_map_radius_sq_get(pcity); int city_radius_sq_new = game.info.init_city_radius_sq + get_city_bonus(pcity, EFT_CITY_RADIUS_SQ); - /* check minimum / maximum allowed city radii */ + /* Check minimum / maximum allowed city radii */ city_radius_sq_new = CLIP(CITY_MAP_MIN_RADIUS_SQ, city_radius_sq_new, CITY_MAP_MAX_RADIUS_SQ); if (city_radius_sq_new == city_radius_sq_old) { - /* no change */ + /* No change */ return FALSE; } - /* get number of city tiles for each radii */ + /* Get number of city tiles for each radii */ city_tiles_old = city_map_tiles(city_radius_sq_old); city_tiles_new = city_map_tiles(city_radius_sq_new); @@ -3453,7 +3459,7 @@ bool city_map_update_radius_sq(struct city *pcity) log_debug("[%s (%d)] city_map_radius_sq: %d => %d", city_name_get(pcity), pcity->id, city_radius_sq_old, city_radius_sq_new); - /* workers map before */ + /* Workers map before */ log_debug("[%s (%d)] city size: %d; specialists: %d (before change)", city_name_get(pcity), pcity->id, city_size_get(pcity), city_specialists(pcity)); @@ -3462,13 +3468,13 @@ bool city_map_update_radius_sq(struct city *pcity) city_map_radius_sq_set(pcity, city_radius_sq_new); if (city_tiles_old < city_tiles_new) { - /* increased number of city tiles */ + /* Increased number of city tiles */ city_refresh_vision(pcity); } else { - /* reduced number of city tiles */ + /* Reduced number of city tiles */ int workers = 0; - /* remove workers from the tiles removed rom the city map */ + /* Remove workers from the tiles removed rom the city map */ city_map_iterate_radius_sq(city_radius_sq_new, city_radius_sq_old, city_x, city_y) { struct tile *ptile = city_map_to_tile(city_tile(pcity), @@ -3481,7 +3487,7 @@ bool city_map_update_radius_sq(struct city *pcity) } } city_map_iterate_radius_sq_end; - /* add workers to free city tiles */ + /* Add workers to free city tiles */ if (workers > 0) { int radius_sq = city_map_radius_sq_get(pcity); city_map_iterate_without_index(radius_sq, city_x, city_y) { @@ -3501,7 +3507,7 @@ bool city_map_update_radius_sq(struct city *pcity) } city_map_iterate_without_index_end; } - /* if there are still workers they will be updated to specialists */ + /* If there still are workers they will be updated to specialists */ if (workers > 0) { pcity->specialists[DEFAULT_SPECIALIST] += workers; } @@ -3509,7 +3515,7 @@ bool city_map_update_radius_sq(struct city *pcity) city_refresh_vision(pcity); } - /* if city is under AI control update it */ + /* If city is under AI control, update it */ adv_city_update(pcity); notify_player(city_owner(pcity), city_tile(pcity), E_CITY_RADIUS_SQ, @@ -3518,7 +3524,7 @@ bool city_map_update_radius_sq(struct city *pcity) city_tiles_old < city_tiles_new ? _("increased") : _("reduced")); - /* workers map after */ + /* Workers map after */ log_debug("[%s (%d)] city size: %d; specialists: %d (after change)", city_name_get(pcity), pcity->id, city_size_get(pcity), city_specialists(pcity)); @@ -3534,7 +3540,7 @@ void clear_worker_task(struct city *pcity, struct worker_task *ptask) { struct packet_worker_task packet; - if (ptask == NULL) { + if (ptask == nullptr) { return; } @@ -3574,7 +3580,7 @@ void package_and_send_worker_tasks(struct city *pcity) worker_task_list_iterate(pcity->task_reqs, ptask) { packet.tile_id = tile_index(ptask->ptile); packet.activity = ptask->act; - if (ptask->tgt == NULL) { + if (ptask->tgt == nullptr) { packet.tgt = -1; } else { packet.tgt = extra_number(ptask->tgt); @@ -3623,7 +3629,8 @@ void city_add_improvement_with_gov_notice(struct city *pcity, govs_data = create_current_governments_data_all(); city_add_improvement(pcity, pimprove); - fc_snprintf(buf, sizeof(buf), format, improvement_name_translation(pimprove)); + fc_snprintf(buf, sizeof(buf), format, + improvement_name_translation(pimprove)); players_iterate_alive(pplayer) { notify_new_government_options(pplayer, govs_data, buf); @@ -3637,18 +3644,18 @@ void city_add_improvement_with_gov_notice(struct city *pcity, /************************************************************************//** Return city's original owner id, as known by specified player. - NULL known_for is expected to mean global observer. + nullptr known_for is expected to mean global observer. ****************************************************************************/ int city_original_owner(const struct city *pcity, const struct player *known_for) { - if (pcity->original == NULL) { + if (pcity->original == nullptr) { /* Nobody knows */ return MAX_NUM_PLAYER_SLOTS; } if (pcity->original != known_for - || known_for == NULL) { + || known_for == nullptr) { /* Players know what they have built themselves, * global observer knows everything. */ return player_number(pcity->original); diff --git a/server/citytools.h b/server/citytools.h index 45c4e7a517..d2d90596f9 100644 --- a/server/citytools.h +++ b/server/citytools.h @@ -29,7 +29,7 @@ int build_points_left(struct city *pcity); -void transfer_city_units(struct player *pplayer, struct player *pvictim, +void transfer_city_units(struct player *pplayer, struct player *pvictim, struct unit_list *units, struct city *pcity, struct city *exclude_city, int kill_outside, bool verbose); @@ -41,7 +41,8 @@ struct city *find_closest_city(const struct tile *ptile, const struct player *pplayer, bool only_ocean, bool only_continent, bool only_known, bool only_player, - bool only_enemy, const struct unit_class *pclass); + bool only_enemy, + const struct unit_class *pclass); bool unit_conquer_city(struct unit *punit, struct city *pcity); bool send_city_suppression(bool now); @@ -79,9 +80,9 @@ bool city_illness_strike(struct city *pcity); void do_sell_building(struct player *pplayer, struct city *pcity, struct impr_type *pimprove, const char *reason); -struct city -*build_or_move_building(struct city *pcity, struct impr_type *pimprove, - struct player **oldcity_owner); +struct city *build_or_move_building(struct city *pcity, + struct impr_type *pimprove, + struct player **oldcity_owner); bool building_removed(struct city *pcity, const struct impr_type *pimprove, const char *reason, struct unit *destroyer); void building_lost(struct city *pcity, const struct impr_type *pimprove, @@ -104,7 +105,7 @@ void city_thaw_workers(struct city *pcity); void city_freeze_workers_queue(struct city *pcity); void city_thaw_workers_queue(void); -/* city map functions */ +/* City map functions */ void city_map_update_empty(struct city *pcity, struct tile *ptile); void city_map_update_worker(struct city *pcity, struct tile *ptile); -- 2.40.1