Freeciv-3.3
|
#include <string.h>
#include <math.h>
#include "rand.h"
#include "registry.h"
#include "actions.h"
#include "game.h"
#include "government.h"
#include "map.h"
#include "research.h"
#include "specialist.h"
#include "cityhand.h"
#include "citytools.h"
#include "cityturn.h"
#include "notify.h"
#include "plrhand.h"
#include "srv_log.h"
#include "unithand.h"
#include "unittools.h"
#include "advdata.h"
#include "advtools.h"
#include "autoworkers.h"
#include "advbuilding.h"
#include "infracache.h"
#include "aitraits.h"
#include "difficulty.h"
#include "handicaps.h"
#include "aihand.h"
#include "daidata.h"
#include "daidiplomacy.h"
#include "daidomestic.h"
#include "daimilitary.h"
#include "daieffects.h"
#include "daiplayer.h"
#include "daisettler.h"
#include "daitools.h"
#include "daicity.h"
#include "specvec.h"
Go to the source code of this file.
#define city_range_iterate_end |
#define LOG_EMERGENCY LOG_VERBOSE |
#define LOG_WANT LOG_VERBOSE |
How undesirable for the owner of a particular city is the fact that it can be a target of a particular action?
The negative utility (how undesirable it is) is given as a positive number. If it is desirable to be the target of an action make the negative utility a negative number since double negative is positive.
Examples: action_target_neg_util(Add to population) = -50 action_target_neg_util(Subtract from population) = 50
Definition at line 1208 of file daicity.c.
Referenced by adjust_improvement_wants_by_effects().
|
static |
Calculate effects of possible improvements and extra effects of existing improvements. Consequently adjust the desirability of those improvements or the technologies that would make them possible.
This function may (indeed, should) be called even for improvements that a city already has, or can not (yet) build. For existing improvements, it will discourage research of technologies that would make the improvement obsolete or reduce its effectiveness, and encourages technologies that would improve its effectiveness. For improvements that the city can not yet build it will encourage research of the techs and building of the improvements that will make the improvement possible.
A complexity is that there are two sets of requirements to consider: the requirements for the building itself, and the requirements for the effects for the building.
A few base variables: c - number of cities we have in current range u - units we have of currently affected type v - the want for the improvement we are considering
This function contains a whole lot of WAGs. We ignore cond_* for now, thinking that one day we may fulfil the cond_s anyway. In general, we first add bonus for city improvements, then for wonders.
IDEA: Calculate per-continent aggregates of various data, and use this for wonders below for better wonder placements.
Definition at line 1579 of file daicity.c.
Referenced by dai_build_adv_adjust().
|
static |
Increase the degree to which we want to meet a set of requirements, because they will enable construction of an improvement with desirable effects.
v is the desire for the improvement.
Returns whether all the requirements are met.
Definition at line 1341 of file daicity.c.
Referenced by adjust_improvement_wants_by_effects(), and adjust_wants_for_reqs().
|
static |
Calculates want for some buildings by actually adding the building and measuring the effect.
Definition at line 1501 of file daicity.c.
Referenced by adjust_improvement_wants_by_effects().
|
static |
Are effects provided by this building not needed?
If this function is called for a building that has not yet been constructed, side effect benefits may not be accurately calculated (see improvement.c for details).
Definition at line 966 of file daicity.c.
Referenced by dai_city_sell_noncritical().
Estimates the want for a terrain improver (aka worker) by creating a virtual unit and feeding it to settler_evaluate_improvements().
TODO: AI does not ship UTYF_WORKERS around, only UTYF_CITIES - Per
Definition at line 750 of file daicity.c.
Referenced by dai_manage_cities().
|
static |
Choose a build for the barbarian player.
TODO: Move this into daimilitary.c TODO: It will be called for each city but doesn't depend on the city, maybe cache it? Although barbarians don't normally have many cities, so can be a bigger bother to cache it.
Definition at line 201 of file daicity.c.
Referenced by dai_city_choose_build().
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 of those improvements, and increase the want for technologies that will enable buildings with desirable effects.
Definition at line 1949 of file daicity.c.
Referenced by cai_build_adv_adjust(), and texwai_build_adv_adjust().
Initialize building advisor. Calculates data of all players, not only of those controlled by current ai type.
Definition at line 1933 of file daicity.c.
Referenced by cai_build_adv_init(), and texwai_build_adv_init().
bool dai_can_city_build_improvement_later | ( | const struct city * | pcity, |
const struct impr_type * | pimprove | ||
) |
Whether AI expects to be ever able to build given building in the city
Definition at line 2094 of file daicity.c.
Referenced by should_force_recalc().
bool dai_can_player_build_improvement_later | ( | const struct player * | p, |
const struct impr_type * | pimprove | ||
) |
Whether AI expects to be ever able to build given building
Definition at line 2124 of file daicity.c.
Referenced by dai_can_city_build_improvement_later().
|
static |
Default AI does not know ways of ever fulfilling this requirement and should not think about it
Definition at line 2073 of file daicity.c.
Referenced by dai_can_city_build_improvement_later(), and dai_can_player_build_improvement_later().
Initialize city for use with default AI.
Definition at line 1112 of file daicity.c.
Referenced by cai_city_alloc().
|
static |
Chooses what the city will build. Is called after the military advisor put it's choice into pcity->server.ai.choice and "settler advisor" put settler want into pcity->founder_*.
Note that AI cheats – it suffers no penalty for switching from unit to improvement, etc.
Definition at line 251 of file daicity.c.
Referenced by dai_manage_cities().
Free city from use with default AI.
Definition at line 1125 of file daicity.c.
Referenced by cai_city_free().
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
Definition at line 1166 of file daicity.c.
Referenced by cai_city_load(), and texwai_city_load().
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
Definition at line 1139 of file daicity.c.
Referenced by cai_city_save(), and texwai_city_save().
Sell an noncritical building if there are any in the city.
Definition at line 988 of file daicity.c.
Referenced by dai_manage_cities().
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. Set pimprove to NULL when nothing in the city has changed, and you just want to know the base want of a city.
Definition at line 1426 of file daicity.c.
Referenced by base_want(), dai_adjust_policies(), dai_build_adv_init(), dai_gov_value(), and dai_tech_base_want().
Is it ok for advisor code to consider given city as wonder city?
Definition at line 2060 of file daicity.c.
Referenced by cai_consider_wonder_city(), and texwai_consider_wonder_city().
Impr_type_id dai_find_source_building | ( | struct city * | pcity, |
enum effect_type effect_type effect_type | , | ||
const struct unit_type * | utype | ||
) |
Returns a buildable, non-obsolete building that can provide the effect.
Note: this function is an inefficient hack to be used by the old AI. It will never find wonders, since that's not what the AI wants.
Definition at line 2160 of file daicity.c.
Referenced by adjust_ai_unit_choice(), assess_danger(), and military_advisor_choose_build().
One of the top level AI functions. It does (by calling other functions): worker allocations, build choices, extra gold spending.
Definition at line 852 of file daicity.c.
Referenced by dai_do_last_activities().
Try to upgrade a city's units. limit is the last amount of gold we can end up with after the upgrade. military is if we want to upgrade non- military or military units.
Definition at line 382 of file daicity.c.
Referenced by dai_spend_gold().
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 effect.
Definition at line 178 of file daicity.c.
Referenced by adjust_improvement_wants_by_effects().
Increase maxbuycost. This variable indicates (via ai_gold_reserve) to the tax selection code how much money do we need for buying stuff.
Definition at line 372 of file daicity.c.
Referenced by dai_spend_gold(), and dai_upgrade_units().
|
static |
This function tries desperately to save a city from going under by revolt or starvation of food or resources. We do this by taking over resources held by nearby cities and disbanding units.
TODO: Try to move units into friendly cities to reduce unhappiness instead of disbanding. Also rather starve city than keep it in revolt, as long as we don't lose settlers.
TODO: Make function that tries to save units by moving them into cities that can upkeep them and change homecity rather than just disband. This means we'll have to move this function to beginning of AI turn sequence (before moving units).
"I don't care how slow this is; it will very rarely be used." – Syela
Syela is wrong. It happens quite too often, mostly due to unhappiness. Also, most of the time we are unable to resolve the situation.
Definition at line 1031 of file daicity.c.
Referenced by dai_manage_cities().
Whether the AI should calculate the building wants for this city this turn, ahead of schedule.
Always recalculate if the city just finished building, so we can make a sensible choice for the next thing to build. Perhaps the improvement we were building has become obsolete, or a different player built the Great Wonder we were building.
Definition at line 1920 of file daicity.c.
Referenced by dai_build_adv_adjust().
|
static |
Try to disband punit in the traditional way.
Try to disband the specified unit. Match the old behavior in what kind of disbanding is tried and who benefits from it.
Definition at line 453 of file daicity.c.
Referenced by dai_spend_gold(), and resolve_city_emergency().
Calculates a unit's food upkeep (per turn).
Definition at line 692 of file daicity.c.
Referenced by contemplate_terrain_improvements().
Returns how much food a settler will consume out of the city's foodbox when created. If unit has id zero it is assumed to be a virtual unit inside a city.
FIXME: This function should be generalised and then moved into common/unittype.c - Per
Definition at line 711 of file daicity.c.
Referenced by contemplate_terrain_improvements().
|
static |
Increase want for a technology because of the value of that technology in providing an improvement effect.
The input building_want gives the desire for the improvement; the value may be negative for technologies that produce undesirable effects.
This function must convert from units of 'building want' to 'tech want'. We put this conversion in a function because the 'want' scales are unclear and kludged. Consequently, this conversion might require tweaking.
Definition at line 128 of file daicity.c.
Referenced by dont_want_tech_obsoleting_impr(), and want_techs_for_improvement_effect().
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 effect.
Definition at line 157 of file daicity.c.
Referenced by adjust_improvement_wants_by_effects(), and adjust_wants_for_reqs().