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

Those patches were against the 2.1.0b4 source, here's the savegame.c
patch against current revision 12954.

Untested.  It compiles.

--- ../savegame.c       Thu May  3 12:42:30 2007
+++ server/savegame.c   Sun May 13 16:17:45 2007
@@ -2512,6 +2512,19 @@
     pcity->ai.urgency = secfile_lookup_int_default(file, 0, 
                                "player%d.c%d.ai.urgency", plrno, i);
 
+    /* avoid myrand recalculations on subsequent reload. */
+    pcity->ai.next_recalc = secfile_lookup_int_default(file, 0, 
+                               "player%d.c%d.ai.building_turn", plrno, i);
+
+    /* avoid myrand and expensive recalculations on subsequent reload. */
+    pcity->ai.next_founder_want_recalc = secfile_lookup_int_default(file, 0, 
+                               "player%d.c%d.ai.founder_turn", plrno, i);
+    pcity->ai.founder_want = secfile_lookup_int_default(file, 0, 
+                               "player%d.c%d.ai.founder_want", plrno, i);
+    pcity->ai.founder_boat = secfile_lookup_bool_default(file,
+                               (pcity->ai.founder_want < 0), 
+                               "player%d.c%d.ai.founder_boat", plrno, i);
+
     tile_set_city(pcity->tile, pcity);
 
     city_list_append(plr->cities, pcity);
@@ -3254,6 +3267,18 @@
     /* FIXME: remove this when the urgency is properly recalculated. */
     secfile_insert_int(file, pcity->ai.urgency,
                       "player%d.c%d.ai.urgency", plrno, i);
+
+    /* avoid myrand recalculations on subsequent reload. */
+    secfile_insert_int(file, pcity->ai.next_recalc,
+                      "player%d.c%d.ai.building_turn", plrno, i);
+
+    /* avoid myrand and expensive recalculations on subsequent reload. */
+    secfile_insert_int(file, pcity->ai.next_founder_want_recalc,
+                      "player%d.c%d.ai.founder_turn", plrno, i);
+    secfile_insert_int(file, pcity->ai.founder_want,
+                      "player%d.c%d.ai.founder_want", plrno, i);
+    secfile_insert_bool(file, pcity->ai.founder_boat,
+                      "player%d.c%d.ai.founder_boat", plrno, i);
   }
   city_list_iterate_end;
 
@@ -3480,6 +3505,7 @@
 {
   int i, k, id;
   enum server_states tmp_server_state;
+  RANDOM_STATE rstate;
   char *savefile_options;
   const char *string;
   char** improvement_order = NULL;
@@ -3874,7 +3900,6 @@
      2) if it is saved. */
   if (section_file_lookup(file, "random.index_J")
       && secfile_lookup_bool_default(file, TRUE, "game.save_random")) {
-    RANDOM_STATE rstate;
     rstate.j = secfile_lookup_int(file,"random.index_J");
     rstate.k = secfile_lookup_int(file,"random.index_K");
     rstate.x = secfile_lookup_int(file,"random.index_X");
@@ -3897,6 +3922,7 @@
      * be needed later during the load. */
     if (tmp_server_state == RUN_GAME_STATE) {
       init_game_seed();
+      rstate = get_myrand_state();
     }
   }
 
@@ -4076,6 +4102,24 @@
   players_iterate(pplayer) {
     calc_civ_score(pplayer);
   } players_iterate_end;
+
+  /* Recalculate the potential buildings for each city.  
+   * Has caused some problems with game random state. */
+  players_iterate(pplayer) {
+    bool saved_ai_control = pplayer->ai.control;
+
+    /* Recalculate for all players. */
+    pplayer->ai.control = FALSE;
+    ai_manage_buildings(pplayer);
+
+    pplayer->ai.control = saved_ai_control;
+  } players_iterate_end;
+  
+  /* Restore game random state, just in case various initialization code
+   * inexplicably altered the previously existing state. */
+  if (!game.info.is_new_game) {
+    set_myrand_state(rstate);
+  }
 }
 
 /***************************************************************
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to