61 #define LOG_BUY LOG_DEBUG
62 #define LOG_EMERGENCY LOG_VERBOSE
63 #define LOG_WANT LOG_VERBOSE
67 #define AI_CITY_RECALC_SPEED 5
69 #define AI_BA_RECALC_SPEED 5
71 #define SPECVEC_TAG tech
72 #define SPECVEC_TYPE struct advance *
75 #define SPECVEC_TAG impr
76 #define SPECVEC_TYPE const struct impr_type *
81 #define city_range_iterate(city_here, list, range, city) \
83 city_list_iterate(list, city) \
85 if (range == REQ_RANGE_PLAYER || range == REQ_RANGE_TEAM \
86 || range == REQ_RANGE_ALLIANCE \
87 || (range == REQ_RANGE_TRADEROUTE \
88 && (city == city_here \
89 || have_cities_trade_route(city, city_here))) \
90 || ((range == REQ_RANGE_CITY || range == REQ_RANGE_LOCAL) \
91 && city == city_here) \
92 || (range == REQ_RANGE_CONTINENT \
93 && tile_continent(city->tile) \
94 == tile_continent(city_here->tile))) {
96 #define city_range_iterate_end \
99 city_list_iterate_end; \
102 #define CITY_EMERGENCY(pcity) \
103 (pcity->surplus[O_SHIELD] < 0 || city_unhappy(pcity) \
104 || pcity->food_stock + pcity->surplus[O_FOOD] < 0)
107 bool redundant_only);
138 "wanted by %s for building: %d -> %d",
140 building_want, tech_want);
154 const struct city *pcity,
156 struct tech_vector *needed_techs,
160 int n_needed_techs = tech_vector_size(needed_techs);
162 for (t = 0; t < n_needed_techs; t++) {
164 *tech_vector_get(needed_techs, t),
175 const struct city *pcity,
181 if (pobs->source.kind == VUT_ADVANCE && pobs->present) {
183 pobs->source.value.advance,
203 int i, bestattack = 0;
278 "Falling back - didn't want to build soldiers,"
279 " workers, caravans, settlers, or buildings!");
301 "Cannot even build a fallback "
302 "(caravan/coinage/settlers). Fix the ruleset!");
313 #ifdef ADV_CHOICE_TRACK
314 if (city_data->
choice.log_if_chosen) {
329 build_new.
kind = VUT_UTYPE;
333 build_new.
kind = VUT_IMPROVEMENT;
337 build_new.
kind = VUT_NONE;
341 build_new.
kind = universals_n_invalid();
347 E_CITY_PRODUCTION_CHANGED);
400 if (pcity->
owner == punit->owner) {
415 if (punittype ==
nullptr) {
423 int real_limit = limit;
431 real_limit = expenses;
436 military ?
"military" :
"civilian");
456 const enum action_requester requester)
458 const int punit_id_stored = punit->
id;
465 struct city *tgt_city;
474 ACTION_HELP_WONDER, requester)) {
489 struct city *tgt_city;
498 ACTION_RECYCLE_UNIT, requester)) {
514 ACTION_DISBAND_UNIT, requester)) {
537 struct tile *ptile = pcity->tile;
541 && pcity->id == punit->homecity
557 int limit = cached_limit;
558 struct city *pcity =
nullptr;
578 if (bestchoice.
want == 0 || pcity ==
nullptr) {
594 "Wonder being built in dangerous position!");
597 int upgrade_limit = limit;
600 upgrade_limit = expenses;
630 }
else if (city_list_size(pplayer->
cities) > 6) {
635 }
else if (war_footing) {
665 || (bestchoice.
want > 200 && city_data->
urgency > 1))) {
674 CITY_LOG(
LOG_BUY, pcity,
"must have %s but can't afford it (%d < %d)!",
731 if (punit->
id == 0) {
741 foodloss_pct =
CLIP(0, foodloss_pct, 100);
745 for (i = pop_cost; i > 0; i--) {
748 cost = cost * foodloss_pct / 100;
765 struct unit *virtualunit;
767 enum unit_activity best_act = ACTIVITY_IDLE;
769 struct tile *best_tile =
nullptr;
790 if (utype ==
nullptr) {
791 log_debug(
"No UTYF_SETTLERS role unit available");
801 &best_tile,
nullptr,
nullptr);
834 "wants %s with want %d to do %s at (%d,%d), "
835 "we have %d workers and %d cities on the continent",
841 "wants %s with want %d to do %s at (%d,%d), "
842 "we have %d workers and %d cities on the ocean",
852 pcity, UTYF_SETTLERS, place >= 0 ? TC_LAND : TC_OCEAN);
884 int count = city_list_size(pplayer->
cities);
885 struct city *sellers[count + 1];
892 for (i = 0; i < count; i++) {
897 sellers[i] = sellers[replace];
898 sellers[replace] = tmp;
953 }
else if (pcity->server.debug) {
985 const struct city *pcity)
988 if (ai_wants_no_science(plr)
1006 bool redundant_only)
1019 PL_(
"%s is selling %s for %d.",
"%s is selling %s for %d.", gain),
1055 "Emergency in %s (%s, angry%d, unhap%d food%d, prod%d)",
1146 if (city_data !=
nullptr) {
1150 city_data =
nullptr;
1159 const char *citystr)
1187 const char *citystr)
1197 file, 0,
"%s.%s.building_turn", citystr, aitstr);
1203 file, 0,
"%s.%s.founder_turn", citystr, aitstr);
1205 file, 0,
"%s.%s.founder_want", citystr, aitstr);
1208 "%s.%s.founder_boat", citystr, aitstr);
1229 switch (paction->
result) {
1230 case ACTRES_SPY_INCITE_CITY:
1239 case ACTRES_SPY_NUKE:
1240 case ACTRES_CONQUER_CITY:
1243 case ACTRES_DESTROY_CITY:
1247 case ACTRES_SPY_POISON:
1248 case ACTRES_SPY_SPREAD_PLAGUE:
1249 case ACTRES_SPY_SABOTAGE_CITY:
1250 case ACTRES_SPY_TARGETED_SABOTAGE_CITY:
1251 case ACTRES_SPY_SABOTAGE_CITY_PRODUCTION:
1252 case ACTRES_STRIKE_BUILDING:
1253 case ACTRES_STRIKE_PRODUCTION:
1254 case ACTRES_SPY_STEAL_GOLD:
1255 case ACTRES_NUKE_CITY:
1260 case ACTRES_SPY_STEAL_TECH:
1261 case ACTRES_SPY_TARGETED_STEAL_TECH:
1262 case ACTRES_STEAL_MAPS:
1267 case ACTRES_ESTABLISH_EMBASSY:
1268 case ACTRES_SPY_INVESTIGATE_CITY:
1269 case ACTRES_MARKETPLACE:
1274 case ACTRES_TRADE_ROUTE:
1275 case ACTRES_HELP_WONDER:
1276 case ACTRES_JOIN_CITY:
1277 case ACTRES_RECYCLE_UNIT:
1278 case ACTRES_HOME_CITY:
1279 case ACTRES_UPGRADE_UNIT:
1280 case ACTRES_AIRLIFT:
1289 case ACTRES_SPY_BRIBE_UNIT:
1290 case ACTRES_SPY_SABOTAGE_UNIT:
1291 case ACTRES_SPY_ATTACK:
1292 case ACTRES_EXPEL_UNIT:
1293 case ACTRES_DISBAND_UNIT:
1294 case ACTRES_CAPTURE_UNITS:
1295 case ACTRES_BOMBARD:
1296 case ACTRES_FOUND_CITY:
1298 case ACTRES_NUKE_UNITS:
1299 case ACTRES_PARADROP:
1301 case ACTRES_HEAL_UNIT:
1302 case ACTRES_TRANSFORM_TERRAIN:
1303 case ACTRES_CULTIVATE:
1305 case ACTRES_PILLAGE:
1306 case ACTRES_CLEAN_POLLUTION:
1307 case ACTRES_CLEAN_FALLOUT:
1308 case ACTRES_FORTIFY:
1310 case ACTRES_CONVERT:
1313 case ACTRES_IRRIGATE:
1314 case ACTRES_TRANSPORT_ALIGHT:
1315 case ACTRES_TRANSPORT_BOARD:
1316 case ACTRES_TRANSPORT_UNLOAD:
1317 case ACTRES_TRANSPORT_DISEMBARK:
1318 case ACTRES_TRANSPORT_EMBARK:
1320 "Action not aimed at cities");
1341 bool all_met =
true;
1342 int n_needed_techs = 0;
1343 int n_needed_improvements = 0;
1344 struct tech_vector needed_techs;
1345 struct impr_vector needed_improvements;
1347 tech_vector_init(&needed_techs);
1348 impr_vector_init(&needed_improvements);
1352 const bool active =
is_req_active(pplayer,
nullptr, pcity, pimprove,
1353 pcity->
tile,
nullptr,
nullptr,
nullptr,
1356 if (VUT_ADVANCE == preq->source.kind && preq->present && !active) {
1358 tech_vector_append(&needed_techs, preq->source.value.advance);
1359 }
else if (VUT_IMPROVEMENT == preq->source.kind && preq->present
1364 impr_vector_append(&needed_improvements, preq->source.value.building);
1366 all_met = all_met && active;
1374 n_needed_techs = tech_vector_size(&needed_techs);
1375 if (0 < v && 0 < n_needed_techs) {
1378 const adv_want dv = v / n_needed_techs;
1388 n_needed_improvements = impr_vector_size(&needed_improvements);
1389 if (0 < v && 0 < n_needed_improvements) {
1392 const adv_want dv = v / (n_needed_improvements * 4);
1395 for (i = 0; i < n_needed_improvements; i++) {
1397 *impr_vector_get(&needed_improvements, i);
1408 tech_vector_free(&needed_techs);
1409 impr_vector_free(&needed_improvements);
1425 memset(prod, 0,
O_LAST *
sizeof(*prod));
1426 if (
nullptr != pimprove
1463 prod[o] * bonus[o] / 100,
nullptr, gov_centers);
1583 int cities[REQ_RANGE_COUNT];
1587 bool can_build =
true;
1590 .kind = VUT_IMPROVEMENT};
1598 if (aplayer->team && aplayer->team == pplayer->
team
1599 && aplayer != pplayer) {
1615 v +=
base_want(ait, pplayer, pcity, pimprove);
1632 cities[REQ_RANGE_PLAYER] = city_list_size(pplayer->
cities);
1638 cities[REQ_RANGE_CONTINENT] = 1;
1649 cities[REQ_RANGE_ADJACENT] =
cities[REQ_RANGE_CADJACENT] = 0;
1653 int potential = (aplayer->server.bulbs_last_turn
1654 + city_list_size(aplayer->cities) + 1);
1656 if (potential > 0) {
1659 if (pobs->source.kind == VUT_ADVANCE && pobs->present) {
1675 int n_needed_techs = 0;
1676 struct tech_vector needed_techs;
1677 bool present =
true;
1678 bool impossible_to_get =
false;
1680 tech_vector_init(&needed_techs);
1686 if (VUT_IMPROVEMENT == preq->source.kind
1687 && preq->source.value.building == pimprove) {
1692 if (!
is_req_active(pplayer,
nullptr, pcity, pimprove,
nullptr,
nullptr,
1693 nullptr,
nullptr,
nullptr,
nullptr, preq,
1696 if (VUT_ADVANCE == preq->source.kind && preq->present) {
1701 tech_vector_append(&needed_techs, preq->source.value.advance);
1704 impossible_to_get =
true;
1710 n_needed_techs = tech_vector_size(&needed_techs);
1711 if ((active || n_needed_techs) && !impossible_to_get) {
1729 }
else if (v1 > 0) {
1740 const int a = already ? 5 : 4;
1741 const adv_want dv = v1 * a / (4 * n_needed_techs);
1748 tech_vector_free(&needed_techs);
1756 bool will_be_possible =
false;
1757 enum req_range max_range;
1766 max_range = REQ_RANGE_LOCAL;
1778 enum req_range
range = REQ_RANGE_LOCAL;
1782 if (VUT_IMPROVEMENT == preq->source.kind
1783 && preq->source.value.building == pimprove) {
1785 if (preq->present) {
1786 range = preq->range;
1795 city_tile(pcity),
nullptr,
nullptr,
nullptr,
1804 will_be_possible =
true;
1807 if (max_range <
range) {
1820 if (is_possible == will_be_possible) {
1831 act_neg_util =
cities[max_range] * act_neg_util;
1835 if (will_be_possible) {
1852 const bool all_met =
1854 can_build = can_build && all_met;
1857 if (is_coinage && can_build) {
1861 }
else if (!already && can_build) {
1884 if (pobs->source.kind == VUT_ADVANCE && pobs->present) {
1991 if (pcity != wonder_city &&
is_wonder(pimprove)) {
2005 fc_assert(!(already && 0 < pcity->server.adv->building_want[idx]));
2010 pcity->server.adv->building_want[idx] *= 1.5;
2012 if (pcity->production.kind == VUT_IMPROVEMENT
2016 pcity->server.adv->building_want[idx] *= 1.25;
2021 if (pcity->server.adv->building_want[idx] > 0) {
2022 pcity->server.adv->building_want[idx] =
2041 #ifdef FREECIV_DEBUG
2096 enum effect_type effect_type,
2099 int greatest_value = 0;
2100 const struct impr_type *best_building =
nullptr;
2104 if (peffect->value > greatest_value) {
2105 const struct impr_type *building =
nullptr;
2106 bool wrong_unit =
false;
2110 if (VUT_IMPROVEMENT == preq->source.kind && preq->present) {
2111 building = preq->source.value.building;
2118 }
else if (utype !=
nullptr
2121 utype,
nullptr,
nullptr,
nullptr, preq,
2130 if (!wrong_unit && building !=
nullptr) {
2131 best_building = building;
2132 greatest_value = peffect->value;
2138 if (best_building) {
bool is_action_possible_on_city(action_id act_id, const struct player *actor_player, const struct city *target_city)
Returns TRUE if the wanted action can be done to the target city.
void action_list_end(action_id *act_list, int size)
Terminate an action list of the specified size.
bool is_action_enabled_unit_on_self(const action_id wanted_action, const struct unit *actor_unit)
Returns TRUE if actor_unit can do wanted_action to itself as far as action enablers are concerned.
bool is_action_enabled_unit_on_city(const action_id wanted_action, const struct unit *actor_unit, const struct city *target_city)
Returns TRUE if actor_unit can do wanted_action to target_city as far as action enablers are concerne...
void action_list_add_all_by_result(action_id *act_list, int *position, enum action_result result)
Add all actions with the specified result to the specified action list starting at the specified posi...
struct action * action_by_number(action_id act_id)
Return the action with the given id.
bool action_id_exists(const action_id act_id)
Returns TRUE iff the specified action ID refers to a valid action.
struct action_enabler_list * action_enablers_for_action(action_id action)
Get all enablers for an action in the current ruleset.
#define action_list_iterate_end
#define action_list_iterate(_act_list_, _act_id_)
#define action_enabler_list_iterate_end
#define action_id_get_role(act_id)
#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)
Prime pcity->server.adv.building_want[].
void adv_deinit_choice(struct adv_choice *choice)
Clear choice without freeing it itself.
void adv_init_choice(struct adv_choice *choice)
Sets the values of the choice to initial values.
void adv_free_choice(struct adv_choice *choice)
Free dynamically allocated choice.
struct adv_choice * adv_better_choice(struct adv_choice *first, struct adv_choice *second)
Return better one of the choices given.
bool is_unit_choice_type(enum choice_type type)
Does choice type refer to unit.
#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)
Return a pointer to our data.
@ ADV_IMPR_CALCULATE_FULL
struct ai_plr * dai_plr_data_get(struct ai_type *ait, struct player *pplayer, bool *caller_closes)
Get current default ai data related to player.
void dai_calc_data(const struct player *pplayer, int *trade, int *expenses, int *income)
Returns the total amount of trade generated (trade) and total amount of gold needed as upkeep (expens...
#define TECH_LOG(ait, _, pplayer, padvance, msg,...)
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)
Reset ai settler engine.
void contemplate_new_city(struct ai_type *ait, struct city *pcity)
Return want for city settler.
int ai_trait_get_value(enum trait tr, struct player *pplayer)
Get current value of player trait.
struct unit_type * dai_role_utype_for_terrain_class(struct city *pcity, int role, enum terrain_class tc)
Get unit type player can build, suitable to role, with given move type.
#define IS_ATTACKER(ptype)
adv_want settler_evaluate_improvements(struct unit *punit, enum unit_activity *best_act, struct extra_type **best_target, struct tile **best_tile, PFPath *path, struct settlermap *state)
Finds tiles to improve, using punit.
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...
int city_granary_size(int city_size)
Generalized formula used to calculate granary size.
void city_set_ai_data(struct city *pcity, const struct ai_type *ai, void *data)
Attach ai data to city.
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.
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 city_has_building(const struct city *pcity, const struct impr_type *pimprove)
Return TRUE iff the city has this building in it.
struct player * city_owner(const struct city *pcity)
Return the owner of the city.
bool is_capital(const struct city *pcity)
Return TRUE iff this city is its nation's capital.
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.
struct tile * city_tile(const struct city *pcity)
Return the tile location of the city.
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.
int city_pollution(const struct city *pcity, int shield_total, int trade_total)
Calculate pollution for the city.
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_unhappy(const struct city *pcity)
Return TRUE iff the city is unhappy.
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_add_improvement(struct city *pcity, const struct impr_type *pimprove)
Adds an improvement (and its effects) to a city.
int city_map_radius_sq_get(const struct city *pcity)
Returns the current squared radius of the city.
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.
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.
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.
bool is_city_center(const struct city *pcity, const struct tile *ptile)
Return TRUE if the city is centered at the given tile.
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...
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.
#define city_list_iterate(citylist, pcity)
#define city_tile_iterate(_radius_sq, _city_tile, _tile)
#define output_type_iterate(output)
#define city_list_iterate_end
#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)
Handle buying request.
void really_handle_city_sell(struct player *pplayer, struct city *pcity, struct impr_type *pimprove)
Handle improvement selling request.
void auto_arrange_workers(struct city *pcity)
Call sync_cities() to send the affected cities to the clients.
bool city_refresh(struct city *pcity)
Updates unit upkeeps and city internal cached data.
static void try_to_sell_stuff(struct player *pplayer, struct city *pcity)
Sell building from city.
#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)
Increase the degree to which we want to meet a set of requirements, because they will enable construc...
static void unit_do_disband_trad(struct player *owner, struct unit *punit, const enum action_requester requester)
Try to disband punit in the traditional way.
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)
Increase want for a technologies because of the value of that technology in providing an improvement ...
static void increase_maxbuycost(struct player *pplayer, int new_value)
Increase maxbuycost.
static void dai_barbarian_choose_build(struct player *pplayer, struct city *pcity, struct adv_choice *choice)
Choose a build for the barbarian player.
void dai_city_save(struct ai_type *ait, const char *aitstr, struct section_file *file, const struct city *pcity, const char *citystr)
Write ai city segments to savefile.
void dai_city_load(struct ai_type *ait, const char *aitstr, const struct section_file *file, struct city *pcity, const char *citystr)
Load ai city segment from savefile.
static void dai_city_sell_noncritical(struct city *pcity, bool redundant_only)
Sell an noncritical building if there are any in the city.
#define city_range_iterate_end
static int unit_food_upkeep(struct unit *punit)
Calculates a unit's food upkeep (per turn).
void dai_manage_cities(struct ai_type *ait, struct player *pplayer)
One of the top level AI functions.
void dai_city_alloc(struct ai_type *ait, struct city *pcity)
Initialize city for use with default AI.
void dai_consider_wonder_city(struct ai_type *ait, struct city *pcity, bool *result)
Is it ok for advisor code to consider given city as wonder city?
static bool should_force_recalc(struct city *pcity)
Whether the AI should calculate the building wants for this city this turn, ahead of schedule.
static int action_target_neg_util(action_id act_id, const struct city *pcity)
How undesirable for the owner of a particular city is the fact that it can be a target of a particula...
#define city_range_iterate(city_here, list, range, city)
static void resolve_city_emergency(struct ai_type *ait, struct player *pplayer, struct city *pcity)
This function tries desperately to save a city from going under by revolt or starvation of food or re...
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)
Decrease want for a technology because of the value of that technology in obsoleting an improvement e...
void dai_build_adv_adjust(struct ai_type *ait, struct player *pplayer, struct city *wonder_city)
Calculate how much an AI player should want to build particular improvements, because of the effects ...
static void contemplate_terrain_improvements(struct ai_type *ait, struct city *pcity)
Estimates the want for a terrain improver (aka worker) by creating a virtual unit and feeding it to s...
static void dai_spend_gold(struct ai_type *ait, struct player *pplayer)
Buy and upgrade stuff!
static void adjust_improvement_wants_by_effects(struct ai_type *ait, struct player *pplayer, struct city *pcity, struct impr_type *pimprove, const bool already)
Calculate effects of possible improvements and extra effects of existing improvements.
void dai_city_free(struct ai_type *ait, struct city *pcity)
Free city from use with default AI.
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)
Increase want for a technology because of the value of that technology in providing an improvement ef...
Impr_type_id dai_find_source_building(struct city *pcity, enum effect_type effect_type, const struct unit_type *utype)
Returns a buildable, non-obsolete building that can provide the effect.
void dai_build_adv_init(struct ai_type *ait, struct player *pplayer)
Initialize building advisor.
static void dai_upgrade_units(struct city *pcity, int limit, bool military)
Try to upgrade a city's units.
#define CITY_EMERGENCY(pcity)
adv_want dai_city_want(struct player *pplayer, struct city *acity, struct adv_data *adv, struct impr_type *pimprove)
Calculates city want from some input values.
static adv_want base_want(struct ai_type *ait, struct player *pplayer, struct city *pcity, struct impr_type *pimprove)
Calculates want for some buildings by actually adding the building and measuring the effect.
static int unit_foodbox_cost(struct unit *punit)
Returns how much food a settler will consume out of the city's foodbox when created.
static bool building_crucial(const struct player *plr, struct impr_type *pimprove, const struct city *pcity)
Are effects provided by this building not needed?
static void dai_city_choose_build(struct ai_type *ait, struct player *pplayer, struct city *pcity)
Chooses what the city will build.
#define BUILDING_WAIT_MINIMUM
bool dai_on_war_footing(struct ai_type *ait, struct player *pplayer)
Are we going to be declaring war in a few turns time? If so, go on a war footing, and try to buy out ...
struct adv_choice * domestic_advisor_choose_build(struct ai_type *ait, struct player *pplayer, struct city *pcity)
This function should fill the supplied choice structure.
bool dai_can_requirement_be_met_in_city(const struct requirement *preq, const struct player *pplayer, const struct city *pcity)
Does the AI expect to ever be able to meet this requirement.
adv_want dai_effect_value(struct player *pplayer, struct government *gov, const struct adv_data *adv, const struct city *pcity, const bool capital, int turns, const struct effect *peffect, const int c, const int nplayers)
How desirable is a particular effect for a particular city, given the number of cities in range (c).
int assess_defense(struct ai_type *ait, struct city *pcity)
Estimate defense strength of city.
struct adv_choice * military_advisor_choose_build(struct ai_type *ait, struct player *pplayer, struct city *pcity, const struct civ_map *mamap, player_unit_list_getter ul_cb)
This function selects either a defender or an attacker to be built.
bool dai_process_defender_want(struct ai_type *ait, struct player *pplayer, struct city *pcity, int danger, struct adv_choice *choice)
What would be the best defender for that city? Records the best defender type in choice.
int assess_defense_quadratic(struct ai_type *ait, struct city *pcity)
Need positive feedback in m_a_c_b and bodyguard routines.
bool ai_fuzzy(const struct player *pplayer, bool normal_decision)
Return the value normal_decision (a boolean), except if the AI is fuzzy, then sometimes flip the valu...
struct effect_list * get_req_source_effects(struct universal *psource)
Get a list of effects with this requirement source.
const effect_list * get_effects()
Get a list of all effects.
bool building_has_effect(const struct impr_type *pimprove, enum effect_type effect_type)
Returns TRUE if the building has any effect bonuses of the given type.
int get_city_bonus(const struct city *pcity, enum effect_type effect_type, enum vision_layer vlayer)
Returns the effect bonus at a city.
#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)
Get a text link to a city.
struct government * government_of_player(const struct player *pplayer)
Return the government of a player.
bool has_handicap(const struct player *pplayer, enum handicap_type htype)
AI players may have handicaps - allowing them to cheat or preventing them from using certain algorith...
int impr_sell_gold(const struct impr_type *pimprove)
Returns the amount of gold received when this improvement is sold.
bool can_city_sell_building(const struct city *pcity, const struct impr_type *pimprove)
Return TRUE iff the city can sell the given improvement.
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...
struct city * city_from_small_wonder(const struct player *pplayer, const struct impr_type *pimprove)
Get the player city with this small wonder.
bool is_improvement(const struct impr_type *pimprove)
Is this building a regular improvement?
Impr_type_id improvement_number(const struct impr_type *pimprove)
Return the improvement index.
Impr_type_id improvement_index(const struct impr_type *pimprove)
Return the improvement index.
int impr_build_shield_cost(const struct city *pcity, const struct impr_type *pimprove)
Returns the number of shields it takes to build this improvement.
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_has_flag(const struct impr_type *pimprove, enum impr_flag_id flag)
Return TRUE if the impr has this flag otherwise FALSE.
const char * improvement_name_translation(const struct impr_type *pimprove)
Return the (translated) name of the given improvement.
bool is_small_wonder(const struct impr_type *pimprove)
Is this building a small wonder?
bool is_improvement_productive(const struct city *pcity, const struct impr_type *pimprove)
Returns TRUE if an improvement in a city is productive, in some way.
#define improvement_iterate_end
#define improvement_iterate(_p)
void initialize_infrastructure_cache(struct player *pplayer)
Do all tile improvement calculations and cache them for later.
#define fc_assert_msg(condition, message,...)
#define fc_assert_ret(condition)
#define fc_assert(condition)
#define fc_assert_ret_msg(condition, message,...)
#define fc_assert_ret_val(condition, val)
#define fc_assert_action(condition, action)
#define log_debug(message,...)
#define log_base(level, message,...)
void notify_player(const struct player *pplayer, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Similar to notify_conn_packet (see also), but takes player as "destination".
struct city_list * cities
int player_get_expected_income(const struct player *pplayer)
Return the expected net income of the player this turn.
std::vector< city * > player_gov_centers(const struct player *pplayer)
Locate the player's government centers.
const char * player_name(const struct player *pplayer)
Return the leader name of the player.
#define players_iterate_end
#define players_iterate(_pplayer)
static bool is_barbarian(const struct player *pplayer)
int normal_player_count()
Return the number of non-barbarian players.
bool secfile_lookup_bool_default(const struct section_file *secfile, bool def, const char *path,...)
Lookup a boolean value in the secfile.
int secfile_lookup_int_default(const struct section_file *secfile, int def, const char *path,...)
Lookup a integer value in the secfile.
#define secfile_insert_int(secfile, value, path,...)
#define secfile_insert_bool(secfile, value, path,...)
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.
#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)
Returns the number of technologies the player need to research to get the goal technology.
struct research * research_get(const struct player *pplayer)
Returns the research structure associated with the player.
int research_goal_bulbs_required(const struct research *presearch, Tech_type_id goal)
Function to determine cost (in bulbs) of reaching goal technology.
#define CLIP(lower, current, upper)
#define DEFAULT_SPECIALIST
#define UNIT_LOG(_, punit, msg,...)
#define CITY_LOG(_, pcity, msg,...)
#define TIMING_LOG(timer, activity)
enum action_result result
struct adv_data::@87 stats
enum adv_improvement_status impr_calc[B_LAST]
enum req_range impr_range[B_LAST]
struct unit_type * worker_type
adv_want tech_want[A_LAST+1]
struct ai_plr::@155 stats
struct universal production
struct city::@15::@17 server
citizens feel[CITIZEN_LAST][FEELING_LAST]
citizens specialists[SP_MAX]
struct unit_list * units_supported
struct civ_game::@28::@32 server
struct packet_game_info info
struct requirement_vector obsolete_by
struct requirement_vector reqs
struct city_list * cities
struct player_ai ai_common
struct player_economic economic
Tech_type_id advance_index(const struct advance *padvance)
Return the advance index.
Tech_type_id advance_number(const struct advance *padvance)
Return the advance index.
struct city * tile_city(const struct tile *ptile)
Return the city on this tile (or nullptr), checking for city center.
#define tile_worked(_tile)
#define tile_continent(_tile)
int city_num_trade_routes(const struct city *pcity)
Return number of trade route city has.
#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_being_aggressive(const struct unit *punit)
An "aggressive" unit is a unit which may cause unhappiness under a Republic or Democracy.
bool unit_is_alive(int id)
Check if unit with given id is still alive.
bool is_field_unit(const struct unit *punit)
This checks the "field unit" flag on the unit.
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Return TRUE iff this unit can do the specified generalized (ruleset defined) action enabler controlle...
void unit_virtual_destroy(struct unit *punit)
Free the memory used by virtual unit.
const char * get_activity_text(enum unit_activity activity)
Return the name of the activity in a static buffer.
struct unit * unit_virtual_create(struct player *pplayer, struct city *pcity, const struct unit_type *punittype, int veteran_level)
Create a virtual unit skeleton.
void unit_tile_set(struct unit *punit, struct tile *ptile)
Set the tile location of the unit.
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)
Execute a request to perform an action and let the caller know if it was performed or not.
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)
Handle unit action.
#define unit_list_iterate(unitlist, punit)
#define unit_list_iterate_safe(unitlist, _unit)
#define unit_list_iterate_end
#define unit_list_iterate_safe_end
const char * unit_rule_name(const struct unit *punit)
Return the (untranslated) rule name of the unit.
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_upkeep_cost(const struct unit_type *ut, struct player *pplayer, Output_type_id otype)
Returns the upkeep of a unit of this type under the given government.
const char * utype_rule_name(const struct unit_type *punittype)
Return the (untranslated) rule name of the unit type.
bool utype_is_cityfounder(const struct unit_type *utype)
Is cityfounder type.
const struct unit_type * can_upgrade_unittype(const struct player *pplayer, const struct unit_type *punittype)
Return whether this player can upgrade this unit type (to any other 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.
int num_role_units(int role)
How many unit types have specified role/flag.
bool unit_has_type_role(const struct unit *punit, enum unit_role_id role)
Return whether the unit has the given role.
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Return whether the unit has the given flag.
struct unit_type * get_role_unit(int role, int role_index)
Return index-th unit with specified role/flag.
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.
int unit_upgrade_price(const struct player *pplayer, const struct unit_type *from, const struct unit_type *to)
Return the cost (gold) of upgrading a single unit of the specified type to the new type.