Freeciv21
Develop your civilization from humble roots to a global empire
citytools.cpp File Reference
#include <QBitArray>
#include "bitvector.h"
#include "fcintl.h"
#include "log.h"
#include "rand.h"
#include "shared.h"
#include "support.h"
#include "ai.h"
#include "citizens.h"
#include "city.h"
#include "culture.h"
#include "game.h"
#include "government.h"
#include "idex.h"
#include "improvement.h"
#include "map.h"
#include "movement.h"
#include "player.h"
#include "requirements.h"
#include "research.h"
#include "road.h"
#include "specialist.h"
#include "tech.h"
#include "traderoutes.h"
#include "unit.h"
#include "unitlist.h"
#include "vision.h"
#include "cm.h"
#include "luascript_types.h"
#include "barbarian.h"
#include "citizenshand.h"
#include "cityturn.h"
#include "gamehand.h"
#include "maphand.h"
#include "notify.h"
#include "plrhand.h"
#include "sanitycheck.h"
#include "sernet.h"
#include "spacerace.h"
#include "srv_main.h"
#include "techtools.h"
#include "unithand.h"
#include "unittools.h"
#include "advbuilding.h"
#include "advgoto.h"
#include "infracache.h"
#include "script_server.h"
#include "handicaps.h"
#include "citytools.h"
+ Include dependency graph for citytools.cpp:

Go to the source code of this file.

Functions

static bool city_workers_queue_remove (struct city *pcity)
 Remove a city from the queue for later calls to auto_arrange_workers(). More...
 
static void announce_trade_route_removal (struct city *pc1, struct city *pc2, bool source_gone)
 Announce to the owners of the cities that trade route has been canceled between them. More...
 
void city_freeze_workers (struct city *pcity)
 Freeze the workers (citizens on tiles) for the city. More...
 
void city_thaw_workers (struct city *pcity)
 Thaw (unfreeze) the workers (citizens on tiles) for the city. More...
 
void city_freeze_workers_queue (struct city *pcity)
 Queue pending auto_arrange_workers() for later. More...
 
void city_thaw_workers_queue ()
 Process the frozen workers. More...
 
static int evaluate_city_name_priority (struct tile *ptile, const struct nation_city *pncity, int default_priority)
 Returns the priority of the city name at the given position, using its own internal algorithm. More...
 
static bool is_default_city_name (const char *name, struct player *pplayer)
 Checks if a city name belongs to default city names of a particular player. More...
 
static const char * search_for_city_name (struct tile *ptile, const struct nation_city_list *default_cities, struct player *pplayer)
 Searches through a city name list (a struct nation_city array) to pick the best available city name, and returns a pointer to it. More...
 
bool is_allowed_city_name (struct player *pplayer, const char *cityname, char *error_buf, size_t bufsz)
 Checks, if a city name is allowed for a player. More...
 
const char * city_name_suggestion (struct player *pplayer, struct tile *ptile)
 Come up with a default name when a new city is about to be built. More...
 
int build_points_left (struct city *pcity)
 Calculate the remaining build points. More...
 
static void transfer_unit (struct unit *punit, struct city *tocity, bool rehome, bool verbose)
 Change player that owns a unit and, if appropriate, its home city, with verbose output. More...
 
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)
 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. More...
 
struct cityfind_closest_city (const struct tile *ptile, const struct city *pexclcity, const struct player *pplayer, bool only_ocean, bool only_continent, bool only_known, bool only_player, bool only_enemy, const struct unit_class *pclass)
 Find the city closest to 'ptile'. More...
 
static void raze_city (struct city *pcity)
 Called when a player conquers a city, remove buildings (not wonders and always palace) with game.server.razechance% chance, barbarians destroy more set the city's shield stock to 0. More...
 
static void reestablish_city_trade_routes (struct city *pcity)
 The following has to be called every time AFTER a city (pcity) has changed owner to update the city's trade routes. More...
 
static void build_free_small_wonders (struct player *pplayer, bv_imprs *had_small_wonders)
 Create saved small wonders in random cities. More...
 
bool transfer_city (struct player *ptaker, struct city *pcity, int kill_outside, bool transfer_unit_verbose, bool resolve_stack, bool raze, bool build_free)
 Handles all transactions in relation to transferring a city. More...
 
void city_build_free_buildings (struct city *pcity)
 Give to a new city the free (initial) buildings. More...
 
void create_city (struct player *pplayer, struct tile *ptile, const char *name, struct player *nationality)
 Creates real city. More...
 
void remove_city (struct city *pcity)
 Remove a city from the game. More...
 
bool unit_conquer_city (struct unit *punit, struct city *pcity)
 Handle unit conquering a city. More...
 
static int city_got_citywalls (const struct city *pcity)
 Which wall gfx city should display? More...
 
bool send_city_suppression (bool now)
 Suppress sending cities during game_load() and end_phase() More...
 
static void package_dumb_city (struct player *pplayer, struct tile *ptile, struct packet_city_short_info *packet)
 This fills out a package from a player's vision_site. More...
 
void refresh_dumb_city (struct city *pcity)
 Update plrtile information about the city, and send out information to the clients if it has changed. More...
 
static void broadcast_city_info (struct city *pcity)
 Broadcast info about a city to all players who observe the tile. More...
 
void send_all_known_cities (struct conn_list *dest)
 Send to each client information about the cities it knows about. More...
 
void send_player_cities (struct player *pplayer)
 Send information about all his/her cities to player. More...
 
void send_city_info (struct player *dest, struct city *pcity)
 A wrapper, accessing either broadcast_city_info() (dest == nullptr), or a convenience case of send_city_info_at_tile(). More...
 
void send_city_info_at_tile (struct player *pviewer, struct conn_list *dest, struct city *pcity, struct tile *ptile)
 Send info about a city, as seen by pviewer, to dest (usually dest will be pviewer->connections). More...
 
void package_city (struct city *pcity, struct packet_city_info *packet, struct traderoute_packet_list *routes, bool dipl_invest)
 Fill city info packet with information about given city. More...
 
bool update_dumb_city (struct player *pplayer, struct city *pcity)
 Updates a players knowledge about a city. More...
 
void reality_check_city (struct player *pplayer, struct tile *ptile)
 Removes outdated (nonexistant) cities from a player. More...
 
void remove_dumb_city (struct player *pplayer, struct tile *ptile)
 Removes a dumb city. More...
 
struct trade_routeremove_trade_route (struct city *pc1, struct trade_route *proute, bool announce, bool source_gone)
 Remove the trade route between pc1 and pc2 (if one exists). More...
 
void city_illness_strike (struct city *pcity)
 Give the city a plague. More...
 
void do_sell_building (struct player *pplayer, struct city *pcity, struct impr_type *pimprove, const char *reason)
 Sell the improvement from the city, and give the player the owner. More...
 
bool building_removed (struct city *pcity, const struct impr_type *pimprove, const char *reason, struct unit *destroyer)
 Remove building from the city. More...
 
void building_lost (struct city *pcity, const struct impr_type *pimprove, const char *reason, struct unit *destroyer)
 Destroy the improvement in the city straight-out. More...
 
void city_units_upkeep (const struct city *pcity)
 Recalculate the upkeep needed for all units supported by the city. More...
 
void change_build_target (struct player *pplayer, struct city *pcity, struct universal *target, enum event_type event)
 Change the build target. More...
 
void city_did_prod_change (struct city *pcity)
 City did something to change production. More...
 
void city_map_update_empty (struct city *pcity, struct tile *ptile)
 Change from worked to empty. More...
 
void city_map_update_worker (struct city *pcity, struct tile *ptile)
 Change from empty to worked. More...
 
static bool city_map_update_tile_direct (struct tile *ptile, bool queued)
 Updates the worked status of a tile. More...
 
bool city_map_update_tile_frozen (struct tile *ptile)
 Updates the worked status of a tile. More...
 
bool city_map_update_tile_now (struct tile *ptile)
 Updates the worked status of a tile immediately. More...
 
void sync_cities ()
 Make sure all players (clients) have up-to-date information about all their cities. More...
 
void city_map_update_all (struct city *pcity)
 Called by auto_arrange_workers() and below. More...
 
void city_map_update_all_cities_for_player (struct player *pplayer)
 Update worked map of all cities of given player. More...
 
void city_landlocked_sell_coastal_improvements (struct tile *ptile)
 For each city adjacent to ptile, check all the buildings in the city. More...
 
void city_refresh_vision (struct city *pcity)
 Refresh the city's vision. More...
 
void refresh_player_cities_vision (struct player *pplayer)
 Refresh the vision of all cities owned by a player, for empire-wide effects. More...
 
bool city_map_update_radius_sq (struct city *pcity)
 Updates the squared city radius. More...
 
void clear_worker_task (struct city *pcity, struct worker_task *ptask)
 Clear worker task from the city and inform owner. More...
 
void clear_worker_tasks (struct city *pcity)
 Clear all worker tasks from the city and inform owner. More...
 
void package_and_send_worker_tasks (struct city *pcity)
 Send city worker task to owner. More...
 
int city_production_buy_gold_cost (const struct city *pcity)
 Return the cost (gold) to buy the current city production. More...
 

Variables

static struct city_list * arrange_workers_queue = nullptr
 
static bool send_city_suppressed = false
 

Function Documentation

◆ announce_trade_route_removal()

static void announce_trade_route_removal ( struct city pc1,
struct city pc2,
bool  source_gone 
)
static

Announce to the owners of the cities that trade route has been canceled between them.

Definition at line 2737 of file citytools.cpp.

Referenced by reestablish_city_trade_routes(), and remove_trade_route().

◆ broadcast_city_info()

static void broadcast_city_info ( struct city pcity)
static

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(). (Split off from send_city_info_at_tile() because that was getting too difficult for me to understand... –dwp)

Definition at line 2194 of file citytools.cpp.

Referenced by send_city_info().

◆ build_free_small_wonders()

static void build_free_small_wonders ( struct player pplayer,
bv_imprs *  had_small_wonders 
)
static

Create saved small wonders in random cities.

Usually used to save the palace when the primary capital was conquered. Respects the 'savepalace' server setting.

Definition at line 1024 of file citytools.cpp.

Referenced by remove_city(), and transfer_city().

◆ build_points_left()

int build_points_left ( struct city pcity)

Calculate the remaining build points.

Definition at line 575 of file citytools.cpp.

Referenced by dai_choose_help_wonder(), and unit_do_help_build().

◆ building_lost()

void building_lost ( struct city pcity,
const struct impr_type pimprove,
const char *  reason,
struct unit destroyer 
)

Destroy the improvement in the city straight-out.

Note that this is different from selling a building.

Definition at line 2878 of file citytools.cpp.

Referenced by apply_disaster(), diplomat_sabotage(), do_sell_building(), and do_unit_strike_city_building().

◆ building_removed()

bool building_removed ( struct city pcity,
const struct impr_type pimprove,
const char *  reason,
struct unit destroyer 
)

Remove building from the city.

Emits lua signal.

Definition at line 2861 of file citytools.cpp.

Referenced by building_lost(), raze_city(), remove_city(), and transfer_city().

◆ change_build_target()

void change_build_target ( struct player pplayer,
struct city pcity,
struct universal target,
enum event_type  event 
)

Change the build target.

Definition at line 2986 of file citytools.cpp.

Referenced by advisor_choose_build(), dai_city_choose_build(), handle_city_change(), and worklist_change_build_target().

◆ city_build_free_buildings()

void city_build_free_buildings ( struct city pcity)

Give to a new city the free (initial) buildings.

Call this when a player has just acquired a city (or batch of cities, e.g. civil war) after having no cities. Doesn't check for building uniqueness! – assumes player has no other cities which might contain unique buildings.

Definition at line 1433 of file citytools.cpp.

Referenced by civil_war(), create_city(), and transfer_city().

◆ city_did_prod_change()

void city_did_prod_change ( struct city pcity)

City did something to change production.

Used to set action timestamps for new units.

Definition at line 3068 of file citytools.cpp.

Referenced by change_build_target(), really_handle_city_buy(), and transfer_city().

◆ city_freeze_workers()

void city_freeze_workers ( struct city pcity)

Freeze the workers (citizens on tiles) for the city.

They will not be auto-arranged until unfreeze_workers is called.

Long explanation:

Historically auto_arrange_workers was called every time a city changed. If the city grew or shrunk, a new tile became available or was removed, the function would be called. However in at least one place this breaks. In some operations (like transfer_city) multiple things may change and the city is not left in a sane state in between. Calling auto_arrange_workers after each change means it's called with an "insane" city. This can lead at best to a failed sanity check with a wasted call, or at worse to a more major bug. The solution is freeze_workers and thaw_workers.

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.

Freezing may safely be done more than once.

It is thus always safe to call freeze and thaw around any set of city actions. However this is unlikely to be needed in very many places.

Definition at line 118 of file citytools.cpp.

Referenced by auto_arrange_workers(), city_freeze_workers_queue(), city_map_update_all_cities_for_player(), sg_load_player_city(), and transfer_city().

◆ city_freeze_workers_queue()

void city_freeze_workers_queue ( struct city pcity)

Queue pending auto_arrange_workers() for later.

Definition at line 141 of file citytools.cpp.

Referenced by city_map_update_tile_direct(), create_city(), and resolve_city_emergency().

◆ city_got_citywalls()

static int city_got_citywalls ( const struct city pcity)
static

Which wall gfx city should display?

Definition at line 2117 of file citytools.cpp.

Referenced by package_city(), and update_dumb_city().

◆ city_illness_strike()

void city_illness_strike ( struct city pcity)

Give the city a plague.

Definition at line 2829 of file citytools.cpp.

Referenced by city_handle_plague_risk(), and spy_spread_plague().

◆ city_landlocked_sell_coastal_improvements()

void city_landlocked_sell_coastal_improvements ( struct tile ptile)

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 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 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 the only requirement that may disappear.

Definition at line 3210 of file citytools.cpp.

Referenced by fix_tile_on_terrain_change().

◆ city_map_update_all()

void city_map_update_all ( struct city pcity)

Called by auto_arrange_workers() and below.

Definition at line 3173 of file citytools.cpp.

Referenced by auto_arrange_workers(), and city_map_update_all_cities_for_player().

◆ city_map_update_all_cities_for_player()

void city_map_update_all_cities_for_player ( struct player pplayer)

Update worked map of all cities of given player.

Definition at line 3189 of file citytools.cpp.

Referenced by handle_diplomacy_accept_treaty_req(), handle_diplomacy_cancel_pact_explicit(), and update_diplomatics().

◆ city_map_update_empty()

void city_map_update_empty ( struct city pcity,
struct tile ptile 
)

Change from worked to empty.

city_x, city_y are city map coordinates. Call sync_cities() to send the affected cities to the clients.

Definition at line 3079 of file citytools.cpp.

Referenced by apply_cmresult_to_city(), city_map_update_radius_sq(), city_reduce_workers(), handle_city_make_specialist(), and resolve_city_emergency().

◆ city_map_update_radius_sq()

bool city_map_update_radius_sq ( struct city pcity)

Updates the squared city radius.

Returns if the radius is changed.

Definition at line 3286 of file citytools.cpp.

Referenced by city_refresh().

◆ city_map_update_tile_direct()

static bool city_map_update_tile_direct ( struct tile ptile,
bool  queued 
)
static

Updates the worked status of a tile.

If the status changes, auto_arrange_workers() may be called.

Definition at line 3103 of file citytools.cpp.

Referenced by city_map_update_all(), city_map_update_tile_frozen(), and city_map_update_tile_now().

◆ city_map_update_tile_frozen()

bool city_map_update_tile_frozen ( struct tile ptile)

Updates the worked status of a tile.

Call city_thaw_workers_queue() followed by sync_cities() to send the affected cities to the clients.

Definition at line 3133 of file citytools.cpp.

Referenced by map_claim_border_ownership(), and really_give_tile_info_from_player_to_player().

◆ city_map_update_tile_now()

bool city_map_update_tile_now ( struct tile ptile)

Updates the worked status of a tile immediately.

Definition at line 3141 of file citytools.cpp.

Referenced by create_unit_full(), server_remove_unit_full(), and unit_move_consequences().

◆ city_map_update_worker()

void city_map_update_worker ( struct city pcity,
struct tile ptile 
)

Change from empty to worked.

city_x, city_y are city map coordinates. Call sync_cities() to send the affected cities to the clients.

Definition at line 3091 of file citytools.cpp.

Referenced by apply_cmresult_to_city(), city_map_update_radius_sq(), and handle_city_make_worker().

◆ city_name_suggestion()

const char* city_name_suggestion ( struct player pplayer,
struct tile ptile 
)

Come up with a default name when a new city is about to be built.

Handle running out of names etc. gracefully. Maybe we should keeptrack of which names have been rejected by the player, so that we do not suggest them again?

Definition at line 451 of file citytools.cpp.

Referenced by api_edit_create_city(), dai_do_build_city(), execute_orders(), handle_city_name_suggestion_req(), handle_edit_city_create(), init_new_game(), and transfer_city().

◆ city_production_buy_gold_cost()

int city_production_buy_gold_cost ( const struct city pcity)

Return the cost (gold) to buy the current city production.

Definition at line 3459 of file citytools.cpp.

Referenced by dai_spend_gold(), package_city(), and really_handle_city_buy().

◆ city_refresh_vision()

void city_refresh_vision ( struct city pcity)

Refresh the city's vision.

This function has very small overhead and can be called any time effects may have changed the vision range of the city.

Definition at line 3261 of file citytools.cpp.

Referenced by building_lost(), city_build_building(), city_map_update_radius_sq(), create_city(), do_city_migration(), found_new_tech(), refresh_player_cities_vision(), sg_load_player_cities(), and transfer_city().

◆ city_thaw_workers()

void city_thaw_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 in freeze_workers().

Definition at line 128 of file citytools.cpp.

Referenced by auto_arrange_workers(), city_map_update_all_cities_for_player(), city_thaw_workers_queue(), sg_load_players(), and transfer_city().

◆ city_thaw_workers_queue()

◆ city_units_upkeep()

void city_units_upkeep ( const struct city pcity)

Recalculate the upkeep needed for all units supported by the city.

It has to be called

If the upkeep for a unit changes, an update is send to the player.

Definition at line 2927 of file citytools.cpp.

Referenced by city_refresh(), create_unit_full(), transform_unit(), unit_change_homecity_handling(), unit_change_owner(), and update_city_activities().

◆ city_workers_queue_remove()

static bool city_workers_queue_remove ( struct city pcity)
static

Remove a city from the queue for later calls to auto_arrange_workers().

Reterns TRUE if the city was found in the queue.

Definition at line 158 of file citytools.cpp.

Referenced by remove_city().

◆ clear_worker_task()

void clear_worker_task ( struct city pcity,
struct worker_task ptask 
)

Clear worker task from the city and inform owner.

Definition at line 3397 of file citytools.cpp.

Referenced by auto_settler_findwork(), and clear_worker_tasks().

◆ clear_worker_tasks()

void clear_worker_tasks ( struct city pcity)

Clear all worker tasks from the city and inform owner.

Definition at line 3423 of file citytools.cpp.

Referenced by dai_auto_settler_run(), dai_gained_control(), and transfer_city().

◆ create_city()

void create_city ( struct player pplayer,
struct tile ptile,
const char *  name,
struct player nationality 
)

Creates real city.

Definition at line 1512 of file citytools.cpp.

Referenced by api_edit_create_city(), city_build(), handle_edit_city_create(), and init_new_game().

◆ do_sell_building()

void do_sell_building ( struct player pplayer,
struct city pcity,
struct impr_type pimprove,
const char *  reason 
)

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?

Definition at line 2849 of file citytools.cpp.

Referenced by city_landlocked_sell_coastal_improvements(), dai_city_sell_noncritical(), really_handle_city_sell(), remove_obsolete_buildings_city(), and sell_random_building().

◆ evaluate_city_name_priority()

static int evaluate_city_name_priority ( struct tile ptile,
const struct nation_city pncity,
int  default_priority 
)
static

Returns the priority of the city name at the given position, using its 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 able to deal with any future options we want to add.

Definition at line 195 of file citytools.cpp.

Referenced by search_for_city_name().

◆ find_closest_city()

struct city* find_closest_city ( const struct tile ptile,
const struct city pexclcity,
const struct player pplayer,
bool  only_ocean,
bool  only_continent,
bool  only_known,
bool  only_player,
bool  only_enemy,
const struct unit_class pclass 
)

Find the city closest to 'ptile'.

Some restrictions can be applied:

'pexclcity' not this city 'pplayer' player to be used by 'only_known', 'only_player' and 'only_enemy'. 'only_ocean' if set the city must be adjacent to ocean. '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 nullptr only cities of this player are returned. '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 nullptr only cities that have adjacent native terrain for that unit class are returned.

If no city is found nullptr is returned.

Definition at line 849 of file citytools.cpp.

Referenced by dai_manage_diplomat(), dai_military_attack_barbarian(), dai_military_defend(), diplomat_escape_full(), disband_city(), do_city_migration(), handle_edit_unit_create(), try_summon_barbarians(), and try_to_save_unit().

◆ is_allowed_city_name()

bool is_allowed_city_name ( struct player pplayer,
const char *  cityname,
char *  error_buf,
size_t  bufsz 
)

Checks, if a city name is allowed for a player.

If not, reports a reason for rejection. There's 4 different modes: 0: no restrictions, 1: a city name has to be unique to player 2: a city name has to be globally unique 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 either nation.)

Definition at line 356 of file citytools.cpp.

Referenced by city_build(), handle_city_rename(), handle_edit_city(), and search_for_city_name().

◆ is_default_city_name()

static bool is_default_city_name ( const char *  name,
struct player pplayer 
)
static

Checks if a city name belongs to default city names of a particular player.

Definition at line 300 of file citytools.cpp.

Referenced by is_allowed_city_name().

◆ package_and_send_worker_tasks()

void package_and_send_worker_tasks ( struct city pcity)

Send city worker task to owner.

Definition at line 3433 of file citytools.cpp.

Referenced by send_all_info(), tai_req_worker_task_rcv(), and texai_req_worker_task_rcv().

◆ package_city()

void package_city ( struct city pcity,
struct packet_city_info *  packet,
struct traderoute_packet_list *  routes,
bool  dipl_invest 
)

Fill city info packet with information about given city.

Definition at line 2438 of file citytools.cpp.

Referenced by broadcast_city_info(), diplomat_investigate(), and send_city_info_at_tile().

◆ package_dumb_city()

static void package_dumb_city ( struct player pplayer,
struct tile ptile,
struct packet_city_short_info *  packet 
)
static

This fills out a package from a player's vision_site.

Definition at line 2138 of file citytools.cpp.

Referenced by broadcast_city_info(), refresh_dumb_city(), and send_city_info_at_tile().

◆ raze_city()

static void raze_city ( struct city pcity)
static

Called when a player conquers a city, remove buildings (not wonders and always palace) with game.server.razechance% chance, barbarians destroy more set the city's shield stock to 0.

Definition at line 929 of file citytools.cpp.

Referenced by transfer_city().

◆ reality_check_city()

void reality_check_city ( struct player pplayer,
struct tile ptile 
)

Removes outdated (nonexistant) cities from a player.

Definition at line 2704 of file citytools.cpp.

Referenced by broadcast_city_info(), do_unit_establish_trade(), map_change_seen(), map_show_tile(), reestablish_city_trade_routes(), remove_city(), and sg_load_player_vision().

◆ reestablish_city_trade_routes()

static void reestablish_city_trade_routes ( struct city pcity)
static

The following has to be called every time AFTER a city (pcity) has changed owner to update the city's trade routes.

Definition at line 965 of file citytools.cpp.

Referenced by transfer_city().

◆ refresh_dumb_city()

void refresh_dumb_city ( struct city pcity)

Update plrtile information about the city, and send out information to the clients if it has changed.

Definition at line 2163 of file citytools.cpp.

Referenced by unit_move().

◆ refresh_player_cities_vision()

void refresh_player_cities_vision ( struct player pplayer)

Refresh the vision of all cities owned by a player, for empire-wide effects.

Definition at line 3277 of file citytools.cpp.

Referenced by end_phase().

◆ remove_city()

void remove_city ( struct city pcity)

◆ remove_dumb_city()

void remove_dumb_city ( struct player pplayer,
struct tile ptile 
)

Removes a dumb city.

Called when the vision changed to unknown.

Definition at line 2722 of file citytools.cpp.

Referenced by map_hide_tile().

◆ remove_trade_route()

struct trade_route* remove_trade_route ( struct city pc1,
struct trade_route proute,
bool  announce,
bool  source_gone 
)

Remove the trade route between pc1 and pc2 (if one exists).

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.

Definition at line 2791 of file citytools.cpp.

Referenced by do_unit_establish_trade(), player_limit_to_max_rates(), reestablish_city_trade_routes(), remove_city(), and update_city_activities().

◆ search_for_city_name()

static const char* search_for_city_name ( struct tile ptile,
const struct nation_city_list *  default_cities,
struct player pplayer 
)
static

Searches through a city name list (a struct nation_city array) to pick 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, nullptr will be returned.

Definition at line 320 of file citytools.cpp.

Referenced by city_name_suggestion().

◆ send_all_known_cities()

void send_all_known_cities ( struct conn_list *  dest)

Send to each client information about the cities it knows about.

dest may not be nullptr

Definition at line 2248 of file citytools.cpp.

Referenced by send_all_info().

◆ send_city_info()

◆ send_city_info_at_tile()

void send_city_info_at_tile ( struct player pviewer,
struct conn_list *  dest,
struct city pcity,
struct tile ptile 
)

Send info about a city, as seen by pviewer, to dest (usually dest will 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 == 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-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.

Definition at line 2344 of file citytools.cpp.

Referenced by really_give_tile_info_from_player_to_player(), send_all_known_cities(), and send_city_info().

◆ send_city_suppression()

bool send_city_suppression ( bool  now)

Suppress sending cities during game_load() and end_phase()

Definition at line 2127 of file citytools.cpp.

Referenced by end_phase(), savegame2_load(), and savegame3_load().

◆ send_player_cities()

void send_player_cities ( struct player pplayer)

Send information about all his/her cities to player.

Definition at line 2274 of file citytools.cpp.

Referenced by begin_phase(), build_free_small_wonders(), and end_phase().

◆ sync_cities()

◆ transfer_city()

bool transfer_city ( struct player ptaker,
struct city pcity,
int  kill_outside,
bool  transfer_unit_verbose,
bool  resolve_stack,
bool  raze,
bool  build_free 
)

Handles all transactions in relation to transferring a city.

The kill_outside and transfer_unit_verbose arguments are passed to transfer_city_units(), which is called in the middle of the function.

Return TRUE iff the city remains after transfering (the city may be destroyed by a script, notably with bouncing or wiping units).

Definition at line 1084 of file citytools.cpp.

Referenced by civil_war(), diplomat_incite(), handle_diplomacy_accept_treaty_req(), kill_player(), kill_unit(), and unit_conquer_city().

◆ transfer_city_units()

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 
)

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 by the transferred city that are not in a city tile may be deleted.

pplayer: The player receiving the units if they are not disbanded and are not in a city pvictim: The owner of the city the units are transferred from. units: A list of units to be transferred, typically a city's unit list. pcity: Default city the units are transferred to. exclude_city: The units cannot be transferred to this city. kill_outside: Units outside this range are deleted. -1 means no units are deleted. verbose: Messages are sent to the involved parties.

Definition at line 708 of file citytools.cpp.

Referenced by disband_city(), do_city_migration(), and transfer_city().

◆ transfer_unit()

static void transfer_unit ( struct unit punit,
struct city tocity,
bool  rehome,
bool  verbose 
)
static

Change player that owns a unit and, if appropriate, its home city, with verbose output.

If 'rehome' is not set, only change the player which owns the unit (the new owner is new_pcity's owner). Otherwise the new unit will be given a homecity, even if it was homeless before.

Definition at line 589 of file citytools.cpp.

Referenced by remove_city(), and transfer_city_units().

◆ unit_conquer_city()

bool unit_conquer_city ( struct unit punit,
struct city pcity 
)

Handle unit conquering a city.

  • Can't conquer a city when not at war. (Enters cities peacefully 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 type has the "NonMil" unit type flag.
  • Transported units trying to conquer a city should be unloaded before this function is called.

Returns TRUE iff action could be done, FALSE if it couldn't. Even if this returns TRUE, unit may have died during the action.

Definition at line 1961 of file citytools.cpp.

Referenced by unit_move_consequences().

◆ update_dumb_city()

bool update_dumb_city ( struct player pplayer,
struct city pcity 
)

Updates a players knowledge about a city.

If the player_tile already 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_cities; elsewhere the data is (of necessity) broadcast regardless.

Definition at line 2637 of file citytools.cpp.

Referenced by broadcast_city_info(), diplomat_investigate(), map_show_tile(), reestablish_city_trade_routes(), refresh_dumb_city(), send_city_info_at_tile(), and sg_load_player_vision().

Variable Documentation

◆ arrange_workers_queue

struct city_list* arrange_workers_queue = nullptr
static

◆ send_city_suppressed

bool send_city_suppressed = false
static