Feature #724 ยป 0028-AI-Improve-military_advisor_choose_build-parameter-o.patch
ai/classic/classicai.c | ||
---|---|---|
{
|
||
struct ai_type *deftype = classic_ai_get_self();
|
||
dai_assess_danger_player(deftype, original, &(wld.map));
|
||
dai_assess_danger_player(deftype, &(wld.map), original);
|
||
}
|
||
/**********************************************************************//**
|
ai/default/aihand.c | ||
---|---|---|
}
|
||
/*************************************************************************//**
|
||
Activities to be done by AI _before_ human turn. Here we just move the
|
||
Activities to be done by AI _before_ human turn. Here we just move the
|
||
units intelligently.
|
||
*****************************************************************************/
|
||
void dai_do_first_activities(struct ai_type *ait, struct player *pplayer)
|
||
{
|
||
TIMING_LOG(AIT_ALL, TIMER_START);
|
||
dai_assess_danger_player(ait, pplayer, &(wld.map));
|
||
dai_assess_danger_player(ait, &(wld.map), pplayer);
|
||
/* TODO: Make assess_danger save information on what is threatening
|
||
* us and make dai_manage_units and Co act upon this information, trying
|
||
* to eliminate the source of danger */
|
||
... | ... | |
}
|
||
/*************************************************************************//**
|
||
Activities to be done by AI _after_ human turn. Here we respond to
|
||
Activities to be done by AI _after_ human turn. Here we respond to
|
||
dangers created by human and AI opposition by ordering defenders in
|
||
cities and setting taxes accordingly. We also do other duties.
|
||
cities and setting taxes accordingly. We also do other duties.
|
||
We do _not_ move units here, otherwise humans complain that AI moves
|
||
twice.
|
ai/default/daicity.c | ||
---|---|---|
if (city_data->choice.want <= 0) {
|
||
/* Note that this function mungs the seamap, but we don't care */
|
||
TIMING_LOG(AIT_CITY_MILITARY, TIMER_START);
|
||
choice = military_advisor_choose_build(ait, pplayer, pcity, &(wld.map), NULL);
|
||
choice = military_advisor_choose_build(ait, &(wld.map), pplayer, pcity, NULL);
|
||
adv_choice_copy(&(city_data->choice), choice);
|
||
adv_free_choice(choice);
|
||
TIMING_LOG(AIT_CITY_MILITARY, TIMER_STOP);
|
ai/default/daimilitary.c | ||
---|---|---|
#define CITY_CONQUEST_WORTH(_city_, _data_) \
|
||
(_data_->worth * 0.9 + (city_size_get(_city_) - 0.5) * 10)
|
||
static unsigned int assess_danger(struct ai_type *ait, struct city *pcity,
|
||
const struct civ_map *dmap,
|
||
static unsigned int assess_danger(struct ai_type *ait,
|
||
const struct civ_map *nmap,
|
||
struct city *pcity,
|
||
player_unit_list_getter ul_cb);
|
||
static adv_want dai_unit_attack_desirability(struct ai_type *ait,
|
||
... | ... | |
This is necessary to initialize some ai data before some ai calculations.
|
||
**************************************************************************/
|
||
void dai_assess_danger_player(struct ai_type *ait, struct player *pplayer,
|
||
const struct civ_map *dmap)
|
||
void dai_assess_danger_player(struct ai_type *ait,
|
||
const struct civ_map *nmap,
|
||
struct player *pplayer)
|
||
{
|
||
/* Do nothing if game is not running */
|
||
if (S_S_RUNNING == server_state()) {
|
||
city_list_iterate(pplayer->cities, pcity) {
|
||
(void) assess_danger(ait, pcity, dmap, NULL);
|
||
(void) assess_danger(ait, nmap, pcity, NULL);
|
||
} city_list_iterate_end;
|
||
}
|
||
}
|
||
... | ... | |
afraid of a boat laden with enemies if it stands on the coast (i.e.
|
||
is directly reachable by this boat).
|
||
**************************************************************************/
|
||
static unsigned int assess_danger(struct ai_type *ait, struct city *pcity,
|
||
const struct civ_map *dmap,
|
||
static unsigned int assess_danger(struct ai_type *ait,
|
||
const struct civ_map *nmap,
|
||
struct city *pcity,
|
||
player_unit_list_getter ul_cb)
|
||
{
|
||
struct player *pplayer = city_owner(pcity);
|
||
... | ... | |
* at war with. */
|
||
pcity_map = pf_reverse_map_new_for_city(pcity, aplayer, assess_turns,
|
||
omnimap, dmap);
|
||
omnimap, nmap);
|
||
if (ul_cb != NULL) {
|
||
units = ul_cb(aplayer);
|
||
... | ... | |
If 'choice->want' is 0 this advisor doesn't want anything.
|
||
**************************************************************************/
|
||
struct adv_choice *military_advisor_choose_build(struct ai_type *ait,
|
||
const struct civ_map *nmap,
|
||
struct player *pplayer,
|
||
struct city *pcity,
|
||
const struct civ_map *mamap,
|
||
player_unit_list_getter ul_cb)
|
||
{
|
||
struct adv_data *ai = adv_data_get(pplayer, NULL);
|
||
... | ... | |
struct adv_choice *choice = adv_new_choice();
|
||
bool allow_gold_upkeep;
|
||
urgency = assess_danger(ait, pcity, mamap, ul_cb);
|
||
urgency = assess_danger(ait, nmap, pcity, ul_cb);
|
||
/* Changing to quadratic to stop AI from building piles
|
||
* of small units -- Syela */
|
||
/* It has to be AFTER assess_danger thanks to wallvalue. */
|
||
/* It has to be AFTER assess_danger() thanks to wallvalue. */
|
||
our_def = assess_defense_quadratic(ait, pcity);
|
||
dai_choose_diplomat_defensive(ait, pplayer, pcity, choice, our_def);
|
||
... | ... | |
if (pcity->server.adv->building_want[wall_id] > 0) {
|
||
/* NB: great wall is under domestic */
|
||
choice->value.building = pimprove;
|
||
/* building_want is hacked by assess_danger */
|
||
/* building_want is hacked by assess_danger() */
|
||
choice->want = pcity->server.adv->building_want[wall_id];
|
||
choice->want = choice->want * (0.5 + (ai_trait_get_value(TRAIT_BUILDER, pplayer)
|
||
/ TRAIT_DEFAULT_VALUE / 2));
|
ai/default/daimilitary.h | ||
---|---|---|
struct unit_type *dai_choose_defender_versus(struct city *pcity,
|
||
struct unit *attacker);
|
||
struct adv_choice *military_advisor_choose_build(struct ai_type *ait,
|
||
const struct civ_map *nmap,
|
||
struct player *pplayer,
|
||
struct city *pcity,
|
||
const struct civ_map *mamap,
|
||
player_unit_list_getter ul_cb);
|
||
void dai_assess_danger_player(struct ai_type *ait, struct player *pplayer,
|
||
const struct civ_map *dmap);
|
||
void dai_assess_danger_player(struct ai_type *ait,
|
||
const struct civ_map *nmap, struct player *pplayer);
|
||
int assess_defense_quadratic(struct ai_type *ait, struct city *pcity);
|
||
int assess_defense_unit(struct ai_type *ait, struct city *pcity,
|
||
struct unit *punit, bool igwall);
|
ai/default/daiplayer.c | ||
---|---|---|
} city_list_iterate_end;
|
||
}
|
||
dai_assess_danger_player(ait, pplayer, &(wld.map));
|
||
dai_assess_danger_player(ait, &(wld.map), pplayer);
|
||
}
|
ai/tex/texai.c | ||
---|---|---|
struct player *created)
|
||
{
|
||
TEXAI_AIT;
|
||
TEXAI_DFUNC(dai_assess_danger_player, original, &(wld.map));
|
||
TEXAI_DFUNC(dai_assess_danger_player, &(wld.map), original);
|
||
}
|
||
/**********************************************************************//**
|
ai/tex/texaiplayer.c | ||
---|---|---|
texai_city_worker_wants(ait, msg->plr, pcity);
|
||
if (tex_city != NULL) {
|
||
choice = military_advisor_choose_build(ait, msg->plr, tex_city,
|
||
texai_map_get(),
|
||
choice = military_advisor_choose_build(ait, texai_map_get(),
|
||
msg->plr, tex_city,
|
||
texai_player_units);
|
||
choice_req->city_id = tex_city->id;
|
||
adv_choice_copy(&(choice_req->choice), choice);
|