Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2004:
[Freeciv-Dev] (PR#9684) civworld saves core
Home

[Freeciv-Dev] (PR#9684) civworld saves core

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: per@xxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#9684) civworld saves core
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 4 Sep 2004 14:09:29 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=9684 >

In fact the seed is correctly initialized, later, when the game starts.

But because the savegame doesn't include the shuffled player order, the
players are shuffled on loading.  This requires myrand calls, of course,
so the seed is checked.  And this causes the error.

It's still easy to fix, though.  See if this patch does it.

jason

? manual
? manual1.html
? manual2.html
? manual3.html
? manual4.html
? manual5.html
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.183
diff -u -r1.183 savegame.c
--- server/savegame.c   3 Sep 2004 01:21:03 -0000       1.183
+++ server/savegame.c   4 Sep 2004 21:09:07 -0000
@@ -3170,6 +3170,13 @@
   } else {
     /* mark it */
     (void) secfile_lookup_bool_default(file, TRUE, "game.save_random");
+
+    /* We're loading a running game without a seed (which is okay, if it's
+     * a scenario).  We need to generate the game seed now because it will
+     * be needed later during the load. */
+    if (tmp_server_state == RUN_GAME_STATE) {
+      init_game_seed();
+    }
   }
 
 
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.184
diff -u -r1.184 srv_main.c
--- server/srv_main.c   29 Aug 2004 19:03:32 -0000      1.184
+++ server/srv_main.c   4 Sep 2004 21:09:07 -0000
@@ -145,6 +145,22 @@
 static bool has_been_srv_init = FALSE;
 
 /**************************************************************************
+  Initialize the game seed.  This may safely be called multiple times.
+**************************************************************************/
+void init_game_seed(void)
+{
+  if (game.randseed == 0) {
+    /* We strip the high bit for now because neither game file nor
+       server options can handle unsigned ints yet. - Cedric */
+    game.randseed = time(NULL) & (MAX_UINT32 >> 1);
+  }
+ 
+  if (!myrand_is_init()) {
+    mysrand(game.randseed);
+  }
+}
+
+/**************************************************************************
 ...
 **************************************************************************/
 void srv_init(void)
@@ -1681,15 +1697,7 @@
     }
   }
 
-  if (game.randseed == 0) {
-    /* We strip the high bit for now because neither game file nor
-       server options can handle unsigned ints yet. - Cedric */
-    game.randseed = time(NULL) & (MAX_UINT32 >> 1);
-  }
- 
-  if (!myrand_is_init()) {
-    mysrand(game.randseed);
-  }
+  init_game_seed();
 
 #ifdef TEST_RANDOM /* not defined anywhere, set it if you want it */
   test_random1(200);
Index: server/srv_main.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.h,v
retrieving revision 1.22
diff -u -r1.22 srv_main.h
--- server/srv_main.h   3 Sep 2004 04:22:37 -0000       1.22
+++ server/srv_main.h   4 Sep 2004 21:09:07 -0000
@@ -52,6 +52,7 @@
   bool auth_allow_newusers;     /* defaults to TRUE */
 };
 
+void init_game_seed(void);
 void srv_init(void);
 void srv_main(void);
 void server_quit(void);

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