Author: sveinung
Date: Tue Mar 22 06:07:40 2016
New Revision: 32263

URL: http://svn.gna.org/viewcvs/freeciv?rev=32263&view=rev
Log:
Fix invalid resource saving.

An invalid resource is illegal at a tile's current terrain. It will appear
if the terrain is changed to something it can exist on.

See bug #24534

Modified:
    trunk/server/savegame3.c

Modified: trunk/server/savegame3.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame3.c?rev=32263&r1=32262&r2=32263&view=diff
==============================================================================
--- trunk/server/savegame3.c    (original)
+++ trunk/server/savegame3.c    Tue Mar 22 06:07:40 2016
@@ -302,7 +302,8 @@
 static void unit_ordering_calc(void);
 static void unit_ordering_apply(void);
 static void sg_extras_set(bv_extras *extras, char ch, struct extra_type 
**index);
-static char sg_extras_get(bv_extras extras, const int *index);
+static char sg_extras_get(bv_extras extras, struct resource_type *presource,
+                          const int *index);
 static struct resource_type *char2resource(char c);
 static char resource2char(const struct resource_type *presource);
 static char num2char(unsigned int num);
@@ -1108,7 +1109,8 @@
   Extras are packed in four to a character in hex notation. 'index'
   specifies which set of extras are included in this character.
 ****************************************************************************/
-static char sg_extras_get(bv_extras extras, const int *index)
+static char sg_extras_get(bv_extras extras, struct resource_type *presource,
+                          const int *index)
 {
   int i, bin = 0;
 
@@ -1119,7 +1121,13 @@
       break;
     }
 
-    if (BV_ISSET(extras, extra)) {
+    if (BV_ISSET(extras, extra)
+        /* An invalid resource, a resource that can't exist at the tile's
+         * current terrain, isn't in the bit extra vector. Save it so it
+         * can return if the tile's terrain changes to something it can
+         * exits on. */
+        || (extra_by_number(extra)->data.resource != NULL
+            && extra_by_number(extra)->data.resource == presource)) {
       bin |= (1 << i);
     }
   }
@@ -2517,7 +2525,7 @@
         mod[l] = 4 * j + l;
       }
     }
-    SAVE_MAP_CHAR(ptile, sg_extras_get(ptile->extras, mod),
+    SAVE_MAP_CHAR(ptile, sg_extras_get(ptile->extras, ptile->resource, mod),
                   saving->file, "map.e%02d_%04d", j);
   } halfbyte_iterate_extras_end;
 }
@@ -6250,7 +6258,9 @@
     }
 
     SAVE_MAP_CHAR(ptile,
-                  sg_extras_get(map_get_player_tile(ptile, plr)->extras, mod),
+                  sg_extras_get(map_get_player_tile(ptile, plr)->extras,
+                                map_get_player_tile(ptile, plr)->resource,
+                                mod),
                   saving->file, "player%d.map_e%02d_%04d", plrno, j);
   } halfbyte_iterate_extras_end;
 


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

Reply via email to