Freeciv-3.3: /fast/freeciv/nightly/main/server/citytools.c File Reference

Freeciv-3.3

Loading...
Searching...
No Matches
Functions | Variables
citytools.c File Reference
`#include <stdio.h>`
`#include <stdlib.h>`
`#include <string.h>`
`#include "bitvector.h"`
`#include "fcintl.h"`
`#include "log.h"`
`#include "mem.h"`
`#include "rand.h"`
`#include "shared.h"`
`#include "support.h"`
`#include "ai.h"`
`#include "base.h"`
`#include "citizens.h"`
`#include "city.h"`
`#include "counters.h"`
`#include "culture.h"`
`#include "events.h"`
`#include "game.h"`
`#include "government.h"`
`#include "improvement.h"`
`#include "idex.h"`
`#include "map.h"`
`#include "movement.h"`
`#include "packets.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 "actiontools.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"`

Go to the source code of this file.

## Functions

static bool | city_workers_queue_remove (struct city *pcity)
static void | announce_trade_route_removal (struct city *pc1, struct city *pc2, bool source_gone) fc__attribute((nonnull(1
static void void | city_freeze_workers (struct city *pcity)
void | city_thaw_workers (struct city *pcity)
void | city_freeze_workers_queue (struct city *pcity)
void | city_thaw_workers_queue (void)
static int | evaluate_city_name_priority (struct tile *ptile, const struct nation_city *pncity, int default_priority)
static bool | is_default_city_name (const char *name, struct player *pplayer)
static const char * | search_for_city_name (struct tile *ptile, const struct nation_city_list *default_cities, struct player *pplayer)
bool | is_allowed_city_name (struct player *pplayer, const char *cityname, char *error_buf, size_t bufsz)
const char * | city_name_suggestion (struct player *pplayer, struct tile *ptile)
int | build_points_left (struct city *pcity)
static void | transfer_unit (struct unit *punit, struct city *tocity, bool rehome, bool verbose)
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)
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)
static void | raze_city (struct city *pcity)
static void | reestablish_city_trade_routes (struct city *pcity)
static void | build_free_small_wonders (struct player *pplayer, bv_imprs *had_small_wonders)
bool | transfer_city (struct player *ptaker, struct city *pcity, int kill_outside, bool transfer_unit_verbose, bool resolve_stack, bool raze, bool build_free)
void | city_build_free_buildings (struct city *pcity)
void | create_city (struct player *pplayer, struct tile *ptile, const char *name, struct player *nationality)
bool | create_city_for_player (struct player *pplayer, struct tile *ptile, const char *name)
void | remove_city (struct city *pcity)
bool | unit_conquer_city (struct unit *punit, struct city *pcity)
static int | city_citywalls_gfx (const struct city *pcity)
bool | send_city_suppression (bool now)
static void | package_dumb_city (struct player *pplayer, struct tile *ptile, struct packet_city_short_info *packet)
void | refresh_dumb_city (struct city *pcity)
void | broadcast_city_info (struct city *pcity)
void | send_all_known_cities (struct conn_list *dest)
void | send_player_cities (struct player *pplayer)
void | send_city_info (struct player *dest, struct city *pcity)
void | send_city_info_at_tile (struct player *pviewer, struct conn_list *dest, struct city *pcity, struct tile *ptile)
void | package_city (struct city *pcity, struct packet_city_info *packet, struct packet_city_nationalities *nat_packet, struct packet_city_rally_point *rally_packet, struct packet_web_city_info_addition *web_packet, struct trade_route_packet_list *routes, bool dipl_invest)
bool | update_dumb_city (struct player *pplayer, struct city *pcity)
void | reality_check_city (struct player *pplayer, struct tile *ptile)
void | remove_dumb_city (struct player *pplayer, struct tile *ptile)
struct trade_route * | remove_trade_route (struct city *pc1, struct trade_route *proute, bool announce, bool source_gone)
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)
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, const char *reason, struct unit *destroyer)
void | update_unit_upkeep (struct unit *punit, int free_uk[O_LAST])
void | city_units_upkeep (const struct city *pcity)
void | change_build_target (struct player *pplayer, struct city *pcity, struct universal *target, enum event_type event)
void | city_map_update_empty (struct city *pcity, struct tile *ptile)
void | city_map_update_worker (struct city *pcity, struct tile *ptile)
static bool | city_map_update_tile_direct (struct tile *ptile, bool queued)
bool | city_map_update_tile_frozen (struct tile *ptile)
bool | city_map_update_tile_now (struct tile *ptile)
void | sync_cities (void)
void | city_map_update_all (struct city *pcity)
void | city_map_update_all_cities_for_player (struct player *pplayer)
void | city_landlocked_sell_coastal_improvements (struct tile *ptile)
void | city_refresh_vision (struct city *pcity)
void | refresh_player_cities_vision (struct player *pplayer)
bool | city_map_update_radius_sq (struct city *pcity)
void | clear_worker_task (struct city *pcity, struct worker_task *ptask)
void | clear_worker_tasks (struct city *pcity)
void | package_and_send_worker_tasks (struct city *pcity)
int | city_production_buy_gold_cost (const struct city *pcity)
void | city_add_improvement_with_gov_notice (struct city *pcity, const struct impr_type *pimprove, const char *format)
int | city_original_owner (const struct city *pcity, const struct player *known_for)

## 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 2854 of file citytools.c.

Referenced by reestablish_city_trade_routes(), and remove_trade_route().

## ◆ broadcast_city_info()

void broadcast_city_info | ( | struct city * | pcity | ) |

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 2225 of file citytools.c.

Referenced by auto_arrange_workers(), and 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 1014 of file citytools.c.

Referenced by remove_city(), and transfer_city().

## ◆ build_or_move_building()

struct city * build_or_move_building | ( | struct city * | pcity,
|  | struct impr_type * | pimprove,
|  | struct player ** | oldcity_owner
| ) |  |

Creates an improvement in a city. If the improvement is a present wonder, 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 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? FIXME: it is not checked if the improvement is obsolete or obsoletes other building, should we?

Definition at line 2995 of file citytools.c.

Referenced by api_edit_create_building(), and handle_edit_city().

## ◆ build_points_left()

int build_points_left | ( | struct city * | pcity | ) |

Calculate the remaining build points

Definition at line 571 of file citytools.c.

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 3045 of file citytools.c.

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 3028 of file citytools.c.

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 3156 of file citytools.c.

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

## ◆ city_add_improvement_with_gov_notice()

void city_add_improvement_with_gov_notice | ( | struct city * | pcity,
|  | const struct impr_type * | pimprove,
|  | const char * | format
| ) |  |

Add improvement to the city, notifying all players about the new government forms it enables for them.

Definition at line 3638 of file citytools.c.

Referenced by build_or_move_building(), city_build_building(), city_build_free_buildings(), and transfer_city().

## ◆ 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 1429 of file citytools.c.

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

## ◆ city_citywalls_gfx()

static int city_citywalls_gfx | ( | const struct city * | pcity | ) |

static

Which wall gfx city should display?

Definition at line 2142 of file citytools.c.

Referenced by package_city(), and update_dumb_city().

## ◆ city_freeze_workers()

static void 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 136 of file citytools.c.

Referenced by auto_arrange_workers(), city_freeze_workers_queue(), city_map_update_all_cities_for_player(), sg_load_player_city(), 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 160 of file citytools.c.

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

## ◆ city_illness_strike()

bool city_illness_strike | ( | struct city * | pcity | ) |

Give the city a plague.

Definition at line 2947 of file citytools.c.

Referenced by spy_spread_plague(), and update_city_activity().

## ◆ 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 3372 of file citytools.c.

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 3338 of file citytools.c.

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 3353 of file citytools.c.

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

## ◆ city_map_update_empty()

void city_map_update_empty | ( | struct city * | pcity,
|  | struct tile * | ptile
| ) |  |

Change city tile from worked to empty. Call sync_cities() to send the affected cities to the clients.

Parameters

  pcity | City to change worker status
  ptile | Tile to clear worker from

Definition at line 3245 of file citytools.c.

Referenced by apply_cmresult_to_city(), city_map_update_radius_sq(), city_reduce_workers(), city_tc_effect_refresh(), handle_city_make_specialist(), handle_diplomacy_cancel_pact(), map_change_seen(), resolve_city_emergency(), and tile_change_side_effects().

## ◆ 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 3444 of file citytools.c.

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 3271 of file citytools.c.

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 3302 of file citytools.c.

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 3310 of file citytools.c.

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

## ◆ city_map_update_worker()

void city_map_update_worker | ( | struct city * | pcity,
|  | struct tile * | ptile
| ) |  |

Change city tile from empty to worked. Call sync_cities() to send the affected cities to the clients.

Parameters

  pcity | City to change worker status
  ptile | Tile to set worker to

Definition at line 3259 of file citytools.c.

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 453 of file citytools.c.

Referenced by api_edit_perform_action_unit_vs_tile(), api_edit_perform_action_unit_vs_tile_extra(), create_city_for_player(), dai_do_build_city(), execute_orders(), handle_city_name_suggestion_req(), init_new_game(), and transfer_city().

## ◆ city_original_owner()

int city_original_owner | ( | const struct city * | pcity,
|  | const struct player * | known_for
| ) |  |

Return city's original owner id, as known by specified player. nullptr known_for is expected to mean global observer.

Definition at line 3667 of file citytools.c.

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

## ◆ 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 3616 of file citytools.c.

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 3419 of file citytools.c.

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(), 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 146 of file citytools.c.

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

## ◆ city_thaw_workers_queue()

void city_thaw_workers_queue | ( | void |  | ) |

Process the frozen workers. Call sync_cities() to send the affected cities to the clients.

Definition at line 192 of file citytools.c.

Referenced by create_city(), end_phase(), give_citymap_from_player_to_player(), give_map_from_player_to_player(), give_seamap_from_player_to_player(), map_calculate_borders(), map_claim_base(), really_give_map_from_player_to_player(), remove_city(), resolve_city_emergency(), and transfer_city().

## ◆ 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 a save game is loaded (via city_refresh() in game_load_internal())
- if the number of units supported by a city changes create a unit (in create_unit_full()) bride a unit (in diplomat_bribe()) change homecity (in unit_change_homecity_handling()) destroy a unit (in wipe_unit())
- if the rules for the upkeep calculation change. This is due to effects which influence the upkeep calculation. tech researched, government change (via city_refresh()) building destroyed (in building_lost()) building created (via city_refresh() in in city_build_building())

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

Definition at line 3133 of file citytools.c.

Referenced by city_refresh(), place_unit(), 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 179 of file citytools.c.

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 3557 of file citytools.c.

Referenced by auto_worker_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 3582 of file citytools.c.

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 1514 of file citytools.c.

Referenced by city_build(), create_city_for_player(), and init_new_game().

## ◆ create_city_for_player()

bool create_city_for_player | ( | struct player * | pplayer,
|  | struct tile * | ptile,
|  | const char * | name
| ) |  |

Create city for player, doing necessary checks and adjustments.

Return whether it was legal to create the city. If not, city was not created.

Definition at line 1674 of file citytools.c.

Referenced by api_edit_create_city(), and handle_edit_city_create().

## ◆ 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 2973 of file citytools.c.

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 214 of file citytools.c.

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 851 of file citytools.c.

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 369 of file citytools.c.

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 315 of file citytools.c.

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 3592 of file citytools.c.

Referenced by send_all_info(), and texai_req_worker_task_rcv().

## ◆ package_city()

void package_city | ( | struct city * | pcity,
|  | struct packet_city_info * | packet,
|  | struct packet_city_nationalities * | nat_packet,
|  | struct packet_city_rally_point * | rally_packet,
|  | struct packet_web_city_info_addition * | web_packet,
|  | struct trade_route_packet_list * | routes,
|  | bool | dipl_invest
| ) |  |

Fill city info packet with information about given city. This can't set 'original', as it depends on who is about to receive the package whether they know true value of that.

Definition at line 2507 of file citytools.c.

Referenced by broadcast_city_info(), diplomat_investigate(), package_city(), 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 2163 of file citytools.c.

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 923 of file citytools.c.

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 2815 of file citytools.c.

Referenced by broadcast_city_info(), map_change_seen(), map_show_tile(), really_give_tile_info_from_player_to_player(), remove_city(), sg_load_player_vision(), 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 957 of file citytools.c.

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 2196 of file citytools.c.

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 3434 of file citytools.c.

Referenced by end_phase().

## ◆ remove_city()

void remove_city | ( | struct city * | pcity | ) |

Remove a city from the game.

Definition at line 1700 of file citytools.c.

Referenced by api_edit_remove_city(), city_reduce_size(), disband_city(), do_city_migration(), fc_interface_init_server(), handle_edit_city_remove(), kill_player(), unit_conquer_city(), and unit_do_destroy_city().

## ◆ 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 2836 of file citytools.c.

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 cities.

Definition at line 2911 of file citytools.c.

Referenced by do_unit_establish_trade(), reestablish_city_trade_routes(), remove_city(), server_remove_player(), 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 333 of file citytools.c.

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 2300 of file citytools.c.

Referenced by send_all_info().

## ◆ send_city_info()

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(). Must specify non-nullptr pcity.

Definition at line 2344 of file citytools.c.

Referenced by api_edit_create_building(), api_edit_remove_building(), build_free_small_wonders(), city_add_unit(), city_map_update_tile_direct(), city_refresh(), city_refresh_for_player(), city_refresh_queue_processing(), city_tc_effect_refresh(), create_city(), diplomat_sabotage(), do_airline(), do_nuke_tile(), do_unit_establish_trade(), do_unit_strike_city_building(), end_turn(), found_new_tech(), handle_city_change(), handle_city_change_specialist(), handle_city_options_req(), handle_city_rally_point(), handle_city_refresh(), handle_city_rename(), handle_city_worklist(), handle_edit_city(), handle_edit_city_create(), handle_web_cma_clear(), map_change_seen(), map_show_tile(), place_unit(), really_handle_city_buy(), really_handle_city_sell(), reestablish_city_trade_routes(), remove_allied_visibility(), remove_obsolete_buildings_city(), remove_trade_route(), research_tech_lost(), send_player_cities(), server_remove_unit_full(), spy_poison(), spy_spread_plague(), sync_cities(), tile_change_side_effects(), transfer_city(), unit_attack_civilian_casualties(), unit_change_homecity_handling(), unit_do_help_build(), unit_move_consequences(), and update_city_activity().

## ◆ 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 2396 of file citytools.c.

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 2152 of file citytools.c.

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

## ◆ send_player_cities()

void send_player_cities | ( | struct player * | pplayer | ) |

Send information about all their cities to player

Definition at line 2324 of file citytools.c.

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

## ◆ sync_cities()

void sync_cities | ( | void |  | ) |

Make sure all players (clients) have up-to-date information about all their cities.

Definition at line 3319 of file citytools.c.

Referenced by city_reduce_size(), city_refresh_after_city_size_increase(), create_city(), dai_manage_cities(), give_citymap_from_player_to_player(), give_map_from_player_to_player(), give_seamap_from_player_to_player(), handle_city_make_specialist(), handle_city_make_worker(), handle_diplomacy_accept_treaty_req(), handle_diplomacy_cancel_pact(), handle_web_cma_set(), place_unit(), really_give_map_from_player_to_player(), remove_city(), resolve_city_emergency(), server_remove_unit_full(), transfer_city(), unit_move_consequences(), and update_diplomatics().

## ◆ 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 transferring (the city may be destroyed by a script, notably with bouncing or wiping units).

Definition at line 1072 of file citytools.c.

Referenced by api_edit_transfer_city(), civil_war(), diplomat_incite(), handle_diplomacy_accept_treaty_req(), kill_player(), player_loot_player(), 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.

- Kris Bubendorfer Kris..nosp@m.Bube.nosp@m.ndorf.nosp@m.er@M.nosp@m.CS.VU.nosp@m.W.AC.nosp@m..NZ

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 716 of file citytools.c.

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 585 of file citytools.c.

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 1974 of file citytools.c.

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

Definition at line 2744 of file citytools.c.

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

## ◆ update_unit_upkeep()

void update_unit_upkeep | ( | struct unit * | punit,
|  | int | free_uk[O_LAST]
| ) |  |

Recalculate the upkeep needed for one unit.

Note that this modifies the free_uk array it gets, if the unit uses some of that free upkeep.

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

Definition at line 3082 of file citytools.c.

Referenced by city_units_upkeep().

## Variable Documentation

## ◆ arrange_workers_queue

struct city_list* arrange_workers_queue = nullptr

static

Definition at line 98 of file citytools.c.

Referenced by city_freeze_workers_queue(), city_thaw_workers_queue(), and city_workers_queue_remove().

## ◆ send_city_suppressed

bool send_city_suppressed = FALSE

static

Definition at line 101 of file citytools.c.

Referenced by broadcast_city_info(), send_city_info(), send_city_info_at_tile(), send_city_suppression(), and sync_cities().