Author: cazfi
Date: Sun May  8 17:46:10 2016
New Revision: 32623

URL: http://svn.gna.org/viewcvs/freeciv?rev=32623&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:
    branches/S2_6/ai/default/daimilitary.c

Modified: branches/S2_6/ai/default/daimilitary.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/ai/default/daimilitary.c?rev=32623&r1=32622&r2=32623&view=diff
==============================================================================
--- branches/S2_6/ai/default/daimilitary.c      (original)
+++ branches/S2_6/ai/default/daimilitary.c      Sun May  8 17:46:10 2016
@@ -1478,39 +1478,54 @@
               || (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;
+          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;
-        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;
           }
 
-          choice->want += martial_value;
+          uchoice.want += martial_value;
 
           CITY_LOG(LOG_DEBUG, pcity, "m_a_c_d wants %s with desire " 
ADV_WANT_PRINTF,
                    utype_rule_name(choice->value.utype),
                    choice->want);
+
+          if (!build_walls || uchoice.want > choice->want) {
+            *choice = uchoice;
+          }
         } else {
           CITY_LOG(LOG_DEBUG, pcity, "m_a_c_d cannot select defender");
         }


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to