Author: jtn
Date: Mon Apr 21 16:06:03 2014
New Revision: 24787

URL: http://svn.gna.org/viewcvs/freeciv?rev=24787&view=rev
Log:
Requirements with Adjacent/CAdjacent ranges always check the centre tile too.
Fixed the TerrainClass, Base, and CityTile requirement types.

See gna bug #21470.

Modified:
    branches/S2_4/common/base.c
    branches/S2_4/common/map.h
    branches/S2_4/common/requirements.c
    branches/S2_4/common/requirements.h
    branches/S2_4/common/terrain.c

Modified: branches/S2_4/common/base.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_4/common/base.c?rev=24787&r1=24786&r2=24787&view=diff
==============================================================================
--- branches/S2_4/common/base.c (original)
+++ branches/S2_4/common/base.c Mon Apr 21 16:06:03 2014
@@ -131,6 +131,7 @@
 
 /****************************************************************************
   Is there base of the given type cardinally near tile?
+  (Does not check ptile itself.)
 ****************************************************************************/
 bool is_base_card_near(const struct tile *ptile, const struct base_type *pbase)
 {
@@ -145,6 +146,7 @@
 
 /****************************************************************************
   Is there base of the given type near tile?
+  (Does not check ptile itself.)
 ****************************************************************************/
 bool is_base_near_tile(const struct tile *ptile, const struct base_type *pbase)
 {

Modified: branches/S2_4/common/map.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_4/common/map.h?rev=24787&r1=24786&r2=24787&view=diff
==============================================================================
--- branches/S2_4/common/map.h  (original)
+++ branches/S2_4/common/map.h  Mon Apr 21 16:06:03 2014
@@ -378,10 +378,10 @@
 
 extern struct terrain_misc terrain_control;
 
-/* This iterates outwards from the starting point. Every tile within max_dist
- * will show up exactly once, in an outward (based on real map distance)
- * order.  The returned values are always real and are normalized.  The
- * starting position must be normal.
+/* This iterates outwards from the starting point.  Every tile within max_dist
+ * (including the starting tile) will show up exactly once, in an outward
+ * (based on real map distance) order.  The returned values are always real
+ * and are normalized.  The starting position must be normal.
  *
  * See also iterate_outward() */
 #define iterate_outward_dxy(start_tile, max_dist, _tile, _x, _y)           \
@@ -470,8 +470,9 @@
   } square_dxy_iterate_end;                                                \
 }
 
-/* Iterate through all map positions adjacent to the given center map
- * position, with normalization.  The order of positions is unspecified. */
+/* Iterate itr_tile through all map tiles adjacent to the given center map
+ * position, with normalization.  Does not include the center position.
+ * The order of positions is unspecified. */
 #define adjc_iterate(center_tile, itr_tile)                                \
 {                                                                          \
   /* Written as a wrapper to adjc_dir_iterate since it's the cleanest and   \
@@ -482,12 +483,14 @@
   } adjc_dir_iterate_end;                                                   \
 }
 
+/* As adjc_iterate() but also set direction8 iterator variable dir_itr */
 #define adjc_dir_iterate(center_tile, itr_tile, dir_itr)                   \
   adjc_dirlist_iterate(center_tile, itr_tile, dir_itr,                     \
                       map.valid_dirs, map.num_valid_dirs)
 
 #define adjc_dir_iterate_end adjc_dirlist_iterate_end
 
+/* Only set direction8 dir_itr (not tile) */
 #define adjc_dir_base_iterate(center_tile, dir_itr)                            
\
   adjc_dirlist_base_iterate(center_tile, dir_itr,                              
\
                             map.valid_dirs, map.num_valid_dirs)
@@ -495,18 +498,23 @@
 #define adjc_dir_base_iterate_end                                              
\
   adjc_dirlist_base_iterate_end
 
+/* Iterate itr_tile through all map tiles cardinally adjacent to the given
+ * center map position, with normalization.  Does not include the center
+ * position.  The order of positions is unspecified. */
 #define cardinal_adjc_iterate(center_tile, itr_tile)                       \
   adjc_dirlist_iterate(center_tile, itr_tile, _dir_itr,                        
    \
                       map.cardinal_dirs, map.num_cardinal_dirs)
 
 #define cardinal_adjc_iterate_end adjc_dirlist_iterate_end
 
+/* As cardinal_adjc_iterate but also set direction8 variable dir_itr */
 #define cardinal_adjc_dir_iterate(center_tile, itr_tile, dir_itr)          \
   adjc_dirlist_iterate(center_tile, itr_tile, dir_itr,                     \
                       map.cardinal_dirs, map.num_cardinal_dirs)
 
 #define cardinal_adjc_dir_iterate_end adjc_dirlist_iterate_end
 
+/* Only set direction8 dir_itr (not tile) */
 #define cardinal_adjc_dir_base_iterate(center_tile, dir_itr)                   
\
   adjc_dirlist_base_iterate(center_tile, dir_itr,                              
\
                             map.cardinal_dirs, map.num_cardinal_dirs)
@@ -516,10 +524,11 @@
 
 /* Iterate through all tiles adjacent to a tile using the given list of
  * directions.  _dir is the directional value, (center_x, center_y) is
- * the center tile (which must be normalized).
+ * the center tile (which must be normalized).  The center tile is not
+ * included in the iteration.
  *
- * This macro should not be used directly.  Instead, use adjc_dir_iterate
- * or cartesian_adjacent_iterate. */
+ * This macro should not be used directly.  Instead, use adjc_iterate,
+ * cardinal_adjc_iterate, or related iterators. */
 #define adjc_dirlist_iterate(center_tile, _tile, _dir,                     \
                             dirlist, dircount)                             \
 {                                                                          \

Modified: branches/S2_4/common/requirements.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_4/common/requirements.c?rev=24787&r1=24786&r2=24787&view=diff
==============================================================================
--- branches/S2_4/common/requirements.c (original)
+++ branches/S2_4/common/requirements.c Mon Apr 21 16:06:03 2014
@@ -871,9 +871,13 @@
     /* The requirement is filled if the tile has the terrain of correct class. 
*/
     return 
BOOL_TO_TRISTATE(terrain_belongs_to_class(tile_terrain(target_tile), class));
   case REQ_RANGE_CADJACENT:
-    return BOOL_TO_TRISTATE(is_terrain_class_card_near(target_tile, class));
+    return BOOL_TO_TRISTATE(terrain_belongs_to_class(tile_terrain(target_tile),
+                                                     class)
+                            || is_terrain_class_card_near(target_tile, class));
   case REQ_RANGE_ADJACENT:
-    return BOOL_TO_TRISTATE(is_terrain_class_near_tile(target_tile, class));
+    return BOOL_TO_TRISTATE(terrain_belongs_to_class(tile_terrain(target_tile),
+                                                     class)
+                            || is_terrain_class_near_tile(target_tile, class));
   case REQ_RANGE_CITY:
   case REQ_RANGE_CONTINENT:
   case REQ_RANGE_PLAYER:
@@ -903,9 +907,11 @@
     /* The requirement is filled if the tile has base of requested type. */
     return BOOL_TO_TRISTATE(tile_has_base(target_tile, pbase));
   case REQ_RANGE_CADJACENT:
-    return BOOL_TO_TRISTATE(is_base_card_near(target_tile, pbase));
+    return BOOL_TO_TRISTATE(tile_has_base(target_tile, pbase)
+                            || is_base_card_near(target_tile, pbase));
   case REQ_RANGE_ADJACENT:
-    return BOOL_TO_TRISTATE(is_base_near_tile(target_tile, pbase));
+    return BOOL_TO_TRISTATE(tile_has_base(target_tile, pbase)
+                            || is_base_near_tile(target_tile, pbase));
   case REQ_RANGE_CITY:
   case REQ_RANGE_CONTINENT:
   case REQ_RANGE_PLAYER:
@@ -1077,6 +1083,9 @@
       case REQ_RANGE_LOCAL:
         return BOOL_TO_TRISTATE(is_city_in_tile(target_tile, target_city));
       case REQ_RANGE_CADJACENT:
+        if (is_city_in_tile(target_tile, target_city)) {
+          return TRI_YES;
+        }
         cardinal_adjc_iterate(target_tile, adjc_tile) {
           if (is_city_in_tile(adjc_tile, target_city)) {
             return TRI_YES;
@@ -1085,6 +1094,9 @@
 
         return TRI_NO;
       case REQ_RANGE_ADJACENT:
+        if (is_city_in_tile(target_tile, target_city)) {
+          return TRI_YES;
+        }
         adjc_iterate(target_tile, adjc_tile) {
           if (is_city_in_tile(adjc_tile, target_city)) {
             return TRI_YES;

Modified: branches/S2_4/common/requirements.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_4/common/requirements.h?rev=24787&r1=24786&r2=24787&view=diff
==============================================================================
--- branches/S2_4/common/requirements.h (original)
+++ branches/S2_4/common/requirements.h Mon Apr 21 16:06:03 2014
@@ -27,7 +27,11 @@
 /* Range of requirements.
  * Used in the network protocol.
  * Order is important -- wider ranges should come later -- some code
- * assumes a total order, or tests for e.g. >= REQ_RANGE_PLAYER. */
+ * assumes a total order, or tests for e.g. >= REQ_RANGE_PLAYER.
+ * Ranges of similar types should be supersets: the set of Adjacent tiles
+ * contains the set of CAdjacent tiles, and both contain the center
+ * Local tile (a requirement on the local tile is also within Adjacent
+ * range). */
 #define SPECENUM_NAME req_range
 #define SPECENUM_VALUE0 REQ_RANGE_LOCAL
 #define SPECENUM_VALUE0NAME "Local"

Modified: branches/S2_4/common/terrain.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_4/common/terrain.c?rev=24787&r1=24786&r2=24787&view=diff
==============================================================================
--- branches/S2_4/common/terrain.c      (original)
+++ branches/S2_4/common/terrain.c      Mon Apr 21 16:06:03 2014
@@ -904,6 +904,7 @@
 
 /****************************************************************************
   Is there terrain of the given class cardinally near tile?
+  (Does not check ptile itself.)
 ****************************************************************************/
 bool is_terrain_class_card_near(const struct tile *ptile, enum terrain_class 
class)
 {
@@ -927,6 +928,7 @@
 
 /****************************************************************************
   Is there terrain of the given class near tile?
+  (Does not check ptile itself.)
 ****************************************************************************/
 bool is_terrain_class_near_tile(const struct tile *ptile, enum terrain_class 
class)
 {


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

Reply via email to