Author: sveinung
Date: Mon May  1 17:24:01 2017
New Revision: 35350

URL: http://svn.gna.org/viewcvs/freeciv?rev=35350&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:
    branches/S3_0/server/savecompat.h
    branches/S3_0/server/savegame3.c

Modified: branches/S3_0/server/savecompat.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S3_0/server/savecompat.h?rev=35350&r1=35349&r2=35350&view=diff
==============================================================================
--- branches/S3_0/server/savecompat.h   (original)
+++ branches/S3_0/server/savecompat.h   Mon May  1 17:24:01 2017
@@ -102,6 +102,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: branches/S3_0/server/savegame3.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S3_0/server/savegame3.c?rev=35350&r1=35349&r2=35350&view=diff
==============================================================================
--- branches/S3_0/server/savegame3.c    (original)
+++ branches/S3_0/server/savegame3.c    Mon May  1 17:24:01 2017
@@ -579,6 +579,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;
 
@@ -616,6 +618,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) {
@@ -1442,6 +1448,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. */
@@ -5420,14 +5458,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