Author: sveinung
Date: Fri Jul 31 15:09:13 2015
New Revision: 29280

URL: http://svn.gna.org/viewcvs/freeciv?rev=29280&view=rev
Log:
Add initial action support to the orders system

The support isn't used by any client yet. Only Explode Nuclear at the tile
the unit is on is currently supported.

See patch #6153

Modified:
    trunk/client/control.c
    trunk/client/goto.c
    trunk/client/packhand.c
    trunk/common/packets.def
    trunk/common/unit.h
    trunk/fc_version
    trunk/server/savegame.c
    trunk/server/savegame2.c
    trunk/server/savegame3.c
    trunk/server/unithand.c
    trunk/server/unittools.c

Modified: trunk/client/control.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/control.c?rev=29280&r1=29279&r2=29280&view=diff
==============================================================================
--- trunk/client/control.c      (original)
+++ trunk/client/control.c      Fri Jul 31 15:09:13 2015
@@ -1347,6 +1347,7 @@
       order.dir = -1;
       order.activity = ACTIVITY_SENTRY;
       order.target = EXTRA_NONE;
+      order.action = ACTION_COUNT;
       send_goto_path(punit, path, &order);
     } else {
       send_goto_path(punit, path, NULL);
@@ -1563,6 +1564,7 @@
   p.dir[0] = dir;
   p.activity[0] = ACTIVITY_LAST;
   p.target[0] = EXTRA_NONE;
+  p.action[0] = ACTION_COUNT;
 
   send_packet_unit_orders(&client.conn, &p);
 }

Modified: trunk/client/goto.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/goto.c?rev=29280&r1=29279&r2=29280&view=diff
==============================================================================
--- trunk/client/goto.c (original)
+++ trunk/client/goto.c Fri Jul 31 15:09:13 2015
@@ -1384,12 +1384,14 @@
       p.dir[i] = -1;
       p.activity[i] = ACTIVITY_LAST;
       p.target[i] = EXTRA_NONE;
+      p.action[i] = ACTION_COUNT;
       log_goto_packet("  packet[%d] = wait: %d,%d", i, TILE_XY(old_tile));
     } else {
       p.orders[i] = ORDER_MOVE;
       p.dir[i] = get_direction_for_step(old_tile, new_tile);
       p.activity[i] = ACTIVITY_LAST;
       p.target[i] = EXTRA_NONE;
+      p.action[i] = ACTION_COUNT;
       log_goto_packet("  packet[%d] = move %s: %d,%d => %d,%d",
                       i, dir_get_name(p.dir[i]),
                       TILE_XY(old_tile), TILE_XY(new_tile));
@@ -1409,6 +1411,7 @@
     p.activity[i] = (final_order->order == ORDER_ACTIVITY)
       ? final_order->activity : ACTIVITY_LAST;
     p.target[i] = final_order->target;
+    p.action[i] = ACTION_COUNT;
     p.length++;
   }
 
@@ -1504,6 +1507,7 @@
   p->dir[p->length] = -1;
   p->activity[p->length] = ACTIVITY_GEN_ROAD;
   p->target[p->length] = extra_index(pextra);
+  p->action[p->length] = ACTION_COUNT;
   p->length++;
 
   return TRUE;
@@ -1552,6 +1556,7 @@
           p.dir[p.length] = -1;
          p.activity[p.length] = ACTIVITY_IRRIGATE;
           p.target[p.length] = extra_index(tgt);
+          p.action[p.length] = ACTION_COUNT;
          p.length++;
        }
        break;
@@ -1572,6 +1577,7 @@
        p.dir[p.length] = get_direction_for_step(old_tile, new_tile);
         p.activity[p.length] = ACTIVITY_LAST;
         p.target[p.length] = EXTRA_NONE;
+        p.action[p.length] = ACTION_COUNT;
        p.length++;
 
        old_tile = new_tile;
@@ -1616,6 +1622,7 @@
       order.dir = -1;
       order.activity = ACTIVITY_LAST;
       order.target = EXTRA_NONE;
+      order.action = ACTION_COUNT;
 
       /* ORDER_MOVE would require real direction,
        * ORDER_ACTIVITY would require real activity */

Modified: trunk/client/packhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/packhand.c?rev=29280&r1=29279&r2=29280&view=diff
==============================================================================
--- trunk/client/packhand.c     (original)
+++ trunk/client/packhand.c     Fri Jul 31 15:09:13 2015
@@ -232,6 +232,7 @@
       punit->orders.list[i].dir = packet->orders_dirs[i];
       punit->orders.list[i].activity = packet->orders_activities[i];
       punit->orders.list[i].target = packet->orders_targets[i];
+      punit->orders.list[i].action = packet->orders_actions[i];
     }
   }
 

Modified: trunk/common/packets.def
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/packets.def?rev=29280&r1=29279&r2=29280&view=diff
==============================================================================
--- trunk/common/packets.def    (original)
+++ trunk/common/packets.def    Fri Jul 31 15:09:13 2015
@@ -909,6 +909,7 @@
   DIRECTION orders_dirs[MAX_LEN_ROUTE:orders_length];
   ACTIVITY orders_activities[MAX_LEN_ROUTE:orders_length];
   EXTRA orders_targets[MAX_LEN_ROUTE:orders_length];
+  GEN_ACTION orders_actions[MAX_LEN_ROUTE:orders_length];
 end
 
 PACKET_UNIT_SHORT_INFO = 64; sc, lsend, is-game-info, force, 
cancel(PACKET_UNIT_INFO)
@@ -964,6 +965,7 @@
   DIRECTION dir[MAX_LEN_ROUTE:length];
   ACTIVITY activity[MAX_LEN_ROUTE:length];
   EXTRA target[MAX_LEN_ROUTE:length];
+  GEN_ACTION action[MAX_LEN_ROUTE:length];
   TILE dest_tile;
 end
 

Modified: trunk/common/unit.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/unit.h?rev=29280&r1=29279&r2=29280&view=diff
==============================================================================
--- trunk/common/unit.h (original)
+++ trunk/common/unit.h Fri Jul 31 15:09:13 2015
@@ -41,6 +41,7 @@
   ORDER_TRADE_ROUTE = 6,
   ORDER_HOMECITY = 7,
   ORDER_ACTION_MOVE = 8,
+  ORDER_PERFORM_ACTION = 9,
   /* and plenty more for later... */
   ORDER_LAST
 };
@@ -99,6 +100,8 @@
   enum unit_orders order;
   enum unit_activity activity;  /* Only valid for ORDER_ACTIVITY. */
   int target;
+  /* Only valid for ORDER_PERFORM_ACTION */
+  int action;
   enum direction8 dir;          /* Only valid for ORDER_MOVE. */
 };
 

Modified: trunk/fc_version
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/fc_version?rev=29280&r1=29279&r2=29280&view=diff
==============================================================================
--- trunk/fc_version    (original)
+++ trunk/fc_version    Fri Jul 31 15:09:13 2015
@@ -54,7 +54,7 @@
 #   - Avoid adding a new mandatory capability to the development branch for
 #     as long as possible.  We want to maintain network compatibility with
 #     the stable branch for as long as possible.
-NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-3.0-2015.Jul.31b"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-3.0-2015.Jul.31c"
 NETWORK_CAPSTRING_OPTIONAL=""
 
 FREECIV_DISTRIBUTOR=""

Modified: trunk/server/savegame.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame.c?rev=29280&r1=29279&r2=29280&view=diff
==============================================================================
--- trunk/server/savegame.c     (original)
+++ trunk/server/savegame.c     Fri Jul 31 15:09:13 2015
@@ -1495,6 +1495,7 @@
          order->order = char2order(orders_buf[j]);
          order->dir = char2dir(dir_buf[j]);
          order->activity = char2activity(act_buf[j]);
+          order->action = ACTION_COUNT;
          if (order->order == ORDER_LAST
              || (order->order == ORDER_MOVE && 
!direction8_is_valid(order->dir))
              || (order->order == ORDER_ACTIVITY

Modified: trunk/server/savegame2.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame2.c?rev=29280&r1=29279&r2=29280&view=diff
==============================================================================
--- trunk/server/savegame2.c    (original)
+++ trunk/server/savegame2.c    Fri Jul 31 15:09:13 2015
@@ -3885,6 +3885,7 @@
         order->order = char2order(orders_unitstr[j]);
         order->dir = char2dir(dir_unitstr[j]);
         order->activity = char2activity(act_unitstr[j]);
+        order->action = ACTION_COUNT;
         if (order->order == ORDER_LAST
             || (order->order == ORDER_MOVE && !direction8_is_valid(order->dir))
             || (order->order == ORDER_ACTIVITY

Modified: trunk/server/savegame3.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame3.c?rev=29280&r1=29279&r2=29280&view=diff
==============================================================================
--- trunk/server/savegame3.c    (original)
+++ trunk/server/savegame3.c    Fri Jul 31 15:09:13 2015
@@ -723,6 +723,9 @@
   case 'x':
   case 'X':
     return ORDER_ACTION_MOVE;
+  case 'p':
+  case 'P':
+    return ORDER_PERFORM_ACTION;
   }
 
   /* This can happen if the savegame is invalid. */
@@ -753,6 +756,8 @@
     return 'h';
   case ORDER_ACTION_MOVE:
     return 'x';
+  case ORDER_PERFORM_ACTION:
+    return 'p';
   case ORDER_LAST:
     break;
   }
@@ -1644,6 +1649,26 @@
     free(modname);
   }
 
+  /* Save action order in the savegame. */
+  secfile_insert_int(saving->file, ACTION_COUNT,
+                     "savefile.action_size");
+  if (ACTION_COUNT > 0) {
+    const char **modname;
+    int j;
+
+    i = 0;
+    modname = fc_calloc(ACTION_COUNT, sizeof(*modname));
+
+    for (j = 0; j < ACTION_COUNT; j++) {
+      modname[i++] = gen_action_name(j);
+    }
+
+    secfile_insert_str_vec(saving->file, modname,
+                           ACTION_COUNT,
+                           "savefile.action_vector");
+    free(modname);
+  }
+
   /* Save terrain character mapping in the savegame. */
   i = 0;
   terrain_type_iterate(pterr) {
@@ -5032,6 +5057,7 @@
     if (len > 0) {
       const char *orders_unitstr, *dir_unitstr, *act_unitstr;
       const char *tgt_unitstr;
+      const char *action_unitstr;
 
       punit->orders.list = fc_malloc(len * sizeof(*(punit->orders.list)));
       punit->orders.length = len;
@@ -5057,12 +5083,15 @@
       tgt_unitstr
         = secfile_lookup_str_default(loading->file, NULL, "%s.tgt_list", 
unitstr);
 
+      action_unitstr
+        = secfile_lookup_str_default(loading->file, "",
+                                     "%s.action_list", unitstr);
       punit->has_orders = TRUE;
       for (j = 0; j < len; j++) {
         struct unit_order *order = &punit->orders.list[j];
 
         if (orders_unitstr[j] == '\0' || dir_unitstr[j] == '\0'
-            || act_unitstr[j] == '\0') {
+            || act_unitstr[j] == '\0' || action_unitstr == '\0') {
           log_sg("Invalid unit orders.");
           free_unit_orders(punit);
           break;
@@ -5070,6 +5099,11 @@
         order->order = char2order(orders_unitstr[j]);
         order->dir = char2dir(dir_unitstr[j]);
         order->activity = char2activity(act_unitstr[j]);
+
+        order->action = (action_unitstr[j] == '?'
+                         ? ACTION_COUNT
+                         : char2num(action_unitstr[j]));
+
         if (order->order == ORDER_LAST
             || (order->order == ORDER_MOVE && !direction8_is_valid(order->dir))
             || (order->order == ORDER_ACTIVITY
@@ -5258,6 +5292,7 @@
       int len = punit->orders.length, j;
       char orders_buf[len + 1], dir_buf[len + 1];
       char act_buf[len + 1], tgt_buf[len + 1];
+      char action_buf[len + 1];
 
       secfile_insert_int(saving->file, len, "%s.orders_length", buf);
       secfile_insert_int(saving->file, punit->orders.index,
@@ -5272,6 +5307,7 @@
         dir_buf[j] = '?';
         act_buf[j] = '?';
         tgt_buf[j] = '?';
+        action_buf[j] = '?';
         switch (punit->orders.list[j].order) {
         case ORDER_MOVE:
           dir_buf[j] = dir2char(punit->orders.list[j].dir);
@@ -5279,6 +5315,9 @@
         case ORDER_ACTIVITY:
           tgt_buf[j] = num2char(punit->orders.list[j].target);
           act_buf[j] = activity2char(punit->orders.list[j].activity);
+          break;
+        case ORDER_PERFORM_ACTION:
+          action_buf[j] = num2char(punit->orders.list[j].action);
           break;
         case ORDER_FULL_MP:
         case ORDER_BUILD_CITY:
@@ -5292,11 +5331,13 @@
         }
       }
       orders_buf[len] = dir_buf[len] = act_buf[len] = tgt_buf[len] = '\0';
+      action_buf[len] = '\0';
 
       secfile_insert_str(saving->file, orders_buf, "%s.orders_list", buf);
       secfile_insert_str(saving->file, dir_buf, "%s.dir_list", buf);
       secfile_insert_str(saving->file, act_buf, "%s.activity_list", buf);
       secfile_insert_str(saving->file, tgt_buf, "%s.tgt_list", buf);
+      secfile_insert_str(saving->file, action_buf, "%s.action_list", buf);
     } else {
       /* Put all the same fields into the savegame - otherwise the
        * registry code can't correctly use a tabular format and the
@@ -5309,6 +5350,7 @@
       secfile_insert_str(saving->file, "-", "%s.dir_list", buf);
       secfile_insert_str(saving->file, "-", "%s.activity_list", buf);
       secfile_insert_str(saving->file, "-", "%s.tgt_list", buf);
+      secfile_insert_str(saving->file, "-", "%s.action_list", buf);
     }
 
     i++;

Modified: trunk/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.c?rev=29280&r1=29279&r2=29280&view=diff
==============================================================================
--- trunk/server/unithand.c     (original)
+++ trunk/server/unithand.c     Fri Jul 31 15:09:13 2015
@@ -3530,6 +3530,35 @@
       }
 
       break;
+    case ORDER_PERFORM_ACTION:
+      switch ((enum gen_action) packet->action[i]) {
+      case ACTION_NUKE:
+        break;
+      default:
+        log_error("handle_unit_orders() the action %s isn't allowed in "
+                  "orders. "
+                  "Sent in order number %d from %s to unit number %d.",
+                  action_get_rule_name(packet->action[i]), i,
+                  player_name(pplayer), packet->unit_id);
+
+        return;
+      }
+
+      switch (action_get_target_kind(packet->action[i])) {
+      case ATK_CITY:
+        break;
+      case ATK_UNIT:
+        break;
+      case ATK_UNITS:
+        break;
+      case ATK_TILE:
+        break;
+      case ATK_COUNT:
+        fc_assert(action_get_target_kind(packet->action[i]) != ATK_COUNT);
+        break;
+      }
+
+      break;
     case ORDER_FULL_MP:
     case ORDER_BUILD_CITY:
     case ORDER_DISBAND:
@@ -3575,6 +3604,7 @@
     punit->orders.list[i].dir = packet->dir[i];
     punit->orders.list[i].activity = packet->activity[i];
     punit->orders.list[i].target = packet->target[i];
+    punit->orders.list[i].action = packet->action[i];
   }
 
   if (!packet->repeat) {

Modified: trunk/server/unittools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unittools.c?rev=29280&r1=29279&r2=29280&view=diff
==============================================================================
--- trunk/server/unittools.c    (original)
+++ trunk/server/unittools.c    Fri Jul 31 15:09:13 2015
@@ -2306,6 +2306,7 @@
       packet->orders_dirs[i] = punit->orders.list[i].dir;
       packet->orders_activities[i] = punit->orders.list[i].activity;
       packet->orders_targets[i] = punit->orders.list[i].target;
+      packet->orders_actions[i] = punit->orders.list[i].action;
     }
   } else {
     packet->orders_length = packet->orders_index = 0;
@@ -3740,6 +3741,7 @@
   case ORDER_ACTIVITY:
   case ORDER_DISBAND:
   case ORDER_HOMECITY:
+  case ORDER_PERFORM_ACTION:
   case ORDER_LAST:
     /* Not action enabler controlled. */
     break;
@@ -3846,6 +3848,12 @@
     case ORDER_BUILD_WONDER:
     case ORDER_TRADE_ROUTE:
       if (should_wait_for_mp(punit, order_to_action(punit, order.order))) {
+        log_debug("  stopping. Not enough move points this turn");
+        return TRUE;
+      }
+      break;
+    case ORDER_PERFORM_ACTION:
+      if (should_wait_for_mp(punit, order.action)) {
         log_debug("  stopping. Not enough move points this turn");
         return TRUE;
       }
@@ -4113,6 +4121,23 @@
       } else {
        return FALSE;
       }
+    case ORDER_PERFORM_ACTION:
+      log_debug("  orders: doing action %d", order.action);
+
+      fc_assert_msg(
+            action_get_target_kind(order.action) == ATK_TILE,
+            "Only tile targets are currently supported");
+
+      dst_tile = unit_tile(punit);
+
+      fc_assert_ret_val_msg(dst_tile, FALSE, "No target tile for action");
+
+      handle_unit_do_action(pplayer,
+                            unitid,
+                            dst_tile->index,
+                            0, "", order.action);
+
+      return player_unit_by_number(pplayer, unitid);
     case ORDER_LAST:
       cancel_orders(punit, "  client sent invalid order!");
       notify_player(pplayer, unit_tile(punit), E_UNIT_ORDERS, ftc_server,


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to