Author: cazfi
Date: Sat Nov 21 11:12:44 2015
New Revision: 30727

URL: http://svn.gna.org/viewcvs/freeciv?rev=30727&view=rev
Log:
Load terrains using terrain mapping in savegame.

See patch #6607

Modified:
    branches/S2_6/common/terrain.h
    branches/S2_6/server/savecompat.c
    branches/S2_6/server/savegame2.c

Modified: branches/S2_6/common/terrain.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/terrain.h?rev=30727&r1=30726&r2=30727&view=diff
==============================================================================
--- branches/S2_6/common/terrain.h      (original)
+++ branches/S2_6/common/terrain.h      Sat Nov 21 11:12:44 2015
@@ -177,7 +177,9 @@
   char graphic_str[MAX_LEN_NAME];      /* add tile_ prefix */
   char graphic_alt[MAX_LEN_NAME];
 
-  char identifier; /* Single-character identifier used in savegames. */
+  char identifier; /* Single-character identifier used in games saved. */
+  char identifier_load; /* Single-character identifier that was used in the 
savegame
+                         * loaded. */
 
 #define TERRAIN_UNKNOWN_IDENTIFIER 'u'
 

Modified: branches/S2_6/server/savecompat.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/savecompat.c?rev=30727&r1=30726&r2=30727&view=diff
==============================================================================
--- branches/S2_6/server/savecompat.c   (original)
+++ branches/S2_6/server/savecompat.c   Sat Nov 21 11:12:44 2015
@@ -560,11 +560,24 @@
   int plrno;
   bool team_pooled_research = GAME_DEFAULT_TEAM_POOLED_RESEARCH;
   int tsize;
+  int ti;
 
   /* Check status and return if not OK (sg_success != TRUE). */
   sg_check_ret();
 
   log_debug("Upgrading data from savegame to version 2.6.0");
+
+  /* Terrain mapping table - use current ruleset as we have no way to know
+   * any other old values. */
+  ti = 0;
+  terrain_type_iterate(pterr) {
+    char buf[2];
+
+    secfile_insert_str(loading->file, terrain_rule_name(pterr), 
"savefile.terrident%d.name", ti);
+    buf[0] = terrain_identifier(pterr);
+    buf[1] = '\0';
+    secfile_insert_str(loading->file, buf, "savefile.terrident%d.identifier", 
ti++);
+  } terrain_type_iterate_end;
 
   /* Server setting migration. */
   {

Modified: branches/S2_6/server/savegame2.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/savegame2.c?rev=30727&r1=30726&r2=30727&view=diff
==============================================================================
--- branches/S2_6/server/savegame2.c    (original)
+++ branches/S2_6/server/savegame2.c    Sat Nov 21 11:12:44 2015
@@ -1442,7 +1442,7 @@
     return T_UNKNOWN;
   }
   terrain_type_iterate(pterrain) {
-    if (pterrain->identifier == ch) {
+    if (pterrain->identifier_load == ch) {
       return pterrain;
     }
   } terrain_type_iterate_end;
@@ -1572,6 +1572,9 @@
 ****************************************************************************/
 static void sg_load_savefile(struct loaddata *loading)
 {
+  int i;
+  const char *terr_name;
+
   /* Check status and return if not OK (sg_success != TRUE). */
   sg_check_ret();
 
@@ -1844,6 +1847,43 @@
 
     free(modname);
   }
+
+    terrain_type_iterate(pterr) {
+    pterr->identifier_load = '\0';
+  } terrain_type_iterate_end;
+
+  i = 0;
+  while ((terr_name = secfile_lookup_str_default(loading->file, NULL,
+                                                 "savefile.terrident%d.name", 
i)) != NULL) {
+    struct terrain *pterr = terrain_by_rule_name(terr_name);
+
+    if (pterr != NULL) {
+      const char *iptr =  secfile_lookup_str_default(loading->file, NULL,
+                                                     
"savefile.terrident%d.identifier", i);
+
+      pterr->identifier_load = *iptr;
+    } else {
+      log_error("Identifier for unknown terrain type %s.", terr_name);
+    }
+    i++;
+  }
+
+  terrain_type_iterate(pterr) {
+    if (pterr->identifier_load == '\0') {
+      /* Use the current identifier for unknown ones. */
+      pterr->identifier_load = pterr->identifier;
+    }
+  } terrain_type_iterate_end;
+
+  terrain_type_iterate(pterr) {
+    terrain_type_iterate(pterr2) {
+      if (pterr != pterr2) {
+        sg_failure_ret((pterr->identifier_load != pterr2->identifier_load),
+                       "%s and %s share a saved identifier",
+                       terrain_rule_name(pterr), terrain_rule_name(pterr2));
+      }
+    } terrain_type_iterate_end;
+  } terrain_type_iterate_end;
 }
 
 /****************************************************************************


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

Reply via email to