<URL: http://bugs.freeciv.org/Ticket/Display.html?id=14969 >
The existing patch made the testing and network slightly more efficient --
using a bitvector instead of a list of pointers -- but that's too much
change for the current state of 2.1 release. I'm not sure it is really
helpful in execution, as the list is only ever 0, 1, or 2 long. Might save
one or two tests on each tile that actually has resources, but greatly
increases the loop iterations for map generation and game saving. Might be
premature optimization.
Therefore, I extracted only the running portion. Any problems?
S2_1 revision 13720.
Index: common/city.c
===================================================================
--- common/city.c (revision 13719)
+++ common/city.c (working copy)
@@ -608,7 +608,8 @@
}
prod = pterrain->output[otype];
- if (ptile->resource) {
+ if (ptile->resource
+ && terrain_has_resource(ptile->terrain, ptile->resource)) {
prod += ptile->resource->output[otype];
}
Index: common/tile.c
===================================================================
--- common/tile.c (revision 13719)
+++ common/tile.c (working copy)
@@ -447,7 +447,8 @@
sz_strlcat(s, special_name_translation(S_RIVER));
}
- if (ptile->resource) {
+ if (ptile->resource
+ && terrain_has_resource(ptile->terrain, ptile->resource)) {
cat_snprintf(s, sizeof(s), " (%s)",
resource_name_translation(ptile->resource));
}
Index: common/terrain.c
===================================================================
--- common/terrain.c (revision 13719)
+++ common/terrain.c (working copy)
@@ -208,6 +208,23 @@
}
/****************************************************************************
+ Check for resource in terrain resources list.
+****************************************************************************/
+bool terrain_has_resource(const struct terrain *pterrain,
+ const struct resource *presource)
+{
+ struct resource **r = pterrain->resources;
+
+ while (NULL != *r) {
+ if (*r == presource) {
+ return TRUE;
+ }
+ r++;
+ }
+ return FALSE;
+}
+
+/****************************************************************************
Free memory which is associated with terrain types.
****************************************************************************/
void terrains_free(void)
Index: common/terrain.h
===================================================================
--- common/terrain.h (revision 13719)
+++ common/terrain.h (working copy)
@@ -181,6 +181,10 @@
enum terrain_flag_id find_terrain_flag_by_rule_name(const char *s);
#define terrain_has_flag(terr, flag) BV_ISSET((terr)->flags, flag)
struct terrain *pick_terrain_by_flag(enum terrain_flag_id flag);
+
+bool terrain_has_resource(const struct terrain *pterrain,
+ const struct resource *presource);
+
void terrains_free(void);
/* General resource accessor functions. */
Index: client/gui-sdl/mapview.c
===================================================================
--- client/gui-sdl/mapview.c (revision 13719)
+++ client/gui-sdl/mapview.c (working copy)
@@ -495,7 +495,8 @@
sz_strlcat(s, special_name_translation(S_RIVER));
}
- if (ptile->resource) {
+ if (ptile->resource
+ && terrain_has_resource(ptile->terrain, ptile->resource)) {
cat_snprintf(s, sizeof(s), " (%s)",
resource_name_translation(ptile->resource));
}
Index: client/tilespec.c
===================================================================
--- client/tilespec.c (revision 13719)
+++ client/tilespec.c (working copy)
@@ -4142,7 +4142,8 @@
case LAYER_SPECIAL1:
if (ptile && client_tile_get_known(ptile) != TILE_UNKNOWN) {
if (draw_specials) {
- if (ptile->resource) {
+ if (ptile->resource
+ && terrain_has_resource(ptile->terrain, ptile->resource)) {
ADD_SPRITE_SIMPLE(t->sprites.resource[ptile->resource->index]);
}
}
_______________________________________________
Freeciv-dev mailing list
[email protected]
https://mail.gna.org/listinfo/freeciv-dev