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

I'm committing this immediately, as it fixes a bug in soft restart
introduced by PR#39862.  It also addresses some other issues for 2.1.1.

In particular, there are loading error messages that should be LOG_VERBOSE
(and therefore untranslated), while there is a LOG_ERROR that arguably
*should* be translated.  And grammar fixed!  Heck, I've even seen that
message, so it actually is seen from time to time by users....

I re-ordered a few secfile lookups to be grouped with others of the same
section.  It just makes reading the code easier (and may be a step in the
direction of single-pass game loading).

I removed a game.version test against 1.3.0 that can never be false, as it
checked earlier for 1.9.0.

Moreover, as I compared 2.1 with 2.2, I found that most of these old tests
had already been eliminated in 2.1!  Therefore, will be bringing 2.2 up to
2.1 standards....

Index: server/srv_main.c
===================================================================
--- server/srv_main.c   (revision 13992)
+++ server/srv_main.c   (working copy)
@@ -2108,13 +2108,22 @@
   /* Free all the treaties that were left open when game finished. */
   free_treaties();
 
+  /* Free the vision data, without sending updates. */
   players_iterate(pplayer) {
     unit_list_iterate(pplayer->units, punit) {
+      /* don't bother using vision_clear_sight() */
+      vision_layer_iterate(v) {
+        punit->server.vision->radius_sq[v] = -1;
+      } vision_layer_iterate_end;
       vision_free(punit->server.vision);
       punit->server.vision = NULL;
     } unit_list_iterate_end;
 
     city_list_iterate(pplayer->cities, pcity) {
+      /* don't bother using vision_clear_sight() */
+      vision_layer_iterate(v) {
+        pcity->server.vision->radius_sq[v] = -1;
+      } vision_layer_iterate_end;
       vision_free(pcity->server.vision);
       pcity->server.vision = NULL;
     } city_list_iterate_end;
Index: server/savegame.c
===================================================================
--- server/savegame.c   (revision 13992)
+++ server/savegame.c   (working copy)
@@ -140,46 +140,40 @@
  * we let any map data type to be empty, and just print an
  * informative warning message about it.
  */
-#define LOAD_MAP_DATA(ch, nat_y, ptile,                                        
    \
-                     SECFILE_LOOKUP_LINE, SET_XY_CHAR)                     \
-{                                                                           \
-  int _nat_x, _nat_y;                                                      \
-                                                                            \
-  bool _warning_printed = FALSE;                                            \
-  for (_nat_y = 0; _nat_y < map.ysize; _nat_y++) {                         \
-    const int nat_y = _nat_y;                                              \
-    const char *_line = (SECFILE_LOOKUP_LINE);                              \
-                                                                            \
-    if (!_line || strlen(_line) != map.xsize) {                             \
-      if (!_warning_printed) {                                              \
-        /* TRANS: Error message. */                                         \
-        freelog(LOG_ERROR, _("The save file contains incomplete "           \
-                "map data.  This can happen with old saved "                \
-                "games, or it may indicate an invalid saved "               \
-                "game file.  Proceed at your own risk."));                  \
-        if(!_line) {                                                        \
-          /* TRANS: Error message. */                                       \
-          freelog(LOG_ERROR, _("Reason: line not found"));                  \
-        } else {                                                            \
-          /* TRANS: Error message. */                                       \
-          freelog(LOG_ERROR, _("Reason: line too short "                    \
-                  "(expected %d got %lu"), map.xsize,                       \
-                  (unsigned long) strlen(_line));                           \
-        }                                                                   \
-        /* Do not translate.. */                                            \
-        freelog(LOG_ERROR, "secfile_lookup_line='%s'",                      \
-                #SECFILE_LOOKUP_LINE);                                      \
-        _warning_printed = TRUE;                                            \
-      }                                                                     \
-      continue;                                                             \
-    }                                                                       \
-    for (_nat_x = 0; _nat_x < map.xsize; _nat_x++) {                       \
-      const char ch = _line[_nat_x];                                        \
-      struct tile *ptile = native_pos_to_tile(_nat_x, _nat_y);             \
-                                                                            \
-      (SET_XY_CHAR);                                                        \
-    }                                                                       \
-  }                                                                         \
+#define LOAD_MAP_DATA(ch, nat_y, ptile,                                        
\
+                     SECFILE_LOOKUP_LINE, SET_XY_CHAR)                 \
+{                                                                      \
+  int _nat_x, _nat_y;                                                  \
+  bool _printed_warning = FALSE;                                       \
+  for (_nat_y = 0; _nat_y < map.ysize; _nat_y++) {                     \
+    const int nat_y = _nat_y;                                          \
+    const char *_line = (SECFILE_LOOKUP_LINE);                         \
+    if (NULL == _line) {                                               \
+      freelog(LOG_VERBOSE, "Line not found='%s'",                      \
+              #SECFILE_LOOKUP_LINE);                                   \
+      _printed_warning = TRUE;                                         \
+      continue;                                                                
\
+    } else if (strlen(_line) != map.xsize) {                           \
+      freelog(LOG_VERBOSE, "Line too short (expected %d got %lu)='%s'",        
\
+             map.xsize, (unsigned long) strlen(_line),                 \
+              #SECFILE_LOOKUP_LINE);                                   \
+      _printed_warning = TRUE;                                         \
+      continue;                                                                
\
+    }                                                                  \
+    for (_nat_x = 0; _nat_x < map.xsize; _nat_x++) {                   \
+      const char ch = _line[_nat_x];                                   \
+      struct tile *ptile = native_pos_to_tile(_nat_x, _nat_y);         \
+                                                                       \
+      (SET_XY_CHAR);                                                   \
+    }                                                                  \
+  }                                                                    \
+  if (_printed_warning) {                                              \
+    /* TRANS: Minor error message. */                                  \
+    freelog(LOG_ERROR,                                                 \
+           _("Saved game contains incomplete map data.  This can"      \
+           " happen with old saved games, or it may indicate an"       \
+           " invalid saved game file.  Proceed at your own risk."));   \
+  }                                                                    \
 }
 
 /* Iterate on the specials half-bytes */
@@ -2251,8 +2245,7 @@
 
     pcity = create_city_virtual(plr, ptile,
                       secfile_lookup_str(file, "player%d.c%d.name", plrno, i));
-    ptile->owner_source = pcity->tile;
-    tile_set_owner(ptile, city_owner(pcity));
+    tile_set_owner(ptile, plr);
 
     pcity->id=secfile_lookup_int(file, "player%d.c%d.id", plrno, i);
     alloc_id(pcity->id);
@@ -2522,8 +2515,8 @@
                                (pcity->ai.founder_want < 0), 
                                "player%d.c%d.ai.founder_boat", plrno, i);
 
+    /* do after all the set_worker_city() are done. */
     tile_set_city(pcity->tile, pcity);
-
     city_list_append(plr->cities, pcity);
   }
 
@@ -3551,11 +3544,13 @@
   const char* name;
   int civstyle = 0;
 
-  game.version = secfile_lookup_int_default(file, 0, "game.version");
-  tmp_server_state = (enum server_states)
-    secfile_lookup_int_default(file, RUN_GAME_STATE, "game.server_state");
+  /* [savefile] */
+  savefile_options = secfile_lookup_str(file, "savefile.options");
 
-  savefile_options = secfile_lookup_str(file, "savefile.options");
+  /* We don't need savefile.reason, but read it anyway to avoid
+   * warnings about unread secfile entries. */
+  secfile_lookup_str_default(file, "None", "savefile.reason");
+
   if (has_capability("improvement_order", savefile_options)) {
     improvement_order = secfile_lookup_str_vec(file, &improvement_order_size,
                                                "savefile.improvement_order");
@@ -3583,16 +3578,19 @@
     }
   }
 
+  /* [game] */
+  game.version = secfile_lookup_int_default(file, 0, "game.version");
+
   /* we require at least version 1.9.0 */
   if (10900 > game.version) {
+    /* TRANS: Fatal error message. */
     freelog(LOG_FATAL,
-           _("Savegame too old, at least version 1.9.0 required."));
+           _("Saved game is too old, at least version 1.9.0 required."));
     exit(EXIT_FAILURE);
   }
 
-  /* We don't need savefile.reason, but read it anyway to avoid
-   * warnings about unread secfile entries. */
-  secfile_lookup_str_default(file, "None", "savefile.reason");
+  tmp_server_state = (enum server_states)
+    secfile_lookup_int_default(file, RUN_GAME_STATE, "game.server_state");
 
   {
     set_meta_patches_string(secfile_lookup_str_default(file, 
@@ -3713,6 +3711,7 @@
     (void) section_file_lookup(file, "game.rail_prod");
     (void) section_file_lookup(file, "game.rail_trade");
     (void) section_file_lookup(file, "game.farmfood");
+
     civstyle = secfile_lookup_int_default(file, 2, "game.civstyle");
 
     game.info.citymindist  = secfile_lookup_int_default(file,
@@ -3810,8 +3809,9 @@
       if (strcmp("classic",
                 secfile_lookup_str_default(file, "default",
                                            "game.info.t.terrain")) == 0) {
-       freelog(LOG_FATAL, _("The savegame uses the classic terrain "
-                            "ruleset which is no longer supported."));
+       /* TRANS: Fatal error message. */
+       freelog(LOG_FATAL, _("Saved game uses the \"classic\" terrain "
+                            "ruleset, and is no longer supported."));
        exit(EXIT_FAILURE);
       }
 
@@ -3864,7 +3864,7 @@
   script_state_load(file);
 
   {
-    if (game.version >= 10300) {
+    {
       {
        if (!has_capability("startunits", savefile_options)) {
          int settlers = secfile_lookup_int(file, "game.settlers");
@@ -3985,7 +3985,10 @@
 
   map_load(file, special_order);
 
-  if (!game.info.is_new_game) {
+  if (game.info.is_new_game) {
+    /* override previous load */
+    game.info.nplayers = 0;
+  } else {
     /* destroyed wonders: */
     string = secfile_lookup_str_default(file, NULL,
                                         "game.destroyed_wonders_new");
@@ -4028,12 +4031,15 @@
                  improvement_order_size, technology_order,
                  technology_order_size);
     } 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.
+     */
     players_iterate(pplayer) {
-      /* Some players may have invalid nations in the ruleset.  Pick new
-       * nations for them. */
       if (pplayer->nation == NO_NATION_SELECTED) {
        player_set_nation(pplayer, pick_a_nation(NULL, FALSE, TRUE));
-       freelog(LOG_ERROR, "%s had invalid nation; changing to %s.",
+       /* TRANS: Minor error message. */
+       freelog(LOG_ERROR, _("%s had invalid nation; changing to %s."),
                pplayer->name,
                nation_rule_name(nation_of_player(pplayer)));
       }
@@ -4054,6 +4060,7 @@
             && pplayers_allied(plr, aplayer)
             && pplayer_can_make_treaty(plr, aplayer, DS_ALLIANCE) 
                == DIPL_ALLIANCE_PROBLEM) {
+          /* TRANS: Minor error message. */
           freelog(LOG_ERROR, _("Illegal alliance structure detected: "
                   "%s's alliance to %s reduced to peace treaty."),
                   plr->name, aplayer->name);
@@ -4094,6 +4101,7 @@
       pplayer->really_gives_vision = 0;
       pplayer->gives_shared_vision = 0;
     } players_iterate_end;
+
     players_iterate(pplayer) {
       char *vision;
       int plrno = pplayer->player_no;
@@ -4126,8 +4134,6 @@
        check_city(pcity);
       } city_list_iterate_end;
     } players_iterate_end;
-  } else {
-    game.info.nplayers = 0;
   }
 
   if (secfile_lookup_int_default(file, -1,
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to