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

On 1/25/07, Marko Lindqvist <[EMAIL PROTECTED]> wrote:
>
> On 1/24/07, Marko Lindqvist <[EMAIL PROTECTED]> wrote:
> >
> > On 1/24/07, Marko Lindqvist <[EMAIL PROTECTED]> wrote:
> > >
> > >  Seen as global observer: Barbarian boats almost never move. If boat
> > > happens to spawn next to land, it almost never unloads units to land.
> >
> >  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.

 Rewritten ai_military_attack_barbarian() for fixing several boat
handling bugs. Now barbarian boats move at least sometimes.
 Main remaining issue is that barbarians do not explore. If they don't
already know proper attack target (which is case quite often) they do
absolutely nothing.


 - ML

diff -Nurd -X.diff_ignore freeciv/ai/aiunit.c freeciv/ai/aiunit.c
--- freeciv/ai/aiunit.c	2007-01-25 12:08:09.000000000 +0200
+++ freeciv/ai/aiunit.c	2007-01-25 13:59:31.000000000 +0200
@@ -1628,20 +1628,40 @@
 					 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 (can_unit_exist_at_tile(punit, punit->tile)) {
       UNIT_LOG(LOG_DEBUG, punit, "Barbarian heading 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);
@@ -1650,6 +1670,8 @@
 	UNIT_LOG(LOG_ERROR, punit, "unable to find barbarian ferry");
       }
     }
+  } else {
+    UNIT_LOG(LOG_DEBUG, "Barbarian find no target city");
   }
 }
 
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to