Author: sveinung
Date: Mon May  1 16:30:13 2017
New Revision: 35348

URL: http://svn.gna.org/viewcvs/freeciv?rev=35348&view=rev
Log:
Use the savegame's action order.

This makes it possible to change the order of the actions without breaking
savegames where a unit has an order to go to a tile and perform some action.

See hrm Feature #655693

Modified:
    trunk/server/savecompat.h
    trunk/server/savegame3.c

Modified: trunk/server/savecompat.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savecompat.h?rev=35348&r1=35347&r2=35348&view=diff
==============================================================================
--- trunk/server/savecompat.h   (original)
+++ trunk/server/savecompat.h   Mon May  1 16:30:13 2017
@@ -109,6 +109,11 @@
   } ds_t;
   /* loaded in sg_load_savefile(); needed in sg_load_player_unit(), ... */
   struct {
+    enum gen_action *order;
+    size_t size;
+  } action;
+  /* loaded in sg_load_savefile(); needed in sg_load_player_unit(), ... */
+  struct {
     enum action_decision *order;
     size_t size;
   } act_dec;

Modified: trunk/server/savegame3.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame3.c?rev=35348&r1=35347&r2=35348&view=diff
==============================================================================
--- trunk/server/savegame3.c    (original)
+++ trunk/server/savegame3.c    Mon May  1 16:30:13 2017
@@ -581,6 +581,8 @@
   loading->multiplier.size = -1;
   loading->specialist.order = NULL;
   loading->specialist.size = -1;
+  loading->action.order = NULL;
+  loading->action.size = -1;
   loading->act_dec.order = NULL;
   loading->act_dec.size = -1;
 
@@ -622,6 +624,10 @@
 
   if (loading->specialist.order != NULL) {
     free(loading->specialist.order);
+  }
+
+  if (loading->action.order != NULL) {
+    free(loading->action.order);
   }
 
   if (loading->act_dec.order != NULL) {
@@ -1461,6 +1467,38 @@
     for (; j < nmod; j++) {
       loading->specialist.order[j] = NULL;
     }
+  }
+
+  /* Load action order. */
+  loading->action.size = secfile_lookup_int_default(loading->file, 0,
+                                                    "savefile.action_size");
+
+  sg_failure_ret(loading->action.size > 0,
+                 "Failed to load action order: %s",
+                 secfile_error());
+
+  if (loading->action.size) {
+    const char **modname;
+    int j;
+
+    modname = secfile_lookup_str_vec(loading->file, &loading->action.size,
+                                     "savefile.action_vector");
+
+    loading->action.order = fc_calloc(loading->action.size,
+                                      sizeof(*loading->action.order));
+
+    for (j = 0; j < loading->action.size; j++) {
+      struct action *real_action = action_by_rule_name(modname[j]);
+
+      if (real_action) {
+        loading->action.order[j] = real_action->id;
+      } else {
+        log_sg("Unknown action \'%s\'", modname[j]);
+        loading->action.order[j] = ACTION_NONE;
+      }
+    }
+
+    free(modname);
   }
 
   /* Load action decision order. */
@@ -5440,14 +5478,25 @@
         order->dir = char2dir(dir_unitstr[j]);
         order->activity = char2activity(act_unitstr[j]);
 
-        order->action = (
+        if (
 #ifdef FREECIV_DEV_SAVE_COMPAT_3_0
                          action_unitstr[0] == '\0'
                          ||
 #endif /* FREECIV_DEV_SAVE_COMPAT_3_0 */
-                         action_unitstr[j] == '?'
-                         ? ACTION_NONE
-                         : char2num(action_unitstr[j]));
+                         action_unitstr[j] == '?') {
+          order->action = ACTION_NONE;
+        } else {
+          unconverted = char2num(action_unitstr[j]);
+
+          if (unconverted >= 0 && unconverted < loading->action.size) {
+            /* Look up what action id the unconverted number represents. */
+            order->action = loading->action.order[unconverted];
+          } else {
+            log_sg("Invalid action id in order for unit %d", punit->id);
+
+            order->action = ACTION_NONE;
+          }
+        }
 
 #ifdef FREECIV_DEV_SAVE_COMPAT_3_0
         if (order->order != ORDER_PERFORM_ACTION


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

Reply via email to