Re: [Freeciv-Dev] (PR#40027) load saved game error using custom ruleset with tech_leakage set to value other than zero

2008-07-05 Thread Marko Lindqvist

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.0 +0300
+++ freeciv/common/tech.c   2008-07-05 14:48:34.0 +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.0 +0300
+++ freeciv/server/barbarian.c  2008-07-05 14:48:34.0 +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.0 +0300
+++ freeciv/server/savegame.c   2008-07-05 14:51:59.0 +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.0 +0300
+++ freeciv/server/srv_main.c   2008-07-05 14:48:34.0 +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.0 +0300
+++ freeciv/server/techtools.c  2008-07-05 14:51:35.0 +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.0 +0300
+++ freeciv/server/techtools.h  2008-07-05 14:48:34.0 +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 

Re: [Freeciv-Dev] (PR#40027) load saved game error using custom ruleset with tech_leakage set to value other than zero

2008-07-02 Thread Marko Lindqvist

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.0 +0200
+++ freeciv/common/tech.c   2008-07-02 21:23:44.0 +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.0 +0300
+++ freeciv/server/barbarian.c  2008-07-02 21:12:47.0 +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.0 +0300
+++ freeciv/server/savegame.c   2008-07-02 21:28:42.0 +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.0 +0300
+++ freeciv/server/srv_main.c   2008-07-02 21:12:38.0 +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.0 +0200
+++ freeciv/server/techtools.c  2008-07-02 21:11:12.0 +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.0 +0200
+++ freeciv/server/techtools.h  2008-07-02 21:12:29.0 +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


[Freeciv-Dev] (PR#40027) load saved game error using custom ruleset with tech_leakage set to value other than zero

2008-01-19 Thread Chris Williams

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

I cannot load saved games using custom ruleset where tech_leakage is
set to a value other than '0' in game.ruleset. 

Editing game.ruleset so that tech_leakage is zero will allow loading of
old game even though it was started with a different tech_leakage value

Ubuntu 7.10
Gnome 2.20.1
freeciv 2.1.2

gdb result:

Program received signal SIGSEGV, Segmentation fault.
0x080faf60 in get_invention (pplayer=0x8272128, tech=1) at tech.c:72
/home/myusername/freeciv-2.1.2/common/tech.c:72:2376:beg:0x80faf60

There are several other changes in the custom ruleset, but no problems
occur as long as tech_leakage is zero. 

I also duplicated the problem using a copy of the default ruleset with
only tech_leakage altered. 

Thanks,
Chris Williams




___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev