Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2005:
[Freeciv-Dev] (PR#13172) gotodlg goto handles caravans poorly
Home

[Freeciv-Dev] (PR#13172) gotodlg goto handles caravans poorly

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: bh@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#13172) gotodlg goto handles caravans poorly
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 27 May 2005 20:01:11 -0700
Reply-to: bugs@xxxxxxxxxxx

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

> [bhudson - Wed May 25 00:35:49 2005]:
> 
> Go to Moyale; select a caravan; send it to Addis Abeba.
> Notice how it asks whether you want to establish a trade route in Mek'ele.
> 
> If you instead use the 'g' key there is no such problem.

Here's a patch.

I did it the "easy" way.  Instead of fixing server goto I just changed
this to use client goto (orders).  A new function send_goto_tile (like
send_goto_path) is added that automatically finds the path to the tile
and sends it.  This is possible now that client goto works for air units.

Also this function allows all server goto to be replaced.  But that's
for another patch.

-jason

Index: client/goto.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/goto.c,v
retrieving revision 1.85
diff -u -r1.85 goto.c
--- client/goto.c       2 May 2005 15:42:51 -0000       1.85
+++ client/goto.c       28 May 2005 02:58:39 -0000
@@ -859,6 +859,35 @@
   send_path_orders(punit, path, FALSE, FALSE, final_order);
 }
 
+/****************************************************************************
+  Send orders for the unit to move it to the arbitrary tile.  Returns
+  FALSE if no path is found.
+****************************************************************************/
+bool send_goto_tile(struct unit *punit, struct tile *ptile)
+{
+  struct pf_parameter parameter;
+  struct pf_map *map;
+  struct pf_path *path = NULL;
+
+  fill_client_goto_parameter(punit, &parameter);
+  map = pf_create_map(&parameter);
+
+  pf_iterator(map, pos) {
+    if (pos.tile == ptile) {
+      path = pf_next_get_path(map);
+      break;
+    }
+  } pf_iterator_end;
+
+  pf_destroy_map(map);
+  if (path) {
+    send_goto_path(punit, path, NULL);
+    return TRUE;
+  } else {
+    return FALSE;
+  }
+}
+
 /**************************************************************************
   Send the current patrol route (i.e., the one generated via HOVER_STATE)
   to the server.
Index: client/goto.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/goto.h,v
retrieving revision 1.17
diff -u -r1.17 goto.h
--- client/goto.h       5 Feb 2005 07:41:53 -0000       1.17
+++ client/goto.h       28 May 2005 02:58:39 -0000
@@ -35,6 +35,7 @@
 void request_orders_cleared(struct unit *punit);
 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(struct unit *punit);
 void send_goto_route(struct unit *punit);
 void send_connect_route(struct unit *punit, enum unit_activity activity);
Index: client/gui-gtk-2.0/gotodlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/gotodlg.c,v
retrieving revision 1.15
diff -u -r1.15 gotodlg.c
--- client/gui-gtk-2.0/gotodlg.c        5 May 2005 18:32:47 -0000       1.15
+++ client/gui-gtk-2.0/gotodlg.c        28 May 2005 02:58:39 -0000
@@ -33,11 +33,13 @@
 #include "clinet.h"
 #include "civclient.h"
 #include "control.h"
+#include "goto.h"
+#include "options.h"
+
 #include "dialogs.h"
 #include "gui_main.h"
 #include "gui_stuff.h"
 #include "mapview.h"
-#include "options.h"
 
 #include "gotodlg.h"
 
@@ -97,7 +99,7 @@
         struct unit *punit = get_unit_in_focus();
 
         if (punit) {
-          send_goto_unit(punit, pdestcity->tile);
+          send_goto_tile(punit, pdestcity->tile);
         }
       }
     }
Index: client/gui-mui/gotodlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/gotodlg.c,v
retrieving revision 1.15
diff -u -r1.15 gotodlg.c
--- client/gui-mui/gotodlg.c    5 May 2005 18:32:48 -0000       1.15
+++ client/gui-mui/gotodlg.c    28 May 2005 02:58:39 -0000
@@ -100,7 +100,7 @@
     struct unit *punit = get_unit_in_focus();
     if (punit)
     {
-      send_goto_unit(punit, pcity->tile);
+      send_goto_tile(punit, pcity->tile);
     }
   }
   set(goto_wnd, MUIA_Window_Open, FALSE);
Index: client/gui-mui/mapclass.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/mapclass.c,v
retrieving revision 1.112
diff -u -r1.112 mapclass.c
--- client/gui-mui/mapclass.c   2 May 2005 15:42:52 -0000       1.112
+++ client/gui-mui/mapclass.c   28 May 2005 02:58:39 -0000
@@ -1806,7 +1806,7 @@
       struct unit *punit = UNPACK_UNIT(udata);
       if (punit)
       {
-       send_goto_unit(punit, data->click.x, data->click.y);
+       send_goto_tile(punit, data->click.x, data->click.y);
       }
     }
     break;
Index: client/gui-sdl/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/dialogs.c,v
retrieving revision 1.62
diff -u -r1.62 dialogs.c
--- client/gui-sdl/dialogs.c    5 May 2005 18:32:48 -0000       1.62
+++ client/gui-sdl/dialogs.c    28 May 2005 02:58:40 -0000
@@ -1197,7 +1197,7 @@
   popdown_advanced_terrain_dialog();
   
   /* may not work */
-  send_goto_unit(get_unit_in_focus(), x, y);
+  send_goto_tile(get_unit_in_focus(), x, y);
   return -1;
 }
 
Index: client/gui-sdl/gotodlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/gotodlg.c,v
retrieving revision 1.9
diff -u -r1.9 gotodlg.c
--- client/gui-sdl/gotodlg.c    5 May 2005 18:32:48 -0000       1.9
+++ client/gui-sdl/gotodlg.c    28 May 2005 02:58:40 -0000
@@ -80,7 +80,7 @@
     struct unit *pUnit = get_unit_in_focus();
     if (pUnit) {
       if(GOTO) {
-        send_goto_unit(pUnit, pDestcity->x, pDestcity->y);
+        send_goto_tile(pUnit, pDestcity->x, pDestcity->y);
       } else {
        request_unit_airlift(pUnit, pDestcity);
       }
Index: client/gui-win32/gotodlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/gotodlg.c,v
retrieving revision 1.11
diff -u -r1.11 gotodlg.c
--- client/gui-win32/gotodlg.c  6 May 2005 23:23:20 -0000       1.11
+++ client/gui-win32/gotodlg.c  28 May 2005 02:58:40 -0000
@@ -99,7 +99,7 @@
            if (pdestcity) {
              struct unit *punit=get_unit_in_focus();
              if (punit) {
-               send_goto_unit(punit, pdestcity->tile);
+               send_goto_tile(punit, pdestcity->tile);
                DestroyWindow(dlg);
              }
            }
Index: client/gui-xaw/gotodlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/gotodlg.c,v
retrieving revision 1.26
diff -u -r1.26 gotodlg.c
--- client/gui-xaw/gotodlg.c    7 May 2005 09:50:46 -0000       1.26
+++ client/gui-xaw/gotodlg.c    28 May 2005 02:58:40 -0000
@@ -306,7 +306,7 @@
   if (pdestcity) {
     struct unit *punit = get_unit_in_focus();
     if (punit) {
-      send_goto_unit(punit, pdestcity->tile);
+      send_goto_tile(punit, pdestcity->tile);
     }
   }
   popdown_goto_dialog();

[Prev in Thread] Current Thread [Next in Thread]