Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2004:
[Freeciv-Dev] Re: (PR#7131) client orders to replace client goto
Home

[Freeciv-Dev] Re: (PR#7131) client orders to replace client goto

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jdorje@xxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#7131) client orders to replace client goto
From: "Jason Short" <jshort@xxxxxxxxxxxxxx>
Date: Sun, 4 Jan 2004 23:19:30 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=7131 >

Here's a first implementation of client orders.

ACTIVITY_GOTO is dropped for use with client goto (it is still used for 
server goto, but server goto should become deprecated when client-side 
air goto is implemented).  Instead a unit on client orders may have any 
activity (it will be ACTIVITY_IDLE for standard goto) and has 
punit->has_orders set.  But a unit on a connect orders may have, for 
instance, ACTIVITY_ROAD instead.

There are problems with unit focusing.  I can't entirely figure out the 
logic of handle_unit_packet_common.

Please comment on the design.

jason

? orders-2.diff
? orders-4.diff
? orders-5.diff
? orders.diff
Index: client/control.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.c,v
retrieving revision 1.122
diff -u -r1.122 control.c
--- client/control.c    2003/12/16 15:07:52     1.122
+++ client/control.c    2004/01/05 07:15:13
@@ -129,6 +129,18 @@
     punit->focus_status=FOCUS_AVAIL;
     refresh_tile_mapcanvas(punit->x, punit->y, FALSE);
 
+    if (punit->has_orders) {
+      struct packet_unit_orders p;
+
+      /* Clear the orders by sending an empty orders path. */
+      freelog(LOG_NORMAL, "Clearing orders for unit %d.", punit->id);
+      p.unit_id = punit->id;
+      p.repeat = p.vigilant = FALSE;
+      p.length = 0;
+      p.dest_x = punit->x;
+      p.dest_y = punit->y;
+      send_packet_unit_orders(&aconnection, &p);
+    }
     if (punit->activity != ACTIVITY_IDLE || punit->ai.control)  {
       punit->activity = ACTIVITY_IDLE;
       punit->ai.control = FALSE;
@@ -180,6 +192,7 @@
 {
   if (!punit_focus
       || (punit_focus->activity != ACTIVITY_IDLE
+         && !unit_has_orders(punit_focus)
          && punit_focus->activity != ACTIVITY_GOTO)
       || punit_focus->done_moving
       || punit_focus->moves_left == 0 
@@ -1194,6 +1207,7 @@
   
   if (game.player_idx == punit->owner
       && auto_center_on_unit
+      && !unit_has_orders(punit)
       && punit->activity != ACTIVITY_GOTO
       && punit->activity != ACTIVITY_SENTRY
       && !tile_visible_and_not_on_border_mapcanvas(target_unit->x,
Index: client/goto.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/goto.c,v
retrieving revision 1.64
diff -u -r1.64 goto.c
--- client/goto.c       2004/01/04 00:40:03     1.64
+++ client/goto.c       2004/01/05 07:15:14
@@ -467,27 +467,51 @@
 /**************************************************************************
   Send a path as a goto or patrol route to the server.
 **************************************************************************/
-static void send_path_route(struct unit *punit, struct pf_path *path,
-                           enum unit_activity activity)
+static void send_path_orders(struct unit *punit, struct pf_path *path,
+                            bool repeat, bool vigilant)
 {
-  struct packet_unit_route p;
-  int i;
+  struct packet_unit_orders p;
+  int i, old_x, old_y;
 
   p.unit_id = punit->id;
-  p.activity = activity;
+  p.repeat = repeat;
+  p.vigilant = vigilant;
+
+  freelog(PACKET_LOG_LEVEL, "Orders for unit %d:", punit->id);
 
-  /* we skip the start position */
+  /* We skip the start position. */
   p.length = path->length - 1;
   assert(p.length < MAX_LEN_ROUTE);
+  old_x = path->positions[0].x;
+  old_y = path->positions[0].y;
+
+  freelog(PACKET_LOG_LEVEL, "  Repeat: %d.  Vigilant: %d.  Length: %d",
+         p.repeat, p.vigilant, p.length);
 
+  /* If the path has n positions it takes n-1 steps. */
   for (i = 0; i < path->length - 1; i++) {
-    p.x[i] = path->positions[i + 1].x;
-    p.y[i] = path->positions[i + 1].y;
-    freelog(PACKET_LOG_LEVEL, "  packet[%d] = (%d,%d)",
-           i, p.x[i], p.y[i]);
+    int new_x = path->positions[i + 1].x;
+    int new_y = path->positions[i + 1].y;
+
+    if (same_pos(new_x, new_y, old_x, old_y)) {
+      p.orders[i] = ORDERS_WAIT;
+      p.dir[i] = -1;
+      freelog(PACKET_LOG_LEVEL, "  packet[%d] = wait: %d,%d",
+             i, old_x, old_y);
+    } else {
+      p.orders[i] = ORDERS_MOVE;
+      p.dir[i] = get_direction_for_step(old_x, old_y, new_x, new_y);
+      freelog(PACKET_LOG_LEVEL, "  packet[%d] = move %s: %d,%d => %d,%d",
+             i, dir_get_name(p.dir[i]), old_x, old_y, new_x, new_y);
+    }
+    old_x = new_x;
+    old_y = new_y;
   }
+
+  p.dest_x = old_x;
+  p.dest_y = old_y;
 
-  send_packet_unit_route(&aconnection, &p);
+  send_packet_unit_orders(&aconnection, &p);
 }
 
 /**************************************************************************
@@ -495,7 +519,7 @@
 **************************************************************************/
 void send_goto_path(struct unit *punit, struct pf_path *path)
 {
-  send_path_route(punit, path, ACTIVITY_GOTO);
+  send_path_orders(punit, path, FALSE, FALSE);
 }
 
 /**************************************************************************
@@ -531,7 +555,7 @@
   pf_destroy_map(map);
   pf_destroy_path(return_path);
 
-  send_path_route(punit, path, ACTIVITY_PATROL);
+  send_path_orders(punit, path, TRUE, TRUE);
 
   pf_destroy_path(path);
 }
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.341
diff -u -r1.341 packhand.c
--- client/packhand.c   2003/12/08 07:48:54     1.341
+++ client/packhand.c   2004/01/05 07:15:14
@@ -116,6 +116,9 @@
   } else {
     punit->transported_by = 0;
   }
+  punit->has_orders = packet->has_orders;
+  punit->orders.repeat = packet->repeat;
+  punit->orders.vigilant = packet->vigilant;
   return punit;
 }
 
@@ -138,6 +141,7 @@
   punit->activity = packet->activity;
   punit->occupy = (packet->occupied ? 1 : 0);
   punit->transported_by = 0;
+  freelog(LOG_NORMAL, "Unpackage_short_unit: %d", punit->id);
   
   return punit;
 }
@@ -936,14 +940,18 @@
     }
 
     if (punit->activity != packet_unit->activity
-        || punit->activity_target != packet_unit->activity_target) {
+        || punit->activity_target != packet_unit->activity_target
+       || punit->has_orders != packet_unit->has_orders
+       || punit->orders.repeat != packet_unit->orders.repeat
+       || punit->orders.vigilant != packet_unit->orders.vigilant) {
       /*** Change in activity or activity's target. ***/
 
       /* May change focus if focus unit gets a new activity.
        * But if new activity is Idle, it means user specifically selected
        * the unit */
       if (punit == get_unit_in_focus()
-         && packet_unit->activity != ACTIVITY_IDLE) {
+         && (packet_unit->activity != ACTIVITY_IDLE
+             || punit->has_orders)) {
         check_focus = TRUE;
       }
 
@@ -972,6 +980,8 @@
 
       punit->activity = packet_unit->activity;
       punit->activity_target = packet_unit->activity_target;
+      punit->has_orders = packet_unit->has_orders;
+      punit->orders = packet_unit->orders;
 
       if (punit->owner == game.player_idx) {
         refresh_unit_city_dialogs(punit);
@@ -1064,9 +1074,7 @@
         if((unit_flag(punit, F_TRADE_ROUTE) || unit_flag(punit, F_HELP_WONDER))
           && (!game.player_ptr->ai.control || ai_popup_windows)
           && punit->owner==game.player_idx
-          && (punit->activity!=ACTIVITY_GOTO
-              || same_pos(goto_dest_x(punit), goto_dest_y(punit),
-                          pcity->x, pcity->y))
+          && !unit_has_orders(punit)
           && (unit_can_help_build_wonder_here(punit)
               || unit_can_est_traderoute_here(punit))) {
          process_caravan_arrival(punit);
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.134
diff -u -r1.134 tilespec.c
--- client/tilespec.c   2003/11/29 19:39:40     1.134
+++ client/tilespec.c   2004/01/05 07:15:15
@@ -1503,8 +1503,12 @@
     ADD_SPRITE_SIMPLE(sprites.unit.connect);
   }
 
-  if (punit->activity == ACTIVITY_PATROL) {
-    ADD_SPRITE_SIMPLE(sprites.unit.patrol);
+  if (unit_has_orders(punit)) {
+    if (punit->orders.repeat) {
+      ADD_SPRITE_SIMPLE(sprites.unit.patrol);
+    } else {
+      ADD_SPRITE_SIMPLE(sprites.unit.go_to);
+    }
   }
 
   ihp = ((NUM_TILES_HP_BAR-1)*punit->hp) / unit_type(punit)->hp;
Index: client/gui-gtk/menu.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/menu.c,v
retrieving revision 1.80
diff -u -r1.80 menu.c
--- client/gui-gtk/menu.c       2003/11/06 11:54:34     1.80
+++ client/gui-gtk/menu.c       2004/01/05 07:15:15
@@ -1146,8 +1146,7 @@
                           can_unit_do_activity(punit, ACTIVITY_EXPLORE));
       menus_set_sensitive("<main>/_Orders/_Connect",
                           can_unit_do_connect(punit, ACTIVITY_IDLE));
-      menus_set_sensitive("<main>/_Orders/Patrol (_Q)",
-                          can_unit_do_activity(punit, ACTIVITY_PATROL));
+      menus_set_sensitive("<main>/_Orders/Patrol (_Q)", TRUE);
       menus_set_sensitive("<main>/_Orders/Return to nearest city",
                          !(is_air_unit(punit) || is_heli_unit(punit)));
       menus_set_sensitive("<main>/_Orders/_Disband Unit",
Index: client/gui-gtk-2.0/menu.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/menu.c,v
retrieving revision 1.25
diff -u -r1.25 menu.c
--- client/gui-gtk-2.0/menu.c   2003/11/09 04:06:50     1.25
+++ client/gui-gtk-2.0/menu.c   2004/01/05 07:15:15
@@ -1175,8 +1175,7 @@
                           can_unit_do_activity(punit, ACTIVITY_EXPLORE));
       menus_set_sensitive("<main>/_Orders/_Connect",
                           can_unit_do_connect(punit, ACTIVITY_IDLE));
-      menus_set_sensitive("<main>/_Orders/Patrol (_Q)",
-                          can_unit_do_activity(punit, ACTIVITY_PATROL));
+      menus_set_sensitive("<main>/_Orders/Patrol (_Q)", TRUE);
       menus_set_sensitive("<main>/_Orders/Return to nearest city",
                          !(is_air_unit(punit) || is_heli_unit(punit)));
       menus_set_sensitive("<main>/_Orders/Diplomat\\/Spy Actions",
Index: client/gui-mui/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/gui_main.c,v
retrieving revision 1.79
diff -u -r1.79 gui_main.c
--- client/gui-mui/gui_main.c   2003/11/19 17:30:51     1.79
+++ client/gui-mui/gui_main.c   2004/01/05 07:15:15
@@ -1259,7 +1259,7 @@
       menu_entry_sensitive(MENU_ORDER_AUTO_ATTACK, (can_unit_do_auto(punit) && 
!unit_flag(punit, F_SETTLERS)));
       menu_entry_sensitive(MENU_ORDER_AUTO_EXPLORE, 
can_unit_do_activity(punit, ACTIVITY_EXPLORE));
       menu_entry_sensitive(MENU_ORDER_CONNECT, can_unit_do_connect(punit, 
ACTIVITY_IDLE));
-      menu_entry_sensitive(MENU_ORDER_PATROL, can_unit_do_activity(punit, 
ACTIVITY_PATROL));
+      menu_entry_sensitive(MENU_ORDER_PATROL, TRUE);
       menu_entry_sensitive(MENU_ORDER_GOTO_CITY, any_cities);
       menu_entry_sensitive(MENU_ORDER_BUILD_WONDER, 
unit_can_help_build_wonder_here(punit));
       menu_entry_sensitive(MENU_ORDER_TRADEROUTE, 
unit_can_est_traderoute_here(punit));
Index: client/gui-sdl/menu.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/menu.c,v
retrieving revision 1.23
diff -u -r1.23 menu.c
--- client/gui-sdl/menu.c       2003/10/02 21:37:44     1.23
+++ client/gui-sdl/menu.c       2004/01/05 07:15:15
@@ -1198,11 +1198,7 @@
        local_hide(ID_UNIT_ORDER_CONNECT);
       }
 
-      if (can_unit_do_activity(pUnit, ACTIVITY_PATROL)) {
-       local_show(ID_UNIT_ORDER_PATROL);
-      } else {
-       local_hide(ID_UNIT_ORDER_PATROL);
-      }
+      local_show(ID_UNIT_ORDER_PATROL);
 
       if (is_diplomat_unit(pUnit) &&
          diplomat_can_do_action(pUnit, DIPLOMAT_ANY_ACTION, pUnit->x,
Index: client/gui-xaw/menu.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/menu.c,v
retrieving revision 1.58
diff -u -r1.58 menu.c
--- client/gui-xaw/menu.c       2003/12/01 19:32:04     1.58
+++ client/gui-xaw/menu.c       2004/01/05 07:15:16
@@ -369,8 +369,7 @@
                           can_unit_do_activity(punit, ACTIVITY_EXPLORE));
       menu_entry_sensitive(MENU_ORDER, MENU_ORDER_CONNECT, 
                           can_unit_do_connect(punit, ACTIVITY_IDLE));
-      menu_entry_sensitive(MENU_ORDER, MENU_ORDER_PATROL, 
-                          can_unit_do_activity(punit, ACTIVITY_PATROL));
+      menu_entry_sensitive(MENU_ORDER, MENU_ORDER_PATROL, TRUE);
       menu_entry_sensitive(MENU_ORDER, MENU_ORDER_GOTO_CITY,
                           any_cities);
       menu_entry_sensitive(MENU_ORDER, MENU_ORDER_BUILD_WONDER,
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.165
diff -u -r1.165 map.h
--- common/map.h        2003/11/28 17:37:21     1.165
+++ common/map.h        2004/01/05 07:15:16
@@ -36,17 +36,6 @@
   int x,y;
 };
 
-struct goto_route {
-  int first_index; /* first valid tile pos */
-  int last_index; /* point to the first non_legal pos. Note that the pos
-                  is always alloced in the pos array (for coding reasons) */
-  int length; /* length of pos array (use this as modulus when iterating)
-                Note that this is always at least 1 greater than the number
-                of valid positions, to make comparing first_index with
-                last_index during wrapped iteration easier. */
-  struct map_position *pos;
-};
-
 /* For client Area Selection */
 enum tile_hilite {
   HILITE_NONE = 0, HILITE_CITY
@@ -576,6 +565,11 @@
 };
 
 BV_DEFINE(dir_vector, 8);
+
+struct unit_order {
+  enum unit_orders order;
+  enum direction8 dir;
+};
 
 /* return the reverse of the direction */
 #define DIR_REVERSE(dir) (7 - (dir))
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.4
diff -u -r1.4 packets.def
--- common/packets.def  2003/12/06 20:37:59     1.4
+++ common/packets.def  2004/01/05 07:15:16
@@ -173,6 +173,8 @@
 type REPORT_TYPE       = uint8(enum report_type)
 type AUTH_TYPE         = uint8(enum authentication_type)
 type IMPR_RANGE                = uint8(enum impr_range)
+type DIRECTION         = uint8(enum direction8)
+type ORDERS            = uint8(enum unit_orders)
 
 # typedefs for IDs
 type PLAYER            = UINT8
@@ -593,6 +595,7 @@
   CITY homecity;
 
   BOOL veteran, ai, paradropped, connecting, carried, done_moving;
+  BOOL has_orders, repeat, vigilant;
 
   UNIT_TYPE type;
   UINT8 movesleft, hp, fuel, activity_count;
@@ -656,18 +659,20 @@
   UNIT unit_id;
 end
 
+# used for server-side goto (air units only)
 PACKET_UNIT_GOTO=58;cs
   UNIT unit_id;
   COORD x, y;
 end
 
-# used for ACTIVITY_GOTO and ACTIVITY_PATROL
-PACKET_UNIT_ROUTE=59;cs
+# used for client-side goto and patrol
+PACKET_UNIT_ORDERS=59;cs
   UNIT unit_id;
-  ACTIVITY activity;
   UINT16 length;
-  COORD x[MAX_LEN_ROUTE:length];
-  COORD y[MAX_LEN_ROUTE:length];
+  BOOL repeat, vigilant;
+  ORDERS orders[MAX_LEN_ROUTE:length];
+  DIRECTION dir[MAX_LEN_ROUTE:length];
+  COORD dest_x, dest_y;
 end
 
 PACKET_UNIT_AUTO=60;cs
Index: common/unit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unit.c,v
retrieving revision 1.190
diff -u -r1.190 unit.c
--- common/unit.c       2003/11/28 17:37:21     1.190
+++ common/unit.c       2004/01/05 07:15:16
@@ -563,7 +563,6 @@
   case ACTIVITY_TRANSFORM:     text = _("Transform"); break;
   case ACTIVITY_AIRBASE:       text = _("Airbase"); break;
   case ACTIVITY_FALLOUT:       text = _("Fallout"); break;
-  case ACTIVITY_PATROL:        text = _("Patrol"); break;
   default:                     text = _("Unknown"); break;
   }
 
@@ -655,7 +654,6 @@
   switch(activity) {
   case ACTIVITY_IDLE:
   case ACTIVITY_GOTO:
-  case ACTIVITY_PATROL:
     return TRUE;
 
   case ACTIVITY_POLLUTION:
@@ -915,7 +913,6 @@
    case ACTIVITY_SENTRY:
    case ACTIVITY_GOTO:
    case ACTIVITY_EXPLORE:
-   case ACTIVITY_PATROL:
      return get_activity_text (punit->activity);
    case ACTIVITY_PILLAGE:
      if(punit->activity_target == S_NO_SPECIAL) {
@@ -1287,7 +1284,7 @@
   /* 1) */
   if (activity != ACTIVITY_IDLE
       && activity != ACTIVITY_GOTO
-      && activity != ACTIVITY_PATROL && !connecting) {
+      && !connecting) {
     return MR_BAD_ACTIVITY;
   }
 
@@ -1481,12 +1478,12 @@
   punit->ai.charge = 0;
   punit->bribe_cost = -1; /* flag value */
   punit->transported_by = -1;
-  punit->pgr = NULL;
   punit->focus_status = FOCUS_AVAIL;
   punit->ord_map = 0;
   punit->ord_city = 0;
   set_unit_activity(punit, ACTIVITY_IDLE);
   punit->occupy = 0;
+  punit->has_orders = FALSE;
 
   return punit;
 }
@@ -1497,7 +1494,7 @@
 **************************************************************************/
 void destroy_unit_virtual(struct unit *punit)
 {
-  free_unit_goto_route(punit);
+  free_unit_orders(punit);
   free(punit);
 }
 
@@ -1505,11 +1502,11 @@
   Free and reset the unit's goto route (punit->pgr).  Only used by the
   server.
 **************************************************************************/
-void free_unit_goto_route(struct unit *punit)
+void free_unit_orders(struct unit *punit)
 {
-  if (punit->pgr) {
-    free(punit->pgr->pos);
-    free(punit->pgr);
-    punit->pgr = NULL;
+  if (punit->has_orders) {
+    free(punit->orders.list);
+    punit->orders.list = NULL;
   }
+  punit->has_orders = FALSE;
 }
Index: common/unit.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unit.h,v
retrieving revision 1.105
diff -u -r1.105 unit.h
--- common/unit.h       2003/12/01 18:14:22     1.105
+++ common/unit.h       2004/01/05 07:15:16
@@ -19,8 +19,8 @@
 
 struct player;
 struct city;
-struct goto_route;
 struct tile;
+struct unit_order;
 
 #define BARBARIAN_LIFE    5
 
@@ -29,10 +29,15 @@
   ACTIVITY_IRRIGATE, ACTIVITY_FORTIFIED, ACTIVITY_FORTRESS, ACTIVITY_SENTRY,
   ACTIVITY_RAILROAD, ACTIVITY_PILLAGE, ACTIVITY_GOTO, ACTIVITY_EXPLORE,
   ACTIVITY_TRANSFORM, ACTIVITY_UNKNOWN, ACTIVITY_AIRBASE, ACTIVITY_FORTIFYING,
-  ACTIVITY_FALLOUT, ACTIVITY_PATROL,
+  ACTIVITY_FALLOUT,
   ACTIVITY_LAST   /* leave this one last */
 };
 
+/* If this enum is changed add a manditory capability. */
+enum unit_orders {
+  ORDERS_MOVE, ORDERS_WAIT,
+};
+
 enum unit_focus_status {
   FOCUS_AVAIL, FOCUS_WAIT, FOCUS_DONE  
 };
@@ -144,7 +149,13 @@
 
   int transported_by;
   int occupy; /* number of units that occupy transporter */
-  struct goto_route *pgr;
+
+  bool has_orders;
+  struct {
+    int length, index; /* server only */
+    bool repeat, vigilant;
+    struct unit_order *list; /* server only */
+  } orders;
 };
 
 /* Wrappers for accessing the goto destination of a unit.  This goto_dest
@@ -161,6 +172,8 @@
 #define clear_goto_dest(punit) ((punit)->goto_dest.x = -1, \
                                 (punit)->goto_dest.y = -1)
 
+#define unit_has_orders(punit) ((punit)->has_orders)
+
 /* get 'struct unit_list' and related functions: */
 #define SPECLIST_TAG unit
 #define SPECLIST_TYPE struct unit
@@ -292,6 +305,6 @@
 struct unit *create_unit_virtual(struct player *pplayer, struct city *pcity,
                                  Unit_Type_id type, bool make_veteran);
 void destroy_unit_virtual(struct unit *punit);
-void free_unit_goto_route(struct unit *punit);
+void free_unit_orders(struct unit *punit);
 
 #endif  /* FC__UNIT_H */
Index: server/gotohand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/gotohand.c,v
retrieving revision 1.176
diff -u -r1.176 gotohand.c
--- server/gotohand.c   2003/10/21 17:20:47     1.176
+++ server/gotohand.c   2004/01/05 07:15:17
@@ -1279,10 +1279,7 @@
   enum goto_result status;
   int x, y;
 
-  if (punit->pgr) {
-    /* we have a precalculated goto route */
-    return goto_route_execute(punit);
-  }
+  assert(!unit_has_orders(punit));
 
   unit_id = punit->id;
   dest_x = waypoint_x = goto_dest_x(punit);
@@ -1412,9 +1409,7 @@
   /* normally we would just do this unconditionally, but if we had an
      airplane goto we might not be finished even if the loop exited */
   if (same_pos(punit->x, punit->y, dest_x, dest_y)) {
-    if (punit->activity != ACTIVITY_PATROL) {
-      punit->activity = ACTIVITY_IDLE;
-    }
+    punit->activity = ACTIVITY_IDLE;
     status = GR_ARRIVED;
   } else {
     /* we have a plane refueling at a waypoint */
Index: server/hand_gen.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/hand_gen.c,v
retrieving revision 1.1
diff -u -r1.1 hand_gen.c
--- server/hand_gen.c   2003/12/06 19:23:51     1.1
+++ server/hand_gen.c   2004/01/05 07:15:17
@@ -180,13 +180,8 @@
       ((struct packet_unit_goto *)packet)->y);
     return TRUE;
 
-  case PACKET_UNIT_ROUTE:
-    handle_unit_route(pplayer,
-      ((struct packet_unit_route *)packet)->unit_id,
-      ((struct packet_unit_route *)packet)->activity,
-      ((struct packet_unit_route *)packet)->length,
-      ((struct packet_unit_route *)packet)->x,
-      ((struct packet_unit_route *)packet)->y);
+  case PACKET_UNIT_ORDERS:
+    handle_unit_orders(pplayer, packet);
     return TRUE;
 
   case PACKET_UNIT_AUTO:
Index: server/hand_gen.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/hand_gen.h,v
retrieving revision 1.2
diff -u -r1.2 hand_gen.h
--- server/hand_gen.h   2003/12/06 19:23:51     1.2
+++ server/hand_gen.h   2004/01/05 07:15:17
@@ -49,7 +49,8 @@
 void handle_unit_establish_trade(struct player *pplayer, int unit_id);
 void handle_unit_help_build_wonder(struct player *pplayer, int unit_id);
 void handle_unit_goto(struct player *pplayer, int unit_id, int x, int y);
-void handle_unit_route(struct player *pplayer, int unit_id, enum unit_activity 
activity, int length, int *x, int *y);
+struct packet_unit_orders;
+void handle_unit_orders(struct player *pplayer, struct packet_unit_orders 
*packet);
 void handle_unit_auto(struct player *pplayer, int unit_id);
 void handle_unit_unload(struct player *pplayer, int unit_id);
 void handle_unit_upgrade(struct player *pplayer, int unit_id);
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.142
diff -u -r1.142 savegame.c
--- server/savegame.c   2003/12/06 20:37:59     1.142
+++ server/savegame.c   2004/01/05 07:15:18
@@ -1074,57 +1074,39 @@
        etc may use junk values).
     */
 
-    /* load the goto route */
+    /* load the unit orders */
     {
-      int len = secfile_lookup_int_default(file, 0, 
"player%d.u%d.goto_length", plrno, i);
+      int len = secfile_lookup_int_default(file, 0,
+                       "player%d.u%d.orders_length", plrno, i);
       if (len > 0) {
-       char *goto_buf, *goto_buf_ptr;
-       struct goto_route *pgr = fc_malloc(sizeof(struct goto_route));
-       pgr->pos = fc_malloc((len+1) * sizeof(struct map_position));
-       pgr->first_index = 0;
-       pgr->length = len+1;
-       pgr->last_index = len;
-       punit->pgr = pgr;
-
-       /* get x coords */
-       goto_buf = secfile_lookup_str(file, "player%d.u%d.goto_route_x", plrno, 
i);
-       goto_buf_ptr = goto_buf;
+       char *orders_buf, *dir_buf;
+
+       punit->orders.list = fc_malloc(len * sizeof(*(punit->orders.list)));
+       punit->orders.length = len;
+       punit->orders.index = secfile_lookup_int_default(file, 0,
+                       "player%d.u%d.orders_index", plrno, i);
+       punit->orders.repeat = secfile_lookup_bool_default(file, FALSE,
+                       "player%d.u%d.orders_repeat", plrno, i);
+       punit->orders.vigilant = secfile_lookup_bool_default(file, FALSE,
+                       "player%d.u%d.orders_vigilant", plrno, i);
+
+       orders_buf = secfile_lookup_str_default(file, "",
+                       "player%d.u%d.orders_list", plrno, i);
+       dir_buf = secfile_lookup_str_default(file, "",
+                       "player%d.u%d.orders_dirs", plrno, i);
        for (j = 0; j < len; j++) {
-         if (sscanf(goto_buf_ptr, "%d", &pgr->pos[j].x) == 0) {
-           die("not an int");
-         }
-         while (*goto_buf_ptr != ',') {
-           goto_buf_ptr++;
-           if (*goto_buf_ptr == '\0') {
-             die("byebye");
-           }
+         if (orders_buf[j] == '\0' || dir_buf == '\0') {
+           freelog(LOG_ERROR, _("Savegame error: invalid unit orders."));
+           free_unit_orders(punit);
+           break;
          }
-         goto_buf_ptr++;
+         punit->orders.list[j].order = orders_buf[j] - 'a';
+         punit->orders.list[j].dir = dir_buf[j] - 'a';
        }
-       /* get y coords */
-       goto_buf = secfile_lookup_str(file, "player%d.u%d.goto_route_y", plrno, 
i);
-       goto_buf_ptr = goto_buf;
-       for (j = 0; j < len; j++) {
-         if (sscanf(goto_buf_ptr, "%d", &pgr->pos[j].y) == 0) {
-           die("not an int");
-         }
-         while (*goto_buf_ptr != ',') {
-           goto_buf_ptr++;
-           if (*goto_buf_ptr == '\0') {
-             die("byebye");
-           }
-         }
-         goto_buf_ptr++;
-       }
+       punit->has_orders = TRUE;
       } else {
-       /* mark unused strings as read to avoid warnings */
-       (void) secfile_lookup_str_default(file, "",
-                                         "player%d.u%d.goto_route_x", plrno,
-                                         i);
-       (void) secfile_lookup_str_default(file, "",
-                                         "player%d.u%d.goto_route_y", plrno,
-                                         i);
-       punit->pgr = NULL;
+       punit->has_orders = FALSE;
+       punit->orders.list = NULL;
       }
     }
 
@@ -1520,42 +1502,30 @@
     secfile_insert_bool(file, punit->paradropped, "player%d.u%d.paradropped", 
plrno, i);
     secfile_insert_int(file, punit->transported_by,
                       "player%d.u%d.transported_by", plrno, i);
-    if (punit->pgr && punit->pgr->first_index != punit->pgr->last_index) {
-      struct goto_route *pgr = punit->pgr;
-      int index = pgr->first_index;
-      int len = 0;
-      while (pgr && index != pgr->last_index) {
-       len++;
-       index = (index + 1) % pgr->length;
+    if (punit->has_orders) {
+      int len = punit->orders.length, j;
+      char orders_buf[len + 1], dir_buf[len + 1];
+
+      secfile_insert_int(file, len, "player%d.u%d.orders_length", plrno, i);
+      secfile_insert_int(file, punit->orders.index,
+                        "player%d.u%d.orders_index", plrno, i);
+      secfile_insert_bool(file, punit->orders.repeat,
+                         "player%d.u%d.orders_repeat", plrno, i);
+      secfile_insert_bool(file, punit->orders.vigilant,
+                         "player%d.u%d.orders_vigilant", plrno, i);
+
+      for (j = 0; j < len; j++) {
+       orders_buf[j] = 'a' + punit->orders.list[j].order;
+       dir_buf[j] = 'a' + punit->orders.list[j].dir;
       }
-      assert(len > 0);
-      secfile_insert_int(file, len, "player%d.u%d.goto_length", plrno, i);
-      /* assumption about the chars per map position */
-      assert(MAP_MAX_HEIGHT < 1000 && MAP_MAX_WIDTH < 1000);
-      {
-       char *goto_buf = fc_malloc(4 * len + 1);
-       char *goto_buf_ptr = goto_buf;
-       index = pgr->first_index;
-       while (index != pgr->last_index) {
-         goto_buf_ptr += sprintf(goto_buf_ptr, "%d,", pgr->pos[index].x);
-         index = (index + 1) % pgr->length;
-       }
-       *goto_buf_ptr = '\0';
-       secfile_insert_str(file, goto_buf, "player%d.u%d.goto_route_x", plrno, 
i);
+      orders_buf[len] = dir_buf[len] = '\0';
 
-       goto_buf_ptr = goto_buf;
-       index = pgr->first_index;
-       while (index != pgr->last_index) {
-         goto_buf_ptr += sprintf(goto_buf_ptr, "%d,", pgr->pos[index].y);
-         index = (index + 1) % pgr->length;
-       }
-       *goto_buf_ptr = '\0';
-       secfile_insert_str(file, goto_buf, "player%d.u%d.goto_route_y", plrno, 
i);
-      }
+      secfile_insert_str(file, orders_buf,
+                        "player%d.u%d.orders_list", plrno, i);
+      secfile_insert_str(file, dir_buf,
+                        "player%d.u%d.dir_list", plrno, i);
     } else {
-      secfile_insert_int(file, 0, "player%d.u%d.goto_length", plrno, i);
-      secfile_insert_str(file, "", "player%d.u%d.goto_route_x", plrno, i);
-      secfile_insert_str(file, "", "player%d.u%d.goto_route_y", plrno, i);
+      secfile_insert_int(file, 0, "player%d.u%d.orders_length", plrno, i);
     }
   }
   unit_list_iterate_end;
Index: server/unithand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unithand.c,v
retrieving revision 1.280
diff -u -r1.280 unithand.c
--- server/unithand.c   2003/12/15 19:14:50     1.280
+++ server/unithand.c   2004/01/05 07:15:18
@@ -832,7 +832,7 @@
   }
 
   if (pwinner == punit && punit->activity != ACTIVITY_IDLE) {
-    /* Ensure we remove ACTIVITY_GOTO here */
+    /* Ensure we remove goto here */
     set_unit_activity(punit, ACTIVITY_IDLE);
   }
   send_unit_info(NULL, pwinner);
@@ -1386,7 +1386,7 @@
     enum tile_special_type old_target = punit->activity_target;
 
     set_unit_activity(punit, new_activity);
-    free_unit_goto_route(punit);
+    free_unit_orders(punit);
     send_unit_info(NULL, punit);
     handle_unit_activity_dependencies(punit, old_activity, old_target);
   }
@@ -1406,7 +1406,7 @@
     enum tile_special_type old_target = punit->activity_target;
 
     set_unit_activity_targeted(punit, new_activity, new_target);
-    free_unit_goto_route(punit);
+    free_unit_orders(punit);
     send_unit_info(NULL, punit);    
     handle_unit_activity_dependencies(punit, old_activity, old_target);
   }
@@ -1479,66 +1479,58 @@
 }
 
 /**************************************************************************
-Receives goto route packages.
+Receives route packages.
 **************************************************************************/
-static void handle_route(struct player *pplayer, struct unit *punit,
-                        int length, int *x, int *y)
+void handle_unit_orders(struct player *pplayer,
+                       struct packet_unit_orders *packet)
 {
-  struct goto_route *pgr = NULL;
+  struct unit *punit = player_find_unit_by_id(pplayer, packet->unit_id);
   int i;
-
-  free_unit_goto_route(punit);
 
-  /* 
-   * pgr->pos is implemented as a circular buffer of positions, and
-   * this circular buffer requires an extra "empty" spot.  Hence we
-   * increase the length by one. 
-   */
-  pgr = fc_malloc(sizeof(struct goto_route));
-  pgr->length = length + 1;
-  pgr->first_index = 0;
-  pgr->last_index = length;
-  pgr->pos = fc_malloc(pgr->length * sizeof(*pgr->pos));
-
-  for (i = 0; i < length; i++) {
-    pgr->pos[i].x = x[i];
-    pgr->pos[i].y = y[i];
+  if (!punit || packet->length < 0) {
+    return;
   }
 
-  punit->pgr = pgr;
+  if (punit->activity != ACTIVITY_IDLE) {
+    return;
+  }
 
-#ifdef DEBUG
-  freelog(LOG_DEBUG, "first:%d, last:%d, length:%d",
-         pgr->first_index, pgr->last_index, pgr->length);
-  for (i = pgr->first_index; i < pgr->last_index; i++) {
-    freelog(LOG_NORMAL, "  %d,%d", pgr->pos[i].x, pgr->pos[i].y);
+  if (packet->length == 0) {
+    /* The client can clear orders by sending an orders packet of length
+     * 0.  The current action will still continue to completion, however. */
+    free_unit_orders(punit);
+    send_unit_info(NULL, punit);
+    return;
   }
-#endif
 
-  if (punit->activity == ACTIVITY_GOTO) {
-    set_goto_dest(punit, pgr->pos[pgr->last_index-1].x,
-                 pgr->pos[pgr->last_index-1].y);
-    send_unit_info(pplayer, punit);
+  punit->orders.length = packet->length;
+  punit->orders.index = 0;
+  punit->orders.repeat = packet->repeat;
+  punit->orders.vigilant = packet->vigilant;
+  punit->orders.list
+    = fc_malloc(packet->length * sizeof(*(punit->orders.list)));
+  for (i = 0; i < packet->length; i++) {
+    punit->orders.list[i].order = packet->orders[i];
+    punit->orders.list[i].dir = packet->dir[i];
   }
 
-  assign_units_to_transporter(punit, TRUE);
-  (void) goto_route_execute(punit);
-}
+  if (!packet->repeat) {
+    set_goto_dest(punit, packet->dest_x, packet->dest_y);
+  }
 
-/**************************************************************************
-Receives route packages.
-**************************************************************************/
-void handle_unit_route(struct player *pplayer, int unit_id,
-                      enum unit_activity activity, int length, int *x,
-                      int *y)
-{
-  struct unit *punit = player_find_unit_by_id(pplayer, unit_id);
+  punit->has_orders = TRUE;
 
-  if (!punit || length < 1
-      || !(activity == ACTIVITY_GOTO || activity == ACTIVITY_PATROL)) {
-    return;
+#ifdef DEBUG
+  freelog(LOG_DEBUG, "Orders for unit %d: length:%d",
+         packet->unit_id, packet->length);
+  for (i = 0; i < packet->length; i++) {
+    freelog(LOG_NORMAL, "  %d,%s", packet->orders[i],
+           dir_get_name(packet->dir[i]);
   }
+#endif
+
+  assign_units_to_transporter(punit, TRUE);
+  (void) execute_orders(punit);
 
-  handle_unit_activity_request(punit, activity);
-  handle_route(pplayer, punit, length, x, y);
+  send_unit_info(NULL, punit);
 }
Index: server/unittools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unittools.c,v
retrieving revision 1.267
diff -u -r1.267 unittools.c
--- server/unittools.c  2003/12/04 18:32:45     1.267
+++ server/unittools.c  2004/01/05 07:15:19
@@ -652,8 +652,7 @@
   struct tile *ptile = map_get_tile(punit->x, punit->y);
 
   if (activity != ACTIVITY_IDLE && activity != ACTIVITY_FORTIFIED
-      && activity != ACTIVITY_GOTO && activity != ACTIVITY_EXPLORE
-      && activity != ACTIVITY_PATROL) {
+      && activity != ACTIVITY_GOTO && activity != ACTIVITY_EXPLORE) {
     /*  We don't need the activity_count for the above */
     if (punit->moves_left > 0) {
       /* 
@@ -876,7 +875,7 @@
     }
   }
 
-  if (activity==ACTIVITY_GOTO) {
+  if (activity == ACTIVITY_GOTO) {
     if (!punit->ai.control && (!is_military_unit(punit) ||
        punit->ai.passenger != 0 || !pplayer->ai.control)) {
 /* autosettlers otherwise waste time; idling them breaks assignment */
@@ -886,8 +885,8 @@
     return;
   }
 
-  if (punit->activity == ACTIVITY_PATROL) {
-    if (goto_route_execute(punit) == GR_DIED) {
+  if (unit_has_orders(punit)) {
+    if (execute_orders(punit) == GR_DIED) {
       return;
     }
   }
@@ -1875,6 +1874,13 @@
   packet->done_moving = punit->done_moving;
   packet->carried = carried;
   packet->occupy = get_transporter_occupancy(punit);
+  packet->has_orders = punit->has_orders;
+  if (punit->has_orders) {
+    packet->repeat = punit->orders.repeat;
+    packet->vigilant = punit->orders.vigilant;
+  } else {
+    packet->repeat = packet->vigilant = FALSE;
+  }
 }
 
 /**************************************************************************
@@ -1907,9 +1913,8 @@
   packet->type = punit->type;
   packet->hp = punit->hp;
   packet->occupied = (get_transporter_occupancy(punit) > 0);
-  if (punit->activity == ACTIVITY_GOTO
-      || punit->activity == ACTIVITY_EXPLORE
-      || punit->activity == ACTIVITY_PATROL) {
+  if (punit->activity == ACTIVITY_EXPLORE
+      || punit->activity == ACTIVITY_GOTO) {
     packet->activity = ACTIVITY_IDLE;
   } else {
     packet->activity = punit->activity;
@@ -2725,7 +2730,8 @@
   square_iterate(punit->x, punit->y, 3, x, y) {
     unit_list_iterate(map_get_tile(x, y)->units, ppatrol) {
       if (punit != ppatrol
-         && ppatrol->activity == ACTIVITY_PATROL) {
+         && unit_has_orders(ppatrol)
+         && ppatrol->orders.vigilant) {
        (void) maybe_cancel_patrol_due_to_enemy(ppatrol);
       }
     } unit_list_iterate_end;
@@ -2840,10 +2846,9 @@
 static void check_unit_activity(struct unit *punit)
 {
   if (punit->activity != ACTIVITY_IDLE
-      && punit->activity != ACTIVITY_GOTO
       && punit->activity != ACTIVITY_SENTRY
       && punit->activity != ACTIVITY_EXPLORE
-      && punit->activity != ACTIVITY_PATROL
+      && punit->activity != ACTIVITY_GOTO
       && !punit->connecting) {
     set_unit_activity(punit, ACTIVITY_IDLE);
   }
@@ -2886,7 +2891,8 @@
   }
 
   /* A transporter should not take units with it on an attack goto. */
-  if (punit->activity == ACTIVITY_GOTO
+  if ((unit_has_orders(punit)
+       || punit->activity == ACTIVITY_GOTO)
       && (is_non_allied_unit_tile(pdesttile, pplayer)
           || is_non_allied_city_tile(pdesttile, pplayer))
       && !is_ocean(psrctile->terrain)) {
@@ -2929,13 +2935,6 @@
       pcargo->x = dest_x;
       pcargo->y = dest_y;
 
-      if ((pcargo->activity == ACTIVITY_GOTO
-          || pcargo->activity == ACTIVITY_PATROL)
-         && !pcargo->ai.control) {
-       /* Cancel any _client_ gotos for these units. */
-       handle_unit_activity_request(pcargo, ACTIVITY_IDLE);
-      }
-
       unit_list_insert(&pdesttile->units, pcargo);
       check_unit_activity(pcargo);
       send_unit_info_to_onlookers(NULL, pcargo, src_x, src_y, FALSE);
@@ -3012,14 +3011,9 @@
     } unit_list_iterate_end;
     assert(punit->transported_by != -1);
 
-    /* set activity to sentry if boarding a ship unless the unit is just 
-     * passing through the ship on its way somewhere else.  If the unit is
-     * GOTOing and the ship isn't the final destination, then don't go
-     * to sleep. */
-    if (!(pplayer->ai.control)
-       && !(punit->activity == ACTIVITY_GOTO
-            && !same_pos(goto_dest_x(punit), goto_dest_y(punit),
-                         dest_x, dest_y))) {
+    /* Set activity to sentry if boarding a ship.  It's safe to do this even
+     * if the unit has orders. */
+    if (!pplayer->ai.control) {
       set_unit_activity(punit, ACTIVITY_SENTRY);
     }
 
@@ -3146,115 +3140,107 @@
   return cancel;
 }
 
-/**************************************************************************
-Moves a unit according to its pgr (goto or patrol order). If two consequetive
-positions in the route is not adjacent it is assumed to be a goto. The unit
-is put on idle if a move fails.
-If the activity is ACTIVITY_PATROL the map positions are put back in the
-route (at the end).  To avoid infinite loops on railroad we stop for this
+/****************************************************************************
+Executes a unit's orders stored in punit->orders.  The unit is put on idle
+if an action fails or if "patrol" is set an an enemy unit is encountered.
+
+If the orders are repeating the loop starts over at the beginning once it
+completes.  To avoid infinite loops on railroad we stop for this
 turn when the unit is back where it started, eben if it have moves left.
 
-If a patrolling unit came across an enemy we could make the patrolling unit
-autoattack or just stop and wait for the owner to attack. It is also
-debateable if units on goto should stop when they encountered an enemy
-unit. Currently the unit continues if it can, or if it is blocked it stops.
-**************************************************************************/
-enum goto_result goto_route_execute(struct unit *punit)
-{
-  struct goto_route *pgr = punit->pgr;
-  int index, x, y;
-  bool res, last_tile, moved;
-  int patrol_stop_index = pgr->last_index;
+A unit will attack under orders only on its final action.
+**************************************************************************/
+enum goto_result execute_orders(struct unit *punit)
+{
+  int dest_x, dest_y;
+  bool res, last_order;
   int unitid = punit->id;
   struct player *pplayer = unit_owner(punit);
+  int moves_made = 0;
 
-  assert(pgr != NULL);
-  while (TRUE) {
-    freelog(LOG_DEBUG, "running a round\n");
+  assert(unit_has_orders(punit));
 
-    index = pgr->first_index;
-    if (index == pgr->last_index) {
-      free_unit_goto_route(punit);
-      if (punit->activity == ACTIVITY_GOTO) 
-       /* the activity could already be SENTRY (if boarded a ship) 
-          -- leave it as it is then */
-       handle_unit_activity_request(punit, ACTIVITY_IDLE);
-      return GR_ARRIVED;
-    }
-    x = pgr->pos[index].x; y = pgr->pos[index].y;
-    freelog(LOG_DEBUG, "%i,%i -> %i,%i\n", punit->x, punit->y, x, y);
+  freelog(LOG_DEBUG, "Executing orders for unit %d", punit->id);
 
+  while (TRUE) {
     if (punit->moves_left == 0) {
+      /* FIXME: this check won't work when actions take 0 MP. */
+      freelog(LOG_DEBUG, "stopping because of no more move points");
       return GR_OUT_OF_MOVEPOINTS;
     }
 
-    if (punit->activity == ACTIVITY_PATROL
-       && maybe_cancel_patrol_due_to_enemy(punit)) {
-      return GR_FAILED;
+    if (punit->done_moving) {
+      freelog(LOG_DEBUG, "stopping because we're done this turn");
+      return GR_WAITING;
     }
-
-    last_tile = (((index + 1) % pgr->length) == (pgr->last_index));
 
-    if (punit->activity == ACTIVITY_GOTO && !last_tile 
-        && maybe_cancel_goto_due_to_enemy(punit, x, y)) {
+    if (punit->orders.vigilant && maybe_cancel_patrol_due_to_enemy(punit)) {
+      /* "Patrol" orders are stopped if an enemy is near. */
+      freelog(LOG_DEBUG, "stopping because of nearby enemy");
       return GR_FAILED;
     }
 
-    /* Move unit */
-    moved = !same_pos(punit->x, punit->y, x, y);
-    if (moved) {
-      res = handle_unit_move_request(punit, x, y, FALSE, !last_tile);
-    } else {
-      res = TRUE;
+    if (moves_made == punit->orders.length) {
+      /* For repeating orders, don't repeat more than once per turn. */
+      freelog(LOG_DEBUG, "stopping because we ran a round");
+      return GR_ARRIVED;
     }
 
-    if (!player_find_unit_by_id(pplayer, unitid)) {
-      return GR_DIED;
-    }
+    last_order = (!punit->orders.repeat
+                 && punit->orders.index + 1 == punit->orders.length);
 
-    if (same_pos(punit->x, punit->y, x, y)) {
-      /* We succeeded in moving one step forward */
-      pgr->first_index = (pgr->first_index + 1) % pgr->length;
-      if (punit->activity == ACTIVITY_PATROL) {
-       /* When patroling we go in little circles; 
-        * done by reinserting points */
-       pgr->pos[pgr->last_index].x = x;
-       pgr->pos[pgr->last_index].y = y;
-       pgr->last_index = (pgr->last_index + 1) % pgr->length;
-
-       if (patrol_stop_index == pgr->first_index) {
-         freelog(LOG_DEBUG, "stopping because we ran a round\n");
-         return GR_ARRIVED;    /* don't patrol more than one round */
-       }
-       if (maybe_cancel_patrol_due_to_enemy(punit)) {
-         return GR_FAILED;
-       }
+    switch (punit->orders.list[punit->orders.index].order) {
+    case ORDERS_WAIT:
+      punit->done_moving = TRUE;
+      freelog(LOG_DEBUG, "waiting this turn");
+      send_unit_info(unit_owner(punit), punit);
+      break;
+    case ORDERS_MOVE:
+      /* Move unit */
+      if (!MAPSTEP(dest_x, dest_y, punit->x, punit->y,
+                  punit->orders.list[punit->orders.index].dir)) {
+       return GR_FAILED;
       }
 
-      if (!moved) {
-       /* Sometimes the goto route will have us sit still for a moment -
-        * for instance a trireme will do this to have enough MP to
-        * cross the ocean in one turn. */
-       punit->done_moving = TRUE;
-       send_unit_info(unit_owner(punit), punit);
-       return GR_WAITING;
+      if (!last_order
+         && maybe_cancel_goto_due_to_enemy(punit, dest_x, dest_y)) {
+       return GR_FAILED;
       }
-    }
 
-    if (res && !same_pos(x, y, punit->x, punit->y)) {
-      /*
-       * unit is alive, moved alright, didn't arrive, has moves_left
-       * --- what else can it be 
-       */
-      return GR_FOUGHT;
+      freelog(LOG_DEBUG, "moving to %d,%d", dest_x, dest_y);
+      res = handle_unit_move_request(punit, dest_x, dest_y,
+                                    FALSE, !last_order);
+      if (!player_find_unit_by_id(pplayer, unitid)) {
+       return GR_DIED;
+      }
+
+      if (res && !same_pos(dest_x, dest_y, punit->x, punit->y)) {
+       /* Movement succeeded but unit didn't move. */
+       return GR_FOUGHT;
+      }
+
+      if (!res && punit->moves_left > 0) {
+       /* Movement failed (ZOC, etc.) */
+       return GR_FAILED;
+      }
+      break;
     }
 
-    if (!res && punit->moves_left > 0) {
-      freelog(LOG_DEBUG, "move idling\n");
-      handle_unit_activity_request(punit, ACTIVITY_IDLE);
-      return GR_FAILED;
+    /* We succeeded in moving one step forward */
+    punit->orders.index++;
+
+    if (punit->orders.index == punit->orders.length) {
+      if (!punit->orders.repeat) {
+       free_unit_orders(punit);
+       assert(punit->has_orders == FALSE);
+       freelog(LOG_DEBUG, "stopping because orders are complete");
+       return GR_ARRIVED;
+      } else {
+       /* Start over. */
+       punit->orders.index = 0;
+      }
     }
-  } /* end while*/
+  } /* end while */
 }
 
 /**************************************************************************
Index: server/unittools.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unittools.h,v
retrieving revision 1.58
diff -u -r1.58 unittools.h
--- server/unittools.h  2003/11/28 17:37:22     1.58
+++ server/unittools.h  2004/01/05 07:15:19
@@ -82,6 +82,6 @@
 void assign_units_to_transporter(struct unit *ptrans, bool take_from_land);
 bool move_unit(struct unit *punit, int dest_x, int dest_y,
              bool transport_units, bool take_from_land, int move_cost);
-enum goto_result goto_route_execute(struct unit *punit);
+enum goto_result execute_orders(struct unit *punit);
 
 #endif  /* FC__UNITTOOLS_H */

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