Author: sveinung
Date: Fri Aug  7 17:33:15 2015
New Revision: 29383

URL: http://svn.gna.org/viewcvs/freeciv?rev=29383&view=rev
Log:
Save game unit order upgrade skeleton

Some unit order types can be expressed as a perform action order. To remove
duplication a order like that should be replaced with the corresponding
perform action order. This will require that the save game loading updates
the orders in a savegame from a previous Freeciv release.

Create a skeleton for unit order save game compatibility. No orders are
updated yet. The update can't be a simple text change because what action an
order maps to depends on data like if the target tile has a city.

See patch #6186

Modified:
    trunk/server/savecompat.c
    trunk/server/savecompat.h
    trunk/server/savegame.c
    trunk/server/savegame2.c

Modified: trunk/server/savecompat.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savecompat.c?rev=29383&r1=29382&r2=29383&view=diff
==============================================================================
--- trunk/server/savecompat.c   (original)
+++ trunk/server/savecompat.c   Fri Aug  7 17:33:15 2015
@@ -1027,3 +1027,14 @@
 
   return barbarian_type_invalid();
 }
+
+/**************************************************************************
+  Returns the action id corresponding to the specified order id. If no
+  corresponding action is found ACTION_COUNT is returned.
+**************************************************************************/
+int sg_order_to_action(enum unit_orders order, struct unit *act_unit,
+                       struct tile *tgt_tile)
+{
+  /* The order hasn't been replaced by an action. */
+  return ACTION_COUNT;
+}

Modified: trunk/server/savecompat.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savecompat.h?rev=29383&r1=29382&r2=29383&view=diff
==============================================================================
--- trunk/server/savecompat.h   (original)
+++ trunk/server/savecompat.h   Fri Aug  7 17:33:15 2015
@@ -159,4 +159,7 @@
 enum ai_level ai_level_convert(int old_level);
 enum barbarian_type barb_type_convert(int old_type);
 
+int sg_order_to_action(enum unit_orders order, struct unit *act_unit,
+                       struct tile *tgt_tile);
+
 #endif /* FC__SAVECOMPAT_H */

Modified: trunk/server/savegame.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame.c?rev=29383&r1=29382&r2=29383&view=diff
==============================================================================
--- trunk/server/savegame.c     (original)
+++ trunk/server/savegame.c     Fri Aug  7 17:33:15 2015
@@ -1495,7 +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
@@ -1506,6 +1506,14 @@
            punit->has_orders = FALSE;
            break;
          }
+
+          /* The order may have been replaced by the perform action order */
+          order->action = sg_order_to_action(order->order, punit,
+                                             punit->goto_tile);
+          if (order->action != ACTION_COUNT) {
+            /* The order was converted by order_to_action */
+            order->order = ORDER_PERFORM_ACTION;
+          }
 
           /* Pre 2.2 savegames had activities ACTIVITY_FORTRESS and 
ACTIVITY_AIRBASE */
           if (order->activity == ACTIVITY_FORTRESS) {

Modified: trunk/server/savegame2.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame2.c?rev=29383&r1=29382&r2=29383&view=diff
==============================================================================
--- trunk/server/savegame2.c    (original)
+++ trunk/server/savegame2.c    Fri Aug  7 17:33:15 2015
@@ -3888,7 +3888,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
@@ -3898,6 +3898,14 @@
           punit->orders.list = NULL;
           punit->has_orders = FALSE;
           break;
+        }
+
+        /* The order may have been replaced by the perform action order */
+        order->action = sg_order_to_action(order->order, punit,
+                                           punit->goto_tile);
+        if (order->action != ACTION_COUNT) {
+          /* The order was converted by order_to_action */
+          order->order = ORDER_PERFORM_ACTION;
         }
 
         if (tgt_unitstr) {


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

Reply via email to