<URL: http://bugs.freeciv.org/Ticket/Display.html?id=40570 >

Marine explorers stop if they try to travel to or trhough a marine 
tile who's owner is at peace with the unit's owner.

As a consequence the units are stoped and require player interaction 
even though there are still unexplored reacheable tiles.

The attached patch should fixe this issue in the vast majority of 
cases. Only if ai_manage_explorer's best_title isn't reacheable does 
the explorer stop, even if there are still other unexplored reachable 
tiles.

diff -ur freeciv-2.1.6/ai/aiexplorer.c freeciv-2.1.6-marine-explorer/ai/aiexplorer.c
--- freeciv-2.1.6/ai/aiexplorer.c	2008-08-10 14:56:15.000000000 +0200
+++ freeciv-2.1.6-marine-explorer/ai/aiexplorer.c	2008-11-18 14:30:08.000000000 +0100
@@ -107,6 +107,51 @@
   }
 }
 
+/*
+ * Explorers shouldn't try to break a peace treaty and thus cause
+ * player interaction.
+ */
+static bool ai_may_explore(const struct tile * ptile,
+    const struct player * pplayer, const bv_flags unit_flags)
+{
+  if(! BV_ISSET(unit_flags, F_IGZOC)){
+    // don't invade unless there are only allied troops on the tile
+    if(players_non_invade(ptile->owner, pplayer)){
+      if(!is_allied_unit_tile(ptile, pplayer)){
+        return FALSE;
+      }
+    }
+  }
+
+  // don't attack
+  if(is_non_allied_unit_tile(ptile, pplayer)){
+    return FALSE;
+  }
+  
+  return TRUE;
+}
+
+enum tile_behavior ai_explorer_tb(const struct tile *ptile, enum known_type k,
+    struct pf_parameter * param)
+{
+  if(!ai_may_explore(ptile, param->owner, param->unit_flags)){
+    return TB_IGNORE;
+  }
+  return TB_NORMAL;
+}
+
+static bool ai_explorer_goto(struct unit *punit, struct tile *ptile)
+{
+  struct pf_parameter parameter;
+  struct ai_risk_cost risk_cost;
+
+  ai_fill_unit_param(&parameter, &risk_cost, punit, ptile);
+  parameter.get_TB = ai_explorer_tb;
+  
+  UNIT_LOG(LOG_DEBUG, punit, "ai_explorer_goto to %d,%d", ptile->x, ptile->y);
+  return ai_unit_goto_constrained(punit, ptile, &parameter);
+}
+
 /**************************************************************************
 Return a value indicating how desirable it is to explore the given tile.
 In general, we want to discover unknown terrain of the opposite kind to
@@ -170,6 +215,11 @@
     return 0;
   }
 
+  /* Enforce diplomatic realtions. */
+  if(! ai_may_explore(ptile, punit->owner, unit_type(punit)->flags)){
+      return 0;
+  }
+
   /* What value we assign to the number of land and water tiles
    * depends on if we're a land or water unit. */
   if (is_ground_unit(punit)) {
@@ -345,7 +395,7 @@
   if (best_tile != NULL) {
     /* TODO: read the path off the map we made.  Then we can make a path 
      * which goes beside the unknown, with a good EC callback... */
-    if (!ai_unit_goto(punit, best_tile)) {
+    if (!ai_explorer_goto(punit, best_tile)) {
       /* Died?  Strange... */
       return MR_DEATH;
     }
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to