Author: cazfi
Date: Wed Jun 22 09:11:37 2016
New Revision: 32956

URL: http://svn.gna.org/viewcvs/freeciv?rev=32956&view=rev
Log:
Make AI to build buildings that are not crucial but merely useful

Reported by David Fernandez <bardo>

See bug #24526

Modified:
    branches/S2_6/ai/default/aicity.c

Modified: branches/S2_6/ai/default/aicity.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/ai/default/aicity.c?rev=32956&r1=32955&r2=32956&view=diff
==============================================================================
--- branches/S2_6/ai/default/aicity.c   (original)
+++ branches/S2_6/ai/default/aicity.c   Wed Jun 22 09:11:37 2016
@@ -824,23 +824,23 @@
   constructed, side effect benefits may not be accurately calculated
   (see improvement.c for details).
 **************************************************************************/
-static bool building_unwanted(const struct player *plr,
-                              struct impr_type *pimprove,
-                              const struct city *pcity)
+static bool building_crucial(const struct player *plr,
+                             struct impr_type *pimprove,
+                             const struct city *pcity)
 {
 #if 0 /* This check will become more complicated now. */ 
   if (ai_wants_no_science(plr)
       && building_has_effect(pimprove, EFT_SCIENCE_BONUS)) {
-    return TRUE;
+    return FALSE;
   }
 #endif
   if (building_has_effect(pimprove, EFT_DEFEND_BONUS)
         /* selling city walls is really, really dumb -- Syela */
       || is_improvement_productive(pcity, pimprove)) {
-    return FALSE;
-  }
-
-  return TRUE;
+    return TRUE;
+  }
+
+  return FALSE;
 }
 
 /**************************************************************************
@@ -851,13 +851,13 @@
   struct player *pplayer = city_owner(pcity);
 
   city_built_iterate(pcity, pimprove) {
-    if (can_city_sell_building(pcity, pimprove) 
-       && building_unwanted(pplayer, pimprove, pcity)) {
+    if (can_city_sell_building(pcity, pimprove)
+        && !building_crucial(pplayer, pimprove, pcity)) {
       do_sell_building(pplayer, pcity, pimprove);
       notify_player(pplayer, pcity->tile, E_IMP_SOLD, ftc_server,
-                    _("%s is selling %s (not needed) for %d."), 
+                    _("%s is selling %s (not needed) for %d."),
                     city_link(pcity),
-                    improvement_name_translation(pimprove), 
+                    improvement_name_translation(pimprove),
                     impr_sell_gold(pimprove));
       return; /* max 1 building each turn */
     }
@@ -1712,17 +1712,12 @@
 
     /* Handle coinage specially because you can never complete coinage */
     if (is_coinage
-     || can_player_build_improvement_later(pplayer, pimprove)) {
+        || can_player_build_improvement_later(pplayer, pimprove)) {
       city_list_iterate(pplayer->cities, pcity) {
         struct ai_city *city_data = def_ai_city_data(pcity, ait);
 
         if (pcity != wonder_city && is_wonder(pimprove)) {
           /* Only wonder city should build wonders! */
-          pcity->server.adv->building_want[improvement_index(pimprove)] = 0;
-        } else if ((!is_coinage
-                    && !can_city_build_improvement_later(pcity, pimprove))
-                   || building_unwanted(pplayer, pimprove, pcity)) {
-          /* Don't consider impossible or unwanted buildings */
           pcity->server.adv->building_want[improvement_index(pimprove)] = 0;
         } else if (city_data->building_turn <= game.info.turn) {
           /* Building wants vary relatively slowly, so not worthwhile
@@ -1731,7 +1726,7 @@
            * we already have. */
           const bool already = city_has_building(pcity, pimprove);
 
-          adjust_improvement_wants_by_effects(ait, pplayer, pcity, 
+          adjust_improvement_wants_by_effects(ait, pplayer, pcity,
                                               pimprove, already);
 
           fc_assert(!(already
@@ -1755,7 +1750,7 @@
     }
   } improvement_iterate_end;
 
-#ifdef DEBUG
+#ifdef FREECIV_DEBUG
   /* This logging is relatively expensive, so activate only if necessary */
   city_list_iterate(pplayer->cities, pcity) {
     improvement_iterate(pimprove) {
@@ -1766,7 +1761,7 @@
       }
     } improvement_iterate_end;
   } city_list_iterate_end;
-#endif /* DEBUG */
+#endif /* FREECIV_DEBUG */
 
   /* Reset recalc counter */
   city_list_iterate(pplayer->cities, pcity) {


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

Reply via email to