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

On 1/26/07, Marko Lindqvist <[EMAIL PROTECTED]> wrote:
> On 1/25/07, Marko Lindqvist <[EMAIL PROTECTED]> wrote:
> >
> > On 1/25/07, Marko Lindqvist <[EMAIL PROTECTED]> wrote:
> > >
> > > On 1/25/07, Marko Lindqvist <[EMAIL PROTECTED]> wrote:
> > > > On 1/24/07, Marko Lindqvist <[EMAIL PROTECTED]> wrote:
> > > > >
> > > > >  Barbarian leader is in charge of the boat. He wants to go where other
> > > > > barbarians protect him. All the other barbarians are sitting in the
> > > > > same boat - in the same tile - he currently is. So the leader is very
> > > > > happy not to move the boat.
> > > >
> > > >  Fix to that particular bug attached. This alone does not fix the
> > > > problem, though. Barbarian boat handling is broken in a number of
> > > > ways.
> > >
> > >  Forget that patch. That approach is not working. Patch to
> > > ai_military_attack_barbarian() is still valid.
> >
> >  Better barbarian leader patch. Also new version of
> > ai_military_attack_barbarian() patch, where one compile error is
> > fixed.
>
>  One more change to ai_military_attack_barbarian() patch. Changed one
> error level log in to debug level, since it is not error at all.

 S2_1 version of ai_military_attack_barbarian() patch. Same leader
patch applies to both trunk and S2_1.


 - ML

diff -Nurd -X.diff_ignore freeciv/ai/aiunit.c freeciv/ai/aiunit.c
--- freeciv/ai/aiunit.c	2006-07-17 14:28:36.000000000 +0300
+++ freeciv/ai/aiunit.c	2007-01-26 17:13:04.000000000 +0200
@@ -1628,28 +1628,53 @@
 					 struct unit *punit)
 {
   struct city *pc;
+  bool any_continent = FALSE;
 
-  if ((pc = dist_nearest_city(pplayer, punit->tile, FALSE, TRUE))) {
+  if (punit->transported_by != -1) {
+    /* If we are in transport, we can go to any continent.
+     * Actually, we are not currently in a continent where to stay. */
+    any_continent = TRUE;
+  }
+
+  if ((pc = dist_nearest_city(pplayer, punit->tile, any_continent, TRUE))) {
     if (!is_ocean(tile_get_terrain(punit->tile))) {
       UNIT_LOG(LOG_DEBUG, punit, "Barbarian marching to conquer %s", pc->name);
       (void) ai_gothere(pplayer, punit, pc->tile);
     } else {
       struct unit *ferry = NULL;
 
-      unit_list_iterate(punit->tile->units, aunit) {
-	if (is_boat_free(aunit, punit, 2)) {
-	  ferry = aunit;
-	  break;
-	}
-      } unit_list_iterate_end;
+      if (punit->transported_by != -1) {
+        ferry = find_unit_by_id(punit->transported_by);
+
+        /* We already are in a boat so it needs no
+         * free capacity */
+        if (!is_boat_free(ferry, punit, 0)) {
+          /* We cannot control our ferry. */
+          ferry = NULL;
+        }
+      } else {
+        /* We are not in a boat yet. Search for one. */
+        unit_list_iterate(punit->tile->units, aunit) {
+          if (is_boat_free(aunit, punit, 1)) {
+            ferry = aunit;
+            punit->transported_by = ferry->id;
+            break;
+          }
+        } unit_list_iterate_end;
+      }
+
       if (ferry) {
 	UNIT_LOG(LOG_DEBUG, punit, "Barbarian sailing to conquer %s",
 		 pc->name);
 	(void)aiferry_goto_amphibious(ferry, punit, pc->tile);
       } else {
-	UNIT_LOG(LOG_ERROR, punit, "unable to find barbarian ferry");
+        /* This is not an error. Somebody else might be in charge
+         * of the ferry. */
+        UNIT_LOG(LOG_DEBUG, punit, "unable to find barbarian ferry");
       }
     }
+  } else {
+    UNIT_LOG(LOG_DEBUG, punit, "Barbarian find no target city");
   }
 }
 
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to