Freeciv-3.3
Loading...
Searching...
No Matches
Data Structures | Macros | Functions | Variables
city.c File Reference
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "distribute.h"
#include "fcintl.h"
#include "log.h"
#include "mem.h"
#include "support.h"
#include "ai.h"
#include "citizens.h"
#include "counters.h"
#include "effects.h"
#include "game.h"
#include "government.h"
#include "improvement.h"
#include "map.h"
#include "movement.h"
#include "packets.h"
#include "specialist.h"
#include "traderoutes.h"
#include "unit.h"
#include "cm.h"
#include "city.h"

Go to the source code of this file.

Data Structures

struct  tile_cache
 

Macros

#define CITYLOG_MAX_VAL   9999 /* maximal value displayed in the citylog */
 
#define log_ca_s_init   log_debug
 

Functions

static charcitylog_map_line (int y, int city_radius_sq, int *city_map_data)
 
static void city_tile_cache_update (const struct civ_map *nmap, struct city *pcity)
 
static int city_tile_cache_get_output (const struct city *pcity, int city_tile_index, enum output_type_id o)
 
static const struct citynearest_gov_center (const struct city *pcity, int *min_dist) fc__attribute((nonnull(1
 
bool city_tile_index_to_xy (int *city_map_x, int *city_map_y, int city_tile_index, int city_radius_sq)
 
int city_tile_xy_to_index (int city_map_x, int city_map_y, int city_radius_sq)
 
int city_map_radius_sq_get (const struct city *pcity)
 
void city_map_radius_sq_set (struct city *pcity, int radius_sq)
 
int rs_max_city_radius_sq (void)
 
int city_map_tiles (int city_radius_sq)
 
bool is_valid_city_coords (const int city_radius_sq, const int city_map_x, const int city_map_y)
 
bool city_tile_to_city_map (int *city_map_x, int *city_map_y, const int city_radius_sq, const struct tile *city_center, const struct tile *map_tile)
 
bool city_base_to_city_map (int *city_map_x, int *city_map_y, const struct city *const pcity, const struct tile *map_tile)
 
bool city_map_includes_tile (const struct city *const pcity, const struct tile *map_tile)
 
struct tilecity_map_to_tile (const struct civ_map *nmap, const struct tile *city_center, int city_radius_sq, int city_map_x, int city_map_y)
 
static int cmp (int v1, int v2)
 
int compare_iter_index (const void *a, const void *b)
 
void citylog_map_data (enum log_level level, int radius_sq, int *map_data)
 
void citylog_map_workers (enum log_level level, struct city *pcity)
 
void generate_city_map_indices (void)
 
void free_city_map_index (void)
 
const charget_output_identifier (Output_type_id output)
 
const charget_output_name (Output_type_id output)
 
struct output_typeget_output_type (Output_type_id output)
 
Output_type_id output_type_by_identifier (const char *id)
 
const charcity_improvement_name_translation (const struct city *pcity, const struct impr_type *pimprove)
 
const charcity_production_name_translation (const struct city *pcity)
 
bool city_production_is_genus (const struct city *pcity, enum impr_genus_id genus)
 
bool city_production_has_flag (const struct city *pcity, enum impr_flag_id flag)
 
int city_production_build_shield_cost (const struct city *pcity)
 
bool city_production_build_units (const struct city *pcity, bool add_production, int *num_units)
 
int city_production_unit_veteran_level (struct city *pcity, const struct unit_type *punittype)
 
int city_production_turns_to_build (const struct city *pcity, bool include_shield_stock)
 
bool can_city_build_improvement_direct (const struct city *pcity, const struct impr_type *pimprove)
 
bool can_city_build_improvement_now (const struct city *pcity, const struct impr_type *pimprove)
 
bool can_city_build_improvement_later (const struct city *pcity, const struct impr_type *pimprove)
 
bool can_city_build_unit_direct (const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
 
bool can_city_build_unit_now (const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
 
bool can_city_build_unit_later (const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
 
bool can_city_build_direct (const struct civ_map *nmap, const struct city *pcity, const struct universal *target)
 
bool can_city_build_now (const struct civ_map *nmap, const struct city *pcity, const struct universal *target)
 
bool can_city_build_later (const struct civ_map *nmap, const struct city *pcity, const struct universal *target)
 
int city_unit_slots_available (const struct city *pcity)
 
bool city_can_use_specialist (const struct city *pcity, Specialist_type_id type)
 
bool city_can_change_build (const struct city *pcity)
 
void city_choose_build_default (const struct civ_map *nmap, struct city *pcity)
 
const charcity_name_get (const struct city *pcity)
 
void city_name_set (struct city *pcity, const char *new_name)
 
void city_size_add (struct city *pcity, int add)
 
void city_size_set (struct city *pcity, citizens size)
 
int city_population (const struct city *pcity)
 
int city_total_impr_gold_upkeep (const struct city *pcity)
 
int city_total_unit_gold_upkeep (const struct city *pcity)
 
bool city_has_building (const struct city *pcity, const struct impr_type *pimprove)
 
int city_improvement_upkeep (const struct city *pcity, const struct impr_type *b)
 
int city_tile_output (const struct city *pcity, const struct tile *ptile, bool is_celebrating, Output_type_id otype)
 
int city_tile_output_now (const struct city *pcity, const struct tile *ptile, Output_type_id otype)
 
bool base_city_can_work_tile (const struct player *restriction, const struct city *pcity, const struct tile *ptile)
 
bool city_can_work_tile (const struct city *pcity, const struct tile *ptile)
 
bool citymindist_prevents_city_on_tile (const struct civ_map *nmap, const struct tile *ptile)
 
bool city_can_be_built_here (const struct civ_map *nmap, const struct tile *ptile, const struct unit *punit, bool hut_test)
 
bool city_can_be_built_tile_only (const struct civ_map *nmap, const struct tile *ptile)
 
bool is_capital (const struct city *pcity)
 
bool is_gov_center (const struct city *pcity)
 
bool city_got_defense_effect (const struct city *pcity, const struct unit_type *attacker)
 
bool city_happy (const struct city *pcity)
 
bool city_unhappy (const struct city *pcity)
 
bool base_city_celebrating (const struct city *pcity)
 
bool city_celebrating (const struct city *pcity)
 
bool city_rapture_grow (const struct city *pcity)
 
bool city_is_occupied (const struct city *pcity)
 
struct citycity_list_find_number (struct city_list *This, int id)
 
struct citycity_list_find_name (struct city_list *This, const char *name)
 
int city_name_compare (const void *p1, const void *p2)
 
int city_style_by_translated_name (const char *s)
 
int city_style_by_rule_name (const char *s)
 
const charcity_style_name_translation (const int style)
 
const charcity_style_rule_name (const int style)
 
void city_production_caravan_shields_init (void)
 
bool city_production_gets_caravan_shields (const struct universal *tgt)
 
int city_change_production_penalty (const struct city *pcity, const struct universal *target)
 
int city_turns_to_build (const struct city *pcity, const struct universal *target, bool include_shield_stock)
 
int city_turns_to_grow (const struct city *pcity)
 
bool city_can_grow_to (const struct city *pcity, int pop_size)
 
struct citytile_enemy_city (const struct tile *ptile, const struct player *pplayer)
 
struct citytile_allied_city (const struct tile *ptile, const struct player *pplayer)
 
struct citytile_non_attack_city (const struct tile *ptile, const struct player *pplayer)
 
struct citytile_non_allied_city (const struct tile *ptile, const struct player *pplayer)
 
bool is_unit_near_a_friendly_city (const struct civ_map *nmap, const struct unit *punit, int distance)
 
bool is_friendly_city_near (const struct civ_map *nmap, const struct player *owner, const struct tile *ptile, int distance)
 
bool city_exists_within_max_city_map (const struct civ_map *nmap, const struct tile *ptile, bool may_be_on_center)
 
int city_granary_size (int city_size)
 
static int player_base_citizen_happiness (const struct player *pplayer)
 
citizens player_content_citizens (const struct player *pplayer)
 
citizens player_angry_citizens (const struct player *pplayer)
 
int get_final_city_output_bonus (const struct city *pcity, Output_type_id otype)
 
int get_city_tithes_bonus (const struct city *pcity)
 
void add_tax_income (const struct player *pplayer, int trade, int *output)
 
bool city_built_last_turn (const struct city *pcity)
 
static void get_worked_tile_output (const struct civ_map *nmap, const struct city *pcity, int *output, bool *workers_map)
 
void add_specialist_output (const struct city *pcity, int *output)
 
static void set_city_bonuses (struct city *pcity)
 
static void set_surpluses (struct city *pcity)
 
static void happy_copy (struct city *pcity, enum citizen_feeling i)
 
static void citizen_base_mood (struct city *pcity)
 
static void citizen_luxury_happy (struct city *pcity, int *luxuries)
 
static void citizen_happy_luxury (struct city *pcity)
 
static void citizen_content_buildings (struct city *pcity)
 
static void citizen_happiness_nationality (struct city *pcity)
 
static void citizen_happy_units (struct city *pcity)
 
static void citizen_happy_wonders (struct city *pcity)
 
static void unhappy_city_check (struct city *pcity)
 
int city_pollution_types (const struct city *pcity, int shield_total, int *pollu_prod, int *pollu_pop, int *pollu_mod)
 
int city_pollution (const struct city *pcity, int shield_total)
 
static int get_trade_illness (const struct city *pcity)
 
static int get_city_health (const struct city *pcity)
 
int city_illness_calc (const struct city *pcity, int *ill_base, int *ill_size, int *ill_trade, int *ill_pollution)
 
bool city_had_recent_plague (const struct city *pcity)
 
int city_build_slots (const struct city *pcity)
 
int city_airlift_max (const struct city *pcity)
 
void set_city_production (struct city *pcity)
 
int city_unit_unhappiness (const struct civ_map *nmap, struct unit *punit, int *free_unhappy)
 
static void city_support (const struct civ_map *nmap, struct city *pcity)
 
void city_refresh_from_main_map (const struct civ_map *nmap, struct city *pcity, bool *workers_map)
 
int city_waste (const struct city *pcity, Output_type_id otype, int total, int *breakdown)
 
citizens city_specialists (const struct city *pcity)
 
Specialist_type_id best_specialist (Output_type_id otype, const struct city *pcity)
 
void city_add_improvement (struct city *pcity, const struct impr_type *pimprove)
 
void city_remove_improvement (struct city *pcity, const struct impr_type *pimprove)
 
bool is_city_option_set (const struct city *pcity, enum city_options option)
 
void city_styles_alloc (int num)
 
void city_styles_free (void)
 
struct citycreate_city_virtual (struct player *pplayer, struct tile *ptile, const char *name)
 
void destroy_city_virtual (struct city *pcity)
 
bool city_exist (int id)
 
bool city_is_virtual (const struct city *pcity)
 
bool is_free_worked (const struct city *pcity, const struct tile *ptile)
 
voidcity_ai_data (const struct city *pcity, const struct ai_type *ai)
 
void city_set_ai_data (struct city *pcity, const struct ai_type *ai, void *data)
 
void city_rally_point_clear (struct city *pcity)
 
void city_rally_point_receive (const struct packet_city_rally_point *packet, struct city *pcity)
 

Variables

static struct iter_indexcity_map_index = NULL
 
static int city_map_xy [CITY_MAP_MAX_SIZE][CITY_MAP_MAX_SIZE]
 
static int city_map_numtiles [CITY_MAP_MAX_RADIUS_SQ+1]
 
static const struct city struct citystylecity_styles = NULL
 
struct output_type output_types [O_LAST]
 
static bv_imprs caravan_helped_impr
 
static bv_unit_types caravan_helped_utype
 

Macro Definition Documentation

◆ CITYLOG_MAX_VAL

#define CITYLOG_MAX_VAL   9999 /* maximal value displayed in the citylog */

Return one line (y coordinate) of a city map. *city_map_data is a pointer to an array containing the data which should be printed. Its size is defined by city_map_tiles(city_radius_sq).

Definition at line 368 of file city.c.

◆ log_ca_s_init

#define log_ca_s_init   log_debug

Function Documentation

◆ add_specialist_output()

void add_specialist_output ( const struct city pcity,
int output 
)

Calculate output (gold, science, and luxury) generated by the specialists of a city. The output[] array is not cleared but is just added to.

Definition at line 2364 of file city.c.

Referenced by city_refresh_from_main_map(), and dai_city_want().

◆ add_tax_income()

void add_tax_income ( const struct player pplayer,
int  trade,
int output 
)

Add the incomes of a city according to the taxrates (ignore # of specialists). trade should be in output[O_TRADE].

Definition at line 2245 of file city.c.

Referenced by dai_city_want(), get_city_dialog_output_text(), and set_city_production().

◆ base_city_can_work_tile()

bool base_city_can_work_tile ( const struct player restriction,
const struct city pcity,
const struct tile ptile 
)

Returns TRUE when a tile is available to be worked, or the city itself is currently working the tile (and can continue).

The parameter 'restriction', which is usually client_player(), allow a player to handle with its real knownledge to guess it the work of this tile is possible.

This function shouldn't be called directly, but with city_can_work_tile() (common/city.[ch]) or client_city_can_work_tile() (client/climap.[ch]).

Definition at line 1401 of file city.c.

Referenced by city_can_work_tile(), and client_city_can_work_tile().

◆ base_city_celebrating()

bool base_city_celebrating ( const struct city pcity)

Return TRUE if the city was celebrating at the start of the turn, and it still has sufficient size to be in rapture.

Definition at line 1637 of file city.c.

Referenced by city_celebrating(), city_tile_cache_update(), compute_max_stats_heuristic(), compute_tile_production(), dai_city_want(), fill_city_overlays_sprite_array(), get_worked_tile_output(), max_tile_trade(), and min_food_surplus_for_fastest_growth().

◆ best_specialist()

Specialist_type_id best_specialist ( Output_type_id  otype,
const struct city pcity 
)

Return the "best" specialist available in the game. This specialist will have the most of the given type of output. If pcity is given then only specialists usable by pcity will be considered.

Definition at line 3359 of file city.c.

Referenced by city_increase_size().

◆ can_city_build_direct()

bool can_city_build_direct ( const struct civ_map nmap,
const struct city pcity,
const struct universal target 
)

Returns whether city can immediately build given target, unit or improvement. This considers obsolete targets still buildable.

Definition at line 994 of file city.c.

Referenced by base_city_queue_insert().

◆ can_city_build_improvement_direct()

bool can_city_build_improvement_direct ( const struct city pcity,
const struct impr_type pimprove 
)

Return whether given city can build given building, ignoring whether it is obsolete.

Definition at line 830 of file city.c.

Referenced by building_upgrades_to(), can_city_build_direct(), can_city_build_improvement_now(), and city_choose_build_default().

◆ can_city_build_improvement_later()

bool can_city_build_improvement_later ( const struct city pcity,
const struct impr_type pimprove 
)

Return whether player can eventually build given building in the city; returns FALSE if improvement can never possibly be built in this city.

Definition at line 871 of file city.c.

Referenced by ba_human_wants(), can_city_build_later(), collect_eventually_buildable_targets(), popup_worklist_editor(), and worklist_change_build_target().

◆ can_city_build_improvement_now()

bool can_city_build_improvement_now ( const struct city pcity,
const struct impr_type pimprove 
)

◆ can_city_build_later()

bool can_city_build_later ( const struct civ_map nmap,
const struct city pcity,
const struct universal target 
)

Returns whether city can ever build given target, unit or improvement.

Definition at line 1031 of file city.c.

Referenced by add_global_worklist(), base_city_queue_insert(), and set_global_worklist().

◆ can_city_build_now()

bool can_city_build_now ( const struct civ_map nmap,
const struct city pcity,
const struct universal target 
)

Returns whether city can immediately build given target, unit or improvement. This considers obsolete targets no longer buildable.

Definition at line 1013 of file city.c.

Referenced by can_city_build_now_client(), city_dialog::change_production(), city_dialog_update_building(), city_worklist_commit(), client_change_all(), clipboard_send_production_packet(), city_widget::display_list_menu(), handle_city_change(), city_production_model::populate(), transfer_city(), and worklist_change_build_target().

◆ can_city_build_unit_direct()

bool can_city_build_unit_direct ( const struct civ_map nmap,
const struct city pcity,
const struct unit_type punittype 
)

Return whether given city can build given unit, ignoring whether unit is obsolete.

Definition at line 903 of file city.c.

Referenced by can_city_build_direct(), can_city_build_unit_now(), city_build_unit(), city_choose_build_default(), city_gold_worth(), process_attacker_want(), unit_upgrades_to(), and upgrade_unit_prod().

◆ can_city_build_unit_later()

bool can_city_build_unit_later ( const struct civ_map nmap,
const struct city pcity,
const struct unit_type punittype 
)

Returns whether player can eventually build given unit in the city; returns FALSE if unit can never possibly be built in this city.

Definition at line 970 of file city.c.

Referenced by can_city_build_later(), collect_eventually_buildable_targets(), dai_process_defender_want(), dai_wants_defender_against(), dai_wants_role_unit(), popup_worklist_editor(), and worklist_change_build_target().

◆ can_city_build_unit_now()

bool can_city_build_unit_now ( const struct civ_map nmap,
const struct city pcity,
const struct unit_type punittype 
)

◆ citizen_base_mood()

static void citizen_base_mood ( struct city pcity)
static

Create content, unhappy and angry citizens.

Definition at line 2505 of file city.c.

Referenced by city_refresh_from_main_map().

◆ citizen_content_buildings()

static void citizen_content_buildings ( struct city pcity)
inlinestatic

Make citizens content due to city improvements.

Definition at line 2591 of file city.c.

Referenced by city_refresh_from_main_map().

◆ citizen_happiness_nationality()

static void citizen_happiness_nationality ( struct city pcity)
inlinestatic

Apply effects of citizen nationality to happiness

Definition at line 2615 of file city.c.

Referenced by city_refresh_from_main_map().

◆ citizen_happy_luxury()

static void citizen_happy_luxury ( struct city pcity)
inlinestatic

Make citizens happy due to luxury.

Definition at line 2581 of file city.c.

Referenced by city_refresh_from_main_map().

◆ citizen_happy_units()

static void citizen_happy_units ( struct city pcity)
inlinestatic

Make citizens happy/unhappy due to units.

This function requires that pcity->martial_law and pcity->unit_happy_cost have already been set in city_support().

Definition at line 2664 of file city.c.

Referenced by city_refresh_from_main_map().

◆ citizen_happy_wonders()

static void citizen_happy_wonders ( struct city pcity)
inlinestatic

Make citizens happy due to wonders.

Definition at line 2712 of file city.c.

Referenced by city_refresh_from_main_map().

◆ citizen_luxury_happy()

static void citizen_luxury_happy ( struct city pcity,
int luxuries 
)
inlinestatic

Make people happy: angry citizen are eliminated first then content are made happy, then unhappy content, etc. each conversions costs 2 or 4 luxuries.

Definition at line 2544 of file city.c.

Referenced by citizen_happy_luxury().

◆ city_add_improvement()

void city_add_improvement ( struct city pcity,
const struct impr_type pimprove 
)

◆ city_ai_data()

void * city_ai_data ( const struct city pcity,
const struct ai_type ai 
)

Return pointer to ai data of given city and ai type.

Definition at line 3634 of file city.c.

Referenced by def_ai_city_data(), and texai_city_data().

◆ city_airlift_max()

int city_airlift_max ( const struct city pcity)

A city's maximum airlift capacity. (Note, this still returns a finite number even if airliftingstyle allows unlimited airlifts)

Definition at line 2942 of file city.c.

Referenced by get_airlift_text(), and update_city_activity().

◆ city_base_to_city_map()

bool city_base_to_city_map ( int city_map_x,
int city_map_y,
const struct city *const  pcity,
const struct tile map_tile 
)

Finds the city map coordinate for a given map position and a city. Returns whether the map position is inside of the city map.

Definition at line 281 of file city.c.

Referenced by adjust_workers_button_pressed(), base_city_can_work_tile(), city_map_includes_tile(), fill_city_overlays_sprite_array(), fill_grid_sprite_array(), fill_sprite_array(), and resolve_city_emergency().

◆ city_build_slots()

int city_build_slots ( const struct city pcity)

The maximum number of units a city can build per turn.

Definition at line 2932 of file city.c.

Referenced by city_dialog_update_building(), city_production_build_units(), city_production_cost_str(), and cr_entry_build_slots().

◆ city_built_last_turn()

bool city_built_last_turn ( const struct city pcity)

Return TRUE if the city built something last turn (meaning production was completed between last turn and this).

Definition at line 2279 of file city.c.

Referenced by city_change_production_penalty(), dai_city_choose_build(), and should_force_recalc().

◆ city_can_be_built_here()

bool city_can_be_built_here ( const struct civ_map nmap,
const struct tile ptile,
const struct unit punit,
bool  hut_test 
)

Returns TRUE if the given unit can build a city at the given map coordinates.

punit is the founding unit. It may be NULL if a city is built out of the blue (e.g., through editing).

Definition at line 1487 of file city.c.

Referenced by api_methods_unit_city_can_be_built_here(), city_desirability(), create_city_for_player(), dai_auto_settler_run(), find_city_or_settler_near_tile(), property_page_create_objects(), and unit_drawn_with_city_outline().

◆ city_can_be_built_tile_only()

bool city_can_be_built_tile_only ( const struct civ_map nmap,
const struct tile ptile 
)

Returns TRUE if the given unit can build a city at the given map coordinates.

It may still be illegal for any unit to build a city at the specified tile.

Definition at line 1560 of file city.c.

Referenced by city_can_be_built_here().

◆ city_can_change_build()

bool city_can_change_build ( const struct city pcity)

Returns TRUE iff the given city can change what it is building

Definition at line 1079 of file city.c.

Referenced by city_build_unit(), city_set_queue(), and handle_city_change().

◆ city_can_grow_to()

bool city_can_grow_to ( const struct city pcity,
int  pop_size 
)

Return TRUE iff the city can grow to the given size.

Definition at line 2012 of file city.c.

Referenced by actres_possible(), city_increase_size(), city_turn_notify(), dai_effect_value(), dai_manage_taxes(), do_city_migration(), and expl_act_not_enabl().

◆ city_can_use_specialist()

bool city_can_use_specialist ( const struct city pcity,
Specialist_type_id  type 
)

Returns TRUE iff the given city can use this kind of specialist.

Definition at line 1065 of file city.c.

Referenced by best_specialist(), city_rotate_specialist(), handle_city_change_specialist(), and init_specialist_lattice_nodes().

◆ city_can_work_tile()

bool city_can_work_tile ( const struct city pcity,
const struct tile ptile 
)

◆ city_celebrating()

bool city_celebrating ( const struct city pcity)

◆ city_change_production_penalty()

int city_change_production_penalty ( const struct city pcity,
const struct universal target 
)

Compute and optionally apply the change-production penalty for the given production change (to target) in the given city (pcity). Always returns the number of shields which would be in the stock if the penalty had been applied.

If we switch the "class" of the target sometime after a city has produced (i.e., not on the turn immediately after), then there's a shield loss. But only on the first switch that turn. Also, if ever change back to original improvement class of this turn, restore lost production.

Definition at line 1886 of file city.c.

Referenced by change_build_target(), change_production(), and city_turns_to_build().

◆ city_choose_build_default()

void city_choose_build_default ( const struct civ_map nmap,
struct city pcity 
)

Always tile_set_owner(ptile, pplayer) sometime before this!

Definition at line 1087 of file city.c.

Referenced by cityresult_fill(), and create_city().

◆ city_exist()

bool city_exist ( int  id)

◆ city_exists_within_max_city_map()

bool city_exists_within_max_city_map ( const struct civ_map nmap,
const struct tile ptile,
bool  may_be_on_center 
)

Return TRUE iff a city exists within a city radius of the given location. may_be_on_center determines if a city at x,y counts.

Definition at line 2112 of file city.c.

Referenced by api_methods_tile_city_exists_within_max_city_map(), and hut_get_limited().

◆ city_got_defense_effect()

bool city_got_defense_effect ( const struct city pcity,
const struct unit_type attacker 
)

This can be City Walls, Coastal defense... depending on attacker type. If attacker type is not given, just any defense effect will do.

Definition at line 1596 of file city.c.

Referenced by base_assess_defense_unit(), and dai_process_defender_want().

◆ city_granary_size()

int city_granary_size ( int  city_size)

◆ city_had_recent_plague()

bool city_had_recent_plague ( const struct city pcity)

Returns whether city had a plague outbreak this turn.

Definition at line 2923 of file city.c.

Referenced by city_populate().

◆ city_happy()

bool city_happy ( const struct city pcity)

Return TRUE iff the city is happy. A happy city will start celebrating soon. A city can only be happy if half or more of the population is happy, none of the population is unhappy or angry, and it has sufficient size.

Definition at line 1614 of file city.c.

Referenced by api_methods_is_city_happy(), city_celebrating(), city_dialog_update_title(), dai_manage_taxes(), get_city_surplus(), handle_city_info(), real_city_dialog_popup(), real_city_report_dialog_update_city(), real_info_city_report_dialog_update(), rebuild_citydlg_title_str(), redraw_city_dialog(), update_city_activity(), update_dumb_city(), and city_dialog::update_title().

◆ city_has_building()

bool city_has_building ( const struct city pcity,
const struct impr_type pimprove 
)

◆ city_illness_calc()

int city_illness_calc ( const struct city pcity,
int ill_base,
int ill_size,
int ill_trade,
int ill_pollution 
)

Calculate city's illness in tenth of percent:

base illness (the maximum value for illness in percent is given by 'game.info.illness_base_factor')

  • trade illness (see get_trade_illness())
  • pollution illness (the pollution in the city times 'game.info.illness_pollution_factor')

The illness is reduced by the percentage given by the health effect. Illness cannot exceed 999 (= 99.9%), or be less then 0

Definition at line 2870 of file city.c.

Referenced by city_dialog_update_information(), city_dialog_update_information(), city_illness_strike(), city_migration_score(), cr_entry_plague_risk(), get_city_dialog_illness_text(), redraw_info_city_dialog(), sg_load_players(), sg_load_players(), update_city_activity(), and city_dialog::update_info_label().

◆ city_improvement_name_translation()

const char * city_improvement_name_translation ( const struct city pcity,
const struct impr_type pimprove 
)

◆ city_improvement_upkeep()

int city_improvement_upkeep ( const struct city pcity,
const struct impr_type b 
)

Return the upkeep (gold) needed each turn to upkeep the given improvement in the given city.

Definition at line 1255 of file city.c.

Referenced by city_dialog_update_improvement_list(), city_total_impr_gold_upkeep(), dai_city_want(), get_city_dialog_production_row(), get_economy_report_data(), get_tooltip_improvement(), sell_random_building(), and city_dialog::update_improvements().

◆ city_is_occupied()

bool city_is_occupied ( const struct city pcity)

Returns TRUE iff the city is occupied.

Definition at line 1665 of file city.c.

Referenced by popup_info_text().

◆ city_is_virtual()

bool city_is_virtual ( const struct city pcity)

Return TRUE if the city is a virtual city. That is, it is a valid city pointer but does not correspond to a city that exists in the game.

NB: A return value of FALSE implies that either the pointer is NULL or that the city exists in the game.

Definition at line 3614 of file city.c.

Referenced by tile_virtual_destroy().

◆ city_list_find_name()

struct city * city_list_find_name ( struct city_list *  This,
const char name 
)

Find city with given name from list.

Definition at line 1695 of file city.c.

Referenced by game_city_by_name(), is_allowed_city_name(), and transfer_city().

◆ city_list_find_number()

struct city * city_list_find_number ( struct city_list *  This,
int  id 
)

Find city with given id from list.

Definition at line 1679 of file city.c.

Referenced by city_freeze_workers_queue(), city_refresh_queue_add(), and dai_goldequiv_clause().

◆ city_map_includes_tile()

bool city_map_includes_tile ( const struct city *const  pcity,
const struct tile map_tile 
)

Returns TRUE iff pcity's city map includes the specified tile.

Definition at line 293 of file city.c.

Referenced by handle_city_make_specialist(), and handle_city_make_worker().

◆ city_map_radius_sq_get()

int city_map_radius_sq_get ( const struct city pcity)

Returns the current squared radius of the city.

Definition at line 137 of file city.c.

Referenced by adv_city_update(), adv_city_worker_act_get(), adv_city_worker_act_set(), adv_city_worker_extra_get(), adv_city_worker_extra_set(), adv_city_worker_rmextra_get(), adv_city_worker_rmextra_set(), api_methods_city_map_sq_radius(), apply_cmresult_to_city(), apply_result_on_server(), apply_solution(), build_landarea_map(), button_down_citymap(), check_city_migrations_player(), city_base_to_city_map(), city_increase_size(), city_map_update_all(), city_map_update_radius_sq(), city_reduce_workers(), city_tc_effect_refresh(), city_tile_cache_get_output(), city_tile_cache_update(), city_toggle_worker(), citylog_map_workers(), citymap_turn_init(), cityresult_fill(), cm_print_city(), cm_result_new(), compute_max_stats_heuristic(), city_map::context_menu(), dai_city_want(), dai_effect_value(), do_city_migration(), game_remove_city(), get_worked_tile_output(), give_citymap_from_player_to_player(), handle_city_info(), handle_city_short_info(), handle_tile_info(), impr_provides_buildable_extras(), init_tile_lattice(), initialize_infrastructure_cache(), is_extra_req_active(), is_extraflag_req_active(), is_roadflag_req_active(), is_terrain_req_active(), is_terrainclass_req_active(), is_terrainflag_req_active(), is_tile_seen_city(), left_button_down_citymap(), map_claim_border(), max_tile_trade(), min_food_surplus_for_fastest_growth(), city_map::mousePressEvent(), package_city(), place_pollution(), player_in_city_map(), resolve_city_emergency(), resource_map_city_dlg_callback(), right_button_down_citymap(), city_map::set_pixmap(), texai_city_worker_task_select(), and worker_evaluate_improvements().

◆ city_map_radius_sq_set()

void city_map_radius_sq_set ( struct city pcity,
int  radius_sq 
)

Sets the squared radius for the city.

Definition at line 148 of file city.c.

Referenced by city_map_update_radius_sq(), handle_city_short_info(), handle_tile_info(), sg_load_player_city(), and sg_load_player_city().

◆ city_map_tiles()

int city_map_tiles ( int  city_radius_sq)

Return the number of tiles for the given city radius. Special case is the value -1 for no city tiles.

Definition at line 171 of file city.c.

Referenced by adv_city_update(), city_map_update_radius_sq(), city_tile_cache_update(), city_tile_index_to_xy(), citylog_map_workers(), cm_print_result(), cm_result_copy(), cm_result_new(), generate_city_map_indices(), max_tile_trade(), place_pollution(), and print_cityresult().

◆ city_map_to_tile()

struct tile * city_map_to_tile ( const struct civ_map nmap,
const struct tile city_center,
int  city_radius_sq,
int  city_map_x,
int  city_map_y 
)

Finds the map position for a given city map coordinate of a certain city. Returns true if the map position found is real.

Definition at line 305 of file city.c.

Referenced by button_down_citymap(), city_map_update_radius_sq(), city_toggle_worker(), citylog_map_workers(), city_map::context_menu(), max_tile_trade(), min_food_surplus_for_fastest_growth(), place_pollution(), and right_button_down_citymap().

◆ city_name_compare()

int city_name_compare ( const void p1,
const void p2 
)

Comparison function for qsort for city pointers, sorting by city name. Args are really (struct city**), to sort an array of pointers. (Compare with old_city_name_compare() in game.c, which use city_id's)

Definition at line 1711 of file city.c.

Referenced by create_clause_menu(), popup_add_menu(), and popup_diplomatic_objects().

◆ city_name_get()

const char * city_name_get ( const struct city pcity)

Return the name of the city.

Definition at line 1137 of file city.c.

Referenced by adv_city_worker_act_set(), adv_city_worker_extra_set(), adv_city_worker_rmextra_set(), agents_city_changed(), agents_city_new(), agents_city_remove(), apply_disaster(), apply_result_on_server(), auto_arrange_workers(), caravan_optimize_callback(), change_build_target(), check_city_migrations_player(), choose_build_target(), cities_update_callback(), citizens_convert(), citizens_convert_conquest(), citizens_print(), city_build_unit(), city_choose_build_default(), city_dialog_update_title(), city_from_wonder(), city_link(), city_map_update_radius_sq(), city_migration_score(), city_packet_common(), city_rally_point_receive(), city_reduce_size(), city_dialog::city_rename(), city_repair_size(), city_tile_link(), citylog_map_workers(), civil_war(), client_diplomacy_clause_string(), client_remove_city(), client_remove_unit(), cm_find_best_solution(), cm_print_city(), cm_state_init(), cma_put_city_under_agent(), cr_entry_cityname(), create_city_dialog(), create_clause_menu(), dai_action_value_unit_vs_city(), dai_airlift(), dai_auto_settler_run(), dai_caravan_goto(), dai_choose_attacker_air(), dai_choose_diplomat_defensive(), dai_choose_diplomat_offensive(), dai_choose_help_wonder(), dai_choose_paratrooper(), dai_city_choose_build(), dai_diplomat_city(), dai_find_strategic_airbase(), dai_goldequiv_clause(), dai_manage_airunit(), dai_manage_diplomat(), dai_manage_hitpoint_recovery(), dai_manage_paratrooper(), dai_manage_taxes(), dai_military_attack_barbarian(), dai_military_defend(), dai_process_defender_want(), dai_should_we_air_attack_tile(), debug_command(), define_orig_production_values(), diplomat_sabotage(), do_capture_units(), edit_buffer_copy(), explain_why_no_action_enabled(), goto_dialog::fill_tab(), find_best_tile_to_paradrop_to(), find_something_to_kill(), game_remove_city(), game_remove_unit(), get_city_citizen_types(), get_city_dialog_output_text(), get_city_mapview_name_and_growth(), get_nearest_city_text(), get_unit_info_label_text2(), handle_city(), handle_city_info(), handle_city_make_specialist(), handle_city_make_worker(), handle_tile_info(), handle_unit_packet_common(), idex_register_city(), idex_unregister_city(), illegal_action_msg(), kill_something_with(), list_store_append_player_cities(), look_for_charge(), plr_widget::nation_selected(), new_name_city_dlg_callback(), package_city(), place_pollution(), popup_action_selection(), popup_add_menu(), popup_advanced_terrain_dialog(), popup_city_cma_dialog(), popup_diplomatic_objects(), popup_find_dialog(), popup_incite_dialog(), popup_incite_dialog(), popup_info_text(), popup_worklist_editor(), process_attacker_want(), rally_set_tile(), real_bodyguard_log(), real_city_dialog_popup(), real_city_log(), real_info_city_report_dialog_update(), real_menus_update(), really_handle_city_buy(), rebuild_citydlg_title_str(), redraw_info_city_dialog(), redraw_unit_info_label(), refresh_city_names(), rename_callback(), report_top_cities(), report_wonders_of_the_world(), report_wonders_of_the_world_long(), resolve_city_emergency(), send_player_cities(), sg_load_player_city(), sg_load_player_city(), sg_load_player_city_citizens(), sg_load_player_city_citizens(), sg_save_player_cities(), show_city_descriptions(), teleport_unit_to_city(), text_tag_initv(), text_tag_replace_text(), text_tag_start_sequence(), throw_units_from_illegal_cities(), tile_set_terrain(), transfer_city(), transfer_city_units(), transfer_unit(), try_summon_barbarians(), unit_description(), hud_units::update_actions(), update_dumb_city(), update_find_dialog(), update_goto_dialog(), update_intel_dialog(), update_intel_wonder_dialog(), update_source_label(), city_dialog::update_title(), usdlg_get_unit_descr(), vision_site_new_from_city(), vision_site_update_from_city(), and want_tech_for_improvement_effect().

◆ city_name_set()

void city_name_set ( struct city pcity,
const char new_name 
)

◆ city_pollution()

int city_pollution ( const struct city pcity,
int  shield_total 
)

Calculate pollution for the city. The shield_total must be passed in (most callers will want to pass pcity->shield_prod).

Definition at line 2821 of file city.c.

Referenced by city_refresh_from_main_map(), and dai_city_want().

◆ city_pollution_types()

int city_pollution_types ( const struct city pcity,
int  shield_total,
int pollu_prod,
int pollu_pop,
int pollu_mod 
)

Calculate the pollution from production and population in the city.

Definition at line 2787 of file city.c.

Referenced by city_pollution(), and get_city_dialog_pollution_text().

◆ city_population()

int city_population ( const struct city pcity)

Returns how many thousand citizen live in this city.

Definition at line 1191 of file city.c.

Referenced by calc_civ_score(), city_dialog_update_title(), civ_population(), popup_city_cma_dialog(), rebuild_citydlg_title_str(), and city_dialog::update_title().

◆ city_production_build_shield_cost()

int city_production_build_shield_cost ( const struct city pcity)

◆ city_production_build_units()

bool city_production_build_units ( const struct city pcity,
bool  add_production,
int num_units 
)

Return TRUE if the city could use the additional build slots provided by the effect City_Build_Slots. Within 'num_units' the total number of units the city can build considering the current shield stock is returned.

Definition at line 747 of file city.c.

Referenced by city_build_unit(), city_production_cost_str(), get_units_report_data(), units_report_update(), and units_reports::update_units().

◆ city_production_caravan_shields_init()

void city_production_caravan_shields_init ( void  )

Initialize the cache of what city production can use shields from caravans.

Definition at line 1778 of file city.c.

Referenced by handle_rulesets_ready(), and load_rulesetdir().

◆ city_production_gets_caravan_shields()

bool city_production_gets_caravan_shields ( const struct universal tgt)

Returns TRUE iff the specified production should get shields from units that has done ACTION_HELP_WONDER.

Definition at line 1860 of file city.c.

Referenced by city_change_production_penalty(), dai_choose_help_wonder(), dai_manage_caravan(), unit_do_help_build(), and wonder_benefit().

◆ city_production_has_flag()

bool city_production_has_flag ( const struct city pcity,
enum impr_flag_id  flag 
)

Return TRUE when the current production has this flag.

Definition at line 727 of file city.c.

Referenced by city_build_building(), cr_entry_building(), get_city_dialog_production(), get_economy_report_data(), player_get_expected_income(), and popup_worklist_editor().

◆ city_production_is_genus()

bool city_production_is_genus ( const struct city pcity,
enum impr_genus_id  genus 
)

◆ city_production_name_translation()

const char * city_production_name_translation ( const struct city pcity)

◆ city_production_turns_to_build()

int city_production_turns_to_build ( const struct city pcity,
bool  include_shield_stock 
)

Calculates the turns which are needed to build the requested production in the city. GUI Independent.

Definition at line 820 of file city.c.

Referenced by city_global_turn_notify(), cr_entry_build_cost(), get_city_dialog_production(), get_city_mapview_production(), get_units_report_data(), popup_worklist_editor(), real_city_report_dialog_update_city(), real_info_city_report_dialog_update(), and redraw_city_dialog().

◆ city_production_unit_veteran_level()

int city_production_unit_veteran_level ( struct city pcity,
const struct unit_type punittype 
)

◆ city_rally_point_clear()

void city_rally_point_clear ( struct city pcity)

Clear rally point set for the city.

Definition at line 3651 of file city.c.

Referenced by city_build_unit(), destroy_city_virtual(), and transfer_city().

◆ city_rally_point_receive()

void city_rally_point_receive ( const struct packet_city_rally_point packet,
struct city pcity 
)

Fill city rally point from a packet.

Definition at line 3666 of file city.c.

Referenced by handle_city_rally_point(), and handle_city_rally_point().

◆ city_rapture_grow()

bool city_rapture_grow ( const struct city pcity)

Returns whether city is growing by rapture.

Definition at line 1653 of file city.c.

Referenced by city_increase_size(), and city_populate().

◆ city_refresh_from_main_map()

void city_refresh_from_main_map ( const struct civ_map nmap,
struct city pcity,
bool workers_map 
)

Refreshes the internal cached data in the city structure.

!full_refresh will not update tile_cache[] or bonus[]. These two values do not need to be recalculated for AI CMA testing.

'workers_map' is an boolean array which defines the placement of the workers within the city map. It uses the tile index and its size is defined by city_map_tiles_from_city(_pcity). See also cm_state_init().

If 'workers_map' is set, only basic updates are needed.

Definition at line 3201 of file city.c.

Referenced by apply_solution(), city_refresh(), cm_query_result(), and dai_manage_taxes().

◆ city_remove_improvement()

void city_remove_improvement ( struct city pcity,
const struct impr_type pimprove 
)

◆ city_set_ai_data()

void city_set_ai_data ( struct city pcity,
const struct ai_type ai,
void data 
)

Attach ai data to city

Definition at line 3642 of file city.c.

Referenced by dai_city_alloc(), dai_city_free(), texai_city_alloc(), and texai_city_free().

◆ city_size_add()

void city_size_add ( struct city pcity,
int  add 
)

Add a (positive or negative) value to the city size. As citizens is an unsigned value use int for the parameter 'add'.

Definition at line 1164 of file city.c.

Referenced by city_add_unit(), city_increase_size(), city_reduce_size(), cityresult_fill(), and handle_city_info().

◆ city_size_set()

void city_size_set ( struct city pcity,
citizens  size 
)

◆ city_specialists()

citizens city_specialists ( const struct city pcity)

◆ city_style_by_rule_name()

int city_style_by_rule_name ( const char s)

Returns the city style that has the given (untranslated) rule name. Returns -1 if none match.

Definition at line 1738 of file city.c.

Referenced by sg_load_player_city(), sg_load_player_city(), sg_load_player_vision_city(), and sg_load_player_vision_city().

◆ city_style_by_translated_name()

int city_style_by_translated_name ( const char s)

Returns the city style that has the given (translated) name. Returns -1 if none match.

Definition at line 1721 of file city.c.

◆ city_style_name_translation()

const char * city_style_name_translation ( const int  style)

Return the (translated) name of the given city style. You don't have to free the return pointer.

Definition at line 1756 of file city.c.

Referenced by city_style_by_translated_name(), and create_races_dialog().

◆ city_style_rule_name()

const char * city_style_rule_name ( const int  style)

Return the (untranslated) rule name of the city style. You don't have to free the return pointer.

Definition at line 1765 of file city.c.

Referenced by city_style_by_rule_name(), is_universal_needed(), load_ruleset_styles(), sanity_check_ruleset_data(), sg_save_player_cities(), sg_save_player_vision(), and tileset_setup_city_tiles().

◆ city_styles_alloc()

void city_styles_alloc ( int  num)

Allocate memory for this amount of city styles.

Definition at line 3421 of file city.c.

Referenced by handle_ruleset_control(), and load_style_names().

◆ city_styles_free()

void city_styles_free ( void  )

De-allocate the memory used by the city styles.

Definition at line 3436 of file city.c.

Referenced by game_ruleset_free().

◆ city_support()

static void city_support ( const struct civ_map nmap,
struct city pcity 
)
inlinestatic

Calculate upkeep costs. This builds the pcity->usage[] array as well as setting some happiness values.

Definition at line 3100 of file city.c.

Referenced by city_refresh_from_main_map().

◆ city_tile_cache_get_output()

static int city_tile_cache_get_output ( const struct city pcity,
int  city_tile_index,
enum output_type_id  o 
)
inlinestatic

This function returns the output of 'o' for the city tile 'city_tile_index' of 'pcity'.

Definition at line 2438 of file city.c.

Referenced by get_worked_tile_output().

◆ city_tile_cache_update()

static void city_tile_cache_update ( const struct civ_map nmap,
struct city pcity 
)
inlinestatic

This function sets the cache for the tile outputs, the pcity->tile_cache[] array. It is called near the beginning of city_refresh_from_main_map().

It doesn't depend on anything else in the refresh and doesn't change as workers are moved around, but does change when buildings are built, etc.

TODO: use the cached values elsewhere in the code!

Definition at line 2409 of file city.c.

Referenced by city_refresh_from_main_map().

◆ city_tile_index_to_xy()

bool city_tile_index_to_xy ( int city_map_x,
int city_map_y,
int  city_tile_index,
int  city_radius_sq 
)

Returns the coordinates for the given city tile index taking into account the squared city radius.

Definition at line 101 of file city.c.

Referenced by cm_print_city(), and place_pollution().

◆ city_tile_output()

int city_tile_output ( const struct city pcity,
const struct tile ptile,
bool  is_celebrating,
Output_type_id  otype 
)

Calculate the output for the tile. pcity may be NULL. is_celebrating may be speculative. otype is the output type (generally O_FOOD, O_TRADE, or O_SHIELD).

This can be used to calculate the benefits celebration would give.

Definition at line 1283 of file city.c.

Referenced by city_tile_cache_update(), city_tile_output_now(), cityresult_fill(), compute_max_stats_heuristic(), compute_tile_production(), dai_city_want(), do_city_migration(), fill_city_overlays_sprite_array(), get_tile_output_text(), get_tile_value(), get_worked_tile_output(), max_tile_trade(), and min_food_surplus_for_fastest_growth().

◆ city_tile_output_now()

int city_tile_output_now ( const struct city pcity,
const struct tile ptile,
Output_type_id  otype 
)

Calculate the production output the given tile is capable of producing for the city. The output type is given by 'otype' (generally O_FOOD, O_SHIELD, or O_TRADE).

NOTE: As of now, return value does not represent output on end of turn if city stops celebrating, because the server side tile output cache uses base_city_celebrating() instead of city_celebrating() on city_tile_cache_update().

Definition at line 1384 of file city.c.

Referenced by city_tile_value(), and package_city().

◆ city_tile_to_city_map()

bool city_tile_to_city_map ( int city_map_x,
int city_map_y,
const int  city_radius_sq,
const struct tile city_center,
const struct tile map_tile 
)

Finds the city map coordinate for a given map position and a city center. Returns whether the map position is inside of the city map.

Definition at line 264 of file city.c.

Referenced by city_base_to_city_map(), and fill_grid_sprite_array().

◆ city_tile_xy_to_index()

int city_tile_xy_to_index ( int  city_map_x,
int  city_map_y,
int  city_radius_sq 
)

Returns the index for the given city tile coordinates taking into account the squared city radius.

Definition at line 123 of file city.c.

Referenced by citylog_map_line().

◆ city_total_impr_gold_upkeep()

int city_total_impr_gold_upkeep ( const struct city pcity)

Returns the total amount of gold needed to pay for all buildings in the city.

Definition at line 1201 of file city.c.

Referenced by city_support(), player_get_expected_income(), and update_city_activity().

◆ city_total_unit_gold_upkeep()

int city_total_unit_gold_upkeep ( const struct city pcity)

Get the total amount of gold needed to pay upkeep costs for all supported units of the city. Takes into account EFT_UNIT_UPKEEP_FREE_PER_CITY.

Definition at line 1222 of file city.c.

Referenced by city_support(), military_advisor_choose_build(), player_get_expected_income(), and update_city_activity().

◆ city_turns_to_build()

int city_turns_to_build ( const struct city pcity,
const struct universal target,
bool  include_shield_stock 
)

Calculates the turns which are needed to build the requested improvement in the city. GUI Independent.

Definition at line 1965 of file city.c.

Referenced by city_production_turns_to_build(), get_city_dialog_production_full(), get_city_dialog_production_row(), popup_worklist_editor(), and refresh_production_label().

◆ city_turns_to_grow()

int city_turns_to_grow ( const struct city pcity)

Calculates the turns which are needed for the city to grow. A value of FC_INFINITY means the city will never grow. A value of 0 means city growth is blocked. A negative value of -x means the city will shrink in x turns. A positive value of x means the city will grow in x turns.

Definition at line 1996 of file city.c.

Referenced by city_dialog_update_information(), city_dialog_update_information(), cr_entry_growturns(), get_city_mapview_name_and_growth(), package_city(), real_city_report_dialog_update_city(), real_info_city_report_dialog_update(), redraw_city_dialog(), and city_dialog::update_info_label().

◆ city_unhappy()

bool city_unhappy ( const struct city pcity)

◆ city_unit_slots_available()

int city_unit_slots_available ( const struct city pcity)

Return number of free unit slots in a city.

Definition at line 1049 of file city.c.

Referenced by actres_possible(), and can_city_build_unit_direct().

◆ city_unit_unhappiness()

int city_unit_unhappiness ( const struct civ_map nmap,
struct unit punit,
int free_unhappy 
)

Query unhappiness caused by a given unit.

Definition at line 3049 of file city.c.

Referenced by city_dialog_update_supported_units(), city_support(), create_unit_surface(), dai_assess_military_unhappiness(), and city_dialog::update_units().

◆ city_waste()

int city_waste ( const struct city pcity,
Output_type_id  otype,
int  total,
int breakdown 
)

Give corruption/waste generated by city. otype gives the output type (O_SHIELD/O_TRADE). 'total' gives the total output of this type in the city. If non-NULL, 'breakdown' should be an OLOSS_LAST-sized array which will be filled in with a breakdown of the kinds of waste (not cumulative).

Definition at line 3253 of file city.c.

Referenced by cityresult_fill(), dai_city_want(), get_city_dialog_output_text(), and set_city_production().

◆ citylog_map_data()

void citylog_map_data ( enum log_level  level,
int  radius_sq,
int map_data 
)

Display 'map_data' on a city map with the given radius 'radius_sq' for the requested log level. The size of 'map_data' is defined by city_map_tiles(radius_sq).

Definition at line 411 of file city.c.

Referenced by citylog_map_workers(), cm_print_result(), and print_cityresult().

◆ citylog_map_line()

static char * citylog_map_line ( int  y,
int  city_radius_sq,
int city_map_data 
)
static

Definition at line 369 of file city.c.

Referenced by citylog_map_data().

◆ citylog_map_workers()

void citylog_map_workers ( enum log_level  level,
struct city pcity 
)

Display the location of the workers within the city map of pcity.

Definition at line 446 of file city.c.

Referenced by city_map_update_radius_sq().

◆ citymindist_prevents_city_on_tile()

bool citymindist_prevents_city_on_tile ( const struct civ_map nmap,
const struct tile ptile 
)

Returns TRUE iff it is illegal to found a city on the specified tile because of citymindist.

Definition at line 1465 of file city.c.

Referenced by actres_possible(), city_can_be_built_tile_only(), and expl_act_not_enabl().

◆ cmp()

static int cmp ( int  v1,
int  v2 
)
static

Compare two integer values, as required by qsort.

Definition at line 325 of file city.c.

Referenced by auto_arrange_workers(), compare_iter_index(), dai_manage_taxes(), data_compare(), set_default_city_manager(), and tile_type_lattice_add().

◆ compare_iter_index()

int compare_iter_index ( const void a,
const void b 
)

Compare two iter_index values from the city_map_index.

This function will be passed to qsort(). It should never return zero, or the sort order will be left up to qsort and will be undefined. This would mean that server execution would not be reproducible.

Definition at line 343 of file city.c.

Referenced by generate_city_map_indices(), and generate_map_indices().

◆ create_city_virtual()

struct city * create_city_virtual ( struct player pplayer,
struct tile ptile,
const char name 
)

Create virtual skeleton for a city. Values are mostly sane defaults.

Always tile_set_owner(ptile, pplayer) sometime after this!

Definition at line 3455 of file city.c.

Referenced by trade_generator::add_tile(), cityresult_fill(), create_city(), edit_buffer_copy(), handle_city_info(), handle_city_short_info(), handle_tile_info(), result_defense_bonus(), sg_load_player_cities(), sg_load_player_cities(), and texai_city_info_recv().

◆ destroy_city_virtual()

void destroy_city_virtual ( struct city pcity)

Removes the virtual skeleton of a city. You should already have removed all buildings and units you have added to the city before this.

Definition at line 3541 of file city.c.

Referenced by cityresult_fill(), trade_generator::clear_trade_planing(), game_remove_city(), packhand_free(), sg_load_player_cities(), sg_load_player_cities(), texai_city_destruction_recv(), and tile_virtual_destroy().

◆ free_city_map_index()

void free_city_map_index ( void  )

Free memory allocated by generate_citymap_index

Definition at line 609 of file city.c.

Referenced by game_free(), game_reset(), handle_map_info(), and srv_ready().

◆ generate_city_map_indices()

void generate_city_map_indices ( void  )

Fill the arrays city_map_index, city_map_xy and city_map_numtiles. This may depend on topology and ruleset settings.

Definition at line 527 of file city.c.

Referenced by main_map_allocate().

◆ get_city_health()

static int get_city_health ( const struct city pcity)
static

Get any effects regarding health from the buildings of the city. The effect defines the reduction of the possibility of an illness in percent.

Definition at line 2853 of file city.c.

Referenced by city_illness_calc().

◆ get_city_tithes_bonus()

int get_city_tithes_bonus ( const struct city pcity)

Return the amount of gold generated by buildings under "tithe" attribute governments.

Definition at line 2227 of file city.c.

Referenced by dai_city_want(), get_city_dialog_output_text(), and set_city_production().

◆ get_final_city_output_bonus()

int get_final_city_output_bonus ( const struct city pcity,
Output_type_id  otype 
)

Return the factor (in %) by which the city's output should be multiplied.

Definition at line 2212 of file city.c.

Referenced by calc_civ_score(), dai_city_want(), and set_city_bonuses().

◆ get_output_identifier()

const char * get_output_identifier ( Output_type_id  output)

Return an id string for the output type. This string can be used internally by rulesets and tilesets and should not be changed or translated.

Definition at line 619 of file city.c.

Referenced by load_ruleset_game(), load_ruleset_terrain(), load_ruleset_units(), save_game_ruleset(), save_terrain_ruleset(), save_units_ruleset(), tileset_lookup_sprite_tags(), and universal_rule_name().

◆ get_output_name()

const char * get_output_name ( Output_type_id  output)

Return a translated name for the output type. This name should only be used for user display.

Definition at line 629 of file city.c.

Referenced by choice_is_promising(), cm_print_result(), create_cma_dialog(), helptext_government(), helptext_unit_upkeep_str(), popup_city_cma_dialog(), req_text_insert(), universal_kind_values(), and universal_name_translation().

◆ get_output_type()

struct output_type * get_output_type ( Output_type_id  output)

◆ get_trade_illness()

static int get_trade_illness ( const struct city pcity)
static

Gets whether cities that pcity trades with had the plague. If so, it returns the health penalty in tenth of percent which depends on the size of both cities. The health penalty is given as the product of the ruleset option 'game.info.illness_trade_infection' (in percent) and the square root of the product of the size of both cities.

Definition at line 2833 of file city.c.

Referenced by city_illness_calc().

◆ get_worked_tile_output()

static void get_worked_tile_output ( const struct civ_map nmap,
const struct city pcity,
int output,
bool workers_map 
)
inlinestatic

Calculate output (food, trade and shields) generated by the worked tiles of a city. This will completely overwrite the output[] array.

'workers_map' is an boolean array which defines the placement of the workers within the city map. It uses the tile index and its size is defined by city_map_tiles_from_city(_pcity). See also cm_state_init().

Definition at line 2324 of file city.c.

Referenced by city_refresh_from_main_map().

◆ happy_copy()

static void happy_copy ( struct city pcity,
enum citizen_feeling  i 
)
static

Copy the happiness array in the city to index i from index i-1.

Definition at line 2493 of file city.c.

Referenced by city_refresh_from_main_map().

◆ is_capital()

bool is_capital ( const struct city pcity)

◆ is_city_option_set()

bool is_city_option_set ( const struct city pcity,
enum city_options  option 
)

Returns TRUE iff the city has set the given option.

Definition at line 3413 of file city.c.

Referenced by city_build_unit(), city_increase_size(), city_dialog::display_worklist_menu(), and set_cityopt_values().

◆ is_free_worked()

bool is_free_worked ( const struct city pcity,
const struct tile ptile 
)

◆ is_friendly_city_near()

bool is_friendly_city_near ( const struct civ_map nmap,
const struct player owner,
const struct tile ptile,
int  distance 
)

Return TRUE if there is a friendly city near to this tile.

Definition at line 2092 of file city.c.

Referenced by is_unit_near_a_friendly_city(), and unit_move_consequences().

◆ is_gov_center()

bool is_gov_center ( const struct city pcity)

Return TRUE iff this city is governmental center.

Definition at line 1587 of file city.c.

Referenced by api_methods_is_gov_center(), and nearest_gov_center().

◆ is_unit_near_a_friendly_city()

bool is_unit_near_a_friendly_city ( const struct civ_map nmap,
const struct unit punit,
int  distance 
)

Return TRUE if there is a friendly city near to this unit

Definition at line 2081 of file city.c.

Referenced by unit_being_aggressive().

◆ is_valid_city_coords()

bool is_valid_city_coords ( const int  city_radius_sq,
const int  city_map_x,
const int  city_map_y 
)

Return TRUE if the given city coordinate pair is "valid"; that is, if it is a part of the citymap and thus is workable by the city.

Definition at line 188 of file city.c.

Referenced by canvas_to_city_pos(), city_map_to_tile(), city_tile_to_city_map(), city_tile_xy_to_index(), city_to_canvas_pos(), city_toggle_worker(), and citylog_map_line().

◆ nearest_gov_center()

static const struct city * nearest_gov_center ( const struct city pcity,
int min_dist 
)
static

Find government center nearest to given city.

Definition at line 2287 of file city.c.

Referenced by city_waste(), and set_surpluses().

◆ output_type_by_identifier()

Output_type_id output_type_by_identifier ( const char id)

Find the output type for this output identifier.

Definition at line 647 of file city.c.

Referenced by api_effects_tile_bonus(), and universal_value_from_str().

◆ player_angry_citizens()

citizens player_angry_citizens ( const struct player pplayer)

Give base number of angry citizens in any city owned by pplayer.

Definition at line 2196 of file city.c.

Referenced by citizen_base_mood(), create_city(), remove_city(), and transfer_city().

◆ player_base_citizen_happiness()

static int player_base_citizen_happiness ( const struct player pplayer)
static

Give base happiness in any city owned by pplayer. A positive number is a number of content citizens. A negative number is a number of angry citizens (a city never starts with both).

Definition at line 2160 of file city.c.

Referenced by player_angry_citizens(), and player_content_citizens().

◆ player_content_citizens()

citizens player_content_citizens ( const struct player pplayer)

Give base number of content citizens in any city owned by pplayer.

Definition at line 2186 of file city.c.

Referenced by choice_is_promising(), citizen_base_mood(), create_city(), evaluate_solution(), remove_city(), and transfer_city().

◆ rs_max_city_radius_sq()

int rs_max_city_radius_sq ( void  )

Maximum city radius in this ruleset.

Definition at line 159 of file city.c.

Referenced by find_city_or_settler_near_tile(), generate_citydlg_dimensions(), and city_map::set_pixmap().

◆ set_city_bonuses()

static void set_city_bonuses ( struct city pcity)
inlinestatic

This function sets all the values in the pcity->bonus[] and pcity->abs_bonus[] arrays. Called near the beginning of city_refresh_from_main_map().

It doesn't depend on anything else in the refresh and doesn't change as workers are moved around, but does change when buildings are built, etc.

Definition at line 2386 of file city.c.

Referenced by city_refresh_from_main_map().

◆ set_city_production()

void set_city_production ( struct city pcity)
inline

Set food, trade and shields production in a city.

This initializes the prod[] and waste[] arrays. It assumes that the bonus[] and citizen_base[] arrays are alread built.

Definition at line 2953 of file city.c.

Referenced by city_refresh_from_main_map(), and compute_max_stats_heuristic().

◆ set_surpluses()

static void set_surpluses ( struct city pcity)
static

Set the final surplus[] array from the prod[] and usage[] values.

Definition at line 2452 of file city.c.

Referenced by city_refresh_from_main_map().

◆ tile_allied_city()

struct city * tile_allied_city ( const struct tile ptile,
const struct player pplayer 
)

Return friendly city on the tile, if one exist

Definition at line 2036 of file city.c.

Referenced by is_allied_city_tile().

◆ tile_enemy_city()

struct city * tile_enemy_city ( const struct tile ptile,
const struct player pplayer 
)

Return enemy city on the tile, if one exist

Definition at line 2021 of file city.c.

Referenced by is_enemy_city_tile().

◆ tile_non_allied_city()

struct city * tile_non_allied_city ( const struct tile ptile,
const struct player pplayer 
)

Return non-allied city on the tile, if one exist

Definition at line 2066 of file city.c.

Referenced by is_non_allied_city_tile(), is_plr_zoc_client(), and is_plr_zoc_srv().

◆ tile_non_attack_city()

struct city * tile_non_attack_city ( const struct tile ptile,
const struct player pplayer 
)

Return non-attack city on the tile, if one exist

Definition at line 2051 of file city.c.

Referenced by is_non_attack_city_tile(), and need_war_player_hlp().

◆ unhappy_city_check()

static void unhappy_city_check ( struct city pcity)
inlinestatic

Set food, tax, science and shields production to zero if city is in disorder.

Definition at line 2760 of file city.c.

Referenced by city_refresh_from_main_map().

Variable Documentation

◆ caravan_helped_impr

bv_imprs caravan_helped_impr
static

◆ caravan_helped_utype

bv_unit_types caravan_helped_utype
static

◆ city_map_index

struct iter_index* city_map_index = NULL
static

Definition at line 60 of file city.c.

Referenced by city_tile_index_to_xy(), free_city_map_index(), and generate_city_map_indices().

◆ city_map_numtiles

int city_map_numtiles[CITY_MAP_MAX_RADIUS_SQ+1]
static

Definition at line 67 of file city.c.

Referenced by city_map_tiles(), and generate_city_map_indices().

◆ city_map_xy

int city_map_xy[CITY_MAP_MAX_SIZE][CITY_MAP_MAX_SIZE]
static

Definition at line 64 of file city.c.

Referenced by city_tile_xy_to_index(), and generate_city_map_indices().

◆ city_styles

◆ output_types

struct output_type output_types[O_LAST]
Initial value:
= {
{O_FOOD, N_("Food"), "food", TRUE, UNHAPPY_PENALTY_SURPLUS},
{O_SHIELD, N_("Shield"), "shield", TRUE, UNHAPPY_PENALTY_SURPLUS},
{O_TRADE, N_("Trade"), "trade", TRUE, UNHAPPY_PENALTY_NONE},
{O_LUXURY, N_("Luxury"), "luxury", FALSE, UNHAPPY_PENALTY_NONE},
{O_SCIENCE, N_("Science"), "science", FALSE, UNHAPPY_PENALTY_ALL_PRODUCTION}
}
@ UNHAPPY_PENALTY_ALL_PRODUCTION
Definition city.h:253
@ UNHAPPY_PENALTY_NONE
Definition city.h:251
@ UNHAPPY_PENALTY_SURPLUS
Definition city.h:252
@ O_SHIELD
Definition fc_types.h:101
@ O_FOOD
Definition fc_types.h:101
@ O_TRADE
Definition fc_types.h:101
@ O_SCIENCE
Definition fc_types.h:101
@ O_LUXURY
Definition fc_types.h:101
@ O_GOLD
Definition fc_types.h:101
#define N_(String)
Definition fcintl.h:69
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47

Definition at line 88 of file city.c.

Referenced by city_tile_output(), get_city_dialog_output_text(), get_final_city_output_bonus(), get_output_identifier(), get_output_name(), get_output_type(), output_type_by_identifier(), set_city_bonuses(), and unhappy_city_check().