Author: cazfi
Date: Mon Feb 22 06:16:25 2016
New Revision: 32017

URL: http://svn.gna.org/viewcvs/freeciv?rev=32017&view=rev
Log:
Corrected savagame conversion from 2.5 to 2.6 format to work when player 
numbers in the savegame
are not consecutive.

See bug #24435

Modified:
    trunk/server/savecompat.c

Modified: trunk/server/savecompat.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savecompat.c?rev=32017&r1=32016&r2=32017&view=diff
==============================================================================
--- trunk/server/savecompat.c   (original)
+++ trunk/server/savecompat.c   Mon Feb 22 06:16:25 2016
@@ -598,8 +598,6 @@
 ****************************************************************************/
 static void compat_load_020600(struct loaddata *loading)
 {
-  int nplayers;
-  int plrno;
   bool team_pooled_research = GAME_DEFAULT_TEAM_POOLED_RESEARCH;
   int tsize;
   int ti;
@@ -820,20 +818,24 @@
     }
   }
 
-  nplayers = secfile_lookup_int_default(loading->file, 0, "players.nplayers");
-
   sg_failure_ret(secfile_lookup_int(loading->file, &tsize, 
"savefile.trait_size"),
                  "Trait size: %s", secfile_error());
 
   turn = secfile_lookup_int_default(loading->file, 0, "game.turn");
 
-  for (plrno = 0; plrno < nplayers; plrno++) {
+  player_slots_iterate(pslot) {
+    int plrno = player_slot_index(pslot);
     bool got_first_city;
     int old_barb_type;
     enum barbarian_type new_barb_type;
     int i;
     const char *name;
     int score;
+    int units_num;
+
+    if (NULL == secfile_section_lookup(loading->file, "player%d", plrno)) {
+      continue;
+    }
 
     /* Renamed 'capital' to 'got_first_city'. */
     if (secfile_lookup_bool(loading->file, &got_first_city, 
@@ -900,14 +902,11 @@
     if (score >= 0) {
       secfile_insert_int(loading->file, score, "score%d.units_lost", plrno);
     }
-  }
-
-  /* Units orders. */
-  for (plrno = 0; plrno < nplayers; plrno++) {
-    int units_num = secfile_lookup_int_default(loading->file, 0,
-                                               "player%d.nunits",
-                                               plrno);
-    int i;
+
+    /* Units orders. */
+    units_num = secfile_lookup_int_default(loading->file, 0,
+                                           "player%d.nunits",
+                                           plrno);
 
     for (i = 0; i < units_num; i++) {
       int len;
@@ -937,7 +936,7 @@
         }
       }
     }
-  }
+  } player_slots_iterate_end;
 
   /* Add specialist order - loading time order is ok here, as we will use
    * that when we in later part of compatibility conversion use the specialist
@@ -961,9 +960,14 @@
   }
 
   /* Replace all city specialist count fields with correct names */
-  for (plrno = 0; plrno < nplayers; plrno++) {
+  player_slots_iterate(pslot) {
+    int plrno = player_slot_index(pslot);
     int ncities;
     int i;
+
+    if (NULL == secfile_section_lookup(loading->file, "player%d", plrno)) {
+      continue;
+    }
 
     ncities = secfile_lookup_int_default(loading->file, 0, "player%d.ncities", 
plrno);
 
@@ -984,7 +988,7 @@
                            plrno, i, k++);
       } specialist_type_iterate_end;
     }
-  }
+  } player_slots_iterate_end;
 
   /* Build [research]. */
   {
@@ -1011,7 +1015,8 @@
       researches[i] = -1;
     }
 
-    for (plrno = 0; plrno < nplayers; plrno++) {
+    player_slots_iterate(pslot) {
+      int plrno = player_slot_index(pslot);
       int ival;
       bool bval;
       const char *sval;
@@ -1077,7 +1082,7 @@
           break;
         }
       }
-    }
+    } player_slots_iterate_end;
     secfile_insert_int(loading->file, count, "research.count");
   }
 
@@ -1104,13 +1109,22 @@
 
   /* Fix save games from Freeciv versions with a bug that made it view
    * "Never met" as closer than "Peace" or "Alliance". */
-  for (plrno = 0; plrno < nplayers; plrno++) {
-    int i;
-
-    for (i = 0; i < nplayers; i++) {
+  player_slots_iterate(pslot) {
+    int plrno = player_slot_index(pslot);
+
+    if (NULL == secfile_section_lookup(loading->file, "player%d", plrno)) {
+      continue;
+    }
+
+    player_slots_iterate(pslot2) {
+      int i = player_slot_index(pslot2);
       char buf[32];
       int current;
       int closest;
+
+      if (NULL == secfile_section_lookup(loading->file, "player%d", i)) {
+        continue;
+      }
 
       fc_snprintf(buf, sizeof(buf), "player%d.diplstate%d", plrno, i);
 
@@ -1137,8 +1151,8 @@
 
         secfile_replace_int(loading->file, current, "%s.max_state", buf);
       }
-    }
-  }
+    } player_slots_iterate_end;
+  } player_slots_iterate_end;
 }
 
 /****************************************************************************


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

Reply via email to