67#define LOG_BUY LOG_DEBUG
68#define LOG_EMERGENCY LOG_VERBOSE
69#define LOG_WANT LOG_VERBOSE
73#define AI_CITY_RECALC_SPEED 5
75#define AI_BA_RECALC_SPEED 5
77#define SPECVEC_TAG tech
78#define SPECVEC_TYPE struct advance *
81#define SPECVEC_TAG impr
82#define SPECVEC_TYPE const struct impr_type *
87#define city_range_iterate(city_here, list, range, city) \
89 city_list_iterate(list, city) { \
90 if (range == REQ_RANGE_PLAYER \
91 || range == REQ_RANGE_TEAM \
92 || range == REQ_RANGE_ALLIANCE \
93 || (range == REQ_RANGE_TRADE_ROUTE \
94 && (city == city_here \
95 || have_cities_trade_route(city, city_here))) \
96 || ((range == REQ_RANGE_CITY || range == REQ_RANGE_LOCAL) \
97 && city == city_here) \
98 || (range == REQ_RANGE_CONTINENT \
99 && tile_continent(city->tile) == \
100 tile_continent(city_here->tile))) {
102#define city_range_iterate_end \
104 } city_list_iterate_end; \
107#define CITY_EMERGENCY(pcity) \
108 (pcity->surplus[O_SHIELD] < 0 || city_unhappy(pcity) \
109 || pcity->food_stock + pcity->surplus[O_FOOD] < 0)
129 const struct city *pcity,
143 "wanted by %s for building: %d -> %d",
145 building_want, tech_want);
158 const struct city *pcity,
179 const struct city *pcity,
186 pobs->source.value.advance,
282 " workers, caravans, settlers, or buildings!");
304 "(caravan/coinage/settlers). Fix the ruleset!");
315#ifdef ADV_CHOICE_TRACK
433 military ?
"military" :
"civilian");
534 struct tile *ptile = pcity->tile;
664 CITY_LOG(
LOG_BUY, pcity,
"must have %s but can't afford it (%d < %d)!",
732 for (
i = pop_cost;
i > 0 ;
i--) {
767 if (!private->contemplace_workers) {
777 log_debug(
"No UTYF_SETTLERS role unit available");
820 "we have %d workers and %d cities on the continent",
829 "we have %d workers and %d cities on the ocean",
881 for (
i = 0;
i < count;
i++) {
938 }
else if (pcity->server.debug) {
967 const struct city *pcity)
999 PL_(
"%s is selling %s for %d.",
1000 "%s is selling %s for %d.",
gain),
1037 "Emergency in %s (%s, angry%d, unhap%d food%d, prod%d)",
1052#ifndef FREECIV_NDEBUG
1099 "Emergency in %s resolved by disbanding unit(s)",
1208 const struct city *pcity)
1213 "Action %d don't exist.", act_id);
1322 "Action not aimed at cities");
1355 .building = pimprove,
1432 if (
NULL != pimprove
1466 prod[
o] = prod[
o] * bonus[
o] / 100 - waste[
o];
1591 .value = {.building = pimprove}
1602 .building = pimprove,
1639 v +=
base_want(ait, pplayer, pcity, pimprove);
1697 bool present =
TRUE;
1710 present =
preq->present;
1745 }
else if (
v1 > 0) {
1797 if (
preq->present) {
1978 if (pcity != wonder_city &&
is_wonder(pimprove)) {
1993 && 0 < pcity->server.adv->building_want[idx]));
1998 pcity->server.adv->building_want[idx] *= 1.5;
2004 pcity->server.adv->building_want[idx] *= 1.25;
2009 if (pcity->server.adv->building_want[idx] > 0) {
2010 pcity->server.adv->building_want[idx]
2011 = pcity->server.adv->building_want[idx]
2157 enum effect_type effect_type,
2176 building =
preq->source.value.building;
2189 if (building ==
NULL) {
2197 if (building ==
NULL) {
2200 }
else if (utype !=
NULL
bool is_action_possible_on_city(action_id act_id, const struct player *actor_player, const struct city *target_city)
void action_array_add_all_by_result(action_id *act_array, int *position, enum action_result result)
void action_array_end(action_id *act_array, int size)
bool action_ever_possible(action_id action)
bool is_action_enabled_unit_on_city(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit, const struct city *target_city)
bool action_id_exists(const action_id act_id)
enum action_target_kind action_get_target_kind(const struct action *paction)
bool is_action_enabled_unit_on_self(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit)
struct action_enabler_list * action_enablers_for_action(action_id action)
static struct action * action_by_number(action_id act_id)
#define action_array_iterate(_act_array_, _act_id_)
#define action_enabler_list_iterate_end
#define action_id_get_role(act_id)
#define action_array_iterate_end
#define action_iterate_end
#define action_enabler_list_iterate(action_enabler_list, aenabler)
#define action_iterate(_act_)
#define action_id_get_target_kind(act_id)
void building_advisor(struct player *pplayer)
void adv_deinit_choice(struct adv_choice *choice)
void adv_init_choice(struct adv_choice *choice)
void adv_free_choice(struct adv_choice *choice)
struct adv_choice * adv_better_choice(struct adv_choice *first, struct adv_choice *second)
bool is_unit_choice_type(enum choice_type type)
const char * adv_choice_rule_name(const struct adv_choice *choice)
#define adv_choice_set_use(_choice, _use)
#define ADV_CHOICE_ASSERT(c)
static void adv_choice_copy(struct adv_choice *dest, struct adv_choice *src)
struct adv_data * adv_data_get(struct player *pplayer, bool *caller_closes)
@ ADV_IMPR_CALCULATE_FULL
void dai_calc_data(const struct player *pplayer, int *trade, int *expenses, int *income)
int ai_trait_get_value(enum trait tr, struct player *pplayer)
adv_want settler_evaluate_improvements(const struct civ_map *nmap, struct unit *punit, enum unit_activity *best_act, struct extra_type **best_target, struct tile **best_tile, struct pf_path **path, struct settlermap *state)
bool base_city_celebrating(const struct city *pcity)
bool is_free_worked(const struct city *pcity, const struct tile *ptile)
int city_granary_size(int city_size)
void city_set_ai_data(struct city *pcity, const struct ai_type *ai, void *data)
bool city_built_last_turn(const struct city *pcity)
int city_waste(const struct city *pcity, Output_type_id otype, int total, int *breakdown)
bool city_has_building(const struct city *pcity, const struct impr_type *pimprove)
bool is_capital(const struct city *pcity)
const char * city_name_get(const struct city *pcity)
void city_remove_improvement(struct city *pcity, const struct impr_type *pimprove)
int city_improvement_upkeep(const struct city *pcity, const struct impr_type *b)
void add_tax_income(const struct player *pplayer, int trade, int *output)
bool can_city_build_improvement_now(const struct city *pcity, const struct impr_type *pimprove)
int get_city_tithes_bonus(const struct city *pcity)
bool city_unhappy(const struct city *pcity)
int get_final_city_output_bonus(const struct city *pcity, Output_type_id otype)
int city_pollution(const struct city *pcity, int shield_total)
void city_add_improvement(struct city *pcity, const struct impr_type *pimprove)
int city_map_radius_sq_get(const struct city *pcity)
bool city_base_to_city_map(int *city_map_x, int *city_map_y, const struct city *const pcity, const struct tile *map_tile)
void add_specialist_output(const struct city *pcity, int *output)
int city_tile_output(const struct city *pcity, const struct tile *ptile, bool is_celebrating, Output_type_id otype)
bool can_city_build_unit_now(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
#define city_list_iterate(citylist, pcity)
#define city_tile(_pcity_)
static citizens city_size_get(const struct city *pcity)
#define output_type_iterate(output)
#define city_owner(_pcity_)
#define city_list_iterate_end
#define city_tile_iterate(_nmap, _radius_sq, _city_tile, _tile)
#define city_tile_iterate_end
#define city_built_iterate(_pcity, _p)
#define city_built_iterate_end
#define output_type_iterate_end
void really_handle_city_buy(struct player *pplayer, struct city *pcity)
void really_handle_city_sell(struct player *pplayer, struct city *pcity, struct impr_type *pimprove)
int city_shrink_granary_savings(const struct city *pcity)
void auto_arrange_workers(struct city *pcity)
bool city_refresh(struct city *pcity)
static void try_to_sell_stuff(struct player *pplayer, struct city *pcity)
#define AI_BA_RECALC_SPEED
#define AI_CITY_RECALC_SPEED
static bool adjust_wants_for_reqs(struct ai_type *ait, struct player *pplayer, struct city *pcity, const struct impr_type *pimprove, const adv_want v)
static void unit_do_disband_trad(struct player *owner, struct unit *punit, const enum action_requester requester)
static bool dai_cant_help_req(const struct req_context *context, const struct requirement *req)
void want_techs_for_improvement_effect(struct ai_type *ait, struct player *pplayer, const struct city *pcity, const struct impr_type *pimprove, struct tech_vector *needed_techs, adv_want building_want)
static void increase_maxbuycost(struct player *pplayer, int new_value)
static void dai_barbarian_choose_build(struct player *pplayer, struct city *pcity, struct adv_choice *choice)
void dai_city_save(struct ai_type *ait, const char *aitstr, struct section_file *file, const struct city *pcity, const char *citystr)
void dai_city_load(struct ai_type *ait, const char *aitstr, const struct section_file *file, struct city *pcity, const char *citystr)
static void dai_city_sell_noncritical(struct city *pcity, bool redundant_only)
#define city_range_iterate_end
static int unit_food_upkeep(struct unit *punit)
void dai_manage_cities(struct ai_type *ait, struct player *pplayer)
void dai_city_alloc(struct ai_type *ait, struct city *pcity)
void dai_consider_wonder_city(struct ai_type *ait, struct city *pcity, bool *result)
static bool should_force_recalc(struct city *pcity)
bool dai_can_player_build_improvement_later(const struct player *p, const struct impr_type *pimprove)
static int action_target_neg_util(action_id act_id, const struct city *pcity)
#define city_range_iterate(city_here, list, range, city)
static void resolve_city_emergency(struct ai_type *ait, struct player *pplayer, struct city *pcity)
void dont_want_tech_obsoleting_impr(struct ai_type *ait, struct player *pplayer, const struct city *pcity, const struct impr_type *pimprove, adv_want building_want)
void dai_build_adv_adjust(struct ai_type *ait, struct player *pplayer, struct city *wonder_city)
static void contemplate_terrain_improvements(struct ai_type *ait, struct city *pcity)
static void dai_spend_gold(struct ai_type *ait, struct player *pplayer)
static void adjust_improvement_wants_by_effects(struct ai_type *ait, struct player *pplayer, struct city *pcity, struct impr_type *pimprove, const bool already)
void dai_city_free(struct ai_type *ait, struct city *pcity)
static void want_tech_for_improvement_effect(struct ai_type *ait, struct player *pplayer, const struct city *pcity, const struct impr_type *pimprove, const struct advance *tech, adv_want building_want)
Impr_type_id dai_find_source_building(struct city *pcity, enum effect_type effect_type, const struct unit_type *utype)
void dai_build_adv_init(struct ai_type *ait, struct player *pplayer)
static void dai_upgrade_units(struct city *pcity, int limit, bool military)
#define CITY_EMERGENCY(pcity)
bool dai_can_city_build_improvement_later(const struct city *pcity, const struct impr_type *pimprove)
adv_want dai_city_want(struct player *pplayer, struct city *acity, struct adv_data *adv, struct impr_type *pimprove)
static adv_want base_want(struct ai_type *ait, struct player *pplayer, struct city *pcity, struct impr_type *pimprove)
static int unit_foodbox_cost(struct unit *punit)
static bool building_crucial(const struct player *plr, struct impr_type *pimprove, const struct city *pcity)
static void dai_city_choose_build(struct ai_type *ait, struct player *pplayer, struct city *pcity)
#define BUILDING_WAIT_MINIMUM
struct ai_plr * dai_plr_data_get(struct ai_type *ait, struct player *pplayer, bool *caller_closes)
bool dai_on_war_footing(struct ai_type *ait, struct player *pplayer)
struct adv_choice * domestic_advisor_choose_build(struct ai_type *ait, struct player *pplayer, struct city *pcity)
bool dai_can_requirement_be_met_in_city(const struct requirement *preq, const struct player *pplayer, const struct city *pcity)
adv_want dai_effect_value(struct player *pplayer, const struct adv_data *adv, const struct city *pcity, const bool capital, int turns, const struct effect *peffect, const int c, const int nplayers)
#define TECH_LOG(ait, loglevel, pplayer, padvance, msg,...)
int assess_defense(struct ai_type *ait, struct city *pcity)
struct adv_choice * military_advisor_choose_build(struct ai_type *ait, const struct civ_map *nmap, struct player *pplayer, struct city *pcity, player_unit_list_getter ul_cb)
bool dai_process_defender_want(struct ai_type *ait, const struct civ_map *nmap, struct player *pplayer, struct city *pcity, unsigned int danger, struct adv_choice *choice, adv_want extra_want)
int assess_defense_quadratic(struct ai_type *ait, struct city *pcity)
static struct ai_plr * def_ai_player_data(const struct player *pplayer, struct ai_type *deftype)
static struct ai_city * def_ai_city_data(const struct city *pcity, struct ai_type *deftype)
static struct unit_ai * def_ai_unit_data(const struct unit *punit, struct ai_type *deftype)
void dai_auto_settler_reset(struct ai_type *ait, struct player *pplayer)
void contemplate_new_city(struct ai_type *ait, struct city *pcity)
struct unit_type * dai_role_utype_for_terrain_class(struct city *pcity, int role, enum terrain_class tc)
#define IS_ATTACKER(ptype)
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int cost
bool ai_fuzzy(const struct player *pplayer, bool normal_decision)
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
struct effect_list * get_effects(enum effect_type effect_type)
struct effect_list * get_req_source_effects(const struct universal *psource)
bool building_has_effect(const struct impr_type *pimprove, enum effect_type effect_type)
#define effect_list_iterate_end
#define effect_list_iterate(effect_list, peffect)
signed short Continent_id
#define PL_(String1, String2, n)
const struct ft_color ftc_server
const char * city_link(const struct city *pcity)
static GtkWidget * source
bool has_handicap(const struct player *pplayer, enum handicap_type htype)
const struct impr_type * valid_improvement(const struct impr_type *pimprove)
int impr_sell_gold(const struct impr_type *pimprove)
bool can_city_sell_building(const struct city *pcity, const struct impr_type *pimprove)
bool is_improvement_redundant(const struct city *pcity, const struct impr_type *pimprove)
bool can_player_build_improvement_later(const struct player *p, const struct impr_type *pimprove)
bool is_improvement(const struct impr_type *pimprove)
Impr_type_id improvement_number(const struct impr_type *pimprove)
const char * improvement_rule_name(const struct impr_type *pimprove)
Impr_type_id improvement_index(const struct impr_type *pimprove)
int impr_build_shield_cost(const struct city *pcity, const struct impr_type *pimprove)
bool is_wonder(const struct impr_type *pimprove)
bool is_great_wonder(const struct impr_type *pimprove)
bool improvement_obsolete(const struct player *pplayer, const struct impr_type *pimprove, const struct city *pcity)
bool improvement_has_flag(const struct impr_type *pimprove, enum impr_flag_id flag)
struct city * city_from_small_wonder(const struct player *pplayer, const struct impr_type *pimprove)
bool is_convert_improvement(const struct impr_type *pimprove)
const char * improvement_name_translation(const struct impr_type *pimprove)
bool is_small_wonder(const struct impr_type *pimprove)
bool great_wonder_is_available(const struct impr_type *pimprove)
bool is_improvement_productive(const struct city *pcity, const struct impr_type *pimprove)
#define improvement_iterate_end
#define improvement_iterate(_p)
void initialize_infrastructure_cache(struct player *pplayer)
#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_normal(message,...)
#define log_base(level, message,...)
#define fc_calloc(n, esz)
void notify_player(const struct player *pplayer, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
struct city_list * cities
int player_get_expected_income(const struct player *pplayer)
const char * player_name(const struct player *pplayer)
#define players_iterate_end
#define players_iterate(_pplayer)
static bool is_barbarian(const struct player *pplayer)
int normal_player_count(void)
bool secfile_lookup_bool_default(const struct section_file *secfile, bool def, const char *path,...)
int secfile_lookup_int_default(const struct section_file *secfile, int def, const char *path,...)
#define secfile_insert_int(secfile, value, path,...)
#define secfile_insert_bool(secfile, value, path,...)
bool is_req_active(const struct req_context *context, const struct player *other_player, const struct requirement *req, const enum req_problem_type prob_type)
enum req_item_found universal_fulfills_requirement(const struct requirement *preq, const struct universal *source)
enum req_unchanging_status is_req_preventing(const struct req_context *context, const struct player *other_player, const struct requirement *req, enum req_problem_type prob_type)
#define requirement_vector_iterate_end
#define requirement_vector_iterate(req_vec, preq)
int research_goal_unknown_techs(const struct research *presearch, Tech_type_id goal)
int research_goal_bulbs_required(const struct research *presearch, Tech_type_id goal)
struct research * research_get(const struct player *pplayer)
#define CLIP(lower, current, upper)
#define DEFAULT_SPECIALIST
#define CITY_LOG(loglevel, pcity, msg,...)
#define UNIT_LOG(loglevel, punit, msg,...)
#define TIMING_LOG(timer, activity)
adv_want building_want[B_LAST]
struct adv_data::@91 stats
enum adv_improvement_status impr_calc[B_LAST]
enum req_range impr_range[B_LAST]
unsigned int grave_danger
struct ai_plr::@253 stats
adv_want tech_want[A_LAST+1]
struct universal production
citizens feel[CITIZEN_LAST][FEELING_LAST]
struct city::@17::@19 server
struct unit_list * units_supported
struct packet_game_info info
int incite_improvement_factor
struct civ_game::@31::@35 server
struct requirement_vector obsolete_by
struct requirement_vector reqs
int great_wonder_owners[B_LAST]
struct city_list * cities
struct player_ai ai_common
struct player_economic economic
const struct player * player
Tech_type_id advance_index(const struct advance *padvance)
Tech_type_id advance_number(const struct advance *padvance)
struct city * tile_city(const struct tile *ptile)
#define tile_worked(_tile)
#define tile_continent(_tile)
int city_num_trade_routes(const struct city *pcity)
#define trade_routes_iterate_end
#define trade_routes_iterate(c, proute)
#define TRAIT_DEFAULT_VALUE
const struct unit_type * utype
const struct impr_type * building
bool unit_is_alive(int id)
bool unit_being_aggressive(const struct civ_map *nmap, const struct unit *punit)
bool is_field_unit(const struct unit *punit)
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
struct unit * unit_virtual_create(struct player *pplayer, struct city *pcity, const struct unit_type *punittype, int veteran_level)
const char * get_activity_text(enum unit_activity activity)
void unit_virtual_destroy(struct unit *punit)
void unit_tile_set(struct unit *punit, struct tile *ptile)
bool unit_perform_action(struct player *pplayer, const int actor_id, const int target_id, const int sub_tgt_id_incoming, const char *name, const action_id action_type, const enum action_requester requester)
void unit_do_action(struct player *pplayer, const int actor_id, const int target_id, const int sub_tgt_id, const char *name, const action_id action_type)
#define unit_list_iterate(unitlist, punit)
#define unit_list_iterate_safe(unitlist, _unit)
#define unit_list_iterate_end
#define unit_list_iterate_safe_end
struct unit_type * best_role_unit(const struct city *pcity, int role)
const struct unit_type * unit_type_get(const struct unit *punit)
int utype_upkeep_cost(const struct unit_type *ut, struct player *pplayer, Output_type_id otype)
bool utype_is_cityfounder(const struct unit_type *utype)
struct unit_type * get_role_unit(int role, int role_index)
const char * unit_rule_name(const struct unit *punit)
int num_role_units(int role)
const struct unit_type * can_upgrade_unittype(const struct player *pplayer, const struct unit_type *punittype)
const char * utype_rule_name(const struct unit_type *punittype)
bool unit_has_type_role(const struct unit *punit, enum unit_role_id role)
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
int utype_build_shield_cost(const struct city *pcity, const struct player *pplayer, const struct unit_type *punittype)
int utype_happy_cost(const struct unit_type *ut, const struct player *pplayer)
int unit_upgrade_price(const struct player *pplayer, const struct unit_type *from, const struct unit_type *to)