Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2005:
[Freeciv-Dev] (PR#14318) Savegame compatibility in 2.1
Home

[Freeciv-Dev] (PR#14318) Savegame compatibility in 2.1

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: himasaram@xxxxxxxx
Subject: [Freeciv-Dev] (PR#14318) Savegame compatibility in 2.1
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 14 Oct 2005 21:43:49 -0700
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=14318 >

The problem is the observer nation was removed, so although observer
players are handled correctly the server can't handle a missing nation.

This patch fixes it.  I had to remove give_initial_techs since this
crashes if there's no nation.  This shouldn't have any impact on
behavior however.

-jason


Index: server/savegame.c
===================================================================
--- server/savegame.c   (revision 11131)
+++ server/savegame.c   (working copy)
@@ -1659,15 +1659,14 @@
     }
   }
   plr->nation = find_nation_by_name_orig(p);
-  if (plr->nation == NO_NATION_SELECTED) {
-    freelog(LOG_FATAL, _("Nation %s (used by %s) isn't available."),
-           p, plr->name);
-    exit(EXIT_FAILURE);
-  }
+  /* Nation may be unselected at this point; we check for this later and
+   * reassign nations to players who don't have them. */
 
   /* Add techs from game and nation, but ignore game.info.tech. */
   init_tech(plr);
-  give_initial_techs(plr);
+  /* We used to call give_initial_techs here, but that shouldn't be
+   * necessary.  The savegame should already mark those techs as known.
+   * give_initial_techs will crash if the nation is unset. */
 
   if (is_barbarian(plr) && plr->nation == NO_NATION_SELECTED) {
     plr->nation = pick_barbarian_nation();
@@ -3557,11 +3556,20 @@
       }
     }
 
-    for (i = 0; i < game.info.nplayers; i++) {
-      player_load(&game.players[i], i, file, improvement_order,
+    players_iterate(pplayer) {
+      player_load(pplayer, pplayer->player_no, file, improvement_order,
                  improvement_order_size, technology_order,
                  technology_order_size); 
-    }
+    } players_iterate_end;
+    players_iterate(pplayer) {
+      /* Some players may have invalid nations in the ruleset.  Pick new
+       * nations for them. */
+      if (pplayer->nation == NO_NATION_SELECTED) {
+       player_set_nation(pplayer, pick_a_nation(NULL, FALSE, TRUE));
+       freelog(LOG_NORMAL, "%s had invalid nation; changing to %s.",
+               pplayer->name, pplayer->nation->name);
+      }
+    } players_iterate_end;
 
     /* Assign players with no team listed onto an empty team. */
     players_iterate(pplayer) {

[Prev in Thread] Current Thread [Next in Thread]