Author: cazfi
Date: Mon Dec 15 22:30:10 2014
New Revision: 27311

URL: http://svn.gna.org/viewcvs/freeciv?rev=27311&view=rev
Log:
Fixed loading of 2.5 or older format savegames.

Reported by Andreas Røsdal <andreasr>

See bug #23068

Modified:
    trunk/server/savecompat.c

Modified: trunk/server/savecompat.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savecompat.c?rev=27311&r1=27310&r2=27311&view=diff
==============================================================================
--- trunk/server/savecompat.c   (original)
+++ trunk/server/savecompat.c   Mon Dec 15 22:30:10 2014
@@ -557,7 +557,7 @@
 static void compat_load_020600(struct loaddata *loading)
 {
   int nplayers;
-  int i;
+  int plrno;
   bool team_pooled_research = GAME_DEFAULT_TEAM_POOLED_RESEARCH;
 
   /* Check status and return if not OK (sg_success != TRUE). */
@@ -751,11 +751,12 @@
     }
   }
 
-  player_slots_iterate(pslot) {
+  nplayers = secfile_lookup_int_default(loading->file, 0, "players.nplayers");
+
+  for (plrno = 0; plrno < nplayers; plrno++) {
     bool got_first_city;
     int old_barb_type;
     enum barbarian_type new_barb_type;
-    int plrno = player_slot_index(pslot);
 
     /* Renamed 'capital' to 'got_first_city'. */
     if (secfile_lookup_bool(loading->file, &got_first_city, 
@@ -770,27 +771,27 @@
     new_barb_type = barb_type_convert(old_barb_type);
     secfile_insert_str(loading->file, barbarian_type_name(new_barb_type),
                        "player%d.ai.barb_type", plrno);
-  } player_slots_iterate_end;
+  }
 
   /* Units orders. */
-  player_slots_iterate(pslot) {
-    int player_idx = player_slot_index(pslot);
+  for (plrno = 0; plrno < nplayers; plrno++) {
     int units_num = secfile_lookup_int_default(loading->file, 0,
                                                "player%d.nunits",
-                                               player_idx);
+                                               plrno);
+    int i;
 
     for (i = 0; i < units_num; i++) {
       int len;
 
       if (secfile_lookup_bool_default(loading->file, FALSE,
                                       "player%d.u%d.orders_last_move_safe",
-                                      player_idx, i)) {
+                                      plrno, i)) {
         continue;
       }
 
       len = secfile_lookup_int_default(loading->file, 0,
                                        "player%d.u%d.orders_length",
-                                       player_idx, i);
+                                       plrno, i);
       if (len > 0) {
         char orders_str[len + 1];
         char *p;
@@ -798,16 +799,16 @@
         sz_strlcpy(orders_str,
                    secfile_lookup_str_default(loading->file, "",
                                               "player%d.u%d.orders_list",
-                                              player_idx, i));
+                                              plrno, i));
         if ((p = strrchr(orders_str, 'm'))
             || (p = strrchr(orders_str, 'M'))) {
           *p = 'x'; /* ORDER_MOVE -> ORDER_ACTION_MOVE */
           secfile_replace_str(loading->file, orders_str,
-                              "player%d.u%d.orders_list", player_idx, i);
-        }
-      }
-    }
-  } player_slots_iterate_end;
+                              "player%d.u%d.orders_list", plrno, i);
+        }
+      }
+    }
+  }
 
   /* 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
@@ -831,15 +832,13 @@
   }
 
   /* Replace all city specialist count fields with correct names */
-  nplayers = secfile_lookup_int_default(loading->file, 0, "players.nplayers");
-
-  for (i = 0; i < nplayers; i++) {
+  for (plrno = 0; plrno < nplayers; plrno++) {
     int ncities;
-    int j;
-
-    ncities = secfile_lookup_int(loading->file, &ncities, "player%d.ncities", 
i);
-
-    for (j = 0; j < ncities; j++) {
+    int i;
+
+    ncities = secfile_lookup_int(loading->file, &ncities, "player%d.ncities", 
plrno);
+
+    for (i = 0; i < ncities; i++) {
       int k = 0;
 
       specialist_type_iterate(sp) {
@@ -848,12 +847,12 @@
 
         sg_failure_ret(secfile_lookup_int(loading->file, &count,
                                           "player%d.c%d.n%s",
-                                          i, j, specialist_rule_name(psp)),
+                                          plrno, i, specialist_rule_name(psp)),
                        "specialist error: %s", secfile_error());
         secfile_entry_delete(loading->file, "player%d.c%d.n%s",
-                             i, j, specialist_rule_name(psp));
+                             plrno, i, specialist_rule_name(psp));
         secfile_insert_int(loading->file, count, "player%d.c%d.nspe%d",
-                           i, j, k++);
+                           plrno, i, k++);
       } specialist_type_iterate_end;
     }
   }
@@ -877,17 +876,17 @@
 
     int researches[MAX(player_slot_count(), team_slot_count())];
     int count = 0;
-    int j;
+    int i;
 
     for (i = 0; i < ARRAY_SIZE(researches); i++) {
       researches[i] = -1;
     }
 
-    player_slots_iterate(pslot) {
-      int plrno = player_slot_index(pslot);
+    for (plrno = 0; plrno < nplayers; plrno++) {
       int ival;
       bool bval;
       const char *sval;
+      int j;
 
       if (secfile_section_lookup(loading->file, "player%d", plrno) == NULL) {
         continue;
@@ -942,7 +941,7 @@
           break;
         }
       }
-    } player_slots_iterate_end;
+    }
     secfile_insert_int(loading->file, count, "research.count");
   }
 }


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

Reply via email to