Author: cazfi
Date: Wed Aug 19 21:33:18 2015
New Revision: 29590

URL: http://svn.gna.org/viewcvs/freeciv?rev=29590&view=rev
Log:
Have save_random as scenario property, available in the editor gui, defaulting 
to FALSE.
In case of loading pre-2.6 scenario it's set to TRUE if scenario already has 
random state included. 

See bug #23793

Modified:
    branches/S2_6/client/gui-gtk-2.0/editprop.c
    branches/S2_6/client/gui-gtk-3.0/editprop.c
    branches/S2_6/client/packhand.c
    branches/S2_6/common/game.c
    branches/S2_6/common/game.h
    branches/S2_6/common/packets.def
    branches/S2_6/fc_version
    branches/S2_6/server/edithand.c
    branches/S2_6/server/savegame.c
    branches/S2_6/server/savegame2.c

Modified: branches/S2_6/client/gui-gtk-2.0/editprop.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-2.0/editprop.c?rev=29590&r1=29589&r2=29590&view=diff
==============================================================================
--- branches/S2_6/client/gui-gtk-2.0/editprop.c (original)
+++ branches/S2_6/client/gui-gtk-2.0/editprop.c Wed Aug 19 21:33:18 2015
@@ -357,6 +357,7 @@
   OPID_GAME_SCENARIO,
   OPID_GAME_SCENARIO_NAME,
   OPID_GAME_SCENARIO_DESC,
+  OPID_GAME_SCENARIO_RANDSTATE,
   OPID_GAME_SCENARIO_PLAYERS,
   OPID_GAME_STARTPOS_NATIONS,
   OPID_GAME_PREVENT_CITIES
@@ -1793,6 +1794,9 @@
       case OPID_GAME_SCENARIO_DESC:
         pv->data.v_const_string = pgame->scenario.description;
         break;
+      case OPID_GAME_SCENARIO_RANDSTATE:
+        pv->data.v_bool = pgame->scenario.save_random;
+        break;
       case OPID_GAME_SCENARIO_PLAYERS:
         pv->data.v_bool = pgame->scenario.players;
         break;
@@ -2534,6 +2538,9 @@
         return;
       case OPID_GAME_SCENARIO_DESC:
         sz_strlcpy(packet->scenario_desc, pv->data.v_const_string);
+        return;
+      case OPID_GAME_SCENARIO_RANDSTATE:
+        packet->scenario_random = pv->data.v_bool;
         return;
       case OPID_GAME_SCENARIO_PLAYERS:
         packet->scenario_players = pv->data.v_bool;
@@ -2980,6 +2987,7 @@
   case OPID_UNIT_MOVED:
   case OPID_UNIT_DONE_MOVING:
   case OPID_GAME_SCENARIO:
+  case OPID_GAME_SCENARIO_RANDSTATE:
   case OPID_GAME_SCENARIO_PLAYERS:
   case OPID_GAME_STARTPOS_NATIONS:
   case OPID_GAME_PREVENT_CITIES:
@@ -3189,6 +3197,7 @@
   case OPID_UNIT_MOVED:
   case OPID_UNIT_DONE_MOVING:
   case OPID_GAME_SCENARIO:
+  case OPID_GAME_SCENARIO_RANDSTATE:
   case OPID_GAME_SCENARIO_PLAYERS:
   case OPID_GAME_STARTPOS_NATIONS:
   case OPID_GAME_PREVENT_CITIES:
@@ -4354,6 +4363,8 @@
     ADDPROP(OPID_GAME_SCENARIO_DESC, _("Scenario Description"),
             OPF_IN_LISTVIEW | OPF_HAS_WIDGET | OPF_EDITABLE,
             VALTYPE_STRING);
+    ADDPROP(OPID_GAME_SCENARIO_RANDSTATE, _("Save Random Number State"),
+            OPF_IN_LISTVIEW | OPF_HAS_WIDGET | OPF_EDITABLE, VALTYPE_BOOL);
     ADDPROP(OPID_GAME_SCENARIO_PLAYERS, _("Save Players"), OPF_IN_LISTVIEW
             | OPF_HAS_WIDGET | OPF_EDITABLE, VALTYPE_BOOL);
     ADDPROP(OPID_GAME_STARTPOS_NATIONS, _("Nation Start Positions"),

Modified: branches/S2_6/client/gui-gtk-3.0/editprop.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-3.0/editprop.c?rev=29590&r1=29589&r2=29590&view=diff
==============================================================================
--- branches/S2_6/client/gui-gtk-3.0/editprop.c (original)
+++ branches/S2_6/client/gui-gtk-3.0/editprop.c Wed Aug 19 21:33:18 2015
@@ -357,6 +357,7 @@
   OPID_GAME_SCENARIO,
   OPID_GAME_SCENARIO_NAME,
   OPID_GAME_SCENARIO_DESC,
+  OPID_GAME_SCENARIO_RANDSTATE,
   OPID_GAME_SCENARIO_PLAYERS,
   OPID_GAME_STARTPOS_NATIONS,
   OPID_GAME_PREVENT_CITIES
@@ -1793,6 +1794,9 @@
       case OPID_GAME_SCENARIO_DESC:
         pv->data.v_const_string = pgame->scenario.description;
         break;
+      case OPID_GAME_SCENARIO_RANDSTATE:
+        pv->data.v_bool = pgame->scenario.save_random;
+        break;
       case OPID_GAME_SCENARIO_PLAYERS:
         pv->data.v_bool = pgame->scenario.players;
         break;
@@ -2534,6 +2538,9 @@
         return;
       case OPID_GAME_SCENARIO_DESC:
         sz_strlcpy(packet->scenario_desc, pv->data.v_const_string);
+        return;
+      case OPID_GAME_SCENARIO_RANDSTATE:
+        packet->scenario_random = pv->data.v_bool;
         return;
       case OPID_GAME_SCENARIO_PLAYERS:
         packet->scenario_players = pv->data.v_bool;
@@ -2993,6 +3000,7 @@
   case OPID_UNIT_MOVED:
   case OPID_UNIT_DONE_MOVING:
   case OPID_GAME_SCENARIO:
+  case OPID_GAME_SCENARIO_RANDSTATE:
   case OPID_GAME_SCENARIO_PLAYERS:
   case OPID_GAME_STARTPOS_NATIONS:
   case OPID_GAME_PREVENT_CITIES:
@@ -3204,6 +3212,7 @@
   case OPID_UNIT_MOVED:
   case OPID_UNIT_DONE_MOVING:
   case OPID_GAME_SCENARIO:
+  case OPID_GAME_SCENARIO_RANDSTATE:
   case OPID_GAME_SCENARIO_PLAYERS:
   case OPID_GAME_STARTPOS_NATIONS:
   case OPID_GAME_PREVENT_CITIES:
@@ -4378,6 +4387,8 @@
     ADDPROP(OPID_GAME_SCENARIO_DESC, _("Scenario Description"),
             OPF_IN_LISTVIEW | OPF_HAS_WIDGET | OPF_EDITABLE,
             VALTYPE_STRING);
+    ADDPROP(OPID_GAME_SCENARIO_RANDSTATE, _("Save Random Number State"),
+            OPF_IN_LISTVIEW | OPF_HAS_WIDGET | OPF_EDITABLE, VALTYPE_BOOL);
     ADDPROP(OPID_GAME_SCENARIO_PLAYERS, _("Save Players"), OPF_IN_LISTVIEW
             | OPF_HAS_WIDGET | OPF_EDITABLE, VALTYPE_BOOL);
     ADDPROP(OPID_GAME_STARTPOS_NATIONS, _("Nation Start Positions"),

Modified: branches/S2_6/client/packhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/packhand.c?rev=29590&r1=29589&r2=29590&view=diff
==============================================================================
--- branches/S2_6/client/packhand.c     (original)
+++ branches/S2_6/client/packhand.c     Wed Aug 19 21:33:18 2015
@@ -2832,6 +2832,7 @@
   game.scenario.players = packet->players;
   game.scenario.startpos_nations = packet->startpos_nations;
   game.scenario.prevent_new_cities = packet->prevent_new_cities;
+  game.scenario.save_random = packet->save_random;
   game.scenario.handmade = packet->handmade;
 
   editgui_notify_object_changed(OBJTYPE_GAME, 1, FALSE);

Modified: branches/S2_6/common/game.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/game.c?rev=29590&r1=29589&r2=29590&view=diff
==============================================================================
--- branches/S2_6/common/game.c (original)
+++ branches/S2_6/common/game.c Wed Aug 19 21:33:18 2015
@@ -340,6 +340,7 @@
   game.scenario.startpos_nations = FALSE;
   game.scenario.handmade = FALSE;
   game.scenario.prevent_new_cities = FALSE;
+  game.scenario.save_random = FALSE;
 
   /* Veteran system. */
   game.veteran = NULL;
@@ -410,7 +411,6 @@
     game.server.save_nturns       = GAME_DEFAULT_SAVETURNS;
     game.server.save_options.save_known = TRUE;
     game.server.save_options.save_private_map = TRUE;
-    game.server.save_options.save_random = TRUE;
     game.server.save_options.save_starts = TRUE;
     game.server.savepalace        = GAME_DEFAULT_SAVEPALACE;
     game.server.scorelog          = GAME_DEFAULT_SCORELOG;

Modified: branches/S2_6/common/game.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/game.h?rev=29590&r1=29589&r2=29590&view=diff
==============================================================================
--- branches/S2_6/common/game.h (original)
+++ branches/S2_6/common/game.h Wed Aug 19 21:33:18 2015
@@ -230,8 +230,6 @@
 
       /* used by the map editor to control game_save. */
       struct {
-        bool save_random;
-
         bool save_known; /* loading will just reveal the squares around
                           * cities and units */
         bool save_starts; /* start positions will be auto generated */

Modified: branches/S2_6/common/packets.def
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/packets.def?rev=29590&r1=29589&r2=29590&view=diff
==============================================================================
--- branches/S2_6/common/packets.def    (original)
+++ branches/S2_6/common/packets.def    Wed Aug 19 21:33:18 2015
@@ -1827,6 +1827,7 @@
   STRING description[MAX_LEN_PACKET];
   BOOL   players;
   BOOL   startpos_nations;
+  BOOL   save_random;
   BOOL   prevent_new_cities;
   BOOL   handmade;
 end
@@ -2078,6 +2079,7 @@
   BOOL scenario;
   STRING scenario_name[256];
   STRING scenario_desc[MAX_LEN_PACKET];
+  BOOL scenario_random;
   BOOL scenario_players;
   BOOL startpos_nations;
   BOOL prevent_new_cities;

Modified: branches/S2_6/fc_version
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/fc_version?rev=29590&r1=29589&r2=29590&view=diff
==============================================================================
--- branches/S2_6/fc_version    (original)
+++ branches/S2_6/fc_version    Wed Aug 19 21:33:18 2015
@@ -54,7 +54,7 @@
 #   - Avoid adding a new mandatory capability to the development branch for
 #     as long as possible.  We want to maintain network compatibility with
 #     the stable branch for as long as possible.
-NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-2.6-2015.Aug.14"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-2.6-2015.Aug.19"
 NETWORK_CAPSTRING_OPTIONAL=""
 
 FREECIV_DISTRIBUTOR=""

Modified: branches/S2_6/server/edithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/edithand.c?rev=29590&r1=29589&r2=29590&view=diff
==============================================================================
--- branches/S2_6/server/edithand.c     (original)
+++ branches/S2_6/server/edithand.c     Wed Aug 19 21:33:18 2015
@@ -1561,6 +1561,11 @@
     changed = TRUE;
   }
 
+  if (packet->scenario_random != game.scenario.save_random) {
+    game.scenario.save_random = packet->scenario_random;
+    changed = TRUE;
+  }
+
   if (packet->scenario_players != game.scenario.players) {
     game.scenario.players = packet->scenario_players;
     changed = TRUE;

Modified: branches/S2_6/server/savegame.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/savegame.c?rev=29590&r1=29589&r2=29590&view=diff
==============================================================================
--- branches/S2_6/server/savegame.c     (original)
+++ branches/S2_6/server/savegame.c     Wed Aug 19 21:33:18 2015
@@ -3803,6 +3803,17 @@
                        "%s", secfile_error());
     fc_assert_exit_msg(secfile_lookup_int(file, &rstate.x, "random.index_X"),
                        "%s", secfile_error());
+
+    /* Since random state was previously saved, save it also when resaving.
+     *
+     * Do NOT touch this in case of regular savegame. They always have random
+     * saved, but if one starts to make scenario based on a savegame, we want
+     * default scenario settings in the beginning (default save_random = 
FALSE).
+     */
+    if (game.scenario.is_scenario) {
+      game.scenario.save_random = TRUE;
+    }
+
     for (i = 0; i < 8; i++) {
       string = secfile_lookup_str(file, "random.table%d",i);
       fc_assert(NULL != string);

Modified: branches/S2_6/server/savegame2.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/savegame2.c?rev=29590&r1=29589&r2=29590&view=diff
==============================================================================
--- branches/S2_6/server/savegame2.c    (original)
+++ branches/S2_6/server/savegame2.c    Wed Aug 19 21:33:18 2015
@@ -2291,6 +2291,20 @@
     const char *string;
     int i;
 
+    /* Since random state was previously saved, save it also when resaving.
+     * This affects only pre-2.6 scenarios where scenario.save_random
+     * is not defined.
+     * - If this is 2.6 or later scenario -> it would have saved random.save = 
TRUE
+     *   only if scenario.save_random is already TRUE
+     *
+     * Do NOT touch this in case of regular savegame. They always have 
random.save
+     * set, but if one starts to make scenario based on a savegame, we want
+     * default scenario settings in the beginning (default save_random = 
FALSE).
+     */
+    if (game.scenario.is_scenario) {
+      game.scenario.save_random = TRUE;
+    }
+
     sg_failure_ret(secfile_lookup_int(loading->file, &loading->rstate.j,
                                       "random.index_J"), "%s", 
secfile_error());
     sg_failure_ret(secfile_lookup_int(loading->file, &loading->rstate.k,
@@ -2328,7 +2342,7 @@
   /* Check status and return if not OK (sg_success != TRUE). */
   sg_check_ret();
 
-  if (fc_rand_is_init() && game.server.save_options.save_random) {
+  if (fc_rand_is_init() && (!saving->scenario || game.scenario.save_random)) {
     int i;
     RANDOM_STATE rstate = fc_rand_state();
 
@@ -2417,6 +2431,8 @@
     } else {
       game.scenario.description[0] = '\0';
     }
+    game.scenario.save_random
+      = secfile_lookup_bool_default(loading->file, FALSE, 
"scenario.save_random");
     game.scenario.players
       = secfile_lookup_bool_default(loading->file, TRUE, "scenario.players");
     game.scenario.startpos_nations
@@ -2465,6 +2481,7 @@
   secfile_insert_str(saving->file, game.scenario.name, "scenario.name");
   secfile_insert_str(saving->file, game.scenario.description,
                      "scenario.description");
+  secfile_insert_bool(saving->file, game.scenario.save_random, 
"scenario.save_random");
   secfile_insert_bool(saving->file, game.scenario.players, "scenario.players");
   secfile_insert_bool(saving->file, game.scenario.startpos_nations,
                       "scenario.startpos_nations");


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to