Author: sveinung
Date: Thu Dec 11 12:12:09 2014
New Revision: 27253

URL: http://svn.gna.org/viewcvs/freeciv?rev=27253&view=rev
Log:
AI: Try a new target when a caravan can't act against its current target.

A ruleset may have restrictions on caravan actions the AI don't understand. Try
a different target when it is clear that current target is impossible.

See patch #5527

Modified:
    trunk/ai/default/aiunit.c
    trunk/common/aicore/caravan.c

Modified: trunk/ai/default/aiunit.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/default/aiunit.c?rev=27253&r1=27252&r2=27253&view=diff
==============================================================================
--- trunk/ai/default/aiunit.c   (original)
+++ trunk/ai/default/aiunit.c   Thu Dec 11 12:12:09 2014
@@ -2190,7 +2190,11 @@
             && !(is_action_enabled_unit_on_city(ACTION_TRADE_ROUTE,
                                                 punit, city_dest)
                  || is_action_enabled_unit_on_city(ACTION_MARKETPLACE,
-                                                   punit, city_dest)))) {
+                                                   punit, city_dest)))
+        || (unit_data->task == AIUNIT_WONDER
+            && real_map_distance(city_dest->tile, unit_tile(punit)) <= 1
+            && !is_action_enabled_unit_on_city(ACTION_HELP_WONDER,
+                                               punit, city_dest))) {
       /* destination invalid! */
       dai_unit_new_task(ait, punit, AIUNIT_NONE, NULL);
       log_base(LOG_CARAVAN2, "%s %s[%d](%d,%d) destination invalid!",

Modified: trunk/common/aicore/caravan.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/aicore/caravan.c?rev=27253&r1=27252&r2=27253&view=diff
==============================================================================
--- trunk/common/aicore/caravan.c       (original)
+++ trunk/common/aicore/caravan.c       Thu Dec 11 12:12:09 2014
@@ -437,7 +437,27 @@
       return;
     }
   }
-  
+
+  /* Make sure that the caravan gets a new target in cases were the old
+   * target turned out to be of no use because of action enablers. */
+  if (real_map_distance(dest->tile, unit_tile(caravan)) <= 1) {
+    /* The caravan is close enought to its target to do a full check.
+     * A caravan can be close enough to max 9 cities in the worst
+     * theoretically possible case. (More than one city is rare.) The
+     * computations are therefore worth it. */
+
+    if (!(is_action_enabled_unit_on_city(ACTION_HELP_WONDER,
+                                         caravan, dest)
+          || is_action_enabled_unit_on_city(ACTION_TRADE_ROUTE,
+                                            caravan, dest)
+          || is_action_enabled_unit_on_city(ACTION_MARKETPLACE,
+                                            caravan, dest))) {
+      /* No caravan action is possible against this target. */
+      caravan_result_init_zero(result);
+      return;
+    }
+  }
+
   trade = trade_benefit(pplayer_src, src, dest, parameter);
   windfall = windfall_benefit(caravan, src, dest, parameter);
   wonder = wonder_benefit(caravan, arrival_time, dest, parameter);


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

Reply via email to