Author: cazfi
Date: Sat Oct 17 22:48:24 2015
New Revision: 30122

URL: http://svn.gna.org/viewcvs/freeciv?rev=30122&view=rev
Log:
AI establishes trade routes with peaceful (and not only allied) players.

See patch #6418

Modified:
    branches/S2_6/ai/default/aiunit.c
    branches/S2_6/common/aicore/caravan.c
    branches/S2_6/common/aicore/caravan.h

Modified: branches/S2_6/ai/default/aiunit.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/ai/default/aiunit.c?rev=30122&r1=30121&r2=30122&view=diff
==============================================================================
--- branches/S2_6/ai/default/aiunit.c   (original)
+++ branches/S2_6/ai/default/aiunit.c   Sat Oct 17 22:48:24 2015
@@ -2230,7 +2230,16 @@
     }
 
     caravan_parameter_init_from_unit(&parameter, punit);
-    parameter.allow_foreign_trade = TRUE;
+    /* Make more trade with allies than other peaceful nations
+     * by considering only allies 50% of the time.
+     * (the other 50% allies are still considered, but so are other nations) */
+    if (fc_rand(2)) {
+      /* Be optimistic about development of relations with no-contact and
+       * cease-fire nations. */
+      parameter.allow_foreign_trade = FTL_NONWAR;
+    } else {
+      parameter.allow_foreign_trade = FTL_ALLIED;
+    }
 
     if (log_do_output_for_level(LOG_CARAVAN2)) {
       parameter.callback = caravan_optimize_callback;

Modified: branches/S2_6/common/aicore/caravan.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/aicore/caravan.c?rev=30122&r1=30121&r2=30122&view=diff
==============================================================================
--- branches/S2_6/common/aicore/caravan.c       (original)
+++ branches/S2_6/common/aicore/caravan.c       Sat Oct 17 22:48:24 2015
@@ -41,7 +41,7 @@
   parameter->consider_trade = TRUE;
   parameter->consider_wonders = TRUE; /* see also init_from_unit */
   parameter->account_for_broken_routes = TRUE;
-  parameter->allow_foreign_trade = FALSE;
+  parameter->allow_foreign_trade = FTL_NATIONAL_ONLY;
   parameter->ignore_transit_time = FALSE;
   parameter->convert_trade = FALSE;
   parameter->callback = NULL;
@@ -111,7 +111,7 @@
          parameter->consider_trade ? "trade" : "-",
          parameter->consider_wonders ? "wonders" : "-",
          parameter->account_for_broken_routes ? "yes" : "no",
-         parameter->allow_foreign_trade ? "yes" : "no",
+         parameter->allow_foreign_trade != FTL_NATIONAL_ONLY ? "yes" : "no",
          parameter->ignore_transit_time ? "yes" : "no",
          parameter->convert_trade ? "yes" : "no");
 }
@@ -425,12 +425,17 @@
   struct player *pplayer_dest = city_owner(dest);
   
   /* if no foreign trade is allowed, just quit. */
-  if (!parameter->allow_foreign_trade && pplayer_src != pplayer_dest) {
+  if (parameter->allow_foreign_trade == FTL_NATIONAL_ONLY
+      && pplayer_src != pplayer_dest) {
     caravan_result_init_zero(result);
     return;
   } else {
     /* foreign trade allowed, we only do business with allies */
-    if (pplayers_allied(pplayer_src, pplayer_dest)) {
+    if (pplayers_allied(pplayer_src, pplayer_dest)
+        || (parameter->allow_foreign_trade == FTL_PEACEFUL
+            && pplayers_in_peace(pplayer_src, pplayer_dest))
+        || (parameter->allow_foreign_trade == FTL_NONWAR
+            && !pplayers_at_war(pplayer_src, pplayer_dest))) {
       /* do some business */
     } else {
       caravan_result_init_zero(result);

Modified: branches/S2_6/common/aicore/caravan.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/aicore/caravan.h?rev=30122&r1=30121&r2=30122&view=diff
==============================================================================
--- branches/S2_6/common/aicore/caravan.h       (original)
+++ branches/S2_6/common/aicore/caravan.h       Sat Oct 17 22:48:24 2015
@@ -19,6 +19,14 @@
 
 /* common */
 #include "fc_types.h"
+
+enum foreign_trade_limit
+{
+  FTL_NATIONAL_ONLY,
+  FTL_ALLIED,
+  FTL_PEACEFUL,
+  FTL_NONWAR
+};
 
 
 /**
@@ -83,7 +91,7 @@
      * Allow trading with allies and peaceful neighbours.
      * BUG: currently we only consider allies.
      */
-    bool allow_foreign_trade;
+    enum foreign_trade_limit allow_foreign_trade;
 
     /*
      * Normally, we'd want to compute the time it takes to establish the


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

Reply via email to