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

2008/1/19 Chris Williams:
>
> I cannot load saved games using custom ruleset where "tech_leakage" is
> set to a value other than '0' in game.ruleset.

 Fix


 - ML

diff -Nurd -X.diff_ignore freeciv/common/tech.c freeciv/common/tech.c
--- freeciv/common/tech.c       2008-01-22 03:47:26.000000000 +0200
+++ freeciv/common/tech.c       2008-07-02 21:23:44.000000000 +0300
@@ -81,7 +81,15 @@
       return TECH_UNKNOWN;
     }
   } else {
-    return get_player_research(pplayer)->inventions[tech].state;
+    struct player_research *research = get_player_research(pplayer);
+
+    /* Research can be null in client when looking for tech_leakage
+     * from player not yet received. */
+    if (research) {
+      return research->inventions[tech].state;
+    } else {
+      return TECH_UNKNOWN;
+    }
   }
 }
 
diff -Nurd -X.diff_ignore freeciv/server/barbarian.c freeciv/server/barbarian.c
--- freeciv/server/barbarian.c  2008-05-03 11:03:46.000000000 +0300
+++ freeciv/server/barbarian.c  2008-07-02 21:12:47.000000000 +0300
@@ -165,7 +165,7 @@
     barbarians->ai.barbarian_type = SEA_BARBARIAN;
   }
   set_ai_level_directer(barbarians, game.info.skill_level);
-  init_tech(barbarians);
+  init_tech(barbarians, TRUE);
   give_initial_techs(barbarians);
 
   /* Ensure that we are at war with everyone else */
diff -Nurd -X.diff_ignore freeciv/server/savegame.c freeciv/server/savegame.c
--- freeciv/server/savegame.c   2008-05-10 14:29:52.000000000 +0300
+++ freeciv/server/savegame.c   2008-07-02 21:28:42.000000000 +0300
@@ -1921,7 +1921,7 @@
    * reassign nations to players who don't have them. */
 
   /* Add techs from game and nation, but ignore game.info.tech. */
-  init_tech(plr);
+  init_tech(plr, FALSE);
   /* 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. */
@@ -2153,8 +2153,6 @@
                                   "player%d.revolution_finishes", plrno);
   }
 
-  update_research(plr);
-
   for (i = 0; i < game.info.nplayers; i++) {
     plr->diplstates[i].type = 
       secfile_lookup_int_default(file, DS_WAR,
@@ -4036,6 +4034,13 @@
                  technology_order_size);
     } players_iterate_end;
 
+    /* In case of tech_leakage, we can update research only after all
+     * the players have been loaded */
+    players_iterate(pplayer) {
+      /* Mark the reachable techs */
+      update_research(pplayer);
+    } players_iterate_end;
+
     /* Some players may have invalid nations in the ruleset.  Once all 
      * players are loaded, pick one of the remaining nations for them.
      */
diff -Nurd -X.diff_ignore freeciv/server/srv_main.c freeciv/server/srv_main.c
--- freeciv/server/srv_main.c   2008-05-12 01:09:34.000000000 +0300
+++ freeciv/server/srv_main.c   2008-07-02 21:12:38.000000000 +0300
@@ -2064,7 +2064,7 @@
 
     players_iterate(pplayer) {
       player_map_allocate(pplayer);
-      init_tech(pplayer);
+      init_tech(pplayer, TRUE);
       player_limit_to_government_rates(pplayer);
       pplayer->economic.gold = game.info.gold;
     } players_iterate_end;
diff -Nurd -X.diff_ignore freeciv/server/techtools.c freeciv/server/techtools.c
--- freeciv/server/techtools.c  2008-01-15 04:04:13.000000000 +0200
+++ freeciv/server/techtools.c  2008-07-02 21:11:12.000000000 +0300
@@ -575,7 +575,7 @@
 /****************************************************************************
   Initializes tech data for the player.
 ****************************************************************************/
-void init_tech(struct player *plr)
+void init_tech(struct player *plr, bool update)
 {
   tech_type_iterate(i) {
     set_invention(plr, i, TECH_UNKNOWN);
@@ -584,10 +584,12 @@
 
   get_player_research(plr)->techs_researched = 1;
 
-  /* Mark the reachable techs */
-  update_research(plr);
-  if (choose_goal_tech(plr) == A_UNSET) {
-    choose_random_tech(plr);
+  if (update) {
+    /* Mark the reachable techs */
+    update_research(plr);
+    if (choose_goal_tech(plr) == A_UNSET) {
+      choose_random_tech(plr);
+    }
   }
 }
 
diff -Nurd -X.diff_ignore freeciv/server/techtools.h freeciv/server/techtools.h
--- freeciv/server/techtools.h  2007-03-05 19:13:46.000000000 +0200
+++ freeciv/server/techtools.h  2008-07-02 21:12:29.000000000 +0300
@@ -24,7 +24,7 @@
 void found_new_tech(struct player *plr, Tech_type_id tech_found,
                    bool was_discovery, bool saving_bulbs);
 void update_tech(struct player *plr, int bulbs);
-void init_tech(struct player *plr);
+void init_tech(struct player *plr, bool update);
 void choose_tech(struct player *plr, Tech_type_id tech);
 void choose_random_tech(struct player* plr);
 Tech_type_id choose_goal_tech(struct player *plr);
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to