Re: [Freeciv-Dev] (PR#12610) AI tries to move units with zero movement

"Per I. Mathisen" <per-0/[email protected]> Tue, 5 Apr 2005 14:06:03 -0700
Newsgroups gmane.games.freeciv.ai
Message-ID <[email protected]>
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12610 >

On Wed, 23 Mar 2005, Marko Lindqvist wrote:
> I don't know if this is a bug or not, but I noticed that AI player
> receives some "This unit has no moves left" messages.

Patch attached.

  - Per
movesleft.diff (text/plain, 2 KB)
Index: ai/aitools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aitools.c,v
retrieving revision 1.143
diff -u -r1.143 aitools.c
--- ai/aitools.c	5 Apr 2005 20:36:09 -0000	1.143
+++ ai/aitools.c	5 Apr 2005 21:04:51 -0000
@@ -170,8 +170,8 @@
       return FALSE;
     }
 
-    if (!same_pos(punit->tile, ptile)) {
-      /* Stopped (or maybe fought) */
+    if (!same_pos(punit->tile, ptile) || punit->moves_left <= 0) {
+      /* Stopped (or maybe fought) or ran out of moves */
       return TRUE;
     }
   }
@@ -256,7 +256,7 @@
 {
   CHECK_UNIT(punit);
 
-  if (same_pos(dest_tile, punit->tile)) {
+  if (same_pos(dest_tile, punit->tile) || punit->moves_left <= 0) {
     /* Nowhere to go */
     return TRUE;
   }
@@ -341,6 +341,9 @@
   enum unit_activity activity = punit->activity;
   bool alive;
 
+  if (punit->moves_left <= 0) {
+    return TRUE;
+  }
   punit->goto_tile = ptile;
   handle_unit_activity_request(punit, ACTIVITY_GOTO);
   alive = ai_unit_execute_path(punit, path);
Index: server/settlers.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/settlers.c,v
retrieving revision 1.223
diff -u -r1.223 settlers.c
--- server/settlers.c	21 Mar 2005 12:28:00 -0000	1.223
+++ server/settlers.c	5 Apr 2005 21:04:52 -0000
@@ -1151,7 +1151,8 @@
 
   /*** Recurse if we want to found a city ***/
 
-  if (punit->ai.ai_role == AIUNIT_BUILD_CITY) {
+  if (punit->ai.ai_role == AIUNIT_BUILD_CITY
+      && punit->moves_left > 0) {
     auto_settler_findwork(pplayer, punit);
   }
 }
@@ -1274,7 +1275,8 @@
     if ((punit->ai.control || pplayer->ai.control)
 	&& (unit_flag(punit, F_SETTLERS)
 	    || unit_flag(punit, F_CITIES))
-	&& !unit_has_orders(punit)) {
+	&& !unit_has_orders(punit)
+        && punit->moves_left > 0) {
       freelog(LOG_DEBUG, "%s's settler at (%d, %d) is ai controlled.",
 	      pplayer->name, TILE_XY(punit->tile)); 
       if (punit->activity == ACTIVITY_SENTRY) {