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

Maybe this patch will satisfy you...

The variable of goto.c are now:
* is_active (no change)
* is_goto_valid (checked if the last update, so if the last unit could
do the move -> check if one unit can do the move)
* goto_tile (which is now the last tile to have been checked)

All updates of the goto code pass by draw_line():
draw_line(struct tile *dest_tile)
{
  assert(is_active);

  goto_tile = dest_tile;
  is_goto_valid = FALSE;
  goto_map_iterate(goto_maps, goto_map, punit) {
    if (update_last_part(goto_map, dest_tile)) {
      is_goto_valid = TRUE;
    }
  } goto_map_iterate_end;

  /* Update goto data in info label. */
  update_unit_info_label(get_units_in_focus());
}

--- client/control.c.old	2007-08-15 20:28:54.000000000 +0200
+++ client/control.c	2007-08-17 03:27:53.000000000 +0200
@@ -2035,15 +2035,12 @@
 **************************************************************************/
 void do_unit_goto(struct tile *ptile)
 {
-  struct tile *dest_tile;
-
   if (hover_state != HOVER_GOTO && hover_state != HOVER_NUKE) {
     return;
   }
 
   draw_line(ptile);
-  dest_tile = get_line_dest();
-  if (ptile == dest_tile) {
+  if (is_valid_goto_destination(ptile)) {
     send_goto_route();
   } else {
     create_event(ptile, E_BAD_COMMAND,
@@ -2072,15 +2069,12 @@
 **************************************************************************/
 void do_unit_patrol_to(struct tile *ptile)
 {
-  struct tile *dest_tile;
-
   draw_line(ptile);
-  dest_tile = get_line_dest();
-  if (ptile == dest_tile
+  if (is_valid_goto_destination(ptile)
       && !is_non_allied_unit_tile(ptile, game.player_ptr)) {
     send_patrol_route();
   } else {
-    create_event(dest_tile, E_BAD_COMMAND,
+    create_event(ptile, E_BAD_COMMAND,
 		 _("Didn't find a route to the destination!"));
   }
 
@@ -2093,11 +2087,8 @@
 void do_unit_connect(struct tile *ptile,
 		     enum unit_activity activity)
 {
-  struct tile *dest_tile;
-
   draw_line(ptile);
-  dest_tile = get_line_dest();
-  if (same_pos(dest_tile, ptile)) {
+  if (is_valid_goto_destination(ptile)) {
     send_connect_route(activity);
   } else {
     create_event(ptile, E_BAD_COMMAND,
--- client/goto.c.old	2007-08-15 20:29:08.000000000 +0200
+++ client/goto.c	2007-08-17 21:49:46.000000000 +0200
@@ -112,6 +112,7 @@
 static bool is_init = FALSE;
 static bool is_goto_valid = FALSE;
 static int connect_initial;
+static struct tile *goto_tile = NULL;
 
 /****************************************************************************
   Create a new goto map.
@@ -180,7 +181,7 @@
 }
 
 /**********************************************************************
-  Determines if a goto to the destination tile is allowed.
+  Determines if the goto a the destination tile is allowed.
 ***********************************************************************/
 bool is_valid_goto_destination(struct tile *ptile) 
 {
@@ -190,8 +191,9 @@
 /********************************************************************** 
   Change the destination of the last part to the given position if a
   path can be found. If not the destination is set to the start.
+  Return TRUE if the new path is found.
 ***********************************************************************/
-static void update_last_part(struct goto_map *goto_map, struct tile *ptile)
+static bool update_last_part(struct goto_map *goto_map, struct tile *ptile)
 {
   struct part *p = &goto_map->parts[goto_map->num_parts - 1];
   struct pf_path *new_path;
@@ -202,12 +204,10 @@
           TILE_XY(ptile), TILE_XY(p->start_tile), TILE_XY(p->end_tile));
   new_path = pf_get_path(p->map, ptile);
 
-  is_goto_valid = (new_path != NULL);
-
   if (!new_path) {
     freelog(PATH_LOG_LEVEL, "  no path found");
     reset_last_part(goto_map);
-    return;
+    return FALSE;
   }
 
   freelog(PATH_LOG_LEVEL, "  path found:");
@@ -277,6 +277,8 @@
   /* Refresh tiles so turn information is shown. */
   refresh_tile_mapcanvas(old_tile, FALSE, FALSE);
   refresh_tile_mapcanvas(ptile, FALSE, FALSE);
+
+  return TRUE;
 }
 
 /********************************************************************** 
@@ -802,6 +804,7 @@
     goto_map_list_append(goto_maps, goto_map);
   } unit_list_iterate_end;
   is_active = TRUE;
+  is_goto_valid = TRUE;
 }
 
 /********************************************************************** 
@@ -821,6 +824,8 @@
   } goto_map_list_iterate_end;
   goto_map_list_unlink_all(goto_maps);
 
+  is_goto_valid = FALSE;
+  goto_tile = NULL;
   is_active = FALSE;
 }
 
@@ -837,14 +842,7 @@
 ***********************************************************************/
 struct tile *get_line_dest(void)
 {
-  if (is_active) {
-    struct goto_map *goto_map = goto_map_list_get(goto_maps, 0);
-    struct part *p = &goto_map->parts[goto_map->num_parts - 1];
-
-    return p->end_tile;
-  } else {
-    return NULL;
-  }
+  return goto_tile;
 }
 
 /**************************************************************************
@@ -859,9 +857,26 @@
     *max = -1;
   }
   if (is_active) {
+    if (!is_goto_valid) {
+      /* Any unit can do the move, useless to check this longer */
+      if (min) {
+        *min = 0;
+      }
+      if (max) {
+        *max = 0;
+      }
+      return;
+    }
+
     goto_map_iterate(goto_maps, goto_map, punit) {
+      struct part *last_part = &goto_map->parts[goto_map->num_parts - 1];
       int time = 0, i;
 
+      if (last_part->end_tile != goto_tile) {
+        /* Cannot move there */
+        continue;
+      }
+
       for (i = 0; i < goto_map->num_parts; i++) {
 	time += goto_map->parts[i].time;
       }
@@ -885,8 +900,12 @@
 {
   assert(is_active);
 
+  goto_tile = dest_tile;
+  is_goto_valid = FALSE;
   goto_map_iterate(goto_maps, goto_map, punit) {
-    update_last_part(goto_map, dest_tile);
+    if (update_last_part(goto_map, dest_tile)) {
+      is_goto_valid = TRUE;
+    }
   } goto_map_iterate_end;
 
   /* Update goto data in info label. */
@@ -1026,10 +1045,16 @@
   assert(is_active);
   goto_map_iterate(goto_maps, goto_map, punit) {
     int i;
+    struct part *last_part = &goto_map->parts[goto_map->num_parts - 1];
     struct pf_path *path = NULL, *return_path;
     struct pf_parameter parameter = goto_map->template;
     struct pf_map *map;
 
+    if (last_part->end_tile != goto_tile) {
+      /* Cannot move there */
+      continue;
+    }
+
     parameter.start_tile = goto_map->parts[goto_map->num_parts - 1].end_tile;
     parameter.moves_left_initially
       = goto_map->parts[goto_map->num_parts - 1].end_moves_left;
@@ -1063,11 +1088,17 @@
 {
   assert(is_active);
   goto_map_iterate(goto_maps, goto_map, punit) {
+    struct part *last_part = &goto_map->parts[goto_map->num_parts - 1];
     struct pf_path *path = NULL;
     int i;
     struct packet_unit_orders p;
     struct tile *old_tile;
 
+    if (last_part->end_tile != goto_tile) {
+      /* Cannot move there */
+      continue;
+    }
+
     memset(&p, 0, sizeof(p));
 
     for (i = 0; i < goto_map->num_parts; i++) {
@@ -1144,9 +1175,15 @@
 {
   assert(is_active);
   goto_map_iterate(goto_maps, goto_map, punit) {
+    struct part *last_part = &goto_map->parts[goto_map->num_parts - 1];
     struct pf_path *path = NULL;
     int i;
 
+    if (last_part->end_tile != goto_tile) {
+      /* Cannot move there */
+      continue;
+    }
+
     for (i = 0; i < goto_map->num_parts; i++) {
       path = pft_concat(path, goto_map->parts[i].path);
     }
--- client/mapctrl_common.c.old	2007-08-17 03:12:28.000000000 +0200
+++ client/mapctrl_common.c	2007-08-17 03:27:59.000000000 +0200
@@ -659,7 +659,7 @@
     }
 
     old_tile = get_line_dest();
-    if (!same_pos(old_tile, ptile)) {
+    if (!old_tile || !same_pos(old_tile, ptile)) {
       draw_line(ptile);
     }
   }
@@ -739,4 +739,3 @@
   /* Then sort it. */
   qsort(unit_list, i, sizeof(*unit_list), unit_list_compare);
 }
-
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to