51 static char *
citylog_map_line(
int y,
int city_radius_sq,
int *city_map_data);
54 static void citylog_map_index(QtMsgType
level);
55 static void citylog_map_radius_sq(QtMsgType
level);
96 int city_tile_index,
int city_radius_sq)
102 if (city_tile_index < 0
154 int max_rad =
game.
info.init_city_radius_sq
182 const int city_map_y)
250 return dist <= city_radius_sq;
258 const int city_radius_sq,
259 const struct tile *city_center,
260 const struct tile *map_tile)
275 const struct city *
const pcity,
276 const struct tile *map_tile)
287 const struct tile *map_tile)
299 int city_radius_sq,
int city_map_x,
317 static int cmp(
int v1,
int v2)
321 }
else if (v1 > v2) {
341 value =
cmp(index1->
dist, index2->dist);
346 value =
cmp(index1->
dx, index2->dx);
351 value =
cmp(index1->
dy, index2->dy);
361 #define CITYLOG_MAX_VAL 9999
365 static char citylog[128], tmp[8];
379 fc_snprintf(tmp,
sizeof(tmp),
"%5d", city_map_data[mindex]);
397 #undef CITYLOG_MAX_VAL
407 char line[128], tmp[8];
437 int *city_map_data =
nullptr;
447 city_map_data[cindex] = (ptile &&
tile_worked(ptile) == pcity)
455 delete[] city_map_data;
462 static void citylog_map_index(QtMsgType
level)
468 city_map_data[cindex] = cindex;
479 static void citylog_map_radius_sq(QtMsgType
level)
485 city_map_data[cindex] =
501 int i, dx, dy, city_x, city_y, dist, city_count_tiles = 0;
520 city_map_index_tmp[city_count_tiles].
dx =
dx;
521 city_map_index_tmp[city_count_tiles].
dy =
dy;
522 city_map_index_tmp[city_count_tiles].
dist =
dist;
543 for (i = 0; i < city_count_tiles; i++) {
551 for (i = 0; i < city_count_tiles; i++) {
565 for (i = 0; i < city_count_tiles; i++) {
568 log_debug(
"[%2d]: (dx,dy) = (%+2d,%+2d), (x,y) = (%2d,%2d), "
569 "dist = %2d, check = %2d",
622 for (
int o = 0; o <
O_LAST; o++) {
638 static char buffer[256];
639 const char *state =
nullptr;
643 state =
Q_(
"?wonder:W");
645 state =
Q_(
"?destroyed:D");
647 state =
Q_(
"?built:B");
654 state =
Q_(
"?obsolete:O");
656 state =
Q_(
"?redundant:*");
674 static char buffer[256];
677 case VUT_IMPROVEMENT:
692 enum impr_flag_id flag)
712 bool add_production,
int *num_units)
718 int unit_shield_cost, i;
736 if (add_production) {
742 for (i = 0; i < build_slots; i++) {
743 if (shields_left < unit_shield_cost) {
749 shields_left -= unit_shield_cost;
753 if (target.
kind != VUT_UTYPE
775 levels =
CLIP(0, levels, max_levels);
785 bool include_shield_stock)
788 include_shield_stock);
807 pcity->
tile,
nullptr,
nullptr,
nullptr,
nullptr,
846 pcity->
tile,
nullptr,
nullptr,
nullptr,
nullptr,
869 city_tile(pcity),
nullptr, punittype,
nullptr,
938 switch (target->
kind) {
941 case VUT_IMPROVEMENT:
956 switch (target->
kind) {
959 case VUT_IMPROVEMENT:
973 switch (target->
kind) {
976 case VUT_IMPROVEMENT:
999 return max - current;
1009 nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
1073 #ifndef city_name_get
1087 return pcity->
owner;
1149 int gold_needed = 0;
1170 int gold_needed = 0;
1179 gold_needed += punit->upkeep[
O_GOLD];
1192 if (
nullptr == pimprove) {
1236 struct player *pplayer =
nullptr;
1246 prod = pterrain->
output[otype];
1251 if (pcity !=
nullptr) {
1260 nullptr, pplayer,
nullptr, pcity,
nullptr, ptile,
nullptr,
1261 nullptr,
nullptr,
nullptr,
nullptr, EFT_MINING_PCT)
1269 nullptr, pplayer,
nullptr, pcity,
nullptr, ptile,
nullptr,
1270 nullptr,
nullptr,
nullptr,
nullptr, EFT_IRRIGATION_PCT)
1290 if (is_celebrating) {
1292 EFT_OUTPUT_INC_TILE_CELEBRATE);
1300 if (!is_celebrating && penalty_limit > 0 && prod > penalty_limit) {
1307 EFT_OUTPUT_TILE_PUNISH_PCT))
1311 prod =
MAX(prod,
game.
info.min_city_center_output[otype]);
1340 const struct city *pcity,
1341 const struct tile *ptile)
1344 int city_map_x, city_map_y;
1346 if (
nullptr == ptile) {
1354 if (
nullptr != restriction
1368 if (powner == restriction
1404 int citymindist =
game.
info.citymindist;
1424 const struct unit *punit)
1430 if (punit ==
nullptr) {
1446 USP_LIVABLE_TILE,
false)) {
1497 return pcity->
capital != CAPITAL_NOT;
1591 return pcity->
client.occupied;
1603 if (pcity->id ==
id) {
1635 const char *qs =
Qn_(s);
1668 #define log_ca_s_init log_debug
1675 prod_as_req.
range = REQ_RANGE_LOCAL;
1745 #undef log_ca_s_init
1754 switch (tgt->
kind) {
1755 case VUT_IMPROVEMENT:
1780 int shield_stock_after_adjustment;
1783 int unpenalized_shields = 0, penalized_shields = 0;
1786 case VUT_IMPROVEMENT:
1801 switch (target->
kind) {
1802 case VUT_IMPROVEMENT:
1818 if (orig_class == new_class || orig_class ==
PCT_LAST) {
1825 unpenalized_shields =
1835 && ((target->
kind == VUT_UTYPE
1855 shield_stock_after_adjustment =
1856 unpenalized_shields + penalized_shields / 2;
1858 return shield_stock_after_adjustment;
1867 bool include_shield_stock)
1870 int city_shield_stock = include_shield_stock
1875 if (target->
kind == VUT_IMPROVEMENT
1881 if (include_shield_stock && (city_shield_stock >= cost)) {
1883 }
else if (city_shield_surplus > 0) {
1884 return (cost - city_shield_stock - 1) / city_shield_surplus + 1;
1924 const struct player *pplayer)
1939 const struct player *pplayer)
1954 const struct player *pplayer)
1969 const struct player *pplayer)
1994 const struct tile *ptile)
2014 bool may_be_on_center)
2018 if (may_be_on_center || !
same_pos(ptile, ptile1)) {
2036 int food_inis =
game.
info.granary_num_inis;
2037 int food_inc =
game.
info.granary_food_inc;
2041 if (city_size == 0) {
2047 if (city_size > food_inis) {
2048 base_value =
game.
info.granary_food_ini[food_inis - 1];
2049 base_value += food_inc * (city_size - food_inis);
2051 base_value =
game.
info.granary_food_ini[city_size - 1];
2054 return MAX(base_value *
game.
info.foodbox / 100, 1);
2069 if (basis +
step <= 0) {
2123 EFT_OUTPUT_BONUS_2);
2125 return MAX(bonus1 * bonus2 / 100, 0);
2134 int tithes_bonus = 0;
2143 return tithes_bonus;
2152 const int SCIENCE = 0, TAX = 1, LUXURY = 2;
2153 int rates[3], result[3];
2158 rates[TAX] = 100 - rates[SCIENCE] - rates[LUXURY];
2160 rates[SCIENCE] =
game.
info.forced_science;
2161 rates[LUXURY] =
game.
info.forced_luxury;
2162 rates[TAX] =
game.
info.forced_gold;
2168 rates[LUXURY] = 100;
2175 output[
O_GOLD] += result[TAX];
2176 output[
O_LUXURY] += result[LUXURY];
2197 int *output,
bool *workers_map)
2200 #ifdef CITY_DEBUGGING
2205 memset(output, 0,
O_LAST *
sizeof(*output));
2210 if (workers_map ==
nullptr) {
2213 is_worked = (
nullptr != pwork && pwork == pcity);
2215 is_worked = workers_map[city_tile_index];
2221 #ifdef CITY_DEBUGGING
2240 const struct city *pcity,
int *output,
2241 const std::vector<std::array<int, O_LAST>> *pcsoutputs)
2252 pcsoutputs =
nullptr);
2256 int amount = pcsoutputs
2257 ? pcsoutputs->at(sp)[stat_index]
2260 output[stat_index] += count * amount;
2315 (pcity->
tile_cache[city_tile_index]).output[o] =
2328 int city_tile_index,
2335 return (pcity->
tile_cache[city_tile_index]).output[o];
2358 pcity->
feel[c][i] = pcity->
feel[c][i - 1];
2383 *content =
MAX(0,
MIN(
size, base_content) - spes);
2387 *angry =
MIN(base_angry,
size - spes);
2392 *unhappy = (
size - spes - *content - *angry);
2411 while (*luxuries >=
game.
info.happy_cost && *angry > 0) {
2417 while (*luxuries >=
game.
info.happy_cost && *content > 0) {
2423 while (*luxuries >= 2 *
game.
info.happy_cost && *unhappy > 0) {
2428 *luxuries -= 2 *
game.
info.happy_cost;
2430 if (*luxuries >=
game.
info.happy_cost && *unhappy > 0) {
2460 while (faces > 0 && *angry > 0) {
2465 while (faces > 0 && *unhappy > 0) {
2481 if (
game.
info.citizen_nationality) {
2492 enemies += nationality;
2497 unhappy_inc = enemies * pct / 100;
2501 while (unhappy_inc > 0 && *content > 0) {
2506 while (unhappy_inc > 1 && *happy > 0) {
2511 while (unhappy_inc > 0 && *happy > 0) {
2536 while (amt > 0 && *angry > 0) {
2541 while (amt > 0 && *unhappy > 0) {
2551 while (amt > 0 && *content > 0) {
2556 while (amt > 1 && *happy > 0) {
2561 while (amt > 0 && *happy > 0) {
2584 while (bonus > 0 && *content > 0) {
2589 while (bonus > 1 && *unhappy > 0) {
2597 *content += *unhappy + *angry;
2606 while (bonus > 0 && *angry > 0) {
2611 while (bonus > 0 && *unhappy > 0) {
2652 int trade_total,
int *pollu_prod,
int *pollu_trade,
2653 int *pollu_pop,
int *pollu_mod)
2655 int prod, trade, pop, mod;
2659 prod = shield_total *
MAX(prod, 0) / 100;
2663 trade = trade_total *
MAX(trade, 0) / 100;
2677 *pollu_trade = trade;
2685 return MAX(prod + trade + pop + mod, 0);
2696 nullptr,
nullptr,
nullptr);
2708 float illness_trade = 0.0;
2715 static_cast<float>(
game.
info.illness_trade_infection)
2722 return static_cast<int>(illness_trade);
2747 int *ill_trade,
int *ill_pollution)
2749 int illness_size = 0, illness_trade = 0, illness_pollution = 0;
2750 int illness_base, illness_percent;
2758 static_cast<int>((1.0 - exp(-
static_cast<float>(use_size) / 10.0))
2759 * 10.0 *
game.
info.illness_base_factor);
2774 illness_base = illness_size + illness_trade + illness_pollution;
2779 *ill_size = illness_size;
2783 *ill_trade = illness_trade;
2786 if (ill_pollution) {
2787 *ill_pollution = illness_pollution;
2791 *ill_base = illness_base;
2794 return CLIP(0, illness_base * illness_percent / 100, 999);
2831 const std::vector<city *> &gov_centers,
2832 const std::array<cached_waste, O_LAST> *pcwaste)
2877 proute->value * (100 +
get_city_bonus(pcity, EFT_TRADEROUTE_PCT))
2897 gov_centers, pcwaste ? &pcwaste->at(o) :
nullptr);
2928 if (!punit || !free_unhappy) {
2933 if (pcity ==
nullptr) {
2941 if (happy_cost <= 0) {
2952 if (happy_cost <= 0) {
2956 if (*free_unhappy >= happy_cost) {
2957 *free_unhappy -= happy_cost;
2960 happy_cost -= *free_unhappy;
2973 int free_unhappy, martial_law_each;
2989 "Invalid gold_upkeep_style %d",
game.
info.gold_upkeep_style);
2990 switch (
game.
info.gold_upkeep_style) {
2991 case GOLD_UPKEEP_CITY:
2994 case GOLD_UPKEEP_MIXED:
2997 case GOLD_UPKEEP_NATION:
3007 if (martial_law_each > 0) {
3009 int martial_law_max =
get_city_bonus(pcity, EFT_MARTIAL_LAW_MAX);
3013 if ((count < martial_law_max || martial_law_max == 0)
3032 pcity->
usage[o] += punit->upkeep[o];
3053 struct city *pcity,
bool *workers_map,
3054 const std::vector<city *> &gov_centers,
3055 const std::array<cached_waste, O_LAST> *pcwaste,
3056 const std::vector<std::array<int, O_LAST>> *pcsoutputs)
3058 if (workers_map ==
nullptr) {
3109 int *breakdown,
const std::vector<city *> &gov_centers,
3112 int penalty_waste = 0;
3113 int penalty_size = 0;
3115 int total_eft = total;
3125 bool waste_all =
false;
3137 penalty_size = total_eft;
3141 penalty_size = total_eft * (fulltradesize -
city_size_get(pcity))
3142 / (fulltradesize - notradesize);
3147 total_eft -= penalty_size;
3151 if (total_eft > 0) {
3159 const struct city *gov_center =
nullptr;
3168 for (
const auto gc : gov_centers) {
3173 if (dist < min_dist) {
3181 if (gov_center ==
nullptr) {
3184 waste.level +=
waste.by_distance * min_dist / 100;
3185 if (
waste.by_rel_distance > 0) {
3189 waste.level +=
waste.by_rel_distance * 50 * min_dist / 100
3197 penalty_waste = total_eft;
3201 EFT_OUTPUT_WASTE_PCT);
3205 if (
waste.level > 0) {
3206 penalty_waste = total_eft *
waste.level / 100;
3210 penalty_waste -= penalty_waste *
waste.relative / 100;
3213 penalty_waste =
MIN(
MAX(penalty_waste, 0), total_eft);
3222 return penalty_waste + penalty_size;
3248 const struct city *pcity)
3290 log_debug(
"Improvement %s removed from city %s",
3356 struct city *pcity =
new city[1]();
3360 pcity->
tile = ptile;
3361 pcity->
owner = pplayer;
3395 pcity->
routes = trade_route_list_new();
3396 pcity->
task_reqs = worker_task_list_new();
3399 pcity->
server.mgr_score_calc_turn = -1;
3401 pcity->
server.prod_change_timestamp = time(NULL);
3406 pcity->
client.info_units_supported =
3408 pcity->
client.info_units_present =
3427 while (worker_task_list_size(pcity->
task_reqs) > 0) {
3430 worker_task_list_remove(pcity->
task_reqs, ptask);
3434 worker_task_list_destroy(pcity->
task_reqs);
3437 trade_route_list_destroy(pcity->
routes);
3444 unit_list_destroy(pcity->
client.info_units_supported);
3445 unit_list_destroy(pcity->
client.info_units_present);
3448 if (pcity->
client.collecting_info_units_supported !=
nullptr) {
3449 unit_list_destroy(pcity->
client.collecting_info_units_supported);
3451 if (pcity->
client.collecting_info_units_present !=
nullptr) {
3452 unit_list_destroy(pcity->
client.collecting_info_units_present);
3456 memset(pcity, 0,
sizeof(*pcity));
struct action_enabler_list * action_enablers_for_action(action_id action)
Get all enablers for an action in the current ruleset.
#define action_enabler_list_iterate_end
#define action_by_result_iterate_end
#define action_by_result_iterate(_paction_, _act_id_, _result_)
#define action_enabler_list_iterate(action_enabler_list, aenabler)
int ai_type_number(const struct ai_type *ai)
Returns id of the given ai_type.
#define CALL_FUNC_EACH_AI(_func,...)
bool BV_ISSET(const BV &bv, int bit)
void citizens_free(struct city *pcity)
Free citizens data.
#define citizens_foreign_iterate_end
#define citizens_foreign_iterate(_pcity, _pslot, _nationality)
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.
static void citizen_luxury_happy(struct city *pcity, int *luxuries)
Make people happy: angry citizen are eliminated first then content are made happy,...
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.
static void citizen_content_buildings(struct city *pcity)
Make citizens content due to city improvements.
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...
static bv_imprs caravan_helped_impr
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.
static void city_tile_cache_update(struct city *pcity)
This function sets the cache for the tile outputs, the pcity->tile_cache[] array.
void city_set_ai_data(struct city *pcity, const struct ai_type *ai, void *data)
Attach ai data to city.
static void get_worked_tile_output(const struct city *pcity, int *output, bool *workers_map)
Calculate output (food, trade and shields) generated by the worked tiles of a city.
static void citizen_happy_wonders(struct city *pcity)
Make citizens happy due to wonders.
void add_specialist_output(const struct city *pcity, int *output, const std::vector< std::array< int, O_LAST >> *pcsoutputs)
Calculate output (gold, science, and luxury) generated by the specialists of a city.
static void city_support(struct city *pcity)
Calculate upkeep costs.
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.
static int city_tile_cache_get_output(const struct city *pcity, int city_tile_index, enum output_type_id o)
This function returns the output of 'o' for the city tile 'city_tile_index' of 'pcity'.
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
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_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.
int city_airlift_max(const struct city *pcity)
A city's maximum airlift capacity.
void set_city_production(struct city *pcity, const std::vector< city * > &gov_centers, const std::array< cached_waste, O_LAST > *pcwaste)
Set food, trade and shields production in a city.
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.
static struct iter_index * city_map_index
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.
static int city_map_numtiles[CITY_MAP_MAX_RADIUS_SQ+1]
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.
static bv_unit_types caravan_helped_utype
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.
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...
static int get_city_health(const struct city *pcity)
Get any effects regarding health from the buildings of the city.
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.
static void set_city_bonuses(struct city *pcity)
This function sets all the values in the pcity->bonus[] array.
static void set_surpluses(struct city *pcity)
Set the final surplus[] array from the prod[] and usage[] values.
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.
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.
static char * citylog_map_line(int y, int city_radius_sq, int *city_map_data)
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.
static int cmp(int v1, int v2)
Compare two integer values, as required by qsort.
#define CITYLOG_MAX_VAL
Return one line (y coordinate) of a city map.
void city_choose_build_default(struct city *pcity)
Always tile_set_owner(ptile, pplayer) sometime before this!
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)
Give corruption/waste generated by city.
static void citizen_happiness_nationality(struct city *pcity)
Apply effects of citizen nationality to happiness.
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.
static int city_map_xy[CITY_MAP_MAX_SIZE][CITY_MAP_MAX_SIZE]
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.
static void citizen_happy_luxury(struct city *pcity)
Make citizens happy due to luxury.
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, const std::vector< std::array< int, O_LAST >> *pcsoutputs)
Refreshes the internal cached data in the city structure.
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).
static void unhappy_city_check(struct city *pcity)
Set food, tax, science and shields production to zero if city is in disorder.
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.
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.
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.
struct output_type output_types[O_LAST]
bool city_had_recent_plague(const struct city *pcity)
Returns whether city had a plague outbreak this turn.
static int get_trade_illness(const struct city *pcity)
Gets whether cities that pcity trades with had the plague.
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.
static void citizen_base_mood(struct city *pcity)
Create content, unhappy and angry citizens.
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.
static void citizen_happy_units(struct city *pcity)
Make citizens happy/unhappy due to units.
static void happy_copy(struct city *pcity, enum citizen_feeling i)
Copy the happyness array in the city to index i from index i-1.
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).
#define city_list_iterate(citylist, pcity)
#define city_tile_iterate(_radius_sq, _city_tile, _tile)
@ UNHAPPY_PENALTY_ALL_PRODUCTION
@ UNHAPPY_PENALTY_SURPLUS
#define CITY_MAP_MAX_RADIUS_SQ
#define CITY_MAP_MAX_SIZE
#define city_tile_iterate_index_end
#define CITY_MAP_CENTER_RADIUS_SQ
#define CITY_MAP_MIN_RADIUS_SQ
#define output_type_iterate(output)
#define CITY_REL2ABS(_coor)
#define city_list_iterate_end
#define city_map_iterate_end
#define is_city_center_index(city_tile_index)
#define city_map_iterate(_radius_sq, _index, _x, _y)
#define city_tile_iterate_end
#define CITY_MAP_MAX_RADIUS
#define city_built_iterate(_pcity, _p)
#define city_tile_iterate_index(_radius_sq, _city_tile, _tile, _index)
#define city_map_tiles_from_city(_pcity)
#define CITY_ABS2REL(_coor)
#define city_built_iterate_end
#define output_type_iterate_end
void cm_init_citymap()
Initialize the CM citymap data.
void distribute(int number, int groups, int *ratios, int *result)
Distribute "number" elements into "groups" groups with ratios given by the elements in "ratios".
int get_target_bonus_effects(struct effect_list *plist, const struct player *target_player, const struct player *other_player, const struct city *target_city, const struct impr_type *target_building, const struct tile *target_tile, const struct unit *target_unit, const struct unit_type *target_unittype, const struct output_type *target_output, const struct specialist *target_specialist, const struct action *target_action, enum effect_type effect_type, enum vision_layer vision_layer, enum national_intelligence nintel)
Returns the effect bonus of a given type for any target.
int get_tile_output_bonus(const struct city *pcity, const struct tile *ptile, const struct output_type *poutput, enum effect_type effect_type)
Returns the effect bonus at a tile for given output type (or nullptr for output-type-independent bonu...
int get_unittype_bonus(const struct player *pplayer, const struct tile *ptile, const struct unit_type *punittype, enum effect_type effect_type, enum vision_layer vision_layer)
Returns the effect bonus that applies at a tile for a given unittype.
int get_city_output_bonus(const struct city *pcity, const struct output_type *poutput, enum effect_type effect_type)
Returns the player effect bonus of an output.
int get_building_bonus(const struct city *pcity, const struct impr_type *building, enum effect_type effect_type)
Returns the effect bonus at a building.
int get_city_tile_output_bonus(const struct city *pcity, const struct tile *ptile, const struct output_type *poutput, enum effect_type effect_type)
Returns the effect bonus at a city tile.
int effect_cumulative_max(enum effect_type type, struct universal *for_uni)
Get the maximum effect value in this ruleset for the universal (that is, the sum of all positive effe...
int get_city_bonus(const struct city *pcity, enum effect_type effect_type, enum vision_layer vlayer)
Returns the effect bonus at a city.
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Returns the effect bonus for a player.
enum output_type_id Output_type_id
bool is_server()
Is program type server?
struct city * game_city_by_number(int id)
Often used function to get a city pointer from a city ID.
struct government * government_of_player(const struct player *pplayer)
Return the government of a player.
bool can_player_build_improvement_direct(const struct player *p, const struct impr_type *pimprove)
Whether player can build given building somewhere, ignoring whether it is obsolete.
const char * improvement_rule_name(const struct impr_type *pimprove)
Return the (untranslated) rule name of the improvement.
bool is_improvement_redundant(const struct city *pcity, const struct impr_type *pimprove)
Returns TRUE if an improvement in a city is redundant, that is, the city wouldn't lose anything by lo...
bool can_player_build_improvement_later(const struct player *p, const struct impr_type *pimprove)
Whether player can eventually build given building somewhere – i.e., returns TRUE if building is avai...
void wonder_built(const struct city *pcity, const struct impr_type *pimprove)
Build a wonder in the city.
bool great_wonder_is_destroyed(const struct impr_type *pimprove)
Returns whether this wonder has been destroyed.
Impr_type_id improvement_index(const struct impr_type *pimprove)
Return the improvement index.
bool is_wonder(const struct impr_type *pimprove)
Returns whether improvement is some kind of wonder.
bool is_great_wonder(const struct impr_type *pimprove)
Is this building a great wonder?
bool improvement_obsolete(const struct player *pplayer, const struct impr_type *pimprove, const struct city *pcity)
Returns TRUE if the improvement or wonder is obsolete.
bool improvement_has_flag(const struct impr_type *pimprove, enum impr_flag_id flag)
Return TRUE if the impr has this flag otherwise FALSE.
void wonder_destroyed(const struct city *pcity, const struct impr_type *pimprove)
Remove a wonder from a city and destroy it if it's a great wonder.
const char * improvement_name_translation(const struct impr_type *pimprove)
Return the (translated) name of the given improvement.
bool great_wonder_is_available(const struct impr_type *pimprove)
Returns whether this wonder can be currently built.
#define improvement_iterate_end
#define improvement_iterate(_p)
#define fc_assert_msg(condition, message,...)
#define fc_assert_ret(condition)
#define fc_assert(condition)
#define fc_assert_ret_val(condition, val)
#define fc_assert_action(condition, action)
#define log_debug(message,...)
#define log_base(level, message,...)
struct tile * map_pos_to_tile(const struct civ_map *nmap, int map_x, int map_y)
Return the tile for the given cartesian (map) position.
int map_vector_to_sq_distance(int dx, int dy)
Return the sq_distance for a given vector.
bool same_pos(const struct tile *tile1, const struct tile *tile2)
Are (x1,y1) and (x2,y2) really the same when adjusted? This function might be necessary ALOT of place...
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
Return real distance between two tiles.
void map_distance_vector(int *dx, int *dy, const struct tile *tile0, const struct tile *tile1)
Topology function to find the vector which has the minimum "real" distance between the map positions ...
#define square_iterate(nmap, center_tile, radius, tile_itr)
#define square_iterate_end
#define index_to_map_pos(pmap_x, pmap_y, mindex)
bool can_unit_exist_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Return TRUE iff the unit can "exist" at this location.
bool is_native_near_tile(const struct civ_map *nmap, const struct unit_class *uclass, const struct tile *ptile)
Is there native tile adjacent to given tile.
static const char * rule_name_get(const struct name_translation *ptrans)
struct city_list * cities
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
Returns true iff players can attack each other.
struct player * player_slot_get_player(const struct player_slot *pslot)
Returns the team corresponding to the slot.
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Returns true iff players are allied.
bool pplayers_non_attack(const struct player *pplayer, const struct player *pplayer2)
Returns true iff players have peace, cease-fire, or armistice.
int universal_build_shield_cost(const struct city *pcity, const struct universal *target)
Return the number of shields it takes to build this universal.
bool is_req_active(const struct player *target_player, const struct player *other_player, const struct city *target_city, const struct impr_type *target_building, const struct tile *target_tile, const struct unit *target_unit, const struct unit_type *target_unittype, const struct output_type *target_output, const struct specialist *target_specialist, const struct action *target_action, const struct requirement *req, const enum req_problem_type prob_type, const enum vision_layer vision_layer, const enum national_intelligence nintel)
Checks the requirement to see if it is active on the given target.
bool is_req_unchanging(const struct requirement *req)
Return TRUE if this is an "unchanging" requirement.
bool are_reqs_active(const struct player *target_player, const struct player *other_player, const struct city *target_city, const struct impr_type *target_building, const struct tile *target_tile, const struct unit *target_unit, const struct unit_type *target_unittype, const struct output_type *target_output, const struct specialist *target_specialist, const struct action *target_action, const struct requirement_vector *reqs, const enum req_problem_type prob_type, const enum vision_layer vision_layer, const enum national_intelligence nintel)
Checks the requirement(s) to see if they are active on the given target.
const char * universal_name_translation(const struct universal *psource, char *buf, size_t bufsz)
Make user-friendly text for the source.
bool req_vec_wants_type(const struct requirement_vector *reqs, enum universals_n kind)
Returns TRUE iff the specified requirement vector has a positive requirement of the specified require...
bool does_req_contradicts_reqs(const struct requirement *req, const struct requirement_vector *vec)
Returns TRUE if the given requirement contradicts the given requirement vector.
#define requirement_vector_iterate_end
#define requirement_vector_iterate(req_vec, preq)
static struct setting settings[]
struct setting_list * level[OLEVELS_NUM]
#define CLIP(lower, current, upper)
struct specialist * specialist_by_number(const Specialist_type_id id)
Return the specialist pointer for the given number.
int get_specialist_output(const struct city *pcity, Specialist_type_id sp, Output_type_id otype)
Return the output for the specialist type with this output type.
#define specialist_type_iterate_end
#define specialist_type_iterate(sp)
#define DEFAULT_SPECIALIST
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 built_status built[B_LAST]
int last_turns_shield_surplus
enum capital_type capital
bv_city_options city_options
citizens unit_happy_upkeep
struct trade_route_list * routes
struct universal production
int unhappy_penalty[O_LAST]
char name[MAX_LEN_CITYNAME]
int before_change_shields
struct city::@15::@17 server
citizens feel[CITIZEN_LAST][FEELING_LAST]
citizens specialists[SP_MAX]
struct cm_parameter * cm_parameter
struct universal changed_from
struct unit_list * units_supported
struct packet_ruleset_control control
struct packet_game_info info
struct government * government_during_revolution
struct requirement_vector reqs
The base class for options.
struct city_list * cities
struct player_economic economic
struct requirement_vector build_reqs
const struct unit_type * obsoleted_by
int fc_snprintf(char *str, size_t n, const char *format,...)
See also fc_utf8_snprintf_trunc(), fc_utf8_snprintf_rep().
int fc_strcasecmp(const char *str0, const char *str1)
Compare strings like strcmp(), but ignoring case.
#define sz_strlcpy(dest, src)
#define fc_realloc(ptr, sz)
#define sz_strlcat(dest, src)
#define terrain_has_flag(terr, flag)
int tile_roads_output_bonus(const struct tile *ptile, enum output_type_id o)
Calculate output bonus given by roads.
int tile_roads_output_incr(const struct tile *ptile, enum output_type_id o)
Calculate output increment given by roads.
enum known_type tile_get_known(const struct tile *ptile, const struct player *pplayer)
Return a known_type enumeration value for the tile.
struct city * tile_city(const struct tile *ptile)
Return the city on this tile (or nullptr), checking for city center.
static bool tile_resource_is_valid(const struct tile *ptile)
#define tile_worked(_tile)
#define tile_resource(_tile)
#define tile_terrain(_tile)
#define tile_owner(_tile)
bool can_cities_trade(const struct city *pc1, const struct city *pc2)
Return TRUE iff the two cities are capable of trade; i.e., if a caravan from one city can enter the o...
enum trade_route_type cities_trade_route_type(const struct city *pcity1, const struct city *pcity2)
What is type of the traderoute between two cities.
int trade_base_between_cities(const struct city *pc1, const struct city *pc2)
Return the trade that exists between these cities, assuming they have a trade route.
int trade_from_route(const struct city *pc1, const struct trade_route *route, int base)
Get trade income specific to route's good.
struct trade_route_settings * trade_route_settings_by_type(enum trade_route_type type)
Get trade route settings related to type.
#define trade_routes_iterate_end
#define trade_partners_iterate_end
#define trade_routes_iterate(c, proute)
#define trade_partners_iterate(c, p)
const struct unit_type * utype
const struct impr_type * building
bool unit_being_aggressive(const struct unit *punit)
An "aggressive" unit is a unit which may cause unhappiness under a Republic or Democracy.
bool is_military_unit(const struct unit *punit)
Military units are capable of enforcing martial law.
struct unit * unit_occupies_tile(const struct tile *ptile, const struct player *pplayer)
Is there an occupying unit on this tile?
bool is_field_unit(const struct unit *punit)
This checks the "field unit" flag on the unit.
void unit_virtual_destroy(struct unit *punit)
Free the memory used by virtual unit.
#define unit_list_iterate(unitlist, punit)
#define unit_list_iterate_end
const struct unit_type * unit_type_get(const struct unit *punit)
Return the unit type for this unit.
struct unit_type * best_role_unit(const struct city *pcity, int role)
Return "best" unit this city can build, with given role/flag.
int utype_pop_value(const struct unit_type *punittype)
How much city shrinks when it builds unit of this type.
struct unit_type * utype_by_number(const Unit_type_id id)
Return a pointer for the unit type struct for the given unit type id.
const char * utype_rule_name(const struct unit_type *punittype)
Return the (untranslated) rule name of the unit type.
int utype_build_shield_cost(const struct city *pcity, const struct unit_type *punittype)
Returns the number of shields it takes to build this unit type.
bool can_player_build_unit_direct(const struct player *p, const struct unit_type *punittype)
Whether player can build given unit somewhere, ignoring whether unit is obsolete and assuming the pla...
int utype_veteran_levels(const struct unit_type *punittype)
Return veteran levels of the given unit type.
bool utype_can_do_act_when_ustate(const struct unit_type *punit_type, const action_id act_id, const enum ustate_prop prop, const bool is_there)
Return TRUE iff the unit type can do the specified (action enabler controlled) action while its unit ...
Unit_type_id utype_index(const struct unit_type *punittype)
Return the unit type index.
bool can_player_build_unit_later(const struct player *p, const struct unit_type *punittype)
Whether player can eventually build given unit somewhere – ie, returns TRUE if unit is available with...
bool can_utype_do_act_if_tgt_diplrel(const struct unit_type *punit_type, const action_id act_id, const int prop, const bool is_there)
Return TRUE iff the given (action enabler controlled) action can be performed by a unit of the given ...
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Return TRUE iff units of the given type can do the specified generalized (ruleset defined) action ena...
int utype_happy_cost(const struct unit_type *ut, const struct player *pplayer)
Return the "happy cost" (the number of citizens who are discontented) for this unit.
static bool uclass_has_flag(const struct unit_class *punitclass, enum unit_class_flag_id flag)
static bool utype_has_flag(const struct unit_type *punittype, int flag)
#define unit_type_iterate(_p)
#define unit_type_iterate_end
void worklist_init(struct worklist *pwl)
Initialize a worklist to be empty.
bool worklist_peek_ith(const struct worklist *pwl, struct universal *prod, int idx)
Fill in the id and is_unit values for the ith element in the worklist.
int worklist_length(const struct worklist *pwl)
Returns the number of entries in the worklist.