Author: cazfi
Date: Wed Aug  3 01:19:40 2016
New Revision: 33429

URL: http://svn.gna.org/viewcvs/freeciv?rev=33429&view=rev
Log:
Make AI not to constantly sell almost all its buildings.

See patch #7522

Modified:
    trunk/ai/default/aicity.c

Modified: trunk/ai/default/aicity.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/default/aicity.c?rev=33429&r1=33428&r2=33429&view=diff
==============================================================================
--- trunk/ai/default/aicity.c   (original)
+++ trunk/ai/default/aicity.c   Wed Aug  3 01:19:40 2016
@@ -110,7 +110,7 @@
  (pcity->surplus[O_SHIELD] < 0 || city_unhappy(pcity)                  \
   || pcity->food_stock + pcity->surplus[O_FOOD] < 0)
 
-static void dai_sell_obsolete_buildings(struct city *pcity);
+static void dai_city_sell_noncritical(struct city *pcity, bool redundant_only);
 static void resolve_city_emergency(struct ai_type *ait, struct player *pplayer,
                                    struct city *pcity);
 
@@ -824,9 +824,35 @@
       /* Fix critical shortages or unhappiness */
       resolve_city_emergency(ait, pplayer, pcity);
     }
-    dai_sell_obsolete_buildings(pcity);
+    dai_city_sell_noncritical(pcity, TRUE);
     sync_cities();
   } city_list_iterate_end;
+  if (pplayer->economic.tax >= 30 /* Otherwise expect it to increase tax */
+      && player_get_expected_income(pplayer) < -(pplayer->economic.gold)) {
+    int count = city_list_size(pplayer->cities);
+    struct city *sellers[count + 1];
+    int i;
+
+    /* Randomized order */
+    i = 0;
+    city_list_iterate(pplayer->cities, pcity) {
+      sellers[i++] = pcity;
+    } city_list_iterate_end;
+    for (i = 0; i < count; i++) {
+      int replace = fc_rand(count);
+      struct city *tmp;
+
+      tmp = sellers[i];
+      sellers[i] = sellers[replace];
+      sellers[replace] = tmp;
+    }
+
+    i = 0;
+    while (player_get_expected_income(pplayer) < -(pplayer->economic.gold)
+           && i < count) {
+      dai_city_sell_noncritical(sellers[i++], FALSE);
+    }
+  }
   TIMING_LOG(AIT_EMERGENCY, TIMER_STOP);
 
   TIMING_LOG(AIT_BUILDINGS, TIMER_START);
@@ -911,18 +937,20 @@
 }
 
 /**************************************************************************
-  Sell an obsolete building if there are any in the city.
-**************************************************************************/
-static void dai_sell_obsolete_buildings(struct city *pcity)
+  Sell an noncritical building if there are any in the city.
+**************************************************************************/
+static void dai_city_sell_noncritical(struct city *pcity,
+                                      bool redundant_only)
 {
   struct player *pplayer = city_owner(pcity);
 
   city_built_iterate(pcity, pimprove) {
     if (can_city_sell_building(pcity, pimprove)
-        && !building_crucial(pplayer, pimprove, pcity)) {
+        && !building_crucial(pplayer, pimprove, pcity)
+        && (!redundant_only || is_improvement_redundant(pcity, pimprove))) {
       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 for %d."),
                     city_link(pcity),
                     improvement_name_translation(pimprove),
                     impr_sell_gold(pimprove));


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

Reply via email to