Author: cazfi
Date: Sun Jan 25 10:47:42 2015
New Revision: 27837

URL: http://svn.gna.org/viewcvs/freeciv?rev=27837&view=rev
Log:
Do not save settings that should take load-time default value to scenarios

See patch #5742

Modified:
    branches/S2_6/server/savegame2.c
    branches/S2_6/server/settings.c
    branches/S2_6/server/settings.h

Modified: branches/S2_6/server/savegame2.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/savegame2.c?rev=27837&r1=27836&r2=27837&view=diff
==============================================================================
--- branches/S2_6/server/savegame2.c    (original)
+++ branches/S2_6/server/savegame2.c    Sun Jan 25 10:47:42 2015
@@ -2434,7 +2434,7 @@
   if (saving->scenario) {
     map.server.generator = MAPGEN_SCENARIO; /* We want a scenario. */
   }
-  settings_game_save(saving->file, "settings");
+  settings_game_save(saving->file, "settings", saving->scenario);
   /* Restore real map generator. */
   map.server.generator = real_generator;
 

Modified: branches/S2_6/server/settings.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/settings.c?rev=27837&r1=27836&r2=27837&view=diff
==============================================================================
--- branches/S2_6/server/settings.c     (original)
+++ branches/S2_6/server/settings.c     Sun Jan 25 10:47:42 2015
@@ -3851,50 +3851,61 @@
 /********************************************************************
   Save game settings.
 *********************************************************************/
-void settings_game_save(struct section_file *file, const char *section)
+void settings_game_save(struct section_file *file, const char *section,
+                        bool scenario)
 {
   int set_count = 0;
 
   settings_iterate(SSET_ALL, pset) {
-    secfile_insert_str(file, setting_name(pset),
-                       "%s.set%d.name", section, set_count);
-    switch (setting_type(pset)) {
-    case SSET_BOOL:
-      secfile_insert_bool(file, *pset->boolean.pvalue,
-                          "%s.set%d.value", section, set_count);
-      secfile_insert_bool(file, pset->boolean.game_value,
-                          "%s.set%d.gamestart", section, set_count);
-      break;
-    case SSET_INT:
-      secfile_insert_int(file, *pset->integer.pvalue,
-                          "%s.set%d.value", section, set_count);
-      secfile_insert_int(file, pset->integer.game_value,
-                          "%s.set%d.gamestart", section, set_count);
-      break;
-    case SSET_STRING:
-      secfile_insert_str(file, pset->string.value,
-                          "%s.set%d.value", section, set_count);
-      secfile_insert_str(file, pset->string.game_value,
-                          "%s.set%d.gamestart", section, set_count);
-      break;
-    case SSET_ENUM:
-      secfile_insert_enum_data(file, read_enum_value(pset), FALSE,
-                               setting_enum_secfile_str, pset,
-                               "%s.set%d.value", section, set_count);
-      secfile_insert_enum_data(file, pset->enumerator.game_value, FALSE,
-                               setting_enum_secfile_str, pset,
-                               "%s.set%d.gamestart", section, set_count);
-      break;
-    case SSET_BITWISE:
-      secfile_insert_enum_data(file, *pset->bitwise.pvalue, TRUE,
-                               setting_bitwise_secfile_str, pset,
-                               "%s.set%d.value", section, set_count);
-      secfile_insert_enum_data(file, pset->bitwise.game_value, TRUE,
-                               setting_bitwise_secfile_str, pset,
-                               "%s.set%d.gamestart", section, set_count);
-      break;
+    char errbuf[200];
+
+    if ( /* Normal save always has all settings saved */
+        !scenario
+         /* It's explicitly set to some value to save */
+        || setting_is_changed(pset)
+         /* It must be same at loading time as it was saving time, even if
+          * freeciv's default has changed. */
+        || !setting_is_changeable(pset, NULL, errbuf, sizeof(errbuf))) {
+      secfile_insert_str(file, setting_name(pset),
+                         "%s.set%d.name", section, set_count);
+      switch (setting_type(pset)) {
+      case SSET_BOOL:
+        secfile_insert_bool(file, *pset->boolean.pvalue,
+                            "%s.set%d.value", section, set_count);
+        secfile_insert_bool(file, pset->boolean.game_value,
+                            "%s.set%d.gamestart", section, set_count);
+        break;
+      case SSET_INT:
+        secfile_insert_int(file, *pset->integer.pvalue,
+                           "%s.set%d.value", section, set_count);
+        secfile_insert_int(file, pset->integer.game_value,
+                           "%s.set%d.gamestart", section, set_count);
+        break;
+      case SSET_STRING:
+        secfile_insert_str(file, pset->string.value,
+                           "%s.set%d.value", section, set_count);
+        secfile_insert_str(file, pset->string.game_value,
+                           "%s.set%d.gamestart", section, set_count);
+        break;
+      case SSET_ENUM:
+        secfile_insert_enum_data(file, read_enum_value(pset), FALSE,
+                                 setting_enum_secfile_str, pset,
+                                 "%s.set%d.value", section, set_count);
+        secfile_insert_enum_data(file, pset->enumerator.game_value, FALSE,
+                                 setting_enum_secfile_str, pset,
+                                 "%s.set%d.gamestart", section, set_count);
+        break;
+      case SSET_BITWISE:
+        secfile_insert_enum_data(file, *pset->bitwise.pvalue, TRUE,
+                                 setting_bitwise_secfile_str, pset,
+                                 "%s.set%d.value", section, set_count);
+        secfile_insert_enum_data(file, pset->bitwise.game_value, TRUE,
+                                 setting_bitwise_secfile_str, pset,
+                                 "%s.set%d.gamestart", section, set_count);
+        break;
+      }
+      set_count++;
     }
-    set_count++;
   } settings_iterate_end;
 
   secfile_insert_int(file, set_count, "%s.set_count", section);
@@ -4513,6 +4524,14 @@
 }
 
 /*****************************************************************************
+  Is the setting in changed state, or the default
+*****************************************************************************/
+bool setting_is_changed(struct setting *pset)
+{
+  return pset->changed;
+}
+
+/*****************************************************************************
   Compatibility function. In the very old times there was no concept of
   'default' value outside setting initialization, all values were handled
   like we now want to handle non-default ones.

Modified: branches/S2_6/server/settings.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/settings.h?rev=27837&r1=27836&r2=27837&view=diff
==============================================================================
--- branches/S2_6/server/settings.h     (original)
+++ branches/S2_6/server/settings.h     Sun Jan 25 10:47:42 2015
@@ -189,7 +189,8 @@
 }
 
 void settings_game_start(void);
-void settings_game_save(struct section_file *file, const char *section);
+void settings_game_save(struct section_file *file, const char *section,
+                        bool scenario);
 void settings_game_load(struct section_file *file, const char *section);
 bool settings_game_reset(void);
 
@@ -210,6 +211,7 @@
 void send_server_setting_control(struct connection *pconn);
 
 void setting_changed(struct setting *pset);
+bool setting_is_changed(struct setting *pset);
 void settings_consider_all_changed(void);
 
 #ifdef __cplusplus


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

Reply via email to