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

This patch should work faster (when there are a lot of unit for
example). This one can be apply on 2.1 and trunk. Enjoy...
--- client/control.c.old	2007-08-15 20:28:54.000000000 +0200
+++ client/control.c	2007-08-16 10:49:38.000000000 +0200
@@ -2035,16 +2035,13 @@
 **************************************************************************/
 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) {
-    send_goto_route();
+  if (is_valid_goto_destination(ptile)) {
+    send_goto_route(ptile);
   } else {
     create_event(ptile, E_BAD_COMMAND,
 		 _("Didn't find a route to the destination!"));
@@ -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();
+    send_patrol_route(ptile);
   } else {
-    create_event(dest_tile, E_BAD_COMMAND,
+    create_event(ptile, E_BAD_COMMAND,
 		 _("Didn't find a route to the destination!"));
   }
 
@@ -2093,12 +2087,9 @@
 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)) {
-    send_connect_route(activity);
+  if (is_valid_goto_destination(ptile)) {
+    send_connect_route(ptile, activity);
   } else {
     create_event(ptile, E_BAD_COMMAND,
 		 _("Didn't find a route to the destination!"));
--- client/goto.c.old	2007-08-15 20:29:08.000000000 +0200
+++ client/goto.c	2007-08-16 11:13:15.000000000 +0200
@@ -190,8 +190,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 +203,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 +276,8 @@
   /* Refresh tiles so turn information is shown. */
   refresh_tile_mapcanvas(old_tile, FALSE, FALSE);
   refresh_tile_mapcanvas(ptile, FALSE, FALSE);
+
+  return TRUE;
 }
 
 /********************************************************************** 
@@ -885,8 +886,11 @@
 {
   assert(is_active);
 
+  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. */
@@ -1021,15 +1025,21 @@
   Send the current patrol route (i.e., the one generated via HOVER_STATE)
   to the server.
 **************************************************************************/
-void send_patrol_route(void)
+void send_patrol_route(struct tile *ptile)
 {
   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 != ptile) {
+      /* 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;
@@ -1059,15 +1069,21 @@
   Send the current connect route (i.e., the one generated via HOVER_STATE)
   to the server.
 **************************************************************************/
-void send_connect_route(enum unit_activity activity)
+void send_connect_route(struct tile *ptile, enum unit_activity activity)
 {
   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 != ptile) {
+      /* Cannot move there */
+      continue;
+    }
+
     memset(&p, 0, sizeof(p));
 
     for (i = 0; i < goto_map->num_parts; i++) {
@@ -1140,13 +1156,19 @@
   HOVER_STATE) to the server.  The route might involve more than one
   part if waypoints were used.  FIXME: danger paths are not supported.
 **************************************************************************/
-void send_goto_route(void)
+void send_goto_route(struct tile *ptile)
 {
   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 != ptile) {
+      /* Cannot move there */
+      continue;
+    }
+
     for (i = 0; i < goto_map->num_parts; i++) {
       path = pft_concat(path, goto_map->parts[i].path);
     }
--- client/goto.h.old	2007-08-15 20:29:48.000000000 +0200
+++ client/goto.h	2007-08-16 10:39:50.000000000 +0200
@@ -37,9 +37,9 @@
 void send_goto_path(struct unit *punit, struct pf_path *path,
 		    struct unit_order *last_order);
 bool send_goto_tile(struct unit *punit, struct tile *ptile);
-void send_patrol_route(void);
-void send_goto_route(void);
-void send_connect_route(enum unit_activity activity);
+void send_patrol_route(struct tile *ptile);
+void send_goto_route(struct tile *ptile);
+void send_connect_route(struct tile *ptile, enum unit_activity activity);
 
 struct pf_path *path_to_nearest_allied_city(struct unit *punit);
 
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to