Author: cazfi
Date: Fri Dec 25 12:55:51 2015
New Revision: 31195

URL: http://svn.gna.org/viewcvs/freeciv?rev=31195&view=rev
Log:
Save resources as part of extras bitvector.

See patch #6716

Modified:
    trunk/common/tile.c
    trunk/server/legacysave.c
    trunk/server/savegame2.c
    trunk/server/savegame3.c

Modified: trunk/common/tile.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/tile.c?rev=31195&r1=31194&r2=31195&view=diff
==============================================================================
--- trunk/common/tile.c (original)
+++ trunk/common/tile.c Fri Dec 25 12:55:51 2015
@@ -354,10 +354,22 @@
 ****************************************************************************/
 void tile_set_resource(struct tile *ptile, struct resource_type *presource)
 {
+  if (presource == ptile->resource) {
+    return; /* No change */
+  }
+
+  if (ptile->resource != NULL) {
+    tile_remove_extra(ptile, ptile->resource->self);
+  }
+  if (presource != NULL) {
+    tile_add_extra(ptile, presource->self);
+  }
+
   ptile->resource = presource;
+
   if (NULL != ptile->terrain
-   && NULL != presource
-   && terrain_has_resource(ptile->terrain, presource)) {
+      && NULL != presource
+      && terrain_has_resource(ptile->terrain, presource)) {
     ptile->resource_valid = TRUE;
   } else {
     ptile->resource_valid = FALSE;

Modified: trunk/server/legacysave.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/legacysave.c?rev=31195&r1=31194&r2=31195&view=diff
==============================================================================
--- trunk/server/legacysave.c   (original)
+++ trunk/server/legacysave.c   Fri Dec 25 12:55:51 2015
@@ -861,6 +861,7 @@
 ****************************************************************************/
 static void set_savegame_old_resource(struct resource_type **r,
                                       const struct terrain *terrain,
+                                      bv_extras *extras,
                                       char ch, int n)
 {
   fc_assert_ret(n == 0 || n == 1);
@@ -876,6 +877,10 @@
     *r = terrain->resources[0];
   } else {
     *r = terrain->resources[1];
+  }
+
+  if ((*r) != NULL) {
+    BV_SET(*extras, extra_index((*r)->self));
   }
 }
 
@@ -962,11 +967,11 @@
                                        ch, default_specials + 12));
     /* Setup resources (from half-bytes 1 and 3 of old savegames) */
     LOAD_MAP_DATA(ch, nat_y, ptile,
-       secfile_lookup_str(file, "map.l%03d", nat_y),
-       set_savegame_old_resource(&ptile->resource, ptile->terrain, ch, 0));
+                  secfile_lookup_str(file, "map.l%03d", nat_y),
+                  set_savegame_old_resource(&ptile->resource, ptile->terrain, 
&ptile->extras, ch, 0));
     LOAD_MAP_DATA(ch, nat_y, ptile,
-       secfile_lookup_str(file, "map.n%03d", nat_y),
-       set_savegame_old_resource(&ptile->resource, ptile->terrain, ch, 1));
+                  secfile_lookup_str(file, "map.n%03d", nat_y),
+                  set_savegame_old_resource(&ptile->resource, ptile->terrain, 
&ptile->extras, ch, 1));
   }
 
   /* after the resources are loaded, indicate those currently valid */
@@ -2788,11 +2793,13 @@
       LOAD_MAP_DATA(ch, vnat_y, ptile,
                     secfile_lookup_str(file, "map.l%03d", vnat_y),
                     set_savegame_old_resource(&map_get_player_tile(ptile, 
plr)->resource,
-                                              ptile->terrain, ch, 0));
+                                              ptile->terrain,
+                                              &map_get_player_tile(ptile, 
plr)->extras, ch, 0));
       LOAD_MAP_DATA(ch, vnat_y, ptile,
                     secfile_lookup_str(file, "map.n%03d", vnat_y),
                     set_savegame_old_resource(&map_get_player_tile(ptile, 
plr)->resource,
-                                              ptile->terrain, ch, 1));
+                                              ptile->terrain,
+                                              &map_get_player_tile(ptile, 
plr)->extras, ch, 1));
     }
 
     if (has_capability("bases", savefile_options)) {

Modified: trunk/server/savegame2.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame2.c?rev=31195&r1=31194&r2=31195&view=diff
==============================================================================
--- trunk/server/savegame2.c    (original)
+++ trunk/server/savegame2.c    Fri Dec 25 12:55:51 2015
@@ -2010,7 +2010,7 @@
   /* Check status and return if not OK (sg_success != TRUE). */
   sg_check_ret();
 
-  LOAD_MAP_CHAR(ch, ptile, ptile->resource = char2resource(ch),
+  LOAD_MAP_CHAR(ch, ptile, tile_set_resource(ptile, char2resource(ch)),
                 loading->file, "map.res%04d");
 
   /* After the resources are loaded, indicate those currently valid. */

Modified: trunk/server/savegame3.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame3.c?rev=31195&r1=31194&r2=31195&view=diff
==============================================================================
--- trunk/server/savegame3.c    (original)
+++ trunk/server/savegame3.c    Fri Dec 25 12:55:51 2015
@@ -347,8 +347,6 @@
 static void sg_save_map_tiles(struct savedata *saving);
 static void sg_load_map_tiles_extras(struct loaddata *loading);
 static void sg_save_map_tiles_extras(struct savedata *saving);
-static void sg_load_map_tiles_resources(struct loaddata *loading);
-static void sg_save_map_tiles_resources(struct savedata *saving);
 
 static void sg_load_map_startpos(struct loaddata *loading);
 static void sg_save_map_startpos(struct savedata *saving);
@@ -2393,11 +2391,6 @@
     sg_load_map_startpos(loading);
     sg_load_map_tiles_extras(loading);
 
-    if (has_capability("specials", loading->secfile_options)) {
-      /* Load resources. */
-      sg_load_map_tiles_resources(loading);
-    }
-
     /* Nothing more needed for a scenario. */
     return;
   }
@@ -2410,7 +2403,6 @@
   sg_load_map_tiles(loading);
   sg_load_map_startpos(loading);
   sg_load_map_tiles_extras(loading);
-  sg_load_map_tiles_resources(loading);
   sg_load_map_known(loading);
   sg_load_map_owner(loading);
   sg_load_map_worked(loading);
@@ -2438,11 +2430,6 @@
   sg_save_map_tiles(saving);
   sg_save_map_startpos(saving);
   sg_save_map_tiles_extras(saving);
-  if (game.map.server.have_resources) {
-    sg_save_savefile_options(saving, " specials");
-    sg_save_map_tiles_resources(saving);
-  }
-
   sg_save_map_owner(saving);
   sg_save_map_worked(saving);
   sg_save_map_known(saving);
@@ -2529,6 +2516,25 @@
     LOAD_MAP_CHAR(ch, ptile, sg_extras_set(&ptile->extras, ch, 
loading->extra.order + 4 * j),
                   loading->file, "map.e%02d_%04d", j);
   } halfbyte_iterate_extras_end;
+
+  if (S_S_INITIAL != loading->server_state
+      || MAPGEN_SCENARIO != game.map.server.generator
+      || has_capability("specials", loading->secfile_options)) {
+    whole_map_iterate(ptile) {
+      extra_type_by_cause_iterate(EC_RESOURCE, pres) {
+        if (tile_has_extra(ptile, pres)) {
+          tile_set_resource(ptile, pres->data.resource);
+
+          if (terrain_has_resource(ptile->terrain, ptile->resource)) {
+            /* cannot use set_special() for internal values */
+            ptile->resource_valid = TRUE;
+          }
+        }
+      } extra_type_by_cause_iterate_end;
+    } whole_map_iterate_end;
+
+    game.map.server.have_resources = TRUE;
+  }
 }
 
 /****************************************************************************
@@ -2538,6 +2544,10 @@
 {
   /* Check status and return if not OK (sg_success != TRUE). */
   sg_check_ret();
+
+  if (game.map.server.have_resources) {
+    sg_save_savefile_options(saving, " specials");
+  }
 
   /* Save extras. */
   halfbyte_iterate_extras(j, game.control.num_extra_types) {
@@ -2554,44 +2564,6 @@
     SAVE_MAP_CHAR(ptile, sg_extras_get(ptile->extras, mod),
                   saving->file, "map.e%02d_%04d", j);
   } halfbyte_iterate_extras_end;
-}
-
-/****************************************************************************
-  Load information about resources on map.
-****************************************************************************/
-static void sg_load_map_tiles_resources(struct loaddata *loading)
-{
-  /* Check status and return if not OK (sg_success != TRUE). */
-  sg_check_ret();
-
-  LOAD_MAP_CHAR(ch, ptile, ptile->resource = char2resource(ch),
-                loading->file, "map.res%04d");
-
-  /* After the resources are loaded, indicate those currently valid. */
-  whole_map_iterate(ptile) {
-    if (NULL == ptile->resource || NULL == ptile->terrain) {
-      continue;
-    }
-
-    if (terrain_has_resource(ptile->terrain, ptile->resource)) {
-      /* cannot use set_special() for internal values */
-      ptile->resource_valid = TRUE;
-    }
-  } whole_map_iterate_end;
-
-  game.map.server.have_resources = TRUE;
-}
-
-/****************************************************************************
-  Load information about resources on map.
-****************************************************************************/
-static void sg_save_map_tiles_resources(struct savedata *saving)
-{
-  /* Check status and return if not OK (sg_success != TRUE). */
-  sg_check_ret();
-
-  SAVE_MAP_CHAR(ptile, resource2char(ptile->resource), saving->file,
-                "map.res%04d");
 }
 
 /****************************************************************************


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

Reply via email to