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

This is a first patch to fix the bug. With this, you cannot get a crash
with goto, patrol and connect. However, the cursor doesn't work well,
sometimes it's give a right move cursor, sometimes a wrong move cursor.
If you want I continue to fix this bug, I would like to know if the
wrong cursor should be used if one unit cannot do the move, or if all
units cannot do the move. Thank you.
--- client/control.c.old	2007-08-15 20:28:54.000000000 +0200
+++ client/control.c	2007-08-15 21:05:10.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_move_possible(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_move_possible(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_move_possible(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-15 21:04:25.000000000 +0200
@@ -847,6 +847,26 @@
   }
 }
 
+/********************************************************************** 
+  Return TRUE if one unit can do the move.
+***********************************************************************/
+bool is_move_possible(struct tile *ptile)
+{
+  if (!is_active) {
+    return FALSE;
+  }
+
+  goto_map_list_iterate(goto_maps, goto_map) {
+    struct part *p = &goto_map->parts[goto_map->num_parts - 1];
+
+    if (p->end_tile == ptile) {
+      return TRUE;
+    }
+  } goto_map_list_iterate_end;
+
+  return FALSE;
+}
+
 /**************************************************************************
   Return the path length (in turns).
 ***************************************************************************/
@@ -1021,15 +1041,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 +1085,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 +1172,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-15 21:02:02.000000000 +0200
@@ -23,6 +23,7 @@
 void exit_goto_state(void);
 bool goto_is_active(void);
 struct tile *get_line_dest(void);
+bool is_move_possible(struct tile *ptile);
 void goto_get_turns(int *min, int *max);
 void goto_add_waypoint(void);
 bool goto_pop_waypoint(void);
@@ -37,9 +38,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