Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2004:
[Freeciv-Dev] (PR#9662) activities as orders
Home

[Freeciv-Dev] (PR#9662) activities as orders

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#9662) activities as orders
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 19 Aug 2004 18:06:15 -0700
Reply-to: rt@xxxxxxxxxxx

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

Here's an update and fix of this patch.

- Updated capstr.c.

- Fixed savegame loading.  If an old savegame is loaded the orders will
be invalid and will be dropped (previously the orders were invalid but
were _not_ dropped, leading to problems).  This means orders from old
savegames will be lost.  This could be worked around but I don't think
it's worth it since 1.14 goto routes will be lost anyway, and since new
types of orders will probably still be added.

I also attached as a comment an old-style savegame that can be used for
testing.

jason

? freeciv-1.14.99-devel.tar.gz
? server/civmanual.c
Index: client/goto.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/goto.c,v
retrieving revision 1.70
diff -u -r1.70 goto.c
--- client/goto.c       21 Jun 2004 15:14:43 -0000      1.70
+++ client/goto.c       20 Aug 2004 01:00:15 -0000
@@ -548,6 +548,7 @@
     } else {
       p.orders[i] = ORDER_MOVE;
       p.dir[i] = get_direction_for_step(old_x, old_y, new_x, new_y);
+      p.activity[i] = ACTIVITY_LAST;
       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);
     }
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.395
diff -u -r1.395 packhand.c
--- client/packhand.c   14 Aug 2004 21:46:27 -0000      1.395
+++ client/packhand.c   20 Aug 2004 01:00:16 -0000
@@ -126,6 +126,7 @@
     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];
+      punit->orders.list[i].activity = packet->orders_activities[i];
     }
   }
   return punit;
Index: common/capstr.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/capstr.c,v
retrieving revision 1.177
diff -u -r1.177 capstr.c
--- common/capstr.c     13 Aug 2004 15:59:12 -0000      1.177
+++ common/capstr.c     20 Aug 2004 01:00:16 -0000
@@ -78,7 +78,7 @@
                    "+change_production +tilespec1 +no_earth +trans " \
                    "+want_hack invasions bombard +killstack2 spec +spec2 " \
                    "+city_map startunits +turn_last_built +happyborders " \
-                   "+connid +love2 +ocean_num"
+                   "+connid +love2 +ocean_num +orders3"
 
 /* "+1.14.delta" is the new delta protocol for 1.14.0-dev.
  *
@@ -140,6 +140,8 @@
  *
  * "ocean_num" means that the oceans are numbered by negative numbers
  * which are stored in ptile->continent and sent to client.
+ *
+ * "orders3" provides some additional orders that can be given
  */
 
 void init_our_capability(void)
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.204
diff -u -r1.204 map.h
--- common/map.h        13 Aug 2004 15:59:12 -0000      1.204
+++ common/map.h        20 Aug 2004 01:00:16 -0000
@@ -578,6 +578,7 @@
 struct unit_order {
   enum unit_orders order;
   enum direction8 dir;         /* Only valid for ORDER_MOVE. */
+  enum unit_activity activity; /* Only valid for ORDER_ACTIVITY. */
 };
 
 /* return the reverse of the direction */
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.39
diff -u -r1.39 packets.def
--- common/packets.def  14 Aug 2004 21:46:28 -0000      1.39
+++ common/packets.def  20 Aug 2004 01:00:16 -0000
@@ -621,6 +621,7 @@
   BOOL orders_repeat, orders_vigilant;
   ORDERS orders[MAX_LEN_ROUTE:orders_length];
   DIRECTION orders_dirs[MAX_LEN_ROUTE:orders_length];
+  ACTIVITY orders_activities[MAX_LEN_ROUTE:orders_length];
 end
 
 PACKET_UNIT_SHORT_INFO=50; is-info,sc,lsend
@@ -692,6 +693,7 @@
   BOOL repeat, vigilant;
   ORDERS orders[MAX_LEN_ROUTE:length];
   DIRECTION dir[MAX_LEN_ROUTE:length];
+  ACTIVITY activity[MAX_LEN_ROUTE:length];
   COORD dest_x, dest_y;
 end
 
Index: common/unit.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unit.h,v
retrieving revision 1.121
diff -u -r1.121 unit.h
--- common/unit.h       2 Aug 2004 16:59:14 -0000       1.121
+++ common/unit.h       20 Aug 2004 01:00:16 -0000
@@ -41,7 +41,7 @@
 
 /* Changing this enum will break savegame and network compatability. */
 enum unit_orders {
-  ORDER_MOVE, ORDER_FINISH_TURN,
+  ORDER_MOVE, ORDER_FINISH_TURN, ORDER_ACTIVITY,
   ORDER_LAST
 };
 
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.176
diff -u -r1.176 savegame.c
--- server/savegame.c   18 Aug 2004 18:11:05 -0000      1.176
+++ server/savegame.c   20 Aug 2004 01:00:19 -0000
@@ -1322,7 +1322,7 @@
       int len = secfile_lookup_int_default(file, 0,
                        "player%d.u%d.orders_length", plrno, i);
       if (len > 0) {
-       char *orders_buf, *dir_buf;
+       char *orders_buf, *dir_buf, *act_buf;
 
        punit->orders.list = fc_malloc(len * sizeof(*(punit->orders.list)));
        punit->orders.length = len;
@@ -1337,16 +1337,20 @@
                        "player%d.u%d.orders_list", plrno, i);
        dir_buf = secfile_lookup_str_default(file, "",
                        "player%d.u%d.dir_list", plrno, i);
+       act_buf = secfile_lookup_str_default(file, "",
+                       "player%d.u%d.activity_list", plrno, i);
+       punit->has_orders = TRUE;
        for (j = 0; j < len; j++) {
-         if (orders_buf[j] == '\0' || dir_buf == '\0') {
+         if (orders_buf[j] == '\0' || dir_buf == '\0'
+             || act_buf[j] == '\0') {
            freelog(LOG_ERROR, _("Savegame error: invalid unit orders."));
            free_unit_orders(punit);
            break;
          }
          punit->orders.list[j].order = orders_buf[j] - 'a';
          punit->orders.list[j].dir = dir_buf[j] - 'a';
+         punit->orders.list[j].activity = act_buf[j] - 'a';
        }
-       punit->has_orders = TRUE;
       } else {
        punit->has_orders = FALSE;
        punit->orders.list = NULL;
@@ -2380,7 +2384,7 @@
                       "player%d.u%d.transported_by", plrno, i);
     if (punit->has_orders) {
       int len = punit->orders.length, j;
-      char orders_buf[len + 1], dir_buf[len + 1];
+      char orders_buf[len + 1], dir_buf[len + 1], act_buf[len + 1];
 
       secfile_insert_int(file, len, "player%d.u%d.orders_length", plrno, i);
       secfile_insert_int(file, punit->orders.index,
@@ -2393,13 +2397,16 @@
       for (j = 0; j < len; j++) {
        orders_buf[j] = 'a' + punit->orders.list[j].order;
        dir_buf[j] = 'a' + punit->orders.list[j].dir;
+       act_buf[j] = 'a' + punit->orders.list[j].activity;
       }
-      orders_buf[len] = dir_buf[len] = '\0';
+      orders_buf[len] = dir_buf[len] = act_buf[len] = '\0';
 
       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);
+      secfile_insert_str(file, act_buf,
+                        "player%d.u%d.activity_list", plrno, i);
     } else {
       /* Put all the same fields into the savegame.  Otherwise the
        * registry code gets confused (although it still works). */
Index: server/unithand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unithand.c,v
retrieving revision 1.301
diff -u -r1.301 unithand.c
--- server/unithand.c   8 Aug 2004 14:15:14 -0000       1.301
+++ server/unithand.c   20 Aug 2004 01:00:19 -0000
@@ -1626,6 +1626,28 @@
        return;
       }
       break;
+    case ORDER_ACTIVITY:
+      switch (packet->activity[i]) {
+      case ACTIVITY_POLLUTION:
+      case ACTIVITY_ROAD:
+      case ACTIVITY_MINE:
+      case ACTIVITY_IRRIGATE:
+      case ACTIVITY_FORTRESS:
+      case ACTIVITY_RAILROAD:
+      case ACTIVITY_TRANSFORM:
+      case ACTIVITY_AIRBASE:
+       /* Simple activities. */
+       break;
+      case ACTIVITY_SENTRY:
+       if (i != packet->length - 1) {
+         /* Only allowed as the last order. */
+         return;
+       }
+       break;
+      default:
+       return;
+      }
+      break;
     case ORDER_FINISH_TURN:
       break;
     default:
@@ -1653,6 +1675,7 @@
   for (i = 0; i < packet->length; i++) {
     punit->orders.list[i].order = packet->orders[i];
     punit->orders.list[i].dir = packet->dir[i];
+    punit->orders.list[i].activity = packet->activity[i];
   }
 
   if (!packet->repeat) {
Index: server/unittools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unittools.c,v
retrieving revision 1.298
diff -u -r1.298 unittools.c
--- server/unittools.c  13 Aug 2004 15:59:13 -0000      1.298
+++ server/unittools.c  20 Aug 2004 01:00:20 -0000
@@ -1853,6 +1853,7 @@
     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;
+      packet->orders_activities[i] = punit->orders.list[i].activity;
     }
   } else {
     packet->orders_length = packet->orders_index = 0;
@@ -2926,9 +2927,16 @@
   int unitid = punit->id;
   struct player *pplayer = unit_owner(punit);
   int moves_made = 0;
+  enum unit_activity activity;
 
   assert(unit_has_orders(punit));
 
+  if (punit->activity != ACTIVITY_IDLE) {
+    /* Unit's in the middle of an activity; wait for it to finish. */
+    punit->done_moving = TRUE;
+    return TRUE;
+  }
+
   freelog(LOG_DEBUG, "Executing orders for %s %d",
          unit_name(punit->type), punit->id);   
 
@@ -2988,6 +2996,20 @@
       freelog(LOG_DEBUG, "  waiting this turn");
       send_unit_info(NULL, punit);
       break;
+    case ORDER_ACTIVITY:
+      activity = order.activity;
+      if (!can_unit_do_activity(punit, activity)) {
+       cancel_orders(punit, "  orders canceled because of failed activity");
+       notify_player_ex(pplayer, punit->x, punit->y, E_UNIT_ORDERS,
+                        _("Game: Orders for %s aborted since they "
+                          "give an invalid activity."),
+                        unit_name(punit->type));
+       return TRUE;
+      }
+      punit->done_moving = TRUE;
+      set_unit_activity(punit, activity);
+      send_unit_info(NULL, punit);
+      break;
     case ORDER_MOVE:
       /* Move unit */
       if (!MAPSTEP(dest_x, dest_y, punit->x, punit->y, order.dir)) {

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