Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2004:
[Freeciv-Dev] (PR#2957) is ocean as a function with oceanness read from
Home

[Freeciv-Dev] (PR#2957) is ocean as a function with oceanness read from

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: kayeats@xxxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#2957) is ocean as a function with oceanness read from ruleset
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 17 Jan 2004 09:40:46 -0800
Reply-to: rt@xxxxxxxxxxx

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

Here is a patch that does the exact same thing, but uses a terrain flag
instead of adding a new boolean terrain value.

jason

Index: common/terrain.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/terrain.c,v
retrieving revision 1.1
diff -u -r1.1 terrain.c
--- common/terrain.c    2004/01/17 17:21:20     1.1
+++ common/terrain.c    2004/01/17 17:38:52
@@ -62,6 +62,7 @@
   enum terrain_flag_id flag;
   const char *flag_names[] = {
     /* Must match terrain flags in terrain.h. */
+    "Oceanic",
     "NoBarbs"
   };
 
@@ -128,6 +129,56 @@
 
   cartesian_adjacent_iterate(map_x, map_y, adjc_x, adjc_y) {
     if (map_get_terrain(adjc_x, adjc_y) == t) {
+      num_adjacent++;
+    }
+  } cartesian_adjacent_iterate_end;
+
+  return num_adjacent;
+}
+
+/****************************************************************************
+  Returns TRUE iff any adjacent tile contains terrain with the given flag.
+****************************************************************************/
+bool is_terrain_flag_near_tile(int map_x, int map_y,
+                              enum terrain_flag_id flag)
+{
+  adjc_iterate(map_x, map_y, adjc_x, adjc_y) {
+    if (terrain_has_flag(map_get_terrain(adjc_x, adjc_y), flag)) {
+      return TRUE;
+    }
+  } adjc_iterate_end;
+
+  return FALSE;
+}
+
+/****************************************************************************
+  Return the number of adjacent tiles that have terrain with the given flag.
+****************************************************************************/
+int count_terrain_flag_near_tile(int map_x, int map_y,
+                                enum terrain_flag_id flag)
+{
+  int count = 0;
+
+  adjc_iterate(map_x, map_y, adjc_x, adjc_y) {
+    if (terrain_has_flag(map_get_terrain(adjc_x, adjc_y), flag)) {
+      count++;
+    }
+  } adjc_iterate_end;
+
+  return count;
+}
+
+/****************************************************************************
+  Return the number of cardinally adjacent tiles that have terrain with
+  the given flag.
+****************************************************************************/
+int adjacent_terrain_flag_tiles4(int map_x, int map_y,
+                                enum terrain_flag_id flag)
+{
+  int num_adjacent = 0;
+
+  cartesian_adjacent_iterate(map_x, map_y, adjc_x, adjc_y) {
+    if (terrain_has_flag(map_get_terrain(adjc_x, adjc_y), flag)) {
       num_adjacent++;
     }
   } cartesian_adjacent_iterate_end;
Index: common/terrain.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/terrain.h,v
retrieving revision 1.8
diff -u -r1.8 terrain.h
--- common/terrain.h    2004/01/17 17:21:20     1.8
+++ common/terrain.h    2004/01/17 17:38:52
@@ -72,6 +72,7 @@
 #define T_COUNT (T_UNKNOWN)
 
 enum terrain_flag_id {
+  TER_OCEANIC, /* This is an ocean terrain. */
   TER_NO_BARBS, /* No barbarians summoned on this terrain. */
   TER_LAST
 };
@@ -100,9 +101,14 @@
 int count_terrain_near_tile(int map_x, int map_y, enum tile_terrain_type t);
 int adjacent_terrain_tiles4(int map_x, int map_y, enum tile_terrain_type t);
 
+/* 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, enum terrain_flag_id flag);
+int adjacent_terrain_flag_tiles4(int x, int y, enum terrain_flag_id flag);
+
 /* Terrain-specific functions. */
-#define is_ocean(x) ((x) == T_OCEAN)
-#define is_ocean_near_tile(x, y) is_terrain_near_tile(x, y, T_OCEAN)
+#define is_ocean(x) (terrain_has_flag((x), TER_OCEANIC))
+#define is_ocean_near_tile(x, y) is_terrain_flag_near_tile(x, y, TER_OCEANIC)
 #define adjacent_ocean_tiles4(x, y) adjacent_terrain_tiles4(x, y, T_OCEAN)
 #define count_ocean_near_tile(x,y) count_terrain_near_tile(x,y, T_OCEAN)
 
Index: data/civ1/terrain.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/civ1/terrain.ruleset,v
retrieving revision 1.15
diff -u -r1.15 terrain.ruleset
--- data/civ1/terrain.ruleset   2003/10/02 17:54:57     1.15
+++ data/civ1/terrain.ruleset   2004/01/17 17:38:52
@@ -424,6 +424,7 @@
 mining_time          = 0
 transform_result     = "no"
 transform_time       = 0
+flags                = "Oceanic"
 helptext            = _("\
 Oceans cover much of the world, and only sea units (Triremes and\
  other boats) can travel on them.\
Index: data/civ2/terrain.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/civ2/terrain.ruleset,v
retrieving revision 1.17
diff -u -r1.17 terrain.ruleset
--- data/civ2/terrain.ruleset   2003/10/02 17:54:57     1.17
+++ data/civ2/terrain.ruleset   2004/01/17 17:38:52
@@ -432,6 +432,7 @@
 mining_time          = 0
 transform_result     = "no"
 transform_time       = 0
+flags                = "Oceanic"
 helptext            = _("\
 Oceans cover much of the world, and only sea units (Triremes and\
  other boats) can travel on them.\
Index: data/default/terrain.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/default/terrain.ruleset,v
retrieving revision 1.18
diff -u -r1.18 terrain.ruleset
--- data/default/terrain.ruleset        2003/10/02 17:54:57     1.18
+++ data/default/terrain.ruleset        2004/01/17 17:38:53
@@ -432,6 +432,7 @@
 mining_time          = 0
 transform_result     = "Swamp"
 transform_time       = 36
+flags                = "Oceanic"
 helptext            = _("\
 Oceans cover much of the world, and only sea units (Triremes and\
  other boats) can travel on them.\
Index: data/history/terrain.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/history/terrain.ruleset,v
retrieving revision 1.2
diff -u -r1.2 terrain.ruleset
--- data/history/terrain.ruleset        2003/10/02 17:54:58     1.2
+++ data/history/terrain.ruleset        2004/01/17 17:38:53
@@ -432,6 +432,7 @@
 mining_time          = 0
 transform_result     = "Swamp"
 transform_time       = 36
+flags                = "Oceanic"
 helptext            = _("\
 Oceans cover much of the world, and only sea units (Triremes and\
  other boats) can travel on them.\

[Prev in Thread] Current Thread [Next in Thread]