Author: cazfi Date: Sun May 8 17:46:05 2016 New Revision: 32622 URL: http://svn.gna.org/viewcvs/freeciv?rev=32622&view=rev Log: AI: Consider building defensive units instead, if would have wanted to build defensive building but there was no good one available. It used to skip defensive unit considerations when ever defensive building was even considered.
See patch #5471 Modified: trunk/ai/default/daimilitary.c Modified: trunk/ai/default/daimilitary.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/ai/default/daimilitary.c?rev=32622&r1=32621&r2=32622&view=diff ============================================================================== --- trunk/ai/default/daimilitary.c (original) +++ trunk/ai/default/daimilitary.c Sun May 8 17:46:05 2016 @@ -41,6 +41,7 @@ /* server/advisors */ #include "advbuilding.h" +#include "advchoice.h" #include "advdata.h" #include "advtools.h" #include "autosettlers.h" @@ -1490,37 +1491,53 @@ || (city_data->grave_danger == 0 && pplayer->economic.gold > impr_buy_gold_cost(pimprove, pcity->shield_stock))) && ai_fuzzy(pplayer, TRUE)) { - /* NB: great wall is under domestic */ - choice->value.building = pimprove; - /* building_want is hacked by assess_danger */ - choice->want = pcity->server.adv->building_want[wall_id]; - if (urgency == 0 && choice->want > 100) { - choice->want = 100; + 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 */ + choice->want = pcity->server.adv->building_want[wall_id]; + if (urgency == 0 && choice->want > 100) { + choice->want = 100; + } + choice->type = CT_BUILDING; + adv_choice_set_use(choice, "defense building"); + CITY_LOG(LOG_DEBUG, pcity, + "m_a_c_d wants defense building with " ADV_WANT_PRINTF, + choice->want); + } else { + build_walls = FALSE; } - choice->type = CT_BUILDING; - adv_choice_set_use(choice, "defense building"); - CITY_LOG(LOG_DEBUG, pcity, - "m_a_c_d wants defense building with " ADV_WANT_PRINTF, - choice->want); - } else if ((danger > 0 && num_defenders <= urgency) || martial_value > 0) { + } else { + build_walls = FALSE; + } + if ((danger > 0 && num_defenders <= urgency) || martial_value > 0) { + struct adv_choice uchoice; + + adv_init_choice(&uchoice); + /* Consider building defensive units */ - if (dai_process_defender_want(ait, pplayer, pcity, danger, choice)) { + if (dai_process_defender_want(ait, pplayer, pcity, danger, &uchoice)) { /* Potential defender found */ if (urgency == 0 - && choice->value.utype->defense_strength == 1) { + && uchoice.value.utype->defense_strength == 1) { /* FIXME: check other reqs (unit class?) */ if (get_city_bonus(pcity, EFT_HP_REGEN) > 0) { /* unlikely */ - choice->want = MIN(49, danger); + uchoice.want = MIN(49, danger); } else { - choice->want = MIN(25, danger); + uchoice.want = MIN(25, danger); } } else { - choice->want = danger; + uchoice.want = danger; } - choice->want += martial_value; - adv_choice_set_use(choice, "defender"); + uchoice.want += martial_value; + adv_choice_set_use(&uchoice, "defender"); + + if (!build_walls || uchoice.want > choice->want) { + adv_choice_copy(choice, &uchoice); + } + adv_deinit_choice(&uchoice); CITY_LOG(LOG_DEBUG, pcity, "m_a_c_d wants %s with desire " ADV_WANT_PRINTF, utype_rule_name(choice->value.utype), _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits