70 int num_cities_nonzero =
MAX(1, city_list_size(pplayer->
cities));
75 memset(values, 0,
sizeof(values));
110 values[k] += plr_data->
tech_want[i] / steps;
131 goal_values[i] = values[i];
135 goal_values[i] += values[k];
143 goal_values[i] /= steps;
146 ", value = %d, goal_value = %d",
148 plr_data->
tech_want[i], values[i], goal_values[i]);
159 if (values[i] > values[newtech]
163 if (goal_values[i] > goal_values[newgoal]
170 #ifdef REALLY_DEBUG_THIS
176 "turn end want: %d", values[
id]);
183 choice->
want = values[newtech] / num_cities_nonzero;
185 (values[presearch->
researching] / num_cities_nonzero);
190 goal->
want = goal_values[newgoal] / num_cities_nonzero;
192 (goal_values[presearch->
tech_goal] / num_cities_nonzero);
195 ", goal_value = %d, "
196 "num_cities_nonzero = %d",
198 goal->
want, goal_values[newgoal], num_cities_nonzero);
222 bool world_knew =
game.
info.global_advances[tech];
223 int world_count =
game.
info.global_advance_count;
230 game.
info.global_advances[tech] = world_knew;
231 game.
info.global_advance_count = world_count;
233 return final_want - orig_want;
254 if (aplayer->team && aplayer->team == pplayer->
team
255 && aplayer != pplayer) {
290 if (VUT_ADVANCE == preq->source.kind
291 && preq->source.value.advance == padv) {
292 present = preq->present;
295 if (!
is_req_active(pplayer,
nullptr, pcity,
nullptr,
nullptr,
296 nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
308 peffect, 1, nplayers);
321 tech_want = v * 14 / 8;
352 if (ds->
type == DS_TEAM) {
366 "new research, was %s, penalty was %d",
404 int best_avl_def = 0;
409 int def_values[
U_LAST] = {0};
414 int mp_pct = deftype->cache.defense_mp_bonuses_pct[att_idx] + 100;
415 int div_bonus_pct = 100
417 CBONUS_DEFENSE_DIVIDER_PCT)
420 CBONUS_DEFENSE_DIVIDER);
421 int def = deftype->defense_strength * mp_pct / div_bonus_pct;
426 if (def > best_avl_def) {
436 if (def_values[
utype_index(deftype)] > best_avl_def
442 struct advance *itech = deftype->require_advance;
443 bool impossible_to_get =
false;
458 city_tile(pcity),
nullptr, deftype,
nullptr,
460 if (VUT_ADVANCE == preq->source.kind && preq->present) {
469 itech = preq->source.value.advance;
475 impossible_to_get =
true;
482 if (
cost < best_cost && !impossible_to_get
497 if (best_avl !=
nullptr
498 && def_values[
utype_index(best_unit)] <= 1.5 * best_avl_def) {
520 struct city *pcity,
int role,
int want)
530 for (i = n - 1; i >= 0; i--) {
553 if (VUT_ADVANCE == preq->source.kind && preq->present) {
561 if (imprcost < cost || cost == 0) {
565 itech = preq->source.value.advance;
589 if (build_unit !=
nullptr) {
struct adv_data * adv_data_get(struct player *pplayer, bool *caller_closes)
Return a pointer to our data.
#define TECH_LOG(ait, _, pplayer, padvance, msg,...)
static struct ai_plr * def_ai_player_data(const struct player *pplayer, struct ai_type *deftype)
struct unit_type * dai_wants_role_unit(struct ai_type *ait, struct player *pplayer, struct city *pcity, int role, int want)
Returns the best unit we can build, or nullptr if none.
static adv_want dai_tech_base_want(struct ai_type *ait, struct player *pplayer, struct city *pcity, struct advance *padv)
Calculates want for some techs by actually adding the tech and measuring the effect.
struct unit_type * dai_wants_defender_against(struct ai_type *ait, struct player *pplayer, struct city *pcity, const struct unit_type *att, int want)
Returns the best defense multiplier unit we can build, or nullptr if none.
void dai_clear_tech_wants(struct ai_type *ait, struct player *pplayer)
Zero player tech wants.
void dai_manage_tech(struct ai_type *ait, struct player *pplayer)
Key AI research function.
static void dai_select_tech(struct ai_type *ait, struct player *pplayer, struct ai_tech_choice *choice, struct ai_tech_choice *goal)
Massage the numbers provided to us by ai.tech_want into unrecognizable pulp.
static void dai_tech_effect_values(struct ai_type *ait, struct player *pplayer)
Add effect values in to tech wants.
const struct impr_type * utype_needs_improvement(const struct unit_type *putype, const struct city *pcity)
Returns an improvement that will make it possible to build units of the specified type the specified ...
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...
bool is_capital(const struct city *pcity)
Return TRUE iff this city is its nation's capital.
struct tile * city_tile(const struct city *pcity)
Return the tile location of 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.
#define city_list_iterate(citylist, pcity)
#define city_list_iterate_end
int combat_bonus_against(const struct combat_bonus_list *list, const struct unit_type *enemy, enum combat_bonus_type type)
Get bonus value against given unit type from bonus list.
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.
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).
struct effect_list * get_req_source_effects(struct universal *psource)
Get a list of effects with this requirement source.
#define effect_list_iterate_end
#define effect_list_iterate(effect_list, peffect)
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.
#define log_debug(message,...)
const char * player_name(const struct player *pplayer)
Return the leader name of the player.
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Returns diplomatic state type between two players.
#define players_iterate_end
#define players_iterate(_pplayer)
int normal_player_count()
Return the number of non-barbarian players.
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.
bool research_invention_reachable(const struct research *presearch, const Tech_type_id tech)
Returns TRUE iff the given tech is ever reachable via research by the players sharing the research by...
bool research_goal_tech_req(const struct research *presearch, Tech_type_id goal, Tech_type_id tech)
Returns if the given tech has to be researched to reach the goal.
enum tech_state research_invention_set(struct research *presearch, Tech_type_id tech, enum tech_state value)
Set research knowledge about tech to given state.
struct research * research_get(const struct player *pplayer)
Returns the research structure associated with the player.
QString research_advance_rule_name(const struct research *presearch, Tech_type_id tech)
Store the rule name of the given tech (including A_FUTURE) in 'buf'.
int research_goal_bulbs_required(const struct research *presearch, Tech_type_id goal)
Function to determine cost (in bulbs) of reaching goal technology.
int research_total_bulbs_required(const struct research *presearch, Tech_type_id tech, bool loss_value)
Function to determine cost for technology.
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Returns state of the tech for current research.
bool research_invention_gettable(const struct research *presearch, const Tech_type_id tech, bool allow_holes)
Returns TRUE iff the given tech can be given to the players sharing the research immediately.
adv_want tech_want[A_LAST+1]
struct packet_game_info info
struct requirement_vector reqs
struct city_list * cities
struct advance * require_advance
struct combat_bonus_list * bonuses
bool is_future_tech(Tech_type_id tech)
Is the given tech a future tech.
const char * advance_rule_name(const struct advance *padvance)
Return the (untranslated) rule name of the advance/technology.
struct advance * advance_by_number(const Tech_type_id atype)
Return the advance for the given advance index.
struct advance * valid_advance_by_number(const Tech_type_id id)
Returns pointer when the advance "exists" in this game, returns nullptr otherwise.
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.
#define advance_index_iterate_end
#define advance_iterate(_start, _p)
#define advance_iterate_end
#define advance_index_iterate(_start, _index)
const char * utype_rule_name(const struct unit_type *punittype)
Return the (untranslated) rule name of the unit type.
int num_role_units(int role)
How many unit types have specified role/flag.
struct unit_type * get_role_unit(int role, int role_index)
Return index-th unit with specified role/flag.
Unit_type_id utype_index(const struct unit_type *punittype)
Return the unit type index.
#define unit_type_iterate(_p)
#define unit_type_iterate_end