Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2004:
[Freeciv-Dev] (PR#9905) count_special_near_tile for cardinal directions
Home

[Freeciv-Dev] (PR#9905) count_special_near_tile for cardinal directions

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#9905) count_special_near_tile for cardinal directions
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 1 Sep 2004 19:03:51 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=9905 >

This patch...

1.  Moves count_special_near_tile and is_special_near_tile into 
terrain.[ch].  (Eventually all specials stuff should go into terrain.h.)

2.  Adds a cardinal_only parameter.

3.  Gets rid of adjacent_river_tiles4 (replaced by count_special_near_tile).

4.  Fixes a bug that could break river generation in hex maps.

The overall goal is to make it easier to deal with an unknown number of 
directions and cardinal directions.

jason

Index: common/map.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.c,v
retrieving revision 1.190
diff -u -r1.190 map.c
--- common/map.c        31 Aug 2004 05:43:51 -0000      1.190
+++ common/map.c        2 Sep 2004 02:01:03 -0000
@@ -577,34 +577,6 @@
   return map_vector_to_distance(dx, dy);
 }
 
-/***************************************************************
-  determines if any tile close to x,y has special spe
-***************************************************************/
-bool is_special_near_tile(int x, int y, enum tile_special_type spe)
-{
-  adjc_iterate(x, y, x1, y1) {
-    if (map_has_special(x1, y1, spe))
-      return TRUE;
-  } adjc_iterate_end;
-
-  return FALSE;
-}
-
-/***************************************************************
-  counts tiles close to x,y having special spe
-***************************************************************/
-int count_special_near_tile(int x, int y, enum tile_special_type spe)
-{
-  int count = 0;
-
-  adjc_iterate(x, y, x1, y1) {
-    if (map_has_special(x1, y1, spe))
-      count++;
-  } adjc_iterate_end;
-
-  return count;
-}
-
 /*************************************************************************
   This is used in mapgen for rivers going into ocen.  The name is 
   intentionally made awkward to prevent people from using it in place of
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.210
diff -u -r1.210 map.h
--- common/map.h        26 Aug 2004 18:37:52 -0000      1.210
+++ common/map.h        2 Sep 2004 02:01:03 -0000
@@ -388,8 +388,6 @@
 int map_move_cost(struct unit *punit, int x, int y);
 enum tile_special_type get_special_by_name(const char * name);
 const char *get_special_name(enum tile_special_type type);
-bool is_special_near_tile(int x, int y, enum tile_special_type spe);
-int count_special_near_tile(int x, int y, enum tile_special_type spe);
 bool is_safe_ocean(int x, int y);
 bool is_cardinally_adj_to_ocean(int x, int y);
 bool is_sea_usable(int x, int y);
Index: common/terrain.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/terrain.c,v
retrieving revision 1.13
diff -u -r1.13 terrain.c
--- common/terrain.c    1 Sep 2004 22:41:39 -0000       1.13
+++ common/terrain.c    2 Sep 2004 02:01:04 -0000
@@ -187,6 +187,37 @@
 }
 
 /****************************************************************************
+  Returns TRUE iff any tile adjacent to (map_x,map_y) has the given special.
+****************************************************************************/
+bool is_special_near_tile(int map_x, int map_y, enum tile_special_type spe)
+{
+  adjc_iterate(map_x, map_y, adjc_x, adjc_y) {
+    if (map_has_special(adjc_x, adjc_y, spe)) {
+      return TRUE;
+    }
+  } adjc_iterate_end;
+
+  return FALSE;
+}
+
+/****************************************************************************
+  Returns the number of adjacent tiles that have the given map special.
+****************************************************************************/
+int count_special_near_tile(int map_x, int map_y, bool cardinal_only,
+                           enum tile_special_type spe)
+{
+  int count = 0;
+
+  variable_adjc_iterate(map_x, map_y, adjc_x, adjc_y, cardinal_only) {
+    if (map_has_special(adjc_x, adjc_y, spe)) {
+      count++;
+    }
+  } variable_adjc_iterate_end;
+
+  return count;
+}
+
+/****************************************************************************
   Returns TRUE iff any adjacent tile contains terrain with the given flag.
 ****************************************************************************/
 bool is_terrain_flag_near_tile(int map_x, int map_y,
Index: common/terrain.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/terrain.h,v
retrieving revision 1.22
diff -u -r1.22 terrain.h
--- common/terrain.h    1 Sep 2004 22:41:39 -0000       1.22
+++ common/terrain.h    2 Sep 2004 02:01:04 -0000
@@ -117,6 +117,11 @@
 int count_terrain_near_tile(int map_x, int map_y, bool cardinal_only,
                            Terrain_type_id t);
 
+/* Functions to operate on a terrain special. */
+bool is_special_near_tile(int map_x, int map_y, enum tile_special_type spe);
+int count_special_near_tile(int map_x, int map_y, bool cardinal_only,
+                           enum tile_special_type spe);
+
 /* Functions to operate on a terrain flag. */
 bool is_terrain_flag_near_tile(int x, int y, enum terrain_flag_id flag);
 int count_terrain_flag_near_tile(int x, int y, bool cardinal_only,
Index: server/mapgen.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/mapgen.c,v
retrieving revision 1.150
diff -u -r1.150 mapgen.c
--- server/mapgen.c     1 Sep 2004 22:41:39 -0000       1.150
+++ server/mapgen.c     2 Sep 2004 02:01:06 -0000
@@ -570,23 +570,6 @@
 }
 
 /*********************************************************************
- Returns the number of adjacent river tiles of a tile. This can be 0
- to 4.                                                     -Erik Sigra
-*********************************************************************/
-static int adjacent_river_tiles4(int x, int y)
-{
-  int num_adjacent  = 0;
-
-  cardinal_adjc_iterate(x, y, x1, y1) {
-    if (map_has_special(x1, y1, S_RIVER)) {
-      num_adjacent++;
-    }
-  } cardinal_adjc_iterate_end;
-
-  return num_adjacent;
-}
-
-/*********************************************************************
  Help function used in make_river(). See the help there.
 *********************************************************************/
 static int river_test_blocked(int x, int y)
@@ -608,7 +591,7 @@
 *********************************************************************/
 static int river_test_rivergrid(int x, int y)
 {
-  return (adjacent_river_tiles4(x, y) > 1) ? 1 : 0;
+  return (count_special_near_tile(x, y, TRUE, S_RIVER) > 1) ? 1 : 0;
 }
 
 /*********************************************************************
@@ -635,7 +618,9 @@
 *********************************************************************/
 static int river_test_adjacent_river(int x, int y)
 {
-  return 4 - adjacent_river_tiles4(x, y);
+  /* This number must always be >= 0.  6 is the maximum number of
+   * cardinal directions. */
+  return 6 - count_special_near_tile(x, y, TRUE, S_RIVER);
 }
 
 /*********************************************************************
@@ -769,8 +754,8 @@
      Rivers must flow down to areas near other rivers when possible:
 
      Possible values:
-     n: 4 - adjacent_river_tiles4(...) (should be < 2 after the
-                                        4-river-grid test)
+     n: 6 - count_river_near_tile(...) (should be small after the
+                                        river-grid test)
                                        
  * Adjacent highlands:
      (river_test_adjacent_highlands)
@@ -819,7 +804,7 @@
 
     /* Test if the river is done. */
     /* We arbitrarily make rivers end at the poles. */
-    if (adjacent_river_tiles4(x, y) != 0
+    if (count_special_near_tile(x, y, TRUE, S_RIVER) != 0
        || count_ocean_near_tile(x, y, TRUE) != 0
         || (map_get_terrain(x, y) == T_ARCTIC 
            && map_temperature(x, y) < 8 * MAX_TEMP / 100)) { 
@@ -963,7 +948,7 @@
 
        /* Don't start a river on a tile is surrounded by > 1 river +
           ocean tile. */
-       && (adjacent_river_tiles4(x, y)
+       && (count_special_near_tile(x, y, TRUE, S_RIVER)
            + count_ocean_near_tile(x, y, TRUE) <= 1)
 
        /* Don't start a river on a tile that is surrounded by hills or
@@ -1974,12 +1959,12 @@
       /* the first condition helps make terrain more contiguous,
         the second lets it avoid the coast: */
       if ((i * 3 > k * 2 
-          || count_special_near_tile(x, y, S_RIVER) > 0
+          || count_special_near_tile(x, y, FALSE, S_RIVER) > 0
           || myrand(100) < 50)
          && (!is_cardinally_adj_to_ocean(x, y) || myrand(100) < coast)) {
        if (is_water_adjacent_to_tile(x, y)
            && count_ocean_near_tile(x, y, FALSE) < 4
-            && count_special_near_tile(x, y, S_RIVER) < 3) {
+            && count_special_near_tile(x, y, FALSE, S_RIVER) < 3) {
          map_set_special(x, y, S_RIVER);
          i--;
        }

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#9905) count_special_near_tile for cardinal directions, Jason Short <=