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

2008/7/2 Marko Lindqvist:
> 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

 S2_2 / TRUNK version


 - ML

diff -Nurd -X.diff_ignore freeciv/common/tech.c freeciv/common/tech.c
--- freeciv/common/tech.c       2008-06-18 18:49:36.000000000 +0300
+++ freeciv/common/tech.c       2008-07-05 14:48:34.000000000 +0300
@@ -125,7 +125,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-04 16:48:15.000000000 +0300
+++ freeciv/server/barbarian.c  2008-07-05 14:48:34.000000000 +0300
@@ -136,7 +136,7 @@
   barbarians->ai.control = TRUE;
   barbarians->ai.barbarian_type = type;
   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-07-03 21:58:06.000000000 +0300
+++ freeciv/server/savegame.c   2008-07-05 14:51:59.000000000 +0300
@@ -1829,7 +1829,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. */
@@ -2081,8 +2081,6 @@
                                   "player%d.revolution_finishes", plrno);
   }
 
-  player_research_update(plr);
-
   for (i = 0; i < player_count(); i++) {
     plr->diplstates[i].type = 
       secfile_lookup_int_default(file, DS_WAR,
@@ -4328,6 +4326,13 @@
       player_load_attributes(pplayer, n, file);
     } 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 */
+      player_research_update(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-07-03 21:58:05.000000000 +0300
+++ freeciv/server/srv_main.c   2008-07-05 14:48:34.000000000 +0300
@@ -2073,7 +2073,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-06-18 18:49:38.000000000 +0300
+++ freeciv/server/techtools.c  2008-07-05 14:51:35.000000000 +0300
@@ -574,7 +574,7 @@
 /****************************************************************************
   Initializes tech data for the player.
 ****************************************************************************/
-void init_tech(struct player *plr)
+void init_tech(struct player *plr, bool update)
 {
   player_invention_set(plr, A_NONE, TECH_KNOWN);
 
@@ -584,10 +584,12 @@
 
   get_player_research(plr)->techs_researched = 1;
 
-  /* Mark the reachable techs */
-  player_research_update(plr);
-  if (choose_goal_tech(plr) == A_UNSET) {
-    choose_random_tech(plr);
+  if (update) {
+    /* Mark the reachable techs */
+    player_research_update(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-09-14 14:44:25.000000000 +0300
+++ freeciv/server/techtools.h  2008-07-05 14:48:34.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