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

> [wsimpson - Mer. AoĆ». 15 20:41:39 2007]:
> Thank you!  Is this trunk or 2.1?
It was for 2.1.

This is now the patch for trunk...

--- client/control.c.old	2007-08-16 00:01:23.000000000 +0200
+++ client/control.c	2007-08-16 00:02:21.000000000 +0200
@@ -925,7 +925,7 @@
     break;
   case HOVER_GOTO:
     /* Determine if the goto is valid, invalid or will attack. */
-    if (is_valid_goto_destination(ptile)) {
+    if (is_move_possible(ptile)) {
       if (can_units_attack_at(active_units, ptile)) {
         /* Goto results in military attack. */
 	mouse_cursor_type = CURSOR_ATTACK;
@@ -940,14 +940,14 @@
     }
     break;
   case HOVER_PATROL:
-    if (is_valid_goto_destination(ptile)) {
+    if (is_move_possible(ptile)) {
       mouse_cursor_type = CURSOR_PATROL;
     } else {
       mouse_cursor_type = CURSOR_INVALID;
     }
     break;
   case HOVER_CONNECT:
-    if (is_valid_goto_destination(ptile)) {
+    if (is_move_possible(ptile)) {
       mouse_cursor_type = CURSOR_GOTO;
     } else {
       mouse_cursor_type = CURSOR_INVALID;
@@ -2083,16 +2083,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!"));
@@ -2120,15 +2117,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!"));
   }
 
@@ -2141,12 +2135,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-16 00:00:54.000000000 +0200
+++ client/goto.c	2007-08-16 00:01:48.000000000 +0200
@@ -110,7 +110,6 @@
 **************************************************************************/
 static bool is_active = FALSE;
 static bool is_init = FALSE;
-static bool is_goto_valid = FALSE;
 static int connect_initial;
 
 /****************************************************************************
@@ -179,14 +178,6 @@
   }
 }
 
-/**********************************************************************
-  Determines if a goto to the destination tile is allowed.
-***********************************************************************/
-bool is_valid_goto_destination(struct tile *ptile) 
-{
-  return is_goto_valid;
-}
-
 /********************************************************************** 
   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.
@@ -202,8 +193,6 @@
           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);
@@ -847,6 +836,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 +1030,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 +1074,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 +1161,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-16 00:01:04.000000000 +0200
+++ client/goto.h	2007-08-16 00:01:51.000000000 +0200
@@ -23,10 +23,10 @@
 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);
-bool is_valid_goto_destination(struct tile *ptile);
 
 void draw_line(struct tile *dest_tile);
 bool is_drawn_line(struct tile *dest_tile, int dir);
@@ -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