Re: [Freeciv-Dev] (PR#39572) make_history_report() random turn not saved/restored

2007-08-17 Thread William Allen Simpson

http://bugs.freeciv.org/Ticket/Display.html?id=39572 >

Committed trunk revision 13343, S2_1 revision 13344.



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


[Freeciv-Dev] (PR#39572) make_history_report() random turn not saved/restored

2007-08-15 Thread William Allen Simpson

http://bugs.freeciv.org/Ticket/Display.html?id=39572 >

Found another myrand() turn that isn't saved, this time for
make_history_report() in report.c.  Patch for trunk:


Index: server/report.c
===
--- server/report.c (revision 13337)
+++ server/report.c (working copy)
@@ -1054,9 +1054,6 @@
 **/
 void make_history_report(void)
 {
-  static enum historian_type report = HISTORIAN_FIRST;
-  static int time_to_report=20;
-
   if (game.scorelog) {
 log_civ_score();
   }
@@ -1065,20 +1062,14 @@
 return;
   }
 
-  time_to_report--;
-
-  if (time_to_report > 0) {
+  if (game.scoreturn > game.info.turn) {
 return;
   }
 
-  time_to_report=myrand(20) + 20;
+  game.scoreturn = game.info.turn + GAME_DEFAULT_SCORETURN
+ + myrand(GAME_DEFAULT_SCORETURN);
 
-  historian_generic(report);
-  
-  report++;
-  if (report > HISTORIAN_LAST) {
-report = HISTORIAN_FIRST;
-  }
+  historian_generic(game.scoreturn % HISTORIAN_LAST);
 }
 
 /**
Index: server/savegame.c
===
--- server/savegame.c   (revision 13337)
+++ server/savegame.c   (working copy)
@@ -3654,6 +3654,9 @@
 game.info.aifill = secfile_lookup_int_default(file, 0, "game.aifill");
 
 game.scorelog = secfile_lookup_bool_default(file, FALSE, "game.scorelog");
+game.scoreturn =
+  secfile_lookup_int_default(file, game.info.turn + GAME_DEFAULT_SCORETURN,
+  "game.scoreturn");
 sz_strlcpy(game.id, secfile_lookup_str_default(file, "", "game.id"));
 
 game.info.fogofwar = secfile_lookup_bool_default(file, FALSE, 
"game.fogofwar");
@@ -4244,6 +4247,7 @@
   secfile_insert_str(file, game.save_name, "game.save_name");
   secfile_insert_int(file, game.info.aifill, "game.aifill");
   secfile_insert_bool(file, game.scorelog, "game.scorelog");
+  secfile_insert_int(file, game.scoreturn, "game.scoreturn");
   secfile_insert_str(file, game.id, "game.id");
   secfile_insert_bool(file, game.info.fogofwar, "game.fogofwar");
   secfile_insert_bool(file, game.info.spacerace, "game.spacerace");
Index: common/game.c
===
--- common/game.c   (revision 13337)
+++ common/game.c   (working copy)
@@ -287,6 +287,11 @@
 
   game.info.is_new_game   = TRUE;
   game.info.is_edit_mode = FALSE;
+
+  game.info.aifill  = GAME_DEFAULT_AIFILL;
+  sz_strlcpy(game.info.start_units, GAME_DEFAULT_START_UNITS);
+
+  game.fogofwar_old = game.info.fogofwar;
   game.simultaneous_phases_stored = GAME_DEFAULT_SIMULTANEOUS_PHASES;
   game.timeoutint= GAME_DEFAULT_TIMEOUTINT;
   game.timeoutintinc = GAME_DEFAULT_TIMEOUTINTINC;
@@ -294,13 +299,12 @@
   game.timeoutincmult= GAME_DEFAULT_TIMEOUTINCMULT;
   game.timeoutcounter= 1;
   game.timeoutaddenemymove = GAME_DEFAULT_TIMEOUTADDEMOVE; 
+
   game.last_ping = 0;
-  game.info.aifill  = GAME_DEFAULT_AIFILL;
-  sz_strlcpy(game.info.start_units, GAME_DEFAULT_START_UNITS);
+  game.scorelog= GAME_DEFAULT_SCORELOG;
+  game.scoreturn   = GAME_DEFAULT_SCORETURN;
+  game.seed = GAME_DEFAULT_SEED;
 
-  game.seed = GAME_DEFAULT_SEED;
-  game.scorelog= GAME_DEFAULT_SCORELOG;
-  game.fogofwar_old = game.info.fogofwar;
   sz_strlcpy(game.save_name, GAME_DEFAULT_SAVE_NAME);
   sz_strlcpy(game.rulesetdir, GAME_DEFAULT_RULESETDIR);
 
Index: common/game.h
===
--- common/game.h   (revision 13337)
+++ common/game.h   (working copy)
@@ -71,6 +71,7 @@
   int timeoutaddenemymove; /* minimum timeout after an enemy move is seen */
   time_t last_ping;
   struct timer *phase_timer; /* Time since seconds_to_phase_done was set. */
+
   /* The .info.simultaneous_phases value indicates the phase mode currently in
* use.  The "stored" value is a value the player can change; it won't
* take effect until the next turn. */
@@ -82,6 +83,7 @@
   struct conn_list *est_connections;/* all established client conns */
   char save_name[MAX_LEN_NAME];
   bool scorelog;
+  int scoreturn;   /* next make_history_report() */
   int seed;
   bool fogofwar_old;   /* as the fog_of_war bit get changed by setting
   the server we need to remember the old setting */
@@ -278,6 +280,7 @@
 #define GAME_MAX_CIVSTYLE2
 
 #define GAME_DEFAULT_SCORELOGFALSE
+#define GAME_DEFAULT_SCORETURN   20
 
 #define GAME_DEFAULT_SPACERACE   TRUE
 
___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev