Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2004:
[Freeciv-Dev] (PR#7357) send order lists back to the client
Home

[Freeciv-Dev] (PR#7357) send order lists back to the client

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#7357) send order lists back to the client
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 5 Feb 2004 23:41:41 -0800
Reply-to: rt@xxxxxxxxxxx

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

Here's a patch that just sends the orders route to the client.  It
should be ready to be applied.

jason

Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.349
diff -u -r1.349 packhand.c
--- client/packhand.c   2004/02/05 08:23:09     1.349
+++ client/packhand.c   2004/02/06 07:39:44
@@ -117,8 +117,20 @@
     punit->transported_by = 0;
   }
   punit->has_orders = packet->has_orders;
-  punit->orders.repeat = packet->repeat;
-  punit->orders.vigilant = packet->vigilant;
+  punit->orders.length = packet->orders_length;
+  punit->orders.index = packet->orders_index;
+  punit->orders.repeat = packet->orders_repeat;
+  punit->orders.vigilant = packet->orders_vigilant;
+  if (punit->has_orders) {
+    int i;
+
+    punit->orders.list
+      = fc_malloc(punit->orders.length * sizeof(*punit->orders.list));
+    for (i = 0; i < punit->orders.length; i++) {
+      punit->orders.list[i].order = packet->orders[i];
+      punit->orders.list[i].dir = packet->orders_dirs[i];
+    }
+  }
   return punit;
 }
 
@@ -979,9 +991,19 @@
 
       punit->activity = packet_unit->activity;
       punit->activity_target = packet_unit->activity_target;
+
       punit->has_orders = packet_unit->has_orders;
+      punit->orders.length = packet_unit->orders.length;
+      punit->orders.index = packet_unit->orders.index;
       punit->orders.repeat = packet_unit->orders.repeat;
       punit->orders.vigilant = packet_unit->orders.vigilant;
+
+      /* We cheat by just stealing the packet unit's list. */
+      if (punit->orders.list) {
+       free(punit->orders.list);
+      }
+      punit->orders.list = packet_unit->orders.list;
+      packet_unit->orders.list = NULL;
 
       if (punit->owner == game.player_idx) {
         refresh_unit_city_dialogs(punit);
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.8
diff -u -r1.8 packets.def
--- common/packets.def  2004/01/31 17:52:41     1.8
+++ common/packets.def  2004/02/06 07:39:45
@@ -599,7 +599,6 @@
   UINT8 veteran; add-cap(veteran)
   BOOL veteran_old; remove-cap(veteran)
   BOOL ai, paradropped, connecting, carried, done_moving;
-  BOOL has_orders, repeat, vigilant;
 
   UNIT_TYPE type;
   UINT8 movesleft, hp, fuel, activity_count;
@@ -607,6 +606,12 @@
   COORD goto_dest_x,goto_dest_y;
   ACTIVITY activity;
   SPECIAL activity_target;
+
+  BOOL has_orders;
+  UINT16 orders_length, orders_index;
+  BOOL orders_repeat, orders_vigilant;
+  ORDERS orders[MAX_LEN_ROUTE:orders_length];
+  DIRECTION orders_dirs[MAX_LEN_ROUTE:orders_length];
 end
 
 PACKET_UNIT_SHORT_INFO=50; is-info,sc
Index: common/unit.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unit.h,v
retrieving revision 1.110
diff -u -r1.110 unit.h
--- common/unit.h       2004/01/25 08:04:53     1.110
+++ common/unit.h       2004/02/06 07:39:45
@@ -164,10 +164,10 @@
 
   bool has_orders;
   struct {
-    int length, index; /* server only */
+    int length, index;
     bool repeat;       /* The path is to be repeated on completion. */
     bool vigilant;     /* Orders should be cleared if an enemy is met. */
-    struct unit_order *list; /* server only */
+    struct unit_order *list;
   } orders;
 };
 
Index: server/unittools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unittools.c,v
retrieving revision 1.277
diff -u -r1.277 unittools.c
--- server/unittools.c  2004/01/31 17:52:42     1.277
+++ server/unittools.c  2004/02/06 07:39:46
@@ -1891,10 +1891,20 @@
   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;
+    int i;
+
+    packet->orders_length = punit->orders.length;
+    packet->orders_index = punit->orders.index;
+    packet->orders_repeat = punit->orders.repeat;
+    packet->orders_vigilant = punit->orders.vigilant;
+    for (i = 0; i < punit->orders.length; i++) {
+      packet->orders[i] = punit->orders.list[i].order;
+      packet->orders_dirs[i] = punit->orders.list[i].dir;
+    }
   } else {
-    packet->repeat = packet->vigilant = FALSE;
+    packet->orders_length = packet->orders_index = 0;
+    packet->orders_repeat = packet->orders_vigilant = FALSE;
+    /* No need to initialize array. */
   }
 }
 
@@ -3217,6 +3227,11 @@
       free_unit_orders(punit);
     }
 
+    /* Advance the orders one step forward.  This is needed because any
+     * updates sent to the client as a result of the action should include
+     * the new index value. */
+    punit->orders.index++;
+
     switch (order.order) {
     case ORDER_FINISH_TURN:
       punit->done_moving = TRUE;
@@ -3287,9 +3302,6 @@
       freelog(LOG_DEBUG, "  stopping because orders are complete");
       return TRUE;
     }
-
-    /* We succeeded in moving one step forward */
-    punit->orders.index++;
 
     if (punit->orders.index == punit->orders.length) {
       assert(punit->orders.repeat);

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#7357) send order lists back to the client, Jason Short <=