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

The attached patch removes the fake special S_RESOURCE_VALID
and all supporting code.

This also 1/2 fixes the broken tile_has_any_specials, and
fixes a bug that would cause resources to sporadically
disappear when editing resources on tiles used by a city.

My plan is to restore the capability to implement civ2 style/
freeciv 2.0.x resource conversion rules and this patch is a
necessary first step in that direction. Subsequent patches
for this will follow shortly.


----------------------------------------------------------------------
頭が痛いほど調べた。
diff --git a/client/editor.c b/client/editor.c
index 030cedb..db1f598 100644
--- a/client/editor.c
+++ b/client/editor.c
@@ -260,6 +260,9 @@ static void editor_start_selection_rectangle(int canvas_x, int canvas_y)
   special values (S_RESOURCE_VALID and S_PILLAGE_BASE) do not in fact
   correspond to drawable special types, or are to be phased out soon
   (the base "specials").
+
+  FIXME: Remove this function when S_RESOURCE_VALID and S_PILLAGE_BASE
+  are finally exorcised.
 ****************************************************************************/
 static inline bool tile_really_has_any_specials(const struct tile *ptile)
 {
@@ -272,7 +275,6 @@ static inline bool tile_really_has_any_specials(const struct tile *ptile)
 
   specials = tile_specials(ptile);
 
-  BV_CLR(specials, S_RESOURCE_VALID);
   BV_CLR(specials, S_PILLAGE_BASE);
 
   base_type_iterate(pbase) {
diff --git a/client/tilespec.c b/client/tilespec.c
index b2fbd15..f6a93d5 100644
--- a/client/tilespec.c
+++ b/client/tilespec.c
@@ -4347,7 +4347,7 @@ int fill_sprite_array(struct tileset *t,
   case LAYER_SPECIAL1:
     if (NULL != pterrain) {
       if (draw_specials) {
-	if (tile_resource_is_valid(ptile)) {
+	if (tile_resource(ptile)) {
 	  ADD_SPRITE_SIMPLE(t->sprites.resource[resource_index(tile_resource(ptile))]);
 	}
       }
diff --git a/common/city.c b/common/city.c
index 5762b05..3abeaac 100644
--- a/common/city.c
+++ b/common/city.c
@@ -723,7 +723,7 @@ int city_tile_output(const struct city *pcity, const struct tile *ptile,
   }
 
   prod = pterrain->output[otype];
-  if (tile_resource_is_valid(ptile)) {
+  if (tile_resource(ptile)) {
     prod += tile_resource(ptile)->output[otype];
   }
 
diff --git a/common/terrain.h b/common/terrain.h
index 24b5600..b6cd4f1 100644
--- a/common/terrain.h
+++ b/common/terrain.h
@@ -43,7 +43,6 @@ enum tile_special_type {
 
   /* internal values not saved */
   S_LAST,
-  S_RESOURCE_VALID = S_LAST,
 
   /* internal values not saved and never set */
   S_LAST_PLUS,
diff --git a/common/tile.c b/common/tile.c
index 84d8e6c..fe1dca8 100644
--- a/common/tile.c
+++ b/common/tile.c
@@ -97,14 +97,6 @@ struct terrain *tile_terrain(const struct tile *ptile)
 void tile_set_terrain(struct tile *ptile, struct terrain *pterrain)
 {
   ptile->terrain = pterrain;
-  if (NULL != pterrain
-   && NULL != ptile->resource
-   && terrain_has_resource(pterrain, ptile->resource)) {
-    /* cannot use set_special() for internal values */
-    BV_SET(ptile->special, S_RESOURCE_VALID);
-  } else {
-    BV_CLR(ptile->special, S_RESOURCE_VALID);
-  }
 }
 
 /****************************************************************************
@@ -269,14 +261,6 @@ const struct resource *tile_resource(const struct tile *ptile)
 void tile_set_resource(struct tile *ptile, struct resource *presource)
 {
   ptile->resource = presource;
-  if (NULL != ptile->terrain
-   && NULL != presource
-   && terrain_has_resource(ptile->terrain, presource)) {
-    /* cannot use set_special() for internal values */
-    BV_SET(ptile->special, S_RESOURCE_VALID);
-  } else {
-    BV_CLR(ptile->special, S_RESOURCE_VALID);
-  }
 }
 
 /****************************************************************************
@@ -679,7 +663,7 @@ const char *tile_get_info_text(const struct tile *ptile, int linebreaks)
     lb = TRUE;
   }
 
-  if (tile_resource_is_valid(ptile)) {
+  if (tile_resource(ptile)) {
     if (lb) {
       sz_strlcat(s, "\n");
       lb = FALSE;
@@ -687,7 +671,7 @@ const char *tile_get_info_text(const struct tile *ptile, int linebreaks)
       sz_strlcat(s, " ");
     }
     cat_snprintf(s, sizeof(s), "(%s)",
-		 resource_name_translation(ptile->resource));
+		 resource_name_translation(tile_resource(ptile)));
   }
   if (linebreaks & TILE_LB_RESOURCE_POLL) {
     /* New linebreak requested */
diff --git a/common/tile.h b/common/tile.h
index a795a8e..43cd6a4 100644
--- a/common/tile.h
+++ b/common/tile.h
@@ -74,7 +74,6 @@ void tile_set_continent(struct tile *ptile, Continent_id val);
 void tile_set_owner(struct tile *ptile, struct player *pplayer);
 
 #define tile_resource(_tile) ((_tile)->resource)
-#define tile_resource_is_valid(_tile) BV_ISSET((_tile)->special, S_RESOURCE_VALID)
 /*const struct resource *tile_resource(const struct tile *ptile);*/
 void tile_set_resource(struct tile *ptile, struct resource *presource);
 
diff --git a/server/savegame.c b/server/savegame.c
index f2cb298..769790a 100644
--- a/server/savegame.c
+++ b/server/savegame.c
@@ -891,22 +891,16 @@ static void map_load(struct section_file *file,
 	set_savegame_old_resource(&ptile->resource, ptile->terrain, ch, 1));
   }
 
-  /* after the resources are loaded, indicate those currently valid */
   whole_map_iterate(ptile) {
-    if (NULL == ptile->resource
-     || NULL == ptile->terrain) {
+    if (NULL == ptile->resource || NULL == ptile->terrain) {
       continue;
     }
     if ('x' == ptile->resource->identifier
-     && 'd' == ptile->terrain->identifier
-     && 20200 > game.version) {
+        && 'd' == ptile->terrain->identifier
+        && game.version < 20200) {
       /* for compatibility with civ2 split of desert oil */
       ptile->resource = find_resource_by_identifier('X');
     }
-    if (terrain_has_resource(ptile->terrain, ptile->resource)) {
-      /* cannot use set_special() for internal values */
-      BV_SET(ptile->special, S_RESOURCE_VALID);
-    }
   } whole_map_iterate_end;
 
   if (secfile_lookup_bool_default(file, TRUE, "game.save_known")) {
diff --git a/client/tilespec.c b/client/tilespec.c
index bab30c1..e4aa2a0 100644
--- a/client/tilespec.c
+++ b/client/tilespec.c
@@ -4135,9 +4135,10 @@ int fill_sprite_array(struct tileset *t,
   case LAYER_SPECIAL1:
     if (NULL != pterrain) {
       if (draw_specials) {
-	if (tile_resource_is_valid(ptile)) {
-	  ADD_SPRITE_SIMPLE(t->sprites.resource[ptile->resource->index]);
-	}
+        if (tile_get_resource(ptile)) {
+          const struct resource *presource = tile_get_resource(ptile);
+          ADD_SPRITE_SIMPLE(t->sprites.resource[presource->index]);
+        }
       }
 
       if (draw_fortress_airbase && contains_special(tspecial, S_FORTRESS)
diff --git a/common/city.c b/common/city.c
index 435bd78..2583308 100644
--- a/common/city.c
+++ b/common/city.c
@@ -622,7 +622,7 @@ static int base_get_output_tile(const struct tile *ptile,
   }
 
   prod = pterrain->output[otype];
-  if (tile_resource_is_valid(p_dummy_tile)) {
+  if (tile_get_resource(p_dummy_tile)) {
     prod += tile_get_resource(p_dummy_tile)->output[otype];
   }
 
diff --git a/common/terrain.h b/common/terrain.h
index 06022f5..7c0913f 100644
--- a/common/terrain.h
+++ b/common/terrain.h
@@ -39,7 +39,6 @@ enum tile_special_type {
 
   /* internal values not saved */
   S_LAST,
-  S_RESOURCE_VALID = S_LAST,
 
   /* internal values not saved and never set */
   S_LAST_PLUS,
diff --git a/common/tile.c b/common/tile.c
index d5b1f17..cecb0a6 100644
--- a/common/tile.c
+++ b/common/tile.c
@@ -68,14 +68,6 @@ struct terrain *tile_get_terrain(const struct tile *ptile)
 void tile_set_terrain(struct tile *ptile, struct terrain *pterrain)
 {
   ptile->terrain = pterrain;
-  if (NULL != pterrain
-   && NULL != ptile->resource
-   && terrain_has_resource(pterrain, ptile->resource)) {
-    /* cannot use set_special() for internal values */
-    BV_SET(ptile->special, S_RESOURCE_VALID);
-  } else {
-    BV_CLR(ptile->special, S_RESOURCE_VALID);
-  }
 }
 
 /****************************************************************************
@@ -125,14 +117,6 @@ const struct resource *tile_get_resource(const struct tile *ptile)
 void tile_set_resource(struct tile *ptile, struct resource *presource)
 {
   ptile->resource = presource;
-  if (NULL != ptile->terrain
-   && NULL != presource
-   && terrain_has_resource(ptile->terrain, presource)) {
-    /* cannot use set_special() for internal values */
-    BV_SET(ptile->special, S_RESOURCE_VALID);
-  } else {
-    BV_CLR(ptile->special, S_RESOURCE_VALID);
-  }
 }
 
 /****************************************************************************
@@ -463,7 +447,7 @@ const char *tile_get_info_text(const struct tile *ptile)
     sz_strlcat(s, special_name_translation(S_RIVER));
   }
 
-  if (tile_resource_is_valid(ptile)) {
+  if (tile_get_resource(ptile)) {
     cat_snprintf(s, sizeof(s), " (%s)",
 		 resource_name_translation(ptile->resource));
   }
diff --git a/common/tile.h b/common/tile.h
index 5f26503..4dcb4f2 100644
--- a/common/tile.h
+++ b/common/tile.h
@@ -74,7 +74,6 @@ void tile_set_special(struct tile *ptile, enum tile_special_type spe);
 void tile_clear_special(struct tile *ptile, enum tile_special_type spe);
 void tile_clear_all_specials(struct tile *ptile);
 
-#define tile_resource_is_valid(vtile) BV_ISSET((vtile)->special, S_RESOURCE_VALID)
 const struct resource *tile_get_resource(const struct tile *ptile);
 void tile_set_resource(struct tile *ptile, struct resource *presource);
 
diff --git a/server/savegame.c b/server/savegame.c
index 66a2bda..2c4c2f0 100644
--- a/server/savegame.c
+++ b/server/savegame.c
@@ -840,16 +840,6 @@ static void map_load(struct section_file *file,
 	set_savegame_old_resource(&ptile->resource, ptile->terrain, ch, 1));
   }
 
-  /* after the resources are loaded, indicate those currently valid */
-  whole_map_iterate(ptile) {
-    if (NULL != ptile->terrain
-     && NULL != ptile->resource
-     && terrain_has_resource(ptile->terrain, ptile->resource)) {
-      /* cannot use set_special() for internal values */
-      BV_SET(ptile->special, S_RESOURCE_VALID);
-    }
-  } whole_map_iterate_end;
-
   /* Owner and ownership source are stored as plain numbers */
   if (has_capability("new_owner_map", savefile_options)) {
     int x, y;
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to