34 #define SPECENUM_NAME city_options
36 #define SPECENUM_VALUE0 CITYO_DISBAND
37 #define SPECENUM_VALUE0NAME "Disband"
39 #define SPECENUM_VALUE1 CITYO_SCIENCE_SPECIALISTS
40 #define SPECENUM_VALUE1NAME "Sci_Specialists"
42 #define SPECENUM_VALUE2 CITYO_GOLD_SPECIALISTS
43 #define SPECENUM_VALUE2NAME "Tax_Specialists"
44 #define SPECENUM_COUNT CITYO_LAST
45 #define SPECENUM_BITVECTOR bv_city_options
46 #include "specenum_gen.h"
50 #define CITY_MAP_MIN_RADIUS 0
51 #define CITY_MAP_DEFAULT_RADIUS 2
52 #define CITY_MAP_MAX_RADIUS 5
55 #define CITY_MAP_DEFAULT_RADIUS_SQ \
56 (CITY_MAP_DEFAULT_RADIUS * CITY_MAP_DEFAULT_RADIUS + 1)
57 #define CITY_MAP_MIN_RADIUS_SQ \
58 (CITY_MAP_MIN_RADIUS * CITY_MAP_MIN_RADIUS + 1)
59 #define CITY_MAP_MAX_RADIUS_SQ \
60 (CITY_MAP_MAX_RADIUS * CITY_MAP_MAX_RADIUS + 1)
62 #define CITY_MAP_CENTER_RADIUS_SQ -1
64 #define CITY_MAP_CENTER_TILE_INDEX 0
67 #define CITY_MAP_MAX_SIZE (CITY_MAP_MAX_RADIUS * 2 + 1)
69 #define INCITE_IMPOSSIBLE_COST (1000 * 1000 * 1000)
79 #define MAX_CITY_SIZE 0xFF
88 #define CITY_REL2ABS(_coor) (_coor + CITY_MAP_MAX_RADIUS)
89 #define CITY_ABS2REL(_coor) (_coor - CITY_MAP_MAX_RADIUS)
92 int city_tile_index,
int city_radius_sq);
100 #define city_map_tiles_from_city(_pcity) \
101 city_map_tiles(city_map_radius_sq_get(_pcity))
110 #define city_map_iterate_outwards_radius_sq_index( \
111 _radius_sq_min, _radius_sq_max, _index, _x, _y) \
113 fc_assert(_radius_sq_min <= _radius_sq_max); \
114 int _x = 0, _y = 0, _index; \
115 int _x##_y##_index = city_map_tiles(_radius_sq_min); \
117 city_tile_index_to_xy(&_x, &_y, _x##_y##_index, _radius_sq_max)) { \
118 _index = _x##_y##_index; \
121 #define city_map_iterate_outwards_radius_sq_index_end \
126 #define city_map_iterate_outwards_radius_sq(_radius_sq_min, _radius_sq_max, \
129 fc_assert(_radius_sq_min <= _radius_sq_max); \
130 int _x = 0, _y = 0; \
131 int _x##_y##_index = city_map_tiles(_radius_sq_min); \
133 city_tile_index_to_xy(&_x, &_y, _x##_y##_index, _radius_sq_max)) { \
136 #define city_map_iterate_outwards_radius_sq_end \
144 #define city_map_iterate(_radius_sq, _index, _x, _y) \
145 city_map_iterate_outwards_radius_sq_index(CITY_MAP_CENTER_RADIUS_SQ, \
146 _radius_sq, _index, _x, _y)
148 #define city_map_iterate_end city_map_iterate_outwards_radius_sq_index_end
150 #define city_map_iterate_without_index(_radius_sq, _x, _y) \
151 city_map_iterate_outwards_radius_sq(CITY_MAP_CENTER_RADIUS_SQ, \
154 #define city_map_iterate_without_index_end \
155 city_map_iterate_outwards_radius_sq_end
158 #define city_map_iterate_radius_sq(_radius_sq_min, _radius_sq_max, _x, _y) \
159 city_map_iterate_outwards_radius_sq(_radius_sq_min, _radius_sq_max, _x, _y)
161 #define city_map_iterate_radius_sq_end \
162 city_map_iterate_outwards_radius_sq_end
169 #define city_tile_iterate_index(_radius_sq, _city_tile, _tile, _index) \
171 city_map_iterate_outwards_radius_sq_index(CITY_MAP_CENTER_RADIUS_SQ, \
172 _radius_sq, _index, _x, \
173 _y) struct tile *_tile = \
174 city_map_to_tile(_city_tile, _radius_sq, _x, _y); \
175 if (nullptr != _tile) {
177 #define city_tile_iterate_index_end \
180 city_map_iterate_outwards_radius_sq_index_end;
183 #define city_tile_iterate_skip_center(_radius_sq, _city_tile, _tile, \
186 city_map_iterate(_radius_sq, _index, _x, _y) \
188 if (!is_city_center_index(_index)) { \
189 struct tile *_tile = \
190 city_map_to_tile(_city_tile, _radius_sq, _x, _y); \
191 if (nullptr != _tile) {
193 #define city_tile_iterate_skip_center_end \
197 city_map_iterate_end; \
202 #define city_tile_iterate(_radius_sq, _city_tile, _tile) \
204 city_map_iterate_outwards_radius_sq( \
205 CITY_MAP_CENTER_RADIUS_SQ, _radius_sq, _x, _y) struct tile *_tile = \
206 city_map_to_tile(_city_tile, _radius_sq, _x, _y); \
207 if (nullptr != _tile) {
209 #define city_tile_iterate_end \
212 city_map_iterate_outwards_radius_sq_end;
220 #define I_DESTROYED (-2)
423 void *
ais[FREECIV_AI_MOD_LAST];
470 struct requirement_vector
reqs;
478 #define SPECLIST_TAG city
479 #define SPECLIST_TYPE struct city
482 #define city_list_iterate(citylist, pcity) \
483 TYPED_LIST_ITERATE(struct city, citylist, pcity)
484 #define city_list_iterate_end LIST_ITERATE_END
486 #define cities_iterate(pcity) \
488 players_iterate(pcity##_player) \
490 city_list_iterate(pcity##_player->cities, pcity) \
493 #define cities_iterate_end \
495 city_list_iterate_end; \
497 players_iterate_end; \
500 #define city_list_iterate_safe(citylist, _city) \
502 int _city##_size = city_list_size(citylist); \
504 if (_city##_size > 0) { \
505 int _city##_numbers[_city##_size]; \
506 int _city##_index = 0; \
508 city_list_iterate(citylist, _city) \
510 _city##_numbers[_city##_index++] = _city->id; \
512 city_list_iterate_end; \
514 for (_city##_index = 0; _city##_index < _city##_size; \
516 struct city *_city = \
517 game_city_by_number(_city##_numbers[_city##_index]); \
519 if (nullptr != _city) {
521 #define city_list_iterate_safe_end \
534 const struct city *pcity,
int *output,
535 const std::vector<std::array<int, O_LAST>> *pcsoutputs =
nullptr);
537 struct city *pcity,
const std::vector<city *> &gov_centers,
538 const std::array<cached_waste, O_LAST> *pcwaste =
nullptr);
561 const struct city *pcity);
606 bool add_production,
int *num_units);
611 enum impr_flag_id flag);
613 bool include_shield_stock);
621 bool include_shield_stock);
637 const int city_map_y);
639 const struct tile *map_tile);
641 const struct city *
const pcity,
642 const struct tile *map_tile);
644 const int city_radius_sq,
645 const struct tile *city_center,
646 const struct tile *map_tile);
649 int city_radius_sq,
int city_map_x,
665 const struct city *pcity,
666 const struct tile *ptile);
672 const struct unit *punit);
685 const struct player *pplayer);
687 const struct player *pplayer);
689 const struct player *pplayer);
691 const struct player *pplayer);
695 const struct tile *ptile);
697 bool may_be_on_center);
709 struct city *pcity,
bool *workers_map,
710 const std::vector<city *> &gov_centers,
711 const std::array<cached_waste, O_LAST> *pcwaste =
nullptr,
712 const std::vector<std::array<int, O_LAST>> *pcsoutputs =
nullptr);
714 int *breakdown,
const std::vector<city *> &gov_centers,
717 const struct city *pcity);
736 int trade_total,
int *pollu_prod,
int *pollu_trade,
737 int *pollu_pop,
int *pollu_mod);
741 int *ill_trade,
int *ill_pollution);
752 #define city_built_iterate(_pcity, _p) \
753 improvement_iterate(_p) \
755 if ((_pcity)->built[improvement_index(_p)].turn <= I_NEVER) { \
759 #define city_built_iterate_end \
761 improvement_iterate_end;
764 #define output_type_iterate(output) \
768 for (ioutput = 0; ioutput < O_LAST; ioutput++) { \
769 Output_type_id output = (enum output_type_id) ioutput;
771 #define output_type_iterate_end \
778 #define is_city_center_index(city_tile_index) \
779 (CITY_MAP_CENTER_TILE_INDEX == city_tile_index)
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...
bool city_is_virtual(const struct city *pcity)
Return TRUE if the city is a virtual city.
bool citymindist_prevents_city_on_tile(const struct tile *ptile)
Returns TRUE iff it is illegal to found a city on the specified tile because of citymindist.
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.
struct output_type * get_output_type(Output_type_id output)
Return the output type for this index.
bool city_exists_within_max_city_map(const struct tile *ptile, bool may_be_on_center)
Return TRUE iff a city exists within a city radius of the given location.
int rs_max_city_radius_sq()
Maximum city radius in this ruleset.
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_WON...
void city_map_radius_sq_set(struct city *pcity, int radius_sq)
Returns the current squared radius of the city.
int city_production_build_shield_cost(const struct city *pcity)
Return the number of shields it takes to build current city production.
bool can_city_build_unit_later(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 p...
int city_granary_size(int city_size)
Generalized formula used to calculate granary size.
citizens player_angry_citizens(const struct player *pplayer)
Give base number of angry citizens in any city owned by pplayer.
void city_set_ai_data(struct city *pcity, const struct ai_type *ai, void *data)
Attach ai data to city.
@ UNHAPPY_PENALTY_ALL_PRODUCTION
@ UNHAPPY_PENALTY_SURPLUS
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...
bool can_city_build_now(const struct city *pcity, const struct universal *target)
Returns whether city can immediately build given target, unit or improvement.
void city_styles_free()
De-allocate the memory used by the city styles.
struct city * city_list_find_number(struct city_list *This, int id)
Find city with given id from list.
struct city * is_non_allied_city_tile(const struct tile *ptile, const struct player *pplayer)
Is there an non_allied city on this tile?
int city_build_slots(const struct city *pcity)
The maximum number of units a city can build per turn.
bool city_has_building(const struct city *pcity, const struct impr_type *pimprove)
Return TRUE iff the city has this building in it.
struct city * is_enemy_city_tile(const struct tile *ptile, const struct player *pplayer)
Is there an enemy city on this tile?
struct player * city_owner(const struct city *pcity)
Return the owner of the city.
int player_base_citizen_happiness(const struct player *pplayer)
Give base happiness in any city owned by pplayer.
struct city * is_allied_city_tile(const struct tile *ptile, const struct player *pplayer)
Is there an friendly city on this tile?
Output_type_id output_type_by_identifier(const char *id)
Find the output type for this output identifier.
bool is_capital(const struct city *pcity)
Return TRUE iff this city is its nation's capital.
void citylog_map_workers(QtMsgType level, struct city *pcity)
Display the location of the workers within the city map of pcity.
struct citystyle * city_styles
int city_improvement_upkeep(const struct city *pcity, const struct impr_type *pimprove)
Return the upkeep (gold) needed each turn to upkeep the given improvement in the given city.
void city_styles_alloc(int num)
Allocate memory for this amount of city styles.
struct city * is_non_attack_city_tile(const struct tile *ptile, const struct player *pplayer)
Is there an enemy city on this 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 ...
int city_unit_slots_available(const struct city *pcity)
Return number of free unit slots in a city.
void city_remove_improvement(struct city *pcity, const struct impr_type *pimprove)
Removes an improvement (and its effects) from a city.
int city_airlift_max(const struct city *pcity)
A city's maximum airlift capacity.
bool is_city_option_set(const struct city *pcity, enum city_options option)
Returns TRUE iff the city has set the given option.
int city_population(const struct city *pcity)
Returns how many thousand citizen live in this city.
struct tile * city_tile(const struct city *pcity)
Return the tile location of the city.
void city_size_add(struct city *pcity, int add)
Add a (positive or negative) value to the city size.
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.
bool city_production_has_flag(const struct city *pcity, enum impr_flag_id flag)
Return TRUE when the current production has this flag.
bool city_is_occupied(const struct city *pcity)
Returns TRUE iff the city is occupied.
struct tile * city_map_to_tile(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.
bool city_can_be_built_tile_only(const struct tile *ptile)
Returns TRUE if the given unit can build a city at the given map coordinates.
int city_production_unit_veteran_level(struct city *pcity, const struct unit_type *punittype)
How many veteran levels will created unit of this type get?
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).
bool can_city_build_improvement_now(const struct city *pcity, const struct impr_type *pimprove)
Return whether given city can build given building; returns FALSE if the building is obsolete.
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.
bool city_got_defense_effect(const struct city *pcity, const struct unit_type *attacker)
This can be City Walls, Coastal defense...
bool city_can_be_built_here(const struct tile *ptile, const struct unit *punit)
Returns TRUE if the given unit can build a city at the given map coordinates.
int city_pollution(const struct city *pcity, int shield_total, int trade_total)
Calculate pollution for the city.
citizens player_content_citizens(const struct player *pplayer)
Give base number of content citizens in any city owned by pplayer.
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.
int get_city_tithes_bonus(const struct city *pcity)
Return the amount of gold generated by buildings under "tithe" attribute governments.
const char * city_name_get(const struct city *pcity)
Return the name of the city.
bool city_rapture_grow(const struct city *pcity)
Returns whether city is growing by rapture.
void * city_ai_data(const struct city *pcity, const struct ai_type *ai)
Return pointer to ai data of given city and ai type.
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.
bool city_unhappy(const struct city *pcity)
Return TRUE iff the city is unhappy.
Specialist_type_id best_specialist(Output_type_id otype, const struct city *pcity)
Return the "best" specialist available in the game.
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.
void city_refresh_from_main_map(struct city *pcity, bool *workers_map, const std::vector< city * > &gov_centers, const std::array< cached_waste, O_LAST > *pcwaste=nullptr, const std::vector< std::array< int, O_LAST >> *pcsoutputs=nullptr)
Refreshes the internal cached data in the city structure.
bool city_celebrating(const struct city *pcity)
cities celebrate only after consecutive happy turns
const char * city_improvement_name_translation(const struct city *pcity, const struct impr_type *pimprove)
Return the extended name of the building.
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.
void generate_city_map_indices()
Fill the arrays city_map_index, city_map_xy and city_map_numtiles.
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:
int city_unit_unhappiness(const unit *punit, int *free_unhappy)
Query unhappiness caused by a given unit.
bool city_can_grow_to(const struct city *pcity, int pop_size)
Return TRUE iff the city can grow to the given size.
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...
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...
void citylog_map_data(QtMsgType 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.
bool city_happy(const struct city *pcity)
Return TRUE iff the city is happy.
void city_size_set(struct city *pcity, citizens size)
Set the city size.
void city_add_improvement(struct city *pcity, const struct impr_type *pimprove)
Adds an improvement (and its effects) to a city.
void add_specialist_output(const struct city *pcity, int *output, const std::vector< std::array< int, O_LAST >> *pcsoutputs=nullptr)
Calculate output (gold, science, and luxury) generated by the specialists of a city.
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.
int city_map_radius_sq_get(const struct city *pcity)
Returns the current squared radius of the city.
bool can_city_build_direct(const struct city *pcity, const struct universal *target)
Returns whether city can immediately build given target, unit or improvement.
const char * get_output_identifier(Output_type_id output)
Return an id string for the output type.
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.
void destroy_city_virtual(struct city *pcity)
Removes the virtual skeleton of a city.
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.
citizens city_specialists(const struct city *pcity)
Give the number of specialists in a city.
struct city * city_list_find_name(struct city_list *This, const char *name)
Find city with given name from list.
const char * city_style_rule_name(const int style)
Return the (untranslated) rule name of the city style.
const Output_type_id num_output_types
void city_choose_build_default(struct city *pcity)
Always tile_set_owner(ptile, pplayer) sometime before this!
bool can_city_build_later(const struct city *pcity, const struct universal *target)
Returns whether city can ever build given target, unit or improvement.
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.
void set_city_production(struct city *pcity, const std::vector< city * > &gov_centers, const std::array< cached_waste, O_LAST > *pcwaste=nullptr)
Set food, trade and shields production in a city.
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.
bool is_gov_center(const struct city *pcity)
Return TRUE iff this city is governmental center.
int city_map_tiles(int city_radius_sq)
Return the number of tiles for the given city radius.
bool is_unit_near_a_friendly_city(const struct unit *punit)
Return TRUE if there is a friendly city near to this unit (within 3 steps).
bool can_city_build_unit_direct(const struct city *pcity, const struct unit_type *punittype)
Return whether given city can build given unit, ignoring whether unit is obsolete.
void free_city_map_index()
Free memory allocated by generate_citymap_index.
int city_pollution_types(const struct city *pcity, int shield_total, int trade_total, int *pollu_prod, int *pollu_trade, int *pollu_pop, int *pollu_mod)
Calculate the pollution from production and population in the city.
bool city_exist(int id)
Check if city with given id still exist.
bool is_city_center(const struct city *pcity, const struct tile *ptile)
Return TRUE if the city is centered at the given tile.
bool city_can_work_tile(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 ...
struct city * create_city_virtual(struct player *pplayer, struct tile *ptile, const char *name)
Create virtual skeleton for a city.
const char * get_output_name(Output_type_id output)
Return a translated name for the output type.
int compare_iter_index(const void *a, const void *b)
Compare two iter_index values from the city_map_index.
int city_waste(const struct city *pcity, Output_type_id otype, int total, int *breakdown, const std::vector< city * > &gov_centers, const cached_waste *pcwaste=nullptr)
Give corruption/waste generated by city.
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.
int city_turns_to_grow(const struct city *pcity)
Calculates the turns which are needed for the city to grow.
citizens city_size_get(const struct city *pcity)
Get the city size.
struct output_type output_types[]
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 c...
const char * city_production_name_translation(const struct city *pcity)
Return the extended name of the current production.
bool city_had_recent_plague(const struct city *pcity)
Returns whether city had a plague outbreak this turn.
bool city_can_change_build(const struct city *pcity)
Returns TRUE iff the given city can change what it is building.
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.
int city_style_by_rule_name(const char *s)
Returns the city style that has the given (untranslated) rule name.
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.
bool can_city_build_unit_now(const struct city *pcity, const struct unit_type *punittype)
Return whether given city can build given unit; returns FALSE if unit is obsolete.
void city_production_caravan_shields_init()
Initialize the cache of what city production can use shields from caravans.
bool is_friendly_city_near(const struct player *owner, const struct tile *ptile)
Return TRUE if there is a friendly city near to this tile (within 3 steps).
enum output_type_id Output_type_id
struct setting_list * level[OLEVELS_NUM]
Used to cache the value of waste effects to speed up governors.
struct worker_task_list * task_reqs
struct tile_cache * tile_cache
struct city::@15::@18 client
struct city::@14 rally_point
struct built_status built[B_LAST]
int saved_surplus[O_LAST]
int last_turns_shield_surplus
enum capital_type capital
struct unit_list * info_units_present
bv_city_options city_options
citizens unit_happy_upkeep
time_t prod_change_timestamp
struct unit_list * info_units_supported
void * ais[FREECIV_AI_MOD_LAST]
struct trade_route_list * routes
struct universal production
struct unit_order * orders
struct unit_list * collecting_info_units_supported
int unhappy_penalty[O_LAST]
char name[MAX_LEN_CITYNAME]
unsigned char first_citizen_index
int before_change_shields
struct city::@15::@17 server
struct unit_list * collecting_info_units_present
citizens feel[CITIZEN_LAST][FEELING_LAST]
citizens specialists[SP_MAX]
struct cm_parameter * cm_parameter
struct universal changed_from
struct unit_list * units_supported
enum city_updates need_updates
struct requirement_vector reqs
char citizens_graphic[MAX_LEN_NAME]
char graphic_alt[MAX_LEN_NAME]
struct name_translation name
char graphic[MAX_LEN_NAME]
char citizens_graphic_alt[MAX_LEN_NAME]
The base class for options.
enum output_unhappy_penalty unhappy_penalty