Project

Profile

Help

HostedRedmine.com has moved to the Planio platform. All logins and passwords remained the same. All users will be able to login and use Redmine just as before. *Read more...*

Feature #732767 ยป 0078-tex-Use-tex-ai-player-data-unit-list-in-military_adv.patch

Marko Lindqvist, 2018-02-12 07:20 PM

View differences:

ai/default/aicity.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));
choice = military_advisor_choose_build(ait, pplayer, pcity, &(wld.map), NULL);
adv_choice_copy(&(city_data->choice), choice);
adv_free_choice(choice);
TIMING_LOG(AIT_CITY_MILITARY, TIMER_STOP);
ai/default/daimilitary.c
#include "daimilitary.h"
static unsigned int assess_danger(struct ai_type *ait, struct city *pcity,
const struct civ_map *dmap);
const struct civ_map *dmap,
player_unit_list_getter ul_cb);
/**********************************************************************//**
Choose the best unit the city can build to defend against attacker v.
......
/* 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);
(void) assess_danger(ait, pcity, dmap, NULL);
} city_list_iterate_end;
}
}
......
is directly reachable by this boat).
**************************************************************************/
static unsigned int assess_danger(struct ai_type *ait, struct city *pcity,
const struct civ_map *dmap)
const struct civ_map *dmap,
player_unit_list_getter ul_cb)
{
struct player *pplayer = city_owner(pcity);
struct tile *ptile = city_tile(pcity);
......
/* Check. */
players_iterate(aplayer) {
struct pf_reverse_map *pcity_map;
struct unit_list *units;
if (!adv_is_player_dangerous(pplayer, aplayer)) {
continue;
......
pcity_map = pf_reverse_map_new_for_city(pcity, aplayer, assess_turns,
omnimap, dmap);
unit_list_iterate(aplayer->units, punit) {
if (ul_cb != NULL) {
units = ul_cb(aplayer);
} else {
units = aplayer->units;
}
unit_list_iterate(units, punit) {
int move_time;
unsigned int vulnerability;
int defbonus;
......
struct adv_choice *military_advisor_choose_build(struct ai_type *ait,
struct player *pplayer,
struct city *pcity,
const struct civ_map *mamap)
const struct civ_map *mamap,
player_unit_list_getter ul_cb)
{
struct adv_data *ai = adv_data_get(pplayer, NULL);
struct unit_type *punittype;
......
struct adv_choice *choice = adv_new_choice();
bool allow_gold_upkeep;
urgency = assess_danger(ait, pcity, mamap);
urgency = assess_danger(ait, pcity, mamap, 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. */
ai/default/daimilitary.h
#define AI_HANDICAP_DISTANCE_LIMIT 6 //TODO: 20 for non-web
#endif /* FREECIV_WEB */
typedef struct unit_list *(player_unit_list_getter)(struct player *pplayer);
struct unit_type *dai_choose_defender_versus(struct city *pcity,
struct unit *attacker);
void military_advisor_choose_tech(struct player *pplayer,
......
struct adv_choice *military_advisor_choose_build(struct ai_type *ait,
struct player *pplayer,
struct city *pcity,
const struct civ_map *mamap);
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);
int assess_defense_quadratic(struct ai_type *ait, struct city *pcity);
ai/tex/texaiplayer.c
texai_map_close();
}
/**********************************************************************//**
Callback that returns unit list from player tex ai data.
**************************************************************************/
static struct unit_list *texai_player_units(struct player *pplayer)
{
struct texai_plr *plr_data = player_ai_data(pplayer, texai_get_self());
return plr_data->units;
}
/**********************************************************************//**
Handle messages from message queue.
**************************************************************************/
......
if (tex_city != NULL) {
choice = military_advisor_choose_build(ait, msg->plr, tex_city,
texai_map_get());
texai_map_get(), texai_player_units);
choice_req->city_id = tex_city->id;
adv_choice_copy(&(choice_req->choice), choice);
adv_free_choice(choice);
    (1-1/1)