Author: sveinung
Date: Wed Sep 23 19:31:38 2015
New Revision: 29959

URL: http://svn.gna.org/viewcvs/freeciv?rev=29959&view=rev
Log:
orders system: support targeted steal tech

Use the existing target field to specify the target tech.

See patch #6367

Modified:
    trunk/common/packets.def
    trunk/fc_version
    trunk/server/savegame3.c
    trunk/server/unithand.c
    trunk/server/unittools.c

Modified: trunk/common/packets.def
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/packets.def?rev=29959&r1=29958&r2=29959&view=diff
==============================================================================
--- trunk/common/packets.def    (original)
+++ trunk/common/packets.def    Wed Sep 23 19:31:38 2015
@@ -268,6 +268,7 @@
 
 # typedefs for IDs
 type EXTRA              = SINT8
+type ACTION_TGT         = SINT16
 type BASE               = sint8(Base_type_id)
 type ROAD               = sint8(Road_type_id)
 type ACT_PROB           = uint8(action_probability)
@@ -916,7 +917,7 @@
   ORDERS orders[MAX_LEN_ROUTE:orders_length];
   DIRECTION orders_dirs[MAX_LEN_ROUTE:orders_length];
   ACTIVITY orders_activities[MAX_LEN_ROUTE:orders_length];
-  EXTRA orders_targets[MAX_LEN_ROUTE:orders_length];
+  ACTION_TGT orders_targets[MAX_LEN_ROUTE:orders_length];
   GEN_ACTION orders_actions[MAX_LEN_ROUTE:orders_length];
 end
 
@@ -972,7 +973,7 @@
   ORDERS orders[MAX_LEN_ROUTE:length];
   DIRECTION dir[MAX_LEN_ROUTE:length];
   ACTIVITY activity[MAX_LEN_ROUTE:length];
-  EXTRA target[MAX_LEN_ROUTE:length];
+  ACTION_TGT target[MAX_LEN_ROUTE:length];
   GEN_ACTION action[MAX_LEN_ROUTE:length];
   TILE dest_tile;
 end
@@ -1019,7 +1020,7 @@
 PACKET_UNIT_DO_ACTION = 84; cs, dsend
   UNIT actor_id;
   SINT32 target_id;   # city_id, unit_id or tile_id
-  SINT16 value;
+  ACTION_TGT value;
   ESTRING name[MAX_LEN_NAME];
   GEN_ACTION action_type;
 end

Modified: trunk/fc_version
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/fc_version?rev=29959&r1=29958&r2=29959&view=diff
==============================================================================
--- trunk/fc_version    (original)
+++ trunk/fc_version    Wed Sep 23 19:31:38 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.Sep.20"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-3.0-2015.Sep.23"
 NETWORK_CAPSTRING_OPTIONAL=""
 
 FREECIV_DISTRIBUTOR=""

Modified: trunk/server/savegame3.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame3.c?rev=29959&r1=29958&r2=29959&view=diff
==============================================================================
--- trunk/server/savegame3.c    (original)
+++ trunk/server/savegame3.c    Wed Sep 23 19:31:38 2015
@@ -5222,8 +5222,53 @@
                                                unitstr, j);
 
         if (order->order == ORDER_PERFORM_ACTION) {
-          /* TODO: Validate action target */
-          order->target = order_tgt;
+          switch (order->action) {
+          case ACTION_SPY_TARGETED_STEAL_TECH:
+            if (order_tgt == A_NONE
+                || (!valid_advance_by_number(order_tgt)
+                    && order_tgt != A_FUTURE)) {
+              /* Target tech is invalid. */
+              log_sg("Cannot find tech %d for %s to steal",
+                     order_tgt, unit_rule_name(punit));
+              order->target = EXTRA_NONE;
+            } else {
+              order->target = order_tgt;
+            }
+            break;
+          case ACTION_ESTABLISH_EMBASSY:
+          case ACTION_SPY_INVESTIGATE_CITY:
+          case ACTION_SPY_POISON:
+          case ACTION_SPY_STEAL_GOLD:
+          case ACTION_SPY_SABOTAGE_CITY:
+          case ACTION_SPY_TARGETED_SABOTAGE_CITY:
+          case ACTION_SPY_STEAL_TECH:
+          case ACTION_SPY_INCITE_CITY:
+          case ACTION_TRADE_ROUTE:
+          case ACTION_MARKETPLACE:
+          case ACTION_HELP_WONDER:
+          case ACTION_SPY_BRIBE_UNIT:
+          case ACTION_SPY_SABOTAGE_UNIT:
+          case ACTION_CAPTURE_UNITS:
+          case ACTION_FOUND_CITY:
+          case ACTION_JOIN_CITY:
+          case ACTION_STEAL_MAPS:
+          case ACTION_BOMBARD:
+          case ACTION_SPY_NUKE:
+          case ACTION_NUKE:
+          case ACTION_DESTROY_CITY:
+          case ACTION_EXPEL_UNIT:
+          case ACTION_COUNT:
+            /* Target in order unsupported. */
+
+            /* Target shouldn't be specified yet. */
+            fc_assert_msg(order_tgt == -1,
+                          "Specified target for action %d unsupported.",
+                          order->action);
+
+            order->target = EXTRA_NONE;
+
+            break;
+          }
         } else {
           /* Assume that this is an extra */
           extra_id = order_tgt;
@@ -5442,6 +5487,7 @@
           break;
         case ORDER_PERFORM_ACTION:
           action_buf[j] = num2char(punit->orders.list[j].action);
+          tgt_vec[j] = punit->orders.list[j].target;
           if (punit->orders.list[j].dir != -1) {
             /* The action target is on another tile. */
             dir_buf[j] = dir2char(punit->orders.list[j].dir);

Modified: trunk/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.c?rev=29959&r1=29958&r2=29959&view=diff
==============================================================================
--- trunk/server/unithand.c     (original)
+++ trunk/server/unithand.c     Wed Sep 23 19:31:38 2015
@@ -3915,6 +3915,20 @@
           return;
         }
         break;
+      case ACTION_SPY_TARGETED_STEAL_TECH:
+        if (packet->target[i] == A_NONE
+            || (!valid_advance_by_number(packet->target[i])
+                && packet->target[i] != A_FUTURE)) {
+          /* Target tech is invalid. */
+
+          log_error("handle_unit_orders() can't do %s without a target. "
+                    "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;
+        }
+        break;
       case ACTION_ESTABLISH_EMBASSY:
       case ACTION_SPY_INVESTIGATE_CITY:
       case ACTION_SPY_POISON:
@@ -3939,7 +3953,6 @@
         break;
       /* Needs additional target information. */
       case ACTION_SPY_TARGETED_SABOTAGE_CITY:
-      case ACTION_SPY_TARGETED_STEAL_TECH:
         log_error("handle_unit_orders() the action %s isn't allowed in "
                   "orders. "
                   "Sent in order number %d from %s to unit number %d.",

Modified: trunk/server/unittools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unittools.c?rev=29959&r1=29958&r2=29959&view=diff
==============================================================================
--- trunk/server/unittools.c    (original)
+++ trunk/server/unittools.c    Wed Sep 23 19:31:38 2015
@@ -4142,7 +4142,8 @@
       performed = unit_perform_action(pplayer,
                                       unitid,
                                       tgt_id,
-                                      0, name,
+                                      order.target,
+                                      name,
                                       order.action);
 
       if (!player_unit_by_number(pplayer, unitid)) {


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

Reply via email to